Breaking getBBox function out of layout

This commit is contained in:
Jeff Avallone 2019-01-31 21:32:14 -05:00
parent a13f26286d
commit b7393b3a4b
5 changed files with 22 additions and 22 deletions

View File

@ -1,6 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom';
import nodeTypes from 'rendering/types'; import nodeTypes from 'rendering/types';
const normalizeBBox = box => ({ const normalizeBBox = box => ({
@ -34,20 +31,4 @@ const layout = data => {
}; };
}; };
const getBBox = content => {
const container = document.createElement('div');
document.body.appendChild(container);
ReactDOM.render(
<svg width="0" height="0" viewBox="0 0 0 0">
<g>{ content }</g>
</svg>, container);
const box = container.querySelector('svg > g').getBBox();
document.body.removeChild(container);
return box;
};
export default layout; export default layout;
export { getBBox };

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { getBBox } from 'layout'; import getBBox from 'rendering/getbbox';
import * as style from './style'; import * as style from './style';

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { getBBox } from 'layout'; import getBBox from 'rendering/getbbox';
import * as style from 'rendering/style'; import * as style from 'rendering/style';

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { getBBox } from 'layout'; import getBBox from 'rendering/getbbox';
import * as style from './style'; import * as style from './style';

19
src/rendering/getbbox.js Normal file
View File

@ -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(
<svg width="0" height="0" viewBox="0 0 0 0">
<g>{ content }</g>
</svg>, container);
const box = container.querySelector('svg > g').getBBox();
document.body.removeChild(container);
return box;
};
export default getBBox;