plotboilerplate 1.17.0 → 1.17.1
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.
- package/changelog.md +16 -0
- package/dist/index.esm.js +42 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +45 -9
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/Bounds.d.ts +11 -0
- package/src/cjs/Bounds.js +14 -0
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +3 -1
- package/src/cjs/PlotBoilerplate.js +8 -1
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/draw.d.ts +5 -2
- package/src/cjs/draw.js +10 -4
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +4 -2
- package/src/cjs/drawgl.js +5 -2
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +4 -2
- package/src/cjs/drawutilssvg.js +8 -2
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +3 -1
- package/src/cjs/interfaces/DrawLib.js +1 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +2 -0
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/datastructures/Color.d.ts +3 -1
- package/src/cjs/utils/datastructures/Color.js +17 -6
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/esm/Bounds.d.ts +11 -0
- package/src/esm/Bounds.js +14 -0
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +3 -1
- package/src/esm/PlotBoilerplate.js +8 -1
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/draw.d.ts +5 -2
- package/src/esm/draw.js +9 -4
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +4 -2
- package/src/esm/drawgl.js +4 -2
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +4 -2
- package/src/esm/drawutilssvg.js +7 -2
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +3 -1
- package/src/esm/interfaces/DrawLib.js +1 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +2 -0
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/datastructures/Color.d.ts +3 -1
- package/src/esm/utils/datastructures/Color.js +17 -6
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/ts/Bounds.ts +15 -0
- package/src/ts/PlotBoilerplate.ts +8 -1
- package/src/ts/draw.ts +10 -4
- package/src/ts/drawgl.ts +4 -2
- package/src/ts/drawutilssvg.ts +7 -2
- package/src/ts/interfaces/DrawLib.ts +3 -1
- package/src/ts/interfaces/core.ts +3 -2
- package/src/ts/utils/datastructures/Color.ts +17 -6
package/dist/index.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{static next(){return""+t.current++}}t.current=0;class e{constructor(){for(var t in this.draggable=!0,this.selectable=!0,this.isSelected=!1,this.visible=!0,e.model)this[t]=e.model[t]}}e.model={draggable:!0,selectable:!0,isSelected:!1,visible:!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=t.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 e,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}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}toString(){return"("+this.x+","+this.y+")"}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)=>{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(e,s){this.className="Polygon",this.uid=t.next(),void 0===e&&(e=[]),this.vertices=e,this.isOpen=s}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}area(){return r.utils.area(this.vertices)}signedArea(){return r.utils.signedArea(this.vertices)}isClockwise(){return r.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}getEvenDistributionPolygon(t){if(t<=0)throw new Error("pointCount must be larger than zero; is "+t+".");const e=new r([],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 n=this.perimeter()/t,a=this.vertices.length;let h=1,o=new i(this.vertices[1]),l=s.distance(o),c=this.isOpen?a:a+1,d=n;for(var u=1;u<t&&h<c;)if(d<l){let t=s.clone().lerpAbs(o,d);e.vertices.push(t),d+=n,u++}else h++,s=o,o=new i(this.vertices[h%a]),d-=l,l=s.distance(o);return e}getBounds(){return n.computeFromVertices(this.vertices)}clone(){return new r(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 l.fromArray(s)}destroy(){for(var t=0;t<this.vertices.length;t++)this.vertices[t].destroy();this.isDestroyed=!0}}r.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 n{constructor(t,e){this.min=t,this.max=e,this.width=e.x-t.x,this.height=e.y-t.y}toPolygon(){return new r([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)}toString(){return`{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`}static computeFromVertices(t){if(0==t.length)return new n(new i(0,0),new i(0,0));let e,s=t[0].x,r=t[0].x,a=t[0].y,h=t[0].y;for(var o in t)e=t[o],s=Math.min(s,e.x),r=Math.max(r,e.x),a=Math.min(a,e.y),h=Math.max(h,e.y);return new n(new i(s,a),new i(r,h))}}class a{constructor(e,s,i){this.uid=t.next(),this.a=e,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=a.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);if(void 0!==e&&e){return Math.sqrt(a.vtutils.dist2(t,this.vertAt(s)))<i.EPSILON&&s>=0&&s<=1}return s>=0&&s<=1}getClosestPoint(t){var e=this.getClosestT(t);return this.vertAt(e)}pointDistance(t){return Math.sqrt(a.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}}a.vtutils={dist2:(t,e)=>(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)};class h extends a{constructor(t,e){super(t,e,((t,e)=>new h(t,e))),this.className="Vector"}perp(){var t=this.clone();return t.sub(this.a),(t=new h(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))}}h.utils={buildArrowHead:(t,e,s,r,n)=>{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}};class o{constructor(e,s,i,r){this.START_POINT=o.START_POINT,this.START_CONTROL_POINT=o.START_CONTROL_POINT,this.END_CONTROL_POINT=o.END_CONTROL_POINT,this.END_POINT=o.END_POINT,this.uid=t.next(),this.startPoint=e,this.startControlPoint=i,this.endPoint=s,this.endControlPoint=r,this.curveIntervals=30,this.segmentCache=[],this.segmentLengths=[],this.arcLength=null,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 n(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)}getSubCurveAt(t,e){const s=new h(this.getPointAt(t),this.getTangentAt(t)),i=new h(this.getPointAt(e),this.getTangentAt(e).inv());return s.b.add(s.a),i.b.add(i.a),s.scale(.33333333*(e-t)),i.scale(.33333333*(e-t)),new o(s.a,i.a,s.b,i.b)}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 o(this.getStartPoint().clone(),this.getEndPoint().clone(),this.getStartControlPoint().clone(),this.getEndControlPoint().clone())}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 o}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 o.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 o(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 o(t[0],t[1],t[2],t[3])}}o.START_POINT=0,o.START_CONTROL_POINT=1,o.END_CONTROL_POINT=2,o.END_POINT=3;class l{constructor(e){this.className="BezierPath",this.START_POINT=0,this.START_CONTROL_POINT=1,this.END_CONTROL_POINT=2,this.END_POINT=3,this.uid=t.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=l._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=l._locateUIndex(this,s),n=l._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 l.fromArray([o])}var c=[];if(r.i>n.i){o=this.bezierCurves[r.i].getSubCurveAt(a,0);c.push(o);for(var d=r.i-1;d>n.i;d--)c.push(this.bezierCurves[d].clone().reverse());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();c.push(this.bezierCurves[n.i].getSubCurveAt(1,h))}else{o=this.bezierCurves[r.i].getSubCurveAt(a,1);c.push(o);for(d=r.i+1;d<n.i&&d<this.bezierCurves.length;d++)c.push(this.bezierCurves[d].clone());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();c.push(this.bezierCurves[n.i].getSubCurveAt(0,h))}return l.fromArray(c)}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);l.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());l.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 n(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 l(void 0),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}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 l.fromArray(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 l(void 0),i=null,r=0;r<e.length;r++){var n;if(o.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=o.fromArray(e[r])}else n=o.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 l.fromReducedList(s,e)}static fromReducedList(t,e){var s,r,n,a,h=new l(null),c=0;do{0==c&&(s=new i(t[c],t[c+1])),r=new i(t[c+2],t[c+3]),n=new i(t[c+4],t[c+5]),a=new i(t[c+6],t[c+7]);var d=new o(s,a,r,n);h.bezierCurves.push(d),s=a,c+=6}while(c+2<t.length);return h.adjustCircular=e,e&&(h.bezierCurves[h.bezierCurves.length-1].endPoint=h.bezierCurves[0].startPoint),h.updateArcLengths(),h}}l.START_POINT=0,l.START_CONTROL_POINT=1,l.END_CONTROL_POINT=2,l.END_POINT=3;class c extends a{constructor(t,e){super(t,e,((t,e)=>new c(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)?void 0:new i(h,o)}}class d{constructor(e,s){this.className="Circle",this.uid=t.next(),this.center=e,this.radius=s}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 h(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),n=(this.radius*this.radius-t.radius*t.radius+r*r)/(2*r),a=Math.sqrt(this.radius*this.radius-n*n),h=s.clone().scale(n/r,e),o=h.x+a*(s.y-e.y)/r,l=h.y-a*(s.x-e.x)/r,d=h.x-a*(s.y-e.y)/r,u=h.y+a*(s.x-e.x)/r;return new c(new i(o,l),new i(d,u))}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(e,s,i){this.className="CircleSector",this.uid=t.next(),this.circle=e,this.startAngle=s,this.endAngle=i}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){this.svgNode=t,this.offset=new i(0,0).set(e),this.scale=new i(1,1).set(s),this.fillShapes=n,this.isSecondary=h,this.drawlibConfiguration={},this.cache=new Map,this.setSize(r),h?(this.gNode=o,this.bufferGNode=l,this.nodeDefs=c,this.bufferedNodeDefs=d):(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);const e={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.nodeStyle.innerHTML=s.join("\n")}addDefsNode(){this.nodeDefs=this.createSVGNode("defs"),this.bufferedNodeDefs=this.createSVGNode("defs"),this.svgNode.appendChild(this.nodeDefs)}addCustomStyleDefs(t){const e=[];t.forEach(((t,s)=>{e.push(s+" { "+t+" }")})),this.nodeStyle.innerHTML+="\n/* Custom styles */\n"+e.join("\n")}findElement(t,e){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){return this.curClassName?t.setAttribute("class",`${e} ${this.curClassName}`):t.setAttribute("class",e),t.setAttribute("fill",this.fillShapes?s:"none"),t.setAttribute("stroke",this.fillShapes?"none":s),t.setAttribute("stroke-width",""+(i||1)),this.curId&&t.setAttribute("id",""+this.curId),t.parentNode||this.bufferGNode.appendChild(t),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,null,!0,this.gNode,this.bufferGNode,this.nodeDefs,this.bufferedNodeDefs)}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.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}_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){const r=this.makeNode("line");return r.setAttribute("x1",""+this._x(t.x)),r.setAttribute("y1",""+this._y(t.y)),r.setAttribute("x2",""+this._x(e.x)),r.setAttribute("y2",""+this._y(e.y)),this._bindFillDraw(r,"line",s,i||1)}arrow(t,e,s,r){const n=this.makeNode("path");var a=i.utils.buildArrowHead(t,e,8,this.scale.x,this.scale.y);const h=["M",this._x(t.x),this._y(t.y)];for(var o=0;o<=a.length;o++)h.push("L"),h.push(this.offset.x+a[o%a.length].x),h.push(this.offset.y+a[o%a.length].y);return n.setAttribute("d",h.join(" ")),this._bindFillDraw(n,"arrow",s,r||1)}image(t,e,s){const i=this.makeNode("image"),r=t=>{if(t.naturalWidth){const r=s.x/t.naturalWidth,n=s.y/t.naturalHeight;i.setAttribute("width",""+t.naturalWidth*this.scale.x),i.setAttribute("height",""+t.naturalHeight*this.scale.y),i.setAttribute("display",null),i.setAttribute("transform",`translate(${this._x(e.x)} ${this._y(e.y)}) scale(${r} ${n})`)}};return t.addEventListener("load",(e=>{r(t)})),i.setAttribute("x","0"),i.setAttribute("y","0"),i.setAttribute("display","none"),r(t),i.setAttribute("href",t.src),this._bindFillDraw(i,"image",null,null)}texturedPoly(e,s,r,n,a){r.getBounds();const h=new i(s.min).clone().rotate(a,n);n.clone().add(h.difference(s.min).inv());const o=this.makeNode("clipPath"),l="clippath_"+t.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",e.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){if(t instanceof o)return this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n);const a=this.makeNode("path"),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 a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"cubierBezier",r,n)}cubicBezierPath(t,e,s){const i=this.makeNode("path");if(!t||0==t.length)return i;const r=["M",this._x(t[0].x),this._y(t[0].y)];for(var n,a,h,o=1;o<t.length;o+=3)a=t[o],h=t[o+1],n=t[o+2],r.push("C",this._x(a.x),this._y(a.y),this._x(h.x),this._y(h.y),this._x(n.x),this._y(n.y));return i.setAttribute("d",r.join(" ")),this._bindFillDraw(i,"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(192,192,192)")}dot(t,e){const s=this.makeNode("line");return 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){const r=this.makeNode("circle");return r.setAttribute("cx",""+this._x(t.x)),r.setAttribute("cy",""+this._y(t.y)),r.setAttribute("r",""+e*this.scale.x),this._bindFillDraw(r,"circle",s,i||1)}circleArc(t,e,s,i,r,n){const a=this.makeNode("path"),h=u.circleSectorUtils.describeSVGArc(this._x(t.x),this._y(t.y),e*this.scale.x,s,i);return a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"circleArc",r,n||1)}ellipse(t,e,s,i,r,n){void 0===n&&(n=0);const a=this.makeNode("ellipse");return a.setAttribute("cx",""+this._x(t.x)),a.setAttribute("cy",""+this._y(t.y)),a.setAttribute("rx",""+e*this.scale.x),a.setAttribute("ry",""+s*this.scale.y),a.setAttribute("transform",`rotate(${180*n/Math.PI} ${this._x(t.x)} ${this._y(t.y)})`),this._bindFillDraw(a,"ellipse",i,r||1)}square(t,e,s,i){const r=this.makeNode("rectangle");return r.setAttribute("x",""+this._x(t.x-e/2)),r.setAttribute("y",""+this._y(t.y-e/2)),r.setAttribute("width",""+e*this.scale.x),r.setAttribute("height",""+e*this.scale.y),this._bindFillDraw(r,"square",s,i||1)}rect(t,e,s,i,r){const n=this.makeNode("rect");return n.setAttribute("x",""+this._x(t.x)),n.setAttribute("y",""+this._y(t.y)),n.setAttribute("width",""+e*this.scale.x),n.setAttribute("height",""+s*this.scale.y),this._bindFillDraw(n,"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){const r=this.makeNode("path");if(0==t.length)return r;const n=["M",this._x(t[0].x),this._y(t[0].y)];for(var a=t.length,h=1;h<a;h++)n.push("L",this._x(t[h].x),this._y(t[h].y));return e||n.push("Z"),r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"polygon",s,i||1)}text(t,e,s,i){var r,n;const a=(i=i||{}).color||"black",h=(null!==(n=null!==(r=i.lineHeight)&&void 0!==r?r:i.fontSize)&&void 0!==n?n:0)*this.scale.x,o="left"===i.textAlign||"start"===i.textAlign?"start":"center"===i.textAlign?"middle":"right"===i.textAlign||"end"===i.textAlign?"end":"start",l=`${this._x(e)}px ${this._y(s)}px`,c=`translate(${this._x(e)} ${this._y(s)+h/2})`,d=i.rotation?`rotate(${i.rotation*g} 0 0)`:"",u=this.makeNode("g"),f=this.curId;this.curId=f+"_text";const x=this.makeNode("text");return u.appendChild(x),x.setAttribute("font-family",i.fontFamily),x.setAttribute("font-size",i.fontSize?""+i.fontSize*this.scale.x:null),x.setAttribute("font-style",i.fontStyle?""+i.fontStyle:null),x.setAttribute("font-weight",i.fontWeight?""+i.fontWeight:null),x.setAttribute("text-anchor",o),x.setAttribute("transform-origin","0 0"),x.setAttribute("transform",d),u.setAttribute("transform-origin",l),u.setAttribute("transform",c),x.innerHTML=t,this.curId=f,this._bindFillDraw(u,"text",a,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"),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=void 0;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=void 0}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;case"z":case"Z":h++;break;default:h++}}}}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}beginDrawCycle(t){}endDrawCycle(t){}setConfiguration(t){this.ctx.globalCompositeOperation=t.blendMode}setCurrentId(t){}setCurrentClassName(t){}line(t,e,s,i){this.ctx.save(),this.ctx.beginPath(),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){this.ctx.save(),this.ctx.beginPath();var n=i.utils.buildArrowHead(t,e,8,this.scale.x,this.scale.y);this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y);for(var a=0;a<n.length;a++)this.ctx.lineTo(this.offset.x+n[a].x,this.offset.y+n[a].y);this.ctx.lineTo(this.offset.x+n[0].x,this.offset.y+n[0].y),this.ctx.lineWidth=r||1,this._fillOrDraw(s),this.ctx.restore()}image(t,e,s){t.complete&&t.naturalWidth&&(this.ctx.save(),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(),h=r.clone().difference(a.getCenter());a.getCenter().sub(h);var o=new i(e.width,e.height),l=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,l.x,l.y,o.x,o.y),this.ctx.restore()}_texturedPoly(t,e,s,r,n,a={x:0,y:0}){var h=s.getBounds(),o=r.clone().difference(h.getCenter()),l=a?r.difference(a):{x:0,y:0},c=h.getCenter().sub(o),d=new i(e.width,e.height),u=new i(-e.width/2,-e.height/2).sub(o);this.ctx.save(),this.ctx.translate(this.offset.x+(c.x-0*l.x+0*u.x)*this.scale.x,this.offset.y+(c.y-0*l.y+0*u.y)*this.scale.y),this.ctx.rotate(n),x.helpers.clipPoly(this.ctx,{x:(1*-o.x-c.x-l.x)*this.scale.x,y:(1*-o.y-c.y-l.y)*this.scale.y},this.scale,s.vertices),this.ctx.drawImage(t,0,0,t.naturalWidth-1,t.naturalHeight-1,(-r.x+1*u.x-1*l.x)*this.scale.x,(-r.y+1*u.y-1*l.y)*this.scale.y,d.x*this.scale.x,d.y*this.scale.y),this.ctx.restore()}rect(t,e,s,i,r){this.ctx.save(),this.ctx.beginPath(),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()}_fillOrDraw(t){this.fillShapes?(this.ctx.fillStyle=t,this.ctx.fill()):(this.ctx.strokeStyle=t,this.ctx.stroke())}cubicBezier(t,e,s,i,r,n){t instanceof o?this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n):(this.ctx.save(),this.ctx.beginPath(),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){this.ctx.save(),this.ctx.beginPath(),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){if(t&&0!=t.length){var i,r,n;this.ctx.save(),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var a=1;a<t.length;a+=3)r=t[a],n=t[a+1],i=t[a+2],this.ctx.bezierCurveTo(this.offset.x+r.x*this.scale.x,this.offset.y+r.y*this.scale.y,this.offset.x+n.x*this.scale.x,this.offset.y+n.y*this.scale.y,this.offset.x+i.x*this.scale.x,this.offset.y+i.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,"rgb(192,192,192)")}dot(t,e){this.ctx.save(),this.ctx.beginPath(),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.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){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.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){void 0===n&&(n=0),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){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.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.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.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.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.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.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.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){this.polyline(t.vertices,t.isOpen,e,s)}polyline(t,e,s,i){if(!(t.length<=1)){this.ctx.save(),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 r=0;r<t.length;r++)this.ctx.lineTo(this.offset.x+t[r].x*this.scale.x,this.offset.y+t[r].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),this.ctx.strokeStyle=e,this.ctx.lineWidth=s||1,this.fillShapes?(this.ctx.fillStyle=e,this.ctx.fill(new Path2D(r.join(" ")))):(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){}image(t,e,s){}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 m{constructor(e,s,i){this.className="Triangle",this.uid=t.next(),this.a=e,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 m(t[0],t[1],t[2])}getArea(){return Math.abs(m.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)<m.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 n(new i(m.utils.min3(this.a.x,this.b.x,this.c.x),m.utils.min3(this.a.y,this.b.y,this.c.y)),new i(m.utils.max3(this.a.x,this.b.x,this.c.x),m.utils.max3(this.a.y,this.b.y,this.c.y)))}toPolygon(){return new r([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 m.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 c(this.a,this.b),e=new c(this.b,this.c),s=new c(this.c,this.a),i=p.nsectAngle(this.b,this.a,this.c,2)[0],r=p.nsectAngle(this.c,this.b,this.a,2)[0],n=i.intersection(r),a=t.getClosestPoint(n),h=e.getClosestPoint(n),o=s.getClosestPoint(n);return new m(a,h,o)}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}}m.EPSILON=1e-6,m.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=m.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 p={nsectAngle(t,e,s,i){const r=new m(t,e,s),n=new c(t,e),a=new c(t,s);var h=n.angle(a);const o=r.determinant()>0;h<0&&(h=2*Math.PI+h),o||(h=-1*(2*Math.PI-h));const l=Math.max(n.length(),a.length())/n.length();for(var d=[],u=1;u<i;u++)d.push(new c(t,e.clone().rotate(h/i*-u,t)).scale(l));return d},wrapMax:(t,e)=>(e+t%e)%e,wrapMinMax:(t,e,s)=>e+p.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=null,this.mouseDragPos=null,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){const s=this.relPos(t),i=t;return i.params={element:this.element,name:e,isTouchEvent:!1,pos:s,button:this.mouseButton,leftButton:0==this.mouseButton,middleButton:1==this.mouseButton,rightButton:2==this.mouseButton,mouseDownPos:this.mouseDownPos,draggedFrom:this.mouseDragPos,wasDragged:null!=this.mouseDownPos&&(this.mouseDownPos.x!=s.x||this.mouseDownPos.y!=s.y),dragAmount:null!=this.mouseDownPos?{x:s.x-this.mouseDragPos.x,y:s.y-this.mouseDragPos.y}:{x:0,y:0}},i}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 T{constructor(e,s,i){this.className="PBImage",this.uid=t.next(),this.image=e,this.upperLeft=s,this.lowerRight=i}destroy(){this.upperLeft.destroy(),this.lowerRight.destroy(),this.isDestroyed=!0}}class S{constructor(e,s,r){this.className="PBText",this.uid=t.next(),this.text=e,this.anchor=null!=s?s:new i,this.color=r.color,this.fontFamily=r.fontFamily,this.fontSize=r.fontSize,this.fontStyle=r.fontStyle,this.fontWeight=r.fontWeight,this.lineHeight=r.lineHeight,this.textAlign=r.textAlign,this.rotation=r.rotation}destroy(){this.anchor.destroy(),this.isDestroyed=!0}}const _=t=>Math.sqrt(t.x*t.x+t.y*t.y),N=(t,e)=>{var s=((t,e)=>{const s=_(t)*_(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=_(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=_(a)/this.pinchStartLen,this.pinch.dispatch(e,this.element)),e.angle=N(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(e,s,i){this.className="VEllipse",this.uid=t.next(),this.center=e,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 c(s,i[0]).angle(),n=r+(new c(s,i[1]).angle()-r)/2,a=s.clone().addX(50).clone().rotate(n,s),o=s.clone().addX(50).clone().rotate(Math.PI+n,s);return this.center.distance(a)<this.center.distance(o)?new h(s,o):new h(s,a)}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],l=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=l.difference(s),e=new o(l.clone(),s.clone(),l.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=l.difference(a),d=s.difference(a),u=new o(l.clone(),s.clone(),l.clone().add(c.scale(e)),s.clone().add(d.scale(e)));n.push(u)}l=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(e,s,i){this.className="VEllipseSector",this.uid=t.next(),this.ellipse=e,this.startAngle=p.wrapMinMax(s,0,2*Math.PI),this.endAngle=p.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 l=[];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 o(d.clone(),s.clone(),d.clone().addXY(.333*t.x,.333*t.y),s.clone().addXY(.333*-t.x,.333*-t.y));l.push(e)}else{let t=n.intersection(a),i=d.difference(t),r=s.difference(t),h=new o(d.clone(),s.clone(),d.clone().add(i.scale(e)),s.clone().add(r.scale(e)));l.push(h)}d=s,c=t}return l}destroy(){this.ellipse.destroy(),this.isDestroyed=!0}}var I;E.ellipseSectorUtils={describeSVGArc:(t,e,s,r,n,a,h,o)=>{void 0===o&&(o={moveToStart:!0}),void 0===h&&(h=0),n=p.wrapMax(n,2*Math.PI),a=p.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=p.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,n,a,h,o,l){const d=Math.abs,u=Math.sin,g=Math.cos,f=Math.sqrt,x=t=>t*t,v=u(n),y=g(n),m=y*(t-o)/2+v*(e-l)/2,p=-v*(t-o)/2+y*(e-l)/2,b=x(m),w=x(p),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 T=a===h?-1:1,S=f((C*P-C*w-P*b)/(C*w+P*b))*T,_=S*(s*p)/r,N=S*(-r*m)/s,z=new i(y*_-v*N+(t+o)/2,v*_+y*N+(e+l)/2),M=z.clone().addXY(s,r),D=new L(z,M,0);D.rotate(n);const I=new c(D.center,new i(t,e)).angle(),k=new c(D.center,new i(o,l)).angle();return new E(D,I-n,k-n)}};class k{constructor(t){if(this.renderTime=0,e.model={bezierAutoAdjust:!1,renderTime:0,selectable:!0,isSelected:!1,draggable:!0,visible:!0},void 0===t.canvas)throw"No canvas specified.";const s=k.utils.fetch;this.config={canvas:t.canvas,fullSize:s.val(t,"fullSize",!0),fitToParent:s.bool(t,"fitToParent",!0),scaleX:s.num(t,"scaleX",1),scaleY:s.num(t,"scaleY",1),offsetX:s.num(t,"offsetX",0),offsetY:s.num(t,"offsetY",0),rasterGrid:s.bool(t,"rasterGrid",!0),rasterScaleX:s.num(t,"rasterScaleX",1),rasterScaleY:s.num(t,"rasterScaleY",1),rasterAdjustFactor:s.num(t,"rasterAdjustdFactror",2),drawOrigin:s.bool(t,"drawOrigin",!1),autoAdjustOffset:s.val(t,"autoAdjustOffset",!0),offsetAdjustXPercent:s.num(t,"offsetAdjustXPercent",50),offsetAdjustYPercent:s.num(t,"offsetAdjustYPercent",50),backgroundColor:t.backgroundColor||"#ffffff",redrawOnResize:s.bool(t,"redrawOnResize",!0),defaultCanvasWidth:s.num(t,"defaultCanvasWidth",k.DEFAULT_CANVAS_WIDTH),defaultCanvasHeight:s.num(t,"defaultCanvasHeight",k.DEFAULT_CANVAS_HEIGHT),canvasWidthFactor:s.num(t,"canvasWidthFactor",1),canvasHeightFactor:s.num(t,"canvasHeightFactor",1),cssScaleX:s.num(t,"cssScaleX",1),cssScaleY:s.num(t,"cssScaleY",1),cssUniformScale:s.bool(t,"cssUniformScale",!0),saveFile:()=>{n.hooks.saveFile(n)},setToRetina:()=>{n._setToRetina()},autoDetectRetina:s.bool(t,"autoDetectRetina",!0),enableSVGExport:s.bool(t,"enableSVGExport",!0),preClear:s.func(t,"preClear",null),preDraw:s.func(t,"preDraw",null),postDraw:s.func(t,"postDraw",null),enableMouse:s.bool(t,"enableMouse",!0),enableTouch:s.bool(t,"enableTouch",!0),enableKeys:s.bool(t,"enableKeys",!0),enableMouseWheel:s.bool(t,"enableMouseWheel",!0),enableGL:s.bool(t,"enableGL",!1)},this.drawConfig={drawVertices:!0,drawBezierHandleLines:s.bool(t,"drawBezierHandleLines",!0),drawBezierHandlePoints:s.bool(t,"drawBezierHandlePoints",!0),drawHandleLines:s.bool(t,"drawHandleLines",!0),drawHandlePoints:s.bool(t,"drawHandlePoints",!0),drawGrid:s.bool(t,"drawGrid",!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}},this.grid=new b(new i(0,0),new i(50,50)),this.canvasSize={width:k.DEFAULT_CANVAS_WIDTH,height:k.DEFAULT_CANVAS_HEIGHT};const r="string"==typeof t.canvas?document.querySelector(t.canvas):t.canvas;if("canvas"===r.tagName.toLowerCase())if(this.canvas=r,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"!==r.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=r,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}this.draw.scale.set(this.config.scaleX,this.config.scaleY),this.fill.scale.set(this.config.scaleX,this.config.scaleY),this.vertices=[],this.selectPolygon=null,this.draggedElements=[],this.drawables=[],this.console=console,this.hooks={saveFile:k._saveFile};var n=this;globalThis.addEventListener("resize",(()=>n.resizeCanvas())),this.resizeCanvas(),t.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),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([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(){this.config.cssUniformScale?k.utils.setCSSscale(this.canvas,this.config.cssScaleX,this.config.cssScaleX):k.utils.setCSSscale(this.canvas,this.config.cssScaleX,this.config.cssScaleY)}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 c)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b);else if(t instanceof h)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 r){this.drawables.push(t);for(s=0;s<t.vertices.length;s++)this.vertices.push(t.vertices[s])}else if(t instanceof m)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b),this.vertices.push(t.c);else if(t instanceof l){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;k.utils.enableBezierPathAutoAdjust(t)}else if(t instanceof T)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 S))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 n=0;n<t.length;n++)this.remove(t[n],!1,s);e&&this.redraw()}else{t instanceof i&&(this.removeVertex(t,!1),e&&this.redraw());for(n=0;n<this.drawables.length;n++)if(this.drawables[n]===t||this.drawables[n].uid===t.uid){if(this.drawables.splice(n,1),s)if(t instanceof c)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1);else if(t instanceof h)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 r)for(n=0;n<t.vertices.length;n++)this.removeVertex(t.vertices[n],!1);else if(t instanceof m)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1),this.removeVertex(t.c,!1);else if(t instanceof l)for(n=0;n<t.bezierCurves.length;n++)this.removeVertex(t.bezierCurves[n].startPoint,!1),this.removeVertex(t.bezierCurves[n].startControlPoint,!1),this.removeVertex(t.bezierCurves[n].endControlPoint,!1),n+1==t.bezierCurves.length&&this.removeVertex(t.bezierCurves[n].endPoint,!1);else t instanceof T?(this.removeVertex(t.upperLeft,!1),this.removeVertex(t.lowerRight,!1)):t instanceof S&&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=this.locatePointNear(this.transformMousePosition(t.x,t.y),e/Math.min(this.config.cssScaleX,this.config.cssScaleY));if(s&&"vertex"==s.typeName)return this.vertices[s.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,"#000000")}_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.draw.setCurrentClassName(r.className),this.drawDrawable(r,t,e,s)}}drawDrawable(t,e,s,n){if(t instanceof l)for(var a in t.bezierCurves){if(s.cubicBezier(t.bezierCurves[a].startPoint,t.bezierCurves[a].endPoint,t.bezierCurves[a].startControlPoint,t.bezierCurves[a].endControlPoint,this.drawConfig.bezier.color,this.drawConfig.bezier.lineWidth),this.drawConfig.drawBezierHandlePoints&&this.drawConfig.drawHandlePoints){if(t.bezierCurves[a].startPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?n:s;e.setCurrentId(t.uid+"_h0"),e.setCurrentClassName(t.className+"-start-handle"),t.bezierCurves[a].startPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[a].startPoint,5,this._handleColor(t.bezierCurves[a].startPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[a].startPoint,7,this._handleColor(t.bezierCurves[a].startPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[a].startPoint.attr.renderTime=e,t.bezierCurves[a].endPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?n:s;e.setCurrentId(t.uid+"_h0"),e.setCurrentClassName(t.className+"-start-handle"),t.bezierCurves[a].endPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[a].endPoint,5,this._handleColor(t.bezierCurves[a].endPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[a].endPoint,7,this._handleColor(t.bezierCurves[a].endPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[a].startControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?n:s;e.setCurrentId(t.uid+"_h2"),e.setCurrentClassName(t.className+"-start-control-handle"),e.circleHandle(t.bezierCurves[a].startControlPoint,3,this._handleColor(t.bezierCurves[a].startControlPoint,this.drawConfig.bezier.controlVertex.color))}if(t.bezierCurves[a].endControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?n:s;e.setCurrentId(t.uid+"_h3"),e.setCurrentClassName(t.className+"-end-control-handle"),e.circleHandle(t.bezierCurves[a].endControlPoint,3,this._handleColor(t.bezierCurves[a].endControlPoint,this.drawConfig.bezier.controlVertex.color))}t.bezierCurves[a].startPoint.attr.renderTime=e,t.bezierCurves[a].endPoint.attr.renderTime=e,t.bezierCurves[a].startControlPoint.attr.renderTime=e,t.bezierCurves[a].endControlPoint.attr.renderTime=e}else t.bezierCurves[a].startPoint.attr.renderTime=e,t.bezierCurves[a].endPoint.attr.renderTime=e,t.bezierCurves[a].startControlPoint.attr.renderTime=e,t.bezierCurves[a].endControlPoint.attr.renderTime=e;this.drawConfig.drawBezierHandleLines&&this.drawConfig.drawHandleLines&&(s.setCurrentId(t.uid+"_l0"),s.setCurrentClassName(t.className+"-start-line"),s.line(t.bezierCurves[a].startPoint,t.bezierCurves[a].startControlPoint,this.drawConfig.bezier.handleLine.color,this.drawConfig.bezier.handleLine.lineWidth),s.setCurrentId(t.uid+"_l1"),s.setCurrentClassName(t.className+"-end-line"),s.line(t.bezierCurves[a].endPoint,t.bezierCurves[a].endControlPoint,this.drawConfig.bezier.handleLine.color,this.drawConfig.bezier.handleLine.lineWidth))}else if(t instanceof r){if(s.polygon(t,this.drawConfig.polygon.color,this.drawConfig.polygon.lineWidth),!this.drawConfig.drawHandlePoints)for(var o in t.vertices)t.vertices[o].attr.renderTime=e}else if(t instanceof m)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.line(t.center.clone().add(0,t.signedRadiusV()).rotate(t.rotation,t.center),t.axis,"#c8c8c8"),s.setCurrentId(t.uid+"_e1"),s.setCurrentClassName(t.className+"-h-line"),s.line(t.center.clone().add(t.signedRadiusH(),0).rotate(t.rotation,t.center),t.axis,"#c8c8c8")),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 c?(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 h?(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 T?(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)),n.setCurrentId(t.uid),n.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 S?(n.setCurrentId(t.uid),n.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?n: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),n.setCurrentClassName(null),n.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.drawGrid(e),this.config.drawOrigin&&this.drawOrigin(e),this.drawDrawables(t,e,s),this.drawVertices(t,e),this.drawSelectPolygon(e),e.setCurrentId(void 0),e.setCurrentClassName(void 0)}clear(){this.draw.clear(this.config.backgroundColor)}clearSelection(t){for(var e in this.vertices)this.vertices[e].attr.isSelected=!1;return t&&this.redraw(),this}viewport(){return new n(this.transformMousePosition(0,0),this.transformMousePosition(this.canvasSize.width*this.config.cssScaleX,this.canvasSize.height*this.config.cssScaleY))}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(){const t=this,e=(e,s)=>{e*=t.config.canvasWidthFactor,s*=t.config.canvasHeightFactor,t.canvasSize.width=e,t.canvasSize.height=s,t.canvas instanceof HTMLCanvasElement?(t.canvas.width=e,t.canvas.height=s):t.canvas instanceof SVGElement?(this.canvas.setAttribute("viewBox",`0 0 ${e} ${s}`),this.canvas.setAttribute("width",""+e),this.canvas.setAttribute("height",""+s),this.draw.setSize(t.canvasSize),this.eventCatcher.style.width=e+"px",this.eventCatcher.style.height=s+"px"):console.error("Error: cannot resize canvas element because it seems neither be a HTMLCanvasElement nor an SVGElement."),t.config.autoAdjustOffset&&t.adjustOffset(!1)};if(t.config.fullSize&&!t.config.fitToParent){var s=globalThis.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,i=globalThis.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;t.canvas.style.position="absolute",t.canvas.style.width=t.config.canvasWidthFactor*s+"px",t.canvas.style.height=t.config.canvasWidthFactor*i+"px",t.canvas.style.top="0px",t.canvas.style.left="0px",e(s,i)}else if(t.config.fitToParent){t.canvas.style.position="absolute";const s=this.getAvailableContainerSpace();t.canvas.style.width=t.config.canvasWidthFactor*s.width+"px",t.canvas.style.height=t.config.canvasHeightFactor*s.height+"px",t.canvas.style.top=null,t.canvas.style.left=null,e(s.width,s.height)}else t.canvas.style.width=null,t.canvas.style.height=null,e(t.config.defaultCanvasWidth,t.config.defaultCanvasHeight);t.config.redrawOnResize&&t.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 k.Draggable(r,k.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),k.DEFAULT_CLICK_TOLERANCE/Math.min(e.config.cssScaleX,e.config.cssScaleY));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.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),k.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 k.Draggable(e.vertices[i],k.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.isDown("alt")||this.keyHandler.isDown("spacebar"))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){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 r=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,n=null,a=null;const h=()=>{e=null,s=null,n=null,a=null,t.draggedElements=[]},o={touchStart:a=>{if(1==a.touches.length&&(e=new i(r({x:a.touches[0].clientX,y:a.touches[0].clientY})),s=new i(r({x:a.touches[0].clientX,y:a.touches[0].clientY})),(n=t.locatePointNear(t.transformMousePosition(e.x,e.y),k.DEFAULT_TOUCH_TOLERANCE/Math.min(t.config.cssScaleX,t.config.cssScaleY)))&&"vertex"==n.typeName)){var h=t.vertices[n.vindex],o={params:{isTouchEvent:!0,dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:h}};t.draggedElements=[n],h.listeners.fireDragStartEvent(o)}},touchMove:a=>{if(1==a.touches.length&&n){a.preventDefault(),a.stopPropagation();var h=r({x:a.touches[0].clientX,y:a.touches[0].clientY}),o=t.transformMousePosition(h.x,h.y),l=new i(t.transformMousePosition(e.x,e.y)).difference(o);if("vertex"==n.typeName){if(!t.vertices[n.vindex].attr.draggable)return;t.vertices[n.vindex].add(l);var c=t.vertices[n.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 2==a.touches.length&&(a.preventDefault(),a.stopPropagation(),t.setOffset(t.draw.offset.clone().addXY(a.deltaX,a.deltaY)),t.redraw())},touchEnd:i=>{if(n&&"vertex"==n.typeName){var r=t.vertices[n.vindex],a={isTouchEvent:!0,params:{dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:r}};e&&s&&s.distance(e)<.001?r.listeners.fireClickEvent(a):r.listeners.fireDragEndEvent(a)}h()},touchCancel:t=>{h()},multipointStart:e=>{a=t.draw.scale.clone()},multipointEnd:t=>{a=null},pinch:e=>{const s=new i(e.touches.item(0).clientX,e.touches.item(0).clientY),r=new i(e.touches.item(1).clientX,e.touches.item(1).clientY),n=new c(s,r).vertAt(.5);t.setZoom(a.x*e.zoom,a.y*e.zoom,n),t.redraw()}};window.createAlloyFinger?window.createAlloyFinger(this.eventCatcher?this.eventCatcher:this.canvas,o):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 r,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){if(globalThis.utils&&"function"==typeof globalThis.utils.createGUI)return globalThis.utils.createGUI(this,t);throw"Cannot create dat.GUI instance; did you load the ./utils/creategui helper function an the dat.GUI library?"}}k.DEFAULT_CANVAS_WIDTH=1024,k.DEFAULT_CANVAS_HEIGHT=768,k.DEFAULT_CLICK_TOLERANCE=8,k.DEFAULT_TOUCH_TOLERANCE=32,k.Draggable=((I=class{constructor(t,e){this.item=t,this.typeName=e}isVertex(){return this.typeName==k.Draggable.VERTEX}setVIndex(t){return this.vindex=t,this}}).VERTEX="vertex",I),k.utils={safeMergeByKeys:(t,e)=>{for(var s in e)if(e.hasOwnProperty(s))if(t.hasOwnProperty(s)){var i=typeof t[s];try{"boolean"==i?t[s]=!!JSON.parse(e[s]):"number"==i?t[s]=1*JSON.parse(e[s]):("function"==i&&e[s],t[s]=e[s])}catch(t){console.error("error in key ",s,e[s],t)}}else t[s]=e[s];return t},setCSSscale:(t,e,s)=>{t.style["transform-origin"]="0 0",t.style.transform=1==e&&1==s?null:"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=l,exports.Bounds=n,exports.Circle=d,exports.CircleSector=u,exports.CubicBezierCurve=o,exports.Grid=b,exports.KeyHandler=w,exports.Line=c,exports.MouseHandler=A,exports.PBImage=T,exports.PBText=S,exports.PlotBoilerplate=k,exports.Polygon=r,exports.Triangle=m,exports.UIDGenerator=t,exports.VEllipse=L,exports.VEllipseSector=E,exports.Vector=h,exports.VertTuple=a,exports.Vertex=i,exports.VertexAttr=e,exports.VertexListeners=s,exports.XMouseEvent=C,exports.XWheelEvent=P,exports.drawutils=x,exports.drawutilsgl=v,exports.drawutilssvg=f,exports.geomutils=p;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{static next(){return""+t.current++}}t.current=0;class e{constructor(){for(var t in this.draggable=!0,this.selectable=!0,this.isSelected=!1,this.visible=!0,e.model)this[t]=e.model[t]}}e.model={draggable:!0,selectable:!0,isSelected:!1,visible:!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=t.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 e,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}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}toString(){return"("+this.x+","+this.y+")"}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)=>{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(e,s){this.className="Polygon",this.uid=t.next(),void 0===e&&(e=[]),this.vertices=e,this.isOpen=s}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}area(){return r.utils.area(this.vertices)}signedArea(){return r.utils.signedArea(this.vertices)}isClockwise(){return r.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}getEvenDistributionPolygon(t){if(t<=0)throw new Error("pointCount must be larger than zero; is "+t+".");const e=new r([],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 n=this.perimeter()/t,a=this.vertices.length;let h=1,o=new i(this.vertices[1]),l=s.distance(o),c=this.isOpen?a:a+1,d=n;for(var u=1;u<t&&h<c;)if(d<l){let t=s.clone().lerpAbs(o,d);e.vertices.push(t),d+=n,u++}else h++,s=o,o=new i(this.vertices[h%a]),d-=l,l=s.distance(o);return e}getBounds(){return n.computeFromVertices(this.vertices)}clone(){return new r(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 l.fromArray(s)}destroy(){for(var t=0;t<this.vertices.length;t++)this.vertices[t].destroy();this.isDestroyed=!0}}r.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 n{constructor(t,e){this.min=t,this.max=e,this.width=e.x-t.x,this.height=e.y-t.y}toPolygon(){return new r([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)}toString(){return`{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`}static computeFromVertices(t){if(0==t.length)return new n(new i(0,0),new i(0,0));let e,s=t[0].x,r=t[0].x,a=t[0].y,h=t[0].y;for(var o in t)e=t[o],s=Math.min(s,e.x),r=Math.max(r,e.x),a=Math.min(a,e.y),h=Math.max(h,e.y);return new n(new i(s,a),new i(r,h))}}class a{constructor(e,s,i){this.uid=t.next(),this.a=e,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=a.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);if(void 0!==e&&e){return Math.sqrt(a.vtutils.dist2(t,this.vertAt(s)))<i.EPSILON&&s>=0&&s<=1}return s>=0&&s<=1}getClosestPoint(t){var e=this.getClosestT(t);return this.vertAt(e)}pointDistance(t){return Math.sqrt(a.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}}a.vtutils={dist2:(t,e)=>(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)};class h extends a{constructor(t,e){super(t,e,((t,e)=>new h(t,e))),this.className="Vector"}perp(){var t=this.clone();return t.sub(this.a),(t=new h(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))}}h.utils={buildArrowHead:(t,e,s,r,n)=>{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}};class o{constructor(e,s,i,r){this.START_POINT=o.START_POINT,this.START_CONTROL_POINT=o.START_CONTROL_POINT,this.END_CONTROL_POINT=o.END_CONTROL_POINT,this.END_POINT=o.END_POINT,this.uid=t.next(),this.startPoint=e,this.startControlPoint=i,this.endPoint=s,this.endControlPoint=r,this.curveIntervals=30,this.segmentCache=[],this.segmentLengths=[],this.arcLength=null,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 n(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)}getSubCurveAt(t,e){const s=new h(this.getPointAt(t),this.getTangentAt(t)),i=new h(this.getPointAt(e),this.getTangentAt(e).inv());return s.b.add(s.a),i.b.add(i.a),s.scale(.33333333*(e-t)),i.scale(.33333333*(e-t)),new o(s.a,i.a,s.b,i.b)}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 o(this.getStartPoint().clone(),this.getEndPoint().clone(),this.getStartControlPoint().clone(),this.getEndControlPoint().clone())}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 o}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 o.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 o(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 o(t[0],t[1],t[2],t[3])}}o.START_POINT=0,o.START_CONTROL_POINT=1,o.END_CONTROL_POINT=2,o.END_POINT=3;class l{constructor(e){this.className="BezierPath",this.START_POINT=0,this.START_CONTROL_POINT=1,this.END_CONTROL_POINT=2,this.END_POINT=3,this.uid=t.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=l._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=l._locateUIndex(this,s),n=l._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 l.fromArray([o])}var c=[];if(r.i>n.i){o=this.bezierCurves[r.i].getSubCurveAt(a,0);c.push(o);for(var d=r.i-1;d>n.i;d--)c.push(this.bezierCurves[d].clone().reverse());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();c.push(this.bezierCurves[n.i].getSubCurveAt(1,h))}else{o=this.bezierCurves[r.i].getSubCurveAt(a,1);c.push(o);for(d=r.i+1;d<n.i&&d<this.bezierCurves.length;d++)c.push(this.bezierCurves[d].clone());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();c.push(this.bezierCurves[n.i].getSubCurveAt(0,h))}return l.fromArray(c)}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);l.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());l.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 n(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 l(void 0),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}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 l.fromArray(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 l(void 0),i=null,r=0;r<e.length;r++){var n;if(o.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=o.fromArray(e[r])}else n=o.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 l.fromReducedList(s,e)}static fromReducedList(t,e){var s,r,n,a,h=new l(null),c=0;do{0==c&&(s=new i(t[c],t[c+1])),r=new i(t[c+2],t[c+3]),n=new i(t[c+4],t[c+5]),a=new i(t[c+6],t[c+7]);var d=new o(s,a,r,n);h.bezierCurves.push(d),s=a,c+=6}while(c+2<t.length);return h.adjustCircular=e,e&&(h.bezierCurves[h.bezierCurves.length-1].endPoint=h.bezierCurves[0].startPoint),h.updateArcLengths(),h}}l.START_POINT=0,l.START_CONTROL_POINT=1,l.END_CONTROL_POINT=2,l.END_POINT=3;class c extends a{constructor(t,e){super(t,e,((t,e)=>new c(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)?void 0:new i(h,o)}}class d{constructor(e,s){this.className="Circle",this.uid=t.next(),this.center=e,this.radius=s}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 h(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),n=(this.radius*this.radius-t.radius*t.radius+r*r)/(2*r),a=Math.sqrt(this.radius*this.radius-n*n),h=s.clone().scale(n/r,e),o=h.x+a*(s.y-e.y)/r,l=h.y-a*(s.x-e.x)/r,d=h.x-a*(s.y-e.y)/r,u=h.y+a*(s.x-e.x)/r;return new c(new i(o,l),new i(d,u))}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(e,s,i){this.className="CircleSector",this.uid=t.next(),this.circle=e,this.startAngle=s,this.endAngle=i}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){this.svgNode=t,this.offset=new i(0,0).set(e),this.scale=new i(1,1).set(s),this.fillShapes=n,this.isSecondary=h,this.drawlibConfiguration={},this.cache=new Map,this.setSize(r),h?(this.gNode=o,this.bufferGNode=l,this.nodeDefs=c,this.bufferedNodeDefs=d):(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);const e={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.nodeStyle.innerHTML=s.join("\n")}addDefsNode(){this.nodeDefs=this.createSVGNode("defs"),this.bufferedNodeDefs=this.createSVGNode("defs"),this.svgNode.appendChild(this.nodeDefs)}addCustomStyleDefs(t){const e=[];t.forEach(((t,s)=>{e.push(s+" { "+t+" }")})),this.nodeStyle.innerHTML+="\n/* Custom styles */\n"+e.join("\n")}findElement(t,e){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){return this.curClassName?t.setAttribute("class",`${e} ${this.curClassName}`):t.setAttribute("class",e),t.setAttribute("fill",this.fillShapes?s:"none"),t.setAttribute("stroke",this.fillShapes?"none":s),t.setAttribute("stroke-width",""+(i||1)),this.curId&&t.setAttribute("id",""+this.curId),t.parentNode||this.bufferGNode.appendChild(t),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,null,!0,this.gNode,this.bufferGNode,this.nodeDefs,this.bufferedNodeDefs)}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.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}_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){const r=this.makeNode("line");return r.setAttribute("x1",""+this._x(t.x)),r.setAttribute("y1",""+this._y(t.y)),r.setAttribute("x2",""+this._x(e.x)),r.setAttribute("y2",""+this._y(e.y)),this._bindFillDraw(r,"line",s,i||1)}arrow(t,e,s,r){const n=this.makeNode("path");var a=i.utils.buildArrowHead(t,e,8,this.scale.x,this.scale.y);const h=["M",this._x(t.x),this._y(t.y)];for(var o=0;o<=a.length;o++)h.push("L"),h.push(this.offset.x+a[o%a.length].x),h.push(this.offset.y+a[o%a.length].y);return n.setAttribute("d",h.join(" ")),this._bindFillDraw(n,"arrow",s,r||1)}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(e,s,r,n,a){r.getBounds();const h=new i(s.min).clone().rotate(a,n);n.clone().add(h.difference(s.min).inv());const o=this.makeNode("clipPath"),l="clippath_"+t.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",e.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){if(t instanceof o)return this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n);const a=this.makeNode("path"),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 a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"cubierBezier",r,n)}cubicBezierPath(t,e,s){const i=this.makeNode("path");if(!t||0==t.length)return i;const r=["M",this._x(t[0].x),this._y(t[0].y)];for(var n,a,h,o=1;o<t.length;o+=3)a=t[o],h=t[o+1],n=t[o+2],r.push("C",this._x(a.x),this._y(a.y),this._x(h.x),this._y(h.y),this._x(n.x),this._y(n.y));return i.setAttribute("d",r.join(" ")),this._bindFillDraw(i,"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(192,192,192)")}dot(t,e){const s=this.makeNode("line");return 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){const r=this.makeNode("circle");return r.setAttribute("cx",""+this._x(t.x)),r.setAttribute("cy",""+this._y(t.y)),r.setAttribute("r",""+e*this.scale.x),this._bindFillDraw(r,"circle",s,i||1)}circleArc(t,e,s,i,r,n){const a=this.makeNode("path"),h=u.circleSectorUtils.describeSVGArc(this._x(t.x),this._y(t.y),e*this.scale.x,s,i);return a.setAttribute("d",h.join(" ")),this._bindFillDraw(a,"circleArc",r,n||1)}ellipse(t,e,s,i,r,n){void 0===n&&(n=0);const a=this.makeNode("ellipse");return a.setAttribute("cx",""+this._x(t.x)),a.setAttribute("cy",""+this._y(t.y)),a.setAttribute("rx",""+e*this.scale.x),a.setAttribute("ry",""+s*this.scale.y),a.setAttribute("transform",`rotate(${180*n/Math.PI} ${this._x(t.x)} ${this._y(t.y)})`),this._bindFillDraw(a,"ellipse",i,r||1)}square(t,e,s,i){const r=this.makeNode("rectangle");return r.setAttribute("x",""+this._x(t.x-e/2)),r.setAttribute("y",""+this._y(t.y-e/2)),r.setAttribute("width",""+e*this.scale.x),r.setAttribute("height",""+e*this.scale.y),this._bindFillDraw(r,"square",s,i||1)}rect(t,e,s,i,r){const n=this.makeNode("rect");return n.setAttribute("x",""+this._x(t.x)),n.setAttribute("y",""+this._y(t.y)),n.setAttribute("width",""+e*this.scale.x),n.setAttribute("height",""+s*this.scale.y),this._bindFillDraw(n,"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){const r=this.makeNode("path");if(0==t.length)return r;const n=["M",this._x(t[0].x),this._y(t[0].y)];for(var a=t.length,h=1;h<a;h++)n.push("L",this._x(t[h].x),this._y(t[h].y));return e||n.push("Z"),r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"polygon",s,i||1)}text(t,e,s,i){var r,n;const a=(i=i||{}).color||"black",h=(null!==(n=null!==(r=i.lineHeight)&&void 0!==r?r:i.fontSize)&&void 0!==n?n:0)*this.scale.x,o="left"===i.textAlign||"start"===i.textAlign?"start":"center"===i.textAlign?"middle":"right"===i.textAlign||"end"===i.textAlign?"end":"start",l=`${this._x(e)}px ${this._y(s)}px`,c=`translate(${this._x(e)} ${this._y(s)+h/2})`,d=i.rotation?`rotate(${i.rotation*g} 0 0)`:"",u=this.makeNode("g"),f=this.curId;this.curId=f+"_text";const x=this.makeNode("text");return u.appendChild(x),x.setAttribute("font-family",i.fontFamily),x.setAttribute("font-size",i.fontSize?""+i.fontSize*this.scale.x:null),x.setAttribute("font-style",i.fontStyle?""+i.fontStyle:null),x.setAttribute("font-weight",i.fontWeight?""+i.fontWeight:null),x.setAttribute("text-anchor",o),x.setAttribute("transform-origin","0 0"),x.setAttribute("transform",d),u.setAttribute("transform-origin",l),u.setAttribute("transform",c),x.innerHTML=t,this.curId=f,this._bindFillDraw(u,"text",a,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"),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=void 0;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=void 0}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;case"z":case"Z":h++;break;default:h++}}}}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}beginDrawCycle(t){}endDrawCycle(t){}setConfiguration(t){this.ctx.globalCompositeOperation=t.blendMode}setCurrentId(t){}setCurrentClassName(t){}line(t,e,s,i){this.ctx.save(),this.ctx.beginPath(),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){this.ctx.save(),this.ctx.beginPath();var n=i.utils.buildArrowHead(t,e,8,this.scale.x,this.scale.y);this.ctx.moveTo(this.offset.x+t.x*this.scale.x,this.offset.y+t.y*this.scale.y);for(var a=0;a<n.length;a++)this.ctx.lineTo(this.offset.x+n[a].x,this.offset.y+n[a].y);this.ctx.lineTo(this.offset.x+n[0].x,this.offset.y+n[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,r,n){var a=s.getBounds(),h=r.clone().difference(a.getCenter());a.getCenter().sub(h);var o=new i(e.width,e.height),l=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,l.x,l.y,o.x,o.y),this.ctx.restore()}_texturedPoly(t,e,s,r,n,a={x:0,y:0}){var h=s.getBounds(),o=r.clone().difference(h.getCenter()),l=a?r.difference(a):{x:0,y:0},c=h.getCenter().sub(o),d=new i(e.width,e.height),u=new i(-e.width/2,-e.height/2).sub(o);this.ctx.save(),this.ctx.translate(this.offset.x+(c.x-0*l.x+0*u.x)*this.scale.x,this.offset.y+(c.y-0*l.y+0*u.y)*this.scale.y),this.ctx.rotate(n),x.helpers.clipPoly(this.ctx,{x:(1*-o.x-c.x-l.x)*this.scale.x,y:(1*-o.y-c.y-l.y)*this.scale.y},this.scale,s.vertices),this.ctx.drawImage(t,0,0,t.naturalWidth-1,t.naturalHeight-1,(-r.x+1*u.x-1*l.x)*this.scale.x,(-r.y+1*u.y-1*l.y)*this.scale.y,d.x*this.scale.x,d.y*this.scale.y),this.ctx.restore()}rect(t,e,s,i,r){this.ctx.save(),this.ctx.beginPath(),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()}_fillOrDraw(t){this.fillShapes?(this.ctx.fillStyle=t,this.ctx.fill()):(this.ctx.strokeStyle=t,this.ctx.stroke())}cubicBezier(t,e,s,i,r,n){t instanceof o?this.cubicBezier(t.startPoint,t.endPoint,t.startControlPoint,t.endControlPoint,r,n):(this.ctx.save(),this.ctx.beginPath(),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){this.ctx.save(),this.ctx.beginPath(),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){if(t&&0!=t.length){var i,r,n;this.ctx.save(),this.ctx.beginPath(),this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var a=1;a<t.length;a+=3)r=t[a],n=t[a+1],i=t[a+2],this.ctx.bezierCurveTo(this.offset.x+r.x*this.scale.x,this.offset.y+r.y*this.scale.y,this.offset.x+n.x*this.scale.x,this.offset.y+n.y*this.scale.y,this.offset.x+i.x*this.scale.x,this.offset.y+i.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,"rgb(192,192,192)")}dot(t,e){this.ctx.save(),this.ctx.beginPath(),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.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){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.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){void 0===n&&(n=0),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){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.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.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.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.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.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.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.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){this.polyline(t.vertices,t.isOpen,e,s)}polyline(t,e,s,i){if(!(t.length<=1)){this.ctx.save(),this.ctx.beginPath(),this.ctx.lineWidth=i*this.scale.x||1,this.ctx.moveTo(this.offset.x+t[0].x*this.scale.x,this.offset.y+t[0].y*this.scale.y);for(var r=0;r<t.length;r++)this.ctx.lineTo(this.offset.x+t[r].x*this.scale.x,this.offset.y+t[r].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),this.ctx.strokeStyle=e,this.ctx.lineWidth=s||1,this.fillShapes?(this.ctx.fillStyle=e,this.ctx.fill(new Path2D(r.join(" ")))):(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){}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 m{constructor(e,s,i){this.className="Triangle",this.uid=t.next(),this.a=e,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 m(t[0],t[1],t[2])}getArea(){return Math.abs(m.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)<m.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 n(new i(m.utils.min3(this.a.x,this.b.x,this.c.x),m.utils.min3(this.a.y,this.b.y,this.c.y)),new i(m.utils.max3(this.a.x,this.b.x,this.c.x),m.utils.max3(this.a.y,this.b.y,this.c.y)))}toPolygon(){return new r([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 m.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 c(this.a,this.b),e=new c(this.b,this.c),s=new c(this.c,this.a),i=p.nsectAngle(this.b,this.a,this.c,2)[0],r=p.nsectAngle(this.c,this.b,this.a,2)[0],n=i.intersection(r),a=t.getClosestPoint(n),h=e.getClosestPoint(n),o=s.getClosestPoint(n);return new m(a,h,o)}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}}m.EPSILON=1e-6,m.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=m.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 p={nsectAngle(t,e,s,i){const r=new m(t,e,s),n=new c(t,e),a=new c(t,s);var h=n.angle(a);const o=r.determinant()>0;h<0&&(h=2*Math.PI+h),o||(h=-1*(2*Math.PI-h));const l=Math.max(n.length(),a.length())/n.length();for(var d=[],u=1;u<i;u++)d.push(new c(t,e.clone().rotate(h/i*-u,t)).scale(l));return d},wrapMax:(t,e)=>(e+t%e)%e,wrapMinMax:(t,e,s)=>e+p.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=null,this.mouseDragPos=null,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){const s=this.relPos(t),i=t;return i.params={element:this.element,name:e,isTouchEvent:!1,pos:s,button:this.mouseButton,leftButton:0==this.mouseButton,middleButton:1==this.mouseButton,rightButton:2==this.mouseButton,mouseDownPos:this.mouseDownPos,draggedFrom:this.mouseDragPos,wasDragged:null!=this.mouseDownPos&&(this.mouseDownPos.x!=s.x||this.mouseDownPos.y!=s.y),dragAmount:null!=this.mouseDownPos?{x:s.x-this.mouseDragPos.x,y:s.y-this.mouseDragPos.y}:{x:0,y:0}},i}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 T{constructor(e,s,i){this.className="PBImage",this.uid=t.next(),this.image=e,this.upperLeft=s,this.lowerRight=i}destroy(){this.upperLeft.destroy(),this.lowerRight.destroy(),this.isDestroyed=!0}}class S{constructor(e,s,r){this.className="PBText",this.uid=t.next(),this.text=e,this.anchor=null!=s?s:new i,this.color=r.color,this.fontFamily=r.fontFamily,this.fontSize=r.fontSize,this.fontStyle=r.fontStyle,this.fontWeight=r.fontWeight,this.lineHeight=r.lineHeight,this.textAlign=r.textAlign,this.rotation=r.rotation}destroy(){this.anchor.destroy(),this.isDestroyed=!0}}const _=t=>Math.sqrt(t.x*t.x+t.y*t.y),N=(t,e)=>{var s=((t,e)=>{const s=_(t)*_(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=_(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=_(a)/this.pinchStartLen,this.pinch.dispatch(e,this.element)),e.angle=N(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(e,s,i){this.className="VEllipse",this.uid=t.next(),this.center=e,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 c(s,i[0]).angle(),n=r+(new c(s,i[1]).angle()-r)/2,a=s.clone().addX(50).clone().rotate(n,s),o=s.clone().addX(50).clone().rotate(Math.PI+n,s);return this.center.distance(a)<this.center.distance(o)?new h(s,o):new h(s,a)}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],l=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=l.difference(s),e=new o(l.clone(),s.clone(),l.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=l.difference(a),d=s.difference(a),u=new o(l.clone(),s.clone(),l.clone().add(c.scale(e)),s.clone().add(d.scale(e)));n.push(u)}l=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(e,s,i){this.className="VEllipseSector",this.uid=t.next(),this.ellipse=e,this.startAngle=p.wrapMinMax(s,0,2*Math.PI),this.endAngle=p.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 l=[];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 o(d.clone(),s.clone(),d.clone().addXY(.333*t.x,.333*t.y),s.clone().addXY(.333*-t.x,.333*-t.y));l.push(e)}else{let t=n.intersection(a),i=d.difference(t),r=s.difference(t),h=new o(d.clone(),s.clone(),d.clone().add(i.scale(e)),s.clone().add(r.scale(e)));l.push(h)}d=s,c=t}return l}destroy(){this.ellipse.destroy(),this.isDestroyed=!0}}var I;E.ellipseSectorUtils={describeSVGArc:(t,e,s,r,n,a,h,o)=>{void 0===o&&(o={moveToStart:!0}),void 0===h&&(h=0),n=p.wrapMax(n,2*Math.PI),a=p.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=p.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,n,a,h,o,l){const d=Math.abs,u=Math.sin,g=Math.cos,f=Math.sqrt,x=t=>t*t,v=u(n),y=g(n),m=y*(t-o)/2+v*(e-l)/2,p=-v*(t-o)/2+y*(e-l)/2,b=x(m),w=x(p),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 T=a===h?-1:1,S=f((C*P-C*w-P*b)/(C*w+P*b))*T,_=S*(s*p)/r,N=S*(-r*m)/s,z=new i(y*_-v*N+(t+o)/2,v*_+y*N+(e+l)/2),M=z.clone().addXY(s,r),D=new L(z,M,0);D.rotate(n);const I=new c(D.center,new i(t,e)).angle(),k=new c(D.center,new i(o,l)).angle();return new E(D,I-n,k-n)}};class k{constructor(t){if(this.renderTime=0,e.model={bezierAutoAdjust:!1,renderTime:0,selectable:!0,isSelected:!1,draggable:!0,visible:!0},void 0===t.canvas)throw"No canvas specified.";const s=k.utils.fetch;this.config={canvas:t.canvas,fullSize:s.val(t,"fullSize",!0),fitToParent:s.bool(t,"fitToParent",!0),scaleX:s.num(t,"scaleX",1),scaleY:s.num(t,"scaleY",1),offsetX:s.num(t,"offsetX",0),offsetY:s.num(t,"offsetY",0),rasterGrid:s.bool(t,"rasterGrid",!0),rasterScaleX:s.num(t,"rasterScaleX",1),rasterScaleY:s.num(t,"rasterScaleY",1),rasterAdjustFactor:s.num(t,"rasterAdjustdFactror",2),drawOrigin:s.bool(t,"drawOrigin",!1),autoAdjustOffset:s.val(t,"autoAdjustOffset",!0),offsetAdjustXPercent:s.num(t,"offsetAdjustXPercent",50),offsetAdjustYPercent:s.num(t,"offsetAdjustYPercent",50),backgroundColor:t.backgroundColor||"#ffffff",redrawOnResize:s.bool(t,"redrawOnResize",!0),defaultCanvasWidth:s.num(t,"defaultCanvasWidth",k.DEFAULT_CANVAS_WIDTH),defaultCanvasHeight:s.num(t,"defaultCanvasHeight",k.DEFAULT_CANVAS_HEIGHT),canvasWidthFactor:s.num(t,"canvasWidthFactor",1),canvasHeightFactor:s.num(t,"canvasHeightFactor",1),cssScaleX:s.num(t,"cssScaleX",1),cssScaleY:s.num(t,"cssScaleY",1),cssUniformScale:s.bool(t,"cssUniformScale",!0),saveFile:()=>{n.hooks.saveFile(n)},setToRetina:()=>{n._setToRetina()},autoDetectRetina:s.bool(t,"autoDetectRetina",!0),enableSVGExport:s.bool(t,"enableSVGExport",!0),preClear:s.func(t,"preClear",null),preDraw:s.func(t,"preDraw",null),postDraw:s.func(t,"postDraw",null),enableMouse:s.bool(t,"enableMouse",!0),enableTouch:s.bool(t,"enableTouch",!0),enableKeys:s.bool(t,"enableKeys",!0),enableMouseWheel:s.bool(t,"enableMouseWheel",!0),enableGL:s.bool(t,"enableGL",!1)},this.drawConfig={drawVertices:!0,drawBezierHandleLines:s.bool(t,"drawBezierHandleLines",!0),drawBezierHandlePoints:s.bool(t,"drawBezierHandlePoints",!0),drawHandleLines:s.bool(t,"drawHandleLines",!0),drawHandlePoints:s.bool(t,"drawHandlePoints",!0),drawGrid:s.bool(t,"drawGrid",!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}},this.grid=new b(new i(0,0),new i(50,50)),this.canvasSize={width:k.DEFAULT_CANVAS_WIDTH,height:k.DEFAULT_CANVAS_HEIGHT};const r="string"==typeof t.canvas?document.querySelector(t.canvas):t.canvas;if("canvas"===r.tagName.toLowerCase())if(this.canvas=r,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"!==r.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=r,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}t.title&&this.eventCatcher.setAttribute("title",t.title),this.draw.scale.set(this.config.scaleX,this.config.scaleY),this.fill.scale.set(this.config.scaleX,this.config.scaleY),this.vertices=[],this.selectPolygon=null,this.draggedElements=[],this.drawables=[],this.console=console,this.hooks={saveFile:k._saveFile};var n=this;globalThis.addEventListener("resize",(()=>n.resizeCanvas())),this.resizeCanvas(),t.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),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([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(){this.config.cssUniformScale?k.utils.setCSSscale(this.canvas,this.config.cssScaleX,this.config.cssScaleX):k.utils.setCSSscale(this.canvas,this.config.cssScaleX,this.config.cssScaleY)}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 c)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b);else if(t instanceof h)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 r){this.drawables.push(t);for(s=0;s<t.vertices.length;s++)this.vertices.push(t.vertices[s])}else if(t instanceof m)this.drawables.push(t),this.vertices.push(t.a),this.vertices.push(t.b),this.vertices.push(t.c);else if(t instanceof l){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;k.utils.enableBezierPathAutoAdjust(t)}else if(t instanceof T)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 S))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 n=0;n<t.length;n++)this.remove(t[n],!1,s);e&&this.redraw()}else{t instanceof i&&(this.removeVertex(t,!1),e&&this.redraw());for(n=0;n<this.drawables.length;n++)if(this.drawables[n]===t||this.drawables[n].uid===t.uid){if(this.drawables.splice(n,1),s)if(t instanceof c)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1);else if(t instanceof h)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 r)for(n=0;n<t.vertices.length;n++)this.removeVertex(t.vertices[n],!1);else if(t instanceof m)this.removeVertex(t.a,!1),this.removeVertex(t.b,!1),this.removeVertex(t.c,!1);else if(t instanceof l)for(n=0;n<t.bezierCurves.length;n++)this.removeVertex(t.bezierCurves[n].startPoint,!1),this.removeVertex(t.bezierCurves[n].startControlPoint,!1),this.removeVertex(t.bezierCurves[n].endControlPoint,!1),n+1==t.bezierCurves.length&&this.removeVertex(t.bezierCurves[n].endPoint,!1);else t instanceof T?(this.removeVertex(t.upperLeft,!1),this.removeVertex(t.lowerRight,!1)):t instanceof S&&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=this.locatePointNear(this.transformMousePosition(t.x,t.y),e/Math.min(this.config.cssScaleX,this.config.cssScaleY));if(s&&"vertex"==s.typeName)return this.vertices[s.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,"#000000")}_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.draw.setCurrentClassName(r.className),this.drawDrawable(r,t,e,s)}}drawDrawable(t,e,s,n){if(t instanceof l)for(var a in t.bezierCurves){if(s.cubicBezier(t.bezierCurves[a].startPoint,t.bezierCurves[a].endPoint,t.bezierCurves[a].startControlPoint,t.bezierCurves[a].endControlPoint,this.drawConfig.bezier.color,this.drawConfig.bezier.lineWidth),this.drawConfig.drawBezierHandlePoints&&this.drawConfig.drawHandlePoints){if(t.bezierCurves[a].startPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?n:s;e.setCurrentId(t.uid+"_h0"),e.setCurrentClassName(t.className+"-start-handle"),t.bezierCurves[a].startPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[a].startPoint,5,this._handleColor(t.bezierCurves[a].startPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[a].startPoint,7,this._handleColor(t.bezierCurves[a].startPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[a].startPoint.attr.renderTime=e,t.bezierCurves[a].endPoint.attr.visible){const e=this.drawConfig.bezier.pathVertex.fill?n:s;e.setCurrentId(t.uid+"_h0"),e.setCurrentClassName(t.className+"-start-handle"),t.bezierCurves[a].endPoint.attr.bezierAutoAdjust?e.squareHandle(t.bezierCurves[a].endPoint,5,this._handleColor(t.bezierCurves[a].endPoint,this.drawConfig.bezier.pathVertex.color)):e.diamondHandle(t.bezierCurves[a].endPoint,7,this._handleColor(t.bezierCurves[a].endPoint,this.drawConfig.bezier.pathVertex.color))}if(t.bezierCurves[a].startControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?n:s;e.setCurrentId(t.uid+"_h2"),e.setCurrentClassName(t.className+"-start-control-handle"),e.circleHandle(t.bezierCurves[a].startControlPoint,3,this._handleColor(t.bezierCurves[a].startControlPoint,this.drawConfig.bezier.controlVertex.color))}if(t.bezierCurves[a].endControlPoint.attr.visible){const e=this.drawConfig.bezier.controlVertex.fill?n:s;e.setCurrentId(t.uid+"_h3"),e.setCurrentClassName(t.className+"-end-control-handle"),e.circleHandle(t.bezierCurves[a].endControlPoint,3,this._handleColor(t.bezierCurves[a].endControlPoint,this.drawConfig.bezier.controlVertex.color))}t.bezierCurves[a].startPoint.attr.renderTime=e,t.bezierCurves[a].endPoint.attr.renderTime=e,t.bezierCurves[a].startControlPoint.attr.renderTime=e,t.bezierCurves[a].endControlPoint.attr.renderTime=e}else t.bezierCurves[a].startPoint.attr.renderTime=e,t.bezierCurves[a].endPoint.attr.renderTime=e,t.bezierCurves[a].startControlPoint.attr.renderTime=e,t.bezierCurves[a].endControlPoint.attr.renderTime=e;this.drawConfig.drawBezierHandleLines&&this.drawConfig.drawHandleLines&&(s.setCurrentId(t.uid+"_l0"),s.setCurrentClassName(t.className+"-start-line"),s.line(t.bezierCurves[a].startPoint,t.bezierCurves[a].startControlPoint,this.drawConfig.bezier.handleLine.color,this.drawConfig.bezier.handleLine.lineWidth),s.setCurrentId(t.uid+"_l1"),s.setCurrentClassName(t.className+"-end-line"),s.line(t.bezierCurves[a].endPoint,t.bezierCurves[a].endControlPoint,this.drawConfig.bezier.handleLine.color,this.drawConfig.bezier.handleLine.lineWidth))}else if(t instanceof r){if(s.polygon(t,this.drawConfig.polygon.color,this.drawConfig.polygon.lineWidth),!this.drawConfig.drawHandlePoints)for(var o in t.vertices)t.vertices[o].attr.renderTime=e}else if(t instanceof m)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.line(t.center.clone().add(0,t.signedRadiusV()).rotate(t.rotation,t.center),t.axis,"#c8c8c8"),s.setCurrentId(t.uid+"_e1"),s.setCurrentClassName(t.className+"-h-line"),s.line(t.center.clone().add(t.signedRadiusH(),0).rotate(t.rotation,t.center),t.axis,"#c8c8c8")),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 c?(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 h?(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 T?(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)),n.setCurrentId(t.uid),n.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 S?(n.setCurrentId(t.uid),n.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?n: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),n.setCurrentClassName(null),n.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.drawGrid(e),this.config.drawOrigin&&this.drawOrigin(e),this.drawDrawables(t,e,s),this.drawVertices(t,e),this.drawSelectPolygon(e),e.setCurrentId(void 0),e.setCurrentClassName(void 0)}clear(){this.draw.clear(this.config.backgroundColor)}clearSelection(t){for(var e in this.vertices)this.vertices[e].attr.isSelected=!1;return t&&this.redraw(),this}viewport(){return new n(this.transformMousePosition(0,0),this.transformMousePosition(this.canvasSize.width*this.config.cssScaleX,this.canvasSize.height*this.config.cssScaleY))}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(){const t=this,e=(e,s)=>{e*=t.config.canvasWidthFactor,s*=t.config.canvasHeightFactor,t.canvasSize.width=e,t.canvasSize.height=s,t.canvas instanceof HTMLCanvasElement?(t.canvas.width=e,t.canvas.height=s):t.canvas instanceof SVGElement?(this.canvas.setAttribute("viewBox",`0 0 ${e} ${s}`),this.canvas.setAttribute("width",""+e),this.canvas.setAttribute("height",""+s),this.draw.setSize(t.canvasSize),this.eventCatcher.style.width=e+"px",this.eventCatcher.style.height=s+"px"):console.error("Error: cannot resize canvas element because it seems neither be a HTMLCanvasElement nor an SVGElement."),t.config.autoAdjustOffset&&t.adjustOffset(!1)};if(t.config.fullSize&&!t.config.fitToParent){var s=globalThis.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,i=globalThis.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;t.canvas.style.position="absolute",t.canvas.style.width=t.config.canvasWidthFactor*s+"px",t.canvas.style.height=t.config.canvasWidthFactor*i+"px",t.canvas.style.top="0px",t.canvas.style.left="0px",e(s,i)}else if(t.config.fitToParent){t.canvas.style.position="absolute";const s=this.getAvailableContainerSpace();t.canvas.style.width=t.config.canvasWidthFactor*s.width+"px",t.canvas.style.height=t.config.canvasHeightFactor*s.height+"px",t.canvas.style.top=null,t.canvas.style.left=null,e(s.width,s.height)}else t.canvas.style.width=null,t.canvas.style.height=null,e(t.config.defaultCanvasWidth,t.config.defaultCanvasHeight);t.config.redrawOnResize&&t.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 k.Draggable(r,k.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),k.DEFAULT_CLICK_TOLERANCE/Math.min(e.config.cssScaleX,e.config.cssScaleY));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.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),k.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 k.Draggable(e.vertices[i],k.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.isDown("alt")||this.keyHandler.isDown("spacebar"))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){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 r=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,n=null,a=null;const h=()=>{e=null,s=null,n=null,a=null,t.draggedElements=[]},o={touchStart:a=>{if(1==a.touches.length&&(e=new i(r({x:a.touches[0].clientX,y:a.touches[0].clientY})),s=new i(r({x:a.touches[0].clientX,y:a.touches[0].clientY})),(n=t.locatePointNear(t.transformMousePosition(e.x,e.y),k.DEFAULT_TOUCH_TOLERANCE/Math.min(t.config.cssScaleX,t.config.cssScaleY)))&&"vertex"==n.typeName)){var h=t.vertices[n.vindex],o={params:{isTouchEvent:!0,dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:h}};t.draggedElements=[n],h.listeners.fireDragStartEvent(o)}},touchMove:a=>{if(1==a.touches.length&&n){a.preventDefault(),a.stopPropagation();var h=r({x:a.touches[0].clientX,y:a.touches[0].clientY}),o=t.transformMousePosition(h.x,h.y),l=new i(t.transformMousePosition(e.x,e.y)).difference(o);if("vertex"==n.typeName){if(!t.vertices[n.vindex].attr.draggable)return;t.vertices[n.vindex].add(l);var c=t.vertices[n.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 2==a.touches.length&&(a.preventDefault(),a.stopPropagation(),t.setOffset(t.draw.offset.clone().addXY(a.deltaX,a.deltaY)),t.redraw())},touchEnd:i=>{if(n&&"vertex"==n.typeName){var r=t.vertices[n.vindex],a={isTouchEvent:!0,params:{dragAmount:{x:0,y:0},wasDragged:!1,mouseDownPos:s.clone(),mouseDragPos:s.clone(),vertex:r}};e&&s&&s.distance(e)<.001?r.listeners.fireClickEvent(a):r.listeners.fireDragEndEvent(a)}h()},touchCancel:t=>{h()},multipointStart:e=>{a=t.draw.scale.clone()},multipointEnd:t=>{a=null},pinch:e=>{const s=new i(e.touches.item(0).clientX,e.touches.item(0).clientY),r=new i(e.touches.item(1).clientX,e.touches.item(1).clientY),n=new c(s,r).vertAt(.5);t.setZoom(a.x*e.zoom,a.y*e.zoom,n),t.redraw()}};window.createAlloyFinger?window.createAlloyFinger(this.eventCatcher?this.eventCatcher:this.canvas,o):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 r,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){if(globalThis.utils&&"function"==typeof globalThis.utils.createGUI)return globalThis.utils.createGUI(this,t);throw"Cannot create dat.GUI instance; did you load the ./utils/creategui helper function an the dat.GUI library?"}}k.DEFAULT_CANVAS_WIDTH=1024,k.DEFAULT_CANVAS_HEIGHT=768,k.DEFAULT_CLICK_TOLERANCE=8,k.DEFAULT_TOUCH_TOLERANCE=32,k.Draggable=((I=class{constructor(t,e){this.item=t,this.typeName=e}isVertex(){return this.typeName==k.Draggable.VERTEX}setVIndex(t){return this.vindex=t,this}}).VERTEX="vertex",I),k.utils={safeMergeByKeys:(t,e)=>{for(var s in e)if(e.hasOwnProperty(s))if(t.hasOwnProperty(s)){var i=typeof t[s];try{"boolean"==i?t[s]=!!JSON.parse(e[s]):"number"==i?t[s]=1*JSON.parse(e[s]):("function"==i&&e[s],t[s]=e[s])}catch(t){console.error("error in key ",s,e[s],t)}}else t[s]=e[s];return t},setCSSscale:(t,e,s)=>{t.style["transform-origin"]="0 0",t.style.transform=1==e&&1==s?null:"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=l,exports.Bounds=n,exports.Circle=d,exports.CircleSector=u,exports.CubicBezierCurve=o,exports.Grid=b,exports.KeyHandler=w,exports.Line=c,exports.MouseHandler=A,exports.PBImage=T,exports.PBText=S,exports.PlotBoilerplate=k,exports.Polygon=r,exports.Triangle=m,exports.UIDGenerator=t,exports.VEllipse=L,exports.VEllipseSector=E,exports.Vector=h,exports.VertTuple=a,exports.Vertex=i,exports.VertexAttr=e,exports.VertexListeners=s,exports.XMouseEvent=C,exports.XWheelEvent=P,exports.drawutils=x,exports.drawutilsgl=v,exports.drawutilssvg=f,exports.geomutils=p;
|
|
2
2
|
//# sourceMappingURL=index.esm.min.js.map
|