{"version":3,"file":"SVGLoader.cjs","sources":["../../src/loaders/SVGLoader.js"],"sourcesContent":["import {\n Box2,\n BufferGeometry,\n FileLoader,\n Float32BufferAttribute,\n Loader,\n Matrix3,\n Path,\n Shape,\n ShapePath,\n ShapeUtils,\n Vector2,\n Vector3,\n} from 'three'\n\nconst COLOR_SPACE_SVG = 'srgb'\n\nconst SVGLoader = /* @__PURE__ */ (() => {\n class SVGLoader extends Loader {\n constructor(manager) {\n super(manager)\n\n // Default dots per inch\n this.defaultDPI = 90\n\n // Accepted units: 'mm', 'cm', 'in', 'pt', 'pc', 'px'\n this.defaultUnit = 'px'\n }\n\n load(url, onLoad, onProgress, onError) {\n const scope = this\n\n const loader = new FileLoader(scope.manager)\n loader.setPath(scope.path)\n loader.setRequestHeader(scope.requestHeader)\n loader.setWithCredentials(scope.withCredentials)\n loader.load(\n url,\n function (text) {\n try {\n onLoad(scope.parse(text))\n } catch (e) {\n if (onError) {\n onError(e)\n } else {\n console.error(e)\n }\n\n scope.manager.itemError(url)\n }\n },\n onProgress,\n onError,\n )\n }\n\n parse(text) {\n const scope = this\n\n function parseNode(node, style) {\n if (node.nodeType !== 1) return\n\n const transform = getNodeTransform(node)\n\n let isDefsNode = false\n\n let path = null\n\n switch (node.nodeName) {\n case 'svg':\n style = parseStyle(node, style)\n break\n\n case 'style':\n parseCSSStylesheet(node)\n break\n\n case 'g':\n style = parseStyle(node, style)\n break\n\n case 'path':\n style = parseStyle(node, style)\n if (node.hasAttribute('d')) path = parsePathNode(node)\n break\n\n case 'rect':\n style = parseStyle(node, style)\n path = parseRectNode(node)\n break\n\n case 'polygon':\n style = parseStyle(node, style)\n path = parsePolygonNode(node)\n break\n\n case 'polyline':\n style = parseStyle(node, style)\n path = parsePolylineNode(node)\n break\n\n case 'circle':\n style = parseStyle(node, style)\n path = parseCircleNode(node)\n break\n\n case 'ellipse':\n style = parseStyle(node, style)\n path = parseEllipseNode(node)\n break\n\n case 'line':\n style = parseStyle(node, style)\n path = parseLineNode(node)\n break\n\n case 'defs':\n isDefsNode = true\n break\n\n case 'use':\n style = parseStyle(node, style)\n\n const href = node.getAttributeNS('http://www.w3.org/1999/xlink', 'href') || ''\n const usedNodeId = href.substring(1)\n const usedNode = node.viewportElement.getElementById(usedNodeId)\n if (usedNode) {\n parseNode(usedNode, style)\n } else {\n console.warn(\"SVGLoader: 'use node' references non-existent node id: \" + usedNodeId)\n }\n\n break\n\n default:\n // console.log( node );\n }\n\n if (path) {\n if (style.fill !== undefined && style.fill !== 'none') {\n path.color.setStyle(style.fill, COLOR_SPACE_SVG)\n }\n\n transformPath(path, currentTransform)\n\n paths.push(path)\n\n path.userData = { node: node, style: style }\n }\n\n const childNodes = node.childNodes\n\n for (let i = 0; i < childNodes.length; i++) {\n const node = childNodes[i]\n\n if (isDefsNode && node.nodeName !== 'style' && node.nodeName !== 'defs') {\n // Ignore everything in defs except CSS style definitions\n // and nested defs, because it is OK by the standard to have\n //