ef-infinite-canvas
Version:
An infinite version of the html canvas
1 lines • 172 kB
JavaScript
(function(k,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(k=typeof globalThis<"u"?globalThis:k||self,k.InfiniteCanvas=h())})(this,(function(){"use strict";var Pa=Object.defineProperty;var Ca=(k,h,H)=>h in k?Pa(k,h,{enumerable:!0,configurable:!0,writable:!0,value:H}):k[h]=H;var a=(k,h,H)=>Ca(k,typeof h!="symbol"?h+"":h,H);let k=class{constructor(t){this.viewBox=t}restore(){this.viewBox.restoreState()}save(){this.viewBox.saveState()}reset(){this.viewBox.resetState()}};const j=class j{constructor(t,e){this.x=t,this.y=e}mod(){return Math.sqrt(this.modSq())}modSq(){return this.x*this.x+this.y*this.y}minus(t){return new j(this.x-t.x,this.y-t.y)}plus(t){return new j(this.x+t.x,this.y+t.y)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}equals(t){return this.x===t.x&&this.y===t.y}getPerpendicular(){return new j(-this.y,this.x)}scale(t){return new j(t*this.x,t*this.y)}projectOn(t){return t.scale(this.dot(t)/t.modSq())}matrix(t,e,n,i){return new j(t*this.x+e*this.y,n*this.x+i*this.y)}inSameDirectionAs(t){return this.cross(t)===0&&this.dot(t)>=0}isInOppositeDirectionAs(t){return this.cross(t)===0&&this.dot(t)<0}isOnSameSideOfOriginAs(t,e){return this.isInSmallerAngleBetweenPoints(t,e)||t.isInSmallerAngleBetweenPoints(this,e)||e.isInSmallerAngleBetweenPoints(this,t)}isInSmallerAngleBetweenPoints(t,e){const n=t.cross(e);return n>0?t.cross(this)>=0&&this.cross(e)>=0:n<0?t.cross(this)<=0&&this.cross(e)<=0:t.dot(e)>0?this.cross(t)===0&&this.dot(t)>0:!0}};a(j,"origin",new j(0,0));let h=j;function H(s){return s.toFixed(10).replace(/\.?0+$/,"")}const O=class O{constructor(t,e,n,i,r,o){a(this,"scale");this.a=t,this.b=e,this.c=n,this.d=i,this.e=r,this.f=o,this.scale=Math.sqrt(t*i-e*n)}getMaximumLineWidthScale(){const t=this.a+this.c,e=this.b+this.d,n=this.a-this.c,i=this.b-this.d;return Math.sqrt(Math.max(t*t+e*e,n*n+i*i))}getRotationAngle(){const t=this.a/this.scale,e=this.b/this.scale;if(t===0)return e>0?Math.PI/2:3*Math.PI/2;const n=Math.atan(e/t);return t>0?e>0?n:e===0?0:2*Math.PI+n:e>0?Math.PI+n:e===0?Math.PI:Math.PI+n}applyToPointAtInfinity(t){return{direction:this.untranslated().apply(t.direction)}}apply(t){return new h(this.a*t.x+this.c*t.y+this.e,this.b*t.x+this.d*t.y+this.f)}untranslated(){const{x:t,y:e}=this.apply(h.origin);return this.before(O.translation(-t,-e))}before(t){const e=t.a*this.a+t.c*this.b,n=t.b*this.a+t.d*this.b,i=t.a*this.c+t.c*this.d,r=t.b*this.c+t.d*this.d,o=t.a*this.e+t.c*this.f+t.e,c=t.b*this.e+t.d*this.f+t.f;return new O(e,n,i,r,o,c)}equals(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}inverse(){var t=this.a*this.d-this.b*this.c;if(t==0)throw new Error("error calculating inverse: zero determinant");const e=this.d/t,n=-this.b/t,i=-this.c/t,r=this.a/t,o=(this.c*this.f-this.d*this.e)/t,c=(this.b*this.e-this.a*this.f)/t;return new O(e,n,i,r,o,c)}static translation(t,e){return new O(1,0,0,1,t,e)}static scale(t){return new O(t,0,0,t,0,0)}static zoom(t,e,n,i,r){const o=1-n;return i!==void 0?new O(n,0,0,n,t*o+i,e*o+r):new O(n,0,0,n,t*o,e*o)}static translateZoom(t,e,n,i,r,o,c,l){const u=n-t,d=i-e,f=u*u+d*d;if(f===0)throw new Error("divide by 0");const p=c-r,C=l-o,I=p*p+C*C,L=Math.sqrt(I/f);return O.zoom(t,e,L,r-t,o-e)}static rotation(t,e,n){const i=Math.cos(n),r=Math.sin(n),o=1-i;return new O(i,r,-r,i,t*o+e*r,-t*r+e*o)}static translateRotateZoom(t,e,n,i,r,o,c,l){const u=n-t,d=i-e,f=u*u+d*d;if(f===0)throw new Error("divide by 0");const p=c-r,C=l-o,I=t*i-e*n,L=n*u+i*d,W=t*u+e*d,et=(u*p+d*C)/f,Pt=(u*C-d*p)/f,Ct=-Pt,Et=et,Rt=(r*L-c*W-I*C)/f,Ft=(o*L-l*W+I*p)/f;return new O(et,Pt,Ct,Et,Rt,Ft)}static create(t){if(t instanceof O)return t;const{a:e,b:n,c:i,d:r,e:o,f:c}=t;return new O(e,n,i,r,o,c)}toString(){return`x: (${H(this.a)}, ${H(this.b)}), y: (${H(this.c)}, ${H(this.d)}), d: (${H(this.e)}, ${H(this.f)})`}};a(O,"identity",new O(1,0,0,1,0,0));let v=O;class T{constructor(t,e){this.propertyName=t,this.noopInstruction=e}changeInstanceValue(t,e){return this.valuesAreEqual(t[this.propertyName],e)?t:t.changeProperty(this.propertyName,e)}isEqualForInstances(t,e){return this.valuesAreEqual(t[this.propertyName],e[this.propertyName])}getInstructionToChange(t,e){return this.valuesAreEqual(t[this.propertyName],e[this.propertyName])?this.noopInstruction:this.changeToNewValue(e[this.propertyName])}valueIsTransformableForInstance(t){return!0}}const w={execute(){}};class Pi{constructor(t){this.transformation=t}execute(t,e){const{a:n,b:i,c:r,d:o,e:c,f:l}=e.getTransformationForInstruction(this.transformation);t.setTransform(n,i,r,o,c,l)}}class Ci extends T{valuesAreEqual(t,e){return t.equals(e)}changeToNewValue(t){return new Pi(t)}}const Wt=new Ci("transformation",w);class Ii{constructor(t){this.viewBox=t}getTransform(){if(DOMMatrix){const t=this.viewBox.state.current.transformation;return new DOMMatrix([t.a,t.b,t.c,t.d,t.e,t.f])}}resetTransform(){this.viewBox.changeState(t=>Wt.changeInstanceValue(t,v.identity))}rotate(t){this.addTransformation(v.rotation(0,0,t))}scale(t,e){this.addTransformation(new v(t,0,0,e,0,0))}setTransform(t,e,n,i,r,o){let c,l,u,d,f,p;typeof t=="number"?(c=t,l=e,u=n,d=i,f=r,p=o):t.a!==void 0?(c=t.a,l=t.b,u=t.c,d=t.d,f=t.e,p=t.f):(c=t.m11,l=t.m12,u=t.m21,d=t.m22,f=t.m41,p=t.m42),this.viewBox.changeState(C=>Wt.changeInstanceValue(C,new v(c,l,u,d,f,p)))}transform(t,e,n,i,r,o){this.addTransformation(new v(t,e,n,i,r,o))}translate(t,e){this.addTransformation(v.translation(t,e))}addTransformation(t){const e=this.viewBox.state.current.transformation,n=t.before(e);this.viewBox.changeState(i=>Wt.changeInstanceValue(i,n))}}class y{constructor(t,e){this.propName=t,this.value=e}execute(t){t[this.propName]=this.value}}class Ti extends T{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return new y("globalAlpha",t)}}const un=new Ti("globalAlpha",w);class Si extends T{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return new y("globalCompositeOperation",t)}}const dn=new Si("globalCompositeOperation",w);class yi{constructor(t){this.viewBox=t}get globalAlpha(){return this.viewBox.state.current.globalAlpha}set globalAlpha(t){this.viewBox.changeState(e=>un.changeInstanceValue(e,t))}get globalCompositeOperation(){return this.viewBox.state.current.globalCompositeOperation}set globalCompositeOperation(t){this.viewBox.changeState(e=>dn.changeInstanceValue(e,t))}}class xi extends T{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return new y("imageSmoothingEnabled",t)}}const fn=new xi("imageSmoothingEnabled",w);class bi extends T{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return new y("imageSmoothingQuality",t)}}const gn=new bi("imageSmoothingQuality",w);class Oi{constructor(t){this.viewBox=t}get imageSmoothingEnabled(){return this.viewBox.state.current.imageSmoothingEnabled}set imageSmoothingEnabled(t){this.viewBox.changeState(e=>fn.changeInstanceValue(e,t))}get imageSmoothingQuality(){return this.viewBox.state.current.imageSmoothingQuality}set imageSmoothingQuality(t){this.viewBox.changeState(e=>gn.changeInstanceValue(e,t))}}class kt{}class mn extends kt{constructor(t){super(),this.fillStrokeStyle=t}setTransform(t){this.fillStrokeStyle.setTransform(t)}getInstructionToSetUntransformed(t){return new y(t,this.fillStrokeStyle)}getInstructionToSetTransformed(t){return new y(t,this.fillStrokeStyle)}}class pn{constructor(t){this.propName=t}changeInstanceValue(t,e){return t.changeProperty(this.propName,e)}isEqualForInstances(t,e){return t[this.propName]===e[this.propName]}getInstructionToChange(t,e){const n=e[this.propName];return this.isEqualForInstances(t,e)?!(n instanceof kt)||t.fillAndStrokeStylesTransformed===e.fillAndStrokeStylesTransformed?w:e.fillAndStrokeStylesTransformed?n.getInstructionToSetTransformed(this.propName):n.getInstructionToSetUntransformed(this.propName):n instanceof kt?e.fillAndStrokeStylesTransformed?n.getInstructionToSetTransformed(this.propName):n.getInstructionToSetUntransformed(this.propName):new y(this.propName,n)}valueIsTransformableForInstance(t){return!(t[this.propName]instanceof mn)}}const vn=new pn("fillStyle"),wn=new pn("strokeStyle");class Li{constructor(t){this.viewBox=t}set fillStyle(t){this.viewBox.changeState(e=>vn.changeInstanceValue(e,t))}set strokeStyle(t){this.viewBox.changeState(e=>wn.changeInstanceValue(e,t))}createLinearGradient(t,e,n,i){return this.viewBox.createLinearGradient(t,e,n,i)}createPattern(t,e){return this.viewBox.createPattern(t,e)}createRadialGradient(t,e,n,i,r,o){return this.viewBox.createRadialGradient(t,e,n,i,r,o)}createConicGradient(t,e,n){return this.viewBox.createConicGradient(t,e,n)}}class Bi extends T{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return new y("shadowColor",t)}}const Pn=new Bi("shadowColor",w);class Ai{constructor(t){this.shadowOffset=t}execute(t,e){const n=v.translation(this.shadowOffset.x,this.shadowOffset.y),i=e.translateInfiniteCanvasContextTransformationToBitmapTransformation(n),{x:r,y:o}=i.apply(h.origin);t.shadowOffsetX=r,t.shadowOffsetY=o}}class Di extends T{changeToNewValue(t){return new Ai(t)}valuesAreEqual(t,e){return t.x===e.x&&t.y==e.y}}const me=new Di("shadowOffset",w);class Ei{constructor(t){this.shadowBlur=t}execute(t,e){const n=v.translation(this.shadowBlur,0),r=e.translateInfiniteCanvasContextTransformationToBitmapTransformation(n).apply(h.origin).mod();t.shadowBlur=r}}class Ri extends T{changeToNewValue(t){return new Ei(t)}valuesAreEqual(t,e){return t===e}}const Cn=new Ri("shadowBlur",w);class Fi{constructor(t){this.viewBox=t}get shadowBlur(){return this.viewBox.state.current.shadowBlur}set shadowBlur(t){this.viewBox.changeState(e=>Cn.changeInstanceValue(e,t))}get shadowOffsetX(){return this.viewBox.state.current.shadowOffset.x}set shadowOffsetX(t){const e=new h(t,this.viewBox.state.current.shadowOffset.y);this.viewBox.changeState(n=>me.changeInstanceValue(n,e))}get shadowOffsetY(){return this.viewBox.state.current.shadowOffset.y}set shadowOffsetY(t){const e=new h(this.viewBox.state.current.shadowOffset.x,t);this.viewBox.changeState(n=>me.changeInstanceValue(n,e))}get shadowColor(){return this.viewBox.state.current.shadowColor}set shadowColor(t){this.viewBox.changeState(e=>Pn.changeInstanceValue(e,t))}}const In="[+-]?(?:\\d*\\.)?\\d+(?:e[+-]?\\d+)?",Tn="[+-]?(?:0*\\.)?0+(?:e[+-]?\\d+)?",Sn="(?:ch|em|ex|ic|rem|vh|vw|vmax|vmin|vb|vi|cqw|cqh|cqi|cqb|cqmin|cqmax|px|cm|mm|Q|in|pc|pt)",Ht=`(?:${Tn}|${In}${Sn})`,yn=`blur\\((${Ht})\\)`,xn="[^())\\s]+(?:\\([^)]*?\\))?",bn=`drop-shadow\\((${Ht})\\s+(${Ht})\\s*?(?:(?:(${Ht})\\s*?(${xn})?)|(${xn}))?\\)`,On=`${yn}|${bn}`;function V(s,t){const e=s.match(new RegExp(`(?:(${Tn})|(${In})(${Sn}))`));return e[1]?0:t.getNumberOfPixels(Number.parseFloat(e[2]),e[3])}class Ln{constructor(t){this.stringRepresentation=t}toTransformedString(){return this.stringRepresentation}getShadowOffset(){return null}}class pe{constructor(t,e){this.stringRepresentation=t,this.size=e}toTransformedString(t){return`blur(${t.translateInfiniteCanvasContextTransformationToBitmapTransformation(v.translation(this.size,0)).apply(h.origin).mod()}px)`}getShadowOffset(){return null}static tryCreate(t,e){const n=t.match(new RegExp(yn));return n===null?null:new pe(t,V(n[1],e))}}class ht{constructor(t,e,n,i,r){this.stringRepresentation=t,this.offsetX=e,this.offsetY=n,this.blurRadius=i,this.color=r}toTransformedString(t){const e=t.translateInfiniteCanvasContextTransformationToBitmapTransformation(v.translation(this.offsetX,this.offsetY)),{x:n,y:i}=e.apply(h.origin);if(this.blurRadius!==null){const o=t.translateInfiniteCanvasContextTransformationToBitmapTransformation(v.translation(this.blurRadius,0)).apply(h.origin).mod();return this.color?`drop-shadow(${n}px ${i}px ${o}px ${this.color})`:`drop-shadow(${n}px ${i}px ${o}px)`}return this.color?`drop-shadow(${n}px ${i}px ${this.color})`:`drop-shadow(${n}px ${i}px)`}getShadowOffset(){return new h(this.offsetX,this.offsetY)}static tryCreate(t,e){const n=t.match(new RegExp(bn));return n===null?null:n[5]?new ht(t,V(n[1],e),V(n[2],e),null,n[5]):n[4]?new ht(t,V(n[1],e),V(n[2],e),V(n[3],e),n[4]):n[3]?new ht(t,V(n[1],e),V(n[2],e),V(n[3],e),null):new ht(t,V(n[1],e),V(n[2],e),null,null)}}const Dt=class Dt{constructor(t,e){this.stringRepresentation=t,this.parts=e}toString(){return this.parts.map(t=>t.stringRepresentation).join(" ")}toTransformedString(t){return this.parts.map(e=>e.toTransformedString(t)).join(" ")}getShadowOffset(){for(const t of this.parts){const e=t.getShadowOffset();if(e!==null)return e}return null}static create(t,e){const i=t.match(new RegExp(`${On}|((?!\\s|${On}).)+`,"g")).map(r=>this.createPart(r,e));return new Dt(t,i)}static createPart(t,e){let n=pe.tryCreate(t,e);return n!==null||(n=ht.tryCreate(t,e),n!=null)?n:new Ln(t)}};a(Dt,"none",new Dt("none",[new Ln("none")]));let Vt=Dt;class Wi{constructor(t){this.value=t}execute(t,e){t.filter=this.value.toTransformedString(e)}}class ki extends T{valuesAreEqual(t,e){return t.stringRepresentation===e.stringRepresentation}changeToNewValue(t){return new Wi(t)}}const Bn=new ki("filter",w);class Hi{constructor(t,e){this.viewBox=t,this.cssLengthConverterFactory=e}get filter(){return this.viewBox.state.current.filter.stringRepresentation}set filter(t){const e=Vt.create(t,this.cssLengthConverterFactory.create());this.viewBox.changeState(n=>Bn.changeInstanceValue(n,e))}}class Vi{constructor(t){this.fillRule=t}execute(t){t.fill(this.fillRule)}}class Nt{execute(t){t.fill()}static create(t){return t===void 0?Ni:new Vi(t)}}const Ni=new Nt;class Mi{constructor(t){this.viewBox=t}clearRect(t,e,n,i){this.viewBox.clearArea(t,e,n,i)}fillRect(t,e,n,i){const r=Nt.create();this.viewBox.fillRect(t,e,n,i,r)}strokeRect(t,e,n,i){this.viewBox.strokeRect(t,e,n,i)}}class qi{constructor(t){this.fillRule=t}execute(t){t.clip(this.fillRule)}}class ve{execute(t){t.clip()}static create(t){return t===void 0?zi:new qi(t)}}const zi=new ve;class Gi{constructor(t){this.viewBox=t}isFillRule(t){return t==="evenodd"||t==="nonzero"}beginPath(){this.viewBox.beginPath()}clip(t,e){const n=this.isFillRule(t)?ve.create(t):ve.create();this.viewBox.clipPath(n)}fill(t,e){if((!t||this.isFillRule(t))&&!this.viewBox.currentPathCanBeFilled())return;const n=this.isFillRule(t)?Nt.create(t):Nt.create();this.viewBox.fillPath(n)}isPointInPath(t,e,n,i){return!0}isPointInStroke(t,e,n){return!0}stroke(t){this.viewBox.strokePath()}}class Yi{drawFocusIfNeeded(t,e){}scrollPathIntoView(t){}}var z=(s=>(s[s.None=0]="None",s[s.Relative=1]="Relative",s[s.Absolute=2]="Absolute",s))(z||{}),x=(s=>(s[s.Positive=0]="Positive",s[s.Negative=1]="Negative",s))(x||{});const Mt={direction:new h(0,1)},qt={direction:new h(0,-1)},zt={direction:new h(-1,0)},Gt={direction:new h(1,0)};function Xi(s,t,e,n){const i=e.minus(s),r=n.cross(t),o=n.getPerpendicular().dot(i)/r;return s.plus(t.scale(o))}class it{constructor(t,e,n){a(this,"leftNormal");a(this,"rightNormal");this.point=t,this.leftHalfPlane=e,this.rightHalfPlane=n,this.leftNormal=e.normalTowardInterior,this.rightNormal=n.normalTowardInterior}replaceLeftHalfPlane(t){return new it(this.point,t,this.rightHalfPlane)}replaceRightHalfPlane(t){return new it(this.point,this.leftHalfPlane,t)}isContainedByHalfPlaneWithNormal(t){return t.isInSmallerAngleBetweenPoints(this.leftNormal,this.rightNormal)}containsPoint(t){return this.leftHalfPlane.containsPoint(t)&&this.rightHalfPlane.containsPoint(t)}containsLineSegmentWithDirection(t){return this.containsPoint(this.point.plus(t))||this.containsPoint(this.point.minus(t))}isContainedByVertex(t){return this.isContainedByHalfPlaneWithNormal(t.leftNormal)&&this.isContainedByHalfPlaneWithNormal(t.rightNormal)}getContainingHalfPlaneThroughPoint(t){let e=t.minus(this.point).getPerpendicular();if(e.cross(this.leftHalfPlane.normalTowardInterior)===0)return this.leftHalfPlane;if(e.cross(this.rightHalfPlane.normalTowardInterior)===0)return this.rightHalfPlane;const n=this.leftNormal.plus(this.rightNormal);return e.dot(n)<=0&&(e=e.scale(-1)),new P(t,e)}static create(t,e,n){return e.normalTowardInterior.cross(n.normalTowardInterior)>=0?new it(t,e,n):new it(t,n,e)}}class P{constructor(t,e){a(this,"lengthOfNormal");this.base=t,this.normalTowardInterior=e,this.lengthOfNormal=e.mod()}getDistanceFromEdge(t){return t.minus(this.base).dot(this.normalTowardInterior)/this.lengthOfNormal}transform(t){const e=t.apply(this.base),n=t.apply(this.base.plus(this.normalTowardInterior.getPerpendicular())),i=t.apply(this.base.plus(this.normalTowardInterior));return P.throughPointsAndContainingPoint(e,n,i)}complement(){return new P(this.base,this.normalTowardInterior.scale(-1))}expandByDistance(t){const e=this.base.plus(this.normalTowardInterior.scale(-t/this.normalTowardInterior.mod()));return new P(e,this.normalTowardInterior)}expandToIncludePoint(t){return this.containsPoint(t)?this:new P(t,this.normalTowardInterior)}containsPoint(t){return this.getDistanceFromEdge(t)>=0}interiorContainsPoint(t){return this.getDistanceFromEdge(t)>0}containsInfinityInDirection(t){return t.dot(this.normalTowardInterior)>=0}isContainedByHalfPlane(t){return this.normalTowardInterior.inSameDirectionAs(t.normalTowardInterior)&&t.getDistanceFromEdge(this.base)>=0}intersectWithLine(t,e){return{point:Xi(this.base,this.normalTowardInterior.getPerpendicular(),t,e),halfPlane:this}}isParallelToLine(t,e){return this.normalTowardInterior.getPerpendicular().cross(e)===0}getIntersectionWith(t){const e=this.intersectWithLine(t.base,t.normalTowardInterior.getPerpendicular());return it.create(e.point,this,t)}static throughPointsAndContainingPoint(t,e,n){const i=P.withBorderPoints(t,e);for(let r of i)if(r.containsPoint(n))return r}static withBorderPointAndInfinityInDirection(t,e){return P.withBorderPoints(t,t.plus(e))}static withBorderPoints(t,e){const n=e.minus(t).getPerpendicular();return[new P(t,n),new P(t,n.scale(-1))]}}class Ui{getVertices(){return[]}expandToIncludePoint(t){return this}expandToIncludePolygon(t){return this}expandToIncludeInfinityInDirection(t){return this}expandByDistance(t){return this}intersects(t){return!0}expandToInclude(t){return this}transform(t){return this}intersectWithLineSegment(t){return t}contains(t){return!0}intersectWith(t){return t}join(t){return this}intersectWithRay(t){return t}intersectWithLine(t){return t}intersectWithConvexPolygon(t){return t}isContainedByRay(t){return!1}isContainedByLineSegment(t){return!1}isContainedByLine(t){return!1}isContainedByConvexPolygon(t){return!1}intersectsRay(t){return!0}intersectsLineSegment(t){return!0}intersectsLine(t){return!0}intersectsConvexPolygon(t){return!0}}const lt=new Ui;class $i{getVertices(){return[]}intersectWith(t){return this}join(t){return t}intersectWithConvexPolygon(t){return this}intersects(t){return!1}intersectWithLineSegment(t){return this}intersectWithRay(t){return this}intersectWithLine(t){return this}expandToInclude(t){return t}transform(t){return this}contains(t){return!1}isContainedByConvexPolygon(t){return!0}isContainedByRay(t){return!0}isContainedByLineSegment(t){return!0}isContainedByLine(t){return!0}intersectsRay(t){return!1}intersectsConvexPolygon(t){return!1}intersectsLineSegment(t){return!1}intersectsLine(t){return!1}expandByDistance(t){return this}expandToIncludePoint(t){return this}expandToIncludeInfinityInDirection(t){return this}expandToIncludePolygon(t){return t}}const B=new $i;class m{constructor(t,e){a(this,"halfPlanes");this.vertices=e,this.halfPlanes=t,this.vertices=this.vertices||m.getVertices(this.halfPlanes)}findVertex(t){for(let e of this.vertices)if(e.point.equals(t))return e}intersects(t){return t.intersectsConvexPolygon(this)}intersectWith(t){return t.intersectWithConvexPolygon(this)}join(t){if(this.contains(t))return this;if(t.contains(this))return t;let e=t;for(let n of this.vertices)e=e.expandToIncludePoint(n.point);for(let n of this.getPointsAtInfinityFromHalfPlanes())this.containsInfinityInDirection(n)&&(e=e.expandToIncludeInfinityInDirection(n));return e}intersectWithRay(t){return t.intersectWithConvexPolygon(this)}intersectWithLine(t){return t.intersectWithConvexPolygon(this)}intersectWithLineSegment(t){return t.intersectWithConvexPolygon(this)}contains(t){return t.isContainedByConvexPolygon(this)}containsHalfPlane(t){for(let e of this.halfPlanes)if(!t.isContainedByHalfPlane(e))return!1;return!0}isContainedByHalfPlane(t){for(let n of this.vertices)if(!t.containsPoint(n.point))return!1;const e=t.complement();for(let n of this.halfPlanes)if(n.isContainedByHalfPlane(t))return!0;for(let n of this.halfPlanes){const i=this.getVerticesOnHalfPlane(n);if(i.length<=1&&(n.isContainedByHalfPlane(e)||e.isContainedByHalfPlane(n)))return!1;const r=n.getIntersectionWith(t),o=i.find(c=>c.point.equals(r.point));if(o){if(!o.isContainedByHalfPlaneWithNormal(t.normalTowardInterior))return!1}else{if(i.length===0)return!1;if(this.containsPoint(r.point))return!1}}return!this.containsHalfPlane(t)}getVertices(){return this.vertices.map(t=>t.point)}expandToIncludePoint(t){if(this.vertices.length===0){const d=this.halfPlanes.map(f=>f.expandToIncludePoint(t));return new m(d)}const e=new Set,n=new Set;let i=null,r=null;const o=[],c=new Set;for(const d of this.vertices){const f=d.leftHalfPlane;n.has(f)?n.delete(f):e.add(f);const p=d.rightHalfPlane;if(e.has(p)?e.delete(p):n.add(p),f.containsPoint(t)){if(c.add(f),p.containsPoint(t)){c.add(p),o.push(d);continue}i=d;continue}p.containsPoint(t)&&(c.add(p),r=d)}if(o.length===this.vertices.length)return this;let l,u;if(i===null){const d=[...e][0];if(!d)return this;l=d.expandToIncludePoint(t)}else l=i.getContainingHalfPlaneThroughPoint(t),l!==i.leftHalfPlane&&o.push(i.replaceRightHalfPlane(l));if(r===null){const d=[...n][0];if(!d)return this;u=d.expandToIncludePoint(t)}else u=r.getContainingHalfPlaneThroughPoint(t),u!==r.rightHalfPlane&&o.push(r.replaceLeftHalfPlane(u));return c.add(l),c.add(u),o.push(new it(t,l,u)),new m([...c],o)}expandToIncludeInfinityInDirection(t){if(this.containsInfinityInDirection(t))return this;let e=this.halfPlanes.filter(n=>n.containsInfinityInDirection(t)).concat(this.getTangentPlanesThroughInfinityInDirection(t));return e=m.getHalfPlanesNotContainingAnyOther(e),e.length===0?lt:new m(e)}getIntersectionsWithLine(t,e){const n=[];for(let i of this.halfPlanes){if(i.isParallelToLine(t,e))continue;const r=i.intersectWithLine(t,e),o=this.findVertex(r.point);o&&!o.containsLineSegmentWithDirection(e)||this.containsPoint(r.point)&&n.push(r)}return n}expandByDistance(t){return new m(this.halfPlanes.map(e=>e.expandByDistance(t)))}transform(t){return new m(this.halfPlanes.map(e=>e.transform(t)))}intersectWithConvexPolygon(t){if(t.isContainedByConvexPolygon(this))return t;if(this.isContainedByConvexPolygon(t))return this;if(this.isOutsideConvexPolygon(t))return B;const e=m.getHalfPlanesNotContainingAnyOther(this.halfPlanes.concat(t.halfPlanes)),r=m.groupVerticesByPoint(m.getVertices(e)).map(c=>m.getVerticesNotContainingAnyOther(c)).reduce((c,l)=>c.concat(l),[]);if(r.length===0)return new m(e);const o=m.getHalfPlanes(r);return new m(o)}containsInfinityInDirection(t){for(let e of this.halfPlanes)if(!e.containsInfinityInDirection(t))return!1;return!0}containsPoint(t){for(let e of this.halfPlanes)if(!e.containsPoint(t))return!1;return!0}intersectsRay(t){return t.intersectsConvexPolygon(this)}intersectsLineSegment(t){return t.intersectsConvexPolygon(this)}intersectsLine(t){return t.intersectsConvexPolygon(this)}intersectsConvexPolygon(t){return this.isContainedByConvexPolygon(t)||t.isContainedByConvexPolygon(this)?!0:!this.isOutsideConvexPolygon(t)}isOutsideConvexPolygon(t){for(let e of t.halfPlanes)if(this.isContainedByHalfPlane(e.complement()))return!0;for(let e of this.halfPlanes)if(t.isContainedByHalfPlane(e.complement()))return!0;return!1}getVerticesOnHalfPlane(t){const e=[];for(let n of this.vertices)(n.leftHalfPlane===t||n.rightHalfPlane===t)&&e.push(n);return e}hasAtMostOneVertex(t){let e=0;for(let n of this.vertices)if((n.leftHalfPlane===t||n.rightHalfPlane===t)&&(e++,e>1))return!1;return!0}getTangentPlanesThroughInfinityInDirection(t){const e=[];for(let n of this.vertices){const i=P.withBorderPointAndInfinityInDirection(n.point,t);for(let r of i)this.isContainedByHalfPlane(r)&&e.push(r)}return e}getPointsAtInfinityFromHalfPlanes(){const t=[];for(let e of this.halfPlanes){const n=e.normalTowardInterior,i=n.getPerpendicular();t.push(n),t.push(i),t.push(i.scale(-1))}return t}isContainedByRay(t){return!1}isContainedByLineSegment(t){return!1}isContainedByLine(t){return!1}isContainedByConvexPolygon(t){for(let e of t.halfPlanes)if(!this.isContainedByHalfPlane(e))return!1;return!0}static getHalfPlanes(t){const e=[];for(let n of t)e.indexOf(n.leftHalfPlane)===-1&&e.push(n.leftHalfPlane),e.indexOf(n.rightHalfPlane)===-1&&e.push(n.rightHalfPlane);return e}static getVerticesNotContainingAnyOther(t){const e=[];for(let n=0;n<t.length;n++){let i=!0;for(let r=0;r<t.length;r++)if(n!==r&&t[r].isContainedByVertex(t[n])){i=!1;break}i&&e.push(t[n])}return e}static getHalfPlanesNotContainingAnyOther(t){const e=[];for(let n of t){let i=!0;for(let r of e)if(r.isContainedByHalfPlane(n)){i=!1;break}i&&e.push(n)}return e}static groupVerticesByPoint(t){const e=[];for(let n of t){let i;for(let r of e)if(r[0].point.equals(n.point)){i=r;break}i?i.push(n):e.push([n])}return e}static getVertices(t){const e=[];for(let n=0;n<t.length;n++)for(let i=n+1;i<t.length;i++){const r=t[n],o=t[i];if(r.complement().isContainedByHalfPlane(o))continue;const c=r.getIntersectionWith(o);let l=!0;for(let u=0;u<t.length;u++){if(u===n||u===i)continue;if(!t[u].containsPoint(c.point)){l=!1;break}}l&&e.push(c)}return e}static createTriangleWithInfinityInTwoDirections(t,e,n){const i=e.getPerpendicular(),r=n.getPerpendicular();return e.cross(n)<0?new m([new P(t,i.scale(-1)),new P(t,r)]):new m([new P(t,i),new P(t,r.scale(-1))])}static createFromHalfPlane(t){return new m([t])}static createTriangleWithInfinityInDirection(t,e,n){const i=e.minus(t).projectOn(n.getPerpendicular());return new m([new P(t,i),new P(e,i.scale(-1)),P.throughPointsAndContainingPoint(t,e,t.plus(n))])}static createTriangle(t,e,n){return new m([P.throughPointsAndContainingPoint(t,e,n),P.throughPointsAndContainingPoint(t,n,e),P.throughPointsAndContainingPoint(e,n,t)])}}class Ki{constructor(t){this.instructions=t}execute(t,e,n){for(const i of this.instructions)i.execute(t,e,n)}}class ji{constructor(t,e){this.instruction=t,this.tempStateInstruction=e}execute(t,e){t.save(),this.tempStateInstruction.execute(t,e),this.instruction.execute(t,e),t.restore()}}class Qi{constructor(t){this.getTransformation=t}execute(t,e){const{a:n,b:i,c:r,d:o,e:c,f:l}=this.getTransformation(e);t.setTransform(n,i,r,o,c,l)}}class Ji{constructor(t){this.getTransformation=t}execute(t,e){const{a:n,b:i,c:r,d:o,e:c,f:l}=this.getTransformation(e);t.transform(n,i,r,o,c,l)}}class Zi{constructor(t,e){this.instruction=t,this.infinity=e}execute(t,e){this.instruction.execute(t,e,this.infinity)}}function _i(s,t){return t?new ji(s,t):s}function ts(s,t){return new Zi(s,t)}function E(...s){return new Ki(s)}function es(s){return s===z.Relative?new Ji(t=>t.getBitmapTransformationToTransformedInfiniteCanvasContext()):s===z.Absolute?new Qi(t=>t.getBitmapTransformationToInfiniteCanvasContext()):null}function ns(s,t){let e=s.area;return e&&t.lineWidth>0&&(e=e.expandByDistance(t.lineWidth/2)),e}function is(s){return{lineWidth:s.current.getMaximumLineWidth(),lineDashPeriod:s.current.getLineDashPeriod(),shadowOffsets:s.current.getShadowOffsets()}}function ss(s){return{lineWidth:0,lineDashPeriod:0,shadowOffsets:s.current.getShadowOffsets()}}class G{constructor(t,e,n,i,r,o,c){this.instruction=t,this.area=e,this.build=n,this.takeClippingRegionIntoAccount=i,this.transformationKind=r,this.state=o,this.tempState=c}static forStrokingPath(t,e,n){return G.forPath(t,e,is,n)}static forFillingPath(t,e,n){return G.forPath(t,e,ss,n)}static forPath(t,e,n,i){const r=e.current.isTransformable(),o=r?z.None:z.Relative,c=e.currentlyTransformed(r),l=n(c),u=i(c),d=ns(u,l);return new G(t,d,f=>u.drawPath(f,c,l),!0,o,c)}getDrawnArea(){let t=this.area;const e=this.state;if(e.current.shadowBlur!==0||!e.current.shadowOffset.equals(h.origin)){const n=t.expandByDistance(e.current.shadowBlur).transform(v.translation(e.current.shadowOffset.x,e.current.shadowOffset.y));t=t.join(n)}return e.current.clippingRegion&&this.takeClippingRegionIntoAccount&&(t=t.intersectWith(e.current.clippingRegion)),t}getModifiedInstruction(){let t=es(this.transformationKind);if(this.tempState){const n=this.takeClippingRegionIntoAccount?this.state.getInstructionToConvertToStateWithClippedPath(this.tempState):this.state.getInstructionToConvertToState(this.tempState);t=E(t,n)}return _i(this.instruction,t)}}class we{constructor(t){a(this,"added",[]);a(this,"addedLast");this.initiallyWithState=t}get length(){return this.added.length}get currentlyWithState(){return this.addedLast?this.addedLast:this.initiallyWithState}reconstructState(t,e){e.setInitialState(t)}get stateOfFirstInstruction(){return this.initiallyWithState.stateOfFirstInstruction}get state(){return this.currentlyWithState.state}get initialState(){return this.initiallyWithState.initialState}addClippedPath(t){this.currentlyWithState.addClippedPath(t)}add(t){this.added.push(t),this.addedLast=t}removeAll(t){let e;for(;(e=this.added.findIndex(t))>-1;)this.removeAtIndex(e)}contains(t){return!!this.added.find(t)}setInitialState(t){this.initiallyWithState.setInitialState(t)}setInitialStateWithClippedPaths(t){this.initiallyWithState.setInitialStateWithClippedPaths(t)}beforeIndex(t){return t===0?this.initiallyWithState.state:this.added[t-1].state}removeAtIndex(t){t===this.added.length-1?this.added.length===1?this.addedLast=void 0:this.addedLast=this.added[t-1]:this.reconstructState(this.beforeIndex(t),this.added[t+1]),this.added.splice(t,1)}}class Pe{constructor(t,e){a(this,"stateConversion");this.initialState=t,this.state=e,this.stateConversion=w}setInitialState(t){this.initialState=t;const e=this.initialState.getInstructionToConvertToState(this.state);this.stateConversion=e}get stateOfFirstInstruction(){return this.state}addClippedPath(t){this.state=this.state.withClippedPath(t)}setInitialStateWithClippedPaths(t){this.initialState=t;const e=this.initialState.getInstructionToConvertToStateWithClippedPath(this.state);this.stateConversion=e}}class X extends Pe{constructor(t,e,n,i){super(t,e),this.instruction=n,this.stateConversion=i}execute(t,e){this.stateConversion&&this.stateConversion.execute(t,e),this.instruction.execute(t,e)}static create(t,e){return new X(t,t,e,w)}}class ut extends Pe{constructor(t,e,n,i){super(t,e),this.instruction=n,this.stateConversion=i}makeExecutable(){return new X(this.initialState,this.state,this.instruction,this.stateConversion)}static create(t,e){return new ut(t,t,e,w)}}function S(s){return s.direction!==void 0}function J(s,t){return S(s)?t.applyToPointAtInfinity(s):t.apply(s)}class rs{constructor(t,e){this.areaBuilder=t,this.transformation=e}addPosition(t){this.areaBuilder.addPosition(J(t,this.transformation))}}class Ce{constructor(t,e){this.base=t,this.direction=e}pointIsOnSameLine(t){return t.minus(this.base).cross(this.direction)===0}comesBefore(t,e){return e.minus(t).dot(this.direction)>=0}lineSegmentIsOnSameLine(t){return this.direction.cross(t.direction)===0&&this.pointIsOnSameLine(t.point1)}expandLineByDistance(t){const e=this.direction.getPerpendicular(),n=new P(this.base,e).expandByDistance(t),i=new P(this.base,e.scale(-1)).expandByDistance(t);return new m([n,i])}getPointsInSameDirection(t,e){return this.comesBefore(e,t)?{point1:e,point2:t}:{point1:t,point2:e}}pointIsBetweenPoints(t,e,n){return t.minus(e).dot(this.direction)*t.minus(n).dot(this.direction)<=0}intersectsConvexPolygon(t){if(this.isContainedByConvexPolygon(t))return!0;const e=t.getIntersectionsWithLine(this.base,this.direction);for(let n of e)if(this.interiorContainsPoint(n.point))return!0;return!1}}class Yt extends Ce{getVertices(){return[]}intersectWith(t){return t.intersectWithLine(this)}join(t){return t.expandToIncludeInfinityInDirection(this.direction).expandToIncludeInfinityInDirection(this.direction.scale(-1))}intersectWithConvexPolygon(t){if(!this.intersectsConvexPolygon(t))return B;if(this.isContainedByConvexPolygon(t))return this;const e=t.getIntersectionsWithLine(this.base,this.direction);let n,i;for(let r of e)(!n&&!i||!n&&this.comesBefore(r.point,i)||!i&&this.comesBefore(n,r.point)||n&&i&&this.pointIsBetweenPoints(r.point,n,i))&&(r.halfPlane.normalTowardInterior.dot(this.direction)>0?n=r.point:i=r.point);return n&&i?new R(n,i):n?new Y(n,this.direction):new Y(i,this.direction.scale(-1))}intersectWithLine(t){return this.intersectsLine(t)?this:B}intersectWithLineSegment(t){return this.lineSegmentIsOnSameLine(t)?t:B}intersectWithRay(t){return this.intersectsRay(t)?t:B}isContainedByConvexPolygon(t){return t.containsPoint(this.base)&&t.containsInfinityInDirection(this.direction)&&t.containsInfinityInDirection(this.direction.scale(-1))}isContainedByLine(t){return this.intersectsSubsetOfLine(t)}isContainedByLineSegment(t){return!1}isContainedByRay(t){return!1}contains(t){return t.isContainedByLine(this)}intersectsLine(t){return this.intersectsSubsetOfLine(t)}intersectsSubsetOfLine(t){return this.pointIsOnSameLine(t.base)&&this.direction.cross(t.direction)===0}intersectsLineSegment(t){return this.lineSegmentIsOnSameLine(t)}intersectsRay(t){return this.intersectsSubsetOfLine(t)}intersects(t){return t.intersectsLine(this)}expandToIncludePoint(t){return this.pointIsOnSameLine(t)?this:m.createTriangleWithInfinityInDirection(this.base,t,this.direction).expandToIncludeInfinityInDirection(this.direction.scale(-1))}expandByDistance(t){return this.expandLineByDistance(t)}expandToIncludeInfinityInDirection(t){const e=t.cross(this.direction),n=this.direction.getPerpendicular();return e===0?this:e>0?m.createFromHalfPlane(new P(this.base,n.scale(-1))):m.createFromHalfPlane(new P(this.base,n))}transform(t){const e=t.apply(this.base);return new Yt(e,t.apply(this.base.plus(this.direction)).minus(e))}interiorContainsPoint(t){return this.pointIsOnSameLine(t)}}class Y extends Ce{getVertices(){return[this.base]}intersectWith(t){return t.intersectWithRay(this)}join(t){return t.expandToIncludePoint(this.base).expandToIncludeInfinityInDirection(this.direction)}intersectWithConvexPolygon(t){if(!this.intersectsConvexPolygon(t))return B;if(this.isContainedByConvexPolygon(t))return this;const e=t.getIntersectionsWithLine(this.base,this.direction);let n=this.base,i;for(let r of e)(!i&&this.comesBefore(n,r.point)||i&&this.pointIsBetweenPoints(r.point,n,i))&&(r.halfPlane.normalTowardInterior.dot(this.direction)>0?n=r.point:i=r.point);return i?new R(n,i):new Y(n,this.direction)}intersectWithRay(t){return this.isContainedByRay(t)?this:t.isContainedByRay(this)?t:this.interiorContainsPoint(t.base)?new R(this.base,t.base):B}intersectWithLine(t){return t.intersectWithRay(this)}intersectWithLineSegment(t){if(t.isContainedByRay(this))return t;if(!this.lineSegmentIsOnSameLine(t))return B;let{point2:e}=this.getPointsInSameDirection(t.point1,t.point2);return this.comesBefore(e,this.base)?B:new R(this.base,e)}isContainedByConvexPolygon(t){return t.containsPoint(this.base)&&t.containsInfinityInDirection(this.direction)}isContainedByRay(t){return t.containsPoint(this.base)&&t.containsInfinityInDirection(this.direction)}isContainedByLine(t){return t.intersectsSubsetOfLine(this)}isContainedByLineSegment(t){return!1}contains(t){return t.isContainedByRay(this)}intersectsRay(t){return this.isContainedByRay(t)||t.isContainedByRay(this)||this.interiorContainsPoint(t.base)}intersectsLine(t){return t.intersectsSubsetOfLine(this)}intersectsLineSegment(t){if(t.isContainedByRay(this))return!0;if(!this.lineSegmentIsOnSameLine(t))return!1;let{point2:e}=this.getPointsInSameDirection(t.point1,t.point2);return!this.comesBefore(e,this.base)}intersects(t){return t.intersectsRay(this)}expandToIncludePoint(t){return this.containsPoint(t)?this:this.pointIsOnSameLine(t)?new Y(t,this.direction):m.createTriangleWithInfinityInDirection(this.base,t,this.direction)}expandByDistance(t){const e=this.expandLineByDistance(t),n=new P(this.base,this.direction).expandByDistance(t);return e.intersectWithConvexPolygon(new m([n]))}expandToIncludeInfinityInDirection(t){return t.inSameDirectionAs(this.direction)?this:this.direction.cross(t)===0?new Yt(this.base,this.direction):m.createTriangleWithInfinityInTwoDirections(this.base,this.direction,t)}transform(t){const e=t.apply(this.base);return new Y(e,t.apply(this.base.plus(this.direction)).minus(e))}interiorContainsPoint(t){return this.pointIsOnSameLine(t)&&!this.comesBefore(t,this.base)}containsInfinityInDirection(t){return this.direction.inSameDirectionAs(t)}containsPoint(t){return this.pointIsOnSameLine(t)&&this.comesBefore(this.base,t)}}class R extends Ce{constructor(t,e){super(t,e.minus(t)),this.point1=t,this.point2=e}getVertices(){return[this.point1,this.point2]}join(t){return t.expandToIncludePoint(this.point1).expandToIncludePoint(this.point2)}intersectWith(t){return t.intersectWithLineSegment(this)}intersectWithLineSegment(t){if(this.isContainedByLineSegment(t))return this;if(t.isContainedByLineSegment(this))return t;if(!this.lineSegmentIsOnSameLine(t))return B;let{point1:e,point2:n}=this.getPointsInSameDirection(t.point1,t.point2);return this.comesBefore(n,this.point1)||this.comesBefore(this.point2,e)?B:this.comesBefore(this.point1,e)?new R(e,this.point2):new R(this.point1,n)}intersectWithRay(t){return t.intersectWithLineSegment(this)}intersectWithLine(t){return t.intersectWithLineSegment(this)}isContainedByRay(t){return t.containsPoint(this.point1)&&t.containsPoint(this.point2)}isContainedByLine(t){return t.intersectsSubsetOfLine(this)}isContainedByLineSegment(t){return t.containsPoint(this.point1)&&t.containsPoint(this.point2)}intersectWithConvexPolygon(t){if(!this.intersectsConvexPolygon(t))return B;if(this.isContainedByConvexPolygon(t))return this;const e=t.getIntersectionsWithLine(this.point1,this.direction);let n=this.point1,i=this.point2;for(let r of e)this.pointIsBetweenPoints(r.point,n,i)&&(r.halfPlane.normalTowardInterior.dot(this.direction)>0?n=r.point:i=r.point);return new R(n,i)}isContainedByConvexPolygon(t){return t.containsPoint(this.point1)&&t.containsPoint(this.point2)}contains(t){return t.isContainedByLineSegment(this)}pointIsStrictlyBetweenPoints(t,e,n){return t.minus(e).dot(this.direction)*t.minus(n).dot(this.direction)<0}containsPoint(t){return this.pointIsOnSameLine(t)&&this.pointIsBetweenPoints(t,this.point1,this.point2)}interiorContainsPoint(t){return this.pointIsOnSameLine(t)&&this.pointIsStrictlyBetweenPoints(t,this.point1,this.point2)}intersectsRay(t){return t.intersectsLineSegment(this)}intersectsLineSegment(t){if(this.isContainedByLineSegment(t)||t.isContainedByLineSegment(this))return!0;if(!this.lineSegmentIsOnSameLine(t))return!1;const{point1:e,point2:n}=this.getPointsInSameDirection(t.point1,t.point2);return!this.comesBefore(n,this.point1)&&!this.comesBefore(this.point2,e)}intersectsLine(t){return t.intersectsSubsetOfLine(this)}intersects(t){return t.intersectsLineSegment(this)}expandByDistance(t){const e=this.expandLineByDistance(t),n=new P(this.base,this.direction).expandByDistance(t),i=new P(this.point2,this.direction.scale(-1)).expandByDistance(t);return e.intersectWithConvexPolygon(new m([n,i]))}expandToIncludePoint(t){return this.containsPoint(t)?this:this.pointIsOnSameLine(t)?this.comesBefore(t,this.point1)?new R(t,this.point2):new R(this.point1,t):m.createTriangle(this.point1,t,this.point2)}expandToIncludeInfinityInDirection(t){return t.inSameDirectionAs(this.direction)?new Y(this.point1,t):t.cross(this.direction)===0?new Y(this.point2,t):m.createTriangleWithInfinityInDirection(this.point1,this.point2,t)}transform(t){return new R(t.apply(this.point1),t.apply(this.point2))}}class os{addPoint(t){return lt}addPointAtInfinity(t){return this}addArea(t){return lt}}const Ie=new os;class Te{constructor(t){this.towardsMiddle=t}addPoint(t){return m.createFromHalfPlane(new P(t,this.towardsMiddle))}addPointAtInfinity(t){return t.dot(this.towardsMiddle)>=0?this:Ie}addArea(t){const e=this.towardsMiddle.getPerpendicular();return t.expandToIncludeInfinityInDirection(this.towardsMiddle).expandToIncludeInfinityInDirection(e).expandToIncludeInfinityInDirection(e.scale(-1))}}class Xt{constructor(t,e){this.direction1=t,this.direction2=e}addPoint(t){return m.createTriangleWithInfinityInTwoDirections(t,this.direction1,this.direction2)}addPointAtInfinity(t){return t.isInSmallerAngleBetweenPoints(this.direction1,this.direction2)?this:t.cross(this.direction1)===0?new Te(this.direction2.projectOn(this.direction1.getPerpendicular())):t.cross(this.direction2)===0?new Te(this.direction1.projectOn(this.direction2.getPerpendicular())):this.direction1.isInSmallerAngleBetweenPoints(t,this.direction2)?new Xt(t,this.direction2):this.direction2.isInSmallerAngleBetweenPoints(t,this.direction1)?new Xt(t,this.direction1):Ie}addArea(t){return t.expandToIncludeInfinityInDirection(this.direction1).expandToIncludeInfinityInDirection(this.direction2)}}class as{constructor(t){this.direction=t}addPoint(t){return new Yt(t,this.direction)}addPointAtInfinity(t){return t.cross(this.direction)===0?this:new Te(t.projectOn(this.direction.getPerpendicular()))}addArea(t){return t.expandToIncludeInfinityInDirection(this.direction).expandToIncludeInfinityInDirection(this.direction.scale(-1))}}class cs{constructor(t){this.direction=t}addPointAtInfinity(t){return t.inSameDirectionAs(this.direction)?this:t.cross(this.direction)===0?new as(this.direction):new Xt(this.direction,t)}addPoint(t){return new Y(t,this.direction)}addArea(t){return t.expandToIncludeInfinityInDirection(this.direction)}}class hs{constructor(t,e,n){this._area=t,this.firstPoint=e,this.subsetOfLineAtInfinity=n}get area(){return this._area||B}addPoint(t){this._area?this._area=this._area.expandToIncludePoint(t):this.firstPoint?t.equals(this.firstPoint)||(this._area=new R(this.firstPoint,t)):this.subsetOfLineAtInfinity?this._area=this.subsetOfLineAtInfinity.addPoint(t):this.firstPoint=t}addPosition(t){S(t)?this.addInfinityInDirection(t.direction):this.addPoint(t)}addInfinityInDirection(t){this._area?this._area=this._area.expandToIncludeInfinityInDirection(t):this.firstPoint?this._area=new Y(this.firstPoint,t):this.subsetOfLineAtInfinity?(this.subsetOfLineAtInfinity=this.subsetOfLineAtInfinity.addPointAtInfinity(t),this.subsetOfLineAtInfinity===Ie&&(this._area=lt)):this.subsetOfLineAtInfinity=new cs(t)}transformedWith(t){return new rs(this,t)}}class Ut extends Pe{constructor(t,e,n,i){super(t,e),this.instruction=n,this.stateConversion=i}replaceInstruction(t){this.instruction=t}makeExecutable(t){const e=t.getInfinity(this.state),n=this.instruction,i=ts(n,e);return new X(this.initialState,this.state,i,this.stateConversion)}static create(t,e){return new Ut(t,t,e,w)}}function ls(s,t){return s?t?S(s)?S(t)&&s.direction.equals(t.direction):!S(t)&&s.equals(t):!s:!t}class us{constructor(t,e){this.point=t,this.direction=e}execute(t,e,n){n.moveToInfinityFromPointInDirection(t,e,this.point,this.direction)}}class ds{constructor(t,e,n){this.point1=t,this.point2=e,this.direction=n}execute(t,e,n){n.drawLineFromInfinityFromPointToInfinityFromPoint(t,e,this.point1,this.point2,this.direction)}}class fs{constructor(t,e){this.point=t,this.direction=e}execute(t,e,n){n.drawLineFromInfinityFromPointToPoint(t,e,this.point,this.direction)}}class gs{constructor(t,e){this.point=t,this.direction=e}execute(t,e,n){n.drawLineToInfinityFromPointInDirection(t,e,this.point,this.direction)}}class ms{constructor(t){this.point=t}execute(t,e){const{x:n,y:i}=e.userTransformation.apply(this.point);t.moveTo(n,i)}}class ps{constructor(t){this.point=t}execute(t,e){const{x:n,y:i}=e.userTransformation.apply(this.point);t.lineTo(n,i)}}class vs{constructor(t,e,n){this.point=t,this.fromDirection=e,this.toDirection=n}execute(t,e,n){n.drawLineToInfinityFromInfinityFromPoint(t,e,this.point,this.fromDirection,this.toDirection)}}class It{constructor(t){this.shape=t}getInstructionToDrawLineTo(t,e){return this.getInstructionToExtendShapeWithLineTo(this.shape.transform(e.current.transformation.inverse()),t)}getInstructionToMoveToBeginning(t){return this.getInstructionToMoveToBeginningOfShape(this.shape.transform(t.current.transformation.inverse()))}get currentPosition(){return this.shape.currentPosition}moveToInfinityFromPointInDirection(t,e){return new us(t,e)}lineFromInfinityFromPointToInfinityFromPoint(t,e,n){return new ds(t,e,n)}lineFromInfinityFromPointToPoint(t,e){return new fs(t,e)}lineToInfinityFromPointInDirection(t,e){return new gs(t,e)}lineToInfinityFromInfinityFromPoint(t,e,n){return new vs(t,e,n)}lineTo(t){return new ps(t)}moveTo(t){return new ms(t)}}class $t{constructor(t,e,n,i){this.initialPosition=t,this.firstFinitePoint=e,this.lastFinitePoint=n,this.currentPosition=i}transform(t){return new $t(t.applyToPointAtInfinity(this.initialPosition),t.apply(this.firstFinitePoint),t.apply(this.lastFinitePoint),t.applyToPointAtInfinity(this.currentPosition))}}class Tt{constructor(t,e,n){this.initialPosition=t,this.firstFinitePoint=e,this.currentPosition=n}transform(t){return new Tt(t.applyToPointAtInfinity(this.initialPosition),t.apply(this.firstFinitePoint),t.apply(this.currentPosition))}}class ws extends It{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){return t.initialPosition.direction.cross(t.currentPosition.direction)===0?this.moveToInfinityFromPointInDirection(t.firstFinitePoint,t.initialPosition.direction):E(this.moveToInfinityFromPointInDirection(t.lastFinitePoint,t.currentPosition.direction),this.lineToInfinityFromInfinityFromPoint(t.lastFinitePoint,t.currentPosition.direction,t.initialPosition.direction),this.lineFromInfinityFromPointToInfinityFromPoint(t.lastFinitePoint,t.firstFinitePoint,t.initialPosition.direction))}getInstructionToExtendShapeWithLineTo(t,e){return S(e)?this.lineToInfinityFromInfinityFromPoint(t.lastFinitePoint,t.currentPosition.direction,e.direction):E(this.lineFromInfinityFromPointToInfinityFromPoint(t.lastFinitePoint,e,t.currentPosition.direction),this.lineFromInfinityFromPointToPoint(e,t.currentPosition.direction))}containsFinitePoint(){return!0}surroundsFinitePoint(){return!0}isClosable(){return!this.shape.initialPosition.direction.isInOppositeDirectionAs(this.shape.currentPosition.direction)}canAddLineTo(t){return!S(t)||!t.direction.isInOppositeDirectionAs(this.shape.currentPosition.direction)}addPosition(t){return S(t)?this.pathBuilderProvider.fromPointAtInfinityToPointAtInfinity(new $t(this.shape.initialPosition,this.shape.firstFinitePoint,this.shape.lastFinitePoint,t)):this.pathBuilderProvider.fromPointAtInfinityToPoint(new Tt(this.shape.initialPosition,this.shape.firstFinitePoint,t))}}class Ps extends It{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){const e=this.moveToInfinityFromPointInDirection(t.currentPosition,t.initialPosition.direction);if(t.currentPosition.equals(t.firstFinitePoint))return e;const n=this.lineFromInfinityFromPointToInfinityFromPoint(t.currentPosition,t.firstFinitePoint,t.initialPosition.direction);return E(e,n)}getInstructionToExtendShapeWithLineTo(t,e){return S(e)?this.lineToInfinityFromPointInDirection(t.currentPosition,e.direction):this.lineTo(e)}canAddLineTo(t){return!0}containsFinitePoint(){return!0}surroundsFinitePoint(){return!0}isClosable(){return!0}addPosition(t){return S(t)?this.pathBuilderProvider.fromPointAtInfinityToPointAtInfinity(new $t(this.shape.initialPosition,this.shape.firstFinitePoint,this.shape.currentPosition,t)):this.pathBuilderProvider.fromPointAtInfinityToPoint(new Tt(this.shape.initialPosition,this.shape.firstFinitePoint,t))}}class Kt{constructor(t,e){this.initialPoint=t,this.currentPosition=e}transform(t){return new Kt(t.apply(this.initialPoint),t.applyToPointAtInfinity(this.currentPosition))}}class St{constructor(t,e){this.initialPoint=t,this.currentPosition=e}transform(t){return new St(t.apply(this.initialPoint),t.apply(this.currentPosition))}}class Cs extends It{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){return this.moveTo(t.initialPoint)}getInstructionToExtendShapeWithLineTo(t,e){return S(e)?e.direction.inSameDirectionAs(t.currentPosition.direction)?w:this.lineToInfinityFromInfinityFromPoint(t.initialPoint,t.currentPosition.direction,e.direction):E(this.lineFromInfinityFromPointToInfinityFromPoint(t.initialPoint,e,t.currentPosition.direction),this.lineFromInfinityFromPointToPoint(e,t.currentPosition.direction))}canAddLineTo(t){return!S(t)||!t.direction.isInOppositeDirectionAs(this.shape.currentPosition.direction)}containsFinitePoint(){return!0}surroundsFinitePoint(){return!0}isClosable(){return!0}addPosition(t){return S(t)?this.pathBuilderProvider.fromPointToPointAtInfinity(new Kt(this.shape.initialPoint,t)):this.pathBuilderProvider.fromPointToPoint(new St(this.shape.initialPoint,t))}}class An extends It{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){return this.moveTo(t.initialPoint)}getInstructionToExtendShapeWithLineTo(t,e){if(S(e)){const n=this.lineToInfinityFromPointInDirection(t.currentPosition,e.direction);if(t.currentPosition.minus(t.initialPoint).cross(e.direction)===0)return n;const i=this.lineFromInfinityFromPointToInfinityFromPoint(t.currentPosition,t.initialPoint,e.direction);return E(n,i)}return this.lineTo(e)}canAddLineTo(t){return!0}containsFinitePoint(){return!0}surroundsFinitePoint(){return!0}isClosable(){return!0}addPosition(t){return S(t)?this.pathBuilderProvider.fromPointToPointAtInfinity(new Kt(this.shape.initialPoint,t)):this.pathBuilderProvider.fromPointToPoint(new St(this.shape.initialPoint,t))}}class Is{constructor(t){this.counterclockwise=t}execute(t,e,n){n.addPathAroundViewbox(t,e,this.counterclockwise)}}class Dn extends It{constructor(t,e){super(