@mylasertools/kerfscript 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,15 +1,15 @@
1
1
  /*! @mylasertools/kerfscript | (c) MyLaserTools | AGPL-3.0-only or commercial licence, see COMMERCIAL-LICENSE.md. Includes Clipper2 (BSL-1.0), opentype.js, tiny-inflate and string.prototype.codepointat (MIT), see THIRD-PARTY-NOTICES.md. */
2
- "use strict";var k5=Object.defineProperty;var Ca=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Ea=Object.prototype.hasOwnProperty;var Ta=(t,e,n)=>e in t?k5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Ia=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Va=(t,e)=>{for(var n in e)k5(t,n,{get:e[n],enumerable:!0})},$a=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Pa(e))!Ea.call(t,a)&&a!==n&&k5(t,a,{get:()=>e[a],enumerable:!(r=Ca(e,a))||r.enumerable});return t};var Ha=t=>$a(k5({},"__esModule",{value:!0}),t);var X=(t,e,n)=>Ta(t,typeof e!="symbol"?e+"":e,n);var l7=Ia((Md,i7)=>{i7.exports={}});var du={};Va(du,{DEFAULT_LAYERS:()=>u5,DEFAULT_LIMITS:()=>Q4,HARDWARE_COLORS:()=>le,HARDWARE_KINDS:()=>X2,KerfError:()=>i1,LANGUAGE_VERSION:()=>fu,LIGHT_COLORS:()=>a3,PAINT_COLORS:()=>d4,SIGNATURES:()=>b4,VERSION:()=>uu,bendPoint:()=>Ae,diffRenders:()=>ir,effectsText:()=>Aa,foldPanels:()=>Ce,format:()=>pt,formatError:()=>ar,formatSignature:()=>W5,importSvg:()=>Tr,instructionsHtml:()=>fr,lightPoints:()=>j5,materialColor:()=>jn,meshBodies:()=>Rt,meshPieces:()=>Pe,panelMarks:()=>T6,parameters:()=>v3,parse:()=>n2,placementMatrix:()=>R0,poseAssembly:()=>Rn,render:()=>mt,settingEffects:()=>Sa,shown:()=>dt,signature:()=>c3,snapshotFromRender:()=>On,to3mf:()=>Kn,toGlb:()=>Jn,toModel:()=>ka,toStl:()=>Yn,tokenize:()=>r3,triage:()=>Fn,triageText:()=>fa,triangulate:()=>Ot,verificationIsCurrent:()=>ha,verify:()=>ua});module.exports=Ha(du);var f0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(f0||(f0={}));var W0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(W0||(W0={}));var J1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(J1||(J1={}));var e0;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(e0||(e0={}));var je=Number.MAX_SAFE_INTEGER,P0=Math.floor(Math.sqrt(je));function z5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=je/Math.abs(e)}function e6(t,e){return Math.abs(t)+Math.abs(e)<=je}function _t(t,e,n,r){if(z5(t,e)&&z5(n,r)){let a=t*e,s=n*r;if(e6(a,s))return a-s}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(r)):t*e-n*r}function qt(t,e,n,r){if(z5(t,e)&&z5(n,r)){let a=t*e,s=n*r;if(e6(a,s))return a+s}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(r)):t*e+n*r}var Dt=BigInt(0),S5=BigInt(2),Oa=BigInt(4),Ra=BigInt(64),Fa=BigInt("0xFFFFFFFFFFFFFFFF"),Bt=BigInt("9223372036854775807"),T3=Number(Bt/Oa),t6=Number(Bt),n6=1e-12,_a=.1,Nt=Math.floor(P0/2),qa=Math.floor(Math.sqrt(Math.sqrt(je/4)));function Da(t){if(!Number.isFinite(t))throw new RangeError("Scale must be a finite number");let e=Math.abs(t);return e===0?Number.POSITIVE_INFINITY:je/e}function Na(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function Ua(t,e){if(!Number.isFinite(t)||Math.abs(t)>je)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function Ba(t,e,n){let r=e.x-t.x,a=n.y-e.y,s=e.y-t.y,c=n.x-e.x;return Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0?r*a-s*c:_t(r,a,s,c)}function m2(t,e,n){let r=e.x-t.x,a=n.y-e.y,s=e.y-t.y,c=n.x-e.x;if(Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0){let l=r*a,h=s*c;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(c)){let l=r*a,h=s*c;return l>h?1:l<h?-1:0}let o=BigInt(r)*BigInt(a),i=BigInt(s)*BigInt(c);return o===i?0:o>i?1:-1}function ja(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function Ga(t){return Math.abs(t)<=n6}function Wa(t){return t<0?-1:t>0?1:0}function Xa(t,e){let n=BigInt(t),r=BigInt(e),a=n*r;return{lo64:a&Fa,hi64:a>>Ra}}function r6(t,e,n,r){let a=Math.abs(t),s=Math.abs(e),c=Math.abs(n),o=Math.abs(r);if(a<P0&&s<P0&&c<P0&&o<P0)return t*e===n*r;let i=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(r<0?-1:r>0?1:0);if(i!==l)return!1;if(i===0)return!0;if(!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(c)||!Number.isSafeInteger(o))return t*e===n*r;let h=BigInt(a),u=BigInt(s),f=BigInt(c),d=BigInt(o);return h*u===f*d}function Za(t,e,n){let r=e.x-t.x,a=n.y-e.y,s=e.y-t.y,c=n.x-e.x;return r6(r,a,s,c)}function Ya(t,e,n){let r=e.x-t.x,a=n.x-e.x,s=e.y-t.y,c=n.y-e.y;return Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0?r*a+s*c:qt(r,a,s,c)}function Ka(t,e,n){let r=e.x-t.x,a=n.x-e.x,s=e.y-t.y,c=n.y-e.y;if(Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0){let i=r*a+s*c;return i>0?1:i<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(c)){let i=r*a+s*c;return i>0?1:i<0?-1:0}let o=BigInt(r)*BigInt(a)+BigInt(s)*BigInt(c);return o===Dt?0:o>Dt?1:-1}function Ja(t){let e=t.length;if(e<3)return 0;let n=!0;for(let s=0;s<e&&n;s++){let c=t[s];(Math.abs(c.x)>=Nt||Math.abs(c.y)>=Nt)&&(n=!1)}let r=t[e-1];if(n){let s=0;for(let c of t)s+=(r.y+c.y)*(r.x-c.x),r=c;return s*.5}let a=Dt;for(let s of t){let c=r.y+s.y,o=r.x-s.x;if(Number.isSafeInteger(c)&&Number.isSafeInteger(o))a+=BigInt(c)*BigInt(o);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(s.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(s.x)){let i=BigInt(r.y)+BigInt(s.y),l=BigInt(r.x)-BigInt(s.x);a+=i*l}else a+=BigInt(Math.round(c*o));r=s}return Number(a)*.5}function Qa(t,e){return t.y*e.x-e.y*t.x}function es(t,e){return t.x*e.x+t.y*e.y}function ts(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function ns(t){return t>=T3||t<=-T3?t6:Math.round(t)}function rs(t,e,n,r){let a=e.y-t.y,s=e.x-t.x,c=r.y-n.y,o=r.x-n.x,i=_t(a,o,c,s);if(i===0)return null;let l=_t(t.x-n.x,c,t.y-n.y,o)/i;return l<=0?{x:t.x,y:t.y,z:t.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(t.x+l*s),y:Math.trunc(t.y+l*a),z:0}}function as(t,e,n,r){let a=e.y-t.y,s=e.x-t.x,c=r.y-n.y,o=r.x-n.x,i=a*o-c*s;if(i===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*c-(t.y-n.y)*o)/i,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*s,y:t.y+l*a,z:0},{success:!0,ip:h}}function ss(t,e,n,r,a=!1){if(!a){let l=m2(t,n,r),h=m2(e,n,r),u=m2(n,t,e),f=m2(r,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let s=m2(t,n,r),c=m2(e,n,r);if(s!==0&&s===c)return!1;let o=m2(n,t,e),i=m2(r,t,e);return o!==0&&o===i?!1:s!==0||c!==0||o!==0||i!==0}function a6(t){if(t.length===0)return{left:0,top:0,right:0,bottom:0};let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of t)n.x<e.left&&(e.left=n.x),n.x>e.right&&(e.right=n.x),n.y<e.top&&(e.top=n.y),n.y>e.bottom&&(e.bottom=n.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function cs(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let r=n.x-e.x,a=n.y-e.y,s=qt(t.x-e.x,r,t.y-e.y,a)/qt(r,r,a,a),c=s<0?0:s>1?1:s;return{x:Math.round(e.x+c*r),y:Math.round(e.y+c*a),z:0}}function Ut(t,e){let n=e.length,r=0;if(n<3)return e0.IsOutside;for(;r<n&&e[r].y===t.y;)r++;if(r===n)return e0.IsOutside;let a=e[r].y<t.y,s=a,c=0,o=r+1,i=n;for(;;){if(o===i){if(i===0||r===0)break;i=r,o=0}if(a)for(;o<i&&e[o].y<t.y;)o++;else for(;o<i&&e[o].y>t.y;)o++;if(o===i)continue;let h=e[o],u=o>0?e[o-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return e0.IsOn;if(o++,o===r)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)c=1-c;else{let f=m2(u,h,t);if(f===0)return e0.IsOn;f<0===a&&(c=1-c)}a=!a,o++}if(a===s)return c===0?e0.IsOutside:e0.IsInside;o===n&&(o=0);let l=o===0?m2(e[n-1],e[0],t):m2(e[o-1],e[o],t);return l===0?e0.IsOn:(l<0===a&&(c=1-c),c===0?e0.IsOutside:e0.IsInside)}function os(t,e){let n=e0.IsOn;for(let o of t)switch(Ut(o,e)){case e0.IsOutside:if(n===e0.IsOutside)return!1;n=e0.IsOutside;break;case e0.IsInside:if(n===e0.IsInside)return!0;n=e0.IsInside;break;default:break}let r=a6(t),a,s;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>Number.MAX_SAFE_INTEGER?(a=Number((BigInt(r.left)+BigInt(r.right))/S5),s=Number((BigInt(r.top)+BigInt(r.bottom))/S5)):(a=Math.round((r.left+r.right)/2),s=Math.round((r.top+r.bottom)/2)),Ut({x:a,y:s},e)!==e0.IsOutside}var j1={MaxInt64:Bt,MaxCoord:T3,max_coord:T3,min_coord:-T3,Invalid64:t6,floatingPointTolerance:n6,defaultMinimumEdgeLength:_a,maxCoordForSafeAreaProduct:Nt,maxCoordForSafeCrossSq:qa,maxSafeCoordinateForScale:Da,checkSafeScaleValue:Na,ensureSafeInteger:Ua,crossProduct:Ba,crossProductSign:m2,checkPrecision:ja,isAlmostZero:Ga,triSign:Wa,multiplyUInt64:Xa,productsAreEqual:r6,isCollinear:Za,dotProduct:Ya,dotProductSign:Ka,area:Ja,crossProductD:Qa,dotProductD:es,roundToEven:ts,checkCastInt64:ns,getLineIntersectPt:rs,getLineIntersectPtD:as,segsIntersect:ss,getBounds:a6,getClosestPtOnSegment:cs,pointInPolygon:Ut,path2ContainsPath1:os},V2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return j1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),j1.ensureSafeInteger(t.y,"Point64Utils.fromPointD"),{x:Math.round(t.x),y:Math.round(t.y),z:t.z||0}},scale(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e),z:t.z||0}},equals(t,e){return t.x===e.x&&t.y===e.y},add(t,e){if(Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(e.y)){let n=t.x+e.x,r=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?{x:n,y:r,z:0}:{x:Number(BigInt(t.x)+BigInt(e.x)),y:Number(BigInt(t.y)+BigInt(e.y)),z:0}}return{x:t.x+e.x,y:t.y+e.y,z:0}},subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:0}},toString(t){return t.z!==void 0&&t.z!==0?`${t.x},${t.y},${t.z} `:`${t.x},${t.y} `}},A5={create(t=0,e=0,n=0){return{x:t,y:e,z:n}},fromPoint64(t){return{x:t.x,y:t.y,z:t.z||0}},scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z||0}},equals(t,e){return j1.isAlmostZero(t.x-e.x)&&j1.isAlmostZero(t.y-e.y)},negate(t){t.x=-t.x,t.y=-t.y},toString(t,e=2){return t.z!==void 0&&t.z!==0?`${t.x.toFixed(e)},${t.y.toFixed(e)},${t.z}`:`${t.x.toFixed(e)},${t.y.toFixed(e)}`}},we={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},isValid(t){return t.left<Number.MAX_SAFE_INTEGER},midPoint(t){if(Number.isSafeInteger(t.left)&&Number.isSafeInteger(t.right)&&Math.abs(t.left)+Math.abs(t.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(t.left)+BigInt(t.right))/S5),n=Number((BigInt(t.top)+BigInt(t.bottom))/S5);return{x:e,y:n}}return{x:Math.round((t.left+t.right)/2),y:Math.round((t.top+t.bottom)/2)}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<=Math.min(t.right,e.right)&&Math.max(t.top,e.top)<=Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}},jt={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},midPoint(t){return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<Math.min(t.right,e.right)&&Math.max(t.top,e.top)<Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}};var s6=Object.freeze(we.createInvalid()),c6=Object.freeze(jt.createInvalid());var I3=BigInt(0),is=BigInt(2),o6=BigInt(4),r0;(function(t){t[t.None=0]="None",t[t.OpenStart=1]="OpenStart",t[t.OpenEnd=2]="OpenEnd",t[t.LocalMax=4]="LocalMax",t[t.LocalMin=8]="LocalMin"})(r0||(r0={}));var Gt=class{constructor(){X(this,"data",[])}push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],n=this.data.pop();return this.data.length>0&&(this.data[0]=n,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let n=this.data[e];for(;e>0;){let r=e-1>>1;if(this.data[r]>=n)break;this.data[e]=this.data[r],e=r}this.data[e]=n}siftDown(e){let n=this.data.length,r=this.data[e];for(;;){let a=(e<<1)+1;if(a>=n)break;let s=a+1,c=a;if(s<n&&this.data[s]>this.data[a]&&(c=s),this.data[c]<=r)break;this.data[e]=this.data[c],e=c}this.data[e]=r}},V3=class{constructor(e,n,r){X(this,"pt");X(this,"next",null);X(this,"prev",null);X(this,"flags");this.pt=e,this.flags=n,this.prev=r}},$3=class{constructor(e,n,r=!1){X(this,"vertex");X(this,"polytype");X(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=r}equals(e){return e!==null&&this.vertex===e.vertex}};function i6(t,e,n){return{pt:t,edge1:e,edge2:n}}var j2=class{constructor(e,n){X(this,"pt");X(this,"next");X(this,"prev");X(this,"outrec");X(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},K0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(K0||(K0={}));var Wt;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(Wt||(Wt={}));var L5=class{constructor(){X(this,"idx",0);X(this,"owner",null);X(this,"frontEdge",null);X(this,"backEdge",null);X(this,"pts",null);X(this,"polypath",null);X(this,"bounds",{left:0,top:0,right:0,bottom:0});X(this,"path",[]);X(this,"isOpen",!1);X(this,"splits",null);X(this,"recursiveSplit",null)}},C5=class{constructor(e){X(this,"leftOp");X(this,"rightOp");X(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},H3=class{constructor(e,n){X(this,"op1");X(this,"op2");this.op1=e,this.op2=n}};function ls(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function hs(t,e){return t.pt.y!==e.pt.y?t.pt.y>e.pt.y?-1:1:t.pt.x!==e.pt.x?t.pt.x<e.pt.x?-1:1:t.edge1.curX!==e.edge1.curX?t.edge1.curX<e.edge1.curX?-1:1:t.edge2.curX<e.edge2.curX?-1:t.edge2.curX>e.edge2.curX?1:0}var O3=class{constructor(){X(this,"bot",{x:0,y:0});X(this,"top",{x:0,y:0});X(this,"curX",0);X(this,"dx",0);X(this,"windDx",0);X(this,"windCount",0);X(this,"windCount2",0);X(this,"outrec",null);X(this,"prevInAEL",null);X(this,"nextInAEL",null);X(this,"prevInSEL",null);X(this,"nextInSEL",null);X(this,"jump",null);X(this,"vertexTop",null);X(this,"localMin",null);X(this,"isLeftBound",!1);X(this,"joinWith",K0.None)}},Ge={addLocMin(t,e,n,r){if((t.flags&r0.LocalMin)!==r0.None)return;t.flags|=r0.LocalMin;let a=new $3(t,e,n);r.push(a)},addPathsToVertexList(t,e,n,r,a){for(let s=0,c=t.length;s<c;s++){let o=t[s],i=null,l=null,h=null;for(let m=0,p=o.length;m<p;m++){let g=o[m];if(i===null)i=new V3(g,r0.None,null),a.push(i),l=i,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new V3(g,r0.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!n&&l.pt.x===i.pt.x&&l.pt.y===i.pt.y&&(l=l.prev),l.next=i,i.prev=l,!n&&l.next===l))continue;let u;if(n){let m=i.next;for(;m!==i&&m.pt.y===i.pt.y;)m=m.next;u=m.pt.y<=i.pt.y,u?(i.flags=r0.OpenStart,Ge.addLocMin(i,e,!0,r)):i.flags=r0.OpenStart|r0.LocalMax}else{for(l=i.prev;l!==i&&l.pt.y===i.pt.y;)l=l.prev;if(l===i)continue;u=l.pt.y>i.pt.y}let f=u;l=i;let d=i.next;for(;d!==i;)d.pt.y>l.pt.y&&u?(l.flags|=r0.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,Ge.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=r0.OpenEnd,u?l.flags|=r0.LocalMax:Ge.addLocMin(l,e,n,r)):u!==f&&(f?Ge.addLocMin(l,e,!1,r):l.flags|=r0.LocalMax)}}};var P5=class{constructor(e=null){X(this,"parent");X(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,n=this.parent;for(;n!==null;)++e,n=n.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)===0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,n){let r="",a=" ".repeat(n),s=this.children.length===1?"":"s";(n&1)===0?r+=`${a}+- hole (${e}) contains ${this.children.length} nested polygon${s}.
2
+ "use strict";var z5=Object.defineProperty;var Ca=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Ea=Object.prototype.hasOwnProperty;var Ta=(t,e,n)=>e in t?z5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Ia=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Va=(t,e)=>{for(var n in e)z5(t,n,{get:e[n],enumerable:!0})},$a=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Pa(e))!Ea.call(t,a)&&a!==n&&z5(t,a,{get:()=>e[a],enumerable:!(r=Ca(e,a))||r.enumerable});return t};var Ha=t=>$a(z5({},"__esModule",{value:!0}),t);var X=(t,e,n)=>Ta(t,typeof e!="symbol"?e+"":e,n);var l7=Ia((Md,i7)=>{i7.exports={}});var du={};Va(du,{DEFAULT_LAYERS:()=>f5,DEFAULT_LIMITS:()=>en,HARDWARE_COLORS:()=>le,HARDWARE_KINDS:()=>X2,KerfError:()=>i1,LANGUAGE_VERSION:()=>fu,LIGHT_COLORS:()=>a3,PAINT_COLORS:()=>m4,SIGNATURES:()=>y4,VERSION:()=>uu,bendPoint:()=>Ae,diffRenders:()=>ir,effectsText:()=>Aa,foldPanels:()=>Ce,format:()=>gt,formatError:()=>ar,formatSignature:()=>X5,importSvg:()=>Tr,instructionsHtml:()=>fr,lightPoints:()=>G5,materialColor:()=>Gn,meshBodies:()=>Ft,meshPieces:()=>Pe,panelMarks:()=>T6,parameters:()=>v3,parse:()=>n2,placementMatrix:()=>R0,poseAssembly:()=>Fn,render:()=>pt,settingEffects:()=>Sa,shown:()=>mt,signature:()=>c3,snapshotFromRender:()=>Rn,to3mf:()=>Kn,toGlb:()=>Jn,toModel:()=>ka,toStl:()=>Yn,tokenize:()=>r3,triage:()=>_n,triageText:()=>fa,triangulate:()=>Rt,verificationIsCurrent:()=>ha,verify:()=>ua});module.exports=Ha(du);var f0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(f0||(f0={}));var W0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(W0||(W0={}));var J1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(J1||(J1={}));var e0;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(e0||(e0={}));var je=Number.MAX_SAFE_INTEGER,P0=Math.floor(Math.sqrt(je));function S5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=je/Math.abs(e)}function e6(t,e){return Math.abs(t)+Math.abs(e)<=je}function qt(t,e,n,r){if(S5(t,e)&&S5(n,r)){let a=t*e,s=n*r;if(e6(a,s))return a-s}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(r)):t*e-n*r}function Dt(t,e,n,r){if(S5(t,e)&&S5(n,r)){let a=t*e,s=n*r;if(e6(a,s))return a+s}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(r)):t*e+n*r}var Nt=BigInt(0),A5=BigInt(2),Oa=BigInt(4),Ra=BigInt(64),Fa=BigInt("0xFFFFFFFFFFFFFFFF"),jt=BigInt("9223372036854775807"),I3=Number(jt/Oa),t6=Number(jt),n6=1e-12,_a=.1,Ut=Math.floor(P0/2),qa=Math.floor(Math.sqrt(Math.sqrt(je/4)));function Da(t){if(!Number.isFinite(t))throw new RangeError("Scale must be a finite number");let e=Math.abs(t);return e===0?Number.POSITIVE_INFINITY:je/e}function Na(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function Ua(t,e){if(!Number.isFinite(t)||Math.abs(t)>je)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function Ba(t,e,n){let r=e.x-t.x,a=n.y-e.y,s=e.y-t.y,c=n.x-e.x;return Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0?r*a-s*c:qt(r,a,s,c)}function m2(t,e,n){let r=e.x-t.x,a=n.y-e.y,s=e.y-t.y,c=n.x-e.x;if(Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0){let l=r*a,h=s*c;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(c)){let l=r*a,h=s*c;return l>h?1:l<h?-1:0}let o=BigInt(r)*BigInt(a),i=BigInt(s)*BigInt(c);return o===i?0:o>i?1:-1}function ja(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function Ga(t){return Math.abs(t)<=n6}function Wa(t){return t<0?-1:t>0?1:0}function Xa(t,e){let n=BigInt(t),r=BigInt(e),a=n*r;return{lo64:a&Fa,hi64:a>>Ra}}function r6(t,e,n,r){let a=Math.abs(t),s=Math.abs(e),c=Math.abs(n),o=Math.abs(r);if(a<P0&&s<P0&&c<P0&&o<P0)return t*e===n*r;let i=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(r<0?-1:r>0?1:0);if(i!==l)return!1;if(i===0)return!0;if(!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(c)||!Number.isSafeInteger(o))return t*e===n*r;let h=BigInt(a),u=BigInt(s),f=BigInt(c),d=BigInt(o);return h*u===f*d}function Za(t,e,n){let r=e.x-t.x,a=n.y-e.y,s=e.y-t.y,c=n.x-e.x;return r6(r,a,s,c)}function Ya(t,e,n){let r=e.x-t.x,a=n.x-e.x,s=e.y-t.y,c=n.y-e.y;return Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0?r*a+s*c:Dt(r,a,s,c)}function Ka(t,e,n){let r=e.x-t.x,a=n.x-e.x,s=e.y-t.y,c=n.y-e.y;if(Math.abs(r)<P0&&Math.abs(a)<P0&&Math.abs(s)<P0&&Math.abs(c)<P0){let i=r*a+s*c;return i>0?1:i<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(c)){let i=r*a+s*c;return i>0?1:i<0?-1:0}let o=BigInt(r)*BigInt(a)+BigInt(s)*BigInt(c);return o===Nt?0:o>Nt?1:-1}function Ja(t){let e=t.length;if(e<3)return 0;let n=!0;for(let s=0;s<e&&n;s++){let c=t[s];(Math.abs(c.x)>=Ut||Math.abs(c.y)>=Ut)&&(n=!1)}let r=t[e-1];if(n){let s=0;for(let c of t)s+=(r.y+c.y)*(r.x-c.x),r=c;return s*.5}let a=Nt;for(let s of t){let c=r.y+s.y,o=r.x-s.x;if(Number.isSafeInteger(c)&&Number.isSafeInteger(o))a+=BigInt(c)*BigInt(o);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(s.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(s.x)){let i=BigInt(r.y)+BigInt(s.y),l=BigInt(r.x)-BigInt(s.x);a+=i*l}else a+=BigInt(Math.round(c*o));r=s}return Number(a)*.5}function Qa(t,e){return t.y*e.x-e.y*t.x}function es(t,e){return t.x*e.x+t.y*e.y}function ts(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function ns(t){return t>=I3||t<=-I3?t6:Math.round(t)}function rs(t,e,n,r){let a=e.y-t.y,s=e.x-t.x,c=r.y-n.y,o=r.x-n.x,i=qt(a,o,c,s);if(i===0)return null;let l=qt(t.x-n.x,c,t.y-n.y,o)/i;return l<=0?{x:t.x,y:t.y,z:t.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(t.x+l*s),y:Math.trunc(t.y+l*a),z:0}}function as(t,e,n,r){let a=e.y-t.y,s=e.x-t.x,c=r.y-n.y,o=r.x-n.x,i=a*o-c*s;if(i===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*c-(t.y-n.y)*o)/i,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*s,y:t.y+l*a,z:0},{success:!0,ip:h}}function ss(t,e,n,r,a=!1){if(!a){let l=m2(t,n,r),h=m2(e,n,r),u=m2(n,t,e),f=m2(r,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let s=m2(t,n,r),c=m2(e,n,r);if(s!==0&&s===c)return!1;let o=m2(n,t,e),i=m2(r,t,e);return o!==0&&o===i?!1:s!==0||c!==0||o!==0||i!==0}function a6(t){if(t.length===0)return{left:0,top:0,right:0,bottom:0};let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of t)n.x<e.left&&(e.left=n.x),n.x>e.right&&(e.right=n.x),n.y<e.top&&(e.top=n.y),n.y>e.bottom&&(e.bottom=n.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function cs(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let r=n.x-e.x,a=n.y-e.y,s=Dt(t.x-e.x,r,t.y-e.y,a)/Dt(r,r,a,a),c=s<0?0:s>1?1:s;return{x:Math.round(e.x+c*r),y:Math.round(e.y+c*a),z:0}}function Bt(t,e){let n=e.length,r=0;if(n<3)return e0.IsOutside;for(;r<n&&e[r].y===t.y;)r++;if(r===n)return e0.IsOutside;let a=e[r].y<t.y,s=a,c=0,o=r+1,i=n;for(;;){if(o===i){if(i===0||r===0)break;i=r,o=0}if(a)for(;o<i&&e[o].y<t.y;)o++;else for(;o<i&&e[o].y>t.y;)o++;if(o===i)continue;let h=e[o],u=o>0?e[o-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return e0.IsOn;if(o++,o===r)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)c=1-c;else{let f=m2(u,h,t);if(f===0)return e0.IsOn;f<0===a&&(c=1-c)}a=!a,o++}if(a===s)return c===0?e0.IsOutside:e0.IsInside;o===n&&(o=0);let l=o===0?m2(e[n-1],e[0],t):m2(e[o-1],e[o],t);return l===0?e0.IsOn:(l<0===a&&(c=1-c),c===0?e0.IsOutside:e0.IsInside)}function os(t,e){let n=e0.IsOn;for(let o of t)switch(Bt(o,e)){case e0.IsOutside:if(n===e0.IsOutside)return!1;n=e0.IsOutside;break;case e0.IsInside:if(n===e0.IsInside)return!0;n=e0.IsInside;break;default:break}let r=a6(t),a,s;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>Number.MAX_SAFE_INTEGER?(a=Number((BigInt(r.left)+BigInt(r.right))/A5),s=Number((BigInt(r.top)+BigInt(r.bottom))/A5)):(a=Math.round((r.left+r.right)/2),s=Math.round((r.top+r.bottom)/2)),Bt({x:a,y:s},e)!==e0.IsOutside}var j1={MaxInt64:jt,MaxCoord:I3,max_coord:I3,min_coord:-I3,Invalid64:t6,floatingPointTolerance:n6,defaultMinimumEdgeLength:_a,maxCoordForSafeAreaProduct:Ut,maxCoordForSafeCrossSq:qa,maxSafeCoordinateForScale:Da,checkSafeScaleValue:Na,ensureSafeInteger:Ua,crossProduct:Ba,crossProductSign:m2,checkPrecision:ja,isAlmostZero:Ga,triSign:Wa,multiplyUInt64:Xa,productsAreEqual:r6,isCollinear:Za,dotProduct:Ya,dotProductSign:Ka,area:Ja,crossProductD:Qa,dotProductD:es,roundToEven:ts,checkCastInt64:ns,getLineIntersectPt:rs,getLineIntersectPtD:as,segsIntersect:ss,getBounds:a6,getClosestPtOnSegment:cs,pointInPolygon:Bt,path2ContainsPath1:os},V2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return j1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),j1.ensureSafeInteger(t.y,"Point64Utils.fromPointD"),{x:Math.round(t.x),y:Math.round(t.y),z:t.z||0}},scale(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e),z:t.z||0}},equals(t,e){return t.x===e.x&&t.y===e.y},add(t,e){if(Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(e.y)){let n=t.x+e.x,r=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?{x:n,y:r,z:0}:{x:Number(BigInt(t.x)+BigInt(e.x)),y:Number(BigInt(t.y)+BigInt(e.y)),z:0}}return{x:t.x+e.x,y:t.y+e.y,z:0}},subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:0}},toString(t){return t.z!==void 0&&t.z!==0?`${t.x},${t.y},${t.z} `:`${t.x},${t.y} `}},L5={create(t=0,e=0,n=0){return{x:t,y:e,z:n}},fromPoint64(t){return{x:t.x,y:t.y,z:t.z||0}},scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z||0}},equals(t,e){return j1.isAlmostZero(t.x-e.x)&&j1.isAlmostZero(t.y-e.y)},negate(t){t.x=-t.x,t.y=-t.y},toString(t,e=2){return t.z!==void 0&&t.z!==0?`${t.x.toFixed(e)},${t.y.toFixed(e)},${t.z}`:`${t.x.toFixed(e)},${t.y.toFixed(e)}`}},we={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},isValid(t){return t.left<Number.MAX_SAFE_INTEGER},midPoint(t){if(Number.isSafeInteger(t.left)&&Number.isSafeInteger(t.right)&&Math.abs(t.left)+Math.abs(t.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(t.left)+BigInt(t.right))/A5),n=Number((BigInt(t.top)+BigInt(t.bottom))/A5);return{x:e,y:n}}return{x:Math.round((t.left+t.right)/2),y:Math.round((t.top+t.bottom)/2)}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<=Math.min(t.right,e.right)&&Math.max(t.top,e.top)<=Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}},Gt={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},midPoint(t){return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<Math.min(t.right,e.right)&&Math.max(t.top,e.top)<Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}};var s6=Object.freeze(we.createInvalid()),c6=Object.freeze(Gt.createInvalid());var V3=BigInt(0),is=BigInt(2),o6=BigInt(4),r0;(function(t){t[t.None=0]="None",t[t.OpenStart=1]="OpenStart",t[t.OpenEnd=2]="OpenEnd",t[t.LocalMax=4]="LocalMax",t[t.LocalMin=8]="LocalMin"})(r0||(r0={}));var Wt=class{constructor(){X(this,"data",[])}push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],n=this.data.pop();return this.data.length>0&&(this.data[0]=n,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let n=this.data[e];for(;e>0;){let r=e-1>>1;if(this.data[r]>=n)break;this.data[e]=this.data[r],e=r}this.data[e]=n}siftDown(e){let n=this.data.length,r=this.data[e];for(;;){let a=(e<<1)+1;if(a>=n)break;let s=a+1,c=a;if(s<n&&this.data[s]>this.data[a]&&(c=s),this.data[c]<=r)break;this.data[e]=this.data[c],e=c}this.data[e]=r}},$3=class{constructor(e,n,r){X(this,"pt");X(this,"next",null);X(this,"prev",null);X(this,"flags");this.pt=e,this.flags=n,this.prev=r}},H3=class{constructor(e,n,r=!1){X(this,"vertex");X(this,"polytype");X(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=r}equals(e){return e!==null&&this.vertex===e.vertex}};function i6(t,e,n){return{pt:t,edge1:e,edge2:n}}var j2=class{constructor(e,n){X(this,"pt");X(this,"next");X(this,"prev");X(this,"outrec");X(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},K0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(K0||(K0={}));var Xt;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(Xt||(Xt={}));var C5=class{constructor(){X(this,"idx",0);X(this,"owner",null);X(this,"frontEdge",null);X(this,"backEdge",null);X(this,"pts",null);X(this,"polypath",null);X(this,"bounds",{left:0,top:0,right:0,bottom:0});X(this,"path",[]);X(this,"isOpen",!1);X(this,"splits",null);X(this,"recursiveSplit",null)}},P5=class{constructor(e){X(this,"leftOp");X(this,"rightOp");X(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},O3=class{constructor(e,n){X(this,"op1");X(this,"op2");this.op1=e,this.op2=n}};function ls(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function hs(t,e){return t.pt.y!==e.pt.y?t.pt.y>e.pt.y?-1:1:t.pt.x!==e.pt.x?t.pt.x<e.pt.x?-1:1:t.edge1.curX!==e.edge1.curX?t.edge1.curX<e.edge1.curX?-1:1:t.edge2.curX<e.edge2.curX?-1:t.edge2.curX>e.edge2.curX?1:0}var R3=class{constructor(){X(this,"bot",{x:0,y:0});X(this,"top",{x:0,y:0});X(this,"curX",0);X(this,"dx",0);X(this,"windDx",0);X(this,"windCount",0);X(this,"windCount2",0);X(this,"outrec",null);X(this,"prevInAEL",null);X(this,"nextInAEL",null);X(this,"prevInSEL",null);X(this,"nextInSEL",null);X(this,"jump",null);X(this,"vertexTop",null);X(this,"localMin",null);X(this,"isLeftBound",!1);X(this,"joinWith",K0.None)}},Ge={addLocMin(t,e,n,r){if((t.flags&r0.LocalMin)!==r0.None)return;t.flags|=r0.LocalMin;let a=new H3(t,e,n);r.push(a)},addPathsToVertexList(t,e,n,r,a){for(let s=0,c=t.length;s<c;s++){let o=t[s],i=null,l=null,h=null;for(let m=0,g=o.length;m<g;m++){let p=o[m];if(i===null)i=new $3(p,r0.None,null),a.push(i),l=i,h=p;else if(!(h.x===p.x&&h.y===p.y)){let v=new $3(p,r0.None,l);l.next=v,l=v,h=p}}if(l?.prev==null||(!n&&l.pt.x===i.pt.x&&l.pt.y===i.pt.y&&(l=l.prev),l.next=i,i.prev=l,!n&&l.next===l))continue;let u;if(n){let m=i.next;for(;m!==i&&m.pt.y===i.pt.y;)m=m.next;u=m.pt.y<=i.pt.y,u?(i.flags=r0.OpenStart,Ge.addLocMin(i,e,!0,r)):i.flags=r0.OpenStart|r0.LocalMax}else{for(l=i.prev;l!==i&&l.pt.y===i.pt.y;)l=l.prev;if(l===i)continue;u=l.pt.y>i.pt.y}let f=u;l=i;let d=i.next;for(;d!==i;)d.pt.y>l.pt.y&&u?(l.flags|=r0.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,Ge.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=r0.OpenEnd,u?l.flags|=r0.LocalMax:Ge.addLocMin(l,e,n,r)):u!==f&&(f?Ge.addLocMin(l,e,!1,r):l.flags|=r0.LocalMax)}}};var E5=class{constructor(e=null){X(this,"parent");X(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,n=this.parent;for(;n!==null;)++e,n=n.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)===0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,n){let r="",a=" ".repeat(n),s=this.children.length===1?"":"s";(n&1)===0?r+=`${a}+- hole (${e}) contains ${this.children.length} nested polygon${s}.
3
3
  `:r+=`${a}+- polygon (${e}) contains ${this.children.length} hole${s}.
4
4
  `;for(let c=0;c<this.count;c++)this.children[c].count>0&&(r+=this.children[c].toStringInternal(c,n+1));return r}toString(){if(this.level>0)return"";let e=this.children.length===1?"":"s",n=`Polytree with ${this.children.length} polygon${e}.
5
5
  `;for(let r=0;r<this.count;r++)this.children[r].count>0&&(n+=this.children[r].toStringInternal(r,1));return n+`
6
- `}},E5=class t extends P5{constructor(n=null){super(n);X(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let r=new t(this);return r.polygon=n,this.children.push(r),r}child(n){if(n<0||n>=this.children.length)throw new Error("Index out of range");return this.children[n]}area(){let n=this.polygon===null?0:Xt.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var R3=class extends E5{};var F=class F{constructor(){X(this,"cliptype",f0.NoClip);X(this,"fillrule",J1.EvenOdd);X(this,"actives",null);X(this,"sel",null);X(this,"minimaList",[]);X(this,"intersectList",[]);X(this,"vertexList",[]);X(this,"outrecList",[]);X(this,"scanlineHeap",new Gt);X(this,"scanlineSet",new Set);X(this,"scanlineArr",[]);X(this,"useScanlineArray",!1);X(this,"horzSegList",[]);X(this,"horzJoinList",[]);X(this,"currentLocMin",0);X(this,"currentBotY",0);X(this,"curXValidAtTop",!1);X(this,"isSortedMinimaList",!1);X(this,"hasOpenPaths",!1);X(this,"usingPolytree",!1);X(this,"succeeded",!1);X(this,"zCallbackInternal");X(this,"preserveCollinear",!0);X(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,r){let a=this.zCallbackInternal;a&&(F.getPolyType(e)===W0.Subject?(this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:r.z=0,a(e.bot,e.top,n.bot,n.top,r)):(this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:r.z=0,a(n.bot,n.top,e.bot,e.top,r)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return F.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return F.openPathsEnabled&&e.localMin.isOpen&&F.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(r0.OpenStart|r0.OpenEnd))!==r0.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!F.openPathsEnabled){for(;n!==null&&!F.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!F.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let r=n.y-e.y;return r!==0?(n.x-e.x)/r:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:j1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=F.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&r0.LocalMax)!==r0.None}static isMaximaEdge(e){return(e.vertexTop.flags&r0.LocalMax)!==r0.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,r,a){let s=e.x<n.x?e.x:n.x;if((r.x>a.x?r.x:a.x)<s)return!1;let o=e.x>n.x?e.x:n.x,i=r.x<a.x?r.x:a.x;if(o<i)return!1;let l=e.y<n.y?e.y:n.y;if((r.y>a.y?r.y:a.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=r.y<a.y?r.y:a.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,r=e.length;n<r;n++){let a=e[n];this.scanlineSet.add(a),this.scanlineHeap.push(a)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let r=0,a=n.length;r<a;r++)if(n[r]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,r=n.length;if(r===0)return null;let a=0,s=n[0];for(let c=1;c<r;c++){let o=n[c];o>s&&(s=o,a=c)}return n[a]=n[r-1],n.pop(),s}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,r=!1){let a=[e];this.addPaths(a,n,r)}addPaths(e,n,r=!1){r&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,Ge.addPathsToVertexList(e,n,r,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new $3(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,r=e.nextInAEL;n===null&&r===null&&e!==this.actives||(n!==null?n.nextInAEL=r:this.actives=r,r!==null&&(r.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let r=n;do r.pt.x<e.left&&(e.left=r.pt.x),r.pt.x>e.right&&(e.right=r.pt.x),r.pt.y<e.top&&(e.top=r.pt.y),r.pt.y>e.bottom&&(e.bottom=r.pt.y),r=r.next;while(r!==n)}return we.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===f0.NoClip)return;F.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let r=this.popScanline();if(r!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(r);let a;for(;(a=this.popHorz())!==null;)this.doHorizontal(a);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=r;let s=this.popScanline();if(s===null)break;for(r=s,this.doIntersections(r),this.doTopOfScanbeam(r);(a=this.popHorz())!==null;)this.doHorizontal(a)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),r;(n.vertex.flags&r0.OpenStart)!==r0.None?r=null:(r=new O3,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=-1,r.vertexTop=n.vertex.prev,r.top=n.vertex.prev.pt,r.outrec=null,r.localMin=n,F.setDx(r));let a;if((n.vertex.flags&r0.OpenEnd)!==r0.None?a=null:(a=new O3,a.bot=n.vertex.pt,a.curX=n.vertex.pt.x,a.windDx=1,a.vertexTop=n.vertex.next,a.top=n.vertex.next.pt,a.outrec=null,a.localMin=n,F.setDx(a)),r!==null&&a!==null){if(F.isHorizontal(r)){if(F.isHeadingRightHorz(r)){let c=r;r=a,a=c}}else if(F.isHorizontal(a)){if(F.isHeadingLeftHorz(a)){let c=r;r=a,a=c}}else if(r.dx<a.dx){let c=r;r=a,a=c}}else r===null&&(r=a,a=null);let s;if(r.isLeftBound=!0,this.insertLeftEdge(r),F.openPathsEnabled?F.isOpen(r)?(this.setWindCountForOpenPathEdge(r),s=this.isContributingOpen(r)):(this.setWindCountForClosedPathEdge(r),s=this.isContributingClosed(r)):(this.setWindCountForClosedPathEdge(r),s=this.isContributingClosed(r)),a!==null){for(a.windCount=r.windCount,a.windCount2=r.windCount2,this.insertRightEdge(r,a),s&&(this.addLocalMinPoly(r,a,r.bot,!0),F.isHorizontal(r)||this.checkJoinLeft(r,r.bot));a.nextInAEL!==null&&this.isValidAelOrder(a.nextInAEL,a);)this.intersectEdges(a,a.nextInAEL,a.bot),this.swapPositionsInAEL(a,a.nextInAEL);F.isHorizontal(a)?this.pushHorz(a):(this.checkJoinRight(a,a.bot),this.insertScanline(a.top.y))}else s&&F.openPathsEnabled&&this.startOpenPath(r,r.bot);F.isHorizontal(r)?this.pushHorz(r):this.insertScanline(r.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!F.openPathsEnabled){this.doHorizontalClosed(e);return}let n=F.isOpen(e),r=e.bot.y,a=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:s,leftX:c,rightX:o}=this.resetHorzDirection(e,a),i=c,l=o;if(F.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:r});this.addToHorzSegList(h)}for(;;){let h=s?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===a){if(F.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),F.isHotEdge(e)){for(;e.vertexTop!==a;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);s?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(a!==e.vertexTop||F.isOpenEnd(e)){if(s&&h.curX>l||!s&&h.curX<i)break;if(h.curX===e.top.x&&!F.isHorizontal(h)){let d=F.nextVertex(e).pt;if(F.isOpen(h)&&!F.isSamePolyType(h,e)&&!F.isHotEdge(h)){if(s&&F.topX(h,d.y)>d.x||!s&&F.topX(h,d.y)<d.x)break}else if(s&&F.topX(h,d.y)>=d.x||!s&&F.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:r};s?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&F.isOpenEnd(e)){F.isHotEdge(e)&&(this.addOutPt(e,e.top),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,a);i=u.leftX,l=u.rightX}if(F.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,r=this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:c}=this.resetHorzDirection(e,r),o=s,i=c;if(F.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=a?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===r){if(F.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),F.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(r!==e.vertexTop){if(a&&l.curX>i||!a&&l.curX<o)break;if(l.curX===e.top.x&&!F.isHorizontal(l)){let f=F.nextVertex(e).pt,d=F.topX(l,f.y);if(a&&d>=f.x||!a&&d<=f.x)break}}let u={x:l.curX,y:n};a?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,r);o=h.leftX,i=h.rightX}if(F.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let r=0,a=e.length;r<a;r++){let s=e[r];this.updateHorzSegment(s)&&(e[n++]=s)}if(!(n<2)){e.length=n,this.horzSegList.sort(ls);for(let r=0;r<n-1;r++){let a=this.horzSegList[r];for(let s=r+1;s<n;s++){let c=this.horzSegList[s];if(c.leftOp.pt.x>=a.rightOp.pt.x||c.leftToRight===a.leftToRight||c.rightOp.pt.x<=a.leftOp.pt.x)continue;let o=a.leftOp.pt.y;if(a.leftToRight){for(;a.leftOp.next.pt.y===o&&a.leftOp.next.pt.x<=c.leftOp.pt.x;)a.leftOp=a.leftOp.next;for(;c.leftOp.prev.pt.y===o&&c.leftOp.prev.pt.x<=a.leftOp.pt.x;)c.leftOp=c.leftOp.prev;let i=new H3(this.duplicateOp(a.leftOp,!0),this.duplicateOp(c.leftOp,!1));this.horzJoinList.push(i)}else{for(;a.leftOp.prev.pt.y===o&&a.leftOp.prev.pt.x<=c.leftOp.pt.x;)a.leftOp=a.leftOp.prev;for(;c.leftOp.next.pt.y===o&&c.leftOp.next.pt.x<=a.leftOp.pt.x;)c.leftOp=c.leftOp.next;let i=new H3(this.duplicateOp(c.leftOp,!0),this.duplicateOp(a.leftOp,!1));this.horzJoinList.push(i)}}}}}updateHorzSegment(e){let n=e.leftOp,r=this.getRealOutRec(n.outrec),a=r.frontEdge!==null,s=n.pt.y,c=n,o=n;if(a){let l=r.pts,h=l.next;for(;c!==h&&c.prev.pt.y===s;)c=c.prev;for(;o!==l&&o.next.pt.y===s;)o=o.next}else{for(;c.prev!==o&&c.prev.pt.y===s;)c=c.prev;for(;o.next!==c&&o.next.pt.y===s;)o=o.next}let i=this.setHorzSegHeadingForward(e,c,o)&&e.leftOp.horz===null;return i?e.leftOp.horz=e:e.rightOp=null,i}setHorzSegHeadingForward(e,n,r){return n.pt.x===r.pt.x?!1:(n.pt.x<r.pt.x?(e.leftOp=n,e.rightOp=r,e.leftToRight=!0):(e.leftOp=r,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let r=new j2(e.pt,e.outrec);return n?(r.next=e.next,r.next.prev=r,r.prev=e,e.next=r):(r.prev=e.prev,r.prev.next=r,r.next=e,e.prev=r),r}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let r=this.actives;for(;r!==null;){if(r.top.y===e)if(r.curX=r.top.x,F.isMaximaEdge(r)){r=this.doMaxima(r);continue}else F.isHotEdge(r)&&this.addOutPt(r,r.top),this.updateEdgeIntoAEL(r),F.isHorizontal(r)&&this.pushHorz(r);else n||(r.curX=F.topX(r,e));r=r.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),r=this.getRealOutRec(e.op2.outrec),a=e.op1.next,s=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,a.prev=s,s.next=a,n===r){let c=this.newOutRec();c.pts=a,this.fixOutRecPts(c),n.pts.outrec===c&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,c.pts)?([c.pts,n.pts]=[n.pts,c.pts],this.fixOutRecPts(n),this.fixOutRecPts(c),c.owner=n):this.path1InsidePath2(c.pts,n.pts)?c.owner=n:c.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(c.idx)):c.owner=n}else r.pts=null,this.usingPolytree?(this.setOwner(r,n),this.moveSplits(r,n)):r.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let r=e0.IsOn,a=e;do{switch(this.pointInOpPolygon(a.pt,n)){case e0.IsOutside:if(r===e0.IsOutside)return!1;r=e0.IsOutside;break;case e0.IsInside:if(r===e0.IsInside)return!0;r=e0.IsInside;break;default:break}a=a.next}while(a!==e);return j1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return e0.IsOutside;let r=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==r);if(n.pt.y===e.y)return e0.IsOutside;let a=n.pt.y<e.y,s=a,c=0;for(r=n.next;r!==n;){if(a)for(;r!==n&&r.pt.y<e.y;)r=r.next;else for(;r!==n&&r.pt.y>e.y;)r=r.next;if(r===n)break;if(r.pt.y===e.y){if(r.pt.x===e.x||r.pt.y===r.prev.pt.y&&e.x<r.prev.pt.x!=e.x<r.pt.x)return e0.IsOn;if(r=r.next,r===n)break;continue}if(r.pt.x<=e.x||r.prev.pt.x<=e.x)if(r.prev.pt.x<e.x&&r.pt.x<e.x)c=1-c;else{let o=j1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return e0.IsOn;o<0===a&&(c=1-c)}a=!a,r=r.next}if(a===s)return c===0?e0.IsOutside:e0.IsInside;{let o=j1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return e0.IsOn;o<0===a&&(c=1-c)}return c===0?e0.IsOutside:e0.IsInside}getCleanPath(e){let n=[],r=e;for(;r.next!==e&&(r.pt.x===r.next.pt.x&&r.pt.x===r.prev.pt.x||r.pt.y===r.next.pt.y&&r.pt.y===r.prev.pt.y);)r=r.next;n.push(r.pt);let a=r;for(r=r.next;r!==e;)(r.pt.x!==r.next.pt.x||r.pt.x!==a.pt.x)&&(r.pt.y!==r.next.pt.y||r.pt.y!==a.pt.y)&&(n.push(r.pt),a=r),r=r.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let r of e.splits)r!==n.idx&&n.splits.push(r);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let r=null;for(;n!==null&&n.jump!==null;){let a=n,s=n.jump,c=s,o=s?.jump||null;for(n.jump=o;n!==c&&s!==o;)if(s.curX<n.curX){let i=s.prevInSEL;for(;this.addNewIntersectNode(i,s,e),i!==n;)i=i.prevInSEL;if(i=s,s=this.extractFromSEL(i),c=s,n!==null&&this.insert1Before2InSEL(i,n),n!==a)continue;a=i,a.jump=o,r===null?this.sel=a:r.jump=a}else n=n.nextInSEL;r=a,n=o}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(hs);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let r=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[r]);)r++;[this.intersectList[r],this.intersectList[e]]=[this.intersectList[e],this.intersectList[r]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let r=Number.NEGATIVE_INFINITY,a=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let s=F.topX(n,e);n.curX=s,s<r&&(a=!0),r=s,n=n.nextInAEL}return a}doMaxima(e){let n=e.prevInAEL,r=e.nextInAEL;if(F.isOpenEnd(e))return F.isHotEdge(e)&&this.addOutPt(e,e.top),F.isHorizontal(e)||(F.isHotEdge(e)&&(F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),r;let a=F.getMaximaPair(e);if(a===null)return r;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(a)&&this.split(a,a.top);r!==a;)this.intersectEdges(e,r,e.top),this.swapPositionsInAEL(e,r),r=e.nextInAEL;return F.isOpen(e)?(F.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(a),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(F.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(e),this.deleteFromAEL(a),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=F.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,F.setDx(e),this.isJoined(e)&&this.split(e,e.bot),F.isHorizontal(e)){F.openPathsEnabled?F.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let r=!1,a=F.nextVertex(e).pt;for(;a.y===e.top.y&&!(n&&a.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=F.nextVertex(e),e.top=a,r=!0,F.isMaximaVertex(e.vertexTop)));)a=F.nextVertex(e).pt;r&&F.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new C5(e))}addNewIntersectNode(e,n,r){let a=j1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(a===null&&(a={x:e.curX,y:r}),a.y>this.currentBotY||a.y<r){let c=Math.abs(e.dx),o=Math.abs(n.dx);c>100&&o>100?c>o?a=j1.getClosestPtOnSegment(a,e.bot,e.top):a=j1.getClosestPtOnSegment(a,n.bot,n.top):c>100?a=j1.getClosestPtOnSegment(a,e.bot,e.top):o>100?a=j1.getClosestPtOnSegment(a,n.bot,n.top):(a.y<r?a.y=r:a.y=this.currentBotY,c<o?a.x=F.topX(e,a.y):a.x=F.topX(n,a.y))}let s=i6(a,e,n);this.intersectList.push(s)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(r0.OpenEnd|r0.LocalMax))===r0.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(r0.OpenEnd|r0.LocalMax))===r0.None;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let r=e.curX,a=e.curX,s=e.nextInAEL;for(;s!==null&&s.vertexTop!==n;)s=s.nextInAEL;return{isLeftToRight:s!==null,leftX:r,rightX:a}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===K0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===J1.EvenOdd){let r=0,a=0;for(;n!==e;)F.getPolyType(n)===W0.Clip?a++:F.isOpen(n)||r++,n=n.nextInAEL;e.windCount=F.isOdd(r)?1:0,e.windCount2=F.isOdd(a)?1:0}else for(;n!==e;)F.getPolyType(n)===W0.Clip?e.windCount2+=n.windDx:F.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,r=F.getPolyType(e);if(!F.openPathsEnabled){for(;n!==null&&F.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===J1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===J1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(F.getPolyType(n)!==r||F.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===J1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=F.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===J1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,r;switch(this.fillrule){case J1.Positive:r=e.windCount>0,n=e.windCount2>0;break;case J1.Negative:r=e.windCount<0,n=e.windCount2<0;break;default:r=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case f0.Intersection:return n;case f0.Union:return!r&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case J1.Positive:if(e.windCount!==1)return!1;break;case J1.Negative:if(e.windCount!==-1)return!1;break;case J1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case f0.Intersection:return this.fillrule===J1.Positive?e.windCount2>0:this.fillrule===J1.Negative?e.windCount2<0:e.windCount2!==0;case f0.Union:return this.fillrule===J1.Positive?e.windCount2<=0:this.fillrule===J1.Negative?e.windCount2>=0:e.windCount2===0;case f0.Difference:{let n=this.fillrule===J1.Positive?e.windCount2<=0:this.fillrule===J1.Negative?e.windCount2>=0:e.windCount2===0;return F.getPolyType(e)===W0.Subject?n:!n}case f0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,r,a=!1){let s=this.newOutRec();if(e.outrec=s,n.outrec=s,F.isOpen(e))s.owner=null,s.isOpen=!0,e.windDx>0?this.setSides(s,e,n):this.setSides(s,n,e);else{s.isOpen=!1;let o=F.getPrevHotEdge(e);o!==null?(this.usingPolytree&&this.setOwner(s,o.outrec),s.owner=o.outrec,this.outrecIsAscending(o)===a?this.setSides(s,n,e):this.setSides(s,e,n)):(s.owner=null,a?this.setSides(s,e,n):this.setSides(s,n,e))}let c=new j2(r,s);return s.pts=c,c}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new L5;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let r=this.newOutRec();r.isOpen=!0,e.windDx>0?(r.frontEdge=e,r.backEdge=null):(r.frontEdge=null,r.backEdge=e),e.outrec=r;let a=new j2(n,r);return r.pts=a,a}checkJoinLeft(e,n,r=!1){let a=e.prevInAEL;a!==null&&(!r&&e.curX!==a.curX||!F.isHotEdge(e)||!F.isHotEdge(a)||F.isHorizontal(e)||F.isHorizontal(a)||F.isOpen(e)||F.isOpen(a)||(n.y<e.top.y+2||n.y<a.top.y+2)&&(e.bot.y>n.y||a.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,a.bot,a.top)||j1.isCollinear(e.top,n,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(a,e,n):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),a.joinWith=K0.Right,e.joinWith=K0.Left))}checkJoinRight(e,n,r=!1){let a=e.nextInAEL;a!==null&&(!r&&e.curX!==a.curX||!F.isHotEdge(e)||!F.isHotEdge(a)||F.isHorizontal(e)||F.isHorizontal(a)||F.isOpen(e)||F.isOpen(a)||(n.y<e.top.y+2||n.y<a.top.y+2)&&(e.bot.y>n.y||a.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,a.bot,a.top)||j1.isCollinear(e.top,n,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(e,a,n):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),e.joinWith=K0.Right,a.joinWith=K0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,r){let a=e.x-n.x,s=e.y-n.y,c=r.x-n.x,o=r.y-n.y;if(c===0&&o===0)return!1;let i=j1.maxCoordForSafeCrossSq;if(Math.abs(a)<i&&Math.abs(s)<i&&Math.abs(c)<i&&Math.abs(o)<i){let h=a*o-c*s;return h*h/(c*c+o*o)>.25}if(Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(c)&&Number.isSafeInteger(o)){let h=BigInt(a)*BigInt(o)-BigInt(c)*BigInt(s),u=h*h,f=BigInt(c)*BigInt(c)+BigInt(o)*BigInt(o);return o6*u>f}let l=a*o-c*s;return l*l/(c*c+o*o)>.25}intersectEdges(e,n,r){let a;if(this.hasOpenPaths&&(F.isOpen(e)||F.isOpen(n))){if(F.isOpen(e)&&F.isOpen(n))return;if(F.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,r),this.cliptype===f0.Union){if(!F.isHotEdge(n))return}else if(n.localMin.polytype===W0.Subject)return;switch(this.fillrule){case J1.Positive:if(n.windCount!==1)return;break;case J1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(F.isHotEdge(e))a=this.addOutPt(e,r),this.setZ(e,n,a.pt),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(r.x===e.localMin.vertex.pt.x&&r.y===e.localMin.vertex.pt.y&&!F.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&F.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}a=this.startOpenPath(e,r)}else a=this.startOpenPath(e,r);this.setZ(e,n,a.pt);return}this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r);let s,c;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===J1.EvenOdd?(s=e.windCount,e.windCount=n.windCount,n.windCount=s):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==J1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==J1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case J1.Positive:s=e.windCount,c=n.windCount;break;case J1.Negative:s=-e.windCount,c=-n.windCount;break;default:s=Math.abs(e.windCount),c=Math.abs(n.windCount);break}let o=s===0||s===1,i=c===0||c===1;if(!(!F.isHotEdge(e)&&!o||!F.isHotEdge(n)&&!i))if(F.isHotEdge(e)&&F.isHotEdge(n))if(s!==0&&s!==1||c!==0&&c!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==f0.Xor)a=this.addLocalMaxPoly(e,n,r),a&&this.setZ(e,n,a.pt);else if(F.isFront(e)||e.outrec===n.outrec){a=this.addLocalMaxPoly(e,n,r),a&&this.setZ(e,n,a.pt);let l=this.addLocalMinPoly(e,n,r);this.setZ(e,n,l.pt)}else{a=this.addOutPt(e,r),this.setZ(e,n,a.pt);let l=this.addOutPt(n,r);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(F.isHotEdge(e))a=this.addOutPt(e,r),this.setZ(e,n,a.pt),this.swapOutrecs(e,n);else if(F.isHotEdge(n))a=this.addOutPt(n,r),this.setZ(e,n,a.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case J1.Positive:l=e.windCount2,h=n.windCount2;break;case J1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!F.isSamePolyType(e,n))a=this.addLocalMinPoly(e,n,r),this.setZ(e,n,a.pt);else if(s===1&&c===1){switch(a=null,this.cliptype){case f0.Union:if(l>0&&h>0)return;a=this.addLocalMinPoly(e,n,r);break;case f0.Difference:(F.getPolyType(e)===W0.Clip&&l>0&&h>0||F.getPolyType(e)===W0.Subject&&l<=0&&h<=0)&&(a=this.addLocalMinPoly(e,n,r));break;case f0.Xor:a=this.addLocalMinPoly(e,n,r);break;default:if(l<=0||h<=0)return;a=this.addLocalMinPoly(e,n,r);break}a&&this.setZ(e,n,a.pt)}}}swapPositionsInAEL(e,n){let r=n.nextInAEL;r!==null&&(r.prevInAEL=e);let a=e.prevInAEL;a!==null&&(a.nextInAEL=n),n.prevInAEL=a,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=r,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let r=j1.crossProductSign(e.top,n.bot,n.top);if(r!==0)return r<0;if(!F.isMaximaEdge(e)&&e.top.y>n.top.y)return j1.crossProductSign(n.bot,e.top,F.nextVertex(e).pt)<=0;if(!F.isMaximaEdge(n)&&n.top.y>e.top.y)return j1.crossProductSign(n.bot,n.top,F.nextVertex(n).pt)>=0;let a=n.bot.y,s=n.isLeftBound;return e.bot.y!==a||e.localMin.vertex.pt.y!==a?n.isLeftBound:e.isLeftBound!==s?s:j1.isCollinear(F.prevPrevVertex(e).pt,e.bot,e.top)?!0:j1.crossProductSign(F.prevPrevVertex(e).pt,n.bot,F.prevPrevVertex(n).pt)>0===s}isJoined(e){return e.joinWith!==K0.None}split(e,n){e.joinWith===K0.Right?(e.joinWith=K0.None,e.nextInAEL.joinWith=K0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=K0.None,e.prevInAEL.joinWith=K0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,r){e.frontEdge=n,e.backEdge=r}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let r=e.outrec,a=F.isFront(e),s=r.pts,c=s.next;if(a&&n.x===s.pt.x&&n.y===s.pt.y)return s;if(!a&&n.x===c.pt.x&&n.y===c.pt.y)return c;let o=new j2(n,r);return c.prev=o,o.prev=s,o.next=c,s.next=o,a&&(r.pts=o),o}addLocalMaxPoly(e,n,r){if(this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r),F.isFront(e)===F.isFront(n))if(F.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(F.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let a=this.addOutPt(e,r);if(e.outrec===n.outrec){let s=e.outrec;if(s.pts=a,this.usingPolytree){let c=F.getPrevHotEdge(e);c===null?s.owner=null:this.setOwner(s,c.outrec)}this.uncoupleOutRec(e)}else F.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return a}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let r=n;for(;r!==null&&r!==e;)r=r.owner;r!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let r=e.outrec.pts,a=n.outrec.pts,s=r.next,c=a.next;F.isFront(e)?(c.prev=r,r.next=c,a.next=s,s.prev=a,e.outrec.pts=a,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(s.prev=a,a.next=s,r.next=c,c.prev=r,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),F.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let r=e.outrec,a=n.outrec;if(r===a){let s=r.frontEdge;r.frontEdge=r.backEdge,r.backEdge=s;return}r!==null&&(e===r.frontEdge?r.frontEdge=n:r.backEdge=n),a!==null&&(n===a.frontEdge?a.frontEdge=e:a.backEdge=e),e.outrec=a,n.outrec=r}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(F.ptsReallyClose(e.prev.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,r,a){if(e===null||e.next===e||!r&&e.next===e.prev)return!1;a.length=0;let s,c;for(n?(s=e.pt,c=e.prev):(e=e.next,s=e.pt,c=e.next),a.push(s);c!==e;)c.pt.x===s.x&&c.pt.y===s.y||(s=c.pt,a.push(s)),n?c=c.prev:c=c.next;return a.length!==3||r||!F.isVerySmallTriangle(c)}buildPaths(e,n){e.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let a=this.outrecList[r++];if(a.pts===null)continue;let s=[];a.isOpen?F.buildPath(a.pts,this.reverseSolution,!0,s)&&n.push(s):(this.cleanCollinear(a),F.buildPath(a.pts,this.reverseSolution,!1,s)&&e.push(s))}return!0}buildTree(e,n){e.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let a=this.outrecList[r++];if(a.pts!==null){if(a.isOpen){let s=[];F.buildPath(a.pts,this.reverseSolution,!0,s)&&n.push(s);continue}this.checkBounds(a)&&this.recursiveCheckOwners(a,e)}}}checkBounds(e){return e.pts===null?!1:we.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!F.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=j1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||we.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,r=n;for(;;){if(r!==null&&j1.isCollinear(r.prev.pt,r.pt,r.next.pt)&&(r.pt.x===r.prev.pt.x&&r.pt.y===r.prev.pt.y||r.pt.x===r.next.pt.x&&r.pt.y===r.next.pt.y||!this.preserveCollinear||j1.dotProductSign(r.prev.pt,r.pt,r.next.pt)<0)){if(r===e.pts&&(e.pts=r.prev),r=this.disposeOutPt(r),!this.isValidClosedPath(r)){e.pts=null;return}n=r;continue}if(r===null||(r=r.next,r===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!F.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&j1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let r=n.prev,a=n.next.next;e.pts=r;let s=j1.getLineIntersectPt(r.pt,n.pt,n.next.pt,a.pt);this.zCallbackInternal&&this.zCallbackInternal(r.pt,n.pt,n.next.pt,a.pt,s);let c=F.areaOutPt(r),o=c<I3?-c:c;if(o<o6){e.pts=null;return}let i=this.areaTriangle(s,n.pt,n.next.pt),l=i<I3?-i:i;if(s.x===r.pt.x&&s.y===r.pt.y||s.x===a.pt.x&&s.y===a.pt.y)a.prev=r,r.next=a;else{let f=new j2(s,e);f.prev=r,f.next=a,a.prev=f,r.next=f}if(!(l>is)||!(l>o)&&i>I3!=c>I3)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new j2(s,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(r,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=j1.maxCoordForSafeAreaProduct,r=0,a=!0,s=e;do{let o=s.prev,i=s.pt;if(Math.abs(o.pt.x)>=n||Math.abs(o.pt.y)>=n||Math.abs(i.x)>=n||Math.abs(i.y)>=n){a=!1;break}r+=(o.pt.y+i.y)*(o.pt.x-i.x),s=s.next}while(s!==e);if(a)return BigInt(Math.round(r));let c=I3;s=e;do{let o=s.prev;if(Number.isSafeInteger(o.pt.y)&&Number.isSafeInteger(s.pt.y)&&Number.isSafeInteger(o.pt.x)&&Number.isSafeInteger(s.pt.x)){let i=BigInt(o.pt.y)+BigInt(s.pt.y),l=BigInt(o.pt.x)-BigInt(s.pt.x);c+=i*l}else{let i=o.pt.y+s.pt.y,l=o.pt.x-s.pt.x;c+=BigInt(Math.round(i*l))}s=s.next}while(s!==e);return c}areaTriangle(e,n,r){let a=j1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<a&&Math.abs(e.y)<a&&Math.abs(n.x)<a&&Math.abs(n.y)<a&&Math.abs(r.x)<a&&Math.abs(r.y)<a){let c=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(c))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(r.y)){let c=(BigInt(r.y)+BigInt(e.y))*(BigInt(r.x)-BigInt(e.x)),o=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),i=(BigInt(n.y)+BigInt(r.y))*(BigInt(n.x)-BigInt(r.x));return c+o+i}let s=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(s))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let r=0;r<n.length;r++){let a=this.outrecList[n[r]];if(a.pts===null&&a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(a=this.getRealOutRec(a),!(a===null||a===e||a.recursiveSplit===e)){if(a.recursiveSplit=e,a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(!(!this.checkBounds(a)||!this.containsRect(a.bounds,e.bounds)||!this.path1InsidePath2(e.pts,a.pts)))return this.isValidOwner(e,a)||(a.owner=e.owner),e.owner=a,!0}}return!1}};X(F,"openPathsEnabled",!0);var T5=F,$2=class extends T5{constructor(){super(...arguments);X(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,r,a=!1){super.addPath(n,r,a)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,r,a=!1){super.addPaths(n,r,a)}addSubject(n){this.addPaths(n,W0.Subject)}addOpenSubject(n){this.addPaths(n,W0.Subject,!0)}addClip(n){this.addPaths(n,W0.Clip)}execute(n,r,a,s){if(Array.isArray(a)){let c=a,o=s;c.length=0,o&&(o.length=0);try{this.executeInternal(n,r),this.buildPaths(c,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let c=a,o=s;c.clear(),o&&(o.length=0),this.usingPolytree=!0;try{this.executeInternal(n,r),this.buildTree(c,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var Xt={area(t){return j1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let r=t[n-1];for(let a of t)e+=(r.y+a.y)*(r.x-a.x),r=a;return e*.5},scalePath64(t,e){let n=j1.maxSafeCoordinateForScale(e),r=[];for(let a of t)j1.checkSafeScaleValue(a.x,n,"scalePath64"),j1.checkSafeScaleValue(a.y,n,"scalePath64"),r.push({x:Math.round(a.x*e),y:Math.round(a.y*e)});return r},scalePaths64(t,e){let n=[];for(let r of t)n.push(Xt.scalePath64(r,e));return n},scalePathD(t,e){let n=[];for(let r of t)n.push({x:r.x*e,y:r.y*e});return n},scalePathsD(t,e){let n=[];for(let r of t)n.push(Xt.scalePathD(r,e));return n}};var J0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(J0||(J0={}));var M0;(function(t){t[t.Polygon=0]="Polygon",t[t.Joined=1]="Joined",t[t.Butt=2]="Butt",t[t.Square=3]="Square",t[t.Round=4]="Round"})(M0||(M0={}));var Zt=class{constructor(e,n,r=M0.Polygon){X(this,"inPaths");X(this,"joinType");X(this,"endType");X(this,"pathsReversed");X(this,"lowestPathIdx");this.joinType=n,this.endType=r;let a=r===M0.Polygon||r===M0.Joined;this.inPaths=[];for(let s of e)this.inPaths.push(ke.stripDuplicates(s,a));if(r===M0.Polygon){let s=ke.getLowestPathInfo(this.inPaths);this.lowestPathIdx=s.idx,this.pathsReversed=this.lowestPathIdx>=0&&s.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},x0=class x0{constructor(e=2,n=0,r=!1,a=!1){X(this,"groupList",[]);X(this,"pathOut",[]);X(this,"normals",[]);X(this,"solution",[]);X(this,"solutionTree",null);X(this,"groupDelta",0);X(this,"delta",0);X(this,"mitLimSqr",0);X(this,"stepsPerRad",0);X(this,"stepSin",0);X(this,"stepCos",0);X(this,"joinType",J0.Bevel);X(this,"endType",M0.Polygon);X(this,"arcTolerance",0);X(this,"mergeGroups",!0);X(this,"miterLimit",2);X(this,"preserveCollinear",!1);X(this,"reverseSolution",!1);X(this,"zCallback");X(this,"deltaCallback",null);X(this,"ZCB",(e,n,r,a,s)=>{(e.z||0)!==0&&(e.z===r.z||e.z===a.z)?s.z=e.z:(r.z||0)!==0&&r.z===n.z?s.z=r.z:(n.z||0)!==0&&n.z===a.z?s.z=n.z:this.zCallback&&this.zCallback(e,n,r,a,s)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=r,this.reverseSolution=a}clear(){this.groupList.length=0}addPath(e,n,r){if(e.length===0)return;let a=[e];this.addPaths(a,n,r)}addPaths(e,n,r){e.length!==0&&this.groupList.push(new Zt(e,n,r))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===M0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===M0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let s of this.groupList)for(let c of s.inPaths)this.solution.push(c);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/x0.sqr(this.miterLimit);for(let s of this.groupList)this.doGroupOffset(s);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),r=n?J1.Negative:J1.Positive,a=new $2;a.preserveCollinear=this.preserveCollinear,a.reverseSolution=this.reverseSolution!==n,a.zCallback=this.ZCB,a.addSubject(this.solution),this.solutionTree!==null?a.execute(f0.Union,r,this.solutionTree):a.execute(f0.Union,r,this.solution)}execute(e,n){if(Array.isArray(n)){let r=n;r.length=0,this.solution=r,this.executeInternal(e)}else{let r=n;r.clear(),this.solutionTree=r,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let r=n.x-e.x,a=n.y-e.y;if(r===0&&a===0)return{x:0,y:0};let s=1/Math.sqrt(r*r+a*a);return{x:a*s,y:-r*s}}static getLowestPathInfo(e){let n=-1,r=!1,a={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let s=0;s<e.length;++s){let c=Number.MAX_VALUE;for(let o of e[s])if(!(o.y<a.y||o.y===a.y&&o.x>=a.x)){if(c===Number.MAX_VALUE){if(c=x0.area(e[s]),c===0)break;r=c<0}n=s,a.x=o.x,a.y=o.y}}return{idx:n,isNegArea:r}}static translatePoint(e,n,r){return{x:e.x+n,y:e.y+r,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=x0.hypotenuse(e.x,e.y);if(x0.almostZero(n))return{x:0,y:0};let r=1/n;return{x:e.x*r,y:e.y*r}}static getAvgUnitVector(e,n){return x0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,r,a){if(j1.isAlmostZero(e.x-n.x)){if(j1.isAlmostZero(r.x-a.x))return{x:0,y:0};let s=(a.y-r.y)/(a.x-r.x),c=r.y-s*r.x;return{x:e.x,y:s*e.x+c}}if(j1.isAlmostZero(r.x-a.x)){let s=(n.y-e.y)/(n.x-e.x),c=e.y-s*e.x;return{x:r.x,y:s*r.x+c}}else{let s=(n.y-e.y)/(n.x-e.x),c=e.y-s*e.x,o=(a.y-r.y)/(a.x-r.x),i=r.y-o*r.x;if(j1.isAlmostZero(s-o))return{x:0,y:0};let l=(i-c)/(s-o);return{x:l,y:s*l+c}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,r){let a,s,c=e[n].z||0;if(n===r){let o=Math.abs(this.groupDelta);a={x:Math.round(e[n].x-o*this.normals[n].x),y:Math.round(e[n].y-o*this.normals[n].y),z:c},s={x:Math.round(e[n].x+o*this.normals[n].x),y:Math.round(e[n].y+o*this.normals[n].y),z:c}}else a={x:Math.round(e[n].x+this.groupDelta*this.normals[r].x),y:Math.round(e[n].y+this.groupDelta*this.normals[r].y),z:c},s={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:c};this.pathOut.push(a),this.pathOut.push(s)}doSquare(e,n,r){let a;n===r?a={x:this.normals[n].y,y:-this.normals[n].x}:a=x0.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let s=Math.abs(this.groupDelta),c={x:e[n].x,y:e[n].y,z:e[n].z||0};c=x0.translatePoint(c,s*a.x,s*a.y);let o=x0.translatePoint(c,this.groupDelta*a.y,this.groupDelta*-a.x),i=x0.translatePoint(c,this.groupDelta*-a.y,this.groupDelta*a.x),l=this.getPerpendicD(e[r],this.normals[r]);if(n===r){let h={x:l.x+a.x*this.groupDelta,y:l.y+a.y*this.groupDelta},u=x0.intersectPoint(o,i,l,h);u.z=c.z,this.pathOut.push(V2.fromPointD(x0.reflectPoint(u,c))),this.pathOut.push(V2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[r]),u=x0.intersectPoint(o,i,l,h);u.z=c.z,this.pathOut.push(V2.fromPointD(u)),this.pathOut.push(V2.fromPointD(x0.reflectPoint(u,c)))}}doMiter(e,n,r,a){let s=this.groupDelta/(a+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[r].x+this.normals[n].x)*s),y:Math.round(e[n].y+(this.normals[r].y+this.normals[n].y)*s),z:e[n].z||0})}doRound(e,n,r,a){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*x0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let s=e[n],c=s.z||0,o={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&A5.negate(o),this.pathOut.push({x:Math.round(s.x+o.x),y:Math.round(s.y+o.y),z:c});let i=Math.ceil(this.stepsPerRad*Math.abs(a));for(let l=1;l<i;l++)o={x:o.x*this.stepCos-this.stepSin*o.y,y:o.x*this.stepSin+o.y*this.stepCos},this.pathOut.push({x:Math.round(s.x+o.x),y:Math.round(s.y+o.y),z:c});this.pathOut.push(this.getPerpendic(e[n],this.normals[n]))}buildNormals(e){let n=e.length;if(this.normals.length=0,n!==0){for(let r=0;r<n-1;r++)this.normals.push(x0.getUnitNormal(e[r],e[r+1]));this.normals.push(x0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,r,a){if(V2.equals(n[r],n[a]))return;let s=j1.crossProductD(this.normals[r],this.normals[a]),c=j1.dotProductD(this.normals[r],this.normals[a]);if(s>1?s=1:s<-1&&(s=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,a),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<x0.Tolerance){this.pathOut.push(n[r]);return}if(c>-.999&&s*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[a])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(c>.999&&this.joinType!==J0.Round)this.doMiter(n,r,a,c);else switch(this.joinType){case J0.Miter:c>this.mitLimSqr-1?this.doMiter(n,r,a,c):this.doSquare(n,r,a);break;case J0.Round:this.doRound(n,r,a,Math.atan2(s,c));break;case J0.Bevel:this.doBevel(n,r,a);break;default:this.doSquare(n,r,a);break}}offsetPolygon(e,n){this.pathOut=[];let r=n.length,a=r-1;for(let s=0;s<r;s++)this.offsetPoint(e,n,s,a),a=s;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let r=[...n].reverse();this.buildNormals(r),this.offsetPolygon(e,r)}offsetOpenPath(e,n){this.pathOut=[];let r=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<x0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case M0.Butt:this.doBevel(n,0,0);break;case M0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let a=1,s=0;a<r;a++)this.offsetPoint(e,n,a,s),s=a;for(let a=r;a>0;a--)this.normals[a]={x:-this.normals[a-1].x,y:-this.normals[a-1].y};if(this.normals[0]=this.normals[r],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,r)),Math.abs(this.groupDelta)<x0.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case M0.Butt:this.doBevel(n,r,r);break;case M0.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let a=r-1,s=r;a>0;a--)this.offsetPoint(e,n,a,s),s=a;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===M0.Polygon?(e.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=e.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===J0.Round||e.endType===M0.Round){let r=this.arcTolerance>.01?this.arcTolerance:n*x0.arc_const,a=Math.PI/Math.acos(1-r/n);this.stepSin=Math.sin(2*Math.PI/a),this.stepCos=Math.cos(2*Math.PI/a),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=a/(2*Math.PI)}for(let r of e.inPaths){this.pathOut=[];let a=r.length;if(a===1){let s=r[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(r,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let c=s.z||0;if(e.endType===M0.Round){let o=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=x0.ellipse(s,Math.abs(this.groupDelta),Math.abs(this.groupDelta),o),c!==0)for(let i=0;i<this.pathOut.length;i++)this.pathOut[i].z=c}else{let o=Math.ceil(Math.abs(this.groupDelta)),i={left:s.x-o,top:s.y-o,right:s.x+o,bottom:s.y+o};this.pathOut=[{x:i.left,y:i.top,z:c},{x:i.right,y:i.top,z:c},{x:i.right,y:i.bottom,z:c},{x:i.left,y:i.bottom,z:c}]}this.solution.push(this.pathOut);continue}switch(a===2&&e.endType===M0.Joined&&(this.endType=e.joinType===J0.Round?M0.Round:M0.Square),this.buildNormals(r),this.endType){case M0.Polygon:this.offsetPolygon(e,r);break;case M0.Joined:this.offsetOpenJoined(e,r);break;default:this.offsetOpenPath(e,r);break}}}static stripDuplicates(e,n){let r=e.length,a=[];if(r===0)return a;let s=e[0];a.push(s);for(let c=1;c<r;c++)V2.equals(s,e[c])||(s=e[c],a.push(s));return n&&V2.equals(s,a[0])&&a.pop(),a}static area(e){return j1.area(e)}static sqr(e){return e*e}static ellipse(e,n,r=0,a=0){if(n<=0)return[];r<=0&&(r=n),a<=2&&(a=Math.ceil(Math.PI*Math.sqrt((n+r)/2)));let s=Math.sin(2*Math.PI/a),c=Math.cos(2*Math.PI/a),o=c,i=s,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<a;++h){l.push({x:Math.round(e.x+n*o),y:Math.round(e.y+r*i)});let u=o*c-i*s;i=i*c+o*s,o=u}return l}};X(x0,"Tolerance",1e-12),X(x0,"arc_const",.002);var ke=x0;var Au=BigInt(2);function Kt(t,e,n){return typeof e=="number"?Yt(f0.Union,t,null,e):Yt(f0.Union,t,e,n)}function Yt(t,e,n,r){let a=[];if(e===null)return a;let s=new $2;return s.addPaths(e,W0.Subject),n!==null&&s.addPaths(n,W0.Clip),s.execute(t,r,a),a}function I5(t,e,n,r,a=2,s=0){let c=new ke(a,s);c.addPaths(t,n,r);let o=[];return c.execute(e,o),o}var y2=1e4,Jt=[1,0,0,1,0,0];function D0(){return{layers:new Map,parts:[]}}function O0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function H2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function u6(t){if(t.parts.length)return!1;for(let e of t.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var f6=t=>t.map(e=>e.map(([n,r])=>({x:Math.round(n*y2),y:Math.round(r*y2)})));function ds(t){let e=(r,a,s)=>(a.x-r.x)*(s.y-a.y)-(a.y-r.y)*(s.x-a.x)===0,n=[];for(let r of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],r);)n.pop();let a=n[n.length-1];(!a||a.x!==r.x||a.y!==r.y)&&n.push(r)}for(let r=!0;r&&n.length>=3;){let a=n.length;r=!0,n[a-1].x===n[0].x&&n[a-1].y===n[0].y||e(n[a-2],n[a-1],n[0])?n.pop():e(n[a-1],n[0],n[1])?n.shift():r=!1}return n}var F3=t=>f6(t).map(ds),_3=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/y2,n.y/y2]));function t1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?J1.EvenOdd:J1.NonZero;return _3(Kt(F3(t),n)).filter(r=>r.length>=3)}function Qt(t,e,n){if(!e.length)return[];let r=new $2;r.addSubject(F3(e)),n.length&&r.addClip(F3(n));let a=[];return r.execute(t,J1.NonZero,a),_3(a).filter(s=>s.length>=3)}var d0=(t,e)=>e.length?Qt(f0.Difference,t,e):t1(t),G1=(t,e)=>Qt(f0.Intersection,t,e),ze=(t,e)=>Qt(f0.Xor,t,e);function N0(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let r=[];for(let p of e)for(let g=0;g<p.length;g++){let v=p[g],b=p[(g+1)%p.length];(v[0]!==b[0]||v[1]!==b[1])&&r.push([v,b])}if(!r.length)return n==="outside"?t:[];let a=m0(e),s=Math.max(a[2]-a[0],a[3]-a[1],1e-6)/Math.max(1,Math.sqrt(r.length)),c=p=>Math.floor(p/s),o=new Map,i=new Map,l=(p,g,v)=>{let b=p.get(g);b?b[b.length-1]!==v&&b.push(v):p.set(g,[v])};r.forEach(([p,g],v)=>{let b=Math.max(1,Math.ceil(Math.hypot(g[0]-p[0],g[1]-p[1])/s*2));for(let y=0;y<=b;y++){let M=p[0]+(g[0]-p[0])*y/b,w=p[1]+(g[1]-p[1])*y/b;for(let x of[-1,0,1])for(let k of[-1,0,1])l(o,`${c(M)+x},${c(w)+k}`,v)}for(let y=c(Math.min(p[1],g[1]));y<=c(Math.max(p[1],g[1]));y++)l(i,y,v)});let h=(p,g)=>{let v=new Set,b=0,y=1;for(let k of[0,1]){let A=g[k]-p[k],L=a[k]-s,z=a[k+2]+s;if(A===0){if(p[k]<L||p[k]>z)return v;continue}let S=(L-p[k])/A,C=(z-p[k])/A;b=Math.max(b,Math.min(S,C)),y=Math.min(y,Math.max(S,C))}if(!(b<=y))return v;let M=[p[0]+(g[0]-p[0])*b,p[1]+(g[1]-p[1])*b],w=[p[0]+(g[0]-p[0])*y,p[1]+(g[1]-p[1])*y],x=Math.max(1,Math.ceil(Math.hypot(w[0]-M[0],w[1]-M[1])/s*2));for(let k=0;k<=x;k++){let A=M[0]+(w[0]-M[0])*k/x,L=M[1]+(w[1]-M[1])*k/x;for(let z of o.get(`${c(A)},${c(L)}`)??[])v.add(z)}return v},u=.5/y2,f=p=>{for(let v of o.get(`${c(p[0])},${c(p[1])}`)??[]){let[b,y]=r[v],M=y[0]-b[0],w=y[1]-b[1],x=Math.max(0,Math.min(1,((p[0]-b[0])*M+(p[1]-b[1])*w)/(M*M+w*w)));if(Math.hypot(p[0]-b[0]-x*M,p[1]-b[1]-x*w)<=u)return}let g=0;for(let v of i.get(c(p[1]))??[]){let[b,y]=r[v],M=(y[0]-b[0])*(p[1]-b[1])-(p[0]-b[0])*(y[1]-b[1]);b[1]<=p[1]?y[1]>p[1]&&M>0&&g++:y[1]<=p[1]&&M<0&&g--}return g!==0},d=p=>Math.round(p*y2)/y2,m=[];for(let p of t){let g=null,v=()=>{g&&g.length>=2&&m.push(g),g=null};for(let b=1;b<p.length;b++){let y=p[b-1],M=p[b],w=M[0]-y[0],x=M[1]-y[1];if(!w&&!x)continue;let k=[0,1];for(let L of h(y,M)){let[z,S]=r[L],C=S[0]-z[0],E=S[1]-z[1],I=w*E-x*C;if(Math.abs(I)>1e-15){let H=((z[0]-y[0])*E-(z[1]-y[1])*C)/I,T=((z[0]-y[0])*x-(z[1]-y[1])*w)/I;H>0&&H<1&&T>=0&&T<=1&&k.push(H)}else{let H=w*w+x*x;for(let T of[z,S]){let O=((T[0]-y[0])*w+(T[1]-y[1])*x)/H,_=Math.abs((T[0]-y[0])*x-(T[1]-y[1])*w)/Math.sqrt(H);O>0&&O<1&&_<=u&&k.push(O)}}}k.sort((L,z)=>L-z);let A=Math.hypot(w,x);for(let L=1;L<k.length;L++){if((k[L]-k[L-1])*A<1e-9||k[L]-k[L-1]<1e-300)continue;let z=[d(y[0]+w*k[L-1]),d(y[1]+x*k[L-1])],S=[d(y[0]+w*k[L]),d(y[1]+x*k[L])],C=(k[L-1]+k[L])/2,E=f([y[0]+w*C,y[1]+x*C]);if(E!==void 0&&E===(n==="inside")){let I=g?g[g.length-1]:void 0;g&&I&&I[0]===z[0]&&I[1]===z[1]?(S[0]!==I[0]||S[1]!==I[1])&&g.push(S):(v(),g=[z,S])}else v()}}v()}return m}function a0(t,e,n="round",r=.01){if(!t.length)return[];if(e===0)return t1(t);let a=n==="round"?J0.Round:n==="square"?J0.Square:J0.Miter,s=I5(F3(t1(t)),e*y2,a,M0.Polygon,2,r*y2);return _3(s).filter(c=>c.length>=3)}function G2(t,e){if(!t.length||e<=0)return[];let n=I5(f6(t),e/2*y2,J0.Round,M0.Round,2,.01*y2);return _3(n)}function E0(t){if(!t.length)return[];let e=new R3,n=new $2;n.addSubject(F3(t)),n.execute(f0.Union,J1.NonZero,e);let r=[],a=s=>{for(let c=0;c<s.count;c++){let o=s.child(c),i=[o.poly];for(let l=0;l<o.count;l++){let h=o.child(l);i.push(h.poly),a(h)}r.push(_3(i))}};return a(e),r}function q3(t){let e=t.length;if(e<2)return t.map((g,v)=>v);let n=t.map(g=>m0([g])??[0,0,0,0]),r=t.map(g=>Math.abs(z1(g))),a=(g,v)=>{let b=!1;for(let y=0,M=v.length-1;y<v.length;M=y++){let[w,x]=v[M],[k,A]=v[y];x>g[1]!=A>g[1]&&g[0]<w+(g[1]-x)*(k-w)/(A-x)&&(b=!b)}return b},[s,c,o,i]=[1/0,1/0,-1/0,-1/0];for(let g of n)s=Math.min(s,g[0]),c=Math.min(c,g[1]),o=Math.max(o,g[2]),i=Math.max(i,g[3]);let l=Math.max(1,Math.ceil(Math.sqrt(e))),h=Math.max(o-s,1e-9)/l,u=Math.max(i-c,1e-9)/l,f=(g,v,b)=>Math.min(l-1,Math.max(0,Math.floor((g-v)/b))),d=new Map,m=[];n.forEach((g,v)=>{let[b,y]=[f(g[0],s,h),f(g[2],s,h)],[M,w]=[f(g[1],c,u),f(g[3],c,u)];if((y-b+1)*(w-M+1)>16)return m.push(v);for(let x=b;x<=y;x++)for(let k=M;k<=w;k++){let A=x*l+k,L=d.get(A);L?L.push(v):d.set(A,[v])}});let p=t.map((g,v)=>{let b=n[v];if(!g.length)return 0;let y=g[0],M=0,w=d.get(f(y[0],s,h)*l+f(y[1],c,u))??[];for(let x of[...w,...m]){let k=n[x];x===v||!(r[x]>r[v])||k[0]>b[0]||k[1]>b[1]||k[2]<b[2]||k[3]<b[3]||a(y,t[x])&&M++}return M});return t.map((g,v)=>v).sort((g,v)=>p[v]-p[g]||g-v)}function z1(t){let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]+t[n][0])*(t[r][1]-t[n][1]);return-e/2}function We(t){let e=0,n=0,r=0;for(let a of t){if(a.length<3)continue;let[s,c]=a[0];for(let o=0,i=a.length-1;o<a.length;i=o++){let l=a[i][0]-s,h=a[i][1]-c,u=a[o][0]-s,f=a[o][1]-c,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+s*d/2,r+=(h+f)*d/6+c*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,r/e]}}function Xe(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}function se(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function l6(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,r=new Map;for(let[a,s]of t)r.set(a,{regions:s.regions.map(c=>{let o=c.map(i=>se(e,i));return n?o.reverse():o}),lines:s.lines.map(c=>c.map(o=>se(e,o)))});return r}function Se(t,e){return{layers:l6(t.layers,e),parts:t.parts.map(n=>({...n,layers:l6(n.layers,e),...n.bends&&{bends:ms(n,e)},...n.folds&&{folds:n.folds.map(r=>({...r,from:se(e,r.from),to:se(e,r.to)}))},...n.hang&&{hang:{...n.hang,at:se(e,n.hang.at)}}}))}}function ms(t,e){let n=t.bends,[r,,,a,s]=[e[0],e[1],e[2],e[3],e[4]];if(Math.abs(e[1])>1e-9||Math.abs(e[2])>1e-9||!(r!==0&&a!==0))throw new Error(`part "${t.name}" bends along its x, so it can be moved, scaled or mirrored but not turned: turn it with part(rotate = ...) instead`);return n.map(c=>{let[o,i]=c.mirrored?[-c.x1,-c.x0]:[c.x0,c.x1],[l,h]=[r*o+s,r*i+s].sort((m,p)=>m-p),u=!!c.mirrored!=r<0,{mirrored:f,...d}=c;return u?{...d,x0:-h,x1:-l,mirrored:!0}:{...d,x0:l,x1:h}})}function O2(t){let e=D0();for(let n of t){for(let[r,a]of n.layers){let s=e.layers.get(r)??{regions:[],lines:[]};for(let c of a.regions)s.regions.push(c);for(let c of a.lines)s.lines.push(c);e.layers.set(r,s)}for(let r of n.parts)e.parts.push(r)}return e}var a2="\0hidden";function h6(t,e){let n={regions:[],lines:[]};for(let[s,c]of t)if(s!==a2){for(let o of c.regions)n.regions.push(o);for(let o of c.lines)n.lines.push(o)}let r=new Map([[e,n]]),a=t.get(a2);return a&&e!==a2&&r.set(a2,a),r}function D3(t,e){if(t.parts.length&&e!=="guide")throw new Error(`a part cannot go on the ${e} layer as a whole. Put ${e}() inside part() instead.`);return{layers:h6(t.layers,e),parts:t.parts.map(n=>({...n,layers:h6(n.layers,e)}))}}function m0(t){let e=1/0,n=1/0,r=-1/0,a=-1/0;for(let s of t)for(let[c,o]of s)c<e&&(e=c),o<n&&(n=o),c>r&&(r=c),o>a&&(a=o);return e===1/0?null:[e,n,r,a]}function Q0(t,e){let n=[];for(let[r,a]of t)if(!e?.(r))for(let s of[...a.regions,...a.lines])n.push(s);return m0(n)}function V5(t){let e=[...t].sort((s,c)=>s[0]-c[0]||s[1]-c[1]);if(e.length<3)return e;let n=(s,c,o)=>(c[0]-s[0])*(o[1]-s[1])-(c[1]-s[1])*(o[0]-s[0]),r=[];for(let s of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let a=[];for(let s=e.length-1;s>=0;s--){let c=e[s];for(;a.length>=2&&n(a[a.length-2],a[a.length-1],c)<=0;)a.pop();a.push(c)}return a.pop(),r.pop(),r.concat(a)}function d6(t,e,n,r){return t<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/n,t*2*Math.PI/r)),5)}function Ze(t,e,n){let r=[];for(let a=0;a<n;a++){let s=2*Math.PI*a/n;r.push([t*Math.cos(s),e*Math.sin(s)])}return r}function m6(t,e,n,r){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let a=Math.max(1,Math.ceil(r(n)/4)),s=[],c=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[o,i,l]of c)for(let h=0;h<=a;h++){let u=(l+90*h/a)*Math.PI/180;s.push([o+n*Math.cos(u),i+n*Math.sin(u)])}return s}function e4(t,e){let n=t1(t);for(let r=0;r<100;r++){let a=E0(n);if(a.length<=1)return n;let s=o=>o.reduce((i,l)=>i+z1(l),0);a.sort((o,i)=>s(i)-s(o));let c=[];for(let o=1;o<a.length;o++){let i=1/0,l=[0,0],h=[0,0];for(let[y,M]of a[o][0])for(let w=0;w<a.length;w++)if(w!==o)for(let x of a[w])for(let k=0,A=x.length-1;k<x.length;A=k++){let[L,z]=x[A],[S,C]=x[k],E=S-L,I=C-z,H=E*E+I*I,T=H?Math.max(0,Math.min(1,((y-L)*E+(M-z)*I)/H)):0,O=L+T*E,_=z+T*I,D=Math.hypot(y-O,M-_);D<i&&([i,l,h]=[D,[y,M],[O,_]])}if(!Number.isFinite(i))continue;let u=h[0]-l[0],f=h[1]-l[1],d=Math.hypot(u,f);d<1e-9?[u,f]=[0,1]:[u,f]=[u/d,f/d];let[m,p]=[-f*(e/2),u*(e/2)],g=[l[0]-u*(e/2),l[1]-f*(e/2)],v=[h[0]+u*(e/2),h[1]+f*(e/2)],b=[[g[0]-m,g[1]-p],[v[0]-m,v[1]-p],[v[0]+m,v[1]+p],[g[0]+m,g[1]+p]];c.push(z1(b)<0?b.reverse():b)}if(!c.length)return n;n=t1([...n,...c])}return n}function ps(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function p6(t){let{spacing:e,step:n,box:r}=t,a=e/2,s=e,c=new Map,o=[],i=[],l=[],h=[],u=[],f=(C,E)=>Math.floor((C-r[0])/s)*1000003+Math.floor((E-r[1])/s),d=(C,E,I)=>{let H=f(C[0],C[1]),T=o.length;o.push(C[0]),i.push(C[1]),l.push(E),h.push(I);let O=c.get(H);O?O.push(T):c.set(H,[T])},m=Math.ceil(2*e/n)+2,p=(C,E,I=-1,H=0)=>{let T=Math.floor((C[0]-r[0])/s),O=Math.floor((C[1]-r[1])/s);for(let _=T-1;_<=T+1;_++)for(let D=O-1;D<=O+1;D++){let G=c.get(_*1000003+D);if(G)for(let V of G){let U=l[V];if(!(!u[U]&&U!==I)&&!(U===I&&Math.abs(h[V]-H)<m)&&Math.hypot(o[V]-C[0],i[V]-C[1])<E)return!1}}return!0},g=[],v=0,b=Math.ceil(4*(r[2]-r[0]+r[3]-r[1]+e)/n+2*m),y=(C,E)=>{let I=t.dir(C);if(!I)return null;let H=[C[0]+E*I[0]*n/2,C[1]+E*I[1]*n/2],T=t.dir(H)??I;return T[0]*I[0]+T[1]*I[1]<0?null:[C[0]+E*T[0]*n,C[1]+E*T[1]*n]},M=C=>{let E=g.length;u[E]=!1,d(C,E,0);let I=[[],[]];for(let[O,_]of[[0,1],[1,-1]]){let D=C;for(let G=1;G<=b;G++){let V=y(D,_);if(!V)break;let U=_*G;if(!t.inside(V)){I[O].push(V);break}if(!p(V,a,E,U))break;if(I[O].push(V),d(V,E,U),++v>t.maxPoints)throw new Error(`the lines have more than ${t.maxPoints} points: use a larger spacing or step`);t.tick(),D=V}}let H=[...I[1].reverse(),C,...I[0]],T=0;for(let O=1;O<H.length;O++)T+=Math.hypot(H[O][0]-H[O-1][0],H[O][1]-H[O-1][1]);return g.push(H),H.length<2||T<t.minLength?null:(u[E]=!0,H)},w=ps(t.seed),x=[];for(let C=r[0]+e/2;C<r[2];C+=e)for(let E=r[1]+e/2;E<r[3];E+=e)x.push([C+(w()-.5)*e,E+(w()-.5)*e]);for(let C=x.length-1;C>0;C--){let E=Math.floor(w()*(C+1));[x[C],x[E]]=[x[E],x[C]]}let k=[],A=[],L=Math.max(1,Math.round(e/(2*n))),z=C=>{if(!t.inside(C)||!p(C,e)||!t.dir(C))return;let E=M(C);E&&(k.push(E),A.push(E))},S=0;for(;;){for(;A.length;){let C=A.shift();for(let E=0;E<C.length;E+=L){let I=C[Math.max(0,E-1)],H=C[Math.min(C.length-1,E+1)],T=Math.hypot(H[0]-I[0],H[1]-I[1]);if(T===0)continue;let O=-(H[1]-I[1])/T,_=(H[0]-I[0])/T;for(let D of[1,-1])z([C[E][0]+D*O*e,C[E][1]+D*_*e])}}if(S>=x.length)break;z(x[S++])}return k}function g6(t,e,n,r,a,s,c){let o=(g,v)=>t[v*e+g],i=(g,v)=>(v*e+g)*2,l=(g,v)=>(v*e+g)*2+1,h=g=>{let v=g>>1,b=v%e,y=(v-b)/e,M=o(b,y),w=g&1?o(b,y+1):o(b+1,y),x=M===w?.5:(c-M)/(w-M);return g&1?[r+b*s,a+(y+x)*s]:[r+(b+x)*s,a+y*s]},u=new Map,f=(g,v)=>{for(let[b,y]of[[g,v],[v,g]]){let M=u.get(b);M?M.push(y):u.set(b,[y])}};for(let g=0;g+1<n;g++)for(let v=0;v+1<e;v++){let b=o(v,g),y=o(v+1,g),M=o(v+1,g+1),w=o(v,g+1);if(Number.isNaN(b+y+M+w))continue;let x=(b>=c?1:0)|(y>=c?2:0)|(M>=c?4:0)|(w>=c?8:0);if(x===0||x===15)continue;let k=i(v,g),A=l(v+1,g),L=i(v,g+1),z=l(v,g);if(x===5||x===10){let C=(b+y+M+w)/4>=c;x===5===C?(f(k,A),f(z,L)):(f(z,k),f(A,L));continue}let S=[];(x&1)!==(x&2)>>1&&S.push(k),(x&2)>>1!==(x&4)>>2&&S.push(A),(x&4)>>2!==(x&8)>>3&&S.push(L),(x&8)>>3!==(x&1)&&S.push(z),S.length===2&&f(S[0],S[1])}let d=new Set,m=g=>{let v=[h(g)];d.add(g);let b=g;for(;;){let y=(u.get(b)??[]).find(M=>!d.has(M));if(y===void 0)return(u.get(b)??[]).includes(g)&&v.length>2&&v.push(v[0]),v;d.add(y),v.push(h(y)),b=y}},p=[];for(let[g,v]of u)v.length===1&&!d.has(g)&&p.push(m(g));for(let g of u.keys())d.has(g)||p.push(m(g));return p.map(g=>g.filter((v,b)=>b===0||v[0]!==g[b-1][0]||v[1]!==g[b-1][1])).filter(g=>g.length>=2&&!(g.length===2&&g[0][0]===g[1][0]&&g[0][1]===g[1][1]))}function v6(t,e=.001){let n=t.filter(l=>l.length>=2).map(l=>[...l]);if(n.length<2)return n;let r=l=>`${Math.round(l[0]/e)},${Math.round(l[1]/e)}`,a=new Map,s=(l,h)=>{let u=r(l),f=a.get(u);f?f.push(h):a.set(u,[h])};n.forEach((l,h)=>{s(l[0],h),s(l[l.length-1],h)});let c=new Array(n.length).fill(!1),o=l=>r(l[0])===r(l[l.length-1]),i=[];for(let l=0;l<n.length;l++){if(c[l])continue;c[l]=!0;let h=n[l];if(!o(h))for(let u=0;u<2;u++){for(;;){let f=h[h.length-1],d=(a.get(r(f))??[]).find(g=>!c[g]);if(d===void 0)break;c[d]=!0;let m=n[d],p=r(m[0])===r(f)?m:[...m].reverse();if(h=h.concat(p.slice(1)),o(h))break}if(o(h))break;h=h.reverse()}i.push(h)}return gs(i)}function gs(t){let e=t.length;if(e<2)return t;let n=1/0,r=1/0,a=-1/0,s=-1/0;for(let p of t)for(let g of[p[0],p[p.length-1]])n=Math.min(n,g[0]),r=Math.min(r,g[1]),a=Math.max(a,g[0]),s=Math.max(s,g[1]);let c=Math.max((a-n+s-r)/Math.sqrt(e),1e-6),o=p=>Math.floor((p-n)/c),i=p=>Math.floor((p-r)/c),l=o(a)+1,h=i(s)+1,u=new Map;t.forEach((p,g)=>{for(let v of[p[0],p[p.length-1]]){let b=i(v[1])*l+o(v[0]),y=u.get(b);y?y[y.length-1]!==g&&y.push(g):u.set(b,[g])}});let f=new Array(e).fill(!1),d=[],m=[0,0];for(let p=0;p<e;p++){let g=-1,v=1/0,b=!1,y=Math.min(Math.max(o(m[0]),0),l-1),M=Math.min(Math.max(i(m[1]),0),h-1);for(let x=0;x<=Math.max(l,h);x++){for(let k=y-x;k<=y+x;k++)for(let A=M-x;A<=M+x;A++)if(Math.max(Math.abs(k-y),Math.abs(A-M))===x&&!(k<0||A<0||k>=l||A>=h))for(let L of u.get(A*l+k)??[]){if(f[L])continue;let z=t[L],S=Math.hypot(z[0][0]-m[0],z[0][1]-m[1]),C=Math.hypot(z[z.length-1][0]-m[0],z[z.length-1][1]-m[1]);S<v&&([g,v,b]=[L,S,!1]),C<v&&([g,v,b]=[L,C,!0])}if(g>=0&&v<=x*c)break}if(g<0){for(let x=0;x<e;x++)if(!f[x]){g=x;break}}f[g]=!0;let w=b?[...t[g]].reverse():t[g];d.push(w),m=w[w.length-1]}return d}function b6(t){let e=[],n=1/0,r=-1/0;for(let o of t)for(let i=0,l=o.length-1;i<o.length;l=i++)e.push([o[l][0],o[l][1],o[i][0],o[i][1]]),n=Math.min(n,o[i][1]),r=Math.max(r,o[i][1]);if(!e.length)return()=>!1;let a=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),s=(r-n)/a||1,c=Array.from({length:a},()=>[]);return e.forEach(([,o,,i],l)=>{let h=Math.max(0,Math.min(a-1,Math.floor((Math.min(o,i)-n)/s))),u=Math.max(0,Math.min(a-1,Math.floor((Math.max(o,i)-n)/s)));for(let f=h;f<=u;f++)c[f].push(l)}),([o,i])=>{if(i<n||i>r)return!1;let l=0;for(let h of c[Math.max(0,Math.min(a-1,Math.floor((i-n)/s)))]){let[u,f,d,m]=e[h];f<=i?m>i&&(d-u)*(i-f)-(o-u)*(m-f)>0&&l++:m<=i&&(d-u)*(i-f)-(o-u)*(m-f)<0&&l--}return l!==0}}var y6=Math.PI/180;function T1(t,e){let n=new Array(16).fill(0);for(let r=0;r<4;r++)for(let a=0;a<4;a++)for(let s=0;s<4;s++)n[r*4+a]+=t[r*4+s]*e[s*4+a];return n}function $5(t,e){let n=Math.cos(e*y6),r=Math.sin(e*y6);return t===0?[1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1]:t===1?[n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1]:[n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1]}var n4=t=>Math.abs(t)<1e-12?0:t;function R0(t){if(t.matrix)return t.matrix.map(n4);let[e,n,r]=t.rotate,a=T1($5(2,r),T1($5(1,n),$5(0,e)));return a[3]=t.at[0],a[7]=t.at[1],a[11]=t.at[2],a.map(n4)}function W2(t,e,n,r){return[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]]}function N3(t){let[e,n,r]=[t[3],t[7],t[11]],a=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[a[0],a[1],a[2],-(a[0]*e+a[1]*n+a[2]*r),a[3],a[4],a[5],-(a[3]*e+a[4]*n+a[5]*r),a[6],a[7],a[8],-(a[6]*e+a[7]*n+a[8]*r),0,0,0,1]}function H5(t){let[e,n,r,a]=[1/0,1/0,-1/0,-1/0];for(let s of t)for(let[c,o]of s)e=Math.min(e,c),n=Math.min(n,o),r=Math.max(r,c),a=Math.max(a,o);return[e,n,r,a]}function k6(t){let[e,n,r,a]=H5(t.outline),s=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];for(let o of[e,r])for(let i of[n,a])for(let l of[0,t.thickness]){let h=W2(t.matrix,o,i,l);for(let u=0;u<3;u++)s[u]=Math.min(s[u],h[u]),c[u]=Math.max(c[u],h[u])}return[s,c]}function z6(t,e,n=10){let r=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(k6))for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),a[f]=Math.max(a[f],u[f]);let s=e.map(h=>H5(h.outline)),c=s.reduce((h,[u,,f])=>Math.max(h,f-u),a[0]-r[0]),o=0,i=0,l=0;return e.map((h,u)=>{let[f,d,m,p]=s[u];o>0&&o+m-f>c&&(o=0,i+=l+n,l=0);let g=[1,0,0,a[0]+n+o-f,0,1,0,r[1]+i-d,0,0,1,r[2],0,0,0,1];return o+=m-f+n,l=Math.max(l,p-d),{...h,matrix:g.map(n4)}})}var vs=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),Ye=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],O5=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],t4=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],Je=t=>[t[2],t[6],t[10]],x6=t=>[t[3],t[7],t[11]],bs=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[4]*e[0]+t[5]*e[1]+t[6]*e[2],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]];function Ke(t,e,n){let r=n[0]*n[0]+n[1]*n[1],a=[];for(let s of t)for(let c=0,o=s.length-1;c<s.length;o=c++){let i=s[o],l=s[c],h=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=i[0]+(l[0]-i[0])*f-e[0],m=i[1]+(l[1]-i[1])*f-e[1];a.push((d*n[0]+m*n[1])/r)}return a.sort((s,c)=>s-c)}function r4(t,e,n){let r=0,a=0,s=0,c=0,o=0;for(;c+1<t.length&&o+1<e.length;){let i=Math.max(t[c],e[o]),l=Math.min(t[c+1],e[o+1])-i;l>n&&(r+=l,l>s&&(s=l,a=i+l/2)),t[c+1]<e[o+1]?c+=2:o+=2}return{total:r,mid:a,run:s}}function ys(t,e){let[n,r,a]=W2(N3(t.matrix),e[0],e[1],e[2]);if(a<0||a>t.thickness)return!1;let s=!1;for(let c of t.outline)for(let o=0,i=c.length-1;o<c.length;i=o++){let[l,h]=c[i],[u,f]=c[o];h>r!=f>r&&n<l+(u-l)*(r-h)/(f-h)&&(s=!s)}return s}var R5=class{constructor(e=[]){this.parts=e;this.seen=[]}see(e,n){e>0&&this.seen.push([n(),e])}get at(){let e=0,n=[0,0,0];for(let[s,c]of this.seen){for(let o=0;o<3;o++)n[o]+=s[o]*c;e+=c}for(let s=0;s<3;s++)n[s]/=e;if(this.parts.length&&this.parts.every(s=>ys(s,n)))return n;let r=this.seen[0][0],a=1/0;for(let[s]of this.seen){let c=Math.hypot(s[0]-n[0],s[1]-n[1],s[2]-n[2]);c<a&&([r,a]=[s,c])}return r}};function F5(t,e,n,r){let a=t+n,s=e-n;if(s<=a)return{at:[],size:0};let c=Math.max(4,Math.ceil((s-a)/r));return{at:Array.from({length:c},(o,i)=>a+(s-a)*(i+.5)/c),size:(s-a)/c}}function M6(t,e,n){let r=W2(t,e[0],e[1],e[2]),a=bs(t,n);return[[r[0],r[1]],[a[0],a[1]]]}function S6(t,e,n,r,a,s,c,o=!1){let i=Je(t.matrix),l=Je(e.matrix),h=O5(i,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=O5(f,i),m=Ye(l,d),p=x6(t.matrix),g=Ye(l,x6(e.matrix)),v=1/0,b=-1/0;for(let A of e.outline)for(let[L,z]of A)for(let S of[0,e.thickness]){let C=W2(e.matrix,L,z,S),E=Ye(i,[C[0]-p[0],C[1]-p[1],C[2]-p[2]]);E<v&&(v=E),E>b&&(b=E)}let y=F5(Math.max(0,v),Math.min(t.thickness,b),a,s),M=1/0,w=-1/0;for(let A of t.outline)for(let[L,z]of A){let S=W2(t.matrix,L,z,0),C=Ye(d,[S[0]-p[0],S[1]-p[1],S[2]-p[2]]);C<M&&(M=C),C>w&&(w=C)}let x=0,k=new R5([t,e]);for(let A of y.at){let L=t4(p,i,A),z=(g-Ye(l,L))/m,S=(g+e.thickness-Ye(l,L))/m,C=F5(Math.max(M,Math.min(z,S)),Math.min(w,Math.max(z,S)),a,s);for(let E of C.at){let I=t4(L,d,E),[H,T]=M6(n,I,f),[O,_]=M6(r,I,f),D=r4(Ke(t.outline,H,T),Ke(e.outline,O,_),a);if(x+=D.total*y.size*C.size,k.see(D.run,()=>t4(I,f,D.mid)),x>c&&!o)return k.at}}return x>c?k.at:void 0}function A6(t,e,n,r,a,s,c=!1){let o=[0,1,2,3].flatMap(z=>[0,1,2,3].map(S=>{let C=0;for(let E=0;E<4;E++)C+=n[z*4+E]*e.matrix[E*4+S];return C})),i=o[11],l=o[11]+o[10]*e.thickness,h=Math.min(t.thickness,Math.max(i,l))-Math.max(0,Math.min(i,l));if(h<=r)return;let u=Math.max(0,Math.min(i,l))+h/2,f=new R5([t,e]),d=e.outline.map(z=>z.map(([S,C])=>[o[0]*S+o[1]*C+o[3],o[4]*S+o[5]*C+o[7]])),[m,p,g,v]=H5(t.outline),[b,y,M,w]=H5(d),x=F5(Math.max(p,y),Math.min(v,w),r,a),k=0;for(let z of x.at){let S=r4(Ke(t.outline,[0,z],[1,0]),Ke(d,[0,z],[1,0]),r);if(k+=S.total*x.size*h,f.see(S.run,()=>W2(t.matrix,S.mid,z,u)),k>s&&!c)return f.at}let A=F5(Math.max(m,b),Math.min(g,M),r,a),L=0;for(let z of A.at){let S=r4(Ke(t.outline,[z,0],[0,1]),Ke(d,[z,0],[0,1]),r);if(L+=S.total*A.size*h,f.see(S.run,()=>W2(t.matrix,z,S.mid,u)),L>s&&!c)return f.at}return k>s||L>s?f.at:void 0}function L6(t,e=1/0,n=.05,r=.25,a=.1){let s=t.map(k6),c=t.map(h=>N3(h.matrix)),o=t.map((h,u)=>u).sort((h,u)=>s[h][0][0]-s[u][0][0]),i=[],l=0;for(let h=0;h<o.length;h++)for(let u=h+1;u<o.length;u++){let f=o[h],d=o[u];if(s[d][0][0]>=s[f][1][0]-n)break;if(!vs(s[f],s[d],n))continue;if(++l>e)return{found:i,complete:!1};let[m,p]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[c[f],c[d]]:[c[d],c[f]],y=Math.hypot(...O5(Je(m.matrix),Je(p.matrix)))<1e-9?A6(m,p,g,n,r,a):S6(m,p,g,v,n,r,a);y&&i.push([m,p,y])}return{found:i,complete:!0}}function C6(t,e,n=.05,r=.25,a=.1){let s=Math.hypot(...O5(Je(t.matrix),Je(e.matrix)))<1e-9,c=N3(t.matrix);return s?A6(t,e,c,n,r,a,!0):S6(t,e,c,N3(e.matrix),n,r,a,!0)}function U0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var a4=U0(0,0,0);function L0(t){return N3(t)}function P6(t,e,n=t.angle,r=t.x1){let a=r-t.x0;if(!n||!(a>0))return U0(0,0,0);let s=(t.x1-t.x0)/(t.angle*Math.PI/180),c=e/2+s;return T1(U0(t.x0,0,c),T1($5(1,-n),U0(-t.x0-a,0,-c)))}function U3(t){return[...t].sort((e,n)=>e.x0-n.x0)}var _5=t=>t.length>0&&t.every(e=>e.mirrored),w6=[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],xs=t=>T1(w6,T1(t,w6));function s4(t){return U3(t).map(e=>e.mirrored?[-e.x1,-e.x0]:[e.x0,e.x1])}function q5(t,e){let n=[U0(0,0,0)];for(let r of U3(t))n.push(T1(n[n.length-1],P6(r,e)));return _5(t)?n.map(xs):n}function Ae(t,e,n){if(_5(t)){let s=Ae(t.map(({mirrored:c,...o})=>o),e,[-n[0],n[1],n[2]]);return[-s[0],s[1],s[2]]}let r=U3(t),a=q5(r,e);for(let s=r.length-1;s>=0;s--){let c=r[s];if(n[0]>=c.x1)return W2(a[s+1],...n);if(n[0]>c.x0){let o=(n[0]-c.x0)/(c.x1-c.x0),i=T1(a[s],P6(c,e,c.angle*o,n[0]));return W2(i,...n)}}return n}function E6(t,e){let n=_5(t)?-e:e;return U3(t).filter(r=>(r.x0+r.x1)/2<n).length}function Le(t){if(t.folds?.length)return Ce(t.outline,t.folds,t.thickness).map(c=>({...t,outline:c.outline,folds:void 0,matrix:T1(t.matrix,c.matrix)}));if(!t.bends?.length)return[t];let e=U3(t.bends),n=q5(t.bends,t.thickness),r=_5(t.bends),a=1e7,s=[];for(let c=0;c<=e.length;c++){let o=c===0?-a:e[c-1].x1,i=c===e.length?a:e[c].x0;if(!(i>o))continue;let[l,h]=r?[-i,-o]:[o,i],u=[[l,-a],[h,-a],[h,a],[l,a]],f=G1(t.outline,[u]);f.length&&s.push({...t,outline:f,bends:void 0,matrix:T1(t.matrix,n[c])})}return s}function Ms(t,e,n){let r=n*Math.PI/180,[a,s,c]=[Math.cos(r),Math.sin(r),1-Math.cos(r)],[o,i,l]=e,h=[a+o*o*c,o*i*c-l*s,o*l*c+i*s,i*o*c+l*s,a+i*i*c,i*l*c-o*s,l*o*c-i*s,l*i*c+o*s,a+l*l*c];return[h[0],h[1],h[2],t[0]-(h[0]*t[0]+h[1]*t[1]+h[2]*t[2]),h[3],h[4],h[5],t[1]-(h[3]*t[0]+h[4]*t[1]+h[5]*t[2]),h[6],h[7],h[8],t[2]-(h[6]*t[0]+h[7]*t[1]+h[8]*t[2]),0,0,0,1]}var ws=(t,[e,n])=>{let r=!1;for(let a of t)for(let s=0,c=a.length-1;s<a.length;c=s++)a[s][1]>n!=a[c][1]>n&&e<(a[c][0]-a[s][0])*(n-a[s][1])/(a[c][1]-a[s][1])+a[s][0]&&(r=!r);return r};function Ce(t,e,n){let r=e.map(d=>{let[m,p]=[d.to[0]-d.from[0],d.to[1]-d.from[1]],g=Math.hypot(m,p),[v,b]=[m/g,p/g],[y,M]=[-b*.005,v*.005],[w,x]=[[d.from[0]-v*.02,d.from[1]-b*.02],[d.to[0]+v*.02,d.to[1]+b*.02]];return[[w[0]-y,w[1]-M],[x[0]-y,x[1]-M],[x[0]+y,x[1]+M],[w[0]+y,w[1]+M]]}),a=E0(d0(t,r)),s=[];if(!a.length)return s;let c=d=>a.findIndex(m=>ws(m,d)),o=e.map(d=>{let[m,p]=[d.to[0]-d.from[0],d.to[1]-d.from[1]],g=Math.hypot(m,p),[v,b]=[-p/g*.05,m/g*.05],y=[];for(let M=0;M<25;M++){let w=(M+.5)/25,x=[d.from[0]+m*w,d.from[1]+p*w],k=c([x[0]+v,x[1]+b]),A=c([x[0]-v,x[1]-b]);k>=0&&A>=0&&k!==A&&!y.some(([L,z])=>L===k&&z===A)&&y.push([k,A])}return y}),i=d=>d.reduce((m,p)=>m+Math.abs(z1(p)),0),l=c([0,0]);l<0&&(l=a.map(i).reduce((d,m,p,g)=>m>g[d]?p:d,0));let h=a.map(()=>{});h[l]=U0(0,0,0);let u=[l];for(;u.length;){let d=u.shift();e.forEach((m,p)=>o[p].forEach(g=>{if(!g.includes(d))return;let v=g[0]===d?g[1]:g[0];if(h[v])return;let[b,y]=[m.to[0]-m.from[0],m.to[1]-m.from[1]],M=Math.hypot(b,y),w=v===g[0]?1:-1,x=m.angle>0?n:0,k=Ms([m.from[0],m.from[1],x],[b/M,y/M,0],w*m.angle);h[v]=T1(h[d],k),u.push(v)}))}a.forEach((d,m)=>s.push({outline:d,matrix:h[m]??U0(0,0,0)}));let f=e.flatMap((d,m)=>o[m].length?[]:[m]);return f.length&&(s.unused=f),s}function T6(t,e){return t.flatMap(n=>{let r=N0(n.mode==="line"?[...n.lines,...n.regions.map(s=>[...s,s[0]])]:n.lines,e,"inside"),a=n.mode==="fill"?G1(n.regions,e):[];return a.length||r.length?[{...n,regions:a,lines:r}]:[]})}var ks=2e3;function Pe(t,e,n=2){if(!e?.length)return E0(t);let r=1e7,a=1/0,s=-1/0;for(let f of t)for(let[d]of f)a=Math.min(a,d),s=Math.max(s,d);let c=s4(e).map(([f,d])=>[Math.max(f,a),Math.min(d,s)]).filter(([f,d])=>d>f),o=c.reduce((f,[d,m])=>f+(m-d),0),i=Math.max(n,o/ks),l=[];for(let[f,d]of c){let m=Math.max(1,Math.ceil((d-f)/i));for(let p=0;p<=m;p++)l.push(f+(d-f)*p/m)}let h=[-r,...l.sort((f,d)=>f-d),r],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-r],[h[f+1],-r],[h[f+1],r],[h[f],r]];for(let m of E0(G1(t,[d])))u.push(m)}return u}var ce=1e6,B3=.01,oe=t=>z1(t)<0?[...t].reverse():t;function zs(t,e){let n=T1(L0(t.matrix),e.matrix),[r,a]=[n[8],n[9]],s=Math.hypot(r,a);if(s<1e-9)return[];let c=0,o=e.thickness,i=I=>(-n[11]-Math.max(n[10]*c,n[10]*o)+I)/s,l=I=>(t.thickness-n[11]-Math.min(n[10]*c,n[10]*o)-I)/s;if(!(l(B3)>i(B3)))return[];let[h,u]=[r/s,a/s],[f,d]=[-u,h],m=(I,H)=>[[h*I-f*ce,u*I-d*ce],[h*H-f*ce,u*H-d*ce],[h*H+f*ce,u*H+d*ce],[h*I+f*ce,u*I+d*ce]],p=1/0,g=-1/0;for(let I of e.outline)for(let[H,T]of I)for(let O of[c,o]){let _=n[8]*H+n[9]*T+n[10]*O+n[11];_<p&&(p=_),_>g&&(g=_)}if(Math.min(t.thickness,g)-Math.max(0,p)<Math.min(1,t.thickness/2))return[];let v=(I,H)=>G1(e.outline,[oe(m(I,H))]).filter(T=>Math.abs(z1(T))>1e-6),b=I=>{let[H,T]=[1/0,-1/0];for(let O of I)for(let[_,D]of O)for(let G of[c,o]){let V=n[8]*_+n[9]*D+n[10]*G+n[11];H=Math.min(H,V),T=Math.max(T,V)}return Math.min(t.thickness,T)-Math.max(0,H)},y=E0(v(i(B3),l(B3))).filter(I=>b(I)>=Math.min(1,t.thickness/2)-2*B3).flat();if(!y.length)return[];let M=Math.abs(l(0)-i(0))+1,w=I=>{let H=I.map(([_,D])=>[_-h*M,D-u*M]),T=I.map(([_,D])=>[_+h*M,D+u*M]),O=[oe(H),oe(T)];for(let _=0;_<I.length;_++){let D=(_+1)%I.length,G=[H[_],H[D],T[D],T[_]];Math.abs(z1(G))>1e-12&&O.push(oe(G))}return O},x=t1(y.flatMap(w),"nonzero"),k=G1(e.outline,x).filter(I=>Math.abs(z1(I))>1e-6);if(!k.length)return[];let A=I=>([H,T])=>[n[0]*H+n[1]*T+n[2]*I+n[3],n[4]*H+n[5]*T+n[6]*I+n[7]],L=t.thickness,z=(I,H)=>(I-n[11]-n[10]*H)/s,S=[],C=I=>{I.length>=3&&Math.abs(z1(I))>1e-9&&S.push(oe(I))};for(let I of[c,o])for(let H of G1(k,[oe(m(z(0,I),z(L,I)))]))C(H.map(A(I)));for(let I of[0,L])if(Math.abs(n[10])>1e-9){let[H,T]=[z(I,c),z(I,o)].sort((O,_)=>O-_);for(let O of G1(k,[oe(m(H,T))]))C(O.map(([_,D])=>A((I-n[11]-n[8]*_-n[9]*D)/n[10])([_,D])))}else{let H=z(I,0);for(let T of G1(k,[oe(m(H-1e-4,H+1e-4))])){let[O,_]=[1/0,-1/0];for(let[V,U]of T){let J=f*V+d*U;O=Math.min(O,J),_=Math.max(_,J)}if(!(_-O>1e-6))continue;let D=[h*H+f*O,u*H+d*O],G=[h*H+f*_,u*H+d*_];C([A(c)(D),A(c)(G),A(o)(G),A(o)(D)])}}let E=(I,H,T)=>n[8]*I+n[9]*H+n[10]*T+n[11];for(let I of k)for(let H=0;H<I.length;H++){let[T,O]=I[H],[_,D]=I[(H+1)%I.length],G=[[0,c],[1,c],[1,o],[0,o]],V=([U,J])=>E(T+(_-T)*U,O+(D-O)*U,J);for(let[U,J]of[[1,0],[-1,-L]]){let n1=M1=>U*V(M1)>=J,m1=[];for(let M1=0;M1<G.length;M1++){let c1=G[M1],C1=G[(M1+1)%G.length];if(n1(c1)&&m1.push(c1),n1(c1)!==n1(C1)){let h1=U*V(c1)-J,B1=U*V(C1)-J,$=h1/(h1-B1);m1.push([c1[0]+(C1[0]-c1[0])*$,c1[1]+(C1[1]-c1[1])*$])}}if(G=m1,!G.length)break}G.length>=3&&C(G.map(([U,J])=>A(J)([T+(_-T)*U,O+(D-O)*U])))}return S.length?t1(S,"nonzero"):[]}function I6(t,e,n){let r=[];for(let s of e)for(let c of zs(t,s))r.push(c);if(!r.length)return[];let a=E0(G1(t1(r),t.outline)).filter(s=>s.reduce((c,o)=>c+z1(o),0)>1e-4);return a.length?a0(a.flat(),n/2,"miter"):[]}var j3=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],V6=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Ss=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],$6=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},G3={turn:.3,press:-.1};function c4(t){let e=$6(j3(t.to,t.from)),n=j3(t.up,e.map(a=>a*V6(t.up,e)));Math.hypot(...n)<1e-9&&(n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0]);let r=$6(j3(n,e.map(a=>a*V6(n,e))));return{axis:e,u:Ss(r,e),v:r}}function As(t,e){let{u:n,v:r}=c4(t);if(Array.isArray(t.size)){let[c,o]=[t.size[0]/2+e/2,t.size[1]/2+e/2];return[[-c,-o],[c,-o],[c,o],[-c,o]].map(([i,l])=>[n[0]*i+r[0]*l,n[1]*i+r[1]*l,n[2]*i+r[2]*l])}let a=t.size/2+e/2,s=t.sides<12?t.sides:64;return Array.from({length:s},(c,o)=>{let i=2*Math.PI*o/s,[l,h]=[Math.cos(i)*a,Math.sin(i)*a];return[n[0]*h+r[0]*l,n[1]*h+r[1]*l,n[2]*h+r[2]*l]})}function H6(t,e,n){let r=j3(e.to,e.from);if(!(Math.hypot(...r)>1e-9))return;let a=L0(t.matrix),s=i=>[a[0]*i[0]+a[1]*i[1]+a[2]*i[2]+a[3],a[4]*i[0]+a[5]*i[1]+a[6]*i[2]+a[7],a[8]*i[0]+a[9]*i[1]+a[10]*i[2]+a[11]],c=j3(s(r),s([0,0,0]));if(Math.abs(c[2])<.05*Math.hypot(...c))return;let o=[];for(let i of As(e,n)){let l=s([e.from[0]+i[0],e.from[1]+i[1],e.from[2]+i[2]]),h=(0-l[2])/c[2],u=(t.thickness-l[2])/c[2];if(h>u&&([h,u]=[u,h]),h=Math.max(0,h),u=Math.min(1,u),u>h)for(let f of[h,u])o.push([l[0]+c[0]*f,l[1]+c[1]*f])}return o.length>=3?V5(o):void 0}var D5=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Ls=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],O6=t=>[t[2],t[6],t[10]],R6=t=>[t[3],t[7],t[11]];function F6(t,e,n){let r=[];for(let a of t)for(let s=0,c=a.length-1;s<a.length;c=s++){let o=a[c],i=a[s],l=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),h=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]);if(l>0==h>0)continue;let u=l/(l-h);r.push((o[0]+(i[0]-o[0])*u-e[0])*n[0]+(o[1]+(i[1]-o[1])*u-e[1])*n[1])}return r.sort((a,s)=>a-s)}function _6(t,e){for(let n=0;n+1<t.length;n+=2)if(t[n]<=e&&e<=t[n+1])return[t[n],t[n+1]]}function Cs(t,[e,n]){let r=!1;for(let a of t)for(let s=0,c=a.length-1;s<a.length;c=s++){let[o,i]=a[c],[l,h]=a[s];i>n!=h>n&&e<o+(l-o)*(n-i)/(h-i)&&(r=!r)}return r}function q6(t,e,n){let r={a:[],b:[],thin:0},a=O6(t.matrix),s=O6(e.matrix),c=Ls(a,s),o=Math.hypot(...c);if(o<1e-6)return r;let i=Math.abs(D5(a,s)),l=[c[0]/o,c[1]/o,c[2]/o],h=D5(a,R6(t.matrix))+t.thickness/2,u=D5(s,R6(e.matrix))+e.thickness/2,f=D5(a,s),d=1-f*f,m=(h-u*f)/d,p=(u-h*f)/d,g=[m*a[0]+p*s[0],m*a[1]+p*s[1],m*a[2]+p*s[2]],v=z=>{let S=L0(z.matrix);return[[S[0]*g[0]+S[1]*g[1]+S[2]*g[2]+S[3],S[4]*g[0]+S[5]*g[1]+S[6]*g[2]+S[7]],[S[0]*l[0]+S[1]*l[1]+S[2]*l[2],S[4]*l[0]+S[5]*l[1]+S[6]*l[2]]]},[b,y]=v(t),[M,w]=v(e),x=F6(t.outline,b,y),k=F6(e.outline,M,w),A=(e.thickness+t.thickness*i)/o+n,L=(t.thickness+e.thickness*i)/o+n;for(let z=0;z+1<x.length;z+=2)for(let S=0;S+1<k.length;S+=2){let C=Math.max(x[z],k[S]),E=Math.min(x[z+1],k[S+1]);if(!(E-C>.01))continue;let I=(C+E)/2,[H,T]=_6(x,I),[O,_]=_6(k,I),D=Math.max(T-I,I-O)<=Math.max(I-H,_-I),G=(J,n1,m1,M1,c1,C1)=>{let h1=[-m1[1],m1[0]],B1=(o1,p1)=>[n1[0]+m1[0]*(I+c1*o1)+h1[0]*p1,n1[1]+m1[1]*(I+c1*o1)+h1[1]*p1],$=C1+M1+1,B=[B1(0,-M1/2),B1($,-M1/2),B1($,M1/2),B1(0,M1/2)];z1(B)<0&&B.reverse();let a1=B1(Math.min(.01,C1/2),0),b1=E0(G1([B],J.outline)).find(o1=>Cs(o1,a1));if(!(!b1||!(b1.reduce((o1,p1)=>o1+z1(p1),0)>1e-4)))return G1(a0(b1,.05,"miter"),[B])},V=G(t,b,y,A,D?1:-1,D?T-I:I-H),U=G(e,M,w,L,D?-1:1,D?I-O:_-I);if(!V||!U){r.thin++;continue}r.a.push(...V),r.b.push(...U)}return r}var p2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",x2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",N6=t=>typeof t=="number",e2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",s2=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function o4(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)o4(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function N5(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let r=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(r>e)throw new Error(`a range of ${r} items is more than the limit of ${e}`);for(let a=0;a<r;a++)n.push(t.start+a*t.step);return n}function w0(t){return t===void 0||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="number"?!Number.isNaN(t):!0}var D6=(t,e,n)=>p2(t)&&p2(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:e2(t)&&e2(e)?t.fields.size===e.fields.size&&[...t.fields].every(([r,a])=>e.fields.has(r)&&Qe(a,e.fields.get(r),n)):t===e;function Qe(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return D6(t,e,n);let r=new Map,a=[],s=(c,o)=>{let i=r.get(c);return i?.has(o)?!0:c.length!==o.length?!1:(i||r.set(c,i=new Set),i.add(o),a.push([c,o,0]),!0)};if(!s(t,e))return!1;for(;a.length;){let c=a[a.length-1];if(c[2]===c[0].length){a.pop();continue}let o=c[0][c[2]],i=c[1][c[2]++];if(n?.(),Array.isArray(o)&&Array.isArray(i)?!s(o,i):!D6(o,i,n))return!1}return!0}function X0(t){return t===void 0?"undef":Array.isArray(t)?"list":p2(t)?"range":x2(t)?"function":e2(t)?"record":typeof t}function Ps(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?l2(t):p2(t)?`[${l2(t.start)}:${l2(t.step)}:${l2(t.end)}]`:x2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:e2(t)?"{}":String(t)}function e3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let r=[],a=0,s=l=>{r.push(l),a+=l.length},c=[],o=t;for(;;){Array.isArray(o)?(s("["),c.push({items:o,i:0,close:"]"})):e2(o)&&o.fields.size?(s("{"),c.push({items:[...o.fields.values()],keys:[...o.fields.keys()],i:0,close:"}"})):s(Ps(o));let l=!1;for(;c.length&&!l&&a<=e;){let h=c[c.length-1];h.i<h.items.length?(h.i&&s(", "),h.keys&&s(`${h.keys[h.i]} = `),o=h.items[h.i++],l=!0):(c.pop(),s(h.close))}if(!l||a>e)break}let i=r.join("");return a>e?{text:i.slice(0,Math.max(e,0)),whole:!1}:{text:i,whole:!0}}function U6(t,e,n){let r=[],a=0;for(let s of t){r.length&&(a+=e.length);let c=e3(s,n-a);if(!c.whole)return;a+=c.text.length,r.push(c.text)}return r.join(e)}function c0(t){let e=e3(t,200,!0);return e.whole?e.text:e.text+"..."}var k0=t=>typeof t=="string"?t:c0(t);function V0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function l2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function t3(t,e=.02){let n=[],r=[],a=[],s=[0,0],c=[0,0],o=l=>{a.length>=2&&(l?n:r).push(a),a=[]},i=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")o(!1),s=c=[l.x,l.y],a=[c];else if(l.type==="L")c=[l.x,l.y],a.push(c);else if(l.type==="Q"){let[h,u]=c,f=i(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=f;d++){let m=d/f,p=1-m;a.push([p*p*h+2*p*m*l.x1+m*m*l.x,p*p*u+2*p*m*l.y1+m*m*l.y])}c=[l.x,l.y]}else if(l.type==="C"){let[h,u]=c,f=i(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let m=d/f,p=1-m;a.push([p*p*p*h+3*p*p*m*l.x1+3*p*m*m*l.x2+m*m*m*l.x,p*p*p*u+3*p*p*m*l.y1+3*p*m*m*l.y2+m*m*m*l.y])}c=[l.x,l.y]}else o(!0),c=s,a=[s];return o(!1),{closed:n,open:r}}function n3(t,e=Math.PI/2,n){let r=M=>/^[a-zA-Z]$/.test(M),a=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],s=[],c=0,o="",i=0,l=0,h=0,u=0,f=0,d=0,m=0,p=0,g="",v=()=>{let M=a[c++];if(M===void 0||r(M))throw new Error(`Bad path data near "${M??"end"}"`);return Number(M)},b=()=>{let M=a[c];if(M===void 0)throw new Error("Bad path data: missing arc flag");return M.length>1&&(M[0]==="0"||M[0]==="1")&&!M.includes(".")?(a[c]=M.slice(1),Number(M[0])):(c++,Number(M))};try{y()}catch(M){if(!n)throw M;n(M.message)}return s;function y(){for(;c<a.length;){if(r(a[c]))o=a[c++];else if(o){if(o==="Z"||o==="z")throw new Error(`Bad path data near "${a[c]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let M=o===o.toLowerCase(),w=o.toUpperCase(),x=M?i:0,k=M?l:0;if(w==="M")i=x+v(),l=k+v(),h=i,u=l,s.push({type:"M",x:i,y:l}),o=M?"l":"L";else if(w==="L")i=x+v(),l=k+v(),s.push({type:"L",x:i,y:l});else if(w==="H")i=x+v(),s.push({type:"L",x:i,y:l});else if(w==="V")l=k+v(),s.push({type:"L",x:i,y:l});else if(w==="C"||w==="S"){let A,L;if(w==="C")A=x+v(),L=k+v();else{let C=g==="C"||g==="S";A=C?2*i-f:i,L=C?2*l-d:l}let z=x+v(),S=k+v();i=x+v(),l=k+v(),f=z,d=S,s.push({type:"C",x1:A,y1:L,x2:z,y2:S,x:i,y:l})}else if(w==="Q"||w==="T"){let A,L;if(w==="Q")A=x+v(),L=k+v();else{let z=g==="Q"||g==="T";A=z?2*i-m:i,L=z?2*l-p:l}i=x+v(),l=k+v(),m=A,p=L,s.push({type:"Q",x1:A,y1:L,x:i,y:l})}else if(w==="A"){let A=v(),L=v(),z=v(),S=b(),C=b(),E=x+v(),I=k+v();s.push(...Es(i,l,A,L,z,S,C,E,I,e)),i=E,l=I}else if(w==="Z")s.push({type:"Z"}),i=h,l=u;else throw new Error(`Unknown path command "${o}"`);g=w}}}function Es(t,e,n,r,a,s,c,o,i,l=Math.PI/2){if(n===0||r===0||t===o&&e===i)return[{type:"L",x:o,y:i}];n=Math.abs(n),r=Math.abs(r);let h=a*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-o)/2,m=(e-i)/2,p=u*d+f*m,g=-f*d+u*m,v=p*p/(n*n)+g*g/(r*r);v>1&&(n*=Math.sqrt(v),r*=Math.sqrt(v));let b=n*n*r*r-n*n*g*g-r*r*p*p,y=n*n*g*g+r*r*p*p,M=Math.sqrt(Math.max(0,b/y));s===c&&(M=-M);let w=M*n*g/r,x=-M*r*p/n,k=u*w-f*x+(t+o)/2,A=f*w+u*x+(e+i)/2,L=(T,O,_,D)=>Math.atan2(T*D-O*_,T*_+O*D),z=L(1,0,(p-w)/n,(g-x)/r),S=L((p-w)/n,(g-x)/r,(-p-w)/n,(-g-x)/r);!c&&S>0&&(S-=2*Math.PI),c&&S<0&&(S+=2*Math.PI);let C=Math.ceil(Math.abs(S)/l),E=[],I=T=>[k+n*Math.cos(T)*u-r*Math.sin(T)*f,A+n*Math.cos(T)*f+r*Math.sin(T)*u],H=T=>[-n*Math.sin(T)*u-r*Math.cos(T)*f,-n*Math.sin(T)*f+r*Math.cos(T)*u];for(let T=0;T<C;T++){let O=z+S*T/C,_=z+S*(T+1)/C,D=4/3*Math.tan((_-O)/4),G=I(O),V=I(_),U=H(O),J=H(_);E.push({type:"C",x1:G[0]+D*U[0],y1:G[1]+D*U[1],x2:V[0]-D*J[0],y2:V[1]-D*J[1],x:V[0],y:V[1]})}return E}var B0=Math.PI/180;function Z6(t,e,n,r){if(typeof t=="number"&&typeof e=="number")return t-e;if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;if(Array.isArray(t)&&Array.isArray(e)){for(let a=0;a<Math.min(t.length,e.length);a++){r();let s=Z6(t[a],e[a],n,r);if(s)return s}return t.length-e.length}throw new Error(`${n}() can only order numbers, strings or lists of them, not ${X0(t)} and ${X0(e)}`)}function u4(t,e,n){let r=Z0(t,e,n);return(r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.flatMap(s=>Z0(s,e,n)):r).map(s=>{if(!Array.isArray(s)||s.length<2)throw new Error(`${e}() needs points [x, y], got ${X0(s)}`);return[I1(s[0],e),I1(s[1],e)]})}function Ts(t,e,n){let r=Z0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(a=>u4(a,e,n)):[u4(r,e,n)]}var P1=(t,e,n)=>({params:t.replace("...","").split(",").map(r=>r.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function Y6(t,e,n){return t.order?[]:t.params.filter((r,a)=>a<e.length&&n.has(r))}function K6(t,e,n){if(t.rest){let s=[...e];return t.params.forEach((c,o)=>{n.has(c)&&(s[o]=n.get(c))}),s}if(!t.order)return t.params.map((s,c)=>n.has(s)?n.get(s):e[c]);let r=e.length+t.params.filter(s=>n.has(s)).length,a=t.order(r).filter(s=>!n.has(s));return t.params.map(s=>n.has(s)?n.get(s):e[a.indexOf(s)])}function i4(t,e,n,r){let a=U6(t,e,n.maxLength);if(a===void 0)throw new Error(`${r}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(a.length/8)),a}function I1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${X0(t)}`);return t}function Z0(t,e,n){if(Array.isArray(t))return t;if(p2(t))return N5(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${X0(t)}`)}var Is=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function J6(t,e,n){if(Is.has(t))return 0;let r=0;for(let a of e)if(typeof a=="string")r+=a.length;else if(Array.isArray(a))r+=t==="len"?0:a.length;else if(p2(a)&&a.step!==0){let s=Math.floor((a.end-a.start)/a.step)+1;s>0&&(r+=Math.min(s,n+1))}return r}var c2=t=>P1("x",e=>typeof e[0]=="number"?g2(t(e[0])):void 0);function g2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function Q6(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var U5=new Map;function Vs(t){let e=U5.get(t);if(e)return e;let n=Q6(t),r=Array.from({length:256},(a,s)=>s);for(let a=255;a>0;a--){let s=Math.floor(n()*(a+1));[r[a],r[s]]=[r[s],r[a]]}e=new Uint8Array(512);for(let a=0;a<512;a++)e[a]=r[a&255];return U5.size>64&&U5.clear(),U5.set(t,e),e}var l4=t=>t*t*t*(t*(t*6-15)+10);function ie(t,e,n,r){let a=t&15,s=a<8?e:n,c=a<4?n:a===12||a===14?e:r;return((a&1)===0?s:-s)+((a&2)===0?c:-c)}function $s(t,e,n,r){let a=Vs(r),s=Math.floor(t),c=Math.floor(e),o=Math.floor(n);t-=s,e-=c,n-=o;let i=s&255,l=c&255,h=o&255,u=l4(t),f=l4(e),d=l4(n),m=a[i]+l,p=a[m]+h,g=a[m+1]+h,v=a[i+1]+l,b=a[v]+h,y=a[v+1]+h,M=(w,x,k)=>x+w*(k-x);return M(d,M(f,M(u,ie(a[p],t,e,n),ie(a[b],t-1,e,n)),M(u,ie(a[g],t,e-1,n),ie(a[y],t-1,e-1,n))),M(f,M(u,ie(a[p+1],t,e,n-1),ie(a[b+1],t-1,e,n-1)),M(u,ie(a[g+1],t,e-1,n-1),ie(a[y+1],t-1,e-1,n-1))))}function B6(t,e,n){let r=t.length===1&&Array.isArray(t[0])?t[0]:t;if(r.length)return e(r.map(a=>I1(a,n)))}var X3={abs:c2(Math.abs),sign:c2(Math.sign),floor:c2(Math.floor),ceil:c2(Math.ceil),round:c2(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:c2(Math.sqrt),exp:c2(Math.exp),ln:c2(Math.log),log:P1("x, base",(t,e)=>e.given<2?g2(Math.log10(I1(t[0],"log"))):Math.log(I1(t[0],"log"))/Math.log(I1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:c2(t=>Math.sin(t*B0)),cos:c2(t=>Math.cos(t*B0)),tan:c2(t=>Math.tan(t*B0)),asin:c2(t=>Math.asin(t)/B0),acos:c2(t=>Math.acos(t)/B0),atan:c2(t=>Math.atan(t)/B0),atan2:P1("y, x",t=>g2(Math.atan2(I1(t[0],"atan2"),I1(t[1],"atan2"))/B0)),pow:P1("x, y",t=>Math.pow(I1(t[0],"pow"),I1(t[1],"pow"))),min:P1("values...",t=>B6(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:P1("values...",t=>B6(t,e=>e.reduce((n,r)=>r>n?r:n,-1/0),"max")),clamp:P1("x, low, high",t=>Math.min(Math.max(I1(t[0],"clamp"),I1(t[1],"clamp")),I1(t[2],"clamp"))),lerp:P1("a, b, t",t=>{let e=I1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((r,a)=>I1(r,"lerp")+(I1(n[a],"lerp")-I1(r,"lerp"))*e)}return I1(t[0],"lerp")+(I1(t[1],"lerp")-I1(t[0],"lerp"))*e}),norm:P1("v",(t,e)=>Math.sqrt(Z0(t[0],"norm",e).reduce((n,r)=>n+I1(r,"norm")**2,0))),cross:P1("a, b",(t,e)=>{let n=Z0(t[0],"cross",e).map(a=>I1(a,"cross")),r=Z0(t[1],"cross",e).map(a=>I1(a,"cross"));return n.length===2?n[0]*r[1]-n[1]*r[0]:[n[1]*r[2]-n[2]*r[1],n[2]*r[0]-n[0]*r[2],n[0]*r[1]-n[1]*r[0]]}),len:P1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:e2(t[0])?t[0].fields.size:void 0),keys:P1("record",t=>e2(t[0])?[...t[0].fields.keys()]:void 0),merge:P1("a, b",t=>{if(!e2(t[0])||!e2(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:P1("...",(t,e)=>{let n=t.reduce((r,a)=>r+(Array.isArray(a)?a.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(r=>Array.isArray(r)?r:[r])}),reverse:P1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...Z0(t[0],"reverse",e)].reverse()),sort:P1("values, key",(t,e)=>{let n=Z0(t[0],"sort",e),r=t[1],a=n.map(s=>[r===void 0?s:e.apply(r,[s]),s]);return e.step(Math.ceil(n.length*Math.log2(n.length+1))),a.sort((s,c)=>Z6(s[0],c[0],"sort",()=>e.step())).map(([,s])=>s)}),fold:P1("values, initial, fn",(t,e)=>{let n=t[1];for(let r of Z0(t[0],"fold",e))n=e.apply(t[2],[n,r]);return n}),scan:P1("values, initial, fn",(t,e)=>{let n=t[1];return Z0(t[0],"scan",e).map(r=>n=e.apply(t[2],[n,r]))}),bounds:P1("points",(t,e)=>{let n=u4(t[0],"bounds",e);if(!n.length)return;let[r,a,s,c]=[1/0,1/0,-1/0,-1/0];for(let[o,i]of n)r=Math.min(r,o),a=Math.min(a,i),s=Math.max(s,o),c=Math.max(c,i);return[r,a,s,c]}),crossings:P1("points, x, y",(t,e)=>{if(t[1]===void 0==(t[2]===void 0))throw new Error("crossings() needs one of x or y");let n=t[1]===void 0,r=I1(n?t[2]:t[1],"crossings"),a=[];for(let s of Ts(t[0],"crossings",e))for(let c=0,o=s.length-1;c<s.length;o=c++){let[i,l]=n?[s[o][1],s[o][0]]:s[o],[h,u]=n?[s[c][1],s[c][0]]:s[c];i>r!=h>r&&a.push(l+(u-l)*(r-i)/(h-i))}return a.sort((s,c)=>s-c)}),sum:P1("values",(t,e)=>Z0(t[0],"sum",e).reduce((n,r)=>n+I1(r,"sum"),0)),slice:P1("value, start, end",(t,e)=>{let r=(typeof t[0]=="string"?[...t[0]]:Z0(t[0],"slice",e)).slice(I1(t[1]??0,"slice"),t[2]===void 0?void 0:I1(t[2],"slice"));return typeof t[0]=="string"?r.join(""):r}),str:P1("...",(t,e)=>i4(t,"",e,"str")),chr:P1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(I1(e,"chr"))).join("")),ord:P1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:P1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:P1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:P1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:P1("values, separator",(t,e)=>i4(Z0(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:P1("value, list",(t,e)=>{let r=(typeof t[1]=="string"?[...t[1]]:Z0(t[1],"search",e)).findIndex(a=>Qe(a,t[0],e.step));return r<0?void 0:r}),contains:P1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(i4([t[1]],"",e,"contains")):Z0(t[0],"contains",e).some(n=>Qe(n,t[1],e.step))),lookup:P1("x, table",(t,e)=>{let n=I1(t[0],"lookup"),r=Z0(t[1],"lookup",e);if(!r.length)return;let a=r.map(s=>[I1(s[0],"lookup"),I1(s[1],"lookup")]).sort((s,c)=>s[0]-c[0]);if(n<=a[0][0])return a[0][1];for(let s=1;s<a.length;s++)if(n<=a[s][0]){let[c,o]=a[s-1],[i,l]=a[s];return o+(n-c)/(i-c)*(l-o)}return a[a.length-1][1]}),rands:P1("min, max, count, seed",t=>{let e=I1(t[0],"rands"),n=I1(t[1],"rands"),r=I1(t[2],"rands"),a=Q6(t[3]===void 0?1:I1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(r)),1e6)},()=>e+(n-e)*a())}),noise:P1("x, y, z, seed, octaves",t=>{let e,n=0,r=0;if(Array.isArray(t[0])){let h=t[0];e=I1(h[0],"noise"),n=h[1]===void 0?0:I1(h[1],"noise"),r=h[2]===void 0?0:I1(h[2],"noise")}else e=I1(t[0],"noise"),t[1]!==void 0&&(n=I1(t[1],"noise")),t[2]!==void 0&&(r=I1(t[2],"noise"));let a=Math.floor(t[3]===void 0?1:I1(t[3],"noise")),s=t[4]===void 0?1:Math.floor(I1(t[4],"noise"));if(!(s>=1&&s<=8))throw new Error("noise(): octaves must be 1 to 8");let c=0,o=1,i=0,l=1;for(let h=0;h<s;h++)c+=o*$s(e*l+h*.3713,n*l+h*.6271,r*l+h*.1943,a+h*7919),i+=o,o/=2,l*=2;return g2(c/i)}),is_num:P1("value",t=>N6(t[0])&&!Number.isNaN(t[0])),is_string:P1("value",t=>typeof t[0]=="string"),is_bool:P1("value",t=>typeof t[0]=="boolean"),is_list:P1("value",t=>Array.isArray(t[0])),is_record:P1("value",t=>e2(t[0])),is_undef:P1("value",t=>t[0]===void 0),is_function:P1("value",t=>x2(t[0])),type_of:P1("value",t=>X0(t[0])),path_length:P1("points",(t,e)=>{let n=W3(t[0],"path_length",e),r=0;for(let a=1;a<n.length;a++)r+=Math.hypot(n[a][0]-n[a-1][0],n[a][1]-n[a-1][1]);return r}),point_at:P1("points, s",(t,e)=>j6(W3(t[0],"point_at",e),I1(t[1],"point_at")).point),heading_at:P1("points, s",(t,e)=>g2(j6(W3(t[0],"heading_at",e),I1(t[1],"heading_at")).heading)),offset_path:P1("points, d, closed",(t,e)=>{let n=W3(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),r=I1(t[1],"offset_path"),a=t[2]===!0,s=a&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(s&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let c=n.length,o=l=>{let[h,u]=n[l%c],[f,d]=n[(l+1)%c],m=Math.hypot(f-h,d-u);return[-(d-u)/m,(f-h)/m]},i=n.map(([l,h],u)=>{let f=!a&&u===0,d=!a&&u===c-1,m=o(f?0:(u-1+c)%c),p=o(d?c-2:u),[g,v]=[m[0]+p[0],m[1]+p[1]],b=Math.hypot(g,v);if(b<1e-9)[g,v]=m;else{let y=Math.min(2/(b*b),4/b);[g,v]=[g*y,v*y]}return[g2(l+r*g),g2(h+r*v)]});return s?[...i,i[0]]:i}),train_for:P1("ratio, stages, pinion, wheel",(t,e)=>{let n=I1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let r=t[1]===void 0?2:I1(t[1],"train_for");if(!(r===1||r===2||r===3))throw new Error("train_for(): stages must be 1, 2 or 3");let a=(v,b,y)=>{if(v===void 0)return b;if(!Array.isArray(v)||v.length!==2||!v.every(x=>typeof x=="number"))throw new Error(`train_for(): ${y} must be [fewest, most] teeth`);let[M,w]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(M>=6&&w>=M&&w<=400))throw new Error(`train_for(): ${y} teeth must be from 6 to 400, fewest first`);return[M,w]},[s,c]=a(t[2],[10,20],"pinion"),[o,i]=a(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=s;v<=c;v++)for(let b=Math.max(o,v);b<=i;b++)u.push([v,b]);let f,d=v=>{let b=v.reduce((w,[x,k])=>w*k/x,1),y=Math.abs(b/h-1),M=v.reduce((w,[x,k])=>w+x+k,0);(!f||y<f.err-1e-12||Math.abs(y-f.err)<=1e-12&&M<f.teeth)&&(f={stages:v.map(w=>[...w]),err:y,teeth:M})},m=(v,b)=>{e.step();for(let y=s;y<=c;y++)for(let M of[Math.floor(b*y),Math.ceil(b*y)])M>=Math.max(o,y)&&M<=i&&d([...v,[y,M]])};if(r===1)m([],h);else for(let v=0;v<u.length;v++){let b=u[v][1]/u[v][0];if(r===2)m([u[v]],h/b);else for(let y=v;y<u.length;y++)m([u[v],u[y]],h/b/(u[y][1]/u[y][0]))}if(!f)throw new Error(`train_for(): no train of ${r} stages reaches a ratio of ${n}`);let p=f.stages.map(([v,b])=>l?[b,v]:[v,b]),g=p.reduce((v,[b,y])=>v*y/b,1);return{type:"record",fields:new Map([["stages",p],["ratio",g],["error",g/n-1]])}}),path_points:P1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:I1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let r=t3(n3(t[0]),n),a=[...r.closed.map(s=>[...s,s[0]]),...r.open];return e.step(a.reduce((s,c)=>s+c.length,0)),a.map(s=>s.map(([c,o])=>[c,o]))}),spline_points:P1("points, steps, closed",(t,e)=>{let n=W3(t[0],"spline_points",e),r=t[1]===void 0?8:Math.floor(I1(t[1],"spline_points"));if(!(r>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*r>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*r),f4(n,r,t[2]===!0)}),rotation:P1("angles",t=>{let[e,n,r]=h4(t[0],"rotation");return _s(W6(Fs(r),W6(Rs(n),Os(e))))}),euler:P1("matrix",t=>X6(Hs(t[0],"euler"))),orient:P1("x, z",t=>{let e=G6(h4(t[0],"orient"),"orient"),n=h4(t[1]??[0,0,1],"orient"),r=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=G6([n[0]-r*e[0],n[1]-r*e[1],n[2]-r*e[2]],"orient");let a=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return X6([[e[0],a[0],n[0]],[e[1],a[1],n[1]],[e[2],a[2],n[2]]])})};function W3(t,e,n){return Z0(t,e,n).map((a,s)=>{if(!Array.isArray(a)||typeof a[0]!="number"||typeof a[1]!="number")throw new Error(`${e}(): points[${s}] must be an [x, y] point`);return[a[0],a[1]]})}function j6(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([i,l],h)=>h===0||i!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let r=0,a=0;for(;r<n.length-2;r++){let i=Math.hypot(n[r+1][0]-n[r][0],n[r+1][1]-n[r][1]);if(a+i>=e)break;a+=i}let[s,c]=[n[r],n[r+1]],o=(e-a)/Math.hypot(c[0]-s[0],c[1]-s[1]);return{point:[s[0]+(c[0]-s[0])*o,s[1]+(c[1]-s[1])*o],heading:Math.atan2(c[1]-s[1],c[0]-s[0])/B0}}function h4(t,e){if(!Array.isArray(t)||t.length<2||t.length>3||!t.every(n=>typeof n=="number"))throw new Error(`${e}() needs [x, y, z]`);return[t[0],t[1],t[2]??0]}function G6(t,e){let n=Math.hypot(...t);if(!(n>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[t[0]/n,t[1]/n,t[2]/n]}function Hs(t,e){if(!Array.isArray(t)||t.length<3||!t.slice(0,3).every(n=>Array.isArray(n)&&n.length>=3&&n.slice(0,3).every(r=>typeof r=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var Os=t=>{let[e,n]=[Math.cos(t*B0),Math.sin(t*B0)];return[[1,0,0],[0,e,-n],[0,n,e]]},Rs=t=>{let[e,n]=[Math.cos(t*B0),Math.sin(t*B0)];return[[e,0,n],[0,1,0],[-n,0,e]]},Fs=t=>{let[e,n]=[Math.cos(t*B0),Math.sin(t*B0)];return[[e,-n,0],[n,e,0],[0,0,1]]},W6=(t,e)=>t.map(n=>[0,1,2].map(r=>n[0]*e[0][r]+n[1]*e[1][r]+n[2]*e[2][r])),_s=t=>t.map(e=>e.map(g2));function X6(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,r=Math.atan2(-t[0][1],t[1][1])/B0;return[0,n,g2(r)]}return[g2(Math.atan2(t[2][1],t[2][2])/B0),g2(Math.asin(e)/B0),g2(Math.atan2(t[1][0],t[0][0])/B0)]}function f4(t,e,n=!1){if(t.length<3)return t.map(([c,o])=>[c,o]);let r=c=>{if(n)return t[(c%t.length+t.length)%t.length];if(c<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(c>=t.length){let[o,i]=[t[t.length-1],t[t.length-2]];return[2*o[0]-i[0],2*o[1]-i[1]]}return t[c]},a=[],s=n?t.length:t.length-1;for(let c=0;c<s;c++){let[o,i,l,h]=[r(c-1),r(c),r(c+1),r(c+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,m=d*f;a.push([0,1].map(p=>.5*(2*i[p]+(-o[p]+l[p])*f+(2*o[p]-5*i[p]+4*l[p]-h[p])*d+(-o[p]+3*i[p]-3*l[p]+h[p])*m)))}}return a.push(n?a[0]:[t[t.length-1][0],t[t.length-1][1]]),a}function Ee(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var Z3=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function qs(t,e,n,r){if(e==="flat")return[];let a=Ee(t,r),s=t/a,c=[];for(let o=0;o<a;o++)(e==="out"?o%2===1:o%2===0)&&c.push(Z3(o*s,-1,(o+1)*s,n));return c}function B5(t,e,n,r,a){let s=[([i,l])=>[i,l],([i,l])=>[t-l,i],([i,l])=>[t-i,e-l],([i,l])=>[l,e-i]],c=[t,e,t,e],o=[];return n.forEach((i,l)=>{for(let h of qs(c[l],i,r,a))o.push(h.map(s[l]))}),d0([Z3(0,0,t,e)],o)}function e7(t,e,n,r){let a=Ee(t,r),s=t/a,c=[];for(let o=0;o<a;o++)(e==="out"?o%2===0:o%2===1)&&c.push(Z3(o*s,-n/2,(o+1)*s,n/2));return c}function t7(t,e,n,r,a){let s=Z3(-t/2,-1,t/2,e),c=Z3(-n/2,a,n/2,a+r);return[s,c]}function n7(t,e,n,r,a){let s=[],c=a+r,o=Math.floor(t/n),i=(t-o*n)/2;for(let l=0;l<=o;l++){let h=i+l*n,u=l%2===0?r:r-c/2;for(let f=u;f<e;f+=c){let d=Math.max(f,l%2===0?r:0),m=Math.min(f+a,e-(l%2===0?r:0));m-d>=r/2&&s.push([[h,d],[h,m]])}}return s}var t2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var i1=class extends Error{constructor(n,r){super(r?`${n} (${t2(r)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,r&&(this.line=r.line,this.col=r.col,this.file=r.file)}addFrame(n,r,a){let s=this.trace.find(c=>c.name===r&&c.line===a.line&&c.col===a.col&&c.file===a.file);s?s.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:r,line:a.line,col:a.col,...a.file&&{file:a.file},count:1})}},Ds=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function r3(t,e){let n=[],r=[],a=0,s=1,c=0,o=()=>({line:s,col:a-c+1,offset:a,...e&&{file:e}}),i=l=>{for(let h=0;h<l;h++)t[a]===`
6
+ `}},T5=class t extends E5{constructor(n=null){super(n);X(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let r=new t(this);return r.polygon=n,this.children.push(r),r}child(n){if(n<0||n>=this.children.length)throw new Error("Index out of range");return this.children[n]}area(){let n=this.polygon===null?0:Zt.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var F3=class extends T5{};var F=class F{constructor(){X(this,"cliptype",f0.NoClip);X(this,"fillrule",J1.EvenOdd);X(this,"actives",null);X(this,"sel",null);X(this,"minimaList",[]);X(this,"intersectList",[]);X(this,"vertexList",[]);X(this,"outrecList",[]);X(this,"scanlineHeap",new Wt);X(this,"scanlineSet",new Set);X(this,"scanlineArr",[]);X(this,"useScanlineArray",!1);X(this,"horzSegList",[]);X(this,"horzJoinList",[]);X(this,"currentLocMin",0);X(this,"currentBotY",0);X(this,"curXValidAtTop",!1);X(this,"isSortedMinimaList",!1);X(this,"hasOpenPaths",!1);X(this,"usingPolytree",!1);X(this,"succeeded",!1);X(this,"zCallbackInternal");X(this,"preserveCollinear",!0);X(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,r){let a=this.zCallbackInternal;a&&(F.getPolyType(e)===W0.Subject?(this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:r.z=0,a(e.bot,e.top,n.bot,n.top,r)):(this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:r.z=0,a(n.bot,n.top,e.bot,e.top,r)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return F.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return F.openPathsEnabled&&e.localMin.isOpen&&F.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(r0.OpenStart|r0.OpenEnd))!==r0.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!F.openPathsEnabled){for(;n!==null&&!F.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!F.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let r=n.y-e.y;return r!==0?(n.x-e.x)/r:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:j1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=F.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&r0.LocalMax)!==r0.None}static isMaximaEdge(e){return(e.vertexTop.flags&r0.LocalMax)!==r0.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,r,a){let s=e.x<n.x?e.x:n.x;if((r.x>a.x?r.x:a.x)<s)return!1;let o=e.x>n.x?e.x:n.x,i=r.x<a.x?r.x:a.x;if(o<i)return!1;let l=e.y<n.y?e.y:n.y;if((r.y>a.y?r.y:a.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=r.y<a.y?r.y:a.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,r=e.length;n<r;n++){let a=e[n];this.scanlineSet.add(a),this.scanlineHeap.push(a)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let r=0,a=n.length;r<a;r++)if(n[r]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,r=n.length;if(r===0)return null;let a=0,s=n[0];for(let c=1;c<r;c++){let o=n[c];o>s&&(s=o,a=c)}return n[a]=n[r-1],n.pop(),s}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,r=!1){let a=[e];this.addPaths(a,n,r)}addPaths(e,n,r=!1){r&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,Ge.addPathsToVertexList(e,n,r,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new H3(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,r=e.nextInAEL;n===null&&r===null&&e!==this.actives||(n!==null?n.nextInAEL=r:this.actives=r,r!==null&&(r.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let r=n;do r.pt.x<e.left&&(e.left=r.pt.x),r.pt.x>e.right&&(e.right=r.pt.x),r.pt.y<e.top&&(e.top=r.pt.y),r.pt.y>e.bottom&&(e.bottom=r.pt.y),r=r.next;while(r!==n)}return we.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===f0.NoClip)return;F.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let r=this.popScanline();if(r!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(r);let a;for(;(a=this.popHorz())!==null;)this.doHorizontal(a);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=r;let s=this.popScanline();if(s===null)break;for(r=s,this.doIntersections(r),this.doTopOfScanbeam(r);(a=this.popHorz())!==null;)this.doHorizontal(a)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),r;(n.vertex.flags&r0.OpenStart)!==r0.None?r=null:(r=new R3,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=-1,r.vertexTop=n.vertex.prev,r.top=n.vertex.prev.pt,r.outrec=null,r.localMin=n,F.setDx(r));let a;if((n.vertex.flags&r0.OpenEnd)!==r0.None?a=null:(a=new R3,a.bot=n.vertex.pt,a.curX=n.vertex.pt.x,a.windDx=1,a.vertexTop=n.vertex.next,a.top=n.vertex.next.pt,a.outrec=null,a.localMin=n,F.setDx(a)),r!==null&&a!==null){if(F.isHorizontal(r)){if(F.isHeadingRightHorz(r)){let c=r;r=a,a=c}}else if(F.isHorizontal(a)){if(F.isHeadingLeftHorz(a)){let c=r;r=a,a=c}}else if(r.dx<a.dx){let c=r;r=a,a=c}}else r===null&&(r=a,a=null);let s;if(r.isLeftBound=!0,this.insertLeftEdge(r),F.openPathsEnabled?F.isOpen(r)?(this.setWindCountForOpenPathEdge(r),s=this.isContributingOpen(r)):(this.setWindCountForClosedPathEdge(r),s=this.isContributingClosed(r)):(this.setWindCountForClosedPathEdge(r),s=this.isContributingClosed(r)),a!==null){for(a.windCount=r.windCount,a.windCount2=r.windCount2,this.insertRightEdge(r,a),s&&(this.addLocalMinPoly(r,a,r.bot,!0),F.isHorizontal(r)||this.checkJoinLeft(r,r.bot));a.nextInAEL!==null&&this.isValidAelOrder(a.nextInAEL,a);)this.intersectEdges(a,a.nextInAEL,a.bot),this.swapPositionsInAEL(a,a.nextInAEL);F.isHorizontal(a)?this.pushHorz(a):(this.checkJoinRight(a,a.bot),this.insertScanline(a.top.y))}else s&&F.openPathsEnabled&&this.startOpenPath(r,r.bot);F.isHorizontal(r)?this.pushHorz(r):this.insertScanline(r.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!F.openPathsEnabled){this.doHorizontalClosed(e);return}let n=F.isOpen(e),r=e.bot.y,a=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:s,leftX:c,rightX:o}=this.resetHorzDirection(e,a),i=c,l=o;if(F.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:r});this.addToHorzSegList(h)}for(;;){let h=s?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===a){if(F.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),F.isHotEdge(e)){for(;e.vertexTop!==a;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);s?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(a!==e.vertexTop||F.isOpenEnd(e)){if(s&&h.curX>l||!s&&h.curX<i)break;if(h.curX===e.top.x&&!F.isHorizontal(h)){let d=F.nextVertex(e).pt;if(F.isOpen(h)&&!F.isSamePolyType(h,e)&&!F.isHotEdge(h)){if(s&&F.topX(h,d.y)>d.x||!s&&F.topX(h,d.y)<d.x)break}else if(s&&F.topX(h,d.y)>=d.x||!s&&F.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:r};s?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&F.isOpenEnd(e)){F.isHotEdge(e)&&(this.addOutPt(e,e.top),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,a);i=u.leftX,l=u.rightX}if(F.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,r=this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:c}=this.resetHorzDirection(e,r),o=s,i=c;if(F.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=a?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===r){if(F.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),F.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(r!==e.vertexTop){if(a&&l.curX>i||!a&&l.curX<o)break;if(l.curX===e.top.x&&!F.isHorizontal(l)){let f=F.nextVertex(e).pt,d=F.topX(l,f.y);if(a&&d>=f.x||!a&&d<=f.x)break}}let u={x:l.curX,y:n};a?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,r);o=h.leftX,i=h.rightX}if(F.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let r=0,a=e.length;r<a;r++){let s=e[r];this.updateHorzSegment(s)&&(e[n++]=s)}if(!(n<2)){e.length=n,this.horzSegList.sort(ls);for(let r=0;r<n-1;r++){let a=this.horzSegList[r];for(let s=r+1;s<n;s++){let c=this.horzSegList[s];if(c.leftOp.pt.x>=a.rightOp.pt.x||c.leftToRight===a.leftToRight||c.rightOp.pt.x<=a.leftOp.pt.x)continue;let o=a.leftOp.pt.y;if(a.leftToRight){for(;a.leftOp.next.pt.y===o&&a.leftOp.next.pt.x<=c.leftOp.pt.x;)a.leftOp=a.leftOp.next;for(;c.leftOp.prev.pt.y===o&&c.leftOp.prev.pt.x<=a.leftOp.pt.x;)c.leftOp=c.leftOp.prev;let i=new O3(this.duplicateOp(a.leftOp,!0),this.duplicateOp(c.leftOp,!1));this.horzJoinList.push(i)}else{for(;a.leftOp.prev.pt.y===o&&a.leftOp.prev.pt.x<=c.leftOp.pt.x;)a.leftOp=a.leftOp.prev;for(;c.leftOp.next.pt.y===o&&c.leftOp.next.pt.x<=a.leftOp.pt.x;)c.leftOp=c.leftOp.next;let i=new O3(this.duplicateOp(c.leftOp,!0),this.duplicateOp(a.leftOp,!1));this.horzJoinList.push(i)}}}}}updateHorzSegment(e){let n=e.leftOp,r=this.getRealOutRec(n.outrec),a=r.frontEdge!==null,s=n.pt.y,c=n,o=n;if(a){let l=r.pts,h=l.next;for(;c!==h&&c.prev.pt.y===s;)c=c.prev;for(;o!==l&&o.next.pt.y===s;)o=o.next}else{for(;c.prev!==o&&c.prev.pt.y===s;)c=c.prev;for(;o.next!==c&&o.next.pt.y===s;)o=o.next}let i=this.setHorzSegHeadingForward(e,c,o)&&e.leftOp.horz===null;return i?e.leftOp.horz=e:e.rightOp=null,i}setHorzSegHeadingForward(e,n,r){return n.pt.x===r.pt.x?!1:(n.pt.x<r.pt.x?(e.leftOp=n,e.rightOp=r,e.leftToRight=!0):(e.leftOp=r,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let r=new j2(e.pt,e.outrec);return n?(r.next=e.next,r.next.prev=r,r.prev=e,e.next=r):(r.prev=e.prev,r.prev.next=r,r.next=e,e.prev=r),r}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let r=this.actives;for(;r!==null;){if(r.top.y===e)if(r.curX=r.top.x,F.isMaximaEdge(r)){r=this.doMaxima(r);continue}else F.isHotEdge(r)&&this.addOutPt(r,r.top),this.updateEdgeIntoAEL(r),F.isHorizontal(r)&&this.pushHorz(r);else n||(r.curX=F.topX(r,e));r=r.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),r=this.getRealOutRec(e.op2.outrec),a=e.op1.next,s=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,a.prev=s,s.next=a,n===r){let c=this.newOutRec();c.pts=a,this.fixOutRecPts(c),n.pts.outrec===c&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,c.pts)?([c.pts,n.pts]=[n.pts,c.pts],this.fixOutRecPts(n),this.fixOutRecPts(c),c.owner=n):this.path1InsidePath2(c.pts,n.pts)?c.owner=n:c.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(c.idx)):c.owner=n}else r.pts=null,this.usingPolytree?(this.setOwner(r,n),this.moveSplits(r,n)):r.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let r=e0.IsOn,a=e;do{switch(this.pointInOpPolygon(a.pt,n)){case e0.IsOutside:if(r===e0.IsOutside)return!1;r=e0.IsOutside;break;case e0.IsInside:if(r===e0.IsInside)return!0;r=e0.IsInside;break;default:break}a=a.next}while(a!==e);return j1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return e0.IsOutside;let r=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==r);if(n.pt.y===e.y)return e0.IsOutside;let a=n.pt.y<e.y,s=a,c=0;for(r=n.next;r!==n;){if(a)for(;r!==n&&r.pt.y<e.y;)r=r.next;else for(;r!==n&&r.pt.y>e.y;)r=r.next;if(r===n)break;if(r.pt.y===e.y){if(r.pt.x===e.x||r.pt.y===r.prev.pt.y&&e.x<r.prev.pt.x!=e.x<r.pt.x)return e0.IsOn;if(r=r.next,r===n)break;continue}if(r.pt.x<=e.x||r.prev.pt.x<=e.x)if(r.prev.pt.x<e.x&&r.pt.x<e.x)c=1-c;else{let o=j1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return e0.IsOn;o<0===a&&(c=1-c)}a=!a,r=r.next}if(a===s)return c===0?e0.IsOutside:e0.IsInside;{let o=j1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return e0.IsOn;o<0===a&&(c=1-c)}return c===0?e0.IsOutside:e0.IsInside}getCleanPath(e){let n=[],r=e;for(;r.next!==e&&(r.pt.x===r.next.pt.x&&r.pt.x===r.prev.pt.x||r.pt.y===r.next.pt.y&&r.pt.y===r.prev.pt.y);)r=r.next;n.push(r.pt);let a=r;for(r=r.next;r!==e;)(r.pt.x!==r.next.pt.x||r.pt.x!==a.pt.x)&&(r.pt.y!==r.next.pt.y||r.pt.y!==a.pt.y)&&(n.push(r.pt),a=r),r=r.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let r of e.splits)r!==n.idx&&n.splits.push(r);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let r=null;for(;n!==null&&n.jump!==null;){let a=n,s=n.jump,c=s,o=s?.jump||null;for(n.jump=o;n!==c&&s!==o;)if(s.curX<n.curX){let i=s.prevInSEL;for(;this.addNewIntersectNode(i,s,e),i!==n;)i=i.prevInSEL;if(i=s,s=this.extractFromSEL(i),c=s,n!==null&&this.insert1Before2InSEL(i,n),n!==a)continue;a=i,a.jump=o,r===null?this.sel=a:r.jump=a}else n=n.nextInSEL;r=a,n=o}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(hs);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let r=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[r]);)r++;[this.intersectList[r],this.intersectList[e]]=[this.intersectList[e],this.intersectList[r]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let r=Number.NEGATIVE_INFINITY,a=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let s=F.topX(n,e);n.curX=s,s<r&&(a=!0),r=s,n=n.nextInAEL}return a}doMaxima(e){let n=e.prevInAEL,r=e.nextInAEL;if(F.isOpenEnd(e))return F.isHotEdge(e)&&this.addOutPt(e,e.top),F.isHorizontal(e)||(F.isHotEdge(e)&&(F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),r;let a=F.getMaximaPair(e);if(a===null)return r;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(a)&&this.split(a,a.top);r!==a;)this.intersectEdges(e,r,e.top),this.swapPositionsInAEL(e,r),r=e.nextInAEL;return F.isOpen(e)?(F.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(a),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(F.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(e),this.deleteFromAEL(a),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=F.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,F.setDx(e),this.isJoined(e)&&this.split(e,e.bot),F.isHorizontal(e)){F.openPathsEnabled?F.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let r=!1,a=F.nextVertex(e).pt;for(;a.y===e.top.y&&!(n&&a.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=F.nextVertex(e),e.top=a,r=!0,F.isMaximaVertex(e.vertexTop)));)a=F.nextVertex(e).pt;r&&F.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new P5(e))}addNewIntersectNode(e,n,r){let a=j1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(a===null&&(a={x:e.curX,y:r}),a.y>this.currentBotY||a.y<r){let c=Math.abs(e.dx),o=Math.abs(n.dx);c>100&&o>100?c>o?a=j1.getClosestPtOnSegment(a,e.bot,e.top):a=j1.getClosestPtOnSegment(a,n.bot,n.top):c>100?a=j1.getClosestPtOnSegment(a,e.bot,e.top):o>100?a=j1.getClosestPtOnSegment(a,n.bot,n.top):(a.y<r?a.y=r:a.y=this.currentBotY,c<o?a.x=F.topX(e,a.y):a.x=F.topX(n,a.y))}let s=i6(a,e,n);this.intersectList.push(s)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(r0.OpenEnd|r0.LocalMax))===r0.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(r0.OpenEnd|r0.LocalMax))===r0.None;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let r=e.curX,a=e.curX,s=e.nextInAEL;for(;s!==null&&s.vertexTop!==n;)s=s.nextInAEL;return{isLeftToRight:s!==null,leftX:r,rightX:a}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===K0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===J1.EvenOdd){let r=0,a=0;for(;n!==e;)F.getPolyType(n)===W0.Clip?a++:F.isOpen(n)||r++,n=n.nextInAEL;e.windCount=F.isOdd(r)?1:0,e.windCount2=F.isOdd(a)?1:0}else for(;n!==e;)F.getPolyType(n)===W0.Clip?e.windCount2+=n.windDx:F.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,r=F.getPolyType(e);if(!F.openPathsEnabled){for(;n!==null&&F.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===J1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===J1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(F.getPolyType(n)!==r||F.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===J1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=F.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===J1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,r;switch(this.fillrule){case J1.Positive:r=e.windCount>0,n=e.windCount2>0;break;case J1.Negative:r=e.windCount<0,n=e.windCount2<0;break;default:r=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case f0.Intersection:return n;case f0.Union:return!r&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case J1.Positive:if(e.windCount!==1)return!1;break;case J1.Negative:if(e.windCount!==-1)return!1;break;case J1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case f0.Intersection:return this.fillrule===J1.Positive?e.windCount2>0:this.fillrule===J1.Negative?e.windCount2<0:e.windCount2!==0;case f0.Union:return this.fillrule===J1.Positive?e.windCount2<=0:this.fillrule===J1.Negative?e.windCount2>=0:e.windCount2===0;case f0.Difference:{let n=this.fillrule===J1.Positive?e.windCount2<=0:this.fillrule===J1.Negative?e.windCount2>=0:e.windCount2===0;return F.getPolyType(e)===W0.Subject?n:!n}case f0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,r,a=!1){let s=this.newOutRec();if(e.outrec=s,n.outrec=s,F.isOpen(e))s.owner=null,s.isOpen=!0,e.windDx>0?this.setSides(s,e,n):this.setSides(s,n,e);else{s.isOpen=!1;let o=F.getPrevHotEdge(e);o!==null?(this.usingPolytree&&this.setOwner(s,o.outrec),s.owner=o.outrec,this.outrecIsAscending(o)===a?this.setSides(s,n,e):this.setSides(s,e,n)):(s.owner=null,a?this.setSides(s,e,n):this.setSides(s,n,e))}let c=new j2(r,s);return s.pts=c,c}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new C5;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let r=this.newOutRec();r.isOpen=!0,e.windDx>0?(r.frontEdge=e,r.backEdge=null):(r.frontEdge=null,r.backEdge=e),e.outrec=r;let a=new j2(n,r);return r.pts=a,a}checkJoinLeft(e,n,r=!1){let a=e.prevInAEL;a!==null&&(!r&&e.curX!==a.curX||!F.isHotEdge(e)||!F.isHotEdge(a)||F.isHorizontal(e)||F.isHorizontal(a)||F.isOpen(e)||F.isOpen(a)||(n.y<e.top.y+2||n.y<a.top.y+2)&&(e.bot.y>n.y||a.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,a.bot,a.top)||j1.isCollinear(e.top,n,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(a,e,n):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),a.joinWith=K0.Right,e.joinWith=K0.Left))}checkJoinRight(e,n,r=!1){let a=e.nextInAEL;a!==null&&(!r&&e.curX!==a.curX||!F.isHotEdge(e)||!F.isHotEdge(a)||F.isHorizontal(e)||F.isHorizontal(a)||F.isOpen(e)||F.isOpen(a)||(n.y<e.top.y+2||n.y<a.top.y+2)&&(e.bot.y>n.y||a.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,a.bot,a.top)||j1.isCollinear(e.top,n,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(e,a,n):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),e.joinWith=K0.Right,a.joinWith=K0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,r){let a=e.x-n.x,s=e.y-n.y,c=r.x-n.x,o=r.y-n.y;if(c===0&&o===0)return!1;let i=j1.maxCoordForSafeCrossSq;if(Math.abs(a)<i&&Math.abs(s)<i&&Math.abs(c)<i&&Math.abs(o)<i){let h=a*o-c*s;return h*h/(c*c+o*o)>.25}if(Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(c)&&Number.isSafeInteger(o)){let h=BigInt(a)*BigInt(o)-BigInt(c)*BigInt(s),u=h*h,f=BigInt(c)*BigInt(c)+BigInt(o)*BigInt(o);return o6*u>f}let l=a*o-c*s;return l*l/(c*c+o*o)>.25}intersectEdges(e,n,r){let a;if(this.hasOpenPaths&&(F.isOpen(e)||F.isOpen(n))){if(F.isOpen(e)&&F.isOpen(n))return;if(F.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,r),this.cliptype===f0.Union){if(!F.isHotEdge(n))return}else if(n.localMin.polytype===W0.Subject)return;switch(this.fillrule){case J1.Positive:if(n.windCount!==1)return;break;case J1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(F.isHotEdge(e))a=this.addOutPt(e,r),this.setZ(e,n,a.pt),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(r.x===e.localMin.vertex.pt.x&&r.y===e.localMin.vertex.pt.y&&!F.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&F.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}a=this.startOpenPath(e,r)}else a=this.startOpenPath(e,r);this.setZ(e,n,a.pt);return}this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r);let s,c;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===J1.EvenOdd?(s=e.windCount,e.windCount=n.windCount,n.windCount=s):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==J1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==J1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case J1.Positive:s=e.windCount,c=n.windCount;break;case J1.Negative:s=-e.windCount,c=-n.windCount;break;default:s=Math.abs(e.windCount),c=Math.abs(n.windCount);break}let o=s===0||s===1,i=c===0||c===1;if(!(!F.isHotEdge(e)&&!o||!F.isHotEdge(n)&&!i))if(F.isHotEdge(e)&&F.isHotEdge(n))if(s!==0&&s!==1||c!==0&&c!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==f0.Xor)a=this.addLocalMaxPoly(e,n,r),a&&this.setZ(e,n,a.pt);else if(F.isFront(e)||e.outrec===n.outrec){a=this.addLocalMaxPoly(e,n,r),a&&this.setZ(e,n,a.pt);let l=this.addLocalMinPoly(e,n,r);this.setZ(e,n,l.pt)}else{a=this.addOutPt(e,r),this.setZ(e,n,a.pt);let l=this.addOutPt(n,r);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(F.isHotEdge(e))a=this.addOutPt(e,r),this.setZ(e,n,a.pt),this.swapOutrecs(e,n);else if(F.isHotEdge(n))a=this.addOutPt(n,r),this.setZ(e,n,a.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case J1.Positive:l=e.windCount2,h=n.windCount2;break;case J1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!F.isSamePolyType(e,n))a=this.addLocalMinPoly(e,n,r),this.setZ(e,n,a.pt);else if(s===1&&c===1){switch(a=null,this.cliptype){case f0.Union:if(l>0&&h>0)return;a=this.addLocalMinPoly(e,n,r);break;case f0.Difference:(F.getPolyType(e)===W0.Clip&&l>0&&h>0||F.getPolyType(e)===W0.Subject&&l<=0&&h<=0)&&(a=this.addLocalMinPoly(e,n,r));break;case f0.Xor:a=this.addLocalMinPoly(e,n,r);break;default:if(l<=0||h<=0)return;a=this.addLocalMinPoly(e,n,r);break}a&&this.setZ(e,n,a.pt)}}}swapPositionsInAEL(e,n){let r=n.nextInAEL;r!==null&&(r.prevInAEL=e);let a=e.prevInAEL;a!==null&&(a.nextInAEL=n),n.prevInAEL=a,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=r,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let r=j1.crossProductSign(e.top,n.bot,n.top);if(r!==0)return r<0;if(!F.isMaximaEdge(e)&&e.top.y>n.top.y)return j1.crossProductSign(n.bot,e.top,F.nextVertex(e).pt)<=0;if(!F.isMaximaEdge(n)&&n.top.y>e.top.y)return j1.crossProductSign(n.bot,n.top,F.nextVertex(n).pt)>=0;let a=n.bot.y,s=n.isLeftBound;return e.bot.y!==a||e.localMin.vertex.pt.y!==a?n.isLeftBound:e.isLeftBound!==s?s:j1.isCollinear(F.prevPrevVertex(e).pt,e.bot,e.top)?!0:j1.crossProductSign(F.prevPrevVertex(e).pt,n.bot,F.prevPrevVertex(n).pt)>0===s}isJoined(e){return e.joinWith!==K0.None}split(e,n){e.joinWith===K0.Right?(e.joinWith=K0.None,e.nextInAEL.joinWith=K0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=K0.None,e.prevInAEL.joinWith=K0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,r){e.frontEdge=n,e.backEdge=r}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let r=e.outrec,a=F.isFront(e),s=r.pts,c=s.next;if(a&&n.x===s.pt.x&&n.y===s.pt.y)return s;if(!a&&n.x===c.pt.x&&n.y===c.pt.y)return c;let o=new j2(n,r);return c.prev=o,o.prev=s,o.next=c,s.next=o,a&&(r.pts=o),o}addLocalMaxPoly(e,n,r){if(this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r),F.isFront(e)===F.isFront(n))if(F.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(F.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let a=this.addOutPt(e,r);if(e.outrec===n.outrec){let s=e.outrec;if(s.pts=a,this.usingPolytree){let c=F.getPrevHotEdge(e);c===null?s.owner=null:this.setOwner(s,c.outrec)}this.uncoupleOutRec(e)}else F.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return a}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let r=n;for(;r!==null&&r!==e;)r=r.owner;r!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let r=e.outrec.pts,a=n.outrec.pts,s=r.next,c=a.next;F.isFront(e)?(c.prev=r,r.next=c,a.next=s,s.prev=a,e.outrec.pts=a,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(s.prev=a,a.next=s,r.next=c,c.prev=r,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),F.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let r=e.outrec,a=n.outrec;if(r===a){let s=r.frontEdge;r.frontEdge=r.backEdge,r.backEdge=s;return}r!==null&&(e===r.frontEdge?r.frontEdge=n:r.backEdge=n),a!==null&&(n===a.frontEdge?a.frontEdge=e:a.backEdge=e),e.outrec=a,n.outrec=r}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(F.ptsReallyClose(e.prev.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,r,a){if(e===null||e.next===e||!r&&e.next===e.prev)return!1;a.length=0;let s,c;for(n?(s=e.pt,c=e.prev):(e=e.next,s=e.pt,c=e.next),a.push(s);c!==e;)c.pt.x===s.x&&c.pt.y===s.y||(s=c.pt,a.push(s)),n?c=c.prev:c=c.next;return a.length!==3||r||!F.isVerySmallTriangle(c)}buildPaths(e,n){e.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let a=this.outrecList[r++];if(a.pts===null)continue;let s=[];a.isOpen?F.buildPath(a.pts,this.reverseSolution,!0,s)&&n.push(s):(this.cleanCollinear(a),F.buildPath(a.pts,this.reverseSolution,!1,s)&&e.push(s))}return!0}buildTree(e,n){e.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let a=this.outrecList[r++];if(a.pts!==null){if(a.isOpen){let s=[];F.buildPath(a.pts,this.reverseSolution,!0,s)&&n.push(s);continue}this.checkBounds(a)&&this.recursiveCheckOwners(a,e)}}}checkBounds(e){return e.pts===null?!1:we.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!F.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=j1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||we.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,r=n;for(;;){if(r!==null&&j1.isCollinear(r.prev.pt,r.pt,r.next.pt)&&(r.pt.x===r.prev.pt.x&&r.pt.y===r.prev.pt.y||r.pt.x===r.next.pt.x&&r.pt.y===r.next.pt.y||!this.preserveCollinear||j1.dotProductSign(r.prev.pt,r.pt,r.next.pt)<0)){if(r===e.pts&&(e.pts=r.prev),r=this.disposeOutPt(r),!this.isValidClosedPath(r)){e.pts=null;return}n=r;continue}if(r===null||(r=r.next,r===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!F.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&j1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let r=n.prev,a=n.next.next;e.pts=r;let s=j1.getLineIntersectPt(r.pt,n.pt,n.next.pt,a.pt);this.zCallbackInternal&&this.zCallbackInternal(r.pt,n.pt,n.next.pt,a.pt,s);let c=F.areaOutPt(r),o=c<V3?-c:c;if(o<o6){e.pts=null;return}let i=this.areaTriangle(s,n.pt,n.next.pt),l=i<V3?-i:i;if(s.x===r.pt.x&&s.y===r.pt.y||s.x===a.pt.x&&s.y===a.pt.y)a.prev=r,r.next=a;else{let f=new j2(s,e);f.prev=r,f.next=a,a.prev=f,r.next=f}if(!(l>is)||!(l>o)&&i>V3!=c>V3)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new j2(s,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(r,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=j1.maxCoordForSafeAreaProduct,r=0,a=!0,s=e;do{let o=s.prev,i=s.pt;if(Math.abs(o.pt.x)>=n||Math.abs(o.pt.y)>=n||Math.abs(i.x)>=n||Math.abs(i.y)>=n){a=!1;break}r+=(o.pt.y+i.y)*(o.pt.x-i.x),s=s.next}while(s!==e);if(a)return BigInt(Math.round(r));let c=V3;s=e;do{let o=s.prev;if(Number.isSafeInteger(o.pt.y)&&Number.isSafeInteger(s.pt.y)&&Number.isSafeInteger(o.pt.x)&&Number.isSafeInteger(s.pt.x)){let i=BigInt(o.pt.y)+BigInt(s.pt.y),l=BigInt(o.pt.x)-BigInt(s.pt.x);c+=i*l}else{let i=o.pt.y+s.pt.y,l=o.pt.x-s.pt.x;c+=BigInt(Math.round(i*l))}s=s.next}while(s!==e);return c}areaTriangle(e,n,r){let a=j1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<a&&Math.abs(e.y)<a&&Math.abs(n.x)<a&&Math.abs(n.y)<a&&Math.abs(r.x)<a&&Math.abs(r.y)<a){let c=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(c))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(r.y)){let c=(BigInt(r.y)+BigInt(e.y))*(BigInt(r.x)-BigInt(e.x)),o=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),i=(BigInt(n.y)+BigInt(r.y))*(BigInt(n.x)-BigInt(r.x));return c+o+i}let s=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(s))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let r=0;r<n.length;r++){let a=this.outrecList[n[r]];if(a.pts===null&&a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(a=this.getRealOutRec(a),!(a===null||a===e||a.recursiveSplit===e)){if(a.recursiveSplit=e,a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(!(!this.checkBounds(a)||!this.containsRect(a.bounds,e.bounds)||!this.path1InsidePath2(e.pts,a.pts)))return this.isValidOwner(e,a)||(a.owner=e.owner),e.owner=a,!0}}return!1}};X(F,"openPathsEnabled",!0);var I5=F,$2=class extends I5{constructor(){super(...arguments);X(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,r,a=!1){super.addPath(n,r,a)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,r,a=!1){super.addPaths(n,r,a)}addSubject(n){this.addPaths(n,W0.Subject)}addOpenSubject(n){this.addPaths(n,W0.Subject,!0)}addClip(n){this.addPaths(n,W0.Clip)}execute(n,r,a,s){if(Array.isArray(a)){let c=a,o=s;c.length=0,o&&(o.length=0);try{this.executeInternal(n,r),this.buildPaths(c,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let c=a,o=s;c.clear(),o&&(o.length=0),this.usingPolytree=!0;try{this.executeInternal(n,r),this.buildTree(c,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var Zt={area(t){return j1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let r=t[n-1];for(let a of t)e+=(r.y+a.y)*(r.x-a.x),r=a;return e*.5},scalePath64(t,e){let n=j1.maxSafeCoordinateForScale(e),r=[];for(let a of t)j1.checkSafeScaleValue(a.x,n,"scalePath64"),j1.checkSafeScaleValue(a.y,n,"scalePath64"),r.push({x:Math.round(a.x*e),y:Math.round(a.y*e)});return r},scalePaths64(t,e){let n=[];for(let r of t)n.push(Zt.scalePath64(r,e));return n},scalePathD(t,e){let n=[];for(let r of t)n.push({x:r.x*e,y:r.y*e});return n},scalePathsD(t,e){let n=[];for(let r of t)n.push(Zt.scalePathD(r,e));return n}};var J0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(J0||(J0={}));var M0;(function(t){t[t.Polygon=0]="Polygon",t[t.Joined=1]="Joined",t[t.Butt=2]="Butt",t[t.Square=3]="Square",t[t.Round=4]="Round"})(M0||(M0={}));var Yt=class{constructor(e,n,r=M0.Polygon){X(this,"inPaths");X(this,"joinType");X(this,"endType");X(this,"pathsReversed");X(this,"lowestPathIdx");this.joinType=n,this.endType=r;let a=r===M0.Polygon||r===M0.Joined;this.inPaths=[];for(let s of e)this.inPaths.push(ke.stripDuplicates(s,a));if(r===M0.Polygon){let s=ke.getLowestPathInfo(this.inPaths);this.lowestPathIdx=s.idx,this.pathsReversed=this.lowestPathIdx>=0&&s.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},x0=class x0{constructor(e=2,n=0,r=!1,a=!1){X(this,"groupList",[]);X(this,"pathOut",[]);X(this,"normals",[]);X(this,"solution",[]);X(this,"solutionTree",null);X(this,"groupDelta",0);X(this,"delta",0);X(this,"mitLimSqr",0);X(this,"stepsPerRad",0);X(this,"stepSin",0);X(this,"stepCos",0);X(this,"joinType",J0.Bevel);X(this,"endType",M0.Polygon);X(this,"arcTolerance",0);X(this,"mergeGroups",!0);X(this,"miterLimit",2);X(this,"preserveCollinear",!1);X(this,"reverseSolution",!1);X(this,"zCallback");X(this,"deltaCallback",null);X(this,"ZCB",(e,n,r,a,s)=>{(e.z||0)!==0&&(e.z===r.z||e.z===a.z)?s.z=e.z:(r.z||0)!==0&&r.z===n.z?s.z=r.z:(n.z||0)!==0&&n.z===a.z?s.z=n.z:this.zCallback&&this.zCallback(e,n,r,a,s)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=r,this.reverseSolution=a}clear(){this.groupList.length=0}addPath(e,n,r){if(e.length===0)return;let a=[e];this.addPaths(a,n,r)}addPaths(e,n,r){e.length!==0&&this.groupList.push(new Yt(e,n,r))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===M0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===M0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let s of this.groupList)for(let c of s.inPaths)this.solution.push(c);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/x0.sqr(this.miterLimit);for(let s of this.groupList)this.doGroupOffset(s);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),r=n?J1.Negative:J1.Positive,a=new $2;a.preserveCollinear=this.preserveCollinear,a.reverseSolution=this.reverseSolution!==n,a.zCallback=this.ZCB,a.addSubject(this.solution),this.solutionTree!==null?a.execute(f0.Union,r,this.solutionTree):a.execute(f0.Union,r,this.solution)}execute(e,n){if(Array.isArray(n)){let r=n;r.length=0,this.solution=r,this.executeInternal(e)}else{let r=n;r.clear(),this.solutionTree=r,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let r=n.x-e.x,a=n.y-e.y;if(r===0&&a===0)return{x:0,y:0};let s=1/Math.sqrt(r*r+a*a);return{x:a*s,y:-r*s}}static getLowestPathInfo(e){let n=-1,r=!1,a={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let s=0;s<e.length;++s){let c=Number.MAX_VALUE;for(let o of e[s])if(!(o.y<a.y||o.y===a.y&&o.x>=a.x)){if(c===Number.MAX_VALUE){if(c=x0.area(e[s]),c===0)break;r=c<0}n=s,a.x=o.x,a.y=o.y}}return{idx:n,isNegArea:r}}static translatePoint(e,n,r){return{x:e.x+n,y:e.y+r,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=x0.hypotenuse(e.x,e.y);if(x0.almostZero(n))return{x:0,y:0};let r=1/n;return{x:e.x*r,y:e.y*r}}static getAvgUnitVector(e,n){return x0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,r,a){if(j1.isAlmostZero(e.x-n.x)){if(j1.isAlmostZero(r.x-a.x))return{x:0,y:0};let s=(a.y-r.y)/(a.x-r.x),c=r.y-s*r.x;return{x:e.x,y:s*e.x+c}}if(j1.isAlmostZero(r.x-a.x)){let s=(n.y-e.y)/(n.x-e.x),c=e.y-s*e.x;return{x:r.x,y:s*r.x+c}}else{let s=(n.y-e.y)/(n.x-e.x),c=e.y-s*e.x,o=(a.y-r.y)/(a.x-r.x),i=r.y-o*r.x;if(j1.isAlmostZero(s-o))return{x:0,y:0};let l=(i-c)/(s-o);return{x:l,y:s*l+c}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,r){let a,s,c=e[n].z||0;if(n===r){let o=Math.abs(this.groupDelta);a={x:Math.round(e[n].x-o*this.normals[n].x),y:Math.round(e[n].y-o*this.normals[n].y),z:c},s={x:Math.round(e[n].x+o*this.normals[n].x),y:Math.round(e[n].y+o*this.normals[n].y),z:c}}else a={x:Math.round(e[n].x+this.groupDelta*this.normals[r].x),y:Math.round(e[n].y+this.groupDelta*this.normals[r].y),z:c},s={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:c};this.pathOut.push(a),this.pathOut.push(s)}doSquare(e,n,r){let a;n===r?a={x:this.normals[n].y,y:-this.normals[n].x}:a=x0.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let s=Math.abs(this.groupDelta),c={x:e[n].x,y:e[n].y,z:e[n].z||0};c=x0.translatePoint(c,s*a.x,s*a.y);let o=x0.translatePoint(c,this.groupDelta*a.y,this.groupDelta*-a.x),i=x0.translatePoint(c,this.groupDelta*-a.y,this.groupDelta*a.x),l=this.getPerpendicD(e[r],this.normals[r]);if(n===r){let h={x:l.x+a.x*this.groupDelta,y:l.y+a.y*this.groupDelta},u=x0.intersectPoint(o,i,l,h);u.z=c.z,this.pathOut.push(V2.fromPointD(x0.reflectPoint(u,c))),this.pathOut.push(V2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[r]),u=x0.intersectPoint(o,i,l,h);u.z=c.z,this.pathOut.push(V2.fromPointD(u)),this.pathOut.push(V2.fromPointD(x0.reflectPoint(u,c)))}}doMiter(e,n,r,a){let s=this.groupDelta/(a+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[r].x+this.normals[n].x)*s),y:Math.round(e[n].y+(this.normals[r].y+this.normals[n].y)*s),z:e[n].z||0})}doRound(e,n,r,a){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*x0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let s=e[n],c=s.z||0,o={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&L5.negate(o),this.pathOut.push({x:Math.round(s.x+o.x),y:Math.round(s.y+o.y),z:c});let i=Math.ceil(this.stepsPerRad*Math.abs(a));for(let l=1;l<i;l++)o={x:o.x*this.stepCos-this.stepSin*o.y,y:o.x*this.stepSin+o.y*this.stepCos},this.pathOut.push({x:Math.round(s.x+o.x),y:Math.round(s.y+o.y),z:c});this.pathOut.push(this.getPerpendic(e[n],this.normals[n]))}buildNormals(e){let n=e.length;if(this.normals.length=0,n!==0){for(let r=0;r<n-1;r++)this.normals.push(x0.getUnitNormal(e[r],e[r+1]));this.normals.push(x0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,r,a){if(V2.equals(n[r],n[a]))return;let s=j1.crossProductD(this.normals[r],this.normals[a]),c=j1.dotProductD(this.normals[r],this.normals[a]);if(s>1?s=1:s<-1&&(s=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,a),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<x0.Tolerance){this.pathOut.push(n[r]);return}if(c>-.999&&s*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[a])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(c>.999&&this.joinType!==J0.Round)this.doMiter(n,r,a,c);else switch(this.joinType){case J0.Miter:c>this.mitLimSqr-1?this.doMiter(n,r,a,c):this.doSquare(n,r,a);break;case J0.Round:this.doRound(n,r,a,Math.atan2(s,c));break;case J0.Bevel:this.doBevel(n,r,a);break;default:this.doSquare(n,r,a);break}}offsetPolygon(e,n){this.pathOut=[];let r=n.length,a=r-1;for(let s=0;s<r;s++)this.offsetPoint(e,n,s,a),a=s;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let r=[...n].reverse();this.buildNormals(r),this.offsetPolygon(e,r)}offsetOpenPath(e,n){this.pathOut=[];let r=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<x0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case M0.Butt:this.doBevel(n,0,0);break;case M0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let a=1,s=0;a<r;a++)this.offsetPoint(e,n,a,s),s=a;for(let a=r;a>0;a--)this.normals[a]={x:-this.normals[a-1].x,y:-this.normals[a-1].y};if(this.normals[0]=this.normals[r],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,r)),Math.abs(this.groupDelta)<x0.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case M0.Butt:this.doBevel(n,r,r);break;case M0.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let a=r-1,s=r;a>0;a--)this.offsetPoint(e,n,a,s),s=a;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===M0.Polygon?(e.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=e.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===J0.Round||e.endType===M0.Round){let r=this.arcTolerance>.01?this.arcTolerance:n*x0.arc_const,a=Math.PI/Math.acos(1-r/n);this.stepSin=Math.sin(2*Math.PI/a),this.stepCos=Math.cos(2*Math.PI/a),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=a/(2*Math.PI)}for(let r of e.inPaths){this.pathOut=[];let a=r.length;if(a===1){let s=r[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(r,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let c=s.z||0;if(e.endType===M0.Round){let o=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=x0.ellipse(s,Math.abs(this.groupDelta),Math.abs(this.groupDelta),o),c!==0)for(let i=0;i<this.pathOut.length;i++)this.pathOut[i].z=c}else{let o=Math.ceil(Math.abs(this.groupDelta)),i={left:s.x-o,top:s.y-o,right:s.x+o,bottom:s.y+o};this.pathOut=[{x:i.left,y:i.top,z:c},{x:i.right,y:i.top,z:c},{x:i.right,y:i.bottom,z:c},{x:i.left,y:i.bottom,z:c}]}this.solution.push(this.pathOut);continue}switch(a===2&&e.endType===M0.Joined&&(this.endType=e.joinType===J0.Round?M0.Round:M0.Square),this.buildNormals(r),this.endType){case M0.Polygon:this.offsetPolygon(e,r);break;case M0.Joined:this.offsetOpenJoined(e,r);break;default:this.offsetOpenPath(e,r);break}}}static stripDuplicates(e,n){let r=e.length,a=[];if(r===0)return a;let s=e[0];a.push(s);for(let c=1;c<r;c++)V2.equals(s,e[c])||(s=e[c],a.push(s));return n&&V2.equals(s,a[0])&&a.pop(),a}static area(e){return j1.area(e)}static sqr(e){return e*e}static ellipse(e,n,r=0,a=0){if(n<=0)return[];r<=0&&(r=n),a<=2&&(a=Math.ceil(Math.PI*Math.sqrt((n+r)/2)));let s=Math.sin(2*Math.PI/a),c=Math.cos(2*Math.PI/a),o=c,i=s,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<a;++h){l.push({x:Math.round(e.x+n*o),y:Math.round(e.y+r*i)});let u=o*c-i*s;i=i*c+o*s,o=u}return l}};X(x0,"Tolerance",1e-12),X(x0,"arc_const",.002);var ke=x0;var Au=BigInt(2);function Jt(t,e,n){return typeof e=="number"?Kt(f0.Union,t,null,e):Kt(f0.Union,t,e,n)}function Kt(t,e,n,r){let a=[];if(e===null)return a;let s=new $2;return s.addPaths(e,W0.Subject),n!==null&&s.addPaths(n,W0.Clip),s.execute(t,r,a),a}function V5(t,e,n,r,a=2,s=0){let c=new ke(a,s);c.addPaths(t,n,r);let o=[];return c.execute(e,o),o}var y2=1e4,Qt=[1,0,0,1,0,0];function D0(){return{layers:new Map,parts:[]}}function O0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function H2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function u6(t){if(t.parts.length)return!1;for(let e of t.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var f6=t=>t.map(e=>e.map(([n,r])=>({x:Math.round(n*y2),y:Math.round(r*y2)})));function ds(t){let e=(r,a,s)=>(a.x-r.x)*(s.y-a.y)-(a.y-r.y)*(s.x-a.x)===0,n=[];for(let r of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],r);)n.pop();let a=n[n.length-1];(!a||a.x!==r.x||a.y!==r.y)&&n.push(r)}for(let r=!0;r&&n.length>=3;){let a=n.length;r=!0,n[a-1].x===n[0].x&&n[a-1].y===n[0].y||e(n[a-2],n[a-1],n[0])?n.pop():e(n[a-1],n[0],n[1])?n.shift():r=!1}return n}var _3=t=>f6(t).map(ds),q3=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/y2,n.y/y2]));function t1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?J1.EvenOdd:J1.NonZero;return q3(Jt(_3(t),n)).filter(r=>r.length>=3)}function e4(t,e,n){if(!e.length)return[];let r=new $2;r.addSubject(_3(e)),n.length&&r.addClip(_3(n));let a=[];return r.execute(t,J1.NonZero,a),q3(a).filter(s=>s.length>=3)}var d0=(t,e)=>e.length?e4(f0.Difference,t,e):t1(t),G1=(t,e)=>e4(f0.Intersection,t,e),ze=(t,e)=>e4(f0.Xor,t,e);function N0(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let r=[];for(let g of e)for(let p=0;p<g.length;p++){let v=g[p],b=g[(p+1)%g.length];(v[0]!==b[0]||v[1]!==b[1])&&r.push([v,b])}if(!r.length)return n==="outside"?t:[];let a=m0(e),s=Math.max(a[2]-a[0],a[3]-a[1],1e-6)/Math.max(1,Math.sqrt(r.length)),c=g=>Math.floor(g/s),o=new Map,i=new Map,l=(g,p,v)=>{let b=g.get(p);b?b[b.length-1]!==v&&b.push(v):g.set(p,[v])};r.forEach(([g,p],v)=>{let b=Math.max(1,Math.ceil(Math.hypot(p[0]-g[0],p[1]-g[1])/s*2));for(let y=0;y<=b;y++){let M=g[0]+(p[0]-g[0])*y/b,w=g[1]+(p[1]-g[1])*y/b;for(let x of[-1,0,1])for(let k of[-1,0,1])l(o,`${c(M)+x},${c(w)+k}`,v)}for(let y=c(Math.min(g[1],p[1]));y<=c(Math.max(g[1],p[1]));y++)l(i,y,v)});let h=(g,p)=>{let v=new Set,b=0,y=1;for(let k of[0,1]){let A=p[k]-g[k],L=a[k]-s,z=a[k+2]+s;if(A===0){if(g[k]<L||g[k]>z)return v;continue}let S=(L-g[k])/A,C=(z-g[k])/A;b=Math.max(b,Math.min(S,C)),y=Math.min(y,Math.max(S,C))}if(!(b<=y))return v;let M=[g[0]+(p[0]-g[0])*b,g[1]+(p[1]-g[1])*b],w=[g[0]+(p[0]-g[0])*y,g[1]+(p[1]-g[1])*y],x=Math.max(1,Math.ceil(Math.hypot(w[0]-M[0],w[1]-M[1])/s*2));for(let k=0;k<=x;k++){let A=M[0]+(w[0]-M[0])*k/x,L=M[1]+(w[1]-M[1])*k/x;for(let z of o.get(`${c(A)},${c(L)}`)??[])v.add(z)}return v},u=.5/y2,f=g=>{for(let v of o.get(`${c(g[0])},${c(g[1])}`)??[]){let[b,y]=r[v],M=y[0]-b[0],w=y[1]-b[1],x=Math.max(0,Math.min(1,((g[0]-b[0])*M+(g[1]-b[1])*w)/(M*M+w*w)));if(Math.hypot(g[0]-b[0]-x*M,g[1]-b[1]-x*w)<=u)return}let p=0;for(let v of i.get(c(g[1]))??[]){let[b,y]=r[v],M=(y[0]-b[0])*(g[1]-b[1])-(g[0]-b[0])*(y[1]-b[1]);b[1]<=g[1]?y[1]>g[1]&&M>0&&p++:y[1]<=g[1]&&M<0&&p--}return p!==0},d=g=>Math.round(g*y2)/y2,m=[];for(let g of t){let p=null,v=()=>{p&&p.length>=2&&m.push(p),p=null};for(let b=1;b<g.length;b++){let y=g[b-1],M=g[b],w=M[0]-y[0],x=M[1]-y[1];if(!w&&!x)continue;let k=[0,1];for(let L of h(y,M)){let[z,S]=r[L],C=S[0]-z[0],E=S[1]-z[1],I=w*E-x*C;if(Math.abs(I)>1e-15){let H=((z[0]-y[0])*E-(z[1]-y[1])*C)/I,T=((z[0]-y[0])*x-(z[1]-y[1])*w)/I;H>0&&H<1&&T>=0&&T<=1&&k.push(H)}else{let H=w*w+x*x;for(let T of[z,S]){let O=((T[0]-y[0])*w+(T[1]-y[1])*x)/H,_=Math.abs((T[0]-y[0])*x-(T[1]-y[1])*w)/Math.sqrt(H);O>0&&O<1&&_<=u&&k.push(O)}}}k.sort((L,z)=>L-z);let A=Math.hypot(w,x);for(let L=1;L<k.length;L++){if((k[L]-k[L-1])*A<1e-9||k[L]-k[L-1]<1e-300)continue;let z=[d(y[0]+w*k[L-1]),d(y[1]+x*k[L-1])],S=[d(y[0]+w*k[L]),d(y[1]+x*k[L])],C=(k[L-1]+k[L])/2,E=f([y[0]+w*C,y[1]+x*C]);if(E!==void 0&&E===(n==="inside")){let I=p?p[p.length-1]:void 0;p&&I&&I[0]===z[0]&&I[1]===z[1]?(S[0]!==I[0]||S[1]!==I[1])&&p.push(S):(v(),p=[z,S])}else v()}}v()}return m}function a0(t,e,n="round",r=.01){if(!t.length)return[];if(e===0)return t1(t);let a=n==="round"?J0.Round:n==="square"?J0.Square:J0.Miter,s=V5(_3(t1(t)),e*y2,a,M0.Polygon,2,r*y2);return q3(s).filter(c=>c.length>=3)}function G2(t,e){if(!t.length||e<=0)return[];let n=V5(f6(t),e/2*y2,J0.Round,M0.Round,2,.01*y2);return q3(n)}function E0(t){if(!t.length)return[];let e=new F3,n=new $2;n.addSubject(_3(t)),n.execute(f0.Union,J1.NonZero,e);let r=[],a=s=>{for(let c=0;c<s.count;c++){let o=s.child(c),i=[o.poly];for(let l=0;l<o.count;l++){let h=o.child(l);i.push(h.poly),a(h)}r.push(q3(i))}};return a(e),r}function D3(t){let e=t.length;if(e<2)return t.map((p,v)=>v);let n=t.map(p=>m0([p])??[0,0,0,0]),r=t.map(p=>Math.abs(z1(p))),a=(p,v)=>{let b=!1;for(let y=0,M=v.length-1;y<v.length;M=y++){let[w,x]=v[M],[k,A]=v[y];x>p[1]!=A>p[1]&&p[0]<w+(p[1]-x)*(k-w)/(A-x)&&(b=!b)}return b},[s,c,o,i]=[1/0,1/0,-1/0,-1/0];for(let p of n)s=Math.min(s,p[0]),c=Math.min(c,p[1]),o=Math.max(o,p[2]),i=Math.max(i,p[3]);let l=Math.max(1,Math.ceil(Math.sqrt(e))),h=Math.max(o-s,1e-9)/l,u=Math.max(i-c,1e-9)/l,f=(p,v,b)=>Math.min(l-1,Math.max(0,Math.floor((p-v)/b))),d=new Map,m=[];n.forEach((p,v)=>{let[b,y]=[f(p[0],s,h),f(p[2],s,h)],[M,w]=[f(p[1],c,u),f(p[3],c,u)];if((y-b+1)*(w-M+1)>16)return m.push(v);for(let x=b;x<=y;x++)for(let k=M;k<=w;k++){let A=x*l+k,L=d.get(A);L?L.push(v):d.set(A,[v])}});let g=t.map((p,v)=>{let b=n[v];if(!p.length)return 0;let y=p[0],M=0,w=d.get(f(y[0],s,h)*l+f(y[1],c,u))??[];for(let x of[...w,...m]){let k=n[x];x===v||!(r[x]>r[v])||k[0]>b[0]||k[1]>b[1]||k[2]<b[2]||k[3]<b[3]||a(y,t[x])&&M++}return M});return t.map((p,v)=>v).sort((p,v)=>g[v]-g[p]||p-v)}function z1(t){let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]+t[n][0])*(t[r][1]-t[n][1]);return-e/2}function We(t){let e=0,n=0,r=0;for(let a of t){if(a.length<3)continue;let[s,c]=a[0];for(let o=0,i=a.length-1;o<a.length;i=o++){let l=a[i][0]-s,h=a[i][1]-c,u=a[o][0]-s,f=a[o][1]-c,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+s*d/2,r+=(h+f)*d/6+c*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,r/e]}}function Xe(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}function se(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function l6(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,r=new Map;for(let[a,s]of t)r.set(a,{regions:s.regions.map(c=>{let o=c.map(i=>se(e,i));return n?o.reverse():o}),lines:s.lines.map(c=>c.map(o=>se(e,o)))});return r}function Se(t,e){return{layers:l6(t.layers,e),parts:t.parts.map(n=>({...n,layers:l6(n.layers,e),...n.bends&&{bends:ms(n,e)},...n.folds&&{folds:n.folds.map(r=>({...r,from:se(e,r.from),to:se(e,r.to)}))},...n.hang&&{hang:{...n.hang,at:se(e,n.hang.at)}}}))}}function ms(t,e){let n=t.bends,[r,,,a,s]=[e[0],e[1],e[2],e[3],e[4]];if(Math.abs(e[1])>1e-9||Math.abs(e[2])>1e-9||!(r!==0&&a!==0))throw new Error(`part "${t.name}" bends along its x, so it can be moved, scaled or mirrored but not turned: turn it with part(rotate = ...) instead`);return n.map(c=>{let[o,i]=c.mirrored?[-c.x1,-c.x0]:[c.x0,c.x1],[l,h]=[r*o+s,r*i+s].sort((m,g)=>m-g),u=!!c.mirrored!=r<0,{mirrored:f,...d}=c;return u?{...d,x0:-h,x1:-l,mirrored:!0}:{...d,x0:l,x1:h}})}function O2(t){let e=D0();for(let n of t){for(let[r,a]of n.layers){let s=e.layers.get(r)??{regions:[],lines:[]};for(let c of a.regions)s.regions.push(c);for(let c of a.lines)s.lines.push(c);e.layers.set(r,s)}for(let r of n.parts)e.parts.push(r)}return e}var a2="\0hidden";function h6(t,e){let n={regions:[],lines:[]};for(let[s,c]of t)if(s!==a2){for(let o of c.regions)n.regions.push(o);for(let o of c.lines)n.lines.push(o)}let r=new Map([[e,n]]),a=t.get(a2);return a&&e!==a2&&r.set(a2,a),r}function N3(t,e){if(t.parts.length&&e!=="guide")throw new Error(`a part cannot go on the ${e} layer as a whole. Put ${e}() inside part() instead.`);return{layers:h6(t.layers,e),parts:t.parts.map(n=>({...n,layers:h6(n.layers,e)}))}}function m0(t){let e=1/0,n=1/0,r=-1/0,a=-1/0;for(let s of t)for(let[c,o]of s)c<e&&(e=c),o<n&&(n=o),c>r&&(r=c),o>a&&(a=o);return e===1/0?null:[e,n,r,a]}function Q0(t,e){let n=[];for(let[r,a]of t)if(!e?.(r))for(let s of[...a.regions,...a.lines])n.push(s);return m0(n)}function $5(t){let e=[...t].sort((s,c)=>s[0]-c[0]||s[1]-c[1]);if(e.length<3)return e;let n=(s,c,o)=>(c[0]-s[0])*(o[1]-s[1])-(c[1]-s[1])*(o[0]-s[0]),r=[];for(let s of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let a=[];for(let s=e.length-1;s>=0;s--){let c=e[s];for(;a.length>=2&&n(a[a.length-2],a[a.length-1],c)<=0;)a.pop();a.push(c)}return a.pop(),r.pop(),r.concat(a)}function d6(t,e,n,r){return t<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/n,t*2*Math.PI/r)),5)}function Ze(t,e,n){let r=[];for(let a=0;a<n;a++){let s=2*Math.PI*a/n;r.push([t*Math.cos(s),e*Math.sin(s)])}return r}function m6(t,e,n,r){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let a=Math.max(1,Math.ceil(r(n)/4)),s=[],c=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[o,i,l]of c)for(let h=0;h<=a;h++){let u=(l+90*h/a)*Math.PI/180;s.push([o+n*Math.cos(u),i+n*Math.sin(u)])}return s}function t4(t,e){let n=t1(t);for(let r=0;r<100;r++){let a=E0(n);if(a.length<=1)return n;let s=o=>o.reduce((i,l)=>i+z1(l),0);a.sort((o,i)=>s(i)-s(o));let c=[];for(let o=1;o<a.length;o++){let i=1/0,l=[0,0],h=[0,0];for(let[y,M]of a[o][0])for(let w=0;w<a.length;w++)if(w!==o)for(let x of a[w])for(let k=0,A=x.length-1;k<x.length;A=k++){let[L,z]=x[A],[S,C]=x[k],E=S-L,I=C-z,H=E*E+I*I,T=H?Math.max(0,Math.min(1,((y-L)*E+(M-z)*I)/H)):0,O=L+T*E,_=z+T*I,D=Math.hypot(y-O,M-_);D<i&&([i,l,h]=[D,[y,M],[O,_]])}if(!Number.isFinite(i))continue;let u=h[0]-l[0],f=h[1]-l[1],d=Math.hypot(u,f);d<1e-9?[u,f]=[0,1]:[u,f]=[u/d,f/d];let[m,g]=[-f*(e/2),u*(e/2)],p=[l[0]-u*(e/2),l[1]-f*(e/2)],v=[h[0]+u*(e/2),h[1]+f*(e/2)],b=[[p[0]-m,p[1]-g],[v[0]-m,v[1]-g],[v[0]+m,v[1]+g],[p[0]+m,p[1]+g]];c.push(z1(b)<0?b.reverse():b)}if(!c.length)return n;n=t1([...n,...c])}return n}function ps(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function p6(t){let{spacing:e,step:n,box:r}=t,a=e/2,s=e,c=new Map,o=[],i=[],l=[],h=[],u=[],f=(C,E)=>Math.floor((C-r[0])/s)*1000003+Math.floor((E-r[1])/s),d=(C,E,I)=>{let H=f(C[0],C[1]),T=o.length;o.push(C[0]),i.push(C[1]),l.push(E),h.push(I);let O=c.get(H);O?O.push(T):c.set(H,[T])},m=Math.ceil(2*e/n)+2,g=(C,E,I=-1,H=0)=>{let T=Math.floor((C[0]-r[0])/s),O=Math.floor((C[1]-r[1])/s);for(let _=T-1;_<=T+1;_++)for(let D=O-1;D<=O+1;D++){let G=c.get(_*1000003+D);if(G)for(let V of G){let U=l[V];if(!(!u[U]&&U!==I)&&!(U===I&&Math.abs(h[V]-H)<m)&&Math.hypot(o[V]-C[0],i[V]-C[1])<E)return!1}}return!0},p=[],v=0,b=Math.ceil(4*(r[2]-r[0]+r[3]-r[1]+e)/n+2*m),y=(C,E)=>{let I=t.dir(C);if(!I)return null;let H=[C[0]+E*I[0]*n/2,C[1]+E*I[1]*n/2],T=t.dir(H)??I;return T[0]*I[0]+T[1]*I[1]<0?null:[C[0]+E*T[0]*n,C[1]+E*T[1]*n]},M=C=>{let E=p.length;u[E]=!1,d(C,E,0);let I=[[],[]];for(let[O,_]of[[0,1],[1,-1]]){let D=C;for(let G=1;G<=b;G++){let V=y(D,_);if(!V)break;let U=_*G;if(!t.inside(V)){I[O].push(V);break}if(!g(V,a,E,U))break;if(I[O].push(V),d(V,E,U),++v>t.maxPoints)throw new Error(`the lines have more than ${t.maxPoints} points: use a larger spacing or step`);t.tick(),D=V}}let H=[...I[1].reverse(),C,...I[0]],T=0;for(let O=1;O<H.length;O++)T+=Math.hypot(H[O][0]-H[O-1][0],H[O][1]-H[O-1][1]);return p.push(H),H.length<2||T<t.minLength?null:(u[E]=!0,H)},w=ps(t.seed),x=[];for(let C=r[0]+e/2;C<r[2];C+=e)for(let E=r[1]+e/2;E<r[3];E+=e)x.push([C+(w()-.5)*e,E+(w()-.5)*e]);for(let C=x.length-1;C>0;C--){let E=Math.floor(w()*(C+1));[x[C],x[E]]=[x[E],x[C]]}let k=[],A=[],L=Math.max(1,Math.round(e/(2*n))),z=C=>{if(!t.inside(C)||!g(C,e)||!t.dir(C))return;let E=M(C);E&&(k.push(E),A.push(E))},S=0;for(;;){for(;A.length;){let C=A.shift();for(let E=0;E<C.length;E+=L){let I=C[Math.max(0,E-1)],H=C[Math.min(C.length-1,E+1)],T=Math.hypot(H[0]-I[0],H[1]-I[1]);if(T===0)continue;let O=-(H[1]-I[1])/T,_=(H[0]-I[0])/T;for(let D of[1,-1])z([C[E][0]+D*O*e,C[E][1]+D*_*e])}}if(S>=x.length)break;z(x[S++])}return k}function g6(t,e,n,r,a,s,c){let o=(p,v)=>t[v*e+p],i=(p,v)=>(v*e+p)*2,l=(p,v)=>(v*e+p)*2+1,h=p=>{let v=p>>1,b=v%e,y=(v-b)/e,M=o(b,y),w=p&1?o(b,y+1):o(b+1,y),x=M===w?.5:(c-M)/(w-M);return p&1?[r+b*s,a+(y+x)*s]:[r+(b+x)*s,a+y*s]},u=new Map,f=(p,v)=>{for(let[b,y]of[[p,v],[v,p]]){let M=u.get(b);M?M.push(y):u.set(b,[y])}};for(let p=0;p+1<n;p++)for(let v=0;v+1<e;v++){let b=o(v,p),y=o(v+1,p),M=o(v+1,p+1),w=o(v,p+1);if(Number.isNaN(b+y+M+w))continue;let x=(b>=c?1:0)|(y>=c?2:0)|(M>=c?4:0)|(w>=c?8:0);if(x===0||x===15)continue;let k=i(v,p),A=l(v+1,p),L=i(v,p+1),z=l(v,p);if(x===5||x===10){let C=(b+y+M+w)/4>=c;x===5===C?(f(k,A),f(z,L)):(f(z,k),f(A,L));continue}let S=[];(x&1)!==(x&2)>>1&&S.push(k),(x&2)>>1!==(x&4)>>2&&S.push(A),(x&4)>>2!==(x&8)>>3&&S.push(L),(x&8)>>3!==(x&1)&&S.push(z),S.length===2&&f(S[0],S[1])}let d=new Set,m=p=>{let v=[h(p)];d.add(p);let b=p;for(;;){let y=(u.get(b)??[]).find(M=>!d.has(M));if(y===void 0)return(u.get(b)??[]).includes(p)&&v.length>2&&v.push(v[0]),v;d.add(y),v.push(h(y)),b=y}},g=[];for(let[p,v]of u)v.length===1&&!d.has(p)&&g.push(m(p));for(let p of u.keys())d.has(p)||g.push(m(p));return g.map(p=>p.filter((v,b)=>b===0||v[0]!==p[b-1][0]||v[1]!==p[b-1][1])).filter(p=>p.length>=2&&!(p.length===2&&p[0][0]===p[1][0]&&p[0][1]===p[1][1]))}function v6(t,e=.001){let n=t.filter(l=>l.length>=2).map(l=>[...l]);if(n.length<2)return n;let r=l=>`${Math.round(l[0]/e)},${Math.round(l[1]/e)}`,a=new Map,s=(l,h)=>{let u=r(l),f=a.get(u);f?f.push(h):a.set(u,[h])};n.forEach((l,h)=>{s(l[0],h),s(l[l.length-1],h)});let c=new Array(n.length).fill(!1),o=l=>r(l[0])===r(l[l.length-1]),i=[];for(let l=0;l<n.length;l++){if(c[l])continue;c[l]=!0;let h=n[l];if(!o(h))for(let u=0;u<2;u++){for(;;){let f=h[h.length-1],d=(a.get(r(f))??[]).find(p=>!c[p]);if(d===void 0)break;c[d]=!0;let m=n[d],g=r(m[0])===r(f)?m:[...m].reverse();if(h=h.concat(g.slice(1)),o(h))break}if(o(h))break;h=h.reverse()}i.push(h)}return gs(i)}function gs(t){let e=t.length;if(e<2)return t;let n=1/0,r=1/0,a=-1/0,s=-1/0;for(let g of t)for(let p of[g[0],g[g.length-1]])n=Math.min(n,p[0]),r=Math.min(r,p[1]),a=Math.max(a,p[0]),s=Math.max(s,p[1]);let c=Math.max((a-n+s-r)/Math.sqrt(e),1e-6),o=g=>Math.floor((g-n)/c),i=g=>Math.floor((g-r)/c),l=o(a)+1,h=i(s)+1,u=new Map;t.forEach((g,p)=>{for(let v of[g[0],g[g.length-1]]){let b=i(v[1])*l+o(v[0]),y=u.get(b);y?y[y.length-1]!==p&&y.push(p):u.set(b,[p])}});let f=new Array(e).fill(!1),d=[],m=[0,0];for(let g=0;g<e;g++){let p=-1,v=1/0,b=!1,y=Math.min(Math.max(o(m[0]),0),l-1),M=Math.min(Math.max(i(m[1]),0),h-1);for(let x=0;x<=Math.max(l,h);x++){for(let k=y-x;k<=y+x;k++)for(let A=M-x;A<=M+x;A++)if(Math.max(Math.abs(k-y),Math.abs(A-M))===x&&!(k<0||A<0||k>=l||A>=h))for(let L of u.get(A*l+k)??[]){if(f[L])continue;let z=t[L],S=Math.hypot(z[0][0]-m[0],z[0][1]-m[1]),C=Math.hypot(z[z.length-1][0]-m[0],z[z.length-1][1]-m[1]);S<v&&([p,v,b]=[L,S,!1]),C<v&&([p,v,b]=[L,C,!0])}if(p>=0&&v<=x*c)break}if(p<0){for(let x=0;x<e;x++)if(!f[x]){p=x;break}}f[p]=!0;let w=b?[...t[p]].reverse():t[p];d.push(w),m=w[w.length-1]}return d}function b6(t){let e=[],n=1/0,r=-1/0;for(let o of t)for(let i=0,l=o.length-1;i<o.length;l=i++)e.push([o[l][0],o[l][1],o[i][0],o[i][1]]),n=Math.min(n,o[i][1]),r=Math.max(r,o[i][1]);if(!e.length)return()=>!1;let a=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),s=(r-n)/a||1,c=Array.from({length:a},()=>[]);return e.forEach(([,o,,i],l)=>{let h=Math.max(0,Math.min(a-1,Math.floor((Math.min(o,i)-n)/s))),u=Math.max(0,Math.min(a-1,Math.floor((Math.max(o,i)-n)/s)));for(let f=h;f<=u;f++)c[f].push(l)}),([o,i])=>{if(i<n||i>r)return!1;let l=0;for(let h of c[Math.max(0,Math.min(a-1,Math.floor((i-n)/s)))]){let[u,f,d,m]=e[h];f<=i?m>i&&(d-u)*(i-f)-(o-u)*(m-f)>0&&l++:m<=i&&(d-u)*(i-f)-(o-u)*(m-f)<0&&l--}return l!==0}}var y6=Math.PI/180;function T1(t,e){let n=new Array(16).fill(0);for(let r=0;r<4;r++)for(let a=0;a<4;a++)for(let s=0;s<4;s++)n[r*4+a]+=t[r*4+s]*e[s*4+a];return n}function H5(t,e){let n=Math.cos(e*y6),r=Math.sin(e*y6);return t===0?[1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1]:t===1?[n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1]:[n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1]}var r4=t=>Math.abs(t)<1e-12?0:t;function R0(t){if(t.matrix)return t.matrix.map(r4);let[e,n,r]=t.rotate,a=T1(H5(2,r),T1(H5(1,n),H5(0,e)));return a[3]=t.at[0],a[7]=t.at[1],a[11]=t.at[2],a.map(r4)}function W2(t,e,n,r){return[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]]}function U3(t){let[e,n,r]=[t[3],t[7],t[11]],a=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[a[0],a[1],a[2],-(a[0]*e+a[1]*n+a[2]*r),a[3],a[4],a[5],-(a[3]*e+a[4]*n+a[5]*r),a[6],a[7],a[8],-(a[6]*e+a[7]*n+a[8]*r),0,0,0,1]}function O5(t){let[e,n,r,a]=[1/0,1/0,-1/0,-1/0];for(let s of t)for(let[c,o]of s)e=Math.min(e,c),n=Math.min(n,o),r=Math.max(r,c),a=Math.max(a,o);return[e,n,r,a]}function k6(t){let[e,n,r,a]=O5(t.outline),s=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];for(let o of[e,r])for(let i of[n,a])for(let l of[0,t.thickness]){let h=W2(t.matrix,o,i,l);for(let u=0;u<3;u++)s[u]=Math.min(s[u],h[u]),c[u]=Math.max(c[u],h[u])}return[s,c]}function z6(t,e,n=10){let r=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(k6))for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),a[f]=Math.max(a[f],u[f]);let s=e.map(h=>O5(h.outline)),c=s.reduce((h,[u,,f])=>Math.max(h,f-u),a[0]-r[0]),o=0,i=0,l=0;return e.map((h,u)=>{let[f,d,m,g]=s[u];o>0&&o+m-f>c&&(o=0,i+=l+n,l=0);let p=[1,0,0,a[0]+n+o-f,0,1,0,r[1]+i-d,0,0,1,r[2],0,0,0,1];return o+=m-f+n,l=Math.max(l,g-d),{...h,matrix:p.map(r4)}})}var vs=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),Ye=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],R5=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],n4=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],Je=t=>[t[2],t[6],t[10]],x6=t=>[t[3],t[7],t[11]],bs=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[4]*e[0]+t[5]*e[1]+t[6]*e[2],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]];function Ke(t,e,n){let r=n[0]*n[0]+n[1]*n[1],a=[];for(let s of t)for(let c=0,o=s.length-1;c<s.length;o=c++){let i=s[o],l=s[c],h=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=i[0]+(l[0]-i[0])*f-e[0],m=i[1]+(l[1]-i[1])*f-e[1];a.push((d*n[0]+m*n[1])/r)}return a.sort((s,c)=>s-c)}function a4(t,e,n){let r=0,a=0,s=0,c=0,o=0;for(;c+1<t.length&&o+1<e.length;){let i=Math.max(t[c],e[o]),l=Math.min(t[c+1],e[o+1])-i;l>n&&(r+=l,l>s&&(s=l,a=i+l/2)),t[c+1]<e[o+1]?c+=2:o+=2}return{total:r,mid:a,run:s}}function ys(t,e){let[n,r,a]=W2(U3(t.matrix),e[0],e[1],e[2]);if(a<0||a>t.thickness)return!1;let s=!1;for(let c of t.outline)for(let o=0,i=c.length-1;o<c.length;i=o++){let[l,h]=c[i],[u,f]=c[o];h>r!=f>r&&n<l+(u-l)*(r-h)/(f-h)&&(s=!s)}return s}var F5=class{constructor(e=[]){this.parts=e;this.seen=[]}see(e,n){e>0&&this.seen.push([n(),e])}get at(){let e=0,n=[0,0,0];for(let[s,c]of this.seen){for(let o=0;o<3;o++)n[o]+=s[o]*c;e+=c}for(let s=0;s<3;s++)n[s]/=e;if(this.parts.length&&this.parts.every(s=>ys(s,n)))return n;let r=this.seen[0][0],a=1/0;for(let[s]of this.seen){let c=Math.hypot(s[0]-n[0],s[1]-n[1],s[2]-n[2]);c<a&&([r,a]=[s,c])}return r}};function _5(t,e,n,r){let a=t+n,s=e-n;if(s<=a)return{at:[],size:0};let c=Math.max(4,Math.ceil((s-a)/r));return{at:Array.from({length:c},(o,i)=>a+(s-a)*(i+.5)/c),size:(s-a)/c}}function M6(t,e,n){let r=W2(t,e[0],e[1],e[2]),a=bs(t,n);return[[r[0],r[1]],[a[0],a[1]]]}function S6(t,e,n,r,a,s,c,o=!1){let i=Je(t.matrix),l=Je(e.matrix),h=R5(i,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=R5(f,i),m=Ye(l,d),g=x6(t.matrix),p=Ye(l,x6(e.matrix)),v=1/0,b=-1/0;for(let A of e.outline)for(let[L,z]of A)for(let S of[0,e.thickness]){let C=W2(e.matrix,L,z,S),E=Ye(i,[C[0]-g[0],C[1]-g[1],C[2]-g[2]]);E<v&&(v=E),E>b&&(b=E)}let y=_5(Math.max(0,v),Math.min(t.thickness,b),a,s),M=1/0,w=-1/0;for(let A of t.outline)for(let[L,z]of A){let S=W2(t.matrix,L,z,0),C=Ye(d,[S[0]-g[0],S[1]-g[1],S[2]-g[2]]);C<M&&(M=C),C>w&&(w=C)}let x=0,k=new F5([t,e]);for(let A of y.at){let L=n4(g,i,A),z=(p-Ye(l,L))/m,S=(p+e.thickness-Ye(l,L))/m,C=_5(Math.max(M,Math.min(z,S)),Math.min(w,Math.max(z,S)),a,s);for(let E of C.at){let I=n4(L,d,E),[H,T]=M6(n,I,f),[O,_]=M6(r,I,f),D=a4(Ke(t.outline,H,T),Ke(e.outline,O,_),a);if(x+=D.total*y.size*C.size,k.see(D.run,()=>n4(I,f,D.mid)),x>c&&!o)return k.at}}return x>c?k.at:void 0}function A6(t,e,n,r,a,s,c=!1){let o=[0,1,2,3].flatMap(z=>[0,1,2,3].map(S=>{let C=0;for(let E=0;E<4;E++)C+=n[z*4+E]*e.matrix[E*4+S];return C})),i=o[11],l=o[11]+o[10]*e.thickness,h=Math.min(t.thickness,Math.max(i,l))-Math.max(0,Math.min(i,l));if(h<=r)return;let u=Math.max(0,Math.min(i,l))+h/2,f=new F5([t,e]),d=e.outline.map(z=>z.map(([S,C])=>[o[0]*S+o[1]*C+o[3],o[4]*S+o[5]*C+o[7]])),[m,g,p,v]=O5(t.outline),[b,y,M,w]=O5(d),x=_5(Math.max(g,y),Math.min(v,w),r,a),k=0;for(let z of x.at){let S=a4(Ke(t.outline,[0,z],[1,0]),Ke(d,[0,z],[1,0]),r);if(k+=S.total*x.size*h,f.see(S.run,()=>W2(t.matrix,S.mid,z,u)),k>s&&!c)return f.at}let A=_5(Math.max(m,b),Math.min(p,M),r,a),L=0;for(let z of A.at){let S=a4(Ke(t.outline,[z,0],[0,1]),Ke(d,[z,0],[0,1]),r);if(L+=S.total*A.size*h,f.see(S.run,()=>W2(t.matrix,z,S.mid,u)),L>s&&!c)return f.at}return k>s||L>s?f.at:void 0}function L6(t,e=1/0,n=.05,r=.25,a=.1){let s=t.map(k6),c=t.map(h=>U3(h.matrix)),o=t.map((h,u)=>u).sort((h,u)=>s[h][0][0]-s[u][0][0]),i=[],l=0;for(let h=0;h<o.length;h++)for(let u=h+1;u<o.length;u++){let f=o[h],d=o[u];if(s[d][0][0]>=s[f][1][0]-n)break;if(!vs(s[f],s[d],n))continue;if(++l>e)return{found:i,complete:!1};let[m,g]=f<d?[t[f],t[d]]:[t[d],t[f]],[p,v]=f<d?[c[f],c[d]]:[c[d],c[f]],y=Math.hypot(...R5(Je(m.matrix),Je(g.matrix)))<1e-9?A6(m,g,p,n,r,a):S6(m,g,p,v,n,r,a);y&&i.push([m,g,y])}return{found:i,complete:!0}}function C6(t,e,n=.05,r=.25,a=.1){let s=Math.hypot(...R5(Je(t.matrix),Je(e.matrix)))<1e-9,c=U3(t.matrix);return s?A6(t,e,c,n,r,a,!0):S6(t,e,c,U3(e.matrix),n,r,a,!0)}function U0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var s4=U0(0,0,0);function L0(t){return U3(t)}function P6(t,e,n=t.angle,r=t.x1){let a=r-t.x0;if(!n||!(a>0))return U0(0,0,0);let s=(t.x1-t.x0)/(t.angle*Math.PI/180),c=e/2+s;return T1(U0(t.x0,0,c),T1(H5(1,-n),U0(-t.x0-a,0,-c)))}function B3(t){return[...t].sort((e,n)=>e.x0-n.x0)}var q5=t=>t.length>0&&t.every(e=>e.mirrored),w6=[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],xs=t=>T1(w6,T1(t,w6));function c4(t){return B3(t).map(e=>e.mirrored?[-e.x1,-e.x0]:[e.x0,e.x1])}function D5(t,e){let n=[U0(0,0,0)];for(let r of B3(t))n.push(T1(n[n.length-1],P6(r,e)));return q5(t)?n.map(xs):n}function Ae(t,e,n){if(q5(t)){let s=Ae(t.map(({mirrored:c,...o})=>o),e,[-n[0],n[1],n[2]]);return[-s[0],s[1],s[2]]}let r=B3(t),a=D5(r,e);for(let s=r.length-1;s>=0;s--){let c=r[s];if(n[0]>=c.x1)return W2(a[s+1],...n);if(n[0]>c.x0){let o=(n[0]-c.x0)/(c.x1-c.x0),i=T1(a[s],P6(c,e,c.angle*o,n[0]));return W2(i,...n)}}return n}function E6(t,e){let n=q5(t)?-e:e;return B3(t).filter(r=>(r.x0+r.x1)/2<n).length}function Le(t){if(t.folds?.length)return Ce(t.outline,t.folds,t.thickness).map(c=>({...t,outline:c.outline,folds:void 0,matrix:T1(t.matrix,c.matrix)}));if(!t.bends?.length)return[t];let e=B3(t.bends),n=D5(t.bends,t.thickness),r=q5(t.bends),a=1e7,s=[];for(let c=0;c<=e.length;c++){let o=c===0?-a:e[c-1].x1,i=c===e.length?a:e[c].x0;if(!(i>o))continue;let[l,h]=r?[-i,-o]:[o,i],u=[[l,-a],[h,-a],[h,a],[l,a]],f=G1(t.outline,[u]);f.length&&s.push({...t,outline:f,bends:void 0,matrix:T1(t.matrix,n[c])})}return s}function Ms(t,e,n){let r=n*Math.PI/180,[a,s,c]=[Math.cos(r),Math.sin(r),1-Math.cos(r)],[o,i,l]=e,h=[a+o*o*c,o*i*c-l*s,o*l*c+i*s,i*o*c+l*s,a+i*i*c,i*l*c-o*s,l*o*c-i*s,l*i*c+o*s,a+l*l*c];return[h[0],h[1],h[2],t[0]-(h[0]*t[0]+h[1]*t[1]+h[2]*t[2]),h[3],h[4],h[5],t[1]-(h[3]*t[0]+h[4]*t[1]+h[5]*t[2]),h[6],h[7],h[8],t[2]-(h[6]*t[0]+h[7]*t[1]+h[8]*t[2]),0,0,0,1]}var ws=(t,[e,n])=>{let r=!1;for(let a of t)for(let s=0,c=a.length-1;s<a.length;c=s++)a[s][1]>n!=a[c][1]>n&&e<(a[c][0]-a[s][0])*(n-a[s][1])/(a[c][1]-a[s][1])+a[s][0]&&(r=!r);return r};function Ce(t,e,n){let r=e.map(d=>{let[m,g]=[d.to[0]-d.from[0],d.to[1]-d.from[1]],p=Math.hypot(m,g),[v,b]=[m/p,g/p],[y,M]=[-b*.005,v*.005],[w,x]=[[d.from[0]-v*.02,d.from[1]-b*.02],[d.to[0]+v*.02,d.to[1]+b*.02]];return[[w[0]-y,w[1]-M],[x[0]-y,x[1]-M],[x[0]+y,x[1]+M],[w[0]+y,w[1]+M]]}),a=E0(d0(t,r)),s=[];if(!a.length)return s;let c=d=>a.findIndex(m=>ws(m,d)),o=e.map(d=>{let[m,g]=[d.to[0]-d.from[0],d.to[1]-d.from[1]],p=Math.hypot(m,g),[v,b]=[-g/p*.05,m/p*.05],y=[];for(let M=0;M<25;M++){let w=(M+.5)/25,x=[d.from[0]+m*w,d.from[1]+g*w],k=c([x[0]+v,x[1]+b]),A=c([x[0]-v,x[1]-b]);k>=0&&A>=0&&k!==A&&!y.some(([L,z])=>L===k&&z===A)&&y.push([k,A])}return y}),i=d=>d.reduce((m,g)=>m+Math.abs(z1(g)),0),l=c([0,0]);l<0&&(l=a.map(i).reduce((d,m,g,p)=>m>p[d]?g:d,0));let h=a.map(()=>{});h[l]=U0(0,0,0);let u=[l];for(;u.length;){let d=u.shift();e.forEach((m,g)=>o[g].forEach(p=>{if(!p.includes(d))return;let v=p[0]===d?p[1]:p[0];if(h[v])return;let[b,y]=[m.to[0]-m.from[0],m.to[1]-m.from[1]],M=Math.hypot(b,y),w=v===p[0]?1:-1,x=m.angle>0?n:0,k=Ms([m.from[0],m.from[1],x],[b/M,y/M,0],w*m.angle);h[v]=T1(h[d],k),u.push(v)}))}a.forEach((d,m)=>s.push({outline:d,matrix:h[m]??U0(0,0,0)}));let f=e.flatMap((d,m)=>o[m].length?[]:[m]);return f.length&&(s.unused=f),s}function T6(t,e){return t.flatMap(n=>{let r=N0(n.mode==="line"?[...n.lines,...n.regions.map(s=>[...s,s[0]])]:n.lines,e,"inside"),a=n.mode==="fill"?G1(n.regions,e):[];return a.length||r.length?[{...n,regions:a,lines:r}]:[]})}var ks=2e3;function Pe(t,e,n=2){if(!e?.length)return E0(t);let r=1e7,a=1/0,s=-1/0;for(let f of t)for(let[d]of f)a=Math.min(a,d),s=Math.max(s,d);let c=c4(e).map(([f,d])=>[Math.max(f,a),Math.min(d,s)]).filter(([f,d])=>d>f),o=c.reduce((f,[d,m])=>f+(m-d),0),i=Math.max(n,o/ks),l=[];for(let[f,d]of c){let m=Math.max(1,Math.ceil((d-f)/i));for(let g=0;g<=m;g++)l.push(f+(d-f)*g/m)}let h=[-r,...l.sort((f,d)=>f-d),r],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-r],[h[f+1],-r],[h[f+1],r],[h[f],r]];for(let m of E0(G1(t,[d])))u.push(m)}return u}var ce=1e6,j3=.01,oe=t=>z1(t)<0?[...t].reverse():t;function zs(t,e){let n=T1(L0(t.matrix),e.matrix),[r,a]=[n[8],n[9]],s=Math.hypot(r,a);if(s<1e-9)return[];let c=0,o=e.thickness,i=I=>(-n[11]-Math.max(n[10]*c,n[10]*o)+I)/s,l=I=>(t.thickness-n[11]-Math.min(n[10]*c,n[10]*o)-I)/s;if(!(l(j3)>i(j3)))return[];let[h,u]=[r/s,a/s],[f,d]=[-u,h],m=(I,H)=>[[h*I-f*ce,u*I-d*ce],[h*H-f*ce,u*H-d*ce],[h*H+f*ce,u*H+d*ce],[h*I+f*ce,u*I+d*ce]],g=1/0,p=-1/0;for(let I of e.outline)for(let[H,T]of I)for(let O of[c,o]){let _=n[8]*H+n[9]*T+n[10]*O+n[11];_<g&&(g=_),_>p&&(p=_)}if(Math.min(t.thickness,p)-Math.max(0,g)<Math.min(1,t.thickness/2))return[];let v=(I,H)=>G1(e.outline,[oe(m(I,H))]).filter(T=>Math.abs(z1(T))>1e-6),b=I=>{let[H,T]=[1/0,-1/0];for(let O of I)for(let[_,D]of O)for(let G of[c,o]){let V=n[8]*_+n[9]*D+n[10]*G+n[11];H=Math.min(H,V),T=Math.max(T,V)}return Math.min(t.thickness,T)-Math.max(0,H)},y=E0(v(i(j3),l(j3))).filter(I=>b(I)>=Math.min(1,t.thickness/2)-2*j3).flat();if(!y.length)return[];let M=Math.abs(l(0)-i(0))+1,w=I=>{let H=I.map(([_,D])=>[_-h*M,D-u*M]),T=I.map(([_,D])=>[_+h*M,D+u*M]),O=[oe(H),oe(T)];for(let _=0;_<I.length;_++){let D=(_+1)%I.length,G=[H[_],H[D],T[D],T[_]];Math.abs(z1(G))>1e-12&&O.push(oe(G))}return O},x=t1(y.flatMap(w),"nonzero"),k=G1(e.outline,x).filter(I=>Math.abs(z1(I))>1e-6);if(!k.length)return[];let A=I=>([H,T])=>[n[0]*H+n[1]*T+n[2]*I+n[3],n[4]*H+n[5]*T+n[6]*I+n[7]],L=t.thickness,z=(I,H)=>(I-n[11]-n[10]*H)/s,S=[],C=I=>{I.length>=3&&Math.abs(z1(I))>1e-9&&S.push(oe(I))};for(let I of[c,o])for(let H of G1(k,[oe(m(z(0,I),z(L,I)))]))C(H.map(A(I)));for(let I of[0,L])if(Math.abs(n[10])>1e-9){let[H,T]=[z(I,c),z(I,o)].sort((O,_)=>O-_);for(let O of G1(k,[oe(m(H,T))]))C(O.map(([_,D])=>A((I-n[11]-n[8]*_-n[9]*D)/n[10])([_,D])))}else{let H=z(I,0);for(let T of G1(k,[oe(m(H-1e-4,H+1e-4))])){let[O,_]=[1/0,-1/0];for(let[V,U]of T){let J=f*V+d*U;O=Math.min(O,J),_=Math.max(_,J)}if(!(_-O>1e-6))continue;let D=[h*H+f*O,u*H+d*O],G=[h*H+f*_,u*H+d*_];C([A(c)(D),A(c)(G),A(o)(G),A(o)(D)])}}let E=(I,H,T)=>n[8]*I+n[9]*H+n[10]*T+n[11];for(let I of k)for(let H=0;H<I.length;H++){let[T,O]=I[H],[_,D]=I[(H+1)%I.length],G=[[0,c],[1,c],[1,o],[0,o]],V=([U,J])=>E(T+(_-T)*U,O+(D-O)*U,J);for(let[U,J]of[[1,0],[-1,-L]]){let n1=M1=>U*V(M1)>=J,m1=[];for(let M1=0;M1<G.length;M1++){let c1=G[M1],C1=G[(M1+1)%G.length];if(n1(c1)&&m1.push(c1),n1(c1)!==n1(C1)){let h1=U*V(c1)-J,B1=U*V(C1)-J,$=h1/(h1-B1);m1.push([c1[0]+(C1[0]-c1[0])*$,c1[1]+(C1[1]-c1[1])*$])}}if(G=m1,!G.length)break}G.length>=3&&C(G.map(([U,J])=>A(J)([T+(_-T)*U,O+(D-O)*U])))}return S.length?t1(S,"nonzero"):[]}function I6(t,e,n){let r=[];for(let s of e)for(let c of zs(t,s))r.push(c);if(!r.length)return[];let a=E0(G1(t1(r),t.outline)).filter(s=>s.reduce((c,o)=>c+z1(o),0)>1e-4);return a.length?a0(a.flat(),n/2,"miter"):[]}var G3=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],V6=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Ss=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],$6=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},W3={turn:.3,press:-.1};function o4(t){let e=$6(G3(t.to,t.from)),n=G3(t.up,e.map(a=>a*V6(t.up,e)));Math.hypot(...n)<1e-9&&(n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0]);let r=$6(G3(n,e.map(a=>a*V6(n,e))));return{axis:e,u:Ss(r,e),v:r}}function As(t,e){let{u:n,v:r}=o4(t);if(Array.isArray(t.size)){let[c,o]=[t.size[0]/2+e/2,t.size[1]/2+e/2];return[[-c,-o],[c,-o],[c,o],[-c,o]].map(([i,l])=>[n[0]*i+r[0]*l,n[1]*i+r[1]*l,n[2]*i+r[2]*l])}let a=t.size/2+e/2,s=t.sides<12?t.sides:64;return Array.from({length:s},(c,o)=>{let i=2*Math.PI*o/s,[l,h]=[Math.cos(i)*a,Math.sin(i)*a];return[n[0]*h+r[0]*l,n[1]*h+r[1]*l,n[2]*h+r[2]*l]})}function H6(t,e,n){let r=G3(e.to,e.from);if(!(Math.hypot(...r)>1e-9))return;let a=L0(t.matrix),s=i=>[a[0]*i[0]+a[1]*i[1]+a[2]*i[2]+a[3],a[4]*i[0]+a[5]*i[1]+a[6]*i[2]+a[7],a[8]*i[0]+a[9]*i[1]+a[10]*i[2]+a[11]],c=G3(s(r),s([0,0,0]));if(Math.abs(c[2])<.05*Math.hypot(...c))return;let o=[];for(let i of As(e,n)){let l=s([e.from[0]+i[0],e.from[1]+i[1],e.from[2]+i[2]]),h=(0-l[2])/c[2],u=(t.thickness-l[2])/c[2];if(h>u&&([h,u]=[u,h]),h=Math.max(0,h),u=Math.min(1,u),u>h)for(let f of[h,u])o.push([l[0]+c[0]*f,l[1]+c[1]*f])}return o.length>=3?$5(o):void 0}var N5=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Ls=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],O6=t=>[t[2],t[6],t[10]],R6=t=>[t[3],t[7],t[11]];function F6(t,e,n){let r=[];for(let a of t)for(let s=0,c=a.length-1;s<a.length;c=s++){let o=a[c],i=a[s],l=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),h=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]);if(l>0==h>0)continue;let u=l/(l-h);r.push((o[0]+(i[0]-o[0])*u-e[0])*n[0]+(o[1]+(i[1]-o[1])*u-e[1])*n[1])}return r.sort((a,s)=>a-s)}function _6(t,e){for(let n=0;n+1<t.length;n+=2)if(t[n]<=e&&e<=t[n+1])return[t[n],t[n+1]]}function Cs(t,[e,n]){let r=!1;for(let a of t)for(let s=0,c=a.length-1;s<a.length;c=s++){let[o,i]=a[c],[l,h]=a[s];i>n!=h>n&&e<o+(l-o)*(n-i)/(h-i)&&(r=!r)}return r}function q6(t,e,n){let r={a:[],b:[],thin:0},a=O6(t.matrix),s=O6(e.matrix),c=Ls(a,s),o=Math.hypot(...c);if(o<1e-6)return r;let i=Math.abs(N5(a,s)),l=[c[0]/o,c[1]/o,c[2]/o],h=N5(a,R6(t.matrix))+t.thickness/2,u=N5(s,R6(e.matrix))+e.thickness/2,f=N5(a,s),d=1-f*f,m=(h-u*f)/d,g=(u-h*f)/d,p=[m*a[0]+g*s[0],m*a[1]+g*s[1],m*a[2]+g*s[2]],v=z=>{let S=L0(z.matrix);return[[S[0]*p[0]+S[1]*p[1]+S[2]*p[2]+S[3],S[4]*p[0]+S[5]*p[1]+S[6]*p[2]+S[7]],[S[0]*l[0]+S[1]*l[1]+S[2]*l[2],S[4]*l[0]+S[5]*l[1]+S[6]*l[2]]]},[b,y]=v(t),[M,w]=v(e),x=F6(t.outline,b,y),k=F6(e.outline,M,w),A=(e.thickness+t.thickness*i)/o+n,L=(t.thickness+e.thickness*i)/o+n;for(let z=0;z+1<x.length;z+=2)for(let S=0;S+1<k.length;S+=2){let C=Math.max(x[z],k[S]),E=Math.min(x[z+1],k[S+1]);if(!(E-C>.01))continue;let I=(C+E)/2,[H,T]=_6(x,I),[O,_]=_6(k,I),D=Math.max(T-I,I-O)<=Math.max(I-H,_-I),G=(J,n1,m1,M1,c1,C1)=>{let h1=[-m1[1],m1[0]],B1=(o1,p1)=>[n1[0]+m1[0]*(I+c1*o1)+h1[0]*p1,n1[1]+m1[1]*(I+c1*o1)+h1[1]*p1],$=C1+M1+1,B=[B1(0,-M1/2),B1($,-M1/2),B1($,M1/2),B1(0,M1/2)];z1(B)<0&&B.reverse();let a1=B1(Math.min(.01,C1/2),0),b1=E0(G1([B],J.outline)).find(o1=>Cs(o1,a1));if(!(!b1||!(b1.reduce((o1,p1)=>o1+z1(p1),0)>1e-4)))return G1(a0(b1,.05,"miter"),[B])},V=G(t,b,y,A,D?1:-1,D?T-I:I-H),U=G(e,M,w,L,D?-1:1,D?I-O:_-I);if(!V||!U){r.thin++;continue}r.a.push(...V),r.b.push(...U)}return r}var p2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",x2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",N6=t=>typeof t=="number",e2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",s2=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function i4(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)i4(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function U5(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let r=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(r>e)throw new Error(`a range of ${r} items is more than the limit of ${e}`);for(let a=0;a<r;a++)n.push(t.start+a*t.step);return n}function w0(t){return t===void 0||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="number"?!Number.isNaN(t):!0}var D6=(t,e,n)=>p2(t)&&p2(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:e2(t)&&e2(e)?t.fields.size===e.fields.size&&[...t.fields].every(([r,a])=>e.fields.has(r)&&Qe(a,e.fields.get(r),n)):t===e;function Qe(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return D6(t,e,n);let r=new Map,a=[],s=(c,o)=>{let i=r.get(c);return i?.has(o)?!0:c.length!==o.length?!1:(i||r.set(c,i=new Set),i.add(o),a.push([c,o,0]),!0)};if(!s(t,e))return!1;for(;a.length;){let c=a[a.length-1];if(c[2]===c[0].length){a.pop();continue}let o=c[0][c[2]],i=c[1][c[2]++];if(n?.(),Array.isArray(o)&&Array.isArray(i)?!s(o,i):!D6(o,i,n))return!1}return!0}function X0(t){return t===void 0?"undef":Array.isArray(t)?"list":p2(t)?"range":x2(t)?"function":e2(t)?"record":typeof t}function Ps(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?l2(t):p2(t)?`[${l2(t.start)}:${l2(t.step)}:${l2(t.end)}]`:x2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:e2(t)?"{}":String(t)}function e3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let r=[],a=0,s=l=>{r.push(l),a+=l.length},c=[],o=t;for(;;){Array.isArray(o)?(s("["),c.push({items:o,i:0,close:"]"})):e2(o)&&o.fields.size?(s("{"),c.push({items:[...o.fields.values()],keys:[...o.fields.keys()],i:0,close:"}"})):s(Ps(o));let l=!1;for(;c.length&&!l&&a<=e;){let h=c[c.length-1];h.i<h.items.length?(h.i&&s(", "),h.keys&&s(`${h.keys[h.i]} = `),o=h.items[h.i++],l=!0):(c.pop(),s(h.close))}if(!l||a>e)break}let i=r.join("");return a>e?{text:i.slice(0,Math.max(e,0)),whole:!1}:{text:i,whole:!0}}function U6(t,e,n){let r=[],a=0;for(let s of t){r.length&&(a+=e.length);let c=e3(s,n-a);if(!c.whole)return;a+=c.text.length,r.push(c.text)}return r.join(e)}function c0(t){let e=e3(t,200,!0);return e.whole?e.text:e.text+"..."}var k0=t=>typeof t=="string"?t:c0(t);function V0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function l2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function t3(t,e=.02){let n=[],r=[],a=[],s=[0,0],c=[0,0],o=l=>{a.length>=2&&(l?n:r).push(a),a=[]},i=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")o(!1),s=c=[l.x,l.y],a=[c];else if(l.type==="L")c=[l.x,l.y],a.push(c);else if(l.type==="Q"){let[h,u]=c,f=i(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=f;d++){let m=d/f,g=1-m;a.push([g*g*h+2*g*m*l.x1+m*m*l.x,g*g*u+2*g*m*l.y1+m*m*l.y])}c=[l.x,l.y]}else if(l.type==="C"){let[h,u]=c,f=i(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let m=d/f,g=1-m;a.push([g*g*g*h+3*g*g*m*l.x1+3*g*m*m*l.x2+m*m*m*l.x,g*g*g*u+3*g*g*m*l.y1+3*g*m*m*l.y2+m*m*m*l.y])}c=[l.x,l.y]}else o(!0),c=s,a=[s];return o(!1),{closed:n,open:r}}function n3(t,e=Math.PI/2,n){let r=M=>/^[a-zA-Z]$/.test(M),a=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],s=[],c=0,o="",i=0,l=0,h=0,u=0,f=0,d=0,m=0,g=0,p="",v=()=>{let M=a[c++];if(M===void 0||r(M))throw new Error(`Bad path data near "${M??"end"}"`);return Number(M)},b=()=>{let M=a[c];if(M===void 0)throw new Error("Bad path data: missing arc flag");return M.length>1&&(M[0]==="0"||M[0]==="1")&&!M.includes(".")?(a[c]=M.slice(1),Number(M[0])):(c++,Number(M))};try{y()}catch(M){if(!n)throw M;n(M.message)}return s;function y(){for(;c<a.length;){if(r(a[c]))o=a[c++];else if(o){if(o==="Z"||o==="z")throw new Error(`Bad path data near "${a[c]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let M=o===o.toLowerCase(),w=o.toUpperCase(),x=M?i:0,k=M?l:0;if(w==="M")i=x+v(),l=k+v(),h=i,u=l,s.push({type:"M",x:i,y:l}),o=M?"l":"L";else if(w==="L")i=x+v(),l=k+v(),s.push({type:"L",x:i,y:l});else if(w==="H")i=x+v(),s.push({type:"L",x:i,y:l});else if(w==="V")l=k+v(),s.push({type:"L",x:i,y:l});else if(w==="C"||w==="S"){let A,L;if(w==="C")A=x+v(),L=k+v();else{let C=p==="C"||p==="S";A=C?2*i-f:i,L=C?2*l-d:l}let z=x+v(),S=k+v();i=x+v(),l=k+v(),f=z,d=S,s.push({type:"C",x1:A,y1:L,x2:z,y2:S,x:i,y:l})}else if(w==="Q"||w==="T"){let A,L;if(w==="Q")A=x+v(),L=k+v();else{let z=p==="Q"||p==="T";A=z?2*i-m:i,L=z?2*l-g:l}i=x+v(),l=k+v(),m=A,g=L,s.push({type:"Q",x1:A,y1:L,x:i,y:l})}else if(w==="A"){let A=v(),L=v(),z=v(),S=b(),C=b(),E=x+v(),I=k+v();s.push(...Es(i,l,A,L,z,S,C,E,I,e)),i=E,l=I}else if(w==="Z")s.push({type:"Z"}),i=h,l=u;else throw new Error(`Unknown path command "${o}"`);p=w}}}function Es(t,e,n,r,a,s,c,o,i,l=Math.PI/2){if(n===0||r===0||t===o&&e===i)return[{type:"L",x:o,y:i}];n=Math.abs(n),r=Math.abs(r);let h=a*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-o)/2,m=(e-i)/2,g=u*d+f*m,p=-f*d+u*m,v=g*g/(n*n)+p*p/(r*r);v>1&&(n*=Math.sqrt(v),r*=Math.sqrt(v));let b=n*n*r*r-n*n*p*p-r*r*g*g,y=n*n*p*p+r*r*g*g,M=Math.sqrt(Math.max(0,b/y));s===c&&(M=-M);let w=M*n*p/r,x=-M*r*g/n,k=u*w-f*x+(t+o)/2,A=f*w+u*x+(e+i)/2,L=(T,O,_,D)=>Math.atan2(T*D-O*_,T*_+O*D),z=L(1,0,(g-w)/n,(p-x)/r),S=L((g-w)/n,(p-x)/r,(-g-w)/n,(-p-x)/r);!c&&S>0&&(S-=2*Math.PI),c&&S<0&&(S+=2*Math.PI);let C=Math.ceil(Math.abs(S)/l),E=[],I=T=>[k+n*Math.cos(T)*u-r*Math.sin(T)*f,A+n*Math.cos(T)*f+r*Math.sin(T)*u],H=T=>[-n*Math.sin(T)*u-r*Math.cos(T)*f,-n*Math.sin(T)*f+r*Math.cos(T)*u];for(let T=0;T<C;T++){let O=z+S*T/C,_=z+S*(T+1)/C,D=4/3*Math.tan((_-O)/4),G=I(O),V=I(_),U=H(O),J=H(_);E.push({type:"C",x1:G[0]+D*U[0],y1:G[1]+D*U[1],x2:V[0]-D*J[0],y2:V[1]-D*J[1],x:V[0],y:V[1]})}return E}var B0=Math.PI/180;function Z6(t,e,n,r){if(typeof t=="number"&&typeof e=="number")return t-e;if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;if(Array.isArray(t)&&Array.isArray(e)){for(let a=0;a<Math.min(t.length,e.length);a++){r();let s=Z6(t[a],e[a],n,r);if(s)return s}return t.length-e.length}throw new Error(`${n}() can only order numbers, strings or lists of them, not ${X0(t)} and ${X0(e)}`)}function f4(t,e,n){let r=Z0(t,e,n);return(r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.flatMap(s=>Z0(s,e,n)):r).map(s=>{if(!Array.isArray(s)||s.length<2)throw new Error(`${e}() needs points [x, y], got ${X0(s)}`);return[I1(s[0],e),I1(s[1],e)]})}function Ts(t,e,n){let r=Z0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(a=>f4(a,e,n)):[f4(r,e,n)]}var P1=(t,e,n)=>({params:t.replace("...","").split(",").map(r=>r.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function Y6(t,e,n){return t.order?[]:t.params.filter((r,a)=>a<e.length&&n.has(r))}function K6(t,e,n){if(t.rest){let s=[...e];return t.params.forEach((c,o)=>{n.has(c)&&(s[o]=n.get(c))}),s}if(!t.order)return t.params.map((s,c)=>n.has(s)?n.get(s):e[c]);let r=e.length+t.params.filter(s=>n.has(s)).length,a=t.order(r).filter(s=>!n.has(s));return t.params.map(s=>n.has(s)?n.get(s):e[a.indexOf(s)])}function l4(t,e,n,r){let a=U6(t,e,n.maxLength);if(a===void 0)throw new Error(`${r}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(a.length/8)),a}function I1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${X0(t)}`);return t}function Z0(t,e,n){if(Array.isArray(t))return t;if(p2(t))return U5(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${X0(t)}`)}var Is=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function J6(t,e,n){if(Is.has(t))return 0;let r=0;for(let a of e)if(typeof a=="string")r+=a.length;else if(Array.isArray(a))r+=t==="len"?0:a.length;else if(p2(a)&&a.step!==0){let s=Math.floor((a.end-a.start)/a.step)+1;s>0&&(r+=Math.min(s,n+1))}return r}var c2=t=>P1("x",e=>typeof e[0]=="number"?g2(t(e[0])):void 0);function g2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function Q6(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var B5=new Map;function Vs(t){let e=B5.get(t);if(e)return e;let n=Q6(t),r=Array.from({length:256},(a,s)=>s);for(let a=255;a>0;a--){let s=Math.floor(n()*(a+1));[r[a],r[s]]=[r[s],r[a]]}e=new Uint8Array(512);for(let a=0;a<512;a++)e[a]=r[a&255];return B5.size>64&&B5.clear(),B5.set(t,e),e}var h4=t=>t*t*t*(t*(t*6-15)+10);function ie(t,e,n,r){let a=t&15,s=a<8?e:n,c=a<4?n:a===12||a===14?e:r;return((a&1)===0?s:-s)+((a&2)===0?c:-c)}function $s(t,e,n,r){let a=Vs(r),s=Math.floor(t),c=Math.floor(e),o=Math.floor(n);t-=s,e-=c,n-=o;let i=s&255,l=c&255,h=o&255,u=h4(t),f=h4(e),d=h4(n),m=a[i]+l,g=a[m]+h,p=a[m+1]+h,v=a[i+1]+l,b=a[v]+h,y=a[v+1]+h,M=(w,x,k)=>x+w*(k-x);return M(d,M(f,M(u,ie(a[g],t,e,n),ie(a[b],t-1,e,n)),M(u,ie(a[p],t,e-1,n),ie(a[y],t-1,e-1,n))),M(f,M(u,ie(a[g+1],t,e,n-1),ie(a[b+1],t-1,e,n-1)),M(u,ie(a[p+1],t,e-1,n-1),ie(a[y+1],t-1,e-1,n-1))))}function B6(t,e,n){let r=t.length===1&&Array.isArray(t[0])?t[0]:t;if(r.length)return e(r.map(a=>I1(a,n)))}var Z3={abs:c2(Math.abs),sign:c2(Math.sign),floor:c2(Math.floor),ceil:c2(Math.ceil),round:c2(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:c2(Math.sqrt),exp:c2(Math.exp),ln:c2(Math.log),log:P1("x, base",(t,e)=>e.given<2?g2(Math.log10(I1(t[0],"log"))):Math.log(I1(t[0],"log"))/Math.log(I1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:c2(t=>Math.sin(t*B0)),cos:c2(t=>Math.cos(t*B0)),tan:c2(t=>Math.tan(t*B0)),asin:c2(t=>Math.asin(t)/B0),acos:c2(t=>Math.acos(t)/B0),atan:c2(t=>Math.atan(t)/B0),atan2:P1("y, x",t=>g2(Math.atan2(I1(t[0],"atan2"),I1(t[1],"atan2"))/B0)),pow:P1("x, y",t=>Math.pow(I1(t[0],"pow"),I1(t[1],"pow"))),min:P1("values...",t=>B6(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:P1("values...",t=>B6(t,e=>e.reduce((n,r)=>r>n?r:n,-1/0),"max")),clamp:P1("x, low, high",t=>Math.min(Math.max(I1(t[0],"clamp"),I1(t[1],"clamp")),I1(t[2],"clamp"))),lerp:P1("a, b, t",t=>{let e=I1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((r,a)=>I1(r,"lerp")+(I1(n[a],"lerp")-I1(r,"lerp"))*e)}return I1(t[0],"lerp")+(I1(t[1],"lerp")-I1(t[0],"lerp"))*e}),norm:P1("v",(t,e)=>Math.sqrt(Z0(t[0],"norm",e).reduce((n,r)=>n+I1(r,"norm")**2,0))),cross:P1("a, b",(t,e)=>{let n=Z0(t[0],"cross",e).map(a=>I1(a,"cross")),r=Z0(t[1],"cross",e).map(a=>I1(a,"cross"));return n.length===2?n[0]*r[1]-n[1]*r[0]:[n[1]*r[2]-n[2]*r[1],n[2]*r[0]-n[0]*r[2],n[0]*r[1]-n[1]*r[0]]}),len:P1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:e2(t[0])?t[0].fields.size:void 0),keys:P1("record",t=>e2(t[0])?[...t[0].fields.keys()]:void 0),merge:P1("a, b",t=>{if(!e2(t[0])||!e2(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:P1("...",(t,e)=>{let n=t.reduce((r,a)=>r+(Array.isArray(a)?a.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(r=>Array.isArray(r)?r:[r])}),reverse:P1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...Z0(t[0],"reverse",e)].reverse()),sort:P1("values, key",(t,e)=>{let n=Z0(t[0],"sort",e),r=t[1],a=n.map(s=>[r===void 0?s:e.apply(r,[s]),s]);return e.step(Math.ceil(n.length*Math.log2(n.length+1))),a.sort((s,c)=>Z6(s[0],c[0],"sort",()=>e.step())).map(([,s])=>s)}),fold:P1("values, initial, fn",(t,e)=>{let n=t[1];for(let r of Z0(t[0],"fold",e))n=e.apply(t[2],[n,r]);return n}),scan:P1("values, initial, fn",(t,e)=>{let n=t[1];return Z0(t[0],"scan",e).map(r=>n=e.apply(t[2],[n,r]))}),bounds:P1("points",(t,e)=>{let n=f4(t[0],"bounds",e);if(!n.length)return;let[r,a,s,c]=[1/0,1/0,-1/0,-1/0];for(let[o,i]of n)r=Math.min(r,o),a=Math.min(a,i),s=Math.max(s,o),c=Math.max(c,i);return[r,a,s,c]}),crossings:P1("points, x, y",(t,e)=>{if(t[1]===void 0==(t[2]===void 0))throw new Error("crossings() needs one of x or y");let n=t[1]===void 0,r=I1(n?t[2]:t[1],"crossings"),a=[];for(let s of Ts(t[0],"crossings",e))for(let c=0,o=s.length-1;c<s.length;o=c++){let[i,l]=n?[s[o][1],s[o][0]]:s[o],[h,u]=n?[s[c][1],s[c][0]]:s[c];i>r!=h>r&&a.push(l+(u-l)*(r-i)/(h-i))}return a.sort((s,c)=>s-c)}),sum:P1("values",(t,e)=>Z0(t[0],"sum",e).reduce((n,r)=>n+I1(r,"sum"),0)),slice:P1("value, start, end",(t,e)=>{let r=(typeof t[0]=="string"?[...t[0]]:Z0(t[0],"slice",e)).slice(I1(t[1]??0,"slice"),t[2]===void 0?void 0:I1(t[2],"slice"));return typeof t[0]=="string"?r.join(""):r}),str:P1("...",(t,e)=>l4(t,"",e,"str")),chr:P1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(I1(e,"chr"))).join("")),ord:P1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:P1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:P1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:P1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:P1("values, separator",(t,e)=>l4(Z0(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:P1("value, list",(t,e)=>{let r=(typeof t[1]=="string"?[...t[1]]:Z0(t[1],"search",e)).findIndex(a=>Qe(a,t[0],e.step));return r<0?void 0:r}),contains:P1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(l4([t[1]],"",e,"contains")):Z0(t[0],"contains",e).some(n=>Qe(n,t[1],e.step))),lookup:P1("x, table",(t,e)=>{let n=I1(t[0],"lookup"),r=Z0(t[1],"lookup",e);if(!r.length)return;let a=r.map(s=>[I1(s[0],"lookup"),I1(s[1],"lookup")]).sort((s,c)=>s[0]-c[0]);if(n<=a[0][0])return a[0][1];for(let s=1;s<a.length;s++)if(n<=a[s][0]){let[c,o]=a[s-1],[i,l]=a[s];return o+(n-c)/(i-c)*(l-o)}return a[a.length-1][1]}),rands:P1("min, max, count, seed",t=>{let e=I1(t[0],"rands"),n=I1(t[1],"rands"),r=I1(t[2],"rands"),a=Q6(t[3]===void 0?1:I1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(r)),1e6)},()=>e+(n-e)*a())}),noise:P1("x, y, z, seed, octaves",t=>{let e,n=0,r=0;if(Array.isArray(t[0])){let h=t[0];e=I1(h[0],"noise"),n=h[1]===void 0?0:I1(h[1],"noise"),r=h[2]===void 0?0:I1(h[2],"noise")}else e=I1(t[0],"noise"),t[1]!==void 0&&(n=I1(t[1],"noise")),t[2]!==void 0&&(r=I1(t[2],"noise"));let a=Math.floor(t[3]===void 0?1:I1(t[3],"noise")),s=t[4]===void 0?1:Math.floor(I1(t[4],"noise"));if(!(s>=1&&s<=8))throw new Error("noise(): octaves must be 1 to 8");let c=0,o=1,i=0,l=1;for(let h=0;h<s;h++)c+=o*$s(e*l+h*.3713,n*l+h*.6271,r*l+h*.1943,a+h*7919),i+=o,o/=2,l*=2;return g2(c/i)}),is_num:P1("value",t=>N6(t[0])&&!Number.isNaN(t[0])),is_string:P1("value",t=>typeof t[0]=="string"),is_bool:P1("value",t=>typeof t[0]=="boolean"),is_list:P1("value",t=>Array.isArray(t[0])),is_record:P1("value",t=>e2(t[0])),is_undef:P1("value",t=>t[0]===void 0),is_function:P1("value",t=>x2(t[0])),type_of:P1("value",t=>X0(t[0])),path_length:P1("points",(t,e)=>{let n=X3(t[0],"path_length",e),r=0;for(let a=1;a<n.length;a++)r+=Math.hypot(n[a][0]-n[a-1][0],n[a][1]-n[a-1][1]);return r}),point_at:P1("points, s",(t,e)=>j6(X3(t[0],"point_at",e),I1(t[1],"point_at")).point),heading_at:P1("points, s",(t,e)=>g2(j6(X3(t[0],"heading_at",e),I1(t[1],"heading_at")).heading)),offset_path:P1("points, d, closed",(t,e)=>{let n=X3(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),r=I1(t[1],"offset_path"),a=t[2]===!0,s=a&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(s&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let c=n.length,o=l=>{let[h,u]=n[l%c],[f,d]=n[(l+1)%c],m=Math.hypot(f-h,d-u);return[-(d-u)/m,(f-h)/m]},i=n.map(([l,h],u)=>{let f=!a&&u===0,d=!a&&u===c-1,m=o(f?0:(u-1+c)%c),g=o(d?c-2:u),[p,v]=[m[0]+g[0],m[1]+g[1]],b=Math.hypot(p,v);if(b<1e-9)[p,v]=m;else{let y=Math.min(2/(b*b),4/b);[p,v]=[p*y,v*y]}return[g2(l+r*p),g2(h+r*v)]});return s?[...i,i[0]]:i}),train_for:P1("ratio, stages, pinion, wheel",(t,e)=>{let n=I1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let r=t[1]===void 0?2:I1(t[1],"train_for");if(!(r===1||r===2||r===3))throw new Error("train_for(): stages must be 1, 2 or 3");let a=(v,b,y)=>{if(v===void 0)return b;if(!Array.isArray(v)||v.length!==2||!v.every(x=>typeof x=="number"))throw new Error(`train_for(): ${y} must be [fewest, most] teeth`);let[M,w]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(M>=6&&w>=M&&w<=400))throw new Error(`train_for(): ${y} teeth must be from 6 to 400, fewest first`);return[M,w]},[s,c]=a(t[2],[10,20],"pinion"),[o,i]=a(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=s;v<=c;v++)for(let b=Math.max(o,v);b<=i;b++)u.push([v,b]);let f,d=v=>{let b=v.reduce((w,[x,k])=>w*k/x,1),y=Math.abs(b/h-1),M=v.reduce((w,[x,k])=>w+x+k,0);(!f||y<f.err-1e-12||Math.abs(y-f.err)<=1e-12&&M<f.teeth)&&(f={stages:v.map(w=>[...w]),err:y,teeth:M})},m=(v,b)=>{e.step();for(let y=s;y<=c;y++)for(let M of[Math.floor(b*y),Math.ceil(b*y)])M>=Math.max(o,y)&&M<=i&&d([...v,[y,M]])};if(r===1)m([],h);else for(let v=0;v<u.length;v++){let b=u[v][1]/u[v][0];if(r===2)m([u[v]],h/b);else for(let y=v;y<u.length;y++)m([u[v],u[y]],h/b/(u[y][1]/u[y][0]))}if(!f)throw new Error(`train_for(): no train of ${r} stages reaches a ratio of ${n}`);let g=f.stages.map(([v,b])=>l?[b,v]:[v,b]),p=g.reduce((v,[b,y])=>v*y/b,1);return{type:"record",fields:new Map([["stages",g],["ratio",p],["error",p/n-1]])}}),path_points:P1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:I1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let r=t3(n3(t[0]),n),a=[...r.closed.map(s=>[...s,s[0]]),...r.open];return e.step(a.reduce((s,c)=>s+c.length,0)),a.map(s=>s.map(([c,o])=>[c,o]))}),spline_points:P1("points, steps, closed",(t,e)=>{let n=X3(t[0],"spline_points",e),r=t[1]===void 0?8:Math.floor(I1(t[1],"spline_points"));if(!(r>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*r>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*r),d4(n,r,t[2]===!0)}),rotation:P1("angles",t=>{let[e,n,r]=u4(t[0],"rotation");return _s(W6(Fs(r),W6(Rs(n),Os(e))))}),euler:P1("matrix",t=>X6(Hs(t[0],"euler"))),orient:P1("x, z",t=>{let e=G6(u4(t[0],"orient"),"orient"),n=u4(t[1]??[0,0,1],"orient"),r=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=G6([n[0]-r*e[0],n[1]-r*e[1],n[2]-r*e[2]],"orient");let a=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return X6([[e[0],a[0],n[0]],[e[1],a[1],n[1]],[e[2],a[2],n[2]]])})};function X3(t,e,n){return Z0(t,e,n).map((a,s)=>{if(!Array.isArray(a)||typeof a[0]!="number"||typeof a[1]!="number")throw new Error(`${e}(): points[${s}] must be an [x, y] point`);return[a[0],a[1]]})}function j6(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([i,l],h)=>h===0||i!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let r=0,a=0;for(;r<n.length-2;r++){let i=Math.hypot(n[r+1][0]-n[r][0],n[r+1][1]-n[r][1]);if(a+i>=e)break;a+=i}let[s,c]=[n[r],n[r+1]],o=(e-a)/Math.hypot(c[0]-s[0],c[1]-s[1]);return{point:[s[0]+(c[0]-s[0])*o,s[1]+(c[1]-s[1])*o],heading:Math.atan2(c[1]-s[1],c[0]-s[0])/B0}}function u4(t,e){if(!Array.isArray(t)||t.length<2||t.length>3||!t.every(n=>typeof n=="number"))throw new Error(`${e}() needs [x, y, z]`);return[t[0],t[1],t[2]??0]}function G6(t,e){let n=Math.hypot(...t);if(!(n>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[t[0]/n,t[1]/n,t[2]/n]}function Hs(t,e){if(!Array.isArray(t)||t.length<3||!t.slice(0,3).every(n=>Array.isArray(n)&&n.length>=3&&n.slice(0,3).every(r=>typeof r=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var Os=t=>{let[e,n]=[Math.cos(t*B0),Math.sin(t*B0)];return[[1,0,0],[0,e,-n],[0,n,e]]},Rs=t=>{let[e,n]=[Math.cos(t*B0),Math.sin(t*B0)];return[[e,0,n],[0,1,0],[-n,0,e]]},Fs=t=>{let[e,n]=[Math.cos(t*B0),Math.sin(t*B0)];return[[e,-n,0],[n,e,0],[0,0,1]]},W6=(t,e)=>t.map(n=>[0,1,2].map(r=>n[0]*e[0][r]+n[1]*e[1][r]+n[2]*e[2][r])),_s=t=>t.map(e=>e.map(g2));function X6(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,r=Math.atan2(-t[0][1],t[1][1])/B0;return[0,n,g2(r)]}return[g2(Math.atan2(t[2][1],t[2][2])/B0),g2(Math.asin(e)/B0),g2(Math.atan2(t[1][0],t[0][0])/B0)]}function d4(t,e,n=!1){if(t.length<3)return t.map(([c,o])=>[c,o]);let r=c=>{if(n)return t[(c%t.length+t.length)%t.length];if(c<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(c>=t.length){let[o,i]=[t[t.length-1],t[t.length-2]];return[2*o[0]-i[0],2*o[1]-i[1]]}return t[c]},a=[],s=n?t.length:t.length-1;for(let c=0;c<s;c++){let[o,i,l,h]=[r(c-1),r(c),r(c+1),r(c+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,m=d*f;a.push([0,1].map(g=>.5*(2*i[g]+(-o[g]+l[g])*f+(2*o[g]-5*i[g]+4*l[g]-h[g])*d+(-o[g]+3*i[g]-3*l[g]+h[g])*m)))}}return a.push(n?a[0]:[t[t.length-1][0],t[t.length-1][1]]),a}function Ee(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var Y3=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function qs(t,e,n,r){if(e==="flat")return[];let a=Ee(t,r),s=t/a,c=[];for(let o=0;o<a;o++)(e==="out"?o%2===1:o%2===0)&&c.push(Y3(o*s,-1,(o+1)*s,n));return c}function j5(t,e,n,r,a){let s=[([i,l])=>[i,l],([i,l])=>[t-l,i],([i,l])=>[t-i,e-l],([i,l])=>[l,e-i]],c=[t,e,t,e],o=[];return n.forEach((i,l)=>{for(let h of qs(c[l],i,r,a))o.push(h.map(s[l]))}),d0([Y3(0,0,t,e)],o)}function e7(t,e,n,r){let a=Ee(t,r),s=t/a,c=[];for(let o=0;o<a;o++)(e==="out"?o%2===0:o%2===1)&&c.push(Y3(o*s,-n/2,(o+1)*s,n/2));return c}function t7(t,e,n,r,a){let s=Y3(-t/2,-1,t/2,e),c=Y3(-n/2,a,n/2,a+r);return[s,c]}function n7(t,e,n,r,a){let s=[],c=a+r,o=Math.floor(t/n),i=(t-o*n)/2;for(let l=0;l<=o;l++){let h=i+l*n,u=l%2===0?r:r-c/2;for(let f=u;f<e;f+=c){let d=Math.max(f,l%2===0?r:0),m=Math.min(f+a,e-(l%2===0?r:0));m-d>=r/2&&s.push([[h,d],[h,m]])}}return s}var t2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var i1=class extends Error{constructor(n,r){super(r?`${n} (${t2(r)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,r&&(this.line=r.line,this.col=r.col,this.file=r.file)}addFrame(n,r,a){let s=this.trace.find(c=>c.name===r&&c.line===a.line&&c.col===a.col&&c.file===a.file);s?s.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:r,line:a.line,col:a.col,...a.file&&{file:a.file},count:1})}},Ds=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function r3(t,e){let n=[],r=[],a=0,s=1,c=0,o=()=>({line:s,col:a-c+1,offset:a,...e&&{file:e}}),i=l=>{for(let h=0;h<l;h++)t[a]===`
7
7
  `&&(s++,c=a+1),a++};for(;a<t.length;){let l=t[a];if(l===" "||l===" "||l==="\r"||l===`
8
8
  `){i(1);continue}if(l==="/"&&t[a+1]==="/"){let f=t.indexOf(`
9
9
  `,a),d=f<0?t.length:f,m=/^[ \t]*$/.test(t.slice(t.lastIndexOf(`
10
10
  `,a-1)+1,a));r.push({text:t.slice(a+2,d).trim(),line:s,block:!1,own:m,start:a,end:d}),a=d;continue}if(l==="/"&&t[a+1]==="*"){let f=o(),d=t.indexOf("*/",a+2);if(d<0)throw new i1("Unclosed block comment",f);r.push({text:t.slice(a+2,d).trim(),line:f.line,block:!0,own:!0,start:a,end:d+2}),i(d+2-a);continue}let h=o();if(/[0-9]/.test(l)||l==="."&&/[0-9]/.test(t[a+1]??"")){let f=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(t.slice(a));n.push({type:"num",value:f[0],pos:h,end:a+f[0].length}),i(f[0].length);continue}if(/[A-Za-z_$]/.test(l)){let f=/^[A-Za-z_$][A-Za-z0-9_]*/.exec(t.slice(a));n.push({type:"id",value:f[0],pos:h,end:a+f[0].length}),i(f[0].length);continue}if(l==='"'){let f="";for(i(1);a<t.length&&t[a]!=='"';){if(t[a]==="\\"){let d=t[a+1];if(d==="n")f+=`
11
11
  `;else if(d==="t")f+=" ";else if(d==="u"){let m=t.slice(a+2,a+6);if(!/^[0-9a-fA-F]{4}$/.test(m))throw new i1("Bad \\u escape",o());f+=String.fromCharCode(parseInt(m,16)),i(4)}else f+=d;i(2);continue}if(t[a]===`
12
- `)throw new i1("Unclosed string",h);f+=t[a],i(1)}if(a>=t.length)throw new i1("Unclosed string",h);i(1),n.push({type:"str",value:f,pos:h,end:a});continue}if(l==="<"){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([^<>\r\n]+)>/.exec(t.slice(a,a+4097));if(d){n.push({type:"str",value:d[1],pos:h,end:a+d[0].length}),i(d[0].length);continue}}}let u=Ds.find(f=>t.startsWith(f,a));if(!u)throw new i1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:a+u.length}),i(u.length)}return n.push({type:"eof",value:"",pos:o(),end:a}),{tokens:n,comments:r}}var X2={dowel:{color:"#e2c48f",doc:"a wooden dowel or axle"},steel:{color:"#a7adb3",metal:!0,doc:"a steel rod, pin or axle"},brass:{color:"#c9a227",metal:!0,doc:"a brass rod, tube or pin"},screw:{color:"#9aa0a6",metal:!0,doc:"a screw"},bolt:{color:"#9aa0a6",metal:!0,doc:"a bolt"},nut:{color:"#9aa0a6",metal:!0,doc:"a nut"},magnet:{color:"#55585c",metal:!0,doc:"a disc or block magnet"},paper:{color:"#fbfaf6",translucent:!0,doc:"a sheet or strip of paper"},vellum:{color:"#f3efe2",translucent:!0,doc:"vellum or tracing paper, as a lantern window that a light shines through"},card:{color:"#f4f1e8",doc:"card stock"},felt:{color:"#6f6a64",doc:"felt pads or lining"},elastic:{color:"#262626",doc:"an elastic band or cord"},cord:{color:"#b23a3a",doc:"cord, string or thread"},ribbon:{color:"#c2485a",doc:"ribbon or tape"},wire:{color:"#b87333",metal:!0,doc:"wire"},led:{color:"#fff4c2",glow:!0,doc:"an LED or a strip of them, giving off light"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb, giving off light; give it shape = "ball"'},tealight:{color:"#d4d8dc",metal:!0,doc:"a tealight, 39 mm across and 16 mm high, standing at from; its flame flickers"},ball:{color:"#8fb8d8",doc:'a marble, ball or bead; give it shape = "ball"'},tube:{color:"#c9a227",metal:!0,doc:"a tube, as a hollow arbor or a sleeve"},lens:{color:"#d6ecf3",doc:"a lens, a thin disc of glass or acrylic"},mirror:{color:"#c8d3da",metal:!0,doc:"a mirror"},movement:{color:"#3d3d3d",doc:"a bought movement, as a clock, music box or motor: a labelled block"},white:{color:"#f7f7f4",doc:"anything white"}},le={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var d4={red:"#c8372d",orange:"#e8742a",yellow:"#f2c230",green:"#3f8f4a","dark green":"#24582f","light green":"#8cc06a",blue:"#2f64b5","dark blue":"#1d3570","light blue":"#86b6e3",navy:"#1f2d55",teal:"#2a8c88",purple:"#7a4aa0",pink:"#ec8fb2",brown:"#7a4e2d",tan:"#d2b48c",cream:"#f3e9cf",white:"#f7f7f4",black:"#222222",grey:"#8f8f8f",gray:"#8f8f8f",silver:"#c0c4c8",gold:"#c9a227",copper:"#b87333",skin:"#f1c9a5","light grey":"#cfcfca","light gray":"#cfcfca","dark grey":"#4a4a4a","dark gray":"#4a4a4a","light brown":"#b07f4f","dark brown":"#4a2e1a",beige:"#e9d6b4",peach:"#f6b892","light pink":"#f8cbd8",maroon:"#7a1f2b","light yellow":"#f8e48a",lime:"#9ccc3c",olive:"#6b7a2f"};function Y3(t){let e=t.trim().toLowerCase();return/^#[0-9a-f]{6}$/.test(e)?e:d4[e.replace(/\s+/g," ")]}var a3={flame:"#ff9a3c",candle:"#ff9a3c",warm:"#ffc27a","warm white":"#ffd9a0",white:"#fff4e5","cool white":"#eef3ff"};function a7(t){let e=t.trim().toLowerCase().replace(/\s+/g," ");return a3[e]??Y3(e)}var s3={diameter:39,height:16,flame:10},s7=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],c7=t=>Math.hypot(t[0],t[1],t[2]),r7=(t,e)=>[(t[0]+e[0])/2,(t[1]+e[1])/2,(t[2]+e[2])/2];function o7(t){let e={step:t.step,...t.label!==void 0&&{label:t.label}},n=s7(t.to,t.from),r=c7(n);if(t.kind==="tealight"){let a=r>0?[n[0]/r,n[1]/r,n[2]/r]:[0,0,1],s=[t.to[0]+a[0]*s3.flame,t.to[1]+a[1]*s3.flame,t.to[2]+a[2]*s3.flame];return[{from:s,to:s,color:a3.flame,lumens:12,flicker:!0,source:"tealight",...e}]}if(t.kind==="led"){let a=r>20,s=r7(t.from,t.to);return[{from:a?t.from:s,to:a?t.to:s,color:a3["warm white"],lumens:a?Math.round(r*2)/10:20,flicker:!1,source:"led",...e}]}if(t.kind==="bulb"){let a=r7(t.from,t.to);return[{from:a,to:a,color:a3["warm white"],lumens:100,flicker:!1,source:"bulb",...e}]}return[]}function j5(t,e=8){let n=s7(t.to,t.from),r=c7(n);if(!(r>0))return[{at:t.from,lumens:t.lumens}];let a=Math.max(2,Math.min(e,Math.ceil(r/50)));return Array.from({length:a},(s,c)=>{let o=(c+.5)/a;return{at:[t.from[0]+n[0]*o,t.from[1]+n[1]*o,t.from[2]+n[2]*o],lumens:t.lumens/a}})}var m4=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function n2(t,e){let{tokens:n,comments:r}=r3(t,e),a=new p4(n),s=[];for(;!a.at("eof");)s.push(...a.statement());return{program:{body:s},comments:r}}var K3=class K3{constructor(e){this.tokens=e;this.i=0}peek(e=0){return this.tokens[Math.min(this.i+e,this.tokens.length-1)]}at(e,n,r=0){let a=this.peek(r);return a.type===e&&(n===void 0||a.value===n)}isP(e,n=0){return this.at("punct",e,n)}isK(e,n=0){return this.at("id",e,n)}next(){return this.tokens[this.i++]}fail(e,n=this.peek()){let r=n.type==="eof"?"end of file":`"${n.value}"`;throw new i1(`${e}, found ${r}`,n.pos)}expectP(e){return this.isP(e)||this.fail(`Expected "${e}"`),this.next()}separator(e){this.isP(e)||(this.isP(",")||this.fail(`Expected "," or "${e}"`),this.next())}ident(){let e=this.peek();return(e.type!=="id"||m4.has(e.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let e=this.stmt();for(let n of e)n.end=this.last();return e}stmt(){let e=this.peek();if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let c=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),c.push(...this.statement());return this.next(),[{kind:"block",body:c,pos:e.pos}]}if(this.isK("module")){this.next();let c=this.ident(),o=this.params();return[{kind:"module",name:c.value,params:o,body:this.body(),pos:e.pos,namePos:c.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let c=this.ident(),o=this.params();this.expectP("=");let i=this.expr();return this.expectP(";"),[{kind:"function",name:c.value,params:o,body:i,pos:e.pos,namePos:c.pos}]}if(this.isK("use")||this.isK("include")){this.next();let c=this.peek();return c.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:c.value,include:e.value==="include",pos:e.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(this.isK("intersection_for")&&this.isP("(",1))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos,intersect:!0}];if(this.isK("if")){this.next(),this.expectP("(");let c=this.expr();this.expectP(")");let o=this.body(),i=[];return this.isK("else")&&(this.next(),i=this.body()),[{kind:"if",cond:c,then:o,else:i,pos:e.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(e.type==="id"&&this.isP("=",1)){let c=this.ident().value;this.next();let o=this.peek().pos.offset,i=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:c,value:i,span:[o,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let r=this.peek();(r.type!=="id"||m4.has(r.value))&&this.fail("Expected a statement"),this.next();let a=this.args(),s=this.body();return[{kind:"call",name:r.value,args:a,children:s,modifier:n,pos:r.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident(),r=null;this.isP("=")&&(this.next(),r=this.expr()),e.push({name:n.value,default:r,pos:n.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let n=this.next();this.next(),e.push({name:n.value,value:this.expr(),pos:n.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident();this.expectP("="),e.push({name:n.value,value:this.expr(),pos:n.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let r=this.params(),a=this.expr();return{kind:"lambda",params:r,body:a,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let r=this.assigns(),a=this.expr();return{kind:"let",assigns:r,body:a,pos:e.pos,end:this.last()}}if(this.at("id")&&(e.value==="assert"||e.value==="echo")&&this.isP("(",1)){let r=this.i;this.next();let a={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:a,body:this.expr(),pos:e.pos};this.i=r}let n=this.binary(0);if(this.isP("?")){this.next();let r=this.expr();this.expectP(":");let a=this.expr();return{kind:"ternary",cond:n,then:r,else:a,pos:e.pos}}return n}binary(e){if(e>=K3.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&K3.LEVELS[e].includes(this.peek().value);){let r=this.next(),a=this.binary(e+1);n={kind:"binary",op:r.value,left:n,right:a,pos:r.pos}}return n}startsValue(){let e=this.peek();return e.type==="num"||e.type==="str"||e.type==="id"?!0:this.isP("[")||this.isP("(")||this.isP("{")||this.isP("!")||this.isP("-")}unary(){if((this.isK("let")||this.isK("function"))&&this.isP("(",1))return this.expr();if(this.isP("-")||this.isP("!")||this.isP("+")){let e=this.next();return{kind:"unary",op:e.value,arg:this.unary(),pos:e.pos}}return this.power()}power(){let e=this.postfix();if(this.isP("^")){let n=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:n.pos}}return e}postfix(){let e=this.primary();for(;;){let n=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let r=this.expr();this.expectP("]"),e={kind:"index",target:e,index:r,pos:n.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:n.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let n=/(mm|cm|m|in|ft)$/.exec(e.value);return n?{kind:"num",value:Number(e.value.slice(0,-n[1].length)),unit:n[1],pos:e.pos}:{kind:"num",value:Number(e.value),pos:e.pos}}if(e.type==="str")return this.next(),{kind:"str",value:e.value,pos:e.pos};if(e.type==="id")return e.value==="true"||e.value==="false"?(this.next(),{kind:"bool",value:e.value==="true",pos:e.pos}):e.value==="undef"?(this.next(),{kind:"undef",pos:e.pos}):(m4.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let n=this.expr();return this.expectP(")"),n}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),n=[];for(;!this.isP("}");){let r=this.ident();if(n.some(a=>a.name===r.value))throw new i1(`Field ${r.value} is given twice`,r.pos);if(this.expectP("="),n.push({name:r.value,value:this.expr(),pos:r.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:n,pos:e.pos}}list(){let e=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:e.pos};if(!this.isK("for")&&!this.isK("if")&&!this.isK("each")&&!(this.isK("let")&&this.isP("(",1))&&!(this.isP("(")&&(this.isK("for",1)||this.isK("if",1)))){let n=this.expr();if(this.isP(":")){this.next();let a=null,s=this.expr();return this.isP(":")&&(this.next(),a=s,s=this.expr()),this.expectP("]"),{kind:"range",start:n,step:a,end:s,pos:e.pos}}let r=[{kind:"item",expr:n}];return this.listRest(r,e.pos)}return this.listRest([],e.pos)}listRest(e,n){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:n};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:n}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"for",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let r=this.listItem(),a=null;return this.isK("else")&&(this.next(),a=this.listItem()),{kind:"if",cond:n,then:r,else:a}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"let",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let n=this.listItem();return this.expectP(")"),n}return{kind:"item",expr:this.expr()}}};K3.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var p4=K3;var R=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),f1=(t,e,n)=>({...R(t,e,n),named:!0}),g4="max(3 * $thickness, 6)",G5=[R("value")],Ns=[R("x")],o2=(t,e)=>({name:t,kind:"function",params:Ns,section:"Numbers and vectors",doc:e}),Te=(t,e)=>({name:t,kind:"function",params:G5,section:"Types",doc:`Whether the value is ${e}`}),v4=(t,e)=>({name:t,kind:"function",params:[R("text","The text to measure",'""'),R("size","Font size in millimetres","10"),R("font","Font name","$font"),f1("halign","left, center or right",'"left"'),f1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),f1("spacing","Letter spacing factor","1"),f1("fit","Measure at the size that fits this width, or [width, cap height]")],section:"Text measurements",doc:e}),b4=[{name:"rect",kind:"module",params:[R("size","A number, or [width, height]","1"),R("center","Centre the rectangle on the origin instead of its corner","false"),f1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[R("size","A number, or [width, height]","1"),R("center","Centre the square on the origin instead of its corner","false"),f1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[R("r","Radius","1"),f1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[R("r","[rx, ry], or one radius for both","1"),f1("d","[width, height], or one diameter for both, instead of r")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[R("n","Number of corners","6"),R("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[R("n","Number of points","5"),R("r","Radius of the points","10"),R("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[R("points","A list of [x, y] points"),R("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[R("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),f1("fill",'"evenodd" or "nonzero"','"evenodd"'),f1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[R("text","The text",'""'),R("size","Font size in millimetres","10"),R("font","Font name","$font"),f1("halign","left, center or right",'"left"'),f1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),f1("spacing","Letter spacing factor","1"),f1("fit","Shrink the size so the text is no wider than this, or fits [width, cap height]"),f1("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),f1("bridge","Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide"),f1("weld","Slide each word's letters together into one piece, as a script name is cut; a number is how far each overlaps the one before, in mm","false"),f1("underline","With weld: a bar this high under the baseline, joining the words"),f1("lines","Break the text at spaces into up to this many lines; with fit, as many as let it be biggest","1"),f1("line_spacing","The distance between lines, as a share of the usual","1"),f1("path","Lay the text along these [x, y] points, each letter turned to the path, centred on it"),f1("arc","Lay the text round a circle of this radius about the origin: over the top, or along the bottom when less than 0")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[R("from","Start point","[0, 0]"),R("to","End point","[10, 0]"),R("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[R("points","A list of [x, y] points"),R("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[R("r","Radius","10"),R("start","Start angle in degrees","0"),R("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[R("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[R("a","Angle in degrees, anticlockwise","0"),f1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[R("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[R("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[R("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[R("r","Grow (positive) or shrink areas with rounded corners"),f1("delta","Grow or shrink areas with sharp corners","0"),f1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[R("spacing","Distance between copies, a number or [x, y]","10"),R("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[R("points","The [x, y] points the curve goes through"),R("width","Make an area this wide along the curve, instead of a line"),f1("steps","Points between each two given ones","8"),f1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[R("angle","Direction of the lines, in degrees from +x","45"),R("pitch","Distance between the lines","5"),R("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"flow",kind:"module",params:[R("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),R("spacing","Distance between neighbouring lines","2"),R("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),f1("min_length","Lines shorter than this are left out","spacing * 2"),f1("seed","Where the first lines start; another seed gives another arrangement","1")],children:!0,section:"Combining",doc:"Evenly spaced lines that follow a direction field across the area of the children, never closer than half the spacing"},{name:"contours",kind:"module",params:[R("field","The height at a point: function(p) giving a number, or undef for none"),R("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),f1("interval","Instead of levels: every multiple of this height"),f1("cell","Distance between the points sampled: smaller is finer and slower","1")],children:!0,section:"Combining",doc:"Contour lines where a height field crosses each level, across the area of the children"},{name:"occlude",kind:"module",params:[],children:!0,section:"Combining",doc:"Children back to front, each opaque: lines and outlines hide behind the areas of later children, and fills lose that area. Each iteration of a for loop is a child of its own"},{name:"hide",kind:"module",params:[],children:!0,section:"Combining",doc:"Inside occlude(): an area that hides what is behind it but is not drawn"},{name:"paint",kind:"module",params:[R("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[R("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1], $area and $centroid = [x, y] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[R("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"join_islands",kind:"module",params:[R("width","How wide each joining strip is","1")],children:!0,section:"Combining",doc:"Join every separate piece of the material to the nearest other piece with a strip, until it is one piece"},{name:"largest",kind:"module",params:[R("n","How many pieces to keep","1")],children:!0,section:"Combining",doc:"Keep the n biggest connected pieces of the material, dropping crumbs; marks stay as drawn"},{name:"close",kind:"module",params:[R("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[R("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[R("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[R("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[R("name","Layer name"),R("mode",'"cut", "line", "fill", "guide" or "paint" (shown in 3D, not cut)'),R("color",'Colour in the output, as "#00aa00" or a name, as "red"'),f1("order","Where it goes among the custom layers in the files, lowest first","0"),f1("bleed","How far past the part's edge it may print","0"),f1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[R("name","Part name",'"part"'),R("qty","Number of copies to cut","1"),f1("at","Where the part goes in the assembled view, [x, y, z]"),f1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),f1("stack","Layers glued in a stack at each placement, one thickness apart","1"),f1("mirror","Cut the part mirrored left to right, its text still reading","false"),f1("material","The material it is cut from, as material(name = ...) sets it"),f1("pieces",'How many separate pieces it cuts into, as a pair of eyes, or "any": no warning that it is in pieces',"1"),f1("paint",'Its colour in the 3D view and the print layout, as "red" or "#c8372d"; the part stays on the sheet of its material'),f1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),f1("fold","Folds along any line in the assembled view, as for card: [from, to, angle] or a list; more than 0 folds towards the top face"),f1("fold_open","How far the folds are folded: 0 lies flat, 1 as their angles say","1"),f1("hang","The point [x, y] on the part it hangs from, at `at`: it swings in its own plane until its weight is below"),f1("cord","The cord it hangs on, in mm; 0 for a ring or pin","0"),f1("split","Cut a part too big for the bed into pieces joined by jigsaw knobs: true for the sheet, or [width, height]"),f1("on","The name of a bent part this one is glued to, to move with it"),f1("slots","Names of parts whose tabs pass through this one: their slots are cut"),f1("clearance","Added to the slots, in total across each","0.1"),f1("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),f1("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),f1("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),f1("fit",'Room in the bores: "turn" (0.3 mm on the diameter) for a part that turns on its axle, "press" (-0.1 mm) for one held fast, or a number of mm','"turn"'),f1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),f1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"'),f1("press_fit","Pressed into the glue part, as an inlay: they overlap on purpose, so they are not checked against each other","false")],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[R("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),R("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[R("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[R("text","What to do in this step",'""'),R("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[R("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),R("from","One end, [x, y, z]; a ball sits midway between from and to"),R("to","The other end, [x, y, z]; a ball may leave it out"),R("size","Diameter, or [width, height] for a flat section","6"),f1("up","The direction a [width, height] section's height points"),f1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),f1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),f1("label","The name in the hardware list"),f1("mass","Its weight in grams, for the check that the model stands, as an egg in a holder")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"light",kind:"module",params:[R("at","Where the light is, [x, y, z]","[0, 0, 0]"),R("color",`Its colour: "warm white", "white", "cool white", "warm", "flame", a colour's name or "#ffd9a0"`,'"warm white"'),R("lumens","How much light it gives off: a tealight is about 12","20"),f1("to","The other end of a strip of light, [x, y, z]: it lights all along"),f1("flicker","A flame: it flickers in the 3D view","false"),f1("label","Its name in 3D files")],children:!0,section:"Parts and sheets",doc:"A light source in the 3D view and GLB files, with nothing to show for it"},{name:"material",kind:"module",params:[R("thickness","Sets $thickness"),R("kerf","Sets $kerf"),R("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[R("size","[width, height]"),R("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),R("finger","Finger width",g4)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[R("length","Length of the edge that plugs in"),R("edge",'"out" or "in", the kind of edge that plugs in','"out"'),R("finger","Finger width",g4)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[R("d","Screw diameter","3"),R("length","Screw length into the panel","12"),R("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),R("nut_at","Distance of the nut from the edge","length / 2")],section:"Joinery",doc:"A T-slot for a screw and nut, opening at y = 0; subtract it from a panel edge"},{name:"living_hinge",kind:"module",params:[R("size","[width, height]"),R("spacing","Distance between the rows of cuts","1.5"),R("bridge","Uncut length between cuts","3"),R("cut","Length of each cut","max(bridge * 2, (height - 3 * bridge) / 2)")],section:"Joinery",doc:"A straight-line flex pattern of cut lines filling [width, height]"},{name:"children",kind:"module",params:[R("index","Which child, from 0, or a list of them")],section:"Other",doc:"Run the child statements passed to the current module"},{name:"echo",kind:"both",params:[],rest:!0,anyNamed:!0,section:"Other",doc:"Write values to the output without making shapes"},{name:"assert",kind:"both",params:[R("condition","Stops the program when false"),R("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},o2("abs","Absolute value"),o2("sign","Sign as -1, 0 or 1"),o2("floor","Round down"),o2("ceil","Round up"),o2("round","Round to the nearest integer, halves away from zero"),o2("sqrt","Square root"),o2("exp","e raised to x"),o2("ln","Natural logarithm"),{name:"log",kind:"function",params:[R("x"),R("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},o2("sin","Sine of an angle in degrees"),o2("cos","Cosine of an angle in degrees"),o2("tan","Tangent of an angle in degrees"),o2("asin","Inverse sine, in degrees"),o2("acos","Inverse cosine, in degrees"),o2("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[R("y"),R("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[R("x"),R("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[R("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[R("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[R("x"),R("low"),R("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[R("a"),R("b"),R("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[R("ratio","Turns in for one turn out; under 1 speeds up"),R("stages","Pairs of gears, 1 to 3","2"),R("pinion","Fewest and most teeth of the small gears","[10, 20]"),R("wheel","Fewest and most teeth of the big gears","[20, 80]")],section:"Numbers and vectors",doc:"Tooth counts for a gear train nearest a ratio: {stages = [[driver, driven], ...], ratio, error}"},{name:"norm",kind:"function",params:[R("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[R("a"),R("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[R("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"offset_path",kind:"function",params:[R("points","A list of [x, y] points"),R("d","How far to move it: to the left going along it, or the right when less than 0"),R("closed","The path goes round, its last point joined to its first","false")],section:"Paths and rotations",doc:"The path moved sideways, each corner mitred: the two edges of a strip along a curve"},{name:"bounds",kind:"function",params:[R("points","A list of [x, y] points, or of outlines")],section:"Paths and rotations",doc:"[x0, y0, x1, y1] round the points; undef for none"},{name:"crossings",kind:"function",params:[R("points","A closed outline of [x, y] points, or a list of outlines"),R("x","The vertical line x = this"),R("y","Or the horizontal line y = this")],section:"Paths and rotations",doc:"Where the line crosses the outline: the y (or x) values, smallest first, entering and leaving in turn"},{name:"point_at",kind:"function",params:[R("points","A list of [x, y] points"),R("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[R("points","A list of [x, y] points"),R("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[R("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),R("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[R("points","The [x, y] points the curve goes through"),R("steps","Points between each two given ones","8"),R("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[R("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[R("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[R("x","Where the part's own x axis points"),R("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:G5,section:"Lists and strings",doc:"Number of items in a list, characters in a string or fields in a record"},{name:"keys",kind:"function",params:[R("record","A record, as {name = value}")],section:"Lists and strings",doc:"A record's field names, in the order they were written"},{name:"merge",kind:"function",params:[R("a","A record"),R("b","A record whose fields add to or replace those of a")],section:"Lists and strings",doc:"A record with the fields of a and b, b winning where both have one"},{name:"concat",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Join lists and single values into one list"},{name:"reverse",kind:"function",params:G5,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[R("values","A list of numbers, strings or lists of them"),R("key","A function giving the value to order each item by")],section:"Lists and strings",doc:"The list in order, smallest first; items with equal keys keep their order"},{name:"fold",kind:"function",params:[R("values","A list"),R("initial","The value to start from"),R("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after fn(acc, item) for each item in turn, from initial: initial for an empty list"},{name:"scan",kind:"function",params:[R("values","A list"),R("initial","The value to start from"),R("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after each item as fold() goes: running totals, one per item"},{name:"sum",kind:"function",params:[R("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[R("value","A list or string"),R("start","First index","0"),R("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[R("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[R("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[R("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[R("text"),R("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[R("values"),R("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[R("value"),R("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[R("value","A list or string"),R("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[R("x"),R("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},Te("is_num","a number other than NaN"),Te("is_string","a string"),Te("is_bool","true or false"),Te("is_list","a list"),Te("is_undef","undef"),Te("is_function","a function"),Te("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:G5,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[R("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),R("y",void 0,"0"),R("z","A third axis: step it to get a related but different pattern","0"),f1("seed","A different seed gives a different pattern","1"),f1("octaves","Layers of finer detail, 1 to 8","1")],section:"Random values",doc:"Smooth noise between about -1 and 1 that changes gradually from point to point: 0 at whole numbers, so scale the point down (x / 30) for broad shapes"},{name:"rands",kind:"function",params:[R("min"),R("max"),R("count"),R("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},v4("text_width","The advance width of the text, including spacing"),v4("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),v4("text_size","The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"),{name:"finger_count",kind:"function",params:[R("length","Edge length"),R("finger","Finger width",g4)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],Us=new Map(b4.map(t=>[t.name,t])),c3=t=>Us.get(t);function W5(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var J3={"kerf/box":`// kerf/box: finger-jointed boxes.
12
+ `)throw new i1("Unclosed string",h);f+=t[a],i(1)}if(a>=t.length)throw new i1("Unclosed string",h);i(1),n.push({type:"str",value:f,pos:h,end:a});continue}if(l==="<"){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([^<>\r\n]+)>/.exec(t.slice(a,a+4097));if(d){n.push({type:"str",value:d[1],pos:h,end:a+d[0].length}),i(d[0].length);continue}}}let u=Ds.find(f=>t.startsWith(f,a));if(!u)throw new i1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:a+u.length}),i(u.length)}return n.push({type:"eof",value:"",pos:o(),end:a}),{tokens:n,comments:r}}var X2={dowel:{color:"#e2c48f",doc:"a wooden dowel or axle"},steel:{color:"#a7adb3",metal:!0,doc:"a steel rod, pin or axle"},brass:{color:"#c9a227",metal:!0,doc:"a brass rod, tube or pin"},screw:{color:"#9aa0a6",metal:!0,doc:"a screw"},bolt:{color:"#9aa0a6",metal:!0,doc:"a bolt"},nut:{color:"#9aa0a6",metal:!0,doc:"a nut"},magnet:{color:"#55585c",metal:!0,doc:"a disc or block magnet"},paper:{color:"#fbfaf6",translucent:!0,doc:"a sheet or strip of paper"},vellum:{color:"#f3efe2",translucent:!0,doc:"vellum or tracing paper, as a lantern window that a light shines through"},card:{color:"#f4f1e8",doc:"card stock"},felt:{color:"#6f6a64",doc:"felt pads or lining"},elastic:{color:"#262626",doc:"an elastic band or cord"},cord:{color:"#b23a3a",doc:"cord, string or thread"},ribbon:{color:"#c2485a",doc:"ribbon or tape"},wire:{color:"#b87333",metal:!0,doc:"wire"},led:{color:"#fff4c2",glow:!0,doc:"an LED or a strip of them, giving off light"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb, giving off light; give it shape = "ball"'},tealight:{color:"#d4d8dc",metal:!0,doc:"a tealight, 39 mm across and 16 mm high, standing at from; its flame flickers"},ball:{color:"#8fb8d8",doc:'a marble, ball or bead; give it shape = "ball"'},tube:{color:"#c9a227",metal:!0,doc:"a tube, as a hollow arbor or a sleeve"},lens:{color:"#d6ecf3",doc:"a lens, a thin disc of glass or acrylic"},mirror:{color:"#c8d3da",metal:!0,doc:"a mirror"},movement:{color:"#3d3d3d",doc:"a bought movement, as a clock, music box or motor: a labelled block"},white:{color:"#f7f7f4",doc:"anything white"}},le={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var m4={red:"#c8372d",orange:"#e8742a",yellow:"#f2c230",green:"#3f8f4a","dark green":"#24582f","light green":"#8cc06a",blue:"#2f64b5","dark blue":"#1d3570","light blue":"#86b6e3",navy:"#1f2d55",teal:"#2a8c88",purple:"#7a4aa0",pink:"#ec8fb2",brown:"#7a4e2d",tan:"#d2b48c",cream:"#f3e9cf",white:"#f7f7f4",black:"#222222",grey:"#8f8f8f",gray:"#8f8f8f",silver:"#c0c4c8",gold:"#c9a227",copper:"#b87333",skin:"#f1c9a5","light grey":"#cfcfca","light gray":"#cfcfca","dark grey":"#4a4a4a","dark gray":"#4a4a4a","light brown":"#b07f4f","dark brown":"#4a2e1a",beige:"#e9d6b4",peach:"#f6b892","light pink":"#f8cbd8",maroon:"#7a1f2b","light yellow":"#f8e48a",lime:"#9ccc3c",olive:"#6b7a2f"};function K3(t){let e=t.trim().toLowerCase();return/^#[0-9a-f]{6}$/.test(e)?e:m4[e.replace(/\s+/g," ")]}var a3={flame:"#ff9a3c",candle:"#ff9a3c",warm:"#ffc27a","warm white":"#ffd9a0",white:"#fff4e5","cool white":"#eef3ff"};function a7(t){let e=t.trim().toLowerCase().replace(/\s+/g," ");return a3[e]??K3(e)}var s3={diameter:39,height:16,flame:10},s7=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],c7=t=>Math.hypot(t[0],t[1],t[2]),r7=(t,e)=>[(t[0]+e[0])/2,(t[1]+e[1])/2,(t[2]+e[2])/2];function o7(t){let e={step:t.step,...t.label!==void 0&&{label:t.label}},n=s7(t.to,t.from),r=c7(n);if(t.kind==="tealight"){let a=r>0?[n[0]/r,n[1]/r,n[2]/r]:[0,0,1],s=[t.to[0]+a[0]*s3.flame,t.to[1]+a[1]*s3.flame,t.to[2]+a[2]*s3.flame];return[{from:s,to:s,color:a3.flame,lumens:12,flicker:!0,source:"tealight",...e}]}if(t.kind==="led"){let a=r>20,s=r7(t.from,t.to);return[{from:a?t.from:s,to:a?t.to:s,color:a3["warm white"],lumens:a?Math.round(r*2)/10:20,flicker:!1,source:"led",...e}]}if(t.kind==="bulb"){let a=r7(t.from,t.to);return[{from:a,to:a,color:a3["warm white"],lumens:100,flicker:!1,source:"bulb",...e}]}return[]}function G5(t,e=8){let n=s7(t.to,t.from),r=c7(n);if(!(r>0))return[{at:t.from,lumens:t.lumens}];let a=Math.max(2,Math.min(e,Math.ceil(r/50)));return Array.from({length:a},(s,c)=>{let o=(c+.5)/a;return{at:[t.from[0]+n[0]*o,t.from[1]+n[1]*o,t.from[2]+n[2]*o],lumens:t.lumens/a}})}var p4=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function n2(t,e){let{tokens:n,comments:r}=r3(t,e),a=new g4(n),s=[];for(;!a.at("eof");)s.push(...a.statement());return{program:{body:s},comments:r}}var J3=class J3{constructor(e){this.tokens=e;this.i=0}peek(e=0){return this.tokens[Math.min(this.i+e,this.tokens.length-1)]}at(e,n,r=0){let a=this.peek(r);return a.type===e&&(n===void 0||a.value===n)}isP(e,n=0){return this.at("punct",e,n)}isK(e,n=0){return this.at("id",e,n)}next(){return this.tokens[this.i++]}fail(e,n=this.peek()){let r=n.type==="eof"?"end of file":`"${n.value}"`;throw new i1(`${e}, found ${r}`,n.pos)}expectP(e){return this.isP(e)||this.fail(`Expected "${e}"`),this.next()}separator(e){this.isP(e)||(this.isP(",")||this.fail(`Expected "," or "${e}"`),this.next())}ident(){let e=this.peek();return(e.type!=="id"||p4.has(e.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let e=this.stmt();for(let n of e)n.end=this.last();return e}stmt(){let e=this.peek();if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let c=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),c.push(...this.statement());return this.next(),[{kind:"block",body:c,pos:e.pos}]}if(this.isK("module")){this.next();let c=this.ident(),o=this.params();return[{kind:"module",name:c.value,params:o,body:this.body(),pos:e.pos,namePos:c.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let c=this.ident(),o=this.params();this.expectP("=");let i=this.expr();return this.expectP(";"),[{kind:"function",name:c.value,params:o,body:i,pos:e.pos,namePos:c.pos}]}if(this.isK("use")||this.isK("include")){this.next();let c=this.peek();return c.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:c.value,include:e.value==="include",pos:e.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(this.isK("intersection_for")&&this.isP("(",1))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos,intersect:!0}];if(this.isK("if")){this.next(),this.expectP("(");let c=this.expr();this.expectP(")");let o=this.body(),i=[];return this.isK("else")&&(this.next(),i=this.body()),[{kind:"if",cond:c,then:o,else:i,pos:e.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(e.type==="id"&&this.isP("=",1)){let c=this.ident().value;this.next();let o=this.peek().pos.offset,i=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:c,value:i,span:[o,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let r=this.peek();(r.type!=="id"||p4.has(r.value))&&this.fail("Expected a statement"),this.next();let a=this.args(),s=this.body();return[{kind:"call",name:r.value,args:a,children:s,modifier:n,pos:r.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident(),r=null;this.isP("=")&&(this.next(),r=this.expr()),e.push({name:n.value,default:r,pos:n.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let n=this.next();this.next(),e.push({name:n.value,value:this.expr(),pos:n.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident();this.expectP("="),e.push({name:n.value,value:this.expr(),pos:n.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let r=this.params(),a=this.expr();return{kind:"lambda",params:r,body:a,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let r=this.assigns(),a=this.expr();return{kind:"let",assigns:r,body:a,pos:e.pos,end:this.last()}}if(this.at("id")&&(e.value==="assert"||e.value==="echo")&&this.isP("(",1)){let r=this.i;this.next();let a={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:a,body:this.expr(),pos:e.pos};this.i=r}let n=this.binary(0);if(this.isP("?")){this.next();let r=this.expr();this.expectP(":");let a=this.expr();return{kind:"ternary",cond:n,then:r,else:a,pos:e.pos}}return n}binary(e){if(e>=J3.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&J3.LEVELS[e].includes(this.peek().value);){let r=this.next(),a=this.binary(e+1);n={kind:"binary",op:r.value,left:n,right:a,pos:r.pos}}return n}startsValue(){let e=this.peek();return e.type==="num"||e.type==="str"||e.type==="id"?!0:this.isP("[")||this.isP("(")||this.isP("{")||this.isP("!")||this.isP("-")}unary(){if((this.isK("let")||this.isK("function"))&&this.isP("(",1))return this.expr();if(this.isP("-")||this.isP("!")||this.isP("+")){let e=this.next();return{kind:"unary",op:e.value,arg:this.unary(),pos:e.pos}}return this.power()}power(){let e=this.postfix();if(this.isP("^")){let n=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:n.pos}}return e}postfix(){let e=this.primary();for(;;){let n=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let r=this.expr();this.expectP("]"),e={kind:"index",target:e,index:r,pos:n.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:n.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let n=/(mm|cm|m|in|ft)$/.exec(e.value);return n?{kind:"num",value:Number(e.value.slice(0,-n[1].length)),unit:n[1],pos:e.pos}:{kind:"num",value:Number(e.value),pos:e.pos}}if(e.type==="str")return this.next(),{kind:"str",value:e.value,pos:e.pos};if(e.type==="id")return e.value==="true"||e.value==="false"?(this.next(),{kind:"bool",value:e.value==="true",pos:e.pos}):e.value==="undef"?(this.next(),{kind:"undef",pos:e.pos}):(p4.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let n=this.expr();return this.expectP(")"),n}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),n=[];for(;!this.isP("}");){let r=this.ident();if(n.some(a=>a.name===r.value))throw new i1(`Field ${r.value} is given twice`,r.pos);if(this.expectP("="),n.push({name:r.value,value:this.expr(),pos:r.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:n,pos:e.pos}}list(){let e=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:e.pos};if(!this.isK("for")&&!this.isK("if")&&!this.isK("each")&&!(this.isK("let")&&this.isP("(",1))&&!(this.isP("(")&&(this.isK("for",1)||this.isK("if",1)))){let n=this.expr();if(this.isP(":")){this.next();let a=null,s=this.expr();return this.isP(":")&&(this.next(),a=s,s=this.expr()),this.expectP("]"),{kind:"range",start:n,step:a,end:s,pos:e.pos}}let r=[{kind:"item",expr:n}];return this.listRest(r,e.pos)}return this.listRest([],e.pos)}listRest(e,n){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:n};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:n}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"for",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let r=this.listItem(),a=null;return this.isK("else")&&(this.next(),a=this.listItem()),{kind:"if",cond:n,then:r,else:a}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"let",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let n=this.listItem();return this.expectP(")"),n}return{kind:"item",expr:this.expr()}}};J3.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var g4=J3;var R=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),f1=(t,e,n)=>({...R(t,e,n),named:!0}),v4="max(3 * $thickness, 6)",W5=[R("value")],Ns=[R("x")],o2=(t,e)=>({name:t,kind:"function",params:Ns,section:"Numbers and vectors",doc:e}),Te=(t,e)=>({name:t,kind:"function",params:W5,section:"Types",doc:`Whether the value is ${e}`}),b4=(t,e)=>({name:t,kind:"function",params:[R("text","The text to measure",'""'),R("size","Font size in millimetres","10"),R("font","Font name","$font"),f1("halign","left, center or right",'"left"'),f1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),f1("spacing","Letter spacing factor","1"),f1("fit","Measure at the size that fits this width, or [width, cap height]")],section:"Text measurements",doc:e}),y4=[{name:"rect",kind:"module",params:[R("size","A number, or [width, height]","1"),R("center","Centre the rectangle on the origin instead of its corner","false"),f1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[R("size","A number, or [width, height]","1"),R("center","Centre the square on the origin instead of its corner","false"),f1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[R("r","Radius","1"),f1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[R("r","[rx, ry], or one radius for both","1"),f1("d","[width, height], or one diameter for both, instead of r")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[R("n","Number of corners","6"),R("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[R("n","Number of points","5"),R("r","Radius of the points","10"),R("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[R("points","A list of [x, y] points"),R("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[R("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),f1("fill",'"evenodd" or "nonzero"','"evenodd"'),f1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[R("text","The text",'""'),R("size","Font size in millimetres","10"),R("font","Font name","$font"),f1("halign","left, center or right",'"left"'),f1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),f1("spacing","Letter spacing factor","1"),f1("fit","Shrink the size so the text is no wider than this, or fits [width, cap height]"),f1("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),f1("bridge","Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide"),f1("weld","Slide each word's letters together into one piece, as a script name is cut; a number is how far each overlaps the one before, in mm","false"),f1("underline","With weld: a bar this high under the baseline, joining the words"),f1("lines","Break the text at spaces into up to this many lines; with fit, as many as let it be biggest","1"),f1("line_spacing","The distance between lines, as a share of the usual","1"),f1("path","Lay the text along these [x, y] points, each letter turned to the path, centred on it"),f1("arc","Lay the text round a circle of this radius about the origin: over the top, or along the bottom when less than 0")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[R("from","Start point","[0, 0]"),R("to","End point","[10, 0]"),R("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[R("points","A list of [x, y] points"),R("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[R("r","Radius","10"),R("start","Start angle in degrees","0"),R("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[R("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[R("a","Angle in degrees, anticlockwise","0"),f1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[R("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[R("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[R("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[R("r","Grow (positive) or shrink areas with rounded corners"),f1("delta","Grow or shrink areas with sharp corners","0"),f1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[R("spacing","Distance between copies, a number or [x, y]","10"),R("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[R("points","The [x, y] points the curve goes through"),R("width","Make an area this wide along the curve, instead of a line"),f1("steps","Points between each two given ones","8"),f1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[R("angle","Direction of the lines, in degrees from +x","45"),R("pitch","Distance between the lines","5"),R("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"flow",kind:"module",params:[R("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),R("spacing","Distance between neighbouring lines","2"),R("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),f1("min_length","Lines shorter than this are left out","spacing * 2"),f1("seed","Where the first lines start; another seed gives another arrangement","1")],children:!0,section:"Combining",doc:"Evenly spaced lines that follow a direction field across the area of the children, never closer than half the spacing"},{name:"contours",kind:"module",params:[R("field","The height at a point: function(p) giving a number, or undef for none"),R("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),f1("interval","Instead of levels: every multiple of this height"),f1("cell","Distance between the points sampled: smaller is finer and slower","1")],children:!0,section:"Combining",doc:"Contour lines where a height field crosses each level, across the area of the children"},{name:"occlude",kind:"module",params:[],children:!0,section:"Combining",doc:"Children back to front, each opaque: lines and outlines hide behind the areas of later children, and fills lose that area. Each iteration of a for loop is a child of its own"},{name:"hide",kind:"module",params:[],children:!0,section:"Combining",doc:"Inside occlude(): an area that hides what is behind it but is not drawn"},{name:"paint",kind:"module",params:[R("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[R("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1], $area and $centroid = [x, y] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[R("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"join_islands",kind:"module",params:[R("width","How wide each joining strip is","1")],children:!0,section:"Combining",doc:"Join every separate piece of the material to the nearest other piece with a strip, until it is one piece"},{name:"largest",kind:"module",params:[R("n","How many pieces to keep","1")],children:!0,section:"Combining",doc:"Keep the n biggest connected pieces of the material, dropping crumbs; marks stay as drawn"},{name:"close",kind:"module",params:[R("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[R("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[R("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[R("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[R("name","Layer name"),R("mode",'"cut", "line", "fill", "guide" or "paint" (shown in 3D, not cut)'),R("color",'Colour in the output, as "#00aa00" or a name, as "red"'),f1("order","Where it goes among the custom layers in the files, lowest first","0"),f1("bleed","How far past the part's edge it may print","0"),f1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[R("name","Part name",'"part"'),R("qty","Number of copies to cut","1"),f1("at","Where the part goes in the assembled view, [x, y, z]"),f1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),f1("stack","Layers glued in a stack at each placement, one thickness apart","1"),f1("mirror","Cut the part mirrored left to right, its text still reading","false"),f1("material","The material it is cut from, as material(name = ...) sets it"),f1("pieces",'How many separate pieces it cuts into, as a pair of eyes, or "any": no warning that it is in pieces',"1"),f1("paint",'Its colour in the 3D view and the print layout, as "red" or "#c8372d"; the part stays on the sheet of its material'),f1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),f1("fold","Folds along any line in the assembled view, as for card: [from, to, angle] or a list; more than 0 folds towards the top face"),f1("fold_open","How far the folds are folded: 0 lies flat, 1 as their angles say","1"),f1("hang","The point [x, y] on the part it hangs from, at `at`: it swings in its own plane until its weight is below"),f1("cord","The cord it hangs on, in mm; 0 for a ring or pin","0"),f1("split","Cut a part too big for the bed into pieces joined by jigsaw knobs: true for the sheet, or [width, height]"),f1("on","The name of a bent part this one is glued to, to move with it"),f1("slots","Names of parts whose tabs pass through this one: their slots are cut"),f1("clearance","Added to the slots, in total across each","0.1"),f1("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),f1("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),f1("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),f1("fit",'Room in the bores: "turn" (0.3 mm on the diameter) for a part that turns on its axle, "press" (-0.1 mm) for one held fast, or a number of mm','"turn"'),f1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),f1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"'),f1("press_fit","Pressed into the glue part, as an inlay: they overlap on purpose, so they are not checked against each other","false")],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[R("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),R("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[R("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[R("text","What to do in this step",'""'),R("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[R("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),R("from","One end, [x, y, z]; a ball sits midway between from and to"),R("to","The other end, [x, y, z]; a ball may leave it out"),R("size","Diameter, or [width, height] for a flat section","6"),f1("up","The direction a [width, height] section's height points"),f1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),f1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),f1("label","The name in the hardware list"),f1("mass","Its weight in grams, for the check that the model stands, as an egg in a holder")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"light",kind:"module",params:[R("at","Where the light is, [x, y, z]","[0, 0, 0]"),R("color",`Its colour: "warm white", "white", "cool white", "warm", "flame", a colour's name or "#ffd9a0"`,'"warm white"'),R("lumens","How much light it gives off: a tealight is about 12","20"),f1("to","The other end of a strip of light, [x, y, z]: it lights all along"),f1("flicker","A flame: it flickers in the 3D view","false"),f1("label","Its name in 3D files")],children:!0,section:"Parts and sheets",doc:"A light source in the 3D view and GLB files, with nothing to show for it"},{name:"material",kind:"module",params:[R("thickness","Sets $thickness"),R("kerf","Sets $kerf"),R("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[R("size","[width, height]"),R("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),R("finger","Finger width",v4)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[R("length","Length of the edge that plugs in"),R("edge",'"out" or "in", the kind of edge that plugs in','"out"'),R("finger","Finger width",v4)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[R("d","Screw diameter","3"),R("length","Screw length into the panel","12"),R("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),R("nut_at","Distance of the nut from the edge","length / 2")],section:"Joinery",doc:"A T-slot for a screw and nut, opening at y = 0; subtract it from a panel edge"},{name:"living_hinge",kind:"module",params:[R("size","[width, height]"),R("spacing","Distance between the rows of cuts","1.5"),R("bridge","Uncut length between cuts","3"),R("cut","Length of each cut","max(bridge * 2, (height - 3 * bridge) / 2)")],section:"Joinery",doc:"A straight-line flex pattern of cut lines filling [width, height]"},{name:"children",kind:"module",params:[R("index","Which child, from 0, or a list of them")],section:"Other",doc:"Run the child statements passed to the current module"},{name:"echo",kind:"both",params:[],rest:!0,anyNamed:!0,section:"Other",doc:"Write values to the output without making shapes"},{name:"assert",kind:"both",params:[R("condition","Stops the program when false"),R("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},o2("abs","Absolute value"),o2("sign","Sign as -1, 0 or 1"),o2("floor","Round down"),o2("ceil","Round up"),o2("round","Round to the nearest integer, halves away from zero"),o2("sqrt","Square root"),o2("exp","e raised to x"),o2("ln","Natural logarithm"),{name:"log",kind:"function",params:[R("x"),R("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},o2("sin","Sine of an angle in degrees"),o2("cos","Cosine of an angle in degrees"),o2("tan","Tangent of an angle in degrees"),o2("asin","Inverse sine, in degrees"),o2("acos","Inverse cosine, in degrees"),o2("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[R("y"),R("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[R("x"),R("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[R("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[R("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[R("x"),R("low"),R("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[R("a"),R("b"),R("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[R("ratio","Turns in for one turn out; under 1 speeds up"),R("stages","Pairs of gears, 1 to 3","2"),R("pinion","Fewest and most teeth of the small gears","[10, 20]"),R("wheel","Fewest and most teeth of the big gears","[20, 80]")],section:"Numbers and vectors",doc:"Tooth counts for a gear train nearest a ratio: {stages = [[driver, driven], ...], ratio, error}"},{name:"norm",kind:"function",params:[R("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[R("a"),R("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[R("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"offset_path",kind:"function",params:[R("points","A list of [x, y] points"),R("d","How far to move it: to the left going along it, or the right when less than 0"),R("closed","The path goes round, its last point joined to its first","false")],section:"Paths and rotations",doc:"The path moved sideways, each corner mitred: the two edges of a strip along a curve"},{name:"bounds",kind:"function",params:[R("points","A list of [x, y] points, or of outlines")],section:"Paths and rotations",doc:"[x0, y0, x1, y1] round the points; undef for none"},{name:"crossings",kind:"function",params:[R("points","A closed outline of [x, y] points, or a list of outlines"),R("x","The vertical line x = this"),R("y","Or the horizontal line y = this")],section:"Paths and rotations",doc:"Where the line crosses the outline: the y (or x) values, smallest first, entering and leaving in turn"},{name:"point_at",kind:"function",params:[R("points","A list of [x, y] points"),R("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[R("points","A list of [x, y] points"),R("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[R("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),R("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[R("points","The [x, y] points the curve goes through"),R("steps","Points between each two given ones","8"),R("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[R("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[R("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[R("x","Where the part's own x axis points"),R("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:W5,section:"Lists and strings",doc:"Number of items in a list, characters in a string or fields in a record"},{name:"keys",kind:"function",params:[R("record","A record, as {name = value}")],section:"Lists and strings",doc:"A record's field names, in the order they were written"},{name:"merge",kind:"function",params:[R("a","A record"),R("b","A record whose fields add to or replace those of a")],section:"Lists and strings",doc:"A record with the fields of a and b, b winning where both have one"},{name:"concat",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Join lists and single values into one list"},{name:"reverse",kind:"function",params:W5,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[R("values","A list of numbers, strings or lists of them"),R("key","A function giving the value to order each item by")],section:"Lists and strings",doc:"The list in order, smallest first; items with equal keys keep their order"},{name:"fold",kind:"function",params:[R("values","A list"),R("initial","The value to start from"),R("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after fn(acc, item) for each item in turn, from initial: initial for an empty list"},{name:"scan",kind:"function",params:[R("values","A list"),R("initial","The value to start from"),R("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after each item as fold() goes: running totals, one per item"},{name:"sum",kind:"function",params:[R("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[R("value","A list or string"),R("start","First index","0"),R("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[R("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[R("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[R("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[R("text"),R("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[R("values"),R("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[R("value"),R("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[R("value","A list or string"),R("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[R("x"),R("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},Te("is_num","a number other than NaN"),Te("is_string","a string"),Te("is_bool","true or false"),Te("is_list","a list"),Te("is_undef","undef"),Te("is_function","a function"),Te("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:W5,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[R("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),R("y",void 0,"0"),R("z","A third axis: step it to get a related but different pattern","0"),f1("seed","A different seed gives a different pattern","1"),f1("octaves","Layers of finer detail, 1 to 8","1")],section:"Random values",doc:"Smooth noise between about -1 and 1 that changes gradually from point to point: 0 at whole numbers, so scale the point down (x / 30) for broad shapes"},{name:"rands",kind:"function",params:[R("min"),R("max"),R("count"),R("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},b4("text_width","The advance width of the text, including spacing"),b4("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),b4("text_size","The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"),{name:"finger_count",kind:"function",params:[R("length","Edge length"),R("finger","Finger width",v4)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],Us=new Map(y4.map(t=>[t.name,t])),c3=t=>Us.get(t);function X5(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var Q3={"kerf/box":`// kerf/box: finger-jointed boxes.
13
13
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
14
14
 
15
15
  // Box from its outer size [width, depth, height] in the current material.
@@ -2328,9 +2328,12 @@ function link_angle(a, b) = atan2(b[1] - a[1], b[0] - a[0]);
2328
2328
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
2329
2329
  //
2330
2330
  // A flat key turns an eccentric cam, which slides a bolt: half a turn
2331
- // throws its nose out past the lock's top edge, into a notch or a slot in
2332
- // whatever it locks, and half a turn back pulls it in. Pulling on what is
2333
- // locked only presses the bolt against its slot. The lock is three layers
2331
+ // throws its nose out past the lock's top edge, into a slot in whatever it
2332
+ // locks, and half a turn back pulls it in. A bolt only holds against a pull
2333
+ // across its travel: set the lock so the bolt moves across the way the
2334
+ // locked part opens (sideways for a lid that lifts), and give the slot
2335
+ // wood on the side the part pulls from (a pocket, not a notch open that
2336
+ // way), so pulling presses the bolt against it. The lock is three layers
2334
2337
  // of the current material: a base with the cam's hub, a frame with the
2335
2338
  // cam and the bolt, and a plate with the keyhole.
2336
2339
  //
@@ -2343,7 +2346,7 @@ function link_angle(a, b) = atan2(b[1] - a[1], b[0] - a[0]);
2343
2346
  function lock_bounds(throw = 7) = let (d = lock_dims(throw))
2344
2347
  [-d[6] / 2, d[8], d[6] / 2, d[7]];
2345
2348
 
2346
- // Where the bolt's nose is: [width, y of its tip when locked]. Cut a notch
2349
+ // Where the bolt's nose is: [width, y of its tip when locked]. Cut a pocket
2347
2350
  // a little wider than this where it goes.
2348
2351
  function lock_nose(throw = 7) = let (d = lock_dims(throw)) [d[4], d[7] + d[5]];
2349
2352
 
@@ -4244,27 +4247,27 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
4244
4247
  if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
4245
4248
  if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
4246
4249
  }
4247
- `};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},r=Object.defineProperty,a=r(n,n,n)&&r}catch{}return a})(),e=function(n){if(this==null)throw TypeError();var r=String(this),a=r.length,s=n?Number(n):0;if(s!=s&&(s=0),!(s<0||s>=a)){var c=r.charCodeAt(s),o;return c>=55296&&c<=56319&&a>s+1&&(o=r.charCodeAt(s+1),o>=56320&&o<=57343)?(c-55296)*1024+o-56320+65536:c}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var R4=0,Z7=-3;function t5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function Bs(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new t5,this.dtree=new t5}var Y7=new t5,K7=new t5,F4=new Uint8Array(30),_4=new Uint16Array(30),J7=new Uint8Array(30),Q7=new Uint16Array(30),js=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h7=new t5,R2=new Uint8Array(320);function e8(t,e,n,r){var a,s;for(a=0;a<n;++a)t[a]=0;for(a=0;a<30-n;++a)t[a+n]=a/n|0;for(s=r,a=0;a<30;++a)e[a]=s,s+=1<<t[a]}function Gs(t,e){var n;for(n=0;n<7;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;n<24;++n)t.trans[n]=256+n;for(n=0;n<144;++n)t.trans[24+n]=n;for(n=0;n<8;++n)t.trans[168+n]=280+n;for(n=0;n<112;++n)t.trans[176+n]=144+n;for(n=0;n<5;++n)e.table[n]=0;for(e.table[5]=32,n=0;n<32;++n)e.trans[n]=n}var u7=new Uint16Array(16);function y4(t,e,n,r){var a,s;for(a=0;a<16;++a)t.table[a]=0;for(a=0;a<r;++a)t.table[e[n+a]]++;for(t.table[0]=0,s=0,a=0;a<16;++a)u7[a]=s,s+=t.table[a];for(a=0;a<r;++a)e[n+a]&&(t.trans[u7[e[n+a]]++]=a)}function Ws(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function F2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var r=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,r+n}function C4(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,r=0,a=0,s=t.tag;do r=2*r+(s&1),s>>>=1,++a,n+=e.table[a],r-=e.table[a];while(r>=0);return t.tag=s,t.bitcount-=a,e.trans[n+r]}function Xs(t,e,n){var r,a,s,c,o,i;for(r=F2(t,5,257),a=F2(t,5,1),s=F2(t,4,4),c=0;c<19;++c)R2[c]=0;for(c=0;c<s;++c){var l=F2(t,3,0);R2[js[c]]=l}for(y4(h7,R2,0,19),o=0;o<r+a;){var h=C4(t,h7);switch(h){case 16:var u=R2[o-1];for(i=F2(t,2,3);i;--i)R2[o++]=u;break;case 17:for(i=F2(t,3,3);i;--i)R2[o++]=0;break;case 18:for(i=F2(t,7,11);i;--i)R2[o++]=0;break;default:R2[o++]=h;break}}y4(e,R2,0,r),y4(n,R2,r,a)}function f7(t,e,n){for(;;){var r=C4(t,e);if(r===256)return R4;if(r<256)t.dest[t.destLen++]=r;else{var a,s,c,o;for(r-=257,a=F2(t,F4[r],_4[r]),s=C4(t,n),c=t.destLen-F2(t,J7[s],Q7[s]),o=c;o<c+a;++o)t.dest[t.destLen++]=t.dest[o]}}}function Zs(t){for(var e,n,r;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return Z7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,R4}function Ys(t,e){var n=new Bs(t,e),r,a,s;do{switch(r=Ws(n),a=F2(n,2,0),a){case 0:s=Zs(n);break;case 1:s=f7(n,Y7,K7);break;case 2:Xs(n,n.ltree,n.dtree),s=f7(n,n.ltree,n.dtree);break;default:s=Z7}if(s!==R4)throw new Error("Data error")}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}Gs(Y7,K7);e8(F4,_4,4,3);e8(J7,Q7,2,1);F4[28]=0;_4[28]=258;var Ks=Ys;function o3(t,e,n,r,a){return Math.pow(1-a,3)*t+3*Math.pow(1-a,2)*a*e+3*(1-a)*Math.pow(a,2)*n+Math.pow(a,3)*r}function ge(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}ge.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};ge.prototype.addPoint=function(t,e){typeof t=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};ge.prototype.addX=function(t){this.addPoint(t,null)};ge.prototype.addY=function(t){this.addPoint(null,t)};ge.prototype.addBezier=function(t,e,n,r,a,s,c,o){var i=[t,e],l=[n,r],h=[a,s],u=[c,o];this.addPoint(t,e),this.addPoint(c,o);for(var f=0;f<=1;f++){var d=6*i[f]-12*l[f]+6*h[f],m=-3*i[f]+9*l[f]-9*h[f]+3*u[f],p=3*l[f]-3*i[f];if(m===0){if(d===0)continue;var g=-p/d;0<g&&g<1&&(f===0&&this.addX(o3(i[f],l[f],h[f],u[f],g)),f===1&&this.addY(o3(i[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*p*m;if(!(v<0)){var b=(-d+Math.sqrt(v))/(2*m);0<b&&b<1&&(f===0&&this.addX(o3(i[f],l[f],h[f],u[f],b)),f===1&&this.addY(o3(i[f],l[f],h[f],u[f],b)));var y=(-d-Math.sqrt(v))/(2*m);0<y&&y<1&&(f===0&&this.addX(o3(i[f],l[f],h[f],u[f],y)),f===1&&this.addY(o3(i[f],l[f],h[f],u[f],y)))}}};ge.prototype.addQuad=function(t,e,n,r,a,s){var c=t+.6666666666666666*(n-t),o=e+2/3*(r-e),i=c+1/3*(a-t),l=o+1/3*(s-e);this.addBezier(t,e,c,o,i,l,a,s)};function F0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}F0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};F0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};F0.prototype.curveTo=F0.prototype.bezierCurveTo=function(t,e,n,r,a,s){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:r,x:a,y:s})};F0.prototype.quadTo=F0.prototype.quadraticCurveTo=function(t,e,n,r){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:r})};F0.prototype.close=F0.prototype.closePath=function(){this.commands.push({type:"Z"})};F0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof ge){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};F0.prototype.getBoundingBox=function(){for(var t=new ge,e=0,n=0,r=0,a=0,s=0;s<this.commands.length;s++){var c=this.commands[s];switch(c.type){case"M":t.addPoint(c.x,c.y),e=r=c.x,n=a=c.y;break;case"L":t.addPoint(c.x,c.y),r=c.x,a=c.y;break;case"Q":t.addQuad(r,a,c.x1,c.y1,c.x,c.y),r=c.x,a=c.y;break;case"C":t.addBezier(r,a,c.x1,c.y1,c.x2,c.y2,c.x,c.y),r=c.x,a=c.y;break;case"Z":r=e,a=n;break;default:throw new Error("Unexpected path command "+c.type)}}return t.isEmpty()&&t.addPoint(0,0),t};F0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};F0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(c){return Math.round(c)===c?""+Math.round(c):c.toFixed(t)}function n(){for(var c=arguments,o="",i=0;i<arguments.length;i+=1){var l=c[i];l>=0&&i>0&&(o+=" "),o+=e(l)}return o}for(var r="",a=0;a<this.commands.length;a+=1){var s=this.commands[a];s.type==="M"?r+="M"+n(s.x,s.y):s.type==="L"?r+="L"+n(s.x,s.y):s.type==="C"?r+="C"+n(s.x1,s.y1,s.x2,s.y2,s.x,s.y):s.type==="Q"?r+="Q"+n(s.x1,s.y1,s.x,s.y):s.type==="Z"&&(r+="Z")}return r};F0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};F0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function t8(t){throw new Error(t)}function d7(t,e){t||t8(e)}var H1={fail:t8,argument:d7,assert:d7},m7=32768,p7=2147483648,l3={},r1={},_1={};function z2(t){return function(){return t}}r1.BYTE=function(t){return H1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};_1.BYTE=z2(1);r1.CHAR=function(t){return[t.charCodeAt(0)]};_1.CHAR=z2(1);r1.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};_1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};r1.USHORT=function(t){return[t>>8&255,t&255]};_1.USHORT=z2(2);r1.SHORT=function(t){return t>=m7&&(t=-(2*m7-t)),[t>>8&255,t&255]};_1.SHORT=z2(2);r1.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};_1.UINT24=z2(3);r1.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};_1.ULONG=z2(4);r1.LONG=function(t){return t>=p7&&(t=-(2*p7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};_1.LONG=z2(4);r1.FIXED=r1.ULONG;_1.FIXED=_1.ULONG;r1.FWORD=r1.SHORT;_1.FWORD=_1.SHORT;r1.UFWORD=r1.USHORT;_1.UFWORD=_1.USHORT;r1.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};_1.LONGDATETIME=z2(8);r1.TAG=function(t){return H1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};_1.TAG=z2(4);r1.Card8=r1.BYTE;_1.Card8=_1.BYTE;r1.Card16=r1.USHORT;_1.Card16=_1.USHORT;r1.OffSize=r1.BYTE;_1.OffSize=_1.BYTE;r1.SID=r1.USHORT;_1.SID=_1.USHORT;r1.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?r1.NUMBER16(t):r1.NUMBER32(t)};_1.NUMBER=function(t){return r1.NUMBER(t).length};r1.NUMBER16=function(t){return[28,t>>8&255,t&255]};_1.NUMBER16=z2(3);r1.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};_1.NUMBER32=z2(5);r1.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var r=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*r)/r).toString()}for(var a="",s=0,c=e.length;s<c;s+=1){var o=e[s];o==="e"?a+=e[++s]==="-"?"c":"b":o==="."?a+="a":o==="-"?a+="e":a+=o}a+=a.length&1?"f":"ff";for(var i=[30],l=0,h=a.length;l<h;l+=2)i.push(parseInt(a.substr(l,2),16));return i};_1.REAL=function(t){return r1.REAL(t).length};r1.NAME=r1.CHARARRAY;_1.NAME=_1.CHARARRAY;r1.STRING=r1.CHARARRAY;_1.STRING=_1.CHARARRAY;l3.UTF8=function(t,e,n){for(var r=[],a=n,s=0;s<a;s++,e+=1)r[s]=t.getUint8(e);return String.fromCharCode.apply(null,r)};l3.UTF16=function(t,e,n){for(var r=[],a=n/2,s=0;s<a;s++,e+=2)r[s]=t.getUint16(e);return String.fromCharCode.apply(null,r)};r1.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var r=t.charCodeAt(n);e[e.length]=r>>8&255,e[e.length]=r&255}return e};_1.UTF16=function(t){return t.length*2};var P4={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};l3.MACSTRING=function(t,e,n,r){var a=P4[r];if(a!==void 0){for(var s="",c=0;c<n;c++){var o=t.getUint8(e+c);o<=127?s+=String.fromCharCode(o):s+=a[o&127]}return s}};var X5=typeof WeakMap=="function"&&new WeakMap,Z5,Js=function(t){if(!Z5){Z5={};for(var e in P4)Z5[e]=new String(e)}var n=Z5[t];if(n!==void 0){if(X5){var r=X5.get(n);if(r!==void 0)return r}var a=P4[t];if(a!==void 0){for(var s={},c=0;c<a.length;c++)s[a.charCodeAt(c)]=c+128;return X5&&X5.set(n,s),s}}};r1.MACSTRING=function(t,e){var n=Js(e);if(n!==void 0){for(var r=[],a=0;a<t.length;a++){var s=t.charCodeAt(a);if(s>=128&&(s=n[s],s===void 0))return;r[a]=s}return r}};_1.MACSTRING=function(t,e){var n=r1.MACSTRING(t,e);return n!==void 0?n.length:0};function E4(t){return t>=-128&&t<=127}function Qs(t,e,n){for(var r=0,a=t.length;e<a&&r<64&&t[e]===0;)++e,++r;return n.push(128|r-1),e}function ec(t,e,n){for(var r=0,a=t.length,s=e;s<a&&r<64;){var c=t[s];if(!E4(c)||c===0&&s+1<a&&t[s+1]===0)break;++s,++r}n.push(r-1);for(var o=e;o<s;++o)n.push(t[o]+256&255);return s}function tc(t,e,n){for(var r=0,a=t.length,s=e;s<a&&r<64;){var c=t[s];if(c===0||E4(c)&&s+1<a&&E4(t[s+1]))break;++s,++r}n.push(64|r-1);for(var o=e;o<s;++o){var i=t[o];n.push(i+65536>>8&255,i+256&255)}return s}r1.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var r=t[e];r===0?e=Qs(t,e,n):r>=-128&&r<=127?e=ec(t,e,n):e=tc(t,e,n)}return n};r1.INDEX=function(t){for(var e=1,n=[e],r=[],a=0;a<t.length;a+=1){var s=r1.OBJECT(t[a]);Array.prototype.push.apply(r,s),e+=s.length,n.push(e)}if(r.length===0)return[0,0];for(var c=[],o=1+Math.floor(Math.log(e)/Math.log(2))/8|0,i=[void 0,r1.BYTE,r1.USHORT,r1.UINT24,r1.ULONG][o],l=0;l<n.length;l+=1){var h=i(n[l]);Array.prototype.push.apply(c,h)}return Array.prototype.concat(r1.Card16(t.length),r1.OffSize(o),c,r)};_1.INDEX=function(t){return r1.INDEX(t).length};r1.DICT=function(t){for(var e=[],n=Object.keys(t),r=n.length,a=0;a<r;a+=1){var s=parseInt(n[a],0),c=t[s];e=e.concat(r1.OPERAND(c.value,c.type)),e=e.concat(r1.OPERATOR(s))}return e};_1.DICT=function(t){return r1.DICT(t).length};r1.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};r1.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r+=1)H1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(r1.OPERAND(t[r],e[r]));else if(e==="SID")n=n.concat(r1.NUMBER(t));else if(e==="offset")n=n.concat(r1.NUMBER32(t));else if(e==="number")n=n.concat(r1.NUMBER(t));else if(e==="real")n=n.concat(r1.REAL(t));else throw new Error("Unknown operand type "+e);return n};r1.OP=r1.BYTE;_1.OP=_1.BYTE;var Y5=typeof WeakMap=="function"&&new WeakMap;r1.CHARSTRING=function(t){if(Y5){var e=Y5.get(t);if(e!==void 0)return e}for(var n=[],r=t.length,a=0;a<r;a+=1){var s=t[a];n=n.concat(r1[s.type](s.value))}return Y5&&Y5.set(t,n),n};_1.CHARSTRING=function(t){return r1.CHARSTRING(t).length};r1.OBJECT=function(t){var e=r1[t.type];return H1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};_1.OBJECT=function(t){var e=_1[t.type];return H1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};r1.TABLE=function(t){for(var e=[],n=t.fields.length,r=[],a=[],s=0;s<n;s+=1){var c=t.fields[s],o=r1[c.type];H1.argument(o!==void 0,"No encoding function for field type "+c.type+" ("+c.name+")");var i=t[c.name];i===void 0&&(i=c.value);var l=o(i);c.type==="TABLE"?(a.push(e.length),e=e.concat([0,0]),r.push(l)):e=e.concat(l)}for(var h=0;h<r.length;h+=1){var u=a[h],f=e.length;H1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(r[h])}return e};_1.TABLE=function(t){for(var e=0,n=t.fields.length,r=0;r<n;r+=1){var a=t.fields[r],s=_1[a.type];H1.argument(s!==void 0,"No sizeOf function for field type "+a.type+" ("+a.name+")");var c=t[a.name];c===void 0&&(c=a.value),e+=s(c),a.type==="TABLE"&&(e+=2)}return e};r1.RECORD=r1.TABLE;_1.RECORD=_1.TABLE;r1.LITERAL=function(t){return t};_1.LITERAL=function(t){return t.length};function j0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var r=0;r<e.length;r+=1){var a=e[r];this[a.name]=a.value}if(this.tableName=t,this.fields=e,n)for(var s=Object.keys(n),c=0;c<s.length;c+=1){var o=s[c],i=n[o];this[o]!==void 0&&(this[o]=i)}}j0.prototype.encode=function(){return r1.TABLE(this)};j0.prototype.sizeOf=function(){return _1.TABLE(this)};function n5(t,e,n){n===void 0&&(n=e.length);var r=new Array(e.length+1);r[0]={name:t+"Count",type:"USHORT",value:n};for(var a=0;a<e.length;a++)r[a+1]={name:t+a,type:"USHORT",value:e[a]};return r}function T4(t,e,n){var r=e.length,a=new Array(r+1);a[0]={name:t+"Count",type:"USHORT",value:r};for(var s=0;s<r;s++)a[s+1]={name:t+s,type:"TABLE",value:n(e[s],s)};return a}function r5(t,e,n){var r=e.length,a=[];a[0]={name:t+"Count",type:"USHORT",value:r};for(var s=0;s<r;s++)a=a.concat(n(e[s],s));return a}function tt(t){t.format===1?j0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(n5("glyph",t.glyphs))):t.format===2?j0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(r5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):H1.assert(!1,"Coverage format must be 1 or 2.")}tt.prototype=Object.create(j0.prototype);tt.prototype.constructor=tt;function nt(t){j0.call(this,"scriptListTable",r5("scriptRecord",t,function(e,n){var r=e.script,a=r.defaultLangSys;return H1.assert(!!a,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new j0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new j0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:a.reqFeatureIndex}].concat(n5("featureIndex",a.featureIndexes)))}].concat(r5("langSys",r.langSysRecords,function(s,c){var o=s.langSys;return[{name:"langSysTag"+c,type:"TAG",value:s.tag},{name:"langSys"+c,type:"TABLE",value:new j0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:o.reqFeatureIndex}].concat(n5("featureIndex",o.featureIndexes)))}]})))}]}))}nt.prototype=Object.create(j0.prototype);nt.prototype.constructor=nt;function rt(t){j0.call(this,"featureListTable",r5("featureRecord",t,function(e,n){var r=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new j0("featureTable",[{name:"featureParams",type:"USHORT",value:r.featureParams}].concat(n5("lookupListIndex",r.lookupListIndexes)))}]}))}rt.prototype=Object.create(j0.prototype);rt.prototype.constructor=rt;function at(t,e){j0.call(this,"lookupListTable",T4("lookup",t,function(n){var r=e[n.lookupType];return H1.assert(!!r,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new j0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(T4("subtable",n.subtables,r)))}))}at.prototype=Object.create(j0.prototype);at.prototype.constructor=at;var l1={Table:j0,Record:j0,Coverage:tt,ScriptList:nt,FeatureList:rt,LookupList:at,ushortList:n5,tableList:T4,recordList:r5};function g7(t,e){return t.getUint8(e)}function st(t,e){return t.getUint16(e,!1)}function nc(t,e){return t.getInt16(e,!1)}function q4(t,e){return t.getUint32(e,!1)}function n8(t,e){var n=t.getInt16(e,!1),r=t.getUint16(e+2,!1);return n+r/65535}function rc(t,e){for(var n="",r=e;r<e+4;r+=1)n+=String.fromCharCode(t.getInt8(r));return n}function ac(t,e,n){for(var r=0,a=0;a<n;a+=1)r<<=8,r+=t.getUint8(e+a);return r}function sc(t,e,n){for(var r=[],a=e;a<n;a+=1)r.push(t.getUint8(a));return r}function cc(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var oc={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function N(t,e){this.data=t,this.offset=e,this.relativeOffset=0}N.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};N.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};N.prototype.parseCard8=N.prototype.parseByte;N.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};N.prototype.parseCard16=N.prototype.parseUShort;N.prototype.parseSID=N.prototype.parseUShort;N.prototype.parseOffset16=N.prototype.parseUShort;N.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};N.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};N.prototype.parseULong=function(){var t=q4(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseOffset32=N.prototype.parseULong;N.prototype.parseFixed=function(){var t=n8(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,r="";this.relativeOffset+=t;for(var a=0;a<t;a++)r+=String.fromCharCode(e.getUint8(n+a));return r};N.prototype.parseTag=function(){return this.parseString(4)};N.prototype.parseLongDateTime=function(){var t=q4(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};N.prototype.parseVersion=function(t){var e=st(this.data,this.offset+this.relativeOffset),n=st(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};N.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=oc[t]*e};N.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getUint32(r),r+=4;return this.relativeOffset+=t*4,e};N.prototype.parseOffset16List=N.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getUint16(r),r+=2;return this.relativeOffset+=t*2,e};N.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getInt16(r),r+=2;return this.relativeOffset+=t*2,e};N.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getUint8(r++);return this.relativeOffset+=t,e};N.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};N.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};N.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=Object.keys(e),a=0;a<t;a++){for(var s={},c=0;c<r.length;c++){var o=r[c],i=e[o];s[o]=i.call(this)}n[a]=s}return n};N.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=Object.keys(e),a=0;a<t;a++){for(var s={},c=0;c<r.length;c++){var o=r[c],i=e[o];s[o]=i.call(this)}n[a]=s}return n};N.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},r=0;r<e.length;r++){var a=e[r],s=t[a];n[a]=s.call(this)}return n};N.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};N.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),r=0;r<e;r++)n[r]=this.parseValueRecord(t);return n};N.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new N(this.data,this.offset+e).parseStruct(t)};N.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new N(this.data,this.offset+e).parseStruct(t)};N.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,r=this.relativeOffset,a=new Array(n),s=0;s<n;s++){var c=e[s];if(c===0){a[s]=void 0;continue}if(this.relativeOffset=c,t){for(var o=this.parseOffset16List(),i=new Array(o.length),l=0;l<o.length;l++)this.relativeOffset=c+o[l],i[l]=t.call(this);a[s]=i}else a[s]=this.parseUShortList()}return this.relativeOffset=r,a};N.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var r=new Array(n),a=0;a<n;a++)r[a]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:r}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};N.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:N.uShort,end:N.uShort,classId:N.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};N.list=function(t,e){return function(){return this.parseList(t,e)}};N.list32=function(t,e){return function(){return this.parseList32(t,e)}};N.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};N.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};N.pointer=function(t){return function(){return this.parsePointer(t)}};N.pointer32=function(t){return function(){return this.parsePointer32(t)}};N.tag=N.prototype.parseTag;N.byte=N.prototype.parseByte;N.uShort=N.offset16=N.prototype.parseUShort;N.uShortList=N.prototype.parseUShortList;N.uLong=N.offset32=N.prototype.parseULong;N.uLongList=N.prototype.parseULongList;N.struct=N.prototype.parseStruct;N.coverage=N.prototype.parseCoverage;N.classDef=N.prototype.parseClassDef;var v7={reserved:N.uShort,reqFeatureIndex:N.uShort,featureIndexes:N.uShortList};N.prototype.parseScriptList=function(){return this.parsePointer(N.recordList({tag:N.tag,script:N.pointer({defaultLangSys:N.pointer(v7),langSysRecords:N.recordList({tag:N.tag,langSys:N.pointer(v7)})})}))||[]};N.prototype.parseFeatureList=function(){return this.parsePointer(N.recordList({tag:N.tag,feature:N.pointer({featureParams:N.offset16,lookupListIndexes:N.uShortList})}))||[]};N.prototype.parseLookupList=function(t){return this.parsePointer(N.list(N.pointer(function(){var e=this.parseUShort();H1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),r=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(N.pointer(t[e])),markFilteringSet:r?this.parseUShort():void 0}})))||[]};N.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();H1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:N.offset32,featureTableSubstitutionOffset:N.offset32});return n})||[]};var y1={getByte:g7,getCard8:g7,getUShort:st,getCard16:st,getShort:nc,getULong:q4,getFixed:n8,getTag:rc,getOffset:ac,getBytes:sc,bytesToString:cc,Parser:N};function ic(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var r=0;r<n;r+=1)for(var a=e.parseULong(),s=e.parseULong(),c=e.parseULong(),o=a;o<=s;o+=1)t.glyphIndexMap[o]=c,c++}function lc(t,e,n,r,a){t.length=e.parseUShort(),t.language=e.parseUShort();var s;t.segCount=s=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var c=new y1.Parser(n,r+a+14),o=new y1.Parser(n,r+a+16+s*2),i=new y1.Parser(n,r+a+16+s*4),l=new y1.Parser(n,r+a+16+s*6),h=r+a+16+s*8,u=0;u<s-1;u+=1)for(var f=void 0,d=c.parseUShort(),m=o.parseUShort(),p=i.parseShort(),g=l.parseUShort(),v=m;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-m)*2,f=y1.getUShort(n,h),f!==0&&(f=f+p&65535)):f=v+p&65535,t.glyphIndexMap[v]=f}function hc(t,e){var n={};n.version=y1.getUShort(t,e),H1.argument(n.version===0,"cmap table version should be 0."),n.numTables=y1.getUShort(t,e+2);for(var r=-1,a=n.numTables-1;a>=0;a-=1){var s=y1.getUShort(t,e+4+a*8),c=y1.getUShort(t,e+4+a*8+2);if(s===3&&(c===0||c===1||c===10)||s===0&&(c===0||c===1||c===2||c===3||c===4)){r=y1.getULong(t,e+4+a*8+4);break}}if(r===-1)throw new Error("No valid cmap sub-tables found.");var o=new y1.Parser(t,e+r);if(n.format=o.parseUShort(),n.format===12)ic(n,o);else if(n.format===4)lc(n,o,t,e,r);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function uc(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function fc(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function dc(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var r=t.get(n);if(r.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var a=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(a=a.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),a=a.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var s=new l1.Table("cmap",a);for(s.segments=[],n=0;n<t.length;n+=1){for(var c=t.get(n),o=0;o<c.unicodes.length;o+=1)uc(s,c.unicodes[o],n);s.segments=s.segments.sort(function(b,y){return b.start-y.start})}fc(s);var i=s.segments.length,l=0,h=[],u=[],f=[],d=[],m=[],p=[];for(n=0;n<i;n+=1){var g=s.segments[n];g.end<=65535&&g.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:g.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:g.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:g.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:g.offset}),g.glyphId!==void 0&&(m=m.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(p=p.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),p=p.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),p=p.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(s.segCountX2=(i-l)*2,s.searchRange=Math.pow(2,Math.floor(Math.log(i-l)/Math.log(2)))*2,s.entrySelector=Math.log(s.searchRange/2)/Math.log(2),s.rangeShift=s.segCountX2-s.searchRange,s.fields=s.fields.concat(h),s.fields.push({name:"reservedPad",type:"USHORT",value:0}),s.fields=s.fields.concat(u),s.fields=s.fields.concat(f),s.fields=s.fields.concat(d),s.fields=s.fields.concat(m),s.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+m.length*2,!e){var v=16+p.length*4;s.cmap12Offset=20+s.cmap4Length,s.fields=s.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:p.length/3}]),s.fields=s.fields.concat(p)}return s}var r8={parse:hc,make:dc},Q5=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],mc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],pc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],Ve=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function a8(t){this.font=t}a8.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var r=0;r<n.length;r+=1)for(var a=n.get(r),s=0;s<a.unicodes.length;s+=1)if(a.unicodes[s]===e)return r}return null};function s8(t){this.cmap=t}s8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function ct(t,e){this.encoding=t,this.charset=e}ct.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function D4(t){switch(t.version){case 1:this.names=Ve.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<Ve.length?this.names[e]=Ve[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-Ve.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=Ve[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}D4.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};D4.prototype.glyphIndexToName=function(t){return this.names[t]};function gc(t){for(var e,n=t.tables.cmap.glyphIndexMap,r=Object.keys(n),a=0;a<r.length;a+=1){var s=r[a],c=n[s];e=t.glyphs.get(c),e.addUnicode(parseInt(s))}for(var o=0;o<t.glyphs.length;o+=1)e=t.glyphs.get(o),t.cffEncoding?t.isCIDFont?e.name="gid"+o:e.name=t.cffEncoding.charset[o]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(o))}function vc(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),r=0;r<n.length;r+=1){var a=n[r],s=e[a];t._IndexToUnicodeMap[s]===void 0?t._IndexToUnicodeMap[s]={unicodes:[parseInt(a)]}:t._IndexToUnicodeMap[s].unicodes.push(parseInt(a))}}function bc(t,e){e.lowMemory?vc(t):gc(t)}function yc(t,e,n,r,a){t.beginPath(),t.moveTo(e,n),t.lineTo(r,a),t.stroke()}var Ie={line:yc};function xc(t,e){var n=e||new F0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(r){n=r}}}function v2(t){this.bindConstructorValues(t)}v2.prototype.bindConstructorValues=function(t){this.index=t.index||0,this.name=t.name||null,this.unicode=t.unicode||void 0,this.unicodes=t.unicodes||t.unicode!==void 0?[t.unicode]:[],"xMin"in t&&(this.xMin=t.xMin),"yMin"in t&&(this.yMin=t.yMin),"xMax"in t&&(this.xMax=t.xMax),"yMax"in t&&(this.yMax=t.yMax),"advanceWidth"in t&&(this.advanceWidth=t.advanceWidth),Object.defineProperty(this,"path",xc(this,t.path))};v2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};v2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};v2.prototype.getPath=function(t,e,n,r,a){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var s,c;r||(r={});var o=r.xScale,i=r.yScale;if(r.hinting&&a&&a.hinting&&(c=this.path&&a.hinting.exec(this,n)),c)s=a.hinting.getCommands(c),t=Math.round(t),e=Math.round(e),o=i=1;else{s=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;o===void 0&&(o=l),i===void 0&&(i=l)}for(var h=new F0,u=0;u<s.length;u+=1){var f=s[u];f.type==="M"?h.moveTo(t+f.x*o,e+-f.y*i):f.type==="L"?h.lineTo(t+f.x*o,e+-f.y*i):f.type==="Q"?h.quadraticCurveTo(t+f.x1*o,e+-f.y1*i,t+f.x*o,e+-f.y*i):f.type==="C"?h.curveTo(t+f.x1*o,e+-f.y1*i,t+f.x2*o,e+-f.y2*i,t+f.x*o,e+-f.y*i):f.type==="Z"&&h.closePath()}return h};v2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var r=this.points[n];e.push(r),r.lastPointOfContour&&(t.push(e),e=[])}return H1.argument(e.length===0,"There are still points left in the current contour."),t};v2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],r=0;r<t.length;r+=1){var a=t[r];a.type!=="Z"&&(e.push(a.x),n.push(a.y)),(a.type==="Q"||a.type==="C")&&(e.push(a.x1),n.push(a.y1)),a.type==="C"&&(e.push(a.x2),n.push(a.y2))}var s={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(s.xMin)||(s.xMin=0),isFinite(s.xMax)||(s.xMax=this.advanceWidth),isFinite(s.yMin)||(s.yMin=0),isFinite(s.yMax)||(s.yMax=0),s.rightSideBearing=this.advanceWidth-s.leftSideBearing-(s.xMax-s.xMin),s};v2.prototype.draw=function(t,e,n,r,a){this.getPath(e,n,r,a).draw(t)};v2.prototype.drawPoints=function(t,e,n,r){function a(u,f,d,m){t.beginPath();for(var p=0;p<u.length;p+=1)t.moveTo(f+u[p].x*m,d+u[p].y*m),t.arc(f+u[p].x*m,d+u[p].y*m,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24;for(var s=1/this.path.unitsPerEm*r,c=[],o=[],i=this.path,l=0;l<i.commands.length;l+=1){var h=i.commands[l];h.x!==void 0&&c.push({x:h.x,y:-h.y}),h.x1!==void 0&&o.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&o.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",a(c,e,n,s),t.fillStyle="red",a(o,e,n,s)};v2.prototype.drawMetrics=function(t,e,n,r){var a;e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24,a=1/this.path.unitsPerEm*r,t.lineWidth=1,t.strokeStyle="black",Ie.line(t,e,-1e4,e,1e4),Ie.line(t,-1e4,n,1e4,n);var s=this.xMin||0,c=this.yMin||0,o=this.xMax||0,i=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",Ie.line(t,e+s*a,-1e4,e+s*a,1e4),Ie.line(t,e+o*a,-1e4,e+o*a,1e4),Ie.line(t,-1e4,n+-c*a,1e4,n+-c*a),Ie.line(t,-1e4,n+-i*a,1e4,n+-i*a),t.strokeStyle="green",Ie.line(t,e+l*a,-1e4,e+l*a,1e4)};function K5(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(r){t[n]=r},enumerable:!0,configurable:!0})}function N4(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var r=e[n];r.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=r}this.length=e&&e.length||0}N4.prototype.get=function(t){if(this.glyphs[t]===void 0){this.font._push(t),typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());var e=this.glyphs[t],n=this.font._IndexToUnicodeMap[t];if(n)for(var r=0;r<n.unicodes.length;r++)e.addUnicode(n.unicodes[r]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+t:e.name=this.font.cffEncoding.charset[t]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(t)),this.glyphs[t].advanceWidth=this.font._hmtxTableData[t].advanceWidth,this.glyphs[t].leftSideBearing=this.font._hmtxTableData[t].leftSideBearing}else typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());return this.glyphs[t]};N4.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Mc(t,e){return new v2({index:e,font:t})}function wc(t,e,n,r,a,s){return function(){var c=new v2({index:e,font:t});return c.path=function(){n(c,r,a);var o=s(t.glyphs,c);return o.unitsPerEm=t.unitsPerEm,o},K5(c,"xMin","_xMin"),K5(c,"xMax","_xMax"),K5(c,"yMin","_yMin"),K5(c,"yMax","_yMax"),c}}function kc(t,e,n,r){return function(){var a=new v2({index:e,font:t});return a.path=function(){var s=n(t,a,r);return s.unitsPerEm=t.unitsPerEm,s},a}}var q2={GlyphSet:N4,glyphLoader:Mc,ttfGlyphLoader:wc,cffGlyphLoader:kc};function c8(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n+=1)if(!c8(t[n],e[n]))return!1;return!0}else return!1}function I4(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function fe(t,e,n){var r=[],a=[],s=y1.getCard16(t,e),c,o;if(s!==0){var i=y1.getByte(t,e+2);c=e+(s+1)*i+2;for(var l=e+3,h=0;h<s+1;h+=1)r.push(y1.getOffset(t,l,i)),l+=i;o=c+r[s]}else o=e+2;for(var u=0;u<r.length-1;u+=1){var f=y1.getBytes(t,c+r[u],c+r[u+1]);n&&(f=n(f)),a.push(f)}return{objects:a,startOffset:e,endOffset:o}}function zc(t,e){var n=[],r=y1.getCard16(t,e),a,s;if(r!==0){var c=y1.getByte(t,e+2);a=e+(r+1)*c+2;for(var o=e+3,i=0;i<r+1;i+=1)n.push(y1.getOffset(t,o,c)),o+=c;s=a+n[r]}else s=e+2;return{offsets:n,startOffset:e,endOffset:s}}function Sc(t,e,n,r,a){var s=y1.getCard16(n,r),c=0;if(s!==0){var o=y1.getByte(n,r+2);c=r+(s+1)*o+2}var i=y1.getBytes(n,c+e[t],c+e[t+1]);return a&&(i=a(i)),i}function Ac(t){for(var e="",n=15,r=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var a=t.parseByte(),s=a>>4,c=a&15;if(s===n||(e+=r[s],c===n))break;e+=r[c]}return parseFloat(e)}function Lc(t,e){var n,r,a,s;if(e===28)return n=t.parseByte(),r=t.parseByte(),n<<8|r;if(e===29)return n=t.parseByte(),r=t.parseByte(),a=t.parseByte(),s=t.parseByte(),n<<24|r<<16|a<<8|s;if(e===30)return Ac(t);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return n=t.parseByte(),(e-247)*256+n+108;if(e>=251&&e<=254)return n=t.parseByte(),-(e-251)*256-n-108;throw new Error("Invalid b0 "+e)}function Cc(t){for(var e={},n=0;n<t.length;n+=1){var r=t[n][0],a=t[n][1],s=void 0;if(a.length===1?s=a[0]:s=a,e.hasOwnProperty(r)&&!isNaN(e[r]))throw new Error("Object "+e+" already has key "+r);e[r]=s}return e}function o8(t,e,n){e=e!==void 0?e:0;var r=new y1.Parser(t,e),a=[],s=[];for(n=n!==void 0?n:t.length;r.relativeOffset<n;){var c=r.parseByte();c<=21?(c===12&&(c=1200+r.parseByte()),a.push([c,s]),s=[]):s.push(Lc(r,c))}return Cc(a)}function e5(t,e){return e<=390?e=Q5[e]:e=t[e-391],e}function i8(t,e,n){for(var r={},a,s=0;s<e.length;s+=1){var c=e[s];if(Array.isArray(c.type)){var o=[];o.length=c.type.length;for(var i=0;i<c.type.length;i++)a=t[c.op]!==void 0?t[c.op][i]:void 0,a===void 0&&(a=c.value!==void 0&&c.value[i]!==void 0?c.value[i]:null),c.type[i]==="SID"&&(a=e5(n,a)),o[i]=a;r[c.name]=o}else a=t[c.op],a===void 0&&(a=c.value!==void 0?c.value:null),c.type==="SID"&&(a=e5(n,a)),r[c.name]=a}return r}function Pc(t,e){var n={};return n.formatMajor=y1.getCard8(t,e),n.formatMinor=y1.getCard8(t,e+1),n.size=y1.getCard8(t,e+2),n.offsetSize=y1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var l8=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],h8=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function Ec(t,e){var n=o8(t,0,t.byteLength);return i8(n,l8,e)}function u8(t,e,n,r){var a=o8(t,e,n);return i8(a,h8,r)}function b7(t,e,n,r){for(var a=[],s=0;s<n.length;s+=1){var c=new DataView(new Uint8Array(n[s]).buffer),o=Ec(c,r);o._subrs=[],o._subrsBias=0,o._defaultWidthX=0,o._nominalWidthX=0;var i=o.private[0],l=o.private[1];if(i!==0&&l!==0){var h=u8(t,l+e,i,r);if(o._defaultWidthX=h.defaultWidthX,o._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=fe(t,u+e);o._subrs=f.objects,o._subrsBias=I4(o._subrs)}o._privateDict=h}a.push(o)}return a}function Tc(t,e,n,r){var a,s,c=new y1.Parser(t,e);n-=1;var o=[".notdef"],i=c.parseCard8();if(i===0)for(var l=0;l<n;l+=1)a=c.parseSID(),o.push(e5(r,a));else if(i===1)for(;o.length<=n;){a=c.parseSID(),s=c.parseCard8();for(var h=0;h<=s;h+=1)o.push(e5(r,a)),a+=1}else if(i===2)for(;o.length<=n;){a=c.parseSID(),s=c.parseCard16();for(var u=0;u<=s;u+=1)o.push(e5(r,a)),a+=1}else throw new Error("Unknown charset format "+i);return o}function Ic(t,e,n){var r,a={},s=new y1.Parser(t,e),c=s.parseCard8();if(c===0)for(var o=s.parseCard8(),i=0;i<o;i+=1)r=s.parseCard8(),a[r]=i;else if(c===1){var l=s.parseCard8();r=1;for(var h=0;h<l;h+=1)for(var u=s.parseCard8(),f=s.parseCard8(),d=u;d<=u+f;d+=1)a[d]=r,r+=1}else throw new Error("Unknown encoding format "+c);return new ct(a,n)}function y7(t,e,n){var r,a,s,c,o=new F0,i=[],l=0,h=!1,u=!1,f=0,d=0,m,p,g,v;if(t.isCIDFont){var b=t.tables.cff.topDict._fdSelect[e.index],y=t.tables.cff.topDict._fdArray[b];m=y._subrs,p=y._subrsBias,g=y._defaultWidthX,v=y._nominalWidthX}else m=t.tables.cff.topDict._subrs,p=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var M=g;function w(A,L){u&&o.closePath(),o.moveTo(A,L),u=!0}function x(){var A;A=i.length%2!==0,A&&!h&&(M=i.shift()+v),l+=i.length>>1,i.length=0,h=!0}function k(A){for(var L,z,S,C,E,I,H,T,O,_,D,G,V=0;V<A.length;){var U=A[V];switch(V+=1,U){case 1:x();break;case 3:x();break;case 4:i.length>1&&!h&&(M=i.shift()+v,h=!0),d+=i.pop(),w(f,d);break;case 5:for(;i.length>0;)f+=i.shift(),d+=i.shift(),o.lineTo(f,d);break;case 6:for(;i.length>0&&(f+=i.shift(),o.lineTo(f,d),i.length!==0);)d+=i.shift(),o.lineTo(f,d);break;case 7:for(;i.length>0&&(d+=i.shift(),o.lineTo(f,d),i.length!==0);)f+=i.shift(),o.lineTo(f,d);break;case 8:for(;i.length>0;)r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+i.shift(),o.curveTo(r,a,s,c,f,d);break;case 10:E=i.pop()+p,I=m[E],I&&k(I);break;case 11:return;case 12:switch(U=A[V],V+=1,U){case 35:r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c+i.shift(),O=H+i.shift(),_=T+i.shift(),D=O+i.shift(),G=_+i.shift(),f=D+i.shift(),d=G+i.shift(),i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;case 34:r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c,O=H+i.shift(),_=c,D=O+i.shift(),G=d,f=D+i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;case 36:r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c,O=H+i.shift(),_=c,D=O+i.shift(),G=_+i.shift(),f=D+i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;case 37:r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c+i.shift(),O=H+i.shift(),_=T+i.shift(),D=O+i.shift(),G=_+i.shift(),Math.abs(D-f)>Math.abs(G-d)?f=D+i.shift():d=G+i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+U),i.length=0}break;case 14:i.length>0&&!h&&(M=i.shift()+v,h=!0),u&&(o.closePath(),u=!1);break;case 18:x();break;case 19:case 20:x(),V+=l+7>>3;break;case 21:i.length>2&&!h&&(M=i.shift()+v,h=!0),d+=i.pop(),f+=i.pop(),w(f,d);break;case 22:i.length>1&&!h&&(M=i.shift()+v,h=!0),f+=i.pop(),w(f,d);break;case 23:x();break;case 24:for(;i.length>2;)r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+i.shift(),o.curveTo(r,a,s,c,f,d);f+=i.shift(),d+=i.shift(),o.lineTo(f,d);break;case 25:for(;i.length>6;)f+=i.shift(),d+=i.shift(),o.lineTo(f,d);r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+i.shift(),o.curveTo(r,a,s,c,f,d);break;case 26:for(i.length%2&&(f+=i.shift());i.length>0;)r=f,a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s,d=c+i.shift(),o.curveTo(r,a,s,c,f,d);break;case 27:for(i.length%2&&(d+=i.shift());i.length>0;)r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c,o.curveTo(r,a,s,c,f,d);break;case 28:L=A[V],z=A[V+1],i.push((L<<24|z<<16)>>16),V+=2;break;case 29:E=i.pop()+t.gsubrsBias,I=t.gsubrs[E],I&&k(I);break;case 30:for(;i.length>0&&(r=f,a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d),i.length!==0);)r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),d=c+i.shift(),f=s+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d);break;case 31:for(;i.length>0&&(r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),d=c+i.shift(),f=s+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d),i.length!==0);)r=f,a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d);break;default:U<32?console.log("Glyph "+e.index+": unknown operator "+U):U<247?i.push(U-139):U<251?(L=A[V],V+=1,i.push((U-247)*256+L+108)):U<255?(L=A[V],V+=1,i.push(-(U-251)*256-L-108)):(L=A[V],z=A[V+1],S=A[V+2],C=A[V+3],V+=4,i.push((L<<24|z<<16|S<<8|C)/65536))}}}return k(n),e.advanceWidth=M,o}function Vc(t,e,n,r){var a=[],s,c=new y1.Parser(t,e),o=c.parseCard8();if(o===0)for(var i=0;i<n;i++){if(s=c.parseCard8(),s>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+r+")");a.push(s)}else if(o===3){var l=c.parseCard16(),h=c.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var u,f=0;f<l;f++){if(s=c.parseCard8(),u=c.parseCard16(),s>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+r+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)a.push(s);h=u}if(u!==n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+u)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+o);return a}function $c(t,e,n,r){n.tables.cff={};var a=Pc(t,e),s=fe(t,a.endOffset,y1.bytesToString),c=fe(t,s.endOffset),o=fe(t,c.endOffset,y1.bytesToString),i=fe(t,o.endOffset);n.gsubrs=i.objects,n.gsubrsBias=I4(n.gsubrs);var l=b7(t,e,c.objects,o.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=fe(t,u),m=b7(t,e,d.objects,o.objects);h._fdArray=m,f+=e,h._fdSelect=Vc(t,f,n.numGlyphs,m.length)}var p=e+h.private[1],g=u8(t,p,h.private[0],o.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=p+g.subrs,b=fe(t,v);n.subrs=b.objects,n.subrsBias=I4(n.subrs)}else n.subrs=[],n.subrsBias=0;var y;r.lowMemory?(y=zc(t,e+h.charStrings),n.nGlyphs=y.offsets.length):(y=fe(t,e+h.charStrings),n.nGlyphs=y.objects.length);var M=Tc(t,e+h.charset,n.nGlyphs,o.objects);if(h.encoding===0?n.cffEncoding=new ct(mc,M):h.encoding===1?n.cffEncoding=new ct(pc,M):n.cffEncoding=Ic(t,e+h.encoding,M),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new q2.GlyphSet(n),r.lowMemory)n._push=function(k){var A=Sc(k,y.offsets,t,e+h.charStrings);n.glyphs.push(k,q2.cffGlyphLoader(n,k,y7,A))};else for(var w=0;w<n.nGlyphs;w+=1){var x=y.objects[w];n.glyphs.push(w,q2.cffGlyphLoader(n,w,y7,x))}}function f8(t,e){var n,r=Q5.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+Q5.length:(n=Q5.length+e.length,e.push(t)),n}function Hc(){return new l1.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function Oc(t){var e=new l1.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var n=0;n<t.length;n+=1)e.names.push({name:"name_"+n,type:"NAME",value:t[n]});return e}function d8(t,e,n){for(var r={},a=0;a<t.length;a+=1){var s=t[a],c=e[s.name];c!==void 0&&!c8(c,s.value)&&(s.type==="SID"&&(c=f8(c,n)),r[s.op]={name:s.name,type:s.type,value:c})}return r}function x7(t,e){var n=new l1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=d8(l8,t,e),n}function M7(t){var e=new l1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function Rc(t){var e=new l1.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var n=0;n<t.length;n+=1)e.strings.push({name:"string_"+n,type:"STRING",value:t[n]});return e}function Fc(){return new l1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function _c(t,e){for(var n=new l1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),r=0;r<t.length;r+=1){var a=t[r],s=f8(a,e);n.fields.push({name:"glyph_"+r,type:"SID",value:s})}return n}function qc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var r=0,a=0,s=0;s<n.commands.length;s+=1){var c=void 0,o=void 0,i=n.commands[s];if(i.type==="Q"){var l=.3333333333333333,h=2/3;i={type:"C",x:i.x,y:i.y,x1:Math.round(l*r+h*i.x1),y1:Math.round(l*a+h*i.y1),x2:Math.round(l*i.x+h*i.x1),y2:Math.round(l*i.y+h*i.y1)}}if(i.type==="M")c=Math.round(i.x-r),o=Math.round(i.y-a),e.push({name:"dx",type:"NUMBER",value:c}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rmoveto",type:"OP",value:21}),r=Math.round(i.x),a=Math.round(i.y);else if(i.type==="L")c=Math.round(i.x-r),o=Math.round(i.y-a),e.push({name:"dx",type:"NUMBER",value:c}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rlineto",type:"OP",value:5}),r=Math.round(i.x),a=Math.round(i.y);else if(i.type==="C"){var u=Math.round(i.x1-r),f=Math.round(i.y1-a),d=Math.round(i.x2-i.x1),m=Math.round(i.y2-i.y1);c=Math.round(i.x-i.x2),o=Math.round(i.y-i.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:m}),e.push({name:"dx",type:"NUMBER",value:c}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rrcurveto",type:"OP",value:8}),r=Math.round(i.x),a=Math.round(i.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function Dc(t){for(var e=new l1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var r=t.get(n),a=qc(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:a})}return e}function Nc(t,e){var n=new l1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=d8(h8,t,e),n}function Uc(t,e){for(var n=new l1.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),r=1/e.unitsPerEm,a={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[r,0,0,r,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},s={},c=[],o,i=1;i<t.length;i+=1)o=t.get(i),c.push(o.name);var l=[];n.header=Hc(),n.nameIndex=Oc([e.postScriptName]);var h=x7(a,l);n.topDictIndex=M7(h),n.globalSubrIndex=Fc(),n.charsets=_c(c,l),n.charStringsIndex=Dc(t),n.privateDict=Nc(s,l),n.stringIndex=Rc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return a.charset=u,a.encoding=0,a.charStrings=a.charset+n.charsets.sizeOf(),a.private[1]=a.charStrings+n.charStringsIndex.sizeOf(),h=x7(a,l),n.topDictIndex=M7(h),n}var m8={parse:$c,make:Uc};function Bc(t,e){var n={},r=new y1.Parser(t,e);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),H1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=r.parseUShort(),n.unitsPerEm=r.parseUShort(),n.created=r.parseLongDateTime(),n.modified=r.parseLongDateTime(),n.xMin=r.parseShort(),n.yMin=r.parseShort(),n.xMax=r.parseShort(),n.yMax=r.parseShort(),n.macStyle=r.parseUShort(),n.lowestRecPPEM=r.parseUShort(),n.fontDirectionHint=r.parseShort(),n.indexToLocFormat=r.parseShort(),n.glyphDataFormat=r.parseShort(),n}function jc(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new l1.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:n},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],t)}var p8={parse:Bc,make:jc};function Gc(t,e){var n={},r=new y1.Parser(t,e);return n.version=r.parseVersion(),n.ascender=r.parseShort(),n.descender=r.parseShort(),n.lineGap=r.parseShort(),n.advanceWidthMax=r.parseUShort(),n.minLeftSideBearing=r.parseShort(),n.minRightSideBearing=r.parseShort(),n.xMaxExtent=r.parseShort(),n.caretSlopeRise=r.parseShort(),n.caretSlopeRun=r.parseShort(),n.caretOffset=r.parseShort(),r.relativeOffset+=8,n.metricDataFormat=r.parseShort(),n.numberOfHMetrics=r.parseUShort(),n}function Wc(t){return new l1.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],t)}var g8={parse:Gc,make:Wc};function Xc(t,e,n,r,a){for(var s,c,o=new y1.Parser(t,e),i=0;i<r;i+=1){i<n&&(s=o.parseUShort(),c=o.parseShort());var l=a.get(i);l.advanceWidth=s,l.leftSideBearing=c}}function Zc(t,e,n,r,a){t._hmtxTableData={};for(var s,c,o=new y1.Parser(e,n),i=0;i<a;i+=1)i<r&&(s=o.parseUShort(),c=o.parseShort()),t._hmtxTableData[i]={advanceWidth:s,leftSideBearing:c}}function Yc(t,e,n,r,a,s,c){c.lowMemory?Zc(t,e,n,r,a):Xc(e,n,r,a,s)}function Kc(t){for(var e=new l1.Table("hmtx",[]),n=0;n<t.length;n+=1){var r=t.get(n),a=r.advanceWidth||0,s=r.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:a}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:s})}return e}var v8={parse:Yc,make:Kc};function Jc(t){for(var e=new l1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",r=12+t.length*4,a=0;a<t.length;++a){var s=n.indexOf(t[a]);s<0&&(s=n.length,n+=t[a]),e.fields.push({name:"offset "+a,type:"USHORT",value:r+s}),e.fields.push({name:"length "+a,type:"USHORT",value:t[a].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Qc(t,e){var n=new y1.Parser(t,e),r=n.parseULong();H1.argument(r===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var a=n.parseULong(),s=[],c=0;c<a;c++){for(var o="",i=e+n.parseUShort(),l=n.parseUShort(),h=i;h<i+l;++h)o+=String.fromCharCode(t.getInt8(h));s.push(o)}return s}var b8={make:Jc,parse:Qc};function e9(t,e){var n={},r=new y1.Parser(t,e);return n.version=r.parseVersion(),n.numGlyphs=r.parseUShort(),n.version===1&&(n.maxPoints=r.parseUShort(),n.maxContours=r.parseUShort(),n.maxCompositePoints=r.parseUShort(),n.maxCompositeContours=r.parseUShort(),n.maxZones=r.parseUShort(),n.maxTwilightPoints=r.parseUShort(),n.maxStorage=r.parseUShort(),n.maxFunctionDefs=r.parseUShort(),n.maxInstructionDefs=r.parseUShort(),n.maxStackElements=r.parseUShort(),n.maxSizeOfInstructions=r.parseUShort(),n.maxComponentElements=r.parseUShort(),n.maxComponentDepth=r.parseUShort()),n}function t9(t){return new l1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var y8={parse:e9,make:t9},x8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],M8={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},n9={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},w8={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function r9(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return M8[e];case 3:return w8[e]}}var V4="utf-16",a9={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},s9={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function k8(t,e,n){switch(t){case 0:return V4;case 1:return s9[n]||a9[e];case 3:if(e===1||e===10)return V4;break}}function c9(t,e,n){for(var r={},a=new y1.Parser(t,e),s=a.parseUShort(),c=a.parseUShort(),o=a.offset+a.parseUShort(),i=0;i<c;i++){var l=a.parseUShort(),h=a.parseUShort(),u=a.parseUShort(),f=a.parseUShort(),d=x8[f]||f,m=a.parseUShort(),p=a.parseUShort(),g=r9(l,u,n),v=k8(l,h,u);if(v!==void 0&&g!==void 0){var b=void 0;if(v===V4?b=l3.UTF16(t,o+p,m):b=l3.MACSTRING(t,o+p,m,v),b){var y=r[d];y===void 0&&(y=r[d]={}),y[g]=b}}}var M=0;return s===1&&(M=a.parseUShort()),r}function x4(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function w7(t,e,n,r,a,s){return new l1.Record("NameRecord",[{name:"platformID",type:"USHORT",value:t},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:n},{name:"nameID",type:"USHORT",value:r},{name:"length",type:"USHORT",value:a},{name:"offset",type:"USHORT",value:s}])}function o9(t,e){var n=t.length,r=e.length-n+1;e:for(var a=0;a<r;a++)for(;a<r;a++){for(var s=0;s<n;s++)if(e[a+s]!==t[s])continue e;return a}return-1}function k7(t,e){var n=o9(t,e);if(n<0){n=e.length;for(var r=0,a=t.length;r<a;++r)e.push(t[r])}return n}function i9(t,e){var n,r=[],a={},s=x4(x8);for(var c in t){var o=s[c];if(o===void 0&&(o=c),n=parseInt(o),isNaN(n))throw new Error('Name table entry "'+c+'" does not exist, see nameTableNames for complete list.');a[n]=t[c],r.push(n)}for(var i=x4(M8),l=x4(w8),h=[],u=[],f=0;f<r.length;f++){n=r[f];var d=a[n];for(var m in d){var p=d[m],g=1,v=i[m],b=n9[v],y=k8(g,b,v),M=r1.MACSTRING(p,y);M===void 0&&(g=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),b=4,M=r1.UTF16(p));var w=k7(M,u);h.push(w7(g,b,v,n,M.length,w));var x=l[m];if(x!==void 0){var k=r1.UTF16(p),A=k7(k,u);h.push(w7(3,1,x,n,k.length,A))}}}h.sort(function(S,C){return S.platformID-C.platformID||S.encodingID-C.encodingID||S.languageID-C.languageID||S.nameID-C.nameID});for(var L=new l1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),z=0;z<h.length;z++)L.fields.push({name:"record_"+z,type:"RECORD",value:h[z]});return L.fields.push({name:"strings",type:"LITERAL",value:u}),L}var z8={parse:c9,make:i9},$4=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function l9(t){for(var e=0;e<$4.length;e+=1){var n=$4[e];if(t>=n.begin&&t<n.end)return e}return-1}function h9(t,e){var n={},r=new y1.Parser(t,e);n.version=r.parseUShort(),n.xAvgCharWidth=r.parseShort(),n.usWeightClass=r.parseUShort(),n.usWidthClass=r.parseUShort(),n.fsType=r.parseUShort(),n.ySubscriptXSize=r.parseShort(),n.ySubscriptYSize=r.parseShort(),n.ySubscriptXOffset=r.parseShort(),n.ySubscriptYOffset=r.parseShort(),n.ySuperscriptXSize=r.parseShort(),n.ySuperscriptYSize=r.parseShort(),n.ySuperscriptXOffset=r.parseShort(),n.ySuperscriptYOffset=r.parseShort(),n.yStrikeoutSize=r.parseShort(),n.yStrikeoutPosition=r.parseShort(),n.sFamilyClass=r.parseShort(),n.panose=[];for(var a=0;a<10;a++)n.panose[a]=r.parseByte();return n.ulUnicodeRange1=r.parseULong(),n.ulUnicodeRange2=r.parseULong(),n.ulUnicodeRange3=r.parseULong(),n.ulUnicodeRange4=r.parseULong(),n.achVendID=String.fromCharCode(r.parseByte(),r.parseByte(),r.parseByte(),r.parseByte()),n.fsSelection=r.parseUShort(),n.usFirstCharIndex=r.parseUShort(),n.usLastCharIndex=r.parseUShort(),n.sTypoAscender=r.parseShort(),n.sTypoDescender=r.parseShort(),n.sTypoLineGap=r.parseShort(),n.usWinAscent=r.parseUShort(),n.usWinDescent=r.parseUShort(),n.version>=1&&(n.ulCodePageRange1=r.parseULong(),n.ulCodePageRange2=r.parseULong()),n.version>=2&&(n.sxHeight=r.parseShort(),n.sCapHeight=r.parseShort(),n.usDefaultChar=r.parseUShort(),n.usBreakChar=r.parseUShort(),n.usMaxContent=r.parseUShort()),n}function u9(t){return new l1.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],t)}var H4={parse:h9,make:u9,unicodeRanges:$4,getUnicodeRange:l9};function f9(t,e){var n={},r=new y1.Parser(t,e);switch(n.version=r.parseVersion(),n.italicAngle=r.parseFixed(),n.underlinePosition=r.parseShort(),n.underlineThickness=r.parseShort(),n.isFixedPitch=r.parseULong(),n.minMemType42=r.parseULong(),n.maxMemType42=r.parseULong(),n.minMemType1=r.parseULong(),n.maxMemType1=r.parseULong(),n.version){case 1:n.names=Ve.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var a=0;a<n.numberOfGlyphs;a++)n.glyphNameIndex[a]=r.parseUShort();n.names=[];for(var s=0;s<n.numberOfGlyphs;s++)if(n.glyphNameIndex[s]>=Ve.length){var c=r.parseChar();n.names.push(r.parseString(c))}break;case 2.5:n.numberOfGlyphs=r.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var o=0;o<n.numberOfGlyphs;o++)n.offset[o]=r.parseChar();break}return n}function d9(){return new l1.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var S8={parse:f9,make:d9},M2=new Array(9);M2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(N.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(N.coverage),substitute:this.parseOffset16List()};H1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};M2[2]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),sequences:this.parseListOfLists()}};M2[3]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),alternateSets:this.parseListOfLists()}};M2[4]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var i3={sequenceIndex:N.uShort,lookupListIndex:N.uShort};M2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(N.coverage),ruleSets:this.parseListOfLists(function(){var s=this.parseUShort(),c=this.parseUShort();return{input:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(c,i3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(N.coverage),classDef:this.parsePointer(N.classDef),classSets:this.parseListOfLists(function(){var s=this.parseUShort(),c=this.parseUShort();return{classes:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(c,i3)}})};if(n===3){var r=this.parseUShort(),a=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,N.pointer(N.coverage)),lookupRecords:this.parseRecordList(a,i3)}}H1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};M2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(N.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(i3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(N.coverage),backtrackClassDef:this.parsePointer(N.classDef),inputClassDef:this.parsePointer(N.classDef),lookaheadClassDef:this.parsePointer(N.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(i3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(N.pointer(N.coverage)),inputCoverage:this.parseList(N.pointer(N.coverage)),lookaheadCoverage:this.parseList(N.pointer(N.coverage)),lookupRecords:this.parseRecordList(i3)};H1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};M2[7]=function(){var e=this.parseUShort();H1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),r=new N(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:M2[n].call(r)}};M2[8]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),backtrackCoverage:this.parseList(N.pointer(N.coverage)),lookaheadCoverage:this.parseList(N.pointer(N.coverage)),substitutes:this.parseUShortList()}};function m9(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return H1.argument(r===1||r===1.1,"Unsupported GSUB table version."),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(M2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(M2),variations:n.parseFeatureVariationsList()}}var h3=new Array(9);h3[1]=function(e){return e.substFormat===1?new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.ushortList("substitute",e.substitute)))};h3[2]=function(e){return H1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("seqSet",e.sequences,function(n){return new l1.Table("sequenceSetTable",l1.ushortList("sequence",n))})))};h3[3]=function(e){return H1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("altSet",e.alternateSets,function(n){return new l1.Table("alternateSetTable",l1.ushortList("alternate",n))})))};h3[4]=function(e){return H1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("ligSet",e.ligatureSets,function(n){return new l1.Table("ligatureSetTable",l1.tableList("ligature",n,function(r){return new l1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:r.ligGlyph}].concat(l1.ushortList("component",r.components,r.components.length+1)))}))})))};h3[6]=function(e){if(e.substFormat===1){var n=new l1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("chainRuleSet",e.chainRuleSets,function(s){return new l1.Table("chainRuleSetTable",l1.tableList("chainRule",s,function(c){var o=l1.ushortList("backtrackGlyph",c.backtrack,c.backtrack.length).concat(l1.ushortList("inputGlyph",c.input,c.input.length+1)).concat(l1.ushortList("lookaheadGlyph",c.lookahead,c.lookahead.length)).concat(l1.ushortList("substitution",[],c.lookupRecords.length));return c.lookupRecords.forEach(function(i,l){o=o.concat({name:"sequenceIndex"+l,type:"USHORT",value:i.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:i.lookupListIndex})}),new l1.Table("chainRuleTable",o)}))})));return n}else if(e.substFormat===2)H1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var r=[{name:"substFormat",type:"USHORT",value:e.substFormat}];r.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(s,c){r.push({name:"backtrackCoverage"+c,type:"TABLE",value:new l1.Coverage(s)})}),r.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(s,c){r.push({name:"inputCoverage"+c,type:"TABLE",value:new l1.Coverage(s)})}),r.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(s,c){r.push({name:"lookaheadCoverage"+c,type:"TABLE",value:new l1.Coverage(s)})}),r.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(s,c){r=r.concat({name:"sequenceIndex"+c,type:"USHORT",value:s.sequenceIndex}).concat({name:"lookupListIndex"+c,type:"USHORT",value:s.lookupListIndex})});var a=new l1.Table("chainContextTable",r);return a}H1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function p9(t){return new l1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new l1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new l1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new l1.LookupList(t.lookups,h3)}])}var A8={parse:m9,make:p9};function g9(t,e){var n=new y1.Parser(t,e),r=n.parseULong();H1.argument(r===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var a=n.parseULong(),s={},c=0;c<a;c++){var o=n.parseTag(),i=n.parseULong(),l=n.parseULong(),h=l3.UTF8(t,e+i,l);s[o]=h}return s}function v9(t){var e=Object.keys(t).length,n="",r=16+e*12,a=new l1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:r},{name:"numTags",type:"ULONG",value:e}]);for(var s in t){var c=n.length;n+=t[s],a.fields.push({name:"tag "+s,type:"TAG",value:s}),a.fields.push({name:"offset "+s,type:"ULONG",value:r+c}),a.fields.push({name:"length "+s,type:"ULONG",value:t[s].length})}return a.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),a}var L8={parse:g9,make:v9};function z7(t){return Math.log(t)/Math.log(2)|0}function U4(t){for(;t.length%4!==0;)t.push(0);for(var e=0,n=0;n<t.length;n+=4)e+=(t[n]<<24)+(t[n+1]<<16)+(t[n+2]<<8)+t[n+3];return e%=Math.pow(2,32),e}function S7(t,e,n,r){return new l1.Record("Table Record",[{name:"tag",type:"TAG",value:t!==void 0?t:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:n!==void 0?n:0},{name:"length",type:"ULONG",value:r!==void 0?r:0}])}function C8(t){var e=new l1.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=t,e.numTables=t.length;var n=Math.pow(2,z7(e.numTables));e.searchRange=16*n,e.entrySelector=z7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],a=[],s=e.sizeOf()+S7().sizeOf()*e.numTables;s%4!==0;)s+=1,a.push({name:"padding",type:"BYTE",value:0});for(var c=0;c<t.length;c+=1){var o=t[c];H1.argument(o.tableName.length===4,"Table name"+o.tableName+" is invalid.");var i=o.sizeOf(),l=S7(o.tableName,U4(o.encode()),s,i);for(r.push({name:l.tag+" Table Record",type:"RECORD",value:l}),a.push({name:o.tableName+" table",type:"RECORD",value:o}),s+=i,H1.argument(!isNaN(s),"Something went wrong calculating the offset.");s%4!==0;)s+=1,a.push({name:"padding",type:"BYTE",value:0})}return r.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(r),e.fields=e.fields.concat(a),e}function A7(t,e,n){for(var r=0;r<e.length;r+=1){var a=t.charToGlyphIndex(e[r]);if(a>0){var s=t.glyphs.get(a);return s.getMetrics()}}return n}function b9(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function y9(t){for(var e=[],n=[],r=[],a=[],s=[],c=[],o=[],i,l=0,h=0,u=0,f=0,d=0,m=0;m<t.glyphs.length;m+=1){var p=t.glyphs.get(m),g=p.unicode|0;if(isNaN(p.advanceWidth))throw new Error("Glyph "+p.name+" ("+m+"): advanceWidth is not a number.");(i>g||i===void 0)&&g>0&&(i=g),l<g&&(l=g);var v=H4.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(p.name!==".notdef"){var b=p.getMetrics();e.push(b.xMin),n.push(b.yMin),r.push(b.xMax),a.push(b.yMax),c.push(b.leftSideBearing),o.push(b.rightSideBearing),s.push(p.advanceWidth)}}var y={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,r),yMax:Math.max.apply(null,a),advanceWidthMax:Math.max.apply(null,s),advanceWidthAvg:b9(s),minLeftSideBearing:Math.min.apply(null,c),maxLeftSideBearing:Math.max.apply(null,c),minRightSideBearing:Math.min.apply(null,o)};y.ascender=t.ascender,y.descender=t.descender;var M=p8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),w=g8.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:t.glyphs.length}),x=y8.make(t.glyphs.length),k=H4.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:i,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:A7(t,"xyvw",{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:A7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",y).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),A=v8.make(t.glyphs),L=r8.make(t.glyphs),z=t.getEnglishName("fontFamily"),S=t.getEnglishName("fontSubfamily"),C=z+" "+S,E=t.getEnglishName("postScriptName");E||(E=z.replace(/\s/g,"")+"-"+S);var I={};for(var H in t.names)I[H]=t.names[H];I.uniqueID||(I.uniqueID={en:t.getEnglishName("manufacturer")+":"+C}),I.postScriptName||(I.postScriptName={en:E}),I.preferredFamily||(I.preferredFamily=t.names.fontFamily),I.preferredSubfamily||(I.preferredSubfamily=t.names.fontSubfamily);var T=[],O=z8.make(I,T),_=T.length>0?b8.make(T):void 0,D=S8.make(),G=m8.make(t.glyphs,{version:t.getEnglishName("version"),fullName:C,familyName:z,weightName:S,postScriptName:E,unitsPerEm:t.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),V=t.metas&&Object.keys(t.metas).length>0?L8.make(t.metas):void 0,U=[M,w,x,k,O,L,D,G,A];_&&U.push(_),t.tables.gsub&&U.push(A8.make(t.tables.gsub)),V&&U.push(V);for(var J=C8(U),n1=J.encode(),m1=U4(n1),M1=J.fields,c1=!1,C1=0;C1<M1.length;C1+=1)if(M1[C1].name==="head table"){M1[C1].value.checkSumAdjustment=2981146554-m1,c1=!0;break}if(!c1)throw new Error("Could not find head table with checkSum to adjust.");return J}var x9={make:C8,fontToTable:y9,computeCheckSum:U4};function M4(t,e){for(var n=0,r=t.length-1;n<=r;){var a=n+r>>>1,s=t[a].tag;if(s===e)return a;s<e?n=a+1:r=a-1}return-n-1}function L7(t,e){for(var n=0,r=t.length-1;n<=r;){var a=n+r>>>1,s=t[a];if(s===e)return a;s<e?n=a+1:r=a-1}return-n-1}function C7(t,e){for(var n,r=0,a=t.length-1;r<=a;){var s=r+a>>>1;n=t[s];var c=n.start;if(c===e)return n;c<e?r=s+1:a=s-1}if(r>0)return n=t[r-1],e>n.end?0:n}function s5(t,e){this.font=t,this.tableName=e}s5.prototype={searchTag:M4,binSearch:L7,getTable:function(t){var e=this.font.tables[this.tableName];return!e&&t&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var t=this.getTable();return t?t.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var t=this.getTable();if(t){for(var e=!1,n=0;n<t.scripts.length;n++){var r=t.scripts[n].tag;if(r==="DFLT")return r;r==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var r=n.scripts,a=M4(n.scripts,t);if(a>=0)return r[a].script;if(e){var s={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-a,0,s),s.script}}},getLangSysTable:function(t,e,n){var r=this.getScriptTable(t,n);if(r){if(!e||e==="dflt"||e==="DFLT")return r.defaultLangSys;var a=M4(r.langSysRecords,e);if(a>=0)return r.langSysRecords[a].langSys;if(n){var s={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-a,0,s),s.langSys}}},getFeatureTable:function(t,e,n,r){var a=this.getLangSysTable(t,e,r);if(a){for(var s,c=a.featureIndexes,o=this.font.tables[this.tableName].features,i=0;i<c.length;i++)if(s=o[c[i]],s.tag===n)return s.feature;if(r){var l=o.length;return H1.assert(l===0||n>=o[l-1].tag,"Features must be added in alphabetical order."),s={tag:n,feature:{params:0,lookupListIndexes:[]}},o.push(s),c.push(l),s.feature}}},getLookupTables:function(t,e,n,r,a){var s=this.getFeatureTable(t,e,n,a),c=[];if(s){for(var o,i=s.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<i.length;h++)o=l[i[h]],o.lookupType===r&&c.push(o);if(c.length===0&&a){o={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(o),i.push(u),[o]}}return c},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=C7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=L7(t.glyphs,e);return n>=0?n:-1;case 2:var r=C7(t.ranges,e);return r?r.index+e-r.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,r=0;r<n.length;r++)for(var a=n[r],s=a.start,c=a.end,o=s;o<=c;o++)e.push(o);return e}};function c5(t){s5.call(this,t,"gpos")}c5.prototype=s5.prototype;c5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};c5.prototype.getKerningValue=function(t,e,n){for(var r=0;r<t.length;r++)for(var a=t[r].subtables,s=0;s<a.length;s++){var c=a[s],o=this.getCoverageIndex(c.coverage,e);if(!(o<0))switch(c.posFormat){case 1:for(var i=c.pairSets[o],l=0;l<i.length;l++){var h=i[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(c.classDef1,e),f=this.getGlyphClass(c.classDef2,n),d=c.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};c5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function h2(t){s5.call(this,t,"gsub")}function M9(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}function B4(t,e,n){for(var r=t.subtables,a=0;a<r.length;a++){var s=r[a];if(s.substFormat===e)return s}if(n)return r.push(n),n}h2.prototype=s5.prototype;h2.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};h2.prototype.getSingle=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,1),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++){var i=c[o],l=this.expandCoverage(i.coverage),h=void 0;if(i.substFormat===1){var u=i.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];r.push({sub:f,by:f+u})}}else{var d=i.substitute;for(h=0;h<l.length;h++)r.push({sub:l[h],by:d[h]})}}return r};h2.prototype.getMultiple=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,2),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++){var i=c[o],l=this.expandCoverage(i.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=i.sequences[h];r.push({sub:u,by:f})}}return r};h2.prototype.getAlternates=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,3),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++)for(var i=c[o],l=this.expandCoverage(i.coverage),h=i.alternateSets,u=0;u<l.length;u++)r.push({sub:l[u],by:h[u]});return r};h2.prototype.getLigatures=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,4),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++)for(var i=c[o],l=this.expandCoverage(i.coverage),h=i.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],m=0;m<d.length;m++){var p=d[m];r.push({sub:[f].concat(p.components),by:p.ligGlyph})}return r};h2.prototype.addSingle=function(t,e,n,r){var a=this.getLookupTables(n,r,t,1,!0)[0],s=B4(a,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});H1.assert(s.coverage.format===1,"Single: unable to modify coverage table format "+s.coverage.format);var c=e.sub,o=this.binSearch(s.coverage.glyphs,c);o<0&&(o=-1-o,s.coverage.glyphs.splice(o,0,c),s.substitute.splice(o,0,0)),s.substitute[o]=e.by};h2.prototype.addMultiple=function(t,e,n,r){H1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var a=this.getLookupTables(n,r,t,2,!0)[0],s=B4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});H1.assert(s.coverage.format===1,"Multiple: unable to modify coverage table format "+s.coverage.format);var c=e.sub,o=this.binSearch(s.coverage.glyphs,c);o<0&&(o=-1-o,s.coverage.glyphs.splice(o,0,c),s.sequences.splice(o,0,0)),s.sequences[o]=e.by};h2.prototype.addAlternate=function(t,e,n,r){var a=this.getLookupTables(n,r,t,3,!0)[0],s=B4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});H1.assert(s.coverage.format===1,"Alternate: unable to modify coverage table format "+s.coverage.format);var c=e.sub,o=this.binSearch(s.coverage.glyphs,c);o<0&&(o=-1-o,s.coverage.glyphs.splice(o,0,c),s.alternateSets.splice(o,0,0)),s.alternateSets[o]=e.by};h2.prototype.addLigature=function(t,e,n,r){var a=this.getLookupTables(n,r,t,4,!0)[0],s=a.subtables[0];s||(s={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},a.subtables[0]=s),H1.assert(s.coverage.format===1,"Ligature: unable to modify coverage table format "+s.coverage.format);var c=e.sub[0],o=e.sub.slice(1),i={ligGlyph:e.by,components:o},l=this.binSearch(s.coverage.glyphs,c);if(l>=0){for(var h=s.ligatureSets[l],u=0;u<h.length;u++)if(M9(h[u].components,o))return;h.push(i)}else l=-1-l,s.coverage.glyphs.splice(l,0,c),s.ligatureSets.splice(l,0,[i])};h2.prototype.getFeature=function(t,e,n){if(/ss\d\d/.test(t))return this.getSingle(t,e,n);switch(t){case"aalt":case"salt":return this.getSingle(t,e,n).concat(this.getAlternates(t,e,n));case"dlig":case"liga":case"rlig":return this.getLigatures(t,e,n);case"ccmp":return this.getMultiple(t,e,n).concat(this.getLigatures(t,e,n));case"stch":return this.getMultiple(t,e,n)}};h2.prototype.add=function(t,e,n,r){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,r);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,r):this.addAlternate(t,e,n,r);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,r);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,r):this.addLigature(t,e,n,r)}};function w9(){return typeof window<"u"}function k9(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),r=0;r<e.length;++r)e[r]=n[r];return e}function Q3(t,e){if(!t)throw e}function P7(t,e,n,r,a){var s;return(e&r)>0?(s=t.parseByte(),(e&a)===0&&(s=-s),s=n+s):(e&a)>0?s=n:s=n+t.parseShort(),s}function P8(t,e,n){var r=new y1.Parser(e,n);t.numberOfContours=r.parseShort(),t._xMin=r.parseShort(),t._yMin=r.parseShort(),t._xMax=r.parseShort(),t._yMax=r.parseShort();var a,s;if(t.numberOfContours>0){for(var c=t.endPointIndices=[],o=0;o<t.numberOfContours;o+=1)c.push(r.parseUShort());t.instructionLength=r.parseUShort(),t.instructions=[];for(var i=0;i<t.instructionLength;i+=1)t.instructions.push(r.parseByte());var l=c[c.length-1]+1;a=[];for(var h=0;h<l;h+=1)if(s=r.parseByte(),a.push(s),(s&8)>0)for(var u=r.parseByte(),f=0;f<u;f+=1)a.push(s),h+=1;if(H1.argument(a.length===l,"Bad flags."),c.length>0){var d=[],m;if(l>0){for(var p=0;p<l;p+=1)s=a[p],m={},m.onCurve=!!(s&1),m.lastPointOfContour=c.indexOf(p)>=0,d.push(m);for(var g=0,v=0;v<l;v+=1)s=a[v],m=d[v],m.x=P7(r,s,g,2,16),g=m.x;for(var b=0,y=0;y<l;y+=1)s=a[y],m=d[y],m.y=P7(r,s,b,4,32),b=m.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var M=!0;M;){a=r.parseUShort();var w={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(a&1)>0?(a&2)>0?(w.dx=r.parseShort(),w.dy=r.parseShort()):w.matchedPoints=[r.parseUShort(),r.parseUShort()]:(a&2)>0?(w.dx=r.parseChar(),w.dy=r.parseChar()):w.matchedPoints=[r.parseByte(),r.parseByte()],(a&8)>0?w.xScale=w.yScale=r.parseF2Dot14():(a&64)>0?(w.xScale=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()):(a&128)>0&&(w.xScale=r.parseF2Dot14(),w.scale01=r.parseF2Dot14(),w.scale10=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()),t.components.push(w),M=!!(a&32)}if(a&256){t.instructionLength=r.parseUShort(),t.instructions=[];for(var x=0;x<t.instructionLength;x+=1)t.instructions.push(r.parseByte())}}}function w4(t,e){for(var n=[],r=0;r<t.length;r+=1){var a=t[r],s={x:e.xScale*a.x+e.scale01*a.y+e.dx,y:e.scale10*a.x+e.yScale*a.y+e.dy,onCurve:a.onCurve,lastPointOfContour:a.lastPointOfContour};n.push(s)}return n}function z9(t){for(var e=[],n=[],r=0;r<t.length;r+=1){var a=t[r];n.push(a),a.lastPointOfContour&&(e.push(n),n=[])}return H1.argument(n.length===0,"There are still points left in the current contour."),e}function E8(t){var e=new F0;if(!t)return e;for(var n=z9(t),r=0;r<n.length;++r){var a=n[r],s=null,c=a[a.length-1],o=a[0];if(c.onCurve)e.moveTo(c.x,c.y);else if(o.onCurve)e.moveTo(o.x,o.y);else{var i={x:(c.x+o.x)*.5,y:(c.y+o.y)*.5};e.moveTo(i.x,i.y)}for(var l=0;l<a.length;++l)if(s=c,c=o,o=a[(l+1)%a.length],c.onCurve)e.lineTo(c.x,c.y);else{var h=s,u=o;s.onCurve||(h={x:(c.x+s.x)*.5,y:(c.y+s.y)*.5}),o.onCurve||(u={x:(c.x+o.x)*.5,y:(c.y+o.y)*.5}),e.quadraticCurveTo(c.x,c.y,u.x,u.y)}e.closePath()}return e}function T8(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var r=e.components[n],a=t.get(r.glyphIndex);if(a.getPath(),a.points){var s=void 0;if(r.matchedPoints===void 0)s=w4(a.points,r);else{if(r.matchedPoints[0]>e.points.length-1||r.matchedPoints[1]>a.points.length-1)throw Error("Matched points out of range in "+e.name);var c=e.points[r.matchedPoints[0]],o=a.points[r.matchedPoints[1]],i={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};o=w4([o],i)[0],i.dx=c.x-o.x,i.dy=c.y-o.y,s=w4(a.points,i)}e.points=e.points.concat(s)}}return E8(e.points)}function S9(t,e,n,r){for(var a=new q2.GlyphSet(r),s=0;s<n.length-1;s+=1){var c=n[s],o=n[s+1];c!==o?a.push(s,q2.ttfGlyphLoader(r,s,P8,t,e+c,T8)):a.push(s,q2.glyphLoader(r,s))}return a}function A9(t,e,n,r){var a=new q2.GlyphSet(r);return r._push=function(s){var c=n[s],o=n[s+1];c!==o?a.push(s,q2.ttfGlyphLoader(r,s,P8,t,e+c,T8)):a.push(s,q2.glyphLoader(r,s))},a}function L9(t,e,n,r,a){return a.lowMemory?A9(t,e,n,r):S9(t,e,n,r)}var I8={getPath:E8,parse:L9},V8,He,$8,O4;function H8(t){this.font=t,this.getCommands=function(e){return I8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function C9(t){return t}function O8(t){return Math.sign(t)*Math.round(Math.abs(t))}function P9(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function E9(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function T9(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function I9(t){return Math.sign(t)*Math.floor(Math.abs(t))}var R8=function(t){var e=this.srPeriod,n=this.srPhase,r=this.srThreshold,a=1;return t<0&&(t=-t,a=-1),t+=r-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*a:t*a},_2={x:1,y:0,axis:"x",distance:function(t,e,n,r){return(n?t.xo:t.x)-(r?e.xo:e.x)},interpolate:function(t,e,n,r){var a,s,c,o,i,l,h;if(!r||r===this){if(a=t.xo-e.xo,s=t.xo-n.xo,i=e.x-e.xo,l=n.x-n.xo,c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){t.x=t.xo+(i+l)/2;return}t.x=t.xo+(i*o+l*c)/h;return}if(a=r.distance(t,e,!0,!0),s=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){_2.setRelative(t,t,(i+l)/2,r,!0);return}_2.setRelative(t,t,(i*o+l*c)/h,r,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,r,a){if(!r||r===this){t.x=(a?e.xo:e.x)+n;return}var s=a?e.xo:e.x,c=a?e.yo:e.y,o=s+n*r.x,i=c+n*r.y;t.x=o+(t.y-i)/r.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},Z2={x:0,y:1,axis:"y",distance:function(t,e,n,r){return(n?t.yo:t.y)-(r?e.yo:e.y)},interpolate:function(t,e,n,r){var a,s,c,o,i,l,h;if(!r||r===this){if(a=t.yo-e.yo,s=t.yo-n.yo,i=e.y-e.yo,l=n.y-n.yo,c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){t.y=t.yo+(i+l)/2;return}t.y=t.yo+(i*o+l*c)/h;return}if(a=r.distance(t,e,!0,!0),s=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){Z2.setRelative(t,t,(i+l)/2,r,!0);return}Z2.setRelative(t,t,(i*o+l*c)/h,r,!0)},normalSlope:0,setRelative:function(t,e,n,r,a){if(!r||r===this){t.y=(a?e.yo:e.y)+n;return}var s=a?e.xo:e.x,c=a?e.yo:e.y,o=s+n*r.x,i=c+n*r.y;t.y=i+r.normalSlope*(t.x-o)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(_2);Object.freeze(Z2);function o5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}o5.prototype.distance=function(t,e,n,r){return this.x*_2.distance(t,e,n,r)+this.y*Z2.distance(t,e,n,r)};o5.prototype.interpolate=function(t,e,n,r){var a,s,c,o,i,l,h;if(c=r.distance(t,e,!0,!0),o=r.distance(t,n,!0,!0),a=r.distance(e,e,!1,!0),s=r.distance(n,n,!1,!0),i=Math.abs(c),l=Math.abs(o),h=i+l,h===0){this.setRelative(t,t,(a+s)/2,r,!0);return}this.setRelative(t,t,(a*l+s*i)/h,r,!0)};o5.prototype.setRelative=function(t,e,n,r,a){r=r||this;var s=a?e.xo:e.x,c=a?e.yo:e.y,o=s+n*r.x,i=c+n*r.y,l=r.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*o+i-f)/(h-l),t.y=h*(t.x-u)+f};o5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function i5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?_2:t===0&&e===1?Z2:new o5(t,e)}function Y2(t,e,n,r){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=r,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}Y2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};Y2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var a5=Object.freeze(new Y2(0,0)),V9={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function de(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=_2,this.round=O8}}H8.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,r=this._prepState;if(!r||r.ppem!==e){var a=this._fpgmState;if(!a){de.prototype=V9,a=this._fpgmState=new de("fpgm",n.tables.fpgm),a.funcs=[],a.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),a.step=-1);try{He(a)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}de.prototype=a,r=this._prepState=new de("prep",n.tables.prep),r.ppem=e;var s=n.tables.cvt;if(s)for(var c=r.cvt=new Array(s.length),o=e/n.unitsPerEm,i=0;i<s.length;i++)c[i]=s[i]*o;else r.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),r.step=-1);try{He(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return $8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};$8=function(t,e){var n=e.ppem/e.font.unitsPerEm,r=n,a=t.components,s,c,o;if(de.prototype=e,!a)o=new de("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),o.step=-1),O4(t,o,n,r),c=o.gZone;else{var i=e.font;c=[],s=[];for(var l=0;l<a.length;l++){var h=a[l],u=i.glyphs.get(h.glyphIndex);o=new de("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),o.step=-1),O4(u,o,n,r);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*r),m=o.gZone,p=o.contours,g=0;g<m.length;g++){var v=m[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var b=c.length;c.push.apply(c,m);for(var y=0;y<p.length;y++)s.push(p[y]+b)}t.instructions&&!o.inhibitGridFit&&(o=new de("glyf",t.instructions),o.gZone=o.z0=o.z1=o.z2=c,o.contours=s,c.push(new Y2(0,0),new Y2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),o.step=-1),He(o),c.length-=2)}return c};O4=function(t,e,n,r){for(var a=t.points||[],s=a.length,c=e.gZone=e.z0=e.z1=e.z2=[],o=e.contours=[],i,l=0;l<s;l++)i=a[l],c[l]=new Y2(i.x*n,i.y*r,i.lastPointOfContour,i.onCurve);for(var h,u,f=0;f<s;f++)i=c[f],h||(h=i,o.push(f)),i.lastPointOfContour?(i.nextPointOnContour=h,h.prevPointOnContour=i,h=void 0):(u=c[f+1],i.nextPointOnContour=u,u.prevPointOnContour=i);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<s;d++)console.log(d,c[d].x,c[d].y)}if(c.push(new Y2(0,0),new Y2(Math.round(t.advanceWidth*n),0)),He(e),c.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<s;m++)console.log(m,c[m].x,c[m].y)}}};He=function(t){var e=t.prog;if(e){var n=e.length,r;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,r=V8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function ot(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new Y2(0,0)}function F8(t,e){var n=t.prog,r=t.ip,a=1,s;do if(s=n[++r],s===88)a++;else if(s===89)a--;else if(s===64)r+=n[r+1]+1;else if(s===65)r+=2*n[r+1]+1;else if(s>=176&&s<=183)r+=s-176+1;else if(s>=184&&s<=191)r+=(s-184+1)*2;else if(e&&a===1&&s===27)break;while(a>0);t.ip=r}function E7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function T7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function I7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function V7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z2[r],c=e.z1[a];exports.DEBUG&&console.log("SPVTL["+t+"]",r,a);var o,i;t?(o=s.y-c.y,i=c.x-s.x):(o=c.x-s.x,i=c.y-s.y),e.pv=e.dpv=i5(o,i)}function $7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z2[r],c=e.z1[a];exports.DEBUG&&console.log("SFVTL["+t+"]",r,a);var o,i;t?(o=s.y-c.y,i=c.x-s.x):(o=c.x-s.x,i=c.y-s.y),e.fv=i5(o,i)}function $9(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.pv=t.dpv=i5(r,n)}function H9(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.fv=i5(r,n)}function O9(t){var e=t.stack,n=t.pv;exports.DEBUG&&console.log(t.step,"GPV[]"),e.push(n.x*16384),e.push(n.y*16384)}function R9(t){var e=t.stack,n=t.fv;exports.DEBUG&&console.log(t.step,"GFV[]"),e.push(n.x*16384),e.push(n.y*16384)}function F9(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function _9(t){var e=t.stack,n=e.pop(),r=e.pop(),a=e.pop(),s=e.pop(),c=e.pop(),o=t.z0,i=t.z1,l=o[n],h=o[r],u=i[a],f=i[s],d=t.z2[c];exports.DEBUG&&console.log("ISECT[], ",n,r,a,s,c);var m=l.x,p=l.y,g=h.x,v=h.y,b=u.x,y=u.y,M=f.x,w=f.y,x=(m-g)*(y-w)-(p-v)*(b-M),k=m*v-p*g,A=b*w-y*M;d.x=(k*(b-M)-A*(m-g))/x,d.y=(k*(y-w)-A*(p-v))/x}function q9(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function D9(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function N9(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function U9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||ot(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function B9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||ot(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function j9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||ot(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function G9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZPS[]",e),t.zp0=t.zp1=t.zp2=e,e){case 0:t.tZone||ot(t),t.z0=t.z1=t.z2=t.tZone;break;case 1:t.z0=t.z1=t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function W9(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function X9(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=O8}function Z9(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=E9}function Y9(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function K9(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),F8(t,!1)}function J9(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Q9(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function eo(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function k4(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function to(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function no(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(r)}function ro(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function ao(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,r);var a=t.ip,s=t.prog;t.prog=t.funcs[n];for(var c=0;c<r;c++)He(t),exports.DEBUG&&console.log(++t.step,c+1<r?"next loopcall":"done loopcall",c);t.ip=a,t.prog=s}function so(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,r=t.prog;t.prog=t.funcs[e],He(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function co(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function oo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"MINDEX[]",n),e.push(e.splice(e.length-n,1)[0])}function io(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,r=t.ip,a=e.pop(),s=r;for(exports.DEBUG&&console.log(t.step,"FDEF[]",a);n[++r]!==45;);t.ip=r,t.funcs[a]=n.slice(s+1,r)}function H7(t,e){var n=e.stack.pop(),r=e.z0[n],a=e.fv,s=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var c=s.distance(r,a5);t&&(c=e.round(c)),a.setRelative(r,a5,c,s),a.touch(r),e.rp0=e.rp1=n}function O7(t,e){var n=e.z2,r=n.length-2,a,s,c;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var o=0;o<r;o++)a=n[o],!t.touched(a)&&(s=a.prevTouched(t),s!==a&&(c=a.nextTouched(t),s===c&&t.setRelative(a,a,t.distance(s,s,!1,!0),t,!0),t.interpolate(a,s,c,t)))}function R7(t,e){for(var n=e.stack,r=t?e.rp1:e.rp2,a=(t?e.z0:e.z1)[r],s=e.fv,c=e.pv,o=e.loop,i=e.z2;o--;){var l=n.pop(),h=i[l],u=c.distance(a,a,!1,!0);s.setRelative(h,h,u,c),s.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-o)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function F7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,a=(t?e.z0:e.z1)[r],s=e.fv,c=e.pv,o=n.pop(),i=e.z2[e.contours[o]],l=i;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",o);var h=c.distance(a,a,!1,!0);do l!==a&&s.setRelative(l,l,h,c),l=l.nextPointOnContour;while(l!==i)}function _7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,a=(t?e.z0:e.z1)[r],s=e.fv,c=e.pv,o=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",o);var i;switch(o){case 0:i=e.tZone;break;case 1:i=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=c.distance(a,a,!1,!0),u=i.length-2,f=0;f<u;f++)l=i[f],s.setRelative(l,l,h,c)}function lo(t){for(var e=t.stack,n=t.loop,r=t.fv,a=e.pop()/64,s=t.z2;n--;){var c=e.pop(),o=s[c];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",c,a),r.setRelative(o,o,a),r.touch(o)}t.loop=1}function ho(t){for(var e=t.stack,n=t.rp1,r=t.rp2,a=t.loop,s=t.z0[n],c=t.z1[r],o=t.fv,i=t.dpv,l=t.z2;a--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-a)+": ":"")+"IP[]",h,n,"<->",r),o.interpolate(u,s,c,i),o.touch(u)}t.loop=1}function q7(t,e){var n=e.stack,r=n.pop()/64,a=n.pop(),s=e.z1[a],c=e.z0[e.rp0],o=e.fv,i=e.pv;o.setRelative(s,c,r,i),o.touch(s),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",r,a),e.rp1=e.rp0,e.rp2=a,t&&(e.rp0=a)}function uo(t){for(var e=t.stack,n=t.rp0,r=t.z0[n],a=t.loop,s=t.fv,c=t.pv,o=t.z1;a--;){var i=e.pop(),l=o[i];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-a)+": ":"")+"ALIGNRP[]",i),s.setRelative(l,r,0,c),s.touch(l)}t.loop=1}function fo(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=P9}function D7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z0[a],c=e.fv,o=e.pv,i=e.cvt[r];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",r,"(",i,")",a);var l=o.distance(s,a5);t&&(Math.abs(l-i)<e.cvCutIn&&(l=i),l=e.round(l)),c.setRelative(s,a5,l,o),e.zp0===0&&(s.xo=s.x,s.yo=s.y),c.touch(s),e.rp0=e.rp1=a}function mo(t){var e=t.prog,n=t.ip,r=t.stack,a=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",a);for(var s=0;s<a;s++)r.push(e[++n]);t.ip=n}function po(t){var e=t.ip,n=t.prog,r=t.stack,a=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",a);for(var s=0;s<a;s++){var c=n[++e]<<8|n[++e];c&32768&&(c=-((c^65535)+1)),r.push(c)}t.ip=e}function go(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var r=e.pop(),a=e.pop();exports.DEBUG&&console.log(t.step,"WS",r,a),n[a]=r}function vo(t){var e=t.stack,n=t.store,r=e.pop();exports.DEBUG&&console.log(t.step,"RS",r);var a=n&&n[r]||0;e.push(a)}function bo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,r),t.cvt[r]=n/64}function yo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function N7(t,e){var n=e.stack,r=n.pop(),a=e.z2[r];exports.DEBUG&&console.log(e.step,"GC["+t+"]",r),n.push(e.dpv.distance(a,a5,t,!1)*64)}function U7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z1[r],c=e.z0[a],o=e.dpv.distance(c,s,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",r,a,"->",o),e.stack.push(Math.round(o*64))}function xo(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Mo(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function wo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,r),e.push(r<n?1:0)}function ko(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,r),e.push(r<=n?1:0)}function zo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,r),e.push(r>n?1:0)}function So(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,r),e.push(r>=n?1:0)}function Ao(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,r),e.push(n===r?1:0)}function Lo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,r),e.push(n!==r?1:0)}function Co(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ODD[]",n),e.push(Math.trunc(n)%2?1:0)}function Po(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"EVEN[]",n),e.push(Math.trunc(n)%2?0:1)}function Eo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(F8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function To(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function Io(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,r),e.push(n&&r?1:0)}function Vo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,r),e.push(n||r?1:0)}function $o(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function z4(t,e){var n=e.stack,r=n.pop(),a=e.fv,s=e.pv,c=e.ppem,o=e.deltaBase+(t-1)*16,i=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",r,n);for(var h=0;h<r;h++){var u=n.pop(),f=n.pop(),d=o+((f&240)>>4);if(d===c){var m=(f&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",m*i);var p=l[u];a.setRelative(p,p,m*i,s)}}}function Ho(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function Oo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function Ro(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,r),e.push(r+n)}function Fo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,r),e.push(r-n)}function _o(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,r),e.push(r*64/n)}function qo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,r),e.push(r*n/64)}function Do(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function No(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function Uo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function Bo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function J5(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function jo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,r),t.cvt[r]=n*t.ppem/t.font.unitsPerEm}function S4(t,e){var n=e.stack,r=n.pop(),a=e.ppem,s=e.deltaBase+(t-1)*16,c=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",r,n);for(var o=0;o<r;o++){var i=n.pop(),l=n.pop(),h=s+((l&240)>>4);if(h===a){var u=(l&15)-8;u>=0&&u++;var f=u*c;exports.DEBUG&&console.log(e.step,"DELTACFIX",i,"by",f),e.cvt[i]+=f}}}function Go(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=R8;var n;switch(e&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw new Error("invalid SROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Wo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=R8;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Xo(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=C9}function Zo(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=T9}function Yo(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=I9}function Ko(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function B7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z2[r],c=e.z1[a];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",r,a);var o,i;t?(o=s.y-c.y,i=c.x-s.x):(o=c.x-s.x,i=c.y-s.y),e.dpv=i5(o,i)}function Jo(t){var e=t.stack,n=e.pop(),r=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(r=35),n&32&&(r|=4096),e.push(r)}function Qo(t){var e=t.stack,n=e.pop(),r=e.pop(),a=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(r),e.push(n),e.push(a)}function ei(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,r),e.push(Math.max(r,n))}function ti(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,r),e.push(Math.min(r,n))}function ni(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function ri(t){var e=t.stack.pop(),n=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"INSTCTRL[]",e,n),e){case 1:t.inhibitGridFit=!!n;return;case 2:t.ignoreCvt=!!n;return;default:throw new Error("invalid INSTCTRL[] selector")}}function he(t,e){var n=e.stack,r=e.prog,a=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var s=0;s<t;s++)n.push(r[++a]);e.ip=a}function ue(t,e){var n=e.ip,r=e.prog,a=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var s=0;s<t;s++){var c=r[++n]<<8|r[++n];c&32768&&(c=-((c^65535)+1)),a.push(c)}e.ip=n}function g1(t,e,n,r,a,s){var c=s.stack,o=t&&c.pop(),i=c.pop(),l=s.rp0,h=s.z0[l],u=s.z1[i],f=s.minDis,d=s.fv,m=s.dpv,p,g,v,b;g=p=m.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(b=s.cvt[o],r&&Math.abs(g-b)<s.cvCutIn&&(g=b)),n&&g<f&&(g=f),r&&(g=s.round(g)),d.setRelative(u,h,v*g,m),d.touch(u),exports.DEBUG&&console.log(s.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(r?"R":"_")+(a===0?"Gr":a===1?"Bl":a===2?"Wh":"")+"]",t?o+"("+s.cvt[o]+","+b+")":"",i,"(d =",p,"->",v*g,")"),s.rp1=s.rp0,s.rp2=i,e&&(s.rp0=i)}V8=[E7.bind(void 0,Z2),E7.bind(void 0,_2),T7.bind(void 0,Z2),T7.bind(void 0,_2),I7.bind(void 0,Z2),I7.bind(void 0,_2),V7.bind(void 0,0),V7.bind(void 0,1),$7.bind(void 0,0),$7.bind(void 0,1),$9,H9,O9,R9,F9,_9,q9,D9,N9,U9,B9,j9,G9,W9,X9,Z9,Y9,K9,J9,Q9,void 0,void 0,eo,k4,to,no,ro,co,oo,void 0,void 0,void 0,ao,so,io,void 0,H7.bind(void 0,0),H7.bind(void 0,1),O7.bind(void 0,Z2),O7.bind(void 0,_2),R7.bind(void 0,0),R7.bind(void 0,1),F7.bind(void 0,0),F7.bind(void 0,1),_7.bind(void 0,0),_7.bind(void 0,1),lo,ho,q7.bind(void 0,0),q7.bind(void 0,1),uo,fo,D7.bind(void 0,0),D7.bind(void 0,1),mo,po,go,vo,bo,yo,N7.bind(void 0,0),N7.bind(void 0,1),void 0,U7.bind(void 0,0),U7.bind(void 0,1),xo,void 0,Mo,void 0,void 0,wo,ko,zo,So,Ao,Lo,Co,Po,Eo,To,Io,Vo,$o,z4.bind(void 0,1),Ho,Oo,Ro,Fo,_o,qo,Do,No,Uo,Bo,J5.bind(void 0,0),J5.bind(void 0,1),J5.bind(void 0,2),J5.bind(void 0,3),void 0,void 0,void 0,void 0,jo,z4.bind(void 0,2),z4.bind(void 0,3),S4.bind(void 0,1),S4.bind(void 0,2),S4.bind(void 0,3),Go,Wo,void 0,void 0,Xo,void 0,Zo,Yo,k4,k4,void 0,void 0,void 0,void 0,void 0,Ko,B7.bind(void 0,0),B7.bind(void 0,1),Jo,void 0,Qo,ei,ti,ni,ri,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,he.bind(void 0,1),he.bind(void 0,2),he.bind(void 0,3),he.bind(void 0,4),he.bind(void 0,5),he.bind(void 0,6),he.bind(void 0,7),he.bind(void 0,8),ue.bind(void 0,1),ue.bind(void 0,2),ue.bind(void 0,3),ue.bind(void 0,4),ue.bind(void 0,5),ue.bind(void 0,6),ue.bind(void 0,7),ue.bind(void 0,8),g1.bind(void 0,0,0,0,0,0),g1.bind(void 0,0,0,0,0,1),g1.bind(void 0,0,0,0,0,2),g1.bind(void 0,0,0,0,0,3),g1.bind(void 0,0,0,0,1,0),g1.bind(void 0,0,0,0,1,1),g1.bind(void 0,0,0,0,1,2),g1.bind(void 0,0,0,0,1,3),g1.bind(void 0,0,0,1,0,0),g1.bind(void 0,0,0,1,0,1),g1.bind(void 0,0,0,1,0,2),g1.bind(void 0,0,0,1,0,3),g1.bind(void 0,0,0,1,1,0),g1.bind(void 0,0,0,1,1,1),g1.bind(void 0,0,0,1,1,2),g1.bind(void 0,0,0,1,1,3),g1.bind(void 0,0,1,0,0,0),g1.bind(void 0,0,1,0,0,1),g1.bind(void 0,0,1,0,0,2),g1.bind(void 0,0,1,0,0,3),g1.bind(void 0,0,1,0,1,0),g1.bind(void 0,0,1,0,1,1),g1.bind(void 0,0,1,0,1,2),g1.bind(void 0,0,1,0,1,3),g1.bind(void 0,0,1,1,0,0),g1.bind(void 0,0,1,1,0,1),g1.bind(void 0,0,1,1,0,2),g1.bind(void 0,0,1,1,0,3),g1.bind(void 0,0,1,1,1,0),g1.bind(void 0,0,1,1,1,1),g1.bind(void 0,0,1,1,1,2),g1.bind(void 0,0,1,1,1,3),g1.bind(void 0,1,0,0,0,0),g1.bind(void 0,1,0,0,0,1),g1.bind(void 0,1,0,0,0,2),g1.bind(void 0,1,0,0,0,3),g1.bind(void 0,1,0,0,1,0),g1.bind(void 0,1,0,0,1,1),g1.bind(void 0,1,0,0,1,2),g1.bind(void 0,1,0,0,1,3),g1.bind(void 0,1,0,1,0,0),g1.bind(void 0,1,0,1,0,1),g1.bind(void 0,1,0,1,0,2),g1.bind(void 0,1,0,1,0,3),g1.bind(void 0,1,0,1,1,0),g1.bind(void 0,1,0,1,1,1),g1.bind(void 0,1,0,1,1,2),g1.bind(void 0,1,0,1,1,3),g1.bind(void 0,1,1,0,0,0),g1.bind(void 0,1,1,0,0,1),g1.bind(void 0,1,1,0,0,2),g1.bind(void 0,1,1,0,0,3),g1.bind(void 0,1,1,0,1,0),g1.bind(void 0,1,1,0,1,1),g1.bind(void 0,1,1,0,1,2),g1.bind(void 0,1,1,0,1,3),g1.bind(void 0,1,1,1,0,0),g1.bind(void 0,1,1,1,0,1),g1.bind(void 0,1,1,1,0,2),g1.bind(void 0,1,1,1,0,3),g1.bind(void 0,1,1,1,1,0),g1.bind(void 0,1,1,1,1,1),g1.bind(void 0,1,1,1,1,2),g1.bind(void 0,1,1,1,1,3)];function u3(t){this.char=t,this.state={},this.activeState=null}function j4(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function ai(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function w2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function it(t){this.eventId=t,this.subscribers=[]}function si(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(a){Object.defineProperty(e.events,a,{value:new it(a)})}),t&&n.forEach(function(a){var s=t[a];typeof s=="function"&&e.events[a].subscribe(s)});var r=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];r.forEach(function(a){e.events[a].subscribe(e.updateContextsRanges)})}function C0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],si.call(this,t)}u3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};u3.prototype.getState=function(t){return this.state[t]||null};C0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};C0.prototype.composeRUD=function(t){var e=this,n=!0,r=t.map(function(s){return e[s[0]].apply(e,s.slice(1).concat(n))}),a=function(s){return typeof s=="object"&&s.hasOwnProperty("FAIL")};if(r.every(a))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:r.filter(a)};this.dispatch("composeRUD",[r.filter(function(s){return!a(s)})])};C0.prototype.replaceRange=function(t,e,n,r){e=e!==null?e:this.tokens.length;var a=n.every(function(c){return c instanceof u3});if(!isNaN(t)&&this.inboundIndex(t)&&a){var s=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return r||this.dispatch("replaceToken",[t,e,n]),[s,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};C0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof u3){var r=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[r[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};C0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var r=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[r,t,e]),r};C0.prototype.removeToken=function(t,e){if(!isNaN(t)&&this.inboundIndex(t)){var n=this.tokens.splice(t,1);return e||this.dispatch("removeToken",[n,t]),n}else return{FAIL:"removeToken: invalid token index."}};C0.prototype.insertToken=function(t,e,n){var r=t.every(function(a){return a instanceof u3});return r?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};C0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(r,a){var s=[r,a],c=e===null||e.apply(this,s)===!0,o=[r,a];if(c){var i=n.apply(this,o);r.setState(t,i)}}),this.registeredModifiers.push(t)};it.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};it.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};w2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};w2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};C0.prototype.rangeToText=function(t){if(t instanceof j4)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};C0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};C0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};C0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};C0.prototype.dispatch=function(t,e){var n=this,r=this.events[t];r instanceof it&&r.subscribers.forEach(function(a){a.apply(n,e||[])})};C0.prototype.registerContextChecker=function(t,e,n){if(this.getContext(t))return{FAIL:"context name '"+t+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof n!="function")return{FAIL:"missing context end check."};var r=new ai(t,e,n);return this.registeredContexts[t]=r,this.contextCheckers.push(r),r};C0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};C0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};C0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};C0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(r){return r.char}),e=0;e<t.length;e++){var n=new w2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};C0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,r=new j4(n,t,e),a=this.getContext(e).ranges;return r.rangeId=e+"."+a.length,a.push(r),this.getContext(e).openRange=null,r};C0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(r){var a=r.contextName,s=e.getContext(a).openRange;if(!s&&r.checkStart(t)&&(s=new j4(n,null,a),e.getContext(a).openRange=s,e.dispatch("contextStart",[a,n])),s&&r.checkEnd(t)){var c=n-s.startIndex+1,o=e.setEndOffset(c,a);e.dispatch("contextEnd",[a,o])}})};C0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var r=e[n],a=new w2(e,n);this.dispatch("next",[a]),this.runContextCheck(a);var s=new u3(r);this.tokens.push(s),this.dispatch("newToken",[s,a])}return this.dispatch("end",[this.tokens]),this.tokens};function me(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function _8(t){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(t)}function pe(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function et(t){return/[A-z]/.test(t)}function ci(t){return/\s/.test(t)}function u2(t){this.font=t,this.features={}}function $e(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function l5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,r=0;r<n.length;r++){var a=n[r];if(t>=a.start&&t<=a.end){var s=t-a.start;return a.index+s}}break;default:return-1}return-1}function oi(t,e){var n=l5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function ii(t,e){var n=l5(t,e.coverage);return n===-1?null:e.substitute[n]}function A4(t,e){for(var n=[],r=0;r<t.length;r++){var a=t[r],s=e.current;s=Array.isArray(s)?s[0]:s;var c=l5(s,a);c!==-1&&n.push(c)}return n.length!==t.length?-1:n}function li(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=A4(e.inputCoverage,t);if(r===-1)return[];var a=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var s=t.lookahead.slice(a);s.length&&pe(s[0].char);)s.shift();var c=new w2(s,0),o=A4(e.lookaheadCoverage,c),i=[].concat(t.backtrack);for(i.reverse();i.length&&pe(i[0].char);)i.shift();if(i.length<e.backtrackCoverage.length)return[];var l=new w2(i,0),h=A4(e.backtrackCoverage,l),u=r.length===e.inputCoverage.length&&o.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var m=e.lookupRecords[d],p=m.lookupListIndex,g=this.getLookupByIndex(p),v=0;v<g.subtables.length;v++){var b=g.subtables[v],y=this.getLookupMethod(g,b),M=this.getSubstitutionType(g,b);if(M==="12")for(var w=0;w<r.length;w++){var x=t.get(w),k=y(x);k&&f.push(k)}}return f}function hi(t,e){var n=t.current,r=l5(n,e.coverage);if(r===-1)return null;for(var a,s=e.ligatureSets[r],c=0;c<s.length;c++){a=s[c];for(var o=0;o<a.components.length;o++){var i=t.lookahead[o],l=a.components[o];if(i!==l)break;if(o===a.components.length-1)return a}}return null}function ui(t,e){var n=l5(t,e.coverage);return n===-1?null:e.sequences[n]}u2.prototype.getDefaultScriptFeaturesIndexes=function(){for(var t=this.font.tables.gsub.scripts,e=0;e<t.length;e++){var n=t[e];if(n.tag==="DFLT")return n.script.defaultLangSys.featureIndexes}return[]};u2.prototype.getScriptFeaturesIndexes=function(t){var e=this.font.tables;if(!e.gsub)return[];if(!t)return this.getDefaultScriptFeaturesIndexes();for(var n=this.font.tables.gsub.scripts,r=0;r<n.length;r++){var a=n[r];if(a.tag===t&&a.script.defaultLangSys)return a.script.defaultLangSys.featureIndexes;var s=a.langSysRecords;if(s)for(var c=0;c<s.length;c++){var o=s[c];if(o.tag===t){var i=o.langSys;return i.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};u2.prototype.mapTagsToFeatures=function(t,e){for(var n={},r=0;r<t.length;r++){var a=t[r].tag,s=t[r].feature;n[a]=s}this.features[e].tags=n};u2.prototype.getScriptFeatures=function(t){var e=this.features[t];if(this.features.hasOwnProperty(t))return e;var n=this.getScriptFeaturesIndexes(t);if(!n)return null;var r=this.font.tables.gsub;return e=n.map(function(a){return r.features[a]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};u2.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),r=e.substFormat.toString();return n+r};u2.prototype.getLookupMethod=function(t,e){var n=this,r=this.getSubstitutionType(t,e);switch(r){case"11":return function(a){return oi.apply(n,[a,e])};case"12":return function(a){return ii.apply(n,[a,e])};case"63":return function(a){return li.apply(n,[a,e])};case"41":return function(a){return hi.apply(n,[a,e])};case"21":return function(a){return ui.apply(n,[a,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};u2.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,r=this.getFeature({tag:t.tag,script:t.script});if(!r)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var a=this.getFeatureLookups(r),s=[].concat(e.context),c=0;c<a.length;c++)for(var o=a[c],i=this.getLookupSubtables(o),l=0;l<i.length;l++){var h=i[l],u=this.getSubstitutionType(o,h),f=this.getLookupMethod(o,h),d=void 0;switch(u){case"11":d=f(e.current),d&&s.splice(n,1,new $e({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&s.splice(n,1,new $e({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&s.splice(n,1,new $e({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&s.splice(n,1,new $e({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&s.splice(n,1,new $e({id:21,tag:t.tag,substitution:d}));break}e=new w2(s,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return s.length?s:null};u2.prototype.supports=function(t){if(!t.script)return!1;this.getScriptFeatures(t.script);var e=this.features.hasOwnProperty(t.script);if(!t.tag)return e;var n=this.features[t.script].some(function(r){return r.tag===t.tag});return e&&n};u2.prototype.getLookupSubtables=function(t){return t.subtables||null};u2.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};u2.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};u2.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var n=this.features[e.script];return n?n.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function fi(t){var e=t.current,n=t.get(-1);return n===null&&me(e)||!me(n)&&me(e)}function di(t){var e=t.get(1);return e===null||!me(e)}var mi={startCheck:fi,endCheck:di};function pi(t){var e=t.current,n=t.get(-1);return(me(e)||pe(e))&&!me(n)}function gi(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!me(e)&&!pe(e)):var n=ci(e);if(!n)return!0;if(n){var r=!1;if(r=t.lookahead.some(function(a){return me(a)||pe(a)}),!r)return!0}break;default:return!1}}var vi={startCheck:pi,endCheck:gi};function bi(t,e,n){e[n].setState(t.tag,t.substitution)}function yi(t,e,n){e[n].setState(t.tag,t.substitution)}function xi(t,e,n){t.substitution.forEach(function(r,a){var s=e[n+a];s.setState(t.tag,r)})}function Mi(t,e,n){var r=e[n];r.setState(t.tag,t.substitution.ligGlyph);for(var a=t.substitution.components.length,s=0;s<a;s++)r=e[n+s+1],r.setState("deleted",!0)}var j7={11:bi,12:yi,63:xi,41:Mi};function G4(t,e,n){t instanceof $e&&j7[t.id]&&j7[t.id](t,e,n)}function wi(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],a=_8(r),s=pe(r);if(!a&&!s)return!0;if(a)return!1}return!1}function ki(t){if(_8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],r=pe(n);if(!r)return!0}return!1}function zi(t){var e=this,n="arab",r=this.featuresTags[n],a=this.tokenizer.getRangeTokens(t);if(a.length!==1){var s=new w2(a.map(function(o){return o.getState("glyphIndex")}),0),c=new w2(a.map(function(o){return o.char}),0);a.forEach(function(o,i){if(!pe(o.char)){s.setCurrentIndex(i),c.setCurrentIndex(i);var l=0;wi(c)&&(l|=1),ki(c)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(r.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:s});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof $e&&(G4(f,a,d),s.context[d]=f.substitution)})}}})}}function G7(t,e){var n=t.map(function(r){return r.activeState.value});return new w2(n,e||0)}function Si(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),a=G7(r);a.context.forEach(function(s,c){a.setCurrentIndex(c);var o=e.query.lookupFeature({tag:"rlig",script:n,contextParams:a});o.length&&(o.forEach(function(i){return G4(i,r,c)}),a=G7(r))})}function Ai(t){var e=t.current,n=t.get(-1);return n===null&&et(e)||!et(n)&&et(e)}function Li(t){var e=t.get(1);return e===null||!et(e)}var Ci={startCheck:Ai,endCheck:Li};function W7(t,e){var n=t.map(function(r){return r.activeState.value});return new w2(n,e||0)}function Pi(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),a=W7(r);a.context.forEach(function(s,c){a.setCurrentIndex(c);var o=e.query.lookupFeature({tag:"liga",script:n,contextParams:a});o.length&&(o.forEach(function(i){return G4(i,r,c)}),a=W7(r))})}function S2(t){this.baseDir=t||"ltr",this.tokenizer=new C0,this.featuresTags={}}S2.prototype.setText=function(t){this.text=t};S2.prototype.contextChecks={latinWordCheck:Ci,arabicWordCheck:mi,arabicSentenceCheck:vi};function L4(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function Ei(){return L4.call(this,"latinWord"),L4.call(this,"arabicWord"),L4.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Ti(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var r=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,r.reverse())})}S2.prototype.registerFeatures=function(t,e){var n=this,r=e.filter(function(a){return n.query.supports({script:t,tag:a})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(r):this.featuresTags[t]=r};S2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new u2(t));for(var n=0;n<e.length;n++){var r=e[n];this.query.supports({script:r.script})&&this.registerFeatures(r.script,r.tags)}};S2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function W4(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Ii(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){W4.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){zi.call(t,r)})}}function Vi(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){W4.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(a){Si.call(t,a)})}}}function $i(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){W4.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(a){Pi.call(t,a)})}}}S2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};S2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Ii.call(this),Vi.call(this)),this.checkContextReady("latinWord")&&$i.call(this),this.checkContextReady("arabicSentence")&&Ti.call(this)};S2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),Ei.call(this),this.applyFeaturesToContexts())};S2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};S2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var r=this.tokenizer.tokens[n];if(!r.state.deleted){var a=r.activeState.value;e.push(Array.isArray(a)?a[0]:a)}}return e};function p0(t){t=t||{},t.tables=t.tables||{},t.empty||(Q3(t.familyName,"When creating a new Font object, familyName is required."),Q3(t.styleName,"When creating a new Font object, styleName is required."),Q3(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),Q3(t.ascender,"When creating a new Font object, ascender is required."),Q3(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new q2.GlyphSet(this,t.glyphs||[]),this.encoding=new a8(this),this.position=new c5(this),this.substitution=new h2(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new H8(this)}})}p0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};p0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};p0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};p0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};p0.prototype.stringToGlyphs=function(t,e){var n=this,r=new S2,a=function(u){return n.charToGlyphIndex(u.char)};r.registerModifier("glyphIndex",null,a);var s=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;r.applyFeatures(this,s);for(var c=r.getTextGlyphs(t),o=c.length,i=new Array(o),l=this.glyphs.get(0),h=0;h<o;h+=1)i[h]=this.glyphs.get(c[h])||l;return i};p0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};p0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};p0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};p0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};p0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};p0.prototype.forEachGlyph=function(t,e,n,r,a,s){e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:72,a=Object.assign({},this.defaultRenderOptions,a);var c=1/this.unitsPerEm*r,o=this.stringToGlyphs(t,a),i;if(a.kerning){var l=a.script||this.position.getDefaultScriptName();i=this.position.getKerningTables(l,a.language)}for(var h=0;h<o.length;h+=1){var u=o[h];if(s.call(this,u,e,n,r,a),u.advanceWidth&&(e+=u.advanceWidth*c),a.kerning&&h<o.length-1){var f=i?this.position.getKerningValue(i,u.index,o[h+1].index):this.getKerningValue(u,o[h+1]);e+=f*c}a.letterSpacing?e+=a.letterSpacing*r:a.tracking&&(e+=a.tracking/1e3*r)}return e};p0.prototype.getPath=function(t,e,n,r,a){var s=new F0;return this.forEachGlyph(t,e,n,r,a,function(c,o,i,l){var h=c.getPath(o,i,l,a,this);s.extend(h)}),s};p0.prototype.getPaths=function(t,e,n,r,a){var s=[];return this.forEachGlyph(t,e,n,r,a,function(c,o,i,l){var h=c.getPath(o,i,l,a,this);s.push(h)}),s};p0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};p0.prototype.draw=function(t,e,n,r,a,s){this.getPath(e,n,r,a,s).draw(t)};p0.prototype.drawPoints=function(t,e,n,r,a,s){this.forEachGlyph(e,n,r,a,s,function(c,o,i,l){c.drawPoints(t,o,i,l)})};p0.prototype.drawMetrics=function(t,e,n,r,a,s){this.forEachGlyph(e,n,r,a,s,function(c,o,i,l){c.drawMetrics(t,o,i,l)})};p0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};p0.prototype.validate=function(){var t=this;function e(r,a){}function n(r){var a=t.getEnglishName(r);a&&a.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};p0.prototype.toTables=function(){return x9.fontToTable(this)};p0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};p0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),r=new Uint8Array(n),a=0;a<e.length;a++)r[a]=e[a];return n};p0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var r=this.toArrayBuffer();if(w9())if(window.URL=window.URL||window.webkitURL,window.URL){var a=new DataView(r),s=new Blob([a],{type:"font/opentype"}),c=document.createElement("a");c.href=window.URL.createObjectURL(s),c.download=t;var o=document.createEvent("MouseEvents");o.initEvent("click",!0,!1),c.dispatchEvent(o)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var i=l7(),l=k9(r);i.writeFileSync(t,l)}};p0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};p0.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};p0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function q8(t,e){var n=JSON.stringify(t),r=256;for(var a in e){var s=parseInt(a);if(!(!s||s<256)){if(JSON.stringify(e[a])===n)return s;r<=s&&(r=s+1)}}return e[r]=t,r}function Hi(t,e,n){var r=q8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:r}]}function Oi(t,e,n){var r={},a=new y1.Parser(t,e);return r.tag=a.parseTag(),r.minValue=a.parseFixed(),r.defaultValue=a.parseFixed(),r.maxValue=a.parseFixed(),a.skip("uShort",1),r.name=n[a.parseUShort()]||{},r}function Ri(t,e,n,r){for(var a=q8(e.name,r),s=[{name:"nameID_"+t,type:"USHORT",value:a},{name:"flags_"+t,type:"USHORT",value:0}],c=0;c<n.length;++c){var o=n[c].tag;s.push({name:"axis_"+t+" "+o,type:"FIXED",value:e.coordinates[o]<<16})}return s}function Fi(t,e,n,r){var a={},s=new y1.Parser(t,e);a.name=r[s.parseUShort()]||{},s.skip("uShort",1),a.coordinates={};for(var c=0;c<n.length;++c)a.coordinates[n[c].tag]=s.parseFixed();return a}function _i(t,e){var n=new l1.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:t.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:t.instances.length},{name:"instanceSize",type:"USHORT",value:4+t.axes.length*4}]);n.offsetToData=n.sizeOf();for(var r=0;r<t.axes.length;r++)n.fields=n.fields.concat(Hi(r,t.axes[r],e));for(var a=0;a<t.instances.length;a++)n.fields=n.fields.concat(Ri(a,t.instances[a],t.axes,e));return n}function qi(t,e,n){var r=new y1.Parser(t,e),a=r.parseULong();H1.argument(a===65536,"Unsupported fvar table version.");var s=r.parseOffset16();r.skip("uShort",1);for(var c=r.parseUShort(),o=r.parseUShort(),i=r.parseUShort(),l=r.parseUShort(),h=[],u=0;u<c;u++)h.push(Oi(t,e+s+u*o,n));for(var f=[],d=e+s+c*o,m=0;m<i;m++)f.push(Fi(t,d+m*l,h,n));return{axes:h,instances:f}}var Di={make:_i,parse:qi},Ni=function(){return{coverage:this.parsePointer(N.coverage),attachPoints:this.parseList(N.pointer(N.uShortList))}},Ui=function(){var t=this.parseUShort();if(H1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},Bi=function(){return this.parseList(N.pointer(Ui))},ji=function(){return{coverage:this.parsePointer(N.coverage),ligGlyphs:this.parseList(N.pointer(Bi))}},Gi=function(){return this.parseUShort(),this.parseList(N.pointer(N.coverage))};function Wi(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);H1.argument(r===1||r===1.2||r===1.3,"Unsupported GDEF table version.");var a={version:r,classDef:n.parsePointer(N.classDef),attachList:n.parsePointer(Ni),ligCaretList:n.parsePointer(ji),markAttachClassDef:n.parsePointer(N.classDef)};return r>=1.2&&(a.markGlyphSets=n.parsePointer(Gi)),a}var Xi={parse:Wi},k2=new Array(10);k2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(N.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(N.coverage),values:this.parseValueRecordList()};H1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};k2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();H1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer(N.coverage),a=this.parseUShort(),s=this.parseUShort();if(n===1)return{posFormat:n,coverage:r,valueFormat1:a,valueFormat2:s,pairSets:this.parseList(N.pointer(N.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(a),value2:this.parseValueRecord(s)}})))};if(n===2){var c=this.parsePointer(N.classDef),o=this.parsePointer(N.classDef),i=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:r,valueFormat1:a,valueFormat2:s,classDef1:c,classDef2:o,class1Count:i,class2Count:l,classRecords:this.parseList(i,N.list(l,function(){return{value1:this.parseValueRecord(a),value2:this.parseValueRecord(s)}}))}}};k2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};k2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};k2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};k2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};k2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};k2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};k2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Zi(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return H1.argument(r===1||r===1.1,"Unsupported GPOS table version "+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(k2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(k2),variations:n.parseFeatureVariationsList()}}var Yi=new Array(10);function Ki(t){return new l1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new l1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new l1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new l1.LookupList(t.lookups,Yi)}])}var Ji={parse:Zi,make:Ki};function Qi(t){var e={};t.skip("uShort");var n=t.parseUShort();H1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var r=t.parseUShort();t.skip("uShort",3);for(var a=0;a<r;a+=1){var s=t.parseUShort(),c=t.parseUShort(),o=t.parseShort();e[s+","+c]=o}return e}function el(t){var e={};t.skip("uShort");var n=t.parseULong();n>1&&console.warn("Only the first kern subtable is supported."),t.skip("uLong");var r=t.parseUShort(),a=r&255;if(t.skip("uShort"),a===0){var s=t.parseUShort();t.skip("uShort",3);for(var c=0;c<s;c+=1){var o=t.parseUShort(),i=t.parseUShort(),l=t.parseShort();e[o+","+i]=l}}return e}function tl(t,e){var n=new y1.Parser(t,e),r=n.parseUShort();if(r===0)return Qi(n);if(r===1)return el(n);throw new Error("Unsupported kern table version ("+r+").")}var nl={parse:tl};function rl(t,e,n,r){for(var a=new y1.Parser(t,e),s=r?a.parseUShort:a.parseULong,c=[],o=0;o<n+1;o+=1){var i=s.call(a);r&&(i*=2),c.push(i)}return c}var al={parse:rl};function X7(t,e){for(var n=[],r=12,a=0;a<e;a+=1){var s=y1.getTag(t,r),c=y1.getULong(t,r+4),o=y1.getULong(t,r+8),i=y1.getULong(t,r+12);n.push({tag:s,checksum:c,offset:o,length:i,compression:!1}),r+=16}return n}function sl(t,e){for(var n=[],r=44,a=0;a<e;a+=1){var s=y1.getTag(t,r),c=y1.getULong(t,r+4),o=y1.getULong(t,r+8),i=y1.getULong(t,r+12),l=void 0;o<i?l="WOFF":l=!1,n.push({tag:s,offset:c,compression:l,compressedLength:o,length:i}),r+=20}return n}function T0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),r=new Uint8Array(e.length);if(Ks(n,r),r.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var a=new DataView(r.buffer,0);return{data:a,offset:0}}else return{data:t,offset:e.offset}}function D8(t,e){e=e??{};var n,r,a=new p0({empty:!0}),s=new DataView(t,0),c,o=[],i=y1.getTag(s,0);if(i==="\0\0\0"||i==="true"||i==="typ1")a.outlinesFormat="truetype",c=y1.getUShort(s,4),o=X7(s,c);else if(i==="OTTO")a.outlinesFormat="cff",c=y1.getUShort(s,4),o=X7(s,c);else if(i==="wOFF"){var l=y1.getTag(s,4);if(l==="\0\0\0")a.outlinesFormat="truetype";else if(l==="OTTO")a.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+i);c=y1.getUShort(s,12),o=sl(s,c)}else throw new Error("Unsupported OpenType signature "+i);for(var h,u,f,d,m,p,g,v,b,y,M,w,x=0;x<c;x+=1){var k=o[x],A=void 0;switch(k.tag){case"cmap":A=T0(s,k),a.tables.cmap=r8.parse(A.data,A.offset),a.encoding=new s8(a.tables.cmap);break;case"cvt ":A=T0(s,k),w=new y1.Parser(A.data,A.offset),a.tables.cvt=w.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":A=T0(s,k),w=new y1.Parser(A.data,A.offset),a.tables.fpgm=w.parseByteList(k.length);break;case"head":A=T0(s,k),a.tables.head=p8.parse(A.data,A.offset),a.unitsPerEm=a.tables.head.unitsPerEm,n=a.tables.head.indexToLocFormat;break;case"hhea":A=T0(s,k),a.tables.hhea=g8.parse(A.data,A.offset),a.ascender=a.tables.hhea.ascender,a.descender=a.tables.hhea.descender,a.numberOfHMetrics=a.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":A=T0(s,k),r=b8.parse(A.data,A.offset);break;case"maxp":A=T0(s,k),a.tables.maxp=y8.parse(A.data,A.offset),a.numGlyphs=a.tables.maxp.numGlyphs;break;case"name":y=k;break;case"OS/2":A=T0(s,k),a.tables.os2=H4.parse(A.data,A.offset);break;case"post":A=T0(s,k),a.tables.post=S8.parse(A.data,A.offset),a.glyphNames=new D4(a.tables.post);break;case"prep":A=T0(s,k),w=new y1.Parser(A.data,A.offset),a.tables.prep=w.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":b=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":m=k;break;case"GSUB":p=k;break;case"meta":M=k;break}}var L=T0(s,y);if(a.tables.name=z8.parse(L.data,L.offset,r),a.names=a.tables.name,f&&b){var z=n===0,S=T0(s,b),C=al.parse(S.data,S.offset,a.numGlyphs,z),E=T0(s,f);a.glyphs=I8.parse(E.data,E.offset,C,a,e)}else if(h){var I=T0(s,h);m8.parse(I.data,I.offset,a,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var H=T0(s,g);if(v8.parse(a,H.data,H.offset,a.numberOfHMetrics,a.numGlyphs,a.glyphs,e),bc(a,e),v){var T=T0(s,v);a.kerningPairs=nl.parse(T.data,T.offset)}else a.kerningPairs={};if(d){var O=T0(s,d);a.tables.gdef=Xi.parse(O.data,O.offset)}if(m){var _=T0(s,m);a.tables.gpos=Ji.parse(_.data,_.offset),a.position.init()}if(p){var D=T0(s,p);a.tables.gsub=A8.parse(D.data,D.offset)}if(u){var G=T0(s,u);a.tables.fvar=Di.parse(G.data,G.offset,a.names)}if(M){var V=T0(s,M);a.tables.meta=L8.parse(V.data,V.offset),a.metas=a.tables.meta}return a}function ht(t,e){let n=t.tables?.os2?.sCapHeight;if(n&&n>0)return n/t.unitsPerEm*e;let r=m0(f3(t,"H",{size:e,font:"",halign:"left",valign:"baseline",spacing:1}).polys);return r?r[3]:t.ascender/t.unitsPerEm*e}var lt=class{constructor(e,n){this.sources=e;this.fallback=n;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let n=e||this.fallback||Object.keys(this.sources)[0];if(!n)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let r=this.parsed.get(n);if(r)return r;let a=s2(this.sources,n);if(!a)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let s=a instanceof Uint8Array?a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength):a,c=D8(s);return this.parsed.set(n,c),c}};function cl(t,e,n){let r={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,r).commands,advance:t.getAdvanceWidth(e,n.size,r)};let a=[],s=0,c=[...e];return c.forEach((o,i)=>{a.push(...t.getPath(o,s,0,n.size,r).commands),s+=t.getAdvanceWidth(o,n.size,r)*(i<c.length-1?n.spacing:1)}),{cmds:a,advance:s}}function f3(t,e,n){let{cmds:r,advance:a}=cl(t,e,n),s=r.map(o=>o.type==="Z"?o:o.type==="C"?{...o,y1:-o.y1,y2:-o.y2,y:-o.y}:o.type==="Q"?{...o,y1:-o.y1,y:-o.y}:{...o,y:-o.y}),c=t3(s,Math.max(.005,n.size/2e3));return{polys:[...c.closed,...c.open.filter(o=>o.length>=3)],advance:a}}function d3(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:a,advance:s}=f3(r,e,n),c=t1(a),o=m0(c);if(!o)return[];let i=n.halign==="center"?-s/2:n.halign==="right"?-s:0,l=n.valign==="top"?-o[3]:n.valign==="center"?-(o[1]+o[3])/2:n.valign==="bottom"?-o[1]:n.valign==="cap"?-ht(r,n.size)/2:0;return c.map(h=>h.map(([u,f])=>[u+i,f+l]))}function h5(t,e,n){let r=t.get(n.font),{polys:a,advance:s}=f3(r,e,n),c=m0(a)??[0,0,0,0];return{advance:s,bounds:[[c[0],c[1]],[c[2],c[3]]],ascent:r.ascender/r.unitsPerEm*n.size,descent:r.descender/r.unitsPerEm*n.size,cap:ht(r,n.size)}}function ol(t,e,n){let r=0;for(;r<t.length-2&&e[r+1]<n;)r++;let[a,s]=[t[r],t[r+1]],c=e[r+1]-e[r],o=(n-e[r])/c,i=[(s[0]-a[0])/c,(s[1]-a[1])/c];return{at:[a[0]+(s[0]-a[0])*o,a[1]+(s[1]-a[1])*o],t:i}}function N8(t,e,n,r){let a=r.filter(([v,b],y)=>y===0||v!==r[y-1][0]||b!==r[y-1][1]);if(!e||a.length<2)return{polys:[],over:0};let s=t.get(n.font),c={kerning:!0},o=[...e],i=[],l=0;o.forEach((v,b)=>{i.push(n.spacing===1?s.getAdvanceWidth(o.slice(0,b+1).join(""),n.size,c)-s.getAdvanceWidth(v,n.size,c):l),l+=s.getAdvanceWidth(v,n.size,c)*(b<o.length-1?n.spacing:1)});let h=n.spacing===1?s.getAdvanceWidth(e,n.size,c):l,u=m0(f3(s,e,n).polys);if(!u)return{polys:[],over:0};let f=n.valign==="top"?-u[3]:n.valign==="center"?-(u[1]+u[3])/2:n.valign==="bottom"?-u[1]:n.valign==="cap"?-ht(s,n.size)/2:0,d=[0];for(let v=1;v<a.length;v++)d.push(d[v-1]+Math.hypot(a[v][0]-a[v-1][0],a[v][1]-a[v-1][1]));let m=d[d.length-1],p=n.halign==="center"?(m-h)/2:n.halign==="right"?m-h:0,g=[];return o.forEach((v,b)=>{let y=s.getAdvanceWidth(v,n.size,c),{at:M,t:w}=ol(a,d,p+i[b]+y/2),x=[-w[1],w[0]];for(let k of f3(s,v,n).polys)g.push(k.map(([A,L])=>{let z=A-y/2,S=L+f;return[M[0]+z*w[0]+S*x[0],M[1]+z*w[1]+S*x[1]]}))}),{polys:t1(g),over:Math.max(0,-p,p+h-m)}}function U8(t){let e=Math.abs(t),n=Math.min(720,Math.max(72,Math.ceil(2*Math.PI*e/.5)));return Array.from({length:n+1},(r,a)=>{let s=t>0?1.5*Math.PI-2*Math.PI*a/n:.5*Math.PI+2*Math.PI*a/n;return[e*Math.cos(s),e*Math.sin(s)]})}function B8(t,e,n,r=0,a){if(!e)return{polys:[],loose:[]};let s=t.get(n.font),c={kerning:!0},o=[...e],i=a??Math.max(n.size*.1,1.5),l=n.size*.6,h=[],u=[],f=0,d=0,m=(L,z)=>L.map(S=>S.map(([C,E])=>[C+z,E])),p=(L,z)=>G1(L,z).length>0;o.forEach((L,z)=>{let S=n.spacing===1?s.getAdvanceWidth(o.slice(0,z+1).join(""),n.size,c)-s.getAdvanceWidth(L,n.size,c):d;if(d+=s.getAdvanceWidth(L,n.size,c)*(z<o.length-1?n.spacing:1),/\s/.test(L)){u=[];return}let C=t1(f3(s,L,n).polys);if(!C.length)return;let E=m(C,S+f);if(u.length&&!p(u,E)){let[I,H]=[0,l];if(p(u,m(E,-H))){for(let O=0;O<24;O++){let _=(I+H)/2;p(u,m(E,-_))?H=_:I=_}let T=Math.min(l,H+i);f-=T,E=m(E,-T)}}u=t1([...u,...E]),h.push({ch:L,polys:E})});let g=a0(a0(t1(h.flatMap(L=>L.polys)),.8,"round"),-.8,"round"),v=m0(g);if(!v)return{polys:[],loose:[]};r>0&&(g=t1([...g,[[v[0],-r*.6],[v[2],-r*.6],[v[2],r*.4],[v[0],r*.4]]]));let b=E0(g),y=L=>L.reduce((z,S)=>z+Math.abs(z1(S)),0),M=b.reduce((L,z)=>y(z)>y(L)?z:L,b[0]),w=b.filter(L=>L!==M).map(L=>{let z=h.find(S=>G1(S.polys,L).length);return z?z.ch:"?"}),x=m0(g),k=n.halign==="center"?-(x[0]+x[2])/2:n.halign==="right"?-x[2]:-x[0],A=n.valign==="top"?-x[3]:n.valign==="center"?-(x[1]+x[3])/2:n.valign==="bottom"?-x[1]:n.valign==="cap"?-ht(s,n.size)/2:0;return{polys:g.map(L=>L.map(([z,S])=>[z+k,S+A])),loose:w}}var j8=Math.PI/180,X4=128;function il(t,e,n){let[r,a]=[0,1],s=e[0]-t[0],c=e[1]-t[1];for(let[o,i]of[[-s,t[0]-n[0]],[s,n[2]-t[0]],[-c,t[1]-n[1]],[c,n[3]-t[1]]])if(o===0){if(i<=0)return!1}else{let l=i/o;o<0?r=Math.max(r,l):a=Math.min(a,l)}return r<a}var u5=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],Q4={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function ll(t,e){if(!t||s2(J4,t)!==void 0)return;let n=t.split("\\").join("/"),r=e.split("\\").join("/");if(r.startsWith("/")||/^[A-Za-z]:\//.test(r))return;let a=n.lastIndexOf("/");if(a<0)return;let s=[...n.slice(0,a).split("/"),...r.split("/")],c=[];for(let o of s)o===".."&&c.length&&c[c.length-1]!==".."?c.pop():o!=="."&&o!==""&&c.push(o);return(n.startsWith("/")?"/":"")+c.join("/")}var X8=new WeakSet,hl=()=>{let t=D0();return X8.add(t),t},G8=t=>!X8.has(t),ul=100,fl={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},m3=4,W8=8,dl=t=>{let e=ul,n=r=>{for(let a of r.values()){for(let s of a.regions)e+=s.length;for(let s of a.lines)e+=s.length}};n(t.layers);for(let r of t.parts)n(r.layers);return e},_0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,r=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=r?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let r=n.fns.get(e);if(r)return r}}mod(e){for(let n=this;n;n=n.parent){let r=n.mods.get(e);if(r)return r}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let r=this;r;r=r.parent)n.push(...r[e].keys());return n}},Z4=t=>t?`.${t}`:"",Y4=(t,e)=>t==="module"?`Recursion too deep in module ${e}(): check that it stops`:`Recursion too deep in ${e}(): check that it stops, or use fold(), scan() or a list comprehension to go through a long list`,ml={color:"its children are drawn as they are. Use cut(), score(), engrave() or layer() to choose how they are cut.",linear_extrude:"its children are drawn flat, as the part outline. A part takes its height from $thickness."},K4=["echo","assert","text_width","text_metrics","text_size","finger_count"];function Oe(t,e){let n="",r=Math.min(2,Math.floor(t.length/3))+.5;for(let a of new Set(e)){if(a===t)continue;let s=a.toLowerCase()===t.toLowerCase()?0:pl(t,a);s<r&&([n,r]=[a,s])}return n?` Did you mean "${n}"?`:""}function pl(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(r,a)=>[a,...Array(e.length).fill(0)]);for(let r=1;r<=e.length;r++)n[0][r]=r;for(let r=1;r<=t.length;r++)for(let a=1;a<=e.length;a++)n[r][a]=Math.min(n[r-1][a]+1,n[r][a-1]+1,n[r-1][a-1]+(t[r-1]===e[a-1]?0:1)),r>1&&a>1&&t[r-1]===e[a-2]&&t[r-2]===e[a-1]&&(n[r][a]=Math.min(n[r][a],n[r-2][a-2]+1));return n[t.length][e.length]}var J4=J3,K2=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.occluding=0;this.pointCount=0;this.itemCount=0;this.retained=0;this.copies=0;this.layerDefs=0;this.frame=a4;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.lights=[];this.echoes=[];this.warnings=[];this.layers=new Map(u5.map(e=>[e.name,e]));this.loaded=new Map;this.clashed=new Set;this.childCache=new WeakMap;this.copyReads=0;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...Q4,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new _0,r={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[o,i]of Object.entries(r))n.vars.set(o,i);let a=new _0(n),s=this.block(e.body,a,!0),c=a.vars.get("$scale");return this.unscaled&&c!==void 0&&c!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${t2(this.unscaled,!1)})`),{shape:s,globals:a,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,lights:this.lights,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new i1(`Stopped after ${this.maxSteps} steps. Is there an endless loop, or more work than one program may do (a long list, a fine spacing)?`,e)}load(e,n){let r=ll(n.file,e),a=e,s=s2(J4,e);if(s===void 0&&r!==void 0){let o=this.loaded.get(r);if(o)return o;s=this.opts.resolve?.(r),typeof s=="string"&&(a=r)}if(a===e){let o=this.loaded.get(e);if(o)return o;s??(s=this.opts.resolve?.(e))}if(typeof s!="string")throw new i1(`Library <${e}> not found`,n);this.loaded.set(a,{body:[]});let{program:c}=n2(s,a);return this.loaded.set(a,c),c}hoist(e,n){for(let r of e)if((r.kind==="module"||r.kind==="function")&&(r.pos.file===void 0||s2(J4,r.pos.file)===void 0)&&(r.kind==="module"?s2(this.builtins,r.name)!==void 0:s2(X3,r.name)!==void 0||K4.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${t2(r.pos,!1)})`),r.kind==="module")n.mods.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="function")n.fns.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="use"&&!r.include){this.enter(this.using,r.path,r.pos,"use");try{let a=this.included(this.load(r.path,r.pos).body,new Set([r.path])),s=new _0(n);this.hoist(a,s);for(let c of a)c.kind==="assign"&&this.assign(c.name,this.expr(c.value,s),s);for(let[c,o]of s.mods)this.clash("module",c,n.mods.get(c),o),n.mods.set(c,o);for(let[c,o]of s.fns)this.clash("function",c,n.fns.get(c),o),n.fns.set(c,o)}finally{this.using.pop()}}}clash(e,n,r,a){!r||r.body===a.body||!r.pos?.file||!a.pos?.file||r.pos.file===a.pos.file||this.clashed.has(`${e} ${n}`)||(this.clashed.add(`${e} ${n}`),this.warn(`${e} ${n} is defined in <${r.pos.file}> (line ${r.pos.line}) and in <${a.pos.file}> (line ${a.pos.line}); the one in <${a.pos.file}> is used. Rename one to use both.`))}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let a=[...n].sort(([l],[h])=>l<h?-1:1),s=[],c=0,o=[];for(let l=a.length-1;l>=0;l--)o.push({text:";"},a[l][1],{text:`${a[l][0]}=`});for(;o.length;){if(c>2e4)return"";let l=o.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){o.push({text:"]"});for(let u=l.length-1;u>=0;u--)o.push(l[u],{text:","});h="["}else if(p2(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(e2(l)){o.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)o.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";s.push(h),c+=h.length}let i=s.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${this.layerDefs}|${i}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.lights.length},${this.stepNames.length},${this.warnings.length},${this.copies},${this.layerDefs}`}enter(e,n,r,a){if(e.includes(n)){let s=[...e.slice(e.indexOf(n)),n].map(c=>`<${c}>`);throw new i1(s.length===2?`Library ${s[0]} ${a}s itself`:`Libraries ${a} each other in a loop: ${s.join(" \u2192 ")}`,r)}e.push(n)}included(e,n){let r=[];for(let a of e)if(a.kind!=="use"||!a.include)r.push(a);else if(!n.has(a.path)){n.add(a.path);for(let s of this.included(this.load(a.path,a.pos).body,n))r.push(s)}return r}assign(e,n,r){r.vars.set(e,n)}block(e,n,r=!1){this.hoist(e,n);let a=[];for(let s of e){let c=this.stmt(s,n,r);c&&!u6(c)&&a.push(c)}return a.length===1?a[0]:O2(a)}stmt(e,n,r=!1){switch(this.tick(e.pos),e.kind){case"assign":{let a=this.opts.overrides,s=r&&a&&Object.prototype.hasOwnProperty.call(a,e.name)?a[e.name]:this.expr(e.value,n);return this.assign(e.name,s,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new _0(n));case"if":return w0(this.expr(e.cond,n))?this.block(e.then,new _0(n)):e.else.length?this.block(e.else,new _0(n)):null;case"let":{let a=new _0(n);return this.bindSeq(e.assigns,a),this.block(e.body,a)}case"for":{let a=[];return this.loop(e.assigns,n,s=>a.push(this.block(e.body,s))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:n,children:()=>O2(a),childList:()=>a,childSeq:()=>a,childItems:()=>a}):O2(a)}case"call":if(e.modifier==="*")return null;{let a=this.callModule(e,n);return(e.name==="echo"||e.name==="assert")&&!e.children.length&&!n.mod(e.name)?null:e.modifier==="#"||e.modifier==="%"?D3(a,"guide"):a}}}bindSeq(e,n){for(let r of e)this.assign(r.name,this.expr(r.value,n),n)}iterable(e,n){if(p2(e))try{return N5(e,this.limits.maxListLength)}catch(r){throw new i1(r.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,r,a=0,s=new _0(n)){if(a===e.length)return r(s);let c=e[a];for(let o of this.iterable(this.expr(c.value,s),c.pos)){this.tick(c.pos);let i=new _0(s);i.vars.set(c.name,o),this.loop(e,n,r,a+1,i)}}evalArgs(e,n,r){let a=[],s=new Map,c=[];for(let o of e){let i=this.expr(o.value,n);o.name===null?a.push(i):s.set(o.name,i),c.push({name:o.name,value:i})}return{pos:a,named:s,all:c,at:r}}bindParams(e,n,r,a,s){let c=e.map(o=>o.name);for(let[o,i]of n.named)o.startsWith("$")&&r.vars.set(o,i);e.forEach((o,i)=>{let l;n.named.has(o.name)?l=n.named.get(o.name):i<n.pos.length?l=n.pos[i]:l=o.default?this.expr(o.default,r):void 0,r.vars.set(o.name,l)});for(let o of n.named.keys())!o.startsWith("$")&&!c.includes(o)&&this.unknownArg(s,o,n.at,c);this.checkCount(s,e.length,n)}checkArgs(e,n){let r=c3(e);if(!r)return;let a=r.params.map(s=>s.name);if(!r.anyNamed)for(let s of n.named.keys())!s.startsWith("$")&&!a.includes(s)&&this.unknownArg(`${e}()`,s,n.at,a);r.rest||this.checkCount(`${e}()`,r.params.filter(s=>!s.named).length,n)}checkCount(e,n,r){r.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${r.pos.length}; the rest are ignored (${t2(r.at,!1)})`)}unknownArg(e,n,r,a){this.warn(`${e}: unknown argument "${n}"${Z4(Oe(n,a))} (${t2(r,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let r=e.args.findIndex(c=>c.name==="name"),a=r>=0?r:e.args.findIndex(c=>c.name===null);if(a<0)throw new i1("call() needs the name of a module",e.pos);let s=this.expr(e.args[a].value,n);if(typeof s!="string")throw new i1(`call() needs a module's name as a string, got ${X0(s)}`,e.pos);if(s==="call")throw new i1("call() can't call itself",e.pos);return this.callModule({...e,name:s,args:e.args.filter((c,o)=>o!==a)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let r=this.evalArgs(e.args,n,e.pos),a=n.mod(e.name);if(a){if(++this.depth>1e3)throw new i1(Y4("module",e.name),e.pos);try{let d=new _0(a.env,n);return this.bindParams(a.params,r,d,a.env,`${e.name}()`),d.children={stmts:e.children,env:n,module:e.name,pos:e.pos},d.vars.set("$children",this.childStmts(e.children).length),this.block(a.body,d)}catch(d){throw this.inCall(d,"module",e.name,e.pos)}finally{this.depth--}}let s=s2(this.builtins,e.name),c=s2(ml,e.name);if(!s&&c)return this.warn(`${e.name}() is ignored: ${c} (${t2(e.pos,!1)})`),e.children.length?this.block(e.children,new _0(n,n)):D0();if(!s){let d=Oe(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new i1(`Unknown module ${e.name}().${d}`,e.pos)}this.checkArgs(e.name,r);let o=new _0(n,n);for(let[d,m]of r.named)d.startsWith("$")&&o.vars.set(d,m);let i=this.childStmts(e.children),l=()=>new _0(n,o),h={args:r,env:o,children:()=>e.children.length?this.block(e.children,l()):D0(),childList:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let p of e.children){let g=this.stmt(p,d);i.includes(p)&&m.push(g??hl())}return m},childItems:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let p of e.children){if(i.includes(p)&&p.kind==="for"&&!p.intersect){this.tick(p.pos),this.loop(p.assigns,d,v=>m.push(this.block(p.body,v)));continue}let g=this.stmt(p,d);i.includes(p)&&m.push(g??D0())}return m},childSeq:d=>{let m=l();this.hoist(e.children,m);let p=[];for(let g of e.children){let v=this.stmt(g,m);i.includes(g)&&(p.push(v??D0()),d(p.length-1,v??D0()))}return p}},u;try{u=s(h)}catch(d){if(d instanceof i1||d instanceof RangeError)throw d;let m=new i1(`${e.name}(): ${d.message}`,e.pos);throw m.call=e.name,m}let f=dl(u);if(e.name!=="children"&&(this.pointCount+=f),f>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new i1(f>this.limits.maxPoints?`The shapes have more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes, or a lower $fn.`:`Making the shapes took more than ${this.limits.maxPoints*10} points of work, the limit. Use fewer or simpler shapes, or a lower $fn.`,e.pos);return u}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,r,a){if(++this.depth>2e3)throw new i1(Y4("function",a),n.at);try{this.tick(n.at);let s=x2(e)?e.scope:e.env,c=new _0(s,r);return this.bindParams(e.params,n,c,s,`${a}()`),this.expr(e.body,c)}catch(s){throw this.inCall(s,"function",a,n.at)}finally{this.depth--}}inCall(e,n,r,a){return e instanceof Error&&!(e instanceof i1)&&e.message.includes("call stack")?new i1(Y4(n,r),a):(e instanceof i1&&e.addFrame(n,r,a),e)}expr(e,n){switch(e.kind){case"num":return e.unit?this.length(e,n):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{e.name==="$copy"&&this.copyReads++;let r=n.get(e.name);if(r.found)return r.value;let a=n.fn(e.name);if(a)return{type:"function",params:a.params,body:a.body,scope:a.env,name:e.name};if(e.name.startsWith("$"))return;throw new i1(`Unknown variable "${e.name}"${Z4(Oe(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let r=[];for(let a of e.items)this.listItem(a,n,r,e.pos);return this.charge(m3,e.pos),r}case"range":{let r=this.expr(e.start,n),a=this.expr(e.end,n),s=e.step?this.expr(e.step,n):1;if(typeof r!="number"||typeof a!="number"||typeof s!="number")throw new i1("Range values must be numbers",e.pos);return{type:"range",start:r,step:s,end:a}}case"unary":{let r=this.expr(e.arg,n);return e.op==="!"?!w0(r):e.op==="+"?r:this.arith("*",-1,r,e.pos)}case"binary":{if(e.op==="&&")return w0(this.expr(e.left,n))&&w0(this.expr(e.right,n));if(e.op==="||")return w0(this.expr(e.left,n))||w0(this.expr(e.right,n));let r=this.expr(e.left,n),a=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return Qe(r,a,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof r=="number"&&typeof a=="number"||typeof r=="string"&&typeof a=="string"))throw new i1(`Can't compare ${X0(r)} ${e.op} ${X0(a)}`,e.pos);return e.op==="<"?r<a:e.op==="<="?r<=a:e.op===">"?r>a:r>=a}return this.arith(e.op,r,a,e.pos)}case"ternary":return w0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let r=this.expr(e.target,n),a=this.expr(e.index,n);if(e2(r)&&typeof a=="string")return r.fields.get(a);if(typeof a!="number")throw new i1(`List index must be a number, got ${X0(a)}`,e.pos);return Array.isArray(r)?r[Math.floor(a)]:typeof r=="string"?[...r][Math.floor(a)]:p2(r)?[r.start,r.step,r.end][Math.floor(a)]:void 0}case"record":return this.record(e,n);case"member":{let r=this.expr(e.target,n);if(e2(r))return r.fields.get(e.name);let a={x:0,y:1,z:2}[e.name];return Array.isArray(r)&&a!==void 0?r[a]:p2(r)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?r.start:e.name==="step"?r.step:r.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let r=new _0(n);return this.bindSeq(e.assigns,r),this.expr(e.body,r)}case"chain":return this.expr(e.check,n),this.expr(e.body,n)}}listItem(e,n,r,a){switch(e.kind){case"item":{let s=this.expr(e.expr,n);this.grow(r,1,a),r.push(s);return}case"each":{let s=this.iterable(this.expr(e.expr,n),a);this.grow(r,s.length,a);for(let c of s)r.push(c);return}case"for":this.loop(e.assigns,n,s=>this.listItem(e.body,s,r,a));return;case"if":w0(this.expr(e.cond,n))?this.listItem(e.then,n,r,a):e.else&&this.listItem(e.else,n,r,a);return;case"let":{let s=new _0(n);this.bindSeq(e.assigns,s),this.listItem(e.body,s,r,a)}}}grow(e,n,r){if(e.length+n>this.limits.maxListLength)throw new i1(`a list of ${e.length+n} items is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n,r)}charge(e,n){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new i1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let a=e.callee.name,s=n.get(a),c=s.found&&!x2(s.value);if(!s.found||c&&this.callable(a,n)){let o=n.fn(a);if(o)return this.callFunction(o,this.evalArgs(e.args,n,e.pos),n,a);let i=this.specialFunction(a,e,n);if(i.handled)return i.value;let l=s2(X3,a);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(a,h);for(let m of Y6(l,h.pos,h.named))this.warn(`${a}(): "${m}" is given by position and by name; the named value is used (${t2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:m=>this.tick(e.pos,m),given:h.pos.length+l.params.filter(m=>h.named.has(m)).length,apply:(m,p)=>{if(!x2(m))throw new Error(`${a}() needs a function, got ${X0(m)}`);return this.callFunction(m,{pos:p,named:new Map,all:p.map(g=>({name:null,value:g})),at:e.pos},n,"function")}},f=K6(l,h.pos,h.named);this.tick(e.pos,J6(a,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof i1)throw m;let p=new i1(m instanceof RangeError?`${a}(): the result is too large`:m.message,e.pos);throw p.call=a,p}return this.checkValue(d,e.pos,a),d}throw new i1(`Unknown function ${a}()${Z4(Oe(a,[...n.names("fns"),...n.names("vars"),...Object.keys(X3),...K4]))}`,e.pos)}if(!x2(s.value))throw new i1(`"${a}" is a ${X0(s.value)}, not a function`,e.pos);return this.callFunction(s.value,this.evalArgs(e.args,n,e.pos),n,a)}let r=this.expr(e.callee,n);if(!x2(r))throw new i1(`Can't call a ${X0(r)}`,e.pos);return this.callFunction(r,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,r,a){let s=c=>Array.isArray(r)?String(r[c]??""):[...e[c].layers.keys()].sort().join(",");for(let c=1;c<e.length;c++){if(!n[c]?.length)continue;let o=s(c),i=t1(e.flatMap((h,u)=>u<c&&s(u)===o?n[u]:[]));!i.length||d0(n[c],i).reduce((h,u)=>h+Math.abs(z1(u)),0)>.001||this.warn(`paint(): child ${c+1} lies wholly on an area of the same layer${Array.isArray(r)&&o?` "${o}"`:""} under it, so it can't be seen (${t2(a,!1)})`)}}record(e,n){let r=new Map;for(let a of e.fields)r.set(a.name,this.expr(a.value,n));return{type:"record",fields:r}}length(e,n){let r=V0(n.get("$scale").value??1);if(!(r>0))throw new i1("$scale must be a number more than 0",e.pos);return r===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*fl[e.unit]/r}callable(e,n){return!!n.fn(e)||K4.includes(e)||!!s2(X3,e)}specialFunction(e,n,r){if(e==="echo"){let a=this.evalArgs(n.args,r,n.pos);return this.echo(this.echoText(a),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let a=this.evalArgs(n.args,r,n.pos);return this.checkArgs(e,a),this.assert(a),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"||e==="text_size"){let a=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,a);let s=this.measure(a,r);return e==="text_width"?{handled:!0,value:s.advance}:e==="text_size"?{handled:!0,value:{type:"record",fields:new Map([["width",s.advance],["height",s.bounds[1][1]-s.bounds[0][1]],["bounds",s.bounds],["cap",s.cap],["ascent",s.ascent],["descent",s.descent],["size",s.size]])}}:{handled:!0,value:[s.advance,s.bounds,s.ascent,s.descent]}}if(e==="finger_count"){let a=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,a);let s=this.num(this.arg(a,"length",0),"finger_count","length");return{handled:!0,value:Ee(s,this.fingerWidth(a,r,1))}}return{handled:!1}}assert(e){if(w0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new i1(`Assertion failed${n===void 0?"":": "+k0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/W8);this.charge(r,n),this.retained+=r,this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,r=[],a=0,s=(c,o,i)=>{r.length&&(a+=2);let l=e3(o,n-a-c.length,i);if(a+=c.length+l.text.length,!l.whole)throw new i1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);r.push(c+l.text)};for(let{name:c,value:o}of e.all)c===null?s("",o,!1):s(`${c} = `,o,!0);return r.join(", ")}arith(e,n,r,a){if(typeof n=="number"&&typeof r=="number")switch(e){case"+":return n+r;case"-":return n-r;case"*":return n*r;case"/":return n/r;case"%":return n%r;case"^":return Math.pow(n,r)}if(e==="+"&&typeof n=="string"&&typeof r=="string")return this.checkSize(n.length+r.length,!0,a),n+r;if(Array.isArray(n)&&Array.isArray(r)){if(e==="+"||e==="-"){if(n.length!==r.length)throw new i1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${r.length}`,a);return this.charge(n.length+m3,a),n.map((c,o)=>this.arith(e,c,r[o],a))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+m3,a),n.map(o=>this.arith("*",o,r,a));let c=(o,i)=>{let l=this.arith("*",o,i,a);if(typeof l!="number")throw new i1("Can't multiply these lists: an item times an item is not a number",a);return l};if(Array.isArray(r[0])){let o=r[0].length;if(n.length!==r.length||r.some(i=>!Array.isArray(i)||i.length!==o))throw new i1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,a);return this.checkSize(o,!1,a),this.tick(a,o*n.length),Array.from({length:o},(i,l)=>n.reduce((h,u,f)=>h+c(u,r[f][l]),0))}if(n.length!==r.length)throw new i1(`Can't multiply lists of length ${n.length} and ${r.length}`,a);return this.tick(a,n.length),n.reduce((o,i,l)=>o+c(i,r[l]),0)}}if(Array.isArray(n)&&typeof r=="number"&&(e==="*"||e==="/"))return this.charge(n.length+m3,a),n.map(c=>this.arith(e,c,r,a));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+m3,a),r.map(c=>this.arith(e,n,c,a));let s={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new i1(`Can't ${s[e]??e} ${X0(n)} and ${X0(r)}`,a)}fieldFn(e,n,r,a){if(!x2(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${c0(e)}`);return s=>{let c=this.itemCount,o=this.retained,i=this.callFunction(e,{pos:[s],named:new Map,all:[{name:null,value:s}],at:a},r,"field");return(!Array.isArray(i)||i.length<=3)&&(this.itemCount=c+this.retained-o),i}}arg(e,n,r,a){return e.named.has(n)?e.named.get(n):r>=0&&r<e.pos.length?e.pos[r]:a}num(e,n,r){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${r} must be a finite number, got ${c0(e)}`);return e}vec2(e,n,r=!0){let a=s=>typeof s=="number"&&Number.isFinite(s);if(a(e)&&r)return[e,e];if(Array.isArray(e)&&a(e[0])&&(e[1]===void 0||a(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${c0(e)}`)}vec3(e,n){let r=a=>typeof a=="number"&&Number.isFinite(a);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(r))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${c0(e)}`)}placements(e,n,r){let a=(o,i)=>o===void 0?[[0,0,0]]:Array.isArray(o)&&o.length>0&&Array.isArray(o[0])?o.map((l,h)=>this.vec3(l,`${i}[${h}]`)):[this.vec3(o,i)],s=a(e,"at"),c=a(n,"rotate");for(let[o,i]of[[s,"at"],[c,"rotate"]])if(o.length!==1&&o.length!==r)throw new Error(`${i} needs one placement per copy: qty is ${r} but ${i} has ${o.length}`);return Array.from({length:r},(o,i)=>({at:s[s.length===1?0:i],rotate:c[c.length===1?0:i]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((r,a)=>{if(!Array.isArray(r)||!Number.isFinite(r[0])||!Number.isFinite(r[1]))throw new Error(`${n}[${a}] must be an [x, y] point, got ${c0(r)}`);return[r[0],r[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,r){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,r)}checkSize(e,n,r,a){if(e>this.limits.maxListLength)throw new i1(`${a?`${a}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n?Math.ceil(e/W8):e+m3,r)}segs(e){let n=V0(this.dyn(e,"$fn"))||0,r=V0(this.dyn(e,"$fa"))||2,a=V0(this.dyn(e,"$fs"))||.2,s=this.limits.maxSegments;return c=>{let o=d6(c,n,r,a);if(!(o<=s))throw new Error(`a circle with ${o} segments is more than the limit of ${s}. Lower $fn, or raise $fa or $fs.`);return o}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||!(n>0&&Number.isFinite(n)))throw new Error(`$thickness must be a positive number, got ${c0(n)}`);return n}kerf(e){let n=this.dyn(e,"$kerf");if(n===void 0)return 0;if(typeof n!="number"||!(n>=0&&Number.isFinite(n)))throw new Error(`$kerf must be a number, 0 or more, got ${c0(n)}`);return n}fingerWidth(e,n,r){let a=this.arg(e,"finger",r);return typeof a=="number"&&a>0?a:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new i1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let r=e3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!r.whole)throw new i1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,r.text.length);try{let a=this.textOpts(e,n,r.text);return{...h5(this.opts.fonts,r.text,a),size:a.size}}catch(a){throw a instanceof i1?a:new i1(a.message,e.at)}}textOpts(e,n,r){let a={size:this.num(this.arg(e,"size",1,10),"text","size"),font:k0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:k0(this.arg(e,"halign",-1,"left")),valign:k0(this.arg(e,"valign",-1,"baseline")),spacing:V0(this.arg(e,"spacing",-1,1))},s=this.arg(e,"fit",-1);if(s!==void 0&&r!==void 0&&this.opts.fonts){let[c,o]=Array.isArray(s)?[s[0],s[1]]:[s,void 0],i=(p,g)=>{if(p===void 0)return;let v=this.num(p,"text","fit");if(!(v>0))throw new Error(`fit must be a ${g} more than 0`);return v},l=i(c,"width"),h=i(o,"height");if(Array.isArray(s)&&(s.length!==2||l===void 0&&h===void 0))throw new Error("fit must be a width, or [width, height] with either one undef");let u=h5(this.opts.fonts,r,{...a,size:1}),f=l===void 0?null:m0(d3(this.opts.fonts,r,{...a,size:1})),d=Math.max(u.advance,f?f[2]-f[0]:0),m=[...l!==void 0&&d>0?[l/d]:[],...h!==void 0&&u.cap>0?[h/u.cap]:[]];if(m.length){let p=this.arg(e,"size",1);a.size=Math.min(...m,...p===void 0?[]:[a.size])}}return a}textBlock(e,n,r,a,s){let c=this.opts.fonts,o={...r,size:1},i=new Map,l=L=>{if(!L)return 0;let z=i.get(L);if(z===void 0){let S=h5(c,L,o);z=Math.max(S.advance,S.bounds[1][0]-S.bounds[0][0]),i.set(L,z)}return z},h=n.split(`
4248
- `).map(L=>L.split(/ +/).filter(Boolean)),u=(L,z)=>{if(z<=1||L.length<=1)return[L.join(" ")];let S=L.length,C=Math.min(z,S),E=(O,_)=>l(L.slice(O,_).join(" ")),I=Array.from({length:C+1},()=>new Array(S+1).fill(1/0)),H=Array.from({length:C+1},()=>new Array(S+1).fill(S));for(let O=0;O<S;O++)I[1][O]=E(O,S);for(let O=2;O<=C;O++)for(let _=0;_<S;_++)for(let D=_+1;D<=S-O+1;D++){let G=Math.max(E(_,D),I[O-1][D]);G<I[O][_]&&([I[O][_],H[O][_]]=[G,D])}let T=[];for(let O=C,_=0;O>=1;O--){let D=O===1?S:H[O][_];T.push(L.slice(_,D).join(" ")),_=D}return T},f=L=>{let z=h.map(()=>1);for(let S=L-h.length;S>0;S--){let C=-1,E=-1;if(h.forEach((I,H)=>{if(z[H]>=I.length)return;let T=Math.max(...u(I,z[H]).map(l));T>C&&([C,E]=[T,H])}),E<0)break;z[E]++}return h.flatMap((S,C)=>u(S,z[C]))},d=h5(c,"H",o),m=s*(d.ascent-d.descent),p=this.arg(e,"size",1),g=this.arg(e,"fit",-1),[v,b]=g===void 0?[void 0,void 0]:Array.isArray(g)?[g[0],g[1]]:[g,void 0],y=L=>{if(g===void 0)return r.size;let z=[...v!==void 0?[v/Math.max(...L.map(l),1e-9)]:[],...b!==void 0?[b/(d.cap+(L.length-1)*m)]:[],...p!==void 0?[this.num(p,"text","size")]:[]];return Math.min(...z)},M=f(Math.max(a,h.length));if(g!==void 0){let L=-1;for(let z=h.length;z<=Math.max(a,h.length);z++){let S=f(z),C=y(S);C>L*(1+1e-9)&&([M,L]=[S,C])}}let w=y(M),x=[];M.forEach((L,z)=>{for(let S of d3(c,L,{...r,size:w,valign:"baseline"}))x.push(S.map(([C,E])=>[C,E-z*m*w]))});let k=m0(x);if(!k)return[];let A=r.valign==="top"?-k[3]:r.valign==="center"?-(k[1]+k[3])/2:r.valign==="bottom"?-k[1]:r.valign==="cap"?-(d.cap*w-(M.length-1)*m*w)/2:0;return A?x.map(L=>L.map(([z,S])=>[z,S+A])):x}edges(e){let n=r=>{if(r==="out"||r==="in"||r==="flat")return r;throw new Error(`edges must be "out", "in" or "flat", got ${c0(r)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,r=this.layers.get(n);if(r&&r.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!r){let a=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...a,name:n,side:"back"}),this.layerDefs++}return n}folds(e,n){if(e===void 0)return[];let r=n===void 0?1:this.num(n,"part","fold_open");if(!Number.isFinite(r))throw new Error("fold_open must be a number");let a=Array.isArray(e)&&e.length&&Array.isArray(e[0])&&Array.isArray(e[0][0])?e:[e];return a.map((s,c)=>{if(!Array.isArray(s)||s.length!==3)throw new Error(`fold${a.length>1?`[${c}]`:""} must be [from, to, angle], as [[0, 0], [0, 60], 90]`);let[o,i]=[this.vec2(s[0],"fold",!1),this.vec2(s[1],"fold",!1)],l=this.num(s[2],"part","fold");if(Math.hypot(i[0]-o[0],i[1]-o[1])<1e-6)throw new Error("a fold needs two different points");if(!(Math.abs(l)<=180))throw new Error(`a fold's angle must be from -180 to 180, got ${c0(s[2])}`);return{from:o,to:i,angle:l*r}})}bends(e){if(e===void 0||Array.isArray(e)&&!e.length)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((r,a)=>{if(!Array.isArray(r)||r.length!==3||!r.every(i=>typeof i=="number"&&Number.isFinite(i)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${c0(r)}${n.length>1?` at ${a}`:""}`);let[s,c,o]=r;if(!(c>s))throw new Error(`a bend's x1 must be more than its x0, got ${c0(r)}`);return{x0:s,x1:c,angle:o}})}makeBuiltins(){let e=(c,o)=>Se(c.children(),o),n=c=>o=>D3(o.children(),c),r=c=>o=>{let i=this.arg(o.args,"side",0,"front");if(i!=="front"&&i!=="back")throw new Error(`side must be "front" or "back", got ${c0(i)}`);return i==="back"&&o.env.vars.set("$mirrored",!w0(this.dyn(o.env,"$mirrored"))),D3(o.children(),i==="back"?this.backLayer(c):c)};return{rect:c=>{let[o,i]=this.vec2(this.arg(c.args,"size",0,1),"size"),l=V0(this.arg(c.args,"r",-1,0))||0,h=w0(this.arg(c.args,"center",1,!1)),u=m6(o,i,l,this.segs(c.env));return O0(t1([h?u.map(([f,d])=>[f-o/2,d-i/2]):u]))},square:c=>this.builtins.rect(c),circle:c=>{let o=this.arg(c.args,"d",-1),i=o!==void 0?this.num(o,"circle","d")/2:this.num(this.arg(c.args,"r",0,1),"circle","r");return O0([Ze(i,i,this.segs(c.env)(i))])},ellipse:c=>{let o=this.arg(c.args,"d",-1),[i,l]=o!==void 0?this.vec2(o,"d").map(h=>h/2):this.vec2(this.arg(c.args,"r",0,1),"r");return O0([Ze(i,l,this.segs(c.env)(Math.max(i,l)))])},regular_polygon:c=>{let o=Math.max(3,Math.floor(this.num(this.arg(c.args,"n",0,6),"regular_polygon","n"))),i=this.num(this.arg(c.args,"r",1,10),"regular_polygon","r");if(!(o<=this.limits.maxSegments))throw new Error(`${o} corners is more than the limit of ${this.limits.maxSegments}`);return O0([Ze(i,i,o)])},star:c=>{let o=Math.max(2,Math.floor(this.num(this.arg(c.args,"n",0,5),"star","n"))),i=this.num(this.arg(c.args,"r",1,10),"star","r"),l=this.num(this.arg(c.args,"inner",2,i*.45),"star","inner");if(!(o*2<=this.limits.maxSegments))throw new Error(`${o} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<o*2;u++){let f=Math.PI/2+Math.PI*u/o,d=u%2?l:i;h.push([d*Math.cos(f),d*Math.sin(f)])}return O0(t1([h]))},polygon:c=>{let o=this.points(this.arg(c.args,"points",0),"points"),i=this.arg(c.args,"paths",1),l=Array.isArray(i)?i.map(h=>(Array.isArray(h)?h:[]).map(u=>o[V0(u)]).filter(Boolean)):[o];return O0(t1(l,"evenodd"))},path:c=>{let o=this.arg(c.args,"d",0);if(typeof o!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let i=t3(n3(o),.01),l=this.arg(c.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return w0(this.arg(c.args,"close",-1,!1))?O0(t1([...i.closed,...i.open.filter(h=>h.length>2)],l)):O2([O0(t1(i.closed,l)),H2(i.open)])},line:c=>{let o=this.vec2(this.arg(c.args,"from",0,[0,0]),"from",!1),i=this.vec2(this.arg(c.args,"to",1,[10,0]),"to",!1),l=this.arg(c.args,"width",2);if(l===void 0)return H2([[o,i]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(i[0]-o[0],i[1]-o[1]);if(!u)return D0();let f=-(i[1]-o[1])/u*(h/2),d=(i[0]-o[0])/u*(h/2);return O0(t1([[[o[0]+f,o[1]+d],[o[0]-f,o[1]-d],[i[0]-f,i[1]-d],[i[0]+f,i[1]+d]]]))},polyline:c=>{let o=this.points(this.arg(c.args,"points",0),"points"),i=w0(this.arg(c.args,"closed",1,!1));return H2([i&&o.length?[...o,o[0]]:o])},arc:c=>{let o=this.num(this.arg(c.args,"r",0,10),"arc","r"),i=this.num(this.arg(c.args,"start",1,0),"arc","start"),l=this.num(this.arg(c.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(c.env)(o)*Math.abs(l-i)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(i+(l-i)*f/h)*Math.PI/180;u.push([o*Math.cos(d),o*Math.sin(d)])}return H2([u])},text:c=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let o=this.arg(c.args,"text",0,""),i=e3(o,this.limits.maxTextLength);if(!i.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(c.args.at,i.text.length);let l=this.textOpts(c.args,c.env,i.text),h=this.arg(c.args,"path",-1),u=this.arg(c.args,"arc",-1);if(h!==void 0&&u!==void 0)throw new Error("text() takes path or arc, not both");let f=this.arg(c.args,"lines",-1),d=f===void 0?1:Math.floor(this.num(f,"text","lines"));if(!(d>=1&&d<=20))throw new Error(`lines must be from 1 to 20, got ${c0(f)}`);let m=i.text.includes(`
4249
- `)||d>1;if(m&&(h!==void 0||u!==void 0))throw new Error("text() lays lines in a block, or along a path, not both");let p,g=this.num(this.arg(c.args,"line_spacing",-1,1),"text","line_spacing");if(!(g>0))throw new Error("line_spacing must be more than 0");let v=this.arg(c.args,"weld",-1,!1),b=typeof v=="number"?v>0:w0(v),y=typeof v=="number"?v:void 0,M=this.arg(c.args,"underline",-1),w=M===void 0?0:this.num(M,"text","underline");if(!(w>=0))throw new Error("underline must be a height, 0 or more");if(w>0&&!b)throw new Error("underline goes with weld = true");if(b&&(m||h!==void 0||u!==void 0))throw new Error("weld = true is for one line of text, not lines or a path");if(b){let A=B8(this.opts.fonts,i.text,l,w,y);p=A.polys,A.loose.length&&this.warn(`text(): welded, "${i.text.length>20?`${i.text.slice(0,20)}...`:i.text}" still has ${A.loose.length} loose piece${A.loose.length>1?"s":""} (${A.loose.map(L=>`in "${L}"`).join(", ")}), as an i's dot or a word apart; add underline = h or bridge = w to join ${A.loose.length>1?"them":"it"} (${t2(c.args.at,!1)})`)}else if(m)p=this.textBlock(c.args,i.text,l,d,g);else if(h!==void 0||u!==void 0){let A;if(u!==void 0){let z=this.num(u,"text","arc");if(!(z!==0&&Number.isFinite(z)))throw new Error(`arc must be a radius other than 0, got ${c0(u)}`);A=U8(z)}else if(A=this.points(h,"path"),A.length<2)throw new Error("path needs at least two points");this.arg(c.args,"halign",-1)===void 0&&(l.halign="center");let L=N8(this.opts.fonts,i.text,l,A);L.over>.01&&this.warn(`text(): "${i.text.length>20?`${i.text.slice(0,20)}...`:i.text}" is ${Math.round(L.over*10)/10} mm longer than its ${u!==void 0?"circle":"path"} allows, so it carries on past the end (${t2(c.args.at,!1)})`),p=L.polys}else p=d3(this.opts.fonts,i.text,l);let x=this.arg(c.args,"weight",-1),k=this.arg(c.args,"bridge",-1);if(x!==void 0&&x!=="regular"){let A=x==="bold"?.035*l.size:this.num(x,"text","weight");A&&(p=a0(t1(p),A,"round"))}if(k!==void 0&&(p=e4(p,this.num(k,"text","bridge"))),w0(this.dyn(c.env,"$mirrored"))){let[A,L]=[1/0,-1/0];for(let z of p)for(let[S]of z)[A,L]=[Math.min(A,S),Math.max(L,S)];return O0(t1(p.map(z=>z.map(([S,C])=>[A+L-S,C]))))}return O0(p)},translate:c=>{let[o,i]=this.vec2(this.arg(c.args,"v",0,[0,0]),"v",!1);return e(c,[1,0,0,1,o,i])},rotate:c=>{let o=this.arg(c.args,"a",0,0),l=(Array.isArray(o)?V0(o[2]??0):this.num(o,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(c.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[m,p]=this.vec2(f,"center",!1);d=[h,u,-u,h,m-h*m+u*p,p-u*m-h*p]}return e(c,d)},scale:c=>{let[o,i]=this.vec2(this.arg(c.args,"v",0,1),"v");return e(c,[o,0,0,i,0,0])},mirror:c=>{let[o,i]=this.vec2(this.arg(c.args,"v",0,[1,0]),"v",!1),l=Math.hypot(o,i)||1,h=o/l,u=i/l;return e(c,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:c=>{let o=this.arg(c.args,"m",0);if(!Array.isArray(o)||o.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let i=o[0],l=o[1];return e(c,[i[0],l[0],i[1],l[1],i[2]??0,l[2]??0])},union:c=>c.children(),group:c=>c.children(),difference:c=>{let[o,...i]=c.childList().filter(G8);if(!o)return D0();let l=a(i,"difference");return s(o,h=>({regions:d0(h.regions,l.regions),lines:N0(h.lines,t1(l.regions),"outside")}))},intersection:c=>{let o=c.childList().filter(G8);if(!o.length)return D0();let i=g=>[...g.layers.values()].some(v=>v.regions.length),l=g=>i(g)||g.parts.some(v=>[...v.layers.values()].some(b=>b.regions.length)),h=g=>[g.layers,...g.parts.map(v=>v.layers)].flatMap(v=>[...v].flatMap(([b,y])=>b===a2?[]:y.regions)),u=g=>{let v;for(let b of o){if(b===g||!l(b))continue;let y=t1(h(b));v=v?G1(v,y):y}return v},f=o[0],d=o.every(l),m=u(f),p=s(f,g=>({regions:d?m?G1(g.regions,m):g.regions:[],lines:m?N0(g.lines,m,"inside"):g.lines}));for(let g of o){if(g===f)continue;if(g.parts.length)throw new Error("part() can only be the first child of intersection()");let v=u(g),b=new Map;for(let[M,w]of g.layers)w.lines.length&&b.set(M,{regions:[],lines:v?N0(w.lines,v,"inside"):w.lines});if(!b.size)continue;let y=p.parts.length===1&&!i(f)?p.parts[0]:void 0;if(y){let M=new Map(y.layers);for(let[w,x]of b){let k=M.get(w);M.set(w,{regions:k?.regions??[],lines:[...k?.lines??[],...x.lines]})}p={layers:p.layers,parts:[{...y,layers:M}]}}else p=O2([p,{layers:b,parts:[]}])}return f.parts.forEach((g,v)=>{let b=[...g.layers.values()].some(M=>M.regions.length),y=[...p.parts[v]?.layers.values()??[]].some(M=>M.regions.length);b&&!y&&this.warn(`intersection() leaves part "${g.name}" with nothing to cut: ${d?"its other children cover none of it":"a child of lines alone leaves no area; to clip lines to the part, put the intersection() inside it"} (${t2(c.args.at,!1)})`)}),p},hull:c=>{let o=c.children(),i=l=>{let h=[],u="cut",f=!0;for(let[m,p]of l){f&&(p.regions.length||p.lines.length)&&(u=m,f=!1);for(let g of[...p.regions,...p.lines])for(let v of g)h.push(v)}let d=V5(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:i(o.layers),parts:o.parts.map(l=>({...l,layers:i(l.layers)}))}},offset:c=>{let o=this.arg(c.args,"r",0),i=this.arg(c.args,"delta",-1),l=w0(this.arg(c.args,"chamfer",-1,!1)),h=o!==void 0?this.num(o,"offset","r"):this.num(i??0,"offset","delta"),u=o!==void 0?"round":l?"square":"miter";return s(c.children(),f=>({regions:a0(f.regions,h,u),lines:f.lines}))},pattern:c=>{let[o,i]=this.vec2(this.arg(c.args,"spacing",0,10),"spacing"),l=this.num(this.arg(c.args,"stagger",1,0),"pattern","stagger");if(!(o>0&&i>0))throw new Error("spacing must be more than 0");let[h,...u]=c.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=t1(a(u,"pattern").regions),d=Q0(h.layers),m=m0(f);if(!d||!m)return D0();let p=Math.floor((m[1]-d[3])/i),g=Math.ceil((m[3]-d[1])/i),v=Math.floor((m[0]-d[2])/o)-1,b=Math.ceil((m[2]-d[0])/o)+1,y=(g-p+1)*(b-v+1);if(!(y<=this.limits.maxParts*10))throw new Error(`the pattern would have ${y} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(c.args.at,y);let M=E0(f).map(L=>({polys:L,box:m0(L)})),w=f,x=(L,z)=>{let S=0;for(let C of w)for(let E=0,I=C.length-1;E<C.length;I=E++){let[H,T]=C[I],[O,_]=C[E];T<=z?_>z&&(O-H)*(z-T)-(L-H)*(_-T)>0&&S++:_<=z&&(O-H)*(z-T)-(L-H)*(_-T)<0&&S--}return S!==0},k=new Map,A=(L,z)=>{let S=k.get(L)??{regions:[],lines:[]};for(let C of z.regions)S.regions.push(C);for(let C of z.lines)S.lines.push(C);k.set(L,S)};for(let L=p;L<=g;L++)for(let z=v;z<=b;z++){let S=z*o+(L%2?l*o:0),C=L*i,E=[d[0]+S,d[1]+C,d[2]+S,d[3]+C];if(E[2]<m[0]||E[0]>m[2]||E[3]<m[1]||E[1]>m[3])continue;let I=M.filter(D=>!(E[2]<D.box[0]||E[0]>D.box[2]||E[3]<D.box[1]||E[1]>D.box[3]));if(!I.length)continue;w=I.length===M.length?f:I.flatMap(D=>D.polys);let H=[x(E[0],E[1]),x(E[2],E[1]),x(E[2],E[3]),x(E[0],E[3])],T=w.some(D=>D.some((G,V)=>il(D[V?V-1:D.length-1],G,E))),O=H.every(Boolean)&&!T,_=[1,0,0,1,S,C];for(let[D,G]of Se({layers:h.layers,parts:[]},_).layers)A(D,O?G:{regions:G1(G.regions,w),lines:N0(G.lines,w,"inside")})}return{layers:k,parts:[]}},spline:c=>{let o=this.points(this.arg(c.args,"points",0),"points"),i=this.arg(c.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(c.args,"steps",-1,8),"spline","steps"))),h=w0(this.arg(c.args,"closed",-1,!1));if(!(o.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=f4(o,l,h);if(i===void 0)return H2([u]);let f=this.num(i,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return O0(t1(G2([u],f)))},hatch:c=>{let o=this.num(this.arg(c.args,"angle",0,45),"hatch","angle"),i=this.num(this.arg(c.args,"pitch",1,5),"hatch","pitch"),l=this.arg(c.args,"width",2);if(!(i>0))throw new Error("pitch must be more than 0");let h=t1(a([c.children()],"hatch").regions),u=m0(h);if(!u)return D0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],m=Math.hypot(u[2]-u[0],u[3]-u[1])/2+i,p=o*Math.PI/180,[g,v]=[Math.cos(p),Math.sin(p)],[b,y]=[-v,g],M=Math.ceil(m/i);if(!(2*M+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(c.args.at,2*M+1);let w=[],x=Math.round((f*b+d*y)/i);for(let A=x-M;A<=x+M;A++){let L=A*i-(f*b+d*y),[z,S]=[f+b*L,d+y*L];w.push([[z-g*m,S-v*m],[z+g*m,S+v*m]])}if(l===void 0)return H2(N0(w,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return O0(G1(t1(G2(w,k).map(A=>A)),h))},flow:c=>{let o=this.arg(c.args,"field",0),i=this.num(this.arg(c.args,"spacing",1,2),"flow","spacing");if(!(i>0))throw new Error("spacing must be more than 0");let l=this.num(this.arg(c.args,"step",2,Math.min(.5,i/4)),"flow","step");if(!(l>0&&l<=i))throw new Error("step must be more than 0 and at most the spacing");let h=this.num(this.arg(c.args,"min_length",-1,2*i),"flow","min_length"),u=this.num(this.arg(c.args,"seed",-1,1),"flow","seed"),f=t1(a([c.children()],"flow").regions),d=m0(f);if(!d)return D0();let m=b=>[Math.cos(b*j8),Math.sin(b*j8)],p;if(typeof o=="number"){let b=m(o);p=()=>b}else{let b=this.fieldFn(o,"flow",c.env,c.args.at);p=y=>{let M=b(y);if(M===void 0)return null;if(typeof M=="number"&&Number.isFinite(M))return m(M);if(Array.isArray(M)&&typeof M[0]=="number"&&typeof M[1]=="number"&&Number.isFinite(M[0])&&Number.isFinite(M[1])){let w=Math.hypot(M[0],M[1]);return w>1e-12?[M[0]/w,M[1]/w]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${c0(M)}`)}}if(!((d[2]-d[0])/i*((d[3]-d[1])/i)<=this.limits.maxPoints/10))throw new Error("spacing is too small for the area");let v=p6({spacing:i,step:l,minLength:h,seed:u,box:d,inside:b6(f),dir:p,tick:()=>this.tick(c.args.at),maxPoints:this.limits.maxPoints});return H2(N0(v,f,"inside"))},contours:c=>{let o=this.arg(c.args,"field",0),i=this.fieldFn(o,"contours",c.env,c.args.at),l=this.arg(c.args,"levels",1,10),h=this.arg(c.args,"interval",-1),u=this.num(this.arg(c.args,"cell",-1,1),"contours","cell");if(!(u>0))throw new Error("cell must be more than 0");let f=t1(a([c.children()],"contours").regions),d=m0(f);if(!d)return D0();let m=Math.ceil((d[2]-d[0])/u)+1,p=Math.ceil((d[3]-d[1])/u)+1;if(!(m*p<=this.limits.maxPoints/2))throw new Error(`a cell of ${u} samples the area at ${m*p} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let g=new Float64Array(m*p),v=1/0,b=-1/0;for(let x=0;x<p;x++)for(let k=0;k<m;k++){let A=i([d[0]+k*u,d[1]+x*u]);if(A===void 0){g[x*m+k]=NaN;continue}if(typeof A!="number"||!Number.isFinite(A))throw new Error(`field() must give a number or undef, got ${c0(A)}`);g[x*m+k]=A,v=Math.min(v,A),b=Math.max(b,A)}if(!(v<=b))return D0();let y;if(h!==void 0){let x=this.num(h,"contours","interval");if(!(x>0))throw new Error("interval must be more than 0");let k=Math.ceil(v/x),A=Math.floor(b/x);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(A))throw new Error(`the heights are too large for an interval of ${x}`);let L=Math.max(0,A-k+1);if(!(L<=1e4))throw new Error(`interval ${x} gives ${L} levels: use a larger interval`);y=Array.from({length:L},(z,S)=>(k+S)*x)}else if(Array.isArray(l))y=l.map(x=>this.num(x,"contours","levels"));else{let x=Math.floor(this.num(l,"contours","levels"));if(!(x>=1&&x<=1e4))throw new Error("levels must be 1 to 10000");y=Array.from({length:x},(k,A)=>v+(b-v)*(A+1)/(x+1))}let M=[],w=0;for(let x of y){this.tick(c.args.at,Math.ceil(m*p/100));let k=g6(g,m,p,d[0],d[1],u,x),A=k.reduce((L,z)=>L+z.length,0);if(!((w+=A)<=this.limits.maxPoints))throw new Error(`the contour lines have more than ${this.limits.maxPoints} points, the limit: use fewer levels or a larger cell`);this.spend(A);for(let L of k)M.push(L)}return H2(N0(M,f,"inside"))},occlude:c=>{let o;this.occluding++;try{o=c.childItems()}finally{this.occluding--}let i=u=>this.layers.get(u)?.mode??"cut",l=[],h=[];for(let u=o.length-1;u>=0;u--){let f=o[u];if(f.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[p,g]of f.layers){if(p===a2)continue;let v=i(p);!h.length||v==="cut"||v==="guide"?d.set(p,g):v==="line"?d.set(p,{regions:[],lines:N0([...g.lines,...t1(g.regions).map(b=>[...b,b[0]])],h,"outside")}):d.set(p,{regions:d0(g.regions,h),lines:N0(g.lines,h,"outside")})}l.push({layers:d,parts:[]});let m=[...f.layers].filter(([p])=>i(p)!=="guide").flatMap(([,p])=>p.regions);m.length&&(h=t1([...h,...m]))}return O2(l.reverse())},hide:c=>this.occluding?O0(t1(a([c.children()],"hide").regions),a2):(this.warn(`hide() only works inside occlude(); it draws nothing (${t2(c.args.at,!1)})`),D0()),paint:c=>{let o=this.arg(c.args,"layers",0);if(o!==void 0&&(!Array.isArray(o)||o.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let i=c.childList(),l=[],h=[],u=[];for(let f=i.length-1;f>=0;f--){let d=i[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let m=h,p=t1(a([d],"paint").regions);u[f]=p,h=m.length?t1([...m,...p]):p;let g=Array.isArray(o)?o[f]:void 0;if(g!=="")if(g!==void 0){this.layers.has(g)||this.layers.set(g,{name:g,mode:"fill",color:"#000000"}),this.layerDefs++,l.push(O0(m.length?d0(p,m):p,g));let v=d.layers.get(a2);v&&l.push({layers:new Map([[a2,v]]),parts:[]})}else l.push(m.length?s(d,v=>({regions:d0(v.regions,m),lines:N0(v.lines,m,"outside")})):d)}return this.invisiblePaint(i,u,o,c.args.at),O2(l.reverse())},measure:c=>{let o=w0(this.arg(c.args,"draw",0,!1)),i=c.childSeq((l,h)=>{if(l!==0)return;let u=Q0(h.layers)??m0(h.parts.flatMap(v=>[...v.layers.values()].flatMap(b=>[...b.regions,...b.lines])));c.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(v=>v.layers)],d=v=>this.layers.get(v)?.mode??(v==="cut"||v==="guide"?v:void 0),m=f.flatMap(v=>[...v].filter(([b])=>d(b)==="cut").flatMap(([,b])=>b.regions)),p=m.length?m:f.flatMap(v=>[...v].filter(([b])=>d(b)!=="guide"&&d(b)!=="paint").flatMap(([,b])=>b.regions)),g=We(t1(p));c.env.vars.set("$area",g.area),c.env.vars.set("$centroid",g.area>0?g.centroid:void 0)});return O2(o?i:i.slice(1))},fill_holes:c=>{let o=this.arg(c.args,"min_area",0),i=o===void 0?1/0:this.num(o,"fill_holes","min_area");return s(c.children(),l=>({regions:t1(l.regions).filter(h=>!(z1(h)<0&&-z1(h)<i)),lines:l.lines}))},join_islands:c=>{let o=this.num(this.arg(c.args,"width",0,1),"join_islands","width");if(!(o>0))throw new Error("join_islands(): width must be more than 0");let i=c.children(),l=h=>new Map([...h].map(([u,f])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:e4(f.regions,o),lines:f.lines}:f]));return{layers:l(i.layers),parts:i.parts.map(h=>({...h,layers:l(h.layers)}))}},largest:c=>{let o=Math.floor(this.num(this.arg(c.args,"n",0,1),"largest","n"));if(!(o>=1))throw new Error("largest(): n must be 1 or more");let i=u=>E0(u).map(f=>({g:f,a:f.reduce((d,m)=>d+z1(m),0)})).sort((f,d)=>d.a-f.a).slice(0,o).flatMap(({g:f})=>f),l=c.children(),h=u=>new Map([...u].map(([f,d])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:i(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(u=>({...u,layers:h(u.layers)}))}},close:c=>{let o=this.num(this.arg(c.args,"r",0,.5),"close","r");return s(c.children(),i=>({regions:a0(a0(i.regions,o,"round"),-o,"round"),lines:i.lines}))},stroke:c=>{let o=this.num(this.arg(c.args,"width",0,1),"stroke","width");return s(c.children(),i=>({regions:t1([...i.regions,...G2(i.lines,o)]),lines:[]}))},outline:c=>s(c.children(),o=>({regions:[],lines:[...o.lines,...t1(o.regions).map(i=>[...i,i[0]])]})),cut:n("cut"),score:r("score"),engrave:r("engrave"),guide:n("guide"),layer:c=>{let o=this.arg(c.args,"name",0);if(typeof o!="string"||!o)throw new Error("layer() needs a name");let i=this.arg(c.args,"mode",1),l=this.arg(c.args,"color",2),h=this.layers.get(o),u=this.arg(c.args,"order",-1),f=this.arg(c.args,"bleed",-1);if(i!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${o}" is the back of layer "${o.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let m=i??h?.mode??"line";if(!["cut","line","fill","guide","paint"].includes(m))throw new Error('mode must be "cut", "line", "fill", "guide" or "paint"');let p=k0(l??h?.color??"#00aa00"),g=/^#[0-9a-fA-F]{6}$/.test(p)?p:Y3(p);if(!g)throw new Error(`color must look like "#00aa00" or be a colour's name, as "red", got ${c0(p)}`);let v=u===void 0?h?.order:this.num(u,"layer","order"),b=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(b!==void 0&&!(b>=0))throw new Error("bleed must be 0 or more");if(b&&(m==="cut"||m==="paint"))throw new Error(`a ${m} layer has no bleed`);this.layerDefs++;let y={name:o,mode:m,color:g,...v!==void 0&&{order:v},...b!==void 0&&{bleed:b}};this.layers.set(o,y);let M=this.layers.get(`${o}-back`);if(M?.side==="back"){if(m==="cut")throw new Error(`layer "${o}" already has marks on the back face, so it cannot become a cut layer`);this.layers.set(M.name,{...y,name:M.name,side:"back"})}}let d=this.arg(c.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${c0(d)}`);if(d==="back"&&this.layers.get(o)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&c.env.vars.set("$mirrored",!w0(this.dyn(c.env,"$mirrored"))),D3(c.children(),d==="back"?this.backLayer(o):o)},part:c=>{let o=k0(this.arg(c.args,"name",0,"part")),i=this.arg(c.args,"qty",1,1),l=typeof i=="number"?Math.floor(i):1;if(!(l>=0))throw new Error(`qty must be 0 or more, got ${c0(i)}`);if(l===0)return{layers:new Map,parts:[]};let h=this.arg(c.args,"stack",-1),u=h===void 0?1:Math.floor(this.num(h,"part","stack"));if(!(u>=1))throw new Error("stack must be 1 or more");if(this.copies+=l*u,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let f=this.arg(c.args,"at",-1),d=this.arg(c.args,"rotate",-1),m=this.arg(c.args,"glue",-1),p=m===void 0?void 0:k0(m),g=k0(this.arg(c.args,"face",-1,"top"));if(g!=="top"&&g!=="bottom")throw new Error(`face must be "top" or "bottom", got ${c0(g)}`);let v=this.frame!==a4&&p===void 0,b=this.arg(c.args,"bend",-1),y=this.arg(c.args,"fold",-1),M=this.folds(y,this.arg(c.args,"fold_open",-1));if(M.length&&b!==void 0)throw new Error("a part bends on living hinges or folds, not both");let w=w0(this.arg(c.args,"press_fit",-1,!1));if(w&&p===void 0)throw new Error('press_fit goes with glue = "host"');let x=this.arg(c.args,"split",-1),k=x===void 0||x===!1?void 0:x===!0?!0:this.vec2(x,"split",!1);if(Array.isArray(k)&&!(k[0]>0&&k[1]>0))throw new Error("split must be true, or [width, height] more than 0");if(k&&(b!==void 0||M.length))throw new Error("a part that bends or folds cannot be split");let A=this.arg(c.args,"hang",-1),L=this.arg(c.args,"cord",-1),z=A===void 0?void 0:{at:this.vec2(A,"hang",!1),cord:L===void 0?0:this.num(L,"part","cord")};if(z&&!(z.cord>=0&&Number.isFinite(z.cord)))throw new Error(`cord must be a length, 0 or more, got ${c0(L)}`);if(L!==void 0&&!z)throw new Error("cord goes with hang = [x, y]");if(z&&(f===void 0||p!==void 0||b!==void 0||M.length))throw new Error("a hanging part needs at, the point it hangs from, and no glue, bend or fold");let S=f===void 0&&d===void 0&&!v&&p===void 0&&b===void 0&&y===void 0?void 0:this.placements(f,d,l),C=this.arg(c.args,"material",-1);C!==void 0&&c.env.vars.set("$material",k0(C));let E=this.thickness(c.env),I=this.arg(c.args,"paint",-1),H=I===void 0?void 0:Y3(k0(I));if(I!==void 0&&!H)throw new Error(`paint must look like "#c8372d" or be a colour's name, as "red", got ${c0(I)}`);let T=this.arg(c.args,"pieces",-1);if(T!==void 0&&T!=="any"&&!(typeof T=="number"&&Number.isInteger(T)&&T>=1))throw new Error(`pieces must be a whole number, 1 or more, or "any", got ${c0(T)}`);let O=T;S&&(v||u>1)&&(S=S.flatMap(Q=>{let W=p===void 0?T1(this.frame,R0(Q)):R0(Q),$1=p!==void 0&&g==="bottom"?-E:E;return Array.from({length:u},(K,k1)=>({...Q,matrix:T1(W,U0(0,0,k1*$1))}))}));let _=this.arg(c.args,"mirror",-1,!1),D;if(Array.isArray(_)){if(_.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${_.length}`);D=_.map(Q=>w0(Q))}else D=Array.from({length:l},()=>w0(_));let G=D.some(Q=>Q)&&!D.every(Q=>Q);if(G&&p!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let V=D[0],U=Q=>{let W=c.env.vars.get("$mirrored"),$1=c.env.vars.has("$mirrored");Q&&c.env.vars.set("$mirrored",!0);try{let K=c.children();return Q?Se(K,[-1,0,0,1,0,0]):K}finally{Q&&($1?c.env.vars.set("$mirrored",W):c.env.vars.delete("$mirrored"))}},J=c.env.vars.has("$copy"),n1=c.env.vars.get("$copy");c.env.vars.set("$copy",0);let m1=this.copyReads,M1,c1;try{if(M1=U(V),l>1&&this.copyReads!==m1){let Q=new Map;for(let W=0;W<l;W++){c.env.vars.set("$copy",W);let $1=W===0&&D[0]===V?M1:U(D[W]),K=`${D[W]}|${JSON.stringify([...$1.layers].map(([L1,A0])=>[L1,A0.regions.map(P=>P.map(([j,s1])=>[Math.round(j*1e4),Math.round(s1*1e4)])),A0.lines.map(P=>P.map(([j,s1])=>[Math.round(j*1e4),Math.round(s1*1e4)]))]))}`,k1=Q.get(K);k1?k1.copies.push(W+1):Q.set(K,{layers:$1.layers,flip:D[W],copies:[W+1]})}c1=[...Q.values()]}}finally{J?c.env.vars.set("$copy",n1):c.env.vars.delete("$copy")}let C1=this.bends(b),h1=this.arg(c.args,"on",-1),B1=this.arg(c.args,"slots",-1),$=B1===void 0?void 0:(Array.isArray(B1)?B1:[B1]).map(Q=>{if(typeof Q!="string")throw new Error("slots must be part names");return Q}),B=this.num(this.arg(c.args,"clearance",-1,.1),"part","clearance"),a1=this.arg(c.args,"slot_extra",-1),b1=a1===void 0?void 0:this.vec2(a1,"slot_extra",!1),o1=this.arg(c.args,"bores",-1),p1=o1===void 0?void 0:(Array.isArray(o1)?o1:[o1]).map(Q=>{if(typeof Q!="string")throw new Error("bores must be hardware labels or kinds");return Q}),K1=this.arg(c.args,"halving",-1),Q1=K1===void 0?void 0:(Array.isArray(K1)?K1:[K1]).map(Q=>{if(typeof Q!="string")throw new Error("halving must be part names");return Q}),W1=this.arg(c.args,"fit",-1,"turn");if(typeof W1!="number"&&!Object.prototype.hasOwnProperty.call(G3,k0(W1)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${c0(W1)}`);let I0=typeof W1=="number"?W1:G3[k0(W1)],q=(Q,W,$1)=>{let K=$1.length===l,k1=S?.filter((L1,A0)=>$1.includes(Math.floor(A0/u)+1));return{name:o,qty:$1.length*u,layers:Q,thickness:E,kerf:this.kerf(c.env),material:k0(this.dyn(c.env,"$material")??"material"),...H&&{paint:H},...O!==void 0&&{pieces:O},...z&&{hang:W?{...z,at:[-z.at[0],z.at[1]]}:z},...k&&{split:k},...w&&{pressFit:!0},...k1?{placements:k1}:{},...u>1?{stack:u}:{},...C1.length?{bends:W?C1.map(L1=>({...L1,mirrored:!0})):C1}:{},...M.length&&{folds:W?M.map(L1=>({...L1,from:[-L1.from[0],L1.from[1]],to:[-L1.to[0],L1.to[1]]})):M},...h1!==void 0?{on:k0(h1)}:{},...$?{slots:$,clearance:B}:{},...$&&b1?{slotExtra:b1}:{},...p1?{bores:p1,fit:I0}:{},...Q1?{halving:Q1,clearance:B}:{},...this.step?{step:this.step}:{},...p!==void 0&&{glue:{host:p,face:g}},...W&&{mirrored:!0},...!K&&{copies:$1}}},Z=Q=>D.flatMap((W,$1)=>W===Q?[$1+1]:[]),e1=c1?c1.map(Q=>q(Q.layers,Q.flip,Q.copies)):G?[q(M1.layers,V,Z(V)),q(U(!V).layers,!V,Z(!V))]:[q(M1.layers,V,Z(V))];return{layers:new Map,parts:[...M1.parts,...e1]}},place:c=>{let o=this.vec3(this.arg(c.args,"at",0,[0,0,0]),"at"),i=this.vec3(this.arg(c.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=T1(l,R0({at:o,rotate:i}));try{return c.children()}finally{this.frame=l}},step:c=>{let o=k0(this.arg(c.args,"text",0,"")),i=w0(this.arg(c.args,"substeps",1,!0));if(this.stepFolded)return c.children();let l=this.step,h=l&&o?`${this.stepNames[l-1]}: ${o}`:o,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!i;try{return c.children()}finally{this.step=l,this.stepFolded=!1}},hardware:c=>{let o=k0(this.arg(c.args,"kind",0,"dowel"));s2(X2,o)===void 0&&s2(le,o)===void 0&&this.warn(`hardware(): unknown kind "${o}"; the 3D view shows it grey (${t2(c.args.at,!1)})${Oe(o,Object.keys(X2))}`);let i=k0(this.arg(c.args,"shape",-1,"rod"));if(i!=="rod"&&i!=="ball")throw new Error(`shape must be "rod" or "ball", got ${c0(i)}`);let l=this.arg(c.args,"sides",-1),h=i==="ball"||l===0,u=this.vec3(this.arg(c.args,"from",1),"from"),f=this.arg(c.args,"to",2),d=o==="tealight",m=f!==void 0?this.vec3(f,"to"):d?[u[0],u[1],u[2]+s3.height]:h?u:this.vec3(f,"to"),p=this.arg(c.args,"size",3,d?s3.diameter:6),g=typeof p=="number"?p:this.vec2(p,"size",!1);if(h){if(typeof g!="number"||!(g>0))throw new Error("a ball's size is its diameter, a number more than 0");u=m=[(u[0]+m[0])/2,(u[1]+m[1])/2,(u[2]+m[2])/2]}let v=[m[0]-u[0],m[1]-u[1],m[2]-u[2]],b=Math.abs(v[2])>.9*Math.hypot(...v),y=this.arg(c.args,"up",-1),M=y===void 0?b?[0,1,0]:[0,0,1]:this.vec3(y,"up"),w=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(w>=3&&w<=X4))throw new Error(`sides must be from 3 to ${X4} (or 0 for a ball), got ${c0(w)}`);if(this.pointCount+=h?2*X4:w*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let x=this.arg(c.args,"label",-1),k=this.arg(c.args,"mass",-1),A=k===void 0?void 0:this.num(k,"hardware","mass");if(A!==void 0&&!(A>=0))throw new Error("mass must be grams, 0 or more");let L=this.frame,z=E=>[L[0]*E[0]+L[1]*E[1]+L[2]*E[2]+L[3],L[4]*E[0]+L[5]*E[1]+L[6]*E[2]+L[7],L[8]*E[0]+L[9]*E[1]+L[10]*E[2]+L[11]],S=E=>[L[0]*E[0]+L[1]*E[1]+L[2]*E[2],L[4]*E[0]+L[5]*E[1]+L[6]*E[2],L[8]*E[0]+L[9]*E[1]+L[10]*E[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);let C={kind:o,from:z(u),to:z(m),size:g,up:S(M),sides:w,step:this.step,...x!==void 0?{label:k0(x)}:{},...A!==void 0&&{mass:A}};return this.hardware.push(C),this.lights.push(...o7(C)),c.children()},light:c=>{let o=this.vec3(this.arg(c.args,"at",0,[0,0,0]),"at"),i=this.arg(c.args,"to",-1),l=i===void 0?o:this.vec3(i,"to"),h=k0(this.arg(c.args,"color",1,"warm white")),u=a7(h);if(!u)throw new Error(`color must look like "#ffd9a0" or be a colour's name, as "warm white" or "flame", got ${c0(h)}`);let f=this.num(this.arg(c.args,"lumens",2,20),"light","lumens");if(!(f>=0&&Number.isFinite(f)))throw new Error(`lumens must be 0 or more, got ${c0(f)}`);let d=w0(this.arg(c.args,"flicker",-1,!1)),m=this.arg(c.args,"label",-1);if(this.lights.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} lights, the limit`);let p=this.frame,g=v=>[p[0]*v[0]+p[1]*v[1]+p[2]*v[2]+p[3],p[4]*v[0]+p[5]*v[1]+p[6]*v[2]+p[7],p[8]*v[0]+p[9]*v[1]+p[10]*v[2]+p[11]];return this.lights.push({from:g(o),to:g(l),color:u,lumens:f,flicker:d,source:"light",step:this.step,...m!==void 0&&{label:k0(m)}}),c.children()},material:c=>{let o=this.arg(c.args,"thickness",0),i=this.arg(c.args,"kerf",1),l=this.arg(c.args,"name",2);return o!==void 0&&c.env.vars.set("$thickness",this.num(o,"material","thickness")),i!==void 0&&c.env.vars.set("$kerf",this.num(i,"material","kerf")),l!==void 0&&c.env.vars.set("$material",k0(l)),c.children()},children:c=>{let o=c.env.childCtx();if(!o)return D0();let i=this.childStmts(o.stmts),l=this.arg(c.args,"index",0),h=new _0(o.env,c.env);this.hoist(o.stmts,h);let u=new Set;if(l===void 0)i.forEach(p=>u.add(p));else for(let p of this.iterable(l,c.args.at)){let g=V0(p);i[g]?u.add(i[g]):i.length&&g>=i.length&&o.module&&o.pos&&this.warn(`${o.module}() uses children(${g}) but was given ${i.length} child${i.length===1?"":"ren"} (${t2(o.pos,!1)}). A module call takes one statement as its child: put several in braces, ${o.module}() { a(); b(); }`)}let f=[],d=this.childCache.get(o)??new Map;this.childCache.set(o,d);let m=this.childKey(h);for(let p of o.stmts)if(p.kind==="assign")this.stmt(p,h);else if(u.has(p)){let g=m&&d.get(p);if(g&&g.key===m){g.shape&&f.push(g.shape);continue}let v=this.effects(),b=this.stmt(p,h);b&&f.push(b),m&&this.effects()===v&&!b?.parts.length&&d.set(p,{key:m,shape:b})}return O2(f)},echo:c=>(this.echo(this.echoText(c.args),c.args.at),c.children()),assert:c=>(this.assert(c.args),c.children()),finger_rect:c=>{let[o,i]=this.vec2(this.arg(c.args,"size",0),"size"),l=this.edges(this.arg(c.args,"edges",1,"out")),h=this.thickness(c.env),u=this.fingerWidth(c.args,c.env,2);return this.spend(2*(Math.abs(o)+Math.abs(i))/u*4),O0(B5(o,i,l,h,u))},finger_holes:c=>{let o=this.num(this.arg(c.args,"length",0),"finger_holes","length"),i=this.edges(this.arg(c.args,"edge",1,"out"))[0];if(i==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(c.args,c.env,2);return this.spend(Math.abs(o)/l*4),O0(e7(o,i,this.thickness(c.env),l))},tslot:c=>{let o=this.num(this.arg(c.args,"d",0,3),"tslot","d"),i=this.num(this.arg(c.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(c.args,"nut",2,[o*1.85,o*.8]),"nut",!1),u=this.num(this.arg(c.args,"nut_at",3,i/2),"tslot","nut_at");return O0(t1(t7(o,i,l,h,u)))},living_hinge:c=>{let[o,i]=this.vec2(this.arg(c.args,"size",0),"size"),l=this.num(this.arg(c.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(c.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(c.args,"cut",3,Math.max(h*2,(i-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||u<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(o)/l+1)*(Math.abs(i)/(u+h)+2)*2),H2(n7(o,i,l,h,u))}};function a(c,o){let i={regions:[],lines:[]};for(let l of c){if(l.parts.length)throw new Error(`part() can only be the first child of ${o}()`);for(let[h,u]of l.layers)if(h!==a2)for(let f of u.regions)i.regions.push(f)}return i}function s(c,o){let i=l=>{let h=new Map;for(let[u,f]of l)h.set(u,o(f));return h};return{layers:i(c.layers),parts:c.parts.map(l=>({...l,layers:i(l.layers)}))}}}};var p3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},en=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/"/g,"&quot;");function tn(t,e){let n=[];for(let[r,a]of t){let s=[p3(r),p3(a)],c=n[n.length-1];(!c||c[0]!==s[0]||c[1]!==s[1])&&n.push(s)}for(;e&&n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n}var g3=(t,e)=>`M${tn(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function ut(t,e){let n=[];for(let r of e){let a=[],s=[];for(let o of t){let i=o.layers.get(r.name);if(i){for(let l of i.lines)a.push(g3(l,!1));for(let l of i.regions)s.push(l)}}let c=q3(s).map(o=>g3(s[o],!0));(a.length||c.length)&&n.push({name:r.name,mode:r.mode,color:r.color,d:[...a,...c].join(""),regions:c.join(""),lines:a.join("")})}return n}function ft(t,e,n,r){let a=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${p3(e)}mm" height="${p3(n)}mm" viewBox="0 0 ${p3(e)} ${p3(n)}">`];for(let s of r){let c=[],o=[],i=[];for(let h of t){let u=h.layers.get(s.name);if(!u)continue;let f=` data-part="${en(h.part)}"`;if(s.mode==="fill"){u.regions.length&&o.push(`<path${f} d="${u.regions.map(d=>g3(d,!0)).join("")}"/>`);for(let d of u.lines)o.push(`<path${f} fill="none" stroke="${s.color}" stroke-width="0.1" d="${g3(d,!1)}"/>`);continue}for(let d of u.lines)c.push(`<path${f} d="${g3(d,!1)}"/>`);for(let d of u.regions)i.push([d,f])}for(let h of q3(i.map(([u])=>u)))c.push(`<path${i[h][1]} d="${g3(i[h][0],!0)}"/>`);if(!c.length&&!o.length)continue;let l=s.mode==="fill"?`fill="${s.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${s.color}" stroke-width="0.1"${s.mode==="guide"?' stroke-dasharray="1 1"':""}`;a.push(`<g id="${en(s.name)}" inkscape:groupmode="layer" inkscape:label="${en(s.name)}" data-mode="${s.mode}" ${l}>`,...c,...o,"</g>")}return a.push("</svg>",""),a.join(`
4250
- `)}var gl={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},vl=t=>{let e=gl[t.toLowerCase()];if(e)return e;let[n,r,a]=[1,3,5].map(s=>parseInt(t.slice(s,s+2),16));return n>r&&n>a?1:r>n&&r>a?3:a>n&&a>r?5:7};function bl(t){let e=o=>o.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(u5.map(o=>o.name)),r=new Set(t.map(o=>e(o.name))),a=new Set,s=new Map,c=[...t.filter(o=>n.has(o.name)),...t.filter(o=>!n.has(o.name))];for(let o of c){let i=e(o.name);if(a.has(i)){let l=2;for(;r.has(`${i}_${l}`)||a.has(`${i}_${l}`);)l++;i=`${i}_${l}`}a.add(i),s.set(o.name,i)}return s}function nn(t,e,n,r){let a=[],s=(i,l)=>a.push(String(i),String(l)),c=bl(r);s(0,"SECTION"),s(2,"HEADER"),s(9,"$ACADVER"),s(1,"AC1009"),s(9,"$INSUNITS"),s(70,4),s(0,"ENDSEC"),s(0,"SECTION"),s(2,"TABLES"),s(0,"TABLE"),s(2,"LAYER"),s(70,r.length);for(let i of r)s(0,"LAYER"),s(2,c.get(i.name)),s(70,0),s(62,vl(i.color)),s(6,"CONTINUOUS");s(0,"ENDTAB"),s(0,"ENDSEC"),s(0,"SECTION"),s(2,"ENTITIES");let o=(i,l,h)=>{s(0,"POLYLINE"),s(8,i),s(66,1),s(10,0),s(20,0),s(30,0),s(70,h?1:0);for(let[u,f]of tn(l.map(([d,m])=>[d,n-m]),h))s(0,"VERTEX"),s(8,i),s(10,u),s(20,f),s(30,0);s(0,"SEQEND"),s(8,i)};for(let i of r){let l=c.get(i.name),h=[];for(let u of t){let f=u.layers.get(i.name);if(f){for(let d of f.lines)o(l,d,!1);for(let d of f.regions)h.push(d)}}for(let u of q3(h))o(l,h[u],!0)}return s(0,"ENDSEC"),s(0,"EOF"),a.join(`
4250
+ `};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},r=Object.defineProperty,a=r(n,n,n)&&r}catch{}return a})(),e=function(n){if(this==null)throw TypeError();var r=String(this),a=r.length,s=n?Number(n):0;if(s!=s&&(s=0),!(s<0||s>=a)){var c=r.charCodeAt(s),o;return c>=55296&&c<=56319&&a>s+1&&(o=r.charCodeAt(s+1),o>=56320&&o<=57343)?(c-55296)*1024+o-56320+65536:c}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var F4=0,Z7=-3;function n5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function Bs(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new n5,this.dtree=new n5}var Y7=new n5,K7=new n5,_4=new Uint8Array(30),q4=new Uint16Array(30),J7=new Uint8Array(30),Q7=new Uint16Array(30),js=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h7=new n5,R2=new Uint8Array(320);function e8(t,e,n,r){var a,s;for(a=0;a<n;++a)t[a]=0;for(a=0;a<30-n;++a)t[a+n]=a/n|0;for(s=r,a=0;a<30;++a)e[a]=s,s+=1<<t[a]}function Gs(t,e){var n;for(n=0;n<7;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;n<24;++n)t.trans[n]=256+n;for(n=0;n<144;++n)t.trans[24+n]=n;for(n=0;n<8;++n)t.trans[168+n]=280+n;for(n=0;n<112;++n)t.trans[176+n]=144+n;for(n=0;n<5;++n)e.table[n]=0;for(e.table[5]=32,n=0;n<32;++n)e.trans[n]=n}var u7=new Uint16Array(16);function x4(t,e,n,r){var a,s;for(a=0;a<16;++a)t.table[a]=0;for(a=0;a<r;++a)t.table[e[n+a]]++;for(t.table[0]=0,s=0,a=0;a<16;++a)u7[a]=s,s+=t.table[a];for(a=0;a<r;++a)e[n+a]&&(t.trans[u7[e[n+a]]++]=a)}function Ws(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function F2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var r=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,r+n}function P4(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,r=0,a=0,s=t.tag;do r=2*r+(s&1),s>>>=1,++a,n+=e.table[a],r-=e.table[a];while(r>=0);return t.tag=s,t.bitcount-=a,e.trans[n+r]}function Xs(t,e,n){var r,a,s,c,o,i;for(r=F2(t,5,257),a=F2(t,5,1),s=F2(t,4,4),c=0;c<19;++c)R2[c]=0;for(c=0;c<s;++c){var l=F2(t,3,0);R2[js[c]]=l}for(x4(h7,R2,0,19),o=0;o<r+a;){var h=P4(t,h7);switch(h){case 16:var u=R2[o-1];for(i=F2(t,2,3);i;--i)R2[o++]=u;break;case 17:for(i=F2(t,3,3);i;--i)R2[o++]=0;break;case 18:for(i=F2(t,7,11);i;--i)R2[o++]=0;break;default:R2[o++]=h;break}}x4(e,R2,0,r),x4(n,R2,r,a)}function f7(t,e,n){for(;;){var r=P4(t,e);if(r===256)return F4;if(r<256)t.dest[t.destLen++]=r;else{var a,s,c,o;for(r-=257,a=F2(t,_4[r],q4[r]),s=P4(t,n),c=t.destLen-F2(t,J7[s],Q7[s]),o=c;o<c+a;++o)t.dest[t.destLen++]=t.dest[o]}}}function Zs(t){for(var e,n,r;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return Z7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,F4}function Ys(t,e){var n=new Bs(t,e),r,a,s;do{switch(r=Ws(n),a=F2(n,2,0),a){case 0:s=Zs(n);break;case 1:s=f7(n,Y7,K7);break;case 2:Xs(n,n.ltree,n.dtree),s=f7(n,n.ltree,n.dtree);break;default:s=Z7}if(s!==F4)throw new Error("Data error")}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}Gs(Y7,K7);e8(_4,q4,4,3);e8(J7,Q7,2,1);_4[28]=0;q4[28]=258;var Ks=Ys;function o3(t,e,n,r,a){return Math.pow(1-a,3)*t+3*Math.pow(1-a,2)*a*e+3*(1-a)*Math.pow(a,2)*n+Math.pow(a,3)*r}function ge(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}ge.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};ge.prototype.addPoint=function(t,e){typeof t=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};ge.prototype.addX=function(t){this.addPoint(t,null)};ge.prototype.addY=function(t){this.addPoint(null,t)};ge.prototype.addBezier=function(t,e,n,r,a,s,c,o){var i=[t,e],l=[n,r],h=[a,s],u=[c,o];this.addPoint(t,e),this.addPoint(c,o);for(var f=0;f<=1;f++){var d=6*i[f]-12*l[f]+6*h[f],m=-3*i[f]+9*l[f]-9*h[f]+3*u[f],g=3*l[f]-3*i[f];if(m===0){if(d===0)continue;var p=-g/d;0<p&&p<1&&(f===0&&this.addX(o3(i[f],l[f],h[f],u[f],p)),f===1&&this.addY(o3(i[f],l[f],h[f],u[f],p)));continue}var v=Math.pow(d,2)-4*g*m;if(!(v<0)){var b=(-d+Math.sqrt(v))/(2*m);0<b&&b<1&&(f===0&&this.addX(o3(i[f],l[f],h[f],u[f],b)),f===1&&this.addY(o3(i[f],l[f],h[f],u[f],b)));var y=(-d-Math.sqrt(v))/(2*m);0<y&&y<1&&(f===0&&this.addX(o3(i[f],l[f],h[f],u[f],y)),f===1&&this.addY(o3(i[f],l[f],h[f],u[f],y)))}}};ge.prototype.addQuad=function(t,e,n,r,a,s){var c=t+.6666666666666666*(n-t),o=e+2/3*(r-e),i=c+1/3*(a-t),l=o+1/3*(s-e);this.addBezier(t,e,c,o,i,l,a,s)};function F0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}F0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};F0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};F0.prototype.curveTo=F0.prototype.bezierCurveTo=function(t,e,n,r,a,s){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:r,x:a,y:s})};F0.prototype.quadTo=F0.prototype.quadraticCurveTo=function(t,e,n,r){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:r})};F0.prototype.close=F0.prototype.closePath=function(){this.commands.push({type:"Z"})};F0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof ge){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};F0.prototype.getBoundingBox=function(){for(var t=new ge,e=0,n=0,r=0,a=0,s=0;s<this.commands.length;s++){var c=this.commands[s];switch(c.type){case"M":t.addPoint(c.x,c.y),e=r=c.x,n=a=c.y;break;case"L":t.addPoint(c.x,c.y),r=c.x,a=c.y;break;case"Q":t.addQuad(r,a,c.x1,c.y1,c.x,c.y),r=c.x,a=c.y;break;case"C":t.addBezier(r,a,c.x1,c.y1,c.x2,c.y2,c.x,c.y),r=c.x,a=c.y;break;case"Z":r=e,a=n;break;default:throw new Error("Unexpected path command "+c.type)}}return t.isEmpty()&&t.addPoint(0,0),t};F0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};F0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(c){return Math.round(c)===c?""+Math.round(c):c.toFixed(t)}function n(){for(var c=arguments,o="",i=0;i<arguments.length;i+=1){var l=c[i];l>=0&&i>0&&(o+=" "),o+=e(l)}return o}for(var r="",a=0;a<this.commands.length;a+=1){var s=this.commands[a];s.type==="M"?r+="M"+n(s.x,s.y):s.type==="L"?r+="L"+n(s.x,s.y):s.type==="C"?r+="C"+n(s.x1,s.y1,s.x2,s.y2,s.x,s.y):s.type==="Q"?r+="Q"+n(s.x1,s.y1,s.x,s.y):s.type==="Z"&&(r+="Z")}return r};F0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};F0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function t8(t){throw new Error(t)}function d7(t,e){t||t8(e)}var H1={fail:t8,argument:d7,assert:d7},m7=32768,p7=2147483648,l3={},r1={},_1={};function z2(t){return function(){return t}}r1.BYTE=function(t){return H1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};_1.BYTE=z2(1);r1.CHAR=function(t){return[t.charCodeAt(0)]};_1.CHAR=z2(1);r1.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};_1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};r1.USHORT=function(t){return[t>>8&255,t&255]};_1.USHORT=z2(2);r1.SHORT=function(t){return t>=m7&&(t=-(2*m7-t)),[t>>8&255,t&255]};_1.SHORT=z2(2);r1.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};_1.UINT24=z2(3);r1.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};_1.ULONG=z2(4);r1.LONG=function(t){return t>=p7&&(t=-(2*p7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};_1.LONG=z2(4);r1.FIXED=r1.ULONG;_1.FIXED=_1.ULONG;r1.FWORD=r1.SHORT;_1.FWORD=_1.SHORT;r1.UFWORD=r1.USHORT;_1.UFWORD=_1.USHORT;r1.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};_1.LONGDATETIME=z2(8);r1.TAG=function(t){return H1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};_1.TAG=z2(4);r1.Card8=r1.BYTE;_1.Card8=_1.BYTE;r1.Card16=r1.USHORT;_1.Card16=_1.USHORT;r1.OffSize=r1.BYTE;_1.OffSize=_1.BYTE;r1.SID=r1.USHORT;_1.SID=_1.USHORT;r1.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?r1.NUMBER16(t):r1.NUMBER32(t)};_1.NUMBER=function(t){return r1.NUMBER(t).length};r1.NUMBER16=function(t){return[28,t>>8&255,t&255]};_1.NUMBER16=z2(3);r1.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};_1.NUMBER32=z2(5);r1.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var r=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*r)/r).toString()}for(var a="",s=0,c=e.length;s<c;s+=1){var o=e[s];o==="e"?a+=e[++s]==="-"?"c":"b":o==="."?a+="a":o==="-"?a+="e":a+=o}a+=a.length&1?"f":"ff";for(var i=[30],l=0,h=a.length;l<h;l+=2)i.push(parseInt(a.substr(l,2),16));return i};_1.REAL=function(t){return r1.REAL(t).length};r1.NAME=r1.CHARARRAY;_1.NAME=_1.CHARARRAY;r1.STRING=r1.CHARARRAY;_1.STRING=_1.CHARARRAY;l3.UTF8=function(t,e,n){for(var r=[],a=n,s=0;s<a;s++,e+=1)r[s]=t.getUint8(e);return String.fromCharCode.apply(null,r)};l3.UTF16=function(t,e,n){for(var r=[],a=n/2,s=0;s<a;s++,e+=2)r[s]=t.getUint16(e);return String.fromCharCode.apply(null,r)};r1.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var r=t.charCodeAt(n);e[e.length]=r>>8&255,e[e.length]=r&255}return e};_1.UTF16=function(t){return t.length*2};var E4={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};l3.MACSTRING=function(t,e,n,r){var a=E4[r];if(a!==void 0){for(var s="",c=0;c<n;c++){var o=t.getUint8(e+c);o<=127?s+=String.fromCharCode(o):s+=a[o&127]}return s}};var Z5=typeof WeakMap=="function"&&new WeakMap,Y5,Js=function(t){if(!Y5){Y5={};for(var e in E4)Y5[e]=new String(e)}var n=Y5[t];if(n!==void 0){if(Z5){var r=Z5.get(n);if(r!==void 0)return r}var a=E4[t];if(a!==void 0){for(var s={},c=0;c<a.length;c++)s[a.charCodeAt(c)]=c+128;return Z5&&Z5.set(n,s),s}}};r1.MACSTRING=function(t,e){var n=Js(e);if(n!==void 0){for(var r=[],a=0;a<t.length;a++){var s=t.charCodeAt(a);if(s>=128&&(s=n[s],s===void 0))return;r[a]=s}return r}};_1.MACSTRING=function(t,e){var n=r1.MACSTRING(t,e);return n!==void 0?n.length:0};function T4(t){return t>=-128&&t<=127}function Qs(t,e,n){for(var r=0,a=t.length;e<a&&r<64&&t[e]===0;)++e,++r;return n.push(128|r-1),e}function ec(t,e,n){for(var r=0,a=t.length,s=e;s<a&&r<64;){var c=t[s];if(!T4(c)||c===0&&s+1<a&&t[s+1]===0)break;++s,++r}n.push(r-1);for(var o=e;o<s;++o)n.push(t[o]+256&255);return s}function tc(t,e,n){for(var r=0,a=t.length,s=e;s<a&&r<64;){var c=t[s];if(c===0||T4(c)&&s+1<a&&T4(t[s+1]))break;++s,++r}n.push(64|r-1);for(var o=e;o<s;++o){var i=t[o];n.push(i+65536>>8&255,i+256&255)}return s}r1.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var r=t[e];r===0?e=Qs(t,e,n):r>=-128&&r<=127?e=ec(t,e,n):e=tc(t,e,n)}return n};r1.INDEX=function(t){for(var e=1,n=[e],r=[],a=0;a<t.length;a+=1){var s=r1.OBJECT(t[a]);Array.prototype.push.apply(r,s),e+=s.length,n.push(e)}if(r.length===0)return[0,0];for(var c=[],o=1+Math.floor(Math.log(e)/Math.log(2))/8|0,i=[void 0,r1.BYTE,r1.USHORT,r1.UINT24,r1.ULONG][o],l=0;l<n.length;l+=1){var h=i(n[l]);Array.prototype.push.apply(c,h)}return Array.prototype.concat(r1.Card16(t.length),r1.OffSize(o),c,r)};_1.INDEX=function(t){return r1.INDEX(t).length};r1.DICT=function(t){for(var e=[],n=Object.keys(t),r=n.length,a=0;a<r;a+=1){var s=parseInt(n[a],0),c=t[s];e=e.concat(r1.OPERAND(c.value,c.type)),e=e.concat(r1.OPERATOR(s))}return e};_1.DICT=function(t){return r1.DICT(t).length};r1.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};r1.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r+=1)H1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(r1.OPERAND(t[r],e[r]));else if(e==="SID")n=n.concat(r1.NUMBER(t));else if(e==="offset")n=n.concat(r1.NUMBER32(t));else if(e==="number")n=n.concat(r1.NUMBER(t));else if(e==="real")n=n.concat(r1.REAL(t));else throw new Error("Unknown operand type "+e);return n};r1.OP=r1.BYTE;_1.OP=_1.BYTE;var K5=typeof WeakMap=="function"&&new WeakMap;r1.CHARSTRING=function(t){if(K5){var e=K5.get(t);if(e!==void 0)return e}for(var n=[],r=t.length,a=0;a<r;a+=1){var s=t[a];n=n.concat(r1[s.type](s.value))}return K5&&K5.set(t,n),n};_1.CHARSTRING=function(t){return r1.CHARSTRING(t).length};r1.OBJECT=function(t){var e=r1[t.type];return H1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};_1.OBJECT=function(t){var e=_1[t.type];return H1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};r1.TABLE=function(t){for(var e=[],n=t.fields.length,r=[],a=[],s=0;s<n;s+=1){var c=t.fields[s],o=r1[c.type];H1.argument(o!==void 0,"No encoding function for field type "+c.type+" ("+c.name+")");var i=t[c.name];i===void 0&&(i=c.value);var l=o(i);c.type==="TABLE"?(a.push(e.length),e=e.concat([0,0]),r.push(l)):e=e.concat(l)}for(var h=0;h<r.length;h+=1){var u=a[h],f=e.length;H1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(r[h])}return e};_1.TABLE=function(t){for(var e=0,n=t.fields.length,r=0;r<n;r+=1){var a=t.fields[r],s=_1[a.type];H1.argument(s!==void 0,"No sizeOf function for field type "+a.type+" ("+a.name+")");var c=t[a.name];c===void 0&&(c=a.value),e+=s(c),a.type==="TABLE"&&(e+=2)}return e};r1.RECORD=r1.TABLE;_1.RECORD=_1.TABLE;r1.LITERAL=function(t){return t};_1.LITERAL=function(t){return t.length};function j0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var r=0;r<e.length;r+=1){var a=e[r];this[a.name]=a.value}if(this.tableName=t,this.fields=e,n)for(var s=Object.keys(n),c=0;c<s.length;c+=1){var o=s[c],i=n[o];this[o]!==void 0&&(this[o]=i)}}j0.prototype.encode=function(){return r1.TABLE(this)};j0.prototype.sizeOf=function(){return _1.TABLE(this)};function r5(t,e,n){n===void 0&&(n=e.length);var r=new Array(e.length+1);r[0]={name:t+"Count",type:"USHORT",value:n};for(var a=0;a<e.length;a++)r[a+1]={name:t+a,type:"USHORT",value:e[a]};return r}function I4(t,e,n){var r=e.length,a=new Array(r+1);a[0]={name:t+"Count",type:"USHORT",value:r};for(var s=0;s<r;s++)a[s+1]={name:t+s,type:"TABLE",value:n(e[s],s)};return a}function a5(t,e,n){var r=e.length,a=[];a[0]={name:t+"Count",type:"USHORT",value:r};for(var s=0;s<r;s++)a=a.concat(n(e[s],s));return a}function nt(t){t.format===1?j0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(r5("glyph",t.glyphs))):t.format===2?j0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(a5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):H1.assert(!1,"Coverage format must be 1 or 2.")}nt.prototype=Object.create(j0.prototype);nt.prototype.constructor=nt;function rt(t){j0.call(this,"scriptListTable",a5("scriptRecord",t,function(e,n){var r=e.script,a=r.defaultLangSys;return H1.assert(!!a,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new j0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new j0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:a.reqFeatureIndex}].concat(r5("featureIndex",a.featureIndexes)))}].concat(a5("langSys",r.langSysRecords,function(s,c){var o=s.langSys;return[{name:"langSysTag"+c,type:"TAG",value:s.tag},{name:"langSys"+c,type:"TABLE",value:new j0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:o.reqFeatureIndex}].concat(r5("featureIndex",o.featureIndexes)))}]})))}]}))}rt.prototype=Object.create(j0.prototype);rt.prototype.constructor=rt;function at(t){j0.call(this,"featureListTable",a5("featureRecord",t,function(e,n){var r=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new j0("featureTable",[{name:"featureParams",type:"USHORT",value:r.featureParams}].concat(r5("lookupListIndex",r.lookupListIndexes)))}]}))}at.prototype=Object.create(j0.prototype);at.prototype.constructor=at;function st(t,e){j0.call(this,"lookupListTable",I4("lookup",t,function(n){var r=e[n.lookupType];return H1.assert(!!r,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new j0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(I4("subtable",n.subtables,r)))}))}st.prototype=Object.create(j0.prototype);st.prototype.constructor=st;var l1={Table:j0,Record:j0,Coverage:nt,ScriptList:rt,FeatureList:at,LookupList:st,ushortList:r5,tableList:I4,recordList:a5};function g7(t,e){return t.getUint8(e)}function ct(t,e){return t.getUint16(e,!1)}function nc(t,e){return t.getInt16(e,!1)}function D4(t,e){return t.getUint32(e,!1)}function n8(t,e){var n=t.getInt16(e,!1),r=t.getUint16(e+2,!1);return n+r/65535}function rc(t,e){for(var n="",r=e;r<e+4;r+=1)n+=String.fromCharCode(t.getInt8(r));return n}function ac(t,e,n){for(var r=0,a=0;a<n;a+=1)r<<=8,r+=t.getUint8(e+a);return r}function sc(t,e,n){for(var r=[],a=e;a<n;a+=1)r.push(t.getUint8(a));return r}function cc(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var oc={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function N(t,e){this.data=t,this.offset=e,this.relativeOffset=0}N.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};N.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};N.prototype.parseCard8=N.prototype.parseByte;N.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};N.prototype.parseCard16=N.prototype.parseUShort;N.prototype.parseSID=N.prototype.parseUShort;N.prototype.parseOffset16=N.prototype.parseUShort;N.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};N.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};N.prototype.parseULong=function(){var t=D4(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseOffset32=N.prototype.parseULong;N.prototype.parseFixed=function(){var t=n8(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,r="";this.relativeOffset+=t;for(var a=0;a<t;a++)r+=String.fromCharCode(e.getUint8(n+a));return r};N.prototype.parseTag=function(){return this.parseString(4)};N.prototype.parseLongDateTime=function(){var t=D4(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};N.prototype.parseVersion=function(t){var e=ct(this.data,this.offset+this.relativeOffset),n=ct(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};N.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=oc[t]*e};N.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getUint32(r),r+=4;return this.relativeOffset+=t*4,e};N.prototype.parseOffset16List=N.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getUint16(r),r+=2;return this.relativeOffset+=t*2,e};N.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getInt16(r),r+=2;return this.relativeOffset+=t*2,e};N.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,a=0;a<t;a++)e[a]=n.getUint8(r++);return this.relativeOffset+=t,e};N.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};N.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};N.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=Object.keys(e),a=0;a<t;a++){for(var s={},c=0;c<r.length;c++){var o=r[c],i=e[o];s[o]=i.call(this)}n[a]=s}return n};N.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=Object.keys(e),a=0;a<t;a++){for(var s={},c=0;c<r.length;c++){var o=r[c],i=e[o];s[o]=i.call(this)}n[a]=s}return n};N.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},r=0;r<e.length;r++){var a=e[r],s=t[a];n[a]=s.call(this)}return n};N.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};N.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),r=0;r<e;r++)n[r]=this.parseValueRecord(t);return n};N.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new N(this.data,this.offset+e).parseStruct(t)};N.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new N(this.data,this.offset+e).parseStruct(t)};N.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,r=this.relativeOffset,a=new Array(n),s=0;s<n;s++){var c=e[s];if(c===0){a[s]=void 0;continue}if(this.relativeOffset=c,t){for(var o=this.parseOffset16List(),i=new Array(o.length),l=0;l<o.length;l++)this.relativeOffset=c+o[l],i[l]=t.call(this);a[s]=i}else a[s]=this.parseUShortList()}return this.relativeOffset=r,a};N.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var r=new Array(n),a=0;a<n;a++)r[a]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:r}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};N.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:N.uShort,end:N.uShort,classId:N.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};N.list=function(t,e){return function(){return this.parseList(t,e)}};N.list32=function(t,e){return function(){return this.parseList32(t,e)}};N.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};N.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};N.pointer=function(t){return function(){return this.parsePointer(t)}};N.pointer32=function(t){return function(){return this.parsePointer32(t)}};N.tag=N.prototype.parseTag;N.byte=N.prototype.parseByte;N.uShort=N.offset16=N.prototype.parseUShort;N.uShortList=N.prototype.parseUShortList;N.uLong=N.offset32=N.prototype.parseULong;N.uLongList=N.prototype.parseULongList;N.struct=N.prototype.parseStruct;N.coverage=N.prototype.parseCoverage;N.classDef=N.prototype.parseClassDef;var v7={reserved:N.uShort,reqFeatureIndex:N.uShort,featureIndexes:N.uShortList};N.prototype.parseScriptList=function(){return this.parsePointer(N.recordList({tag:N.tag,script:N.pointer({defaultLangSys:N.pointer(v7),langSysRecords:N.recordList({tag:N.tag,langSys:N.pointer(v7)})})}))||[]};N.prototype.parseFeatureList=function(){return this.parsePointer(N.recordList({tag:N.tag,feature:N.pointer({featureParams:N.offset16,lookupListIndexes:N.uShortList})}))||[]};N.prototype.parseLookupList=function(t){return this.parsePointer(N.list(N.pointer(function(){var e=this.parseUShort();H1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),r=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(N.pointer(t[e])),markFilteringSet:r?this.parseUShort():void 0}})))||[]};N.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();H1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:N.offset32,featureTableSubstitutionOffset:N.offset32});return n})||[]};var y1={getByte:g7,getCard8:g7,getUShort:ct,getCard16:ct,getShort:nc,getULong:D4,getFixed:n8,getTag:rc,getOffset:ac,getBytes:sc,bytesToString:cc,Parser:N};function ic(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var r=0;r<n;r+=1)for(var a=e.parseULong(),s=e.parseULong(),c=e.parseULong(),o=a;o<=s;o+=1)t.glyphIndexMap[o]=c,c++}function lc(t,e,n,r,a){t.length=e.parseUShort(),t.language=e.parseUShort();var s;t.segCount=s=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var c=new y1.Parser(n,r+a+14),o=new y1.Parser(n,r+a+16+s*2),i=new y1.Parser(n,r+a+16+s*4),l=new y1.Parser(n,r+a+16+s*6),h=r+a+16+s*8,u=0;u<s-1;u+=1)for(var f=void 0,d=c.parseUShort(),m=o.parseUShort(),g=i.parseShort(),p=l.parseUShort(),v=m;v<=d;v+=1)p!==0?(h=l.offset+l.relativeOffset-2,h+=p,h+=(v-m)*2,f=y1.getUShort(n,h),f!==0&&(f=f+g&65535)):f=v+g&65535,t.glyphIndexMap[v]=f}function hc(t,e){var n={};n.version=y1.getUShort(t,e),H1.argument(n.version===0,"cmap table version should be 0."),n.numTables=y1.getUShort(t,e+2);for(var r=-1,a=n.numTables-1;a>=0;a-=1){var s=y1.getUShort(t,e+4+a*8),c=y1.getUShort(t,e+4+a*8+2);if(s===3&&(c===0||c===1||c===10)||s===0&&(c===0||c===1||c===2||c===3||c===4)){r=y1.getULong(t,e+4+a*8+4);break}}if(r===-1)throw new Error("No valid cmap sub-tables found.");var o=new y1.Parser(t,e+r);if(n.format=o.parseUShort(),n.format===12)ic(n,o);else if(n.format===4)lc(n,o,t,e,r);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function uc(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function fc(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function dc(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var r=t.get(n);if(r.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var a=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(a=a.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),a=a.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var s=new l1.Table("cmap",a);for(s.segments=[],n=0;n<t.length;n+=1){for(var c=t.get(n),o=0;o<c.unicodes.length;o+=1)uc(s,c.unicodes[o],n);s.segments=s.segments.sort(function(b,y){return b.start-y.start})}fc(s);var i=s.segments.length,l=0,h=[],u=[],f=[],d=[],m=[],g=[];for(n=0;n<i;n+=1){var p=s.segments[n];p.end<=65535&&p.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:p.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:p.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:p.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:p.offset}),p.glyphId!==void 0&&(m=m.concat({name:"glyph_"+n,type:"USHORT",value:p.glyphId}))):l+=1,!e&&p.glyphIndex!==void 0&&(g=g.concat({name:"cmap12Start_"+n,type:"ULONG",value:p.start}),g=g.concat({name:"cmap12End_"+n,type:"ULONG",value:p.end}),g=g.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:p.glyphIndex}))}if(s.segCountX2=(i-l)*2,s.searchRange=Math.pow(2,Math.floor(Math.log(i-l)/Math.log(2)))*2,s.entrySelector=Math.log(s.searchRange/2)/Math.log(2),s.rangeShift=s.segCountX2-s.searchRange,s.fields=s.fields.concat(h),s.fields.push({name:"reservedPad",type:"USHORT",value:0}),s.fields=s.fields.concat(u),s.fields=s.fields.concat(f),s.fields=s.fields.concat(d),s.fields=s.fields.concat(m),s.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+m.length*2,!e){var v=16+g.length*4;s.cmap12Offset=20+s.cmap4Length,s.fields=s.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:g.length/3}]),s.fields=s.fields.concat(g)}return s}var r8={parse:hc,make:dc},et=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],mc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],pc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],Ve=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function a8(t){this.font=t}a8.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var r=0;r<n.length;r+=1)for(var a=n.get(r),s=0;s<a.unicodes.length;s+=1)if(a.unicodes[s]===e)return r}return null};function s8(t){this.cmap=t}s8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function ot(t,e){this.encoding=t,this.charset=e}ot.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function N4(t){switch(t.version){case 1:this.names=Ve.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<Ve.length?this.names[e]=Ve[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-Ve.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=Ve[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}N4.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};N4.prototype.glyphIndexToName=function(t){return this.names[t]};function gc(t){for(var e,n=t.tables.cmap.glyphIndexMap,r=Object.keys(n),a=0;a<r.length;a+=1){var s=r[a],c=n[s];e=t.glyphs.get(c),e.addUnicode(parseInt(s))}for(var o=0;o<t.glyphs.length;o+=1)e=t.glyphs.get(o),t.cffEncoding?t.isCIDFont?e.name="gid"+o:e.name=t.cffEncoding.charset[o]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(o))}function vc(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),r=0;r<n.length;r+=1){var a=n[r],s=e[a];t._IndexToUnicodeMap[s]===void 0?t._IndexToUnicodeMap[s]={unicodes:[parseInt(a)]}:t._IndexToUnicodeMap[s].unicodes.push(parseInt(a))}}function bc(t,e){e.lowMemory?vc(t):gc(t)}function yc(t,e,n,r,a){t.beginPath(),t.moveTo(e,n),t.lineTo(r,a),t.stroke()}var Ie={line:yc};function xc(t,e){var n=e||new F0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(r){n=r}}}function v2(t){this.bindConstructorValues(t)}v2.prototype.bindConstructorValues=function(t){this.index=t.index||0,this.name=t.name||null,this.unicode=t.unicode||void 0,this.unicodes=t.unicodes||t.unicode!==void 0?[t.unicode]:[],"xMin"in t&&(this.xMin=t.xMin),"yMin"in t&&(this.yMin=t.yMin),"xMax"in t&&(this.xMax=t.xMax),"yMax"in t&&(this.yMax=t.yMax),"advanceWidth"in t&&(this.advanceWidth=t.advanceWidth),Object.defineProperty(this,"path",xc(this,t.path))};v2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};v2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};v2.prototype.getPath=function(t,e,n,r,a){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var s,c;r||(r={});var o=r.xScale,i=r.yScale;if(r.hinting&&a&&a.hinting&&(c=this.path&&a.hinting.exec(this,n)),c)s=a.hinting.getCommands(c),t=Math.round(t),e=Math.round(e),o=i=1;else{s=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;o===void 0&&(o=l),i===void 0&&(i=l)}for(var h=new F0,u=0;u<s.length;u+=1){var f=s[u];f.type==="M"?h.moveTo(t+f.x*o,e+-f.y*i):f.type==="L"?h.lineTo(t+f.x*o,e+-f.y*i):f.type==="Q"?h.quadraticCurveTo(t+f.x1*o,e+-f.y1*i,t+f.x*o,e+-f.y*i):f.type==="C"?h.curveTo(t+f.x1*o,e+-f.y1*i,t+f.x2*o,e+-f.y2*i,t+f.x*o,e+-f.y*i):f.type==="Z"&&h.closePath()}return h};v2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var r=this.points[n];e.push(r),r.lastPointOfContour&&(t.push(e),e=[])}return H1.argument(e.length===0,"There are still points left in the current contour."),t};v2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],r=0;r<t.length;r+=1){var a=t[r];a.type!=="Z"&&(e.push(a.x),n.push(a.y)),(a.type==="Q"||a.type==="C")&&(e.push(a.x1),n.push(a.y1)),a.type==="C"&&(e.push(a.x2),n.push(a.y2))}var s={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(s.xMin)||(s.xMin=0),isFinite(s.xMax)||(s.xMax=this.advanceWidth),isFinite(s.yMin)||(s.yMin=0),isFinite(s.yMax)||(s.yMax=0),s.rightSideBearing=this.advanceWidth-s.leftSideBearing-(s.xMax-s.xMin),s};v2.prototype.draw=function(t,e,n,r,a){this.getPath(e,n,r,a).draw(t)};v2.prototype.drawPoints=function(t,e,n,r){function a(u,f,d,m){t.beginPath();for(var g=0;g<u.length;g+=1)t.moveTo(f+u[g].x*m,d+u[g].y*m),t.arc(f+u[g].x*m,d+u[g].y*m,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24;for(var s=1/this.path.unitsPerEm*r,c=[],o=[],i=this.path,l=0;l<i.commands.length;l+=1){var h=i.commands[l];h.x!==void 0&&c.push({x:h.x,y:-h.y}),h.x1!==void 0&&o.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&o.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",a(c,e,n,s),t.fillStyle="red",a(o,e,n,s)};v2.prototype.drawMetrics=function(t,e,n,r){var a;e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24,a=1/this.path.unitsPerEm*r,t.lineWidth=1,t.strokeStyle="black",Ie.line(t,e,-1e4,e,1e4),Ie.line(t,-1e4,n,1e4,n);var s=this.xMin||0,c=this.yMin||0,o=this.xMax||0,i=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",Ie.line(t,e+s*a,-1e4,e+s*a,1e4),Ie.line(t,e+o*a,-1e4,e+o*a,1e4),Ie.line(t,-1e4,n+-c*a,1e4,n+-c*a),Ie.line(t,-1e4,n+-i*a,1e4,n+-i*a),t.strokeStyle="green",Ie.line(t,e+l*a,-1e4,e+l*a,1e4)};function J5(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(r){t[n]=r},enumerable:!0,configurable:!0})}function U4(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var r=e[n];r.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=r}this.length=e&&e.length||0}U4.prototype.get=function(t){if(this.glyphs[t]===void 0){this.font._push(t),typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());var e=this.glyphs[t],n=this.font._IndexToUnicodeMap[t];if(n)for(var r=0;r<n.unicodes.length;r++)e.addUnicode(n.unicodes[r]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+t:e.name=this.font.cffEncoding.charset[t]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(t)),this.glyphs[t].advanceWidth=this.font._hmtxTableData[t].advanceWidth,this.glyphs[t].leftSideBearing=this.font._hmtxTableData[t].leftSideBearing}else typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());return this.glyphs[t]};U4.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Mc(t,e){return new v2({index:e,font:t})}function wc(t,e,n,r,a,s){return function(){var c=new v2({index:e,font:t});return c.path=function(){n(c,r,a);var o=s(t.glyphs,c);return o.unitsPerEm=t.unitsPerEm,o},J5(c,"xMin","_xMin"),J5(c,"xMax","_xMax"),J5(c,"yMin","_yMin"),J5(c,"yMax","_yMax"),c}}function kc(t,e,n,r){return function(){var a=new v2({index:e,font:t});return a.path=function(){var s=n(t,a,r);return s.unitsPerEm=t.unitsPerEm,s},a}}var q2={GlyphSet:U4,glyphLoader:Mc,ttfGlyphLoader:wc,cffGlyphLoader:kc};function c8(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n+=1)if(!c8(t[n],e[n]))return!1;return!0}else return!1}function V4(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function fe(t,e,n){var r=[],a=[],s=y1.getCard16(t,e),c,o;if(s!==0){var i=y1.getByte(t,e+2);c=e+(s+1)*i+2;for(var l=e+3,h=0;h<s+1;h+=1)r.push(y1.getOffset(t,l,i)),l+=i;o=c+r[s]}else o=e+2;for(var u=0;u<r.length-1;u+=1){var f=y1.getBytes(t,c+r[u],c+r[u+1]);n&&(f=n(f)),a.push(f)}return{objects:a,startOffset:e,endOffset:o}}function zc(t,e){var n=[],r=y1.getCard16(t,e),a,s;if(r!==0){var c=y1.getByte(t,e+2);a=e+(r+1)*c+2;for(var o=e+3,i=0;i<r+1;i+=1)n.push(y1.getOffset(t,o,c)),o+=c;s=a+n[r]}else s=e+2;return{offsets:n,startOffset:e,endOffset:s}}function Sc(t,e,n,r,a){var s=y1.getCard16(n,r),c=0;if(s!==0){var o=y1.getByte(n,r+2);c=r+(s+1)*o+2}var i=y1.getBytes(n,c+e[t],c+e[t+1]);return a&&(i=a(i)),i}function Ac(t){for(var e="",n=15,r=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var a=t.parseByte(),s=a>>4,c=a&15;if(s===n||(e+=r[s],c===n))break;e+=r[c]}return parseFloat(e)}function Lc(t,e){var n,r,a,s;if(e===28)return n=t.parseByte(),r=t.parseByte(),n<<8|r;if(e===29)return n=t.parseByte(),r=t.parseByte(),a=t.parseByte(),s=t.parseByte(),n<<24|r<<16|a<<8|s;if(e===30)return Ac(t);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return n=t.parseByte(),(e-247)*256+n+108;if(e>=251&&e<=254)return n=t.parseByte(),-(e-251)*256-n-108;throw new Error("Invalid b0 "+e)}function Cc(t){for(var e={},n=0;n<t.length;n+=1){var r=t[n][0],a=t[n][1],s=void 0;if(a.length===1?s=a[0]:s=a,e.hasOwnProperty(r)&&!isNaN(e[r]))throw new Error("Object "+e+" already has key "+r);e[r]=s}return e}function o8(t,e,n){e=e!==void 0?e:0;var r=new y1.Parser(t,e),a=[],s=[];for(n=n!==void 0?n:t.length;r.relativeOffset<n;){var c=r.parseByte();c<=21?(c===12&&(c=1200+r.parseByte()),a.push([c,s]),s=[]):s.push(Lc(r,c))}return Cc(a)}function t5(t,e){return e<=390?e=et[e]:e=t[e-391],e}function i8(t,e,n){for(var r={},a,s=0;s<e.length;s+=1){var c=e[s];if(Array.isArray(c.type)){var o=[];o.length=c.type.length;for(var i=0;i<c.type.length;i++)a=t[c.op]!==void 0?t[c.op][i]:void 0,a===void 0&&(a=c.value!==void 0&&c.value[i]!==void 0?c.value[i]:null),c.type[i]==="SID"&&(a=t5(n,a)),o[i]=a;r[c.name]=o}else a=t[c.op],a===void 0&&(a=c.value!==void 0?c.value:null),c.type==="SID"&&(a=t5(n,a)),r[c.name]=a}return r}function Pc(t,e){var n={};return n.formatMajor=y1.getCard8(t,e),n.formatMinor=y1.getCard8(t,e+1),n.size=y1.getCard8(t,e+2),n.offsetSize=y1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var l8=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],h8=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function Ec(t,e){var n=o8(t,0,t.byteLength);return i8(n,l8,e)}function u8(t,e,n,r){var a=o8(t,e,n);return i8(a,h8,r)}function b7(t,e,n,r){for(var a=[],s=0;s<n.length;s+=1){var c=new DataView(new Uint8Array(n[s]).buffer),o=Ec(c,r);o._subrs=[],o._subrsBias=0,o._defaultWidthX=0,o._nominalWidthX=0;var i=o.private[0],l=o.private[1];if(i!==0&&l!==0){var h=u8(t,l+e,i,r);if(o._defaultWidthX=h.defaultWidthX,o._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=fe(t,u+e);o._subrs=f.objects,o._subrsBias=V4(o._subrs)}o._privateDict=h}a.push(o)}return a}function Tc(t,e,n,r){var a,s,c=new y1.Parser(t,e);n-=1;var o=[".notdef"],i=c.parseCard8();if(i===0)for(var l=0;l<n;l+=1)a=c.parseSID(),o.push(t5(r,a));else if(i===1)for(;o.length<=n;){a=c.parseSID(),s=c.parseCard8();for(var h=0;h<=s;h+=1)o.push(t5(r,a)),a+=1}else if(i===2)for(;o.length<=n;){a=c.parseSID(),s=c.parseCard16();for(var u=0;u<=s;u+=1)o.push(t5(r,a)),a+=1}else throw new Error("Unknown charset format "+i);return o}function Ic(t,e,n){var r,a={},s=new y1.Parser(t,e),c=s.parseCard8();if(c===0)for(var o=s.parseCard8(),i=0;i<o;i+=1)r=s.parseCard8(),a[r]=i;else if(c===1){var l=s.parseCard8();r=1;for(var h=0;h<l;h+=1)for(var u=s.parseCard8(),f=s.parseCard8(),d=u;d<=u+f;d+=1)a[d]=r,r+=1}else throw new Error("Unknown encoding format "+c);return new ot(a,n)}function y7(t,e,n){var r,a,s,c,o=new F0,i=[],l=0,h=!1,u=!1,f=0,d=0,m,g,p,v;if(t.isCIDFont){var b=t.tables.cff.topDict._fdSelect[e.index],y=t.tables.cff.topDict._fdArray[b];m=y._subrs,g=y._subrsBias,p=y._defaultWidthX,v=y._nominalWidthX}else m=t.tables.cff.topDict._subrs,g=t.tables.cff.topDict._subrsBias,p=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var M=p;function w(A,L){u&&o.closePath(),o.moveTo(A,L),u=!0}function x(){var A;A=i.length%2!==0,A&&!h&&(M=i.shift()+v),l+=i.length>>1,i.length=0,h=!0}function k(A){for(var L,z,S,C,E,I,H,T,O,_,D,G,V=0;V<A.length;){var U=A[V];switch(V+=1,U){case 1:x();break;case 3:x();break;case 4:i.length>1&&!h&&(M=i.shift()+v,h=!0),d+=i.pop(),w(f,d);break;case 5:for(;i.length>0;)f+=i.shift(),d+=i.shift(),o.lineTo(f,d);break;case 6:for(;i.length>0&&(f+=i.shift(),o.lineTo(f,d),i.length!==0);)d+=i.shift(),o.lineTo(f,d);break;case 7:for(;i.length>0&&(d+=i.shift(),o.lineTo(f,d),i.length!==0);)f+=i.shift(),o.lineTo(f,d);break;case 8:for(;i.length>0;)r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+i.shift(),o.curveTo(r,a,s,c,f,d);break;case 10:E=i.pop()+g,I=m[E],I&&k(I);break;case 11:return;case 12:switch(U=A[V],V+=1,U){case 35:r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c+i.shift(),O=H+i.shift(),_=T+i.shift(),D=O+i.shift(),G=_+i.shift(),f=D+i.shift(),d=G+i.shift(),i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;case 34:r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c,O=H+i.shift(),_=c,D=O+i.shift(),G=d,f=D+i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;case 36:r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c,O=H+i.shift(),_=c,D=O+i.shift(),G=_+i.shift(),f=D+i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;case 37:r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),H=s+i.shift(),T=c+i.shift(),O=H+i.shift(),_=T+i.shift(),D=O+i.shift(),G=_+i.shift(),Math.abs(D-f)>Math.abs(G-d)?f=D+i.shift():d=G+i.shift(),o.curveTo(r,a,s,c,H,T),o.curveTo(O,_,D,G,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+U),i.length=0}break;case 14:i.length>0&&!h&&(M=i.shift()+v,h=!0),u&&(o.closePath(),u=!1);break;case 18:x();break;case 19:case 20:x(),V+=l+7>>3;break;case 21:i.length>2&&!h&&(M=i.shift()+v,h=!0),d+=i.pop(),f+=i.pop(),w(f,d);break;case 22:i.length>1&&!h&&(M=i.shift()+v,h=!0),f+=i.pop(),w(f,d);break;case 23:x();break;case 24:for(;i.length>2;)r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+i.shift(),o.curveTo(r,a,s,c,f,d);f+=i.shift(),d+=i.shift(),o.lineTo(f,d);break;case 25:for(;i.length>6;)f+=i.shift(),d+=i.shift(),o.lineTo(f,d);r=f+i.shift(),a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+i.shift(),o.curveTo(r,a,s,c,f,d);break;case 26:for(i.length%2&&(f+=i.shift());i.length>0;)r=f,a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s,d=c+i.shift(),o.curveTo(r,a,s,c,f,d);break;case 27:for(i.length%2&&(d+=i.shift());i.length>0;)r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c,o.curveTo(r,a,s,c,f,d);break;case 28:L=A[V],z=A[V+1],i.push((L<<24|z<<16)>>16),V+=2;break;case 29:E=i.pop()+t.gsubrsBias,I=t.gsubrs[E],I&&k(I);break;case 30:for(;i.length>0&&(r=f,a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d),i.length!==0);)r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),d=c+i.shift(),f=s+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d);break;case 31:for(;i.length>0&&(r=f+i.shift(),a=d,s=r+i.shift(),c=a+i.shift(),d=c+i.shift(),f=s+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d),i.length!==0);)r=f,a=d+i.shift(),s=r+i.shift(),c=a+i.shift(),f=s+i.shift(),d=c+(i.length===1?i.shift():0),o.curveTo(r,a,s,c,f,d);break;default:U<32?console.log("Glyph "+e.index+": unknown operator "+U):U<247?i.push(U-139):U<251?(L=A[V],V+=1,i.push((U-247)*256+L+108)):U<255?(L=A[V],V+=1,i.push(-(U-251)*256-L-108)):(L=A[V],z=A[V+1],S=A[V+2],C=A[V+3],V+=4,i.push((L<<24|z<<16|S<<8|C)/65536))}}}return k(n),e.advanceWidth=M,o}function Vc(t,e,n,r){var a=[],s,c=new y1.Parser(t,e),o=c.parseCard8();if(o===0)for(var i=0;i<n;i++){if(s=c.parseCard8(),s>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+r+")");a.push(s)}else if(o===3){var l=c.parseCard16(),h=c.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var u,f=0;f<l;f++){if(s=c.parseCard8(),u=c.parseCard16(),s>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+r+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)a.push(s);h=u}if(u!==n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+u)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+o);return a}function $c(t,e,n,r){n.tables.cff={};var a=Pc(t,e),s=fe(t,a.endOffset,y1.bytesToString),c=fe(t,s.endOffset),o=fe(t,c.endOffset,y1.bytesToString),i=fe(t,o.endOffset);n.gsubrs=i.objects,n.gsubrsBias=V4(n.gsubrs);var l=b7(t,e,c.objects,o.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=fe(t,u),m=b7(t,e,d.objects,o.objects);h._fdArray=m,f+=e,h._fdSelect=Vc(t,f,n.numGlyphs,m.length)}var g=e+h.private[1],p=u8(t,g,h.private[0],o.objects);if(n.defaultWidthX=p.defaultWidthX,n.nominalWidthX=p.nominalWidthX,p.subrs!==0){var v=g+p.subrs,b=fe(t,v);n.subrs=b.objects,n.subrsBias=V4(n.subrs)}else n.subrs=[],n.subrsBias=0;var y;r.lowMemory?(y=zc(t,e+h.charStrings),n.nGlyphs=y.offsets.length):(y=fe(t,e+h.charStrings),n.nGlyphs=y.objects.length);var M=Tc(t,e+h.charset,n.nGlyphs,o.objects);if(h.encoding===0?n.cffEncoding=new ot(mc,M):h.encoding===1?n.cffEncoding=new ot(pc,M):n.cffEncoding=Ic(t,e+h.encoding,M),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new q2.GlyphSet(n),r.lowMemory)n._push=function(k){var A=Sc(k,y.offsets,t,e+h.charStrings);n.glyphs.push(k,q2.cffGlyphLoader(n,k,y7,A))};else for(var w=0;w<n.nGlyphs;w+=1){var x=y.objects[w];n.glyphs.push(w,q2.cffGlyphLoader(n,w,y7,x))}}function f8(t,e){var n,r=et.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+et.length:(n=et.length+e.length,e.push(t)),n}function Hc(){return new l1.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function Oc(t){var e=new l1.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var n=0;n<t.length;n+=1)e.names.push({name:"name_"+n,type:"NAME",value:t[n]});return e}function d8(t,e,n){for(var r={},a=0;a<t.length;a+=1){var s=t[a],c=e[s.name];c!==void 0&&!c8(c,s.value)&&(s.type==="SID"&&(c=f8(c,n)),r[s.op]={name:s.name,type:s.type,value:c})}return r}function x7(t,e){var n=new l1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=d8(l8,t,e),n}function M7(t){var e=new l1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function Rc(t){var e=new l1.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var n=0;n<t.length;n+=1)e.strings.push({name:"string_"+n,type:"STRING",value:t[n]});return e}function Fc(){return new l1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function _c(t,e){for(var n=new l1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),r=0;r<t.length;r+=1){var a=t[r],s=f8(a,e);n.fields.push({name:"glyph_"+r,type:"SID",value:s})}return n}function qc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var r=0,a=0,s=0;s<n.commands.length;s+=1){var c=void 0,o=void 0,i=n.commands[s];if(i.type==="Q"){var l=.3333333333333333,h=2/3;i={type:"C",x:i.x,y:i.y,x1:Math.round(l*r+h*i.x1),y1:Math.round(l*a+h*i.y1),x2:Math.round(l*i.x+h*i.x1),y2:Math.round(l*i.y+h*i.y1)}}if(i.type==="M")c=Math.round(i.x-r),o=Math.round(i.y-a),e.push({name:"dx",type:"NUMBER",value:c}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rmoveto",type:"OP",value:21}),r=Math.round(i.x),a=Math.round(i.y);else if(i.type==="L")c=Math.round(i.x-r),o=Math.round(i.y-a),e.push({name:"dx",type:"NUMBER",value:c}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rlineto",type:"OP",value:5}),r=Math.round(i.x),a=Math.round(i.y);else if(i.type==="C"){var u=Math.round(i.x1-r),f=Math.round(i.y1-a),d=Math.round(i.x2-i.x1),m=Math.round(i.y2-i.y1);c=Math.round(i.x-i.x2),o=Math.round(i.y-i.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:m}),e.push({name:"dx",type:"NUMBER",value:c}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rrcurveto",type:"OP",value:8}),r=Math.round(i.x),a=Math.round(i.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function Dc(t){for(var e=new l1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var r=t.get(n),a=qc(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:a})}return e}function Nc(t,e){var n=new l1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=d8(h8,t,e),n}function Uc(t,e){for(var n=new l1.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),r=1/e.unitsPerEm,a={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[r,0,0,r,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},s={},c=[],o,i=1;i<t.length;i+=1)o=t.get(i),c.push(o.name);var l=[];n.header=Hc(),n.nameIndex=Oc([e.postScriptName]);var h=x7(a,l);n.topDictIndex=M7(h),n.globalSubrIndex=Fc(),n.charsets=_c(c,l),n.charStringsIndex=Dc(t),n.privateDict=Nc(s,l),n.stringIndex=Rc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return a.charset=u,a.encoding=0,a.charStrings=a.charset+n.charsets.sizeOf(),a.private[1]=a.charStrings+n.charStringsIndex.sizeOf(),h=x7(a,l),n.topDictIndex=M7(h),n}var m8={parse:$c,make:Uc};function Bc(t,e){var n={},r=new y1.Parser(t,e);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),H1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=r.parseUShort(),n.unitsPerEm=r.parseUShort(),n.created=r.parseLongDateTime(),n.modified=r.parseLongDateTime(),n.xMin=r.parseShort(),n.yMin=r.parseShort(),n.xMax=r.parseShort(),n.yMax=r.parseShort(),n.macStyle=r.parseUShort(),n.lowestRecPPEM=r.parseUShort(),n.fontDirectionHint=r.parseShort(),n.indexToLocFormat=r.parseShort(),n.glyphDataFormat=r.parseShort(),n}function jc(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new l1.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:n},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],t)}var p8={parse:Bc,make:jc};function Gc(t,e){var n={},r=new y1.Parser(t,e);return n.version=r.parseVersion(),n.ascender=r.parseShort(),n.descender=r.parseShort(),n.lineGap=r.parseShort(),n.advanceWidthMax=r.parseUShort(),n.minLeftSideBearing=r.parseShort(),n.minRightSideBearing=r.parseShort(),n.xMaxExtent=r.parseShort(),n.caretSlopeRise=r.parseShort(),n.caretSlopeRun=r.parseShort(),n.caretOffset=r.parseShort(),r.relativeOffset+=8,n.metricDataFormat=r.parseShort(),n.numberOfHMetrics=r.parseUShort(),n}function Wc(t){return new l1.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],t)}var g8={parse:Gc,make:Wc};function Xc(t,e,n,r,a){for(var s,c,o=new y1.Parser(t,e),i=0;i<r;i+=1){i<n&&(s=o.parseUShort(),c=o.parseShort());var l=a.get(i);l.advanceWidth=s,l.leftSideBearing=c}}function Zc(t,e,n,r,a){t._hmtxTableData={};for(var s,c,o=new y1.Parser(e,n),i=0;i<a;i+=1)i<r&&(s=o.parseUShort(),c=o.parseShort()),t._hmtxTableData[i]={advanceWidth:s,leftSideBearing:c}}function Yc(t,e,n,r,a,s,c){c.lowMemory?Zc(t,e,n,r,a):Xc(e,n,r,a,s)}function Kc(t){for(var e=new l1.Table("hmtx",[]),n=0;n<t.length;n+=1){var r=t.get(n),a=r.advanceWidth||0,s=r.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:a}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:s})}return e}var v8={parse:Yc,make:Kc};function Jc(t){for(var e=new l1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",r=12+t.length*4,a=0;a<t.length;++a){var s=n.indexOf(t[a]);s<0&&(s=n.length,n+=t[a]),e.fields.push({name:"offset "+a,type:"USHORT",value:r+s}),e.fields.push({name:"length "+a,type:"USHORT",value:t[a].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Qc(t,e){var n=new y1.Parser(t,e),r=n.parseULong();H1.argument(r===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var a=n.parseULong(),s=[],c=0;c<a;c++){for(var o="",i=e+n.parseUShort(),l=n.parseUShort(),h=i;h<i+l;++h)o+=String.fromCharCode(t.getInt8(h));s.push(o)}return s}var b8={make:Jc,parse:Qc};function e9(t,e){var n={},r=new y1.Parser(t,e);return n.version=r.parseVersion(),n.numGlyphs=r.parseUShort(),n.version===1&&(n.maxPoints=r.parseUShort(),n.maxContours=r.parseUShort(),n.maxCompositePoints=r.parseUShort(),n.maxCompositeContours=r.parseUShort(),n.maxZones=r.parseUShort(),n.maxTwilightPoints=r.parseUShort(),n.maxStorage=r.parseUShort(),n.maxFunctionDefs=r.parseUShort(),n.maxInstructionDefs=r.parseUShort(),n.maxStackElements=r.parseUShort(),n.maxSizeOfInstructions=r.parseUShort(),n.maxComponentElements=r.parseUShort(),n.maxComponentDepth=r.parseUShort()),n}function t9(t){return new l1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var y8={parse:e9,make:t9},x8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],M8={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},n9={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},w8={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function r9(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return M8[e];case 3:return w8[e]}}var $4="utf-16",a9={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},s9={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function k8(t,e,n){switch(t){case 0:return $4;case 1:return s9[n]||a9[e];case 3:if(e===1||e===10)return $4;break}}function c9(t,e,n){for(var r={},a=new y1.Parser(t,e),s=a.parseUShort(),c=a.parseUShort(),o=a.offset+a.parseUShort(),i=0;i<c;i++){var l=a.parseUShort(),h=a.parseUShort(),u=a.parseUShort(),f=a.parseUShort(),d=x8[f]||f,m=a.parseUShort(),g=a.parseUShort(),p=r9(l,u,n),v=k8(l,h,u);if(v!==void 0&&p!==void 0){var b=void 0;if(v===$4?b=l3.UTF16(t,o+g,m):b=l3.MACSTRING(t,o+g,m,v),b){var y=r[d];y===void 0&&(y=r[d]={}),y[p]=b}}}var M=0;return s===1&&(M=a.parseUShort()),r}function M4(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function w7(t,e,n,r,a,s){return new l1.Record("NameRecord",[{name:"platformID",type:"USHORT",value:t},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:n},{name:"nameID",type:"USHORT",value:r},{name:"length",type:"USHORT",value:a},{name:"offset",type:"USHORT",value:s}])}function o9(t,e){var n=t.length,r=e.length-n+1;e:for(var a=0;a<r;a++)for(;a<r;a++){for(var s=0;s<n;s++)if(e[a+s]!==t[s])continue e;return a}return-1}function k7(t,e){var n=o9(t,e);if(n<0){n=e.length;for(var r=0,a=t.length;r<a;++r)e.push(t[r])}return n}function i9(t,e){var n,r=[],a={},s=M4(x8);for(var c in t){var o=s[c];if(o===void 0&&(o=c),n=parseInt(o),isNaN(n))throw new Error('Name table entry "'+c+'" does not exist, see nameTableNames for complete list.');a[n]=t[c],r.push(n)}for(var i=M4(M8),l=M4(w8),h=[],u=[],f=0;f<r.length;f++){n=r[f];var d=a[n];for(var m in d){var g=d[m],p=1,v=i[m],b=n9[v],y=k8(p,b,v),M=r1.MACSTRING(g,y);M===void 0&&(p=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),b=4,M=r1.UTF16(g));var w=k7(M,u);h.push(w7(p,b,v,n,M.length,w));var x=l[m];if(x!==void 0){var k=r1.UTF16(g),A=k7(k,u);h.push(w7(3,1,x,n,k.length,A))}}}h.sort(function(S,C){return S.platformID-C.platformID||S.encodingID-C.encodingID||S.languageID-C.languageID||S.nameID-C.nameID});for(var L=new l1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),z=0;z<h.length;z++)L.fields.push({name:"record_"+z,type:"RECORD",value:h[z]});return L.fields.push({name:"strings",type:"LITERAL",value:u}),L}var z8={parse:c9,make:i9},H4=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function l9(t){for(var e=0;e<H4.length;e+=1){var n=H4[e];if(t>=n.begin&&t<n.end)return e}return-1}function h9(t,e){var n={},r=new y1.Parser(t,e);n.version=r.parseUShort(),n.xAvgCharWidth=r.parseShort(),n.usWeightClass=r.parseUShort(),n.usWidthClass=r.parseUShort(),n.fsType=r.parseUShort(),n.ySubscriptXSize=r.parseShort(),n.ySubscriptYSize=r.parseShort(),n.ySubscriptXOffset=r.parseShort(),n.ySubscriptYOffset=r.parseShort(),n.ySuperscriptXSize=r.parseShort(),n.ySuperscriptYSize=r.parseShort(),n.ySuperscriptXOffset=r.parseShort(),n.ySuperscriptYOffset=r.parseShort(),n.yStrikeoutSize=r.parseShort(),n.yStrikeoutPosition=r.parseShort(),n.sFamilyClass=r.parseShort(),n.panose=[];for(var a=0;a<10;a++)n.panose[a]=r.parseByte();return n.ulUnicodeRange1=r.parseULong(),n.ulUnicodeRange2=r.parseULong(),n.ulUnicodeRange3=r.parseULong(),n.ulUnicodeRange4=r.parseULong(),n.achVendID=String.fromCharCode(r.parseByte(),r.parseByte(),r.parseByte(),r.parseByte()),n.fsSelection=r.parseUShort(),n.usFirstCharIndex=r.parseUShort(),n.usLastCharIndex=r.parseUShort(),n.sTypoAscender=r.parseShort(),n.sTypoDescender=r.parseShort(),n.sTypoLineGap=r.parseShort(),n.usWinAscent=r.parseUShort(),n.usWinDescent=r.parseUShort(),n.version>=1&&(n.ulCodePageRange1=r.parseULong(),n.ulCodePageRange2=r.parseULong()),n.version>=2&&(n.sxHeight=r.parseShort(),n.sCapHeight=r.parseShort(),n.usDefaultChar=r.parseUShort(),n.usBreakChar=r.parseUShort(),n.usMaxContent=r.parseUShort()),n}function u9(t){return new l1.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],t)}var O4={parse:h9,make:u9,unicodeRanges:H4,getUnicodeRange:l9};function f9(t,e){var n={},r=new y1.Parser(t,e);switch(n.version=r.parseVersion(),n.italicAngle=r.parseFixed(),n.underlinePosition=r.parseShort(),n.underlineThickness=r.parseShort(),n.isFixedPitch=r.parseULong(),n.minMemType42=r.parseULong(),n.maxMemType42=r.parseULong(),n.minMemType1=r.parseULong(),n.maxMemType1=r.parseULong(),n.version){case 1:n.names=Ve.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var a=0;a<n.numberOfGlyphs;a++)n.glyphNameIndex[a]=r.parseUShort();n.names=[];for(var s=0;s<n.numberOfGlyphs;s++)if(n.glyphNameIndex[s]>=Ve.length){var c=r.parseChar();n.names.push(r.parseString(c))}break;case 2.5:n.numberOfGlyphs=r.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var o=0;o<n.numberOfGlyphs;o++)n.offset[o]=r.parseChar();break}return n}function d9(){return new l1.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var S8={parse:f9,make:d9},M2=new Array(9);M2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(N.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(N.coverage),substitute:this.parseOffset16List()};H1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};M2[2]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),sequences:this.parseListOfLists()}};M2[3]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),alternateSets:this.parseListOfLists()}};M2[4]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var i3={sequenceIndex:N.uShort,lookupListIndex:N.uShort};M2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(N.coverage),ruleSets:this.parseListOfLists(function(){var s=this.parseUShort(),c=this.parseUShort();return{input:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(c,i3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(N.coverage),classDef:this.parsePointer(N.classDef),classSets:this.parseListOfLists(function(){var s=this.parseUShort(),c=this.parseUShort();return{classes:this.parseUShortList(s-1),lookupRecords:this.parseRecordList(c,i3)}})};if(n===3){var r=this.parseUShort(),a=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,N.pointer(N.coverage)),lookupRecords:this.parseRecordList(a,i3)}}H1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};M2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(N.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(i3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(N.coverage),backtrackClassDef:this.parsePointer(N.classDef),inputClassDef:this.parsePointer(N.classDef),lookaheadClassDef:this.parsePointer(N.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(i3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(N.pointer(N.coverage)),inputCoverage:this.parseList(N.pointer(N.coverage)),lookaheadCoverage:this.parseList(N.pointer(N.coverage)),lookupRecords:this.parseRecordList(i3)};H1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};M2[7]=function(){var e=this.parseUShort();H1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),r=new N(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:M2[n].call(r)}};M2[8]=function(){var e=this.parseUShort();return H1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),backtrackCoverage:this.parseList(N.pointer(N.coverage)),lookaheadCoverage:this.parseList(N.pointer(N.coverage)),substitutes:this.parseUShortList()}};function m9(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return H1.argument(r===1||r===1.1,"Unsupported GSUB table version."),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(M2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(M2),variations:n.parseFeatureVariationsList()}}var h3=new Array(9);h3[1]=function(e){return e.substFormat===1?new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.ushortList("substitute",e.substitute)))};h3[2]=function(e){return H1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("seqSet",e.sequences,function(n){return new l1.Table("sequenceSetTable",l1.ushortList("sequence",n))})))};h3[3]=function(e){return H1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("altSet",e.alternateSets,function(n){return new l1.Table("alternateSetTable",l1.ushortList("alternate",n))})))};h3[4]=function(e){return H1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new l1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("ligSet",e.ligatureSets,function(n){return new l1.Table("ligatureSetTable",l1.tableList("ligature",n,function(r){return new l1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:r.ligGlyph}].concat(l1.ushortList("component",r.components,r.components.length+1)))}))})))};h3[6]=function(e){if(e.substFormat===1){var n=new l1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new l1.Coverage(e.coverage)}].concat(l1.tableList("chainRuleSet",e.chainRuleSets,function(s){return new l1.Table("chainRuleSetTable",l1.tableList("chainRule",s,function(c){var o=l1.ushortList("backtrackGlyph",c.backtrack,c.backtrack.length).concat(l1.ushortList("inputGlyph",c.input,c.input.length+1)).concat(l1.ushortList("lookaheadGlyph",c.lookahead,c.lookahead.length)).concat(l1.ushortList("substitution",[],c.lookupRecords.length));return c.lookupRecords.forEach(function(i,l){o=o.concat({name:"sequenceIndex"+l,type:"USHORT",value:i.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:i.lookupListIndex})}),new l1.Table("chainRuleTable",o)}))})));return n}else if(e.substFormat===2)H1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var r=[{name:"substFormat",type:"USHORT",value:e.substFormat}];r.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(s,c){r.push({name:"backtrackCoverage"+c,type:"TABLE",value:new l1.Coverage(s)})}),r.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(s,c){r.push({name:"inputCoverage"+c,type:"TABLE",value:new l1.Coverage(s)})}),r.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(s,c){r.push({name:"lookaheadCoverage"+c,type:"TABLE",value:new l1.Coverage(s)})}),r.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(s,c){r=r.concat({name:"sequenceIndex"+c,type:"USHORT",value:s.sequenceIndex}).concat({name:"lookupListIndex"+c,type:"USHORT",value:s.lookupListIndex})});var a=new l1.Table("chainContextTable",r);return a}H1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function p9(t){return new l1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new l1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new l1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new l1.LookupList(t.lookups,h3)}])}var A8={parse:m9,make:p9};function g9(t,e){var n=new y1.Parser(t,e),r=n.parseULong();H1.argument(r===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var a=n.parseULong(),s={},c=0;c<a;c++){var o=n.parseTag(),i=n.parseULong(),l=n.parseULong(),h=l3.UTF8(t,e+i,l);s[o]=h}return s}function v9(t){var e=Object.keys(t).length,n="",r=16+e*12,a=new l1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:r},{name:"numTags",type:"ULONG",value:e}]);for(var s in t){var c=n.length;n+=t[s],a.fields.push({name:"tag "+s,type:"TAG",value:s}),a.fields.push({name:"offset "+s,type:"ULONG",value:r+c}),a.fields.push({name:"length "+s,type:"ULONG",value:t[s].length})}return a.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),a}var L8={parse:g9,make:v9};function z7(t){return Math.log(t)/Math.log(2)|0}function B4(t){for(;t.length%4!==0;)t.push(0);for(var e=0,n=0;n<t.length;n+=4)e+=(t[n]<<24)+(t[n+1]<<16)+(t[n+2]<<8)+t[n+3];return e%=Math.pow(2,32),e}function S7(t,e,n,r){return new l1.Record("Table Record",[{name:"tag",type:"TAG",value:t!==void 0?t:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:n!==void 0?n:0},{name:"length",type:"ULONG",value:r!==void 0?r:0}])}function C8(t){var e=new l1.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=t,e.numTables=t.length;var n=Math.pow(2,z7(e.numTables));e.searchRange=16*n,e.entrySelector=z7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],a=[],s=e.sizeOf()+S7().sizeOf()*e.numTables;s%4!==0;)s+=1,a.push({name:"padding",type:"BYTE",value:0});for(var c=0;c<t.length;c+=1){var o=t[c];H1.argument(o.tableName.length===4,"Table name"+o.tableName+" is invalid.");var i=o.sizeOf(),l=S7(o.tableName,B4(o.encode()),s,i);for(r.push({name:l.tag+" Table Record",type:"RECORD",value:l}),a.push({name:o.tableName+" table",type:"RECORD",value:o}),s+=i,H1.argument(!isNaN(s),"Something went wrong calculating the offset.");s%4!==0;)s+=1,a.push({name:"padding",type:"BYTE",value:0})}return r.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(r),e.fields=e.fields.concat(a),e}function A7(t,e,n){for(var r=0;r<e.length;r+=1){var a=t.charToGlyphIndex(e[r]);if(a>0){var s=t.glyphs.get(a);return s.getMetrics()}}return n}function b9(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function y9(t){for(var e=[],n=[],r=[],a=[],s=[],c=[],o=[],i,l=0,h=0,u=0,f=0,d=0,m=0;m<t.glyphs.length;m+=1){var g=t.glyphs.get(m),p=g.unicode|0;if(isNaN(g.advanceWidth))throw new Error("Glyph "+g.name+" ("+m+"): advanceWidth is not a number.");(i>p||i===void 0)&&p>0&&(i=p),l<p&&(l=p);var v=O4.getUnicodeRange(p);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(g.name!==".notdef"){var b=g.getMetrics();e.push(b.xMin),n.push(b.yMin),r.push(b.xMax),a.push(b.yMax),c.push(b.leftSideBearing),o.push(b.rightSideBearing),s.push(g.advanceWidth)}}var y={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,r),yMax:Math.max.apply(null,a),advanceWidthMax:Math.max.apply(null,s),advanceWidthAvg:b9(s),minLeftSideBearing:Math.min.apply(null,c),maxLeftSideBearing:Math.max.apply(null,c),minRightSideBearing:Math.min.apply(null,o)};y.ascender=t.ascender,y.descender=t.descender;var M=p8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),w=g8.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:t.glyphs.length}),x=y8.make(t.glyphs.length),k=O4.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:i,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:A7(t,"xyvw",{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:A7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",y).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),A=v8.make(t.glyphs),L=r8.make(t.glyphs),z=t.getEnglishName("fontFamily"),S=t.getEnglishName("fontSubfamily"),C=z+" "+S,E=t.getEnglishName("postScriptName");E||(E=z.replace(/\s/g,"")+"-"+S);var I={};for(var H in t.names)I[H]=t.names[H];I.uniqueID||(I.uniqueID={en:t.getEnglishName("manufacturer")+":"+C}),I.postScriptName||(I.postScriptName={en:E}),I.preferredFamily||(I.preferredFamily=t.names.fontFamily),I.preferredSubfamily||(I.preferredSubfamily=t.names.fontSubfamily);var T=[],O=z8.make(I,T),_=T.length>0?b8.make(T):void 0,D=S8.make(),G=m8.make(t.glyphs,{version:t.getEnglishName("version"),fullName:C,familyName:z,weightName:S,postScriptName:E,unitsPerEm:t.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),V=t.metas&&Object.keys(t.metas).length>0?L8.make(t.metas):void 0,U=[M,w,x,k,O,L,D,G,A];_&&U.push(_),t.tables.gsub&&U.push(A8.make(t.tables.gsub)),V&&U.push(V);for(var J=C8(U),n1=J.encode(),m1=B4(n1),M1=J.fields,c1=!1,C1=0;C1<M1.length;C1+=1)if(M1[C1].name==="head table"){M1[C1].value.checkSumAdjustment=2981146554-m1,c1=!0;break}if(!c1)throw new Error("Could not find head table with checkSum to adjust.");return J}var x9={make:C8,fontToTable:y9,computeCheckSum:B4};function w4(t,e){for(var n=0,r=t.length-1;n<=r;){var a=n+r>>>1,s=t[a].tag;if(s===e)return a;s<e?n=a+1:r=a-1}return-n-1}function L7(t,e){for(var n=0,r=t.length-1;n<=r;){var a=n+r>>>1,s=t[a];if(s===e)return a;s<e?n=a+1:r=a-1}return-n-1}function C7(t,e){for(var n,r=0,a=t.length-1;r<=a;){var s=r+a>>>1;n=t[s];var c=n.start;if(c===e)return n;c<e?r=s+1:a=s-1}if(r>0)return n=t[r-1],e>n.end?0:n}function c5(t,e){this.font=t,this.tableName=e}c5.prototype={searchTag:w4,binSearch:L7,getTable:function(t){var e=this.font.tables[this.tableName];return!e&&t&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var t=this.getTable();return t?t.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var t=this.getTable();if(t){for(var e=!1,n=0;n<t.scripts.length;n++){var r=t.scripts[n].tag;if(r==="DFLT")return r;r==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var r=n.scripts,a=w4(n.scripts,t);if(a>=0)return r[a].script;if(e){var s={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-a,0,s),s.script}}},getLangSysTable:function(t,e,n){var r=this.getScriptTable(t,n);if(r){if(!e||e==="dflt"||e==="DFLT")return r.defaultLangSys;var a=w4(r.langSysRecords,e);if(a>=0)return r.langSysRecords[a].langSys;if(n){var s={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-a,0,s),s.langSys}}},getFeatureTable:function(t,e,n,r){var a=this.getLangSysTable(t,e,r);if(a){for(var s,c=a.featureIndexes,o=this.font.tables[this.tableName].features,i=0;i<c.length;i++)if(s=o[c[i]],s.tag===n)return s.feature;if(r){var l=o.length;return H1.assert(l===0||n>=o[l-1].tag,"Features must be added in alphabetical order."),s={tag:n,feature:{params:0,lookupListIndexes:[]}},o.push(s),c.push(l),s.feature}}},getLookupTables:function(t,e,n,r,a){var s=this.getFeatureTable(t,e,n,a),c=[];if(s){for(var o,i=s.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<i.length;h++)o=l[i[h]],o.lookupType===r&&c.push(o);if(c.length===0&&a){o={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(o),i.push(u),[o]}}return c},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=C7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=L7(t.glyphs,e);return n>=0?n:-1;case 2:var r=C7(t.ranges,e);return r?r.index+e-r.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,r=0;r<n.length;r++)for(var a=n[r],s=a.start,c=a.end,o=s;o<=c;o++)e.push(o);return e}};function o5(t){c5.call(this,t,"gpos")}o5.prototype=c5.prototype;o5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};o5.prototype.getKerningValue=function(t,e,n){for(var r=0;r<t.length;r++)for(var a=t[r].subtables,s=0;s<a.length;s++){var c=a[s],o=this.getCoverageIndex(c.coverage,e);if(!(o<0))switch(c.posFormat){case 1:for(var i=c.pairSets[o],l=0;l<i.length;l++){var h=i[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(c.classDef1,e),f=this.getGlyphClass(c.classDef2,n),d=c.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};o5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function h2(t){c5.call(this,t,"gsub")}function M9(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}function j4(t,e,n){for(var r=t.subtables,a=0;a<r.length;a++){var s=r[a];if(s.substFormat===e)return s}if(n)return r.push(n),n}h2.prototype=c5.prototype;h2.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};h2.prototype.getSingle=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,1),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++){var i=c[o],l=this.expandCoverage(i.coverage),h=void 0;if(i.substFormat===1){var u=i.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];r.push({sub:f,by:f+u})}}else{var d=i.substitute;for(h=0;h<l.length;h++)r.push({sub:l[h],by:d[h]})}}return r};h2.prototype.getMultiple=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,2),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++){var i=c[o],l=this.expandCoverage(i.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=i.sequences[h];r.push({sub:u,by:f})}}return r};h2.prototype.getAlternates=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,3),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++)for(var i=c[o],l=this.expandCoverage(i.coverage),h=i.alternateSets,u=0;u<l.length;u++)r.push({sub:l[u],by:h[u]});return r};h2.prototype.getLigatures=function(t,e,n){for(var r=[],a=this.getLookupTables(e,n,t,4),s=0;s<a.length;s++)for(var c=a[s].subtables,o=0;o<c.length;o++)for(var i=c[o],l=this.expandCoverage(i.coverage),h=i.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],m=0;m<d.length;m++){var g=d[m];r.push({sub:[f].concat(g.components),by:g.ligGlyph})}return r};h2.prototype.addSingle=function(t,e,n,r){var a=this.getLookupTables(n,r,t,1,!0)[0],s=j4(a,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});H1.assert(s.coverage.format===1,"Single: unable to modify coverage table format "+s.coverage.format);var c=e.sub,o=this.binSearch(s.coverage.glyphs,c);o<0&&(o=-1-o,s.coverage.glyphs.splice(o,0,c),s.substitute.splice(o,0,0)),s.substitute[o]=e.by};h2.prototype.addMultiple=function(t,e,n,r){H1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var a=this.getLookupTables(n,r,t,2,!0)[0],s=j4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});H1.assert(s.coverage.format===1,"Multiple: unable to modify coverage table format "+s.coverage.format);var c=e.sub,o=this.binSearch(s.coverage.glyphs,c);o<0&&(o=-1-o,s.coverage.glyphs.splice(o,0,c),s.sequences.splice(o,0,0)),s.sequences[o]=e.by};h2.prototype.addAlternate=function(t,e,n,r){var a=this.getLookupTables(n,r,t,3,!0)[0],s=j4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});H1.assert(s.coverage.format===1,"Alternate: unable to modify coverage table format "+s.coverage.format);var c=e.sub,o=this.binSearch(s.coverage.glyphs,c);o<0&&(o=-1-o,s.coverage.glyphs.splice(o,0,c),s.alternateSets.splice(o,0,0)),s.alternateSets[o]=e.by};h2.prototype.addLigature=function(t,e,n,r){var a=this.getLookupTables(n,r,t,4,!0)[0],s=a.subtables[0];s||(s={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},a.subtables[0]=s),H1.assert(s.coverage.format===1,"Ligature: unable to modify coverage table format "+s.coverage.format);var c=e.sub[0],o=e.sub.slice(1),i={ligGlyph:e.by,components:o},l=this.binSearch(s.coverage.glyphs,c);if(l>=0){for(var h=s.ligatureSets[l],u=0;u<h.length;u++)if(M9(h[u].components,o))return;h.push(i)}else l=-1-l,s.coverage.glyphs.splice(l,0,c),s.ligatureSets.splice(l,0,[i])};h2.prototype.getFeature=function(t,e,n){if(/ss\d\d/.test(t))return this.getSingle(t,e,n);switch(t){case"aalt":case"salt":return this.getSingle(t,e,n).concat(this.getAlternates(t,e,n));case"dlig":case"liga":case"rlig":return this.getLigatures(t,e,n);case"ccmp":return this.getMultiple(t,e,n).concat(this.getLigatures(t,e,n));case"stch":return this.getMultiple(t,e,n)}};h2.prototype.add=function(t,e,n,r){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,r);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,r):this.addAlternate(t,e,n,r);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,r);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,r):this.addLigature(t,e,n,r)}};function w9(){return typeof window<"u"}function k9(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),r=0;r<e.length;++r)e[r]=n[r];return e}function e5(t,e){if(!t)throw e}function P7(t,e,n,r,a){var s;return(e&r)>0?(s=t.parseByte(),(e&a)===0&&(s=-s),s=n+s):(e&a)>0?s=n:s=n+t.parseShort(),s}function P8(t,e,n){var r=new y1.Parser(e,n);t.numberOfContours=r.parseShort(),t._xMin=r.parseShort(),t._yMin=r.parseShort(),t._xMax=r.parseShort(),t._yMax=r.parseShort();var a,s;if(t.numberOfContours>0){for(var c=t.endPointIndices=[],o=0;o<t.numberOfContours;o+=1)c.push(r.parseUShort());t.instructionLength=r.parseUShort(),t.instructions=[];for(var i=0;i<t.instructionLength;i+=1)t.instructions.push(r.parseByte());var l=c[c.length-1]+1;a=[];for(var h=0;h<l;h+=1)if(s=r.parseByte(),a.push(s),(s&8)>0)for(var u=r.parseByte(),f=0;f<u;f+=1)a.push(s),h+=1;if(H1.argument(a.length===l,"Bad flags."),c.length>0){var d=[],m;if(l>0){for(var g=0;g<l;g+=1)s=a[g],m={},m.onCurve=!!(s&1),m.lastPointOfContour=c.indexOf(g)>=0,d.push(m);for(var p=0,v=0;v<l;v+=1)s=a[v],m=d[v],m.x=P7(r,s,p,2,16),p=m.x;for(var b=0,y=0;y<l;y+=1)s=a[y],m=d[y],m.y=P7(r,s,b,4,32),b=m.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var M=!0;M;){a=r.parseUShort();var w={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(a&1)>0?(a&2)>0?(w.dx=r.parseShort(),w.dy=r.parseShort()):w.matchedPoints=[r.parseUShort(),r.parseUShort()]:(a&2)>0?(w.dx=r.parseChar(),w.dy=r.parseChar()):w.matchedPoints=[r.parseByte(),r.parseByte()],(a&8)>0?w.xScale=w.yScale=r.parseF2Dot14():(a&64)>0?(w.xScale=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()):(a&128)>0&&(w.xScale=r.parseF2Dot14(),w.scale01=r.parseF2Dot14(),w.scale10=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()),t.components.push(w),M=!!(a&32)}if(a&256){t.instructionLength=r.parseUShort(),t.instructions=[];for(var x=0;x<t.instructionLength;x+=1)t.instructions.push(r.parseByte())}}}function k4(t,e){for(var n=[],r=0;r<t.length;r+=1){var a=t[r],s={x:e.xScale*a.x+e.scale01*a.y+e.dx,y:e.scale10*a.x+e.yScale*a.y+e.dy,onCurve:a.onCurve,lastPointOfContour:a.lastPointOfContour};n.push(s)}return n}function z9(t){for(var e=[],n=[],r=0;r<t.length;r+=1){var a=t[r];n.push(a),a.lastPointOfContour&&(e.push(n),n=[])}return H1.argument(n.length===0,"There are still points left in the current contour."),e}function E8(t){var e=new F0;if(!t)return e;for(var n=z9(t),r=0;r<n.length;++r){var a=n[r],s=null,c=a[a.length-1],o=a[0];if(c.onCurve)e.moveTo(c.x,c.y);else if(o.onCurve)e.moveTo(o.x,o.y);else{var i={x:(c.x+o.x)*.5,y:(c.y+o.y)*.5};e.moveTo(i.x,i.y)}for(var l=0;l<a.length;++l)if(s=c,c=o,o=a[(l+1)%a.length],c.onCurve)e.lineTo(c.x,c.y);else{var h=s,u=o;s.onCurve||(h={x:(c.x+s.x)*.5,y:(c.y+s.y)*.5}),o.onCurve||(u={x:(c.x+o.x)*.5,y:(c.y+o.y)*.5}),e.quadraticCurveTo(c.x,c.y,u.x,u.y)}e.closePath()}return e}function T8(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var r=e.components[n],a=t.get(r.glyphIndex);if(a.getPath(),a.points){var s=void 0;if(r.matchedPoints===void 0)s=k4(a.points,r);else{if(r.matchedPoints[0]>e.points.length-1||r.matchedPoints[1]>a.points.length-1)throw Error("Matched points out of range in "+e.name);var c=e.points[r.matchedPoints[0]],o=a.points[r.matchedPoints[1]],i={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};o=k4([o],i)[0],i.dx=c.x-o.x,i.dy=c.y-o.y,s=k4(a.points,i)}e.points=e.points.concat(s)}}return E8(e.points)}function S9(t,e,n,r){for(var a=new q2.GlyphSet(r),s=0;s<n.length-1;s+=1){var c=n[s],o=n[s+1];c!==o?a.push(s,q2.ttfGlyphLoader(r,s,P8,t,e+c,T8)):a.push(s,q2.glyphLoader(r,s))}return a}function A9(t,e,n,r){var a=new q2.GlyphSet(r);return r._push=function(s){var c=n[s],o=n[s+1];c!==o?a.push(s,q2.ttfGlyphLoader(r,s,P8,t,e+c,T8)):a.push(s,q2.glyphLoader(r,s))},a}function L9(t,e,n,r,a){return a.lowMemory?A9(t,e,n,r):S9(t,e,n,r)}var I8={getPath:E8,parse:L9},V8,He,$8,R4;function H8(t){this.font=t,this.getCommands=function(e){return I8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function C9(t){return t}function O8(t){return Math.sign(t)*Math.round(Math.abs(t))}function P9(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function E9(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function T9(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function I9(t){return Math.sign(t)*Math.floor(Math.abs(t))}var R8=function(t){var e=this.srPeriod,n=this.srPhase,r=this.srThreshold,a=1;return t<0&&(t=-t,a=-1),t+=r-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*a:t*a},_2={x:1,y:0,axis:"x",distance:function(t,e,n,r){return(n?t.xo:t.x)-(r?e.xo:e.x)},interpolate:function(t,e,n,r){var a,s,c,o,i,l,h;if(!r||r===this){if(a=t.xo-e.xo,s=t.xo-n.xo,i=e.x-e.xo,l=n.x-n.xo,c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){t.x=t.xo+(i+l)/2;return}t.x=t.xo+(i*o+l*c)/h;return}if(a=r.distance(t,e,!0,!0),s=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){_2.setRelative(t,t,(i+l)/2,r,!0);return}_2.setRelative(t,t,(i*o+l*c)/h,r,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,r,a){if(!r||r===this){t.x=(a?e.xo:e.x)+n;return}var s=a?e.xo:e.x,c=a?e.yo:e.y,o=s+n*r.x,i=c+n*r.y;t.x=o+(t.y-i)/r.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},Z2={x:0,y:1,axis:"y",distance:function(t,e,n,r){return(n?t.yo:t.y)-(r?e.yo:e.y)},interpolate:function(t,e,n,r){var a,s,c,o,i,l,h;if(!r||r===this){if(a=t.yo-e.yo,s=t.yo-n.yo,i=e.y-e.yo,l=n.y-n.yo,c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){t.y=t.yo+(i+l)/2;return}t.y=t.yo+(i*o+l*c)/h;return}if(a=r.distance(t,e,!0,!0),s=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),c=Math.abs(a),o=Math.abs(s),h=c+o,h===0){Z2.setRelative(t,t,(i+l)/2,r,!0);return}Z2.setRelative(t,t,(i*o+l*c)/h,r,!0)},normalSlope:0,setRelative:function(t,e,n,r,a){if(!r||r===this){t.y=(a?e.yo:e.y)+n;return}var s=a?e.xo:e.x,c=a?e.yo:e.y,o=s+n*r.x,i=c+n*r.y;t.y=i+r.normalSlope*(t.x-o)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(_2);Object.freeze(Z2);function i5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}i5.prototype.distance=function(t,e,n,r){return this.x*_2.distance(t,e,n,r)+this.y*Z2.distance(t,e,n,r)};i5.prototype.interpolate=function(t,e,n,r){var a,s,c,o,i,l,h;if(c=r.distance(t,e,!0,!0),o=r.distance(t,n,!0,!0),a=r.distance(e,e,!1,!0),s=r.distance(n,n,!1,!0),i=Math.abs(c),l=Math.abs(o),h=i+l,h===0){this.setRelative(t,t,(a+s)/2,r,!0);return}this.setRelative(t,t,(a*l+s*i)/h,r,!0)};i5.prototype.setRelative=function(t,e,n,r,a){r=r||this;var s=a?e.xo:e.x,c=a?e.yo:e.y,o=s+n*r.x,i=c+n*r.y,l=r.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*o+i-f)/(h-l),t.y=h*(t.x-u)+f};i5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function l5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?_2:t===0&&e===1?Z2:new i5(t,e)}function Y2(t,e,n,r){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=r,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}Y2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};Y2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var s5=Object.freeze(new Y2(0,0)),V9={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function de(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=_2,this.round=O8}}H8.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,r=this._prepState;if(!r||r.ppem!==e){var a=this._fpgmState;if(!a){de.prototype=V9,a=this._fpgmState=new de("fpgm",n.tables.fpgm),a.funcs=[],a.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),a.step=-1);try{He(a)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}de.prototype=a,r=this._prepState=new de("prep",n.tables.prep),r.ppem=e;var s=n.tables.cvt;if(s)for(var c=r.cvt=new Array(s.length),o=e/n.unitsPerEm,i=0;i<s.length;i++)c[i]=s[i]*o;else r.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),r.step=-1);try{He(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return $8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};$8=function(t,e){var n=e.ppem/e.font.unitsPerEm,r=n,a=t.components,s,c,o;if(de.prototype=e,!a)o=new de("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),o.step=-1),R4(t,o,n,r),c=o.gZone;else{var i=e.font;c=[],s=[];for(var l=0;l<a.length;l++){var h=a[l],u=i.glyphs.get(h.glyphIndex);o=new de("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),o.step=-1),R4(u,o,n,r);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*r),m=o.gZone,g=o.contours,p=0;p<m.length;p++){var v=m[p];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var b=c.length;c.push.apply(c,m);for(var y=0;y<g.length;y++)s.push(g[y]+b)}t.instructions&&!o.inhibitGridFit&&(o=new de("glyf",t.instructions),o.gZone=o.z0=o.z1=o.z2=c,o.contours=s,c.push(new Y2(0,0),new Y2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),o.step=-1),He(o),c.length-=2)}return c};R4=function(t,e,n,r){for(var a=t.points||[],s=a.length,c=e.gZone=e.z0=e.z1=e.z2=[],o=e.contours=[],i,l=0;l<s;l++)i=a[l],c[l]=new Y2(i.x*n,i.y*r,i.lastPointOfContour,i.onCurve);for(var h,u,f=0;f<s;f++)i=c[f],h||(h=i,o.push(f)),i.lastPointOfContour?(i.nextPointOnContour=h,h.prevPointOnContour=i,h=void 0):(u=c[f+1],i.nextPointOnContour=u,u.prevPointOnContour=i);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<s;d++)console.log(d,c[d].x,c[d].y)}if(c.push(new Y2(0,0),new Y2(Math.round(t.advanceWidth*n),0)),He(e),c.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<s;m++)console.log(m,c[m].x,c[m].y)}}};He=function(t){var e=t.prog;if(e){var n=e.length,r;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,r=V8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function it(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new Y2(0,0)}function F8(t,e){var n=t.prog,r=t.ip,a=1,s;do if(s=n[++r],s===88)a++;else if(s===89)a--;else if(s===64)r+=n[r+1]+1;else if(s===65)r+=2*n[r+1]+1;else if(s>=176&&s<=183)r+=s-176+1;else if(s>=184&&s<=191)r+=(s-184+1)*2;else if(e&&a===1&&s===27)break;while(a>0);t.ip=r}function E7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function T7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function I7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function V7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z2[r],c=e.z1[a];exports.DEBUG&&console.log("SPVTL["+t+"]",r,a);var o,i;t?(o=s.y-c.y,i=c.x-s.x):(o=c.x-s.x,i=c.y-s.y),e.pv=e.dpv=l5(o,i)}function $7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z2[r],c=e.z1[a];exports.DEBUG&&console.log("SFVTL["+t+"]",r,a);var o,i;t?(o=s.y-c.y,i=c.x-s.x):(o=c.x-s.x,i=c.y-s.y),e.fv=l5(o,i)}function $9(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.pv=t.dpv=l5(r,n)}function H9(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.fv=l5(r,n)}function O9(t){var e=t.stack,n=t.pv;exports.DEBUG&&console.log(t.step,"GPV[]"),e.push(n.x*16384),e.push(n.y*16384)}function R9(t){var e=t.stack,n=t.fv;exports.DEBUG&&console.log(t.step,"GFV[]"),e.push(n.x*16384),e.push(n.y*16384)}function F9(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function _9(t){var e=t.stack,n=e.pop(),r=e.pop(),a=e.pop(),s=e.pop(),c=e.pop(),o=t.z0,i=t.z1,l=o[n],h=o[r],u=i[a],f=i[s],d=t.z2[c];exports.DEBUG&&console.log("ISECT[], ",n,r,a,s,c);var m=l.x,g=l.y,p=h.x,v=h.y,b=u.x,y=u.y,M=f.x,w=f.y,x=(m-p)*(y-w)-(g-v)*(b-M),k=m*v-g*p,A=b*w-y*M;d.x=(k*(b-M)-A*(m-p))/x,d.y=(k*(y-w)-A*(g-v))/x}function q9(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function D9(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function N9(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function U9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||it(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function B9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||it(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function j9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||it(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function G9(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZPS[]",e),t.zp0=t.zp1=t.zp2=e,e){case 0:t.tZone||it(t),t.z0=t.z1=t.z2=t.tZone;break;case 1:t.z0=t.z1=t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function W9(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function X9(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=O8}function Z9(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=E9}function Y9(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function K9(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),F8(t,!1)}function J9(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Q9(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function eo(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function z4(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function to(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function no(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(r)}function ro(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function ao(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,r);var a=t.ip,s=t.prog;t.prog=t.funcs[n];for(var c=0;c<r;c++)He(t),exports.DEBUG&&console.log(++t.step,c+1<r?"next loopcall":"done loopcall",c);t.ip=a,t.prog=s}function so(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,r=t.prog;t.prog=t.funcs[e],He(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function co(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function oo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"MINDEX[]",n),e.push(e.splice(e.length-n,1)[0])}function io(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,r=t.ip,a=e.pop(),s=r;for(exports.DEBUG&&console.log(t.step,"FDEF[]",a);n[++r]!==45;);t.ip=r,t.funcs[a]=n.slice(s+1,r)}function H7(t,e){var n=e.stack.pop(),r=e.z0[n],a=e.fv,s=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var c=s.distance(r,s5);t&&(c=e.round(c)),a.setRelative(r,s5,c,s),a.touch(r),e.rp0=e.rp1=n}function O7(t,e){var n=e.z2,r=n.length-2,a,s,c;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var o=0;o<r;o++)a=n[o],!t.touched(a)&&(s=a.prevTouched(t),s!==a&&(c=a.nextTouched(t),s===c&&t.setRelative(a,a,t.distance(s,s,!1,!0),t,!0),t.interpolate(a,s,c,t)))}function R7(t,e){for(var n=e.stack,r=t?e.rp1:e.rp2,a=(t?e.z0:e.z1)[r],s=e.fv,c=e.pv,o=e.loop,i=e.z2;o--;){var l=n.pop(),h=i[l],u=c.distance(a,a,!1,!0);s.setRelative(h,h,u,c),s.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-o)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function F7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,a=(t?e.z0:e.z1)[r],s=e.fv,c=e.pv,o=n.pop(),i=e.z2[e.contours[o]],l=i;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",o);var h=c.distance(a,a,!1,!0);do l!==a&&s.setRelative(l,l,h,c),l=l.nextPointOnContour;while(l!==i)}function _7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,a=(t?e.z0:e.z1)[r],s=e.fv,c=e.pv,o=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",o);var i;switch(o){case 0:i=e.tZone;break;case 1:i=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=c.distance(a,a,!1,!0),u=i.length-2,f=0;f<u;f++)l=i[f],s.setRelative(l,l,h,c)}function lo(t){for(var e=t.stack,n=t.loop,r=t.fv,a=e.pop()/64,s=t.z2;n--;){var c=e.pop(),o=s[c];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",c,a),r.setRelative(o,o,a),r.touch(o)}t.loop=1}function ho(t){for(var e=t.stack,n=t.rp1,r=t.rp2,a=t.loop,s=t.z0[n],c=t.z1[r],o=t.fv,i=t.dpv,l=t.z2;a--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-a)+": ":"")+"IP[]",h,n,"<->",r),o.interpolate(u,s,c,i),o.touch(u)}t.loop=1}function q7(t,e){var n=e.stack,r=n.pop()/64,a=n.pop(),s=e.z1[a],c=e.z0[e.rp0],o=e.fv,i=e.pv;o.setRelative(s,c,r,i),o.touch(s),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",r,a),e.rp1=e.rp0,e.rp2=a,t&&(e.rp0=a)}function uo(t){for(var e=t.stack,n=t.rp0,r=t.z0[n],a=t.loop,s=t.fv,c=t.pv,o=t.z1;a--;){var i=e.pop(),l=o[i];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-a)+": ":"")+"ALIGNRP[]",i),s.setRelative(l,r,0,c),s.touch(l)}t.loop=1}function fo(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=P9}function D7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z0[a],c=e.fv,o=e.pv,i=e.cvt[r];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",r,"(",i,")",a);var l=o.distance(s,s5);t&&(Math.abs(l-i)<e.cvCutIn&&(l=i),l=e.round(l)),c.setRelative(s,s5,l,o),e.zp0===0&&(s.xo=s.x,s.yo=s.y),c.touch(s),e.rp0=e.rp1=a}function mo(t){var e=t.prog,n=t.ip,r=t.stack,a=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",a);for(var s=0;s<a;s++)r.push(e[++n]);t.ip=n}function po(t){var e=t.ip,n=t.prog,r=t.stack,a=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",a);for(var s=0;s<a;s++){var c=n[++e]<<8|n[++e];c&32768&&(c=-((c^65535)+1)),r.push(c)}t.ip=e}function go(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var r=e.pop(),a=e.pop();exports.DEBUG&&console.log(t.step,"WS",r,a),n[a]=r}function vo(t){var e=t.stack,n=t.store,r=e.pop();exports.DEBUG&&console.log(t.step,"RS",r);var a=n&&n[r]||0;e.push(a)}function bo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,r),t.cvt[r]=n/64}function yo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function N7(t,e){var n=e.stack,r=n.pop(),a=e.z2[r];exports.DEBUG&&console.log(e.step,"GC["+t+"]",r),n.push(e.dpv.distance(a,s5,t,!1)*64)}function U7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z1[r],c=e.z0[a],o=e.dpv.distance(c,s,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",r,a,"->",o),e.stack.push(Math.round(o*64))}function xo(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Mo(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function wo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,r),e.push(r<n?1:0)}function ko(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,r),e.push(r<=n?1:0)}function zo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,r),e.push(r>n?1:0)}function So(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,r),e.push(r>=n?1:0)}function Ao(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,r),e.push(n===r?1:0)}function Lo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,r),e.push(n!==r?1:0)}function Co(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ODD[]",n),e.push(Math.trunc(n)%2?1:0)}function Po(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"EVEN[]",n),e.push(Math.trunc(n)%2?0:1)}function Eo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(F8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function To(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function Io(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,r),e.push(n&&r?1:0)}function Vo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,r),e.push(n||r?1:0)}function $o(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function S4(t,e){var n=e.stack,r=n.pop(),a=e.fv,s=e.pv,c=e.ppem,o=e.deltaBase+(t-1)*16,i=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",r,n);for(var h=0;h<r;h++){var u=n.pop(),f=n.pop(),d=o+((f&240)>>4);if(d===c){var m=(f&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",m*i);var g=l[u];a.setRelative(g,g,m*i,s)}}}function Ho(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function Oo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function Ro(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,r),e.push(r+n)}function Fo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,r),e.push(r-n)}function _o(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,r),e.push(r*64/n)}function qo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,r),e.push(r*n/64)}function Do(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function No(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function Uo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function Bo(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function Q5(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function jo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,r),t.cvt[r]=n*t.ppem/t.font.unitsPerEm}function A4(t,e){var n=e.stack,r=n.pop(),a=e.ppem,s=e.deltaBase+(t-1)*16,c=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",r,n);for(var o=0;o<r;o++){var i=n.pop(),l=n.pop(),h=s+((l&240)>>4);if(h===a){var u=(l&15)-8;u>=0&&u++;var f=u*c;exports.DEBUG&&console.log(e.step,"DELTACFIX",i,"by",f),e.cvt[i]+=f}}}function Go(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=R8;var n;switch(e&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw new Error("invalid SROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Wo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=R8;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Xo(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=C9}function Zo(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=T9}function Yo(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=I9}function Ko(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function B7(t,e){var n=e.stack,r=n.pop(),a=n.pop(),s=e.z2[r],c=e.z1[a];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",r,a);var o,i;t?(o=s.y-c.y,i=c.x-s.x):(o=c.x-s.x,i=c.y-s.y),e.dpv=l5(o,i)}function Jo(t){var e=t.stack,n=e.pop(),r=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(r=35),n&32&&(r|=4096),e.push(r)}function Qo(t){var e=t.stack,n=e.pop(),r=e.pop(),a=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(r),e.push(n),e.push(a)}function ei(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,r),e.push(Math.max(r,n))}function ti(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,r),e.push(Math.min(r,n))}function ni(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function ri(t){var e=t.stack.pop(),n=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"INSTCTRL[]",e,n),e){case 1:t.inhibitGridFit=!!n;return;case 2:t.ignoreCvt=!!n;return;default:throw new Error("invalid INSTCTRL[] selector")}}function he(t,e){var n=e.stack,r=e.prog,a=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var s=0;s<t;s++)n.push(r[++a]);e.ip=a}function ue(t,e){var n=e.ip,r=e.prog,a=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var s=0;s<t;s++){var c=r[++n]<<8|r[++n];c&32768&&(c=-((c^65535)+1)),a.push(c)}e.ip=n}function g1(t,e,n,r,a,s){var c=s.stack,o=t&&c.pop(),i=c.pop(),l=s.rp0,h=s.z0[l],u=s.z1[i],f=s.minDis,d=s.fv,m=s.dpv,g,p,v,b;p=g=m.distance(u,h,!0,!0),v=p>=0?1:-1,p=Math.abs(p),t&&(b=s.cvt[o],r&&Math.abs(p-b)<s.cvCutIn&&(p=b)),n&&p<f&&(p=f),r&&(p=s.round(p)),d.setRelative(u,h,v*p,m),d.touch(u),exports.DEBUG&&console.log(s.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(r?"R":"_")+(a===0?"Gr":a===1?"Bl":a===2?"Wh":"")+"]",t?o+"("+s.cvt[o]+","+b+")":"",i,"(d =",g,"->",v*p,")"),s.rp1=s.rp0,s.rp2=i,e&&(s.rp0=i)}V8=[E7.bind(void 0,Z2),E7.bind(void 0,_2),T7.bind(void 0,Z2),T7.bind(void 0,_2),I7.bind(void 0,Z2),I7.bind(void 0,_2),V7.bind(void 0,0),V7.bind(void 0,1),$7.bind(void 0,0),$7.bind(void 0,1),$9,H9,O9,R9,F9,_9,q9,D9,N9,U9,B9,j9,G9,W9,X9,Z9,Y9,K9,J9,Q9,void 0,void 0,eo,z4,to,no,ro,co,oo,void 0,void 0,void 0,ao,so,io,void 0,H7.bind(void 0,0),H7.bind(void 0,1),O7.bind(void 0,Z2),O7.bind(void 0,_2),R7.bind(void 0,0),R7.bind(void 0,1),F7.bind(void 0,0),F7.bind(void 0,1),_7.bind(void 0,0),_7.bind(void 0,1),lo,ho,q7.bind(void 0,0),q7.bind(void 0,1),uo,fo,D7.bind(void 0,0),D7.bind(void 0,1),mo,po,go,vo,bo,yo,N7.bind(void 0,0),N7.bind(void 0,1),void 0,U7.bind(void 0,0),U7.bind(void 0,1),xo,void 0,Mo,void 0,void 0,wo,ko,zo,So,Ao,Lo,Co,Po,Eo,To,Io,Vo,$o,S4.bind(void 0,1),Ho,Oo,Ro,Fo,_o,qo,Do,No,Uo,Bo,Q5.bind(void 0,0),Q5.bind(void 0,1),Q5.bind(void 0,2),Q5.bind(void 0,3),void 0,void 0,void 0,void 0,jo,S4.bind(void 0,2),S4.bind(void 0,3),A4.bind(void 0,1),A4.bind(void 0,2),A4.bind(void 0,3),Go,Wo,void 0,void 0,Xo,void 0,Zo,Yo,z4,z4,void 0,void 0,void 0,void 0,void 0,Ko,B7.bind(void 0,0),B7.bind(void 0,1),Jo,void 0,Qo,ei,ti,ni,ri,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,he.bind(void 0,1),he.bind(void 0,2),he.bind(void 0,3),he.bind(void 0,4),he.bind(void 0,5),he.bind(void 0,6),he.bind(void 0,7),he.bind(void 0,8),ue.bind(void 0,1),ue.bind(void 0,2),ue.bind(void 0,3),ue.bind(void 0,4),ue.bind(void 0,5),ue.bind(void 0,6),ue.bind(void 0,7),ue.bind(void 0,8),g1.bind(void 0,0,0,0,0,0),g1.bind(void 0,0,0,0,0,1),g1.bind(void 0,0,0,0,0,2),g1.bind(void 0,0,0,0,0,3),g1.bind(void 0,0,0,0,1,0),g1.bind(void 0,0,0,0,1,1),g1.bind(void 0,0,0,0,1,2),g1.bind(void 0,0,0,0,1,3),g1.bind(void 0,0,0,1,0,0),g1.bind(void 0,0,0,1,0,1),g1.bind(void 0,0,0,1,0,2),g1.bind(void 0,0,0,1,0,3),g1.bind(void 0,0,0,1,1,0),g1.bind(void 0,0,0,1,1,1),g1.bind(void 0,0,0,1,1,2),g1.bind(void 0,0,0,1,1,3),g1.bind(void 0,0,1,0,0,0),g1.bind(void 0,0,1,0,0,1),g1.bind(void 0,0,1,0,0,2),g1.bind(void 0,0,1,0,0,3),g1.bind(void 0,0,1,0,1,0),g1.bind(void 0,0,1,0,1,1),g1.bind(void 0,0,1,0,1,2),g1.bind(void 0,0,1,0,1,3),g1.bind(void 0,0,1,1,0,0),g1.bind(void 0,0,1,1,0,1),g1.bind(void 0,0,1,1,0,2),g1.bind(void 0,0,1,1,0,3),g1.bind(void 0,0,1,1,1,0),g1.bind(void 0,0,1,1,1,1),g1.bind(void 0,0,1,1,1,2),g1.bind(void 0,0,1,1,1,3),g1.bind(void 0,1,0,0,0,0),g1.bind(void 0,1,0,0,0,1),g1.bind(void 0,1,0,0,0,2),g1.bind(void 0,1,0,0,0,3),g1.bind(void 0,1,0,0,1,0),g1.bind(void 0,1,0,0,1,1),g1.bind(void 0,1,0,0,1,2),g1.bind(void 0,1,0,0,1,3),g1.bind(void 0,1,0,1,0,0),g1.bind(void 0,1,0,1,0,1),g1.bind(void 0,1,0,1,0,2),g1.bind(void 0,1,0,1,0,3),g1.bind(void 0,1,0,1,1,0),g1.bind(void 0,1,0,1,1,1),g1.bind(void 0,1,0,1,1,2),g1.bind(void 0,1,0,1,1,3),g1.bind(void 0,1,1,0,0,0),g1.bind(void 0,1,1,0,0,1),g1.bind(void 0,1,1,0,0,2),g1.bind(void 0,1,1,0,0,3),g1.bind(void 0,1,1,0,1,0),g1.bind(void 0,1,1,0,1,1),g1.bind(void 0,1,1,0,1,2),g1.bind(void 0,1,1,0,1,3),g1.bind(void 0,1,1,1,0,0),g1.bind(void 0,1,1,1,0,1),g1.bind(void 0,1,1,1,0,2),g1.bind(void 0,1,1,1,0,3),g1.bind(void 0,1,1,1,1,0),g1.bind(void 0,1,1,1,1,1),g1.bind(void 0,1,1,1,1,2),g1.bind(void 0,1,1,1,1,3)];function u3(t){this.char=t,this.state={},this.activeState=null}function G4(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function ai(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function w2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function lt(t){this.eventId=t,this.subscribers=[]}function si(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(a){Object.defineProperty(e.events,a,{value:new lt(a)})}),t&&n.forEach(function(a){var s=t[a];typeof s=="function"&&e.events[a].subscribe(s)});var r=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];r.forEach(function(a){e.events[a].subscribe(e.updateContextsRanges)})}function C0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],si.call(this,t)}u3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};u3.prototype.getState=function(t){return this.state[t]||null};C0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};C0.prototype.composeRUD=function(t){var e=this,n=!0,r=t.map(function(s){return e[s[0]].apply(e,s.slice(1).concat(n))}),a=function(s){return typeof s=="object"&&s.hasOwnProperty("FAIL")};if(r.every(a))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:r.filter(a)};this.dispatch("composeRUD",[r.filter(function(s){return!a(s)})])};C0.prototype.replaceRange=function(t,e,n,r){e=e!==null?e:this.tokens.length;var a=n.every(function(c){return c instanceof u3});if(!isNaN(t)&&this.inboundIndex(t)&&a){var s=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return r||this.dispatch("replaceToken",[t,e,n]),[s,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};C0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof u3){var r=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[r[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};C0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var r=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[r,t,e]),r};C0.prototype.removeToken=function(t,e){if(!isNaN(t)&&this.inboundIndex(t)){var n=this.tokens.splice(t,1);return e||this.dispatch("removeToken",[n,t]),n}else return{FAIL:"removeToken: invalid token index."}};C0.prototype.insertToken=function(t,e,n){var r=t.every(function(a){return a instanceof u3});return r?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};C0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(r,a){var s=[r,a],c=e===null||e.apply(this,s)===!0,o=[r,a];if(c){var i=n.apply(this,o);r.setState(t,i)}}),this.registeredModifiers.push(t)};lt.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};lt.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};w2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};w2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};C0.prototype.rangeToText=function(t){if(t instanceof G4)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};C0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};C0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};C0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};C0.prototype.dispatch=function(t,e){var n=this,r=this.events[t];r instanceof lt&&r.subscribers.forEach(function(a){a.apply(n,e||[])})};C0.prototype.registerContextChecker=function(t,e,n){if(this.getContext(t))return{FAIL:"context name '"+t+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof n!="function")return{FAIL:"missing context end check."};var r=new ai(t,e,n);return this.registeredContexts[t]=r,this.contextCheckers.push(r),r};C0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};C0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};C0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};C0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(r){return r.char}),e=0;e<t.length;e++){var n=new w2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};C0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,r=new G4(n,t,e),a=this.getContext(e).ranges;return r.rangeId=e+"."+a.length,a.push(r),this.getContext(e).openRange=null,r};C0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(r){var a=r.contextName,s=e.getContext(a).openRange;if(!s&&r.checkStart(t)&&(s=new G4(n,null,a),e.getContext(a).openRange=s,e.dispatch("contextStart",[a,n])),s&&r.checkEnd(t)){var c=n-s.startIndex+1,o=e.setEndOffset(c,a);e.dispatch("contextEnd",[a,o])}})};C0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var r=e[n],a=new w2(e,n);this.dispatch("next",[a]),this.runContextCheck(a);var s=new u3(r);this.tokens.push(s),this.dispatch("newToken",[s,a])}return this.dispatch("end",[this.tokens]),this.tokens};function me(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function _8(t){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(t)}function pe(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function tt(t){return/[A-z]/.test(t)}function ci(t){return/\s/.test(t)}function u2(t){this.font=t,this.features={}}function $e(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function h5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,r=0;r<n.length;r++){var a=n[r];if(t>=a.start&&t<=a.end){var s=t-a.start;return a.index+s}}break;default:return-1}return-1}function oi(t,e){var n=h5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function ii(t,e){var n=h5(t,e.coverage);return n===-1?null:e.substitute[n]}function L4(t,e){for(var n=[],r=0;r<t.length;r++){var a=t[r],s=e.current;s=Array.isArray(s)?s[0]:s;var c=h5(s,a);c!==-1&&n.push(c)}return n.length!==t.length?-1:n}function li(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=L4(e.inputCoverage,t);if(r===-1)return[];var a=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var s=t.lookahead.slice(a);s.length&&pe(s[0].char);)s.shift();var c=new w2(s,0),o=L4(e.lookaheadCoverage,c),i=[].concat(t.backtrack);for(i.reverse();i.length&&pe(i[0].char);)i.shift();if(i.length<e.backtrackCoverage.length)return[];var l=new w2(i,0),h=L4(e.backtrackCoverage,l),u=r.length===e.inputCoverage.length&&o.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var m=e.lookupRecords[d],g=m.lookupListIndex,p=this.getLookupByIndex(g),v=0;v<p.subtables.length;v++){var b=p.subtables[v],y=this.getLookupMethod(p,b),M=this.getSubstitutionType(p,b);if(M==="12")for(var w=0;w<r.length;w++){var x=t.get(w),k=y(x);k&&f.push(k)}}return f}function hi(t,e){var n=t.current,r=h5(n,e.coverage);if(r===-1)return null;for(var a,s=e.ligatureSets[r],c=0;c<s.length;c++){a=s[c];for(var o=0;o<a.components.length;o++){var i=t.lookahead[o],l=a.components[o];if(i!==l)break;if(o===a.components.length-1)return a}}return null}function ui(t,e){var n=h5(t,e.coverage);return n===-1?null:e.sequences[n]}u2.prototype.getDefaultScriptFeaturesIndexes=function(){for(var t=this.font.tables.gsub.scripts,e=0;e<t.length;e++){var n=t[e];if(n.tag==="DFLT")return n.script.defaultLangSys.featureIndexes}return[]};u2.prototype.getScriptFeaturesIndexes=function(t){var e=this.font.tables;if(!e.gsub)return[];if(!t)return this.getDefaultScriptFeaturesIndexes();for(var n=this.font.tables.gsub.scripts,r=0;r<n.length;r++){var a=n[r];if(a.tag===t&&a.script.defaultLangSys)return a.script.defaultLangSys.featureIndexes;var s=a.langSysRecords;if(s)for(var c=0;c<s.length;c++){var o=s[c];if(o.tag===t){var i=o.langSys;return i.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};u2.prototype.mapTagsToFeatures=function(t,e){for(var n={},r=0;r<t.length;r++){var a=t[r].tag,s=t[r].feature;n[a]=s}this.features[e].tags=n};u2.prototype.getScriptFeatures=function(t){var e=this.features[t];if(this.features.hasOwnProperty(t))return e;var n=this.getScriptFeaturesIndexes(t);if(!n)return null;var r=this.font.tables.gsub;return e=n.map(function(a){return r.features[a]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};u2.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),r=e.substFormat.toString();return n+r};u2.prototype.getLookupMethod=function(t,e){var n=this,r=this.getSubstitutionType(t,e);switch(r){case"11":return function(a){return oi.apply(n,[a,e])};case"12":return function(a){return ii.apply(n,[a,e])};case"63":return function(a){return li.apply(n,[a,e])};case"41":return function(a){return hi.apply(n,[a,e])};case"21":return function(a){return ui.apply(n,[a,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};u2.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,r=this.getFeature({tag:t.tag,script:t.script});if(!r)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var a=this.getFeatureLookups(r),s=[].concat(e.context),c=0;c<a.length;c++)for(var o=a[c],i=this.getLookupSubtables(o),l=0;l<i.length;l++){var h=i[l],u=this.getSubstitutionType(o,h),f=this.getLookupMethod(o,h),d=void 0;switch(u){case"11":d=f(e.current),d&&s.splice(n,1,new $e({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&s.splice(n,1,new $e({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&s.splice(n,1,new $e({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&s.splice(n,1,new $e({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&s.splice(n,1,new $e({id:21,tag:t.tag,substitution:d}));break}e=new w2(s,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return s.length?s:null};u2.prototype.supports=function(t){if(!t.script)return!1;this.getScriptFeatures(t.script);var e=this.features.hasOwnProperty(t.script);if(!t.tag)return e;var n=this.features[t.script].some(function(r){return r.tag===t.tag});return e&&n};u2.prototype.getLookupSubtables=function(t){return t.subtables||null};u2.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};u2.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};u2.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var n=this.features[e.script];return n?n.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function fi(t){var e=t.current,n=t.get(-1);return n===null&&me(e)||!me(n)&&me(e)}function di(t){var e=t.get(1);return e===null||!me(e)}var mi={startCheck:fi,endCheck:di};function pi(t){var e=t.current,n=t.get(-1);return(me(e)||pe(e))&&!me(n)}function gi(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!me(e)&&!pe(e)):var n=ci(e);if(!n)return!0;if(n){var r=!1;if(r=t.lookahead.some(function(a){return me(a)||pe(a)}),!r)return!0}break;default:return!1}}var vi={startCheck:pi,endCheck:gi};function bi(t,e,n){e[n].setState(t.tag,t.substitution)}function yi(t,e,n){e[n].setState(t.tag,t.substitution)}function xi(t,e,n){t.substitution.forEach(function(r,a){var s=e[n+a];s.setState(t.tag,r)})}function Mi(t,e,n){var r=e[n];r.setState(t.tag,t.substitution.ligGlyph);for(var a=t.substitution.components.length,s=0;s<a;s++)r=e[n+s+1],r.setState("deleted",!0)}var j7={11:bi,12:yi,63:xi,41:Mi};function W4(t,e,n){t instanceof $e&&j7[t.id]&&j7[t.id](t,e,n)}function wi(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],a=_8(r),s=pe(r);if(!a&&!s)return!0;if(a)return!1}return!1}function ki(t){if(_8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],r=pe(n);if(!r)return!0}return!1}function zi(t){var e=this,n="arab",r=this.featuresTags[n],a=this.tokenizer.getRangeTokens(t);if(a.length!==1){var s=new w2(a.map(function(o){return o.getState("glyphIndex")}),0),c=new w2(a.map(function(o){return o.char}),0);a.forEach(function(o,i){if(!pe(o.char)){s.setCurrentIndex(i),c.setCurrentIndex(i);var l=0;wi(c)&&(l|=1),ki(c)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(r.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:s});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof $e&&(W4(f,a,d),s.context[d]=f.substitution)})}}})}}function G7(t,e){var n=t.map(function(r){return r.activeState.value});return new w2(n,e||0)}function Si(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),a=G7(r);a.context.forEach(function(s,c){a.setCurrentIndex(c);var o=e.query.lookupFeature({tag:"rlig",script:n,contextParams:a});o.length&&(o.forEach(function(i){return W4(i,r,c)}),a=G7(r))})}function Ai(t){var e=t.current,n=t.get(-1);return n===null&&tt(e)||!tt(n)&&tt(e)}function Li(t){var e=t.get(1);return e===null||!tt(e)}var Ci={startCheck:Ai,endCheck:Li};function W7(t,e){var n=t.map(function(r){return r.activeState.value});return new w2(n,e||0)}function Pi(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),a=W7(r);a.context.forEach(function(s,c){a.setCurrentIndex(c);var o=e.query.lookupFeature({tag:"liga",script:n,contextParams:a});o.length&&(o.forEach(function(i){return W4(i,r,c)}),a=W7(r))})}function S2(t){this.baseDir=t||"ltr",this.tokenizer=new C0,this.featuresTags={}}S2.prototype.setText=function(t){this.text=t};S2.prototype.contextChecks={latinWordCheck:Ci,arabicWordCheck:mi,arabicSentenceCheck:vi};function C4(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function Ei(){return C4.call(this,"latinWord"),C4.call(this,"arabicWord"),C4.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Ti(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var r=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,r.reverse())})}S2.prototype.registerFeatures=function(t,e){var n=this,r=e.filter(function(a){return n.query.supports({script:t,tag:a})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(r):this.featuresTags[t]=r};S2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new u2(t));for(var n=0;n<e.length;n++){var r=e[n];this.query.supports({script:r.script})&&this.registerFeatures(r.script,r.tags)}};S2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function X4(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Ii(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){X4.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){zi.call(t,r)})}}function Vi(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){X4.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(a){Si.call(t,a)})}}}function $i(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){X4.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(a){Pi.call(t,a)})}}}S2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};S2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Ii.call(this),Vi.call(this)),this.checkContextReady("latinWord")&&$i.call(this),this.checkContextReady("arabicSentence")&&Ti.call(this)};S2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),Ei.call(this),this.applyFeaturesToContexts())};S2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};S2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var r=this.tokenizer.tokens[n];if(!r.state.deleted){var a=r.activeState.value;e.push(Array.isArray(a)?a[0]:a)}}return e};function p0(t){t=t||{},t.tables=t.tables||{},t.empty||(e5(t.familyName,"When creating a new Font object, familyName is required."),e5(t.styleName,"When creating a new Font object, styleName is required."),e5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),e5(t.ascender,"When creating a new Font object, ascender is required."),e5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new q2.GlyphSet(this,t.glyphs||[]),this.encoding=new a8(this),this.position=new o5(this),this.substitution=new h2(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new H8(this)}})}p0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};p0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};p0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};p0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};p0.prototype.stringToGlyphs=function(t,e){var n=this,r=new S2,a=function(u){return n.charToGlyphIndex(u.char)};r.registerModifier("glyphIndex",null,a);var s=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;r.applyFeatures(this,s);for(var c=r.getTextGlyphs(t),o=c.length,i=new Array(o),l=this.glyphs.get(0),h=0;h<o;h+=1)i[h]=this.glyphs.get(c[h])||l;return i};p0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};p0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};p0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};p0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};p0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};p0.prototype.forEachGlyph=function(t,e,n,r,a,s){e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:72,a=Object.assign({},this.defaultRenderOptions,a);var c=1/this.unitsPerEm*r,o=this.stringToGlyphs(t,a),i;if(a.kerning){var l=a.script||this.position.getDefaultScriptName();i=this.position.getKerningTables(l,a.language)}for(var h=0;h<o.length;h+=1){var u=o[h];if(s.call(this,u,e,n,r,a),u.advanceWidth&&(e+=u.advanceWidth*c),a.kerning&&h<o.length-1){var f=i?this.position.getKerningValue(i,u.index,o[h+1].index):this.getKerningValue(u,o[h+1]);e+=f*c}a.letterSpacing?e+=a.letterSpacing*r:a.tracking&&(e+=a.tracking/1e3*r)}return e};p0.prototype.getPath=function(t,e,n,r,a){var s=new F0;return this.forEachGlyph(t,e,n,r,a,function(c,o,i,l){var h=c.getPath(o,i,l,a,this);s.extend(h)}),s};p0.prototype.getPaths=function(t,e,n,r,a){var s=[];return this.forEachGlyph(t,e,n,r,a,function(c,o,i,l){var h=c.getPath(o,i,l,a,this);s.push(h)}),s};p0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};p0.prototype.draw=function(t,e,n,r,a,s){this.getPath(e,n,r,a,s).draw(t)};p0.prototype.drawPoints=function(t,e,n,r,a,s){this.forEachGlyph(e,n,r,a,s,function(c,o,i,l){c.drawPoints(t,o,i,l)})};p0.prototype.drawMetrics=function(t,e,n,r,a,s){this.forEachGlyph(e,n,r,a,s,function(c,o,i,l){c.drawMetrics(t,o,i,l)})};p0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};p0.prototype.validate=function(){var t=this;function e(r,a){}function n(r){var a=t.getEnglishName(r);a&&a.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};p0.prototype.toTables=function(){return x9.fontToTable(this)};p0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};p0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),r=new Uint8Array(n),a=0;a<e.length;a++)r[a]=e[a];return n};p0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var r=this.toArrayBuffer();if(w9())if(window.URL=window.URL||window.webkitURL,window.URL){var a=new DataView(r),s=new Blob([a],{type:"font/opentype"}),c=document.createElement("a");c.href=window.URL.createObjectURL(s),c.download=t;var o=document.createEvent("MouseEvents");o.initEvent("click",!0,!1),c.dispatchEvent(o)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var i=l7(),l=k9(r);i.writeFileSync(t,l)}};p0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};p0.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};p0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function q8(t,e){var n=JSON.stringify(t),r=256;for(var a in e){var s=parseInt(a);if(!(!s||s<256)){if(JSON.stringify(e[a])===n)return s;r<=s&&(r=s+1)}}return e[r]=t,r}function Hi(t,e,n){var r=q8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:r}]}function Oi(t,e,n){var r={},a=new y1.Parser(t,e);return r.tag=a.parseTag(),r.minValue=a.parseFixed(),r.defaultValue=a.parseFixed(),r.maxValue=a.parseFixed(),a.skip("uShort",1),r.name=n[a.parseUShort()]||{},r}function Ri(t,e,n,r){for(var a=q8(e.name,r),s=[{name:"nameID_"+t,type:"USHORT",value:a},{name:"flags_"+t,type:"USHORT",value:0}],c=0;c<n.length;++c){var o=n[c].tag;s.push({name:"axis_"+t+" "+o,type:"FIXED",value:e.coordinates[o]<<16})}return s}function Fi(t,e,n,r){var a={},s=new y1.Parser(t,e);a.name=r[s.parseUShort()]||{},s.skip("uShort",1),a.coordinates={};for(var c=0;c<n.length;++c)a.coordinates[n[c].tag]=s.parseFixed();return a}function _i(t,e){var n=new l1.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:t.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:t.instances.length},{name:"instanceSize",type:"USHORT",value:4+t.axes.length*4}]);n.offsetToData=n.sizeOf();for(var r=0;r<t.axes.length;r++)n.fields=n.fields.concat(Hi(r,t.axes[r],e));for(var a=0;a<t.instances.length;a++)n.fields=n.fields.concat(Ri(a,t.instances[a],t.axes,e));return n}function qi(t,e,n){var r=new y1.Parser(t,e),a=r.parseULong();H1.argument(a===65536,"Unsupported fvar table version.");var s=r.parseOffset16();r.skip("uShort",1);for(var c=r.parseUShort(),o=r.parseUShort(),i=r.parseUShort(),l=r.parseUShort(),h=[],u=0;u<c;u++)h.push(Oi(t,e+s+u*o,n));for(var f=[],d=e+s+c*o,m=0;m<i;m++)f.push(Fi(t,d+m*l,h,n));return{axes:h,instances:f}}var Di={make:_i,parse:qi},Ni=function(){return{coverage:this.parsePointer(N.coverage),attachPoints:this.parseList(N.pointer(N.uShortList))}},Ui=function(){var t=this.parseUShort();if(H1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},Bi=function(){return this.parseList(N.pointer(Ui))},ji=function(){return{coverage:this.parsePointer(N.coverage),ligGlyphs:this.parseList(N.pointer(Bi))}},Gi=function(){return this.parseUShort(),this.parseList(N.pointer(N.coverage))};function Wi(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);H1.argument(r===1||r===1.2||r===1.3,"Unsupported GDEF table version.");var a={version:r,classDef:n.parsePointer(N.classDef),attachList:n.parsePointer(Ni),ligCaretList:n.parsePointer(ji),markAttachClassDef:n.parsePointer(N.classDef)};return r>=1.2&&(a.markGlyphSets=n.parsePointer(Gi)),a}var Xi={parse:Wi},k2=new Array(10);k2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(N.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(N.coverage),values:this.parseValueRecordList()};H1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};k2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();H1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer(N.coverage),a=this.parseUShort(),s=this.parseUShort();if(n===1)return{posFormat:n,coverage:r,valueFormat1:a,valueFormat2:s,pairSets:this.parseList(N.pointer(N.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(a),value2:this.parseValueRecord(s)}})))};if(n===2){var c=this.parsePointer(N.classDef),o=this.parsePointer(N.classDef),i=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:r,valueFormat1:a,valueFormat2:s,classDef1:c,classDef2:o,class1Count:i,class2Count:l,classRecords:this.parseList(i,N.list(l,function(){return{value1:this.parseValueRecord(a),value2:this.parseValueRecord(s)}}))}}};k2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};k2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};k2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};k2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};k2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};k2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};k2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Zi(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return H1.argument(r===1||r===1.1,"Unsupported GPOS table version "+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(k2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(k2),variations:n.parseFeatureVariationsList()}}var Yi=new Array(10);function Ki(t){return new l1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new l1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new l1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new l1.LookupList(t.lookups,Yi)}])}var Ji={parse:Zi,make:Ki};function Qi(t){var e={};t.skip("uShort");var n=t.parseUShort();H1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var r=t.parseUShort();t.skip("uShort",3);for(var a=0;a<r;a+=1){var s=t.parseUShort(),c=t.parseUShort(),o=t.parseShort();e[s+","+c]=o}return e}function el(t){var e={};t.skip("uShort");var n=t.parseULong();n>1&&console.warn("Only the first kern subtable is supported."),t.skip("uLong");var r=t.parseUShort(),a=r&255;if(t.skip("uShort"),a===0){var s=t.parseUShort();t.skip("uShort",3);for(var c=0;c<s;c+=1){var o=t.parseUShort(),i=t.parseUShort(),l=t.parseShort();e[o+","+i]=l}}return e}function tl(t,e){var n=new y1.Parser(t,e),r=n.parseUShort();if(r===0)return Qi(n);if(r===1)return el(n);throw new Error("Unsupported kern table version ("+r+").")}var nl={parse:tl};function rl(t,e,n,r){for(var a=new y1.Parser(t,e),s=r?a.parseUShort:a.parseULong,c=[],o=0;o<n+1;o+=1){var i=s.call(a);r&&(i*=2),c.push(i)}return c}var al={parse:rl};function X7(t,e){for(var n=[],r=12,a=0;a<e;a+=1){var s=y1.getTag(t,r),c=y1.getULong(t,r+4),o=y1.getULong(t,r+8),i=y1.getULong(t,r+12);n.push({tag:s,checksum:c,offset:o,length:i,compression:!1}),r+=16}return n}function sl(t,e){for(var n=[],r=44,a=0;a<e;a+=1){var s=y1.getTag(t,r),c=y1.getULong(t,r+4),o=y1.getULong(t,r+8),i=y1.getULong(t,r+12),l=void 0;o<i?l="WOFF":l=!1,n.push({tag:s,offset:c,compression:l,compressedLength:o,length:i}),r+=20}return n}function T0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),r=new Uint8Array(e.length);if(Ks(n,r),r.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var a=new DataView(r.buffer,0);return{data:a,offset:0}}else return{data:t,offset:e.offset}}function D8(t,e){e=e??{};var n,r,a=new p0({empty:!0}),s=new DataView(t,0),c,o=[],i=y1.getTag(s,0);if(i==="\0\0\0"||i==="true"||i==="typ1")a.outlinesFormat="truetype",c=y1.getUShort(s,4),o=X7(s,c);else if(i==="OTTO")a.outlinesFormat="cff",c=y1.getUShort(s,4),o=X7(s,c);else if(i==="wOFF"){var l=y1.getTag(s,4);if(l==="\0\0\0")a.outlinesFormat="truetype";else if(l==="OTTO")a.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+i);c=y1.getUShort(s,12),o=sl(s,c)}else throw new Error("Unsupported OpenType signature "+i);for(var h,u,f,d,m,g,p,v,b,y,M,w,x=0;x<c;x+=1){var k=o[x],A=void 0;switch(k.tag){case"cmap":A=T0(s,k),a.tables.cmap=r8.parse(A.data,A.offset),a.encoding=new s8(a.tables.cmap);break;case"cvt ":A=T0(s,k),w=new y1.Parser(A.data,A.offset),a.tables.cvt=w.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":A=T0(s,k),w=new y1.Parser(A.data,A.offset),a.tables.fpgm=w.parseByteList(k.length);break;case"head":A=T0(s,k),a.tables.head=p8.parse(A.data,A.offset),a.unitsPerEm=a.tables.head.unitsPerEm,n=a.tables.head.indexToLocFormat;break;case"hhea":A=T0(s,k),a.tables.hhea=g8.parse(A.data,A.offset),a.ascender=a.tables.hhea.ascender,a.descender=a.tables.hhea.descender,a.numberOfHMetrics=a.tables.hhea.numberOfHMetrics;break;case"hmtx":p=k;break;case"ltag":A=T0(s,k),r=b8.parse(A.data,A.offset);break;case"maxp":A=T0(s,k),a.tables.maxp=y8.parse(A.data,A.offset),a.numGlyphs=a.tables.maxp.numGlyphs;break;case"name":y=k;break;case"OS/2":A=T0(s,k),a.tables.os2=O4.parse(A.data,A.offset);break;case"post":A=T0(s,k),a.tables.post=S8.parse(A.data,A.offset),a.glyphNames=new N4(a.tables.post);break;case"prep":A=T0(s,k),w=new y1.Parser(A.data,A.offset),a.tables.prep=w.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":b=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":m=k;break;case"GSUB":g=k;break;case"meta":M=k;break}}var L=T0(s,y);if(a.tables.name=z8.parse(L.data,L.offset,r),a.names=a.tables.name,f&&b){var z=n===0,S=T0(s,b),C=al.parse(S.data,S.offset,a.numGlyphs,z),E=T0(s,f);a.glyphs=I8.parse(E.data,E.offset,C,a,e)}else if(h){var I=T0(s,h);m8.parse(I.data,I.offset,a,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var H=T0(s,p);if(v8.parse(a,H.data,H.offset,a.numberOfHMetrics,a.numGlyphs,a.glyphs,e),bc(a,e),v){var T=T0(s,v);a.kerningPairs=nl.parse(T.data,T.offset)}else a.kerningPairs={};if(d){var O=T0(s,d);a.tables.gdef=Xi.parse(O.data,O.offset)}if(m){var _=T0(s,m);a.tables.gpos=Ji.parse(_.data,_.offset),a.position.init()}if(g){var D=T0(s,g);a.tables.gsub=A8.parse(D.data,D.offset)}if(u){var G=T0(s,u);a.tables.fvar=Di.parse(G.data,G.offset,a.names)}if(M){var V=T0(s,M);a.tables.meta=L8.parse(V.data,V.offset),a.metas=a.tables.meta}return a}function ut(t,e){let n=t.tables?.os2?.sCapHeight;if(n&&n>0)return n/t.unitsPerEm*e;let r=m0(f3(t,"H",{size:e,font:"",halign:"left",valign:"baseline",spacing:1}).polys);return r?r[3]:t.ascender/t.unitsPerEm*e}var ht=class{constructor(e,n){this.sources=e;this.fallback=n;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let n=e||this.fallback||Object.keys(this.sources)[0];if(!n)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let r=this.parsed.get(n);if(r)return r;let a=s2(this.sources,n);if(!a)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let s=a instanceof Uint8Array?a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength):a,c=D8(s);return this.parsed.set(n,c),c}};function cl(t,e,n){let r={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,r).commands,advance:t.getAdvanceWidth(e,n.size,r)};let a=[],s=0,c=[...e];return c.forEach((o,i)=>{a.push(...t.getPath(o,s,0,n.size,r).commands),s+=t.getAdvanceWidth(o,n.size,r)*(i<c.length-1?n.spacing:1)}),{cmds:a,advance:s}}function f3(t,e,n){let{cmds:r,advance:a}=cl(t,e,n),s=r.map(o=>o.type==="Z"?o:o.type==="C"?{...o,y1:-o.y1,y2:-o.y2,y:-o.y}:o.type==="Q"?{...o,y1:-o.y1,y:-o.y}:{...o,y:-o.y}),c=t3(s,Math.max(.005,n.size/2e3));return{polys:[...c.closed,...c.open.filter(o=>o.length>=3)],advance:a}}function d3(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:a,advance:s}=f3(r,e,n),c=t1(a),o=m0(c);if(!o)return[];let i=n.halign==="center"?-s/2:n.halign==="right"?-s:0,l=n.valign==="top"?-o[3]:n.valign==="center"?-(o[1]+o[3])/2:n.valign==="bottom"?-o[1]:n.valign==="cap"?-ut(r,n.size)/2:0;return c.map(h=>h.map(([u,f])=>[u+i,f+l]))}function u5(t,e,n){let r=t.get(n.font),{polys:a,advance:s}=f3(r,e,n),c=m0(a)??[0,0,0,0];return{advance:s,bounds:[[c[0],c[1]],[c[2],c[3]]],ascent:r.ascender/r.unitsPerEm*n.size,descent:r.descender/r.unitsPerEm*n.size,cap:ut(r,n.size)}}function ol(t,e,n){let r=0;for(;r<t.length-2&&e[r+1]<n;)r++;let[a,s]=[t[r],t[r+1]],c=e[r+1]-e[r],o=(n-e[r])/c,i=[(s[0]-a[0])/c,(s[1]-a[1])/c];return{at:[a[0]+(s[0]-a[0])*o,a[1]+(s[1]-a[1])*o],t:i}}function N8(t,e,n,r){let a=r.filter(([v,b],y)=>y===0||v!==r[y-1][0]||b!==r[y-1][1]);if(!e||a.length<2)return{polys:[],over:0};let s=t.get(n.font),c={kerning:!0},o=[...e],i=[],l=0;o.forEach((v,b)=>{i.push(n.spacing===1?s.getAdvanceWidth(o.slice(0,b+1).join(""),n.size,c)-s.getAdvanceWidth(v,n.size,c):l),l+=s.getAdvanceWidth(v,n.size,c)*(b<o.length-1?n.spacing:1)});let h=n.spacing===1?s.getAdvanceWidth(e,n.size,c):l,u=m0(f3(s,e,n).polys);if(!u)return{polys:[],over:0};let f=n.valign==="top"?-u[3]:n.valign==="center"?-(u[1]+u[3])/2:n.valign==="bottom"?-u[1]:n.valign==="cap"?-ut(s,n.size)/2:0,d=[0];for(let v=1;v<a.length;v++)d.push(d[v-1]+Math.hypot(a[v][0]-a[v-1][0],a[v][1]-a[v-1][1]));let m=d[d.length-1],g=n.halign==="center"?(m-h)/2:n.halign==="right"?m-h:0,p=[];return o.forEach((v,b)=>{let y=s.getAdvanceWidth(v,n.size,c),{at:M,t:w}=ol(a,d,g+i[b]+y/2),x=[-w[1],w[0]];for(let k of f3(s,v,n).polys)p.push(k.map(([A,L])=>{let z=A-y/2,S=L+f;return[M[0]+z*w[0]+S*x[0],M[1]+z*w[1]+S*x[1]]}))}),{polys:t1(p),over:Math.max(0,-g,g+h-m)}}function U8(t){let e=Math.abs(t),n=Math.min(720,Math.max(72,Math.ceil(2*Math.PI*e/.5)));return Array.from({length:n+1},(r,a)=>{let s=t>0?1.5*Math.PI-2*Math.PI*a/n:.5*Math.PI+2*Math.PI*a/n;return[e*Math.cos(s),e*Math.sin(s)]})}function B8(t,e,n,r=0,a){if(!e)return{polys:[],loose:[]};let s=t.get(n.font),c={kerning:!0},o=[...e],i=a??Math.max(n.size*.1,1.5),l=n.size*.6,h=[],u=[],f=0,d=0,m=(L,z)=>L.map(S=>S.map(([C,E])=>[C+z,E])),g=(L,z)=>G1(L,z).length>0;o.forEach((L,z)=>{let S=n.spacing===1?s.getAdvanceWidth(o.slice(0,z+1).join(""),n.size,c)-s.getAdvanceWidth(L,n.size,c):d;if(d+=s.getAdvanceWidth(L,n.size,c)*(z<o.length-1?n.spacing:1),/\s/.test(L)){u=[];return}let C=t1(f3(s,L,n).polys);if(!C.length)return;let E=m(C,S+f);if(u.length&&!g(u,E)){let[I,H]=[0,l];if(g(u,m(E,-H))){for(let O=0;O<24;O++){let _=(I+H)/2;g(u,m(E,-_))?H=_:I=_}let T=Math.min(l,H+i);f-=T,E=m(E,-T)}}u=t1([...u,...E]),h.push({ch:L,polys:E})});let p=a0(a0(t1(h.flatMap(L=>L.polys)),.8,"round"),-.8,"round"),v=m0(p);if(!v)return{polys:[],loose:[]};r>0&&(p=t1([...p,[[v[0],-r*.6],[v[2],-r*.6],[v[2],r*.4],[v[0],r*.4]]]));let b=E0(p),y=L=>L.reduce((z,S)=>z+Math.abs(z1(S)),0),M=b.reduce((L,z)=>y(z)>y(L)?z:L,b[0]),w=b.filter(L=>L!==M).map(L=>{let z=h.find(S=>G1(S.polys,L).length);return z?z.ch:"?"}),x=m0(p),k=n.halign==="center"?-(x[0]+x[2])/2:n.halign==="right"?-x[2]:-x[0],A=n.valign==="top"?-x[3]:n.valign==="center"?-(x[1]+x[3])/2:n.valign==="bottom"?-x[1]:n.valign==="cap"?-ut(s,n.size)/2:0;return{polys:p.map(L=>L.map(([z,S])=>[z+k,S+A])),loose:w}}var j8=Math.PI/180,Z4=128;function il(t,e,n){let[r,a]=[0,1],s=e[0]-t[0],c=e[1]-t[1];for(let[o,i]of[[-s,t[0]-n[0]],[s,n[2]-t[0]],[-c,t[1]-n[1]],[c,n[3]-t[1]]])if(o===0){if(i<=0)return!1}else{let l=i/o;o<0?r=Math.max(r,l):a=Math.min(a,l)}return r<a}var f5=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],en={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function ll(t,e){if(!t||s2(Q4,t)!==void 0)return;let n=t.split("\\").join("/"),r=e.split("\\").join("/");if(r.startsWith("/")||/^[A-Za-z]:\//.test(r))return;let a=n.lastIndexOf("/");if(a<0)return;let s=[...n.slice(0,a).split("/"),...r.split("/")],c=[];for(let o of s)o===".."&&c.length&&c[c.length-1]!==".."?c.pop():o!=="."&&o!==""&&c.push(o);return(n.startsWith("/")?"/":"")+c.join("/")}var X8=new WeakSet,hl=()=>{let t=D0();return X8.add(t),t},G8=t=>!X8.has(t),ul=100,fl={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},m3=4,W8=8,dl=t=>{let e=ul,n=r=>{for(let a of r.values()){for(let s of a.regions)e+=s.length;for(let s of a.lines)e+=s.length}};n(t.layers);for(let r of t.parts)n(r.layers);return e},_0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,r=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=r?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let r=n.fns.get(e);if(r)return r}}mod(e){for(let n=this;n;n=n.parent){let r=n.mods.get(e);if(r)return r}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let r=this;r;r=r.parent)n.push(...r[e].keys());return n}},Y4=t=>t?`.${t}`:"",K4=(t,e)=>t==="module"?`Recursion too deep in module ${e}(): check that it stops`:`Recursion too deep in ${e}(): check that it stops, or use fold(), scan() or a list comprehension to go through a long list`,ml={color:"its children are drawn as they are. Use cut(), score(), engrave() or layer() to choose how they are cut.",linear_extrude:"its children are drawn flat, as the part outline. A part takes its height from $thickness."},J4=["echo","assert","text_width","text_metrics","text_size","finger_count"];function Oe(t,e){let n="",r=Math.min(2,Math.floor(t.length/3))+.5;for(let a of new Set(e)){if(a===t)continue;let s=a.toLowerCase()===t.toLowerCase()?0:pl(t,a);s<r&&([n,r]=[a,s])}return n?` Did you mean "${n}"?`:""}function pl(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(r,a)=>[a,...Array(e.length).fill(0)]);for(let r=1;r<=e.length;r++)n[0][r]=r;for(let r=1;r<=t.length;r++)for(let a=1;a<=e.length;a++)n[r][a]=Math.min(n[r-1][a]+1,n[r][a-1]+1,n[r-1][a-1]+(t[r-1]===e[a-1]?0:1)),r>1&&a>1&&t[r-1]===e[a-2]&&t[r-2]===e[a-1]&&(n[r][a]=Math.min(n[r][a],n[r-2][a-2]+1));return n[t.length][e.length]}var Q4=Q3,K2=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.occluding=0;this.pointCount=0;this.itemCount=0;this.retained=0;this.copies=0;this.layerDefs=0;this.frame=s4;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.lights=[];this.echoes=[];this.warnings=[];this.layers=new Map(f5.map(e=>[e.name,e]));this.loaded=new Map;this.clashed=new Set;this.childCache=new WeakMap;this.copyReads=0;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...en,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new _0,r={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[o,i]of Object.entries(r))n.vars.set(o,i);let a=new _0(n),s=this.block(e.body,a,!0),c=a.vars.get("$scale");return this.unscaled&&c!==void 0&&c!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${t2(this.unscaled,!1)})`),{shape:s,globals:a,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,lights:this.lights,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new i1(`Stopped after ${this.maxSteps} steps. Is there an endless loop, or more work than one program may do (a long list, a fine spacing)?`,e)}load(e,n){let r=ll(n.file,e),a=e,s=s2(Q4,e);if(s===void 0&&r!==void 0){let o=this.loaded.get(r);if(o)return o;s=this.opts.resolve?.(r),typeof s=="string"&&(a=r)}if(a===e){let o=this.loaded.get(e);if(o)return o;s??(s=this.opts.resolve?.(e))}if(typeof s!="string")throw new i1(`Library <${e}> not found`,n);this.loaded.set(a,{body:[]});let{program:c}=n2(s,a);return this.loaded.set(a,c),c}hoist(e,n){for(let r of e)if((r.kind==="module"||r.kind==="function")&&(r.pos.file===void 0||s2(Q4,r.pos.file)===void 0)&&(r.kind==="module"?s2(this.builtins,r.name)!==void 0:s2(Z3,r.name)!==void 0||J4.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${t2(r.pos,!1)})`),r.kind==="module")n.mods.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="function")n.fns.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="use"&&!r.include){this.enter(this.using,r.path,r.pos,"use");try{let a=this.included(this.load(r.path,r.pos).body,new Set([r.path])),s=new _0(n);this.hoist(a,s);for(let c of a)c.kind==="assign"&&this.assign(c.name,this.expr(c.value,s),s);for(let[c,o]of s.mods)this.clash("module",c,n.mods.get(c),o),n.mods.set(c,o);for(let[c,o]of s.fns)this.clash("function",c,n.fns.get(c),o),n.fns.set(c,o)}finally{this.using.pop()}}}clash(e,n,r,a){!r||r.body===a.body||!r.pos?.file||!a.pos?.file||r.pos.file===a.pos.file||this.clashed.has(`${e} ${n}`)||(this.clashed.add(`${e} ${n}`),this.warn(`${e} ${n} is defined in <${r.pos.file}> (line ${r.pos.line}) and in <${a.pos.file}> (line ${a.pos.line}); the one in <${a.pos.file}> is used. Rename one to use both.`))}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let a=[...n].sort(([l],[h])=>l<h?-1:1),s=[],c=0,o=[];for(let l=a.length-1;l>=0;l--)o.push({text:";"},a[l][1],{text:`${a[l][0]}=`});for(;o.length;){if(c>2e4)return"";let l=o.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){o.push({text:"]"});for(let u=l.length-1;u>=0;u--)o.push(l[u],{text:","});h="["}else if(p2(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(e2(l)){o.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)o.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";s.push(h),c+=h.length}let i=s.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${this.layerDefs}|${i}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.lights.length},${this.stepNames.length},${this.warnings.length},${this.copies},${this.layerDefs}`}enter(e,n,r,a){if(e.includes(n)){let s=[...e.slice(e.indexOf(n)),n].map(c=>`<${c}>`);throw new i1(s.length===2?`Library ${s[0]} ${a}s itself`:`Libraries ${a} each other in a loop: ${s.join(" \u2192 ")}`,r)}e.push(n)}included(e,n){let r=[];for(let a of e)if(a.kind!=="use"||!a.include)r.push(a);else if(!n.has(a.path)){n.add(a.path);for(let s of this.included(this.load(a.path,a.pos).body,n))r.push(s)}return r}assign(e,n,r){r.vars.set(e,n)}block(e,n,r=!1){this.hoist(e,n);let a=[];for(let s of e){let c=this.stmt(s,n,r);c&&!u6(c)&&a.push(c)}return a.length===1?a[0]:O2(a)}stmt(e,n,r=!1){switch(this.tick(e.pos),e.kind){case"assign":{let a=this.opts.overrides,s=r&&a&&Object.prototype.hasOwnProperty.call(a,e.name)?a[e.name]:this.expr(e.value,n);return this.assign(e.name,s,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new _0(n));case"if":return w0(this.expr(e.cond,n))?this.block(e.then,new _0(n)):e.else.length?this.block(e.else,new _0(n)):null;case"let":{let a=new _0(n);return this.bindSeq(e.assigns,a),this.block(e.body,a)}case"for":{let a=[];return this.loop(e.assigns,n,s=>a.push(this.block(e.body,s))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:n,children:()=>O2(a),childList:()=>a,childSeq:()=>a,childItems:()=>a}):O2(a)}case"call":if(e.modifier==="*")return null;{let a=this.callModule(e,n);return(e.name==="echo"||e.name==="assert")&&!e.children.length&&!n.mod(e.name)?null:e.modifier==="#"||e.modifier==="%"?N3(a,"guide"):a}}}bindSeq(e,n){for(let r of e)this.assign(r.name,this.expr(r.value,n),n)}iterable(e,n){if(p2(e))try{return U5(e,this.limits.maxListLength)}catch(r){throw new i1(r.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,r,a=0,s=new _0(n)){if(a===e.length)return r(s);let c=e[a];for(let o of this.iterable(this.expr(c.value,s),c.pos)){this.tick(c.pos);let i=new _0(s);i.vars.set(c.name,o),this.loop(e,n,r,a+1,i)}}evalArgs(e,n,r){let a=[],s=new Map,c=[];for(let o of e){let i=this.expr(o.value,n);o.name===null?a.push(i):s.set(o.name,i),c.push({name:o.name,value:i})}return{pos:a,named:s,all:c,at:r}}bindParams(e,n,r,a,s){let c=e.map(o=>o.name);for(let[o,i]of n.named)o.startsWith("$")&&r.vars.set(o,i);e.forEach((o,i)=>{let l;n.named.has(o.name)?l=n.named.get(o.name):i<n.pos.length?l=n.pos[i]:l=o.default?this.expr(o.default,r):void 0,r.vars.set(o.name,l)});for(let o of n.named.keys())!o.startsWith("$")&&!c.includes(o)&&this.unknownArg(s,o,n.at,c);this.checkCount(s,e.length,n)}checkArgs(e,n){let r=c3(e);if(!r)return;let a=r.params.map(s=>s.name);if(!r.anyNamed)for(let s of n.named.keys())!s.startsWith("$")&&!a.includes(s)&&this.unknownArg(`${e}()`,s,n.at,a);r.rest||this.checkCount(`${e}()`,r.params.filter(s=>!s.named).length,n)}checkCount(e,n,r){r.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${r.pos.length}; the rest are ignored (${t2(r.at,!1)})`)}unknownArg(e,n,r,a){this.warn(`${e}: unknown argument "${n}"${Y4(Oe(n,a))} (${t2(r,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let r=e.args.findIndex(c=>c.name==="name"),a=r>=0?r:e.args.findIndex(c=>c.name===null);if(a<0)throw new i1("call() needs the name of a module",e.pos);let s=this.expr(e.args[a].value,n);if(typeof s!="string")throw new i1(`call() needs a module's name as a string, got ${X0(s)}`,e.pos);if(s==="call")throw new i1("call() can't call itself",e.pos);return this.callModule({...e,name:s,args:e.args.filter((c,o)=>o!==a)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let r=this.evalArgs(e.args,n,e.pos),a=n.mod(e.name);if(a){if(++this.depth>1e3)throw new i1(K4("module",e.name),e.pos);try{let d=new _0(a.env,n);return this.bindParams(a.params,r,d,a.env,`${e.name}()`),d.children={stmts:e.children,env:n,module:e.name,pos:e.pos},d.vars.set("$children",this.childStmts(e.children).length),this.block(a.body,d)}catch(d){throw this.inCall(d,"module",e.name,e.pos)}finally{this.depth--}}let s=s2(this.builtins,e.name),c=s2(ml,e.name);if(!s&&c)return this.warn(`${e.name}() is ignored: ${c} (${t2(e.pos,!1)})`),e.children.length?this.block(e.children,new _0(n,n)):D0();if(!s){let d=Oe(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new i1(`Unknown module ${e.name}().${d}`,e.pos)}this.checkArgs(e.name,r);let o=new _0(n,n);for(let[d,m]of r.named)d.startsWith("$")&&o.vars.set(d,m);let i=this.childStmts(e.children),l=()=>new _0(n,o),h={args:r,env:o,children:()=>e.children.length?this.block(e.children,l()):D0(),childList:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let g of e.children){let p=this.stmt(g,d);i.includes(g)&&m.push(p??hl())}return m},childItems:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let g of e.children){if(i.includes(g)&&g.kind==="for"&&!g.intersect){this.tick(g.pos),this.loop(g.assigns,d,v=>m.push(this.block(g.body,v)));continue}let p=this.stmt(g,d);i.includes(g)&&m.push(p??D0())}return m},childSeq:d=>{let m=l();this.hoist(e.children,m);let g=[];for(let p of e.children){let v=this.stmt(p,m);i.includes(p)&&(g.push(v??D0()),d(g.length-1,v??D0()))}return g}},u;try{u=s(h)}catch(d){if(d instanceof i1||d instanceof RangeError)throw d;let m=new i1(`${e.name}(): ${d.message}`,e.pos);throw m.call=e.name,m}let f=dl(u);if(e.name!=="children"&&(this.pointCount+=f),f>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new i1(f>this.limits.maxPoints?`The shapes have more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes, or a lower $fn.`:`Making the shapes took more than ${this.limits.maxPoints*10} points of work, the limit. Use fewer or simpler shapes, or a lower $fn.`,e.pos);return u}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,r,a){if(++this.depth>2e3)throw new i1(K4("function",a),n.at);try{this.tick(n.at);let s=x2(e)?e.scope:e.env,c=new _0(s,r);return this.bindParams(e.params,n,c,s,`${a}()`),this.expr(e.body,c)}catch(s){throw this.inCall(s,"function",a,n.at)}finally{this.depth--}}inCall(e,n,r,a){return e instanceof Error&&!(e instanceof i1)&&e.message.includes("call stack")?new i1(K4(n,r),a):(e instanceof i1&&e.addFrame(n,r,a),e)}expr(e,n){switch(e.kind){case"num":return e.unit?this.length(e,n):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{e.name==="$copy"&&this.copyReads++;let r=n.get(e.name);if(r.found)return r.value;let a=n.fn(e.name);if(a)return{type:"function",params:a.params,body:a.body,scope:a.env,name:e.name};if(e.name.startsWith("$"))return;throw new i1(`Unknown variable "${e.name}"${Y4(Oe(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let r=[];for(let a of e.items)this.listItem(a,n,r,e.pos);return this.charge(m3,e.pos),r}case"range":{let r=this.expr(e.start,n),a=this.expr(e.end,n),s=e.step?this.expr(e.step,n):1;if(typeof r!="number"||typeof a!="number"||typeof s!="number")throw new i1("Range values must be numbers",e.pos);return{type:"range",start:r,step:s,end:a}}case"unary":{let r=this.expr(e.arg,n);return e.op==="!"?!w0(r):e.op==="+"?r:this.arith("*",-1,r,e.pos)}case"binary":{if(e.op==="&&")return w0(this.expr(e.left,n))&&w0(this.expr(e.right,n));if(e.op==="||")return w0(this.expr(e.left,n))||w0(this.expr(e.right,n));let r=this.expr(e.left,n),a=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return Qe(r,a,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof r=="number"&&typeof a=="number"||typeof r=="string"&&typeof a=="string"))throw new i1(`Can't compare ${X0(r)} ${e.op} ${X0(a)}`,e.pos);return e.op==="<"?r<a:e.op==="<="?r<=a:e.op===">"?r>a:r>=a}return this.arith(e.op,r,a,e.pos)}case"ternary":return w0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let r=this.expr(e.target,n),a=this.expr(e.index,n);if(e2(r)&&typeof a=="string")return r.fields.get(a);if(typeof a!="number")throw new i1(`List index must be a number, got ${X0(a)}`,e.pos);return Array.isArray(r)?r[Math.floor(a)]:typeof r=="string"?[...r][Math.floor(a)]:p2(r)?[r.start,r.step,r.end][Math.floor(a)]:void 0}case"record":return this.record(e,n);case"member":{let r=this.expr(e.target,n);if(e2(r))return r.fields.get(e.name);let a={x:0,y:1,z:2}[e.name];return Array.isArray(r)&&a!==void 0?r[a]:p2(r)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?r.start:e.name==="step"?r.step:r.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let r=new _0(n);return this.bindSeq(e.assigns,r),this.expr(e.body,r)}case"chain":return this.expr(e.check,n),this.expr(e.body,n)}}listItem(e,n,r,a){switch(e.kind){case"item":{let s=this.expr(e.expr,n);this.grow(r,1,a),r.push(s);return}case"each":{let s=this.iterable(this.expr(e.expr,n),a);this.grow(r,s.length,a);for(let c of s)r.push(c);return}case"for":this.loop(e.assigns,n,s=>this.listItem(e.body,s,r,a));return;case"if":w0(this.expr(e.cond,n))?this.listItem(e.then,n,r,a):e.else&&this.listItem(e.else,n,r,a);return;case"let":{let s=new _0(n);this.bindSeq(e.assigns,s),this.listItem(e.body,s,r,a)}}}grow(e,n,r){if(e.length+n>this.limits.maxListLength)throw new i1(`a list of ${e.length+n} items is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n,r)}charge(e,n){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new i1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let a=e.callee.name,s=n.get(a),c=s.found&&!x2(s.value);if(!s.found||c&&this.callable(a,n)){let o=n.fn(a);if(o)return this.callFunction(o,this.evalArgs(e.args,n,e.pos),n,a);let i=this.specialFunction(a,e,n);if(i.handled)return i.value;let l=s2(Z3,a);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(a,h);for(let m of Y6(l,h.pos,h.named))this.warn(`${a}(): "${m}" is given by position and by name; the named value is used (${t2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:m=>this.tick(e.pos,m),given:h.pos.length+l.params.filter(m=>h.named.has(m)).length,apply:(m,g)=>{if(!x2(m))throw new Error(`${a}() needs a function, got ${X0(m)}`);return this.callFunction(m,{pos:g,named:new Map,all:g.map(p=>({name:null,value:p})),at:e.pos},n,"function")}},f=K6(l,h.pos,h.named);this.tick(e.pos,J6(a,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof i1)throw m;let g=new i1(m instanceof RangeError?`${a}(): the result is too large`:m.message,e.pos);throw g.call=a,g}return this.checkValue(d,e.pos,a),d}throw new i1(`Unknown function ${a}()${Y4(Oe(a,[...n.names("fns"),...n.names("vars"),...Object.keys(Z3),...J4]))}`,e.pos)}if(!x2(s.value))throw new i1(`"${a}" is a ${X0(s.value)}, not a function`,e.pos);return this.callFunction(s.value,this.evalArgs(e.args,n,e.pos),n,a)}let r=this.expr(e.callee,n);if(!x2(r))throw new i1(`Can't call a ${X0(r)}`,e.pos);return this.callFunction(r,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,r,a){let s=c=>Array.isArray(r)?String(r[c]??""):[...e[c].layers.keys()].sort().join(",");for(let c=1;c<e.length;c++){if(!n[c]?.length)continue;let o=s(c),i=t1(e.flatMap((h,u)=>u<c&&s(u)===o?n[u]:[]));!i.length||d0(n[c],i).reduce((h,u)=>h+Math.abs(z1(u)),0)>.001||this.warn(`paint(): child ${c+1} lies wholly on an area of the same layer${Array.isArray(r)&&o?` "${o}"`:""} under it, so it can't be seen (${t2(a,!1)})`)}}record(e,n){let r=new Map;for(let a of e.fields)r.set(a.name,this.expr(a.value,n));return{type:"record",fields:r}}length(e,n){let r=V0(n.get("$scale").value??1);if(!(r>0))throw new i1("$scale must be a number more than 0",e.pos);return r===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*fl[e.unit]/r}callable(e,n){return!!n.fn(e)||J4.includes(e)||!!s2(Z3,e)}specialFunction(e,n,r){if(e==="echo"){let a=this.evalArgs(n.args,r,n.pos);return this.echo(this.echoText(a),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let a=this.evalArgs(n.args,r,n.pos);return this.checkArgs(e,a),this.assert(a),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"||e==="text_size"){let a=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,a);let s=this.measure(a,r);return e==="text_width"?{handled:!0,value:s.advance}:e==="text_size"?{handled:!0,value:{type:"record",fields:new Map([["width",s.advance],["height",s.bounds[1][1]-s.bounds[0][1]],["bounds",s.bounds],["cap",s.cap],["ascent",s.ascent],["descent",s.descent],["size",s.size]])}}:{handled:!0,value:[s.advance,s.bounds,s.ascent,s.descent]}}if(e==="finger_count"){let a=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,a);let s=this.num(this.arg(a,"length",0),"finger_count","length");return{handled:!0,value:Ee(s,this.fingerWidth(a,r,1))}}return{handled:!1}}assert(e){if(w0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new i1(`Assertion failed${n===void 0?"":": "+k0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/W8);this.charge(r,n),this.retained+=r,this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,r=[],a=0,s=(c,o,i)=>{r.length&&(a+=2);let l=e3(o,n-a-c.length,i);if(a+=c.length+l.text.length,!l.whole)throw new i1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);r.push(c+l.text)};for(let{name:c,value:o}of e.all)c===null?s("",o,!1):s(`${c} = `,o,!0);return r.join(", ")}arith(e,n,r,a){if(typeof n=="number"&&typeof r=="number")switch(e){case"+":return n+r;case"-":return n-r;case"*":return n*r;case"/":return n/r;case"%":return n%r;case"^":return Math.pow(n,r)}if(e==="+"&&typeof n=="string"&&typeof r=="string")return this.checkSize(n.length+r.length,!0,a),n+r;if(Array.isArray(n)&&Array.isArray(r)){if(e==="+"||e==="-"){if(n.length!==r.length)throw new i1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${r.length}`,a);return this.charge(n.length+m3,a),n.map((c,o)=>this.arith(e,c,r[o],a))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+m3,a),n.map(o=>this.arith("*",o,r,a));let c=(o,i)=>{let l=this.arith("*",o,i,a);if(typeof l!="number")throw new i1("Can't multiply these lists: an item times an item is not a number",a);return l};if(Array.isArray(r[0])){let o=r[0].length;if(n.length!==r.length||r.some(i=>!Array.isArray(i)||i.length!==o))throw new i1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,a);return this.checkSize(o,!1,a),this.tick(a,o*n.length),Array.from({length:o},(i,l)=>n.reduce((h,u,f)=>h+c(u,r[f][l]),0))}if(n.length!==r.length)throw new i1(`Can't multiply lists of length ${n.length} and ${r.length}`,a);return this.tick(a,n.length),n.reduce((o,i,l)=>o+c(i,r[l]),0)}}if(Array.isArray(n)&&typeof r=="number"&&(e==="*"||e==="/"))return this.charge(n.length+m3,a),n.map(c=>this.arith(e,c,r,a));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+m3,a),r.map(c=>this.arith(e,n,c,a));let s={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new i1(`Can't ${s[e]??e} ${X0(n)} and ${X0(r)}`,a)}fieldFn(e,n,r,a){if(!x2(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${c0(e)}`);return s=>{let c=this.itemCount,o=this.retained,i=this.callFunction(e,{pos:[s],named:new Map,all:[{name:null,value:s}],at:a},r,"field");return(!Array.isArray(i)||i.length<=3)&&(this.itemCount=c+this.retained-o),i}}arg(e,n,r,a){return e.named.has(n)?e.named.get(n):r>=0&&r<e.pos.length?e.pos[r]:a}num(e,n,r){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${r} must be a finite number, got ${c0(e)}`);return e}vec2(e,n,r=!0){let a=s=>typeof s=="number"&&Number.isFinite(s);if(a(e)&&r)return[e,e];if(Array.isArray(e)&&a(e[0])&&(e[1]===void 0||a(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${c0(e)}`)}vec3(e,n){let r=a=>typeof a=="number"&&Number.isFinite(a);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(r))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${c0(e)}`)}placements(e,n,r){let a=(o,i)=>o===void 0?[[0,0,0]]:Array.isArray(o)&&o.length>0&&Array.isArray(o[0])?o.map((l,h)=>this.vec3(l,`${i}[${h}]`)):[this.vec3(o,i)],s=a(e,"at"),c=a(n,"rotate");for(let[o,i]of[[s,"at"],[c,"rotate"]])if(o.length!==1&&o.length!==r)throw new Error(`${i} needs one placement per copy: qty is ${r} but ${i} has ${o.length}`);return Array.from({length:r},(o,i)=>({at:s[s.length===1?0:i],rotate:c[c.length===1?0:i]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((r,a)=>{if(!Array.isArray(r)||!Number.isFinite(r[0])||!Number.isFinite(r[1]))throw new Error(`${n}[${a}] must be an [x, y] point, got ${c0(r)}`);return[r[0],r[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,r){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,r)}checkSize(e,n,r,a){if(e>this.limits.maxListLength)throw new i1(`${a?`${a}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n?Math.ceil(e/W8):e+m3,r)}segs(e){let n=V0(this.dyn(e,"$fn"))||0,r=V0(this.dyn(e,"$fa"))||2,a=V0(this.dyn(e,"$fs"))||.2,s=this.limits.maxSegments;return c=>{let o=d6(c,n,r,a);if(!(o<=s))throw new Error(`a circle with ${o} segments is more than the limit of ${s}. Lower $fn, or raise $fa or $fs.`);return o}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||!(n>0&&Number.isFinite(n)))throw new Error(`$thickness must be a positive number, got ${c0(n)}`);return n}kerf(e){let n=this.dyn(e,"$kerf");if(n===void 0)return 0;if(typeof n!="number"||!(n>=0&&Number.isFinite(n)))throw new Error(`$kerf must be a number, 0 or more, got ${c0(n)}`);return n}fingerWidth(e,n,r){let a=this.arg(e,"finger",r);return typeof a=="number"&&a>0?a:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new i1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let r=e3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!r.whole)throw new i1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,r.text.length);try{let a=this.textOpts(e,n,r.text);return{...u5(this.opts.fonts,r.text,a),size:a.size}}catch(a){throw a instanceof i1?a:new i1(a.message,e.at)}}textOpts(e,n,r){let a={size:this.num(this.arg(e,"size",1,10),"text","size"),font:k0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:k0(this.arg(e,"halign",-1,"left")),valign:k0(this.arg(e,"valign",-1,"baseline")),spacing:V0(this.arg(e,"spacing",-1,1))},s=this.arg(e,"fit",-1);if(s!==void 0&&r!==void 0&&this.opts.fonts){let[c,o]=Array.isArray(s)?[s[0],s[1]]:[s,void 0],i=(g,p)=>{if(g===void 0)return;let v=this.num(g,"text","fit");if(!(v>0))throw new Error(`fit must be a ${p} more than 0`);return v},l=i(c,"width"),h=i(o,"height");if(Array.isArray(s)&&(s.length!==2||l===void 0&&h===void 0))throw new Error("fit must be a width, or [width, height] with either one undef");let u=u5(this.opts.fonts,r,{...a,size:1}),f=l===void 0?null:m0(d3(this.opts.fonts,r,{...a,size:1})),d=Math.max(u.advance,f?f[2]-f[0]:0),m=[...l!==void 0&&d>0?[l/d]:[],...h!==void 0&&u.cap>0?[h/u.cap]:[]];if(m.length){let g=this.arg(e,"size",1);a.size=Math.min(...m,...g===void 0?[]:[a.size])}}return a}textBlock(e,n,r,a,s){let c=this.opts.fonts,o={...r,size:1},i=new Map,l=L=>{if(!L)return 0;let z=i.get(L);if(z===void 0){let S=u5(c,L,o);z=Math.max(S.advance,S.bounds[1][0]-S.bounds[0][0]),i.set(L,z)}return z},h=n.split(`
4251
+ `).map(L=>L.split(/ +/).filter(Boolean)),u=(L,z)=>{if(z<=1||L.length<=1)return[L.join(" ")];let S=L.length,C=Math.min(z,S),E=(O,_)=>l(L.slice(O,_).join(" ")),I=Array.from({length:C+1},()=>new Array(S+1).fill(1/0)),H=Array.from({length:C+1},()=>new Array(S+1).fill(S));for(let O=0;O<S;O++)I[1][O]=E(O,S);for(let O=2;O<=C;O++)for(let _=0;_<S;_++)for(let D=_+1;D<=S-O+1;D++){let G=Math.max(E(_,D),I[O-1][D]);G<I[O][_]&&([I[O][_],H[O][_]]=[G,D])}let T=[];for(let O=C,_=0;O>=1;O--){let D=O===1?S:H[O][_];T.push(L.slice(_,D).join(" ")),_=D}return T},f=L=>{let z=h.map(()=>1);for(let S=L-h.length;S>0;S--){let C=-1,E=-1;if(h.forEach((I,H)=>{if(z[H]>=I.length)return;let T=Math.max(...u(I,z[H]).map(l));T>C&&([C,E]=[T,H])}),E<0)break;z[E]++}return h.flatMap((S,C)=>u(S,z[C]))},d=u5(c,"H",o),m=s*(d.ascent-d.descent),g=this.arg(e,"size",1),p=this.arg(e,"fit",-1),[v,b]=p===void 0?[void 0,void 0]:Array.isArray(p)?[p[0],p[1]]:[p,void 0],y=L=>{if(p===void 0)return r.size;let z=[...v!==void 0?[v/Math.max(...L.map(l),1e-9)]:[],...b!==void 0?[b/(d.cap+(L.length-1)*m)]:[],...g!==void 0?[this.num(g,"text","size")]:[]];return Math.min(...z)},M=f(Math.max(a,h.length));if(p!==void 0){let L=-1;for(let z=h.length;z<=Math.max(a,h.length);z++){let S=f(z),C=y(S);C>L*(1+1e-9)&&([M,L]=[S,C])}}let w=y(M),x=[];M.forEach((L,z)=>{for(let S of d3(c,L,{...r,size:w,valign:"baseline"}))x.push(S.map(([C,E])=>[C,E-z*m*w]))});let k=m0(x);if(!k)return[];let A=r.valign==="top"?-k[3]:r.valign==="center"?-(k[1]+k[3])/2:r.valign==="bottom"?-k[1]:r.valign==="cap"?-(d.cap*w-(M.length-1)*m*w)/2:0;return A?x.map(L=>L.map(([z,S])=>[z,S+A])):x}edges(e){let n=r=>{if(r==="out"||r==="in"||r==="flat")return r;throw new Error(`edges must be "out", "in" or "flat", got ${c0(r)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,r=this.layers.get(n);if(r&&r.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!r){let a=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...a,name:n,side:"back"}),this.layerDefs++}return n}folds(e,n){if(e===void 0)return[];let r=n===void 0?1:this.num(n,"part","fold_open");if(!Number.isFinite(r))throw new Error("fold_open must be a number");let a=Array.isArray(e)&&e.length&&Array.isArray(e[0])&&Array.isArray(e[0][0])?e:[e];return a.map((s,c)=>{if(!Array.isArray(s)||s.length!==3)throw new Error(`fold${a.length>1?`[${c}]`:""} must be [from, to, angle], as [[0, 0], [0, 60], 90]`);let[o,i]=[this.vec2(s[0],"fold",!1),this.vec2(s[1],"fold",!1)],l=this.num(s[2],"part","fold");if(Math.hypot(i[0]-o[0],i[1]-o[1])<1e-6)throw new Error("a fold needs two different points");if(!(Math.abs(l)<=180))throw new Error(`a fold's angle must be from -180 to 180, got ${c0(s[2])}`);return{from:o,to:i,angle:l*r}})}bends(e){if(e===void 0||Array.isArray(e)&&!e.length)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((r,a)=>{if(!Array.isArray(r)||r.length!==3||!r.every(i=>typeof i=="number"&&Number.isFinite(i)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${c0(r)}${n.length>1?` at ${a}`:""}`);let[s,c,o]=r;if(!(c>s))throw new Error(`a bend's x1 must be more than its x0, got ${c0(r)}`);return{x0:s,x1:c,angle:o}})}makeBuiltins(){let e=(c,o)=>Se(c.children(),o),n=c=>o=>N3(o.children(),c),r=c=>o=>{let i=this.arg(o.args,"side",0,"front");if(i!=="front"&&i!=="back")throw new Error(`side must be "front" or "back", got ${c0(i)}`);return i==="back"&&o.env.vars.set("$mirrored",!w0(this.dyn(o.env,"$mirrored"))),N3(o.children(),i==="back"?this.backLayer(c):c)};return{rect:c=>{let[o,i]=this.vec2(this.arg(c.args,"size",0,1),"size"),l=V0(this.arg(c.args,"r",-1,0))||0,h=w0(this.arg(c.args,"center",1,!1)),u=m6(o,i,l,this.segs(c.env));return O0(t1([h?u.map(([f,d])=>[f-o/2,d-i/2]):u]))},square:c=>this.builtins.rect(c),circle:c=>{let o=this.arg(c.args,"d",-1),i=o!==void 0?this.num(o,"circle","d")/2:this.num(this.arg(c.args,"r",0,1),"circle","r");return O0([Ze(i,i,this.segs(c.env)(i))])},ellipse:c=>{let o=this.arg(c.args,"d",-1),[i,l]=o!==void 0?this.vec2(o,"d").map(h=>h/2):this.vec2(this.arg(c.args,"r",0,1),"r");return O0([Ze(i,l,this.segs(c.env)(Math.max(i,l)))])},regular_polygon:c=>{let o=Math.max(3,Math.floor(this.num(this.arg(c.args,"n",0,6),"regular_polygon","n"))),i=this.num(this.arg(c.args,"r",1,10),"regular_polygon","r");if(!(o<=this.limits.maxSegments))throw new Error(`${o} corners is more than the limit of ${this.limits.maxSegments}`);return O0([Ze(i,i,o)])},star:c=>{let o=Math.max(2,Math.floor(this.num(this.arg(c.args,"n",0,5),"star","n"))),i=this.num(this.arg(c.args,"r",1,10),"star","r"),l=this.num(this.arg(c.args,"inner",2,i*.45),"star","inner");if(!(o*2<=this.limits.maxSegments))throw new Error(`${o} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<o*2;u++){let f=Math.PI/2+Math.PI*u/o,d=u%2?l:i;h.push([d*Math.cos(f),d*Math.sin(f)])}return O0(t1([h]))},polygon:c=>{let o=this.points(this.arg(c.args,"points",0),"points"),i=this.arg(c.args,"paths",1),l=Array.isArray(i)?i.map(h=>(Array.isArray(h)?h:[]).map(u=>o[V0(u)]).filter(Boolean)):[o];return O0(t1(l,"evenodd"))},path:c=>{let o=this.arg(c.args,"d",0);if(typeof o!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let i=t3(n3(o),.01),l=this.arg(c.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return w0(this.arg(c.args,"close",-1,!1))?O0(t1([...i.closed,...i.open.filter(h=>h.length>2)],l)):O2([O0(t1(i.closed,l)),H2(i.open)])},line:c=>{let o=this.vec2(this.arg(c.args,"from",0,[0,0]),"from",!1),i=this.vec2(this.arg(c.args,"to",1,[10,0]),"to",!1),l=this.arg(c.args,"width",2);if(l===void 0)return H2([[o,i]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(i[0]-o[0],i[1]-o[1]);if(!u)return D0();let f=-(i[1]-o[1])/u*(h/2),d=(i[0]-o[0])/u*(h/2);return O0(t1([[[o[0]+f,o[1]+d],[o[0]-f,o[1]-d],[i[0]-f,i[1]-d],[i[0]+f,i[1]+d]]]))},polyline:c=>{let o=this.points(this.arg(c.args,"points",0),"points"),i=w0(this.arg(c.args,"closed",1,!1));return H2([i&&o.length?[...o,o[0]]:o])},arc:c=>{let o=this.num(this.arg(c.args,"r",0,10),"arc","r"),i=this.num(this.arg(c.args,"start",1,0),"arc","start"),l=this.num(this.arg(c.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(c.env)(o)*Math.abs(l-i)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(i+(l-i)*f/h)*Math.PI/180;u.push([o*Math.cos(d),o*Math.sin(d)])}return H2([u])},text:c=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let o=this.arg(c.args,"text",0,""),i=e3(o,this.limits.maxTextLength);if(!i.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(c.args.at,i.text.length);let l=this.textOpts(c.args,c.env,i.text),h=this.arg(c.args,"path",-1),u=this.arg(c.args,"arc",-1);if(h!==void 0&&u!==void 0)throw new Error("text() takes path or arc, not both");let f=this.arg(c.args,"lines",-1),d=f===void 0?1:Math.floor(this.num(f,"text","lines"));if(!(d>=1&&d<=20))throw new Error(`lines must be from 1 to 20, got ${c0(f)}`);let m=i.text.includes(`
4252
+ `)||d>1;if(m&&(h!==void 0||u!==void 0))throw new Error("text() lays lines in a block, or along a path, not both");let g,p=this.num(this.arg(c.args,"line_spacing",-1,1),"text","line_spacing");if(!(p>0))throw new Error("line_spacing must be more than 0");let v=this.arg(c.args,"weld",-1,!1),b=typeof v=="number"?v>0:w0(v),y=typeof v=="number"?v:void 0,M=this.arg(c.args,"underline",-1),w=M===void 0?0:this.num(M,"text","underline");if(!(w>=0))throw new Error("underline must be a height, 0 or more");if(w>0&&!b)throw new Error("underline goes with weld = true");if(b&&(m||h!==void 0||u!==void 0))throw new Error("weld = true is for one line of text, not lines or a path");if(b){let A=B8(this.opts.fonts,i.text,l,w,y);g=A.polys,A.loose.length&&this.warn(`text(): welded, "${i.text.length>20?`${i.text.slice(0,20)}...`:i.text}" still has ${A.loose.length} loose piece${A.loose.length>1?"s":""} (${A.loose.map(L=>`in "${L}"`).join(", ")}), as an i's dot or a word apart; add underline = h or bridge = w to join ${A.loose.length>1?"them":"it"} (${t2(c.args.at,!1)})`)}else if(m)g=this.textBlock(c.args,i.text,l,d,p);else if(h!==void 0||u!==void 0){let A;if(u!==void 0){let z=this.num(u,"text","arc");if(!(z!==0&&Number.isFinite(z)))throw new Error(`arc must be a radius other than 0, got ${c0(u)}`);A=U8(z)}else if(A=this.points(h,"path"),A.length<2)throw new Error("path needs at least two points");this.arg(c.args,"halign",-1)===void 0&&(l.halign="center");let L=N8(this.opts.fonts,i.text,l,A);L.over>.01&&this.warn(`text(): "${i.text.length>20?`${i.text.slice(0,20)}...`:i.text}" is ${Math.round(L.over*10)/10} mm longer than its ${u!==void 0?"circle":"path"} allows, so it carries on past the end (${t2(c.args.at,!1)})`),g=L.polys}else g=d3(this.opts.fonts,i.text,l);let x=this.arg(c.args,"weight",-1),k=this.arg(c.args,"bridge",-1);if(x!==void 0&&x!=="regular"){let A=x==="bold"?.035*l.size:this.num(x,"text","weight");A&&(g=a0(t1(g),A,"round"))}if(k!==void 0&&(g=t4(g,this.num(k,"text","bridge"))),w0(this.dyn(c.env,"$mirrored"))){let[A,L]=[1/0,-1/0];for(let z of g)for(let[S]of z)[A,L]=[Math.min(A,S),Math.max(L,S)];return O0(t1(g.map(z=>z.map(([S,C])=>[A+L-S,C]))))}return O0(g)},translate:c=>{let[o,i]=this.vec2(this.arg(c.args,"v",0,[0,0]),"v",!1);return e(c,[1,0,0,1,o,i])},rotate:c=>{let o=this.arg(c.args,"a",0,0),l=(Array.isArray(o)?V0(o[2]??0):this.num(o,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(c.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[m,g]=this.vec2(f,"center",!1);d=[h,u,-u,h,m-h*m+u*g,g-u*m-h*g]}return e(c,d)},scale:c=>{let[o,i]=this.vec2(this.arg(c.args,"v",0,1),"v");return e(c,[o,0,0,i,0,0])},mirror:c=>{let[o,i]=this.vec2(this.arg(c.args,"v",0,[1,0]),"v",!1),l=Math.hypot(o,i)||1,h=o/l,u=i/l;return e(c,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:c=>{let o=this.arg(c.args,"m",0);if(!Array.isArray(o)||o.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let i=o[0],l=o[1];return e(c,[i[0],l[0],i[1],l[1],i[2]??0,l[2]??0])},union:c=>c.children(),group:c=>c.children(),difference:c=>{let[o,...i]=c.childList().filter(G8);if(!o)return D0();let l=a(i,"difference");return s(o,h=>({regions:d0(h.regions,l.regions),lines:N0(h.lines,t1(l.regions),"outside")}))},intersection:c=>{let o=c.childList().filter(G8);if(!o.length)return D0();let i=p=>[...p.layers.values()].some(v=>v.regions.length),l=p=>i(p)||p.parts.some(v=>[...v.layers.values()].some(b=>b.regions.length)),h=p=>[p.layers,...p.parts.map(v=>v.layers)].flatMap(v=>[...v].flatMap(([b,y])=>b===a2?[]:y.regions)),u=p=>{let v;for(let b of o){if(b===p||!l(b))continue;let y=t1(h(b));v=v?G1(v,y):y}return v},f=o[0],d=o.every(l),m=u(f),g=s(f,p=>({regions:d?m?G1(p.regions,m):p.regions:[],lines:m?N0(p.lines,m,"inside"):p.lines}));for(let p of o){if(p===f)continue;if(p.parts.length)throw new Error("part() can only be the first child of intersection()");let v=u(p),b=new Map;for(let[M,w]of p.layers)w.lines.length&&b.set(M,{regions:[],lines:v?N0(w.lines,v,"inside"):w.lines});if(!b.size)continue;let y=g.parts.length===1&&!i(f)?g.parts[0]:void 0;if(y){let M=new Map(y.layers);for(let[w,x]of b){let k=M.get(w);M.set(w,{regions:k?.regions??[],lines:[...k?.lines??[],...x.lines]})}g={layers:g.layers,parts:[{...y,layers:M}]}}else g=O2([g,{layers:b,parts:[]}])}return f.parts.forEach((p,v)=>{let b=[...p.layers.values()].some(M=>M.regions.length),y=[...g.parts[v]?.layers.values()??[]].some(M=>M.regions.length);b&&!y&&this.warn(`intersection() leaves part "${p.name}" with nothing to cut: ${d?"its other children cover none of it":"a child of lines alone leaves no area; to clip lines to the part, put the intersection() inside it"} (${t2(c.args.at,!1)})`)}),g},hull:c=>{let o=c.children(),i=l=>{let h=[],u="cut",f=!0;for(let[m,g]of l){f&&(g.regions.length||g.lines.length)&&(u=m,f=!1);for(let p of[...g.regions,...g.lines])for(let v of p)h.push(v)}let d=$5(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:i(o.layers),parts:o.parts.map(l=>({...l,layers:i(l.layers)}))}},offset:c=>{let o=this.arg(c.args,"r",0),i=this.arg(c.args,"delta",-1),l=w0(this.arg(c.args,"chamfer",-1,!1)),h=o!==void 0?this.num(o,"offset","r"):this.num(i??0,"offset","delta"),u=o!==void 0?"round":l?"square":"miter";return s(c.children(),f=>({regions:a0(f.regions,h,u),lines:f.lines}))},pattern:c=>{let[o,i]=this.vec2(this.arg(c.args,"spacing",0,10),"spacing"),l=this.num(this.arg(c.args,"stagger",1,0),"pattern","stagger");if(!(o>0&&i>0))throw new Error("spacing must be more than 0");let[h,...u]=c.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=t1(a(u,"pattern").regions),d=Q0(h.layers),m=m0(f);if(!d||!m)return D0();let g=Math.floor((m[1]-d[3])/i),p=Math.ceil((m[3]-d[1])/i),v=Math.floor((m[0]-d[2])/o)-1,b=Math.ceil((m[2]-d[0])/o)+1,y=(p-g+1)*(b-v+1);if(!(y<=this.limits.maxParts*10))throw new Error(`the pattern would have ${y} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(c.args.at,y);let M=E0(f).map(L=>({polys:L,box:m0(L)})),w=f,x=(L,z)=>{let S=0;for(let C of w)for(let E=0,I=C.length-1;E<C.length;I=E++){let[H,T]=C[I],[O,_]=C[E];T<=z?_>z&&(O-H)*(z-T)-(L-H)*(_-T)>0&&S++:_<=z&&(O-H)*(z-T)-(L-H)*(_-T)<0&&S--}return S!==0},k=new Map,A=(L,z)=>{let S=k.get(L)??{regions:[],lines:[]};for(let C of z.regions)S.regions.push(C);for(let C of z.lines)S.lines.push(C);k.set(L,S)};for(let L=g;L<=p;L++)for(let z=v;z<=b;z++){let S=z*o+(L%2?l*o:0),C=L*i,E=[d[0]+S,d[1]+C,d[2]+S,d[3]+C];if(E[2]<m[0]||E[0]>m[2]||E[3]<m[1]||E[1]>m[3])continue;let I=M.filter(D=>!(E[2]<D.box[0]||E[0]>D.box[2]||E[3]<D.box[1]||E[1]>D.box[3]));if(!I.length)continue;w=I.length===M.length?f:I.flatMap(D=>D.polys);let H=[x(E[0],E[1]),x(E[2],E[1]),x(E[2],E[3]),x(E[0],E[3])],T=w.some(D=>D.some((G,V)=>il(D[V?V-1:D.length-1],G,E))),O=H.every(Boolean)&&!T,_=[1,0,0,1,S,C];for(let[D,G]of Se({layers:h.layers,parts:[]},_).layers)A(D,O?G:{regions:G1(G.regions,w),lines:N0(G.lines,w,"inside")})}return{layers:k,parts:[]}},spline:c=>{let o=this.points(this.arg(c.args,"points",0),"points"),i=this.arg(c.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(c.args,"steps",-1,8),"spline","steps"))),h=w0(this.arg(c.args,"closed",-1,!1));if(!(o.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=d4(o,l,h);if(i===void 0)return H2([u]);let f=this.num(i,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return O0(t1(G2([u],f)))},hatch:c=>{let o=this.num(this.arg(c.args,"angle",0,45),"hatch","angle"),i=this.num(this.arg(c.args,"pitch",1,5),"hatch","pitch"),l=this.arg(c.args,"width",2);if(!(i>0))throw new Error("pitch must be more than 0");let h=t1(a([c.children()],"hatch").regions),u=m0(h);if(!u)return D0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],m=Math.hypot(u[2]-u[0],u[3]-u[1])/2+i,g=o*Math.PI/180,[p,v]=[Math.cos(g),Math.sin(g)],[b,y]=[-v,p],M=Math.ceil(m/i);if(!(2*M+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(c.args.at,2*M+1);let w=[],x=Math.round((f*b+d*y)/i);for(let A=x-M;A<=x+M;A++){let L=A*i-(f*b+d*y),[z,S]=[f+b*L,d+y*L];w.push([[z-p*m,S-v*m],[z+p*m,S+v*m]])}if(l===void 0)return H2(N0(w,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return O0(G1(t1(G2(w,k).map(A=>A)),h))},flow:c=>{let o=this.arg(c.args,"field",0),i=this.num(this.arg(c.args,"spacing",1,2),"flow","spacing");if(!(i>0))throw new Error("spacing must be more than 0");let l=this.num(this.arg(c.args,"step",2,Math.min(.5,i/4)),"flow","step");if(!(l>0&&l<=i))throw new Error("step must be more than 0 and at most the spacing");let h=this.num(this.arg(c.args,"min_length",-1,2*i),"flow","min_length"),u=this.num(this.arg(c.args,"seed",-1,1),"flow","seed"),f=t1(a([c.children()],"flow").regions),d=m0(f);if(!d)return D0();let m=b=>[Math.cos(b*j8),Math.sin(b*j8)],g;if(typeof o=="number"){let b=m(o);g=()=>b}else{let b=this.fieldFn(o,"flow",c.env,c.args.at);g=y=>{let M=b(y);if(M===void 0)return null;if(typeof M=="number"&&Number.isFinite(M))return m(M);if(Array.isArray(M)&&typeof M[0]=="number"&&typeof M[1]=="number"&&Number.isFinite(M[0])&&Number.isFinite(M[1])){let w=Math.hypot(M[0],M[1]);return w>1e-12?[M[0]/w,M[1]/w]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${c0(M)}`)}}if(!((d[2]-d[0])/i*((d[3]-d[1])/i)<=this.limits.maxPoints/10))throw new Error("spacing is too small for the area");let v=p6({spacing:i,step:l,minLength:h,seed:u,box:d,inside:b6(f),dir:g,tick:()=>this.tick(c.args.at),maxPoints:this.limits.maxPoints});return H2(N0(v,f,"inside"))},contours:c=>{let o=this.arg(c.args,"field",0),i=this.fieldFn(o,"contours",c.env,c.args.at),l=this.arg(c.args,"levels",1,10),h=this.arg(c.args,"interval",-1),u=this.num(this.arg(c.args,"cell",-1,1),"contours","cell");if(!(u>0))throw new Error("cell must be more than 0");let f=t1(a([c.children()],"contours").regions),d=m0(f);if(!d)return D0();let m=Math.ceil((d[2]-d[0])/u)+1,g=Math.ceil((d[3]-d[1])/u)+1;if(!(m*g<=this.limits.maxPoints/2))throw new Error(`a cell of ${u} samples the area at ${m*g} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let p=new Float64Array(m*g),v=1/0,b=-1/0;for(let x=0;x<g;x++)for(let k=0;k<m;k++){let A=i([d[0]+k*u,d[1]+x*u]);if(A===void 0){p[x*m+k]=NaN;continue}if(typeof A!="number"||!Number.isFinite(A))throw new Error(`field() must give a number or undef, got ${c0(A)}`);p[x*m+k]=A,v=Math.min(v,A),b=Math.max(b,A)}if(!(v<=b))return D0();let y;if(h!==void 0){let x=this.num(h,"contours","interval");if(!(x>0))throw new Error("interval must be more than 0");let k=Math.ceil(v/x),A=Math.floor(b/x);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(A))throw new Error(`the heights are too large for an interval of ${x}`);let L=Math.max(0,A-k+1);if(!(L<=1e4))throw new Error(`interval ${x} gives ${L} levels: use a larger interval`);y=Array.from({length:L},(z,S)=>(k+S)*x)}else if(Array.isArray(l))y=l.map(x=>this.num(x,"contours","levels"));else{let x=Math.floor(this.num(l,"contours","levels"));if(!(x>=1&&x<=1e4))throw new Error("levels must be 1 to 10000");y=Array.from({length:x},(k,A)=>v+(b-v)*(A+1)/(x+1))}let M=[],w=0;for(let x of y){this.tick(c.args.at,Math.ceil(m*g/100));let k=g6(p,m,g,d[0],d[1],u,x),A=k.reduce((L,z)=>L+z.length,0);if(!((w+=A)<=this.limits.maxPoints))throw new Error(`the contour lines have more than ${this.limits.maxPoints} points, the limit: use fewer levels or a larger cell`);this.spend(A);for(let L of k)M.push(L)}return H2(N0(M,f,"inside"))},occlude:c=>{let o;this.occluding++;try{o=c.childItems()}finally{this.occluding--}let i=u=>this.layers.get(u)?.mode??"cut",l=[],h=[];for(let u=o.length-1;u>=0;u--){let f=o[u];if(f.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[g,p]of f.layers){if(g===a2)continue;let v=i(g);!h.length||v==="cut"||v==="guide"?d.set(g,p):v==="line"?d.set(g,{regions:[],lines:N0([...p.lines,...t1(p.regions).map(b=>[...b,b[0]])],h,"outside")}):d.set(g,{regions:d0(p.regions,h),lines:N0(p.lines,h,"outside")})}l.push({layers:d,parts:[]});let m=[...f.layers].filter(([g])=>i(g)!=="guide").flatMap(([,g])=>g.regions);m.length&&(h=t1([...h,...m]))}return O2(l.reverse())},hide:c=>this.occluding?O0(t1(a([c.children()],"hide").regions),a2):(this.warn(`hide() only works inside occlude(); it draws nothing (${t2(c.args.at,!1)})`),D0()),paint:c=>{let o=this.arg(c.args,"layers",0);if(o!==void 0&&(!Array.isArray(o)||o.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let i=c.childList(),l=[],h=[],u=[];for(let f=i.length-1;f>=0;f--){let d=i[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let m=h,g=t1(a([d],"paint").regions);u[f]=g,h=m.length?t1([...m,...g]):g;let p=Array.isArray(o)?o[f]:void 0;if(p!=="")if(p!==void 0){this.layers.has(p)||this.layers.set(p,{name:p,mode:"fill",color:"#000000"}),this.layerDefs++,l.push(O0(m.length?d0(g,m):g,p));let v=d.layers.get(a2);v&&l.push({layers:new Map([[a2,v]]),parts:[]})}else l.push(m.length?s(d,v=>({regions:d0(v.regions,m),lines:N0(v.lines,m,"outside")})):d)}return this.invisiblePaint(i,u,o,c.args.at),O2(l.reverse())},measure:c=>{let o=w0(this.arg(c.args,"draw",0,!1)),i=c.childSeq((l,h)=>{if(l!==0)return;let u=Q0(h.layers)??m0(h.parts.flatMap(v=>[...v.layers.values()].flatMap(b=>[...b.regions,...b.lines])));c.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(v=>v.layers)],d=v=>this.layers.get(v)?.mode??(v==="cut"||v==="guide"?v:void 0),m=f.flatMap(v=>[...v].filter(([b])=>d(b)==="cut").flatMap(([,b])=>b.regions)),g=m.length?m:f.flatMap(v=>[...v].filter(([b])=>d(b)!=="guide"&&d(b)!=="paint").flatMap(([,b])=>b.regions)),p=We(t1(g));c.env.vars.set("$area",p.area),c.env.vars.set("$centroid",p.area>0?p.centroid:void 0)});return O2(o?i:i.slice(1))},fill_holes:c=>{let o=this.arg(c.args,"min_area",0),i=o===void 0?1/0:this.num(o,"fill_holes","min_area");return s(c.children(),l=>({regions:t1(l.regions).filter(h=>!(z1(h)<0&&-z1(h)<i)),lines:l.lines}))},join_islands:c=>{let o=this.num(this.arg(c.args,"width",0,1),"join_islands","width");if(!(o>0))throw new Error("join_islands(): width must be more than 0");let i=c.children(),l=h=>new Map([...h].map(([u,f])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:t4(f.regions,o),lines:f.lines}:f]));return{layers:l(i.layers),parts:i.parts.map(h=>({...h,layers:l(h.layers)}))}},largest:c=>{let o=Math.floor(this.num(this.arg(c.args,"n",0,1),"largest","n"));if(!(o>=1))throw new Error("largest(): n must be 1 or more");let i=u=>E0(u).map(f=>({g:f,a:f.reduce((d,m)=>d+z1(m),0)})).sort((f,d)=>d.a-f.a).slice(0,o).flatMap(({g:f})=>f),l=c.children(),h=u=>new Map([...u].map(([f,d])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:i(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(u=>({...u,layers:h(u.layers)}))}},close:c=>{let o=this.num(this.arg(c.args,"r",0,.5),"close","r");return s(c.children(),i=>({regions:a0(a0(i.regions,o,"round"),-o,"round"),lines:i.lines}))},stroke:c=>{let o=this.num(this.arg(c.args,"width",0,1),"stroke","width");return s(c.children(),i=>({regions:t1([...i.regions,...G2(i.lines,o)]),lines:[]}))},outline:c=>s(c.children(),o=>({regions:[],lines:[...o.lines,...t1(o.regions).map(i=>[...i,i[0]])]})),cut:n("cut"),score:r("score"),engrave:r("engrave"),guide:n("guide"),layer:c=>{let o=this.arg(c.args,"name",0);if(typeof o!="string"||!o)throw new Error("layer() needs a name");let i=this.arg(c.args,"mode",1),l=this.arg(c.args,"color",2),h=this.layers.get(o),u=this.arg(c.args,"order",-1),f=this.arg(c.args,"bleed",-1);if(i!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${o}" is the back of layer "${o.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let m=i??h?.mode??"line";if(!["cut","line","fill","guide","paint"].includes(m))throw new Error('mode must be "cut", "line", "fill", "guide" or "paint"');let g=k0(l??h?.color??"#00aa00"),p=/^#[0-9a-fA-F]{6}$/.test(g)?g:K3(g);if(!p)throw new Error(`color must look like "#00aa00" or be a colour's name, as "red", got ${c0(g)}`);let v=u===void 0?h?.order:this.num(u,"layer","order"),b=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(b!==void 0&&!(b>=0))throw new Error("bleed must be 0 or more");if(b&&(m==="cut"||m==="paint"))throw new Error(`a ${m} layer has no bleed`);this.layerDefs++;let y={name:o,mode:m,color:p,...v!==void 0&&{order:v},...b!==void 0&&{bleed:b}};this.layers.set(o,y);let M=this.layers.get(`${o}-back`);if(M?.side==="back"){if(m==="cut")throw new Error(`layer "${o}" already has marks on the back face, so it cannot become a cut layer`);this.layers.set(M.name,{...y,name:M.name,side:"back"})}}let d=this.arg(c.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${c0(d)}`);if(d==="back"&&this.layers.get(o)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&c.env.vars.set("$mirrored",!w0(this.dyn(c.env,"$mirrored"))),N3(c.children(),d==="back"?this.backLayer(o):o)},part:c=>{let o=k0(this.arg(c.args,"name",0,"part")),i=this.arg(c.args,"qty",1,1),l=typeof i=="number"?Math.floor(i):1;if(!(l>=0))throw new Error(`qty must be 0 or more, got ${c0(i)}`);if(l===0)return{layers:new Map,parts:[]};let h=this.arg(c.args,"stack",-1),u=h===void 0?1:Math.floor(this.num(h,"part","stack"));if(!(u>=1))throw new Error("stack must be 1 or more");if(this.copies+=l*u,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let f=this.arg(c.args,"at",-1),d=this.arg(c.args,"rotate",-1),m=this.arg(c.args,"glue",-1),g=m===void 0?void 0:k0(m),p=k0(this.arg(c.args,"face",-1,"top"));if(p!=="top"&&p!=="bottom")throw new Error(`face must be "top" or "bottom", got ${c0(p)}`);let v=this.frame!==s4&&g===void 0,b=this.arg(c.args,"bend",-1),y=this.arg(c.args,"fold",-1),M=this.folds(y,this.arg(c.args,"fold_open",-1));if(M.length&&b!==void 0)throw new Error("a part bends on living hinges or folds, not both");let w=w0(this.arg(c.args,"press_fit",-1,!1));if(w&&g===void 0)throw new Error('press_fit goes with glue = "host"');let x=this.arg(c.args,"split",-1),k=x===void 0||x===!1?void 0:x===!0?!0:this.vec2(x,"split",!1);if(Array.isArray(k)&&!(k[0]>0&&k[1]>0))throw new Error("split must be true, or [width, height] more than 0");if(k&&(b!==void 0||M.length))throw new Error("a part that bends or folds cannot be split");let A=this.arg(c.args,"hang",-1),L=this.arg(c.args,"cord",-1),z=A===void 0?void 0:{at:this.vec2(A,"hang",!1),cord:L===void 0?0:this.num(L,"part","cord")};if(z&&!(z.cord>=0&&Number.isFinite(z.cord)))throw new Error(`cord must be a length, 0 or more, got ${c0(L)}`);if(L!==void 0&&!z)throw new Error("cord goes with hang = [x, y]");if(z&&(f===void 0||g!==void 0||b!==void 0||M.length))throw new Error("a hanging part needs at, the point it hangs from, and no glue, bend or fold");let S=f===void 0&&d===void 0&&!v&&g===void 0&&b===void 0&&y===void 0?void 0:this.placements(f,d,l),C=this.arg(c.args,"material",-1);C!==void 0&&c.env.vars.set("$material",k0(C));let E=this.thickness(c.env),I=this.arg(c.args,"paint",-1),H=I===void 0?void 0:K3(k0(I));if(I!==void 0&&!H)throw new Error(`paint must look like "#c8372d" or be a colour's name, as "red", got ${c0(I)}`);let T=this.arg(c.args,"pieces",-1);if(T!==void 0&&T!=="any"&&!(typeof T=="number"&&Number.isInteger(T)&&T>=1))throw new Error(`pieces must be a whole number, 1 or more, or "any", got ${c0(T)}`);let O=T;S&&(v||u>1)&&(S=S.flatMap(Q=>{let W=g===void 0?T1(this.frame,R0(Q)):R0(Q),$1=g!==void 0&&p==="bottom"?-E:E;return Array.from({length:u},(K,k1)=>({...Q,matrix:T1(W,U0(0,0,k1*$1))}))}));let _=this.arg(c.args,"mirror",-1,!1),D;if(Array.isArray(_)){if(_.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${_.length}`);D=_.map(Q=>w0(Q))}else D=Array.from({length:l},()=>w0(_));let G=D.some(Q=>Q)&&!D.every(Q=>Q);if(G&&g!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let V=D[0],U=Q=>{let W=c.env.vars.get("$mirrored"),$1=c.env.vars.has("$mirrored");Q&&c.env.vars.set("$mirrored",!0);try{let K=c.children();return Q?Se(K,[-1,0,0,1,0,0]):K}finally{Q&&($1?c.env.vars.set("$mirrored",W):c.env.vars.delete("$mirrored"))}},J=c.env.vars.has("$copy"),n1=c.env.vars.get("$copy");c.env.vars.set("$copy",0);let m1=this.copyReads,M1,c1;try{if(M1=U(V),l>1&&this.copyReads!==m1){let Q=new Map;for(let W=0;W<l;W++){c.env.vars.set("$copy",W);let $1=W===0&&D[0]===V?M1:U(D[W]),K=`${D[W]}|${JSON.stringify([...$1.layers].map(([L1,A0])=>[L1,A0.regions.map(P=>P.map(([j,s1])=>[Math.round(j*1e4),Math.round(s1*1e4)])),A0.lines.map(P=>P.map(([j,s1])=>[Math.round(j*1e4),Math.round(s1*1e4)]))]))}`,k1=Q.get(K);k1?k1.copies.push(W+1):Q.set(K,{layers:$1.layers,flip:D[W],copies:[W+1]})}c1=[...Q.values()]}}finally{J?c.env.vars.set("$copy",n1):c.env.vars.delete("$copy")}let C1=this.bends(b),h1=this.arg(c.args,"on",-1),B1=this.arg(c.args,"slots",-1),$=B1===void 0?void 0:(Array.isArray(B1)?B1:[B1]).map(Q=>{if(typeof Q!="string")throw new Error("slots must be part names");return Q}),B=this.num(this.arg(c.args,"clearance",-1,.1),"part","clearance"),a1=this.arg(c.args,"slot_extra",-1),b1=a1===void 0?void 0:this.vec2(a1,"slot_extra",!1),o1=this.arg(c.args,"bores",-1),p1=o1===void 0?void 0:(Array.isArray(o1)?o1:[o1]).map(Q=>{if(typeof Q!="string")throw new Error("bores must be hardware labels or kinds");return Q}),K1=this.arg(c.args,"halving",-1),Q1=K1===void 0?void 0:(Array.isArray(K1)?K1:[K1]).map(Q=>{if(typeof Q!="string")throw new Error("halving must be part names");return Q}),W1=this.arg(c.args,"fit",-1,"turn");if(typeof W1!="number"&&!Object.prototype.hasOwnProperty.call(W3,k0(W1)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${c0(W1)}`);let I0=typeof W1=="number"?W1:W3[k0(W1)],q=(Q,W,$1)=>{let K=$1.length===l,k1=S?.filter((L1,A0)=>$1.includes(Math.floor(A0/u)+1));return{name:o,qty:$1.length*u,layers:Q,thickness:E,kerf:this.kerf(c.env),material:k0(this.dyn(c.env,"$material")??"material"),...H&&{paint:H},...O!==void 0&&{pieces:O},...z&&{hang:W?{...z,at:[-z.at[0],z.at[1]]}:z},...k&&{split:k},...w&&{pressFit:!0},...k1?{placements:k1}:{},...u>1?{stack:u}:{},...C1.length?{bends:W?C1.map(L1=>({...L1,mirrored:!0})):C1}:{},...M.length&&{folds:W?M.map(L1=>({...L1,from:[-L1.from[0],L1.from[1]],to:[-L1.to[0],L1.to[1]]})):M},...h1!==void 0?{on:k0(h1)}:{},...$?{slots:$,clearance:B}:{},...$&&b1?{slotExtra:b1}:{},...p1?{bores:p1,fit:I0}:{},...Q1?{halving:Q1,clearance:B}:{},...this.step?{step:this.step}:{},...g!==void 0&&{glue:{host:g,face:p}},...W&&{mirrored:!0},...!K&&{copies:$1}}},Z=Q=>D.flatMap((W,$1)=>W===Q?[$1+1]:[]),e1=c1?c1.map(Q=>q(Q.layers,Q.flip,Q.copies)):G?[q(M1.layers,V,Z(V)),q(U(!V).layers,!V,Z(!V))]:[q(M1.layers,V,Z(V))];return{layers:new Map,parts:[...M1.parts,...e1]}},place:c=>{let o=this.vec3(this.arg(c.args,"at",0,[0,0,0]),"at"),i=this.vec3(this.arg(c.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=T1(l,R0({at:o,rotate:i}));try{return c.children()}finally{this.frame=l}},step:c=>{let o=k0(this.arg(c.args,"text",0,"")),i=w0(this.arg(c.args,"substeps",1,!0));if(this.stepFolded)return c.children();let l=this.step,h=l&&o?`${this.stepNames[l-1]}: ${o}`:o,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!i;try{return c.children()}finally{this.step=l,this.stepFolded=!1}},hardware:c=>{let o=k0(this.arg(c.args,"kind",0,"dowel"));s2(X2,o)===void 0&&s2(le,o)===void 0&&this.warn(`hardware(): unknown kind "${o}"; the 3D view shows it grey (${t2(c.args.at,!1)})${Oe(o,Object.keys(X2))}`);let i=k0(this.arg(c.args,"shape",-1,"rod"));if(i!=="rod"&&i!=="ball")throw new Error(`shape must be "rod" or "ball", got ${c0(i)}`);let l=this.arg(c.args,"sides",-1),h=i==="ball"||l===0,u=this.vec3(this.arg(c.args,"from",1),"from"),f=this.arg(c.args,"to",2),d=o==="tealight",m=f!==void 0?this.vec3(f,"to"):d?[u[0],u[1],u[2]+s3.height]:h?u:this.vec3(f,"to"),g=this.arg(c.args,"size",3,d?s3.diameter:6),p=typeof g=="number"?g:this.vec2(g,"size",!1);if(h){if(typeof p!="number"||!(p>0))throw new Error("a ball's size is its diameter, a number more than 0");u=m=[(u[0]+m[0])/2,(u[1]+m[1])/2,(u[2]+m[2])/2]}let v=[m[0]-u[0],m[1]-u[1],m[2]-u[2]],b=Math.abs(v[2])>.9*Math.hypot(...v),y=this.arg(c.args,"up",-1),M=y===void 0?b?[0,1,0]:[0,0,1]:this.vec3(y,"up"),w=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(w>=3&&w<=Z4))throw new Error(`sides must be from 3 to ${Z4} (or 0 for a ball), got ${c0(w)}`);if(this.pointCount+=h?2*Z4:w*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let x=this.arg(c.args,"label",-1),k=this.arg(c.args,"mass",-1),A=k===void 0?void 0:this.num(k,"hardware","mass");if(A!==void 0&&!(A>=0))throw new Error("mass must be grams, 0 or more");let L=this.frame,z=E=>[L[0]*E[0]+L[1]*E[1]+L[2]*E[2]+L[3],L[4]*E[0]+L[5]*E[1]+L[6]*E[2]+L[7],L[8]*E[0]+L[9]*E[1]+L[10]*E[2]+L[11]],S=E=>[L[0]*E[0]+L[1]*E[1]+L[2]*E[2],L[4]*E[0]+L[5]*E[1]+L[6]*E[2],L[8]*E[0]+L[9]*E[1]+L[10]*E[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);let C={kind:o,from:z(u),to:z(m),size:p,up:S(M),sides:w,step:this.step,...x!==void 0?{label:k0(x)}:{},...A!==void 0&&{mass:A}};return this.hardware.push(C),this.lights.push(...o7(C)),c.children()},light:c=>{let o=this.vec3(this.arg(c.args,"at",0,[0,0,0]),"at"),i=this.arg(c.args,"to",-1),l=i===void 0?o:this.vec3(i,"to"),h=k0(this.arg(c.args,"color",1,"warm white")),u=a7(h);if(!u)throw new Error(`color must look like "#ffd9a0" or be a colour's name, as "warm white" or "flame", got ${c0(h)}`);let f=this.num(this.arg(c.args,"lumens",2,20),"light","lumens");if(!(f>=0&&Number.isFinite(f)))throw new Error(`lumens must be 0 or more, got ${c0(f)}`);let d=w0(this.arg(c.args,"flicker",-1,!1)),m=this.arg(c.args,"label",-1);if(this.lights.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} lights, the limit`);let g=this.frame,p=v=>[g[0]*v[0]+g[1]*v[1]+g[2]*v[2]+g[3],g[4]*v[0]+g[5]*v[1]+g[6]*v[2]+g[7],g[8]*v[0]+g[9]*v[1]+g[10]*v[2]+g[11]];return this.lights.push({from:p(o),to:p(l),color:u,lumens:f,flicker:d,source:"light",step:this.step,...m!==void 0&&{label:k0(m)}}),c.children()},material:c=>{let o=this.arg(c.args,"thickness",0),i=this.arg(c.args,"kerf",1),l=this.arg(c.args,"name",2);return o!==void 0&&c.env.vars.set("$thickness",this.num(o,"material","thickness")),i!==void 0&&c.env.vars.set("$kerf",this.num(i,"material","kerf")),l!==void 0&&c.env.vars.set("$material",k0(l)),c.children()},children:c=>{let o=c.env.childCtx();if(!o)return D0();let i=this.childStmts(o.stmts),l=this.arg(c.args,"index",0),h=new _0(o.env,c.env);this.hoist(o.stmts,h);let u=new Set;if(l===void 0)i.forEach(g=>u.add(g));else for(let g of this.iterable(l,c.args.at)){let p=V0(g);i[p]?u.add(i[p]):i.length&&p>=i.length&&o.module&&o.pos&&this.warn(`${o.module}() uses children(${p}) but was given ${i.length} child${i.length===1?"":"ren"} (${t2(o.pos,!1)}). A module call takes one statement as its child: put several in braces, ${o.module}() { a(); b(); }`)}let f=[],d=this.childCache.get(o)??new Map;this.childCache.set(o,d);let m=this.childKey(h);for(let g of o.stmts)if(g.kind==="assign")this.stmt(g,h);else if(u.has(g)){let p=m&&d.get(g);if(p&&p.key===m){p.shape&&f.push(p.shape);continue}let v=this.effects(),b=this.stmt(g,h);b&&f.push(b),m&&this.effects()===v&&!b?.parts.length&&d.set(g,{key:m,shape:b})}return O2(f)},echo:c=>(this.echo(this.echoText(c.args),c.args.at),c.children()),assert:c=>(this.assert(c.args),c.children()),finger_rect:c=>{let[o,i]=this.vec2(this.arg(c.args,"size",0),"size"),l=this.edges(this.arg(c.args,"edges",1,"out")),h=this.thickness(c.env),u=this.fingerWidth(c.args,c.env,2);return this.spend(2*(Math.abs(o)+Math.abs(i))/u*4),O0(j5(o,i,l,h,u))},finger_holes:c=>{let o=this.num(this.arg(c.args,"length",0),"finger_holes","length"),i=this.edges(this.arg(c.args,"edge",1,"out"))[0];if(i==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(c.args,c.env,2);return this.spend(Math.abs(o)/l*4),O0(e7(o,i,this.thickness(c.env),l))},tslot:c=>{let o=this.num(this.arg(c.args,"d",0,3),"tslot","d"),i=this.num(this.arg(c.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(c.args,"nut",2,[o*1.85,o*.8]),"nut",!1),u=this.num(this.arg(c.args,"nut_at",3,i/2),"tslot","nut_at");return O0(t1(t7(o,i,l,h,u)))},living_hinge:c=>{let[o,i]=this.vec2(this.arg(c.args,"size",0),"size"),l=this.num(this.arg(c.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(c.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(c.args,"cut",3,Math.max(h*2,(i-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||u<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(o)/l+1)*(Math.abs(i)/(u+h)+2)*2),H2(n7(o,i,l,h,u))}};function a(c,o){let i={regions:[],lines:[]};for(let l of c){if(l.parts.length)throw new Error(`part() can only be the first child of ${o}()`);for(let[h,u]of l.layers)if(h!==a2)for(let f of u.regions)i.regions.push(f)}return i}function s(c,o){let i=l=>{let h=new Map;for(let[u,f]of l)h.set(u,o(f));return h};return{layers:i(c.layers),parts:c.parts.map(l=>({...l,layers:i(l.layers)}))}}}};var p3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},tn=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/"/g,"&quot;");function nn(t,e){let n=[];for(let[r,a]of t){let s=[p3(r),p3(a)],c=n[n.length-1];(!c||c[0]!==s[0]||c[1]!==s[1])&&n.push(s)}for(;e&&n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n}var g3=(t,e)=>`M${nn(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function ft(t,e){let n=[];for(let r of e){let a=[],s=[];for(let o of t){let i=o.layers.get(r.name);if(i){for(let l of i.lines)a.push(g3(l,!1));for(let l of i.regions)s.push(l)}}let c=D3(s).map(o=>g3(s[o],!0));(a.length||c.length)&&n.push({name:r.name,mode:r.mode,color:r.color,d:[...a,...c].join(""),regions:c.join(""),lines:a.join("")})}return n}function dt(t,e,n,r){let a=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${p3(e)}mm" height="${p3(n)}mm" viewBox="0 0 ${p3(e)} ${p3(n)}">`];for(let s of r){let c=[],o=[],i=[];for(let h of t){let u=h.layers.get(s.name);if(!u)continue;let f=` data-part="${tn(h.part)}"`;if(s.mode==="fill"){u.regions.length&&o.push(`<path${f} d="${u.regions.map(d=>g3(d,!0)).join("")}"/>`);for(let d of u.lines)o.push(`<path${f} fill="none" stroke="${s.color}" stroke-width="0.1" d="${g3(d,!1)}"/>`);continue}for(let d of u.lines)c.push(`<path${f} d="${g3(d,!1)}"/>`);for(let d of u.regions)i.push([d,f])}for(let h of D3(i.map(([u])=>u)))c.push(`<path${i[h][1]} d="${g3(i[h][0],!0)}"/>`);if(!c.length&&!o.length)continue;let l=s.mode==="fill"?`fill="${s.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${s.color}" stroke-width="0.1"${s.mode==="guide"?' stroke-dasharray="1 1"':""}`;a.push(`<g id="${tn(s.name)}" inkscape:groupmode="layer" inkscape:label="${tn(s.name)}" data-mode="${s.mode}" ${l}>`,...c,...o,"</g>")}return a.push("</svg>",""),a.join(`
4253
+ `)}var gl={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},vl=t=>{let e=gl[t.toLowerCase()];if(e)return e;let[n,r,a]=[1,3,5].map(s=>parseInt(t.slice(s,s+2),16));return n>r&&n>a?1:r>n&&r>a?3:a>n&&a>r?5:7};function bl(t){let e=o=>o.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(f5.map(o=>o.name)),r=new Set(t.map(o=>e(o.name))),a=new Set,s=new Map,c=[...t.filter(o=>n.has(o.name)),...t.filter(o=>!n.has(o.name))];for(let o of c){let i=e(o.name);if(a.has(i)){let l=2;for(;r.has(`${i}_${l}`)||a.has(`${i}_${l}`);)l++;i=`${i}_${l}`}a.add(i),s.set(o.name,i)}return s}function rn(t,e,n,r){let a=[],s=(i,l)=>a.push(String(i),String(l)),c=bl(r);s(0,"SECTION"),s(2,"HEADER"),s(9,"$ACADVER"),s(1,"AC1009"),s(9,"$INSUNITS"),s(70,4),s(0,"ENDSEC"),s(0,"SECTION"),s(2,"TABLES"),s(0,"TABLE"),s(2,"LAYER"),s(70,r.length);for(let i of r)s(0,"LAYER"),s(2,c.get(i.name)),s(70,0),s(62,vl(i.color)),s(6,"CONTINUOUS");s(0,"ENDTAB"),s(0,"ENDSEC"),s(0,"SECTION"),s(2,"ENTITIES");let o=(i,l,h)=>{s(0,"POLYLINE"),s(8,i),s(66,1),s(10,0),s(20,0),s(30,0),s(70,h?1:0);for(let[u,f]of nn(l.map(([d,m])=>[d,n-m]),h))s(0,"VERTEX"),s(8,i),s(10,u),s(20,f),s(30,0);s(0,"SEQEND"),s(8,i)};for(let i of r){let l=c.get(i.name),h=[];for(let u of t){let f=u.layers.get(i.name);if(f){for(let d of f.lines)o(l,d,!1);for(let d of f.regions)h.push(d)}}for(let u of D3(h))o(l,h[u],!0)}return s(0,"ENDSEC"),s(0,"EOF"),a.join(`
4251
4254
  `)+`
4252
4255
  `}function K8(t){switch(t.kind){case"num":return t.unit?{ok:!1}:{ok:!0,value:t.value};case"str":case"bool":return{ok:!0,value:t.value};case"unary":return t.op==="-"&&t.arg.kind==="num"?{ok:!0,value:-t.arg.value}:{ok:!1};case"list":{let e=[];for(let n of t.items){if(n.kind!=="item")return{ok:!1};let r=K8(n.expr);if(!r.ok||typeof r.value!="number")return{ok:!1};e.push(r.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function yl(t,e){if(!/^[A-Za-z_][A-Za-z0-9_]*\s*\(.*\)$/.test(e.trim()))return;let n=t.split(`
4253
4256
  `).filter(r=>/^\s*(use|include)\s*<kerf\/[A-Za-z0-9_/-]+>/.test(r)).map(r=>/^\s*(?:use|include)\s*<kerf\/[A-Za-z0-9_/-]+>/.exec(r)[0].trim()).map(r=>r.replace(/^include/,"use"));try{let a=new K2({maxSteps:2e6}).run(n2(`${n.join(`
4254
4257
  `)}
4255
- __options = ${e};`).program).globals.get("__options").value;return!Array.isArray(a)||!a.length?void 0:a.map(s=>Array.isArray(s)&&s.length===2?{name:String(s[1]),value:typeof s[0]=="number"?s[0]:String(s[0])}:{name:String(s),value:typeof s=="number"?s:String(s)})}catch{return}}function Z8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function v3(t){let{program:e,comments:n}=n2(t),r=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),a=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),s=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),c=[],o=new Set;for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let l=K8(i.value);if(!l.ok)continue;let h=r.filter(y=>y.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(h.toLowerCase()==="hidden")continue;let u=a.get(i.pos.line),f=s.get(i.pos.line-1)??"",d=l.value,m={name:i.name,caption:f,group:h,type:typeof d=="number"||Array.isArray(d)?"number":typeof d=="boolean"?"boolean":"string",initial:d,span:i.span},p=u?/^((?:\[.*\](?:\s+drive)?)?)\s*when\s+(.+)$/.exec(u.trim()):null;p&&(m.when=p[2].trim()),p?.[1]&&o.add(m);let g=p?p[1].trim():u?.trim(),v=g?/^\[(.*)\](\s+drive)?$/.exec(g):null;v?.[2]&&m.type==="number"&&typeof d=="number"&&(m.drive=!0);let b=v?yl(t,v[1]):void 0;if(b)m.options=b;else if(v){let y=v[1];if(y.includes(",")||/[a-zA-Z"]/.test(y)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(y))m.options=y.split(",").map(M=>{let[w,x]=M.split(":").map(L=>L.trim().replace(/^"|"$/g,"")),k=Z8(w),A=m.type==="number"&&k!==void 0?k:w;return{name:x??w,value:A}});else{let M=y.split(":").map(Z8);M.every(w=>w!==void 0)&&(M.length===1?m.max=M[0]:M.length===2?(m.min=M[0],m.max=M[1]):(m.min=M[0],m.step=M[1],m.max=M[2]))}}c.push(m)}for(let i of c){if(i.when===void 0)continue;if(!o.has(i)&&typeof J8(i.when)=="string"){delete i.when;continue}let l=xl(i.when,c);l&&(i.whenProblem=l,delete i.when)}return{parameters:c}}function J8(t){try{let e=n2(`when__ = (${t});`).program.body[0];return e?.kind==="assign"?e.value:"it is not an expression"}catch(e){return e.message.replace(/\s*\(line \d+, column \d+\)$/,"")}}var Y8=new Set(["==","!=","<","<=",">",">=","&&","||","+","-","*","/","%","!"]);function xl(t,e){let n=J8(t);if(typeof n=="string")return`its condition (${t}) is not an expression: ${n}`;let r=new Set(e.map(c=>c.name)),a=c=>{switch(c.kind){case"num":case"str":case"bool":case"undef":return;case"var":return r.has(c.name)?void 0:`uses ${c.name}, which is not a setting`;case"list":for(let o of c.items){if(o.kind!=="item")return"uses a list comprehension";let i=a(o.expr);if(i)return i}return;case"unary":return Y8.has(c.op)?a(c.arg):`uses ${c.op}`;case"binary":return Y8.has(c.op)?a(c.left)??a(c.right):`uses ${c.op}`;case"ternary":return a(c.cond)??a(c.then)??a(c.else);case"index":return a(c.target)??a(c.index);default:return"uses more than settings, values and operators"}},s=a(n);return s?`its condition (${t}) ${s}`:void 0}function dt(t,e,n){if(t.when===void 0)return!0;let r=Object.fromEntries(n.map(s=>[s.name,s.initial])),a=Object.fromEntries(Object.entries(e).filter(([s])=>Object.prototype.hasOwnProperty.call(r,s)));try{let s=[...n.map(o=>`${o.name} = undef;`),`echo((${t.when}) ? 1 : 0);`];return new K2({overrides:{...r,...a},maxSteps:1e5}).run(n2(s.join(`
4256
- `)).program).echoes[0]!=="0"}catch{return!0}}var Q8=(t,e)=>{let n=0;for(let r=1;r<t.length;r++)n+=Math.hypot(t[r][0]-t[r-1][0],t[r][1]-t[r-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},v0=t=>Math.round(t*100)/100;function mt(t,e={}){for(let[P,j]of Object.entries(e.params??{}))try{o4(P,j)}catch(s1){throw new i1(s1.message)}let{program:n}=n2(t),r=new Set(n.body.flatMap(P=>P.kind==="assign"?[P.name]:[])),a=Object.keys(e.params??{}).filter(P=>!P.startsWith("$")&&!r.has(P)),s=e.fonts?new lt(e.fonts,e.defaultFont):void 0,c=new K2({overrides:e.params,resolve:e.resolve,fonts:s,maxSteps:e.maxSteps,limits:e.limits}),o=c.limits,i;try{i=c.run(n)}catch(P){let j=P instanceof RangeError?new i1(/call stack/i.test(P.message)?"Recursion too deep: check that it stops, or use fold(), scan() or a list comprehension to go through a long list":"A value grew too large. Is a list or string doubling without end?"):P;throw j instanceof i1&&(j.echoes=c.echoes,j.warnings=[...c.warnings],s?.missing.size&&(j.missingFonts=[...s.missing])),j}let l=P=>i.globals.get(P).value,h=i.warnings;for(let P of a)h.push(`Setting "${P}" is not a variable of the program, so it is ignored.${Oe(P,r)}`);let u=i.layers,f=P=>u.get(P)?.mode??"line",d=[...i.shape.parts];[...i.shape.layers.values()].some(P=>P.regions.length||P.lines.length)&&d.unshift({name:"part",qty:1,layers:i.shape.layers,thickness:l("$thickness")===void 0?3:V0(l("$thickness")),kerf:l("$kerf")===void 0?0:V0(l("$kerf")),material:k0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let p=new Set;for(let P of d)p.has(P.name)||[...P.layers].some(([s1,w1])=>s1!==a2&&(w1.regions.length||w1.lines.length))||(p.add(P.name),h.some(s1=>s1.includes(`leaves part "${P.name}" with nothing to cut`))||h.push(`Part "${P.name}" is empty: nothing drawn in it is left to cut.`));try{for(let P of v3(t).parameters)P.whenProblem&&h.push(`Setting ${P.name} is always shown: ${P.whenProblem} (line ${t.slice(0,P.span[0]).split(`
4257
- `).length})`)}catch{}let g=P=>JSON.stringify([P.thickness,P.material,[...P.layers].map(([j,s1])=>[j,s1.regions.map(w1=>w1.map(([R1,F1])=>[Math.round(R1*100),Math.round(F1*100)])),s1.lines.map(w1=>w1.map(([R1,F1])=>[Math.round(R1*100),Math.round(F1*100)]))])]),v=new Map,b=new Set;for(let P of d){let j=g(P),s1=P.copies?`${P.name}\0${P.copies.join(",")}${P.mirrored?"m":""}`:P.mirrored?`${P.name}\0mirrored`:P.name,w1=v.get(s1);w1===void 0?v.set(s1,j):w1!==j&&b.add(P.name)}for(let P of b)h.push(`Two different parts are named "${P}"; slots, glue and on = find parts by name, so give each its own.`);Sl(d,f,i.hardware);{let P=e.sheet??(i.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet")),j=l("$knob")===void 0?12:V0(l("$knob")),s1=l("$knob_clearance")===void 0?.15:V0(l("$knob_clearance")),w1={left:o.maxParts-d.reduce((R1,F1)=>R1+F1.qty,0),max:o.maxParts};for(let R1=d.length-1;R1>=0;R1--){let F1=d[R1];if(!F1.split)continue;let u0=F1.split===!0?[P[0]-2*(e.margin??e.gap??V0(l("$gap")??3)),P[1]-2*(e.margin??e.gap??V0(l("$gap")??3))]:F1.split,n0=kl(F1,f,u0,j,s1,h,w1);d.splice(R1,1,...n0),n0.length>1&&zl(d,F1.name,n0,f)}}Ol(d,h),Pl(d,f,h),Ll(d,f,h,i.hardware),Cl(d,f,h);let y=[],M=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,w=[],x=[],k=[],A=new Set,L=new Map,z=[],S=l("$min_width"),C=S===void 0?1.5:V0(S),E=l("$label_parts")===!0,I=l("$join_lines")===!0,H=0;E&&!s&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let T=u.get("engrave-back");E&&s&&T&&T.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let O=E&&!!s&&(!T||T.side==="back");if(O){let P=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:P?.color??"#000000",side:"back"})}let _=[];for(let P of d){let j=t1([...P.layers].filter(([u1])=>f(u1)==="cut").flatMap(([,u1])=>u1.regions)),s1;if(P.bends&&j.length){let u1=1/0,E1=-1/0;for(let A1 of j)for(let[q1]of A1)u1=Math.min(u1,q1),E1=Math.max(E1,q1);for(let[A1,q1]of s4(P.bends))(A1<u1-.001||q1>E1+.001)&&h.push(`Part "${P.name}" bends from x = ${l2(A1)} to ${l2(q1)}, beyond the part (x = ${l2(u1)} to ${l2(E1)}); only the part itself bends.`)}let w1=P.folds&&j.length?d0(j,G2([...P.layers].filter(([u1])=>f(u1)==="cut").flatMap(([,u1])=>u1.lines.filter(E1=>E1.length>=2)),.2)):j;if(P.folds&&j.length){let u1=Ce(w1,P.folds,P.thickness).unused??[];for(let E1 of u1){let A1=P.folds[E1];h.push(`Part "${P.name}": the fold from [${l2(A1.from[0])}, ${l2(A1.from[1])}] to [${l2(A1.to[0])}, ${l2(A1.to[1])}] does not divide the part, so nothing folds there; run it from edge to edge, or to a cut.`)}}if(O&&j.length){s1=++H;let u1=Rl(j,String(s1),s,k0(l("$font")??""));if(u1.length){let E1=P.layers.get("engrave-back")??{regions:[],lines:[]};P.layers=new Map(P.layers).set("engrave-back",{regions:[...E1.regions,...u1],lines:E1.lines})}else h.push(`Part "${P.name}" is too small to take its number ${s1}.`)}if(C>0&&j.length){let u1=a0(a0(j,-C/2,"round"),C/2,"round"),E1=E0(d0(j,u1)).filter(A1=>A1.reduce((q1,x1)=>q1+z1(x1),0)>2*C*C);if(E1.length){let A1=E1.slice(0,3).map(q1=>{let[x1,U1,s0,S0]=Q0(new Map([["cut",{regions:q1,lines:[]}]]));return`[${v0((x1+s0)/2)}, ${v0((U1+S0)/2)}]`});h.push(`Part "${P.name}" is narrower than ${C} mm ($min_width) in ${E1.length} place${E1.length>1?"s":""}, at ${A1.join(", ")}${E1.length>3?" and more":""} in the part's coordinates.`)}}let R1=new Map,F1=[];for(let[u1,E1]of P.layers){if(u1===a2||f(u1)==="guide"&&!e.guides)continue;if(f(u1)==="paint"){let x1=u.get(u1),U1=G1(t1(E1.regions),j),s0=N0(E1.lines.filter(S0=>S0.length>=2),j,"inside");(U1.length||s0.length)&&F1.push({layer:u1,mode:"fill",color:x1.color,side:x1.side??"front",regions:U1,lines:s0});continue}let A1=t1(E1.regions),q1=E1.lines.filter(x1=>x1.length>=2);if((f(u1)==="line"||f(u1)==="guide")&&(q1=[...q1,...A1.map(x1=>[...x1,x1[0]])],A1=[]),j.length&&f(u1)!=="guide"){let x1=u.get(u1)?.bleed??0,U1=x1>0?a0(j,x1,"round"):j;f(u1)!=="cut"&&(A1=G1(A1,U1)),q1=N0(q1,U1,"inside")}I&&q1.length>1&&f(u1)!=="guide"&&(q1=v6(q1)),(A1.length||q1.length)&&R1.set(u1,{regions:A1,lines:q1})}if(_.push(...$l(P.name,R1,u)),j.length){let u1=[...F1];for(let[A1,q1]of R1){let x1=u.get(A1);if(x1?.mode==="cut"&&q1.lines.length)for(let U1 of["front","back"])u1.push({layer:A1,mode:"line",color:"#000000",side:U1,regions:[],lines:q1.lines});!x1||x1.mode!=="fill"&&x1.mode!=="line"||u1.push({layer:A1,mode:x1.mode,color:x1.color,side:x1.side??"front",regions:q1.regions,lines:q1.lines})}let E1={name:P.name,thickness:P.thickness,material:P.material,...P.paint&&{paint:P.paint},outline:w1,...u1.length&&{marks:u1}};for(let A1=0;A1<(P.placements?.length??P.qty);A1++)k.push({...E1,copy:b3(P,A1),matrix:R0({at:[0,0,0],rotate:[0,0,0]}),placed:!1});if(P.placements){let A1=new Set;P.placements.forEach((q1,x1)=>{let U1={...E1,copy:b3(P,x1),matrix:R0(q1),placed:!0,...P.bends&&{bends:P.bends},...P.folds&&{folds:P.folds},...P.step&&{step:P.step},...P.stack&&{stack:P.stack},...P.pressFit&&{pressFit:!0}};L.set(P,[...L.get(P)??[],w.length]),w.push(U1);let s0=U1.matrix.map(S0=>S0.toFixed(6)).join(",");A1.has(s0)&&A.add(U1),A1.add(s0)}),A1.size<P.placements.length&&h.push(`Copies of part "${P.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let A1=0;A1<P.qty;A1++)x.push({...E1,copy:b3(P,A1),matrix:R0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...P.step&&{step:P.step}})}let u0=E0(j),n0=u0.length;if(typeof P.pieces=="number"&&n0>0&&n0!==P.pieces)h.push(`Part "${P.name}" cuts into ${n0} separate piece${n0>1?"s":""}, not the ${P.pieces} its pieces = says.`);else if(n0>1&&P.pieces===void 0){let u1=q1=>q1.reduce((x1,U1)=>x1+z1(U1),0),A1=[...u0].sort((q1,x1)=>u1(x1)-u1(q1)).slice(1,4).map(q1=>{let[x1,U1,s0,S0]=Q0(new Map([["cut",{regions:q1,lines:[]}]]));return`[${v0(x1)}, ${v0(U1)}] to [${v0(s0)}, ${v0(S0)}]`}).join(", ");h.push(`Part "${P.name}" cuts into ${n0} separate pieces. Join them, or make them separate parts. The smaller ${n0===2?"one is":"ones are"} at ${A1}${n0>4?" and more":""}, in the part's coordinates.`)}let N1=0;for(let[u1,E1]of R1)if(f(u1)==="cut"){for(let A1 of E1.regions)N1+=Q8(A1,!0);for(let A1 of E1.lines)N1+=Q8(A1,!1)}let X1=Q0(R1)??[0,0,0,0],h0=e.kerf??P.kerf;if(!(Number.isFinite(h0)&&h0>=0))throw new i1("$kerf must be a number, 0 or more");if(!(Number.isFinite(P.thickness)&&P.thickness>0))throw new i1("$thickness must be a positive number");let g0={name:P.name,qty:P.qty,width:v0(X1[2]-X1[0]),height:v0(X1[3]-X1[1]),pieces:n0,cutLength:Math.round(N1),thickness:P.thickness,kerf:h0,material:P.material,...P.paint&&{paint:P.paint},...P.stack&&{stack:P.stack},...P.glue&&{glued:P.glue.host},...P.mirrored&&{mirrored:!0},...P.copies&&{copies:P.copies},...P.joins&&{joins:P.joins},...s1!==void 0&&{label:s1}};if(M&&M.parts.push({name:P.name,kerf:h0,qty:P.qty,...P.stack&&{stack:P.stack},...P.glue&&{glue:P.glue},...P.on&&{on:P.on},cutRegions:j.map(u1=>u1.map(([E1,A1])=>[E1,A1])),cutLines:[...R1].filter(([u1])=>f(u1)==="cut").flatMap(([,u1])=>u1.lines.map(E1=>E1.map(([A1,q1])=>[A1,q1])))}),h0>0){for(let[u1,E1]of R1)if(f(u1)==="cut"){let A1=E1.regions.filter(U1=>z1(U1)<0);E1.regions=a0(E1.regions,h0/2,"round",Math.min(.01,h0/20));let q1=E1.regions.filter(U1=>z1(U1)<0),x1=A1.length-q1.length;if(x1>0){let U1=S0=>{let[q0,T2,I2,La]=Q0(new Map([["cut",{regions:[S0],lines:[]}]]));return[(q0+I2)/2,(T2+La)/2]},s0=A1.map(U1).filter(([S0,q0])=>!q1.some(T2=>sn(T2,S0,q0))).slice(0,3).map(([S0,q0])=>`[${v0(S0)}, ${v0(q0)}]`);h.push(`Part "${P.name}": ${x1} hole${x1===1?" is":"s are"} narrower than the ${h0} mm kerf and will not be cut${s0.length?`, at ${s0.join(", ")}${x1>s0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(g0),z.push({info:g0,layers:R1,copy:u1=>b3(P,u1)})}let D=new Map;for(let[P,j]of L){if(!P.layerOf){D.set(P,j);continue}let{part:s1,k:w1}=P.layerOf,R1=s1.stack??1,F1=D.get(s1)??[];j.forEach((u0,n0)=>F1[n0*R1+w1]=u0),D.set(s1,F1)}for(let[P,j]of D){let s1=P.stack??1,w1=P.glue&&[...D.keys()].find(u0=>u0.name===P.glue.host&&u0!==P),R1=w1?D.get(w1):void 0,F1=j.length/s1;j.forEach((u0,n0)=>{let N1=n0%s1,X1=N1>0?j[n0-N1]:w1&&R1?.[rr(w1,P,Math.floor(n0/s1),F1)];X1!==void 0&&(w[u0].glued=X1)})}let G=new Map,V=w.filter(P=>!A.has(P)).flatMap(P=>{let j=Le(P);for(let s1 of j)G.set(s1,P);return j}),{found:U,complete:J}=L6(V,o.maxCollisionPairs),n1=(P,j)=>!!P.pressFit&&P.glued!==void 0&&w[P.glued]===j,m1=U.filter(([P,j])=>G.get(P)!==G.get(j)).filter(([P,j])=>{let[s1,w1]=[G.get(P)??P,G.get(j)??j];return!n1(s1,w1)&&!n1(w1,s1)}).map(([P,j,s1])=>[G.get(P)??P,G.get(j)??j,s1,P,j]).filter(([P,j],s1,w1)=>w1.findIndex(([R1,F1])=>R1===P&&F1===j)===s1);J||h.push(`The assembly has more than ${o.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[P,j,s1,w1,R1]of m1.slice(0,5)){let F1=(C6(w1,R1)??s1).map(v0);h.push(`Parts "${P.name}"${P.copy>1?` (copy ${P.copy})`:""} and "${j.name}"${j.copy>1?` (copy ${j.copy})`:""} collide in the assembly, around [${F1.join(", ")}]. Check their edges and where they are placed.`)}if(m1.length>5&&h.push(`${m1.length-5} more pairs of parts collide in the assembly.`),l("$stands")===!0){let P=Ml(w.filter(j=>!A.has(j)),i.hardware,V0(l("$density")??.6));P&&h.push(P)}if(Hl(_,h),w.length&&x.length){let P=[...new Set(x.map(j=>`"${j.name}"`))];h.push(`${P.length===1?"Part":"Parts"} ${P.slice(0,5).join(", ")}${P.length>5?` and ${P.length-5} more`:""} ${P.length===1?"has":"have"} no at or rotate, so ${P.length===1?"it lies":"they lie"} flat beside the assembly.`),w.push(...z6(w,x))}let M1=0;for(let P of z){let j=0;for(let s1 of P.layers.values()){for(let w1 of s1.regions)j+=w1.length;for(let w1 of s1.lines)j+=w1.length}M1+=j*P.info.qty}if(M1>o.maxOutputPoints)throw new i1(`The files would have ${M1} points, more than the limit of ${o.maxOutputPoints}. Use fewer copies or simpler shapes.`);let c1=e.sheet??(i.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(c1)||!(Number.isFinite(c1[0])&&c1[0]>0)||!(Number.isFinite(c1[1])&&c1[1]>0))throw new i1("$sheet must be [width, height], both more than 0");let C1=e.gap??V0(l("$gap")??3),h1=e.margin??C1;if(!(Number.isFinite(C1)&&C1>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(h1)&&h1>=0))throw new i1("margin must be a number, 0 or more");let B1=e.nest??l("$nest")===!0,$=e.layout??(l("$layout")==="none"?"none":"pack"),B=[...u.keys()].filter(P=>!["engrave","score","cut","guide"].includes(P)),a1=P=>(u.get(P)?.order??0)*2+(f(P)==="fill"?0:1),o1=["engrave",...B.map((P,j)=>[P,j]).sort((P,j)=>a1(P[0])-a1(j[0])||P[1]-j[1]).map(([P])=>P),"score","cut","guide"].map(P=>u.get(P)).filter(P=>P&&P.mode!=="paint"),p1=o1.filter(P=>P.side!=="back"),K1=[...o1.filter(P=>P.side==="back")],Q1=l("$registration")===!0;Q1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),Q1&&!p1.some(P=>P.name==="registration")&&p1.push(u.get("registration"));let W1=[],I0=[1,0,0,-1,0,0],q=P=>Q0(P)??[0,0,0,0],Z=(P,j)=>Se({layers:P,parts:[]},j).layers,e1=new Map;for(let P of z){let j=`${P.info.material}|${P.info.thickness}`;e1.set(j,[...e1.get(j)??[],P])}if($==="none"){for(let P of e1.values()){let j=[];for(let F1 of P)for(let u0=0;u0<F1.info.qty;u0++)j.push({part:F1.info.name,copy:F1.copy(u0),layers:Z(F1.layers,I0),rotated:!1});let s1=new Map;for(let F1 of j)for(let[u0,n0]of F1.layers){let N1=s1.get(u0)??{regions:[],lines:[]};for(let X1 of n0.regions)N1.regions.push(X1);for(let X1 of n0.lines)N1.lines.push(X1);s1.set(u0,N1)}let w1=q(s1),R1=[1,0,0,1,h1-w1[0],h1-w1[1]];for(let F1 of j)F1.layers=Z(F1.layers,R1),F1.offset=[R1[4],R1[5]];W1.push(Q(j,w1[2]-w1[0]+2*h1,w1[3]-w1[1]+2*h1,P[0].info))}e1.size||W1.push(Q([],2*h1,2*h1,void 0))}else for(let P of e1.values()){let[j,s1]=c1,w1=[];for(let x1 of P){let U1=Z(x1.layers,I0),s0=q(U1),S0=s0[2]-s0[0],q0=s0[3]-s0[1],T2=!1;(S0>j-2*h1||q0>s1-2*h1)&&q0<=j-2*h1&&S0<=s1-2*h1&&(U1=Z(U1,[0,1,-1,0,0,0]),s0=q(U1),S0=s0[2]-s0[0],q0=s0[3]-s0[1],T2=!0),(S0>j-2*h1||q0>s1-2*h1)&&h.push(`Part "${x1.info.name}" (${v0(S0)} x ${v0(q0)} mm) is bigger than the ${j} x ${s1} mm sheet.`),U1=Z(U1,[1,0,0,1,-s0[0],-s0[1]]);for(let I2=0;I2<x1.info.qty;I2++)w1.push({info:x1.info,layers:U1,w:S0,h:q0,copy:x1.copy(I2),rotated:T2})}let R1=(x1,U1)=>U1.h-x1.h||U1.w-x1.w,F1=x1=>{let U1=0,s0=h1,S0=h1,q0=0,T2=!1;for(let I2 of x1)s0>h1&&s0+I2.w>j-h1&&(s0=h1,S0+=q0+C1,q0=0),T2&&S0+I2.h>s1-h1&&(U1++,[s0,S0,q0]=[h1,h1,0]),T2=!0,s0+=I2.w+C1,q0=Math.max(q0,I2.h);return U1+(T2?1:0)};w1.sort(R1);let u0=Tl(w1,C1,x1=>f(x1)==="cut",[j-2*h1,s1-2*h1]).sort(R1),n0=u0.length<w1.length&&F1(u0)<F1(w1)?u0:w1,N1=B1?El(n0,C1,x1=>f(x1)==="cut"):n0,X1=[],h0=h1,g0=h1,u1=0,E1=0,A1=0,q1=()=>{if(X1.length&&W1.length>=o.maxSheets)throw new i1(`The parts need more than ${o.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);X1.length&&W1.push(Q(X1,Math.max(E1+h1,1),Math.max(A1+h1,1),P[0].info)),X1=[],h0=h1,g0=h1,u1=0,E1=0,A1=0};for(let x1 of N1){h0>h1&&h0+x1.w>j-h1&&(h0=h1,g0+=u1+C1,u1=0),X1.length&&g0+x1.h>s1-h1&&q1(),X1.push({part:x1.info.name,copy:x1.copy,layers:Z(x1.layers,[1,0,0,1,h0,g0]),rotated:x1.rotated});for(let U1 of x1.inner??[])X1.push({part:U1.item.info.name,copy:U1.item.copy,layers:Z(U1.item.layers,[1,0,0,1,h0+U1.dx,g0+U1.dy]),rotated:U1.item.rotated});E1=Math.max(E1,h0+x1.w),A1=Math.max(A1,g0+x1.h),h0+=x1.w+C1,u1=Math.max(u1,x1.h)}q1()}function Q(P,j,s1,w1){let R1=v0(j),F1=v0(s1);if(Q1){let N1=Math.min(5,h1-1);if(!(N1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let X1=(h0,g0)=>[[h0,g0],[h0+N1,g0],[h0+N1,g0+N1],[h0,g0+N1]];P=[...P,{part:"registration",copy:1,layers:new Map([["registration",{regions:[X1(.5,.5),X1(R1-.5-N1,.5),X1(.5,F1-.5-N1)],lines:[]}]]),rotated:!1}]}}let u0=P.some(N1=>K1.some(X1=>N1.layers.has(X1.name))),n0=u0?P.map(N1=>({...N1,layers:Z(N1.layers,[-1,0,0,1,R1,0])})):[];return{width:R1,height:F1,material:w1?.material??"material",thickness:w1?.thickness??0,items:P,paths:ut(P,p1),svg:ft(P,R1,F1,p1),dxf:nn(P,R1,F1,p1),...u0&&{back:{paths:ut(n0,K1),svg:ft(n0,R1,F1,K1),dxf:nn(n0,R1,F1,K1)}}}}let W=W1.length===1?W1[0]:void 0,$1=W?[]:W1.flatMap((P,j)=>{let s1=W1.slice(0,j).reduce((w1,R1)=>w1+R1.height+10,0);return P.items.map(w1=>({...w1,layers:Z(w1.layers,[1,0,0,1,0,s1])}))}),K=v0(Math.max(1,...W1.map(P=>P.width))),k1=v0(Math.max(1,W1.reduce((P,j)=>P+j.height,0)+10*Math.max(0,W1.length-1))),L1=W?W.svg:ft($1,K,k1,p1),A0=W?W.paths:ut($1,p1);return{sheets:W1,width:W?.width??K,height:W?.height??k1,paths:A0,svg:L1,parts:y,assembly:w,flat:k,layers:[...p1,...K1],warnings:h,echoes:i.echoes,...M&&{analysis:M},hardware:i.hardware,lights:i.lights,steps:i.steps}}function Ml(t,e,n){let r=t.filter(d=>d.placed).flatMap(d=>Le(d));if(!r.length)return;let a=(d,[m,p,g])=>[d[0]*m+d[1]*p+d[2]*g+d[3],d[4]*m+d[5]*p+d[6]*g+d[7],d[8]*m+d[9]*p+d[10]*g+d[11]],s=0,c=[0,0,0],o=1/0,i=[];for(let d of r){let{area:m,centroid:p}=We(d.outline);if(!(m>0))continue;let g=m*d.thickness*n*.001,v=a(d.matrix,[p[0],p[1],d.thickness/2]);for(let b=0;b<3;b++)c[b]+=v[b]*g;s+=g;for(let b of d.outline)for(let[y,M]of b)for(let w of[0,d.thickness]){let x=a(d.matrix,[y,M,w]);i.push(x),o=Math.min(o,x[2])}}for(let d of e){if(!(d.mass&&d.mass>0))continue;let m=[0,1,2].map(p=>(d.from[p]+d.to[p])/2);for(let p=0;p<3;p++)c[p]+=m[p]*d.mass;s+=d.mass}if(!(s>0)||!i.length)return;let l=c.map(d=>d/s),h=i.filter(d=>d[2]<=o+.5).map(([d,m])=>[d,m]),u=wl(h);if(!(d=>{if(u.length<3)return!1;for(let m=0;m<u.length;m++){let p=u[m],g=u[(m+1)%u.length];if((g[0]-p[0])*(d[1]-p[1])-(g[1]-p[1])*(d[0]-p[0])<-.5*Math.hypot(g[0]-p[0],g[1]-p[1]))return!1}return!0})([l[0],l[1]]))return`The model tips over: its weight's centre, at [${v0(l[0])}, ${v0(l[1])}, ${v0(l[2])}], is not over what it stands on. Widen its base or move weight over it.`}function wl(t){let e=[...t].sort((s,c)=>s[0]-c[0]||s[1]-c[1]);if(e.length<3)return e;let n=(s,c,o)=>(c[0]-s[0])*(o[1]-s[1])-(c[1]-s[1])*(o[0]-s[0]),r=[];for(let s of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let a=[];for(let s of[...e].reverse()){for(;a.length>=2&&n(a[a.length-2],a[a.length-1],s)<=0;)a.pop();a.push(s)}return[...r.slice(0,-1),...a.slice(0,-1)]}function nr(t,e,n){let r=[];for(let s of t)for(let c=0;c<s.length;c++){let o=s[c],i=s[(c+1)%s.length];if(o[n]>e!=i[n]>e){let l=(e-o[n])/(i[n]-o[n]);r.push(o[1-n]+l*(i[1-n]-o[1-n]))}}r.sort((s,c)=>s-c);let a=[];for(let s=0;s+1<r.length;s+=2)a.push([r[s],r[s+1]]);return a}function er(t,e,n,r,a){let s=[[t-.3*n,e-.22*n],[t+.4*n,e-.22*n],[t+.4*n,e+.22*n],[t-.3*n,e+.22*n]],c=Array.from({length:48},(i,l)=>{let h=2*Math.PI*l/48;return[t+.58*n+.32*n*Math.cos(h),e+.32*n*Math.sin(h)]}),o=t1([s,c]);return a&&(o=a0(o,a,"round")),r===0?o:o.map(i=>i.map(([l,h])=>[h,l]).reverse())}function tr(t,e,n,r,a,s){let c=Math.ceil((r-n)/a-1e-9),o=[],i=n;for(let l=1;l<c;l++){let h=Math.max(i+1,r-(c-l)*a),u=Math.min(i+a,r-1),f=(h+u)/2,d=1/0;for(let m=0;m<=40;m++){let p=h+(u-h)*m/40,g=b=>nr(b,p,s).reduce((y,[M,w])=>y+w-M,0),v=g(t)+5*g(e);v<d-1e-6&&([d,f]=[v,p])}o.push(f),i=f}return o}function kl(t,e,n,r,a,s,c){let o=t1([...t.layers].filter(([S])=>e(S)==="cut").flatMap(([,S])=>S.regions)),i=Q0(new Map([["cut",{regions:o,lines:[]}]]));if(!i)return[t];let l=.9*r,h=[n[0]-l,n[1]-l];if(!(h[0]>r&&h[1]>r))return s.push(`Part "${t.name}": split = [${n.join(", ")}] is too small to cut into pieces with ${r} mm knobs.`),[t];let u=S=>i[S+2]-i[S]<=n[S]+1e-9,f=t1([...t.layers].filter(([S])=>e(S)!=="cut").flatMap(([,S])=>S.regions)),d=S=>u(S)?1:Math.ceil((i[S+2]-i[S])/h[S]-1e-9),m=(d(0)*d(1)-1)*t.qty;if(!(m<=c.left))throw new i1(`Part "${t.name}": split into ${d(0)*d(1)} pieces would make more than ${c.max} part copies in total, the limit`);c.left-=m;let p=u(0)?[]:tr(o,f,i[0],i[2],h[0],0),g=u(1)?[]:tr(o,f,i[1],i[3],h[1],1);if(!p.length&&!g.length)return[t];let v=1e6,b=(S,C,E)=>[E===0?[[S,-v],[C,-v],[C,v],[S,v]]:[[-v,S],[v,S],[v,C],[-v,C]]],y=(S,C,E,I)=>{let H=[];for(let[T,O]of nr(I,S,C)){let _=O-T;if(_<1.6*r)continue;let D=Math.max(1,Math.floor(_/(5*r)));for(let G=0;G<D;G++){let[V,U]=[T+_*G/D,T+_*(G+1)/D],J=(V+U)/2;if(f.length){let n1=1/0;for(let m1=0;m1<=12;m1++){let M1=V+.7*r+(U-V-1.4*r)*m1/12,c1=G1(er(S,M1,r*1.2,C,0),f).reduce((h1,B1)=>h1+Math.abs(z1(B1)),0),C1=Math.abs(M1-(V+U)/2)*.001;c1+C1<n1&&([n1,J]=[c1+C1,M1])}}H.push(...er(S,J,r,C,E))}}return t1([...b(-v,S,C),...H])},M=(S,C,E,I)=>{let H=C<S.length?y(S[C],E,-a/2,I):b(-v,v,E);return C>0?d0(H,y(S[C-1],E,a/2,I)):H},w=S=>[-v,...S,v],[x,k]=[w(p),w(g)],A=[],L=[],z=0;for(let S=0;S<=g.length;S++)for(let C=0;C<=p.length;C++){let E=G1(o,b(k[S],k[S+1],1)),I=G1(o,b(x[C],x[C+1],0)),H=G1(M(p,C,0,E),M(g,S,1,I));if(!G1(o,H).length)continue;let O=`${t.name} piece ${++z}`;(A[S]??(A[S]=[]))[C]=O;let _=new Map;for(let[D,G]of t.layers){let V=G1(G.regions,H),U=N0(G.lines,H,"inside");(V.length||U.length)&&_.set(D,{regions:V,lines:U})}L.push({...t,name:O,layers:_,split:void 0})}for(let S of L){let C=A.findIndex(I=>I?.includes(S.name)),E=A[C].indexOf(S.name);S.joins=[A[C][E-1],A[C][E+1],A[C-1]?.[E],A[C+1]?.[E]].filter(I=>!!I)}return L}function zl(t,e,n,r){let a=o=>[...o.layers].filter(([i])=>r(i)==="cut").flatMap(([,i])=>i.regions),s=o=>{let{area:i,centroid:l}=We(t1(a(o))),h=R0(o.placements?.[0]??{at:[0,0,0],rotate:[0,0,0]}),[u,f]=i>0?l:[0,0],[d,m]=[h[0]*u+h[1]*f+h[3],h[4]*u+h[5]*f+h[7]],p=g=>a(g).reduce((v,b)=>v+(sn(b,d,m)?z1(b)>0?1:-1:0),0)>0;return(n.find(p)??n[0]).name},c=n.map(o=>o.name);for(let o of t)n.includes(o)||(o.glue?.host===e&&(o.glue={...o.glue,host:s(o)}),o.on===e&&(o.on=s(o)),o.slots?.includes(e)&&(o.slots=o.slots.flatMap(i=>i===e?c:[i])))}function Sl(t,e,n){for(let r of t){if(!r.hang||!r.placements)continue;let a=t1([...r.layers].filter(([f])=>e(f)==="cut").flatMap(([,f])=>f.regions)),{area:s,centroid:c}=We(a),[o,i]=r.hang.at,[l,h]=s>0?[c[0]-o,c[1]-i]:[0,-1],u=r.hang.cord;r.placements=r.placements.map((f,d)=>{let m=R0(f),[p,g]=[m[8],m[9]],v=Math.hypot(p,g)<1e-9?0:Math.atan2(-(g*l-p*h),-(p*l+g*h)),[b,y]=[Math.cos(v),Math.sin(v)],M=[b,-y,0,-(b*o-y*i),y,b,0,-(y*o+b*i),0,0,1,0,0,0,0,1],w=T1(U0(0,0,-u),T1(m,M));if(u>0){let x=[m[3],m[7],m[11]];n.push({kind:"cord",from:x,to:[x[0],x[1],x[2]-u],size:1.5,up:[0,1,0],sides:12,step:r.step??0,label:`${r.name}${r.placements.length>1?` ${d+1}`:""} cord`})}return{...f,matrix:w}})}}function rn(t){if(!t.includes("*"))return n=>n===t;let e=new RegExp(`^${t.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return n=>e.test(n)}function Al(t,e){if(!e||!t.length||e[0]===0&&e[1]===0)return t;let n=[...t];for(let r of t){let a=r.map(([s,c])=>[s+e[0],c+e[1]]);n.push(a);for(let s=0;s<r.length;s++){let c=(s+1)%r.length,o=[r[s],r[c],a[c],a[s]];Math.abs(z1(o))>1e-9&&n.push(z1(o)<0?o.reverse():o)}}return t1(n,"nonzero")}function an(t,e){let n=new Map(t);for(let[r,a]of t)n.set(r,{regions:d0(a.regions,e),lines:N0(a.lines,e,"outside")});return n}function Ll(t,e,n,r=[]){if(!t.some(l=>l.slots||l.bores))return;let a=new Map,s=l=>{let h=a.get(l);return h||(h=t1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),a.set(l,h)),h},c=l=>(l.placements??[]).flatMap(h=>Le({name:l.name,copy:0,placed:!0,matrix:R0(h),thickness:l.thickness,outline:s(l),...l.bends&&{bends:l.bends},...l.folds&&{folds:l.folds}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),o=new Map,i=new Map;for(let l of t){if(!l.slots&&!l.bores)continue;if(!l.placements){n.push(`Part "${l.name}" has ${l.slots?"slots":"bores"} but no at or rotate, so they can't be found.`);continue}let h=[];for(let M of l.bores??[]){let w=M.startsWith("!"),x=rn(w?M.slice(1):M),k=r.filter(A=>x(A.label??"")||x(A.kind));!k.length&&!w&&n.push(`Part "${l.name}": no hardware "${M}" to bore for.`);for(let A of k)w?h.splice(0,h.length,...h.filter(L=>L!==A)):h.includes(A)||h.push(A)}let u=!1,f=new Set;for(let M of l.slots??[]){let w=M.startsWith("!"),x=rn(w?M.slice(1):M),k=t.filter(A=>A!==l&&x(A.name));!k.length&&!w&&n.push(`Part "${l.name}": no part "${M}" to cut slots for.`);for(let A of k)w?f.delete(A):f.add(A)}let d=new Map,m=[...f].flatMap(M=>c(M).map(w=>(d.set(w,M.name),w))),p=new Set,g=(l.placements??[]).map(M=>t1(Le({name:l.name,copy:0,placed:!0,matrix:R0(M),thickness:l.thickness,outline:s(l),...l.bends&&{bends:l.bends},...l.folds&&{folds:l.folds}}).flatMap(w=>{let x=[];if(l.slots){let k=m.map(L=>I6(w,[L],0));for(let L=0;L<k.length;L++)for(let z=L+1;z<k.length;z++){let[S,C]=[d.get(m[L]),d.get(m[z])];if(!k[L].length||!k[z].length||S===C||!S||!C)continue;let E=G1(k[L],k[z]);if(E.reduce((I,H)=>I+Math.abs(z1(H)),0)>.01){let I=E.flat().map(G=>G[0]),H=E.flat().map(G=>G[1]),[T,O,_,D]=[Math.min(...I),Math.min(...H),Math.max(...I),Math.max(...H)];p.add(`Tabs of "${S}" and "${C}" meet in the same slot in "${l.name}", at [${v0(T)}, ${v0(O)}] to [${v0(_)}, ${v0(D)}] in its coordinates. Move one's tabs along the edge.`)}}let A=k.flat();x=A.length?Al(a0(t1(A),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let A=H6(w,k,l.fit??G3.turn);A&&G1([A],w.outline).some(L=>Math.abs(z1(L))>1e-4)&&(x.push(A),u=!0)}return l.bends?G1(x,a0(w.outline,1,"miter")):x}))),v=(M,w)=>ze(M,w).reduce((x,k)=>x+Math.abs(z1(k)),0)>.001,b=l.stack??1;if(b>1){let M=x=>g.filter((k,A)=>A%b===x),w=Array.from({length:b},(x,k)=>t1(M(k).flat()));if(w.slice(1).some(x=>v(w[0],x))){Array.from({length:b},(x,k)=>M(k)).some(x=>x.slice(1).some(k=>v(x[0],k)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),i.set(l,w);continue}}g.slice(1).some(M=>v(g[0],M))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);for(let M of p)n.push(M);l.bores&&h.length&&!u&&n.push(`Part "${l.name}": none of ${l.bores.map(M=>`"${M}"`).join(", ")} pass through it, so it has no bores.`);let y=t1(g.flat());if(!y.length){l.slots?.length&&!l.slots.some(M=>M.includes("*"))&&n.push(`Part "${l.name}": none of ${l.slots.map(M=>`"${M}"`).join(", ")} pass through it, so it has no slots.`);continue}o.set(l,y)}for(let[l,h]of o)l.layers=an(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/u,layers:d.length?an(l.layers,d):l.layers,placements:l.placements.filter((p,g)=>g%u===m),stack:void 0,layerOf:{part:l.layerOf?.part??l,k:m}}));t.splice(t.indexOf(l),1,...f)}}function Cl(t,e,n){if(!t.some(o=>o.halving))return;let r=o=>t1([...o.layers].filter(([i])=>e(i)==="cut").flatMap(([,i])=>i.regions)),a=o=>{let i=r(o);return(o.placements??[]).map(l=>({matrix:R0(l),thickness:o.thickness,outline:i}))},s=new Map,c=(o,i,l)=>{let h=s.get(o)??(o.placements??[]).map(()=>[]);h[i].push(...l),s.set(o,h)};for(let o of t){if(!o.halving)continue;if(!o.placements){n.push(`Part "${o.name}" has halving but no at or rotate, so the crossings can't be found.`);continue}let i=new Set;for(let f of o.halving){let d=f.startsWith("!"),m=rn(d?f.slice(1):f),p=t.filter(g=>g!==o&&(m(g.name)||g.layerOf&&m(g.layerOf.part.name)));!p.length&&!d&&n.push(`Part "${o.name}": no part "${f}" to halve with.`);for(let g of p)d?i.delete(g):i.add(g)}let l=0,h=0,u=a(o);for(let f of i){if(o.bends||f.bends){n.push(`Parts "${o.name}" and "${f.name}": halving joints can't go in a bent part.`);continue}if(!f.placements)continue;let d=a(f);u.forEach((m,p)=>d.forEach((g,v)=>{let b=q6(m,g,o.clearance??.1);h+=b.thin,b.a.length&&(l++,c(o,p,b.a),c(f,v,b.b))}))}h&&n.push(`Part "${o.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&i.size&&!o.halving.some(f=>f.includes("*"))&&n.push(`Part "${o.name}" crosses none of ${o.halving.map(f=>`"${f}"`).join(", ")}, so it has no halving slots.`)}for(let[o,i]of s){let l=i.map(h=>t1(h));l.slice(1).some(h=>ze(l[0],h).reduce((u,f)=>u+Math.abs(z1(f)),0)>.001)&&n.push(`Copies of part "${o.name}" are halved in different places; they all get every slot. Make them separate parts to cut each its own.`),o.layers=an(o.layers,t1(l.flat()))}}function Pl(t,e,n){let r=new Set;for(let a of t){if(a.on===void 0||!a.placements?.length)continue;let s=a.on,c=t.filter(p=>p.name===s&&p.placements?.length).flatMap(p=>p.placements.map((g,v)=>({q:p,m:R0(g),copy:b3(p,v)}))),o=t.filter(p=>p.name===a.name&&p.on===s).reduce((p,g)=>p+(g.placements?.length??0),0);if(!c.length){r.has(s)||n.push(`Part "${a.name}" is on "${s}", which is not a placed part.`),r.add(s);continue}let[i,l,h,u]=[1/0,1/0,-1/0,-1/0];for(let[p,g]of a.layers)if(e(p)==="cut")for(let v of g.regions)for(let[b,y]of v)i=Math.min(i,b),l=Math.min(l,y),h=Math.max(h,b),u=Math.max(u,y);if(!(h>=i))continue;let[f,d,m]=[(i+h)/2,(l+u)/2,a.thickness/2];a.placements=a.placements.map((p,g)=>{let v=b3(a,g),b=c.length===o&&c.find(A=>A.copy===v)||c[0];if(!b.q.bends?.length)return p;let y=R0(p),M=[y[0]*f+y[1]*d+y[2]*m+y[3],y[4]*f+y[5]*d+y[6]*m+y[7],y[8]*f+y[9]*d+y[10]*m+y[11]],w=L0(b.m),x=w[0]*M[0]+w[1]*M[1]+w[2]*M[2]+w[3],k=q5(b.q.bends,b.q.thickness)[E6(b.q.bends,x)];return{...p,matrix:T1(b.m,T1(k,T1(w,y)))}})}}function El(t,e,n){var l;let r=[],a=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)z1(m)<0&&u.push([...m].reverse());return u.length?a0(t1(u),-e,"miter"):[]},s=(h,u,f)=>{let d=0;for(let m of h)for(let p=0,g=m.length-1;p<m.length;g=p++){let[v,b]=m[g],[y,M]=m[p];b<=f?M>f&&(y-v)*(f-b)-(u-v)*(M-b)>0&&d++:M<=f&&(y-v)*(f-b)-(u-v)*(M-b)<0&&d--}return d!==0},c=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)z1(m)>0&&u.push(m);return t1(u)},o=(h,u)=>{let{w:f,h:d}=u,m=c(u),p=[];for(let g of m)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))p.push(g[v]);for(let g of h){if(z1(g)<=0)continue;let[v,b,y,M]=[1/0,1/0,-1/0,-1/0];for(let[x,k]of g)v=Math.min(v,x),b=Math.min(b,k),y=Math.max(y,x),M=Math.max(M,k);if(y-v<f||M-b<d)continue;let w=Math.max(.5,Math.min(f,d,y-v-f+1,M-b-d+1)/4);for(let x=b;x<=M-d+1e-9;x+=w)for(let k=v;k<=y-f+1e-9;k+=w){if(!p.every(([L,z])=>s(h,L+k,z+x)))continue;let A=m.map(L=>L.map(([z,S])=>[z+k,S+x]));if(d0(A,h).reduce((L,z)=>L+Math.abs(z1(z)),0)<.01)return[k,x]}}},i=[];for(let h of t){let u=!1;for(let d of h.inner?.length?[]:r){let m=o(d.region,h);if(!m)continue;let[p,g]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+p,dy:d.oy+g}),d.region=d0(d.region,a0(c(h).map(b=>b.map(([y,M])=>[y+p,M+g])),e,"miter"));let v=a(h);v.length&&r.push({host:d.host,ox:d.ox+p,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;i.push(h);let f=a(h);f.length&&r.push({host:h,ox:0,oy:0,region:f})}return i}function Tl(t,e,n,r){let a=new Map;for(let o of t)a.set(o.info,[...a.get(o.info)??[],o]);let s=[],c=(o,i)=>Se({layers:o,parts:[]},i).layers;for(let[,o]of a){let i=o[0],l=t1([...i.layers].filter(([d])=>n(d)).flatMap(([,d])=>d.regions.filter(m=>z1(m)>0))),h=l.reduce((d,m)=>d+z1(m),0)/(i.w*i.h),u=o.length>=2&&l.length&&h<.75?Il(l,i.w,i.h,e,r):void 0;if(!u){s.push(...o);continue}let f=c(i.layers,[-1,0,0,-1,i.w,i.h]);for(let d=0;d<o.length;d+=u.n){let m=o.slice(d,d+u.n);if(m.length===1){s.push(m[0]);continue}let p=u.at.slice(0,m.length),g=Math.min(...p.map(M=>M[0])),v=Math.min(...p.map(M=>M[1])),b=Math.max(...p.map(M=>M[0]+i.w))-g,y=Math.max(...p.map(M=>M[1]+i.h))-v;s.push({...m[0],layers:c(m[0].layers,[1,0,0,1,p[0][0]-g,p[0][1]-v]),w:b,h:y,inner:m.slice(1).map((M,w)=>({item:{...M,layers:(w+1)%2?f:M.layers},dx:p[w+1][0]-g,dy:p[w+1][1]-v}))})}}return s}function Il(t,e,n,r,a){let c=a0(t.map(y=>Vl(y,.25)).filter(y=>y.length>=3),.25,"miter"),o=a0(c,r,"miter"),i=c.map(y=>y.map(([M,w])=>[e-M,n-w])),l=(y,[M,w])=>y.map(x=>x.map(([k,A])=>[k+M,A+w])),h=(y,M)=>!G1(y,M).some(w=>Math.abs(z1(w))>.001),u=(y,M,w,x)=>{let[k,A]=[0,x];if(h(y,l(M,w(A)))){if(h(y,l(M,w(k))))return w(k);for(let L=0;L<10;L++){let z=(k+A)/2;h(y,l(M,w(z)))?A=z:k=z}return w(A)}},f;for(let y of[!1,!0])for(let M=-10;M<=10;M++){let w=M/10*(y?e:n),x=u(o,i,L=>y?[w,L]:[L,w],(y?n:e)+r);if(!x)continue;let k=Math.max(e,x[0]+e)-Math.min(0,x[0]),A=Math.max(n,x[1]+n)-Math.min(0,x[1]);k>a[0]||A>a[1]||k*A<.85*2*e*n&&(!f||k*A<f.area)&&(f={d:x,across:y,area:k*A})}if(!f)return;let{d,across:m}=f,p=t1([...o,...a0(l(i,d),r,"miter")]),v=u(p,c,y=>m?[0,y]:[y,0],2*((m?n:e)+r)+Math.abs(m?d[1]:d[0])),b=[[0,0],[d[0],d[1]]];if(v){let y=M=>Math.max(...M.map(w=>w[0]+e))-Math.min(...M.map(w=>w[0]))<=a[0]&&Math.max(...M.map(w=>w[1]+n))-Math.min(...M.map(w=>w[1]))<=a[1];for(let M=2;M<500;M++){let w=Math.floor(M/2),x=M%2?[d[0]+w*v[0],d[1]+w*v[1]]:[w*v[0],w*v[1]];if(!y([...b,x]))break;let k=l(M%2?i:c,x),A=t1(b.slice(Math.max(0,b.length-3)).map((L,z,S)=>{let C=b.length-S.length+z;return a0(l(C%2?i:c,L),r,"miter")}).flat());if(!h(A,k))break;b.push(x)}}return{at:b,n:b.length}}function Vl(t,e){if(t.length<8)return t;let n=o=>{let i=new Uint8Array(o.length);i[0]=i[o.length-1]=1;let l=[[0,o.length-1]];for(;l.length;){let[h,u]=l.pop(),[f,d]=o[h],[m,p]=o[u],g=Math.hypot(m-f,p-d),v=-1,b=-1;for(let y=h+1;y<u;y++){let[M,w]=o[y],x=g?Math.abs((m-f)*(d-w)-(f-M)*(p-d))/g:Math.hypot(M-f,w-d);x>v&&([v,b]=[x,y])}v>e&&(i[b]=1,l.push([h,b],[b,u]))}return o.filter((h,u)=>i[u])},r=o=>Math.hypot(o[0]-t[0][0],o[1]-t[0][1]),a=1;for(let o=2;o<t.length;o++)r(t[o])>r(t[a])&&(a=o);let s=n(t.slice(0,a+1)),c=n([...t.slice(a),t[0]]);return[...s,...c.slice(1,-1)]}function b3(t,e){if(!t.copies)return e+1;let n=t.stack??1;return(t.copies[Math.floor(e/n)]-1)*n+e%n+1}function $l(t,e,n){let r=[...n.keys()],a=[...e.keys()].filter(o=>n.get(o)?.mode==="fill"&&e.get(o).regions.length&&!["score","cut","guide"].includes(o)),s=[];if(a.length<2)return s;let c=o=>o==="engrave"?-1/0:(n.get(o)?.order??0)*2+r.indexOf(o)/r.length;a.sort((o,i)=>c(o)-c(i));for(let o=0;o<a.length-1;o++){let i=n.get(a[o]).side??"front",l=a.slice(o+1).filter(u=>(n.get(u).side??"front")===i);if(!l.length)continue;let h;for(let u of E0(e.get(a[o]).regions)){let f=u.reduce((w,x)=>w+z1(x),0);if(!(f>.001)||!a0(u,-.5,"round").length)continue;let d=u;for(let w of l)d.length&&(d=d0(d,e.get(w).regions));if(d.reduce((w,x)=>w+z1(x),0)>.001*Math.max(1,f))continue;let p=l.filter(w=>G1(u,e.get(w).regions).length),g=p.length?p:l;if(h){h.count++;for(let w of g)h.under.includes(w)||h.under.push(w);continue}let[v,b,y,M]=Q0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:a[o],under:g,count:1,at:[v0((v+y)/2),v0((b+M)/2)]}}h&&s.push(h)}return s}function Hl(t,e){for(let n of t.slice(0,5)){let r=n.under.map(s=>`"${s}"`),a=r.length>1?`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`:r[0];e.push(`Part "${n.part}": ${n.count>1?`${n.count} fills`:"a fill"} on layer "${n.layer}" (${n.count>1?"the first ":""}at [${n.at.join(", ")}]) ${n.count>1?"lie":"lies"} wholly under ${a}, stacked above it in the files: printed, ${n.count>1?"they":"it"} won't show, and engraved, ${n.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${n.layer}" a higher order.`)}if(t.length>5){let n=t.slice(5),r=new Set(n.map(s=>s.part)).size,a=[...new Set(n.map(s=>`"${s.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${r} part${r>1?"s":""} (layer${a.length>1?"s":""} ${a.slice(0,5).join(", ")}${a.length>5?" and more":""}).`)}}function rr(t,e,n,r){let a=t.stack??1,c=(t.placements?.length??0)/a===r?n:0,o=t.glue?.face==="bottom",i=e.glue?.face==="top";return c*a+(i!==o?a-1:0)}function Ol(t,e){let n=new Set,r=(a,s)=>{if(!a.glue||n.has(a))return;if(s.includes(a)){e.push(`Part "${a.name}" is glued in a loop of parts; it is left where it is.`),n.add(a);return}let c=t.find(h=>h.name===a.glue.host&&h!==a);if(!c?.placements){e.push(`Part "${a.name}" is glued to "${a.glue.host}", which is not a placed part.`),n.add(a);return}r(c,[...s,a]);let o=c.placements.map(R0),i=a.glue.face==="top"?c.thickness:-a.thickness,l=a.placements.length/(a.stack??1);a.placements=a.placements.map((h,u)=>{let f=o[rr(c,a,Math.floor(u/(a.stack??1)),l)];return{...h,matrix:T1(f,T1(U0(0,0,i),R0(h)))}}),n.add(a)};for(let a of t)r(a,[])}function Rl(t,e,n,r){let a=0,s=50;for(let p=0;p<14;p++){let g=(a+s)/2;a0(t,-g,"round").length?a=g:s=g}if(a<1)return[];let c=a0(t,-a*.98,"round"),o=Q0(new Map([["cut",{regions:c,lines:[]}]]));if(!o)return[];let[i,l]=[(o[0]+o[2])/2,(o[1]+o[3])/2];((p,g)=>c.reduce((v,b)=>v+(sn(b,p,g)?z1(b)>0?1:-1:0),0)>0)(i,l)||([i,l]=c.reduce((p,g)=>z1(g)>z1(p)?g:p)[0]);let u=Math.min(6,Math.max(2,a*.9)),f=d3(n,e,{size:u,font:r,halign:"center",valign:"center",spacing:1}),d=Q0(new Map([["t",{regions:f,lines:[]}]])),m=d?Math.min(1,1.6*a/Math.max(d[2]-d[0],1e-9)):1;return f.map(p=>p.map(([g,v])=>[i-g*m,l+v*m]).reverse())}function sn(t,e,n){let r=!1;for(let a=0,s=t.length-1;a<t.length;s=a++){let[c,o]=t[a],[i,l]=t[s];o>n!=l>n&&e<(i-c)*(n-o)/(l-o)+c&&(r=!r)}return r}var Fl=8,_l=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,ql=(t,e)=>Math.max(1,_l.exec(t.slice(e-1))?.[0].length??1);function ar(t,e,n={}){if(!(t instanceof i1))return`error: ${t instanceof Error?t.message:String(t)}`;let r=n.file??"design.kerf",a=(i,l,h)=>`${i?`<${i}>`:r}:${l}:${h}`,s=i=>i===void 0?e:(Object.prototype.hasOwnProperty.call(J3,i)?J3[i]:void 0)??n.resolve?.(i),c=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){c.push(` --> ${a(t.file,t.line,t.col)}`);let l=s(t.file)?.split(`
4258
- `)?.[t.line-1]?.replace(/\r$/,"");if(l!==void 0){let h=String(t.line),u=" ".repeat(h.length),f=l.slice(0,t.col-1),d=ql(l,t.col),m=f.replace(/[^\t]/g," ");c.push(`${u} |`,`${h} | ${l}`,`${u} | ${m}${"^".repeat(d)}`)}}for(let i of Dl(t,a))c.push(` = ${i}`);let o=t.call?c3(t.call):void 0;return o&&c.push(` = ${W5(o)}: ${o.doc}`),c.join(`
4259
- `)}function Dl(t,e){let n=s=>`in ${s.kind==="module"?"module ":""}${s.name}(), called at ${e(s.file,s.line,s.col)}${s.count>1?` (${s.count} times)`:""}`,r=t.trace.slice(0,Fl).map(n),a=t.trace.length-r.length+t.traceMore;return a&&r.push(`and ${a} more call${a===1?"":"s"}`),r}var sr=new Set(["module","function","if","else","for","let","each","use","include"]),Nl=new Set(["true","false","undef"]),Ul=new Set(["for","if","let","function"]),cn={"(":")","[":"]","{":"}"},Bl=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function jl(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let r=n+1;for(;t[r]!=='"';)r+=t[r]==="\\"?2:1;return t.slice(n,r+1)}function on(t){let{tokens:e}=r3(t),n=[],r=0,a=0,s=c=>{for(;r<c;)if(t[r]===`
4258
+ __options = ${e};`).program).globals.get("__options").value;return!Array.isArray(a)||!a.length?void 0:a.map(s=>Array.isArray(s)&&s.length===2?{name:String(s[1]),value:typeof s[0]=="number"?s[0]:String(s[0])}:{name:String(s),value:typeof s=="number"?s:String(s)})}catch{return}}function Z8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function v3(t){let{program:e,comments:n}=n2(t),r=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),a=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),s=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),c=[],o=new Set;for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let l=K8(i.value);if(!l.ok)continue;let h=r.filter(y=>y.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(h.toLowerCase()==="hidden")continue;let u=a.get(i.pos.line),f=s.get(i.pos.line-1)??"",d=l.value,m={name:i.name,caption:f,group:h,type:typeof d=="number"||Array.isArray(d)?"number":typeof d=="boolean"?"boolean":"string",initial:d,span:i.span},g=u?/^((?:\[.*\](?:\s+drive)?)?)\s*when\s+(.+)$/.exec(u.trim()):null;g&&(m.when=g[2].trim()),g?.[1]&&o.add(m);let p=g?g[1].trim():u?.trim(),v=p?/^\[(.*)\](\s+drive)?$/.exec(p):null;v?.[2]&&m.type==="number"&&typeof d=="number"&&(m.drive=!0);let b=v?yl(t,v[1]):void 0;if(b)m.options=b;else if(v){let y=v[1];if(y.includes(",")||/[a-zA-Z"]/.test(y)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(y))m.options=y.split(",").map(M=>{let[w,x]=M.split(":").map(L=>L.trim().replace(/^"|"$/g,"")),k=Z8(w),A=m.type==="number"&&k!==void 0?k:w;return{name:x??w,value:A}});else{let M=y.split(":").map(Z8);M.every(w=>w!==void 0)&&(M.length===1?m.max=M[0]:M.length===2?(m.min=M[0],m.max=M[1]):(m.min=M[0],m.step=M[1],m.max=M[2]))}}c.push(m)}for(let i of c){if(i.when===void 0)continue;if(!o.has(i)&&typeof J8(i.when)=="string"){delete i.when;continue}let l=xl(i.when,c);l&&(i.whenProblem=l,delete i.when)}return{parameters:c}}function J8(t){try{let e=n2(`when__ = (${t});`).program.body[0];return e?.kind==="assign"?e.value:"it is not an expression"}catch(e){return e.message.replace(/\s*\(line \d+, column \d+\)$/,"")}}var Y8=new Set(["==","!=","<","<=",">",">=","&&","||","+","-","*","/","%","!"]);function xl(t,e){let n=J8(t);if(typeof n=="string")return`its condition (${t}) is not an expression: ${n}`;let r=new Set(e.map(c=>c.name)),a=c=>{switch(c.kind){case"num":case"str":case"bool":case"undef":return;case"var":return r.has(c.name)?void 0:`uses ${c.name}, which is not a setting`;case"list":for(let o of c.items){if(o.kind!=="item")return"uses a list comprehension";let i=a(o.expr);if(i)return i}return;case"unary":return Y8.has(c.op)?a(c.arg):`uses ${c.op}`;case"binary":return Y8.has(c.op)?a(c.left)??a(c.right):`uses ${c.op}`;case"ternary":return a(c.cond)??a(c.then)??a(c.else);case"index":return a(c.target)??a(c.index);default:return"uses more than settings, values and operators"}},s=a(n);return s?`its condition (${t}) ${s}`:void 0}function mt(t,e,n){if(t.when===void 0)return!0;let r=Object.fromEntries(n.map(s=>[s.name,s.initial])),a=Object.fromEntries(Object.entries(e).filter(([s])=>Object.prototype.hasOwnProperty.call(r,s)));try{let s=[...n.map(o=>`${o.name} = undef;`),`echo((${t.when}) ? 1 : 0);`];return new K2({overrides:{...r,...a},maxSteps:1e5}).run(n2(s.join(`
4259
+ `)).program).echoes[0]!=="0"}catch{return!0}}var Q8=(t,e)=>{let n=0;for(let r=1;r<t.length;r++)n+=Math.hypot(t[r][0]-t[r-1][0],t[r][1]-t[r-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},v0=t=>Math.round(t*100)/100;function pt(t,e={}){for(let[P,j]of Object.entries(e.params??{}))try{i4(P,j)}catch(s1){throw new i1(s1.message)}let{program:n}=n2(t),r=new Set(n.body.flatMap(P=>P.kind==="assign"?[P.name]:[])),a=Object.keys(e.params??{}).filter(P=>!P.startsWith("$")&&!r.has(P)),s=e.fonts?new ht(e.fonts,e.defaultFont):void 0,c=new K2({overrides:e.params,resolve:e.resolve,fonts:s,maxSteps:e.maxSteps,limits:e.limits}),o=c.limits,i;try{i=c.run(n)}catch(P){let j=P instanceof RangeError?new i1(/call stack/i.test(P.message)?"Recursion too deep: check that it stops, or use fold(), scan() or a list comprehension to go through a long list":"A value grew too large. Is a list or string doubling without end?"):P;throw j instanceof i1&&(j.echoes=c.echoes,j.warnings=[...c.warnings],s?.missing.size&&(j.missingFonts=[...s.missing])),j}let l=P=>i.globals.get(P).value,h=i.warnings;for(let P of a)h.push(`Setting "${P}" is not a variable of the program, so it is ignored.${Oe(P,r)}`);let u=i.layers,f=P=>u.get(P)?.mode??"line",d=[...i.shape.parts];[...i.shape.layers.values()].some(P=>P.regions.length||P.lines.length)&&d.unshift({name:"part",qty:1,layers:i.shape.layers,thickness:l("$thickness")===void 0?3:V0(l("$thickness")),kerf:l("$kerf")===void 0?0:V0(l("$kerf")),material:k0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let g=new Set;for(let P of d)g.has(P.name)||[...P.layers].some(([s1,w1])=>s1!==a2&&(w1.regions.length||w1.lines.length))||(g.add(P.name),h.some(s1=>s1.includes(`leaves part "${P.name}" with nothing to cut`))||h.push(`Part "${P.name}" is empty: nothing drawn in it is left to cut.`));try{for(let P of v3(t).parameters)P.whenProblem&&h.push(`Setting ${P.name} is always shown: ${P.whenProblem} (line ${t.slice(0,P.span[0]).split(`
4260
+ `).length})`)}catch{}let p=P=>JSON.stringify([P.thickness,P.material,[...P.layers].map(([j,s1])=>[j,s1.regions.map(w1=>w1.map(([R1,F1])=>[Math.round(R1*100),Math.round(F1*100)])),s1.lines.map(w1=>w1.map(([R1,F1])=>[Math.round(R1*100),Math.round(F1*100)]))])]),v=new Map,b=new Set;for(let P of d){let j=p(P),s1=P.copies?`${P.name}\0${P.copies.join(",")}${P.mirrored?"m":""}`:P.mirrored?`${P.name}\0mirrored`:P.name,w1=v.get(s1);w1===void 0?v.set(s1,j):w1!==j&&b.add(P.name)}for(let P of b)h.push(`Two different parts are named "${P}"; slots, glue and on = find parts by name, so give each its own.`);Sl(d,f,i.hardware);{let P=e.sheet??(i.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet")),j=l("$knob")===void 0?12:V0(l("$knob")),s1=l("$knob_clearance")===void 0?.15:V0(l("$knob_clearance")),w1={left:o.maxParts-d.reduce((R1,F1)=>R1+F1.qty,0),max:o.maxParts};for(let R1=d.length-1;R1>=0;R1--){let F1=d[R1];if(!F1.split)continue;let u0=F1.split===!0?[P[0]-2*(e.margin??e.gap??V0(l("$gap")??3)),P[1]-2*(e.margin??e.gap??V0(l("$gap")??3))]:F1.split,n0=kl(F1,f,u0,j,s1,h,w1);d.splice(R1,1,...n0),n0.length>1&&zl(d,F1.name,n0,f)}}Ol(d,h),Pl(d,f,h),Ll(d,f,h,i.hardware),Cl(d,f,h);let y=[],M=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,w=[],x=[],k=[],A=new Set,L=new Map,z=[],S=l("$min_width"),C=S===void 0?1.5:V0(S),E=l("$label_parts")===!0,I=l("$join_lines")===!0,H=0;E&&!s&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let T=u.get("engrave-back");E&&s&&T&&T.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let O=E&&!!s&&(!T||T.side==="back");if(O){let P=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:P?.color??"#000000",side:"back"})}let _=[];for(let P of d){let j=t1([...P.layers].filter(([u1])=>f(u1)==="cut").flatMap(([,u1])=>u1.regions)),s1;if(P.bends&&j.length){let u1=1/0,E1=-1/0;for(let A1 of j)for(let[q1]of A1)u1=Math.min(u1,q1),E1=Math.max(E1,q1);for(let[A1,q1]of c4(P.bends))(A1<u1-.001||q1>E1+.001)&&h.push(`Part "${P.name}" bends from x = ${l2(A1)} to ${l2(q1)}, beyond the part (x = ${l2(u1)} to ${l2(E1)}); only the part itself bends.`)}let w1=P.folds&&j.length?d0(j,G2([...P.layers].filter(([u1])=>f(u1)==="cut").flatMap(([,u1])=>u1.lines.filter(E1=>E1.length>=2)),.2)):j;if(P.folds&&j.length){let u1=Ce(w1,P.folds,P.thickness).unused??[];for(let E1 of u1){let A1=P.folds[E1];h.push(`Part "${P.name}": the fold from [${l2(A1.from[0])}, ${l2(A1.from[1])}] to [${l2(A1.to[0])}, ${l2(A1.to[1])}] does not divide the part, so nothing folds there; run it from edge to edge, or to a cut.`)}}if(O&&j.length){s1=++H;let u1=Rl(j,String(s1),s,k0(l("$font")??""));if(u1.length){let E1=P.layers.get("engrave-back")??{regions:[],lines:[]};P.layers=new Map(P.layers).set("engrave-back",{regions:[...E1.regions,...u1],lines:E1.lines})}else h.push(`Part "${P.name}" is too small to take its number ${s1}.`)}if(C>0&&j.length){let u1=a0(a0(j,-C/2,"round"),C/2,"round"),E1=E0(d0(j,u1)).filter(A1=>A1.reduce((q1,x1)=>q1+z1(x1),0)>2*C*C);if(E1.length){let A1=E1.slice(0,3).map(q1=>{let[x1,U1,s0,S0]=Q0(new Map([["cut",{regions:q1,lines:[]}]]));return`[${v0((x1+s0)/2)}, ${v0((U1+S0)/2)}]`});h.push(`Part "${P.name}" is narrower than ${C} mm ($min_width) in ${E1.length} place${E1.length>1?"s":""}, at ${A1.join(", ")}${E1.length>3?" and more":""} in the part's coordinates.`)}}let R1=new Map,F1=[];for(let[u1,E1]of P.layers){if(u1===a2||f(u1)==="guide"&&!e.guides)continue;if(f(u1)==="paint"){let x1=u.get(u1),U1=G1(t1(E1.regions),j),s0=N0(E1.lines.filter(S0=>S0.length>=2),j,"inside");(U1.length||s0.length)&&F1.push({layer:u1,mode:"fill",color:x1.color,side:x1.side??"front",regions:U1,lines:s0});continue}let A1=t1(E1.regions),q1=E1.lines.filter(x1=>x1.length>=2);if((f(u1)==="line"||f(u1)==="guide")&&(q1=[...q1,...A1.map(x1=>[...x1,x1[0]])],A1=[]),j.length&&f(u1)!=="guide"){let x1=u.get(u1)?.bleed??0,U1=x1>0?a0(j,x1,"round"):j;f(u1)!=="cut"&&(A1=G1(A1,U1)),q1=N0(q1,U1,"inside")}I&&q1.length>1&&f(u1)!=="guide"&&(q1=v6(q1)),(A1.length||q1.length)&&R1.set(u1,{regions:A1,lines:q1})}if(_.push(...$l(P.name,R1,u)),j.length){let u1=[...F1];for(let[A1,q1]of R1){let x1=u.get(A1);if(x1?.mode==="cut"&&q1.lines.length)for(let U1 of["front","back"])u1.push({layer:A1,mode:"line",color:"#000000",side:U1,regions:[],lines:q1.lines});!x1||x1.mode!=="fill"&&x1.mode!=="line"||u1.push({layer:A1,mode:x1.mode,color:x1.color,side:x1.side??"front",regions:q1.regions,lines:q1.lines})}let E1={name:P.name,thickness:P.thickness,material:P.material,...P.paint&&{paint:P.paint},outline:w1,...u1.length&&{marks:u1}};for(let A1=0;A1<(P.placements?.length??P.qty);A1++)k.push({...E1,copy:b3(P,A1),matrix:R0({at:[0,0,0],rotate:[0,0,0]}),placed:!1});if(P.placements){let A1=new Set;P.placements.forEach((q1,x1)=>{let U1={...E1,copy:b3(P,x1),matrix:R0(q1),placed:!0,...P.bends&&{bends:P.bends},...P.folds&&{folds:P.folds},...P.step&&{step:P.step},...P.stack&&{stack:P.stack},...P.pressFit&&{pressFit:!0}};L.set(P,[...L.get(P)??[],w.length]),w.push(U1);let s0=U1.matrix.map(S0=>S0.toFixed(6)).join(",");A1.has(s0)&&A.add(U1),A1.add(s0)}),A1.size<P.placements.length&&h.push(`Copies of part "${P.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let A1=0;A1<P.qty;A1++)x.push({...E1,copy:b3(P,A1),matrix:R0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...P.step&&{step:P.step}})}let u0=E0(j),n0=u0.length;if(typeof P.pieces=="number"&&n0>0&&n0!==P.pieces)h.push(`Part "${P.name}" cuts into ${n0} separate piece${n0>1?"s":""}, not the ${P.pieces} its pieces = says.`);else if(n0>1&&P.pieces===void 0){let u1=q1=>q1.reduce((x1,U1)=>x1+z1(U1),0),A1=[...u0].sort((q1,x1)=>u1(x1)-u1(q1)).slice(1,4).map(q1=>{let[x1,U1,s0,S0]=Q0(new Map([["cut",{regions:q1,lines:[]}]]));return`[${v0(x1)}, ${v0(U1)}] to [${v0(s0)}, ${v0(S0)}]`}).join(", ");h.push(`Part "${P.name}" cuts into ${n0} separate pieces. Join them, or make them separate parts. The smaller ${n0===2?"one is":"ones are"} at ${A1}${n0>4?" and more":""}, in the part's coordinates.`)}let N1=0;for(let[u1,E1]of R1)if(f(u1)==="cut"){for(let A1 of E1.regions)N1+=Q8(A1,!0);for(let A1 of E1.lines)N1+=Q8(A1,!1)}let X1=Q0(R1)??[0,0,0,0],h0=e.kerf??P.kerf;if(!(Number.isFinite(h0)&&h0>=0))throw new i1("$kerf must be a number, 0 or more");if(!(Number.isFinite(P.thickness)&&P.thickness>0))throw new i1("$thickness must be a positive number");let g0={name:P.name,qty:P.qty,width:v0(X1[2]-X1[0]),height:v0(X1[3]-X1[1]),pieces:n0,cutLength:Math.round(N1),thickness:P.thickness,kerf:h0,material:P.material,...P.paint&&{paint:P.paint},...P.stack&&{stack:P.stack},...P.glue&&{glued:P.glue.host},...P.mirrored&&{mirrored:!0},...P.copies&&{copies:P.copies},...P.joins&&{joins:P.joins},...s1!==void 0&&{label:s1}};if(M&&M.parts.push({name:P.name,kerf:h0,qty:P.qty,...P.stack&&{stack:P.stack},...P.glue&&{glue:P.glue},...P.on&&{on:P.on},cutRegions:j.map(u1=>u1.map(([E1,A1])=>[E1,A1])),cutLines:[...R1].filter(([u1])=>f(u1)==="cut").flatMap(([,u1])=>u1.lines.map(E1=>E1.map(([A1,q1])=>[A1,q1])))}),h0>0){for(let[u1,E1]of R1)if(f(u1)==="cut"){let A1=E1.regions.filter(U1=>z1(U1)<0);E1.regions=a0(E1.regions,h0/2,"round",Math.min(.01,h0/20));let q1=E1.regions.filter(U1=>z1(U1)<0),x1=A1.length-q1.length;if(x1>0){let U1=S0=>{let[q0,T2,I2,La]=Q0(new Map([["cut",{regions:[S0],lines:[]}]]));return[(q0+I2)/2,(T2+La)/2]},s0=A1.map(U1).filter(([S0,q0])=>!q1.some(T2=>cn(T2,S0,q0))).slice(0,3).map(([S0,q0])=>`[${v0(S0)}, ${v0(q0)}]`);h.push(`Part "${P.name}": ${x1} hole${x1===1?" is":"s are"} narrower than the ${h0} mm kerf and will not be cut${s0.length?`, at ${s0.join(", ")}${x1>s0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(g0),z.push({info:g0,layers:R1,copy:u1=>b3(P,u1)})}let D=new Map;for(let[P,j]of L){if(!P.layerOf){D.set(P,j);continue}let{part:s1,k:w1}=P.layerOf,R1=s1.stack??1,F1=D.get(s1)??[];j.forEach((u0,n0)=>F1[n0*R1+w1]=u0),D.set(s1,F1)}for(let[P,j]of D){let s1=P.stack??1,w1=P.glue&&[...D.keys()].find(u0=>u0.name===P.glue.host&&u0!==P),R1=w1?D.get(w1):void 0,F1=j.length/s1;j.forEach((u0,n0)=>{let N1=n0%s1,X1=N1>0?j[n0-N1]:w1&&R1?.[rr(w1,P,Math.floor(n0/s1),F1)];X1!==void 0&&(w[u0].glued=X1)})}let G=new Map,V=w.filter(P=>!A.has(P)).flatMap(P=>{let j=Le(P);for(let s1 of j)G.set(s1,P);return j}),{found:U,complete:J}=L6(V,o.maxCollisionPairs),n1=(P,j)=>!!P.pressFit&&P.glued!==void 0&&w[P.glued]===j,m1=U.filter(([P,j])=>G.get(P)!==G.get(j)).filter(([P,j])=>{let[s1,w1]=[G.get(P)??P,G.get(j)??j];return!n1(s1,w1)&&!n1(w1,s1)}).map(([P,j,s1])=>[G.get(P)??P,G.get(j)??j,s1,P,j]).filter(([P,j],s1,w1)=>w1.findIndex(([R1,F1])=>R1===P&&F1===j)===s1);J||h.push(`The assembly has more than ${o.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[P,j,s1,w1,R1]of m1.slice(0,5)){let F1=(C6(w1,R1)??s1).map(v0);h.push(`Parts "${P.name}"${P.copy>1?` (copy ${P.copy})`:""} and "${j.name}"${j.copy>1?` (copy ${j.copy})`:""} collide in the assembly, around [${F1.join(", ")}]. Check their edges and where they are placed.`)}if(m1.length>5&&h.push(`${m1.length-5} more pairs of parts collide in the assembly.`),l("$stands")===!0){let P=Ml(w.filter(j=>!A.has(j)),i.hardware,V0(l("$density")??.6));P&&h.push(P)}if(Hl(_,h),w.length&&x.length){let P=[...new Set(x.map(j=>`"${j.name}"`))];h.push(`${P.length===1?"Part":"Parts"} ${P.slice(0,5).join(", ")}${P.length>5?` and ${P.length-5} more`:""} ${P.length===1?"has":"have"} no at or rotate, so ${P.length===1?"it lies":"they lie"} flat beside the assembly.`),w.push(...z6(w,x))}let M1=0;for(let P of z){let j=0;for(let s1 of P.layers.values()){for(let w1 of s1.regions)j+=w1.length;for(let w1 of s1.lines)j+=w1.length}M1+=j*P.info.qty}if(M1>o.maxOutputPoints)throw new i1(`The files would have ${M1} points, more than the limit of ${o.maxOutputPoints}. Use fewer copies or simpler shapes.`);let c1=e.sheet??(i.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(c1)||!(Number.isFinite(c1[0])&&c1[0]>0)||!(Number.isFinite(c1[1])&&c1[1]>0))throw new i1("$sheet must be [width, height], both more than 0");let C1=e.gap??V0(l("$gap")??3),h1=e.margin??C1;if(!(Number.isFinite(C1)&&C1>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(h1)&&h1>=0))throw new i1("margin must be a number, 0 or more");let B1=e.nest??l("$nest")===!0,$=e.layout??(l("$layout")==="none"?"none":"pack"),B=[...u.keys()].filter(P=>!["engrave","score","cut","guide"].includes(P)),a1=P=>(u.get(P)?.order??0)*2+(f(P)==="fill"?0:1),o1=["engrave",...B.map((P,j)=>[P,j]).sort((P,j)=>a1(P[0])-a1(j[0])||P[1]-j[1]).map(([P])=>P),"score","cut","guide"].map(P=>u.get(P)).filter(P=>P&&P.mode!=="paint"),p1=o1.filter(P=>P.side!=="back"),K1=[...o1.filter(P=>P.side==="back")],Q1=l("$registration")===!0;Q1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),Q1&&!p1.some(P=>P.name==="registration")&&p1.push(u.get("registration"));let W1=[],I0=[1,0,0,-1,0,0],q=P=>Q0(P)??[0,0,0,0],Z=(P,j)=>Se({layers:P,parts:[]},j).layers,e1=new Map;for(let P of z){let j=`${P.info.material}|${P.info.thickness}`;e1.set(j,[...e1.get(j)??[],P])}if($==="none"){for(let P of e1.values()){let j=[];for(let F1 of P)for(let u0=0;u0<F1.info.qty;u0++)j.push({part:F1.info.name,copy:F1.copy(u0),layers:Z(F1.layers,I0),rotated:!1});let s1=new Map;for(let F1 of j)for(let[u0,n0]of F1.layers){let N1=s1.get(u0)??{regions:[],lines:[]};for(let X1 of n0.regions)N1.regions.push(X1);for(let X1 of n0.lines)N1.lines.push(X1);s1.set(u0,N1)}let w1=q(s1),R1=[1,0,0,1,h1-w1[0],h1-w1[1]];for(let F1 of j)F1.layers=Z(F1.layers,R1),F1.offset=[R1[4],R1[5]];W1.push(Q(j,w1[2]-w1[0]+2*h1,w1[3]-w1[1]+2*h1,P[0].info))}e1.size||W1.push(Q([],2*h1,2*h1,void 0))}else for(let P of e1.values()){let[j,s1]=c1,w1=[];for(let x1 of P){let U1=Z(x1.layers,I0),s0=q(U1),S0=s0[2]-s0[0],q0=s0[3]-s0[1],T2=!1;(S0>j-2*h1||q0>s1-2*h1)&&q0<=j-2*h1&&S0<=s1-2*h1&&(U1=Z(U1,[0,1,-1,0,0,0]),s0=q(U1),S0=s0[2]-s0[0],q0=s0[3]-s0[1],T2=!0),(S0>j-2*h1||q0>s1-2*h1)&&h.push(`Part "${x1.info.name}" (${v0(S0)} x ${v0(q0)} mm) is bigger than the ${j} x ${s1} mm sheet.`),U1=Z(U1,[1,0,0,1,-s0[0],-s0[1]]);for(let I2=0;I2<x1.info.qty;I2++)w1.push({info:x1.info,layers:U1,w:S0,h:q0,copy:x1.copy(I2),rotated:T2})}let R1=(x1,U1)=>U1.h-x1.h||U1.w-x1.w,F1=x1=>{let U1=0,s0=h1,S0=h1,q0=0,T2=!1;for(let I2 of x1)s0>h1&&s0+I2.w>j-h1&&(s0=h1,S0+=q0+C1,q0=0),T2&&S0+I2.h>s1-h1&&(U1++,[s0,S0,q0]=[h1,h1,0]),T2=!0,s0+=I2.w+C1,q0=Math.max(q0,I2.h);return U1+(T2?1:0)};w1.sort(R1);let u0=Tl(w1,C1,x1=>f(x1)==="cut",[j-2*h1,s1-2*h1]).sort(R1),n0=u0.length<w1.length&&F1(u0)<F1(w1)?u0:w1,N1=B1?El(n0,C1,x1=>f(x1)==="cut"):n0,X1=[],h0=h1,g0=h1,u1=0,E1=0,A1=0,q1=()=>{if(X1.length&&W1.length>=o.maxSheets)throw new i1(`The parts need more than ${o.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);X1.length&&W1.push(Q(X1,Math.max(E1+h1,1),Math.max(A1+h1,1),P[0].info)),X1=[],h0=h1,g0=h1,u1=0,E1=0,A1=0};for(let x1 of N1){h0>h1&&h0+x1.w>j-h1&&(h0=h1,g0+=u1+C1,u1=0),X1.length&&g0+x1.h>s1-h1&&q1(),X1.push({part:x1.info.name,copy:x1.copy,layers:Z(x1.layers,[1,0,0,1,h0,g0]),rotated:x1.rotated});for(let U1 of x1.inner??[])X1.push({part:U1.item.info.name,copy:U1.item.copy,layers:Z(U1.item.layers,[1,0,0,1,h0+U1.dx,g0+U1.dy]),rotated:U1.item.rotated});E1=Math.max(E1,h0+x1.w),A1=Math.max(A1,g0+x1.h),h0+=x1.w+C1,u1=Math.max(u1,x1.h)}q1()}function Q(P,j,s1,w1){let R1=v0(j),F1=v0(s1);if(Q1){let N1=Math.min(5,h1-1);if(!(N1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let X1=(h0,g0)=>[[h0,g0],[h0+N1,g0],[h0+N1,g0+N1],[h0,g0+N1]];P=[...P,{part:"registration",copy:1,layers:new Map([["registration",{regions:[X1(.5,.5),X1(R1-.5-N1,.5),X1(.5,F1-.5-N1)],lines:[]}]]),rotated:!1}]}}let u0=P.some(N1=>K1.some(X1=>N1.layers.has(X1.name))),n0=u0?P.map(N1=>({...N1,layers:Z(N1.layers,[-1,0,0,1,R1,0])})):[];return{width:R1,height:F1,material:w1?.material??"material",thickness:w1?.thickness??0,items:P,paths:ft(P,p1),svg:dt(P,R1,F1,p1),dxf:rn(P,R1,F1,p1),...u0&&{back:{paths:ft(n0,K1),svg:dt(n0,R1,F1,K1),dxf:rn(n0,R1,F1,K1)}}}}let W=W1.length===1?W1[0]:void 0,$1=W?[]:W1.flatMap((P,j)=>{let s1=W1.slice(0,j).reduce((w1,R1)=>w1+R1.height+10,0);return P.items.map(w1=>({...w1,layers:Z(w1.layers,[1,0,0,1,0,s1])}))}),K=v0(Math.max(1,...W1.map(P=>P.width))),k1=v0(Math.max(1,W1.reduce((P,j)=>P+j.height,0)+10*Math.max(0,W1.length-1))),L1=W?W.svg:dt($1,K,k1,p1),A0=W?W.paths:ft($1,p1);return{sheets:W1,width:W?.width??K,height:W?.height??k1,paths:A0,svg:L1,parts:y,assembly:w,flat:k,layers:[...p1,...K1],warnings:h,echoes:i.echoes,...M&&{analysis:M},hardware:i.hardware,lights:i.lights,steps:i.steps}}function Ml(t,e,n){let r=t.filter(d=>d.placed).flatMap(d=>Le(d));if(!r.length)return;let a=(d,[m,g,p])=>[d[0]*m+d[1]*g+d[2]*p+d[3],d[4]*m+d[5]*g+d[6]*p+d[7],d[8]*m+d[9]*g+d[10]*p+d[11]],s=0,c=[0,0,0],o=1/0,i=[];for(let d of r){let{area:m,centroid:g}=We(d.outline);if(!(m>0))continue;let p=m*d.thickness*n*.001,v=a(d.matrix,[g[0],g[1],d.thickness/2]);for(let b=0;b<3;b++)c[b]+=v[b]*p;s+=p;for(let b of d.outline)for(let[y,M]of b)for(let w of[0,d.thickness]){let x=a(d.matrix,[y,M,w]);i.push(x),o=Math.min(o,x[2])}}for(let d of e){if(!(d.mass&&d.mass>0))continue;let m=[0,1,2].map(g=>(d.from[g]+d.to[g])/2);for(let g=0;g<3;g++)c[g]+=m[g]*d.mass;s+=d.mass}if(!(s>0)||!i.length)return;let l=c.map(d=>d/s),h=i.filter(d=>d[2]<=o+.5).map(([d,m])=>[d,m]),u=wl(h);if(!(d=>{if(u.length<3)return!1;for(let m=0;m<u.length;m++){let g=u[m],p=u[(m+1)%u.length];if((p[0]-g[0])*(d[1]-g[1])-(p[1]-g[1])*(d[0]-g[0])<-.5*Math.hypot(p[0]-g[0],p[1]-g[1]))return!1}return!0})([l[0],l[1]]))return`The model tips over: its weight's centre, at [${v0(l[0])}, ${v0(l[1])}, ${v0(l[2])}], is not over what it stands on. Widen its base or move weight over it.`}function wl(t){let e=[...t].sort((s,c)=>s[0]-c[0]||s[1]-c[1]);if(e.length<3)return e;let n=(s,c,o)=>(c[0]-s[0])*(o[1]-s[1])-(c[1]-s[1])*(o[0]-s[0]),r=[];for(let s of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let a=[];for(let s of[...e].reverse()){for(;a.length>=2&&n(a[a.length-2],a[a.length-1],s)<=0;)a.pop();a.push(s)}return[...r.slice(0,-1),...a.slice(0,-1)]}function nr(t,e,n){let r=[];for(let s of t)for(let c=0;c<s.length;c++){let o=s[c],i=s[(c+1)%s.length];if(o[n]>e!=i[n]>e){let l=(e-o[n])/(i[n]-o[n]);r.push(o[1-n]+l*(i[1-n]-o[1-n]))}}r.sort((s,c)=>s-c);let a=[];for(let s=0;s+1<r.length;s+=2)a.push([r[s],r[s+1]]);return a}function er(t,e,n,r,a){let s=[[t-.3*n,e-.22*n],[t+.4*n,e-.22*n],[t+.4*n,e+.22*n],[t-.3*n,e+.22*n]],c=Array.from({length:48},(i,l)=>{let h=2*Math.PI*l/48;return[t+.58*n+.32*n*Math.cos(h),e+.32*n*Math.sin(h)]}),o=t1([s,c]);return a&&(o=a0(o,a,"round")),r===0?o:o.map(i=>i.map(([l,h])=>[h,l]).reverse())}function tr(t,e,n,r,a,s){let c=Math.ceil((r-n)/a-1e-9),o=[],i=n;for(let l=1;l<c;l++){let h=Math.max(i+1,r-(c-l)*a),u=Math.min(i+a,r-1),f=(h+u)/2,d=1/0;for(let m=0;m<=40;m++){let g=h+(u-h)*m/40,p=b=>nr(b,g,s).reduce((y,[M,w])=>y+w-M,0),v=p(t)+5*p(e);v<d-1e-6&&([d,f]=[v,g])}o.push(f),i=f}return o}function kl(t,e,n,r,a,s,c){let o=t1([...t.layers].filter(([S])=>e(S)==="cut").flatMap(([,S])=>S.regions)),i=Q0(new Map([["cut",{regions:o,lines:[]}]]));if(!i)return[t];let l=.9*r,h=[n[0]-l,n[1]-l];if(!(h[0]>r&&h[1]>r))return s.push(`Part "${t.name}": split = [${n.join(", ")}] is too small to cut into pieces with ${r} mm knobs.`),[t];let u=S=>i[S+2]-i[S]<=n[S]+1e-9,f=t1([...t.layers].filter(([S])=>e(S)!=="cut").flatMap(([,S])=>S.regions)),d=S=>u(S)?1:Math.ceil((i[S+2]-i[S])/h[S]-1e-9),m=(d(0)*d(1)-1)*t.qty;if(!(m<=c.left))throw new i1(`Part "${t.name}": split into ${d(0)*d(1)} pieces would make more than ${c.max} part copies in total, the limit`);c.left-=m;let g=u(0)?[]:tr(o,f,i[0],i[2],h[0],0),p=u(1)?[]:tr(o,f,i[1],i[3],h[1],1);if(!g.length&&!p.length)return[t];let v=1e6,b=(S,C,E)=>[E===0?[[S,-v],[C,-v],[C,v],[S,v]]:[[-v,S],[v,S],[v,C],[-v,C]]],y=(S,C,E,I)=>{let H=[];for(let[T,O]of nr(I,S,C)){let _=O-T;if(_<1.6*r)continue;let D=Math.max(1,Math.floor(_/(5*r)));for(let G=0;G<D;G++){let[V,U]=[T+_*G/D,T+_*(G+1)/D],J=(V+U)/2;if(f.length){let n1=1/0;for(let m1=0;m1<=12;m1++){let M1=V+.7*r+(U-V-1.4*r)*m1/12,c1=G1(er(S,M1,r*1.2,C,0),f).reduce((h1,B1)=>h1+Math.abs(z1(B1)),0),C1=Math.abs(M1-(V+U)/2)*.001;c1+C1<n1&&([n1,J]=[c1+C1,M1])}}H.push(...er(S,J,r,C,E))}}return t1([...b(-v,S,C),...H])},M=(S,C,E,I)=>{let H=C<S.length?y(S[C],E,-a/2,I):b(-v,v,E);return C>0?d0(H,y(S[C-1],E,a/2,I)):H},w=S=>[-v,...S,v],[x,k]=[w(g),w(p)],A=[],L=[],z=0;for(let S=0;S<=p.length;S++)for(let C=0;C<=g.length;C++){let E=G1(o,b(k[S],k[S+1],1)),I=G1(o,b(x[C],x[C+1],0)),H=G1(M(g,C,0,E),M(p,S,1,I));if(!G1(o,H).length)continue;let O=`${t.name} piece ${++z}`;(A[S]??(A[S]=[]))[C]=O;let _=new Map;for(let[D,G]of t.layers){let V=G1(G.regions,H),U=N0(G.lines,H,"inside");(V.length||U.length)&&_.set(D,{regions:V,lines:U})}L.push({...t,name:O,layers:_,split:void 0})}for(let S of L){let C=A.findIndex(I=>I?.includes(S.name)),E=A[C].indexOf(S.name);S.joins=[A[C][E-1],A[C][E+1],A[C-1]?.[E],A[C+1]?.[E]].filter(I=>!!I)}return L}function zl(t,e,n,r){let a=o=>[...o.layers].filter(([i])=>r(i)==="cut").flatMap(([,i])=>i.regions),s=o=>{let{area:i,centroid:l}=We(t1(a(o))),h=R0(o.placements?.[0]??{at:[0,0,0],rotate:[0,0,0]}),[u,f]=i>0?l:[0,0],[d,m]=[h[0]*u+h[1]*f+h[3],h[4]*u+h[5]*f+h[7]],g=p=>a(p).reduce((v,b)=>v+(cn(b,d,m)?z1(b)>0?1:-1:0),0)>0;return(n.find(g)??n[0]).name},c=n.map(o=>o.name);for(let o of t)n.includes(o)||(o.glue?.host===e&&(o.glue={...o.glue,host:s(o)}),o.on===e&&(o.on=s(o)),o.slots?.includes(e)&&(o.slots=o.slots.flatMap(i=>i===e?c:[i])))}function Sl(t,e,n){for(let r of t){if(!r.hang||!r.placements)continue;let a=t1([...r.layers].filter(([f])=>e(f)==="cut").flatMap(([,f])=>f.regions)),{area:s,centroid:c}=We(a),[o,i]=r.hang.at,[l,h]=s>0?[c[0]-o,c[1]-i]:[0,-1],u=r.hang.cord;r.placements=r.placements.map((f,d)=>{let m=R0(f),[g,p]=[m[8],m[9]],v=Math.hypot(g,p)<1e-9?0:Math.atan2(-(p*l-g*h),-(g*l+p*h)),[b,y]=[Math.cos(v),Math.sin(v)],M=[b,-y,0,-(b*o-y*i),y,b,0,-(y*o+b*i),0,0,1,0,0,0,0,1],w=T1(U0(0,0,-u),T1(m,M));if(u>0){let x=[m[3],m[7],m[11]];n.push({kind:"cord",from:x,to:[x[0],x[1],x[2]-u],size:1.5,up:[0,1,0],sides:12,step:r.step??0,label:`${r.name}${r.placements.length>1?` ${d+1}`:""} cord`})}return{...f,matrix:w}})}}function an(t){if(!t.includes("*"))return n=>n===t;let e=new RegExp(`^${t.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return n=>e.test(n)}function Al(t,e){if(!e||!t.length||e[0]===0&&e[1]===0)return t;let n=[...t];for(let r of t){let a=r.map(([s,c])=>[s+e[0],c+e[1]]);n.push(a);for(let s=0;s<r.length;s++){let c=(s+1)%r.length,o=[r[s],r[c],a[c],a[s]];Math.abs(z1(o))>1e-9&&n.push(z1(o)<0?o.reverse():o)}}return t1(n,"nonzero")}function sn(t,e){let n=new Map(t);for(let[r,a]of t)n.set(r,{regions:d0(a.regions,e),lines:N0(a.lines,e,"outside")});return n}function Ll(t,e,n,r=[]){if(!t.some(l=>l.slots||l.bores))return;let a=new Map,s=l=>{let h=a.get(l);return h||(h=t1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),a.set(l,h)),h},c=l=>(l.placements??[]).flatMap(h=>Le({name:l.name,copy:0,placed:!0,matrix:R0(h),thickness:l.thickness,outline:s(l),...l.bends&&{bends:l.bends},...l.folds&&{folds:l.folds}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),o=new Map,i=new Map;for(let l of t){if(!l.slots&&!l.bores)continue;if(!l.placements){n.push(`Part "${l.name}" has ${l.slots?"slots":"bores"} but no at or rotate, so they can't be found.`);continue}let h=[];for(let M of l.bores??[]){let w=M.startsWith("!"),x=an(w?M.slice(1):M),k=r.filter(A=>x(A.label??"")||x(A.kind));!k.length&&!w&&n.push(`Part "${l.name}": no hardware "${M}" to bore for.`);for(let A of k)w?h.splice(0,h.length,...h.filter(L=>L!==A)):h.includes(A)||h.push(A)}let u=!1,f=new Set;for(let M of l.slots??[]){let w=M.startsWith("!"),x=an(w?M.slice(1):M),k=t.filter(A=>A!==l&&x(A.name));!k.length&&!w&&n.push(`Part "${l.name}": no part "${M}" to cut slots for.`);for(let A of k)w?f.delete(A):f.add(A)}let d=new Map,m=[...f].flatMap(M=>c(M).map(w=>(d.set(w,M.name),w))),g=new Set,p=(l.placements??[]).map(M=>t1(Le({name:l.name,copy:0,placed:!0,matrix:R0(M),thickness:l.thickness,outline:s(l),...l.bends&&{bends:l.bends},...l.folds&&{folds:l.folds}}).flatMap(w=>{let x=[];if(l.slots){let k=m.map(L=>I6(w,[L],0));for(let L=0;L<k.length;L++)for(let z=L+1;z<k.length;z++){let[S,C]=[d.get(m[L]),d.get(m[z])];if(!k[L].length||!k[z].length||S===C||!S||!C)continue;let E=G1(k[L],k[z]);if(E.reduce((I,H)=>I+Math.abs(z1(H)),0)>.01){let I=E.flat().map(G=>G[0]),H=E.flat().map(G=>G[1]),[T,O,_,D]=[Math.min(...I),Math.min(...H),Math.max(...I),Math.max(...H)];g.add(`Tabs of "${S}" and "${C}" meet in the same slot in "${l.name}", at [${v0(T)}, ${v0(O)}] to [${v0(_)}, ${v0(D)}] in its coordinates. Move one's tabs along the edge.`)}}let A=k.flat();x=A.length?Al(a0(t1(A),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let A=H6(w,k,l.fit??W3.turn);A&&G1([A],w.outline).some(L=>Math.abs(z1(L))>1e-4)&&(x.push(A),u=!0)}return l.bends?G1(x,a0(w.outline,1,"miter")):x}))),v=(M,w)=>ze(M,w).reduce((x,k)=>x+Math.abs(z1(k)),0)>.001,b=l.stack??1;if(b>1){let M=x=>p.filter((k,A)=>A%b===x),w=Array.from({length:b},(x,k)=>t1(M(k).flat()));if(w.slice(1).some(x=>v(w[0],x))){Array.from({length:b},(x,k)=>M(k)).some(x=>x.slice(1).some(k=>v(x[0],k)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),i.set(l,w);continue}}p.slice(1).some(M=>v(p[0],M))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);for(let M of g)n.push(M);l.bores&&h.length&&!u&&n.push(`Part "${l.name}": none of ${l.bores.map(M=>`"${M}"`).join(", ")} pass through it, so it has no bores.`);let y=t1(p.flat());if(!y.length){l.slots?.length&&!l.slots.some(M=>M.includes("*"))&&n.push(`Part "${l.name}": none of ${l.slots.map(M=>`"${M}"`).join(", ")} pass through it, so it has no slots.`);continue}o.set(l,y)}for(let[l,h]of o)l.layers=sn(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/u,layers:d.length?sn(l.layers,d):l.layers,placements:l.placements.filter((g,p)=>p%u===m),stack:void 0,layerOf:{part:l.layerOf?.part??l,k:m}}));t.splice(t.indexOf(l),1,...f)}}function Cl(t,e,n){if(!t.some(o=>o.halving))return;let r=o=>t1([...o.layers].filter(([i])=>e(i)==="cut").flatMap(([,i])=>i.regions)),a=o=>{let i=r(o);return(o.placements??[]).map(l=>({matrix:R0(l),thickness:o.thickness,outline:i}))},s=new Map,c=(o,i,l)=>{let h=s.get(o)??(o.placements??[]).map(()=>[]);h[i].push(...l),s.set(o,h)};for(let o of t){if(!o.halving)continue;if(!o.placements){n.push(`Part "${o.name}" has halving but no at or rotate, so the crossings can't be found.`);continue}let i=new Set;for(let f of o.halving){let d=f.startsWith("!"),m=an(d?f.slice(1):f),g=t.filter(p=>p!==o&&(m(p.name)||p.layerOf&&m(p.layerOf.part.name)));!g.length&&!d&&n.push(`Part "${o.name}": no part "${f}" to halve with.`);for(let p of g)d?i.delete(p):i.add(p)}let l=0,h=0,u=a(o);for(let f of i){if(o.bends||f.bends){n.push(`Parts "${o.name}" and "${f.name}": halving joints can't go in a bent part.`);continue}if(!f.placements)continue;let d=a(f);u.forEach((m,g)=>d.forEach((p,v)=>{let b=q6(m,p,o.clearance??.1);h+=b.thin,b.a.length&&(l++,c(o,g,b.a),c(f,v,b.b))}))}h&&n.push(`Part "${o.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&i.size&&!o.halving.some(f=>f.includes("*"))&&n.push(`Part "${o.name}" crosses none of ${o.halving.map(f=>`"${f}"`).join(", ")}, so it has no halving slots.`)}for(let[o,i]of s){let l=i.map(h=>t1(h));l.slice(1).some(h=>ze(l[0],h).reduce((u,f)=>u+Math.abs(z1(f)),0)>.001)&&n.push(`Copies of part "${o.name}" are halved in different places; they all get every slot. Make them separate parts to cut each its own.`),o.layers=sn(o.layers,t1(l.flat()))}}function Pl(t,e,n){let r=new Set;for(let a of t){if(a.on===void 0||!a.placements?.length)continue;let s=a.on,c=t.filter(g=>g.name===s&&g.placements?.length).flatMap(g=>g.placements.map((p,v)=>({q:g,m:R0(p),copy:b3(g,v)}))),o=t.filter(g=>g.name===a.name&&g.on===s).reduce((g,p)=>g+(p.placements?.length??0),0);if(!c.length){r.has(s)||n.push(`Part "${a.name}" is on "${s}", which is not a placed part.`),r.add(s);continue}let[i,l,h,u]=[1/0,1/0,-1/0,-1/0];for(let[g,p]of a.layers)if(e(g)==="cut")for(let v of p.regions)for(let[b,y]of v)i=Math.min(i,b),l=Math.min(l,y),h=Math.max(h,b),u=Math.max(u,y);if(!(h>=i))continue;let[f,d,m]=[(i+h)/2,(l+u)/2,a.thickness/2];a.placements=a.placements.map((g,p)=>{let v=b3(a,p),b=c.length===o&&c.find(A=>A.copy===v)||c[0];if(!b.q.bends?.length)return g;let y=R0(g),M=[y[0]*f+y[1]*d+y[2]*m+y[3],y[4]*f+y[5]*d+y[6]*m+y[7],y[8]*f+y[9]*d+y[10]*m+y[11]],w=L0(b.m),x=w[0]*M[0]+w[1]*M[1]+w[2]*M[2]+w[3],k=D5(b.q.bends,b.q.thickness)[E6(b.q.bends,x)];return{...g,matrix:T1(b.m,T1(k,T1(w,y)))}})}}function El(t,e,n){var l;let r=[],a=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)z1(m)<0&&u.push([...m].reverse());return u.length?a0(t1(u),-e,"miter"):[]},s=(h,u,f)=>{let d=0;for(let m of h)for(let g=0,p=m.length-1;g<m.length;p=g++){let[v,b]=m[p],[y,M]=m[g];b<=f?M>f&&(y-v)*(f-b)-(u-v)*(M-b)>0&&d++:M<=f&&(y-v)*(f-b)-(u-v)*(M-b)<0&&d--}return d!==0},c=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)z1(m)>0&&u.push(m);return t1(u)},o=(h,u)=>{let{w:f,h:d}=u,m=c(u),g=[];for(let p of m)for(let v=0;v<p.length;v+=Math.max(1,Math.floor(p.length/12)))g.push(p[v]);for(let p of h){if(z1(p)<=0)continue;let[v,b,y,M]=[1/0,1/0,-1/0,-1/0];for(let[x,k]of p)v=Math.min(v,x),b=Math.min(b,k),y=Math.max(y,x),M=Math.max(M,k);if(y-v<f||M-b<d)continue;let w=Math.max(.5,Math.min(f,d,y-v-f+1,M-b-d+1)/4);for(let x=b;x<=M-d+1e-9;x+=w)for(let k=v;k<=y-f+1e-9;k+=w){if(!g.every(([L,z])=>s(h,L+k,z+x)))continue;let A=m.map(L=>L.map(([z,S])=>[z+k,S+x]));if(d0(A,h).reduce((L,z)=>L+Math.abs(z1(z)),0)<.01)return[k,x]}}},i=[];for(let h of t){let u=!1;for(let d of h.inner?.length?[]:r){let m=o(d.region,h);if(!m)continue;let[g,p]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+g,dy:d.oy+p}),d.region=d0(d.region,a0(c(h).map(b=>b.map(([y,M])=>[y+g,M+p])),e,"miter"));let v=a(h);v.length&&r.push({host:d.host,ox:d.ox+g,oy:d.oy+p,region:v}),u=!0;break}if(u)continue;i.push(h);let f=a(h);f.length&&r.push({host:h,ox:0,oy:0,region:f})}return i}function Tl(t,e,n,r){let a=new Map;for(let o of t)a.set(o.info,[...a.get(o.info)??[],o]);let s=[],c=(o,i)=>Se({layers:o,parts:[]},i).layers;for(let[,o]of a){let i=o[0],l=t1([...i.layers].filter(([d])=>n(d)).flatMap(([,d])=>d.regions.filter(m=>z1(m)>0))),h=l.reduce((d,m)=>d+z1(m),0)/(i.w*i.h),u=o.length>=2&&l.length&&h<.75?Il(l,i.w,i.h,e,r):void 0;if(!u){s.push(...o);continue}let f=c(i.layers,[-1,0,0,-1,i.w,i.h]);for(let d=0;d<o.length;d+=u.n){let m=o.slice(d,d+u.n);if(m.length===1){s.push(m[0]);continue}let g=u.at.slice(0,m.length),p=Math.min(...g.map(M=>M[0])),v=Math.min(...g.map(M=>M[1])),b=Math.max(...g.map(M=>M[0]+i.w))-p,y=Math.max(...g.map(M=>M[1]+i.h))-v;s.push({...m[0],layers:c(m[0].layers,[1,0,0,1,g[0][0]-p,g[0][1]-v]),w:b,h:y,inner:m.slice(1).map((M,w)=>({item:{...M,layers:(w+1)%2?f:M.layers},dx:g[w+1][0]-p,dy:g[w+1][1]-v}))})}}return s}function Il(t,e,n,r,a){let c=a0(t.map(y=>Vl(y,.25)).filter(y=>y.length>=3),.25,"miter"),o=a0(c,r,"miter"),i=c.map(y=>y.map(([M,w])=>[e-M,n-w])),l=(y,[M,w])=>y.map(x=>x.map(([k,A])=>[k+M,A+w])),h=(y,M)=>!G1(y,M).some(w=>Math.abs(z1(w))>.001),u=(y,M,w,x)=>{let[k,A]=[0,x];if(h(y,l(M,w(A)))){if(h(y,l(M,w(k))))return w(k);for(let L=0;L<10;L++){let z=(k+A)/2;h(y,l(M,w(z)))?A=z:k=z}return w(A)}},f;for(let y of[!1,!0])for(let M=-10;M<=10;M++){let w=M/10*(y?e:n),x=u(o,i,L=>y?[w,L]:[L,w],(y?n:e)+r);if(!x)continue;let k=Math.max(e,x[0]+e)-Math.min(0,x[0]),A=Math.max(n,x[1]+n)-Math.min(0,x[1]);k>a[0]||A>a[1]||k*A<.85*2*e*n&&(!f||k*A<f.area)&&(f={d:x,across:y,area:k*A})}if(!f)return;let{d,across:m}=f,g=t1([...o,...a0(l(i,d),r,"miter")]),v=u(g,c,y=>m?[0,y]:[y,0],2*((m?n:e)+r)+Math.abs(m?d[1]:d[0])),b=[[0,0],[d[0],d[1]]];if(v){let y=M=>Math.max(...M.map(w=>w[0]+e))-Math.min(...M.map(w=>w[0]))<=a[0]&&Math.max(...M.map(w=>w[1]+n))-Math.min(...M.map(w=>w[1]))<=a[1];for(let M=2;M<500;M++){let w=Math.floor(M/2),x=M%2?[d[0]+w*v[0],d[1]+w*v[1]]:[w*v[0],w*v[1]];if(!y([...b,x]))break;let k=l(M%2?i:c,x),A=t1(b.slice(Math.max(0,b.length-3)).map((L,z,S)=>{let C=b.length-S.length+z;return a0(l(C%2?i:c,L),r,"miter")}).flat());if(!h(A,k))break;b.push(x)}}return{at:b,n:b.length}}function Vl(t,e){if(t.length<8)return t;let n=o=>{let i=new Uint8Array(o.length);i[0]=i[o.length-1]=1;let l=[[0,o.length-1]];for(;l.length;){let[h,u]=l.pop(),[f,d]=o[h],[m,g]=o[u],p=Math.hypot(m-f,g-d),v=-1,b=-1;for(let y=h+1;y<u;y++){let[M,w]=o[y],x=p?Math.abs((m-f)*(d-w)-(f-M)*(g-d))/p:Math.hypot(M-f,w-d);x>v&&([v,b]=[x,y])}v>e&&(i[b]=1,l.push([h,b],[b,u]))}return o.filter((h,u)=>i[u])},r=o=>Math.hypot(o[0]-t[0][0],o[1]-t[0][1]),a=1;for(let o=2;o<t.length;o++)r(t[o])>r(t[a])&&(a=o);let s=n(t.slice(0,a+1)),c=n([...t.slice(a),t[0]]);return[...s,...c.slice(1,-1)]}function b3(t,e){if(!t.copies)return e+1;let n=t.stack??1;return(t.copies[Math.floor(e/n)]-1)*n+e%n+1}function $l(t,e,n){let r=[...n.keys()],a=[...e.keys()].filter(o=>n.get(o)?.mode==="fill"&&e.get(o).regions.length&&!["score","cut","guide"].includes(o)),s=[];if(a.length<2)return s;let c=o=>o==="engrave"?-1/0:(n.get(o)?.order??0)*2+r.indexOf(o)/r.length;a.sort((o,i)=>c(o)-c(i));for(let o=0;o<a.length-1;o++){let i=n.get(a[o]).side??"front",l=a.slice(o+1).filter(u=>(n.get(u).side??"front")===i);if(!l.length)continue;let h;for(let u of E0(e.get(a[o]).regions)){let f=u.reduce((w,x)=>w+z1(x),0);if(!(f>.001)||!a0(u,-.5,"round").length)continue;let d=u;for(let w of l)d.length&&(d=d0(d,e.get(w).regions));if(d.reduce((w,x)=>w+z1(x),0)>.001*Math.max(1,f))continue;let g=l.filter(w=>G1(u,e.get(w).regions).length),p=g.length?g:l;if(h){h.count++;for(let w of p)h.under.includes(w)||h.under.push(w);continue}let[v,b,y,M]=Q0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:a[o],under:p,count:1,at:[v0((v+y)/2),v0((b+M)/2)]}}h&&s.push(h)}return s}function Hl(t,e){for(let n of t.slice(0,5)){let r=n.under.map(s=>`"${s}"`),a=r.length>1?`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`:r[0];e.push(`Part "${n.part}": ${n.count>1?`${n.count} fills`:"a fill"} on layer "${n.layer}" (${n.count>1?"the first ":""}at [${n.at.join(", ")}]) ${n.count>1?"lie":"lies"} wholly under ${a}, stacked above it in the files: printed, ${n.count>1?"they":"it"} won't show, and engraved, ${n.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${n.layer}" a higher order.`)}if(t.length>5){let n=t.slice(5),r=new Set(n.map(s=>s.part)).size,a=[...new Set(n.map(s=>`"${s.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${r} part${r>1?"s":""} (layer${a.length>1?"s":""} ${a.slice(0,5).join(", ")}${a.length>5?" and more":""}).`)}}function rr(t,e,n,r){let a=t.stack??1,c=(t.placements?.length??0)/a===r?n:0,o=t.glue?.face==="bottom",i=e.glue?.face==="top";return c*a+(i!==o?a-1:0)}function Ol(t,e){let n=new Set,r=(a,s)=>{if(!a.glue||n.has(a))return;if(s.includes(a)){e.push(`Part "${a.name}" is glued in a loop of parts; it is left where it is.`),n.add(a);return}let c=t.find(h=>h.name===a.glue.host&&h!==a);if(!c?.placements){e.push(`Part "${a.name}" is glued to "${a.glue.host}", which is not a placed part.`),n.add(a);return}r(c,[...s,a]);let o=c.placements.map(R0),i=a.glue.face==="top"?c.thickness:-a.thickness,l=a.placements.length/(a.stack??1);a.placements=a.placements.map((h,u)=>{let f=o[rr(c,a,Math.floor(u/(a.stack??1)),l)];return{...h,matrix:T1(f,T1(U0(0,0,i),R0(h)))}}),n.add(a)};for(let a of t)r(a,[])}function Rl(t,e,n,r){let a=0,s=50;for(let g=0;g<14;g++){let p=(a+s)/2;a0(t,-p,"round").length?a=p:s=p}if(a<1)return[];let c=a0(t,-a*.98,"round"),o=Q0(new Map([["cut",{regions:c,lines:[]}]]));if(!o)return[];let[i,l]=[(o[0]+o[2])/2,(o[1]+o[3])/2];((g,p)=>c.reduce((v,b)=>v+(cn(b,g,p)?z1(b)>0?1:-1:0),0)>0)(i,l)||([i,l]=c.reduce((g,p)=>z1(p)>z1(g)?p:g)[0]);let u=Math.min(6,Math.max(2,a*.9)),f=d3(n,e,{size:u,font:r,halign:"center",valign:"center",spacing:1}),d=Q0(new Map([["t",{regions:f,lines:[]}]])),m=d?Math.min(1,1.6*a/Math.max(d[2]-d[0],1e-9)):1;return f.map(g=>g.map(([p,v])=>[i-p*m,l+v*m]).reverse())}function cn(t,e,n){let r=!1;for(let a=0,s=t.length-1;a<t.length;s=a++){let[c,o]=t[a],[i,l]=t[s];o>n!=l>n&&e<(i-c)*(n-o)/(l-o)+c&&(r=!r)}return r}var Fl=8,_l=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,ql=(t,e)=>Math.max(1,_l.exec(t.slice(e-1))?.[0].length??1);function ar(t,e,n={}){if(!(t instanceof i1))return`error: ${t instanceof Error?t.message:String(t)}`;let r=n.file??"design.kerf",a=(i,l,h)=>`${i?`<${i}>`:r}:${l}:${h}`,s=i=>i===void 0?e:(Object.prototype.hasOwnProperty.call(Q3,i)?Q3[i]:void 0)??n.resolve?.(i),c=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){c.push(` --> ${a(t.file,t.line,t.col)}`);let l=s(t.file)?.split(`
4261
+ `)?.[t.line-1]?.replace(/\r$/,"");if(l!==void 0){let h=String(t.line),u=" ".repeat(h.length),f=l.slice(0,t.col-1),d=ql(l,t.col),m=f.replace(/[^\t]/g," ");c.push(`${u} |`,`${h} | ${l}`,`${u} | ${m}${"^".repeat(d)}`)}}for(let i of Dl(t,a))c.push(` = ${i}`);let o=t.call?c3(t.call):void 0;return o&&c.push(` = ${X5(o)}: ${o.doc}`),c.join(`
4262
+ `)}function Dl(t,e){let n=s=>`in ${s.kind==="module"?"module ":""}${s.name}(), called at ${e(s.file,s.line,s.col)}${s.count>1?` (${s.count} times)`:""}`,r=t.trace.slice(0,Fl).map(n),a=t.trace.length-r.length+t.traceMore;return a&&r.push(`and ${a} more call${a===1?"":"s"}`),r}var sr=new Set(["module","function","if","else","for","let","each","use","include"]),Nl=new Set(["true","false","undef"]),Ul=new Set(["for","if","let","function"]),on={"(":")","[":"]","{":"}"},Bl=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function jl(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let r=n+1;for(;t[r]!=='"';)r+=t[r]==="\\"?2:1;return t.slice(n,r+1)}function ln(t){let{tokens:e}=r3(t),n=[],r=0,a=0,s=c=>{for(;r<c;)if(t[r]===`
4260
4263
  `)a++,r++;else if(t.startsWith("//",r)){let o=t.indexOf(`
4261
4264
  `,r),i=o<0?t.length:o;n.push({kind:"line",text:t.slice(r,i).trimEnd(),breaks:a}),[a,r]=[0,i]}else if(t.startsWith("/*",r)){let o=t.indexOf("*/",r+2)+2,i=t.slice(r,o).replace(/[ \t\r]+\n/g,`
4262
- `);n.push({kind:"block",text:i,breaks:a}),[a,r]=[0,o]}else r++};for(let c of e){if(s(c.pos.offset),c.type==="eof")break;let o=jl(t,c);n.push({kind:"token",text:o,token:c,breaks:a}),a=0,r=c.pos.offset+o.length}return n}function pt(t,e={}){n2(t);let n=" ".repeat(e.indent??2),r=on(t),a=[],s=null,c=-1,o=0,i=[],l=0,h=!0,u=0,f=!1,d=0,m=0,p,g,v=()=>i[i.length-1],b=()=>!v()||v().open==="{"&&!v().record,y=A=>A.kind==="token"&&!!v()&&A.text===cn[v().open],M=(A,L)=>{s!==null&&a.push(s.trimEnd()),L&&a.length&&a[a.length-1]!==""&&a.push(""),c++,o=A,s=n.repeat(A),g=void 0},w=A=>{if(y(A))return v().outer;if(!b())return!p||p.text===","||cn[p.text]?v().inner:p.role==="header"?m+1:v().inner+1;let L=v()?v().inner:0;return h?L:f?u+1:d+1},x=A=>r.slice(A).find(L=>L.kind==="token");for(let A=0;A<r.length;A++){let L=r[A],z=c<0||L.breaks>0;if(L.kind!=="token"){if(z){let E=x(A),I=E?y(E)?v().inner:w(E):0;M(I,L.breaks>1&&c>=0)}else s+=" ";s+=L.text,g=L;continue}let S=L.text,C=L.token.type;if("*!#%".includes(S)&&b()&&!f&&(h||p?.text===")"||p?.text==="else")?L.role="modifier":(S==="!"||(S==="-"||S==="+")&&(!p||Gl(p)))&&(L.role="unary"),S===":"){let E=v();(E?E.ternaries:l)?E?E.ternaries--:l--:E?.open==="["&&(L.role="range")}if((S==="}"&&v()?.record||S==="{"&&p&&["=","(",",","[","?",":"].includes(p.text))&&(L.role="record"),z){let E=w(L);M(E,L.breaks>1&&c>=0),b()&&!y(L)&&(d=E)}else g&&Wl(g,L)&&(s+=" ");if(b()&&h&&!y(L)&&(u=o,f=C==="id"&&r[A+1]?.kind==="token"&&r[A+1].text==="="||S==="function",h=!1),s+=S,cn[S]){let E=v(),I=L.role==="record",H=E&&E.line===c&&(E.open!=="{"||E.record)&&(S!=="{"||I);i.push({record:I,open:S,outer:o,inner:H?E.inner:o+1,line:c,ternaries:0,header:S==="("&&!!p&&Ul.has(p.text)&&p.token?.type==="id"}),S==="{"&&!I&&(h=!0)}else if(y(L)){let E=i.pop();E.header&&(L.role="header",m=E.outer),S==="}"&&!E.record&&(h=!0)}else S===";"&&b()||C==="str"&&S.startsWith("<")&&b()?h=!0:S==="?"&&(v()?v().ternaries++:l++);p=L,g=L}for(s!==null&&a.push(s.trimEnd());a.length&&a[a.length-1]==="";)a.pop();let k=a.length?a.join(`
4265
+ `);n.push({kind:"block",text:i,breaks:a}),[a,r]=[0,o]}else r++};for(let c of e){if(s(c.pos.offset),c.type==="eof")break;let o=jl(t,c);n.push({kind:"token",text:o,token:c,breaks:a}),a=0,r=c.pos.offset+o.length}return n}function gt(t,e={}){n2(t);let n=" ".repeat(e.indent??2),r=ln(t),a=[],s=null,c=-1,o=0,i=[],l=0,h=!0,u=0,f=!1,d=0,m=0,g,p,v=()=>i[i.length-1],b=()=>!v()||v().open==="{"&&!v().record,y=A=>A.kind==="token"&&!!v()&&A.text===on[v().open],M=(A,L)=>{s!==null&&a.push(s.trimEnd()),L&&a.length&&a[a.length-1]!==""&&a.push(""),c++,o=A,s=n.repeat(A),p=void 0},w=A=>{if(y(A))return v().outer;if(!b())return!g||g.text===","||on[g.text]?v().inner:g.role==="header"?m+1:v().inner+1;let L=v()?v().inner:0;return h?L:f?u+1:d+1},x=A=>r.slice(A).find(L=>L.kind==="token");for(let A=0;A<r.length;A++){let L=r[A],z=c<0||L.breaks>0;if(L.kind!=="token"){if(z){let E=x(A),I=E?y(E)?v().inner:w(E):0;M(I,L.breaks>1&&c>=0)}else s+=" ";s+=L.text,p=L;continue}let S=L.text,C=L.token.type;if("*!#%".includes(S)&&b()&&!f&&(h||g?.text===")"||g?.text==="else")?L.role="modifier":(S==="!"||(S==="-"||S==="+")&&(!g||Gl(g)))&&(L.role="unary"),S===":"){let E=v();(E?E.ternaries:l)?E?E.ternaries--:l--:E?.open==="["&&(L.role="range")}if((S==="}"&&v()?.record||S==="{"&&g&&["=","(",",","[","?",":"].includes(g.text))&&(L.role="record"),z){let E=w(L);M(E,L.breaks>1&&c>=0),b()&&!y(L)&&(d=E)}else p&&Wl(p,L)&&(s+=" ");if(b()&&h&&!y(L)&&(u=o,f=C==="id"&&r[A+1]?.kind==="token"&&r[A+1].text==="="||S==="function",h=!1),s+=S,on[S]){let E=v(),I=L.role==="record",H=E&&E.line===c&&(E.open!=="{"||E.record)&&(S!=="{"||I);i.push({record:I,open:S,outer:o,inner:H?E.inner:o+1,line:c,ternaries:0,header:S==="("&&!!g&&Ul.has(g.text)&&g.token?.type==="id"}),S==="{"&&!I&&(h=!0)}else if(y(L)){let E=i.pop();E.header&&(L.role="header",m=E.outer),S==="}"&&!E.record&&(h=!0)}else S===";"&&b()||C==="str"&&S.startsWith("<")&&b()?h=!0:S==="?"&&(v()?v().ternaries++:l++);g=L,p=L}for(s!==null&&a.push(s.trimEnd());a.length&&a[a.length-1]==="";)a.pop();let k=a.length?a.join(`
4263
4266
  `)+`
4264
- `:"";return Xl(t,k),k}var Gl=t=>Bl.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&sr.has(t.text)||t.role==="unary"||t.role==="modifier";function Wl(t,e){if(t.kind!=="token"||e.kind!=="token")return!0;let n=t.text,r=e.text;if(r===","||r===";"||r===")"||r==="]"||n==="("||n==="["||n==="{"&&r==="}"||n==="{"&&t.role==="record"||r==="}"&&e.role==="record"||n==="."||r==="."||t.role==="unary"||t.role==="modifier"||t.role==="range"||e.role==="range")return!1;let a=t.token,s=a.type==="num"||a.type==="str"&&!n.startsWith("<")||a.type==="id"&&(!sr.has(n)||Nl.has(n))||n===")"&&t.role!=="header"||n==="]";return r==="("?n==="for"||n==="if"||n==="let"||!s&&n!=="function":r==="["?!s:!0}function Xl(t,e){let n=on(t),r=on(e);if(!(n.length===r.length&&n.every((s,c)=>s.kind===r[c].kind&&s.text===r[c].text)))throw new i1("The formatter would change the program, so it was left as it is")}function cr(t){let e=new Map;for(let n of t.sheets)for(let r of n.items){let[a,s]=r.offset??[0,0],c=i=>i.map(([l,h])=>[l-a,s-h]),o=new Map;for(let[i,l]of r.layers)o.set(i,{regions:l.regions.map(c),lines:l.lines.map(c)});e.set(`${r.part}\0${r.copy}`,o)}return e}var or=t=>Math.round(t*100)/100,gt=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function ir(t,e,n=.01){let r=cr(t),a=cr(e),s=[],c=o=>{let[i,l]=o.split("\0");return{part:i,copy:Number(l)}};for(let o of new Set([...r.keys(),...a.keys()])){let i=r.get(o),l=a.get(o);if(!i||!l){s.push({...c(o),change:i?"removed":"added"});continue}for(let h of new Set([...i.keys(),...l.keys()])){let u=i.get(h)??{regions:[],lines:[]},f=l.get(h)??{regions:[],lines:[]},d=ze(u.regions,f.regions),m=d.reduce((M,w)=>M+Math.abs(z1(w)),0),p=new Set(u.lines.map(gt)),g=new Set(f.lines.map(gt)),v=u.lines.filter(M=>!g.has(gt(M))),b=f.lines.filter(M=>!p.has(gt(M)));if(m<=n&&!v.length&&!b.length)continue;let y=Q0(new Map([[h,{regions:m>n?d:[],lines:[...v,...b]}]]));s.push({...c(o),layer:h,change:i.has(h)?l.has(h)?"changed":"removed":"added",...m>n&&{area:or(m)},...v.length&&{linesRemoved:v.length},...b.length&&{linesAdded:b.length},...y&&{at:y.map(or)}})}}return s}var Zl=[Math.SQRT1_2,Math.SQRT1_2,0],Yl=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],ln=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],Kl=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),y3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],lr=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Jl=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ql=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3],t[4]*e[0]+t[5]*e[1]+t[6]*e[2]+t[7],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]+t[11]],J2=t=>t.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]);function hr(t,e){let n=parseInt(t.slice(1),16),r=a=>Math.max(0,Math.min(255,Math.round(a*e))).toString(16).padStart(2,"0");return`#${r(n>>16)}${r(n>>8&255)}${r(n&255)}`}function ur(t,e,n){if(t.folds?.length)return Le(t).flatMap(o=>ur(o,e,n));let r=(o,i,l)=>Ql(t.matrix,t.bends?.length?Ae(t.bends,t.thickness,[o,i,l]):[o,i,l]),a=[],s=(o,i)=>{if(o.length<3)return;let l=Jl(lr(o[1],o[0]),lr(o[2],o[0])),h=[0,0,0];for(let m=0;m<o.length;m++){let p=o[m],g=o[(m+1)%o.length];h[0]+=(p[1]-g[1])*(p[2]+g[2]),h[1]+=(p[2]-g[2])*(p[0]+g[0]),h[2]+=(p[0]-g[0])*(p[1]+g[1])}let u=Math.hypot(...h)||Math.hypot(...l);if(!u)return;let f=[h[0]/u,h[1]/u,h[2]/u];if(y3(f,ln)<=0)return;let d=o.reduce((m,p)=>[m[0]+p[0],m[1]+p[1],m[2]+p[2]],[0,0,0]);a.push({pts:o,holes:i,color:hr(e,.55+.45*Math.max(0,y3(f,Kl))),depth:y3([d[0]/o.length,d[1]/o.length,d[2]/o.length],ln),stroke:n})},c=t.thickness;for(let o of Pe(t.outline,t.bends)){let i=u=>u.reduce((f,d,m)=>f+d[0]*u[(m+1)%u.length][1]-u[(m+1)%u.length][0]*d[1],0),l=o.find(u=>i(u)>0)??o[0],h=o.filter(u=>u!==l);s(l.map(([u,f])=>r(u,f,c)),h.map(u=>u.map(([f,d])=>r(f,d,c)))),s([...l].reverse().map(([u,f])=>r(u,f,0)),h.map(u=>[...u].reverse().map(([f,d])=>r(f,d,0))));for(let u of o)for(let f=0;f<u.length;f++){let[d,m]=u[f],[p,g]=u[(f+1)%u.length];s([r(d,m,0),r(p,g,0),r(p,g,c),r(d,m,c)])}}return a}function eh(t,e){let n=typeof t.size=="number"?t.size:Math.max(...t.size),r=[(t.from[0]+t.to[0])/2,(t.from[1]+t.to[1])/2,(t.from[2]+t.to[2])/2];return[{pts:[t.from,t.to],color:e,depth:y3(r,ln)+n/2,stroke:String(n)}]}function th(t,e=640,n=420){let r=p=>[y3(p,Zl),-y3(p,Yl)],a=1/0,s=1/0,c=-1/0,o=-1/0;for(let p of t)for(let g of p.pts){let[v,b]=r(g);a=Math.min(a,v),c=Math.max(c,v),s=Math.min(s,b),o=Math.max(o,b)}if(!Number.isFinite(a))return"";let i=Math.max(c-a,o-s)*.04+1,l=Math.min(e/(c-a+2*i),n/(o-s+2*i)),h=p=>{let[g,v]=r(p);return`${((g-a+i)*l).toFixed(1)} ${((v-s+i)*l).toFixed(1)}`},u=p=>`M${p.map(h).join("L")}Z`,f=[...t].sort((p,g)=>p.depth-g.depth).map(p=>p.pts.length===2?`<path d="M${h(p.pts[0])}L${h(p.pts[1])}" stroke="${p.color}" stroke-width="${(Number(p.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(p.pts)}${(p.holes??[]).map(u).join("")}" fill="${p.color}" fill-rule="evenodd" stroke="${p.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((c-a+2*i)*l).toFixed(0),m=((o-s+2*i)*l).toFixed(0);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d} ${m}" width="${d}" height="${m}">${f.join("")}</svg>`}var nh="#d9bf91",rh="#cfc6b8",ah="#e08a3c";function fr(t,e){let n=new Map;t.parts.forEach((f,d)=>n.set(f.name,f.label??d+1));let r=t.assembly.filter(f=>f.placed),a=t.steps.length?t.steps:["Put the parts together"],s=f=>t.steps.length?f??0:1,c=f=>le[f]??X2[f]?.color??"#9a9a9a",o=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",i=[],l=r.filter(f=>s(f.step)===0);a.forEach((f,d)=>{let m=d+1,p=[];for(let b of r){let y=s(b.step);y>m||p.push(...ur(b,y===m?ah:b.step===void 0&&!t.steps.length?nh:rh,y===m?"#7a3e0c":"#8a8274"))}for(let b of t.hardware){let y=t.steps.length?b.step:1;y<=m&&p.push(...eh(b,y===m?c(b.kind):hr(c(b.kind),.8)))}let g=new Map;for(let b of r)s(b.step)===m&&g.set(b.name,(g.get(b.name)??0)+1);let v=new Map;for(let b of t.hardware)if((t.steps.length?b.step:1)===m){let y=typeof b.size=="number"?`${b.size} mm`:`${b.size[0]} x ${b.size[1]} mm`,M=Math.round(Math.hypot(b.to[0]-b.from[0],b.to[1]-b.from[1],b.to[2]-b.from[2])),w=`${b.label?`${J2(b.label)}: `:""}${J2(b.kind)}, ${y}, ${M} mm long`;v.set(w,(v.get(w)??0)+1)}i.push(`<section>
4267
+ `:"";return Xl(t,k),k}var Gl=t=>Bl.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&sr.has(t.text)||t.role==="unary"||t.role==="modifier";function Wl(t,e){if(t.kind!=="token"||e.kind!=="token")return!0;let n=t.text,r=e.text;if(r===","||r===";"||r===")"||r==="]"||n==="("||n==="["||n==="{"&&r==="}"||n==="{"&&t.role==="record"||r==="}"&&e.role==="record"||n==="."||r==="."||t.role==="unary"||t.role==="modifier"||t.role==="range"||e.role==="range")return!1;let a=t.token,s=a.type==="num"||a.type==="str"&&!n.startsWith("<")||a.type==="id"&&(!sr.has(n)||Nl.has(n))||n===")"&&t.role!=="header"||n==="]";return r==="("?n==="for"||n==="if"||n==="let"||!s&&n!=="function":r==="["?!s:!0}function Xl(t,e){let n=ln(t),r=ln(e);if(!(n.length===r.length&&n.every((s,c)=>s.kind===r[c].kind&&s.text===r[c].text)))throw new i1("The formatter would change the program, so it was left as it is")}function cr(t){let e=new Map;for(let n of t.sheets)for(let r of n.items){let[a,s]=r.offset??[0,0],c=i=>i.map(([l,h])=>[l-a,s-h]),o=new Map;for(let[i,l]of r.layers)o.set(i,{regions:l.regions.map(c),lines:l.lines.map(c)});e.set(`${r.part}\0${r.copy}`,o)}return e}var or=t=>Math.round(t*100)/100,vt=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function ir(t,e,n=.01){let r=cr(t),a=cr(e),s=[],c=o=>{let[i,l]=o.split("\0");return{part:i,copy:Number(l)}};for(let o of new Set([...r.keys(),...a.keys()])){let i=r.get(o),l=a.get(o);if(!i||!l){s.push({...c(o),change:i?"removed":"added"});continue}for(let h of new Set([...i.keys(),...l.keys()])){let u=i.get(h)??{regions:[],lines:[]},f=l.get(h)??{regions:[],lines:[]},d=ze(u.regions,f.regions),m=d.reduce((M,w)=>M+Math.abs(z1(w)),0),g=new Set(u.lines.map(vt)),p=new Set(f.lines.map(vt)),v=u.lines.filter(M=>!p.has(vt(M))),b=f.lines.filter(M=>!g.has(vt(M)));if(m<=n&&!v.length&&!b.length)continue;let y=Q0(new Map([[h,{regions:m>n?d:[],lines:[...v,...b]}]]));s.push({...c(o),layer:h,change:i.has(h)?l.has(h)?"changed":"removed":"added",...m>n&&{area:or(m)},...v.length&&{linesRemoved:v.length},...b.length&&{linesAdded:b.length},...y&&{at:y.map(or)}})}}return s}var Zl=[Math.SQRT1_2,Math.SQRT1_2,0],Yl=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],hn=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],Kl=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),y3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],lr=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Jl=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ql=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3],t[4]*e[0]+t[5]*e[1]+t[6]*e[2]+t[7],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]+t[11]],J2=t=>t.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]);function hr(t,e){let n=parseInt(t.slice(1),16),r=a=>Math.max(0,Math.min(255,Math.round(a*e))).toString(16).padStart(2,"0");return`#${r(n>>16)}${r(n>>8&255)}${r(n&255)}`}function ur(t,e,n){if(t.folds?.length)return Le(t).flatMap(o=>ur(o,e,n));let r=(o,i,l)=>Ql(t.matrix,t.bends?.length?Ae(t.bends,t.thickness,[o,i,l]):[o,i,l]),a=[],s=(o,i)=>{if(o.length<3)return;let l=Jl(lr(o[1],o[0]),lr(o[2],o[0])),h=[0,0,0];for(let m=0;m<o.length;m++){let g=o[m],p=o[(m+1)%o.length];h[0]+=(g[1]-p[1])*(g[2]+p[2]),h[1]+=(g[2]-p[2])*(g[0]+p[0]),h[2]+=(g[0]-p[0])*(g[1]+p[1])}let u=Math.hypot(...h)||Math.hypot(...l);if(!u)return;let f=[h[0]/u,h[1]/u,h[2]/u];if(y3(f,hn)<=0)return;let d=o.reduce((m,g)=>[m[0]+g[0],m[1]+g[1],m[2]+g[2]],[0,0,0]);a.push({pts:o,holes:i,color:hr(e,.55+.45*Math.max(0,y3(f,Kl))),depth:y3([d[0]/o.length,d[1]/o.length,d[2]/o.length],hn),stroke:n})},c=t.thickness;for(let o of Pe(t.outline,t.bends)){let i=u=>u.reduce((f,d,m)=>f+d[0]*u[(m+1)%u.length][1]-u[(m+1)%u.length][0]*d[1],0),l=o.find(u=>i(u)>0)??o[0],h=o.filter(u=>u!==l);s(l.map(([u,f])=>r(u,f,c)),h.map(u=>u.map(([f,d])=>r(f,d,c)))),s([...l].reverse().map(([u,f])=>r(u,f,0)),h.map(u=>[...u].reverse().map(([f,d])=>r(f,d,0))));for(let u of o)for(let f=0;f<u.length;f++){let[d,m]=u[f],[g,p]=u[(f+1)%u.length];s([r(d,m,0),r(g,p,0),r(g,p,c),r(d,m,c)])}}return a}function eh(t,e){let n=typeof t.size=="number"?t.size:Math.max(...t.size),r=[(t.from[0]+t.to[0])/2,(t.from[1]+t.to[1])/2,(t.from[2]+t.to[2])/2];return[{pts:[t.from,t.to],color:e,depth:y3(r,hn)+n/2,stroke:String(n)}]}function th(t,e=640,n=420){let r=g=>[y3(g,Zl),-y3(g,Yl)],a=1/0,s=1/0,c=-1/0,o=-1/0;for(let g of t)for(let p of g.pts){let[v,b]=r(p);a=Math.min(a,v),c=Math.max(c,v),s=Math.min(s,b),o=Math.max(o,b)}if(!Number.isFinite(a))return"";let i=Math.max(c-a,o-s)*.04+1,l=Math.min(e/(c-a+2*i),n/(o-s+2*i)),h=g=>{let[p,v]=r(g);return`${((p-a+i)*l).toFixed(1)} ${((v-s+i)*l).toFixed(1)}`},u=g=>`M${g.map(h).join("L")}Z`,f=[...t].sort((g,p)=>g.depth-p.depth).map(g=>g.pts.length===2?`<path d="M${h(g.pts[0])}L${h(g.pts[1])}" stroke="${g.color}" stroke-width="${(Number(g.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(g.pts)}${(g.holes??[]).map(u).join("")}" fill="${g.color}" fill-rule="evenodd" stroke="${g.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((c-a+2*i)*l).toFixed(0),m=((o-s+2*i)*l).toFixed(0);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d} ${m}" width="${d}" height="${m}">${f.join("")}</svg>`}var nh="#d9bf91",rh="#cfc6b8",ah="#e08a3c";function fr(t,e){let n=new Map;t.parts.forEach((f,d)=>n.set(f.name,f.label??d+1));let r=t.assembly.filter(f=>f.placed),a=t.steps.length?t.steps:["Put the parts together"],s=f=>t.steps.length?f??0:1,c=f=>le[f]??X2[f]?.color??"#9a9a9a",o=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",i=[],l=r.filter(f=>s(f.step)===0);a.forEach((f,d)=>{let m=d+1,g=[];for(let b of r){let y=s(b.step);y>m||g.push(...ur(b,y===m?ah:b.step===void 0&&!t.steps.length?nh:rh,y===m?"#7a3e0c":"#8a8274"))}for(let b of t.hardware){let y=t.steps.length?b.step:1;y<=m&&g.push(...eh(b,y===m?c(b.kind):hr(c(b.kind),.8)))}let p=new Map;for(let b of r)s(b.step)===m&&p.set(b.name,(p.get(b.name)??0)+1);let v=new Map;for(let b of t.hardware)if((t.steps.length?b.step:1)===m){let y=typeof b.size=="number"?`${b.size} mm`:`${b.size[0]} x ${b.size[1]} mm`,M=Math.round(Math.hypot(b.to[0]-b.from[0],b.to[1]-b.from[1],b.to[2]-b.from[2])),w=`${b.label?`${J2(b.label)}: `:""}${J2(b.kind)}, ${y}, ${M} mm long`;v.set(w,(v.get(w)??0)+1)}i.push(`<section>
4265
4268
  <h2><span>${m}</span> ${J2(f)}</h2>
4266
- <div class="view">${th(p)}</div>
4267
- ${g.size?`<h3>Parts</h3>${o([...g].sort((b,y)=>(n.get(b[0])??0)-(n.get(y[0])??0)).map(([b,y])=>`<b>${n.get(b)??""}</b> ${J2(b)}${y>1?` &times; ${y}`:""}`))}`:""}
4269
+ <div class="view">${th(g)}</div>
4270
+ ${p.size?`<h3>Parts</h3>${o([...p].sort((b,y)=>(n.get(b[0])??0)-(n.get(y[0])??0)).map(([b,y])=>`<b>${n.get(b)??""}</b> ${J2(b)}${y>1?` &times; ${y}`:""}`))}`:""}
4268
4271
  ${v.size?`<h3>Hardware</h3>${o([...v].map(([b,y])=>`${b}${y>1?` &times; ${y}`:""}`))}`:""}
4269
4272
  </section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${J2(f.name)}${f.mirrored?" (mirrored)":""}${f.copies&&!f.mirrored?` (cop${f.copies.length>1?"ies":"y"} ${f.copies.join(", ")})`:""}</td><td>${f.qty}</td><td>${f.width} &times; ${f.height} mm</td><td>${f.thickness} mm ${J2(f.material)}${f.paint?`, painted ${f.paint}`:""}</td></tr>`).join(""),u=t.sheets.map((f,d)=>`<figure><div class="sheet">${f.svg.replace(/^<\?xml[^>]*>\s*/,"")}</div><figcaption>Sheet ${d+1}: ${f.width} &times; ${f.height} mm, ${f.thickness} mm ${J2(f.material)}</figcaption></figure>`).join("");return`<!doctype html>
4270
4273
  <html lang="en">
@@ -4298,16 +4301,16 @@ ${i.join(`
4298
4301
  </body>
4299
4302
  </html>
4300
4303
  `}var sh={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function dr(t,e={}){return t.replace(/&(#x[0-9a-fA-F]+|#\d+|[A-Za-z_][\w.-]*);/g,(n,r)=>{if(r[0]==="#"){let a=r[1]==="x"?parseInt(r.slice(2),16):parseInt(r.slice(1),10);return Number.isFinite(a)&&a<=1114111?String.fromCodePoint(a):n}return sh[r]??e[r]??n})}function mr(t){let e=[],n={},r={name:"#document",attrs:{},children:[],text:""},a=[r],s=0,c=i=>{let l=t.slice(0,s).split(`
4301
- `).length;throw new Error(`${i} (line ${l})`)};for(;s<t.length;){let i=t.indexOf("<",s),l=i<0?t.length:i;if(l>s&&(a[a.length-1].text+=dr(t.slice(s,l),n)),i<0)break;if(s=i,t.startsWith("<!--",s)){let h=t.indexOf("-->",s+4);h<0&&c("Unclosed comment"),e.push(t.slice(s+4,h)),s=h+3}else if(t.startsWith("<![CDATA[",s)){let h=t.indexOf("]]>",s+9);h<0&&c("Unclosed CDATA section"),a[a.length-1].text+=t.slice(s+9,h),s=h+3}else if(t.startsWith("<?",s)){let h=t.indexOf("?>",s+2);h<0&&c("Unclosed processing instruction"),s=h+2}else if(t.startsWith("<!",s)){let h=0,u=s+2;for(;u<t.length;u++){let d=t[u];if(d==="[")h++;else if(d==="]")h--;else if(d===">"&&h<=0)break}let f=t.slice(s,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];s=u+1}else if(t[s+1]==="/"){let h=t.indexOf(">",s);h<0&&c("Unclosed end tag");let u=t.slice(s+2,h).trim(),f=a.pop();(!f||f===r||f.name!==u)&&c(`</${u}> does not match <${f?.name??"nothing"}>`),s=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(s,s+256));h||c("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};s+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=s;let d=f.exec(t);if(d||c(`Bad attribute in <${u.name}>`),s=f.lastIndex,d[5]){a[a.length-1].children.push(u),d[5]===">"&&a.push(u);break}u.attrs[d[1]]=dr(d[3]??d[4]??"",n)}}}a.length>1&&c(`<${a[a.length-1].name}> is not closed`);let o=r.children[0];if(!o)throw new Error("The file has no elements");return{root:o,comments:e}}var b2={cut:{name:"cut",mode:"cut",color:"#ff0000"},score:{name:"score",mode:"line",color:"#0000ff"},engrave:{name:"engrave",mode:"fill",color:"#000000"},guide:{name:"guide",mode:"guide",color:"#00a0ff"}},un={black:"#000000",white:"#ffffff",red:"#ff0000",lime:"#00ff00",green:"#008000",blue:"#0000ff",yellow:"#ffff00",cyan:"#00ffff",aqua:"#00ffff",magenta:"#ff00ff",fuchsia:"#ff00ff",gray:"#808080",grey:"#808080",silver:"#c0c0c0",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",teal:"#008080",orange:"#ffa500"},ch=Object.fromEntries(Object.entries(un).reverse().map(([t,e])=>[e,t]));function f5(t,e){if(t===void 0)return;if(t=t.trim().toLowerCase(),t==="none"||t==="transparent")return"none";if(t==="currentcolor")return e;if(t.startsWith("url("))return"paint";if(un[t])return un[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let r=n[1];if(r.length===3||r.length===4)return"#"+[...r.slice(0,3)].map(a=>a+a).join("");if(r.length===6||r.length===8)return"#"+r.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let r=n[1].split(/[\s,/]+/).filter(Boolean);if(r.length>=3){let a=r.slice(0,3).map(s=>{let c=s.endsWith("%")?parseFloat(s)*255/100:parseFloat(s);return Math.max(0,Math.min(255,Math.round(c||0)))});return r[3]!==void 0&&parseFloat(r[3])===0?"none":"#"+a.map(s=>s.toString(16).padStart(2,"0")).join("")}}return"#000000"}var x3=(t,e)=>n3(t,Math.PI/12,e),d5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function oh(t){let e=Jt;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let a=d5(r),s=(a[0]??0)*Math.PI/180,c=Jt;if(n==="matrix"&&a.length===6)c=a;else if(n==="translate")c=[1,0,0,1,a[0]??0,a[1]??0];else if(n==="scale")c=[a[0]??1,0,0,a[1]??a[0]??1,0,0];else if(n==="rotate"){let o=Math.cos(s),i=Math.sin(s),[l,h]=[a[1]??0,a[2]??0];c=[o,i,-i,o,l-o*l+i*h,h-i*l-o*h]}else n==="skewX"?c=[1,0,Math.tan(s),1,0,0]:n==="skewY"&&(c=[1,Math.tan(s),0,1,0,0]);e=Xe(e,c)}return e}function ih(t,e){let n=[],r=[],a=[0,0],s=[0,0],c=(l,h)=>se(e,[l,h]),o=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,i=l=>{r.length&&n.push({segs:r,closed:l}),r=[]};for(let l of t)if(l.type==="M")i(!1),a=s=c(l.x,l.y);else if(l.type==="L"){let h=c(l.x,l.y);o(s,h)||r.push({c:"L",a:s,b:h}),s=h}else if(l.type==="Q"){let h=c(l.x1,l.y1),u=c(l.x,l.y);r.push({c:"C",a:s,p1:[s[0]+2/3*(h[0]-s[0]),s[1]+2/3*(h[1]-s[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),s=u}else if(l.type==="C"){let h=c(l.x,l.y);r.push({c:"C",a:s,p1:c(l.x1,l.y1),p2:c(l.x2,l.y2),b:h}),s=h}else r.length&&!o(s,a)&&r.push({c:"L",a:s,b:a}),i(!0),s=a;return i(!1),n}var lh=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],hh=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function pr(t){let e={};for(let n of t.split(";")){let r=n.indexOf(":");if(r<0)continue;let a=n.slice(0,r).trim().toLowerCase(),s=n.slice(r+1).replace(/!important/i,"").trim();a&&s&&(e[a]=s)}return e}function uh(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let a=pr(r);for(let s of n.split(",")){let c=s.trim(),o=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(c);if(!o)continue;let i=[],l;for(let[,h,u]of o[2].matchAll(/([.#])([\w-]+)/g))h==="."?i.push(u):l=u;e.push({tag:o[1]&&o[1]!=="*"?o[1]:void 0,id:l,classes:i,decls:a})}}return e}function gr(t,e){switch(t){case"mm":return 1;case"cm":return 10;case"in":return 25.4;case"pt":return 25.4/72;case"pc":return 25.4/6;case"q":return .25;default:return 25.4/e}}function hn(t,e){if(!t)return;let n=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(t);if(!(!n||n[2]==="%"))return Number(n[1])*gr(n[2].toLowerCase(),e)}var fh=/^(path|g|rect|circle|ellipse|line|polyline|polygon|layer|svg|use|text|tspan|group|shape|cls|clip|mask|defs|_?x?\d|Layer_\d|Ebene|Calque|Capa|Livello|Laag|Warstwa)[-_ ]*[\d-]*$/i;function dh(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!fh.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function mh(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return b2.score;if(/engrav|raster|etch/.test(e))return b2.engrave;if(/\bguide/.test(e))return b2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return b2.cut}function vr(t,e={}){if(t=t.replace(/^\uFEFF/,""),!/^\s*</.test(t)||t.includes("\0"))throw new Error("This is not an SVG file: it does not start with a tag");let n=mr(t),r=n.root;if(r.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let a=[],s=n.comments.some(q=>/Adobe Illustrator/i.test(q)),c=e.dpi??(s?72:96);e.dpi===void 0&&s&&a.push("Adobe Illustrator file: px measured at 72 per inch.");let o=d5(r.attrs.viewBox??""),i=hn(r.attrs.width,c),l=hn(r.attrs.height,c),h=25.4/c,u=h,f=h,d=0,m=0,p=0,g=0;if(o.length===4&&o[2]>0&&o[3]>0&&(u=i!==void 0?i/o[2]:l!==void 0?l/o[3]:h,f=l!==void 0?l/o[3]:u,d=o[0],m=o[1],i!==void 0&&l!==void 0)){let q=(r.attrs.preserveAspectRatio??"").trim().split(/\s+/).filter(Boolean);q[0]==="defer"&&q.shift();let Z=q[0]??"xMidYMid";if(Z!=="none"){let e1=q[1]==="slice"?Math.max(u,f):Math.min(u,f),Q=(W,$1)=>W.test(Z)?0:$1.test(Z)?1:.5;p=(i-o[2]*e1)*Q(/xMin/,/xMax/),g=(l-o[3]*e1)*Q(/YMin/,/YMax/),u=f=e1}}i===void 0&&l===void 0&&e.dpi===void 0&&!s&&a.push(`The file gives no page size in mm or inches: px measured at ${c} per inch.`);let v=l??(o.length===4?o[3]*f:0),b=Xe([1,0,0,-1,0,v],[u,0,0,f,-d*u+p,-m*f+g]),y=o.length===4?o[2]:(i??0)/h,M=o.length===4?o[3]:(l??0)/h,w=(q,Z)=>{if(q===void 0)return 0;let e1=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(q);if(!e1)return parseFloat(q)||0;let Q=Number(e1[1]),W=e1[2].toLowerCase();return W==="%"?Q/100*(Z==="x"?y:Z==="y"?M:Math.hypot(y,M)/Math.SQRT2):W===""||W==="px"?Q:Q*gr(W,c)/h},x=[],k=new Map,A=q=>{q.name==="style"&&x.push(...uh(q.text)),q.attrs.id&&k.set(q.attrs.id,q),q.children.forEach(A)};A(r);let L=(q,Z)=>{let e1={};for(let W of Object.keys(Z))hh.has(W)&&(e1[W]=Z[W]);for(let W of lh)q.attrs[W]!==void 0&&(e1[W]=q.attrs[W]);let Q=(q.attrs.class??"").split(/\s+/).filter(Boolean);for(let W of x)(!W.tag||W.tag===q.name)&&(!W.id||W.id===q.attrs.id)&&W.classes.every($1=>Q.includes($1))&&Object.assign(e1,W.decls);return q.attrs.style&&Object.assign(e1,pr(q.attrs.style)),e1},z=[],S=[],C=0,E=0,I=0,H=0,T=0,O=0,_=2e4,D=[],G=q=>Number.isFinite(q[0])&&Number.isFinite(q[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],U=q=>[...V,"x1","y1","x2","y2","points"].some(Z=>q.attrs[Z]!==void 0&&d5(q.attrs[Z]).some(e1=>!Number.isFinite(e1))),J=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),n1=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),m1=q=>{let Z=e1=>w(q.attrs[e1],/^(x|cx|rx|x1|x2|width)$/.test(e1)?"x":/^(y|cy|ry|y1|y2|height)$/.test(e1)?"y":"r");switch(q.name){case"path":return x3(q.attrs.d??"",()=>I++);case"rect":{let[e1,Q,W,$1]=[Z("x"),Z("y"),Z("width"),Z("height")];if(W<=0||$1<=0)return[];let K=q.attrs.rx!==void 0?Z("rx"):q.attrs.ry!==void 0?Z("ry"):0,k1=q.attrs.ry!==void 0?Z("ry"):K;return K=Math.min(Math.abs(K),W/2),k1=Math.min(Math.abs(k1),$1/2),K<=0||k1<=0?x3(`M${e1} ${Q}H${e1+W}V${Q+$1}H${e1}Z`):x3(`M${e1+K} ${Q}H${e1+W-K}A${K} ${k1} 0 0 1 ${e1+W} ${Q+k1}V${Q+$1-k1}A${K} ${k1} 0 0 1 ${e1+W-K} ${Q+$1}H${e1+K}A${K} ${k1} 0 0 1 ${e1} ${Q+$1-k1}V${Q+k1}A${K} ${k1} 0 0 1 ${e1+K} ${Q}Z`)}case"circle":case"ellipse":{let[e1,Q]=[Z("cx"),Z("cy")],W=q.name==="circle"?Z("r"):Z("rx"),$1=q.name==="circle"?Z("r"):q.attrs.ry!==void 0?Z("ry"):W;return W<=0||$1<=0?[]:x3(`M${e1+W} ${Q}A${W} ${$1} 0 0 1 ${e1} ${Q+$1}A${W} ${$1} 0 0 1 ${e1-W} ${Q}A${W} ${$1} 0 0 1 ${e1} ${Q-$1}A${W} ${$1} 0 0 1 ${e1+W} ${Q}Z`)}case"line":return x3(`M${Z("x1")} ${Z("y1")}L${Z("x2")} ${Z("y2")}`);case"polyline":case"polygon":{let e1=d5(q.attrs.points??"");if(e1.length<4)return[];let Q=`M${e1[0]} ${e1[1]}`;for(let W=2;W+1<e1.length;W+=2)Q+=`L${e1[W]} ${e1[W+1]}`;return x3(q.name==="polygon"?Q+"Z":Q)}}},M1=q=>(q.text+q.children.map(Z=>Z.name==="tspan"?" "+M1(Z):"").join("")).replace(/\s+/g," ").trim(),c1=(q,Z,e1,Q,W,$1)=>{if($1>64||J.has(q.name)||T&&++O>_)return;let K=L(q,e1);if(K.display==="none"||K.visibility==="hidden"||K.opacity==="0"){(q.children.length||n1.has(q.name))&&E++;return}let k1=Xe(Z,oh(q.attrs.transform));if(!k1.every(Number.isFinite)){H++;return}let L1=dh(q),A0=q.attrs["inkscape:groupmode"]==="layer",P=Q;if(q.name==="g"||q.name==="svg"||q.name==="a"||q.name==="switch"){let N1=q.attrs["inkscape:label"]??q.attrs["data-name"]??q.attrs.id,X1=mh(N1);if(q.attrs["data-mode"]&&N1&&/^(cut|line|fill|guide)$/.test(q.attrs["data-mode"])){let g0=f5(K.stroke,"#000000"),u1=f5(K.fill,"#000000"),E1=q.attrs["data-mode"]==="fill"?u1:g0;P=b2[N1]??{name:N1,mode:q.attrs["data-mode"],color:E1&&E1.startsWith("#")?E1:"#00aa00"}}else X1&&(P=X1);if(q!==r&&q.name==="svg"){let g0=u1=>parseFloat(q.attrs[u1]??"0")||0;k1=Xe(k1,[1,0,0,1,g0("x"),g0("y")])}let h0=A0||X1||q===r||!L1?W:[L1,...W];D.push(q);for(let g0 of q.children)c1(g0,k1,K,P,h0,$1+1);D.pop();return}if(q.name==="use"){let N1=k.get((q.attrs.href??q.attrs["xlink:href"]??"").replace(/^#/,""));if(!N1||D.includes(N1))return;let X1=u1=>parseFloat(q.attrs[u1]??"0")||0,h0=Xe(k1,[1,0,0,1,X1("x"),X1("y")]),g0=N1.name==="symbol"?{...N1,name:"g"}:N1;D.push(N1),T++,c1(g0,h0,K,P,L1?[L1,...W]:W,$1+1),T--,D.pop();return}if(q.name==="image"){C++;return}let j=f5(K.color,"#000000")??"#000000",s1=parseFloat(K["stroke-width"]??"1"),w1=f5(K.stroke,j);w1&&(s1===0||K["stroke-opacity"]==="0")&&(w1="none");let R1=f5(K.fill??"black",j);if(K["fill-opacity"]==="0"&&(R1="none"),q.name==="text"){let N1=M1(q);if(!N1)return;let X1=q.children.find(q1=>q1.name==="tspan"),h0=q1=>d5(q.attrs[q1]??X1?.attrs[q1]??"0")[0]??0,g0=se(k1,[h0("x"),h0("y")]),u1=Math.sqrt(Math.abs(k1[0]*k1[3]-k1[1]*k1[2])),E1=(hn(K["font-size"],96)??16*h)/h;if(!G(g0)||!Number.isFinite(E1*u1)){H++;return}let A1=K["text-anchor"];S.push({text:N1,at:g0,size:E1*u1,angle:Math.atan2(-k1[1],k1[0])*180/Math.PI,font:(K["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:A1==="middle"?"center":A1==="end"?"right":"left",stroke:w1,fill:R1,layer:P});return}if(q.name!=="path"&&U(q)){H++;return}let F1=m1(q);if(!F1){for(let N1 of q.children)c1(N1,k1,K,P,W,$1+1);return}let u0=ih(F1,k1),n0=u0.filter(N1=>N1.segs.every(X1=>G(X1.a)&&G(X1.b)&&(X1.c==="L"||G(X1.p1)&&G(X1.p2))));n0.length<u0.length&&H++,n0.length&&z.push({subs:n0,stroke:w1,fill:q.name==="line"||q.name==="polyline"?"none":R1,fillRule:K["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:P,names:L1?[L1,...W]:W})};c1(r,b,{},void 0,[],0),C&&a.push(`${C} embedded image${C===1?" was":"s were"} left out: trace ${C===1?"it":"them"} to paths first.`),E&&a.push(`${E} hidden element${E===1?" was":"s were"} left out.`),I&&a.push(`${I} path${I===1?" has":"s have"} bad data: read up to the error, as browsers draw ${I===1?"it":"them"}.`),H&&a.push(`${H} element${H===1?" was":"s were"} left out: ${H===1?"its":"their"} numbers are too large to draw.`),O>_&&a.push(`The drawing repeats its elements with <use> more than ${_.toLocaleString("en")} times: only the first ${_.toLocaleString("en")} copies were read.`);let C1=q=>{let[Z,e1,Q]=[1,3,5].map(W=>parseInt(q.slice(W,W+2),16));return Z>=200&&e1<=80&&Q<=80},h1=q=>{let[Z,e1,Q]=[1,3,5].map(W=>parseInt(q.slice(W,W+2),16));return Q>=200&&Z<=80&&e1<=80},B1=q=>!!q.stroke&&q.stroke!=="none",$=z.filter(q=>!q.layer),B=new Map;for(let q of $)B1(q)&&q.stroke.startsWith("#")&&B.set(q.stroke,(B.get(q.stroke)??0)+q.subs.length);let a1=[...B.keys()],b1=a1.filter(C1),o1=new Set(b1.length?b1:a1.length?[a1.reduce((q,Z)=>(B.get(Z)??0)>(B.get(q)??0)?Z:q)]:[]),p1=z.some(q=>B1(q)&&!q.layer)||z.some(q=>q.layer),K1=new Map,Q1=(q,Z)=>{if(q&&q!=="none"){let e1=q.startsWith("#")?q:"#000000";if(o1.has(e1))return b2.cut;if(e1==="#00a0ff")return b2.guide;if(h1(e1))return b2.score;if(!K1.has(e1)){let Q=ch[e1]??"color_"+e1.slice(1);K1.set(e1,{name:Q,mode:"line",color:e1})}return K1.get(e1)}if(Z&&Z!=="none")return p1?b2.engrave:b2.cut};!p1&&z.some(q=>q.fill&&q.fill!=="none")?a.push("The file has filled shapes and no strokes: the shapes are cut out."):!b1.length&&o1.size&&a.push(`No red lines: ${[...o1][0]} lines, the most common colour, are cut.`),K1.size&&a.push(`Lines in ${[...K1.values()].map(q=>q.color).join(", ")} went on their own layer${K1.size===1?"":"s"}, set to mark, not cut.`);let W1=[];for(let q of z){let Z=q.layer??Q1(q.stroke,q.fill);if(!Z)continue;let e1=!q.layer&&Z===b2.cut&&!B1(q);W1.push({subs:q.subs,layer:Z,fillRule:q.fillRule,names:q.names,filled:e1})}let I0=[];for(let q of S){let Z=q.layer??Q1(q.fill!=="none"?void 0:q.stroke,q.fill);Z&&I0.push({...q,layer:Z.mode==="cut"&&p1?b2.engrave:Z})}return{items:W1,texts:I0,notes:a}}var Z1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),A2=([t,e],n)=>{let r=n*Math.PI/180,a=Math.cos(r),s=Math.sin(r);return[t*a-e*s,t*s+e*a]},dn=(t,e)=>[t[0]+e[0],t[1]+e[1]],L2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function Fe(t,e=.005){let n=[t.segs[0].a];for(let r of t.segs)if(r.c==="L")n.push(r.b);else{let a=Z1(r.a,r.p1)+Z1(r.p1,r.p2)+Z1(r.p2,r.b),s=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(a/e))));for(let c=1;c<=s;c++){let o=c/s,i=1-o;n.push([i*i*i*r.a[0]+3*i*i*o*r.p1[0]+3*i*o*o*r.p2[0]+o*o*o*r.b[0],i*i*i*r.a[1]+3*i*i*o*r.p1[1]+3*i*o*o*r.p2[1]+o*o*o*r.b[1]])}}return t.closed&&n.length>1&&Z1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function D2(t,e=!0){let n=0;for(let r=1;r<t.length;r++)n+=Z1(t[r-1],t[r]);return e&&t.length>2?n+Z1(t[t.length-1],t[0]):n}function ee(t,e,n){let r=[],a=e?t.length:t.length-1;for(let s=0;s<a;s++){let c=t[s],o=t[(s+1)%t.length];r.push(c);let i=Math.floor(Z1(c,o)/n);for(let l=1;l<i;l++)r.push([c[0]+(o[0]-c[0])*l/i,c[1]+(o[1]-c[1])*l/i])}return!e&&t.length&&r.push(t[t.length-1]),r}function ve(t,e,n){let r=n[0]-e[0],a=n[1]-e[1],s=r*r+a*a,c=s?((t[0]-e[0])*r+(t[1]-e[1])*a)/s:0;return c=Math.max(0,Math.min(1,c)),Math.hypot(t[0]-e[0]-c*r,t[1]-e[1]-c*a)}var Re=class{constructor(e,n,r){this.size=r;this.cells=new Map;for(let a of e){let s=n?a.length:a.length-1;for(let c=0;c<s;c++){let o=a[c],i=a[(c+1)%a.length],l=Math.max(1,Math.ceil(Z1(o,i)/(r*2)));for(let h=0;h<l;h++){let u=[o[0]+(i[0]-o[0])*h/l,o[1]+(i[1]-o[1])*h/l],f=[o[0]+(i[0]-o[0])*(h+1)/l,o[1]+(i[1]-o[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/r),m=Math.floor(Math.max(u[0],f[0])/r),p=Math.floor(Math.min(u[1],f[1])/r),g=Math.floor(Math.max(u[1],f[1])/r);for(let v=d;v<=m;v++)for(let b=p;b<=g;b++){let y=`${v},${b}`,M=this.cells.get(y);M?M.push([u,f]):this.cells.set(y,[[u,f]])}}}}}near(e,n){let r=Math.floor((e[0]-n)/this.size),a=Math.floor((e[0]+n)/this.size),s=Math.floor((e[1]-n)/this.size),c=Math.floor((e[1]+n)/this.size);for(let o=r;o<=a;o++)for(let i=s;i<=c;i++)for(let[l,h]of this.cells.get(`${o},${i}`)??[])if(ve(e,l,h)<=n)return!0;return!1}meets(e,n,r){let a=Math.max(1,Math.ceil(Z1(e,n)/(this.size*2)));for(let s=0;s<a;s++){let c=[e[0]+(n[0]-e[0])*s/a,e[1]+(n[1]-e[1])*s/a],o=[e[0]+(n[0]-e[0])*(s+1)/a,e[1]+(n[1]-e[1])*(s+1)/a],i=Math.floor((Math.min(c[0],o[0])-r)/this.size),l=Math.floor((Math.max(c[0],o[0])+r)/this.size),h=Math.floor((Math.min(c[1],o[1])-r)/this.size),u=Math.floor((Math.max(c[1],o[1])+r)/this.size);for(let f=i;f<=l;f++)for(let d=h;d<=u;d++)for(let[m,p]of this.cells.get(`${f},${d}`)??[])if(yr(c,o,m,p)<=r)return!0}return!1}};function yr(t,e,n,r){let a=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),s=a(n,r,t),c=a(n,r,e),o=a(t,e,n),i=a(t,e,r);return s*c<0&&o*i<0?0:Math.min(ve(t,n,r),ve(e,n,r),ve(n,t,e),ve(r,t,e))}function ph(t,e,n=.2){let r=t.length;if(r<4)return!1;let a=[0];for(let h=1;h<=r;h++)a.push(a[h-1]+Z1(t[h-1],t[h%r]));let s=a[r],c=m0([t]),o=Math.max(c[2]-c[0],c[3]-c[1],e)/Math.max(1,Math.sqrt(r)),i=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/o),m=Math.floor((Math.max(h[0],u[0])+e)/o),p=Math.floor((Math.min(h[1],u[1])-e)/o),g=Math.floor((Math.max(h[1],u[1])+e)/o);if((m-d+1)*(g-p+1)>4096)return null;for(let v=d;v<=m;v++)for(let b=p;b<=g;b++)f.push(`${v},${b}`);return f};for(let h=0;h<r;h++){let u=t[h],f=t[(h+1)%r],d=l(u,f);if(!d)return!1;for(let m of d)for(let p of i.get(m)??[]){let g=Math.abs(a[h]-a[p]);if(!(Math.min(g,s-g)-Z1(u,f)-Z1(t[p],t[(p+1)%r])<n)&&yr(u,f,t[p],t[(p+1)%r])<=e)return!0}for(let m of d){let p=i.get(m);p?p.push(h):i.set(m,[h])}}return!1}function xr(t,e){let n=t.map(()=>!1),r=[],a=t.map(l=>m0([l]));t.forEach((l,h)=>{let u=t1([l]),f=u.reduce((p,g)=>p+z1(g),0),d=D2(l),m=u.reduce((p,g)=>p+D2(g),0);(u.length!==1||Math.abs(f-Math.abs(z1(l)))>d*.001+1e-6||Math.abs(m-d)>d*.001+.05||ph(l,e))&&(n[h]=!0)});let s=new Map,c=l=>{let h=s.get(l);return h||s.set(l,h=new Re([t[l]],!0,Math.max(e*4,1))),h},o=t.map((l,h)=>h).sort((l,h)=>a[l][0]-a[h][0]),i=[];for(let l of o){let[h,u,f,d]=a[l];for(let m=i.length-1;m>=0;m--)a[i[m]][2]<h-e&&i.splice(m,1);for(let m of i){let p=a[m];if(p[1]>d+e||p[3]<u-e)continue;let[g,v]=t[l].length<=t[m].length?[l,m]:[m,l],b=t[g],y=c(v);for(let M=0;M<b.length;M++)if(y.meets(b[M],b[(M+1)%b.length],e)){r.push([l,m]);break}}i.push(l)}return{self:n,pairs:r}}function _e(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let a=Math.max(n*2,.2),s=new Re(t,r,Math.max(n*4,1)),c=new Re(e,r,Math.max(n*4,1));for(let o of t)for(let i of ee(o,r,a))if(!c.near(i,n))return!1;for(let o of e)for(let i of ee(o,r,a))if(!s.near(i,n))return!1;return!0}function Mr(t,e,n){let r=new Re([t,...e],!0,Math.max(n*4,1)),a=s=>Q2(s,t)&&!e.some(c=>Q2(s,c));return(s,c)=>{let o=c?s.length:s.length-1;if(o<1)return!1;let i;for(let l=0;l<o;l++){let h=s[l],u=s[(l+1)%s.length];if(!r.meets(h,u,n)){i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(c||l!==0&&l!==o-1)return!1;let f=Z1(h,u),d=Math.min(n*3,f/3)/f,m=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,p=l===o-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(r.meets(m,p,n))return!1;i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return i?a(i):!0}}function wr(t,e,n){if(!t.length)return!1;let r=new Re([e],!0,Math.max(n*4,1));return t.some(a=>ee(a,!1,Math.max(n*2,.2)).some(s=>r.near(s,n)))}function Q2(t,e){let n=!1;for(let r=0,a=e.length-1;r<e.length;a=r++){let[s,c]=e[r],[o,i]=e[a];c>t[1]!=i>t[1]&&t[0]<(o-s)*(t[1]-c)/(i-c)+s&&(n=!n)}return n}function xt(t){let e=t.length;if(e<3)return null;let n=0,r=0;for(let[g,v]of t)n+=g,r+=v;n/=e,r/=e;let a=0,s=0,c=0,o=0,i=0,l=0,h=0;for(let[g,v]of t){let b=g-n,y=v-r;a+=b*b,s+=b*y,c+=y*y,o+=b*b*b,i+=y*y*y,l+=b*y*y,h+=y*b*b}let u=a*c-s*s;if(Math.abs(u)<1e-12)return null;let f=(o+l)/2,d=(i+h)/2,m=(f*c-d*s)/u,p=(d*a-f*s)/u;return{c:[m+n,p+r],r:Math.sqrt(m*m+p*p+(a+c)/e)}}function M3(t,e=.01){if(t.length<4)return t;let n=0;for(let i=1;i<t.length;i++)Z1(t[0],t[i])>Z1(t[0],t[n])&&(n=i);let r=i=>{if(i.length<3)return i;let l=0,h=0;for(let f=1;f<i.length-1;f++){let d=ve(i[f],i[0],i[i.length-1]);d>l&&(l=d,h=f)}return l<=e?[i[0],i[i.length-1]]:[...r(i.slice(0,h+1)).slice(0,-1),...r(i.slice(h))]},a=r(t.slice(0,n+1)),s=r([...t.slice(n),t[0]]),c=[...a.slice(0,-1),...s.slice(0,-1)],o=[];for(let i=0;i<c.length;i++){let l=c[(i-1+c.length)%c.length],h=c[(i+1)%c.length];ve(c[i],l,h)>e&&o.push(c[i])}return o.length>=3?o:c}function kr(t){let e=[],n=[];for(let s of t.slice(0,300)){let c=M3(s,.002),o=c.length,i=c.findIndex((u,f)=>Z1(u,c[(f+1)%o])>=.5);if(o<4||i<0)continue;let l=z1(s)>0,h=[];for(let u=1;u<=o;u++){let f=(i+u)%o,d=c[f],m=c[(f+1)%o];if(Z1(d,m)<.3){h.length||h.push(d),h.push(m);continue}if(h.length>=3){let p=xt(h),[g,v,b]=[h[0],h[1],h[h.length-1]],y=(v[0]-g[0])*(b[1]-g[1])-(v[1]-g[1])*(b[0]-g[0]);p&&p.r>.005&&p.r<.6&&(y>0===l?e:n).push(p.r)}h=[]}}if(e.length<4)return;e.sort((s,c)=>s-c);let r=e[Math.floor(e.length/2)],a=s=>Math.abs(s-r)<=Math.max(.005,r*.1);if(!(r>.2||n.filter(a).length>e.length*.2))return e.filter(a).length>=e.length*.8?r:void 0}function mn(t,e){let n=t.length,r=o=>Z1(t[o],t[(o+1)%n])<e*1.5,a=t.findIndex((o,i)=>!r(i));if(a<0)return t;let s=[],c=a;do{let o=(c+1)%n;for(;r(o)&&o!==c;)o=(o+1)%n;let i=(o-c-1+n)%n,l=t[c],h=t[(c+1)%n],u=t[o],f=t[(o+1)%n],d;if(i>0){let m=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(m)>1e-12){let p=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/m,g=[l[0]+p*(h[0]-l[0]),l[1]+p*(h[1]-l[1])],v=t[(c+1+Math.floor(i/2))%n],b=[];for(let w=1;w<=i+1;w++)b.push(t[(c+w)%n]);let y=b.length>=3?xt(b):{c:g,r:e};!!y&&Math.abs(y.r-e)<=e*.3&&Z1(g,v)<=e*2&&p>=1-1e-9&&(d=g)}}if(s.push(l),d)s.push(d);else for(let m=1;m<=i;m++)s.push(t[(c+m)%n]);c=o}while(c!==a);return s}function D1(t){for(let r of[0,1,2]){let a=10**r,s=Math.round(t*a)/a;if(Math.abs(t-s)<=.003)return Object.is(s,-0)?0:s}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var O1=t=>String(D1(t)),b0=t=>`[${O1(t[0])}, ${O1(t[1])}]`;function gh(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function N2(t,e,n){let r=[];(D1(t[0])!==0||D1(t[1])!==0)&&r.push(`translate(${b0(t)})`);let a=gh(e);return a!==0&&r.push(`rotate(${a})`),[...r,n].join(" ")}function m5(t,e){return{poly:t,area:Math.abs(z1(t)),box:m0([t]),ends:e?.segs.map(n=>n.a)}}var yt=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function Mt(t,e){let n=D2(t.poly),r=ee(t.poly,!0,Math.min(.5,n/256)),a=xt(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:r);if(!a||a.r<.05)return;let s=Math.min(e*.6,Math.max(e/2,a.r*3e-4));for(let o of t.poly)if(Math.abs(Z1(o,a.c)-a.r)>s)return;let c=s+a.r*2e-4;for(let o of r)if(Math.abs(Z1(o,a.c)-a.r)>c)return;if(!(Math.abs(t.area-Math.PI*a.r*a.r)>n*s*2))return{kind:"circle",body:`circle(d = ${O1(a.r*2)})`,at:a.c,angle:0,center:a.c,circle:a,radius:a.r}}function zr(t){let e=0,n=0;for(let[c,o]of t)e+=c,n+=o;e/=t.length,n/=t.length;let r=0,a=0,s=0;for(let[c,o]of t)r+=(c-e)**2,a+=(o-n)**2,s+=(c-e)*(o-n);return .5*Math.atan2(2*s,r-a)*180/Math.PI}function wt(t,e){let n=D2(t.poly),r=ee(t.poly,!0,Math.min(.5,n/256)),a=zr(r),s=r.map(p=>A2(p,-a)),[c,o,i,l]=m0([s]),h=(i-c)/2,u=(l-o)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(c+i)/2,(o+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[p,g]of s){let v=Math.hypot((p-f[0])/h,(g-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let m=A2(f,a);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${b0([h,u])})`,at:m,angle:a,center:m}}function Sr(t){let e=0,n=0;for(let r=0;r<t.length;r++){let a=t[r],s=t[(r+1)%t.length],c=Z1(a,s);c>e&&(e=c,n=Math.atan2(s[1]-a[1],s[0]-a[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function kt(t,e){let n=M3(t.poly,e/4),r=Sr(n),a=D2(t.poly),s=ee(t.poly,!0,Math.min(.5,a/256)).map(b=>A2(b,-r)),[c,o,i,l]=m0([s]),h=i-c,u=l-o;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[c,o],[i,o],[i,l],[c,l]].map(b=>Math.min(...s.map(y=>Z1(y,b)))*f),m=d.reduce((b,y)=>b+y,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;m<e&&(m=0),m=Math.min(m,h/2,u/2);let p=[(c+i)/2,(o+l)/2];for(let[b,y]of s){let M=Math.abs(b-p[0])-(h/2-m),w=Math.abs(y-p[1])-(u/2-m),x=Math.hypot(Math.max(M,0),Math.max(w,0))+Math.min(Math.max(M,w),0)-m;if(Math.abs(x)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*m*m))>a*e)return;let g=A2(p,r),v=D1(m)>0?`, r = ${O1(m)}`:"";return{kind:"rect",radius:m,body:`rect(${b0([h,u])}, center = true${v})`,at:g,angle:r,center:g,rect:{w:h,h:u,r:m}}}function zt(t,e){let n=M3(t.poly,e/4),r=n.length;if(r<3||r>48)return;let a=0,s=0;for(let[u,f]of n)a+=u/r,s+=f/r;let c=[a,s],o=n.map(u=>Z1(u,c)),i=n.map((u,f)=>Z1(u,n[(f+1)%r])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-s,u[0]-a)*180/Math.PI);if(l(i)<=e&&l(o)<=e&&r<=24){let u=o.reduce((m,p)=>m+p,0)/r,f=360/r,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${r}, ${O1(u)})`,at:c,angle:d,center:c}}if(r%2===0&&r>=4&&l(i)<=e){let u=o.filter((M,w)=>w%2===0),f=o.filter((M,w)=>w%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((M,w)=>M+w,0)/u.length,m=f.reduce((M,w)=>M+w,0)/f.length,p=h[0];if(m>d&&([d,m]=[m,d],p=h[1]),d-m<e)return;let g=r/2,v=360/g,b=((p-90)%v+v)%v;v-b<.01&&(b=0);let y=D1(m)===D1(d*.45);return{kind:"star",body:`star(${g}, ${O1(d)}${y?"":`, ${O1(m)}`})`,at:c,angle:b,center:c}}}function vh(t,e,n){let[r,a,s,c]=e,o=[[],[],[],[]],i=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let m=f[1];Math.abs(m-a)<=n?o[0].push(vt(f[0]-r,d[0]-r)):Math.abs(m-c)<=n?o[2].push(vt(s-f[0],s-d[0])):(i[0].push(m-a),i[2].push(c-m))}else{let m=f[0];Math.abs(m-s)<=n?o[1].push(vt(f[1]-a,d[1]-a)):Math.abs(m-r)<=n?o[3].push(vt(c-f[1],c-d[1])):(i[1].push(s-m),i[3].push(m-r))}}let l=[s-r,c-a,s-r,c-a],h=i.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:o.map(u=>bh(u,n)),depth:h,length:l}}var vt=(t,e)=>t<e?[t,e]:[e,t];function bh(t,e){t.sort((r,a)=>r[0]-a[0]);let n=[];for(let[r,a]of t){let s=n[n.length-1];s&&r<=s[1]+e?s[1]=Math.max(s[1],a):n.push([r,a])}return n}var fn=t=>t.reduce((e,[n,r])=>e+r-n,0);function yh(t,e,n,r,a,s){let c=[yt(0,0,t,e)],o=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],i=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=i[h];for(let f=0;f<r[h];f++){let d=u*(f+.5)/r[h];c.push(yt(d-a[h]/2,-s,d+a[h]/2,0).map(o[h]))}}),t1(c)}function pn(t,e,n){let r=M3(t.poly,e/4);if(r.length<8)return;let a=Sr(r),s=r.map(V=>A2(V,-a)),c=e/2;for(let V=0;V<s.length;V++){let U=s[V],J=s[(V+1)%s.length];if(Math.abs(U[0]-J[0])>c&&Math.abs(U[1]-J[1])>c)return}let o=m0([s]),i=vh(s,o,c),l=(V,U)=>V.map(J=>J.map(n1=>dn(n1,U))),h=(V,U)=>_e([s],l(V,U),e),u=(V,U,J)=>{let n1=A2(V,a);return{kind:"tabs",body:U,at:n1,angle:a,center:A2([(o[0]+o[2])/2,(o[1]+o[3])/2],a),...J}},f=D2(t.poly),d=[0,1,2,3].filter(V=>fn(i.outer[V])<i.length[V]-c);if(!d.length)return;let m=d.map(V=>i.depth[V]).filter(V=>V!==void 0);if(!m.length)return;let p=[...new Set([n,...m].filter(V=>!!V).map(D1))];for(let V of p){let U=D1(o[2]-o[0]),J=D1(o[3]-o[1]),n1=[[]];for(let K=0;K<4;K++){let L1=fn(i.outer[K])>=i.length[K]-2*V-c?["flat"]:["out","in"],A0=[];for(let P of n1)for(let j of L1)A0.push([...P,j]);n1.splice(0,n1.length,...A0)}let m1=Math.max(3*V,6),M1=new Set([m1]);for(let K of d){let k1=i.outer[K].length;for(let L1 of[2*k1-1,2*k1+1,2*k1-3,2*k1+3])L1>=3&&M1.add(D1(i.length[K]/L1))}for(let K of M1)for(let k1 of n1){if(k1.every(s1=>s1==="flat"))continue;let L1=B5(U,J,k1,V,K);if(Math.abs(Math.abs(L1.reduce((s1,w1)=>s1+z1(w1),0))-t.area)>f*e||!h(L1,[o[0],o[1]]))continue;let P=k1.every(s1=>s1===k1[0])?`"${k1[0]}"`:`[${k1.map(s1=>`"${s1}"`).join(", ")}]`,j=K===m1||[0,1].every(s1=>Ee(i.length[s1],K)===Ee(i.length[s1],m1));return u([o[0],o[1]],`finger_rect(${b0([U,J])}, ${P}${j?"":`, finger = ${O1(K)}`})`,{kind:"fingers",thickness:V,edges:k1,finger:j?m1:K})}let c1=[0,1,2,3].map(K=>d.includes(K)&&i.depth[K]!==void 0&&Math.abs(i.depth[K]-V)<=c);if(!c1.some(Boolean))continue;let C1=o[0]+(c1[3]?V:0),h1=o[1]+(c1[0]?V:0),B1=D1(o[2]-(c1[1]?V:0)-C1),$=D1(o[3]-(c1[2]?V:0)-h1),B=[B1,$,B1,$],a1=[c1[3]?V:0,c1[0]?V:0,c1[1]?V:0,c1[2]?V:0],b1=[0,0,0,0],o1=[0,0,0,0],p1=!0;for(let K=0;K<4&&p1;K++){if(!c1[K])continue;let k1=i.outer[K].map(([L1,A0])=>[L1-a1[K],A0-a1[K]]);b1[K]=k1.length,o1[K]=k1.length?D1(k1.reduce((L1,[A0,P])=>L1+P-A0,0)/k1.length):0,k1.forEach(([L1,A0],P)=>{(Math.abs((L1+A0)/2-B[K]*(P+.5)/b1[K])>c||Math.abs(A0-L1-o1[K])>c)&&(p1=!1)})}if(!p1||!h(yh(B1,$,c1,b1,o1,V),[C1,h1]))continue;let K1=c1.every(Boolean)?"":`[${c1.join(", ")}]`,Q1=[0,1,2,3].filter(K=>c1[K]),W1=K=>Math.max(1,Math.round(B[K]/50)),I0=Q1.every(K=>b1[K]===W1(K)),q=Q1.every(K=>b1[K]===b1[Q1[0]]),Z=I0?void 0:q?b1[Q1[0]]:null,e1=Q1.every(K=>Math.abs(o1[K]-B[K]/(2*b1[K]))<=c),Q=Q1.every(K=>Math.abs(o1[K]-o1[Q1[0]])<=c),W=e1?void 0:Q?o1[Q1[0]]:null,$1;if(Z!==null&&W!==null){let K=[b0([B1,$])];K1?K.push(K1):(Z!==void 0||W!==void 0)&&K.push("true"),Z!==void 0&&K.push(`count = ${Z}`),W!==void 0&&K.push(`width = ${O1(W)}`),$1=`tab_rect(${K.join(", ")})`}else{let K=[L1=>L1,L1=>`translate(${b0([B1,0])}) rotate(90) ${L1}`,L1=>`translate(${b0([B1,$])}) rotate(180) ${L1}`,L1=>`translate(${b0([0,$])}) rotate(270) ${L1}`],k1=[`rect(${b0([B1,$])});`];for(let L1 of Q1){let A0=[O1(B[L1])];b1[L1]!==W1(L1)&&A0.push(`count = ${b1[L1]}`),Math.abs(o1[L1]-B[L1]/(2*b1[L1]))>c&&A0.push(`width = ${O1(o1[L1])}`),k1.push(K[L1](`tabs(${A0.join(", ")});`))}$1=`{
4304
+ `).length;throw new Error(`${i} (line ${l})`)};for(;s<t.length;){let i=t.indexOf("<",s),l=i<0?t.length:i;if(l>s&&(a[a.length-1].text+=dr(t.slice(s,l),n)),i<0)break;if(s=i,t.startsWith("<!--",s)){let h=t.indexOf("-->",s+4);h<0&&c("Unclosed comment"),e.push(t.slice(s+4,h)),s=h+3}else if(t.startsWith("<![CDATA[",s)){let h=t.indexOf("]]>",s+9);h<0&&c("Unclosed CDATA section"),a[a.length-1].text+=t.slice(s+9,h),s=h+3}else if(t.startsWith("<?",s)){let h=t.indexOf("?>",s+2);h<0&&c("Unclosed processing instruction"),s=h+2}else if(t.startsWith("<!",s)){let h=0,u=s+2;for(;u<t.length;u++){let d=t[u];if(d==="[")h++;else if(d==="]")h--;else if(d===">"&&h<=0)break}let f=t.slice(s,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];s=u+1}else if(t[s+1]==="/"){let h=t.indexOf(">",s);h<0&&c("Unclosed end tag");let u=t.slice(s+2,h).trim(),f=a.pop();(!f||f===r||f.name!==u)&&c(`</${u}> does not match <${f?.name??"nothing"}>`),s=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(s,s+256));h||c("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};s+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=s;let d=f.exec(t);if(d||c(`Bad attribute in <${u.name}>`),s=f.lastIndex,d[5]){a[a.length-1].children.push(u),d[5]===">"&&a.push(u);break}u.attrs[d[1]]=dr(d[3]??d[4]??"",n)}}}a.length>1&&c(`<${a[a.length-1].name}> is not closed`);let o=r.children[0];if(!o)throw new Error("The file has no elements");return{root:o,comments:e}}var b2={cut:{name:"cut",mode:"cut",color:"#ff0000"},score:{name:"score",mode:"line",color:"#0000ff"},engrave:{name:"engrave",mode:"fill",color:"#000000"},guide:{name:"guide",mode:"guide",color:"#00a0ff"}},fn={black:"#000000",white:"#ffffff",red:"#ff0000",lime:"#00ff00",green:"#008000",blue:"#0000ff",yellow:"#ffff00",cyan:"#00ffff",aqua:"#00ffff",magenta:"#ff00ff",fuchsia:"#ff00ff",gray:"#808080",grey:"#808080",silver:"#c0c0c0",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",teal:"#008080",orange:"#ffa500"},ch=Object.fromEntries(Object.entries(fn).reverse().map(([t,e])=>[e,t]));function d5(t,e){if(t===void 0)return;if(t=t.trim().toLowerCase(),t==="none"||t==="transparent")return"none";if(t==="currentcolor")return e;if(t.startsWith("url("))return"paint";if(fn[t])return fn[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let r=n[1];if(r.length===3||r.length===4)return"#"+[...r.slice(0,3)].map(a=>a+a).join("");if(r.length===6||r.length===8)return"#"+r.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let r=n[1].split(/[\s,/]+/).filter(Boolean);if(r.length>=3){let a=r.slice(0,3).map(s=>{let c=s.endsWith("%")?parseFloat(s)*255/100:parseFloat(s);return Math.max(0,Math.min(255,Math.round(c||0)))});return r[3]!==void 0&&parseFloat(r[3])===0?"none":"#"+a.map(s=>s.toString(16).padStart(2,"0")).join("")}}return"#000000"}var x3=(t,e)=>n3(t,Math.PI/12,e),m5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function oh(t){let e=Qt;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let a=m5(r),s=(a[0]??0)*Math.PI/180,c=Qt;if(n==="matrix"&&a.length===6)c=a;else if(n==="translate")c=[1,0,0,1,a[0]??0,a[1]??0];else if(n==="scale")c=[a[0]??1,0,0,a[1]??a[0]??1,0,0];else if(n==="rotate"){let o=Math.cos(s),i=Math.sin(s),[l,h]=[a[1]??0,a[2]??0];c=[o,i,-i,o,l-o*l+i*h,h-i*l-o*h]}else n==="skewX"?c=[1,0,Math.tan(s),1,0,0]:n==="skewY"&&(c=[1,Math.tan(s),0,1,0,0]);e=Xe(e,c)}return e}function ih(t,e){let n=[],r=[],a=[0,0],s=[0,0],c=(l,h)=>se(e,[l,h]),o=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,i=l=>{r.length&&n.push({segs:r,closed:l}),r=[]};for(let l of t)if(l.type==="M")i(!1),a=s=c(l.x,l.y);else if(l.type==="L"){let h=c(l.x,l.y);o(s,h)||r.push({c:"L",a:s,b:h}),s=h}else if(l.type==="Q"){let h=c(l.x1,l.y1),u=c(l.x,l.y);r.push({c:"C",a:s,p1:[s[0]+2/3*(h[0]-s[0]),s[1]+2/3*(h[1]-s[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),s=u}else if(l.type==="C"){let h=c(l.x,l.y);r.push({c:"C",a:s,p1:c(l.x1,l.y1),p2:c(l.x2,l.y2),b:h}),s=h}else r.length&&!o(s,a)&&r.push({c:"L",a:s,b:a}),i(!0),s=a;return i(!1),n}var lh=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],hh=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function pr(t){let e={};for(let n of t.split(";")){let r=n.indexOf(":");if(r<0)continue;let a=n.slice(0,r).trim().toLowerCase(),s=n.slice(r+1).replace(/!important/i,"").trim();a&&s&&(e[a]=s)}return e}function uh(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let a=pr(r);for(let s of n.split(",")){let c=s.trim(),o=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(c);if(!o)continue;let i=[],l;for(let[,h,u]of o[2].matchAll(/([.#])([\w-]+)/g))h==="."?i.push(u):l=u;e.push({tag:o[1]&&o[1]!=="*"?o[1]:void 0,id:l,classes:i,decls:a})}}return e}function gr(t,e){switch(t){case"mm":return 1;case"cm":return 10;case"in":return 25.4;case"pt":return 25.4/72;case"pc":return 25.4/6;case"q":return .25;default:return 25.4/e}}function un(t,e){if(!t)return;let n=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(t);if(!(!n||n[2]==="%"))return Number(n[1])*gr(n[2].toLowerCase(),e)}var fh=/^(path|g|rect|circle|ellipse|line|polyline|polygon|layer|svg|use|text|tspan|group|shape|cls|clip|mask|defs|_?x?\d|Layer_\d|Ebene|Calque|Capa|Livello|Laag|Warstwa)[-_ ]*[\d-]*$/i;function dh(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!fh.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function mh(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return b2.score;if(/engrav|raster|etch/.test(e))return b2.engrave;if(/\bguide/.test(e))return b2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return b2.cut}function vr(t,e={}){if(t=t.replace(/^\uFEFF/,""),!/^\s*</.test(t)||t.includes("\0"))throw new Error("This is not an SVG file: it does not start with a tag");let n=mr(t),r=n.root;if(r.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let a=[],s=n.comments.some(q=>/Adobe Illustrator/i.test(q)),c=e.dpi??(s?72:96);e.dpi===void 0&&s&&a.push("Adobe Illustrator file: px measured at 72 per inch.");let o=m5(r.attrs.viewBox??""),i=un(r.attrs.width,c),l=un(r.attrs.height,c),h=25.4/c,u=h,f=h,d=0,m=0,g=0,p=0;if(o.length===4&&o[2]>0&&o[3]>0&&(u=i!==void 0?i/o[2]:l!==void 0?l/o[3]:h,f=l!==void 0?l/o[3]:u,d=o[0],m=o[1],i!==void 0&&l!==void 0)){let q=(r.attrs.preserveAspectRatio??"").trim().split(/\s+/).filter(Boolean);q[0]==="defer"&&q.shift();let Z=q[0]??"xMidYMid";if(Z!=="none"){let e1=q[1]==="slice"?Math.max(u,f):Math.min(u,f),Q=(W,$1)=>W.test(Z)?0:$1.test(Z)?1:.5;g=(i-o[2]*e1)*Q(/xMin/,/xMax/),p=(l-o[3]*e1)*Q(/YMin/,/YMax/),u=f=e1}}i===void 0&&l===void 0&&e.dpi===void 0&&!s&&a.push(`The file gives no page size in mm or inches: px measured at ${c} per inch.`);let v=l??(o.length===4?o[3]*f:0),b=Xe([1,0,0,-1,0,v],[u,0,0,f,-d*u+g,-m*f+p]),y=o.length===4?o[2]:(i??0)/h,M=o.length===4?o[3]:(l??0)/h,w=(q,Z)=>{if(q===void 0)return 0;let e1=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(q);if(!e1)return parseFloat(q)||0;let Q=Number(e1[1]),W=e1[2].toLowerCase();return W==="%"?Q/100*(Z==="x"?y:Z==="y"?M:Math.hypot(y,M)/Math.SQRT2):W===""||W==="px"?Q:Q*gr(W,c)/h},x=[],k=new Map,A=q=>{q.name==="style"&&x.push(...uh(q.text)),q.attrs.id&&k.set(q.attrs.id,q),q.children.forEach(A)};A(r);let L=(q,Z)=>{let e1={};for(let W of Object.keys(Z))hh.has(W)&&(e1[W]=Z[W]);for(let W of lh)q.attrs[W]!==void 0&&(e1[W]=q.attrs[W]);let Q=(q.attrs.class??"").split(/\s+/).filter(Boolean);for(let W of x)(!W.tag||W.tag===q.name)&&(!W.id||W.id===q.attrs.id)&&W.classes.every($1=>Q.includes($1))&&Object.assign(e1,W.decls);return q.attrs.style&&Object.assign(e1,pr(q.attrs.style)),e1},z=[],S=[],C=0,E=0,I=0,H=0,T=0,O=0,_=2e4,D=[],G=q=>Number.isFinite(q[0])&&Number.isFinite(q[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],U=q=>[...V,"x1","y1","x2","y2","points"].some(Z=>q.attrs[Z]!==void 0&&m5(q.attrs[Z]).some(e1=>!Number.isFinite(e1))),J=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),n1=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),m1=q=>{let Z=e1=>w(q.attrs[e1],/^(x|cx|rx|x1|x2|width)$/.test(e1)?"x":/^(y|cy|ry|y1|y2|height)$/.test(e1)?"y":"r");switch(q.name){case"path":return x3(q.attrs.d??"",()=>I++);case"rect":{let[e1,Q,W,$1]=[Z("x"),Z("y"),Z("width"),Z("height")];if(W<=0||$1<=0)return[];let K=q.attrs.rx!==void 0?Z("rx"):q.attrs.ry!==void 0?Z("ry"):0,k1=q.attrs.ry!==void 0?Z("ry"):K;return K=Math.min(Math.abs(K),W/2),k1=Math.min(Math.abs(k1),$1/2),K<=0||k1<=0?x3(`M${e1} ${Q}H${e1+W}V${Q+$1}H${e1}Z`):x3(`M${e1+K} ${Q}H${e1+W-K}A${K} ${k1} 0 0 1 ${e1+W} ${Q+k1}V${Q+$1-k1}A${K} ${k1} 0 0 1 ${e1+W-K} ${Q+$1}H${e1+K}A${K} ${k1} 0 0 1 ${e1} ${Q+$1-k1}V${Q+k1}A${K} ${k1} 0 0 1 ${e1+K} ${Q}Z`)}case"circle":case"ellipse":{let[e1,Q]=[Z("cx"),Z("cy")],W=q.name==="circle"?Z("r"):Z("rx"),$1=q.name==="circle"?Z("r"):q.attrs.ry!==void 0?Z("ry"):W;return W<=0||$1<=0?[]:x3(`M${e1+W} ${Q}A${W} ${$1} 0 0 1 ${e1} ${Q+$1}A${W} ${$1} 0 0 1 ${e1-W} ${Q}A${W} ${$1} 0 0 1 ${e1} ${Q-$1}A${W} ${$1} 0 0 1 ${e1+W} ${Q}Z`)}case"line":return x3(`M${Z("x1")} ${Z("y1")}L${Z("x2")} ${Z("y2")}`);case"polyline":case"polygon":{let e1=m5(q.attrs.points??"");if(e1.length<4)return[];let Q=`M${e1[0]} ${e1[1]}`;for(let W=2;W+1<e1.length;W+=2)Q+=`L${e1[W]} ${e1[W+1]}`;return x3(q.name==="polygon"?Q+"Z":Q)}}},M1=q=>(q.text+q.children.map(Z=>Z.name==="tspan"?" "+M1(Z):"").join("")).replace(/\s+/g," ").trim(),c1=(q,Z,e1,Q,W,$1)=>{if($1>64||J.has(q.name)||T&&++O>_)return;let K=L(q,e1);if(K.display==="none"||K.visibility==="hidden"||K.opacity==="0"){(q.children.length||n1.has(q.name))&&E++;return}let k1=Xe(Z,oh(q.attrs.transform));if(!k1.every(Number.isFinite)){H++;return}let L1=dh(q),A0=q.attrs["inkscape:groupmode"]==="layer",P=Q;if(q.name==="g"||q.name==="svg"||q.name==="a"||q.name==="switch"){let N1=q.attrs["inkscape:label"]??q.attrs["data-name"]??q.attrs.id,X1=mh(N1);if(q.attrs["data-mode"]&&N1&&/^(cut|line|fill|guide)$/.test(q.attrs["data-mode"])){let g0=d5(K.stroke,"#000000"),u1=d5(K.fill,"#000000"),E1=q.attrs["data-mode"]==="fill"?u1:g0;P=b2[N1]??{name:N1,mode:q.attrs["data-mode"],color:E1&&E1.startsWith("#")?E1:"#00aa00"}}else X1&&(P=X1);if(q!==r&&q.name==="svg"){let g0=u1=>parseFloat(q.attrs[u1]??"0")||0;k1=Xe(k1,[1,0,0,1,g0("x"),g0("y")])}let h0=A0||X1||q===r||!L1?W:[L1,...W];D.push(q);for(let g0 of q.children)c1(g0,k1,K,P,h0,$1+1);D.pop();return}if(q.name==="use"){let N1=k.get((q.attrs.href??q.attrs["xlink:href"]??"").replace(/^#/,""));if(!N1||D.includes(N1))return;let X1=u1=>parseFloat(q.attrs[u1]??"0")||0,h0=Xe(k1,[1,0,0,1,X1("x"),X1("y")]),g0=N1.name==="symbol"?{...N1,name:"g"}:N1;D.push(N1),T++,c1(g0,h0,K,P,L1?[L1,...W]:W,$1+1),T--,D.pop();return}if(q.name==="image"){C++;return}let j=d5(K.color,"#000000")??"#000000",s1=parseFloat(K["stroke-width"]??"1"),w1=d5(K.stroke,j);w1&&(s1===0||K["stroke-opacity"]==="0")&&(w1="none");let R1=d5(K.fill??"black",j);if(K["fill-opacity"]==="0"&&(R1="none"),q.name==="text"){let N1=M1(q);if(!N1)return;let X1=q.children.find(q1=>q1.name==="tspan"),h0=q1=>m5(q.attrs[q1]??X1?.attrs[q1]??"0")[0]??0,g0=se(k1,[h0("x"),h0("y")]),u1=Math.sqrt(Math.abs(k1[0]*k1[3]-k1[1]*k1[2])),E1=(un(K["font-size"],96)??16*h)/h;if(!G(g0)||!Number.isFinite(E1*u1)){H++;return}let A1=K["text-anchor"];S.push({text:N1,at:g0,size:E1*u1,angle:Math.atan2(-k1[1],k1[0])*180/Math.PI,font:(K["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:A1==="middle"?"center":A1==="end"?"right":"left",stroke:w1,fill:R1,layer:P});return}if(q.name!=="path"&&U(q)){H++;return}let F1=m1(q);if(!F1){for(let N1 of q.children)c1(N1,k1,K,P,W,$1+1);return}let u0=ih(F1,k1),n0=u0.filter(N1=>N1.segs.every(X1=>G(X1.a)&&G(X1.b)&&(X1.c==="L"||G(X1.p1)&&G(X1.p2))));n0.length<u0.length&&H++,n0.length&&z.push({subs:n0,stroke:w1,fill:q.name==="line"||q.name==="polyline"?"none":R1,fillRule:K["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:P,names:L1?[L1,...W]:W})};c1(r,b,{},void 0,[],0),C&&a.push(`${C} embedded image${C===1?" was":"s were"} left out: trace ${C===1?"it":"them"} to paths first.`),E&&a.push(`${E} hidden element${E===1?" was":"s were"} left out.`),I&&a.push(`${I} path${I===1?" has":"s have"} bad data: read up to the error, as browsers draw ${I===1?"it":"them"}.`),H&&a.push(`${H} element${H===1?" was":"s were"} left out: ${H===1?"its":"their"} numbers are too large to draw.`),O>_&&a.push(`The drawing repeats its elements with <use> more than ${_.toLocaleString("en")} times: only the first ${_.toLocaleString("en")} copies were read.`);let C1=q=>{let[Z,e1,Q]=[1,3,5].map(W=>parseInt(q.slice(W,W+2),16));return Z>=200&&e1<=80&&Q<=80},h1=q=>{let[Z,e1,Q]=[1,3,5].map(W=>parseInt(q.slice(W,W+2),16));return Q>=200&&Z<=80&&e1<=80},B1=q=>!!q.stroke&&q.stroke!=="none",$=z.filter(q=>!q.layer),B=new Map;for(let q of $)B1(q)&&q.stroke.startsWith("#")&&B.set(q.stroke,(B.get(q.stroke)??0)+q.subs.length);let a1=[...B.keys()],b1=a1.filter(C1),o1=new Set(b1.length?b1:a1.length?[a1.reduce((q,Z)=>(B.get(Z)??0)>(B.get(q)??0)?Z:q)]:[]),p1=z.some(q=>B1(q)&&!q.layer)||z.some(q=>q.layer),K1=new Map,Q1=(q,Z)=>{if(q&&q!=="none"){let e1=q.startsWith("#")?q:"#000000";if(o1.has(e1))return b2.cut;if(e1==="#00a0ff")return b2.guide;if(h1(e1))return b2.score;if(!K1.has(e1)){let Q=ch[e1]??"color_"+e1.slice(1);K1.set(e1,{name:Q,mode:"line",color:e1})}return K1.get(e1)}if(Z&&Z!=="none")return p1?b2.engrave:b2.cut};!p1&&z.some(q=>q.fill&&q.fill!=="none")?a.push("The file has filled shapes and no strokes: the shapes are cut out."):!b1.length&&o1.size&&a.push(`No red lines: ${[...o1][0]} lines, the most common colour, are cut.`),K1.size&&a.push(`Lines in ${[...K1.values()].map(q=>q.color).join(", ")} went on their own layer${K1.size===1?"":"s"}, set to mark, not cut.`);let W1=[];for(let q of z){let Z=q.layer??Q1(q.stroke,q.fill);if(!Z)continue;let e1=!q.layer&&Z===b2.cut&&!B1(q);W1.push({subs:q.subs,layer:Z,fillRule:q.fillRule,names:q.names,filled:e1})}let I0=[];for(let q of S){let Z=q.layer??Q1(q.fill!=="none"?void 0:q.stroke,q.fill);Z&&I0.push({...q,layer:Z.mode==="cut"&&p1?b2.engrave:Z})}return{items:W1,texts:I0,notes:a}}var Z1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),A2=([t,e],n)=>{let r=n*Math.PI/180,a=Math.cos(r),s=Math.sin(r);return[t*a-e*s,t*s+e*a]},mn=(t,e)=>[t[0]+e[0],t[1]+e[1]],L2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function Fe(t,e=.005){let n=[t.segs[0].a];for(let r of t.segs)if(r.c==="L")n.push(r.b);else{let a=Z1(r.a,r.p1)+Z1(r.p1,r.p2)+Z1(r.p2,r.b),s=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(a/e))));for(let c=1;c<=s;c++){let o=c/s,i=1-o;n.push([i*i*i*r.a[0]+3*i*i*o*r.p1[0]+3*i*o*o*r.p2[0]+o*o*o*r.b[0],i*i*i*r.a[1]+3*i*i*o*r.p1[1]+3*i*o*o*r.p2[1]+o*o*o*r.b[1]])}}return t.closed&&n.length>1&&Z1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function D2(t,e=!0){let n=0;for(let r=1;r<t.length;r++)n+=Z1(t[r-1],t[r]);return e&&t.length>2?n+Z1(t[t.length-1],t[0]):n}function ee(t,e,n){let r=[],a=e?t.length:t.length-1;for(let s=0;s<a;s++){let c=t[s],o=t[(s+1)%t.length];r.push(c);let i=Math.floor(Z1(c,o)/n);for(let l=1;l<i;l++)r.push([c[0]+(o[0]-c[0])*l/i,c[1]+(o[1]-c[1])*l/i])}return!e&&t.length&&r.push(t[t.length-1]),r}function ve(t,e,n){let r=n[0]-e[0],a=n[1]-e[1],s=r*r+a*a,c=s?((t[0]-e[0])*r+(t[1]-e[1])*a)/s:0;return c=Math.max(0,Math.min(1,c)),Math.hypot(t[0]-e[0]-c*r,t[1]-e[1]-c*a)}var Re=class{constructor(e,n,r){this.size=r;this.cells=new Map;for(let a of e){let s=n?a.length:a.length-1;for(let c=0;c<s;c++){let o=a[c],i=a[(c+1)%a.length],l=Math.max(1,Math.ceil(Z1(o,i)/(r*2)));for(let h=0;h<l;h++){let u=[o[0]+(i[0]-o[0])*h/l,o[1]+(i[1]-o[1])*h/l],f=[o[0]+(i[0]-o[0])*(h+1)/l,o[1]+(i[1]-o[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/r),m=Math.floor(Math.max(u[0],f[0])/r),g=Math.floor(Math.min(u[1],f[1])/r),p=Math.floor(Math.max(u[1],f[1])/r);for(let v=d;v<=m;v++)for(let b=g;b<=p;b++){let y=`${v},${b}`,M=this.cells.get(y);M?M.push([u,f]):this.cells.set(y,[[u,f]])}}}}}near(e,n){let r=Math.floor((e[0]-n)/this.size),a=Math.floor((e[0]+n)/this.size),s=Math.floor((e[1]-n)/this.size),c=Math.floor((e[1]+n)/this.size);for(let o=r;o<=a;o++)for(let i=s;i<=c;i++)for(let[l,h]of this.cells.get(`${o},${i}`)??[])if(ve(e,l,h)<=n)return!0;return!1}meets(e,n,r){let a=Math.max(1,Math.ceil(Z1(e,n)/(this.size*2)));for(let s=0;s<a;s++){let c=[e[0]+(n[0]-e[0])*s/a,e[1]+(n[1]-e[1])*s/a],o=[e[0]+(n[0]-e[0])*(s+1)/a,e[1]+(n[1]-e[1])*(s+1)/a],i=Math.floor((Math.min(c[0],o[0])-r)/this.size),l=Math.floor((Math.max(c[0],o[0])+r)/this.size),h=Math.floor((Math.min(c[1],o[1])-r)/this.size),u=Math.floor((Math.max(c[1],o[1])+r)/this.size);for(let f=i;f<=l;f++)for(let d=h;d<=u;d++)for(let[m,g]of this.cells.get(`${f},${d}`)??[])if(yr(c,o,m,g)<=r)return!0}return!1}};function yr(t,e,n,r){let a=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),s=a(n,r,t),c=a(n,r,e),o=a(t,e,n),i=a(t,e,r);return s*c<0&&o*i<0?0:Math.min(ve(t,n,r),ve(e,n,r),ve(n,t,e),ve(r,t,e))}function ph(t,e,n=.2){let r=t.length;if(r<4)return!1;let a=[0];for(let h=1;h<=r;h++)a.push(a[h-1]+Z1(t[h-1],t[h%r]));let s=a[r],c=m0([t]),o=Math.max(c[2]-c[0],c[3]-c[1],e)/Math.max(1,Math.sqrt(r)),i=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/o),m=Math.floor((Math.max(h[0],u[0])+e)/o),g=Math.floor((Math.min(h[1],u[1])-e)/o),p=Math.floor((Math.max(h[1],u[1])+e)/o);if((m-d+1)*(p-g+1)>4096)return null;for(let v=d;v<=m;v++)for(let b=g;b<=p;b++)f.push(`${v},${b}`);return f};for(let h=0;h<r;h++){let u=t[h],f=t[(h+1)%r],d=l(u,f);if(!d)return!1;for(let m of d)for(let g of i.get(m)??[]){let p=Math.abs(a[h]-a[g]);if(!(Math.min(p,s-p)-Z1(u,f)-Z1(t[g],t[(g+1)%r])<n)&&yr(u,f,t[g],t[(g+1)%r])<=e)return!0}for(let m of d){let g=i.get(m);g?g.push(h):i.set(m,[h])}}return!1}function xr(t,e){let n=t.map(()=>!1),r=[],a=t.map(l=>m0([l]));t.forEach((l,h)=>{let u=t1([l]),f=u.reduce((g,p)=>g+z1(p),0),d=D2(l),m=u.reduce((g,p)=>g+D2(p),0);(u.length!==1||Math.abs(f-Math.abs(z1(l)))>d*.001+1e-6||Math.abs(m-d)>d*.001+.05||ph(l,e))&&(n[h]=!0)});let s=new Map,c=l=>{let h=s.get(l);return h||s.set(l,h=new Re([t[l]],!0,Math.max(e*4,1))),h},o=t.map((l,h)=>h).sort((l,h)=>a[l][0]-a[h][0]),i=[];for(let l of o){let[h,u,f,d]=a[l];for(let m=i.length-1;m>=0;m--)a[i[m]][2]<h-e&&i.splice(m,1);for(let m of i){let g=a[m];if(g[1]>d+e||g[3]<u-e)continue;let[p,v]=t[l].length<=t[m].length?[l,m]:[m,l],b=t[p],y=c(v);for(let M=0;M<b.length;M++)if(y.meets(b[M],b[(M+1)%b.length],e)){r.push([l,m]);break}}i.push(l)}return{self:n,pairs:r}}function _e(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let a=Math.max(n*2,.2),s=new Re(t,r,Math.max(n*4,1)),c=new Re(e,r,Math.max(n*4,1));for(let o of t)for(let i of ee(o,r,a))if(!c.near(i,n))return!1;for(let o of e)for(let i of ee(o,r,a))if(!s.near(i,n))return!1;return!0}function Mr(t,e,n){let r=new Re([t,...e],!0,Math.max(n*4,1)),a=s=>Q2(s,t)&&!e.some(c=>Q2(s,c));return(s,c)=>{let o=c?s.length:s.length-1;if(o<1)return!1;let i;for(let l=0;l<o;l++){let h=s[l],u=s[(l+1)%s.length];if(!r.meets(h,u,n)){i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(c||l!==0&&l!==o-1)return!1;let f=Z1(h,u),d=Math.min(n*3,f/3)/f,m=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,g=l===o-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(r.meets(m,g,n))return!1;i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return i?a(i):!0}}function wr(t,e,n){if(!t.length)return!1;let r=new Re([e],!0,Math.max(n*4,1));return t.some(a=>ee(a,!1,Math.max(n*2,.2)).some(s=>r.near(s,n)))}function Q2(t,e){let n=!1;for(let r=0,a=e.length-1;r<e.length;a=r++){let[s,c]=e[r],[o,i]=e[a];c>t[1]!=i>t[1]&&t[0]<(o-s)*(t[1]-c)/(i-c)+s&&(n=!n)}return n}function Mt(t){let e=t.length;if(e<3)return null;let n=0,r=0;for(let[p,v]of t)n+=p,r+=v;n/=e,r/=e;let a=0,s=0,c=0,o=0,i=0,l=0,h=0;for(let[p,v]of t){let b=p-n,y=v-r;a+=b*b,s+=b*y,c+=y*y,o+=b*b*b,i+=y*y*y,l+=b*y*y,h+=y*b*b}let u=a*c-s*s;if(Math.abs(u)<1e-12)return null;let f=(o+l)/2,d=(i+h)/2,m=(f*c-d*s)/u,g=(d*a-f*s)/u;return{c:[m+n,g+r],r:Math.sqrt(m*m+g*g+(a+c)/e)}}function M3(t,e=.01){if(t.length<4)return t;let n=0;for(let i=1;i<t.length;i++)Z1(t[0],t[i])>Z1(t[0],t[n])&&(n=i);let r=i=>{if(i.length<3)return i;let l=0,h=0;for(let f=1;f<i.length-1;f++){let d=ve(i[f],i[0],i[i.length-1]);d>l&&(l=d,h=f)}return l<=e?[i[0],i[i.length-1]]:[...r(i.slice(0,h+1)).slice(0,-1),...r(i.slice(h))]},a=r(t.slice(0,n+1)),s=r([...t.slice(n),t[0]]),c=[...a.slice(0,-1),...s.slice(0,-1)],o=[];for(let i=0;i<c.length;i++){let l=c[(i-1+c.length)%c.length],h=c[(i+1)%c.length];ve(c[i],l,h)>e&&o.push(c[i])}return o.length>=3?o:c}function kr(t){let e=[],n=[];for(let s of t.slice(0,300)){let c=M3(s,.002),o=c.length,i=c.findIndex((u,f)=>Z1(u,c[(f+1)%o])>=.5);if(o<4||i<0)continue;let l=z1(s)>0,h=[];for(let u=1;u<=o;u++){let f=(i+u)%o,d=c[f],m=c[(f+1)%o];if(Z1(d,m)<.3){h.length||h.push(d),h.push(m);continue}if(h.length>=3){let g=Mt(h),[p,v,b]=[h[0],h[1],h[h.length-1]],y=(v[0]-p[0])*(b[1]-p[1])-(v[1]-p[1])*(b[0]-p[0]);g&&g.r>.005&&g.r<.6&&(y>0===l?e:n).push(g.r)}h=[]}}if(e.length<4)return;e.sort((s,c)=>s-c);let r=e[Math.floor(e.length/2)],a=s=>Math.abs(s-r)<=Math.max(.005,r*.1);if(!(r>.2||n.filter(a).length>e.length*.2))return e.filter(a).length>=e.length*.8?r:void 0}function pn(t,e){let n=t.length,r=o=>Z1(t[o],t[(o+1)%n])<e*1.5,a=t.findIndex((o,i)=>!r(i));if(a<0)return t;let s=[],c=a;do{let o=(c+1)%n;for(;r(o)&&o!==c;)o=(o+1)%n;let i=(o-c-1+n)%n,l=t[c],h=t[(c+1)%n],u=t[o],f=t[(o+1)%n],d;if(i>0){let m=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(m)>1e-12){let g=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/m,p=[l[0]+g*(h[0]-l[0]),l[1]+g*(h[1]-l[1])],v=t[(c+1+Math.floor(i/2))%n],b=[];for(let w=1;w<=i+1;w++)b.push(t[(c+w)%n]);let y=b.length>=3?Mt(b):{c:p,r:e};!!y&&Math.abs(y.r-e)<=e*.3&&Z1(p,v)<=e*2&&g>=1-1e-9&&(d=p)}}if(s.push(l),d)s.push(d);else for(let m=1;m<=i;m++)s.push(t[(c+m)%n]);c=o}while(c!==a);return s}function D1(t){for(let r of[0,1,2]){let a=10**r,s=Math.round(t*a)/a;if(Math.abs(t-s)<=.003)return Object.is(s,-0)?0:s}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var O1=t=>String(D1(t)),b0=t=>`[${O1(t[0])}, ${O1(t[1])}]`;function gh(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function N2(t,e,n){let r=[];(D1(t[0])!==0||D1(t[1])!==0)&&r.push(`translate(${b0(t)})`);let a=gh(e);return a!==0&&r.push(`rotate(${a})`),[...r,n].join(" ")}function p5(t,e){return{poly:t,area:Math.abs(z1(t)),box:m0([t]),ends:e?.segs.map(n=>n.a)}}var xt=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function wt(t,e){let n=D2(t.poly),r=ee(t.poly,!0,Math.min(.5,n/256)),a=Mt(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:r);if(!a||a.r<.05)return;let s=Math.min(e*.6,Math.max(e/2,a.r*3e-4));for(let o of t.poly)if(Math.abs(Z1(o,a.c)-a.r)>s)return;let c=s+a.r*2e-4;for(let o of r)if(Math.abs(Z1(o,a.c)-a.r)>c)return;if(!(Math.abs(t.area-Math.PI*a.r*a.r)>n*s*2))return{kind:"circle",body:`circle(d = ${O1(a.r*2)})`,at:a.c,angle:0,center:a.c,circle:a,radius:a.r}}function zr(t){let e=0,n=0;for(let[c,o]of t)e+=c,n+=o;e/=t.length,n/=t.length;let r=0,a=0,s=0;for(let[c,o]of t)r+=(c-e)**2,a+=(o-n)**2,s+=(c-e)*(o-n);return .5*Math.atan2(2*s,r-a)*180/Math.PI}function kt(t,e){let n=D2(t.poly),r=ee(t.poly,!0,Math.min(.5,n/256)),a=zr(r),s=r.map(g=>A2(g,-a)),[c,o,i,l]=m0([s]),h=(i-c)/2,u=(l-o)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(c+i)/2,(o+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[g,p]of s){let v=Math.hypot((g-f[0])/h,(p-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let m=A2(f,a);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${b0([h,u])})`,at:m,angle:a,center:m}}function Sr(t){let e=0,n=0;for(let r=0;r<t.length;r++){let a=t[r],s=t[(r+1)%t.length],c=Z1(a,s);c>e&&(e=c,n=Math.atan2(s[1]-a[1],s[0]-a[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function zt(t,e){let n=M3(t.poly,e/4),r=Sr(n),a=D2(t.poly),s=ee(t.poly,!0,Math.min(.5,a/256)).map(b=>A2(b,-r)),[c,o,i,l]=m0([s]),h=i-c,u=l-o;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[c,o],[i,o],[i,l],[c,l]].map(b=>Math.min(...s.map(y=>Z1(y,b)))*f),m=d.reduce((b,y)=>b+y,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;m<e&&(m=0),m=Math.min(m,h/2,u/2);let g=[(c+i)/2,(o+l)/2];for(let[b,y]of s){let M=Math.abs(b-g[0])-(h/2-m),w=Math.abs(y-g[1])-(u/2-m),x=Math.hypot(Math.max(M,0),Math.max(w,0))+Math.min(Math.max(M,w),0)-m;if(Math.abs(x)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*m*m))>a*e)return;let p=A2(g,r),v=D1(m)>0?`, r = ${O1(m)}`:"";return{kind:"rect",radius:m,body:`rect(${b0([h,u])}, center = true${v})`,at:p,angle:r,center:p,rect:{w:h,h:u,r:m}}}function St(t,e){let n=M3(t.poly,e/4),r=n.length;if(r<3||r>48)return;let a=0,s=0;for(let[u,f]of n)a+=u/r,s+=f/r;let c=[a,s],o=n.map(u=>Z1(u,c)),i=n.map((u,f)=>Z1(u,n[(f+1)%r])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-s,u[0]-a)*180/Math.PI);if(l(i)<=e&&l(o)<=e&&r<=24){let u=o.reduce((m,g)=>m+g,0)/r,f=360/r,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${r}, ${O1(u)})`,at:c,angle:d,center:c}}if(r%2===0&&r>=4&&l(i)<=e){let u=o.filter((M,w)=>w%2===0),f=o.filter((M,w)=>w%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((M,w)=>M+w,0)/u.length,m=f.reduce((M,w)=>M+w,0)/f.length,g=h[0];if(m>d&&([d,m]=[m,d],g=h[1]),d-m<e)return;let p=r/2,v=360/p,b=((g-90)%v+v)%v;v-b<.01&&(b=0);let y=D1(m)===D1(d*.45);return{kind:"star",body:`star(${p}, ${O1(d)}${y?"":`, ${O1(m)}`})`,at:c,angle:b,center:c}}}function vh(t,e,n){let[r,a,s,c]=e,o=[[],[],[],[]],i=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let m=f[1];Math.abs(m-a)<=n?o[0].push(bt(f[0]-r,d[0]-r)):Math.abs(m-c)<=n?o[2].push(bt(s-f[0],s-d[0])):(i[0].push(m-a),i[2].push(c-m))}else{let m=f[0];Math.abs(m-s)<=n?o[1].push(bt(f[1]-a,d[1]-a)):Math.abs(m-r)<=n?o[3].push(bt(c-f[1],c-d[1])):(i[1].push(s-m),i[3].push(m-r))}}let l=[s-r,c-a,s-r,c-a],h=i.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:o.map(u=>bh(u,n)),depth:h,length:l}}var bt=(t,e)=>t<e?[t,e]:[e,t];function bh(t,e){t.sort((r,a)=>r[0]-a[0]);let n=[];for(let[r,a]of t){let s=n[n.length-1];s&&r<=s[1]+e?s[1]=Math.max(s[1],a):n.push([r,a])}return n}var dn=t=>t.reduce((e,[n,r])=>e+r-n,0);function yh(t,e,n,r,a,s){let c=[xt(0,0,t,e)],o=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],i=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=i[h];for(let f=0;f<r[h];f++){let d=u*(f+.5)/r[h];c.push(xt(d-a[h]/2,-s,d+a[h]/2,0).map(o[h]))}}),t1(c)}function gn(t,e,n){let r=M3(t.poly,e/4);if(r.length<8)return;let a=Sr(r),s=r.map(V=>A2(V,-a)),c=e/2;for(let V=0;V<s.length;V++){let U=s[V],J=s[(V+1)%s.length];if(Math.abs(U[0]-J[0])>c&&Math.abs(U[1]-J[1])>c)return}let o=m0([s]),i=vh(s,o,c),l=(V,U)=>V.map(J=>J.map(n1=>mn(n1,U))),h=(V,U)=>_e([s],l(V,U),e),u=(V,U,J)=>{let n1=A2(V,a);return{kind:"tabs",body:U,at:n1,angle:a,center:A2([(o[0]+o[2])/2,(o[1]+o[3])/2],a),...J}},f=D2(t.poly),d=[0,1,2,3].filter(V=>dn(i.outer[V])<i.length[V]-c);if(!d.length)return;let m=d.map(V=>i.depth[V]).filter(V=>V!==void 0);if(!m.length)return;let g=[...new Set([n,...m].filter(V=>!!V).map(D1))];for(let V of g){let U=D1(o[2]-o[0]),J=D1(o[3]-o[1]),n1=[[]];for(let K=0;K<4;K++){let L1=dn(i.outer[K])>=i.length[K]-2*V-c?["flat"]:["out","in"],A0=[];for(let P of n1)for(let j of L1)A0.push([...P,j]);n1.splice(0,n1.length,...A0)}let m1=Math.max(3*V,6),M1=new Set([m1]);for(let K of d){let k1=i.outer[K].length;for(let L1 of[2*k1-1,2*k1+1,2*k1-3,2*k1+3])L1>=3&&M1.add(D1(i.length[K]/L1))}for(let K of M1)for(let k1 of n1){if(k1.every(s1=>s1==="flat"))continue;let L1=j5(U,J,k1,V,K);if(Math.abs(Math.abs(L1.reduce((s1,w1)=>s1+z1(w1),0))-t.area)>f*e||!h(L1,[o[0],o[1]]))continue;let P=k1.every(s1=>s1===k1[0])?`"${k1[0]}"`:`[${k1.map(s1=>`"${s1}"`).join(", ")}]`,j=K===m1||[0,1].every(s1=>Ee(i.length[s1],K)===Ee(i.length[s1],m1));return u([o[0],o[1]],`finger_rect(${b0([U,J])}, ${P}${j?"":`, finger = ${O1(K)}`})`,{kind:"fingers",thickness:V,edges:k1,finger:j?m1:K})}let c1=[0,1,2,3].map(K=>d.includes(K)&&i.depth[K]!==void 0&&Math.abs(i.depth[K]-V)<=c);if(!c1.some(Boolean))continue;let C1=o[0]+(c1[3]?V:0),h1=o[1]+(c1[0]?V:0),B1=D1(o[2]-(c1[1]?V:0)-C1),$=D1(o[3]-(c1[2]?V:0)-h1),B=[B1,$,B1,$],a1=[c1[3]?V:0,c1[0]?V:0,c1[1]?V:0,c1[2]?V:0],b1=[0,0,0,0],o1=[0,0,0,0],p1=!0;for(let K=0;K<4&&p1;K++){if(!c1[K])continue;let k1=i.outer[K].map(([L1,A0])=>[L1-a1[K],A0-a1[K]]);b1[K]=k1.length,o1[K]=k1.length?D1(k1.reduce((L1,[A0,P])=>L1+P-A0,0)/k1.length):0,k1.forEach(([L1,A0],P)=>{(Math.abs((L1+A0)/2-B[K]*(P+.5)/b1[K])>c||Math.abs(A0-L1-o1[K])>c)&&(p1=!1)})}if(!p1||!h(yh(B1,$,c1,b1,o1,V),[C1,h1]))continue;let K1=c1.every(Boolean)?"":`[${c1.join(", ")}]`,Q1=[0,1,2,3].filter(K=>c1[K]),W1=K=>Math.max(1,Math.round(B[K]/50)),I0=Q1.every(K=>b1[K]===W1(K)),q=Q1.every(K=>b1[K]===b1[Q1[0]]),Z=I0?void 0:q?b1[Q1[0]]:null,e1=Q1.every(K=>Math.abs(o1[K]-B[K]/(2*b1[K]))<=c),Q=Q1.every(K=>Math.abs(o1[K]-o1[Q1[0]])<=c),W=e1?void 0:Q?o1[Q1[0]]:null,$1;if(Z!==null&&W!==null){let K=[b0([B1,$])];K1?K.push(K1):(Z!==void 0||W!==void 0)&&K.push("true"),Z!==void 0&&K.push(`count = ${Z}`),W!==void 0&&K.push(`width = ${O1(W)}`),$1=`tab_rect(${K.join(", ")})`}else{let K=[L1=>L1,L1=>`translate(${b0([B1,0])}) rotate(90) ${L1}`,L1=>`translate(${b0([B1,$])}) rotate(180) ${L1}`,L1=>`translate(${b0([0,$])}) rotate(270) ${L1}`],k1=[`rect(${b0([B1,$])});`];for(let L1 of Q1){let A0=[O1(B[L1])];b1[L1]!==W1(L1)&&A0.push(`count = ${b1[L1]}`),Math.abs(o1[L1]-B[L1]/(2*b1[L1]))>c&&A0.push(`width = ${O1(o1[L1])}`),k1.push(K[L1](`tabs(${A0.join(", ")});`))}$1=`{
4302
4305
  ${k1.map(L1=>" "+L1).join(`
4303
4306
  `)}
4304
- }`}return u([C1,h1],$1,{kind:"tabs",thickness:V,library:"tabs",label:`tabs ${O1(V)} mm deep`})}let g=i.depth;if(d.some(V=>g[V]===void 0))return;let v=[0,1,2,3].map(V=>d.includes(V)&&fn(i.outer[V])<i.length[V]*.4),b=o[0]+(v[3]?g[3]:0),y=o[1]+(v[0]?g[0]:0),M=o[2]-(v[1]?g[1]:0)-b,w=o[3]-(v[2]?g[2]:0)-y,x=(V,U,J,n1,m1)=>V===0?[o[0]+U-b,n1,J-U,m1-n1]:V===1?[M-m1,o[1]+U-y,m1-n1,J-U]:V===2?[o[2]-J-b,w-m1,J-U,m1-n1]:[n1,o[3]-J-y,m1-n1,J-U],k=[[],[],[],[]],A=[[],[],[],[]],L=[],z=[[b-o[0],b-o[0]+M],[y-o[1],y-o[1]+w],[o[2]-(b+M),o[2]-b],[o[3]-(y+w),o[3]-y]];for(let V of d)if(v[V])for(let[U,J]of i.outer[V])k[V].push(x(V,U,J,-g[V],0));else{let U=z[V][0];for(let[J,n1]of[...i.outer[V],[z[V][1],z[V][1]]]){let[m1,M1]=[Math.max(U,z[V][0]),Math.min(J,z[V][1])];M1-m1>c&&((m1-z[V][0]<=c||z[V][1]-M1<=c)&&L.push([V,A[V].length]),A[V].push(x(V,m1,M1,-1,g[V]))),U=Math.max(U,n1)}}let S=([V,U,J,n1])=>yt(V,U,V+J,U+n1),C=t1([yt(0,0,M,w),...k.flat().map(S)]),E=()=>h(d0(C,A.flat().map(S)),[b,y]);if(!E())return;for(let[V,U]of L.reverse()){let[J]=A[V].splice(U,1);E()||A[V].splice(U,0,J)}let I=(V,U)=>{let J=U%2===0,n1=$=>J?$[0]:$[1];V.sort(($,B)=>n1($)-n1(B));let m1=V.every($=>Math.abs($[2]-V[0][2])<=c&&Math.abs($[3]-V[0][3])<=c),M1=V.length>1?n1(V[1])-n1(V[0]):0,c1=V.every(($,B)=>Math.abs(n1($)-n1(V[0])-B*M1)<=c),C1=D1(M1),h1=D1(n1(V[0])),B1=D1(h1+C1*(V.length-1));if(V.length>=3&&m1&&c1&&C1>0&&Math.floor((B1-h1)/C1+1e-9)+1===V.length){let[,,$,B]=V[0],a1=J?`[x, ${O1(V[0][1])}]`:`[${O1(V[0][0])}, y]`;return[`for (${J?"x":"y"} = [${O1(h1)}:${O1(C1)}:${O1(B1)}]) translate(${a1}) rect(${b0([$,B])});`]}return V.map(([$,B,a1,b1])=>`translate(${b0([$,B])}) rect(${b0([a1,b1])});`)},H=[0,1,2,3].flatMap(V=>k[V].length?I(k[V],V):[]),T=[0,1,2,3].flatMap(V=>A[V].length?I(A[V],V):[]),O=H.length?`union() {
4307
+ }`}return u([C1,h1],$1,{kind:"tabs",thickness:V,library:"tabs",label:`tabs ${O1(V)} mm deep`})}let p=i.depth;if(d.some(V=>p[V]===void 0))return;let v=[0,1,2,3].map(V=>d.includes(V)&&dn(i.outer[V])<i.length[V]*.4),b=o[0]+(v[3]?p[3]:0),y=o[1]+(v[0]?p[0]:0),M=o[2]-(v[1]?p[1]:0)-b,w=o[3]-(v[2]?p[2]:0)-y,x=(V,U,J,n1,m1)=>V===0?[o[0]+U-b,n1,J-U,m1-n1]:V===1?[M-m1,o[1]+U-y,m1-n1,J-U]:V===2?[o[2]-J-b,w-m1,J-U,m1-n1]:[n1,o[3]-J-y,m1-n1,J-U],k=[[],[],[],[]],A=[[],[],[],[]],L=[],z=[[b-o[0],b-o[0]+M],[y-o[1],y-o[1]+w],[o[2]-(b+M),o[2]-b],[o[3]-(y+w),o[3]-y]];for(let V of d)if(v[V])for(let[U,J]of i.outer[V])k[V].push(x(V,U,J,-p[V],0));else{let U=z[V][0];for(let[J,n1]of[...i.outer[V],[z[V][1],z[V][1]]]){let[m1,M1]=[Math.max(U,z[V][0]),Math.min(J,z[V][1])];M1-m1>c&&((m1-z[V][0]<=c||z[V][1]-M1<=c)&&L.push([V,A[V].length]),A[V].push(x(V,m1,M1,-1,p[V]))),U=Math.max(U,n1)}}let S=([V,U,J,n1])=>xt(V,U,V+J,U+n1),C=t1([xt(0,0,M,w),...k.flat().map(S)]),E=()=>h(d0(C,A.flat().map(S)),[b,y]);if(!E())return;for(let[V,U]of L.reverse()){let[J]=A[V].splice(U,1);E()||A[V].splice(U,0,J)}let I=(V,U)=>{let J=U%2===0,n1=$=>J?$[0]:$[1];V.sort(($,B)=>n1($)-n1(B));let m1=V.every($=>Math.abs($[2]-V[0][2])<=c&&Math.abs($[3]-V[0][3])<=c),M1=V.length>1?n1(V[1])-n1(V[0]):0,c1=V.every(($,B)=>Math.abs(n1($)-n1(V[0])-B*M1)<=c),C1=D1(M1),h1=D1(n1(V[0])),B1=D1(h1+C1*(V.length-1));if(V.length>=3&&m1&&c1&&C1>0&&Math.floor((B1-h1)/C1+1e-9)+1===V.length){let[,,$,B]=V[0],a1=J?`[x, ${O1(V[0][1])}]`:`[${O1(V[0][0])}, y]`;return[`for (${J?"x":"y"} = [${O1(h1)}:${O1(C1)}:${O1(B1)}]) translate(${a1}) rect(${b0([$,B])});`]}return V.map(([$,B,a1,b1])=>`translate(${b0([$,B])}) rect(${b0([a1,b1])});`)},H=[0,1,2,3].flatMap(V=>k[V].length?I(k[V],V):[]),T=[0,1,2,3].flatMap(V=>A[V].length?I(A[V],V):[]),O=H.length?`union() {
4305
4308
  ${[`rect(${b0([M,w])});`,...H].join(`
4306
4309
  `)}
4307
4310
  }`:`rect(${b0([M,w])})`,_=T.length?`difference() {
4308
4311
  ${[O.endsWith("}")?O:O+";",...T].join(`
4309
4312
  `)}
4310
- }`:O,D=d.map(V=>D1(g[V])),G=D.sort((V,U)=>D.filter(J=>J===U).length-D.filter(J=>J===V).length)[0];return u([b,y],_,{kind:T.length?"fingers":"tabs",thickness:G,generic:!0,label:`${T.length?"finger joints":"tabs"} ${O1(G)} mm deep`})}function xh(t){let[e,n,r,a]=m0([t]),s=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,ve(h,t[d],t[f]));return u},c=[(e+r)/2,(n+a)/2],o=Q2(c,t)?s(c):0,i=24;for(let h=0;h<=i;h++)for(let u=0;u<=i;u++){let f=[e+(r-e)*h/i,n+(a-n)*u/i];if(!Q2(f,t))continue;let d=s(f);d>o&&(c=f,o=d)}let l=Math.max(r-e,a-n)/i;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[c[0]+u*l,c[1]+f*l];if(!Q2(d,t))continue;let m=s(d);m>o&&(c=d,o=m,h=!0)}h||(l/=2)}return{c,r:o}}function Mh(t,e,n){let a=Math.atan2(e[1]-t[1],e[0]-t[0]),s=[];for(let c=0;c<=64;c++){let o=a+Math.PI/2+Math.PI*c/64;s.push([t[0]+n*Math.cos(o),t[1]+n*Math.sin(o)])}for(let c=0;c<=64;c++){let o=a-Math.PI/2+Math.PI*c/64;s.push([e[0]+n*Math.cos(o),e[1]+n*Math.sin(o)])}return s}function Ar(t,e){let[n,r,a,s]=t.box;if(Math.max(a-n,s-r)>80)return;let c=D2(t.poly),o=ee(t.poly,!0,Math.min(.25,c/400)),i=xh(t.poly),l=o.filter(T=>Math.abs(Z1(T,i.c)-i.r)<=e),h=xt(l);if(!h||l.length<8)return;let u=o[0];for(let T of o)Z1(T,h.c)>Z1(u,h.c)&&(u=T);let f=Z1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],m=T=>(T[0]-h.c[0])*d[0]+(T[1]-h.c[1])*d[1],p=T=>-(T[0]-h.c[0])*d[1]+(T[1]-h.c[1])*d[0],g=o.filter(T=>m(T)>h.r+e&&m(T)<f-h.r);if(g.length<4)return;let v=[g.filter(T=>p(T)>0),g.filter(T=>p(T)<0)];if(v.some(T=>T.length<2))return;let b=v.map(T=>A2([1,0],zr(T))).map(T=>T[0]*d[0]+T[1]*d[1]<0?[-T[0],-T[1]]:T),y=[b[0][0]+b[1][0],b[0][1]+b[1][1]],M=Math.hypot(y[0],y[1]);if(d=[y[0]/M,y[1]/M],g=o.filter(T=>m(T)>h.r+e&&m(T)<f-h.r),g.length<4||Math.abs(g.reduce((T,O)=>T+p(O),0)/g.length)>e)return;let w=g.map(T=>Math.abs(p(T))).sort((T,O)=>T-O),x=w[Math.floor(w.length/2)]*2;if(x>=h.r*2-e||x<.3)return;let k=Math.max(...o.map(m)),A=dn(h.c,[d[0]*(k-x/2),d[1]*(k-x/2)]),L=t1([Ze(h.r,h.r,256).map(T=>dn(T,h.c)),Mh(h.c,A,x/2)]);if(!_e([t.poly],L,e))return;let z=k-x/2,S=h.r*2,C=Math.atan2(d[1],d[0])*180/Math.PI-90,E=[];D1(S)!==9&&E.push(`head = ${O1(S)}`),D1(x)!==4.5&&E.push(`shank = ${O1(x)}`),D1(z)!==10&&E.push(`drop = ${O1(z)}`);let I=z>=(S+x)/2-1e-9,H=I?`keyhole(${E.join(", ")})`:`{ translate(${b0([0,-z])}) circle(d = ${O1(S)}); hull() { circle(d = ${O1(x)}); translate(${b0([0,-z])}) circle(d = ${O1(x)}); } }`;return{kind:"keyhole",radius:S/2,body:H,at:A,angle:C,center:A,label:"keyhole",keyhole:{head:S,shank:x,drop:z,top:A},library:I?"hanging":void 0}}var br=.0025,bt=(t,e)=>Math.abs(t[0]-e[0])>br||Math.abs(t[1]-e[1])>br;function w3(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(s=>s.a);t.closed||n.push(t.segs[t.segs.length-1].b);let r=[n[0]];for(let s of n.slice(1))bt(s,r[r.length-1])&&r.push(s);!t.closed&&r.length<2&&r.push(n[n.length-1]);let a=`[${r.map(s=>b0(L2(s,e))).join(", ")}]`;return t.closed?`polygon(${a})`:r.length===2?`line(${b0(L2(r[0],e))}, ${b0(L2(r[1],e))})`:`polyline(${a})`}return`path("${gn([t],e)}")`}function gn(t,e){let n=r=>`${O1(r[0]-e[0])} ${O1(r[1]-e[1])}`;return t.map(r=>{let a=`M${n(r.segs[0].a)}`,s=r.segs[0].a;for(let c of r.segs)!bt(c.b,s)&&(c.c==="L"||!bt(c.p1,s)&&!bt(c.p2,s))||(a+=c.c==="L"?`L${n(c.b)}`:`C${n(c.p1)} ${n(c.p2)} ${n(c.b)}`,s=c.b);return r.closed?a+"Z":a}).join("")}var Y0=.01;function Lr(t){return{closed:t.closed,segs:t.segs.slice().reverse().map(e=>e.c==="L"?{c:"L",a:e.b,b:e.a}:{c:"C",a:e.b,p1:e.p2,p2:e.p1,b:e.a})}}var k3=t=>t.segs[0].a,Cr=t=>t.segs[t.segs.length-1].b;function wh(t){let e=new Set,n=[],r=c=>`${Math.round(c[0]/Y0)},${Math.round(c[1]/Y0)}`,a=new Map;t.forEach((c,o)=>{for(let i of[k3(c),Cr(c)]){let l=r(i);a.set(l,[...a.get(l)??[],o])}});let s=c=>{let[o,i]=[Math.round(c[0]/Y0),Math.round(c[1]/Y0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of a.get(`${o+l},${i+h}`)??[])if(!e.has(u)&&(Z1(k3(t[u]),c)<=Y0||Z1(Cr(t[u]),c)<=Y0))return u};for(let c=0;c<t.length;c++){if(e.has(c))continue;e.add(c);let o=t[c].segs.slice();for(let l=0;l<2;l++){for(;;){let h=o[o.length-1].b;if(Z1(h,o[0].a)<=Y0&&o.length>1)break;let u=s(h);if(u===void 0)break;e.add(u);let f=Z1(k3(t[u]),h)<=Y0?t[u]:Lr(t[u]);o=o.concat(f.segs)}o=Lr({segs:o,closed:!1}).segs}let i=o.length>1&&Z1(o[o.length-1].b,o[0].a)<=Y0;n.push({sub:{segs:o,closed:i},from:t[c]})}return n}var Er=.05;function kh(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n=e[0]===255&&e[1]===254||e[0]===60&&e[1]===0?"utf-16le":e[0]===254&&e[1]===255||e[0]===0&&e[1]===60?"utf-16be":"utf-8";return new TextDecoder(n).decode(e)}function Tr(t,e={}){let n=e.tolerance??Er,r=typeof t=="string"?t:kh(t),a=vr(r,{dpi:e.dpi}),s=[...a.notes],c={},o=($,B=1)=>c[$]=(c[$]??0)+B,i=[],l=[],h=new Map;for(let $ of a.items)if($.layer.mode==="cut")for(let B of $.subs)B.closed?i.push({sub:B,names:$.names,group:$.filled?$:void 0}):(l.push(B),h.set(B,$.names));let u=wh(l);l=[];for(let{sub:$,from:B}of u)$.closed?i.push({sub:$,names:h.get(B)??[],line:{segs:$.segs,closed:!1}}):l.push($);let f=i.map($=>({...$,outline:m5(Fe($.sub),$.sub)})),d=f.filter($=>$.outline.poly.length>=3&&$.outline.area>D2($.outline.poly)*Y0);for(let $ of f)d.includes($)||l.push($.line??{segs:$.sub.segs,closed:!1});let m=($,B,a1,b1)=>{if(a1!==b1)return!1;let[o1,p1,K1,Q1]=$.box,[W1,I0,q,Z]=B.box;if(o1<W1-Y0||p1<I0-Y0||K1>q+Y0||Q1>Z+Y0)return!1;let e1=$.poly.length;return[0,Math.floor(e1/3),Math.floor(2*e1/3)].filter(W=>Q2($.poly[W],B.poly)).length>=2},p=$=>{let B=d.map((o1,p1)=>p1).filter(o1=>!$.has(o1)).sort((o1,p1)=>d[p1].outline.area-d[o1].outline.area),a1=new Map,b1=new Map;return B.forEach((o1,p1)=>{let K1=-1;for(let Q1=p1-1;Q1>=0;Q1--){let W1=B[Q1];if(d[W1].outline.area>d[o1].outline.area&&m(d[o1].outline,d[W1].outline,d[o1].group,d[W1].group)){K1=W1;break}}a1.set(o1,K1),b1.set(o1,K1<0?0:b1.get(K1)+1)}),{order:B,parent:a1,depth:b1}},g=xr(d.map($=>$.outline.poly),Y0*2),v=p(new Set),{parent:b,depth:y}=v,M=$=>y.get($)%2===0?$:b.get($),w=new Set(d.map(($,B)=>B).filter($=>g.self[$]));for(let[$,B]of g.pairs)M($)===M(B)&&w.add($).add(B);for(let $ of v.order)y.get($)%2===1&&w.has(b.get($))&&w.add($);for(let $ of w)l.push(d[$].line??{segs:d[$].sub.segs,closed:!1});w.size&&s.push(`${w.size} outline${w.size===1?" touches or crosses":"s touch or cross"} a hole or ${w.size===1?"itself":"themselves"}, so ${w.size===1?"it is":"they are"} kept as cut lines.`);let x=[],k=new Map;for(let $ of v.order){if(w.has($))continue;let B=d[$];if(y.get($)%2===0){let a1={sub:B.sub,outline:B.outline,names:B.names,holes:[],lines:[],marks:new Map,texts:[]};x.push(a1),k.set($,a1)}else k.get(b.get($)).holes.push({sub:B.sub,outline:B.outline,line:B.line})}let A=e.kerf!==void 0?e.kerf/2:kr(x.map($=>$.outline.poly)),L=0;if(A&&A>0){let $=B=>({closed:!0,segs:B.map((a1,b1)=>({c:"L",a:a1,b:B[(b1+1)%B.length]}))});for(let B of x){let a1=d0([mn(B.outline.poly,A)],B.holes.map(Z=>mn(Z.outline.poly,A))),b1=E0(a0(a1,-A,"miter")),o1=a0(b1.flat(),A,"round",Math.min(.01,A/10)),p1=d0([B.outline.poly],B.holes.map(Z=>Z.outline.poly)),K1=Z=>Math.abs(z1(Z))<=D2(Z)*Y0;if(b1.length!==1||b1[0].length!==B.holes.length+1||b1[0].some(K1)||!_e(o1,p1,n)){B.noKerf=!0;continue}B.drawn=[B.sub,...B.holes.map(Z=>Z.sub)];let[Q1,...W1]=b1[0].map(Z=>M3(Z,.001));B.outline=m5(Q1),B.sub=$(Q1);let I0=Z=>[(Z.box[0]+Z.box[2])/2,(Z.box[1]+Z.box[3])/2],q=W1.map(Z=>m5(Z));for(let Z of B.holes){let e1=I0(Z.outline),Q=q.reduce((W,$1)=>Z1(I0($1),e1)<Z1(I0(W),e1)?$1:W);q.splice(q.indexOf(Q),1),Z.outline=Q,Z.sub=$(Q.poly),Z.line=void 0}}L=A*2,e.kerf===void 0&&s.push(`The cut outlines are offset for a ${O1(L)} mm kerf: they are moved back, and $kerf is set.`)}let z=$=>{let B;for(let a1 of x){let[b1,o1,p1,K1]=a1.outline.box;$[0]<b1||$[0]>p1||$[1]<o1||$[1]>K1||Q2($,a1.outline.poly)&&(!B||a1.outline.area<B.outline.area)&&(B=a1)}return B},S={lines:[],marks:new Map,texts:[]},C=new Map,E=$=>{let B=z(k3($));if(!B)return;let a1=C.get(B);return a1||(a1=Mr(B.outline.poly,B.holes.map(b1=>b1.outline.poly),n),C.set(B,a1)),a1(Fe($,.02),$.closed)?B:void 0};for(let $ of l){let B=E($);(B?B.lines:S.lines).push($)}for(let $ of a.items)if($.layer.mode!=="cut")for(let B of $.subs){let a1=(E(B)??S).marks;a1.set($,[...a1.get($)??[],B])}for(let $ of a.texts)(z($.at)??S).texts.push($);a.texts.some($=>$.layer.mode==="cut")&&s.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let $ of x){let B=$.lines.map(a1=>Fe(a1));$.holes=$.holes.filter(a1=>{if(!a1.line)return!0;let b1=p1=>Q2(p1,a1.outline.poly),o1=wr(B,a1.outline.poly,Y0*2)||$.lines.some(p1=>b1(k3(p1)))||[...$.marks.values()].some(p1=>p1.some(K1=>b1(k3(K1))))||$.texts.some(p1=>b1(p1.at))||x.some(p1=>p1!==$&&p1.outline.area<a1.outline.area&&b1(p1.outline.poly[0]));return o1&&$.lines.push(a1.line),!o1})}let I=$=>Mt($,n)??kt($,n)??wt($,n)??zt($,n)??Ar($,n),H=new Map;for(let $ of x){let B=Mt($.outline,n)??kt($.outline,n)??wt($.outline,n)??zt($.outline,n)??pn($.outline,n);H.set($,B);for(let a1 of $.holes)a1.found=I(a1.outline)}let T=new Map,O=[...H.values()].some($=>$?.thickness&&!$.generic);for(let $ of H.values())$?.thickness&&$.thickness<=10&&(!O||!$.generic)&&T.set($.thickness,(T.get($.thickness)??0)+1);let _=[...T.entries()].sort(($,B)=>B[1]-$[1])[0]?.[0];if(_!==void 0)for(let $ of x){let B=H.get($);if(B?.thickness!==void 0&&B.thickness!==_){let a1=pn($.outline,n,_);a1&&a1.thickness===_&&H.set($,a1)}}let D=new Set;for(let $ of H.values())$?.kind==="fingers"&&$.finger&&D.add(D1($.finger));x.sort(($,B)=>{let a1=B.outline.box[3]-$.outline.box[3];return Math.abs(a1)>1?a1:$.outline.box[0]-B.outline.box[0]});let G=new Set,V=new Map,U=[];for(let[$,B]of x.entries()){let a1=B.names[0]??`part ${$+1}`,b1=(V.get(a1)??0)+1;V.set(a1,b1);let o1=b1>1?`${a1} ${b1}`:a1,p1;for(let Q of[2,1,0]){let W=Sh(B,H.get(B),Q,_,D,n);if(Ch(W,B,n)){p1=W,Q<2&&s.push(Q===1?`Part "${o1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${o1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!p1){let Q=B.drawn??[B.sub,...B.holes.map(W=>W.sub)];S.lines.push(...Q.map(W=>({segs:W.segs,closed:!1})),...B.lines);for(let[W,$1]of B.marks)S.marks.set(W,[...S.marks.get(W)??[],...$1]);S.texts.push(...B.texts),s.push(`Part "${o1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let Q of p1.found)o(Q);for(let Q of p1.libraries)G.add(Q);let K1=Pr(B.marks,[],B.texts,p1.origin),Q1=[...p1.cut,...K1],W1=p1.thickness,I0=[...W1!==void 0&&(_===void 0||D1(W1)!==D1(_))?[`thickness = ${O1(W1)}`]:[],...B.noKerf&&L>0?["kerf = 0"]:[]],q=I0.length?`material(${I0.join(", ")}) `:"",Z=`part("${o1.replace(/["\\]/g,"")}")`,e1=Q1.length===1&&!Q1[0].includes(`
4313
+ }`:O,D=d.map(V=>D1(p[V])),G=D.sort((V,U)=>D.filter(J=>J===U).length-D.filter(J=>J===V).length)[0];return u([b,y],_,{kind:T.length?"fingers":"tabs",thickness:G,generic:!0,label:`${T.length?"finger joints":"tabs"} ${O1(G)} mm deep`})}function xh(t){let[e,n,r,a]=m0([t]),s=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,ve(h,t[d],t[f]));return u},c=[(e+r)/2,(n+a)/2],o=Q2(c,t)?s(c):0,i=24;for(let h=0;h<=i;h++)for(let u=0;u<=i;u++){let f=[e+(r-e)*h/i,n+(a-n)*u/i];if(!Q2(f,t))continue;let d=s(f);d>o&&(c=f,o=d)}let l=Math.max(r-e,a-n)/i;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[c[0]+u*l,c[1]+f*l];if(!Q2(d,t))continue;let m=s(d);m>o&&(c=d,o=m,h=!0)}h||(l/=2)}return{c,r:o}}function Mh(t,e,n){let a=Math.atan2(e[1]-t[1],e[0]-t[0]),s=[];for(let c=0;c<=64;c++){let o=a+Math.PI/2+Math.PI*c/64;s.push([t[0]+n*Math.cos(o),t[1]+n*Math.sin(o)])}for(let c=0;c<=64;c++){let o=a-Math.PI/2+Math.PI*c/64;s.push([e[0]+n*Math.cos(o),e[1]+n*Math.sin(o)])}return s}function Ar(t,e){let[n,r,a,s]=t.box;if(Math.max(a-n,s-r)>80)return;let c=D2(t.poly),o=ee(t.poly,!0,Math.min(.25,c/400)),i=xh(t.poly),l=o.filter(T=>Math.abs(Z1(T,i.c)-i.r)<=e),h=Mt(l);if(!h||l.length<8)return;let u=o[0];for(let T of o)Z1(T,h.c)>Z1(u,h.c)&&(u=T);let f=Z1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],m=T=>(T[0]-h.c[0])*d[0]+(T[1]-h.c[1])*d[1],g=T=>-(T[0]-h.c[0])*d[1]+(T[1]-h.c[1])*d[0],p=o.filter(T=>m(T)>h.r+e&&m(T)<f-h.r);if(p.length<4)return;let v=[p.filter(T=>g(T)>0),p.filter(T=>g(T)<0)];if(v.some(T=>T.length<2))return;let b=v.map(T=>A2([1,0],zr(T))).map(T=>T[0]*d[0]+T[1]*d[1]<0?[-T[0],-T[1]]:T),y=[b[0][0]+b[1][0],b[0][1]+b[1][1]],M=Math.hypot(y[0],y[1]);if(d=[y[0]/M,y[1]/M],p=o.filter(T=>m(T)>h.r+e&&m(T)<f-h.r),p.length<4||Math.abs(p.reduce((T,O)=>T+g(O),0)/p.length)>e)return;let w=p.map(T=>Math.abs(g(T))).sort((T,O)=>T-O),x=w[Math.floor(w.length/2)]*2;if(x>=h.r*2-e||x<.3)return;let k=Math.max(...o.map(m)),A=mn(h.c,[d[0]*(k-x/2),d[1]*(k-x/2)]),L=t1([Ze(h.r,h.r,256).map(T=>mn(T,h.c)),Mh(h.c,A,x/2)]);if(!_e([t.poly],L,e))return;let z=k-x/2,S=h.r*2,C=Math.atan2(d[1],d[0])*180/Math.PI-90,E=[];D1(S)!==9&&E.push(`head = ${O1(S)}`),D1(x)!==4.5&&E.push(`shank = ${O1(x)}`),D1(z)!==10&&E.push(`drop = ${O1(z)}`);let I=z>=(S+x)/2-1e-9,H=I?`keyhole(${E.join(", ")})`:`{ translate(${b0([0,-z])}) circle(d = ${O1(S)}); hull() { circle(d = ${O1(x)}); translate(${b0([0,-z])}) circle(d = ${O1(x)}); } }`;return{kind:"keyhole",radius:S/2,body:H,at:A,angle:C,center:A,label:"keyhole",keyhole:{head:S,shank:x,drop:z,top:A},library:I?"hanging":void 0}}var br=.0025,yt=(t,e)=>Math.abs(t[0]-e[0])>br||Math.abs(t[1]-e[1])>br;function w3(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(s=>s.a);t.closed||n.push(t.segs[t.segs.length-1].b);let r=[n[0]];for(let s of n.slice(1))yt(s,r[r.length-1])&&r.push(s);!t.closed&&r.length<2&&r.push(n[n.length-1]);let a=`[${r.map(s=>b0(L2(s,e))).join(", ")}]`;return t.closed?`polygon(${a})`:r.length===2?`line(${b0(L2(r[0],e))}, ${b0(L2(r[1],e))})`:`polyline(${a})`}return`path("${vn([t],e)}")`}function vn(t,e){let n=r=>`${O1(r[0]-e[0])} ${O1(r[1]-e[1])}`;return t.map(r=>{let a=`M${n(r.segs[0].a)}`,s=r.segs[0].a;for(let c of r.segs)!yt(c.b,s)&&(c.c==="L"||!yt(c.p1,s)&&!yt(c.p2,s))||(a+=c.c==="L"?`L${n(c.b)}`:`C${n(c.p1)} ${n(c.p2)} ${n(c.b)}`,s=c.b);return r.closed?a+"Z":a}).join("")}var Y0=.01;function Lr(t){return{closed:t.closed,segs:t.segs.slice().reverse().map(e=>e.c==="L"?{c:"L",a:e.b,b:e.a}:{c:"C",a:e.b,p1:e.p2,p2:e.p1,b:e.a})}}var k3=t=>t.segs[0].a,Cr=t=>t.segs[t.segs.length-1].b;function wh(t){let e=new Set,n=[],r=c=>`${Math.round(c[0]/Y0)},${Math.round(c[1]/Y0)}`,a=new Map;t.forEach((c,o)=>{for(let i of[k3(c),Cr(c)]){let l=r(i);a.set(l,[...a.get(l)??[],o])}});let s=c=>{let[o,i]=[Math.round(c[0]/Y0),Math.round(c[1]/Y0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of a.get(`${o+l},${i+h}`)??[])if(!e.has(u)&&(Z1(k3(t[u]),c)<=Y0||Z1(Cr(t[u]),c)<=Y0))return u};for(let c=0;c<t.length;c++){if(e.has(c))continue;e.add(c);let o=t[c].segs.slice();for(let l=0;l<2;l++){for(;;){let h=o[o.length-1].b;if(Z1(h,o[0].a)<=Y0&&o.length>1)break;let u=s(h);if(u===void 0)break;e.add(u);let f=Z1(k3(t[u]),h)<=Y0?t[u]:Lr(t[u]);o=o.concat(f.segs)}o=Lr({segs:o,closed:!1}).segs}let i=o.length>1&&Z1(o[o.length-1].b,o[0].a)<=Y0;n.push({sub:{segs:o,closed:i},from:t[c]})}return n}var Er=.05;function kh(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n=e[0]===255&&e[1]===254||e[0]===60&&e[1]===0?"utf-16le":e[0]===254&&e[1]===255||e[0]===0&&e[1]===60?"utf-16be":"utf-8";return new TextDecoder(n).decode(e)}function Tr(t,e={}){let n=e.tolerance??Er,r=typeof t=="string"?t:kh(t),a=vr(r,{dpi:e.dpi}),s=[...a.notes],c={},o=($,B=1)=>c[$]=(c[$]??0)+B,i=[],l=[],h=new Map;for(let $ of a.items)if($.layer.mode==="cut")for(let B of $.subs)B.closed?i.push({sub:B,names:$.names,group:$.filled?$:void 0}):(l.push(B),h.set(B,$.names));let u=wh(l);l=[];for(let{sub:$,from:B}of u)$.closed?i.push({sub:$,names:h.get(B)??[],line:{segs:$.segs,closed:!1}}):l.push($);let f=i.map($=>({...$,outline:p5(Fe($.sub),$.sub)})),d=f.filter($=>$.outline.poly.length>=3&&$.outline.area>D2($.outline.poly)*Y0);for(let $ of f)d.includes($)||l.push($.line??{segs:$.sub.segs,closed:!1});let m=($,B,a1,b1)=>{if(a1!==b1)return!1;let[o1,p1,K1,Q1]=$.box,[W1,I0,q,Z]=B.box;if(o1<W1-Y0||p1<I0-Y0||K1>q+Y0||Q1>Z+Y0)return!1;let e1=$.poly.length;return[0,Math.floor(e1/3),Math.floor(2*e1/3)].filter(W=>Q2($.poly[W],B.poly)).length>=2},g=$=>{let B=d.map((o1,p1)=>p1).filter(o1=>!$.has(o1)).sort((o1,p1)=>d[p1].outline.area-d[o1].outline.area),a1=new Map,b1=new Map;return B.forEach((o1,p1)=>{let K1=-1;for(let Q1=p1-1;Q1>=0;Q1--){let W1=B[Q1];if(d[W1].outline.area>d[o1].outline.area&&m(d[o1].outline,d[W1].outline,d[o1].group,d[W1].group)){K1=W1;break}}a1.set(o1,K1),b1.set(o1,K1<0?0:b1.get(K1)+1)}),{order:B,parent:a1,depth:b1}},p=xr(d.map($=>$.outline.poly),Y0*2),v=g(new Set),{parent:b,depth:y}=v,M=$=>y.get($)%2===0?$:b.get($),w=new Set(d.map(($,B)=>B).filter($=>p.self[$]));for(let[$,B]of p.pairs)M($)===M(B)&&w.add($).add(B);for(let $ of v.order)y.get($)%2===1&&w.has(b.get($))&&w.add($);for(let $ of w)l.push(d[$].line??{segs:d[$].sub.segs,closed:!1});w.size&&s.push(`${w.size} outline${w.size===1?" touches or crosses":"s touch or cross"} a hole or ${w.size===1?"itself":"themselves"}, so ${w.size===1?"it is":"they are"} kept as cut lines.`);let x=[],k=new Map;for(let $ of v.order){if(w.has($))continue;let B=d[$];if(y.get($)%2===0){let a1={sub:B.sub,outline:B.outline,names:B.names,holes:[],lines:[],marks:new Map,texts:[]};x.push(a1),k.set($,a1)}else k.get(b.get($)).holes.push({sub:B.sub,outline:B.outline,line:B.line})}let A=e.kerf!==void 0?e.kerf/2:kr(x.map($=>$.outline.poly)),L=0;if(A&&A>0){let $=B=>({closed:!0,segs:B.map((a1,b1)=>({c:"L",a:a1,b:B[(b1+1)%B.length]}))});for(let B of x){let a1=d0([pn(B.outline.poly,A)],B.holes.map(Z=>pn(Z.outline.poly,A))),b1=E0(a0(a1,-A,"miter")),o1=a0(b1.flat(),A,"round",Math.min(.01,A/10)),p1=d0([B.outline.poly],B.holes.map(Z=>Z.outline.poly)),K1=Z=>Math.abs(z1(Z))<=D2(Z)*Y0;if(b1.length!==1||b1[0].length!==B.holes.length+1||b1[0].some(K1)||!_e(o1,p1,n)){B.noKerf=!0;continue}B.drawn=[B.sub,...B.holes.map(Z=>Z.sub)];let[Q1,...W1]=b1[0].map(Z=>M3(Z,.001));B.outline=p5(Q1),B.sub=$(Q1);let I0=Z=>[(Z.box[0]+Z.box[2])/2,(Z.box[1]+Z.box[3])/2],q=W1.map(Z=>p5(Z));for(let Z of B.holes){let e1=I0(Z.outline),Q=q.reduce((W,$1)=>Z1(I0($1),e1)<Z1(I0(W),e1)?$1:W);q.splice(q.indexOf(Q),1),Z.outline=Q,Z.sub=$(Q.poly),Z.line=void 0}}L=A*2,e.kerf===void 0&&s.push(`The cut outlines are offset for a ${O1(L)} mm kerf: they are moved back, and $kerf is set.`)}let z=$=>{let B;for(let a1 of x){let[b1,o1,p1,K1]=a1.outline.box;$[0]<b1||$[0]>p1||$[1]<o1||$[1]>K1||Q2($,a1.outline.poly)&&(!B||a1.outline.area<B.outline.area)&&(B=a1)}return B},S={lines:[],marks:new Map,texts:[]},C=new Map,E=$=>{let B=z(k3($));if(!B)return;let a1=C.get(B);return a1||(a1=Mr(B.outline.poly,B.holes.map(b1=>b1.outline.poly),n),C.set(B,a1)),a1(Fe($,.02),$.closed)?B:void 0};for(let $ of l){let B=E($);(B?B.lines:S.lines).push($)}for(let $ of a.items)if($.layer.mode!=="cut")for(let B of $.subs){let a1=(E(B)??S).marks;a1.set($,[...a1.get($)??[],B])}for(let $ of a.texts)(z($.at)??S).texts.push($);a.texts.some($=>$.layer.mode==="cut")&&s.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let $ of x){let B=$.lines.map(a1=>Fe(a1));$.holes=$.holes.filter(a1=>{if(!a1.line)return!0;let b1=p1=>Q2(p1,a1.outline.poly),o1=wr(B,a1.outline.poly,Y0*2)||$.lines.some(p1=>b1(k3(p1)))||[...$.marks.values()].some(p1=>p1.some(K1=>b1(k3(K1))))||$.texts.some(p1=>b1(p1.at))||x.some(p1=>p1!==$&&p1.outline.area<a1.outline.area&&b1(p1.outline.poly[0]));return o1&&$.lines.push(a1.line),!o1})}let I=$=>wt($,n)??zt($,n)??kt($,n)??St($,n)??Ar($,n),H=new Map;for(let $ of x){let B=wt($.outline,n)??zt($.outline,n)??kt($.outline,n)??St($.outline,n)??gn($.outline,n);H.set($,B);for(let a1 of $.holes)a1.found=I(a1.outline)}let T=new Map,O=[...H.values()].some($=>$?.thickness&&!$.generic);for(let $ of H.values())$?.thickness&&$.thickness<=10&&(!O||!$.generic)&&T.set($.thickness,(T.get($.thickness)??0)+1);let _=[...T.entries()].sort(($,B)=>B[1]-$[1])[0]?.[0];if(_!==void 0)for(let $ of x){let B=H.get($);if(B?.thickness!==void 0&&B.thickness!==_){let a1=gn($.outline,n,_);a1&&a1.thickness===_&&H.set($,a1)}}let D=new Set;for(let $ of H.values())$?.kind==="fingers"&&$.finger&&D.add(D1($.finger));x.sort(($,B)=>{let a1=B.outline.box[3]-$.outline.box[3];return Math.abs(a1)>1?a1:$.outline.box[0]-B.outline.box[0]});let G=new Set,V=new Map,U=[];for(let[$,B]of x.entries()){let a1=B.names[0]??`part ${$+1}`,b1=(V.get(a1)??0)+1;V.set(a1,b1);let o1=b1>1?`${a1} ${b1}`:a1,p1;for(let Q of[2,1,0]){let W=Sh(B,H.get(B),Q,_,D,n);if(Ch(W,B,n)){p1=W,Q<2&&s.push(Q===1?`Part "${o1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${o1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!p1){let Q=B.drawn??[B.sub,...B.holes.map(W=>W.sub)];S.lines.push(...Q.map(W=>({segs:W.segs,closed:!1})),...B.lines);for(let[W,$1]of B.marks)S.marks.set(W,[...S.marks.get(W)??[],...$1]);S.texts.push(...B.texts),s.push(`Part "${o1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let Q of p1.found)o(Q);for(let Q of p1.libraries)G.add(Q);let K1=Pr(B.marks,[],B.texts,p1.origin),Q1=[...p1.cut,...K1],W1=p1.thickness,I0=[...W1!==void 0&&(_===void 0||D1(W1)!==D1(_))?[`thickness = ${O1(W1)}`]:[],...B.noKerf&&L>0?["kerf = 0"]:[]],q=I0.length?`material(${I0.join(", ")}) `:"",Z=`part("${o1.replace(/["\\]/g,"")}")`,e1=Q1.length===1&&!Q1[0].includes(`
4311
4314
  `)?`${q}${Z} ${Q1[0]}`:`${q}${Z} {
4312
4315
  ${Q1.join(`
4313
4316
  `)}
@@ -4321,28 +4324,30 @@ ${Q1.join(`
4321
4324
  `).replace(/\n{3,}/g,`
4322
4325
 
4323
4326
  `)+`
4324
- `;try{B1=pt(B1)}catch{}return{source:B1,parts:U.length,found:c,summary:M1,notes:s}}var zh={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},p5=t=>t.trimEnd().endsWith("}")?t:t+";";function Sh(t,e,n,r,a,s){let c=[],o=new Set,i=n>0?e:void 0,l=t.outline.box,h,u;if(i?.kind==="rect"){let{w:z,h:S,r:C}=i.rect;h=L2(i.center,A2([z/2,S/2],i.angle)),h=[D1(h[0]),D1(h[1])],u=N2([0,0],i.angle,`rect(${b0([z,S])}${D1(C)>0?`, r = ${O1(C)}`:""})`),c.push("rectangle")}else i?(h=[D1(i.at[0]),D1(i.at[1])],u=N2(L2(i.at,h),i.angle,i.body),c.push(vn[i.kind]),i.library&&o.add(i.library)):(h=[D1(l[0]),D1(l[1])],u=w3(t.sub,h),c.push("outline"));let f=t.holes.map(z=>({...z,found:n>0?z.found:void 0})),d=[],m=z=>L2(z,h),p=z=>z,g=0,v=new Set(f);if(n===2&&!i)for(let z of f){let S=z.found?.circle;if(!S||S.r*2>15)continue;let C=ee(t.outline.poly,!0,.25),E=Math.min(...C.map(O=>Z1(O,S.c))),I=E-S.r;if(I<.5||C.filter(O=>Math.abs(Z1(O,S.c)-E)<=s).length*.25<E*Math.PI*.8)continue;let T=[b0(m(S.c))];D1(S.r*2)!==4&&T.push(`d = ${O1(S.r*2)}`),D1(I)!==3&&T.push(`wall = ${O1(I)}`),p=O=>`hanging_loop(${T.join(", ")}) ${O}`,g=E,o.add("hanging"),c.push("hanging loop"),v.delete(z);break}if(n===2){let[z,S,C,E]=l,I=(z+C)/2,H=C-z,T=E-S,O=U=>U[1]>=S+T*.66,_=U=>[...v].filter(J=>J.found?.circle&&D1(J.found.circle.r)===D1(U.found.circle.r)).length,D=[...v].filter(U=>U.found?.circle&&U.found.circle.r*2>=1.5&&U.found.circle.r*2<=15&&O(U.found.circle.c)&&_(U)<=2),G=!1;for(let U of D){let J=U.found.circle;if(Math.abs(J.c[0]-I)>Math.max(.5,H*.02))continue;let n1=J.r*2;d.push(`hanging_hole(${b0(m(J.c))}${D1(n1)!==5?`, d = ${O1(n1)}`:""})`),v.delete(U),G=!0;break}if(!G)for(let U of D)for(let J of D){if(G||U===J)continue;let[n1,m1]=[U.found.circle,J.found.circle];if(Math.abs(n1.r-m1.r)>s||Math.abs(n1.c[1]-m1.c[1])>s||n1.c[0]>=m1.c[0])continue;let M1=[(n1.c[0]+m1.c[0])/2,n1.c[1]];if(Math.abs(M1[0]-I)>Math.max(1,H*.02))continue;let c1=n1.r*2;d.push(`hanging_hole(${b0(m(M1))}${D1(c1)!==5?`, d = ${O1(c1)}`:""}, spacing = ${O1(m1.c[0]-n1.c[0])})`),v.delete(U),v.delete(J),G=!0}G&&(o.add("hanging"),c.push("hanger hole"));let V=[...v].filter(U=>U.found?.kind==="keyhole"&&U.found.library&&Math.abs(U.found.angle)<.01);for(let U of V)for(let J of V){if(!v.has(U)||!v.has(J)||U===J)continue;let[n1,m1]=[U.found,J.found];if(n1.body!==m1.body||Math.abs(n1.at[1]-m1.at[1])>s||n1.at[0]>=m1.at[0])continue;let M1=[O1(m1.at[0]-n1.at[0])],c1=m([(n1.at[0]+m1.at[0])/2,n1.at[1]]),C1=n1.body.slice(8,-1);M1.push(D1(c1[0])||D1(c1[1])?`at = ${b0(c1)}`:""),C1&&M1.push(C1),d.push(`keyholes(${M1.filter(Boolean).join(", ")})`),v.delete(U),v.delete(J),o.add("hanging"),c.push("keyhole","keyhole")}if(r!==void 0){let U=[...v].filter(J=>J.found?.kind==="rect"&&D1(J.found.rect.r)===0);for(let J of Ah(U,s)){let{items:n1,dir:m1,spacing:M1,along:c1,across:C1}=J,h1=n1.length,B1=r,$=C1-B1,B=L2(n1[0].found.center,[m1[0]*M1/2,m1[1]*M1/2]),a1=Math.atan2(m1[1],m1[0])*180/Math.PI,b1=h1*M1;if(Math.abs($)<=s&&Math.abs(c1-M1/2)<=s&&h1>=2){let o1=2*h1-1,p1=o1*c1,K1=Math.max(3*B1,6),Q1=(q,Z)=>{let e1=Math.round(q/Z);return e1%2===0&&(e1+=q/Z>e1?1:-1),Math.max(3,e1)};if(Q1(p1,K1)!==o1&&Q1(p1,c1)!==o1)continue;let W1=L2(n1[0].found.center,[m1[0]*c1/2,m1[1]*c1/2]),I0=Q1(p1,K1)===o1?"":`, finger = ${O1(c1)}`;d.push(N2(m(W1),a1,`finger_holes(${O1(p1)}${I0})`)),c.push("finger joint slot row")}else if($>=-s&&$<=1){let o1=[O1(b1)];h1!==Math.max(1,Math.round(b1/50))&&o1.push(`count = ${h1}`);let p1=c1-$;Math.abs(p1-b1/(2*h1))>s&&o1.push(`width = ${O1(p1)}`),Math.abs($-.1)>.001&&o1.push(`clearance = ${O1($)}`),d.push(N2(m(B),a1,`slots(${o1.join(", ")})`)),o.add("tabs"),c.push("slot row")}else continue;for(let o1 of n1)v.delete(o1)}}}let b=[...v].filter(z=>z.found),y=[...v].filter(z=>!z.found);if(n===2){let z=new Map;for(let S of b){let C=N2([0,0],S.found.angle,S.found.body);z.set(C,[...z.get(C)??[],S])}for(let[S,C]of z){let E=Lh(C.map(I=>m(I.found.at)),s);if(E){d.push(`${E} ${S}`);for(let I of C)c.push(vn[I.found.kind]),I.found.library&&o.add(I.found.library);c.push("hole pattern");for(let I of C)v.delete(I)}}}for(let z of v)z.found&&(d.push(N2(m(z.found.at),z.found.angle,z.found.body)),c.push(vn[z.found.kind]),z.found.library&&o.add(z.found.library));for(let z of y)d.push(w3(z.sub,h)),c.push("outline");let M=p(u),w=d.length?[`difference() {
4325
- ${[M,...d].map(p5).join(`
4327
+ `;try{B1=gt(B1)}catch{}return{source:B1,parts:U.length,found:c,summary:M1,notes:s}}var zh={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},g5=t=>t.trimEnd().endsWith("}")?t:t+";";function Sh(t,e,n,r,a,s){let c=[],o=new Set,i=n>0?e:void 0,l=t.outline.box,h,u;if(i?.kind==="rect"){let{w:z,h:S,r:C}=i.rect;h=L2(i.center,A2([z/2,S/2],i.angle)),h=[D1(h[0]),D1(h[1])],u=N2([0,0],i.angle,`rect(${b0([z,S])}${D1(C)>0?`, r = ${O1(C)}`:""})`),c.push("rectangle")}else i?(h=[D1(i.at[0]),D1(i.at[1])],u=N2(L2(i.at,h),i.angle,i.body),c.push(bn[i.kind]),i.library&&o.add(i.library)):(h=[D1(l[0]),D1(l[1])],u=w3(t.sub,h),c.push("outline"));let f=t.holes.map(z=>({...z,found:n>0?z.found:void 0})),d=[],m=z=>L2(z,h),g=z=>z,p=0,v=new Set(f);if(n===2&&!i)for(let z of f){let S=z.found?.circle;if(!S||S.r*2>15)continue;let C=ee(t.outline.poly,!0,.25),E=Math.min(...C.map(O=>Z1(O,S.c))),I=E-S.r;if(I<.5||C.filter(O=>Math.abs(Z1(O,S.c)-E)<=s).length*.25<E*Math.PI*.8)continue;let T=[b0(m(S.c))];D1(S.r*2)!==4&&T.push(`d = ${O1(S.r*2)}`),D1(I)!==3&&T.push(`wall = ${O1(I)}`),g=O=>`hanging_loop(${T.join(", ")}) ${O}`,p=E,o.add("hanging"),c.push("hanging loop"),v.delete(z);break}if(n===2){let[z,S,C,E]=l,I=(z+C)/2,H=C-z,T=E-S,O=U=>U[1]>=S+T*.66,_=U=>[...v].filter(J=>J.found?.circle&&D1(J.found.circle.r)===D1(U.found.circle.r)).length,D=[...v].filter(U=>U.found?.circle&&U.found.circle.r*2>=1.5&&U.found.circle.r*2<=15&&O(U.found.circle.c)&&_(U)<=2),G=!1;for(let U of D){let J=U.found.circle;if(Math.abs(J.c[0]-I)>Math.max(.5,H*.02))continue;let n1=J.r*2;d.push(`hanging_hole(${b0(m(J.c))}${D1(n1)!==5?`, d = ${O1(n1)}`:""})`),v.delete(U),G=!0;break}if(!G)for(let U of D)for(let J of D){if(G||U===J)continue;let[n1,m1]=[U.found.circle,J.found.circle];if(Math.abs(n1.r-m1.r)>s||Math.abs(n1.c[1]-m1.c[1])>s||n1.c[0]>=m1.c[0])continue;let M1=[(n1.c[0]+m1.c[0])/2,n1.c[1]];if(Math.abs(M1[0]-I)>Math.max(1,H*.02))continue;let c1=n1.r*2;d.push(`hanging_hole(${b0(m(M1))}${D1(c1)!==5?`, d = ${O1(c1)}`:""}, spacing = ${O1(m1.c[0]-n1.c[0])})`),v.delete(U),v.delete(J),G=!0}G&&(o.add("hanging"),c.push("hanger hole"));let V=[...v].filter(U=>U.found?.kind==="keyhole"&&U.found.library&&Math.abs(U.found.angle)<.01);for(let U of V)for(let J of V){if(!v.has(U)||!v.has(J)||U===J)continue;let[n1,m1]=[U.found,J.found];if(n1.body!==m1.body||Math.abs(n1.at[1]-m1.at[1])>s||n1.at[0]>=m1.at[0])continue;let M1=[O1(m1.at[0]-n1.at[0])],c1=m([(n1.at[0]+m1.at[0])/2,n1.at[1]]),C1=n1.body.slice(8,-1);M1.push(D1(c1[0])||D1(c1[1])?`at = ${b0(c1)}`:""),C1&&M1.push(C1),d.push(`keyholes(${M1.filter(Boolean).join(", ")})`),v.delete(U),v.delete(J),o.add("hanging"),c.push("keyhole","keyhole")}if(r!==void 0){let U=[...v].filter(J=>J.found?.kind==="rect"&&D1(J.found.rect.r)===0);for(let J of Ah(U,s)){let{items:n1,dir:m1,spacing:M1,along:c1,across:C1}=J,h1=n1.length,B1=r,$=C1-B1,B=L2(n1[0].found.center,[m1[0]*M1/2,m1[1]*M1/2]),a1=Math.atan2(m1[1],m1[0])*180/Math.PI,b1=h1*M1;if(Math.abs($)<=s&&Math.abs(c1-M1/2)<=s&&h1>=2){let o1=2*h1-1,p1=o1*c1,K1=Math.max(3*B1,6),Q1=(q,Z)=>{let e1=Math.round(q/Z);return e1%2===0&&(e1+=q/Z>e1?1:-1),Math.max(3,e1)};if(Q1(p1,K1)!==o1&&Q1(p1,c1)!==o1)continue;let W1=L2(n1[0].found.center,[m1[0]*c1/2,m1[1]*c1/2]),I0=Q1(p1,K1)===o1?"":`, finger = ${O1(c1)}`;d.push(N2(m(W1),a1,`finger_holes(${O1(p1)}${I0})`)),c.push("finger joint slot row")}else if($>=-s&&$<=1){let o1=[O1(b1)];h1!==Math.max(1,Math.round(b1/50))&&o1.push(`count = ${h1}`);let p1=c1-$;Math.abs(p1-b1/(2*h1))>s&&o1.push(`width = ${O1(p1)}`),Math.abs($-.1)>.001&&o1.push(`clearance = ${O1($)}`),d.push(N2(m(B),a1,`slots(${o1.join(", ")})`)),o.add("tabs"),c.push("slot row")}else continue;for(let o1 of n1)v.delete(o1)}}}let b=[...v].filter(z=>z.found),y=[...v].filter(z=>!z.found);if(n===2){let z=new Map;for(let S of b){let C=N2([0,0],S.found.angle,S.found.body);z.set(C,[...z.get(C)??[],S])}for(let[S,C]of z){let E=Lh(C.map(I=>m(I.found.at)),s);if(E){d.push(`${E} ${S}`);for(let I of C)c.push(bn[I.found.kind]),I.found.library&&o.add(I.found.library);c.push("hole pattern");for(let I of C)v.delete(I)}}}for(let z of v)z.found&&(d.push(N2(m(z.found.at),z.found.angle,z.found.body)),c.push(bn[z.found.kind]),z.found.library&&o.add(z.found.library));for(let z of y)d.push(w3(z.sub,h)),c.push("outline");let M=g(u),w=d.length?[`difference() {
4328
+ ${[M,...d].map(g5).join(`
4326
4329
  `)}
4327
- }`]:[p5(M)],x=t.lines.map(z=>p5(w3(z,h))),k=e?.thickness??r,A=[...[...o].map(z=>`use <kerf/${z}>`),`$thickness = ${k??3};`,`translate(${b0(h)}) {
4330
+ }`]:[g5(M)],x=t.lines.map(z=>g5(w3(z,h))),k=e?.thickness??r,A=[...[...o].map(z=>`use <kerf/${z}>`),`$thickness = ${k??3};`,`translate(${b0(h)}) {
4328
4331
  ${[...w,...x].join(`
4329
4332
  `)}
4330
4333
  }`].join(`
4331
- `),L=Math.max(0,g,i?.radius??0,...f.map(z=>n>0?z.found?.radius??0:0));return{origin:h,round:L,cut:[...w,...x],check:A,found:c,libraries:o,thickness:i?.thickness}}var vn={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function Ah(t,e){let n=[],r=new Set,a=c=>{let o=c.found.rect;return`${Math.round((c.found.angle%180+180)%180)}|${D1(o.w)}|${D1(o.h)}`},s=new Map;for(let c of t)s.set(a(c),[...s.get(a(c))??[],c]);for(let c of s.values()){if(c.length<2)continue;let{w:o,h:i}=c[0].found.rect,l=c[0].found.angle;for(let[h,u,f]of[[l,o,i],[l+90,i,o]]){let d=A2([1,0],h),m=[-d[1],d[0]],p=c.filter(v=>!r.has(v)),g=new Map;for(let v of p){let b=v.found.center,y=Math.round((b[0]*m[0]+b[1]*m[1])/e),M=[...g.keys()].find(w=>Math.abs(w-y)<=1)??y;g.set(M,[...g.get(M)??[],v])}for(let v of g.values()){let b=M=>M.found.center[0]*d[0]+M.found.center[1]*d[1];v.sort((M,w)=>b(M)-b(w));let y=0;for(;y<v.length-1;){let M=b(v[y+1])-b(v[y]),w=y+1;for(;w+1<v.length&&Math.abs(b(v[w+1])-b(v[w])-M)<=e;)w++;if(w>y&&M>u){let x=v.slice(y,w+1);for(let k of x)r.add(k);n.push({items:x,dir:d,spacing:M,along:u,across:f})}y=w}}}}return n}function Lh(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let p of[...h].sort((g,v)=>g-v))(!u.length||p-u[u.length-1]>e*2)&&u.push(p);if(u.length===1)return;let[f,d]=[D1(u[0]),D1((u[u.length-1]-u[0])/(u.length-1))],m=D1(f+d*(u.length-1));if(!(d<=0||Math.floor((m-f)/d+1e-9)+1!==u.length)&&!u.some((p,g)=>Math.abs(p-(f+g*d))>e))return`[${O1(f)}:${O1(d)}:${O1(m)}]`},r=t.map(h=>h[0]),a=t.map(h=>h[1]),s=h=>new Set(h.map(u=>Math.round(u/(e*2)))).size,c=s(r),o=s(a);if(o===1||c===1){let h=o===1?r:a;if(s(h)!==t.length)return;let u=n(h);return u?o===1?`for (x = ${u}) translate([x, ${O1(a[0])}])`:`for (y = ${u}) translate([${O1(r[0])}, y])`:void 0}if(c*o!==t.length)return;let i=n(r),l=n(a);if(!(!i||!l))return`for (x = ${i}, y = ${l}) translate([x, y])`}function Pr(t,e,n,r){let a=[];for(let o of e)a.push(p5(w3(o,r)));let s=new Map,c=(o,i,l)=>{let h=o.name,u=s.get(h)??{layer:o,code:[]};u.code.push(p5(i)+(l?` // ${l}`:"")),s.set(h,u)};for(let[o,i]of t){let l=Er;if(i.length===1&&i[0].closed){let d=m5(Fe(i[0]),i[0]),m=d.area>1e-6?Mt(d,l)??kt(d,l)??wt(d,l)??zt(d,l):void 0;if(m){c(o.layer,N2(L2(m.at,r),m.angle,m.body));continue}}if(o.layer.mode!=="fill"||i.every(d=>!d.closed)){for(let d of i)c(o.layer,w3(d,r));continue}let h=gn(i,r),u=i.filter(d=>d.closed).map(d=>Fe(d)),f=o.fillRule==="evenodd"||_e(t1(u,"nonzero"),t1(u,"evenodd"),.01);c(o.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let o of n){let i=[JSON.stringify(o.text),`size = ${O1(o.size)}`];o.anchor!=="left"&&i.push(`halign = "${o.anchor}"`),c(o.layer,N2(L2(o.at,r),o.angle,`text(${i.join(", ")})`),o.font?`${o.font} in the drawing`:void 0)}for(let{layer:o,code:i}of s.values()){let l=["cut","score","engrave","guide"].includes(o.name)?`${o.name}()`:`layer("${o.name}", mode = "${o.mode}", color = "${o.color}")`;a.push(i.length===1&&!i[0].includes("//")?`${l} ${i[0]}`:`${l} {
4334
+ `),L=Math.max(0,p,i?.radius??0,...f.map(z=>n>0?z.found?.radius??0:0));return{origin:h,round:L,cut:[...w,...x],check:A,found:c,libraries:o,thickness:i?.thickness}}var bn={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function Ah(t,e){let n=[],r=new Set,a=c=>{let o=c.found.rect;return`${Math.round((c.found.angle%180+180)%180)}|${D1(o.w)}|${D1(o.h)}`},s=new Map;for(let c of t)s.set(a(c),[...s.get(a(c))??[],c]);for(let c of s.values()){if(c.length<2)continue;let{w:o,h:i}=c[0].found.rect,l=c[0].found.angle;for(let[h,u,f]of[[l,o,i],[l+90,i,o]]){let d=A2([1,0],h),m=[-d[1],d[0]],g=c.filter(v=>!r.has(v)),p=new Map;for(let v of g){let b=v.found.center,y=Math.round((b[0]*m[0]+b[1]*m[1])/e),M=[...p.keys()].find(w=>Math.abs(w-y)<=1)??y;p.set(M,[...p.get(M)??[],v])}for(let v of p.values()){let b=M=>M.found.center[0]*d[0]+M.found.center[1]*d[1];v.sort((M,w)=>b(M)-b(w));let y=0;for(;y<v.length-1;){let M=b(v[y+1])-b(v[y]),w=y+1;for(;w+1<v.length&&Math.abs(b(v[w+1])-b(v[w])-M)<=e;)w++;if(w>y&&M>u){let x=v.slice(y,w+1);for(let k of x)r.add(k);n.push({items:x,dir:d,spacing:M,along:u,across:f})}y=w}}}}return n}function Lh(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let g of[...h].sort((p,v)=>p-v))(!u.length||g-u[u.length-1]>e*2)&&u.push(g);if(u.length===1)return;let[f,d]=[D1(u[0]),D1((u[u.length-1]-u[0])/(u.length-1))],m=D1(f+d*(u.length-1));if(!(d<=0||Math.floor((m-f)/d+1e-9)+1!==u.length)&&!u.some((g,p)=>Math.abs(g-(f+p*d))>e))return`[${O1(f)}:${O1(d)}:${O1(m)}]`},r=t.map(h=>h[0]),a=t.map(h=>h[1]),s=h=>new Set(h.map(u=>Math.round(u/(e*2)))).size,c=s(r),o=s(a);if(o===1||c===1){let h=o===1?r:a;if(s(h)!==t.length)return;let u=n(h);return u?o===1?`for (x = ${u}) translate([x, ${O1(a[0])}])`:`for (y = ${u}) translate([${O1(r[0])}, y])`:void 0}if(c*o!==t.length)return;let i=n(r),l=n(a);if(!(!i||!l))return`for (x = ${i}, y = ${l}) translate([x, y])`}function Pr(t,e,n,r){let a=[];for(let o of e)a.push(g5(w3(o,r)));let s=new Map,c=(o,i,l)=>{let h=o.name,u=s.get(h)??{layer:o,code:[]};u.code.push(g5(i)+(l?` // ${l}`:"")),s.set(h,u)};for(let[o,i]of t){let l=Er;if(i.length===1&&i[0].closed){let d=p5(Fe(i[0]),i[0]),m=d.area>1e-6?wt(d,l)??zt(d,l)??kt(d,l)??St(d,l):void 0;if(m){c(o.layer,N2(L2(m.at,r),m.angle,m.body));continue}}if(o.layer.mode!=="fill"||i.every(d=>!d.closed)){for(let d of i)c(o.layer,w3(d,r));continue}let h=vn(i,r),u=i.filter(d=>d.closed).map(d=>Fe(d)),f=o.fillRule==="evenodd"||_e(t1(u,"nonzero"),t1(u,"evenodd"),.01);c(o.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let o of n){let i=[JSON.stringify(o.text),`size = ${O1(o.size)}`];o.anchor!=="left"&&i.push(`halign = "${o.anchor}"`),c(o.layer,N2(L2(o.at,r),o.angle,`text(${i.join(", ")})`),o.font?`${o.font} in the drawing`:void 0)}for(let{layer:o,code:i}of s.values()){let l=["cut","score","engrave","guide"].includes(o.name)?`${o.name}()`:`layer("${o.name}", mode = "${o.mode}", color = "${o.color}")`;a.push(i.length===1&&!i[0].includes("//")?`${l} ${i[0]}`:`${l} {
4332
4335
  ${i.join(`
4333
4336
  `)}
4334
- }`)}return a}function Ch(t,e,n){let r;try{r=new K2({maxSteps:2e6}).run(n2(t.check).program).shape}catch{return!1}let a=r.layers.get("cut");if(!a)return!1;let s=d0([e.outline.poly],e.holes.map(l=>l.outline.poly)),c=t1(a.regions),o=n+t.round*16e-5;if(!_e(s,c,o))return!1;let i=e.lines.map(l=>Fe(l));return!(i.length&&!_e(i,a.lines,o,!1))}var Y=.001,o0=(t,e)=>t.reduce((n,r,a)=>n+r*e[a],0),S1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],V1=t=>Math.hypot(...t),$r=t=>[t[2],t[6],t[10]],z0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]+t[n*4+3]),bn=(t,e)=>T1(L0(t.matrix),e.matrix);function qe(t){let[e,n]=t[0],r=0;for(let a=1;a<t.length-1;a++)r+=(t[a][0]-e)*(t[a+1][1]-n)-(t[a][1]-n)*(t[a+1][0]-e);return r/2}var be=t=>Math.abs(t.reduce((e,n)=>e+qe(n),0)),yn=t=>t.reduce((e,n)=>e+n.reduce((r,a,s)=>r+Math.hypot(a[0]-n[(s+1)%n.length][0],a[1]-n[(s+1)%n.length][1]),0),0);function St(t){let e=t.flat();return[Math.min(...e.map(n=>n[0])),Math.min(...e.map(n=>n[1])),Math.max(...e.map(n=>n[0])),Math.max(...e.map(n=>n[1]))]}var Hr=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function xn(t){if(t.length!==1)return!1;let e=St(t);return be(ze(t,[Hr(e)]))<Y*Y}var Mn=(t,e)=>G1(t,[Hr(e)]);function Or(t,e,n=0){let r=e[0]*e[5]-e[1]*e[4]<0;return t.map(a=>{let s=a.map(([c,o])=>z0(e,[c,o,n]).slice(0,2));return r?s.reverse():s})}function Ph(t,e){let n=!1;for(let r=0,a=t.length-1;r<t.length;a=r++){let[s,c]=t[r],[o,i]=t[a];c>e[1]!=i>e[1]&&e[0]<(o-s)*(e[1]-c)/(i-c)+s&&(n=!n)}return n}function z3(t,e,n){let r=n[0]-e[0],a=n[1]-e[1],s=r*r+a*a,c=s?Math.max(0,Math.min(1,((t[0]-e[0])*r+(t[1]-e[1])*a)/s)):0;return Math.hypot(t[0]-e[0]-c*r,t[1]-e[1]-c*a)}function Rr(t,e){let n=1/0;for(let r of t)for(let a=0;a<e.length;a++)n=Math.min(n,z3(r,e[a],e[(a+1)%e.length]));for(let r of e)for(let a=0;a<t.length;a++)n=Math.min(n,z3(r,t[a],t[(a+1)%t.length]));return n}var wn=(t,e)=>t.filter(n=>qe(n)<0&&Ph(n,e));function S3(t){return t.placed?t.bends.length?"Flexible or bent geometry is not supported by this rigid check.":t.folds?.length?"Folded geometry is not supported by this rigid check.":t.cutLines===null?"Nominal cutting-line geometry is unavailable; render with analysis: true.":t.cutLines.length?"Open cutting lines may remove or weaken material; this rigid check cannot model them.":null:"The part has no physical placement."}function Fr(t){return[0,1,2,4,5,6,8,9,10].every(e=>Math.abs(t[e])<1e-9||Math.abs(Math.abs(t[e])-1)<1e-9)}function At(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&Ir(t.regions)===Ir(e.regions)&&Vr(t.cutLines)===Vr(e.cutLines)}function Ir(t){let e=n=>{let r=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,a=[r,[...r].reverse()].map(s=>{let c=0;for(let o=1;o<s.length;o++)(s[o][0]<s[c][0]||s[o][0]===s[c][0]&&s[o][1]<s[c][1])&&(c=o);return JSON.stringify([...s.slice(c),...s.slice(0,c)])});return JSON.stringify([Math.sign(qe(n)),a.sort()[0]])};return JSON.stringify(t.map(e).sort())}function Vr(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),r=JSON.stringify([...e].reverse());return n<r?n:r}).sort())}var Y1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),$0=t=>typeof t=="string"&&t.length>0,P2=t=>typeof t=="number"&&Number.isFinite(t),ne=t=>P2(t)&&t>=0,U2=t=>P2(t)&&t>0,De=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(P2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,re=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(P2),C2=t=>re(t,3)&&t.every(e=>Math.abs(e)<=1e7),ye=t=>Y1(t)&&$0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),Lt=t=>Y1(t)&&$0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),A3=t=>ye(t)||Lt(t),te=t=>Array.isArray(t)&&t.every(A3),Ne=t=>C2(t)&&Math.hypot(...t)>1e-9,Eh=t=>Y1(t)&&(t.kind==="translate"&&C2(t.by)||t.kind==="rotate"&&C2(t.origin)&&Ne(t.axis)&&P2(t.angle)&&Math.abs(t.angle)<=1e6),kn=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),_r=t=>Y1(t)&&Object.values(t).every(kn),Dr=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||P2(t)||Array.isArray(t)&&t.every(n=>Dr(n,e+1))),zn=t=>Y1(t)&&Object.values(t).every(e=>Dr(e)),Th=t=>t===null||Y1(t)&&kn(t.sourceHash)&&kn(t.engineHash)&&_r(t.dependencies)&&_r(t.fonts);function g5(t){let e=[],n=(c,o)=>e.push({code:"invalid-spec",path:c,message:o});if(!Y1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let r=(c,o,i)=>{for(let l of Object.keys(c))o.includes(l)||n(i?`${i}.${l}`:l,"Unknown specification field.")};r(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),$0(t.model)||n("model","Give the model a nonempty name.");let a=new Set,s=(c,o)=>{if(!Y1(c)){n(o,"Materials must map material names to measured profiles.");return}for(let[i,l]of Object.entries(c))(!i||!Y1(l)||!De(l.thickness,Number.MIN_VALUE)||!De(l.kerf)||l.edgeError!==void 0&&!ne(l.edgeError)||l.lot!==void 0&&!$0(l.lot))&&n(`${o}.${i}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),Y1(l)&&r(l,["thickness","kerf","edgeError","lot"],`${o}.${i}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[c,o]of t.configurations.entries())!Y1(o)||!$0(o.id)||o.params!==void 0&&!zn(o.params)?n(`configurations[${c}]`,"Expected a unique id and finite KerfScript parameter values."):a.has(o.id)?n(`configurations[${c}].id`,"Configuration ids must be unique."):(a.add(o.id),r(o,["id","params","materials"],`configurations[${c}]`),o.materials!==void 0&&s(o.materials,`configurations[${c}].materials`));if(t.materials!==void 0&&s(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let c=new Set,o=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!Y1(h)||!$0(h.id)||!$0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(r(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),c.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),c.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&o++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(m=>typeof m=="string"&&a.has(m)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!ye(h.a)||!ye(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!U2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!ye(h.tab)||!ye(h.receiver)||!re(h.region,4)||h.region.some(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!De(h.clearance)||!ne(h.flushTolerance)||!ne(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let m=h.stops;if(!Lt(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(ye)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(ye)||!De(h.clearance)||!De(h.endplay)||!U2(h.minimumOverlap)||!ne(h.maximumStopGap)||!Array.isArray(m)||m.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let p of m){if(!Y1(p)||!Lt(p.body)||!Y1(p.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}r(p,["body","attachment"],u+".stops");let g=p.attachment;r(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!Lt(g.thread)||!U2(g.minimumEngagement)||typeof g.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!ne(h.minimumGap)||h.bodies!==void 0&&(!te(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!$0(h.from)||!a.has(h.from)||!$0(h.to)||!a.has(h.to)||h.from===h.to||!ne(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(m=>Y1(m)&&A3(m.body)&&Eh(m.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!$0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!te(h.initial)||h.initial.length>1||h.scope!==void 0&&(!te(h.scope)||!h.scope.length)||!ne(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(m=>Y1(m)&&$0(m.id)&&A3(m.part)&&C2(m.from)&&typeof m.held=="boolean"&&(m.fasten===void 0||Array.isArray(m.fasten)&&m.fasten.every($0))&&(m.tool===void 0||Y1(m.tool)&&C2(m.tool.from)&&C2(m.tool.to)&&U2(m.tool.diameter)&&m.tool.diameter<=1e6&&C2(m.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!te(h.roots)||!h.roots.length||h.removable!==void 0&&!te(h.removable)||!Array.isArray(h.links)||!h.links.every(m=>Y1(m)&&$0(m.claim)&&["glued","locked","captured"].includes(m.fastening)&&typeof m.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!te(h.bodies)||!h.bodies.length||!te(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(m=>Y1(m)&&A3(m.a)&&A3(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&C2(m.anchorA)&&C2(m.anchorB)&&Ne(m.axisA)&&Ne(m.axisB)&&(m.range===void 0||De(m.range,-1e6))||m.kind==="prismatic"&&Ne(m.axisA)&&De(m.travel,-1e6)||m.kind==="gear"&&Ne(m.axisA)&&Ne(m.axisB)&&U2(m.ratio)&&m.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!te(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!P2(h.ground)||Math.abs(h.ground)>1e7||!Ne(h.gravity)||h.gravity[2]>=0||!ne(h.minimumMargin)||!h.loads.every(m=>Y1(m)&&A3(m.body)&&U2(m.mass)&&(m.center===void 0||C2(m.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!$0(h.plan)||!$0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(m=>Y1(m)&&$0(m.step)&&te(m.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(m,p,g)=>{Y1(m)&&r(m,p,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[m,p]of h.moving.entries())Y1(p)&&(d(p,["body","trajectory"],`${u}.moving[${m}]`),d(p.trajectory,Y1(p.trajectory)&&p.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${m}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[m,p]of h.steps.entries())Y1(p)&&(d(p,["id","part","from","held","fasten","tool"],`${u}.steps[${m}]`),d(p.tool,["from","to","diameter","travel"],`${u}.steps[${m}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[m,p]of h.joints.entries())Y1(p)&&d(p,["kind","a","b",...p.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:p.kind==="prismatic"?["axisA","travel"]:p.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${m}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((m,p)=>d(m,["claim","fastening","installed"],`${u}.links[${p}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((m,p)=>d(m,["body","mass","center"],`${u}.loads[${p}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((m,p)=>d(m,["step","bodies"],`${u}.holds[${p}]`))}o||n("claims","At least one claim must be required.");let i=t.claims.filter(Y1);for(let l of i){let h=(u,f)=>i.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=i.find(p=>p.id===l.plan&&p.kind==="assembly-access"),f=i.find(p=>p.id===l.retention&&p.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(Y1).map(p=>p.id)),m=new Set((Array.isArray(f?.links)?f.links:[]).filter(Y1).map(p=>p.claim));if(Array.isArray(l.holds))for(let p of l.holds)Y1(p)&&!d.has(p.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(p.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let p of u.steps)if(Y1(p)&&Array.isArray(p.fasten))for(let g of p.fasten)m.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(p.id)} fastens ${String(g)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(Y1(f)){let d=Y1(f.body)?f.body:{},m=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(m)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(m)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)Y1(u)&&!i.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function Sn(t){let e=[],n=(a,s)=>e.push({code:"invalid-snapshot",path:a,message:s});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let r=new Set;for(let[a,s]of t.entries()){let c=`snapshots[${a}]`;if(!Y1(s)||s.schemaVersion!==1||!$0(s.configuration)||!zn(s.params)||!zn(s.renderSettings)||!Th(s.provenance)||!Array.isArray(s.parts)||!Array.isArray(s.hardware)||!Array.isArray(s.warnings)||!s.warnings.every(i=>typeof i=="string")||typeof s.legacyHardware!="boolean"||typeof s.relationsKnown!="boolean"||s.error!==void 0&&typeof s.error!="string"){n(c,"Malformed snapshot, configuration, provenance or inventory.");continue}r.has(s.configuration)&&n(c,"Configuration snapshots must be unique."),r.add(s.configuration);let o=new Set;for(let[i,l]of s.parts.entries()){if(!Y1(l)||!$0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!U2(l.thickness)||l.glue!==void 0&&(!ye(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!$0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!ne(l.kerf)||l.kerf>1e6)||!Ih(l.matrix)||typeof l.placed!="boolean"||!qr(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!qr(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>Y1(u)&&P2(u.x0)&&P2(u.x1)&&u.x1>u.x0&&P2(u.angle))||l.folds!==void 0&&(!Array.isArray(l.folds)||!l.folds.every(u=>Y1(u)&&re(u.from,2)&&re(u.to,2)&&P2(u.angle)))){n(`${c}.parts[${i}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);o.has(h)&&n(`${c}.parts[${i}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),o.add(h)}for(let[i,l]of s.hardware.entries())(!Y1(l)||l.label!==null&&!$0(l.label)||typeof l.kind!="string"||!re(l.from,3)||!re(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!C2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!U2(l.size))||!(U2(l.size)&&l.size<=1e6||re(l.size,2)&&l.size.every(h=>U2(h)&&h<=1e6)))&&n(`${c}.hardware[${i}]`,"Malformed hardware geometry or label.")}return e}function qr(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>re(r,2)&&r.every(a=>Math.abs(a)<=1e6)))}function Ih(t){if(!re(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(r=>Math.abs(r)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let r=0;r<3;r++)for(let a=0;a<3;a++){let s=e[r]*e[a]+e[4+r]*e[4+a]+e[8+r]*e[8+a];if(Math.abs(s-(r===a?1:0))>n)return!1}return Math.abs(e[0]*(e[5]*e[10]-e[6]*e[9])-e[1]*(e[4]*e[10]-e[6]*e[8])+e[2]*(e[4]*e[9]-e[5]*e[8])-1)<n}function Nr(t){let e=[];for(let n of t.claims){let r=a=>e.push({claim:n.id,ref:a});n.kind==="glue-contact"&&(r(n.a),r(n.b)),n.kind==="tab-slot"&&(r(n.tab),r(n.receiver)),n.kind==="captured-shaft"&&(r(n.shaft),n.bearings.forEach(r),n.stack.forEach(r),n.stops.forEach(a=>{r(a.body),a.attachment.kind==="threaded"&&r(a.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(r),n.kind==="motion-clearance"&&n.moving.forEach(a=>r(a.body)),n.kind==="assembly-access"&&(n.initial.forEach(r),n.scope?.forEach(r),n.steps.forEach(a=>r(a.part))),n.kind==="retention"&&(n.roots.forEach(r),n.removable?.forEach(r)),n.kind==="joint-constraints"&&(n.bodies.forEach(r),n.roots.forEach(r),n.joints.forEach(a=>{r(a.a),r(a.b)})),n.kind==="stability"&&(n.supports.forEach(r),n.loads.forEach(a=>r(a.body))),n.kind==="assembly-support"&&n.holds?.forEach(a=>a.bodies.forEach(r))}return e}var f2=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),B2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var i0=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),d1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),En=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),y5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,b5=(t,e)=>y5(t,e)?.thickness??[e.thickness,e.thickness];function L3(t,e){let n=y5(t,e);return n?e.kerf===null?[-1/0,1/0]:[e.kerf-n.kerf[1]-2*(n.edgeError??0),e.kerf-n.kerf[0]+2*(n.edgeError??0)]:[0,0]}var Cn=(t,e)=>t[0]>=e[0]+Y&&t[1]<=e[1]-Y,Pn=(t,e)=>t[0]<e[0]-Y||t[1]>e[1]+Y,Tn=(...t)=>t.map(S3).find(Boolean);function Pt(t,e){let n=f2(e,t.a),r=f2(e,t.b);if(n===r)return i0("A glue contact needs two different physical instances.");let a=Tn(n,r);if(a)return d1(a);let s=bn(n,r),c=t.faceA==="top"?n.thickness:0,o=t.faceB==="top"?r.thickness:0;if(Math.hypot(s[8],s[9])>1e-9)return i0("The selected faces are not parallel.");let i=Math.abs(s[11]+s[10]*o-c);if(i>Y)return i0("The selected faces are separated.",{faceGap:i});if(i>1e-7)return d1("Face separation is within numerical uncertainty; exact contact is not established.");let l=t.faceA==="top"?1:-1,h=t.faceB==="top"?1:-1;if(l*h*s[10]>-1+1e-7)return i0("The selected surfaces face the same way, rather than meeting.");let u=Or(r.regions,s,o),f=be(G1(n.regions,u)),d=Y*(yn(n.regions)+yn(u)),m={contactArea:f,requiredArea:t.minimumArea,faceGap:i,areaUncertainty:d};return f<t.minimumArea-d?i0("There is insufficient geometric glue contact.",m):f<t.minimumArea+d?{...d1("Contact area is on the numerical acceptance boundary."),measurements:m}:En("The selected nominal faces have the required geometric contact.",m,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function Ur(t,e,n){let r=f2(e,t.tab),a=f2(e,t.receiver);if(r===a)return i0("A tongue and its receiving panel must be different instances.");let s=Tn(r,a);if(s)return d1(s);let c=bn(a,r);if(!Fr(c)||Math.abs(c[10])>Y)return d1("Only orthogonal tab/slot geometry is supported.");let o=Mn(r.regions,t.region);if(!xn(o))return d1("The selected tongue is not one solid rectangle.");let[i,l,h,u]=St(o),f=4*Y,d=Y,p=[[i-f,l+d,i,u-d],[h,l+d,h+f,u-d],[i+d,l-f,h-d,l],[i+d,u,h-d,u+f]].map(T=>be(Mn(r.regions,T))>Y*Y).flatMap((T,O)=>T?[O]:[]);if(p.length>1)return d1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(p.length&&Math.abs(p[0]<2?c[8]:c[9])<.5)return d1("The tongue must join its parent along the insertion direction.");let g;if(p.length){let T=p[0],O=T<2?[T===0?i:h,(l+u)/2,0]:[(i+h)/2,T===2?l:u,0],_=z0(c,O)[2],D=(T<2?c[8]:c[9])*(T%2===0?-1:1);g={z:_,outward:D}}let v=[];for(let T of[i,h])for(let O of[l,u])for(let _ of[0,r.thickness])v.push(z0(c,[T,O,_]));let b=[0,1,2].map(T=>Math.min(...v.map(O=>O[T]))),y=[0,1,2].map(T=>Math.max(...v.map(O=>O[T]))),M=wn(a.regions,[(b[0]+y[0])/2,(b[1]+y[1])/2]);if(!M.length)return i0("The receiving panel has no closed slot at the tongue.");if(M.length!==1||!xn([M[0]]))return d1("The receiving feature must be an unambiguous rectangular closed slot.");let w=M[0],x=St([w]),k=L3(n,r),A=L3(n,a);if(![...k,...A].every(Number.isFinite))return d1("Compensated kerf metadata is needed for manufacturing bounds.");let L={},z=!1;for(let T=0;T<2;T++){let O=Math.abs(c[T*4+2])>.5,_=O?b5(n,r):[y[T]-b[T]+k[0],y[T]-b[T]+k[1]],D=x[T+2]-x[T],G=[D-A[1]-_[1],D-A[0]-_[0]];if(L[T?"clearanceY":"clearanceX"]=G,Pn(G,t.clearance))return i0("Tab/slot clearance is outside the required range.",L);z||(z=!Cn(G,t.clearance));let V=b[T],U=y[T];O?c[T*4+2]>0?U+=_[1]-r.thickness:V-=_[1]-r.thickness:(V-=Math.max(0,k[1])/2,U+=Math.max(0,k[1])/2);let J=Math.min(V-x[T],x[T+2]-U)-Math.max(0,A[1])/2;if(L[T?"minimumSideGapY":"minimumSideGapX"]=J,J<-Y)return i0("The tongue is offset into the edge of its slot.",L);J<Y&&(z=!0)}let S=Math.max(0,-k[0])/2,C=b5(n,a);if(t.flushTolerance>=C[0]-Y)return d1("flushTolerance must be smaller than the receiving thickness.");let E=Math.max(0,Math.min(y[2]-S,C[1])-Math.max(b[2]+S,0)),I=C[1]-t.flushTolerance;if(L.engagement=E,L.requiredEngagement=I,E<=Y)return i0("The tongue does not engage the receiving panel.",L);if(E<I-Y)return i0("The tongue does not engage through the receiving panel.",L);if(E<I+Y&&(z=!0),g&&(g.outward>0&&g.z<C[1]-Y||g.outward<0&&g.z>Y))return i0("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",L);let H=Math.min(...a.regions.filter(T=>T!==w).map(T=>Rr(w,T)))-Math.max(0,-A[0]);return L.minimumLigament=H,H<t.minimumLigament-Y?i0("Too little material remains around the slot.",L):(H<t.minimumLigament+Y&&(z=!0),z?{...d1("A fit condition is on its numerical acceptance boundary."),measurements:L}:En("The rectangular tongue fits and engages its receiving slot.",L,["Rigid orthogonal parts; nominal placements are held fixed while finished dimensions vary.","The selected local rectangle must identify the physical tongue; this fit does not establish retention."],y5(n,r)||y5(n,a)?"bounded-fit":"nominal"))}function v5(t){let e=S1(t.to,t.from),n=V1(e);return typeof t.size=="number"&&n>Y?{start:t.from,dir:e.map(r=>r/n),length:n,diameter:t.size}:null}function An(t,e){let n=v5(e);if(!n||V1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let r=S1(n.start,t.start),a=o0(r,t.dir);return V1(r.map((s,c)=>s-a*t.dir[c]))<Y}var Ct=(t,e)=>o0(S1(e,t.start),t.dir),Ln=(t,e)=>[Ct(t,e.from),Ct(t,e.to)].sort((n,r)=>n-r);function Vh(t,e){let n=$r(e.matrix);if(o0(n,t.dir)<0||V1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let r=z0(L0(e.matrix),t.start),a=[r[0],r[1]],s=wn(e.regions,a);if(!s.length)return"No bore surrounds the shaft axis.";if(s.length!==1)return"The bore selector is ambiguous.";let c=s[0],o=c.length>1&&c[0][0]===c[c.length-1][0]&&c[0][1]===c[c.length-1][1]?c.slice(0,-1):c,i=[o.reduce((p,g)=>p+g[0],0)/o.length,o.reduce((p,g)=>p+g[1],0)/o.length];if(Math.hypot(i[0]-a[0],i[1]-a[1])>Y)return"The shaft is not centered in the bore.";let l=c.map(p=>Math.hypot(p[0]-i[0],p[1]-i[1]));if(Math.max(...l)-Math.min(...l)>Y)return"The bore is not a supported circular polygon.";let h=Math.min(...c.map((p,g)=>z3(a,p,c[(g+1)%c.length]))),u=Math.max(...c.map(p=>Math.hypot(p[0]-a[0],p[1]-a[1]))),f=Ct(t,z0(e.matrix,[0,0,0])),d=Ct(t,z0(e.matrix,[0,0,e.thickness])),m=Math.max(...e.regions.flatMap(p=>p.map(g=>Math.hypot(g[0]-a[0],g[1]-a[1]))));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u],reach:m}}function Br(t,e,n){let r=B2(e,t.shaft),a=v5(r);if(!a)return d1("The shaft must have a nonzero cylindrical physical envelope.");let s=[...t.bearings,...t.stack],c=s.map(x=>JSON.stringify([x.part,x.copy??1]));if(new Set(c).size!==c.length)return i0("Bearing and stack references must name distinct physical parts.");let o=s.map(x=>f2(e,x)),i=Tn(...o);if(i)return d1(i);let l={shaftDiameter:a.diameter},h=[],u=!1;for(let x=0;x<o.length;x++){let k=o[x],A=Vh(a,k);if(typeof A=="string")return/unsupported|supported/.test(A)?d1(`${k.name}: ${A}`):i0(`${k.name}: ${A}`);let L=L3(n,k);if(!L.every(Number.isFinite))return d1("Kerf metadata is required for bore tolerance bounds.");let z=[A.hole[0]-L[1]-a.diameter,A.hole[1]-L[0]-a.diameter];if(l[`clearance${x+1}`]=z,Pn(z,t.clearance))return i0(`${k.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!Cn(z,t.clearance)),A.lo<-Y||A.lo+b5(n,k)[1]>a.length+Y)return i0(`${k.name}: the shaft does not extend through this part.`,l);h.push(A)}let f=h.slice(0,2).sort((x,k)=>x.lo-k.lo),d=h.slice(2).sort((x,k)=>x.lo-k.lo);if(f.some(x=>b5(n,x.part).some(k=>Math.abs(k-x.part.thickness)>Y)))return d1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-Y)return i0("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-Y||d[x].hi>f[1].lo+Y||x&&d[x-1].hi>d[x].lo+Y)return i0("The axial stack overlaps another component or its supports.");let m=f[1].lo-f[0].lo,g=[f[0].part,...d.map(x=>x.part)].map(x=>b5(n,x)).reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[0,0]),v=[m-g[1],m-g[0]];if(l.endplay=v,Pn(v,t.endplay))return i0("The axial stack has insufficient or excessive endplay.",l);u||(u=!Cn(v,t.endplay));let b=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],y=t.stops.map(x=>({stop:x,h:B2(e,x.body)})).map(x=>({...x,at:x.h&&An(a,x.h)?Ln(a,x.h):void 0}));if(y.some(x=>!x.at))return i0("A retainer is not coaxial with the shaft.");y.sort((x,k)=>x.at[0]+x.at[1]-(k.at[0]+k.at[1]));let M=x=>x.hole[1]-L3(n,x.part)[0],w=x=>2*x.reach+L3(n,x.part)[0];for(let x=0;x<2;x++){let k=Math.max(w(f[x]),v5(y[x].h)?.diameter??0),A=x===0?d.map((z,S)=>S):d.map((z,S)=>d.length-1-S),L=[];for(let z=0;z<A.length;z++){let S=d[A[z]],C=M(S),E=A.slice(0,z).map((O,_)=>({b:d[O],gone:L[_]})),I=O=>C>O+Y,H=O=>Math.abs(C-O)<=Y,T=I(k)&&E.every(O=>O.gone||I(w(O.b)));if(L.push(T),T)return i0(`${S.part.name} can slide off over ${f[x].part.name} and its retainer: its bore is wider than all that holds it on that side.`,l);(H(k)||E.some(O=>!O.gone&&H(w(O.b))))&&(u=!0)}}for(let x=0;x<2;x++){let{stop:k,h:A}=y[x];if(!An(a,A))return i0("A retainer is not coaxial with the shaft.");let L=v5(A),z=Ln(a,A),S=f[x],C=x===0?z[1]:z[0],E=x===0?S.lo:S.hi,I=x===0?E-C:C-E;l[`stopGap${x+1}`]=I;let H=L3(n,S.part),T=(L.diameter-(S.hole[1]-H[0]))/2;if(l[`stopOverlap${x+1}`]=T,I<-Y||I>t.maximumStopGap+Y)return i0("A retainer is misplaced relative to the outside bearing face.",l);if((I<-1e-7||I>t.maximumStopGap+1e-7)&&(u=!0),T<t.minimumOverlap-Y)return i0("A retainer can pass through its bearing opening.",l);T<t.minimumOverlap+Y&&(u=!0);let O=k.attachment;if(O.kind==="unknown")return{...d1("The stop is present but its fastening is unverified."),measurements:l};if(O.kind==="integral"){if(Math.min(Math.abs(C),Math.abs(C-a.length))>Y)return i0("An integral head must meet an end of its shaft.",l);b.push("The specified head and shaft are one integral purchased component.")}else{let _=B2(e,O.thread);if(!An(a,_))return i0("The threaded attachment is off the shaft axis.");if(v5(_).diameter>a.diameter+Y)return i0("The declared threaded section exceeds the shaft envelope.");let D=Ln(a,_),G=Math.max(0,Math.min(z[1],D[1])-Math.max(z[0],D[0]));if(D[0]<-Y||D[1]>a.length+Y)return i0("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=G,G<O.minimumEngagement-Y)return i0("The threaded stop has insufficient declared thread engagement.",l);if(G<O.minimumEngagement+Y&&(u=!0),!O.secured)return{...d1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};b.push("The specified usable thread envelope and matching nut are installed and secured as declared; thread form/capacity and resistance to loosening are not verified.")}}return u?{...d1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:En("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,b,o.some(x=>y5(n,x))?"bounded-fit":"nominal")}var Et=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},v1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),G0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],H0=(t,e)=>t.map(n=>n*e),Wr=(t,e)=>t.map((n,r)=>n+e[r]),t0=t=>H0(t,1/V1(t)),Xr=()=>U0(0,0,0);function In(t,e){let n=r=>r.kind==="translate"?V1(r.by)<1e-9:Math.abs(r.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?V1(S1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?V1(S1(H0(t0(t.axis),t.angle),H0(t0(e.axis),e.angle)))<1e-9&&V1(G0(S1(t.origin,e.origin),t0(t.axis)))<1e-9:!1}function $h(t,e){let n=new Map;for(let r of e)for(let a=0;a<r.length;a++){let s=r[a],c=r[(a+1)%r.length],o=s<c?[s,c]:[c,s];n.set(o.join(","),o)}return{vertices:t,faces:e,edges:[...n.values()]}}function C3(t,e,n){let r=t.length,a=[];for(let s of[0,e])for(let[c,o]of t)a.push(z0(n,[c,o,s]));return $h(a,[t.map((s,c)=>c).reverse(),t.map((s,c)=>r+c),...t.map((s,c)=>[c,(c+1)%r,(c+1)%r+r,c+r])])}function Hh(t,e){let n=t1(t),r=[...new Set(n.flat().map(o=>o[0]))].sort((o,i)=>o-i),a=n.flatMap(o=>o.map((i,l)=>({a:i,b:o[(l+1)%o.length]}))),s=[],c=(o,i)=>o.a[1]+(i-o.a[0])*(o.b[1]-o.a[1])/(o.b[0]-o.a[0]);for(let o=1;o<r.length;o++){let i=r[o-1],l=r[o],h=(i+l)/2;e.tick(a.length);let u=a.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>c(f,h)-c(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],m=u[f+1],p=[[i,c(d,i)],[l,c(d,l)],[l,c(m,l)],[i,c(m,i)]],g=p.filter((v,b)=>V1([v[0]-p[(b+1)%p.length][0],v[1]-p[(b+1)%p.length][1],0])>1e-10);if(g.length<3||Math.abs(qe(g))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(s.push(g),s.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!s.length||Math.abs(be(s)-be(n))>Y*Y*Math.max(1,be(n)))throw new Error("Rigid decomposition did not preserve material area.");return s}function Ue(t){if(t.hardware.some(n=>!n.label))throw new Error("Physical hardware needs unique labels for whole-inventory checks.");let e=[...t.parts.map(n=>({part:n.name,copy:n.copy})),...t.hardware.map(n=>({hardware:n.label}))];if(new Set(e.map(v1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function x5(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function y0(t,e){if("part"in e)return f2(t,e).matrix;let n=B2(t,e),[r,a]=x5(n),s={...n,from:r,to:a},c=t0(S1(s.to,s.from));if(!V1(S1(s.to,s.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let o=S1(s.up,H0(c,o0(s.up,c)));if(V1(o)<1e-9){if(Array.isArray(s.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(c[0])<.8?[1,0,0]:[0,1,0];o=S1(l,H0(c,o0(l,c)))}o=t0(o);let i=G0(o,c);return[i[0],o[0],c[0],s.from[0],i[1],o[1],c[1],s.from[1],i[2],o[2],c[2],s.from[2],0,0,0,1]}function xe(t,e,n){if(n.tick(),"part"in e){let h=f2(t,e),u=S3(h);if(u)throw new Error(u);let d=Hh(h.regions,n).map(m=>C3(m,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=B2(t,e),a=y0(t,e),[s,c]=x5(r),o=V1(S1(c,s));if(o<Y)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(r.size)){let[h,u]=r.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[C3(f,o,a)];return{ref:e,outer:d,inner:d}}let i=32,l=h=>Array.from({length:i},(u,f)=>[h*Math.cos(f*2*Math.PI/i),h*Math.sin(f*2*Math.PI/i)]);if(r.shape==="ball"){let h=r.size/2,u=h/Math.SQRT2,f=U0(0,0,h-u);return{ref:e,inner:[C3(l(u),2*u,T1(a,f))],outer:[C3(l(h/Math.cos(Math.PI/i)),o,a)]}}return{ref:e,inner:[C3(l(r.size/2),o,a)],outer:[C3(l(r.size/2/Math.cos(Math.PI/i)),o,a)]}}function Tt(t,e){let n=a=>a.map(s=>({...s,vertices:s.vertices.map(c=>z0(e,c))})),r=n(t.outer);return{ref:t.ref,outer:r,inner:t.inner===t.outer?r:n(t.inner)}}function Be(t,e){if(t.kind==="translate")return U0(...H0(t.by,e));let[n,r,a]=t0(t.axis),s=t.angle*Math.PI/180*e,c=Math.cos(s),o=Math.sin(s),i=1-c,l=[c+n*n*i,n*r*i-a*o,n*a*i+r*o,0,r*n*i+a*o,c+r*r*i,r*a*i-n*o,0,a*n*i-r*o,a*r*i+n*o,c+a*a*i,0,0,0,0,1];return T1(U0(...t.origin),T1(l,U0(...H0(t.origin,-1))))}function Vn(t,e){if(e.kind==="translate")return V1(e.by);let n=t0(e.axis),r=0;for(let a of t.outer)for(let s of a.vertices){let c=S1(s,e.origin);r=Math.max(r,V1(S1(c,H0(n,o0(c,n)))))}return Math.abs(e.angle)*Math.PI/180*r}function jr(t){return t.faces.map(e=>G0(S1(t.vertices[e[1]],t.vertices[e[0]]),S1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>V1(e)>1e-12).map(t0)}function Zr(t,e){let n=[...jr(t),...jr(e)];for(let[r,a]of t.edges)for(let[s,c]of e.edges){let o=G0(S1(t.vertices[a],t.vertices[r]),S1(e.vertices[c],e.vertices[s]));V1(o)>1e-12&&n.push(t0(o))}return n}var P3=(t,e)=>{let n=t.vertices.map(r=>o0(r,e));return[Math.min(...n),Math.max(...n)]};function Oh(t,e,n){let r=-1/0;for(let a of Zr(t,e)){n.tick();let s=P3(t,a),c=P3(e,a);r=Math.max(r,c[0]-s[1],s[0]-c[1])}return r}function Rh(t,e){let n=0;for(let r=0;r<3;r++){let a=t.vertices.map(o=>o[r]),s=e.vertices.map(o=>o[r]),c=Math.max(0,Math.min(...s)-Math.max(...a),Math.min(...a)-Math.max(...s));n+=c*c}return Math.sqrt(n)}function Fh(t,e,n,r){let a=S1(n,e),s=S1(r,e),c=S1(t,e),o=o0(a,c),i=o0(s,c);if(o<=0&&i<=0)return V1(c);let l=S1(t,n),h=o0(a,l),u=o0(s,l);if(h>=0&&u<=h)return V1(l);let f=o*u-h*i;if(f<=0&&o>=0&&h<=0)return V1(S1(c,H0(a,o/(o-h))));let d=S1(t,r),m=o0(a,d),p=o0(s,d);if(p>=0&&m<=p)return V1(d);let g=m*i-o*p;if(g<=0&&i>=0&&p<=0)return V1(S1(c,H0(s,i/(i-p))));let v=h*p-m*u;if(v<=0&&u-h>=0&&m-p>=0)return V1(S1(l,H0(S1(r,n),(u-h)/(u-h+m-p))));let b=v+g+f;if(Math.abs(b)<1e-20)return 1/0;let y=Math.max(0,Math.min(1,g/b)),M=Math.max(0,Math.min(1-y,f/b));return V1(S1(c,Wr(H0(a,y),H0(s,M))))}function _h(t,e,n,r){let a=S1(e,t),s=S1(r,n),c=S1(t,n),o=o0(a,a),i=o0(a,s),l=o0(s,s),h=o0(a,c),u=o0(s,c);if(o<1e-20||l<1e-20)return 1/0;let f=o*l-i*i,d=f>1e-20?Math.max(0,Math.min(1,(i*u-l*h)/f)):0,m=(i*d+u)/l;return m<0&&(m=0,d=Math.max(0,Math.min(1,-h/o))),m>1&&(m=1,d=Math.max(0,Math.min(1,(i-h)/o))),V1(Wr(c,S1(H0(a,d),H0(s,m))))}function qh(t,e,n){let r=1/0;for(let[a,s]of[[t,e],[e,t]])for(let c of a.vertices)for(let o of s.faces)for(let i=1;i<o.length-1;i++)n.tick(),r=Math.min(r,Fh(c,s.vertices[o[0]],s.vertices[o[i]],s.vertices[o[i+1]]));for(let[a,s]of t.edges)for(let[c,o]of e.edges)n.tick(),r=Math.min(r,_h(t.vertices[a],t.vertices[s],e.vertices[c],e.vertices[o]));return r}function Gr(t,e,n,r){let a=1/0,s=1/0,c=!1,o=!0;for(let i of t)for(let l of e){n.tick();let h=Rh(i,l);if(h>Math.min(s,r)){a=Math.min(a,h);continue}let u=Oh(i,l,n);u<-Y&&(c=!0),u<0&&(o=!1),a=Math.min(a,Math.max(0,h,u)),u<-Y?s=0:u<=Math.min(s,r)&&(s=Math.min(s,qh(i,l,n)))}return{lower:a,upper:s,penetration:c,touchSafe:o}}function It(t,e,n,r){let a=Gr(t.outer,e.outer,n,r+Y),s=t.outer===t.inner&&e.outer===e.inner;if(a.lower>r+Y)return{lower:a.lower-Y,upper:1/0,penetration:!1,touchSafe:!0};let c=s?a:Gr(t.inner,e.inner,n,1/0);return{lower:Math.max(0,a.lower-Y),upper:c.upper+Y,penetration:c.penetration,touchSafe:a.touchSafe}}function Yr(t,e,n,r,a,s){for(let c=0;c<t.outer.length;c++)for(let o=0;o<n.outer.length;o++){let i=t.outer[c],l=n.outer[o],h=e.outer[c],u=r.outer[o],f=!1;for(let d of Zr(i,l)){s.tick();let m=P3(i,d),p=P3(l,d),g=P3(h,d),v=P3(u,d);if(Math.min(p[0]-m[1],v[0]-g[1])>=a||Math.min(m[0]-p[1],g[0]-v[1])>=a){f=!0;break}}if(!f)return!1}return!0}function Vt(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let r={part:n.name,copy:n.copy},a=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(a>1&&(n.copy-1)%a!==0){let s=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:r,faceA:s?"bottom":"top",faceB:s?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:r,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var E2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),M5=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<Y);function Kr(t,e,n){if(new Set(e.map(v1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(r=>xe(t,r,n))}function Jr(t,e,n){let r=Kr(e,t.bodies??Ue(e),n);if(r.length<2)return d1("Rigid clearance requires at least two physical bodies.");let a=1/0;for(let s=0;s<r.length;s++)for(let c=s+1;c<r.length;c++){let o=It(r[s],r[c],n,t.minimumGap);if(a=Math.min(a,o.lower),o.penetration||o.upper<t.minimumGap-Y)return E2("Physical bodies interfere or violate the required clearance.",{gapUpper:o.upper},[r[s].ref,r[c].ref]);if(!(o.lower>t.minimumGap||t.minimumGap===0&&o.touchSafe))return{...d1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[r[s].ref,r[c].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:a},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function $n(t,e,n,r,a=1e3){let s=i=>({solid:i,trajectory:{kind:"translate",by:[0,0,0]}});function*c(){for(let i=0;i<t.length;i++){for(let l of e)yield{a:t[i],b:s(l)};for(let l=i+1;l<t.length;l++)yield{a:t[i],b:t[l]}}}let o=0;for(let{a:i,b:l}of c()){r.tick();let h=(d,m)=>Tt(d.solid,Be(d.trajectory,m));if(In(i.trajectory,l.trajectory)){let d=It(i.solid,l.solid,r,n);if(d.penetration||d.upper<n-Y)return E2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[i.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...d1("The fixed relative clearance is within geometric uncertainty."),entities:[i.solid.ref,l.solid.ref]}}if(i.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&Yr(h(i,0),h(i,1),h(l,0),h(l,1),n===0?0:n+Y,r))continue;let u=Vn(i.solid,i.trajectory)+Vn(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++o>a)return{...d1("Continuous clearance interval budget exhausted."),measurements:{intervals:o},entities:[i.solid.ref,l.solid.ref]};r.tick();let[d,m]=f.shift(),p=(d+m)/2,g=u*(m-d)/2,v=It(h(i,p),h(l,p),r,n+g);if(v.penetration||v.upper<n-Y)return E2("The specified path has physical interference.",{phase:p,gapUpper:v.upper},[i.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(m-d<1e-9)return{...d1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,m]},entities:[i.solid.ref,l.solid.ref]};f.push([d,p],[p,m])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:o},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function Dh(t,e){if(t.parts.length!==e.parts.length||t.hardware.length!==e.hardware.length)return"The physical inventory changes between motion endpoints.";for(let n of t.parts){let r=e.parts.find(a=>a.name===n.name&&a.copy===n.copy);if(!r||n.cutLines===null||r.cutLines===null||!At(n,r))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([r.stack,r.glue,r.glueFace,r.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let r=e.hardware.find(a=>a.label===n.label);if(!n.label||!r||n.kind!==r.kind||JSON.stringify(n.size)!==JSON.stringify(r.size)||Math.abs(V1(S1(n.to,n.from))-V1(S1(r.to,r.from)))>Y)return"Hardware identities and dimensions must remain invariant."}return null}function Qr(t,e,n,r,a=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return d1("Motion requires complete cutting and native attachment metadata at both endpoints.");let s=Dh(e,n);if(s)return{status:"fail",code:"motion-inventory",message:s};let c=Ue(e),o=new Set(t.moving.map(l=>v1(l.body)));if(o.size!==t.moving.length)return E2("A body has conflicting simultaneous trajectories.");let i=l=>t.moving.find(h=>v1(h.body)===v1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...Vt(e),...a]){let h=T1(L0(y0(e,l.a)),y0(e,l.b)),u=T1(L0(y0(n,l.a)),y0(n,l.b));if(!M5(h,u)||!In(i(l.a),i(l.b)))return E2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of c){let h=t.moving.find(f=>v1(f.body)===v1(l))?.trajectory,u=h?Be(h,1):Xr();if("part"in l){if(!M5(T1(u,y0(e,l)),y0(n,l)))return E2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=B2(e,l),d=B2(n,l);if(typeof f.size=="number"){if(!M5(z0(u,f.from),d.from)||!M5(z0(u,f.to),d.to))return E2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!M5(T1(u,y0(e,l)),y0(n,l)))return E2("A box trajectory does not match its rendered destination.",{},[l])}}return $n(t.moving.map(l=>({solid:xe(e,l.body,r),trajectory:l.trajectory})),Kr(e,c.filter(l=>!o.has(v1(l))),r),t.minimumGap,r,t.maxIntervals)}function ea(t,e,n){let r=t.scope??Ue(e),a=new Set(r.map(v1)),s=new Map(t.initial.map(i=>[v1(i),xe(e,i,n)]));if(a.size!==r.length||s.size!==t.initial.length||t.initial.some(i=>!a.has(v1(i))))return E2("Assembly scope and initial inventory must be unique and consistent.");let c=new Set,o=0;for(let i of t.steps){if(c.has(i.id)||!a.has(v1(i.part))||s.has(v1(i.part)))return E2("An assembly step duplicates or misidentifies a required installation.");if(c.add(i.id),!i.held)return{...d1(`Step ${i.id} needs an explicit temporary holding/support assumption.`),assemblyStep:i.id};let l=xe(e,i.part,n),h=Tt(l,Be({kind:"translate",by:i.from},1)),u=$n([{solid:h,trajectory:{kind:"translate",by:i.from.map(f=>-f)}}],[...s.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:i.id,message:`Assembly step ${i.id}: ${u.message}`};if(o+=u.measurements?.intervals??0,s.set(v1(i.part),l),i.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:i.tool.from,to:i.tool.to,size:i.tool.diameter,up:[0,1,0]}]},m=xe(d,{hardware:f},n),p=Tt(m,Be({kind:"translate",by:i.tool.travel},1)),g=$n([{solid:p,trajectory:{kind:"translate",by:i.tool.travel.map(v=>-v)}}],[...s.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:i.id,message:`Tool access at step ${i.id}: ${g.message}`}}}return s.size!==a.size?E2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:s.size,intervals:o},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var l0=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),i2=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),r2=t=>[t[3],t[7],t[11]],Hn=t=>{let e=t0(t),n=t0(G0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,G0(e,n)]},$t=(t,e,n)=>{let r=Hn(n)[0],a=t0(i2(e,r)),s=t0(i2(t,r)),c=t0(i2(e,n));return Math.atan2(o0(c,G0(a,s)),o0(a,s))*180/Math.PI},ta=(t,e,n)=>{let r=[],a=Math.ceil((e[0]-n-t)/360),s=Math.floor((e[1]+n-t)/360);for(let o=a;o<=s&&r.length<64;o++)r.push(t+360*o);let c=(e[0]+e[1])/2;return r.sort((o,i)=>Math.abs(o-c)-Math.abs(i-c))};function na(t,e){if(t?.kind==="glue-contact"&&e==="glued")return[t.a,t.b];if(t?.kind==="captured-shaft"&&e==="captured"){let n=[t.shaft,...t.bearings,...t.stack,...t.stops.map(r=>r.body)];for(let r of t.stops)r.attachment.kind==="threaded"&&n.push(r.attachment.thread);return n}}function ra(t,e,n,r){let a=Ue(e),s=new Set(a.map(v1));for(let f of t.removable??[])s.delete(v1(f));if(t.roots.some(f=>!s.has(v1(f))))return l0("A retention root cannot be excluded as removable.");let c=new Map,o=f=>{for(let d of f)for(let m of f){let p=v1(d),g=c.get(p)??new Set;g.add(v1(m)),c.set(p,g)}},i=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(g=>g.id===f.claim),m=r.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!m)return d1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(m.status==="fail")return l0(`Attachment ${f.claim} fails its geometric contract.`);if(m.status!=="pass")return d1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return l0(`The fastening for ${f.claim} is explicitly not installed.`);let p=na(d,f.fastening);if(!p)return d1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);o(p),d.kind==="glue-contact"&&i.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(v1)),h=[...l];for(;h.length;)for(let f of c.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=a.filter(f=>s.has(v1(f))&&!l.has(v1(f)));return u.length?{...l0("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:s.size,removableComponents:t.removable?.length??0},assumptions:i}}function Nh(t,e){if("hardware"in e){let o=y0(t,e),i=t.hardware.find(l=>l.label===e.hardware);return z0(o,[0,0,V1(S1(x5(i)[1],x5(i)[0]))/2])}let n=f2(t,e),r=S3(n);if(r)throw new Error(r);let a=0,s=0,c=0;for(let o of n.regions){let[i,l]=o[0],h=0,u=0,f=0;for(let m=0;m<o.length;m++){let p=o[m],g=o[(m+1)%o.length],v=p[0]-i,b=p[1]-l,y=g[0]-i,M=g[1]-l,w=v*M-y*b;h+=w,u+=(v+y)*w,f+=(b+M)*w}if(Math.abs(h)<1e-12)continue;let d=qe(o);a+=d,s+=(i+u/(3*h))*d,c+=(l+f/(3*h))*d}if(a<=Y*Y)throw new Error("Material centroid is numerically unresolved.");return z0(n.matrix,[s/a,c/a,n.thickness/2])}function Uh(t){let e=[...t].sort((c,o)=>c[0]-o[0]||c[1]-o[1]),n=(c,o,i)=>(o[0]-c[0])*(i[1]-c[1])-(o[1]-c[1])*(i[0]-c[0]),r=c=>{let o=[];for(let i of c){for(;o.length>1&&n(o[o.length-2],o[o.length-1],i)<=0;)o.pop();o.push(i)}return o},a=r(e),s=r([...e].reverse());return[...a.slice(0,-1),...s.slice(0,-1)]}function Bh(t,e,n){let r=new Map,a=o=>{for(let i of o)for(let l of o){let h=r.get(v1(i))??new Set;h.add(v1(l)),r.set(v1(i),h)}};for(let o of t.links){let i=na(e.claims.find(l=>l.id===o.claim),o.fastening);i&&a(i)}if(!n.length)return!0;let s=new Set([v1(n[0])]),c=[...s];for(;c.length;)for(let o of r.get(c.pop())??[])s.has(o)||(s.add(o),c.push(o));return n.every(o=>s.has(v1(o)))}function aa(t,e,n,r=[],a){let s=Ue(e),c=t.loads.map(p=>v1(p.body));if(new Set(c).size!==c.length||s.some(p=>!c.includes(v1(p))))return d1("Stability needs one declared positive mass for every physical component.");if(s.length>1){let p=r.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=a?.claims.find(v=>v.id===t.retention);if(!p||p.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return d1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!Bh(g,a,s))return d1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let o=0,i=[0,0,0];for(let p of t.loads){let g=p.center?z0(y0(e,p.body),p.center):Nh(e,p.body);o+=p.mass,i=i.map((v,b)=>v+p.mass*g[b])}if(!Number.isFinite(o)||!i.every(Number.isFinite))return d1("Mass/centroid calculation exceeds its numerical range.");i=H0(i,1/o);let l=[];for(let p of s){let g=xe(e,p,n),v=Math.min(...g.inner.flatMap(y=>y.vertices.map(M=>M[2]))),b=Math.min(...g.outer.flatMap(y=>y.vertices.map(M=>M[2])));if(v<t.ground-Y)return l0("A physical component penetrates the ground plane.");if(b<t.ground-Y)return d1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(y=>v1(y)===v1(p))){if(Math.abs(v-t.ground)>1e-8)return d1("Ground contact is separated or within physical-envelope uncertainty.");for(let y of g.inner)for(let M of y.vertices)Math.abs(M[2]-t.ground)<1e-8&&l.push([M[0],M[1]])}}let h=Uh(l);if(h.length<3)return d1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-i[2])/t.gravity[2],f=[i[0]+u*t.gravity[0],i[1]+u*t.gravity[1]],d=1/0;for(let p=0;p<h.length;p++){let g=h[p],v=h[(p+1)%h.length],b=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),y=z3(f,g,v);d=Math.min(d,b<0?-y:y)}let m={supportMargin:d,mass:o,centerX:i[0],centerY:i[1],centerZ:i[2]};return d<t.minimumMargin-Y?l0("The gravity line lies outside the required support margin.",m):d<t.minimumMargin+Y?{...d1("Stability is on its numerical support boundary."),measurements:m}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:m,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function sa(t,e,n,r){let a=n.claims.find(d=>d.id===t.plan),s=n.claims.find(d=>d.id===t.retention),c=d=>r.find(m=>m.id===d&&m.configurations.includes(e.configuration));if(!a||a.kind!=="assembly-access"||!s||s.kind!=="retention"||c(t.plan)?.status!=="pass"||c(t.retention)?.status!=="pass")return d1("Assembly support needs verified insertion and retention contracts.");if(s.removable?.length)return d1("Per-step support of removable objects needs an explicit contact model.");let o=new Set(s.roots.map(v1)),i=new Set(a.initial.map(v1));if(a.initial.some(d=>!o.has(v1(d))))return d1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of s.links){let m=n.claims.find(p=>p.id===d.claim);if(m?.kind==="glue-contact")l.set(d.claim,[m.a,m.b]);else if(m?.kind==="captured-shaft"){let p=[m.shaft,...m.bearings,...m.stack,...m.stops.map(g=>g.body)];m.stops.forEach(g=>{g.attachment.kind==="threaded"&&p.push(g.attachment.thread)}),l.set(d.claim,p)}}let h=new Set,u=new Set(a.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return l0("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let g of h)for(let v of l.get(g)??[])for(let b of l.get(g)??[]){let y=d.get(v1(v))??new Set;y.add(v1(b)),d.set(v1(v),y)}let m=new Set([...o].filter(g=>i.has(g))),p=[...m];for(;p.length;)for(let g of d.get(p.pop())??[])m.has(g)||(m.add(g),p.push(g));return m};for(let d of a.steps){i.add(v1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return l0(`Step ${d.id} names an unknown fastening.`);if(v.some(b=>!i.has(v1(b))))return l0(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let m=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(v1));if([...m].some(g=>!i.has(g)))return l0(`Step ${d.id} holds an uninstalled body.`);let p=f();if([...i].some(g=>!p.has(g)&&!m.has(g)))return l0(`Step ${d.id} releases a component before it is retained or supported.`)}return[...i].some(d=>!f().has(d))?l0("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function jh(t){let e=t.map(a=>{let s=Math.max(...a.map(Math.abs),1e-20);return a.map(c=>c/s)}),n=0,r=!1;for(let a=0;a<(e[0]?.length??0)&&n<e.length;a++){let s=n;for(let i=n+1;i<e.length;i++)Math.abs(e[i][a])>Math.abs(e[s][a])&&(s=i);let c=Math.abs(e[s][a]);if(c<1e-10)continue;c<1e-7&&(r=!0),[e[n],e[s]]=[e[s],e[n]];let o=e[n][a];for(let i=a;i<e[n].length;i++)e[n][i]/=o;for(let i=n+1;i<e.length;i++){let l=e[i][a];for(let h=a;h<e[i].length;h++)e[i][h]-=l*e[n][h]}n++}return{rank:n,uncertain:r}}function ca(t,e,n,r,a,s=[]){if(t.bodies.length>64)return d1("Joint rank checks support at most 64 scoped rigid bodies.");let c=t.bodies.map(v1),o=t.roots.map(v1);if(new Set(c).size!==c.length||new Set(o).size!==o.length||o.some(v=>!c.includes(v)))return l0("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>y0(e,v).some((b,y)=>Math.abs(b-y0(n,v)[y])>Y)))return l0("A grounded kinematic root changes pose.");let i=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(c.length*6).fill(0),u=(v,b,y,M,w=1)=>{let x=c.indexOf(v1(b));if(x<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[x*6+y+k]+=w*M[k]};for(let v of t.roots)for(let b=0;b<6;b++){let y=h();y[c.indexOf(v1(v))*6+b]=1,i.push(y)}let f=Vt({...e,parts:e.parts.filter(v=>c.includes(v1({part:v.name,copy:v.copy})))});for(let v of a?.claims??[])if(v.kind==="retention")for(let b of v.links){let y=a.claims.find(M=>M.id===b.claim);b.installed&&b.fastening==="glued"&&y?.kind==="glue-contact"&&s.some(M=>M.id===y.id&&M.configurations.includes(e.configuration)&&M.status==="pass")&&f.push({a:y.a,b:y.b})}for(let v of f)if(!(!c.includes(v1(v.a))&&!c.includes(v1(v.b)))){if(!c.includes(v1(v.a))||!c.includes(v1(v.b)))return d1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let b=Pt({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:Y*Y*4},e);if(b.status!=="pass")return{...b,message:`A native glue/stack bond is not physically established: ${b.message}`}}}let d=[...t.joints,...f.filter(v=>c.includes(v1(v.a))&&c.includes(v1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(r.tick(),v1(v.a)===v1(v.b))return l0("A joint cannot connect a body to itself.");let b=y0(e,v.a),y=y0(e,v.b),M=y0(n,v.a),w=y0(n,v.b),x=T1(L0(b),y),k=T1(L0(M),w),A=z=>{let S=h();u(S,v.b,3,z),u(S,v.a,3,z,-1),i.push(S)},L=(z,S,C)=>{let E=h();u(E,v.b,0,z),u(E,v.a,0,z,-1),u(E,v.b,3,G0(C,z)),u(E,v.a,3,G0(S,z),-1),i.push(E)};if(v.kind==="fixed"){if(x.some((z,S)=>Math.abs(z-k[S])>Y))return l0("A fixed joint changes its relative transform.");l.forEach(z=>A(z)),l.forEach(z=>L(z,S1(r2(y),r2(b)),[0,0,0]))}else if(v.kind==="revolute"){let z=z0(b,v.anchorA),S=z0(y,v.anchorB),C=t0(i2(b,v.axisA)),E=t0(i2(y,v.axisB)),I=o0(t0(i2(M,v.axisA)),t0(i2(w,v.axisB)));if(V1(S1(z,S))>Y||V1(G0(C,E))>1e-7||Math.abs(o0(C,E)-I)>1e-7)return l0("Revolute anchors or axes do not coincide.");if(v.range){let H=$t(x,k,v.axisB);if(!ta(H,v.range,Y).length)return l0("A revolute joint exceeds its declared angular travel.",{angle:H})}l.forEach(H=>L(H,S1(z,r2(b)),S1(S,r2(y)))),Hn(C).forEach(A)}else if(v.kind==="prismatic"){let z=S1(r2(x),r2(k)),S=t0(v.axisA),C=o0(z,S);if([0,1,2,4,5,6,8,9,10].some(E=>Math.abs(x[E]-k[E])>Y)||V1(S1(z,H0(S,C)))>Y)return l0("A slider rotates or moves away from its guide axis.");if(C<v.travel[0]-Y||C>v.travel[1]+Y)return l0("The slider exceeds its allowed travel.",{travel:C});l.forEach(A),Hn(t0(i2(b,v.axisA))).forEach(E=>L(E,S1(r2(y),r2(b)),[0,0,0]))}else{let z=t0(i2(b,v.axisA)),S=t0(i2(y,v.axisB));if(V1(G0(z,S))>1e-7||V1(S1(r2(b),r2(M)))>Y||V1(S1(r2(y),r2(w)))>Y)return l0("The scoped gear axes/centers are not fixed and parallel.");let C=$t(b,M,v.axisA),E=$t(y,w,v.axisB);if(Math.abs(C)>90||Math.abs(E)>90)return d1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(E+v.ratio*C)>1e-6)return l0("The rendered gears do not obey their declared angular ratio.");let I=h();u(I,v.a,3,z,v.ratio),u(I,v.b,3,S),i.push(I)}}r.tick(i.length*c.length*6);let m=jh(i),p=c.length*6-m.rank;if(m.uncertain)return d1("Constraint rank is numerically singular.");let g={degreesOfFreedom:p,constraintRank:m.rank,redundantRows:i.length-m.rank};return p!==t.expectedDof?l0("The joint graph has unintended freedom or is overconstrained.",g):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:g,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function oa(t,e,n,r){let a=i=>t.moving.find(l=>v1(l.body)===v1(i))?.trajectory??{kind:"translate",by:[0,0,0]},s=i=>i.kind==="translate"?V1(i.by)<1e-9:Math.abs(i.angle)<1e-9,c=(i,l)=>s(i)&&s(l)?!0:i.kind==="translate"&&l.kind==="translate"?V1(S1(i.by,l.by))<1e-9:i.kind==="rotate"&&l.kind==="rotate"?V1(S1(H0(t0(i.axis),i.angle),H0(t0(l.axis),l.angle)))<1e-9&&V1(G0(S1(i.origin,l.origin),t0(i.axis)))<1e-9:!1;if(e.roots.some(i=>!s(a(i))))return l0("The analytic path moves a grounded joint root.");let o=new Map;for(let i of e.joints.filter(l=>l.kind!=="gear")){if(o.has(v1(i.b)))return d1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");o.set(v1(i.b),v1(i.a))}for(let i of o.keys()){let l=new Set,h=i;for(;h&&o.has(h);){if(l.has(h))return d1("Continuous closed-linkage constraints need a solver.");l.add(h),h=o.get(h)}}for(let i of e.joints){let l=a(i.a),h=a(i.b),u=y0(n,i.a),f=y0(n,i.b);if(i.kind==="fixed"){if(!c(l,h))return l0("The analytic path separates a fixed joint.");continue}if(i.kind==="revolute"){if(c(l,h))continue;if(!s(l)||h.kind!=="rotate")return d1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=z0(u,i.anchorA),m=t0(i2(u,i.axisA)),p=t0(h.axis);if(V1(G0(m,p))>1e-9||V1(G0(S1(h.origin,d),m))>Y)return l0("The trajectory does not rotate about the actual hinge.");if(i.range){let g=T1(L0(u),f),v=T1(L0(y0(r,i.a)),y0(r,i.b)),b=h.angle*o0(t0(i2(f,i.axisB)),p),y=i.range;if(!ta($t(g,v,i.axisB),y,Y).some(w=>Math.min(w,w+b)>=y[0]-Y&&Math.max(w,w+b)<=y[1]+Y))return l0("The continuous hinge path exceeds its angular stops.")}}else if(i.kind==="prismatic"){if(c(l,h))continue;if(!s(l)||h.kind!=="translate")return d1("This slider trajectory composition needs a richer constraint solver.");let d=t0(i2(u,i.axisA));if(V1(G0(h.by,d))>Y)return l0("The analytic slider path leaves its guide.");let m=T1(L0(u),f),p=T1(L0(y0(r,i.a)),y0(r,i.b)),g=o0(S1(r2(m),r2(p)),t0(i.axisA)),v=g+o0(h.by,d);if(Math.min(g,v)<i.travel[0]-Y||Math.max(g,v)>i.travel[1]+Y)return l0("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,b)=>{if(s(v))return 0;if(v.kind!=="rotate")return null;let y=y0(n,g),M=t0(i2(y,b));return V1(G0(t0(v.axis),M))>1e-9||V1(G0(S1(v.origin,r2(y)),M))>Y?null:v.angle*o0(t0(v.axis),M)},m=d(i.a,l,i.axisA),p=d(i.b,h,i.axisB);if(m===null||p===null)return d1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(p+i.ratio*m)>1e-7)return l0("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function On(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return ia(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(r=>{let a=n?.parts.filter(l=>l.name===r.name),s=a?.length===1?a[0]:void 0,c=s?.glue?.host,i=(c?t.assembly.filter(l=>l.name===c):[]).length===(s?.qty??0)/(s?.stack??1)?Math.floor((r.copy-1)/(s?.stack??1))+1:1;return{name:r.name,copy:r.copy,thickness:r.thickness,material:r.material??"",matrix:r.matrix,placed:r.placed,regions:s?.cutRegions??r.outline,bends:r.bends??[],...r.folds?.length&&{folds:r.folds},kerf:s?.kerf??null,cutLines:s?.cutLines??null,...s?.stack&&{stack:s.stack},...c&&{glue:{part:c,copy:i},glueFace:s.glue.face},...s?.on&&{on:s.on}}}),hardware:t.hardware.map(r=>({label:r.label??null,kind:r.kind,from:r.from,to:r.to,size:r.size,up:r.up,...r.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(r=>r.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function ia(t){if(t&&typeof t=="object"){for(let e of Object.values(t))ia(e);Object.freeze(t)}return t}function Rn(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=g5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(r.length)throw new Error(r[0].message);let a=new Map;for(let s of e){let c=s.body,o=v1(c);if(("part"in c?t.assembly.filter(l=>l.name===c.part&&l.copy===(c.copy??1)).length:t.hardware.filter(l=>l.label===c.hardware).length)!==1||a.has(o))throw new Error("Pose controls must identify one unique physical instance each.");a.set(o,Be(s.trajectory,n))}return{...t,assembly:t.assembly.map(s=>{let c=a.get(v1({part:s.name,copy:s.copy}));return c?{...s,matrix:T1(c,s.matrix)}:s}),hardware:t.hardware.map(s=>{let c={hardware:s.label??""},o=a.get(v1(c));return o?{...s,from:z0(o,s.from),to:z0(o,s.to),up:S1(z0(o,s.up),z0(o,[0,0,0]))}:s})}}function ha(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==Y||g5(e).length||Sn(n).length||n.some(a=>a.error!==void 0||!a.provenance)||!Array.isArray(t.inputs))return!1;let r=a=>JSON.stringify(a,(s,c)=>c&&typeof c=="object"&&!Array.isArray(c)?Object.fromEntries(Object.keys(c).sort().map(o=>[o,c[o]])):c);try{let a=n.map(c=>({configuration:c.configuration,params:c.params,renderSettings:c.renderSettings,provenance:c.provenance})),s=c=>[...c].sort((o,i)=>o.configuration.localeCompare(i.configuration));return r(e)===r(t.specification)&&r(s(a))===r(s(t.inputs))}catch{return!1}}function ua(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let r=g5(t);if(r.length)return{kind:"invalid-spec",issues:r};let a=Sn(e);if(a.length)return{kind:"invalid-snapshot",issues:a};let s=t,c=e,o=[];for(let[g,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(g)||!Number.isSafeInteger(v)||!(v>0))&&o.push({code:"invalid-limits",path:`limits.${g}`,message:"Verification limits must be positive safe integers."});if(o.length)return{kind:"invalid-spec",issues:o};let i={schemaVersion:1,model:s.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:Y,specification:JSON.parse(JSON.stringify(s)),claims:[],inputs:JSON.parse(JSON.stringify(c.map(g=>({configuration:g.configuration,params:g.params,renderSettings:g.renderSettings,provenance:g.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(c.reduce((g,v)=>g+v.hardware.reduce((b,y)=>b+(typeof y.size=="number"?128:8),0)+v.parts.reduce((b,y)=>b+y.regions.reduce((M,w)=>M+w.length,0)+(y.cutLines??[]).reduce((M,w)=>M+w.length,0),0),0)>(n.maxPoints??2e5)||s.claims.length>(n.maxClaims??1e3)||s.configurations.length>(n.maxConfigurations??100))return i.claims.push(Me("$resource-limit","resource-limit",!0,[],{status:"unverified",code:"resource-limit",message:"The verification input exceeds its point, claim or configuration budget. No mechanical conclusions were reached."})),{kind:"report",report:i};let h=new Set(s.configurations.map(g=>g.id));for(let g of c)h.has(g.configuration)||o.push({code:"unknown-configuration",message:`Snapshot ${g.configuration} is not declared.`});for(let g of c){let v=s.configurations.find(b=>b.id===g.configuration)?.params??{};for(let[b,y]of Object.entries(v))JSON.stringify(g.params[b])!==JSON.stringify(y)&&o.push({code:"configuration-mismatch",message:`${g.configuration}: captured parameter ${b} differs from its required value.`})}let u=new Map(s.claims.map(g=>[g.id,g]));for(let{claim:g,ref:v}of Nr(s)){let b=u.get(g);for(let y of c.filter(M=>M.error===void 0&&(!b.configurations||b.configurations.includes(M.configuration)))){let M="part"in v?y.parts.filter(w=>w.name===v.part&&w.copy===(v.copy??1)):y.hardware.filter(w=>w.label===v.hardware);M.length!==1&&o.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${y.configuration}: ${JSON.stringify(v)} resolves to ${M.length} instances; exactly one is required.`})}}if(o.length)return{kind:"invalid-spec",issues:o};for(let g of s.configurations){let v=c.find(y=>y.configuration===g.id),b=v&&v.error===void 0;i.claims.push(Me(`$configuration:${g.id}`,"configuration",!0,[g.id],b?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),b&&(i.claims.push(Me(`$provenance:${g.id}`,"provenance",!0,[g.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&i.claims.push(Me(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
4335
- `)})),v.legacyHardware&&i.claims.push(Me(`$legacy:${g.id}`,"hardware-inventory",!0,[g.id],{status:"unverified",code:"legacy-hardware",message:"echo hardware is not authoritative physical inventory. Migrate it to native hardware before verification."})))}let f=new Et(n.maxOperations),d=g=>g.kind==="retention"?3:g.kind==="stability"||g.kind==="assembly-support"?4:g.kind==="motion-clearance"||g.kind==="assembly-access"?2:g.kind==="joint-constraints"?1:0,m=[...s.claims].sort((g,v)=>d(g)-d(v));for(let g of m){let v=g.configurations??s.configurations.map(b=>b.id);if(g.kind==="cut-invariant"){let b=v.map(y=>c.find(M=>M.configuration===y));i.claims.push(Me(g.id,g.kind,g.required!==!1,v,b.some(y=>!y||y.error!==void 0)?d1("A required configuration is unavailable."):Gh(b)));continue}if(g.kind==="motion-clearance"){let b=c.find(w=>w.configuration===g.from),y=c.find(w=>w.configuration===g.to),M;if(!b||!y||b.error!==void 0||y.error!==void 0)M=d1("Motion endpoints are unavailable.");else try{if(M={status:"pass"},g.constraints){let w=s.claims.find(k=>k.id===g.constraints),x=i.claims.filter(k=>k.id===g.constraints);if(!w||w.kind!=="joint-constraints"||!x.length||x.some(k=>k.status!=="pass")||![g.from,g.to].every(k=>x.some(A=>A.configurations.includes(k))))M=d1("The motion needs verified endpoint joint constraints.");else{let k=c.find(A=>A.configuration===(w.configurations??s.configurations.map(L=>L.id))[0]);M=oa(g,w,b,k)}}if(M.status==="pass"){let w=[];for(let x of s.claims)if(x.kind==="retention")for(let k of x.links){let A=s.claims.find(L=>L.id===k.claim);k.installed&&k.fastening==="glued"&&A?.kind==="glue-contact"&&[g.from,g.to].every(L=>i.claims.some(z=>z.id===A.id&&z.configurations.includes(L)&&z.status==="pass"))&&w.push({a:A.a,b:A.b})}M=Qr(g,b,y,f,w)}}catch(w){M={status:"unverified",code:"geometry-unresolved",message:w.message}}i.claims.push(Me(g.id,g.kind,g.required!==!1,[g.from,g.to],M,la(g)));continue}for(let b of v){let y=c.find(k=>k.configuration===b),M=s.configurations.find(k=>k.id===b)?.materials,w=M?{...s,materials:{...s.materials,...M}}:s,x;if(!y||y.error!==void 0)x=d1("The configuration is unavailable.");else try{switch(g.kind){case"glue-contact":x=Pt(g,y);break;case"tab-slot":x=Ur(g,y,w);break;case"captured-shaft":x=Br(g,y,w);break;case"material-assignment":x=Wh(y,w);break;case"rigid-clearance":x=Jr(g,y,f);break;case"assembly-access":x=ea(g,y,f);break;case"joint-constraints":{let k=c.find(A=>A.configuration===v[0]);x=k&&k.error===void 0?ca(g,y,k,f,s,i.claims):d1("The kinematic reference configuration is unavailable.");break}case"retention":x=ra(g,y,s,i.claims);break;case"stability":x=aa(g,y,f,i.claims,s);break;case"assembly-support":x=sa(g,y,s,i.claims);break;default:x=d1(`The ${g.kind} capability is not implemented; it cannot inherit a geometric-fit pass.`)}}catch(k){x={status:"unverified",code:"geometry-unresolved",message:`The geometric check could not complete: ${k.message}`}}i.claims.push(Me(g.id,g.kind,g.required!==!1,[b],x,la(g)))}}let p=i.claims.filter(g=>g.required);i.status=p.some(g=>g.status==="fail")?"fail":p.some(g=>g.status==="unverified")?"unverified":"pass";for(let[g,v]of[["retention","Retention of permanent inventory."],["stability","Static stability under declared masses and gravity."],["assembly-access","Authored insertion and tool access paths."],["assembly-support","Support throughout the installation sequence."],["motion-clearance","Continuous nominal operating motion clearance."],["joint-constraints","Mechanism constraints and intended mobility."]]){let b=i.claims.filter(M=>M.kind===g&&M.required),y=new Set(b.filter(M=>M.status==="pass").flatMap(M=>M.configurations));(!b.length||b.some(M=>M.status!=="pass")||s.configurations.some(M=>!y.has(M.id)))&&i.uncovered.push(v)}return{kind:"report",report:i}}function Me(t,e,n,r,a,s=[]){return{id:t,kind:e,required:n,configurations:r,status:"unverified",code:"unverified",message:"",entities:s,measurements:{},assumptions:[],coverage:"none",...a}}function la(t){return t.kind==="glue-contact"?[t.a,t.b]:t.kind==="tab-slot"?[t.tab,t.receiver]:t.kind==="captured-shaft"?[t.shaft,...t.bearings,...t.stack,...t.stops.map(e=>e.body)]:t.kind==="rigid-clearance"?t.bodies??[]:t.kind==="motion-clearance"?t.moving.map(e=>e.body):t.kind==="assembly-access"?[...t.initial,...t.steps.map(e=>e.part)]:t.kind==="retention"?t.roots:t.kind==="stability"?t.loads.map(e=>e.body):t.kind==="joint-constraints"?t.bodies:[]}function Gh(t){if(t.length<2)return d1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return d1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(r=>r.cutLines===null||r.kerf===null)))return d1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(r=>!r.label)))return d1("Cross-pose hardware requires unique native labels.");for(let n of t){let r=n.hardware.map(a=>a.label);if(new Set(r).size!==r.length)return d1("Hardware labels are ambiguous across operating poses.");if(n.parts.length!==e.parts.length||n.hardware.length!==e.hardware.length)return{status:"fail",code:"inventory-changed",message:"Operating motion changed the manufacturing inventory."};for(let a of e.parts){let s=f2(n,{part:a.name,copy:a.copy});if(!s||!At(a,s))return{status:"fail",code:"cut-geometry-changed",message:`Operating motion changed cut geometry/material for ${a.name} copy ${a.copy}.`}}for(let a of e.hardware){let s=n.hardware.find(c=>c.label===a.label);if(!s||a.kind!==s.kind||JSON.stringify(a.size)!==JSON.stringify(s.size)||Math.abs(V1(S1(a.to,a.from))-V1(S1(s.to,s.from)))>Y)return{status:"fail",code:"hardware-changed",message:`Operating motion changed hardware ${a.label}.`}}}return{status:"pass",code:"cuts-invariant",message:"Nominal cut regions, cut lines, materials and inventory agree at the declared poses.",coverage:"discrete",assumptions:["This checks the declared configurations only; it does not bound behavior between samples."]}}function Wh(t,e){if(!t.parts.length)return d1("There are no sheet parts to assign a stock profile.");for(let n of t.parts){let r=e.materials&&Object.prototype.hasOwnProperty.call(e.materials,n.material)?e.materials[n.material]:void 0;if(!r)return d1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<r.thickness[0]-Y||n.thickness>r.thickness[1]+Y)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return d1("Compensation metadata is unavailable.")}return{status:"pass",code:"materials-assigned",message:"Every sheet part has a measured profile containing its nominal design thickness.",coverage:"bounded-fit"}}var Xh=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function Fn(t){if(t.kind!=="report")return[];let e=new Map;for(let r of t.report.claims){if(r.status==="pass")continue;let a=`${r.status}\0${r.code}`,s=e.get(a)??{status:r.status,code:r.code,message:r.message,claims:[]};s.claims.push({id:r.id,configurations:r.configurations,bodies:r.entities.map(Xh),measurements:r.measurements}),e.set(a,s)}let n=r=>r==="fail"?0:1;return[...e.values()].sort((r,a)=>n(r.status)-n(a.status)||a.claims.length-r.claims.length)}function fa(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(a=>a.message).join("; ")}
4336
- `;let e=Fn(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
4337
+ }`)}return a}function Ch(t,e,n){let r;try{r=new K2({maxSteps:2e6}).run(n2(t.check).program).shape}catch{return!1}let a=r.layers.get("cut");if(!a)return!1;let s=d0([e.outline.poly],e.holes.map(l=>l.outline.poly)),c=t1(a.regions),o=n+t.round*16e-5;if(!_e(s,c,o))return!1;let i=e.lines.map(l=>Fe(l));return!(i.length&&!_e(i,a.lines,o,!1))}var Y=.001,o0=(t,e)=>t.reduce((n,r,a)=>n+r*e[a],0),S1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],V1=t=>Math.hypot(...t),$r=t=>[t[2],t[6],t[10]],z0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]+t[n*4+3]),yn=(t,e)=>T1(L0(t.matrix),e.matrix);function qe(t){let[e,n]=t[0],r=0;for(let a=1;a<t.length-1;a++)r+=(t[a][0]-e)*(t[a+1][1]-n)-(t[a][1]-n)*(t[a+1][0]-e);return r/2}var be=t=>Math.abs(t.reduce((e,n)=>e+qe(n),0)),xn=t=>t.reduce((e,n)=>e+n.reduce((r,a,s)=>r+Math.hypot(a[0]-n[(s+1)%n.length][0],a[1]-n[(s+1)%n.length][1]),0),0);function At(t){let e=t.flat();return[Math.min(...e.map(n=>n[0])),Math.min(...e.map(n=>n[1])),Math.max(...e.map(n=>n[0])),Math.max(...e.map(n=>n[1]))]}var Hr=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function Mn(t){if(t.length!==1)return!1;let e=At(t);return be(ze(t,[Hr(e)]))<Y*Y}var wn=(t,e)=>G1(t,[Hr(e)]);function Or(t,e,n=0){let r=e[0]*e[5]-e[1]*e[4]<0;return t.map(a=>{let s=a.map(([c,o])=>z0(e,[c,o,n]).slice(0,2));return r?s.reverse():s})}function Ph(t,e){let n=!1;for(let r=0,a=t.length-1;r<t.length;a=r++){let[s,c]=t[r],[o,i]=t[a];c>e[1]!=i>e[1]&&e[0]<(o-s)*(e[1]-c)/(i-c)+s&&(n=!n)}return n}function z3(t,e,n){let r=n[0]-e[0],a=n[1]-e[1],s=r*r+a*a,c=s?Math.max(0,Math.min(1,((t[0]-e[0])*r+(t[1]-e[1])*a)/s)):0;return Math.hypot(t[0]-e[0]-c*r,t[1]-e[1]-c*a)}function Rr(t,e){let n=1/0;for(let r of t)for(let a=0;a<e.length;a++)n=Math.min(n,z3(r,e[a],e[(a+1)%e.length]));for(let r of e)for(let a=0;a<t.length;a++)n=Math.min(n,z3(r,t[a],t[(a+1)%t.length]));return n}var kn=(t,e)=>t.filter(n=>qe(n)<0&&Ph(n,e));function S3(t){return t.placed?t.bends.length?"Flexible or bent geometry is not supported by this rigid check.":t.folds?.length?"Folded geometry is not supported by this rigid check.":t.cutLines===null?"Nominal cutting-line geometry is unavailable; render with analysis: true.":t.cutLines.length?"Open cutting lines may remove or weaken material; this rigid check cannot model them.":null:"The part has no physical placement."}function Fr(t){return[0,1,2,4,5,6,8,9,10].every(e=>Math.abs(t[e])<1e-9||Math.abs(Math.abs(t[e])-1)<1e-9)}function Lt(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&Ir(t.regions)===Ir(e.regions)&&Vr(t.cutLines)===Vr(e.cutLines)}function Ir(t){let e=n=>{let r=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,a=[r,[...r].reverse()].map(s=>{let c=0;for(let o=1;o<s.length;o++)(s[o][0]<s[c][0]||s[o][0]===s[c][0]&&s[o][1]<s[c][1])&&(c=o);return JSON.stringify([...s.slice(c),...s.slice(0,c)])});return JSON.stringify([Math.sign(qe(n)),a.sort()[0]])};return JSON.stringify(t.map(e).sort())}function Vr(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),r=JSON.stringify([...e].reverse());return n<r?n:r}).sort())}var Y1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),$0=t=>typeof t=="string"&&t.length>0,P2=t=>typeof t=="number"&&Number.isFinite(t),ne=t=>P2(t)&&t>=0,U2=t=>P2(t)&&t>0,De=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(P2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,re=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(P2),C2=t=>re(t,3)&&t.every(e=>Math.abs(e)<=1e7),ye=t=>Y1(t)&&$0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),Ct=t=>Y1(t)&&$0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),A3=t=>ye(t)||Ct(t),te=t=>Array.isArray(t)&&t.every(A3),Ne=t=>C2(t)&&Math.hypot(...t)>1e-9,Eh=t=>Y1(t)&&(t.kind==="translate"&&C2(t.by)||t.kind==="rotate"&&C2(t.origin)&&Ne(t.axis)&&P2(t.angle)&&Math.abs(t.angle)<=1e6),zn=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),_r=t=>Y1(t)&&Object.values(t).every(zn),Dr=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||P2(t)||Array.isArray(t)&&t.every(n=>Dr(n,e+1))),Sn=t=>Y1(t)&&Object.values(t).every(e=>Dr(e)),Th=t=>t===null||Y1(t)&&zn(t.sourceHash)&&zn(t.engineHash)&&_r(t.dependencies)&&_r(t.fonts);function v5(t){let e=[],n=(c,o)=>e.push({code:"invalid-spec",path:c,message:o});if(!Y1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let r=(c,o,i)=>{for(let l of Object.keys(c))o.includes(l)||n(i?`${i}.${l}`:l,"Unknown specification field.")};r(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),$0(t.model)||n("model","Give the model a nonempty name.");let a=new Set,s=(c,o)=>{if(!Y1(c)){n(o,"Materials must map material names to measured profiles.");return}for(let[i,l]of Object.entries(c))(!i||!Y1(l)||!De(l.thickness,Number.MIN_VALUE)||!De(l.kerf)||l.edgeError!==void 0&&!ne(l.edgeError)||l.lot!==void 0&&!$0(l.lot))&&n(`${o}.${i}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),Y1(l)&&r(l,["thickness","kerf","edgeError","lot"],`${o}.${i}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[c,o]of t.configurations.entries())!Y1(o)||!$0(o.id)||o.params!==void 0&&!Sn(o.params)?n(`configurations[${c}]`,"Expected a unique id and finite KerfScript parameter values."):a.has(o.id)?n(`configurations[${c}].id`,"Configuration ids must be unique."):(a.add(o.id),r(o,["id","params","materials"],`configurations[${c}]`),o.materials!==void 0&&s(o.materials,`configurations[${c}].materials`));if(t.materials!==void 0&&s(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let c=new Set,o=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!Y1(h)||!$0(h.id)||!$0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(r(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),c.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),c.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&o++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(m=>typeof m=="string"&&a.has(m)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!ye(h.a)||!ye(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!U2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!ye(h.tab)||!ye(h.receiver)||!re(h.region,4)||h.region.some(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!De(h.clearance)||!ne(h.flushTolerance)||!ne(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let m=h.stops;if(!Ct(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(ye)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(ye)||!De(h.clearance)||!De(h.endplay)||!U2(h.minimumOverlap)||!ne(h.maximumStopGap)||!Array.isArray(m)||m.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let g of m){if(!Y1(g)||!Ct(g.body)||!Y1(g.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}r(g,["body","attachment"],u+".stops");let p=g.attachment;r(p,p.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(p.kind)||p.kind==="threaded"&&(!Ct(p.thread)||!U2(p.minimumEngagement)||typeof p.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!ne(h.minimumGap)||h.bodies!==void 0&&(!te(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!$0(h.from)||!a.has(h.from)||!$0(h.to)||!a.has(h.to)||h.from===h.to||!ne(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(m=>Y1(m)&&A3(m.body)&&Eh(m.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!$0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!te(h.initial)||h.initial.length>1||h.scope!==void 0&&(!te(h.scope)||!h.scope.length)||!ne(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(m=>Y1(m)&&$0(m.id)&&A3(m.part)&&C2(m.from)&&typeof m.held=="boolean"&&(m.fasten===void 0||Array.isArray(m.fasten)&&m.fasten.every($0))&&(m.tool===void 0||Y1(m.tool)&&C2(m.tool.from)&&C2(m.tool.to)&&U2(m.tool.diameter)&&m.tool.diameter<=1e6&&C2(m.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!te(h.roots)||!h.roots.length||h.removable!==void 0&&!te(h.removable)||!Array.isArray(h.links)||!h.links.every(m=>Y1(m)&&$0(m.claim)&&["glued","locked","captured"].includes(m.fastening)&&typeof m.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!te(h.bodies)||!h.bodies.length||!te(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(m=>Y1(m)&&A3(m.a)&&A3(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&C2(m.anchorA)&&C2(m.anchorB)&&Ne(m.axisA)&&Ne(m.axisB)&&(m.range===void 0||De(m.range,-1e6))||m.kind==="prismatic"&&Ne(m.axisA)&&De(m.travel,-1e6)||m.kind==="gear"&&Ne(m.axisA)&&Ne(m.axisB)&&U2(m.ratio)&&m.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!te(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!P2(h.ground)||Math.abs(h.ground)>1e7||!Ne(h.gravity)||h.gravity[2]>=0||!ne(h.minimumMargin)||!h.loads.every(m=>Y1(m)&&A3(m.body)&&U2(m.mass)&&(m.center===void 0||C2(m.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!$0(h.plan)||!$0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(m=>Y1(m)&&$0(m.step)&&te(m.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(m,g,p)=>{Y1(m)&&r(m,g,p)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[m,g]of h.moving.entries())Y1(g)&&(d(g,["body","trajectory"],`${u}.moving[${m}]`),d(g.trajectory,Y1(g.trajectory)&&g.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${m}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[m,g]of h.steps.entries())Y1(g)&&(d(g,["id","part","from","held","fasten","tool"],`${u}.steps[${m}]`),d(g.tool,["from","to","diameter","travel"],`${u}.steps[${m}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[m,g]of h.joints.entries())Y1(g)&&d(g,["kind","a","b",...g.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:g.kind==="prismatic"?["axisA","travel"]:g.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${m}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((m,g)=>d(m,["claim","fastening","installed"],`${u}.links[${g}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((m,g)=>d(m,["body","mass","center"],`${u}.loads[${g}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((m,g)=>d(m,["step","bodies"],`${u}.holds[${g}]`))}o||n("claims","At least one claim must be required.");let i=t.claims.filter(Y1);for(let l of i){let h=(u,f)=>i.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=i.find(g=>g.id===l.plan&&g.kind==="assembly-access"),f=i.find(g=>g.id===l.retention&&g.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(Y1).map(g=>g.id)),m=new Set((Array.isArray(f?.links)?f.links:[]).filter(Y1).map(g=>g.claim));if(Array.isArray(l.holds))for(let g of l.holds)Y1(g)&&!d.has(g.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(g.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let g of u.steps)if(Y1(g)&&Array.isArray(g.fasten))for(let p of g.fasten)m.has(p)||n(`claims.${String(u.id)}.steps`,`Step ${String(g.id)} fastens ${String(p)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(Y1(f)){let d=Y1(f.body)?f.body:{},m=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(m)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(m)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)Y1(u)&&!i.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function An(t){let e=[],n=(a,s)=>e.push({code:"invalid-snapshot",path:a,message:s});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let r=new Set;for(let[a,s]of t.entries()){let c=`snapshots[${a}]`;if(!Y1(s)||s.schemaVersion!==1||!$0(s.configuration)||!Sn(s.params)||!Sn(s.renderSettings)||!Th(s.provenance)||!Array.isArray(s.parts)||!Array.isArray(s.hardware)||!Array.isArray(s.warnings)||!s.warnings.every(i=>typeof i=="string")||typeof s.legacyHardware!="boolean"||typeof s.relationsKnown!="boolean"||s.error!==void 0&&typeof s.error!="string"){n(c,"Malformed snapshot, configuration, provenance or inventory.");continue}r.has(s.configuration)&&n(c,"Configuration snapshots must be unique."),r.add(s.configuration);let o=new Set;for(let[i,l]of s.parts.entries()){if(!Y1(l)||!$0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!U2(l.thickness)||l.glue!==void 0&&(!ye(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!$0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!ne(l.kerf)||l.kerf>1e6)||!Ih(l.matrix)||typeof l.placed!="boolean"||!qr(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!qr(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>Y1(u)&&P2(u.x0)&&P2(u.x1)&&u.x1>u.x0&&P2(u.angle))||l.folds!==void 0&&(!Array.isArray(l.folds)||!l.folds.every(u=>Y1(u)&&re(u.from,2)&&re(u.to,2)&&P2(u.angle)))){n(`${c}.parts[${i}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);o.has(h)&&n(`${c}.parts[${i}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),o.add(h)}for(let[i,l]of s.hardware.entries())(!Y1(l)||l.label!==null&&!$0(l.label)||typeof l.kind!="string"||!re(l.from,3)||!re(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!C2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!U2(l.size))||!(U2(l.size)&&l.size<=1e6||re(l.size,2)&&l.size.every(h=>U2(h)&&h<=1e6)))&&n(`${c}.hardware[${i}]`,"Malformed hardware geometry or label.")}return e}function qr(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>re(r,2)&&r.every(a=>Math.abs(a)<=1e6)))}function Ih(t){if(!re(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(r=>Math.abs(r)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let r=0;r<3;r++)for(let a=0;a<3;a++){let s=e[r]*e[a]+e[4+r]*e[4+a]+e[8+r]*e[8+a];if(Math.abs(s-(r===a?1:0))>n)return!1}return Math.abs(e[0]*(e[5]*e[10]-e[6]*e[9])-e[1]*(e[4]*e[10]-e[6]*e[8])+e[2]*(e[4]*e[9]-e[5]*e[8])-1)<n}function Nr(t){let e=[];for(let n of t.claims){let r=a=>e.push({claim:n.id,ref:a});n.kind==="glue-contact"&&(r(n.a),r(n.b)),n.kind==="tab-slot"&&(r(n.tab),r(n.receiver)),n.kind==="captured-shaft"&&(r(n.shaft),n.bearings.forEach(r),n.stack.forEach(r),n.stops.forEach(a=>{r(a.body),a.attachment.kind==="threaded"&&r(a.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(r),n.kind==="motion-clearance"&&n.moving.forEach(a=>r(a.body)),n.kind==="assembly-access"&&(n.initial.forEach(r),n.scope?.forEach(r),n.steps.forEach(a=>r(a.part))),n.kind==="retention"&&(n.roots.forEach(r),n.removable?.forEach(r)),n.kind==="joint-constraints"&&(n.bodies.forEach(r),n.roots.forEach(r),n.joints.forEach(a=>{r(a.a),r(a.b)})),n.kind==="stability"&&(n.supports.forEach(r),n.loads.forEach(a=>r(a.body))),n.kind==="assembly-support"&&n.holds?.forEach(a=>a.bodies.forEach(r))}return e}var f2=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),B2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var i0=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),d1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),Tn=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),x5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,y5=(t,e)=>x5(t,e)?.thickness??[e.thickness,e.thickness];function L3(t,e){let n=x5(t,e);return n?e.kerf===null?[-1/0,1/0]:[e.kerf-n.kerf[1]-2*(n.edgeError??0),e.kerf-n.kerf[0]+2*(n.edgeError??0)]:[0,0]}var Pn=(t,e)=>t[0]>=e[0]+Y&&t[1]<=e[1]-Y,En=(t,e)=>t[0]<e[0]-Y||t[1]>e[1]+Y,In=(...t)=>t.map(S3).find(Boolean);function Et(t,e){let n=f2(e,t.a),r=f2(e,t.b);if(n===r)return i0("A glue contact needs two different physical instances.");let a=In(n,r);if(a)return d1(a);let s=yn(n,r),c=t.faceA==="top"?n.thickness:0,o=t.faceB==="top"?r.thickness:0;if(Math.hypot(s[8],s[9])>1e-9)return i0("The selected faces are not parallel.");let i=Math.abs(s[11]+s[10]*o-c);if(i>Y)return i0("The selected faces are separated.",{faceGap:i});if(i>1e-7)return d1("Face separation is within numerical uncertainty; exact contact is not established.");let l=t.faceA==="top"?1:-1,h=t.faceB==="top"?1:-1;if(l*h*s[10]>-1+1e-7)return i0("The selected surfaces face the same way, rather than meeting.");let u=Or(r.regions,s,o),f=be(G1(n.regions,u)),d=Y*(xn(n.regions)+xn(u)),m={contactArea:f,requiredArea:t.minimumArea,faceGap:i,areaUncertainty:d};return f<t.minimumArea-d?i0("There is insufficient geometric glue contact.",m):f<t.minimumArea+d?{...d1("Contact area is on the numerical acceptance boundary."),measurements:m}:Tn("The selected nominal faces have the required geometric contact.",m,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function Ur(t,e,n){let r=f2(e,t.tab),a=f2(e,t.receiver);if(r===a)return i0("A tongue and its receiving panel must be different instances.");let s=In(r,a);if(s)return d1(s);let c=yn(a,r);if(!Fr(c)||Math.abs(c[10])>Y)return d1("Only orthogonal tab/slot geometry is supported.");let o=wn(r.regions,t.region);if(!Mn(o))return d1("The selected tongue is not one solid rectangle.");let[i,l,h,u]=At(o),f=4*Y,d=Y,g=[[i-f,l+d,i,u-d],[h,l+d,h+f,u-d],[i+d,l-f,h-d,l],[i+d,u,h-d,u+f]].map(T=>be(wn(r.regions,T))>Y*Y).flatMap((T,O)=>T?[O]:[]);if(g.length>1)return d1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(g.length&&Math.abs(g[0]<2?c[8]:c[9])<.5)return d1("The tongue must join its parent along the insertion direction.");let p;if(g.length){let T=g[0],O=T<2?[T===0?i:h,(l+u)/2,0]:[(i+h)/2,T===2?l:u,0],_=z0(c,O)[2],D=(T<2?c[8]:c[9])*(T%2===0?-1:1);p={z:_,outward:D}}let v=[];for(let T of[i,h])for(let O of[l,u])for(let _ of[0,r.thickness])v.push(z0(c,[T,O,_]));let b=[0,1,2].map(T=>Math.min(...v.map(O=>O[T]))),y=[0,1,2].map(T=>Math.max(...v.map(O=>O[T]))),M=kn(a.regions,[(b[0]+y[0])/2,(b[1]+y[1])/2]);if(!M.length)return i0("The receiving panel has no closed slot at the tongue.");if(M.length!==1||!Mn([M[0]]))return d1("The receiving feature must be an unambiguous rectangular closed slot.");let w=M[0],x=At([w]),k=L3(n,r),A=L3(n,a);if(![...k,...A].every(Number.isFinite))return d1("Compensated kerf metadata is needed for manufacturing bounds.");let L={},z=!1;for(let T=0;T<2;T++){let O=Math.abs(c[T*4+2])>.5,_=O?y5(n,r):[y[T]-b[T]+k[0],y[T]-b[T]+k[1]],D=x[T+2]-x[T],G=[D-A[1]-_[1],D-A[0]-_[0]];if(L[T?"clearanceY":"clearanceX"]=G,En(G,t.clearance))return i0("Tab/slot clearance is outside the required range.",L);z||(z=!Pn(G,t.clearance));let V=b[T],U=y[T];O?c[T*4+2]>0?U+=_[1]-r.thickness:V-=_[1]-r.thickness:(V-=Math.max(0,k[1])/2,U+=Math.max(0,k[1])/2);let J=Math.min(V-x[T],x[T+2]-U)-Math.max(0,A[1])/2;if(L[T?"minimumSideGapY":"minimumSideGapX"]=J,J<-Y)return i0("The tongue is offset into the edge of its slot.",L);J<Y&&(z=!0)}let S=Math.max(0,-k[0])/2,C=y5(n,a);if(t.flushTolerance>=C[0]-Y)return d1("flushTolerance must be smaller than the receiving thickness.");let E=Math.max(0,Math.min(y[2]-S,C[1])-Math.max(b[2]+S,0)),I=C[1]-t.flushTolerance;if(L.engagement=E,L.requiredEngagement=I,E<=Y)return i0("The tongue does not engage the receiving panel.",L);if(E<I-Y)return i0("The tongue does not engage through the receiving panel.",L);if(E<I+Y&&(z=!0),p&&(p.outward>0&&p.z<C[1]-Y||p.outward<0&&p.z>Y))return i0("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",L);let H=Math.min(...a.regions.filter(T=>T!==w).map(T=>Rr(w,T)))-Math.max(0,-A[0]);return L.minimumLigament=H,H<t.minimumLigament-Y?i0("Too little material remains around the slot.",L):(H<t.minimumLigament+Y&&(z=!0),z?{...d1("A fit condition is on its numerical acceptance boundary."),measurements:L}:Tn("The rectangular tongue fits and engages its receiving slot.",L,["Rigid orthogonal parts; nominal placements are held fixed while finished dimensions vary.","The selected local rectangle must identify the physical tongue; this fit does not establish retention."],x5(n,r)||x5(n,a)?"bounded-fit":"nominal"))}function b5(t){let e=S1(t.to,t.from),n=V1(e);return typeof t.size=="number"&&n>Y?{start:t.from,dir:e.map(r=>r/n),length:n,diameter:t.size}:null}function Ln(t,e){let n=b5(e);if(!n||V1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let r=S1(n.start,t.start),a=o0(r,t.dir);return V1(r.map((s,c)=>s-a*t.dir[c]))<Y}var Pt=(t,e)=>o0(S1(e,t.start),t.dir),Cn=(t,e)=>[Pt(t,e.from),Pt(t,e.to)].sort((n,r)=>n-r);function Vh(t,e){let n=$r(e.matrix);if(o0(n,t.dir)<0||V1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let r=z0(L0(e.matrix),t.start),a=[r[0],r[1]],s=kn(e.regions,a);if(!s.length)return"No bore surrounds the shaft axis.";if(s.length!==1)return"The bore selector is ambiguous.";let c=s[0],o=c.length>1&&c[0][0]===c[c.length-1][0]&&c[0][1]===c[c.length-1][1]?c.slice(0,-1):c,i=[o.reduce((g,p)=>g+p[0],0)/o.length,o.reduce((g,p)=>g+p[1],0)/o.length];if(Math.hypot(i[0]-a[0],i[1]-a[1])>Y)return"The shaft is not centered in the bore.";let l=c.map(g=>Math.hypot(g[0]-i[0],g[1]-i[1]));if(Math.max(...l)-Math.min(...l)>Y)return"The bore is not a supported circular polygon.";let h=Math.min(...c.map((g,p)=>z3(a,g,c[(p+1)%c.length]))),u=Math.max(...c.map(g=>Math.hypot(g[0]-a[0],g[1]-a[1]))),f=Pt(t,z0(e.matrix,[0,0,0])),d=Pt(t,z0(e.matrix,[0,0,e.thickness])),m=Math.max(...e.regions.flatMap(g=>g.map(p=>Math.hypot(p[0]-a[0],p[1]-a[1]))));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u],reach:m}}function Br(t,e,n){let r=B2(e,t.shaft),a=b5(r);if(!a)return d1("The shaft must have a nonzero cylindrical physical envelope.");let s=[...t.bearings,...t.stack],c=s.map(x=>JSON.stringify([x.part,x.copy??1]));if(new Set(c).size!==c.length)return i0("Bearing and stack references must name distinct physical parts.");let o=s.map(x=>f2(e,x)),i=In(...o);if(i)return d1(i);let l={shaftDiameter:a.diameter},h=[],u=!1;for(let x=0;x<o.length;x++){let k=o[x],A=Vh(a,k);if(typeof A=="string")return/unsupported|supported/.test(A)?d1(`${k.name}: ${A}`):i0(`${k.name}: ${A}`);let L=L3(n,k);if(!L.every(Number.isFinite))return d1("Kerf metadata is required for bore tolerance bounds.");let z=[A.hole[0]-L[1]-a.diameter,A.hole[1]-L[0]-a.diameter];if(l[`clearance${x+1}`]=z,En(z,t.clearance))return i0(`${k.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!Pn(z,t.clearance)),A.lo<-Y||A.lo+y5(n,k)[1]>a.length+Y)return i0(`${k.name}: the shaft does not extend through this part.`,l);h.push(A)}let f=h.slice(0,2).sort((x,k)=>x.lo-k.lo),d=h.slice(2).sort((x,k)=>x.lo-k.lo);if(f.some(x=>y5(n,x.part).some(k=>Math.abs(k-x.part.thickness)>Y)))return d1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-Y)return i0("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-Y||d[x].hi>f[1].lo+Y||x&&d[x-1].hi>d[x].lo+Y)return i0("The axial stack overlaps another component or its supports.");let m=f[1].lo-f[0].lo,p=[f[0].part,...d.map(x=>x.part)].map(x=>y5(n,x)).reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[0,0]),v=[m-p[1],m-p[0]];if(l.endplay=v,En(v,t.endplay))return i0("The axial stack has insufficient or excessive endplay.",l);u||(u=!Pn(v,t.endplay));let b=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],y=t.stops.map(x=>({stop:x,h:B2(e,x.body)})).map(x=>({...x,at:x.h&&Ln(a,x.h)?Cn(a,x.h):void 0}));if(y.some(x=>!x.at))return i0("A retainer is not coaxial with the shaft.");y.sort((x,k)=>x.at[0]+x.at[1]-(k.at[0]+k.at[1]));let M=x=>x.hole[1]-L3(n,x.part)[0],w=x=>2*x.reach+L3(n,x.part)[0];for(let x=0;x<2;x++){let k=Math.max(w(f[x]),b5(y[x].h)?.diameter??0),A=x===0?d.map((z,S)=>S):d.map((z,S)=>d.length-1-S),L=[];for(let z=0;z<A.length;z++){let S=d[A[z]],C=M(S),E=A.slice(0,z).map((O,_)=>({b:d[O],gone:L[_]})),I=O=>C>O+Y,H=O=>Math.abs(C-O)<=Y,T=I(k)&&E.every(O=>O.gone||I(w(O.b)));if(L.push(T),T)return i0(`${S.part.name} can slide off over ${f[x].part.name} and its retainer: its bore is wider than all that holds it on that side.`,l);(H(k)||E.some(O=>!O.gone&&H(w(O.b))))&&(u=!0)}}for(let x=0;x<2;x++){let{stop:k,h:A}=y[x];if(!Ln(a,A))return i0("A retainer is not coaxial with the shaft.");let L=b5(A),z=Cn(a,A),S=f[x],C=x===0?z[1]:z[0],E=x===0?S.lo:S.hi,I=x===0?E-C:C-E;l[`stopGap${x+1}`]=I;let H=L3(n,S.part),T=(L.diameter-(S.hole[1]-H[0]))/2;if(l[`stopOverlap${x+1}`]=T,I<-Y||I>t.maximumStopGap+Y)return i0("A retainer is misplaced relative to the outside bearing face.",l);if((I<-1e-7||I>t.maximumStopGap+1e-7)&&(u=!0),T<t.minimumOverlap-Y)return i0("A retainer can pass through its bearing opening.",l);T<t.minimumOverlap+Y&&(u=!0);let O=k.attachment;if(O.kind==="unknown")return{...d1("The stop is present but its fastening is unverified."),measurements:l};if(O.kind==="integral"){if(Math.min(Math.abs(C),Math.abs(C-a.length))>Y)return i0("An integral head must meet an end of its shaft.",l);b.push("The specified head and shaft are one integral purchased component.")}else{let _=B2(e,O.thread);if(!Ln(a,_))return i0("The threaded attachment is off the shaft axis.");if(b5(_).diameter>a.diameter+Y)return i0("The declared threaded section exceeds the shaft envelope.");let D=Cn(a,_),G=Math.max(0,Math.min(z[1],D[1])-Math.max(z[0],D[0]));if(D[0]<-Y||D[1]>a.length+Y)return i0("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=G,G<O.minimumEngagement-Y)return i0("The threaded stop has insufficient declared thread engagement.",l);if(G<O.minimumEngagement+Y&&(u=!0),!O.secured)return{...d1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};b.push("The specified usable thread envelope and matching nut are installed and secured as declared; thread form/capacity and resistance to loosening are not verified.")}}return u?{...d1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:Tn("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,b,o.some(x=>x5(n,x))?"bounded-fit":"nominal")}var Tt=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},v1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),G0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],H0=(t,e)=>t.map(n=>n*e),Wr=(t,e)=>t.map((n,r)=>n+e[r]),t0=t=>H0(t,1/V1(t)),Xr=()=>U0(0,0,0);function Vn(t,e){let n=r=>r.kind==="translate"?V1(r.by)<1e-9:Math.abs(r.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?V1(S1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?V1(S1(H0(t0(t.axis),t.angle),H0(t0(e.axis),e.angle)))<1e-9&&V1(G0(S1(t.origin,e.origin),t0(t.axis)))<1e-9:!1}function $h(t,e){let n=new Map;for(let r of e)for(let a=0;a<r.length;a++){let s=r[a],c=r[(a+1)%r.length],o=s<c?[s,c]:[c,s];n.set(o.join(","),o)}return{vertices:t,faces:e,edges:[...n.values()]}}function C3(t,e,n){let r=t.length,a=[];for(let s of[0,e])for(let[c,o]of t)a.push(z0(n,[c,o,s]));return $h(a,[t.map((s,c)=>c).reverse(),t.map((s,c)=>r+c),...t.map((s,c)=>[c,(c+1)%r,(c+1)%r+r,c+r])])}function Hh(t,e){let n=t1(t),r=[...new Set(n.flat().map(o=>o[0]))].sort((o,i)=>o-i),a=n.flatMap(o=>o.map((i,l)=>({a:i,b:o[(l+1)%o.length]}))),s=[],c=(o,i)=>o.a[1]+(i-o.a[0])*(o.b[1]-o.a[1])/(o.b[0]-o.a[0]);for(let o=1;o<r.length;o++){let i=r[o-1],l=r[o],h=(i+l)/2;e.tick(a.length);let u=a.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>c(f,h)-c(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],m=u[f+1],g=[[i,c(d,i)],[l,c(d,l)],[l,c(m,l)],[i,c(m,i)]],p=g.filter((v,b)=>V1([v[0]-g[(b+1)%g.length][0],v[1]-g[(b+1)%g.length][1],0])>1e-10);if(p.length<3||Math.abs(qe(p))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(s.push(p),s.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!s.length||Math.abs(be(s)-be(n))>Y*Y*Math.max(1,be(n)))throw new Error("Rigid decomposition did not preserve material area.");return s}function Ue(t){if(t.hardware.some(n=>!n.label))throw new Error("Physical hardware needs unique labels for whole-inventory checks.");let e=[...t.parts.map(n=>({part:n.name,copy:n.copy})),...t.hardware.map(n=>({hardware:n.label}))];if(new Set(e.map(v1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function M5(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function y0(t,e){if("part"in e)return f2(t,e).matrix;let n=B2(t,e),[r,a]=M5(n),s={...n,from:r,to:a},c=t0(S1(s.to,s.from));if(!V1(S1(s.to,s.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let o=S1(s.up,H0(c,o0(s.up,c)));if(V1(o)<1e-9){if(Array.isArray(s.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(c[0])<.8?[1,0,0]:[0,1,0];o=S1(l,H0(c,o0(l,c)))}o=t0(o);let i=G0(o,c);return[i[0],o[0],c[0],s.from[0],i[1],o[1],c[1],s.from[1],i[2],o[2],c[2],s.from[2],0,0,0,1]}function xe(t,e,n){if(n.tick(),"part"in e){let h=f2(t,e),u=S3(h);if(u)throw new Error(u);let d=Hh(h.regions,n).map(m=>C3(m,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=B2(t,e),a=y0(t,e),[s,c]=M5(r),o=V1(S1(c,s));if(o<Y)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(r.size)){let[h,u]=r.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[C3(f,o,a)];return{ref:e,outer:d,inner:d}}let i=32,l=h=>Array.from({length:i},(u,f)=>[h*Math.cos(f*2*Math.PI/i),h*Math.sin(f*2*Math.PI/i)]);if(r.shape==="ball"){let h=r.size/2,u=h/Math.SQRT2,f=U0(0,0,h-u);return{ref:e,inner:[C3(l(u),2*u,T1(a,f))],outer:[C3(l(h/Math.cos(Math.PI/i)),o,a)]}}return{ref:e,inner:[C3(l(r.size/2),o,a)],outer:[C3(l(r.size/2/Math.cos(Math.PI/i)),o,a)]}}function It(t,e){let n=a=>a.map(s=>({...s,vertices:s.vertices.map(c=>z0(e,c))})),r=n(t.outer);return{ref:t.ref,outer:r,inner:t.inner===t.outer?r:n(t.inner)}}function Be(t,e){if(t.kind==="translate")return U0(...H0(t.by,e));let[n,r,a]=t0(t.axis),s=t.angle*Math.PI/180*e,c=Math.cos(s),o=Math.sin(s),i=1-c,l=[c+n*n*i,n*r*i-a*o,n*a*i+r*o,0,r*n*i+a*o,c+r*r*i,r*a*i-n*o,0,a*n*i-r*o,a*r*i+n*o,c+a*a*i,0,0,0,0,1];return T1(U0(...t.origin),T1(l,U0(...H0(t.origin,-1))))}function $n(t,e){if(e.kind==="translate")return V1(e.by);let n=t0(e.axis),r=0;for(let a of t.outer)for(let s of a.vertices){let c=S1(s,e.origin);r=Math.max(r,V1(S1(c,H0(n,o0(c,n)))))}return Math.abs(e.angle)*Math.PI/180*r}function jr(t){return t.faces.map(e=>G0(S1(t.vertices[e[1]],t.vertices[e[0]]),S1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>V1(e)>1e-12).map(t0)}function Zr(t,e){let n=[...jr(t),...jr(e)];for(let[r,a]of t.edges)for(let[s,c]of e.edges){let o=G0(S1(t.vertices[a],t.vertices[r]),S1(e.vertices[c],e.vertices[s]));V1(o)>1e-12&&n.push(t0(o))}return n}var P3=(t,e)=>{let n=t.vertices.map(r=>o0(r,e));return[Math.min(...n),Math.max(...n)]};function Oh(t,e,n){let r=-1/0;for(let a of Zr(t,e)){n.tick();let s=P3(t,a),c=P3(e,a);r=Math.max(r,c[0]-s[1],s[0]-c[1])}return r}function Rh(t,e){let n=0;for(let r=0;r<3;r++){let a=t.vertices.map(o=>o[r]),s=e.vertices.map(o=>o[r]),c=Math.max(0,Math.min(...s)-Math.max(...a),Math.min(...a)-Math.max(...s));n+=c*c}return Math.sqrt(n)}function Fh(t,e,n,r){let a=S1(n,e),s=S1(r,e),c=S1(t,e),o=o0(a,c),i=o0(s,c);if(o<=0&&i<=0)return V1(c);let l=S1(t,n),h=o0(a,l),u=o0(s,l);if(h>=0&&u<=h)return V1(l);let f=o*u-h*i;if(f<=0&&o>=0&&h<=0)return V1(S1(c,H0(a,o/(o-h))));let d=S1(t,r),m=o0(a,d),g=o0(s,d);if(g>=0&&m<=g)return V1(d);let p=m*i-o*g;if(p<=0&&i>=0&&g<=0)return V1(S1(c,H0(s,i/(i-g))));let v=h*g-m*u;if(v<=0&&u-h>=0&&m-g>=0)return V1(S1(l,H0(S1(r,n),(u-h)/(u-h+m-g))));let b=v+p+f;if(Math.abs(b)<1e-20)return 1/0;let y=Math.max(0,Math.min(1,p/b)),M=Math.max(0,Math.min(1-y,f/b));return V1(S1(c,Wr(H0(a,y),H0(s,M))))}function _h(t,e,n,r){let a=S1(e,t),s=S1(r,n),c=S1(t,n),o=o0(a,a),i=o0(a,s),l=o0(s,s),h=o0(a,c),u=o0(s,c);if(o<1e-20||l<1e-20)return 1/0;let f=o*l-i*i,d=f>1e-20?Math.max(0,Math.min(1,(i*u-l*h)/f)):0,m=(i*d+u)/l;return m<0&&(m=0,d=Math.max(0,Math.min(1,-h/o))),m>1&&(m=1,d=Math.max(0,Math.min(1,(i-h)/o))),V1(Wr(c,S1(H0(a,d),H0(s,m))))}function qh(t,e,n){let r=1/0;for(let[a,s]of[[t,e],[e,t]])for(let c of a.vertices)for(let o of s.faces)for(let i=1;i<o.length-1;i++)n.tick(),r=Math.min(r,Fh(c,s.vertices[o[0]],s.vertices[o[i]],s.vertices[o[i+1]]));for(let[a,s]of t.edges)for(let[c,o]of e.edges)n.tick(),r=Math.min(r,_h(t.vertices[a],t.vertices[s],e.vertices[c],e.vertices[o]));return r}function Gr(t,e,n,r){let a=1/0,s=1/0,c=!1,o=!0;for(let i of t)for(let l of e){n.tick();let h=Rh(i,l);if(h>Math.min(s,r)){a=Math.min(a,h);continue}let u=Oh(i,l,n);u<-Y&&(c=!0),u<0&&(o=!1),a=Math.min(a,Math.max(0,h,u)),u<-Y?s=0:u<=Math.min(s,r)&&(s=Math.min(s,qh(i,l,n)))}return{lower:a,upper:s,penetration:c,touchSafe:o}}function Vt(t,e,n,r){let a=Gr(t.outer,e.outer,n,r+Y),s=t.outer===t.inner&&e.outer===e.inner;if(a.lower>r+Y)return{lower:a.lower-Y,upper:1/0,penetration:!1,touchSafe:!0};let c=s?a:Gr(t.inner,e.inner,n,1/0);return{lower:Math.max(0,a.lower-Y),upper:c.upper+Y,penetration:c.penetration,touchSafe:a.touchSafe}}function Yr(t,e,n,r,a,s){for(let c=0;c<t.outer.length;c++)for(let o=0;o<n.outer.length;o++){let i=t.outer[c],l=n.outer[o],h=e.outer[c],u=r.outer[o],f=!1;for(let d of Zr(i,l)){s.tick();let m=P3(i,d),g=P3(l,d),p=P3(h,d),v=P3(u,d);if(Math.min(g[0]-m[1],v[0]-p[1])>=a||Math.min(m[0]-g[1],p[0]-v[1])>=a){f=!0;break}}if(!f)return!1}return!0}function $t(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let r={part:n.name,copy:n.copy},a=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(a>1&&(n.copy-1)%a!==0){let s=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:r,faceA:s?"bottom":"top",faceB:s?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:r,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var E2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),w5=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<Y);function Kr(t,e,n){if(new Set(e.map(v1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(r=>xe(t,r,n))}function Jr(t,e,n){let r=Kr(e,t.bodies??Ue(e),n);if(r.length<2)return d1("Rigid clearance requires at least two physical bodies.");let a=1/0;for(let s=0;s<r.length;s++)for(let c=s+1;c<r.length;c++){let o=Vt(r[s],r[c],n,t.minimumGap);if(a=Math.min(a,o.lower),o.penetration||o.upper<t.minimumGap-Y)return E2("Physical bodies interfere or violate the required clearance.",{gapUpper:o.upper},[r[s].ref,r[c].ref]);if(!(o.lower>t.minimumGap||t.minimumGap===0&&o.touchSafe))return{...d1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[r[s].ref,r[c].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:a},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function Hn(t,e,n,r,a=1e3){let s=i=>({solid:i,trajectory:{kind:"translate",by:[0,0,0]}});function*c(){for(let i=0;i<t.length;i++){for(let l of e)yield{a:t[i],b:s(l)};for(let l=i+1;l<t.length;l++)yield{a:t[i],b:t[l]}}}let o=0;for(let{a:i,b:l}of c()){r.tick();let h=(d,m)=>It(d.solid,Be(d.trajectory,m));if(Vn(i.trajectory,l.trajectory)){let d=Vt(i.solid,l.solid,r,n);if(d.penetration||d.upper<n-Y)return E2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[i.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...d1("The fixed relative clearance is within geometric uncertainty."),entities:[i.solid.ref,l.solid.ref]}}if(i.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&Yr(h(i,0),h(i,1),h(l,0),h(l,1),n===0?0:n+Y,r))continue;let u=$n(i.solid,i.trajectory)+$n(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++o>a)return{...d1("Continuous clearance interval budget exhausted."),measurements:{intervals:o},entities:[i.solid.ref,l.solid.ref]};r.tick();let[d,m]=f.shift(),g=(d+m)/2,p=u*(m-d)/2,v=Vt(h(i,g),h(l,g),r,n+p);if(v.penetration||v.upper<n-Y)return E2("The specified path has physical interference.",{phase:g,gapUpper:v.upper},[i.solid.ref,l.solid.ref]);if(!(v.lower-p>n)){if(m-d<1e-9)return{...d1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,m]},entities:[i.solid.ref,l.solid.ref]};f.push([d,g],[g,m])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:o},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function Dh(t,e){if(t.parts.length!==e.parts.length||t.hardware.length!==e.hardware.length)return"The physical inventory changes between motion endpoints.";for(let n of t.parts){let r=e.parts.find(a=>a.name===n.name&&a.copy===n.copy);if(!r||n.cutLines===null||r.cutLines===null||!Lt(n,r))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([r.stack,r.glue,r.glueFace,r.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let r=e.hardware.find(a=>a.label===n.label);if(!n.label||!r||n.kind!==r.kind||JSON.stringify(n.size)!==JSON.stringify(r.size)||Math.abs(V1(S1(n.to,n.from))-V1(S1(r.to,r.from)))>Y)return"Hardware identities and dimensions must remain invariant."}return null}function Qr(t,e,n,r,a=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return d1("Motion requires complete cutting and native attachment metadata at both endpoints.");let s=Dh(e,n);if(s)return{status:"fail",code:"motion-inventory",message:s};let c=Ue(e),o=new Set(t.moving.map(l=>v1(l.body)));if(o.size!==t.moving.length)return E2("A body has conflicting simultaneous trajectories.");let i=l=>t.moving.find(h=>v1(h.body)===v1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...$t(e),...a]){let h=T1(L0(y0(e,l.a)),y0(e,l.b)),u=T1(L0(y0(n,l.a)),y0(n,l.b));if(!w5(h,u)||!Vn(i(l.a),i(l.b)))return E2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of c){let h=t.moving.find(f=>v1(f.body)===v1(l))?.trajectory,u=h?Be(h,1):Xr();if("part"in l){if(!w5(T1(u,y0(e,l)),y0(n,l)))return E2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=B2(e,l),d=B2(n,l);if(typeof f.size=="number"){if(!w5(z0(u,f.from),d.from)||!w5(z0(u,f.to),d.to))return E2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!w5(T1(u,y0(e,l)),y0(n,l)))return E2("A box trajectory does not match its rendered destination.",{},[l])}}return Hn(t.moving.map(l=>({solid:xe(e,l.body,r),trajectory:l.trajectory})),Kr(e,c.filter(l=>!o.has(v1(l))),r),t.minimumGap,r,t.maxIntervals)}function ea(t,e,n){let r=t.scope??Ue(e),a=new Set(r.map(v1)),s=new Map(t.initial.map(i=>[v1(i),xe(e,i,n)]));if(a.size!==r.length||s.size!==t.initial.length||t.initial.some(i=>!a.has(v1(i))))return E2("Assembly scope and initial inventory must be unique and consistent.");let c=new Set,o=0;for(let i of t.steps){if(c.has(i.id)||!a.has(v1(i.part))||s.has(v1(i.part)))return E2("An assembly step duplicates or misidentifies a required installation.");if(c.add(i.id),!i.held)return{...d1(`Step ${i.id} needs an explicit temporary holding/support assumption.`),assemblyStep:i.id};let l=xe(e,i.part,n),h=It(l,Be({kind:"translate",by:i.from},1)),u=Hn([{solid:h,trajectory:{kind:"translate",by:i.from.map(f=>-f)}}],[...s.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:i.id,message:`Assembly step ${i.id}: ${u.message}`};if(o+=u.measurements?.intervals??0,s.set(v1(i.part),l),i.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:i.tool.from,to:i.tool.to,size:i.tool.diameter,up:[0,1,0]}]},m=xe(d,{hardware:f},n),g=It(m,Be({kind:"translate",by:i.tool.travel},1)),p=Hn([{solid:g,trajectory:{kind:"translate",by:i.tool.travel.map(v=>-v)}}],[...s.values()],0,n,t.maxIntervals);if(p.status!=="pass")return{...p,assemblyStep:i.id,message:`Tool access at step ${i.id}: ${p.message}`}}}return s.size!==a.size?E2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:s.size,intervals:o},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var l0=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),i2=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),r2=t=>[t[3],t[7],t[11]],On=t=>{let e=t0(t),n=t0(G0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,G0(e,n)]},Ht=(t,e,n)=>{let r=On(n)[0],a=t0(i2(e,r)),s=t0(i2(t,r)),c=t0(i2(e,n));return Math.atan2(o0(c,G0(a,s)),o0(a,s))*180/Math.PI},ta=(t,e,n)=>{let r=[],a=Math.ceil((e[0]-n-t)/360),s=Math.floor((e[1]+n-t)/360);for(let o=a;o<=s&&r.length<64;o++)r.push(t+360*o);let c=(e[0]+e[1])/2;return r.sort((o,i)=>Math.abs(o-c)-Math.abs(i-c))};function na(t,e){if(t?.kind==="glue-contact"&&e==="glued")return[t.a,t.b];if(t?.kind==="captured-shaft"&&e==="captured"){let n=[t.shaft,...t.bearings,...t.stack,...t.stops.map(r=>r.body)];for(let r of t.stops)r.attachment.kind==="threaded"&&n.push(r.attachment.thread);return n}}function ra(t,e,n,r){let a=Ue(e),s=new Set(a.map(v1));for(let f of t.removable??[])s.delete(v1(f));if(t.roots.some(f=>!s.has(v1(f))))return l0("A retention root cannot be excluded as removable.");let c=new Map,o=f=>{for(let d of f)for(let m of f){let g=v1(d),p=c.get(g)??new Set;p.add(v1(m)),c.set(g,p)}},i=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(p=>p.id===f.claim),m=r.find(p=>p.id===f.claim&&p.configurations.includes(e.configuration));if(!d||!m)return d1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(m.status==="fail")return l0(`Attachment ${f.claim} fails its geometric contract.`);if(m.status!=="pass")return d1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return l0(`The fastening for ${f.claim} is explicitly not installed.`);let g=na(d,f.fastening);if(!g)return d1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);o(g),d.kind==="glue-contact"&&i.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(v1)),h=[...l];for(;h.length;)for(let f of c.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=a.filter(f=>s.has(v1(f))&&!l.has(v1(f)));return u.length?{...l0("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:s.size,removableComponents:t.removable?.length??0},assumptions:i}}function Nh(t,e){if("hardware"in e){let o=y0(t,e),i=t.hardware.find(l=>l.label===e.hardware);return z0(o,[0,0,V1(S1(M5(i)[1],M5(i)[0]))/2])}let n=f2(t,e),r=S3(n);if(r)throw new Error(r);let a=0,s=0,c=0;for(let o of n.regions){let[i,l]=o[0],h=0,u=0,f=0;for(let m=0;m<o.length;m++){let g=o[m],p=o[(m+1)%o.length],v=g[0]-i,b=g[1]-l,y=p[0]-i,M=p[1]-l,w=v*M-y*b;h+=w,u+=(v+y)*w,f+=(b+M)*w}if(Math.abs(h)<1e-12)continue;let d=qe(o);a+=d,s+=(i+u/(3*h))*d,c+=(l+f/(3*h))*d}if(a<=Y*Y)throw new Error("Material centroid is numerically unresolved.");return z0(n.matrix,[s/a,c/a,n.thickness/2])}function Uh(t){let e=[...t].sort((c,o)=>c[0]-o[0]||c[1]-o[1]),n=(c,o,i)=>(o[0]-c[0])*(i[1]-c[1])-(o[1]-c[1])*(i[0]-c[0]),r=c=>{let o=[];for(let i of c){for(;o.length>1&&n(o[o.length-2],o[o.length-1],i)<=0;)o.pop();o.push(i)}return o},a=r(e),s=r([...e].reverse());return[...a.slice(0,-1),...s.slice(0,-1)]}function Bh(t,e,n){let r=new Map,a=o=>{for(let i of o)for(let l of o){let h=r.get(v1(i))??new Set;h.add(v1(l)),r.set(v1(i),h)}};for(let o of t.links){let i=na(e.claims.find(l=>l.id===o.claim),o.fastening);i&&a(i)}if(!n.length)return!0;let s=new Set([v1(n[0])]),c=[...s];for(;c.length;)for(let o of r.get(c.pop())??[])s.has(o)||(s.add(o),c.push(o));return n.every(o=>s.has(v1(o)))}function aa(t,e,n,r=[],a){let s=Ue(e),c=t.loads.map(g=>v1(g.body));if(new Set(c).size!==c.length||s.some(g=>!c.includes(v1(g))))return d1("Stability needs one declared positive mass for every physical component.");if(s.length>1){let g=r.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),p=a?.claims.find(v=>v.id===t.retention);if(!g||g.status!=="pass"||!p||p.kind!=="retention"||p.removable?.length)return d1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!Bh(p,a,s))return d1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let o=0,i=[0,0,0];for(let g of t.loads){let p=g.center?z0(y0(e,g.body),g.center):Nh(e,g.body);o+=g.mass,i=i.map((v,b)=>v+g.mass*p[b])}if(!Number.isFinite(o)||!i.every(Number.isFinite))return d1("Mass/centroid calculation exceeds its numerical range.");i=H0(i,1/o);let l=[];for(let g of s){let p=xe(e,g,n),v=Math.min(...p.inner.flatMap(y=>y.vertices.map(M=>M[2]))),b=Math.min(...p.outer.flatMap(y=>y.vertices.map(M=>M[2])));if(v<t.ground-Y)return l0("A physical component penetrates the ground plane.");if(b<t.ground-Y)return d1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(y=>v1(y)===v1(g))){if(Math.abs(v-t.ground)>1e-8)return d1("Ground contact is separated or within physical-envelope uncertainty.");for(let y of p.inner)for(let M of y.vertices)Math.abs(M[2]-t.ground)<1e-8&&l.push([M[0],M[1]])}}let h=Uh(l);if(h.length<3)return d1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-i[2])/t.gravity[2],f=[i[0]+u*t.gravity[0],i[1]+u*t.gravity[1]],d=1/0;for(let g=0;g<h.length;g++){let p=h[g],v=h[(g+1)%h.length],b=(v[0]-p[0])*(f[1]-p[1])-(v[1]-p[1])*(f[0]-p[0]),y=z3(f,p,v);d=Math.min(d,b<0?-y:y)}let m={supportMargin:d,mass:o,centerX:i[0],centerY:i[1],centerZ:i[2]};return d<t.minimumMargin-Y?l0("The gravity line lies outside the required support margin.",m):d<t.minimumMargin+Y?{...d1("Stability is on its numerical support boundary."),measurements:m}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:m,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function sa(t,e,n,r){let a=n.claims.find(d=>d.id===t.plan),s=n.claims.find(d=>d.id===t.retention),c=d=>r.find(m=>m.id===d&&m.configurations.includes(e.configuration));if(!a||a.kind!=="assembly-access"||!s||s.kind!=="retention"||c(t.plan)?.status!=="pass"||c(t.retention)?.status!=="pass")return d1("Assembly support needs verified insertion and retention contracts.");if(s.removable?.length)return d1("Per-step support of removable objects needs an explicit contact model.");let o=new Set(s.roots.map(v1)),i=new Set(a.initial.map(v1));if(a.initial.some(d=>!o.has(v1(d))))return d1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of s.links){let m=n.claims.find(g=>g.id===d.claim);if(m?.kind==="glue-contact")l.set(d.claim,[m.a,m.b]);else if(m?.kind==="captured-shaft"){let g=[m.shaft,...m.bearings,...m.stack,...m.stops.map(p=>p.body)];m.stops.forEach(p=>{p.attachment.kind==="threaded"&&g.push(p.attachment.thread)}),l.set(d.claim,g)}}let h=new Set,u=new Set(a.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return l0("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let p of h)for(let v of l.get(p)??[])for(let b of l.get(p)??[]){let y=d.get(v1(v))??new Set;y.add(v1(b)),d.set(v1(v),y)}let m=new Set([...o].filter(p=>i.has(p))),g=[...m];for(;g.length;)for(let p of d.get(g.pop())??[])m.has(p)||(m.add(p),g.push(p));return m};for(let d of a.steps){i.add(v1(d.part));for(let p of d.fasten??[]){let v=l.get(p);if(!v)return l0(`Step ${d.id} names an unknown fastening.`);if(v.some(b=>!i.has(v1(b))))return l0(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(p)}let m=new Set((t.holds?.find(p=>p.step===d.id)?.bodies??[]).map(v1));if([...m].some(p=>!i.has(p)))return l0(`Step ${d.id} holds an uninstalled body.`);let g=f();if([...i].some(p=>!g.has(p)&&!m.has(p)))return l0(`Step ${d.id} releases a component before it is retained or supported.`)}return[...i].some(d=>!f().has(d))?l0("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function jh(t){let e=t.map(a=>{let s=Math.max(...a.map(Math.abs),1e-20);return a.map(c=>c/s)}),n=0,r=!1;for(let a=0;a<(e[0]?.length??0)&&n<e.length;a++){let s=n;for(let i=n+1;i<e.length;i++)Math.abs(e[i][a])>Math.abs(e[s][a])&&(s=i);let c=Math.abs(e[s][a]);if(c<1e-10)continue;c<1e-7&&(r=!0),[e[n],e[s]]=[e[s],e[n]];let o=e[n][a];for(let i=a;i<e[n].length;i++)e[n][i]/=o;for(let i=n+1;i<e.length;i++){let l=e[i][a];for(let h=a;h<e[i].length;h++)e[i][h]-=l*e[n][h]}n++}return{rank:n,uncertain:r}}function ca(t,e,n,r,a,s=[]){if(t.bodies.length>64)return d1("Joint rank checks support at most 64 scoped rigid bodies.");let c=t.bodies.map(v1),o=t.roots.map(v1);if(new Set(c).size!==c.length||new Set(o).size!==o.length||o.some(v=>!c.includes(v)))return l0("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>y0(e,v).some((b,y)=>Math.abs(b-y0(n,v)[y])>Y)))return l0("A grounded kinematic root changes pose.");let i=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(c.length*6).fill(0),u=(v,b,y,M,w=1)=>{let x=c.indexOf(v1(b));if(x<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[x*6+y+k]+=w*M[k]};for(let v of t.roots)for(let b=0;b<6;b++){let y=h();y[c.indexOf(v1(v))*6+b]=1,i.push(y)}let f=$t({...e,parts:e.parts.filter(v=>c.includes(v1({part:v.name,copy:v.copy})))});for(let v of a?.claims??[])if(v.kind==="retention")for(let b of v.links){let y=a.claims.find(M=>M.id===b.claim);b.installed&&b.fastening==="glued"&&y?.kind==="glue-contact"&&s.some(M=>M.id===y.id&&M.configurations.includes(e.configuration)&&M.status==="pass")&&f.push({a:y.a,b:y.b})}for(let v of f)if(!(!c.includes(v1(v.a))&&!c.includes(v1(v.b)))){if(!c.includes(v1(v.a))||!c.includes(v1(v.b)))return d1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let b=Et({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:Y*Y*4},e);if(b.status!=="pass")return{...b,message:`A native glue/stack bond is not physically established: ${b.message}`}}}let d=[...t.joints,...f.filter(v=>c.includes(v1(v.a))&&c.includes(v1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(r.tick(),v1(v.a)===v1(v.b))return l0("A joint cannot connect a body to itself.");let b=y0(e,v.a),y=y0(e,v.b),M=y0(n,v.a),w=y0(n,v.b),x=T1(L0(b),y),k=T1(L0(M),w),A=z=>{let S=h();u(S,v.b,3,z),u(S,v.a,3,z,-1),i.push(S)},L=(z,S,C)=>{let E=h();u(E,v.b,0,z),u(E,v.a,0,z,-1),u(E,v.b,3,G0(C,z)),u(E,v.a,3,G0(S,z),-1),i.push(E)};if(v.kind==="fixed"){if(x.some((z,S)=>Math.abs(z-k[S])>Y))return l0("A fixed joint changes its relative transform.");l.forEach(z=>A(z)),l.forEach(z=>L(z,S1(r2(y),r2(b)),[0,0,0]))}else if(v.kind==="revolute"){let z=z0(b,v.anchorA),S=z0(y,v.anchorB),C=t0(i2(b,v.axisA)),E=t0(i2(y,v.axisB)),I=o0(t0(i2(M,v.axisA)),t0(i2(w,v.axisB)));if(V1(S1(z,S))>Y||V1(G0(C,E))>1e-7||Math.abs(o0(C,E)-I)>1e-7)return l0("Revolute anchors or axes do not coincide.");if(v.range){let H=Ht(x,k,v.axisB);if(!ta(H,v.range,Y).length)return l0("A revolute joint exceeds its declared angular travel.",{angle:H})}l.forEach(H=>L(H,S1(z,r2(b)),S1(S,r2(y)))),On(C).forEach(A)}else if(v.kind==="prismatic"){let z=S1(r2(x),r2(k)),S=t0(v.axisA),C=o0(z,S);if([0,1,2,4,5,6,8,9,10].some(E=>Math.abs(x[E]-k[E])>Y)||V1(S1(z,H0(S,C)))>Y)return l0("A slider rotates or moves away from its guide axis.");if(C<v.travel[0]-Y||C>v.travel[1]+Y)return l0("The slider exceeds its allowed travel.",{travel:C});l.forEach(A),On(t0(i2(b,v.axisA))).forEach(E=>L(E,S1(r2(y),r2(b)),[0,0,0]))}else{let z=t0(i2(b,v.axisA)),S=t0(i2(y,v.axisB));if(V1(G0(z,S))>1e-7||V1(S1(r2(b),r2(M)))>Y||V1(S1(r2(y),r2(w)))>Y)return l0("The scoped gear axes/centers are not fixed and parallel.");let C=Ht(b,M,v.axisA),E=Ht(y,w,v.axisB);if(Math.abs(C)>90||Math.abs(E)>90)return d1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(E+v.ratio*C)>1e-6)return l0("The rendered gears do not obey their declared angular ratio.");let I=h();u(I,v.a,3,z,v.ratio),u(I,v.b,3,S),i.push(I)}}r.tick(i.length*c.length*6);let m=jh(i),g=c.length*6-m.rank;if(m.uncertain)return d1("Constraint rank is numerically singular.");let p={degreesOfFreedom:g,constraintRank:m.rank,redundantRows:i.length-m.rank};return g!==t.expectedDof?l0("The joint graph has unintended freedom or is overconstrained.",p):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:p,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function oa(t,e,n,r){let a=i=>t.moving.find(l=>v1(l.body)===v1(i))?.trajectory??{kind:"translate",by:[0,0,0]},s=i=>i.kind==="translate"?V1(i.by)<1e-9:Math.abs(i.angle)<1e-9,c=(i,l)=>s(i)&&s(l)?!0:i.kind==="translate"&&l.kind==="translate"?V1(S1(i.by,l.by))<1e-9:i.kind==="rotate"&&l.kind==="rotate"?V1(S1(H0(t0(i.axis),i.angle),H0(t0(l.axis),l.angle)))<1e-9&&V1(G0(S1(i.origin,l.origin),t0(i.axis)))<1e-9:!1;if(e.roots.some(i=>!s(a(i))))return l0("The analytic path moves a grounded joint root.");let o=new Map;for(let i of e.joints.filter(l=>l.kind!=="gear")){if(o.has(v1(i.b)))return d1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");o.set(v1(i.b),v1(i.a))}for(let i of o.keys()){let l=new Set,h=i;for(;h&&o.has(h);){if(l.has(h))return d1("Continuous closed-linkage constraints need a solver.");l.add(h),h=o.get(h)}}for(let i of e.joints){let l=a(i.a),h=a(i.b),u=y0(n,i.a),f=y0(n,i.b);if(i.kind==="fixed"){if(!c(l,h))return l0("The analytic path separates a fixed joint.");continue}if(i.kind==="revolute"){if(c(l,h))continue;if(!s(l)||h.kind!=="rotate")return d1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=z0(u,i.anchorA),m=t0(i2(u,i.axisA)),g=t0(h.axis);if(V1(G0(m,g))>1e-9||V1(G0(S1(h.origin,d),m))>Y)return l0("The trajectory does not rotate about the actual hinge.");if(i.range){let p=T1(L0(u),f),v=T1(L0(y0(r,i.a)),y0(r,i.b)),b=h.angle*o0(t0(i2(f,i.axisB)),g),y=i.range;if(!ta(Ht(p,v,i.axisB),y,Y).some(w=>Math.min(w,w+b)>=y[0]-Y&&Math.max(w,w+b)<=y[1]+Y))return l0("The continuous hinge path exceeds its angular stops.")}}else if(i.kind==="prismatic"){if(c(l,h))continue;if(!s(l)||h.kind!=="translate")return d1("This slider trajectory composition needs a richer constraint solver.");let d=t0(i2(u,i.axisA));if(V1(G0(h.by,d))>Y)return l0("The analytic slider path leaves its guide.");let m=T1(L0(u),f),g=T1(L0(y0(r,i.a)),y0(r,i.b)),p=o0(S1(r2(m),r2(g)),t0(i.axisA)),v=p+o0(h.by,d);if(Math.min(p,v)<i.travel[0]-Y||Math.max(p,v)>i.travel[1]+Y)return l0("The continuous slider path exceeds its travel stops.")}else{let d=(p,v,b)=>{if(s(v))return 0;if(v.kind!=="rotate")return null;let y=y0(n,p),M=t0(i2(y,b));return V1(G0(t0(v.axis),M))>1e-9||V1(G0(S1(v.origin,r2(y)),M))>Y?null:v.angle*o0(t0(v.axis),M)},m=d(i.a,l,i.axisA),g=d(i.b,h,i.axisB);if(m===null||g===null)return d1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(g+i.ratio*m)>1e-7)return l0("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function Rn(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return ia(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(r=>{let a=n?.parts.filter(l=>l.name===r.name),s=a?.length===1?a[0]:void 0,c=s?.glue?.host,i=(c?t.assembly.filter(l=>l.name===c):[]).length===(s?.qty??0)/(s?.stack??1)?Math.floor((r.copy-1)/(s?.stack??1))+1:1;return{name:r.name,copy:r.copy,thickness:r.thickness,material:r.material??"",matrix:r.matrix,placed:r.placed,regions:s?.cutRegions??r.outline,bends:r.bends??[],...r.folds?.length&&{folds:r.folds},kerf:s?.kerf??null,cutLines:s?.cutLines??null,...s?.stack&&{stack:s.stack},...c&&{glue:{part:c,copy:i},glueFace:s.glue.face},...s?.on&&{on:s.on}}}),hardware:t.hardware.map(r=>({label:r.label??null,kind:r.kind,from:r.from,to:r.to,size:r.size,up:r.up,...r.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(r=>r.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function ia(t){if(t&&typeof t=="object"){for(let e of Object.values(t))ia(e);Object.freeze(t)}return t}function Fn(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=v5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(r.length)throw new Error(r[0].message);let a=new Map;for(let s of e){let c=s.body,o=v1(c);if(("part"in c?t.assembly.filter(l=>l.name===c.part&&l.copy===(c.copy??1)).length:t.hardware.filter(l=>l.label===c.hardware).length)!==1||a.has(o))throw new Error("Pose controls must identify one unique physical instance each.");a.set(o,Be(s.trajectory,n))}return{...t,assembly:t.assembly.map(s=>{let c=a.get(v1({part:s.name,copy:s.copy}));return c?{...s,matrix:T1(c,s.matrix)}:s}),hardware:t.hardware.map(s=>{let c={hardware:s.label??""},o=a.get(v1(c));return o?{...s,from:z0(o,s.from),to:z0(o,s.to),up:S1(z0(o,s.up),z0(o,[0,0,0]))}:s})}}function ha(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==Y||v5(e).length||An(n).length||n.some(a=>a.error!==void 0||!a.provenance)||!Array.isArray(t.inputs))return!1;let r=a=>JSON.stringify(a,(s,c)=>c&&typeof c=="object"&&!Array.isArray(c)?Object.fromEntries(Object.keys(c).sort().map(o=>[o,c[o]])):c);try{let a=n.map(c=>({configuration:c.configuration,params:c.params,renderSettings:c.renderSettings,provenance:c.provenance})),s=c=>[...c].sort((o,i)=>o.configuration.localeCompare(i.configuration));return r(e)===r(t.specification)&&r(s(a))===r(s(t.inputs))}catch{return!1}}function ua(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let r=v5(t);if(r.length)return{kind:"invalid-spec",issues:r};let a=An(e);if(a.length)return{kind:"invalid-snapshot",issues:a};let s=t,c=e,o=[];for(let[p,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(p)||!Number.isSafeInteger(v)||!(v>0))&&o.push({code:"invalid-limits",path:`limits.${p}`,message:"Verification limits must be positive safe integers."});if(o.length)return{kind:"invalid-spec",issues:o};let i={schemaVersion:1,model:s.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:Y,specification:JSON.parse(JSON.stringify(s)),claims:[],inputs:JSON.parse(JSON.stringify(c.map(p=>({configuration:p.configuration,params:p.params,renderSettings:p.renderSettings,provenance:p.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(c.reduce((p,v)=>p+v.hardware.reduce((b,y)=>b+(typeof y.size=="number"?128:8),0)+v.parts.reduce((b,y)=>b+y.regions.reduce((M,w)=>M+w.length,0)+(y.cutLines??[]).reduce((M,w)=>M+w.length,0),0),0)>(n.maxPoints??2e5)||s.claims.length>(n.maxClaims??1e3)||s.configurations.length>(n.maxConfigurations??100))return i.claims.push(Me("$resource-limit","resource-limit",!0,[],{status:"unverified",code:"resource-limit",message:"The verification input exceeds its point, claim or configuration budget. No mechanical conclusions were reached."})),{kind:"report",report:i};let h=new Set(s.configurations.map(p=>p.id));for(let p of c)h.has(p.configuration)||o.push({code:"unknown-configuration",message:`Snapshot ${p.configuration} is not declared.`});for(let p of c){let v=s.configurations.find(b=>b.id===p.configuration)?.params??{};for(let[b,y]of Object.entries(v))JSON.stringify(p.params[b])!==JSON.stringify(y)&&o.push({code:"configuration-mismatch",message:`${p.configuration}: captured parameter ${b} differs from its required value.`})}let u=new Map(s.claims.map(p=>[p.id,p]));for(let{claim:p,ref:v}of Nr(s)){let b=u.get(p);for(let y of c.filter(M=>M.error===void 0&&(!b.configurations||b.configurations.includes(M.configuration)))){let M="part"in v?y.parts.filter(w=>w.name===v.part&&w.copy===(v.copy??1)):y.hardware.filter(w=>w.label===v.hardware);M.length!==1&&o.push({code:"ambiguous-reference",path:`claims.${p}`,message:`${y.configuration}: ${JSON.stringify(v)} resolves to ${M.length} instances; exactly one is required.`})}}if(o.length)return{kind:"invalid-spec",issues:o};for(let p of s.configurations){let v=c.find(y=>y.configuration===p.id),b=v&&v.error===void 0;i.claims.push(Me(`$configuration:${p.id}`,"configuration",!0,[p.id],b?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),b&&(i.claims.push(Me(`$provenance:${p.id}`,"provenance",!0,[p.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&i.claims.push(Me(`$compiler:${p.id}`,"compiler-diagnostics",!0,[p.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
4338
+ `)})),v.legacyHardware&&i.claims.push(Me(`$legacy:${p.id}`,"hardware-inventory",!0,[p.id],{status:"unverified",code:"legacy-hardware",message:"echo hardware is not authoritative physical inventory. Migrate it to native hardware before verification."})))}let f=new Tt(n.maxOperations),d=p=>p.kind==="retention"?3:p.kind==="stability"||p.kind==="assembly-support"?4:p.kind==="motion-clearance"||p.kind==="assembly-access"?2:p.kind==="joint-constraints"?1:0,m=[...s.claims].sort((p,v)=>d(p)-d(v));for(let p of m){let v=p.configurations??s.configurations.map(b=>b.id);if(p.kind==="cut-invariant"){let b=v.map(y=>c.find(M=>M.configuration===y));i.claims.push(Me(p.id,p.kind,p.required!==!1,v,b.some(y=>!y||y.error!==void 0)?d1("A required configuration is unavailable."):Gh(b)));continue}if(p.kind==="motion-clearance"){let b=c.find(w=>w.configuration===p.from),y=c.find(w=>w.configuration===p.to),M;if(!b||!y||b.error!==void 0||y.error!==void 0)M=d1("Motion endpoints are unavailable.");else try{if(M={status:"pass"},p.constraints){let w=s.claims.find(k=>k.id===p.constraints),x=i.claims.filter(k=>k.id===p.constraints);if(!w||w.kind!=="joint-constraints"||!x.length||x.some(k=>k.status!=="pass")||![p.from,p.to].every(k=>x.some(A=>A.configurations.includes(k))))M=d1("The motion needs verified endpoint joint constraints.");else{let k=c.find(A=>A.configuration===(w.configurations??s.configurations.map(L=>L.id))[0]);M=oa(p,w,b,k)}}if(M.status==="pass"){let w=[];for(let x of s.claims)if(x.kind==="retention")for(let k of x.links){let A=s.claims.find(L=>L.id===k.claim);k.installed&&k.fastening==="glued"&&A?.kind==="glue-contact"&&[p.from,p.to].every(L=>i.claims.some(z=>z.id===A.id&&z.configurations.includes(L)&&z.status==="pass"))&&w.push({a:A.a,b:A.b})}M=Qr(p,b,y,f,w)}}catch(w){M={status:"unverified",code:"geometry-unresolved",message:w.message}}i.claims.push(Me(p.id,p.kind,p.required!==!1,[p.from,p.to],M,la(p)));continue}for(let b of v){let y=c.find(k=>k.configuration===b),M=s.configurations.find(k=>k.id===b)?.materials,w=M?{...s,materials:{...s.materials,...M}}:s,x;if(!y||y.error!==void 0)x=d1("The configuration is unavailable.");else try{switch(p.kind){case"glue-contact":x=Et(p,y);break;case"tab-slot":x=Ur(p,y,w);break;case"captured-shaft":x=Br(p,y,w);break;case"material-assignment":x=Wh(y,w);break;case"rigid-clearance":x=Jr(p,y,f);break;case"assembly-access":x=ea(p,y,f);break;case"joint-constraints":{let k=c.find(A=>A.configuration===v[0]);x=k&&k.error===void 0?ca(p,y,k,f,s,i.claims):d1("The kinematic reference configuration is unavailable.");break}case"retention":x=ra(p,y,s,i.claims);break;case"stability":x=aa(p,y,f,i.claims,s);break;case"assembly-support":x=sa(p,y,s,i.claims);break;default:x=d1(`The ${p.kind} capability is not implemented; it cannot inherit a geometric-fit pass.`)}}catch(k){x={status:"unverified",code:"geometry-unresolved",message:`The geometric check could not complete: ${k.message}`}}i.claims.push(Me(p.id,p.kind,p.required!==!1,[b],x,la(p)))}}let g=i.claims.filter(p=>p.required);i.status=g.some(p=>p.status==="fail")?"fail":g.some(p=>p.status==="unverified")?"unverified":"pass";for(let[p,v]of[["retention","Retention of permanent inventory."],["stability","Static stability under declared masses and gravity."],["assembly-access","Authored insertion and tool access paths."],["assembly-support","Support throughout the installation sequence."],["motion-clearance","Continuous nominal operating motion clearance."],["joint-constraints","Mechanism constraints and intended mobility."]]){let b=i.claims.filter(M=>M.kind===p&&M.required),y=new Set(b.filter(M=>M.status==="pass").flatMap(M=>M.configurations));(!b.length||b.some(M=>M.status!=="pass")||s.configurations.some(M=>!y.has(M.id)))&&i.uncovered.push(v)}return{kind:"report",report:i}}function Me(t,e,n,r,a,s=[]){return{id:t,kind:e,required:n,configurations:r,status:"unverified",code:"unverified",message:"",entities:s,measurements:{},assumptions:[],coverage:"none",...a}}function la(t){return t.kind==="glue-contact"?[t.a,t.b]:t.kind==="tab-slot"?[t.tab,t.receiver]:t.kind==="captured-shaft"?[t.shaft,...t.bearings,...t.stack,...t.stops.map(e=>e.body)]:t.kind==="rigid-clearance"?t.bodies??[]:t.kind==="motion-clearance"?t.moving.map(e=>e.body):t.kind==="assembly-access"?[...t.initial,...t.steps.map(e=>e.part)]:t.kind==="retention"?t.roots:t.kind==="stability"?t.loads.map(e=>e.body):t.kind==="joint-constraints"?t.bodies:[]}function Gh(t){if(t.length<2)return d1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return d1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(r=>r.cutLines===null||r.kerf===null)))return d1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(r=>!r.label)))return d1("Cross-pose hardware requires unique native labels.");for(let n of t){let r=n.hardware.map(a=>a.label);if(new Set(r).size!==r.length)return d1("Hardware labels are ambiguous across operating poses.");if(n.parts.length!==e.parts.length||n.hardware.length!==e.hardware.length)return{status:"fail",code:"inventory-changed",message:"Operating motion changed the manufacturing inventory."};for(let a of e.parts){let s=f2(n,{part:a.name,copy:a.copy});if(!s||!Lt(a,s))return{status:"fail",code:"cut-geometry-changed",message:`Operating motion changed cut geometry/material for ${a.name} copy ${a.copy}.`}}for(let a of e.hardware){let s=n.hardware.find(c=>c.label===a.label);if(!s||a.kind!==s.kind||JSON.stringify(a.size)!==JSON.stringify(s.size)||Math.abs(V1(S1(a.to,a.from))-V1(S1(s.to,s.from)))>Y)return{status:"fail",code:"hardware-changed",message:`Operating motion changed hardware ${a.label}.`}}}return{status:"pass",code:"cuts-invariant",message:"Nominal cut regions, cut lines, materials and inventory agree at the declared poses.",coverage:"discrete",assumptions:["This checks the declared configurations only; it does not bound behavior between samples."]}}function Wh(t,e){if(!t.parts.length)return d1("There are no sheet parts to assign a stock profile.");for(let n of t.parts){let r=e.materials&&Object.prototype.hasOwnProperty.call(e.materials,n.material)?e.materials[n.material]:void 0;if(!r)return d1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<r.thickness[0]-Y||n.thickness>r.thickness[1]+Y)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return d1("Compensation metadata is unavailable.")}return{status:"pass",code:"materials-assigned",message:"Every sheet part has a measured profile containing its nominal design thickness.",coverage:"bounded-fit"}}var Xh=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function _n(t){if(t.kind!=="report")return[];let e=new Map;for(let r of t.report.claims){if(r.status==="pass")continue;let a=`${r.status}\0${r.code}`,s=e.get(a)??{status:r.status,code:r.code,message:r.message,claims:[]};s.claims.push({id:r.id,configurations:r.configurations,bodies:r.entities.map(Xh),measurements:r.measurements}),e.set(a,s)}let n=r=>r==="fail"?0:1;return[...e.values()].sort((r,a)=>n(r.status)-n(a.status)||a.claims.length-r.claims.length)}function fa(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(a=>a.message).join("; ")}
4339
+ `;let e=_n(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
4337
4340
  `;let n=a=>Array.isArray(a)?`${+a[0].toFixed(3)}..${+a[1].toFixed(3)}`:`${+a.toFixed(3)}`,r=[];for(let a of e){r.push(`${a.status} ${a.code} (${a.claims.length}): ${a.message}`);for(let s of a.claims){let c=Object.entries(s.measurements).slice(0,4).map(([o,i])=>`${o} ${n(i)}`).join(", ");r.push(` ${s.id}${s.configurations.length?` [${s.configurations.join(", ")}]`:""}${s.bodies.length?`: ${s.bodies.join(" / ")}`:""}${c?`; ${c}`:""}`)}}return r.join(`
4338
4341
  `)+`
4339
- `}var Zh=t=>{let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]-t[n][0])*(t[r][1]+t[n][1]);return e},d2=(t,e,n)=>(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x),E3=(t,e)=>t.x===e.x&&t.y===e.y;function qn(t,e,n){let r={i:t,x:e,y:n};return r.prev=r,r.next=r,r}function Yh(t,e){return t&&(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e),e}function da(t,e,n){let r=null,a=Zh(t)>0===n;for(let s=0;s<t.length;s++){let c=a?s:t.length-1-s;r=Yh(r,qn(e+c,t[c][0],t[c][1]))}if(r&&E3(r,r.next)){let s=r.next;Ht(r),r=s}return r?r.next:null}function Ht(t){t.next.prev=t.prev,t.prev.next=t.next}function _n(t,e){let n=e??t,r=t,a;do if(a=!1,E3(r,r.next)||E3(r.prev,r.next)){if(Ht(r),r=n=r.prev,r===r.next)break;a=!0}else r=r.next;while(a||r!==n);return n}function Kh(t,e){let n=qn(t.i,t.x,t.y),r=qn(e.i,e.x,e.y),a=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=a,a.prev=n,r.next=n,n.prev=r,s.next=r,r.prev=s,r}function Dn(t,e,n,r,a,s,c,o){return(n-t)*(o-e)-(r-e)*(c-t)>=0&&(a-n)*(o-r)-(s-r)*(c-n)>=0&&(t-a)*(o-s)-(e-s)*(c-a)>=0}function Jh(t,e){return d2(t.prev,t,t.next)>0?d2(t,e,t.next)<=0&&d2(t,t.prev,e)<=0:d2(t,e,t.prev)>0||d2(t,t.next,e)>0}function Qh(t,e){let n=t.x,r=t.y,a=e,s=-1/0,c=null;do{if(r<=a.y&&r>=a.next.y&&a.next.y!==a.y){let u=a.x+(r-a.y)*(a.next.x-a.x)/(a.next.y-a.y);if(u<=n&&u>s&&(s=u,c=a.x<a.next.x?a:a.next,u===n))return c}a=a.next}while(a!==e);if(!c)return null;let o=c,i=c.x,l=c.y,h=1/0;a=c;do{if(n>=a.x&&a.x>=i&&n!==a.x&&(r<l?Dn(n,r,i,l,s,r,a.x,a.y):Dn(s,r,i,l,n,r,a.x,a.y))){let u=Math.abs(r-a.y)/(n-a.x);Jh(a,t)&&(u<h||u===h&&(a.x>c.x||a.x===c.x&&d2(c.prev,c,a.prev)>0&&d2(a.next,c,c.next)>0))&&(c=a,h=u)}a=a.next}while(a!==o);return c}function eu(t){let e=t.prev,n=t.next;if(d2(e,t,n)<=0)return!1;for(let r=n.next;r!==e;r=r.next)if(!E3(r,e)&&!E3(r,n)&&!E3(r,t)&&Dn(e.x,e.y,t.x,t.y,n.x,n.y,r.x,r.y)&&d2(r.prev,r,r.next)<=0)return!1;return!0}function Ot(t,e=[]){let n=[];if(t.length<3)return n;let r=da(t,0,!0);if(!r||r===r.next)return n;let a=t.length,s=[];for(let h of e){let u=h.length>=3?da(h,a,!1):null;if(a+=h.length,!u||u===u.next)continue;let f=u,d=u;do(d.x<f.x||d.x===f.x&&d.y<f.y)&&(f=d),d=d.next;while(d!==u);s.push(f)}s.sort((h,u)=>h.x-u.x||h.y-u.y);for(let h of s){let u=Qh(h,r);if(!u)continue;let f=Kh(u,h);_n(f,f.next),r=_n(u,u.next)}let c=_n(r),o=0,i=c;do o++,i=i.next;while(i!==c);let l=0;for(;o>3;){if(eu(c)){n.push([c.prev.i,c.i,c.next.i]);let h=c.next;Ht(c),o--,c=h,l=0;continue}if(c=c.next,++l>o){let h=c,u=c;do d2(u.prev,u,u.next)>d2(h.prev,h,h.next)&&(h=u),u=u.next;while(u!==c);d2(h.prev,h,h.next)>0&&n.push([h.prev.i,h.i,h.next.i]);let f=h.next;Ht(h),o--,c=f,l=0}}return o===3&&d2(c.prev,c,c.next)>0&&n.push([c.prev.i,c.i,c.next.i]),n}var tu=[[/frosted/i,"#e6eef0"],[/vellum|tracing|parchment|rice paper/i,"#f3efe2"],[/walnut|dark/i,"#7b5538"],[/cherry|mahogany|red/i,"#a0613f"],[/oak/i,"#c9a571"],[/mdf|hardboard/i,"#b4966c"],[/cork/i,"#c49a6c"],[/felt|leather/i,"#8a6a52"],[/card|paper/i,"#ece6d8"],[/black/i,"#2b2b2b"],[/white/i,"#f1f1ee"],[/green/i,"#4f8a4b"],[/blue/i,"#3f6fa8"],[/yellow/i,"#e3c13b"],[/orange/i,"#e07b2e"],[/purple|violet/i,"#7b4f9e"],[/pink/i,"#e58fae"],[/gr[ae]y|silver/i,"#9a9a9a"],[/gold/i,"#c9a227"],[/brown/i,"#7a5534"],[/clear|acrylic|perspex|glass/i,"#cfe6ee"]];function jn(t){let e=/#[0-9a-f]{6}(?![0-9a-f])/i.exec(t);return e?e[0].toLowerCase():tu.find(([n])=>n.test(t))?.[1]??"#dcc39a"}var nu=t=>/clear|acrylic|perspex|glass/i.test(t)&&!ba(t),ba=t=>/vellum|tracing|parchment|rice paper|frosted|translucent|\bpaper\b/i.test(t),ma=.01,Nn=(t,[e,n,r])=>[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]],ya=t=>t[0]*(t[5]*t[10]-t[6]*t[9])-t[1]*(t[4]*t[10]-t[6]*t[8])+t[2]*(t[4]*t[9]-t[5]*t[8]),pa=(t,e)=>z1(t)>0===e?t:[...t].reverse();function Un(t,e,n,r,a,s){let[c,...o]=e;if(!c||c.length<3)return;let i=[pa(c,!0),...o.map(p=>pa(p,!1))],l=i.flat(),h=Ot(i[0],i.slice(1));if(!h.length)return;let u=l.length,f=t.positions.length/3;for(let[p,g]of l)t.positions.push(...a([p,g,n]));for(let[p,g]of l)t.positions.push(...a([p,g,r]));let d=(p,g,v)=>s?t.indices.push(p,v,g):t.indices.push(p,g,v);for(let[p,g,v]of h)d(f+u+p,f+u+g,f+u+v),d(f+v,f+g,f+p);let m=0;for(let p of i){for(let g=0;g<p.length;g++){let v=f+m+g,b=f+m+(g+1)%p.length;d(v,b,b+u),d(v,b+u,v+u)}m+=p.length}}var Bn=(t,e,n,r,a={})=>({name:t,kind:e,material:n,color:r,positions:[],indices:[],...a});function ru(t,e,n,r){let a=[];for(let s of t.marks??[]){if(r.has(s.layer))continue;let c=s.mode==="line"?[...s.lines,...s.regions.map(l=>[...l,l[0]])]:s.lines,o=t1([...s.mode==="fill"?s.regions:[],...G2(c,n)]),i=G1(o,e);i.length&&a.push({layer:s.layer,color:s.color,side:s.side,regions:i})}return a}function Gn(t,e,n,r,a,s,c,o){let i=t.thickness,l=(t.marks??[]).filter(v=>a.has(v.layer)&&v.side==="front"),h=l.length?d0(t.outline,G2(l.flatMap(v=>v.lines),n.slitWidth)):t.outline;if(r&&t.folds?.length)return Ce(h,t.folds,i).flatMap(b=>Gn({...t,folds:void 0,outline:b.outline,marks:t.marks?.map(y=>({...y}))},T1(e,b.matrix),n,r,a,s,c,b.outline));let u=r?t.bends:void 0,f=v=>Nn(e,u?.length?Ae(u,i,v):v),d=ya(e)<0,m=t.material??"material",p=[],g=Bn(t.name,"part",m,t.paint??jn(m),{part:t.name,copy:t.copy,instance:s,clear:!t.paint&&nu(m),translucent:!t.paint&&ba(m)});for(let v of Pe(h,u))Un(g,v,0,i,f,d);if(p.push(g),n.markHeight>0)for(let v of ru(t,o??h,n.lineWidth,a)){if(v.side==="back"&&n.layout==="flat")continue;let b=c?.(v.side);if(b===null)continue;for(let x of b??[])v.regions=d0(v.regions,x);if(!v.regions.length)continue;let[y,M]=v.side==="front"?[i-ma,i+n.markHeight]:[-n.markHeight,ma],w=Bn(`${t.name} ${v.layer}`,"mark",v.layer,v.color,{part:t.name,copy:t.copy,instance:s});for(let x of Pe(v.regions,u))Un(w,x,y,M,f,d);w.indices.length&&p.push(w)}return p}function ga(t){let e=X2[t.kind],n=le[t.kind]??e?.color??"#c8c8c8",r=Bn(t.label??t.kind,"hardware",t.kind,n,{metal:e?.metal,clear:t.kind==="glass",...e?.glow&&{glow:!0},...e?.translucent&&{translucent:!0}}),a=t.to.map((d,m)=>d-t.from[m]),s=Math.hypot(...a),c=Array.isArray(t.size)?t.size:[t.size,t.size];if(t.sides===0&&!Array.isArray(t.size)&&t.size>0){let d=t.size/2,m=12,p=24;for(let g=0;g<=m;g++)for(let v=0;v<p;v++){let b=Math.PI*g/m,y=2*Math.PI*v/p;r.positions.push(t.from[0]+d*Math.sin(b)*Math.cos(y),t.from[1]+d*Math.sin(b)*Math.sin(y),t.from[2]+d*Math.cos(b))}for(let g=0;g<m;g++)for(let v=0;v<p;v++){let b=g*p+v,y=g*p+(v+1)%p;r.indices.push(b,b+p,y+p,b,y+p,y)}return r}if(!(s>0)||!(c[0]>0))return null;let{axis:o,u:i,v:l}=c4(t),h=Array.isArray(t.size)?4:Math.min(128,Math.max(3,Math.floor(t.sides)||24)),u=Array.isArray(t.size)?[[-c[0]/2,-c[1]/2],[c[0]/2,-c[1]/2],[c[0]/2,c[1]/2],[-c[0]/2,c[1]/2]]:Array.from({length:h},(d,m)=>{let p=2*Math.PI*m/h;return[c[0]/2*Math.sin(p),c[0]/2*Math.cos(p)]});return Un(r,[u],0,s,([d,m,p])=>[t.from[0]+d*i[0]+m*l[0]+p*o[0],t.from[1]+d*i[1]+m*l[1]+p*o[1],t.from[2]+d*i[2]+m*l[2]+p*o[2]],!1),r}var au=t=>{let[e,n,r,a]=[1/0,1/0,-1/0,-1/0];for(let s of t.outline)for(let[c,o]of s)e=Math.min(e,c),n=Math.min(n,o),r=Math.max(r,c),a=Math.max(a,o);return[e,n,r,a]};function su(t,e){return xa(t.map(au),e)}function xa(t,e){let n=t.reduce((l,[h,u,f,d])=>l+(f-h+e)*(d-u+e),0),r=Math.max(Math.sqrt(n)*1.3,...t.map(([l,,h])=>h-l)),a=t.map((l,h)=>h).sort((l,h)=>t[h][3]-t[h][1]-(t[l][3]-t[l][1])),s=new Array(t.length),c=0,o=0,i=0;for(let l of a){let[h,u,f,d]=t[l];c>0&&c+(f-h)>r&&(c=0,o+=i+e,i=0),s[l]=[1,0,0,c-h,0,1,0,o-u,0,0,1,0,0,0,0,1],c+=f-h+e,i=Math.max(i,d-u)}return s}function va(t){let[e,n,r,,a,s,c,,o,i,l]=t,h=e*(s*l-c*i)-n*(a*l-c*o)+r*(a*i-s*o),u=[(s*l-c*i)/h,(r*i-n*l)/h,(n*c-r*s)/h,(c*o-a*l)/h,(e*l-r*o)/h,(r*a-e*c)/h,(a*i-s*o)/h,(n*o-e*i)/h,(e*s-n*a)/h],[f,d,m]=[t[3],t[7],t[11]];return[u[0],u[1],u[2],-(u[0]*f+u[1]*d+u[2]*m),u[3],u[4],u[5],-(u[3]*f+u[4]*d+u[5]*m),u[6],u[7],u[8],-(u[6]*f+u[7]*d+u[8]*m),0,0,0,1]}function cu(t,e,n){let r=t.assembly,a=f=>{let d=new Set,m=f;for(;r[m].glued!==void 0&&r[r[m].glued]&&!d.has(m);)d.add(m),m=r[m].glued;return m},s=new Map;r.forEach((f,d)=>{if(!f.outline.length)return;let m=a(d);s.set(m,[...s.get(m)??[],d])});let c=[];for(let[f,d]of s)if(d.length>1&&d.some(m=>r[m].bends?.length))for(let m of d)c.push({root:m,members:[m]});else c.push({root:f,members:d});let o=.001,i=c.map(({root:f,members:d})=>{let m=va(r[f].matrix),p=new Map(d.map(w=>[w,T1(m,r[w].matrix)])),[g,v,b,y,M]=[1/0,1/0,1/0,-1/0,-1/0];for(let w of d)for(let x of r[w].outline)for(let[k,A]of x)for(let L of[0,r[w].thickness]){let[z,S,C]=Nn(p.get(w),[k,A,L]);[g,v,b]=[Math.min(g,z),Math.min(v,S),Math.min(b,C)],[y,M]=[Math.max(y,z),Math.max(M,S)]}return{members:d,local:p,box:[g,v,y,M],z0:b}}),l=xa(i.map(f=>f.box),e.gap),h=(f,d,m)=>{if(Math.abs(Math.abs(f[10])-1)>o)return;let p=m==="front"?d:0,g=f[10]>0==(m==="front");return{height:f[11]+f[10]*p,up:g}},u=[];return i.forEach(({members:f,local:d,z0:m},p)=>{let g=T1(l[p],[1,0,0,0,0,1,0,0,0,0,1,-m,0,0,0,1]);for(let v of f){let b=r[v],y=d.get(v),M=w=>{let x=h(y,b.thickness,w);if(!x)return[];if(!x.up&&Math.abs(x.height-m)<o)return null;let k=va(y),A=[];for(let L of f){if(L===v)continue;let z=d.get(L);for(let S of["front","back"]){let C=h(z,r[L].thickness,S);if(!C||C.up===x.up||Math.abs(C.height-x.height)>o)continue;let E=S==="front"?r[L].thickness:0,I=T1(k,z),H=ya(I)<0;A.push(t1(r[L].outline.map(T=>{let O=T.map(([_,D])=>{let[G,V]=Nn(I,[_,D,E]);return[G,V]});return H?O.reverse():O})))}}return A};u.push(...Gn(b,T1(g,y),e,!1,n,p,M))}}),u}function Rt(t,e={}){let n={layout:e.layout??"assembled",markHeight:e.markHeight??.1,lineWidth:e.lineWidth??.3,hardware:e.hardware??!0,gap:e.gap??5,slitWidth:e.slitWidth??.2},r=new Set((t.layers??[{name:"cut",mode:"cut"}]).filter(i=>i.mode==="cut").map(i=>i.name));if(n.layout==="print"&&t.assembly.length)return cu(t,n,r);let a=n.layout!=="assembled"||!t.assembly.length,s=(a?t.flat??t.assembly:t.assembly).filter(i=>i.outline.length),c=a?su(s,n.gap):s.map(i=>i.matrix),o=s.flatMap((i,l)=>Gn(i,c[l],{...n,layout:a?"flat":"assembled"},!a,r,l));if(!a&&n.hardware){for(let i of t.hardware??[]){let l=ga(i);l&&o.push(l)}for(let i of t.lights??[])if(i.flicker){let l=ga({kind:"flame",from:i.from,to:i.from,size:6,up:[0,0,1],sides:0,step:i.step});l&&o.push({...l,name:i.label??"flame",material:"flame",color:i.color,glow:!0})}}return o}var ou=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}return t})();function iu(t){let e=4294967295;for(let n=0;n<t.length;n++)e=ou[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function Ma(t){let e=new TextEncoder,n=[],r=[],a=0,s=0,c=23585;for(let f of t){let d=e.encode(f.name),m=iu(f.data),p=new DataView(new ArrayBuffer(30));p.setUint32(0,67324752,!0),p.setUint16(4,20,!0),p.setUint16(6,2048,!0),p.setUint16(8,0,!0),p.setUint16(10,s,!0),p.setUint16(12,c,!0),p.setUint32(14,m,!0),p.setUint32(18,f.data.length,!0),p.setUint32(22,f.data.length,!0),p.setUint16(26,d.length,!0),p.setUint16(28,0,!0),n.push(new Uint8Array(p.buffer),d,f.data);let g=new DataView(new ArrayBuffer(46));g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint16(8,2048,!0),g.setUint16(10,0,!0),g.setUint16(12,s,!0),g.setUint16(14,c,!0),g.setUint32(16,m,!0),g.setUint32(20,f.data.length,!0),g.setUint32(24,f.data.length,!0),g.setUint16(28,d.length,!0),g.setUint32(42,a,!0),r.push(new Uint8Array(g.buffer),d),a+=30+d.length+f.data.length}let o=r.reduce((f,d)=>f+d.length,0),i=new DataView(new ArrayBuffer(22));i.setUint32(0,101010256,!0),i.setUint16(8,t.length,!0),i.setUint16(10,t.length,!0),i.setUint32(12,o,!0),i.setUint32(16,a,!0);let l=[...n,...r,new Uint8Array(i.buffer)],h=new Uint8Array(l.reduce((f,d)=>f+d.length,0)),u=0;for(let f of l)h.set(f,u),u+=f.length;return h}var Zn=t=>{let e=/^#?([0-9a-f]{6})$/i.exec(t.trim()),n=e?parseInt(e[1],16):13158600;return[n>>16&255,n>>8&255,n&255]},Wn=t=>{let e=(Math.abs(t)<5e-7?0:t).toFixed(4);return e.includes(".")?e.replace(/\.?0+$/,""):e},Ft=t=>t.copy&&t.copy>1?`${t.name} (${t.copy})`:t.name;function wa(t,e,n,r){let a=t[n*3]-t[e*3],s=t[n*3+1]-t[e*3+1],c=t[n*3+2]-t[e*3+2],o=t[r*3]-t[e*3],i=t[r*3+1]-t[e*3+1],l=t[r*3+2]-t[e*3+2],h=s*l-c*i,u=c*o-a*l,f=a*i-s*o,d=Math.hypot(h,u,f)||1;return[h/d,u/d,f/d]}function Yn(t){let e=t.reduce((s,c)=>s+c.indices.length/3,0),n=new DataView(new ArrayBuffer(84+50*e)),r=new TextEncoder().encode("KerfScript model, millimetres");new Uint8Array(n.buffer).set(r.slice(0,80)),n.setUint32(80,e,!0);let a=84;for(let s of t)for(let c=0;c<s.indices.length;c+=3){let[o,i,l]=[s.indices[c],s.indices[c+1],s.indices[c+2]];for(let h of wa(s.positions,o,i,l))n.setFloat32(a,h,!0),a+=4;for(let h of[o,i,l])for(let u=0;u<3;u++)n.setFloat32(a,s.positions[h*3+u],!0),a+=4;a+=2}return new Uint8Array(n.buffer)}var Xn=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function Kn(t){let e=[],n=h=>{let u=`${h.material}\0${h.color}`,f=e.indexOf(u);return f<0&&(f=e.push(u)-1),f},r=[],a=[],s=new Map;t.forEach((h,u)=>{let f=h.instance===void 0?`h${u}`:`p${h.instance}`;s.set(f,[...s.get(f)??[],h])});let c=2;for(let h of s.values()){let u=[];for(let f of h){let d=[];for(let p=0;p<f.positions.length;p+=3)d.push(`<vertex x="${Wn(f.positions[p])}" y="${Wn(f.positions[p+1])}" z="${Wn(f.positions[p+2])}"/>`);let m=[];for(let p=0;p<f.indices.length;p+=3)m.push(`<triangle v1="${f.indices[p]}" v2="${f.indices[p+1]}" v3="${f.indices[p+2]}"/>`);r.push(`<object id="${c}" type="model" name="${Xn(Ft(f))}" pid="1" pindex="${n(f)}"><mesh><vertices>${d.join("")}</vertices><triangles>${m.join("")}</triangles></mesh></object>`),u.push(c++)}u.length===1?a.push(`<item objectid="${u[0]}"/>`):(r.push(`<object id="${c}" type="model" name="${Xn(Ft(h[0]))}"><components>${u.map(f=>`<component objectid="${f}"/>`).join("")}</components></object>`),a.push(`<item objectid="${c++}"/>`))}let i=`<?xml version="1.0" encoding="UTF-8"?>
4340
- <model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"><metadata name="Application">KerfScript</metadata><resources><basematerials id="1">${e.map(h=>{let[u,f]=h.split("\0"),[d,m,p]=Zn(f),g=[d,m,p].map(v=>v.toString(16).padStart(2,"0")).join("").toUpperCase();return`<base name="${Xn(u)}" displaycolor="#${g}FF"/>`}).join("")}</basematerials>${r.join("")}</resources><build>${a.join("")}</build></model>
4341
- `,l=new TextEncoder;return Ma([{name:"[Content_Types].xml",data:l.encode(`<?xml version="1.0" encoding="UTF-8"?>
4342
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml"/></Types>
4343
- `)},{name:"_rels/.rels",data:l.encode(`<?xml version="1.0" encoding="UTF-8"?>
4342
+ `}var Zh=t=>{let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]-t[n][0])*(t[r][1]+t[n][1]);return e},d2=(t,e,n)=>(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x),E3=(t,e)=>t.x===e.x&&t.y===e.y;function Dn(t,e,n){let r={i:t,x:e,y:n};return r.prev=r,r.next=r,r}function Yh(t,e){return t&&(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e),e}function da(t,e,n){let r=null,a=Zh(t)>0===n;for(let s=0;s<t.length;s++){let c=a?s:t.length-1-s;r=Yh(r,Dn(e+c,t[c][0],t[c][1]))}if(r&&E3(r,r.next)){let s=r.next;Ot(r),r=s}return r?r.next:null}function Ot(t){t.next.prev=t.prev,t.prev.next=t.next}function qn(t,e){let n=e??t,r=t,a;do if(a=!1,E3(r,r.next)||E3(r.prev,r.next)){if(Ot(r),r=n=r.prev,r===r.next)break;a=!0}else r=r.next;while(a||r!==n);return n}function Kh(t,e){let n=Dn(t.i,t.x,t.y),r=Dn(e.i,e.x,e.y),a=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=a,a.prev=n,r.next=n,n.prev=r,s.next=r,r.prev=s,r}function Nn(t,e,n,r,a,s,c,o){return(n-t)*(o-e)-(r-e)*(c-t)>=0&&(a-n)*(o-r)-(s-r)*(c-n)>=0&&(t-a)*(o-s)-(e-s)*(c-a)>=0}function Jh(t,e){return d2(t.prev,t,t.next)>0?d2(t,e,t.next)<=0&&d2(t,t.prev,e)<=0:d2(t,e,t.prev)>0||d2(t,t.next,e)>0}function Qh(t,e){let n=t.x,r=t.y,a=e,s=-1/0,c=null;do{if(r<=a.y&&r>=a.next.y&&a.next.y!==a.y){let u=a.x+(r-a.y)*(a.next.x-a.x)/(a.next.y-a.y);if(u<=n&&u>s&&(s=u,c=a.x<a.next.x?a:a.next,u===n))return c}a=a.next}while(a!==e);if(!c)return null;let o=c,i=c.x,l=c.y,h=1/0;a=c;do{if(n>=a.x&&a.x>=i&&n!==a.x&&(r<l?Nn(n,r,i,l,s,r,a.x,a.y):Nn(s,r,i,l,n,r,a.x,a.y))){let u=Math.abs(r-a.y)/(n-a.x);Jh(a,t)&&(u<h||u===h&&(a.x>c.x||a.x===c.x&&d2(c.prev,c,a.prev)>0&&d2(a.next,c,c.next)>0))&&(c=a,h=u)}a=a.next}while(a!==o);return c}function eu(t){let e=t.prev,n=t.next;if(d2(e,t,n)<=0)return!1;for(let r=n.next;r!==e;r=r.next)if(!E3(r,e)&&!E3(r,n)&&!E3(r,t)&&Nn(e.x,e.y,t.x,t.y,n.x,n.y,r.x,r.y)&&d2(r.prev,r,r.next)<=0)return!1;return!0}function Rt(t,e=[]){let n=[];if(t.length<3)return n;let r=da(t,0,!0);if(!r||r===r.next)return n;let a=t.length,s=[];for(let h of e){let u=h.length>=3?da(h,a,!1):null;if(a+=h.length,!u||u===u.next)continue;let f=u,d=u;do(d.x<f.x||d.x===f.x&&d.y<f.y)&&(f=d),d=d.next;while(d!==u);s.push(f)}s.sort((h,u)=>h.x-u.x||h.y-u.y);for(let h of s){let u=Qh(h,r);if(!u)continue;let f=Kh(u,h);qn(f,f.next),r=qn(u,u.next)}let c=qn(r),o=0,i=c;do o++,i=i.next;while(i!==c);let l=0;for(;o>3;){if(eu(c)){n.push([c.prev.i,c.i,c.next.i]);let h=c.next;Ot(c),o--,c=h,l=0;continue}if(c=c.next,++l>o){let h=c,u=c;do d2(u.prev,u,u.next)>d2(h.prev,h,h.next)&&(h=u),u=u.next;while(u!==c);d2(h.prev,h,h.next)>0&&n.push([h.prev.i,h.i,h.next.i]);let f=h.next;Ot(h),o--,c=f,l=0}}return o===3&&d2(c.prev,c,c.next)>0&&n.push([c.prev.i,c.i,c.next.i]),n}var tu=[[/frosted/i,"#e6eef0"],[/vellum|tracing|parchment|rice paper/i,"#f3efe2"],[/walnut|dark/i,"#7b5538"],[/cherry|mahogany|red/i,"#a0613f"],[/oak/i,"#c9a571"],[/mdf|hardboard/i,"#b4966c"],[/cork/i,"#c49a6c"],[/felt|leather/i,"#8a6a52"],[/card|paper/i,"#ece6d8"],[/black/i,"#2b2b2b"],[/white/i,"#f1f1ee"],[/green/i,"#4f8a4b"],[/blue/i,"#3f6fa8"],[/yellow/i,"#e3c13b"],[/orange/i,"#e07b2e"],[/purple|violet/i,"#7b4f9e"],[/pink/i,"#e58fae"],[/gr[ae]y|silver/i,"#9a9a9a"],[/gold/i,"#c9a227"],[/brown/i,"#7a5534"],[/clear|acrylic|perspex|glass/i,"#cfe6ee"]];function Gn(t){let e=/#[0-9a-f]{6}(?![0-9a-f])/i.exec(t);return e?e[0].toLowerCase():tu.find(([n])=>n.test(t))?.[1]??"#dcc39a"}var nu=t=>/clear|acrylic|perspex|glass/i.test(t)&&!ba(t),ba=t=>/vellum|tracing|parchment|rice paper|frosted|translucent|\bpaper\b/i.test(t),ma=.01,Un=(t,[e,n,r])=>[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]],ya=t=>t[0]*(t[5]*t[10]-t[6]*t[9])-t[1]*(t[4]*t[10]-t[6]*t[8])+t[2]*(t[4]*t[9]-t[5]*t[8]),pa=(t,e)=>z1(t)>0===e?t:[...t].reverse();function Bn(t,e,n,r,a,s){let[c,...o]=e;if(!c||c.length<3)return;let i=[pa(c,!0),...o.map(g=>pa(g,!1))],l=i.flat(),h=Rt(i[0],i.slice(1));if(!h.length)return;let u=l.length,f=t.positions.length/3;for(let[g,p]of l)t.positions.push(...a([g,p,n]));for(let[g,p]of l)t.positions.push(...a([g,p,r]));let d=(g,p,v)=>s?t.indices.push(g,v,p):t.indices.push(g,p,v);for(let[g,p,v]of h)d(f+u+g,f+u+p,f+u+v),d(f+v,f+p,f+g);let m=0;for(let g of i){for(let p=0;p<g.length;p++){let v=f+m+p,b=f+m+(p+1)%g.length;d(v,b,b+u),d(v,b+u,v+u)}m+=g.length}}var jn=(t,e,n,r,a={})=>({name:t,kind:e,material:n,color:r,positions:[],indices:[],...a});function ru(t,e,n,r){let a=[];for(let s of t.marks??[]){if(r.has(s.layer))continue;let c=s.mode==="line"?[...s.lines,...s.regions.map(l=>[...l,l[0]])]:s.lines,o=t1([...s.mode==="fill"?s.regions:[],...G2(c,n)]),i=G1(o,e);i.length&&a.push({layer:s.layer,color:s.color,side:s.side,regions:i})}return a}function Wn(t,e,n,r,a,s,c,o){let i=t.thickness,l=(t.marks??[]).filter(v=>a.has(v.layer)&&v.side==="front"),h=l.length?d0(t.outline,G2(l.flatMap(v=>v.lines),n.slitWidth)):t.outline;if(r&&t.folds?.length)return Ce(h,t.folds,i).flatMap(b=>Wn({...t,folds:void 0,outline:b.outline,marks:t.marks?.map(y=>({...y}))},T1(e,b.matrix),n,r,a,s,c,b.outline));let u=r?t.bends:void 0,f=v=>Un(e,u?.length?Ae(u,i,v):v),d=ya(e)<0,m=t.material??"material",g=[],p=jn(t.name,"part",m,t.paint??Gn(m),{part:t.name,copy:t.copy,instance:s,clear:!t.paint&&nu(m),translucent:!t.paint&&ba(m)});for(let v of Pe(h,u))Bn(p,v,0,i,f,d);if(g.push(p),n.markHeight>0)for(let v of ru(t,o??h,n.lineWidth,a)){if(v.side==="back"&&n.layout==="flat")continue;let b=c?.(v.side);if(b===null)continue;for(let x of b??[])v.regions=d0(v.regions,x);if(!v.regions.length)continue;let[y,M]=v.side==="front"?[i-ma,i+n.markHeight]:[-n.markHeight,ma],w=jn(`${t.name} ${v.layer}`,"mark",v.layer,v.color,{part:t.name,copy:t.copy,instance:s});for(let x of Pe(v.regions,u))Bn(w,x,y,M,f,d);w.indices.length&&g.push(w)}return g}function ga(t){let e=X2[t.kind],n=le[t.kind]??e?.color??"#c8c8c8",r=jn(t.label??t.kind,"hardware",t.kind,n,{metal:e?.metal,clear:t.kind==="glass",...e?.glow&&{glow:!0},...e?.translucent&&{translucent:!0}}),a=t.to.map((d,m)=>d-t.from[m]),s=Math.hypot(...a),c=Array.isArray(t.size)?t.size:[t.size,t.size];if(t.sides===0&&!Array.isArray(t.size)&&t.size>0){let d=t.size/2,m=12,g=24;for(let p=0;p<=m;p++)for(let v=0;v<g;v++){let b=Math.PI*p/m,y=2*Math.PI*v/g;r.positions.push(t.from[0]+d*Math.sin(b)*Math.cos(y),t.from[1]+d*Math.sin(b)*Math.sin(y),t.from[2]+d*Math.cos(b))}for(let p=0;p<m;p++)for(let v=0;v<g;v++){let b=p*g+v,y=p*g+(v+1)%g;r.indices.push(b,b+g,y+g,b,y+g,y)}return r}if(!(s>0)||!(c[0]>0))return null;let{axis:o,u:i,v:l}=o4(t),h=Array.isArray(t.size)?4:Math.min(128,Math.max(3,Math.floor(t.sides)||24)),u=Array.isArray(t.size)?[[-c[0]/2,-c[1]/2],[c[0]/2,-c[1]/2],[c[0]/2,c[1]/2],[-c[0]/2,c[1]/2]]:Array.from({length:h},(d,m)=>{let g=2*Math.PI*m/h;return[c[0]/2*Math.sin(g),c[0]/2*Math.cos(g)]});return Bn(r,[u],0,s,([d,m,g])=>[t.from[0]+d*i[0]+m*l[0]+g*o[0],t.from[1]+d*i[1]+m*l[1]+g*o[1],t.from[2]+d*i[2]+m*l[2]+g*o[2]],!1),r}var au=t=>{let[e,n,r,a]=[1/0,1/0,-1/0,-1/0];for(let s of t.outline)for(let[c,o]of s)e=Math.min(e,c),n=Math.min(n,o),r=Math.max(r,c),a=Math.max(a,o);return[e,n,r,a]};function su(t,e){return xa(t.map(au),e)}function xa(t,e){let n=t.reduce((l,[h,u,f,d])=>l+(f-h+e)*(d-u+e),0),r=Math.max(Math.sqrt(n)*1.3,...t.map(([l,,h])=>h-l)),a=t.map((l,h)=>h).sort((l,h)=>t[h][3]-t[h][1]-(t[l][3]-t[l][1])),s=new Array(t.length),c=0,o=0,i=0;for(let l of a){let[h,u,f,d]=t[l];c>0&&c+(f-h)>r&&(c=0,o+=i+e,i=0),s[l]=[1,0,0,c-h,0,1,0,o-u,0,0,1,0,0,0,0,1],c+=f-h+e,i=Math.max(i,d-u)}return s}function va(t){let[e,n,r,,a,s,c,,o,i,l]=t,h=e*(s*l-c*i)-n*(a*l-c*o)+r*(a*i-s*o),u=[(s*l-c*i)/h,(r*i-n*l)/h,(n*c-r*s)/h,(c*o-a*l)/h,(e*l-r*o)/h,(r*a-e*c)/h,(a*i-s*o)/h,(n*o-e*i)/h,(e*s-n*a)/h],[f,d,m]=[t[3],t[7],t[11]];return[u[0],u[1],u[2],-(u[0]*f+u[1]*d+u[2]*m),u[3],u[4],u[5],-(u[3]*f+u[4]*d+u[5]*m),u[6],u[7],u[8],-(u[6]*f+u[7]*d+u[8]*m),0,0,0,1]}function cu(t,e,n){let r=t.assembly,a=f=>{let d=new Set,m=f;for(;r[m].glued!==void 0&&r[r[m].glued]&&!d.has(m);)d.add(m),m=r[m].glued;return m},s=new Map;r.forEach((f,d)=>{if(!f.outline.length)return;let m=a(d);s.set(m,[...s.get(m)??[],d])});let c=[];for(let[f,d]of s)if(d.length>1&&d.some(m=>r[m].bends?.length))for(let m of d)c.push({root:m,members:[m]});else c.push({root:f,members:d});let o=.001,i=c.map(({root:f,members:d})=>{let m=va(r[f].matrix),g=new Map(d.map(w=>[w,T1(m,r[w].matrix)])),[p,v,b,y,M]=[1/0,1/0,1/0,-1/0,-1/0];for(let w of d)for(let x of r[w].outline)for(let[k,A]of x)for(let L of[0,r[w].thickness]){let[z,S,C]=Un(g.get(w),[k,A,L]);[p,v,b]=[Math.min(p,z),Math.min(v,S),Math.min(b,C)],[y,M]=[Math.max(y,z),Math.max(M,S)]}return{members:d,local:g,box:[p,v,y,M],z0:b}}),l=xa(i.map(f=>f.box),e.gap),h=(f,d,m)=>{if(Math.abs(Math.abs(f[10])-1)>o)return;let g=m==="front"?d:0,p=f[10]>0==(m==="front");return{height:f[11]+f[10]*g,up:p}},u=[];return i.forEach(({members:f,local:d,z0:m},g)=>{let p=T1(l[g],[1,0,0,0,0,1,0,0,0,0,1,-m,0,0,0,1]);for(let v of f){let b=r[v],y=d.get(v),M=w=>{let x=h(y,b.thickness,w);if(!x)return[];if(!x.up&&Math.abs(x.height-m)<o)return null;let k=va(y),A=[];for(let L of f){if(L===v)continue;let z=d.get(L);for(let S of["front","back"]){let C=h(z,r[L].thickness,S);if(!C||C.up===x.up||Math.abs(C.height-x.height)>o)continue;let E=S==="front"?r[L].thickness:0,I=T1(k,z),H=ya(I)<0;A.push(t1(r[L].outline.map(T=>{let O=T.map(([_,D])=>{let[G,V]=Un(I,[_,D,E]);return[G,V]});return H?O.reverse():O})))}}return A};u.push(...Wn(b,T1(p,y),e,!1,n,g,M))}}),u}function Ft(t,e={}){let n={layout:e.layout??"assembled",markHeight:e.markHeight??.1,lineWidth:e.lineWidth??.3,hardware:e.hardware??!0,gap:e.gap??5,slitWidth:e.slitWidth??.2},r=new Set((t.layers??[{name:"cut",mode:"cut"}]).filter(i=>i.mode==="cut").map(i=>i.name));if(n.layout==="print"&&t.assembly.length)return cu(t,n,r);let a=n.layout!=="assembled"||!t.assembly.length,s=(a?t.flat??t.assembly:t.assembly).filter(i=>i.outline.length),c=a?su(s,n.gap):s.map(i=>i.matrix),o=s.flatMap((i,l)=>Wn(i,c[l],{...n,layout:a?"flat":"assembled"},!a,r,l));if(!a&&n.hardware){for(let i of t.hardware??[]){let l=ga(i);l&&o.push(l)}for(let i of t.lights??[])if(i.flicker){let l=ga({kind:"flame",from:i.from,to:i.from,size:6,up:[0,0,1],sides:0,step:i.step});l&&o.push({...l,name:i.label??"flame",material:"flame",color:i.color,glow:!0})}}return o}var ou=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}return t})();function iu(t){let e=4294967295;for(let n=0;n<t.length;n++)e=ou[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function Ma(t){let e=new TextEncoder,n=[],r=[],a=0,s=0,c=23585;for(let f of t){let d=e.encode(f.name),m=iu(f.data),g=new DataView(new ArrayBuffer(30));g.setUint32(0,67324752,!0),g.setUint16(4,20,!0),g.setUint16(6,2048,!0),g.setUint16(8,0,!0),g.setUint16(10,s,!0),g.setUint16(12,c,!0),g.setUint32(14,m,!0),g.setUint32(18,f.data.length,!0),g.setUint32(22,f.data.length,!0),g.setUint16(26,d.length,!0),g.setUint16(28,0,!0),n.push(new Uint8Array(g.buffer),d,f.data);let p=new DataView(new ArrayBuffer(46));p.setUint32(0,33639248,!0),p.setUint16(4,20,!0),p.setUint16(6,20,!0),p.setUint16(8,2048,!0),p.setUint16(10,0,!0),p.setUint16(12,s,!0),p.setUint16(14,c,!0),p.setUint32(16,m,!0),p.setUint32(20,f.data.length,!0),p.setUint32(24,f.data.length,!0),p.setUint16(28,d.length,!0),p.setUint32(42,a,!0),r.push(new Uint8Array(p.buffer),d),a+=30+d.length+f.data.length}let o=r.reduce((f,d)=>f+d.length,0),i=new DataView(new ArrayBuffer(22));i.setUint32(0,101010256,!0),i.setUint16(8,t.length,!0),i.setUint16(10,t.length,!0),i.setUint32(12,o,!0),i.setUint32(16,a,!0);let l=[...n,...r,new Uint8Array(i.buffer)],h=new Uint8Array(l.reduce((f,d)=>f+d.length,0)),u=0;for(let f of l)h.set(f,u),u+=f.length;return h}var Zn=t=>{let e=/^#?([0-9a-f]{6})$/i.exec(t.trim()),n=e?parseInt(e[1],16):13158600;return[n>>16&255,n>>8&255,n&255]},Xn=t=>{let e=(Math.abs(t)<5e-7?0:t).toFixed(4);return e.includes(".")?e.replace(/\.?0+$/,""):e},T3=t=>t.copy&&t.copy>1?`${t.name} (${t.copy})`:t.name;function wa(t,e,n,r){let a=t[n*3]-t[e*3],s=t[n*3+1]-t[e*3+1],c=t[n*3+2]-t[e*3+2],o=t[r*3]-t[e*3],i=t[r*3+1]-t[e*3+1],l=t[r*3+2]-t[e*3+2],h=s*l-c*i,u=c*o-a*l,f=a*i-s*o,d=Math.hypot(h,u,f)||1;return[h/d,u/d,f/d]}function Yn(t){let e=t.reduce((s,c)=>s+c.indices.length/3,0),n=new DataView(new ArrayBuffer(84+50*e)),r=new TextEncoder().encode("KerfScript model, millimetres");new Uint8Array(n.buffer).set(r.slice(0,80)),n.setUint32(80,e,!0);let a=84;for(let s of t)for(let c=0;c<s.indices.length;c+=3){let[o,i,l]=[s.indices[c],s.indices[c+1],s.indices[c+2]];for(let h of wa(s.positions,o,i,l))n.setFloat32(a,h,!0),a+=4;for(let h of[o,i,l])for(let u=0;u<3;u++)n.setFloat32(a,s.positions[h*3+u],!0),a+=4;a+=2}return new Uint8Array(n.buffer)}var _t=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function Kn(t){let e=[],n=f=>{let d=`${f.material}\0${f.color}`,m=e.indexOf(d);return m<0&&(m=e.push(d)-1),m},r=[],a=[],s=[],c=(f,d)=>`<metadata key="${f}" value="${_t(String(d))}"/>`,o=new Map;t.forEach((f,d)=>{let m=f.instance===void 0?`h${d}`:`p${f.instance}`;o.set(m,[...o.get(m)??[],f])});let i=2;for(let f of o.values()){let d=[],m=[];for(let p of f){let v=[];for(let y=0;y<p.positions.length;y+=3)v.push(`<vertex x="${Xn(p.positions[y])}" y="${Xn(p.positions[y+1])}" z="${Xn(p.positions[y+2])}"/>`);let b=[];for(let y=0;y<p.indices.length;y+=3)b.push(`<triangle v1="${p.indices[y]}" v2="${p.indices[y+1]}" v3="${p.indices[y+2]}"/>`);r.push(`<object id="${i}" type="model" name="${_t(T3(p))}" pid="1" pindex="${n(p)}"><mesh><vertices>${v.join("")}</vertices><triangles>${b.join("")}</triangles></mesh></object>`),m.push(`<part id="${i}" subtype="normal_part">${c("name",T3(p))}${c("extruder",n(p)+1)}</part>`),d.push(i++)}let g=`${c("name",T3(f[0]))}${c("extruder",n(f[0])+1)}`;d.length===1?(a.push(`<item objectid="${d[0]}"/>`),s.push(`<object id="${d[0]}">${g}</object>`)):(r.push(`<object id="${i}" type="model" name="${_t(T3(f[0]))}"><components>${d.map(p=>`<component objectid="${p}"/>`).join("")}</components></object>`),s.push(`<object id="${i}">${g}${m.join("")}</object>`),a.push(`<item objectid="${i++}"/>`))}let h=`<?xml version="1.0" encoding="UTF-8"?>
4343
+ <model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"><metadata name="Application">KerfScript</metadata><resources><basematerials id="1">${e.map(f=>{let[d,m]=f.split("\0"),[g,p,v]=Zn(m),b=[g,p,v].map(y=>y.toString(16).padStart(2,"0")).join("").toUpperCase();return`<base name="${_t(d)}" displaycolor="#${b}FF"/>`}).join("")}</basematerials>${r.join("")}</resources><build>${a.join("")}</build></model>
4344
+ `,u=new TextEncoder;return Ma([{name:"[Content_Types].xml",data:u.encode(`<?xml version="1.0" encoding="UTF-8"?>
4345
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml"/><Default Extension="config" ContentType="text/xml"/></Types>
4346
+ `)},{name:"_rels/.rels",data:u.encode(`<?xml version="1.0" encoding="UTF-8"?>
4344
4347
  <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="/3D/3dmodel.model" Id="rel0" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel"/></Relationships>
4345
- `)},{name:"3D/3dmodel.model",data:l.encode(i)}])}var ae=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)};function Jn(t,e=[]){let n=[],r=0,a=[],s=[],c=[],o=[],i=[],l=[],h=x=>{let k=new Uint8Array(x.buffer,x.byteOffset,x.byteLength);return a.push({buffer:0,byteOffset:r,byteLength:k.length,target:34962}),n.push(k),r+=k.length,a.length-1};for(let x of t){if(!x.indices.length)continue;let k=x.indices.length,A=new Float32Array(k*3),L=new Float32Array(k*3),z=[1/0,1/0,1/0],S=[-1/0,-1/0,-1/0];for(let T=0;T<k;T+=3){let[O,_,D]=[x.indices[T],x.indices[T+1],x.indices[T+2]],[G,V,U]=wa(x.positions,O,_,D);[O,_,D].forEach((J,n1)=>{let m1=x.positions[J*3]/1e3,M1=x.positions[J*3+2]/1e3,c1=-x.positions[J*3+1]/1e3,C1=(T+n1)*3;A.set([m1,M1,c1],C1),L.set([G,U,-V],C1),[m1,M1,c1].forEach((h1,B1)=>{z[B1]=Math.min(z[B1],h1),S[B1]=Math.max(S[B1],h1)})})}let C=h(A);s.push({bufferView:C,componentType:5126,count:k,type:"VEC3",min:z,max:S});let E=h(L);s.push({bufferView:E,componentType:5126,count:k,type:"VEC3"});let I=`${x.material}\0${x.color}\0${x.metal?1:0}\0${x.clear?1:0}\0${x.glow?1:0}\0${x.translucent?1:0}`,H=l.indexOf(I);if(H<0){let[T,O,_]=Zn(x.color);i.push({name:x.material,pbrMetallicRoughness:{baseColorFactor:[ae(T),ae(O),ae(_),x.clear?.45:x.translucent?.75:1],metallicFactor:x.metal?.6:0,roughnessFactor:x.metal?.35:.85},...(x.clear||x.translucent)&&{alphaMode:"BLEND",doubleSided:!0},...x.translucent&&{extensions:{KHR_materials_transmission:{transmissionFactor:.5}}},...x.glow&&{emissiveFactor:[ae(T),ae(O),ae(_)]}}),H=l.push(I)-1}c.push({name:Ft(x),primitives:[{attributes:{POSITION:s.length-2,NORMAL:s.length-1},material:H}]}),o.push({name:Ft(x),mesh:c.length-1,extras:{kind:x.kind,material:x.material,...x.part!==void 0&&{part:x.part,copy:x.copy}}})}let u=[];for(let x of e){let[k,A,L]=Zn(x.color);for(let{at:z,lumens:S}of j5(x))u.push({type:"point",color:[ae(k),ae(A),ae(L)],intensity:S/(4*Math.PI)}),o.push({name:x.label??x.source,translation:[z[0]/1e3+0,z[2]/1e3+0,-z[1]/1e3+0],extensions:{KHR_lights_punctual:{light:u.length-1}},extras:{kind:"light",source:x.source,flicker:x.flicker,lumens:S}})}let f=[...u.length?["KHR_lights_punctual"]:[],...t.some(x=>x.translucent&&x.indices.length)?["KHR_materials_transmission"]:[]],d={asset:{version:"2.0",generator:"KerfScript"},...f.length&&{extensionsUsed:f},...u.length&&{extensions:{KHR_lights_punctual:{lights:u}}},scene:0,scenes:[{nodes:o.map((x,k)=>k)}],nodes:o,meshes:c,materials:i,accessors:s,bufferViews:a,buffers:[{byteLength:r}]},p=new TextEncoder().encode(JSON.stringify(d)),g=(4-p.length%4)%4,v=(4-r%4)%4,b=20+p.length+g+8+r+v,y=new Uint8Array(b),M=new DataView(y.buffer);M.setUint32(0,1179937895,!0),M.setUint32(4,2,!0),M.setUint32(8,b,!0),M.setUint32(12,p.length+g,!0),M.setUint32(16,1313821514,!0),y.set(p,20),y.fill(32,20+p.length,20+p.length+g);let w=20+p.length+g;M.setUint32(w,r+v,!0),M.setUint32(w+4,5130562,!0),w+=8;for(let x of n)y.set(x,w),w+=x.length;return y}function ka(t,e,n={}){let r=Rt(t,n);if(e==="stl")return Yn(r);if(e==="3mf")return Kn(r);let a=(n.layout??"assembled")==="assembled"&&t.assembly.length>0;return Jn(r,a&&n.hardware!==!1?t.lights??[]:[])}function za(t){let e=2166136261,n=16777619;for(let r=0;r<t.length;r++){let a=t.charCodeAt(r);e=Math.imul(e^a,16777619),n=Math.imul(n^a,1540483477)}return`${(e>>>0).toString(36)}${(n>>>0).toString(36)}${t.length}`}var w5=t=>Math.round(t*1e3)/1e3,Qn=t=>t.map(e=>e.map(([n,r])=>[w5(n),w5(r)]));function lu(t){let e=JSON.stringify([t.sheets.map(r=>[r.svg,r.back?.svg??"",r.width,r.height,r.material,r.thickness]),t.parts.map(r=>[r.name,r.qty,r.thickness,r.material,r.kerf,r.stack,r.glued,r.mirrored])]),n=JSON.stringify([[...t.assembly,...t.flat].map(r=>[r.name,r.copy,r.placed,r.thickness,r.material,r.matrix.map(w5),r.bends,r.folds??null,r.paint??null,r.step,Qn(r.outline),(r.marks??[]).map(a=>[a.layer,a.side,a.color,Qn(a.regions),Qn(a.lines)])]),t.hardware,t.lights,t.steps]);return{files:za(e),view:za(n)}}function hu(t,e){let n=t.initial;if(t.options)return t.options.map(s=>s.value);if(t.type==="boolean")return[!0,!1];if(t.type==="string"){let s=String(n??"");if(!s)return["","Sample"];let c=[...s].reverse().join("");return[...new Set([s,s.slice(0,Math.ceil(s.length/2)),c===s?s+s:c])]}if(Array.isArray(n))return"a list of numbers";if(typeof n!="number")return"not a number, text or choice";if(t.min===void 0||t.max===void 0||!(t.max>t.min)){let s=Math.abs(n)>0?Math.abs(n)/2:1;return[n-s,n,n+s]}let r=s=>t.step?w5(t.min+Math.round((s-t.min)/t.step)*t.step):w5(s),a=Array.from({length:e},(s,c)=>r(t.min+(t.max-t.min)*c/(e-1)));return[...new Set([...a,n])].sort((s,c)=>s-c)}function Sa(t,e={},n=5){let r=v3(t).parameters,a={...e.params},s=[];for(let c of r){if(c.drive){s.push({name:c.name,tried:[],effect:"skipped",reason:"it drives the motion"});continue}if(!dt(c,a,r)){s.push({name:c.name,tried:[],effect:"skipped",reason:`it applies only when ${c.when}`});continue}let o=hu(c,Math.max(3,n));if(typeof o=="string"){s.push({name:c.name,tried:[],effect:"skipped",reason:`it is ${o}`});continue}let i=[],l=[];for(let m of o)try{i.push(lu(mt(t,{...e,params:{...a,[c.name]:m}})))}catch(p){i.push(null),l.push({value:m,message:p.message})}let h=i.filter(m=>m!==null),u=new Set(h.map(m=>m.files)).size>1,f=new Set(h.map(m=>`${m.files} ${m.view}`)).size>1,d={name:c.name,tried:o,effect:h.length<2?"failed":u?"files":f?"view":"nothing",...l.length&&{errors:l}};if(d.effect==="files"||d.effect==="view"){let m=g=>i[g]?`${i[g].files} ${i[g].view}`:`x${g}`,p=[];if(c.options){let g=new Map;o.forEach((v,b)=>g.set(m(b),[...g.get(m(b))??[],v]));for(let[v,b]of g)b.length>1&&!v.startsWith("x")&&p.push(b)}else{let g=0;for(let v=1;v<=o.length;v++)(v===o.length||m(v)!==m(g))&&(v-g>1&&i[g]&&p.push(o.slice(g,v)),g=v)}p.length&&(d.same=p)}s.push(d)}return s}function Aa(t){let e=a=>JSON.stringify(a),n=["Each setting tried across its range, the others as they are:"],r=!1;for(let a of t){if(a.effect==="skipped"){n.push(`${a.name}: not tried, as ${a.reason}`);continue}a.effect==="failed"?(r=!0,n.push(`${a.name}: the program stops at ${a.errors?.length??0} of the ${a.tried.length} values tried`)):a.effect==="nothing"?(r=!0,n.push(`${a.name}: changes nothing at ${a.tried.map(e).join(", ")}`)):a.effect==="view"?n.push(`${a.name}: changes only the assembled view, not the files`):n.push(`${a.name}: changes the files`);for(let s of a.same??[])n.push(typeof s[0]=="number"?` from ${e(s[0])} to ${e(s[s.length-1])} it changes nothing`:` ${s.slice(0,-1).map(e).join(", ")} and ${e(s[s.length-1])} give the same result`);for(let s of a.errors??[])n.push(` at ${e(s.value)}: ${s.message}`)}return{lines:n,idle:r}}var uu="0.11.0",fu="0.3";
4348
+ `)},{name:"3D/3dmodel.model",data:u.encode(h)},{name:"Metadata/model_settings.config",data:u.encode(`<?xml version="1.0" encoding="UTF-8"?>
4349
+ <config>${s.join("")}</config>
4350
+ `)}])}var ae=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)};function Jn(t,e=[]){let n=[],r=0,a=[],s=[],c=[],o=[],i=[],l=[],h=x=>{let k=new Uint8Array(x.buffer,x.byteOffset,x.byteLength);return a.push({buffer:0,byteOffset:r,byteLength:k.length,target:34962}),n.push(k),r+=k.length,a.length-1};for(let x of t){if(!x.indices.length)continue;let k=x.indices.length,A=new Float32Array(k*3),L=new Float32Array(k*3),z=[1/0,1/0,1/0],S=[-1/0,-1/0,-1/0];for(let T=0;T<k;T+=3){let[O,_,D]=[x.indices[T],x.indices[T+1],x.indices[T+2]],[G,V,U]=wa(x.positions,O,_,D);[O,_,D].forEach((J,n1)=>{let m1=x.positions[J*3]/1e3,M1=x.positions[J*3+2]/1e3,c1=-x.positions[J*3+1]/1e3,C1=(T+n1)*3;A.set([m1,M1,c1],C1),L.set([G,U,-V],C1),[m1,M1,c1].forEach((h1,B1)=>{z[B1]=Math.min(z[B1],h1),S[B1]=Math.max(S[B1],h1)})})}let C=h(A);s.push({bufferView:C,componentType:5126,count:k,type:"VEC3",min:z,max:S});let E=h(L);s.push({bufferView:E,componentType:5126,count:k,type:"VEC3"});let I=`${x.material}\0${x.color}\0${x.metal?1:0}\0${x.clear?1:0}\0${x.glow?1:0}\0${x.translucent?1:0}`,H=l.indexOf(I);if(H<0){let[T,O,_]=Zn(x.color);i.push({name:x.material,pbrMetallicRoughness:{baseColorFactor:[ae(T),ae(O),ae(_),x.clear?.45:x.translucent?.75:1],metallicFactor:x.metal?.6:0,roughnessFactor:x.metal?.35:.85},...(x.clear||x.translucent)&&{alphaMode:"BLEND",doubleSided:!0},...x.translucent&&{extensions:{KHR_materials_transmission:{transmissionFactor:.5}}},...x.glow&&{emissiveFactor:[ae(T),ae(O),ae(_)]}}),H=l.push(I)-1}c.push({name:T3(x),primitives:[{attributes:{POSITION:s.length-2,NORMAL:s.length-1},material:H}]}),o.push({name:T3(x),mesh:c.length-1,extras:{kind:x.kind,material:x.material,...x.part!==void 0&&{part:x.part,copy:x.copy}}})}let u=[];for(let x of e){let[k,A,L]=Zn(x.color);for(let{at:z,lumens:S}of G5(x))u.push({type:"point",color:[ae(k),ae(A),ae(L)],intensity:S/(4*Math.PI)}),o.push({name:x.label??x.source,translation:[z[0]/1e3+0,z[2]/1e3+0,-z[1]/1e3+0],extensions:{KHR_lights_punctual:{light:u.length-1}},extras:{kind:"light",source:x.source,flicker:x.flicker,lumens:S}})}let f=[...u.length?["KHR_lights_punctual"]:[],...t.some(x=>x.translucent&&x.indices.length)?["KHR_materials_transmission"]:[]],d={asset:{version:"2.0",generator:"KerfScript"},...f.length&&{extensionsUsed:f},...u.length&&{extensions:{KHR_lights_punctual:{lights:u}}},scene:0,scenes:[{nodes:o.map((x,k)=>k)}],nodes:o,meshes:c,materials:i,accessors:s,bufferViews:a,buffers:[{byteLength:r}]},g=new TextEncoder().encode(JSON.stringify(d)),p=(4-g.length%4)%4,v=(4-r%4)%4,b=20+g.length+p+8+r+v,y=new Uint8Array(b),M=new DataView(y.buffer);M.setUint32(0,1179937895,!0),M.setUint32(4,2,!0),M.setUint32(8,b,!0),M.setUint32(12,g.length+p,!0),M.setUint32(16,1313821514,!0),y.set(g,20),y.fill(32,20+g.length,20+g.length+p);let w=20+g.length+p;M.setUint32(w,r+v,!0),M.setUint32(w+4,5130562,!0),w+=8;for(let x of n)y.set(x,w),w+=x.length;return y}function ka(t,e,n={}){let r=Ft(t,n);if(e==="stl")return Yn(r);if(e==="3mf")return Kn(r);let a=(n.layout??"assembled")==="assembled"&&t.assembly.length>0;return Jn(r,a&&n.hardware!==!1?t.lights??[]:[])}function za(t){let e=2166136261,n=16777619;for(let r=0;r<t.length;r++){let a=t.charCodeAt(r);e=Math.imul(e^a,16777619),n=Math.imul(n^a,1540483477)}return`${(e>>>0).toString(36)}${(n>>>0).toString(36)}${t.length}`}var k5=t=>Math.round(t*1e3)/1e3,Qn=t=>t.map(e=>e.map(([n,r])=>[k5(n),k5(r)]));function lu(t){let e=JSON.stringify([t.sheets.map(r=>[r.svg,r.back?.svg??"",r.width,r.height,r.material,r.thickness]),t.parts.map(r=>[r.name,r.qty,r.thickness,r.material,r.kerf,r.stack,r.glued,r.mirrored])]),n=JSON.stringify([[...t.assembly,...t.flat].map(r=>[r.name,r.copy,r.placed,r.thickness,r.material,r.matrix.map(k5),r.bends,r.folds??null,r.paint??null,r.step,Qn(r.outline),(r.marks??[]).map(a=>[a.layer,a.side,a.color,Qn(a.regions),Qn(a.lines)])]),t.hardware,t.lights,t.steps]);return{files:za(e),view:za(n)}}function hu(t,e){let n=t.initial;if(t.options)return t.options.map(s=>s.value);if(t.type==="boolean")return[!0,!1];if(t.type==="string"){let s=String(n??"");if(!s)return["","Sample"];let c=[...s].reverse().join("");return[...new Set([s,s.slice(0,Math.ceil(s.length/2)),c===s?s+s:c])]}if(Array.isArray(n))return"a list of numbers";if(typeof n!="number")return"not a number, text or choice";if(t.min===void 0||t.max===void 0||!(t.max>t.min)){let s=Math.abs(n)>0?Math.abs(n)/2:1;return[n-s,n,n+s]}let r=s=>t.step?k5(t.min+Math.round((s-t.min)/t.step)*t.step):k5(s),a=Array.from({length:e},(s,c)=>r(t.min+(t.max-t.min)*c/(e-1)));return[...new Set([...a,n])].sort((s,c)=>s-c)}function Sa(t,e={},n=5){let r=v3(t).parameters,a={...e.params},s=[];for(let c of r){if(c.drive){s.push({name:c.name,tried:[],effect:"skipped",reason:"it drives the motion"});continue}if(!mt(c,a,r)){s.push({name:c.name,tried:[],effect:"skipped",reason:`it applies only when ${c.when}`});continue}let o=hu(c,Math.max(3,n));if(typeof o=="string"){s.push({name:c.name,tried:[],effect:"skipped",reason:`it is ${o}`});continue}let i=[],l=[];for(let m of o)try{i.push(lu(pt(t,{...e,params:{...a,[c.name]:m}})))}catch(g){i.push(null),l.push({value:m,message:g.message})}let h=i.filter(m=>m!==null),u=new Set(h.map(m=>m.files)).size>1,f=new Set(h.map(m=>`${m.files} ${m.view}`)).size>1,d={name:c.name,tried:o,effect:h.length<2?"failed":u?"files":f?"view":"nothing",...l.length&&{errors:l}};if(d.effect==="files"||d.effect==="view"){let m=p=>i[p]?`${i[p].files} ${i[p].view}`:`x${p}`,g=[];if(c.options){let p=new Map;o.forEach((v,b)=>p.set(m(b),[...p.get(m(b))??[],v]));for(let[v,b]of p)b.length>1&&!v.startsWith("x")&&g.push(b)}else{let p=0;for(let v=1;v<=o.length;v++)(v===o.length||m(v)!==m(p))&&(v-p>1&&i[p]&&g.push(o.slice(p,v)),p=v)}g.length&&(d.same=g)}s.push(d)}return s}function Aa(t){let e=a=>JSON.stringify(a),n=["Each setting tried across its range, the others as they are:"],r=!1;for(let a of t){if(a.effect==="skipped"){n.push(`${a.name}: not tried, as ${a.reason}`);continue}a.effect==="failed"?(r=!0,n.push(`${a.name}: the program stops at ${a.errors?.length??0} of the ${a.tried.length} values tried`)):a.effect==="nothing"?(r=!0,n.push(`${a.name}: changes nothing at ${a.tried.map(e).join(", ")}`)):a.effect==="view"?n.push(`${a.name}: changes only the assembled view, not the files`):n.push(`${a.name}: changes the files`);for(let s of a.same??[])n.push(typeof s[0]=="number"?` from ${e(s[0])} to ${e(s[s.length-1])} it changes nothing`:` ${s.slice(0,-1).map(e).join(", ")} and ${e(s[s.length-1])} give the same result`);for(let s of a.errors??[])n.push(` at ${e(s.value)}: ${s.message}`)}return{lines:n,idle:r}}var uu="0.11.1",fu="0.3";
4346
4351
  /*! Bundled license information:
4347
4352
 
4348
4353
  opentype.js/dist/opentype.module.js: