plotboilerplate 1.23.2 → 1.23.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/index.esm.js +7052 -6754
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.esm.min.js +1 -1
  4. package/dist/index.esm.min.js.map +1 -1
  5. package/dist/plotboilerplate.browser.min.js +1 -1
  6. package/dist/plotboilerplate.browser.min.js.map +1 -1
  7. package/dist/plotboilerplate.js +329 -27
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +4 -2
  10. package/src/cjs/PlotBoilerplate.d.ts +4 -2
  11. package/src/cjs/PlotBoilerplate.js +7 -3
  12. package/src/cjs/PlotBoilerplate.js.map +1 -1
  13. package/src/cjs/Polygon.d.ts +107 -4
  14. package/src/cjs/Polygon.js +215 -9
  15. package/src/cjs/Polygon.js.map +1 -1
  16. package/src/cjs/Triangle.d.ts +23 -3
  17. package/src/cjs/Triangle.js +15 -2
  18. package/src/cjs/Triangle.js.map +1 -1
  19. package/src/cjs/VertTuple.d.ts +12 -7
  20. package/src/cjs/VertTuple.js +14 -9
  21. package/src/cjs/VertTuple.js.map +1 -1
  22. package/src/cjs/Vertex.d.ts +2 -1
  23. package/src/cjs/Vertex.js +5 -2
  24. package/src/cjs/Vertex.js.map +1 -1
  25. package/src/cjs/draw.d.ts +1 -0
  26. package/src/cjs/draw.js +2 -1
  27. package/src/cjs/draw.js.map +1 -1
  28. package/src/cjs/drawutilssvg.js +24 -0
  29. package/src/cjs/drawutilssvg.js.map +1 -1
  30. package/src/cjs/geomutils.d.ts +32 -1
  31. package/src/cjs/geomutils.js +47 -1
  32. package/src/cjs/geomutils.js.map +1 -1
  33. package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
  34. package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
  35. package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
  36. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
  37. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
  38. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  39. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
  40. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
  41. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  42. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
  43. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
  44. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  45. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  46. package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
  47. package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
  48. package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
  49. package/src/esm/PlotBoilerplate.d.ts +4 -2
  50. package/src/esm/PlotBoilerplate.js +7 -3
  51. package/src/esm/PlotBoilerplate.js.map +1 -1
  52. package/src/esm/Polygon.d.ts +107 -4
  53. package/src/esm/Polygon.js +214 -9
  54. package/src/esm/Polygon.js.map +1 -1
  55. package/src/esm/Triangle.d.ts +23 -3
  56. package/src/esm/Triangle.js +15 -2
  57. package/src/esm/Triangle.js.map +1 -1
  58. package/src/esm/VertTuple.d.ts +12 -7
  59. package/src/esm/VertTuple.js +14 -9
  60. package/src/esm/VertTuple.js.map +1 -1
  61. package/src/esm/Vertex.d.ts +2 -1
  62. package/src/esm/Vertex.js +5 -2
  63. package/src/esm/Vertex.js.map +1 -1
  64. package/src/esm/draw.d.ts +1 -0
  65. package/src/esm/draw.js +2 -1
  66. package/src/esm/draw.js.map +1 -1
  67. package/src/esm/drawutilssvg.js +24 -0
  68. package/src/esm/drawutilssvg.js.map +1 -1
  69. package/src/esm/geomutils.d.ts +32 -1
  70. package/src/esm/geomutils.js +47 -1
  71. package/src/esm/geomutils.js.map +1 -1
  72. package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
  73. package/src/esm/utils/algorithms/PolygonInset.js +424 -0
  74. package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
  75. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
  76. package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
  77. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  78. package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
  79. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
  80. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  81. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
  82. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
  83. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  84. package/src/esm/utils/detectDarkMode.js.map +1 -1
  85. package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
  86. package/src/esm/utils/dom/guiSizeToggler.js +4 -2
  87. package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
  88. package/src/ts/PlotBoilerplate.ts +7 -3
  89. package/src/ts/Polygon.ts +230 -9
  90. package/src/ts/Triangle.ts +18 -4
  91. package/src/ts/VertTuple.ts +15 -10
  92. package/src/ts/Vertex.ts +5 -2
  93. package/src/ts/draw.ts +2 -1
  94. package/src/ts/drawutilssvg.ts +29 -0
  95. package/src/ts/geomutils.ts +49 -1
  96. package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
  97. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
  98. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
  99. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
  100. package/src/ts/utils/detectDarkMode.ts +1 -3
  101. package/src/ts/utils/dom/guiSizeToggler.ts +4 -2
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{constructor(){for(var e in this.draggable=!0,this.selectable=!0,this.isSelected=!1,this.visible=!0,t.model)this[e]=t.model[e]}}t.model={draggable:!0,selectable:!0,isSelected:!1,visible:!0};class e{static next(){return""+e.current++}}e.current=0;class s{constructor(t){this.click=[],this.drag=[],this.dragStart=[],this.dragEnd=[],this.vertex=t}addClickListener(t){return s._addListener(this.click,t),this}removeClickListener(t){return this.click=s._removeListener(this.click,t),this}addDragListener(t){return s._addListener(this.drag,t),this}removeDragListener(t){return this.drag=s._removeListener(this.drag,t),this}addDragStartListener(t){return s._addListener(this.dragStart,t),this}removeDragStartListener(t){return this.dragStart=s._removeListener(this.dragStart,t),this}addDragEndListener(t){return s._addListener(this.dragEnd,t),this}removeDragEndListener(t){return this.dragEnd=s._removeListener(this.dragEnd,t),this}fireClickEvent(t){s._fireEvent(this,this.click,t)}fireDragEvent(t){s._fireEvent(this,this.drag,t)}fireDragStartEvent(t){s._fireEvent(this,this.dragStart,t)}fireDragEndEvent(t){s._fireEvent(this,this.dragEnd,t)}removeAllListeners(){this.click=[],this.drag=[],this.dragStart=[],this.dragEnd=[]}static _fireEvent(t,e,s){const i=s;for(var r in void 0===i.params?i.params={vertex:t.vertex}:i.params.vertex=t.vertex,e)e[r](i)}static _addListener(t,e){for(var s in t)if(t[s]==e)return!1;return t.push(e),!0}static _removeListener(t,e){for(var s=0;s<t.length;s++)if(t[s]==e)return t.splice(s,1);return t}}class i{constructor(i,r){if(this.className="Vertex",this.uid=e.next(),void 0===i)this.x=0,this.y=0;else if("number"==typeof i&&"number"==typeof r)this.x=i,this.y=r;else{const t=i;"number"==typeof t.x&&"number"==typeof t.y?(this.x=t.x,this.y=t.y):(this.x="number"==typeof i?i:void 0===i?0:NaN,this.y="number"==typeof r?r:void 0===r?0:NaN)}this.attr=new t,this.listeners=new s(this)}set(t,e){if("number"==typeof t&&"number"==typeof e)this.x=t,this.y=e;else{const s=t;"number"==typeof s.x&&"number"==typeof s.y?(this.x=s.x,this.y=s.y):(this.x="number"==typeof t?t:void 0===t?0:NaN,this.y="number"==typeof e?e:void 0===e?0:NaN)}return this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}invX(){return this.x=-this.x,this}invY(){return this.y=-this.y,this}add(t,e){if("number"==typeof t&&"number"==typeof e)this.x+=t,this.y+=e;else{const s=t;if("number"==typeof s.x&&"number"==typeof s.y)this.x+=s.x,this.y+=s.y;else{if("number"!=typeof t)throw`Cannot add ${typeof t} to numeric x component!`;if(this.x+=t,"number"!=typeof e)throw`Cannot add ${typeof e} to numeric y component!`;this.y+=e}}return this}addXY(t,e){return this.x+=t,this.y+=e,this}addX(t){return this.x+=t,this}addY(t){return this.y+=t,this}sub(t,e){if("number"==typeof t&&"number"==typeof e)this.x-=t,this.y-=e;else{const s=t;if("number"==typeof s.x&&"number"==typeof s.y)this.x-=s.x,this.y-=s.y;else{if("number"!=typeof t)throw`Cannot add ${typeof t} to numeric x component!`;if(this.x-=t,"number"!=typeof e)throw`Cannot add ${typeof e} to numeric y component!`;this.y-=e}}return this}subXY(t,e){return this.x-=t,this.y-=e,this}subX(t){return this.x-=t,this}subY(t){return this.y-=t,this}equals(t){var e=Math.abs(this.x-t.x)<i.EPSILON,s=Math.abs(this.y-t.y)<i.EPSILON;return e&&s}clone(){return new i(this.x,this.y)}distance(t){return Math.sqrt(Math.pow(t.x-this.x,2)+Math.pow(t.y-this.y,2))}angle(t){const e=void 0===t?Math.PI/2-Math.atan2(this.x,this.y):Math.PI/2-Math.atan2(t.x-this.x,t.y-this.y);return e<0?2*Math.PI+e:e}difference(t){return new i(t.x-this.x,t.y-this.y)}scale(t,e){return this.scaleXY({x:t,y:t},e)}lerp(t,e){var s=this.difference(t);return this.x+=s.x*e,this.y+=s.y*e,this}lerpAbs(t,e){var s=this.distance(t),i=this.difference(t),r=i.x/s,n=i.y/s;return this.x+=r*e,this.y+=n*e,this}scaleXY(t,e){return e&&void 0!==e||(e={x:0,y:0}),this.x=e.x+(this.x-e.x)*t.x,this.y=e.y+(this.y-e.y)*t.y,this}rotate(t,e){e&&void 0!==e||(e={x:0,y:0}),this.sub(e),t+=Math.atan2(this.y,this.x);let s=this.distance(i.ZERO);return this.x=s*Math.cos(t),this.y=s*Math.sin(t),this.add(e),this}multiplyScalar(t){return this.x*=t,this.y*=t,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}inv(){return this.x=-this.x,this.y=-this.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}toString(t){return void 0===t?"("+this.x+","+this.y+")":"("+this.x.toFixed(t)+","+this.y.toFixed(t)+")"}destroy(){this.listeners.removeAllListeners(),this.isDestroyed=!0}static randomVertex(t){return new i(t.min.x+Math.random()*(t.max.x-t.min.x),t.min.y+Math.random()*(t.max.y-t.min.y))}}i.ZERO=new i(0,0),i.EPSILON=1e-6,i.utils={buildArrowHead:(t,e,s,r,n)=>{console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");var a=Math.atan2((e.y-t.y)*n,(e.x-t.x)*r),h=[];return h.push(new i(e.x*r-s*Math.cos(a),e.y*n-s*Math.sin(a))),h.push(new i(e.x*r-1.35*s*Math.cos(a-Math.PI/8),e.y*n-1.35*s*Math.sin(a-Math.PI/8))),h.push(new i(e.x*r,e.y*n)),h.push(new i(e.x*r-1.35*s*Math.cos(a+Math.PI/8),e.y*n-1.35*s*Math.sin(a+Math.PI/8))),h},arrayToJSON:(t,e)=>JSON.stringify(t.map((function(t){return void 0===typeof e?{x:t.x,y:t.y}:{x:Number(t.x.toFixed(e)),y:Number(t.y.toFixed(e))}})))};class r{constructor(t,s,i){this.uid=e.next(),this.a=t,this.b=s,this.factory=i}length(){return Math.sqrt(Math.pow(this.b.x-this.a.x,2)+Math.pow(this.b.y-this.a.y,2))}setLength(t){return this.scale(t/this.length())}sub(t){return this.a.sub(t),this.b.sub(t),this}add(t){return this.a.add(t),this.b.add(t),this}normalize(){return this.b.set(this.a.x+(this.b.x-this.a.x)/this.length(),this.a.y+(this.b.y-this.a.y)/this.length()),this}scale(t){return this.b.set(this.a.x+(this.b.x-this.a.x)*t,this.a.y+(this.b.y-this.a.y)*t),this}moveTo(t){let e=this.a.difference(t);return this.a.add(e),this.b.add(e),this}angle(t){null!=t&&void 0!==t||(t=this.factory(new i(0,0),new i(100,0)));const e=this.b.clone().sub(this.a),s=t.b.clone().sub(t.a);return Math.atan2(s.x,s.y)-Math.atan2(e.x,e.y)}vertAt(t){return new i(this.a.x+(this.b.x-this.a.x)*t,this.a.y+(this.b.y-this.a.y)*t)}denominator(t){return(t.b.y-t.a.y)*(this.b.x-this.a.x)-(t.b.x-t.a.x)*(this.b.y-this.a.y)}colinear(t){return Math.abs(this.denominator(t))<i.EPSILON}getClosestT(t){var e=r.vtutils.dist2(this.a,this.b);return 0===e?0:((t.x-this.a.x)*(this.b.x-this.a.x)+(t.y-this.a.y)*(this.b.y-this.a.y))/e}hasPoint(t,e){const s=this.getClosestT(t),n=Math.sqrt(r.vtutils.dist2(t,this.vertAt(s)));return void 0!==e&&e?n<i.EPSILON&&s>=0&&s<=1:n<i.EPSILON}getClosestPoint(t){var e=this.getClosestT(t);return this.vertAt(e)}pointDistance(t){return Math.sqrt(r.vtutils.dist2(t,this.vertAt(this.getClosestT(t))))}clone(){return this.factory(this.a.clone(),this.b.clone())}toString(){return"{ a : "+this.a.toString()+", b : "+this.b.toString()+" }"}destroy(){this.a.destroy(),this.b.destroy(),this.isDestroyed=!0}}r.vtutils={dist2:(t,e)=>(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)};class n extends r{constructor(t,e){super(t,e,((t,e)=>new n(t,e))),this.className="Line"}intersection(t){const e=this.denominator(t);if(0==e)return null;let s=this.a.y-t.a.y,r=this.a.x-t.a.x;const n=(t.b.x-t.a.x)*s-(t.b.y-t.a.y)*r,a=(this.b.x-this.a.x)*s-(this.b.y-this.a.y)*r;s=n/e,r=a/e;const h=this.a.x+s*(this.b.x-this.a.x),o=this.a.y+s*(this.b.y-this.a.y);return isNaN(s)||isNaN(h)||isNaN(o)?null:new i(h,o)}getStartPoint(){return this.a}getEndPoint(){return this.b}getStartTangent(){return this.b}getEndTangent(){return this.a}reverse(){var t=this.a;return this.a=this.b,this.b=t,this}}class a{constructor(t,s){this.className="Polygon",this.uid=e.next(),void 0===t&&(t=[]),this.vertices=t,this.isOpen=s||!1}addVertex(t){this.vertices.push(t)}getVertexAt(t){return t<0?this.vertices[this.vertices.length-Math.abs(t)%this.vertices.length]:this.vertices[t%this.vertices.length]}move(t){for(var e in this.vertices)this.vertices[e].add(t);return this}containsVert(t){for(var e=!1,s=0,i=this.vertices.length-1;s<this.vertices.length;i=s++){let r=this.vertices[s].x,n=this.vertices[s].y,a=this.vertices[i].x,h=this.vertices[i].y;n>t.y!=h>t.y&&t.x<(a-r)*(t.y-n)/(h-n)+r&&(e=!e)}return e}containsPolygon(t){for(var e=0;e<t.vertices.length;e++)if(!this.containsVert(t.vertices[e]))return!1;const s=new n(new i,new i);for(e=0;e<t.vertices.length;e++)if(s.a.set(t.vertices[e]),s.b.set(t.vertices[(e+1)%t.vertices.length]),this.lineIntersections(s,!0).length>0)return!1;return!0}area(){return a.utils.area(this.vertices)}signedArea(){return a.utils.signedArea(this.vertices)}isClockwise(){return a.utils.signedArea(this.vertices)<0}perimeter(){let t=0;for(var e=1;e<this.vertices.length;e++)t+=this.vertices[e-1].distance(this.vertices[e]);return!this.isOpen&&this.vertices.length>1&&(t+=this.vertices[0].distance(this.vertices[this.vertices.length-1])),t}scale(t,e){for(var s in this.vertices)"function"==typeof this.vertices[s].scale?this.vertices[s].scale(t,e):console.log("There seems to be a null vertex!",this.vertices[s]);return this}rotate(t,e){for(var s in this.vertices)this.vertices[s].rotate(t,e);return this}lineIntersections(t,e=!1){const s=[];for(var i=0;i<this.vertices.length;i++){const r=new n(this.vertices[i],this.vertices[(i+1)%this.vertices.length]),a=r.intersection(t);this.isOpen&&i+1===this.vertices.length||null===a||!r.hasPoint(a,!0)||e&&!t.hasPoint(a,e)||s.push(a)}return s}closestLineIntersection(t,e=!1){const s=this.lineIntersections(t,e);if(s.length<=0)return null;let r=new i(Number.MAX_VALUE,Number.MAX_VALUE),n=Number.MAX_VALUE;for(var a in s){const e=s[a],i=e.distance(t.a);i<n&&(n=i,r=e)}return r}getInterpolationPolygon(t){const e=[];for(var s=0;s<this.vertices.length;s++){const r=this.vertices[s],n=this.vertices[(s+1)%this.vertices.length];if(e.push(r.clone()),!this.isOpen||s+1!==this.vertices.length){const s=1/(t+1);for(var i=1;i<=t;i++)e.push(r.clone().lerp(n,s*i))}}return new a(e,this.isOpen)}getEvenDistributionPolygon(t){if(t<=0)throw new Error("pointCount must be larger than zero; is "+t+".");const e=new a([],this.isOpen);if(0===this.vertices.length)return e;let s=new i(this.vertices[0]);if(e.vertices.push(s),1===this.vertices.length)return e;const r=this.perimeter()/t,n=this.vertices.length;let h=1,o=new i(this.vertices[1]),l=s.distance(o),c=this.isOpen?n:n+1,d=r;for(var u=1;u<t&&h<c;)if(d<l){let t=s.clone().lerpAbs(o,d);e.vertices.push(t),d+=r,u++}else h++,s=o,o=new i(this.vertices[h%n]),d-=l,l=s.distance(o);return e}getBounds(){return h.computeFromVertices(this.vertices)}clone(){return new a(this.vertices.map((t=>t.clone())),this.isOpen)}toQuadraticBezierData(){if(this.vertices.length<3)return[];var t=[],e=this.vertices[0],s=this.vertices[1],r=new i(e.x+(s.x-e.x)/2,e.y+(s.y-e.y)/2);t.push(r);for(var n=this.isOpen?this.vertices.length:this.vertices.length+1,a=1;a<n;a++){e=this.vertices[a%this.vertices.length],s=this.vertices[(a+1)%this.vertices.length];r=new i(e.x+(s.x-e.x)/2,e.y+(s.y-e.y)/2);t.push(e),t.push(r),e=s}return t}toQuadraticBezierSVGString(){var t=this.toQuadraticBezierData();if(0==t.length)return"";for(var e=["M "+t[0].x+" "+t[0].y],s=1;s<t.length;s+=2)e.push("Q "+t[s].x+" "+t[s].y+", "+t[s+1].x+" "+t[s+1].y);return e.join(" ")}toCubicBezierData(t){if(void 0===t&&(t=1),this.vertices.length<3)return[];var e=[],s=this.vertices[0],r=this.vertices[1],n=new i(s.x+(r.x-s.x)/2,s.y+(r.y-s.y)/2);e.push(n);for(var a=this.isOpen?this.vertices.length-1:this.vertices.length,h=0;h<a;h++){s=this.vertices[h%this.vertices.length],r=this.vertices[(h+1)%this.vertices.length];var o=this.vertices[(h+2)%this.vertices.length],l=new i(s.x+(r.x-s.x)/2,s.y+(r.y-s.y)/2),c=new i(r.x+(o.x-r.x)/2,r.y+(o.y-r.y)/2),d=new i(l.x+(r.x-l.x)*t,l.y+(r.y-l.y)*t),u=new i(c.x+(r.x-c.x)*t,c.y+(r.y-c.y)*t);e.push(d),e.push(u),e.push(c)}return e}toCubicBezierSVGString(t){var e=this.toCubicBezierData(t);if(0==e.length)return"";for(var s=["M "+e[0].x+" "+e[0].y],i=1;i<e.length;i+=3)s.push("C "+e[i].x+" "+e[i].y+", "+e[i+1].x+" "+e[i+1].y+", "+e[i+2].x+" "+e[i+2].y);return s.join(" ")}toCubicBezierPath(t){for(var e=this.toCubicBezierData(t),s=[],i=0;i+3<e.length;i+=3)s.push([e[i],e[i+3],e[i+1],e[i+2]]);return c.fromArray(s)}destroy(){for(var t=0;t<this.vertices.length;t++)this.vertices[t].destroy();this.isDestroyed=!0}}a.utils={area(t){let e=0;for(var s=0,i=t.length;s<i;s++){e+=t[s].x*t[(s+1)%i].y*.5,e-=t[(s+1)%i].x*t[s].y*.5}return Math.abs(e)},signedArea(t){let e=0;const s=t.length;for(var i=0;i<s;i++){const r=(i+1)%s;e+=(t[r].x-t[i].x)*(t[i].y+t[r].y)}return e}};class h{constructor(t,e){this.min=t,this.max=e,this.width=e.x-t.x,this.height=e.y-t.y}toPolygon(){return new a([new i(this.min),new i(this.max.x,this.min.y),new i(this.max),new i(this.min.x,this.max.y)],!1)}getCenter(){return new i(this.min.x+(this.max.x-this.min.x)/2,this.min.y+(this.max.y-this.min.y)/2)}randomPoint(t=0,e=0){const s=t>0&&t<1?this.width*t:t,r=e>0&&e<1?this.height*e:e;return new i(this.min.x+s+Math.random()*(this.width-2*s),this.min.y+r+Math.random()*(this.height-2*r))}toString(){return`{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`}clone(){return new h({x:this.min.x,y:this.min.y},{x:this.max.x,y:this.max.y})}static computeFromVertices(t){if(0==t.length)return new h(new i(0,0),new i(0,0));let e,s=t[0].x,r=t[0].x,n=t[0].y,a=t[0].y;for(var o in t)e=t[o],s=Math.min(s,e.x),r=Math.max(r,e.x),n=Math.min(n,e.y),a=Math.max(a,e.y);return new h(new i(s,n),new i(r,a))}static fromDimension(t,e,s){return new h(null!=s?s:{x:0,y:0},{x:(s?s.x:0)+t,y:(s?s.y:0)+e})}}class o extends r{constructor(t,e){super(t,e,((t,e)=>new o(t,e))),this.className="Vector"}perp(){var t=this.clone();return t.sub(this.a),(t=new o(new i,new i(-t.b.y,t.b.x))).a.add(this.a),t.b.add(this.a),t}inverse(){var t=this.a;return this.a=this.b,this.b=t,this}inv(){return this.b.x=this.a.x-(this.b.x-this.a.x),this.b.y=this.a.y-(this.b.y-this.a.y),this}intersection(t){var e=this.denominator(t);if(0==e)return null;var s=this.a.y-t.a.y,r=this.a.x-t.a.x,n=(t.b.x-t.a.x)*s-(t.b.y-t.a.y)*r,a=(this.b.x-this.a.x)*s-(this.b.y-this.a.y)*r;return s=n/e,r=a/e,new i(this.a.x+s*(this.b.x-this.a.x),this.a.y+s*(this.b.y-this.a.y))}getOrthogonal(){const t=this.a.clone(),e=this.b.clone().sub(this.a),s=e.x;return e.x=-e.y,e.y=s,new o(t,e.add(this.a))}}o.utils={buildArrowHead:(t,e,s,r,n)=>{const a=Math.atan2((e.y-t.y)*n,(e.x-t.x)*r),h=[];return h.push(new i(e.x*r-s*Math.cos(a),e.y*n-s*Math.sin(a))),h.push(new i(e.x*r-1.35*s*Math.cos(a-Math.PI/8),e.y*n-1.35*s*Math.sin(a-Math.PI/8))),h.push(new i(e.x*r,e.y*n)),h.push(new i(e.x*r-1.35*s*Math.cos(a+Math.PI/8),e.y*n-1.35*s*Math.sin(a+Math.PI/8))),h}};class l{constructor(t,s,i,r){this.START_POINT=l.START_POINT,this.START_CONTROL_POINT=l.START_CONTROL_POINT,this.END_CONTROL_POINT=l.END_CONTROL_POINT,this.END_POINT=l.END_POINT,this.uid=e.next(),this.startPoint=t,this.startControlPoint=i,this.endPoint=s,this.endControlPoint=r,this.curveIntervals=30,this.segmentCache=[],this.segmentLengths=[],this.updateArcLengths()}moveCurvePoint(t,e,s,i){t==this.START_POINT?(this.getStartPoint().add(e),s&&this.getStartControlPoint().add(e)):t==this.START_CONTROL_POINT?this.getStartControlPoint().add(e):t==this.END_CONTROL_POINT?this.getEndControlPoint().add(e):t==this.END_POINT?(this.getEndPoint().add(e),s&&this.getEndControlPoint().add(e)):console.log(`[CubicBezierCurve.moveCurvePoint] pointID '${t}' invalid.`),i&&this.updateArcLengths()}translate(t){return this.startPoint.add(t),this.startControlPoint.add(t),this.endControlPoint.add(t),this.endPoint.add(t),this}reverse(){let t=this.startPoint;return this.startPoint=this.endPoint,this.endPoint=t,t=this.startControlPoint,this.startControlPoint=this.endControlPoint,this.endControlPoint=t,this}getLength(){return this.arcLength}updateArcLengths(){let t=this.startPoint.clone(),e=new i(0,0),s=1/this.curveIntervals;this.segmentCache=[],this.segmentCache.push(this.startPoint),this.segmentLengths=[];let r=0;var n=0;let a;for(;n<=1;)e=this.getPointAt(n),this.segmentCache.push(e),a=t.distance(e),this.segmentLengths.push(a),r+=a,t=e,n+=s;this.arcLength=r}getClosestT(t){var e={t:0,tPrev:0,tNext:1},s=0;do{e=this.locateIntervalByDistance(t,e.tPrev,e.tNext,this.curveIntervals),s++}while(s<4&&this.getPointAt(e.tPrev).distance(this.getPointAt(e.tNext))>1);return e.t}locateIntervalByDistance(t,e,s,i){var r=-1,n=0,a=0;const h=s-e;for(var o=0;o<=i;o++){a=e+h*(o/i);var l=this.getPointAt(a).distance(t);(-1==r||l<n)&&(r=o,n=l)}return{t:e+h*(r/i),tPrev:e+h*(Math.max(0,r-1)/i),tNext:e+h*(Math.min(i,r+1)/i)}}getBounds(){var t=new i(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),e=new i(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);let s;for(var r=0;r<this.segmentCache.length;r++)s=this.segmentCache[r],t.x=Math.min(t.x,s.x),t.y=Math.min(t.y,s.y),e.x=Math.max(e.x,s.x),e.y=Math.max(e.y,s.y);return new h(t,e)}getStartPoint(){return this.startPoint}getEndPoint(){return this.endPoint}getStartControlPoint(){return this.startControlPoint}getEndControlPoint(){return this.endControlPoint}getPointByID(t){if(t==this.START_POINT)return this.startPoint;if(t==this.END_POINT)return this.endPoint;if(t==this.START_CONTROL_POINT)return this.startControlPoint;if(t==this.END_CONTROL_POINT)return this.endControlPoint;throw new Error(`Invalid point ID '${t}'.`)}getPointAt(t){const e=this.startPoint.x*Math.pow(1-t,3)+3*this.startControlPoint.x*t*Math.pow(1-t,2)+3*this.endControlPoint.x*Math.pow(t,2)*(1-t)+this.endPoint.x*Math.pow(t,3),s=this.startPoint.y*Math.pow(1-t,3)+3*this.startControlPoint.y*t*Math.pow(1-t,2)+3*this.endControlPoint.y*Math.pow(t,2)*(1-t)+this.endPoint.y*Math.pow(t,3);return new i(e,s)}getPoint(t){return this.getPointAt(t/this.arcLength)}getTangentAt(t){const e=this.getStartPoint(),s=this.getStartControlPoint(),r=this.getEndControlPoint(),n=this.getEndPoint(),a=t*t,h=1-2*t+a,o=-3*e.x*h+s.x*(3*h-6*(t-a))+r.x*(6*(t-a)-3*a)+3*n.x*a,l=-3*e.y*h+s.y*(3*h-6*(t-a))+r.y*(6*(t-a)-3*a)+3*n.y*a;return new i(o,l)}trimStart(t){return this.trimStartAt(this.convertU2T(t))}trimStartAt(t){const e=l.utils.getSubCurvePointsAt(this,t,1);return this.startPoint.set(e[0]),this.startControlPoint.set(e[2]),this.endPoint.set(e[1]),this.endControlPoint.set(e[3]),this.updateArcLengths(),this}trimEnd(t){return this.trimEndAt(this.convertU2T(t))}trimEndAt(t){const e=l.utils.getSubCurvePointsAt(this,0,t);return this.startPoint.set(e[0]),this.startControlPoint.set(e[2]),this.endPoint.set(e[1]),this.endControlPoint.set(e[3]),this.updateArcLengths(),this}getSubCurve(t,e){return this.getSubCurveAt(this.convertU2T(t),this.convertU2T(e))}getSubCurveAt(t,e){const s=l.utils.getSubCurvePointsAt(this,t,e);return new l(s[0],s[1],s[2],s[3])}convertU2T(t){return Math.max(0,Math.min(1,t/this.arcLength))}getTangent(t){return this.getTangentAt(this.convertU2T(t))}getPerpendicular(t){return this.getPerpendicularAt(this.convertU2T(t))}getPerpendicularAt(t){const e=this.getTangentAt(t);return new i(e.y,-e.x)}clone(){return new l(this.getStartPoint().clone(),this.getEndPoint().clone(),this.getStartControlPoint().clone(),this.getEndControlPoint().clone())}getStartTangent(){return this.startControlPoint}getEndTangent(){return this.endControlPoint}equals(t){return!!t&&(!!(t.startPoint&&t.endPoint&&t.startControlPoint&&t.endControlPoint)&&(this.startPoint.equals(t.startPoint)&&this.endPoint.equals(t.endPoint)&&this.startControlPoint.equals(t.startControlPoint)&&this.endControlPoint.equals(t.endControlPoint)))}destroy(){this.startPoint.destroy(),this.endPoint.destroy(),this.startControlPoint.destroy(),this.endControlPoint.destroy(),this.isDestroyed=!0}static isInstance(t){return t instanceof l}toJSON(t){return"{ "+(t?"\n\t":"")+'"startPoint" : ['+this.getStartPoint().x+","+this.getStartPoint().y+"], "+(t?"\n\t":"")+'"endPoint" : ['+this.getEndPoint().x+","+this.getEndPoint().y+"], "+(t?"\n\t":"")+'"startControlPoint": ['+this.getStartControlPoint().x+","+this.getStartControlPoint().y+"], "+(t?"\n\t":"")+'"endControlPoint" : ['+this.getEndControlPoint().x+","+this.getEndControlPoint().y+"]"+(t?"\n\t":"")+" }"}static fromJSON(t){var e=JSON.parse(t);return l.fromObject(e)}static fromObject(t){if("object"!=typeof t)throw"Can only build from object.";if(!t.startPoint)throw'Object member "startPoint" missing.';if(!t.endPoint)throw'Object member "endPoint" missing.';if(!t.startControlPoint)throw'Object member "startControlPoint" missing.';if(!t.endControlPoint)throw'Object member "endControlPoint" missing.';return new l(new i(t.startPoint[0],t.startPoint[1]),new i(t.endPoint[0],t.endPoint[1]),new i(t.startControlPoint[0],t.startControlPoint[1]),new i(t.endControlPoint[0],t.endControlPoint[1]))}static fromArray(t){if(!Array.isArray(t))throw"Can only build from object.";if(4!=t.length)throw"Can only build from array with four elements.";return new l(t[0],t[1],t[2],t[3])}}l.START_POINT=0,l.START_CONTROL_POINT=1,l.END_CONTROL_POINT=2,l.END_POINT=3,l.utils={getSubCurvePointsAt:(t,e,s)=>{const i=new o(t.getPointAt(e),t.getTangentAt(e)),r=new o(t.getPointAt(s),t.getTangentAt(s).inv());return i.b.add(i.a),r.b.add(r.a),i.scale(.33333333*(s-e)),r.scale(.33333333*(s-e)),[i.a,r.a,i.b,r.b]}};class c{constructor(){this.className="BezierPath",this.START_POINT=0,this.START_CONTROL_POINT=1,this.END_CONTROL_POINT=2,this.END_POINT=3,this.uid=e.next(),this.totalArcLength=0,this.adjustCircular=!1,this.bezierCurves=[]}addCurve(t){if(null==t||void 0===t)throw"Cannot add null curve to bézier path.";this.bezierCurves.push(t),this.bezierCurves.length>1?(t.startPoint=this.bezierCurves[this.bezierCurves.length-2].endPoint,this.adjustSuccessorControlPoint(this.bezierCurves.length-2,!0,!0)):this.totalArcLength+=t.getLength()}locateCurveByStartPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].startPoint.equals(t))return e;return-1}locateCurveByEndPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].endPoint.equals(t))return e;return-1}locateCurveByStartControlPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].startControlPoint.equals(t))return e;return-1}locateCurveByEndControlPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].endControlPoint.equals(t))return e;return-1}getLength(){return this.totalArcLength}updateArcLengths(){this.totalArcLength=0;for(var t=0;t<this.bezierCurves.length;t++)this.bezierCurves[t].updateArcLengths(),this.totalArcLength+=this.bezierCurves[t].getLength()}getCurveCount(){return this.bezierCurves.length}getCurveAt(t){return this.bezierCurves[t]}translate(t){for(var e=0;e<this.bezierCurves.length;e++){(s=this.bezierCurves[e]).getStartPoint().add(t),s.getStartControlPoint().add(t),s.getEndControlPoint().add(t)}var s;return(s=this.bezierCurves[this.bezierCurves.length-1]).getEndPoint().add(t),this.updateArcLengths(),this}scale(t,e){return this.scaleXY({x:e,y:e},t)}scaleXY(t,e){for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];i.getStartPoint().scaleXY(t,e),i.getStartControlPoint().scaleXY(t,e),i.getEndControlPoint().scaleXY(t,e)}return this.bezierCurves.length>0&&!this.adjustCircular&&this.bezierCurves[this.bezierCurves.length-1].getEndPoint().scaleXY(t,e),this.updateArcLengths(),this}rotate(t,e){for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];i.getStartPoint().rotate(t,e),i.getStartControlPoint().rotate(t,e),i.getEndControlPoint().rotate(t,e)}this.bezierCurves.length>0&&!this.adjustCircular&&this.bezierCurves[this.bezierCurves.length-1].getEndPoint().rotate(t,e)}getClosestT(t){for(var e=-1,s=0,i=0,r=0,n=0,a=0,h=0;h<this.bezierCurves.length;h++)r=this.bezierCurves[h].getClosestT(t),i=this.bezierCurves[h].getPointAt(r).distance(t),(-1==e||i<s)&&(e=h,s=i,n=a+r*this.bezierCurves[h].getLength()),a+=this.bezierCurves[h].getLength();return Math.max(0,Math.min(1,n/this.totalArcLength))}getPoint(t){(t<0||t>this.totalArcLength)&&(console.warn("[BezierPath.getPoint(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(t,0)));for(var e=0,s=0;e<this.bezierCurves.length&&s+this.bezierCurves[e].getLength()<t;)s+=this.bezierCurves[e].getLength(),e++;if(e>=this.bezierCurves.length)return this.bezierCurves[this.bezierCurves.length-1].getEndPoint().clone();var i=t-s;return this.bezierCurves[e].getPoint(i)}getPointAt(t){return this.getPoint(t*this.totalArcLength)}getTangentAt(t){return this.getTangent(t*this.totalArcLength)}getTangent(t){(t<0||t>this.totalArcLength)&&(console.warn("[BezierPath.getTangent(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(0,t)));for(var e=0,s=0;e<this.bezierCurves.length&&s+this.bezierCurves[e].getLength()<t;)s+=this.bezierCurves[e].getLength(),e++;var i=t-s;return this.bezierCurves[e].getTangent(i)}getPerpendicularAt(t){return this.getPerpendicular(t*this.totalArcLength)}getPerpendicular(t){(t<0||t>this.totalArcLength)&&(console.log("[BezierPath.getPerpendicular(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(0,t)));var e=c._locateUIndex(this,t),s=this.bezierCurves[e.i],i=t-e.uPart;return s.getPerpendicular(i)}static _locateUIndex(t,e){for(var s=0,i=0,r=0;s<t.bezierCurves.length&&i+t.bezierCurves[s].getLength()<e;)i+=t.bezierCurves[s].getLength(),s+1<t.bezierCurves.length&&(r+=t.bezierCurves[s].getLength()),s++;return{i:s,uPart:i,uBefore:r}}getSubPathAt(t,e){t=Math.max(0,t),e=Math.min(1,e);let s=t*this.totalArcLength,i=e*this.totalArcLength;var r=c._locateUIndex(this,s),n=c._locateUIndex(this,i),a=(s-r.uBefore)/this.bezierCurves[r.i].getLength();if(r.i==n.i){var h=(i-n.uBefore)/this.bezierCurves[n.i].getLength(),o=this.bezierCurves[r.i].getSubCurveAt(a,h);return c.fromArray([o])}var l=[];if(r.i>n.i){o=this.bezierCurves[r.i].getSubCurveAt(a,0);l.push(o);for(var d=r.i-1;d>n.i;d--)l.push(this.bezierCurves[d].clone().reverse());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();l.push(this.bezierCurves[n.i].getSubCurveAt(1,h))}else{o=this.bezierCurves[r.i].getSubCurveAt(a,1);l.push(o);for(d=r.i+1;d<n.i&&d<this.bezierCurves.length;d++)l.push(this.bezierCurves[d].clone());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();l.push(this.bezierCurves[n.i].getSubCurveAt(0,h))}return c.fromArray(l)}moveCurvePoint(t,e,s){if(this.getCurveAt(t).moveCurvePoint(e,s,!0,!0),e==this.START_POINT&&(t>0||this.adjustCircular))this.getCurveAt(t-1<0?this.bezierCurves.length+(t-1):t-1).moveCurvePoint(this.END_CONTROL_POINT,s,!0,!1);else if(e==this.END_POINT&&(t+1<this.bezierCurves.length||this.adjustCircular)){this.getCurveAt((t+1)%this.bezierCurves.length).moveCurvePoint(this.START_CONTROL_POINT,s,!0,!1)}else e==this.START_CONTROL_POINT&&t>0?this.adjustPredecessorControlPoint(t,!0,!1):e==this.END_CONTROL_POINT&&t+1<this.getCurveCount()&&this.adjustSuccessorControlPoint(t,!0,!1);this.updateArcLengths()}adjustPredecessorControlPoint(t,e,s){if(this.adjustCircular||!(t<=0)){var i=this.getCurveAt(t),r=this.getCurveAt(t-1<0?this.getCurveCount()+(t-1):t-1);c.adjustNeighbourControlPoint(i,r,i.getStartPoint(),i.getStartControlPoint(),r.getEndPoint(),r.getEndControlPoint(),e,s)}}adjustSuccessorControlPoint(t,e,s){if(this.adjustCircular||!(t+1>this.getCurveCount())){var i=this.getCurveAt(t),r=this.getCurveAt((t+1)%this.getCurveCount());c.adjustNeighbourControlPoint(i,r,i.getEndPoint(),i.getEndControlPoint(),r.getStartPoint(),r.getStartControlPoint(),e,s)}}static adjustNeighbourControlPoint(t,e,s,r,n,a,h,o){var l=new i(r.x-s.x,r.y-s.y),c=new i(a.x-n.x,a.y-n.y),d=Math.sqrt(Math.pow(l.x,2)+Math.pow(l.y,2)),u=Math.sqrt(Math.pow(c.x,2)+Math.pow(c.y,2));d<=.1||(h?a.set(n.x-l.x*(u/d),n.y-l.y*(u/d)):a.set(n.x-l.x,n.y-l.y),e.updateArcLengths())}getBounds(){const t=new i(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),e=new i(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);for(var s,r=0;r<this.bezierCurves.length;r++)s=this.bezierCurves[r].getBounds(),t.x=Math.min(t.x,s.min.x),t.y=Math.min(t.y,s.min.y),e.x=Math.max(e.x,s.max.x),e.y=Math.max(e.y,s.max.y);return new h(t,e)}getEvenDistributionVertices(t){if(t<2)throw new Error("pointCount must be larger than one; is "+t+".");const e=[];if(0===this.bezierCurves.length)return e;var s=new i(this.bezierCurves[0].startPoint);e.push(s);const r=this.totalArcLength/(t-1),n=this.bezierCurves.length;let a=0,h=this.bezierCurves[0].arcLength,o=r,l=1;for(;l<t&&a<n;)if(o<h){var c=this.bezierCurves[a].getPoint(o);e.push(c),o+=r,l++}else a++,o-=h,h=a<n?this.bezierCurves[a].arcLength:0;return e.push(new i(this.bezierCurves[n-1].endPoint)),e}clone(){for(var t=new c,e=0;e<this.bezierCurves.length;e++)t.bezierCurves.push(this.bezierCurves[e].clone()),e>0&&(t.bezierCurves[e-1].endPoint=t.bezierCurves[e].startPoint);return t.updateArcLengths(),t.adjustCircular=this.adjustCircular,t}equals(t){if(!t)return!1;if(!t.bezierCurves)return!1;if(void 0===t.bezierCurves.length)return!1;if(t.bezierCurves.length!=this.bezierCurves.length)return!1;for(var e=0;e<this.bezierCurves.length;e++)if(!this.bezierCurves[e].equals(t.bezierCurves[e]))return!1;return!0}destroy(){for(var t=0;t<this.bezierCurves.length;t++)this.bezierCurves[t].destroy();this.isDestroyed=!0}toPathPoints(){if(0===this.bezierCurves.length)return[];if(1===this.bezierCurves.length)return[this.bezierCurves[0].startPoint,this.bezierCurves[0].startControlPoint,this.bezierCurves[0].endControlPoint,this.bezierCurves[0].endPoint];const t=[];t.push(this.bezierCurves[0].startPoint),t.push(this.bezierCurves[0].startControlPoint);for(var e=1;e<this.bezierCurves.length;e++)t.push(this.bezierCurves[e-1].endControlPoint),t.push(this.bezierCurves[e-1].endPoint),t.push(this.bezierCurves[e].startPoint),t.push(this.bezierCurves[e].startControlPoint);return t.push(this.bezierCurves[0].endControlPoint),t.push(this.bezierCurves[0].endPoint),t}toJSON(t){var e=[];e.push("[");for(var s=0;s<this.bezierCurves.length;s++)s>0&&e.push(","),t?e.push("\n\t"):e.push(" "),e.push(this.bezierCurves[s].toJSON(t));return 0!=this.bezierCurves.length&&e.push(" "),e.push("]"),e.join("")}static fromJSON(t){var e=JSON.parse(t);return c.fromArray(e)}static fromCurve(t){const e=new c;return e.addCurve(t),e}static fromArray(t){if(!Array.isArray(t))throw"[BezierPath.fromArray] Passed object must be an array.";const e=t;if(e.length<1)throw"[BezierPath.fromArray] Passed array must contain at least one bezier curve (has "+e.length+").";for(var s=new c,i=null,r=0;r<e.length;r++){var n;if(l.isInstance(e[r]))n=e[r].clone();else if(0 in e[r]&&1 in e[r]&&2 in e[r]&&3 in e[r]){if(!(e[r][0]&&e[r][1]&&e[r][2]&&e[r][3]))throw"Cannot convert path data to BezierPath instance. At least one element is undefined (index="+r+"): "+e[r];n=l.fromArray(e[r])}else n=l.fromObject(e[r]);i&&(n.startPoint=i.endPoint),s.bezierCurves.push(n),i=n}return s.updateArcLengths(),s}toReducedListRepresentation(t){void 0===t&&(t=1);var e=[];e.push("[");for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];e.push(i.getStartPoint().x.toFixed(t)),e.push(","),e.push(i.getStartPoint().y.toFixed(t)),e.push(","),e.push(i.getStartControlPoint().x.toFixed(t)),e.push(","),e.push(i.getStartControlPoint().y.toFixed(t)),e.push(","),e.push(i.getEndControlPoint().x.toFixed(t)),e.push(","),e.push(i.getEndControlPoint().y.toFixed(t)),e.push(",")}if(0!=this.bezierCurves.length){i=this.bezierCurves[this.bezierCurves.length-1];e.push(i.getEndPoint().x.toFixed(t)),e.push(","),e.push(i.getEndPoint().y.toFixed(t))}return e.push("]"),e.join("")}static fromReducedListRepresentation(t,e){var s=JSON.parse(t);if(!s.length)throw console.log("Cannot parse bezier path from non-array object nor from empty point list."),"Cannot parse bezier path from non-array object nor from empty point list.";if(s.length<8)throw console.log("Cannot build bezier path. The passed array must contain at least 8 elements (numbers)."),"Cannot build bezier path. The passed array must contain at least 8 elements (numbers).";return c.fromReducedList(s,e)}static fromReducedList(t,e){var s,r,n,a=new c,h=new i,o=0;do{0==o&&(h=new i(t[o],t[o+1])),s=new i(t[o+2],t[o+3]),r=new i(t[o+4],t[o+5]),n=new i(t[o+6],t[o+7]);var d=new l(h,n,s,r);a.bezierCurves.push(d),h=n,o+=6}while(o+2<t.length);return a.adjustCircular=null!=e&&e,e&&(a.bezierCurves[a.bezierCurves.length-1].endPoint=a.bezierCurves[0].startPoint),a.updateArcLengths(),a}}c.START_POINT=0,c.START_CONTROL_POINT=1,c.END_CONTROL_POINT=2,c.END_POINT=3;class d{constructor(t,s){this.className="Circle",this.uid=e.next(),this.center=t,this.radius=s}containsPoint(t){return this.center.distance(t)<this.radius}containsCircle(t){return this.center.distance(t.center)+t.radius<this.radius}lineDistance(t){return t.getClosestPoint(this.center).distance(this.center)-this.radius}vertAt(t){return d.circleUtils.vertAt(t,this.radius).add(this.center)}tangentAt(t){const e=d.circleUtils.vertAt(t,this.radius);return new o(e,new i(0,0)).add(this.center).perp()}circleIntersection(t){if(this.center.distance(t.center)>this.radius+t.radius)return null;if(this.center.distance(t.center)<Math.abs(this.radius-t.radius))return null;var e=this.center,s=t.center,r=e.distance(s),a=(this.radius*this.radius-t.radius*t.radius+r*r)/(2*r),h=Math.sqrt(this.radius*this.radius-a*a),o=s.clone().scale(a/r,e),l=o.x+h*(s.y-e.y)/r,c=o.y-h*(s.x-e.x)/r,d=o.x-h*(s.y-e.y)/r,u=o.y+h*(s.x-e.x)/r;return new n(new i(l,c),new i(d,u))}lineIntersection(t,e){const s=new i,r=new i,a=new i(t).sub(this.center),h=new i(e).sub(this.center),o=a.difference(h);0===Math.abs(o.y)&&(o.y=1e-6);const l=a.distance(h),c=a.x*h.y-a.y*h.x,d=l*l;if(this.radius*this.radius*d-c*c<0)return null;const u=this.radius*this.radius*l*l-c*c,g=Math.sqrt(u);return s.x=(c*o.y+Math.sign(o.y)*o.x*g)/d,r.x=(c*o.y-Math.sign(o.y)*o.x*g)/d,s.y=(-c*o.x+Math.abs(o.y)*g)/d,r.y=(-c*o.x-Math.abs(o.y)*g)/d,new n(s.add(this.center),r.add(this.center))}closestPoint(t){const e=this.lineIntersection(this.center,t);return e?e.a.distance(t)<e.b.distance(t)?e.a:e.b:new i}destroy(){this.center.destroy(),this.isDestroyed=!0}}d.circleUtils={vertAt:(t,e)=>new i(Math.cos(t)*e,Math.sin(t)*e)};class u{constructor(t,s,i){this.className="CircleSector",this.uid=e.next(),this.circle=t,this.startAngle=s,this.endAngle=i}containsAngle(t){return this.startAngle<=this.endAngle?t>=this.startAngle&&t<this.endAngle:t>=this.startAngle||t<this.endAngle}angleAt(t){if(this.startAngle<=this.endAngle){return(this.startAngle+(this.endAngle-this.startAngle)*t)%(2*Math.PI)}return(this.startAngle+(2*Math.PI-this.startAngle+this.endAngle)*t)%(2*Math.PI)}getStartPoint(){return this.circle.vertAt(this.startAngle)}getEndPoint(){return this.circle.vertAt(this.endAngle)}circleSectorIntersection(t){const e=this.circle.circleIntersection(t.circle);if(!e)return null;const s=this.circle.center.angle(e.a),i=this.circle.center.angle(e.b);if(!this.containsAngle(s)||!this.containsAngle(i))return null;const r=t.circle.center.angle(e.a),n=t.circle.center.angle(e.b);if(!t.containsAngle(r)||!t.containsAngle(n))return null;var a=new u(this.circle,this.endAngle,this.startAngle).angleAt(.5);const h=new u(new d(this.circle.center.clone(),this.circle.radius),s,i);return h.containsAngle(a)&&(h.startAngle=i,h.endAngle=s),h}destroy(){this.circle.destroy(),this.isDestroyed=!0}}u.circleSectorUtils={polarToCartesian:(t,e,s,i)=>({x:t+s*Math.cos(i),y:e+s*Math.sin(i)}),describeSVGArc:(t,e,s,i,r,n)=>{void 0===n&&(n={moveToStart:!0});const a=u.circleSectorUtils.polarToCartesian(t,e,s,r),h=u.circleSectorUtils.polarToCartesian(t,e,s,i);if(2*Math.PI-Math.abs(i-r)<.001){const a=u.circleSectorUtils.describeSVGArc(t,e,s,i,i+(r-i)/2,n),h=u.circleSectorUtils.describeSVGArc(t,e,s,i+(r-i)/2,r,n);return a.concat(h)}const o=r-i;var l,c;o<0?(l=Math.abs(o)<Math.PI?1:0,c=1):(l=Math.abs(o)>Math.PI?1:0,c=1);const d=[];return n.moveToStart&&d.push("M",h.x,h.y),d.push("A",s,s,0,l,c,a.x,a.y),d}};const g=180/Math.PI;class f{constructor(t,e,s,r,n,a,h,o,l,c,d,u){if(this.svgNode=t,this.offset=new i(0,0).set(e),this.scale=new i(1,1).set(s),this.fillShapes=n,this.isSecondary=Boolean(h),this.drawConfig=a,this.drawlibConfiguration={},this.cache=new Map,this.setSize(r),h){if(!(o&&l&&c&&d))throw"Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";this.gNode=o,this.bufferGNode=l,this.nodeDefs=c,this.bufferedNodeDefs=d,u&&(this.nodeStyle=u)}else this.addStyleDefs(a),this.addDefsNode(),this.gNode=this.createSVGNode("g"),this.bufferGNode=this.createSVGNode("g"),this.svgNode.appendChild(this.gNode)}addStyleDefs(t){this.nodeStyle=this.createSVGNode("style"),this.svgNode.appendChild(this.nodeStyle),this.rebuildStyleDefs(t)}rebuildStyleDefs(t){const e={bezier:"CubicBezierCurve",polygon:"Polygon",triangle:"Triangle",ellipse:"Ellipse",ellipseSector:"EllipseSector",circle:"Circle",circleSector:"CircleSector",vertex:"Vertex",line:"Line",vector:"Vector",image:"Image",text:"Text"},s=[];for(var i in e){const r=e[i],n=t[i];n?s.push(`.${r} { fill : none; stroke: ${n.color}; stroke-width: ${n.lineWidth}px }`):console.warn(`Warning: your draw config is missing the key '${i}' which is required.`)}this.customStyleDefs&&(s.push("\n/* Custom styles */\n"),this.customStyleDefs.forEach(((t,e)=>{s.push(e+" { "+t+" }")}))),this.nodeStyle.innerHTML=s.join("\n")}addDefsNode(){this.nodeDefs=this.createSVGNode("defs"),this.bufferedNodeDefs=this.createSVGNode("defs"),this.svgNode.appendChild(this.nodeDefs)}addCustomStyleDefs(t){this.customStyleDefs=t}findElement(t,e){if(!t)return null;var s=this.cache.get(t);return s&&s.nodeName.toUpperCase()===e.toUpperCase()?(this.cache.delete(t),s):null}createSVGNode(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}makeNode(t){var e=this.findElement(this.curId,t);return e||(e=this.createSVGNode(t)),this.drawlibConfiguration.blendMode&&e.style["mix-blend-mode"](this.drawlibConfiguration.blendMode),e}_bindFillDraw(t,e,s,i,r){return this._configureNode(t,e,this.fillShapes,s,i,r),this._bindNode(t,void 0)}_bindNode(t,e){return t.parentNode||(null!=e?e:this.bufferGNode).appendChild(t),t}_addCSSClasses(t,e){this.curClassName?t.setAttribute("class",`${e} ${this.curClassName}`):t.setAttribute("class",e)}_configureNode(t,e,s,i,r,n){return this._addCSSClasses(t,e),t.setAttribute("fill",s&&i?i:"none"),t.setAttribute("stroke",s?"none":i||"none"),t.setAttribute("stroke-width",`${r||1}`),this.curId&&t.setAttribute("id",`${this.curId}`),this.applyStrokeOpts(t,n),t}setSize(t){this.canvasSize=t,this.svgNode.setAttribute("viewBox",`0 0 ${this.canvasSize.width} ${this.canvasSize.height}`),this.svgNode.setAttribute("width",`${this.canvasSize.width}`),this.svgNode.setAttribute("height",`${this.canvasSize.height}`)}copyInstance(t){return new f(this.svgNode,this.offset,this.scale,this.canvasSize,t,this.drawConfig,!0,this.gNode,this.bufferGNode,this.nodeDefs,this.bufferedNodeDefs,this.nodeStyle)}setConfiguration(t){this.drawlibConfiguration=t}setCurrentId(t){this.curId=t}setCurrentClassName(t){this.curClassName=t}beginDrawCycle(t){this.cache.clear();for(var e=0;e<this.bufferGNode.childNodes.length;e++){var s=this.bufferGNode.childNodes[e];this.cache.set(s.getAttribute("id"),s)}this.removeAllChildNodes()}endDrawCycle(t){this.rebuildStyleDefs(this.drawConfig),this.isSecondary||(this.svgNode.replaceChild(this.bufferedNodeDefs,this.nodeDefs),this.svgNode.replaceChild(this.bufferGNode,this.gNode));const e=this.gNode;this.gNode=this.bufferGNode,this.bufferGNode=e;const s=this.nodeDefs;this.nodeDefs=this.bufferedNodeDefs,this.bufferedNodeDefs=s}applyStrokeOpts(t,e){e&&e.dashArray&&e.dashArray.length>0&&f.nodeSupportsLineDash(t.tagName)&&(t.setAttribute("stroke-dasharray",e.dashArray.map((t=>t*this.scale.x)).join(" ")),e.dashOffset&&t.setAttribute("stroke-dashoffset",""+e.dashOffset*this.scale.x))}_x(t){return this.offset.x+this.scale.x*t}_y(t){return this.offset.y+this.scale.y*t}line(t,e,s,i,r){const n=this.makeLineNode(t,e,s,i,r);return this._bindFillDraw(n,"line",s,i||1,r)}arrow(t,e,s,i,r=8,n){const a=this.makeNode("g"),h={x:0,y:0},o=this.makeArrowHeadNode(t,e,s,i,r,void 0,h),l=this.makeLineNode(t,h,s,i,n);return a.appendChild(l),a.appendChild(o),this._addCSSClasses(a,"linear-arrow"),this._bindNode(a,void 0),a}cubicBezierArrow(t,e,s,r,n,a,h=8,o){const l=this.makeNode("g"),c=new i(0,0),d=this.makeArrowHeadNode(r,e,n,a,h,void 0,c),u=c.difference(e),g=this.makeCubicBezierNode(t,{x:e.x-u.x,y:e.y-u.y},s,{x:r.x-u.x,y:r.y-u.y},n,a,o);return l.appendChild(g),l.appendChild(d),this._addCSSClasses(l,"cubicbezier-arrow"),this._bindNode(l,void 0),l}arrowHead(t,e,s,i,r=8,n){const a=this.makeArrowHeadNode(t,e,s,i,r,n);return this._bindFillDraw(a,"arrowhead",s,i||1,n)}image(t,e,s,i=1){const r=this.makeNode("image"),n=t=>{if(t.naturalWidth){const n=s.x/t.naturalWidth,a=s.y/t.naturalHeight;r.setAttribute("width",""+t.naturalWidth*this.scale.x),r.setAttribute("height",""+t.naturalHeight*this.scale.y),r.setAttribute("display",null),r.setAttribute("opacity",`${i}`),r.setAttribute("transform",`translate(${this._x(e.x)} ${this._y(e.y)}) scale(${n} ${a})`)}};return t.addEventListener("load",(e=>{n(t)})),r.setAttribute("x","0"),r.setAttribute("y","0"),r.setAttribute("display","none"),n(t),r.setAttribute("href",t.src),this._bindFillDraw(r,"image",null,null)}texturedPoly(t,s,r,n,a){const h=new i(s.min).clone().rotate(a,n),o=this.makeNode("clipPath"),l=`clippath_${e.next()}`;o.setAttribute("id",l);const c=this.makeNode("g"),d=this.makeNode("image");d.setAttribute("x",`${this._x(h.x)}`),d.setAttribute("y",`${this._y(h.y)}`),d.setAttribute("width",`${s.width}`),d.setAttribute("height",`${s.height}`),d.setAttribute("href",t.src),d.setAttribute("transform",`rotate(${a*g}, ${this._x(h.x)}, ${this._y(h.y)})`);const u=this.makeNode("path"),f=[];if(r.vertices.length>0){f.push("M",`${this._x(r.vertices[0].x)}`,`${this._y(r.vertices[0].y)}`);for(var x=1;x<r.vertices.length;x++)f.push("L",`${this._x(r.vertices[x].x)}`,`${this._y(r.vertices[x].y)}`)}u.setAttribute("d",f.join(" ")),o.appendChild(u),this.bufferedNodeDefs.appendChild(o),c.appendChild(d),c.setAttribute("transform-origin",`${this._x(h.x)} ${this._y(h.y)}`),c.setAttribute("transform",`scale(${this.scale.x}, ${this.scale.y})`);const v=this.makeNode("g");return v.appendChild(c),v.setAttribute("clip-path",`url(#${l})`),this._bindFillDraw(v,"image",null,null),v}cubicBezier(t,e,s,i,r,n,a){const h=this.makeCubicBezierNode(t,e,s,i,r,n,a);return this._bindNode(h,void 0)}cubicBezierPath(t,e,s,i){const r=this.makeNode("path");if(this.applyStrokeOpts(r,i),!t||0==t.length)return r;const n=["M",this._x(t[0].x),this._y(t[0].y)];for(var a,h,o,l=1;l<t.length;l+=3)h=t[l],o=t[l+1],a=t[l+2],n.push("C",this._x(h.x),this._y(h.y),this._x(o.x),this._y(o.y),this._x(a.x),this._y(a.y));return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"cubicBezierPath",e,s||1)}handle(t,e){this.point(t,"rgb(0,32,192)"),this.square(e,5,"rgba(0,128,192,0.5)")}handleLine(t,e){this.line(t,e,"rgb(128,128,128,0.5)")}dot(t,e){const s=this.makeNode("line");return s.setAttribute("x1",`${this._x(t.x)}`),s.setAttribute("y1",`${this._y(t.y)}`),s.setAttribute("x2",`${this._x(t.x)}`),s.setAttribute("y2",`${this._y(t.y)}`),this._bindFillDraw(s,"dot",e,1)}point(t,e){const s=this.makeNode("circle");return s.setAttribute("cx",`${this._x(t.x)}`),s.setAttribute("cy",`${this._y(t.y)}`),s.setAttribute("r","3"),this._bindFillDraw(s,"point",e,1)}circle(t,e,s,i,r){const n=this.makeNode("circle");return this.applyStrokeOpts(n,r),n.setAttribute("cx",`${this._x(t.x)}`),n.setAttribute("cy",`${this._y(t.y)}`),n.setAttribute("r",""+e*this.scale.x),this._bindFillDraw(n,"circle",s,i||1)}circleArc(t,e,s,i,r,n,a){const h=this.makeNode("path");this.applyStrokeOpts(h,a);const o=u.circleSectorUtils.describeSVGArc(this._x(t.x),this._y(t.y),e*this.scale.x,s,i);return h.setAttribute("d",o.join(" ")),this._bindFillDraw(h,"circleArc",r,n||1)}ellipse(t,e,s,i,r,n,a){void 0===n&&(n=0);const h=this.makeNode("ellipse");return this.applyStrokeOpts(h,a),h.setAttribute("cx",`${this._x(t.x)}`),h.setAttribute("cy",`${this._y(t.y)}`),h.setAttribute("rx",""+e*this.scale.x),h.setAttribute("ry",""+s*this.scale.y),h.setAttribute("transform",`rotate(${180*n/Math.PI} ${this._x(t.x)} ${this._y(t.y)})`),this._bindFillDraw(h,"ellipse",i,r||1)}square(t,e,s,i,r){const n=this.makeNode("rectangle");return this.applyStrokeOpts(n,r),n.setAttribute("x",`${this._x(t.x-e/2)}`),n.setAttribute("y",`${this._y(t.y-e/2)}`),n.setAttribute("width",""+e*this.scale.x),n.setAttribute("height",""+e*this.scale.y),this._bindFillDraw(n,"square",s,i||1)}rect(t,e,s,i,r,n){const a=this.makeNode("rect");return this.applyStrokeOpts(a,n),a.setAttribute("x",`${this._x(t.x)}`),a.setAttribute("y",`${this._y(t.y)}`),a.setAttribute("width",""+e*this.scale.x),a.setAttribute("height",""+s*this.scale.y),this._bindFillDraw(a,"rect",i,r||1)}grid(t,e,s,i,r,n){const a=this.makeNode("path"),h=[];for(var o=-Math.ceil(.5*s/r)*r,l=s/2,c=-Math.ceil(.5*e/i)*i;c<e/2;c+=i)h.push("M",this._x(t.x+c),this._y(t.y+o)),h.push("L",this._x(t.x+c),this._y(t.y+l));for(var d=-Math.ceil(.5*e/i)*i,u=e/2,g=-Math.ceil(.5*s/r)*r;g<s/2;g+=r)h.push("M",this._x(t.x+d),this._y(t.y+g)),h.push("L",this._x(t.x+u),this._y(t.y+g));return a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"grid",n,1)}raster(t,e,s,i,r,n){const a=this.makeNode("path"),h=[];for(var o=-Math.ceil(.5*e/i)*i;o<e/2;o+=i)for(var l=-Math.ceil(.5*s/r)*r;l<s/2;l+=r)h.push("M",this._x(t.x+o)-4,this._y(t.y+l)),h.push("L",this._x(t.x+o)+4,this._y(t.y+l)),h.push("M",this._x(t.x+o),this._y(t.y+l)-4),h.push("L",this._x(t.x+o),this._y(t.y+l)+4);return a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"raster",n,1)}diamondHandle(t,e,s){const i=this.makeNode("path"),r=["M",this._x(t.x)-e/2,this._y(t.y),"L",this._x(t.x),this._y(t.y)-e/2,"L",this._x(t.x)+e/2,this._y(t.y),"L",this._x(t.x),this._y(t.y)+e/2,"Z"];return i.setAttribute("d",r.join(" ")),this._bindFillDraw(i,"diamondHandle",s,1)}squareHandle(t,e,s){const i=this.makeNode("rect");return i.setAttribute("x",""+(this._x(t.x)-e/2)),i.setAttribute("y",""+(this._y(t.y)-e/2)),i.setAttribute("width",`${e}`),i.setAttribute("height",`${e}`),this._bindFillDraw(i,"squareHandle",s,1)}circleHandle(t,e,s){e=e||3;const i=this.makeNode("circle");return i.setAttribute("cx",`${this._x(t.x)}`),i.setAttribute("cy",`${this._y(t.y)}`),i.setAttribute("r",`${e}`),this._bindFillDraw(i,"circleHandle",s,1)}crosshair(t,e,s,i){const r=this.makeNode("path"),n=["M",this._x(t.x)-e,this._y(t.y),"L",this._x(t.x)+e,this._y(t.y),"M",this._x(t.x),this._y(t.y)-e,"L",this._x(t.x),this._y(t.y)+e];return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"crosshair",s,i||.5)}cross(t,e,s,i){const r=this.makeNode("path"),n=["M",this._x(t.x)-e,this._y(t.y)-e,"L",this._x(t.x)+e,this._y(t.y)+e,"M",this._x(t.x)-e,this._y(t.y)+e,"L",this._x(t.x)+e,this._y(t.y)-e];return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"cross",s,i||1)}polygon(t,e,s){return this.polyline(t.vertices,t.isOpen,e,s)}polyline(t,e,s,i,r){const n=this.makeNode("path");if(this.applyStrokeOpts(n,r),0==t.length)return n;const a=["M",this._x(t[0].x),this._y(t[0].y)];for(var h=t.length,o=1;o<h;o++)a.push("L",this._x(t[o].x),this._y(t[o].y));return e||a.push("Z"),n.setAttribute("d",a.join(" ")),this._bindFillDraw(n,"polygon",s,i||1)}text(t,e,s,i){var r,n,a;const h=(i=i||{}).color||"black",o=(null!==(n=null!==(r=i.lineHeight)&&void 0!==r?r:i.fontSize)&&void 0!==n?n:0)*this.scale.x,l="left"===i.textAlign||"start"===i.textAlign?"start":"center"===i.textAlign?"middle":"right"===i.textAlign||"end"===i.textAlign?"end":"start",c=`${this._x(e)}px ${this._y(s)}px`,d=`translate(${this._x(e)} ${this._y(s)+o/2})`,u=i.rotation?`rotate(${i.rotation*g} 0 0)`:"",f=this.makeNode("g"),x=this.curId;this.curId=x+"_text";const v=this.makeNode("text");return f.appendChild(v),v.setAttribute("font-family",null!==(a=i.fontFamily)&&void 0!==a?a:""),v.setAttribute("font-size",i.fontSize?""+i.fontSize*this.scale.x:""),v.setAttribute("font-style",i.fontStyle?`${i.fontStyle}`:""),v.setAttribute("font-weight",i.fontWeight?`${i.fontWeight}`:""),v.setAttribute("text-anchor",l),v.setAttribute("transform-origin","0 0"),v.setAttribute("transform",u),f.setAttribute("transform-origin",c),f.setAttribute("transform",d),v.innerHTML=t,this.curId=x,this._bindFillDraw(f,"text",h,1)}label(t,e,s,i,r){const n=this.makeNode("text");return n.setAttribute("transform",`translate(${e},${s}), rotate(${(i||0)/Math.PI*180})`),n.setAttribute("font-family","Arial"),n.setAttribute("font-size","9pt"),n.setAttribute("font-style","normal"),n.setAttribute("font-weight","lighter"),n.innerHTML=t,this._bindFillDraw(n,"label",r||"black",null)}path(t,e,s,i){const r=this.makeNode("path");this.applyStrokeOpts(r,i);const n=i&&i.inplace?t:f.copyPathData(t);return f.transformPathData(n,this.offset,this.scale),r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"path",e,s)}clear(t){if(this.isSecondary)return;this.curId="background",this.curClassName=null;const e=this.makeNode("rect");e.setAttribute("x","0"),e.setAttribute("y","0"),e.setAttribute("width",`${this.canvasSize.width}`),e.setAttribute("height",`${this.canvasSize.height}`),this._bindFillDraw(e,this.curId,null,null),e.setAttribute("fill",void 0===t?"none":t),this.curId=null}removeAllChildNodes(){for(;this.bufferGNode.lastChild;)this.bufferGNode.removeChild(this.bufferGNode.lastChild);for(;this.bufferedNodeDefs.lastChild;)this.bufferedNodeDefs.removeChild(this.bufferedNodeDefs.lastChild)}static createSvg(){return document.createElementNS("http://www.w3.org/2000/svg","svg")}static copyPathData(t){const e=new Array(t.length);for(var s=0,i=t.length;s<i;s++)e[s]=t[s];return e}static transformPathData(t,e,s){const i=i=>{t[i]=e.x+s.x*Number(t[i])},r=i=>{t[i]=e.y+s.y*Number(t[i])},n=e=>{t[e]=s.x*Number(t[e])},a=e=>{t[e]=s.y*Number(t[e])};for(var h=0,o=e=>{Number(t[e]),Number(t[e+1])};h<t.length;){switch(t[h]){case"M":case"L":case"T":i(h+1),r(h+2),o(h+1),h+=3;break;case"m":case"l":case"t":n(h+1),a(h+2),o(h+1),h+=3;break;case"H":i(h+1),Number(t[h+1]),h+=2;break;case"h":n(h+1),Number(t[h+1]),h+=2;break;case"V":r(h+1),Number(t[h+1]),h+=2;break;case"v":a(h+1),Number(t[h+1]),h+=2;break;case"C":i(h+1),r(h+2),i(h+3),r(h+4),i(h+5),r(h+6),o(h+5),h+=7;break;case"c":n(h+1),a(h+2),n(h+3),a(h+4),n(h+5),a(h+6),o(h+5),h+=7;break;case"S":case"Q":i(h+1),r(h+2),i(h+3),r(h+4),o(h+3),h+=5;break;case"s":case"q":n(h+1),a(h+2),n(h+3),a(h+4),o(h+3),h+=5;break;case"A":n(h+1),a(h+2),i(h+6),r(h+7),o(h+6),(s.x<0&&s.y>=0||s.x>=0&&s.y<0)&&(t[h+5]=t[h+5]?0:1),h+=8;break;case"a":n(h+1),a(h+2),n(h+6),a(h+7),o(h+6),h+=8;break;default:h++}}}static nodeSupportsLineDash(t){return["line","path","circle","ellipse","rectangle","rect"].includes(t)}makeLineNode(t,e,s,i,r,n){const a=this.makeNode("line");return a.setAttribute("x1",`${this._x(t.x)}`),a.setAttribute("y1",`${this._y(t.y)}`),a.setAttribute("x2",`${this._x(e.x)}`),a.setAttribute("y2",`${this._y(e.y)}`),this._configureNode(a,null!=n?n:"line",this.fillShapes,s,i||1,r),a}makePathNode(t,e,s,i,r){const n=this.makeNode("path");return n.setAttribute("d",t),this._configureNode(n,null!=r?r:"path",this.fillShapes,e,s||1,i),n}makeArrowHeadNode(t,e,s,i,r=8,n,a){var h=o.utils.buildArrowHead(t,e,r,this.scale.x,this.scale.y);const l=["M",this.offset.x+h[0].x,this.offset.y+h[0].y];a&&(a.x=h[0].x/this.scale.x,a.y=h[0].y/this.scale.y);for(var c=1;c<=h.length;c++)l.push("L"),l.push(this.offset.x+h[c%h.length].x),l.push(this.offset.y+h[c%h.length].y);return this.makePathNode(l.join(" "),s,i,n,"arrowhead")}makeCubicBezierNode(t,e,s,i,r,n,a){if(t instanceof l)return this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n);const h=["M",this._x(t.x),this._y(t.y),"C",this._x(s.x),this._y(s.y),this._x(i.x),this._y(i.y),this._x(e.x),this._y(e.y)];return this.makePathNode(h.join(" "),r,n,a,"cubicBezier")}}f.HEAD_XML=['<?xml version="1.0" encoding="UTF-8" standalone="no"?>','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" ',' "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',""].join("\n");class x{constructor(t,e){this.ctx=t,this.offset=new i(0,0),this.scale=new i(1,1),this.fillShapes=e}applyStrokeOpts(t){var e,s;this.ctx.setLineDash((null!==(e=null==t?void 0:t.dashArray)&&void 0!==e?e:[]).map((t=>t*this.scale.x))),this.ctx.lineDashOffset=(null!==(s=null==t?void 0:t.dashOffset)&&void 0!==s?s:0)*this.scale.x}_fillOrDraw(t){this.fillShapes?(this.ctx.fillStyle=t,this.ctx.fill()):(this.ctx.strokeStyle=t,this.ctx.stroke())}beginDrawCycle(t){}endDrawCycle(t){}setConfiguration(t){this.ctx.globalCompositeOperation=t.blendMode||"source-over"}setCurrentId(t){}setCurrentClassName(t){}line(t,e,s,i,r){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(r),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y),this.ctx.strokeStyle=s,this.ctx.lineWidth=i||1,this.ctx.stroke(),this.ctx.restore()}arrow(t,e,s,r,n=8,a){const h=new i(0,0);this.arrowHead(t,e,s,r,n,void 0,h),this.line(t,h,s,r,a)}cubicBezierArrow(t,e,s,r,n,a,h,o){const l=new i(0,0);this.arrowHead(r,e,n,a,h,void 0,l);const c=l.difference(e);this.cubicBezier(t,{x:e.x-c.x,y:e.y-c.y},s,{x:r.x-c.x,y:r.y-c.y},n,a,o)}arrowHead(t,e,s,i,r=8,n,a){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(n);var h=o.utils.buildArrowHead(t,e,r,this.scale.x,this.scale.y);a&&(a.x=h[0].x/this.scale.x,a.y=h[0].y/this.scale.y),this.ctx.moveTo(this.offset.x+h[0].x,this.offset.y+h[0].y);for(var l=0;l<h.length;l++)this.ctx.lineTo(this.offset.x+h[l].x,this.offset.y+h[l].y);this.ctx.lineTo(this.offset.x+h[0].x,this.offset.y+h[0].y),this.ctx.lineWidth=i||1,this._fillOrDraw(s),this.ctx.restore()}image(t,e,s,i=1){t.complete&&t.naturalWidth&&(this.ctx.save(),this.ctx.globalAlpha=i,this.ctx.drawImage(t,0,0,t.naturalWidth-1,t.naturalHeight-1,this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y,s.x*this.scale.x,s.y*this.scale.y),this.ctx.restore())}texturedPoly(t,e,s,r,n){var a=s.getBounds();new i(r.x,r.y).difference(a.getCenter());var h=new i(e.width,e.height),o=new i(e.min.x,e.min.y).sub(r);this.ctx.save(),this.ctx.translate(this.offset.x+r.x*this.scale.x,this.offset.y+r.y*this.scale.y),x.helpers.clipPoly(this.ctx,{x:-r.x*this.scale.x,y:-r.y*this.scale.y},this.scale,s.vertices),this.ctx.scale(this.scale.x,this.scale.y),this.ctx.rotate(n),this.ctx.drawImage(t,0,0,t.naturalWidth-1,t.naturalHeight-1,o.x,o.y,h.x,h.y),this.ctx.restore()}rect(t,e,s,i,r,n){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(n),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+e)*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+e)*this.scale.x,this.offset.y+(t.y+s)*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+(t.y+s)*this.scale.y),this.ctx.closePath(),this.ctx.lineWidth=r||1,this._fillOrDraw(i),this.ctx.restore()}cubicBezier(t,e,s,i,r,n,a){t instanceof l?this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n):(this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(a),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.bezierCurveTo(this.offset.x+s.x*this.scale.x,this.offset.y+s.y*this.scale.y,this.offset.x+i.x*this.scale.x,this.offset.y+i.y*this.scale.y,this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y),this.ctx.lineWidth=n||2,this._fillOrDraw(r),this.ctx.restore())}quadraticBezier(t,e,s,i,r,n){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(n),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.quadraticCurveTo(this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y,this.offset.x+s.x*this.scale.x,this.offset.y+s.y*this.scale.y),this.ctx.lineWidth=r||2,this._fillOrDraw(i),this.ctx.restore()}cubicBezierPath(t,e,s,i){if(t&&0!=t.length){var r,n,a;this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(i),this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var h=1;h<t.length;h+=3)n=t[h],a=t[h+1],r=t[h+2],this.ctx.bezierCurveTo(this.offset.x+n.x*this.scale.x,this.offset.y+n.y*this.scale.y,this.offset.x+a.x*this.scale.x,this.offset.y+a.y*this.scale.y,this.offset.x+r.x*this.scale.x,this.offset.y+r.y*this.scale.y);this.ctx.closePath(),this.ctx.lineWidth=s||1,this._fillOrDraw(e),this.ctx.restore()}}handle(t,e){this.point(t,"rgb(0,32,192)"),this.square(e,5,"rgba(0,128,192,0.5)")}handleLine(t,e){this.line(t,e,"rgba(128,128,128, 0.5)",void 0)}dot(t,e){this.ctx.save(),this.ctx.beginPath(),this.ctx.setLineDash([]),this.ctx.moveTo(Math.round(this.offset.x+this.scale.x*t.x),Math.round(this.offset.y+this.scale.y*t.y)),this.ctx.lineTo(Math.round(this.offset.x+this.scale.x*t.x+1),Math.round(this.offset.y+this.scale.y*t.y+1)),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(e),this.ctx.restore()}point(t,e){this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.arc(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,3,0,2*Math.PI,!1),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(e)}circle(t,e,s,i,r){this.applyStrokeOpts(r),this.ctx.beginPath(),this.ctx.ellipse(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e*this.scale.x,e*this.scale.y,0,0,2*Math.PI),this.ctx.closePath(),this.ctx.lineWidth=i||1,this._fillOrDraw(s)}circleArc(t,e,s,i,r,n,a){a&&a.asSegment||this.ctx.beginPath(),this.applyStrokeOpts(a),this.ctx.ellipse(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e*this.scale.x,e*this.scale.y,0,s,i,!1),a&&a.asSegment||(this.ctx.lineWidth=n||1,this._fillOrDraw(r||"#000000"))}ellipse(t,e,s,i,r,n,a){void 0===n&&(n=0),this.applyStrokeOpts(a),this.ctx.beginPath(),this.ctx.ellipse(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e*this.scale.x,s*this.scale.y,n,0,2*Math.PI),this.ctx.closePath(),this.ctx.lineWidth=r||1,this._fillOrDraw(i)}square(t,e,s,i,r){this.applyStrokeOpts(r),this.ctx.beginPath(),this.ctx.rect(this.offset.x+(t.x-e/2)*this.scale.x,this.offset.y+(t.y-e/2)*this.scale.y,e*this.scale.x,e*this.scale.y),this.ctx.closePath(),this.ctx.lineWidth=i||1,this._fillOrDraw(s)}grid(t,e,s,i,r,n){this.ctx.setLineDash([]),this.ctx.beginPath();for(var a=-Math.ceil(.5*s/r)*r,h=s/2,o=-Math.ceil(.5*e/i)*i;o<e/2;o+=i)this.ctx.moveTo(this.offset.x+(t.x+o)*this.scale.x,this.offset.y+(t.y+a)*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+o)*this.scale.x,this.offset.y+(t.y+h)*this.scale.y);for(var l=-Math.ceil(.5*e/i)*i,c=e/2,d=-Math.ceil(.5*s/r)*r;d<s/2;d+=r)this.ctx.moveTo(this.offset.x+(t.x+l)*this.scale.x-4,this.offset.y+(t.y+d)*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+c)*this.scale.x+4,this.offset.y+(t.y+d)*this.scale.y);this.ctx.strokeStyle=n,this.ctx.lineWidth=1,this.ctx.stroke(),this.ctx.closePath()}raster(t,e,s,i,r,n){this.ctx.save(),this.ctx.setLineDash([]),this.ctx.beginPath();for(var a=-Math.ceil(.5*e/i)*i;a<e/2;a+=i)for(var h=-Math.ceil(.5*s/r)*r;h<s/2;h+=r)this.ctx.moveTo(this.offset.x+(t.x+a)*this.scale.x-4,this.offset.y+(t.y+h)*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+a)*this.scale.x+4,this.offset.y+(t.y+h)*this.scale.y),this.ctx.moveTo(this.offset.x+(t.x+a)*this.scale.x,this.offset.y+(t.y+h)*this.scale.y-4),this.ctx.lineTo(this.offset.x+(t.x+a)*this.scale.x,this.offset.y+(t.y+h)*this.scale.y+4);this.ctx.strokeStyle=n,this.ctx.lineWidth=1,this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}diamondHandle(t,e,s){this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e/2,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y-e/2),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e/2,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y+e/2),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(s)}squareHandle(t,e,s){this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.rect(this.offset.x+t.x*this.scale.x-e/2,this.offset.y+t.y*this.scale.y-e/2,e,e),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(s)}circleHandle(t,e,s){e=e||3,this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.arc(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e,0,2*Math.PI,!1),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(s)}crosshair(t,e,s,i){this.ctx.save(),this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e,this.offset.y+t.y*this.scale.y),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y-e),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y+e),this.ctx.strokeStyle=s,this.ctx.lineWidth=i||.5,this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}cross(t,e,s,i){this.ctx.save(),this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e,this.offset.y+t.y*this.scale.y-e),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e,this.offset.y+t.y*this.scale.y+e),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e,this.offset.y+t.y*this.scale.y+e),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e,this.offset.y+t.y*this.scale.y-e),this.ctx.strokeStyle=s,this.ctx.lineWidth=i||1,this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}polygon(t,e,s,i){this.polyline(t.vertices,t.isOpen,e,s,i)}polyline(t,e,s,i,r){if(!(t.length<=1)){this.ctx.save(),this.applyStrokeOpts(r),this.ctx.beginPath(),this.ctx.lineWidth=(i||1)*this.scale.x,this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var n=0;n<t.length;n++)this.ctx.lineTo(this.offset.x+t[n].x*this.scale.x,this.offset.y+t[n].y*this.scale.y);e||this.ctx.closePath(),this._fillOrDraw(s),this.ctx.closePath(),this.ctx.setLineDash([]),this.ctx.restore()}}text(t,e,s,i){var r,n,a;i=i||{},this.ctx.save();let h=this.offset.x+e*this.scale.x,o=this.offset.y+s*this.scale.y;const l=i.color||"black";(i.fontSize||i.fontFamily)&&(this.ctx.font=(i.fontWeight?i.fontWeight+" ":"")+(i.fontStyle?i.fontStyle+" ":"")+(i.fontSize?i.fontSize*this.scale.x+"px ":" ")+(i.fontFamily?-1===i.fontFamily.indexOf(" ")?i.fontFamily:`"${i.fontFamily}"`:"Arial")),i.textAlign&&(this.ctx.textAlign=i.textAlign);const c=null!==(r=i.rotation)&&void 0!==r?r:0,d=(null!==(a=null!==(n=i.lineHeight)&&void 0!==n?n:i.fontSize)&&void 0!==a?a:0)*this.scale.x;this.ctx.translate(h,o),this.ctx.rotate(c),this.fillShapes?(this.ctx.fillStyle=l,this.ctx.fillText(t,0,d/2)):(this.ctx.strokeStyle=l,this.ctx.strokeText(t,0,d/2)),this.ctx.restore()}label(t,e,s,i,r){this.ctx.save(),this.ctx.font="lighter 9pt Arial",this.ctx.translate(e,s),void 0!==i&&this.ctx.rotate(i),this.ctx.fillStyle=r||"black",this.fillShapes?this.ctx.fillText(t,0,0):this.ctx.strokeText(t,0,0),this.ctx.restore()}path(t,e,s,i){const r=i&&i.inplace?t:f.copyPathData(t);f.transformPathData(r,this.offset,this.scale),e&&(this.ctx.strokeStyle=e),this.ctx.lineWidth=s||1,this.applyStrokeOpts(i),this.fillShapes?(e&&(this.ctx.fillStyle=e),this.ctx.fill(new Path2D(r.join(" ")))):(e&&(this.ctx.strokeStyle=e),this.ctx.stroke(new Path2D(r.join(" "))))}clear(t){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.fillStyle=t,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}}x.helpers={clipPoly:(t,e,s,i)=>{t.beginPath(),t.moveTo(e.x+i[0].x*s.x,e.y+i[0].y*s.y);for(var r=1;r<i.length;r++){const n=i[r];t.lineTo(e.x+n.x*s.x,e.y+n.y*s.y)}t.closePath(),t.clip()}};class v{constructor(t,e){this.gl=t,this.offset=new i(0,0),this.scale=new i(1,1),this.fillShapes=e,this._zindex=0,null!=t&&void 0!==t&&(this.glutils=new y(t),this._vertShader=this.glutils.compileShader(v.vertCode,this.gl.VERTEX_SHADER),this._fragShader=this.glutils.compileShader(v.fragCode,this.gl.FRAGMENT_SHADER),this._program=this.glutils.makeProgram(this._vertShader,this._fragShader),this.vertex_buffer=this.gl.createBuffer(),console.log("gl initialized"))}_x2rel(t){return(this.scale.x*t+this.offset.x)/this.gl.canvas.width*2-1}_y2rel(t){return(this.offset.y-this.scale.y*t)/this.gl.canvas.height*2-1}copyInstance(t){var e=new v(null,t);return e.gl=this.gl,e.glutils=this.glutils,e._vertShader=this._vertShader,e._fragShader=this._fragShader,e._program=this._program,e}beginDrawCycle(t){this._zindex=0,this.renderTime=t}endDrawCycle(t){}setConfiguration(t){}setCurrentId(t){this.curId=t}setCurrentClassName(t){}line(t,e,s){const i=new Float32Array(6);i[0]=this._x2rel(t.x),i[1]=this._y2rel(t.y),i[2]=this._zindex,i[3]=this._x2rel(e.x),i[4]=this._y2rel(e.y),i[5]=this._zindex,this._zindex+=.001,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertex_buffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,i,this.gl.STATIC_DRAW);var r=this.gl.getAttribLocation(this._program,"position");this.gl.vertexAttribPointer(r,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(r),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);let n=this.gl.getUniformLocation(this._program,"uRotationVector");this.gl.uniform2fv(n,[0,1]),this.gl.lineWidth(5),this.gl.drawArrays(this.gl.LINES,0,i.length/3)}arrow(t,e,s){}cubicBezierArrow(t,e,s,i,r,n,a){}arrowHead(t,e,s,i,r){}image(t,e,s,i=0){}texturedPoly(t,e,s,i,r){}_fillOrDraw(t){}cubicBezier(t,e,s,i,r,n){}cubicBezierPath(t,e,s){}handle(t,e){}handleLine(t,e){}dot(t,e){}point(t,e){}circle(t,e,s,i){}circleArc(t,e,s,i,r,n){}ellipse(t,e,s,i,r,n){}square(t,e,s,i){}rect(t,e,s,i,r){}grid(t,e,s,i,r,n){}raster(t,e,s,i,r,n){}diamondHandle(t,e,s){}squareHandle(t,e,s){}circleHandle(t,e,s){}crosshair(t,e,s,i){}cross(t,e,s,i){}polygon(t,e,s){const i=new Float32Array(3*t.vertices.length);for(var r=0;r<t.vertices.length;r++)i[3*r+0]=this._x2rel(t.vertices[r].x),i[3*r+1]=this._y2rel(t.vertices[r].y),i[3*r+2]=this._zindex;this._zindex+=.001,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertex_buffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,i,this.gl.STATIC_DRAW);var n=this.gl.getAttribLocation(this._program,"position");this.gl.vertexAttribPointer(n,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(n),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);let a=this.gl.getUniformLocation(this._program,"uRotationVector");this.gl.uniform2fv(a,[0,1]),this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,i.length/3)}polyline(t,e,s,i){}text(t,e,s,i){}label(t,e,s,i,r){}path(t,e,s,i){}clear(t){this.gl.clearColor(1,1,1,1),this.gl.enable(this.gl.DEPTH_TEST),this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT)}}v.vertCode="\n precision mediump float;\n\n attribute vec3 position;\n\n uniform vec2 uRotationVector;\n\n void main(void) {\n\tvec2 rotatedPosition = vec2(\n\t position.x * uRotationVector.y +\n\t\tposition.y * uRotationVector.x,\n\t position.y * uRotationVector.y -\n\t\tposition.x * uRotationVector.x\n\t);\n\n\tgl_Position = vec4(rotatedPosition, position.z, 1.0);\n }",v.fragCode="\n precision highp float;\n\n void main(void) {\n\tgl_FragColor = vec4(0.0,0.75,1.0,1.0);\n }";class y{constructor(t){this.gl=t}bufferData(t){var e=this.gl.createBuffer();return this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e),this.gl.bufferData(this.gl.ARRAY_BUFFER,t,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),e}compileShader(t,e){var s=this.gl.createShader(e);this.gl.shaderSource(s,t),this.gl.compileShader(s);return this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)?s:(console.warn("Error in shader:"+this.gl.getShaderInfoLog(s)),this.gl.deleteShader(s),null)}makeProgram(t,e){var s=this.gl.createProgram();return this.gl.attachShader(s,t),this.gl.attachShader(s,e),this.gl.linkProgram(s),this.gl.useProgram(s),this.gl.detachShader(s,t),this.gl.detachShader(s,e),this.gl.deleteShader(t),this.gl.deleteShader(e),s}}class p{constructor(t,s,i){this.className="Triangle",this.uid=e.next(),this.a=t,this.b=s,this.c=i,this.calcCircumcircle()}static fromArray(t){if(t.length<3)throw`Cannot create triangle from array with less than three vertices (${t.length})`;return new p(t[0],t[1],t[2])}getArea(){return Math.abs(p.utils.signedArea(this.a.x,this.a.y,this.b.x,this.b.y,this.c.x,this.c.y))}getCentroid(){return new i((this.a.x+this.b.x+this.c.x)/3,(this.a.y+this.b.y+this.c.y)/3)}scaleToCentroid(t){let e=this.getCentroid();return this.a.scale(t,e),this.b.scale(t,e),this.c.scale(t,e),this}getCircumcircle(){return this.calcCircumcircle(),new d(this.center.clone(),this.radius)}isAdjacent(t){var e=this.a.equals(t.a)||this.a.equals(t.b)||this.a.equals(t.c),s=this.b.equals(t.a)||this.b.equals(t.b)||this.b.equals(t.c),i=this.c.equals(t.a)||this.c.equals(t.b)||this.c.equals(t.c);return e&&s||e&&i||s&&i}getThirdVertex(t,e){return this.a.equals(t)&&this.b.equals(e)||this.a.equals(e)&&this.b.equals(t)?this.c:this.b.equals(t)&&this.c.equals(e)||this.b.equals(e)&&this.c.equals(t)?this.a:this.b}calcCircumcircle(){const t=this.b.x-this.a.x,e=this.b.y-this.a.y,s=this.c.x-this.a.x,r=this.c.y-this.a.y,n=t*(this.a.x+this.b.x)+e*(this.a.y+this.b.y),a=s*(this.a.x+this.c.x)+r*(this.a.y+this.c.y),h=2*(t*(this.c.y-this.b.y)-e*(this.c.x-this.b.x));let o,l;if(Math.abs(h)<p.EPSILON){const t=this.bounds();this.center=new i((t.min.x+t.max.x)/2,(t.min.y+t.max.y)/2),o=this.center.x-t.min.x,l=this.center.y-t.min.y}else{const c=(r*n-e*a)/h,d=(t*a-s*n)/h;this.center=new i(c,d),o=this.center.x-this.a.x,l=this.center.y-this.a.y}this.radius_squared=o*o+l*l,this.radius=Math.sqrt(this.radius_squared)}inCircumcircle(t){const e=this.center.x-t.x,s=this.center.y-t.y;return e*e+s*s<=this.radius_squared}bounds(){return new h(new i(p.utils.min3(this.a.x,this.b.x,this.c.x),p.utils.min3(this.a.y,this.b.y,this.c.y)),new i(p.utils.max3(this.a.x,this.b.x,this.c.x),p.utils.max3(this.a.y,this.b.y,this.c.y)))}toPolygon(){return new a([this.a,this.b,this.c])}determinant(){return(this.b.y-this.a.y)*(this.c.x-this.b.x)-(this.c.y-this.b.y)*(this.b.x-this.a.x)}containsPoint(t){return p.utils.pointIsInTriangle(t.x,t.y,this.a.x,this.a.y,this.b.x,this.b.y,this.c.x,this.c.y)}getIncircularTriangle(){const t=new n(this.a,this.b),e=new n(this.b,this.c),s=new n(this.c,this.a),i=m.nsectAngle(this.b,this.a,this.c,2)[0],r=m.nsectAngle(this.c,this.b,this.a,2)[0],a=i.intersection(r),h=t.getClosestPoint(a),o=e.getClosestPoint(a),l=s.getClosestPoint(a);return new p(h,o,l)}getIncircle(){return this.getIncircularTriangle().getCircumcircle()}getIncenter(){return this.center&&this.radius||this.calcCircumcircle(),this.center.clone()}toString(){return"{ a : "+this.a.toString()+", b : "+this.b.toString()+", c : "+this.c.toString()+"}"}destroy(){this.a.destroy(),this.b.destroy(),this.c.destroy(),this.isDestroyed=!0}}p.EPSILON=1e-6,p.utils={max3:(t,e,s)=>t>=e&&t>=s?t:e>=t&&e>=s?e:s,min3:(t,e,s)=>t<=e&&t<=s?t:e<=t&&e<=s?e:s,signedArea:(t,e,s,i,r,n)=>.5*(-i*r+e*(-s+r)+t*(i-n)+s*n),pointIsInTriangle(t,e,s,i,r,n,a,h){var o=p.utils.signedArea(s,i,r,n,a,h),l=1/(2*o)*(i*a-s*h+(h-i)*t+(s-a)*e),c=1/(2*o)*(s*n-i*r+(i-n)*t+(r-s)*e);return l>0&&c>0&&1-l-c>0}};const m={nsectAngle(t,e,s,i){const r=new p(t,e,s),a=new n(t,e),h=new n(t,s);var o=a.angle(h);const l=r.determinant()>0;o<0&&(o=2*Math.PI+o),l||(o=-1*(2*Math.PI-o));const c=Math.max(a.length(),h.length())/a.length();for(var d=[],u=1;u<i;u++)d.push(new n(t,e.clone().rotate(o/i*-u,t)).scale(c));return d},wrapMax:(t,e)=>(e+t%e)%e,wrapMinMax:(t,e,s)=>e+m.wrapMax(t-e,s-e)};class b{constructor(t,e){this.center=t,this.size=e}}b.utils={baseLog:(t,e)=>Math.log(t)/Math.log(e),mapRasterScale:(t,e)=>{var s=1;return e>=1?(s=Math.abs(Math.floor(1/b.utils.baseLog(t,e))),s=1/Math.pow(t,s)):s=Math.abs(Math.floor(b.utils.baseLog(1/t,1/(e+1)))),s}};class w{constructor(t){this.downListeners=[],this.pressListeners=[],this.upListeners=[],this.keyStates={},t=t||{},this.element=t.element?t.element:globalThis,this.downListeners=[],this.pressListeners=[],this.upListeners=[],this.keyStates=[],this.trackAllKeys=t.trackAll||!1,this.installListeners()}fireEvent(t,e){let s=!1;for(var i in e){var r=e[i];r.keyCode==t.keyCode&&(r.listener(t),s=!0)}return s}fireDownEvent(t,e){(e.fireEvent(t,e.downListeners)||e.trackAllKeys)&&(e.keyStates[t.keyCode]="down")}firePressEvent(t,e){e.fireEvent(t,e.pressListeners)}fireUpEvent(t,e){(e.fireEvent(t,e.upListeners)||e.trackAllKeys)&&delete e.keyStates[t.keyCode]}static key2code(t){if("number"==typeof t)return t;if("string"!=typeof t)throw"Unknown key name or key type (should be a string or integer): "+t;if(w.KEY_CODES[t])return w.KEY_CODES[t];throw"Unknown key (cannot resolve key code): "+t}installListeners(){var t=this;this.element.addEventListener("keydown",this._keyDownListener=e=>{t.fireDownEvent(e,t)}),this.element.addEventListener("keypress",this._keyPressListener=e=>{t.firePressEvent(e,t)}),this.element.addEventListener("keyup",this._keyUpListener=e=>{t.fireUpEvent(e,t)})}releaseListeners(){this.element.removeEventListener("keydown",this._keyDownListener),this.element.removeEventListener("keypress",this._keyPressListener),this.element.removeEventListener("keyup",this._keyUpListener)}down(t,e){return this.downListeners.push({key:t,keyCode:w.key2code(t),listener:e}),this}press(t,e){return this.pressListeners.push({key:t,keyCode:w.key2code(t),listener:e}),this}up(t,e){return this.upListeners.push({key:t,keyCode:w.key2code(t),listener:e}),this}isDown(t){return"number"==typeof t?!!this.keyStates[t]:!!this.keyStates[w.key2code(t)]}destroy(){this.releaseListeners()}}w.KEY_CODES={break:3,backspace:8,tab:9,clear:12,enter:13,shift:16,ctrl:17,alt:18,pause:19,capslock:20,hangul:21,hanja:25,escape:27,conversion:28,"non-conversion":29,spacebar:32,pageup:33,pagedown:34,end:35,home:36,leftarrow:37,uparrow:38,rightarrow:39,downarrow:40,select:41,print:42,execute:43,printscreen:44,insert:45,delete:46,help:47,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,":":58,"semicolon (firefox)":59,equals:59,"<":60,"equals (firefox)":61,"ß":63,"@ (firefox)":64,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,windows:91,leftcommand:91,chromebooksearch:91,rightwindowkey:92,windowsmenu:93,rightcommant:93,sleep:95,numpad0:96,numpad1:97,numpad2:98,numpad3:99,numpad4:100,numpad5:101,numpad6:102,numpad7:103,numpad8:104,numpad9:105,multiply:106,add:107,numpadperiod:108,subtract:109,decimalpoint:110,divide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,f13:124,f14:125,f15:126,f16:127,f17:128,f18:129,f19:130,f20:131,f21:132,f22:133,f23:134,f24:135,numlock:144,scrolllock:145,"^":160,"!":161,"#":163,$:164,"ù":165,pagebackward:166,pageforward:167,refresh:168,closingparen:169,"*":170,"~+*":171,minus:173,decreasevolumelevel:174,increasevolumelevel:175,next:176,previous:177,stop:178,"play/pause":179,email:180,mute:181,unmute:181,semicolon:186,"ñ":186,equal:187,comma:188,dash:189,period:190,forwardslash:191,"ç":191,"grave accent":192,"æ":192,"ö":192,"?":193,"/":193,"°":193,openbracket:219,backslash:220,closebracket:221,"å":221,singlequote:222,"ø":222,"ä":222,"`":223,altgr:225,"GNOME Compose Key":230,XF86Forward:233,XF86Back:234,alphanumeric:240,hiragana:242,katakana:242,"half-width":243,"full-width":243,kanji:244,unlocktrackpad:251,toggletouchpad:255};class C extends MouseEvent{}class P extends WheelEvent{}class A{constructor(t,e){this.mouseDownPos=void 0,this.mouseDragPos=void 0,this.mouseButton=-1,this.listeners={},this.installed={},this.handlers={},this.name=e,this.element=t,this.mouseDownPos=void 0,this.mouseDragPos=void 0,this.mouseButton=-1,this.listeners={},this.installed={},this.handlers={};const s=this;this.handlers.mousemove=t=>{s.listeners.mousemove&&s.listeners.mousemove(s.mkParams(t,"mousemove")),s.mouseDragPos&&s.listeners.drag&&s.listeners.drag(s.mkParams(t,"drag")),s.mouseDownPos&&(s.mouseDragPos=s.relPos(t))},this.handlers.mouseup=t=>{s.listeners.mouseup&&s.listeners.mouseup(s.mkParams(t,"mouseup")),s.mouseDragPos=void 0,s.mouseDownPos=void 0,s.mouseButton=-1},this.handlers.mousedown=t=>{s.mouseDragPos=s.relPos(t),s.mouseDownPos=s.relPos(t),s.mouseButton=t.button,s.listeners.mousedown&&s.listeners.mousedown(s.mkParams(t,"mousedown"))},this.handlers.click=t=>{s.listeners.click&&s.listeners.click(s.mkParams(t,"click"))},this.handlers.wheel=t=>{s.listeners.wheel&&s.listeners.wheel(s.mkParams(t,"wheel"))},this.element.addEventListener("mousemove",this.handlers.mousemove),this.element.addEventListener("mouseup",this.handlers.mouseup),this.element.addEventListener("mousedown",this.handlers.mousedown),this.element.addEventListener("click",this.handlers.click),this.element.addEventListener("wheel",this.handlers.wheel)}relPos(t){return{x:t.offsetX,y:t.offsetY}}mkParams(t,e){var s,i;const r=this.relPos(t),n=t;return n.params={element:this.element,name:e,isTouchEvent:!1,pos:r,button:t.button,leftButton:0===t.button,middleButton:1===t.button,rightButton:2===t.button,mouseDownPos:null!==(s=this.mouseDownPos)&&void 0!==s?s:{x:NaN,y:NaN},draggedFrom:null!==(i=this.mouseDragPos)&&void 0!==i?i:{x:NaN,y:NaN},wasDragged:null!=this.mouseDownPos&&(this.mouseDownPos.x!=r.x||this.mouseDownPos.y!=r.y),dragAmount:null!=this.mouseDragPos?{x:r.x-this.mouseDragPos.x,y:r.y-this.mouseDragPos.y}:{x:0,y:0}},n}listenFor(t){this.installed[t]||(this.installed[t]=!0)}unlistenFor(t){this.installed[t]&&delete this.installed[t]}drag(t){return this.listeners.drag&&this.throwAlreadyInstalled("drag"),this.listeners.drag=t,this.listenFor("mousedown"),this.listenFor("mousemove"),this.listenFor("mouseup"),this}move(t){return this.listeners.mousemove&&this.throwAlreadyInstalled("mousemove"),this.listenFor("mousemove"),this.listeners.mousemove=t,this}up(t){return this.listeners.mouseup&&this.throwAlreadyInstalled("mouseup"),this.listenFor("mouseup"),this.listeners.mouseup=t,this}down(t){return this.listeners.mousedown&&this.throwAlreadyInstalled("mousedown"),this.listenFor("mousedown"),this.listeners.mousedown=t,this}click(t){return this.listeners.click&&this.throwAlreadyInstalled("click"),this.listenFor("click"),this.listeners.click=t,this}wheel(t){return this.listeners.wheel&&this.throwAlreadyInstalled("wheel"),this.listenFor("wheel"),this.listeners.wheel=t,this}throwAlreadyInstalled(t){throw`This MouseHandler already has a '${t}' callback. To keep the code simple there is only room for one.`}destroy(){this.unlistenFor("mousedown"),this.unlistenFor("mousemove"),this.unlistenFor("moseup"),this.unlistenFor("click"),this.unlistenFor("wheel"),this.element.removeEventListener("mousemove",this.handlers.mousemove),this.element.removeEventListener("mouseup",this.handlers.mousedown),this.element.removeEventListener("mousedown",this.handlers.mousedown),this.element.removeEventListener("click",this.handlers.click),this.element.removeEventListener("wheel",this.handlers.wheel)}}class S{constructor(t,s,i){this.className="PBImage",this.uid=e.next(),this.image=t,this.upperLeft=s,this.lowerRight=i}destroy(){this.upperLeft.destroy(),this.lowerRight.destroy(),this.isDestroyed=!0}}class T{constructor(t,s,r){this.className="PBText",this.uid=e.next(),this.text=t,this.anchor=null!=s?s:new i,this.color=null==r?void 0:r.color,this.fontFamily=null==r?void 0:r.fontFamily,this.fontSize=null==r?void 0:r.fontSize,this.fontStyle=null==r?void 0:r.fontStyle,this.fontWeight=null==r?void 0:r.fontWeight,this.lineHeight=null==r?void 0:r.lineHeight,this.textAlign=null==r?void 0:r.textAlign,this.rotation=null==r?void 0:r.rotation}destroy(){this.anchor.destroy(),this.isDestroyed=!0}}const N=t=>Math.sqrt(t.x*t.x+t.y*t.y),_=(t,e)=>{var s=((t,e)=>{const s=N(t)*N(e);if(0===s)return 0;var i=((t,e)=>t.x*e.x+t.y*e.y)(t,e)/s;return i>1&&(i=1),Math.acos(i)})(t,e);return((t,e)=>t.x*e.y-e.x*t.y)(t,e)>0&&(s*=-1),180*s/Math.PI};class z{constructor(t){this.handlers=[],this.el=t}add(t){this.handlers.push(t)}del(t){t||(this.handlers=[]);for(var e=this.handlers.length;e>=0;e--)this.handlers[e]===t&&this.handlers.splice(e,1)}dispatch(...t){for(var e=0,s=this.handlers.length;e<s;e++){const t=this.handlers[e];"function"==typeof t&&t.apply(this.el,arguments)}}}const D=(t,e)=>{const s=new z(t);return s.add(e),s};class M{constructor(t,e){this.element="string"==typeof t?document.querySelector(t):t,this.start=this.start.bind(this),this.move=this.move.bind(this),this.end=this.end.bind(this),this.cancel=this.cancel.bind(this),this.element.addEventListener("touchstart",this.start,!1),this.element.addEventListener("touchmove",this.move,!1),this.element.addEventListener("touchend",this.end,!1),this.element.addEventListener("touchcancel",this.cancel,!1),this.preV={x:null,y:null},this.pinchStartLen=null,this.zoom=1,this.isDoubleTap=!1;const s=()=>{};this.rotate=D(this.element,e.rotate||s),this.touchStart=D(this.element,e.touchStart||s),this.multipointStart=D(this.element,e.multipointStart||s),this.multipointEnd=D(this.element,e.multipointEnd||s),this.pinch=D(this.element,e.pinch||s),this.swipe=D(this.element,e.swipe||s),this.tap=D(this.element,e.tap||s),this.doubleTap=D(this.element,e.doubleTap||s),this.longTap=D(this.element,e.longTap||s),this.singleTap=D(this.element,e.singleTap||s),this.pressMove=D(this.element,e.pressMove||s),this.twoFingerPressMove=D(this.element,e.twoFingerPressMove||s),this.touchMove=D(this.element,e.touchMove||s),this.touchEnd=D(this.element,e.touchEnd||s),this.touchCancel=D(this.element,e.touchCancel||s),this._cancelAllHandler=this.cancelAll.bind(this),globalThis&&"function"==typeof globalThis.addEventListener&&globalThis.addEventListener("scroll",this._cancelAllHandler),this.delta=null,this.last=null,this.now=null,this.tapTimeout=null,this.singleTapTimeout=null,this.longTapTimeout=null,this.swipeTimeout=null,this.x1=this.x2=this.y1=this.y2=null,this.preTapPosition={x:null,y:null}}start(t){if(!t.touches)return;const e=this;this.now=Date.now(),this.x1=t.touches[0].pageX,this.y1=t.touches[0].pageY,this.delta=this.now-(this.last||this.now),this.touchStart.dispatch(t,this.element),null!==this.preTapPosition.x&&(this.isDoubleTap=this.delta>0&&this.delta<=250&&Math.abs(this.preTapPosition.x-this.x1)<30&&Math.abs(this.preTapPosition.y-this.y1)<30,this.isDoubleTap&&clearTimeout(this.singleTapTimeout)),this.preTapPosition.x=this.x1,this.preTapPosition.y=this.y1,this.last=this.now;const s=this.preV;if(t.touches.length>1){this._cancelLongTap(),this._cancelSingleTap();const e={x:t.touches[1].pageX-this.x1,y:t.touches[1].pageY-this.y1};s.x=e.x,s.y=e.y,this.pinchStartLen=N(s),this.multipointStart.dispatch(t,this.element)}this._preventTap=!1,this.longTapTimeout=setTimeout((()=>{e.longTap.dispatch(t,e.element),e._preventTap=!0}).bind(e),750)}move(t){if(!t.touches)return;const e=t,s=this.preV,i=t.touches.length,r=t.touches[0].pageX,n=t.touches[0].pageY;if(this.isDoubleTap=!1,i>1){const t=e.touches[1].pageX,i=e.touches[1].pageY,a={x:e.touches[1].pageX-r,y:e.touches[1].pageY-n};null!==s.x&&(this.pinchStartLen>0&&(e.zoom=N(a)/this.pinchStartLen,this.pinch.dispatch(e,this.element)),e.angle=_(a,s),this.rotate.dispatch(e,this.element)),s.x=a.x,s.y=a.y,null!==this.x2&&null!==this.sx2?(e.deltaX=(r-this.x2+t-this.sx2)/2,e.deltaY=(n-this.y2+i-this.sy2)/2):(e.deltaX=0,e.deltaY=0),this.twoFingerPressMove.dispatch(e,this.element),this.sx2=t,this.sy2=i}else{if(null!==this.x2){e.deltaX=r-this.x2,e.deltaY=n-this.y2;const t=Math.abs(this.x1-this.x2),s=Math.abs(this.y1-this.y2);(t>10||s>10)&&(this._preventTap=!0)}else e.deltaX=0,e.deltaY=0;this.pressMove.dispatch(e,this.element)}this.touchMove.dispatch(e,this.element),this._cancelLongTap(),this.x2=r,this.y2=n,i>1&&t.preventDefault()}end(t){if(!t.changedTouches)return;const e=t;this._cancelLongTap();const s=this;e.touches.length<2&&(this.multipointEnd.dispatch(e,this.element),this.sx2=this.sy2=null),this.x2&&Math.abs(this.x1-this.x2)>30||this.y2&&Math.abs(this.y1-this.y2)>30?(e.direction=this._swipeDirection(this.x1,this.x2,this.y1,this.y2),this.swipeTimeout=setTimeout((function(){s.swipe.dispatch(e,s.element)}),0)):(this.tapTimeout=setTimeout((function(){s._preventTap||s.tap.dispatch(e,s.element),s.isDoubleTap&&(s.doubleTap.dispatch(e,s.element),s.isDoubleTap=!1)}),0),s.isDoubleTap||(s.singleTapTimeout=setTimeout((function(){s.singleTap.dispatch(e,s.element)}),250))),this.touchEnd.dispatch(e,this.element),this.preV.x=0,this.preV.y=0,this.zoom=1,this.pinchStartLen=null,this.x1=this.x2=this.y1=this.y2=null}cancelAll(){this._preventTap=!0,clearTimeout(this.singleTapTimeout),clearTimeout(this.tapTimeout),clearTimeout(this.longTapTimeout),clearTimeout(this.swipeTimeout)}cancel(t){this.cancelAll(),this.touchCancel.dispatch(t,this.element)}_cancelLongTap(){clearTimeout(this.longTapTimeout)}_cancelSingleTap(){clearTimeout(this.singleTapTimeout)}_swipeDirection(t,e,s,i){return Math.abs(t-e)>=Math.abs(s-i)?t-e>0?"Left":"Right":s-i>0?"Up":"Down"}on(t,e){if(this[t]){this[t].add(e)}}off(t,e){if(this[t]){this[t].del(e)}}destroy(){this.singleTapTimeout&&clearTimeout(this.singleTapTimeout),this.tapTimeout&&clearTimeout(this.tapTimeout),this.longTapTimeout&&clearTimeout(this.longTapTimeout),this.swipeTimeout&&clearTimeout(this.swipeTimeout),this.element.removeEventListener("touchstart",this.start),this.element.removeEventListener("touchmove",this.move),this.element.removeEventListener("touchend",this.end),this.element.removeEventListener("touchcancel",this.cancel),this.rotate.del(),this.touchStart.del(),this.multipointStart.del(),this.multipointEnd.del(),this.pinch.del(),this.swipe.del(),this.tap.del(),this.doubleTap.del(),this.longTap.del(),this.singleTap.del(),this.pressMove.del(),this.twoFingerPressMove.del(),this.touchMove.del(),this.touchEnd.del(),this.touchCancel.del(),this.preV=this.pinchStartLen=this.zoom=this.isDoubleTap=this.delta=this.last=this.now=this.tapTimeout=this.singleTapTimeout=this.longTapTimeout=this.swipeTimeout=this.x1=this.x2=this.y1=this.y2=this.preTapPosition=this.rotate=this.touchStart=this.multipointStart=this.multipointEnd=this.pinch=this.swipe=this.tap=this.doubleTap=this.longTap=this.singleTap=this.pressMove=this.touchMove=this.touchEnd=this.touchCancel=this.twoFingerPressMove=null,globalThis&&"function"==typeof globalThis.removeEventListener&&globalThis.removeEventListener("scroll",this._cancelAllHandler)}}class L{constructor(t,s,i){this.className="VEllipse",this.uid=e.next(),this.center=t,this.axis=s,this.rotation=i||0}clone(){return new L(this.center.clone(),this.axis.clone(),this.rotation)}radiusH(){return Math.abs(this.signedRadiusH())}signedRadiusH(){return new i(this.axis).rotate(-this.rotation,this.center).x-this.center.x}radiusV(){return Math.abs(this.signedRadiusV())}signedRadiusV(){return new i(this.axis).rotate(-this.rotation,this.center).y-this.center.y}scale(t){return this.axis.scale(t,this.center),this}rotate(t){return this.axis.rotate(t,this.center),this.rotation+=t,this}vertAt(t){const e=this.radiusH(),s=this.radiusV();return new i(L.utils.polarToCartesian(this.center.x,this.center.y,e,s,t)).rotate(this.rotation,this.center)}normalAt(t,e){const s=this.vertAt(t),i=this.getFoci(),r=new n(s,i[0]).angle(),a=r+(new n(s,i[1]).angle()-r)/2,h=s.clone().addX(50).clone().rotate(a,s),l=s.clone().addX(50).clone().rotate(Math.PI+a,s);return this.center.distance(h)<this.center.distance(l)?new o(s,l):new o(s,h)}tangentAt(t,e){const s=this.normalAt(t,e);return s.b.rotate(Math.PI/2,s.a),s}perimeter(){const t=this.radiusH(),e=this.radiusV();return Math.PI*(3*(t+e)-Math.sqrt((3*t+e)*(t+3*e)))}getFoci(){const t=this.radiusH(),e=this.radiusV(),s=t*t-e*e,i=Math.sqrt(Math.abs(s));return s<0?[this.center.clone().addY(i).rotate(this.rotation,this.center),this.center.clone().addY(-i).rotate(this.rotation,this.center)]:[this.center.clone().addX(i).rotate(this.rotation,this.center),this.center.clone().addX(-i).rotate(this.rotation,this.center)]}getEquidistantVertices(t){const e=L.utils.equidistantVertAngles(this.radiusH(),this.radiusV(),t),s=[];for(var i=0;i<e.length;i++)s.push(this.vertAt(e[i]));return s}toCubicBezier(t,e){const s=4*Math.max(1,t||3);e=void 0===e?.666666:e;const i=this.radiusH(),r=this.radiusV(),n=[],a=L.utils.equidistantVertAngles(i,r,s);let h=a[0],o=this.vertAt(h);for(var c=0;c<a.length;c++){let t=a[(c+1)%a.length],s=this.vertAt(t);if(Math.abs(r)<1e-4||Math.abs(i)<1e-4){let t=o.difference(s),e=new l(o.clone(),s.clone(),o.clone().addXY(.333*t.x,.333*t.y),s.clone().addXY(.333*-t.x,.333*-t.y));n.push(e)}else{let i=this.tangentAt(h),r=this.tangentAt(t),a=i.intersection(r),c=o.difference(a),d=s.difference(a),u=new l(o.clone(),s.clone(),o.clone().add(c.scale(e)),s.clone().add(d.scale(e)));n.push(u)}o=s,h=t}return n}destroy(){this.center.destroy(),this.axis.destroy(),this.isDestroyed=!0}}L.utils={polarToCartesian:(t,e,s,i,r)=>{var n=Math.sin(Math.PI/2-r),a=Math.cos(Math.PI/2-r);return{x:t+s*i*n/Math.sqrt(Math.pow(s*a,2)+Math.pow(i*n,2)),y:e+s*i*a/Math.sqrt(Math.pow(s*a,2)+Math.pow(i*n,2))}},phiToTheta:(t,e,s)=>{var i=Math.tan(s),r=i*i;return-Math.PI/2+s+Math.atan((t-e)*i/(e+t*r))},equidistantVertAngles:(t,e,s)=>{const i=[];for(var r=0;r<s;r++){var n=Math.PI/2+2*Math.PI/s*r;let a=L.utils.phiToTheta(t,e,n);i[r]=a}return i}};class E{constructor(t,s,i){this.className="VEllipseSector",this.uid=e.next(),this.ellipse=t,this.startAngle=m.wrapMinMax(s,0,2*Math.PI),this.endAngle=m.wrapMinMax(i,0,2*Math.PI)}toCubicBezier(t,e){const s=4*Math.max(1,t||3);e=void 0===e?.666666:e;const i=this.ellipse.radiusH(),r=this.ellipse.radiusV();var n=E.ellipseSectorUtils.normalizeAngle(this.startAngle),a=E.ellipseSectorUtils.normalizeAngle(this.endAngle),h=E.ellipseSectorUtils.equidistantVertAngles(i,r,n,a,s);const o=[];let c=(h=[n].concat(h).concat([a]))[0],d=this.ellipse.vertAt(c);for(var u=0;u+1<h.length;u++){let t=h[(u+1)%h.length],s=this.ellipse.vertAt(t),n=this.ellipse.tangentAt(c),a=this.ellipse.tangentAt(t);if(Math.abs(r)<1e-4||Math.abs(i)<1e-4){let t=d.difference(s),e=new l(d.clone(),s.clone(),d.clone().addXY(.333*t.x,.333*t.y),s.clone().addXY(.333*-t.x,.333*-t.y));o.push(e)}else{let t=n.intersection(a);if(t){let i=d.difference(t),r=s.difference(t),n=new l(d.clone(),s.clone(),d.clone().add(i.scale(e)),s.clone().add(r.scale(e)));o.push(n)}}d=s,c=t}return o}destroy(){this.ellipse.destroy(),this.isDestroyed=!0}}E.ellipseSectorUtils={describeSVGArc:(t,e,s,r,n,a,h,o)=>{void 0===o&&(o={moveToStart:!0}),void 0===h&&(h=0),n=m.wrapMax(n,2*Math.PI),a=m.wrapMax(a,2*Math.PI);var l=new i(L.utils.polarToCartesian(t,e,s,r,a)),c=new i(L.utils.polarToCartesian(t,e,s,r,n));l.rotate(h,{x:t,y:e}),c.rotate(h,{x:t,y:e});var d,u=a-n;d=u<0?Math.abs(u)<Math.PI?1:0:Math.abs(u)>Math.PI?1:0;const g=[];o.moveToStart&&g.push("M",c.x,c.y);const f=180/Math.PI;return g.push("A",s,r,h*f,d,1,l.x,l.y),g},equidistantVertAngles:(t,e,s,i,r)=>{for(var n=(n=(n=L.utils.equidistantVertAngles(t,e,r)).map((t=>E.ellipseSectorUtils.normalizeAngle(t)))).filter((t=>s<i?t>=s&&t<=i:t>=s||t<=i&&t>=0)),a=E.ellipseSectorUtils.findClosestToStartAngle(s,i,n),h=[],o=0;o<n.length;o++)h.push(n[(a+o)%n.length]);return h},findClosestToStartAngle:(t,e,s)=>{if(t>e){const r=s.length;for(var i=0;i<r;i++){const r=m.wrapMinMax(s[i],0,2*Math.PI);if(r>=t&&r>=e)return i}}return 0},normalizeAngle:t=>t<0?2*Math.PI+t:t,endpointToCenterParameters(t,e,s,r,a,h,o,l,c){const d=Math.abs,u=Math.sin,g=Math.cos,f=Math.sqrt,x=t=>t*t,v=u(a),y=g(a),p=y*(t-l)/2+v*(e-c)/2,m=-v*(t-l)/2+y*(e-c)/2,b=x(p),w=x(m),C=x(s),P=x(r),A=b/C+w/P;A>1?(s=f(A)*d(s),r=f(A)*d(r)):(s=d(s),r=d(r));const S=h===o?-1:1,T=f(Math.abs((C*P-C*w-P*b)/(C*w+P*b)))*S,N=T*(s*m)/r,_=T*(-r*p)/s,z=new i(y*N-v*_+(t+l)/2,v*N+y*_+(e+c)/2),D=z.clone().addXY(s,r),M=new L(z,D,0);M.rotate(a);const I=new n(M.center,new i(t,e)).angle(),k=new n(M.center,new i(l,c)).angle();return new E(M,I-a,k-a)}};var I,k=function(t,e,s){return"symbol"==typeof e&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(t,"name",{configurable:!0,value:s?"".concat(s," ",e):e})};class O{constructor(e,s){var r,n;if(this.renderTime=0,this._gui=null,t.model={bezierAutoAdjust:!1,renderTime:0,selectable:!0,isSelected:!1,draggable:!0,visible:!0},void 0===e.canvas)throw"No canvas specified.";const a=O.utils.fetch;this.config={canvas:e.canvas,fullSize:a.val(e,"fullSize",!0),fitToParent:a.bool(e,"fitToParent",!0),scaleX:a.num(e,"scaleX",1),scaleY:a.num(e,"scaleY",1),offsetX:a.num(e,"offsetX",0),offsetY:a.num(e,"offsetY",0),rasterGrid:a.bool(e,"rasterGrid",!0),drawRaster:a.bool(e,"drawRaster",!0),rasterScaleX:a.num(e,"rasterScaleX",1),rasterScaleY:a.num(e,"rasterScaleY",1),rasterAdjustFactor:a.num(e,"rasterAdjustdFactror",2),drawOrigin:a.bool(e,"drawOrigin",!1),autoAdjustOffset:a.val(e,"autoAdjustOffset",!0),offsetAdjustXPercent:a.num(e,"offsetAdjustXPercent",50),offsetAdjustYPercent:a.num(e,"offsetAdjustYPercent",50),backgroundColor:e.backgroundColor||"#ffffff",redrawOnResize:a.bool(e,"redrawOnResize",!0),defaultCanvasWidth:a.num(e,"defaultCanvasWidth",O.DEFAULT_CANVAS_WIDTH),defaultCanvasHeight:a.num(e,"defaultCanvasHeight",O.DEFAULT_CANVAS_HEIGHT),canvasWidthFactor:a.num(e,"canvasWidthFactor",1),canvasHeightFactor:a.num(e,"canvasHeightFactor",1),cssScaleX:a.num(e,"cssScaleX",1),cssScaleY:a.num(e,"cssScaleY",1),cssUniformScale:a.bool(e,"cssUniformScale",!0),saveFile:()=>{o.hooks.saveFile(o)},setToRetina:()=>{o._setToRetina()},autoDetectRetina:a.bool(e,"autoDetectRetina",!0),enableSVGExport:a.bool(e,"enableSVGExport",!0),preClear:a.func(e,"preClear",null),preDraw:a.func(e,"preDraw",null),postDraw:a.func(e,"postDraw",null),enableMouse:a.bool(e,"enableMouse",!0),enableTouch:a.bool(e,"enableTouch",!0),enableKeys:a.bool(e,"enableKeys",!0),enableMouseWheel:a.bool(e,"enableMouseWheel",!0),enableZoom:a.bool(e,"enableZoom",!0),enablePan:a.bool(e,"enablePan",!0),enableGL:a.bool(e,"enableGL",!1),isBackdropFiltersEnabled:a.bool(e,"isBackdropFiltersEnabled",!0)},this.drawConfig={drawVertices:!0,drawBezierHandleLines:a.bool(e,"drawBezierHandleLines",!0),drawBezierHandlePoints:a.bool(e,"drawBezierHandlePoints",!0),drawHandleLines:a.bool(e,"drawHandleLines",!0),drawHandlePoints:a.bool(e,"drawHandlePoints",!0),drawGrid:a.bool(e,"drawGrid",!0),drawRaster:a.bool(e,"drawRaster",!0),bezier:{color:"#00a822",lineWidth:2,handleLine:{color:"rgba(180,180,180,0.5)",lineWidth:1},pathVertex:{color:"#B400FF",lineWidth:1,fill:!0},controlVertex:{color:"#B8D438",lineWidth:1,fill:!0}},polygon:{color:"#0022a8",lineWidth:1},triangle:{color:"#6600ff",lineWidth:1},ellipse:{color:"#2222a8",lineWidth:1},ellipseSector:{color:"#a822a8",lineWidth:2},circle:{color:"#22a8a8",lineWidth:2},circleSector:{color:"#2280a8",lineWidth:1},vertex:{color:"#a8a8a8",lineWidth:1},selectedVertex:{color:"#c08000",lineWidth:2},line:{color:"#a844a8",lineWidth:1},vector:{color:"#ff44a8",lineWidth:1},image:{color:"#a8a8a8",lineWidth:1},text:{color:"rgba(192,0,128,0.5)",lineWidth:1,fill:!0,anchor:!0},origin:{color:"#000000"}},this.grid=new b(new i(0,0),new i(50,50)),this.canvasSize={width:O.DEFAULT_CANVAS_WIDTH,height:O.DEFAULT_CANVAS_HEIGHT};const h="string"==typeof e.canvas?document.querySelector(e.canvas):e.canvas;if(void 0===h)throw`Cannot initialize PlotBoilerplate with a null canvas (element "${e.canvas} not found).`;if("canvas"===h.tagName.toLowerCase())if(this.canvas=h,this.eventCatcher=this.canvas,this.config.enableGL&&void 0===v&&(console.warn("Cannot use webgl. Package was compiled without experimental gl support. Please use plotboilerplate-glsupport.min.js instead."),console.warn("Disabling GL and falling back to Canvas2D."),this.config.enableGL=!1),this.config.enableGL){const t=this.canvas.getContext("webgl");this.draw=new v(t,!1),this.fill=this.draw.copyInstance(!0),console.warn("Initialized with experimental mode enableGL=true. Note that this is not yet fully implemented.")}else{const t=this.canvas.getContext("2d");this.draw=new x(t,!1),this.fill=new x(t,!0)}else{if("svg"!==h.tagName.toLowerCase())throw"Element is neither a canvas nor an svg element.";if(void 0===f)throw"The svg draw library is not yet integrated part of PlotBoilerplate. Please include ./src/js/utils/helpers/drawutils.svg into your document.";this.canvas=h,this.draw=new f(this.canvas,new i,new i,this.canvasSize,!1,this.drawConfig,!1),this.fill=this.draw.copyInstance(!0),this.canvas.parentElement?(this.eventCatcher=document.createElement("div"),this.eventCatcher.style.position="absolute",this.eventCatcher.style.left="0",this.eventCatcher.style.top="0",this.eventCatcher.style.cursor="pointer",this.canvas.parentElement.style.position="relative",this.canvas.parentElement.appendChild(this.eventCatcher)):this.eventCatcher=document.body}e.title&&this.eventCatcher.setAttribute("title",e.title),this.draw.scale.set(null!==(r=this.config.scaleX)&&void 0!==r?r:1,this.config.scaleY),this.fill.scale.set(null!==(n=this.config.scaleX)&&void 0!==n?n:1,this.config.scaleY),this.vertices=[],this.selectPolygon=null,this.draggedElements=[],this.drawables=[],this.console=console,this.hooks={saveFile:O._saveFile};var o=this;globalThis.addEventListener("resize",(()=>o.resizeCanvas())),this.resizeCanvas(),e.autoDetectRetina&&this._setToRetina(),this.installInputListeners(),this.updateCSSscale(),this.redraw(),this.canvas.focus()}static _saveFile(t){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");var s=new f(e,t.draw.offset,t.draw.scale,t.canvasSize,!1,t.drawConfig),i=s.copyInstance(!0);s.beginDrawCycle(0),i.beginDrawCycle(0),t.config.preClear&&t.config.preClear(),s.clear(t.config.backgroundColor||"white"),t.config.preDraw&&t.config.preDraw(s,i),t.drawAll(0,s,i),t.drawVertices(0,s),t.config.postDraw&&t.config.postDraw(s,i),s.endDrawCycle(0),i.endDrawCycle(0);var r=(new XMLSerializer).serializeToString(e),n=new Blob(['<?xml version="1.0" encoding="utf-8"?>\n'+r],{type:"image/svg;charset=utf-8"});if("function"!=typeof globalThis.saveAs)throw"Cannot save file; did you load the ./utils/savefile helper function and the eligrey/SaveFile library?";(0,globalThis.saveAs)(n,"plotboilerplate.svg")}_setToRetina(){this.config.autoDetectRetina=!0;const t=globalThis.devicePixelRatio||1;this.config.cssScaleX=this.config.cssScaleY=1/t,this.config.canvasWidthFactor=this.config.canvasHeightFactor=t,this.resizeCanvas(),this.updateCSSscale()}fitToView(t){const e=new i(this.canvasSize.width/2,this.canvasSize.height/2),s=this.canvasSize.width/this.canvasSize.height,r=t.width/t.height,n=new i(t.max.x-t.width/2,t.max.y-t.height/2).inv().addXY(this.canvasSize.width/2,this.canvasSize.height/2);if(this.setOffset(n),s<r){const s=this.canvasSize.width/t.width;this.setZoom(s,s,e)}else{const s=this.canvasSize.height/t.height;this.setZoom(s,s,e)}this.redraw()}setConsole(t){this.console=t}updateCSSscale(){var t,e,s,i;this.config.cssUniformScale?O.utils.setCSSscale(this.canvas,null!==(t=this.config.cssScaleX)&&void 0!==t?t:1,null!==(e=this.config.cssScaleX)&&void 0!==e?e:1):O.utils.setCSSscale(this.canvas,null!==(s=this.config.cssScaleX)&&void 0!==s?s:1,null!==(i=this.config.cssScaleY)&&void 0!==i?i:1)}add(t,e){if(Array.isArray(t)){const e=t;for(var s=0;s<e.length;s++)this.add(e[s],!1)}else if(t instanceof i)this.drawables.push(t),this.vertices.push(t);else if(t instanceof n)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b);else if(t instanceof o)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b);else if(t instanceof L)this.vertices.push(t.center),this.vertices.push(t.axis),this.drawables.push(t),t.center.listeners.addDragListener((e=>{t.axis.add(e.params.dragAmount)}));else if(t instanceof E)this.vertices.push(t.ellipse.center),this.vertices.push(t.ellipse.axis),this.drawables.push(t),t.ellipse.center.listeners.addDragListener((e=>{t.ellipse.axis.add(e.params.dragAmount)}));else if(t instanceof d)this.vertices.push(t.center),this.drawables.push(t);else if(t instanceof u)this.vertices.push(t.circle.center),this.drawables.push(t);else if(t instanceof a){this.drawables.push(t);for(s=0;s<t.vertices.length;s++)this.vertices.push(t.vertices[s])}else if(t instanceof p)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b),this.vertices.push(t.c);else if(t instanceof c){this.drawables.push(t);const e=t;for(s=0;s<e.bezierCurves.length;s++)t.adjustCircular||0!=s||this.vertices.push(e.bezierCurves[s].startPoint),this.vertices.push(e.bezierCurves[s].endPoint),this.vertices.push(e.bezierCurves[s].startControlPoint),this.vertices.push(e.bezierCurves[s].endControlPoint),e.bezierCurves[s].startControlPoint.attr.selectable=!1,e.bezierCurves[s].endControlPoint.attr.selectable=!1;O.utils.enableBezierPathAutoAdjust(t)}else if(t instanceof S)this.vertices.push(t.upperLeft),this.vertices.push(t.lowerRight),this.drawables.push(t),t.upperLeft.listeners.addDragListener((e=>{t.lowerRight.add(e.params.dragAmount)})),t.lowerRight.attr.selectable=!1;else{if(!(t instanceof T))throw"Cannot add drawable of unrecognized type: "+typeof t+".";this.vertices.push(t.anchor),this.drawables.push(t),t.anchor.attr.selectable=!1}(e||void 0===e)&&this.redraw()}remove(t,e,s){if(Array.isArray(t)){for(var r=0;r<t.length;r++)this.remove(t[r],!1,s);e&&this.redraw()}else{t instanceof i&&(this.removeVertex(t,!1),e&&this.redraw());for(r=0;r<this.drawables.length;r++)if(this.drawables[r]===t||this.drawables[r].uid===t.uid){if(this.drawables.splice(r,1),s)if(t instanceof n)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1);else if(t instanceof o)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1);else if(t instanceof L)this.removeVertex(t.center,!1),this.removeVertex(t.axis,!1);else if(t instanceof E)this.removeVertex(t.ellipse.center),this.removeVertex(t.ellipse.axis);else if(t instanceof d)this.removeVertex(t.center,!1);else if(t instanceof u)this.removeVertex(t.circle.center,!1);else if(t instanceof a)for(r=0;r<t.vertices.length;r++)this.removeVertex(t.vertices[r],!1);else if(t instanceof p)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1),this.removeVertex(t.c,!1);else if(t instanceof c)for(r=0;r<t.bezierCurves.length;r++)this.removeVertex(t.bezierCurves[r].startPoint,!1),this.removeVertex(t.bezierCurves[r].startControlPoint,!1),this.removeVertex(t.bezierCurves[r].endControlPoint,!1),r+1==t.bezierCurves.length&&this.removeVertex(t.bezierCurves[r].endPoint,!1);else t instanceof S?(this.removeVertex(t.upperLeft,!1),this.removeVertex(t.lowerRight,!1)):t instanceof T&&this.removeVertex(t.anchor,!1);e&&this.redraw()}}}removeVertex(t,e){for(var s=0;s<this.vertices.length;s++)if(this.vertices[s]===t)return this.vertices.splice(s,1),void(e&&this.redraw())}removeAll(t){this.drawables=[],Boolean(t)||(this.vertices=[]),this.redraw()}getVertexNear(t,e){var s,i;const r=this.locatePointNear(this.transformMousePosition(t.x,t.y),e/Math.min(null!==(s=this.config.cssScaleX)&&void 0!==s?s:1,null!==(i=this.config.cssScaleY)&&void 0!==i?i:1));if(r&&"vertex"==r.typeName)return this.vertices[r.vindex]}drawGrid(t){void 0===t&&(t=this.draw);const e=b.utils.mapRasterScale(this.config.rasterAdjustFactor,this.draw.scale.x)*this.config.rasterScaleX/this.config.cssScaleX,s=b.utils.mapRasterScale(this.config.rasterAdjustFactor,this.draw.scale.y)*this.config.rasterScaleY/this.config.cssScaleY;var i={width:this.grid.size.x*e,height:this.grid.size.y*s},r=this.canvasSize.width/2,n=this.canvasSize.height/2,a=this.draw.offset.clone().inv();a.x=Math.round(a.x+r)/Math.round(i.width)*i.width/this.draw.scale.x+(this.draw.offset.x-r)/this.draw.scale.x%i.width,a.y=Math.round(a.y+n)/Math.round(i.height)*i.height/this.draw.scale.y+(this.draw.offset.y-n)/this.draw.scale.x%i.height,this.drawConfig.drawGrid&&(t.setCurrentClassName(null),this.config.rasterGrid?(t.setCurrentId("raster"),t.raster(a,this.canvasSize.width/this.draw.scale.x,this.canvasSize.height/this.draw.scale.y,i.width,i.height,"rgba(0,128,255,0.125)")):(t.setCurrentId("grid"),t.grid(a,this.canvasSize.width/this.draw.scale.x,this.canvasSize.height/this.draw.scale.y,i.width,i.height,"rgba(0,128,255,0.095)")))}drawOrigin(t){t.setCurrentId("origin"),t.crosshair({x:0,y:0},10,this.drawConfig.origin.color)}_handleColor(t,e){return t.attr.isSelected?this.drawConfig.selectedVertex.color:t.attr.draggable?e:"rgba(128,128,128,0.5)"}drawDrawables(t,e,s){for(var i in this.drawables){var r=this.drawables[i];this.draw.setCurrentId(r.uid),this.fill.setCurrentId(r.uid),this.draw.setCurrentClassName(r.className),this.fill.setCurrentClassName(r.className),this.drawDrawable(r,t,e,s)}}drawDrawable(t,e,s,r){if(t instanceof c){var h=0;for(var l in t.bezierCurves){if(this.draw.setCurrentId(`${t.uid}-${h}`),this.fill.setCurrentId(`${t.uid}-${h}`),this.draw.setCurrentClassName(t.className),this.fill.setCurrentClassName(t.className),s.cubicBezier(t.bezierCurves[l].startPoint,t.bezierCurves[l].endPoint,t.bezierCurves[l].startControlPoint,t.bezierCurves[l].endControlPoint,this.drawConfig.bezier.color,this.drawConfig.bezier.lineWidth),this.drawConfig.drawBezierHandlePoints&&this.drawConfig.drawHandlePoints){if(t.bezierCurves[l].startPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?r:s;e.setCurrentId(`${t.uid}_h0`),e.setCurrentClassName(`${t.className}-start-handle`),t.bezierCurves[l].startPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[l].startPoint,5,this._handleColor(t.bezierCurves[l].startPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[l].startPoint,7,this._handleColor(t.bezierCurves[l].startPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[l].startPoint.attr.renderTime=e,t.bezierCurves[l].endPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?r:s;e.setCurrentId(`${t.uid}_h0`),e.setCurrentClassName(`${t.className}-start-handle`),t.bezierCurves[l].endPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[l].endPoint,5,this._handleColor(t.bezierCurves[l].endPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[l].endPoint,7,this._handleColor(t.bezierCurves[l].endPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[l].startControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?r:s;e.setCurrentId(`${t.uid}_h2`),e.setCurrentClassName(`${t.className}-start-control-handle`),e.circleHandle(t.bezierCurves[l].startControlPoint,3,this._handleColor(t.bezierCurves[l].startControlPoint,this.drawConfig.bezier.controlVertex.color))}if(t.bezierCurves[l].endControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?r:s;e.setCurrentId(`${t.uid}_h3`),e.setCurrentClassName(`${t.className}-end-control-handle`),e.circleHandle(t.bezierCurves[l].endControlPoint,3,this._handleColor(t.bezierCurves[l].endControlPoint,this.drawConfig.bezier.controlVertex.color))}t.bezierCurves[l].startPoint.attr.renderTime=e,t.bezierCurves[l].endPoint.attr.renderTime=e,t.bezierCurves[l].startControlPoint.attr.renderTime=e,t.bezierCurves[l].endControlPoint.attr.renderTime=e}else t.bezierCurves[l].startPoint.attr.renderTime=e,t.bezierCurves[l].endPoint.attr.renderTime=e,t.bezierCurves[l].startControlPoint.attr.renderTime=e,t.bezierCurves[l].endControlPoint.attr.renderTime=e;this.drawConfig.drawBezierHandleLines&&this.drawConfig.drawHandleLines&&(s.setCurrentId(`${t.uid}_l0`),s.setCurrentClassName(`${t.className}-start-line`),s.handleLine(t.bezierCurves[l].startPoint,t.bezierCurves[l].startControlPoint),s.setCurrentId(`${t.uid}_l1`),s.setCurrentClassName(`${t.className}-end-line`),s.handleLine(t.bezierCurves[l].endPoint,t.bezierCurves[l].endControlPoint)),h++}}else if(t instanceof a){if(s.polygon(t,this.drawConfig.polygon.color,this.drawConfig.polygon.lineWidth),!this.drawConfig.drawHandlePoints)for(var g in t.vertices)t.vertices[g].attr.renderTime=e}else if(t instanceof p)s.polyline([t.a,t.b,t.c],!1,this.drawConfig.triangle.color,this.drawConfig.triangle.lineWidth),this.drawConfig.drawHandlePoints||(t.a.attr.renderTime=t.b.attr.renderTime=t.c.attr.renderTime=e);else if(t instanceof L)this.drawConfig.drawHandleLines&&(s.setCurrentId(`${t.uid}_e0`),s.setCurrentClassName(`${t.className}-v-line`),s.handleLine(t.center.clone().add(0,t.signedRadiusV()).rotate(t.rotation,t.center),t.axis),s.setCurrentId(`${t.uid}_e1`),s.setCurrentClassName(`${t.className}-h-line`),s.handleLine(t.center.clone().add(t.signedRadiusH(),0).rotate(t.rotation,t.center),t.axis)),s.setCurrentId(t.uid),s.setCurrentClassName(`${t.className}`),s.ellipse(t.center,t.radiusH(),t.radiusV(),this.drawConfig.ellipse.color,this.drawConfig.ellipse.lineWidth,t.rotation),this.drawConfig.drawHandlePoints||(t.center.attr.renderTime=e,t.axis.attr.renderTime=e);else if(t instanceof E){s.setCurrentId(t.uid),s.setCurrentClassName(`${t.className}`);const e=E.ellipseSectorUtils.describeSVGArc(t.ellipse.center.x,t.ellipse.center.y,t.ellipse.radiusH(),t.ellipse.radiusV(),t.startAngle,t.endAngle,t.ellipse.rotation,{moveToStart:!0});s.path(e,this.drawConfig.ellipseSector.color,this.drawConfig.ellipseSector.lineWidth)}else t instanceof d?s.circle(t.center,t.radius,this.drawConfig.circle.color,this.drawConfig.circle.lineWidth):t instanceof u?s.circleArc(t.circle.center,t.circle.radius,t.startAngle,t.endAngle,this.drawConfig.circleSector.color,this.drawConfig.circleSector.lineWidth):t instanceof i?!this.drawConfig.drawVertices||t.attr.selectable&&t.attr.draggable||!t.attr.visible||(s.circleHandle(t,7,this.drawConfig.vertex.color),t.attr.renderTime=e):t instanceof n?(s.line(t.a,t.b,this.drawConfig.line.color,this.drawConfig.line.lineWidth),this.drawConfig.drawHandlePoints&&t.a.attr.selectable||(t.a.attr.renderTime=e),this.drawConfig.drawHandlePoints&&t.b.attr.selectable||(t.b.attr.renderTime=e)):t instanceof o?(s.arrow(t.a,t.b,this.drawConfig.vector.color),this.drawConfig.drawHandlePoints&&t.b.attr.selectable&&t.b.attr.visible?(s.setCurrentId(`${t.uid}_h0`),s.setCurrentClassName(`${t.className}-handle`),s.circleHandle(t.b,3,"#a8a8a8")):t.b.attr.renderTime=e,this.drawConfig.drawHandlePoints&&t.a.attr.selectable||(t.a.attr.renderTime=e),this.drawConfig.drawHandlePoints&&t.b.attr.selectable||(t.b.attr.renderTime=e)):t instanceof S?(this.drawConfig.drawHandleLines&&(s.setCurrentId(`${t.uid}_l0`),s.setCurrentClassName(`${t.className}-line`),s.line(t.upperLeft,t.lowerRight,this.drawConfig.image.color,this.drawConfig.image.lineWidth)),r.setCurrentId(t.uid),r.image(t.image,t.upperLeft,t.lowerRight.clone().sub(t.upperLeft)),this.drawConfig.drawHandlePoints&&(s.setCurrentId(`${t.uid}_h0`),s.setCurrentClassName(`${t.className}-lower-right`),s.circleHandle(t.lowerRight,3,this.drawConfig.image.color),t.lowerRight.attr.renderTime=e)):t instanceof T?(r.setCurrentId(t.uid),r.text(t.text,t.anchor.x,t.anchor.y,t),this.drawConfig.text.anchor&&(s.setCurrentId(`${t.uid}_a0`),s.setCurrentClassName(`${t.className}-anchor`),(this.drawConfig.text.fill?r:s).point(t.anchor,this.drawConfig.text.color)),t.anchor.attr.renderTime=e):console.error("Cannot draw object. Unknown class.");s.setCurrentClassName(null),s.setCurrentId(null),r.setCurrentClassName(null),r.setCurrentId(null)}drawSelectPolygon(t){null!=this.selectPolygon&&this.selectPolygon.vertices.length>0&&(t.setCurrentId(this.selectPolygon.uid),t.polygon(this.selectPolygon,"#888888"),t.crosshair(this.selectPolygon.vertices[0],3,"#008888"))}drawVertices(t,e){for(var s in this.vertices)this.drawConfig.drawVertices&&this.vertices[s].attr.renderTime!=t&&this.vertices[s].attr.visible&&(e.setCurrentId(this.vertices[s].uid),e.squareHandle(this.vertices[s],5,this._handleColor(this.vertices[s],"rgb(0,128,192)")),this.vertices[s].attr.renderTime=t)}redraw(){const t=this.renderTime++;this.draw.beginDrawCycle(t),this.fill.beginDrawCycle(t),this.config.preClear&&this.config.preClear(),this.clear(),this.config.preDraw&&this.config.preDraw(this.draw,this.fill),this.drawAll(t,this.draw,this.fill),this.config.postDraw&&this.config.postDraw(this.draw,this.fill),this.draw.endDrawCycle(t),this.fill.endDrawCycle(t)}drawAll(t,e,s){this.config.drawRaster&&this.drawGrid(e),this.config.drawOrigin&&this.drawOrigin(e),this.drawDrawables(t,e,s),this.drawVertices(t,e),this.drawSelectPolygon(e),e.setCurrentId(null),e.setCurrentClassName(null)}clear(){this.draw.clear(this.config.backgroundColor||"white")}clearSelection(t){for(var e in this.vertices)this.vertices[e].attr.isSelected=!1;return t&&this.redraw(),this}viewport(){var t,e;return new h(this.transformMousePosition(0,0),this.transformMousePosition(this.canvasSize.width*(null!==(t=this.config.cssScaleX)&&void 0!==t?t:1),this.canvasSize.height*(null!==(e=this.config.cssScaleY)&&void 0!==e?e:1)))}saveFile(){this.hooks.saveFile(this)}getFProp(t,e){return parseFloat(globalThis.getComputedStyle(t,null).getPropertyValue(e))}getAvailableContainerSpace(){const t=this,e=t.canvas.parentNode;t.canvas.style.display="none";var s=this.getFProp(e,"padding")||0,i=this.getFProp(t.canvas,"border-width")||0,r=this.getFProp(e,"padding-left")||s,n=this.getFProp(e,"padding-right")||s,a=this.getFProp(e,"padding-top")||s,h=this.getFProp(e,"padding-bottom")||s,o=this.getFProp(t.canvas,"border-left-width")||i,l=this.getFProp(t.canvas,"border-right-width")||i,c=this.getFProp(t.canvas,"border-top-width")||i,d=this.getFProp(t.canvas,"border-bottom-width")||i,u=e.clientWidth,g=e.clientHeight;return t.canvas.style.display="block",{width:u-r-n-o-l,height:g-a-h-c-d}}resizeCanvas(){var t,e,s,i,r,n;const a=this,h=(t,e)=>{var s,i;t*=null!==(s=a.config.canvasWidthFactor)&&void 0!==s?s:1,e*=null!==(i=a.config.canvasHeightFactor)&&void 0!==i?i:1,a.canvasSize.width=t,a.canvasSize.height=e,a.canvas instanceof HTMLCanvasElement?(a.canvas.width=t,a.canvas.height=e):a.canvas instanceof SVGElement?(this.canvas.setAttribute("viewBox",`0 0 ${t} ${e}`),this.canvas.setAttribute("width",`${t}`),this.canvas.setAttribute("height",`${e}`),this.draw.setSize(a.canvasSize),this.eventCatcher.style.width=`${t}px`,this.eventCatcher.style.height=`${e}px`):console.error("Error: cannot resize canvas element because it seems neither be a HTMLCanvasElement nor an SVGElement."),a.config.autoAdjustOffset&&a.adjustOffset(!1)};if(a.config.fullSize&&!a.config.fitToParent){var o=globalThis.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,l=globalThis.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;a.canvas.style.position="absolute",a.canvas.style.width=(null!==(t=a.config.canvasWidthFactor)&&void 0!==t?t:1)*o+"px",a.canvas.style.height=(null!==(e=a.config.canvasWidthFactor)&&void 0!==e?e:1)*l+"px",a.canvas.style.top="0px",a.canvas.style.left="0px",h(o,l)}else if(a.config.fitToParent){a.canvas.style.position="static";const t=this.getAvailableContainerSpace();a.canvas.style.width=(null!==(s=a.config.canvasWidthFactor)&&void 0!==s?s:1)*t.width+"px",a.canvas.style.height=(null!==(i=a.config.canvasHeightFactor)&&void 0!==i?i:1)*t.height+"px",a.canvas.style.top="",a.canvas.style.left="",h(t.width,t.height)}else a.canvas.style.width="",a.canvas.style.height="",h(null!==(r=a.config.defaultCanvasWidth)&&void 0!==r?r:1024,null!==(n=a.config.defaultCanvasHeight)&&void 0!==n?n:768);a.config.redrawOnResize&&a.redraw()}selectVerticesInPolygon(t){for(var e in this.vertices)this.vertices[e].attr.selectable&&t.containsVert(this.vertices[e])&&(this.vertices[e].attr.isSelected=!0)}locatePointNear(t,e){const s=this;void 0===e&&(e=7),e/=s.draw.scale.x;for(var i=0;i<s.vertices.length;i++){var r=s.vertices[i];if((r.attr.draggable||r.attr.selectable)&&r.distance(t)<e)return new O.Draggable(r,O.Draggable.VERTEX).setVIndex(i)}return null}handleClick(t){const e=this;var s=this.locatePointNear(e.transformMousePosition(t.params.pos.x,t.params.pos.y),O.DEFAULT_CLICK_TOLERANCE/Math.min(e.config.cssScaleX||1,e.config.cssScaleY||1));if(s)if(e.vertices[s.vindex].listeners.fireClickEvent(t),this.keyHandler&&this.keyHandler.isDown("shift")){if("bpath"==s.typeName){let t=e.paths[s.pindex].bezierCurves[s.cindex].getPointByID(s.pid);t.attr.selectable&&(t.attr.isSelected=!t.attr.isSelected)}else if("vertex"==s.typeName){let t=e.vertices[s.vindex];t.attr.selectable&&(t.attr.isSelected=!t.attr.isSelected)}e.redraw()}else this.keyHandler&&this.keyHandler.isDown("y")&&(e.vertices[s.vindex].attr.bezierAutoAdjust=!e.vertices[s.vindex].attr.bezierAutoAdjust,e.redraw());else if(null!=e.selectPolygon){const s=e.transformMousePosition(t.params.pos.x,t.params.pos.y);e.selectPolygon.vertices.push(new i(s.x,s.y)),e.redraw()}}transformMousePosition(t,e){return{x:(t/this.config.cssScaleX-this.config.offsetX)/this.config.scaleX,y:(e/this.config.cssScaleY-this.config.offsetY)/this.config.scaleY}}revertMousePosition(t,e){return{x:t/this.config.cssScaleX+this.config.offsetX,y:e/this.config.cssScaleY+this.config.offsetY}}getDraggedElementCount(){return this.draggedElements.length}mouseDownHandler(t){const e=this;if(0==t.button){var s=e.locatePointNear(e.transformMousePosition(t.params.pos.x,t.params.pos.y),O.DEFAULT_CLICK_TOLERANCE/Math.min(e.config.cssScaleX,e.config.cssScaleY));if(s){if("vertex"==s.typeName&&e.vertices[s.vindex].attr.isSelected)for(var i=0;i<e.vertices.length;i++)e.vertices[i].attr.isSelected&&(e.draggedElements.push(new O.Draggable(e.vertices[i],O.Draggable.VERTEX).setVIndex(i)),e.vertices[i].listeners.fireDragStartEvent(t));else{if(!e.vertices[s.vindex].attr.draggable)return;e.draggedElements.push(s),"bpath"==s.typeName?e.paths[s.pindex].bezierCurves[s.cindex].getPointByID(s.pid).listeners.fireDragStartEvent(t):"vertex"==s.typeName&&e.vertices[s.vindex].listeners.fireDragStartEvent(t)}e.redraw()}}}mouseDragHandler(t){const e=this,s={x:t.params.dragAmount.x,y:t.params.dragAmount.y};if(t.params.dragAmount.x/=e.config.cssScaleX,t.params.dragAmount.y/=e.config.cssScaleY,this.keyHandler&&(this.keyHandler.isDown("alt")||this.keyHandler.isDown("spacebar"))){if(!this.config.enablePan)return;e.setOffset(e.draw.offset.clone().add(t.params.dragAmount)),e.redraw()}else for(var r in t.params.dragAmount.x/=e.draw.scale.x,t.params.dragAmount.y/=e.draw.scale.y,e.draggedElements){var n=e.draggedElements[r];if("bpath"==n.typeName)e.paths[n.pindex].moveCurvePoint(n.cindex,n.pid,new i(t.params.dragAmount.x,t.params.dragAmount.y)),e.paths[n.pindex].bezierCurves[n.cindex].getPointByID(n.pid).listeners.fireDragEvent(t);else if("vertex"==n.typeName){if(!e.vertices[n.vindex].attr.draggable)continue;e.vertices[n.vindex].add(t.params.dragAmount),e.vertices[n.vindex].listeners.fireDragEvent(t)}}t.params.dragAmount.x=s.x,t.params.dragAmount.y=s.y,e.redraw()}mouseUpHandler(t){const e=this;if(0==t.button){for(var s in t.params.wasDragged||e.handleClick(t),e.draggedElements){var i=e.draggedElements[s];"bpath"==i.typeName?e.paths[i.pindex].bezierCurves[i.cindex].getPointByID(i.pid).listeners.fireDragEndEvent(t):"vertex"==i.typeName&&e.vertices[i.vindex].listeners.fireDragEndEvent(t)}e.draggedElements=[],e.redraw()}}mouseWheelHandler(t){if(!this.config.enableZoom)return;var e=1.25;const s=this,r=t;r.deltaY<0?s.setZoom(s.config.scaleX*e,s.config.scaleY*e,new i(t.params.pos.x,t.params.pos.y)):r.deltaY>0&&s.setZoom(s.config.scaleX/e,s.config.scaleY/e,new i(t.params.pos.x,t.params.pos.y)),t.preventDefault(),s.redraw()}adjustOffset(t){this.draw.offset.x=this.fill.offset.x=this.config.offsetX=this.canvasSize.width*(this.config.offsetAdjustXPercent/100),this.draw.offset.y=this.fill.offset.y=this.config.offsetY=this.canvasSize.height*(this.config.offsetAdjustYPercent/100),t&&this.redraw()}setOffset(t){this.draw.offset.set(t),this.fill.offset.set(t),this.config.offsetX=t.x,this.config.offsetY=t.y}setZoom(t,e,s){let i=this.transformMousePosition(s.x,s.y);this.draw.scale.x=this.fill.scale.x=this.config.scaleX=Math.max(t,.01),this.draw.scale.y=this.fill.scale.y=this.config.scaleY=Math.max(e,.01);let r=this.transformMousePosition(s.x,s.y),n=this.draw.offset.x+(r.x-i.x)*this.draw.scale.x,a=this.draw.offset.y+(r.y-i.y)*this.draw.scale.y;this.setOffset({x:n,y:a})}installInputListeners(){var t=this;if(this.config.enableMouse?new A(this.eventCatcher?this.eventCatcher:this.canvas).down((e=>{t.mouseDownHandler(e)})).drag((e=>{t.mouseDragHandler(e)})).up((e=>{t.mouseUpHandler(e)})):t.console.log("Mouse interaction disabled."),this.config.enableMouseWheel?new A(this.eventCatcher?this.eventCatcher:this.canvas).wheel((e=>{t.mouseWheelHandler(e)})):t.console.log("Mouse wheel interaction disabled."),this.config.enableTouch){const a=e=>{const s=t.canvas.getBoundingClientRect();return{x:e.x-s.left,y:e.y-s.top}};if("function"==typeof globalThis.AlloyFinger||"function"==typeof globalThis.createAlloyFinger)try{var e=null,s=null,r=null,h=null;const o=()=>{e=null,s=null,r=null,h=null,t.draggedElements=[]},l={touchStart:n=>{if(1==n.touches.length&&(e=new i(a({x:n.touches[0].clientX,y:n.touches[0].clientY})),s=new i(a({x:n.touches[0].clientX,y:n.touches[0].clientY})),(r=t.locatePointNear(t.transformMousePosition(e.x,e.y),O.DEFAULT_TOUCH_TOLERANCE/Math.min(t.config.cssScaleX,t.config.cssScaleY)))&&"vertex"==r.typeName)){var h=t.vertices[r.vindex],o={params:{isTouchEvent:!0,dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:h}};t.draggedElements=[r],h.listeners.fireDragStartEvent(o)}},touchMove:n=>{if(1==n.touches.length&&r){if(n.preventDefault(),n.stopPropagation(),!s||!e)return;var h=a({x:n.touches[0].clientX,y:n.touches[0].clientY}),o=t.transformMousePosition(h.x,h.y),l=new i(t.transformMousePosition(e.x,e.y)).difference(o);if("vertex"==r.typeName){if(!t.vertices[r.vindex].attr.draggable)return;t.vertices[r.vindex].add(l);var c=t.vertices[r.vindex],d={isTouchEvent:!0,params:{dragAmount:l.clone(),wasDragged:!0,mouseDownPos:s.clone(),mouseDragPos:s.clone().add(l),vertex:c}};c.listeners.fireDragEvent(d),t.redraw()}e=new i(h)}else if(2==n.touches.length){if(!this.config.enablePan)return;n.preventDefault(),n.stopPropagation(),t.setOffset(t.draw.offset.clone().addXY(n.deltaX,n.deltaY)),t.redraw()}},touchEnd:i=>{if(r&&"vertex"==r.typeName){if(!s)return;var n=t.vertices[r.vindex],a={isTouchEvent:!0,params:{dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:n}};e&&s&&s.distance(e)<.001?n.listeners.fireClickEvent(a):n.listeners.fireDragEndEvent(a)}o()},touchCancel:t=>{o()},multipointStart:e=>{h=t.draw.scale.clone()},multipointEnd:t=>{h=null},pinch:e=>{if(!this.config.enableZoom)return;const s=e.touches.item(0),r=e.touches.item(1);if(!(e.touches&&h&&s&&r))return;const a=new i(s.clientX,s.clientY),o=new i(r.clientX,r.clientY),l=new n(a,o).vertAt(.5);t.setZoom(h.x*e.zoom,h.y*e.zoom,l),t.redraw()}};if(window.createAlloyFinger){(0,window.createAlloyFinger)(this.eventCatcher?this.eventCatcher:this.canvas,l)}else new M(this.eventCatcher?this.eventCatcher:this.canvas,l)}catch(t){console.error("Failed to initialize AlloyFinger!"),console.error(t)}else globalThis.Touchy&&"function"==typeof globalThis.Touchy?console.error("[Deprecation] Found Touchy which is not supported any more. Please use AlloyFinger instead."):console.warn("Cannot initialize the touch handler. AlloyFinger is missig. Did you include it?")}else t.console.log("Touch interaction disabled.");this.config.enableKeys?this.keyHandler=new w({trackAll:!0}).down("escape",(function(){t.clearSelection(!0)})).down("shift",(function(){t.selectPolygon=new a,t.redraw()})).up("shift",(function(){null!=t.selectPolygon&&(t.selectVerticesInPolygon(t.selectPolygon),t.selectPolygon=null,t.redraw())})):t.console.log("Keyboard interaction disabled.")}createGUI(t){const e=globalThis.utils;if(e&&"function"==typeof e.createGUI)return this._gui=e.createGUI(this,t);throw"Cannot create dat.GUI or lil-gui instance; did you load the ./utils/creategui helper function an the dat.GUI/lil-gui library?"}getGUI(){return this._gui}}O.DEFAULT_CANVAS_WIDTH=1024,O.DEFAULT_CANVAS_HEIGHT=768,O.DEFAULT_CLICK_TOLERANCE=8,O.DEFAULT_TOUCH_TOLERANCE=32,O.Draggable=(k(I=class{constructor(t,e){this.item=t,this.typeName=e}isVertex(){return this.typeName==O.Draggable.VERTEX}setVIndex(t){return this.vindex=t,this}},"Draggable"),I.VERTEX="vertex",I),O.utils={safeMergeByKeys:(t,e)=>{for(var s in e)if(e.hasOwnProperty(s))if(t.hasOwnProperty(s)){const i=typeof t[s],r=e[s];try{t[s]="boolean"==i?"string"==typeof r?Boolean(!!JSON.parse(r)):r:"number"==i&&"string"==typeof r?Number(1*JSON.parse(r)):e[s]}catch(t){console.error("error in key ",s,r,t)}}else t[s]=e[s];return t},setCSSscale:(t,e,s)=>{t.style.transformOrigin="0 0",1==e&&1==s?t.style.removeProperty("transform"):t.style.transform="scale("+e+","+s+")"},fetch:{val:(t,e,s)=>t.hasOwnProperty(e)?void 0===t[e]?s:t[e]:s,num:(t,e,s)=>{if(!t.hasOwnProperty(e))return s;if("number"==typeof t[e])return t[e];try{return 1*JSON.parse(t[e])}catch(t){return s}},bool:(t,e,s)=>{if(!t.hasOwnProperty(e))return s;if("boolean"==typeof t[e])return t[e];try{return!!JSON.parse(t[e])}catch(t){return s}},func:(t,e,s)=>t.hasOwnProperty(e)?"function"!=typeof t[e]?s:t[e]:s},enableBezierPathAutoAdjust:t=>{for(var e=0;e<t.bezierCurves.length;e++)t.bezierCurves[e].startPoint.listeners.addDragListener((function(e){var s=t.locateCurveByStartPoint(e.params.vertex);t.bezierCurves[s].startPoint.addXY(-e.params.dragAmount.x,-e.params.dragAmount.y),t.moveCurvePoint(1*s,t.START_POINT,e.params.dragAmount),t.updateArcLengths()})),t.bezierCurves[e].startControlPoint.listeners.addDragListener((function(e){var s=t.locateCurveByStartControlPoint(e.params.vertex);t.bezierCurves[s].startPoint.attr.bezierAutoAdjust&&(t.adjustPredecessorControlPoint(1*s,!0,!1),t.updateArcLengths())})),t.bezierCurves[e].endControlPoint.listeners.addDragListener((function(e){var s=t.locateCurveByEndControlPoint(e.params.vertex);t.bezierCurves[s%t.bezierCurves.length].endPoint.attr.bezierAutoAdjust&&(t.adjustSuccessorControlPoint(1*s,!0,!1),t.updateArcLengths())})),e+1==t.bezierCurves.length&&t.bezierCurves[t.bezierCurves.length-1].endPoint.listeners.addDragListener((function(e){if(!t.adjustCircular){var s=t.locateCurveByEndPoint(e.params.vertex);t.moveCurvePoint(1*s,t.END_CONTROL_POINT,new i({x:e.params.dragAmount.x,y:e.params.dragAmount.y}))}t.updateArcLengths()}))}},exports.BezierPath=c,exports.Bounds=h,exports.Circle=d,exports.CircleSector=u,exports.CubicBezierCurve=l,exports.Grid=b,exports.KeyHandler=w,exports.Line=n,exports.MouseHandler=A,exports.PBImage=S,exports.PBText=T,exports.PlotBoilerplate=O,exports.Polygon=a,exports.Triangle=p,exports.UIDGenerator=e,exports.VEllipse=L,exports.VEllipseSector=E,exports.Vector=o,exports.VertTuple=r,exports.Vertex=i,exports.VertexAttr=t,exports.VertexListeners=s,exports.XMouseEvent=C,exports.XWheelEvent=P,exports.drawutils=x,exports.drawutilsgl=v,exports.drawutilssvg=f,exports.geomutils=m;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{constructor(){for(var e in this.draggable=!0,this.selectable=!0,this.isSelected=!1,this.visible=!0,t.model)this[e]=t.model[e]}}t.model={draggable:!0,selectable:!0,isSelected:!1,visible:!0};class e{static next(){return""+e.current++}}e.current=0;class s{constructor(t){this.click=[],this.drag=[],this.dragStart=[],this.dragEnd=[],this.vertex=t}addClickListener(t){return s._addListener(this.click,t),this}removeClickListener(t){return this.click=s._removeListener(this.click,t),this}addDragListener(t){return s._addListener(this.drag,t),this}removeDragListener(t){return this.drag=s._removeListener(this.drag,t),this}addDragStartListener(t){return s._addListener(this.dragStart,t),this}removeDragStartListener(t){return this.dragStart=s._removeListener(this.dragStart,t),this}addDragEndListener(t){return s._addListener(this.dragEnd,t),this}removeDragEndListener(t){return this.dragEnd=s._removeListener(this.dragEnd,t),this}fireClickEvent(t){s._fireEvent(this,this.click,t)}fireDragEvent(t){s._fireEvent(this,this.drag,t)}fireDragStartEvent(t){s._fireEvent(this,this.dragStart,t)}fireDragEndEvent(t){s._fireEvent(this,this.dragEnd,t)}removeAllListeners(){this.click=[],this.drag=[],this.dragStart=[],this.dragEnd=[]}static _fireEvent(t,e,s){const i=s;for(var r in void 0===i.params?i.params={vertex:t.vertex}:i.params.vertex=t.vertex,e)e[r](i)}static _addListener(t,e){for(var s in t)if(t[s]==e)return!1;return t.push(e),!0}static _removeListener(t,e){for(var s=0;s<t.length;s++)if(t[s]==e)return t.splice(s,1);return t}}class i extends o{constructor(t,e){super(t,e,((t,e)=>new i(t,e))),this.className="Vector"}perp(){var t=this.clone();return t.sub(this.a),(t=new i(new h,new h(-t.b.y,t.b.x))).a.add(this.a),t.b.add(this.a),t}inverse(){var t=this.a;return this.a=this.b,this.b=t,this}inv(){return this.b.x=this.a.x-(this.b.x-this.a.x),this.b.y=this.a.y-(this.b.y-this.a.y),this}intersection(t){var e=this.denominator(t);if(0==e)return null;var s=this.a.y-t.a.y,i=this.a.x-t.a.x,r=(t.b.x-t.a.x)*s-(t.b.y-t.a.y)*i,n=(this.b.x-this.a.x)*s-(this.b.y-this.a.y)*i;return s=r/e,i=n/e,new h(this.a.x+s*(this.b.x-this.a.x),this.a.y+s*(this.b.y-this.a.y))}getOrthogonal(){const t=this.a.clone(),e=this.b.clone().sub(this.a),s=e.x;return e.x=-e.y,e.y=s,new i(t,e.add(this.a))}}i.utils={buildArrowHead:(t,e,s,i,r)=>{const n=Math.atan2((e.y-t.y)*r,(e.x-t.x)*i),a=[];return a.push(new h(e.x*i-s*Math.cos(n),e.y*r-s*Math.sin(n))),a.push(new h(e.x*i-1.35*s*Math.cos(n-Math.PI/8),e.y*r-1.35*s*Math.sin(n-Math.PI/8))),a.push(new h(e.x*i,e.y*r)),a.push(new h(e.x*i-1.35*s*Math.cos(n+Math.PI/8),e.y*r-1.35*s*Math.sin(n+Math.PI/8))),a}};class r{constructor(t,s){this.className="Circle",this.uid=e.next(),this.center=t,this.radius=s}containsPoint(t){return this.center.distance(t)<this.radius}containsCircle(t){return this.center.distance(t.center)+t.radius<this.radius}lineDistance(t){return t.getClosestPoint(this.center).distance(this.center)-this.radius}vertAt(t){return r.circleUtils.vertAt(t,this.radius).add(this.center)}tangentAt(t){const e=r.circleUtils.vertAt(t,this.radius);return new i(e,new h(0,0)).add(this.center).perp()}circleIntersection(t){if(this.center.distance(t.center)>this.radius+t.radius)return null;if(this.center.distance(t.center)<Math.abs(this.radius-t.radius))return null;var e=this.center,s=t.center,i=e.distance(s),r=(this.radius*this.radius-t.radius*t.radius+i*i)/(2*i),n=Math.sqrt(this.radius*this.radius-r*r),a=s.clone().scale(r/i,e),o=a.x+n*(s.y-e.y)/i,c=a.y-n*(s.x-e.x)/i,d=a.x-n*(s.y-e.y)/i,u=a.y+n*(s.x-e.x)/i;return new l(new h(o,c),new h(d,u))}lineIntersection(t,e){const s=new h,i=new h,r=new h(t).sub(this.center),n=new h(e).sub(this.center),a=r.difference(n);0===Math.abs(a.y)&&(a.y=1e-6);const o=r.distance(n),c=r.x*n.y-r.y*n.x,d=o*o;if(this.radius*this.radius*d-c*c<0)return null;const u=this.radius*this.radius*o*o-c*c,g=Math.sqrt(u);return s.x=(c*a.y+Math.sign(a.y)*a.x*g)/d,i.x=(c*a.y-Math.sign(a.y)*a.x*g)/d,s.y=(-c*a.x+Math.abs(a.y)*g)/d,i.y=(-c*a.x-Math.abs(a.y)*g)/d,new l(s.add(this.center),i.add(this.center))}closestPoint(t){const e=this.lineIntersection(this.center,t);return e?e.a.distance(t)<e.b.distance(t)?e.a:e.b:new h}destroy(){this.center.destroy(),this.isDestroyed=!0}}r.circleUtils={vertAt:(t,e)=>new h(Math.cos(t)*e,Math.sin(t)*e)};class n{constructor(t,s,i){this.className="Triangle",this.uid=e.next(),this.a=t,this.b=s,this.c=i,this.calcCircumcircle()}static fromArray(t){if(t.length<3)throw`Cannot create triangle from array with less than three vertices (${t.length})`;return new n(t[0],t[1],t[2])}getArea(){return Math.abs(n.utils.signedArea(this.a.x,this.a.y,this.b.x,this.b.y,this.c.x,this.c.y))}getCentroid(){return new h((this.a.x+this.b.x+this.c.x)/3,(this.a.y+this.b.y+this.c.y)/3)}scaleToCentroid(t){let e=this.getCentroid();return this.a.scale(t,e),this.b.scale(t,e),this.c.scale(t,e),this}getCircumcircle(){return this.calcCircumcircle(),new r(this.center.clone(),this.radius)}isAdjacent(t){var e=this.a.equals(t.a)||this.a.equals(t.b)||this.a.equals(t.c),s=this.b.equals(t.a)||this.b.equals(t.b)||this.b.equals(t.c),i=this.c.equals(t.a)||this.c.equals(t.b)||this.c.equals(t.c);return e&&s||e&&i||s&&i}getThirdVertex(t,e){return this.a.equals(t)&&this.b.equals(e)||this.a.equals(e)&&this.b.equals(t)?this.c:this.b.equals(t)&&this.c.equals(e)||this.b.equals(e)&&this.c.equals(t)?this.a:this.b}calcCircumcircle(){const t=this.b.x-this.a.x,e=this.b.y-this.a.y,s=this.c.x-this.a.x,i=this.c.y-this.a.y,r=t*(this.a.x+this.b.x)+e*(this.a.y+this.b.y),a=s*(this.a.x+this.c.x)+i*(this.a.y+this.c.y),o=2*(t*(this.c.y-this.b.y)-e*(this.c.x-this.b.x));let l,c;if(Math.abs(o)<n.EPSILON){const t=this.bounds();this.center=new h((t.min.x+t.max.x)/2,(t.min.y+t.max.y)/2),l=this.center.x-t.min.x,c=this.center.y-t.min.y}else{const n=(i*r-e*a)/o,d=(t*a-s*r)/o;this.center=new h(n,d),l=this.center.x-this.a.x,c=this.center.y-this.a.y}this.radius_squared=l*l+c*c,this.radius=Math.sqrt(this.radius_squared)}inCircumcircle(t){const e=this.center.x-t.x,s=this.center.y-t.y;return e*e+s*s<=this.radius_squared}bounds(){return new d(new h(n.utils.min3(this.a.x,this.b.x,this.c.x),n.utils.min3(this.a.y,this.b.y,this.c.y)),new h(n.utils.max3(this.a.x,this.b.x,this.c.x),n.utils.max3(this.a.y,this.b.y,this.c.y)))}toPolygon(){return new c([this.a,this.b,this.c])}determinant(){return n.utils.determinant(this.a,this.b,this.c)}containsPoint(t){return n.utils.pointIsInTriangle(t.x,t.y,this.a.x,this.a.y,this.b.x,this.b.y,this.c.x,this.c.y)}getIncircularTriangle(){const t=new l(this.a,this.b),e=new l(this.b,this.c),s=new l(this.c,this.a),i=a.nsectAngle(this.b,this.a,this.c,2)[0],r=a.nsectAngle(this.c,this.b,this.a,2)[0],h=i.intersection(r),o=t.getClosestPoint(h),c=e.getClosestPoint(h),d=s.getClosestPoint(h);return new n(o,c,d)}getIncircle(){return this.getIncircularTriangle().getCircumcircle()}getIncenter(){return this.center&&this.radius||this.calcCircumcircle(),this.center.clone()}toString(){return"{ a : "+this.a.toString()+", b : "+this.b.toString()+", c : "+this.c.toString()+"}"}destroy(){this.a.destroy(),this.b.destroy(),this.c.destroy(),this.isDestroyed=!0}}n.EPSILON=1e-6,n.utils={max3:(t,e,s)=>t>=e&&t>=s?t:e>=t&&e>=s?e:s,min3:(t,e,s)=>t<=e&&t<=s?t:e<=t&&e<=s?e:s,signedArea:(t,e,s,i,r,n)=>.5*(-i*r+e*(-s+r)+t*(i-n)+s*n),pointIsInTriangle(t,e,s,i,r,a,h,o){var l=n.utils.signedArea(s,i,r,a,h,o),c=1/(2*l)*(i*h-s*o+(o-i)*t+(s-h)*e),d=1/(2*l)*(s*a-i*r+(i-a)*t+(r-s)*e);return c>0&&d>0&&1-c-d>0},determinant:(t,e,s)=>(e.y-t.y)*(s.x-e.x)-(s.y-e.y)*(e.x-t.x)};const a={mapAngleTo2PI(t){const e=Math.asin(Math.sin(t));return Math.cos(t)<0?Math.PI-e:e<0?e+2*Math.PI:e},dist4:(t,e,s,i)=>Math.sqrt(Math.pow(s-t,2)+Math.pow(e-i,2)),dotProduct:(t,e)=>t.x*e.x+t.y*e.y,nsectAngle(t,e,s,i){const r=new n(t,e,s),a=new l(t,e),h=new l(t,s);var o=a.angle(h);const c=r.determinant()>0;o<0&&(o=2*Math.PI+o),c||(o=-1*(2*Math.PI-o));const d=Math.max(a.length(),h.length())/a.length();for(var u=[],g=1;g<i;g++)u.push(new l(t,e.clone().rotate(o/i*-g,t)).scale(d));return u},wrapMax:(t,e)=>(e+t%e)%e,wrapMinMax:(t,e,s)=>e+a.wrapMax(t-e,s-e)};class h{constructor(i,r){if(this.className="Vertex",this.uid=e.next(),void 0===i)this.x=0,this.y=0;else if("number"==typeof i&&"number"==typeof r)this.x=i,this.y=r;else{const t=i;"number"==typeof t.x&&"number"==typeof t.y?(this.x=t.x,this.y=t.y):(this.x="number"==typeof i?i:void 0===i?0:NaN,this.y="number"==typeof r?r:void 0===r?0:NaN)}this.attr=new t,this.listeners=new s(this)}set(t,e){if("number"==typeof t&&"number"==typeof e)this.x=t,this.y=e;else{const s=t;"number"==typeof s.x&&"number"==typeof s.y?(this.x=s.x,this.y=s.y):(this.x="number"==typeof t?t:void 0===t?0:NaN,this.y="number"==typeof e?e:void 0===e?0:NaN)}return this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}invX(){return this.x=-this.x,this}invY(){return this.y=-this.y,this}add(t,e){if("number"==typeof t&&"number"==typeof e)this.x+=t,this.y+=e;else{const s=t;if("number"==typeof s.x&&"number"==typeof s.y)this.x+=s.x,this.y+=s.y;else{if("number"!=typeof t)throw`Cannot add ${typeof t} to numeric x component!`;if(this.x+=t,"number"!=typeof e)throw`Cannot add ${typeof e} to numeric y component!`;this.y+=e}}return this}addXY(t,e){return this.x+=t,this.y+=e,this}addX(t){return this.x+=t,this}addY(t){return this.y+=t,this}sub(t,e){if("number"==typeof t&&"number"==typeof e)this.x-=t,this.y-=e;else{const s=t;if("number"==typeof s.x&&"number"==typeof s.y)this.x-=s.x,this.y-=s.y;else{if("number"!=typeof t)throw`Cannot add ${typeof t} to numeric x component!`;if(this.x-=t,"number"!=typeof e)throw`Cannot add ${typeof e} to numeric y component!`;this.y-=e}}return this}subXY(t,e){return this.x-=t,this.y-=e,this}subX(t){return this.x-=t,this}subY(t){return this.y-=t,this}equals(t){var e=Math.abs(this.x-t.x)<h.EPSILON,s=Math.abs(this.y-t.y)<h.EPSILON;return e&&s}clone(){return new h(this.x,this.y)}distance(t){return a.dist4(this.x,this.y,t.x,t.y)}angle(t){const e=void 0===t?Math.PI/2-Math.atan2(this.x,this.y):Math.PI/2-Math.atan2(t.x-this.x,t.y-this.y);return e<0?2*Math.PI+e:e}difference(t){return new h(t.x-this.x,t.y-this.y)}scale(t,e){return this.scaleXY({x:t,y:t},e)}lerp(t,e){var s=this.difference(t);return this.x+=s.x*e,this.y+=s.y*e,this}lerpAbs(t,e){var s=this.distance(t),i=this.difference(t),r=i.x/s,n=i.y/s;return this.x+=r*e,this.y+=n*e,this}scaleXY(t,e){return e&&void 0!==e||(e={x:0,y:0}),this.x=e.x+(this.x-e.x)*t.x,this.y=e.y+(this.y-e.y)*t.y,this}rotate(t,e){e&&void 0!==e||(e={x:0,y:0}),this.sub(e),t+=Math.atan2(this.y,this.x);let s=this.distance(h.ZERO);return this.x=s*Math.cos(t),this.y=s*Math.sin(t),this.add(e),this}multiplyScalar(t){return this.x*=t,this.y*=t,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}inv(){return this.x=-this.x,this.y=-this.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}toString(t){return void 0===t?"("+this.x+","+this.y+")":"("+this.x.toFixed(t)+","+this.y.toFixed(t)+")"}destroy(){this.listeners.removeAllListeners(),this.isDestroyed=!0}static randomVertex(t){return new h(t.min.x+Math.random()*(t.max.x-t.min.x),t.min.y+Math.random()*(t.max.y-t.min.y))}}h.ZERO=new h(0,0),h.EPSILON=1e-6,h.utils={buildArrowHead:(t,e,s,i,r)=>{console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");var n=Math.atan2((e.y-t.y)*r,(e.x-t.x)*i),a=[];return a.push(new h(e.x*i-s*Math.cos(n),e.y*r-s*Math.sin(n))),a.push(new h(e.x*i-1.35*s*Math.cos(n-Math.PI/8),e.y*r-1.35*s*Math.sin(n-Math.PI/8))),a.push(new h(e.x*i,e.y*r)),a.push(new h(e.x*i-1.35*s*Math.cos(n+Math.PI/8),e.y*r-1.35*s*Math.sin(n+Math.PI/8))),a},arrayToJSON:(t,e)=>JSON.stringify(t.map((function(t){return void 0===typeof e?{x:t.x,y:t.y}:{x:Number(t.x.toFixed(e)),y:Number(t.y.toFixed(e))}})))};class o{constructor(t,s,i){this.uid=e.next(),this.a=t,this.b=s,this.factory=i}length(){return Math.sqrt(Math.pow(this.b.x-this.a.x,2)+Math.pow(this.b.y-this.a.y,2))}setLength(t){return this.scale(t/this.length())}sub(t){return this.a.sub(t),this.b.sub(t),this}add(t){return this.a.add(t),this.b.add(t),this}normalize(){return this.b.set(this.a.x+(this.b.x-this.a.x)/this.length(),this.a.y+(this.b.y-this.a.y)/this.length()),this}scale(t){return this.b.set(this.a.x+(this.b.x-this.a.x)*t,this.a.y+(this.b.y-this.a.y)*t),this}moveTo(t){let e=this.a.difference(t);return this.a.add(e),this.b.add(e),this}angle(t){null!=t&&void 0!==t||(t=this.factory(new h(0,0),new h(100,0)));const e=this.b.clone().sub(this.a),s=t.b.clone().sub(t.a);return Math.atan2(s.x,s.y)-Math.atan2(e.x,e.y)}vertAt(t){return new h(this.a.x+(this.b.x-this.a.x)*t,this.a.y+(this.b.y-this.a.y)*t)}denominator(t){return(t.b.y-t.a.y)*(this.b.x-this.a.x)-(t.b.x-t.a.x)*(this.b.y-this.a.y)}colinear(t,e){return Math.abs(this.denominator(t))<(void 0===e?h.EPSILON:e)}getClosestT(t){var e=o.vtutils.dist2(this.a,this.b);return 0===e?0:((t.x-this.a.x)*(this.b.x-this.a.x)+(t.y-this.a.y)*(this.b.y-this.a.y))/e}hasPoint(t,e,s){const i=this.getClosestT(t),r=Math.sqrt(o.vtutils.dist2(t,this.vertAt(i)));return void 0!==e&&e?r<(null!=s?s:h.EPSILON)&&i>=0&&i<=1:r<(null!=s?s:h.EPSILON)}getClosestPoint(t){var e=this.getClosestT(t);return this.vertAt(e)}pointDistance(t){return Math.sqrt(o.vtutils.dist2(t,this.vertAt(this.getClosestT(t))))}clone(){return this.factory(this.a.clone(),this.b.clone())}toString(){return"{ a : "+this.a.toString()+", b : "+this.b.toString()+" }"}destroy(){this.a.destroy(),this.b.destroy(),this.isDestroyed=!0}}o.vtutils={dist2:(t,e)=>(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)};class l extends o{constructor(t,e){super(t,e,((t,e)=>new l(t,e))),this.className="Line"}intersection(t){const e=this.denominator(t);if(0==e)return null;let s=this.a.y-t.a.y,i=this.a.x-t.a.x;const r=(t.b.x-t.a.x)*s-(t.b.y-t.a.y)*i,n=(this.b.x-this.a.x)*s-(this.b.y-this.a.y)*i;s=r/e,i=n/e;const a=this.a.x+s*(this.b.x-this.a.x),o=this.a.y+s*(this.b.y-this.a.y);return isNaN(s)||isNaN(a)||isNaN(o)?null:new h(a,o)}getStartPoint(){return this.a}getEndPoint(){return this.b}getStartTangent(){return this.b}getEndTangent(){return this.a}reverse(){var t=this.a;return this.a=this.b,this.b=t,this}}class c{constructor(t,s){this.className="Polygon",this.uid=e.next(),void 0===t&&(t=[]),this.vertices=t,this.isOpen=s||!1}addVertex(t){this.vertices.push(t)}addVertexAt(t,e){this.vertices.splice(e,0,t)}getEdgeAt(t){return new l(this.getVertexAt(t),this.getVertexAt(t+1))}getEdges(){const t=[];for(var e=0;e+1<this.vertices.length;e++)t.push(this.getEdgeAt(e));return!this.isOpen&&this.vertices.length>0&&t.push(this.getEdgeAt(this.vertices.length-1)),t}getInnerAngleAt(t){const e=this.vertices[t],s=this.vertices[(t+this.vertices.length-1)%this.vertices.length].clone(),i=this.vertices[(t+1)%this.vertices.length].clone(),r=this.isAngleAcute(t),n=new h(0,0),o=new h(e.x-s.x,e.y-s.y),l=new h(i.x-e.x,i.y-e.y),c=n.distance(o),d=n.distance(l),u=a.dotProduct(o,l),g=c*d;return r?Math.PI-Math.acos(u/g):Math.PI+Math.acos(u/g)}isAngleAcute(t){const e=this.vertices[(t+this.vertices.length-1)%this.vertices.length].clone(),s=this.vertices[t],i=this.vertices[(t+1)%this.vertices.length].clone();return n.utils.determinant(e,s,i)<0}getVertexAt(t){return t<0?this.vertices[this.vertices.length-Math.abs(t)%this.vertices.length]:this.vertices[t%this.vertices.length]}move(t){for(var e in this.vertices)this.vertices[e].add(t);return this}containsVert(t){for(var e=!1,s=0,i=this.vertices.length-1;s<this.vertices.length;i=s++){let r=this.vertices[s].x,n=this.vertices[s].y,a=this.vertices[i].x,h=this.vertices[i].y;n>t.y!=h>t.y&&t.x<(a-r)*(t.y-n)/(h-n)+r&&(e=!e)}return e}containsVerts(t){return t.every((t=>this.containsVert(t)))}containsPolygon(t){for(var e=0;e<t.vertices.length;e++)if(!this.containsVert(t.vertices[e]))return!1;const s=new l(new h,new h);for(e=0;e<t.vertices.length;e++)if(s.a.set(t.vertices[e]),s.b.set(t.vertices[(e+1)%t.vertices.length]),this.lineIntersections(s,!0).length>0)return!1;return!0}area(){return c.utils.area(this.vertices)}signedArea(){return c.utils.signedArea(this.vertices)}isClockwise(){return c.utils.isClockwise(this.vertices)}perimeter(){let t=0;for(var e=1;e<this.vertices.length;e++)t+=this.vertices[e-1].distance(this.vertices[e]);return!this.isOpen&&this.vertices.length>1&&(t+=this.vertices[0].distance(this.vertices[this.vertices.length-1])),t}scale(t,e){for(var s in this.vertices)"function"==typeof this.vertices[s].scale?this.vertices[s].scale(t,e):console.log("There seems to be a null vertex!",this.vertices[s]);return this}rotate(t,e){for(var s in this.vertices)this.vertices[s].rotate(t,e);return this}getMeanCenter(){if(0===this.vertices.length)return null;const t=this.vertices[0].clone();for(var e=1;e<this.vertices.length;e++)t.add(this.vertices[e]);return t.x/=this.vertices.length,t.y/=this.vertices.length,t}lineIntersections(t,e=!1){const s=[];for(var i=0;i<this.vertices.length;i++){const r=new l(this.vertices[i],this.vertices[(i+1)%this.vertices.length]),n=r.intersection(t);this.isOpen&&i+1===this.vertices.length||null===n||!r.hasPoint(n,!0)||e&&!t.hasPoint(n,e)||s.push(n)}return s}closestLineIntersection(t,e=!1){const s=this.lineIntersections(t,e);if(s.length<=0)return null;let i=new h(Number.MAX_VALUE,Number.MAX_VALUE),r=Number.MAX_VALUE;for(var n in s){const e=s[n],a=e.distance(t.a);a<r&&(r=a,i=e)}return i}getInterpolationPolygon(t){const e=[];for(var s=0;s<this.vertices.length;s++){const r=this.vertices[s],n=this.vertices[(s+1)%this.vertices.length];if(e.push(r.clone()),!this.isOpen||s+1!==this.vertices.length){const s=1/(t+1);for(var i=1;i<=t;i++)e.push(r.clone().lerp(n,s*i))}}return new c(e,this.isOpen)}getEvenDistributionPolygon(t){if(t<=0)throw new Error("pointCount must be larger than zero; is "+t+".");const e=new c([],this.isOpen);if(0===this.vertices.length)return e;let s=new h(this.vertices[0]);if(e.vertices.push(s),1===this.vertices.length)return e;const i=this.perimeter()/t,r=this.vertices.length;let n=1,a=new h(this.vertices[1]),o=s.distance(a),l=this.isOpen?r:r+1,d=i;for(var u=1;u<t&&n<l;)if(d<o){let t=s.clone().lerpAbs(a,d);e.vertices.push(t),d+=i,u++}else n++,s=a,a=new h(this.vertices[n%r]),d-=o,o=s.distance(a);return e}getBounds(){return d.computeFromVertices(this.vertices)}clone(){return new c(this.vertices.map((t=>t.clone())),this.isOpen)}elimitateColinearEdges(t){const e=void 0===t?1:t,s=this.vertices.slice();let i=0;for(var r=new l(new h,new h),n=new l(new h,new h);i+1<s.length&&s.length>2;){const t=s[i],a=s[(i+1)%s.length];r.a=t,r.b=a,n.a=a;let h=!1,o=i+2;do{let t=s[o%s.length];n.b=t,h=r.colinear(n,e),h&&o++}while(h);o-i>2&&s.splice(i+1,o-i-2),i++}return new c(s,this.isOpen)}toQuadraticBezierData(){if(this.vertices.length<3)return[];var t=[],e=this.vertices[0],s=this.vertices[1],i=new h(e.x+(s.x-e.x)/2,e.y+(s.y-e.y)/2);t.push(i);for(var r=this.isOpen?this.vertices.length:this.vertices.length+1,n=1;n<r;n++){e=this.vertices[n%this.vertices.length],s=this.vertices[(n+1)%this.vertices.length];i=new h(e.x+(s.x-e.x)/2,e.y+(s.y-e.y)/2);t.push(e),t.push(i),e=s}return t}toQuadraticBezierSVGString(){var t=this.toQuadraticBezierData();if(0==t.length)return"";for(var e=["M "+t[0].x+" "+t[0].y],s=1;s<t.length;s+=2)e.push("Q "+t[s].x+" "+t[s].y+", "+t[s+1].x+" "+t[s+1].y);return e.join(" ")}toCubicBezierData(t){if(void 0===t&&(t=1),this.vertices.length<3)return[];var e=[],s=this.vertices[0],i=this.vertices[1],r=new h(s.x+(i.x-s.x)/2,s.y+(i.y-s.y)/2);e.push(r);for(var n=this.isOpen?this.vertices.length-1:this.vertices.length,a=0;a<n;a++){s=this.vertices[a%this.vertices.length],i=this.vertices[(a+1)%this.vertices.length];var o=this.vertices[(a+2)%this.vertices.length],l=new h(s.x+(i.x-s.x)/2,s.y+(i.y-s.y)/2),c=new h(i.x+(o.x-i.x)/2,i.y+(o.y-i.y)/2),d=new h(l.x+(i.x-l.x)*t,l.y+(i.y-l.y)*t),u=new h(c.x+(i.x-c.x)*t,c.y+(i.y-c.y)*t);e.push(d),e.push(u),e.push(c)}return e}toCubicBezierSVGString(t){var e=this.toCubicBezierData(t);if(0==e.length)return"";for(var s=["M "+e[0].x+" "+e[0].y],i=1;i<e.length;i+=3)s.push("C "+e[i].x+" "+e[i].y+", "+e[i+1].x+" "+e[i+1].y+", "+e[i+2].x+" "+e[i+2].y);return s.join(" ")}toCubicBezierPath(t){for(var e=this.toCubicBezierData(t),s=[],i=0;i+3<e.length;i+=3)s.push([e[i],e[i+3],e[i+1],e[i+2]]);return g.fromArray(s)}destroy(){for(var t=0;t<this.vertices.length;t++)this.vertices[t].destroy();this.isDestroyed=!0}}c.utils={area(t){let e=0;for(var s=0,i=t.length;s<i;s++){e+=t[s].x*t[(s+1)%i].y*.5,e-=t[(s+1)%i].x*t[s].y*.5}return Math.abs(e)},isClockwise:t=>c.utils.signedArea(t)<0,signedArea(t){let e=0;const s=t.length;for(var i=0;i<s;i++){const r=(i+1)%s;e+=(t[r].x-t[i].x)*(t[i].y+t[r].y)}return e}};class d{constructor(t,e){this.min=t,this.max=e,this.width=e.x-t.x,this.height=e.y-t.y}toPolygon(){return new c([new h(this.min),new h(this.max.x,this.min.y),new h(this.max),new h(this.min.x,this.max.y)],!1)}getCenter(){return new h(this.min.x+(this.max.x-this.min.x)/2,this.min.y+(this.max.y-this.min.y)/2)}randomPoint(t=0,e=0){const s=t>0&&t<1?this.width*t:t,i=e>0&&e<1?this.height*e:e;return new h(this.min.x+s+Math.random()*(this.width-2*s),this.min.y+i+Math.random()*(this.height-2*i))}toString(){return`{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`}clone(){return new d({x:this.min.x,y:this.min.y},{x:this.max.x,y:this.max.y})}static computeFromVertices(t){if(0==t.length)return new d(new h(0,0),new h(0,0));let e,s=t[0].x,i=t[0].x,r=t[0].y,n=t[0].y;for(var a in t)e=t[a],s=Math.min(s,e.x),i=Math.max(i,e.x),r=Math.min(r,e.y),n=Math.max(n,e.y);return new d(new h(s,r),new h(i,n))}static fromDimension(t,e,s){return new d(null!=s?s:{x:0,y:0},{x:(s?s.x:0)+t,y:(s?s.y:0)+e})}}class u{constructor(t,s,i,r){this.START_POINT=u.START_POINT,this.START_CONTROL_POINT=u.START_CONTROL_POINT,this.END_CONTROL_POINT=u.END_CONTROL_POINT,this.END_POINT=u.END_POINT,this.uid=e.next(),this.startPoint=t,this.startControlPoint=i,this.endPoint=s,this.endControlPoint=r,this.curveIntervals=30,this.segmentCache=[],this.segmentLengths=[],this.updateArcLengths()}moveCurvePoint(t,e,s,i){t==this.START_POINT?(this.getStartPoint().add(e),s&&this.getStartControlPoint().add(e)):t==this.START_CONTROL_POINT?this.getStartControlPoint().add(e):t==this.END_CONTROL_POINT?this.getEndControlPoint().add(e):t==this.END_POINT?(this.getEndPoint().add(e),s&&this.getEndControlPoint().add(e)):console.log(`[CubicBezierCurve.moveCurvePoint] pointID '${t}' invalid.`),i&&this.updateArcLengths()}translate(t){return this.startPoint.add(t),this.startControlPoint.add(t),this.endControlPoint.add(t),this.endPoint.add(t),this}reverse(){let t=this.startPoint;return this.startPoint=this.endPoint,this.endPoint=t,t=this.startControlPoint,this.startControlPoint=this.endControlPoint,this.endControlPoint=t,this}getLength(){return this.arcLength}updateArcLengths(){let t=this.startPoint.clone(),e=new h(0,0),s=1/this.curveIntervals;this.segmentCache=[],this.segmentCache.push(this.startPoint),this.segmentLengths=[];let i=0;var r=0;let n;for(;r<=1;)e=this.getPointAt(r),this.segmentCache.push(e),n=t.distance(e),this.segmentLengths.push(n),i+=n,t=e,r+=s;this.arcLength=i}getClosestT(t){var e={t:0,tPrev:0,tNext:1},s=0;do{e=this.locateIntervalByDistance(t,e.tPrev,e.tNext,this.curveIntervals),s++}while(s<4&&this.getPointAt(e.tPrev).distance(this.getPointAt(e.tNext))>1);return e.t}locateIntervalByDistance(t,e,s,i){var r=-1,n=0,a=0;const h=s-e;for(var o=0;o<=i;o++){a=e+h*(o/i);var l=this.getPointAt(a).distance(t);(-1==r||l<n)&&(r=o,n=l)}return{t:e+h*(r/i),tPrev:e+h*(Math.max(0,r-1)/i),tNext:e+h*(Math.min(i,r+1)/i)}}getBounds(){var t=new h(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),e=new h(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);let s;for(var i=0;i<this.segmentCache.length;i++)s=this.segmentCache[i],t.x=Math.min(t.x,s.x),t.y=Math.min(t.y,s.y),e.x=Math.max(e.x,s.x),e.y=Math.max(e.y,s.y);return new d(t,e)}getStartPoint(){return this.startPoint}getEndPoint(){return this.endPoint}getStartControlPoint(){return this.startControlPoint}getEndControlPoint(){return this.endControlPoint}getPointByID(t){if(t==this.START_POINT)return this.startPoint;if(t==this.END_POINT)return this.endPoint;if(t==this.START_CONTROL_POINT)return this.startControlPoint;if(t==this.END_CONTROL_POINT)return this.endControlPoint;throw new Error(`Invalid point ID '${t}'.`)}getPointAt(t){const e=this.startPoint.x*Math.pow(1-t,3)+3*this.startControlPoint.x*t*Math.pow(1-t,2)+3*this.endControlPoint.x*Math.pow(t,2)*(1-t)+this.endPoint.x*Math.pow(t,3),s=this.startPoint.y*Math.pow(1-t,3)+3*this.startControlPoint.y*t*Math.pow(1-t,2)+3*this.endControlPoint.y*Math.pow(t,2)*(1-t)+this.endPoint.y*Math.pow(t,3);return new h(e,s)}getPoint(t){return this.getPointAt(t/this.arcLength)}getTangentAt(t){const e=this.getStartPoint(),s=this.getStartControlPoint(),i=this.getEndControlPoint(),r=this.getEndPoint(),n=t*t,a=1-2*t+n,o=-3*e.x*a+s.x*(3*a-6*(t-n))+i.x*(6*(t-n)-3*n)+3*r.x*n,l=-3*e.y*a+s.y*(3*a-6*(t-n))+i.y*(6*(t-n)-3*n)+3*r.y*n;return new h(o,l)}trimStart(t){return this.trimStartAt(this.convertU2T(t))}trimStartAt(t){const e=u.utils.getSubCurvePointsAt(this,t,1);return this.startPoint.set(e[0]),this.startControlPoint.set(e[2]),this.endPoint.set(e[1]),this.endControlPoint.set(e[3]),this.updateArcLengths(),this}trimEnd(t){return this.trimEndAt(this.convertU2T(t))}trimEndAt(t){const e=u.utils.getSubCurvePointsAt(this,0,t);return this.startPoint.set(e[0]),this.startControlPoint.set(e[2]),this.endPoint.set(e[1]),this.endControlPoint.set(e[3]),this.updateArcLengths(),this}getSubCurve(t,e){return this.getSubCurveAt(this.convertU2T(t),this.convertU2T(e))}getSubCurveAt(t,e){const s=u.utils.getSubCurvePointsAt(this,t,e);return new u(s[0],s[1],s[2],s[3])}convertU2T(t){return Math.max(0,Math.min(1,t/this.arcLength))}getTangent(t){return this.getTangentAt(this.convertU2T(t))}getPerpendicular(t){return this.getPerpendicularAt(this.convertU2T(t))}getPerpendicularAt(t){const e=this.getTangentAt(t);return new h(e.y,-e.x)}clone(){return new u(this.getStartPoint().clone(),this.getEndPoint().clone(),this.getStartControlPoint().clone(),this.getEndControlPoint().clone())}getStartTangent(){return this.startControlPoint}getEndTangent(){return this.endControlPoint}equals(t){return!!t&&(!!(t.startPoint&&t.endPoint&&t.startControlPoint&&t.endControlPoint)&&(this.startPoint.equals(t.startPoint)&&this.endPoint.equals(t.endPoint)&&this.startControlPoint.equals(t.startControlPoint)&&this.endControlPoint.equals(t.endControlPoint)))}destroy(){this.startPoint.destroy(),this.endPoint.destroy(),this.startControlPoint.destroy(),this.endControlPoint.destroy(),this.isDestroyed=!0}static isInstance(t){return t instanceof u}toJSON(t){return"{ "+(t?"\n\t":"")+'"startPoint" : ['+this.getStartPoint().x+","+this.getStartPoint().y+"], "+(t?"\n\t":"")+'"endPoint" : ['+this.getEndPoint().x+","+this.getEndPoint().y+"], "+(t?"\n\t":"")+'"startControlPoint": ['+this.getStartControlPoint().x+","+this.getStartControlPoint().y+"], "+(t?"\n\t":"")+'"endControlPoint" : ['+this.getEndControlPoint().x+","+this.getEndControlPoint().y+"]"+(t?"\n\t":"")+" }"}static fromJSON(t){var e=JSON.parse(t);return u.fromObject(e)}static fromObject(t){if("object"!=typeof t)throw"Can only build from object.";if(!t.startPoint)throw'Object member "startPoint" missing.';if(!t.endPoint)throw'Object member "endPoint" missing.';if(!t.startControlPoint)throw'Object member "startControlPoint" missing.';if(!t.endControlPoint)throw'Object member "endControlPoint" missing.';return new u(new h(t.startPoint[0],t.startPoint[1]),new h(t.endPoint[0],t.endPoint[1]),new h(t.startControlPoint[0],t.startControlPoint[1]),new h(t.endControlPoint[0],t.endControlPoint[1]))}static fromArray(t){if(!Array.isArray(t))throw"Can only build from object.";if(4!=t.length)throw"Can only build from array with four elements.";return new u(t[0],t[1],t[2],t[3])}}u.START_POINT=0,u.START_CONTROL_POINT=1,u.END_CONTROL_POINT=2,u.END_POINT=3,u.utils={getSubCurvePointsAt:(t,e,s)=>{const r=new i(t.getPointAt(e),t.getTangentAt(e)),n=new i(t.getPointAt(s),t.getTangentAt(s).inv());return r.b.add(r.a),n.b.add(n.a),r.scale(.33333333*(s-e)),n.scale(.33333333*(s-e)),[r.a,n.a,r.b,n.b]}};class g{constructor(){this.className="BezierPath",this.START_POINT=0,this.START_CONTROL_POINT=1,this.END_CONTROL_POINT=2,this.END_POINT=3,this.uid=e.next(),this.totalArcLength=0,this.adjustCircular=!1,this.bezierCurves=[]}addCurve(t){if(null==t||void 0===t)throw"Cannot add null curve to bézier path.";this.bezierCurves.push(t),this.bezierCurves.length>1?(t.startPoint=this.bezierCurves[this.bezierCurves.length-2].endPoint,this.adjustSuccessorControlPoint(this.bezierCurves.length-2,!0,!0)):this.totalArcLength+=t.getLength()}locateCurveByStartPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].startPoint.equals(t))return e;return-1}locateCurveByEndPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].endPoint.equals(t))return e;return-1}locateCurveByStartControlPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].startControlPoint.equals(t))return e;return-1}locateCurveByEndControlPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].endControlPoint.equals(t))return e;return-1}getLength(){return this.totalArcLength}updateArcLengths(){this.totalArcLength=0;for(var t=0;t<this.bezierCurves.length;t++)this.bezierCurves[t].updateArcLengths(),this.totalArcLength+=this.bezierCurves[t].getLength()}getCurveCount(){return this.bezierCurves.length}getCurveAt(t){return this.bezierCurves[t]}translate(t){for(var e=0;e<this.bezierCurves.length;e++){(s=this.bezierCurves[e]).getStartPoint().add(t),s.getStartControlPoint().add(t),s.getEndControlPoint().add(t)}var s;return(s=this.bezierCurves[this.bezierCurves.length-1]).getEndPoint().add(t),this.updateArcLengths(),this}scale(t,e){return this.scaleXY({x:e,y:e},t)}scaleXY(t,e){for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];i.getStartPoint().scaleXY(t,e),i.getStartControlPoint().scaleXY(t,e),i.getEndControlPoint().scaleXY(t,e)}return this.bezierCurves.length>0&&!this.adjustCircular&&this.bezierCurves[this.bezierCurves.length-1].getEndPoint().scaleXY(t,e),this.updateArcLengths(),this}rotate(t,e){for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];i.getStartPoint().rotate(t,e),i.getStartControlPoint().rotate(t,e),i.getEndControlPoint().rotate(t,e)}this.bezierCurves.length>0&&!this.adjustCircular&&this.bezierCurves[this.bezierCurves.length-1].getEndPoint().rotate(t,e)}getClosestT(t){for(var e=-1,s=0,i=0,r=0,n=0,a=0,h=0;h<this.bezierCurves.length;h++)r=this.bezierCurves[h].getClosestT(t),i=this.bezierCurves[h].getPointAt(r).distance(t),(-1==e||i<s)&&(e=h,s=i,n=a+r*this.bezierCurves[h].getLength()),a+=this.bezierCurves[h].getLength();return Math.max(0,Math.min(1,n/this.totalArcLength))}getPoint(t){(t<0||t>this.totalArcLength)&&(console.warn("[BezierPath.getPoint(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(t,0)));for(var e=0,s=0;e<this.bezierCurves.length&&s+this.bezierCurves[e].getLength()<t;)s+=this.bezierCurves[e].getLength(),e++;if(e>=this.bezierCurves.length)return this.bezierCurves[this.bezierCurves.length-1].getEndPoint().clone();var i=t-s;return this.bezierCurves[e].getPoint(i)}getPointAt(t){return this.getPoint(t*this.totalArcLength)}getTangentAt(t){return this.getTangent(t*this.totalArcLength)}getTangent(t){(t<0||t>this.totalArcLength)&&(console.warn("[BezierPath.getTangent(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(0,t)));for(var e=0,s=0;e<this.bezierCurves.length&&s+this.bezierCurves[e].getLength()<t;)s+=this.bezierCurves[e].getLength(),e++;var i=t-s;return this.bezierCurves[e].getTangent(i)}getPerpendicularAt(t){return this.getPerpendicular(t*this.totalArcLength)}getPerpendicular(t){(t<0||t>this.totalArcLength)&&(console.log("[BezierPath.getPerpendicular(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(0,t)));var e=g._locateUIndex(this,t),s=this.bezierCurves[e.i],i=t-e.uPart;return s.getPerpendicular(i)}static _locateUIndex(t,e){for(var s=0,i=0,r=0;s<t.bezierCurves.length&&i+t.bezierCurves[s].getLength()<e;)i+=t.bezierCurves[s].getLength(),s+1<t.bezierCurves.length&&(r+=t.bezierCurves[s].getLength()),s++;return{i:s,uPart:i,uBefore:r}}getSubPathAt(t,e){t=Math.max(0,t),e=Math.min(1,e);let s=t*this.totalArcLength,i=e*this.totalArcLength;var r=g._locateUIndex(this,s),n=g._locateUIndex(this,i),a=(s-r.uBefore)/this.bezierCurves[r.i].getLength();if(r.i==n.i){var h=(i-n.uBefore)/this.bezierCurves[n.i].getLength(),o=this.bezierCurves[r.i].getSubCurveAt(a,h);return g.fromArray([o])}var l=[];if(r.i>n.i){o=this.bezierCurves[r.i].getSubCurveAt(a,0);l.push(o);for(var c=r.i-1;c>n.i;c--)l.push(this.bezierCurves[c].clone().reverse());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();l.push(this.bezierCurves[n.i].getSubCurveAt(1,h))}else{o=this.bezierCurves[r.i].getSubCurveAt(a,1);l.push(o);for(c=r.i+1;c<n.i&&c<this.bezierCurves.length;c++)l.push(this.bezierCurves[c].clone());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();l.push(this.bezierCurves[n.i].getSubCurveAt(0,h))}return g.fromArray(l)}moveCurvePoint(t,e,s){if(this.getCurveAt(t).moveCurvePoint(e,s,!0,!0),e==this.START_POINT&&(t>0||this.adjustCircular))this.getCurveAt(t-1<0?this.bezierCurves.length+(t-1):t-1).moveCurvePoint(this.END_CONTROL_POINT,s,!0,!1);else if(e==this.END_POINT&&(t+1<this.bezierCurves.length||this.adjustCircular)){this.getCurveAt((t+1)%this.bezierCurves.length).moveCurvePoint(this.START_CONTROL_POINT,s,!0,!1)}else e==this.START_CONTROL_POINT&&t>0?this.adjustPredecessorControlPoint(t,!0,!1):e==this.END_CONTROL_POINT&&t+1<this.getCurveCount()&&this.adjustSuccessorControlPoint(t,!0,!1);this.updateArcLengths()}adjustPredecessorControlPoint(t,e,s){if(this.adjustCircular||!(t<=0)){var i=this.getCurveAt(t),r=this.getCurveAt(t-1<0?this.getCurveCount()+(t-1):t-1);g.adjustNeighbourControlPoint(i,r,i.getStartPoint(),i.getStartControlPoint(),r.getEndPoint(),r.getEndControlPoint(),e,s)}}adjustSuccessorControlPoint(t,e,s){if(this.adjustCircular||!(t+1>this.getCurveCount())){var i=this.getCurveAt(t),r=this.getCurveAt((t+1)%this.getCurveCount());g.adjustNeighbourControlPoint(i,r,i.getEndPoint(),i.getEndControlPoint(),r.getStartPoint(),r.getStartControlPoint(),e,s)}}static adjustNeighbourControlPoint(t,e,s,i,r,n,a,o){var l=new h(i.x-s.x,i.y-s.y),c=new h(n.x-r.x,n.y-r.y),d=Math.sqrt(Math.pow(l.x,2)+Math.pow(l.y,2)),u=Math.sqrt(Math.pow(c.x,2)+Math.pow(c.y,2));d<=.1||(a?n.set(r.x-l.x*(u/d),r.y-l.y*(u/d)):n.set(r.x-l.x,r.y-l.y),e.updateArcLengths())}getBounds(){const t=new h(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),e=new h(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);for(var s,i=0;i<this.bezierCurves.length;i++)s=this.bezierCurves[i].getBounds(),t.x=Math.min(t.x,s.min.x),t.y=Math.min(t.y,s.min.y),e.x=Math.max(e.x,s.max.x),e.y=Math.max(e.y,s.max.y);return new d(t,e)}getEvenDistributionVertices(t){if(t<2)throw new Error("pointCount must be larger than one; is "+t+".");const e=[];if(0===this.bezierCurves.length)return e;var s=new h(this.bezierCurves[0].startPoint);e.push(s);const i=this.totalArcLength/(t-1),r=this.bezierCurves.length;let n=0,a=this.bezierCurves[0].arcLength,o=i,l=1;for(;l<t&&n<r;)if(o<a){var c=this.bezierCurves[n].getPoint(o);e.push(c),o+=i,l++}else n++,o-=a,a=n<r?this.bezierCurves[n].arcLength:0;return e.push(new h(this.bezierCurves[r-1].endPoint)),e}clone(){for(var t=new g,e=0;e<this.bezierCurves.length;e++)t.bezierCurves.push(this.bezierCurves[e].clone()),e>0&&(t.bezierCurves[e-1].endPoint=t.bezierCurves[e].startPoint);return t.updateArcLengths(),t.adjustCircular=this.adjustCircular,t}equals(t){if(!t)return!1;if(!t.bezierCurves)return!1;if(void 0===t.bezierCurves.length)return!1;if(t.bezierCurves.length!=this.bezierCurves.length)return!1;for(var e=0;e<this.bezierCurves.length;e++)if(!this.bezierCurves[e].equals(t.bezierCurves[e]))return!1;return!0}destroy(){for(var t=0;t<this.bezierCurves.length;t++)this.bezierCurves[t].destroy();this.isDestroyed=!0}toPathPoints(){if(0===this.bezierCurves.length)return[];if(1===this.bezierCurves.length)return[this.bezierCurves[0].startPoint,this.bezierCurves[0].startControlPoint,this.bezierCurves[0].endControlPoint,this.bezierCurves[0].endPoint];const t=[];t.push(this.bezierCurves[0].startPoint),t.push(this.bezierCurves[0].startControlPoint);for(var e=1;e<this.bezierCurves.length;e++)t.push(this.bezierCurves[e-1].endControlPoint),t.push(this.bezierCurves[e-1].endPoint),t.push(this.bezierCurves[e].startPoint),t.push(this.bezierCurves[e].startControlPoint);return t.push(this.bezierCurves[0].endControlPoint),t.push(this.bezierCurves[0].endPoint),t}toJSON(t){var e=[];e.push("[");for(var s=0;s<this.bezierCurves.length;s++)s>0&&e.push(","),t?e.push("\n\t"):e.push(" "),e.push(this.bezierCurves[s].toJSON(t));return 0!=this.bezierCurves.length&&e.push(" "),e.push("]"),e.join("")}static fromJSON(t){var e=JSON.parse(t);return g.fromArray(e)}static fromCurve(t){const e=new g;return e.addCurve(t),e}static fromArray(t){if(!Array.isArray(t))throw"[BezierPath.fromArray] Passed object must be an array.";const e=t;if(e.length<1)throw"[BezierPath.fromArray] Passed array must contain at least one bezier curve (has "+e.length+").";for(var s=new g,i=null,r=0;r<e.length;r++){var n;if(u.isInstance(e[r]))n=e[r].clone();else if(0 in e[r]&&1 in e[r]&&2 in e[r]&&3 in e[r]){if(!(e[r][0]&&e[r][1]&&e[r][2]&&e[r][3]))throw"Cannot convert path data to BezierPath instance. At least one element is undefined (index="+r+"): "+e[r];n=u.fromArray(e[r])}else n=u.fromObject(e[r]);i&&(n.startPoint=i.endPoint),s.bezierCurves.push(n),i=n}return s.updateArcLengths(),s}toReducedListRepresentation(t){void 0===t&&(t=1);var e=[];e.push("[");for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];e.push(i.getStartPoint().x.toFixed(t)),e.push(","),e.push(i.getStartPoint().y.toFixed(t)),e.push(","),e.push(i.getStartControlPoint().x.toFixed(t)),e.push(","),e.push(i.getStartControlPoint().y.toFixed(t)),e.push(","),e.push(i.getEndControlPoint().x.toFixed(t)),e.push(","),e.push(i.getEndControlPoint().y.toFixed(t)),e.push(",")}if(0!=this.bezierCurves.length){i=this.bezierCurves[this.bezierCurves.length-1];e.push(i.getEndPoint().x.toFixed(t)),e.push(","),e.push(i.getEndPoint().y.toFixed(t))}return e.push("]"),e.join("")}static fromReducedListRepresentation(t,e){var s=JSON.parse(t);if(!s.length)throw console.log("Cannot parse bezier path from non-array object nor from empty point list."),"Cannot parse bezier path from non-array object nor from empty point list.";if(s.length<8)throw console.log("Cannot build bezier path. The passed array must contain at least 8 elements (numbers)."),"Cannot build bezier path. The passed array must contain at least 8 elements (numbers).";return g.fromReducedList(s,e)}static fromReducedList(t,e){var s,i,r,n=new g,a=new h,o=0;do{0==o&&(a=new h(t[o],t[o+1])),s=new h(t[o+2],t[o+3]),i=new h(t[o+4],t[o+5]),r=new h(t[o+6],t[o+7]);var l=new u(a,r,s,i);n.bezierCurves.push(l),a=r,o+=6}while(o+2<t.length);return n.adjustCircular=null!=e&&e,e&&(n.bezierCurves[n.bezierCurves.length-1].endPoint=n.bezierCurves[0].startPoint),n.updateArcLengths(),n}}g.START_POINT=0,g.START_CONTROL_POINT=1,g.END_CONTROL_POINT=2,g.END_POINT=3;class f{constructor(t,s,i){this.className="CircleSector",this.uid=e.next(),this.circle=t,this.startAngle=s,this.endAngle=i}containsAngle(t){return this.startAngle<=this.endAngle?t>=this.startAngle&&t<this.endAngle:t>=this.startAngle||t<this.endAngle}angleAt(t){if(this.startAngle<=this.endAngle){return(this.startAngle+(this.endAngle-this.startAngle)*t)%(2*Math.PI)}return(this.startAngle+(2*Math.PI-this.startAngle+this.endAngle)*t)%(2*Math.PI)}getStartPoint(){return this.circle.vertAt(this.startAngle)}getEndPoint(){return this.circle.vertAt(this.endAngle)}circleSectorIntersection(t){const e=this.circle.circleIntersection(t.circle);if(!e)return null;const s=this.circle.center.angle(e.a),i=this.circle.center.angle(e.b);if(!this.containsAngle(s)||!this.containsAngle(i))return null;const n=t.circle.center.angle(e.a),a=t.circle.center.angle(e.b);if(!t.containsAngle(n)||!t.containsAngle(a))return null;var h=new f(this.circle,this.endAngle,this.startAngle).angleAt(.5);const o=new f(new r(this.circle.center.clone(),this.circle.radius),s,i);return o.containsAngle(h)&&(o.startAngle=i,o.endAngle=s),o}destroy(){this.circle.destroy(),this.isDestroyed=!0}}f.circleSectorUtils={polarToCartesian:(t,e,s,i)=>({x:t+s*Math.cos(i),y:e+s*Math.sin(i)}),describeSVGArc:(t,e,s,i,r,n)=>{void 0===n&&(n={moveToStart:!0});const a=f.circleSectorUtils.polarToCartesian(t,e,s,r),h=f.circleSectorUtils.polarToCartesian(t,e,s,i);if(2*Math.PI-Math.abs(i-r)<.001){const a=f.circleSectorUtils.describeSVGArc(t,e,s,i,i+(r-i)/2,n),h=f.circleSectorUtils.describeSVGArc(t,e,s,i+(r-i)/2,r,n);return a.concat(h)}const o=r-i;var l,c;o<0?(l=Math.abs(o)<Math.PI?1:0,c=1):(l=Math.abs(o)>Math.PI?1:0,c=1);const d=[];return n.moveToStart&&d.push("M",h.x,h.y),d.push("A",s,s,0,l,c,a.x,a.y),d}};const v=180/Math.PI;class x{constructor(t,e,s,i,r,n,a,o,l,c,d,u){if(this.svgNode=t,this.offset=new h(0,0).set(e),this.scale=new h(1,1).set(s),this.fillShapes=r,this.isSecondary=Boolean(a),this.drawConfig=n,this.drawlibConfiguration={},this.cache=new Map,this.setSize(i),a){if(!(o&&l&&c&&d))throw"Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";this.gNode=o,this.bufferGNode=l,this.nodeDefs=c,this.bufferedNodeDefs=d,u&&(this.nodeStyle=u)}else this.addStyleDefs(n),this.addDefsNode(),this.gNode=this.createSVGNode("g"),this.bufferGNode=this.createSVGNode("g"),this.svgNode.appendChild(this.gNode)}addStyleDefs(t){this.nodeStyle=this.createSVGNode("style"),this.svgNode.appendChild(this.nodeStyle),this.rebuildStyleDefs(t)}rebuildStyleDefs(t){const e={bezier:"CubicBezierCurve",polygon:"Polygon",triangle:"Triangle",ellipse:"Ellipse",ellipseSector:"EllipseSector",circle:"Circle",circleSector:"CircleSector",vertex:"Vertex",line:"Line",vector:"Vector",image:"Image",text:"Text"},s=[];for(var i in e){const r=e[i],n=t[i];n?s.push(`.${r} { fill : none; stroke: ${n.color}; stroke-width: ${n.lineWidth}px }`):console.warn(`Warning: your draw config is missing the key '${i}' which is required.`)}this.customStyleDefs&&(s.push("\n/* Custom styles */\n"),this.customStyleDefs.forEach(((t,e)=>{s.push(e+" { "+t+" }")}))),this.nodeStyle.innerHTML=s.join("\n")}addDefsNode(){this.nodeDefs=this.createSVGNode("defs"),this.bufferedNodeDefs=this.createSVGNode("defs"),this.svgNode.appendChild(this.nodeDefs)}addCustomStyleDefs(t){this.customStyleDefs=t}findElement(t,e){if(!t)return null;var s=this.cache.get(t);return s&&s.nodeName.toUpperCase()===e.toUpperCase()?(this.cache.delete(t),s):null}createSVGNode(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}makeNode(t){var e=this.findElement(this.curId,t);return e||(e=this.createSVGNode(t)),this.drawlibConfiguration.blendMode&&e.style["mix-blend-mode"](this.drawlibConfiguration.blendMode),e}_bindFillDraw(t,e,s,i,r){return this._configureNode(t,e,this.fillShapes,s,i,r),this._bindNode(t,void 0)}_bindNode(t,e){return t.parentNode||(null!=e?e:this.bufferGNode).appendChild(t),t}_addCSSClasses(t,e){this.curClassName?t.setAttribute("class",`${e} ${this.curClassName}`):t.setAttribute("class",e)}_configureNode(t,e,s,i,r,n){return this._addCSSClasses(t,e),t.setAttribute("fill",s&&i?i:"none"),t.setAttribute("stroke",s?"none":i||"none"),t.setAttribute("stroke-width",`${r||1}`),this.curId&&t.setAttribute("id",`${this.curId}`),this.applyStrokeOpts(t,n),t}setSize(t){this.canvasSize=t,this.svgNode.setAttribute("viewBox",`0 0 ${this.canvasSize.width} ${this.canvasSize.height}`),this.svgNode.setAttribute("width",`${this.canvasSize.width}`),this.svgNode.setAttribute("height",`${this.canvasSize.height}`)}copyInstance(t){return new x(this.svgNode,this.offset,this.scale,this.canvasSize,t,this.drawConfig,!0,this.gNode,this.bufferGNode,this.nodeDefs,this.bufferedNodeDefs,this.nodeStyle)}setConfiguration(t){this.drawlibConfiguration=t}setCurrentId(t){this.curId=t}setCurrentClassName(t){this.curClassName=t}beginDrawCycle(t){this.cache.clear();for(var e=0;e<this.bufferGNode.childNodes.length;e++){var s=this.bufferGNode.childNodes[e];this.cache.set(s.getAttribute("id"),s)}this.removeAllChildNodes()}endDrawCycle(t){this.rebuildStyleDefs(this.drawConfig),this.isSecondary||(this.svgNode.replaceChild(this.bufferedNodeDefs,this.nodeDefs),this.svgNode.replaceChild(this.bufferGNode,this.gNode));const e=this.gNode;this.gNode=this.bufferGNode,this.bufferGNode=e;const s=this.nodeDefs;this.nodeDefs=this.bufferedNodeDefs,this.bufferedNodeDefs=s}applyStrokeOpts(t,e){e&&e.dashArray&&e.dashArray.length>0&&x.nodeSupportsLineDash(t.tagName)&&(t.setAttribute("stroke-dasharray",e.dashArray.map((t=>t*this.scale.x)).join(" ")),e.dashOffset&&t.setAttribute("stroke-dashoffset",""+e.dashOffset*this.scale.x))}_x(t){return this.offset.x+this.scale.x*t}_y(t){return this.offset.y+this.scale.y*t}line(t,e,s,i,r){const n=this.makeLineNode(t,e,s,i,r);return this._bindFillDraw(n,"line",s,i||1,r)}arrow(t,e,s,i,r=8,n){const a=this.makeNode("g"),h={x:0,y:0},o=this.makeArrowHeadNode(t,e,s,i,r,void 0,h),l=this.makeLineNode(t,h,s,i,n);return a.appendChild(l),a.appendChild(o),this._addCSSClasses(a,"linear-arrow"),this._bindNode(a,void 0),a}cubicBezierArrow(t,e,s,i,r,n,a=8,o){const l=this.makeNode("g"),c=new h(0,0),d=this.makeArrowHeadNode(i,e,r,n,a,void 0,c),u=c.difference(e),g=this.makeCubicBezierNode(t,{x:e.x-u.x,y:e.y-u.y},s,{x:i.x-u.x,y:i.y-u.y},r,n,o);return l.appendChild(g),l.appendChild(d),this._addCSSClasses(l,"cubicbezier-arrow"),this._bindNode(l,void 0),l}arrowHead(t,e,s,i,r=8,n){const a=this.makeArrowHeadNode(t,e,s,i,r,n);return this._bindFillDraw(a,"arrowhead",s,i||1,n)}image(t,e,s,i=1){const r=this.makeNode("image"),n=t=>{if(t.naturalWidth){const n=s.x/t.naturalWidth,a=s.y/t.naturalHeight;r.setAttribute("width",""+t.naturalWidth*this.scale.x),r.setAttribute("height",""+t.naturalHeight*this.scale.y),r.setAttribute("display",null),r.setAttribute("opacity",`${i}`),r.setAttribute("transform",`translate(${this._x(e.x)} ${this._y(e.y)}) scale(${n} ${a})`)}};return t.addEventListener("load",(e=>{n(t)})),r.setAttribute("x","0"),r.setAttribute("y","0"),r.setAttribute("display","none"),n(t),r.setAttribute("href",t.src),this._bindFillDraw(r,"image",null,null)}texturedPoly(t,s,i,r,n){const a=new h(s.min).clone().rotate(n,r),o=this.makeNode("clipPath"),l=`clippath_${e.next()}`;o.setAttribute("id",l);const c=this.makeNode("g"),d=this.makeNode("image");d.setAttribute("x",`${this._x(a.x)}`),d.setAttribute("y",`${this._y(a.y)}`),d.setAttribute("width",`${s.width}`),d.setAttribute("height",`${s.height}`),d.setAttribute("href",t.src),d.setAttribute("transform",`rotate(${n*v}, ${this._x(a.x)}, ${this._y(a.y)})`);const u=this.makeNode("path"),g=[];if(i.vertices.length>0){g.push("M",`${this._x(i.vertices[0].x)}`,`${this._y(i.vertices[0].y)}`);for(var f=1;f<i.vertices.length;f++)g.push("L",`${this._x(i.vertices[f].x)}`,`${this._y(i.vertices[f].y)}`)}u.setAttribute("d",g.join(" ")),o.appendChild(u),this.bufferedNodeDefs.appendChild(o),c.appendChild(d),c.setAttribute("transform-origin",`${this._x(a.x)} ${this._y(a.y)}`),c.setAttribute("transform",`scale(${this.scale.x}, ${this.scale.y})`);const x=this.makeNode("g");return x.appendChild(c),x.setAttribute("clip-path",`url(#${l})`),this._bindFillDraw(x,"image",null,null),x}cubicBezier(t,e,s,i,r,n,a){const h=this.makeCubicBezierNode(t,e,s,i,r,n,a);return this._bindNode(h,void 0)}cubicBezierPath(t,e,s,i){const r=this.makeNode("path");if(this.applyStrokeOpts(r,i),!t||0==t.length)return r;const n=["M",this._x(t[0].x),this._y(t[0].y)];for(var a,h,o,l=1;l<t.length;l+=3)h=t[l],o=t[l+1],a=t[l+2],n.push("C",this._x(h.x),this._y(h.y),this._x(o.x),this._y(o.y),this._x(a.x),this._y(a.y));return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"cubicBezierPath",e,s||1)}handle(t,e){this.point(t,"rgb(0,32,192)"),this.square(e,5,"rgba(0,128,192,0.5)")}handleLine(t,e){this.line(t,e,"rgb(128,128,128,0.5)")}dot(t,e){const s=this.makeNode("line");return s.setAttribute("x1",`${this._x(t.x)}`),s.setAttribute("y1",`${this._y(t.y)}`),s.setAttribute("x2",`${this._x(t.x)}`),s.setAttribute("y2",`${this._y(t.y)}`),this._bindFillDraw(s,"dot",e,1)}point(t,e){const s=this.makeNode("circle");return s.setAttribute("cx",`${this._x(t.x)}`),s.setAttribute("cy",`${this._y(t.y)}`),s.setAttribute("r","3"),this._bindFillDraw(s,"point",e,1)}circle(t,e,s,i,r){const n=this.makeNode("circle");return this.applyStrokeOpts(n,r),n.setAttribute("cx",`${this._x(t.x)}`),n.setAttribute("cy",`${this._y(t.y)}`),n.setAttribute("r",""+e*this.scale.x),this._bindFillDraw(n,"circle",s,i||1)}circleArc(t,e,s,i,r,n,a){const h=this.makeNode("path");this.applyStrokeOpts(h,a);const o=f.circleSectorUtils.describeSVGArc(this._x(t.x),this._y(t.y),e*this.scale.x,s,i);return h.setAttribute("d",o.join(" ")),this._bindFillDraw(h,"circleArc",r,n||1)}ellipse(t,e,s,i,r,n,a){void 0===n&&(n=0);const h=this.makeNode("ellipse");return this.applyStrokeOpts(h,a),h.setAttribute("cx",`${this._x(t.x)}`),h.setAttribute("cy",`${this._y(t.y)}`),h.setAttribute("rx",""+e*this.scale.x),h.setAttribute("ry",""+s*this.scale.y),h.setAttribute("transform",`rotate(${180*n/Math.PI} ${this._x(t.x)} ${this._y(t.y)})`),this._bindFillDraw(h,"ellipse",i,r||1)}square(t,e,s,i,r){const n=this.makeNode("rectangle");return this.applyStrokeOpts(n,r),n.setAttribute("x",`${this._x(t.x-e/2)}`),n.setAttribute("y",`${this._y(t.y-e/2)}`),n.setAttribute("width",""+e*this.scale.x),n.setAttribute("height",""+e*this.scale.y),this._bindFillDraw(n,"square",s,i||1)}rect(t,e,s,i,r,n){const a=this.makeNode("rect");return this.applyStrokeOpts(a,n),a.setAttribute("x",`${this._x(t.x)}`),a.setAttribute("y",`${this._y(t.y)}`),a.setAttribute("width",""+e*this.scale.x),a.setAttribute("height",""+s*this.scale.y),this._bindFillDraw(a,"rect",i,r||1)}grid(t,e,s,i,r,n){const a=this.makeNode("path"),h=[];for(var o=-Math.ceil(.5*s/r)*r,l=s/2,c=-Math.ceil(.5*e/i)*i;c<e/2;c+=i)h.push("M",this._x(t.x+c),this._y(t.y+o)),h.push("L",this._x(t.x+c),this._y(t.y+l));for(var d=-Math.ceil(.5*e/i)*i,u=e/2,g=-Math.ceil(.5*s/r)*r;g<s/2;g+=r)h.push("M",this._x(t.x+d),this._y(t.y+g)),h.push("L",this._x(t.x+u),this._y(t.y+g));return a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"grid",n,1)}raster(t,e,s,i,r,n){const a=this.makeNode("path"),h=[];for(var o=-Math.ceil(.5*e/i)*i;o<e/2;o+=i)for(var l=-Math.ceil(.5*s/r)*r;l<s/2;l+=r)h.push("M",this._x(t.x+o)-4,this._y(t.y+l)),h.push("L",this._x(t.x+o)+4,this._y(t.y+l)),h.push("M",this._x(t.x+o),this._y(t.y+l)-4),h.push("L",this._x(t.x+o),this._y(t.y+l)+4);return a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"raster",n,1)}diamondHandle(t,e,s){const i=this.makeNode("path"),r=["M",this._x(t.x)-e/2,this._y(t.y),"L",this._x(t.x),this._y(t.y)-e/2,"L",this._x(t.x)+e/2,this._y(t.y),"L",this._x(t.x),this._y(t.y)+e/2,"Z"];return i.setAttribute("d",r.join(" ")),this._bindFillDraw(i,"diamondHandle",s,1)}squareHandle(t,e,s){const i=this.makeNode("rect");return i.setAttribute("x",""+(this._x(t.x)-e/2)),i.setAttribute("y",""+(this._y(t.y)-e/2)),i.setAttribute("width",`${e}`),i.setAttribute("height",`${e}`),this._bindFillDraw(i,"squareHandle",s,1)}circleHandle(t,e,s){e=e||3;const i=this.makeNode("circle");return i.setAttribute("cx",`${this._x(t.x)}`),i.setAttribute("cy",`${this._y(t.y)}`),i.setAttribute("r",`${e}`),this._bindFillDraw(i,"circleHandle",s,1)}crosshair(t,e,s,i){const r=this.makeNode("path"),n=["M",this._x(t.x)-e,this._y(t.y),"L",this._x(t.x)+e,this._y(t.y),"M",this._x(t.x),this._y(t.y)-e,"L",this._x(t.x),this._y(t.y)+e];return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"crosshair",s,i||.5)}cross(t,e,s,i){const r=this.makeNode("path"),n=["M",this._x(t.x)-e,this._y(t.y)-e,"L",this._x(t.x)+e,this._y(t.y)+e,"M",this._x(t.x)-e,this._y(t.y)+e,"L",this._x(t.x)+e,this._y(t.y)-e];return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"cross",s,i||1)}polygon(t,e,s){return this.polyline(t.vertices,t.isOpen,e,s)}polyline(t,e,s,i,r){const n=this.makeNode("path");if(this.applyStrokeOpts(n,r),0==t.length)return n;const a=["M",this._x(t[0].x),this._y(t[0].y)];for(var h=t.length,o=1;o<h;o++)a.push("L",this._x(t[o].x),this._y(t[o].y));return e||a.push("Z"),n.setAttribute("d",a.join(" ")),this._bindFillDraw(n,"polygon",s,i||1)}text(t,e,s,i){var r,n,a;const h=(i=i||{}).color||"black",o=(null!==(n=null!==(r=i.lineHeight)&&void 0!==r?r:i.fontSize)&&void 0!==n?n:0)*this.scale.x,l="left"===i.textAlign||"start"===i.textAlign?"start":"center"===i.textAlign?"middle":"right"===i.textAlign||"end"===i.textAlign?"end":"start",c=`${this._x(e)}px ${this._y(s)}px`,d=`translate(${this._x(e)} ${this._y(s)+o/2})`,u=i.rotation?`rotate(${i.rotation*v} 0 0)`:"",g=this.makeNode("g"),f=this.curId;this.curId=f+"_text";const x=this.makeNode("text");return g.appendChild(x),x.setAttribute("font-family",null!==(a=i.fontFamily)&&void 0!==a?a:""),x.setAttribute("font-size",i.fontSize?""+i.fontSize*this.scale.x:""),x.setAttribute("font-style",i.fontStyle?`${i.fontStyle}`:""),x.setAttribute("font-weight",i.fontWeight?`${i.fontWeight}`:""),x.setAttribute("text-anchor",l),x.setAttribute("transform-origin","0 0"),x.setAttribute("transform",u),g.setAttribute("transform-origin",c),g.setAttribute("transform",d),x.innerHTML=t,this.curId=f,this._bindFillDraw(g,"text",h,1)}label(t,e,s,i,r){const n=this.makeNode("text");return n.setAttribute("transform",`translate(${e},${s}), rotate(${(i||0)/Math.PI*180})`),n.setAttribute("font-family","Arial"),n.setAttribute("font-size","9pt"),n.setAttribute("font-style","normal"),n.setAttribute("font-weight","lighter"),n.innerHTML=t,this._bindFillDraw(n,"label",r||"black",null)}path(t,e,s,i){const r=this.makeNode("path");this.applyStrokeOpts(r,i);const n=i&&i.inplace?t:x.copyPathData(t);return x.transformPathData(n,this.offset,this.scale),r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"path",e,s)}clear(t){if(this.isSecondary)return;this.curId="background",this.curClassName=null;const e=this.makeNode("rect");e.setAttribute("x","0"),e.setAttribute("y","0"),e.setAttribute("width",`${this.canvasSize.width}`),e.setAttribute("height",`${this.canvasSize.height}`),this._bindFillDraw(e,this.curId,null,null),e.setAttribute("fill",void 0===t?"none":t),this.curId=null}removeAllChildNodes(){for(;this.bufferGNode.lastChild;)this.bufferGNode.removeChild(this.bufferGNode.lastChild);for(;this.bufferedNodeDefs.lastChild;)this.bufferedNodeDefs.removeChild(this.bufferedNodeDefs.lastChild)}static createSvg(){return document.createElementNS("http://www.w3.org/2000/svg","svg")}static copyPathData(t){const e=new Array(t.length);for(var s=0,i=t.length;s<i;s++)e[s]=t[s];return e}static transformPathData(t,e,s){const i=i=>{t[i]=e.x+s.x*Number(t[i])},r=i=>{t[i]=e.y+s.y*Number(t[i])},n=e=>{t[e]=s.x*Number(t[e])},a=e=>{t[e]=s.y*Number(t[e])};for(var h=0,o=e=>{Number(t[e]),Number(t[e+1])};h<t.length;){switch(t[h]){case"M":case"L":case"T":i(h+1),r(h+2),o(h+1),h+=3;break;case"m":case"l":case"t":n(h+1),a(h+2),o(h+1),h+=3;break;case"H":i(h+1),Number(t[h+1]),h+=2;break;case"h":n(h+1),Number(t[h+1]),h+=2;break;case"V":r(h+1),Number(t[h+1]),h+=2;break;case"v":a(h+1),Number(t[h+1]),h+=2;break;case"C":i(h+1),r(h+2),i(h+3),r(h+4),i(h+5),r(h+6),o(h+5),h+=7;break;case"c":n(h+1),a(h+2),n(h+3),a(h+4),n(h+5),a(h+6),o(h+5),h+=7;break;case"S":case"Q":i(h+1),r(h+2),i(h+3),r(h+4),o(h+3),h+=5;break;case"s":case"q":n(h+1),a(h+2),n(h+3),a(h+4),o(h+3),h+=5;break;case"A":n(h+1),a(h+2),i(h+6),r(h+7),o(h+6),(s.x<0&&s.y>=0||s.x>=0&&s.y<0)&&(t[h+5]=t[h+5]?0:1),h+=8;break;case"a":n(h+1),a(h+2),n(h+6),a(h+7),o(h+6),h+=8;break;default:h++}}}static nodeSupportsLineDash(t){return["line","path","circle","ellipse","rectangle","rect"].includes(t)}makeLineNode(t,e,s,i,r,n){const a=this.makeNode("line");return a.setAttribute("x1",`${this._x(t.x)}`),a.setAttribute("y1",`${this._y(t.y)}`),a.setAttribute("x2",`${this._x(e.x)}`),a.setAttribute("y2",`${this._y(e.y)}`),this._configureNode(a,null!=n?n:"line",this.fillShapes,s,i||1,r),a}makePathNode(t,e,s,i,r){const n=this.makeNode("path");return n.setAttribute("d",t),this._configureNode(n,null!=r?r:"path",this.fillShapes,e,s||1,i),n}makeArrowHeadNode(t,e,s,r,n=8,a,h){var o=i.utils.buildArrowHead(t,e,n,this.scale.x,this.scale.y);const l=["M",this.offset.x+o[0].x,this.offset.y+o[0].y];h&&(h.x=o[0].x/this.scale.x,h.y=o[0].y/this.scale.y);for(var c=1;c<=o.length;c++)l.push("L"),l.push(this.offset.x+o[c%o.length].x),l.push(this.offset.y+o[c%o.length].y);return this.makePathNode(l.join(" "),s,r,a,"arrowhead")}makeCubicBezierNode(t,e,s,i,r,n,a){if(t instanceof u)return this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n);const h=["M",this._x(t.x),this._y(t.y),"C",this._x(s.x),this._y(s.y),this._x(i.x),this._y(i.y),this._x(e.x),this._y(e.y)];return this.makePathNode(h.join(" "),r,n,a,"cubicBezier")}}x.HEAD_XML=['<?xml version="1.0" encoding="UTF-8" standalone="no"?>','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" ',' "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',""].join("\n");class y{constructor(t,e){this.ctx=t,this.offset=new h(0,0),this.scale=new h(1,1),this.fillShapes=e}applyStrokeOpts(t){var e,s;this.ctx.setLineDash((null!==(e=null==t?void 0:t.dashArray)&&void 0!==e?e:[]).map((t=>t*this.scale.x))),this.ctx.lineDashOffset=(null!==(s=null==t?void 0:t.dashOffset)&&void 0!==s?s:0)*this.scale.x}_fillOrDraw(t){this.fillShapes?(this.ctx.fillStyle=t,this.ctx.fill()):(this.ctx.strokeStyle=t,this.ctx.stroke())}beginDrawCycle(t){}endDrawCycle(t){}setConfiguration(t){this.ctx.globalCompositeOperation=t.blendMode||"source-over"}setCurrentId(t){}setCurrentClassName(t){}line(t,e,s,i,r){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(r),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y),this.ctx.strokeStyle=s,this.ctx.lineWidth=i||1,this.ctx.stroke(),this.ctx.restore()}arrow(t,e,s,i,r=8,n){const a=new h(0,0);this.arrowHead(t,e,s,i,r,void 0,a),this.line(t,a,s,i,n)}cubicBezierArrow(t,e,s,i,r,n,a,o){const l=new h(0,0);this.arrowHead(i,e,r,n,a,void 0,l);const c=l.difference(e);this.cubicBezier(t,{x:e.x-c.x,y:e.y-c.y},s,{x:i.x-c.x,y:i.y-c.y},r,n,o)}arrowHead(t,e,s,r,n=8,a,h){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(a);var o=i.utils.buildArrowHead(t,e,n,this.scale.x,this.scale.y);h&&(h.x=o[0].x/this.scale.x,h.y=o[0].y/this.scale.y),this.ctx.moveTo(this.offset.x+o[0].x,this.offset.y+o[0].y);for(var l=0;l<o.length;l++)this.ctx.lineTo(this.offset.x+o[l].x,this.offset.y+o[l].y);this.ctx.lineTo(this.offset.x+o[0].x,this.offset.y+o[0].y),this.ctx.lineWidth=r||1,this._fillOrDraw(s),this.ctx.restore()}image(t,e,s,i=1){t.complete&&t.naturalWidth&&(this.ctx.save(),this.ctx.globalAlpha=i,this.ctx.drawImage(t,0,0,t.naturalWidth-1,t.naturalHeight-1,this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y,s.x*this.scale.x,s.y*this.scale.y),this.ctx.restore())}texturedPoly(t,e,s,i,r){var n=s.getBounds();new h(i.x,i.y).difference(n.getCenter());var a=new h(e.width,e.height),o=new h(e.min.x,e.min.y).sub(i);this.ctx.save(),this.ctx.translate(this.offset.x+i.x*this.scale.x,this.offset.y+i.y*this.scale.y),y.helpers.clipPoly(this.ctx,{x:-i.x*this.scale.x,y:-i.y*this.scale.y},this.scale,s.vertices),this.ctx.scale(this.scale.x,this.scale.y),this.ctx.rotate(r),this.ctx.drawImage(t,0,0,t.naturalWidth-1,t.naturalHeight-1,o.x,o.y,a.x,a.y),this.ctx.restore()}rect(t,e,s,i,r,n){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(n),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+e)*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+e)*this.scale.x,this.offset.y+(t.y+s)*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+(t.y+s)*this.scale.y),this.ctx.closePath(),this.ctx.lineWidth=r||1,this._fillOrDraw(i),this.ctx.restore()}cubicBezier(t,e,s,i,r,n,a){t instanceof u?this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n):(this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(a),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.bezierCurveTo(this.offset.x+s.x*this.scale.x,this.offset.y+s.y*this.scale.y,this.offset.x+i.x*this.scale.x,this.offset.y+i.y*this.scale.y,this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y),this.ctx.lineWidth=n||2,this._fillOrDraw(r),this.ctx.restore())}quadraticBezier(t,e,s,i,r,n){this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(n),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y),this.ctx.quadraticCurveTo(this.offset.x+e.x*this.scale.x,this.offset.y+e.y*this.scale.y,this.offset.x+s.x*this.scale.x,this.offset.y+s.y*this.scale.y),this.ctx.lineWidth=r||2,this._fillOrDraw(i),this.ctx.restore()}cubicBezierPath(t,e,s,i){if(t&&0!=t.length){var r,n,a;this.ctx.save(),this.ctx.beginPath(),this.applyStrokeOpts(i),this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var h=1;h<t.length;h+=3)n=t[h],a=t[h+1],r=t[h+2],this.ctx.bezierCurveTo(this.offset.x+n.x*this.scale.x,this.offset.y+n.y*this.scale.y,this.offset.x+a.x*this.scale.x,this.offset.y+a.y*this.scale.y,this.offset.x+r.x*this.scale.x,this.offset.y+r.y*this.scale.y);this.ctx.closePath(),this.ctx.lineWidth=s||1,this._fillOrDraw(e),this.ctx.restore()}}handle(t,e){this.point(t,"rgb(0,32,192)"),this.square(e,5,"rgba(0,128,192,0.5)")}handleLine(t,e){this.line(t,e,"rgba(128,128,128, 0.5)",void 0)}dot(t,e){this.ctx.save(),this.ctx.beginPath(),this.ctx.setLineDash([]),this.ctx.moveTo(Math.round(this.offset.x+this.scale.x*t.x),Math.round(this.offset.y+this.scale.y*t.y)),this.ctx.lineTo(Math.round(this.offset.x+this.scale.x*t.x+1),Math.round(this.offset.y+this.scale.y*t.y+1)),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(e),this.ctx.restore()}point(t,e){this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.arc(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,3,0,2*Math.PI,!1),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(e)}circle(t,e,s,i,r){this.applyStrokeOpts(r),this.ctx.beginPath(),this.ctx.ellipse(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e*this.scale.x,e*this.scale.y,0,0,2*Math.PI),this.ctx.closePath(),this.ctx.lineWidth=i||1,this._fillOrDraw(s)}circleArc(t,e,s,i,r,n,a){a&&a.asSegment||this.ctx.beginPath(),this.applyStrokeOpts(a),this.ctx.ellipse(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e*this.scale.x,e*this.scale.y,0,s,i,!1),a&&a.asSegment||(this.ctx.lineWidth=n||1,this._fillOrDraw(r||"#000000"))}ellipse(t,e,s,i,r,n,a){void 0===n&&(n=0),this.applyStrokeOpts(a),this.ctx.beginPath(),this.ctx.ellipse(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e*this.scale.x,s*this.scale.y,n,0,2*Math.PI),this.ctx.closePath(),this.ctx.lineWidth=r||1,this._fillOrDraw(i)}square(t,e,s,i,r){this.applyStrokeOpts(r),this.ctx.beginPath(),this.ctx.rect(this.offset.x+(t.x-e/2)*this.scale.x,this.offset.y+(t.y-e/2)*this.scale.y,e*this.scale.x,e*this.scale.y),this.ctx.closePath(),this.ctx.lineWidth=i||1,this._fillOrDraw(s)}grid(t,e,s,i,r,n){this.ctx.setLineDash([]),this.ctx.beginPath();for(var a=-Math.ceil(.5*s/r)*r,h=s/2,o=-Math.ceil(.5*e/i)*i;o<e/2;o+=i)this.ctx.moveTo(this.offset.x+(t.x+o)*this.scale.x,this.offset.y+(t.y+a)*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+o)*this.scale.x,this.offset.y+(t.y+h)*this.scale.y);for(var l=-Math.ceil(.5*e/i)*i,c=e/2,d=-Math.ceil(.5*s/r)*r;d<s/2;d+=r)this.ctx.moveTo(this.offset.x+(t.x+l)*this.scale.x-4,this.offset.y+(t.y+d)*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+c)*this.scale.x+4,this.offset.y+(t.y+d)*this.scale.y);this.ctx.strokeStyle=n,this.ctx.lineWidth=1,this.ctx.stroke(),this.ctx.closePath()}raster(t,e,s,i,r,n){this.ctx.save(),this.ctx.setLineDash([]),this.ctx.beginPath();for(var a=-Math.ceil(.5*e/i)*i;a<e/2;a+=i)for(var h=-Math.ceil(.5*s/r)*r;h<s/2;h+=r)this.ctx.moveTo(this.offset.x+(t.x+a)*this.scale.x-4,this.offset.y+(t.y+h)*this.scale.y),this.ctx.lineTo(this.offset.x+(t.x+a)*this.scale.x+4,this.offset.y+(t.y+h)*this.scale.y),this.ctx.moveTo(this.offset.x+(t.x+a)*this.scale.x,this.offset.y+(t.y+h)*this.scale.y-4),this.ctx.lineTo(this.offset.x+(t.x+a)*this.scale.x,this.offset.y+(t.y+h)*this.scale.y+4);this.ctx.strokeStyle=n,this.ctx.lineWidth=1,this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}diamondHandle(t,e,s){this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e/2,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y-e/2),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e/2,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y+e/2),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(s)}squareHandle(t,e,s){this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.rect(this.offset.x+t.x*this.scale.x-e/2,this.offset.y+t.y*this.scale.y-e/2,e,e),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(s)}circleHandle(t,e,s){e=e||3,this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.arc(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y,e,0,2*Math.PI,!1),this.ctx.closePath(),this.ctx.lineWidth=1,this._fillOrDraw(s)}crosshair(t,e,s,i){this.ctx.save(),this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e,this.offset.y+t.y*this.scale.y),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e,this.offset.y+t.y*this.scale.y),this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y-e),this.ctx.lineTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y+e),this.ctx.strokeStyle=s,this.ctx.lineWidth=i||.5,this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}cross(t,e,s,i){this.ctx.save(),this.ctx.setLineDash([]),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e,this.offset.y+t.y*this.scale.y-e),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e,this.offset.y+t.y*this.scale.y+e),this.ctx.moveTo(this.offset.x+t.x*this.scale.x-e,this.offset.y+t.y*this.scale.y+e),this.ctx.lineTo(this.offset.x+t.x*this.scale.x+e,this.offset.y+t.y*this.scale.y-e),this.ctx.strokeStyle=s,this.ctx.lineWidth=i||1,this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()}polygon(t,e,s,i){this.polyline(t.vertices,t.isOpen,e,s,i)}polyline(t,e,s,i,r){if(!(t.length<=1)){this.ctx.save(),this.applyStrokeOpts(r),this.ctx.beginPath(),this.ctx.lineWidth=i||1,this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var n=0;n<t.length;n++)this.ctx.lineTo(this.offset.x+t[n].x*this.scale.x,this.offset.y+t[n].y*this.scale.y);e||this.ctx.closePath(),this._fillOrDraw(s),this.ctx.closePath(),this.ctx.setLineDash([]),this.ctx.restore()}}text(t,e,s,i){var r,n,a;i=i||{},this.ctx.save();let h=this.offset.x+e*this.scale.x,o=this.offset.y+s*this.scale.y;const l=i.color||"black";(i.fontSize||i.fontFamily)&&(this.ctx.font=(i.fontWeight?i.fontWeight+" ":"")+(i.fontStyle?i.fontStyle+" ":"")+(i.fontSize?i.fontSize*this.scale.x+"px ":" ")+(i.fontFamily?-1===i.fontFamily.indexOf(" ")?i.fontFamily:`"${i.fontFamily}"`:"Arial")),i.textAlign&&(this.ctx.textAlign=i.textAlign);const c=null!==(r=i.rotation)&&void 0!==r?r:0,d=(null!==(a=null!==(n=i.lineHeight)&&void 0!==n?n:i.fontSize)&&void 0!==a?a:0)*this.scale.x;this.ctx.translate(h,o),this.ctx.rotate(c),this.fillShapes?(this.ctx.fillStyle=l,this.ctx.fillText(t,0,d/2)):(this.ctx.strokeStyle=l,this.ctx.strokeText(t,0,d/2)),this.ctx.restore()}label(t,e,s,i,r){this.ctx.save(),this.ctx.font="lighter 9pt Arial",this.ctx.translate(e,s),void 0!==i&&this.ctx.rotate(i),this.ctx.fillStyle=r||"black",this.fillShapes?this.ctx.fillText(t,0,0):this.ctx.strokeText(t,0,0),this.ctx.restore()}path(t,e,s,i){const r=i&&i.inplace?t:x.copyPathData(t);x.transformPathData(r,this.offset,this.scale),e&&(this.ctx.strokeStyle=e),this.ctx.lineWidth=s||1,this.applyStrokeOpts(i),this.fillShapes?(e&&(this.ctx.fillStyle=e),this.ctx.fill(new Path2D(r.join(" ")))):(e&&(this.ctx.strokeStyle=e),this.ctx.stroke(new Path2D(r.join(" "))))}clear(t){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.fillStyle=t,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}}y.helpers={clipPoly:(t,e,s,i)=>{t.beginPath(),t.moveTo(e.x+i[0].x*s.x,e.y+i[0].y*s.y);for(var r=1;r<i.length;r++){const n=i[r];t.lineTo(e.x+n.x*s.x,e.y+n.y*s.y)}t.closePath(),t.clip()}};class p{constructor(t,e){this.gl=t,this.offset=new h(0,0),this.scale=new h(1,1),this.fillShapes=e,this._zindex=0,null!=t&&void 0!==t&&(this.glutils=new m(t),this._vertShader=this.glutils.compileShader(p.vertCode,this.gl.VERTEX_SHADER),this._fragShader=this.glutils.compileShader(p.fragCode,this.gl.FRAGMENT_SHADER),this._program=this.glutils.makeProgram(this._vertShader,this._fragShader),this.vertex_buffer=this.gl.createBuffer(),console.log("gl initialized"))}_x2rel(t){return(this.scale.x*t+this.offset.x)/this.gl.canvas.width*2-1}_y2rel(t){return(this.offset.y-this.scale.y*t)/this.gl.canvas.height*2-1}copyInstance(t){var e=new p(null,t);return e.gl=this.gl,e.glutils=this.glutils,e._vertShader=this._vertShader,e._fragShader=this._fragShader,e._program=this._program,e}beginDrawCycle(t){this._zindex=0,this.renderTime=t}endDrawCycle(t){}setConfiguration(t){}setCurrentId(t){this.curId=t}setCurrentClassName(t){}line(t,e,s){const i=new Float32Array(6);i[0]=this._x2rel(t.x),i[1]=this._y2rel(t.y),i[2]=this._zindex,i[3]=this._x2rel(e.x),i[4]=this._y2rel(e.y),i[5]=this._zindex,this._zindex+=.001,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertex_buffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,i,this.gl.STATIC_DRAW);var r=this.gl.getAttribLocation(this._program,"position");this.gl.vertexAttribPointer(r,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(r),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);let n=this.gl.getUniformLocation(this._program,"uRotationVector");this.gl.uniform2fv(n,[0,1]),this.gl.lineWidth(5),this.gl.drawArrays(this.gl.LINES,0,i.length/3)}arrow(t,e,s){}cubicBezierArrow(t,e,s,i,r,n,a){}arrowHead(t,e,s,i,r){}image(t,e,s,i=0){}texturedPoly(t,e,s,i,r){}_fillOrDraw(t){}cubicBezier(t,e,s,i,r,n){}cubicBezierPath(t,e,s){}handle(t,e){}handleLine(t,e){}dot(t,e){}point(t,e){}circle(t,e,s,i){}circleArc(t,e,s,i,r,n){}ellipse(t,e,s,i,r,n){}square(t,e,s,i){}rect(t,e,s,i,r){}grid(t,e,s,i,r,n){}raster(t,e,s,i,r,n){}diamondHandle(t,e,s){}squareHandle(t,e,s){}circleHandle(t,e,s){}crosshair(t,e,s,i){}cross(t,e,s,i){}polygon(t,e,s){const i=new Float32Array(3*t.vertices.length);for(var r=0;r<t.vertices.length;r++)i[3*r+0]=this._x2rel(t.vertices[r].x),i[3*r+1]=this._y2rel(t.vertices[r].y),i[3*r+2]=this._zindex;this._zindex+=.001,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertex_buffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,i,this.gl.STATIC_DRAW);var n=this.gl.getAttribLocation(this._program,"position");this.gl.vertexAttribPointer(n,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(n),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);let a=this.gl.getUniformLocation(this._program,"uRotationVector");this.gl.uniform2fv(a,[0,1]),this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,i.length/3)}polyline(t,e,s,i){}text(t,e,s,i){}label(t,e,s,i,r){}path(t,e,s,i){}clear(t){this.gl.clearColor(1,1,1,1),this.gl.enable(this.gl.DEPTH_TEST),this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT)}}p.vertCode="\n precision mediump float;\n\n attribute vec3 position;\n\n uniform vec2 uRotationVector;\n\n void main(void) {\n\tvec2 rotatedPosition = vec2(\n\t position.x * uRotationVector.y +\n\t\tposition.y * uRotationVector.x,\n\t position.y * uRotationVector.y -\n\t\tposition.x * uRotationVector.x\n\t);\n\n\tgl_Position = vec4(rotatedPosition, position.z, 1.0);\n }",p.fragCode="\n precision highp float;\n\n void main(void) {\n\tgl_FragColor = vec4(0.0,0.75,1.0,1.0);\n }";class m{constructor(t){this.gl=t}bufferData(t){var e=this.gl.createBuffer();return this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e),this.gl.bufferData(this.gl.ARRAY_BUFFER,t,this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),e}compileShader(t,e){var s=this.gl.createShader(e);this.gl.shaderSource(s,t),this.gl.compileShader(s);return this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)?s:(console.warn("Error in shader:"+this.gl.getShaderInfoLog(s)),this.gl.deleteShader(s),null)}makeProgram(t,e){var s=this.gl.createProgram();return this.gl.attachShader(s,t),this.gl.attachShader(s,e),this.gl.linkProgram(s),this.gl.useProgram(s),this.gl.detachShader(s,t),this.gl.detachShader(s,e),this.gl.deleteShader(t),this.gl.deleteShader(e),s}}class b{constructor(t,e){this.center=t,this.size=e}}b.utils={baseLog:(t,e)=>Math.log(t)/Math.log(e),mapRasterScale:(t,e)=>{var s=1;return e>=1?(s=Math.abs(Math.floor(1/b.utils.baseLog(t,e))),s=1/Math.pow(t,s)):s=Math.abs(Math.floor(b.utils.baseLog(1/t,1/(e+1)))),s}};class w{constructor(t){this.downListeners=[],this.pressListeners=[],this.upListeners=[],this.keyStates={},t=t||{},this.element=t.element?t.element:globalThis,this.downListeners=[],this.pressListeners=[],this.upListeners=[],this.keyStates=[],this.trackAllKeys=t.trackAll||!1,this.installListeners()}fireEvent(t,e){let s=!1;for(var i in e){var r=e[i];r.keyCode==t.keyCode&&(r.listener(t),s=!0)}return s}fireDownEvent(t,e){(e.fireEvent(t,e.downListeners)||e.trackAllKeys)&&(e.keyStates[t.keyCode]="down")}firePressEvent(t,e){e.fireEvent(t,e.pressListeners)}fireUpEvent(t,e){(e.fireEvent(t,e.upListeners)||e.trackAllKeys)&&delete e.keyStates[t.keyCode]}static key2code(t){if("number"==typeof t)return t;if("string"!=typeof t)throw"Unknown key name or key type (should be a string or integer): "+t;if(w.KEY_CODES[t])return w.KEY_CODES[t];throw"Unknown key (cannot resolve key code): "+t}installListeners(){var t=this;this.element.addEventListener("keydown",this._keyDownListener=e=>{t.fireDownEvent(e,t)}),this.element.addEventListener("keypress",this._keyPressListener=e=>{t.firePressEvent(e,t)}),this.element.addEventListener("keyup",this._keyUpListener=e=>{t.fireUpEvent(e,t)})}releaseListeners(){this.element.removeEventListener("keydown",this._keyDownListener),this.element.removeEventListener("keypress",this._keyPressListener),this.element.removeEventListener("keyup",this._keyUpListener)}down(t,e){return this.downListeners.push({key:t,keyCode:w.key2code(t),listener:e}),this}press(t,e){return this.pressListeners.push({key:t,keyCode:w.key2code(t),listener:e}),this}up(t,e){return this.upListeners.push({key:t,keyCode:w.key2code(t),listener:e}),this}isDown(t){return"number"==typeof t?!!this.keyStates[t]:!!this.keyStates[w.key2code(t)]}destroy(){this.releaseListeners()}}w.KEY_CODES={break:3,backspace:8,tab:9,clear:12,enter:13,shift:16,ctrl:17,alt:18,pause:19,capslock:20,hangul:21,hanja:25,escape:27,conversion:28,"non-conversion":29,spacebar:32,pageup:33,pagedown:34,end:35,home:36,leftarrow:37,uparrow:38,rightarrow:39,downarrow:40,select:41,print:42,execute:43,printscreen:44,insert:45,delete:46,help:47,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,":":58,"semicolon (firefox)":59,equals:59,"<":60,"equals (firefox)":61,"ß":63,"@ (firefox)":64,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,windows:91,leftcommand:91,chromebooksearch:91,rightwindowkey:92,windowsmenu:93,rightcommant:93,sleep:95,numpad0:96,numpad1:97,numpad2:98,numpad3:99,numpad4:100,numpad5:101,numpad6:102,numpad7:103,numpad8:104,numpad9:105,multiply:106,add:107,numpadperiod:108,subtract:109,decimalpoint:110,divide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,f13:124,f14:125,f15:126,f16:127,f17:128,f18:129,f19:130,f20:131,f21:132,f22:133,f23:134,f24:135,numlock:144,scrolllock:145,"^":160,"!":161,"#":163,$:164,"ù":165,pagebackward:166,pageforward:167,refresh:168,closingparen:169,"*":170,"~+*":171,minus:173,decreasevolumelevel:174,increasevolumelevel:175,next:176,previous:177,stop:178,"play/pause":179,email:180,mute:181,unmute:181,semicolon:186,"ñ":186,equal:187,comma:188,dash:189,period:190,forwardslash:191,"ç":191,"grave accent":192,"æ":192,"ö":192,"?":193,"/":193,"°":193,openbracket:219,backslash:220,closebracket:221,"å":221,singlequote:222,"ø":222,"ä":222,"`":223,altgr:225,"GNOME Compose Key":230,XF86Forward:233,XF86Back:234,alphanumeric:240,hiragana:242,katakana:242,"half-width":243,"full-width":243,kanji:244,unlocktrackpad:251,toggletouchpad:255};class C extends MouseEvent{}class P extends WheelEvent{}class A{constructor(t,e){this.mouseDownPos=void 0,this.mouseDragPos=void 0,this.mouseButton=-1,this.listeners={},this.installed={},this.handlers={},this.name=e,this.element=t,this.mouseDownPos=void 0,this.mouseDragPos=void 0,this.mouseButton=-1,this.listeners={},this.installed={},this.handlers={};const s=this;this.handlers.mousemove=t=>{s.listeners.mousemove&&s.listeners.mousemove(s.mkParams(t,"mousemove")),s.mouseDragPos&&s.listeners.drag&&s.listeners.drag(s.mkParams(t,"drag")),s.mouseDownPos&&(s.mouseDragPos=s.relPos(t))},this.handlers.mouseup=t=>{s.listeners.mouseup&&s.listeners.mouseup(s.mkParams(t,"mouseup")),s.mouseDragPos=void 0,s.mouseDownPos=void 0,s.mouseButton=-1},this.handlers.mousedown=t=>{s.mouseDragPos=s.relPos(t),s.mouseDownPos=s.relPos(t),s.mouseButton=t.button,s.listeners.mousedown&&s.listeners.mousedown(s.mkParams(t,"mousedown"))},this.handlers.click=t=>{s.listeners.click&&s.listeners.click(s.mkParams(t,"click"))},this.handlers.wheel=t=>{s.listeners.wheel&&s.listeners.wheel(s.mkParams(t,"wheel"))},this.element.addEventListener("mousemove",this.handlers.mousemove),this.element.addEventListener("mouseup",this.handlers.mouseup),this.element.addEventListener("mousedown",this.handlers.mousedown),this.element.addEventListener("click",this.handlers.click),this.element.addEventListener("wheel",this.handlers.wheel)}relPos(t){return{x:t.offsetX,y:t.offsetY}}mkParams(t,e){var s,i;const r=this.relPos(t),n=t;return n.params={element:this.element,name:e,isTouchEvent:!1,pos:r,button:t.button,leftButton:0===t.button,middleButton:1===t.button,rightButton:2===t.button,mouseDownPos:null!==(s=this.mouseDownPos)&&void 0!==s?s:{x:NaN,y:NaN},draggedFrom:null!==(i=this.mouseDragPos)&&void 0!==i?i:{x:NaN,y:NaN},wasDragged:null!=this.mouseDownPos&&(this.mouseDownPos.x!=r.x||this.mouseDownPos.y!=r.y),dragAmount:null!=this.mouseDragPos?{x:r.x-this.mouseDragPos.x,y:r.y-this.mouseDragPos.y}:{x:0,y:0}},n}listenFor(t){this.installed[t]||(this.installed[t]=!0)}unlistenFor(t){this.installed[t]&&delete this.installed[t]}drag(t){return this.listeners.drag&&this.throwAlreadyInstalled("drag"),this.listeners.drag=t,this.listenFor("mousedown"),this.listenFor("mousemove"),this.listenFor("mouseup"),this}move(t){return this.listeners.mousemove&&this.throwAlreadyInstalled("mousemove"),this.listenFor("mousemove"),this.listeners.mousemove=t,this}up(t){return this.listeners.mouseup&&this.throwAlreadyInstalled("mouseup"),this.listenFor("mouseup"),this.listeners.mouseup=t,this}down(t){return this.listeners.mousedown&&this.throwAlreadyInstalled("mousedown"),this.listenFor("mousedown"),this.listeners.mousedown=t,this}click(t){return this.listeners.click&&this.throwAlreadyInstalled("click"),this.listenFor("click"),this.listeners.click=t,this}wheel(t){return this.listeners.wheel&&this.throwAlreadyInstalled("wheel"),this.listenFor("wheel"),this.listeners.wheel=t,this}throwAlreadyInstalled(t){throw`This MouseHandler already has a '${t}' callback. To keep the code simple there is only room for one.`}destroy(){this.unlistenFor("mousedown"),this.unlistenFor("mousemove"),this.unlistenFor("moseup"),this.unlistenFor("click"),this.unlistenFor("wheel"),this.element.removeEventListener("mousemove",this.handlers.mousemove),this.element.removeEventListener("mouseup",this.handlers.mousedown),this.element.removeEventListener("mousedown",this.handlers.mousedown),this.element.removeEventListener("click",this.handlers.click),this.element.removeEventListener("wheel",this.handlers.wheel)}}class S{constructor(t,s,i){this.className="PBImage",this.uid=e.next(),this.image=t,this.upperLeft=s,this.lowerRight=i}destroy(){this.upperLeft.destroy(),this.lowerRight.destroy(),this.isDestroyed=!0}}class T{constructor(t,s,i){this.className="PBText",this.uid=e.next(),this.text=t,this.anchor=null!=s?s:new h,this.color=null==i?void 0:i.color,this.fontFamily=null==i?void 0:i.fontFamily,this.fontSize=null==i?void 0:i.fontSize,this.fontStyle=null==i?void 0:i.fontStyle,this.fontWeight=null==i?void 0:i.fontWeight,this.lineHeight=null==i?void 0:i.lineHeight,this.textAlign=null==i?void 0:i.textAlign,this.rotation=null==i?void 0:i.rotation}destroy(){this.anchor.destroy(),this.isDestroyed=!0}}const N=t=>Math.sqrt(t.x*t.x+t.y*t.y),_=(t,e)=>{var s=((t,e)=>{const s=N(t)*N(e);if(0===s)return 0;var i=((t,e)=>t.x*e.x+t.y*e.y)(t,e)/s;return i>1&&(i=1),Math.acos(i)})(t,e);return((t,e)=>t.x*e.y-e.x*t.y)(t,e)>0&&(s*=-1),180*s/Math.PI};class z{constructor(t){this.handlers=[],this.el=t}add(t){this.handlers.push(t)}del(t){t||(this.handlers=[]);for(var e=this.handlers.length;e>=0;e--)this.handlers[e]===t&&this.handlers.splice(e,1)}dispatch(...t){for(var e=0,s=this.handlers.length;e<s;e++){const t=this.handlers[e];"function"==typeof t&&t.apply(this.el,arguments)}}}const M=(t,e)=>{const s=new z(t);return s.add(e),s};class D{constructor(t,e){this.element="string"==typeof t?document.querySelector(t):t,this.start=this.start.bind(this),this.move=this.move.bind(this),this.end=this.end.bind(this),this.cancel=this.cancel.bind(this),this.element.addEventListener("touchstart",this.start,!1),this.element.addEventListener("touchmove",this.move,!1),this.element.addEventListener("touchend",this.end,!1),this.element.addEventListener("touchcancel",this.cancel,!1),this.preV={x:null,y:null},this.pinchStartLen=null,this.zoom=1,this.isDoubleTap=!1;const s=()=>{};this.rotate=M(this.element,e.rotate||s),this.touchStart=M(this.element,e.touchStart||s),this.multipointStart=M(this.element,e.multipointStart||s),this.multipointEnd=M(this.element,e.multipointEnd||s),this.pinch=M(this.element,e.pinch||s),this.swipe=M(this.element,e.swipe||s),this.tap=M(this.element,e.tap||s),this.doubleTap=M(this.element,e.doubleTap||s),this.longTap=M(this.element,e.longTap||s),this.singleTap=M(this.element,e.singleTap||s),this.pressMove=M(this.element,e.pressMove||s),this.twoFingerPressMove=M(this.element,e.twoFingerPressMove||s),this.touchMove=M(this.element,e.touchMove||s),this.touchEnd=M(this.element,e.touchEnd||s),this.touchCancel=M(this.element,e.touchCancel||s),this._cancelAllHandler=this.cancelAll.bind(this),globalThis&&"function"==typeof globalThis.addEventListener&&globalThis.addEventListener("scroll",this._cancelAllHandler),this.delta=null,this.last=null,this.now=null,this.tapTimeout=null,this.singleTapTimeout=null,this.longTapTimeout=null,this.swipeTimeout=null,this.x1=this.x2=this.y1=this.y2=null,this.preTapPosition={x:null,y:null}}start(t){if(!t.touches)return;const e=this;this.now=Date.now(),this.x1=t.touches[0].pageX,this.y1=t.touches[0].pageY,this.delta=this.now-(this.last||this.now),this.touchStart.dispatch(t,this.element),null!==this.preTapPosition.x&&(this.isDoubleTap=this.delta>0&&this.delta<=250&&Math.abs(this.preTapPosition.x-this.x1)<30&&Math.abs(this.preTapPosition.y-this.y1)<30,this.isDoubleTap&&clearTimeout(this.singleTapTimeout)),this.preTapPosition.x=this.x1,this.preTapPosition.y=this.y1,this.last=this.now;const s=this.preV;if(t.touches.length>1){this._cancelLongTap(),this._cancelSingleTap();const e={x:t.touches[1].pageX-this.x1,y:t.touches[1].pageY-this.y1};s.x=e.x,s.y=e.y,this.pinchStartLen=N(s),this.multipointStart.dispatch(t,this.element)}this._preventTap=!1,this.longTapTimeout=setTimeout((()=>{e.longTap.dispatch(t,e.element),e._preventTap=!0}).bind(e),750)}move(t){if(!t.touches)return;const e=t,s=this.preV,i=t.touches.length,r=t.touches[0].pageX,n=t.touches[0].pageY;if(this.isDoubleTap=!1,i>1){const t=e.touches[1].pageX,i=e.touches[1].pageY,a={x:e.touches[1].pageX-r,y:e.touches[1].pageY-n};null!==s.x&&(this.pinchStartLen>0&&(e.zoom=N(a)/this.pinchStartLen,this.pinch.dispatch(e,this.element)),e.angle=_(a,s),this.rotate.dispatch(e,this.element)),s.x=a.x,s.y=a.y,null!==this.x2&&null!==this.sx2?(e.deltaX=(r-this.x2+t-this.sx2)/2,e.deltaY=(n-this.y2+i-this.sy2)/2):(e.deltaX=0,e.deltaY=0),this.twoFingerPressMove.dispatch(e,this.element),this.sx2=t,this.sy2=i}else{if(null!==this.x2){e.deltaX=r-this.x2,e.deltaY=n-this.y2;const t=Math.abs(this.x1-this.x2),s=Math.abs(this.y1-this.y2);(t>10||s>10)&&(this._preventTap=!0)}else e.deltaX=0,e.deltaY=0;this.pressMove.dispatch(e,this.element)}this.touchMove.dispatch(e,this.element),this._cancelLongTap(),this.x2=r,this.y2=n,i>1&&t.preventDefault()}end(t){if(!t.changedTouches)return;const e=t;this._cancelLongTap();const s=this;e.touches.length<2&&(this.multipointEnd.dispatch(e,this.element),this.sx2=this.sy2=null),this.x2&&Math.abs(this.x1-this.x2)>30||this.y2&&Math.abs(this.y1-this.y2)>30?(e.direction=this._swipeDirection(this.x1,this.x2,this.y1,this.y2),this.swipeTimeout=setTimeout((function(){s.swipe.dispatch(e,s.element)}),0)):(this.tapTimeout=setTimeout((function(){s._preventTap||s.tap.dispatch(e,s.element),s.isDoubleTap&&(s.doubleTap.dispatch(e,s.element),s.isDoubleTap=!1)}),0),s.isDoubleTap||(s.singleTapTimeout=setTimeout((function(){s.singleTap.dispatch(e,s.element)}),250))),this.touchEnd.dispatch(e,this.element),this.preV.x=0,this.preV.y=0,this.zoom=1,this.pinchStartLen=null,this.x1=this.x2=this.y1=this.y2=null}cancelAll(){this._preventTap=!0,clearTimeout(this.singleTapTimeout),clearTimeout(this.tapTimeout),clearTimeout(this.longTapTimeout),clearTimeout(this.swipeTimeout)}cancel(t){this.cancelAll(),this.touchCancel.dispatch(t,this.element)}_cancelLongTap(){clearTimeout(this.longTapTimeout)}_cancelSingleTap(){clearTimeout(this.singleTapTimeout)}_swipeDirection(t,e,s,i){return Math.abs(t-e)>=Math.abs(s-i)?t-e>0?"Left":"Right":s-i>0?"Up":"Down"}on(t,e){if(this[t]){this[t].add(e)}}off(t,e){if(this[t]){this[t].del(e)}}destroy(){this.singleTapTimeout&&clearTimeout(this.singleTapTimeout),this.tapTimeout&&clearTimeout(this.tapTimeout),this.longTapTimeout&&clearTimeout(this.longTapTimeout),this.swipeTimeout&&clearTimeout(this.swipeTimeout),this.element.removeEventListener("touchstart",this.start),this.element.removeEventListener("touchmove",this.move),this.element.removeEventListener("touchend",this.end),this.element.removeEventListener("touchcancel",this.cancel),this.rotate.del(),this.touchStart.del(),this.multipointStart.del(),this.multipointEnd.del(),this.pinch.del(),this.swipe.del(),this.tap.del(),this.doubleTap.del(),this.longTap.del(),this.singleTap.del(),this.pressMove.del(),this.twoFingerPressMove.del(),this.touchMove.del(),this.touchEnd.del(),this.touchCancel.del(),this.preV=this.pinchStartLen=this.zoom=this.isDoubleTap=this.delta=this.last=this.now=this.tapTimeout=this.singleTapTimeout=this.longTapTimeout=this.swipeTimeout=this.x1=this.x2=this.y1=this.y2=this.preTapPosition=this.rotate=this.touchStart=this.multipointStart=this.multipointEnd=this.pinch=this.swipe=this.tap=this.doubleTap=this.longTap=this.singleTap=this.pressMove=this.touchMove=this.touchEnd=this.touchCancel=this.twoFingerPressMove=null,globalThis&&"function"==typeof globalThis.removeEventListener&&globalThis.removeEventListener("scroll",this._cancelAllHandler)}}class L{constructor(t,s,i){this.className="VEllipse",this.uid=e.next(),this.center=t,this.axis=s,this.rotation=i||0}clone(){return new L(this.center.clone(),this.axis.clone(),this.rotation)}radiusH(){return Math.abs(this.signedRadiusH())}signedRadiusH(){return new h(this.axis).rotate(-this.rotation,this.center).x-this.center.x}radiusV(){return Math.abs(this.signedRadiusV())}signedRadiusV(){return new h(this.axis).rotate(-this.rotation,this.center).y-this.center.y}scale(t){return this.axis.scale(t,this.center),this}rotate(t){return this.axis.rotate(t,this.center),this.rotation+=t,this}vertAt(t){const e=this.radiusH(),s=this.radiusV();return new h(L.utils.polarToCartesian(this.center.x,this.center.y,e,s,t)).rotate(this.rotation,this.center)}normalAt(t,e){const s=this.vertAt(t),r=this.getFoci(),n=new l(s,r[0]).angle(),a=n+(new l(s,r[1]).angle()-n)/2,h=s.clone().addX(50).clone().rotate(a,s),o=s.clone().addX(50).clone().rotate(Math.PI+a,s);return this.center.distance(h)<this.center.distance(o)?new i(s,o):new i(s,h)}tangentAt(t,e){const s=this.normalAt(t,e);return s.b.rotate(Math.PI/2,s.a),s}perimeter(){const t=this.radiusH(),e=this.radiusV();return Math.PI*(3*(t+e)-Math.sqrt((3*t+e)*(t+3*e)))}getFoci(){const t=this.radiusH(),e=this.radiusV(),s=t*t-e*e,i=Math.sqrt(Math.abs(s));return s<0?[this.center.clone().addY(i).rotate(this.rotation,this.center),this.center.clone().addY(-i).rotate(this.rotation,this.center)]:[this.center.clone().addX(i).rotate(this.rotation,this.center),this.center.clone().addX(-i).rotate(this.rotation,this.center)]}getEquidistantVertices(t){const e=L.utils.equidistantVertAngles(this.radiusH(),this.radiusV(),t),s=[];for(var i=0;i<e.length;i++)s.push(this.vertAt(e[i]));return s}toCubicBezier(t,e){const s=4*Math.max(1,t||3);e=void 0===e?.666666:e;const i=this.radiusH(),r=this.radiusV(),n=[],a=L.utils.equidistantVertAngles(i,r,s);let h=a[0],o=this.vertAt(h);for(var l=0;l<a.length;l++){let t=a[(l+1)%a.length],s=this.vertAt(t);if(Math.abs(r)<1e-4||Math.abs(i)<1e-4){let t=o.difference(s),e=new u(o.clone(),s.clone(),o.clone().addXY(.333*t.x,.333*t.y),s.clone().addXY(.333*-t.x,.333*-t.y));n.push(e)}else{let i=this.tangentAt(h),r=this.tangentAt(t),a=i.intersection(r),l=o.difference(a),c=s.difference(a),d=new u(o.clone(),s.clone(),o.clone().add(l.scale(e)),s.clone().add(c.scale(e)));n.push(d)}o=s,h=t}return n}destroy(){this.center.destroy(),this.axis.destroy(),this.isDestroyed=!0}}L.utils={polarToCartesian:(t,e,s,i,r)=>{var n=Math.sin(Math.PI/2-r),a=Math.cos(Math.PI/2-r);return{x:t+s*i*n/Math.sqrt(Math.pow(s*a,2)+Math.pow(i*n,2)),y:e+s*i*a/Math.sqrt(Math.pow(s*a,2)+Math.pow(i*n,2))}},phiToTheta:(t,e,s)=>{var i=Math.tan(s),r=i*i;return-Math.PI/2+s+Math.atan((t-e)*i/(e+t*r))},equidistantVertAngles:(t,e,s)=>{const i=[];for(var r=0;r<s;r++){var n=Math.PI/2+2*Math.PI/s*r;let a=L.utils.phiToTheta(t,e,n);i[r]=a}return i}};class E{constructor(t,s,i){this.className="VEllipseSector",this.uid=e.next(),this.ellipse=t,this.startAngle=a.wrapMinMax(s,0,2*Math.PI),this.endAngle=a.wrapMinMax(i,0,2*Math.PI)}toCubicBezier(t,e){const s=4*Math.max(1,t||3);e=void 0===e?.666666:e;const i=this.ellipse.radiusH(),r=this.ellipse.radiusV();var n=E.ellipseSectorUtils.normalizeAngle(this.startAngle),a=E.ellipseSectorUtils.normalizeAngle(this.endAngle),h=E.ellipseSectorUtils.equidistantVertAngles(i,r,n,a,s);const o=[];let l=(h=[n].concat(h).concat([a]))[0],c=this.ellipse.vertAt(l);for(var d=0;d+1<h.length;d++){let t=h[(d+1)%h.length],s=this.ellipse.vertAt(t),n=this.ellipse.tangentAt(l),a=this.ellipse.tangentAt(t);if(Math.abs(r)<1e-4||Math.abs(i)<1e-4){let t=c.difference(s),e=new u(c.clone(),s.clone(),c.clone().addXY(.333*t.x,.333*t.y),s.clone().addXY(.333*-t.x,.333*-t.y));o.push(e)}else{let t=n.intersection(a);if(t){let i=c.difference(t),r=s.difference(t),n=new u(c.clone(),s.clone(),c.clone().add(i.scale(e)),s.clone().add(r.scale(e)));o.push(n)}}c=s,l=t}return o}destroy(){this.ellipse.destroy(),this.isDestroyed=!0}}E.ellipseSectorUtils={describeSVGArc:(t,e,s,i,r,n,o,l)=>{void 0===l&&(l={moveToStart:!0}),void 0===o&&(o=0),r=a.wrapMax(r,2*Math.PI),n=a.wrapMax(n,2*Math.PI);var c=new h(L.utils.polarToCartesian(t,e,s,i,n)),d=new h(L.utils.polarToCartesian(t,e,s,i,r));c.rotate(o,{x:t,y:e}),d.rotate(o,{x:t,y:e});var u,g=n-r;u=g<0?Math.abs(g)<Math.PI?1:0:Math.abs(g)>Math.PI?1:0;const f=[];l.moveToStart&&f.push("M",d.x,d.y);const v=180/Math.PI;return f.push("A",s,i,o*v,u,1,c.x,c.y),f},equidistantVertAngles:(t,e,s,i,r)=>{for(var n=(n=(n=L.utils.equidistantVertAngles(t,e,r)).map((t=>E.ellipseSectorUtils.normalizeAngle(t)))).filter((t=>s<i?t>=s&&t<=i:t>=s||t<=i&&t>=0)),a=E.ellipseSectorUtils.findClosestToStartAngle(s,i,n),h=[],o=0;o<n.length;o++)h.push(n[(a+o)%n.length]);return h},findClosestToStartAngle:(t,e,s)=>{if(t>e){const r=s.length;for(var i=0;i<r;i++){const r=a.wrapMinMax(s[i],0,2*Math.PI);if(r>=t&&r>=e)return i}}return 0},normalizeAngle:t=>t<0?2*Math.PI+t:t,endpointToCenterParameters(t,e,s,i,r,n,a,o,c){const d=Math.abs,u=Math.sin,g=Math.cos,f=Math.sqrt,v=t=>t*t,x=u(r),y=g(r),p=y*(t-o)/2+x*(e-c)/2,m=-x*(t-o)/2+y*(e-c)/2,b=v(p),w=v(m),C=v(s),P=v(i),A=b/C+w/P;A>1?(s=f(A)*d(s),i=f(A)*d(i)):(s=d(s),i=d(i));const S=n===a?-1:1,T=f(Math.abs((C*P-C*w-P*b)/(C*w+P*b)))*S,N=T*(s*m)/i,_=T*(-i*p)/s,z=new h(y*N-x*_+(t+o)/2,x*N+y*_+(e+c)/2),M=z.clone().addXY(s,i),D=new L(z,M,0);D.rotate(r);const I=new l(D.center,new h(t,e)).angle(),k=new l(D.center,new h(o,c)).angle();return new E(D,I-r,k-r)}};var I,k=function(t,e,s){return"symbol"==typeof e&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(t,"name",{configurable:!0,value:s?"".concat(s," ",e):e})};class O{constructor(e,s){var i,r;if(this.renderTime=0,this._gui=null,t.model={bezierAutoAdjust:!1,renderTime:0,selectable:!0,isSelected:!1,draggable:!0,visible:!0},void 0===e.canvas)throw"No canvas specified.";const n=O.utils.fetch;this.config={canvas:e.canvas,fullSize:n.val(e,"fullSize",!0),fitToParent:n.bool(e,"fitToParent",!0),scaleX:n.num(e,"scaleX",1),scaleY:n.num(e,"scaleY",1),offsetX:n.num(e,"offsetX",0),offsetY:n.num(e,"offsetY",0),rasterGrid:n.bool(e,"rasterGrid",!0),drawRaster:n.bool(e,"drawRaster",!0),rasterScaleX:n.num(e,"rasterScaleX",1),rasterScaleY:n.num(e,"rasterScaleY",1),rasterAdjustFactor:n.num(e,"rasterAdjustdFactror",2),drawOrigin:n.bool(e,"drawOrigin",!1),autoAdjustOffset:n.val(e,"autoAdjustOffset",!0),offsetAdjustXPercent:n.num(e,"offsetAdjustXPercent",50),offsetAdjustYPercent:n.num(e,"offsetAdjustYPercent",50),backgroundColor:e.backgroundColor||"#ffffff",redrawOnResize:n.bool(e,"redrawOnResize",!0),defaultCanvasWidth:n.num(e,"defaultCanvasWidth",O.DEFAULT_CANVAS_WIDTH),defaultCanvasHeight:n.num(e,"defaultCanvasHeight",O.DEFAULT_CANVAS_HEIGHT),canvasWidthFactor:n.num(e,"canvasWidthFactor",1),canvasHeightFactor:n.num(e,"canvasHeightFactor",1),cssScaleX:n.num(e,"cssScaleX",1),cssScaleY:n.num(e,"cssScaleY",1),cssUniformScale:n.bool(e,"cssUniformScale",!0),saveFile:()=>{o.hooks.saveFile(o)},setToRetina:()=>{o._setToRetina()},autoDetectRetina:n.bool(e,"autoDetectRetina",!0),enableSVGExport:n.bool(e,"enableSVGExport",!0),preClear:n.func(e,"preClear",null),preDraw:n.func(e,"preDraw",null),postDraw:n.func(e,"postDraw",null),enableMouse:n.bool(e,"enableMouse",!0),enableTouch:n.bool(e,"enableTouch",!0),enableKeys:n.bool(e,"enableKeys",!0),enableMouseWheel:n.bool(e,"enableMouseWheel",!0),enableZoom:n.bool(e,"enableZoom",!0),enablePan:n.bool(e,"enablePan",!0),enableGL:n.bool(e,"enableGL",!1),isBackdropFiltersEnabled:n.bool(e,"isBackdropFiltersEnabled",!0)},this.drawConfig={drawVertices:!0,drawBezierHandleLines:n.bool(e,"drawBezierHandleLines",!0),drawBezierHandlePoints:n.bool(e,"drawBezierHandlePoints",!0),drawHandleLines:n.bool(e,"drawHandleLines",!0),drawHandlePoints:n.bool(e,"drawHandlePoints",!0),drawGrid:n.bool(e,"drawGrid",!0),drawRaster:n.bool(e,"drawRaster",!0),bezier:{color:"#00a822",lineWidth:2,handleLine:{color:"rgba(180,180,180,0.5)",lineWidth:1},pathVertex:{color:"#B400FF",lineWidth:1,fill:!0},controlVertex:{color:"#B8D438",lineWidth:1,fill:!0}},polygon:{color:"#0022a8",lineWidth:1},triangle:{color:"#6600ff",lineWidth:1},ellipse:{color:"#2222a8",lineWidth:1},ellipseSector:{color:"#a822a8",lineWidth:2},circle:{color:"#22a8a8",lineWidth:2},circleSector:{color:"#2280a8",lineWidth:1},vertex:{color:"#a8a8a8",lineWidth:1},selectedVertex:{color:"#c08000",lineWidth:2},line:{color:"#a844a8",lineWidth:1},vector:{color:"#ff44a8",lineWidth:1},image:{color:"#a8a8a8",lineWidth:1},text:{color:"rgba(192,0,128,0.5)",lineWidth:1,fill:!0,anchor:!0},origin:{color:"#000000"}},this.grid=new b(new h(0,0),new h(50,50)),this.canvasSize={width:O.DEFAULT_CANVAS_WIDTH,height:O.DEFAULT_CANVAS_HEIGHT};const a="string"==typeof e.canvas?document.querySelector(e.canvas):e.canvas;if(void 0===a)throw`Cannot initialize PlotBoilerplate with a null canvas (element "${e.canvas} not found).`;if("canvas"===a.tagName.toLowerCase())if(this.canvas=a,this.eventCatcher=this.canvas,this.config.enableGL&&void 0===p&&(console.warn("Cannot use webgl. Package was compiled without experimental gl support. Please use plotboilerplate-glsupport.min.js instead."),console.warn("Disabling GL and falling back to Canvas2D."),this.config.enableGL=!1),this.config.enableGL){const t=this.canvas.getContext("webgl");this.draw=new p(t,!1),this.fill=this.draw.copyInstance(!0),console.warn("Initialized with experimental mode enableGL=true. Note that this is not yet fully implemented.")}else{const t=this.canvas.getContext("2d");this.draw=new y(t,!1),this.fill=new y(t,!0)}else{if("svg"!==a.tagName.toLowerCase())throw"Element is neither a canvas nor an svg element.";if(void 0===x)throw"The svg draw library is not yet integrated part of PlotBoilerplate. Please include ./src/js/utils/helpers/drawutils.svg into your document.";this.canvas=a,this.draw=new x(this.canvas,new h,new h,this.canvasSize,!1,this.drawConfig,!1),this.fill=this.draw.copyInstance(!0),this.canvas.parentElement?(this.eventCatcher=document.createElement("div"),this.eventCatcher.style.position="absolute",this.eventCatcher.style.left="0",this.eventCatcher.style.top="0",this.eventCatcher.style.cursor="pointer",this.canvas.parentElement.style.position="relative",this.canvas.parentElement.appendChild(this.eventCatcher)):this.eventCatcher=document.body}e.title&&this.eventCatcher.setAttribute("title",e.title),this.draw.scale.set(null!==(i=this.config.scaleX)&&void 0!==i?i:1,this.config.scaleY),this.fill.scale.set(null!==(r=this.config.scaleX)&&void 0!==r?r:1,this.config.scaleY),this.vertices=[],this.selectPolygon=null,this.draggedElements=[],this.drawables=[],this.console=console,this.hooks={saveFile:O._saveFile};var o=this;globalThis.addEventListener("resize",(()=>o.resizeCanvas())),this.resizeCanvas(),e.autoDetectRetina&&this._setToRetina(),this.installInputListeners(),this.updateCSSscale(),this.redraw(),this.canvas.focus()}static _saveFile(t){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");var s=new x(e,t.draw.offset,t.draw.scale,t.canvasSize,!1,t.drawConfig),i=s.copyInstance(!0);s.beginDrawCycle(0),i.beginDrawCycle(0),t.config.preClear&&t.config.preClear(),s.clear(t.config.backgroundColor||"white"),t.config.preDraw&&t.config.preDraw(s,i),t.drawAll(0,s,i),t.drawVertices(0,s),t.config.postDraw&&t.config.postDraw(s,i),s.endDrawCycle(0),i.endDrawCycle(0);var r=(new XMLSerializer).serializeToString(e),n=new Blob(['<?xml version="1.0" encoding="utf-8"?>\n'+r],{type:"image/svg;charset=utf-8"});if("function"!=typeof globalThis.saveAs)throw"Cannot save file; did you load the ./utils/savefile helper function and the eligrey/SaveFile library?";(0,globalThis.saveAs)(n,"plotboilerplate.svg")}_setToRetina(){this.config.autoDetectRetina=!0;const t=globalThis.devicePixelRatio||1;this.config.cssScaleX=this.config.cssScaleY=1/t,this.config.canvasWidthFactor=this.config.canvasHeightFactor=t,this.resizeCanvas(),this.updateCSSscale()}fitToView(t){const e=new h(this.canvasSize.width/2,this.canvasSize.height/2),s=this.canvasSize.width/this.canvasSize.height,i=t.width/t.height,r=new h(t.max.x-t.width/2,t.max.y-t.height/2).inv().addXY(this.canvasSize.width/2,this.canvasSize.height/2);if(this.setOffset(r),s<i){const s=this.canvasSize.width/t.width;this.setZoom(s,s,e)}else{const s=this.canvasSize.height/t.height;this.setZoom(s,s,e)}this.redraw()}setConsole(t){this.console=t}updateCSSscale(){var t,e,s,i;this.config.cssUniformScale?O.utils.setCSSscale(this.canvas,null!==(t=this.config.cssScaleX)&&void 0!==t?t:1,null!==(e=this.config.cssScaleX)&&void 0!==e?e:1):O.utils.setCSSscale(this.canvas,null!==(s=this.config.cssScaleX)&&void 0!==s?s:1,null!==(i=this.config.cssScaleY)&&void 0!==i?i:1)}add(t,e){if(Array.isArray(t)){const e=t;for(var s=0;s<e.length;s++)this.add(e[s],!1)}else if(t instanceof h)this.drawables.push(t),this.vertices.push(t);else if(t instanceof l)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b);else if(t instanceof i)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b);else if(t instanceof L)this.vertices.push(t.center),this.vertices.push(t.axis),this.drawables.push(t),t.center.listeners.addDragListener((e=>{t.axis.add(e.params.dragAmount)}));else if(t instanceof E)this.vertices.push(t.ellipse.center),this.vertices.push(t.ellipse.axis),this.drawables.push(t),t.ellipse.center.listeners.addDragListener((e=>{t.ellipse.axis.add(e.params.dragAmount)}));else if(t instanceof r)this.vertices.push(t.center),this.drawables.push(t);else if(t instanceof f)this.vertices.push(t.circle.center),this.drawables.push(t);else if(t instanceof c){this.drawables.push(t);for(s=0;s<t.vertices.length;s++)this.vertices.push(t.vertices[s])}else if(t instanceof n)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b),this.vertices.push(t.c);else if(t instanceof g){this.drawables.push(t);const e=t;for(s=0;s<e.bezierCurves.length;s++)t.adjustCircular||0!=s||this.vertices.push(e.bezierCurves[s].startPoint),this.vertices.push(e.bezierCurves[s].endPoint),this.vertices.push(e.bezierCurves[s].startControlPoint),this.vertices.push(e.bezierCurves[s].endControlPoint),e.bezierCurves[s].startControlPoint.attr.selectable=!1,e.bezierCurves[s].endControlPoint.attr.selectable=!1;O.utils.enableBezierPathAutoAdjust(t)}else if(t instanceof S)this.vertices.push(t.upperLeft),this.vertices.push(t.lowerRight),this.drawables.push(t),t.upperLeft.listeners.addDragListener((e=>{t.lowerRight.add(e.params.dragAmount)})),t.lowerRight.attr.selectable=!1;else{if(!(t instanceof T))throw"Cannot add drawable of unrecognized type: "+typeof t+".";this.vertices.push(t.anchor),this.drawables.push(t),t.anchor.attr.selectable=!1}(e||void 0===e)&&this.redraw()}remove(t,e,s){if(Array.isArray(t)){for(var a=0;a<t.length;a++)this.remove(t[a],!1,s);e&&this.redraw()}else{t instanceof h&&(this.removeVertex(t,!1),e&&this.redraw());for(a=0;a<this.drawables.length;a++)if(this.drawables[a]===t||this.drawables[a].uid===t.uid){if(this.drawables.splice(a,1),s)if(t instanceof l)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1);else if(t instanceof i)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1);else if(t instanceof L)this.removeVertex(t.center,!1),this.removeVertex(t.axis,!1);else if(t instanceof E)this.removeVertex(t.ellipse.center),this.removeVertex(t.ellipse.axis);else if(t instanceof r)this.removeVertex(t.center,!1);else if(t instanceof f)this.removeVertex(t.circle.center,!1);else if(t instanceof c)for(a=0;a<t.vertices.length;a++)this.removeVertex(t.vertices[a],!1);else if(t instanceof n)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1),this.removeVertex(t.c,!1);else if(t instanceof g)for(a=0;a<t.bezierCurves.length;a++)this.removeVertex(t.bezierCurves[a].startPoint,!1),this.removeVertex(t.bezierCurves[a].startControlPoint,!1),this.removeVertex(t.bezierCurves[a].endControlPoint,!1),a+1==t.bezierCurves.length&&this.removeVertex(t.bezierCurves[a].endPoint,!1);else t instanceof S?(this.removeVertex(t.upperLeft,!1),this.removeVertex(t.lowerRight,!1)):t instanceof T&&this.removeVertex(t.anchor,!1);e&&this.redraw()}}}removeVertex(t,e){for(var s=0;s<this.vertices.length;s++)if(this.vertices[s]===t)return this.vertices.splice(s,1),void(e&&this.redraw())}removeAll(t,e){this.drawables=[],Boolean(t)||(this.vertices=[]),(e||void 0===e)&&this.redraw()}getVertexNear(t,e){var s,i;const r=this.locatePointNear(this.transformMousePosition(t.x,t.y),e/Math.min(null!==(s=this.config.cssScaleX)&&void 0!==s?s:1,null!==(i=this.config.cssScaleY)&&void 0!==i?i:1));if(r&&"vertex"==r.typeName)return this.vertices[r.vindex]}drawGrid(t){void 0===t&&(t=this.draw);const e=b.utils.mapRasterScale(this.config.rasterAdjustFactor,this.draw.scale.x)*this.config.rasterScaleX/this.config.cssScaleX,s=b.utils.mapRasterScale(this.config.rasterAdjustFactor,this.draw.scale.y)*this.config.rasterScaleY/this.config.cssScaleY;var i={width:this.grid.size.x*e,height:this.grid.size.y*s},r=this.canvasSize.width/2,n=this.canvasSize.height/2,a=this.draw.offset.clone().inv();a.x=Math.round(a.x+r)/Math.round(i.width)*i.width/this.draw.scale.x+(this.draw.offset.x-r)/this.draw.scale.x%i.width,a.y=Math.round(a.y+n)/Math.round(i.height)*i.height/this.draw.scale.y+(this.draw.offset.y-n)/this.draw.scale.x%i.height,this.drawConfig.drawGrid&&(t.setCurrentClassName(null),this.config.rasterGrid?(t.setCurrentId("raster"),t.raster(a,this.canvasSize.width/this.draw.scale.x,this.canvasSize.height/this.draw.scale.y,i.width,i.height,"rgba(0,128,255,0.125)")):(t.setCurrentId("grid"),t.grid(a,this.canvasSize.width/this.draw.scale.x,this.canvasSize.height/this.draw.scale.y,i.width,i.height,"rgba(0,128,255,0.095)")))}drawOrigin(t){t.setCurrentId("origin"),t.crosshair({x:0,y:0},10,this.drawConfig.origin.color)}_handleColor(t,e){return t.attr.isSelected?this.drawConfig.selectedVertex.color:t.attr.draggable?e:"rgba(128,128,128,0.5)"}drawDrawables(t,e,s){for(var i in this.drawables){var r=this.drawables[i];this.draw.setCurrentId(r.uid),this.fill.setCurrentId(r.uid),this.draw.setCurrentClassName(r.className),this.fill.setCurrentClassName(r.className),this.drawDrawable(r,t,e,s)}}drawDrawable(t,e,s,a){if(t instanceof g){var o=0;for(var d in t.bezierCurves){if(this.draw.setCurrentId(`${t.uid}-${o}`),this.fill.setCurrentId(`${t.uid}-${o}`),this.draw.setCurrentClassName(t.className),this.fill.setCurrentClassName(t.className),s.cubicBezier(t.bezierCurves[d].startPoint,t.bezierCurves[d].endPoint,t.bezierCurves[d].startControlPoint,t.bezierCurves[d].endControlPoint,this.drawConfig.bezier.color,this.drawConfig.bezier.lineWidth),this.drawConfig.drawBezierHandlePoints&&this.drawConfig.drawHandlePoints){if(t.bezierCurves[d].startPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?a:s;e.setCurrentId(`${t.uid}_h0`),e.setCurrentClassName(`${t.className}-start-handle`),t.bezierCurves[d].startPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[d].startPoint,5,this._handleColor(t.bezierCurves[d].startPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[d].startPoint,7,this._handleColor(t.bezierCurves[d].startPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[d].startPoint.attr.renderTime=e,t.bezierCurves[d].endPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?a:s;e.setCurrentId(`${t.uid}_h0`),e.setCurrentClassName(`${t.className}-start-handle`),t.bezierCurves[d].endPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[d].endPoint,5,this._handleColor(t.bezierCurves[d].endPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[d].endPoint,7,this._handleColor(t.bezierCurves[d].endPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[d].startControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?a:s;e.setCurrentId(`${t.uid}_h2`),e.setCurrentClassName(`${t.className}-start-control-handle`),e.circleHandle(t.bezierCurves[d].startControlPoint,3,this._handleColor(t.bezierCurves[d].startControlPoint,this.drawConfig.bezier.controlVertex.color))}if(t.bezierCurves[d].endControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?a:s;e.setCurrentId(`${t.uid}_h3`),e.setCurrentClassName(`${t.className}-end-control-handle`),e.circleHandle(t.bezierCurves[d].endControlPoint,3,this._handleColor(t.bezierCurves[d].endControlPoint,this.drawConfig.bezier.controlVertex.color))}t.bezierCurves[d].startPoint.attr.renderTime=e,t.bezierCurves[d].endPoint.attr.renderTime=e,t.bezierCurves[d].startControlPoint.attr.renderTime=e,t.bezierCurves[d].endControlPoint.attr.renderTime=e}else t.bezierCurves[d].startPoint.attr.renderTime=e,t.bezierCurves[d].endPoint.attr.renderTime=e,t.bezierCurves[d].startControlPoint.attr.renderTime=e,t.bezierCurves[d].endControlPoint.attr.renderTime=e;this.drawConfig.drawBezierHandleLines&&this.drawConfig.drawHandleLines&&(s.setCurrentId(`${t.uid}_l0`),s.setCurrentClassName(`${t.className}-start-line`),s.handleLine(t.bezierCurves[d].startPoint,t.bezierCurves[d].startControlPoint),s.setCurrentId(`${t.uid}_l1`),s.setCurrentClassName(`${t.className}-end-line`),s.handleLine(t.bezierCurves[d].endPoint,t.bezierCurves[d].endControlPoint)),o++}}else if(t instanceof c){if(s.polygon(t,this.drawConfig.polygon.color,this.drawConfig.polygon.lineWidth),!this.drawConfig.drawHandlePoints)for(var u in t.vertices)t.vertices[u].attr.renderTime=e}else if(t instanceof n)s.polyline([t.a,t.b,t.c],!1,this.drawConfig.triangle.color,this.drawConfig.triangle.lineWidth),this.drawConfig.drawHandlePoints||(t.a.attr.renderTime=t.b.attr.renderTime=t.c.attr.renderTime=e);else if(t instanceof L)this.drawConfig.drawHandleLines&&(s.setCurrentId(`${t.uid}_e0`),s.setCurrentClassName(`${t.className}-v-line`),s.handleLine(t.center.clone().add(0,t.signedRadiusV()).rotate(t.rotation,t.center),t.axis),s.setCurrentId(`${t.uid}_e1`),s.setCurrentClassName(`${t.className}-h-line`),s.handleLine(t.center.clone().add(t.signedRadiusH(),0).rotate(t.rotation,t.center),t.axis)),s.setCurrentId(t.uid),s.setCurrentClassName(`${t.className}`),s.ellipse(t.center,t.radiusH(),t.radiusV(),this.drawConfig.ellipse.color,this.drawConfig.ellipse.lineWidth,t.rotation),this.drawConfig.drawHandlePoints||(t.center.attr.renderTime=e,t.axis.attr.renderTime=e);else if(t instanceof E){s.setCurrentId(t.uid),s.setCurrentClassName(`${t.className}`);const e=E.ellipseSectorUtils.describeSVGArc(t.ellipse.center.x,t.ellipse.center.y,t.ellipse.radiusH(),t.ellipse.radiusV(),t.startAngle,t.endAngle,t.ellipse.rotation,{moveToStart:!0});s.path(e,this.drawConfig.ellipseSector.color,this.drawConfig.ellipseSector.lineWidth)}else t instanceof r?s.circle(t.center,t.radius,this.drawConfig.circle.color,this.drawConfig.circle.lineWidth):t instanceof f?s.circleArc(t.circle.center,t.circle.radius,t.startAngle,t.endAngle,this.drawConfig.circleSector.color,this.drawConfig.circleSector.lineWidth):t instanceof h?!this.drawConfig.drawVertices||t.attr.selectable&&t.attr.draggable||!t.attr.visible||(s.circleHandle(t,7,this.drawConfig.vertex.color),t.attr.renderTime=e):t instanceof l?(s.line(t.a,t.b,this.drawConfig.line.color,this.drawConfig.line.lineWidth),this.drawConfig.drawHandlePoints&&t.a.attr.selectable||(t.a.attr.renderTime=e),this.drawConfig.drawHandlePoints&&t.b.attr.selectable||(t.b.attr.renderTime=e)):t instanceof i?(s.arrow(t.a,t.b,this.drawConfig.vector.color),this.drawConfig.drawHandlePoints&&t.b.attr.selectable&&t.b.attr.visible?(s.setCurrentId(`${t.uid}_h0`),s.setCurrentClassName(`${t.className}-handle`),s.circleHandle(t.b,3,"#a8a8a8")):t.b.attr.renderTime=e,this.drawConfig.drawHandlePoints&&t.a.attr.selectable||(t.a.attr.renderTime=e),this.drawConfig.drawHandlePoints&&t.b.attr.selectable||(t.b.attr.renderTime=e)):t instanceof S?(this.drawConfig.drawHandleLines&&(s.setCurrentId(`${t.uid}_l0`),s.setCurrentClassName(`${t.className}-line`),s.line(t.upperLeft,t.lowerRight,this.drawConfig.image.color,this.drawConfig.image.lineWidth)),a.setCurrentId(t.uid),a.image(t.image,t.upperLeft,t.lowerRight.clone().sub(t.upperLeft)),this.drawConfig.drawHandlePoints&&(s.setCurrentId(`${t.uid}_h0`),s.setCurrentClassName(`${t.className}-lower-right`),s.circleHandle(t.lowerRight,3,this.drawConfig.image.color),t.lowerRight.attr.renderTime=e)):t instanceof T?(a.setCurrentId(t.uid),a.text(t.text,t.anchor.x,t.anchor.y,t),this.drawConfig.text.anchor&&(s.setCurrentId(`${t.uid}_a0`),s.setCurrentClassName(`${t.className}-anchor`),(this.drawConfig.text.fill?a:s).point(t.anchor,this.drawConfig.text.color)),t.anchor.attr.renderTime=e):console.error("Cannot draw object. Unknown class.");s.setCurrentClassName(null),s.setCurrentId(null),a.setCurrentClassName(null),a.setCurrentId(null)}drawSelectPolygon(t){null!=this.selectPolygon&&this.selectPolygon.vertices.length>0&&(t.setCurrentId(this.selectPolygon.uid),t.polygon(this.selectPolygon,"#888888"),t.crosshair(this.selectPolygon.vertices[0],3,"#008888"))}drawVertices(t,e){for(var s in this.vertices)this.drawConfig.drawVertices&&this.vertices[s].attr.renderTime!=t&&this.vertices[s].attr.visible&&(e.setCurrentId(this.vertices[s].uid),e.squareHandle(this.vertices[s],5,this._handleColor(this.vertices[s],"rgb(0,128,192)")),this.vertices[s].attr.renderTime=t)}redraw(){const t=this.renderTime++;this.draw.beginDrawCycle(t),this.fill.beginDrawCycle(t),this.config.preClear&&this.config.preClear(),this.clear(),this.config.preDraw&&this.config.preDraw(this.draw,this.fill),this.drawAll(t,this.draw,this.fill),this.config.postDraw&&this.config.postDraw(this.draw,this.fill),this.draw.endDrawCycle(t),this.fill.endDrawCycle(t)}drawAll(t,e,s){this.config.drawRaster&&this.drawGrid(e),this.config.drawOrigin&&this.drawOrigin(e),this.drawDrawables(t,e,s),this.drawVertices(t,e),this.drawSelectPolygon(e),e.setCurrentId(null),e.setCurrentClassName(null)}clear(){this.draw.clear(this.config.backgroundColor||"white")}clearSelection(t){for(var e in this.vertices)this.vertices[e].attr.isSelected=!1;return t&&this.redraw(),this}viewport(){var t,e;return new d(this.transformMousePosition(0,0),this.transformMousePosition(this.canvasSize.width*(null!==(t=this.config.cssScaleX)&&void 0!==t?t:1),this.canvasSize.height*(null!==(e=this.config.cssScaleY)&&void 0!==e?e:1)))}saveFile(){this.hooks.saveFile(this)}getFProp(t,e){return parseFloat(globalThis.getComputedStyle(t,null).getPropertyValue(e))}getAvailableContainerSpace(){const t=this,e=t.canvas.parentNode;t.canvas.style.display="none";var s=this.getFProp(e,"padding")||0,i=this.getFProp(t.canvas,"border-width")||0,r=this.getFProp(e,"padding-left")||s,n=this.getFProp(e,"padding-right")||s,a=this.getFProp(e,"padding-top")||s,h=this.getFProp(e,"padding-bottom")||s,o=this.getFProp(t.canvas,"border-left-width")||i,l=this.getFProp(t.canvas,"border-right-width")||i,c=this.getFProp(t.canvas,"border-top-width")||i,d=this.getFProp(t.canvas,"border-bottom-width")||i,u=e.clientWidth,g=e.clientHeight;return t.canvas.style.display="block",{width:u-r-n-o-l,height:g-a-h-c-d}}resizeCanvas(){var t,e,s,i,r,n;const a=this,h=(t,e)=>{var s,i;t*=null!==(s=a.config.canvasWidthFactor)&&void 0!==s?s:1,e*=null!==(i=a.config.canvasHeightFactor)&&void 0!==i?i:1,a.canvasSize.width=t,a.canvasSize.height=e,a.canvas instanceof HTMLCanvasElement?(a.canvas.width=t,a.canvas.height=e):a.canvas instanceof SVGElement?(this.canvas.setAttribute("viewBox",`0 0 ${t} ${e}`),this.canvas.setAttribute("width",`${t}`),this.canvas.setAttribute("height",`${e}`),this.draw.setSize(a.canvasSize),this.eventCatcher.style.width=`${t}px`,this.eventCatcher.style.height=`${e}px`):console.error("Error: cannot resize canvas element because it seems neither be a HTMLCanvasElement nor an SVGElement."),a.config.autoAdjustOffset&&a.adjustOffset(!1)};if(a.config.fullSize&&!a.config.fitToParent){var o=globalThis.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,l=globalThis.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;a.canvas.style.position="absolute",a.canvas.style.width=(null!==(t=a.config.canvasWidthFactor)&&void 0!==t?t:1)*o+"px",a.canvas.style.height=(null!==(e=a.config.canvasWidthFactor)&&void 0!==e?e:1)*l+"px",a.canvas.style.top="0px",a.canvas.style.left="0px",h(o,l)}else if(a.config.fitToParent){a.canvas.style.position="static";const t=this.getAvailableContainerSpace();a.canvas.style.width=(null!==(s=a.config.canvasWidthFactor)&&void 0!==s?s:1)*t.width+"px",a.canvas.style.height=(null!==(i=a.config.canvasHeightFactor)&&void 0!==i?i:1)*t.height+"px",a.canvas.style.top="",a.canvas.style.left="",h(t.width,t.height)}else a.canvas.style.width="",a.canvas.style.height="",h(null!==(r=a.config.defaultCanvasWidth)&&void 0!==r?r:1024,null!==(n=a.config.defaultCanvasHeight)&&void 0!==n?n:768);a.config.redrawOnResize&&a.redraw()}selectVerticesInPolygon(t){for(var e in this.vertices)this.vertices[e].attr.selectable&&t.containsVert(this.vertices[e])&&(this.vertices[e].attr.isSelected=!0)}locatePointNear(t,e){const s=this;void 0===e&&(e=7),e/=s.draw.scale.x;for(var i=0;i<s.vertices.length;i++){var r=s.vertices[i];if((r.attr.draggable||r.attr.selectable)&&r.distance(t)<e)return new O.Draggable(r,O.Draggable.VERTEX).setVIndex(i)}return null}handleClick(t){const e=this;var s=this.locatePointNear(e.transformMousePosition(t.params.pos.x,t.params.pos.y),O.DEFAULT_CLICK_TOLERANCE/Math.min(e.config.cssScaleX||1,e.config.cssScaleY||1));if(s)if(e.vertices[s.vindex].listeners.fireClickEvent(t),this.keyHandler&&this.keyHandler.isDown("shift")){if("bpath"==s.typeName){let t=e.paths[s.pindex].bezierCurves[s.cindex].getPointByID(s.pid);t.attr.selectable&&(t.attr.isSelected=!t.attr.isSelected)}else if("vertex"==s.typeName){let t=e.vertices[s.vindex];t.attr.selectable&&(t.attr.isSelected=!t.attr.isSelected)}e.redraw()}else this.keyHandler&&this.keyHandler.isDown("y")&&(e.vertices[s.vindex].attr.bezierAutoAdjust=!e.vertices[s.vindex].attr.bezierAutoAdjust,e.redraw());else if(null!=e.selectPolygon){const s=e.transformMousePosition(t.params.pos.x,t.params.pos.y);e.selectPolygon.vertices.push(new h(s.x,s.y)),e.redraw()}}transformMousePosition(t,e){return{x:(t/this.config.cssScaleX-this.config.offsetX)/this.config.scaleX,y:(e/this.config.cssScaleY-this.config.offsetY)/this.config.scaleY}}revertMousePosition(t,e){return{x:t/this.config.cssScaleX+this.config.offsetX,y:e/this.config.cssScaleY+this.config.offsetY}}getDraggedElementCount(){return this.draggedElements.length}mouseDownHandler(t){const e=this;if(0==t.button){var s=e.locatePointNear(e.transformMousePosition(t.params.pos.x,t.params.pos.y),O.DEFAULT_CLICK_TOLERANCE/Math.min(e.config.cssScaleX,e.config.cssScaleY));if(s){if("vertex"==s.typeName&&e.vertices[s.vindex].attr.isSelected)for(var i=0;i<e.vertices.length;i++)e.vertices[i].attr.isSelected&&(e.draggedElements.push(new O.Draggable(e.vertices[i],O.Draggable.VERTEX).setVIndex(i)),e.vertices[i].listeners.fireDragStartEvent(t));else{if(!e.vertices[s.vindex].attr.draggable)return;e.draggedElements.push(s),"bpath"==s.typeName?e.paths[s.pindex].bezierCurves[s.cindex].getPointByID(s.pid).listeners.fireDragStartEvent(t):"vertex"==s.typeName&&e.vertices[s.vindex].listeners.fireDragStartEvent(t)}e.redraw()}}}mouseDragHandler(t){const e=this,s={x:t.params.dragAmount.x,y:t.params.dragAmount.y};if(t.params.dragAmount.x/=e.config.cssScaleX,t.params.dragAmount.y/=e.config.cssScaleY,this.keyHandler&&(this.keyHandler.isDown("alt")||this.keyHandler.isDown("spacebar"))){if(!this.config.enablePan)return;e.setOffset(e.draw.offset.clone().add(t.params.dragAmount)),e.redraw()}else for(var i in t.params.dragAmount.x/=e.draw.scale.x,t.params.dragAmount.y/=e.draw.scale.y,e.draggedElements){var r=e.draggedElements[i];if("bpath"==r.typeName)e.paths[r.pindex].moveCurvePoint(r.cindex,r.pid,new h(t.params.dragAmount.x,t.params.dragAmount.y)),e.paths[r.pindex].bezierCurves[r.cindex].getPointByID(r.pid).listeners.fireDragEvent(t);else if("vertex"==r.typeName){if(!e.vertices[r.vindex].attr.draggable)continue;e.vertices[r.vindex].add(t.params.dragAmount),e.vertices[r.vindex].listeners.fireDragEvent(t)}}t.params.dragAmount.x=s.x,t.params.dragAmount.y=s.y,e.redraw()}mouseUpHandler(t){const e=this;if(0==t.button){for(var s in t.params.wasDragged||e.handleClick(t),e.draggedElements){var i=e.draggedElements[s];"bpath"==i.typeName?e.paths[i.pindex].bezierCurves[i.cindex].getPointByID(i.pid).listeners.fireDragEndEvent(t):"vertex"==i.typeName&&e.vertices[i.vindex].listeners.fireDragEndEvent(t)}e.draggedElements=[],e.redraw()}}mouseWheelHandler(t){if(!this.config.enableZoom)return;var e=1.25;const s=this,i=t;i.deltaY<0?s.setZoom(s.config.scaleX*e,s.config.scaleY*e,new h(t.params.pos.x,t.params.pos.y)):i.deltaY>0&&s.setZoom(s.config.scaleX/e,s.config.scaleY/e,new h(t.params.pos.x,t.params.pos.y)),t.preventDefault(),s.redraw()}adjustOffset(t){this.draw.offset.x=this.fill.offset.x=this.config.offsetX=this.canvasSize.width*(this.config.offsetAdjustXPercent/100),this.draw.offset.y=this.fill.offset.y=this.config.offsetY=this.canvasSize.height*(this.config.offsetAdjustYPercent/100),t&&this.redraw()}setOffset(t){this.draw.offset.set(t),this.fill.offset.set(t),this.config.offsetX=t.x,this.config.offsetY=t.y}setZoom(t,e,s){let i=this.transformMousePosition(s.x,s.y);this.draw.scale.x=this.fill.scale.x=this.config.scaleX=Math.max(t,.01),this.draw.scale.y=this.fill.scale.y=this.config.scaleY=Math.max(e,.01);let r=this.transformMousePosition(s.x,s.y),n=this.draw.offset.x+(r.x-i.x)*this.draw.scale.x,a=this.draw.offset.y+(r.y-i.y)*this.draw.scale.y;this.setOffset({x:n,y:a})}installInputListeners(){var t=this;if(this.config.enableMouse?new A(this.eventCatcher?this.eventCatcher:this.canvas).down((e=>{t.mouseDownHandler(e)})).drag((e=>{t.mouseDragHandler(e)})).up((e=>{t.mouseUpHandler(e)})):t.console.log("Mouse interaction disabled."),this.config.enableMouseWheel?new A(this.eventCatcher?this.eventCatcher:this.canvas).wheel((e=>{t.mouseWheelHandler(e)})):t.console.log("Mouse wheel interaction disabled."),this.config.enableTouch){const n=e=>{const s=t.canvas.getBoundingClientRect();return{x:e.x-s.left,y:e.y-s.top}};if("function"==typeof globalThis.AlloyFinger||"function"==typeof globalThis.createAlloyFinger)try{var e=null,s=null,i=null,r=null;const a=()=>{e=null,s=null,i=null,r=null,t.draggedElements=[]},o={touchStart:r=>{if(1==r.touches.length&&(e=new h(n({x:r.touches[0].clientX,y:r.touches[0].clientY})),s=new h(n({x:r.touches[0].clientX,y:r.touches[0].clientY})),(i=t.locatePointNear(t.transformMousePosition(e.x,e.y),O.DEFAULT_TOUCH_TOLERANCE/Math.min(t.config.cssScaleX,t.config.cssScaleY)))&&"vertex"==i.typeName)){var a=t.vertices[i.vindex],o={params:{isTouchEvent:!0,dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:a}};t.draggedElements=[i],a.listeners.fireDragStartEvent(o)}},touchMove:r=>{if(1==r.touches.length&&i){if(r.preventDefault(),r.stopPropagation(),!s||!e)return;var a=n({x:r.touches[0].clientX,y:r.touches[0].clientY}),o=t.transformMousePosition(a.x,a.y),l=new h(t.transformMousePosition(e.x,e.y)).difference(o);if("vertex"==i.typeName){if(!t.vertices[i.vindex].attr.draggable)return;t.vertices[i.vindex].add(l);var c=t.vertices[i.vindex],d={isTouchEvent:!0,params:{dragAmount:l.clone(),wasDragged:!0,mouseDownPos:s.clone(),mouseDragPos:s.clone().add(l),vertex:c}};c.listeners.fireDragEvent(d),t.redraw()}e=new h(a)}else if(2==r.touches.length){if(!this.config.enablePan)return;r.preventDefault(),r.stopPropagation(),t.setOffset(t.draw.offset.clone().addXY(r.deltaX,r.deltaY)),t.redraw()}},touchEnd:r=>{if(i&&"vertex"==i.typeName){if(!s)return;var n=t.vertices[i.vindex],h={isTouchEvent:!0,params:{dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:n}};e&&s&&s.distance(e)<.001?n.listeners.fireClickEvent(h):n.listeners.fireDragEndEvent(h)}a()},touchCancel:t=>{a()},multipointStart:e=>{r=t.draw.scale.clone()},multipointEnd:t=>{r=null},pinch:e=>{if(!this.config.enableZoom)return;const s=e.touches.item(0),i=e.touches.item(1);if(!(e.touches&&r&&s&&i))return;const n=new h(s.clientX,s.clientY),a=new h(i.clientX,i.clientY),o=new l(n,a).vertAt(.5);t.setZoom(r.x*e.zoom,r.y*e.zoom,o),t.redraw()}};if(window.createAlloyFinger){(0,window.createAlloyFinger)(this.eventCatcher?this.eventCatcher:this.canvas,o)}else new D(this.eventCatcher?this.eventCatcher:this.canvas,o)}catch(t){console.error("Failed to initialize AlloyFinger!"),console.error(t)}else globalThis.Touchy&&"function"==typeof globalThis.Touchy?console.error("[Deprecation] Found Touchy which is not supported any more. Please use AlloyFinger instead."):console.warn("Cannot initialize the touch handler. AlloyFinger is missig. Did you include it?")}else t.console.log("Touch interaction disabled.");this.config.enableKeys?this.keyHandler=new w({trackAll:!0}).down("escape",(function(){t.clearSelection(!0)})).down("shift",(function(){t.selectPolygon=new c,t.redraw()})).up("shift",(function(){null!=t.selectPolygon&&(t.selectVerticesInPolygon(t.selectPolygon),t.selectPolygon=null,t.redraw())})):t.console.log("Keyboard interaction disabled.")}createGUI(t){const e=globalThis.utils;if(e&&"function"==typeof e.createGUI)return this._gui=e.createGUI(this,t);throw"Cannot create dat.GUI or lil-gui instance; did you load the ./utils/creategui helper function an the dat.GUI/lil-gui library?"}getGUI(){return this._gui}}O.DEFAULT_CANVAS_WIDTH=1024,O.DEFAULT_CANVAS_HEIGHT=768,O.DEFAULT_CLICK_TOLERANCE=8,O.DEFAULT_TOUCH_TOLERANCE=32,O.Draggable=(k(I=class{constructor(t,e){this.item=t,this.typeName=e}isVertex(){return this.typeName==O.Draggable.VERTEX}setVIndex(t){return this.vindex=t,this}},"Draggable"),I.VERTEX="vertex",I),O.utils={safeMergeByKeys:(t,e)=>{for(var s in e)if(e.hasOwnProperty(s))if(t.hasOwnProperty(s)){const i=typeof t[s],r=e[s];try{t[s]="boolean"==i?"string"==typeof r?Boolean(!!JSON.parse(r)):r:"number"==i&&"string"==typeof r?Number(1*JSON.parse(r)):e[s]}catch(t){console.error("error in key ",s,r,t)}}else t[s]=e[s];return t},setCSSscale:(t,e,s)=>{t.style.transformOrigin="0 0",1==e&&1==s?t.style.removeProperty("transform"):t.style.transform="scale("+e+","+s+")"},fetch:{val:(t,e,s)=>t.hasOwnProperty(e)?void 0===t[e]?s:t[e]:s,num:(t,e,s)=>{if(!t.hasOwnProperty(e))return s;if("number"==typeof t[e])return t[e];try{return 1*JSON.parse(t[e])}catch(t){return s}},bool:(t,e,s)=>{if(!t.hasOwnProperty(e))return s;if("boolean"==typeof t[e])return t[e];try{return!!JSON.parse(t[e])}catch(t){return s}},func:(t,e,s)=>t.hasOwnProperty(e)?"function"!=typeof t[e]?s:t[e]:s},enableBezierPathAutoAdjust:t=>{for(var e=0;e<t.bezierCurves.length;e++)t.bezierCurves[e].startPoint.listeners.addDragListener((function(e){var s=t.locateCurveByStartPoint(e.params.vertex);t.bezierCurves[s].startPoint.addXY(-e.params.dragAmount.x,-e.params.dragAmount.y),t.moveCurvePoint(1*s,t.START_POINT,e.params.dragAmount),t.updateArcLengths()})),t.bezierCurves[e].startControlPoint.listeners.addDragListener((function(e){var s=t.locateCurveByStartControlPoint(e.params.vertex);t.bezierCurves[s].startPoint.attr.bezierAutoAdjust&&(t.adjustPredecessorControlPoint(1*s,!0,!1),t.updateArcLengths())})),t.bezierCurves[e].endControlPoint.listeners.addDragListener((function(e){var s=t.locateCurveByEndControlPoint(e.params.vertex);t.bezierCurves[s%t.bezierCurves.length].endPoint.attr.bezierAutoAdjust&&(t.adjustSuccessorControlPoint(1*s,!0,!1),t.updateArcLengths())})),e+1==t.bezierCurves.length&&t.bezierCurves[t.bezierCurves.length-1].endPoint.listeners.addDragListener((function(e){if(!t.adjustCircular){var s=t.locateCurveByEndPoint(e.params.vertex);t.moveCurvePoint(1*s,t.END_CONTROL_POINT,new h({x:e.params.dragAmount.x,y:e.params.dragAmount.y}))}t.updateArcLengths()}))}},exports.BezierPath=g,exports.Bounds=d,exports.Circle=r,exports.CircleSector=f,exports.CubicBezierCurve=u,exports.Grid=b,exports.KeyHandler=w,exports.Line=l,exports.MouseHandler=A,exports.PBImage=S,exports.PBText=T,exports.PlotBoilerplate=O,exports.Polygon=c,exports.Triangle=n,exports.UIDGenerator=e,exports.VEllipse=L,exports.VEllipseSector=E,exports.Vector=i,exports.VertTuple=o,exports.Vertex=h,exports.VertexAttr=t,exports.VertexListeners=s,exports.XMouseEvent=C,exports.XWheelEvent=P,exports.drawutils=y,exports.drawutilsgl=p,exports.drawutilssvg=x,exports.geomutils=a;
2
2
  //# sourceMappingURL=index.esm.min.js.map