From b7393b3a4bf5be3a31984b5c008267e269f4fa5a Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Thu, 31 Jan 2019 21:32:14 -0500 Subject: [PATCH] Breaking getBBox function out of layout --- src/layout.js | 19 ------------------- src/rendering/Box/index.js | 2 +- src/rendering/Loop/index.js | 2 +- src/rendering/Text/index.js | 2 +- src/rendering/getbbox.js | 19 +++++++++++++++++++ 5 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 src/rendering/getbbox.js diff --git a/src/layout.js b/src/layout.js index 5ad571c..aac4be1 100644 --- a/src/layout.js +++ b/src/layout.js @@ -1,6 +1,3 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; - import nodeTypes from 'rendering/types'; const normalizeBBox = box => ({ @@ -34,20 +31,4 @@ const layout = data => { }; }; -const getBBox = content => { - const container = document.createElement('div'); - document.body.appendChild(container); - - ReactDOM.render( - - { content } - , container); - - const box = container.querySelector('svg > g').getBBox(); - document.body.removeChild(container); - - return box; -}; - export default layout; -export { getBBox }; diff --git a/src/rendering/Box/index.js b/src/rendering/Box/index.js index e37be85..281435b 100644 --- a/src/rendering/Box/index.js +++ b/src/rendering/Box/index.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { getBBox } from 'layout'; +import getBBox from 'rendering/getbbox'; import * as style from './style'; diff --git a/src/rendering/Loop/index.js b/src/rendering/Loop/index.js index e11e9d3..71f8c18 100644 --- a/src/rendering/Loop/index.js +++ b/src/rendering/Loop/index.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { getBBox } from 'layout'; +import getBBox from 'rendering/getbbox'; import * as style from 'rendering/style'; diff --git a/src/rendering/Text/index.js b/src/rendering/Text/index.js index 5448d54..1bc8008 100644 --- a/src/rendering/Text/index.js +++ b/src/rendering/Text/index.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { getBBox } from 'layout'; +import getBBox from 'rendering/getbbox'; import * as style from './style'; diff --git a/src/rendering/getbbox.js b/src/rendering/getbbox.js new file mode 100644 index 0000000..f849139 --- /dev/null +++ b/src/rendering/getbbox.js @@ -0,0 +1,19 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; + +const getBBox = content => { + const container = document.createElement('div'); + document.body.appendChild(container); + + ReactDOM.render( + + { content } + , container); + + const box = container.querySelector('svg > g').getBBox(); + document.body.removeChild(container); + + return box; +}; + +export default getBBox;