Breaking getBBox function out of layout
This commit is contained in:
parent
a13f26286d
commit
b7393b3a4b
@ -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 };
|
|
||||||
|
@ -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';
|
||||||
|
|
||||||
|
@ -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';
|
||||||
|
|
||||||
|
@ -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
19
src/rendering/getbbox.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user