UNPKG

ef-infinite-canvas

Version:

An infinite version of the html canvas

1 lines 165 kB
(function(F,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(F=typeof globalThis<"u"?globalThis:F||self,F.InfiniteCanvas=h())})(this,function(){"use strict";var co=Object.defineProperty;var ho=(F,h,W)=>h in F?co(F,h,{enumerable:!0,configurable:!0,writable:!0,value:W}):F[h]=W;var a=(F,h,W)=>ho(F,typeof h!="symbol"?h+"":h,W);let F=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 W(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,u){const l=n-t,f=i-e,d=l*l+f*f;if(d===0)throw new Error("divide by 0");const m=c-r,P=u-o,C=m*m+P*P,x=Math.sqrt(C/d);return O.zoom(t,e,x,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,u){const l=n-t,f=i-e,d=l*l+f*f;if(d===0)throw new Error("divide by 0");const m=c-r,P=u-o,C=t*i-e*n,x=n*l+i*f,B=t*l+e*f,G=(l*m+f*P)/d,et=(l*P-f*m)/d,nt=-et,Dt=G,Et=(r*x-c*B-C*P)/d,Rt=(o*x-u*B+C*m)/d;return new O(G,et,nt,Dt,Et,Rt)}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: (${W(this.a)}, ${W(this.b)}), y: (${W(this.c)}, ${W(this.d)}), d: (${W(this.e)}, ${W(this.f)})`}};a(O,"identity",new O(1,0,0,1,0,0));let v=O;class S{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 y=()=>{};class si extends S{valuesAreEqual(t,e){return t.equals(e)}changeToNewValue(t){return(e,n)=>{const{a:i,b:r,c:o,d:c,e:u,f:l}=n.getTransformationForInstruction(t);e.setTransform(i,r,o,c,u,l)}}}const Ft=new si("transformation",y);class oi{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=>Ft.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,u,l,f,d,m;typeof t=="number"?(c=t,u=e,l=n,f=i,d=r,m=o):t.a!==void 0?(c=t.a,u=t.b,l=t.c,f=t.d,d=t.e,m=t.f):(c=t.m11,u=t.m12,l=t.m21,f=t.m22,d=t.m41,m=t.m42),this.viewBox.changeState(P=>Ft.changeInstanceValue(P,new v(c,u,l,f,d,m)))}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=>Ft.changeInstanceValue(i,n))}}class ai extends S{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return e=>e.globalAlpha=t}}const Qe=new ai("globalAlpha",y);class ci extends S{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return e=>e.globalCompositeOperation=t}}const Je=new ci("globalCompositeOperation",y);class hi{constructor(t){this.viewBox=t}get globalAlpha(){return this.viewBox.state.current.globalAlpha}set globalAlpha(t){this.viewBox.changeState(e=>Qe.changeInstanceValue(e,t))}get globalCompositeOperation(){return this.viewBox.state.current.globalCompositeOperation}set globalCompositeOperation(t){this.viewBox.changeState(e=>Je.changeInstanceValue(e,t))}}class li extends S{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return e=>{e.imageSmoothingEnabled=t}}}const Ze=new li("imageSmoothingEnabled",y);class ui extends S{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return e=>{e.imageSmoothingQuality=t}}}const _e=new ui("imageSmoothingQuality",y);class di{constructor(t){this.viewBox=t}get imageSmoothingEnabled(){return this.viewBox.state.current.imageSmoothingEnabled}set imageSmoothingEnabled(t){this.viewBox.changeState(e=>Ze.changeInstanceValue(e,t))}get imageSmoothingQuality(){return this.viewBox.state.current.imageSmoothingQuality}set imageSmoothingQuality(t){this.viewBox.changeState(e=>_e.changeInstanceValue(e,t))}}class Wt{}class tn extends Wt{constructor(t){super(),this.fillStrokeStyle=t}setTransform(t){this.fillStrokeStyle.setTransform(t)}getInstructionToSetUntransformed(t){return e=>{e[t]=this.fillStrokeStyle}}getInstructionToSetTransformed(t){return e=>{e[t]=this.fillStrokeStyle}}}class en{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 Wt)||t.fillAndStrokeStylesTransformed===e.fillAndStrokeStylesTransformed?()=>{}:e.fillAndStrokeStylesTransformed?n.getInstructionToSetTransformed(this.propName):n.getInstructionToSetUntransformed(this.propName):n instanceof Wt?e.fillAndStrokeStylesTransformed?n.getInstructionToSetTransformed(this.propName):n.getInstructionToSetUntransformed(this.propName):i=>{i[this.propName]=e[this.propName]}}valueIsTransformableForInstance(t){return!(t[this.propName]instanceof tn)}}const nn=new en("fillStyle"),rn=new en("strokeStyle");class fi{constructor(t){this.viewBox=t}set fillStyle(t){this.viewBox.changeState(e=>nn.changeInstanceValue(e,t))}set strokeStyle(t){this.viewBox.changeState(e=>rn.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 gi extends S{valuesAreEqual(t,e){return t===e}changeToNewValue(t){return e=>{e.shadowColor=t}}}const sn=new gi("shadowColor",y);class mi extends S{changeToNewValue(t){return(e,n)=>{const i=v.translation(t.x,t.y),r=n.translateInfiniteCanvasContextTransformationToBitmapTransformation(i),{x:o,y:c}=r.apply(h.origin);e.shadowOffsetX=o,e.shadowOffsetY=c}}valuesAreEqual(t,e){return t.x===e.x&&t.y==e.y}}const de=new mi("shadowOffset",y);class pi extends S{changeToNewValue(t){return(e,n)=>{const i=v.translation(t,0),o=n.translateInfiniteCanvasContextTransformationToBitmapTransformation(i).apply(h.origin).mod();e.shadowBlur=o}}valuesAreEqual(t,e){return t===e}}const on=new pi("shadowBlur",y);class vi{constructor(t){this.viewBox=t}get shadowBlur(){return this.viewBox.state.current.shadowBlur}set shadowBlur(t){this.viewBox.changeState(e=>on.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=>de.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=>de.changeInstanceValue(n,e))}get shadowColor(){return this.viewBox.state.current.shadowColor}set shadowColor(t){this.viewBox.changeState(e=>sn.changeInstanceValue(e,t))}}const an="[+-]?(?:\\d*\\.)?\\d+(?:e[+-]?\\d+)?",cn="[+-]?(?:0*\\.)?0+(?:e[+-]?\\d+)?",hn="(?:ch|em|ex|ic|rem|vh|vw|vmax|vmin|vb|vi|cqw|cqh|cqi|cqb|cqmin|cqmax|px|cm|mm|Q|in|pc|pt)",kt=`(?:${cn}|${an}${hn})`,ln=`blur\\((${kt})\\)`,un="[^())\\s]+(?:\\([^)]*?\\))?",dn=`drop-shadow\\((${kt})\\s+(${kt})\\s*?(?:(?:(${kt})\\s*?(${un})?)|(${un}))?\\)`,fn=`${ln}|${dn}`;function k(s,t){const e=s.match(new RegExp(`(?:(${cn})|(${an})(${hn}))`));return e[1]?0:t.getNumberOfPixels(Number.parseFloat(e[2]),e[3])}class gn{constructor(t){this.stringRepresentation=t}toTransformedString(){return this.stringRepresentation}getShadowOffset(){return null}}class fe{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(ln));return n===null?null:new fe(t,k(n[1],e))}}class lt{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(dn));return n===null?null:n[5]?new lt(t,k(n[1],e),k(n[2],e),null,n[5]):n[4]?new lt(t,k(n[1],e),k(n[2],e),k(n[3],e),n[4]):n[3]?new lt(t,k(n[1],e),k(n[2],e),k(n[3],e),null):new lt(t,k(n[1],e),k(n[2],e),null,null)}}const At=class At{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(`${fn}|((?!\\s|${fn}).)+`,"g")).map(r=>this.createPart(r,e));return new At(t,i)}static createPart(t,e){let n=fe.tryCreate(t,e);return n!==null||(n=lt.tryCreate(t,e),n!=null)?n:new gn(t)}};a(At,"none",new At("none",[new gn("none")]));let Ht=At;class wi extends S{valuesAreEqual(t,e){return t.stringRepresentation===e.stringRepresentation}changeToNewValue(t){return(e,n)=>e.filter=t.toTransformedString(n)}}const mn=new wi("filter",y);class Pi{constructor(t,e){this.viewBox=t,this.cssLengthConverterFactory=e}get filter(){return this.viewBox.state.current.filter.stringRepresentation}set filter(t){const e=Ht.create(t,this.cssLengthConverterFactory.create());this.viewBox.changeState(n=>mn.changeInstanceValue(n,e))}}class Ci{constructor(t){this.viewBox=t}clearRect(t,e,n,i){this.viewBox.clearArea(t,e,n,i)}fillRect(t,e,n,i){let r=o=>o.fill();this.viewBox.fillRect(t,e,n,i,r)}strokeRect(t,e,n,i){this.viewBox.strokeRect(t,e,n,i)}}class Ii{constructor(t){this.viewBox=t}isFillRule(t){return t==="evenodd"||t==="nonzero"}beginPath(){this.viewBox.beginPath()}clip(t,e){let n=this.isFillRule(t)?i=>{i.clip(t)}:i=>{i.clip()};this.viewBox.clipPath(n)}fill(t,e){if((!t||this.isFillRule(t))&&!this.viewBox.currentPathCanBeFilled())return;let n=this.isFillRule(t)?i=>{i.fill(t)}:i=>{i.fill()};this.viewBox.fillPath(n)}isPointInPath(t,e,n,i){return!0}isPointInStroke(t,e,n){return!0}stroke(t){this.viewBox.strokePath()}}class Ti{drawFocusIfNeeded(t,e){}scrollPathIntoView(t){}}var N=(s=>(s[s.None=0]="None",s[s.Relative=1]="Relative",s[s.Absolute=2]="Absolute",s))(N||{}),T=(s=>(s[s.Positive=0]="Positive",s[s.Negative=1]="Negative",s))(T||{});const Vt={direction:new h(0,1)},Mt={direction:new h(0,-1)},Nt={direction:new h(-1,0)},zt={direction:new h(1,0)};function Si(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 rt{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 rt(this.point,t,this.rightHalfPlane)}replaceRightHalfPlane(t){return new rt(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 w(t,e)}static create(t,e,n){return e.normalTowardInterior.cross(n.normalTowardInterior)>=0?new rt(t,e,n):new rt(t,n,e)}}class w{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 w.throughPointsAndContainingPoint(e,n,i)}complement(){return new w(this.base,this.normalTowardInterior.scale(-1))}expandByDistance(t){const e=this.base.plus(this.normalTowardInterior.scale(-t/this.normalTowardInterior.mod()));return new w(e,this.normalTowardInterior)}expandToIncludePoint(t){return this.containsPoint(t)?this:new w(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:Si(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 rt.create(e.point,this,t)}static throughPointsAndContainingPoint(t,e,n){const i=w.withBorderPoints(t,e);for(let r of i)if(r.containsPoint(n))return r}static withBorderPointAndInfinityInDirection(t,e){return w.withBorderPoints(t,t.plus(e))}static withBorderPoints(t,e){const n=e.minus(t).getPerpendicular();return[new w(t,n),new w(t,n.scale(-1))]}}class yi{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 ut=new yi;class xi{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 L=new xi;class p{constructor(t,e){a(this,"halfPlanes");this.vertices=e,this.halfPlanes=t,this.vertices=this.vertices||p.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 f=this.halfPlanes.map(d=>d.expandToIncludePoint(t));return new p(f)}const e=new Set,n=new Set;let i=null,r=null;const o=[],c=new Set;for(const f of this.vertices){const d=f.leftHalfPlane;n.has(d)?n.delete(d):e.add(d);const m=f.rightHalfPlane;if(e.has(m)?e.delete(m):n.add(m),d.containsPoint(t)){if(c.add(d),m.containsPoint(t)){c.add(m),o.push(f);continue}i=f;continue}m.containsPoint(t)&&(c.add(m),r=f)}if(o.length===this.vertices.length)return this;let u,l;if(i===null){const f=[...e][0];if(!f)return this;u=f.expandToIncludePoint(t)}else u=i.getContainingHalfPlaneThroughPoint(t),u!==i.leftHalfPlane&&o.push(i.replaceRightHalfPlane(u));if(r===null){const f=[...n][0];if(!f)return this;l=f.expandToIncludePoint(t)}else l=r.getContainingHalfPlaneThroughPoint(t),l!==r.rightHalfPlane&&o.push(r.replaceLeftHalfPlane(l));return c.add(u),c.add(l),o.push(new rt(t,u,l)),new p([...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=p.getHalfPlanesNotContainingAnyOther(e),e.length===0?ut:new p(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 p(this.halfPlanes.map(e=>e.expandByDistance(t)))}transform(t){return new p(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 L;const e=p.getHalfPlanesNotContainingAnyOther(this.halfPlanes.concat(t.halfPlanes)),r=p.groupVerticesByPoint(p.getVertices(e)).map(c=>p.getVerticesNotContainingAnyOther(c)).reduce((c,u)=>c.concat(u),[]);if(r.length===0)return new p(e);const o=p.getHalfPlanes(r);return new p(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=w.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 u=!0;for(let l=0;l<t.length;l++){if(l===n||l===i)continue;if(!t[l].containsPoint(c.point)){u=!1;break}}u&&e.push(c)}return e}static createTriangleWithInfinityInTwoDirections(t,e,n){const i=e.getPerpendicular(),r=n.getPerpendicular();return e.cross(n)<0?new p([new w(t,i.scale(-1)),new w(t,r)]):new p([new w(t,i),new w(t,r.scale(-1))])}static createFromHalfPlane(t){return new p([t])}static createTriangleWithInfinityInDirection(t,e,n){const i=e.minus(t).projectOn(n.getPerpendicular());return new p([new w(t,i),new w(e,i.scale(-1)),w.throughPointsAndContainingPoint(t,e,t.plus(n))])}static createTriangle(t,e,n){return new p([w.throughPointsAndContainingPoint(t,e,n),w.throughPointsAndContainingPoint(t,n,e),w.throughPointsAndContainingPoint(e,n,t)])}}function Y(...s){return(...t)=>{for(const e of s)e&&e(...t)}}function bi(s,t){return t?(e,n)=>{e.save(),t(e,n),s(e,n),e.restore()}:s}function Oi(s){return s===N.Relative?(t,e)=>{const{a:n,b:i,c:r,d:o,e:c,f:u}=e.getBitmapTransformationToTransformedInfiniteCanvasContext();t.transform(n,i,r,o,c,u)}:s===N.Absolute?(t,e)=>{const{a:n,b:i,c:r,d:o,e:c,f:u}=e.getBitmapTransformationToInfiniteCanvasContext();t.setTransform(n,i,r,o,c,u)}:null}function Li(s,t){let e=s.area;return e&&t.lineWidth>0&&(e=e.expandByDistance(t.lineWidth/2)),e}function Bi(s){return{lineWidth:s.current.getMaximumLineWidth(),lineDashPeriod:s.current.getLineDashPeriod(),shadowOffsets:s.current.getShadowOffsets()}}function Ai(s){return{lineWidth:0,lineDashPeriod:0,shadowOffsets:s.current.getShadowOffsets()}}class z{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 z.forPath(t,e,Bi,n)}static forFillingPath(t,e,n){return z.forPath(t,e,Ai,n)}static forPath(t,e,n,i){const r=e.current.isTransformable(),o=r?N.None:N.Relative,c=e.currentlyTransformed(r),u=n(c),l=i(c),f=Li(l,u);return new z(t,f,d=>l.drawPath(d,c,u),!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=Oi(this.transformationKind);if(this.tempState){const n=this.takeClippingRegionIntoAccount?this.state.getInstructionToConvertToStateWithClippedPath(this.tempState):this.state.getInstructionToConvertToState(this.tempState);t=Y(t,n)}return bi(this.instruction,t)}}class ge{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 me{constructor(t,e){a(this,"stateConversion");this.initialState=t,this.state=e,this.stateConversion=()=>{}}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 me{constructor(t,e,n,i){super(t,e),this.instruction=n,this.stateConversion=i}execute(t,e){this.stateConversion&&this.stateConversion(t,e),this.instruction(t,e)}static create(t,e){return new X(t,t,e,()=>{})}}class dt extends me{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 dt(t,t,e,()=>{})}}function I(s){return s.direction!==void 0}function J(s,t){return I(s)?t.applyToPointAtInfinity(s):t.apply(s)}class Di{constructor(t,e){this.areaBuilder=t,this.transformation=e}addPosition(t){this.areaBuilder.addPosition(J(t,this.transformation))}}class pe{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 w(this.base,e).expandByDistance(t),i=new w(this.base,e.scale(-1)).expandByDistance(t);return new p([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 qt extends pe{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 L;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 E(n,i):n?new q(n,this.direction):new q(i,this.direction.scale(-1))}intersectWithLine(t){return this.intersectsLine(t)?this:L}intersectWithLineSegment(t){return this.lineSegmentIsOnSameLine(t)?t:L}intersectWithRay(t){return this.intersectsRay(t)?t:L}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:p.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?p.createFromHalfPlane(new w(this.base,n.scale(-1))):p.createFromHalfPlane(new w(this.base,n))}transform(t){const e=t.apply(this.base);return new qt(e,t.apply(this.base.plus(this.direction)).minus(e))}interiorContainsPoint(t){return this.pointIsOnSameLine(t)}}class q extends pe{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 L;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 E(n,i):new q(n,this.direction)}intersectWithRay(t){return this.isContainedByRay(t)?this:t.isContainedByRay(this)?t:this.interiorContainsPoint(t.base)?new E(this.base,t.base):L}intersectWithLine(t){return t.intersectWithRay(this)}intersectWithLineSegment(t){if(t.isContainedByRay(this))return t;if(!this.lineSegmentIsOnSameLine(t))return L;let{point2:e}=this.getPointsInSameDirection(t.point1,t.point2);return this.comesBefore(e,this.base)?L:new E(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 q(t,this.direction):p.createTriangleWithInfinityInDirection(this.base,t,this.direction)}expandByDistance(t){const e=this.expandLineByDistance(t),n=new w(this.base,this.direction).expandByDistance(t);return e.intersectWithConvexPolygon(new p([n]))}expandToIncludeInfinityInDirection(t){return t.inSameDirectionAs(this.direction)?this:this.direction.cross(t)===0?new qt(this.base,this.direction):p.createTriangleWithInfinityInTwoDirections(this.base,this.direction,t)}transform(t){const e=t.apply(this.base);return new q(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 E extends pe{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 L;let{point1:e,point2:n}=this.getPointsInSameDirection(t.point1,t.point2);return this.comesBefore(n,this.point1)||this.comesBefore(this.point2,e)?L:this.comesBefore(this.point1,e)?new E(e,this.point2):new E(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 L;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 E(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 w(this.base,this.direction).expandByDistance(t),i=new w(this.point2,this.direction.scale(-1)).expandByDistance(t);return e.intersectWithConvexPolygon(new p([n,i]))}expandToIncludePoint(t){return this.containsPoint(t)?this:this.pointIsOnSameLine(t)?this.comesBefore(t,this.point1)?new E(t,this.point2):new E(this.point1,t):p.createTriangle(this.point1,t,this.point2)}expandToIncludeInfinityInDirection(t){return t.inSameDirectionAs(this.direction)?new q(this.point1,t):t.cross(this.direction)===0?new q(this.point2,t):p.createTriangleWithInfinityInDirection(this.point1,this.point2,t)}transform(t){return new E(t.apply(this.point1),t.apply(this.point2))}}class Ei{addPoint(t){return ut}addPointAtInfinity(t){return this}addArea(t){return ut}}const ve=new Ei;class we{constructor(t){this.towardsMiddle=t}addPoint(t){return p.createFromHalfPlane(new w(t,this.towardsMiddle))}addPointAtInfinity(t){return t.dot(this.towardsMiddle)>=0?this:ve}addArea(t){const e=this.towardsMiddle.getPerpendicular();return t.expandToIncludeInfinityInDirection(this.towardsMiddle).expandToIncludeInfinityInDirection(e).expandToIncludeInfinityInDirection(e.scale(-1))}}class Gt{constructor(t,e){this.direction1=t,this.direction2=e}addPoint(t){return p.createTriangleWithInfinityInTwoDirections(t,this.direction1,this.direction2)}addPointAtInfinity(t){return t.isInSmallerAngleBetweenPoints(this.direction1,this.direction2)?this:t.cross(this.direction1)===0?new we(this.direction2.projectOn(this.direction1.getPerpendicular())):t.cross(this.direction2)===0?new we(this.direction1.projectOn(this.direction2.getPerpendicular())):this.direction1.isInSmallerAngleBetweenPoints(t,this.direction2)?new Gt(t,this.direction2):this.direction2.isInSmallerAngleBetweenPoints(t,this.direction1)?new Gt(t,this.direction1):ve}addArea(t){return t.expandToIncludeInfinityInDirection(this.direction1).expandToIncludeInfinityInDirection(this.direction2)}}class Ri{constructor(t){this.direction=t}addPoint(t){return new qt(t,this.direction)}addPointAtInfinity(t){return t.cross(this.direction)===0?this:new we(t.projectOn(this.direction.getPerpendicular()))}addArea(t){return t.expandToIncludeInfinityInDirection(this.direction).expandToIncludeInfinityInDirection(this.direction.scale(-1))}}class Fi{constructor(t){this.direction=t}addPointAtInfinity(t){return t.inSameDirectionAs(this.direction)?this:t.cross(this.direction)===0?new Ri(this.direction):new Gt(this.direction,t)}addPoint(t){return new q(t,this.direction)}addArea(t){return t.expandToIncludeInfinityInDirection(this.direction)}}class Wi{constructor(t,e,n){this._area=t,this.firstPoint=e,this.subsetOfLineAtInfinity=n}get area(){return this._area||L}addPoint(t){this._area?this._area=this._area.expandToIncludePoint(t):this.firstPoint?t.equals(this.firstPoint)||(this._area=new E(this.firstPoint,t)):this.subsetOfLineAtInfinity?this._area=this.subsetOfLineAtInfinity.addPoint(t):this.firstPoint=t}addPosition(t){I(t)?this.addInfinityInDirection(t.direction):this.addPoint(t)}addInfinityInDirection(t){this._area?this._area=this._area.expandToIncludeInfinityInDirection(t):this.firstPoint?this._area=new q(this.firstPoint,t):this.subsetOfLineAtInfinity?(this.subsetOfLineAtInfinity=this.subsetOfLineAtInfinity.addPointAtInfinity(t),this.subsetOfLineAtInfinity===ve&&(this._area=ut)):this.subsetOfLineAtInfinity=new Fi(t)}transformedWith(t){return new Di(this,t)}}class Yt extends me{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=(r,o)=>n(r,o,e);return new X(this.initialState,this.state,i,this.stateConversion)}static create(t,e){return new Yt(t,t,e,()=>{})}}function ki(s,t){return s?t?I(s)?I(t)&&s.direction.equals(t.direction):!I(t)&&s.equals(t):!s:!t}class Ct{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(n,i,r)=>{r.moveToInfinityFromPointInDirection(n,i,t,e)}}lineFromInfinityFromPointToInfinityFromPoint(t,e,n){return(i,r,o)=>{o.drawLineFromInfinityFromPointToInfinityFromPoint(i,r,t,e,n)}}lineFromInfinityFromPointToPoint(t,e){return(n,i,r)=>{r.drawLineFromInfinityFromPointToPoint(n,i,t,e)}}lineToInfinityFromPointInDirection(t,e){return(n,i,r)=>{r.drawLineToInfinityFromPointInDirection(n,i,t,e)}}lineToInfinityFromInfinityFromPoint(t,e,n){return(i,r,o)=>{o.drawLineToInfinityFromInfinityFromPoint(i,r,t,e,n)}}lineTo(t){return(e,n)=>{const{x:i,y:r}=n.userTransformation.apply(t);e.lineTo(i,r)}}moveTo(t){return(e,n)=>{const{x:i,y:r}=n.userTransformation.apply(t);e.moveTo(i,r)}}}class Xt{constructor(t,e,n,i){this.initialPosition=t,this.firstFinitePoint=e,this.lastFinitePoint=n,this.currentPosition=i}transform(t){return new Xt(t.applyToPointAtInfinity(this.initialPosition),t.apply(this.firstFinitePoint),t.apply(this.lastFinitePoint),t.applyToPointAtInfinity(this.currentPosition))}}class It{constructor(t,e,n){this.initialPosition=t,this.firstFinitePoint=e,this.currentPosition=n}transform(t){return new It(t.applyToPointAtInfinity(this.initialPosition),t.apply(this.firstFinitePoint),t.apply(this.currentPosition))}}class Hi extends Ct{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):Y(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 I(e)?this.lineToInfinityFromInfinityFromPoint(t.lastFinitePoint,t.currentPosition.direction,e.direction):Y(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!I(t)||!t.direction.isInOppositeDirectionAs(this.shape.currentPosition.direction)}addPosition(t){return I(t)?this.pathBuilderProvider.fromPointAtInfinityToPointAtInfinity(new Xt(this.shape.initialPosition,this.shape.firstFinitePoint,this.shape.lastFinitePoint,t)):this.pathBuilderProvider.fromPointAtInfinityToPoint(new It(this.shape.initialPosition,this.shape.firstFinitePoint,t))}}class Vi extends Ct{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 Y(e,n)}getInstructionToExtendShapeWithLineTo(t,e){return I(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 I(t)?this.pathBuilderProvider.fromPointAtInfinityToPointAtInfinity(new Xt(this.shape.initialPosition,this.shape.firstFinitePoint,this.shape.currentPosition,t)):this.pathBuilderProvider.fromPointAtInfinityToPoint(new It(this.shape.initialPosition,this.shape.firstFinitePoint,t))}}class Ut{constructor(t,e){this.initialPoint=t,this.currentPosition=e}transform(t){return new Ut(t.apply(this.initialPoint),t.applyToPointAtInfinity(this.currentPosition))}}class Tt{constructor(t,e){this.initialPoint=t,this.currentPosition=e}transform(t){return new Tt(t.apply(this.initialPoint),t.apply(this.currentPosition))}}class Mi extends Ct{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){return this.moveTo(t.initialPoint)}getInstructionToExtendShapeWithLineTo(t,e){return I(e)?e.direction.inSameDirectionAs(t.currentPosition.direction)?()=>{}:this.lineToInfinityFromInfinityFromPoint(t.initialPoint,t.currentPosition.direction,e.direction):Y(this.lineFromInfinityFromPointToInfinityFromPoint(t.initialPoint,e,t.currentPosition.direction),this.lineFromInfinityFromPointToPoint(e,t.currentPosition.direction))}canAddLineTo(t){return!I(t)||!t.direction.isInOppositeDirectionAs(this.shape.currentPosition.direction)}containsFinitePoint(){return!0}surroundsFinitePoint(){return!0}isClosable(){return!0}addPosition(t){return I(t)?this.pathBuilderProvider.fromPointToPointAtInfinity(new Ut(this.shape.initialPoint,t)):this.pathBuilderProvider.fromPointToPoint(new Tt(this.shape.initialPoint,t))}}class pn extends Ct{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){return this.moveTo(t.initialPoint)}getInstructionToExtendShapeWithLineTo(t,e){if(I(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 Y(n,i)}return this.lineTo(e)}canAddLineTo(t){return!0}containsFinitePoint(){return!0}surroundsFinitePoint(){return!0}isClosable(){return!0}addPosition(t){return I(t)?this.pathBuilderProvider.fromPointToPointAtInfinity(new Ut(this.shape.initialPoint,t)):this.pathBuilderProvider.fromPointToPoint(new Tt(this.shape.initialPoint,t))}}class vn extends Ct{constructor(t,e){super(e),this.pathBuilderProvider=t}getInstructionToMoveToBeginningOfShape(t){return t.surroundsFinitePoint?(e,n,i)=>i.addPathAroundViewbox(e,n,t.direction==="counterclockwise"):()=>{}}getInstructionToExtendShapeWithLineTo(t,e){if(I(e))return;if(t.positionsSoFar.length===1)return this.lineFromInfinityFromPointToPoint(e,t.positionsSoFar[0].direction);const n=t.positionsSoFar.slice(1);let i=t.initialPosition;const r=[];for(let o of n)r.push(this.lineToInfinityFromInfinityFromPoint(e,i.direction,o.direction)),i=o;return Y(Y(...r),this.lineFromInfinityFromPointToPoint(e,i.direction))}canAddLineTo(t){return!I(t)||!t.direction.isInOppositeDirectionAs(this.shape.currentPosition.direction)}containsFinitePoint(){return!1}surroundsFinitePoint(){return this.shape.surroundsFinitePoint}isClosable(){return!0}addPosition(t){return I(t)?this.pathBuilderProvider.atInfinity(this.shape.addPosition(t)):this.pathBuilderProvider.fromPointAtInfinityToPoint(new It(this.shape.initialPosition,t,t))}}class St{constructor(t,e,n,i){a(this,"direction");this.initialPosition=t,this.surroundsFinitePoint=e,this.positionsSoFar=n,this.currentPosition=i;const r=t.direction.cross(i.direction);this.direction=e?r>=0?"counterclockwise":"clockwise":r>=0?"clockwise":"counterclockwise"}transform(t){return new St(t.applyToPointAtInfinity(this.initialPosition),this.surroundsFinitePoint,this.positionsSoFar.map(e=>t.applyToPointAtInfinity(e)),t.applyToPointAtInfinity(this.currentPosition))}addPosition(t){const n=t.direction.isOnSameSideOfOriginAs(this.initialPosition.direction,this.currentPosition.direction)?this.surroundsFinitePoint:!this.surroundsFinitePoint;return new St(this.initialPosition,n,this.positionsSoFar.concat([t]),t)}static create(t){return new St(t,!1,[t],t)}}class Ni{fromPointAtInfinityToPointAtInfinity(t){return new Hi(this,t)}fromPointAtInfinityToPoint(t){return new Vi(this,t)}fromPointToPointAtInfinity(t){return new Mi(this,t)}fromPointToPoint(t){return new pn(this,t)}atInfinity(t){return new vn(this,t)}getBuilderFromPosition(t){return I(t)?new vn(this,St.create(t)):new pn(this,