import { watch as Me, reactive as Ti, watchEffect as xn, ref as Ya, computed as ch } from "vue";
var Ds = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function uh(s) {
  return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
}
var bn = {}, H = {}, rt = {}, V = {};
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s._registerNode = s.Konva = s.glob = void 0;
  const t = Math.PI / 180;
  function e() {
    return typeof window < "u" && ({}.toString.call(window) === "[object Window]" || {}.toString.call(window) === "[object global]");
  }
  s.glob = typeof Ds < "u" ? Ds : typeof window < "u" ? window : typeof WorkerGlobalScope < "u" ? self : {}, s.Konva = {
    _global: s.glob,
    version: "9.3.6",
    isBrowser: e(),
    isUnminified: /param/.test((function(n) {
    }).toString()),
    dblClickWindow: 400,
    getAngle(n) {
      return s.Konva.angleDeg ? n * t : n;
    },
    enableTrace: !1,
    pointerEventsEnabled: !0,
    autoDrawEnabled: !0,
    hitOnDragEnabled: !1,
    capturePointerEventsEnabled: !1,
    _mouseListenClick: !1,
    _touchListenClick: !1,
    _pointerListenClick: !1,
    _mouseInDblClickWindow: !1,
    _touchInDblClickWindow: !1,
    _pointerInDblClickWindow: !1,
    _mouseDblClickPointerId: null,
    _touchDblClickPointerId: null,
    _pointerDblClickPointerId: null,
    pixelRatio: typeof window < "u" && window.devicePixelRatio || 1,
    dragDistance: 3,
    angleDeg: !0,
    showWarnings: !0,
    dragButtons: [0, 1],
    isDragging() {
      return s.Konva.DD.isDragging;
    },
    isTransforming() {
      var n;
      return (n = s.Konva.Transformer) === null || n === void 0 ? void 0 : n.isTransforming();
    },
    isDragReady() {
      return !!s.Konva.DD.node;
    },
    releaseCanvasOnDestroy: !0,
    document: s.glob.document,
    _injectGlobal(n) {
      s.glob.Konva = n;
    }
  };
  const i = (n) => {
    s.Konva[n.prototype.getClassName()] = n;
  };
  s._registerNode = i, s.Konva._injectGlobal(s.Konva);
})(V);
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.Util = s.Transform = void 0;
  const t = V;
  class e {
    constructor(y = [1, 0, 0, 1, 0, 0]) {
      this.dirty = !1, this.m = y && y.slice() || [1, 0, 0, 1, 0, 0];
    }
    reset() {
      this.m[0] = 1, this.m[1] = 0, this.m[2] = 0, this.m[3] = 1, this.m[4] = 0, this.m[5] = 0;
    }
    copy() {
      return new e(this.m);
    }
    copyInto(y) {
      y.m[0] = this.m[0], y.m[1] = this.m[1], y.m[2] = this.m[2], y.m[3] = this.m[3], y.m[4] = this.m[4], y.m[5] = this.m[5];
    }
    point(y) {
      var _ = this.m;
      return {
        x: _[0] * y.x + _[2] * y.y + _[4],
        y: _[1] * y.x + _[3] * y.y + _[5]
      };
    }
    translate(y, _) {
      return this.m[4] += this.m[0] * y + this.m[2] * _, this.m[5] += this.m[1] * y + this.m[3] * _, this;
    }
    scale(y, _) {
      return this.m[0] *= y, this.m[1] *= y, this.m[2] *= _, this.m[3] *= _, this;
    }
    rotate(y) {
      var _ = Math.cos(y), b = Math.sin(y), C = this.m[0] * _ + this.m[2] * b, w = this.m[1] * _ + this.m[3] * b, E = this.m[0] * -b + this.m[2] * _, S = this.m[1] * -b + this.m[3] * _;
      return this.m[0] = C, this.m[1] = w, this.m[2] = E, this.m[3] = S, this;
    }
    getTranslation() {
      return {
        x: this.m[4],
        y: this.m[5]
      };
    }
    skew(y, _) {
      var b = this.m[0] + this.m[2] * _, C = this.m[1] + this.m[3] * _, w = this.m[2] + this.m[0] * y, E = this.m[3] + this.m[1] * y;
      return this.m[0] = b, this.m[1] = C, this.m[2] = w, this.m[3] = E, this;
    }
    multiply(y) {
      var _ = this.m[0] * y.m[0] + this.m[2] * y.m[1], b = this.m[1] * y.m[0] + this.m[3] * y.m[1], C = this.m[0] * y.m[2] + this.m[2] * y.m[3], w = this.m[1] * y.m[2] + this.m[3] * y.m[3], E = this.m[0] * y.m[4] + this.m[2] * y.m[5] + this.m[4], S = this.m[1] * y.m[4] + this.m[3] * y.m[5] + this.m[5];
      return this.m[0] = _, this.m[1] = b, this.m[2] = C, this.m[3] = w, this.m[4] = E, this.m[5] = S, this;
    }
    invert() {
      var y = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]), _ = this.m[3] * y, b = -this.m[1] * y, C = -this.m[2] * y, w = this.m[0] * y, E = y * (this.m[2] * this.m[5] - this.m[3] * this.m[4]), S = y * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
      return this.m[0] = _, this.m[1] = b, this.m[2] = C, this.m[3] = w, this.m[4] = E, this.m[5] = S, this;
    }
    getMatrix() {
      return this.m;
    }
    decompose() {
      var y = this.m[0], _ = this.m[1], b = this.m[2], C = this.m[3], w = this.m[4], E = this.m[5], S = y * C - _ * b;
      let P = {
        x: w,
        y: E,
        rotation: 0,
        scaleX: 0,
        scaleY: 0,
        skewX: 0,
        skewY: 0
      };
      if (y != 0 || _ != 0) {
        var k = Math.sqrt(y * y + _ * _);
        P.rotation = _ > 0 ? Math.acos(y / k) : -Math.acos(y / k), P.scaleX = k, P.scaleY = S / k, P.skewX = (y * b + _ * C) / S, P.skewY = 0;
      } else if (b != 0 || C != 0) {
        var F = Math.sqrt(b * b + C * C);
        P.rotation = Math.PI / 2 - (C > 0 ? Math.acos(-b / F) : -Math.acos(b / F)), P.scaleX = S / F, P.scaleY = F, P.skewX = 0, P.skewY = (y * b + _ * C) / S;
      }
      return P.rotation = s.Util._getRotation(P.rotation), P;
    }
  }
  s.Transform = e;
  var i = "[object Array]", n = "[object Number]", r = "[object String]", a = "[object Boolean]", o = Math.PI / 180, h = 180 / Math.PI, l = "#", A = "", u = "0", f = "Konva warning: ", d = "Konva error: ", c = "rgb(", p = {
    aliceblue: [240, 248, 255],
    antiquewhite: [250, 235, 215],
    aqua: [0, 255, 255],
    aquamarine: [127, 255, 212],
    azure: [240, 255, 255],
    beige: [245, 245, 220],
    bisque: [255, 228, 196],
    black: [0, 0, 0],
    blanchedalmond: [255, 235, 205],
    blue: [0, 0, 255],
    blueviolet: [138, 43, 226],
    brown: [165, 42, 42],
    burlywood: [222, 184, 135],
    cadetblue: [95, 158, 160],
    chartreuse: [127, 255, 0],
    chocolate: [210, 105, 30],
    coral: [255, 127, 80],
    cornflowerblue: [100, 149, 237],
    cornsilk: [255, 248, 220],
    crimson: [220, 20, 60],
    cyan: [0, 255, 255],
    darkblue: [0, 0, 139],
    darkcyan: [0, 139, 139],
    darkgoldenrod: [184, 132, 11],
    darkgray: [169, 169, 169],
    darkgreen: [0, 100, 0],
    darkgrey: [169, 169, 169],
    darkkhaki: [189, 183, 107],
    darkmagenta: [139, 0, 139],
    darkolivegreen: [85, 107, 47],
    darkorange: [255, 140, 0],
    darkorchid: [153, 50, 204],
    darkred: [139, 0, 0],
    darksalmon: [233, 150, 122],
    darkseagreen: [143, 188, 143],
    darkslateblue: [72, 61, 139],
    darkslategray: [47, 79, 79],
    darkslategrey: [47, 79, 79],
    darkturquoise: [0, 206, 209],
    darkviolet: [148, 0, 211],
    deeppink: [255, 20, 147],
    deepskyblue: [0, 191, 255],
    dimgray: [105, 105, 105],
    dimgrey: [105, 105, 105],
    dodgerblue: [30, 144, 255],
    firebrick: [178, 34, 34],
    floralwhite: [255, 255, 240],
    forestgreen: [34, 139, 34],
    fuchsia: [255, 0, 255],
    gainsboro: [220, 220, 220],
    ghostwhite: [248, 248, 255],
    gold: [255, 215, 0],
    goldenrod: [218, 165, 32],
    gray: [128, 128, 128],
    green: [0, 128, 0],
    greenyellow: [173, 255, 47],
    grey: [128, 128, 128],
    honeydew: [240, 255, 240],
    hotpink: [255, 105, 180],
    indianred: [205, 92, 92],
    indigo: [75, 0, 130],
    ivory: [255, 255, 240],
    khaki: [240, 230, 140],
    lavender: [230, 230, 250],
    lavenderblush: [255, 240, 245],
    lawngreen: [124, 252, 0],
    lemonchiffon: [255, 250, 205],
    lightblue: [173, 216, 230],
    lightcoral: [240, 128, 128],
    lightcyan: [224, 255, 255],
    lightgoldenrodyellow: [250, 250, 210],
    lightgray: [211, 211, 211],
    lightgreen: [144, 238, 144],
    lightgrey: [211, 211, 211],
    lightpink: [255, 182, 193],
    lightsalmon: [255, 160, 122],
    lightseagreen: [32, 178, 170],
    lightskyblue: [135, 206, 250],
    lightslategray: [119, 136, 153],
    lightslategrey: [119, 136, 153],
    lightsteelblue: [176, 196, 222],
    lightyellow: [255, 255, 224],
    lime: [0, 255, 0],
    limegreen: [50, 205, 50],
    linen: [250, 240, 230],
    magenta: [255, 0, 255],
    maroon: [128, 0, 0],
    mediumaquamarine: [102, 205, 170],
    mediumblue: [0, 0, 205],
    mediumorchid: [186, 85, 211],
    mediumpurple: [147, 112, 219],
    mediumseagreen: [60, 179, 113],
    mediumslateblue: [123, 104, 238],
    mediumspringgreen: [0, 250, 154],
    mediumturquoise: [72, 209, 204],
    mediumvioletred: [199, 21, 133],
    midnightblue: [25, 25, 112],
    mintcream: [245, 255, 250],
    mistyrose: [255, 228, 225],
    moccasin: [255, 228, 181],
    navajowhite: [255, 222, 173],
    navy: [0, 0, 128],
    oldlace: [253, 245, 230],
    olive: [128, 128, 0],
    olivedrab: [107, 142, 35],
    orange: [255, 165, 0],
    orangered: [255, 69, 0],
    orchid: [218, 112, 214],
    palegoldenrod: [238, 232, 170],
    palegreen: [152, 251, 152],
    paleturquoise: [175, 238, 238],
    palevioletred: [219, 112, 147],
    papayawhip: [255, 239, 213],
    peachpuff: [255, 218, 185],
    peru: [205, 133, 63],
    pink: [255, 192, 203],
    plum: [221, 160, 203],
    powderblue: [176, 224, 230],
    purple: [128, 0, 128],
    rebeccapurple: [102, 51, 153],
    red: [255, 0, 0],
    rosybrown: [188, 143, 143],
    royalblue: [65, 105, 225],
    saddlebrown: [139, 69, 19],
    salmon: [250, 128, 114],
    sandybrown: [244, 164, 96],
    seagreen: [46, 139, 87],
    seashell: [255, 245, 238],
    sienna: [160, 82, 45],
    silver: [192, 192, 192],
    skyblue: [135, 206, 235],
    slateblue: [106, 90, 205],
    slategray: [119, 128, 144],
    slategrey: [119, 128, 144],
    snow: [255, 255, 250],
    springgreen: [0, 255, 127],
    steelblue: [70, 130, 180],
    tan: [210, 180, 140],
    teal: [0, 128, 128],
    thistle: [216, 191, 216],
    transparent: [255, 255, 255, 0],
    tomato: [255, 99, 71],
    turquoise: [64, 224, 208],
    violet: [238, 130, 238],
    wheat: [245, 222, 179],
    white: [255, 255, 255],
    whitesmoke: [245, 245, 245],
    yellow: [255, 255, 0],
    yellowgreen: [154, 205, 5]
  }, m = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/, v = [];
  const x = typeof requestAnimationFrame < "u" && requestAnimationFrame || function(g) {
    setTimeout(g, 60);
  };
  s.Util = {
    _isElement(g) {
      return !!(g && g.nodeType == 1);
    },
    _isFunction(g) {
      return !!(g && g.constructor && g.call && g.apply);
    },
    _isPlainObject(g) {
      return !!g && g.constructor === Object;
    },
    _isArray(g) {
      return Object.prototype.toString.call(g) === i;
    },
    _isNumber(g) {
      return Object.prototype.toString.call(g) === n && !isNaN(g) && isFinite(g);
    },
    _isString(g) {
      return Object.prototype.toString.call(g) === r;
    },
    _isBoolean(g) {
      return Object.prototype.toString.call(g) === a;
    },
    isObject(g) {
      return g instanceof Object;
    },
    isValidSelector(g) {
      if (typeof g != "string")
        return !1;
      var y = g[0];
      return y === "#" || y === "." || y === y.toUpperCase();
    },
    _sign(g) {
      return g === 0 || g > 0 ? 1 : -1;
    },
    requestAnimFrame(g) {
      v.push(g), v.length === 1 && x(function() {
        const y = v;
        v = [], y.forEach(function(_) {
          _();
        });
      });
    },
    createCanvasElement() {
      var g = document.createElement("canvas");
      try {
        g.style = g.style || {};
      } catch {
      }
      return g;
    },
    createImageElement() {
      return document.createElement("img");
    },
    _isInDocument(g) {
      for (; g = g.parentNode; )
        if (g == document)
          return !0;
      return !1;
    },
    _urlToImage(g, y) {
      var _ = s.Util.createImageElement();
      _.onload = function() {
        y(_);
      }, _.src = g;
    },
    _rgbToHex(g, y, _) {
      return ((1 << 24) + (g << 16) + (y << 8) + _).toString(16).slice(1);
    },
    _hexToRgb(g) {
      g = g.replace(l, A);
      var y = parseInt(g, 16);
      return {
        r: y >> 16 & 255,
        g: y >> 8 & 255,
        b: y & 255
      };
    },
    getRandomColor() {
      for (var g = (Math.random() * 16777215 << 0).toString(16); g.length < 6; )
        g = u + g;
      return l + g;
    },
    getRGB(g) {
      var y;
      return g in p ? (y = p[g], {
        r: y[0],
        g: y[1],
        b: y[2]
      }) : g[0] === l ? this._hexToRgb(g.substring(1)) : g.substr(0, 4) === c ? (y = m.exec(g.replace(/ /g, "")), {
        r: parseInt(y[1], 10),
        g: parseInt(y[2], 10),
        b: parseInt(y[3], 10)
      }) : {
        r: 0,
        g: 0,
        b: 0
      };
    },
    colorToRGBA(g) {
      return g = g || "black", s.Util._namedColorToRBA(g) || s.Util._hex3ColorToRGBA(g) || s.Util._hex4ColorToRGBA(g) || s.Util._hex6ColorToRGBA(g) || s.Util._hex8ColorToRGBA(g) || s.Util._rgbColorToRGBA(g) || s.Util._rgbaColorToRGBA(g) || s.Util._hslColorToRGBA(g);
    },
    _namedColorToRBA(g) {
      var y = p[g.toLowerCase()];
      return y ? {
        r: y[0],
        g: y[1],
        b: y[2],
        a: 1
      } : null;
    },
    _rgbColorToRGBA(g) {
      if (g.indexOf("rgb(") === 0) {
        g = g.match(/rgb\(([^)]+)\)/)[1];
        var y = g.split(/ *, */).map(Number);
        return {
          r: y[0],
          g: y[1],
          b: y[2],
          a: 1
        };
      }
    },
    _rgbaColorToRGBA(g) {
      if (g.indexOf("rgba(") === 0) {
        g = g.match(/rgba\(([^)]+)\)/)[1];
        var y = g.split(/ *, */).map((_, b) => _.slice(-1) === "%" ? b === 3 ? parseInt(_) / 100 : parseInt(_) / 100 * 255 : Number(_));
        return {
          r: y[0],
          g: y[1],
          b: y[2],
          a: y[3]
        };
      }
    },
    _hex8ColorToRGBA(g) {
      if (g[0] === "#" && g.length === 9)
        return {
          r: parseInt(g.slice(1, 3), 16),
          g: parseInt(g.slice(3, 5), 16),
          b: parseInt(g.slice(5, 7), 16),
          a: parseInt(g.slice(7, 9), 16) / 255
        };
    },
    _hex6ColorToRGBA(g) {
      if (g[0] === "#" && g.length === 7)
        return {
          r: parseInt(g.slice(1, 3), 16),
          g: parseInt(g.slice(3, 5), 16),
          b: parseInt(g.slice(5, 7), 16),
          a: 1
        };
    },
    _hex4ColorToRGBA(g) {
      if (g[0] === "#" && g.length === 5)
        return {
          r: parseInt(g[1] + g[1], 16),
          g: parseInt(g[2] + g[2], 16),
          b: parseInt(g[3] + g[3], 16),
          a: parseInt(g[4] + g[4], 16) / 255
        };
    },
    _hex3ColorToRGBA(g) {
      if (g[0] === "#" && g.length === 4)
        return {
          r: parseInt(g[1] + g[1], 16),
          g: parseInt(g[2] + g[2], 16),
          b: parseInt(g[3] + g[3], 16),
          a: 1
        };
    },
    _hslColorToRGBA(g) {
      if (/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(g)) {
        const [y, ..._] = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(g), b = Number(_[0]) / 360, C = Number(_[1]) / 100, w = Number(_[2]) / 100;
        let E, S, P;
        if (C === 0)
          return P = w * 255, {
            r: Math.round(P),
            g: Math.round(P),
            b: Math.round(P),
            a: 1
          };
        w < 0.5 ? E = w * (1 + C) : E = w + C - w * C;
        const k = 2 * w - E, F = [0, 0, 0];
        for (let I = 0; I < 3; I++)
          S = b + 1 / 3 * -(I - 1), S < 0 && S++, S > 1 && S--, 6 * S < 1 ? P = k + (E - k) * 6 * S : 2 * S < 1 ? P = E : 3 * S < 2 ? P = k + (E - k) * (2 / 3 - S) * 6 : P = k, F[I] = P * 255;
        return {
          r: Math.round(F[0]),
          g: Math.round(F[1]),
          b: Math.round(F[2]),
          a: 1
        };
      }
    },
    haveIntersection(g, y) {
      return !(y.x > g.x + g.width || y.x + y.width < g.x || y.y > g.y + g.height || y.y + y.height < g.y);
    },
    cloneObject(g) {
      var y = {};
      for (var _ in g)
        this._isPlainObject(g[_]) ? y[_] = this.cloneObject(g[_]) : this._isArray(g[_]) ? y[_] = this.cloneArray(g[_]) : y[_] = g[_];
      return y;
    },
    cloneArray(g) {
      return g.slice(0);
    },
    degToRad(g) {
      return g * o;
    },
    radToDeg(g) {
      return g * h;
    },
    _degToRad(g) {
      return s.Util.warn("Util._degToRad is removed. Please use public Util.degToRad instead."), s.Util.degToRad(g);
    },
    _radToDeg(g) {
      return s.Util.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."), s.Util.radToDeg(g);
    },
    _getRotation(g) {
      return t.Konva.angleDeg ? s.Util.radToDeg(g) : g;
    },
    _capitalize(g) {
      return g.charAt(0).toUpperCase() + g.slice(1);
    },
    throw(g) {
      throw new Error(d + g);
    },
    error(g) {
      console.error(d + g);
    },
    warn(g) {
      t.Konva.showWarnings && console.warn(f + g);
    },
    each(g, y) {
      for (var _ in g)
        y(_, g[_]);
    },
    _inRange(g, y, _) {
      return y <= g && g < _;
    },
    _getProjectionToSegment(g, y, _, b, C, w) {
      var E, S, P, k = (g - _) * (g - _) + (y - b) * (y - b);
      if (k == 0)
        E = g, S = y, P = (C - _) * (C - _) + (w - b) * (w - b);
      else {
        var F = ((C - g) * (_ - g) + (w - y) * (b - y)) / k;
        F < 0 ? (E = g, S = y, P = (g - C) * (g - C) + (y - w) * (y - w)) : F > 1 ? (E = _, S = b, P = (_ - C) * (_ - C) + (b - w) * (b - w)) : (E = g + F * (_ - g), S = y + F * (b - y), P = (E - C) * (E - C) + (S - w) * (S - w));
      }
      return [E, S, P];
    },
    _getProjectionToLine(g, y, _) {
      var b = s.Util.cloneObject(g), C = Number.MAX_VALUE;
      return y.forEach(function(w, E) {
        if (!(!_ && E === y.length - 1)) {
          var S = y[(E + 1) % y.length], P = s.Util._getProjectionToSegment(w.x, w.y, S.x, S.y, g.x, g.y), k = P[0], F = P[1], I = P[2];
          I < C && (b.x = k, b.y = F, C = I);
        }
      }), b;
    },
    _prepareArrayForTween(g, y, _) {
      var b, C = [], w = [];
      if (g.length > y.length) {
        var E = y;
        y = g, g = E;
      }
      for (b = 0; b < g.length; b += 2)
        C.push({
          x: g[b],
          y: g[b + 1]
        });
      for (b = 0; b < y.length; b += 2)
        w.push({
          x: y[b],
          y: y[b + 1]
        });
      var S = [];
      return w.forEach(function(P) {
        var k = s.Util._getProjectionToLine(P, C, _);
        S.push(k.x), S.push(k.y);
      }), S;
    },
    _prepareToStringify(g) {
      var y;
      g.visitedByCircularReferenceRemoval = !0;
      for (var _ in g)
        if (g.hasOwnProperty(_) && g[_] && typeof g[_] == "object") {
          if (y = Object.getOwnPropertyDescriptor(g, _), g[_].visitedByCircularReferenceRemoval || s.Util._isElement(g[_]))
            if (y.configurable)
              delete g[_];
            else
              return null;
          else if (s.Util._prepareToStringify(g[_]) === null)
            if (y.configurable)
              delete g[_];
            else
              return null;
        }
      return delete g.visitedByCircularReferenceRemoval, g;
    },
    _assign(g, y) {
      for (var _ in y)
        g[_] = y[_];
      return g;
    },
    _getFirstPointerId(g) {
      return g.touches ? g.changedTouches[0].identifier : g.pointerId || 999;
    },
    releaseCanvas(...g) {
      t.Konva.releaseCanvasOnDestroy && g.forEach((y) => {
        y.width = 0, y.height = 0;
      });
    },
    drawRoundedRectPath(g, y, _, b) {
      let C = 0, w = 0, E = 0, S = 0;
      typeof b == "number" ? C = w = E = S = Math.min(b, y / 2, _ / 2) : (C = Math.min(b[0] || 0, y / 2, _ / 2), w = Math.min(b[1] || 0, y / 2, _ / 2), S = Math.min(b[2] || 0, y / 2, _ / 2), E = Math.min(b[3] || 0, y / 2, _ / 2)), g.moveTo(C, 0), g.lineTo(y - w, 0), g.arc(y - w, w, w, Math.PI * 3 / 2, 0, !1), g.lineTo(y, _ - S), g.arc(y - S, _ - S, S, 0, Math.PI / 2, !1), g.lineTo(E, _), g.arc(E, _ - E, E, Math.PI / 2, Math.PI, !1), g.lineTo(0, C), g.arc(C, C, C, Math.PI, Math.PI * 3 / 2, !1);
    }
  };
})(rt);
var N = {};
Object.defineProperty(N, "__esModule", { value: !0 });
N.getComponentValidator = N.getBooleanValidator = N.getNumberArrayValidator = N.getFunctionValidator = N.getStringOrGradientValidator = N.getStringValidator = N.getNumberOrAutoValidator = N.getNumberOrArrayOfNumbersValidator = N.getNumberValidator = N.alphaComponent = N.RGBComponent = void 0;
const Qt = V, ht = rt;
function Kt(s) {
  return ht.Util._isString(s) ? '"' + s + '"' : Object.prototype.toString.call(s) === "[object Number]" || ht.Util._isBoolean(s) ? s : Object.prototype.toString.call(s);
}
function fh(s) {
  return s > 255 ? 255 : s < 0 ? 0 : Math.round(s);
}
N.RGBComponent = fh;
function gh(s) {
  return s > 1 ? 1 : s < 1e-4 ? 1e-4 : s;
}
N.alphaComponent = gh;
function ph() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      return ht.Util._isNumber(s) || ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a number.'), s;
    };
}
N.getNumberValidator = ph;
function yh(s) {
  if (Qt.Konva.isUnminified)
    return function(t, e) {
      let i = ht.Util._isNumber(t), n = ht.Util._isArray(t) && t.length == s;
      return !i && !n && ht.Util.warn(Kt(t) + ' is a not valid value for "' + e + '" attribute. The value should be a number or Array<number>(' + s + ")"), t;
    };
}
N.getNumberOrArrayOfNumbersValidator = yh;
function mh() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      var e = ht.Util._isNumber(s), i = s === "auto";
      return e || i || ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a number or "auto".'), s;
    };
}
N.getNumberOrAutoValidator = mh;
function vh() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      return ht.Util._isString(s) || ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a string.'), s;
    };
}
N.getStringValidator = vh;
function _h() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      const e = ht.Util._isString(s), i = Object.prototype.toString.call(s) === "[object CanvasGradient]" || s && s.addColorStop;
      return e || i || ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a string or a native gradient.'), s;
    };
}
N.getStringOrGradientValidator = _h;
function xh() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      return ht.Util._isFunction(s) || ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a function.'), s;
    };
}
N.getFunctionValidator = xh;
function bh() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      const e = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
      return e && s instanceof e || (ht.Util._isArray(s) ? s.forEach(function(i) {
        ht.Util._isNumber(i) || ht.Util.warn('"' + t + '" attribute has non numeric element ' + i + ". Make sure that all elements are numbers.");
      }) : ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a array of numbers.')), s;
    };
}
N.getNumberArrayValidator = bh;
function wh() {
  if (Qt.Konva.isUnminified)
    return function(s, t) {
      var e = s === !0 || s === !1;
      return e || ht.Util.warn(Kt(s) + ' is a not valid value for "' + t + '" attribute. The value should be a boolean.'), s;
    };
}
N.getBooleanValidator = wh;
function Sh(s) {
  if (Qt.Konva.isUnminified)
    return function(t, e) {
      return t == null || ht.Util.isObject(t) || ht.Util.warn(Kt(t) + ' is a not valid value for "' + e + '" attribute. The value should be an object with properties ' + s), t;
    };
}
N.getComponentValidator = Sh;
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.Factory = void 0;
  const t = rt, e = N;
  var i = "get", n = "set";
  s.Factory = {
    addGetterSetter(r, a, o, h, l) {
      s.Factory.addGetter(r, a, o), s.Factory.addSetter(r, a, h, l), s.Factory.addOverloadedGetterSetter(r, a);
    },
    addGetter(r, a, o) {
      var h = i + t.Util._capitalize(a);
      r.prototype[h] = r.prototype[h] || function() {
        var l = this.attrs[a];
        return l === void 0 ? o : l;
      };
    },
    addSetter(r, a, o, h) {
      var l = n + t.Util._capitalize(a);
      r.prototype[l] || s.Factory.overWriteSetter(r, a, o, h);
    },
    overWriteSetter(r, a, o, h) {
      var l = n + t.Util._capitalize(a);
      r.prototype[l] = function(A) {
        return o && A !== void 0 && A !== null && (A = o.call(this, A, a)), this._setAttr(a, A), h && h.call(this), this;
      };
    },
    addComponentsGetterSetter(r, a, o, h, l) {
      var A = o.length, u = t.Util._capitalize, f = i + u(a), d = n + u(a), c, p;
      r.prototype[f] = function() {
        var v = {};
        for (c = 0; c < A; c++)
          p = o[c], v[p] = this.getAttr(a + u(p));
        return v;
      };
      var m = (0, e.getComponentValidator)(o);
      r.prototype[d] = function(v) {
        var x = this.attrs[a], g;
        h && (v = h.call(this, v)), m && m.call(this, v, a);
        for (g in v)
          v.hasOwnProperty(g) && this._setAttr(a + u(g), v[g]);
        return v || o.forEach((y) => {
          this._setAttr(a + u(y), void 0);
        }), this._fireChangeEvent(a, x, v), l && l.call(this), this;
      }, s.Factory.addOverloadedGetterSetter(r, a);
    },
    addOverloadedGetterSetter(r, a) {
      var o = t.Util._capitalize(a), h = n + o, l = i + o;
      r.prototype[a] = function() {
        return arguments.length ? (this[h](arguments[0]), this) : this[l]();
      };
    },
    addDeprecatedGetterSetter(r, a, o, h) {
      t.Util.error("Adding deprecated " + a);
      var l = i + t.Util._capitalize(a), A = a + " property is deprecated and will be removed soon. Look at Konva change log for more information.";
      r.prototype[l] = function() {
        t.Util.error(A);
        var u = this.attrs[a];
        return u === void 0 ? o : u;
      }, s.Factory.addSetter(r, a, h, function() {
        t.Util.error(A);
      }), s.Factory.addOverloadedGetterSetter(r, a);
    },
    backCompat(r, a) {
      t.Util.each(a, function(o, h) {
        var l = r.prototype[h], A = i + t.Util._capitalize(o), u = n + t.Util._capitalize(o);
        function f() {
          l.apply(this, arguments), t.Util.error('"' + o + '" method is deprecated and will be removed soon. Use ""' + h + '" instead.');
        }
        r.prototype[o] = f, r.prototype[A] = f, r.prototype[u] = f;
      });
    },
    afterSetFilter() {
      this._filterUpToDate = !1;
    }
  };
})(H);
var ft = {}, st = {}, It = {}, Wt = {};
Object.defineProperty(Wt, "__esModule", { value: !0 });
Wt.HitContext = Wt.SceneContext = Wt.Context = void 0;
const Xa = rt, Ch = V;
function Mh(s) {
  var t = [], e = s.length, i = Xa.Util, n, r;
  for (n = 0; n < e; n++)
    r = s[n], i._isNumber(r) ? r = Math.round(r * 1e3) / 1e3 : i._isString(r) || (r = r + ""), t.push(r);
  return t;
}
var Ts = ",", Ph = "(", Eh = ")", Fh = "([", kh = "])", Dh = ";", Th = "()", Ih = "=", Is = [
  "arc",
  "arcTo",
  "beginPath",
  "bezierCurveTo",
  "clearRect",
  "clip",
  "closePath",
  "createLinearGradient",
  "createPattern",
  "createRadialGradient",
  "drawImage",
  "ellipse",
  "fill",
  "fillText",
  "getImageData",
  "createImageData",
  "lineTo",
  "moveTo",
  "putImageData",
  "quadraticCurveTo",
  "rect",
  "roundRect",
  "restore",
  "rotate",
  "save",
  "scale",
  "setLineDash",
  "setTransform",
  "stroke",
  "strokeText",
  "transform",
  "translate"
], Rh = [
  "fillStyle",
  "strokeStyle",
  "shadowColor",
  "shadowBlur",
  "shadowOffsetX",
  "shadowOffsetY",
  "letterSpacing",
  "lineCap",
  "lineDashOffset",
  "lineJoin",
  "lineWidth",
  "miterLimit",
  "direction",
  "font",
  "textAlign",
  "textBaseline",
  "globalAlpha",
  "globalCompositeOperation",
  "imageSmoothingEnabled"
];
const Lh = 100;
class wn {
  constructor(t) {
    this.canvas = t, Ch.Konva.enableTrace && (this.traceArr = [], this._enableTrace());
  }
  fillShape(t) {
    t.fillEnabled() && this._fill(t);
  }
  _fill(t) {
  }
  strokeShape(t) {
    t.hasStroke() && this._stroke(t);
  }
  _stroke(t) {
  }
  fillStrokeShape(t) {
    t.attrs.fillAfterStrokeEnabled ? (this.strokeShape(t), this.fillShape(t)) : (this.fillShape(t), this.strokeShape(t));
  }
  getTrace(t, e) {
    var i = this.traceArr, n = i.length, r = "", a, o, h, l;
    for (a = 0; a < n; a++)
      o = i[a], h = o.method, h ? (l = o.args, r += h, t ? r += Th : Xa.Util._isArray(l[0]) ? r += Fh + l.join(Ts) + kh : (e && (l = l.map((A) => typeof A == "number" ? Math.floor(A) : A)), r += Ph + l.join(Ts) + Eh)) : (r += o.property, t || (r += Ih + o.val)), r += Dh;
    return r;
  }
  clearTrace() {
    this.traceArr = [];
  }
  _trace(t) {
    var e = this.traceArr, i;
    e.push(t), i = e.length, i >= Lh && e.shift();
  }
  reset() {
    var t = this.getCanvas().getPixelRatio();
    this.setTransform(1 * t, 0, 0, 1 * t, 0, 0);
  }
  getCanvas() {
    return this.canvas;
  }
  clear(t) {
    var e = this.getCanvas();
    t ? this.clearRect(t.x || 0, t.y || 0, t.width || 0, t.height || 0) : this.clearRect(0, 0, e.getWidth() / e.pixelRatio, e.getHeight() / e.pixelRatio);
  }
  _applyLineCap(t) {
    const e = t.attrs.lineCap;
    e && this.setAttr("lineCap", e);
  }
  _applyOpacity(t) {
    var e = t.getAbsoluteOpacity();
    e !== 1 && this.setAttr("globalAlpha", e);
  }
  _applyLineJoin(t) {
    const e = t.attrs.lineJoin;
    e && this.setAttr("lineJoin", e);
  }
  setAttr(t, e) {
    this._context[t] = e;
  }
  arc(t, e, i, n, r, a) {
    this._context.arc(t, e, i, n, r, a);
  }
  arcTo(t, e, i, n, r) {
    this._context.arcTo(t, e, i, n, r);
  }
  beginPath() {
    this._context.beginPath();
  }
  bezierCurveTo(t, e, i, n, r, a) {
    this._context.bezierCurveTo(t, e, i, n, r, a);
  }
  clearRect(t, e, i, n) {
    this._context.clearRect(t, e, i, n);
  }
  clip(...t) {
    this._context.clip.apply(this._context, t);
  }
  closePath() {
    this._context.closePath();
  }
  createImageData(t, e) {
    var i = arguments;
    if (i.length === 2)
      return this._context.createImageData(t, e);
    if (i.length === 1)
      return this._context.createImageData(t);
  }
  createLinearGradient(t, e, i, n) {
    return this._context.createLinearGradient(t, e, i, n);
  }
  createPattern(t, e) {
    return this._context.createPattern(t, e);
  }
  createRadialGradient(t, e, i, n, r, a) {
    return this._context.createRadialGradient(t, e, i, n, r, a);
  }
  drawImage(t, e, i, n, r, a, o, h, l) {
    var A = arguments, u = this._context;
    A.length === 3 ? u.drawImage(t, e, i) : A.length === 5 ? u.drawImage(t, e, i, n, r) : A.length === 9 && u.drawImage(t, e, i, n, r, a, o, h, l);
  }
  ellipse(t, e, i, n, r, a, o, h) {
    this._context.ellipse(t, e, i, n, r, a, o, h);
  }
  isPointInPath(t, e, i, n) {
    return i ? this._context.isPointInPath(i, t, e, n) : this._context.isPointInPath(t, e, n);
  }
  fill(...t) {
    this._context.fill.apply(this._context, t);
  }
  fillRect(t, e, i, n) {
    this._context.fillRect(t, e, i, n);
  }
  strokeRect(t, e, i, n) {
    this._context.strokeRect(t, e, i, n);
  }
  fillText(t, e, i, n) {
    n ? this._context.fillText(t, e, i, n) : this._context.fillText(t, e, i);
  }
  measureText(t) {
    return this._context.measureText(t);
  }
  getImageData(t, e, i, n) {
    return this._context.getImageData(t, e, i, n);
  }
  lineTo(t, e) {
    this._context.lineTo(t, e);
  }
  moveTo(t, e) {
    this._context.moveTo(t, e);
  }
  rect(t, e, i, n) {
    this._context.rect(t, e, i, n);
  }
  roundRect(t, e, i, n, r) {
    this._context.roundRect(t, e, i, n, r);
  }
  putImageData(t, e, i) {
    this._context.putImageData(t, e, i);
  }
  quadraticCurveTo(t, e, i, n) {
    this._context.quadraticCurveTo(t, e, i, n);
  }
  restore() {
    this._context.restore();
  }
  rotate(t) {
    this._context.rotate(t);
  }
  save() {
    this._context.save();
  }
  scale(t, e) {
    this._context.scale(t, e);
  }
  setLineDash(t) {
    this._context.setLineDash ? this._context.setLineDash(t) : "mozDash" in this._context ? this._context.mozDash = t : "webkitLineDash" in this._context && (this._context.webkitLineDash = t);
  }
  getLineDash() {
    return this._context.getLineDash();
  }
  setTransform(t, e, i, n, r, a) {
    this._context.setTransform(t, e, i, n, r, a);
  }
  stroke(t) {
    t ? this._context.stroke(t) : this._context.stroke();
  }
  strokeText(t, e, i, n) {
    this._context.strokeText(t, e, i, n);
  }
  transform(t, e, i, n, r, a) {
    this._context.transform(t, e, i, n, r, a);
  }
  translate(t, e) {
    this._context.translate(t, e);
  }
  _enableTrace() {
    var t = this, e = Is.length, i = this.setAttr, n, r, a = function(o) {
      var h = t[o], l;
      t[o] = function() {
        return r = Mh(Array.prototype.slice.call(arguments, 0)), l = h.apply(t, arguments), t._trace({
          method: o,
          args: r
        }), l;
      };
    };
    for (n = 0; n < e; n++)
      a(Is[n]);
    t.setAttr = function() {
      i.apply(t, arguments);
      var o = arguments[0], h = arguments[1];
      (o === "shadowOffsetX" || o === "shadowOffsetY" || o === "shadowBlur") && (h = h / this.canvas.getPixelRatio()), t._trace({
        property: o,
        val: h
      });
    };
  }
  _applyGlobalCompositeOperation(t) {
    const e = t.attrs.globalCompositeOperation;
    var i = !e || e === "source-over";
    i || this.setAttr("globalCompositeOperation", e);
  }
}
Wt.Context = wn;
Rh.forEach(function(s) {
  Object.defineProperty(wn.prototype, s, {
    get() {
      return this._context[s];
    },
    set(t) {
      this._context[s] = t;
    }
  });
});
class Oh extends wn {
  constructor(t, { willReadFrequently: e = !1 } = {}) {
    super(t), this._context = t._canvas.getContext("2d", {
      willReadFrequently: e
    });
  }
  _fillColor(t) {
    var e = t.fill();
    this.setAttr("fillStyle", e), t._fillFunc(this);
  }
  _fillPattern(t) {
    this.setAttr("fillStyle", t._getFillPattern()), t._fillFunc(this);
  }
  _fillLinearGradient(t) {
    var e = t._getLinearGradient();
    e && (this.setAttr("fillStyle", e), t._fillFunc(this));
  }
  _fillRadialGradient(t) {
    const e = t._getRadialGradient();
    e && (this.setAttr("fillStyle", e), t._fillFunc(this));
  }
  _fill(t) {
    const e = t.fill(), i = t.getFillPriority();
    if (e && i === "color") {
      this._fillColor(t);
      return;
    }
    const n = t.getFillPatternImage();
    if (n && i === "pattern") {
      this._fillPattern(t);
      return;
    }
    const r = t.getFillLinearGradientColorStops();
    if (r && i === "linear-gradient") {
      this._fillLinearGradient(t);
      return;
    }
    const a = t.getFillRadialGradientColorStops();
    if (a && i === "radial-gradient") {
      this._fillRadialGradient(t);
      return;
    }
    e ? this._fillColor(t) : n ? this._fillPattern(t) : r ? this._fillLinearGradient(t) : a && this._fillRadialGradient(t);
  }
  _strokeLinearGradient(t) {
    const e = t.getStrokeLinearGradientStartPoint(), i = t.getStrokeLinearGradientEndPoint(), n = t.getStrokeLinearGradientColorStops(), r = this.createLinearGradient(e.x, e.y, i.x, i.y);
    if (n) {
      for (var a = 0; a < n.length; a += 2)
        r.addColorStop(n[a], n[a + 1]);
      this.setAttr("strokeStyle", r);
    }
  }
  _stroke(t) {
    var e = t.dash(), i = t.getStrokeScaleEnabled();
    if (t.hasStroke()) {
      if (!i) {
        this.save();
        var n = this.getCanvas().getPixelRatio();
        this.setTransform(n, 0, 0, n, 0, 0);
      }
      this._applyLineCap(t), e && t.dashEnabled() && (this.setLineDash(e), this.setAttr("lineDashOffset", t.dashOffset())), this.setAttr("lineWidth", t.strokeWidth()), t.getShadowForStrokeEnabled() || this.setAttr("shadowColor", "rgba(0,0,0,0)");
      var r = t.getStrokeLinearGradientColorStops();
      r ? this._strokeLinearGradient(t) : this.setAttr("strokeStyle", t.stroke()), t._strokeFunc(this), i || this.restore();
    }
  }
  _applyShadow(t) {
    var e, i, n, r = (e = t.getShadowRGBA()) !== null && e !== void 0 ? e : "black", a = (i = t.getShadowBlur()) !== null && i !== void 0 ? i : 5, o = (n = t.getShadowOffset()) !== null && n !== void 0 ? n : {
      x: 0,
      y: 0
    }, h = t.getAbsoluteScale(), l = this.canvas.getPixelRatio(), A = h.x * l, u = h.y * l;
    this.setAttr("shadowColor", r), this.setAttr("shadowBlur", a * Math.min(Math.abs(A), Math.abs(u))), this.setAttr("shadowOffsetX", o.x * A), this.setAttr("shadowOffsetY", o.y * u);
  }
}
Wt.SceneContext = Oh;
class Nh extends wn {
  constructor(t) {
    super(t), this._context = t._canvas.getContext("2d", {
      willReadFrequently: !0
    });
  }
  _fill(t) {
    this.save(), this.setAttr("fillStyle", t.colorKey), t._fillFuncHit(this), this.restore();
  }
  strokeShape(t) {
    t.hasHitStroke() && this._stroke(t);
  }
  _stroke(t) {
    if (t.hasHitStroke()) {
      const r = t.getStrokeScaleEnabled();
      if (!r) {
        this.save();
        var e = this.getCanvas().getPixelRatio();
        this.setTransform(e, 0, 0, e, 0, 0);
      }
      this._applyLineCap(t);
      var i = t.hitStrokeWidth(), n = i === "auto" ? t.strokeWidth() : i;
      this.setAttr("lineWidth", n), this.setAttr("strokeStyle", t.colorKey), t._strokeFuncHit(this), r || this.restore();
    }
  }
}
Wt.HitContext = Nh;
Object.defineProperty(It, "__esModule", { value: !0 });
It.HitCanvas = It.SceneCanvas = It.Canvas = void 0;
const sn = rt, ja = Wt, qa = V, Gh = H, Bh = N;
var Ui;
function zh() {
  if (Ui)
    return Ui;
  var s = sn.Util.createCanvasElement(), t = s.getContext("2d");
  return Ui = function() {
    var e = qa.Konva._global.devicePixelRatio || 1, i = t.webkitBackingStorePixelRatio || t.mozBackingStorePixelRatio || t.msBackingStorePixelRatio || t.oBackingStorePixelRatio || t.backingStorePixelRatio || 1;
    return e / i;
  }(), sn.Util.releaseCanvas(s), Ui;
}
class Sn {
  constructor(t) {
    this.pixelRatio = 1, this.width = 0, this.height = 0, this.isCache = !1;
    var e = t || {}, i = e.pixelRatio || qa.Konva.pixelRatio || zh();
    this.pixelRatio = i, this._canvas = sn.Util.createCanvasElement(), this._canvas.style.padding = "0", this._canvas.style.margin = "0", this._canvas.style.border = "0", this._canvas.style.background = "transparent", this._canvas.style.position = "absolute", this._canvas.style.top = "0", this._canvas.style.left = "0";
  }
  getContext() {
    return this.context;
  }
  getPixelRatio() {
    return this.pixelRatio;
  }
  setPixelRatio(t) {
    var e = this.pixelRatio;
    this.pixelRatio = t, this.setSize(this.getWidth() / e, this.getHeight() / e);
  }
  setWidth(t) {
    this.width = this._canvas.width = t * this.pixelRatio, this._canvas.style.width = t + "px";
    var e = this.pixelRatio, i = this.getContext()._context;
    i.scale(e, e);
  }
  setHeight(t) {
    this.height = this._canvas.height = t * this.pixelRatio, this._canvas.style.height = t + "px";
    var e = this.pixelRatio, i = this.getContext()._context;
    i.scale(e, e);
  }
  getWidth() {
    return this.width;
  }
  getHeight() {
    return this.height;
  }
  setSize(t, e) {
    this.setWidth(t || 0), this.setHeight(e || 0);
  }
  toDataURL(t, e) {
    try {
      return this._canvas.toDataURL(t, e);
    } catch {
      try {
        return this._canvas.toDataURL();
      } catch (n) {
        return sn.Util.error("Unable to get data URL. " + n.message + " For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."), "";
      }
    }
  }
}
It.Canvas = Sn;
Gh.Factory.addGetterSetter(Sn, "pixelRatio", void 0, (0, Bh.getNumberValidator)());
class Uh extends Sn {
  constructor(t = { width: 0, height: 0, willReadFrequently: !1 }) {
    super(t), this.context = new ja.SceneContext(this, {
      willReadFrequently: t.willReadFrequently
    }), this.setSize(t.width, t.height);
  }
}
It.SceneCanvas = Uh;
class Hh extends Sn {
  constructor(t = { width: 0, height: 0 }) {
    super(t), this.hitCanvas = !0, this.context = new ja.HitContext(this), this.setSize(t.width, t.height);
  }
}
It.HitCanvas = Hh;
var Cn = {};
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.DD = void 0;
  const t = V, e = rt;
  s.DD = {
    get isDragging() {
      var i = !1;
      return s.DD._dragElements.forEach((n) => {
        n.dragStatus === "dragging" && (i = !0);
      }), i;
    },
    justDragged: !1,
    get node() {
      var i;
      return s.DD._dragElements.forEach((n) => {
        i = n.node;
      }), i;
    },
    _dragElements: /* @__PURE__ */ new Map(),
    _drag(i) {
      const n = [];
      s.DD._dragElements.forEach((r, a) => {
        const { node: o } = r, h = o.getStage();
        h.setPointersPositions(i), r.pointerId === void 0 && (r.pointerId = e.Util._getFirstPointerId(i));
        const l = h._changedPointerPositions.find((f) => f.id === r.pointerId);
        if (l) {
          if (r.dragStatus !== "dragging") {
            var A = o.dragDistance(), u = Math.max(Math.abs(l.x - r.startPointerPos.x), Math.abs(l.y - r.startPointerPos.y));
            if (u < A || (o.startDrag({ evt: i }), !o.isDragging()))
              return;
          }
          o._setDragPosition(i, r), n.push(o);
        }
      }), n.forEach((r) => {
        r.fire("dragmove", {
          type: "dragmove",
          target: r,
          evt: i
        }, !0);
      });
    },
    _endDragBefore(i) {
      const n = [];
      s.DD._dragElements.forEach((r) => {
        const { node: a } = r, o = a.getStage();
        if (i && o.setPointersPositions(i), !o._changedPointerPositions.find((A) => A.id === r.pointerId))
          return;
        (r.dragStatus === "dragging" || r.dragStatus === "stopped") && (s.DD.justDragged = !0, t.Konva._mouseListenClick = !1, t.Konva._touchListenClick = !1, t.Konva._pointerListenClick = !1, r.dragStatus = "stopped");
        const l = r.node.getLayer() || r.node instanceof t.Konva.Stage && r.node;
        l && n.indexOf(l) === -1 && n.push(l);
      }), n.forEach((r) => {
        r.draw();
      });
    },
    _endDragAfter(i) {
      s.DD._dragElements.forEach((n, r) => {
        n.dragStatus === "stopped" && n.node.fire("dragend", {
          type: "dragend",
          target: n.node,
          evt: i
        }, !0), n.dragStatus !== "dragging" && s.DD._dragElements.delete(r);
      });
    }
  }, t.Konva.isBrowser && (window.addEventListener("mouseup", s.DD._endDragBefore, !0), window.addEventListener("touchend", s.DD._endDragBefore, !0), window.addEventListener("mousemove", s.DD._drag), window.addEventListener("touchmove", s.DD._drag), window.addEventListener("mouseup", s.DD._endDragAfter, !1), window.addEventListener("touchend", s.DD._endDragAfter, !1));
})(Cn);
Object.defineProperty(st, "__esModule", { value: !0 });
st.Node = void 0;
const W = rt, Ii = H, ui = It, ie = V, Ct = Cn, dt = N;
var en = "absoluteOpacity", Hi = "allEventListeners", Vt = "absoluteTransform", Rs = "absoluteScale", ve = "canvas", Vh = "Change", $h = "children", Wh = "konva", Gr = "listening", Ls = "mouseenter", Os = "mouseleave", Ns = "set", Gs = "Shape", nn = " ", Bs = "stage", ae = "transform", Yh = "Stage", Br = "visible", Xh = [
  "xChange.konva",
  "yChange.konva",
  "scaleXChange.konva",
  "scaleYChange.konva",
  "skewXChange.konva",
  "skewYChange.konva",
  "rotationChange.konva",
  "offsetXChange.konva",
  "offsetYChange.konva",
  "transformsEnabledChange.konva"
].join(nn);
let jh = 1, U = class zr {
  constructor(t) {
    this._id = jh++, this.eventListeners = {}, this.attrs = {}, this.index = 0, this._allEventListeners = null, this.parent = null, this._cache = /* @__PURE__ */ new Map(), this._attachedDepsListeners = /* @__PURE__ */ new Map(), this._lastPos = null, this._batchingTransformChange = !1, this._needClearTransformCache = !1, this._filterUpToDate = !1, this._isUnderCache = !1, this._dragEventId = null, this._shouldFireChangeEvents = !1, this.setAttrs(t), this._shouldFireChangeEvents = !0;
  }
  hasChildren() {
    return !1;
  }
  _clearCache(t) {
    (t === ae || t === Vt) && this._cache.get(t) ? this._cache.get(t).dirty = !0 : t ? this._cache.delete(t) : this._cache.clear();
  }
  _getCache(t, e) {
    var i = this._cache.get(t), n = t === ae || t === Vt, r = i === void 0 || n && i.dirty === !0;
    return r && (i = e.call(this), this._cache.set(t, i)), i;
  }
  _calculate(t, e, i) {
    if (!this._attachedDepsListeners.get(t)) {
      const n = e.map((r) => r + "Change.konva").join(nn);
      this.on(n, () => {
        this._clearCache(t);
      }), this._attachedDepsListeners.set(t, !0);
    }
    return this._getCache(t, i);
  }
  _getCanvasCache() {
    return this._cache.get(ve);
  }
  _clearSelfAndDescendantCache(t) {
    this._clearCache(t), t === Vt && this.fire("absoluteTransformChange");
  }
  clearCache() {
    if (this._cache.has(ve)) {
      const { scene: t, filter: e, hit: i } = this._cache.get(ve);
      W.Util.releaseCanvas(t, e, i), this._cache.delete(ve);
    }
    return this._clearSelfAndDescendantCache(), this._requestDraw(), this;
  }
  cache(t) {
    var e = t || {}, i = {};
    (e.x === void 0 || e.y === void 0 || e.width === void 0 || e.height === void 0) && (i = this.getClientRect({
      skipTransform: !0,
      relativeTo: this.getParent() || void 0
    }));
    var n = Math.ceil(e.width || i.width), r = Math.ceil(e.height || i.height), a = e.pixelRatio, o = e.x === void 0 ? Math.floor(i.x) : e.x, h = e.y === void 0 ? Math.floor(i.y) : e.y, l = e.offset || 0, A = e.drawBorder || !1, u = e.hitCanvasPixelRatio || 1;
    if (!n || !r) {
      W.Util.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");
      return;
    }
    const f = Math.abs(Math.round(i.x) - o) > 0.5 ? 1 : 0, d = Math.abs(Math.round(i.y) - h) > 0.5 ? 1 : 0;
    n += l * 2 + f, r += l * 2 + d, o -= l, h -= l;
    var c = new ui.SceneCanvas({
      pixelRatio: a,
      width: n,
      height: r
    }), p = new ui.SceneCanvas({
      pixelRatio: a,
      width: 0,
      height: 0,
      willReadFrequently: !0
    }), m = new ui.HitCanvas({
      pixelRatio: u,
      width: n,
      height: r
    }), v = c.getContext(), x = m.getContext();
    return m.isCache = !0, c.isCache = !0, this._cache.delete(ve), this._filterUpToDate = !1, e.imageSmoothingEnabled === !1 && (c.getContext()._context.imageSmoothingEnabled = !1, p.getContext()._context.imageSmoothingEnabled = !1), v.save(), x.save(), v.translate(-o, -h), x.translate(-o, -h), this._isUnderCache = !0, this._clearSelfAndDescendantCache(en), this._clearSelfAndDescendantCache(Rs), this.drawScene(c, this), this.drawHit(m, this), this._isUnderCache = !1, v.restore(), x.restore(), A && (v.save(), v.beginPath(), v.rect(0, 0, n, r), v.closePath(), v.setAttr("strokeStyle", "red"), v.setAttr("lineWidth", 5), v.stroke(), v.restore()), this._cache.set(ve, {
      scene: c,
      filter: p,
      hit: m,
      x: o,
      y: h
    }), this._requestDraw(), this;
  }
  isCached() {
    return this._cache.has(ve);
  }
  getClientRect(t) {
    throw new Error('abstract "getClientRect" method call');
  }
  _transformedRect(t, e) {
    var i = [
      { x: t.x, y: t.y },
      { x: t.x + t.width, y: t.y },
      { x: t.x + t.width, y: t.y + t.height },
      { x: t.x, y: t.y + t.height }
    ], n = 1 / 0, r = 1 / 0, a = -1 / 0, o = -1 / 0, h = this.getAbsoluteTransform(e);
    return i.forEach(function(l) {
      var A = h.point(l);
      n === void 0 && (n = a = A.x, r = o = A.y), n = Math.min(n, A.x), r = Math.min(r, A.y), a = Math.max(a, A.x), o = Math.max(o, A.y);
    }), {
      x: n,
      y: r,
      width: a - n,
      height: o - r
    };
  }
  _drawCachedSceneCanvas(t) {
    t.save(), t._applyOpacity(this), t._applyGlobalCompositeOperation(this);
    const e = this._getCanvasCache();
    t.translate(e.x, e.y);
    var i = this._getCachedSceneCanvas(), n = i.pixelRatio;
    t.drawImage(i._canvas, 0, 0, i.width / n, i.height / n), t.restore();
  }
  _drawCachedHitCanvas(t) {
    var e = this._getCanvasCache(), i = e.hit;
    t.save(), t.translate(e.x, e.y), t.drawImage(i._canvas, 0, 0, i.width / i.pixelRatio, i.height / i.pixelRatio), t.restore();
  }
  _getCachedSceneCanvas() {
    var t = this.filters(), e = this._getCanvasCache(), i = e.scene, n = e.filter, r = n.getContext(), a, o, h, l;
    if (t) {
      if (!this._filterUpToDate) {
        var A = i.pixelRatio;
        n.setSize(i.width / i.pixelRatio, i.height / i.pixelRatio);
        try {
          for (a = t.length, r.clear(), r.drawImage(i._canvas, 0, 0, i.getWidth() / A, i.getHeight() / A), o = r.getImageData(0, 0, n.getWidth(), n.getHeight()), h = 0; h < a; h++) {
            if (l = t[h], typeof l != "function") {
              W.Util.error("Filter should be type of function, but got " + typeof l + " instead. Please check correct filters");
              continue;
            }
            l.call(this, o), r.putImageData(o, 0, 0);
          }
        } catch (u) {
          W.Util.error("Unable to apply filter. " + u.message + " This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.");
        }
        this._filterUpToDate = !0;
      }
      return n;
    }
    return i;
  }
  on(t, e) {
    if (this._cache && this._cache.delete(Hi), arguments.length === 3)
      return this._delegate.apply(this, arguments);
    var i = t.split(nn), n = i.length, r, a, o, h, l;
    for (r = 0; r < n; r++)
      a = i[r], o = a.split("."), h = o[0], l = o[1] || "", this.eventListeners[h] || (this.eventListeners[h] = []), this.eventListeners[h].push({
        name: l,
        handler: e
      });
    return this;
  }
  off(t, e) {
    var i = (t || "").split(nn), n = i.length, r, a, o, h, l, A;
    if (this._cache && this._cache.delete(Hi), !t)
      for (a in this.eventListeners)
        this._off(a);
    for (r = 0; r < n; r++)
      if (o = i[r], h = o.split("."), l = h[0], A = h[1], l)
        this.eventListeners[l] && this._off(l, A, e);
      else
        for (a in this.eventListeners)
          this._off(a, A, e);
    return this;
  }
  dispatchEvent(t) {
    var e = {
      target: this,
      type: t.type,
      evt: t
    };
    return this.fire(t.type, e), this;
  }
  addEventListener(t, e) {
    return this.on(t, function(i) {
      e.call(this, i.evt);
    }), this;
  }
  removeEventListener(t) {
    return this.off(t), this;
  }
  _delegate(t, e, i) {
    var n = this;
    this.on(t, function(r) {
      for (var a = r.target.findAncestors(e, !0, n), o = 0; o < a.length; o++)
        r = W.Util.cloneObject(r), r.currentTarget = a[o], i.call(a[o], r);
    });
  }
  remove() {
    return this.isDragging() && this.stopDrag(), Ct.DD._dragElements.delete(this._id), this._remove(), this;
  }
  _clearCaches() {
    this._clearSelfAndDescendantCache(Vt), this._clearSelfAndDescendantCache(en), this._clearSelfAndDescendantCache(Rs), this._clearSelfAndDescendantCache(Bs), this._clearSelfAndDescendantCache(Br), this._clearSelfAndDescendantCache(Gr);
  }
  _remove() {
    this._clearCaches();
    var t = this.getParent();
    t && t.children && (t.children.splice(this.index, 1), t._setChildrenIndices(), this.parent = null);
  }
  destroy() {
    return this.remove(), this.clearCache(), this;
  }
  getAttr(t) {
    var e = "get" + W.Util._capitalize(t);
    return W.Util._isFunction(this[e]) ? this[e]() : this.attrs[t];
  }
  getAncestors() {
    for (var t = this.getParent(), e = []; t; )
      e.push(t), t = t.getParent();
    return e;
  }
  getAttrs() {
    return this.attrs || {};
  }
  setAttrs(t) {
    return this._batchTransformChanges(() => {
      var e, i;
      if (!t)
        return this;
      for (e in t)
        e !== $h && (i = Ns + W.Util._capitalize(e), W.Util._isFunction(this[i]) ? this[i](t[e]) : this._setAttr(e, t[e]));
    }), this;
  }
  isListening() {
    return this._getCache(Gr, this._isListening);
  }
  _isListening(t) {
    if (!this.listening())
      return !1;
    const i = this.getParent();
    return i && i !== t && this !== t ? i._isListening(t) : !0;
  }
  isVisible() {
    return this._getCache(Br, this._isVisible);
  }
  _isVisible(t) {
    if (!this.visible())
      return !1;
    const i = this.getParent();
    return i && i !== t && this !== t ? i._isVisible(t) : !0;
  }
  shouldDrawHit(t, e = !1) {
    if (t)
      return this._isVisible(t) && this._isListening(t);
    var i = this.getLayer(), n = !1;
    Ct.DD._dragElements.forEach((a) => {
      a.dragStatus === "dragging" && (a.node.nodeType === "Stage" || a.node.getLayer() === i) && (n = !0);
    });
    var r = !e && !ie.Konva.hitOnDragEnabled && (n || ie.Konva.isTransforming());
    return this.isListening() && this.isVisible() && !r;
  }
  show() {
    return this.visible(!0), this;
  }
  hide() {
    return this.visible(!1), this;
  }
  getZIndex() {
    return this.index || 0;
  }
  getAbsoluteZIndex() {
    var t = this.getDepth(), e = this, i = 0, n, r, a, o;
    function h(A) {
      for (n = [], r = A.length, a = 0; a < r; a++)
        o = A[a], i++, o.nodeType !== Gs && (n = n.concat(o.getChildren().slice())), o._id === e._id && (a = r);
      n.length > 0 && n[0].getDepth() <= t && h(n);
    }
    const l = this.getStage();
    return e.nodeType !== Yh && l && h(l.getChildren()), i;
  }
  getDepth() {
    for (var t = 0, e = this.parent; e; )
      t++, e = e.parent;
    return t;
  }
  _batchTransformChanges(t) {
    this._batchingTransformChange = !0, t(), this._batchingTransformChange = !1, this._needClearTransformCache && (this._clearCache(ae), this._clearSelfAndDescendantCache(Vt)), this._needClearTransformCache = !1;
  }
  setPosition(t) {
    return this._batchTransformChanges(() => {
      this.x(t.x), this.y(t.y);
    }), this;
  }
  getPosition() {
    return {
      x: this.x(),
      y: this.y()
    };
  }
  getRelativePointerPosition() {
    const t = this.getStage();
    if (!t)
      return null;
    var e = t.getPointerPosition();
    if (!e)
      return null;
    var i = this.getAbsoluteTransform().copy();
    return i.invert(), i.point(e);
  }
  getAbsolutePosition(t) {
    let e = !1, i = this.parent;
    for (; i; ) {
      if (i.isCached()) {
        e = !0;
        break;
      }
      i = i.parent;
    }
    e && !t && (t = !0);
    var n = this.getAbsoluteTransform(t).getMatrix(), r = new W.Transform(), a = this.offset();
    return r.m = n.slice(), r.translate(a.x, a.y), r.getTranslation();
  }
  setAbsolutePosition(t) {
    const { x: e, y: i, ...n } = this._clearTransform();
    this.attrs.x = e, this.attrs.y = i, this._clearCache(ae);
    var r = this._getAbsoluteTransform().copy();
    return r.invert(), r.translate(t.x, t.y), t = {
      x: this.attrs.x + r.getTranslation().x,
      y: this.attrs.y + r.getTranslation().y
    }, this._setTransform(n), this.setPosition({ x: t.x, y: t.y }), this._clearCache(ae), this._clearSelfAndDescendantCache(Vt), this;
  }
  _setTransform(t) {
    var e;
    for (e in t)
      this.attrs[e] = t[e];
  }
  _clearTransform() {
    var t = {
      x: this.x(),
      y: this.y(),
      rotation: this.rotation(),
      scaleX: this.scaleX(),
      scaleY: this.scaleY(),
      offsetX: this.offsetX(),
      offsetY: this.offsetY(),
      skewX: this.skewX(),
      skewY: this.skewY()
    };
    return this.attrs.x = 0, this.attrs.y = 0, this.attrs.rotation = 0, this.attrs.scaleX = 1, this.attrs.scaleY = 1, this.attrs.offsetX = 0, this.attrs.offsetY = 0, this.attrs.skewX = 0, this.attrs.skewY = 0, t;
  }
  move(t) {
    var e = t.x, i = t.y, n = this.x(), r = this.y();
    return e !== void 0 && (n += e), i !== void 0 && (r += i), this.setPosition({ x: n, y: r }), this;
  }
  _eachAncestorReverse(t, e) {
    var i = [], n = this.getParent(), r, a;
    if (!(e && e._id === this._id)) {
      for (i.unshift(this); n && (!e || n._id !== e._id); )
        i.unshift(n), n = n.parent;
      for (r = i.length, a = 0; a < r; a++)
        t(i[a]);
    }
  }
  rotate(t) {
    return this.rotation(this.rotation() + t), this;
  }
  moveToTop() {
    if (!this.parent)
      return W.Util.warn("Node has no parent. moveToTop function is ignored."), !1;
    var t = this.index, e = this.parent.getChildren().length;
    return t < e - 1 ? (this.parent.children.splice(t, 1), this.parent.children.push(this), this.parent._setChildrenIndices(), !0) : !1;
  }
  moveUp() {
    if (!this.parent)
      return W.Util.warn("Node has no parent. moveUp function is ignored."), !1;
    var t = this.index, e = this.parent.getChildren().length;
    return t < e - 1 ? (this.parent.children.splice(t, 1), this.parent.children.splice(t + 1, 0, this), this.parent._setChildrenIndices(), !0) : !1;
  }
  moveDown() {
    if (!this.parent)
      return W.Util.warn("Node has no parent. moveDown function is ignored."), !1;
    var t = this.index;
    return t > 0 ? (this.parent.children.splice(t, 1), this.parent.children.splice(t - 1, 0, this), this.parent._setChildrenIndices(), !0) : !1;
  }
  moveToBottom() {
    if (!this.parent)
      return W.Util.warn("Node has no parent. moveToBottom function is ignored."), !1;
    var t = this.index;
    return t > 0 ? (this.parent.children.splice(t, 1), this.parent.children.unshift(this), this.parent._setChildrenIndices(), !0) : !1;
  }
  setZIndex(t) {
    if (!this.parent)
      return W.Util.warn("Node has no parent. zIndex parameter is ignored."), this;
    (t < 0 || t >= this.parent.children.length) && W.Util.warn("Unexpected value " + t + " for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to " + (this.parent.children.length - 1) + ".");
    var e = this.index;
    return this.parent.children.splice(e, 1), this.parent.children.splice(t, 0, this), this.parent._setChildrenIndices(), this;
  }
  getAbsoluteOpacity() {
    return this._getCache(en, this._getAbsoluteOpacity);
  }
  _getAbsoluteOpacity() {
    var t = this.opacity(), e = this.getParent();
    return e && !e._isUnderCache && (t *= e.getAbsoluteOpacity()), t;
  }
  moveTo(t) {
    return this.getParent() !== t && (this._remove(), t.add(this)), this;
  }
  toObject() {
    var t = this.getAttrs(), e, i, n, r, a;
    const o = {
      attrs: {},
      className: this.getClassName()
    };
    for (e in t)
      i = t[e], a = W.Util.isObject(i) && !W.Util._isPlainObject(i) && !W.Util._isArray(i), !a && (n = typeof this[e] == "function" && this[e], delete t[e], r = n ? n.call(this) : null, t[e] = i, r !== i && (o.attrs[e] = i));
    return W.Util._prepareToStringify(o);
  }
  toJSON() {
    return JSON.stringify(this.toObject());
  }
  getParent() {
    return this.parent;
  }
  findAncestors(t, e, i) {
    var n = [];
    e && this._isMatch(t) && n.push(this);
    for (var r = this.parent; r; ) {
      if (r === i)
        return n;
      r._isMatch(t) && n.push(r), r = r.parent;
    }
    return n;
  }
  isAncestorOf(t) {
    return !1;
  }
  findAncestor(t, e, i) {
    return this.findAncestors(t, e, i)[0];
  }
  _isMatch(t) {
    if (!t)
      return !1;
    if (typeof t == "function")
      return t(this);
    var e = t.replace(/ /g, "").split(","), i = e.length, n, r;
    for (n = 0; n < i; n++)
      if (r = e[n], W.Util.isValidSelector(r) || (W.Util.warn('Selector "' + r + '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'), W.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'), W.Util.warn("Konva is awesome, right?")), r.charAt(0) === "#") {
        if (this.id() === r.slice(1))
          return !0;
      } else if (r.charAt(0) === ".") {
        if (this.hasName(r.slice(1)))
          return !0;
      } else if (this.className === r || this.nodeType === r)
        return !0;
    return !1;
  }
  getLayer() {
    var t = this.getParent();
    return t ? t.getLayer() : null;
  }
  getStage() {
    return this._getCache(Bs, this._getStage);
  }
  _getStage() {
    var t = this.getParent();
    return t ? t.getStage() : null;
  }
  fire(t, e = {}, i) {
    return e.target = e.target || this, i ? this._fireAndBubble(t, e) : this._fire(t, e), this;
  }
  getAbsoluteTransform(t) {
    return t ? this._getAbsoluteTransform(t) : this._getCache(Vt, this._getAbsoluteTransform);
  }
  _getAbsoluteTransform(t) {
    var e;
    if (t)
      return e = new W.Transform(), this._eachAncestorReverse(function(n) {
        var r = n.transformsEnabled();
        r === "all" ? e.multiply(n.getTransform()) : r === "position" && e.translate(n.x() - n.offsetX(), n.y() - n.offsetY());
      }, t), e;
    e = this._cache.get(Vt) || new W.Transform(), this.parent ? this.parent.getAbsoluteTransform().copyInto(e) : e.reset();
    var i = this.transformsEnabled();
    if (i === "all")
      e.multiply(this.getTransform());
    else if (i === "position") {
      const n = this.attrs.x || 0, r = this.attrs.y || 0, a = this.attrs.offsetX || 0, o = this.attrs.offsetY || 0;
      e.translate(n - a, r - o);
    }
    return e.dirty = !1, e;
  }
  getAbsoluteScale(t) {
    for (var e = this; e; )
      e._isUnderCache && (t = e), e = e.getParent();
    const n = this.getAbsoluteTransform(t).decompose();
    return {
      x: n.scaleX,
      y: n.scaleY
    };
  }
  getAbsoluteRotation() {
    return this.getAbsoluteTransform().decompose().rotation;
  }
  getTransform() {
    return this._getCache(ae, this._getTransform);
  }
  _getTransform() {
    var t, e, i = this._cache.get(ae) || new W.Transform();
    i.reset();
    var n = this.x(), r = this.y(), a = ie.Konva.getAngle(this.rotation()), o = (t = this.attrs.scaleX) !== null && t !== void 0 ? t : 1, h = (e = this.attrs.scaleY) !== null && e !== void 0 ? e : 1, l = this.attrs.skewX || 0, A = this.attrs.skewY || 0, u = this.attrs.offsetX || 0, f = this.attrs.offsetY || 0;
    return (n !== 0 || r !== 0) && i.translate(n, r), a !== 0 && i.rotate(a), (l !== 0 || A !== 0) && i.skew(l, A), (o !== 1 || h !== 1) && i.scale(o, h), (u !== 0 || f !== 0) && i.translate(-1 * u, -1 * f), i.dirty = !1, i;
  }
  clone(t) {
    var e = W.Util.cloneObject(this.attrs), i, n, r, a, o;
    for (i in t)
      e[i] = t[i];
    var h = new this.constructor(e);
    for (i in this.eventListeners)
      for (n = this.eventListeners[i], r = n.length, a = 0; a < r; a++)
        o = n[a], o.name.indexOf(Wh) < 0 && (h.eventListeners[i] || (h.eventListeners[i] = []), h.eventListeners[i].push(o));
    return h;
  }
  _toKonvaCanvas(t) {
    t = t || {};
    var e = this.getClientRect(), i = this.getStage(), n = t.x !== void 0 ? t.x : Math.floor(e.x), r = t.y !== void 0 ? t.y : Math.floor(e.y), a = t.pixelRatio || 1, o = new ui.SceneCanvas({
      width: t.width || Math.ceil(e.width) || (i ? i.width() : 0),
      height: t.height || Math.ceil(e.height) || (i ? i.height() : 0),
      pixelRatio: a
    }), h = o.getContext();
    const l = new ui.SceneCanvas({
      width: o.width / o.pixelRatio + Math.abs(n),
      height: o.height / o.pixelRatio + Math.abs(r),
      pixelRatio: o.pixelRatio
    });
    return t.imageSmoothingEnabled === !1 && (h._context.imageSmoothingEnabled = !1), h.save(), (n || r) && h.translate(-1 * n, -1 * r), this.drawScene(o, void 0, l), h.restore(), o;
  }
  toCanvas(t) {
    return this._toKonvaCanvas(t)._canvas;
  }
  toDataURL(t) {
    t = t || {};
    var e = t.mimeType || null, i = t.quality || null, n = this._toKonvaCanvas(t).toDataURL(e, i);
    return t.callback && t.callback(n), n;
  }
  toImage(t) {
    return new Promise((e, i) => {
      try {
        const n = t == null ? void 0 : t.callback;
        n && delete t.callback, W.Util._urlToImage(this.toDataURL(t), function(r) {
          e(r), n == null || n(r);
        });
      } catch (n) {
        i(n);
      }
    });
  }
  toBlob(t) {
    return new Promise((e, i) => {
      try {
        const n = t == null ? void 0 : t.callback;
        n && delete t.callback, this.toCanvas(t).toBlob((r) => {
          e(r), n == null || n(r);
        }, t == null ? void 0 : t.mimeType, t == null ? void 0 : t.quality);
      } catch (n) {
        i(n);
      }
    });
  }
  setSize(t) {
    return this.width(t.width), this.height(t.height), this;
  }
  getSize() {
    return {
      width: this.width(),
      height: this.height()
    };
  }
  getClassName() {
    return this.className || this.nodeType;
  }
  getType() {
    return this.nodeType;
  }
  getDragDistance() {
    return this.attrs.dragDistance !== void 0 ? this.attrs.dragDistance : this.parent ? this.parent.getDragDistance() : ie.Konva.dragDistance;
  }
  _off(t, e, i) {
    var n = this.eventListeners[t], r, a, o;
    for (r = 0; r < n.length; r++)
      if (a = n[r].name, o = n[r].handler, (a !== "konva" || e === "konva") && (!e || a === e) && (!i || i === o)) {
        if (n.splice(r, 1), n.length === 0) {
          delete this.eventListeners[t];
          break;
        }
        r--;
      }
  }
  _fireChangeEvent(t, e, i) {
    this._fire(t + Vh, {
      oldVal: e,
      newVal: i
    });
  }
  addName(t) {
    if (!this.hasName(t)) {
      var e = this.name(), i = e ? e + " " + t : t;
      this.name(i);
    }
    return this;
  }
  hasName(t) {
    if (!t)
      return !1;
    const e = this.name();
    if (!e)
      return !1;
    var i = (e || "").split(/\s/g);
    return i.indexOf(t) !== -1;
  }
  removeName(t) {
    var e = (this.name() || "").split(/\s/g), i = e.indexOf(t);
    return i !== -1 && (e.splice(i, 1), this.name(e.join(" "))), this;
  }
  setAttr(t, e) {
    var i = this[Ns + W.Util._capitalize(t)];
    return W.Util._isFunction(i) ? i.call(this, e) : this._setAttr(t, e), this;
  }
  _requestDraw() {
    if (ie.Konva.autoDrawEnabled) {
      const t = this.getLayer() || this.getStage();
      t == null || t.batchDraw();
    }
  }
  _setAttr(t, e) {
    var i = this.attrs[t];
    i === e && !W.Util.isObject(e) || (e == null ? delete this.attrs[t] : this.attrs[t] = e, this._shouldFireChangeEvents && this._fireChangeEvent(t, i, e), this._requestDraw());
  }
  _setComponentAttr(t, e, i) {
    var n;
    i !== void 0 && (n = this.attrs[t], n || (this.attrs[t] = this.getAttr(t)), this.attrs[t][e] = i, this._fireChangeEvent(t, n, i));
  }
  _fireAndBubble(t, e, i) {
    e && this.nodeType === Gs && (e.target = this);
    var n = (t === Ls || t === Os) && (i && (this === i || this.isAncestorOf && this.isAncestorOf(i)) || this.nodeType === "Stage" && !i);
    if (!n) {
      this._fire(t, e);
      var r = (t === Ls || t === Os) && i && i.isAncestorOf && i.isAncestorOf(this) && !i.isAncestorOf(this.parent);
      (e && !e.cancelBubble || !e) && this.parent && this.parent.isListening() && !r && (i && i.parent ? this._fireAndBubble.call(this.parent, t, e, i) : this._fireAndBubble.call(this.parent, t, e));
    }
  }
  _getProtoListeners(t) {
    var e, i, n;
    const r = (e = this._cache.get(Hi)) !== null && e !== void 0 ? e : {};
    let a = r == null ? void 0 : r[t];
    if (a === void 0) {
      a = [];
      let o = Object.getPrototypeOf(this);
      for (; o; ) {
        const h = (n = (i = o.eventListeners) === null || i === void 0 ? void 0 : i[t]) !== null && n !== void 0 ? n : [];
        a.push(...h), o = Object.getPrototypeOf(o);
      }
      r[t] = a, this._cache.set(Hi, r);
    }
    return a;
  }
  _fire(t, e) {
    e = e || {}, e.currentTarget = this, e.type = t;
    const i = this._getProtoListeners(t);
    if (i)
      for (var n = 0; n < i.length; n++)
        i[n].handler.call(this, e);
    const r = this.eventListeners[t];
    if (r)
      for (var n = 0; n < r.length; n++)
        r[n].handler.call(this, e);
  }
  draw() {
    return this.drawScene(), this.drawHit(), this;
  }
  _createDragElement(t) {
    var e = t ? t.pointerId : void 0, i = this.getStage(), n = this.getAbsolutePosition();
    if (i) {
      var r = i._getPointerById(e) || i._changedPointerPositions[0] || n;
      Ct.DD._dragElements.set(this._id, {
        node: this,
        startPointerPos: r,
        offset: {
          x: r.x - n.x,
          y: r.y - n.y
        },
        dragStatus: "ready",
        pointerId: e
      });
    }
  }
  startDrag(t, e = !0) {
    Ct.DD._dragElements.has(this._id) || this._createDragElement(t);
    const i = Ct.DD._dragElements.get(this._id);
    i.dragStatus = "dragging", this.fire("dragstart", {
      type: "dragstart",
      target: this,
      evt: t && t.evt
    }, e);
  }
  _setDragPosition(t, e) {
    const i = this.getStage()._getPointerById(e.pointerId);
    if (i) {
      var n = {
        x: i.x - e.offset.x,
        y: i.y - e.offset.y
      }, r = this.dragBoundFunc();
      if (r !== void 0) {
        const a = r.call(this, n, t);
        a ? n = a : W.Util.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.");
      }
      (!this._lastPos || this._lastPos.x !== n.x || this._lastPos.y !== n.y) && (this.setAbsolutePosition(n), this._requestDraw()), this._lastPos = n;
    }
  }
  stopDrag(t) {
    const e = Ct.DD._dragElements.get(this._id);
    e && (e.dragStatus = "stopped"), Ct.DD._endDragBefore(t), Ct.DD._endDragAfter(t);
  }
  setDraggable(t) {
    this._setAttr("draggable", t), this._dragChange();
  }
  isDragging() {
    const t = Ct.DD._dragElements.get(this._id);
    return t ? t.dragStatus === "dragging" : !1;
  }
  _listenDrag() {
    this._dragCleanup(), this.on("mousedown.konva touchstart.konva", function(t) {
      var e = t.evt.button !== void 0, i = !e || ie.Konva.dragButtons.indexOf(t.evt.button) >= 0;
      if (i && !this.isDragging()) {
        var n = !1;
        Ct.DD._dragElements.forEach((r) => {
          this.isAncestorOf(r.node) && (n = !0);
        }), n || this._createDragElement(t);
      }
    });
  }
  _dragChange() {
    if (this.attrs.draggable)
      this._listenDrag();
    else {
      this._dragCleanup();
      var t = this.getStage();
      if (!t)
        return;
      const e = Ct.DD._dragElements.get(this._id), i = e && e.dragStatus === "dragging", n = e && e.dragStatus === "ready";
      i ? this.stopDrag() : n && Ct.DD._dragElements.delete(this._id);
    }
  }
  _dragCleanup() {
    this.off("mousedown.konva"), this.off("touchstart.konva");
  }
  isClientRectOnScreen(t = { x: 0, y: 0 }) {
    const e = this.getStage();
    if (!e)
      return !1;
    const i = {
      x: -t.x,
      y: -t.y,
      width: e.width() + 2 * t.x,
      height: e.height() + 2 * t.y
    };
    return W.Util.haveIntersection(i, this.getClientRect());
  }
  static create(t, e) {
    return W.Util._isString(t) && (t = JSON.parse(t)), this._createNode(t, e);
  }
  static _createNode(t, e) {
    var i = zr.prototype.getClassName.call(t), n = t.children, r, a, o;
    e && (t.attrs.container = e), ie.Konva[i] || (W.Util.warn('Can not find a node with class name "' + i + '". Fallback to "Shape".'), i = "Shape");
    const h = ie.Konva[i];
    if (r = new h(t.attrs), n)
      for (a = n.length, o = 0; o < a; o++)
        r.add(zr._createNode(n[o]));
    return r;
  }
};
st.Node = U;
U.prototype.nodeType = "Node";
U.prototype._attrsAffectingSize = [];
U.prototype.eventListeners = {};
U.prototype.on.call(U.prototype, Xh, function() {
  if (this._batchingTransformChange) {
    this._needClearTransformCache = !0;
    return;
  }
  this._clearCache(ae), this._clearSelfAndDescendantCache(Vt);
});
U.prototype.on.call(U.prototype, "visibleChange.konva", function() {
  this._clearSelfAndDescendantCache(Br);
});
U.prototype.on.call(U.prototype, "listeningChange.konva", function() {
  this._clearSelfAndDescendantCache(Gr);
});
U.prototype.on.call(U.prototype, "opacityChange.konva", function() {
  this._clearSelfAndDescendantCache(en);
});
const J = Ii.Factory.addGetterSetter;
J(U, "zIndex");
J(U, "absolutePosition");
J(U, "position");
J(U, "x", 0, (0, dt.getNumberValidator)());
J(U, "y", 0, (0, dt.getNumberValidator)());
J(U, "globalCompositeOperation", "source-over", (0, dt.getStringValidator)());
J(U, "opacity", 1, (0, dt.getNumberValidator)());
J(U, "name", "", (0, dt.getStringValidator)());
J(U, "id", "", (0, dt.getStringValidator)());
J(U, "rotation", 0, (0, dt.getNumberValidator)());
Ii.Factory.addComponentsGetterSetter(U, "scale", ["x", "y"]);
J(U, "scaleX", 1, (0, dt.getNumberValidator)());
J(U, "scaleY", 1, (0, dt.getNumberValidator)());
Ii.Factory.addComponentsGetterSetter(U, "skew", ["x", "y"]);
J(U, "skewX", 0, (0, dt.getNumberValidator)());
J(U, "skewY", 0, (0, dt.getNumberValidator)());
Ii.Factory.addComponentsGetterSetter(U, "offset", ["x", "y"]);
J(U, "offsetX", 0, (0, dt.getNumberValidator)());
J(U, "offsetY", 0, (0, dt.getNumberValidator)());
J(U, "dragDistance", null, (0, dt.getNumberValidator)());
J(U, "width", 0, (0, dt.getNumberValidator)());
J(U, "height", 0, (0, dt.getNumberValidator)());
J(U, "listening", !0, (0, dt.getBooleanValidator)());
J(U, "preventDefault", !0, (0, dt.getBooleanValidator)());
J(U, "filters", null, function(s) {
  return this._filterUpToDate = !1, s;
});
J(U, "visible", !0, (0, dt.getBooleanValidator)());
J(U, "transformsEnabled", "all", (0, dt.getStringValidator)());
J(U, "size");
J(U, "dragBoundFunc");
J(U, "draggable", !1, (0, dt.getBooleanValidator)());
Ii.Factory.backCompat(U, {
  rotateDeg: "rotate",
  setRotationDeg: "setRotation",
  getRotationDeg: "getRotation"
});
var bt = {};
Object.defineProperty(bt, "__esModule", { value: !0 });
bt.releaseCapture = bt.setPointerCapture = bt.hasPointerCapture = bt.createEvent = bt.getCapturedShape = void 0;
const qh = V, wi = /* @__PURE__ */ new Map(), Qa = qh.Konva._global.PointerEvent !== void 0;
function Qh(s) {
  return wi.get(s);
}
bt.getCapturedShape = Qh;
function rs(s) {
  return {
    evt: s,
    pointerId: s.pointerId
  };
}
bt.createEvent = rs;
function Kh(s, t) {
  return wi.get(s) === t;
}
bt.hasPointerCapture = Kh;
function Zh(s, t) {
  Ka(s), t.getStage() && (wi.set(s, t), Qa && t._fire("gotpointercapture", rs(new PointerEvent("gotpointercapture"))));
}
bt.setPointerCapture = Zh;
function Ka(s, t) {
  const e = wi.get(s);
  if (!e)
    return;
  const i = e.getStage();
  i && i.content, wi.delete(s), Qa && e._fire("lostpointercapture", rs(new PointerEvent("lostpointercapture")));
}
bt.releaseCapture = Ka;
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.Shape = s.shapes = void 0;
  const t = V, e = rt, i = H, n = st, r = N, a = V, o = bt;
  var h = "hasShadow", l = "shadowRGBA", A = "patternImage", u = "linearGradient", f = "radialGradient";
  let d;
  function c() {
    return d || (d = e.Util.createCanvasElement().getContext("2d"), d);
  }
  s.shapes = {};
  function p(E) {
    const S = this.attrs.fillRule;
    S ? E.fill(S) : E.fill();
  }
  function m(E) {
    E.stroke();
  }
  function v(E) {
    E.fill();
  }
  function x(E) {
    E.stroke();
  }
  function g() {
    this._clearCache(h);
  }
  function y() {
    this._clearCache(l);
  }
  function _() {
    this._clearCache(A);
  }
  function b() {
    this._clearCache(u);
  }
  function C() {
    this._clearCache(f);
  }
  class w extends n.Node {
    constructor(S) {
      super(S);
      let P;
      for (; P = e.Util.getRandomColor(), !(P && !(P in s.shapes)); )
        ;
      this.colorKey = P, s.shapes[P] = this;
    }
    getContext() {
      return e.Util.warn("shape.getContext() method is deprecated. Please do not use it."), this.getLayer().getContext();
    }
    getCanvas() {
      return e.Util.warn("shape.getCanvas() method is deprecated. Please do not use it."), this.getLayer().getCanvas();
    }
    getSceneFunc() {
      return this.attrs.sceneFunc || this._sceneFunc;
    }
    getHitFunc() {
      return this.attrs.hitFunc || this._hitFunc;
    }
    hasShadow() {
      return this._getCache(h, this._hasShadow);
    }
    _hasShadow() {
      return this.shadowEnabled() && this.shadowOpacity() !== 0 && !!(this.shadowColor() || this.shadowBlur() || this.shadowOffsetX() || this.shadowOffsetY());
    }
    _getFillPattern() {
      return this._getCache(A, this.__getFillPattern);
    }
    __getFillPattern() {
      if (this.fillPatternImage()) {
        var S = c();
        const P = S.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || "repeat");
        if (P && P.setTransform) {
          const k = new e.Transform();
          k.translate(this.fillPatternX(), this.fillPatternY()), k.rotate(t.Konva.getAngle(this.fillPatternRotation())), k.scale(this.fillPatternScaleX(), this.fillPatternScaleY()), k.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
          const F = k.getMatrix(), I = typeof DOMMatrix > "u" ? {
            a: F[0],
            b: F[1],
            c: F[2],
            d: F[3],
            e: F[4],
            f: F[5]
          } : new DOMMatrix(F);
          P.setTransform(I);
        }
        return P;
      }
    }
    _getLinearGradient() {
      return this._getCache(u, this.__getLinearGradient);
    }
    __getLinearGradient() {
      var S = this.fillLinearGradientColorStops();
      if (S) {
        for (var P = c(), k = this.fillLinearGradientStartPoint(), F = this.fillLinearGradientEndPoint(), I = P.createLinearGradient(k.x, k.y, F.x, F.y), T = 0; T < S.length; T += 2)
          I.addColorStop(S[T], S[T + 1]);
        return I;
      }
    }
    _getRadialGradient() {
      return this._getCache(f, this.__getRadialGradient);
    }
    __getRadialGradient() {
      var S = this.fillRadialGradientColorStops();
      if (S) {
        for (var P = c(), k = this.fillRadialGradientStartPoint(), F = this.fillRadialGradientEndPoint(), I = P.createRadialGradient(k.x, k.y, this.fillRadialGradientStartRadius(), F.x, F.y, this.fillRadialGradientEndRadius()), T = 0; T < S.length; T += 2)
          I.addColorStop(S[T], S[T + 1]);
        return I;
      }
    }
    getShadowRGBA() {
      return this._getCache(l, this._getShadowRGBA);
    }
    _getShadowRGBA() {
      if (this.hasShadow()) {
        var S = e.Util.colorToRGBA(this.shadowColor());
        if (S)
          return "rgba(" + S.r + "," + S.g + "," + S.b + "," + S.a * (this.shadowOpacity() || 1) + ")";
      }
    }
    hasFill() {
      return this._calculate("hasFill", [
        "fillEnabled",
        "fill",
        "fillPatternImage",
        "fillLinearGradientColorStops",
        "fillRadialGradientColorStops"
      ], () => this.fillEnabled() && !!(this.fill() || this.fillPatternImage() || this.fillLinearGradientColorStops() || this.fillRadialGradientColorStops()));
    }
    hasStroke() {
      return this._calculate("hasStroke", [
        "strokeEnabled",
        "strokeWidth",
        "stroke",
        "strokeLinearGradientColorStops"
      ], () => this.strokeEnabled() && this.strokeWidth() && !!(this.stroke() || this.strokeLinearGradientColorStops()));
    }
    hasHitStroke() {
      const S = this.hitStrokeWidth();
      return S === "auto" ? this.hasStroke() : this.strokeEnabled() && !!S;
    }
    intersects(S) {
      var P = this.getStage();
      if (!P)
        return !1;
      const k = P.bufferHitCanvas;
      return k.getContext().clear(), this.drawHit(k, void 0, !0), k.context.getImageData(Math.round(S.x), Math.round(S.y), 1, 1).data[3] > 0;
    }
    destroy() {
      return n.Node.prototype.destroy.call(this), delete s.shapes[this.colorKey], delete this.colorKey, this;
    }
    _useBufferCanvas(S) {
      var P;
      if (!((P = this.attrs.perfectDrawEnabled) !== null && P !== void 0 ? P : !0))
        return !1;
      const F = S || this.hasFill(), I = this.hasStroke(), T = this.getAbsoluteOpacity() !== 1;
      if (F && I && T)
        return !0;
      const R = this.hasShadow(), L = this.shadowForStrokeEnabled();
      return !!(F && I && R && L);
    }
    setStrokeHitEnabled(S) {
      e.Util.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."), S ? this.hitStrokeWidth("auto") : this.hitStrokeWidth(0);
    }
    getStrokeHitEnabled() {
      return this.hitStrokeWidth() !== 0;
    }
    getSelfRect() {
      var S = this.size();
      return {
        x: this._centroid ? -S.width / 2 : 0,
        y: this._centroid ? -S.height / 2 : 0,
        width: S.width,
        height: S.height
      };
    }
    getClientRect(S = {}) {
      const P = S.skipTransform, k = S.relativeTo, F = this.getSelfRect(), T = !S.skipStroke && this.hasStroke() && this.strokeWidth() || 0, R = F.width + T, L = F.height + T, B = !S.skipShadow && this.hasShadow(), $ = B ? this.shadowOffsetX() : 0, O = B ? this.shadowOffsetY() : 0, G = R + Math.abs($), Q = L + Math.abs(O), et = B && this.shadowBlur() || 0, tt = G + et * 2, Bt = Q + et * 2, ct = {
        width: tt,
        height: Bt,
        x: -(T / 2 + et) + Math.min($, 0) + F.x,
        y: -(T / 2 + et) + Math.min(O, 0) + F.y
      };
      return P ? ct : this._transformedRect(ct, k);
    }
    drawScene(S, P, k) {
      var F = this.getLayer(), I = S || F.getCanvas(), T = I.getContext(), R = this._getCanvasCache(), L = this.getSceneFunc(), B = this.hasShadow(), $, O, G = I.isCache, Q = P === this;
      if (!this.isVisible() && !Q)
        return this;
      if (R) {
        T.save();
        var et = this.getAbsoluteTransform(P).getMatrix();
        return T.transform(et[0], et[1], et[2], et[3], et[4], et[5]), this._drawCachedSceneCanvas(T), T.restore(), this;
      }
      if (!L)
        return this;
      if (T.save(), this._useBufferCanvas() && !G) {
        $ = this.getStage();
        const ct = k || $.bufferCanvas;
        O = ct.getContext(), O.clear(), O.save(), O._applyLineJoin(this);
        var tt = this.getAbsoluteTransform(P).getMatrix();
        O.transform(tt[0], tt[1], tt[2], tt[3], tt[4], tt[5]), L.call(this, O, this), O.restore();
        var Bt = ct.pixelRatio;
        B && T._applyShadow(this), T._applyOpacity(this), T._applyGlobalCompositeOperation(this), T.drawImage(ct._canvas, 0, 0, ct.width / Bt, ct.height / Bt);
      } else {
        if (T._applyLineJoin(this), !Q) {
          var tt = this.getAbsoluteTransform(P).getMatrix();
          T.transform(tt[0], tt[1], tt[2], tt[3], tt[4], tt[5]), T._applyOpacity(this), T._applyGlobalCompositeOperation(this);
        }
        B && T._applyShadow(this), L.call(this, T, this);
      }
      return T.restore(), this;
    }
    drawHit(S, P, k = !1) {
      if (!this.shouldDrawHit(P, k))
        return this;
      var F = this.getLayer(), I = S || F.hitCanvas, T = I && I.getContext(), R = this.hitFunc() || this.sceneFunc(), L = this._getCanvasCache(), B = L && L.hit;
      if (this.colorKey || e.Util.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"), B) {
        T.save();
        var $ = this.getAbsoluteTransform(P).getMatrix();
        return T.transform($[0], $[1], $[2], $[3], $[4], $[5]), this._drawCachedHitCanvas(T), T.restore(), this;
      }
      if (!R)
        return this;
      if (T.save(), T._applyLineJoin(this), !(this === P)) {
        var G = this.getAbsoluteTransform(P).getMatrix();
        T.transform(G[0], G[1], G[2], G[3], G[4], G[5]);
      }
      return R.call(this, T, this), T.restore(), this;
    }
    drawHitFromCache(S = 0) {
      var P = this._getCanvasCache(), k = this._getCachedSceneCanvas(), F = P.hit, I = F.getContext(), T = F.getWidth(), R = F.getHeight(), L, B, $, O, G, Q;
      I.clear(), I.drawImage(k._canvas, 0, 0, T, R);
      try {
        for (L = I.getImageData(0, 0, T, R), B = L.data, $ = B.length, O = e.Util._hexToRgb(this.colorKey), G = 0; G < $; G += 4)
          Q = B[G + 3], Q > S ? (B[G] = O.r, B[G + 1] = O.g, B[G + 2] = O.b, B[G + 3] = 255) : B[G + 3] = 0;
        I.putImageData(L, 0, 0);
      } catch (et) {
        e.Util.error("Unable to draw hit graph from cached scene canvas. " + et.message);
      }
      return this;
    }
    hasPointerCapture(S) {
      return o.hasPointerCapture(S, this);
    }
    setPointerCapture(S) {
      o.setPointerCapture(S, this);
    }
    releaseCapture(S) {
      o.releaseCapture(S, this);
    }
  }
  s.Shape = w, w.prototype._fillFunc = p, w.prototype._strokeFunc = m, w.prototype._fillFuncHit = v, w.prototype._strokeFuncHit = x, w.prototype._centroid = !1, w.prototype.nodeType = "Shape", (0, a._registerNode)(w), w.prototype.eventListeners = {}, w.prototype.on.call(w.prototype, "shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva", g), w.prototype.on.call(w.prototype, "shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva", y), w.prototype.on.call(w.prototype, "fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva", _), w.prototype.on.call(w.prototype, "fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva", b), w.prototype.on.call(w.prototype, "fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva", C), i.Factory.addGetterSetter(w, "stroke", void 0, (0, r.getStringOrGradientValidator)()), i.Factory.addGetterSetter(w, "strokeWidth", 2, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "fillAfterStrokeEnabled", !1), i.Factory.addGetterSetter(w, "hitStrokeWidth", "auto", (0, r.getNumberOrAutoValidator)()), i.Factory.addGetterSetter(w, "strokeHitEnabled", !0, (0, r.getBooleanValidator)()), i.Factory.addGetterSetter(w, "perfectDrawEnabled", !0, (0, r.getBooleanValidator)()), i.Factory.addGetterSetter(w, "shadowForStrokeEnabled", !0, (0, r.getBooleanValidator)()), i.Factory.addGetterSetter(w, "lineJoin"), i.Factory.addGetterSetter(w, "lineCap"), i.Factory.addGetterSetter(w, "sceneFunc"), i.Factory.addGetterSetter(w, "hitFunc"), i.Factory.addGetterSetter(w, "dash"), i.Factory.addGetterSetter(w, "dashOffset", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "shadowColor", void 0, (0, r.getStringValidator)()), i.Factory.addGetterSetter(w, "shadowBlur", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "shadowOpacity", 1, (0, r.getNumberValidator)()), i.Factory.addComponentsGetterSetter(w, "shadowOffset", ["x", "y"]), i.Factory.addGetterSetter(w, "shadowOffsetX", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "shadowOffsetY", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "fillPatternImage"), i.Factory.addGetterSetter(w, "fill", void 0, (0, r.getStringOrGradientValidator)()), i.Factory.addGetterSetter(w, "fillPatternX", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "fillPatternY", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "fillLinearGradientColorStops"), i.Factory.addGetterSetter(w, "strokeLinearGradientColorStops"), i.Factory.addGetterSetter(w, "fillRadialGradientStartRadius", 0), i.Factory.addGetterSetter(w, "fillRadialGradientEndRadius", 0), i.Factory.addGetterSetter(w, "fillRadialGradientColorStops"), i.Factory.addGetterSetter(w, "fillPatternRepeat", "repeat"), i.Factory.addGetterSetter(w, "fillEnabled", !0), i.Factory.addGetterSetter(w, "strokeEnabled", !0), i.Factory.addGetterSetter(w, "shadowEnabled", !0), i.Factory.addGetterSetter(w, "dashEnabled", !0), i.Factory.addGetterSetter(w, "strokeScaleEnabled", !0), i.Factory.addGetterSetter(w, "fillPriority", "color"), i.Factory.addComponentsGetterSetter(w, "fillPatternOffset", ["x", "y"]), i.Factory.addGetterSetter(w, "fillPatternOffsetX", 0, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "fillPatternOffsetY", 0, (0, r.getNumberValidator)()), i.Factory.addComponentsGetterSetter(w, "fillPatternScale", ["x", "y"]), i.Factory.addGetterSetter(w, "fillPatternScaleX", 1, (0, r.getNumberValidator)()), i.Factory.addGetterSetter(w, "fillPatternScaleY", 1, (0, r.getNumberValidator)()), i.Factory.addComponentsGetterSetter(w, "fillLinearGradientStartPoint", [
    "x",
    "y"
  ]), i.Factory.addComponentsGetterSetter(w, "strokeLinearGradientStartPoint", [
    "x",
    "y"
  ]), i.Factory.addGetterSetter(w, "fillLinearGradientStartPointX", 0), i.Factory.addGetterSetter(w, "strokeLinearGradientStartPointX", 0), i.Factory.addGetterSetter(w, "fillLinearGradientStartPointY", 0), i.Factory.addGetterSetter(w, "strokeLinearGradientStartPointY", 0), i.Factory.addComponentsGetterSetter(w, "fillLinearGradientEndPoint", [
    "x",
    "y"
  ]), i.Factory.addComponentsGetterSetter(w, "strokeLinearGradientEndPoint", [
    "x",
    "y"
  ]), i.Factory.addGetterSetter(w, "fillLinearGradientEndPointX", 0), i.Factory.addGetterSetter(w, "strokeLinearGradientEndPointX", 0), i.Factory.addGetterSetter(w, "fillLinearGradientEndPointY", 0), i.Factory.addGetterSetter(w, "strokeLinearGradientEndPointY", 0), i.Factory.addComponentsGetterSetter(w, "fillRadialGradientStartPoint", [
    "x",
    "y"
  ]), i.Factory.addGetterSetter(w, "fillRadialGradientStartPointX", 0), i.Factory.addGetterSetter(w, "fillRadialGradientStartPointY", 0), i.Factory.addComponentsGetterSetter(w, "fillRadialGradientEndPoint", [
    "x",
    "y"
  ]), i.Factory.addGetterSetter(w, "fillRadialGradientEndPointX", 0), i.Factory.addGetterSetter(w, "fillRadialGradientEndPointY", 0), i.Factory.addGetterSetter(w, "fillPatternRotation", 0), i.Factory.addGetterSetter(w, "fillRule", void 0, (0, r.getStringValidator)()), i.Factory.backCompat(w, {
    dashArray: "dash",
    getDashArray: "getDash",
    setDashArray: "getDash",
    drawFunc: "sceneFunc",
    getDrawFunc: "getSceneFunc",
    setDrawFunc: "setSceneFunc",
    drawHitFunc: "hitFunc",
    getDrawHitFunc: "getHitFunc",
    setDrawHitFunc: "setHitFunc"
  });
})(ft);
Object.defineProperty(bn, "__esModule", { value: !0 });
var Ri = bn.Circle = void 0;
const Jh = H, tl = ft, el = N, il = V;
class ii extends tl.Shape {
  _sceneFunc(t) {
    t.beginPath(), t.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, !1), t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    return this.radius() * 2;
  }
  getHeight() {
    return this.radius() * 2;
  }
  setWidth(t) {
    this.radius() !== t / 2 && this.radius(t / 2);
  }
  setHeight(t) {
    this.radius() !== t / 2 && this.radius(t / 2);
  }
}
Ri = bn.Circle = ii;
ii.prototype._centroid = !0;
ii.prototype.className = "Circle";
ii.prototype._attrsAffectingSize = ["radius"];
(0, il._registerNode)(ii);
Jh.Factory.addGetterSetter(ii, "radius", 0, (0, el.getNumberValidator)());
var Li = {};
Object.defineProperty(Li, "__esModule", { value: !0 });
var ss = Li.Line = void 0;
const Mn = H, nl = ft, Za = N, rl = V;
function Ur(s, t, e, i, n, r, a) {
  var o = Math.sqrt(Math.pow(e - s, 2) + Math.pow(i - t, 2)), h = Math.sqrt(Math.pow(n - e, 2) + Math.pow(r - i, 2)), l = a * o / (o + h), A = a * h / (o + h), u = e - l * (n - s), f = i - l * (r - t), d = e + A * (n - s), c = i + A * (r - t);
  return [u, f, d, c];
}
function zs(s, t) {
  var e = s.length, i = [], n, r;
  for (n = 2; n < e - 2; n += 2)
    r = Ur(s[n - 2], s[n - 1], s[n], s[n + 1], s[n + 2], s[n + 3], t), !isNaN(r[0]) && (i.push(r[0]), i.push(r[1]), i.push(s[n]), i.push(s[n + 1]), i.push(r[2]), i.push(r[3]));
  return i;
}
class ue extends nl.Shape {
  constructor(t) {
    super(t), this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva", function() {
      this._clearCache("tensionPoints");
    });
  }
  _sceneFunc(t) {
    var e = this.points(), i = e.length, n = this.tension(), r = this.closed(), a = this.bezier(), o, h, l;
    if (i) {
      if (t.beginPath(), t.moveTo(e[0], e[1]), n !== 0 && i > 4) {
        for (o = this.getTensionPoints(), h = o.length, l = r ? 0 : 4, r || t.quadraticCurveTo(o[0], o[1], o[2], o[3]); l < h - 2; )
          t.bezierCurveTo(o[l++], o[l++], o[l++], o[l++], o[l++], o[l++]);
        r || t.quadraticCurveTo(o[h - 2], o[h - 1], e[i - 2], e[i - 1]);
      } else if (a)
        for (l = 2; l < i; )
          t.bezierCurveTo(e[l++], e[l++], e[l++], e[l++], e[l++], e[l++]);
      else
        for (l = 2; l < i; l += 2)
          t.lineTo(e[l], e[l + 1]);
      r ? (t.closePath(), t.fillStrokeShape(this)) : t.strokeShape(this);
    }
  }
  getTensionPoints() {
    return this._getCache("tensionPoints", this._getTensionPoints);
  }
  _getTensionPoints() {
    return this.closed() ? this._getTensionPointsClosed() : zs(this.points(), this.tension());
  }
  _getTensionPointsClosed() {
    var t = this.points(), e = t.length, i = this.tension(), n = Ur(t[e - 2], t[e - 1], t[0], t[1], t[2], t[3], i), r = Ur(t[e - 4], t[e - 3], t[e - 2], t[e - 1], t[0], t[1], i), a = zs(t, i), o = [n[2], n[3]].concat(a).concat([
      r[0],
      r[1],
      t[e - 2],
      t[e - 1],
      r[2],
      r[3],
      n[0],
      n[1],
      t[0],
      t[1]
    ]);
    return o;
  }
  getWidth() {
    return this.getSelfRect().width;
  }
  getHeight() {
    return this.getSelfRect().height;
  }
  getSelfRect() {
    var t = this.points();
    if (t.length < 4)
      return {
        x: t[0] || 0,
        y: t[1] || 0,
        width: 0,
        height: 0
      };
    this.tension() !== 0 ? t = [
      t[0],
      t[1],
      ...this._getTensionPoints(),
      t[t.length - 2],
      t[t.length - 1]
    ] : t = this.points();
    for (var e = t[0], i = t[0], n = t[1], r = t[1], a, o, h = 0; h < t.length / 2; h++)
      a = t[h * 2], o = t[h * 2 + 1], e = Math.min(e, a), i = Math.max(i, a), n = Math.min(n, o), r = Math.max(r, o);
    return {
      x: e,
      y: n,
      width: i - e,
      height: r - n
    };
  }
}
ss = Li.Line = ue;
ue.prototype.className = "Line";
ue.prototype._attrsAffectingSize = ["points", "bezier", "tension"];
(0, rl._registerNode)(ue);
Mn.Factory.addGetterSetter(ue, "closed", !1);
Mn.Factory.addGetterSetter(ue, "bezier", !1);
Mn.Factory.addGetterSetter(ue, "tension", 0, (0, Za.getNumberValidator)());
Mn.Factory.addGetterSetter(ue, "points", [], (0, Za.getNumberArrayValidator)());
let jt = !1;
const Du = (s) => jt = s, Tu = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent), an = "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
var ni = {}, Ja = {};
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.t2length = s.getQuadraticArcLength = s.getCubicArcLength = s.binomialCoefficients = s.cValues = s.tValues = void 0, s.tValues = [
    [],
    [],
    [
      -0.5773502691896257,
      0.5773502691896257
    ],
    [
      0,
      -0.7745966692414834,
      0.7745966692414834
    ],
    [
      -0.33998104358485626,
      0.33998104358485626,
      -0.8611363115940526,
      0.8611363115940526
    ],
    [
      0,
      -0.5384693101056831,
      0.5384693101056831,
      -0.906179845938664,
      0.906179845938664
    ],
    [
      0.6612093864662645,
      -0.6612093864662645,
      -0.2386191860831969,
      0.2386191860831969,
      -0.932469514203152,
      0.932469514203152
    ],
    [
      0,
      0.4058451513773972,
      -0.4058451513773972,
      -0.7415311855993945,
      0.7415311855993945,
      -0.9491079123427585,
      0.9491079123427585
    ],
    [
      -0.1834346424956498,
      0.1834346424956498,
      -0.525532409916329,
      0.525532409916329,
      -0.7966664774136267,
      0.7966664774136267,
      -0.9602898564975363,
      0.9602898564975363
    ],
    [
      0,
      -0.8360311073266358,
      0.8360311073266358,
      -0.9681602395076261,
      0.9681602395076261,
      -0.3242534234038089,
      0.3242534234038089,
      -0.6133714327005904,
      0.6133714327005904
    ],
    [
      -0.14887433898163122,
      0.14887433898163122,
      -0.4333953941292472,
      0.4333953941292472,
      -0.6794095682990244,
      0.6794095682990244,
      -0.8650633666889845,
      0.8650633666889845,
      -0.9739065285171717,
      0.9739065285171717
    ],
    [
      0,
      -0.26954315595234496,
      0.26954315595234496,
      -0.5190961292068118,
      0.5190961292068118,
      -0.7301520055740494,
      0.7301520055740494,
      -0.8870625997680953,
      0.8870625997680953,
      -0.978228658146057,
      0.978228658146057
    ],
    [
      -0.1252334085114689,
      0.1252334085114689,
      -0.3678314989981802,
      0.3678314989981802,
      -0.5873179542866175,
      0.5873179542866175,
      -0.7699026741943047,
      0.7699026741943047,
      -0.9041172563704749,
      0.9041172563704749,
      -0.9815606342467192,
      0.9815606342467192
    ],
    [
      0,
      -0.2304583159551348,
      0.2304583159551348,
      -0.44849275103644687,
      0.44849275103644687,
      -0.6423493394403402,
      0.6423493394403402,
      -0.8015780907333099,
      0.8015780907333099,
      -0.9175983992229779,
      0.9175983992229779,
      -0.9841830547185881,
      0.9841830547185881
    ],
    [
      -0.10805494870734367,
      0.10805494870734367,
      -0.31911236892788974,
      0.31911236892788974,
      -0.5152486363581541,
      0.5152486363581541,
      -0.6872929048116855,
      0.6872929048116855,
      -0.827201315069765,
      0.827201315069765,
      -0.9284348836635735,
      0.9284348836635735,
      -0.9862838086968123,
      0.9862838086968123
    ],
    [
      0,
      -0.20119409399743451,
      0.20119409399743451,
      -0.3941513470775634,
      0.3941513470775634,
      -0.5709721726085388,
      0.5709721726085388,
      -0.7244177313601701,
      0.7244177313601701,
      -0.8482065834104272,
      0.8482065834104272,
      -0.937273392400706,
      0.937273392400706,
      -0.9879925180204854,
      0.9879925180204854
    ],
    [
      -0.09501250983763744,
      0.09501250983763744,
      -0.2816035507792589,
      0.2816035507792589,
      -0.45801677765722737,
      0.45801677765722737,
      -0.6178762444026438,
      0.6178762444026438,
      -0.755404408355003,
      0.755404408355003,
      -0.8656312023878318,
      0.8656312023878318,
      -0.9445750230732326,
      0.9445750230732326,
      -0.9894009349916499,
      0.9894009349916499
    ],
    [
      0,
      -0.17848418149584785,
      0.17848418149584785,
      -0.3512317634538763,
      0.3512317634538763,
      -0.5126905370864769,
      0.5126905370864769,
      -0.6576711592166907,
      0.6576711592166907,
      -0.7815140038968014,
      0.7815140038968014,
      -0.8802391537269859,
      0.8802391537269859,
      -0.9506755217687678,
      0.9506755217687678,
      -0.9905754753144174,
      0.9905754753144174
    ],
    [
      -0.0847750130417353,
      0.0847750130417353,
      -0.2518862256915055,
      0.2518862256915055,
      -0.41175116146284263,
      0.41175116146284263,
      -0.5597708310739475,
      0.5597708310739475,
      -0.6916870430603532,
      0.6916870430603532,
      -0.8037049589725231,
      0.8037049589725231,
      -0.8926024664975557,
      0.8926024664975557,
      -0.9558239495713977,
      0.9558239495713977,
      -0.9915651684209309,
      0.9915651684209309
    ],
    [
      0,
      -0.16035864564022537,
      0.16035864564022537,
      -0.31656409996362983,
      0.31656409996362983,
      -0.46457074137596094,
      0.46457074137596094,
      -0.600545304661681,
      0.600545304661681,
      -0.7209661773352294,
      0.7209661773352294,
      -0.8227146565371428,
      0.8227146565371428,
      -0.9031559036148179,
      0.9031559036148179,
      -0.96020815213483,
      0.96020815213483,
      -0.9924068438435844,
      0.9924068438435844
    ],
    [
      -0.07652652113349734,
      0.07652652113349734,
      -0.22778585114164507,
      0.22778585114164507,
      -0.37370608871541955,
      0.37370608871541955,
      -0.5108670019508271,
      0.5108670019508271,
      -0.636053680726515,
      0.636053680726515,
      -0.7463319064601508,
      0.7463319064601508,
      -0.8391169718222188,
      0.8391169718222188,
      -0.912234428251326,
      0.912234428251326,
      -0.9639719272779138,
      0.9639719272779138,
      -0.9931285991850949,
      0.9931285991850949
    ],
    [
      0,
      -0.1455618541608951,
      0.1455618541608951,
      -0.2880213168024011,
      0.2880213168024011,
      -0.4243421202074388,
      0.4243421202074388,
      -0.5516188358872198,
      0.5516188358872198,
      -0.6671388041974123,
      0.6671388041974123,
      -0.7684399634756779,
      0.7684399634756779,
      -0.8533633645833173,
      0.8533633645833173,
      -0.9200993341504008,
      0.9200993341504008,
      -0.9672268385663063,
      0.9672268385663063,
      -0.9937521706203895,
      0.9937521706203895
    ],
    [
      -0.06973927331972223,
      0.06973927331972223,
      -0.20786042668822127,
      0.20786042668822127,
      -0.34193582089208424,
      0.34193582089208424,
      -0.469355837986757,
      0.469355837986757,
      -0.5876404035069116,
      0.5876404035069116,
      -0.6944872631866827,
      0.6944872631866827,
      -0.7878168059792081,
      0.7878168059792081,
      -0.8658125777203002,
      0.8658125777203002,
      -0.926956772187174,
      0.926956772187174,
      -0.9700604978354287,
      0.9700604978354287,
      -0.9942945854823992,
      0.9942945854823992
    ],
    [
      0,
      -0.1332568242984661,
      0.1332568242984661,
      -0.26413568097034495,
      0.26413568097034495,
      -0.3903010380302908,
      0.3903010380302908,
      -0.5095014778460075,
      0.5095014778460075,
      -0.6196098757636461,
      0.6196098757636461,
      -0.7186613631319502,
      0.7186613631319502,
      -0.8048884016188399,
      0.8048884016188399,
      -0.8767523582704416,
      0.8767523582704416,
      -0.9329710868260161,
      0.9329710868260161,
      -0.9725424712181152,
      0.9725424712181152,
      -0.9947693349975522,
      0.9947693349975522
    ],
    [
      -0.06405689286260563,
      0.06405689286260563,
      -0.1911188674736163,
      0.1911188674736163,
      -0.3150426796961634,
      0.3150426796961634,
      -0.4337935076260451,
      0.4337935076260451,
      -0.5454214713888396,
      0.5454214713888396,
      -0.6480936519369755,
      0.6480936519369755,
      -0.7401241915785544,
      0.7401241915785544,
      -0.820001985973903,
      0.820001985973903,
      -0.8864155270044011,
      0.8864155270044011,
      -0.9382745520027328,
      0.9382745520027328,
      -0.9747285559713095,
      0.9747285559713095,
      -0.9951872199970213,
      0.9951872199970213
    ]
  ], s.cValues = [
    [],
    [],
    [1, 1],
    [
      0.8888888888888888,
      0.5555555555555556,
      0.5555555555555556
    ],
    [
      0.6521451548625461,
      0.6521451548625461,
      0.34785484513745385,
      0.34785484513745385
    ],
    [
      0.5688888888888889,
      0.47862867049936647,
      0.47862867049936647,
      0.23692688505618908,
      0.23692688505618908
    ],
    [
      0.3607615730481386,
      0.3607615730481386,
      0.46791393457269104,
      0.46791393457269104,
      0.17132449237917036,
      0.17132449237917036
    ],
    [
      0.4179591836734694,
      0.3818300505051189,
      0.3818300505051189,
      0.27970539148927664,
      0.27970539148927664,
      0.1294849661688697,
      0.1294849661688697
    ],
    [
      0.362683783378362,
      0.362683783378362,
      0.31370664587788727,
      0.31370664587788727,
      0.22238103445337448,
      0.22238103445337448,
      0.10122853629037626,
      0.10122853629037626
    ],
    [
      0.3302393550012598,
      0.1806481606948574,
      0.1806481606948574,
      0.08127438836157441,
      0.08127438836157441,
      0.31234707704000286,
      0.31234707704000286,
      0.26061069640293544,
      0.26061069640293544
    ],
    [
      0.29552422471475287,
      0.29552422471475287,
      0.26926671930999635,
      0.26926671930999635,
      0.21908636251598204,
      0.21908636251598204,
      0.1494513491505806,
      0.1494513491505806,
      0.06667134430868814,
      0.06667134430868814
    ],
    [
      0.2729250867779006,
      0.26280454451024665,
      0.26280454451024665,
      0.23319376459199048,
      0.23319376459199048,
      0.18629021092773426,
      0.18629021092773426,
      0.1255803694649046,
      0.1255803694649046,
      0.05566856711617366,
      0.05566856711617366
    ],
    [
      0.24914704581340277,
      0.24914704581340277,
      0.2334925365383548,
      0.2334925365383548,
      0.20316742672306592,
      0.20316742672306592,
      0.16007832854334622,
      0.16007832854334622,
      0.10693932599531843,
      0.10693932599531843,
      0.04717533638651183,
      0.04717533638651183
    ],
    [
      0.2325515532308739,
      0.22628318026289723,
      0.22628318026289723,
      0.2078160475368885,
      0.2078160475368885,
      0.17814598076194574,
      0.17814598076194574,
      0.13887351021978725,
      0.13887351021978725,
      0.09212149983772845,
      0.09212149983772845,
      0.04048400476531588,
      0.04048400476531588
    ],
    [
      0.2152638534631578,
      0.2152638534631578,
      0.2051984637212956,
      0.2051984637212956,
      0.18553839747793782,
      0.18553839747793782,
      0.15720316715819355,
      0.15720316715819355,
      0.12151857068790319,
      0.12151857068790319,
      0.08015808715976021,
      0.08015808715976021,
      0.03511946033175186,
      0.03511946033175186
    ],
    [
      0.2025782419255613,
      0.19843148532711158,
      0.19843148532711158,
      0.1861610000155622,
      0.1861610000155622,
      0.16626920581699392,
      0.16626920581699392,
      0.13957067792615432,
      0.13957067792615432,
      0.10715922046717194,
      0.10715922046717194,
      0.07036604748810812,
      0.07036604748810812,
      0.03075324199611727,
      0.03075324199611727
    ],
    [
      0.1894506104550685,
      0.1894506104550685,
      0.18260341504492358,
      0.18260341504492358,
      0.16915651939500254,
      0.16915651939500254,
      0.14959598881657674,
      0.14959598881657674,
      0.12462897125553388,
      0.12462897125553388,
      0.09515851168249279,
      0.09515851168249279,
      0.062253523938647894,
      0.062253523938647894,
      0.027152459411754096,
      0.027152459411754096
    ],
    [
      0.17944647035620653,
      0.17656270536699264,
      0.17656270536699264,
      0.16800410215645004,
      0.16800410215645004,
      0.15404576107681028,
      0.15404576107681028,
      0.13513636846852548,
      0.13513636846852548,
      0.11188384719340397,
      0.11188384719340397,
      0.08503614831717918,
      0.08503614831717918,
      0.0554595293739872,
      0.0554595293739872,
      0.02414830286854793,
      0.02414830286854793
    ],
    [
      0.1691423829631436,
      0.1691423829631436,
      0.16427648374583273,
      0.16427648374583273,
      0.15468467512626524,
      0.15468467512626524,
      0.14064291467065065,
      0.14064291467065065,
      0.12255520671147846,
      0.12255520671147846,
      0.10094204410628717,
      0.10094204410628717,
      0.07642573025488905,
      0.07642573025488905,
      0.0497145488949698,
      0.0497145488949698,
      0.02161601352648331,
      0.02161601352648331
    ],
    [
      0.1610544498487837,
      0.15896884339395434,
      0.15896884339395434,
      0.15276604206585967,
      0.15276604206585967,
      0.1426067021736066,
      0.1426067021736066,
      0.12875396253933621,
      0.12875396253933621,
      0.11156664554733399,
      0.11156664554733399,
      0.09149002162245,
      0.09149002162245,
      0.06904454273764123,
      0.06904454273764123,
      0.0448142267656996,
      0.0448142267656996,
      0.019461788229726478,
      0.019461788229726478
    ],
    [
      0.15275338713072584,
      0.15275338713072584,
      0.14917298647260374,
      0.14917298647260374,
      0.14209610931838204,
      0.14209610931838204,
      0.13168863844917664,
      0.13168863844917664,
      0.11819453196151841,
      0.11819453196151841,
      0.10193011981724044,
      0.10193011981724044,
      0.08327674157670475,
      0.08327674157670475,
      0.06267204833410907,
      0.06267204833410907,
      0.04060142980038694,
      0.04060142980038694,
      0.017614007139152118,
      0.017614007139152118
    ],
    [
      0.14608113364969041,
      0.14452440398997005,
      0.14452440398997005,
      0.13988739479107315,
      0.13988739479107315,
      0.13226893863333747,
      0.13226893863333747,
      0.12183141605372853,
      0.12183141605372853,
      0.10879729916714838,
      0.10879729916714838,
      0.09344442345603386,
      0.09344442345603386,
      0.0761001136283793,
      0.0761001136283793,
      0.057134425426857205,
      0.057134425426857205,
      0.036953789770852494,
      0.036953789770852494,
      0.016017228257774335,
      0.016017228257774335
    ],
    [
      0.13925187285563198,
      0.13925187285563198,
      0.13654149834601517,
      0.13654149834601517,
      0.13117350478706238,
      0.13117350478706238,
      0.12325237681051242,
      0.12325237681051242,
      0.11293229608053922,
      0.11293229608053922,
      0.10041414444288096,
      0.10041414444288096,
      0.08594160621706773,
      0.08594160621706773,
      0.06979646842452049,
      0.06979646842452049,
      0.052293335152683286,
      0.052293335152683286,
      0.03377490158481415,
      0.03377490158481415,
      0.0146279952982722,
      0.0146279952982722
    ],
    [
      0.13365457218610619,
      0.1324620394046966,
      0.1324620394046966,
      0.12890572218808216,
      0.12890572218808216,
      0.12304908430672953,
      0.12304908430672953,
      0.11499664022241136,
      0.11499664022241136,
      0.10489209146454141,
      0.10489209146454141,
      0.09291576606003515,
      0.09291576606003515,
      0.07928141177671895,
      0.07928141177671895,
      0.06423242140852585,
      0.06423242140852585,
      0.04803767173108467,
      0.04803767173108467,
      0.030988005856979445,
      0.030988005856979445,
      0.013411859487141771,
      0.013411859487141771
    ],
    [
      0.12793819534675216,
      0.12793819534675216,
      0.1258374563468283,
      0.1258374563468283,
      0.12167047292780339,
      0.12167047292780339,
      0.1155056680537256,
      0.1155056680537256,
      0.10744427011596563,
      0.10744427011596563,
      0.09761865210411388,
      0.09761865210411388,
      0.08619016153195327,
      0.08619016153195327,
      0.0733464814110803,
      0.0733464814110803,
      0.05929858491543678,
      0.05929858491543678,
      0.04427743881741981,
      0.04427743881741981,
      0.028531388628933663,
      0.028531388628933663,
      0.0123412297999872,
      0.0123412297999872
    ]
  ], s.binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
  const t = (a, o, h) => {
    let l, A, u;
    l = h / 2, A = 0;
    for (let d = 0; d < 20; d++)
      u = l * s.tValues[20][d] + l, A += s.cValues[20][d] * i(a, o, u);
    return l * A;
  };
  s.getCubicArcLength = t;
  const e = (a, o, h) => {
    h === void 0 && (h = 1);
    const l = a[0] - 2 * a[1] + a[2], A = o[0] - 2 * o[1] + o[2], u = 2 * a[1] - 2 * a[0], f = 2 * o[1] - 2 * o[0], d = 4 * (l * l + A * A), c = 4 * (l * u + A * f), p = u * u + f * f;
    if (d === 0)
      return h * Math.sqrt(Math.pow(a[2] - a[0], 2) + Math.pow(o[2] - o[0], 2));
    const m = c / (2 * d), v = p / d, x = h + m, g = v - m * m, y = x * x + g > 0 ? Math.sqrt(x * x + g) : 0, _ = m * m + g > 0 ? Math.sqrt(m * m + g) : 0, b = m + Math.sqrt(m * m + g) !== 0 ? g * Math.log(Math.abs((x + y) / (m + _))) : 0;
    return Math.sqrt(d) / 2 * (x * y - m * _ + b);
  };
  s.getQuadraticArcLength = e;
  function i(a, o, h) {
    const l = n(1, h, a), A = n(1, h, o), u = l * l + A * A;
    return Math.sqrt(u);
  }
  const n = (a, o, h) => {
    const l = h.length - 1;
    let A, u;
    if (l === 0)
      return 0;
    if (a === 0) {
      u = 0;
      for (let f = 0; f <= l; f++)
        u += s.binomialCoefficients[l][f] * Math.pow(1 - o, l - f) * Math.pow(o, f) * h[f];
      return u;
    } else {
      A = new Array(l);
      for (let f = 0; f < l; f++)
        A[f] = l * (h[f + 1] - h[f]);
      return n(a - 1, o, A);
    }
  }, r = (a, o, h) => {
    let l = 1, A = a / o, u = (a - h(A)) / o, f = 0;
    for (; l > 1e-3; ) {
      const d = h(A + u), c = Math.abs(a - d) / o;
      if (c < l)
        l = c, A += u;
      else {
        const p = h(A - u), m = Math.abs(a - p) / o;
        m < l ? (l = m, A -= u) : u /= 2;
      }
      if (f++, f > 500)
        break;
    }
    return A;
  };
  s.t2length = r;
})(Ja);
Object.defineProperty(ni, "__esModule", { value: !0 });
var _i = ni.Path = void 0;
const sl = H, al = ft, ol = V, Ne = Ja;
class ut extends al.Shape {
  constructor(t) {
    super(t), this.dataArray = [], this.pathLength = 0, this._readDataAttribute(), this.on("dataChange.konva", function() {
      this._readDataAttribute();
    });
  }
  _readDataAttribute() {
    this.dataArray = ut.parsePathData(this.data()), this.pathLength = ut.getPathLength(this.dataArray);
  }
  _sceneFunc(t) {
    var e = this.dataArray;
    t.beginPath();
    for (var i = !1, n = 0; n < e.length; n++) {
      var r = e[n].command, a = e[n].points;
      switch (r) {
        case "L":
          t.lineTo(a[0], a[1]);
          break;
        case "M":
          t.moveTo(a[0], a[1]);
          break;
        case "C":
          t.bezierCurveTo(a[0], a[1], a[2], a[3], a[4], a[5]);
          break;
        case "Q":
          t.quadraticCurveTo(a[0], a[1], a[2], a[3]);
          break;
        case "A":
          var o = a[0], h = a[1], l = a[2], A = a[3], u = a[4], f = a[5], d = a[6], c = a[7], p = l > A ? l : A, m = l > A ? 1 : l / A, v = l > A ? A / l : 1;
          t.translate(o, h), t.rotate(d), t.scale(m, v), t.arc(0, 0, p, u, u + f, 1 - c), t.scale(1 / m, 1 / v), t.rotate(-d), t.translate(-o, -h);
          break;
        case "z":
          i = !0, t.closePath();
          break;
      }
    }
    !i && !this.hasFill() ? t.strokeShape(this) : t.fillStrokeShape(this);
  }
  getSelfRect() {
    var t = [];
    this.dataArray.forEach(function(l) {
      if (l.command === "A") {
        var A = l.points[4], u = l.points[5], f = l.points[4] + u, d = Math.PI / 180;
        if (Math.abs(A - f) < d && (d = Math.abs(A - f)), u < 0)
          for (let c = A - d; c > f; c -= d) {
            const p = ut.getPointOnEllipticalArc(l.points[0], l.points[1], l.points[2], l.points[3], c, 0);
            t.push(p.x, p.y);
          }
        else
          for (let c = A + d; c < f; c += d) {
            const p = ut.getPointOnEllipticalArc(l.points[0], l.points[1], l.points[2], l.points[3], c, 0);
            t.push(p.x, p.y);
          }
      } else if (l.command === "C")
        for (let c = 0; c <= 1; c += 0.01) {
          const p = ut.getPointOnCubicBezier(c, l.start.x, l.start.y, l.points[0], l.points[1], l.points[2], l.points[3], l.points[4], l.points[5]);
          t.push(p.x, p.y);
        }
      else
        t = t.concat(l.points);
    });
    for (var e = t[0], i = t[0], n = t[1], r = t[1], a, o, h = 0; h < t.length / 2; h++)
      a = t[h * 2], o = t[h * 2 + 1], isNaN(a) || (e = Math.min(e, a), i = Math.max(i, a)), isNaN(o) || (n = Math.min(n, o), r = Math.max(r, o));
    return {
      x: e,
      y: n,
      width: i - e,
      height: r - n
    };
  }
  getLength() {
    return this.pathLength;
  }
  getPointAtLength(t) {
    return ut.getPointAtLengthOfDataArray(t, this.dataArray);
  }
  static getLineLength(t, e, i, n) {
    return Math.sqrt((i - t) * (i - t) + (n - e) * (n - e));
  }
  static getPathLength(t) {
    let e = 0;
    for (var i = 0; i < t.length; ++i)
      e += t[i].pathLength;
    return e;
  }
  static getPointAtLengthOfDataArray(t, e) {
    var i, n = 0, r = e.length;
    if (!r)
      return null;
    for (; n < r && t > e[n].pathLength; )
      t -= e[n].pathLength, ++n;
    if (n === r)
      return i = e[n - 1].points.slice(-2), {
        x: i[0],
        y: i[1]
      };
    if (t < 0.01)
      return i = e[n].points.slice(0, 2), {
        x: i[0],
        y: i[1]
      };
    var a = e[n], o = a.points;
    switch (a.command) {
      case "L":
        return ut.getPointOnLine(t, a.start.x, a.start.y, o[0], o[1]);
      case "C":
        return ut.getPointOnCubicBezier((0, Ne.t2length)(t, ut.getPathLength(e), (p) => (0, Ne.getCubicArcLength)([a.start.x, o[0], o[2], o[4]], [a.start.y, o[1], o[3], o[5]], p)), a.start.x, a.start.y, o[0], o[1], o[2], o[3], o[4], o[5]);
      case "Q":
        return ut.getPointOnQuadraticBezier((0, Ne.t2length)(t, ut.getPathLength(e), (p) => (0, Ne.getQuadraticArcLength)([a.start.x, o[0], o[2]], [a.start.y, o[1], o[3]], p)), a.start.x, a.start.y, o[0], o[1], o[2], o[3]);
      case "A":
        var h = o[0], l = o[1], A = o[2], u = o[3], f = o[4], d = o[5], c = o[6];
        return f += d * t / a.pathLength, ut.getPointOnEllipticalArc(h, l, A, u, f, c);
    }
    return null;
  }
  static getPointOnLine(t, e, i, n, r, a, o) {
    a === void 0 && (a = e), o === void 0 && (o = i);
    var h = (r - i) / (n - e + 1e-8), l = Math.sqrt(t * t / (1 + h * h));
    n < e && (l *= -1);
    var A = h * l, u;
    if (n === e)
      u = {
        x: a,
        y: o + A
      };
    else if ((o - i) / (a - e + 1e-8) === h)
      u = {
        x: a + l,
        y: o + A
      };
    else {
      var f, d, c = this.getLineLength(e, i, n, r), p = (a - e) * (n - e) + (o - i) * (r - i);
      p = p / (c * c), f = e + p * (n - e), d = i + p * (r - i);
      var m = this.getLineLength(a, o, f, d), v = Math.sqrt(t * t - m * m);
      l = Math.sqrt(v * v / (1 + h * h)), n < e && (l *= -1), A = h * l, u = {
        x: f + l,
        y: d + A
      };
    }
    return u;
  }
  static getPointOnCubicBezier(t, e, i, n, r, a, o, h, l) {
    function A(m) {
      return m * m * m;
    }
    function u(m) {
      return 3 * m * m * (1 - m);
    }
    function f(m) {
      return 3 * m * (1 - m) * (1 - m);
    }
    function d(m) {
      return (1 - m) * (1 - m) * (1 - m);
    }
    var c = h * A(t) + a * u(t) + n * f(t) + e * d(t), p = l * A(t) + o * u(t) + r * f(t) + i * d(t);
    return {
      x: c,
      y: p
    };
  }
  static getPointOnQuadraticBezier(t, e, i, n, r, a, o) {
    function h(d) {
      return d * d;
    }
    function l(d) {
      return 2 * d * (1 - d);
    }
    function A(d) {
      return (1 - d) * (1 - d);
    }
    var u = a * h(t) + n * l(t) + e * A(t), f = o * h(t) + r * l(t) + i * A(t);
    return {
      x: u,
      y: f
    };
  }
  static getPointOnEllipticalArc(t, e, i, n, r, a) {
    var o = Math.cos(a), h = Math.sin(a), l = {
      x: i * Math.cos(r),
      y: n * Math.sin(r)
    };
    return {
      x: t + (l.x * o - l.y * h),
      y: e + (l.x * h + l.y * o)
    };
  }
  static parsePathData(t) {
    if (!t)
      return [];
    var e = t, i = [
      "m",
      "M",
      "l",
      "L",
      "v",
      "V",
      "h",
      "H",
      "z",
      "Z",
      "c",
      "C",
      "q",
      "Q",
      "t",
      "T",
      "s",
      "S",
      "a",
      "A"
    ];
    e = e.replace(new RegExp(" ", "g"), ",");
    for (var n = 0; n < i.length; n++)
      e = e.replace(new RegExp(i[n], "g"), "|" + i[n]);
    var r = e.split("|"), a = [], o = [], h = 0, l = 0, A = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi, u;
    for (n = 1; n < r.length; n++) {
      var f = r[n], d = f.charAt(0);
      for (f = f.slice(1), o.length = 0; u = A.exec(f); )
        o.push(u[0]);
      for (var c = [], p = 0, m = o.length; p < m; p++) {
        if (o[p] === "00") {
          c.push(0, 0);
          continue;
        }
        var v = parseFloat(o[p]);
        isNaN(v) ? c.push(0) : c.push(v);
      }
      for (; c.length > 0 && !isNaN(c[0]); ) {
        var x = "", g = [], y = h, _ = l, b, C, w, E, S, P, k, F, I, T;
        switch (d) {
          case "l":
            h += c.shift(), l += c.shift(), x = "L", g.push(h, l);
            break;
          case "L":
            h = c.shift(), l = c.shift(), g.push(h, l);
            break;
          case "m":
            var R = c.shift(), L = c.shift();
            if (h += R, l += L, x = "M", a.length > 2 && a[a.length - 1].command === "z") {
              for (var B = a.length - 2; B >= 0; B--)
                if (a[B].command === "M") {
                  h = a[B].points[0] + R, l = a[B].points[1] + L;
                  break;
                }
            }
            g.push(h, l), d = "l";
            break;
          case "M":
            h = c.shift(), l = c.shift(), x = "M", g.push(h, l), d = "L";
            break;
          case "h":
            h += c.shift(), x = "L", g.push(h, l);
            break;
          case "H":
            h = c.shift(), x = "L", g.push(h, l);
            break;
          case "v":
            l += c.shift(), x = "L", g.push(h, l);
            break;
          case "V":
            l = c.shift(), x = "L", g.push(h, l);
            break;
          case "C":
            g.push(c.shift(), c.shift(), c.shift(), c.shift()), h = c.shift(), l = c.shift(), g.push(h, l);
            break;
          case "c":
            g.push(h + c.shift(), l + c.shift(), h + c.shift(), l + c.shift()), h += c.shift(), l += c.shift(), x = "C", g.push(h, l);
            break;
          case "S":
            C = h, w = l, b = a[a.length - 1], b.command === "C" && (C = h + (h - b.points[2]), w = l + (l - b.points[3])), g.push(C, w, c.shift(), c.shift()), h = c.shift(), l = c.shift(), x = "C", g.push(h, l);
            break;
          case "s":
            C = h, w = l, b = a[a.length - 1], b.command === "C" && (C = h + (h - b.points[2]), w = l + (l - b.points[3])), g.push(C, w, h + c.shift(), l + c.shift()), h += c.shift(), l += c.shift(), x = "C", g.push(h, l);
            break;
          case "Q":
            g.push(c.shift(), c.shift()), h = c.shift(), l = c.shift(), g.push(h, l);
            break;
          case "q":
            g.push(h + c.shift(), l + c.shift()), h += c.shift(), l += c.shift(), x = "Q", g.push(h, l);
            break;
          case "T":
            C = h, w = l, b = a[a.length - 1], b.command === "Q" && (C = h + (h - b.points[0]), w = l + (l - b.points[1])), h = c.shift(), l = c.shift(), x = "Q", g.push(C, w, h, l);
            break;
          case "t":
            C = h, w = l, b = a[a.length - 1], b.command === "Q" && (C = h + (h - b.points[0]), w = l + (l - b.points[1])), h += c.shift(), l += c.shift(), x = "Q", g.push(C, w, h, l);
            break;
          case "A":
            E = c.shift(), S = c.shift(), P = c.shift(), k = c.shift(), F = c.shift(), I = h, T = l, h = c.shift(), l = c.shift(), x = "A", g = this.convertEndpointToCenterParameterization(I, T, h, l, k, F, E, S, P);
            break;
          case "a":
            E = c.shift(), S = c.shift(), P = c.shift(), k = c.shift(), F = c.shift(), I = h, T = l, h += c.shift(), l += c.shift(), x = "A", g = this.convertEndpointToCenterParameterization(I, T, h, l, k, F, E, S, P);
            break;
        }
        a.push({
          command: x || d,
          points: g,
          start: {
            x: y,
            y: _
          },
          pathLength: this.calcLength(y, _, x || d, g)
        });
      }
      (d === "z" || d === "Z") && a.push({
        command: "z",
        points: [],
        start: void 0,
        pathLength: 0
      });
    }
    return a;
  }
  static calcLength(t, e, i, n) {
    var r, a, o, h, l = ut;
    switch (i) {
      case "L":
        return l.getLineLength(t, e, n[0], n[1]);
      case "C":
        return (0, Ne.getCubicArcLength)([t, n[0], n[2], n[4]], [e, n[1], n[3], n[5]], 1);
      case "Q":
        return (0, Ne.getQuadraticArcLength)([t, n[0], n[2]], [e, n[1], n[3]], 1);
      case "A":
        r = 0;
        var A = n[4], u = n[5], f = n[4] + u, d = Math.PI / 180;
        if (Math.abs(A - f) < d && (d = Math.abs(A - f)), a = l.getPointOnEllipticalArc(n[0], n[1], n[2], n[3], A, 0), u < 0)
          for (h = A - d; h > f; h -= d)
            o = l.getPointOnEllipticalArc(n[0], n[1], n[2], n[3], h, 0), r += l.getLineLength(a.x, a.y, o.x, o.y), a = o;
        else
          for (h = A + d; h < f; h += d)
            o = l.getPointOnEllipticalArc(n[0], n[1], n[2], n[3], h, 0), r += l.getLineLength(a.x, a.y, o.x, o.y), a = o;
        return o = l.getPointOnEllipticalArc(n[0], n[1], n[2], n[3], f, 0), r += l.getLineLength(a.x, a.y, o.x, o.y), r;
    }
    return 0;
  }
  static convertEndpointToCenterParameterization(t, e, i, n, r, a, o, h, l) {
    var A = l * (Math.PI / 180), u = Math.cos(A) * (t - i) / 2 + Math.sin(A) * (e - n) / 2, f = -1 * Math.sin(A) * (t - i) / 2 + Math.cos(A) * (e - n) / 2, d = u * u / (o * o) + f * f / (h * h);
    d > 1 && (o *= Math.sqrt(d), h *= Math.sqrt(d));
    var c = Math.sqrt((o * o * (h * h) - o * o * (f * f) - h * h * (u * u)) / (o * o * (f * f) + h * h * (u * u)));
    r === a && (c *= -1), isNaN(c) && (c = 0);
    var p = c * o * f / h, m = c * -h * u / o, v = (t + i) / 2 + Math.cos(A) * p - Math.sin(A) * m, x = (e + n) / 2 + Math.sin(A) * p + Math.cos(A) * m, g = function(S) {
      return Math.sqrt(S[0] * S[0] + S[1] * S[1]);
    }, y = function(S, P) {
      return (S[0] * P[0] + S[1] * P[1]) / (g(S) * g(P));
    }, _ = function(S, P) {
      return (S[0] * P[1] < S[1] * P[0] ? -1 : 1) * Math.acos(y(S, P));
    }, b = _([1, 0], [(u - p) / o, (f - m) / h]), C = [(u - p) / o, (f - m) / h], w = [(-1 * u - p) / o, (-1 * f - m) / h], E = _(C, w);
    return y(C, w) <= -1 && (E = Math.PI), y(C, w) >= 1 && (E = 0), a === 0 && E > 0 && (E = E - 2 * Math.PI), a === 1 && E < 0 && (E = E + 2 * Math.PI), [v, x, o, h, b, E, A, a];
  }
}
_i = ni.Path = ut;
ut.prototype.className = "Path";
ut.prototype._attrsAffectingSize = ["data"];
(0, ol._registerNode)(ut);
sl.Factory.addGetterSetter(ut, "data");
var Oi = {};
Object.defineProperty(Oi, "__esModule", { value: !0 });
var to = Oi.Rect = void 0;
const hl = H, ll = ft, Al = V, dl = rt, cl = N;
class Pn extends ll.Shape {
  _sceneFunc(t) {
    var e = this.cornerRadius(), i = this.width(), n = this.height();
    t.beginPath(), e ? dl.Util.drawRoundedRectPath(t, i, n, e) : t.rect(0, 0, i, n), t.closePath(), t.fillStrokeShape(this);
  }
}
to = Oi.Rect = Pn;
Pn.prototype.className = "Rect";
(0, Al._registerNode)(Pn);
hl.Factory.addGetterSetter(Pn, "cornerRadius", 0, (0, cl.getNumberOrArrayOfNumbersValidator)(4));
const on = (s, t = !1) => {
  let e = s;
  const i = t ? s.getTransform().copy() : new rt.Transform();
  for (; e = e.parent; )
    i.multiply(e.getTransform());
  return i;
};
function Iu(s) {
  const [t, e, i, n] = s.m, r = Math.sqrt(t * t + i * i), a = Math.sqrt(e * e + n * n), o = Math.atan2(i, t), h = o, l = o + Math.PI / 2;
  return console.log(h, l), { x: r, y: a };
}
const Nt = (s, t, e = !1) => {
  let i = s, n = e ? s.scale() : { x: 1, y: 1 };
  for (; i = i.parent; ) {
    const r = i.scale();
    n.x *= r.x, n.y *= r.y;
  }
  return [t[0] / n.x, t[1] / n.y];
};
var ri = {}, Pe = {};
Object.defineProperty(Pe, "__esModule", { value: !0 });
Pe.Container = void 0;
const si = H, mr = st, En = N;
let Ee = class extends mr.Node {
  constructor() {
    super(...arguments), this.children = [];
  }
  getChildren(t) {
    if (!t)
      return this.children || [];
    const e = this.children || [];
    var i = [];
    return e.forEach(function(n) {
      t(n) && i.push(n);
    }), i;
  }
  hasChildren() {
    return this.getChildren().length > 0;
  }
  removeChildren() {
    return this.getChildren().forEach((t) => {
      t.parent = null, t.index = 0, t.remove();
    }), this.children = [], this._requestDraw(), this;
  }
  destroyChildren() {
    return this.getChildren().forEach((t) => {
      t.parent = null, t.index = 0, t.destroy();
    }), this.children = [], this._requestDraw(), this;
  }
  add(...t) {
    if (t.length === 0)
      return this;
    if (t.length > 1) {
      for (var e = 0; e < t.length; e++)
        this.add(t[e]);
      return this;
    }
    const i = t[0];
    return i.getParent() ? (i.moveTo(this), this) : (this._validateAdd(i), i.index = this.getChildren().length, i.parent = this, i._clearCaches(), this.getChildren().push(i), this._fire("add", {
      child: i
    }), this._requestDraw(), this);
  }
  destroy() {
    return this.hasChildren() && this.destroyChildren(), super.destroy(), this;
  }
  find(t) {
    return this._generalFind(t, !1);
  }
  findOne(t) {
    var e = this._generalFind(t, !0);
    return e.length > 0 ? e[0] : void 0;
  }
  _generalFind(t, e) {
    var i = [];
    return this._descendants((n) => {
      const r = n._isMatch(t);
      return r && i.push(n), !!(r && e);
    }), i;
  }
  _descendants(t) {
    let e = !1;
    const i = this.getChildren();
    for (const n of i) {
      if (e = t(n), e)
        return !0;
      if (n.hasChildren() && (e = n._descendants(t), e))
        return !0;
    }
    return !1;
  }
  toObject() {
    var t = mr.Node.prototype.toObject.call(this);
    return t.children = [], this.getChildren().forEach((e) => {
      t.children.push(e.toObject());
    }), t;
  }
  isAncestorOf(t) {
    for (var e = t.getParent(); e; ) {
      if (e._id === this._id)
        return !0;
      e = e.getParent();
    }
    return !1;
  }
  clone(t) {
    var e = mr.Node.prototype.clone.call(this, t);
    return this.getChildren().forEach(function(i) {
      e.add(i.clone());
    }), e;
  }
  getAllIntersections(t) {
    var e = [];
    return this.find("Shape").forEach((i) => {
      i.isVisible() && i.intersects(t) && e.push(i);
    }), e;
  }
  _clearSelfAndDescendantCache(t) {
    var e;
    super._clearSelfAndDescendantCache(t), !this.isCached() && ((e = this.children) === null || e === void 0 || e.forEach(function(i) {
      i._clearSelfAndDescendantCache(t);
    }));
  }
  _setChildrenIndices() {
    var t;
    (t = this.children) === null || t === void 0 || t.forEach(function(e, i) {
      e.index = i;
    }), this._requestDraw();
  }
  drawScene(t, e, i) {
    var n = this.getLayer(), r = t || n && n.getCanvas(), a = r && r.getContext(), o = this._getCanvasCache(), h = o && o.scene, l = r && r.isCache;
    if (!this.isVisible() && !l)
      return this;
    if (h) {
      a.save();
      var A = this.getAbsoluteTransform(e).getMatrix();
      a.transform(A[0], A[1], A[2], A[3], A[4], A[5]), this._drawCachedSceneCanvas(a), a.restore();
    } else
      this._drawChildren("drawScene", r, e, i);
    return this;
  }
  drawHit(t, e) {
    if (!this.shouldDrawHit(e))
      return this;
    var i = this.getLayer(), n = t || i && i.hitCanvas, r = n && n.getContext(), a = this._getCanvasCache(), o = a && a.hit;
    if (o) {
      r.save();
      var h = this.getAbsoluteTransform(e).getMatrix();
      r.transform(h[0], h[1], h[2], h[3], h[4], h[5]), this._drawCachedHitCanvas(r), r.restore();
    } else
      this._drawChildren("drawHit", n, e);
    return this;
  }
  _drawChildren(t, e, i, n) {
    var r, a = e && e.getContext(), o = this.clipWidth(), h = this.clipHeight(), l = this.clipFunc(), A = typeof o == "number" && typeof h == "number" || l;
    const u = i === this;
    if (A) {
      a.save();
      var f = this.getAbsoluteTransform(i), d = f.getMatrix();
      a.transform(d[0], d[1], d[2], d[3], d[4], d[5]), a.beginPath();
      let v;
      if (l)
        v = l.call(this, a, this);
      else {
        var c = this.clipX(), p = this.clipY();
        a.rect(c || 0, p || 0, o, h);
      }
      a.clip.apply(a, v), d = f.copy().invert().getMatrix(), a.transform(d[0], d[1], d[2], d[3], d[4], d[5]);
    }
    var m = !u && this.globalCompositeOperation() !== "source-over" && t === "drawScene";
    m && (a.save(), a._applyGlobalCompositeOperation(this)), (r = this.children) === null || r === void 0 || r.forEach(function(v) {
      v[t](e, i, n);
    }), m && a.restore(), A && a.restore();
  }
  getClientRect(t = {}) {
    var e, i = t.skipTransform, n = t.relativeTo, r, a, o, h, l = {
      x: 1 / 0,
      y: 1 / 0,
      width: 0,
      height: 0
    }, A = this;
    (e = this.children) === null || e === void 0 || e.forEach(function(p) {
      if (p.visible()) {
        var m = p.getClientRect({
          relativeTo: A,
          skipShadow: t.skipShadow,
          skipStroke: t.skipStroke
        });
        m.width === 0 && m.height === 0 || (r === void 0 ? (r = m.x, a = m.y, o = m.x + m.width, h = m.y + m.height) : (r = Math.min(r, m.x), a = Math.min(a, m.y), o = Math.max(o, m.x + m.width), h = Math.max(h, m.y + m.height)));
      }
    });
    for (var u = this.find("Shape"), f = !1, d = 0; d < u.length; d++) {
      var c = u[d];
      if (c._isVisible(this)) {
        f = !0;
        break;
      }
    }
    return f && r !== void 0 ? l = {
      x: r,
      y: a,
      width: o - r,
      height: h - a
    } : l = {
      x: 0,
      y: 0,
      width: 0,
      height: 0
    }, i ? l : this._transformedRect(l, n);
  }
};
Pe.Container = Ee;
si.Factory.addComponentsGetterSetter(Ee, "clip", [
  "x",
  "y",
  "width",
  "height"
]);
si.Factory.addGetterSetter(Ee, "clipX", void 0, (0, En.getNumberValidator)());
si.Factory.addGetterSetter(Ee, "clipY", void 0, (0, En.getNumberValidator)());
si.Factory.addGetterSetter(Ee, "clipWidth", void 0, (0, En.getNumberValidator)());
si.Factory.addGetterSetter(Ee, "clipHeight", void 0, (0, En.getNumberValidator)());
si.Factory.addGetterSetter(Ee, "clipFunc");
Object.defineProperty(ri, "__esModule", { value: !0 });
var Yt = ri.Group = void 0;
const ul = rt, fl = Pe, gl = V;
class as extends fl.Container {
  _validateAdd(t) {
    var e = t.getType();
    e !== "Group" && e !== "Shape" && ul.Util.throw("You may only add groups and shapes to groups.");
  }
}
Yt = ri.Group = as;
as.prototype.nodeType = "Group";
(0, gl._registerNode)(as);
const Lu = (s, t = !1) => {
  const e = s.size, n = (s.realWidth || s.size[0]) / e[0], r = e.map((c) => c * n), a = (s.offset || [0, 0]).map((c) => c * n), o = s.strokeWidth ? s.strokeWidth * n : 1, h = s.strokeColor || "#000", l = s.paths.map(
    (c, p) => new _i({
      data: c,
      id: `path-${p}`,
      name: "path",
      strokeScaleEnabled: !!s.fixed,
      stroke: h,
      fill: h,
      scale: { x: n, y: n },
      strokeWidth: o
    })
  ), A = new to({
    x: a[0],
    y: a[1],
    name: "rect",
    width: r[0],
    height: r[1],
    fill: `rgba(0, 0, 0, ${t ? 0.3 : 0})`
  }), u = () => {
    let [c, p] = Nt(d, [1, 1]);
    d.scale({ x: c, y: p });
  }, f = new Yt();
  f.add(...l, A), f.x(-r[0] / 2), f.y(-r[1] / 2);
  const d = new Yt();
  return d.add(f), {
    getSize: () => {
      const c = A.getSize();
      if (s.fixed) {
        let [p] = Nt(d, [1, 1]);
        return [c.width * p, c.height * p];
      }
      return [c.width, c.height];
    },
    shape: d,
    setData(c) {
      console.log("set", c), d.position(c), s.fixed && u();
    },
    common() {
      l.forEach((c) => {
        c.fill(h);
      });
    }
  };
}, eo = (s) => {
  const e = s.evt.target.getBoundingClientRect(), i = s.evt.changedTouches[0].pageX - e.left, n = s.evt.changedTouches[0].pageY - e.top;
  return {
    offsetX: i,
    offsetY: n
  };
};
/**
 * @license
 * Copyright 2010-2024 Three.js Authors
 * SPDX-License-Identifier: MIT
 */
const io = "164", no = 300, Us = 1e3, Vi = 1001, Hs = 1002, Vs = 1003, pl = 1006, yl = 1008, ml = 1009, vl = 1014, _l = 1020, xl = 1023, vr = 1026, $s = 1027, ro = "", oe = "srgb", os = "srgb-linear", bl = "display-p3", so = "display-p3-linear", Hr = "linear", Ws = "srgb", Ys = "rec709", Xs = "p3", wl = 515, $i = 2e3, js = 2001;
class ao {
  addEventListener(t, e) {
    this._listeners === void 0 && (this._listeners = {});
    const i = this._listeners;
    i[t] === void 0 && (i[t] = []), i[t].indexOf(e) === -1 && i[t].push(e);
  }
  hasEventListener(t, e) {
    if (this._listeners === void 0)
      return !1;
    const i = this._listeners;
    return i[t] !== void 0 && i[t].indexOf(e) !== -1;
  }
  removeEventListener(t, e) {
    if (this._listeners === void 0)
      return;
    const n = this._listeners[t];
    if (n !== void 0) {
      const r = n.indexOf(e);
      r !== -1 && n.splice(r, 1);
    }
  }
  dispatchEvent(t) {
    if (this._listeners === void 0)
      return;
    const i = this._listeners[t.type];
    if (i !== void 0) {
      t.target = this;
      const n = i.slice(0);
      for (let r = 0, a = n.length; r < a; r++)
        n[r].call(this, t);
      t.target = null;
    }
  }
}
const pt = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
let qs = 1234567;
const oo = Math.PI / 180, ho = 180 / Math.PI;
function Fn() {
  const s = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, i = Math.random() * 4294967295 | 0;
  return (pt[s & 255] + pt[s >> 8 & 255] + pt[s >> 16 & 255] + pt[s >> 24 & 255] + "-" + pt[t & 255] + pt[t >> 8 & 255] + "-" + pt[t >> 16 & 15 | 64] + pt[t >> 24 & 255] + "-" + pt[e & 63 | 128] + pt[e >> 8 & 255] + "-" + pt[e >> 16 & 255] + pt[e >> 24 & 255] + pt[i & 255] + pt[i >> 8 & 255] + pt[i >> 16 & 255] + pt[i >> 24 & 255]).toLowerCase();
}
function mt(s, t, e) {
  return Math.max(t, Math.min(e, s));
}
function hs(s, t) {
  return (s % t + t) % t;
}
function Sl(s, t, e, i, n) {
  return i + (s - t) * (n - i) / (e - t);
}
function Cl(s, t, e) {
  return s !== t ? (e - s) / (t - s) : 0;
}
function xi(s, t, e) {
  return (1 - e) * s + e * t;
}
function Ml(s, t, e, i) {
  return xi(s, t, 1 - Math.exp(-e * i));
}
function Pl(s, t = 1) {
  return t - Math.abs(hs(s, t * 2) - t);
}
function El(s, t, e) {
  return s <= t ? 0 : s >= e ? 1 : (s = (s - t) / (e - t), s * s * (3 - 2 * s));
}
function Fl(s, t, e) {
  return s <= t ? 0 : s >= e ? 1 : (s = (s - t) / (e - t), s * s * s * (s * (s * 6 - 15) + 10));
}
function kl(s, t) {
  return s + Math.floor(Math.random() * (t - s + 1));
}
function Dl(s, t) {
  return s + Math.random() * (t - s);
}
function Tl(s) {
  return s * (0.5 - Math.random());
}
function Il(s) {
  s !== void 0 && (qs = s);
  let t = qs += 1831565813;
  return t = Math.imul(t ^ t >>> 15, t | 1), t ^= t + Math.imul(t ^ t >>> 7, t | 61), ((t ^ t >>> 14) >>> 0) / 4294967296;
}
function Rl(s) {
  return s * oo;
}
function Ll(s) {
  return s * ho;
}
function Ol(s) {
  return (s & s - 1) === 0 && s !== 0;
}
function Nl(s) {
  return Math.pow(2, Math.ceil(Math.log(s) / Math.LN2));
}
function Gl(s) {
  return Math.pow(2, Math.floor(Math.log(s) / Math.LN2));
}
function Bl(s, t, e, i, n) {
  const r = Math.cos, a = Math.sin, o = r(e / 2), h = a(e / 2), l = r((t + i) / 2), A = a((t + i) / 2), u = r((t - i) / 2), f = a((t - i) / 2), d = r((i - t) / 2), c = a((i - t) / 2);
  switch (n) {
    case "XYX":
      s.set(o * A, h * u, h * f, o * l);
      break;
    case "YZY":
      s.set(h * f, o * A, h * u, o * l);
      break;
    case "ZXZ":
      s.set(h * u, h * f, o * A, o * l);
      break;
    case "XZX":
      s.set(o * A, h * c, h * d, o * l);
      break;
    case "YXY":
      s.set(h * d, o * A, h * c, o * l);
      break;
    case "ZYZ":
      s.set(h * c, h * d, o * A, o * l);
      break;
    default:
      console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + n);
  }
}
function zl(s, t) {
  switch (t.constructor) {
    case Float32Array:
      return s;
    case Uint32Array:
      return s / 4294967295;
    case Uint16Array:
      return s / 65535;
    case Uint8Array:
      return s / 255;
    case Int32Array:
      return Math.max(s / 2147483647, -1);
    case Int16Array:
      return Math.max(s / 32767, -1);
    case Int8Array:
      return Math.max(s / 127, -1);
    default:
      throw new Error("Invalid component type.");
  }
}
function Ul(s, t) {
  switch (t.constructor) {
    case Float32Array:
      return s;
    case Uint32Array:
      return Math.round(s * 4294967295);
    case Uint16Array:
      return Math.round(s * 65535);
    case Uint8Array:
      return Math.round(s * 255);
    case Int32Array:
      return Math.round(s * 2147483647);
    case Int16Array:
      return Math.round(s * 32767);
    case Int8Array:
      return Math.round(s * 127);
    default:
      throw new Error("Invalid component type.");
  }
}
const be = {
  DEG2RAD: oo,
  RAD2DEG: ho,
  generateUUID: Fn,
  clamp: mt,
  euclideanModulo: hs,
  mapLinear: Sl,
  inverseLerp: Cl,
  lerp: xi,
  damp: Ml,
  pingpong: Pl,
  smoothstep: El,
  smootherstep: Fl,
  randInt: kl,
  randFloat: Dl,
  randFloatSpread: Tl,
  seededRandom: Il,
  degToRad: Rl,
  radToDeg: Ll,
  isPowerOfTwo: Ol,
  ceilPowerOfTwo: Nl,
  floorPowerOfTwo: Gl,
  setQuaternionFromProperEuler: Bl,
  normalize: Ul,
  denormalize: zl
};
class X {
  constructor(t = 0, e = 0) {
    X.prototype.isVector2 = !0, this.x = t, this.y = e;
  }
  get width() {
    return this.x;
  }
  set width(t) {
    this.x = t;
  }
  get height() {
    return this.y;
  }
  set height(t) {
    this.y = t;
  }
  set(t, e) {
    return this.x = t, this.y = e, this;
  }
  setScalar(t) {
    return this.x = t, this.y = t, this;
  }
  setX(t) {
    return this.x = t, this;
  }
  setY(t) {
    return this.y = t, this;
  }
  setComponent(t, e) {
    switch (t) {
      case 0:
        this.x = e;
        break;
      case 1:
        this.y = e;
        break;
      default:
        throw new Error("index is out of range: " + t);
    }
    return this;
  }
  getComponent(t) {
    switch (t) {
      case 0:
        return this.x;
      case 1:
        return this.y;
      default:
        throw new Error("index is out of range: " + t);
    }
  }
  clone() {
    return new this.constructor(this.x, this.y);
  }
  copy(t) {
    return this.x = t.x, this.y = t.y, this;
  }
  add(t) {
    return this.x += t.x, this.y += t.y, this;
  }
  addScalar(t) {
    return this.x += t, this.y += t, this;
  }
  addVectors(t, e) {
    return this.x = t.x + e.x, this.y = t.y + e.y, this;
  }
  addScaledVector(t, e) {
    return this.x += t.x * e, this.y += t.y * e, this;
  }
  sub(t) {
    return this.x -= t.x, this.y -= t.y, this;
  }
  subScalar(t) {
    return this.x -= t, this.y -= t, this;
  }
  subVectors(t, e) {
    return this.x = t.x - e.x, this.y = t.y - e.y, this;
  }
  multiply(t) {
    return this.x *= t.x, this.y *= t.y, this;
  }
  multiplyScalar(t) {
    return this.x *= t, this.y *= t, this;
  }
  divide(t) {
    return this.x /= t.x, this.y /= t.y, this;
  }
  divideScalar(t) {
    return this.multiplyScalar(1 / t);
  }
  applyMatrix3(t) {
    const e = this.x, i = this.y, n = t.elements;
    return this.x = n[0] * e + n[3] * i + n[6], this.y = n[1] * e + n[4] * i + n[7], this;
  }
  min(t) {
    return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this;
  }
  max(t) {
    return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this;
  }
  clamp(t, e) {
    return this.x = Math.max(t.x, Math.min(e.x, this.x)), this.y = Math.max(t.y, Math.min(e.y, this.y)), this;
  }
  clampScalar(t, e) {
    return this.x = Math.max(t, Math.min(e, this.x)), this.y = Math.max(t, Math.min(e, this.y)), this;
  }
  clampLength(t, e) {
    const i = this.length();
    return this.divideScalar(i || 1).multiplyScalar(Math.max(t, Math.min(e, i)));
  }
  floor() {
    return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this;
  }
  ceil() {
    return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this;
  }
  round() {
    return this.x = Math.round(this.x), this.y = Math.round(this.y), this;
  }
  roundToZero() {
    return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this;
  }
  negate() {
    return this.x = -this.x, this.y = -this.y, this;
  }
  dot(t) {
    return this.x * t.x + this.y * t.y;
  }
  cross(t) {
    return this.x * t.y - this.y * t.x;
  }
  lengthSq() {
    return this.x * this.x + this.y * this.y;
  }
  length() {
    return Math.sqrt(this.x * this.x + this.y * this.y);
  }
  manhattanLength() {
    return Math.abs(this.x) + Math.abs(this.y);
  }
  normalize() {
    return this.divideScalar(this.length() || 1);
  }
  angle() {
    return Math.atan2(-this.y, -this.x) + Math.PI;
  }
  angleTo(t) {
    const e = Math.sqrt(this.lengthSq() * t.lengthSq());
    if (e === 0)
      return Math.PI / 2;
    const i = this.dot(t) / e;
    return Math.acos(mt(i, -1, 1));
  }
  distanceTo(t) {
    return Math.sqrt(this.distanceToSquared(t));
  }
  distanceToSquared(t) {
    const e = this.x - t.x, i = this.y - t.y;
    return e * e + i * i;
  }
  manhattanDistanceTo(t) {
    return Math.abs(this.x - t.x) + Math.abs(this.y - t.y);
  }
  setLength(t) {
    return this.normalize().multiplyScalar(t);
  }
  lerp(t, e) {
    return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this;
  }
  lerpVectors(t, e, i) {
    return this.x = t.x + (e.x - t.x) * i, this.y = t.y + (e.y - t.y) * i, this;
  }
  equals(t) {
    return t.x === this.x && t.y === this.y;
  }
  fromArray(t, e = 0) {
    return this.x = t[e], this.y = t[e + 1], this;
  }
  toArray(t = [], e = 0) {
    return t[e] = this.x, t[e + 1] = this.y, t;
  }
  fromBufferAttribute(t, e) {
    return this.x = t.getX(e), this.y = t.getY(e), this;
  }
  rotateAround(t, e) {
    const i = Math.cos(e), n = Math.sin(e), r = this.x - t.x, a = this.y - t.y;
    return this.x = r * i - a * n + t.x, this.y = r * n + a * i + t.y, this;
  }
  random() {
    return this.x = Math.random(), this.y = Math.random(), this;
  }
  *[Symbol.iterator]() {
    yield this.x, yield this.y;
  }
}
class Zt {
  constructor(t, e, i, n, r, a, o, h, l) {
    Zt.prototype.isMatrix3 = !0, this.elements = [
      1,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      1
    ], t !== void 0 && this.set(t, e, i, n, r, a, o, h, l);
  }
  set(t, e, i, n, r, a, o, h, l) {
    const A = this.elements;
    return A[0] = t, A[1] = n, A[2] = o, A[3] = e, A[4] = r, A[5] = h, A[6] = i, A[7] = a, A[8] = l, this;
  }
  identity() {
    return this.set(
      1,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      1
    ), this;
  }
  copy(t) {
    const e = this.elements, i = t.elements;
    return e[0] = i[0], e[1] = i[1], e[2] = i[2], e[3] = i[3], e[4] = i[4], e[5] = i[5], e[6] = i[6], e[7] = i[7], e[8] = i[8], this;
  }
  extractBasis(t, e, i) {
    return t.setFromMatrix3Column(this, 0), e.setFromMatrix3Column(this, 1), i.setFromMatrix3Column(this, 2), this;
  }
  setFromMatrix4(t) {
    const e = t.elements;
    return this.set(
      e[0],
      e[4],
      e[8],
      e[1],
      e[5],
      e[9],
      e[2],
      e[6],
      e[10]
    ), this;
  }
  multiply(t) {
    return this.multiplyMatrices(this, t);
  }
  premultiply(t) {
    return this.multiplyMatrices(t, this);
  }
  multiplyMatrices(t, e) {
    const i = t.elements, n = e.elements, r = this.elements, a = i[0], o = i[3], h = i[6], l = i[1], A = i[4], u = i[7], f = i[2], d = i[5], c = i[8], p = n[0], m = n[3], v = n[6], x = n[1], g = n[4], y = n[7], _ = n[2], b = n[5], C = n[8];
    return r[0] = a * p + o * x + h * _, r[3] = a * m + o * g + h * b, r[6] = a * v + o * y + h * C, r[1] = l * p + A * x + u * _, r[4] = l * m + A * g + u * b, r[7] = l * v + A * y + u * C, r[2] = f * p + d * x + c * _, r[5] = f * m + d * g + c * b, r[8] = f * v + d * y + c * C, this;
  }
  multiplyScalar(t) {
    const e = this.elements;
    return e[0] *= t, e[3] *= t, e[6] *= t, e[1] *= t, e[4] *= t, e[7] *= t, e[2] *= t, e[5] *= t, e[8] *= t, this;
  }
  determinant() {
    const t = this.elements, e = t[0], i = t[1], n = t[2], r = t[3], a = t[4], o = t[5], h = t[6], l = t[7], A = t[8];
    return e * a * A - e * o * l - i * r * A + i * o * h + n * r * l - n * a * h;
  }
  invert() {
    const t = this.elements, e = t[0], i = t[1], n = t[2], r = t[3], a = t[4], o = t[5], h = t[6], l = t[7], A = t[8], u = A * a - o * l, f = o * h - A * r, d = l * r - a * h, c = e * u + i * f + n * d;
    if (c === 0)
      return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
    const p = 1 / c;
    return t[0] = u * p, t[1] = (n * l - A * i) * p, t[2] = (o * i - n * a) * p, t[3] = f * p, t[4] = (A * e - n * h) * p, t[5] = (n * r - o * e) * p, t[6] = d * p, t[7] = (i * h - l * e) * p, t[8] = (a * e - i * r) * p, this;
  }
  transpose() {
    let t;
    const e = this.elements;
    return t = e[1], e[1] = e[3], e[3] = t, t = e[2], e[2] = e[6], e[6] = t, t = e[5], e[5] = e[7], e[7] = t, this;
  }
  getNormalMatrix(t) {
    return this.setFromMatrix4(t).invert().transpose();
  }
  transposeIntoArray(t) {
    const e = this.elements;
    return t[0] = e[0], t[1] = e[3], t[2] = e[6], t[3] = e[1], t[4] = e[4], t[5] = e[7], t[6] = e[2], t[7] = e[5], t[8] = e[8], this;
  }
  setUvTransform(t, e, i, n, r, a, o) {
    const h = Math.cos(r), l = Math.sin(r);
    return this.set(
      i * h,
      i * l,
      -i * (h * a + l * o) + a + t,
      -n * l,
      n * h,
      -n * (-l * a + h * o) + o + e,
      0,
      0,
      1
    ), this;
  }
  //
  scale(t, e) {
    return this.premultiply(_r.makeScale(t, e)), this;
  }
  rotate(t) {
    return this.premultiply(_r.makeRotation(-t)), this;
  }
  translate(t, e) {
    return this.premultiply(_r.makeTranslation(t, e)), this;
  }
  // for 2D Transforms
  makeTranslation(t, e) {
    return t.isVector2 ? this.set(
      1,
      0,
      t.x,
      0,
      1,
      t.y,
      0,
      0,
      1
    ) : this.set(
      1,
      0,
      t,
      0,
      1,
      e,
      0,
      0,
      1
    ), this;
  }
  makeRotation(t) {
    const e = Math.cos(t), i = Math.sin(t);
    return this.set(
      e,
      -i,
      0,
      i,
      e,
      0,
      0,
      0,
      1
    ), this;
  }
  makeScale(t, e) {
    return this.set(
      t,
      0,
      0,
      0,
      e,
      0,
      0,
      0,
      1
    ), this;
  }
  //
  equals(t) {
    const e = this.elements, i = t.elements;
    for (let n = 0; n < 9; n++)
      if (e[n] !== i[n])
        return !1;
    return !0;
  }
  fromArray(t, e = 0) {
    for (let i = 0; i < 9; i++)
      this.elements[i] = t[i + e];
    return this;
  }
  toArray(t = [], e = 0) {
    const i = this.elements;
    return t[e] = i[0], t[e + 1] = i[1], t[e + 2] = i[2], t[e + 3] = i[3], t[e + 4] = i[4], t[e + 5] = i[5], t[e + 6] = i[6], t[e + 7] = i[7], t[e + 8] = i[8], t;
  }
  clone() {
    return new this.constructor().fromArray(this.elements);
  }
}
const _r = /* @__PURE__ */ new Zt();
function Qs(s) {
  return document.createElementNS("http://www.w3.org/1999/xhtml", s);
}
const Ks = /* @__PURE__ */ new Zt().set(
  0.8224621,
  0.177538,
  0,
  0.0331941,
  0.9668058,
  0,
  0.0170827,
  0.0723974,
  0.9105199
), Zs = /* @__PURE__ */ new Zt().set(
  1.2249401,
  -0.2249404,
  0,
  -0.0420569,
  1.0420571,
  0,
  -0.0196376,
  -0.0786361,
  1.0982735
), Wi = {
  [os]: {
    transfer: Hr,
    primaries: Ys,
    toReference: (s) => s,
    fromReference: (s) => s
  },
  [oe]: {
    transfer: Ws,
    primaries: Ys,
    toReference: (s) => s.convertSRGBToLinear(),
    fromReference: (s) => s.convertLinearToSRGB()
  },
  [so]: {
    transfer: Hr,
    primaries: Xs,
    toReference: (s) => s.applyMatrix3(Zs),
    fromReference: (s) => s.applyMatrix3(Ks)
  },
  [bl]: {
    transfer: Ws,
    primaries: Xs,
    toReference: (s) => s.convertSRGBToLinear().applyMatrix3(Zs),
    fromReference: (s) => s.applyMatrix3(Ks).convertLinearToSRGB()
  }
}, Hl = /* @__PURE__ */ new Set([os, so]), kt = {
  enabled: !0,
  _workingColorSpace: os,
  get workingColorSpace() {
    return this._workingColorSpace;
  },
  set workingColorSpace(s) {
    if (!Hl.has(s))
      throw new Error(`Unsupported working color space, "${s}".`);
    this._workingColorSpace = s;
  },
  convert: function(s, t, e) {
    if (this.enabled === !1 || t === e || !t || !e)
      return s;
    const i = Wi[t].toReference, n = Wi[e].fromReference;
    return n(i(s));
  },
  fromWorkingColorSpace: function(s, t) {
    return this.convert(s, this._workingColorSpace, t);
  },
  toWorkingColorSpace: function(s, t) {
    return this.convert(s, t, this._workingColorSpace);
  },
  getPrimaries: function(s) {
    return Wi[s].primaries;
  },
  getTransfer: function(s) {
    return s === ro ? Hr : Wi[s].transfer;
  }
};
function je(s) {
  return s < 0.04045 ? s * 0.0773993808 : Math.pow(s * 0.9478672986 + 0.0521327014, 2.4);
}
function xr(s) {
  return s < 31308e-7 ? s * 12.92 : 1.055 * Math.pow(s, 0.41666) - 0.055;
}
let Ge;
class Vl {
  static getDataURL(t) {
    if (/^data:/i.test(t.src) || typeof HTMLCanvasElement > "u")
      return t.src;
    let e;
    if (t instanceof HTMLCanvasElement)
      e = t;
    else {
      Ge === void 0 && (Ge = Qs("canvas")), Ge.width = t.width, Ge.height = t.height;
      const i = Ge.getContext("2d");
      t instanceof ImageData ? i.putImageData(t, 0, 0) : i.drawImage(t, 0, 0, t.width, t.height), e = Ge;
    }
    return e.width > 2048 || e.height > 2048 ? (console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons", t), e.toDataURL("image/jpeg", 0.6)) : e.toDataURL("image/png");
  }
  static sRGBToLinear(t) {
    if (typeof HTMLImageElement < "u" && t instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && t instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && t instanceof ImageBitmap) {
      const e = Qs("canvas");
      e.width = t.width, e.height = t.height;
      const i = e.getContext("2d");
      i.drawImage(t, 0, 0, t.width, t.height);
      const n = i.getImageData(0, 0, t.width, t.height), r = n.data;
      for (let a = 0; a < r.length; a++)
        r[a] = je(r[a] / 255) * 255;
      return i.putImageData(n, 0, 0), e;
    } else if (t.data) {
      const e = t.data.slice(0);
      for (let i = 0; i < e.length; i++)
        e instanceof Uint8Array || e instanceof Uint8ClampedArray ? e[i] = Math.floor(je(e[i] / 255) * 255) : e[i] = je(e[i]);
      return {
        data: e,
        width: t.width,
        height: t.height
      };
    } else
      return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."), t;
  }
}
let $l = 0;
class Wl {
  constructor(t = null) {
    this.isSource = !0, Object.defineProperty(this, "id", { value: $l++ }), this.uuid = Fn(), this.data = t, this.dataReady = !0, this.version = 0;
  }
  set needsUpdate(t) {
    t === !0 && this.version++;
  }
  toJSON(t) {
    const e = t === void 0 || typeof t == "string";
    if (!e && t.images[this.uuid] !== void 0)
      return t.images[this.uuid];
    const i = {
      uuid: this.uuid,
      url: ""
    }, n = this.data;
    if (n !== null) {
      let r;
      if (Array.isArray(n)) {
        r = [];
        for (let a = 0, o = n.length; a < o; a++)
          n[a].isDataTexture ? r.push(br(n[a].image)) : r.push(br(n[a]));
      } else
        r = br(n);
      i.url = r;
    }
    return e || (t.images[this.uuid] = i), i;
  }
}
function br(s) {
  return typeof HTMLImageElement < "u" && s instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && s instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && s instanceof ImageBitmap ? Vl.getDataURL(s) : s.data ? {
    data: Array.from(s.data),
    width: s.width,
    height: s.height,
    type: s.data.constructor.name
  } : (console.warn("THREE.Texture: Unable to serialize Texture."), {});
}
let Yl = 0;
class le extends ao {
  constructor(t = le.DEFAULT_IMAGE, e = le.DEFAULT_MAPPING, i = Vi, n = Vi, r = pl, a = yl, o = xl, h = ml, l = le.DEFAULT_ANISOTROPY, A = ro) {
    super(), this.isTexture = !0, Object.defineProperty(this, "id", { value: Yl++ }), this.uuid = Fn(), this.name = "", this.source = new Wl(t), this.mipmaps = [], this.mapping = e, this.channel = 0, this.wrapS = i, this.wrapT = n, this.magFilter = r, this.minFilter = a, this.anisotropy = l, this.format = o, this.internalFormat = null, this.type = h, this.offset = new X(0, 0), this.repeat = new X(1, 1), this.center = new X(0, 0), this.rotation = 0, this.matrixAutoUpdate = !0, this.matrix = new Zt(), this.generateMipmaps = !0, this.premultiplyAlpha = !1, this.flipY = !0, this.unpackAlignment = 4, this.colorSpace = A, this.userData = {}, this.version = 0, this.onUpdate = null, this.isRenderTargetTexture = !1, this.pmremVersion = 0;
  }
  get image() {
    return this.source.data;
  }
  set image(t = null) {
    this.source.data = t;
  }
  updateMatrix() {
    this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(t) {
    return this.name = t.name, this.source = t.source, this.mipmaps = t.mipmaps.slice(0), this.mapping = t.mapping, this.channel = t.channel, this.wrapS = t.wrapS, this.wrapT = t.wrapT, this.magFilter = t.magFilter, this.minFilter = t.minFilter, this.anisotropy = t.anisotropy, this.format = t.format, this.internalFormat = t.internalFormat, this.type = t.type, this.offset.copy(t.offset), this.repeat.copy(t.repeat), this.center.copy(t.center), this.rotation = t.rotation, this.matrixAutoUpdate = t.matrixAutoUpdate, this.matrix.copy(t.matrix), this.generateMipmaps = t.generateMipmaps, this.premultiplyAlpha = t.premultiplyAlpha, this.flipY = t.flipY, this.unpackAlignment = t.unpackAlignment, this.colorSpace = t.colorSpace, this.userData = JSON.parse(JSON.stringify(t.userData)), this.needsUpdate = !0, this;
  }
  toJSON(t) {
    const e = t === void 0 || typeof t == "string";
    if (!e && t.textures[this.uuid] !== void 0)
      return t.textures[this.uuid];
    const i = {
      metadata: {
        version: 4.6,
        type: "Texture",
        generator: "Texture.toJSON"
      },
      uuid: this.uuid,
      name: this.name,
      image: this.source.toJSON(t).uuid,
      mapping: this.mapping,
      channel: this.channel,
      repeat: [this.repeat.x, this.repeat.y],
      offset: [this.offset.x, this.offset.y],
      center: [this.center.x, this.center.y],
      rotation: this.rotation,
      wrap: [this.wrapS, this.wrapT],
      format: this.format,
      internalFormat: this.internalFormat,
      type: this.type,
      colorSpace: this.colorSpace,
      minFilter: this.minFilter,
      magFilter: this.magFilter,
      anisotropy: this.anisotropy,
      flipY: this.flipY,
      generateMipmaps: this.generateMipmaps,
      premultiplyAlpha: this.premultiplyAlpha,
      unpackAlignment: this.unpackAlignment
    };
    return Object.keys(this.userData).length > 0 && (i.userData = this.userData), e || (t.textures[this.uuid] = i), i;
  }
  dispose() {
    this.dispatchEvent({ type: "dispose" });
  }
  transformUv(t) {
    if (this.mapping !== no)
      return t;
    if (t.applyMatrix3(this.matrix), t.x < 0 || t.x > 1)
      switch (this.wrapS) {
        case Us:
          t.x = t.x - Math.floor(t.x);
          break;
        case Vi:
          t.x = t.x < 0 ? 0 : 1;
          break;
        case Hs:
          Math.abs(Math.floor(t.x) % 2) === 1 ? t.x = Math.ceil(t.x) - t.x : t.x = t.x - Math.floor(t.x);
          break;
      }
    if (t.y < 0 || t.y > 1)
      switch (this.wrapT) {
        case Us:
          t.y = t.y - Math.floor(t.y);
          break;
        case Vi:
          t.y = t.y < 0 ? 0 : 1;
          break;
        case Hs:
          Math.abs(Math.floor(t.y) % 2) === 1 ? t.y = Math.ceil(t.y) - t.y : t.y = t.y - Math.floor(t.y);
          break;
      }
    return this.flipY && (t.y = 1 - t.y), t;
  }
  set needsUpdate(t) {
    t === !0 && (this.version++, this.source.needsUpdate = !0);
  }
  set needsPMREMUpdate(t) {
    t === !0 && this.pmremVersion++;
  }
}
le.DEFAULT_IMAGE = null;
le.DEFAULT_MAPPING = no;
le.DEFAULT_ANISOTROPY = 1;
class ai {
  constructor(t = 0, e = 0, i = 0, n = 1) {
    this.isQuaternion = !0, this._x = t, this._y = e, this._z = i, this._w = n;
  }
  static slerpFlat(t, e, i, n, r, a, o) {
    let h = i[n + 0], l = i[n + 1], A = i[n + 2], u = i[n + 3];
    const f = r[a + 0], d = r[a + 1], c = r[a + 2], p = r[a + 3];
    if (o === 0) {
      t[e + 0] = h, t[e + 1] = l, t[e + 2] = A, t[e + 3] = u;
      return;
    }
    if (o === 1) {
      t[e + 0] = f, t[e + 1] = d, t[e + 2] = c, t[e + 3] = p;
      return;
    }
    if (u !== p || h !== f || l !== d || A !== c) {
      let m = 1 - o;
      const v = h * f + l * d + A * c + u * p, x = v >= 0 ? 1 : -1, g = 1 - v * v;
      if (g > Number.EPSILON) {
        const _ = Math.sqrt(g), b = Math.atan2(_, v * x);
        m = Math.sin(m * b) / _, o = Math.sin(o * b) / _;
      }
      const y = o * x;
      if (h = h * m + f * y, l = l * m + d * y, A = A * m + c * y, u = u * m + p * y, m === 1 - o) {
        const _ = 1 / Math.sqrt(h * h + l * l + A * A + u * u);
        h *= _, l *= _, A *= _, u *= _;
      }
    }
    t[e] = h, t[e + 1] = l, t[e + 2] = A, t[e + 3] = u;
  }
  static multiplyQuaternionsFlat(t, e, i, n, r, a) {
    const o = i[n], h = i[n + 1], l = i[n + 2], A = i[n + 3], u = r[a], f = r[a + 1], d = r[a + 2], c = r[a + 3];
    return t[e] = o * c + A * u + h * d - l * f, t[e + 1] = h * c + A * f + l * u - o * d, t[e + 2] = l * c + A * d + o * f - h * u, t[e + 3] = A * c - o * u - h * f - l * d, t;
  }
  get x() {
    return this._x;
  }
  set x(t) {
    this._x = t, this._onChangeCallback();
  }
  get y() {
    return this._y;
  }
  set y(t) {
    this._y = t, this._onChangeCallback();
  }
  get z() {
    return this._z;
  }
  set z(t) {
    this._z = t, this._onChangeCallback();
  }
  get w() {
    return this._w;
  }
  set w(t) {
    this._w = t, this._onChangeCallback();
  }
  set(t, e, i, n) {
    return this._x = t, this._y = e, this._z = i, this._w = n, this._onChangeCallback(), this;
  }
  clone() {
    return new this.constructor(this._x, this._y, this._z, this._w);
  }
  copy(t) {
    return this._x = t.x, this._y = t.y, this._z = t.z, this._w = t.w, this._onChangeCallback(), this;
  }
  setFromEuler(t, e = !0) {
    const i = t._x, n = t._y, r = t._z, a = t._order, o = Math.cos, h = Math.sin, l = o(i / 2), A = o(n / 2), u = o(r / 2), f = h(i / 2), d = h(n / 2), c = h(r / 2);
    switch (a) {
      case "XYZ":
        this._x = f * A * u + l * d * c, this._y = l * d * u - f * A * c, this._z = l * A * c + f * d * u, this._w = l * A * u - f * d * c;
        break;
      case "YXZ":
        this._x = f * A * u + l * d * c, this._y = l * d * u - f * A * c, this._z = l * A * c - f * d * u, this._w = l * A * u + f * d * c;
        break;
      case "ZXY":
        this._x = f * A * u - l * d * c, this._y = l * d * u + f * A * c, this._z = l * A * c + f * d * u, this._w = l * A * u - f * d * c;
        break;
      case "ZYX":
        this._x = f * A * u - l * d * c, this._y = l * d * u + f * A * c, this._z = l * A * c - f * d * u, this._w = l * A * u + f * d * c;
        break;
      case "YZX":
        this._x = f * A * u + l * d * c, this._y = l * d * u + f * A * c, this._z = l * A * c - f * d * u, this._w = l * A * u - f * d * c;
        break;
      case "XZY":
        this._x = f * A * u - l * d * c, this._y = l * d * u - f * A * c, this._z = l * A * c + f * d * u, this._w = l * A * u + f * d * c;
        break;
      default:
        console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + a);
    }
    return e === !0 && this._onChangeCallback(), this;
  }
  setFromAxisAngle(t, e) {
    const i = e / 2, n = Math.sin(i);
    return this._x = t.x * n, this._y = t.y * n, this._z = t.z * n, this._w = Math.cos(i), this._onChangeCallback(), this;
  }
  setFromRotationMatrix(t) {
    const e = t.elements, i = e[0], n = e[4], r = e[8], a = e[1], o = e[5], h = e[9], l = e[2], A = e[6], u = e[10], f = i + o + u;
    if (f > 0) {
      const d = 0.5 / Math.sqrt(f + 1);
      this._w = 0.25 / d, this._x = (A - h) * d, this._y = (r - l) * d, this._z = (a - n) * d;
    } else if (i > o && i > u) {
      const d = 2 * Math.sqrt(1 + i - o - u);
      this._w = (A - h) / d, this._x = 0.25 * d, this._y = (n + a) / d, this._z = (r + l) / d;
    } else if (o > u) {
      const d = 2 * Math.sqrt(1 + o - i - u);
      this._w = (r - l) / d, this._x = (n + a) / d, this._y = 0.25 * d, this._z = (h + A) / d;
    } else {
      const d = 2 * Math.sqrt(1 + u - i - o);
      this._w = (a - n) / d, this._x = (r + l) / d, this._y = (h + A) / d, this._z = 0.25 * d;
    }
    return this._onChangeCallback(), this;
  }
  setFromUnitVectors(t, e) {
    let i = t.dot(e) + 1;
    return i < Number.EPSILON ? (i = 0, Math.abs(t.x) > Math.abs(t.z) ? (this._x = -t.y, this._y = t.x, this._z = 0, this._w = i) : (this._x = 0, this._y = -t.z, this._z = t.y, this._w = i)) : (this._x = t.y * e.z - t.z * e.y, this._y = t.z * e.x - t.x * e.z, this._z = t.x * e.y - t.y * e.x, this._w = i), this.normalize();
  }
  angleTo(t) {
    return 2 * Math.acos(Math.abs(mt(this.dot(t), -1, 1)));
  }
  rotateTowards(t, e) {
    const i = this.angleTo(t);
    if (i === 0)
      return this;
    const n = Math.min(1, e / i);
    return this.slerp(t, n), this;
  }
  identity() {
    return this.set(0, 0, 0, 1);
  }
  invert() {
    return this.conjugate();
  }
  conjugate() {
    return this._x *= -1, this._y *= -1, this._z *= -1, this._onChangeCallback(), this;
  }
  dot(t) {
    return this._x * t._x + this._y * t._y + this._z * t._z + this._w * t._w;
  }
  lengthSq() {
    return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  }
  length() {
    return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  }
  normalize() {
    let t = this.length();
    return t === 0 ? (this._x = 0, this._y = 0, this._z = 0, this._w = 1) : (t = 1 / t, this._x = this._x * t, this._y = this._y * t, this._z = this._z * t, this._w = this._w * t), this._onChangeCallback(), this;
  }
  multiply(t) {
    return this.multiplyQuaternions(this, t);
  }
  premultiply(t) {
    return this.multiplyQuaternions(t, this);
  }
  multiplyQuaternions(t, e) {
    const i = t._x, n = t._y, r = t._z, a = t._w, o = e._x, h = e._y, l = e._z, A = e._w;
    return this._x = i * A + a * o + n * l - r * h, this._y = n * A + a * h + r * o - i * l, this._z = r * A + a * l + i * h - n * o, this._w = a * A - i * o - n * h - r * l, this._onChangeCallback(), this;
  }
  slerp(t, e) {
    if (e === 0)
      return this;
    if (e === 1)
      return this.copy(t);
    const i = this._x, n = this._y, r = this._z, a = this._w;
    let o = a * t._w + i * t._x + n * t._y + r * t._z;
    if (o < 0 ? (this._w = -t._w, this._x = -t._x, this._y = -t._y, this._z = -t._z, o = -o) : this.copy(t), o >= 1)
      return this._w = a, this._x = i, this._y = n, this._z = r, this;
    const h = 1 - o * o;
    if (h <= Number.EPSILON) {
      const d = 1 - e;
      return this._w = d * a + e * this._w, this._x = d * i + e * this._x, this._y = d * n + e * this._y, this._z = d * r + e * this._z, this.normalize(), this;
    }
    const l = Math.sqrt(h), A = Math.atan2(l, o), u = Math.sin((1 - e) * A) / l, f = Math.sin(e * A) / l;
    return this._w = a * u + this._w * f, this._x = i * u + this._x * f, this._y = n * u + this._y * f, this._z = r * u + this._z * f, this._onChangeCallback(), this;
  }
  slerpQuaternions(t, e, i) {
    return this.copy(t).slerp(e, i);
  }
  random() {
    const t = 2 * Math.PI * Math.random(), e = 2 * Math.PI * Math.random(), i = Math.random(), n = Math.sqrt(1 - i), r = Math.sqrt(i);
    return this.set(
      n * Math.sin(t),
      n * Math.cos(t),
      r * Math.sin(e),
      r * Math.cos(e)
    );
  }
  equals(t) {
    return t._x === this._x && t._y === this._y && t._z === this._z && t._w === this._w;
  }
  fromArray(t, e = 0) {
    return this._x = t[e], this._y = t[e + 1], this._z = t[e + 2], this._w = t[e + 3], this._onChangeCallback(), this;
  }
  toArray(t = [], e = 0) {
    return t[e] = this._x, t[e + 1] = this._y, t[e + 2] = this._z, t[e + 3] = this._w, t;
  }
  fromBufferAttribute(t, e) {
    return this._x = t.getX(e), this._y = t.getY(e), this._z = t.getZ(e), this._w = t.getW(e), this._onChangeCallback(), this;
  }
  toJSON() {
    return this.toArray();
  }
  _onChange(t) {
    return this._onChangeCallback = t, this;
  }
  _onChangeCallback() {
  }
  *[Symbol.iterator]() {
    yield this._x, yield this._y, yield this._z, yield this._w;
  }
}
class j {
  constructor(t = 0, e = 0, i = 0) {
    j.prototype.isVector3 = !0, this.x = t, this.y = e, this.z = i;
  }
  set(t, e, i) {
    return i === void 0 && (i = this.z), this.x = t, this.y = e, this.z = i, this;
  }
  setScalar(t) {
    return this.x = t, this.y = t, this.z = t, this;
  }
  setX(t) {
    return this.x = t, this;
  }
  setY(t) {
    return this.y = t, this;
  }
  setZ(t) {
    return this.z = t, this;
  }
  setComponent(t, e) {
    switch (t) {
      case 0:
        this.x = e;
        break;
      case 1:
        this.y = e;
        break;
      case 2:
        this.z = e;
        break;
      default:
        throw new Error("index is out of range: " + t);
    }
    return this;
  }
  getComponent(t) {
    switch (t) {
      case 0:
        return this.x;
      case 1:
        return this.y;
      case 2:
        return this.z;
      default:
        throw new Error("index is out of range: " + t);
    }
  }
  clone() {
    return new this.constructor(this.x, this.y, this.z);
  }
  copy(t) {
    return this.x = t.x, this.y = t.y, this.z = t.z, this;
  }
  add(t) {
    return this.x += t.x, this.y += t.y, this.z += t.z, this;
  }
  addScalar(t) {
    return this.x += t, this.y += t, this.z += t, this;
  }
  addVectors(t, e) {
    return this.x = t.x + e.x, this.y = t.y + e.y, this.z = t.z + e.z, this;
  }
  addScaledVector(t, e) {
    return this.x += t.x * e, this.y += t.y * e, this.z += t.z * e, this;
  }
  sub(t) {
    return this.x -= t.x, this.y -= t.y, this.z -= t.z, this;
  }
  subScalar(t) {
    return this.x -= t, this.y -= t, this.z -= t, this;
  }
  subVectors(t, e) {
    return this.x = t.x - e.x, this.y = t.y - e.y, this.z = t.z - e.z, this;
  }
  multiply(t) {
    return this.x *= t.x, this.y *= t.y, this.z *= t.z, this;
  }
  multiplyScalar(t) {
    return this.x *= t, this.y *= t, this.z *= t, this;
  }
  multiplyVectors(t, e) {
    return this.x = t.x * e.x, this.y = t.y * e.y, this.z = t.z * e.z, this;
  }
  applyEuler(t) {
    return this.applyQuaternion(Js.setFromEuler(t));
  }
  applyAxisAngle(t, e) {
    return this.applyQuaternion(Js.setFromAxisAngle(t, e));
  }
  applyMatrix3(t) {
    const e = this.x, i = this.y, n = this.z, r = t.elements;
    return this.x = r[0] * e + r[3] * i + r[6] * n, this.y = r[1] * e + r[4] * i + r[7] * n, this.z = r[2] * e + r[5] * i + r[8] * n, this;
  }
  applyNormalMatrix(t) {
    return this.applyMatrix3(t).normalize();
  }
  applyMatrix4(t) {
    const e = this.x, i = this.y, n = this.z, r = t.elements, a = 1 / (r[3] * e + r[7] * i + r[11] * n + r[15]);
    return this.x = (r[0] * e + r[4] * i + r[8] * n + r[12]) * a, this.y = (r[1] * e + r[5] * i + r[9] * n + r[13]) * a, this.z = (r[2] * e + r[6] * i + r[10] * n + r[14]) * a, this;
  }
  applyQuaternion(t) {
    const e = this.x, i = this.y, n = this.z, r = t.x, a = t.y, o = t.z, h = t.w, l = 2 * (a * n - o * i), A = 2 * (o * e - r * n), u = 2 * (r * i - a * e);
    return this.x = e + h * l + a * u - o * A, this.y = i + h * A + o * l - r * u, this.z = n + h * u + r * A - a * l, this;
  }
  project(t) {
    return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix);
  }
  unproject(t) {
    return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld);
  }
  transformDirection(t) {
    const e = this.x, i = this.y, n = this.z, r = t.elements;
    return this.x = r[0] * e + r[4] * i + r[8] * n, this.y = r[1] * e + r[5] * i + r[9] * n, this.z = r[2] * e + r[6] * i + r[10] * n, this.normalize();
  }
  divide(t) {
    return this.x /= t.x, this.y /= t.y, this.z /= t.z, this;
  }
  divideScalar(t) {
    return this.multiplyScalar(1 / t);
  }
  min(t) {
    return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this.z = Math.min(this.z, t.z), this;
  }
  max(t) {
    return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this.z = Math.max(this.z, t.z), this;
  }
  clamp(t, e) {
    return this.x = Math.max(t.x, Math.min(e.x, this.x)), this.y = Math.max(t.y, Math.min(e.y, this.y)), this.z = Math.max(t.z, Math.min(e.z, this.z)), this;
  }
  clampScalar(t, e) {
    return this.x = Math.max(t, Math.min(e, this.x)), this.y = Math.max(t, Math.min(e, this.y)), this.z = Math.max(t, Math.min(e, this.z)), this;
  }
  clampLength(t, e) {
    const i = this.length();
    return this.divideScalar(i || 1).multiplyScalar(Math.max(t, Math.min(e, i)));
  }
  floor() {
    return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this.z = Math.floor(this.z), this;
  }
  ceil() {
    return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this.z = Math.ceil(this.z), this;
  }
  round() {
    return this.x = Math.round(this.x), this.y = Math.round(this.y), this.z = Math.round(this.z), this;
  }
  roundToZero() {
    return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this.z = Math.trunc(this.z), this;
  }
  negate() {
    return this.x = -this.x, this.y = -this.y, this.z = -this.z, this;
  }
  dot(t) {
    return this.x * t.x + this.y * t.y + this.z * t.z;
  }
  // TODO lengthSquared?
  lengthSq() {
    return this.x * this.x + this.y * this.y + this.z * this.z;
  }
  length() {
    return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  }
  manhattanLength() {
    return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  }
  normalize() {
    return this.divideScalar(this.length() || 1);
  }
  setLength(t) {
    return this.normalize().multiplyScalar(t);
  }
  lerp(t, e) {
    return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this.z += (t.z - this.z) * e, this;
  }
  lerpVectors(t, e, i) {
    return this.x = t.x + (e.x - t.x) * i, this.y = t.y + (e.y - t.y) * i, this.z = t.z + (e.z - t.z) * i, this;
  }
  cross(t) {
    return this.crossVectors(this, t);
  }
  crossVectors(t, e) {
    const i = t.x, n = t.y, r = t.z, a = e.x, o = e.y, h = e.z;
    return this.x = n * h - r * o, this.y = r * a - i * h, this.z = i * o - n * a, this;
  }
  projectOnVector(t) {
    const e = t.lengthSq();
    if (e === 0)
      return this.set(0, 0, 0);
    const i = t.dot(this) / e;
    return this.copy(t).multiplyScalar(i);
  }
  projectOnPlane(t) {
    return wr.copy(this).projectOnVector(t), this.sub(wr);
  }
  reflect(t) {
    return this.sub(wr.copy(t).multiplyScalar(2 * this.dot(t)));
  }
  angleTo(t) {
    const e = Math.sqrt(this.lengthSq() * t.lengthSq());
    if (e === 0)
      return Math.PI / 2;
    const i = this.dot(t) / e;
    return Math.acos(mt(i, -1, 1));
  }
  distanceTo(t) {
    return Math.sqrt(this.distanceToSquared(t));
  }
  distanceToSquared(t) {
    const e = this.x - t.x, i = this.y - t.y, n = this.z - t.z;
    return e * e + i * i + n * n;
  }
  manhattanDistanceTo(t) {
    return Math.abs(this.x - t.x) + Math.abs(this.y - t.y) + Math.abs(this.z - t.z);
  }
  setFromSpherical(t) {
    return this.setFromSphericalCoords(t.radius, t.phi, t.theta);
  }
  setFromSphericalCoords(t, e, i) {
    const n = Math.sin(e) * t;
    return this.x = n * Math.sin(i), this.y = Math.cos(e) * t, this.z = n * Math.cos(i), this;
  }
  setFromCylindrical(t) {
    return this.setFromCylindricalCoords(t.radius, t.theta, t.y);
  }
  setFromCylindricalCoords(t, e, i) {
    return this.x = t * Math.sin(e), this.y = i, this.z = t * Math.cos(e), this;
  }
  setFromMatrixPosition(t) {
    const e = t.elements;
    return this.x = e[12], this.y = e[13], this.z = e[14], this;
  }
  setFromMatrixScale(t) {
    const e = this.setFromMatrixColumn(t, 0).length(), i = this.setFromMatrixColumn(t, 1).length(), n = this.setFromMatrixColumn(t, 2).length();
    return this.x = e, this.y = i, this.z = n, this;
  }
  setFromMatrixColumn(t, e) {
    return this.fromArray(t.elements, e * 4);
  }
  setFromMatrix3Column(t, e) {
    return this.fromArray(t.elements, e * 3);
  }
  setFromEuler(t) {
    return this.x = t._x, this.y = t._y, this.z = t._z, this;
  }
  setFromColor(t) {
    return this.x = t.r, this.y = t.g, this.z = t.b, this;
  }
  equals(t) {
    return t.x === this.x && t.y === this.y && t.z === this.z;
  }
  fromArray(t, e = 0) {
    return this.x = t[e], this.y = t[e + 1], this.z = t[e + 2], this;
  }
  toArray(t = [], e = 0) {
    return t[e] = this.x, t[e + 1] = this.y, t[e + 2] = this.z, t;
  }
  fromBufferAttribute(t, e) {
    return this.x = t.getX(e), this.y = t.getY(e), this.z = t.getZ(e), this;
  }
  random() {
    return this.x = Math.random(), this.y = Math.random(), this.z = Math.random(), this;
  }
  randomDirection() {
    const t = Math.random() * Math.PI * 2, e = Math.random() * 2 - 1, i = Math.sqrt(1 - e * e);
    return this.x = i * Math.cos(t), this.y = e, this.z = i * Math.sin(t), this;
  }
  *[Symbol.iterator]() {
    yield this.x, yield this.y, yield this.z;
  }
}
const wr = /* @__PURE__ */ new j(), Js = /* @__PURE__ */ new ai();
class ot {
  constructor(t, e, i, n, r, a, o, h, l, A, u, f, d, c, p, m) {
    ot.prototype.isMatrix4 = !0, this.elements = [
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1
    ], t !== void 0 && this.set(t, e, i, n, r, a, o, h, l, A, u, f, d, c, p, m);
  }
  set(t, e, i, n, r, a, o, h, l, A, u, f, d, c, p, m) {
    const v = this.elements;
    return v[0] = t, v[4] = e, v[8] = i, v[12] = n, v[1] = r, v[5] = a, v[9] = o, v[13] = h, v[2] = l, v[6] = A, v[10] = u, v[14] = f, v[3] = d, v[7] = c, v[11] = p, v[15] = m, this;
  }
  identity() {
    return this.set(
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  clone() {
    return new ot().fromArray(this.elements);
  }
  copy(t) {
    const e = this.elements, i = t.elements;
    return e[0] = i[0], e[1] = i[1], e[2] = i[2], e[3] = i[3], e[4] = i[4], e[5] = i[5], e[6] = i[6], e[7] = i[7], e[8] = i[8], e[9] = i[9], e[10] = i[10], e[11] = i[11], e[12] = i[12], e[13] = i[13], e[14] = i[14], e[15] = i[15], this;
  }
  copyPosition(t) {
    const e = this.elements, i = t.elements;
    return e[12] = i[12], e[13] = i[13], e[14] = i[14], this;
  }
  setFromMatrix3(t) {
    const e = t.elements;
    return this.set(
      e[0],
      e[3],
      e[6],
      0,
      e[1],
      e[4],
      e[7],
      0,
      e[2],
      e[5],
      e[8],
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  extractBasis(t, e, i) {
    return t.setFromMatrixColumn(this, 0), e.setFromMatrixColumn(this, 1), i.setFromMatrixColumn(this, 2), this;
  }
  makeBasis(t, e, i) {
    return this.set(
      t.x,
      e.x,
      i.x,
      0,
      t.y,
      e.y,
      i.y,
      0,
      t.z,
      e.z,
      i.z,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  extractRotation(t) {
    const e = this.elements, i = t.elements, n = 1 / Be.setFromMatrixColumn(t, 0).length(), r = 1 / Be.setFromMatrixColumn(t, 1).length(), a = 1 / Be.setFromMatrixColumn(t, 2).length();
    return e[0] = i[0] * n, e[1] = i[1] * n, e[2] = i[2] * n, e[3] = 0, e[4] = i[4] * r, e[5] = i[5] * r, e[6] = i[6] * r, e[7] = 0, e[8] = i[8] * a, e[9] = i[9] * a, e[10] = i[10] * a, e[11] = 0, e[12] = 0, e[13] = 0, e[14] = 0, e[15] = 1, this;
  }
  makeRotationFromEuler(t) {
    const e = this.elements, i = t.x, n = t.y, r = t.z, a = Math.cos(i), o = Math.sin(i), h = Math.cos(n), l = Math.sin(n), A = Math.cos(r), u = Math.sin(r);
    if (t.order === "XYZ") {
      const f = a * A, d = a * u, c = o * A, p = o * u;
      e[0] = h * A, e[4] = -h * u, e[8] = l, e[1] = d + c * l, e[5] = f - p * l, e[9] = -o * h, e[2] = p - f * l, e[6] = c + d * l, e[10] = a * h;
    } else if (t.order === "YXZ") {
      const f = h * A, d = h * u, c = l * A, p = l * u;
      e[0] = f + p * o, e[4] = c * o - d, e[8] = a * l, e[1] = a * u, e[5] = a * A, e[9] = -o, e[2] = d * o - c, e[6] = p + f * o, e[10] = a * h;
    } else if (t.order === "ZXY") {
      const f = h * A, d = h * u, c = l * A, p = l * u;
      e[0] = f - p * o, e[4] = -a * u, e[8] = c + d * o, e[1] = d + c * o, e[5] = a * A, e[9] = p - f * o, e[2] = -a * l, e[6] = o, e[10] = a * h;
    } else if (t.order === "ZYX") {
      const f = a * A, d = a * u, c = o * A, p = o * u;
      e[0] = h * A, e[4] = c * l - d, e[8] = f * l + p, e[1] = h * u, e[5] = p * l + f, e[9] = d * l - c, e[2] = -l, e[6] = o * h, e[10] = a * h;
    } else if (t.order === "YZX") {
      const f = a * h, d = a * l, c = o * h, p = o * l;
      e[0] = h * A, e[4] = p - f * u, e[8] = c * u + d, e[1] = u, e[5] = a * A, e[9] = -o * A, e[2] = -l * A, e[6] = d * u + c, e[10] = f - p * u;
    } else if (t.order === "XZY") {
      const f = a * h, d = a * l, c = o * h, p = o * l;
      e[0] = h * A, e[4] = -u, e[8] = l * A, e[1] = f * u + p, e[5] = a * A, e[9] = d * u - c, e[2] = c * u - d, e[6] = o * A, e[10] = p * u + f;
    }
    return e[3] = 0, e[7] = 0, e[11] = 0, e[12] = 0, e[13] = 0, e[14] = 0, e[15] = 1, this;
  }
  makeRotationFromQuaternion(t) {
    return this.compose(Xl, t, jl);
  }
  lookAt(t, e, i) {
    const n = this.elements;
    return xt.subVectors(t, e), xt.lengthSq() === 0 && (xt.z = 1), xt.normalize(), ne.crossVectors(i, xt), ne.lengthSq() === 0 && (Math.abs(i.z) === 1 ? xt.x += 1e-4 : xt.z += 1e-4, xt.normalize(), ne.crossVectors(i, xt)), ne.normalize(), Yi.crossVectors(xt, ne), n[0] = ne.x, n[4] = Yi.x, n[8] = xt.x, n[1] = ne.y, n[5] = Yi.y, n[9] = xt.y, n[2] = ne.z, n[6] = Yi.z, n[10] = xt.z, this;
  }
  multiply(t) {
    return this.multiplyMatrices(this, t);
  }
  premultiply(t) {
    return this.multiplyMatrices(t, this);
  }
  multiplyMatrices(t, e) {
    const i = t.elements, n = e.elements, r = this.elements, a = i[0], o = i[4], h = i[8], l = i[12], A = i[1], u = i[5], f = i[9], d = i[13], c = i[2], p = i[6], m = i[10], v = i[14], x = i[3], g = i[7], y = i[11], _ = i[15], b = n[0], C = n[4], w = n[8], E = n[12], S = n[1], P = n[5], k = n[9], F = n[13], I = n[2], T = n[6], R = n[10], L = n[14], B = n[3], $ = n[7], O = n[11], G = n[15];
    return r[0] = a * b + o * S + h * I + l * B, r[4] = a * C + o * P + h * T + l * $, r[8] = a * w + o * k + h * R + l * O, r[12] = a * E + o * F + h * L + l * G, r[1] = A * b + u * S + f * I + d * B, r[5] = A * C + u * P + f * T + d * $, r[9] = A * w + u * k + f * R + d * O, r[13] = A * E + u * F + f * L + d * G, r[2] = c * b + p * S + m * I + v * B, r[6] = c * C + p * P + m * T + v * $, r[10] = c * w + p * k + m * R + v * O, r[14] = c * E + p * F + m * L + v * G, r[3] = x * b + g * S + y * I + _ * B, r[7] = x * C + g * P + y * T + _ * $, r[11] = x * w + g * k + y * R + _ * O, r[15] = x * E + g * F + y * L + _ * G, this;
  }
  multiplyScalar(t) {
    const e = this.elements;
    return e[0] *= t, e[4] *= t, e[8] *= t, e[12] *= t, e[1] *= t, e[5] *= t, e[9] *= t, e[13] *= t, e[2] *= t, e[6] *= t, e[10] *= t, e[14] *= t, e[3] *= t, e[7] *= t, e[11] *= t, e[15] *= t, this;
  }
  determinant() {
    const t = this.elements, e = t[0], i = t[4], n = t[8], r = t[12], a = t[1], o = t[5], h = t[9], l = t[13], A = t[2], u = t[6], f = t[10], d = t[14], c = t[3], p = t[7], m = t[11], v = t[15];
    return c * (+r * h * u - n * l * u - r * o * f + i * l * f + n * o * d - i * h * d) + p * (+e * h * d - e * l * f + r * a * f - n * a * d + n * l * A - r * h * A) + m * (+e * l * u - e * o * d - r * a * u + i * a * d + r * o * A - i * l * A) + v * (-n * o * A - e * h * u + e * o * f + n * a * u - i * a * f + i * h * A);
  }
  transpose() {
    const t = this.elements;
    let e;
    return e = t[1], t[1] = t[4], t[4] = e, e = t[2], t[2] = t[8], t[8] = e, e = t[6], t[6] = t[9], t[9] = e, e = t[3], t[3] = t[12], t[12] = e, e = t[7], t[7] = t[13], t[13] = e, e = t[11], t[11] = t[14], t[14] = e, this;
  }
  setPosition(t, e, i) {
    const n = this.elements;
    return t.isVector3 ? (n[12] = t.x, n[13] = t.y, n[14] = t.z) : (n[12] = t, n[13] = e, n[14] = i), this;
  }
  invert() {
    const t = this.elements, e = t[0], i = t[1], n = t[2], r = t[3], a = t[4], o = t[5], h = t[6], l = t[7], A = t[8], u = t[9], f = t[10], d = t[11], c = t[12], p = t[13], m = t[14], v = t[15], x = u * m * l - p * f * l + p * h * d - o * m * d - u * h * v + o * f * v, g = c * f * l - A * m * l - c * h * d + a * m * d + A * h * v - a * f * v, y = A * p * l - c * u * l + c * o * d - a * p * d - A * o * v + a * u * v, _ = c * u * h - A * p * h - c * o * f + a * p * f + A * o * m - a * u * m, b = e * x + i * g + n * y + r * _;
    if (b === 0)
      return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    const C = 1 / b;
    return t[0] = x * C, t[1] = (p * f * r - u * m * r - p * n * d + i * m * d + u * n * v - i * f * v) * C, t[2] = (o * m * r - p * h * r + p * n * l - i * m * l - o * n * v + i * h * v) * C, t[3] = (u * h * r - o * f * r - u * n * l + i * f * l + o * n * d - i * h * d) * C, t[4] = g * C, t[5] = (A * m * r - c * f * r + c * n * d - e * m * d - A * n * v + e * f * v) * C, t[6] = (c * h * r - a * m * r - c * n * l + e * m * l + a * n * v - e * h * v) * C, t[7] = (a * f * r - A * h * r + A * n * l - e * f * l - a * n * d + e * h * d) * C, t[8] = y * C, t[9] = (c * u * r - A * p * r - c * i * d + e * p * d + A * i * v - e * u * v) * C, t[10] = (a * p * r - c * o * r + c * i * l - e * p * l - a * i * v + e * o * v) * C, t[11] = (A * o * r - a * u * r - A * i * l + e * u * l + a * i * d - e * o * d) * C, t[12] = _ * C, t[13] = (A * p * n - c * u * n + c * i * f - e * p * f - A * i * m + e * u * m) * C, t[14] = (c * o * n - a * p * n - c * i * h + e * p * h + a * i * m - e * o * m) * C, t[15] = (a * u * n - A * o * n + A * i * h - e * u * h - a * i * f + e * o * f) * C, this;
  }
  scale(t) {
    const e = this.elements, i = t.x, n = t.y, r = t.z;
    return e[0] *= i, e[4] *= n, e[8] *= r, e[1] *= i, e[5] *= n, e[9] *= r, e[2] *= i, e[6] *= n, e[10] *= r, e[3] *= i, e[7] *= n, e[11] *= r, this;
  }
  getMaxScaleOnAxis() {
    const t = this.elements, e = t[0] * t[0] + t[1] * t[1] + t[2] * t[2], i = t[4] * t[4] + t[5] * t[5] + t[6] * t[6], n = t[8] * t[8] + t[9] * t[9] + t[10] * t[10];
    return Math.sqrt(Math.max(e, i, n));
  }
  makeTranslation(t, e, i) {
    return t.isVector3 ? this.set(
      1,
      0,
      0,
      t.x,
      0,
      1,
      0,
      t.y,
      0,
      0,
      1,
      t.z,
      0,
      0,
      0,
      1
    ) : this.set(
      1,
      0,
      0,
      t,
      0,
      1,
      0,
      e,
      0,
      0,
      1,
      i,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationX(t) {
    const e = Math.cos(t), i = Math.sin(t);
    return this.set(
      1,
      0,
      0,
      0,
      0,
      e,
      -i,
      0,
      0,
      i,
      e,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationY(t) {
    const e = Math.cos(t), i = Math.sin(t);
    return this.set(
      e,
      0,
      i,
      0,
      0,
      1,
      0,
      0,
      -i,
      0,
      e,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationZ(t) {
    const e = Math.cos(t), i = Math.sin(t);
    return this.set(
      e,
      -i,
      0,
      0,
      i,
      e,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationAxis(t, e) {
    const i = Math.cos(e), n = Math.sin(e), r = 1 - i, a = t.x, o = t.y, h = t.z, l = r * a, A = r * o;
    return this.set(
      l * a + i,
      l * o - n * h,
      l * h + n * o,
      0,
      l * o + n * h,
      A * o + i,
      A * h - n * a,
      0,
      l * h - n * o,
      A * h + n * a,
      r * h * h + i,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeScale(t, e, i) {
    return this.set(
      t,
      0,
      0,
      0,
      0,
      e,
      0,
      0,
      0,
      0,
      i,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeShear(t, e, i, n, r, a) {
    return this.set(
      1,
      i,
      r,
      0,
      t,
      1,
      a,
      0,
      e,
      n,
      1,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  compose(t, e, i) {
    const n = this.elements, r = e._x, a = e._y, o = e._z, h = e._w, l = r + r, A = a + a, u = o + o, f = r * l, d = r * A, c = r * u, p = a * A, m = a * u, v = o * u, x = h * l, g = h * A, y = h * u, _ = i.x, b = i.y, C = i.z;
    return n[0] = (1 - (p + v)) * _, n[1] = (d + y) * _, n[2] = (c - g) * _, n[3] = 0, n[4] = (d - y) * b, n[5] = (1 - (f + v)) * b, n[6] = (m + x) * b, n[7] = 0, n[8] = (c + g) * C, n[9] = (m - x) * C, n[10] = (1 - (f + p)) * C, n[11] = 0, n[12] = t.x, n[13] = t.y, n[14] = t.z, n[15] = 1, this;
  }
  decompose(t, e, i) {
    const n = this.elements;
    let r = Be.set(n[0], n[1], n[2]).length();
    const a = Be.set(n[4], n[5], n[6]).length(), o = Be.set(n[8], n[9], n[10]).length();
    this.determinant() < 0 && (r = -r), t.x = n[12], t.y = n[13], t.z = n[14], Dt.copy(this);
    const l = 1 / r, A = 1 / a, u = 1 / o;
    return Dt.elements[0] *= l, Dt.elements[1] *= l, Dt.elements[2] *= l, Dt.elements[4] *= A, Dt.elements[5] *= A, Dt.elements[6] *= A, Dt.elements[8] *= u, Dt.elements[9] *= u, Dt.elements[10] *= u, e.setFromRotationMatrix(Dt), i.x = r, i.y = a, i.z = o, this;
  }
  makePerspective(t, e, i, n, r, a, o = $i) {
    const h = this.elements, l = 2 * r / (e - t), A = 2 * r / (i - n), u = (e + t) / (e - t), f = (i + n) / (i - n);
    let d, c;
    if (o === $i)
      d = -(a + r) / (a - r), c = -2 * a * r / (a - r);
    else if (o === js)
      d = -a / (a - r), c = -a * r / (a - r);
    else
      throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + o);
    return h[0] = l, h[4] = 0, h[8] = u, h[12] = 0, h[1] = 0, h[5] = A, h[9] = f, h[13] = 0, h[2] = 0, h[6] = 0, h[10] = d, h[14] = c, h[3] = 0, h[7] = 0, h[11] = -1, h[15] = 0, this;
  }
  makeOrthographic(t, e, i, n, r, a, o = $i) {
    const h = this.elements, l = 1 / (e - t), A = 1 / (i - n), u = 1 / (a - r), f = (e + t) * l, d = (i + n) * A;
    let c, p;
    if (o === $i)
      c = (a + r) * u, p = -2 * u;
    else if (o === js)
      c = r * u, p = -1 * u;
    else
      throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + o);
    return h[0] = 2 * l, h[4] = 0, h[8] = 0, h[12] = -f, h[1] = 0, h[5] = 2 * A, h[9] = 0, h[13] = -d, h[2] = 0, h[6] = 0, h[10] = p, h[14] = -c, h[3] = 0, h[7] = 0, h[11] = 0, h[15] = 1, this;
  }
  equals(t) {
    const e = this.elements, i = t.elements;
    for (let n = 0; n < 16; n++)
      if (e[n] !== i[n])
        return !1;
    return !0;
  }
  fromArray(t, e = 0) {
    for (let i = 0; i < 16; i++)
      this.elements[i] = t[i + e];
    return this;
  }
  toArray(t = [], e = 0) {
    const i = this.elements;
    return t[e] = i[0], t[e + 1] = i[1], t[e + 2] = i[2], t[e + 3] = i[3], t[e + 4] = i[4], t[e + 5] = i[5], t[e + 6] = i[6], t[e + 7] = i[7], t[e + 8] = i[8], t[e + 9] = i[9], t[e + 10] = i[10], t[e + 11] = i[11], t[e + 12] = i[12], t[e + 13] = i[13], t[e + 14] = i[14], t[e + 15] = i[15], t;
  }
}
const Be = /* @__PURE__ */ new j(), Dt = /* @__PURE__ */ new ot(), Xl = /* @__PURE__ */ new j(0, 0, 0), jl = /* @__PURE__ */ new j(1, 1, 1), ne = /* @__PURE__ */ new j(), Yi = /* @__PURE__ */ new j(), xt = /* @__PURE__ */ new j(), ta = /* @__PURE__ */ new ot(), ea = /* @__PURE__ */ new ai();
class Ni {
  constructor(t = 0, e = 0, i = 0, n = Ni.DEFAULT_ORDER) {
    this.isEuler = !0, this._x = t, this._y = e, this._z = i, this._order = n;
  }
  get x() {
    return this._x;
  }
  set x(t) {
    this._x = t, this._onChangeCallback();
  }
  get y() {
    return this._y;
  }
  set y(t) {
    this._y = t, this._onChangeCallback();
  }
  get z() {
    return this._z;
  }
  set z(t) {
    this._z = t, this._onChangeCallback();
  }
  get order() {
    return this._order;
  }
  set order(t) {
    this._order = t, this._onChangeCallback();
  }
  set(t, e, i, n = this._order) {
    return this._x = t, this._y = e, this._z = i, this._order = n, this._onChangeCallback(), this;
  }
  clone() {
    return new this.constructor(this._x, this._y, this._z, this._order);
  }
  copy(t) {
    return this._x = t._x, this._y = t._y, this._z = t._z, this._order = t._order, this._onChangeCallback(), this;
  }
  setFromRotationMatrix(t, e = this._order, i = !0) {
    const n = t.elements, r = n[0], a = n[4], o = n[8], h = n[1], l = n[5], A = n[9], u = n[2], f = n[6], d = n[10];
    switch (e) {
      case "XYZ":
        this._y = Math.asin(mt(o, -1, 1)), Math.abs(o) < 0.9999999 ? (this._x = Math.atan2(-A, d), this._z = Math.atan2(-a, r)) : (this._x = Math.atan2(f, l), this._z = 0);
        break;
      case "YXZ":
        this._x = Math.asin(-mt(A, -1, 1)), Math.abs(A) < 0.9999999 ? (this._y = Math.atan2(o, d), this._z = Math.atan2(h, l)) : (this._y = Math.atan2(-u, r), this._z = 0);
        break;
      case "ZXY":
        this._x = Math.asin(mt(f, -1, 1)), Math.abs(f) < 0.9999999 ? (this._y = Math.atan2(-u, d), this._z = Math.atan2(-a, l)) : (this._y = 0, this._z = Math.atan2(h, r));
        break;
      case "ZYX":
        this._y = Math.asin(-mt(u, -1, 1)), Math.abs(u) < 0.9999999 ? (this._x = Math.atan2(f, d), this._z = Math.atan2(h, r)) : (this._x = 0, this._z = Math.atan2(-a, l));
        break;
      case "YZX":
        this._z = Math.asin(mt(h, -1, 1)), Math.abs(h) < 0.9999999 ? (this._x = Math.atan2(-A, l), this._y = Math.atan2(-u, r)) : (this._x = 0, this._y = Math.atan2(o, d));
        break;
      case "XZY":
        this._z = Math.asin(-mt(a, -1, 1)), Math.abs(a) < 0.9999999 ? (this._x = Math.atan2(f, l), this._y = Math.atan2(o, r)) : (this._x = Math.atan2(-A, d), this._y = 0);
        break;
      default:
        console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + e);
    }
    return this._order = e, i === !0 && this._onChangeCallback(), this;
  }
  setFromQuaternion(t, e, i) {
    return ta.makeRotationFromQuaternion(t), this.setFromRotationMatrix(ta, e, i);
  }
  setFromVector3(t, e = this._order) {
    return this.set(t.x, t.y, t.z, e);
  }
  reorder(t) {
    return ea.setFromEuler(this), this.setFromQuaternion(ea, t);
  }
  equals(t) {
    return t._x === this._x && t._y === this._y && t._z === this._z && t._order === this._order;
  }
  fromArray(t) {
    return this._x = t[0], this._y = t[1], this._z = t[2], t[3] !== void 0 && (this._order = t[3]), this._onChangeCallback(), this;
  }
  toArray(t = [], e = 0) {
    return t[e] = this._x, t[e + 1] = this._y, t[e + 2] = this._z, t[e + 3] = this._order, t;
  }
  _onChange(t) {
    return this._onChangeCallback = t, this;
  }
  _onChangeCallback() {
  }
  *[Symbol.iterator]() {
    yield this._x, yield this._y, yield this._z, yield this._order;
  }
}
Ni.DEFAULT_ORDER = "XYZ";
class ql {
  constructor() {
    this.mask = 1;
  }
  set(t) {
    this.mask = (1 << t | 0) >>> 0;
  }
  enable(t) {
    this.mask |= 1 << t | 0;
  }
  enableAll() {
    this.mask = -1;
  }
  toggle(t) {
    this.mask ^= 1 << t | 0;
  }
  disable(t) {
    this.mask &= ~(1 << t | 0);
  }
  disableAll() {
    this.mask = 0;
  }
  test(t) {
    return (this.mask & t.mask) !== 0;
  }
  isEnabled(t) {
    return (this.mask & (1 << t | 0)) !== 0;
  }
}
let Ql = 0;
const ia = /* @__PURE__ */ new j(), ze = /* @__PURE__ */ new ai(), Ut = /* @__PURE__ */ new ot(), Xi = /* @__PURE__ */ new j(), fi = /* @__PURE__ */ new j(), Kl = /* @__PURE__ */ new j(), Zl = /* @__PURE__ */ new ai(), na = /* @__PURE__ */ new j(1, 0, 0), ra = /* @__PURE__ */ new j(0, 1, 0), sa = /* @__PURE__ */ new j(0, 0, 1), aa = { type: "added" }, Jl = { type: "removed" }, Ue = { type: "childadded", child: null }, Sr = { type: "childremoved", child: null };
class xe extends ao {
  constructor() {
    super(), this.isObject3D = !0, Object.defineProperty(this, "id", { value: Ql++ }), this.uuid = Fn(), this.name = "", this.type = "Object3D", this.parent = null, this.children = [], this.up = xe.DEFAULT_UP.clone();
    const t = new j(), e = new Ni(), i = new ai(), n = new j(1, 1, 1);
    function r() {
      i.setFromEuler(e, !1);
    }
    function a() {
      e.setFromQuaternion(i, void 0, !1);
    }
    e._onChange(r), i._onChange(a), Object.defineProperties(this, {
      position: {
        configurable: !0,
        enumerable: !0,
        value: t
      },
      rotation: {
        configurable: !0,
        enumerable: !0,
        value: e
      },
      quaternion: {
        configurable: !0,
        enumerable: !0,
        value: i
      },
      scale: {
        configurable: !0,
        enumerable: !0,
        value: n
      },
      modelViewMatrix: {
        value: new ot()
      },
      normalMatrix: {
        value: new Zt()
      }
    }), this.matrix = new ot(), this.matrixWorld = new ot(), this.matrixAutoUpdate = xe.DEFAULT_MATRIX_AUTO_UPDATE, this.matrixWorldAutoUpdate = xe.DEFAULT_MATRIX_WORLD_AUTO_UPDATE, this.matrixWorldNeedsUpdate = !1, this.layers = new ql(), this.visible = !0, this.castShadow = !1, this.receiveShadow = !1, this.frustumCulled = !0, this.renderOrder = 0, this.animations = [], this.userData = {};
  }
  onBeforeShadow() {
  }
  onAfterShadow() {
  }
  onBeforeRender() {
  }
  onAfterRender() {
  }
  applyMatrix4(t) {
    this.matrixAutoUpdate && this.updateMatrix(), this.matrix.premultiply(t), this.matrix.decompose(this.position, this.quaternion, this.scale);
  }
  applyQuaternion(t) {
    return this.quaternion.premultiply(t), this;
  }
  setRotationFromAxisAngle(t, e) {
    this.quaternion.setFromAxisAngle(t, e);
  }
  setRotationFromEuler(t) {
    this.quaternion.setFromEuler(t, !0);
  }
  setRotationFromMatrix(t) {
    this.quaternion.setFromRotationMatrix(t);
  }
  setRotationFromQuaternion(t) {
    this.quaternion.copy(t);
  }
  rotateOnAxis(t, e) {
    return ze.setFromAxisAngle(t, e), this.quaternion.multiply(ze), this;
  }
  rotateOnWorldAxis(t, e) {
    return ze.setFromAxisAngle(t, e), this.quaternion.premultiply(ze), this;
  }
  rotateX(t) {
    return this.rotateOnAxis(na, t);
  }
  rotateY(t) {
    return this.rotateOnAxis(ra, t);
  }
  rotateZ(t) {
    return this.rotateOnAxis(sa, t);
  }
  translateOnAxis(t, e) {
    return ia.copy(t).applyQuaternion(this.quaternion), this.position.add(ia.multiplyScalar(e)), this;
  }
  translateX(t) {
    return this.translateOnAxis(na, t);
  }
  translateY(t) {
    return this.translateOnAxis(ra, t);
  }
  translateZ(t) {
    return this.translateOnAxis(sa, t);
  }
  localToWorld(t) {
    return this.updateWorldMatrix(!0, !1), t.applyMatrix4(this.matrixWorld);
  }
  worldToLocal(t) {
    return this.updateWorldMatrix(!0, !1), t.applyMatrix4(Ut.copy(this.matrixWorld).invert());
  }
  lookAt(t, e, i) {
    t.isVector3 ? Xi.copy(t) : Xi.set(t, e, i);
    const n = this.parent;
    this.updateWorldMatrix(!0, !1), fi.setFromMatrixPosition(this.matrixWorld), this.isCamera || this.isLight ? Ut.lookAt(fi, Xi, this.up) : Ut.lookAt(Xi, fi, this.up), this.quaternion.setFromRotationMatrix(Ut), n && (Ut.extractRotation(n.matrixWorld), ze.setFromRotationMatrix(Ut), this.quaternion.premultiply(ze.invert()));
  }
  add(t) {
    if (arguments.length > 1) {
      for (let e = 0; e < arguments.length; e++)
        this.add(arguments[e]);
      return this;
    }
    return t === this ? (console.error("THREE.Object3D.add: object can't be added as a child of itself.", t), this) : (t && t.isObject3D ? (t.removeFromParent(), t.parent = this, this.children.push(t), t.dispatchEvent(aa), Ue.child = t, this.dispatchEvent(Ue), Ue.child = null) : console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", t), this);
  }
  remove(t) {
    if (arguments.length > 1) {
      for (let i = 0; i < arguments.length; i++)
        this.remove(arguments[i]);
      return this;
    }
    const e = this.children.indexOf(t);
    return e !== -1 && (t.parent = null, this.children.splice(e, 1), t.dispatchEvent(Jl), Sr.child = t, this.dispatchEvent(Sr), Sr.child = null), this;
  }
  removeFromParent() {
    const t = this.parent;
    return t !== null && t.remove(this), this;
  }
  clear() {
    return this.remove(...this.children);
  }
  attach(t) {
    return this.updateWorldMatrix(!0, !1), Ut.copy(this.matrixWorld).invert(), t.parent !== null && (t.parent.updateWorldMatrix(!0, !1), Ut.multiply(t.parent.matrixWorld)), t.applyMatrix4(Ut), t.removeFromParent(), t.parent = this, this.children.push(t), t.updateWorldMatrix(!1, !0), t.dispatchEvent(aa), Ue.child = t, this.dispatchEvent(Ue), Ue.child = null, this;
  }
  getObjectById(t) {
    return this.getObjectByProperty("id", t);
  }
  getObjectByName(t) {
    return this.getObjectByProperty("name", t);
  }
  getObjectByProperty(t, e) {
    if (this[t] === e)
      return this;
    for (let i = 0, n = this.children.length; i < n; i++) {
      const a = this.children[i].getObjectByProperty(t, e);
      if (a !== void 0)
        return a;
    }
  }
  getObjectsByProperty(t, e, i = []) {
    this[t] === e && i.push(this);
    const n = this.children;
    for (let r = 0, a = n.length; r < a; r++)
      n[r].getObjectsByProperty(t, e, i);
    return i;
  }
  getWorldPosition(t) {
    return this.updateWorldMatrix(!0, !1), t.setFromMatrixPosition(this.matrixWorld);
  }
  getWorldQuaternion(t) {
    return this.updateWorldMatrix(!0, !1), this.matrixWorld.decompose(fi, t, Kl), t;
  }
  getWorldScale(t) {
    return this.updateWorldMatrix(!0, !1), this.matrixWorld.decompose(fi, Zl, t), t;
  }
  getWorldDirection(t) {
    this.updateWorldMatrix(!0, !1);
    const e = this.matrixWorld.elements;
    return t.set(e[8], e[9], e[10]).normalize();
  }
  raycast() {
  }
  traverse(t) {
    t(this);
    const e = this.children;
    for (let i = 0, n = e.length; i < n; i++)
      e[i].traverse(t);
  }
  traverseVisible(t) {
    if (this.visible === !1)
      return;
    t(this);
    const e = this.children;
    for (let i = 0, n = e.length; i < n; i++)
      e[i].traverseVisible(t);
  }
  traverseAncestors(t) {
    const e = this.parent;
    e !== null && (t(e), e.traverseAncestors(t));
  }
  updateMatrix() {
    this.matrix.compose(this.position, this.quaternion, this.scale), this.matrixWorldNeedsUpdate = !0;
  }
  updateMatrixWorld(t) {
    this.matrixAutoUpdate && this.updateMatrix(), (this.matrixWorldNeedsUpdate || t) && (this.parent === null ? this.matrixWorld.copy(this.matrix) : this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix), this.matrixWorldNeedsUpdate = !1, t = !0);
    const e = this.children;
    for (let i = 0, n = e.length; i < n; i++) {
      const r = e[i];
      (r.matrixWorldAutoUpdate === !0 || t === !0) && r.updateMatrixWorld(t);
    }
  }
  updateWorldMatrix(t, e) {
    const i = this.parent;
    if (t === !0 && i !== null && i.matrixWorldAutoUpdate === !0 && i.updateWorldMatrix(!0, !1), this.matrixAutoUpdate && this.updateMatrix(), this.parent === null ? this.matrixWorld.copy(this.matrix) : this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix), e === !0) {
      const n = this.children;
      for (let r = 0, a = n.length; r < a; r++) {
        const o = n[r];
        o.matrixWorldAutoUpdate === !0 && o.updateWorldMatrix(!1, !0);
      }
    }
  }
  toJSON(t) {
    const e = t === void 0 || typeof t == "string", i = {};
    e && (t = {
      geometries: {},
      materials: {},
      textures: {},
      images: {},
      shapes: {},
      skeletons: {},
      animations: {},
      nodes: {}
    }, i.metadata = {
      version: 4.6,
      type: "Object",
      generator: "Object3D.toJSON"
    });
    const n = {};
    n.uuid = this.uuid, n.type = this.type, this.name !== "" && (n.name = this.name), this.castShadow === !0 && (n.castShadow = !0), this.receiveShadow === !0 && (n.receiveShadow = !0), this.visible === !1 && (n.visible = !1), this.frustumCulled === !1 && (n.frustumCulled = !1), this.renderOrder !== 0 && (n.renderOrder = this.renderOrder), Object.keys(this.userData).length > 0 && (n.userData = this.userData), n.layers = this.layers.mask, n.matrix = this.matrix.toArray(), n.up = this.up.toArray(), this.matrixAutoUpdate === !1 && (n.matrixAutoUpdate = !1), this.isInstancedMesh && (n.type = "InstancedMesh", n.count = this.count, n.instanceMatrix = this.instanceMatrix.toJSON(), this.instanceColor !== null && (n.instanceColor = this.instanceColor.toJSON())), this.isBatchedMesh && (n.type = "BatchedMesh", n.perObjectFrustumCulled = this.perObjectFrustumCulled, n.sortObjects = this.sortObjects, n.drawRanges = this._drawRanges, n.reservedRanges = this._reservedRanges, n.visibility = this._visibility, n.active = this._active, n.bounds = this._bounds.map((o) => ({
      boxInitialized: o.boxInitialized,
      boxMin: o.box.min.toArray(),
      boxMax: o.box.max.toArray(),
      sphereInitialized: o.sphereInitialized,
      sphereRadius: o.sphere.radius,
      sphereCenter: o.sphere.center.toArray()
    })), n.maxGeometryCount = this._maxGeometryCount, n.maxVertexCount = this._maxVertexCount, n.maxIndexCount = this._maxIndexCount, n.geometryInitialized = this._geometryInitialized, n.geometryCount = this._geometryCount, n.matricesTexture = this._matricesTexture.toJSON(t), this.boundingSphere !== null && (n.boundingSphere = {
      center: n.boundingSphere.center.toArray(),
      radius: n.boundingSphere.radius
    }), this.boundingBox !== null && (n.boundingBox = {
      min: n.boundingBox.min.toArray(),
      max: n.boundingBox.max.toArray()
    }));
    function r(o, h) {
      return o[h.uuid] === void 0 && (o[h.uuid] = h.toJSON(t)), h.uuid;
    }
    if (this.isScene)
      this.background && (this.background.isColor ? n.background = this.background.toJSON() : this.background.isTexture && (n.background = this.background.toJSON(t).uuid)), this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== !0 && (n.environment = this.environment.toJSON(t).uuid);
    else if (this.isMesh || this.isLine || this.isPoints) {
      n.geometry = r(t.geometries, this.geometry);
      const o = this.geometry.parameters;
      if (o !== void 0 && o.shapes !== void 0) {
        const h = o.shapes;
        if (Array.isArray(h))
          for (let l = 0, A = h.length; l < A; l++) {
            const u = h[l];
            r(t.shapes, u);
          }
        else
          r(t.shapes, h);
      }
    }
    if (this.isSkinnedMesh && (n.bindMode = this.bindMode, n.bindMatrix = this.bindMatrix.toArray(), this.skeleton !== void 0 && (r(t.skeletons, this.skeleton), n.skeleton = this.skeleton.uuid)), this.material !== void 0)
      if (Array.isArray(this.material)) {
        const o = [];
        for (let h = 0, l = this.material.length; h < l; h++)
          o.push(r(t.materials, this.material[h]));
        n.material = o;
      } else
        n.material = r(t.materials, this.material);
    if (this.children.length > 0) {
      n.children = [];
      for (let o = 0; o < this.children.length; o++)
        n.children.push(this.children[o].toJSON(t).object);
    }
    if (this.animations.length > 0) {
      n.animations = [];
      for (let o = 0; o < this.animations.length; o++) {
        const h = this.animations[o];
        n.animations.push(r(t.animations, h));
      }
    }
    if (e) {
      const o = a(t.geometries), h = a(t.materials), l = a(t.textures), A = a(t.images), u = a(t.shapes), f = a(t.skeletons), d = a(t.animations), c = a(t.nodes);
      o.length > 0 && (i.geometries = o), h.length > 0 && (i.materials = h), l.length > 0 && (i.textures = l), A.length > 0 && (i.images = A), u.length > 0 && (i.shapes = u), f.length > 0 && (i.skeletons = f), d.length > 0 && (i.animations = d), c.length > 0 && (i.nodes = c);
    }
    return i.object = n, i;
    function a(o) {
      const h = [];
      for (const l in o) {
        const A = o[l];
        delete A.metadata, h.push(A);
      }
      return h;
    }
  }
  clone(t) {
    return new this.constructor().copy(this, t);
  }
  copy(t, e = !0) {
    if (this.name = t.name, this.up.copy(t.up), this.position.copy(t.position), this.rotation.order = t.rotation.order, this.quaternion.copy(t.quaternion), this.scale.copy(t.scale), this.matrix.copy(t.matrix), this.matrixWorld.copy(t.matrixWorld), this.matrixAutoUpdate = t.matrixAutoUpdate, this.matrixWorldAutoUpdate = t.matrixWorldAutoUpdate, this.matrixWorldNeedsUpdate = t.matrixWorldNeedsUpdate, this.layers.mask = t.layers.mask, this.visible = t.visible, this.castShadow = t.castShadow, this.receiveShadow = t.receiveShadow, this.frustumCulled = t.frustumCulled, this.renderOrder = t.renderOrder, this.animations = t.animations.slice(), this.userData = JSON.parse(JSON.stringify(t.userData)), e === !0)
      for (let i = 0; i < t.children.length; i++) {
        const n = t.children[i];
        this.add(n.clone());
      }
    return this;
  }
}
xe.DEFAULT_UP = /* @__PURE__ */ new j(0, 1, 0);
xe.DEFAULT_MATRIX_AUTO_UPDATE = !0;
xe.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = !0;
const lo = {
  aliceblue: 15792383,
  antiquewhite: 16444375,
  aqua: 65535,
  aquamarine: 8388564,
  azure: 15794175,
  beige: 16119260,
  bisque: 16770244,
  black: 0,
  blanchedalmond: 16772045,
  blue: 255,
  blueviolet: 9055202,
  brown: 10824234,
  burlywood: 14596231,
  cadetblue: 6266528,
  chartreuse: 8388352,
  chocolate: 13789470,
  coral: 16744272,
  cornflowerblue: 6591981,
  cornsilk: 16775388,
  crimson: 14423100,
  cyan: 65535,
  darkblue: 139,
  darkcyan: 35723,
  darkgoldenrod: 12092939,
  darkgray: 11119017,
  darkgreen: 25600,
  darkgrey: 11119017,
  darkkhaki: 12433259,
  darkmagenta: 9109643,
  darkolivegreen: 5597999,
  darkorange: 16747520,
  darkorchid: 10040012,
  darkred: 9109504,
  darksalmon: 15308410,
  darkseagreen: 9419919,
  darkslateblue: 4734347,
  darkslategray: 3100495,
  darkslategrey: 3100495,
  darkturquoise: 52945,
  darkviolet: 9699539,
  deeppink: 16716947,
  deepskyblue: 49151,
  dimgray: 6908265,
  dimgrey: 6908265,
  dodgerblue: 2003199,
  firebrick: 11674146,
  floralwhite: 16775920,
  forestgreen: 2263842,
  fuchsia: 16711935,
  gainsboro: 14474460,
  ghostwhite: 16316671,
  gold: 16766720,
  goldenrod: 14329120,
  gray: 8421504,
  green: 32768,
  greenyellow: 11403055,
  grey: 8421504,
  honeydew: 15794160,
  hotpink: 16738740,
  indianred: 13458524,
  indigo: 4915330,
  ivory: 16777200,
  khaki: 15787660,
  lavender: 15132410,
  lavenderblush: 16773365,
  lawngreen: 8190976,
  lemonchiffon: 16775885,
  lightblue: 11393254,
  lightcoral: 15761536,
  lightcyan: 14745599,
  lightgoldenrodyellow: 16448210,
  lightgray: 13882323,
  lightgreen: 9498256,
  lightgrey: 13882323,
  lightpink: 16758465,
  lightsalmon: 16752762,
  lightseagreen: 2142890,
  lightskyblue: 8900346,
  lightslategray: 7833753,
  lightslategrey: 7833753,
  lightsteelblue: 11584734,
  lightyellow: 16777184,
  lime: 65280,
  limegreen: 3329330,
  linen: 16445670,
  magenta: 16711935,
  maroon: 8388608,
  mediumaquamarine: 6737322,
  mediumblue: 205,
  mediumorchid: 12211667,
  mediumpurple: 9662683,
  mediumseagreen: 3978097,
  mediumslateblue: 8087790,
  mediumspringgreen: 64154,
  mediumturquoise: 4772300,
  mediumvioletred: 13047173,
  midnightblue: 1644912,
  mintcream: 16121850,
  mistyrose: 16770273,
  moccasin: 16770229,
  navajowhite: 16768685,
  navy: 128,
  oldlace: 16643558,
  olive: 8421376,
  olivedrab: 7048739,
  orange: 16753920,
  orangered: 16729344,
  orchid: 14315734,
  palegoldenrod: 15657130,
  palegreen: 10025880,
  paleturquoise: 11529966,
  palevioletred: 14381203,
  papayawhip: 16773077,
  peachpuff: 16767673,
  peru: 13468991,
  pink: 16761035,
  plum: 14524637,
  powderblue: 11591910,
  purple: 8388736,
  rebeccapurple: 6697881,
  red: 16711680,
  rosybrown: 12357519,
  royalblue: 4286945,
  saddlebrown: 9127187,
  salmon: 16416882,
  sandybrown: 16032864,
  seagreen: 3050327,
  seashell: 16774638,
  sienna: 10506797,
  silver: 12632256,
  skyblue: 8900331,
  slateblue: 6970061,
  slategray: 7372944,
  slategrey: 7372944,
  snow: 16775930,
  springgreen: 65407,
  steelblue: 4620980,
  tan: 13808780,
  teal: 32896,
  thistle: 14204888,
  tomato: 16737095,
  turquoise: 4251856,
  violet: 15631086,
  wheat: 16113331,
  white: 16777215,
  whitesmoke: 16119285,
  yellow: 16776960,
  yellowgreen: 10145074
}, re = { h: 0, s: 0, l: 0 }, ji = { h: 0, s: 0, l: 0 };
function Cr(s, t, e) {
  return e < 0 && (e += 1), e > 1 && (e -= 1), e < 1 / 6 ? s + (t - s) * 6 * e : e < 1 / 2 ? t : e < 2 / 3 ? s + (t - s) * 6 * (2 / 3 - e) : s;
}
class ls {
  constructor(t, e, i) {
    return this.isColor = !0, this.r = 1, this.g = 1, this.b = 1, this.set(t, e, i);
  }
  set(t, e, i) {
    if (e === void 0 && i === void 0) {
      const n = t;
      n && n.isColor ? this.copy(n) : typeof n == "number" ? this.setHex(n) : typeof n == "string" && this.setStyle(n);
    } else
      this.setRGB(t, e, i);
    return this;
  }
  setScalar(t) {
    return this.r = t, this.g = t, this.b = t, this;
  }
  setHex(t, e = oe) {
    return t = Math.floor(t), this.r = (t >> 16 & 255) / 255, this.g = (t >> 8 & 255) / 255, this.b = (t & 255) / 255, kt.toWorkingColorSpace(this, e), this;
  }
  setRGB(t, e, i, n = kt.workingColorSpace) {
    return this.r = t, this.g = e, this.b = i, kt.toWorkingColorSpace(this, n), this;
  }
  setHSL(t, e, i, n = kt.workingColorSpace) {
    if (t = hs(t, 1), e = mt(e, 0, 1), i = mt(i, 0, 1), e === 0)
      this.r = this.g = this.b = i;
    else {
      const r = i <= 0.5 ? i * (1 + e) : i + e - i * e, a = 2 * i - r;
      this.r = Cr(a, r, t + 1 / 3), this.g = Cr(a, r, t), this.b = Cr(a, r, t - 1 / 3);
    }
    return kt.toWorkingColorSpace(this, n), this;
  }
  setStyle(t, e = oe) {
    function i(r) {
      r !== void 0 && parseFloat(r) < 1 && console.warn("THREE.Color: Alpha component of " + t + " will be ignored.");
    }
    let n;
    if (n = /^(\w+)\(([^\)]*)\)/.exec(t)) {
      let r;
      const a = n[1], o = n[2];
      switch (a) {
        case "rgb":
        case "rgba":
          if (r = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))
            return i(r[4]), this.setRGB(
              Math.min(255, parseInt(r[1], 10)) / 255,
              Math.min(255, parseInt(r[2], 10)) / 255,
              Math.min(255, parseInt(r[3], 10)) / 255,
              e
            );
          if (r = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))
            return i(r[4]), this.setRGB(
              Math.min(100, parseInt(r[1], 10)) / 100,
              Math.min(100, parseInt(r[2], 10)) / 100,
              Math.min(100, parseInt(r[3], 10)) / 100,
              e
            );
          break;
        case "hsl":
        case "hsla":
          if (r = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))
            return i(r[4]), this.setHSL(
              parseFloat(r[1]) / 360,
              parseFloat(r[2]) / 100,
              parseFloat(r[3]) / 100,
              e
            );
          break;
        default:
          console.warn("THREE.Color: Unknown color model " + t);
      }
    } else if (n = /^\#([A-Fa-f\d]+)$/.exec(t)) {
      const r = n[1], a = r.length;
      if (a === 3)
        return this.setRGB(
          parseInt(r.charAt(0), 16) / 15,
          parseInt(r.charAt(1), 16) / 15,
          parseInt(r.charAt(2), 16) / 15,
          e
        );
      if (a === 6)
        return this.setHex(parseInt(r, 16), e);
      console.warn("THREE.Color: Invalid hex color " + t);
    } else if (t && t.length > 0)
      return this.setColorName(t, e);
    return this;
  }
  setColorName(t, e = oe) {
    const i = lo[t.toLowerCase()];
    return i !== void 0 ? this.setHex(i, e) : console.warn("THREE.Color: Unknown color " + t), this;
  }
  clone() {
    return new this.constructor(this.r, this.g, this.b);
  }
  copy(t) {
    return this.r = t.r, this.g = t.g, this.b = t.b, this;
  }
  copySRGBToLinear(t) {
    return this.r = je(t.r), this.g = je(t.g), this.b = je(t.b), this;
  }
  copyLinearToSRGB(t) {
    return this.r = xr(t.r), this.g = xr(t.g), this.b = xr(t.b), this;
  }
  convertSRGBToLinear() {
    return this.copySRGBToLinear(this), this;
  }
  convertLinearToSRGB() {
    return this.copyLinearToSRGB(this), this;
  }
  getHex(t = oe) {
    return kt.fromWorkingColorSpace(yt.copy(this), t), Math.round(mt(yt.r * 255, 0, 255)) * 65536 + Math.round(mt(yt.g * 255, 0, 255)) * 256 + Math.round(mt(yt.b * 255, 0, 255));
  }
  getHexString(t = oe) {
    return ("000000" + this.getHex(t).toString(16)).slice(-6);
  }
  getHSL(t, e = kt.workingColorSpace) {
    kt.fromWorkingColorSpace(yt.copy(this), e);
    const i = yt.r, n = yt.g, r = yt.b, a = Math.max(i, n, r), o = Math.min(i, n, r);
    let h, l;
    const A = (o + a) / 2;
    if (o === a)
      h = 0, l = 0;
    else {
      const u = a - o;
      switch (l = A <= 0.5 ? u / (a + o) : u / (2 - a - o), a) {
        case i:
          h = (n - r) / u + (n < r ? 6 : 0);
          break;
        case n:
          h = (r - i) / u + 2;
          break;
        case r:
          h = (i - n) / u + 4;
          break;
      }
      h /= 6;
    }
    return t.h = h, t.s = l, t.l = A, t;
  }
  getRGB(t, e = kt.workingColorSpace) {
    return kt.fromWorkingColorSpace(yt.copy(this), e), t.r = yt.r, t.g = yt.g, t.b = yt.b, t;
  }
  getStyle(t = oe) {
    kt.fromWorkingColorSpace(yt.copy(this), t);
    const e = yt.r, i = yt.g, n = yt.b;
    return t !== oe ? `color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${n.toFixed(3)})` : `rgb(${Math.round(e * 255)},${Math.round(i * 255)},${Math.round(n * 255)})`;
  }
  offsetHSL(t, e, i) {
    return this.getHSL(re), this.setHSL(re.h + t, re.s + e, re.l + i);
  }
  add(t) {
    return this.r += t.r, this.g += t.g, this.b += t.b, this;
  }
  addColors(t, e) {
    return this.r = t.r + e.r, this.g = t.g + e.g, this.b = t.b + e.b, this;
  }
  addScalar(t) {
    return this.r += t, this.g += t, this.b += t, this;
  }
  sub(t) {
    return this.r = Math.max(0, this.r - t.r), this.g = Math.max(0, this.g - t.g), this.b = Math.max(0, this.b - t.b), this;
  }
  multiply(t) {
    return this.r *= t.r, this.g *= t.g, this.b *= t.b, this;
  }
  multiplyScalar(t) {
    return this.r *= t, this.g *= t, this.b *= t, this;
  }
  lerp(t, e) {
    return this.r += (t.r - this.r) * e, this.g += (t.g - this.g) * e, this.b += (t.b - this.b) * e, this;
  }
  lerpColors(t, e, i) {
    return this.r = t.r + (e.r - t.r) * i, this.g = t.g + (e.g - t.g) * i, this.b = t.b + (e.b - t.b) * i, this;
  }
  lerpHSL(t, e) {
    this.getHSL(re), t.getHSL(ji);
    const i = xi(re.h, ji.h, e), n = xi(re.s, ji.s, e), r = xi(re.l, ji.l, e);
    return this.setHSL(i, n, r), this;
  }
  setFromVector3(t) {
    return this.r = t.x, this.g = t.y, this.b = t.z, this;
  }
  applyMatrix3(t) {
    const e = this.r, i = this.g, n = this.b, r = t.elements;
    return this.r = r[0] * e + r[3] * i + r[6] * n, this.g = r[1] * e + r[4] * i + r[7] * n, this.b = r[2] * e + r[5] * i + r[8] * n, this;
  }
  equals(t) {
    return t.r === this.r && t.g === this.g && t.b === this.b;
  }
  fromArray(t, e = 0) {
    return this.r = t[e], this.g = t[e + 1], this.b = t[e + 2], this;
  }
  toArray(t = [], e = 0) {
    return t[e] = this.r, t[e + 1] = this.g, t[e + 2] = this.b, t;
  }
  fromBufferAttribute(t, e) {
    return this.r = t.getX(e), this.g = t.getY(e), this.b = t.getZ(e), this;
  }
  toJSON() {
    return this.getHex();
  }
  *[Symbol.iterator]() {
    yield this.r, yield this.g, yield this.b;
  }
}
const yt = /* @__PURE__ */ new ls();
ls.NAMES = lo;
class tA extends le {
  constructor(t, e, i, n, r, a, o, h, l, A) {
    if (A = A !== void 0 ? A : vr, A !== vr && A !== $s)
      throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");
    i === void 0 && A === vr && (i = vl), i === void 0 && A === $s && (i = _l), super(null, n, r, a, o, h, A, i, l), this.isDepthTexture = !0, this.image = { width: t, height: e }, this.magFilter = o !== void 0 ? o : Vs, this.minFilter = h !== void 0 ? h : Vs, this.flipY = !1, this.generateMipmaps = !1, this.compareFunction = null;
  }
  copy(t) {
    return super.copy(t), this.compareFunction = t.compareFunction, this;
  }
  toJSON(t) {
    const e = super.toJSON(t);
    return this.compareFunction !== null && (e.compareFunction = this.compareFunction), e;
  }
}
const eA = /* @__PURE__ */ new tA(1, 1);
eA.compareFunction = wl;
const iA = {
  triangulate: function(s, t, e = 2) {
    const i = t && t.length, n = i ? t[0] * e : s.length;
    let r = Ao(s, 0, n, e, !0);
    const a = [];
    if (!r || r.next === r.prev)
      return a;
    let o, h, l, A, u, f, d;
    if (i && (r = oA(s, t, r, e)), s.length > 80 * e) {
      o = l = s[0], h = A = s[1];
      for (let c = e; c < n; c += e)
        u = s[c], f = s[c + 1], u < o && (o = u), f < h && (h = f), u > l && (l = u), f > A && (A = f);
      d = Math.max(l - o, A - h), d = d !== 0 ? 32767 / d : 0;
    }
    return Si(r, a, e, o, h, d, 0), a;
  }
};
function Ao(s, t, e, i, n) {
  let r, a;
  if (n === mA(s, t, e, i) > 0)
    for (r = t; r < e; r += i)
      a = oa(r, s[r], s[r + 1], a);
  else
    for (r = e - i; r >= t; r -= i)
      a = oa(r, s[r], s[r + 1], a);
  return a && kn(a, a.next) && (Mi(a), a = a.next), a;
}
function we(s, t) {
  if (!s)
    return s;
  t || (t = s);
  let e = s, i;
  do
    if (i = !1, !e.steiner && (kn(e, e.next) || at(e.prev, e, e.next) === 0)) {
      if (Mi(e), e = t = e.prev, e === e.next)
        break;
      i = !0;
    } else
      e = e.next;
  while (i || e !== t);
  return t;
}
function Si(s, t, e, i, n, r, a) {
  if (!s)
    return;
  !a && r && cA(s, i, n, r);
  let o = s, h, l;
  for (; s.prev !== s.next; ) {
    if (h = s.prev, l = s.next, r ? rA(s, i, n, r) : nA(s)) {
      t.push(h.i / e | 0), t.push(s.i / e | 0), t.push(l.i / e | 0), Mi(s), s = l.next, o = l.next;
      continue;
    }
    if (s = l, s === o) {
      a ? a === 1 ? (s = sA(we(s), t, e), Si(s, t, e, i, n, r, 2)) : a === 2 && aA(s, t, e, i, n, r) : Si(we(s), t, e, i, n, r, 1);
      break;
    }
  }
}
function nA(s) {
  const t = s.prev, e = s, i = s.next;
  if (at(t, e, i) >= 0)
    return !1;
  const n = t.x, r = e.x, a = i.x, o = t.y, h = e.y, l = i.y, A = n < r ? n < a ? n : a : r < a ? r : a, u = o < h ? o < l ? o : l : h < l ? h : l, f = n > r ? n > a ? n : a : r > a ? r : a, d = o > h ? o > l ? o : l : h > l ? h : l;
  let c = i.next;
  for (; c !== t; ) {
    if (c.x >= A && c.x <= f && c.y >= u && c.y <= d && We(n, o, r, h, a, l, c.x, c.y) && at(c.prev, c, c.next) >= 0)
      return !1;
    c = c.next;
  }
  return !0;
}
function rA(s, t, e, i) {
  const n = s.prev, r = s, a = s.next;
  if (at(n, r, a) >= 0)
    return !1;
  const o = n.x, h = r.x, l = a.x, A = n.y, u = r.y, f = a.y, d = o < h ? o < l ? o : l : h < l ? h : l, c = A < u ? A < f ? A : f : u < f ? u : f, p = o > h ? o > l ? o : l : h > l ? h : l, m = A > u ? A > f ? A : f : u > f ? u : f, v = Vr(d, c, t, e, i), x = Vr(p, m, t, e, i);
  let g = s.prevZ, y = s.nextZ;
  for (; g && g.z >= v && y && y.z <= x; ) {
    if (g.x >= d && g.x <= p && g.y >= c && g.y <= m && g !== n && g !== a && We(o, A, h, u, l, f, g.x, g.y) && at(g.prev, g, g.next) >= 0 || (g = g.prevZ, y.x >= d && y.x <= p && y.y >= c && y.y <= m && y !== n && y !== a && We(o, A, h, u, l, f, y.x, y.y) && at(y.prev, y, y.next) >= 0))
      return !1;
    y = y.nextZ;
  }
  for (; g && g.z >= v; ) {
    if (g.x >= d && g.x <= p && g.y >= c && g.y <= m && g !== n && g !== a && We(o, A, h, u, l, f, g.x, g.y) && at(g.prev, g, g.next) >= 0)
      return !1;
    g = g.prevZ;
  }
  for (; y && y.z <= x; ) {
    if (y.x >= d && y.x <= p && y.y >= c && y.y <= m && y !== n && y !== a && We(o, A, h, u, l, f, y.x, y.y) && at(y.prev, y, y.next) >= 0)
      return !1;
    y = y.nextZ;
  }
  return !0;
}
function sA(s, t, e) {
  let i = s;
  do {
    const n = i.prev, r = i.next.next;
    !kn(n, r) && co(n, i, i.next, r) && Ci(n, r) && Ci(r, n) && (t.push(n.i / e | 0), t.push(i.i / e | 0), t.push(r.i / e | 0), Mi(i), Mi(i.next), i = s = r), i = i.next;
  } while (i !== s);
  return we(i);
}
function aA(s, t, e, i, n, r) {
  let a = s;
  do {
    let o = a.next.next;
    for (; o !== a.prev; ) {
      if (a.i !== o.i && gA(a, o)) {
        let h = uo(a, o);
        a = we(a, a.next), h = we(h, h.next), Si(a, t, e, i, n, r, 0), Si(h, t, e, i, n, r, 0);
        return;
      }
      o = o.next;
    }
    a = a.next;
  } while (a !== s);
}
function oA(s, t, e, i) {
  const n = [];
  let r, a, o, h, l;
  for (r = 0, a = t.length; r < a; r++)
    o = t[r] * i, h = r < a - 1 ? t[r + 1] * i : s.length, l = Ao(s, o, h, i, !1), l === l.next && (l.steiner = !0), n.push(fA(l));
  for (n.sort(hA), r = 0; r < n.length; r++)
    e = lA(n[r], e);
  return e;
}
function hA(s, t) {
  return s.x - t.x;
}
function lA(s, t) {
  const e = AA(s, t);
  if (!e)
    return t;
  const i = uo(e, s);
  return we(i, i.next), we(e, e.next);
}
function AA(s, t) {
  let e = t, i = -1 / 0, n;
  const r = s.x, a = s.y;
  do {
    if (a <= e.y && a >= e.next.y && e.next.y !== e.y) {
      const f = e.x + (a - e.y) * (e.next.x - e.x) / (e.next.y - e.y);
      if (f <= r && f > i && (i = f, n = e.x < e.next.x ? e : e.next, f === r))
        return n;
    }
    e = e.next;
  } while (e !== t);
  if (!n)
    return null;
  const o = n, h = n.x, l = n.y;
  let A = 1 / 0, u;
  e = n;
  do
    r >= e.x && e.x >= h && r !== e.x && We(a < l ? r : i, a, h, l, a < l ? i : r, a, e.x, e.y) && (u = Math.abs(a - e.y) / (r - e.x), Ci(e, s) && (u < A || u === A && (e.x > n.x || e.x === n.x && dA(n, e))) && (n = e, A = u)), e = e.next;
  while (e !== o);
  return n;
}
function dA(s, t) {
  return at(s.prev, s, t.prev) < 0 && at(t.next, s, s.next) < 0;
}
function cA(s, t, e, i) {
  let n = s;
  do
    n.z === 0 && (n.z = Vr(n.x, n.y, t, e, i)), n.prevZ = n.prev, n.nextZ = n.next, n = n.next;
  while (n !== s);
  n.prevZ.nextZ = null, n.prevZ = null, uA(n);
}
function uA(s) {
  let t, e, i, n, r, a, o, h, l = 1;
  do {
    for (e = s, s = null, r = null, a = 0; e; ) {
      for (a++, i = e, o = 0, t = 0; t < l && (o++, i = i.nextZ, !!i); t++)
        ;
      for (h = l; o > 0 || h > 0 && i; )
        o !== 0 && (h === 0 || !i || e.z <= i.z) ? (n = e, e = e.nextZ, o--) : (n = i, i = i.nextZ, h--), r ? r.nextZ = n : s = n, n.prevZ = r, r = n;
      e = i;
    }
    r.nextZ = null, l *= 2;
  } while (a > 1);
  return s;
}
function Vr(s, t, e, i, n) {
  return s = (s - e) * n | 0, t = (t - i) * n | 0, s = (s | s << 8) & 16711935, s = (s | s << 4) & 252645135, s = (s | s << 2) & 858993459, s = (s | s << 1) & 1431655765, t = (t | t << 8) & 16711935, t = (t | t << 4) & 252645135, t = (t | t << 2) & 858993459, t = (t | t << 1) & 1431655765, s | t << 1;
}
function fA(s) {
  let t = s, e = s;
  do
    (t.x < e.x || t.x === e.x && t.y < e.y) && (e = t), t = t.next;
  while (t !== s);
  return e;
}
function We(s, t, e, i, n, r, a, o) {
  return (n - a) * (t - o) >= (s - a) * (r - o) && (s - a) * (i - o) >= (e - a) * (t - o) && (e - a) * (r - o) >= (n - a) * (i - o);
}
function gA(s, t) {
  return s.next.i !== t.i && s.prev.i !== t.i && !pA(s, t) && // dones't intersect other edges
  (Ci(s, t) && Ci(t, s) && yA(s, t) && // locally visible
  (at(s.prev, s, t.prev) || at(s, t.prev, t)) || // does not create opposite-facing sectors
  kn(s, t) && at(s.prev, s, s.next) > 0 && at(t.prev, t, t.next) > 0);
}
function at(s, t, e) {
  return (t.y - s.y) * (e.x - t.x) - (t.x - s.x) * (e.y - t.y);
}
function kn(s, t) {
  return s.x === t.x && s.y === t.y;
}
function co(s, t, e, i) {
  const n = Qi(at(s, t, e)), r = Qi(at(s, t, i)), a = Qi(at(e, i, s)), o = Qi(at(e, i, t));
  return !!(n !== r && a !== o || n === 0 && qi(s, e, t) || r === 0 && qi(s, i, t) || a === 0 && qi(e, s, i) || o === 0 && qi(e, t, i));
}
function qi(s, t, e) {
  return t.x <= Math.max(s.x, e.x) && t.x >= Math.min(s.x, e.x) && t.y <= Math.max(s.y, e.y) && t.y >= Math.min(s.y, e.y);
}
function Qi(s) {
  return s > 0 ? 1 : s < 0 ? -1 : 0;
}
function pA(s, t) {
  let e = s;
  do {
    if (e.i !== s.i && e.next.i !== s.i && e.i !== t.i && e.next.i !== t.i && co(e, e.next, s, t))
      return !0;
    e = e.next;
  } while (e !== s);
  return !1;
}
function Ci(s, t) {
  return at(s.prev, s, s.next) < 0 ? at(s, t, s.next) >= 0 && at(s, s.prev, t) >= 0 : at(s, t, s.prev) < 0 || at(s, s.next, t) < 0;
}
function yA(s, t) {
  let e = s, i = !1;
  const n = (s.x + t.x) / 2, r = (s.y + t.y) / 2;
  do
    e.y > r != e.next.y > r && e.next.y !== e.y && n < (e.next.x - e.x) * (r - e.y) / (e.next.y - e.y) + e.x && (i = !i), e = e.next;
  while (e !== s);
  return i;
}
function uo(s, t) {
  const e = new $r(s.i, s.x, s.y), i = new $r(t.i, t.x, t.y), n = s.next, r = t.prev;
  return s.next = t, t.prev = s, e.next = n, n.prev = e, i.next = e, e.prev = i, r.next = i, i.prev = r, i;
}
function oa(s, t, e, i) {
  const n = new $r(s, t, e);
  return i ? (n.next = i.next, n.prev = i, i.next.prev = n, i.next = n) : (n.prev = n, n.next = n), n;
}
function Mi(s) {
  s.next.prev = s.prev, s.prev.next = s.next, s.prevZ && (s.prevZ.nextZ = s.nextZ), s.nextZ && (s.nextZ.prevZ = s.prevZ);
}
function $r(s, t, e) {
  this.i = s, this.x = t, this.y = e, this.prev = null, this.next = null, this.z = 0, this.prevZ = null, this.nextZ = null, this.steiner = !1;
}
function mA(s, t, e, i) {
  let n = 0;
  for (let r = t, a = e - i; r < e; r += i)
    n += (s[a] - s[r]) * (s[r + 1] + s[a + 1]), a = r;
  return n;
}
class As {
  // calculate area of the contour polygon
  static area(t) {
    const e = t.length;
    let i = 0;
    for (let n = e - 1, r = 0; r < e; n = r++)
      i += t[n].x * t[r].y - t[r].x * t[n].y;
    return i * 0.5;
  }
  static isClockWise(t) {
    return As.area(t) < 0;
  }
  static triangulateShape(t, e) {
    const i = [], n = [], r = [];
    ha(t), la(i, t);
    let a = t.length;
    e.forEach(ha);
    for (let h = 0; h < e.length; h++)
      n.push(a), a += e[h].length, la(i, e[h]);
    const o = iA.triangulate(i, n);
    for (let h = 0; h < o.length; h += 3)
      r.push(o.slice(h, h + 3));
    return r;
  }
}
function ha(s) {
  const t = s.length;
  t > 2 && s[t - 1].equals(s[0]) && s.pop();
}
function la(s, t) {
  for (let e = 0; e < t.length; e++)
    s.push(t[e].x), s.push(t[e].y);
}
const Aa = /* @__PURE__ */ new j(), Ki = /* @__PURE__ */ new j();
class vA {
  constructor(t = new j(), e = new j()) {
    this.start = t, this.end = e;
  }
  set(t, e) {
    return this.start.copy(t), this.end.copy(e), this;
  }
  copy(t) {
    return this.start.copy(t.start), this.end.copy(t.end), this;
  }
  getCenter(t) {
    return t.addVectors(this.start, this.end).multiplyScalar(0.5);
  }
  delta(t) {
    return t.subVectors(this.end, this.start);
  }
  distanceSq() {
    return this.start.distanceToSquared(this.end);
  }
  distance() {
    return this.start.distanceTo(this.end);
  }
  at(t, e) {
    return this.delta(e).multiplyScalar(t).add(this.start);
  }
  closestPointToPointParameter(t, e) {
    Aa.subVectors(t, this.start), Ki.subVectors(this.end, this.start);
    const i = Ki.dot(Ki);
    let r = Ki.dot(Aa) / i;
    return e && (r = mt(r, 0, 1)), r;
  }
  closestPointToPoint(t, e, i) {
    const n = this.closestPointToPointParameter(t, e);
    return this.delta(i).multiplyScalar(n).add(this.start);
  }
  applyMatrix4(t) {
    return this.start.applyMatrix4(t), this.end.applyMatrix4(t), this;
  }
  equals(t) {
    return t.start.equals(this.start) && t.end.equals(this.end);
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register", { detail: {
  revision: io
} }));
typeof window < "u" && (window.__THREE__ ? console.warn("WARNING: Multiple instances of Three.js being imported.") : window.__THREE__ = io);
const Wr = (s) => new X(s[2] - s[0], s[3] - s[1]).normalize(), da = 1e-6, se = (s, t) => Math.abs(s[0] - t[0]) < da && Math.abs(s[1] - t[1]) < da, Et = (s, t) => new X(s[0], s[1]).distanceTo({ x: t[0], y: t[1] }), Ou = (s) => new X(s[0], s[1]).length(), Ae = (s) => Wr(s).toArray(), ds = (s) => new X(-s[1], s[0]).normalize().toArray(), _A = (s, t) => {
  const e = new Zt().set(
    Math.cos(t),
    -Math.sin(t),
    0,
    Math.sin(t),
    Math.cos(t),
    0,
    0,
    0,
    1
  ), i = new X(s[0], s[1]);
  return i.applyMatrix3(e), i.toArray();
}, qe = (s, t, e) => {
  const i = new X(s[0], s[1]);
  return [
    ...t,
    ...i.multiplyScalar(e).add({ x: t[0], y: t[1] }).toArray()
  ];
}, xA = (s) => ds(Ae(s)), Nu = (s, t = [0, 0], e = 1) => {
  const i = ds(s), n = new X(i[0], i[1]);
  return n.multiplyScalar(e).add({ x: t[0], y: t[1] }), [...t, ...n.toArray()];
}, Ye = (s, t) => {
  const e = new X(s[0], s[1]), i = new X(t[0], t[1]), n = e.angleTo(i);
  return e.cross(i) > 0 ? n : -n;
}, bA = (s, t) => Ye(Ae(s), Ae(t)), wA = (s, t) => Ye(t, Ae(s)), Gu = (s) => [(s[0] + s[2]) / 2, (s[1] + s[3]) / 2], he = (s, t = 2) => {
  const e = Math.pow(10, t);
  return Math.round(s * e) / e;
};
var fo = /* @__PURE__ */ ((s) => (s.Overlap = "Overlap", s.Intersect = "Intersect", s.ExtendIntersect = "ExtendIntersect", s.Parallel = "Parallel", s.Join = "Join", s.Equal = "Equal", s.None = "None", s))(fo || {});
const SA = (s, t) => {
  const e = s.slice(0, 2), i = t.slice(0, 2), n = s.slice(2, 4), r = t.slice(2, 4);
  if (se(e, i) && se(n, r))
    return "Equal";
  const a = se(e, i) || se(e, r) || se(n, i) || se(n, r), o = Wr(s), h = Wr(t), l = new X(-o.y, o.x).normalize(), A = new X(-h.y, h.x).normalize(), u = new X(s[0], s[1]), f = new X(t[0], t[1]), d = new X(s[2], s[3]), c = new X(t[2], t[3]), p = he(
    A.dot(f.clone().sub(u).normalize()) / A.dot(o),
    6
  ), m = he(
    l.dot(u.clone().sub(f).normalize()) / l.dot(h),
    6
  ), v = A.negate();
  if (p === 0 && m === 0)
    return "Overlap";
  if (se([l.x, l.y], [A.x, A.y]) || se([l.x, l.y], [v.x, v.y]))
    return a ? "Overlap" : "Parallel";
  {
    if (a)
      return "Join";
    const x = (c.y - f.y) * (d.x - u.x) - (c.x - f.x) * (d.y - u.y), g = he(
      ((c.x - f.x) * (u.y - f.y) - (c.y - f.y) * (u.x - f.x)) / x,
      6
    ), y = he(
      ((d.x - u.x) * (u.y - f.y) - (d.y - u.y) * (u.x - f.x)) / x,
      6
    );
    return g >= 0 && g <= 1 && y >= 0 && y <= 1 ? "Intersect" : "ExtendIntersect";
  }
}, go = (s, t, e = [
  "Overlap",
  "Intersect",
  "ExtendIntersect",
  "Parallel",
  "Join",
  "Equal",
  "None"
  /* None */
]) => {
  let i = SA(s, t);
  if (!e.includes(i))
    return null;
  const n = new X(s[0], s[1]), r = new X(s[2], s[3]), a = new X(t[0], t[1]), o = new X(t[2], t[3]), h = r.clone().sub(n), l = o.clone().sub(a), A = h.x, u = -l.x, f = h.y, d = -l.y, c = a.x - n.x, p = a.y - n.y, m = (d * c - u * p) / (A * d - u * f);
  return n.clone().add(h.clone().multiplyScalar(m)).toArray();
}, Gi = (s, t) => {
  const e = new X(s[0], s[1]), i = new X(s[2], s[3]), n = new X(t[0], t[1]), r = i.clone().sub(e), o = n.clone().sub(e).dot(r.normalize()), h = e.add(r.multiplyScalar(o));
  return {
    point: h.toArray(),
    len: h.distanceTo(e)
  };
}, CA = (s, t) => {
  const e = new vA(
    new j(s[0], s[1], 0),
    new j(s[2], s[3], 0)
  ), i = new j(t[0], t[1], 0), n = e.closestPointToPoint(i, !0, new j());
  return [n.x, n.y];
}, MA = (s, t) => {
  const e = CA(s, t);
  return Et(t, e);
}, Bu = (s) => {
  const t = s.map((e) => new X(e[0], e[1]));
  return As.isClockWise(t);
}, zu = (s, t, e = 5) => {
  const i = [];
  for (let n = 0; n < e; n++) {
    const r = t.map((o) => o *= n + 1), a = Gi(s, [
      s[0] + r[0],
      s[1] + r[1]
    ]).point;
    i.push(a);
  }
  return i;
}, PA = Object.prototype.toString, EA = (s) => PA.call(s), hn = (s) => EA(s).slice(8, -1), $e = (s, t, e) => {
  if (s === t)
    return !1;
  const i = hn(s), n = hn(t);
  if (i !== n)
    return !0;
  if (i === "String" || i === "Number" || i === "Boolean")
    return i === "Number" && isNaN(s) && isNaN(t) ? !1 : s !== t;
  const r = Array.from(e.values());
  for (const a of r)
    if (a.includes(s) && a.includes(t))
      return !1;
  if (e.add([s, t]), i === "Array")
    return s.length !== t.length || s.some((a, o) => $e(a, t[o], e));
  if (i === "Object") {
    const a = Object.keys(s).sort(), o = Object.keys(t).sort();
    return $e(a, o, e) || a.some((h) => $e(s[h], t[h], e));
  } else if (i === "Map") {
    const a = Array.from(s.keys()).sort(), o = Array.from(t.keys()).sort();
    return $e(a, o, e) || a.some((h) => $e(s.get(h), t.get(h), e));
  } else
    return i === "Set" ? oi(Array.from(s.values()), Array.from(t.values())) : s !== t;
}, oi = (s, t) => $e(s, t, /* @__PURE__ */ new Set());
let _e = !1;
const bi = [], po = () => {
  console.log("disable mose"), _e = !0, bi.forEach((s) => s.draggable(!1));
}, yo = () => {
  _e = !1, bi.forEach((s) => s.draggable(!0));
}, ca = (s, t = []) => ["draging", "active", "hover"].find((i) => s[i] && !t.includes(i)), ua = (s, t, e = "mouse-style") => {
  s.listening(!0);
  const i = [], n = (A, u) => {
    s.on(A, u), i.push(A);
  };
  let r;
  t.bus && t.bus.on("statusChange", (A) => {
    r = A, A && Object.assign(a, A), h();
  });
  const a = {
    hover: !1,
    draging: !1,
    active: !1
  };
  let o = "common";
  const h = (A) => {
    let u = r && ca(r);
    u || (u = _e ? "common" : ca(a) || "common"), o !== u && (t[u] && t[u](A), o = u);
  };
  t.hover && (n(`mouseenter.${e}`, (A) => {
    a.hover = !0, h(A);
  }), n(`mouseleave.${e}`, (A) => {
    a.hover = !1, h(A);
  }));
  let l;
  if (t.active) {
    let A = 0;
    n(`click.${e} touchend.${e}`, (p) => {
      t.active && (a.active = !0, h(p), A = Date.now());
    });
    const u = `click.${e}${s.id()} touchend.${e}${s.id()}`;
    let f = 3, d;
    const c = setInterval(() => {
      if (!(d = s.getStage())) {
        --f < 0 && console.error("可能发生资源泄露");
        return;
      }
      clearInterval(c), d.on(u, (p) => {
        Date.now() - A > 500 && p.target !== s && (a.active = !1, h(p));
      });
    }, 100);
    l = () => {
      d && d.off(u), clearInterval(c);
    };
  }
  return n(`dragstart.${e}`, (A) => {
    a.draging = !0, h(A);
  }), n(`dragend.${e}`, (A) => {
    setTimeout(() => {
      a.draging = !1, h(A);
    }, 16);
  }), () => {
    s.listening(!1), s.off(i.join(" ")), l && l();
  };
}, cs = (s, t, e = !0, i = !1) => {
  let n = null;
  return _e || s.draggable(!0), bi.push(s), s.dragBoundFunc((r, a) => {
    if (!_e) {
      let o = r;
      e && (o = on(s, i).invert().point(r)), t.moveHandler([o.x, o.y], n, a);
    }
    return s.absolutePosition();
  }), t.readyHandler && s.on("dragstart.drag", (r) => {
    _e || (n = t.readyHandler(r));
  }), t.endHandler && s.on("dragend.drag", (r) => {
    _e || t.endHandler(n, r);
  }), () => {
    const r = bi.indexOf(s);
    ~r && bi.splice(r, 1), s.draggable(!1), s.off("dragstart.drag dragend.drag");
  };
}, ln = (s, t) => {
  s.enableDrag({
    readyHandler(e) {
      return t.readyHandler && t.readyHandler(s.attrib, e);
    },
    moveHandler(e, i, n) {
      return t.moveHandler(s.attrib, e, i, n);
    },
    endHandler(e, i) {
      return t.endHandler && t.endHandler(s.attrib, e, i);
    }
  });
}, mo = (s, t) => {
  if (t(s))
    return s;
  if ("children" in s) {
    for (const e of s.children)
      if (mo(e, t))
        return e;
  }
  return null;
}, FA = (s, t) => {
  for (; s; ) {
    if (t(s))
      return s;
    s = s.parent;
  }
  return null;
}, Uu = (s, t) => !!mo(s, (i) => i === t), Hu = (s, t) => {
  for (const e in t)
    typeof s[e] == "function" && s[e](t[e]);
}, us = (s, t = []) => {
  const e = s.filter((r) => !t.includes(r)), i = t.filter((r) => !s.includes(r)), n = t.filter((r) => s.includes(r));
  return { addPort: e, delPort: i, holdPort: n };
}, fs = (s, t) => {
  const e = s.map(({ id: a }) => a), i = t.map(({ id: a }) => a), n = us(e, i), r = s.filter(
    (a) => !t.includes(a) && i.includes(a.id)
  ).map((a) => a.id);
  return t = s, { ...n, changePort: r };
}, Vu = (s, t, e = !0) => Me(
  () => [...s],
  (i, n = []) => {
    t(fs(i, n));
  },
  { immediate: e, flush: "sync" }
), $u = (s) => {
  const t = Ti(s()), e = Me(s, (i) => {
    oi(t, i) && (Array.isArray(i) ? i.forEach((n, r) => {
      t[r] = n;
    }) : (Object.keys(t).forEach((n) => delete t[n]), Object.assign(t, i)));
  });
  return {
    data: t,
    stop: e
  };
}, Wu = (s) => {
  const t = Ti(s()), e = Me(s, (i, n) => {
    const { addPort: r, delPort: a, changePort: o } = fs(
      i,
      n
    );
    for (const h of a) {
      const l = t.findIndex((A) => A.id === h);
      ~l && t.splice(l, 1);
    }
    for (const h of r) {
      const l = i.find((A) => A.id === h);
      l && t.push(l);
    }
    for (const h of o) {
      const l = t.findIndex((u) => u.id === h), A = i.findIndex((u) => u.id === h);
      oi(t[l], i[A]) && (t[l] = i[A]);
    }
  });
  return {
    data: t,
    stop: e
  };
}, rn = (s, t) => {
  var l, A;
  if (!oi(s, t))
    return t;
  if (!t)
    return s;
  const e = s, i = t, n = hn(e);
  if (hn(t) !== n)
    return s;
  switch (n) {
    case "Array":
      if ((l = e[0]) != null && l.id || (A = i[0]) != null && A.id) {
        var { changePort: r, addPort: a, delPort: o } = fs(e, i);
        a.forEach((p) => {
          i.push(e.find(({ id: m }) => m === p));
        }), o.forEach((p) => {
          const m = i.findIndex(({ id: v }) => v === p);
          ~m && i.splice(m, 1);
        }), r.forEach((p) => {
          const m = e.find(({ id: x }) => x === p), v = i.findIndex(({ id: x }) => x === p);
          i[v] = rn(m, i[v]);
        });
      } else {
        for (let d = 0; d < e.length; d++)
          i[d] = rn(e[d], i[d]);
        for (; i.length !== e.length; )
          i.pop();
      }
      break;
    case "Object":
      const u = Object.keys(i).sort(), f = Object.keys(e).sort();
      var { addPort: a, delPort: o, holdPort: h } = us(f, u);
      for (let d = 0; d < h.length; d++)
        i[u[d]] = rn(
          e[h[d]],
          i[h[d]]
        );
      a.forEach((d) => i[d] = e[d]), o.forEach((d) => delete i[d]);
      break;
    default:
      return s;
  }
  return t;
}, Yu = (s, t) => {
  t.forEach((e) => {
    const i = new Ri({
      fill: "red",
      radius: 5,
      x: e[0],
      y: e[1]
    });
    s.children[0].add(i);
  });
}, vo = (s) => {
  const t = [];
  for (const e of s.children)
    t.push(e, ...vo(e));
  return t;
}, kA = (s) => (Math.max(1, ...s.map(({ id: t }) => Number(t))) + 1).toString(), _o = (...s) => () => {
  s.forEach((t) => {
    Array.isArray(t) ? t.forEach((e) => e()) : t();
  });
}, DA = (s) => s ? {
  reactive: s.props.reactive,
  readonly: s.props.reactive
} : {}, TA = (s, t, e, i, n) => {
  const r = new t({
    attrib: s,
    ...DA(e)
  });
  return i && i(r), e && (r.container = e.container, r.setParent(e)), r.init(), r.mount(r.teleport), e != null && e.isMounted && r.mounted(), n && n(r), r;
}, Pt = (s, t, e, i) => {
  let n = [];
  const r = (l, A) => l.find((u) => u.id === A), a = {}, o = (l) => {
    const A = a[l];
    return A.destory(), delete a[l], A;
  }, h = (l) => {
    const A = TA(l, s, t, e, i);
    return a[l.id] = A, A;
  };
  return (l) => {
    const A = Array.isArray(l) ? l : [l], { addPort: u, delPort: f } = us(A, n), d = [], c = f.map((v) => o(v.id)), p = u.map((v) => h(r(A, v.id))), m = d.map((v) => {
      const x = r(A, v);
      return oi(x, a[v].attrib) && a[v].setAttrib(r(A, v)), a[v];
    });
    return n = [...A], {
      adds: p,
      dels: c,
      upds: m
    };
  };
}, IA = (s) => {
  const t = s.count || 1, e = s.dire || [1, 0], i = s.size, n = s.entity, r = n.shape.getPosition(), a = qe(e, [r.x, r.y], 10), o = n.container.getSameLevelData(n);
  for (let h = 0; h < t; h++) {
    const l = i.map((f) => f *= h + 1), A = Gi(a, [
      r.x + l[0],
      r.y + l[1]
    ]).point, u = {
      ...s.factoryAttrib(A),
      id: kA(o)
    };
    o.push(u);
  }
}, Mr = /* @__PURE__ */ new WeakMap(), Xu = (s, t) => {
  const e = Mr.get(s);
  e && e();
  let i = !1;
  const n = () => {
    i || (an ? s.stage.off("touchend.addEntity") : s.stage.off("click.addEntity"), yo(), Mr.delete(s), i = !0);
  }, r = (A) => {
    n(), o(A);
  }, a = () => {
    n(), h("cancel");
  };
  let o, h;
  return {
    promise: new Promise((A, u) => {
      o = A, h = u;
      const f = (d) => {
        let c = d.evt;
        d.evt instanceof TouchEvent && (c = eo(d));
        const p = s.getRealFromStage([c.offsetX, c.offsetY]);
        r(t(p));
      };
      po(), Mr.set(s, a), an ? s.stage.on("touchend.addEntity", f) : s.stage.on("click.addEntity", f);
    }),
    interrupt: a
  };
}, Mt = {
  fill: "#ffffff",
  radius: 6,
  stroke: "#409EFF",
  strokeWidth: 3,
  zIndex: 3,
  hitStrokeWidth: 5,
  activeFill: "#ffffff",
  activeStroke: "#E6A23C"
}, Dn = () => {
  const s = new Ri({
    radius: Mt.radius,
    strokeWidth: Mt.strokeWidth,
    hitStrokeWidth: Mt.hitStrokeWidth
  }), t = () => {
    const [n] = Nt(s, [1, 1]);
    s.scale({ x: n, y: n });
  }, e = () => {
    t(), s.fill(Mt.fill).stroke(Mt.stroke);
  }, i = () => {
    t(), s.fill(Mt.activeFill).stroke(Mt.activeStroke);
  };
  return e(), {
    shape: s,
    setData(n) {
      t(), s.x(n[0]), s.y(n[1]);
    },
    common: e,
    hover: i,
    active: i,
    draging: i
  };
}, Xe = {
  strokeWidth: 5,
  hitStrokeWidth: 20,
  stroke: "rgba(230, 162, 60, 1)",
  zIndex: 1,
  activeStroke: "rgba(64, 158, 255, 1)"
}, hi = () => {
  const s = new ss({
    strokeScaleEnabled: !1,
    strokeWidth: Xe.strokeWidth,
    hitStrokeWidth: Xe.hitStrokeWidth
  }), t = () => {
    s.stroke(Xe.stroke);
  }, e = () => {
    s.stroke(Xe.activeStroke);
  };
  return t(), {
    shape: s,
    setData(i) {
      s.points(i);
    },
    common: t,
    hover: t,
    active: e,
    draging: e
  };
}, An = {
  fill: "rgba(230, 162, 60, 0.30)",
  activeFill: "rgba(64, 158, 255, 0.3)",
  zIndex: 0
}, Tn = (s = {}) => {
  let t = "rgba(0, 0, 0, 0)";
  if (jt) {
    const o = new ls();
    o.setHSL(be.randFloat(0, 1), 1, 0.8), t = "#" + o.getHexString();
  }
  const e = new Yt(), i = new ss({
    name: "polygon-line",
    closed: !0,
    fill: t
  }), n = s.autoClose ? s.lineFactory ? s.lineFactory() : hi() : null;
  e.add(i), n && e.add(n.shape);
  const r = (o) => {
    i.fill(An.fill), n && n.common(o);
  }, a = (o) => {
    i.fill(An.activeFill), n && n.active && n.active(o);
  };
  return r(), {
    closeLine: n,
    shape: e,
    setData(o) {
      if (i.points(o), n)
        if (o.length > 4) {
          const h = [o.length - 2, o.length - 1, 0, 1];
          n.setData(h.map((l) => o[l])), n.shape.visible(!0);
        } else
          n.shape.visible(!1);
    },
    common: r,
    hover: r,
    active: a,
    draging: a
  };
}, ju = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  line: Xe,
  lineShapeFactory: hi,
  point: Mt,
  pointShapeFactory: Dn,
  polygon: An,
  polygonShapeFactory: Tn
}, Symbol.toStringTag, { value: "Module" }));
var gs = { exports: {} }, In = {}, xo = {}, Pi = {};
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.Stage = s.stages = void 0;
  const t = rt, e = H, i = Pe, n = V, r = It, a = Cn, o = V, h = bt;
  var l = "Stage", A = "string", u = "px", f = "mouseout", d = "mouseleave", c = "mouseover", p = "mouseenter", m = "mousemove", v = "mousedown", x = "mouseup", g = "pointermove", y = "pointerdown", _ = "pointerup", b = "pointercancel", C = "lostpointercapture", w = "pointerout", E = "pointerleave", S = "pointerover", P = "pointerenter", k = "contextmenu", F = "touchstart", I = "touchend", T = "touchmove", R = "touchcancel", L = "wheel", B = 5, $ = [
    [p, "_pointerenter"],
    [v, "_pointerdown"],
    [m, "_pointermove"],
    [x, "_pointerup"],
    [d, "_pointerleave"],
    [F, "_pointerdown"],
    [T, "_pointermove"],
    [I, "_pointerup"],
    [R, "_pointercancel"],
    [c, "_pointerover"],
    [L, "_wheel"],
    [k, "_contextmenu"],
    [y, "_pointerdown"],
    [g, "_pointermove"],
    [_, "_pointerup"],
    [b, "_pointercancel"],
    [C, "_lostpointercapture"]
  ];
  const O = {
    mouse: {
      [w]: f,
      [E]: d,
      [S]: c,
      [P]: p,
      [g]: m,
      [y]: v,
      [_]: x,
      [b]: "mousecancel",
      pointerclick: "click",
      pointerdblclick: "dblclick"
    },
    touch: {
      [w]: "touchout",
      [E]: "touchleave",
      [S]: "touchover",
      [P]: "touchenter",
      [g]: T,
      [y]: F,
      [_]: I,
      [b]: R,
      pointerclick: "tap",
      pointerdblclick: "dbltap"
    },
    pointer: {
      [w]: w,
      [E]: E,
      [S]: S,
      [P]: P,
      [g]: g,
      [y]: y,
      [_]: _,
      [b]: b,
      pointerclick: "pointerclick",
      pointerdblclick: "pointerdblclick"
    }
  }, G = (ct) => ct.indexOf("pointer") >= 0 ? "pointer" : ct.indexOf("touch") >= 0 ? "touch" : "mouse", Q = (ct) => {
    const M = G(ct);
    if (M === "pointer")
      return n.Konva.pointerEventsEnabled && O.pointer;
    if (M === "touch")
      return O.touch;
    if (M === "mouse")
      return O.mouse;
  };
  function et(ct = {}) {
    return (ct.clipFunc || ct.clipWidth || ct.clipHeight) && t.Util.warn("Stage does not support clipping. Please use clip for Layers or Groups."), ct;
  }
  const tt = "Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);";
  s.stages = [];
  class Bt extends i.Container {
    constructor(M) {
      super(et(M)), this._pointerPositions = [], this._changedPointerPositions = [], this._buildDOM(), this._bindContentEvents(), s.stages.push(this), this.on("widthChange.konva heightChange.konva", this._resizeDOM), this.on("visibleChange.konva", this._checkVisibility), this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva", () => {
        et(this.attrs);
      }), this._checkVisibility();
    }
    _validateAdd(M) {
      const D = M.getType() === "Layer", z = M.getType() === "FastLayer";
      D || z || t.Util.throw("You may only add layers to the stage.");
    }
    _checkVisibility() {
      if (!this.content)
        return;
      const M = this.visible() ? "" : "none";
      this.content.style.display = M;
    }
    setContainer(M) {
      if (typeof M === A) {
        if (M.charAt(0) === ".") {
          var D = M.slice(1);
          M = document.getElementsByClassName(D)[0];
        } else {
          var z;
          M.charAt(0) !== "#" ? z = M : z = M.slice(1), M = document.getElementById(z);
        }
        if (!M)
          throw "Can not find container in document with id " + z;
      }
      return this._setAttr("container", M), this.content && (this.content.parentElement && this.content.parentElement.removeChild(this.content), M.appendChild(this.content)), this;
    }
    shouldDrawHit() {
      return !0;
    }
    clear() {
      var M = this.children, D = M.length, z;
      for (z = 0; z < D; z++)
        M[z].clear();
      return this;
    }
    clone(M) {
      return M || (M = {}), M.container = typeof document < "u" && document.createElement("div"), i.Container.prototype.clone.call(this, M);
    }
    destroy() {
      super.destroy();
      var M = this.content;
      M && t.Util._isInDocument(M) && this.container().removeChild(M);
      var D = s.stages.indexOf(this);
      return D > -1 && s.stages.splice(D, 1), t.Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas), this;
    }
    getPointerPosition() {
      const M = this._pointerPositions[0] || this._changedPointerPositions[0];
      return M ? {
        x: M.x,
        y: M.y
      } : (t.Util.warn(tt), null);
    }
    _getPointerById(M) {
      return this._pointerPositions.find((D) => D.id === M);
    }
    getPointersPositions() {
      return this._pointerPositions;
    }
    getStage() {
      return this;
    }
    getContent() {
      return this.content;
    }
    _toKonvaCanvas(M) {
      M = M || {}, M.x = M.x || 0, M.y = M.y || 0, M.width = M.width || this.width(), M.height = M.height || this.height();
      var D = new r.SceneCanvas({
        width: M.width,
        height: M.height,
        pixelRatio: M.pixelRatio || 1
      }), z = D.getContext()._context, nt = this.children;
      return (M.x || M.y) && z.translate(-1 * M.x, -1 * M.y), nt.forEach(function(K) {
        if (K.isVisible()) {
          var At = K._toKonvaCanvas(M);
          z.drawImage(At._canvas, M.x, M.y, At.getWidth() / At.getPixelRatio(), At.getHeight() / At.getPixelRatio());
        }
      }), D;
    }
    getIntersection(M) {
      if (!M)
        return null;
      var D = this.children, z = D.length, nt = z - 1, K;
      for (K = nt; K >= 0; K--) {
        const At = D[K].getIntersection(M);
        if (At)
          return At;
      }
      return null;
    }
    _resizeDOM() {
      var M = this.width(), D = this.height();
      this.content && (this.content.style.width = M + u, this.content.style.height = D + u), this.bufferCanvas.setSize(M, D), this.bufferHitCanvas.setSize(M, D), this.children.forEach((z) => {
        z.setSize({ width: M, height: D }), z.draw();
      });
    }
    add(M, ...D) {
      if (arguments.length > 1) {
        for (var z = 0; z < arguments.length; z++)
          this.add(arguments[z]);
        return this;
      }
      super.add(M);
      var nt = this.children.length;
      return nt > B && t.Util.warn("The stage has " + nt + " layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."), M.setSize({ width: this.width(), height: this.height() }), M.draw(), n.Konva.isBrowser && this.content.appendChild(M.canvas._canvas), this;
    }
    getParent() {
      return null;
    }
    getLayer() {
      return null;
    }
    hasPointerCapture(M) {
      return h.hasPointerCapture(M, this);
    }
    setPointerCapture(M) {
      h.setPointerCapture(M, this);
    }
    releaseCapture(M) {
      h.releaseCapture(M, this);
    }
    getLayers() {
      return this.children;
    }
    _bindContentEvents() {
      n.Konva.isBrowser && $.forEach(([M, D]) => {
        this.content.addEventListener(M, (z) => {
          this[D](z);
        }, { passive: !1 });
      });
    }
    _pointerenter(M) {
      this.setPointersPositions(M);
      const D = Q(M.type);
      D && this._fire(D.pointerenter, {
        evt: M,
        target: this,
        currentTarget: this
      });
    }
    _pointerover(M) {
      this.setPointersPositions(M);
      const D = Q(M.type);
      D && this._fire(D.pointerover, {
        evt: M,
        target: this,
        currentTarget: this
      });
    }
    _getTargetShape(M) {
      let D = this[M + "targetShape"];
      return D && !D.getStage() && (D = null), D;
    }
    _pointerleave(M) {
      const D = Q(M.type), z = G(M.type);
      if (D) {
        this.setPointersPositions(M);
        var nt = this._getTargetShape(z), K = !(n.Konva.isDragging() || n.Konva.isTransforming()) || n.Konva.hitOnDragEnabled;
        nt && K ? (nt._fireAndBubble(D.pointerout, { evt: M }), nt._fireAndBubble(D.pointerleave, { evt: M }), this._fire(D.pointerleave, {
          evt: M,
          target: this,
          currentTarget: this
        }), this[z + "targetShape"] = null) : K && (this._fire(D.pointerleave, {
          evt: M,
          target: this,
          currentTarget: this
        }), this._fire(D.pointerout, {
          evt: M,
          target: this,
          currentTarget: this
        })), this.pointerPos = null, this._pointerPositions = [];
      }
    }
    _pointerdown(M) {
      const D = Q(M.type), z = G(M.type);
      if (D) {
        this.setPointersPositions(M);
        var nt = !1;
        this._changedPointerPositions.forEach((K) => {
          var At = this.getIntersection(K);
          if (a.DD.justDragged = !1, n.Konva["_" + z + "ListenClick"] = !0, !At || !At.isListening())
            return;
          n.Konva.capturePointerEventsEnabled && At.setPointerCapture(K.id), this[z + "ClickStartShape"] = At, At._fireAndBubble(D.pointerdown, {
            evt: M,
            pointerId: K.id
          }), nt = !0;
          const St = M.type.indexOf("touch") >= 0;
          At.preventDefault() && M.cancelable && St && M.preventDefault();
        }), nt || this._fire(D.pointerdown, {
          evt: M,
          target: this,
          currentTarget: this,
          pointerId: this._pointerPositions[0].id
        });
      }
    }
    _pointermove(M) {
      const D = Q(M.type), z = G(M.type);
      if (!D)
        return;
      n.Konva.isDragging() && a.DD.node.preventDefault() && M.cancelable && M.preventDefault(), this.setPointersPositions(M);
      var nt = !(n.Konva.isDragging() || n.Konva.isTransforming()) || n.Konva.hitOnDragEnabled;
      if (!nt)
        return;
      var K = {};
      let At = !1;
      var St = this._getTargetShape(z);
      this._changedPointerPositions.forEach((ee) => {
        const it = h.getCapturedShape(ee.id) || this.getIntersection(ee), Le = ee.id, zt = { evt: M, pointerId: Le };
        var Oe = St !== it;
        if (Oe && St && (St._fireAndBubble(D.pointerout, { ...zt }, it), St._fireAndBubble(D.pointerleave, { ...zt }, it)), it) {
          if (K[it._id])
            return;
          K[it._id] = !0;
        }
        it && it.isListening() ? (At = !0, Oe && (it._fireAndBubble(D.pointerover, { ...zt }, St), it._fireAndBubble(D.pointerenter, { ...zt }, St), this[z + "targetShape"] = it), it._fireAndBubble(D.pointermove, { ...zt })) : St && (this._fire(D.pointerover, {
          evt: M,
          target: this,
          currentTarget: this,
          pointerId: Le
        }), this[z + "targetShape"] = null);
      }), At || this._fire(D.pointermove, {
        evt: M,
        target: this,
        currentTarget: this,
        pointerId: this._changedPointerPositions[0].id
      });
    }
    _pointerup(M) {
      const D = Q(M.type), z = G(M.type);
      if (!D)
        return;
      this.setPointersPositions(M);
      const nt = this[z + "ClickStartShape"], K = this[z + "ClickEndShape"];
      var At = {};
      let St = !1;
      this._changedPointerPositions.forEach((ee) => {
        const it = h.getCapturedShape(ee.id) || this.getIntersection(ee);
        if (it) {
          if (it.releaseCapture(ee.id), At[it._id])
            return;
          At[it._id] = !0;
        }
        const Le = ee.id, zt = { evt: M, pointerId: Le };
        let Oe = !1;
        n.Konva["_" + z + "InDblClickWindow"] ? (Oe = !0, clearTimeout(this[z + "DblTimeout"])) : a.DD.justDragged || (n.Konva["_" + z + "InDblClickWindow"] = !0, clearTimeout(this[z + "DblTimeout"])), this[z + "DblTimeout"] = setTimeout(function() {
          n.Konva["_" + z + "InDblClickWindow"] = !1;
        }, n.Konva.dblClickWindow), it && it.isListening() ? (St = !0, this[z + "ClickEndShape"] = it, it._fireAndBubble(D.pointerup, { ...zt }), n.Konva["_" + z + "ListenClick"] && nt && nt === it && (it._fireAndBubble(D.pointerclick, { ...zt }), Oe && K && K === it && it._fireAndBubble(D.pointerdblclick, { ...zt }))) : (this[z + "ClickEndShape"] = null, n.Konva["_" + z + "ListenClick"] && this._fire(D.pointerclick, {
          evt: M,
          target: this,
          currentTarget: this,
          pointerId: Le
        }), Oe && this._fire(D.pointerdblclick, {
          evt: M,
          target: this,
          currentTarget: this,
          pointerId: Le
        }));
      }), St || this._fire(D.pointerup, {
        evt: M,
        target: this,
        currentTarget: this,
        pointerId: this._changedPointerPositions[0].id
      }), n.Konva["_" + z + "ListenClick"] = !1, M.cancelable && z !== "touch" && M.preventDefault();
    }
    _contextmenu(M) {
      this.setPointersPositions(M);
      var D = this.getIntersection(this.getPointerPosition());
      D && D.isListening() ? D._fireAndBubble(k, { evt: M }) : this._fire(k, {
        evt: M,
        target: this,
        currentTarget: this
      });
    }
    _wheel(M) {
      this.setPointersPositions(M);
      var D = this.getIntersection(this.getPointerPosition());
      D && D.isListening() ? D._fireAndBubble(L, { evt: M }) : this._fire(L, {
        evt: M,
        target: this,
        currentTarget: this
      });
    }
    _pointercancel(M) {
      this.setPointersPositions(M);
      const D = h.getCapturedShape(M.pointerId) || this.getIntersection(this.getPointerPosition());
      D && D._fireAndBubble(_, h.createEvent(M)), h.releaseCapture(M.pointerId);
    }
    _lostpointercapture(M) {
      h.releaseCapture(M.pointerId);
    }
    setPointersPositions(M) {
      var D = this._getContentPosition(), z = null, nt = null;
      M = M || window.event, M.touches !== void 0 ? (this._pointerPositions = [], this._changedPointerPositions = [], Array.prototype.forEach.call(M.touches, (K) => {
        this._pointerPositions.push({
          id: K.identifier,
          x: (K.clientX - D.left) / D.scaleX,
          y: (K.clientY - D.top) / D.scaleY
        });
      }), Array.prototype.forEach.call(M.changedTouches || M.touches, (K) => {
        this._changedPointerPositions.push({
          id: K.identifier,
          x: (K.clientX - D.left) / D.scaleX,
          y: (K.clientY - D.top) / D.scaleY
        });
      })) : (z = (M.clientX - D.left) / D.scaleX, nt = (M.clientY - D.top) / D.scaleY, this.pointerPos = {
        x: z,
        y: nt
      }, this._pointerPositions = [{ x: z, y: nt, id: t.Util._getFirstPointerId(M) }], this._changedPointerPositions = [
        { x: z, y: nt, id: t.Util._getFirstPointerId(M) }
      ]);
    }
    _setPointerPosition(M) {
      t.Util.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'), this.setPointersPositions(M);
    }
    _getContentPosition() {
      if (!this.content || !this.content.getBoundingClientRect)
        return {
          top: 0,
          left: 0,
          scaleX: 1,
          scaleY: 1
        };
      var M = this.content.getBoundingClientRect();
      return {
        top: M.top,
        left: M.left,
        scaleX: M.width / this.content.clientWidth || 1,
        scaleY: M.height / this.content.clientHeight || 1
      };
    }
    _buildDOM() {
      if (this.bufferCanvas = new r.SceneCanvas({
        width: this.width(),
        height: this.height()
      }), this.bufferHitCanvas = new r.HitCanvas({
        pixelRatio: 1,
        width: this.width(),
        height: this.height()
      }), !!n.Konva.isBrowser) {
        var M = this.container();
        if (!M)
          throw "Stage has no container. A container is required.";
        M.innerHTML = "", this.content = document.createElement("div"), this.content.style.position = "relative", this.content.style.userSelect = "none", this.content.className = "konvajs-content", this.content.setAttribute("role", "presentation"), M.appendChild(this.content), this._resizeDOM();
      }
    }
    cache() {
      return t.Util.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes."), this;
    }
    clearCache() {
      return this;
    }
    batchDraw() {
      return this.getChildren().forEach(function(M) {
        M.batchDraw();
      }), this;
    }
  }
  s.Stage = Bt, Bt.prototype.nodeType = l, (0, o._registerNode)(Bt), e.Factory.addGetterSetter(Bt, "container");
})(Pi);
var Bi = {};
Object.defineProperty(Bi, "__esModule", { value: !0 });
var ps = Bi.Layer = void 0;
const Ht = rt, Pr = Pe, He = st, ys = H, fa = It, RA = N, LA = ft, OA = V;
var NA = "#", GA = "beforeDraw", BA = "draw", bo = [
  { x: 0, y: 0 },
  { x: -1, y: -1 },
  { x: 1, y: -1 },
  { x: 1, y: 1 },
  { x: -1, y: 1 }
], zA = bo.length;
class li extends Pr.Container {
  constructor(t) {
    super(t), this.canvas = new fa.SceneCanvas(), this.hitCanvas = new fa.HitCanvas({
      pixelRatio: 1
    }), this._waitingForDraw = !1, this.on("visibleChange.konva", this._checkVisibility), this._checkVisibility(), this.on("imageSmoothingEnabledChange.konva", this._setSmoothEnabled), this._setSmoothEnabled();
  }
  createPNGStream() {
    return this.canvas._canvas.createPNGStream();
  }
  getCanvas() {
    return this.canvas;
  }
  getNativeCanvasElement() {
    return this.canvas._canvas;
  }
  getHitCanvas() {
    return this.hitCanvas;
  }
  getContext() {
    return this.getCanvas().getContext();
  }
  clear(t) {
    return this.getContext().clear(t), this.getHitCanvas().getContext().clear(t), this;
  }
  setZIndex(t) {
    super.setZIndex(t);
    var e = this.getStage();
    return e && e.content && (e.content.removeChild(this.getNativeCanvasElement()), t < e.children.length - 1 ? e.content.insertBefore(this.getNativeCanvasElement(), e.children[t + 1].getCanvas()._canvas) : e.content.appendChild(this.getNativeCanvasElement())), this;
  }
  moveToTop() {
    He.Node.prototype.moveToTop.call(this);
    var t = this.getStage();
    return t && t.content && (t.content.removeChild(this.getNativeCanvasElement()), t.content.appendChild(this.getNativeCanvasElement())), !0;
  }
  moveUp() {
    var t = He.Node.prototype.moveUp.call(this);
    if (!t)
      return !1;
    var e = this.getStage();
    return !e || !e.content ? !1 : (e.content.removeChild(this.getNativeCanvasElement()), this.index < e.children.length - 1 ? e.content.insertBefore(this.getNativeCanvasElement(), e.children[this.index + 1].getCanvas()._canvas) : e.content.appendChild(this.getNativeCanvasElement()), !0);
  }
  moveDown() {
    if (He.Node.prototype.moveDown.call(this)) {
      var t = this.getStage();
      if (t) {
        var e = t.children;
        t.content && (t.content.removeChild(this.getNativeCanvasElement()), t.content.insertBefore(this.getNativeCanvasElement(), e[this.index + 1].getCanvas()._canvas));
      }
      return !0;
    }
    return !1;
  }
  moveToBottom() {
    if (He.Node.prototype.moveToBottom.call(this)) {
      var t = this.getStage();
      if (t) {
        var e = t.children;
        t.content && (t.content.removeChild(this.getNativeCanvasElement()), t.content.insertBefore(this.getNativeCanvasElement(), e[1].getCanvas()._canvas));
      }
      return !0;
    }
    return !1;
  }
  getLayer() {
    return this;
  }
  remove() {
    var t = this.getNativeCanvasElement();
    return He.Node.prototype.remove.call(this), t && t.parentNode && Ht.Util._isInDocument(t) && t.parentNode.removeChild(t), this;
  }
  getStage() {
    return this.parent;
  }
  setSize({ width: t, height: e }) {
    return this.canvas.setSize(t, e), this.hitCanvas.setSize(t, e), this._setSmoothEnabled(), this;
  }
  _validateAdd(t) {
    var e = t.getType();
    e !== "Group" && e !== "Shape" && Ht.Util.throw("You may only add groups and shapes to a layer.");
  }
  _toKonvaCanvas(t) {
    return t = t || {}, t.width = t.width || this.getWidth(), t.height = t.height || this.getHeight(), t.x = t.x !== void 0 ? t.x : this.x(), t.y = t.y !== void 0 ? t.y : this.y(), He.Node.prototype._toKonvaCanvas.call(this, t);
  }
  _checkVisibility() {
    this.visible() ? this.canvas._canvas.style.display = "block" : this.canvas._canvas.style.display = "none";
  }
  _setSmoothEnabled() {
    this.getContext()._context.imageSmoothingEnabled = this.imageSmoothingEnabled();
  }
  getWidth() {
    if (this.parent)
      return this.parent.width();
  }
  setWidth() {
    Ht.Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.');
  }
  getHeight() {
    if (this.parent)
      return this.parent.height();
  }
  setHeight() {
    Ht.Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.');
  }
  batchDraw() {
    return this._waitingForDraw || (this._waitingForDraw = !0, Ht.Util.requestAnimFrame(() => {
      this.draw(), this._waitingForDraw = !1;
    })), this;
  }
  getIntersection(t) {
    if (!this.isListening() || !this.isVisible())
      return null;
    for (var e = 1, i = !1; ; ) {
      for (let n = 0; n < zA; n++) {
        const r = bo[n], a = this._getIntersection({
          x: t.x + r.x * e,
          y: t.y + r.y * e
        }), o = a.shape;
        if (o)
          return o;
        if (i = !!a.antialiased, !a.antialiased)
          break;
      }
      if (i)
        e += 1;
      else
        return null;
    }
  }
  _getIntersection(t) {
    const e = this.hitCanvas.pixelRatio, i = this.hitCanvas.context.getImageData(Math.round(t.x * e), Math.round(t.y * e), 1, 1).data, n = i[3];
    if (n === 255) {
      const r = Ht.Util._rgbToHex(i[0], i[1], i[2]), a = LA.shapes[NA + r];
      return a ? {
        shape: a
      } : {
        antialiased: !0
      };
    } else if (n > 0)
      return {
        antialiased: !0
      };
    return {};
  }
  drawScene(t, e) {
    var i = this.getLayer(), n = t || i && i.getCanvas();
    return this._fire(GA, {
      node: this
    }), this.clearBeforeDraw() && n.getContext().clear(), Pr.Container.prototype.drawScene.call(this, n, e), this._fire(BA, {
      node: this
    }), this;
  }
  drawHit(t, e) {
    var i = this.getLayer(), n = t || i && i.hitCanvas;
    return i && i.clearBeforeDraw() && i.getHitCanvas().getContext().clear(), Pr.Container.prototype.drawHit.call(this, n, e), this;
  }
  enableHitGraph() {
    return this.hitGraphEnabled(!0), this;
  }
  disableHitGraph() {
    return this.hitGraphEnabled(!1), this;
  }
  setHitGraphEnabled(t) {
    Ht.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."), this.listening(t);
  }
  getHitGraphEnabled(t) {
    return Ht.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."), this.listening();
  }
  toggleHitCanvas() {
    if (!(!this.parent || !this.parent.content)) {
      var t = this.parent, e = !!this.hitCanvas._canvas.parentNode;
      e ? t.content.removeChild(this.hitCanvas._canvas) : t.content.appendChild(this.hitCanvas._canvas);
    }
  }
  destroy() {
    return Ht.Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas), super.destroy();
  }
}
ps = Bi.Layer = li;
li.prototype.nodeType = "Layer";
(0, OA._registerNode)(li);
ys.Factory.addGetterSetter(li, "imageSmoothingEnabled", !0);
ys.Factory.addGetterSetter(li, "clearBeforeDraw", !0);
ys.Factory.addGetterSetter(li, "hitGraphEnabled", !0, (0, RA.getBooleanValidator)());
var Rn = {};
Object.defineProperty(Rn, "__esModule", { value: !0 });
Rn.FastLayer = void 0;
const UA = rt, HA = Bi, VA = V;
class ms extends HA.Layer {
  constructor(t) {
    super(t), this.listening(!1), UA.Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.');
  }
}
Rn.FastLayer = ms;
ms.prototype.nodeType = "FastLayer";
(0, VA._registerNode)(ms);
var Ai = {};
Object.defineProperty(Ai, "__esModule", { value: !0 });
Ai.Animation = void 0;
const Er = V, ga = rt, Fr = function() {
  return Er.glob.performance && Er.glob.performance.now ? function() {
    return Er.glob.performance.now();
  } : function() {
    return (/* @__PURE__ */ new Date()).getTime();
  };
}();
class Ot {
  constructor(t, e) {
    this.id = Ot.animIdCounter++, this.frame = {
      time: 0,
      timeDiff: 0,
      lastTime: Fr(),
      frameRate: 0
    }, this.func = t, this.setLayers(e);
  }
  setLayers(t) {
    let e = [];
    return t && (e = Array.isArray(t) ? t : [t]), this.layers = e, this;
  }
  getLayers() {
    return this.layers;
  }
  addLayer(t) {
    const e = this.layers, i = e.length;
    for (let n = 0; n < i; n++)
      if (e[n]._id === t._id)
        return !1;
    return this.layers.push(t), !0;
  }
  isRunning() {
    const e = Ot.animations, i = e.length;
    for (let n = 0; n < i; n++)
      if (e[n].id === this.id)
        return !0;
    return !1;
  }
  start() {
    return this.stop(), this.frame.timeDiff = 0, this.frame.lastTime = Fr(), Ot._addAnimation(this), this;
  }
  stop() {
    return Ot._removeAnimation(this), this;
  }
  _updateFrameObject(t) {
    this.frame.timeDiff = t - this.frame.lastTime, this.frame.lastTime = t, this.frame.time += this.frame.timeDiff, this.frame.frameRate = 1e3 / this.frame.timeDiff;
  }
  static _addAnimation(t) {
    this.animations.push(t), this._handleAnimation();
  }
  static _removeAnimation(t) {
    const e = t.id, i = this.animations, n = i.length;
    for (let r = 0; r < n; r++)
      if (i[r].id === e) {
        this.animations.splice(r, 1);
        break;
      }
  }
  static _runFrames() {
    const t = {}, e = this.animations;
    for (let i = 0; i < e.length; i++) {
      const n = e[i], r = n.layers, a = n.func;
      n._updateFrameObject(Fr());
      const o = r.length;
      let h;
      if (a ? h = a.call(n, n.frame) !== !1 : h = !0, !!h)
        for (let l = 0; l < o; l++) {
          const A = r[l];
          A._id !== void 0 && (t[A._id] = A);
        }
    }
    for (let i in t)
      t.hasOwnProperty(i) && t[i].batchDraw();
  }
  static _animationLoop() {
    const t = Ot;
    t.animations.length ? (t._runFrames(), ga.Util.requestAnimFrame(t._animationLoop)) : t.animRunning = !1;
  }
  static _handleAnimation() {
    this.animRunning || (this.animRunning = !0, ga.Util.requestAnimFrame(this._animationLoop));
  }
}
Ai.Animation = Ot;
Ot.animations = [];
Ot.animIdCounter = 0;
Ot.animRunning = !1;
var wo = {};
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.Easings = s.Tween = void 0;
  const t = rt, e = Ai, i = st, n = V;
  var r = {
    node: 1,
    duration: 1,
    easing: 1,
    onFinish: 1,
    yoyo: 1
  }, a = 1, o = 2, h = 3, l = 0, A = ["fill", "stroke", "shadowColor"];
  class u {
    constructor(c, p, m, v, x, g, y) {
      this.prop = c, this.propFunc = p, this.begin = v, this._pos = v, this.duration = g, this._change = 0, this.prevPos = 0, this.yoyo = y, this._time = 0, this._position = 0, this._startTime = 0, this._finish = 0, this.func = m, this._change = x - this.begin, this.pause();
    }
    fire(c) {
      var p = this[c];
      p && p();
    }
    setTime(c) {
      c > this.duration ? this.yoyo ? (this._time = this.duration, this.reverse()) : this.finish() : c < 0 ? this.yoyo ? (this._time = 0, this.play()) : this.reset() : (this._time = c, this.update());
    }
    getTime() {
      return this._time;
    }
    setPosition(c) {
      this.prevPos = this._pos, this.propFunc(c), this._pos = c;
    }
    getPosition(c) {
      return c === void 0 && (c = this._time), this.func(c, this.begin, this._change, this.duration);
    }
    play() {
      this.state = o, this._startTime = this.getTimer() - this._time, this.onEnterFrame(), this.fire("onPlay");
    }
    reverse() {
      this.state = h, this._time = this.duration - this._time, this._startTime = this.getTimer() - this._time, this.onEnterFrame(), this.fire("onReverse");
    }
    seek(c) {
      this.pause(), this._time = c, this.update(), this.fire("onSeek");
    }
    reset() {
      this.pause(), this._time = 0, this.update(), this.fire("onReset");
    }
    finish() {
      this.pause(), this._time = this.duration, this.update(), this.fire("onFinish");
    }
    update() {
      this.setPosition(this.getPosition(this._time)), this.fire("onUpdate");
    }
    onEnterFrame() {
      var c = this.getTimer() - this._startTime;
      this.state === o ? this.setTime(c) : this.state === h && this.setTime(this.duration - c);
    }
    pause() {
      this.state = a, this.fire("onPause");
    }
    getTimer() {
      return (/* @__PURE__ */ new Date()).getTime();
    }
  }
  class f {
    constructor(c) {
      var p = this, m = c.node, v = m._id, x, g = c.easing || s.Easings.Linear, y = !!c.yoyo, _;
      typeof c.duration > "u" ? x = 0.3 : c.duration === 0 ? x = 1e-3 : x = c.duration, this.node = m, this._id = l++;
      var b = m.getLayer() || (m instanceof n.Konva.Stage ? m.getLayers() : null);
      b || t.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."), this.anim = new e.Animation(function() {
        p.tween.onEnterFrame();
      }, b), this.tween = new u(_, function(C) {
        p._tweenFunc(C);
      }, g, 0, 1, x * 1e3, y), this._addListeners(), f.attrs[v] || (f.attrs[v] = {}), f.attrs[v][this._id] || (f.attrs[v][this._id] = {}), f.tweens[v] || (f.tweens[v] = {});
      for (_ in c)
        r[_] === void 0 && this._addAttr(_, c[_]);
      this.reset(), this.onFinish = c.onFinish, this.onReset = c.onReset, this.onUpdate = c.onUpdate;
    }
    _addAttr(c, p) {
      var m = this.node, v = m._id, x, g, y, _, b, C, w, E;
      if (y = f.tweens[v][c], y && delete f.attrs[v][y][c], x = m.getAttr(c), t.Util._isArray(p))
        if (g = [], b = Math.max(p.length, x.length), c === "points" && p.length !== x.length && (p.length > x.length ? (w = x, x = t.Util._prepareArrayForTween(x, p, m.closed())) : (C = p, p = t.Util._prepareArrayForTween(p, x, m.closed()))), c.indexOf("fill") === 0)
          for (_ = 0; _ < b; _++)
            if (_ % 2 === 0)
              g.push(p[_] - x[_]);
            else {
              var S = t.Util.colorToRGBA(x[_]);
              E = t.Util.colorToRGBA(p[_]), x[_] = S, g.push({
                r: E.r - S.r,
                g: E.g - S.g,
                b: E.b - S.b,
                a: E.a - S.a
              });
            }
        else
          for (_ = 0; _ < b; _++)
            g.push(p[_] - x[_]);
      else
        A.indexOf(c) !== -1 ? (x = t.Util.colorToRGBA(x), E = t.Util.colorToRGBA(p), g = {
          r: E.r - x.r,
          g: E.g - x.g,
          b: E.b - x.b,
          a: E.a - x.a
        }) : g = p - x;
      f.attrs[v][this._id][c] = {
        start: x,
        diff: g,
        end: p,
        trueEnd: C,
        trueStart: w
      }, f.tweens[v][c] = this._id;
    }
    _tweenFunc(c) {
      var p = this.node, m = f.attrs[p._id][this._id], v, x, g, y, _, b, C, w;
      for (v in m) {
        if (x = m[v], g = x.start, y = x.diff, w = x.end, t.Util._isArray(g))
          if (_ = [], C = Math.max(g.length, w.length), v.indexOf("fill") === 0)
            for (b = 0; b < C; b++)
              b % 2 === 0 ? _.push((g[b] || 0) + y[b] * c) : _.push("rgba(" + Math.round(g[b].r + y[b].r * c) + "," + Math.round(g[b].g + y[b].g * c) + "," + Math.round(g[b].b + y[b].b * c) + "," + (g[b].a + y[b].a * c) + ")");
          else
            for (b = 0; b < C; b++)
              _.push((g[b] || 0) + y[b] * c);
        else
          A.indexOf(v) !== -1 ? _ = "rgba(" + Math.round(g.r + y.r * c) + "," + Math.round(g.g + y.g * c) + "," + Math.round(g.b + y.b * c) + "," + (g.a + y.a * c) + ")" : _ = g + y * c;
        p.setAttr(v, _);
      }
    }
    _addListeners() {
      this.tween.onPlay = () => {
        this.anim.start();
      }, this.tween.onReverse = () => {
        this.anim.start();
      }, this.tween.onPause = () => {
        this.anim.stop();
      }, this.tween.onFinish = () => {
        var c = this.node, p = f.attrs[c._id][this._id];
        p.points && p.points.trueEnd && c.setAttr("points", p.points.trueEnd), this.onFinish && this.onFinish.call(this);
      }, this.tween.onReset = () => {
        var c = this.node, p = f.attrs[c._id][this._id];
        p.points && p.points.trueStart && c.points(p.points.trueStart), this.onReset && this.onReset();
      }, this.tween.onUpdate = () => {
        this.onUpdate && this.onUpdate.call(this);
      };
    }
    play() {
      return this.tween.play(), this;
    }
    reverse() {
      return this.tween.reverse(), this;
    }
    reset() {
      return this.tween.reset(), this;
    }
    seek(c) {
      return this.tween.seek(c * 1e3), this;
    }
    pause() {
      return this.tween.pause(), this;
    }
    finish() {
      return this.tween.finish(), this;
    }
    destroy() {
      var c = this.node._id, p = this._id, m = f.tweens[c], v;
      this.pause();
      for (v in m)
        delete f.tweens[c][v];
      delete f.attrs[c][p];
    }
  }
  s.Tween = f, f.attrs = {}, f.tweens = {}, i.Node.prototype.to = function(d) {
    var c = d.onFinish;
    d.node = this, d.onFinish = function() {
      this.destroy(), c && c();
    };
    var p = new f(d);
    p.play();
  }, s.Easings = {
    BackEaseIn(d, c, p, m) {
      var v = 1.70158;
      return p * (d /= m) * d * ((v + 1) * d - v) + c;
    },
    BackEaseOut(d, c, p, m) {
      var v = 1.70158;
      return p * ((d = d / m - 1) * d * ((v + 1) * d + v) + 1) + c;
    },
    BackEaseInOut(d, c, p, m) {
      var v = 1.70158;
      return (d /= m / 2) < 1 ? p / 2 * (d * d * (((v *= 1.525) + 1) * d - v)) + c : p / 2 * ((d -= 2) * d * (((v *= 1.525) + 1) * d + v) + 2) + c;
    },
    ElasticEaseIn(d, c, p, m, v, x) {
      var g = 0;
      return d === 0 ? c : (d /= m) === 1 ? c + p : (x || (x = m * 0.3), !v || v < Math.abs(p) ? (v = p, g = x / 4) : g = x / (2 * Math.PI) * Math.asin(p / v), -(v * Math.pow(2, 10 * (d -= 1)) * Math.sin((d * m - g) * (2 * Math.PI) / x)) + c);
    },
    ElasticEaseOut(d, c, p, m, v, x) {
      var g = 0;
      return d === 0 ? c : (d /= m) === 1 ? c + p : (x || (x = m * 0.3), !v || v < Math.abs(p) ? (v = p, g = x / 4) : g = x / (2 * Math.PI) * Math.asin(p / v), v * Math.pow(2, -10 * d) * Math.sin((d * m - g) * (2 * Math.PI) / x) + p + c);
    },
    ElasticEaseInOut(d, c, p, m, v, x) {
      var g = 0;
      return d === 0 ? c : (d /= m / 2) === 2 ? c + p : (x || (x = m * (0.3 * 1.5)), !v || v < Math.abs(p) ? (v = p, g = x / 4) : g = x / (2 * Math.PI) * Math.asin(p / v), d < 1 ? -0.5 * (v * Math.pow(2, 10 * (d -= 1)) * Math.sin((d * m - g) * (2 * Math.PI) / x)) + c : v * Math.pow(2, -10 * (d -= 1)) * Math.sin((d * m - g) * (2 * Math.PI) / x) * 0.5 + p + c);
    },
    BounceEaseOut(d, c, p, m) {
      return (d /= m) < 1 / 2.75 ? p * (7.5625 * d * d) + c : d < 2 / 2.75 ? p * (7.5625 * (d -= 1.5 / 2.75) * d + 0.75) + c : d < 2.5 / 2.75 ? p * (7.5625 * (d -= 2.25 / 2.75) * d + 0.9375) + c : p * (7.5625 * (d -= 2.625 / 2.75) * d + 0.984375) + c;
    },
    BounceEaseIn(d, c, p, m) {
      return p - s.Easings.BounceEaseOut(m - d, 0, p, m) + c;
    },
    BounceEaseInOut(d, c, p, m) {
      return d < m / 2 ? s.Easings.BounceEaseIn(d * 2, 0, p, m) * 0.5 + c : s.Easings.BounceEaseOut(d * 2 - m, 0, p, m) * 0.5 + p * 0.5 + c;
    },
    EaseIn(d, c, p, m) {
      return p * (d /= m) * d + c;
    },
    EaseOut(d, c, p, m) {
      return -p * (d /= m) * (d - 2) + c;
    },
    EaseInOut(d, c, p, m) {
      return (d /= m / 2) < 1 ? p / 2 * d * d + c : -p / 2 * (--d * (d - 2) - 1) + c;
    },
    StrongEaseIn(d, c, p, m) {
      return p * (d /= m) * d * d * d * d + c;
    },
    StrongEaseOut(d, c, p, m) {
      return p * ((d = d / m - 1) * d * d * d * d + 1) + c;
    },
    StrongEaseInOut(d, c, p, m) {
      return (d /= m / 2) < 1 ? p / 2 * d * d * d * d * d + c : p / 2 * ((d -= 2) * d * d * d * d + 2) + c;
    },
    Linear(d, c, p, m) {
      return p * d / m + c;
    }
  };
})(wo);
(function(s) {
  Object.defineProperty(s, "__esModule", { value: !0 }), s.Konva = void 0;
  const t = V, e = rt, i = st, n = Pe, r = Pi, a = Bi, o = Rn, h = ri, l = Cn, A = ft, u = Ai, f = wo, d = Wt, c = It;
  s.Konva = e.Util._assign(t.Konva, {
    Util: e.Util,
    Transform: e.Transform,
    Node: i.Node,
    Container: n.Container,
    Stage: r.Stage,
    stages: r.stages,
    Layer: a.Layer,
    FastLayer: o.FastLayer,
    Group: h.Group,
    DD: l.DD,
    Shape: A.Shape,
    shapes: A.shapes,
    Animation: u.Animation,
    Tween: f.Tween,
    Easings: f.Easings,
    Context: d.Context,
    Canvas: c.Canvas
  }), s.default = s.Konva;
})(xo);
var Ln = {};
Object.defineProperty(Ln, "__esModule", { value: !0 });
Ln.Arc = void 0;
const On = H, $A = ft, pa = V, Nn = N, WA = V;
class Jt extends $A.Shape {
  _sceneFunc(t) {
    var e = pa.Konva.getAngle(this.angle()), i = this.clockwise();
    t.beginPath(), t.arc(0, 0, this.outerRadius(), 0, e, i), t.arc(0, 0, this.innerRadius(), e, 0, !i), t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    return this.outerRadius() * 2;
  }
  getHeight() {
    return this.outerRadius() * 2;
  }
  setWidth(t) {
    this.outerRadius(t / 2);
  }
  setHeight(t) {
    this.outerRadius(t / 2);
  }
  getSelfRect() {
    const t = this.innerRadius(), e = this.outerRadius(), i = this.clockwise(), n = pa.Konva.getAngle(i ? 360 - this.angle() : this.angle()), r = Math.cos(Math.min(n, Math.PI)), a = 1, o = Math.sin(Math.min(Math.max(Math.PI, n), 3 * Math.PI / 2)), h = Math.sin(Math.min(n, Math.PI / 2)), l = r * (r > 0 ? t : e), A = a * e, u = o * (o > 0 ? t : e), f = h * (h > 0 ? e : t);
    return {
      x: l,
      y: i ? -1 * f : u,
      width: A - l,
      height: f - u
    };
  }
}
Ln.Arc = Jt;
Jt.prototype._centroid = !0;
Jt.prototype.className = "Arc";
Jt.prototype._attrsAffectingSize = ["innerRadius", "outerRadius"];
(0, WA._registerNode)(Jt);
On.Factory.addGetterSetter(Jt, "innerRadius", 0, (0, Nn.getNumberValidator)());
On.Factory.addGetterSetter(Jt, "outerRadius", 0, (0, Nn.getNumberValidator)());
On.Factory.addGetterSetter(Jt, "angle", 0, (0, Nn.getNumberValidator)());
On.Factory.addGetterSetter(Jt, "clockwise", !1, (0, Nn.getBooleanValidator)());
var Gn = {};
Object.defineProperty(Gn, "__esModule", { value: !0 });
Gn.Arrow = void 0;
const Bn = H, YA = Li, So = N, XA = V, ya = ni;
class Fe extends YA.Line {
  _sceneFunc(t) {
    super._sceneFunc(t);
    var e = Math.PI * 2, i = this.points(), n = i, r = this.tension() !== 0 && i.length > 4;
    r && (n = this.getTensionPoints());
    var a = this.pointerLength(), o = i.length, h, l;
    if (r) {
      const f = [
        n[n.length - 4],
        n[n.length - 3],
        n[n.length - 2],
        n[n.length - 1],
        i[o - 2],
        i[o - 1]
      ], d = ya.Path.calcLength(n[n.length - 4], n[n.length - 3], "C", f), c = ya.Path.getPointOnQuadraticBezier(Math.min(1, 1 - a / d), f[0], f[1], f[2], f[3], f[4], f[5]);
      h = i[o - 2] - c.x, l = i[o - 1] - c.y;
    } else
      h = i[o - 2] - i[o - 4], l = i[o - 1] - i[o - 3];
    var A = (Math.atan2(l, h) + e) % e, u = this.pointerWidth();
    this.pointerAtEnding() && (t.save(), t.beginPath(), t.translate(i[o - 2], i[o - 1]), t.rotate(A), t.moveTo(0, 0), t.lineTo(-a, u / 2), t.lineTo(-a, -u / 2), t.closePath(), t.restore(), this.__fillStroke(t)), this.pointerAtBeginning() && (t.save(), t.beginPath(), t.translate(i[0], i[1]), r ? (h = (n[0] + n[2]) / 2 - i[0], l = (n[1] + n[3]) / 2 - i[1]) : (h = i[2] - i[0], l = i[3] - i[1]), t.rotate((Math.atan2(-l, -h) + e) % e), t.moveTo(0, 0), t.lineTo(-a, u / 2), t.lineTo(-a, -u / 2), t.closePath(), t.restore(), this.__fillStroke(t));
  }
  __fillStroke(t) {
    var e = this.dashEnabled();
    e && (this.attrs.dashEnabled = !1, t.setLineDash([])), t.fillStrokeShape(this), e && (this.attrs.dashEnabled = !0);
  }
  getSelfRect() {
    const t = super.getSelfRect(), e = this.pointerWidth() / 2;
    return {
      x: t.x - e,
      y: t.y - e,
      width: t.width + e * 2,
      height: t.height + e * 2
    };
  }
}
Gn.Arrow = Fe;
Fe.prototype.className = "Arrow";
(0, XA._registerNode)(Fe);
Bn.Factory.addGetterSetter(Fe, "pointerLength", 10, (0, So.getNumberValidator)());
Bn.Factory.addGetterSetter(Fe, "pointerWidth", 10, (0, So.getNumberValidator)());
Bn.Factory.addGetterSetter(Fe, "pointerAtBeginning", !1);
Bn.Factory.addGetterSetter(Fe, "pointerAtEnding", !0);
var zn = {};
Object.defineProperty(zn, "__esModule", { value: !0 });
zn.Ellipse = void 0;
const vs = H, jA = ft, Co = N, qA = V;
class fe extends jA.Shape {
  _sceneFunc(t) {
    var e = this.radiusX(), i = this.radiusY();
    t.beginPath(), t.save(), e !== i && t.scale(1, i / e), t.arc(0, 0, e, 0, Math.PI * 2, !1), t.restore(), t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    return this.radiusX() * 2;
  }
  getHeight() {
    return this.radiusY() * 2;
  }
  setWidth(t) {
    this.radiusX(t / 2);
  }
  setHeight(t) {
    this.radiusY(t / 2);
  }
}
zn.Ellipse = fe;
fe.prototype.className = "Ellipse";
fe.prototype._centroid = !0;
fe.prototype._attrsAffectingSize = ["radiusX", "radiusY"];
(0, qA._registerNode)(fe);
vs.Factory.addComponentsGetterSetter(fe, "radius", ["x", "y"]);
vs.Factory.addGetterSetter(fe, "radiusX", 0, (0, Co.getNumberValidator)());
vs.Factory.addGetterSetter(fe, "radiusY", 0, (0, Co.getNumberValidator)());
var Un = {};
Object.defineProperty(Un, "__esModule", { value: !0 });
Un.Image = void 0;
const kr = rt, ke = H, QA = ft, KA = V, zi = N;
class Ft extends QA.Shape {
  constructor(t) {
    super(t), this.on("imageChange.konva", () => {
      this._setImageLoad();
    }), this._setImageLoad();
  }
  _setImageLoad() {
    const t = this.image();
    t && t.complete || t && t.readyState === 4 || t && t.addEventListener && t.addEventListener("load", () => {
      this._requestDraw();
    });
  }
  _useBufferCanvas() {
    return super._useBufferCanvas(!0);
  }
  _sceneFunc(t) {
    const e = this.getWidth(), i = this.getHeight(), n = this.cornerRadius(), r = this.attrs.image;
    let a;
    if (r) {
      const o = this.attrs.cropWidth, h = this.attrs.cropHeight;
      o && h ? a = [
        r,
        this.cropX(),
        this.cropY(),
        o,
        h,
        0,
        0,
        e,
        i
      ] : a = [r, 0, 0, e, i];
    }
    (this.hasFill() || this.hasStroke() || n) && (t.beginPath(), n ? kr.Util.drawRoundedRectPath(t, e, i, n) : t.rect(0, 0, e, i), t.closePath(), t.fillStrokeShape(this)), r && (n && t.clip(), t.drawImage.apply(t, a));
  }
  _hitFunc(t) {
    var e = this.width(), i = this.height(), n = this.cornerRadius();
    t.beginPath(), n ? kr.Util.drawRoundedRectPath(t, e, i, n) : t.rect(0, 0, e, i), t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    var t, e;
    return (t = this.attrs.width) !== null && t !== void 0 ? t : (e = this.image()) === null || e === void 0 ? void 0 : e.width;
  }
  getHeight() {
    var t, e;
    return (t = this.attrs.height) !== null && t !== void 0 ? t : (e = this.image()) === null || e === void 0 ? void 0 : e.height;
  }
  static fromURL(t, e, i = null) {
    var n = kr.Util.createImageElement();
    n.onload = function() {
      var r = new Ft({
        image: n
      });
      e(r);
    }, n.onerror = i, n.crossOrigin = "Anonymous", n.src = t;
  }
}
Un.Image = Ft;
Ft.prototype.className = "Image";
(0, KA._registerNode)(Ft);
ke.Factory.addGetterSetter(Ft, "cornerRadius", 0, (0, zi.getNumberOrArrayOfNumbersValidator)(4));
ke.Factory.addGetterSetter(Ft, "image");
ke.Factory.addComponentsGetterSetter(Ft, "crop", ["x", "y", "width", "height"]);
ke.Factory.addGetterSetter(Ft, "cropX", 0, (0, zi.getNumberValidator)());
ke.Factory.addGetterSetter(Ft, "cropY", 0, (0, zi.getNumberValidator)());
ke.Factory.addGetterSetter(Ft, "cropWidth", 0, (0, zi.getNumberValidator)());
ke.Factory.addGetterSetter(Ft, "cropHeight", 0, (0, zi.getNumberValidator)());
var Ze = {};
Object.defineProperty(Ze, "__esModule", { value: !0 });
var Mo = Ze.Tag = Fo = Ze.Label = void 0;
const Hn = H, ZA = ft, JA = ri, _s = N, Po = V;
var Eo = [
  "fontFamily",
  "fontSize",
  "fontStyle",
  "padding",
  "lineHeight",
  "text",
  "width",
  "height",
  "pointerDirection",
  "pointerWidth",
  "pointerHeight"
], t0 = "Change.konva", e0 = "none", Yr = "up", Xr = "right", jr = "down", qr = "left", i0 = Eo.length;
class xs extends JA.Group {
  constructor(t) {
    super(t), this.on("add.konva", function(e) {
      this._addListeners(e.child), this._sync();
    });
  }
  getText() {
    return this.find("Text")[0];
  }
  getTag() {
    return this.find("Tag")[0];
  }
  _addListeners(t) {
    var e = this, i, n = function() {
      e._sync();
    };
    for (i = 0; i < i0; i++)
      t.on(Eo[i] + t0, n);
  }
  getWidth() {
    return this.getText().width();
  }
  getHeight() {
    return this.getText().height();
  }
  _sync() {
    var t = this.getText(), e = this.getTag(), i, n, r, a, o, h, l;
    if (t && e) {
      switch (i = t.width(), n = t.height(), r = e.pointerDirection(), a = e.pointerWidth(), l = e.pointerHeight(), o = 0, h = 0, r) {
        case Yr:
          o = i / 2, h = -1 * l;
          break;
        case Xr:
          o = i + a, h = n / 2;
          break;
        case jr:
          o = i / 2, h = n + l;
          break;
        case qr:
          o = -1 * a, h = n / 2;
          break;
      }
      e.setAttrs({
        x: -1 * o,
        y: -1 * h,
        width: i,
        height: n
      }), t.setAttrs({
        x: -1 * o,
        y: -1 * h
      });
    }
  }
}
var Fo = Ze.Label = xs;
xs.prototype.className = "Label";
(0, Po._registerNode)(xs);
class De extends ZA.Shape {
  _sceneFunc(t) {
    var e = this.width(), i = this.height(), n = this.pointerDirection(), r = this.pointerWidth(), a = this.pointerHeight(), o = this.cornerRadius();
    let h = 0, l = 0, A = 0, u = 0;
    typeof o == "number" ? h = l = A = u = Math.min(o, e / 2, i / 2) : (h = Math.min(o[0] || 0, e / 2, i / 2), l = Math.min(o[1] || 0, e / 2, i / 2), u = Math.min(o[2] || 0, e / 2, i / 2), A = Math.min(o[3] || 0, e / 2, i / 2)), t.beginPath(), t.moveTo(h, 0), n === Yr && (t.lineTo((e - r) / 2, 0), t.lineTo(e / 2, -1 * a), t.lineTo((e + r) / 2, 0)), t.lineTo(e - l, 0), t.arc(e - l, l, l, Math.PI * 3 / 2, 0, !1), n === Xr && (t.lineTo(e, (i - a) / 2), t.lineTo(e + r, i / 2), t.lineTo(e, (i + a) / 2)), t.lineTo(e, i - u), t.arc(e - u, i - u, u, 0, Math.PI / 2, !1), n === jr && (t.lineTo((e + r) / 2, i), t.lineTo(e / 2, i + a), t.lineTo((e - r) / 2, i)), t.lineTo(A, i), t.arc(A, i - A, A, Math.PI / 2, Math.PI, !1), n === qr && (t.lineTo(0, (i + a) / 2), t.lineTo(-1 * r, i / 2), t.lineTo(0, (i - a) / 2)), t.lineTo(0, h), t.arc(h, h, h, Math.PI, Math.PI * 3 / 2, !1), t.closePath(), t.fillStrokeShape(this);
  }
  getSelfRect() {
    var t = 0, e = 0, i = this.pointerWidth(), n = this.pointerHeight(), r = this.pointerDirection(), a = this.width(), o = this.height();
    return r === Yr ? (e -= n, o += n) : r === jr ? o += n : r === qr ? (t -= i * 1.5, a += i) : r === Xr && (a += i * 1.5), {
      x: t,
      y: e,
      width: a,
      height: o
    };
  }
}
Mo = Ze.Tag = De;
De.prototype.className = "Tag";
(0, Po._registerNode)(De);
Hn.Factory.addGetterSetter(De, "pointerDirection", e0);
Hn.Factory.addGetterSetter(De, "pointerWidth", 0, (0, _s.getNumberValidator)());
Hn.Factory.addGetterSetter(De, "pointerHeight", 0, (0, _s.getNumberValidator)());
Hn.Factory.addGetterSetter(De, "cornerRadius", 0, (0, _s.getNumberOrArrayOfNumbersValidator)(4));
var Vn = {};
Object.defineProperty(Vn, "__esModule", { value: !0 });
Vn.RegularPolygon = void 0;
const ko = H, n0 = ft, Do = N, r0 = V;
class Te extends n0.Shape {
  _sceneFunc(t) {
    const e = this._getPoints();
    t.beginPath(), t.moveTo(e[0].x, e[0].y);
    for (var i = 1; i < e.length; i++)
      t.lineTo(e[i].x, e[i].y);
    t.closePath(), t.fillStrokeShape(this);
  }
  _getPoints() {
    const t = this.attrs.sides, e = this.attrs.radius || 0, i = [];
    for (var n = 0; n < t; n++)
      i.push({
        x: e * Math.sin(n * 2 * Math.PI / t),
        y: -1 * e * Math.cos(n * 2 * Math.PI / t)
      });
    return i;
  }
  getSelfRect() {
    const t = this._getPoints();
    var e = t[0].x, i = t[0].y, n = t[0].x, r = t[0].y;
    return t.forEach((a) => {
      e = Math.min(e, a.x), i = Math.max(i, a.x), n = Math.min(n, a.y), r = Math.max(r, a.y);
    }), {
      x: e,
      y: n,
      width: i - e,
      height: r - n
    };
  }
  getWidth() {
    return this.radius() * 2;
  }
  getHeight() {
    return this.radius() * 2;
  }
  setWidth(t) {
    this.radius(t / 2);
  }
  setHeight(t) {
    this.radius(t / 2);
  }
}
Vn.RegularPolygon = Te;
Te.prototype.className = "RegularPolygon";
Te.prototype._centroid = !0;
Te.prototype._attrsAffectingSize = ["radius"];
(0, r0._registerNode)(Te);
ko.Factory.addGetterSetter(Te, "radius", 0, (0, Do.getNumberValidator)());
ko.Factory.addGetterSetter(Te, "sides", 0, (0, Do.getNumberValidator)());
var $n = {};
Object.defineProperty($n, "__esModule", { value: !0 });
$n.Ring = void 0;
const To = H, s0 = ft, Io = N, a0 = V;
var ma = Math.PI * 2;
class Ie extends s0.Shape {
  _sceneFunc(t) {
    t.beginPath(), t.arc(0, 0, this.innerRadius(), 0, ma, !1), t.moveTo(this.outerRadius(), 0), t.arc(0, 0, this.outerRadius(), ma, 0, !0), t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    return this.outerRadius() * 2;
  }
  getHeight() {
    return this.outerRadius() * 2;
  }
  setWidth(t) {
    this.outerRadius(t / 2);
  }
  setHeight(t) {
    this.outerRadius(t / 2);
  }
}
$n.Ring = Ie;
Ie.prototype.className = "Ring";
Ie.prototype._centroid = !0;
Ie.prototype._attrsAffectingSize = ["innerRadius", "outerRadius"];
(0, a0._registerNode)(Ie);
To.Factory.addGetterSetter(Ie, "innerRadius", 0, (0, Io.getNumberValidator)());
To.Factory.addGetterSetter(Ie, "outerRadius", 0, (0, Io.getNumberValidator)());
var Wn = {};
Object.defineProperty(Wn, "__esModule", { value: !0 });
Wn.Sprite = void 0;
const Re = H, o0 = ft, h0 = Ai, Ro = N, l0 = V;
class Gt extends o0.Shape {
  constructor(t) {
    super(t), this._updated = !0, this.anim = new h0.Animation(() => {
      var e = this._updated;
      return this._updated = !1, e;
    }), this.on("animationChange.konva", function() {
      this.frameIndex(0);
    }), this.on("frameIndexChange.konva", function() {
      this._updated = !0;
    }), this.on("frameRateChange.konva", function() {
      this.anim.isRunning() && (clearInterval(this.interval), this._setInterval());
    });
  }
  _sceneFunc(t) {
    var e = this.animation(), i = this.frameIndex(), n = i * 4, r = this.animations()[e], a = this.frameOffsets(), o = r[n + 0], h = r[n + 1], l = r[n + 2], A = r[n + 3], u = this.image();
    if ((this.hasFill() || this.hasStroke()) && (t.beginPath(), t.rect(0, 0, l, A), t.closePath(), t.fillStrokeShape(this)), u)
      if (a) {
        var f = a[e], d = i * 2;
        t.drawImage(u, o, h, l, A, f[d + 0], f[d + 1], l, A);
      } else
        t.drawImage(u, o, h, l, A, 0, 0, l, A);
  }
  _hitFunc(t) {
    var e = this.animation(), i = this.frameIndex(), n = i * 4, r = this.animations()[e], a = this.frameOffsets(), o = r[n + 2], h = r[n + 3];
    if (t.beginPath(), a) {
      var l = a[e], A = i * 2;
      t.rect(l[A + 0], l[A + 1], o, h);
    } else
      t.rect(0, 0, o, h);
    t.closePath(), t.fillShape(this);
  }
  _useBufferCanvas() {
    return super._useBufferCanvas(!0);
  }
  _setInterval() {
    var t = this;
    this.interval = setInterval(function() {
      t._updateIndex();
    }, 1e3 / this.frameRate());
  }
  start() {
    if (!this.isRunning()) {
      var t = this.getLayer();
      this.anim.setLayers(t), this._setInterval(), this.anim.start();
    }
  }
  stop() {
    this.anim.stop(), clearInterval(this.interval);
  }
  isRunning() {
    return this.anim.isRunning();
  }
  _updateIndex() {
    var t = this.frameIndex(), e = this.animation(), i = this.animations(), n = i[e], r = n.length / 4;
    t < r - 1 ? this.frameIndex(t + 1) : this.frameIndex(0);
  }
}
Wn.Sprite = Gt;
Gt.prototype.className = "Sprite";
(0, l0._registerNode)(Gt);
Re.Factory.addGetterSetter(Gt, "animation");
Re.Factory.addGetterSetter(Gt, "animations");
Re.Factory.addGetterSetter(Gt, "frameOffsets");
Re.Factory.addGetterSetter(Gt, "image");
Re.Factory.addGetterSetter(Gt, "frameIndex", 0, (0, Ro.getNumberValidator)());
Re.Factory.addGetterSetter(Gt, "frameRate", 17, (0, Ro.getNumberValidator)());
Re.Factory.backCompat(Gt, {
  index: "frameIndex",
  getIndex: "getFrameIndex",
  setIndex: "setFrameIndex"
});
var Yn = {};
Object.defineProperty(Yn, "__esModule", { value: !0 });
Yn.Star = void 0;
const bs = H, A0 = ft, ws = N, d0 = V;
class ge extends A0.Shape {
  _sceneFunc(t) {
    var e = this.innerRadius(), i = this.outerRadius(), n = this.numPoints();
    t.beginPath(), t.moveTo(0, 0 - i);
    for (var r = 1; r < n * 2; r++) {
      var a = r % 2 === 0 ? i : e, o = a * Math.sin(r * Math.PI / n), h = -1 * a * Math.cos(r * Math.PI / n);
      t.lineTo(o, h);
    }
    t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    return this.outerRadius() * 2;
  }
  getHeight() {
    return this.outerRadius() * 2;
  }
  setWidth(t) {
    this.outerRadius(t / 2);
  }
  setHeight(t) {
    this.outerRadius(t / 2);
  }
}
Yn.Star = ge;
ge.prototype.className = "Star";
ge.prototype._centroid = !0;
ge.prototype._attrsAffectingSize = ["innerRadius", "outerRadius"];
(0, d0._registerNode)(ge);
bs.Factory.addGetterSetter(ge, "numPoints", 5, (0, ws.getNumberValidator)());
bs.Factory.addGetterSetter(ge, "innerRadius", 0, (0, ws.getNumberValidator)());
bs.Factory.addGetterSetter(ge, "outerRadius", 0, (0, ws.getNumberValidator)());
var Se = {};
Object.defineProperty(Se, "__esModule", { value: !0 });
var Qr = Se.Text = Se.stringToArray = void 0;
const Kr = rt, vt = H, c0 = ft, pe = N, u0 = V;
function Lo(s) {
  return Array.from(s);
}
Se.stringToArray = Lo;
var Ve = "auto", f0 = "center", Oo = "inherit", gi = "justify", g0 = "Change.konva", p0 = "2d", va = "-", No = "left", y0 = "text", m0 = "Text", v0 = "top", _0 = "bottom", _a = "middle", Go = "normal", x0 = "px ", Zi = " ", b0 = "right", xa = "rtl", w0 = "word", S0 = "char", ba = "none", Dr = "…", Bo = [
  "direction",
  "fontFamily",
  "fontSize",
  "fontStyle",
  "fontVariant",
  "padding",
  "align",
  "verticalAlign",
  "lineHeight",
  "text",
  "width",
  "height",
  "wrap",
  "ellipsis",
  "letterSpacing"
], C0 = Bo.length;
function M0(s) {
  return s.split(",").map((t) => {
    t = t.trim();
    const e = t.indexOf(" ") >= 0, i = t.indexOf('"') >= 0 || t.indexOf("'") >= 0;
    return e && !i && (t = `"${t}"`), t;
  }).join(", ");
}
var Ji;
function Tr() {
  return Ji || (Ji = Kr.Util.createCanvasElement().getContext(p0), Ji);
}
function P0(s) {
  s.fillText(this._partialText, this._partialTextX, this._partialTextY);
}
function E0(s) {
  s.setAttr("miterLimit", 2), s.strokeText(this._partialText, this._partialTextX, this._partialTextY);
}
function F0(s) {
  return s = s || {}, !s.fillLinearGradientColorStops && !s.fillRadialGradientColorStops && !s.fillPatternImage && (s.fill = s.fill || "black"), s;
}
class lt extends c0.Shape {
  constructor(t) {
    super(F0(t)), this._partialTextX = 0, this._partialTextY = 0;
    for (var e = 0; e < C0; e++)
      this.on(Bo[e] + g0, this._setTextData);
    this._setTextData();
  }
  _sceneFunc(t) {
    var e = this.textArr, i = e.length;
    if (this.text()) {
      var n = this.padding(), r = this.fontSize(), a = this.lineHeight() * r, o = this.verticalAlign(), h = this.direction(), l = 0, A = this.align(), u = this.getWidth(), f = this.letterSpacing(), d = this.fill(), c = this.textDecoration(), p = c.indexOf("underline") !== -1, m = c.indexOf("line-through") !== -1, v;
      h = h === Oo ? t.direction : h;
      var x = 0, x = a / 2, g = 0, y = 0;
      for (h === xa && t.setAttr("direction", h), t.setAttr("font", this._getContextFont()), t.setAttr("textBaseline", _a), t.setAttr("textAlign", No), o === _a ? l = (this.getHeight() - i * a - n * 2) / 2 : o === _0 && (l = this.getHeight() - i * a - n * 2), t.translate(n, l + n), v = 0; v < i; v++) {
        var g = 0, y = 0, _ = e[v], b = _.text, C = _.width, w = _.lastInParagraph, E, S, P;
        if (t.save(), A === b0 ? g += u - C - n * 2 : A === f0 && (g += (u - C - n * 2) / 2), p) {
          t.save(), t.beginPath(), t.moveTo(g, x + y + Math.round(r / 2)), E = b.split(" ").length - 1, S = E === 0, P = A === gi && !w ? u - n * 2 : C, t.lineTo(g + Math.round(P), x + y + Math.round(r / 2)), t.lineWidth = r / 15;
          const L = this._getLinearGradient();
          t.strokeStyle = L || d, t.stroke(), t.restore();
        }
        if (m) {
          t.save(), t.beginPath(), t.moveTo(g, x + y), E = b.split(" ").length - 1, S = E === 0, P = A === gi && w && !S ? u - n * 2 : C, t.lineTo(g + Math.round(P), x + y), t.lineWidth = r / 15;
          const L = this._getLinearGradient();
          t.strokeStyle = L || d, t.stroke(), t.restore();
        }
        if (h !== xa && (f !== 0 || A === gi)) {
          E = b.split(" ").length - 1;
          for (var k = Lo(b), F = 0; F < k.length; F++) {
            var I = k[F];
            I === " " && !w && A === gi && (g += (u - n * 2 - C) / E), this._partialTextX = g, this._partialTextY = x + y, this._partialText = I, t.fillStrokeShape(this), g += this.measureSize(I).width + f;
          }
        } else
          f !== 0 && t.setAttr("letterSpacing", `${f}px`), this._partialTextX = g, this._partialTextY = x + y, this._partialText = b, t.fillStrokeShape(this);
        t.restore(), i > 1 && (x += a);
      }
    }
  }
  _hitFunc(t) {
    var e = this.getWidth(), i = this.getHeight();
    t.beginPath(), t.rect(0, 0, e, i), t.closePath(), t.fillStrokeShape(this);
  }
  setText(t) {
    var e = Kr.Util._isString(t) ? t : t == null ? "" : t + "";
    return this._setAttr(y0, e), this;
  }
  getWidth() {
    var t = this.attrs.width === Ve || this.attrs.width === void 0;
    return t ? this.getTextWidth() + this.padding() * 2 : this.attrs.width;
  }
  getHeight() {
    var t = this.attrs.height === Ve || this.attrs.height === void 0;
    return t ? this.fontSize() * this.textArr.length * this.lineHeight() + this.padding() * 2 : this.attrs.height;
  }
  getTextWidth() {
    return this.textWidth;
  }
  getTextHeight() {
    return Kr.Util.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."), this.textHeight;
  }
  measureSize(t) {
    var e = Tr(), i = this.fontSize(), n;
    return e.save(), e.font = this._getContextFont(), n = e.measureText(t), e.restore(), {
      width: n.width,
      height: i
    };
  }
  _getContextFont() {
    return this.fontStyle() + Zi + this.fontVariant() + Zi + (this.fontSize() + x0) + M0(this.fontFamily());
  }
  _addTextLine(t) {
    this.align() === gi && (t = t.trim());
    var i = this._getTextWidth(t);
    return this.textArr.push({
      text: t,
      width: i,
      lastInParagraph: !1
    });
  }
  _getTextWidth(t) {
    var e = this.letterSpacing(), i = t.length;
    return Tr().measureText(t).width + (i ? e * (i - 1) : 0);
  }
  _setTextData() {
    var t = this.text().split(`
`), e = +this.fontSize(), i = 0, n = this.lineHeight() * e, r = this.attrs.width, a = this.attrs.height, o = r !== Ve && r !== void 0, h = a !== Ve && a !== void 0, l = this.padding(), A = r - l * 2, u = a - l * 2, f = 0, d = this.wrap(), c = d !== ba, p = d !== S0 && c, m = this.ellipsis();
    this.textArr = [], Tr().font = this._getContextFont();
    for (var v = m ? this._getTextWidth(Dr) : 0, x = 0, g = t.length; x < g; ++x) {
      var y = t[x], _ = this._getTextWidth(y);
      if (o && _ > A)
        for (; y.length > 0; ) {
          for (var b = 0, C = y.length, w = "", E = 0; b < C; ) {
            var S = b + C >>> 1, P = y.slice(0, S + 1), k = this._getTextWidth(P) + v;
            k <= A ? (b = S + 1, w = P, E = k) : C = S;
          }
          if (w) {
            if (p) {
              var F, I = y[w.length], T = I === Zi || I === va;
              T && E <= A ? F = w.length : F = Math.max(w.lastIndexOf(Zi), w.lastIndexOf(va)) + 1, F > 0 && (b = F, w = w.slice(0, b), E = this._getTextWidth(w));
            }
            w = w.trimRight(), this._addTextLine(w), i = Math.max(i, E), f += n;
            var R = this._shouldHandleEllipsis(f);
            if (R) {
              this._tryToAddEllipsisToLastLine();
              break;
            }
            if (y = y.slice(b), y = y.trimLeft(), y.length > 0 && (_ = this._getTextWidth(y), _ <= A)) {
              this._addTextLine(y), f += n, i = Math.max(i, _);
              break;
            }
          } else
            break;
        }
      else
        this._addTextLine(y), f += n, i = Math.max(i, _), this._shouldHandleEllipsis(f) && x < g - 1 && this._tryToAddEllipsisToLastLine();
      if (this.textArr[this.textArr.length - 1] && (this.textArr[this.textArr.length - 1].lastInParagraph = !0), h && f + n > u)
        break;
    }
    this.textHeight = e, this.textWidth = i;
  }
  _shouldHandleEllipsis(t) {
    var e = +this.fontSize(), i = this.lineHeight() * e, n = this.attrs.height, r = n !== Ve && n !== void 0, a = this.padding(), o = n - a * 2, h = this.wrap(), l = h !== ba;
    return !l || r && t + i > o;
  }
  _tryToAddEllipsisToLastLine() {
    var t = this.attrs.width, e = t !== Ve && t !== void 0, i = this.padding(), n = t - i * 2, r = this.ellipsis(), a = this.textArr[this.textArr.length - 1];
    if (!(!a || !r)) {
      if (e) {
        var o = this._getTextWidth(a.text + Dr) < n;
        o || (a.text = a.text.slice(0, a.text.length - 3));
      }
      this.textArr.splice(this.textArr.length - 1, 1), this._addTextLine(a.text + Dr);
    }
  }
  getStrokeScaleEnabled() {
    return !0;
  }
  _useBufferCanvas() {
    const t = this.textDecoration().indexOf("underline") !== -1 || this.textDecoration().indexOf("line-through") !== -1, e = this.hasShadow();
    return t && e ? !0 : super._useBufferCanvas();
  }
}
Qr = Se.Text = lt;
lt.prototype._fillFunc = P0;
lt.prototype._strokeFunc = E0;
lt.prototype.className = m0;
lt.prototype._attrsAffectingSize = [
  "text",
  "fontSize",
  "padding",
  "wrap",
  "lineHeight",
  "letterSpacing"
];
(0, u0._registerNode)(lt);
vt.Factory.overWriteSetter(lt, "width", (0, pe.getNumberOrAutoValidator)());
vt.Factory.overWriteSetter(lt, "height", (0, pe.getNumberOrAutoValidator)());
vt.Factory.addGetterSetter(lt, "direction", Oo);
vt.Factory.addGetterSetter(lt, "fontFamily", "Arial");
vt.Factory.addGetterSetter(lt, "fontSize", 12, (0, pe.getNumberValidator)());
vt.Factory.addGetterSetter(lt, "fontStyle", Go);
vt.Factory.addGetterSetter(lt, "fontVariant", Go);
vt.Factory.addGetterSetter(lt, "padding", 0, (0, pe.getNumberValidator)());
vt.Factory.addGetterSetter(lt, "align", No);
vt.Factory.addGetterSetter(lt, "verticalAlign", v0);
vt.Factory.addGetterSetter(lt, "lineHeight", 1, (0, pe.getNumberValidator)());
vt.Factory.addGetterSetter(lt, "wrap", w0);
vt.Factory.addGetterSetter(lt, "ellipsis", !1, (0, pe.getBooleanValidator)());
vt.Factory.addGetterSetter(lt, "letterSpacing", 0, (0, pe.getNumberValidator)());
vt.Factory.addGetterSetter(lt, "text", "", (0, pe.getStringValidator)());
vt.Factory.addGetterSetter(lt, "textDecoration", "");
var Xn = {};
Object.defineProperty(Xn, "__esModule", { value: !0 });
Xn.TextPath = void 0;
const Ir = rt, Lt = H, k0 = ft, pi = ni, Rr = Se, zo = N, D0 = V;
var T0 = "", Uo = "normal";
function Ho(s) {
  s.fillText(this.partialText, 0, 0);
}
function Vo(s) {
  s.strokeText(this.partialText, 0, 0);
}
class gt extends k0.Shape {
  constructor(t) {
    super(t), this.dummyCanvas = Ir.Util.createCanvasElement(), this.dataArray = [], this._readDataAttribute(), this.on("dataChange.konva", function() {
      this._readDataAttribute(), this._setTextData();
    }), this.on("textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva", this._setTextData), this._setTextData();
  }
  _getTextPathLength() {
    return pi.Path.getPathLength(this.dataArray);
  }
  _getPointAtLength(t) {
    if (!this.attrs.data)
      return null;
    const e = this.pathLength;
    return t - 1 > e ? null : pi.Path.getPointAtLengthOfDataArray(t, this.dataArray);
  }
  _readDataAttribute() {
    this.dataArray = pi.Path.parsePathData(this.attrs.data), this.pathLength = this._getTextPathLength();
  }
  _sceneFunc(t) {
    t.setAttr("font", this._getContextFont()), t.setAttr("textBaseline", this.textBaseline()), t.setAttr("textAlign", "left"), t.save();
    var e = this.textDecoration(), i = this.fill(), n = this.fontSize(), r = this.glyphInfo;
    e === "underline" && t.beginPath();
    for (var a = 0; a < r.length; a++) {
      t.save();
      var o = r[a].p0;
      t.translate(o.x, o.y), t.rotate(r[a].rotation), this.partialText = r[a].text, t.fillStrokeShape(this), e === "underline" && (a === 0 && t.moveTo(0, n / 2 + 1), t.lineTo(n, n / 2 + 1)), t.restore();
    }
    e === "underline" && (t.strokeStyle = i, t.lineWidth = n / 20, t.stroke()), t.restore();
  }
  _hitFunc(t) {
    t.beginPath();
    var e = this.glyphInfo;
    if (e.length >= 1) {
      var i = e[0].p0;
      t.moveTo(i.x, i.y);
    }
    for (var n = 0; n < e.length; n++) {
      var r = e[n].p1;
      t.lineTo(r.x, r.y);
    }
    t.setAttr("lineWidth", this.fontSize()), t.setAttr("strokeStyle", this.colorKey), t.stroke();
  }
  getTextWidth() {
    return this.textWidth;
  }
  getTextHeight() {
    return Ir.Util.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."), this.textHeight;
  }
  setText(t) {
    return Rr.Text.prototype.setText.call(this, t);
  }
  _getContextFont() {
    return Rr.Text.prototype._getContextFont.call(this);
  }
  _getTextSize(t) {
    var e = this.dummyCanvas, i = e.getContext("2d");
    i.save(), i.font = this._getContextFont();
    var n = i.measureText(t);
    return i.restore(), {
      width: n.width,
      height: parseInt(`${this.fontSize()}`, 10)
    };
  }
  _setTextData() {
    const { width: t, height: e } = this._getTextSize(this.attrs.text);
    if (this.textWidth = t, this.textHeight = e, this.glyphInfo = [], !this.attrs.data)
      return null;
    const i = this.letterSpacing(), n = this.align(), r = this.kerningFunc(), a = Math.max(this.textWidth + ((this.attrs.text || "").length - 1) * i, 0);
    let o = 0;
    n === "center" && (o = Math.max(0, this.pathLength / 2 - a / 2)), n === "right" && (o = Math.max(0, this.pathLength - a));
    const h = (0, Rr.stringToArray)(this.text());
    let l = o;
    for (var A = 0; A < h.length; A++) {
      const u = this._getPointAtLength(l);
      if (!u)
        return;
      let f = this._getTextSize(h[A]).width + i;
      if (h[A] === " " && n === "justify") {
        const x = this.text().split(" ").length - 1;
        f += (this.pathLength - a) / x;
      }
      const d = this._getPointAtLength(l + f);
      if (!d)
        return;
      const c = pi.Path.getLineLength(u.x, u.y, d.x, d.y);
      let p = 0;
      if (r)
        try {
          p = r(h[A - 1], h[A]) * this.fontSize();
        } catch {
          p = 0;
        }
      u.x += p, d.x += p, this.textWidth += p;
      const m = pi.Path.getPointOnLine(p + c / 2, u.x, u.y, d.x, d.y), v = Math.atan2(d.y - u.y, d.x - u.x);
      this.glyphInfo.push({
        transposeX: m.x,
        transposeY: m.y,
        text: h[A],
        rotation: v,
        p0: u,
        p1: d
      }), l += f;
    }
  }
  getSelfRect() {
    if (!this.glyphInfo.length)
      return {
        x: 0,
        y: 0,
        width: 0,
        height: 0
      };
    var t = [];
    this.glyphInfo.forEach(function(A) {
      t.push(A.p0.x), t.push(A.p0.y), t.push(A.p1.x), t.push(A.p1.y);
    });
    for (var e = t[0] || 0, i = t[0] || 0, n = t[1] || 0, r = t[1] || 0, a, o, h = 0; h < t.length / 2; h++)
      a = t[h * 2], o = t[h * 2 + 1], e = Math.min(e, a), i = Math.max(i, a), n = Math.min(n, o), r = Math.max(r, o);
    var l = this.fontSize();
    return {
      x: e - l / 2,
      y: n - l / 2,
      width: i - e + l,
      height: r - n + l
    };
  }
  destroy() {
    return Ir.Util.releaseCanvas(this.dummyCanvas), super.destroy();
  }
}
Xn.TextPath = gt;
gt.prototype._fillFunc = Ho;
gt.prototype._strokeFunc = Vo;
gt.prototype._fillFuncHit = Ho;
gt.prototype._strokeFuncHit = Vo;
gt.prototype.className = "TextPath";
gt.prototype._attrsAffectingSize = ["text", "fontSize", "data"];
(0, D0._registerNode)(gt);
Lt.Factory.addGetterSetter(gt, "data");
Lt.Factory.addGetterSetter(gt, "fontFamily", "Arial");
Lt.Factory.addGetterSetter(gt, "fontSize", 12, (0, zo.getNumberValidator)());
Lt.Factory.addGetterSetter(gt, "fontStyle", Uo);
Lt.Factory.addGetterSetter(gt, "align", "left");
Lt.Factory.addGetterSetter(gt, "letterSpacing", 0, (0, zo.getNumberValidator)());
Lt.Factory.addGetterSetter(gt, "textBaseline", "middle");
Lt.Factory.addGetterSetter(gt, "fontVariant", Uo);
Lt.Factory.addGetterSetter(gt, "text", T0);
Lt.Factory.addGetterSetter(gt, "textDecoration", null);
Lt.Factory.addGetterSetter(gt, "kerningFunc", null);
var jn = {};
Object.defineProperty(jn, "__esModule", { value: !0 });
jn.Transformer = void 0;
const Z = rt, q = H, wa = st, I0 = ft, R0 = Oi, Sa = ri, Tt = V, ye = N, L0 = V;
var $o = "tr-konva", O0 = [
  "resizeEnabledChange",
  "rotateAnchorOffsetChange",
  "rotateEnabledChange",
  "enabledAnchorsChange",
  "anchorSizeChange",
  "borderEnabledChange",
  "borderStrokeChange",
  "borderStrokeWidthChange",
  "borderDashChange",
  "anchorStrokeChange",
  "anchorStrokeWidthChange",
  "anchorFillChange",
  "anchorCornerRadiusChange",
  "ignoreStrokeChange",
  "anchorStyleFuncChange"
].map((s) => s + `.${$o}`).join(" "), Ca = "nodesRect", N0 = [
  "widthChange",
  "heightChange",
  "scaleXChange",
  "scaleYChange",
  "skewXChange",
  "skewYChange",
  "rotationChange",
  "offsetXChange",
  "offsetYChange",
  "transformsEnabledChange",
  "strokeWidthChange"
], G0 = {
  "top-left": -45,
  "top-center": 0,
  "top-right": 45,
  "middle-right": -90,
  "middle-left": 90,
  "bottom-left": -135,
  "bottom-center": 180,
  "bottom-right": 135
};
const B0 = "ontouchstart" in Tt.Konva._global;
function z0(s, t, e) {
  if (s === "rotater")
    return e;
  t += Z.Util.degToRad(G0[s] || 0);
  var i = (Z.Util.radToDeg(t) % 360 + 360) % 360;
  return Z.Util._inRange(i, 315 + 22.5, 360) || Z.Util._inRange(i, 0, 22.5) ? "ns-resize" : Z.Util._inRange(i, 45 - 22.5, 45 + 22.5) ? "nesw-resize" : Z.Util._inRange(i, 90 - 22.5, 90 + 22.5) ? "ew-resize" : Z.Util._inRange(i, 135 - 22.5, 135 + 22.5) ? "nwse-resize" : Z.Util._inRange(i, 180 - 22.5, 180 + 22.5) ? "ns-resize" : Z.Util._inRange(i, 225 - 22.5, 225 + 22.5) ? "nesw-resize" : Z.Util._inRange(i, 270 - 22.5, 270 + 22.5) ? "ew-resize" : Z.Util._inRange(i, 315 - 22.5, 315 + 22.5) ? "nwse-resize" : (Z.Util.error("Transformer has unknown angle for cursor detection: " + i), "pointer");
}
var dn = [
  "top-left",
  "top-center",
  "top-right",
  "middle-right",
  "middle-left",
  "bottom-left",
  "bottom-center",
  "bottom-right"
], Ma = 1e8;
function U0(s) {
  return {
    x: s.x + s.width / 2 * Math.cos(s.rotation) + s.height / 2 * Math.sin(-s.rotation),
    y: s.y + s.height / 2 * Math.cos(s.rotation) + s.width / 2 * Math.sin(s.rotation)
  };
}
function Wo(s, t, e) {
  const i = e.x + (s.x - e.x) * Math.cos(t) - (s.y - e.y) * Math.sin(t), n = e.y + (s.x - e.x) * Math.sin(t) + (s.y - e.y) * Math.cos(t);
  return {
    ...s,
    rotation: s.rotation + t,
    x: i,
    y: n
  };
}
function H0(s, t) {
  const e = U0(s);
  return Wo(s, t, e);
}
function V0(s, t, e) {
  let i = t;
  for (let n = 0; n < s.length; n++) {
    const r = Tt.Konva.getAngle(s[n]), a = Math.abs(r - t) % (Math.PI * 2);
    Math.min(a, Math.PI * 2 - a) < e && (i = r);
  }
  return i;
}
let Zr = 0;
class Y extends Sa.Group {
  constructor(t) {
    super(t), this._movingAnchorName = null, this._transforming = !1, this._createElements(), this._handleMouseMove = this._handleMouseMove.bind(this), this._handleMouseUp = this._handleMouseUp.bind(this), this.update = this.update.bind(this), this.on(O0, this.update), this.getNode() && this.update();
  }
  attachTo(t) {
    return this.setNode(t), this;
  }
  setNode(t) {
    return Z.Util.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."), this.setNodes([t]);
  }
  getNode() {
    return this._nodes && this._nodes[0];
  }
  _getEventNamespace() {
    return $o + this._id;
  }
  setNodes(t = []) {
    this._nodes && this._nodes.length && this.detach();
    const e = t.filter((n) => n.isAncestorOf(this) ? (Z.Util.error("Konva.Transformer cannot be an a child of the node you are trying to attach"), !1) : !0);
    this._nodes = t = e, t.length === 1 && this.useSingleNodeRotation() ? this.rotation(t[0].getAbsoluteRotation()) : this.rotation(0), this._nodes.forEach((n) => {
      const r = () => {
        this.nodes().length === 1 && this.useSingleNodeRotation() && this.rotation(this.nodes()[0].getAbsoluteRotation()), this._resetTransformCache(), !this._transforming && !this.isDragging() && this.update();
      }, a = n._attrsAffectingSize.map((o) => o + "Change." + this._getEventNamespace()).join(" ");
      n.on(a, r), n.on(N0.map((o) => o + `.${this._getEventNamespace()}`).join(" "), r), n.on(`absoluteTransformChange.${this._getEventNamespace()}`, r), this._proxyDrag(n);
    }), this._resetTransformCache();
    var i = !!this.findOne(".top-left");
    return i && this.update(), this;
  }
  _proxyDrag(t) {
    let e;
    t.on(`dragstart.${this._getEventNamespace()}`, (i) => {
      e = t.getAbsolutePosition(), !this.isDragging() && t !== this.findOne(".back") && this.startDrag(i, !1);
    }), t.on(`dragmove.${this._getEventNamespace()}`, (i) => {
      if (!e)
        return;
      const n = t.getAbsolutePosition(), r = n.x - e.x, a = n.y - e.y;
      this.nodes().forEach((o) => {
        if (o === t || o.isDragging())
          return;
        const h = o.getAbsolutePosition();
        o.setAbsolutePosition({
          x: h.x + r,
          y: h.y + a
        }), o.startDrag(i);
      }), e = null;
    });
  }
  getNodes() {
    return this._nodes || [];
  }
  getActiveAnchor() {
    return this._movingAnchorName;
  }
  detach() {
    this._nodes && this._nodes.forEach((t) => {
      t.off("." + this._getEventNamespace());
    }), this._nodes = [], this._resetTransformCache();
  }
  _resetTransformCache() {
    this._clearCache(Ca), this._clearCache("transform"), this._clearSelfAndDescendantCache("absoluteTransform");
  }
  _getNodeRect() {
    return this._getCache(Ca, this.__getNodeRect);
  }
  __getNodeShape(t, e = this.rotation(), i) {
    var n = t.getClientRect({
      skipTransform: !0,
      skipShadow: !0,
      skipStroke: this.ignoreStroke()
    }), r = t.getAbsoluteScale(i), a = t.getAbsolutePosition(i), o = n.x * r.x - t.offsetX() * r.x, h = n.y * r.y - t.offsetY() * r.y;
    const l = (Tt.Konva.getAngle(t.getAbsoluteRotation()) + Math.PI * 2) % (Math.PI * 2), A = {
      x: a.x + o * Math.cos(l) + h * Math.sin(-l),
      y: a.y + h * Math.cos(l) + o * Math.sin(l),
      width: n.width * r.x,
      height: n.height * r.y,
      rotation: l
    };
    return Wo(A, -Tt.Konva.getAngle(e), {
      x: 0,
      y: 0
    });
  }
  __getNodeRect() {
    var t = this.getNode();
    if (!t)
      return {
        x: -Ma,
        y: -Ma,
        width: 0,
        height: 0,
        rotation: 0
      };
    const e = [];
    this.nodes().map((l) => {
      const A = l.getClientRect({
        skipTransform: !0,
        skipShadow: !0,
        skipStroke: this.ignoreStroke()
      });
      var u = [
        { x: A.x, y: A.y },
        { x: A.x + A.width, y: A.y },
        { x: A.x + A.width, y: A.y + A.height },
        { x: A.x, y: A.y + A.height }
      ], f = l.getAbsoluteTransform();
      u.forEach(function(d) {
        var c = f.point(d);
        e.push(c);
      });
    });
    const i = new Z.Transform();
    i.rotate(-Tt.Konva.getAngle(this.rotation()));
    var n = 1 / 0, r = 1 / 0, a = -1 / 0, o = -1 / 0;
    e.forEach(function(l) {
      var A = i.point(l);
      n === void 0 && (n = a = A.x, r = o = A.y), n = Math.min(n, A.x), r = Math.min(r, A.y), a = Math.max(a, A.x), o = Math.max(o, A.y);
    }), i.invert();
    const h = i.point({ x: n, y: r });
    return {
      x: h.x,
      y: h.y,
      width: a - n,
      height: o - r,
      rotation: Tt.Konva.getAngle(this.rotation())
    };
  }
  getX() {
    return this._getNodeRect().x;
  }
  getY() {
    return this._getNodeRect().y;
  }
  getWidth() {
    return this._getNodeRect().width;
  }
  getHeight() {
    return this._getNodeRect().height;
  }
  _createElements() {
    this._createBack(), dn.forEach((t) => {
      this._createAnchor(t);
    }), this._createAnchor("rotater");
  }
  _createAnchor(t) {
    var e = new R0.Rect({
      stroke: "rgb(0, 161, 255)",
      fill: "white",
      strokeWidth: 1,
      name: t + " _anchor",
      dragDistance: 0,
      draggable: !0,
      hitStrokeWidth: B0 ? 10 : "auto"
    }), i = this;
    e.on("mousedown touchstart", function(n) {
      i._handleMouseDown(n);
    }), e.on("dragstart", (n) => {
      e.stopDrag(), n.cancelBubble = !0;
    }), e.on("dragend", (n) => {
      n.cancelBubble = !0;
    }), e.on("mouseenter", () => {
      var n = Tt.Konva.getAngle(this.rotation()), r = this.rotateAnchorCursor(), a = z0(t, n, r);
      e.getStage().content && (e.getStage().content.style.cursor = a), this._cursorChange = !0;
    }), e.on("mouseout", () => {
      e.getStage().content && (e.getStage().content.style.cursor = ""), this._cursorChange = !1;
    }), this.add(e);
  }
  _createBack() {
    var t = new I0.Shape({
      name: "back",
      width: 0,
      height: 0,
      draggable: !0,
      sceneFunc(e, i) {
        var n = i.getParent(), r = n.padding();
        e.beginPath(), e.rect(-r, -r, i.width() + r * 2, i.height() + r * 2), e.moveTo(i.width() / 2, -r), n.rotateEnabled() && n.rotateLineVisible() && e.lineTo(i.width() / 2, -n.rotateAnchorOffset() * Z.Util._sign(i.height()) - r), e.fillStrokeShape(i);
      },
      hitFunc: (e, i) => {
        if (this.shouldOverdrawWholeArea()) {
          var n = this.padding();
          e.beginPath(), e.rect(-n, -n, i.width() + n * 2, i.height() + n * 2), e.fillStrokeShape(i);
        }
      }
    });
    this.add(t), this._proxyDrag(t), t.on("dragstart", (e) => {
      e.cancelBubble = !0;
    }), t.on("dragmove", (e) => {
      e.cancelBubble = !0;
    }), t.on("dragend", (e) => {
      e.cancelBubble = !0;
    }), this.on("dragmove", (e) => {
      this.update();
    });
  }
  _handleMouseDown(t) {
    this._movingAnchorName = t.target.name().split(" ")[0];
    var e = this._getNodeRect(), i = e.width, n = e.height, r = Math.sqrt(Math.pow(i, 2) + Math.pow(n, 2));
    this.sin = Math.abs(n / r), this.cos = Math.abs(i / r), typeof window < "u" && (window.addEventListener("mousemove", this._handleMouseMove), window.addEventListener("touchmove", this._handleMouseMove), window.addEventListener("mouseup", this._handleMouseUp, !0), window.addEventListener("touchend", this._handleMouseUp, !0)), this._transforming = !0;
    var a = t.target.getAbsolutePosition(), o = t.target.getStage().getPointerPosition();
    this._anchorDragOffset = {
      x: o.x - a.x,
      y: o.y - a.y
    }, Zr++, this._fire("transformstart", { evt: t.evt, target: this.getNode() }), this._nodes.forEach((h) => {
      h._fire("transformstart", { evt: t.evt, target: h });
    });
  }
  _handleMouseMove(t) {
    var e, i, n, r = this.findOne("." + this._movingAnchorName), a = r.getStage();
    a.setPointersPositions(t);
    const o = a.getPointerPosition();
    let h = {
      x: o.x - this._anchorDragOffset.x,
      y: o.y - this._anchorDragOffset.y
    };
    const l = r.getAbsolutePosition();
    this.anchorDragBoundFunc() && (h = this.anchorDragBoundFunc()(l, h, t)), r.setAbsolutePosition(h);
    const A = r.getAbsolutePosition();
    if (!(l.x === A.x && l.y === A.y)) {
      if (this._movingAnchorName === "rotater") {
        var u = this._getNodeRect();
        e = r.x() - u.width / 2, i = -r.y() + u.height / 2;
        let F = Math.atan2(-i, e) + Math.PI / 2;
        u.height < 0 && (F -= Math.PI);
        var f = Tt.Konva.getAngle(this.rotation());
        const I = f + F, T = Tt.Konva.getAngle(this.rotationSnapTolerance()), L = V0(this.rotationSnaps(), I, T) - u.rotation, B = H0(u, L);
        this._fitNodesInto(B, t);
        return;
      }
      var d = this.shiftBehavior(), c;
      d === "inverted" ? c = this.keepRatio() && !t.shiftKey : d === "none" ? c = this.keepRatio() : c = this.keepRatio() || t.shiftKey;
      var g = this.centeredScaling() || t.altKey;
      if (this._movingAnchorName === "top-left") {
        if (c) {
          var p = g ? {
            x: this.width() / 2,
            y: this.height() / 2
          } : {
            x: this.findOne(".bottom-right").x(),
            y: this.findOne(".bottom-right").y()
          };
          n = Math.sqrt(Math.pow(p.x - r.x(), 2) + Math.pow(p.y - r.y(), 2));
          var m = this.findOne(".top-left").x() > p.x ? -1 : 1, v = this.findOne(".top-left").y() > p.y ? -1 : 1;
          e = n * this.cos * m, i = n * this.sin * v, this.findOne(".top-left").x(p.x - e), this.findOne(".top-left").y(p.y - i);
        }
      } else if (this._movingAnchorName === "top-center")
        this.findOne(".top-left").y(r.y());
      else if (this._movingAnchorName === "top-right") {
        if (c) {
          var p = g ? {
            x: this.width() / 2,
            y: this.height() / 2
          } : {
            x: this.findOne(".bottom-left").x(),
            y: this.findOne(".bottom-left").y()
          };
          n = Math.sqrt(Math.pow(r.x() - p.x, 2) + Math.pow(p.y - r.y(), 2));
          var m = this.findOne(".top-right").x() < p.x ? -1 : 1, v = this.findOne(".top-right").y() > p.y ? -1 : 1;
          e = n * this.cos * m, i = n * this.sin * v, this.findOne(".top-right").x(p.x + e), this.findOne(".top-right").y(p.y - i);
        }
        var x = r.position();
        this.findOne(".top-left").y(x.y), this.findOne(".bottom-right").x(x.x);
      } else if (this._movingAnchorName === "middle-left")
        this.findOne(".top-left").x(r.x());
      else if (this._movingAnchorName === "middle-right")
        this.findOne(".bottom-right").x(r.x());
      else if (this._movingAnchorName === "bottom-left") {
        if (c) {
          var p = g ? {
            x: this.width() / 2,
            y: this.height() / 2
          } : {
            x: this.findOne(".top-right").x(),
            y: this.findOne(".top-right").y()
          };
          n = Math.sqrt(Math.pow(p.x - r.x(), 2) + Math.pow(r.y() - p.y, 2));
          var m = p.x < r.x() ? -1 : 1, v = r.y() < p.y ? -1 : 1;
          e = n * this.cos * m, i = n * this.sin * v, r.x(p.x - e), r.y(p.y + i);
        }
        x = r.position(), this.findOne(".top-left").x(x.x), this.findOne(".bottom-right").y(x.y);
      } else if (this._movingAnchorName === "bottom-center")
        this.findOne(".bottom-right").y(r.y());
      else if (this._movingAnchorName === "bottom-right") {
        if (c) {
          var p = g ? {
            x: this.width() / 2,
            y: this.height() / 2
          } : {
            x: this.findOne(".top-left").x(),
            y: this.findOne(".top-left").y()
          };
          n = Math.sqrt(Math.pow(r.x() - p.x, 2) + Math.pow(r.y() - p.y, 2));
          var m = this.findOne(".bottom-right").x() < p.x ? -1 : 1, v = this.findOne(".bottom-right").y() < p.y ? -1 : 1;
          e = n * this.cos * m, i = n * this.sin * v, this.findOne(".bottom-right").x(p.x + e), this.findOne(".bottom-right").y(p.y + i);
        }
      } else
        console.error(new Error("Wrong position argument of selection resizer: " + this._movingAnchorName));
      var g = this.centeredScaling() || t.altKey;
      if (g) {
        var y = this.findOne(".top-left"), _ = this.findOne(".bottom-right"), b = y.x(), C = y.y(), w = this.getWidth() - _.x(), E = this.getHeight() - _.y();
        _.move({
          x: -b,
          y: -C
        }), y.move({
          x: w,
          y: E
        });
      }
      var S = this.findOne(".top-left").getAbsolutePosition();
      e = S.x, i = S.y;
      var P = this.findOne(".bottom-right").x() - this.findOne(".top-left").x(), k = this.findOne(".bottom-right").y() - this.findOne(".top-left").y();
      this._fitNodesInto({
        x: e,
        y: i,
        width: P,
        height: k,
        rotation: Tt.Konva.getAngle(this.rotation())
      }, t);
    }
  }
  _handleMouseUp(t) {
    this._removeEvents(t);
  }
  getAbsoluteTransform() {
    return this.getTransform();
  }
  _removeEvents(t) {
    var e;
    if (this._transforming) {
      this._transforming = !1, typeof window < "u" && (window.removeEventListener("mousemove", this._handleMouseMove), window.removeEventListener("touchmove", this._handleMouseMove), window.removeEventListener("mouseup", this._handleMouseUp, !0), window.removeEventListener("touchend", this._handleMouseUp, !0));
      var i = this.getNode();
      Zr--, this._fire("transformend", { evt: t, target: i }), (e = this.getLayer()) === null || e === void 0 || e.batchDraw(), i && this._nodes.forEach((n) => {
        var r;
        n._fire("transformend", { evt: t, target: n }), (r = n.getLayer()) === null || r === void 0 || r.batchDraw();
      }), this._movingAnchorName = null;
    }
  }
  _fitNodesInto(t, e) {
    var i = this._getNodeRect();
    const n = 1;
    if (Z.Util._inRange(t.width, -this.padding() * 2 - n, n)) {
      this.update();
      return;
    }
    if (Z.Util._inRange(t.height, -this.padding() * 2 - n, n)) {
      this.update();
      return;
    }
    var r = new Z.Transform();
    if (r.rotate(Tt.Konva.getAngle(this.rotation())), this._movingAnchorName && t.width < 0 && this._movingAnchorName.indexOf("left") >= 0) {
      const f = r.point({
        x: -this.padding() * 2,
        y: 0
      });
      t.x += f.x, t.y += f.y, t.width += this.padding() * 2, this._movingAnchorName = this._movingAnchorName.replace("left", "right"), this._anchorDragOffset.x -= f.x, this._anchorDragOffset.y -= f.y;
    } else if (this._movingAnchorName && t.width < 0 && this._movingAnchorName.indexOf("right") >= 0) {
      const f = r.point({
        x: this.padding() * 2,
        y: 0
      });
      this._movingAnchorName = this._movingAnchorName.replace("right", "left"), this._anchorDragOffset.x -= f.x, this._anchorDragOffset.y -= f.y, t.width += this.padding() * 2;
    }
    if (this._movingAnchorName && t.height < 0 && this._movingAnchorName.indexOf("top") >= 0) {
      const f = r.point({
        x: 0,
        y: -this.padding() * 2
      });
      t.x += f.x, t.y += f.y, this._movingAnchorName = this._movingAnchorName.replace("top", "bottom"), this._anchorDragOffset.x -= f.x, this._anchorDragOffset.y -= f.y, t.height += this.padding() * 2;
    } else if (this._movingAnchorName && t.height < 0 && this._movingAnchorName.indexOf("bottom") >= 0) {
      const f = r.point({
        x: 0,
        y: this.padding() * 2
      });
      this._movingAnchorName = this._movingAnchorName.replace("bottom", "top"), this._anchorDragOffset.x -= f.x, this._anchorDragOffset.y -= f.y, t.height += this.padding() * 2;
    }
    if (this.boundBoxFunc()) {
      const f = this.boundBoxFunc()(i, t);
      f ? t = f : Z.Util.warn("boundBoxFunc returned falsy. You should return new bound rect from it!");
    }
    const a = 1e7, o = new Z.Transform();
    o.translate(i.x, i.y), o.rotate(i.rotation), o.scale(i.width / a, i.height / a);
    const h = new Z.Transform(), l = t.width / a, A = t.height / a;
    this.flipEnabled() === !1 ? (h.translate(t.x, t.y), h.rotate(t.rotation), h.translate(t.width < 0 ? t.width : 0, t.height < 0 ? t.height : 0), h.scale(Math.abs(l), Math.abs(A))) : (h.translate(t.x, t.y), h.rotate(t.rotation), h.scale(l, A));
    const u = h.multiply(o.invert());
    this._nodes.forEach((f) => {
      var d;
      const c = f.getParent().getAbsoluteTransform(), p = f.getTransform().copy();
      p.translate(f.offsetX(), f.offsetY());
      const m = new Z.Transform();
      m.multiply(c.copy().invert()).multiply(u).multiply(c).multiply(p);
      const v = m.decompose();
      f.setAttrs(v), (d = f.getLayer()) === null || d === void 0 || d.batchDraw();
    }), this.rotation(Z.Util._getRotation(t.rotation)), this._nodes.forEach((f) => {
      this._fire("transform", { evt: e, target: f }), f._fire("transform", { evt: e, target: f });
    }), this._resetTransformCache(), this.update(), this.getLayer().batchDraw();
  }
  forceUpdate() {
    this._resetTransformCache(), this.update();
  }
  _batchChangeChild(t, e) {
    this.findOne(t).setAttrs(e);
  }
  update() {
    var t, e = this._getNodeRect();
    this.rotation(Z.Util._getRotation(e.rotation));
    var i = e.width, n = e.height, r = this.enabledAnchors(), a = this.resizeEnabled(), o = this.padding(), h = this.anchorSize();
    const l = this.find("._anchor");
    l.forEach((u) => {
      u.setAttrs({
        width: h,
        height: h,
        offsetX: h / 2,
        offsetY: h / 2,
        stroke: this.anchorStroke(),
        strokeWidth: this.anchorStrokeWidth(),
        fill: this.anchorFill(),
        cornerRadius: this.anchorCornerRadius()
      });
    }), this._batchChangeChild(".top-left", {
      x: 0,
      y: 0,
      offsetX: h / 2 + o,
      offsetY: h / 2 + o,
      visible: a && r.indexOf("top-left") >= 0
    }), this._batchChangeChild(".top-center", {
      x: i / 2,
      y: 0,
      offsetY: h / 2 + o,
      visible: a && r.indexOf("top-center") >= 0
    }), this._batchChangeChild(".top-right", {
      x: i,
      y: 0,
      offsetX: h / 2 - o,
      offsetY: h / 2 + o,
      visible: a && r.indexOf("top-right") >= 0
    }), this._batchChangeChild(".middle-left", {
      x: 0,
      y: n / 2,
      offsetX: h / 2 + o,
      visible: a && r.indexOf("middle-left") >= 0
    }), this._batchChangeChild(".middle-right", {
      x: i,
      y: n / 2,
      offsetX: h / 2 - o,
      visible: a && r.indexOf("middle-right") >= 0
    }), this._batchChangeChild(".bottom-left", {
      x: 0,
      y: n,
      offsetX: h / 2 + o,
      offsetY: h / 2 - o,
      visible: a && r.indexOf("bottom-left") >= 0
    }), this._batchChangeChild(".bottom-center", {
      x: i / 2,
      y: n,
      offsetY: h / 2 - o,
      visible: a && r.indexOf("bottom-center") >= 0
    }), this._batchChangeChild(".bottom-right", {
      x: i,
      y: n,
      offsetX: h / 2 - o,
      offsetY: h / 2 - o,
      visible: a && r.indexOf("bottom-right") >= 0
    }), this._batchChangeChild(".rotater", {
      x: i / 2,
      y: -this.rotateAnchorOffset() * Z.Util._sign(n) - o,
      visible: this.rotateEnabled()
    }), this._batchChangeChild(".back", {
      width: i,
      height: n,
      visible: this.borderEnabled(),
      stroke: this.borderStroke(),
      strokeWidth: this.borderStrokeWidth(),
      dash: this.borderDash(),
      x: 0,
      y: 0
    });
    const A = this.anchorStyleFunc();
    A && l.forEach((u) => {
      A(u);
    }), (t = this.getLayer()) === null || t === void 0 || t.batchDraw();
  }
  isTransforming() {
    return this._transforming;
  }
  stopTransform() {
    if (this._transforming) {
      this._removeEvents();
      var t = this.findOne("." + this._movingAnchorName);
      t && t.stopDrag();
    }
  }
  destroy() {
    return this.getStage() && this._cursorChange && this.getStage().content && (this.getStage().content.style.cursor = ""), Sa.Group.prototype.destroy.call(this), this.detach(), this._removeEvents(), this;
  }
  toObject() {
    return wa.Node.prototype.toObject.call(this);
  }
  clone(t) {
    var e = wa.Node.prototype.clone.call(this, t);
    return e;
  }
  getClientRect() {
    return this.nodes().length > 0 ? super.getClientRect() : { x: 0, y: 0, width: 0, height: 0 };
  }
}
jn.Transformer = Y;
Y.isTransforming = () => Zr > 0;
function $0(s) {
  return s instanceof Array || Z.Util.warn("enabledAnchors value should be an array"), s instanceof Array && s.forEach(function(t) {
    dn.indexOf(t) === -1 && Z.Util.warn("Unknown anchor name: " + t + ". Available names are: " + dn.join(", "));
  }), s || [];
}
Y.prototype.className = "Transformer";
(0, L0._registerNode)(Y);
q.Factory.addGetterSetter(Y, "enabledAnchors", dn, $0);
q.Factory.addGetterSetter(Y, "flipEnabled", !0, (0, ye.getBooleanValidator)());
q.Factory.addGetterSetter(Y, "resizeEnabled", !0);
q.Factory.addGetterSetter(Y, "anchorSize", 10, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "rotateEnabled", !0);
q.Factory.addGetterSetter(Y, "rotateLineVisible", !0);
q.Factory.addGetterSetter(Y, "rotationSnaps", []);
q.Factory.addGetterSetter(Y, "rotateAnchorOffset", 50, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "rotateAnchorCursor", "crosshair");
q.Factory.addGetterSetter(Y, "rotationSnapTolerance", 5, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "borderEnabled", !0);
q.Factory.addGetterSetter(Y, "anchorStroke", "rgb(0, 161, 255)");
q.Factory.addGetterSetter(Y, "anchorStrokeWidth", 1, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "anchorFill", "white");
q.Factory.addGetterSetter(Y, "anchorCornerRadius", 0, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "borderStroke", "rgb(0, 161, 255)");
q.Factory.addGetterSetter(Y, "borderStrokeWidth", 1, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "borderDash");
q.Factory.addGetterSetter(Y, "keepRatio", !0);
q.Factory.addGetterSetter(Y, "shiftBehavior", "default");
q.Factory.addGetterSetter(Y, "centeredScaling", !1);
q.Factory.addGetterSetter(Y, "ignoreStroke", !1);
q.Factory.addGetterSetter(Y, "padding", 0, (0, ye.getNumberValidator)());
q.Factory.addGetterSetter(Y, "node");
q.Factory.addGetterSetter(Y, "nodes");
q.Factory.addGetterSetter(Y, "boundBoxFunc");
q.Factory.addGetterSetter(Y, "anchorDragBoundFunc");
q.Factory.addGetterSetter(Y, "anchorStyleFunc");
q.Factory.addGetterSetter(Y, "shouldOverdrawWholeArea", !1);
q.Factory.addGetterSetter(Y, "useSingleNodeRotation", !0);
q.Factory.backCompat(Y, {
  lineEnabled: "borderEnabled",
  rotateHandlerOffset: "rotateAnchorOffset",
  enabledHandlers: "enabledAnchors"
});
var qn = {};
Object.defineProperty(qn, "__esModule", { value: !0 });
qn.Wedge = void 0;
const Qn = H, W0 = ft, Y0 = V, Yo = N, X0 = V;
class te extends W0.Shape {
  _sceneFunc(t) {
    t.beginPath(), t.arc(0, 0, this.radius(), 0, Y0.Konva.getAngle(this.angle()), this.clockwise()), t.lineTo(0, 0), t.closePath(), t.fillStrokeShape(this);
  }
  getWidth() {
    return this.radius() * 2;
  }
  getHeight() {
    return this.radius() * 2;
  }
  setWidth(t) {
    this.radius(t / 2);
  }
  setHeight(t) {
    this.radius(t / 2);
  }
}
qn.Wedge = te;
te.prototype.className = "Wedge";
te.prototype._centroid = !0;
te.prototype._attrsAffectingSize = ["radius"];
(0, X0._registerNode)(te);
Qn.Factory.addGetterSetter(te, "radius", 0, (0, Yo.getNumberValidator)());
Qn.Factory.addGetterSetter(te, "angle", 0, (0, Yo.getNumberValidator)());
Qn.Factory.addGetterSetter(te, "clockwise", !1);
Qn.Factory.backCompat(te, {
  angleDeg: "angle",
  getAngleDeg: "getAngle",
  setAngleDeg: "setAngle"
});
var Kn = {};
Object.defineProperty(Kn, "__esModule", { value: !0 });
Kn.Blur = void 0;
const Pa = H, j0 = st, q0 = N;
function Ea() {
  this.r = 0, this.g = 0, this.b = 0, this.a = 0, this.next = null;
}
var Q0 = [
  512,
  512,
  456,
  512,
  328,
  456,
  335,
  512,
  405,
  328,
  271,
  456,
  388,
  335,
  292,
  512,
  454,
  405,
  364,
  328,
  298,
  271,
  496,
  456,
  420,
  388,
  360,
  335,
  312,
  292,
  273,
  512,
  482,
  454,
  428,
  405,
  383,
  364,
  345,
  328,
  312,
  298,
  284,
  271,
  259,
  496,
  475,
  456,
  437,
  420,
  404,
  388,
  374,
  360,
  347,
  335,
  323,
  312,
  302,
  292,
  282,
  273,
  265,
  512,
  497,
  482,
  468,
  454,
  441,
  428,
  417,
  405,
  394,
  383,
  373,
  364,
  354,
  345,
  337,
  328,
  320,
  312,
  305,
  298,
  291,
  284,
  278,
  271,
  265,
  259,
  507,
  496,
  485,
  475,
  465,
  456,
  446,
  437,
  428,
  420,
  412,
  404,
  396,
  388,
  381,
  374,
  367,
  360,
  354,
  347,
  341,
  335,
  329,
  323,
  318,
  312,
  307,
  302,
  297,
  292,
  287,
  282,
  278,
  273,
  269,
  265,
  261,
  512,
  505,
  497,
  489,
  482,
  475,
  468,
  461,
  454,
  447,
  441,
  435,
  428,
  422,
  417,
  411,
  405,
  399,
  394,
  389,
  383,
  378,
  373,
  368,
  364,
  359,
  354,
  350,
  345,
  341,
  337,
  332,
  328,
  324,
  320,
  316,
  312,
  309,
  305,
  301,
  298,
  294,
  291,
  287,
  284,
  281,
  278,
  274,
  271,
  268,
  265,
  262,
  259,
  257,
  507,
  501,
  496,
  491,
  485,
  480,
  475,
  470,
  465,
  460,
  456,
  451,
  446,
  442,
  437,
  433,
  428,
  424,
  420,
  416,
  412,
  408,
  404,
  400,
  396,
  392,
  388,
  385,
  381,
  377,
  374,
  370,
  367,
  363,
  360,
  357,
  354,
  350,
  347,
  344,
  341,
  338,
  335,
  332,
  329,
  326,
  323,
  320,
  318,
  315,
  312,
  310,
  307,
  304,
  302,
  299,
  297,
  294,
  292,
  289,
  287,
  285,
  282,
  280,
  278,
  275,
  273,
  271,
  269,
  267,
  265,
  263,
  261,
  259
], K0 = [
  9,
  11,
  12,
  13,
  13,
  14,
  14,
  15,
  15,
  15,
  15,
  16,
  16,
  16,
  16,
  17,
  17,
  17,
  17,
  17,
  17,
  17,
  18,
  18,
  18,
  18,
  18,
  18,
  18,
  18,
  18,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  20,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  21,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  23,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24,
  24
];
function Z0(s, t) {
  var e = s.data, i = s.width, n = s.height, r, a, o, h, l, A, u, f, d, c, p, m, v, x, g, y, _, b, C, w, E, S, P, k, F = t + t + 1, I = i - 1, T = n - 1, R = t + 1, L = R * (R + 1) / 2, B = new Ea(), $ = null, O = B, G = null, Q = null, et = Q0[t], tt = K0[t];
  for (o = 1; o < F; o++)
    O = O.next = new Ea(), o === R && ($ = O);
  for (O.next = B, u = A = 0, a = 0; a < n; a++) {
    for (y = _ = b = C = f = d = c = p = 0, m = R * (w = e[A]), v = R * (E = e[A + 1]), x = R * (S = e[A + 2]), g = R * (P = e[A + 3]), f += L * w, d += L * E, c += L * S, p += L * P, O = B, o = 0; o < R; o++)
      O.r = w, O.g = E, O.b = S, O.a = P, O = O.next;
    for (o = 1; o < R; o++)
      h = A + ((I < o ? I : o) << 2), f += (O.r = w = e[h]) * (k = R - o), d += (O.g = E = e[h + 1]) * k, c += (O.b = S = e[h + 2]) * k, p += (O.a = P = e[h + 3]) * k, y += w, _ += E, b += S, C += P, O = O.next;
    for (G = B, Q = $, r = 0; r < i; r++)
      e[A + 3] = P = p * et >> tt, P !== 0 ? (P = 255 / P, e[A] = (f * et >> tt) * P, e[A + 1] = (d * et >> tt) * P, e[A + 2] = (c * et >> tt) * P) : e[A] = e[A + 1] = e[A + 2] = 0, f -= m, d -= v, c -= x, p -= g, m -= G.r, v -= G.g, x -= G.b, g -= G.a, h = u + ((h = r + t + 1) < I ? h : I) << 2, y += G.r = e[h], _ += G.g = e[h + 1], b += G.b = e[h + 2], C += G.a = e[h + 3], f += y, d += _, c += b, p += C, G = G.next, m += w = Q.r, v += E = Q.g, x += S = Q.b, g += P = Q.a, y -= w, _ -= E, b -= S, C -= P, Q = Q.next, A += 4;
    u += i;
  }
  for (r = 0; r < i; r++) {
    for (_ = b = C = y = d = c = p = f = 0, A = r << 2, m = R * (w = e[A]), v = R * (E = e[A + 1]), x = R * (S = e[A + 2]), g = R * (P = e[A + 3]), f += L * w, d += L * E, c += L * S, p += L * P, O = B, o = 0; o < R; o++)
      O.r = w, O.g = E, O.b = S, O.a = P, O = O.next;
    for (l = i, o = 1; o <= t; o++)
      A = l + r << 2, f += (O.r = w = e[A]) * (k = R - o), d += (O.g = E = e[A + 1]) * k, c += (O.b = S = e[A + 2]) * k, p += (O.a = P = e[A + 3]) * k, y += w, _ += E, b += S, C += P, O = O.next, o < T && (l += i);
    for (A = r, G = B, Q = $, a = 0; a < n; a++)
      h = A << 2, e[h + 3] = P = p * et >> tt, P > 0 ? (P = 255 / P, e[h] = (f * et >> tt) * P, e[h + 1] = (d * et >> tt) * P, e[h + 2] = (c * et >> tt) * P) : e[h] = e[h + 1] = e[h + 2] = 0, f -= m, d -= v, c -= x, p -= g, m -= G.r, v -= G.g, x -= G.b, g -= G.a, h = r + ((h = a + R) < T ? h : T) * i << 2, f += y += G.r = e[h], d += _ += G.g = e[h + 1], c += b += G.b = e[h + 2], p += C += G.a = e[h + 3], G = G.next, m += w = Q.r, v += E = Q.g, x += S = Q.b, g += P = Q.a, y -= w, _ -= E, b -= S, C -= P, Q = Q.next, A += i;
  }
}
const J0 = function(t) {
  var e = Math.round(this.blurRadius());
  e > 0 && Z0(t, e);
};
Kn.Blur = J0;
Pa.Factory.addGetterSetter(j0.Node, "blurRadius", 0, (0, q0.getNumberValidator)(), Pa.Factory.afterSetFilter);
var Zn = {};
Object.defineProperty(Zn, "__esModule", { value: !0 });
Zn.Brighten = void 0;
const Fa = H, td = st, ed = N, id = function(s) {
  var t = this.brightness() * 255, e = s.data, i = e.length, n;
  for (n = 0; n < i; n += 4)
    e[n] += t, e[n + 1] += t, e[n + 2] += t;
};
Zn.Brighten = id;
Fa.Factory.addGetterSetter(td.Node, "brightness", 0, (0, ed.getNumberValidator)(), Fa.Factory.afterSetFilter);
var Jn = {};
Object.defineProperty(Jn, "__esModule", { value: !0 });
Jn.Contrast = void 0;
const ka = H, nd = st, rd = N, sd = function(s) {
  var t = Math.pow((this.contrast() + 100) / 100, 2), e = s.data, i = e.length, n = 150, r = 150, a = 150, o;
  for (o = 0; o < i; o += 4)
    n = e[o], r = e[o + 1], a = e[o + 2], n /= 255, n -= 0.5, n *= t, n += 0.5, n *= 255, r /= 255, r -= 0.5, r *= t, r += 0.5, r *= 255, a /= 255, a -= 0.5, a *= t, a += 0.5, a *= 255, n = n < 0 ? 0 : n > 255 ? 255 : n, r = r < 0 ? 0 : r > 255 ? 255 : r, a = a < 0 ? 0 : a > 255 ? 255 : a, e[o] = n, e[o + 1] = r, e[o + 2] = a;
};
Jn.Contrast = sd;
ka.Factory.addGetterSetter(nd.Node, "contrast", 0, (0, rd.getNumberValidator)(), ka.Factory.afterSetFilter);
var tr = {};
Object.defineProperty(tr, "__esModule", { value: !0 });
tr.Emboss = void 0;
const de = H, er = st, ad = rt, Xo = N, od = function(s) {
  var t = this.embossStrength() * 10, e = this.embossWhiteLevel() * 255, i = this.embossDirection(), n = this.embossBlend(), r = 0, a = 0, o = s.data, h = s.width, l = s.height, A = h * 4, u = l;
  switch (i) {
    case "top-left":
      r = -1, a = -1;
      break;
    case "top":
      r = -1, a = 0;
      break;
    case "top-right":
      r = -1, a = 1;
      break;
    case "right":
      r = 0, a = 1;
      break;
    case "bottom-right":
      r = 1, a = 1;
      break;
    case "bottom":
      r = 1, a = 0;
      break;
    case "bottom-left":
      r = 1, a = -1;
      break;
    case "left":
      r = 0, a = -1;
      break;
    default:
      ad.Util.error("Unknown emboss direction: " + i);
  }
  do {
    var f = (u - 1) * A, d = r;
    u + d < 1 && (d = 0), u + d > l && (d = 0);
    var c = (u - 1 + d) * h * 4, p = h;
    do {
      var m = f + (p - 1) * 4, v = a;
      p + v < 1 && (v = 0), p + v > h && (v = 0);
      var x = c + (p - 1 + v) * 4, g = o[m] - o[x], y = o[m + 1] - o[x + 1], _ = o[m + 2] - o[x + 2], b = g, C = b > 0 ? b : -b, w = y > 0 ? y : -y, E = _ > 0 ? _ : -_;
      if (w > C && (b = y), E > C && (b = _), b *= t, n) {
        var S = o[m] + b, P = o[m + 1] + b, k = o[m + 2] + b;
        o[m] = S > 255 ? 255 : S < 0 ? 0 : S, o[m + 1] = P > 255 ? 255 : P < 0 ? 0 : P, o[m + 2] = k > 255 ? 255 : k < 0 ? 0 : k;
      } else {
        var F = e - b;
        F < 0 ? F = 0 : F > 255 && (F = 255), o[m] = o[m + 1] = o[m + 2] = F;
      }
    } while (--p);
  } while (--u);
};
tr.Emboss = od;
de.Factory.addGetterSetter(er.Node, "embossStrength", 0.5, (0, Xo.getNumberValidator)(), de.Factory.afterSetFilter);
de.Factory.addGetterSetter(er.Node, "embossWhiteLevel", 0.5, (0, Xo.getNumberValidator)(), de.Factory.afterSetFilter);
de.Factory.addGetterSetter(er.Node, "embossDirection", "top-left", null, de.Factory.afterSetFilter);
de.Factory.addGetterSetter(er.Node, "embossBlend", !1, null, de.Factory.afterSetFilter);
var ir = {};
Object.defineProperty(ir, "__esModule", { value: !0 });
ir.Enhance = void 0;
const Da = H, hd = st, ld = N;
function Lr(s, t, e, i, n) {
  var r = e - t, a = n - i, o;
  return r === 0 ? i + a / 2 : a === 0 ? i : (o = (s - t) / r, o = a * o + i, o);
}
const Ad = function(s) {
  var t = s.data, e = t.length, i = t[0], n = i, r, a = t[1], o = a, h, l = t[2], A = l, u, f, d = this.enhance();
  if (d !== 0) {
    for (f = 0; f < e; f += 4)
      r = t[f + 0], r < i ? i = r : r > n && (n = r), h = t[f + 1], h < a ? a = h : h > o && (o = h), u = t[f + 2], u < l ? l = u : u > A && (A = u);
    n === i && (n = 255, i = 0), o === a && (o = 255, a = 0), A === l && (A = 255, l = 0);
    var c, p, m, v, x, g, y, _, b;
    for (d > 0 ? (p = n + d * (255 - n), m = i - d * (i - 0), x = o + d * (255 - o), g = a - d * (a - 0), _ = A + d * (255 - A), b = l - d * (l - 0)) : (c = (n + i) * 0.5, p = n + d * (n - c), m = i + d * (i - c), v = (o + a) * 0.5, x = o + d * (o - v), g = a + d * (a - v), y = (A + l) * 0.5, _ = A + d * (A - y), b = l + d * (l - y)), f = 0; f < e; f += 4)
      t[f + 0] = Lr(t[f + 0], i, n, m, p), t[f + 1] = Lr(t[f + 1], a, o, g, x), t[f + 2] = Lr(t[f + 2], l, A, b, _);
  }
};
ir.Enhance = Ad;
Da.Factory.addGetterSetter(hd.Node, "enhance", 0, (0, ld.getNumberValidator)(), Da.Factory.afterSetFilter);
var nr = {};
Object.defineProperty(nr, "__esModule", { value: !0 });
nr.Grayscale = void 0;
const dd = function(s) {
  var t = s.data, e = t.length, i, n;
  for (i = 0; i < e; i += 4)
    n = 0.34 * t[i] + 0.5 * t[i + 1] + 0.16 * t[i + 2], t[i] = n, t[i + 1] = n, t[i + 2] = n;
};
nr.Grayscale = dd;
var rr = {};
Object.defineProperty(rr, "__esModule", { value: !0 });
rr.HSL = void 0;
const Je = H, Ss = st, Cs = N;
Je.Factory.addGetterSetter(Ss.Node, "hue", 0, (0, Cs.getNumberValidator)(), Je.Factory.afterSetFilter);
Je.Factory.addGetterSetter(Ss.Node, "saturation", 0, (0, Cs.getNumberValidator)(), Je.Factory.afterSetFilter);
Je.Factory.addGetterSetter(Ss.Node, "luminance", 0, (0, Cs.getNumberValidator)(), Je.Factory.afterSetFilter);
const cd = function(s) {
  var t = s.data, e = t.length, i = 1, n = Math.pow(2, this.saturation()), r = Math.abs(this.hue() + 360) % 360, a = this.luminance() * 127, o, h = i * n * Math.cos(r * Math.PI / 180), l = i * n * Math.sin(r * Math.PI / 180), A = 0.299 * i + 0.701 * h + 0.167 * l, u = 0.587 * i - 0.587 * h + 0.33 * l, f = 0.114 * i - 0.114 * h - 0.497 * l, d = 0.299 * i - 0.299 * h - 0.328 * l, c = 0.587 * i + 0.413 * h + 0.035 * l, p = 0.114 * i - 0.114 * h + 0.293 * l, m = 0.299 * i - 0.3 * h + 1.25 * l, v = 0.587 * i - 0.586 * h - 1.05 * l, x = 0.114 * i + 0.886 * h - 0.2 * l, g, y, _, b;
  for (o = 0; o < e; o += 4)
    g = t[o + 0], y = t[o + 1], _ = t[o + 2], b = t[o + 3], t[o + 0] = A * g + u * y + f * _ + a, t[o + 1] = d * g + c * y + p * _ + a, t[o + 2] = m * g + v * y + x * _ + a, t[o + 3] = b;
};
rr.HSL = cd;
var sr = {};
Object.defineProperty(sr, "__esModule", { value: !0 });
sr.HSV = void 0;
const ti = H, Ms = st, Ps = N, ud = function(s) {
  var t = s.data, e = t.length, i = Math.pow(2, this.value()), n = Math.pow(2, this.saturation()), r = Math.abs(this.hue() + 360) % 360, a, o = i * n * Math.cos(r * Math.PI / 180), h = i * n * Math.sin(r * Math.PI / 180), l = 0.299 * i + 0.701 * o + 0.167 * h, A = 0.587 * i - 0.587 * o + 0.33 * h, u = 0.114 * i - 0.114 * o - 0.497 * h, f = 0.299 * i - 0.299 * o - 0.328 * h, d = 0.587 * i + 0.413 * o + 0.035 * h, c = 0.114 * i - 0.114 * o + 0.293 * h, p = 0.299 * i - 0.3 * o + 1.25 * h, m = 0.587 * i - 0.586 * o - 1.05 * h, v = 0.114 * i + 0.886 * o - 0.2 * h, x, g, y, _;
  for (a = 0; a < e; a += 4)
    x = t[a + 0], g = t[a + 1], y = t[a + 2], _ = t[a + 3], t[a + 0] = l * x + A * g + u * y, t[a + 1] = f * x + d * g + c * y, t[a + 2] = p * x + m * g + v * y, t[a + 3] = _;
};
sr.HSV = ud;
ti.Factory.addGetterSetter(Ms.Node, "hue", 0, (0, Ps.getNumberValidator)(), ti.Factory.afterSetFilter);
ti.Factory.addGetterSetter(Ms.Node, "saturation", 0, (0, Ps.getNumberValidator)(), ti.Factory.afterSetFilter);
ti.Factory.addGetterSetter(Ms.Node, "value", 0, (0, Ps.getNumberValidator)(), ti.Factory.afterSetFilter);
var ar = {};
Object.defineProperty(ar, "__esModule", { value: !0 });
ar.Invert = void 0;
const fd = function(s) {
  var t = s.data, e = t.length, i;
  for (i = 0; i < e; i += 4)
    t[i] = 255 - t[i], t[i + 1] = 255 - t[i + 1], t[i + 2] = 255 - t[i + 2];
};
ar.Invert = fd;
var or = {};
Object.defineProperty(or, "__esModule", { value: !0 });
or.Kaleidoscope = void 0;
const cn = H, jo = st, Ta = rt, qo = N;
var gd = function(s, t, e) {
  var i = s.data, n = t.data, r = s.width, a = s.height, o = e.polarCenterX || r / 2, h = e.polarCenterY || a / 2, l, A, u, f = 0, d = 0, c = 0, p = 0, m, v = Math.sqrt(o * o + h * h);
  A = r - o, u = a - h, m = Math.sqrt(A * A + u * u), v = m > v ? m : v;
  var x = a, g = r, y, _, b = 360 / g * Math.PI / 180, C, w;
  for (_ = 0; _ < g; _ += 1)
    for (C = Math.sin(_ * b), w = Math.cos(_ * b), y = 0; y < x; y += 1)
      A = Math.floor(o + v * y / x * w), u = Math.floor(h + v * y / x * C), l = (u * r + A) * 4, f = i[l + 0], d = i[l + 1], c = i[l + 2], p = i[l + 3], l = (_ + y * r) * 4, n[l + 0] = f, n[l + 1] = d, n[l + 2] = c, n[l + 3] = p;
}, pd = function(s, t, e) {
  var i = s.data, n = t.data, r = s.width, a = s.height, o = e.polarCenterX || r / 2, h = e.polarCenterY || a / 2, l, A, u, f, d, c = 0, p = 0, m = 0, v = 0, x, g = Math.sqrt(o * o + h * h);
  A = r - o, u = a - h, x = Math.sqrt(A * A + u * u), g = x > g ? x : g;
  var y = a, _ = r, b, C, w = 0, E, S;
  for (A = 0; A < r; A += 1)
    for (u = 0; u < a; u += 1)
      f = A - o, d = u - h, b = Math.sqrt(f * f + d * d) * y / g, C = (Math.atan2(d, f) * 180 / Math.PI + 360 + w) % 360, C = C * _ / 360, E = Math.floor(C), S = Math.floor(b), l = (S * r + E) * 4, c = i[l + 0], p = i[l + 1], m = i[l + 2], v = i[l + 3], l = (u * r + A) * 4, n[l + 0] = c, n[l + 1] = p, n[l + 2] = m, n[l + 3] = v;
};
const yd = function(s) {
  var t = s.width, e = s.height, i, n, r, a, o, h, l, A, u, f, d = Math.round(this.kaleidoscopePower()), c = Math.round(this.kaleidoscopeAngle()), p = Math.floor(t * (c % 360) / 360);
  if (!(d < 1)) {
    var m = Ta.Util.createCanvasElement();
    m.width = t, m.height = e;
    var v = m.getContext("2d").getImageData(0, 0, t, e);
    Ta.Util.releaseCanvas(m), gd(s, v, {
      polarCenterX: t / 2,
      polarCenterY: e / 2
    });
    for (var x = t / Math.pow(2, d); x <= 8; )
      x = x * 2, d -= 1;
    x = Math.ceil(x);
    var g = x, y = 0, _ = g, b = 1;
    for (p + x > t && (y = g, _ = 0, b = -1), n = 0; n < e; n += 1)
      for (i = y; i !== _; i += b)
        r = Math.round(i + p) % t, u = (t * n + r) * 4, o = v.data[u + 0], h = v.data[u + 1], l = v.data[u + 2], A = v.data[u + 3], f = (t * n + i) * 4, v.data[f + 0] = o, v.data[f + 1] = h, v.data[f + 2] = l, v.data[f + 3] = A;
    for (n = 0; n < e; n += 1)
      for (g = Math.floor(x), a = 0; a < d; a += 1) {
        for (i = 0; i < g + 1; i += 1)
          u = (t * n + i) * 4, o = v.data[u + 0], h = v.data[u + 1], l = v.data[u + 2], A = v.data[u + 3], f = (t * n + g * 2 - i - 1) * 4, v.data[f + 0] = o, v.data[f + 1] = h, v.data[f + 2] = l, v.data[f + 3] = A;
        g *= 2;
      }
    pd(v, s, { polarRotation: 0 });
  }
};
or.Kaleidoscope = yd;
cn.Factory.addGetterSetter(jo.Node, "kaleidoscopePower", 2, (0, qo.getNumberValidator)(), cn.Factory.afterSetFilter);
cn.Factory.addGetterSetter(jo.Node, "kaleidoscopeAngle", 0, (0, qo.getNumberValidator)(), cn.Factory.afterSetFilter);
var hr = {};
Object.defineProperty(hr, "__esModule", { value: !0 });
hr.Mask = void 0;
const Ia = H, md = st, vd = N;
function tn(s, t, e) {
  var i = (e * s.width + t) * 4, n = [];
  return n.push(s.data[i++], s.data[i++], s.data[i++], s.data[i++]), n;
}
function yi(s, t) {
  return Math.sqrt(Math.pow(s[0] - t[0], 2) + Math.pow(s[1] - t[1], 2) + Math.pow(s[2] - t[2], 2));
}
function _d(s) {
  for (var t = [0, 0, 0], e = 0; e < s.length; e++)
    t[0] += s[e][0], t[1] += s[e][1], t[2] += s[e][2];
  return t[0] /= s.length, t[1] /= s.length, t[2] /= s.length, t;
}
function xd(s, t) {
  var e = tn(s, 0, 0), i = tn(s, s.width - 1, 0), n = tn(s, 0, s.height - 1), r = tn(s, s.width - 1, s.height - 1), a = t || 10;
  if (yi(e, i) < a && yi(i, r) < a && yi(r, n) < a && yi(n, e) < a) {
    for (var o = _d([i, e, r, n]), h = [], l = 0; l < s.width * s.height; l++) {
      var A = yi(o, [
        s.data[l * 4],
        s.data[l * 4 + 1],
        s.data[l * 4 + 2]
      ]);
      h[l] = A < a ? 0 : 255;
    }
    return h;
  }
}
function bd(s, t) {
  for (var e = 0; e < s.width * s.height; e++)
    s.data[4 * e + 3] = t[e];
}
function wd(s, t, e) {
  for (var i = [1, 1, 1, 1, 0, 1, 1, 1, 1], n = Math.round(Math.sqrt(i.length)), r = Math.floor(n / 2), a = [], o = 0; o < e; o++)
    for (var h = 0; h < t; h++) {
      for (var l = o * t + h, A = 0, u = 0; u < n; u++)
        for (var f = 0; f < n; f++) {
          var d = o + u - r, c = h + f - r;
          if (d >= 0 && d < e && c >= 0 && c < t) {
            var p = d * t + c, m = i[u * n + f];
            A += s[p] * m;
          }
        }
      a[l] = A === 255 * 8 ? 255 : 0;
    }
  return a;
}
function Sd(s, t, e) {
  for (var i = [1, 1, 1, 1, 1, 1, 1, 1, 1], n = Math.round(Math.sqrt(i.length)), r = Math.floor(n / 2), a = [], o = 0; o < e; o++)
    for (var h = 0; h < t; h++) {
      for (var l = o * t + h, A = 0, u = 0; u < n; u++)
        for (var f = 0; f < n; f++) {
          var d = o + u - r, c = h + f - r;
          if (d >= 0 && d < e && c >= 0 && c < t) {
            var p = d * t + c, m = i[u * n + f];
            A += s[p] * m;
          }
        }
      a[l] = A >= 255 * 4 ? 255 : 0;
    }
  return a;
}
function Cd(s, t, e) {
  for (var i = [0.1111111111111111, 0.1111111111111111, 0.1111111111111111, 0.1111111111111111, 0.1111111111111111, 0.1111111111111111, 0.1111111111111111, 0.1111111111111111, 0.1111111111111111], n = Math.round(Math.sqrt(i.length)), r = Math.floor(n / 2), a = [], o = 0; o < e; o++)
    for (var h = 0; h < t; h++) {
      for (var l = o * t + h, A = 0, u = 0; u < n; u++)
        for (var f = 0; f < n; f++) {
          var d = o + u - r, c = h + f - r;
          if (d >= 0 && d < e && c >= 0 && c < t) {
            var p = d * t + c, m = i[u * n + f];
            A += s[p] * m;
          }
        }
      a[l] = A;
    }
  return a;
}
const Md = function(s) {
  var t = this.threshold(), e = xd(s, t);
  return e && (e = wd(e, s.width, s.height), e = Sd(e, s.width, s.height), e = Cd(e, s.width, s.height), bd(s, e)), s;
};
hr.Mask = Md;
Ia.Factory.addGetterSetter(md.Node, "threshold", 0, (0, vd.getNumberValidator)(), Ia.Factory.afterSetFilter);
var lr = {};
Object.defineProperty(lr, "__esModule", { value: !0 });
lr.Noise = void 0;
const Ra = H, Pd = st, Ed = N, Fd = function(s) {
  var t = this.noise() * 255, e = s.data, i = e.length, n = t / 2, r;
  for (r = 0; r < i; r += 4)
    e[r + 0] += n - 2 * n * Math.random(), e[r + 1] += n - 2 * n * Math.random(), e[r + 2] += n - 2 * n * Math.random();
};
lr.Noise = Fd;
Ra.Factory.addGetterSetter(Pd.Node, "noise", 0.2, (0, Ed.getNumberValidator)(), Ra.Factory.afterSetFilter);
var Ar = {};
Object.defineProperty(Ar, "__esModule", { value: !0 });
Ar.Pixelate = void 0;
const La = H, kd = rt, Dd = st, Td = N, Id = function(s) {
  var t = Math.ceil(this.pixelSize()), e = s.width, i = s.height, n, r, a, o, h, l, A, u = Math.ceil(e / t), f = Math.ceil(i / t), d, c, p, m, v, x, g, y = s.data;
  if (t <= 0) {
    kd.Util.error("pixelSize value can not be <= 0");
    return;
  }
  for (v = 0; v < u; v += 1)
    for (x = 0; x < f; x += 1) {
      for (o = 0, h = 0, l = 0, A = 0, d = v * t, c = d + t, p = x * t, m = p + t, g = 0, n = d; n < c; n += 1)
        if (!(n >= e))
          for (r = p; r < m; r += 1)
            r >= i || (a = (e * r + n) * 4, o += y[a + 0], h += y[a + 1], l += y[a + 2], A += y[a + 3], g += 1);
      for (o = o / g, h = h / g, l = l / g, A = A / g, n = d; n < c; n += 1)
        if (!(n >= e))
          for (r = p; r < m; r += 1)
            r >= i || (a = (e * r + n) * 4, y[a + 0] = o, y[a + 1] = h, y[a + 2] = l, y[a + 3] = A);
    }
};
Ar.Pixelate = Id;
La.Factory.addGetterSetter(Dd.Node, "pixelSize", 8, (0, Td.getNumberValidator)(), La.Factory.afterSetFilter);
var dr = {};
Object.defineProperty(dr, "__esModule", { value: !0 });
dr.Posterize = void 0;
const Oa = H, Rd = st, Ld = N, Od = function(s) {
  var t = Math.round(this.levels() * 254) + 1, e = s.data, i = e.length, n = 255 / t, r;
  for (r = 0; r < i; r += 1)
    e[r] = Math.floor(e[r] / n) * n;
};
dr.Posterize = Od;
Oa.Factory.addGetterSetter(Rd.Node, "levels", 0.5, (0, Ld.getNumberValidator)(), Oa.Factory.afterSetFilter);
var cr = {};
Object.defineProperty(cr, "__esModule", { value: !0 });
cr.RGB = void 0;
const un = H, Es = st, Nd = N, Gd = function(s) {
  var t = s.data, e = t.length, i = this.red(), n = this.green(), r = this.blue(), a, o;
  for (a = 0; a < e; a += 4)
    o = (0.34 * t[a] + 0.5 * t[a + 1] + 0.16 * t[a + 2]) / 255, t[a] = o * i, t[a + 1] = o * n, t[a + 2] = o * r, t[a + 3] = t[a + 3];
};
cr.RGB = Gd;
un.Factory.addGetterSetter(Es.Node, "red", 0, function(s) {
  return this._filterUpToDate = !1, s > 255 ? 255 : s < 0 ? 0 : Math.round(s);
});
un.Factory.addGetterSetter(Es.Node, "green", 0, function(s) {
  return this._filterUpToDate = !1, s > 255 ? 255 : s < 0 ? 0 : Math.round(s);
});
un.Factory.addGetterSetter(Es.Node, "blue", 0, Nd.RGBComponent, un.Factory.afterSetFilter);
var ur = {};
Object.defineProperty(ur, "__esModule", { value: !0 });
ur.RGBA = void 0;
const Ei = H, fr = st, Bd = N, zd = function(s) {
  var t = s.data, e = t.length, i = this.red(), n = this.green(), r = this.blue(), a = this.alpha(), o, h;
  for (o = 0; o < e; o += 4)
    h = 1 - a, t[o] = i * a + t[o] * h, t[o + 1] = n * a + t[o + 1] * h, t[o + 2] = r * a + t[o + 2] * h;
};
ur.RGBA = zd;
Ei.Factory.addGetterSetter(fr.Node, "red", 0, function(s) {
  return this._filterUpToDate = !1, s > 255 ? 255 : s < 0 ? 0 : Math.round(s);
});
Ei.Factory.addGetterSetter(fr.Node, "green", 0, function(s) {
  return this._filterUpToDate = !1, s > 255 ? 255 : s < 0 ? 0 : Math.round(s);
});
Ei.Factory.addGetterSetter(fr.Node, "blue", 0, Bd.RGBComponent, Ei.Factory.afterSetFilter);
Ei.Factory.addGetterSetter(fr.Node, "alpha", 1, function(s) {
  return this._filterUpToDate = !1, s > 1 ? 1 : s < 0 ? 0 : s;
});
var gr = {};
Object.defineProperty(gr, "__esModule", { value: !0 });
gr.Sepia = void 0;
const Ud = function(s) {
  var t = s.data, e = t.length, i, n, r, a;
  for (i = 0; i < e; i += 4)
    n = t[i + 0], r = t[i + 1], a = t[i + 2], t[i + 0] = Math.min(255, n * 0.393 + r * 0.769 + a * 0.189), t[i + 1] = Math.min(255, n * 0.349 + r * 0.686 + a * 0.168), t[i + 2] = Math.min(255, n * 0.272 + r * 0.534 + a * 0.131);
};
gr.Sepia = Ud;
var pr = {};
Object.defineProperty(pr, "__esModule", { value: !0 });
pr.Solarize = void 0;
const Hd = function(s) {
  var t = s.data, e = s.width, i = s.height, n = e * 4, r = i;
  do {
    var a = (r - 1) * n, o = e;
    do {
      var h = a + (o - 1) * 4, l = t[h], A = t[h + 1], u = t[h + 2];
      l > 127 && (l = 255 - l), A > 127 && (A = 255 - A), u > 127 && (u = 255 - u), t[h] = l, t[h + 1] = A, t[h + 2] = u;
    } while (--o);
  } while (--r);
};
pr.Solarize = Hd;
var yr = {};
Object.defineProperty(yr, "__esModule", { value: !0 });
yr.Threshold = void 0;
const Na = H, Vd = st, $d = N, Wd = function(s) {
  var t = this.threshold() * 255, e = s.data, i = e.length, n;
  for (n = 0; n < i; n += 1)
    e[n] = e[n] < t ? 0 : 255;
};
yr.Threshold = Wd;
Na.Factory.addGetterSetter(Vd.Node, "threshold", 0.5, (0, $d.getNumberValidator)(), Na.Factory.afterSetFilter);
Object.defineProperty(In, "__esModule", { value: !0 });
In.Konva = void 0;
const Ga = xo, Yd = Ln, Xd = Gn, jd = bn, qd = zn, Qd = Un, Ba = Ze, Kd = Li, Zd = ni, Jd = Oi, tc = Vn, ec = $n, ic = Wn, nc = Yn, rc = Se, sc = Xn, ac = jn, oc = qn, hc = Kn, lc = Zn, Ac = Jn, dc = tr, cc = ir, uc = nr, fc = rr, gc = sr, pc = ar, yc = or, mc = hr, vc = lr, _c = Ar, xc = dr, bc = cr, wc = ur, Sc = gr, Cc = pr, Mc = yr;
In.Konva = Ga.Konva.Util._assign(Ga.Konva, {
  Arc: Yd.Arc,
  Arrow: Xd.Arrow,
  Circle: jd.Circle,
  Ellipse: qd.Ellipse,
  Image: Qd.Image,
  Label: Ba.Label,
  Tag: Ba.Tag,
  Line: Kd.Line,
  Path: Zd.Path,
  Rect: Jd.Rect,
  RegularPolygon: tc.RegularPolygon,
  Ring: ec.Ring,
  Sprite: ic.Sprite,
  Star: nc.Star,
  Text: rc.Text,
  TextPath: sc.TextPath,
  Transformer: ac.Transformer,
  Wedge: oc.Wedge,
  Filters: {
    Blur: hc.Blur,
    Brighten: lc.Brighten,
    Contrast: Ac.Contrast,
    Emboss: dc.Emboss,
    Enhance: cc.Enhance,
    Grayscale: uc.Grayscale,
    HSL: fc.HSL,
    HSV: gc.HSV,
    Invert: pc.Invert,
    Kaleidoscope: yc.Kaleidoscope,
    Mask: mc.Mask,
    Noise: vc.Noise,
    Pixelate: _c.Pixelate,
    Posterize: xc.Posterize,
    RGB: bc.RGB,
    RGBA: wc.RGBA,
    Sepia: Sc.Sepia,
    Solarize: Cc.Solarize,
    Threshold: Mc.Threshold
  }
});
var Pc = gs.exports;
Object.defineProperty(Pc, "__esModule", { value: !0 });
const Ec = In;
gs.exports = Ec.Konva;
var Fc = gs.exports;
const $t = /* @__PURE__ */ uh(Fc);
function Fs(s) {
  return { all: s = s || /* @__PURE__ */ new Map(), on: function(t, e) {
    var i = s.get(t);
    i ? i.push(e) : s.set(t, [e]);
  }, off: function(t, e) {
    var i = s.get(t);
    i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : s.set(t, []));
  }, emit: function(t, e) {
    var i = s.get(t);
    i && i.slice().map(function(n) {
      n(e);
    }), (i = s.get("*")) && i.slice().map(function(n) {
      n(t, e);
    });
  } };
}
class me {
  constructor(t) {
    this.bus = Fs(), this.children = [], this.isMounted = !1, this.name = t.name, this.teleport = t.teleport, this.props = t, this.attrib = t.reactive ? Ti(t.attrib) : t.attrib, this.zIndex = t.zIndex || 0;
  }
  getShape() {
    return this.shape;
  }
  redraw() {
    this.diffRedraw(), this.children.forEach((t) => t.redraw());
  }
  setAttrib(t) {
    this.attrib = rn(
      { ...t, id: this.attrib.id },
      this.attrib
    ), this.props.reactive || this.diffRedraw(), console.error("setAttrib");
  }
  initReactive(t = "pre") {
    this.destoryReactive && this.destoryReactive();
    let e = !1;
    const i = xn(
      () => {
        e || this.diffRedraw();
      },
      { flush: t }
    );
    return () => {
      e = !0, i();
    };
  }
  init() {
    this.shape = this.initShape(), this.shape.id(this.name), this.bus.emit("created");
  }
  mount(t) {
    if (this.shape instanceof Pi.Stage)
      throw "stage 为顶级容器无法挂载";
    if (t && this.shape instanceof ps && !(t instanceof Pi.Stage))
      throw console.log(this.name, t), "layer 只能挂载到 Stage";
    if (this.teleport && this.teleport === t)
      return;
    this.children.sort((i, n) => i.zIndex - n.zIndex);
    const e = t || this.parent.shape;
    if (e.add(this.shape), this.teleport = e, this.setZIndex(this.zIndex), this.props.reactive && (this.destoryReactive = this.initReactive()), jt) {
      let i = { ...this.attrib };
      Me(
        () => this.attrib.id,
        (n, r) => {
          n !== r && console.error("changeId", i, this.attrib, n, r);
        },
        { flush: "sync" }
      );
    }
  }
  mounted() {
    this.diffRedraw(), this.children.forEach((t) => t.mounted()), this.isMounted = !0, this.bus.emit("mounted");
  }
  setParent(t) {
    if (this.parent) {
      const e = this.parent.children.indexOf(this);
      ~e && this.parent.children.splice(e, 1);
    }
    this.parent = t, t && this.parent.children.push(this);
  }
  getLevelNdx(t = this.parent) {
    if (t) {
      const e = t.children;
      for (let i = e.length - 1; i >= 0; i--)
        if (e[i] !== this && e[i].zIndex <= this.zIndex)
          return i;
      return -1;
    }
    return null;
  }
  setZIndex(t) {
    this.zIndex = t;
    const e = this.getLevelNdx();
    if (e === null)
      return;
    const i = this.parent.children;
    if (i.indexOf(this) !== e + 1) {
      let l = this;
      for (let A = e + 1; A < i.length; A++) {
        const u = i[A];
        i[A] = l, l = u;
      }
    }
    const r = this.teleport, a = r.children, o = e === -1 ? 0 : a.indexOf(i[e].getShape()) + 1;
    if (a.indexOf(this.shape) !== o)
      if (o !== 0) {
        let l = this.shape;
        for (let A = o; A < a.length; A++) {
          const u = a[A];
          r.add(l), l.zIndex(A), l = u;
        }
      } else
        this.shape.zIndex(0);
  }
  enableDrag(t) {
    this.disableDrag(), this.dragDestory = cs(this.shape, t);
  }
  disableDrag() {
    this.dragDestory && this.dragDestory(), this.dragDestory = null;
  }
  enableActive(t) {
    this.disableActive(), this.activeDestory = ua(
      this.shape,
      {
        active: () => t(!0),
        bus: this.bus,
        common: () => t(!1)
      },
      "mouse-active"
    );
  }
  disableActive() {
    this.activeDestory && this.activeDestory(), this.activeDestory = null;
  }
  enableMouseAct(t) {
    this.disableMouseAct(), this.mouseActDestory = ua(
      this.shape,
      { ...t, bus: this.bus },
      "act-mouse"
    );
  }
  disableMouseAct() {
    this.mouseActDestory && this.mouseActDestory(), this.mouseActDestory = null;
  }
  destory() {
    this.setParent(null), this.destoryReactive && this.destoryReactive(), this.disableDrag(), this.disableActive(), this.disableActive(), jt && console.log(this.name, "destory"), this.shape instanceof $t.Group ? this.shape.destroyChildren() : this.shape.destroy(), this.bus.emit("destroyed"), this.bus.off("*");
  }
  find(t) {
    for (const e of this.children) {
      if (e.name === t)
        return e;
      const i = e.find(t);
      if (i)
        return i;
    }
    return null;
  }
}
const fn = class fn extends me {
  constructor(t) {
    t.zIndex = t.zIndex || 4, t.name = t.name || fn.namespace + t.attrib.id, super(t);
  }
  setConfig(t) {
    this.config = t;
  }
  initShape() {
    const t = new $t.Label({
      opacity: 0.75,
      name: "label",
      listening: !1
    });
    t.add(
      new $t.Tag({
        name: "tag",
        fill: "rgba(0, 0, 0, 0.8)",
        pointerDirection: "down",
        pointerWidth: 5,
        pointerHeight: 5,
        lineJoin: "round",
        shadowColor: "black",
        shadowBlur: 10,
        shadowOffsetX: 10,
        shadowOffsetY: 10,
        shadowOpacity: 0.5,
        listening: !1
      }),
      new $t.Text({
        name: "text",
        text: "text",
        fontFamily: "Calibri",
        fontSize: 10,
        padding: 3,
        fill: "white",
        listening: !1
      })
    );
    const e = 8, i = new Yt({ name: "offset" });
    return i.add(t).add(
      new $t.Arrow({
        name: "arrow-1",
        visible: !1,
        points: [0, 0],
        pointerLength: e,
        pointerWidth: e,
        fill: "black",
        stroke: "black",
        strokeWidth: 4,
        listening: !1
      }),
      new $t.Arrow({
        name: "arrow-2",
        visible: !1,
        points: [0, 0],
        pointerLength: e,
        pointerWidth: e,
        fill: "black",
        stroke: "black",
        strokeWidth: 4,
        listening: !1
      })
    ), i;
  }
  diffRedraw() {
    const t = this.attrib.pointIds.map(
      (o) => this.config.points.find((h) => h.id === o)
    );
    if (t.some((o) => !o))
      return null;
    let e = !1;
    const i = [];
    for (const o of this.config.polygons)
      for (const h of o.lineIds) {
        const l = this.config.lines.find(({ id: A }) => A === h);
        l.pointIds.includes(this.attrib.pointIds[0]) && l.pointIds.includes(this.attrib.pointIds[1]) && (i.push(`${l.id} [${l.pointIds.join(",")}]`), e = e || l.pointIds[0] === this.attrib.pointIds[1]);
      }
    const n = [];
    t.forEach(({ x: o, y: h }, l) => {
      n[l * 2] = o, n[l * 2 + 1] = h;
    });
    let r = Nt(
      this.shape.findOne(".label"),
      [1, 1]
    );
    const a = be.radToDeg(wA(n, [0, 1]));
    this.shape.findOne(".label").x((n[0] + n[2]) / 2).y((n[1] + n[3]) / 2).scale({ x: r[0], y: r[1] }).rotation(a < 0 ? a + 90 : a - 90), this.shape.findOne(".arrow-1").x(n[2]).y(n[3]).scale({ x: r[0], y: r[1] }).rotation(a + 90).visible(!0), e ? this.shape.findOne(".arrow-2").x(n[0]).y(n[1]).rotation(a - 90).scale({ x: r[0], y: r[1] }).visible(!0) : this.shape.findOne(".arrow-2").visible(!1), this.shape.findOne(".text").text(i.join(" | "));
  }
};
fn.namespace = "line-helper";
let Jr = fn;
const gn = class gn extends me {
  constructor(t) {
    t.zIndex = t.zIndex || 5, t.name = t.name || gn.namespace + t.attrib.id, super(t);
  }
  initShape() {
    const t = new $t.Label({ opacity: 0.75, name: "label" });
    return t.add(
      new $t.Tag({
        name: "tag",
        fill: "rgba(0, 0, 0, 0.8)",
        pointerDirection: "down",
        pointerWidth: 5,
        pointerHeight: 5,
        lineJoin: "round",
        shadowColor: "black",
        shadowBlur: 10,
        shadowOffsetX: 10,
        shadowOffsetY: 10,
        shadowOpacity: 0.5
      }),
      new $t.Text({
        name: "text",
        text: `P${this.attrib.id}`,
        fontFamily: "Calibri",
        fontSize: 10,
        padding: 3,
        fill: "white"
      })
    ), t;
  }
  diffRedraw() {
    this.shape.x(this.attrib.x).y(this.attrib.y);
    const t = Nt(this.shape, [1, 1]);
    this.shape.scale({ x: t[0], y: t[0] });
  }
};
gn.namespace = "point-helper";
let ts = gn;
const pn = class pn extends me {
  constructor(t) {
    t.zIndex = t.zIndex || Mt.zIndex, t.name = t.name || pn.namespace + t.attrib.id, super(t), this.actShapeFactory = Dn;
  }
  setActShapeFactory(t) {
    this.actShapeFactory = t;
  }
  initShape() {
    return this.actShape = this.actShapeFactory(this.attrib, this), this.actShape.shape;
  }
  diffRedraw() {
    this.actShape.setData([this.attrib.x, this.attrib.y]);
  }
  mounted() {
    super.mounted(), this.actShape.common(null);
  }
};
pn.namespace = "point";
let Rt = pn;
const Qo = (s) => (Math.max(1, ...s.lines.map(({ id: t }) => Number(t))) + 1).toString(), Ko = (s) => (Math.max(1, ...s.points.map(({ id: t }) => Number(t))) + 1).toString(), Zo = (s, t = []) => (Math.max(
  1,
  ...s.polygons.map(({ id: e }) => Number(e)),
  ...t.map(Number)
) + 1).toString(), Ce = (s, t) => s.points.find((e) => e.id === t), _t = (s, t) => t ? t.map((e) => Ce(s, e)) : s.points, Jo = (s, t) => s.lines.filter(({ pointIds: e }) => e.includes(t)), kc = (s, t, e = !1) => s.lines.filter(({ pointIds: i }) => {
  let n = i.includes(t[0]) && i.includes(t[1]);
  return n || (e && (n = i.includes(t[1]) && i.includes(t[0])), n);
}), Dc = (s, t) => Jo(s, t.id), wt = (s, t) => s.lines.find(({ id: e }) => e === t), th = (s, t) => t.map((e) => wt(s, e)), di = (s, t) => _t(s, wt(s, t).pointIds), qu = (s) => s.lines.map((t) => _t(s, t.pointIds)), ci = (s, t) => s.polygons.find((e) => e.id === t), Tc = (s, t) => ci(s, t).lineIds.map(
  (e) => di(s, e)
), eh = (s, t) => {
  const e = ci(s, t);
  return e ? e.lineIds.map(
    (i) => wt(s, i)
  ) : [];
}, Qu = (s, t) => s.lines.filter(({ pointIds: e }) => e.includes(t)).map((e) => di(s, e.id)), ih = (s, t) => {
  const e = [];
  for (const i of s.polygons) {
    const n = i.lineIds.filter(
      (r) => wt(s, r).pointIds.includes(t)
    ).map((r) => di(s, r));
    n.length && e.push({
      polygonId: i.id,
      lines: n
    });
  }
  return e;
}, Ku = (s, t) => s.polygons.filter((e) => e.lineIds.some(
  (i) => wt(s, i).pointIds.includes(t)
)), Fi = (s, t) => {
  const e = ci(s, t);
  if (!e)
    return [];
  const { lineIds: i } = e, n = [];
  for (let r = 0; r < i.length; r++) {
    const a = wt(s, i[r]);
    n.push(Ce(s, a.pointIds[0])), r === i.length - 1 && n.push(Ce(s, a.pointIds[1]));
  }
  return n;
}, vi = (...s) => {
  const t = {};
  for (const e of s)
    for (const i in e)
      if (!t[i])
        t[i] = Object.fromEntries(
          Object.entries(e[i]).map(([n, r]) => [
            n,
            [...r]
          ])
        );
      else
        for (const n in e[i]) {
          if (!t[i][n]) {
            t[i][n] = [...e[i][n]];
            break;
          }
          const r = e[i][n], a = t[i][n];
          for (const o of r)
            a.every(({ id: h }) => h !== o.id) && a.push(o);
        }
  return t;
}, nh = (s, t) => s.lines.findIndex(
  ({ pointIds: e }) => e[0] === t[0] && e[1] === t[1]
), ce = (s, t) => {
  const e = {
    lineChange: { add: [] }
  };
  let i = nh(s, t);
  return ~i || (i = s.lines.push({
    id: Qo(s),
    pointIds: [...t]
  }) - 1, e.lineChange.add.push(s.lines[i])), { line: s.lines[i], change: e };
}, ei = (s, t, e = !0) => {
  const i = {
    lineChange: { del: [] },
    pointChange: { del: [] }
  }, n = nh(s, t), r = s.lines[n];
  return ~n ? (s.polygons.every(
    ({ lineIds: o }) => !o.includes(r.id)
  ) && (s.lines.splice(n, 1), i.lineChange.del.push(r)), e && t.forEach((o) => {
    const h = s.points.findIndex(({ id: l }) => l === o);
    ~h && s.lines.every(({ pointIds: l }) => !l.includes(o)) && (i.pointChange.del.push(s.points[h]), s.points.splice(h, 1));
  }), { line: r, change: i }) : { change: i };
}, rh = (s, t) => {
  const e = s.polygons.findIndex(({ id: i }) => t === i);
  if (~e) {
    const i = s.polygons[e];
    s.polygons.splice(e, 1), i.lineIds.map(
      (r) => wt(s, r)
    ).forEach((r) => {
      ei(s, r.pointIds);
    });
  }
}, za = (s, t, e = !0) => {
  t = Array.isArray(t) ? t : [t];
  const i = {
    lineChange: {
      del: [],
      add: []
    },
    polygonChange: {
      update: [],
      del: []
    },
    pointChange: {
      del: []
    }
  };
  let n = 100;
  for (let r = 0; r < s.polygons.length; r++) {
    const a = s.polygons[r], o = a.lineIds;
    let h = o.length, l;
    for (let A = 0; A < h; A++) {
      const u = th(s, o), f = u[A], d = t.includes(f.pointIds[0]), c = t.includes(f.pointIds[1]);
      if (!(d || c))
        continue;
      l = l || [...o];
      let p = A, m = null;
      if (c) {
        let v = A + 1;
        for (v; v < u.length; v++) {
          const x = u[v].pointIds[1];
          if (!t.includes(x) && x !== f.pointIds[0])
            break;
        }
        if (v !== u.length) {
          const x = ce(s, [
            f.pointIds[0],
            u[v].pointIds[1]
          ]);
          i.lineChange.add.push(...x.change.lineChange.add), o[A] = x.line.id, m = x.line.id;
        }
      }
      if (~p) {
        const v = u[A].pointIds;
        m ? o.splice(A, 1, m) : (o.splice(A, 1), u.splice(A, 1), h--, A--);
        const x = ei(
          s,
          v,
          e
        );
        if (i.lineChange.del.push(...x.change.lineChange.del), i.pointChange.del.push(...x.change.pointChange.del), n-- < 0)
          break;
      }
    }
    if (l) {
      const A = { ...a, lineIds: l };
      a.lineIds.length === 0 ? (s.polygons.splice(r--, 1), i.polygonChange.del.push(A)) : i.polygonChange.update.push({
        before: A,
        after: a
      });
    }
  }
  return e && t.forEach((r) => {
    if (!i.pointChange.del.some(({ id: a }) => a === r)) {
      const a = s.points.findIndex(({ id: o }) => o === r);
      ~a && (i.pointChange.del.push(s.points[a]), s.points.splice(a, 1));
    }
  }), i;
}, es = (s, t, e) => {
  const i = {
    lineChange: {
      del: [],
      add: []
    },
    polygonChange: {
      update: []
    },
    pointChange: {
      add: [],
      del: []
    }
  };
  let n = null;
  const r = t.map((a) => a.id);
  if (r.includes(e))
    return { addedPoints: n, change: i };
  for (const a of s.polygons) {
    let o;
    for (let h = 0; h < a.lineIds.length; h++) {
      const l = wt(s, a.lineIds[h]);
      if (r.includes(l.pointIds[0]) && r.includes(l.pointIds[1])) {
        o = o || [...a.lineIds], n = n || [
          l.pointIds[0],
          e,
          l.pointIds[1]
        ];
        const A = ce(s, [
          l.pointIds[0],
          e
        ]), u = ce(s, [
          e,
          l.pointIds[1]
        ]);
        i.lineChange.add.push(
          ...A.change.lineChange.add,
          ...u.change.lineChange.add
        ), a.lineIds.splice(h, 1, A.line.id, u.line.id);
        const f = ei(s, l.pointIds);
        i.lineChange.del.push(...f.change.lineChange.del), i.pointChange.del.push(...f.change.pointChange.del);
      }
    }
    o && i.polygonChange.update.push({
      before: { ...a, lineIds: o },
      after: a
    });
  }
  return { addedPoints: n, change: i };
}, is = (s, t, e) => {
  const i = {
    pointChange: {
      del: []
    },
    lineChange: {
      del: [],
      add: [],
      update: []
    },
    polygonChange: {
      del: [],
      update: []
    }
  }, n = [];
  for (let r = 0; r < s.polygons.length; r++) {
    const a = s.polygons[r];
    let o;
    for (const h of t) {
      if (h === e)
        break;
      for (let l = 0; l < a.lineIds.length; l++) {
        const A = wt(s, a.lineIds[l]);
        let u = A.pointIds.indexOf(h);
        if (!~u)
          continue;
        o = o || [...a.lineIds];
        const f = [...A.pointIds];
        if (f[u] = e, f[0] === f[1])
          a.lineIds.splice(l, 1);
        else {
          const d = ce(s, f);
          a.lineIds[l] = d.line.id, i.lineChange.del.push(...d.change.lineChange.add);
        }
        n.push(A.pointIds), l--;
      }
      if (o) {
        const l = { ...a, lineIds: o };
        a.lineIds.length === 0 ? (i.polygonChange.del.push(l), s.polygons.splice(r--, 1), console.log("del polygon")) : i.polygonChange.update.push({
          before: l,
          after: a
        });
      }
    }
  }
  return n.forEach((r) => {
    const a = ei(s, r);
    i.lineChange.del.push(...a.change.lineChange.del), i.pointChange.del.push(...a.change.pointChange.del);
  }), i;
}, Ic = (s, t, e, i) => {
  const n = {
    lineChange: {
      update: [],
      add: []
    },
    polygonChange: {
      update: []
    }
  }, r = kc(
    s,
    t.map(({ id: h }) => h),
    !0
  );
  s.lines.forEach((h) => {
    let l = -1;
    if (r.includes(h) || !~(l = h.pointIds.indexOf(e)))
      return;
    const A = [...h.pointIds];
    A[l] = i, n.lineChange.update.push({
      before: { ...h, pointIds: [...h.pointIds] },
      after: { ...h, pointIds: [...A] }
    }), h.pointIds = A;
  });
  let a, o;
  for (const h of s.polygons) {
    let l;
    for (let A = 0; A < h.lineIds.length; A++) {
      if (!r.some(({ id: v }) => v === h.lineIds[A]))
        continue;
      const f = wt(s, h.lineIds[A]).pointIds.indexOf(e) === 1, d = ((f ? A + 1 : A - 1) + h.lineIds.length) % h.lineIds.length, c = wt(s, h.lineIds[d]);
      if (f ? c.pointIds[0] === e : c.pointIds[1] === e)
        continue;
      l = l || [...h.lineIds];
      let p;
      if (f) {
        if (!o) {
          const { line: v, change: x } = ce(s, [
            e,
            i
          ]);
          x.lineChange.add.push(...x.lineChange.add), o = v;
        }
        p = o;
      } else {
        if (!a) {
          const { line: v, change: x } = ce(s, [
            i,
            e
          ]);
          x.lineChange.add.push(...x.lineChange.add), a = v;
        }
        p = a;
      }
      const m = f ? A + 1 : A;
      h.lineIds.splice(m, 0, p.id);
    }
    l && n.polygonChange.update.push({
      before: { ...h, lineIds: l },
      after: h
    });
  }
  return { change: n };
}, yn = class yn extends me {
  constructor(t) {
    t.zIndex = t.zIndex || Xe.zIndex, t.name = t.name || yn.namespace + t.attrib.id, super(t), this.actShapeFactory = hi;
  }
  setActShapeFactory(t) {
    this.actShapeFactory = t;
  }
  initShape() {
    return this.actShape = this.actShapeFactory(this.attrib, this), this.actShape.shape;
  }
  diffRedraw() {
    const t = this.getCoords();
    t.length ? this.actShape.setData(t) : console.error("line:", this.attrib, "找不到对应的点坐标", [
      ...this.config.points
    ]);
  }
  setConfig(t) {
    this.config = t;
  }
  getCoords() {
    const t = [], e = _t(this.config, this.attrib.pointIds);
    return e.some((i) => !i) || e.forEach(({ x: i, y: n }, r) => {
      t[r * 2] = i, t[r * 2 + 1] = n;
    }), t;
  }
  initReactive() {
    return super.initReactive("post");
  }
  mounted() {
    super.mounted(), this.actShape.common(null);
  }
};
yn.namespace = "line";
let qt = yn;
const mn = class mn extends me {
  constructor(t) {
    t.zIndex = t.zIndex || An.zIndex, t.name = t.name || mn.namespace + t.attrib.id, super(t), this.actShapeFactory = Tn;
  }
  setActShapeFactory(t) {
    this.actShapeFactory = t;
  }
  initShape() {
    return this.actShape = this.actShapeFactory(this.attrib, this), this.actShape.shape;
  }
  diffRedraw() {
    this.actShape.setData(this.getCoords());
  }
  setConfig(t) {
    this.config = t;
  }
  getCoords() {
    const t = [], e = Fi(this.config, this.attrib.id);
    return e.some((i) => !i) || e.forEach(({ x: i, y: n }, r) => {
      t[r * 2] = i, t[r * 2 + 1] = n;
    }), t;
  }
  mounted() {
    super.mounted(), this.actShape.common(null);
  }
};
mn.namespace = "polygon";
let ki = mn;
const vn = class vn extends me {
  constructor(t) {
    t.name = t.name || vn.namespace + t.attrib.id, super(t);
  }
  initIncFactory() {
    this.incLinesFactory = Pt(
      qt,
      this,
      (t) => {
        t.setConfig(this.attrib);
      }
    ), this.incPointsFactory = Pt(
      Rt,
      this
    ), this.incPolygonFactory = Pt(
      ki,
      this,
      (t) => {
        t.setConfig(this.attrib);
      }
    ), jt && (this.incLinesHelperFactory = Pt(
      Jr,
      this,
      (t) => {
        t.setConfig(this.attrib);
      }
    ), this.incPointsHelperFactory = Pt(
      ts,
      this
    ));
  }
  init() {
    this.initIncFactory(), super.init();
  }
  initShape() {
    return new Yt({ id: this.name });
  }
  getRedrawLines() {
    const t = [];
    for (let e = this.attrib.lines.length - 1; e >= 0; e--) {
      const i = this.attrib.lines[e];
      let n = 0;
      for (n = 0; n < e; n++) {
        const r = this.attrib.lines[n];
        if (r.pointIds.includes(i.pointIds[0]) && r.pointIds.includes(i.pointIds[1]))
          break;
      }
      e === n && t.push(i);
    }
    return t;
  }
  diffRedraw() {
    const t = this.getRedrawLines();
    jt && (this.incLinesHelperFactory(t), this.incPointsHelperFactory(this.attrib.points));
    const e = this.incPointsFactory(this.attrib.points), i = this.incLinesFactory(t), n = this.incPolygonFactory(
      this.attrib.polygons
    );
    return { lineEntityInc: i, pointEntityInc: e, polygonEntityInc: n };
  }
  initReactive() {
    return Me(
      () => ({
        pointIds: this.attrib.points.map(({ id: t }) => t),
        lineIds: this.attrib.lines.map(({ id: t }) => t)
      }),
      this.diffRedraw.bind(this),
      { immediate: !0, flush: "pre" }
    );
  }
};
vn.namespace = "whole-line";
let Di = vn, Xt;
const Rc = () => {
  const s = {}, t = {}, e = (n, r) => {
    s[n] = r, t[n] = r;
  }, i = (n) => {
    for (const r in s)
      s[r] = t[r] / n;
  };
  return e("WHOLE_LINE_POINT_EQ_DIST", 1e-3), e("WHOLE_LINE_POINT_MERGE_DIST", 10), e("WHOLE_LINE_POINT_CHECK_DIST", 500), {
    addConstant: e,
    updateConstantScale: i,
    use() {
      Xt = s;
    },
    unuse() {
      Xt === s && (Xt = null);
    }
  };
}, Qe = (s, t) => {
  const e = "id" in t && t.id ? t.id : Ko(s);
  if (s.points.some(({ id: i }) => i === e))
    return t;
  {
    const i = {
      ...t,
      id: e
    };
    return s.points.push(i), i;
  }
}, Lc = (s, t, e) => {
  const i = di(s, t), n = Gi(
    i.flatMap(({ x: h, y: l }) => [h, l]),
    [e.x, e.y]
  ).point, r = Qe(s, {
    ...e,
    x: n[0],
    y: n[1]
  }), { change: a, addedPoints: o } = es(
    s,
    i,
    r.id
  );
  return a.pointChange.add.push(r), { change: a, addedPoints: o };
}, Oc = (s, t, e) => {
  const i = ci(s, t);
  return Nc(
    s,
    t,
    i.lineIds[i.lineIds.length - 1],
    e
  );
}, Nc = (s, t, e, i) => {
  const n = ci(s, t), r = di(s, e), a = Qe(s, i);
  let { line: o, change: h } = ce(s, [
    r[1].id,
    a.id
  ]);
  return h = vi(h, {
    pointChange: {
      add: [a]
    },
    polygonChange: {
      update: [
        {
          before: { ...n, lineIds: [...n.lineIds] },
          after: {
            ...n,
            lineIds: [...n.lineIds, o.id]
          }
        }
      ]
    }
  }), n.lineIds.push(o.id), { line: o, change: h };
}, Gc = (s) => {
  let t = Math.max(...s.points.map((e) => Number(e.id) || 0));
  return (e) => {
    const i = {
      ...e,
      id: (++t).toString()
    };
    return s.points.push(i), i;
  };
}, Bc = (s) => {
  const t = (o) => [o[0].x, o[0].y, o[1].x, o[1].y].join("-"), e = {}, i = (o, h) => [t(o), t(h)].join("-"), n = {}, r = [], a = Gc(s);
  return (o) => {
    let h;
    const l = t(o);
    if (h = e[l])
      return h;
    if (h = e[t([o[1], o[0]])])
      return h = [...h].reverse(), e[l] = h, h;
    h = [];
    const A = o;
    for (const f of s.polygons) {
      const d = Tc(s, f.id);
      for (const c of d) {
        const p = i(o, c), m = {
          polygonId: f.id,
          line: c
        };
        if (p in n)
          n[p] && h.push({
            passive: m,
            intersection: n[p]
          });
        else {
          const v = c, x = go(
            [A[0].x, A[0].y, A[1].x, A[1].y],
            [v[0].x, v[0].y, v[1].x, v[1].y],
            [fo.Intersect]
          );
          if (x) {
            jt && console.log("join split", A[0].id, A[1].id, v[0].id, v[1].id);
            let g = -1, y = Number.MAX_VALUE;
            for (let b = 0; b < r.length; b++) {
              const C = [r[b].x, r[b].y], w = Et(C, x);
              y > w && (g = b, y = w);
            }
            let _;
            y <= Xt.WHOLE_LINE_POINT_EQ_DIST ? _ = r[g] : (_ = a({ x: x[0], y: x[1] }), console.log("add", _.id), r.push(_)), h.push({
              passive: m,
              intersection: _
            }), n[p] = _;
          } else
            n[p] = null;
        }
      }
    }
    const u = [A[0].x, A[0].y];
    return h.sort(
      (f, d) => Et([f.intersection.x, f.intersection.y], u) - Et([d.intersection.x, d.intersection.y], u)
    ), e[l] = h, h;
  };
}, Ua = (s, t, e, i) => {
  const n = s.map(({ id: h }) => h);
  if (!(n.includes(e[0].id) && n.includes(e[1].id)))
    return s;
  let a = Number.MAX_VALUE, o = -1;
  for (let h = 1; h < i.length; h++) {
    const l = [i[h - 1], i[h]], A = MA(
      [l[0].x, l[0].y, l[1].x, l[1].y],
      [t.x, t.y]
    );
    A < a && (a = A, o = h);
  }
  return ~o ? s[0] === s[0] ? [i[o - 1], i[o]] : [i[o], i[o - 1]] : s;
}, zc = (s, t) => {
  const e = Bc(s), i = [];
  for (let n = 1; n < t.length; n++) {
    let r = 0;
    for (; r < n && !(t[n].includes(t[r][0]) && t[n].includes(t[r][1])); r++)
      ;
    r !== n && t.splice(n--, 1);
  }
  for (const n of t) {
    const r = e(n), a = n;
    r.forEach((o) => {
      const h = [...o.passive.line];
      i.some((A) => {
        if (o.intersection.id !== A.intersection.id)
          return !1;
        const u = [...A.passive], f = [...A.splitLine];
        return f.includes(a[0]) && f.includes(a[1]) && u.includes(h[0]) && u.includes(h[1]) || u.includes(a[0]) && u.includes(a[1]) && f.includes(h[0]) && f.includes(h[1]);
      }) || i.push({
        splitLine: n,
        passive: o.passive.line,
        intersection: o.intersection
      });
    });
  }
  for (let n = 0; n < i.length; n++) {
    const { passive: r, splitLine: a, intersection: o } = i[n], h = es(
      s,
      a,
      o.id
    ).addedPoints, l = es(
      s,
      r,
      o.id
    ).addedPoints;
    if (jt && (h || console.error(
      `添加 addedPointIds 失败， 
交点：`,
      o.id,
      `
 线段：`,
      a
    ), l || console.error(
      `添加 passiveAddedPointIds 失败， 
交点：`,
      o,
      `
线段：`,
      r
    )), !h && !l)
      continue;
    const A = h && _t(s, h), u = l && _t(s, l), f = (d, c) => {
      const p = d;
      return h && (d = Ua(
        d,
        c,
        a,
        A
      )), l && (d = Ua(
        d,
        c,
        r,
        u
      )), jt && p !== d && console.log(
        "fix line",
        p.map(({ id: m }) => m),
        `
after: ,`,
        d.map(({ id: m }) => m)
      ), d;
    };
    for (let d = n + 1; d < i.length; d++) {
      const c = i[d];
      c.passive = f(c.passive, c.intersection), c.splitLine = f(c.splitLine, c.intersection);
    }
  }
}, Or = (s, t) => zc(
  s,
  ih(s, t).reduce((e, i) => (e.push(...i.lines), e), [])
), Uc = (s, t) => {
  const e = [t], i = s.points.filter(
    (n) => !e.includes(n) && Et([n.x, n.y], [t.x, t.y]) < Xt.WHOLE_LINE_POINT_MERGE_DIST
  );
  return i.length ? i.length > 1 ? {
    main: t,
    merges: i,
    mergeAfterPosition: [t.x, t.y]
  } : {
    main: i[0],
    merges: [t],
    mergeAfterPosition: [i[0].x, i[0].y]
  } : null;
}, Hc = (s, t) => {
  const e = Uc(
    s,
    Ce(s, t)
  );
  if (!e)
    return;
  const i = is(
    s,
    e.merges.map(({ id: r }) => r),
    e.main.id
  ), n = Ce(s, e.main.id);
  return n && (n.x = e.mergeAfterPosition[0], n.y = e.mergeAfterPosition[1]), {
    info: e,
    change: i
  };
}, Vc = (s, t, e, i = [10, 170]) => {
  const n = {}, r = t.pointIds, a = _t(s, [r[0], r[1]]), o = Ae([
    a[0].x,
    a[0].y,
    a[1].x,
    a[1].y
  ]), h = _t(s, [r[1], r[0]]), l = Ae([
    h[0].x,
    h[0].y,
    h[1].x,
    h[1].y
  ]), A = (u, f) => {
    let d = !0;
    const c = r[f];
    if (!n[c])
      n[c] = {};
    else
      return d = !1, { ...n[c], isFirst: d };
    const p = Jo(s, c).filter(
      (F) => !(F.pointIds.includes(r[0]) && F.pointIds.includes(r[1]))
    ), m = [], v = f === 0 ? o : l;
    let x = Number.MAX_VALUE, g, y = null, _ = -Number.MAX_VALUE, b, C = null;
    for (let { pointIds: F, id: I } of p) {
      F = [
        r[f],
        ...F.filter((B) => B !== r[f])
      ];
      const T = _t(s, F), R = Ae([
        T[0].x,
        T[0].y,
        T[1].x,
        T[1].y
      ]);
      m.push(R);
      const L = Ye(v, R);
      L > 0 ? L < x && (x = L, g = I, y = R) : L > _ && (_ = L, b = I, C = R);
    }
    let w = null, E = null, S = null;
    !y || !C ? (w = y || C, S = y ? g : b, E = y ? x : _) : Math.abs(Ye(u, y)) < Math.abs(Ye(u, C)) ? (w = y, S = g, E = x) : (w = C, S = b, E = _);
    let P = !1, k = Math.abs(be.radToDeg(E));
    if (w !== null && k > i[1] || k < i[0])
      console.log(
        "夹角不在范围，分割",
        S,
        f === 0 ? a : h,
        k
      ), S = null, w = ds(w), P = !0;
    else if (p.length > 1) {
      const F = w;
      for (let I = 0; I < p.length; I++) {
        if (F === m[I])
          continue;
        const T = (Ye(F, m[I]) + Math.PI) % Math.PI;
        if (he(T, 3) > 0) {
          console.log("方向不同，分割"), P = !0;
          break;
        }
      }
    }
    return n[c].refDire = w, n[c].lineDire = v, n[c].id = S, n[c].split = P, n[c].isFirst = d, n[c];
  };
  return (u) => {
    const f = new X(u[0], u[1]).normalize().toArray(), d = [
      A(f, 0),
      A(f, 1)
    ], c = [
      [e[0][0] + u[0], e[0][1] + u[1]],
      [e[1][0] + u[0], e[1][1] + u[1]]
    ], p = _t(s, t.pointIds);
    if (d[0].refDire || d[1].refDire) {
      const m = [], v = d.map(
        ({ refDire: S }) => S === null ? d[0].refDire || d[1].refDire : S
      );
      for (let S = 0; S < d.length; S++) {
        const P = v[S], k = d[S].split && d[S].isFirst, F = qe(P, e[S], 10);
        if (k) {
          const I = Ko(s);
          s.points.push({
            ...p[S],
            id: I
          }), Ic(
            s,
            a,
            t.pointIds[S],
            I
          );
        }
        m[S] = Gi(F, c[S]).point;
      }
      const x = Et(m[0], e[0]) < Et(m[1], e[1]), g = x ? o : l, y = x ? m[0] : m[1], _ = x ? v[1] : v[0], b = x ? e[1] : e[0], C = qe(g, y, 10), w = qe(_, b, 10), E = go(C, w);
      x ? (c[0] = y, c[1] = E) : (c[1] = y, c[0] = E);
    }
    p[0].x = c[0][0], p[0].y = c[0][1], p[1].x = c[1][0], p[1].y = c[1][1];
  };
}, Nr = (s) => {
  for (let e = 0; e < s.lines.length; e++) {
    const i = s.lines[e], n = _t(s, i.pointIds);
    if (he(
      Et([n[0].x, n[0].y], [n[1].x, n[1].y]),
      4
    ) !== 0)
      continue;
    const a = is(s, [n[1].id], n[0].id);
    e = Math.max(e - a.lineChange.del.length, 0);
  }
  const t = [];
  for (let e = 0; e < s.polygons.length; e++) {
    const i = s.polygons[e];
    for (let n = 0; n < i.lineIds.length; n++) {
      const r = wt(s, i.lineIds[n]), a = (n + 1) % i.lineIds.length, o = wt(s, i.lineIds[a]);
      if (r.pointIds[0] === o.pointIds[1] && r.pointIds[1] === o.pointIds[0]) {
        t.push(_t(s, r.pointIds)), n > a ? (i.lineIds.splice(n, 1), i.lineIds.splice(a, 1)) : (i.lineIds.splice(n, 2), n -= 1), ei(s, r.pointIds), ei(s, o.pointIds);
        continue;
      }
      const h = _t(s, r.pointIds);
      Et(
        [h[0].x, h[0].y],
        [h[1].x, h[1].y]
      ) < Xt.WHOLE_LINE_POINT_MERGE_DIST && (is(s, [h[0].id], h[1].id), n--);
    }
    i.lineIds.length === 0 && (console.log("del polygon"), s.polygons.splice(e--, 1));
  }
  t.forEach((e) => {
    if (e[0].id === e[1].id)
      return;
    const i = Zo(s), n = Qo(s);
    e = e.map((r) => s.points.some(({ id: a }) => a === r.id) ? r : Qe(s, { x: r.x, y: r.y })), s.lines.push({
      id: n,
      pointIds: e.map(({ id: r }) => r)
    }), s.polygons.push({
      id: i,
      lineIds: [n]
    });
  });
}, $c = ({
  tree: s,
  position: t,
  refPointName: e = "adsord-point",
  exclusionIds: i = [],
  radius: n = 10
}) => {
  const r = s.stage.find(`.${e}`).filter((a) => !i.includes(a.id())).map((a) => {
    const o = a.position();
    return [o.x, o.y];
  });
  return Wc({ refPositions: r, radius: n, position: t });
}, Wc = ({
  position: s,
  radius: t = 10,
  refPositions: e
}) => {
  let i = null, n = Number.MAX_VALUE;
  for (const r of e) {
    const a = Et(r, s);
    a < t && a < n && (n = a, i = r);
  }
  return i;
}, mi = [0, 90, 180, 270, 360], sh = ({
  position: s,
  refLines: t,
  angle: e = 3
}) => {
  let i = null, n = null, r = !1;
  for (const a of t) {
    const h = [
      [a[0], a[1]],
      [a[2], a[3]]
    ].map((u) => (be.radToDeg(
      bA(a, [...u, ...s])
    ) + 360) % 360);
    let l = 0, A = 0;
    for (l = 0; l < h.length; l++) {
      for (A = 0; A < mi.length; A++) {
        const u = mi[A];
        if (h[l] >= u - e && h[l] <= u + e)
          break;
      }
      if (A !== mi.length)
        break;
    }
    if (A !== mi.length || l !== h.length) {
      n = a, i = mi[A];
      const u = _A(
        Ae(n),
        be.degToRad(i)
      ), f = Et([n[0], n[1]], s) > Et([n[2], n[3]], s) ? [n[2], n[3]] : [n[0], n[1]];
      n = qe(u, f, 10), s = Gi(n, s).point, r = !0;
    }
  }
  if (r)
    return s;
}, Yc = ({
  position: s,
  angle: t,
  points: e
}) => {
  if (e != null && e.length && e.length === 1) {
    const i = e[0], n = [
      [i[0] - 1, i[1], i[0] + 1, i[1]],
      [i[0], i[1] - 1, i[0], i[1] + 1]
    ];
    return sh({ position: s, refLines: n, angle: t });
  }
}, Ha = ({
  position: s,
  points: t,
  angle: e
}) => {
  if (!(t != null && t.length))
    return;
  const i = t.slice(0, 2).flatMap((o) => o), n = t.slice(t.length - 2, t.length).flatMap((o) => o), r = [
    i,
    // createLineByDire(getVerticaLineDire(last), [last[2], last[3]], 10),
    qe(xA(n), [n[2], n[3]], 10)
  ];
  let a;
  if (a = sh({
    position: s,
    refLines: r,
    angle: e
  }))
    return a;
}, ah = (s) => {
  const t = s.position || s.tree.getRealFromStage(s.pixel);
  let e;
  if (e = $c({ ...s, position: t }))
    return e;
  if (e = Yc({ ...s, position: t }))
    return e;
  if (e = Ha({ ...s, position: t }))
    return e;
  if (s.pointsArray) {
    for (let i = 0; i < s.pointsArray.length; i++)
      if (e = Ha({
        ...s,
        position: t,
        points: s.pointsArray[i]
      }))
        return e;
  }
  return t;
}, Va = ({
  tree: s,
  config: t,
  polygonId: e,
  pointAttribFactory: i,
  quotePoint: n,
  canOper: r,
  autoAdd: a,
  adsorbRadius: o,
  canDelPoint: h,
  closeAutoQuit: l,
  changePolygon: A,
  autoClose: u
}) => {
  i = i || ((b) => ({
    x: b[0],
    y: b[1]
  }));
  const f = (b) => {
    if (b)
      return t.polygons.find(({ id: C }) => C === b);
    {
      const C = Zo(t);
      return t.polygons.push({
        id: C,
        lineIds: []
      }), t.polygons[t.polygons.length - 1];
    }
  };
  let d, c = !1, p = null, m = !0;
  const v = (b) => {
    if (d = f(b), !d)
      throw `${b}的多边形不存在！`;
    A && A(d.id), e = d.id, c = !b, p = null, m = a || d.lineIds.length < 2;
  };
  v(e);
  const x = () => {
    const b = t.polygons.indexOf(d);
    ~b && t.polygons.splice(b, 1);
  }, g = (b) => {
    let C = {
      lineChange: {
        del: [],
        update: [],
        add: []
      },
      polygonChange: {
        add: [],
        update: [],
        del: []
      },
      pointChange: {
        add: [],
        del: []
      }
    };
    const w = FA(b.target, (R) => {
      const L = R.id();
      return L.includes(qt.namespace) || L.includes(Rt.namespace);
    });
    let E = w && s.find(w.id());
    const S = [b.evt.offsetX, b.evt.offsetY];
    if (E instanceof qt && (!r || r(E, b.target)) && d.lineIds.includes(E.attrib.id)) {
      const { change: R } = Lc(
        t,
        E.attrib.id,
        i(s.getRealFromStage(S))
      );
      return { change: vi(C, R), isClose: !1 };
    }
    let P;
    const k = Fi(t, d.id);
    for (; ; ) {
      if (E instanceof Rt) {
        if (r && !r(E, b.target))
          return { change: C, isClose: !1 };
        if (P = n ? E.attrib : { ...E.attrib }, d.id === p)
          return { change: C, isClose: !1 };
      } else {
        let R;
        if (o) {
          const $ = k.map(({ x: O, y: G }) => [O, G]);
          if (p) {
            const O = Ce(t, p);
            $.push([O.x, O.y]);
          }
          R = ah({
            tree: s,
            pixel: S,
            radius: o,
            points: [...$].reverse()
          });
        } else
          R = s.getRealFromStage(S);
        const L = vo(s);
        let B = 0;
        for (; B < L.length; B++)
          if (L[B] instanceof Rt) {
            const $ = L[B];
            if (he($.attrib.x - R[0], 4) === 0 && he($.attrib.y - R[1], 4) === 0) {
              E = s.children[B];
              break;
            }
          }
        if (B !== L.length) {
          E = L[B];
          continue;
        }
        P = i(R);
      }
      break;
    }
    const F = k.findIndex(({ id: R }) => R === P.id), I = F === 0 && (!u || k.length >= 3);
    if (F >= 0 && !I) {
      const R = za(
        t,
        P.id,
        !h || h(P, b)
      );
      if (C = vi(C, R), d.lineIds.length === 0) {
        rh(t, d.id);
        const L = R.pointChange.del.find(
          ({ id: $ }) => $ !== P.id
        );
        v(null);
        const B = Qe(t, { ...L, id: void 0 });
        p = B.id, C.pointChange.add.push(B);
      }
      return { change: C, isClose: I };
    }
    n || delete P.id;
    const T = (R) => (!l && I && v(null), { change: R, isClose: I });
    if (d.lineIds.length > 0)
      if (c) {
        const R = Oc(
          t,
          e,
          P
        ).change;
        return T(vi(C, R));
      } else
        return m ? (v(null), g(b)) : { change: C, isClose: I };
    else if (p) {
      const [R] = Nt(s.stage, [4, 4], !0), L = Ce(t, p);
      if (!(Math.abs(P.x - L.x) > R || Math.abs(P.y - L.y) > R))
        return T(C);
      const { line: B, change: $ } = ce(t, [
        p,
        Qe(t, P).id
      ]);
      return C = vi(C, $, {
        polygonChange: {
          update: [
            {
              before: { ...d, lineIds: [...d.lineIds] },
              after: {
                ...d,
                lineIds: [...d.lineIds, B.id]
              }
            }
          ]
        },
        pointChange: {
          add: [P]
        }
      }), d.lineIds.push(B.id), p = null, T(C);
    } else {
      const R = Qe(t, P);
      return p = R.id, C.pointChange.add.push(R), T(C);
    }
  };
  return {
    continuous: g,
    end: () => {
      d.lineIds.length === 0 && (p && za(t, p), x()), A && A(null);
    },
    getStatus: () => ({
      newMode: c,
      polyginAttribId: d.id,
      prevId: p,
      config: t
    }),
    setStatus: (b) => {
      c = b.newMode, d = b.config.polygons.find(
        ({ id: C }) => C === b.polyginAttribId
      ), e = d.id, p = b.prevId, t = b.config;
    }
  };
}, Xc = "data:image/x-icon;base64,[encoded data, 5716 characters]", jc = "data:image/x-icon;base64,[encoded data, 5716 characters]", qc = (s) => {
  const t = () => JSON.parse(JSON.stringify(s.config)), e = Va({ ...s }), i = Va({
    ...s,
    closeAutoQuit: !0,
    changePolygon: void 0,
    config: t()
  }), n = () => {
    const g = e.getStatus();
    i.setStatus({
      ...g,
      config: t()
    });
  }, r = s.tree.stage, a = Ya();
  let o = !1;
  const h = () => {
    o = !0;
  }, l = (g) => {
    if (o)
      return;
    n();
    const { change: y } = i.continuous(g), { config: _ } = i.getStatus();
    a.value = {
      change: y,
      config: _
    };
  }, A = (g) => {
    o = !1, l(g);
  };
  let u;
  const f = (g) => {
    const [y] = Nt(r, [4, 4], !0);
    if (!(u && Math.abs(g.evt.offsetX - u.x) < y && Math.abs(g.evt.offsetY - u.y) < y)) {
      const { isClose: _, change: b } = e.continuous(g);
      n(), _ && s.closeAutoQuit && x(), s.onChange && s.onChange(b), u = null;
    }
  }, d = (g) => {
    const y = eo(g);
    g.evt.offsetX = y.offsetX, g.evt.offsetY = y.offsetY;
  }, c = (g) => {
    g.evt.preventDefault(), d(g), l(g), !a.value.change.lineChange.add.length && !a.value.change.lineChange.del.length && (m(g), u = {
      x: g.evt.offsetX,
      y: g.evt.offsetY
    });
  }, p = (g) => {
    g.evt.preventDefault(), d(g), l(g);
  }, m = (g) => {
    g.evt.preventDefault(), d(g), f(g), a.value = void 0;
  }, v = (g) => {
    g instanceof KeyboardEvent ? g.key === "Escape" && x() : (x(), g.preventDefault());
  };
  let x = () => {
    an ? (r.off("touchstart.editPolygonsMode", c), r.off("touchmove.editPolygonsMode", p), r.off("touchend.editPolygonsMode", m)) : (r.off("click.editPolygonsMode", f), r.off("mousedown.editPolygonsMode", h), r.off("mousemove.editPolygonsMode", l), r.off("mouseup.editPolygonsMode", A), document.removeEventListener("contextmenu", v), document.removeEventListener("keydown", v)), a.value = void 0, e.end(), i.end(), s.quitHandler && s.quitHandler();
  };
  return an ? (r.on("touchstart.editPolygonsMode", c), r.on("touchmove.editPolygonsMode", p), r.on("touchend.editPolygonsMode", m)) : (r.on("click.editPolygonsMode", f), r.on("mousedown.editPolygonsMode", h), r.on("mousemove.editPolygonsMode", l), r.on("mouseup.editPolygonsMode", A), document.addEventListener("contextmenu", v), document.addEventListener("keydown", v)), {
    helperInfo: a,
    destory() {
      x && (x(), x = null);
    }
  };
}, Qc = (s, t) => {
  var o, h, l;
  const { lineChange: e, polygonChange: i } = s;
  if (!e || !((o = i == null ? void 0 : i.update) != null && o.length))
    return !1;
  const n = i.update.find(
    ({ after: A }) => A.id === t
  );
  if (!n)
    return !1;
  const { before: r, after: a } = n;
  if ((h = e.del) != null && h.length) {
    if ((l = e.add) != null && l.length)
      return !1;
  } else if (a.lineIds.length >= 2)
    return "after";
  if (a.lineIds.length !== r.lineIds.length)
    if (a.lineIds.includes(r.lineIds[r.lineIds.length - 1])) {
      if (!a.lineIds.includes(r.lineIds[0]))
        return "before";
    } else
      return "after";
  return !1;
}, Kc = (s, t = !1) => {
  var o, h, l, A, u, f, d, c, p, m, v, x, g, y, _, b;
  const e = [];
  (h = (o = s.change) == null ? void 0 : o.pointChange) != null && h.add && e.push(
    ...(A = (l = s.change) == null ? void 0 : l.pointChange) == null ? void 0 : A.add.map(({ x: C, y: w }) => [C, w])
  );
  const i = [];
  (f = (u = s.change) == null ? void 0 : u.pointChange) != null && f.del && i.push(...(c = (d = s.change) == null ? void 0 : d.pointChange) == null ? void 0 : c.del.map(({ id: C }) => C));
  const n = [];
  if ((m = (p = s.change) == null ? void 0 : p.lineChange) != null && m.add) {
    const C = s.change.lineChange.add.map(
      ({ pointIds: w }) => w
    );
    n.push(
      ...C.map((w) => _t(s.config, w).flatMap(({ x: S, y: P }) => [S, P]))
    );
  }
  const r = [];
  (x = (v = s.change) == null ? void 0 : v.lineChange) != null && x.del && r.push(...(y = (g = s.change) == null ? void 0 : g.lineChange) == null ? void 0 : y.del.map(({ id: C }) => C));
  const a = {};
  return t && ((b = (_ = s.change) == null ? void 0 : _.polygonChange) != null && b.update) && s.change.polygonChange.update.forEach((C) => {
    if (Qc(s.change, C.after.id)) {
      const w = th(s.config, [
        C.after.lineIds[C.after.lineIds.length - 1],
        C.after.lineIds[0]
      ]);
      a[C.after.id] = _t(s.config, [
        w[0].pointIds[1],
        w[1].pointIds[0]
      ]).flatMap(({ x: E, y: S }) => [E, S]);
    }
  }), {
    addLines: n,
    delLines: r,
    addPoints: e,
    delPoints: i,
    cloneLines: a
  };
}, ks = (s, t) => {
  const { helperInfo: e, destory: i } = qc({
    ...s,
    quitHandler: () => {
      o(), s.quitHandler && s.quitHandler();
    }
  }), n = ch(
    () => e.value && Kc(e.value, s.autoClose)
  ), r = Dn();
  r.shape.listening(!1);
  const a = hi();
  a.active(), a.shape.dash([5, 5]), a.shape.listening(!1);
  const o = xn((h) => {
    if (!n.value)
      return;
    const { addLines: l, cloneLines: A, addPoints: u } = n.value, f = [...l, ...Object.values(A)].map(
      (m) => (a.setData(m), a.shape.clone())
    ), [d] = Nt(t, [1, 1]), c = u.map((m) => (r.setData(m), r.shape.scale({ x: d, y: d }), r.shape.clone()));
    t.add(...f, ...c);
    let p;
    n.value.delPoints.length ? p = s.tree.setCursor(jc) : u.length && (p = s.tree.setCursor(Xc)), h(() => {
      [...f, ...c].forEach((m) => {
        m.remove();
      }), p && p();
    });
  });
  return i;
};
class Zu extends Di {
  diffRedraw() {
    const t = super.diffRedraw();
    return t.lineEntityInc.adds.forEach((e) => {
      ln(e, this.lineDragHandler), e.enableMouseAct({ ...e.actShape, active: void 0 }), e.shape.name("adsord-line");
    }), t.pointEntityInc.adds.forEach((e) => {
      ln(e, this.pointDragHandler), e.enableMouseAct({ ...e.actShape, active: void 0 }), e.shape.addName("adsord-point");
    }), t;
  }
  getChildByPointsAttrib(t) {
    const e = [];
    for (let i = 0; i < t.length; i++) {
      const n = Rt.namespace + t[i].id;
      e.includes(n) || e.push(n), this.attrib.lines.filter(({ pointIds: r }) => r.includes(t[i].id)).forEach(({ id: r }) => {
        const a = qt.namespace + r;
        e.includes(a) || e.push(a);
      });
    }
    return this.children.filter((i) => e.includes(i.name));
  }
  editPolygon(t) {
    po(), this.container.constant.use();
    const e = /* @__PURE__ */ new Set();
    let i = !1;
    this.endCreatePolygon && this.endCreatePolygon(), this.container.bus.emit("dataChangeBefore");
    const n = Fs();
    let r = !1;
    const a = new Promise((o) => {
      this.endCreatePolygon = ks(
        {
          polygonId: t,
          quotePoint: !0,
          autoClose: !1,
          tree: this.container,
          autoAdd: !0,
          adsorbRadius: Xt.WHOLE_LINE_POINT_MERGE_DIST,
          config: this.attrib,
          changePolygon: (h) => {
            console.log("changePolygon", h), h && e.add(h);
          },
          onChange(h) {
            !r && h.pointChange.add.length && (n.emit("penStart"), r = !0);
          },
          quitHandler: () => {
            this.container.bus.emit("dataChangeAfter"), this.endCreatePolygon = null, e.forEach((h) => {
              const l = ci(this.attrib, h);
              l && (i ? rh(this.attrib, h) : this.polygonAfterHandler(l));
            }), o(i ? "cancel" : "submit"), yo(), this.container.constant.unuse();
          }
        },
        this.shape
      );
    });
    return {
      bus: n,
      submit: this.endCreatePolygon.bind(this),
      cancel: () => {
        i = !0, this.endCreatePolygon();
      },
      promise: a
    };
  }
  createPolygon() {
    return this.editPolygon();
  }
  pointAfterHandler(t) {
    this.container.constant.use();
    const e = Hc(this.attrib, t.id);
    Or(
      this.attrib,
      (e == null ? void 0 : e.info.main.id) || t.id
    ), Nr(this.attrib), this.container.constant.unuse();
  }
  lineAfterHandler(t) {
    this.container.constant.use();
    for (let e = 0; e < t.pointIds.length; e++)
      Or(this.attrib, t.pointIds[e]);
    Nr(this.attrib), this.container.constant.unuse();
  }
  polygonAfterHandler(t) {
    this.container.constant.use(), Fi(this.attrib, t.id).forEach(
      (e) => {
        this.attrib.points.includes(e) && Or(this.attrib, e.id);
      }
    ), Nr(this.attrib), this.container.constant.unuse();
  }
  init() {
    this.lineDragHandler = {
      readyHandler: (t) => {
        this.container.bus.emit("dataChangeBefore"), this.container.tempDraw();
        const e = di(this.attrib, t.id);
        return Vc(
          this.attrib,
          t,
          e.map(({ x: i, y: n }) => [i, n])
        );
      },
      moveHandler: (t, e, i) => {
        i(e);
      },
      endHandler: (t) => {
        this.lineAfterHandler(t), this.container.bus.emit("dataChangeAfter");
      }
    }, this.pointDragHandler = {
      readyHandler: (t) => (this.container.constant.use(), this.container.bus.emit("dataChangeBefore"), ih(
        this.attrib,
        t.id
      ).map(({ polygonId: n }) => {
        let r = Fi(this.attrib, n);
        const a = r.indexOf(t), o = r[0] === r[r.length - 1] ? r.length - 1 : r.length;
        return r = [
          ...r.slice(a + 1, o),
          ...r.slice(0, a)
        ], console.log(r), r.map((h) => [h.x, h.y]);
      })),
      moveHandler: (t, e, i) => {
        const n = Dc(
          this.attrib,
          t
        ).map((a) => qt.namespace + a.id);
        n.push(Rt.namespace + t.id);
        const r = ah({
          tree: this.container,
          position: e,
          radius: Xt.WHOLE_LINE_POINT_MERGE_DIST,
          radiusInner: Xt.WHOLE_LINE_POINT_CHECK_DIST,
          pointsArray: i,
          exclusionIds: n
        });
        t.x = r[0], t.y = r[1];
      },
      endHandler: (t) => {
        this.container.constant.unuse(), this.pointAfterHandler(t), this.container.bus.emit("dataChangeAfter");
      }
    }, super.init();
  }
  destory() {
    this.endCreatePolygon && this.endCreatePolygon(), super.destory();
  }
}
const Zc = (s, t) => {
  const e = t.parent, i = hi(), n = () => !!(e.editPolygonId.value && eh(
    e.attrib,
    e.editPolygonId.value
  ).some(({ id: o }) => o === s.id)), r = () => {
    var o, h, l;
    ((l = (h = (o = e.helperInfo) == null ? void 0 : o.value) == null ? void 0 : h.delLines) == null ? void 0 : l.includes(s.id)) ? i.shape.stroke("rgba(0, 0, 0, 0)") : n() ? i.active() : i.common();
  };
  return {
    shape: i.shape,
    setData(a) {
      i.setData(a), r();
    },
    common: r
  };
}, oh = (s) => (t, e) => {
  const i = e.parent, n = () => i.editPolygonId.value === t.id, r = Tn({ autoClose: s }), a = (o) => {
    n() ? r.active(o) : r.common(o);
  };
  return {
    shape: r.shape,
    setData(o) {
      var l, A, u, f;
      a(), r.setData(o);
      const h = (A = (l = i.helperInfo) == null ? void 0 : l.value) != null && A.cloneLines ? Object.keys((f = (u = i.helperInfo) == null ? void 0 : u.value) == null ? void 0 : f.cloneLines).includes(
        t.id
      ) : !1;
      r.shape.children[1].visible(!h);
    },
    common: a
  };
}, Jc = oh(!0), tu = oh(!1);
class Ju extends Di {
  constructor() {
    super(...arguments), this.editPolygonId = Ya(), this.autoClose = !0, this._leaveEditMode = void 0;
  }
  dragAttach(t) {
    t.pointEntityInc.adds.forEach((e) => {
      ln(e, {
        readyHandler: (i) => [i.x, i.y],
        moveHandler: (i, n) => {
          this.editPolygonId.value && (i.x = n[0], i.y = n[1]);
        }
      }), e.enableMouseAct(e.actShape);
    }), t.lineEntityInc.adds.forEach((e) => {
      e.enableMouseAct(e.actShape);
    }), t.polygonEntityInc.adds.forEach((e) => {
      e.enableMouseAct(e.actShape);
    });
  }
  diffRedraw() {
    const t = super.diffRedraw();
    return this.dragAttach(t), t;
  }
  initIncFactory() {
    super.initIncFactory(), this.incLinesFactory = Pt(
      qt,
      this,
      (t) => {
        t.actShapeFactory = Zc, t.setConfig(this.attrib);
      }
    ), this.incPointsFactory = Pt(
      Rt,
      this
    ), this.incPolygonFactory = Pt(
      ki,
      this,
      (t) => {
        t.actShapeFactory = this.autoClose ? Jc : tu, t.setConfig(this.attrib);
      }
    );
  }
  enterEditMode(t) {
    this._leaveEditMode && this._leaveEditMode(), this._leaveEditMode = ks(
      {
        ...t,
        closeAutoQuit: !0,
        tree: this.container,
        autoAdd: !1,
        autoClose: this.autoClose,
        config: this.attrib,
        changePolygon: (e) => {
          this.editPolygonId.value = e;
        },
        quitHandler: () => {
          t.quitHandler && t.quitHandler();
        }
      },
      this.shape
    );
  }
  leaveEditMode() {
    this._leaveEditMode && this._leaveEditMode();
  }
  destory() {
    this.leaveEditMode(), super.destory();
  }
}
const hh = (s, t) => {
  t(s);
  for (const e of s.children)
    hh(e, t);
};
class eu extends me {
  constructor(t) {
    for (const i in t.types)
      t.data[i] = t.data[i] || [];
    for (const i in t.data)
      i in t.types || delete t.data[i];
    super({
      name: "container",
      attrib: { id: "0", data: t.data },
      ...t
    }), this.entrys = {}, this.incFactorys = {}, this.constant = Rc(), this.config = t, this.container = this;
    const { dom: e } = this.config;
    this.stage = new Pi.Stage({
      container: e,
      width: e.offsetWidth,
      height: e.offsetHeight
    });
  }
  initShape() {
    return new ps();
  }
  init() {
    this.initIncFactory(), super.init(), this.mount(this.stage), this.mounted();
  }
  initIncFactory() {
    const t = this.config.types;
    let e = null;
    for (const i in t)
      this.incFactorys[i] = Pt(
        t[i],
        this,
        (n) => {
          const r = n;
          this.entrys[i] || (this.entrys[i] = []), this.entrys[i].push(r), r.bus.on("destroyed", () => {
            const a = this.entrys[i].indexOf(r);
            ~a && this.entrys[i].splice(a, 1);
          });
        },
        (n) => {
          hh(n, (r) => {
            var a;
            !((a = r.actShape) != null && a.active) || r.activeDestory || (r.enableActive((o) => {
              o ? e !== r && (this.bus.emit("active", r), e = r) : e === r && (this.bus.emit("active", null), e = null);
            }), r.bus.on("destroyed", () => {
              e === r && (this.bus.emit("active", null), e = null);
            }));
          });
        }
      );
  }
  diffRedraw() {
    const t = this.attrib.data, e = {};
    for (const i in t)
      i in this.incFactorys && (e[i] = this.incFactorys[i](t[i]));
    return e;
  }
  initReactive() {
    return Me(
      () => {
        const t = {};
        for (const e in this.attrib.data) {
          const i = this.attrib.data[e];
          t[e] = Array.isArray(i) ? i.map(({ id: n }) => n) : i.id;
        }
        return t;
      },
      this.diffRedraw.bind(this),
      { immediate: !0, flush: "sync" }
    );
  }
  // 临时绘制
  tempDraw(...t) {
    const e = t.map((i) => i.teleport);
    return t.forEach((i) => {
      i.mount(this.tempLayer);
    }), () => {
      t.forEach((i, n) => {
        i.mount(e[n]);
      });
    };
  }
  getPixelFromStage(t) {
    const e = on(this.stage, !0), { x: i, y: n } = e.point({ x: t[0], y: t[1] });
    return [i, n];
  }
  getRealFromStage(t) {
    const e = on(this.stage, !0).invert(), { x: i, y: n } = e.point({ x: t[0], y: t[1] });
    return [i, n];
  }
  setCursor(t) {
    return t = ["move", "inherit", "pointer"].includes(t) ? t : t ? `url("${t}"), auto` : "inherit", this.config.dom.style.cursor = t, this.prevCursor = t, () => {
      this.prevCursor === t && (this.config.dom.style.cursor = "inherit", this.prevCursor = "inherit");
    };
  }
  getSameLevelData(t) {
    const e = this.attrib.data;
    for (const i in e)
      if (Array.isArray(e[i]) && ~e[i].indexOf(t.attrib))
        return e[i];
  }
  updateViewMat(t) {
    const e = new j(), i = new ai(), n = new j();
    t.decompose(e, i, n);
    const r = ["XYZ", "YZX", "ZXY", "XZY", "YXZ", "ZYX"];
    let a = new Ni();
    for (let h = 0; h < r.length; h++) {
      a.setFromQuaternion(i, r[h]);
      const l = Math.abs(be.radToDeg(a.z) % 90);
      if (Math.abs(l) < 5)
        break;
    }
    a.setFromQuaternion(i, "XYZ");
    const o = a.z;
    this.stage.scale({ x: n.x, y: n.y }), this.stage.position({ x: e.x, y: e.y }), this.stage.rotation(be.radToDeg(o)), this.redraw(), this.constant.updateConstantScale(Math.min(n.x, n.y));
  }
}
const iu = () => {
  const s = new Ri({
    radius: 3,
    fill: "red"
  }), t = () => {
    const [e] = Nt(s, [1, 1]);
    s.scale({ x: e, y: e });
  };
  return {
    getSize: () => [3, 3],
    shape: s,
    common() {
    },
    setData(e) {
      t(), s.position(e);
    }
  };
}, lh = {}, t1 = (s, t) => {
  lh[s] = t;
}, _n = class _n extends me {
  constructor(t) {
    t.zIndex = t.zIndex || 5, t.name = t.name || _n.namespace + t.attrib.id, super(t);
  }
  initShape() {
    const t = lh[this.attrib.type] || iu;
    return this.actShape = t(this.attrib, this), this.actShape.shape;
  }
  diffRedraw() {
    this.actShape.setData(this.attrib);
  }
  mounted() {
    super.mounted(), this.actShape.common(null);
  }
};
_n.namespace = "poi";
let ns = _n;
class e1 extends ns {
  mounted() {
    super.enableMouseAct(this.actShape), super.enableDrag({
      readyHandler: () => {
        this.container.bus.emit("dataChangeBefore");
      },
      moveHandler: (t) => {
        this.attrib.x = t[0], this.attrib.y = t[1];
      },
      endHandler: () => {
        this.container.bus.emit("dataChangeAfter");
      }
    });
  }
  del() {
    const t = this.container.getSameLevelData(this);
    t && t.splice(t.indexOf(this.attrib), 1), this.container.bus.emit("dataChange");
  }
  copy(t = {}) {
    IA({
      ...t,
      entity: this,
      size: this.actShape.getSize(),
      factoryAttrib: (e) => ({
        x: e[0],
        y: e[1],
        type: this.attrib.type
      })
    }), this.container.bus.emit("dataChange");
  }
}
const nu = (s, t) => (i, n, r = !1) => {
  const a = document.createElement("div");
  a.style.width = "100%", a.style.height = "100%";
  const o = new eu({
    dom: a,
    readonly: r,
    types: s,
    data: n,
    reactive: !r
  });
  o.init();
  const h = {};
  if (t)
    for (const u in t) {
      const f = t[u];
      f.setTree(o), h[u] = f;
    }
  let l = null;
  const A = (u) => {
    a.parentElement && a.parentElement.removeChild(a), u.appendChild(a), a.style.width = "100%", a.style.height = "100%", o.stage.width(a.offsetWidth), o.stage.height(a.offsetHeight), l = u;
  };
  return i ? A(i) : (a.style.width = "300px", a.style.height = "300px"), {
    types: s,
    tree: o,
    setData(u) {
      o.setAttrib({ data: u });
    },
    getData() {
      return o.attrib.data;
    },
    destory() {
      for (const u in t) {
        const f = t[u];
        f.destory && f.destory();
      }
      o.destory();
    },
    mountedDom: l,
    mount: A,
    ...h
  };
}, Ke = new Zt(), ru = (s, t) => {
  Ke.identity().translate(-t[0], -t[1]);
  const e = new X(s[0], s[1]).applyMatrix3(Ke), i = new X(s[2], s[3]).applyMatrix3(Ke);
  return [e.x, e.y, i.x, i.y];
}, su = (s, t, e) => {
  Ke.identity().translate(-t[0], -t[1]).scale(e, e).translate(t[0], t[1]);
  const i = new X(s[0], s[1]).applyMatrix3(Ke), n = new X(s[2], s[3]).applyMatrix3(Ke);
  return [i.x, i.y, n.x, n.y];
};
class au {
  constructor(t = {}) {
    this.bound = t.bound, this.props = t, this.props.move = t.move || !1, this.props.wheel = t.wheel || !1;
  }
  disableMove() {
    this.props.move = !1, this.dragDestory && this.dragDestory();
  }
  enableMove(t) {
    if (this.disableMove(), this.props.move = !0, !this.tree)
      return;
    const { stage: e } = this.tree;
    this.dragDestory = cs(
      e,
      {
        readyHandler: () => ({
          tf: on(e, !0).invert(),
          initBound: this.bound
        }),
        moveHandler: (i, { tf: n, initBound: r }) => {
          const a = n.point({ x: i[0], y: i[1] }), o = [a.x, a.y];
          let h = ru(r, o);
          if (t) {
            const l = t(h, o);
            if (typeof l != "boolean")
              h = l;
            else if (!l)
              return;
          }
          this.setBound(h);
        }
      },
      !1
    );
  }
  disableWheel() {
    this.props.wheel = !1, this.wheelDestory && this.wheelDestory();
  }
  enableWheel(t) {
    if (this.disableWheel(), this.props.wheel = !0, !this.tree)
      return;
    const {
      stage: e,
      config: { dom: i }
    } = this.tree, n = (r) => {
      const a = 1 + r.deltaY / 1e3, o = e.getRelativePointerPosition(), h = [o.x, o.y];
      let l = su(this.bound, h, a);
      if (t) {
        const A = t(l, h, a);
        if (typeof A != "boolean")
          l = A;
        else if (!A)
          return;
      }
      this.bound = l, this.update();
    };
    i.addEventListener("wheel", n), this.wheelDestory = () => i.removeEventListener("wheel", n);
  }
  setBound(t) {
    this.bound = t, this.update();
  }
  setSize(t, e) {
    this.tree.stage.width(t), this.tree.stage.height(e);
  }
  setTree(t) {
    if (this.tree = t, !this.bound) {
      const e = t.stage.getSize(), i = t.stage.position();
      this.bound = [i.x, i.y, e.width, e.height];
    }
    this.props.move && this.enableMove(), this.props.wheel && this.enableWheel();
  }
  update() {
    const { stage: t } = this.tree, e = this.bound[2] - this.bound[0], i = this.bound[3] - this.bound[1], n = t.width() / e, r = t.height() / i, a = -this.bound[0] * n, o = -this.bound[1] * r;
    t.scale({ x: n, y: r }), t.position({ x: a, y: o }), this.tree.redraw(), this.tree.shape.batchDraw();
  }
}
var Ah = {};
Object.defineProperty(Ah, "__esModule", { value: !0 });
var ou = function(t) {
  for (var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, i = t.length, n = e ^ i, r = 0, a = void 0; i >= 4; )
    a = t.charCodeAt(r) & 255 | (t.charCodeAt(++r) & 255) << 8 | (t.charCodeAt(++r) & 255) << 16 | (t.charCodeAt(++r) & 255) << 24, a = (a & 65535) * 1540483477 + (((a >>> 16) * 1540483477 & 65535) << 16), a ^= a >>> 24, a = (a & 65535) * 1540483477 + (((a >>> 16) * 1540483477 & 65535) << 16), n = (n & 65535) * 1540483477 + (((n >>> 16) * 1540483477 & 65535) << 16) ^ a, i -= 4, ++r;
  switch (i) {
    case 3:
      n ^= (t.charCodeAt(r + 2) & 255) << 16;
    case 2:
      n ^= (t.charCodeAt(r + 1) & 255) << 8;
    case 1:
      n ^= t.charCodeAt(r) & 255, n = (n & 65535) * 1540483477 + (((n >>> 16) * 1540483477 & 65535) << 16);
  }
  return n ^= n >>> 13, n = (n & 65535) * 1540483477 + (((n >>> 16) * 1540483477 & 65535) << 16), n ^= n >>> 15, n >>> 0;
}, hu = ou, lu = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(s) {
  return typeof s;
} : function(s) {
  return s && typeof Symbol == "function" && s.constructor === Symbol && s !== Symbol.prototype ? "symbol" : typeof s;
};
function Au(s) {
  var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2, e = /* @__PURE__ */ new Set(), i = JSON.stringify(s, function(n, r) {
    return (typeof r > "u" ? "undefined" : lu(r)) === "object" && r !== null ? e.has(r) ? void 0 : e.add(r) && r : r;
  }, t);
  return e = null, i;
}
var $a = Object.assign || function(s) {
  for (var t = 1; t < arguments.length; t++) {
    var e = arguments[t];
    for (var i in e)
      Object.prototype.hasOwnProperty.call(e, i) && (s[i] = e[i]);
  }
  return s;
};
function du(s) {
  if (Array.isArray(s)) {
    for (var t = 0, e = Array(s.length); t < s.length; t++)
      e[t] = s[t];
    return e;
  } else
    return Array.from(s);
}
var dh = {
  // StateNode => { Chunks, Children }
  toRecord: function(t) {
    return {
      chunks: [$a({}, t, { children: void 0 })],
      children: t.children
    };
  },
  // { Chunks, Children } => StateNode
  fromRecord: function(t) {
    var e = t.chunks, i = t.children;
    return $a({}, e[0], { children: i });
  }
}, cu = function s(t, e) {
  for (var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [], n = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : null, r = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : -1, a = i.findIndex(function(v) {
    var x = v.match;
    return x(t);
  }), o = i[a] || dh, h = o.toRecord(t), l = h.chunks, A = h.children, u = A, f = [], d = 0; d < l.length; d++) {
    var c = Au(l[d], 0), p = hu(c);
    f.push(p), e[p] = c;
  }
  if (r !== -1 && Array.isArray(n && n.children)) {
    var m = [].concat(du(n.children));
    return m[r] = s(u[r], e, i), { hashes: f, ruleIndex: a, children: m };
  } else
    return {
      hashes: f,
      ruleIndex: a,
      children: A && A.map(function(v) {
        return s(v, e, i);
      })
    };
}, uu = function s(t, e) {
  var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [], n = t.hashes, r = t.ruleIndex, a = t.children, o = n.map(function(l) {
    return JSON.parse(e[l]);
  }), h = i[r] || dh;
  return h.fromRecord({
    chunks: o,
    children: a && a.map(function(l) {
      return s(l, e, i);
    })
  });
}, fu = /* @__PURE__ */ function() {
  function s(t, e) {
    for (var i = 0; i < e.length; i++) {
      var n = e[i];
      n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(t, n.key, n);
    }
  }
  return function(t, e, i) {
    return e && s(t.prototype, e), i && s(t, i), t;
  };
}();
function gu(s, t) {
  if (!(s instanceof t))
    throw new TypeError("Cannot call a class as a function");
}
var Wa = function() {
}, pu = function() {
  function s() {
    var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
      initialState: void 0,
      rules: [],
      delay: 50,
      maxLength: 100,
      onChange: Wa,
      useChunks: !0
    };
    gu(this, s), this.rules = t.rules || [], this.delay = t.delay || 50, this.maxLength = t.maxLength || 100, this.useChunks = t.useChunks === void 0 ? !0 : t.useChunks, this.onChange = Wa, this.$index = -1, this.$records = [], this.$chunks = {}, this.$pending = {
      state: null,
      pickIndex: null,
      onResolves: [],
      timer: null
    }, this.$debounceTime = null, t.initialState !== void 0 && this.pushSync(t.initialState), t.onChange && (this.onChange = t.onChange);
  }
  return fu(s, [{
    key: "get",
    // void => State
    value: function() {
      var e = this.$records[this.$index], i = void 0;
      return e ? this.useChunks ? i = uu(e, this.$chunks, this.rules) : i = e : i = null, this.onChange(i), i;
    }
    // (State, number?) => History
  }, {
    key: "pushSync",
    value: function(e) {
      var i = this, n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : -1, r = this.$records[this.$index] || null, a = this.useChunks ? cu(e, this.$chunks, this.rules, r, n) : e;
      this.$index++, this.$records[this.$index] = a;
      for (var o = this.$index + 1; o < this.$records.length; o++)
        this.$records[o] = null;
      return this.$index >= this.maxLength && (this.$records[this.$index - this.maxLength] = null), this.$pending.timer && (clearTimeout(this.$pending.timer), this.$pending.state = null, this.$pending.pickIndex = null, this.$pending.timer = null, this.$debounceTime = null, this.$pending.onResolves.forEach(function(h) {
        return h(i);
      }), this.$pending.onResolves = []), this.onChange(e), this;
    }
    // (State, number?) => Promise<History>
  }, {
    key: "push",
    value: function(e) {
      var i = this, n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : -1, r = +/* @__PURE__ */ new Date(), a = function() {
        i.$pending.state = e, i.$pending.pickIndex = n, i.$debounceTime = r;
        var h = new Promise(function(l, A) {
          i.$pending.onResolves.push(l), i.$pending.timer = setTimeout(function() {
            i.pushSync(i.$pending.state, i.$pending.pickIndex);
          }, i.delay);
        });
        return h;
      };
      return this.$pending.timer === null ? a() : r - this.$debounceTime < this.delay ? (clearTimeout(this.$pending.timer), this.$pending.timer = null, a()) : Promise.reject(new Error("Invalid push ops"));
    }
    // void => History
  }, {
    key: "undo",
    value: function() {
      return this.hasUndo && this.$index--, this;
    }
    // void => History
  }, {
    key: "redo",
    value: function() {
      return this.hasRedo && this.$index++, this;
    }
    // void => History
  }, {
    key: "reset",
    value: function() {
      var e = this;
      return this.$index = -1, this.$records.forEach(function(i) {
      }), Object.keys(this.$chunks).forEach(function(i) {
        e.$chunks[i] = null;
      }), this.$records = [], this.$chunks = {}, clearTimeout(this.$pending.timer), this.$pending = {
        state: null,
        pickIndex: null,
        onResolves: [],
        timer: null
      }, this.$debounceTime = null, this;
    }
  }, {
    key: "hasRedo",
    get: function() {
      if (this.$index === this.$records.length - 1)
        return !1;
      for (var e = !1, i = this.$index + 1; i < this.$records.length; i++)
        this.$records[i] !== null && (e = !0);
      return e;
    }
    // : boolean
  }, {
    key: "hasUndo",
    get: function() {
      var e = Math.max(this.$records.length - this.maxLength, 0);
      return this.$index > e;
    }
    // : number
  }, {
    key: "length",
    get: function() {
      return Math.min(this.$records.length, this.maxLength);
    }
  }]), s;
}(), yu = Ah.History = pu;
class i1 {
  constructor() {
    this.state = Ti({
      hasUndo: !1,
      hasRedo: !1
    }), this.disabled = !0;
  }
  setDisable(t) {
    this.disabled = t, t ? this.state.hasRedo = this.state.hasUndo = !1 : this.syncState();
  }
  syncState() {
    !this.history || this.disabled || (this.state.hasRedo = this.history.hasRedo, this.state.hasUndo = this.history.hasUndo);
  }
  setTree(t) {
    this.tree = t, this.history = new yu(), this.setDisable(!1), this.push(this.tree.attrib), this.timelyPush();
  }
  undo() {
    !this.disabled && this.history.hasUndo && (this.history.undo(), this.tree.setAttrib(this.history.get()), this.syncState());
  }
  redo() {
    !this.disabled && this.history.hasRedo && (this.history.redo(), this.tree.setAttrib(this.history.get()), this.syncState());
  }
  push(t) {
    const e = this.history.get();
    e && delete e.children, oi(t, e) && (t = JSON.parse(JSON.stringify(t)), this.history.pushSync(t), this.syncState());
  }
  clear() {
    this.history.reset();
  }
  timelyPush() {
    this.timelyPushDestory && this.timelyPushDestory();
    const t = () => {
      this.push(this.tree.attrib);
    }, e = () => {
      this.setDisable(!0);
    }, i = () => {
      this.setDisable(!1), t();
    };
    this.tree.bus.on("dataChange", t), this.tree.bus.on("dataChangeBefore", e), this.tree.bus.on("dataChangeAfter", i), this.timelyPushDestory = () => {
      this.tree.bus.off("dataChange", t), this.tree.bus.off("dataChangeBefore", e), this.tree.bus.off("dataChangeAfter", i), this.timelyPushDestory = null;
    };
  }
}
class n1 {
  constructor(t = {}) {
    this.clipMat = new ot(), this.bus = Fs(), this.props = t, this.props.move = t.move || !1, this.props.wheel = t.wheel || !1, this.cameraMat = new ot(), t.size && this.setSize(t.size[0], t.size[1]), t.bound && this.setBound(t.bound, t.padding);
  }
  disableMove() {
    this.props.move = !1, this.dragDestory && this.dragDestory();
  }
  enableMove() {
    if (this.disableMove(), this.props.move = !0, !this.tree)
      return;
    const { stage: t } = this.tree;
    this.dragDestory = cs(
      t,
      {
        readyHandler: () => this.cameraMat.clone(),
        moveHandler: (e, i) => {
          const n = this.clipMat.clone().multiply(i).invert(), r = new j(e[0], e[1], 0).applyMatrix4(n);
          this.move([r.x, r.y], i);
        }
      },
      !1
    );
  }
  disableWheel() {
    this.props.wheel = !1, this.wheelDestory && this.wheelDestory();
  }
  enableWheel() {
    if (this.disableWheel(), this.props.wheel = !0, !this.tree)
      return;
    const {
      config: { dom: t }
    } = this.tree, e = (i) => {
      const n = 1 - i.deltaY / 1e3, r = new j(i.offsetX, i.offsetY, 0).applyMatrix4(
        this.clipMat.clone().multiply(this.cameraMat).invert()
      );
      this.scale([r.x, r.y], n);
    };
    t.addEventListener("wheel", e), this.wheelDestory = () => t.removeEventListener("wheel", e);
  }
  move(t, e = this.cameraMat) {
    this.mutMat(
      new ot().setPosition(t[0], t[1], 0),
      e
    );
  }
  scale(t, e, i = this.cameraMat) {
    this.mutMat(
      new ot().makeTranslation(t[0], t[1], 0).multiply(
        new ot().makeScale(e, e, 1).multiply(new ot().makeTranslation(-t[0], -t[1], 0))
      ),
      i
    );
  }
  rotate(t, e, i = this.cameraMat) {
    this.mutMat(
      new ot().makeTranslation(t[0], t[1], 0).multiply(
        new ot().makeRotationAxis(new j(0, 0, 1), e).multiply(new ot().makeTranslation(-t[0], -t[1], 0))
      ),
      i
    );
  }
  mutMat(t, e = this.cameraMat) {
    t instanceof ot ? e = e.clone().multiply(t) : e = e.multiply(new ot().fromArray(t)), this.setCameraMat(e), this.bus.emit("cameraChange", this.cameraMat.toArray());
  }
  setCameraMat(t) {
    t instanceof ot ? this.cameraMat = t : this.cameraMat.fromArray(t), this.update();
  }
  autoBound(t, e = [".adsord-point"]) {
    const i = e.flatMap(
      (r) => this.tree.stage.find(r).map((a) => a.position())
    );
    if (i.length < 2)
      return;
    const n = [
      Number.MAX_VALUE,
      Number.MAX_VALUE,
      -Number.MAX_VALUE,
      -Number.MAX_VALUE
    ];
    for (const r of i)
      n[0] = Math.min(n[0], r.x), n[1] = Math.min(n[1], r.y), n[2] = Math.max(n[2], r.x), n[3] = Math.max(n[3], r.y);
    this.setBound(n, t);
  }
  setBound(t, e, i = !1) {
    e = Array.isArray(e) ? e : [e || 0, e || 0], e.length === 1 && e.push(e[0]);
    const n = t[2] - t[0], r = t[3] - t[1], a = this.tree.stage.width(), o = this.tree.stage.height(), h = this.tree.stage.width() - e[0] * 2, l = this.tree.stage.height() - e[1] * 2;
    let A = h / n, u = l / r;
    if (i) {
      const p = Math.min(A, u);
      A = p, u = p;
    }
    const f = (a - n * A) / 2 - t[0] * A, d = (o - r * u) / 2 - t[1] * u, c = new ot().scale(new j(A, u, 1)).setPosition(f, d, 0);
    this.bound = t, this.padding = e, this.clipMat = c, this.update();
  }
  setSize(t, e) {
    this.tree.stage.width(t), this.tree.stage.height(e), this.bound && this.setBound(this.bound, this.padding);
  }
  setTree(t) {
    this.tree = t, this.props.move && this.enableMove(), this.props.wheel && this.enableWheel();
  }
  update() {
    console.log(this.clipMat.clone().multiply(this.cameraMat)), this.tree.updateViewMat(this.clipMat.clone().multiply(this.cameraMat));
  }
}
const mu = (s, t) => {
  const e = t.parent, i = { width: 43, height: 44 }, n = new _i({
    data: "M22 44C32.6667 33.891 38 25.891 38 20C38 11.1634 30.8366 4 22 4C13.1634 4 6 11.1634 6 20C6 25.891 11.3333 33.891 22 44Z",
    strokeScaleEnabled: !0,
    stroke: "#ffffff",
    strokeWidth: 1
  }), r = new _i({
    fill: "#fff",
    data: "M22 30C27.5228 30 32 25.5228 32 20C32 14.4772 27.5228 10 22 10C16.4772 10 12 14.4772 12 20C12 25.5228 16.4772 30 22 30Z"
  }), a = new _i({
    fill: "#409EFF",
    offset: {
      x: -5,
      y: -5
    },
    data: "M20.5143 12.213C20.7983 12.497 20.7983 12.9575 20.5143 13.2415L15.2727 18.4831L11.8494 15.0597C11.5654 14.7757 11.5654 14.3152 11.8494 14.0312C12.1334 13.7472 12.5939 13.7472 12.8779 14.0312L15.2727 16.426L19.4857 12.213C19.7698 11.929 20.2302 11.929 20.5143 12.213Z"
  }), o = new Yt({
    name: "anchor-move"
  }), h = new Ri({
    name: "anchor-move",
    radius: Math.min(i.width, i.height) / 2,
    fill: "rgba(0, 0, 0, 0)",
    offset: { x: -i.width / 2, y: -i.height / 2 }
  }), l = Dn();
  Mt.radius = 5, Mt.hitStrokeWidth = Mt.strokeWidth = 4, l.shape.name("anchor-point");
  const A = new Qr({
    name: "text",
    text: "1",
    fontFamily: "Calibri",
    fontSize: 12,
    padding: 5,
    offsetY: -8,
    fill: "#000"
  }), u = new Fo({
    visible: !1,
    opacity: 0.75,
    name: "label",
    offsetX: -i.width / 2,
    offsetY: -6
  });
  o.add(A, u, h), u.add(
    new Mo({
      name: "tag",
      fill: "rgba(255, 255, 255, 0.8)",
      pointerDirection: "down",
      pointerWidth: 5,
      pointerHeight: 5,
      lineJoin: "round",
      shadowColor: "black",
      shadowBlur: 10,
      shadowOffsetX: 10,
      shadowOffsetY: 10,
      shadowOpacity: 0.5
    }),
    new Qr({
      name: "text",
      text: s.title || `P${s.id}`,
      fontFamily: "Calibri",
      fontSize: 10,
      padding: 5,
      fill: "#000"
    })
  );
  const f = new Yt();
  f.add(n, r, a, o), f.x(-i.width / 2), f.y(-i.height);
  const d = new Yt();
  return d.add(f, l.shape), {
    shape: d,
    common() {
      n.fill(s.rtk ? "rgba(230, 162, 60, 1)" : "#409EFF"), a.fill(s.rtk ? "rgba(230, 162, 60, 1)" : "#409EFF"), l.common(), u.visible(!1);
    },
    hover: () => {
      u.visible(!0);
    },
    setData(p) {
      let [m, v] = Nt(d, [1, 1]);
      d.scale({ x: m, y: v }), d.x(p[0]), d.y(p[1]), ~t.editPolygonNdx ? (A.text((t.editPolygonNdx + 1).toString()).visible(!0), A.offsetX(-h.width() / 2 + A.width() / 2), l.shape.visible(!0), a.visible(!1)) : (A.visible(!1), l.shape.visible(!1), a.visible(e.status.selectPoiIds.includes(s.id)));
    },
    draging() {
      ~t.editPolygonNdx && (n.fill("#e0403c"), a.fill("#e0403c"));
    },
    active() {
      e.bus.emit("clickPoint", s), u.visible(!0);
    }
  };
};
class vu extends Rt {
  constructor() {
    super(...arguments), this.actShape = null;
  }
  get editPolygonNdx() {
    const t = this.parent;
    return t.status.editPolygonId ? Fi(
      t.attrib,
      t.status.editPolygonId
    ).map(({ id: i }) => i).indexOf(this.attrib.id) : -1;
  }
  init() {
    this.actShapeFactory = mu, super.init(), this.enableMouseAct(this.actShape);
  }
  initReactive() {
    const t = this.parent;
    return _o(
      super.initReactive(),
      xn(() => {
        t.status.editPolygonId === this.attrib.id ? this.bus.emit("statusChange", { active: !0 }) : this.bus.emit("statusChange", { active: !1 });
      }),
      Me(
        () => this.editPolygonNdx,
        (e, i, n) => {
          ~e || n(() => {
          });
          const r = this.shape.findOne(".anchor-move");
          let a = null;
          r.on("mouseenter.anchor", () => {
            a && a(), a = this.container.setCursor("move");
          }), r.on("mouseleave.anchor", () => {
            a && a(), a = null;
          }), ln(this, {
            readyHandler: (o) => [o.x, o.y],
            moveHandler: (o, h) => {
              ~this.editPolygonNdx && (o.x = h[0], o.y = h[1]);
            }
          }), n(() => {
            r.off("mouseenter.anchor mouseleave.anchor"), a && a(), this.disableDrag();
          });
        },
        { immediate: !0 }
      )
    );
  }
}
const _u = (s, t) => {
  const e = t.parent, i = Tn({
    autoClose: !0
  }), n = i.shape.findOne(".polygon-line");
  return {
    ...i,
    common() {
      n.fill("rgba(0, 0, 0, 0)"), i.closeLine.common();
    },
    hover() {
      n.fill("rgba(0, 0, 0, 0.3)"), i.closeLine.hover();
    },
    active() {
      n.fill("rgba(0, 0, 0, 0.3)"), i.closeLine.active(), e.status.newModel || e.bus.emit("clickPolygon", s);
    }
  };
};
class xu extends ki {
  constructor() {
    super(...arguments), this.actShapeFactory = _u;
  }
  init() {
    super.init(), this.enableMouseAct(this.actShape);
  }
  initReactive() {
    const t = this.parent;
    return _o(
      super.initReactive(),
      xn(
        () => {
          t.status.editPolygonId === this.attrib.id ? this.bus.emit("statusChange", { active: !0 }) : this.bus.emit("statusChange", { active: !1 });
        },
        { flush: "post" }
      )
    );
  }
}
const bu = (s) => ({
  rtk: !1,
  title: "",
  x: s[0],
  y: s[1]
}), wu = (s, t) => {
  const e = t.parent, i = hi(), n = () => !!(e.status.editPolygonId && eh(
    e.attrib,
    e.status.editPolygonId
  ).some(({ id: o }) => o === s.id)), r = () => {
    n() ? i.active() : i.common();
  };
  return {
    shape: i.shape,
    setData(a) {
      i.setData(a), r();
    },
    common: r
  };
};
class Su extends Di {
  constructor() {
    super(...arguments), this.status = Ti({
      selectPoiIds: ["108", "109", "110"],
      newModel: !1
    });
  }
  removePolygon(t) {
    const e = this.attrib.polygons.findIndex(({ id: r }) => r === t);
    if (!~e)
      return;
    const i = this.attrib.polygons[e].lineIds;
    let n = [];
    for (; i.length; ) {
      const r = this.attrib.lines.findIndex(
        ({ id: a }) => a === i[0]
      );
      ~r && (n.push(...this.attrib.lines[r].pointIds), this.attrib.lines.splice(r, 1)), i.shift();
    }
    for (n = Array.from(new Set(n)); n.length; ) {
      const r = this.attrib.points.findIndex(
        ({ id: a }) => a === n[0]
      );
      ~r && !this.attrib.points[r].rtk && this.attrib.points.splice(r, 1), n.shift();
    }
    this.attrib.polygons.splice(e, 1);
  }
  initIncFactory() {
    super.initIncFactory(), this.incPointsFactory = Pt(vu, this), this.incLinesFactory = Pt(
      qt,
      this,
      (t) => {
        t.setConfig(this.attrib), t.actShapeFactory = wu;
      }
    ), this.incPolygonFactory = Pt(xu, this, (t) => {
      t.setConfig(this.attrib);
    });
  }
  editPolygon(t) {
    return this.endEditPolygon && this.endEditPolygon(), this.status.newModel = !t, this.endEditPolygon = ks(
      {
        polygonId: t,
        pointAttribFactory: bu,
        canOper: (e, i) => !e.name.includes(Rt.namespace) || i.name() === "anchor-point",
        quitHandler: () => {
          this.status.newModel = !1, this.bus.emit("penEndHandler");
        },
        canDelPoint: (e) => !e.rtk,
        quotePoint: !1,
        closeAutoQuit: !0,
        tree: this.container,
        autoAdd: !1,
        autoClose: !0,
        config: this.attrib,
        changePolygon: (e) => {
          this.status.editPolygonId = e;
        }
      },
      this.shape
    ), this.endEditPolygon;
  }
  destory() {
    this.endEditPolygon && this.endEditPolygon(), super.destory();
  }
}
function Cu(s) {
  const t = Mu();
  for (let e = 0, i = s.length; e < i; ++e)
    Pu(t, s[e]);
  return t;
}
function Mu() {
  return [1 / 0, 1 / 0, -1 / 0, -1 / 0];
}
function Pu(s, t) {
  t[0] < s[0] && (s[0] = t[0]), t[0] > s[2] && (s[2] = t[0]), t[1] < s[1] && (s[1] = t[1]), t[1] > s[3] && (s[3] = t[1]);
}
const Eu = (s, t, e) => {
  const i = () => e.getView().calculateExtent(e.getSize()), n = (o) => {
    const h = Cu([
      [o[0], o[1]],
      [o[2], o[3]]
    ]);
    e.getView().fit(h, {
      size: e.getSize(),
      padding: [0, 0, 0, 0],
      // 根据需要调整边距
      maxZoom: 19.5
      // 防止过度放大
    });
  }, r = () => {
    if (t && e) {
      const o = i();
      s.setSize(t.offsetWidth, t.offsetHeight), s.setBound([o[0], o[3], o[2], o[1]]);
    }
  }, a = (o) => {
    e && e.removeEventListener("moveend", r), o.addEventListener("moveend", r), e = o, r();
  };
  return s.enableMove((o) => (e && n(o), !0)), s.enableWheel((o) => (e && n(o), !0)), {
    setMap: a,
    setMountDom(o) {
      t = o, r();
    },
    destory() {
      e.removeEventListener("moveend", r);
    }
  };
}, Fu = nu(
  { polygons: Su },
  { bound: new au() }
), r1 = (s = {}) => {
  const t = s.store || [
    { id: "0", points: [], polygons: [], lines: [] }
  ], e = Fu(s.dom, { polygons: t }, !1), i = Eu(e.bound, s.dom, s.map);
  return e.tree.bus.on("active", (n) => {
    console.log(n);
  }), {
    raw: e,
    setProps(n) {
      n.dom && (e.mount(n.dom), i.setMountDom(n.dom)), n.map && i.setMap(n.map);
    },
    getData() {
      return e.getData().polygons;
    },
    setData(n) {
      e.setData({ polygons: [n] });
    },
    destory() {
      i.destory(), e.destory();
    },
    get polygon() {
      return e.tree.children[0];
    },
    getPixelFromCoordinate(n) {
      return e.tree.getPixelFromStage(n);
    }
  };
};
export {
  au as BoundQueryPlugin,
  n1 as CameraQueryPlugin,
  eu as Container,
  jt as DEV,
  e1 as EditPoi,
  Zu as EditWholeLine,
  me as Entity,
  i1 as HistoryPlugin,
  Ju as PenEditWholeLine,
  ns as Poi,
  Su as Polygons,
  fo as RelationshipEnum,
  Di as WholeLine,
  qt as WholeLineLine,
  Jr as WholeLineLineHelper,
  Rt as WholeLinePoint,
  ts as WholeLinePointHelper,
  ki as WholeLinePolygon,
  Xu as addEntityAttrib,
  Du as changeEnv,
  Jc as closePenPolygonActShapeFactory,
  IA as copyEntityAttrib,
  r1 as createBoard,
  qe as createLineByDire,
  iu as defaultPoiShapeFactory,
  rn as depPartialUpdate,
  $u as deptComputed,
  po as disableMouse,
  yo as enableMouse,
  TA as entityFactory,
  se as eqPoint,
  Nr as fixWholeLineConfig,
  kA as generateId,
  Qo as generateWholeLineLineId,
  Ko as generateWholeLinePointId,
  Zo as generateWholeLinePoygonId,
  on as getAbsoluteTransform,
  ca as getActiveKey,
  fs as getChangeAllPoart,
  us as getChangePart,
  Ye as getDire2Angle,
  Ou as getDireDist,
  vo as getFlatChildren,
  bA as getLine2Angle,
  Gu as getLineCenter,
  Ae as getLineDire,
  wA as getLineDireAngle,
  Et as getLineDist,
  zu as getLineInnerContinuityPoints,
  go as getLineIntersection,
  CA as getLineNearPoint,
  MA as getLineNearPointDist,
  Gi as getLineProjection,
  SA as getLineRelationship,
  Nt as getRealAbsoluteSize,
  _A as getRotateDire,
  Iu as getTfScaleFactors,
  eo as getTouchOffset,
  xA as getVerticaLineDire,
  ds as getVerticalDire,
  Nu as getVerticalDireLine,
  di as getWholeLineLine,
  nh as getWholeLineLineNdxByPointIds,
  wt as getWholeLineLineRaw,
  qu as getWholeLineLines,
  Qu as getWholeLineLinesByPointId,
  th as getWholeLineLinesRaw,
  Dc as getWholeLineLinesRawByPoint,
  Jo as getWholeLineLinesRawByPointId,
  kc as getWholeLineLinesRawByPointIds,
  Ce as getWholeLinePoint,
  Uc as getWholeLinePointMerge,
  _t as getWholeLinePoints,
  Ku as getWholeLinePolygonByPoint,
  Tc as getWholeLinePolygonLines,
  ih as getWholeLinePolygonLinesByPoint,
  eh as getWholeLinePolygonLinesRaw,
  Fi as getWholeLinePolygonPoints,
  ci as getWholeLinePolygonRaw,
  an as hasTouchEvents,
  oi as inRevise,
  Pt as incEntitysFactoryGenerate,
  t1 as injectPoiType,
  Tu as isMobile,
  vi as mergeChange,
  _o as mergeFuns,
  Hc as mergeWholeLinePointsByPoint,
  Qc as needUpdatePolygonClose,
  PA as objectToString,
  ln as openEntityDrag,
  cs as openShapeDrag,
  ua as openShapeMouseStyles,
  Wu as partialComputed,
  Lu as pathsToActShape,
  Zc as penLineActShapeFactory,
  tu as penPolygonActShapeFactory,
  Va as penWholeLinePoygonsEdit,
  qc as penWholeLinePoygonsEditWithHelperMouse,
  ks as penWholeLinePoygonsEditWithHelperShapesMouse,
  lh as poiTypes,
  Bu as polygonCounterclockwise,
  nu as register,
  Vc as repeatMoveWholeLineLine,
  Gc as repeatablePushWholeLinePoint,
  Bc as repeatableWholeLineLineIntersections,
  he as round,
  Hu as setShapeConfig,
  FA as shapeParentsEq,
  Uu as shapeTreeContain,
  mo as shapeTreeEq,
  zc as spliceWholeLineLineByLines,
  Or as spliceWholeLineLineByPoint,
  Yu as testPoint,
  hn as toRawType,
  EA as toTypeString,
  Vu as watchAttribs,
  ce as wholeLineAddLineByPointIds,
  Qe as wholeLineAddPoint,
  Kc as wholeLineAnalysisHelperInfo,
  ei as wholeLineDelLineByPointIds,
  za as wholeLineDelPointByPointIds,
  rh as wholeLineDelPolygon,
  Lc as wholeLineFixLineAddPoint,
  es as wholeLineLineAddPoint,
  Ic as wholeLineLineIsolatePoint,
  Nc as wholeLinePolygonAddPoint,
  Oc as wholeLinePolygonLastAddPoint,
  is as wholeLineReplacePoint,
  ju as wholeLineStyle
};
