UNPKG

lingo3d-react

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

992 lines (991 loc) 37.8 kB
import { L as Mt, F as It, t as at, J as q, a as yt, ay as Pt, az as St, aA as Nt, aB as mt, r as Et, s as xt, aC as ct, x as Ct, y as Lt, z as Rt, H as jt } from "./index-895cfa2f.mjs"; import "react"; import "react-dom"; class bt extends Mt { constructor(C) { super(C), this.defaultDPI = 90, this.defaultUnit = "px"; } load(C, F, R, S) { const M = this, J = new It(M.manager); J.setPath(M.path), J.setRequestHeader(M.requestHeader), J.setWithCredentials(M.withCredentials), J.load(C, function(tt) { try { F(M.parse(tt)); } catch (Q) { S ? S(Q) : console.error(Q), M.manager.itemError(C); } }, R, S); } parse(C) { const F = this; function R(i, s) { if (i.nodeType !== 1) return; const e = T(i); let t = !1, c = null; switch (i.nodeName) { case "svg": s = z(i, s); break; case "style": M(i); break; case "g": s = z(i, s); break; case "path": s = z(i, s), i.hasAttribute("d") && (c = S(i)); break; case "rect": s = z(i, s), c = Q(i); break; case "polygon": s = z(i, s), c = X(i); break; case "polyline": s = z(i, s), c = $(i); break; case "circle": s = z(i, s), c = V(i); break; case "ellipse": s = z(i, s), c = B(i); break; case "line": s = z(i, s), c = ot(i); break; case "defs": t = !0; break; case "use": s = z(i, s); const y = (i.getAttributeNS("http://www.w3.org/1999/xlink", "href") || "").substring(1), d = i.viewportElement.getElementById(y); d ? R(d, s) : console.warn("SVGLoader: 'use node' references non-existent node id: " + y); break; } c && (s.fill !== void 0 && s.fill !== "none" && c.color.setStyle(s.fill), N(c, nt), A.push(c), c.userData = { node: i, style: s }); const u = i.childNodes; for (let r = 0; r < u.length; r++) { const y = u[r]; t && y.nodeName !== "style" && y.nodeName !== "defs" || R(y, s); } e && (H.pop(), H.length > 0 ? nt.copy(H[H.length - 1]) : nt.identity()); } function S(i) { const s = new ct(), e = new q(), t = new q(), c = new q(); let u = !0, r = !1; const y = i.getAttribute("d"); if (y === "" || y === "none") return null; const d = y.match(/[a-df-z][^a-df-z]*/ig); for (let m = 0, a = d.length; m < a; m++) { const l = d[m], x = l.charAt(0), g = l.slice(1).trim(); u === !0 && (r = !0, u = !1); let o; switch (x) { case "M": o = p(g); for (let n = 0, k = o.length; n < k; n += 2) e.x = o[n + 0], e.y = o[n + 1], t.x = e.x, t.y = e.y, n === 0 ? s.moveTo(e.x, e.y) : s.lineTo(e.x, e.y), n === 0 && c.copy(e); break; case "H": o = p(g); for (let n = 0, k = o.length; n < k; n++) e.x = o[n], t.x = e.x, t.y = e.y, s.lineTo(e.x, e.y), n === 0 && r === !0 && c.copy(e); break; case "V": o = p(g); for (let n = 0, k = o.length; n < k; n++) e.y = o[n], t.x = e.x, t.y = e.y, s.lineTo(e.x, e.y), n === 0 && r === !0 && c.copy(e); break; case "L": o = p(g); for (let n = 0, k = o.length; n < k; n += 2) e.x = o[n + 0], e.y = o[n + 1], t.x = e.x, t.y = e.y, s.lineTo(e.x, e.y), n === 0 && r === !0 && c.copy(e); break; case "C": o = p(g); for (let n = 0, k = o.length; n < k; n += 6) s.bezierCurveTo( o[n + 0], o[n + 1], o[n + 2], o[n + 3], o[n + 4], o[n + 5] ), t.x = o[n + 2], t.y = o[n + 3], e.x = o[n + 4], e.y = o[n + 5], n === 0 && r === !0 && c.copy(e); break; case "S": o = p(g); for (let n = 0, k = o.length; n < k; n += 4) s.bezierCurveTo( b(e.x, t.x), b(e.y, t.y), o[n + 0], o[n + 1], o[n + 2], o[n + 3] ), t.x = o[n + 0], t.y = o[n + 1], e.x = o[n + 2], e.y = o[n + 3], n === 0 && r === !0 && c.copy(e); break; case "Q": o = p(g); for (let n = 0, k = o.length; n < k; n += 4) s.quadraticCurveTo( o[n + 0], o[n + 1], o[n + 2], o[n + 3] ), t.x = o[n + 0], t.y = o[n + 1], e.x = o[n + 2], e.y = o[n + 3], n === 0 && r === !0 && c.copy(e); break; case "T": o = p(g); for (let n = 0, k = o.length; n < k; n += 2) { const G = b(e.x, t.x), et = b(e.y, t.y); s.quadraticCurveTo( G, et, o[n + 0], o[n + 1] ), t.x = G, t.y = et, e.x = o[n + 0], e.y = o[n + 1], n === 0 && r === !0 && c.copy(e); } break; case "A": o = p(g, [3, 4], 7); for (let n = 0, k = o.length; n < k; n += 7) { if (o[n + 5] == e.x && o[n + 6] == e.y) continue; const G = e.clone(); e.x = o[n + 5], e.y = o[n + 6], t.x = e.x, t.y = e.y, J( s, o[n], o[n + 1], o[n + 2], o[n + 3], o[n + 4], G, e ), n === 0 && r === !0 && c.copy(e); } break; case "m": o = p(g); for (let n = 0, k = o.length; n < k; n += 2) e.x += o[n + 0], e.y += o[n + 1], t.x = e.x, t.y = e.y, n === 0 ? s.moveTo(e.x, e.y) : s.lineTo(e.x, e.y), n === 0 && c.copy(e); break; case "h": o = p(g); for (let n = 0, k = o.length; n < k; n++) e.x += o[n], t.x = e.x, t.y = e.y, s.lineTo(e.x, e.y), n === 0 && r === !0 && c.copy(e); break; case "v": o = p(g); for (let n = 0, k = o.length; n < k; n++) e.y += o[n], t.x = e.x, t.y = e.y, s.lineTo(e.x, e.y), n === 0 && r === !0 && c.copy(e); break; case "l": o = p(g); for (let n = 0, k = o.length; n < k; n += 2) e.x += o[n + 0], e.y += o[n + 1], t.x = e.x, t.y = e.y, s.lineTo(e.x, e.y), n === 0 && r === !0 && c.copy(e); break; case "c": o = p(g); for (let n = 0, k = o.length; n < k; n += 6) s.bezierCurveTo( e.x + o[n + 0], e.y + o[n + 1], e.x + o[n + 2], e.y + o[n + 3], e.x + o[n + 4], e.y + o[n + 5] ), t.x = e.x + o[n + 2], t.y = e.y + o[n + 3], e.x += o[n + 4], e.y += o[n + 5], n === 0 && r === !0 && c.copy(e); break; case "s": o = p(g); for (let n = 0, k = o.length; n < k; n += 4) s.bezierCurveTo( b(e.x, t.x), b(e.y, t.y), e.x + o[n + 0], e.y + o[n + 1], e.x + o[n + 2], e.y + o[n + 3] ), t.x = e.x + o[n + 0], t.y = e.y + o[n + 1], e.x += o[n + 2], e.y += o[n + 3], n === 0 && r === !0 && c.copy(e); break; case "q": o = p(g); for (let n = 0, k = o.length; n < k; n += 4) s.quadraticCurveTo( e.x + o[n + 0], e.y + o[n + 1], e.x + o[n + 2], e.y + o[n + 3] ), t.x = e.x + o[n + 0], t.y = e.y + o[n + 1], e.x += o[n + 2], e.y += o[n + 3], n === 0 && r === !0 && c.copy(e); break; case "t": o = p(g); for (let n = 0, k = o.length; n < k; n += 2) { const G = b(e.x, t.x), et = b(e.y, t.y); s.quadraticCurveTo( G, et, e.x + o[n + 0], e.y + o[n + 1] ), t.x = G, t.y = et, e.x = e.x + o[n + 0], e.y = e.y + o[n + 1], n === 0 && r === !0 && c.copy(e); } break; case "a": o = p(g, [3, 4], 7); for (let n = 0, k = o.length; n < k; n += 7) { if (o[n + 5] == 0 && o[n + 6] == 0) continue; const G = e.clone(); e.x += o[n + 5], e.y += o[n + 6], t.x = e.x, t.y = e.y, J( s, o[n], o[n + 1], o[n + 2], o[n + 3], o[n + 4], G, e ), n === 0 && r === !0 && c.copy(e); } break; case "Z": case "z": s.currentPath.autoClose = !0, s.currentPath.curves.length > 0 && (e.copy(c), s.currentPath.currentPoint.copy(e), u = !0); break; default: console.warn(l); } r = !1; } return s; } function M(i) { if (!(!i.sheet || !i.sheet.cssRules || !i.sheet.cssRules.length)) for (let s = 0; s < i.sheet.cssRules.length; s++) { const e = i.sheet.cssRules[s]; if (e.type !== 1) continue; const t = e.selectorText.split(/,/gm).filter(Boolean).map((c) => c.trim()); for (let c = 0; c < t.length; c++) { const u = Object.fromEntries( Object.entries(e.style).filter(([, r]) => r !== "") ); U[t[c]] = Object.assign( U[t[c]] || {}, u ); } } } function J(i, s, e, t, c, u, r, y) { if (s == 0 || e == 0) { i.lineTo(y.x, y.y); return; } t = t * Math.PI / 180, s = Math.abs(s), e = Math.abs(e); const d = (r.x - y.x) / 2, m = (r.y - y.y) / 2, a = Math.cos(t) * d + Math.sin(t) * m, l = -Math.sin(t) * d + Math.cos(t) * m; let x = s * s, g = e * e; const o = a * a, n = l * l, k = o / x + n / g; if (k > 1) { const ht = Math.sqrt(k); s = ht * s, e = ht * e, x = s * s, g = e * e; } const G = x * n + g * o, et = (x * g - G) / G; let st = Math.sqrt(Math.max(0, et)); c === u && (st = -st); const K = st * s * l / e, it = -st * e * a / s, ft = Math.cos(t) * K - Math.sin(t) * it + (r.x + y.x) / 2, gt = Math.sin(t) * K + Math.cos(t) * it + (r.y + y.y) / 2, ut = tt(1, 0, (a - K) / s, (l - it) / e), dt = tt((a - K) / s, (l - it) / e, (-a - K) / s, (-l - it) / e) % (Math.PI * 2); i.currentPath.absellipse(ft, gt, s, e, ut, ut + dt, u === 0, t); } function tt(i, s, e, t) { const c = i * e + s * t, u = Math.sqrt(i * i + s * s) * Math.sqrt(e * e + t * t); let r = Math.acos(Math.max(-1, Math.min(1, c / u))); return i * t - s * e < 0 && (r = -r), r; } function Q(i) { const s = h(i.getAttribute("x") || 0), e = h(i.getAttribute("y") || 0), t = h(i.getAttribute("rx") || i.getAttribute("ry") || 0), c = h(i.getAttribute("ry") || i.getAttribute("rx") || 0), u = h(i.getAttribute("width")), r = h(i.getAttribute("height")), y = 1 - 0.551915024494, d = new ct(); return d.moveTo(s + t, e), d.lineTo(s + u - t, e), (t !== 0 || c !== 0) && d.bezierCurveTo( s + u - t * y, e, s + u, e + c * y, s + u, e + c ), d.lineTo(s + u, e + r - c), (t !== 0 || c !== 0) && d.bezierCurveTo( s + u, e + r - c * y, s + u - t * y, e + r, s + u - t, e + r ), d.lineTo(s + t, e + r), (t !== 0 || c !== 0) && d.bezierCurveTo( s + t * y, e + r, s, e + r - c * y, s, e + r - c ), d.lineTo(s, e + c), (t !== 0 || c !== 0) && d.bezierCurveTo(s, e + c * y, s + t * y, e, s + t, e), d; } function X(i) { function s(u, r, y) { const d = h(r), m = h(y); c === 0 ? t.moveTo(d, m) : t.lineTo(d, m), c++; } const e = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g, t = new ct(); let c = 0; return i.getAttribute("points").replace(e, s), t.currentPath.autoClose = !0, t; } function $(i) { function s(u, r, y) { const d = h(r), m = h(y); c === 0 ? t.moveTo(d, m) : t.lineTo(d, m), c++; } const e = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g, t = new ct(); let c = 0; return i.getAttribute("points").replace(e, s), t.currentPath.autoClose = !1, t; } function V(i) { const s = h(i.getAttribute("cx") || 0), e = h(i.getAttribute("cy") || 0), t = h(i.getAttribute("r") || 0), c = new mt(); c.absarc(s, e, t, 0, Math.PI * 2); const u = new ct(); return u.subPaths.push(c), u; } function B(i) { const s = h(i.getAttribute("cx") || 0), e = h(i.getAttribute("cy") || 0), t = h(i.getAttribute("rx") || 0), c = h(i.getAttribute("ry") || 0), u = new mt(); u.absellipse(s, e, t, c, 0, Math.PI * 2); const r = new ct(); return r.subPaths.push(u), r; } function ot(i) { const s = h(i.getAttribute("x1") || 0), e = h(i.getAttribute("y1") || 0), t = h(i.getAttribute("x2") || 0), c = h(i.getAttribute("y2") || 0), u = new ct(); return u.moveTo(s, e), u.lineTo(t, c), u.currentPath.autoClose = !1, u; } function z(i, s) { s = Object.assign({}, s); let e = {}; if (i.hasAttribute("class")) { const r = i.getAttribute("class").split(/\s/).filter(Boolean).map((y) => y.trim()); for (let y = 0; y < r.length; y++) e = Object.assign(e, U["." + r[y]]); } i.hasAttribute("id") && (e = Object.assign(e, U["#" + i.getAttribute("id")])); function t(r, y, d) { d === void 0 && (d = function(a) { return a.startsWith("url") && console.warn("SVGLoader: url access in attributes is not implemented."), a; }), i.hasAttribute(r) && (s[y] = d(i.getAttribute(r))), e[r] && (s[y] = d(e[r])), i.style && i.style[r] !== "" && (s[y] = d(i.style[r])); } function c(r) { return Math.max(0, Math.min(1, h(r))); } function u(r) { return Math.max(0, h(r)); } return t("fill", "fill"), t("fill-opacity", "fillOpacity", c), t("fill-rule", "fillRule"), t("opacity", "opacity", c), t("stroke", "stroke"), t("stroke-opacity", "strokeOpacity", c), t("stroke-width", "strokeWidth", u), t("stroke-linejoin", "strokeLineJoin"), t("stroke-linecap", "strokeLineCap"), t("stroke-miterlimit", "strokeMiterLimit", u), t("visibility", "visibility"), s; } function b(i, s) { return i - (s - i); } function p(i, s, e) { if (typeof i != "string") throw new TypeError("Invalid input: " + typeof i); const t = { SEPARATOR: /[ \t\r\n\,.\-+]/, WHITESPACE: /[ \t\r\n]/, DIGIT: /[\d]/, SIGN: /[-+]/, POINT: /\./, COMMA: /,/, EXP: /e/i, FLAGS: /[01]/ }, c = 0, u = 1, r = 2, y = 3; let d = c, m = !0, a = "", l = ""; const x = []; function g(G, et, st) { const K = new SyntaxError('Unexpected character "' + G + '" at index ' + et + "."); throw K.partial = st, K; } function o() { a !== "" && (l === "" ? x.push(Number(a)) : x.push(Number(a) * Math.pow(10, Number(l)))), a = "", l = ""; } let n; const k = i.length; for (let G = 0; G < k; G++) { if (n = i[G], Array.isArray(s) && s.includes(x.length % e) && t.FLAGS.test(n)) { d = u, a = n, o(); continue; } if (d === c) { if (t.WHITESPACE.test(n)) continue; if (t.DIGIT.test(n) || t.SIGN.test(n)) { d = u, a = n; continue; } if (t.POINT.test(n)) { d = r, a = n; continue; } t.COMMA.test(n) && (m && g(n, G, x), m = !0); } if (d === u) { if (t.DIGIT.test(n)) { a += n; continue; } if (t.POINT.test(n)) { a += n, d = r; continue; } if (t.EXP.test(n)) { d = y; continue; } t.SIGN.test(n) && a.length === 1 && t.SIGN.test(a[0]) && g(n, G, x); } if (d === r) { if (t.DIGIT.test(n)) { a += n; continue; } if (t.EXP.test(n)) { d = y; continue; } t.POINT.test(n) && a[a.length - 1] === "." && g(n, G, x); } if (d === y) { if (t.DIGIT.test(n)) { l += n; continue; } if (t.SIGN.test(n)) { if (l === "") { l += n; continue; } l.length === 1 && t.SIGN.test(l) && g(n, G, x); } } t.WHITESPACE.test(n) ? (o(), d = c, m = !1) : t.COMMA.test(n) ? (o(), d = c, m = !0) : t.SIGN.test(n) ? (o(), d = u, a = n) : t.POINT.test(n) ? (o(), d = r, a = n) : g(n, G, x); } return o(), x; } const w = ["mm", "cm", "in", "pt", "pc", "px"], j = { mm: { mm: 1, cm: 0.1, in: 1 / 25.4, pt: 72 / 25.4, pc: 6 / 25.4, px: -1 }, cm: { mm: 10, cm: 1, in: 1 / 2.54, pt: 72 / 2.54, pc: 6 / 2.54, px: -1 }, in: { mm: 25.4, cm: 2.54, in: 1, pt: 72, pc: 6, px: -1 }, pt: { mm: 25.4 / 72, cm: 2.54 / 72, in: 1 / 72, pt: 1, pc: 6 / 72, px: -1 }, pc: { mm: 25.4 / 6, cm: 2.54 / 6, in: 1 / 6, pt: 72 / 6, pc: 1, px: -1 }, px: { px: 1 } }; function h(i) { let s = "px"; if (typeof i == "string" || i instanceof String) for (let t = 0, c = w.length; t < c; t++) { const u = w[t]; if (i.endsWith(u)) { s = u, i = i.substring(0, i.length - u.length); break; } } let e; return s === "px" && F.defaultUnit !== "px" ? e = j.in[F.defaultUnit] / F.defaultDPI : (e = j[s][F.defaultUnit], e < 0 && (e = j[s].in * F.defaultDPI)), e * parseFloat(i); } function T(i) { if (!(i.hasAttribute("transform") || i.nodeName === "use" && (i.hasAttribute("x") || i.hasAttribute("y")))) return null; const s = I(i); return H.length > 0 && s.premultiply(H[H.length - 1]), nt.copy(s), H.push(s), s; } function I(i) { const s = new at(), e = _; if (i.nodeName === "use" && (i.hasAttribute("x") || i.hasAttribute("y"))) { const t = h(i.getAttribute("x")), c = h(i.getAttribute("y")); s.translate(t, c); } if (i.hasAttribute("transform")) { const t = i.getAttribute("transform").split(")"); for (let c = t.length - 1; c >= 0; c--) { const u = t[c].trim(); if (u === "") continue; const r = u.indexOf("("), y = u.length; if (r > 0 && r < y) { const d = u.slice(0, r), m = p(u.slice(r + 1)); switch (e.identity(), d) { case "translate": if (m.length >= 1) { const a = m[0]; let l = 0; m.length >= 2 && (l = m[1]), e.translate(a, l); } break; case "rotate": if (m.length >= 1) { let a = 0, l = 0, x = 0; a = m[0] * Math.PI / 180, m.length >= 3 && (l = m[1], x = m[2]), Y.makeTranslation(-l, -x), P.makeRotation(a), f.multiplyMatrices(P, Y), Y.makeTranslation(l, x), e.multiplyMatrices(Y, f); } break; case "scale": if (m.length >= 1) { const a = m[0]; let l = a; m.length >= 2 && (l = m[1]), e.scale(a, l); } break; case "skewX": m.length === 1 && e.set( 1, Math.tan(m[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1 ); break; case "skewY": m.length === 1 && e.set( 1, 0, 0, Math.tan(m[0] * Math.PI / 180), 1, 0, 0, 0, 1 ); break; case "matrix": m.length === 6 && e.set( m[0], m[2], m[4], m[1], m[3], m[5], 0, 0, 1 ); break; } } s.premultiply(e); } } return s; } function N(i, s) { function e(r) { D.set(r.x, r.y, 1).applyMatrix3(s), r.set(D.x, D.y); } function t(r) { const y = r.xRadius, d = r.yRadius, m = Math.cos(r.aRotation), a = Math.sin(r.aRotation), l = new yt(y * m, y * a, 0), x = new yt(-d * a, d * m, 0), g = l.applyMatrix3(s), o = x.applyMatrix3(s), n = _.set( g.x, o.x, 0, g.y, o.y, 0, 0, 0, 1 ), k = Y.copy(n).invert(), st = P.copy(k).transpose().multiply(k).elements, K = v(st[0], st[1], st[4]), it = Math.sqrt(K.rt1), ft = Math.sqrt(K.rt2); if (r.xRadius = 1 / it, r.yRadius = 1 / ft, r.aRotation = Math.atan2(K.sn, K.cs), !((r.aEndAngle - r.aStartAngle) % (2 * Math.PI) < Number.EPSILON)) { const ut = Y.set( it, 0, 0, 0, ft, 0, 0, 0, 1 ), dt = P.set( K.cs, K.sn, 0, -K.sn, K.cs, 0, 0, 0, 1 ), ht = ut.multiply(dt).multiply(n), kt = (Tt) => { const { x: At, y: wt } = new yt(Math.cos(Tt), Math.sin(Tt), 0).applyMatrix3(ht); return Math.atan2(wt, At); }; r.aStartAngle = kt(r.aStartAngle), r.aEndAngle = kt(r.aEndAngle), O(s) && (r.aClockwise = !r.aClockwise); } } function c(r) { const y = L(s), d = W(s); r.xRadius *= y, r.yRadius *= d; const m = y > Number.EPSILON ? Math.atan2(s.elements[1], s.elements[0]) : Math.atan2(-s.elements[3], s.elements[4]); r.aRotation += m, O(s) && (r.aStartAngle *= -1, r.aEndAngle *= -1, r.aClockwise = !r.aClockwise); } const u = i.subPaths; for (let r = 0, y = u.length; r < y; r++) { const m = u[r].curves; for (let a = 0; a < m.length; a++) { const l = m[a]; l.isLineCurve ? (e(l.v1), e(l.v2)) : l.isCubicBezierCurve ? (e(l.v0), e(l.v1), e(l.v2), e(l.v3)) : l.isQuadraticBezierCurve ? (e(l.v0), e(l.v1), e(l.v2)) : l.isEllipseCurve && (Z.set(l.aX, l.aY), e(Z), l.aX = Z.x, l.aY = Z.y, E(s) ? t(l) : c(l)); } } } function O(i) { const s = i.elements; return s[0] * s[4] - s[1] * s[3] < 0; } function E(i) { const s = i.elements, e = s[0] * s[3] + s[1] * s[4]; if (e === 0) return !1; const t = L(i), c = W(i); return Math.abs(e / (t * c)) > Number.EPSILON; } function L(i) { const s = i.elements; return Math.sqrt(s[0] * s[0] + s[1] * s[1]); } function W(i) { const s = i.elements; return Math.sqrt(s[3] * s[3] + s[4] * s[4]); } function v(i, s, e) { let t, c, u, r, y; const d = i + e, m = i - e, a = Math.sqrt(m * m + 4 * s * s); return d > 0 ? (t = 0.5 * (d + a), y = 1 / t, c = i * y * e - s * y * s) : d < 0 ? c = 0.5 * (d - a) : (t = 0.5 * a, c = -0.5 * a), m > 0 ? u = m + a : u = m - a, Math.abs(u) > 2 * Math.abs(s) ? (y = -2 * s / u, r = 1 / Math.sqrt(1 + y * y), u = y * r) : Math.abs(s) === 0 ? (u = 1, r = 0) : (y = -0.5 * u / s, u = 1 / Math.sqrt(1 + y * y), r = y * u), m > 0 && (y = u, u = -r, r = y), { rt1: t, rt2: c, cs: u, sn: r }; } const A = [], U = {}, H = [], _ = new at(), Y = new at(), P = new at(), f = new at(), Z = new q(), D = new yt(), nt = new at(), rt = new DOMParser().parseFromString(C, "image/svg+xml"); return R(rt.documentElement, { fill: "#000", fillOpacity: 1, strokeOpacity: 1, strokeWidth: 1, strokeLineJoin: "miter", strokeLineCap: "butt", strokeMiterLimit: 4 }), { paths: A, xml: rt.documentElement }; } static createShapes(C) { const R = { ORIGIN: 0, DESTINATION: 1, BETWEEN: 2, LEFT: 3, RIGHT: 4, BEHIND: 5, BEYOND: 6 }, S = { loc: R.ORIGIN, t: 0 }; function M(b, p, w, j) { const h = b.x, T = p.x, I = w.x, N = j.x, O = b.y, E = p.y, L = w.y, W = j.y, v = (N - I) * (O - L) - (W - L) * (h - I), A = (T - h) * (O - L) - (E - O) * (h - I), U = (W - L) * (T - h) - (N - I) * (E - O), H = v / U, _ = A / U; if (U === 0 && v !== 0 || H <= 0 || H >= 1 || _ < 0 || _ > 1) return null; if (v === 0 && U === 0) { for (let Y = 0; Y < 2; Y++) if (J(Y === 0 ? w : j, b, p), S.loc == R.ORIGIN) { const P = Y === 0 ? w : j; return { x: P.x, y: P.y, t: S.t }; } else if (S.loc == R.BETWEEN) { const P = +(h + S.t * (T - h)).toPrecision(10), f = +(O + S.t * (E - O)).toPrecision(10); return { x: P, y: f, t: S.t }; } return null; } else { for (let f = 0; f < 2; f++) if (J(f === 0 ? w : j, b, p), S.loc == R.ORIGIN) { const Z = f === 0 ? w : j; return { x: Z.x, y: Z.y, t: S.t }; } const Y = +(h + H * (T - h)).toPrecision(10), P = +(O + H * (E - O)).toPrecision(10); return { x: Y, y: P, t: H }; } } function J(b, p, w) { const j = w.x - p.x, h = w.y - p.y, T = b.x - p.x, I = b.y - p.y, N = j * I - T * h; if (b.x === p.x && b.y === p.y) { S.loc = R.ORIGIN, S.t = 0; return; } if (b.x === w.x && b.y === w.y) { S.loc = R.DESTINATION, S.t = 1; return; } if (N < -Number.EPSILON) { S.loc = R.LEFT; return; } if (N > Number.EPSILON) { S.loc = R.RIGHT; return; } if (j * T < 0 || h * I < 0) { S.loc = R.BEHIND; return; } if (Math.sqrt(j * j + h * h) < Math.sqrt(T * T + I * I)) { S.loc = R.BEYOND; return; } let O; j !== 0 ? O = T / j : O = I / h, S.loc = R.BETWEEN, S.t = O; } function tt(b, p) { const w = [], j = []; for (let h = 1; h < b.length; h++) { const T = b[h - 1], I = b[h]; for (let N = 1; N < p.length; N++) { const O = p[N - 1], E = p[N], L = M(T, I, O, E); L !== null && w.find((W) => W.t <= L.t + Number.EPSILON && W.t >= L.t - Number.EPSILON) === void 0 && (w.push(L), j.push(new q(L.x, L.y))); } } return j; } function Q(b, p, w) { const j = new q(); p.getCenter(j); const h = []; return w.forEach((T) => { T.boundingBox.containsPoint(j) && tt(b, T.points).forEach((N) => { h.push({ identifier: T.identifier, isCW: T.isCW, point: N }); }); }), h.sort((T, I) => T.point.x - I.point.x), h; } function X(b, p, w, j, h) { (h == null || h === "") && (h = "nonzero"); const T = new q(); b.boundingBox.getCenter(T); const I = [new q(w, T.y), new q(j, T.y)], N = Q(I, b.boundingBox, p); N.sort((A, U) => A.point.x - U.point.x); const O = [], E = []; N.forEach((A) => { A.identifier === b.identifier ? O.push(A) : E.push(A); }); const L = O[0].point.x, W = []; let v = 0; for (; v < E.length && E[v].point.x < L; ) W.length > 0 && W[W.length - 1] === E[v].identifier ? W.pop() : W.push(E[v].identifier), v++; if (W.push(b.identifier), h === "evenodd") { const A = W.length % 2 === 0, U = W[W.length - 2]; return { identifier: b.identifier, isHole: A, for: U }; } else if (h === "nonzero") { let A = !0, U = null, H = null; for (let _ = 0; _ < W.length; _++) { const Y = W[_]; A ? (H = p[Y].isCW, A = !1, U = Y) : H !== p[Y].isCW && (H = p[Y].isCW, A = !0); } return { identifier: b.identifier, isHole: A, for: U }; } else console.warn('fill-rule: "' + h + '" is currently not implemented.'); } let $ = 999999999, V = -999999999, B = C.subPaths.map((b) => { const p = b.getPoints(); let w = -999999999, j = 999999999, h = -999999999, T = 999999999; for (let I = 0; I < p.length; I++) { const N = p[I]; N.y > w && (w = N.y), N.y < j && (j = N.y), N.x > h && (h = N.x), N.x < T && (T = N.x); } return V <= h && (V = h + 1), $ >= T && ($ = T - 1), { curves: b.curves, points: p, isCW: Pt.isClockWise(p), identifier: -1, boundingBox: new St(new q(T, j), new q(h, w)) }; }); B = B.filter((b) => b.points.length > 1); for (let b = 0; b < B.length; b++) B[b].identifier = b; const ot = B.map((b) => X(b, B, $, V, C.userData ? C.userData.style.fillRule : void 0)), z = []; return B.forEach((b) => { if (!ot[b.identifier].isHole) { const w = new Nt(); w.curves = b.curves, ot.filter((h) => h.isHole && h.for === b.identifier).forEach((h) => { const T = B[h.identifier], I = new mt(); I.curves = T.curves, w.holes.push(I); }), z.push(w); } }), z; } static getStrokeStyle(C, F, R, S, M) { return C = C !== void 0 ? C : 1, F = F !== void 0 ? F : "#000", R = R !== void 0 ? R : "miter", S = S !== void 0 ? S : "butt", M = M !== void 0 ? M : 4, { strokeColor: F, strokeWidth: C, strokeLineJoin: R, strokeLineCap: S, strokeMiterLimit: M }; } static pointsToStroke(C, F, R, S) { const M = [], J = [], tt = []; if (bt.pointsToStrokeWithBuffers(C, F, R, S, M, J, tt) === 0) return null; const Q = new Et(); return Q.setAttribute("position", new xt(M, 3)), Q.setAttribute("normal", new xt(J, 3)), Q.setAttribute("uv", new xt(tt, 2)), Q; } static pointsToStrokeWithBuffers(C, F, R, S, M, J, tt, Q) { const X = new q(), $ = new q(), V = new q(), B = new q(), ot = new q(), z = new q(), b = new q(), p = new q(), w = new q(), j = new q(), h = new q(), T = new q(), I = new q(), N = new q(), O = new q(), E = new q(), L = new q(); R = R !== void 0 ? R : 12, S = S !== void 0 ? S : 1e-3, Q = Q !== void 0 ? Q : 0, C = m(C); const W = C.length; if (W < 2) return 0; const v = C[0].equals(C[W - 1]); let A, U = C[0], H; const _ = F.strokeWidth / 2, Y = 1 / (W - 1); let P = 0, f, Z, D, nt, rt = !1, pt = 0, i = Q * 3, s = Q * 2; e(C[0], C[1], X).multiplyScalar(_), p.copy(C[0]).sub(X), w.copy(C[0]).add(X), j.copy(p), h.copy(w); for (let a = 1; a < W; a++) { A = C[a], a === W - 1 ? v ? H = C[1] : H = void 0 : H = C[a + 1]; const l = X; if (e(U, A, l), V.copy(l).multiplyScalar(_), T.copy(A).sub(V), I.copy(A).add(V), f = P + Y, Z = !1, H !== void 0) { e(A, H, $), V.copy($).multiplyScalar(_), N.copy(A).sub(V), O.copy(A).add(V), D = !0, V.subVectors(H, U), l.dot(V) < 0 && (D = !1), a === 1 && (rt = D), V.subVectors(H, A), V.normalize(); const x = Math.abs(l.dot(V)); if (x > Number.EPSILON) { const g = _ / x; V.multiplyScalar(-g), B.subVectors(A, U), ot.copy(B).setLength(g).add(V), E.copy(ot).negate(); const o = ot.length(), n = B.length(); B.divideScalar(n), z.subVectors(H, A); const k = z.length(); switch (z.divideScalar(k), B.dot(E) < n && z.dot(E) < k && (Z = !0), L.copy(ot).add(A), E.add(A), nt = !1, Z ? D ? (O.copy(E), I.copy(E)) : (N.copy(E), T.copy(E)) : u(), F.strokeLineJoin) { case "bevel": r(D, Z, f); break; case "round": y(D, Z), D ? c(A, T, N, f, 0) : c(A, O, I, f, 1); break; case "miter": case "miter-clip": default: const G = _ * F.strokeMiterLimit / o; if (G < 1) if (F.strokeLineJoin !== "miter-clip") { r(D, Z, f); break; } else y(D, Z), D ? (z.subVectors(L, T).multiplyScalar(G).add(T), b.subVectors(L, N).multiplyScalar(G).add(N), t(T, f, 0), t(z, f, 0), t(A, f, 0.5), t(A, f, 0.5), t(z, f, 0), t(b, f, 0), t(A, f, 0.5), t(b, f, 0), t(N, f, 0)) : (z.subVectors(L, I).multiplyScalar(G).add(I), b.subVectors(L, O).multiplyScalar(G).add(O), t(I, f, 1), t(z, f, 1), t(A, f, 0.5), t(A, f, 0.5), t(z, f, 1), t(b, f, 1), t(A, f, 0.5), t(b, f, 1), t(O, f, 1)); else Z ? (D ? (t(w, P, 1), t(p, P, 0), t(L, f, 0), t(w, P, 1), t(L, f, 0), t(E, f, 1)) : (t(w, P, 1), t(p, P, 0), t(L, f, 1), t(p, P, 0), t(E, f, 0), t(L, f, 1)), D ? N.copy(L) : O.copy(L)) : D ? (t(T, f, 0), t(L, f, 0), t(A, f, 0.5), t(A, f, 0.5), t(L, f, 0), t(N, f, 0)) : (t(I, f, 1), t(L, f, 1), t(A, f, 0.5), t(A, f, 0.5), t(L, f, 1), t(O, f, 1)), nt = !0; break; } } else u(); } else u(); !v && a === W - 1 && d(C[0], j, h, D, !0, P), P = f, U = A, p.copy(N), w.copy(O); } if (!v) d(A, T, I, D, !1, f); else if (Z && M) { let a = L, l = E; rt !== D && (a = E, l = L), D ? (nt || rt) && (l.toArray(M, 0 * 3), l.toArray(M, 3 * 3), nt && a.toArray(M, 1 * 3)) : (nt || !rt) && (l.toArray(M, 1 * 3), l.toArray(M, 3 * 3), nt && a.toArray(M, 0 * 3)); } return pt; function e(a, l, x) { return x.subVectors(l, a), x.set(-x.y, x.x).normalize(); } function t(a, l, x) { M && (M[i] = a.x, M[i + 1] = a.y, M[i + 2] = 0, J && (J[i] = 0, J[i + 1] = 0, J[i + 2] = 1), i += 3, tt && (tt[s] = l, tt[s + 1] = x, s += 2)), pt += 3; } function c(a, l, x, g, o) { X.copy(l).sub(a).normalize(), $.copy(x).sub(a).normalize(); let n = Math.PI; const k = X.dot($); Math.abs(k) < 1 && (n = Math.abs(Math.acos(k))), n /= R, V.copy(l); for (let G = 0, et = R - 1; G < et; G++) B.copy(V).rotateAround(a, n), t(V, g, o), t(B, g, o), t(a, g, 0.5), V.copy(B); t(B, g, o), t(x, g, o), t(a, g, 0.5); } function u() { t(w, P, 1), t(p, P, 0), t(T, f, 0), t(w, P, 1), t(T, f, 1), t(I, f, 0); } function r(a, l, x) { l ? a ? (t(w, P, 1), t(p, P, 0), t(T, f, 0), t(w, P, 1), t(T, f, 0), t(E, f, 1), t(T, x, 0), t(N, x, 0), t(E, x, 0.5)) : (t(w, P, 1), t(p, P, 0), t(I, f, 1), t(p, P, 0), t(E, f, 0), t(I, f, 1), t(I, x, 1), t(O, x, 0), t(E, x, 0.5)) : a ? (t(T, x, 0), t(N, x, 0), t(A, x, 0.5)) : (t(I, x, 1), t(O, x, 0), t(A, x, 0.5)); } function y(a, l) { l && (a ? (t(w, P, 1), t(p, P, 0), t(T, f, 0), t(w, P, 1), t(T, f, 0), t(E, f, 1), t(T, P, 0), t(A, f, 0.5), t(E, f, 1), t(A, f, 0.5), t(N, P, 0), t(E, f, 1)) : (t(w, P, 1), t(p, P, 0), t(I, f, 1), t(p, P, 0), t(E, f, 0), t(I, f, 1), t(I, P, 1), t(E, f, 0), t(A, f, 0.5), t(A, f, 0.5), t(E, f, 0), t(O, P, 1))); } function d(a, l, x, g, o, n) { switch (F.strokeLineCap) { case "round": o ? c(a, x, l, n, 0.5) : c(a, l, x, n, 0.5); break; case "square": if (o) X.subVectors(l, a), $.set(X.y, -X.x), V.addVectors(X, $).add(a), B.subVectors($, X).add(a), g ? (V.toArray(M, 1 * 3), B.toArray(M, 0 * 3), B.toArray(M, 3 * 3)) : (V.toArray(M, 1 * 3), V.toArray(M, 3 * 3), B.toArray(M, 0 * 3)); else { X.subVectors(x, a), $.set(X.y, -X.x), V.addVectors(X, $).add(a), B.subVectors($, X).add(a); const k = M.length; g ? (V.toArray(M, k - 1 * 3), B.toArray(M, k - 2 * 3), B.toArray(M, k - 4 * 3)) : (V.toArray(M, k - 2 * 3), B.toArray(M, k - 1 * 3), B.toArray(M, k - 4 * 3)); } break; } } function m(a) { let l = !1; for (let g = 1, o = a.length - 1; g < o; g++) if (a[g].distanceTo(a[g + 1]) < S) { l = !0; break; } if (!l) return a; const x = []; x.push(a[0]); for (let g = 1, o = a.length - 1; g < o; g++) a[g].distanceTo(a[g + 1]) >= S && x.push(a[g]); return x.push(a[a.length - 1]), x; } } } const Ot = /* @__PURE__ */ new Map(), Gt = new bt(), Wt = (lt) => Ct(Ot, lt, () => new Promise((C, F) => { const R = lt.startsWith("https://unpkg.com/"); R && Lt(), Gt.load(lt, (S) => { R && Rt(), C(S); }, jt(lt), F); })); export { Wt as default, Gt as loader };