Fix: avoid to select defs or title as parentElement (#840)

* Fix: avoid to select defs or title as parentElement
This commit is contained in:
cg-scorpio
2022-10-15 17:21:14 +02:00
committed by GitHub
parent e2ad8211a5
commit aabd593123
5 changed files with 1345 additions and 1497 deletions

View File

@@ -6,7 +6,6 @@ import rimraf from 'rimraf'
import babel from '@rollup/plugin-babel'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
// import progress from 'rollup-plugin-progress';
import filesize from 'rollup-plugin-filesize'
@@ -31,7 +30,6 @@ const config = [{
}),
commonjs(),
babel({ babelHelpers: 'bundled', exclude: [/\/core-js\//] }), // exclude core-js to avoid circular dependencies.
terser({ keep_fnames: true }), // keep_fnames is needed to avoid an error when calling extensions.
filesize()
]
}]

View File

@@ -962,7 +962,15 @@ export const getStrokedBBox = (elems, addSVGElementsFromJson, pathActions) => {
export const getVisibleElements = (parentElement) => {
if (!parentElement) {
const svgContent = svgCanvas.getSvgContent()
parentElement = svgContent.children[0] // Prevent layers from being included
for (let i = 0; i < svgContent.children.length; i++) {
if (svgContent.children[i].getBBox) {
const bbox = svgContent.children[i].getBBox()
if (bbox.width !== 0 && bbox.height !== 0 && bbox.width !== 0 && bbox.height !== 0) {
parentElement = svgContent.children[i]
break
}
}
}
}
const contentElems = []