@mylasertools/kerfscript 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +157 -0
- package/LANGUAGE.md +200 -84
- package/README.md +4 -3
- package/dist/assembly.d.cts +4 -1
- package/dist/assembly.d.ts +4 -1
- package/dist/ast.d.cts +6 -0
- package/dist/ast.d.ts +6 -0
- package/dist/bores.d.cts +15 -0
- package/dist/bores.d.ts +15 -0
- package/dist/cli.js +8959 -6064
- package/dist/customizer.d.cts +4 -0
- package/dist/customizer.d.ts +4 -0
- package/dist/effects.d.cts +31 -0
- package/dist/effects.d.ts +31 -0
- package/dist/evaluator.d.cts +10 -0
- package/dist/evaluator.d.ts +10 -0
- package/dist/export/mesh.d.cts +53 -0
- package/dist/export/mesh.d.ts +53 -0
- package/dist/export/model.d.cts +12 -0
- package/dist/export/model.d.ts +12 -0
- package/dist/export/triangulate.d.cts +5 -0
- package/dist/export/triangulate.d.ts +5 -0
- package/dist/export/zip.d.cts +5 -0
- package/dist/export/zip.d.ts +5 -0
- package/dist/functions.d.cts +2 -0
- package/dist/functions.d.ts +2 -0
- package/dist/geometry.d.cts +7 -0
- package/dist/geometry.d.ts +7 -0
- package/dist/halving.d.cts +8 -0
- package/dist/halving.d.ts +8 -0
- package/dist/highlight.cjs +3 -2
- package/dist/highlight.js +3 -2
- package/dist/import/dbg.d.cts +1 -0
- package/dist/import/dbg.d.ts +1 -0
- package/dist/index.cjs +522 -56
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +522 -56
- package/dist/language.cjs +495 -36
- package/dist/language.js +495 -36
- package/dist/libraries.cjs +474 -16
- package/dist/libraries.js +474 -16
- package/dist/plot.d.cts +16 -0
- package/dist/plot.d.ts +16 -0
- package/dist/render.d.cts +3 -0
- package/dist/render.d.ts +3 -0
- package/dist/signatures.cjs +182 -5
- package/dist/signatures.js +182 -5
- package/dist/text.d.cts +6 -0
- package/dist/text.d.ts +6 -0
- package/docs/3d-files.md +72 -0
- package/docs/cli.md +27 -21
- package/docs/compatibility.md +0 -8
- package/docs/customizer.md +74 -0
- package/docs/javascript.md +46 -0
- package/docs/library.md +162 -1
- package/docs/openscad.md +15 -13
- package/docs/parts-and-sheets.md +57 -1
- package/docs/versions.md +2 -2
- package/package.json +1 -1
package/dist/index.js
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
|
-
var yn=Object.defineProperty;var bn=(t,e,n)=>e in t?yn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var xn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var D=(t,e,n)=>bn(t,typeof e!="symbol"?e+"":e,n);var S7=xn((mh,k7)=>{k7.exports={}});var e0;(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"})(e0||(e0={}));var I0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(I0||(I0={}));var D1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(D1||(D1={}));var N1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(N1||(N1={}));var b3=Number.MAX_SAFE_INTEGER,f0=Math.floor(Math.sqrt(b3));function D5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=b3/Math.abs(e)}function H6(t,e){return Math.abs(t)+Math.abs(e)<=b3}function j4(t,e,n,c){if(D5(t,e)&&D5(n,c)){let r=t*e,a=n*c;if(H6(r,a))return r-a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(c)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(c)):t*e-n*c}function W4(t,e,n,c){if(D5(t,e)&&D5(n,c)){let r=t*e,a=n*c;if(H6(r,a))return r+a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(c)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(c)):t*e+n*c}var X4=BigInt(0),q5=BigInt(2),Mn=BigInt(4),wn=BigInt(64),zn=BigInt("0xFFFFFFFFFFFFFFFF"),J4=BigInt("9223372036854775807"),K3=Number(J4/Mn),O6=Number(J4),R6=1e-12,kn=.1,Z4=Math.floor(f0/2),Sn=Math.floor(Math.sqrt(Math.sqrt(b3/4)));function Ln(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:b3/e}function An(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function Cn(t,e){if(!Number.isFinite(t)||Math.abs(t)>b3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function Pn(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0?c*r-a*s:j4(c,r,a,s)}function Y0(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;if(Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0){let l=c*r,h=a*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let l=c*r,h=a*s;return l>h?1:l<h?-1:0}let i=BigInt(c)*BigInt(r),o=BigInt(a)*BigInt(s);return i===o?0:i>o?1:-1}function Tn(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function En(t){return Math.abs(t)<=R6}function In(t){return t<0?-1:t>0?1:0}function Vn(t,e){let n=BigInt(t),c=BigInt(e),r=n*c;return{lo64:r&zn,hi64:r>>wn}}function F6(t,e,n,c){let r=Math.abs(t),a=Math.abs(e),s=Math.abs(n),i=Math.abs(c);if(r<f0&&a<f0&&s<f0&&i<f0)return t*e===n*c;let o=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(c<0?-1:c>0?1:0);if(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return t*e===n*c;let h=BigInt(r),u=BigInt(a),f=BigInt(s),d=BigInt(i);return h*u===f*d}function Hn(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return F6(c,r,a,s)}function On(t,e,n){let c=e.x-t.x,r=n.x-e.x,a=e.y-t.y,s=n.y-e.y;return Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0?c*r+a*s:W4(c,r,a,s)}function Rn(t,e,n){let c=e.x-t.x,r=n.x-e.x,a=e.y-t.y,s=n.y-e.y;if(Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0){let o=c*r+a*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let o=c*r+a*s;return o>0?1:o<0?-1:0}let i=BigInt(c)*BigInt(r)+BigInt(a)*BigInt(s);return i===X4?0:i>X4?1:-1}function Fn(t){let e=t.length;if(e<3)return 0;let n=!0;for(let a=0;a<e&&n;a++){let s=t[a];(Math.abs(s.x)>=Z4||Math.abs(s.y)>=Z4)&&(n=!1)}let c=t[e-1];if(n){let a=0;for(let s of t)a+=(c.y+s.y)*(c.x-s.x),c=s;return a*.5}let r=X4;for(let a of t){let s=c.y+a.y,i=c.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))r+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(c.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(a.x)){let o=BigInt(c.y)+BigInt(a.y),l=BigInt(c.x)-BigInt(a.x);r+=o*l}else r+=BigInt(Math.round(s*i));c=a}return Number(r)*.5}function $n(t,e){return t.y*e.x-e.y*t.x}function Dn(t,e){return t.x*e.x+t.y*e.y}function qn(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function Nn(t){return t>=K3||t<=-K3?O6:Math.round(t)}function Un(t,e,n,c){let r=e.y-t.y,a=e.x-t.x,s=c.y-n.y,i=c.x-n.x,o=j4(r,i,s,a);if(o===0)return null;let l=j4(t.x-n.x,s,t.y-n.y,i)/o;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*a),y:Math.trunc(t.y+l*r),z:0}}function Bn(t,e,n,c){let r=e.y-t.y,a=e.x-t.x,s=c.y-n.y,i=c.x-n.x,o=r*i-s*a;if(o===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*s-(t.y-n.y)*i)/o,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*a,y:t.y+l*r,z:0},{success:!0,ip:h}}function _n(t,e,n,c,r=!1){if(!r){let l=Y0(t,n,c),h=Y0(e,n,c),u=Y0(n,t,e),f=Y0(c,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=Y0(t,n,c),s=Y0(e,n,c);if(a!==0&&a===s)return!1;let i=Y0(n,t,e),o=Y0(c,t,e);return i!==0&&i===o?!1:a!==0||s!==0||i!==0||o!==0}function $6(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 Gn(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let c=n.x-e.x,r=n.y-e.y,a=W4(t.x-e.x,c,t.y-e.y,r)/W4(c,c,r,r),s=a<0?0:a>1?1:a;return{x:Math.round(e.x+s*c),y:Math.round(e.y+s*r),z:0}}function Y4(t,e){let n=e.length,c=0;if(n<3)return N1.IsOutside;for(;c<n&&e[c].y===t.y;)c++;if(c===n)return N1.IsOutside;let r=e[c].y<t.y,a=r,s=0,i=c+1,o=n;for(;;){if(i===o){if(o===0||c===0)break;o=c,i=0}if(r)for(;i<o&&e[i].y<t.y;)i++;else for(;i<o&&e[i].y>t.y;)i++;if(i===o)continue;let h=e[i],u=i>0?e[i-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 N1.IsOn;if(i++,i===c)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)s=1-s;else{let f=Y0(u,h,t);if(f===0)return N1.IsOn;f<0===r&&(s=1-s)}r=!r,i++}if(r===a)return s===0?N1.IsOutside:N1.IsInside;i===n&&(i=0);let l=i===0?Y0(e[n-1],e[0],t):Y0(e[i-1],e[i],t);return l===0?N1.IsOn:(l<0===r&&(s=1-s),s===0?N1.IsOutside:N1.IsInside)}function jn(t,e){let n=N1.IsOn;for(let i of t)switch(Y4(i,e)){case N1.IsOutside:if(n===N1.IsOutside)return!1;n=N1.IsOutside;break;case N1.IsInside:if(n===N1.IsInside)return!0;n=N1.IsInside;break;default:break}let c=$6(t),r,a;return Number.isSafeInteger(c.left)&&Number.isSafeInteger(c.right)&&Math.abs(c.left)+Math.abs(c.right)>Number.MAX_SAFE_INTEGER?(r=Number((BigInt(c.left)+BigInt(c.right))/q5),a=Number((BigInt(c.top)+BigInt(c.bottom))/q5)):(r=Math.round((c.left+c.right)/2),a=Math.round((c.top+c.bottom)/2)),Y4({x:r,y:a},e)!==N1.IsOutside}var V1={MaxInt64:J4,MaxCoord:K3,max_coord:K3,min_coord:-K3,Invalid64:O6,floatingPointTolerance:R6,defaultMinimumEdgeLength:kn,maxCoordForSafeAreaProduct:Z4,maxCoordForSafeCrossSq:Sn,maxSafeCoordinateForScale:Ln,checkSafeScaleValue:An,ensureSafeInteger:Cn,crossProduct:Pn,crossProductSign:Y0,checkPrecision:Tn,isAlmostZero:En,triSign:In,multiplyUInt64:Vn,productsAreEqual:F6,isCollinear:Hn,dotProduct:On,dotProductSign:Rn,area:Fn,crossProductD:$n,dotProductD:Dn,roundToEven:qn,checkCastInt64:Nn,getLineIntersectPt:Un,getLineIntersectPtD:Bn,segsIntersect:_n,getBounds:$6,getClosestPtOnSegment:Gn,pointInPolygon:Y4,path2ContainsPath1:jn},m2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return V1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),V1.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,c=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(c)?{x:n,y:c,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} `}},N5={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 V1.isAlmostZero(t.x-e.x)&&V1.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)}`}},t3={create(t=0,e=0,n=0,c=0){return{left:t,top:e,right:n,bottom:c}},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))/q5),n=Number((BigInt(t.top)+BigInt(t.bottom))/q5);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}]}},K4={create(t=0,e=0,n=0,c=0){return{left:t,top:e,right:n,bottom:c}},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 D6=Object.freeze(t3.createInvalid()),q6=Object.freeze(K4.createInvalid());var Q3=BigInt(0),Wn=BigInt(2),N6=BigInt(4),X1;(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"})(X1||(X1={}));var Q4=class{constructor(){D(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 c=e-1>>1;if(this.data[c]>=n)break;this.data[e]=this.data[c],e=c}this.data[e]=n}siftDown(e){let n=this.data.length,c=this.data[e];for(;;){let r=(e<<1)+1;if(r>=n)break;let a=r+1,s=r;if(a<n&&this.data[a]>this.data[r]&&(s=a),this.data[s]<=c)break;this.data[e]=this.data[s],e=s}this.data[e]=c}},e5=class{constructor(e,n,c){D(this,"pt");D(this,"next",null);D(this,"prev",null);D(this,"flags");this.pt=e,this.flags=n,this.prev=c}},t5=class{constructor(e,n,c=!1){D(this,"vertex");D(this,"polytype");D(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=c}equals(e){return e!==null&&this.vertex===e.vertex}};function U6(t,e,n){return{pt:t,edge1:e,edge2:n}}var A2=class{constructor(e,n){D(this,"pt");D(this,"next");D(this,"prev");D(this,"outrec");D(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},H0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(H0||(H0={}));var ee;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(ee||(ee={}));var U5=class{constructor(){D(this,"idx",0);D(this,"owner",null);D(this,"frontEdge",null);D(this,"backEdge",null);D(this,"pts",null);D(this,"polypath",null);D(this,"bounds",{left:0,top:0,right:0,bottom:0});D(this,"path",[]);D(this,"isOpen",!1);D(this,"splits",null);D(this,"recursiveSplit",null)}},B5=class{constructor(e){D(this,"leftOp");D(this,"rightOp");D(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},n5=class{constructor(e,n){D(this,"op1");D(this,"op2");this.op1=e,this.op2=n}};function Xn(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function Zn(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 c5=class{constructor(){D(this,"bot",{x:0,y:0});D(this,"top",{x:0,y:0});D(this,"curX",0);D(this,"dx",0);D(this,"windDx",0);D(this,"windCount",0);D(this,"windCount2",0);D(this,"outrec",null);D(this,"prevInAEL",null);D(this,"nextInAEL",null);D(this,"prevInSEL",null);D(this,"nextInSEL",null);D(this,"jump",null);D(this,"vertexTop",null);D(this,"localMin",null);D(this,"isLeftBound",!1);D(this,"joinWith",H0.None)}},x3={addLocMin(t,e,n,c){if((t.flags&X1.LocalMin)!==X1.None)return;t.flags|=X1.LocalMin;let r=new t5(t,e,n);c.push(r)},addPathsToVertexList(t,e,n,c,r){for(let a=0,s=t.length;a<s;a++){let i=t[a],o=null,l=null,h=null;for(let p=0,m=i.length;p<m;p++){let g=i[p];if(o===null)o=new e5(g,X1.None,null),r.push(o),l=o,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new e5(g,X1.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!n&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!n&&l.next===l))continue;let u;if(n){let p=o.next;for(;p!==o&&p.pt.y===o.pt.y;)p=p.next;u=p.pt.y<=o.pt.y,u?(o.flags=X1.OpenStart,x3.addLocMin(o,e,!0,c)):o.flags=X1.OpenStart|X1.LocalMax}else{for(l=o.prev;l!==o&&l.pt.y===o.pt.y;)l=l.prev;if(l===o)continue;u=l.pt.y>o.pt.y}let f=u;l=o;let d=o.next;for(;d!==o;)d.pt.y>l.pt.y&&u?(l.flags|=X1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,x3.addLocMin(l,e,n,c)),l=d,d=d.next;n?(l.flags|=X1.OpenEnd,u?l.flags|=X1.LocalMax:x3.addLocMin(l,e,n,c)):u!==f&&(f?x3.addLocMin(l,e,!1,c):l.flags|=X1.LocalMax)}}};var _5=class{constructor(e=null){D(this,"parent");D(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 c="",r=" ".repeat(n),a=this.children.length===1?"":"s";(n&1)===0?c+=`${r}+- hole (${e}) contains ${this.children.length} nested polygon${a}.
|
|
3
|
-
`:
|
|
4
|
-
`;for(let s=0;s<this.count;s++)this.children[s].count>0&&(
|
|
5
|
-
`;for(let
|
|
6
|
-
`}},G5=class t extends _5{constructor(n=null){super(n);D(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let c=new t(this);return c.polygon=n,this.children.push(c),c}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:te.area(this.polygon);for(let c of this.children)n+=c.area();return n}};var r5=class extends G5{};var T=class T{constructor(){D(this,"cliptype",e0.NoClip);D(this,"fillrule",D1.EvenOdd);D(this,"actives",null);D(this,"sel",null);D(this,"minimaList",[]);D(this,"intersectList",[]);D(this,"vertexList",[]);D(this,"outrecList",[]);D(this,"scanlineHeap",new Q4);D(this,"scanlineSet",new Set);D(this,"scanlineArr",[]);D(this,"useScanlineArray",!1);D(this,"horzSegList",[]);D(this,"horzJoinList",[]);D(this,"currentLocMin",0);D(this,"currentBotY",0);D(this,"curXValidAtTop",!1);D(this,"isSortedMinimaList",!1);D(this,"hasOpenPaths",!1);D(this,"usingPolytree",!1);D(this,"succeeded",!1);D(this,"zCallbackInternal");D(this,"preserveCollinear",!0);D(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,c){let r=this.zCallbackInternal;r&&(T.getPolyType(e)===I0.Subject?(this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:c.z=0,r(e.bot,e.top,n.bot,n.top,c)):(this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:c.z=0,r(n.bot,n.top,e.bot,e.top,c)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return T.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return T.openPathsEnabled&&e.localMin.isOpen&&T.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(X1.OpenStart|X1.OpenEnd))!==X1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!T.openPathsEnabled){for(;n!==null&&!T.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!T.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let c=n.y-e.y;return c!==0?(n.x-e.x)/c: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:V1.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=T.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&X1.LocalMax)!==X1.None}static isMaximaEdge(e){return(e.vertexTop.flags&X1.LocalMax)!==X1.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,c,r){let a=e.x<n.x?e.x:n.x;if((c.x>r.x?c.x:r.x)<a)return!1;let i=e.x>n.x?e.x:n.x,o=c.x<r.x?c.x:r.x;if(i<o)return!1;let l=e.y<n.y?e.y:n.y;if((c.y>r.y?c.y:r.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=c.y<r.y?c.y:r.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,c=e.length;n<c;n++){let r=e[n];this.scanlineSet.add(r),this.scanlineHeap.push(r)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let c=0,r=n.length;c<r;c++)if(n[c]===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,c=n.length;if(c===0)return null;let r=0,a=n[0];for(let s=1;s<c;s++){let i=n[s];i>a&&(a=i,r=s)}return n[r]=n[c-1],n.pop(),a}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,c=!1){let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c=!1){c&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,x3.addPathsToVertexList(e,n,c,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new t5(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,c=e.nextInAEL;n===null&&c===null&&e!==this.actives||(n!==null?n.nextInAEL=c:this.actives=c,c!==null&&(c.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 c=n;do c.pt.x<e.left&&(e.left=c.pt.x),c.pt.x>e.right&&(e.right=c.pt.x),c.pt.y<e.top&&(e.top=c.pt.y),c.pt.y>e.bottom&&(e.bottom=c.pt.y),c=c.next;while(c!==n)}return t3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===e0.NoClip)return;T.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let c=this.popScanline();if(c!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(c);let r;for(;(r=this.popHorz())!==null;)this.doHorizontal(r);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=c;let a=this.popScanline();if(a===null)break;for(c=a,this.doIntersections(c),this.doTopOfScanbeam(c);(r=this.popHorz())!==null;)this.doHorizontal(r)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),c;(n.vertex.flags&X1.OpenStart)!==X1.None?c=null:(c=new c5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=-1,c.vertexTop=n.vertex.prev,c.top=n.vertex.prev.pt,c.outrec=null,c.localMin=n,T.setDx(c));let r;if((n.vertex.flags&X1.OpenEnd)!==X1.None?r=null:(r=new c5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=1,r.vertexTop=n.vertex.next,r.top=n.vertex.next.pt,r.outrec=null,r.localMin=n,T.setDx(r)),c!==null&&r!==null){if(T.isHorizontal(c)){if(T.isHeadingRightHorz(c)){let s=c;c=r,r=s}}else if(T.isHorizontal(r)){if(T.isHeadingLeftHorz(r)){let s=c;c=r,r=s}}else if(c.dx<r.dx){let s=c;c=r,r=s}}else c===null&&(c=r,r=null);let a;if(c.isLeftBound=!0,this.insertLeftEdge(c),T.openPathsEnabled?T.isOpen(c)?(this.setWindCountForOpenPathEdge(c),a=this.isContributingOpen(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)),r!==null){for(r.windCount=c.windCount,r.windCount2=c.windCount2,this.insertRightEdge(c,r),a&&(this.addLocalMinPoly(c,r,c.bot,!0),T.isHorizontal(c)||this.checkJoinLeft(c,c.bot));r.nextInAEL!==null&&this.isValidAelOrder(r.nextInAEL,r);)this.intersectEdges(r,r.nextInAEL,r.bot),this.swapPositionsInAEL(r,r.nextInAEL);T.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else a&&T.openPathsEnabled&&this.startOpenPath(c,c.bot);T.isHorizontal(c)?this.pushHorz(c):this.insertScanline(c.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(!T.openPathsEnabled){this.doHorizontalClosed(e);return}let n=T.isOpen(e),c=e.bot.y,r=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:i}=this.resetHorzDirection(e,r),o=s,l=i;if(T.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:c});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===r){if(T.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),T.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(r!==e.vertexTop||T.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!T.isHorizontal(h)){let d=T.nextVertex(e).pt;if(T.isOpen(h)&&!T.isSamePolyType(h,e)&&!T.isHotEdge(h)){if(a&&T.topX(h,d.y)>d.x||!a&&T.topX(h,d.y)<d.x)break}else if(a&&T.topX(h,d.y)>=d.x||!a&&T.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:c};a?(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),T.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&T.isOpenEnd(e)){T.isHotEdge(e)&&(this.addOutPt(e,e.top),T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(T.nextVertex(e).pt.y!==e.top.y)break;T.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,r);o=u.leftX,l=u.rightX}if(T.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,c=this.getCurrYMaximaVertex(e),{isLeftToRight:r,leftX:a,rightX:s}=this.resetHorzDirection(e,c),i=a,o=s;if(T.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=r?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===c){if(T.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),T.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);r?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(c!==e.vertexTop){if(r&&l.curX>o||!r&&l.curX<i)break;if(l.curX===e.top.x&&!T.isHorizontal(l)){let f=T.nextVertex(e).pt,d=T.topX(l,f.y);if(r&&d>=f.x||!r&&d<=f.x)break}}let u={x:l.curX,y:n};r?(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),T.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(T.nextVertex(e).pt.y!==e.top.y)break;T.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(T.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let c=0,r=e.length;c<r;c++){let a=e[c];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(Xn);for(let c=0;c<n-1;c++){let r=this.horzSegList[c];for(let a=c+1;a<n;a++){let s=this.horzSegList[a];if(s.leftOp.pt.x>=r.rightOp.pt.x||s.leftToRight===r.leftToRight||s.rightOp.pt.x<=r.leftOp.pt.x)continue;let i=r.leftOp.pt.y;if(r.leftToRight){for(;r.leftOp.next.pt.y===i&&r.leftOp.next.pt.x<=s.leftOp.pt.x;)r.leftOp=r.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=r.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new n5(this.duplicateOp(r.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;r.leftOp.prev.pt.y===i&&r.leftOp.prev.pt.x<=s.leftOp.pt.x;)r.leftOp=r.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=r.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new n5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(r.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let n=e.leftOp,c=this.getRealOutRec(n.outrec),r=c.frontEdge!==null,a=n.pt.y,s=n,i=n;if(r){let l=c.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;i!==l&&i.next.pt.y===a;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===a;)s=s.prev;for(;i.next!==s&&i.next.pt.y===a;)i=i.next}let o=this.setHorzSegHeadingForward(e,s,i)&&e.leftOp.horz===null;return o?e.leftOp.horz=e:e.rightOp=null,o}setHorzSegHeadingForward(e,n,c){return n.pt.x===c.pt.x?!1:(n.pt.x<c.pt.x?(e.leftOp=n,e.rightOp=c,e.leftToRight=!0):(e.leftOp=c,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let c=new A2(e.pt,e.outrec);return n?(c.next=e.next,c.next.prev=c,c.prev=e,e.next=c):(c.prev=e.prev,c.prev.next=c,c.next=e,e.prev=c),c}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 c=this.actives;for(;c!==null;){if(c.top.y===e)if(c.curX=c.top.x,T.isMaximaEdge(c)){c=this.doMaxima(c);continue}else T.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),T.isHorizontal(c)&&this.pushHorz(c);else n||(c.curX=T.topX(c,e));c=c.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),c=this.getRealOutRec(e.op2.outrec),r=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,r.prev=a,a.next=r,n===c){let s=this.newOutRec();s.pts=r,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.owner=n}else c.pts=null,this.usingPolytree?(this.setOwner(c,n),this.moveSplits(c,n)):c.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let c=N1.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,n)){case N1.IsOutside:if(c===N1.IsOutside)return!1;c=N1.IsOutside;break;case N1.IsInside:if(c===N1.IsInside)return!0;c=N1.IsInside;break;default:break}r=r.next}while(r!==e);return V1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return N1.IsOutside;let c=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==c);if(n.pt.y===e.y)return N1.IsOutside;let r=n.pt.y<e.y,a=r,s=0;for(c=n.next;c!==n;){if(r)for(;c!==n&&c.pt.y<e.y;)c=c.next;else for(;c!==n&&c.pt.y>e.y;)c=c.next;if(c===n)break;if(c.pt.y===e.y){if(c.pt.x===e.x||c.pt.y===c.prev.pt.y&&e.x<c.prev.pt.x!=e.x<c.pt.x)return N1.IsOn;if(c=c.next,c===n)break;continue}if(c.pt.x<=e.x||c.prev.pt.x<=e.x)if(c.prev.pt.x<e.x&&c.pt.x<e.x)s=1-s;else{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return N1.IsOn;i<0===r&&(s=1-s)}r=!r,c=c.next}if(r===a)return s===0?N1.IsOutside:N1.IsInside;{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return N1.IsOn;i<0===r&&(s=1-s)}return s===0?N1.IsOutside:N1.IsInside}getCleanPath(e){let n=[],c=e;for(;c.next!==e&&(c.pt.x===c.next.pt.x&&c.pt.x===c.prev.pt.x||c.pt.y===c.next.pt.y&&c.pt.y===c.prev.pt.y);)c=c.next;n.push(c.pt);let r=c;for(c=c.next;c!==e;)(c.pt.x!==c.next.pt.x||c.pt.x!==r.pt.x)&&(c.pt.y!==c.next.pt.y||c.pt.y!==r.pt.y)&&(n.push(c.pt),r=c),c=c.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let c of e.splits)c!==n.idx&&n.splits.push(c);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 c=null;for(;n!==null&&n.jump!==null;){let r=n,a=n.jump,s=a,i=a?.jump||null;for(n.jump=i;n!==s&&a!==i;)if(a.curX<n.curX){let o=a.prevInSEL;for(;this.addNewIntersectNode(o,a,e),o!==n;)o=o.prevInSEL;if(o=a,a=this.extractFromSEL(o),s=a,n!==null&&this.insert1Before2InSEL(o,n),n!==r)continue;r=o,r.jump=i,c===null?this.sel=r:c.jump=r}else n=n.nextInSEL;c=r,n=i}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(Zn);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let c=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[c]);)c++;[this.intersectList[c],this.intersectList[e]]=[this.intersectList[e],this.intersectList[c]]}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 c=Number.NEGATIVE_INFINITY,r=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=T.topX(n,e);n.curX=a,a<c&&(r=!0),c=a,n=n.nextInAEL}return r}doMaxima(e){let n=e.prevInAEL,c=e.nextInAEL;if(T.isOpenEnd(e))return T.isHotEdge(e)&&this.addOutPt(e,e.top),T.isHorizontal(e)||(T.isHotEdge(e)&&(T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let r=T.getMaximaPair(e);if(r===null)return c;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(r)&&this.split(r,r.top);c!==r;)this.intersectEdges(e,c,e.top),this.swapPositionsInAEL(e,c),c=e.nextInAEL;return T.isOpen(e)?(T.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(r),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(T.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(e),this.deleteFromAEL(r),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=T.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,T.setDx(e),this.isJoined(e)&&this.split(e,e.bot),T.isHorizontal(e)){T.openPathsEnabled?T.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 c=!1,r=T.nextVertex(e).pt;for(;r.y===e.top.y&&!(n&&r.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=T.nextVertex(e),e.top=r,c=!0,T.isMaximaVertex(e.vertexTop)));)r=T.nextVertex(e).pt;c&&T.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new B5(e))}addNewIntersectNode(e,n,c){let r=V1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(r===null&&(r={x:e.curX,y:c}),r.y>this.currentBotY||r.y<c){let s=Math.abs(e.dx),i=Math.abs(n.dx);s>100&&i>100?s>i?r=V1.getClosestPtOnSegment(r,e.bot,e.top):r=V1.getClosestPtOnSegment(r,n.bot,n.top):s>100?r=V1.getClosestPtOnSegment(r,e.bot,e.top):i>100?r=V1.getClosestPtOnSegment(r,n.bot,n.top):(r.y<c?r.y=c:r.y=this.currentBotY,s<i?r.x=T.topX(e,r.y):r.x=T.topX(n,r.y))}let a=U6(r,e,n);this.intersectList.push(a)}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&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.prev;return T.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 T.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let c=e.curX,r=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:c,rightX:r}}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===H0.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===D1.EvenOdd){let c=0,r=0;for(;n!==e;)T.getPolyType(n)===I0.Clip?r++:T.isOpen(n)||c++,n=n.nextInAEL;e.windCount=T.isOdd(c)?1:0,e.windCount2=T.isOdd(r)?1:0}else for(;n!==e;)T.getPolyType(n)===I0.Clip?e.windCount2+=n.windDx:T.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,c=T.getPolyType(e);if(!T.openPathsEnabled){for(;n!==null&&T.getPolyType(n)!==c;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===D1.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===D1.EvenOdd)for(;n!==e;)T.getPolyType(n)!==c&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)T.getPolyType(n)!==c&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(T.getPolyType(n)!==c||T.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===D1.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=T.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===D1.EvenOdd)for(;n!==e;)T.getPolyType(n)!==c&&!T.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)T.getPolyType(n)!==c&&!T.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,c;switch(this.fillrule){case D1.Positive:c=e.windCount>0,n=e.windCount2>0;break;case D1.Negative:c=e.windCount<0,n=e.windCount2<0;break;default:c=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case e0.Intersection:return n;case e0.Union:return!c&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case D1.Positive:if(e.windCount!==1)return!1;break;case D1.Negative:if(e.windCount!==-1)return!1;break;case D1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case e0.Intersection:return this.fillrule===D1.Positive?e.windCount2>0:this.fillrule===D1.Negative?e.windCount2<0:e.windCount2!==0;case e0.Union:return this.fillrule===D1.Positive?e.windCount2<=0:this.fillrule===D1.Negative?e.windCount2>=0:e.windCount2===0;case e0.Difference:{let n=this.fillrule===D1.Positive?e.windCount2<=0:this.fillrule===D1.Negative?e.windCount2>=0:e.windCount2===0;return T.getPolyType(e)===I0.Subject?n:!n}case e0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,c,r=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,T.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let i=T.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(a,i.outrec),a.owner=i.outrec,this.outrecIsAscending(i)===r?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,r?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new A2(c,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new U5;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let c=this.newOutRec();c.isOpen=!0,e.windDx>0?(c.frontEdge=e,c.backEdge=null):(c.frontEdge=null,c.backEdge=e),e.outrec=c;let r=new A2(n,c);return c.pts=r,r}checkJoinLeft(e,n,c=!1){let r=e.prevInAEL;r!==null&&(!c&&e.curX!==r.curX||!T.isHotEdge(e)||!T.isHotEdge(r)||T.isHorizontal(e)||T.isHorizontal(r)||T.isOpen(e)||T.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(r,e,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),r.joinWith=H0.Right,e.joinWith=H0.Left))}checkJoinRight(e,n,c=!1){let r=e.nextInAEL;r!==null&&(!c&&e.curX!==r.curX||!T.isHotEdge(e)||!T.isHotEdge(r)||T.isHorizontal(e)||T.isHorizontal(r)||T.isOpen(e)||T.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(e,r,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),e.joinWith=H0.Right,r.joinWith=H0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,c){let r=e.x-n.x,a=e.y-n.y,s=c.x-n.x,i=c.y-n.y;if(s===0&&i===0)return!1;let o=V1.maxCoordForSafeCrossSq;if(Math.abs(r)<o&&Math.abs(a)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=r*i-s*a;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(r)*BigInt(i)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return N6*u>f}let l=r*i-s*a;return l*l/(s*s+i*i)>.25}intersectEdges(e,n,c){let r;if(this.hasOpenPaths&&(T.isOpen(e)||T.isOpen(n))){if(T.isOpen(e)&&T.isOpen(n))return;if(T.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,c),this.cliptype===e0.Union){if(!T.isHotEdge(n))return}else if(n.localMin.polytype===I0.Subject)return;switch(this.fillrule){case D1.Positive:if(n.windCount!==1)return;break;case D1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(T.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(c.x===e.localMin.vertex.pt.x&&c.y===e.localMin.vertex.pt.y&&!T.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&T.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}r=this.startOpenPath(e,c)}else r=this.startOpenPath(e,c);this.setZ(e,n,r.pt);return}this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===D1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(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!==D1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==D1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case D1.Positive:a=e.windCount,s=n.windCount;break;case D1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let i=a===0||a===1,o=s===0||s===1;if(!(!T.isHotEdge(e)&&!i||!T.isHotEdge(n)&&!o))if(T.isHotEdge(e)&&T.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==e0.Xor)r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);else if(T.isFront(e)||e.outrec===n.outrec){r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);let l=this.addLocalMinPoly(e,n,c);this.setZ(e,n,l.pt)}else{r=this.addOutPt(e,c),this.setZ(e,n,r.pt);let l=this.addOutPt(n,c);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(T.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else if(T.isHotEdge(n))r=this.addOutPt(n,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case D1.Positive:l=e.windCount2,h=n.windCount2;break;case D1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!T.isSamePolyType(e,n))r=this.addLocalMinPoly(e,n,c),this.setZ(e,n,r.pt);else if(a===1&&s===1){switch(r=null,this.cliptype){case e0.Union:if(l>0&&h>0)return;r=this.addLocalMinPoly(e,n,c);break;case e0.Difference:(T.getPolyType(e)===I0.Clip&&l>0&&h>0||T.getPolyType(e)===I0.Subject&&l<=0&&h<=0)&&(r=this.addLocalMinPoly(e,n,c));break;case e0.Xor:r=this.addLocalMinPoly(e,n,c);break;default:if(l<=0||h<=0)return;r=this.addLocalMinPoly(e,n,c);break}r&&this.setZ(e,n,r.pt)}}}swapPositionsInAEL(e,n){let c=n.nextInAEL;c!==null&&(c.prevInAEL=e);let r=e.prevInAEL;r!==null&&(r.nextInAEL=n),n.prevInAEL=r,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=c,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let c=V1.crossProductSign(e.top,n.bot,n.top);if(c!==0)return c<0;if(!T.isMaximaEdge(e)&&e.top.y>n.top.y)return V1.crossProductSign(n.bot,e.top,T.nextVertex(e).pt)<=0;if(!T.isMaximaEdge(n)&&n.top.y>e.top.y)return V1.crossProductSign(n.bot,n.top,T.nextVertex(n).pt)>=0;let r=n.bot.y,a=n.isLeftBound;return e.bot.y!==r||e.localMin.vertex.pt.y!==r?n.isLeftBound:e.isLeftBound!==a?a:V1.isCollinear(T.prevPrevVertex(e).pt,e.bot,e.top)?!0:V1.crossProductSign(T.prevPrevVertex(e).pt,n.bot,T.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==H0.None}split(e,n){e.joinWith===H0.Right?(e.joinWith=H0.None,e.nextInAEL.joinWith=H0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=H0.None,e.prevInAEL.joinWith=H0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,c){e.frontEdge=n,e.backEdge=c}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!T.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(!T.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 c=e.outrec,r=T.isFront(e),a=c.pts,s=a.next;if(r&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!r&&n.x===s.pt.x&&n.y===s.pt.y)return s;let i=new A2(n,c);return s.prev=i,i.prev=a,i.next=s,a.next=i,r&&(c.pts=i),i}addLocalMaxPoly(e,n,c){if(this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c),T.isFront(e)===T.isFront(n))if(T.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(T.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let r=this.addOutPt(e,c);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=r,this.usingPolytree){let s=T.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else T.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 r}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 c=n;for(;c!==null&&c!==e;)c=c.owner;c!==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 c=e.outrec.pts,r=n.outrec.pts,a=c.next,s=r.next;T.isFront(e)?(s.prev=c,c.next=s,r.next=a,a.prev=r,e.outrec.pts=r,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=r,r.next=a,c.next=s,s.prev=c,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),T.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let c=e.outrec,r=n.outrec;if(c===r){let a=c.frontEdge;c.frontEdge=c.backEdge,c.backEdge=a;return}c!==null&&(e===c.frontEdge?c.frontEdge=n:c.backEdge=n),r!==null&&(n===r.frontEdge?r.frontEdge=e:r.backEdge=e),e.outrec=r,n.outrec=c}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&&(T.ptsReallyClose(e.prev.pt,e.next.pt)||T.ptsReallyClose(e.pt,e.next.pt)||T.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,c,r){if(e===null||e.next===e||!c&&e.next===e.prev)return!1;r.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),r.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,r.push(a)),n?s=s.prev:s=s.next;return r.length!==3||c||!T.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts===null)continue;let a=[];r.isOpen?T.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(r),T.buildPath(r.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts!==null){if(r.isOpen){let a=[];T.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(r)&&this.recursiveCheckOwners(r,e)}}}checkBounds(e){return e.pts===null?!1:t3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!T.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=V1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||t3.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,c=n;for(;;){if(c!==null&&V1.isCollinear(c.prev.pt,c.pt,c.next.pt)&&(c.pt.x===c.prev.pt.x&&c.pt.y===c.prev.pt.y||c.pt.x===c.next.pt.x&&c.pt.y===c.next.pt.y||!this.preserveCollinear||V1.dotProductSign(c.prev.pt,c.pt,c.next.pt)<0)){if(c===e.pts&&(e.pts=c.prev),c=this.disposeOutPt(c),!this.isValidClosedPath(c)){e.pts=null;return}n=c;continue}if(c===null||(c=c.next,c===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!T.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)&&V1.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 c=n.prev,r=n.next.next;e.pts=c;let a=V1.getLineIntersectPt(c.pt,n.pt,n.next.pt,r.pt);this.zCallbackInternal&&this.zCallbackInternal(c.pt,n.pt,n.next.pt,r.pt,a);let s=T.areaOutPt(c),i=s<Q3?-s:s;if(i<N6){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<Q3?-o:o;if(a.x===c.pt.x&&a.y===c.pt.y||a.x===r.pt.x&&a.y===r.pt.y)r.prev=c,c.next=r;else{let f=new A2(a,e);f.prev=c,f.next=r,r.prev=f,c.next=f}if(!(l>Wn)||!(l>i)&&o>Q3!=s>Q3)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new A2(a,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(c,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=V1.maxCoordForSafeAreaProduct,c=0,r=!0,a=e;do{let i=a.prev,o=a.pt;if(Math.abs(i.pt.x)>=n||Math.abs(i.pt.y)>=n||Math.abs(o.x)>=n||Math.abs(o.y)>=n){r=!1;break}c+=(i.pt.y+o.y)*(i.pt.x-o.x),a=a.next}while(a!==e);if(r)return BigInt(Math.round(c));let s=Q3;a=e;do{let i=a.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(a.pt.x)){let o=BigInt(i.pt.y)+BigInt(a.pt.y),l=BigInt(i.pt.x)-BigInt(a.pt.x);s+=o*l}else{let o=i.pt.y+a.pt.y,l=i.pt.x-a.pt.x;s+=BigInt(Math.round(o*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,c){let r=V1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<r&&Math.abs(e.y)<r&&Math.abs(n.x)<r&&Math.abs(n.y)<r&&Math.abs(c.x)<r&&Math.abs(c.y)<r){let s=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(c.y)){let s=(BigInt(c.y)+BigInt(e.y))*(BigInt(c.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),o=(BigInt(n.y)+BigInt(c.y))*(BigInt(n.x)-BigInt(c.x));return s+i+o}let a=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(a))}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 c=0;c<n.length;c++){let r=this.outrecList[n[c]];if(r.pts===null&&r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(r=this.getRealOutRec(r),!(r===null||r===e||r.recursiveSplit===e)){if(r.recursiveSplit=e,r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(!(!this.checkBounds(r)||!this.containsRect(r.bounds,e.bounds)||!this.path1InsidePath2(e.pts,r.pts)))return this.isValidOwner(e,r)||(r.owner=e.owner),e.owner=r,!0}}return!1}};D(T,"openPathsEnabled",!0);var j5=T,g2=class extends j5{constructor(){super(...arguments);D(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,c,r=!1){super.addPath(n,c,r)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,c,r=!1){super.addPaths(n,c,r)}addSubject(n){this.addPaths(n,I0.Subject)}addOpenSubject(n){this.addPaths(n,I0.Subject,!0)}addClip(n){this.addPaths(n,I0.Clip)}execute(n,c,r,a){if(Array.isArray(r)){let s=r,i=a;s.length=0,i&&(i.length=0);try{this.executeInternal(n,c),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=r,i=a;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(n,c),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var te={area(t){return V1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let c=t[n-1];for(let r of t)e+=(c.y+r.y)*(c.x-r.x),c=r;return e*.5},scalePath64(t,e){let n=V1.maxSafeCoordinateForScale(e),c=[];for(let r of t)V1.checkSafeScaleValue(r.x,n,"scalePath64"),V1.checkSafeScaleValue(r.y,n,"scalePath64"),c.push({x:Math.round(r.x*e),y:Math.round(r.y*e)});return c},scalePaths64(t,e){let n=[];for(let c of t)n.push(te.scalePath64(c,e));return n},scalePathD(t,e){let n=[];for(let c of t)n.push({x:c.x*e,y:c.y*e});return n},scalePathsD(t,e){let n=[];for(let c of t)n.push(te.scalePathD(c,e));return n}};var O0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(O0||(O0={}));var s0;(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"})(s0||(s0={}));var ne=class{constructor(e,n,c=s0.Polygon){D(this,"inPaths");D(this,"joinType");D(this,"endType");D(this,"pathsReversed");D(this,"lowestPathIdx");this.joinType=n,this.endType=c;let r=c===s0.Polygon||c===s0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(n3.stripDuplicates(a,r));if(c===s0.Polygon){let a=n3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},a0=class a0{constructor(e=2,n=0,c=!1,r=!1){D(this,"groupList",[]);D(this,"pathOut",[]);D(this,"normals",[]);D(this,"solution",[]);D(this,"solutionTree",null);D(this,"groupDelta",0);D(this,"delta",0);D(this,"mitLimSqr",0);D(this,"stepsPerRad",0);D(this,"stepSin",0);D(this,"stepCos",0);D(this,"joinType",O0.Bevel);D(this,"endType",s0.Polygon);D(this,"arcTolerance",0);D(this,"mergeGroups",!0);D(this,"miterLimit",2);D(this,"preserveCollinear",!1);D(this,"reverseSolution",!1);D(this,"zCallback");D(this,"deltaCallback",null);D(this,"ZCB",(e,n,c,r,a)=>{(e.z||0)!==0&&(e.z===c.z||e.z===r.z)?a.z=e.z:(c.z||0)!==0&&c.z===n.z?a.z=c.z:(n.z||0)!==0&&n.z===r.z?a.z=n.z:this.zCallback&&this.zCallback(e,n,c,r,a)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=c,this.reverseSolution=r}clear(){this.groupList.length=0}addPath(e,n,c){if(e.length===0)return;let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c){e.length!==0&&this.groupList.push(new ne(e,n,c))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===s0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===s0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/a0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),c=n?D1.Negative:D1.Positive,r=new g2;r.preserveCollinear=this.preserveCollinear,r.reverseSolution=this.reverseSolution!==n,r.zCallback=this.ZCB,r.addSubject(this.solution),this.solutionTree!==null?r.execute(e0.Union,c,this.solutionTree):r.execute(e0.Union,c,this.solution)}execute(e,n){if(Array.isArray(n)){let c=n;c.length=0,this.solution=c,this.executeInternal(e)}else{let c=n;c.clear(),this.solutionTree=c,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let c=n.x-e.x,r=n.y-e.y;if(c===0&&r===0)return{x:0,y:0};let a=1/Math.sqrt(c*c+r*r);return{x:r*a,y:-c*a}}static getLowestPathInfo(e){let n=-1,c=!1,r={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let i of e[a])if(!(i.y<r.y||i.y===r.y&&i.x>=r.x)){if(s===Number.MAX_VALUE){if(s=a0.area(e[a]),s===0)break;c=s<0}n=a,r.x=i.x,r.y=i.y}}return{idx:n,isNegArea:c}}static translatePoint(e,n,c){return{x:e.x+n,y:e.y+c,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=a0.hypotenuse(e.x,e.y);if(a0.almostZero(n))return{x:0,y:0};let c=1/n;return{x:e.x*c,y:e.y*c}}static getAvgUnitVector(e,n){return a0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,c,r){if(V1.isAlmostZero(e.x-n.x)){if(V1.isAlmostZero(c.x-r.x))return{x:0,y:0};let a=(r.y-c.y)/(r.x-c.x),s=c.y-a*c.x;return{x:e.x,y:a*e.x+s}}if(V1.isAlmostZero(c.x-r.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:c.x,y:a*c.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,i=(r.y-c.y)/(r.x-c.x),o=c.y-i*c.x;if(V1.isAlmostZero(a-i))return{x:0,y:0};let l=(o-s)/(a-i);return{x:l,y:a*l+s}}}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,c){let r,a,s=e[n].z||0;if(n===c){let i=Math.abs(this.groupDelta);r={x:Math.round(e[n].x-i*this.normals[n].x),y:Math.round(e[n].y-i*this.normals[n].y),z:s},a={x:Math.round(e[n].x+i*this.normals[n].x),y:Math.round(e[n].y+i*this.normals[n].y),z:s}}else r={x:Math.round(e[n].x+this.groupDelta*this.normals[c].x),y:Math.round(e[n].y+this.groupDelta*this.normals[c].y),z:s},a={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:s};this.pathOut.push(r),this.pathOut.push(a)}doSquare(e,n,c){let r;n===c?r={x:this.normals[n].y,y:-this.normals[n].x}:r=a0.getAvgUnitVector({x:-this.normals[c].y,y:this.normals[c].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=a0.translatePoint(s,a*r.x,a*r.y);let i=a0.translatePoint(s,this.groupDelta*r.y,this.groupDelta*-r.x),o=a0.translatePoint(s,this.groupDelta*-r.y,this.groupDelta*r.x),l=this.getPerpendicD(e[c],this.normals[c]);if(n===c){let h={x:l.x+r.x*this.groupDelta,y:l.y+r.y*this.groupDelta},u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s))),this.pathOut.push(m2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[c]),u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(u)),this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s)))}}doMiter(e,n,c,r){let a=this.groupDelta/(r+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[c].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[c].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,c,r){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*a0.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 a=e[n],s=a.z||0,i={x:this.normals[c].x*this.groupDelta,y:this.normals[c].y*this.groupDelta};n===c&&N5.negate(i),this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});let o=Math.ceil(this.stepsPerRad*Math.abs(r));for(let l=1;l<o;l++)i={x:i.x*this.stepCos-this.stepSin*i.y,y:i.x*this.stepSin+i.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});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 c=0;c<n-1;c++)this.normals.push(a0.getUnitNormal(e[c],e[c+1]));this.normals.push(a0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,c,r){if(m2.equals(n[c],n[r]))return;let a=V1.crossProductD(this.normals[c],this.normals[r]),s=V1.dotProductD(this.normals[c],this.normals[r]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,c,r),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<a0.Tolerance){this.pathOut.push(n[c]);return}if(s>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[c],this.normals[r])),this.pathOut.push(n[c]),this.pathOut.push(this.getPerpendic(n[c],this.normals[c]));else if(s>.999&&this.joinType!==O0.Round)this.doMiter(n,c,r,s);else switch(this.joinType){case O0.Miter:s>this.mitLimSqr-1?this.doMiter(n,c,r,s):this.doSquare(n,c,r);break;case O0.Round:this.doRound(n,c,r,Math.atan2(a,s));break;case O0.Bevel:this.doBevel(n,c,r);break;default:this.doSquare(n,c,r);break}}offsetPolygon(e,n){this.pathOut=[];let c=n.length,r=c-1;for(let a=0;a<c;a++)this.offsetPoint(e,n,a,r),r=a;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let c=[...n].reverse();this.buildNormals(c),this.offsetPolygon(e,c)}offsetOpenPath(e,n){this.pathOut=[];let c=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<a0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case s0.Butt:this.doBevel(n,0,0);break;case s0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let r=1,a=0;r<c;r++)this.offsetPoint(e,n,r,a),a=r;for(let r=c;r>0;r--)this.normals[r]={x:-this.normals[r-1].x,y:-this.normals[r-1].y};if(this.normals[0]=this.normals[c],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,c,c)),Math.abs(this.groupDelta)<a0.Tolerance)this.pathOut.push(n[c]);else switch(this.endType){case s0.Butt:this.doBevel(n,c,c);break;case s0.Round:this.doRound(n,c,c,Math.PI);break;default:this.doSquare(n,c,c);break}for(let r=c-1,a=c;r>0;r--)this.offsetPoint(e,n,r,a),a=r;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===s0.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===O0.Round||e.endType===s0.Round){let c=this.arcTolerance>.01?this.arcTolerance:n*a0.arc_const,r=Math.PI/Math.acos(1-c/n);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}for(let c of e.inPaths){this.pathOut=[];let r=c.length;if(r===1){let a=c[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(c,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=a.z||0;if(e.endType===s0.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=a0.ellipse(a,Math.abs(this.groupDelta),Math.abs(this.groupDelta),i),s!==0)for(let o=0;o<this.pathOut.length;o++)this.pathOut[o].z=s}else{let i=Math.ceil(Math.abs(this.groupDelta)),o={left:a.x-i,top:a.y-i,right:a.x+i,bottom:a.y+i};this.pathOut=[{x:o.left,y:o.top,z:s},{x:o.right,y:o.top,z:s},{x:o.right,y:o.bottom,z:s},{x:o.left,y:o.bottom,z:s}]}this.solution.push(this.pathOut);continue}switch(r===2&&e.endType===s0.Joined&&(this.endType=e.joinType===O0.Round?s0.Round:s0.Square),this.buildNormals(c),this.endType){case s0.Polygon:this.offsetPolygon(e,c);break;case s0.Joined:this.offsetOpenJoined(e,c);break;default:this.offsetOpenPath(e,c);break}}}static stripDuplicates(e,n){let c=e.length,r=[];if(c===0)return r;let a=e[0];r.push(a);for(let s=1;s<c;s++)m2.equals(a,e[s])||(a=e[s],r.push(a));return n&&m2.equals(a,r[0])&&r.pop(),r}static area(e){return V1.area(e)}static sqr(e){return e*e}static ellipse(e,n,c=0,r=0){if(n<=0)return[];c<=0&&(c=n),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((n+c)/2)));let a=Math.sin(2*Math.PI/r),s=Math.cos(2*Math.PI/r),i=s,o=a,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<r;++h){l.push({x:Math.round(e.x+n*i),y:Math.round(e.y+c*o)});let u=i*s-o*a;o=o*s+i*a,i=u}return l}};D(a0,"Tolerance",1e-12),D(a0,"arc_const",.002);var n3=a0;var Eo=BigInt(2);function re(t,e,n){return typeof e=="number"?ce(e0.Union,t,null,e):ce(e0.Union,t,e,n)}function ce(t,e,n,c){let r=[];if(e===null)return r;let a=new g2;return a.addPaths(e,I0.Subject),n!==null&&a.addPaths(n,I0.Clip),a.execute(t,c,r),r}function W5(t,e,n,c,r=2,a=0){let s=new n3(r,a);s.addPaths(t,n,c);let i=[];return s.execute(e,i),i}var n2=1e4,ae=[1,0,0,1,0,0];function J0(){return{layers:new Map,parts:[]}}function k0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function D2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function G6(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 j6=t=>t.map(e=>e.map(([n,c])=>({x:Math.round(n*n2),y:Math.round(c*n2)})));function Kn(t){let e=(c,r,a)=>(r.x-c.x)*(a.y-r.y)-(r.y-c.y)*(a.x-r.x)===0,n=[];for(let c of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],c);)n.pop();let r=n[n.length-1];(!r||r.x!==c.x||r.y!==c.y)&&n.push(c)}for(let c=!0;c&&n.length>=3;){let r=n.length;c=!0,n[r-1].x===n[0].x&&n[r-1].y===n[0].y||e(n[r-2],n[r-1],n[0])?n.pop():e(n[r-1],n[0],n[1])?n.shift():c=!1}return n}var a5=t=>j6(t).map(Kn),i5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/n2,n.y/n2]));function x1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?D1.EvenOdd:D1.NonZero;return i5(re(a5(t),n)).filter(c=>c.length>=3)}function se(t,e,n){if(!e.length)return[];let c=new g2;c.addSubject(a5(e)),n.length&&c.addClip(a5(n));let r=[];return c.execute(t,D1.NonZero,r),i5(r).filter(a=>a.length>=3)}var b0=(t,e)=>e.length?se(e0.Difference,t,e):x1(t),x0=(t,e)=>se(e0.Intersection,t,e),M3=(t,e)=>se(e0.Xor,t,e);function v2(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let c=[];for(let m of e)for(let g=0;g<m.length;g++){let v=m[g],y=m[(g+1)%m.length];(v[0]!==y[0]||v[1]!==y[1])&&c.push([v,y])}if(!c.length)return n==="outside"?t:[];let r=S0(e),a=Math.max(r[2]-r[0],r[3]-r[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=m=>Math.floor(m/a),i=new Map,o=new Map,l=(m,g,v)=>{let y=m.get(g);y?y[y.length-1]!==v&&y.push(v):m.set(g,[v])};c.forEach(([m,g],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let b=0;b<=y;b++){let x=m[0]+(g[0]-m[0])*b/y,M=m[1]+(g[1]-m[1])*b/y;for(let w of[-1,0,1])for(let k of[-1,0,1])l(i,`${s(x)+w},${s(M)+k}`,v)}for(let b=s(Math.min(m[1],g[1]));b<=s(Math.max(m[1],g[1]));b++)l(o,b,v)});let h=(m,g)=>{let v=new Set,y=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let b=0;b<=y;b++){let x=m[0]+(g[0]-m[0])*b/y,M=m[1]+(g[1]-m[1])*b/y;for(let w of i.get(`${s(x)},${s(M)}`)??[])v.add(w)}return v},u=.5/n2,f=m=>{for(let v of i.get(`${s(m[0])},${s(m[1])}`)??[]){let[y,b]=c[v],x=b[0]-y[0],M=b[1]-y[1],w=Math.max(0,Math.min(1,((m[0]-y[0])*x+(m[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(m[0]-y[0]-w*x,m[1]-y[1]-w*M)<=u)return}let g=0;for(let v of o.get(s(m[1]))??[]){let[y,b]=c[v],x=(b[0]-y[0])*(m[1]-y[1])-(m[0]-y[0])*(b[1]-y[1]);y[1]<=m[1]?b[1]>m[1]&&x>0&&g++:b[1]<=m[1]&&x<0&&g--}return g!==0},d=m=>Math.round(m*n2)/n2,p=[];for(let m of t){let g=null,v=()=>{g&&g.length>=2&&p.push(g),g=null};for(let y=1;y<m.length;y++){let b=m[y-1],x=m[y],M=x[0]-b[0],w=x[1]-b[1];if(!M&&!w)continue;let k=[0,1];for(let z of h(b,x)){let[S,L]=c[z],I=L[0]-S[0],q=L[1]-S[1],R=M*q-w*I;if(Math.abs(R)>1e-15){let N=((S[0]-b[0])*q-(S[1]-b[1])*I)/R,G=((S[0]-b[0])*w-(S[1]-b[1])*M)/R;N>0&&N<1&&G>=0&&G<=1&&k.push(N)}else{let N=M*M+w*w;for(let G of[S,L]){let V=((G[0]-b[0])*M+(G[1]-b[1])*w)/N,J=Math.abs((G[0]-b[0])*w-(G[1]-b[1])*M)/Math.sqrt(N);V>0&&V<1&&J<=u&&k.push(V)}}}k.sort((z,S)=>z-S);for(let z=1;z<k.length;z++){if(k[z]-k[z-1]<1e-12)continue;let S=[d(b[0]+M*k[z-1]),d(b[1]+w*k[z-1])],L=[d(b[0]+M*k[z]),d(b[1]+w*k[z])],I=(k[z-1]+k[z])/2,q=f([b[0]+M*I,b[1]+w*I]);if(q!==void 0&&q===(n==="inside")){let R=g?g[g.length-1]:void 0;g&&R&&R[0]===S[0]&&R[1]===S[1]?(L[0]!==R[0]||L[1]!==R[1])&&g.push(L):(v(),g=[S,L])}else v()}}v()}return p}function m0(t,e,n="round",c=.01){if(!t.length)return[];if(e===0)return x1(t);let r=n==="round"?O0.Round:n==="square"?O0.Square:O0.Miter,a=W5(a5(x1(t)),e*n2,r,s0.Polygon,2,c*n2);return i5(a).filter(s=>s.length>=3)}function X5(t,e){if(!t.length||e<=0)return[];let n=W5(j6(t),e/2*n2,O0.Round,s0.Round,2,.01*n2);return i5(n)}function _0(t){if(!t.length)return[];let e=new r5,n=new g2;n.addSubject(a5(t)),n.execute(e0.Union,D1.NonZero,e);let c=[],r=a=>{for(let s=0;s<a.count;s++){let i=a.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),r(h)}c.push(i5(o))}};return r(e),c}function H1(t){let e=0;for(let n=0,c=t.length-1;n<t.length;c=n++)e+=(t[c][0]+t[n][0])*(t[c][1]-t[n][1]);return-e/2}function W6(t){let e=0,n=0,c=0;for(let r of t){if(r.length<3)continue;let[a,s]=r[0];for(let i=0,o=r.length-1;i<r.length;o=i++){let l=r[o][0]-a,h=r[o][1]-s,u=r[i][0]-a,f=r[i][1]-s,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+a*d/2,c+=(h+f)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,c/e]}}function w3(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 s5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function B6(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,c=new Map;for(let[r,a]of t)c.set(r,{regions:a.regions.map(s=>{let i=s.map(o=>s5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>s5(e,i)))});return c}function z3(t,e){return{layers:B6(t.layers,e),parts:t.parts.map(n=>({...n,layers:B6(n.layers,e)}))}}function q2(t){let e=J0();for(let n of t){for(let[c,r]of n.layers){let a=e.layers.get(c)??{regions:[],lines:[]};for(let s of r.regions)a.regions.push(s);for(let s of r.lines)a.lines.push(s);e.layers.set(c,a)}for(let c of n.parts)e.parts.push(c)}return e}function _6(t,e){let n={regions:[],lines:[]};for(let c of t.values()){for(let r of c.regions)n.regions.push(r);for(let r of c.lines)n.lines.push(r)}return new Map([[e,n]])}function o5(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:_6(t.layers,e),parts:t.parts.map(n=>({...n,layers:_6(n.layers,e)}))}}function S0(t){let e=1/0,n=1/0,c=-1/0,r=-1/0;for(let a of t)for(let[s,i]of a)s<e&&(e=s),i<n&&(n=i),s>c&&(c=s),i>r&&(r=i);return e===1/0?null:[e,n,c,r]}function D0(t,e){let n=[];for(let[c,r]of t)if(!e?.(c))for(let a of[...r.regions,...r.lines])n.push(a);return S0(n)}function X6(t){let e=[...t].sort((a,s)=>a[0]-s[0]||a[1]-s[1]);if(e.length<3)return e;let n=(a,s,i)=>(s[0]-a[0])*(i[1]-a[1])-(s[1]-a[1])*(i[0]-a[0]),c=[];for(let a of e){for(;c.length>=2&&n(c[c.length-2],c[c.length-1],a)<=0;)c.pop();c.push(a)}let r=[];for(let a=e.length-1;a>=0;a--){let s=e[a];for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}return r.pop(),c.pop(),c.concat(r)}function Z6(t,e,n,c){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/c)),5)}function k3(t,e,n){let c=[];for(let r=0;r<n;r++){let a=2*Math.PI*r/n;c.push([t*Math.cos(a),e*Math.sin(a)])}return c}function Y6(t,e,n,c){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let r=Math.max(1,Math.ceil(c(n)/4)),a=[],s=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[i,o,l]of s)for(let h=0;h<=r;h++){let u=(l+90*h/r)*Math.PI/180;a.push([i+n*Math.cos(u),o+n*Math.sin(u)])}return a}var J6=Math.PI/180;function O1(t,e){let n=new Array(16).fill(0);for(let c=0;c<4;c++)for(let r=0;r<4;r++)for(let a=0;a<4;a++)n[c*4+r]+=t[c*4+a]*e[a*4+r];return n}function Z5(t,e){let n=Math.cos(e*J6),c=Math.sin(e*J6);return t===0?[1,0,0,0,0,n,-c,0,0,c,n,0,0,0,0,1]:t===1?[n,0,c,0,0,1,0,0,-c,0,n,0,0,0,0,1]:[n,-c,0,0,c,n,0,0,0,0,1,0,0,0,0,1]}var ie=t=>Math.abs(t)<1e-12?0:t;function K0(t){if(t.matrix)return t.matrix.map(ie);let[e,n,c]=t.rotate,r=O1(Z5(2,c),O1(Z5(1,n),Z5(0,e)));return r[3]=t.at[0],r[7]=t.at[1],r[11]=t.at[2],r.map(ie)}function A3(t,e,n,c){return[t[0]*e+t[1]*n+t[2]*c+t[3],t[4]*e+t[5]*n+t[6]*c+t[7],t[8]*e+t[9]*n+t[10]*c+t[11]]}function t7(t){let[e,n,c]=[t[3],t[7],t[11]],r=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[r[0],r[1],r[2],-(r[0]*e+r[1]*n+r[2]*c),r[3],r[4],r[5],-(r[3]*e+r[4]*n+r[5]*c),r[6],r[7],r[8],-(r[6]*e+r[7]*n+r[8]*c),0,0,0,1]}function Y5(t){let[e,n,c,r]=[1/0,1/0,-1/0,-1/0];for(let a of t)for(let[s,i]of a)e=Math.min(e,s),n=Math.min(n,i),c=Math.max(c,s),r=Math.max(r,i);return[e,n,c,r]}function l5(t){let[e,n,c,r]=Y5(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,c])for(let o of[n,r])for(let l of[0,t.thickness]){let h=A3(t.matrix,i,o,l);for(let u=0;u<3;u++)a[u]=Math.min(a[u],h[u]),s[u]=Math.max(s[u],h[u])}return[a,s]}function n7(t,e,n=10){let c=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(l5))for(let f=0;f<3;f++)c[f]=Math.min(c[f],h[f]),r[f]=Math.max(r[f],u[f]);let a=e.map(h=>Y5(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),r[0]-c[0]),i=0,o=0,l=0;return e.map((h,u)=>{let[f,d,p,m]=a[u];i>0&&i+p-f>s&&(i=0,o+=l+n,l=0);let g=[1,0,0,r[0]+n+i-f,0,1,0,c[1]+o-d,0,0,1,c[2],0,0,0,1];return i+=p-f+n,l=Math.max(l,m-d),{...h,matrix:g.map(ie)}})}var Qn=(t,e,n)=>[0,1,2].every(c=>t[0][c]<e[1][c]-n&&e[0][c]<t[1][c]-n),S3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],oe=(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]],K6=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],J5=t=>[t[2],t[6],t[10]],Q6=t=>[t[3],t[7],t[11]],e9=(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 L3(t,e,n){let c=n[0]*n[0]+n[1]*n[1],r=[];for(let a of t)for(let s=0,i=a.length-1;s<a.length;i=s++){let o=a[i],l=a[s],h=n[0]*(o[1]-e[1])-n[1]*(o[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=o[0]+(l[0]-o[0])*f-e[0],p=o[1]+(l[1]-o[1])*f-e[1];r.push((d*n[0]+p*n[1])/c)}return r.sort((a,s)=>a-s)}function le(t,e,n){let c=0,r=0,a=0;for(;r+1<t.length&&a+1<e.length;){let s=Math.min(t[r+1],e[a+1])-Math.max(t[r],e[a]);s>n&&(c+=s),t[r+1]<e[a+1]?r+=2:a+=2}return c}function K5(t,e,n,c){let r=t+n,a=e-n;if(a<=r)return{at:[],size:0};let s=Math.max(4,Math.ceil((a-r)/c));return{at:Array.from({length:s},(i,o)=>r+(a-r)*(o+.5)/s),size:(a-r)/s}}function e7(t,e,n){let c=A3(t,e[0],e[1],e[2]),r=e9(t,n);return[[c[0],c[1]],[r[0],r[1]]]}function t9(t,e,n,c,r,a,s){let i=J5(t.matrix),o=J5(e.matrix),l=oe(i,o),h=Math.hypot(...l),u=[l[0]/h,l[1]/h,l[2]/h],f=oe(u,i),d=S3(o,f),p=Q6(t.matrix),m=S3(o,Q6(e.matrix)),g=1/0,v=-1/0;for(let w of e.outline)for(let[k,z]of w)for(let S of[0,e.thickness]){let L=A3(e.matrix,k,z,S),I=S3(i,[L[0]-p[0],L[1]-p[1],L[2]-p[2]]);I<g&&(g=I),I>v&&(v=I)}let y=K5(Math.max(0,g),Math.min(t.thickness,v),r,a),b=1/0,x=-1/0;for(let w of t.outline)for(let[k,z]of w){let S=A3(t.matrix,k,z,0),L=S3(f,[S[0]-p[0],S[1]-p[1],S[2]-p[2]]);L<b&&(b=L),L>x&&(x=L)}let M=0;for(let w of y.at){let k=K6(p,i,w),z=(m-S3(o,k))/d,S=(m+e.thickness-S3(o,k))/d,L=K5(Math.max(b,Math.min(z,S)),Math.min(x,Math.max(z,S)),r,a);for(let I of L.at){let q=K6(k,f,I),[R,N]=e7(n,q,u),[G,V]=e7(c,q,u);if(M+=le(L3(t.outline,R,N),L3(e.outline,G,V),r)*y.size*L.size,M>s)return!0}}return!1}function n9(t,e,n,c,r,a){let s=[0,1,2,3].flatMap(k=>[0,1,2,3].map(z=>{let S=0;for(let L=0;L<4;L++)S+=n[k*4+L]*e.matrix[L*4+z];return S})),i=s[11],o=s[11]+s[10]*e.thickness,l=Math.min(t.thickness,Math.max(i,o))-Math.max(0,Math.min(i,o));if(l<=c)return!1;let h=e.outline.map(k=>k.map(([z,S])=>[s[0]*z+s[1]*S+s[3],s[4]*z+s[5]*S+s[7]])),[u,f,d,p]=Y5(t.outline),[m,g,v,y]=Y5(h),b=K5(Math.max(f,g),Math.min(p,y),c,r),x=0;for(let k of b.at)if(x+=le(L3(t.outline,[0,k],[1,0]),L3(h,[0,k],[1,0]),c)*b.size*l,x>a)return!0;let M=K5(Math.max(u,m),Math.min(d,v),c,r),w=0;for(let k of M.at)if(w+=le(L3(t.outline,[k,0],[0,1]),L3(h,[k,0],[0,1]),c)*M.size*l,w>a)return!0;return!1}function c7(t,e=1/0,n=.05,c=.25,r=.1){let a=t.map(l5),s=t.map(h=>t7(h.matrix)),i=t.map((h,u)=>u).sort((h,u)=>a[h][0][0]-a[u][0][0]),o=[],l=0;for(let h=0;h<i.length;h++)for(let u=h+1;u<i.length;u++){let f=i[h],d=i[u];if(a[d][0][0]>=a[f][1][0]-n)break;if(!Qn(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[p,m]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]];(Math.hypot(...oe(J5(p.matrix),J5(m.matrix)))<1e-9?n9(p,m,g,n,c,r):t9(p,m,g,v,n,c,r))&&o.push([p,m])}return{found:o,complete:!0}}function R0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var he=R0(0,0,0);function L0(t){return t7(t)}function r7(t,e,n=t.angle,c=t.x1){let r=c-t.x0;if(!n||!(r>0))return R0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return O1(R0(t.x0,0,s),O1(Z5(1,-n),R0(-t.x0-r,0,-s)))}function h5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function Q5(t,e){let n=[R0(0,0,0)];for(let c of h5(t))n.push(O1(n[n.length-1],r7(c,e)));return n}function ue(t,e,n){let c=h5(t),r=Q5(c,e);for(let a=c.length-1;a>=0;a--){let s=c[a];if(n[0]>=s.x1)return A3(r[a+1],...n);if(n[0]>s.x0){let i=(n[0]-s.x0)/(s.x1-s.x0),o=O1(r[a],r7(s,e,s.angle*i,n[0]));return A3(o,...n)}}return n}function a7(t,e){return h5(t).filter(n=>(n.x0+n.x1)/2<e).length}function e4(t){if(!t.bends?.length)return[t];let e=h5(t.bends),n=Q5(e,t.thickness),c=1e7,r=[];for(let a=0;a<=e.length;a++){let s=a===0?-c:e[a-1].x1,i=a===e.length?c:e[a].x0;if(!(i>s))continue;let o=[[s,-c],[i,-c],[i,c],[s,c]],l=x0(t.outline,[o]);l.length&&r.push({...t,outline:l,bends:void 0,matrix:O1(t.matrix,n[a])})}return r}var c9=2e3;function fe(t,e,n=2){if(!e?.length)return _0(t);let c=1e7,r=1/0,a=-1/0;for(let f of t)for(let[d]of f)r=Math.min(r,d),a=Math.max(a,d);let s=h5(e).map(f=>[Math.max(f.x0,r),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,p])=>f+(p-d),0),o=Math.max(n,i/c9),l=[];for(let[f,d]of s){let p=Math.max(1,Math.ceil((d-f)/o));for(let m=0;m<=p;m++)l.push(f+(d-f)*m/p)}let h=[-c,...l.sort((f,d)=>f-d),c],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-c],[h[f+1],-c],[h[f+1],c],[h[f],c]];for(let p of _0(x0(t,[d])))u.push(p)}return u}var N2=1e6,t4=.01,s7=t=>H1(t)<0?[...t].reverse():t;function r9(t,e){let n=O1(L0(t.matrix),e.matrix),[c,r]=[n[8],n[9]],a=Math.hypot(c,r);if(a<1e-9)return[];let s=0,i=e.thickness,o=k=>(-n[11]-Math.max(n[10]*s,n[10]*i)+k)/a,l=k=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-k)/a;if(!(l(t4)>o(t4)))return[];let[h,u]=[c/a,r/a],[f,d]=[-u,h],p=(k,z)=>[[h*k-f*N2,u*k-d*N2],[h*z-f*N2,u*z-d*N2],[h*z+f*N2,u*z+d*N2],[h*k+f*N2,u*k+d*N2]],m=1/0,g=-1/0;for(let k of e.outline)for(let[z,S]of k)for(let L of[s,i]){let I=n[8]*z+n[9]*S+n[10]*L+n[11];I<m&&(m=I),I>g&&(g=I)}if(Math.min(t.thickness,g)-Math.max(0,m)<Math.min(1,t.thickness/2))return[];let v=(k,z)=>x0(e.outline,[s7(p(k,z))]).filter(S=>Math.abs(H1(S))>1e-6);if(!v(o(t4),l(t4)).length)return[];let y=v(o(0),l(0));if(!y.length)return[];let b=k=>([z,S])=>[n[0]*z+n[1]*S+n[2]*k+n[3],n[4]*z+n[5]*S+n[6]*k+n[7]],x=n[0]*n[5]-n[1]*n[4]<0,M=k=>y.map(z=>{let S=z.map(b(k));return x?S.reverse():S}),w=[];for(let k of y)for(let z=0;z<k.length;z++){let S=k[z],L=k[(z+1)%k.length],I=[b(s)(S),b(s)(L),b(i)(L),b(i)(S)];Math.abs(H1(I))>1e-9&&w.push(s7(I))}return x1([...M(s),...M(i),...w],"nonzero")}function i7(t,e,n){let c=[];for(let a of e)for(let s of r9(t,a))c.push(s);if(!c.length)return[];let r=_0(x0(x1(c),t.outline)).filter(a=>a.reduce((s,i)=>s+H1(i),0)>1e-4);return r.length?m0(r.flat(),n/2,"miter"):[]}var Q0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",P2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",l7=t=>typeof t=="number",F0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",G0=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function de(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let c of e)de(t,c,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function n4(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let c=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(c>e)throw new Error(`a range of ${c} items is more than the limit of ${e}`);for(let r=0;r<c;r++)n.push(t.start+r*t.step);return n}function h0(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 o7=(t,e,n)=>Q0(t)&&Q0(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:F0(t)&&F0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([c,r])=>e.fields.has(c)&&C3(r,e.fields.get(c),n)):t===e;function C3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return o7(t,e,n);let c=new Map,r=[],a=(s,i)=>{let o=c.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||c.set(s,o=new Set),o.add(i),r.push([s,i,0]),!0)};if(!a(t,e))return!1;for(;r.length;){let s=r[r.length-1];if(s[2]===s[0].length){r.pop();continue}let i=s[0][s[2]],o=s[1][s[2]++];if(n?.(),Array.isArray(i)&&Array.isArray(o)?!a(i,o):!o7(i,o,n))return!1}return!0}function j0(t){return t===void 0?"undef":Array.isArray(t)?"list":Q0(t)?"range":P2(t)?"function":F0(t)?"record":typeof t}function a9(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?C2(t):Q0(t)?`[${C2(t.start)}:${C2(t.step)}:${C2(t.end)}]`:P2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:F0(t)?"{}":String(t)}function P3(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 c=[],r=0,a=l=>{c.push(l),r+=l.length},s=[],i=t;for(;;){Array.isArray(i)?(a("["),s.push({items:i,i:0,close:"]"})):F0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(a9(i));let l=!1;for(;s.length&&!l&&r<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&a(", "),h.keys&&a(`${h.keys[h.i]} = `),i=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||r>e)break}let o=c.join("");return r>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function h7(t,e,n){let c=[],r=0;for(let a of t){c.length&&(r+=e.length);let s=P3(a,n-r);if(!s.whole)return;r+=s.text.length,c.push(s.text)}return c.join(e)}function q0(t){let e=P3(t,200,!0);return e.whole?e.text:e.text+"..."}var g0=t=>typeof t=="string"?t:q0(t);function A0(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 C2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function T3(t,e=.02){let n=[],c=[],r=[],a=[0,0],s=[0,0],i=l=>{r.length>=2&&(l?n:c).push(r),r=[]},o=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")i(!1),a=s=[l.x,l.y],r=[s];else if(l.type==="L")s=[l.x,l.y],r.push(s);else if(l.type==="Q"){let[h,u]=s,f=o(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 p=d/f,m=1-p;r.push([m*m*h+2*m*p*l.x1+p*p*l.x,m*m*u+2*m*p*l.y1+p*p*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,f=o(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 p=d/f,m=1-p;r.push([m*m*m*h+3*m*m*p*l.x1+3*m*p*p*l.x2+p*p*p*l.x,m*m*m*u+3*m*m*p*l.y1+3*m*p*p*l.y2+p*p*p*l.y])}s=[l.x,l.y]}else i(!0),s=a,r=[a];return i(!1),{closed:n,open:c}}function E3(t,e=Math.PI/2,n){let c=x=>/^[a-zA-Z]$/.test(x),r=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,i="",o=0,l=0,h=0,u=0,f=0,d=0,p=0,m=0,g="",v=()=>{let x=r[s++];if(x===void 0||c(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},y=()=>{let x=r[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(r[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{b()}catch(x){if(!n)throw x;n(x.message)}return a;function b(){for(;s<r.length;){if(c(r[s]))i=r[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${r[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=i===i.toLowerCase(),M=i.toUpperCase(),w=x?o:0,k=x?l:0;if(M==="M")o=w+v(),l=k+v(),h=o,u=l,a.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=w+v(),l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="H")o=w+v(),a.push({type:"L",x:o,y:l});else if(M==="V")l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let z,S;if(M==="C")z=w+v(),S=k+v();else{let q=g==="C"||g==="S";z=q?2*o-f:o,S=q?2*l-d:l}let L=w+v(),I=k+v();o=w+v(),l=k+v(),f=L,d=I,a.push({type:"C",x1:z,y1:S,x2:L,y2:I,x:o,y:l})}else if(M==="Q"||M==="T"){let z,S;if(M==="Q")z=w+v(),S=k+v();else{let L=g==="Q"||g==="T";z=L?2*o-p:o,S=L?2*l-m:l}o=w+v(),l=k+v(),p=z,m=S,a.push({type:"Q",x1:z,y1:S,x:o,y:l})}else if(M==="A"){let z=v(),S=v(),L=v(),I=y(),q=y(),R=w+v(),N=k+v();a.push(...s9(o,l,z,S,L,I,q,R,N,e)),o=R,l=N}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);g=M}}}function s9(t,e,n,c,r,a,s,i,o,l=Math.PI/2){if(n===0||c===0||t===i&&e===o)return[{type:"L",x:i,y:o}];n=Math.abs(n),c=Math.abs(c);let h=r*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-i)/2,p=(e-o)/2,m=u*d+f*p,g=-f*d+u*p,v=m*m/(n*n)+g*g/(c*c);v>1&&(n*=Math.sqrt(v),c*=Math.sqrt(v));let y=n*n*c*c-n*n*g*g-c*c*m*m,b=n*n*g*g+c*c*m*m,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*g/c,w=-x*c*m/n,k=u*M-f*w+(t+i)/2,z=f*M+u*w+(e+o)/2,S=(V,J,o1,Z)=>Math.atan2(V*Z-J*o1,V*o1+J*Z),L=S(1,0,(m-M)/n,(g-w)/c),I=S((m-M)/n,(g-w)/c,(-m-M)/n,(-g-w)/c);!s&&I>0&&(I-=2*Math.PI),s&&I<0&&(I+=2*Math.PI);let q=Math.ceil(Math.abs(I)/l),R=[],N=V=>[k+n*Math.cos(V)*u-c*Math.sin(V)*f,z+n*Math.cos(V)*f+c*Math.sin(V)*u],G=V=>[-n*Math.sin(V)*u-c*Math.cos(V)*f,-n*Math.sin(V)*f+c*Math.cos(V)*u];for(let V=0;V<q;V++){let J=L+I*V/q,o1=L+I*(V+1)/q,Z=4/3*Math.tan((o1-J)/4),p1=N(J),E=N(o1),$=G(J),X=G(o1);R.push({type:"C",x1:p1[0]+Z*$[0],y1:p1[1]+Z*$[1],x2:E[0]-Z*X[0],y2:E[1]-Z*X[1],x:E[0],y:E[1]})}return R}var C0=Math.PI/180,P1=(t,e,n)=>({params:t.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function g7(t,e,n){return t.order?[]:t.params.filter((c,r)=>r<e.length&&n.has(c))}function v7(t,e,n){if(t.rest){let a=[...e];return t.params.forEach((s,i)=>{n.has(s)&&(a[i]=n.get(s))}),a}if(!t.order)return t.params.map((a,s)=>n.has(a)?n.get(a):e[s]);let c=e.length+t.params.filter(a=>n.has(a)).length,r=t.order(c).filter(a=>!n.has(a));return t.params.map(a=>n.has(a)?n.get(a):e[r.indexOf(a)])}function pe(t,e,n,c){let r=h7(t,e,n.maxLength);if(r===void 0)throw new Error(`${c}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(r.length/8)),r}function R1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${j0(t)}`);return t}function c2(t,e,n){if(Array.isArray(t))return t;if(Q0(t))return n4(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${j0(t)}`)}var i9=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function y7(t,e,n){if(i9.has(t))return 0;let c=0;for(let r of e)if(typeof r=="string")c+=r.length;else if(Array.isArray(r))c+=t==="len"?0:r.length;else if(Q0(r)&&r.step!==0){let a=Math.floor((r.end-r.start)/r.step)+1;a>0&&(c+=Math.min(a,n+1))}return c}var N0=t=>P1("x",e=>typeof e[0]=="number"?r2(t(e[0])):void 0);function r2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function o9(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 u7(t,e,n){let c=t.length===1&&Array.isArray(t[0])?t[0]:t;if(c.length)return e(c.map(r=>R1(r,n)))}var f5={abs:N0(Math.abs),sign:N0(Math.sign),floor:N0(Math.floor),ceil:N0(Math.ceil),round:N0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:N0(Math.sqrt),exp:N0(Math.exp),ln:N0(Math.log),log:P1("x, base",(t,e)=>e.given<2?r2(Math.log10(R1(t[0],"log"))):Math.log(R1(t[0],"log"))/Math.log(R1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:N0(t=>Math.sin(t*C0)),cos:N0(t=>Math.cos(t*C0)),tan:N0(t=>Math.tan(t*C0)),asin:N0(t=>Math.asin(t)/C0),acos:N0(t=>Math.acos(t)/C0),atan:N0(t=>Math.atan(t)/C0),atan2:P1("y, x",t=>r2(Math.atan2(R1(t[0],"atan2"),R1(t[1],"atan2"))/C0)),pow:P1("x, y",t=>Math.pow(R1(t[0],"pow"),R1(t[1],"pow"))),min:P1("values...",t=>u7(t,e=>e.reduce((n,c)=>c<n?c:n,1/0),"min")),max:P1("values...",t=>u7(t,e=>e.reduce((n,c)=>c>n?c:n,-1/0),"max")),clamp:P1("x, low, high",t=>Math.min(Math.max(R1(t[0],"clamp"),R1(t[1],"clamp")),R1(t[2],"clamp"))),lerp:P1("a, b, t",t=>{let e=R1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((c,r)=>R1(c,"lerp")+(R1(n[r],"lerp")-R1(c,"lerp"))*e)}return R1(t[0],"lerp")+(R1(t[1],"lerp")-R1(t[0],"lerp"))*e}),norm:P1("v",(t,e)=>Math.sqrt(c2(t[0],"norm",e).reduce((n,c)=>n+R1(c,"norm")**2,0))),cross:P1("a, b",(t,e)=>{let n=c2(t[0],"cross",e).map(r=>R1(r,"cross")),c=c2(t[1],"cross",e).map(r=>R1(r,"cross"));return n.length===2?n[0]*c[1]-n[1]*c[0]:[n[1]*c[2]-n[2]*c[1],n[2]*c[0]-n[0]*c[2],n[0]*c[1]-n[1]*c[0]]}),len:P1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:F0(t[0])?t[0].fields.size:void 0),keys:P1("record",t=>F0(t[0])?[...t[0].fields.keys()]:void 0),merge:P1("a, b",t=>{if(!F0(t[0])||!F0(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((c,r)=>c+(Array.isArray(r)?r.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(c=>Array.isArray(c)?c:[c])}),reverse:P1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...c2(t[0],"reverse",e)].reverse()),sum:P1("values",(t,e)=>c2(t[0],"sum",e).reduce((n,c)=>n+R1(c,"sum"),0)),slice:P1("value, start, end",(t,e)=>{let c=(typeof t[0]=="string"?[...t[0]]:c2(t[0],"slice",e)).slice(R1(t[1]??0,"slice"),t[2]===void 0?void 0:R1(t[2],"slice"));return typeof t[0]=="string"?c.join(""):c}),str:P1("...",(t,e)=>pe(t,"",e,"str")),chr:P1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(R1(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)=>pe(c2(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:P1("value, list",(t,e)=>{let c=(typeof t[1]=="string"?[...t[1]]:c2(t[1],"search",e)).findIndex(r=>C3(r,t[0],e.step));return c<0?void 0:c}),contains:P1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(pe([t[1]],"",e,"contains")):c2(t[0],"contains",e).some(n=>C3(n,t[1],e.step))),lookup:P1("x, table",(t,e)=>{let n=R1(t[0],"lookup"),c=c2(t[1],"lookup",e);if(!c.length)return;let r=c.map(a=>[R1(a[0],"lookup"),R1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=r[0][0])return r[0][1];for(let a=1;a<r.length;a++)if(n<=r[a][0]){let[s,i]=r[a-1],[o,l]=r[a];return i+(n-s)/(o-s)*(l-i)}return r[r.length-1][1]}),rands:P1("min, max, count, seed",t=>{let e=R1(t[0],"rands"),n=R1(t[1],"rands"),c=R1(t[2],"rands"),r=o9(t[3]===void 0?1:R1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(n-e)*r())}),is_num:P1("value",t=>l7(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=>F0(t[0])),is_undef:P1("value",t=>t[0]===void 0),is_function:P1("value",t=>P2(t[0])),type_of:P1("value",t=>j0(t[0])),path_length:P1("points",(t,e)=>{let n=u5(t[0],"path_length",e),c=0;for(let r=1;r<n.length;r++)c+=Math.hypot(n[r][0]-n[r-1][0],n[r][1]-n[r-1][1]);return c}),point_at:P1("points, s",(t,e)=>f7(u5(t[0],"point_at",e),R1(t[1],"point_at")).point),heading_at:P1("points, s",(t,e)=>r2(f7(u5(t[0],"heading_at",e),R1(t[1],"heading_at")).heading)),offset_path:P1("points, d, closed",(t,e)=>{let n=u5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),c=R1(t[1],"offset_path"),r=t[2]===!0,a=r&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(a&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let s=n.length,i=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],p=Math.hypot(f-h,d-u);return[-(d-u)/p,(f-h)/p]},o=n.map(([l,h],u)=>{let f=!r&&u===0,d=!r&&u===s-1,p=i(f?0:(u-1+s)%s),m=i(d?s-2:u),[g,v]=[p[0]+m[0],p[1]+m[1]],y=Math.hypot(g,v);if(y<1e-9)[g,v]=p;else{let b=Math.min(2/(y*y),4/y);[g,v]=[g*b,v*b]}return[r2(l+c*g),r2(h+c*v)]});return a?[...o,o[0]]:o}),train_for:P1("ratio, stages, pinion, wheel",(t,e)=>{let n=R1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let c=t[1]===void 0?2:R1(t[1],"train_for");if(!(c===1||c===2||c===3))throw new Error("train_for(): stages must be 1, 2 or 3");let r=(v,y,b)=>{if(v===void 0)return y;if(!Array.isArray(v)||v.length!==2||!v.every(w=>typeof w=="number"))throw new Error(`train_for(): ${b} must be [fewest, most] teeth`);let[x,M]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(x>=6&&M>=x&&M<=400))throw new Error(`train_for(): ${b} teeth must be from 6 to 400, fewest first`);return[x,M]},[a,s]=r(t[2],[10,20],"pinion"),[i,o]=r(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=a;v<=s;v++)for(let y=Math.max(i,v);y<=o;y++)u.push([v,y]);let f,d=v=>{let y=v.reduce((M,[w,k])=>M*k/w,1),b=Math.abs(y/h-1),x=v.reduce((M,[w,k])=>M+w+k,0);(!f||b<f.err-1e-12||Math.abs(b-f.err)<=1e-12&&x<f.teeth)&&(f={stages:v.map(M=>[...M]),err:b,teeth:x})},p=(v,y)=>{e.step();for(let b=a;b<=s;b++)for(let x of[Math.floor(y*b),Math.ceil(y*b)])x>=Math.max(i,b)&&x<=o&&d([...v,[b,x]])};if(c===1)p([],h);else for(let v=0;v<u.length;v++){let y=u[v][1]/u[v][0];if(c===2)p([u[v]],h/y);else for(let b=v;b<u.length;b++)p([u[v],u[b]],h/y/(u[b][1]/u[b][0]))}if(!f)throw new Error(`train_for(): no train of ${c} stages reaches a ratio of ${n}`);let m=f.stages.map(([v,y])=>l?[y,v]:[v,y]),g=m.reduce((v,[y,b])=>v*b/y,1);return{type:"record",fields:new Map([["stages",m],["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:R1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let c=T3(E3(t[0]),n),r=[...c.closed.map(a=>[...a,a[0]]),...c.open];return e.step(r.reduce((a,s)=>a+s.length,0)),r.map(a=>a.map(([s,i])=>[s,i]))}),spline_points:P1("points, steps, closed",(t,e)=>{let n=u5(t[0],"spline_points",e),c=t[1]===void 0?8:Math.floor(R1(t[1],"spline_points"));if(!(c>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*c>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*c),ge(n,c,t[2]===!0)}),rotation:P1("angles",t=>{let[e,n,c]=me(t[0],"rotation");return d9(p7(f9(c),p7(u9(n),h9(e))))}),euler:P1("matrix",t=>m7(l9(t[0],"euler"))),orient:P1("x, z",t=>{let e=d7(me(t[0],"orient"),"orient"),n=me(t[1]??[0,0,1],"orient"),c=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=d7([n[0]-c*e[0],n[1]-c*e[1],n[2]-c*e[2]],"orient");let r=[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 m7([[e[0],r[0],n[0]],[e[1],r[1],n[1]],[e[2],r[2],n[2]]])})};function u5(t,e,n){return c2(t,e,n).map((r,a)=>{if(!Array.isArray(r)||typeof r[0]!="number"||typeof r[1]!="number")throw new Error(`${e}(): points[${a}] must be an [x, y] point`);return[r[0],r[1]]})}function f7(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([o,l],h)=>h===0||o!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let c=0,r=0;for(;c<n.length-2;c++){let o=Math.hypot(n[c+1][0]-n[c][0],n[c+1][1]-n[c][1]);if(r+o>=e)break;r+=o}let[a,s]=[n[c],n[c+1]],i=(e-r)/Math.hypot(s[0]-a[0],s[1]-a[1]);return{point:[a[0]+(s[0]-a[0])*i,a[1]+(s[1]-a[1])*i],heading:Math.atan2(s[1]-a[1],s[0]-a[0])/C0}}function me(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 d7(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 l9(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(c=>typeof c=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var h9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[1,0,0],[0,e,-n],[0,n,e]]},u9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,0,n],[0,1,0],[-n,0,e]]},f9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,-n,0],[n,e,0],[0,0,1]]},p7=(t,e)=>t.map(n=>[0,1,2].map(c=>n[0]*e[0][c]+n[1]*e[1][c]+n[2]*e[2][c])),d9=t=>t.map(e=>e.map(r2));function m7(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,c=Math.atan2(-t[0][1],t[1][1])/C0;return[0,n,r2(c)]}return[r2(Math.atan2(t[2][1],t[2][2])/C0),r2(Math.asin(e)/C0),r2(Math.atan2(t[1][0],t[0][0])/C0)]}function ge(t,e,n=!1){if(t.length<3)return t.map(([s,i])=>[s,i]);let c=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=t.length){let[i,o]=[t[t.length-1],t[t.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return t[s]},r=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[i,o,l,h]=[c(s-1),c(s),c(s+1),c(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,p=d*f;r.push([0,1].map(m=>.5*(2*o[m]+(-i[m]+l[m])*f+(2*i[m]-5*o[m]+4*l[m]-h[m])*d+(-i[m]+3*o[m]-3*l[m]+h[m])*p)))}}return r.push(n?r[0]:[t[t.length-1][0],t[t.length-1][1]]),r}function c3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var d5=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function p9(t,e,n,c){if(e==="flat")return[];let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===1:i%2===0)&&s.push(d5(i*a,-1,(i+1)*a,n));return s}function c4(t,e,n,c,r){let a=[([o,l])=>[o,l],([o,l])=>[t-l,o],([o,l])=>[t-o,e-l],([o,l])=>[l,e-o]],s=[t,e,t,e],i=[];return n.forEach((o,l)=>{for(let h of p9(s[l],o,c,r))i.push(h.map(a[l]))}),b0([d5(0,0,t,e)],i)}function b7(t,e,n,c){let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===0:i%2===1)&&s.push(d5(i*a,-n/2,(i+1)*a,n/2));return s}function x7(t,e,n,c,r){let a=d5(-t/2,-1,t/2,e),s=d5(-n/2,r,n/2,r+c);return[a,s]}function M7(t,e,n,c,r){let a=[],s=r+c,i=Math.floor(t/n),o=(t-i*n)/2;for(let l=0;l<=i;l++){let h=o+l*n,u=l%2===0?c:c-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?c:0),p=Math.min(f+r,e-(l%2===0?c:0));p-d>=c/2&&a.push([[h,d],[h,p]])}}return a}var T2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var i1=class extends Error{constructor(n,c){super(c?`${n} (${T2(c)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,c&&(this.line=c.line,this.col=c.col,this.file=c.file)}addFrame(n,c,r){let a=this.trace.find(s=>s.name===c&&s.line===r.line&&s.col===r.col&&s.file===r.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:c,line:r.line,col:r.col,...r.file&&{file:r.file},count:1})}},m9=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function p5(t,e){let n=[],c=[],r=0,a=1,s=0,i=()=>({line:a,col:r-s+1,offset:r,...e&&{file:e}}),o=l=>{for(let h=0;h<l;h++)t[r]===`
|
|
7
|
-
`&&(a++,s=
|
|
8
|
-
`){
|
|
9
|
-
`,
|
|
10
|
-
`,
|
|
11
|
-
`;else if(d==="t")f+=" ";else if(d==="u"){let p=t.slice(
|
|
12
|
-
`)throw new i1("Unclosed string",h);f+=t[r],o(1)}if(r>=t.length)throw new i1("Unclosed string",h);o(1),n.push({type:"str",value:f,pos:h,end:r});continue}if(l==="<"&&/^<[A-Za-z0-9_./-]+>/.test(t.slice(r))){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([A-Za-z0-9_./-]+)>/.exec(t.slice(r));n.push({type:"str",value:d[1],pos:h,end:r+d[0].length}),o(d[0].length);continue}}let u=m9.find(f=>t.startsWith(f,r));if(!u)throw new i1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:r+u.length}),o(u.length)}return n.push({type:"eof",value:"",pos:i(),end:r}),{tokens:n,comments:c}}var I3={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",doc:"a sheet or strip of paper"},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"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb; give it shape = "ball"'},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"}},m5={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var ve=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function a2(t,e){let{tokens:n,comments:c}=p5(t,e),r=new ye(n),a=[];for(;!r.at("eof");)a.push(...r.statement());return{program:{body:a},comments:c}}var g5=class g5{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,c=0){let r=this.peek(c);return r.type===e&&(n===void 0||r.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 c=n.type==="eof"?"end of file":`"${n.value}"`;throw new i1(`${e}, found ${c}`,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"||ve.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 s=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),s.push(...this.statement());return this.next(),[{kind:"block",body:s,pos:e.pos}]}if(this.isK("module")){this.next();let s=this.ident(),i=this.params();return[{kind:"module",name:s.value,params:i,body:this.body(),pos:e.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),i=this.params();this.expectP("=");let o=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:i,body:o,pos:e.pos,namePos:s.pos}]}if(this.isK("use")||this.isK("include")){this.next();let s=this.peek();return s.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:s.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("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let i=this.body(),o=[];return this.isK("else")&&(this.next(),o=this.body()),[{kind:"if",cond:s,then:i,else:o,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 s=this.ident().value;this.next();let i=this.peek().pos.offset,o=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:o,span:[i,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let c=this.peek();(c.type!=="id"||ve.has(c.value))&&this.fail("Expected a statement"),this.next();let r=this.args(),a=this.body();return[{kind:"call",name:c.value,args:r,children:a,modifier:n,pos:c.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(),c=null;this.isP("=")&&(this.next(),c=this.expr()),e.push({name:n.value,default:c,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 c=this.params(),r=this.expr();return{kind:"lambda",params:c,body:r,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let c=this.assigns(),r=this.expr();return{kind:"let",assigns:c,body:r,pos:e.pos,end:this.last()}}let n=this.binary(0);if(this.isP("?")){this.next();let c=this.expr();this.expectP(":");let r=this.expr();return{kind:"ternary",cond:n,then:c,else:r,pos:e.pos}}return n}binary(e){if(e>=g5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&g5.LEVELS[e].includes(this.peek().value);){let c=this.next(),r=this.binary(e+1);n={kind:"binary",op:c.value,left:n,right:r,pos:c.pos}}return n}unary(){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 c=this.expr();this.expectP("]"),e={kind:"index",target:e,index:c,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}):(ve.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 c=this.ident();if(n.some(r=>r.name===c.value))throw new i1(`Field ${c.value} is given twice`,c.pos);if(this.expectP("="),n.push({name:c.value,value:this.expr(),pos:c.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 r=null,a=this.expr();return this.isP(":")&&(this.next(),r=a,a=this.expr()),this.expectP("]"),{kind:"range",start:n,step:r,end:a,pos:e.pos}}let c=[{kind:"item",expr:n}];return this.listRest(c,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(),c=this.listItem();return{kind:"for",assigns:n,body:c,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let c=this.listItem(),r=null;return this.isK("else")&&(this.next(),r=this.listItem()),{kind:"if",cond:n,then:c,else:r}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),c=this.listItem();return{kind:"let",assigns:n,body:c,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()}}};g5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var ye=g5;var H=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),B1=(t,e,n)=>({...H(t,e,n),named:!0}),be="max(3 * $thickness, 6)",r4=[H("value")],g9=[H("x")],U0=(t,e)=>({name:t,kind:"function",params:g9,section:"Numbers and vectors",doc:e}),r3=(t,e)=>({name:t,kind:"function",params:r4,section:"Types",doc:`Whether the value is ${e}`}),w7=(t,e)=>({name:t,kind:"function",params:[H("text","The text to measure",'""'),H("size","Font size in millimetres","10"),H("font","Font name","$font"),B1("halign","left, center or right",'"left"'),B1("valign","baseline, top, center or bottom",'"baseline"'),B1("spacing","Letter spacing factor","1"),B1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),z7=[{name:"rect",kind:"module",params:[H("size","A number, or [width, height]","1"),H("center","Centre the rectangle on the origin instead of its corner","false"),B1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[H("size","A number, or [width, height]","1"),H("center","Centre the square on the origin instead of its corner","false"),B1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[H("r","Radius","1"),B1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[H("r","[rx, ry], or one radius for both","1")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[H("n","Number of corners","6"),H("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[H("n","Number of points","5"),H("r","Radius of the points","10"),H("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[H("points","A list of [x, y] points"),H("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:[H("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),B1("fill",'"evenodd" or "nonzero"','"evenodd"'),B1("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:[H("text","The text",'""'),H("size","Font size in millimetres","10"),H("font","Font name","$font"),B1("halign","left, center or right",'"left"'),B1("valign","baseline, top, center or bottom",'"baseline"'),B1("spacing","Letter spacing factor","1"),B1("fit","Shrink the size so the text is no wider than this")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[H("from","Start point","[0, 0]"),H("to","End point","[10, 0]"),H("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:[H("points","A list of [x, y] points"),H("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[H("r","Radius","10"),H("start","Start angle in degrees","0"),H("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[H("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[H("a","Angle in degrees, anticlockwise","0"),B1("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:[H("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[H("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:[H("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:[H("r","Grow (positive) or shrink areas with rounded corners"),B1("delta","Grow or shrink areas with sharp corners","0"),B1("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:[H("spacing","Distance between copies, a number or [x, y]","10"),H("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:[H("points","The [x, y] points the curve goes through"),H("width","Make an area this wide along the curve, instead of a line"),B1("steps","Points between each two given ones","8"),B1("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:[H("angle","Direction of the lines, in degrees from +x","45"),H("pitch","Distance between the lines","5"),H("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:"paint",kind:"module",params:[H("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:[H("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:[H("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:"close",kind:"module",params:[H("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:[H("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:[H("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:[H("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:[H("name","Layer name"),H("mode",'"cut", "line", "fill" or "guide"'),H("color",'Colour in the output, as "#00aa00"'),B1("order","Where it goes among the custom layers in the files, lowest first","0"),B1("bleed","How far past the part's edge it may print","0"),B1("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:[H("name","Part name",'"part"'),H("qty","Number of copies to cut","1"),B1("at","Where the part goes in the assembled view, [x, y, z]"),B1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),B1("stack","Layers glued in a stack at each placement, one thickness apart","1"),B1("mirror","Cut the part mirrored left to right, its text still reading","false"),B1("material","The material it is cut from, as material(name = ...) sets it"),B1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),B1("on","The name of a bent part this one is glued to, to move with it"),B1("slots","Names of parts whose tabs pass through this one: their slots are cut"),B1("clearance","Added to the slots, in total across each","0.1"),B1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),B1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[H("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),H("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:[H("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:[H("text","What to do in this step",'""'),H("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:[H("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),H("from","One end, [x, y, z]; a ball sits midway between from and to"),H("to","The other end, [x, y, z]; a ball may leave it out"),H("size","Diameter, or [width, height] for a flat section","6"),B1("up","The direction a [width, height] section's height points"),B1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),B1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),B1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[H("thickness","Sets $thickness"),H("kerf","Sets $kerf"),H("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:[H("size","[width, height]"),H("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),H("finger","Finger width",be)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[H("length","Length of the edge that plugs in"),H("edge",'"out" or "in", the kind of edge that plugs in','"out"'),H("finger","Finger width",be)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[H("d","Screw diameter","3"),H("length","Screw length into the panel","12"),H("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),H("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:[H("size","[width, height]"),H("spacing","Distance between the rows of cuts","1.5"),H("bridge","Uncut length between cuts","3"),H("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:[H("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:[H("condition","Stops the program when false"),H("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},U0("abs","Absolute value"),U0("sign","Sign as -1, 0 or 1"),U0("floor","Round down"),U0("ceil","Round up"),U0("round","Round to the nearest integer, halves away from zero"),U0("sqrt","Square root"),U0("exp","e raised to x"),U0("ln","Natural logarithm"),{name:"log",kind:"function",params:[H("x"),H("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"},U0("sin","Sine of an angle in degrees"),U0("cos","Cosine of an angle in degrees"),U0("tan","Tangent of an angle in degrees"),U0("asin","Inverse sine, in degrees"),U0("acos","Inverse cosine, in degrees"),U0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[H("y"),H("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[H("x"),H("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[H("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:[H("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:[H("x"),H("low"),H("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[H("a"),H("b"),H("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[H("ratio","Turns in for one turn out; under 1 speeds up"),H("stages","Pairs of gears, 1 to 3","2"),H("pinion","Fewest and most teeth of the small gears","[10, 20]"),H("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:[H("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[H("a"),H("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[H("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:[H("points","A list of [x, y] points"),H("d","How far to move it: to the left going along it, or the right when less than 0"),H("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:"point_at",kind:"function",params:[H("points","A list of [x, y] points"),H("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:[H("points","A list of [x, y] points"),H("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:[H("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),H("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:[H("points","The [x, y] points the curve goes through"),H("steps","Points between each two given ones","8"),H("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:[H("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:[H("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:[H("x","Where the part's own x axis points"),H("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:r4,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:[H("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:[H("a","A record"),H("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:r4,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sum",kind:"function",params:[H("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[H("value","A list or string"),H("start","First index","0"),H("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:[H("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[H("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[H("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[H("text"),H("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[H("values"),H("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[H("value"),H("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[H("value","A list or string"),H("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[H("x"),H("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},r3("is_num","a number other than NaN"),r3("is_string","a string"),r3("is_bool","true or false"),r3("is_list","a list"),r3("is_undef","undef"),r3("is_function","a function"),r3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:r4,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"rands",kind:"function",params:[H("min"),H("max"),H("count"),H("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},w7("text_width","The advance width of the text, including spacing"),w7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[H("length","Edge length"),H("finger","Finger width",be)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],v9=new Map(z7.map(t=>[t.name,t])),v5=t=>v9.get(t);function xe(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 y5={"kerf/box":`// kerf/box: finger-jointed boxes.
|
|
2
|
+
var $9=Object.defineProperty;var R9=(t,e,n)=>e in t?$9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var F9=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var G=(t,e,n)=>R9(t,typeof e!="symbol"?e+"":e,n);var In=F9((bf,Tn)=>{Tn.exports={}});var r0;(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"})(r0||(r0={}));var $0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})($0||($0={}));var U1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(U1||(U1={}));var _1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(_1||(_1={}));var O3=Number.MAX_SAFE_INTEGER,M0=Math.floor(Math.sqrt(O3));function se(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=O3/Math.abs(e)}function A6(t,e){return Math.abs(t)+Math.abs(e)<=O3}function v4(t,e,n,r){if(se(t,e)&&se(n,r)){let c=t*e,a=n*r;if(A6(c,a))return c-a}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 y4(t,e,n,r){if(se(t,e)&&se(n,r)){let c=t*e,a=n*r;if(A6(c,a))return c+a}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 b4=BigInt(0),oe=BigInt(2),D9=BigInt(4),q9=BigInt(64),N9=BigInt("0xFFFFFFFFFFFFFFFF"),w4=BigInt("9223372036854775807"),p5=Number(w4/D9),L6=Number(w4),C6=1e-12,U9=.1,x4=Math.floor(M0/2),B9=Math.floor(Math.sqrt(Math.sqrt(O3/4)));function _9(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:O3/e}function j9(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function G9(t,e){if(!Number.isFinite(t)||Math.abs(t)>O3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function W9(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0?r*c-a*s:v4(r,c,a,s)}function l2(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;if(Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0){let l=r*c,h=a*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let l=r*c,h=a*s;return l>h?1:l<h?-1:0}let o=BigInt(r)*BigInt(c),i=BigInt(a)*BigInt(s);return o===i?0:o>i?1:-1}function X9(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function Z9(t){return Math.abs(t)<=C6}function Y9(t){return t<0?-1:t>0?1:0}function J9(t,e){let n=BigInt(t),r=BigInt(e),c=n*r;return{lo64:c&N9,hi64:c>>q9}}function P6(t,e,n,r){let c=Math.abs(t),a=Math.abs(e),s=Math.abs(n),o=Math.abs(r);if(c<M0&&a<M0&&s<M0&&o<M0)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(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(o))return t*e===n*r;let h=BigInt(c),u=BigInt(a),f=BigInt(s),d=BigInt(o);return h*u===f*d}function K9(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return P6(r,c,a,s)}function Q9(t,e,n){let r=e.x-t.x,c=n.x-e.x,a=e.y-t.y,s=n.y-e.y;return Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0?r*c+a*s:y4(r,c,a,s)}function er(t,e,n){let r=e.x-t.x,c=n.x-e.x,a=e.y-t.y,s=n.y-e.y;if(Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0){let i=r*c+a*s;return i>0?1:i<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let i=r*c+a*s;return i>0?1:i<0?-1:0}let o=BigInt(r)*BigInt(c)+BigInt(a)*BigInt(s);return o===b4?0:o>b4?1:-1}function tr(t){let e=t.length;if(e<3)return 0;let n=!0;for(let a=0;a<e&&n;a++){let s=t[a];(Math.abs(s.x)>=x4||Math.abs(s.y)>=x4)&&(n=!1)}let r=t[e-1];if(n){let a=0;for(let s of t)a+=(r.y+s.y)*(r.x-s.x),r=s;return a*.5}let c=b4;for(let a of t){let s=r.y+a.y,o=r.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(o))c+=BigInt(s)*BigInt(o);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(a.x)){let i=BigInt(r.y)+BigInt(a.y),l=BigInt(r.x)-BigInt(a.x);c+=i*l}else c+=BigInt(Math.round(s*o));r=a}return Number(c)*.5}function nr(t,e){return t.y*e.x-e.y*t.x}function rr(t,e){return t.x*e.x+t.y*e.y}function cr(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function ar(t){return t>=p5||t<=-p5?L6:Math.round(t)}function sr(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,o=r.x-n.x,i=v4(c,o,s,a);if(i===0)return null;let l=v4(t.x-n.x,s,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*a),y:Math.trunc(t.y+l*c),z:0}}function or(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,o=r.x-n.x,i=c*o-s*a;if(i===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*s-(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*a,y:t.y+l*c,z:0},{success:!0,ip:h}}function ir(t,e,n,r,c=!1){if(!c){let l=l2(t,n,r),h=l2(e,n,r),u=l2(n,t,e),f=l2(r,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=l2(t,n,r),s=l2(e,n,r);if(a!==0&&a===s)return!1;let o=l2(n,t,e),i=l2(r,t,e);return o!==0&&o===i?!1:a!==0||s!==0||o!==0||i!==0}function E6(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 lr(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,c=n.y-e.y,a=y4(t.x-e.x,r,t.y-e.y,c)/y4(r,r,c,c),s=a<0?0:a>1?1:a;return{x:Math.round(e.x+s*r),y:Math.round(e.y+s*c),z:0}}function M4(t,e){let n=e.length,r=0;if(n<3)return _1.IsOutside;for(;r<n&&e[r].y===t.y;)r++;if(r===n)return _1.IsOutside;let c=e[r].y<t.y,a=c,s=0,o=r+1,i=n;for(;;){if(o===i){if(i===0||r===0)break;i=r,o=0}if(c)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 _1.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)s=1-s;else{let f=l2(u,h,t);if(f===0)return _1.IsOn;f<0===c&&(s=1-s)}c=!c,o++}if(c===a)return s===0?_1.IsOutside:_1.IsInside;o===n&&(o=0);let l=o===0?l2(e[n-1],e[0],t):l2(e[o-1],e[o],t);return l===0?_1.IsOn:(l<0===c&&(s=1-s),s===0?_1.IsOutside:_1.IsInside)}function hr(t,e){let n=_1.IsOn;for(let o of t)switch(M4(o,e)){case _1.IsOutside:if(n===_1.IsOutside)return!1;n=_1.IsOutside;break;case _1.IsInside:if(n===_1.IsInside)return!0;n=_1.IsInside;break;default:break}let r=E6(t),c,a;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>Number.MAX_SAFE_INTEGER?(c=Number((BigInt(r.left)+BigInt(r.right))/oe),a=Number((BigInt(r.top)+BigInt(r.bottom))/oe)):(c=Math.round((r.left+r.right)/2),a=Math.round((r.top+r.bottom)/2)),M4({x:c,y:a},e)!==_1.IsOutside}var R1={MaxInt64:w4,MaxCoord:p5,max_coord:p5,min_coord:-p5,Invalid64:L6,floatingPointTolerance:C6,defaultMinimumEdgeLength:U9,maxCoordForSafeAreaProduct:x4,maxCoordForSafeCrossSq:B9,maxSafeCoordinateForScale:_9,checkSafeScaleValue:j9,ensureSafeInteger:G9,crossProduct:W9,crossProductSign:l2,checkPrecision:X9,isAlmostZero:Z9,triSign:Y9,multiplyUInt64:J9,productsAreEqual:P6,isCollinear:K9,dotProduct:Q9,dotProductSign:er,area:tr,crossProductD:nr,dotProductD:rr,roundToEven:cr,checkCastInt64:ar,getLineIntersectPt:sr,getLineIntersectPtD:or,segsIntersect:ir,getBounds:E6,getClosestPtOnSegment:lr,pointInPolygon:M4,path2ContainsPath1:hr},S2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return R1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),R1.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} `}},ie={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 R1.isAlmostZero(t.x-e.x)&&R1.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)}`}},f3={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))/oe),n=Number((BigInt(t.top)+BigInt(t.bottom))/oe);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}]}},k4={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 T6=Object.freeze(f3.createInvalid()),I6=Object.freeze(k4.createInvalid());var g5=BigInt(0),ur=BigInt(2),V6=BigInt(4),Y1;(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"})(Y1||(Y1={}));var z4=class{constructor(){G(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 c=(e<<1)+1;if(c>=n)break;let a=c+1,s=c;if(a<n&&this.data[a]>this.data[c]&&(s=a),this.data[s]<=r)break;this.data[e]=this.data[s],e=s}this.data[e]=r}},v5=class{constructor(e,n,r){G(this,"pt");G(this,"next",null);G(this,"prev",null);G(this,"flags");this.pt=e,this.flags=n,this.prev=r}},y5=class{constructor(e,n,r=!1){G(this,"vertex");G(this,"polytype");G(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=r}equals(e){return e!==null&&this.vertex===e.vertex}};function H6(t,e,n){return{pt:t,edge1:e,edge2:n}}var F2=class{constructor(e,n){G(this,"pt");G(this,"next");G(this,"prev");G(this,"outrec");G(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},B0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(B0||(B0={}));var S4;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(S4||(S4={}));var le=class{constructor(){G(this,"idx",0);G(this,"owner",null);G(this,"frontEdge",null);G(this,"backEdge",null);G(this,"pts",null);G(this,"polypath",null);G(this,"bounds",{left:0,top:0,right:0,bottom:0});G(this,"path",[]);G(this,"isOpen",!1);G(this,"splits",null);G(this,"recursiveSplit",null)}},he=class{constructor(e){G(this,"leftOp");G(this,"rightOp");G(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},b5=class{constructor(e,n){G(this,"op1");G(this,"op2");this.op1=e,this.op2=n}};function fr(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function dr(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 x5=class{constructor(){G(this,"bot",{x:0,y:0});G(this,"top",{x:0,y:0});G(this,"curX",0);G(this,"dx",0);G(this,"windDx",0);G(this,"windCount",0);G(this,"windCount2",0);G(this,"outrec",null);G(this,"prevInAEL",null);G(this,"nextInAEL",null);G(this,"prevInSEL",null);G(this,"nextInSEL",null);G(this,"jump",null);G(this,"vertexTop",null);G(this,"localMin",null);G(this,"isLeftBound",!1);G(this,"joinWith",B0.None)}},$3={addLocMin(t,e,n,r){if((t.flags&Y1.LocalMin)!==Y1.None)return;t.flags|=Y1.LocalMin;let c=new y5(t,e,n);r.push(c)},addPathsToVertexList(t,e,n,r,c){for(let a=0,s=t.length;a<s;a++){let o=t[a],i=null,l=null,h=null;for(let p=0,m=o.length;p<m;p++){let g=o[p];if(i===null)i=new v5(g,Y1.None,null),c.push(i),l=i,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new v5(g,Y1.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 p=i.next;for(;p!==i&&p.pt.y===i.pt.y;)p=p.next;u=p.pt.y<=i.pt.y,u?(i.flags=Y1.OpenStart,$3.addLocMin(i,e,!0,r)):i.flags=Y1.OpenStart|Y1.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|=Y1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,$3.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=Y1.OpenEnd,u?l.flags|=Y1.LocalMax:$3.addLocMin(l,e,n,r)):u!==f&&(f?$3.addLocMin(l,e,!1,r):l.flags|=Y1.LocalMax)}}};var ue=class{constructor(e=null){G(this,"parent");G(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="",c=" ".repeat(n),a=this.children.length===1?"":"s";(n&1)===0?r+=`${c}+- hole (${e}) contains ${this.children.length} nested polygon${a}.
|
|
3
|
+
`:r+=`${c}+- polygon (${e}) contains ${this.children.length} hole${a}.
|
|
4
|
+
`;for(let s=0;s<this.count;s++)this.children[s].count>0&&(r+=this.children[s].toStringInternal(s,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
|
+
`;for(let r=0;r<this.count;r++)this.children[r].count>0&&(n+=this.children[r].toStringInternal(r,1));return n+`
|
|
6
|
+
`}},fe=class t extends ue{constructor(n=null){super(n);G(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:A4.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var M5=class extends fe{};var $=class ${constructor(){G(this,"cliptype",r0.NoClip);G(this,"fillrule",U1.EvenOdd);G(this,"actives",null);G(this,"sel",null);G(this,"minimaList",[]);G(this,"intersectList",[]);G(this,"vertexList",[]);G(this,"outrecList",[]);G(this,"scanlineHeap",new z4);G(this,"scanlineSet",new Set);G(this,"scanlineArr",[]);G(this,"useScanlineArray",!1);G(this,"horzSegList",[]);G(this,"horzJoinList",[]);G(this,"currentLocMin",0);G(this,"currentBotY",0);G(this,"curXValidAtTop",!1);G(this,"isSortedMinimaList",!1);G(this,"hasOpenPaths",!1);G(this,"usingPolytree",!1);G(this,"succeeded",!1);G(this,"zCallbackInternal");G(this,"preserveCollinear",!0);G(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,r){let c=this.zCallbackInternal;c&&($.getPolyType(e)===$0.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,c(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,c(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 $.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return $.openPathsEnabled&&e.localMin.isOpen&&$.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(Y1.OpenStart|Y1.OpenEnd))!==Y1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!$.openPathsEnabled){for(;n!==null&&!$.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!$.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:R1.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=$.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&Y1.LocalMax)!==Y1.None}static isMaximaEdge(e){return(e.vertexTop.flags&Y1.LocalMax)!==Y1.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,c){let a=e.x<n.x?e.x:n.x;if((r.x>c.x?r.x:c.x)<a)return!1;let o=e.x>n.x?e.x:n.x,i=r.x<c.x?r.x:c.x;if(o<i)return!1;let l=e.y<n.y?e.y:n.y;if((r.y>c.y?r.y:c.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=r.y<c.y?r.y:c.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 c=e[n];this.scanlineSet.add(c),this.scanlineHeap.push(c)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let r=0,c=n.length;r<c;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 c=0,a=n[0];for(let s=1;s<r;s++){let o=n[s];o>a&&(a=o,c=s)}return n[c]=n[r-1],n.pop(),a}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 c=[e];this.addPaths(c,n,r)}addPaths(e,n,r=!1){r&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,$3.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 y5(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 f3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===r0.NoClip)return;$.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 c;for(;(c=this.popHorz())!==null;)this.doHorizontal(c);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=r;let a=this.popScanline();if(a===null)break;for(r=a,this.doIntersections(r),this.doTopOfScanbeam(r);(c=this.popHorz())!==null;)this.doHorizontal(c)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),r;(n.vertex.flags&Y1.OpenStart)!==Y1.None?r=null:(r=new x5,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,$.setDx(r));let c;if((n.vertex.flags&Y1.OpenEnd)!==Y1.None?c=null:(c=new x5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=1,c.vertexTop=n.vertex.next,c.top=n.vertex.next.pt,c.outrec=null,c.localMin=n,$.setDx(c)),r!==null&&c!==null){if($.isHorizontal(r)){if($.isHeadingRightHorz(r)){let s=r;r=c,c=s}}else if($.isHorizontal(c)){if($.isHeadingLeftHorz(c)){let s=r;r=c,c=s}}else if(r.dx<c.dx){let s=r;r=c,c=s}}else r===null&&(r=c,c=null);let a;if(r.isLeftBound=!0,this.insertLeftEdge(r),$.openPathsEnabled?$.isOpen(r)?(this.setWindCountForOpenPathEdge(r),a=this.isContributingOpen(r)):(this.setWindCountForClosedPathEdge(r),a=this.isContributingClosed(r)):(this.setWindCountForClosedPathEdge(r),a=this.isContributingClosed(r)),c!==null){for(c.windCount=r.windCount,c.windCount2=r.windCount2,this.insertRightEdge(r,c),a&&(this.addLocalMinPoly(r,c,r.bot,!0),$.isHorizontal(r)||this.checkJoinLeft(r,r.bot));c.nextInAEL!==null&&this.isValidAelOrder(c.nextInAEL,c);)this.intersectEdges(c,c.nextInAEL,c.bot),this.swapPositionsInAEL(c,c.nextInAEL);$.isHorizontal(c)?this.pushHorz(c):(this.checkJoinRight(c,c.bot),this.insertScanline(c.top.y))}else a&&$.openPathsEnabled&&this.startOpenPath(r,r.bot);$.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(!$.openPathsEnabled){this.doHorizontalClosed(e);return}let n=$.isOpen(e),r=e.bot.y,c=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:o}=this.resetHorzDirection(e,c),i=s,l=o;if($.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:r});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===c){if($.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),$.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(c!==e.vertexTop||$.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<i)break;if(h.curX===e.top.x&&!$.isHorizontal(h)){let d=$.nextVertex(e).pt;if($.isOpen(h)&&!$.isSamePolyType(h,e)&&!$.isHotEdge(h)){if(a&&$.topX(h,d.y)>d.x||!a&&$.topX(h,d.y)<d.x)break}else if(a&&$.topX(h,d.y)>=d.x||!a&&$.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:r};a?(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),$.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&$.isOpenEnd(e)){$.isHotEdge(e)&&(this.addOutPt(e,e.top),$.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if($.nextVertex(e).pt.y!==e.top.y)break;$.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,c);i=u.leftX,l=u.rightX}if($.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:c,leftX:a,rightX:s}=this.resetHorzDirection(e,r),o=a,i=s;if($.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=c?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===r){if($.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),$.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);c?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(r!==e.vertexTop){if(c&&l.curX>i||!c&&l.curX<o)break;if(l.curX===e.top.x&&!$.isHorizontal(l)){let f=$.nextVertex(e).pt,d=$.topX(l,f.y);if(c&&d>=f.x||!c&&d<=f.x)break}}let u={x:l.curX,y:n};c?(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),$.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if($.nextVertex(e).pt.y!==e.top.y)break;$.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,r);o=h.leftX,i=h.rightX}if($.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,c=e.length;r<c;r++){let a=e[r];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(fr);for(let r=0;r<n-1;r++){let c=this.horzSegList[r];for(let a=r+1;a<n;a++){let s=this.horzSegList[a];if(s.leftOp.pt.x>=c.rightOp.pt.x||s.leftToRight===c.leftToRight||s.rightOp.pt.x<=c.leftOp.pt.x)continue;let o=c.leftOp.pt.y;if(c.leftToRight){for(;c.leftOp.next.pt.y===o&&c.leftOp.next.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.next;for(;s.leftOp.prev.pt.y===o&&s.leftOp.prev.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let i=new b5(this.duplicateOp(c.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(i)}else{for(;c.leftOp.prev.pt.y===o&&c.leftOp.prev.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.prev;for(;s.leftOp.next.pt.y===o&&s.leftOp.next.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.next;let i=new b5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(c.leftOp,!1));this.horzJoinList.push(i)}}}}}updateHorzSegment(e){let n=e.leftOp,r=this.getRealOutRec(n.outrec),c=r.frontEdge!==null,a=n.pt.y,s=n,o=n;if(c){let l=r.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;o!==l&&o.next.pt.y===a;)o=o.next}else{for(;s.prev!==o&&s.prev.pt.y===a;)s=s.prev;for(;o.next!==s&&o.next.pt.y===a;)o=o.next}let i=this.setHorzSegHeadingForward(e,s,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 F2(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,$.isMaximaEdge(r)){r=this.doMaxima(r);continue}else $.isHotEdge(r)&&this.addOutPt(r,r.top),this.updateEdgeIntoAEL(r),$.isHorizontal(r)&&this.pushHorz(r);else n||(r.curX=$.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),c=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,c.prev=a,a.next=c,n===r){let s=this.newOutRec();s.pts=c,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.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=_1.IsOn,c=e;do{switch(this.pointInOpPolygon(c.pt,n)){case _1.IsOutside:if(r===_1.IsOutside)return!1;r=_1.IsOutside;break;case _1.IsInside:if(r===_1.IsInside)return!0;r=_1.IsInside;break;default:break}c=c.next}while(c!==e);return R1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return _1.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 _1.IsOutside;let c=n.pt.y<e.y,a=c,s=0;for(r=n.next;r!==n;){if(c)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 _1.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)s=1-s;else{let o=R1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return _1.IsOn;o<0===c&&(s=1-s)}c=!c,r=r.next}if(c===a)return s===0?_1.IsOutside:_1.IsInside;{let o=R1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return _1.IsOn;o<0===c&&(s=1-s)}return s===0?_1.IsOutside:_1.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 c=r;for(r=r.next;r!==e;)(r.pt.x!==r.next.pt.x||r.pt.x!==c.pt.x)&&(r.pt.y!==r.next.pt.y||r.pt.y!==c.pt.y)&&(n.push(r.pt),c=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 c=n,a=n.jump,s=a,o=a?.jump||null;for(n.jump=o;n!==s&&a!==o;)if(a.curX<n.curX){let i=a.prevInSEL;for(;this.addNewIntersectNode(i,a,e),i!==n;)i=i.prevInSEL;if(i=a,a=this.extractFromSEL(i),s=a,n!==null&&this.insert1Before2InSEL(i,n),n!==c)continue;c=i,c.jump=o,r===null?this.sel=c:r.jump=c}else n=n.nextInSEL;r=c,n=o}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(dr);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,c=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=$.topX(n,e);n.curX=a,a<r&&(c=!0),r=a,n=n.nextInAEL}return c}doMaxima(e){let n=e.prevInAEL,r=e.nextInAEL;if($.isOpenEnd(e))return $.isHotEdge(e)&&this.addOutPt(e,e.top),$.isHorizontal(e)||($.isHotEdge(e)&&($.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),r;let c=$.getMaximaPair(e);if(c===null)return r;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(c)&&this.split(c,c.top);r!==c;)this.intersectEdges(e,r,e.top),this.swapPositionsInAEL(e,r),r=e.nextInAEL;return $.isOpen(e)?($.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(c),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):($.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(e),this.deleteFromAEL(c),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=$.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,$.setDx(e),this.isJoined(e)&&this.split(e,e.bot),$.isHorizontal(e)){$.openPathsEnabled?$.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,c=$.nextVertex(e).pt;for(;c.y===e.top.y&&!(n&&c.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=$.nextVertex(e),e.top=c,r=!0,$.isMaximaVertex(e.vertexTop)));)c=$.nextVertex(e).pt;r&&$.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new he(e))}addNewIntersectNode(e,n,r){let c=R1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(c===null&&(c={x:e.curX,y:r}),c.y>this.currentBotY||c.y<r){let s=Math.abs(e.dx),o=Math.abs(n.dx);s>100&&o>100?s>o?c=R1.getClosestPtOnSegment(c,e.bot,e.top):c=R1.getClosestPtOnSegment(c,n.bot,n.top):s>100?c=R1.getClosestPtOnSegment(c,e.bot,e.top):o>100?c=R1.getClosestPtOnSegment(c,n.bot,n.top):(c.y<r?c.y=r:c.y=this.currentBotY,s<o?c.x=$.topX(e,c.y):c.x=$.topX(n,c.y))}let a=H6(c,e,n);this.intersectList.push(a)}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&(Y1.OpenEnd|Y1.LocalMax))===Y1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(Y1.OpenEnd|Y1.LocalMax))===Y1.None;)n=n.prev;return $.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 $.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let r=e.curX,c=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:r,rightX:c}}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===B0.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===U1.EvenOdd){let r=0,c=0;for(;n!==e;)$.getPolyType(n)===$0.Clip?c++:$.isOpen(n)||r++,n=n.nextInAEL;e.windCount=$.isOdd(r)?1:0,e.windCount2=$.isOdd(c)?1:0}else for(;n!==e;)$.getPolyType(n)===$0.Clip?e.windCount2+=n.windDx:$.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,r=$.getPolyType(e);if(!$.openPathsEnabled){for(;n!==null&&$.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===U1.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===U1.EvenOdd)for(;n!==e;)$.getPolyType(n)!==r&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)$.getPolyType(n)!==r&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&($.getPolyType(n)!==r||$.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===U1.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=$.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===U1.EvenOdd)for(;n!==e;)$.getPolyType(n)!==r&&!$.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)$.getPolyType(n)!==r&&!$.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,r;switch(this.fillrule){case U1.Positive:r=e.windCount>0,n=e.windCount2>0;break;case U1.Negative:r=e.windCount<0,n=e.windCount2<0;break;default:r=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case r0.Intersection:return n;case r0.Union:return!r&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case U1.Positive:if(e.windCount!==1)return!1;break;case U1.Negative:if(e.windCount!==-1)return!1;break;case U1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case r0.Intersection:return this.fillrule===U1.Positive?e.windCount2>0:this.fillrule===U1.Negative?e.windCount2<0:e.windCount2!==0;case r0.Union:return this.fillrule===U1.Positive?e.windCount2<=0:this.fillrule===U1.Negative?e.windCount2>=0:e.windCount2===0;case r0.Difference:{let n=this.fillrule===U1.Positive?e.windCount2<=0:this.fillrule===U1.Negative?e.windCount2>=0:e.windCount2===0;return $.getPolyType(e)===$0.Subject?n:!n}case r0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,r,c=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,$.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let o=$.getPrevHotEdge(e);o!==null?(this.usingPolytree&&this.setOwner(a,o.outrec),a.owner=o.outrec,this.outrecIsAscending(o)===c?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,c?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new F2(r,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new le;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 c=new F2(n,r);return r.pts=c,c}checkJoinLeft(e,n,r=!1){let c=e.prevInAEL;c!==null&&(!r&&e.curX!==c.curX||!$.isHotEdge(e)||!$.isHotEdge(c)||$.isHorizontal(e)||$.isHorizontal(c)||$.isOpen(e)||$.isOpen(c)||(n.y<e.top.y+2||n.y<c.top.y+2)&&(e.bot.y>n.y||c.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,c.bot,c.top)||R1.isCollinear(e.top,n,c.top)&&(e.outrec.idx===c.outrec.idx?this.addLocalMaxPoly(c,e,n):e.outrec.idx<c.outrec.idx?this.joinOutrecPaths(e,c):this.joinOutrecPaths(c,e),c.joinWith=B0.Right,e.joinWith=B0.Left))}checkJoinRight(e,n,r=!1){let c=e.nextInAEL;c!==null&&(!r&&e.curX!==c.curX||!$.isHotEdge(e)||!$.isHotEdge(c)||$.isHorizontal(e)||$.isHorizontal(c)||$.isOpen(e)||$.isOpen(c)||(n.y<e.top.y+2||n.y<c.top.y+2)&&(e.bot.y>n.y||c.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,c.bot,c.top)||R1.isCollinear(e.top,n,c.top)&&(e.outrec.idx===c.outrec.idx?this.addLocalMaxPoly(e,c,n):e.outrec.idx<c.outrec.idx?this.joinOutrecPaths(e,c):this.joinOutrecPaths(c,e),e.joinWith=B0.Right,c.joinWith=B0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,r){let c=e.x-n.x,a=e.y-n.y,s=r.x-n.x,o=r.y-n.y;if(s===0&&o===0)return!1;let i=R1.maxCoordForSafeCrossSq;if(Math.abs(c)<i&&Math.abs(a)<i&&Math.abs(s)<i&&Math.abs(o)<i){let h=c*o-s*a;return h*h/(s*s+o*o)>.25}if(Number.isSafeInteger(c)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(o)){let h=BigInt(c)*BigInt(o)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(o)*BigInt(o);return V6*u>f}let l=c*o-s*a;return l*l/(s*s+o*o)>.25}intersectEdges(e,n,r){let c;if(this.hasOpenPaths&&($.isOpen(e)||$.isOpen(n))){if($.isOpen(e)&&$.isOpen(n))return;if($.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,r),this.cliptype===r0.Union){if(!$.isHotEdge(n))return}else if(n.localMin.polytype===$0.Subject)return;switch(this.fillrule){case U1.Positive:if(n.windCount!==1)return;break;case U1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if($.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),$.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&&!$.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&$.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}c=this.startOpenPath(e,r)}else c=this.startOpenPath(e,r);this.setZ(e,n,c.pt);return}this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===U1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(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!==U1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==U1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case U1.Positive:a=e.windCount,s=n.windCount;break;case U1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let o=a===0||a===1,i=s===0||s===1;if(!(!$.isHotEdge(e)&&!o||!$.isHotEdge(n)&&!i))if($.isHotEdge(e)&&$.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==r0.Xor)c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);else if($.isFront(e)||e.outrec===n.outrec){c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);let l=this.addLocalMinPoly(e,n,r);this.setZ(e,n,l.pt)}else{c=this.addOutPt(e,r),this.setZ(e,n,c.pt);let l=this.addOutPt(n,r);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if($.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else if($.isHotEdge(n))c=this.addOutPt(n,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case U1.Positive:l=e.windCount2,h=n.windCount2;break;case U1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!$.isSamePolyType(e,n))c=this.addLocalMinPoly(e,n,r),this.setZ(e,n,c.pt);else if(a===1&&s===1){switch(c=null,this.cliptype){case r0.Union:if(l>0&&h>0)return;c=this.addLocalMinPoly(e,n,r);break;case r0.Difference:($.getPolyType(e)===$0.Clip&&l>0&&h>0||$.getPolyType(e)===$0.Subject&&l<=0&&h<=0)&&(c=this.addLocalMinPoly(e,n,r));break;case r0.Xor:c=this.addLocalMinPoly(e,n,r);break;default:if(l<=0||h<=0)return;c=this.addLocalMinPoly(e,n,r);break}c&&this.setZ(e,n,c.pt)}}}swapPositionsInAEL(e,n){let r=n.nextInAEL;r!==null&&(r.prevInAEL=e);let c=e.prevInAEL;c!==null&&(c.nextInAEL=n),n.prevInAEL=c,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=R1.crossProductSign(e.top,n.bot,n.top);if(r!==0)return r<0;if(!$.isMaximaEdge(e)&&e.top.y>n.top.y)return R1.crossProductSign(n.bot,e.top,$.nextVertex(e).pt)<=0;if(!$.isMaximaEdge(n)&&n.top.y>e.top.y)return R1.crossProductSign(n.bot,n.top,$.nextVertex(n).pt)>=0;let c=n.bot.y,a=n.isLeftBound;return e.bot.y!==c||e.localMin.vertex.pt.y!==c?n.isLeftBound:e.isLeftBound!==a?a:R1.isCollinear($.prevPrevVertex(e).pt,e.bot,e.top)?!0:R1.crossProductSign($.prevPrevVertex(e).pt,n.bot,$.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==B0.None}split(e,n){e.joinWith===B0.Right?(e.joinWith=B0.None,e.nextInAEL.joinWith=B0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=B0.None,e.prevInAEL.joinWith=B0.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;!$.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(!$.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,c=$.isFront(e),a=r.pts,s=a.next;if(c&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!c&&n.x===s.pt.x&&n.y===s.pt.y)return s;let o=new F2(n,r);return s.prev=o,o.prev=a,o.next=s,a.next=o,c&&(r.pts=o),o}addLocalMaxPoly(e,n,r){if(this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r),$.isFront(e)===$.isFront(n))if($.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if($.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let c=this.addOutPt(e,r);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=c,this.usingPolytree){let s=$.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else $.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 c}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,c=n.outrec.pts,a=r.next,s=c.next;$.isFront(e)?(s.prev=r,r.next=s,c.next=a,a.prev=c,e.outrec.pts=c,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=c,c.next=a,r.next=s,s.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),$.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,c=n.outrec;if(r===c){let a=r.frontEdge;r.frontEdge=r.backEdge,r.backEdge=a;return}r!==null&&(e===r.frontEdge?r.frontEdge=n:r.backEdge=n),c!==null&&(n===c.frontEdge?c.frontEdge=e:c.backEdge=e),e.outrec=c,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&&($.ptsReallyClose(e.prev.pt,e.next.pt)||$.ptsReallyClose(e.pt,e.next.pt)||$.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,r,c){if(e===null||e.next===e||!r&&e.next===e.prev)return!1;c.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),c.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,c.push(a)),n?s=s.prev:s=s.next;return c.length!==3||r||!$.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let c=this.outrecList[r++];if(c.pts===null)continue;let a=[];c.isOpen?$.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(c),$.buildPath(c.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let c=this.outrecList[r++];if(c.pts!==null){if(c.isOpen){let a=[];$.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(c)&&this.recursiveCheckOwners(c,e)}}}checkBounds(e){return e.pts===null?!1:f3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!$.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=R1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||f3.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&&R1.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||R1.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||!$.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)&&R1.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,c=n.next.next;e.pts=r;let a=R1.getLineIntersectPt(r.pt,n.pt,n.next.pt,c.pt);this.zCallbackInternal&&this.zCallbackInternal(r.pt,n.pt,n.next.pt,c.pt,a);let s=$.areaOutPt(r),o=s<g5?-s:s;if(o<V6){e.pts=null;return}let i=this.areaTriangle(a,n.pt,n.next.pt),l=i<g5?-i:i;if(a.x===r.pt.x&&a.y===r.pt.y||a.x===c.pt.x&&a.y===c.pt.y)c.prev=r,r.next=c;else{let f=new F2(a,e);f.prev=r,f.next=c,c.prev=f,r.next=f}if(!(l>ur)||!(l>o)&&i>g5!=s>g5)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new F2(a,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=R1.maxCoordForSafeAreaProduct,r=0,c=!0,a=e;do{let o=a.prev,i=a.pt;if(Math.abs(o.pt.x)>=n||Math.abs(o.pt.y)>=n||Math.abs(i.x)>=n||Math.abs(i.y)>=n){c=!1;break}r+=(o.pt.y+i.y)*(o.pt.x-i.x),a=a.next}while(a!==e);if(c)return BigInt(Math.round(r));let s=g5;a=e;do{let o=a.prev;if(Number.isSafeInteger(o.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(o.pt.x)&&Number.isSafeInteger(a.pt.x)){let i=BigInt(o.pt.y)+BigInt(a.pt.y),l=BigInt(o.pt.x)-BigInt(a.pt.x);s+=i*l}else{let i=o.pt.y+a.pt.y,l=o.pt.x-a.pt.x;s+=BigInt(Math.round(i*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,r){let c=R1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<c&&Math.abs(e.y)<c&&Math.abs(n.x)<c&&Math.abs(n.y)<c&&Math.abs(r.x)<c&&Math.abs(r.y)<c){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))}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 s=(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 s+o+i}let a=(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(a))}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 c=this.outrecList[n[r]];if(c.pts===null&&c.splits!==null&&this.checkSplitOwner(e,c.splits))return!0;if(c=this.getRealOutRec(c),!(c===null||c===e||c.recursiveSplit===e)){if(c.recursiveSplit=e,c.splits!==null&&this.checkSplitOwner(e,c.splits))return!0;if(!(!this.checkBounds(c)||!this.containsRect(c.bounds,e.bounds)||!this.path1InsidePath2(e.pts,c.pts)))return this.isValidOwner(e,c)||(c.owner=e.owner),e.owner=c,!0}}return!1}};G($,"openPathsEnabled",!0);var de=$,A2=class extends de{constructor(){super(...arguments);G(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,r,c=!1){super.addPath(n,r,c)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,r,c=!1){super.addPaths(n,r,c)}addSubject(n){this.addPaths(n,$0.Subject)}addOpenSubject(n){this.addPaths(n,$0.Subject,!0)}addClip(n){this.addPaths(n,$0.Clip)}execute(n,r,c,a){if(Array.isArray(c)){let s=c,o=a;s.length=0,o&&(o.length=0);try{this.executeInternal(n,r),this.buildPaths(s,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=c,o=a;s.clear(),o&&(o.length=0),this.usingPolytree=!0;try{this.executeInternal(n,r),this.buildTree(s,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var A4={area(t){return R1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let r=t[n-1];for(let c of t)e+=(r.y+c.y)*(r.x-c.x),r=c;return e*.5},scalePath64(t,e){let n=R1.maxSafeCoordinateForScale(e),r=[];for(let c of t)R1.checkSafeScaleValue(c.x,n,"scalePath64"),R1.checkSafeScaleValue(c.y,n,"scalePath64"),r.push({x:Math.round(c.x*e),y:Math.round(c.y*e)});return r},scalePaths64(t,e){let n=[];for(let r of t)n.push(A4.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(A4.scalePathD(r,e));return n}};var _0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(_0||(_0={}));var h0;(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"})(h0||(h0={}));var L4=class{constructor(e,n,r=h0.Polygon){G(this,"inPaths");G(this,"joinType");G(this,"endType");G(this,"pathsReversed");G(this,"lowestPathIdx");this.joinType=n,this.endType=r;let c=r===h0.Polygon||r===h0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(d3.stripDuplicates(a,c));if(r===h0.Polygon){let a=d3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},l0=class l0{constructor(e=2,n=0,r=!1,c=!1){G(this,"groupList",[]);G(this,"pathOut",[]);G(this,"normals",[]);G(this,"solution",[]);G(this,"solutionTree",null);G(this,"groupDelta",0);G(this,"delta",0);G(this,"mitLimSqr",0);G(this,"stepsPerRad",0);G(this,"stepSin",0);G(this,"stepCos",0);G(this,"joinType",_0.Bevel);G(this,"endType",h0.Polygon);G(this,"arcTolerance",0);G(this,"mergeGroups",!0);G(this,"miterLimit",2);G(this,"preserveCollinear",!1);G(this,"reverseSolution",!1);G(this,"zCallback");G(this,"deltaCallback",null);G(this,"ZCB",(e,n,r,c,a)=>{(e.z||0)!==0&&(e.z===r.z||e.z===c.z)?a.z=e.z:(r.z||0)!==0&&r.z===n.z?a.z=r.z:(n.z||0)!==0&&n.z===c.z?a.z=n.z:this.zCallback&&this.zCallback(e,n,r,c,a)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=r,this.reverseSolution=c}clear(){this.groupList.length=0}addPath(e,n,r){if(e.length===0)return;let c=[e];this.addPaths(c,n,r)}addPaths(e,n,r){e.length!==0&&this.groupList.push(new L4(e,n,r))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===h0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===h0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/l0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),r=n?U1.Negative:U1.Positive,c=new A2;c.preserveCollinear=this.preserveCollinear,c.reverseSolution=this.reverseSolution!==n,c.zCallback=this.ZCB,c.addSubject(this.solution),this.solutionTree!==null?c.execute(r0.Union,r,this.solutionTree):c.execute(r0.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,c=n.y-e.y;if(r===0&&c===0)return{x:0,y:0};let a=1/Math.sqrt(r*r+c*c);return{x:c*a,y:-r*a}}static getLowestPathInfo(e){let n=-1,r=!1,c={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let o of e[a])if(!(o.y<c.y||o.y===c.y&&o.x>=c.x)){if(s===Number.MAX_VALUE){if(s=l0.area(e[a]),s===0)break;r=s<0}n=a,c.x=o.x,c.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=l0.hypotenuse(e.x,e.y);if(l0.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 l0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,r,c){if(R1.isAlmostZero(e.x-n.x)){if(R1.isAlmostZero(r.x-c.x))return{x:0,y:0};let a=(c.y-r.y)/(c.x-r.x),s=r.y-a*r.x;return{x:e.x,y:a*e.x+s}}if(R1.isAlmostZero(r.x-c.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:r.x,y:a*r.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,o=(c.y-r.y)/(c.x-r.x),i=r.y-o*r.x;if(R1.isAlmostZero(a-o))return{x:0,y:0};let l=(i-s)/(a-o);return{x:l,y:a*l+s}}}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 c,a,s=e[n].z||0;if(n===r){let o=Math.abs(this.groupDelta);c={x:Math.round(e[n].x-o*this.normals[n].x),y:Math.round(e[n].y-o*this.normals[n].y),z:s},a={x:Math.round(e[n].x+o*this.normals[n].x),y:Math.round(e[n].y+o*this.normals[n].y),z:s}}else c={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:s},a={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:s};this.pathOut.push(c),this.pathOut.push(a)}doSquare(e,n,r){let c;n===r?c={x:this.normals[n].y,y:-this.normals[n].x}:c=l0.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=l0.translatePoint(s,a*c.x,a*c.y);let o=l0.translatePoint(s,this.groupDelta*c.y,this.groupDelta*-c.x),i=l0.translatePoint(s,this.groupDelta*-c.y,this.groupDelta*c.x),l=this.getPerpendicD(e[r],this.normals[r]);if(n===r){let h={x:l.x+c.x*this.groupDelta,y:l.y+c.y*this.groupDelta},u=l0.intersectPoint(o,i,l,h);u.z=s.z,this.pathOut.push(S2.fromPointD(l0.reflectPoint(u,s))),this.pathOut.push(S2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[r]),u=l0.intersectPoint(o,i,l,h);u.z=s.z,this.pathOut.push(S2.fromPointD(u)),this.pathOut.push(S2.fromPointD(l0.reflectPoint(u,s)))}}doMiter(e,n,r,c){let a=this.groupDelta/(c+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[r].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[r].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,r,c){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*l0.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 a=e[n],s=a.z||0,o={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&ie.negate(o),this.pathOut.push({x:Math.round(a.x+o.x),y:Math.round(a.y+o.y),z:s});let i=Math.ceil(this.stepsPerRad*Math.abs(c));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(a.x+o.x),y:Math.round(a.y+o.y),z:s});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(l0.getUnitNormal(e[r],e[r+1]));this.normals.push(l0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,r,c){if(S2.equals(n[r],n[c]))return;let a=R1.crossProductD(this.normals[r],this.normals[c]),s=R1.dotProductD(this.normals[r],this.normals[c]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,c),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<l0.Tolerance){this.pathOut.push(n[r]);return}if(s>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[c])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(s>.999&&this.joinType!==_0.Round)this.doMiter(n,r,c,s);else switch(this.joinType){case _0.Miter:s>this.mitLimSqr-1?this.doMiter(n,r,c,s):this.doSquare(n,r,c);break;case _0.Round:this.doRound(n,r,c,Math.atan2(a,s));break;case _0.Bevel:this.doBevel(n,r,c);break;default:this.doSquare(n,r,c);break}}offsetPolygon(e,n){this.pathOut=[];let r=n.length,c=r-1;for(let a=0;a<r;a++)this.offsetPoint(e,n,a,c),c=a;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)<l0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case h0.Butt:this.doBevel(n,0,0);break;case h0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let c=1,a=0;c<r;c++)this.offsetPoint(e,n,c,a),a=c;for(let c=r;c>0;c--)this.normals[c]={x:-this.normals[c-1].x,y:-this.normals[c-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)<l0.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case h0.Butt:this.doBevel(n,r,r);break;case h0.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let c=r-1,a=r;c>0;c--)this.offsetPoint(e,n,c,a),a=c;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===h0.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===_0.Round||e.endType===h0.Round){let r=this.arcTolerance>.01?this.arcTolerance:n*l0.arc_const,c=Math.PI/Math.acos(1-r/n);this.stepSin=Math.sin(2*Math.PI/c),this.stepCos=Math.cos(2*Math.PI/c),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=c/(2*Math.PI)}for(let r of e.inPaths){this.pathOut=[];let c=r.length;if(c===1){let a=r[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(r,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=a.z||0;if(e.endType===h0.Round){let o=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=l0.ellipse(a,Math.abs(this.groupDelta),Math.abs(this.groupDelta),o),s!==0)for(let i=0;i<this.pathOut.length;i++)this.pathOut[i].z=s}else{let o=Math.ceil(Math.abs(this.groupDelta)),i={left:a.x-o,top:a.y-o,right:a.x+o,bottom:a.y+o};this.pathOut=[{x:i.left,y:i.top,z:s},{x:i.right,y:i.top,z:s},{x:i.right,y:i.bottom,z:s},{x:i.left,y:i.bottom,z:s}]}this.solution.push(this.pathOut);continue}switch(c===2&&e.endType===h0.Joined&&(this.endType=e.joinType===_0.Round?h0.Round:h0.Square),this.buildNormals(r),this.endType){case h0.Polygon:this.offsetPolygon(e,r);break;case h0.Joined:this.offsetOpenJoined(e,r);break;default:this.offsetOpenPath(e,r);break}}}static stripDuplicates(e,n){let r=e.length,c=[];if(r===0)return c;let a=e[0];c.push(a);for(let s=1;s<r;s++)S2.equals(a,e[s])||(a=e[s],c.push(a));return n&&S2.equals(a,c[0])&&c.pop(),c}static area(e){return R1.area(e)}static sqr(e){return e*e}static ellipse(e,n,r=0,c=0){if(n<=0)return[];r<=0&&(r=n),c<=2&&(c=Math.ceil(Math.PI*Math.sqrt((n+r)/2)));let a=Math.sin(2*Math.PI/c),s=Math.cos(2*Math.PI/c),o=s,i=a,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<c;++h){l.push({x:Math.round(e.x+n*o),y:Math.round(e.y+r*i)});let u=o*s-i*a;i=i*s+o*a,o=u}return l}};G(l0,"Tolerance",1e-12),G(l0,"arc_const",.002);var d3=l0;var Lh=BigInt(2);function P4(t,e,n){return typeof e=="number"?C4(r0.Union,t,null,e):C4(r0.Union,t,e,n)}function C4(t,e,n,r){let c=[];if(e===null)return c;let a=new A2;return a.addPaths(e,$0.Subject),n!==null&&a.addPaths(n,$0.Clip),a.execute(t,r,c),c}function me(t,e,n,r,c=2,a=0){let s=new d3(c,a);s.addPaths(t,n,r);let o=[];return s.execute(e,o),o}var m2=1e4,E4=[1,0,0,1,0,0];function T0(){return{layers:new Map,parts:[]}}function L0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function L2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function R6(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*m2),y:Math.round(r*m2)})));function gr(t){let e=(r,c,a)=>(c.x-r.x)*(a.y-c.y)-(c.y-r.y)*(a.x-c.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 c=n[n.length-1];(!c||c.x!==r.x||c.y!==r.y)&&n.push(r)}for(let r=!0;r&&n.length>=3;){let c=n.length;r=!0,n[c-1].x===n[0].x&&n[c-1].y===n[0].y||e(n[c-2],n[c-1],n[0])?n.pop():e(n[c-1],n[0],n[1])?n.shift():r=!1}return n}var w5=t=>F6(t).map(gr),z5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/m2,n.y/m2]));function s1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?U1.EvenOdd:U1.NonZero;return z5(P4(w5(t),n)).filter(r=>r.length>=3)}function T4(t,e,n){if(!e.length)return[];let r=new A2;r.addSubject(w5(e)),n.length&&r.addClip(w5(n));let c=[];return r.execute(t,U1.NonZero,c),z5(c).filter(a=>a.length>=3)}var g0=(t,e)=>e.length?T4(r0.Difference,t,e):s1(t),K1=(t,e)=>T4(r0.Intersection,t,e),m3=(t,e)=>T4(r0.Xor,t,e);function Y0(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let r=[];for(let m of e)for(let g=0;g<m.length;g++){let v=m[g],b=m[(g+1)%m.length];(v[0]!==b[0]||v[1]!==b[1])&&r.push([v,b])}if(!r.length)return n==="outside"?t:[];let c=w0(e),a=Math.max(c[2]-c[0],c[3]-c[1],1e-6)/Math.max(1,Math.sqrt(r.length)),s=m=>Math.floor(m/a),o=new Map,i=new Map,l=(m,g,v)=>{let b=m.get(g);b?b[b.length-1]!==v&&b.push(v):m.set(g,[v])};r.forEach(([m,g],v)=>{let b=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let y=0;y<=b;y++){let x=m[0]+(g[0]-m[0])*y/b,w=m[1]+(g[1]-m[1])*y/b;for(let M of[-1,0,1])for(let k of[-1,0,1])l(o,`${s(x)+M},${s(w)+k}`,v)}for(let y=s(Math.min(m[1],g[1]));y<=s(Math.max(m[1],g[1]));y++)l(i,y,v)});let h=(m,g)=>{let v=new Set,b=0,y=1;for(let k of[0,1]){let z=g[k]-m[k],A=c[k]-a,S=c[k+2]+a;if(z===0){if(m[k]<A||m[k]>S)return v;continue}let C=(A-m[k])/z,I=(S-m[k])/z;b=Math.max(b,Math.min(C,I)),y=Math.min(y,Math.max(C,I))}if(!(b<=y))return v;let x=[m[0]+(g[0]-m[0])*b,m[1]+(g[1]-m[1])*b],w=[m[0]+(g[0]-m[0])*y,m[1]+(g[1]-m[1])*y],M=Math.max(1,Math.ceil(Math.hypot(w[0]-x[0],w[1]-x[1])/a*2));for(let k=0;k<=M;k++){let z=x[0]+(w[0]-x[0])*k/M,A=x[1]+(w[1]-x[1])*k/M;for(let S of o.get(`${s(z)},${s(A)}`)??[])v.add(S)}return v},u=.5/m2,f=m=>{for(let v of o.get(`${s(m[0])},${s(m[1])}`)??[]){let[b,y]=r[v],x=y[0]-b[0],w=y[1]-b[1],M=Math.max(0,Math.min(1,((m[0]-b[0])*x+(m[1]-b[1])*w)/(x*x+w*w)));if(Math.hypot(m[0]-b[0]-M*x,m[1]-b[1]-M*w)<=u)return}let g=0;for(let v of i.get(s(m[1]))??[]){let[b,y]=r[v],x=(y[0]-b[0])*(m[1]-b[1])-(m[0]-b[0])*(y[1]-b[1]);b[1]<=m[1]?y[1]>m[1]&&x>0&&g++:y[1]<=m[1]&&x<0&&g--}return g!==0},d=m=>Math.round(m*m2)/m2,p=[];for(let m of t){let g=null,v=()=>{g&&g.length>=2&&p.push(g),g=null};for(let b=1;b<m.length;b++){let y=m[b-1],x=m[b],w=x[0]-y[0],M=x[1]-y[1];if(!w&&!M)continue;let k=[0,1];for(let A of h(y,x)){let[S,C]=r[A],I=C[0]-S[0],L=C[1]-S[1],T=w*L-M*I;if(Math.abs(T)>1e-15){let q=((S[0]-y[0])*L-(S[1]-y[1])*I)/T,P=((S[0]-y[0])*M-(S[1]-y[1])*w)/T;q>0&&q<1&&P>=0&&P<=1&&k.push(q)}else{let q=w*w+M*M;for(let P of[S,C]){let F=((P[0]-y[0])*w+(P[1]-y[1])*M)/q,j=Math.abs((P[0]-y[0])*M-(P[1]-y[1])*w)/Math.sqrt(q);F>0&&F<1&&j<=u&&k.push(F)}}}k.sort((A,S)=>A-S);let z=Math.hypot(w,M);for(let A=1;A<k.length;A++){if((k[A]-k[A-1])*z<1e-9||k[A]-k[A-1]<1e-300)continue;let S=[d(y[0]+w*k[A-1]),d(y[1]+M*k[A-1])],C=[d(y[0]+w*k[A]),d(y[1]+M*k[A])],I=(k[A-1]+k[A])/2,L=f([y[0]+w*I,y[1]+M*I]);if(L!==void 0&&L===(n==="inside")){let T=g?g[g.length-1]:void 0;g&&T&&T[0]===S[0]&&T[1]===S[1]?(C[0]!==T[0]||C[1]!==T[1])&&g.push(C):(v(),g=[S,C])}else v()}}v()}return p}function c0(t,e,n="round",r=.01){if(!t.length)return[];if(e===0)return s1(t);let c=n==="round"?_0.Round:n==="square"?_0.Square:_0.Miter,a=me(w5(s1(t)),e*m2,c,h0.Polygon,2,r*m2);return z5(a).filter(s=>s.length>=3)}function p3(t,e){if(!t.length||e<=0)return[];let n=me(F6(t),e/2*m2,_0.Round,h0.Round,2,.01*m2);return z5(n)}function R0(t){if(!t.length)return[];let e=new M5,n=new A2;n.addSubject(w5(t)),n.execute(r0.Union,U1.NonZero,e);let r=[],c=a=>{for(let s=0;s<a.count;s++){let o=a.child(s),i=[o.poly];for(let l=0;l<o.count;l++){let h=o.child(l);i.push(h.poly),c(h)}r.push(z5(i))}};return c(e),r}function b1(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 D6(t){let e=0,n=0,r=0;for(let c of t){if(c.length<3)continue;let[a,s]=c[0];for(let o=0,i=c.length-1;o<c.length;i=o++){let l=c[i][0]-a,h=c[i][1]-s,u=c[o][0]-a,f=c[o][1]-s,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+a*d/2,r+=(h+f)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,r/e]}}function R3(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 k5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function O6(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,r=new Map;for(let[c,a]of t)r.set(c,{regions:a.regions.map(s=>{let o=s.map(i=>k5(e,i));return n?o.reverse():o}),lines:a.lines.map(s=>s.map(o=>k5(e,o)))});return r}function g3(t,e){return{layers:O6(t.layers,e),parts:t.parts.map(n=>({...n,layers:O6(n.layers,e)}))}}function C2(t){let e=T0();for(let n of t){for(let[r,c]of n.layers){let a=e.layers.get(r)??{regions:[],lines:[]};for(let s of c.regions)a.regions.push(s);for(let s of c.lines)a.lines.push(s);e.layers.set(r,a)}for(let r of n.parts)e.parts.push(r)}return e}var n2="\0hidden";function $6(t,e){let n={regions:[],lines:[]};for(let[a,s]of t)if(a!==n2){for(let o of s.regions)n.regions.push(o);for(let o of s.lines)n.lines.push(o)}let r=new Map([[e,n]]),c=t.get(n2);return c&&e!==n2&&r.set(n2,c),r}function S5(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:$6(t.layers,e),parts:t.parts.map(n=>({...n,layers:$6(n.layers,e)}))}}function w0(t){let e=1/0,n=1/0,r=-1/0,c=-1/0;for(let a of t)for(let[s,o]of a)s<e&&(e=s),o<n&&(n=o),s>r&&(r=s),o>c&&(c=o);return e===1/0?null:[e,n,r,c]}function J0(t,e){let n=[];for(let[r,c]of t)if(!e?.(r))for(let a of[...c.regions,...c.lines])n.push(a);return w0(n)}function pe(t){let e=[...t].sort((a,s)=>a[0]-s[0]||a[1]-s[1]);if(e.length<3)return e;let n=(a,s,o)=>(s[0]-a[0])*(o[1]-a[1])-(s[1]-a[1])*(o[0]-a[0]),r=[];for(let a of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],a)<=0;)r.pop();r.push(a)}let c=[];for(let a=e.length-1;a>=0;a--){let s=e[a];for(;c.length>=2&&n(c[c.length-2],c[c.length-1],s)<=0;)c.pop();c.push(s)}return c.pop(),r.pop(),r.concat(c)}function q6(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 F3(t,e,n){let r=[];for(let c=0;c<n;c++){let a=2*Math.PI*c/n;r.push([t*Math.cos(a),e*Math.sin(a)])}return r}function N6(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 c=Math.max(1,Math.ceil(r(n)/4)),a=[],s=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[o,i,l]of s)for(let h=0;h<=c;h++){let u=(l+90*h/c)*Math.PI/180;a.push([o+n*Math.cos(u),i+n*Math.sin(u)])}return a}function I4(t,e){let n=s1(t);for(let r=0;r<100;r++){let c=R0(n);if(c.length<=1)return n;let a=o=>o.reduce((i,l)=>i+b1(l),0);c.sort((o,i)=>a(i)-a(o));let s=[];for(let o=1;o<c.length;o++){let i=1/0,l=[0,0],h=[0,0];for(let[y,x]of c[o][0])for(let w=0;w<c.length;w++)if(w!==o)for(let M of c[w])for(let k=0,z=M.length-1;k<M.length;z=k++){let[A,S]=M[z],[C,I]=M[k],L=C-A,T=I-S,q=L*L+T*T,P=q?Math.max(0,Math.min(1,((y-A)*L+(x-S)*T)/q)):0,F=A+P*L,j=S+P*T,_=Math.hypot(y-F,x-j);_<i&&([i,l,h]=[_,[y,x],[F,j]])}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[p,m]=[-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]-p,g[1]-m],[v[0]-p,v[1]-m],[v[0]+p,v[1]+m],[g[0]+p,g[1]+m]];s.push(b1(b)<0?b.reverse():b)}if(!s.length)return n;n=s1([...n,...s])}return n}function vr(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 U6(t){let{spacing:e,step:n,box:r}=t,c=e/2,a=e,s=new Map,o=[],i=[],l=[],h=[],u=[],f=(I,L)=>Math.floor((I-r[0])/a)*1000003+Math.floor((L-r[1])/a),d=(I,L,T)=>{let q=f(I[0],I[1]),P=o.length;o.push(I[0]),i.push(I[1]),l.push(L),h.push(T);let F=s.get(q);F?F.push(P):s.set(q,[P])},p=Math.ceil(2*e/n)+2,m=(I,L,T=-1,q=0)=>{let P=Math.floor((I[0]-r[0])/a),F=Math.floor((I[1]-r[1])/a);for(let j=P-1;j<=P+1;j++)for(let _=F-1;_<=F+1;_++){let Q=s.get(j*1000003+_);if(Q)for(let H of Q){let B=l[H];if(!(!u[B]&&B!==T)&&!(B===T&&Math.abs(h[H]-q)<p)&&Math.hypot(o[H]-I[0],i[H]-I[1])<L)return!1}}return!0},g=[],v=0,b=Math.ceil(4*(r[2]-r[0]+r[3]-r[1]+e)/n+2*p),y=(I,L)=>{let T=t.dir(I);if(!T)return null;let q=[I[0]+L*T[0]*n/2,I[1]+L*T[1]*n/2],P=t.dir(q)??T;return P[0]*T[0]+P[1]*T[1]<0?null:[I[0]+L*P[0]*n,I[1]+L*P[1]*n]},x=I=>{let L=g.length;u[L]=!1,d(I,L,0);let T=[[],[]];for(let[F,j]of[[0,1],[1,-1]]){let _=I;for(let Q=1;Q<=b;Q++){let H=y(_,j);if(!H)break;let B=j*Q;if(!t.inside(H)){T[F].push(H);break}if(!m(H,c,L,B))break;if(T[F].push(H),d(H,L,B),++v>t.maxPoints)throw new Error(`the lines have more than ${t.maxPoints} points: use a larger spacing or step`);t.tick(),_=H}}let q=[...T[1].reverse(),I,...T[0]],P=0;for(let F=1;F<q.length;F++)P+=Math.hypot(q[F][0]-q[F-1][0],q[F][1]-q[F-1][1]);return g.push(q),q.length<2||P<t.minLength?null:(u[L]=!0,q)},w=vr(t.seed),M=[];for(let I=r[0]+e/2;I<r[2];I+=e)for(let L=r[1]+e/2;L<r[3];L+=e)M.push([I+(w()-.5)*e,L+(w()-.5)*e]);for(let I=M.length-1;I>0;I--){let L=Math.floor(w()*(I+1));[M[I],M[L]]=[M[L],M[I]]}let k=[],z=[],A=Math.max(1,Math.round(e/(2*n))),S=I=>{if(!t.inside(I)||!m(I,e)||!t.dir(I))return;let L=x(I);L&&(k.push(L),z.push(L))},C=0;for(;;){for(;z.length;){let I=z.shift();for(let L=0;L<I.length;L+=A){let T=I[Math.max(0,L-1)],q=I[Math.min(I.length-1,L+1)],P=Math.hypot(q[0]-T[0],q[1]-T[1]);if(P===0)continue;let F=-(q[1]-T[1])/P,j=(q[0]-T[0])/P;for(let _ of[1,-1])S([I[L][0]+_*F*e,I[L][1]+_*j*e])}}if(C>=M.length)break;S(M[C++])}return k}function B6(t,e,n,r,c,a,s){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,x=o(b,y),w=g&1?o(b,y+1):o(b+1,y),M=x===w?.5:(s-x)/(w-x);return g&1?[r+b*a,c+(y+M)*a]:[r+(b+M)*a,c+y*a]},u=new Map,f=(g,v)=>{for(let[b,y]of[[g,v],[v,g]]){let x=u.get(b);x?x.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),x=o(v+1,g+1),w=o(v,g+1);if(Number.isNaN(b+y+x+w))continue;let M=(b>=s?1:0)|(y>=s?2:0)|(x>=s?4:0)|(w>=s?8:0);if(M===0||M===15)continue;let k=i(v,g),z=l(v+1,g),A=i(v,g+1),S=l(v,g);if(M===5||M===10){let I=(b+y+x+w)/4>=s;M===5===I?(f(k,z),f(S,A)):(f(S,k),f(z,A));continue}let C=[];(M&1)!==(M&2)>>1&&C.push(k),(M&2)>>1!==(M&4)>>2&&C.push(z),(M&4)>>2!==(M&8)>>3&&C.push(A),(M&8)>>3!==(M&1)&&C.push(S),C.length===2&&f(C[0],C[1])}let d=new Set,p=g=>{let v=[h(g)];d.add(g);let b=g;for(;;){let y=(u.get(b)??[]).find(x=>!d.has(x));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}},m=[];for(let[g,v]of u)v.length===1&&!d.has(g)&&m.push(p(g));for(let g of u.keys())d.has(g)||m.push(p(g));return m.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 _6(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)}`,c=new Map,a=(l,h)=>{let u=r(l),f=c.get(u);f?f.push(h):c.set(u,[h])};n.forEach((l,h)=>{a(l[0],h),a(l[l.length-1],h)});let s=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(s[l])continue;s[l]=!0;let h=n[l];if(!o(h))for(let u=0;u<2;u++){for(;;){let f=h[h.length-1],d=(c.get(r(f))??[]).find(g=>!s[g]);if(d===void 0)break;s[d]=!0;let p=n[d],m=r(p[0])===r(f)?p:[...p].reverse();if(h=h.concat(m.slice(1)),o(h))break}if(o(h))break;h=h.reverse()}i.push(h)}return yr(i)}function yr(t){let e=t.length;if(e<2)return t;let n=1/0,r=1/0,c=-1/0,a=-1/0;for(let m of t)for(let g of[m[0],m[m.length-1]])n=Math.min(n,g[0]),r=Math.min(r,g[1]),c=Math.max(c,g[0]),a=Math.max(a,g[1]);let s=Math.max((c-n+a-r)/Math.sqrt(e),1e-6),o=m=>Math.floor((m-n)/s),i=m=>Math.floor((m-r)/s),l=o(c)+1,h=i(a)+1,u=new Map;t.forEach((m,g)=>{for(let v of[m[0],m[m.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=[],p=[0,0];for(let m=0;m<e;m++){let g=-1,v=1/0,b=!1,y=Math.min(Math.max(o(p[0]),0),l-1),x=Math.min(Math.max(i(p[1]),0),h-1);for(let M=0;M<=Math.max(l,h);M++){for(let k=y-M;k<=y+M;k++)for(let z=x-M;z<=x+M;z++)if(Math.max(Math.abs(k-y),Math.abs(z-x))===M&&!(k<0||z<0||k>=l||z>=h))for(let A of u.get(z*l+k)??[]){if(f[A])continue;let S=t[A],C=Math.hypot(S[0][0]-p[0],S[0][1]-p[1]),I=Math.hypot(S[S.length-1][0]-p[0],S[S.length-1][1]-p[1]);C<v&&([g,v,b]=[A,C,!1]),I<v&&([g,v,b]=[A,I,!0])}if(g>=0&&v<=M*s)break}if(g<0){for(let M=0;M<e;M++)if(!f[M]){g=M;break}}f[g]=!0;let w=b?[...t[g]].reverse():t[g];d.push(w),p=w[w.length-1]}return d}function j6(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 c=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),a=(r-n)/c||1,s=Array.from({length:c},()=>[]);return e.forEach(([,o,,i],l)=>{let h=Math.max(0,Math.min(c-1,Math.floor((Math.min(o,i)-n)/a))),u=Math.max(0,Math.min(c-1,Math.floor((Math.max(o,i)-n)/a)));for(let f=h;f<=u;f++)s[f].push(l)}),([o,i])=>{if(i<n||i>r)return!1;let l=0;for(let h of s[Math.max(0,Math.min(c-1,Math.floor((i-n)/a)))]){let[u,f,d,p]=e[h];f<=i?p>i&&(d-u)*(i-f)-(o-u)*(p-f)>0&&l++:p<=i&&(d-u)*(i-f)-(o-u)*(p-f)<0&&l--}return l!==0}}var G6=Math.PI/180;function D1(t,e){let n=new Array(16).fill(0);for(let r=0;r<4;r++)for(let c=0;c<4;c++)for(let a=0;a<4;a++)n[r*4+c]+=t[r*4+a]*e[a*4+c];return n}function ge(t,e){let n=Math.cos(e*G6),r=Math.sin(e*G6);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 H4=t=>Math.abs(t)<1e-12?0:t;function N0(t){if(t.matrix)return t.matrix.map(H4);let[e,n,r]=t.rotate,c=D1(ge(2,r),D1(ge(1,n),ge(0,e)));return c[3]=t.at[0],c[7]=t.at[1],c[11]=t.at[2],c.map(H4)}function D2(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 A5(t){let[e,n,r]=[t[3],t[7],t[11]],c=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[c[0],c[1],c[2],-(c[0]*e+c[1]*n+c[2]*r),c[3],c[4],c[5],-(c[3]*e+c[4]*n+c[5]*r),c[6],c[7],c[8],-(c[6]*e+c[7]*n+c[8]*r),0,0,0,1]}function ve(t){let[e,n,r,c]=[1/0,1/0,-1/0,-1/0];for(let a of t)for(let[s,o]of a)e=Math.min(e,s),n=Math.min(n,o),r=Math.max(r,s),c=Math.max(c,o);return[e,n,r,c]}function Y6(t){let[e,n,r,c]=ve(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let o of[e,r])for(let i of[n,c])for(let l of[0,t.thickness]){let h=D2(t.matrix,o,i,l);for(let u=0;u<3;u++)a[u]=Math.min(a[u],h[u]),s[u]=Math.max(s[u],h[u])}return[a,s]}function J6(t,e,n=10){let r=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(Y6))for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),c[f]=Math.max(c[f],u[f]);let a=e.map(h=>ve(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),c[0]-r[0]),o=0,i=0,l=0;return e.map((h,u)=>{let[f,d,p,m]=a[u];o>0&&o+p-f>s&&(o=0,i+=l+n,l=0);let g=[1,0,0,c[0]+n+o-f,0,1,0,r[1]+i-d,0,0,1,r[2],0,0,0,1];return o+=p-f+n,l=Math.max(l,m-d),{...h,matrix:g.map(H4)}})}var br=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),D3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],ye=(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]],V4=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],N3=t=>[t[2],t[6],t[10]],W6=t=>[t[3],t[7],t[11]],xr=(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 q3(t,e,n){let r=n[0]*n[0]+n[1]*n[1],c=[];for(let a of t)for(let s=0,o=a.length-1;s<a.length;o=s++){let i=a[o],l=a[s],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],p=i[1]+(l[1]-i[1])*f-e[1];c.push((d*n[0]+p*n[1])/r)}return c.sort((a,s)=>a-s)}function O4(t,e,n){let r=0,c=0,a=0,s=0,o=0;for(;s+1<t.length&&o+1<e.length;){let i=Math.max(t[s],e[o]),l=Math.min(t[s+1],e[o+1])-i;l>n&&(r+=l,l>a&&(a=l,c=i+l/2)),t[s+1]<e[o+1]?s+=2:o+=2}return{total:r,mid:c,run:a}}function Mr(t,e){let[n,r,c]=D2(A5(t.matrix),e[0],e[1],e[2]);if(c<0||c>t.thickness)return!1;let a=!1;for(let s of t.outline)for(let o=0,i=s.length-1;o<s.length;i=o++){let[l,h]=s[i],[u,f]=s[o];h>r!=f>r&&n<l+(u-l)*(r-h)/(f-h)&&(a=!a)}return a}var be=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[a,s]of this.seen){for(let o=0;o<3;o++)n[o]+=a[o]*s;e+=s}for(let a=0;a<3;a++)n[a]/=e;if(this.parts.length&&this.parts.every(a=>Mr(a,n)))return n;let r=this.seen[0][0],c=1/0;for(let[a]of this.seen){let s=Math.hypot(a[0]-n[0],a[1]-n[1],a[2]-n[2]);s<c&&([r,c]=[a,s])}return r}};function xe(t,e,n,r){let c=t+n,a=e-n;if(a<=c)return{at:[],size:0};let s=Math.max(4,Math.ceil((a-c)/r));return{at:Array.from({length:s},(o,i)=>c+(a-c)*(i+.5)/s),size:(a-c)/s}}function X6(t,e,n){let r=D2(t,e[0],e[1],e[2]),c=xr(t,n);return[[r[0],r[1]],[c[0],c[1]]]}function K6(t,e,n,r,c,a,s,o=!1){let i=N3(t.matrix),l=N3(e.matrix),h=ye(i,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=ye(f,i),p=D3(l,d),m=W6(t.matrix),g=D3(l,W6(e.matrix)),v=1/0,b=-1/0;for(let z of e.outline)for(let[A,S]of z)for(let C of[0,e.thickness]){let I=D2(e.matrix,A,S,C),L=D3(i,[I[0]-m[0],I[1]-m[1],I[2]-m[2]]);L<v&&(v=L),L>b&&(b=L)}let y=xe(Math.max(0,v),Math.min(t.thickness,b),c,a),x=1/0,w=-1/0;for(let z of t.outline)for(let[A,S]of z){let C=D2(t.matrix,A,S,0),I=D3(d,[C[0]-m[0],C[1]-m[1],C[2]-m[2]]);I<x&&(x=I),I>w&&(w=I)}let M=0,k=new be([t,e]);for(let z of y.at){let A=V4(m,i,z),S=(g-D3(l,A))/p,C=(g+e.thickness-D3(l,A))/p,I=xe(Math.max(x,Math.min(S,C)),Math.min(w,Math.max(S,C)),c,a);for(let L of I.at){let T=V4(A,d,L),[q,P]=X6(n,T,f),[F,j]=X6(r,T,f),_=O4(q3(t.outline,q,P),q3(e.outline,F,j),c);if(M+=_.total*y.size*I.size,k.see(_.run,()=>V4(T,f,_.mid)),M>s&&!o)return k.at}}return M>s?k.at:void 0}function Q6(t,e,n,r,c,a,s=!1){let o=[0,1,2,3].flatMap(S=>[0,1,2,3].map(C=>{let I=0;for(let L=0;L<4;L++)I+=n[S*4+L]*e.matrix[L*4+C];return I})),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 be([t,e]),d=e.outline.map(S=>S.map(([C,I])=>[o[0]*C+o[1]*I+o[3],o[4]*C+o[5]*I+o[7]])),[p,m,g,v]=ve(t.outline),[b,y,x,w]=ve(d),M=xe(Math.max(m,y),Math.min(v,w),r,c),k=0;for(let S of M.at){let C=O4(q3(t.outline,[0,S],[1,0]),q3(d,[0,S],[1,0]),r);if(k+=C.total*M.size*h,f.see(C.run,()=>D2(t.matrix,C.mid,S,u)),k>a&&!s)return f.at}let z=xe(Math.max(p,b),Math.min(g,x),r,c),A=0;for(let S of z.at){let C=O4(q3(t.outline,[S,0],[0,1]),q3(d,[S,0],[0,1]),r);if(A+=C.total*z.size*h,f.see(C.run,()=>D2(t.matrix,S,C.mid,u)),A>a&&!s)return f.at}return k>a||A>a?f.at:void 0}function en(t,e=1/0,n=.05,r=.25,c=.1){let a=t.map(Y6),s=t.map(h=>A5(h.matrix)),o=t.map((h,u)=>u).sort((h,u)=>a[h][0][0]-a[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(a[d][0][0]>=a[f][1][0]-n)break;if(!br(a[f],a[d],n))continue;if(++l>e)return{found:i,complete:!1};let[p,m]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]],y=Math.hypot(...ye(N3(p.matrix),N3(m.matrix)))<1e-9?Q6(p,m,g,n,r,c):K6(p,m,g,v,n,r,c);y&&i.push([p,m,y])}return{found:i,complete:!0}}function tn(t,e,n=.05,r=.25,c=.1){let a=Math.hypot(...ye(N3(t.matrix),N3(e.matrix)))<1e-9,s=A5(t.matrix);return a?Q6(t,e,s,n,r,c,!0):K6(t,e,s,A5(e.matrix),n,r,c,!0)}function j0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var $4=j0(0,0,0);function v0(t){return A5(t)}function nn(t,e,n=t.angle,r=t.x1){let c=r-t.x0;if(!n||!(c>0))return j0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return D1(j0(t.x0,0,s),D1(ge(1,-n),j0(-t.x0-c,0,-s)))}function L5(t){return[...t].sort((e,n)=>e.x0-n.x0)}var Me=t=>t.length>0&&t.every(e=>e.mirrored),Z6=[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],wr=t=>D1(Z6,D1(t,Z6));function R4(t){return L5(t).map(e=>e.mirrored?[-e.x1,-e.x0]:[e.x0,e.x1])}function we(t,e){let n=[j0(0,0,0)];for(let r of L5(t))n.push(D1(n[n.length-1],nn(r,e)));return Me(t)?n.map(wr):n}function U3(t,e,n){if(Me(t)){let a=U3(t.map(({mirrored:s,...o})=>o),e,[-n[0],n[1],n[2]]);return[-a[0],a[1],a[2]]}let r=L5(t),c=we(r,e);for(let a=r.length-1;a>=0;a--){let s=r[a];if(n[0]>=s.x1)return D2(c[a+1],...n);if(n[0]>s.x0){let o=(n[0]-s.x0)/(s.x1-s.x0),i=D1(c[a],nn(s,e,s.angle*o,n[0]));return D2(i,...n)}}return n}function rn(t,e){let n=Me(t)?-e:e;return L5(t).filter(r=>(r.x0+r.x1)/2<n).length}function ke(t){if(!t.bends?.length)return[t];let e=L5(t.bends),n=we(t.bends,t.thickness),r=Me(t.bends),c=1e7,a=[];for(let s=0;s<=e.length;s++){let o=s===0?-c:e[s-1].x1,i=s===e.length?c:e[s].x0;if(!(i>o))continue;let[l,h]=r?[-i,-o]:[o,i],u=[[l,-c],[h,-c],[h,c],[l,c]],f=K1(t.outline,[u]);f.length&&a.push({...t,outline:f,bends:void 0,matrix:D1(t.matrix,n[s])})}return a}var kr=2e3;function B3(t,e,n=2){if(!e?.length)return R0(t);let r=1e7,c=1/0,a=-1/0;for(let f of t)for(let[d]of f)c=Math.min(c,d),a=Math.max(a,d);let s=R4(e).map(([f,d])=>[Math.max(f,c),Math.min(d,a)]).filter(([f,d])=>d>f),o=s.reduce((f,[d,p])=>f+(p-d),0),i=Math.max(n,o/kr),l=[];for(let[f,d]of s){let p=Math.max(1,Math.ceil((d-f)/i));for(let m=0;m<=p;m++)l.push(f+(d-f)*m/p)}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 p of R0(K1(t,[d])))u.push(p)}return u}var Z2=1e6,ze=.01,Y2=t=>b1(t)<0?[...t].reverse():t;function zr(t,e){let n=D1(v0(t.matrix),e.matrix),[r,c]=[n[8],n[9]],a=Math.hypot(r,c);if(a<1e-9)return[];let s=0,o=e.thickness,i=L=>(-n[11]-Math.max(n[10]*s,n[10]*o)+L)/a,l=L=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*o)-L)/a;if(!(l(ze)>i(ze)))return[];let[h,u]=[r/a,c/a],[f,d]=[-u,h],p=(L,T)=>[[h*L-f*Z2,u*L-d*Z2],[h*T-f*Z2,u*T-d*Z2],[h*T+f*Z2,u*T+d*Z2],[h*L+f*Z2,u*L+d*Z2]],m=1/0,g=-1/0;for(let L of e.outline)for(let[T,q]of L)for(let P of[s,o]){let F=n[8]*T+n[9]*q+n[10]*P+n[11];F<m&&(m=F),F>g&&(g=F)}if(Math.min(t.thickness,g)-Math.max(0,m)<Math.min(1,t.thickness/2))return[];let b=((L,T)=>K1(e.outline,[Y2(p(L,T))]).filter(q=>Math.abs(b1(q))>1e-6))(i(ze),l(ze));if(!b.length)return[];let y=Math.abs(l(0)-i(0))+1,x=L=>{let T=L.map(([F,j])=>[F-h*y,j-u*y]),q=L.map(([F,j])=>[F+h*y,j+u*y]),P=[Y2(T),Y2(q)];for(let F=0;F<L.length;F++){let j=(F+1)%L.length,_=[T[F],T[j],q[j],q[F]];Math.abs(b1(_))>1e-12&&P.push(Y2(_))}return P},w=s1(b.flatMap(x),"nonzero"),M=K1(e.outline,w).filter(L=>Math.abs(b1(L))>1e-6);if(!M.length)return[];let k=L=>([T,q])=>[n[0]*T+n[1]*q+n[2]*L+n[3],n[4]*T+n[5]*q+n[6]*L+n[7]],z=t.thickness,A=(L,T)=>(L-n[11]-n[10]*T)/a,S=[],C=L=>{L.length>=3&&Math.abs(b1(L))>1e-9&&S.push(Y2(L))};for(let L of[s,o])for(let T of K1(M,[Y2(p(A(0,L),A(z,L)))]))C(T.map(k(L)));for(let L of[0,z])if(Math.abs(n[10])>1e-9){let[T,q]=[A(L,s),A(L,o)].sort((P,F)=>P-F);for(let P of K1(M,[Y2(p(T,q))]))C(P.map(([F,j])=>k((L-n[11]-n[8]*F-n[9]*j)/n[10])([F,j])))}else{let T=A(L,0);for(let q of K1(M,[Y2(p(T-1e-4,T+1e-4))])){let[P,F]=[1/0,-1/0];for(let[Q,H]of q){let B=f*Q+d*H;P=Math.min(P,B),F=Math.max(F,B)}if(!(F-P>1e-6))continue;let j=[h*T+f*P,u*T+d*P],_=[h*T+f*F,u*T+d*F];C([k(s)(j),k(s)(_),k(o)(_),k(o)(j)])}}let I=(L,T,q)=>n[8]*L+n[9]*T+n[10]*q+n[11];for(let L of M)for(let T=0;T<L.length;T++){let[q,P]=L[T],[F,j]=L[(T+1)%L.length],_=[[0,s],[1,s],[1,o],[0,o]],Q=([H,B])=>I(q+(F-q)*H,P+(j-P)*H,B);for(let[H,B]of[[1,0],[-1,-z]]){let Y=X=>H*Q(X)>=B,e1=[];for(let X=0;X<_.length;X++){let M1=_[X],v1=_[(X+1)%_.length];if(Y(M1)&&e1.push(M1),Y(M1)!==Y(v1)){let p1=H*Q(M1)-B,G1=H*Q(v1)-B,F1=p1/(p1-G1);e1.push([M1[0]+(v1[0]-M1[0])*F1,M1[1]+(v1[1]-M1[1])*F1])}}if(_=e1,!_.length)break}_.length>=3&&C(_.map(([H,B])=>k(B)([q+(F-q)*H,P+(j-P)*H])))}return S.length?s1(S,"nonzero"):[]}function cn(t,e,n){let r=[];for(let a of e)for(let s of zr(t,a))r.push(s);if(!r.length)return[];let c=R0(K1(s1(r),t.outline)).filter(a=>a.reduce((s,o)=>s+b1(o),0)>1e-4);return c.length?c0(c.flat(),n/2,"miter"):[]}var C5=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],an=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Sr=(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]],sn=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},P5={turn:.3,press:-.1};function F4(t){let e=sn(C5(t.to,t.from)),n=C5(t.up,e.map(c=>c*an(t.up,e)));Math.hypot(...n)<1e-9&&(n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0]);let r=sn(C5(n,e.map(c=>c*an(n,e))));return{axis:e,u:Sr(r,e),v:r}}function Ar(t,e){let{u:n,v:r}=F4(t);if(Array.isArray(t.size)){let[s,o]=[t.size[0]/2+e/2,t.size[1]/2+e/2];return[[-s,-o],[s,-o],[s,o],[-s,o]].map(([i,l])=>[n[0]*i+r[0]*l,n[1]*i+r[1]*l,n[2]*i+r[2]*l])}let c=t.size/2+e/2,a=t.sides<12?t.sides:64;return Array.from({length:a},(s,o)=>{let i=2*Math.PI*o/a,[l,h]=[Math.cos(i)*c,Math.sin(i)*c];return[n[0]*h+r[0]*l,n[1]*h+r[1]*l,n[2]*h+r[2]*l]})}function on(t,e,n){let r=C5(e.to,e.from);if(!(Math.hypot(...r)>1e-9))return;let c=v0(t.matrix),a=i=>[c[0]*i[0]+c[1]*i[1]+c[2]*i[2]+c[3],c[4]*i[0]+c[5]*i[1]+c[6]*i[2]+c[7],c[8]*i[0]+c[9]*i[1]+c[10]*i[2]+c[11]],s=C5(a(r),a([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let o=[];for(let i of Ar(e,n)){let l=a([e.from[0]+i[0],e.from[1]+i[1],e.from[2]+i[2]]),h=(0-l[2])/s[2],u=(t.thickness-l[2])/s[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]+s[0]*f,l[1]+s[1]*f])}return o.length>=3?pe(o):void 0}var Se=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Lr=(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]],ln=t=>[t[2],t[6],t[10]],hn=t=>[t[3],t[7],t[11]];function un(t,e,n){let r=[];for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let o=c[s],i=c[a],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((c,a)=>c-a)}function fn(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 Cr(t,[e,n]){let r=!1;for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let[o,i]=c[s],[l,h]=c[a];i>n!=h>n&&e<o+(l-o)*(n-i)/(h-i)&&(r=!r)}return r}function dn(t,e,n){let r={a:[],b:[],thin:0},c=ln(t.matrix),a=ln(e.matrix),s=Lr(c,a),o=Math.hypot(...s);if(o<1e-6)return r;let i=Math.abs(Se(c,a)),l=[s[0]/o,s[1]/o,s[2]/o],h=Se(c,hn(t.matrix))+t.thickness/2,u=Se(a,hn(e.matrix))+e.thickness/2,f=Se(c,a),d=1-f*f,p=(h-u*f)/d,m=(u-h*f)/d,g=[p*c[0]+m*a[0],p*c[1]+m*a[1],p*c[2]+m*a[2]],v=S=>{let C=v0(S.matrix);return[[C[0]*g[0]+C[1]*g[1]+C[2]*g[2]+C[3],C[4]*g[0]+C[5]*g[1]+C[6]*g[2]+C[7]],[C[0]*l[0]+C[1]*l[1]+C[2]*l[2],C[4]*l[0]+C[5]*l[1]+C[6]*l[2]]]},[b,y]=v(t),[x,w]=v(e),M=un(t.outline,b,y),k=un(e.outline,x,w),z=(e.thickness+t.thickness*i)/o+n,A=(t.thickness+e.thickness*i)/o+n;for(let S=0;S+1<M.length;S+=2)for(let C=0;C+1<k.length;C+=2){let I=Math.max(M[S],k[C]),L=Math.min(M[S+1],k[C+1]);if(!(L-I>.01))continue;let T=(I+L)/2,[q,P]=fn(M,T),[F,j]=fn(k,T),_=Math.max(P-T,T-F)<=Math.max(T-q,j-T),Q=(Y,e1,X,M1,v1,p1)=>{let G1=[-X[1],X[0]],F1=(a1,x1)=>[e1[0]+X[0]*(T+v1*a1)+G1[0]*x1,e1[1]+X[1]*(T+v1*a1)+G1[1]*x1],V=p1+M1+1,U=[F1(0,-M1/2),F1(V,-M1/2),F1(V,M1/2),F1(0,M1/2)];b1(U)<0&&U.reverse();let r1=F1(Math.min(.01,p1/2),0),h1=R0(K1([U],Y.outline)).find(a1=>Cr(a1,r1));if(!(!h1||!(h1.reduce((a1,x1)=>a1+b1(x1),0)>1e-4)))return K1(c0(h1,.05,"miter"),[U])},H=Q(t,b,y,z,_?1:-1,_?P-T:T-q),B=Q(e,x,w,A,_?-1:1,_?T-F:j-T);if(!H||!B){r.thin++;continue}r.a.push(...H),r.b.push(...B)}return r}var h2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",p2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",pn=t=>typeof t=="number",G0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",K0=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function D4(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)D4(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function Ae(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 c=0;c<r;c++)n.push(t.start+c*t.step);return n}function y0(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 mn=(t,e,n)=>h2(t)&&h2(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:G0(t)&&G0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([r,c])=>e.fields.has(r)&&_3(c,e.fields.get(r),n)):t===e;function _3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return mn(t,e,n);let r=new Map,c=[],a=(s,o)=>{let i=r.get(s);return i?.has(o)?!0:s.length!==o.length?!1:(i||r.set(s,i=new Set),i.add(o),c.push([s,o,0]),!0)};if(!a(t,e))return!1;for(;c.length;){let s=c[c.length-1];if(s[2]===s[0].length){c.pop();continue}let o=s[0][s[2]],i=s[1][s[2]++];if(n?.(),Array.isArray(o)&&Array.isArray(i)?!a(o,i):!mn(o,i,n))return!1}return!0}function F0(t){return t===void 0?"undef":Array.isArray(t)?"list":h2(t)?"range":p2(t)?"function":G0(t)?"record":typeof t}function Pr(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?q2(t):h2(t)?`[${q2(t.start)}:${q2(t.step)}:${q2(t.end)}]`:p2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:G0(t)?"{}":String(t)}function j3(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=[],c=0,a=l=>{r.push(l),c+=l.length},s=[],o=t;for(;;){Array.isArray(o)?(a("["),s.push({items:o,i:0,close:"]"})):G0(o)&&o.fields.size?(a("{"),s.push({items:[...o.fields.values()],keys:[...o.fields.keys()],i:0,close:"}"})):a(Pr(o));let l=!1;for(;s.length&&!l&&c<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&a(", "),h.keys&&a(`${h.keys[h.i]} = `),o=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||c>e)break}let i=r.join("");return c>e?{text:i.slice(0,Math.max(e,0)),whole:!1}:{text:i,whole:!0}}function gn(t,e,n){let r=[],c=0;for(let a of t){r.length&&(c+=e.length);let s=j3(a,n-c);if(!s.whole)return;c+=s.text.length,r.push(s.text)}return r.join(e)}function C0(t){let e=j3(t,200,!0);return e.whole?e.text:e.text+"..."}var b0=t=>typeof t=="string"?t:C0(t);function U0(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 q2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function G3(t,e=.02){let n=[],r=[],c=[],a=[0,0],s=[0,0],o=l=>{c.length>=2&&(l?n:r).push(c),c=[]},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),a=s=[l.x,l.y],c=[s];else if(l.type==="L")s=[l.x,l.y],c.push(s);else if(l.type==="Q"){let[h,u]=s,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 p=d/f,m=1-p;c.push([m*m*h+2*m*p*l.x1+p*p*l.x,m*m*u+2*m*p*l.y1+p*p*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,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 p=d/f,m=1-p;c.push([m*m*m*h+3*m*m*p*l.x1+3*m*p*p*l.x2+p*p*p*l.x,m*m*m*u+3*m*m*p*l.y1+3*m*p*p*l.y2+p*p*p*l.y])}s=[l.x,l.y]}else o(!0),s=a,c=[a];return o(!1),{closed:n,open:r}}function W3(t,e=Math.PI/2,n){let r=x=>/^[a-zA-Z]$/.test(x),c=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,o="",i=0,l=0,h=0,u=0,f=0,d=0,p=0,m=0,g="",v=()=>{let x=c[s++];if(x===void 0||r(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},b=()=>{let x=c[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(c[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{y()}catch(x){if(!n)throw x;n(x.message)}return a;function y(){for(;s<c.length;){if(r(c[s]))o=c[s++];else if(o){if(o==="Z"||o==="z")throw new Error(`Bad path data near "${c[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=o===o.toLowerCase(),w=o.toUpperCase(),M=x?i:0,k=x?l:0;if(w==="M")i=M+v(),l=k+v(),h=i,u=l,a.push({type:"M",x:i,y:l}),o=x?"l":"L";else if(w==="L")i=M+v(),l=k+v(),a.push({type:"L",x:i,y:l});else if(w==="H")i=M+v(),a.push({type:"L",x:i,y:l});else if(w==="V")l=k+v(),a.push({type:"L",x:i,y:l});else if(w==="C"||w==="S"){let z,A;if(w==="C")z=M+v(),A=k+v();else{let I=g==="C"||g==="S";z=I?2*i-f:i,A=I?2*l-d:l}let S=M+v(),C=k+v();i=M+v(),l=k+v(),f=S,d=C,a.push({type:"C",x1:z,y1:A,x2:S,y2:C,x:i,y:l})}else if(w==="Q"||w==="T"){let z,A;if(w==="Q")z=M+v(),A=k+v();else{let S=g==="Q"||g==="T";z=S?2*i-p:i,A=S?2*l-m:l}i=M+v(),l=k+v(),p=z,m=A,a.push({type:"Q",x1:z,y1:A,x:i,y:l})}else if(w==="A"){let z=v(),A=v(),S=v(),C=b(),I=b(),L=M+v(),T=k+v();a.push(...Er(i,l,z,A,S,C,I,L,T,e)),i=L,l=T}else if(w==="Z")a.push({type:"Z"}),i=h,l=u;else throw new Error(`Unknown path command "${o}"`);g=w}}}function Er(t,e,n,r,c,a,s,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=c*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-o)/2,p=(e-i)/2,m=u*d+f*p,g=-f*d+u*p,v=m*m/(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*m*m,y=n*n*g*g+r*r*m*m,x=Math.sqrt(Math.max(0,b/y));a===s&&(x=-x);let w=x*n*g/r,M=-x*r*m/n,k=u*w-f*M+(t+o)/2,z=f*w+u*M+(e+i)/2,A=(P,F,j,_)=>Math.atan2(P*_-F*j,P*j+F*_),S=A(1,0,(m-w)/n,(g-M)/r),C=A((m-w)/n,(g-M)/r,(-m-w)/n,(-g-M)/r);!s&&C>0&&(C-=2*Math.PI),s&&C<0&&(C+=2*Math.PI);let I=Math.ceil(Math.abs(C)/l),L=[],T=P=>[k+n*Math.cos(P)*u-r*Math.sin(P)*f,z+n*Math.cos(P)*f+r*Math.sin(P)*u],q=P=>[-n*Math.sin(P)*u-r*Math.cos(P)*f,-n*Math.sin(P)*f+r*Math.cos(P)*u];for(let P=0;P<I;P++){let F=S+C*P/I,j=S+C*(P+1)/I,_=4/3*Math.tan((j-F)/4),Q=T(F),H=T(j),B=q(F),Y=q(j);L.push({type:"C",x1:Q[0]+_*B[0],y1:Q[1]+_*B[1],x2:H[0]-_*Y[0],y2:H[1]-_*Y[1],x:H[0],y:H[1]})}return L}var I0=Math.PI/180;function wn(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 c=0;c<Math.min(t.length,e.length);c++){r();let a=wn(t[c],e[c],n,r);if(a)return a}return t.length-e.length}throw new Error(`${n}() can only order numbers, strings or lists of them, not ${F0(t)} and ${F0(e)}`)}function B4(t,e,n){let r=D0(t,e,n);return(r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.flatMap(a=>D0(a,e,n)):r).map(a=>{if(!Array.isArray(a)||a.length<2)throw new Error(`${e}() needs points [x, y], got ${F0(a)}`);return[C1(a[0],e),C1(a[1],e)]})}function Tr(t,e,n){let r=D0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(c=>B4(c,e,n)):[B4(r,e,n)]}var A1=(t,e,n)=>({params:t.replace("...","").split(",").map(r=>r.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function kn(t,e,n){return t.order?[]:t.params.filter((r,c)=>c<e.length&&n.has(r))}function zn(t,e,n){if(t.rest){let a=[...e];return t.params.forEach((s,o)=>{n.has(s)&&(a[o]=n.get(s))}),a}if(!t.order)return t.params.map((a,s)=>n.has(a)?n.get(a):e[s]);let r=e.length+t.params.filter(a=>n.has(a)).length,c=t.order(r).filter(a=>!n.has(a));return t.params.map(a=>n.has(a)?n.get(a):e[c.indexOf(a)])}function q4(t,e,n,r){let c=gn(t,e,n.maxLength);if(c===void 0)throw new Error(`${r}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(c.length/8)),c}function C1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${F0(t)}`);return t}function D0(t,e,n){if(Array.isArray(t))return t;if(h2(t))return Ae(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${F0(t)}`)}var Ir=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function Sn(t,e,n){if(Ir.has(t))return 0;let r=0;for(let c of e)if(typeof c=="string")r+=c.length;else if(Array.isArray(c))r+=t==="len"?0:c.length;else if(h2(c)&&c.step!==0){let a=Math.floor((c.end-c.start)/c.step)+1;a>0&&(r+=Math.min(a,n+1))}return r}var Q0=t=>A1("x",e=>typeof e[0]=="number"?u2(t(e[0])):void 0);function u2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function An(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 Le=new Map;function Vr(t){let e=Le.get(t);if(e)return e;let n=An(t),r=Array.from({length:256},(c,a)=>a);for(let c=255;c>0;c--){let a=Math.floor(n()*(c+1));[r[c],r[a]]=[r[a],r[c]]}e=new Uint8Array(512);for(let c=0;c<512;c++)e[c]=r[c&255];return Le.size>64&&Le.clear(),Le.set(t,e),e}var N4=t=>t*t*t*(t*(t*6-15)+10);function J2(t,e,n,r){let c=t&15,a=c<8?e:n,s=c<4?n:c===12||c===14?e:r;return((c&1)===0?a:-a)+((c&2)===0?s:-s)}function Hr(t,e,n,r){let c=Vr(r),a=Math.floor(t),s=Math.floor(e),o=Math.floor(n);t-=a,e-=s,n-=o;let i=a&255,l=s&255,h=o&255,u=N4(t),f=N4(e),d=N4(n),p=c[i]+l,m=c[p]+h,g=c[p+1]+h,v=c[i+1]+l,b=c[v]+h,y=c[v+1]+h,x=(w,M,k)=>M+w*(k-M);return x(d,x(f,x(u,J2(c[m],t,e,n),J2(c[b],t-1,e,n)),x(u,J2(c[g],t,e-1,n),J2(c[y],t-1,e-1,n))),x(f,x(u,J2(c[m+1],t,e,n-1),J2(c[b+1],t-1,e,n-1)),x(u,J2(c[g+1],t,e-1,n-1),J2(c[y+1],t-1,e-1,n-1))))}function vn(t,e,n){let r=t.length===1&&Array.isArray(t[0])?t[0]:t;if(r.length)return e(r.map(c=>C1(c,n)))}var T5={abs:Q0(Math.abs),sign:Q0(Math.sign),floor:Q0(Math.floor),ceil:Q0(Math.ceil),round:Q0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:Q0(Math.sqrt),exp:Q0(Math.exp),ln:Q0(Math.log),log:A1("x, base",(t,e)=>e.given<2?u2(Math.log10(C1(t[0],"log"))):Math.log(C1(t[0],"log"))/Math.log(C1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:Q0(t=>Math.sin(t*I0)),cos:Q0(t=>Math.cos(t*I0)),tan:Q0(t=>Math.tan(t*I0)),asin:Q0(t=>Math.asin(t)/I0),acos:Q0(t=>Math.acos(t)/I0),atan:Q0(t=>Math.atan(t)/I0),atan2:A1("y, x",t=>u2(Math.atan2(C1(t[0],"atan2"),C1(t[1],"atan2"))/I0)),pow:A1("x, y",t=>Math.pow(C1(t[0],"pow"),C1(t[1],"pow"))),min:A1("values...",t=>vn(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:A1("values...",t=>vn(t,e=>e.reduce((n,r)=>r>n?r:n,-1/0),"max")),clamp:A1("x, low, high",t=>Math.min(Math.max(C1(t[0],"clamp"),C1(t[1],"clamp")),C1(t[2],"clamp"))),lerp:A1("a, b, t",t=>{let e=C1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((r,c)=>C1(r,"lerp")+(C1(n[c],"lerp")-C1(r,"lerp"))*e)}return C1(t[0],"lerp")+(C1(t[1],"lerp")-C1(t[0],"lerp"))*e}),norm:A1("v",(t,e)=>Math.sqrt(D0(t[0],"norm",e).reduce((n,r)=>n+C1(r,"norm")**2,0))),cross:A1("a, b",(t,e)=>{let n=D0(t[0],"cross",e).map(c=>C1(c,"cross")),r=D0(t[1],"cross",e).map(c=>C1(c,"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:A1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:G0(t[0])?t[0].fields.size:void 0),keys:A1("record",t=>G0(t[0])?[...t[0].fields.keys()]:void 0),merge:A1("a, b",t=>{if(!G0(t[0])||!G0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:A1("...",(t,e)=>{let n=t.reduce((r,c)=>r+(Array.isArray(c)?c.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:A1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...D0(t[0],"reverse",e)].reverse()),sort:A1("values, key",(t,e)=>{let n=D0(t[0],"sort",e),r=t[1],c=n.map(a=>[r===void 0?a:e.apply(r,[a]),a]);return e.step(Math.ceil(n.length*Math.log2(n.length+1))),c.sort((a,s)=>wn(a[0],s[0],"sort",()=>e.step())).map(([,a])=>a)}),fold:A1("values, initial, fn",(t,e)=>{let n=t[1];for(let r of D0(t[0],"fold",e))n=e.apply(t[2],[n,r]);return n}),scan:A1("values, initial, fn",(t,e)=>{let n=t[1];return D0(t[0],"scan",e).map(r=>n=e.apply(t[2],[n,r]))}),bounds:A1("points",(t,e)=>{let n=B4(t[0],"bounds",e);if(!n.length)return;let[r,c,a,s]=[1/0,1/0,-1/0,-1/0];for(let[o,i]of n)r=Math.min(r,o),c=Math.min(c,i),a=Math.max(a,o),s=Math.max(s,i);return[r,c,a,s]}),crossings:A1("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=C1(n?t[2]:t[1],"crossings"),c=[];for(let a of Tr(t[0],"crossings",e))for(let s=0,o=a.length-1;s<a.length;o=s++){let[i,l]=n?[a[o][1],a[o][0]]:a[o],[h,u]=n?[a[s][1],a[s][0]]:a[s];i>r!=h>r&&c.push(l+(u-l)*(r-i)/(h-i))}return c.sort((a,s)=>a-s)}),sum:A1("values",(t,e)=>D0(t[0],"sum",e).reduce((n,r)=>n+C1(r,"sum"),0)),slice:A1("value, start, end",(t,e)=>{let r=(typeof t[0]=="string"?[...t[0]]:D0(t[0],"slice",e)).slice(C1(t[1]??0,"slice"),t[2]===void 0?void 0:C1(t[2],"slice"));return typeof t[0]=="string"?r.join(""):r}),str:A1("...",(t,e)=>q4(t,"",e,"str")),chr:A1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(C1(e,"chr"))).join("")),ord:A1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:A1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:A1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:A1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:A1("values, separator",(t,e)=>q4(D0(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:A1("value, list",(t,e)=>{let r=(typeof t[1]=="string"?[...t[1]]:D0(t[1],"search",e)).findIndex(c=>_3(c,t[0],e.step));return r<0?void 0:r}),contains:A1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(q4([t[1]],"",e,"contains")):D0(t[0],"contains",e).some(n=>_3(n,t[1],e.step))),lookup:A1("x, table",(t,e)=>{let n=C1(t[0],"lookup"),r=D0(t[1],"lookup",e);if(!r.length)return;let c=r.map(a=>[C1(a[0],"lookup"),C1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=c[0][0])return c[0][1];for(let a=1;a<c.length;a++)if(n<=c[a][0]){let[s,o]=c[a-1],[i,l]=c[a];return o+(n-s)/(i-s)*(l-o)}return c[c.length-1][1]}),rands:A1("min, max, count, seed",t=>{let e=C1(t[0],"rands"),n=C1(t[1],"rands"),r=C1(t[2],"rands"),c=An(t[3]===void 0?1:C1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(r)),1e6)},()=>e+(n-e)*c())}),noise:A1("x, y, z, seed, octaves",t=>{let e,n=0,r=0;if(Array.isArray(t[0])){let h=t[0];e=C1(h[0],"noise"),n=h[1]===void 0?0:C1(h[1],"noise"),r=h[2]===void 0?0:C1(h[2],"noise")}else e=C1(t[0],"noise"),t[1]!==void 0&&(n=C1(t[1],"noise")),t[2]!==void 0&&(r=C1(t[2],"noise"));let c=Math.floor(t[3]===void 0?1:C1(t[3],"noise")),a=t[4]===void 0?1:Math.floor(C1(t[4],"noise"));if(!(a>=1&&a<=8))throw new Error("noise(): octaves must be 1 to 8");let s=0,o=1,i=0,l=1;for(let h=0;h<a;h++)s+=o*Hr(e*l+h*.3713,n*l+h*.6271,r*l+h*.1943,c+h*7919),i+=o,o/=2,l*=2;return u2(s/i)}),is_num:A1("value",t=>pn(t[0])&&!Number.isNaN(t[0])),is_string:A1("value",t=>typeof t[0]=="string"),is_bool:A1("value",t=>typeof t[0]=="boolean"),is_list:A1("value",t=>Array.isArray(t[0])),is_record:A1("value",t=>G0(t[0])),is_undef:A1("value",t=>t[0]===void 0),is_function:A1("value",t=>p2(t[0])),type_of:A1("value",t=>F0(t[0])),path_length:A1("points",(t,e)=>{let n=E5(t[0],"path_length",e),r=0;for(let c=1;c<n.length;c++)r+=Math.hypot(n[c][0]-n[c-1][0],n[c][1]-n[c-1][1]);return r}),point_at:A1("points, s",(t,e)=>yn(E5(t[0],"point_at",e),C1(t[1],"point_at")).point),heading_at:A1("points, s",(t,e)=>u2(yn(E5(t[0],"heading_at",e),C1(t[1],"heading_at")).heading)),offset_path:A1("points, d, closed",(t,e)=>{let n=E5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),r=C1(t[1],"offset_path"),c=t[2]===!0,a=c&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(a&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let s=n.length,o=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],p=Math.hypot(f-h,d-u);return[-(d-u)/p,(f-h)/p]},i=n.map(([l,h],u)=>{let f=!c&&u===0,d=!c&&u===s-1,p=o(f?0:(u-1+s)%s),m=o(d?s-2:u),[g,v]=[p[0]+m[0],p[1]+m[1]],b=Math.hypot(g,v);if(b<1e-9)[g,v]=p;else{let y=Math.min(2/(b*b),4/b);[g,v]=[g*y,v*y]}return[u2(l+r*g),u2(h+r*v)]});return a?[...i,i[0]]:i}),train_for:A1("ratio, stages, pinion, wheel",(t,e)=>{let n=C1(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:C1(t[1],"train_for");if(!(r===1||r===2||r===3))throw new Error("train_for(): stages must be 1, 2 or 3");let c=(v,b,y)=>{if(v===void 0)return b;if(!Array.isArray(v)||v.length!==2||!v.every(M=>typeof M=="number"))throw new Error(`train_for(): ${y} must be [fewest, most] teeth`);let[x,w]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(x>=6&&w>=x&&w<=400))throw new Error(`train_for(): ${y} teeth must be from 6 to 400, fewest first`);return[x,w]},[a,s]=c(t[2],[10,20],"pinion"),[o,i]=c(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=a;v<=s;v++)for(let b=Math.max(o,v);b<=i;b++)u.push([v,b]);let f,d=v=>{let b=v.reduce((w,[M,k])=>w*k/M,1),y=Math.abs(b/h-1),x=v.reduce((w,[M,k])=>w+M+k,0);(!f||y<f.err-1e-12||Math.abs(y-f.err)<=1e-12&&x<f.teeth)&&(f={stages:v.map(w=>[...w]),err:y,teeth:x})},p=(v,b)=>{e.step();for(let y=a;y<=s;y++)for(let x of[Math.floor(b*y),Math.ceil(b*y)])x>=Math.max(o,y)&&x<=i&&d([...v,[y,x]])};if(r===1)p([],h);else for(let v=0;v<u.length;v++){let b=u[v][1]/u[v][0];if(r===2)p([u[v]],h/b);else for(let y=v;y<u.length;y++)p([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 m=f.stages.map(([v,b])=>l?[b,v]:[v,b]),g=m.reduce((v,[b,y])=>v*y/b,1);return{type:"record",fields:new Map([["stages",m],["ratio",g],["error",g/n-1]])}}),path_points:A1("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:C1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let r=G3(W3(t[0]),n),c=[...r.closed.map(a=>[...a,a[0]]),...r.open];return e.step(c.reduce((a,s)=>a+s.length,0)),c.map(a=>a.map(([s,o])=>[s,o]))}),spline_points:A1("points, steps, closed",(t,e)=>{let n=E5(t[0],"spline_points",e),r=t[1]===void 0?8:Math.floor(C1(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),_4(n,r,t[2]===!0)}),rotation:A1("angles",t=>{let[e,n,r]=U4(t[0],"rotation");return Dr(xn(Fr(r),xn(Rr(n),$r(e))))}),euler:A1("matrix",t=>Mn(Or(t[0],"euler"))),orient:A1("x, z",t=>{let e=bn(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=bn([n[0]-r*e[0],n[1]-r*e[1],n[2]-r*e[2]],"orient");let c=[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 Mn([[e[0],c[0],n[0]],[e[1],c[1],n[1]],[e[2],c[2],n[2]]])})};function E5(t,e,n){return D0(t,e,n).map((c,a)=>{if(!Array.isArray(c)||typeof c[0]!="number"||typeof c[1]!="number")throw new Error(`${e}(): points[${a}] must be an [x, y] point`);return[c[0],c[1]]})}function yn(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,c=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(c+i>=e)break;c+=i}let[a,s]=[n[r],n[r+1]],o=(e-c)/Math.hypot(s[0]-a[0],s[1]-a[1]);return{point:[a[0]+(s[0]-a[0])*o,a[1]+(s[1]-a[1])*o],heading:Math.atan2(s[1]-a[1],s[0]-a[0])/I0}}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 bn(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 Or(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 $r=t=>{let[e,n]=[Math.cos(t*I0),Math.sin(t*I0)];return[[1,0,0],[0,e,-n],[0,n,e]]},Rr=t=>{let[e,n]=[Math.cos(t*I0),Math.sin(t*I0)];return[[e,0,n],[0,1,0],[-n,0,e]]},Fr=t=>{let[e,n]=[Math.cos(t*I0),Math.sin(t*I0)];return[[e,-n,0],[n,e,0],[0,0,1]]},xn=(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])),Dr=t=>t.map(e=>e.map(u2));function Mn(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])/I0;return[0,n,u2(r)]}return[u2(Math.atan2(t[2][1],t[2][2])/I0),u2(Math.asin(e)/I0),u2(Math.atan2(t[1][0],t[0][0])/I0)]}function _4(t,e,n=!1){if(t.length<3)return t.map(([s,o])=>[s,o]);let r=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=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[s]},c=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[o,i,l,h]=[r(s-1),r(s),r(s+1),r(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,p=d*f;c.push([0,1].map(m=>.5*(2*i[m]+(-o[m]+l[m])*f+(2*o[m]-5*i[m]+4*l[m]-h[m])*d+(-o[m]+3*i[m]-3*l[m]+h[m])*p)))}}return c.push(n?c[0]:[t[t.length-1][0],t[t.length-1][1]]),c}function v3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var I5=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function qr(t,e,n,r){if(e==="flat")return[];let c=v3(t,r),a=t/c,s=[];for(let o=0;o<c;o++)(e==="out"?o%2===1:o%2===0)&&s.push(I5(o*a,-1,(o+1)*a,n));return s}function Ce(t,e,n,r,c){let a=[([i,l])=>[i,l],([i,l])=>[t-l,i],([i,l])=>[t-i,e-l],([i,l])=>[l,e-i]],s=[t,e,t,e],o=[];return n.forEach((i,l)=>{for(let h of qr(s[l],i,r,c))o.push(h.map(a[l]))}),g0([I5(0,0,t,e)],o)}function Ln(t,e,n,r){let c=v3(t,r),a=t/c,s=[];for(let o=0;o<c;o++)(e==="out"?o%2===0:o%2===1)&&s.push(I5(o*a,-n/2,(o+1)*a,n/2));return s}function Cn(t,e,n,r,c){let a=I5(-t/2,-1,t/2,e),s=I5(-n/2,c,n/2,c+r);return[a,s]}function Pn(t,e,n,r,c){let a=[],s=c+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-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?r:0),p=Math.min(f+c,e-(l%2===0?r:0));p-d>=r/2&&a.push([[h,d],[h,p]])}}return a}var r2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var l1=class extends Error{constructor(n,r){super(r?`${n} (${r2(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,c){let a=this.trace.find(s=>s.name===r&&s.line===c.line&&s.col===c.col&&s.file===c.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:r,line:c.line,col:c.col,...c.file&&{file:c.file},count:1})}},Nr=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function V5(t,e){let n=[],r=[],c=0,a=1,s=0,o=()=>({line:a,col:c-s+1,offset:c,...e&&{file:e}}),i=l=>{for(let h=0;h<l;h++)t[c]===`
|
|
7
|
+
`&&(a++,s=c+1),c++};for(;c<t.length;){let l=t[c];if(l===" "||l===" "||l==="\r"||l===`
|
|
8
|
+
`){i(1);continue}if(l==="/"&&t[c+1]==="/"){let f=t.indexOf(`
|
|
9
|
+
`,c),d=f<0?t.length:f,p=/^[ \t]*$/.test(t.slice(t.lastIndexOf(`
|
|
10
|
+
`,c-1)+1,c));r.push({text:t.slice(c+2,d).trim(),line:a,block:!1,own:p,start:c,end:d}),c=d;continue}if(l==="/"&&t[c+1]==="*"){let f=o(),d=t.indexOf("*/",c+2);if(d<0)throw new l1("Unclosed block comment",f);r.push({text:t.slice(c+2,d).trim(),line:f.line,block:!0,own:!0,start:c,end:d+2}),i(d+2-c);continue}let h=o();if(/[0-9]/.test(l)||l==="."&&/[0-9]/.test(t[c+1]??"")){let f=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(t.slice(c));n.push({type:"num",value:f[0],pos:h,end:c+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(c));n.push({type:"id",value:f[0],pos:h,end:c+f[0].length}),i(f[0].length);continue}if(l==='"'){let f="";for(i(1);c<t.length&&t[c]!=='"';){if(t[c]==="\\"){let d=t[c+1];if(d==="n")f+=`
|
|
11
|
+
`;else if(d==="t")f+=" ";else if(d==="u"){let p=t.slice(c+2,c+6);if(!/^[0-9a-fA-F]{4}$/.test(p))throw new l1("Bad \\u escape",o());f+=String.fromCharCode(parseInt(p,16)),i(4)}else f+=d;i(2);continue}if(t[c]===`
|
|
12
|
+
`)throw new l1("Unclosed string",h);f+=t[c],i(1)}if(c>=t.length)throw new l1("Unclosed string",h);i(1),n.push({type:"str",value:f,pos:h,end:c});continue}if(l==="<"&&/^<[A-Za-z0-9_./\\: -]+>/.test(t.slice(c))){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([A-Za-z0-9_./\\: -]+)>/.exec(t.slice(c));n.push({type:"str",value:d[1],pos:h,end:c+d[0].length}),i(d[0].length);continue}}let u=Nr.find(f=>t.startsWith(f,c));if(!u)throw new l1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:c+u.length}),i(u.length)}return n.push({type:"eof",value:"",pos:o(),end:c}),{tokens:n,comments:r}}var K2={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",doc:"a sheet or strip of paper"},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"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb; give it shape = "ball"'},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"}},y3={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var j4=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function c2(t,e){let{tokens:n,comments:r}=V5(t,e),c=new G4(n),a=[];for(;!c.at("eof");)a.push(...c.statement());return{program:{body:a},comments:r}}var H5=class H5{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 c=this.peek(r);return c.type===e&&(n===void 0||c.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 l1(`${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"||j4.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 s=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),s.push(...this.statement());return this.next(),[{kind:"block",body:s,pos:e.pos}]}if(this.isK("module")){this.next();let s=this.ident(),o=this.params();return[{kind:"module",name:s.value,params:o,body:this.body(),pos:e.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),o=this.params();this.expectP("=");let i=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:o,body:i,pos:e.pos,namePos:s.pos}]}if(this.isK("use")||this.isK("include")){this.next();let s=this.peek();return s.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:s.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 s=this.expr();this.expectP(")");let o=this.body(),i=[];return this.isK("else")&&(this.next(),i=this.body()),[{kind:"if",cond:s,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 s=this.ident().value;this.next();let o=this.peek().pos.offset,i=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:s,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"||j4.has(r.value))&&this.fail("Expected a statement"),this.next();let c=this.args(),a=this.body();return[{kind:"call",name:r.value,args:c,children:a,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(),c=this.expr();return{kind:"lambda",params:r,body:c,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let r=this.assigns(),c=this.expr();return{kind:"let",assigns:r,body:c,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 c={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:c,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 c=this.expr();return{kind:"ternary",cond:n,then:r,else:c,pos:e.pos}}return n}binary(e){if(e>=H5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&H5.LEVELS[e].includes(this.peek().value);){let r=this.next(),c=this.binary(e+1);n={kind:"binary",op:r.value,left:n,right:c,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}):(j4.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(c=>c.name===r.value))throw new l1(`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 c=null,a=this.expr();return this.isP(":")&&(this.next(),c=a,a=this.expr()),this.expectP("]"),{kind:"range",start:n,step:c,end:a,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(),c=null;return this.isK("else")&&(this.next(),c=this.listItem()),{kind:"if",cond:n,then:r,else:c}}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()}}};H5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var G4=H5;var O=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),E1=(t,e,n)=>({...O(t,e,n),named:!0}),W4="max(3 * $thickness, 6)",Pe=[O("value")],Ur=[O("x")],e2=(t,e)=>({name:t,kind:"function",params:Ur,section:"Numbers and vectors",doc:e}),b3=(t,e)=>({name:t,kind:"function",params:Pe,section:"Types",doc:`Whether the value is ${e}`}),X4=(t,e)=>({name:t,kind:"function",params:[O("text","The text to measure",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),E1("halign","left, center or right",'"left"'),E1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Measure at the size that fits this width, or [width, cap height]")],section:"Text measurements",doc:e}),En=[{name:"rect",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the rectangle on the origin instead of its corner","false"),E1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the square on the origin instead of its corner","false"),E1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[O("r","Radius","1"),E1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[O("r","[rx, ry], or one radius for both","1"),E1("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:[O("n","Number of corners","6"),O("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[O("n","Number of points","5"),O("r","Radius of the points","10"),O("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[O("points","A list of [x, y] points"),O("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:[O("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),E1("fill",'"evenodd" or "nonzero"','"evenodd"'),E1("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:[O("text","The text",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),E1("halign","left, center or right",'"left"'),E1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Shrink the size so the text is no wider than this, or fits [width, cap height]"),E1("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),E1("bridge","Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[O("from","Start point","[0, 0]"),O("to","End point","[10, 0]"),O("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:[O("points","A list of [x, y] points"),O("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[O("r","Radius","10"),O("start","Start angle in degrees","0"),O("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[O("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[O("a","Angle in degrees, anticlockwise","0"),E1("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:[O("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[O("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:[O("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:[O("r","Grow (positive) or shrink areas with rounded corners"),E1("delta","Grow or shrink areas with sharp corners","0"),E1("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:[O("spacing","Distance between copies, a number or [x, y]","10"),O("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:[O("points","The [x, y] points the curve goes through"),O("width","Make an area this wide along the curve, instead of a line"),E1("steps","Points between each two given ones","8"),E1("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:[O("angle","Direction of the lines, in degrees from +x","45"),O("pitch","Distance between the lines","5"),O("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:[O("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),O("spacing","Distance between neighbouring lines","2"),O("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),E1("min_length","Lines shorter than this are left out","spacing * 2"),E1("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:[O("field","The height at a point: function(p) giving a number, or undef for none"),O("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),E1("interval","Instead of levels: every multiple of this height"),E1("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:[O("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:[O("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:[O("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:[O("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:[O("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:[O("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:[O("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:[O("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:[O("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:[O("name","Layer name"),O("mode",'"cut", "line", "fill" or "guide"'),O("color",'Colour in the output, as "#00aa00"'),E1("order","Where it goes among the custom layers in the files, lowest first","0"),E1("bleed","How far past the part's edge it may print","0"),E1("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:[O("name","Part name",'"part"'),O("qty","Number of copies to cut","1"),E1("at","Where the part goes in the assembled view, [x, y, z]"),E1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),E1("stack","Layers glued in a stack at each placement, one thickness apart","1"),E1("mirror","Cut the part mirrored left to right, its text still reading","false"),E1("material","The material it is cut from, as material(name = ...) sets it"),E1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),E1("on","The name of a bent part this one is glued to, to move with it"),E1("slots","Names of parts whose tabs pass through this one: their slots are cut"),E1("clearance","Added to the slots, in total across each","0.1"),E1("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),E1("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),E1("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),E1("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"'),E1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),E1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[O("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),O("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:[O("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:[O("text","What to do in this step",'""'),O("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:[O("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),O("from","One end, [x, y, z]; a ball sits midway between from and to"),O("to","The other end, [x, y, z]; a ball may leave it out"),O("size","Diameter, or [width, height] for a flat section","6"),E1("up","The direction a [width, height] section's height points"),E1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),E1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),E1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[O("thickness","Sets $thickness"),O("kerf","Sets $kerf"),O("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:[O("size","[width, height]"),O("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),O("finger","Finger width",W4)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[O("length","Length of the edge that plugs in"),O("edge",'"out" or "in", the kind of edge that plugs in','"out"'),O("finger","Finger width",W4)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[O("d","Screw diameter","3"),O("length","Screw length into the panel","12"),O("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),O("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:[O("size","[width, height]"),O("spacing","Distance between the rows of cuts","1.5"),O("bridge","Uncut length between cuts","3"),O("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:[O("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:[O("condition","Stops the program when false"),O("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},e2("abs","Absolute value"),e2("sign","Sign as -1, 0 or 1"),e2("floor","Round down"),e2("ceil","Round up"),e2("round","Round to the nearest integer, halves away from zero"),e2("sqrt","Square root"),e2("exp","e raised to x"),e2("ln","Natural logarithm"),{name:"log",kind:"function",params:[O("x"),O("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"},e2("sin","Sine of an angle in degrees"),e2("cos","Cosine of an angle in degrees"),e2("tan","Tangent of an angle in degrees"),e2("asin","Inverse sine, in degrees"),e2("acos","Inverse cosine, in degrees"),e2("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[O("y"),O("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[O("x"),O("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[O("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:[O("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:[O("x"),O("low"),O("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[O("a"),O("b"),O("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[O("ratio","Turns in for one turn out; under 1 speeds up"),O("stages","Pairs of gears, 1 to 3","2"),O("pinion","Fewest and most teeth of the small gears","[10, 20]"),O("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:[O("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[O("a"),O("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[O("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:[O("points","A list of [x, y] points"),O("d","How far to move it: to the left going along it, or the right when less than 0"),O("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:[O("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:[O("points","A closed outline of [x, y] points, or a list of outlines"),O("x","The vertical line x = this"),O("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:[O("points","A list of [x, y] points"),O("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:[O("points","A list of [x, y] points"),O("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:[O("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),O("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:[O("points","The [x, y] points the curve goes through"),O("steps","Points between each two given ones","8"),O("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:[O("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:[O("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:[O("x","Where the part's own x axis points"),O("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:Pe,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:[O("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:[O("a","A record"),O("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:Pe,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[O("values","A list of numbers, strings or lists of them"),O("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:[O("values","A list"),O("initial","The value to start from"),O("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:[O("values","A list"),O("initial","The value to start from"),O("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:[O("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[O("value","A list or string"),O("start","First index","0"),O("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:[O("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[O("text"),O("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[O("values"),O("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[O("value"),O("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[O("value","A list or string"),O("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[O("x"),O("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},b3("is_num","a number other than NaN"),b3("is_string","a string"),b3("is_bool","true or false"),b3("is_list","a list"),b3("is_undef","undef"),b3("is_function","a function"),b3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:Pe,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[O("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),O("y",void 0,"0"),O("z","A third axis: step it to get a related but different pattern","0"),E1("seed","A different seed gives a different pattern","1"),E1("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:[O("min"),O("max"),O("count"),O("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},X4("text_width","The advance width of the text, including spacing"),X4("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),X4("text_size","The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"),{name:"finger_count",kind:"function",params:[O("length","Edge length"),O("finger","Finger width",W4)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],Br=new Map(En.map(t=>[t.name,t])),O5=t=>Br.get(t);function Z4(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 $5={"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.
|
|
@@ -279,6 +279,70 @@ module vents(size, slot = 3, pitch = 6) {
|
|
|
279
279
|
translate([0, ends]) circle(d = slot, $fn = 24);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
+
`,"kerf/fit":`// kerf/fit: drawings scaled to a size and placed by a point of their box.
|
|
283
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
284
|
+
//
|
|
285
|
+
// For any drawing whose size you don't know beforehand: an imported SVG
|
|
286
|
+
// path, a silhouette, a symbol, a line of text. Each measures its children
|
|
287
|
+
// and moves or scales them, keeping their layers, so cut, score and
|
|
288
|
+
// engrave stay together. They are for drawings, not for parts: scaling a
|
|
289
|
+
// part would scale its joints and leave its thickness.
|
|
290
|
+
|
|
291
|
+
// The fractions of a box an anchor names, [0, 0] the bottom left and
|
|
292
|
+
// [1, 1] the top right: "center", "left", "right", "top", "bottom",
|
|
293
|
+
// "top-left", "top-right", "bottom-left", "bottom-right", or [fx, fy]
|
|
294
|
+
function anchor_point(anchor) =
|
|
295
|
+
is_list(anchor) ? anchor
|
|
296
|
+
: let (
|
|
297
|
+
a = lower(anchor),
|
|
298
|
+
fx = contains(a, "left") ? 0 : contains(a, "right") ? 1 : 0.5,
|
|
299
|
+
fy = contains(a, "bottom") ? 0 : contains(a, "top") ? 1 : 0.5
|
|
300
|
+
)
|
|
301
|
+
assert(
|
|
302
|
+
len([for (w = split(a, "-")) if (w != "center" && w != "left" && w != "right" && w != "top" && w != "bottom") w]) == 0,
|
|
303
|
+
str("Unknown anchor \\"", anchor, "\\": use center, left, right, top, bottom or a corner such as top-left")
|
|
304
|
+
)
|
|
305
|
+
[fx, fy];
|
|
306
|
+
|
|
307
|
+
// The children moved so the point of their box that \`anchor\` names is at
|
|
308
|
+
// the origin: align("bottom-left") puts their box's corner there, and
|
|
309
|
+
// align() centres them.
|
|
310
|
+
module align(anchor = "center") {
|
|
311
|
+
f = anchor_point(anchor);
|
|
312
|
+
measure() {
|
|
313
|
+
children();
|
|
314
|
+
if (!is_undef($bounds))
|
|
315
|
+
translate([-($bounds[0] + f[0] * ($bounds[2] - $bounds[0])), -($bounds[1] + f[1] * ($bounds[3] - $bounds[1]))])
|
|
316
|
+
children();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// The children scaled to \`size\` = [w, h] (or one number for a square):
|
|
321
|
+
// mode = "contain" keeps their proportions and fits them inside, "stretch"
|
|
322
|
+
// fills the size exactly. A drawing with no width or no height (a line)
|
|
323
|
+
// is scaled by the other side. They are then placed by \`anchor\` as
|
|
324
|
+
// align() does, the box's bottom left at the origin by default.
|
|
325
|
+
module fit(size, mode = "contain", anchor = "bottom-left") {
|
|
326
|
+
s = is_list(size) ? size : [size, size];
|
|
327
|
+
assert(s[0] > 0 && s[1] > 0, "fit(): size must be more than 0");
|
|
328
|
+
assert(mode == "contain" || mode == "stretch", "fit(): mode is \\"contain\\" or \\"stretch\\"");
|
|
329
|
+
f = anchor_point(anchor);
|
|
330
|
+
measure() {
|
|
331
|
+
children();
|
|
332
|
+
if (!is_undef($bounds)) {
|
|
333
|
+
w = $bounds[2] - $bounds[0];
|
|
334
|
+
h = $bounds[3] - $bounds[1];
|
|
335
|
+
kx = w > 0 ? s[0] / w : undef;
|
|
336
|
+
ky = h > 0 ? s[1] / h : undef;
|
|
337
|
+
k = mode == "stretch"
|
|
338
|
+
? [is_undef(kx) ? 1 : kx, is_undef(ky) ? 1 : ky]
|
|
339
|
+
: let (one = is_undef(kx) ? ky : is_undef(ky) ? kx : min(kx, ky)) [one, one];
|
|
340
|
+
if (!is_undef(k[0]))
|
|
341
|
+
translate([-f[0] * w * k[0], -f[1] * h * k[1]])
|
|
342
|
+
scale(k) translate([-$bounds[0], -$bounds[1]]) children();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
282
346
|
`,"kerf/gears":`// kerf/gears: gears, racks, lantern gears and cams for moving models.
|
|
283
347
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
284
348
|
//
|
|
@@ -1482,6 +1546,330 @@ module ring_stack(diameters, hole, name = "ring", count = undef, feet = true, cl
|
|
|
1482
1546
|
translate([-(t + clearance) / 2, -t - 1]) rect([t + clearance, h / 2 + t + 1]);
|
|
1483
1547
|
}
|
|
1484
1548
|
}
|
|
1549
|
+
`,"kerf/shapes":`// kerf/shapes: basic shapes by name, sized to a box.
|
|
1550
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1551
|
+
//
|
|
1552
|
+
// Hearts, teardrops, clouds, shields, banners, arrows and the other shapes
|
|
1553
|
+
// that signs, tags, ornaments and boxes are made of. Each takes its size as
|
|
1554
|
+
// [w, h] (or one number for both) and is centred on the origin, as circle()
|
|
1555
|
+
// and ellipse() are; arrows and chevrons point along x, the others stand
|
|
1556
|
+
// upright. A shape with one outline also has a _points() function giving
|
|
1557
|
+
// that outline, counter-clockwise, for offset_path(), flex_strip() and
|
|
1558
|
+
// anything else that works on points. Curves follow $fn when it is set,
|
|
1559
|
+
// and otherwise take about a point per millimetre.
|
|
1560
|
+
|
|
1561
|
+
use <kerf/fit>
|
|
1562
|
+
|
|
1563
|
+
// [w, h] from a number or a pair, checked
|
|
1564
|
+
function shape_size(size, what) =
|
|
1565
|
+
let (s = is_list(size) ? size : [size, size])
|
|
1566
|
+
assert(
|
|
1567
|
+
len(s) == 2 && is_num(s[0]) && is_num(s[1]) && s[0] > 0 && s[1] > 0,
|
|
1568
|
+
str(what, "(): size must be more than 0, as a number or [w, h]")
|
|
1569
|
+
)
|
|
1570
|
+
s;
|
|
1571
|
+
|
|
1572
|
+
// How many points a curve about \`length\` mm long is drawn with
|
|
1573
|
+
function shape_steps(length) = $fn > 0 ? max(3, $fn) : clamp(ceil(length), 32, 200);
|
|
1574
|
+
|
|
1575
|
+
// The points scaled to fill the box [w, h], centred on the origin
|
|
1576
|
+
function shape_fill(points, s) =
|
|
1577
|
+
let (b = bounds(points), c = [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2], kx = s[0] / (b[2] - b[0]), ky = s[1] / (b[3] - b[1]))
|
|
1578
|
+
[for (p = points) [(p[0] - c[0]) * kx, (p[1] - c[1]) * ky]];
|
|
1579
|
+
|
|
1580
|
+
// The points moved so their box is centred on the origin
|
|
1581
|
+
function shape_centre(points) =
|
|
1582
|
+
let (b = bounds(points), c = [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2])
|
|
1583
|
+
[for (p = points) p - c];
|
|
1584
|
+
|
|
1585
|
+
// Points along an arc round \`c\` of radius r, from angle a0 to a1, the first
|
|
1586
|
+
// and last included
|
|
1587
|
+
function shape_arc(c, r, a0, a1, n) = [for (i = [0:n]) let (a = a0 + (a1 - a0) * i / n) c + r * [cos(a), sin(a)]];
|
|
1588
|
+
|
|
1589
|
+
// A heart: two round lobes meeting in a dip, and a point at the bottom
|
|
1590
|
+
module heart(size = 20) polygon(heart_points(size));
|
|
1591
|
+
|
|
1592
|
+
// The outline of heart(), as points
|
|
1593
|
+
function heart_points(size = 20) =
|
|
1594
|
+
let (s = shape_size(size, "heart"), n = shape_steps(1.7 * (s[0] + s[1])))
|
|
1595
|
+
shape_fill([for (i = [0:n - 1]) let (a = -360 * i / n) [16 * pow(sin(a), 3), 13 * cos(a) - 5 * cos(2 * a) - 2 * cos(3 * a) - cos(4 * a)]], s);
|
|
1596
|
+
|
|
1597
|
+
// A drop: round at the bottom, coming to a point at the top. It must be
|
|
1598
|
+
// taller than it is wide.
|
|
1599
|
+
module teardrop(size = [14, 20]) polygon(teardrop_points(size));
|
|
1600
|
+
|
|
1601
|
+
// The outline of teardrop(), as points
|
|
1602
|
+
function teardrop_points(size = [14, 20]) =
|
|
1603
|
+
let (
|
|
1604
|
+
s = shape_size(size, "teardrop"),
|
|
1605
|
+
r = s[0] / 2,
|
|
1606
|
+
d = s[1] - r
|
|
1607
|
+
)
|
|
1608
|
+
assert(s[1] > s[0], "teardrop(): make it taller than it is wide")
|
|
1609
|
+
let (
|
|
1610
|
+
t = acos(r / d),
|
|
1611
|
+
n = shape_steps(PI * s[0])
|
|
1612
|
+
)
|
|
1613
|
+
[for (p = concat([[0, s[1]]], shape_arc([0, r], r, 90 + t, 450 - t, n))) p - [0, s[1] / 2]];
|
|
1614
|
+
|
|
1615
|
+
// An egg standing on its broad end; \`taper\` is how much narrower the top
|
|
1616
|
+
// is, 0 for an ellipse
|
|
1617
|
+
module egg(size = [16, 20], taper = 0.2) polygon(egg_points(size, taper));
|
|
1618
|
+
|
|
1619
|
+
// The outline of egg(), as points
|
|
1620
|
+
function egg_points(size = [16, 20], taper = 0.2) =
|
|
1621
|
+
let (s = shape_size(size, "egg"), n = shape_steps(1.6 * (s[0] + s[1])))
|
|
1622
|
+
assert(taper >= 0 && taper < 1, "egg(): taper is from 0 up to 1")
|
|
1623
|
+
shape_fill([for (i = [0:n - 1]) let (a = 360 * i / n) [cos(a) * (1 - taper * sin(a)), sin(a)]], s);
|
|
1624
|
+
|
|
1625
|
+
// A lens (a leaf, a petal, an eye): two arcs meeting in a point at each
|
|
1626
|
+
// end of its longer side, the top and bottom of a tall one, the left and
|
|
1627
|
+
// right of a wide one
|
|
1628
|
+
module lens(size = [10, 20]) polygon(lens_points(size));
|
|
1629
|
+
|
|
1630
|
+
// The outline of lens(), as points
|
|
1631
|
+
function lens_points(size = [10, 20]) =
|
|
1632
|
+
let (s = shape_size(size, "lens"))
|
|
1633
|
+
// A wide lens is a tall one turned a quarter turn, so its arcs stay less
|
|
1634
|
+
// than half circles and its ends pointed
|
|
1635
|
+
s[0] > s[1] ? [for (p = shape_tall_lens([s[1], s[0]])) [p[1], -p[0]]] : shape_tall_lens(s);
|
|
1636
|
+
|
|
1637
|
+
// A lens with its points at the top and the bottom, no wider than tall
|
|
1638
|
+
function shape_tall_lens(s) =
|
|
1639
|
+
let (
|
|
1640
|
+
g = s[0] / 2,
|
|
1641
|
+
R = g / 2 + s[1] * s[1] / (8 * g),
|
|
1642
|
+
t = asin(min(1, s[1] / 2 / R)),
|
|
1643
|
+
// even, so a point falls on the widest place
|
|
1644
|
+
n = 2 * max(2, ceil(shape_steps(PI * (s[0] + s[1]) / 2) / 4))
|
|
1645
|
+
)
|
|
1646
|
+
concat(shape_arc([g - R, 0], R, -t, t, n), [for (p = shape_arc([R - g, 0], R, 180 - t, 180 + t, n)) if (abs(p[1]) < s[1] / 2 - 1e-9) p]);
|
|
1647
|
+
|
|
1648
|
+
// A crescent moon \`d\` across, open to the right, \`thickness\` at its widest
|
|
1649
|
+
module crescent(d = 20, thickness) polygon(crescent_points(d, thickness));
|
|
1650
|
+
|
|
1651
|
+
// The outline of crescent(), as points
|
|
1652
|
+
function crescent_points(d = 20, thickness) =
|
|
1653
|
+
let (
|
|
1654
|
+
R = d / 2,
|
|
1655
|
+
t = is_undef(thickness) ? d / 4 : thickness
|
|
1656
|
+
)
|
|
1657
|
+
assert(is_num(d) && d > 0, "crescent(): d must be more than 0")
|
|
1658
|
+
assert(t > 0 && t < d, "crescent(): thickness must be more than 0 and less than d")
|
|
1659
|
+
let (
|
|
1660
|
+
Y = sqrt(R * R - t * t / 4),
|
|
1661
|
+
a = atan2(Y, t / 2),
|
|
1662
|
+
b = atan2(Y, -t / 2),
|
|
1663
|
+
n = shape_steps(PI * d)
|
|
1664
|
+
)
|
|
1665
|
+
shape_centre(concat(
|
|
1666
|
+
shape_arc([0, 0], R, a, 360 - a, n),
|
|
1667
|
+
[for (i = [1:n - 1]) let (q = 360 - b - (360 - 2 * b) * i / n) [t, 0] + R * [cos(q), sin(q)]]
|
|
1668
|
+
));
|
|
1669
|
+
|
|
1670
|
+
// A rectangle with round ends (a stadium, a pill)
|
|
1671
|
+
module capsule(size = [30, 10]) polygon(capsule_points(size));
|
|
1672
|
+
|
|
1673
|
+
// The outline of capsule(), as points
|
|
1674
|
+
function capsule_points(size = [30, 10]) =
|
|
1675
|
+
let (
|
|
1676
|
+
s = shape_size(size, "capsule"),
|
|
1677
|
+
r = min(s) / 2,
|
|
1678
|
+
c = s[0] >= s[1] ? [s[0] / 2 - r, 0] : [0, s[1] / 2 - r],
|
|
1679
|
+
a = s[0] >= s[1] ? -90 : 0,
|
|
1680
|
+
n = ceil(shape_steps(PI * r * 2) / 2)
|
|
1681
|
+
)
|
|
1682
|
+
concat(shape_arc(c, r, a, a + 180, n), shape_arc(-c, r, a + 180, a + 360, n));
|
|
1683
|
+
|
|
1684
|
+
// A diamond (a rhombus) touching the middle of each side of its box
|
|
1685
|
+
module diamond(size = [14, 20]) polygon(diamond_points(size));
|
|
1686
|
+
|
|
1687
|
+
// The outline of diamond(), as points
|
|
1688
|
+
function diamond_points(size = [14, 20]) =
|
|
1689
|
+
let (s = shape_size(size, "diamond") / 2) [[0, -s[1]], [s[0], 0], [0, s[1]], [-s[0], 0]];
|
|
1690
|
+
|
|
1691
|
+
// A regular polygon with \`n\` corners \`r\` from its centre, as
|
|
1692
|
+
// regular_polygon(n, r), each rounded with radius \`round\`
|
|
1693
|
+
module rounded_polygon(n = 6, r = 10, round = 2) polygon(rounded_polygon_points(n, r, round));
|
|
1694
|
+
|
|
1695
|
+
// The outline of rounded_polygon(), as points
|
|
1696
|
+
function rounded_polygon_points(n = 6, r = 10, round = 2) =
|
|
1697
|
+
assert(is_num(n) && n >= 3, "rounded_polygon(): n must be 3 or more")
|
|
1698
|
+
assert(r > 0, "rounded_polygon(): r must be more than 0")
|
|
1699
|
+
assert(round >= 0 && round < r * cos(180 / n), "rounded_polygon(): round must be less than the distance to a side")
|
|
1700
|
+
let (
|
|
1701
|
+
k = floor(n),
|
|
1702
|
+
c = r - round / cos(180 / k),
|
|
1703
|
+
m = round > 0 ? max(2, ceil(shape_steps(2 * PI * round) / k)) : 0
|
|
1704
|
+
)
|
|
1705
|
+
[for (i = [0:k - 1]) let (a = 360 * i / k)
|
|
1706
|
+
each (round > 0 ? shape_arc(c * [cos(a), sin(a)], round, a - 180 / k, a + 180 / k, m) : [r * [cos(a), sin(a)]])];
|
|
1707
|
+
|
|
1708
|
+
// A shield: a flat top, straight sides, curving in to a point at the
|
|
1709
|
+
// bottom. \`point\` is how much of the height the curved part takes.
|
|
1710
|
+
module shield(size = [16, 20], point = 0.55) polygon(shield_points(size, point));
|
|
1711
|
+
|
|
1712
|
+
// The outline of shield(), as points
|
|
1713
|
+
function shield_points(size = [16, 20], point = 0.55) =
|
|
1714
|
+
let (s = shape_size(size, "shield"), w = s[0] / 2, top = s[1] / 2)
|
|
1715
|
+
assert(point > 0 && point <= 1, "shield(): point is more than 0, up to 1")
|
|
1716
|
+
let (
|
|
1717
|
+
yk = top - s[1] * (1 - point),
|
|
1718
|
+
n = shape_steps(s[1] * point),
|
|
1719
|
+
side = function(u) [w * (1 - u * u), yk - (yk + top) * u]
|
|
1720
|
+
)
|
|
1721
|
+
concat(
|
|
1722
|
+
[[-w, top]],
|
|
1723
|
+
[for (i = [0:n]) let (p = side(i / n)) [-p[0], p[1]]],
|
|
1724
|
+
[for (i = [n - 1:-1:0]) side(i / n)],
|
|
1725
|
+
[[w, top]]
|
|
1726
|
+
);
|
|
1727
|
+
|
|
1728
|
+
// An arrow pointing along x: \`size\` is its length and the head's width,
|
|
1729
|
+
// \`shaft\` the shaft's width and \`head\` the head's length
|
|
1730
|
+
module arrow(size = [30, 14], shaft, head) polygon(arrow_points(size, shaft, head));
|
|
1731
|
+
|
|
1732
|
+
// The outline of arrow(), as points
|
|
1733
|
+
function arrow_points(size = [30, 14], shaft, head) =
|
|
1734
|
+
let (
|
|
1735
|
+
s = shape_size(size, "arrow"),
|
|
1736
|
+
L = s[0] / 2,
|
|
1737
|
+
W = s[1] / 2,
|
|
1738
|
+
sw = is_undef(shaft) ? s[1] / 3 : shaft,
|
|
1739
|
+
hl = is_undef(head) ? min(s[0] / 2, s[1]) : head
|
|
1740
|
+
)
|
|
1741
|
+
assert(sw > 0 && sw <= s[1], "arrow(): shaft must be more than 0 and no wider than the head")
|
|
1742
|
+
assert(hl > 0 && hl <= s[0], "arrow(): head must be more than 0 and no longer than the arrow")
|
|
1743
|
+
[[-L, -sw / 2], [L - hl, -sw / 2], [L - hl, -W], [L, 0], [L - hl, W], [L - hl, sw / 2], [-L, sw / 2]];
|
|
1744
|
+
|
|
1745
|
+
// A chevron (>) pointing along x, \`thickness\` across each arm along x
|
|
1746
|
+
module chevron(size = [12, 20], thickness) polygon(chevron_points(size, thickness));
|
|
1747
|
+
|
|
1748
|
+
// The outline of chevron(), as points
|
|
1749
|
+
function chevron_points(size = [12, 20], thickness) =
|
|
1750
|
+
let (
|
|
1751
|
+
s = shape_size(size, "chevron"),
|
|
1752
|
+
w = s[0] / 2,
|
|
1753
|
+
h = s[1] / 2,
|
|
1754
|
+
t = is_undef(thickness) ? s[0] / 2 : thickness
|
|
1755
|
+
)
|
|
1756
|
+
assert(t > 0 && t < s[0], "chevron(): thickness must be more than 0 and less than the width")
|
|
1757
|
+
[[-w, -h], [-w + t, -h], [w, 0], [-w + t, h], [-w, h], [w - t, 0]];
|
|
1758
|
+
|
|
1759
|
+
// A banner with a V cut \`notch\` deep into each end
|
|
1760
|
+
module banner(size = [60, 16], notch) polygon(banner_points(size, notch));
|
|
1761
|
+
|
|
1762
|
+
// The outline of banner(), as points
|
|
1763
|
+
function banner_points(size = [60, 16], notch) =
|
|
1764
|
+
let (
|
|
1765
|
+
s = shape_size(size, "banner"),
|
|
1766
|
+
w = s[0] / 2,
|
|
1767
|
+
h = s[1] / 2,
|
|
1768
|
+
v = is_undef(notch) ? s[1] / 3 : notch
|
|
1769
|
+
)
|
|
1770
|
+
assert(v >= 0 && v < s[0] / 2, "banner(): notch must be less than half the width")
|
|
1771
|
+
[[-w, -h], [w, -h], [w - v, 0], [w, h], [-w, h], [-w + v, 0]];
|
|
1772
|
+
|
|
1773
|
+
// A house: walls and a pitched roof \`roof\` tall
|
|
1774
|
+
module house(size = [20, 24], roof) polygon(house_points(size, roof));
|
|
1775
|
+
|
|
1776
|
+
// The outline of house(), as points
|
|
1777
|
+
function house_points(size = [20, 24], roof) =
|
|
1778
|
+
let (
|
|
1779
|
+
s = shape_size(size, "house"),
|
|
1780
|
+
w = s[0] / 2,
|
|
1781
|
+
h = s[1] / 2,
|
|
1782
|
+
rf = is_undef(roof) ? s[0] / 2 : roof
|
|
1783
|
+
)
|
|
1784
|
+
assert(rf > 0 && rf < s[1], "house(): roof must be more than 0 and less than the height")
|
|
1785
|
+
[[-w, -h], [w, -h], [w, h - rf], [0, h], [-w, h - rf]];
|
|
1786
|
+
|
|
1787
|
+
// A gift or luggage tag: its left end's corners cut off by \`cut\`, with a
|
|
1788
|
+
// hole \`hole\` across near that end (0 for none)
|
|
1789
|
+
module tag(size = [50, 25], cut, hole) {
|
|
1790
|
+
s = shape_size(size, "tag");
|
|
1791
|
+
hd = is_undef(hole) ? s[1] / 4 : hole;
|
|
1792
|
+
difference() {
|
|
1793
|
+
polygon(tag_points(size, cut));
|
|
1794
|
+
if (hd > 0) translate([-s[0] / 2 + s[1] / 3, 0]) circle(d = hd);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
// The outline of tag(), without its hole, as points
|
|
1799
|
+
function tag_points(size = [50, 25], cut) =
|
|
1800
|
+
let (
|
|
1801
|
+
s = shape_size(size, "tag"),
|
|
1802
|
+
w = s[0] / 2,
|
|
1803
|
+
h = s[1] / 2,
|
|
1804
|
+
c = is_undef(cut) ? s[1] / 4 : cut
|
|
1805
|
+
)
|
|
1806
|
+
assert(c >= 0 && c < min(s[0], s[1] / 2), "tag(): cut must be less than half the height")
|
|
1807
|
+
[[-w + c, -h], [w, -h], [w, h], [-w + c, h], [-w, h - c], [-w, -h + c]];
|
|
1808
|
+
|
|
1809
|
+
// A ring \`d\` across, its band \`width\` wide
|
|
1810
|
+
module ring(d = 20, width = 3) {
|
|
1811
|
+
assert(is_num(d) && d > 0, "ring(): d must be more than 0");
|
|
1812
|
+
assert(width > 0 && width < d / 2, "ring(): width must be more than 0 and less than half of d");
|
|
1813
|
+
difference() {
|
|
1814
|
+
circle(d = d);
|
|
1815
|
+
circle(d = d - 2 * width);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
// A circle \`d\` across with \`n\` round scallops round its edge
|
|
1820
|
+
module scalloped(d = 30, n = 16) {
|
|
1821
|
+
assert(is_num(d) && d > 0, "scalloped(): d must be more than 0");
|
|
1822
|
+
assert(n >= 3, "scalloped(): n must be 3 or more");
|
|
1823
|
+
k = sin(180 / n);
|
|
1824
|
+
rb = d / 2 / (1 + k);
|
|
1825
|
+
union() {
|
|
1826
|
+
circle(r = rb);
|
|
1827
|
+
for (i = [0:n - 1]) rotate(360 * i / n) translate([rb, 0]) circle(r = rb * k);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// A flower \`d\` across with \`petals\` petals round a round middle \`center\`
|
|
1832
|
+
// of d across
|
|
1833
|
+
module flower(d = 30, petals = 6, center = 0.35) {
|
|
1834
|
+
assert(is_num(d) && d > 0, "flower(): d must be more than 0");
|
|
1835
|
+
assert(petals >= 3, "flower(): petals must be 3 or more");
|
|
1836
|
+
assert(center > 0 && center < 1, "flower(): center is a part of d, more than 0 and less than 1");
|
|
1837
|
+
pl = d / 2 * (1 - center / 3);
|
|
1838
|
+
rc = d / 2 - pl / 2;
|
|
1839
|
+
pw = min(pl, 2.2 * rc * sin(180 / petals));
|
|
1840
|
+
union() {
|
|
1841
|
+
circle(d = d * center);
|
|
1842
|
+
for (i = [0:petals - 1]) rotate(90 + 360 * i / petals) translate([rc, 0]) ellipse(d = [pl, pw]);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// A cloud: a flat bottom with \`puffs\` round puffs along the top
|
|
1847
|
+
module cloud(size = [40, 24], puffs = 3) {
|
|
1848
|
+
s = shape_size(size, "cloud");
|
|
1849
|
+
assert(puffs >= 1, "cloud(): puffs must be 1 or more");
|
|
1850
|
+
fit(s, mode = "stretch", anchor = "center") union() {
|
|
1851
|
+
translate([0.08, 0]) rect([0.84, 0.3], r = 0.15);
|
|
1852
|
+
for (i = [0:puffs - 1]) let (f = (i + 0.5) / puffs, rise = sin(180 * f), r = (0.3 + 0.2 * rise) / max(1, puffs / 2.2))
|
|
1853
|
+
translate([0.12 + 0.76 * f, 0.18 + 0.32 * rise]) circle(r = r, $fn = shape_steps(150));
|
|
1854
|
+
translate([0.12, 0.17]) circle(r = 0.12, $fn = shape_steps(80));
|
|
1855
|
+
translate([0.88, 0.17]) circle(r = 0.12, $fn = shape_steps(80));
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// A speech bubble: a rounded box with a tail \`tail\` long at its bottom
|
|
1860
|
+
// left (mirror() it for the right). The tail is part of \`size\`.
|
|
1861
|
+
module speech_bubble(size = [40, 30], r, tail) {
|
|
1862
|
+
s = shape_size(size, "speech_bubble");
|
|
1863
|
+
th = is_undef(tail) ? s[1] / 4 : tail;
|
|
1864
|
+
assert(th > 0 && th < s[1] / 2, "speech_bubble(): tail must be more than 0 and less than half the height");
|
|
1865
|
+
rr = is_undef(r) ? min(s[0], s[1] - th) / 5 : r;
|
|
1866
|
+
bh = s[1] - th;
|
|
1867
|
+
yb = -s[1] / 2 + th;
|
|
1868
|
+
union() {
|
|
1869
|
+
translate([-s[0] / 2, yb]) rect([s[0], bh], r = rr);
|
|
1870
|
+
polygon([[-s[0] * 0.3, yb + min(bh / 2, rr + 1)], [-s[0] * 0.3 + s[0] / 5, yb + min(bh / 2, rr + 1)], [-s[0] * 0.38, -s[1] / 2]]);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1485
1873
|
`,"kerf/sizes":`// kerf/sizes: paper, card and photo sizes, in millimetres, for holders,
|
|
1486
1874
|
// folders, frames and boxes made to fit them.
|
|
1487
1875
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
@@ -1560,6 +1948,61 @@ function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = ali
|
|
|
1560
1948
|
len(hit) ? hit[0] : name;
|
|
1561
1949
|
// The names in a table, for messages
|
|
1562
1950
|
function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
1951
|
+
`,"kerf/stand":`// kerf/stand: a sign, a photo or a calendar standing in a base.
|
|
1952
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1953
|
+
//
|
|
1954
|
+
// The panel has tabs along its bottom edge that go through slots in a
|
|
1955
|
+
// base, upright or leaning back. stand() makes both parts and puts them
|
|
1956
|
+
// together; stand_tabs() and stand_slots() are the two halves of the joint
|
|
1957
|
+
// for a base of your own, and match whenever they are given the same
|
|
1958
|
+
// width, count, tab and lean. The base is $thickness thick, as the panel.
|
|
1959
|
+
|
|
1960
|
+
use <kerf/tabs>
|
|
1961
|
+
|
|
1962
|
+
// The panel \`width\` wide drawn by the children, its bottom edge on y = 0
|
|
1963
|
+
// from x = 0, standing in a base \`depth\` deep and \`margin\` wider than it
|
|
1964
|
+
// on each side, leaning back by \`lean\` degrees. Its back face meets the
|
|
1965
|
+
// base \`back\` from the front, half way by default. The parts are \`name\`
|
|
1966
|
+
// and "\`name\` stand".
|
|
1967
|
+
module stand(width, depth = 40, count = undef, tab = undef, lean = 0, margin = 10, back = undef, r = 3, clearance = 0.1, name = "Sign") {
|
|
1968
|
+
t = $thickness;
|
|
1969
|
+
assert(width > 0, "stand(): width must be more than 0");
|
|
1970
|
+
assert(lean >= 0 && lean < 45, "stand(): lean is from 0 up to 45 degrees");
|
|
1971
|
+
ys = is_undef(back) ? depth / 2 : back;
|
|
1972
|
+
assert(ys > 0 && ys < depth, "stand(): back must be inside the base's depth");
|
|
1973
|
+
part(name, at = [0, ys, t], rotate = [90 - lean, 0, 0]) {
|
|
1974
|
+
children();
|
|
1975
|
+
stand_tabs(width, count, tab, lean);
|
|
1976
|
+
}
|
|
1977
|
+
part(str(name, " stand"), at = [0, 0, 0]) difference() {
|
|
1978
|
+
translate([-margin, 0]) rect([width + 2 * margin, depth], r = r);
|
|
1979
|
+
translate([0, ys]) stand_slots(width, count, tab, lean, clearance);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
// Tabs for the bottom edge of a panel \`width\` wide, x from 0 to \`width\`,
|
|
1984
|
+
// hanging below y = 0 far enough to go through a base $thickness thick
|
|
1985
|
+
// when the panel leans back by \`lean\` degrees. Each is \`tab\` wide, half
|
|
1986
|
+
// the space between tabs by default; \`count\` is one for every 50 mm.
|
|
1987
|
+
module stand_tabs(width, count = undef, tab = undef, lean = 0) {
|
|
1988
|
+
at = tab_positions(width, count);
|
|
1989
|
+
w = is_undef(tab) ? width / (2 * len(at)) : tab;
|
|
1990
|
+
d = $thickness / cos(lean);
|
|
1991
|
+
for (x = at) translate([x - w / 2, -d]) rect([w, d + 0.01]);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
// The slots in a base for stand_tabs() with the same width, count, tab
|
|
1995
|
+
// and lean, x from 0 to \`width\`, for a panel whose back face meets the top
|
|
1996
|
+
// of the base on y = 0, standing towards -y and leaning back towards +y.
|
|
1997
|
+
// \`clearance\` is added to each slot's width and depth.
|
|
1998
|
+
module stand_slots(width, count = undef, tab = undef, lean = 0, clearance = 0.1) {
|
|
1999
|
+
at = tab_positions(width, count);
|
|
2000
|
+
w = is_undef(tab) ? width / (2 * len(at)) : tab;
|
|
2001
|
+
t = $thickness;
|
|
2002
|
+
// from the back face at the top to the tab's front corner at its end
|
|
2003
|
+
across = t * cos(lean) + t * tan(lean);
|
|
2004
|
+
for (x = at) translate([x, -across / 2]) rect([w + clearance, across + clearance], center = true);
|
|
2005
|
+
}
|
|
1563
2006
|
`,"kerf/symbols":`// kerf/symbols: 867 pictograms by name, for engraving and cutting.
|
|
1564
2007
|
// The library code: Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or
|
|
1565
2008
|
// MyLaserTools commercial licence. The symbols come from open icon sets,
|
|
@@ -1572,14 +2015,29 @@ function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
|
1572
2015
|
// symbol_names() lists them: "heart", "star", "paw", "tree" and the like.
|
|
1573
2016
|
// box = "grid" sizes and places it by its icon set's grid (24 x 24 for
|
|
1574
2017
|
// Material Design Icons) instead, so icons of one set line up as drawn.
|
|
1575
|
-
|
|
2018
|
+
// solid = true cuts it as one silhouette, gaps narrower than 2 * close
|
|
2019
|
+
// closed and its holes filled, with the drawing's detail engraved on it:
|
|
2020
|
+
// a pictogram drawn as separate strokes (a moon and stars, yarn) cut out
|
|
2021
|
+
// in one piece. bridge = w also joins pieces too far apart to close, by
|
|
2022
|
+
// strips w wide.
|
|
2023
|
+
module symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close = undef, bridge = undef) {
|
|
1576
2024
|
assert(box == "drawn" || box == "grid", "box is \\"drawn\\" or \\"grid\\"");
|
|
1577
2025
|
s = symbol_entry(name);
|
|
1578
2026
|
vb = box == "grid" ? s[5] : s[2];
|
|
1579
2027
|
k = size / max(vb[2], vb[3]);
|
|
1580
|
-
translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
2028
|
+
module drawn() translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
1581
2029
|
scale([k, -k]) translate([-vb[0] - vb[2] / 2, -vb[1] - vb[3] / 2])
|
|
1582
2030
|
path(s[4], fill = fill, close = true);
|
|
2031
|
+
r = is_undef(close) ? size / 30 : close;
|
|
2032
|
+
module silhouette() if (is_undef(bridge)) fill_holes() close(r) drawn();
|
|
2033
|
+
else join_islands(bridge) fill_holes() close(r) drawn();
|
|
2034
|
+
if (solid) {
|
|
2035
|
+
silhouette();
|
|
2036
|
+
engrave() difference() {
|
|
2037
|
+
silhouette();
|
|
2038
|
+
drawn();
|
|
2039
|
+
}
|
|
2040
|
+
} else drawn();
|
|
1583
2041
|
}
|
|
1584
2042
|
|
|
1585
2043
|
// [width, height] of what a symbol draws when it is \`size\` across its
|
|
@@ -2560,27 +3018,29 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
|
|
|
2560
3018
|
if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
|
|
2561
3019
|
if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
|
|
2562
3020
|
}
|
|
2563
|
-
`};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},c=Object.defineProperty,r=c(n,n,n)&&c}catch{}return r})(),e=function(n){if(this==null)throw TypeError();var c=String(this),r=c.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=r)){var s=c.charCodeAt(a),i;return s>=55296&&s<=56319&&r>a+1&&(i=c.charCodeAt(a+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var De=0,ut=-3;function M5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function y9(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new M5,this.dtree=new M5}var ft=new M5,dt=new M5,qe=new Uint8Array(30),Ne=new Uint16Array(30),pt=new Uint8Array(30),mt=new Uint16Array(30),b9=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),L7=new M5,y2=new Uint8Array(320);function gt(t,e,n,c){var r,a;for(r=0;r<n;++r)t[r]=0;for(r=0;r<30-n;++r)t[r+n]=r/n|0;for(a=c,r=0;r<30;++r)e[r]=a,a+=1<<t[r]}function x9(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 A7=new Uint16Array(16);function Me(t,e,n,c){var r,a;for(r=0;r<16;++r)t.table[r]=0;for(r=0;r<c;++r)t.table[e[n+r]]++;for(t.table[0]=0,a=0,r=0;r<16;++r)A7[r]=a,a+=t.table[r];for(r=0;r<c;++r)e[n+r]&&(t.trans[A7[e[n+r]]++]=r)}function M9(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function b2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var c=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,c+n}function Te(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,c=0,r=0,a=t.tag;do c=2*c+(a&1),a>>>=1,++r,n+=e.table[r],c-=e.table[r];while(c>=0);return t.tag=a,t.bitcount-=r,e.trans[n+c]}function w9(t,e,n){var c,r,a,s,i,o;for(c=b2(t,5,257),r=b2(t,5,1),a=b2(t,4,4),s=0;s<19;++s)y2[s]=0;for(s=0;s<a;++s){var l=b2(t,3,0);y2[b9[s]]=l}for(Me(L7,y2,0,19),i=0;i<c+r;){var h=Te(t,L7);switch(h){case 16:var u=y2[i-1];for(o=b2(t,2,3);o;--o)y2[i++]=u;break;case 17:for(o=b2(t,3,3);o;--o)y2[i++]=0;break;case 18:for(o=b2(t,7,11);o;--o)y2[i++]=0;break;default:y2[i++]=h;break}}Me(e,y2,0,c),Me(n,y2,c,r)}function C7(t,e,n){for(;;){var c=Te(t,e);if(c===256)return De;if(c<256)t.dest[t.destLen++]=c;else{var r,a,s,i;for(c-=257,r=b2(t,qe[c],Ne[c]),a=Te(t,n),s=t.destLen-b2(t,pt[a],mt[a]),i=s;i<s+r;++i)t.dest[t.destLen++]=t.dest[i]}}}function z9(t){for(var e,n,c;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 ut;for(t.sourceIndex+=4,c=e;c;--c)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,De}function k9(t,e){var n=new y9(t,e),c,r,a;do{switch(c=M9(n),r=b2(n,2,0),r){case 0:a=z9(n);break;case 1:a=C7(n,ft,dt);break;case 2:w9(n,n.ltree,n.dtree),a=C7(n,n.ltree,n.dtree);break;default:a=ut}if(a!==De)throw new Error("Data error")}while(!c);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}x9(ft,dt);gt(qe,Ne,4,3);gt(pt,mt,2,1);qe[28]=0;Ne[28]=258;var S9=k9;function V3(t,e,n,c,r){return Math.pow(1-r,3)*t+3*Math.pow(1-r,2)*r*e+3*(1-r)*Math.pow(r,2)*n+Math.pow(r,3)*c}function X2(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}X2.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};X2.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))};X2.prototype.addX=function(t){this.addPoint(t,null)};X2.prototype.addY=function(t){this.addPoint(null,t)};X2.prototype.addBezier=function(t,e,n,c,r,a,s,i){var o=[t,e],l=[n,c],h=[r,a],u=[s,i];this.addPoint(t,e),this.addPoint(s,i);for(var f=0;f<=1;f++){var d=6*o[f]-12*l[f]+6*h[f],p=-3*o[f]+9*l[f]-9*h[f]+3*u[f],m=3*l[f]-3*o[f];if(p===0){if(d===0)continue;var g=-m/d;0<g&&g<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],g)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*m*p;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*p);0<y&&y<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],y)));var b=(-d-Math.sqrt(v))/(2*p);0<b&&b<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],b)))}}};X2.prototype.addQuad=function(t,e,n,c,r,a){var s=t+.6666666666666666*(n-t),i=e+2/3*(c-e),o=s+1/3*(r-t),l=i+1/3*(a-e);this.addBezier(t,e,s,i,o,l,r,a)};function M0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}M0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};M0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};M0.prototype.curveTo=M0.prototype.bezierCurveTo=function(t,e,n,c,r,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:c,x:r,y:a})};M0.prototype.quadTo=M0.prototype.quadraticCurveTo=function(t,e,n,c){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:c})};M0.prototype.close=M0.prototype.closePath=function(){this.commands.push({type:"Z"})};M0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof X2){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)};M0.prototype.getBoundingBox=function(){for(var t=new X2,e=0,n=0,c=0,r=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=c=s.x,n=r=s.y;break;case"L":t.addPoint(s.x,s.y),c=s.x,r=s.y;break;case"Q":t.addQuad(c,r,s.x1,s.y1,s.x,s.y),c=s.x,r=s.y;break;case"C":t.addBezier(c,r,s.x1,s.y1,s.x2,s.y2,s.x,s.y),c=s.x,r=s.y;break;case"Z":c=e,r=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};M0.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())};M0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var c="",r=0;r<this.commands.length;r+=1){var a=this.commands[r];a.type==="M"?c+="M"+n(a.x,a.y):a.type==="L"?c+="L"+n(a.x,a.y):a.type==="C"?c+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?c+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(c+="Z")}return c};M0.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};M0.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 vt(t){throw new Error(t)}function P7(t,e){t||vt(e)}var k1={fail:vt,argument:P7,assert:P7},T7=32768,E7=2147483648,O3={},K={},C1={};function l2(t){return function(){return t}}K.BYTE=function(t){return k1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};C1.BYTE=l2(1);K.CHAR=function(t){return[t.charCodeAt(0)]};C1.CHAR=l2(1);K.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};C1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};K.USHORT=function(t){return[t>>8&255,t&255]};C1.USHORT=l2(2);K.SHORT=function(t){return t>=T7&&(t=-(2*T7-t)),[t>>8&255,t&255]};C1.SHORT=l2(2);K.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};C1.UINT24=l2(3);K.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.ULONG=l2(4);K.LONG=function(t){return t>=E7&&(t=-(2*E7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONG=l2(4);K.FIXED=K.ULONG;C1.FIXED=C1.ULONG;K.FWORD=K.SHORT;C1.FWORD=C1.SHORT;K.UFWORD=K.USHORT;C1.UFWORD=C1.USHORT;K.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONGDATETIME=l2(8);K.TAG=function(t){return k1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};C1.TAG=l2(4);K.Card8=K.BYTE;C1.Card8=C1.BYTE;K.Card16=K.USHORT;C1.Card16=C1.USHORT;K.OffSize=K.BYTE;C1.OffSize=C1.BYTE;K.SID=K.USHORT;C1.SID=C1.USHORT;K.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?K.NUMBER16(t):K.NUMBER32(t)};C1.NUMBER=function(t){return K.NUMBER(t).length};K.NUMBER16=function(t){return[28,t>>8&255,t&255]};C1.NUMBER16=l2(3);K.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.NUMBER32=l2(5);K.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var c=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*c)/c).toString()}for(var r="",a=0,s=e.length;a<s;a+=1){var i=e[a];i==="e"?r+=e[++a]==="-"?"c":"b":i==="."?r+="a":i==="-"?r+="e":r+=i}r+=r.length&1?"f":"ff";for(var o=[30],l=0,h=r.length;l<h;l+=2)o.push(parseInt(r.substr(l,2),16));return o};C1.REAL=function(t){return K.REAL(t).length};K.NAME=K.CHARARRAY;C1.NAME=C1.CHARARRAY;K.STRING=K.CHARARRAY;C1.STRING=C1.CHARARRAY;O3.UTF8=function(t,e,n){for(var c=[],r=n,a=0;a<r;a++,e+=1)c[a]=t.getUint8(e);return String.fromCharCode.apply(null,c)};O3.UTF16=function(t,e,n){for(var c=[],r=n/2,a=0;a<r;a++,e+=2)c[a]=t.getUint16(e);return String.fromCharCode.apply(null,c)};K.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var c=t.charCodeAt(n);e[e.length]=c>>8&255,e[e.length]=c&255}return e};C1.UTF16=function(t){return t.length*2};var Ee={"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"};O3.MACSTRING=function(t,e,n,c){var r=Ee[c];if(r!==void 0){for(var a="",s=0;s<n;s++){var i=t.getUint8(e+s);i<=127?a+=String.fromCharCode(i):a+=r[i&127]}return a}};var a4=typeof WeakMap=="function"&&new WeakMap,s4,L9=function(t){if(!s4){s4={};for(var e in Ee)s4[e]=new String(e)}var n=s4[t];if(n!==void 0){if(a4){var c=a4.get(n);if(c!==void 0)return c}var r=Ee[t];if(r!==void 0){for(var a={},s=0;s<r.length;s++)a[r.charCodeAt(s)]=s+128;return a4&&a4.set(n,a),a}}};K.MACSTRING=function(t,e){var n=L9(e);if(n!==void 0){for(var c=[],r=0;r<t.length;r++){var a=t.charCodeAt(r);if(a>=128&&(a=n[a],a===void 0))return;c[r]=a}return c}};C1.MACSTRING=function(t,e){var n=K.MACSTRING(t,e);return n!==void 0?n.length:0};function Ie(t){return t>=-128&&t<=127}function A9(t,e,n){for(var c=0,r=t.length;e<r&&c<64&&t[e]===0;)++e,++c;return n.push(128|c-1),e}function C9(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(!Ie(s)||s===0&&a+1<r&&t[a+1]===0)break;++a,++c}n.push(c-1);for(var i=e;i<a;++i)n.push(t[i]+256&255);return a}function P9(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(s===0||Ie(s)&&a+1<r&&Ie(t[a+1]))break;++a,++c}n.push(64|c-1);for(var i=e;i<a;++i){var o=t[i];n.push(o+65536>>8&255,o+256&255)}return a}K.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var c=t[e];c===0?e=A9(t,e,n):c>=-128&&c<=127?e=C9(t,e,n):e=P9(t,e,n)}return n};K.INDEX=function(t){for(var e=1,n=[e],c=[],r=0;r<t.length;r+=1){var a=K.OBJECT(t[r]);Array.prototype.push.apply(c,a),e+=a.length,n.push(e)}if(c.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,K.BYTE,K.USHORT,K.UINT24,K.ULONG][i],l=0;l<n.length;l+=1){var h=o(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(K.Card16(t.length),K.OffSize(i),s,c)};C1.INDEX=function(t){return K.INDEX(t).length};K.DICT=function(t){for(var e=[],n=Object.keys(t),c=n.length,r=0;r<c;r+=1){var a=parseInt(n[r],0),s=t[a];e=e.concat(K.OPERAND(s.value,s.type)),e=e.concat(K.OPERATOR(a))}return e};C1.DICT=function(t){return K.DICT(t).length};K.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};K.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)k1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(K.OPERAND(t[c],e[c]));else if(e==="SID")n=n.concat(K.NUMBER(t));else if(e==="offset")n=n.concat(K.NUMBER32(t));else if(e==="number")n=n.concat(K.NUMBER(t));else if(e==="real")n=n.concat(K.REAL(t));else throw new Error("Unknown operand type "+e);return n};K.OP=K.BYTE;C1.OP=C1.BYTE;var i4=typeof WeakMap=="function"&&new WeakMap;K.CHARSTRING=function(t){if(i4){var e=i4.get(t);if(e!==void 0)return e}for(var n=[],c=t.length,r=0;r<c;r+=1){var a=t[r];n=n.concat(K[a.type](a.value))}return i4&&i4.set(t,n),n};C1.CHARSTRING=function(t){return K.CHARSTRING(t).length};K.OBJECT=function(t){var e=K[t.type];return k1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};C1.OBJECT=function(t){var e=C1[t.type];return k1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};K.TABLE=function(t){for(var e=[],n=t.fields.length,c=[],r=[],a=0;a<n;a+=1){var s=t.fields[a],i=K[s.type];k1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=t[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(r.push(e.length),e=e.concat([0,0]),c.push(l)):e=e.concat(l)}for(var h=0;h<c.length;h+=1){var u=r[h],f=e.length;k1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(c[h])}return e};C1.TABLE=function(t){for(var e=0,n=t.fields.length,c=0;c<n;c+=1){var r=t.fields[c],a=C1[r.type];k1.argument(a!==void 0,"No sizeOf function for field type "+r.type+" ("+r.name+")");var s=t[r.name];s===void 0&&(s=r.value),e+=a(s),r.type==="TABLE"&&(e+=2)}return e};K.RECORD=K.TABLE;C1.RECORD=C1.TABLE;K.LITERAL=function(t){return t};C1.LITERAL=function(t){return t.length};function P0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var c=0;c<e.length;c+=1){var r=e[c];this[r.name]=r.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var i=a[s],o=n[i];this[i]!==void 0&&(this[i]=o)}}P0.prototype.encode=function(){return K.TABLE(this)};P0.prototype.sizeOf=function(){return C1.TABLE(this)};function w5(t,e,n){n===void 0&&(n=e.length);var c=new Array(e.length+1);c[0]={name:t+"Count",type:"USHORT",value:n};for(var r=0;r<e.length;r++)c[r+1]={name:t+r,type:"USHORT",value:e[r]};return c}function Ve(t,e,n){var c=e.length,r=new Array(c+1);r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return r}function z5(t,e,n){var c=e.length,r=[];r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r=r.concat(n(e[a],a));return r}function f4(t){t.format===1?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(w5("glyph",t.glyphs))):t.format===2?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(z5("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}]}))):k1.assert(!1,"Coverage format must be 1 or 2.")}f4.prototype=Object.create(P0.prototype);f4.prototype.constructor=f4;function d4(t){P0.call(this,"scriptListTable",z5("scriptRecord",t,function(e,n){var c=e.script,r=c.defaultLangSys;return k1.assert(!!r,"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 P0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new P0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:r.reqFeatureIndex}].concat(w5("featureIndex",r.featureIndexes)))}].concat(z5("langSys",c.langSysRecords,function(a,s){var i=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new P0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(w5("featureIndex",i.featureIndexes)))}]})))}]}))}d4.prototype=Object.create(P0.prototype);d4.prototype.constructor=d4;function p4(t){P0.call(this,"featureListTable",z5("featureRecord",t,function(e,n){var c=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new P0("featureTable",[{name:"featureParams",type:"USHORT",value:c.featureParams}].concat(w5("lookupListIndex",c.lookupListIndexes)))}]}))}p4.prototype=Object.create(P0.prototype);p4.prototype.constructor=p4;function m4(t,e){P0.call(this,"lookupListTable",Ve("lookup",t,function(n){var c=e[n.lookupType];return k1.assert(!!c,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new P0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(Ve("subtable",n.subtables,c)))}))}m4.prototype=Object.create(P0.prototype);m4.prototype.constructor=m4;var n1={Table:P0,Record:P0,Coverage:f4,ScriptList:d4,FeatureList:p4,LookupList:m4,ushortList:w5,tableList:Ve,recordList:z5};function I7(t,e){return t.getUint8(e)}function g4(t,e){return t.getUint16(e,!1)}function T9(t,e){return t.getInt16(e,!1)}function Ue(t,e){return t.getUint32(e,!1)}function yt(t,e){var n=t.getInt16(e,!1),c=t.getUint16(e+2,!1);return n+c/65535}function E9(t,e){for(var n="",c=e;c<e+4;c+=1)n+=String.fromCharCode(t.getInt8(c));return n}function I9(t,e,n){for(var c=0,r=0;r<n;r+=1)c<<=8,c+=t.getUint8(e+r);return c}function V9(t,e,n){for(var c=[],r=e;r<n;r+=1)c.push(t.getUint8(r));return c}function H9(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var O9={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function O(t,e){this.data=t,this.offset=e,this.relativeOffset=0}O.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};O.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};O.prototype.parseCard8=O.prototype.parseByte;O.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};O.prototype.parseCard16=O.prototype.parseUShort;O.prototype.parseSID=O.prototype.parseUShort;O.prototype.parseOffset16=O.prototype.parseUShort;O.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};O.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};O.prototype.parseULong=function(){var t=Ue(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};O.prototype.parseOffset32=O.prototype.parseULong;O.prototype.parseFixed=function(){var t=yt(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};O.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,c="";this.relativeOffset+=t;for(var r=0;r<t;r++)c+=String.fromCharCode(e.getUint8(n+r));return c};O.prototype.parseTag=function(){return this.parseString(4)};O.prototype.parseLongDateTime=function(){var t=Ue(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};O.prototype.parseVersion=function(t){var e=g4(this.data,this.offset+this.relativeOffset),n=g4(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};O.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=O9[t]*e};O.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint32(c),c+=4;return this.relativeOffset+=t*4,e};O.prototype.parseOffset16List=O.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint16(c),c+=2;return this.relativeOffset+=t*2,e};O.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getInt16(c),c+=2;return this.relativeOffset+=t*2,e};O.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint8(c++);return this.relativeOffset+=t,e};O.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};O.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};O.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};O.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};O.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},c=0;c<e.length;c++){var r=e[c],a=t[r];n[r]=a.call(this)}return n};O.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}};O.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),c=0;c<e;c++)n[c]=this.parseValueRecord(t);return n};O.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new O(this.data,this.offset+e).parseStruct(t)};O.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new O(this.data,this.offset+e).parseStruct(t)};O.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,c=this.relativeOffset,r=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){r[a]=void 0;continue}if(this.relativeOffset=s,t){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=t.call(this);r[a]=o}else r[a]=this.parseUShortList()}return this.relativeOffset=c,r};O.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 c=new Array(n),r=0;r<n;r++)c[r]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:c}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};O.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:O.uShort,end:O.uShort,classId:O.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};O.list=function(t,e){return function(){return this.parseList(t,e)}};O.list32=function(t,e){return function(){return this.parseList32(t,e)}};O.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};O.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};O.pointer=function(t){return function(){return this.parsePointer(t)}};O.pointer32=function(t){return function(){return this.parsePointer32(t)}};O.tag=O.prototype.parseTag;O.byte=O.prototype.parseByte;O.uShort=O.offset16=O.prototype.parseUShort;O.uShortList=O.prototype.parseUShortList;O.uLong=O.offset32=O.prototype.parseULong;O.uLongList=O.prototype.parseULongList;O.struct=O.prototype.parseStruct;O.coverage=O.prototype.parseCoverage;O.classDef=O.prototype.parseClassDef;var V7={reserved:O.uShort,reqFeatureIndex:O.uShort,featureIndexes:O.uShortList};O.prototype.parseScriptList=function(){return this.parsePointer(O.recordList({tag:O.tag,script:O.pointer({defaultLangSys:O.pointer(V7),langSysRecords:O.recordList({tag:O.tag,langSys:O.pointer(V7)})})}))||[]};O.prototype.parseFeatureList=function(){return this.parsePointer(O.recordList({tag:O.tag,feature:O.pointer({featureParams:O.offset16,lookupListIndexes:O.uShortList})}))||[]};O.prototype.parseLookupList=function(t){return this.parsePointer(O.list(O.pointer(function(){var e=this.parseUShort();k1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),c=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(O.pointer(t[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};O.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();k1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:O.offset32,featureTableSubstitutionOffset:O.offset32});return n})||[]};var f1={getByte:I7,getCard8:I7,getUShort:g4,getCard16:g4,getShort:T9,getULong:Ue,getFixed:yt,getTag:E9,getOffset:I9,getBytes:V9,bytesToString:H9,Parser:O};function R9(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var c=0;c<n;c+=1)for(var r=e.parseULong(),a=e.parseULong(),s=e.parseULong(),i=r;i<=a;i+=1)t.glyphIndexMap[i]=s,s++}function F9(t,e,n,c,r){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new f1.Parser(n,c+r+14),i=new f1.Parser(n,c+r+16+a*2),o=new f1.Parser(n,c+r+16+a*4),l=new f1.Parser(n,c+r+16+a*6),h=c+r+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),p=i.parseUShort(),m=o.parseShort(),g=l.parseUShort(),v=p;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-p)*2,f=f1.getUShort(n,h),f!==0&&(f=f+m&65535)):f=v+m&65535,t.glyphIndexMap[v]=f}function $9(t,e){var n={};n.version=f1.getUShort(t,e),k1.argument(n.version===0,"cmap table version should be 0."),n.numTables=f1.getUShort(t,e+2);for(var c=-1,r=n.numTables-1;r>=0;r-=1){var a=f1.getUShort(t,e+4+r*8),s=f1.getUShort(t,e+4+r*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){c=f1.getULong(t,e+4+r*8+4);break}}if(c===-1)throw new Error("No valid cmap sub-tables found.");var i=new f1.Parser(t,e+c);if(n.format=i.parseUShort(),n.format===12)R9(n,i);else if(n.format===4)F9(n,i,t,e,c);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function D9(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function q9(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function N9(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var c=t.get(n);if(c.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var r=[{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||(r=r.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),r=r.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 a=new n1.Table("cmap",r);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)D9(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}q9(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],p=[],m=[];for(n=0;n<o;n+=1){var g=a.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&&(p=p.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),m=m.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),m=m.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(a.segCountX2=(o-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(p),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+p.length*2,!e){var v=16+m.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.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:m.length/3}]),a.fields=a.fields.concat(m)}return a}var bt={parse:$9,make:N9},h4=[".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"],U9=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],B9=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],s3=[".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 xt(t){this.font=t}xt.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var c=0;c<n.length;c+=1)for(var r=n.get(c),a=0;a<r.unicodes.length;a+=1)if(r.unicodes[a]===e)return c}return null};function Mt(t){this.cmap=t}Mt.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function v4(t,e){this.encoding=t,this.charset=e}v4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function Be(t){switch(t.version){case 1:this.names=s3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<s3.length?this.names[e]=s3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-s3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=s3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}Be.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};Be.prototype.glyphIndexToName=function(t){return this.names[t]};function _9(t){for(var e,n=t.tables.cmap.glyphIndexMap,c=Object.keys(n),r=0;r<c.length;r+=1){var a=c[r],s=n[a];e=t.glyphs.get(s),e.addUnicode(parseInt(a))}for(var i=0;i<t.glyphs.length;i+=1)e=t.glyphs.get(i),t.cffEncoding?t.isCIDFont?e.name="gid"+i:e.name=t.cffEncoding.charset[i]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(i))}function G9(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),c=0;c<n.length;c+=1){var r=n[c],a=e[r];t._IndexToUnicodeMap[a]===void 0?t._IndexToUnicodeMap[a]={unicodes:[parseInt(r)]}:t._IndexToUnicodeMap[a].unicodes.push(parseInt(r))}}function j9(t,e){e.lowMemory?G9(t):_9(t)}function W9(t,e,n,c,r){t.beginPath(),t.moveTo(e,n),t.lineTo(c,r),t.stroke()}var a3={line:W9};function X9(t,e){var n=e||new M0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(c){n=c}}}function e2(t){this.bindConstructorValues(t)}e2.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",X9(this,t.path))};e2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};e2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};e2.prototype.getPath=function(t,e,n,c,r){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;c||(c={});var i=c.xScale,o=c.yScale;if(c.hinting&&r&&r.hinting&&(s=this.path&&r.hinting.exec(this,n)),s)a=r.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),i=o=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new M0,u=0;u<a.length;u+=1){var f=a[u];f.type==="M"?h.moveTo(t+f.x*i,e+-f.y*o):f.type==="L"?h.lineTo(t+f.x*i,e+-f.y*o):f.type==="Q"?h.quadraticCurveTo(t+f.x1*i,e+-f.y1*o,t+f.x*i,e+-f.y*o):f.type==="C"?h.curveTo(t+f.x1*i,e+-f.y1*o,t+f.x2*i,e+-f.y2*o,t+f.x*i,e+-f.y*o):f.type==="Z"&&h.closePath()}return h};e2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var c=this.points[n];e.push(c),c.lastPointOfContour&&(t.push(e),e=[])}return k1.argument(e.length===0,"There are still points left in the current contour."),t};e2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];r.type!=="Z"&&(e.push(r.x),n.push(r.y)),(r.type==="Q"||r.type==="C")&&(e.push(r.x1),n.push(r.y1)),r.type==="C"&&(e.push(r.x2),n.push(r.y2))}var a={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(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a};e2.prototype.draw=function(t,e,n,c,r){this.getPath(e,n,c,r).draw(t)};e2.prototype.drawPoints=function(t,e,n,c){function r(u,f,d,p){t.beginPath();for(var m=0;m<u.length;m+=1)t.moveTo(f+u[m].x*p,d+u[m].y*p),t.arc(f+u[m].x*p,d+u[m].y*p,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24;for(var a=1/this.path.unitsPerEm*c,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",r(s,e,n,a),t.fillStyle="red",r(i,e,n,a)};e2.prototype.drawMetrics=function(t,e,n,c){var r;e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24,r=1/this.path.unitsPerEm*c,t.lineWidth=1,t.strokeStyle="black",a3.line(t,e,-1e4,e,1e4),a3.line(t,-1e4,n,1e4,n);var a=this.xMin||0,s=this.yMin||0,i=this.xMax||0,o=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",a3.line(t,e+a*r,-1e4,e+a*r,1e4),a3.line(t,e+i*r,-1e4,e+i*r,1e4),a3.line(t,-1e4,n+-s*r,1e4,n+-s*r),a3.line(t,-1e4,n+-o*r,1e4,n+-o*r),t.strokeStyle="green",a3.line(t,e+l*r,-1e4,e+l*r,1e4)};function o4(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(c){t[n]=c},enumerable:!0,configurable:!0})}function _e(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var c=e[n];c.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=c}this.length=e&&e.length||0}_e.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 c=0;c<n.unicodes.length;c++)e.addUnicode(n.unicodes[c]);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]};_e.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Z9(t,e){return new e2({index:e,font:t})}function Y9(t,e,n,c,r,a){return function(){var s=new e2({index:e,font:t});return s.path=function(){n(s,c,r);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},o4(s,"xMin","_xMin"),o4(s,"xMax","_xMax"),o4(s,"yMin","_yMin"),o4(s,"yMax","_yMax"),s}}function J9(t,e,n,c){return function(){var r=new e2({index:e,font:t});return r.path=function(){var a=n(t,r,c);return a.unitsPerEm=t.unitsPerEm,a},r}}var M2={GlyphSet:_e,glyphLoader:Z9,ttfGlyphLoader:Y9,cffGlyphLoader:J9};function wt(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(!wt(t[n],e[n]))return!1;return!0}else return!1}function He(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function _2(t,e,n){var c=[],r=[],a=f1.getCard16(t,e),s,i;if(a!==0){var o=f1.getByte(t,e+2);s=e+(a+1)*o+2;for(var l=e+3,h=0;h<a+1;h+=1)c.push(f1.getOffset(t,l,o)),l+=o;i=s+c[a]}else i=e+2;for(var u=0;u<c.length-1;u+=1){var f=f1.getBytes(t,s+c[u],s+c[u+1]);n&&(f=n(f)),r.push(f)}return{objects:r,startOffset:e,endOffset:i}}function K9(t,e){var n=[],c=f1.getCard16(t,e),r,a;if(c!==0){var s=f1.getByte(t,e+2);r=e+(c+1)*s+2;for(var i=e+3,o=0;o<c+1;o+=1)n.push(f1.getOffset(t,i,s)),i+=s;a=r+n[c]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function Q9(t,e,n,c,r){var a=f1.getCard16(n,c),s=0;if(a!==0){var i=f1.getByte(n,c+2);s=c+(a+1)*i+2}var o=f1.getBytes(n,s+e[t],s+e[t+1]);return r&&(o=r(o)),o}function ec(t){for(var e="",n=15,c=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var r=t.parseByte(),a=r>>4,s=r&15;if(a===n||(e+=c[a],s===n))break;e+=c[s]}return parseFloat(e)}function tc(t,e){var n,c,r,a;if(e===28)return n=t.parseByte(),c=t.parseByte(),n<<8|c;if(e===29)return n=t.parseByte(),c=t.parseByte(),r=t.parseByte(),a=t.parseByte(),n<<24|c<<16|r<<8|a;if(e===30)return ec(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 nc(t){for(var e={},n=0;n<t.length;n+=1){var c=t[n][0],r=t[n][1],a=void 0;if(r.length===1?a=r[0]:a=r,e.hasOwnProperty(c)&&!isNaN(e[c]))throw new Error("Object "+e+" already has key "+c);e[c]=a}return e}function zt(t,e,n){e=e!==void 0?e:0;var c=new f1.Parser(t,e),r=[],a=[];for(n=n!==void 0?n:t.length;c.relativeOffset<n;){var s=c.parseByte();s<=21?(s===12&&(s=1200+c.parseByte()),r.push([s,a]),a=[]):a.push(tc(c,s))}return nc(r)}function x5(t,e){return e<=390?e=h4[e]:e=t[e-391],e}function kt(t,e,n){for(var c={},r,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)r=t[s.op]!==void 0?t[s.op][o]:void 0,r===void 0&&(r=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(r=x5(n,r)),i[o]=r;c[s.name]=i}else r=t[s.op],r===void 0&&(r=s.value!==void 0?s.value:null),s.type==="SID"&&(r=x5(n,r)),c[s.name]=r}return c}function cc(t,e){var n={};return n.formatMajor=f1.getCard8(t,e),n.formatMinor=f1.getCard8(t,e+1),n.size=f1.getCard8(t,e+2),n.offsetSize=f1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var St=[{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"}],Lt=[{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 rc(t,e){var n=zt(t,0,t.byteLength);return kt(n,St,e)}function At(t,e,n,c){var r=zt(t,e,n);return kt(r,Lt,c)}function H7(t,e,n,c){for(var r=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=rc(s,c);i._subrs=[],i._subrsBias=0,i._defaultWidthX=0,i._nominalWidthX=0;var o=i.private[0],l=i.private[1];if(o!==0&&l!==0){var h=At(t,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=_2(t,u+e);i._subrs=f.objects,i._subrsBias=He(i._subrs)}i._privateDict=h}r.push(i)}return r}function ac(t,e,n,c){var r,a,s=new f1.Parser(t,e);n-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<n;l+=1)r=s.parseSID(),i.push(x5(c,r));else if(o===1)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)i.push(x5(c,r)),r+=1}else if(o===2)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)i.push(x5(c,r)),r+=1}else throw new Error("Unknown charset format "+o);return i}function sc(t,e,n){var c,r={},a=new f1.Parser(t,e),s=a.parseCard8();if(s===0)for(var i=a.parseCard8(),o=0;o<i;o+=1)c=a.parseCard8(),r[c]=o;else if(s===1){var l=a.parseCard8();c=1;for(var h=0;h<l;h+=1)for(var u=a.parseCard8(),f=a.parseCard8(),d=u;d<=u+f;d+=1)r[d]=c,c+=1}else throw new Error("Unknown encoding format "+s);return new v4(r,n)}function O7(t,e,n){var c,r,a,s,i=new M0,o=[],l=0,h=!1,u=!1,f=0,d=0,p,m,g,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];p=b._subrs,m=b._subrsBias,g=b._defaultWidthX,v=b._nominalWidthX}else p=t.tables.cff.topDict._subrs,m=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function M(z,S){u&&i.closePath(),i.moveTo(z,S),u=!0}function w(){var z;z=o.length%2!==0,z&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function k(z){for(var S,L,I,q,R,N,G,V,J,o1,Z,p1,E=0;E<z.length;){var $=z[E];switch(E+=1,$){case 1:w();break;case 3:w();break;case 4:o.length>1&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),M(f,d);break;case 5:for(;o.length>0;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 6:for(;o.length>0&&(f+=o.shift(),i.lineTo(f,d),o.length!==0);)d+=o.shift(),i.lineTo(f,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(f,d),o.length!==0);)f+=o.shift(),i.lineTo(f,d);break;case 8:for(;o.length>0;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 10:R=o.pop()+m,N=p[R],N&&k(N);break;case 11:return;case 12:switch($=z[E],E+=1,$){case 35:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s+o.shift(),J=G+o.shift(),o1=V+o.shift(),Z=J+o.shift(),p1=o1+o.shift(),f=Z+o.shift(),d=p1+o.shift(),o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 34:c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s,J=G+o.shift(),o1=s,Z=J+o.shift(),p1=d,f=Z+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 36:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s,J=G+o.shift(),o1=s,Z=J+o.shift(),p1=o1+o.shift(),f=Z+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 37:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s+o.shift(),J=G+o.shift(),o1=V+o.shift(),Z=J+o.shift(),p1=o1+o.shift(),Math.abs(Z-f)>Math.abs(p1-d)?f=Z+o.shift():d=p1+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+$),o.length=0}break;case 14:o.length>0&&!h&&(x=o.shift()+v,h=!0),u&&(i.closePath(),u=!1);break;case 18:w();break;case 19:case 20:w(),E+=l+7>>3;break;case 21:o.length>2&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),f+=o.pop(),M(f,d);break;case 22:o.length>1&&!h&&(x=o.shift()+v,h=!0),f+=o.pop(),M(f,d);break;case 23:w();break;case 24:for(;o.length>2;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 25:for(;o.length>6;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 26:for(o.length%2&&(f+=o.shift());o.length>0;)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a,d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s,i.curveTo(c,r,a,s,f,d);break;case 28:S=z[E],L=z[E+1],o.push((S<<24|L<<16)>>16),E+=2;break;case 29:R=o.pop()+t.gsubrsBias,N=t.gsubrs[R],N&&k(N);break;case 30:for(;o.length>0&&(c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;case 31:for(;o.length>0&&(c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;default:$<32?console.log("Glyph "+e.index+": unknown operator "+$):$<247?o.push($-139):$<251?(S=z[E],E+=1,o.push(($-247)*256+S+108)):$<255?(S=z[E],E+=1,o.push(-($-251)*256-S-108)):(S=z[E],L=z[E+1],I=z[E+2],q=z[E+3],E+=4,o.push((S<<24|L<<16|I<<8|q)/65536))}}}return k(n),e.advanceWidth=x,i}function ic(t,e,n,c){var r=[],a,s=new f1.Parser(t,e),i=s.parseCard8();if(i===0)for(var o=0;o<n;o++){if(a=s.parseCard8(),a>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+c+")");r.push(a)}else if(i===3){var l=s.parseCard16(),h=s.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(a=s.parseCard8(),u=s.parseCard16(),a>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+c+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)r.push(a);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 "+i);return r}function oc(t,e,n,c){n.tables.cff={};var r=cc(t,e),a=_2(t,r.endOffset,f1.bytesToString),s=_2(t,a.endOffset),i=_2(t,s.endOffset,f1.bytesToString),o=_2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=He(n.gsubrs);var l=H7(t,e,s.objects,i.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=_2(t,u),p=H7(t,e,d.objects,i.objects);h._fdArray=p,f+=e,h._fdSelect=ic(t,f,n.numGlyphs,p.length)}var m=e+h.private[1],g=At(t,m,h.private[0],i.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=m+g.subrs,y=_2(t,v);n.subrs=y.objects,n.subrsBias=He(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;c.lowMemory?(b=K9(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=_2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=ac(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new v4(U9,x):h.encoding===1?n.cffEncoding=new v4(B9,x):n.cffEncoding=sc(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new M2.GlyphSet(n),c.lowMemory)n._push=function(k){var z=Q9(k,b.offsets,t,e+h.charStrings);n.glyphs.push(k,M2.cffGlyphLoader(n,k,O7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var w=b.objects[M];n.glyphs.push(M,M2.cffGlyphLoader(n,M,O7,w))}}function Ct(t,e){var n,c=h4.indexOf(t);return c>=0&&(n=c),c=e.indexOf(t),c>=0?n=c+h4.length:(n=h4.length+e.length,e.push(t)),n}function lc(){return new n1.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 hc(t){var e=new n1.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 Pt(t,e,n){for(var c={},r=0;r<t.length;r+=1){var a=t[r],s=e[a.name];s!==void 0&&!wt(s,a.value)&&(a.type==="SID"&&(s=Ct(s,n)),c[a.op]={name:a.name,type:a.type,value:s})}return c}function R7(t,e){var n=new n1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=Pt(St,t,e),n}function F7(t){var e=new n1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function uc(t){var e=new n1.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 n1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function dc(t,e){for(var n=new n1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),c=0;c<t.length;c+=1){var r=t[c],a=Ct(r,e);n.fields.push({name:"glyph_"+c,type:"SID",value:a})}return n}function pc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var c=0,r=0,a=0;a<n.commands.length;a+=1){var s=void 0,i=void 0,o=n.commands[a];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*c+h*o.x1),y1:Math.round(l*r+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="C"){var u=Math.round(o.x1-c),f=Math.round(o.y1-r),d=Math.round(o.x2-o.x1),p=Math.round(o.y2-o.y1);s=Math.round(o.x-o.x2),i=Math.round(o.y-o.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:p}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),c=Math.round(o.x),r=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function mc(t){for(var e=new n1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var c=t.get(n),r=pc(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:r})}return e}function gc(t,e){var n=new n1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=Pt(Lt,t,e),n}function vc(t,e){for(var n=new n1.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"}]),c=1/e.unitsPerEm,r={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[c,0,0,c,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},s=[],i,o=1;o<t.length;o+=1)i=t.get(o),s.push(i.name);var l=[];n.header=lc(),n.nameIndex=hc([e.postScriptName]);var h=R7(r,l);n.topDictIndex=F7(h),n.globalSubrIndex=fc(),n.charsets=dc(s,l),n.charStringsIndex=mc(t),n.privateDict=gc(a,l),n.stringIndex=uc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return r.charset=u,r.encoding=0,r.charStrings=r.charset+n.charsets.sizeOf(),r.private[1]=r.charStrings+n.charStringsIndex.sizeOf(),h=R7(r,l),n.topDictIndex=F7(h),n}var Tt={parse:oc,make:vc};function yc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.fontRevision=Math.round(c.parseFixed()*1e3)/1e3,n.checkSumAdjustment=c.parseULong(),n.magicNumber=c.parseULong(),k1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=c.parseUShort(),n.unitsPerEm=c.parseUShort(),n.created=c.parseLongDateTime(),n.modified=c.parseLongDateTime(),n.xMin=c.parseShort(),n.yMin=c.parseShort(),n.xMax=c.parseShort(),n.yMax=c.parseShort(),n.macStyle=c.parseUShort(),n.lowestRecPPEM=c.parseUShort(),n.fontDirectionHint=c.parseShort(),n.indexToLocFormat=c.parseShort(),n.glyphDataFormat=c.parseShort(),n}function bc(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new n1.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 Et={parse:yc,make:bc};function xc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.ascender=c.parseShort(),n.descender=c.parseShort(),n.lineGap=c.parseShort(),n.advanceWidthMax=c.parseUShort(),n.minLeftSideBearing=c.parseShort(),n.minRightSideBearing=c.parseShort(),n.xMaxExtent=c.parseShort(),n.caretSlopeRise=c.parseShort(),n.caretSlopeRun=c.parseShort(),n.caretOffset=c.parseShort(),c.relativeOffset+=8,n.metricDataFormat=c.parseShort(),n.numberOfHMetrics=c.parseUShort(),n}function Mc(t){return new n1.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 It={parse:xc,make:Mc};function wc(t,e,n,c,r){for(var a,s,i=new f1.Parser(t,e),o=0;o<c;o+=1){o<n&&(a=i.parseUShort(),s=i.parseShort());var l=r.get(o);l.advanceWidth=a,l.leftSideBearing=s}}function zc(t,e,n,c,r){t._hmtxTableData={};for(var a,s,i=new f1.Parser(e,n),o=0;o<r;o+=1)o<c&&(a=i.parseUShort(),s=i.parseShort()),t._hmtxTableData[o]={advanceWidth:a,leftSideBearing:s}}function kc(t,e,n,c,r,a,s){s.lowMemory?zc(t,e,n,c,r):wc(e,n,c,r,a)}function Sc(t){for(var e=new n1.Table("hmtx",[]),n=0;n<t.length;n+=1){var c=t.get(n),r=c.advanceWidth||0,a=c.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:r}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:a})}return e}var Vt={parse:kc,make:Sc};function Lc(t){for(var e=new n1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",c=12+t.length*4,r=0;r<t.length;++r){var a=n.indexOf(t[r]);a<0&&(a=n.length,n+=t[r]),e.fields.push({name:"offset "+r,type:"USHORT",value:c+a}),e.fields.push({name:"length "+r,type:"USHORT",value:t[r].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Ac(t,e){var n=new f1.Parser(t,e),c=n.parseULong();k1.argument(c===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var r=n.parseULong(),a=[],s=0;s<r;s++){for(var i="",o=e+n.parseUShort(),l=n.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(t.getInt8(h));a.push(i)}return a}var Ht={make:Lc,parse:Ac};function Cc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.numGlyphs=c.parseUShort(),n.version===1&&(n.maxPoints=c.parseUShort(),n.maxContours=c.parseUShort(),n.maxCompositePoints=c.parseUShort(),n.maxCompositeContours=c.parseUShort(),n.maxZones=c.parseUShort(),n.maxTwilightPoints=c.parseUShort(),n.maxStorage=c.parseUShort(),n.maxFunctionDefs=c.parseUShort(),n.maxInstructionDefs=c.parseUShort(),n.maxStackElements=c.parseUShort(),n.maxSizeOfInstructions=c.parseUShort(),n.maxComponentElements=c.parseUShort(),n.maxComponentDepth=c.parseUShort()),n}function Pc(t){return new n1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var Ot={parse:Cc,make:Pc},Rt=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Ft={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"},Tc={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},$t={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 Ec(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return Ft[e];case 3:return $t[e]}}var Oe="utf-16",Ic={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"},Vc={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 Dt(t,e,n){switch(t){case 0:return Oe;case 1:return Vc[n]||Ic[e];case 3:if(e===1||e===10)return Oe;break}}function Hc(t,e,n){for(var c={},r=new f1.Parser(t,e),a=r.parseUShort(),s=r.parseUShort(),i=r.offset+r.parseUShort(),o=0;o<s;o++){var l=r.parseUShort(),h=r.parseUShort(),u=r.parseUShort(),f=r.parseUShort(),d=Rt[f]||f,p=r.parseUShort(),m=r.parseUShort(),g=Ec(l,u,n),v=Dt(l,h,u);if(v!==void 0&&g!==void 0){var y=void 0;if(v===Oe?y=O3.UTF16(t,i+m,p):y=O3.MACSTRING(t,i+m,p,v),y){var b=c[d];b===void 0&&(b=c[d]={}),b[g]=y}}}var x=0;return a===1&&(x=r.parseUShort()),c}function we(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function $7(t,e,n,c,r,a){return new n1.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:c},{name:"length",type:"USHORT",value:r},{name:"offset",type:"USHORT",value:a}])}function Oc(t,e){var n=t.length,c=e.length-n+1;e:for(var r=0;r<c;r++)for(;r<c;r++){for(var a=0;a<n;a++)if(e[r+a]!==t[a])continue e;return r}return-1}function D7(t,e){var n=Oc(t,e);if(n<0){n=e.length;for(var c=0,r=t.length;c<r;++c)e.push(t[c])}return n}function Rc(t,e){var n,c=[],r={},a=we(Rt);for(var s in t){var i=a[s];if(i===void 0&&(i=s),n=parseInt(i),isNaN(n))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');r[n]=t[s],c.push(n)}for(var o=we(Ft),l=we($t),h=[],u=[],f=0;f<c.length;f++){n=c[f];var d=r[n];for(var p in d){var m=d[p],g=1,v=o[p],y=Tc[v],b=Dt(g,y,v),x=K.MACSTRING(m,b);x===void 0&&(g=0,v=e.indexOf(p),v<0&&(v=e.length,e.push(p)),y=4,x=K.UTF16(m));var M=D7(x,u);h.push($7(g,y,v,n,x.length,M));var w=l[p];if(w!==void 0){var k=K.UTF16(m),z=D7(k,u);h.push($7(3,1,w,n,k.length,z))}}}h.sort(function(I,q){return I.platformID-q.platformID||I.encodingID-q.encodingID||I.languageID-q.languageID||I.nameID-q.nameID});for(var S=new n1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),L=0;L<h.length;L++)S.fields.push({name:"record_"+L,type:"RECORD",value:h[L]});return S.fields.push({name:"strings",type:"LITERAL",value:u}),S}var qt={parse:Hc,make:Rc},Re=[{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 Fc(t){for(var e=0;e<Re.length;e+=1){var n=Re[e];if(t>=n.begin&&t<n.end)return e}return-1}function $c(t,e){var n={},c=new f1.Parser(t,e);n.version=c.parseUShort(),n.xAvgCharWidth=c.parseShort(),n.usWeightClass=c.parseUShort(),n.usWidthClass=c.parseUShort(),n.fsType=c.parseUShort(),n.ySubscriptXSize=c.parseShort(),n.ySubscriptYSize=c.parseShort(),n.ySubscriptXOffset=c.parseShort(),n.ySubscriptYOffset=c.parseShort(),n.ySuperscriptXSize=c.parseShort(),n.ySuperscriptYSize=c.parseShort(),n.ySuperscriptXOffset=c.parseShort(),n.ySuperscriptYOffset=c.parseShort(),n.yStrikeoutSize=c.parseShort(),n.yStrikeoutPosition=c.parseShort(),n.sFamilyClass=c.parseShort(),n.panose=[];for(var r=0;r<10;r++)n.panose[r]=c.parseByte();return n.ulUnicodeRange1=c.parseULong(),n.ulUnicodeRange2=c.parseULong(),n.ulUnicodeRange3=c.parseULong(),n.ulUnicodeRange4=c.parseULong(),n.achVendID=String.fromCharCode(c.parseByte(),c.parseByte(),c.parseByte(),c.parseByte()),n.fsSelection=c.parseUShort(),n.usFirstCharIndex=c.parseUShort(),n.usLastCharIndex=c.parseUShort(),n.sTypoAscender=c.parseShort(),n.sTypoDescender=c.parseShort(),n.sTypoLineGap=c.parseShort(),n.usWinAscent=c.parseUShort(),n.usWinDescent=c.parseUShort(),n.version>=1&&(n.ulCodePageRange1=c.parseULong(),n.ulCodePageRange2=c.parseULong()),n.version>=2&&(n.sxHeight=c.parseShort(),n.sCapHeight=c.parseShort(),n.usDefaultChar=c.parseUShort(),n.usBreakChar=c.parseUShort(),n.usMaxContent=c.parseUShort()),n}function Dc(t){return new n1.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 Fe={parse:$c,make:Dc,unicodeRanges:Re,getUnicodeRange:Fc};function qc(t,e){var n={},c=new f1.Parser(t,e);switch(n.version=c.parseVersion(),n.italicAngle=c.parseFixed(),n.underlinePosition=c.parseShort(),n.underlineThickness=c.parseShort(),n.isFixedPitch=c.parseULong(),n.minMemType42=c.parseULong(),n.maxMemType42=c.parseULong(),n.minMemType1=c.parseULong(),n.maxMemType1=c.parseULong(),n.version){case 1:n.names=s3.slice();break;case 2:n.numberOfGlyphs=c.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var r=0;r<n.numberOfGlyphs;r++)n.glyphNameIndex[r]=c.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=s3.length){var s=c.parseChar();n.names.push(c.parseString(s))}break;case 2.5:n.numberOfGlyphs=c.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var i=0;i<n.numberOfGlyphs;i++)n.offset[i]=c.parseChar();break}return n}function Nc(){return new n1.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 Nt={parse:qc,make:Nc},s2=new Array(9);s2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(O.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(O.coverage),substitute:this.parseOffset16List()};k1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};s2[2]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),sequences:this.parseListOfLists()}};s2[3]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),alternateSets:this.parseListOfLists()}};s2[4]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var H3={sequenceIndex:O.uShort,lookupListIndex:O.uShort};s2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(O.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,H3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(O.coverage),classDef:this.parsePointer(O.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,H3)}})};if(n===3){var c=this.parseUShort(),r=this.parseUShort();return{substFormat:n,coverages:this.parseList(c,O.pointer(O.coverage)),lookupRecords:this.parseRecordList(r,H3)}}k1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};s2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(O.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(H3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(O.coverage),backtrackClassDef:this.parsePointer(O.classDef),inputClassDef:this.parsePointer(O.classDef),lookaheadClassDef:this.parsePointer(O.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(H3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(O.pointer(O.coverage)),inputCoverage:this.parseList(O.pointer(O.coverage)),lookaheadCoverage:this.parseList(O.pointer(O.coverage)),lookupRecords:this.parseRecordList(H3)};k1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};s2[7]=function(){var e=this.parseUShort();k1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),c=new O(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:s2[n].call(c)}};s2[8]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),backtrackCoverage:this.parseList(O.pointer(O.coverage)),lookaheadCoverage:this.parseList(O.pointer(O.coverage)),substitutes:this.parseUShortList()}};function Uc(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);return k1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(s2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(s2),variations:n.parseFeatureVariationsList()}}var R3=new Array(9);R3[1]=function(e){return e.substFormat===1?new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.ushortList("substitute",e.substitute)))};R3[2]=function(e){return k1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("seqSet",e.sequences,function(n){return new n1.Table("sequenceSetTable",n1.ushortList("sequence",n))})))};R3[3]=function(e){return k1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("altSet",e.alternateSets,function(n){return new n1.Table("alternateSetTable",n1.ushortList("alternate",n))})))};R3[4]=function(e){return k1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("ligSet",e.ligatureSets,function(n){return new n1.Table("ligatureSetTable",n1.tableList("ligature",n,function(c){return new n1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:c.ligGlyph}].concat(n1.ushortList("component",c.components,c.components.length+1)))}))})))};R3[6]=function(e){if(e.substFormat===1){var n=new n1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new n1.Table("chainRuleSetTable",n1.tableList("chainRule",a,function(s){var i=n1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(n1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(n1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(n1.ushortList("substitution",[],s.lookupRecords.length));return s.lookupRecords.forEach(function(o,l){i=i.concat({name:"sequenceIndex"+l,type:"USHORT",value:o.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:o.lookupListIndex})}),new n1.Table("chainRuleTable",i)}))})));return n}else if(e.substFormat===2)k1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var c=[{name:"substFormat",type:"USHORT",value:e.substFormat}];c.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(a,s){c.push({name:"backtrackCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){c.push({name:"inputCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){c.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){c=c.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var r=new n1.Table("chainContextTable",c);return r}k1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Bc(t){return new n1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new n1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new n1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new n1.LookupList(t.lookups,R3)}])}var Ut={parse:Uc,make:Bc};function _c(t,e){var n=new f1.Parser(t,e),c=n.parseULong();k1.argument(c===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var r=n.parseULong(),a={},s=0;s<r;s++){var i=n.parseTag(),o=n.parseULong(),l=n.parseULong(),h=O3.UTF8(t,e+o,l);a[i]=h}return a}function Gc(t){var e=Object.keys(t).length,n="",c=16+e*12,r=new n1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:c},{name:"numTags",type:"ULONG",value:e}]);for(var a in t){var s=n.length;n+=t[a],r.fields.push({name:"tag "+a,type:"TAG",value:a}),r.fields.push({name:"offset "+a,type:"ULONG",value:c+s}),r.fields.push({name:"length "+a,type:"ULONG",value:t[a].length})}return r.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),r}var Bt={parse:_c,make:Gc};function q7(t){return Math.log(t)/Math.log(2)|0}function Ge(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 N7(t,e,n,c){return new n1.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:c!==void 0?c:0}])}function _t(t){var e=new n1.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,q7(e.numTables));e.searchRange=16*n,e.entrySelector=q7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],r=[],a=e.sizeOf()+N7().sizeOf()*e.numTables;a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var i=t[s];k1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=N7(i.tableName,Ge(i.encode()),a,o);for(c.push({name:l.tag+" Table Record",type:"RECORD",value:l}),r.push({name:i.tableName+" table",type:"RECORD",value:i}),a+=o,k1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0})}return c.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(c),e.fields=e.fields.concat(r),e}function U7(t,e,n){for(var c=0;c<e.length;c+=1){var r=t.charToGlyphIndex(e[c]);if(r>0){var a=t.glyphs.get(r);return a.getMetrics()}}return n}function jc(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function Wc(t){for(var e=[],n=[],c=[],r=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,p=0;p<t.glyphs.length;p+=1){var m=t.glyphs.get(p),g=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+p+"): advanceWidth is not a number.");(o>g||o===void 0)&&g>0&&(o=g),l<g&&(l=g);var v=Fe.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(m.name!==".notdef"){var y=m.getMetrics();e.push(y.xMin),n.push(y.yMin),c.push(y.xMax),r.push(y.yMax),s.push(y.leftSideBearing),i.push(y.rightSideBearing),a.push(m.advanceWidth)}}var b={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,c),yMax:Math.max.apply(null,r),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:jc(a),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,i)};b.ascender=t.ascender,b.descender=t.descender;var x=Et.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=It.make({ascender:b.ascender,descender:b.descender,advanceWidthMax:b.advanceWidthMax,minLeftSideBearing:b.minLeftSideBearing,minRightSideBearing:b.minRightSideBearing,xMaxExtent:b.maxLeftSideBearing+(b.xMax-b.xMin),numberOfHMetrics:t.glyphs.length}),w=Ot.make(t.glyphs.length),k=Fe.make(Object.assign({xAvgCharWidth:Math.round(b.advanceWidthAvg),usFirstCharIndex:o,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:b.ascender,sTypoDescender:b.descender,sTypoLineGap:0,usWinAscent:b.yMax,usWinDescent:Math.abs(b.yMin),ulCodePageRange1:1,sxHeight:U7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:U7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=Vt.make(t.glyphs),S=bt.make(t.glyphs),L=t.getEnglishName("fontFamily"),I=t.getEnglishName("fontSubfamily"),q=L+" "+I,R=t.getEnglishName("postScriptName");R||(R=L.replace(/\s/g,"")+"-"+I);var N={};for(var G in t.names)N[G]=t.names[G];N.uniqueID||(N.uniqueID={en:t.getEnglishName("manufacturer")+":"+q}),N.postScriptName||(N.postScriptName={en:R}),N.preferredFamily||(N.preferredFamily=t.names.fontFamily),N.preferredSubfamily||(N.preferredSubfamily=t.names.fontSubfamily);var V=[],J=qt.make(N,V),o1=V.length>0?Ht.make(V):void 0,Z=Nt.make(),p1=Tt.make(t.glyphs,{version:t.getEnglishName("version"),fullName:q,familyName:L,weightName:I,postScriptName:R,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),E=t.metas&&Object.keys(t.metas).length>0?Bt.make(t.metas):void 0,$=[x,M,w,k,J,S,Z,p1,z];o1&&$.push(o1),t.tables.gsub&&$.push(Ut.make(t.tables.gsub)),E&&$.push(E);for(var X=_t($),j=X.encode(),w1=Ge(j),W1=X.fields,E1=!1,Z1=0;Z1<W1.length;Z1+=1)if(W1[Z1].name==="head table"){W1[Z1].value.checkSumAdjustment=2981146554-w1,E1=!0;break}if(!E1)throw new Error("Could not find head table with checkSum to adjust.");return X}var Xc={make:_t,fontToTable:Wc,computeCheckSum:Ge};function ze(t,e){for(var n=0,c=t.length-1;n<=c;){var r=n+c>>>1,a=t[r].tag;if(a===e)return r;a<e?n=r+1:c=r-1}return-n-1}function B7(t,e){for(var n=0,c=t.length-1;n<=c;){var r=n+c>>>1,a=t[r];if(a===e)return r;a<e?n=r+1:c=r-1}return-n-1}function _7(t,e){for(var n,c=0,r=t.length-1;c<=r;){var a=c+r>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?c=a+1:r=a-1}if(c>0)return n=t[c-1],e>n.end?0:n}function S5(t,e){this.font=t,this.tableName=e}S5.prototype={searchTag:ze,binSearch:B7,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 c=t.scripts[n].tag;if(c==="DFLT")return c;c==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var c=n.scripts,r=ze(n.scripts,t);if(r>=0)return c[r].script;if(e){var a={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return c.splice(-1-r,0,a),a.script}}},getLangSysTable:function(t,e,n){var c=this.getScriptTable(t,n);if(c){if(!e||e==="dflt"||e==="DFLT")return c.defaultLangSys;var r=ze(c.langSysRecords,e);if(r>=0)return c.langSysRecords[r].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return c.langSysRecords.splice(-1-r,0,a),a.langSys}}},getFeatureTable:function(t,e,n,c){var r=this.getLangSysTable(t,e,c);if(r){for(var a,s=r.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(a=i[s[o]],a.tag===n)return a.feature;if(c){var l=i.length;return k1.assert(l===0||n>=i[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},i.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,c,r){var a=this.getFeatureTable(t,e,n,r),s=[];if(a){for(var i,o=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===c&&s.push(i);if(s.length===0&&r){i={lookupType:c,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(i),o.push(u),[i]}}return s},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=_7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=B7(t.glyphs,e);return n>=0?n:-1;case 2:var c=_7(t.ranges,e);return c?c.index+e-c.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,c=0;c<n.length;c++)for(var r=n[c],a=r.start,s=r.end,i=a;i<=s;i++)e.push(i);return e}};function L5(t){S5.call(this,t,"gpos")}L5.prototype=S5.prototype;L5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};L5.prototype.getKerningValue=function(t,e,n){for(var c=0;c<t.length;c++)for(var r=t[c].subtables,a=0;a<r.length;a++){var s=r[a],i=this.getCoverageIndex(s.coverage,e);if(!(i<0))switch(s.posFormat){case 1:for(var o=s.pairSets[i],l=0;l<o.length;l++){var h=o[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};L5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function W0(t){S5.call(this,t,"gsub")}function Zc(t,e){var n=t.length;if(n!==e.length)return!1;for(var c=0;c<n;c++)if(t[c]!==e[c])return!1;return!0}function je(t,e,n){for(var c=t.subtables,r=0;r<c.length;r++){var a=c[r];if(a.substFormat===e)return a}if(n)return c.push(n),n}W0.prototype=S5.prototype;W0.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};W0.prototype.getSingle=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,1),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;if(o.substFormat===1){var u=o.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];c.push({sub:f,by:f+u})}}else{var d=o.substitute;for(h=0;h<l.length;h++)c.push({sub:l[h],by:d[h]})}}return c};W0.prototype.getMultiple=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,2),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=o.sequences[h];c.push({sub:u,by:f})}}return c};W0.prototype.getAlternates=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,3),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.alternateSets,u=0;u<l.length;u++)c.push({sub:l[u],by:h[u]});return c};W0.prototype.getLigatures=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,4),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],p=0;p<d.length;p++){var m=d[p];c.push({sub:[f].concat(m.components),by:m.ligGlyph})}return c};W0.prototype.addSingle=function(t,e,n,c){var r=this.getLookupTables(n,c,t,1,!0)[0],a=je(r,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});k1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.substitute.splice(i,0,0)),a.substitute[i]=e.by};W0.prototype.addMultiple=function(t,e,n,c){k1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var r=this.getLookupTables(n,c,t,2,!0)[0],a=je(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});k1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.sequences.splice(i,0,0)),a.sequences[i]=e.by};W0.prototype.addAlternate=function(t,e,n,c){var r=this.getLookupTables(n,c,t,3,!0)[0],a=je(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});k1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.alternateSets.splice(i,0,0)),a.alternateSets[i]=e.by};W0.prototype.addLigature=function(t,e,n,c){var r=this.getLookupTables(n,c,t,4,!0)[0],a=r.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},r.subtables[0]=a),k1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(Zc(h[u].components,i))return;h.push(o)}else l=-1-l,a.coverage.glyphs.splice(l,0,s),a.ligatureSets.splice(l,0,[o])};W0.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)}};W0.prototype.add=function(t,e,n,c){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,c);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,c):this.addAlternate(t,e,n,c);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,c);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,c):this.addLigature(t,e,n,c)}};function Yc(){return typeof window<"u"}function Jc(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),c=0;c<e.length;++c)e[c]=n[c];return e}function b5(t,e){if(!t)throw e}function G7(t,e,n,c,r){var a;return(e&c)>0?(a=t.parseByte(),(e&r)===0&&(a=-a),a=n+a):(e&r)>0?a=n:a=n+t.parseShort(),a}function Gt(t,e,n){var c=new f1.Parser(e,n);t.numberOfContours=c.parseShort(),t._xMin=c.parseShort(),t._yMin=c.parseShort(),t._xMax=c.parseShort(),t._yMax=c.parseShort();var r,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],i=0;i<t.numberOfContours;i+=1)s.push(c.parseUShort());t.instructionLength=c.parseUShort(),t.instructions=[];for(var o=0;o<t.instructionLength;o+=1)t.instructions.push(c.parseByte());var l=s[s.length-1]+1;r=[];for(var h=0;h<l;h+=1)if(a=c.parseByte(),r.push(a),(a&8)>0)for(var u=c.parseByte(),f=0;f<u;f+=1)r.push(a),h+=1;if(k1.argument(r.length===l,"Bad flags."),s.length>0){var d=[],p;if(l>0){for(var m=0;m<l;m+=1)a=r[m],p={},p.onCurve=!!(a&1),p.lastPointOfContour=s.indexOf(m)>=0,d.push(p);for(var g=0,v=0;v<l;v+=1)a=r[v],p=d[v],p.x=G7(c,a,g,2,16),g=p.x;for(var y=0,b=0;b<l;b+=1)a=r[b],p=d[b],p.y=G7(c,a,y,4,32),y=p.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){r=c.parseUShort();var M={glyphIndex:c.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(r&1)>0?(r&2)>0?(M.dx=c.parseShort(),M.dy=c.parseShort()):M.matchedPoints=[c.parseUShort(),c.parseUShort()]:(r&2)>0?(M.dx=c.parseChar(),M.dy=c.parseChar()):M.matchedPoints=[c.parseByte(),c.parseByte()],(r&8)>0?M.xScale=M.yScale=c.parseF2Dot14():(r&64)>0?(M.xScale=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()):(r&128)>0&&(M.xScale=c.parseF2Dot14(),M.scale01=c.parseF2Dot14(),M.scale10=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()),t.components.push(M),x=!!(r&32)}if(r&256){t.instructionLength=c.parseUShort(),t.instructions=[];for(var w=0;w<t.instructionLength;w+=1)t.instructions.push(c.parseByte())}}}function ke(t,e){for(var n=[],c=0;c<t.length;c+=1){var r=t[c],a={x:e.xScale*r.x+e.scale01*r.y+e.dx,y:e.scale10*r.x+e.yScale*r.y+e.dy,onCurve:r.onCurve,lastPointOfContour:r.lastPointOfContour};n.push(a)}return n}function Kc(t){for(var e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];n.push(r),r.lastPointOfContour&&(e.push(n),n=[])}return k1.argument(n.length===0,"There are still points left in the current contour."),e}function jt(t){var e=new M0;if(!t)return e;for(var n=Kc(t),c=0;c<n.length;++c){var r=n[c],a=null,s=r[r.length-1],i=r[0];if(s.onCurve)e.moveTo(s.x,s.y);else if(i.onCurve)e.moveTo(i.x,i.y);else{var o={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5};e.moveTo(o.x,o.y)}for(var l=0;l<r.length;++l)if(a=s,s=i,i=r[(l+1)%r.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=a,u=i;a.onCurve||(h={x:(s.x+a.x)*.5,y:(s.y+a.y)*.5}),i.onCurve||(u={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5}),e.quadraticCurveTo(s.x,s.y,u.x,u.y)}e.closePath()}return e}function Wt(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var c=e.components[n],r=t.get(c.glyphIndex);if(r.getPath(),r.points){var a=void 0;if(c.matchedPoints===void 0)a=ke(r.points,c);else{if(c.matchedPoints[0]>e.points.length-1||c.matchedPoints[1]>r.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[c.matchedPoints[0]],i=r.points[c.matchedPoints[1]],o={xScale:c.xScale,scale01:c.scale01,scale10:c.scale10,yScale:c.yScale,dx:0,dy:0};i=ke([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=ke(r.points,o)}e.points=e.points.concat(a)}}return jt(e.points)}function Qc(t,e,n,c){for(var r=new M2.GlyphSet(c),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?r.push(a,M2.ttfGlyphLoader(c,a,Gt,t,e+s,Wt)):r.push(a,M2.glyphLoader(c,a))}return r}function er(t,e,n,c){var r=new M2.GlyphSet(c);return c._push=function(a){var s=n[a],i=n[a+1];s!==i?r.push(a,M2.ttfGlyphLoader(c,a,Gt,t,e+s,Wt)):r.push(a,M2.glyphLoader(c,a))},r}function tr(t,e,n,c,r){return r.lowMemory?er(t,e,n,c):Qc(t,e,n,c)}var Xt={getPath:jt,parse:tr},Zt,o3,Yt,$e;function Jt(t){this.font=t,this.getCommands=function(e){return Xt.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function nr(t){return t}function Kt(t){return Math.sign(t)*Math.round(Math.abs(t))}function cr(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function rr(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function ar(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function sr(t){return Math.sign(t)*Math.floor(Math.abs(t))}var Qt=function(t){var e=this.srPeriod,n=this.srPhase,c=this.srThreshold,r=1;return t<0&&(t=-t,r=-1),t+=c-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*r:t*r},x2={x:1,y:0,axis:"x",distance:function(t,e,n,c){return(n?t.xo:t.x)-(c?e.xo:e.x)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.xo-e.xo,a=t.xo-n.xo,o=e.x-e.xo,l=n.x-n.xo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.x=t.xo+(o+l)/2;return}t.x=t.xo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){x2.setRelative(t,t,(o+l)/2,c,!0);return}x2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,c,r){if(!c||c===this){t.x=(r?e.xo:e.x)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.x=i+(t.y-o)/c.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},E2={x:0,y:1,axis:"y",distance:function(t,e,n,c){return(n?t.yo:t.y)-(c?e.yo:e.y)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.yo-e.yo,a=t.yo-n.yo,o=e.y-e.yo,l=n.y-n.yo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.y=t.yo+(o+l)/2;return}t.y=t.yo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){E2.setRelative(t,t,(o+l)/2,c,!0);return}E2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:0,setRelative:function(t,e,n,c,r){if(!c||c===this){t.y=(r?e.yo:e.y)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.y=o+c.normalSlope*(t.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(x2);Object.freeze(E2);function A5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}A5.prototype.distance=function(t,e,n,c){return this.x*x2.distance(t,e,n,c)+this.y*E2.distance(t,e,n,c)};A5.prototype.interpolate=function(t,e,n,c){var r,a,s,i,o,l,h;if(s=c.distance(t,e,!0,!0),i=c.distance(t,n,!0,!0),r=c.distance(e,e,!1,!0),a=c.distance(n,n,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(t,t,(r+a)/2,c,!0);return}this.setRelative(t,t,(r*l+a*o)/h,c,!0)};A5.prototype.setRelative=function(t,e,n,c,r){c=c||this;var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y,l=c.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*i+o-f)/(h-l),t.y=h*(t.x-u)+f};A5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function C5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?x2:t===0&&e===1?E2:new A5(t,e)}function I2(t,e,n,c){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=c,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}I2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};I2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var k5=Object.freeze(new I2(0,0)),ir={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function G2(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=x2,this.round=Kt}}Jt.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,c=this._prepState;if(!c||c.ppem!==e){var r=this._fpgmState;if(!r){G2.prototype=ir,r=this._fpgmState=new G2("fpgm",n.tables.fpgm),r.funcs=[],r.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),r.step=-1);try{o3(r)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}G2.prototype=r,c=this._prepState=new G2("prep",n.tables.prep),c.ppem=e;var a=n.tables.cvt;if(a)for(var s=c.cvt=new Array(a.length),i=e/n.unitsPerEm,o=0;o<a.length;o++)s[o]=a[o]*i;else c.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),c.step=-1);try{o3(c)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return Yt(t,c)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};Yt=function(t,e){var n=e.ppem/e.font.unitsPerEm,c=n,r=t.components,a,s,i;if(G2.prototype=e,!r)i=new G2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),$e(t,i,n,c),s=i.gZone;else{var o=e.font;s=[],a=[];for(var l=0;l<r.length;l++){var h=r[l],u=o.glyphs.get(h.glyphIndex);i=new G2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),$e(u,i,n,c);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*c),p=i.gZone,m=i.contours,g=0;g<p.length;g++){var v=p[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,p);for(var b=0;b<m.length;b++)a.push(m[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new G2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new I2(0,0),new I2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),o3(i),s.length-=2)}return s};$e=function(t,e,n,c){for(var r=t.points||[],a=r.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<a;l++)o=r[l],s[l]=new I2(o.x*n,o.y*c,o.lastPointOfContour,o.onCurve);for(var h,u,f=0;f<a;f++)o=s[f],h||(h=o,i.push(f)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(u=s[f+1],o.nextPointOnContour=u,u.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new I2(0,0),new I2(Math.round(t.advanceWidth*n),0)),o3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var p=0;p<a;p++)console.log(p,s[p].x,s[p].y)}}};o3=function(t){var e=t.prog;if(e){var n=e.length,c;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,c=Zt[e[t.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));c(t)}}};function y4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new I2(0,0)}function e8(t,e){var n=t.prog,c=t.ip,r=1,a;do if(a=n[++c],a===88)r++;else if(a===89)r--;else if(a===64)c+=n[c+1]+1;else if(a===65)c+=2*n[c+1]+1;else if(a>=176&&a<=183)c+=a-176+1;else if(a>=184&&a<=191)c+=(a-184+1)*2;else if(e&&r===1&&a===27)break;while(r>0);t.ip=c}function j7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function W7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function X7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function Z7(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.pv=e.dpv=C5(i,o)}function Y7(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SFVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.fv=C5(i,o)}function or(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.pv=t.dpv=C5(c,n)}function lr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.fv=C5(c,n)}function hr(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 ur(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 fr(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function dr(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop(),a=e.pop(),s=e.pop(),i=t.z0,o=t.z1,l=i[n],h=i[c],u=o[r],f=o[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,c,r,a,s);var p=l.x,m=l.y,g=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,w=(p-g)*(b-M)-(m-v)*(y-x),k=p*v-m*g,z=y*M-b*x;d.x=(k*(y-x)-z*(p-g))/w,d.y=(k*(b-M)-z*(m-v))/w}function pr(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function mr(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function gr(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function vr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||y4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function yr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||y4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function br(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||y4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function xr(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||y4(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 Mr(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function wr(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=Kt}function zr(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=rr}function kr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function Sr(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),e8(t,!1)}function Lr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Ar(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Cr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function Se(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function Pr(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Tr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(c)}function Er(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Ir(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,c);var r=t.ip,a=t.prog;t.prog=t.funcs[n];for(var s=0;s<c;s++)o3(t),exports.DEBUG&&console.log(++t.step,s+1<c?"next loopcall":"done loopcall",s);t.ip=r,t.prog=a}function Vr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,c=t.prog;t.prog=t.funcs[e],o3(t),t.ip=n,t.prog=c,exports.DEBUG&&console.log(++t.step,"returning from",e)}function Hr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Or(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 Rr(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,c=t.ip,r=e.pop(),a=c;for(exports.DEBUG&&console.log(t.step,"FDEF[]",r);n[++c]!==45;);t.ip=c,t.funcs[r]=n.slice(a+1,c)}function J7(t,e){var n=e.stack.pop(),c=e.z0[n],r=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(c,k5);t&&(s=e.round(s)),r.setRelative(c,k5,s,a),r.touch(c),e.rp0=e.rp1=n}function K7(t,e){var n=e.z2,c=n.length-2,r,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var i=0;i<c;i++)r=n[i],!t.touched(r)&&(a=r.prevTouched(t),a!==r&&(s=r.nextTouched(t),a===s&&t.setRelative(r,r,t.distance(a,a,!1,!0),t,!0),t.interpolate(r,a,s,t)))}function Q7(t,e){for(var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=e.loop,o=e.z2;i--;){var l=n.pop(),h=o[l],u=s.distance(r,r,!1,!0);a.setRelative(h,h,u,s),a.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-i)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function et(t,e){var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=n.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",i);var h=s.distance(r,r,!1,!0);do l!==r&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function tt(t,e){var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",i);var o;switch(i){case 0:o=e.tZone;break;case 1:o=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=s.distance(r,r,!1,!0),u=o.length-2,f=0;f<u;f++)l=o[f],a.setRelative(l,l,h,s)}function Fr(t){for(var e=t.stack,n=t.loop,c=t.fv,r=e.pop()/64,a=t.z2;n--;){var s=e.pop(),i=a[s];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",s,r),c.setRelative(i,i,r),c.touch(i)}t.loop=1}function $r(t){for(var e=t.stack,n=t.rp1,c=t.rp2,r=t.loop,a=t.z0[n],s=t.z1[c],i=t.fv,o=t.dpv,l=t.z2;r--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-r)+": ":"")+"IP[]",h,n,"<->",c),i.interpolate(u,a,s,o),i.touch(u)}t.loop=1}function nt(t,e){var n=e.stack,c=n.pop()/64,r=n.pop(),a=e.z1[r],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(a,s,c,o),i.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",c,r),e.rp1=e.rp0,e.rp2=r,t&&(e.rp0=r)}function Dr(t){for(var e=t.stack,n=t.rp0,c=t.z0[n],r=t.loop,a=t.fv,s=t.pv,i=t.z1;r--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-r)+": ":"")+"ALIGNRP[]",o),a.setRelative(l,c,0,s),a.touch(l)}t.loop=1}function qr(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=cr}function ct(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z0[r],s=e.fv,i=e.pv,o=e.cvt[c];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",c,"(",o,")",r);var l=i.distance(a,k5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,k5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=r}function Nr(t){var e=t.prog,n=t.ip,c=t.stack,r=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",r);for(var a=0;a<r;a++)c.push(e[++n]);t.ip=n}function Ur(t){var e=t.ip,n=t.prog,c=t.stack,r=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",r);for(var a=0;a<r;a++){var s=n[++e]<<8|n[++e];s&32768&&(s=-((s^65535)+1)),c.push(s)}t.ip=e}function Br(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var c=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WS",c,r),n[r]=c}function _r(t){var e=t.stack,n=t.store,c=e.pop();exports.DEBUG&&console.log(t.step,"RS",c);var r=n&&n[c]||0;e.push(r)}function Gr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,c),t.cvt[c]=n/64}function jr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function rt(t,e){var n=e.stack,c=n.pop(),r=e.z2[c];exports.DEBUG&&console.log(e.step,"GC["+t+"]",c),n.push(e.dpv.distance(r,k5,t,!1)*64)}function at(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z1[c],s=e.z0[r],i=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",c,r,"->",i),e.stack.push(Math.round(i*64))}function Wr(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Xr(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Zr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,c),e.push(c<n?1:0)}function Yr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,c),e.push(c<=n?1:0)}function Jr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,c),e.push(c>n?1:0)}function Kr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,c),e.push(c>=n?1:0)}function Qr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,c),e.push(n===c?1:0)}function ea(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,c),e.push(n!==c?1:0)}function ta(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 na(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 ca(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(e8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function ra(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function aa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,c),e.push(n&&c?1:0)}function sa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,c),e.push(n||c?1:0)}function ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function Le(t,e){var n=e.stack,c=n.pop(),r=e.fv,a=e.pv,s=e.ppem,i=e.deltaBase+(t-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",c,n);for(var h=0;h<c;h++){var u=n.pop(),f=n.pop(),d=i+((f&240)>>4);if(d===s){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",p*o);var m=l[u];r.setRelative(m,m,p*o,a)}}}function oa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function la(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function ha(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,c),e.push(c+n)}function ua(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,c),e.push(c-n)}function fa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,c),e.push(c*64/n)}function da(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,c),e.push(c*n/64)}function pa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function ma(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function ga(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function va(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function l4(t,e){var n=e.stack,c=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(c/64)*64)}function ya(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,c),t.cvt[c]=n*t.ppem/t.font.unitsPerEm}function Ae(t,e){var n=e.stack,c=n.pop(),r=e.ppem,a=e.deltaBase+(t-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",c,n);for(var i=0;i<c;i++){var o=n.pop(),l=n.pop(),h=a+((l&240)>>4);if(h===r){var u=(l&15)-8;u>=0&&u++;var f=u*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",o,"by",f),e.cvt[o]+=f}}}function ba(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=Qt;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 xa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=Qt;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 Ma(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=nr}function wa(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=ar}function za(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=sr}function ka(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function st(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.dpv=C5(i,o)}function Sa(t){var e=t.stack,n=e.pop(),c=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(c=35),n&32&&(c|=4096),e.push(c)}function La(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(c),e.push(n),e.push(r)}function Aa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,c),e.push(Math.max(c,n))}function Ca(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,c),e.push(Math.min(c,n))}function Pa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ta(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 U2(t,e){var n=e.stack,c=e.prog,r=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(c[++r]);e.ip=r}function B2(t,e){var n=e.ip,c=e.prog,r=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=c[++n]<<8|c[++n];s&32768&&(s=-((s^65535)+1)),r.push(s)}e.ip=n}function h1(t,e,n,c,r,a){var s=a.stack,i=t&&s.pop(),o=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[o],f=a.minDis,d=a.fv,p=a.dpv,m,g,v,y;g=m=p.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(y=a.cvt[i],c&&Math.abs(g-y)<a.cvCutIn&&(g=y)),n&&g<f&&(g=f),c&&(g=a.round(g)),d.setRelative(u,h,v*g,p),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(c?"R":"_")+(r===0?"Gr":r===1?"Bl":r===2?"Wh":"")+"]",t?i+"("+a.cvt[i]+","+y+")":"",o,"(d =",m,"->",v*g,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}Zt=[j7.bind(void 0,E2),j7.bind(void 0,x2),W7.bind(void 0,E2),W7.bind(void 0,x2),X7.bind(void 0,E2),X7.bind(void 0,x2),Z7.bind(void 0,0),Z7.bind(void 0,1),Y7.bind(void 0,0),Y7.bind(void 0,1),or,lr,hr,ur,fr,dr,pr,mr,gr,vr,yr,br,xr,Mr,wr,zr,kr,Sr,Lr,Ar,void 0,void 0,Cr,Se,Pr,Tr,Er,Hr,Or,void 0,void 0,void 0,Ir,Vr,Rr,void 0,J7.bind(void 0,0),J7.bind(void 0,1),K7.bind(void 0,E2),K7.bind(void 0,x2),Q7.bind(void 0,0),Q7.bind(void 0,1),et.bind(void 0,0),et.bind(void 0,1),tt.bind(void 0,0),tt.bind(void 0,1),Fr,$r,nt.bind(void 0,0),nt.bind(void 0,1),Dr,qr,ct.bind(void 0,0),ct.bind(void 0,1),Nr,Ur,Br,_r,Gr,jr,rt.bind(void 0,0),rt.bind(void 0,1),void 0,at.bind(void 0,0),at.bind(void 0,1),Wr,void 0,Xr,void 0,void 0,Zr,Yr,Jr,Kr,Qr,ea,ta,na,ca,ra,aa,sa,ia,Le.bind(void 0,1),oa,la,ha,ua,fa,da,pa,ma,ga,va,l4.bind(void 0,0),l4.bind(void 0,1),l4.bind(void 0,2),l4.bind(void 0,3),void 0,void 0,void 0,void 0,ya,Le.bind(void 0,2),Le.bind(void 0,3),Ae.bind(void 0,1),Ae.bind(void 0,2),Ae.bind(void 0,3),ba,xa,void 0,void 0,Ma,void 0,wa,za,Se,Se,void 0,void 0,void 0,void 0,void 0,ka,st.bind(void 0,0),st.bind(void 0,1),Sa,void 0,La,Aa,Ca,Pa,Ta,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,U2.bind(void 0,1),U2.bind(void 0,2),U2.bind(void 0,3),U2.bind(void 0,4),U2.bind(void 0,5),U2.bind(void 0,6),U2.bind(void 0,7),U2.bind(void 0,8),B2.bind(void 0,1),B2.bind(void 0,2),B2.bind(void 0,3),B2.bind(void 0,4),B2.bind(void 0,5),B2.bind(void 0,6),B2.bind(void 0,7),B2.bind(void 0,8),h1.bind(void 0,0,0,0,0,0),h1.bind(void 0,0,0,0,0,1),h1.bind(void 0,0,0,0,0,2),h1.bind(void 0,0,0,0,0,3),h1.bind(void 0,0,0,0,1,0),h1.bind(void 0,0,0,0,1,1),h1.bind(void 0,0,0,0,1,2),h1.bind(void 0,0,0,0,1,3),h1.bind(void 0,0,0,1,0,0),h1.bind(void 0,0,0,1,0,1),h1.bind(void 0,0,0,1,0,2),h1.bind(void 0,0,0,1,0,3),h1.bind(void 0,0,0,1,1,0),h1.bind(void 0,0,0,1,1,1),h1.bind(void 0,0,0,1,1,2),h1.bind(void 0,0,0,1,1,3),h1.bind(void 0,0,1,0,0,0),h1.bind(void 0,0,1,0,0,1),h1.bind(void 0,0,1,0,0,2),h1.bind(void 0,0,1,0,0,3),h1.bind(void 0,0,1,0,1,0),h1.bind(void 0,0,1,0,1,1),h1.bind(void 0,0,1,0,1,2),h1.bind(void 0,0,1,0,1,3),h1.bind(void 0,0,1,1,0,0),h1.bind(void 0,0,1,1,0,1),h1.bind(void 0,0,1,1,0,2),h1.bind(void 0,0,1,1,0,3),h1.bind(void 0,0,1,1,1,0),h1.bind(void 0,0,1,1,1,1),h1.bind(void 0,0,1,1,1,2),h1.bind(void 0,0,1,1,1,3),h1.bind(void 0,1,0,0,0,0),h1.bind(void 0,1,0,0,0,1),h1.bind(void 0,1,0,0,0,2),h1.bind(void 0,1,0,0,0,3),h1.bind(void 0,1,0,0,1,0),h1.bind(void 0,1,0,0,1,1),h1.bind(void 0,1,0,0,1,2),h1.bind(void 0,1,0,0,1,3),h1.bind(void 0,1,0,1,0,0),h1.bind(void 0,1,0,1,0,1),h1.bind(void 0,1,0,1,0,2),h1.bind(void 0,1,0,1,0,3),h1.bind(void 0,1,0,1,1,0),h1.bind(void 0,1,0,1,1,1),h1.bind(void 0,1,0,1,1,2),h1.bind(void 0,1,0,1,1,3),h1.bind(void 0,1,1,0,0,0),h1.bind(void 0,1,1,0,0,1),h1.bind(void 0,1,1,0,0,2),h1.bind(void 0,1,1,0,0,3),h1.bind(void 0,1,1,0,1,0),h1.bind(void 0,1,1,0,1,1),h1.bind(void 0,1,1,0,1,2),h1.bind(void 0,1,1,0,1,3),h1.bind(void 0,1,1,1,0,0),h1.bind(void 0,1,1,1,0,1),h1.bind(void 0,1,1,1,0,2),h1.bind(void 0,1,1,1,0,3),h1.bind(void 0,1,1,1,1,0),h1.bind(void 0,1,1,1,1,1),h1.bind(void 0,1,1,1,1,2),h1.bind(void 0,1,1,1,1,3)];function F3(t){this.char=t,this.state={},this.activeState=null}function We(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function Ea(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function i2(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 b4(t){this.eventId=t,this.subscribers=[]}function Ia(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(r){Object.defineProperty(e.events,r,{value:new b4(r)})}),t&&n.forEach(function(r){var a=t[r];typeof a=="function"&&e.events[r].subscribe(a)});var c=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];c.forEach(function(r){e.events[r].subscribe(e.updateContextsRanges)})}function u0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Ia.call(this,t)}F3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};F3.prototype.getState=function(t){return this.state[t]||null};u0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};u0.prototype.composeRUD=function(t){var e=this,n=!0,c=t.map(function(a){return e[a[0]].apply(e,a.slice(1).concat(n))}),r=function(a){return typeof a=="object"&&a.hasOwnProperty("FAIL")};if(c.every(r))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:c.filter(r)};this.dispatch("composeRUD",[c.filter(function(a){return!r(a)})])};u0.prototype.replaceRange=function(t,e,n,c){e=e!==null?e:this.tokens.length;var r=n.every(function(s){return s instanceof F3});if(!isNaN(t)&&this.inboundIndex(t)&&r){var a=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return c||this.dispatch("replaceToken",[t,e,n]),[a,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};u0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof F3){var c=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[c[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};u0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var c=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[c,t,e]),c};u0.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."}};u0.prototype.insertToken=function(t,e,n){var c=t.every(function(r){return r instanceof F3});return c?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};u0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(c,r){var a=[c,r],s=e===null||e.apply(this,a)===!0,i=[c,r];if(s){var o=n.apply(this,i);c.setState(t,o)}}),this.registeredModifiers.push(t)};b4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};b4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};i2.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)};i2.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}};u0.prototype.rangeToText=function(t){if(t instanceof We)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};u0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};u0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};u0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};u0.prototype.dispatch=function(t,e){var n=this,c=this.events[t];c instanceof b4&&c.subscribers.forEach(function(r){r.apply(n,e||[])})};u0.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 c=new Ea(t,e,n);return this.registeredContexts[t]=c,this.contextCheckers.push(c),c};u0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};u0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};u0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};u0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(c){return c.char}),e=0;e<t.length;e++){var n=new i2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};u0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,c=new We(n,t,e),r=this.getContext(e).ranges;return c.rangeId=e+"."+r.length,r.push(c),this.getContext(e).openRange=null,c};u0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(c){var r=c.contextName,a=e.getContext(r).openRange;if(!a&&c.checkStart(t)&&(a=new We(n,null,r),e.getContext(r).openRange=a,e.dispatch("contextStart",[r,n])),a&&c.checkEnd(t)){var s=n-a.startIndex+1,i=e.setEndOffset(s,r);e.dispatch("contextEnd",[r,i])}})};u0.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 c=e[n],r=new i2(e,n);this.dispatch("next",[r]),this.runContextCheck(r);var a=new F3(c);this.tokens.push(a),this.dispatch("newToken",[a,r])}return this.dispatch("end",[this.tokens]),this.tokens};function j2(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function t8(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 W2(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function u4(t){return/[A-z]/.test(t)}function Va(t){return/\s/.test(t)}function X0(t){this.font=t,this.features={}}function i3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function P5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,c=0;c<n.length;c++){var r=n[c];if(t>=r.start&&t<=r.end){var a=t-r.start;return r.index+a}}break;default:return-1}return-1}function Ha(t,e){var n=P5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Oa(t,e){var n=P5(t,e.coverage);return n===-1?null:e.substitute[n]}function Ce(t,e){for(var n=[],c=0;c<t.length;c++){var r=t[c],a=e.current;a=Array.isArray(a)?a[0]:a;var s=P5(a,r);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function Ra(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var c=Ce(e.inputCoverage,t);if(c===-1)return[];var r=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(r);a.length&&W2(a[0].char);)a.shift();var s=new i2(a,0),i=Ce(e.lookaheadCoverage,s),o=[].concat(t.backtrack);for(o.reverse();o.length&&W2(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new i2(o,0),h=Ce(e.backtrackCoverage,l),u=c.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var p=e.lookupRecords[d],m=p.lookupListIndex,g=this.getLookupByIndex(m),v=0;v<g.subtables.length;v++){var y=g.subtables[v],b=this.getLookupMethod(g,y),x=this.getSubstitutionType(g,y);if(x==="12")for(var M=0;M<c.length;M++){var w=t.get(M),k=b(w);k&&f.push(k)}}return f}function Fa(t,e){var n=t.current,c=P5(n,e.coverage);if(c===-1)return null;for(var r,a=e.ligatureSets[c],s=0;s<a.length;s++){r=a[s];for(var i=0;i<r.components.length;i++){var o=t.lookahead[i],l=r.components[i];if(o!==l)break;if(i===r.components.length-1)return r}}return null}function $a(t,e){var n=P5(t,e.coverage);return n===-1?null:e.sequences[n]}X0.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[]};X0.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,c=0;c<n.length;c++){var r=n[c];if(r.tag===t&&r.script.defaultLangSys)return r.script.defaultLangSys.featureIndexes;var a=r.langSysRecords;if(a)for(var s=0;s<a.length;s++){var i=a[s];if(i.tag===t){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};X0.prototype.mapTagsToFeatures=function(t,e){for(var n={},c=0;c<t.length;c++){var r=t[c].tag,a=t[c].feature;n[r]=a}this.features[e].tags=n};X0.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 c=this.font.tables.gsub;return e=n.map(function(r){return c.features[r]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};X0.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),c=e.substFormat.toString();return n+c};X0.prototype.getLookupMethod=function(t,e){var n=this,c=this.getSubstitutionType(t,e);switch(c){case"11":return function(r){return Ha.apply(n,[r,e])};case"12":return function(r){return Oa.apply(n,[r,e])};case"63":return function(r){return Ra.apply(n,[r,e])};case"41":return function(r){return Fa.apply(n,[r,e])};case"21":return function(r){return $a.apply(n,[r,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};X0.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,c=this.getFeature({tag:t.tag,script:t.script});if(!c)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var r=this.getFeatureLookups(c),a=[].concat(e.context),s=0;s<r.length;s++)for(var i=r[s],o=this.getLookupSubtables(i),l=0;l<o.length;l++){var h=o[l],u=this.getSubstitutionType(i,h),f=this.getLookupMethod(i,h),d=void 0;switch(u){case"11":d=f(e.current),d&&a.splice(n,1,new i3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new i3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new i3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new i3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new i3({id:21,tag:t.tag,substitution:d}));break}e=new i2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};X0.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(c){return c.tag===t.tag});return e&&n};X0.prototype.getLookupSubtables=function(t){return t.subtables||null};X0.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};X0.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};X0.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 Da(t){var e=t.current,n=t.get(-1);return n===null&&j2(e)||!j2(n)&&j2(e)}function qa(t){var e=t.get(1);return e===null||!j2(e)}var Na={startCheck:Da,endCheck:qa};function Ua(t){var e=t.current,n=t.get(-1);return(j2(e)||W2(e))&&!j2(n)}function Ba(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!j2(e)&&!W2(e)):var n=Va(e);if(!n)return!0;if(n){var c=!1;if(c=t.lookahead.some(function(r){return j2(r)||W2(r)}),!c)return!0}break;default:return!1}}var _a={startCheck:Ua,endCheck:Ba};function Ga(t,e,n){e[n].setState(t.tag,t.substitution)}function ja(t,e,n){e[n].setState(t.tag,t.substitution)}function Wa(t,e,n){t.substitution.forEach(function(c,r){var a=e[n+r];a.setState(t.tag,c)})}function Xa(t,e,n){var c=e[n];c.setState(t.tag,t.substitution.ligGlyph);for(var r=t.substitution.components.length,a=0;a<r;a++)c=e[n+a+1],c.setState("deleted",!0)}var it={11:Ga,12:ja,63:Wa,41:Xa};function Xe(t,e,n){t instanceof i3&&it[t.id]&&it[t.id](t,e,n)}function Za(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var c=e[n],r=t8(c),a=W2(c);if(!r&&!a)return!0;if(r)return!1}return!1}function Ya(t){if(t8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],c=W2(n);if(!c)return!0}return!1}function Ja(t){var e=this,n="arab",c=this.featuresTags[n],r=this.tokenizer.getRangeTokens(t);if(r.length!==1){var a=new i2(r.map(function(i){return i.getState("glyphIndex")}),0),s=new i2(r.map(function(i){return i.char}),0);r.forEach(function(i,o){if(!W2(i.char)){a.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;Za(s)&&(l|=1),Ya(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(c.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof i3&&(Xe(f,r,d),a.context[d]=f.substitution)})}}})}}function ot(t,e){var n=t.map(function(c){return c.activeState.value});return new i2(n,e||0)}function Ka(t){var e=this,n="arab",c=this.tokenizer.getRangeTokens(t),r=ot(c);r.context.forEach(function(a,s){r.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:n,contextParams:r});i.length&&(i.forEach(function(o){return Xe(o,c,s)}),r=ot(c))})}function Qa(t){var e=t.current,n=t.get(-1);return n===null&&u4(e)||!u4(n)&&u4(e)}function es(t){var e=t.get(1);return e===null||!u4(e)}var ts={startCheck:Qa,endCheck:es};function lt(t,e){var n=t.map(function(c){return c.activeState.value});return new i2(n,e||0)}function ns(t){var e=this,n="latn",c=this.tokenizer.getRangeTokens(t),r=lt(c);r.context.forEach(function(a,s){r.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:n,contextParams:r});i.length&&(i.forEach(function(o){return Xe(o,c,s)}),r=lt(c))})}function h2(t){this.baseDir=t||"ltr",this.tokenizer=new u0,this.featuresTags={}}h2.prototype.setText=function(t){this.text=t};h2.prototype.contextChecks={latinWordCheck:ts,arabicWordCheck:Na,arabicSentenceCheck:_a};function Pe(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function cs(){return Pe.call(this,"latinWord"),Pe.call(this,"arabicWord"),Pe.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function rs(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var c=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,c.reverse())})}h2.prototype.registerFeatures=function(t,e){var n=this,c=e.filter(function(r){return n.query.supports({script:t,tag:r})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(c):this.featuresTags[t]=c};h2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new X0(t));for(var n=0;n<e.length;n++){var c=e[n];this.query.supports({script:c.script})&&this.registerFeatures(c.script,c.tags)}};h2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function Ze(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function as(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){Ze.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(c){Ja.call(t,c)})}}function ss(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){Ze.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(r){Ka.call(t,r)})}}}function is(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){Ze.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(r){ns.call(t,r)})}}}h2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};h2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(as.call(this),ss.call(this)),this.checkContextReady("latinWord")&&is.call(this),this.checkContextReady("arabicSentence")&&rs.call(this)};h2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),cs.call(this),this.applyFeaturesToContexts())};h2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};h2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var c=this.tokenizer.tokens[n];if(!c.state.deleted){var r=c.activeState.value;e.push(Array.isArray(r)?r[0]:r)}}return e};function t0(t){t=t||{},t.tables=t.tables||{},t.empty||(b5(t.familyName,"When creating a new Font object, familyName is required."),b5(t.styleName,"When creating a new Font object, styleName is required."),b5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),b5(t.ascender,"When creating a new Font object, ascender is required."),b5(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 M2.GlyphSet(this,t.glyphs||[]),this.encoding=new xt(this),this.position=new L5(this),this.substitution=new W0(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 Jt(this)}})}t0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};t0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};t0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.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})};t0.prototype.stringToGlyphs=function(t,e){var n=this,c=new h2,r=function(u){return n.charToGlyphIndex(u.char)};c.registerModifier("glyphIndex",null,r);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;c.applyFeatures(this,a);for(var s=c.getTextGlyphs(t),i=s.length,o=new Array(i),l=this.glyphs.get(0),h=0;h<i;h+=1)o[h]=this.glyphs.get(s[h])||l;return o};t0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};t0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};t0.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};t0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};t0.prototype.forEachGlyph=function(t,e,n,c,r,a){e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:72,r=Object.assign({},this.defaultRenderOptions,r);var s=1/this.unitsPerEm*c,i=this.stringToGlyphs(t,r),o;if(r.kerning){var l=r.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,r.language)}for(var h=0;h<i.length;h+=1){var u=i[h];if(a.call(this,u,e,n,c,r),u.advanceWidth&&(e+=u.advanceWidth*s),r.kerning&&h<i.length-1){var f=o?this.position.getKerningValue(o,u.index,i[h+1].index):this.getKerningValue(u,i[h+1]);e+=f*s}r.letterSpacing?e+=r.letterSpacing*c:r.tracking&&(e+=r.tracking/1e3*c)}return e};t0.prototype.getPath=function(t,e,n,c,r){var a=new M0;return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.extend(h)}),a};t0.prototype.getPaths=function(t,e,n,c,r){var a=[];return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.push(h)}),a};t0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};t0.prototype.draw=function(t,e,n,c,r,a){this.getPath(e,n,c,r,a).draw(t)};t0.prototype.drawPoints=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawPoints(t,i,o,l)})};t0.prototype.drawMetrics=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawMetrics(t,i,o,l)})};t0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};t0.prototype.validate=function(){var t=this;function e(c,r){}function n(c){var r=t.getEnglishName(c);r&&r.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};t0.prototype.toTables=function(){return Xc.fontToTable(this)};t0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};t0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),c=new Uint8Array(n),r=0;r<e.length;r++)c[r]=e[r];return n};t0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var c=this.toArrayBuffer();if(Yc())if(window.URL=window.URL||window.webkitURL,window.URL){var r=new DataView(c),a=new Blob([r],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(a),s.download=t;var i=document.createEvent("MouseEvents");i.initEvent("click",!0,!1),s.dispatchEvent(i)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var o=S7(),l=Jc(c);o.writeFileSync(t,l)}};t0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};t0.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};t0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function n8(t,e){var n=JSON.stringify(t),c=256;for(var r in e){var a=parseInt(r);if(!(!a||a<256)){if(JSON.stringify(e[r])===n)return a;c<=a&&(c=a+1)}}return e[c]=t,c}function os(t,e,n){var c=n8(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:c}]}function ls(t,e,n){var c={},r=new f1.Parser(t,e);return c.tag=r.parseTag(),c.minValue=r.parseFixed(),c.defaultValue=r.parseFixed(),c.maxValue=r.parseFixed(),r.skip("uShort",1),c.name=n[r.parseUShort()]||{},c}function hs(t,e,n,c){for(var r=n8(e.name,c),a=[{name:"nameID_"+t,type:"USHORT",value:r},{name:"flags_"+t,type:"USHORT",value:0}],s=0;s<n.length;++s){var i=n[s].tag;a.push({name:"axis_"+t+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return a}function us(t,e,n,c){var r={},a=new f1.Parser(t,e);r.name=c[a.parseUShort()]||{},a.skip("uShort",1),r.coordinates={};for(var s=0;s<n.length;++s)r.coordinates[n[s].tag]=a.parseFixed();return r}function fs(t,e){var n=new n1.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 c=0;c<t.axes.length;c++)n.fields=n.fields.concat(os(c,t.axes[c],e));for(var r=0;r<t.instances.length;r++)n.fields=n.fields.concat(hs(r,t.instances[r],t.axes,e));return n}function ds(t,e,n){var c=new f1.Parser(t,e),r=c.parseULong();k1.argument(r===65536,"Unsupported fvar table version.");var a=c.parseOffset16();c.skip("uShort",1);for(var s=c.parseUShort(),i=c.parseUShort(),o=c.parseUShort(),l=c.parseUShort(),h=[],u=0;u<s;u++)h.push(ls(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,p=0;p<o;p++)f.push(us(t,d+p*l,h,n));return{axes:h,instances:f}}var ps={make:fs,parse:ds},ms=function(){return{coverage:this.parsePointer(O.coverage),attachPoints:this.parseList(O.pointer(O.uShortList))}},gs=function(){var t=this.parseUShort();if(k1.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()}},vs=function(){return this.parseList(O.pointer(gs))},ys=function(){return{coverage:this.parsePointer(O.coverage),ligGlyphs:this.parseList(O.pointer(vs))}},bs=function(){return this.parseUShort(),this.parseList(O.pointer(O.coverage))};function xs(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);k1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var r={version:c,classDef:n.parsePointer(O.classDef),attachList:n.parsePointer(ms),ligCaretList:n.parsePointer(ys),markAttachClassDef:n.parsePointer(O.classDef)};return c>=1.2&&(r.markGlyphSets=n.parsePointer(bs)),r}var Ms={parse:xs},o2=new Array(10);o2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(O.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(O.coverage),values:this.parseValueRecordList()};k1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};o2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();k1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(O.coverage),r=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,pairSets:this.parseList(O.pointer(O.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(O.classDef),i=this.parsePointer(O.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,O.list(l,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}}))}}};o2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};o2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};o2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};o2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};o2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};o2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};o2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function ws(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);return k1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(o2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(o2),variations:n.parseFeatureVariationsList()}}var zs=new Array(10);function ks(t){return new n1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new n1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new n1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new n1.LookupList(t.lookups,zs)}])}var Ss={parse:ws,make:ks};function Ls(t){var e={};t.skip("uShort");var n=t.parseUShort();k1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var c=t.parseUShort();t.skip("uShort",3);for(var r=0;r<c;r+=1){var a=t.parseUShort(),s=t.parseUShort(),i=t.parseShort();e[a+","+s]=i}return e}function As(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 c=t.parseUShort(),r=c&255;if(t.skip("uShort"),r===0){var a=t.parseUShort();t.skip("uShort",3);for(var s=0;s<a;s+=1){var i=t.parseUShort(),o=t.parseUShort(),l=t.parseShort();e[i+","+o]=l}}return e}function Cs(t,e){var n=new f1.Parser(t,e),c=n.parseUShort();if(c===0)return Ls(n);if(c===1)return As(n);throw new Error("Unsupported kern table version ("+c+").")}var Ps={parse:Cs};function Ts(t,e,n,c){for(var r=new f1.Parser(t,e),a=c?r.parseUShort:r.parseULong,s=[],i=0;i<n+1;i+=1){var o=a.call(r);c&&(o*=2),s.push(o)}return s}var Es={parse:Ts};function ht(t,e){for(var n=[],c=12,r=0;r<e;r+=1){var a=f1.getTag(t,c),s=f1.getULong(t,c+4),i=f1.getULong(t,c+8),o=f1.getULong(t,c+12);n.push({tag:a,checksum:s,offset:i,length:o,compression:!1}),c+=16}return n}function Is(t,e){for(var n=[],c=44,r=0;r<e;r+=1){var a=f1.getTag(t,c),s=f1.getULong(t,c+4),i=f1.getULong(t,c+8),o=f1.getULong(t,c+12),l=void 0;i<o?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:i,length:o}),c+=20}return n}function d0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),c=new Uint8Array(e.length);if(S9(n,c),c.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var r=new DataView(c.buffer,0);return{data:r,offset:0}}else return{data:t,offset:e.offset}}function c8(t,e){e=e??{};var n,c,r=new t0({empty:!0}),a=new DataView(t,0),s,i=[],o=f1.getTag(a,0);if(o==="\0\0\0"||o==="true"||o==="typ1")r.outlinesFormat="truetype",s=f1.getUShort(a,4),i=ht(a,s);else if(o==="OTTO")r.outlinesFormat="cff",s=f1.getUShort(a,4),i=ht(a,s);else if(o==="wOFF"){var l=f1.getTag(a,4);if(l==="\0\0\0")r.outlinesFormat="truetype";else if(l==="OTTO")r.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+o);s=f1.getUShort(a,12),i=Is(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,p,m,g,v,y,b,x,M,w=0;w<s;w+=1){var k=i[w],z=void 0;switch(k.tag){case"cmap":z=d0(a,k),r.tables.cmap=bt.parse(z.data,z.offset),r.encoding=new Mt(r.tables.cmap);break;case"cvt ":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.cvt=M.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.fpgm=M.parseByteList(k.length);break;case"head":z=d0(a,k),r.tables.head=Et.parse(z.data,z.offset),r.unitsPerEm=r.tables.head.unitsPerEm,n=r.tables.head.indexToLocFormat;break;case"hhea":z=d0(a,k),r.tables.hhea=It.parse(z.data,z.offset),r.ascender=r.tables.hhea.ascender,r.descender=r.tables.hhea.descender,r.numberOfHMetrics=r.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":z=d0(a,k),c=Ht.parse(z.data,z.offset);break;case"maxp":z=d0(a,k),r.tables.maxp=Ot.parse(z.data,z.offset),r.numGlyphs=r.tables.maxp.numGlyphs;break;case"name":b=k;break;case"OS/2":z=d0(a,k),r.tables.os2=Fe.parse(z.data,z.offset);break;case"post":z=d0(a,k),r.tables.post=Nt.parse(z.data,z.offset),r.glyphNames=new Be(r.tables.post);break;case"prep":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.prep=M.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":y=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":p=k;break;case"GSUB":m=k;break;case"meta":x=k;break}}var S=d0(a,b);if(r.tables.name=qt.parse(S.data,S.offset,c),r.names=r.tables.name,f&&y){var L=n===0,I=d0(a,y),q=Es.parse(I.data,I.offset,r.numGlyphs,L),R=d0(a,f);r.glyphs=Xt.parse(R.data,R.offset,q,r,e)}else if(h){var N=d0(a,h);Tt.parse(N.data,N.offset,r,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var G=d0(a,g);if(Vt.parse(r,G.data,G.offset,r.numberOfHMetrics,r.numGlyphs,r.glyphs,e),j9(r,e),v){var V=d0(a,v);r.kerningPairs=Ps.parse(V.data,V.offset)}else r.kerningPairs={};if(d){var J=d0(a,d);r.tables.gdef=Ms.parse(J.data,J.offset)}if(p){var o1=d0(a,p);r.tables.gpos=Ss.parse(o1.data,o1.offset),r.position.init()}if(m){var Z=d0(a,m);r.tables.gsub=Ut.parse(Z.data,Z.offset)}if(u){var p1=d0(a,u);r.tables.fvar=ps.parse(p1.data,p1.offset,r.names)}if(x){var E=d0(a,x);r.tables.meta=Bt.parse(E.data,E.offset),r.metas=r.tables.meta}return r}var x4=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 c=this.parsed.get(n);if(c)return c;let r=G0(this.sources,n);if(!r)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let a=r instanceof Uint8Array?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r,s=c8(a);return this.parsed.set(n,s),s}};function Vs(t,e,n){let c={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,c).commands,advance:t.getAdvanceWidth(e,n.size,c)};let r=[],a=0,s=[...e];return s.forEach((i,o)=>{r.push(...t.getPath(i,a,0,n.size,c).commands),a+=t.getAdvanceWidth(i,n.size,c)*(o<s.length-1?n.spacing:1)}),{cmds:r,advance:a}}function r8(t,e,n){let{cmds:c,advance:r}=Vs(t,e,n),a=c.map(i=>i.type==="Z"?i:i.type==="C"?{...i,y1:-i.y1,y2:-i.y2,y:-i.y}:i.type==="Q"?{...i,y1:-i.y1,y:-i.y}:{...i,y:-i.y}),s=T3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:r}}function M4(t,e,n){if(!e)return[];let c=t.get(n.font),{polys:r,advance:a}=r8(c,e,n),s=x1(r),i=S0(s);if(!i)return[];let o=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-i[3]:n.valign==="center"?-(i[1]+i[3])/2:n.valign==="bottom"?-i[1]:0;return s.map(h=>h.map(([u,f])=>[u+o,f+l]))}function Ye(t,e,n){let c=t.get(n.font),{polys:r,advance:a}=r8(c,e,n),s=S0(r)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:c.ascender/c.unitsPerEm*n.size,descent:c.descender/c.unitsPerEm*n.size}}var Je=128,w4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],s8={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Hs(t,e){if(!t||G0(e6,t)!==void 0||e.startsWith("/"))return;let n=t.lastIndexOf("/");if(n<0)return;let c=[...t.slice(0,n).split("/"),...e.split("/")],r=[];for(let a of c)a===".."&&r.length&&r[r.length-1]!==".."?r.pop():a!=="."&&a!==""&&r.push(a);return(t.startsWith("/")?"/":"")+r.join("/")}var Os=100,Rs={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},$3=4,a8=8,Fs=t=>{let e=Os,n=c=>{for(let r of c.values()){for(let a of r.regions)e+=a.length;for(let a of r.lines)e+=a.length}};n(t.layers);for(let c of t.parts)n(c.layers);return e},T0=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,c=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=c?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let c=n.fns.get(e);if(c)return c}}mod(e){for(let n=this;n;n=n.parent){let c=n.mods.get(e);if(c)return c}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let c=this;c;c=c.parent)n.push(...c[e].keys());return n}},Ke=t=>t?`.${t}`:"",Qe=["echo","assert","text_width","text_metrics","finger_count"];function l3(t,e){let n="",c=Math.min(2,Math.floor(t.length/3))+.5;for(let r of new Set(e)){if(r===t)continue;let a=r.toLowerCase()===t.toLowerCase()?0:$s(t,r);a<c&&([n,c]=[r,a])}return n?` Did you mean "${n}"?`:""}function $s(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(c,r)=>[r,...Array(e.length).fill(0)]);for(let c=1;c<=e.length;c++)n[0][c]=c;for(let c=1;c<=t.length;c++)for(let r=1;r<=e.length;r++)n[c][r]=Math.min(n[c-1][r]+1,n[c][r-1]+1,n[c-1][r-1]+(t[c-1]===e[r-1]?0:1)),c>1&&r>1&&t[c-1]===e[r-2]&&t[c-2]===e[r-1]&&(n[c][r]=Math.min(n[c][r],n[c-2][r-2]+1));return n[t.length][e.length]}var e6=y5,D3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.pointCount=0;this.itemCount=0;this.copies=0;this.frame=he;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(w4.map(e=>[e.name,e]));this.loaded=new Map;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...s8,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new T0,c={$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[i,o]of Object.entries(c))n.vars.set(i,o);let r=new T0(n),a=this.block(e.body,r,!0),s=r.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==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:a,globals:r,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,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?`,e)}load(e,n){let c=Hs(n.file,e),r=e,a=G0(e6,e);if(a===void 0&&c!==void 0){let i=this.loaded.get(c);if(i)return i;a=this.opts.resolve?.(c),typeof a=="string"&&(r=c)}if(r===e){let i=this.loaded.get(e);if(i)return i;a??(a=this.opts.resolve?.(e))}if(typeof a!="string")throw new i1(`Library <${e}> not found`,n);this.loaded.set(r,{body:[]});let{program:s}=a2(a,r);return this.loaded.set(r,s),s}hoist(e,n){for(let c of e)if((c.kind==="module"||c.kind==="function")&&(c.pos.file===void 0||G0(e6,c.pos.file)===void 0)&&(c.kind==="module"?G0(this.builtins,c.name)!==void 0:G0(f5,c.name)!==void 0||Qe.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${T2(c.pos,!1)})`),c.kind==="module")n.mods.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="function")n.fns.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="use"&&!c.include){this.enter(this.using,c.path,c.pos,"use");try{let r=this.included(this.load(c.path,c.pos).body,new Set([c.path])),a=new T0(n);this.hoist(r,a);for(let s of r)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,i]of a.mods)n.mods.set(s,i);for(let[s,i]of a.fns)n.fns.set(s,i)}finally{this.using.pop()}}}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 r=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,i=[];for(let l=r.length-1;l>=0;l--)i.push({text:";"},r[l][1],{text:`${r[l][0]}=`});for(;i.length;){if(s>2e4)return"";let l=i.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)){i.push({text:"]"});for(let u=l.length-1;u>=0;u--)i.push(l[u],{text:","});h="["}else if(Q0(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(F0(l)){i.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)i.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";a.push(h),s+=h.length}let o=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies}`}enter(e,n,c,r){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new i1(a.length===2?`Library ${a[0]} ${r}s itself`:`Libraries ${r} each other in a loop: ${a.join(" \u2192 ")}`,c)}e.push(n)}included(e,n){let c=[];for(let r of e)if(r.kind!=="use"||!r.include)c.push(r);else if(!n.has(r.path)){n.add(r.path);for(let a of this.included(this.load(r.path,r.pos).body,n))c.push(a)}return c}assign(e,n,c){c.vars.set(e,n)}block(e,n,c=!1){this.hoist(e,n);let r=[];for(let a of e){let s=this.stmt(a,n,c);s&&!G6(s)&&r.push(s)}return r.length===1?r[0]:q2(r)}stmt(e,n,c=!1){switch(this.tick(e.pos),e.kind){case"assign":{let r=this.opts.overrides,a=c&&r&&Object.prototype.hasOwnProperty.call(r,e.name)?r[e.name]:this.expr(e.value,n);return this.assign(e.name,a,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 T0(n));case"if":return h0(this.expr(e.cond,n))?this.block(e.then,new T0(n)):this.block(e.else,new T0(n));case"let":{let r=new T0(n);return this.bindSeq(e.assigns,r),this.block(e.body,r)}case"for":{let r=[];return this.loop(e.assigns,n,a=>r.push(this.block(e.body,a))),q2(r)}case"call":if(e.modifier==="*")return null;{let r=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?o5(r,"guide"):r}}}bindSeq(e,n){for(let c of e)this.assign(c.name,this.expr(c.value,n),n)}iterable(e,n){if(Q0(e))try{return n4(e,this.limits.maxListLength)}catch(c){throw new i1(c.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,c,r=0,a=new T0(n)){if(r===e.length)return c(a);let s=e[r];for(let i of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let o=new T0(a);o.vars.set(s.name,i),this.loop(e,n,c,r+1,o)}}evalArgs(e,n,c){let r=[],a=new Map,s=[];for(let i of e){let o=this.expr(i.value,n);i.name===null?r.push(o):a.set(i.name,o),s.push({name:i.name,value:o})}return{pos:r,named:a,all:s,at:c}}bindParams(e,n,c,r,a){let s=e.map(i=>i.name);e.forEach((i,o)=>{let l;n.named.has(i.name)?l=n.named.get(i.name):o<n.pos.length?l=n.pos[o]:l=i.default?this.expr(i.default,c):void 0,c.vars.set(i.name,l)});for(let i of n.named.keys())i.startsWith("$")?c.vars.set(i,n.named.get(i)):s.includes(i)||this.unknownArg(a,i,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let c=v5(e);if(!c)return;let r=c.params.map(a=>a.name);if(!c.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!r.includes(a)&&this.unknownArg(`${e}()`,a,n.at,r);c.rest||this.checkCount(`${e}()`,c.params.filter(a=>!a.named).length,n)}checkCount(e,n,c){c.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${c.pos.length}; the rest are ignored (${T2(c.at,!1)})`)}unknownArg(e,n,c,r){this.warn(`${e}: unknown argument "${n}"${Ke(l3(n,r))} (${T2(c,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let c=e.args.findIndex(s=>s.name==="name"),r=c>=0?c:e.args.findIndex(s=>s.name===null);if(r<0)throw new i1("call() needs the name of a module",e.pos);let a=this.expr(e.args[r].value,n);if(typeof a!="string")throw new i1(`call() needs a module's name as a string, got ${j0(a)}`,e.pos);if(a==="call")throw new i1("call() can't call itself",e.pos);return this.callModule({...e,name:a,args:e.args.filter((s,i)=>i!==r)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let c=this.evalArgs(e.args,n,e.pos),r=n.mod(e.name);if(r){if(++this.depth>1e3)throw new i1(`Recursion too deep in module ${e.name}(): it calls itself without stopping`,e.pos);try{let f=new T0(r.env,n);return this.bindParams(r.params,c,f,r.env,`${e.name}()`),f.children={stmts:e.children,env:n},f.vars.set("$children",this.childStmts(e.children).length),this.block(r.body,f)}catch(f){throw this.inCall(f,"module",e.name,e.pos)}finally{this.depth--}}let a=G0(this.builtins,e.name);if(!a){let f=e.name==="color"?" Use layer(), cut(), score() or engrave() instead.":l3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new i1(`Unknown module ${e.name}().${f}`,e.pos)}this.checkArgs(e.name,c);let s=new T0(n,n);for(let[f,d]of c.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new T0(n,s),l={args:c,env:s,children:()=>e.children.length?this.block(e.children,o()):J0(),childList:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let p of e.children){let m=this.stmt(p,f);i.includes(p)&&d.push(m??J0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let p=[];for(let m of e.children){let g=this.stmt(m,d);i.includes(m)&&(p.push(g??J0()),f(p.length-1,g??J0()))}return p}},h;try{h=a(l)}catch(f){if(f instanceof i1||f instanceof RangeError)throw f;let d=new i1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=Fs(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new i1(u>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 h}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,c,r){if(++this.depth>2e3)throw new i1(`Recursion too deep in ${r}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=P2(e)?e.scope:e.env,s=new T0(a,c);return this.bindParams(e.params,n,s,a,`${r}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",r,n.at)}finally{this.depth--}}inCall(e,n,c,r){return e instanceof Error&&!(e instanceof i1)&&e.message.includes("call stack")?new i1(`Recursion too deep in ${n==="module"?"module ":""}${c}(): it calls itself without stopping`,r):(e instanceof i1&&e.addFrame(n,c,r),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":{let c=n.get(e.name);if(c.found)return c.value;let r=n.fn(e.name);if(r)return{type:"function",params:r.params,body:r.body,scope:r.env,name:e.name};if(e.name.startsWith("$"))return;throw new i1(`Unknown variable "${e.name}"${Ke(l3(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let c=[];for(let r of e.items)this.listItem(r,n,c,e.pos);return this.charge($3,e.pos),c}case"range":{let c=this.expr(e.start,n),r=this.expr(e.end,n),a=e.step?this.expr(e.step,n):1;if(typeof c!="number"||typeof r!="number"||typeof a!="number")throw new i1("Range values must be numbers",e.pos);return{type:"range",start:c,step:a,end:r}}case"unary":{let c=this.expr(e.arg,n);return e.op==="!"?!h0(c):e.op==="+"?c:this.arith("*",-1,c,e.pos)}case"binary":{if(e.op==="&&")return h0(this.expr(e.left,n))&&h0(this.expr(e.right,n));if(e.op==="||")return h0(this.expr(e.left,n))||h0(this.expr(e.right,n));let c=this.expr(e.left,n),r=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return C3(c,r,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof c=="number"&&typeof r=="number"||typeof c=="string"&&typeof r=="string"))throw new i1(`Can't compare ${j0(c)} ${e.op} ${j0(r)}`,e.pos);return e.op==="<"?c<r:e.op==="<="?c<=r:e.op===">"?c>r:c>=r}return this.arith(e.op,c,r,e.pos)}case"ternary":return h0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let c=this.expr(e.target,n),r=this.expr(e.index,n);if(F0(c)&&typeof r=="string")return c.fields.get(r);if(typeof r!="number")throw new i1(`List index must be a number, got ${j0(r)}`,e.pos);return Array.isArray(c)?c[Math.floor(r)]:typeof c=="string"?[...c][Math.floor(r)]:Q0(c)?[c.start,c.step,c.end][Math.floor(r)]:void 0}case"record":return this.record(e,n);case"member":{let c=this.expr(e.target,n);if(F0(c))return c.fields.get(e.name);let r={x:0,y:1,z:2}[e.name];return Array.isArray(c)&&r!==void 0?c[r]:Q0(c)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?c.start:e.name==="step"?c.step:c.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 c=new T0(n);return this.bindSeq(e.assigns,c),this.expr(e.body,c)}}}listItem(e,n,c,r){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(c,1,r),c.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),r);this.grow(c,a.length,r);for(let s of a)c.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,c,r));return;case"if":h0(this.expr(e.cond,n))?this.listItem(e.then,n,c,r):e.else&&this.listItem(e.else,n,c,r);return;case"let":{let a=new T0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,c,r)}}}grow(e,n,c){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}`,c);this.charge(n,c)}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 r=e.callee.name,a=n.get(r),s=a.found&&!P2(a.value);if(!a.found||s&&this.callable(r,n)){let i=n.fn(r);if(i)return this.callFunction(i,this.evalArgs(e.args,n,e.pos),n,r);let o=this.specialFunction(r,e,n);if(o.handled)return o.value;let l=G0(f5,r);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(r,h);for(let p of g7(l,h.pos,h.named))this.warn(`${r}(): "${p}" is given by position and by name; the named value is used (${T2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:p=>this.tick(e.pos,p),given:h.pos.length+l.params.filter(p=>h.named.has(p)).length},f=v7(l,h.pos,h.named);this.tick(e.pos,y7(r,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(p){if(p instanceof i1)throw p;let m=new i1(p instanceof RangeError?`${r}(): the result is too large`:p.message,e.pos);throw m.call=r,m}return this.checkValue(d,e.pos,r),d}throw new i1(`Unknown function ${r}()${Ke(l3(r,[...n.names("fns"),...n.names("vars"),...Object.keys(f5),...Qe]))}`,e.pos)}if(!P2(a.value))throw new i1(`"${r}" is a ${j0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,r)}let c=this.expr(e.callee,n);if(!P2(c))throw new i1(`Can't call a ${j0(c)}`,e.pos);return this.callFunction(c,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,c,r){let a=s=>Array.isArray(c)?String(c[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let i=a(s),o=x1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||b0(n[s],o).reduce((h,u)=>h+Math.abs(H1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(c)&&i?` "${i}"`:""} under it, so it can't be seen (${T2(r,!1)})`)}}record(e,n){let c=new Map;for(let r of e.fields)c.set(r.name,this.expr(r.value,n));return{type:"record",fields:c}}length(e,n){let c=A0(n.get("$scale").value??1);if(!(c>0))throw new i1("$scale must be a number more than 0",e.pos);return c===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Rs[e.unit]/c}callable(e,n){return!!n.fn(e)||Qe.includes(e)||!!G0(f5,e)}specialFunction(e,n,c){if(e==="echo"){let r=this.evalArgs(n.args,c,n.pos);return this.echo(this.echoText(r),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let r=this.evalArgs(n.args,c,n.pos);return this.checkArgs(e,r),this.assert(r),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"){let r=this.evalArgs(n.args,c,n.pos);this.checkArgs(e,r);let a=this.measure(r,c);return e==="text_width"?{handled:!0,value:a.advance}:{handled:!0,value:[a.advance,a.bounds,a.ascent,a.descent]}}if(e==="finger_count"){let r=this.evalArgs(n.args,c,n.pos);this.checkArgs(e,r);let a=this.num(this.arg(r,"length",0),"finger_count","length");return{handled:!0,value:c3(a,this.fingerWidth(r,c,1))}}return{handled:!1}}assert(e){if(h0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new i1(`Assertion failed${n===void 0?"":": "+g0(n)}`,e.at)}echo(e,n){this.charge(Math.ceil(e.length/a8),n),this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,c=[],r=0,a=(s,i,o)=>{c.length&&(r+=2);let l=P3(i,n-r-s.length,o);if(r+=s.length+l.text.length,!l.whole)throw new i1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);c.push(s+l.text)};for(let{name:s,value:i}of e.all)s===null?a("",i,!1):a(`${s} = `,i,!0);return c.join(", ")}arith(e,n,c,r){if(typeof n=="number"&&typeof c=="number")switch(e){case"+":return n+c;case"-":return n-c;case"*":return n*c;case"/":return n/c;case"%":return n%c;case"^":return Math.pow(n,c)}if(e==="+"&&typeof n=="string"&&typeof c=="string")return this.checkSize(n.length+c.length,!0,r),n+c;if(Array.isArray(n)&&Array.isArray(c)){if(e==="+"||e==="-"){if(n.length!==c.length)throw new i1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${c.length}`,r);return this.charge(n.length+$3,r),n.map((s,i)=>this.arith(e,s,c[i],r))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+$3,r),n.map(i=>this.arith("*",i,c,r));let s=(i,o)=>{let l=this.arith("*",i,o,r);if(typeof l!="number")throw new i1("Can't multiply these lists: an item times an item is not a number",r);return l};if(Array.isArray(c[0])){let i=c[0].length;if(n.length!==c.length||c.some(o=>!Array.isArray(o)||o.length!==i))throw new i1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,r);return this.checkSize(i,!1,r),this.tick(r,i*n.length),Array.from({length:i},(o,l)=>n.reduce((h,u,f)=>h+s(u,c[f][l]),0))}if(n.length!==c.length)throw new i1(`Can't multiply lists of length ${n.length} and ${c.length}`,r);return this.tick(r,n.length),n.reduce((i,o,l)=>i+s(o,c[l]),0)}}if(Array.isArray(n)&&typeof c=="number"&&(e==="*"||e==="/"))return this.charge(n.length+$3,r),n.map(s=>this.arith(e,s,c,r));if(typeof n=="number"&&Array.isArray(c)&&e==="*")return this.charge(c.length+$3,r),c.map(s=>this.arith(e,n,s,r));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new i1(`Can't ${a[e]??e} ${j0(n)} and ${j0(c)}`,r)}arg(e,n,c,r){return e.named.has(n)?e.named.get(n):c>=0&&c<e.pos.length?e.pos[c]:r}num(e,n,c){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${c} must be a finite number, got ${q0(e)}`);return e}vec2(e,n,c=!0){let r=a=>typeof a=="number"&&Number.isFinite(a);if(r(e)&&c)return[e,e];if(Array.isArray(e)&&r(e[0])&&(e[1]===void 0||r(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${q0(e)}`)}vec3(e,n){let c=r=>typeof r=="number"&&Number.isFinite(r);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(c))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${q0(e)}`)}placements(e,n,c){let r=(i,o)=>i===void 0?[[0,0,0]]:Array.isArray(i)&&i.length>0&&Array.isArray(i[0])?i.map((l,h)=>this.vec3(l,`${o}[${h}]`)):[this.vec3(i,o)],a=r(e,"at"),s=r(n,"rotate");for(let[i,o]of[[a,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==c)throw new Error(`${o} needs one placement per copy: qty is ${c} but ${o} has ${i.length}`);return Array.from({length:c},(i,o)=>({at:a[a.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((c,r)=>{if(!Array.isArray(c)||!Number.isFinite(c[0])||!Number.isFinite(c[1]))throw new Error(`${n}[${r}] must be an [x, y] point, got ${q0(c)}`);return[c[0],c[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,c){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,c)}checkSize(e,n,c,r){if(e>this.limits.maxListLength)throw new i1(`${r?`${r}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,c);this.charge(n?Math.ceil(e/a8):e+$3,c)}segs(e){let n=A0(this.dyn(e,"$fn"))||0,c=A0(this.dyn(e,"$fa"))||2,r=A0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let i=Z6(s,n,c,r);if(!(i<=a))throw new Error(`a circle with ${i} segments is more than the limit of ${a}. Lower $fn, or raise $fa or $fs.`);return i}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||n<=0)throw new Error("$thickness must be a positive number");return n}fingerWidth(e,n,c){let r=this.arg(e,"finger",c);return typeof r=="number"&&r>0?r: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 c=P3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!c.whole)throw new i1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,c.text.length);try{return Ye(this.opts.fonts,c.text,this.textOpts(e,n,c.text))}catch(r){throw r instanceof i1?r:new i1(r.message,e.at)}}textOpts(e,n,c){let r={size:this.num(this.arg(e,"size",1,10),"text","size"),font:g0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:g0(this.arg(e,"halign",-1,"left")),valign:g0(this.arg(e,"valign",-1,"baseline")),spacing:A0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&c!==void 0&&this.opts.fonts){let s=this.num(a,"text","fit");if(!(s>0))throw new Error("fit must be a width more than 0");let i=Ye(this.opts.fonts,c,{...r,size:1}).advance;if(i>0){let o=this.arg(e,"size",1);r.size=o===void 0?s/i:Math.min(r.size,s/i)}}return r}edges(e){let n=c=>{if(c==="out"||c==="in"||c==="flat")return c;throw new Error(`edges must be "out", "in" or "flat", got ${q0(c)}`)};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`,c=this.layers.get(n);if(c&&c.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(!c){let r=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...r,name:n,side:"back"})}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((c,r)=>{if(!Array.isArray(c)||c.length!==3||!c.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${q0(c)}${n.length>1?` at ${r}`:""}`);let[a,s,i]=c;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${q0(c)}`);return{x0:a,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>z3(s.children(),i),n=s=>i=>o5(i.children(),s),c=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${q0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!h0(this.dyn(i.env,"$mirrored"))),o5(i.children(),o==="back"?this.backLayer(s):s)};return{rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0,1),"size"),l=A0(this.arg(s.args,"r",-1,0))||0,h=h0(this.arg(s.args,"center",1,!1)),u=Y6(i,o,l,this.segs(s.env));return k0(x1([h?u.map(([f,d])=>[f-i/2,d-o/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let i=this.arg(s.args,"d",-1),o=i!==void 0?this.num(i,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return k0([k3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return k0([k3(i,o,this.segs(s.env)(Math.max(i,o)))])},regular_polygon:s=>{let i=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),o=this.num(this.arg(s.args,"r",1,10),"regular_polygon","r");if(!(i<=this.limits.maxSegments))throw new Error(`${i} corners is more than the limit of ${this.limits.maxSegments}`);return k0([k3(o,o,i)])},star:s=>{let i=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),o=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.args,"inner",2,o*.45),"star","inner");if(!(i*2<=this.limits.maxSegments))throw new Error(`${i} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<i*2;u++){let f=Math.PI/2+Math.PI*u/i,d=u%2?l:o;h.push([d*Math.cos(f),d*Math.sin(f)])}return k0(x1([h]))},polygon:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"paths",1),l=Array.isArray(o)?o.map(h=>(Array.isArray(h)?h:[]).map(u=>i[A0(u)]).filter(Boolean)):[i];return k0(x1(l,"evenodd"))},path:s=>{let i=this.arg(s.args,"d",0);if(typeof i!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let o=T3(E3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return h0(this.arg(s.args,"close",-1,!1))?k0(x1([...o.closed,...o.open.filter(h=>h.length>2)],l)):q2([k0(x1(o.closed,l)),D2(o.open)])},line:s=>{let i=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),o=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return D2([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!u)return J0();let f=-(o[1]-i[1])/u*(h/2),d=(o[0]-i[0])/u*(h/2);return k0(x1([[[i[0]+f,i[1]+d],[i[0]-f,i[1]-d],[o[0]-f,o[1]-d],[o[0]+f,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=h0(this.arg(s.args,"closed",1,!1));return D2([o&&i.length?[...i,i[0]]:i])},arc:s=>{let i=this.num(this.arg(s.args,"r",0,10),"arc","r"),o=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.env)(i)*Math.abs(l-o)/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=(o+(l-o)*f/h)*Math.PI/180;u.push([i*Math.cos(d),i*Math.sin(d)])}return D2([u])},text:s=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let i=this.arg(s.args,"text",0,""),o=P3(i,this.limits.maxTextLength);if(!o.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(s.args.at,o.text.length);let l=M4(this.opts.fonts,o.text,this.textOpts(s.args,s.env,o.text));if(h0(this.dyn(s.env,"$mirrored"))){let[h,u]=[1/0,-1/0];for(let f of l)for(let[d]of f)[h,u]=[Math.min(h,d),Math.max(u,d)];return k0(x1(l.map(f=>f.map(([d,p])=>[h+u-d,p]))))}return k0(l)},translate:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,i,o])},rotate:s=>{let i=this.arg(s.args,"a",0,0),l=(Array.isArray(i)?A0(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[p,m]=this.vec2(f,"center",!1);d=[h,u,-u,h,p-h*p+u*m,m-u*p-h*m]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,u=o/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let i=this.arg(s.args,"m",0);if(!Array.isArray(i)||i.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let o=i[0],l=i[1];return e(s,[o[0],l[0],o[1],l[1],o[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[i,...o]=s.childList();if(!i)return J0();let l=r(o,"difference");return a(i,h=>({regions:b0(h.regions,l.regions),lines:v2(h.lines,x1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return J0();let o=p=>[...p.layers.values()].some(m=>m.regions.length),l=p=>{let m;for(let g of i){if(g===p||!o(g))continue;let v=x1(r([g],"intersection").regions);m=m?x0(m,v):v}return m},h=i[0],u=i.every(o),f=l(h),d=a(h,p=>({regions:u?f?x0(p.regions,f):p.regions:[],lines:f?v2(p.lines,f,"inside"):p.lines}));for(let p of i){if(p===h)continue;if(p.parts.length)throw new Error("part() can only be the first child of intersection()");let m=l(p),g=new Map;for(let[v,y]of p.layers)y.lines.length&&g.set(v,{regions:[],lines:m?v2(y.lines,m,"inside"):y.lines});g.size&&(d=q2([d,{layers:g,parts:[]}]))}return d},hull:s=>{let i=s.children(),o=l=>{let h=[],u="cut",f=!0;for(let[p,m]of l){f&&(m.regions.length||m.lines.length)&&(u=p,f=!1);for(let g of[...m.regions,...m.lines])for(let v of g)h.push(v)}let d=X6(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:o(i.layers),parts:i.parts.map(l=>({...l,layers:o(l.layers)}))}},offset:s=>{let i=this.arg(s.args,"r",0),o=this.arg(s.args,"delta",-1),l=h0(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),u=i!==void 0?"round":l?"square":"miter";return a(s.children(),f=>({regions:m0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[i,o]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(i>0&&o>0))throw new Error("spacing must be more than 0");let[h,...u]=s.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=x1(r(u,"pattern").regions),d=D0(h.layers),p=S0(f);if(!d||!p)return J0();let m=Math.floor((p[1]-d[3])/o),g=Math.ceil((p[3]-d[1])/o),v=Math.floor((p[0]-d[2])/i)-1,y=Math.ceil((p[2]-d[0])/i)+1,b=(g-m+1)*(y-v+1);if(!(b<=this.limits.maxParts*10))throw new Error(`the pattern would have ${b} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(s.args.at,b);let x=_0(f).map(S=>({polys:S,box:S0(S)})),M=f,w=(S,L)=>{let I=0;for(let q of M)for(let R=0,N=q.length-1;R<q.length;N=R++){let[G,V]=q[N],[J,o1]=q[R];V<=L?o1>L&&(J-G)*(L-V)-(S-G)*(o1-V)>0&&I++:o1<=L&&(J-G)*(L-V)-(S-G)*(o1-V)<0&&I--}return I!==0},k=new Map,z=(S,L)=>{let I=k.get(S)??{regions:[],lines:[]};for(let q of L.regions)I.regions.push(q);for(let q of L.lines)I.lines.push(q);k.set(S,I)};for(let S=m;S<=g;S++)for(let L=v;L<=y;L++){let I=L*i+(S%2?l*i:0),q=S*o,R=[d[0]+I,d[1]+q,d[2]+I,d[3]+q];if(R[2]<p[0]||R[0]>p[2]||R[3]<p[1]||R[1]>p[3])continue;let N=x.filter(Z=>!(R[2]<Z.box[0]||R[0]>Z.box[2]||R[3]<Z.box[1]||R[1]>Z.box[3]));if(!N.length)continue;M=N.length===x.length?f:N.flatMap(Z=>Z.polys);let G=[w(R[0],R[1]),w(R[2],R[1]),w(R[2],R[3]),w(R[0],R[3])],V=M.some(Z=>Z.some(([p1,E])=>p1>R[0]&&p1<R[2]&&E>R[1]&&E<R[3])),J=G.every(Boolean)&&!V,o1=[1,0,0,1,I,q];for(let[Z,p1]of z3({layers:h.layers,parts:[]},o1).layers)z(Z,J?p1:{regions:x0(p1.regions,M),lines:v2(p1.lines,M,"inside")})}return{layers:k,parts:[]}},spline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=h0(this.arg(s.args,"closed",-1,!1));if(!(i.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=ge(i,l,h);if(o===void 0)return D2([u]);let f=this.num(o,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return k0(x1(X5([u],f)))},hatch:s=>{let i=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),o=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(o>0))throw new Error("pitch must be more than 0");let h=x1(r([s.children()],"hatch").regions),u=S0(h);if(!u)return J0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],p=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,m=i*Math.PI/180,[g,v]=[Math.cos(m),Math.sin(m)],[y,b]=[-v,g],x=Math.ceil(p/o);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let M=[],w=Math.round((f*y+d*b)/o);for(let z=w-x;z<=w+x;z++){let S=z*o-(f*y+d*b),[L,I]=[f+y*S,d+b*S];M.push([[L-g*p,I-v*p],[L+g*p,I+v*p]])}if(l===void 0)return D2(v2(M,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return k0(x0(x1(X5(M,k).map(z=>z)),h))},paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],u=[];for(let f=o.length-1;f>=0;f--){let d=o[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let p=h,m=x1(r([d],"paint").regions);u[f]=m,h=p.length?x1([...p,...m]):m;let g=Array.isArray(i)?i[f]:void 0;g!==""&&(g!==void 0?(this.layers.has(g)||this.layers.set(g,{name:g,mode:"fill",color:"#000000"}),l.push(k0(p.length?b0(m,p):m,g))):l.push(p.length?a(d,v=>({regions:b0(v.regions,p),lines:v2(v.lines,p,"outside")})):d))}return this.invisiblePaint(o,u,i,s.args.at),q2(l.reverse())},measure:s=>{let i=h0(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let u=D0(h.layers)??S0(h.parts.flatMap(g=>[...g.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(g=>g.layers)],d=f.flatMap(g=>g.get("cut")?.regions??[]),p=d.length?d:f.flatMap(g=>[...g].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),m=W6(x1(p));s.env.vars.set("$area",m.area),s.env.vars.set("$centroid",m.area>0?m.centroid:void 0)});return q2(i?o:o.slice(1))},fill_holes:s=>{let i=this.arg(s.args,"min_area",0),o=i===void 0?1/0:this.num(i,"fill_holes","min_area");return a(s.children(),l=>({regions:x1(l.regions).filter(h=>!(H1(h)<0&&-H1(h)<o)),lines:l.lines}))},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),o=>({regions:m0(m0(o.regions,i,"round"),-i,"round"),lines:o.lines}))},stroke:s=>{let i=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),o=>({regions:x1([...o.regions,...X5(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...x1(i.regions).map(o=>[...o,o[0]])]})),cut:n("cut"),score:c("score"),engrave:c("engrave"),guide:n("guide"),layer:s=>{let i=this.arg(s.args,"name",0);if(typeof i!="string"||!i)throw new Error("layer() needs a name");let o=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(i),u=this.arg(s.args,"order",-1),f=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${i}" is the back of layer "${i.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let p=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(p))throw new Error('mode must be "cut", "line", "fill" or "guide"');let m=g0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(m))throw new Error('color must look like "#00aa00"');let g=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&p==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:p,color:m,...g!==void 0&&{order:g},...v!==void 0&&{bleed:v}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${q0(d)}`);if(d==="back"&&this.layers.get(i)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&s.env.vars.set("$mirrored",!h0(this.dyn(s.env,"$mirrored"))),o5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=g0(this.arg(s.args,"name",0,"part")),o=Math.max(1,Math.floor(A0(this.arg(s.args,"qty",1,1))||1)),l=this.arg(s.args,"stack",-1),h=l===void 0?1:Math.floor(this.num(l,"part","stack"));if(!(h>=1))throw new Error("stack must be 1 or more");if(this.copies+=o*h,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let u=this.arg(s.args,"at",-1),f=this.arg(s.args,"rotate",-1),d=this.arg(s.args,"glue",-1),p=d===void 0?void 0:g0(d),m=g0(this.arg(s.args,"face",-1,"top"));if(m!=="top"&&m!=="bottom")throw new Error(`face must be "top" or "bottom", got ${q0(m)}`);let g=this.frame!==he&&p===void 0,v=this.arg(s.args,"bend",-1),y=u===void 0&&f===void 0&&!g&&p===void 0&&v===void 0?void 0:this.placements(u,f,o),b=this.arg(s.args,"material",-1);b!==void 0&&s.env.vars.set("$material",g0(b));let x=this.thickness(s.env);y&&(g||h>1)&&(y=y.flatMap(Z=>{let p1=p===void 0?O1(this.frame,K0(Z)):K0(Z),E=p!==void 0&&m==="bottom"?-x:x;return Array.from({length:h},($,X)=>({...Z,matrix:O1(p1,R0(0,0,X*E))}))}));let M=this.arg(s.args,"mirror",-1,!1),w;if(Array.isArray(M)){if(M.length!==o)throw new Error(`mirror needs one true or false per copy: qty is ${o} but mirror has ${M.length}`);w=M.map(Z=>h0(Z))}else w=Array.from({length:o},()=>h0(M));let k=w.some(Z=>Z)&&!w.every(Z=>Z);if(k&&p!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let z=w[0],S=Z=>{let p1=s.env.vars.get("$mirrored"),E=s.env.vars.has("$mirrored");Z&&s.env.vars.set("$mirrored",!0);try{let $=s.children();return Z?z3($,[-1,0,0,1,0,0]):$}finally{Z&&(E?s.env.vars.set("$mirrored",p1):s.env.vars.delete("$mirrored"))}},L=S(z),I=this.bends(v),q=this.arg(s.args,"on",-1),R=this.arg(s.args,"slots",-1),N=R===void 0?void 0:(Array.isArray(R)?R:[R]).map(Z=>{if(typeof Z!="string")throw new Error("slots must be part names");return Z}),G=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),V=(Z,p1,E)=>{let $=E.length===o,X=y?.filter((j,w1)=>E.includes(Math.floor(w1/h)+1));return{name:i,qty:E.length*h,layers:Z,thickness:x,kerf:A0(this.dyn(s.env,"$kerf"))||0,material:g0(this.dyn(s.env,"$material")??"material"),...X?{placements:X}:{},...h>1?{stack:h}:{},...I.length?{bends:I}:{},...q!==void 0?{on:g0(q)}:{},...N?{slots:N,clearance:G}:{},...this.step?{step:this.step}:{},...p!==void 0&&{glue:{host:p,face:m}},...p1&&{mirrored:!0},...!$&&{copies:E}}},J=Z=>w.flatMap((p1,E)=>p1===Z?[E+1]:[]),o1=k?[V(L.layers,z,J(z)),V(S(!z).layers,!z,J(!z))]:[V(L.layers,z,J(z))];return{layers:new Map,parts:[...L.parts,...o1]}},place:s=>{let i=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),o=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=O1(l,K0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=g0(this.arg(s.args,"text",0,"")),o=h0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.children();let l=this.step,h=l&&i?`${this.stepNames[l-1]}: ${i}`:i,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=g0(this.arg(s.args,"kind",0,"dowel"));G0(I3,i)===void 0&&G0(m5,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${T2(s.args.at,!1)})${l3(i,Object.keys(I3))}`);let o=g0(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${q0(o)}`);let l=this.arg(s.args,"sides",-1),h=o==="ball"||l===0,u=this.vec3(this.arg(s.args,"from",1),"from"),f=this.arg(s.args,"to",2),d=h&&f===void 0?u:this.vec3(f,"to"),p=this.arg(s.args,"size",3,6),m=typeof p=="number"?p:this.vec2(p,"size",!1);if(h){if(typeof m!="number"||!(m>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let g=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(g[2])>.9*Math.hypot(...g),y=this.arg(s.args,"up",-1),b=y===void 0?v?[0,1,0]:[0,0,1]:this.vec3(y,"up"),x=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(x>=3&&x<=Je))throw new Error(`sides must be from 3 to ${Je} (or 0 for a ball), got ${q0(x)}`);if(this.pointCount+=h?2*Je:x*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 M=this.arg(s.args,"label",-1),w=this.frame,k=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2]+w[3],w[4]*S[0]+w[5]*S[1]+w[6]*S[2]+w[7],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]+w[11]],z=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2],w[4]*S[0]+w[5]*S[1]+w[6]*S[2],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:i,from:k(u),to:k(d),size:m,up:z(b),sides:x,step:this.step,...M!==void 0?{label:g0(M)}:{}}),s.children()},material:s=>{let i=this.arg(s.args,"thickness",0),o=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return i!==void 0&&s.env.vars.set("$thickness",this.num(i,"material","thickness")),o!==void 0&&s.env.vars.set("$kerf",this.num(o,"material","kerf")),l!==void 0&&s.env.vars.set("$material",g0(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return J0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new T0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(m=>u.add(m));else for(let m of this.iterable(l,s.args.at))o[A0(m)]&&u.add(o[A0(m)]);let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let p=this.childKey(h);for(let m of i.stmts)if(m.kind==="assign")this.stmt(m,h);else if(u.has(m)){let g=p&&d.get(m);if(g&&g.key===p){g.shape&&f.push(g.shape);continue}let v=this.effects(),y=this.stmt(m,h);y&&f.push(y),p&&this.effects()===v&&!y?.parts.length&&d.set(m,{key:p,shape:y})}return q2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/u*4),k0(c4(i,o,l,h,u))},finger_holes:s=>{let i=this.num(this.arg(s.args,"length",0),"finger_holes","length"),o=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(o==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(i)/l*4),k0(b7(i,o,this.thickness(s.env),l))},tslot:s=>{let i=this.num(this.arg(s.args,"d",0,3),"tslot","d"),o=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[i*1.85,i*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return k0(x1(x7(i,o,l,h,u)))},living_hinge:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.num(this.arg(s.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(s.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(o-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(i)/l+1)*(Math.abs(o)/(u+h)+2)*2),D2(M7(i,o,l,h,u))}};function r(s,i){let o={regions:[],lines:[]};for(let l of s){if(l.parts.length)throw new Error(`part() can only be the first child of ${i}()`);for(let h of l.layers.values())for(let u of h.regions)o.regions.push(u)}return o}function a(s,i){let o=l=>{let h=new Map;for(let[u,f]of l)h.set(u,i(f));return h};return{layers:o(s.layers),parts:s.parts.map(l=>({...l,layers:o(l.layers)}))}}}};var q3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},t6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function n6(t,e){let n=[];for(let[c,r]of t){let a=[q3(c),q3(r)],s=n[n.length-1];(!s||s[0]!==a[0]||s[1]!==a[1])&&n.push(a)}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 N3=(t,e)=>`M${n6(t,e).map(([n,c])=>`${n} ${c}`).join("L")}${e?"Z":""}`;function z4(t,e){let n=[];for(let c of e){let r=[],a=[],s=[];for(let i of t){let o=i.layers.get(c.name);if(o){for(let l of o.lines)r.push(N3(l,!1));for(let l of o.regions)(H1(l)<0?a:s).push(N3(l,!0))}}(r.length||a.length||s.length)&&n.push({name:c.name,mode:c.mode,color:c.color,d:[...r,...a,...s].join(""),regions:[...a,...s].join(""),lines:r.join("")})}return n}function k4(t,e,n,c){let r=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${q3(e)}mm" height="${q3(n)}mm" viewBox="0 0 ${q3(e)} ${q3(n)}">`];for(let a of c){let s=[],i=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${t6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>N3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${N3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${N3(f,!1)}"/>`);for(let f of h.regions)(H1(f)<0?s:i).push(`<path${u} d="${N3(f,!0)}"/>`)}if(!s.length&&!i.length)continue;let o=a.mode==="fill"?`fill="${a.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${a.color}" stroke-width="0.1"${a.mode==="guide"?' stroke-dasharray="1 1"':""}`;r.push(`<g id="${t6(a.name)}" inkscape:groupmode="layer" inkscape:label="${t6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return r.push("</svg>",""),r.join(`
|
|
2564
|
-
`)}var
|
|
3021
|
+
`};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},r=Object.defineProperty,c=r(n,n,n)&&r}catch{}return c})(),e=function(n){if(this==null)throw TypeError();var r=String(this),c=r.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=c)){var s=r.charCodeAt(a),o;return s>=55296&&s<=56319&&c>a+1&&(o=r.charCodeAt(a+1),o>=56320&&o<=57343)?(s-55296)*1024+o-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var mt=0,y7=-3;function D5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function _r(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new D5,this.dtree=new D5}var b7=new D5,x7=new D5,pt=new Uint8Array(30),gt=new Uint16Array(30),M7=new Uint8Array(30),w7=new Uint16Array(30),jr=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Vn=new D5,P2=new Uint8Array(320);function k7(t,e,n,r){var c,a;for(c=0;c<n;++c)t[c]=0;for(c=0;c<30-n;++c)t[c+n]=c/n|0;for(a=r,c=0;c<30;++c)e[c]=a,a+=1<<t[c]}function Gr(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 Hn=new Uint16Array(16);function Y4(t,e,n,r){var c,a;for(c=0;c<16;++c)t.table[c]=0;for(c=0;c<r;++c)t.table[e[n+c]]++;for(t.table[0]=0,a=0,c=0;c<16;++c)Hn[c]=a,a+=t.table[c];for(c=0;c<r;++c)e[n+c]&&(t.trans[Hn[e[n+c]]++]=c)}function Wr(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function E2(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 at(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,r=0,c=0,a=t.tag;do r=2*r+(a&1),a>>>=1,++c,n+=e.table[c],r-=e.table[c];while(r>=0);return t.tag=a,t.bitcount-=c,e.trans[n+r]}function Xr(t,e,n){var r,c,a,s,o,i;for(r=E2(t,5,257),c=E2(t,5,1),a=E2(t,4,4),s=0;s<19;++s)P2[s]=0;for(s=0;s<a;++s){var l=E2(t,3,0);P2[jr[s]]=l}for(Y4(Vn,P2,0,19),o=0;o<r+c;){var h=at(t,Vn);switch(h){case 16:var u=P2[o-1];for(i=E2(t,2,3);i;--i)P2[o++]=u;break;case 17:for(i=E2(t,3,3);i;--i)P2[o++]=0;break;case 18:for(i=E2(t,7,11);i;--i)P2[o++]=0;break;default:P2[o++]=h;break}}Y4(e,P2,0,r),Y4(n,P2,r,c)}function On(t,e,n){for(;;){var r=at(t,e);if(r===256)return mt;if(r<256)t.dest[t.destLen++]=r;else{var c,a,s,o;for(r-=257,c=E2(t,pt[r],gt[r]),a=at(t,n),s=t.destLen-E2(t,M7[a],w7[a]),o=s;o<s+c;++o)t.dest[t.destLen++]=t.dest[o]}}}function Zr(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 y7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,mt}function Yr(t,e){var n=new _r(t,e),r,c,a;do{switch(r=Wr(n),c=E2(n,2,0),c){case 0:a=Zr(n);break;case 1:a=On(n,b7,x7);break;case 2:Xr(n,n.ltree,n.dtree),a=On(n,n.ltree,n.dtree);break;default:a=y7}if(a!==mt)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}Gr(b7,x7);k7(pt,gt,4,3);k7(M7,w7,2,1);pt[28]=0;gt[28]=258;var Jr=Yr;function X3(t,e,n,r,c){return Math.pow(1-c,3)*t+3*Math.pow(1-c,2)*c*e+3*(1-c)*Math.pow(c,2)*n+Math.pow(c,3)*r}function a3(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}a3.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};a3.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))};a3.prototype.addX=function(t){this.addPoint(t,null)};a3.prototype.addY=function(t){this.addPoint(null,t)};a3.prototype.addBezier=function(t,e,n,r,c,a,s,o){var i=[t,e],l=[n,r],h=[c,a],u=[s,o];this.addPoint(t,e),this.addPoint(s,o);for(var f=0;f<=1;f++){var d=6*i[f]-12*l[f]+6*h[f],p=-3*i[f]+9*l[f]-9*h[f]+3*u[f],m=3*l[f]-3*i[f];if(p===0){if(d===0)continue;var g=-m/d;0<g&&g<1&&(f===0&&this.addX(X3(i[f],l[f],h[f],u[f],g)),f===1&&this.addY(X3(i[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*m*p;if(!(v<0)){var b=(-d+Math.sqrt(v))/(2*p);0<b&&b<1&&(f===0&&this.addX(X3(i[f],l[f],h[f],u[f],b)),f===1&&this.addY(X3(i[f],l[f],h[f],u[f],b)));var y=(-d-Math.sqrt(v))/(2*p);0<y&&y<1&&(f===0&&this.addX(X3(i[f],l[f],h[f],u[f],y)),f===1&&this.addY(X3(i[f],l[f],h[f],u[f],y)))}}};a3.prototype.addQuad=function(t,e,n,r,c,a){var s=t+.6666666666666666*(n-t),o=e+2/3*(r-e),i=s+1/3*(c-t),l=o+1/3*(a-e);this.addBezier(t,e,s,o,i,l,c,a)};function P0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}P0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};P0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};P0.prototype.curveTo=P0.prototype.bezierCurveTo=function(t,e,n,r,c,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:r,x:c,y:a})};P0.prototype.quadTo=P0.prototype.quadraticCurveTo=function(t,e,n,r){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:r})};P0.prototype.close=P0.prototype.closePath=function(){this.commands.push({type:"Z"})};P0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof a3){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)};P0.prototype.getBoundingBox=function(){for(var t=new a3,e=0,n=0,r=0,c=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=r=s.x,n=c=s.y;break;case"L":t.addPoint(s.x,s.y),r=s.x,c=s.y;break;case"Q":t.addQuad(r,c,s.x1,s.y1,s.x,s.y),r=s.x,c=s.y;break;case"C":t.addBezier(r,c,s.x1,s.y1,s.x2,s.y2,s.x,s.y),r=s.x,c=s.y;break;case"Z":r=e,c=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};P0.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())};P0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,o="",i=0;i<arguments.length;i+=1){var l=s[i];l>=0&&i>0&&(o+=" "),o+=e(l)}return o}for(var r="",c=0;c<this.commands.length;c+=1){var a=this.commands[c];a.type==="M"?r+="M"+n(a.x,a.y):a.type==="L"?r+="L"+n(a.x,a.y):a.type==="C"?r+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?r+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(r+="Z")}return r};P0.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};P0.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 z7(t){throw new Error(t)}function $n(t,e){t||z7(e)}var T1={fail:z7,argument:$n,assert:$n},Rn=32768,Fn=2147483648,Y3={},c1={},H1={};function b2(t){return function(){return t}}c1.BYTE=function(t){return T1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};H1.BYTE=b2(1);c1.CHAR=function(t){return[t.charCodeAt(0)]};H1.CHAR=b2(1);c1.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};H1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};c1.USHORT=function(t){return[t>>8&255,t&255]};H1.USHORT=b2(2);c1.SHORT=function(t){return t>=Rn&&(t=-(2*Rn-t)),[t>>8&255,t&255]};H1.SHORT=b2(2);c1.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};H1.UINT24=b2(3);c1.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};H1.ULONG=b2(4);c1.LONG=function(t){return t>=Fn&&(t=-(2*Fn-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};H1.LONG=b2(4);c1.FIXED=c1.ULONG;H1.FIXED=H1.ULONG;c1.FWORD=c1.SHORT;H1.FWORD=H1.SHORT;c1.UFWORD=c1.USHORT;H1.UFWORD=H1.USHORT;c1.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};H1.LONGDATETIME=b2(8);c1.TAG=function(t){return T1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};H1.TAG=b2(4);c1.Card8=c1.BYTE;H1.Card8=H1.BYTE;c1.Card16=c1.USHORT;H1.Card16=H1.USHORT;c1.OffSize=c1.BYTE;H1.OffSize=H1.BYTE;c1.SID=c1.USHORT;H1.SID=H1.USHORT;c1.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?c1.NUMBER16(t):c1.NUMBER32(t)};H1.NUMBER=function(t){return c1.NUMBER(t).length};c1.NUMBER16=function(t){return[28,t>>8&255,t&255]};H1.NUMBER16=b2(3);c1.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};H1.NUMBER32=b2(5);c1.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 c="",a=0,s=e.length;a<s;a+=1){var o=e[a];o==="e"?c+=e[++a]==="-"?"c":"b":o==="."?c+="a":o==="-"?c+="e":c+=o}c+=c.length&1?"f":"ff";for(var i=[30],l=0,h=c.length;l<h;l+=2)i.push(parseInt(c.substr(l,2),16));return i};H1.REAL=function(t){return c1.REAL(t).length};c1.NAME=c1.CHARARRAY;H1.NAME=H1.CHARARRAY;c1.STRING=c1.CHARARRAY;H1.STRING=H1.CHARARRAY;Y3.UTF8=function(t,e,n){for(var r=[],c=n,a=0;a<c;a++,e+=1)r[a]=t.getUint8(e);return String.fromCharCode.apply(null,r)};Y3.UTF16=function(t,e,n){for(var r=[],c=n/2,a=0;a<c;a++,e+=2)r[a]=t.getUint16(e);return String.fromCharCode.apply(null,r)};c1.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};H1.UTF16=function(t){return t.length*2};var st={"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"};Y3.MACSTRING=function(t,e,n,r){var c=st[r];if(c!==void 0){for(var a="",s=0;s<n;s++){var o=t.getUint8(e+s);o<=127?a+=String.fromCharCode(o):a+=c[o&127]}return a}};var Ee=typeof WeakMap=="function"&&new WeakMap,Te,Kr=function(t){if(!Te){Te={};for(var e in st)Te[e]=new String(e)}var n=Te[t];if(n!==void 0){if(Ee){var r=Ee.get(n);if(r!==void 0)return r}var c=st[t];if(c!==void 0){for(var a={},s=0;s<c.length;s++)a[c.charCodeAt(s)]=s+128;return Ee&&Ee.set(n,a),a}}};c1.MACSTRING=function(t,e){var n=Kr(e);if(n!==void 0){for(var r=[],c=0;c<t.length;c++){var a=t.charCodeAt(c);if(a>=128&&(a=n[a],a===void 0))return;r[c]=a}return r}};H1.MACSTRING=function(t,e){var n=c1.MACSTRING(t,e);return n!==void 0?n.length:0};function ot(t){return t>=-128&&t<=127}function Qr(t,e,n){for(var r=0,c=t.length;e<c&&r<64&&t[e]===0;)++e,++r;return n.push(128|r-1),e}function ec(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(!ot(s)||s===0&&a+1<c&&t[a+1]===0)break;++a,++r}n.push(r-1);for(var o=e;o<a;++o)n.push(t[o]+256&255);return a}function tc(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(s===0||ot(s)&&a+1<c&&ot(t[a+1]))break;++a,++r}n.push(64|r-1);for(var o=e;o<a;++o){var i=t[o];n.push(i+65536>>8&255,i+256&255)}return a}c1.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var r=t[e];r===0?e=Qr(t,e,n):r>=-128&&r<=127?e=ec(t,e,n):e=tc(t,e,n)}return n};c1.INDEX=function(t){for(var e=1,n=[e],r=[],c=0;c<t.length;c+=1){var a=c1.OBJECT(t[c]);Array.prototype.push.apply(r,a),e+=a.length,n.push(e)}if(r.length===0)return[0,0];for(var s=[],o=1+Math.floor(Math.log(e)/Math.log(2))/8|0,i=[void 0,c1.BYTE,c1.USHORT,c1.UINT24,c1.ULONG][o],l=0;l<n.length;l+=1){var h=i(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(c1.Card16(t.length),c1.OffSize(o),s,r)};H1.INDEX=function(t){return c1.INDEX(t).length};c1.DICT=function(t){for(var e=[],n=Object.keys(t),r=n.length,c=0;c<r;c+=1){var a=parseInt(n[c],0),s=t[a];e=e.concat(c1.OPERAND(s.value,s.type)),e=e.concat(c1.OPERATOR(a))}return e};H1.DICT=function(t){return c1.DICT(t).length};c1.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};c1.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r+=1)T1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(c1.OPERAND(t[r],e[r]));else if(e==="SID")n=n.concat(c1.NUMBER(t));else if(e==="offset")n=n.concat(c1.NUMBER32(t));else if(e==="number")n=n.concat(c1.NUMBER(t));else if(e==="real")n=n.concat(c1.REAL(t));else throw new Error("Unknown operand type "+e);return n};c1.OP=c1.BYTE;H1.OP=H1.BYTE;var Ie=typeof WeakMap=="function"&&new WeakMap;c1.CHARSTRING=function(t){if(Ie){var e=Ie.get(t);if(e!==void 0)return e}for(var n=[],r=t.length,c=0;c<r;c+=1){var a=t[c];n=n.concat(c1[a.type](a.value))}return Ie&&Ie.set(t,n),n};H1.CHARSTRING=function(t){return c1.CHARSTRING(t).length};c1.OBJECT=function(t){var e=c1[t.type];return T1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};H1.OBJECT=function(t){var e=H1[t.type];return T1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};c1.TABLE=function(t){for(var e=[],n=t.fields.length,r=[],c=[],a=0;a<n;a+=1){var s=t.fields[a],o=c1[s.type];T1.argument(o!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var i=t[s.name];i===void 0&&(i=s.value);var l=o(i);s.type==="TABLE"?(c.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=c[h],f=e.length;T1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(r[h])}return e};H1.TABLE=function(t){for(var e=0,n=t.fields.length,r=0;r<n;r+=1){var c=t.fields[r],a=H1[c.type];T1.argument(a!==void 0,"No sizeOf function for field type "+c.type+" ("+c.name+")");var s=t[c.name];s===void 0&&(s=c.value),e+=a(s),c.type==="TABLE"&&(e+=2)}return e};c1.RECORD=c1.TABLE;H1.RECORD=H1.TABLE;c1.LITERAL=function(t){return t};H1.LITERAL=function(t){return t.length};function V0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var r=0;r<e.length;r+=1){var c=e[r];this[c.name]=c.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var o=a[s],i=n[o];this[o]!==void 0&&(this[o]=i)}}V0.prototype.encode=function(){return c1.TABLE(this)};V0.prototype.sizeOf=function(){return H1.TABLE(this)};function q5(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 c=0;c<e.length;c++)r[c+1]={name:t+c,type:"USHORT",value:e[c]};return r}function it(t,e,n){var r=e.length,c=new Array(r+1);c[0]={name:t+"Count",type:"USHORT",value:r};for(var a=0;a<r;a++)c[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return c}function N5(t,e,n){var r=e.length,c=[];c[0]={name:t+"Count",type:"USHORT",value:r};for(var a=0;a<r;a++)c=c.concat(n(e[a],a));return c}function Re(t){t.format===1?V0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(q5("glyph",t.glyphs))):t.format===2?V0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(N5("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}]}))):T1.assert(!1,"Coverage format must be 1 or 2.")}Re.prototype=Object.create(V0.prototype);Re.prototype.constructor=Re;function Fe(t){V0.call(this,"scriptListTable",N5("scriptRecord",t,function(e,n){var r=e.script,c=r.defaultLangSys;return T1.assert(!!c,"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 V0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new V0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:c.reqFeatureIndex}].concat(q5("featureIndex",c.featureIndexes)))}].concat(N5("langSys",r.langSysRecords,function(a,s){var o=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new V0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:o.reqFeatureIndex}].concat(q5("featureIndex",o.featureIndexes)))}]})))}]}))}Fe.prototype=Object.create(V0.prototype);Fe.prototype.constructor=Fe;function De(t){V0.call(this,"featureListTable",N5("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 V0("featureTable",[{name:"featureParams",type:"USHORT",value:r.featureParams}].concat(q5("lookupListIndex",r.lookupListIndexes)))}]}))}De.prototype=Object.create(V0.prototype);De.prototype.constructor=De;function qe(t,e){V0.call(this,"lookupListTable",it("lookup",t,function(n){var r=e[n.lookupType];return T1.assert(!!r,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new V0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(it("subtable",n.subtables,r)))}))}qe.prototype=Object.create(V0.prototype);qe.prototype.constructor=qe;var o1={Table:V0,Record:V0,Coverage:Re,ScriptList:Fe,FeatureList:De,LookupList:qe,ushortList:q5,tableList:it,recordList:N5};function Dn(t,e){return t.getUint8(e)}function Ne(t,e){return t.getUint16(e,!1)}function nc(t,e){return t.getInt16(e,!1)}function vt(t,e){return t.getUint32(e,!1)}function S7(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 cc(t,e,n){for(var r=0,c=0;c<n;c+=1)r<<=8,r+=t.getUint8(e+c);return r}function ac(t,e,n){for(var r=[],c=e;c<n;c+=1)r.push(t.getUint8(c));return r}function sc(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=vt(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseOffset32=N.prototype.parseULong;N.prototype.parseFixed=function(){var t=S7(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 c=0;c<t;c++)r+=String.fromCharCode(e.getUint8(n+c));return r};N.prototype.parseTag=function(){return this.parseString(4)};N.prototype.parseLongDateTime=function(){var t=vt(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};N.prototype.parseVersion=function(t){var e=Ne(this.data,this.offset+this.relativeOffset),n=Ne(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,c=0;c<t;c++)e[c]=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,c=0;c<t;c++)e[c]=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,c=0;c<t;c++)e[c]=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,c=0;c<t;c++)e[c]=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),c=0;c<t;c++){for(var a={},s=0;s<r.length;s++){var o=r[s],i=e[o];a[o]=i.call(this)}n[c]=a}return n};N.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=Object.keys(e),c=0;c<t;c++){for(var a={},s=0;s<r.length;s++){var o=r[s],i=e[o];a[o]=i.call(this)}n[c]=a}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 c=e[r],a=t[c];n[c]=a.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,c=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){c[a]=void 0;continue}if(this.relativeOffset=s,t){for(var o=this.parseOffset16List(),i=new Array(o.length),l=0;l<o.length;l++)this.relativeOffset=s+o[l],i[l]=t.call(this);c[a]=i}else c[a]=this.parseUShortList()}return this.relativeOffset=r,c};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),c=0;c<n;c++)r[c]={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 qn={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(qn),langSysRecords:N.recordList({tag:N.tag,langSys:N.pointer(qn)})})}))||[]};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();T1.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();T1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:N.offset32,featureTableSubstitutionOffset:N.offset32});return n})||[]};var d1={getByte:Dn,getCard8:Dn,getUShort:Ne,getCard16:Ne,getShort:nc,getULong:vt,getFixed:S7,getTag:rc,getOffset:cc,getBytes:ac,bytesToString:sc,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 c=e.parseULong(),a=e.parseULong(),s=e.parseULong(),o=c;o<=a;o+=1)t.glyphIndexMap[o]=s,s++}function lc(t,e,n,r,c){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new d1.Parser(n,r+c+14),o=new d1.Parser(n,r+c+16+a*2),i=new d1.Parser(n,r+c+16+a*4),l=new d1.Parser(n,r+c+16+a*6),h=r+c+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),p=o.parseUShort(),m=i.parseShort(),g=l.parseUShort(),v=p;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-p)*2,f=d1.getUShort(n,h),f!==0&&(f=f+m&65535)):f=v+m&65535,t.glyphIndexMap[v]=f}function hc(t,e){var n={};n.version=d1.getUShort(t,e),T1.argument(n.version===0,"cmap table version should be 0."),n.numTables=d1.getUShort(t,e+2);for(var r=-1,c=n.numTables-1;c>=0;c-=1){var a=d1.getUShort(t,e+4+c*8),s=d1.getUShort(t,e+4+c*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){r=d1.getULong(t,e+4+c*8+4);break}}if(r===-1)throw new Error("No valid cmap sub-tables found.");var o=new d1.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 c=[{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||(c=c.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),c=c.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 a=new o1.Table("cmap",c);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),o=0;o<s.unicodes.length;o+=1)uc(a,s.unicodes[o],n);a.segments=a.segments.sort(function(b,y){return b.start-y.start})}fc(a);var i=a.segments.length,l=0,h=[],u=[],f=[],d=[],p=[],m=[];for(n=0;n<i;n+=1){var g=a.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&&(p=p.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),m=m.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),m=m.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(a.segCountX2=(i-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(i-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(p),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+p.length*2,!e){var v=16+m.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.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:m.length/3}]),a.fields=a.fields.concat(m)}return a}var A7={parse:hc,make:dc},Oe=[".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"],M3=[".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 L7(t){this.font=t}L7.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 c=n.get(r),a=0;a<c.unicodes.length;a+=1)if(c.unicodes[a]===e)return r}return null};function C7(t){this.cmap=t}C7.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function Ue(t,e){this.encoding=t,this.charset=e}Ue.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function yt(t){switch(t.version){case 1:this.names=M3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<M3.length?this.names[e]=M3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-M3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=M3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}yt.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};yt.prototype.glyphIndexToName=function(t){return this.names[t]};function gc(t){for(var e,n=t.tables.cmap.glyphIndexMap,r=Object.keys(n),c=0;c<r.length;c+=1){var a=r[c],s=n[a];e=t.glyphs.get(s),e.addUnicode(parseInt(a))}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 c=n[r],a=e[c];t._IndexToUnicodeMap[a]===void 0?t._IndexToUnicodeMap[a]={unicodes:[parseInt(c)]}:t._IndexToUnicodeMap[a].unicodes.push(parseInt(c))}}function yc(t,e){e.lowMemory?vc(t):gc(t)}function bc(t,e,n,r,c){t.beginPath(),t.moveTo(e,n),t.lineTo(r,c),t.stroke()}var x3={line:bc};function xc(t,e){var n=e||new P0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(r){n=r}}}function f2(t){this.bindConstructorValues(t)}f2.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))};f2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};f2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};f2.prototype.getPath=function(t,e,n,r,c){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;r||(r={});var o=r.xScale,i=r.yScale;if(r.hinting&&c&&c.hinting&&(s=this.path&&c.hinting.exec(this,n)),s)a=c.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),o=i=1;else{a=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 P0,u=0;u<a.length;u+=1){var f=a[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};f2.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 T1.argument(e.length===0,"There are still points left in the current contour."),t};f2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],r=0;r<t.length;r+=1){var c=t[r];c.type!=="Z"&&(e.push(c.x),n.push(c.y)),(c.type==="Q"||c.type==="C")&&(e.push(c.x1),n.push(c.y1)),c.type==="C"&&(e.push(c.x2),n.push(c.y2))}var a={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(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a};f2.prototype.draw=function(t,e,n,r,c){this.getPath(e,n,r,c).draw(t)};f2.prototype.drawPoints=function(t,e,n,r){function c(u,f,d,p){t.beginPath();for(var m=0;m<u.length;m+=1)t.moveTo(f+u[m].x*p,d+u[m].y*p),t.arc(f+u[m].x*p,d+u[m].y*p,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 a=1/this.path.unitsPerEm*r,s=[],o=[],i=this.path,l=0;l<i.commands.length;l+=1){var h=i.commands[l];h.x!==void 0&&s.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",c(s,e,n,a),t.fillStyle="red",c(o,e,n,a)};f2.prototype.drawMetrics=function(t,e,n,r){var c;e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24,c=1/this.path.unitsPerEm*r,t.lineWidth=1,t.strokeStyle="black",x3.line(t,e,-1e4,e,1e4),x3.line(t,-1e4,n,1e4,n);var a=this.xMin||0,s=this.yMin||0,o=this.xMax||0,i=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",x3.line(t,e+a*c,-1e4,e+a*c,1e4),x3.line(t,e+o*c,-1e4,e+o*c,1e4),x3.line(t,-1e4,n+-s*c,1e4,n+-s*c),x3.line(t,-1e4,n+-i*c,1e4,n+-i*c),t.strokeStyle="green",x3.line(t,e+l*c,-1e4,e+l*c,1e4)};function Ve(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 bt(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}bt.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]};bt.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Mc(t,e){return new f2({index:e,font:t})}function wc(t,e,n,r,c,a){return function(){var s=new f2({index:e,font:t});return s.path=function(){n(s,r,c);var o=a(t.glyphs,s);return o.unitsPerEm=t.unitsPerEm,o},Ve(s,"xMin","_xMin"),Ve(s,"xMax","_xMax"),Ve(s,"yMin","_yMin"),Ve(s,"yMax","_yMax"),s}}function kc(t,e,n,r){return function(){var c=new f2({index:e,font:t});return c.path=function(){var a=n(t,c,r);return a.unitsPerEm=t.unitsPerEm,a},c}}var I2={GlyphSet:bt,glyphLoader:Mc,ttfGlyphLoader:wc,cffGlyphLoader:kc};function P7(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(!P7(t[n],e[n]))return!1;return!0}else return!1}function lt(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function t3(t,e,n){var r=[],c=[],a=d1.getCard16(t,e),s,o;if(a!==0){var i=d1.getByte(t,e+2);s=e+(a+1)*i+2;for(var l=e+3,h=0;h<a+1;h+=1)r.push(d1.getOffset(t,l,i)),l+=i;o=s+r[a]}else o=e+2;for(var u=0;u<r.length-1;u+=1){var f=d1.getBytes(t,s+r[u],s+r[u+1]);n&&(f=n(f)),c.push(f)}return{objects:c,startOffset:e,endOffset:o}}function zc(t,e){var n=[],r=d1.getCard16(t,e),c,a;if(r!==0){var s=d1.getByte(t,e+2);c=e+(r+1)*s+2;for(var o=e+3,i=0;i<r+1;i+=1)n.push(d1.getOffset(t,o,s)),o+=s;a=c+n[r]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function Sc(t,e,n,r,c){var a=d1.getCard16(n,r),s=0;if(a!==0){var o=d1.getByte(n,r+2);s=r+(a+1)*o+2}var i=d1.getBytes(n,s+e[t],s+e[t+1]);return c&&(i=c(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 c=t.parseByte(),a=c>>4,s=c&15;if(a===n||(e+=r[a],s===n))break;e+=r[s]}return parseFloat(e)}function Lc(t,e){var n,r,c,a;if(e===28)return n=t.parseByte(),r=t.parseByte(),n<<8|r;if(e===29)return n=t.parseByte(),r=t.parseByte(),c=t.parseByte(),a=t.parseByte(),n<<24|r<<16|c<<8|a;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],c=t[n][1],a=void 0;if(c.length===1?a=c[0]:a=c,e.hasOwnProperty(r)&&!isNaN(e[r]))throw new Error("Object "+e+" already has key "+r);e[r]=a}return e}function E7(t,e,n){e=e!==void 0?e:0;var r=new d1.Parser(t,e),c=[],a=[];for(n=n!==void 0?n:t.length;r.relativeOffset<n;){var s=r.parseByte();s<=21?(s===12&&(s=1200+r.parseByte()),c.push([s,a]),a=[]):a.push(Lc(r,s))}return Cc(c)}function F5(t,e){return e<=390?e=Oe[e]:e=t[e-391],e}function T7(t,e,n){for(var r={},c,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var o=[];o.length=s.type.length;for(var i=0;i<s.type.length;i++)c=t[s.op]!==void 0?t[s.op][i]:void 0,c===void 0&&(c=s.value!==void 0&&s.value[i]!==void 0?s.value[i]:null),s.type[i]==="SID"&&(c=F5(n,c)),o[i]=c;r[s.name]=o}else c=t[s.op],c===void 0&&(c=s.value!==void 0?s.value:null),s.type==="SID"&&(c=F5(n,c)),r[s.name]=c}return r}function Pc(t,e){var n={};return n.formatMajor=d1.getCard8(t,e),n.formatMinor=d1.getCard8(t,e+1),n.size=d1.getCard8(t,e+2),n.offsetSize=d1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var I7=[{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"}],V7=[{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=E7(t,0,t.byteLength);return T7(n,I7,e)}function H7(t,e,n,r){var c=E7(t,e,n);return T7(c,V7,r)}function Nn(t,e,n,r){for(var c=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),o=Ec(s,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=H7(t,l+e,i,r);if(o._defaultWidthX=h.defaultWidthX,o._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=t3(t,u+e);o._subrs=f.objects,o._subrsBias=lt(o._subrs)}o._privateDict=h}c.push(o)}return c}function Tc(t,e,n,r){var c,a,s=new d1.Parser(t,e);n-=1;var o=[".notdef"],i=s.parseCard8();if(i===0)for(var l=0;l<n;l+=1)c=s.parseSID(),o.push(F5(r,c));else if(i===1)for(;o.length<=n;){c=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)o.push(F5(r,c)),c+=1}else if(i===2)for(;o.length<=n;){c=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)o.push(F5(r,c)),c+=1}else throw new Error("Unknown charset format "+i);return o}function Ic(t,e,n){var r,c={},a=new d1.Parser(t,e),s=a.parseCard8();if(s===0)for(var o=a.parseCard8(),i=0;i<o;i+=1)r=a.parseCard8(),c[r]=i;else if(s===1){var l=a.parseCard8();r=1;for(var h=0;h<l;h+=1)for(var u=a.parseCard8(),f=a.parseCard8(),d=u;d<=u+f;d+=1)c[d]=r,r+=1}else throw new Error("Unknown encoding format "+s);return new Ue(c,n)}function Un(t,e,n){var r,c,a,s,o=new P0,i=[],l=0,h=!1,u=!1,f=0,d=0,p,m,g,v;if(t.isCIDFont){var b=t.tables.cff.topDict._fdSelect[e.index],y=t.tables.cff.topDict._fdArray[b];p=y._subrs,m=y._subrsBias,g=y._defaultWidthX,v=y._nominalWidthX}else p=t.tables.cff.topDict._subrs,m=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function w(z,A){u&&o.closePath(),o.moveTo(z,A),u=!0}function M(){var z;z=i.length%2!==0,z&&!h&&(x=i.shift()+v),l+=i.length>>1,i.length=0,h=!0}function k(z){for(var A,S,C,I,L,T,q,P,F,j,_,Q,H=0;H<z.length;){var B=z[H];switch(H+=1,B){case 1:M();break;case 3:M();break;case 4:i.length>1&&!h&&(x=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(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+i.shift(),o.curveTo(r,c,a,s,f,d);break;case 10:L=i.pop()+m,T=p[L],T&&k(T);break;case 11:return;case 12:switch(B=z[H],H+=1,B){case 35:r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s+i.shift(),F=q+i.shift(),j=P+i.shift(),_=F+i.shift(),Q=j+i.shift(),f=_+i.shift(),d=Q+i.shift(),i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;case 34:r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s,F=q+i.shift(),j=s,_=F+i.shift(),Q=d,f=_+i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;case 36:r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s,F=q+i.shift(),j=s,_=F+i.shift(),Q=j+i.shift(),f=_+i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;case 37:r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s+i.shift(),F=q+i.shift(),j=P+i.shift(),_=F+i.shift(),Q=j+i.shift(),Math.abs(_-f)>Math.abs(Q-d)?f=_+i.shift():d=Q+i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+B),i.length=0}break;case 14:i.length>0&&!h&&(x=i.shift()+v,h=!0),u&&(o.closePath(),u=!1);break;case 18:M();break;case 19:case 20:M(),H+=l+7>>3;break;case 21:i.length>2&&!h&&(x=i.shift()+v,h=!0),d+=i.pop(),f+=i.pop(),w(f,d);break;case 22:i.length>1&&!h&&(x=i.shift()+v,h=!0),f+=i.pop(),w(f,d);break;case 23:M();break;case 24:for(;i.length>2;)r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+i.shift(),o.curveTo(r,c,a,s,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(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+i.shift(),o.curveTo(r,c,a,s,f,d);break;case 26:for(i.length%2&&(f+=i.shift());i.length>0;)r=f,c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a,d=s+i.shift(),o.curveTo(r,c,a,s,f,d);break;case 27:for(i.length%2&&(d+=i.shift());i.length>0;)r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s,o.curveTo(r,c,a,s,f,d);break;case 28:A=z[H],S=z[H+1],i.push((A<<24|S<<16)>>16),H+=2;break;case 29:L=i.pop()+t.gsubrsBias,T=t.gsubrs[L],T&&k(T);break;case 30:for(;i.length>0&&(r=f,c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d),i.length!==0);)r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),d=s+i.shift(),f=a+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d);break;case 31:for(;i.length>0&&(r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),d=s+i.shift(),f=a+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d),i.length!==0);)r=f,c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d);break;default:B<32?console.log("Glyph "+e.index+": unknown operator "+B):B<247?i.push(B-139):B<251?(A=z[H],H+=1,i.push((B-247)*256+A+108)):B<255?(A=z[H],H+=1,i.push(-(B-251)*256-A-108)):(A=z[H],S=z[H+1],C=z[H+2],I=z[H+3],H+=4,i.push((A<<24|S<<16|C<<8|I)/65536))}}}return k(n),e.advanceWidth=x,o}function Vc(t,e,n,r){var c=[],a,s=new d1.Parser(t,e),o=s.parseCard8();if(o===0)for(var i=0;i<n;i++){if(a=s.parseCard8(),a>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+r+")");c.push(a)}else if(o===3){var l=s.parseCard16(),h=s.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(a=s.parseCard8(),u=s.parseCard16(),a>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (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++)c.push(a);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 c}function Hc(t,e,n,r){n.tables.cff={};var c=Pc(t,e),a=t3(t,c.endOffset,d1.bytesToString),s=t3(t,a.endOffset),o=t3(t,s.endOffset,d1.bytesToString),i=t3(t,o.endOffset);n.gsubrs=i.objects,n.gsubrsBias=lt(n.gsubrs);var l=Nn(t,e,s.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=t3(t,u),p=Nn(t,e,d.objects,o.objects);h._fdArray=p,f+=e,h._fdSelect=Vc(t,f,n.numGlyphs,p.length)}var m=e+h.private[1],g=H7(t,m,h.private[0],o.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=m+g.subrs,b=t3(t,v);n.subrs=b.objects,n.subrsBias=lt(n.subrs)}else n.subrs=[],n.subrsBias=0;var y;r.lowMemory?(y=zc(t,e+h.charStrings),n.nGlyphs=y.offsets.length):(y=t3(t,e+h.charStrings),n.nGlyphs=y.objects.length);var x=Tc(t,e+h.charset,n.nGlyphs,o.objects);if(h.encoding===0?n.cffEncoding=new Ue(mc,x):h.encoding===1?n.cffEncoding=new Ue(pc,x):n.cffEncoding=Ic(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new I2.GlyphSet(n),r.lowMemory)n._push=function(k){var z=Sc(k,y.offsets,t,e+h.charStrings);n.glyphs.push(k,I2.cffGlyphLoader(n,k,Un,z))};else for(var w=0;w<n.nGlyphs;w+=1){var M=y.objects[w];n.glyphs.push(w,I2.cffGlyphLoader(n,w,Un,M))}}function O7(t,e){var n,r=Oe.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+Oe.length:(n=Oe.length+e.length,e.push(t)),n}function Oc(){return new o1.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 $c(t){var e=new o1.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 $7(t,e,n){for(var r={},c=0;c<t.length;c+=1){var a=t[c],s=e[a.name];s!==void 0&&!P7(s,a.value)&&(a.type==="SID"&&(s=O7(s,n)),r[a.op]={name:a.name,type:a.type,value:s})}return r}function Bn(t,e){var n=new o1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=$7(I7,t,e),n}function _n(t){var e=new o1.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 o1.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 o1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function Dc(t,e){for(var n=new o1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),r=0;r<t.length;r+=1){var c=t[r],a=O7(c,e);n.fields.push({name:"glyph_"+r,type:"SID",value:a})}return n}function qc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var r=0,c=0,a=0;a<n.commands.length;a+=1){var s=void 0,o=void 0,i=n.commands[a];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*c+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")s=Math.round(i.x-r),o=Math.round(i.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rmoveto",type:"OP",value:21}),r=Math.round(i.x),c=Math.round(i.y);else if(i.type==="L")s=Math.round(i.x-r),o=Math.round(i.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rlineto",type:"OP",value:5}),r=Math.round(i.x),c=Math.round(i.y);else if(i.type==="C"){var u=Math.round(i.x1-r),f=Math.round(i.y1-c),d=Math.round(i.x2-i.x1),p=Math.round(i.y2-i.y1);s=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:p}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rrcurveto",type:"OP",value:8}),r=Math.round(i.x),c=Math.round(i.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function Nc(t){for(var e=new o1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var r=t.get(n),c=qc(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:c})}return e}function Uc(t,e){var n=new o1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=$7(V7,t,e),n}function Bc(t,e){for(var n=new o1.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,c={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]},a={},s=[],o,i=1;i<t.length;i+=1)o=t.get(i),s.push(o.name);var l=[];n.header=Oc(),n.nameIndex=$c([e.postScriptName]);var h=Bn(c,l);n.topDictIndex=_n(h),n.globalSubrIndex=Fc(),n.charsets=Dc(s,l),n.charStringsIndex=Nc(t),n.privateDict=Uc(a,l),n.stringIndex=Rc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return c.charset=u,c.encoding=0,c.charStrings=c.charset+n.charsets.sizeOf(),c.private[1]=c.charStrings+n.charStringsIndex.sizeOf(),h=Bn(c,l),n.topDictIndex=_n(h),n}var R7={parse:Hc,make:Bc};function _c(t,e){var n={},r=new d1.Parser(t,e);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),T1.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 o1.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 F7={parse:_c,make:jc};function Gc(t,e){var n={},r=new d1.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 o1.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 D7={parse:Gc,make:Wc};function Xc(t,e,n,r,c){for(var a,s,o=new d1.Parser(t,e),i=0;i<r;i+=1){i<n&&(a=o.parseUShort(),s=o.parseShort());var l=c.get(i);l.advanceWidth=a,l.leftSideBearing=s}}function Zc(t,e,n,r,c){t._hmtxTableData={};for(var a,s,o=new d1.Parser(e,n),i=0;i<c;i+=1)i<r&&(a=o.parseUShort(),s=o.parseShort()),t._hmtxTableData[i]={advanceWidth:a,leftSideBearing:s}}function Yc(t,e,n,r,c,a,s){s.lowMemory?Zc(t,e,n,r,c):Xc(e,n,r,c,a)}function Jc(t){for(var e=new o1.Table("hmtx",[]),n=0;n<t.length;n+=1){var r=t.get(n),c=r.advanceWidth||0,a=r.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:c}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:a})}return e}var q7={parse:Yc,make:Jc};function Kc(t){for(var e=new o1.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,c=0;c<t.length;++c){var a=n.indexOf(t[c]);a<0&&(a=n.length,n+=t[c]),e.fields.push({name:"offset "+c,type:"USHORT",value:r+a}),e.fields.push({name:"length "+c,type:"USHORT",value:t[c].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Qc(t,e){var n=new d1.Parser(t,e),r=n.parseULong();T1.argument(r===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var c=n.parseULong(),a=[],s=0;s<c;s++){for(var o="",i=e+n.parseUShort(),l=n.parseUShort(),h=i;h<i+l;++h)o+=String.fromCharCode(t.getInt8(h));a.push(o)}return a}var N7={make:Kc,parse:Qc};function ea(t,e){var n={},r=new d1.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 ta(t){return new o1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var U7={parse:ea,make:ta},B7=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],_7={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"},na={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},j7={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 ra(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return _7[e];case 3:return j7[e]}}var ht="utf-16",ca={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"},aa={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 G7(t,e,n){switch(t){case 0:return ht;case 1:return aa[n]||ca[e];case 3:if(e===1||e===10)return ht;break}}function sa(t,e,n){for(var r={},c=new d1.Parser(t,e),a=c.parseUShort(),s=c.parseUShort(),o=c.offset+c.parseUShort(),i=0;i<s;i++){var l=c.parseUShort(),h=c.parseUShort(),u=c.parseUShort(),f=c.parseUShort(),d=B7[f]||f,p=c.parseUShort(),m=c.parseUShort(),g=ra(l,u,n),v=G7(l,h,u);if(v!==void 0&&g!==void 0){var b=void 0;if(v===ht?b=Y3.UTF16(t,o+m,p):b=Y3.MACSTRING(t,o+m,p,v),b){var y=r[d];y===void 0&&(y=r[d]={}),y[g]=b}}}var x=0;return a===1&&(x=c.parseUShort()),r}function J4(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function jn(t,e,n,r,c,a){return new o1.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:c},{name:"offset",type:"USHORT",value:a}])}function oa(t,e){var n=t.length,r=e.length-n+1;e:for(var c=0;c<r;c++)for(;c<r;c++){for(var a=0;a<n;a++)if(e[c+a]!==t[a])continue e;return c}return-1}function Gn(t,e){var n=oa(t,e);if(n<0){n=e.length;for(var r=0,c=t.length;r<c;++r)e.push(t[r])}return n}function ia(t,e){var n,r=[],c={},a=J4(B7);for(var s in t){var o=a[s];if(o===void 0&&(o=s),n=parseInt(o),isNaN(n))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');c[n]=t[s],r.push(n)}for(var i=J4(_7),l=J4(j7),h=[],u=[],f=0;f<r.length;f++){n=r[f];var d=c[n];for(var p in d){var m=d[p],g=1,v=i[p],b=na[v],y=G7(g,b,v),x=c1.MACSTRING(m,y);x===void 0&&(g=0,v=e.indexOf(p),v<0&&(v=e.length,e.push(p)),b=4,x=c1.UTF16(m));var w=Gn(x,u);h.push(jn(g,b,v,n,x.length,w));var M=l[p];if(M!==void 0){var k=c1.UTF16(m),z=Gn(k,u);h.push(jn(3,1,M,n,k.length,z))}}}h.sort(function(C,I){return C.platformID-I.platformID||C.encodingID-I.encodingID||C.languageID-I.languageID||C.nameID-I.nameID});for(var A=new o1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),S=0;S<h.length;S++)A.fields.push({name:"record_"+S,type:"RECORD",value:h[S]});return A.fields.push({name:"strings",type:"LITERAL",value:u}),A}var W7={parse:sa,make:ia},ut=[{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 la(t){for(var e=0;e<ut.length;e+=1){var n=ut[e];if(t>=n.begin&&t<n.end)return e}return-1}function ha(t,e){var n={},r=new d1.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 c=0;c<10;c++)n.panose[c]=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 ua(t){return new o1.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 ft={parse:ha,make:ua,unicodeRanges:ut,getUnicodeRange:la};function fa(t,e){var n={},r=new d1.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=M3.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var c=0;c<n.numberOfGlyphs;c++)n.glyphNameIndex[c]=r.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=M3.length){var s=r.parseChar();n.names.push(r.parseString(s))}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 da(){return new o1.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 X7={parse:fa,make:da},g2=new Array(9);g2[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()};T1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};g2[2]=function(){var e=this.parseUShort();return T1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),sequences:this.parseListOfLists()}};g2[3]=function(){var e=this.parseUShort();return T1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),alternateSets:this.parseListOfLists()}};g2[4]=function(){var e=this.parseUShort();return T1.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 Z3={sequenceIndex:N.uShort,lookupListIndex:N.uShort};g2[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 a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,Z3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(N.coverage),classDef:this.parsePointer(N.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,Z3)}})};if(n===3){var r=this.parseUShort(),c=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,N.pointer(N.coverage)),lookupRecords:this.parseRecordList(c,Z3)}}T1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};g2[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(Z3)}})};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(Z3)}})};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(Z3)};T1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};g2[7]=function(){var e=this.parseUShort();T1.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:g2[n].call(r)}};g2[8]=function(){var e=this.parseUShort();return T1.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 ma(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return T1.argument(r===1||r===1.1,"Unsupported GSUB table version."),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(g2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(g2),variations:n.parseFeatureVariationsList()}}var J3=new Array(9);J3[1]=function(e){return e.substFormat===1?new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.ushortList("substitute",e.substitute)))};J3[2]=function(e){return T1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("seqSet",e.sequences,function(n){return new o1.Table("sequenceSetTable",o1.ushortList("sequence",n))})))};J3[3]=function(e){return T1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("altSet",e.alternateSets,function(n){return new o1.Table("alternateSetTable",o1.ushortList("alternate",n))})))};J3[4]=function(e){return T1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("ligSet",e.ligatureSets,function(n){return new o1.Table("ligatureSetTable",o1.tableList("ligature",n,function(r){return new o1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:r.ligGlyph}].concat(o1.ushortList("component",r.components,r.components.length+1)))}))})))};J3[6]=function(e){if(e.substFormat===1){var n=new o1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new o1.Table("chainRuleSetTable",o1.tableList("chainRule",a,function(s){var o=o1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(o1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(o1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(o1.ushortList("substitution",[],s.lookupRecords.length));return s.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 o1.Table("chainRuleTable",o)}))})));return n}else if(e.substFormat===2)T1.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(a,s){r.push({name:"backtrackCoverage"+s,type:"TABLE",value:new o1.Coverage(a)})}),r.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){r.push({name:"inputCoverage"+s,type:"TABLE",value:new o1.Coverage(a)})}),r.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){r.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new o1.Coverage(a)})}),r.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){r=r.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var c=new o1.Table("chainContextTable",r);return c}T1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function pa(t){return new o1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new o1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new o1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new o1.LookupList(t.lookups,J3)}])}var Z7={parse:ma,make:pa};function ga(t,e){var n=new d1.Parser(t,e),r=n.parseULong();T1.argument(r===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var c=n.parseULong(),a={},s=0;s<c;s++){var o=n.parseTag(),i=n.parseULong(),l=n.parseULong(),h=Y3.UTF8(t,e+i,l);a[o]=h}return a}function va(t){var e=Object.keys(t).length,n="",r=16+e*12,c=new o1.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 a in t){var s=n.length;n+=t[a],c.fields.push({name:"tag "+a,type:"TAG",value:a}),c.fields.push({name:"offset "+a,type:"ULONG",value:r+s}),c.fields.push({name:"length "+a,type:"ULONG",value:t[a].length})}return c.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),c}var Y7={parse:ga,make:va};function Wn(t){return Math.log(t)/Math.log(2)|0}function xt(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 Xn(t,e,n,r){return new o1.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 J7(t){var e=new o1.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,Wn(e.numTables));e.searchRange=16*n,e.entrySelector=Wn(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],c=[],a=e.sizeOf()+Xn().sizeOf()*e.numTables;a%4!==0;)a+=1,c.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var o=t[s];T1.argument(o.tableName.length===4,"Table name"+o.tableName+" is invalid.");var i=o.sizeOf(),l=Xn(o.tableName,xt(o.encode()),a,i);for(r.push({name:l.tag+" Table Record",type:"RECORD",value:l}),c.push({name:o.tableName+" table",type:"RECORD",value:o}),a+=i,T1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,c.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(c),e}function Zn(t,e,n){for(var r=0;r<e.length;r+=1){var c=t.charToGlyphIndex(e[r]);if(c>0){var a=t.glyphs.get(c);return a.getMetrics()}}return n}function ya(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function ba(t){for(var e=[],n=[],r=[],c=[],a=[],s=[],o=[],i,l=0,h=0,u=0,f=0,d=0,p=0;p<t.glyphs.length;p+=1){var m=t.glyphs.get(p),g=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+p+"): advanceWidth is not a number.");(i>g||i===void 0)&&g>0&&(i=g),l<g&&(l=g);var v=ft.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(m.name!==".notdef"){var b=m.getMetrics();e.push(b.xMin),n.push(b.yMin),r.push(b.xMax),c.push(b.yMax),s.push(b.leftSideBearing),o.push(b.rightSideBearing),a.push(m.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,c),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:ya(a),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,o)};y.ascender=t.ascender,y.descender=t.descender;var x=F7.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),w=D7.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}),M=U7.make(t.glyphs.length),k=ft.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:Zn(t,"xyvw",{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:Zn(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",y).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=q7.make(t.glyphs),A=A7.make(t.glyphs),S=t.getEnglishName("fontFamily"),C=t.getEnglishName("fontSubfamily"),I=S+" "+C,L=t.getEnglishName("postScriptName");L||(L=S.replace(/\s/g,"")+"-"+C);var T={};for(var q in t.names)T[q]=t.names[q];T.uniqueID||(T.uniqueID={en:t.getEnglishName("manufacturer")+":"+I}),T.postScriptName||(T.postScriptName={en:L}),T.preferredFamily||(T.preferredFamily=t.names.fontFamily),T.preferredSubfamily||(T.preferredSubfamily=t.names.fontSubfamily);var P=[],F=W7.make(T,P),j=P.length>0?N7.make(P):void 0,_=X7.make(),Q=R7.make(t.glyphs,{version:t.getEnglishName("version"),fullName:I,familyName:S,weightName:C,postScriptName:L,unitsPerEm:t.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),H=t.metas&&Object.keys(t.metas).length>0?Y7.make(t.metas):void 0,B=[x,w,M,k,F,A,_,Q,z];j&&B.push(j),t.tables.gsub&&B.push(Z7.make(t.tables.gsub)),H&&B.push(H);for(var Y=J7(B),e1=Y.encode(),X=xt(e1),M1=Y.fields,v1=!1,p1=0;p1<M1.length;p1+=1)if(M1[p1].name==="head table"){M1[p1].value.checkSumAdjustment=2981146554-X,v1=!0;break}if(!v1)throw new Error("Could not find head table with checkSum to adjust.");return Y}var xa={make:J7,fontToTable:ba,computeCheckSum:xt};function K4(t,e){for(var n=0,r=t.length-1;n<=r;){var c=n+r>>>1,a=t[c].tag;if(a===e)return c;a<e?n=c+1:r=c-1}return-n-1}function Yn(t,e){for(var n=0,r=t.length-1;n<=r;){var c=n+r>>>1,a=t[c];if(a===e)return c;a<e?n=c+1:r=c-1}return-n-1}function Jn(t,e){for(var n,r=0,c=t.length-1;r<=c;){var a=r+c>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?r=a+1:c=a-1}if(r>0)return n=t[r-1],e>n.end?0:n}function B5(t,e){this.font=t,this.tableName=e}B5.prototype={searchTag:K4,binSearch:Yn,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,c=K4(n.scripts,t);if(c>=0)return r[c].script;if(e){var a={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-c,0,a),a.script}}},getLangSysTable:function(t,e,n){var r=this.getScriptTable(t,n);if(r){if(!e||e==="dflt"||e==="DFLT")return r.defaultLangSys;var c=K4(r.langSysRecords,e);if(c>=0)return r.langSysRecords[c].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-c,0,a),a.langSys}}},getFeatureTable:function(t,e,n,r){var c=this.getLangSysTable(t,e,r);if(c){for(var a,s=c.featureIndexes,o=this.font.tables[this.tableName].features,i=0;i<s.length;i++)if(a=o[s[i]],a.tag===n)return a.feature;if(r){var l=o.length;return T1.assert(l===0||n>=o[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},o.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,r,c){var a=this.getFeatureTable(t,e,n,c),s=[];if(a){for(var o,i=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<i.length;h++)o=l[i[h]],o.lookupType===r&&s.push(o);if(s.length===0&&c){o={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(o),i.push(u),[o]}}return s},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=Jn(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=Yn(t.glyphs,e);return n>=0?n:-1;case 2:var r=Jn(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 c=n[r],a=c.start,s=c.end,o=a;o<=s;o++)e.push(o);return e}};function _5(t){B5.call(this,t,"gpos")}_5.prototype=B5.prototype;_5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};_5.prototype.getKerningValue=function(t,e,n){for(var r=0;r<t.length;r++)for(var c=t[r].subtables,a=0;a<c.length;a++){var s=c[a],o=this.getCoverageIndex(s.coverage,e);if(!(o<0))switch(s.posFormat){case 1:for(var i=s.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(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};_5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function a2(t){B5.call(this,t,"gsub")}function Ma(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 Mt(t,e,n){for(var r=t.subtables,c=0;c<r.length;c++){var a=r[c];if(a.substFormat===e)return a}if(n)return r.push(n),n}a2.prototype=B5.prototype;a2.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};a2.prototype.getSingle=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,1),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++){var i=s[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};a2.prototype.getMultiple=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,2),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++){var i=s[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};a2.prototype.getAlternates=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,3),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++)for(var i=s[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};a2.prototype.getLigatures=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,4),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++)for(var i=s[o],l=this.expandCoverage(i.coverage),h=i.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],p=0;p<d.length;p++){var m=d[p];r.push({sub:[f].concat(m.components),by:m.ligGlyph})}return r};a2.prototype.addSingle=function(t,e,n,r){var c=this.getLookupTables(n,r,t,1,!0)[0],a=Mt(c,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});T1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,o=this.binSearch(a.coverage.glyphs,s);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,s),a.substitute.splice(o,0,0)),a.substitute[o]=e.by};a2.prototype.addMultiple=function(t,e,n,r){T1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var c=this.getLookupTables(n,r,t,2,!0)[0],a=Mt(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});T1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,o=this.binSearch(a.coverage.glyphs,s);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,s),a.sequences.splice(o,0,0)),a.sequences[o]=e.by};a2.prototype.addAlternate=function(t,e,n,r){var c=this.getLookupTables(n,r,t,3,!0)[0],a=Mt(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});T1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,o=this.binSearch(a.coverage.glyphs,s);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,s),a.alternateSets.splice(o,0,0)),a.alternateSets[o]=e.by};a2.prototype.addLigature=function(t,e,n,r){var c=this.getLookupTables(n,r,t,4,!0)[0],a=c.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},c.subtables[0]=a),T1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],o=e.sub.slice(1),i={ligGlyph:e.by,components:o},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(Ma(h[u].components,o))return;h.push(i)}else l=-1-l,a.coverage.glyphs.splice(l,0,s),a.ligatureSets.splice(l,0,[i])};a2.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)}};a2.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 wa(){return typeof window<"u"}function ka(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 R5(t,e){if(!t)throw e}function Kn(t,e,n,r,c){var a;return(e&r)>0?(a=t.parseByte(),(e&c)===0&&(a=-a),a=n+a):(e&c)>0?a=n:a=n+t.parseShort(),a}function K7(t,e,n){var r=new d1.Parser(e,n);t.numberOfContours=r.parseShort(),t._xMin=r.parseShort(),t._yMin=r.parseShort(),t._xMax=r.parseShort(),t._yMax=r.parseShort();var c,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],o=0;o<t.numberOfContours;o+=1)s.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=s[s.length-1]+1;c=[];for(var h=0;h<l;h+=1)if(a=r.parseByte(),c.push(a),(a&8)>0)for(var u=r.parseByte(),f=0;f<u;f+=1)c.push(a),h+=1;if(T1.argument(c.length===l,"Bad flags."),s.length>0){var d=[],p;if(l>0){for(var m=0;m<l;m+=1)a=c[m],p={},p.onCurve=!!(a&1),p.lastPointOfContour=s.indexOf(m)>=0,d.push(p);for(var g=0,v=0;v<l;v+=1)a=c[v],p=d[v],p.x=Kn(r,a,g,2,16),g=p.x;for(var b=0,y=0;y<l;y+=1)a=c[y],p=d[y],p.y=Kn(r,a,b,4,32),b=p.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){c=r.parseUShort();var w={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(c&1)>0?(c&2)>0?(w.dx=r.parseShort(),w.dy=r.parseShort()):w.matchedPoints=[r.parseUShort(),r.parseUShort()]:(c&2)>0?(w.dx=r.parseChar(),w.dy=r.parseChar()):w.matchedPoints=[r.parseByte(),r.parseByte()],(c&8)>0?w.xScale=w.yScale=r.parseF2Dot14():(c&64)>0?(w.xScale=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()):(c&128)>0&&(w.xScale=r.parseF2Dot14(),w.scale01=r.parseF2Dot14(),w.scale10=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()),t.components.push(w),x=!!(c&32)}if(c&256){t.instructionLength=r.parseUShort(),t.instructions=[];for(var M=0;M<t.instructionLength;M+=1)t.instructions.push(r.parseByte())}}}function Q4(t,e){for(var n=[],r=0;r<t.length;r+=1){var c=t[r],a={x:e.xScale*c.x+e.scale01*c.y+e.dx,y:e.scale10*c.x+e.yScale*c.y+e.dy,onCurve:c.onCurve,lastPointOfContour:c.lastPointOfContour};n.push(a)}return n}function za(t){for(var e=[],n=[],r=0;r<t.length;r+=1){var c=t[r];n.push(c),c.lastPointOfContour&&(e.push(n),n=[])}return T1.argument(n.length===0,"There are still points left in the current contour."),e}function Q7(t){var e=new P0;if(!t)return e;for(var n=za(t),r=0;r<n.length;++r){var c=n[r],a=null,s=c[c.length-1],o=c[0];if(s.onCurve)e.moveTo(s.x,s.y);else if(o.onCurve)e.moveTo(o.x,o.y);else{var i={x:(s.x+o.x)*.5,y:(s.y+o.y)*.5};e.moveTo(i.x,i.y)}for(var l=0;l<c.length;++l)if(a=s,s=o,o=c[(l+1)%c.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=a,u=o;a.onCurve||(h={x:(s.x+a.x)*.5,y:(s.y+a.y)*.5}),o.onCurve||(u={x:(s.x+o.x)*.5,y:(s.y+o.y)*.5}),e.quadraticCurveTo(s.x,s.y,u.x,u.y)}e.closePath()}return e}function e8(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var r=e.components[n],c=t.get(r.glyphIndex);if(c.getPath(),c.points){var a=void 0;if(r.matchedPoints===void 0)a=Q4(c.points,r);else{if(r.matchedPoints[0]>e.points.length-1||r.matchedPoints[1]>c.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[r.matchedPoints[0]],o=c.points[r.matchedPoints[1]],i={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};o=Q4([o],i)[0],i.dx=s.x-o.x,i.dy=s.y-o.y,a=Q4(c.points,i)}e.points=e.points.concat(a)}}return Q7(e.points)}function Sa(t,e,n,r){for(var c=new I2.GlyphSet(r),a=0;a<n.length-1;a+=1){var s=n[a],o=n[a+1];s!==o?c.push(a,I2.ttfGlyphLoader(r,a,K7,t,e+s,e8)):c.push(a,I2.glyphLoader(r,a))}return c}function Aa(t,e,n,r){var c=new I2.GlyphSet(r);return r._push=function(a){var s=n[a],o=n[a+1];s!==o?c.push(a,I2.ttfGlyphLoader(r,a,K7,t,e+s,e8)):c.push(a,I2.glyphLoader(r,a))},c}function La(t,e,n,r,c){return c.lowMemory?Aa(t,e,n,r):Sa(t,e,n,r)}var t8={getPath:Q7,parse:La},n8,k3,r8,dt;function c8(t){this.font=t,this.getCommands=function(e){return t8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function Ca(t){return t}function a8(t){return Math.sign(t)*Math.round(Math.abs(t))}function Pa(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function Ea(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function Ta(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function Ia(t){return Math.sign(t)*Math.floor(Math.abs(t))}var s8=function(t){var e=this.srPeriod,n=this.srPhase,r=this.srThreshold,c=1;return t<0&&(t=-t,c=-1),t+=r-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*c:t*c},T2={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 c,a,s,o,i,l,h;if(!r||r===this){if(c=t.xo-e.xo,a=t.xo-n.xo,i=e.x-e.xo,l=n.x-n.xo,s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){t.x=t.xo+(i+l)/2;return}t.x=t.xo+(i*o+l*s)/h;return}if(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){T2.setRelative(t,t,(i+l)/2,r,!0);return}T2.setRelative(t,t,(i*o+l*s)/h,r,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,r,c){if(!r||r===this){t.x=(c?e.xo:e.x)+n;return}var a=c?e.xo:e.x,s=c?e.yo:e.y,o=a+n*r.x,i=s+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}},N2={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 c,a,s,o,i,l,h;if(!r||r===this){if(c=t.yo-e.yo,a=t.yo-n.yo,i=e.y-e.yo,l=n.y-n.yo,s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){t.y=t.yo+(i+l)/2;return}t.y=t.yo+(i*o+l*s)/h;return}if(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){N2.setRelative(t,t,(i+l)/2,r,!0);return}N2.setRelative(t,t,(i*o+l*s)/h,r,!0)},normalSlope:0,setRelative:function(t,e,n,r,c){if(!r||r===this){t.y=(c?e.yo:e.y)+n;return}var a=c?e.xo:e.x,s=c?e.yo:e.y,o=a+n*r.x,i=s+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(T2);Object.freeze(N2);function j5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}j5.prototype.distance=function(t,e,n,r){return this.x*T2.distance(t,e,n,r)+this.y*N2.distance(t,e,n,r)};j5.prototype.interpolate=function(t,e,n,r){var c,a,s,o,i,l,h;if(s=r.distance(t,e,!0,!0),o=r.distance(t,n,!0,!0),c=r.distance(e,e,!1,!0),a=r.distance(n,n,!1,!0),i=Math.abs(s),l=Math.abs(o),h=i+l,h===0){this.setRelative(t,t,(c+a)/2,r,!0);return}this.setRelative(t,t,(c*l+a*i)/h,r,!0)};j5.prototype.setRelative=function(t,e,n,r,c){r=r||this;var a=c?e.xo:e.x,s=c?e.yo:e.y,o=a+n*r.x,i=s+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};j5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function G5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?T2:t===0&&e===1?N2:new j5(t,e)}function U2(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)}U2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};U2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var U5=Object.freeze(new U2(0,0)),Va={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function n3(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=T2,this.round=a8}}c8.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 c=this._fpgmState;if(!c){n3.prototype=Va,c=this._fpgmState=new n3("fpgm",n.tables.fpgm),c.funcs=[],c.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),c.step=-1);try{k3(c)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}n3.prototype=c,r=this._prepState=new n3("prep",n.tables.prep),r.ppem=e;var a=n.tables.cvt;if(a)for(var s=r.cvt=new Array(a.length),o=e/n.unitsPerEm,i=0;i<a.length;i++)s[i]=a[i]*o;else r.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),r.step=-1);try{k3(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return r8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};r8=function(t,e){var n=e.ppem/e.font.unitsPerEm,r=n,c=t.components,a,s,o;if(n3.prototype=e,!c)o=new n3("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),o.step=-1),dt(t,o,n,r),s=o.gZone;else{var i=e.font;s=[],a=[];for(var l=0;l<c.length;l++){var h=c[l],u=i.glyphs.get(h.glyphIndex);o=new n3("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),o.step=-1),dt(u,o,n,r);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*r),p=o.gZone,m=o.contours,g=0;g<p.length;g++){var v=p[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var b=s.length;s.push.apply(s,p);for(var y=0;y<m.length;y++)a.push(m[y]+b)}t.instructions&&!o.inhibitGridFit&&(o=new n3("glyf",t.instructions),o.gZone=o.z0=o.z1=o.z2=s,o.contours=a,s.push(new U2(0,0),new U2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),o.step=-1),k3(o),s.length-=2)}return s};dt=function(t,e,n,r){for(var c=t.points||[],a=c.length,s=e.gZone=e.z0=e.z1=e.z2=[],o=e.contours=[],i,l=0;l<a;l++)i=c[l],s[l]=new U2(i.x*n,i.y*r,i.lastPointOfContour,i.onCurve);for(var h,u,f=0;f<a;f++)i=s[f],h||(h=i,o.push(f)),i.lastPointOfContour?(i.nextPointOnContour=h,h.prevPointOnContour=i,h=void 0):(u=s[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<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new U2(0,0),new U2(Math.round(t.advanceWidth*n),0)),k3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var p=0;p<a;p++)console.log(p,s[p].x,s[p].y)}}};k3=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=n8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function Be(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new U2(0,0)}function o8(t,e){var n=t.prog,r=t.ip,c=1,a;do if(a=n[++r],a===88)c++;else if(a===89)c--;else if(a===64)r+=n[r+1]+1;else if(a===65)r+=2*n[r+1]+1;else if(a>=176&&a<=183)r+=a-176+1;else if(a>=184&&a<=191)r+=(a-184+1)*2;else if(e&&c===1&&a===27)break;while(c>0);t.ip=r}function Qn(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function e7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function t7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function n7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log("SPVTL["+t+"]",r,c);var o,i;t?(o=a.y-s.y,i=s.x-a.x):(o=s.x-a.x,i=s.y-a.y),e.pv=e.dpv=G5(o,i)}function r7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log("SFVTL["+t+"]",r,c);var o,i;t?(o=a.y-s.y,i=s.x-a.x):(o=s.x-a.x,i=s.y-a.y),e.fv=G5(o,i)}function Ha(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.pv=t.dpv=G5(r,n)}function Oa(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.fv=G5(r,n)}function $a(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 Ra(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 Fa(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function Da(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop(),a=e.pop(),s=e.pop(),o=t.z0,i=t.z1,l=o[n],h=o[r],u=i[c],f=i[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,r,c,a,s);var p=l.x,m=l.y,g=h.x,v=h.y,b=u.x,y=u.y,x=f.x,w=f.y,M=(p-g)*(y-w)-(m-v)*(b-x),k=p*v-m*g,z=b*w-y*x;d.x=(k*(b-x)-z*(p-g))/M,d.y=(k*(y-w)-z*(m-v))/M}function qa(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function Na(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function Ua(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function Ba(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||Be(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function _a(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||Be(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function ja(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||Be(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function Ga(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||Be(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 Wa(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function Xa(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=a8}function Za(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=Ea}function Ya(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function Ja(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),o8(t,!1)}function Ka(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Qa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function es(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function et(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function ts(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function ns(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 rs(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function cs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,r);var c=t.ip,a=t.prog;t.prog=t.funcs[n];for(var s=0;s<r;s++)k3(t),exports.DEBUG&&console.log(++t.step,s+1<r?"next loopcall":"done loopcall",s);t.ip=c,t.prog=a}function as(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],k3(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function ss(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function os(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 is(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,r=t.ip,c=e.pop(),a=r;for(exports.DEBUG&&console.log(t.step,"FDEF[]",c);n[++r]!==45;);t.ip=r,t.funcs[c]=n.slice(a+1,r)}function c7(t,e){var n=e.stack.pop(),r=e.z0[n],c=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(r,U5);t&&(s=e.round(s)),c.setRelative(r,U5,s,a),c.touch(r),e.rp0=e.rp1=n}function a7(t,e){var n=e.z2,r=n.length-2,c,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var o=0;o<r;o++)c=n[o],!t.touched(c)&&(a=c.prevTouched(t),a!==c&&(s=c.nextTouched(t),a===s&&t.setRelative(c,c,t.distance(a,a,!1,!0),t,!0),t.interpolate(c,a,s,t)))}function s7(t,e){for(var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,o=e.loop,i=e.z2;o--;){var l=n.pop(),h=i[l],u=s.distance(c,c,!1,!0);a.setRelative(h,h,u,s),a.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-o)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function o7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,o=n.pop(),i=e.z2[e.contours[o]],l=i;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",o);var h=s.distance(c,c,!1,!0);do l!==c&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==i)}function i7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=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=s.distance(c,c,!1,!0),u=i.length-2,f=0;f<u;f++)l=i[f],a.setRelative(l,l,h,s)}function ls(t){for(var e=t.stack,n=t.loop,r=t.fv,c=e.pop()/64,a=t.z2;n--;){var s=e.pop(),o=a[s];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",s,c),r.setRelative(o,o,c),r.touch(o)}t.loop=1}function hs(t){for(var e=t.stack,n=t.rp1,r=t.rp2,c=t.loop,a=t.z0[n],s=t.z1[r],o=t.fv,i=t.dpv,l=t.z2;c--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"IP[]",h,n,"<->",r),o.interpolate(u,a,s,i),o.touch(u)}t.loop=1}function l7(t,e){var n=e.stack,r=n.pop()/64,c=n.pop(),a=e.z1[c],s=e.z0[e.rp0],o=e.fv,i=e.pv;o.setRelative(a,s,r,i),o.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",r,c),e.rp1=e.rp0,e.rp2=c,t&&(e.rp0=c)}function us(t){for(var e=t.stack,n=t.rp0,r=t.z0[n],c=t.loop,a=t.fv,s=t.pv,o=t.z1;c--;){var i=e.pop(),l=o[i];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"ALIGNRP[]",i),a.setRelative(l,r,0,s),a.touch(l)}t.loop=1}function fs(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=Pa}function h7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z0[c],s=e.fv,o=e.pv,i=e.cvt[r];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",r,"(",i,")",c);var l=o.distance(a,U5);t&&(Math.abs(l-i)<e.cvCutIn&&(l=i),l=e.round(l)),s.setRelative(a,U5,l,o),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=c}function ds(t){var e=t.prog,n=t.ip,r=t.stack,c=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",c);for(var a=0;a<c;a++)r.push(e[++n]);t.ip=n}function ms(t){var e=t.ip,n=t.prog,r=t.stack,c=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",c);for(var a=0;a<c;a++){var s=n[++e]<<8|n[++e];s&32768&&(s=-((s^65535)+1)),r.push(s)}t.ip=e}function ps(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var r=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WS",r,c),n[c]=r}function gs(t){var e=t.stack,n=t.store,r=e.pop();exports.DEBUG&&console.log(t.step,"RS",r);var c=n&&n[r]||0;e.push(c)}function vs(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 ys(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function u7(t,e){var n=e.stack,r=n.pop(),c=e.z2[r];exports.DEBUG&&console.log(e.step,"GC["+t+"]",r),n.push(e.dpv.distance(c,U5,t,!1)*64)}function f7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z1[r],s=e.z0[c],o=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",r,c,"->",o),e.stack.push(Math.round(o*64))}function bs(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function xs(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Ms(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 ws(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 ks(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 zs(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 Ss(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 As(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 Ls(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 Cs(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 Ps(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(o8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function Es(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function Ts(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 Is(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 Vs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function tt(t,e){var n=e.stack,r=n.pop(),c=e.fv,a=e.pv,s=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===s){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",p*i);var m=l[u];c.setRelative(m,m,p*i,a)}}}function Hs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function Os(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function $s(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 Rs(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 Fs(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 Ds(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 qs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function Ns(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function Us(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function Bs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function He(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function _s(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 nt(t,e){var n=e.stack,r=n.pop(),c=e.ppem,a=e.deltaBase+(t-1)*16,s=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=a+((l&240)>>4);if(h===c){var u=(l&15)-8;u>=0&&u++;var f=u*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",i,"by",f),e.cvt[i]+=f}}}function js(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=s8;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 Gs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=s8;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 Ws(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=Ca}function Xs(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=Ta}function Zs(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=Ia}function Ys(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function d7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",r,c);var o,i;t?(o=a.y-s.y,i=s.x-a.x):(o=s.x-a.x,i=s.y-a.y),e.dpv=G5(o,i)}function Js(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 Ks(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(r),e.push(n),e.push(c)}function Qs(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 eo(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 to(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function no(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 Q2(t,e){var n=e.stack,r=e.prog,c=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(r[++c]);e.ip=c}function e3(t,e){var n=e.ip,r=e.prog,c=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=r[++n]<<8|r[++n];s&32768&&(s=-((s^65535)+1)),c.push(s)}e.ip=n}function u1(t,e,n,r,c,a){var s=a.stack,o=t&&s.pop(),i=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[i],f=a.minDis,d=a.fv,p=a.dpv,m,g,v,b;g=m=p.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(b=a.cvt[o],r&&Math.abs(g-b)<a.cvCutIn&&(g=b)),n&&g<f&&(g=f),r&&(g=a.round(g)),d.setRelative(u,h,v*g,p),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(r?"R":"_")+(c===0?"Gr":c===1?"Bl":c===2?"Wh":"")+"]",t?o+"("+a.cvt[o]+","+b+")":"",i,"(d =",m,"->",v*g,")"),a.rp1=a.rp0,a.rp2=i,e&&(a.rp0=i)}n8=[Qn.bind(void 0,N2),Qn.bind(void 0,T2),e7.bind(void 0,N2),e7.bind(void 0,T2),t7.bind(void 0,N2),t7.bind(void 0,T2),n7.bind(void 0,0),n7.bind(void 0,1),r7.bind(void 0,0),r7.bind(void 0,1),Ha,Oa,$a,Ra,Fa,Da,qa,Na,Ua,Ba,_a,ja,Ga,Wa,Xa,Za,Ya,Ja,Ka,Qa,void 0,void 0,es,et,ts,ns,rs,ss,os,void 0,void 0,void 0,cs,as,is,void 0,c7.bind(void 0,0),c7.bind(void 0,1),a7.bind(void 0,N2),a7.bind(void 0,T2),s7.bind(void 0,0),s7.bind(void 0,1),o7.bind(void 0,0),o7.bind(void 0,1),i7.bind(void 0,0),i7.bind(void 0,1),ls,hs,l7.bind(void 0,0),l7.bind(void 0,1),us,fs,h7.bind(void 0,0),h7.bind(void 0,1),ds,ms,ps,gs,vs,ys,u7.bind(void 0,0),u7.bind(void 0,1),void 0,f7.bind(void 0,0),f7.bind(void 0,1),bs,void 0,xs,void 0,void 0,Ms,ws,ks,zs,Ss,As,Ls,Cs,Ps,Es,Ts,Is,Vs,tt.bind(void 0,1),Hs,Os,$s,Rs,Fs,Ds,qs,Ns,Us,Bs,He.bind(void 0,0),He.bind(void 0,1),He.bind(void 0,2),He.bind(void 0,3),void 0,void 0,void 0,void 0,_s,tt.bind(void 0,2),tt.bind(void 0,3),nt.bind(void 0,1),nt.bind(void 0,2),nt.bind(void 0,3),js,Gs,void 0,void 0,Ws,void 0,Xs,Zs,et,et,void 0,void 0,void 0,void 0,void 0,Ys,d7.bind(void 0,0),d7.bind(void 0,1),Js,void 0,Ks,Qs,eo,to,no,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,Q2.bind(void 0,1),Q2.bind(void 0,2),Q2.bind(void 0,3),Q2.bind(void 0,4),Q2.bind(void 0,5),Q2.bind(void 0,6),Q2.bind(void 0,7),Q2.bind(void 0,8),e3.bind(void 0,1),e3.bind(void 0,2),e3.bind(void 0,3),e3.bind(void 0,4),e3.bind(void 0,5),e3.bind(void 0,6),e3.bind(void 0,7),e3.bind(void 0,8),u1.bind(void 0,0,0,0,0,0),u1.bind(void 0,0,0,0,0,1),u1.bind(void 0,0,0,0,0,2),u1.bind(void 0,0,0,0,0,3),u1.bind(void 0,0,0,0,1,0),u1.bind(void 0,0,0,0,1,1),u1.bind(void 0,0,0,0,1,2),u1.bind(void 0,0,0,0,1,3),u1.bind(void 0,0,0,1,0,0),u1.bind(void 0,0,0,1,0,1),u1.bind(void 0,0,0,1,0,2),u1.bind(void 0,0,0,1,0,3),u1.bind(void 0,0,0,1,1,0),u1.bind(void 0,0,0,1,1,1),u1.bind(void 0,0,0,1,1,2),u1.bind(void 0,0,0,1,1,3),u1.bind(void 0,0,1,0,0,0),u1.bind(void 0,0,1,0,0,1),u1.bind(void 0,0,1,0,0,2),u1.bind(void 0,0,1,0,0,3),u1.bind(void 0,0,1,0,1,0),u1.bind(void 0,0,1,0,1,1),u1.bind(void 0,0,1,0,1,2),u1.bind(void 0,0,1,0,1,3),u1.bind(void 0,0,1,1,0,0),u1.bind(void 0,0,1,1,0,1),u1.bind(void 0,0,1,1,0,2),u1.bind(void 0,0,1,1,0,3),u1.bind(void 0,0,1,1,1,0),u1.bind(void 0,0,1,1,1,1),u1.bind(void 0,0,1,1,1,2),u1.bind(void 0,0,1,1,1,3),u1.bind(void 0,1,0,0,0,0),u1.bind(void 0,1,0,0,0,1),u1.bind(void 0,1,0,0,0,2),u1.bind(void 0,1,0,0,0,3),u1.bind(void 0,1,0,0,1,0),u1.bind(void 0,1,0,0,1,1),u1.bind(void 0,1,0,0,1,2),u1.bind(void 0,1,0,0,1,3),u1.bind(void 0,1,0,1,0,0),u1.bind(void 0,1,0,1,0,1),u1.bind(void 0,1,0,1,0,2),u1.bind(void 0,1,0,1,0,3),u1.bind(void 0,1,0,1,1,0),u1.bind(void 0,1,0,1,1,1),u1.bind(void 0,1,0,1,1,2),u1.bind(void 0,1,0,1,1,3),u1.bind(void 0,1,1,0,0,0),u1.bind(void 0,1,1,0,0,1),u1.bind(void 0,1,1,0,0,2),u1.bind(void 0,1,1,0,0,3),u1.bind(void 0,1,1,0,1,0),u1.bind(void 0,1,1,0,1,1),u1.bind(void 0,1,1,0,1,2),u1.bind(void 0,1,1,0,1,3),u1.bind(void 0,1,1,1,0,0),u1.bind(void 0,1,1,1,0,1),u1.bind(void 0,1,1,1,0,2),u1.bind(void 0,1,1,1,0,3),u1.bind(void 0,1,1,1,1,0),u1.bind(void 0,1,1,1,1,1),u1.bind(void 0,1,1,1,1,2),u1.bind(void 0,1,1,1,1,3)];function K3(t){this.char=t,this.state={},this.activeState=null}function wt(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function ro(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function v2(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 _e(t){this.eventId=t,this.subscribers=[]}function co(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(c){Object.defineProperty(e.events,c,{value:new _e(c)})}),t&&n.forEach(function(c){var a=t[c];typeof a=="function"&&e.events[c].subscribe(a)});var r=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];r.forEach(function(c){e.events[c].subscribe(e.updateContextsRanges)})}function x0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],co.call(this,t)}K3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};K3.prototype.getState=function(t){return this.state[t]||null};x0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};x0.prototype.composeRUD=function(t){var e=this,n=!0,r=t.map(function(a){return e[a[0]].apply(e,a.slice(1).concat(n))}),c=function(a){return typeof a=="object"&&a.hasOwnProperty("FAIL")};if(r.every(c))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:r.filter(c)};this.dispatch("composeRUD",[r.filter(function(a){return!c(a)})])};x0.prototype.replaceRange=function(t,e,n,r){e=e!==null?e:this.tokens.length;var c=n.every(function(s){return s instanceof K3});if(!isNaN(t)&&this.inboundIndex(t)&&c){var a=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return r||this.dispatch("replaceToken",[t,e,n]),[a,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};x0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof K3){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."}};x0.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};x0.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."}};x0.prototype.insertToken=function(t,e,n){var r=t.every(function(c){return c instanceof K3});return r?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};x0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(r,c){var a=[r,c],s=e===null||e.apply(this,a)===!0,o=[r,c];if(s){var i=n.apply(this,o);r.setState(t,i)}}),this.registeredModifiers.push(t)};_e.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};_e.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};v2.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)};v2.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}};x0.prototype.rangeToText=function(t){if(t instanceof wt)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};x0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};x0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};x0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};x0.prototype.dispatch=function(t,e){var n=this,r=this.events[t];r instanceof _e&&r.subscribers.forEach(function(c){c.apply(n,e||[])})};x0.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 ro(t,e,n);return this.registeredContexts[t]=r,this.contextCheckers.push(r),r};x0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};x0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};x0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};x0.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 v2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};x0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,r=new wt(n,t,e),c=this.getContext(e).ranges;return r.rangeId=e+"."+c.length,c.push(r),this.getContext(e).openRange=null,r};x0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(r){var c=r.contextName,a=e.getContext(c).openRange;if(!a&&r.checkStart(t)&&(a=new wt(n,null,c),e.getContext(c).openRange=a,e.dispatch("contextStart",[c,n])),a&&r.checkEnd(t)){var s=n-a.startIndex+1,o=e.setEndOffset(s,c);e.dispatch("contextEnd",[c,o])}})};x0.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],c=new v2(e,n);this.dispatch("next",[c]),this.runContextCheck(c);var a=new K3(r);this.tokens.push(a),this.dispatch("newToken",[a,c])}return this.dispatch("end",[this.tokens]),this.tokens};function r3(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function i8(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 c3(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function $e(t){return/[A-z]/.test(t)}function ao(t){return/\s/.test(t)}function s2(t){this.font=t,this.features={}}function w3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function W5(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 c=n[r];if(t>=c.start&&t<=c.end){var a=t-c.start;return c.index+a}}break;default:return-1}return-1}function so(t,e){var n=W5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function oo(t,e){var n=W5(t,e.coverage);return n===-1?null:e.substitute[n]}function rt(t,e){for(var n=[],r=0;r<t.length;r++){var c=t[r],a=e.current;a=Array.isArray(a)?a[0]:a;var s=W5(a,c);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function io(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=rt(e.inputCoverage,t);if(r===-1)return[];var c=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(c);a.length&&c3(a[0].char);)a.shift();var s=new v2(a,0),o=rt(e.lookaheadCoverage,s),i=[].concat(t.backtrack);for(i.reverse();i.length&&c3(i[0].char);)i.shift();if(i.length<e.backtrackCoverage.length)return[];var l=new v2(i,0),h=rt(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 p=e.lookupRecords[d],m=p.lookupListIndex,g=this.getLookupByIndex(m),v=0;v<g.subtables.length;v++){var b=g.subtables[v],y=this.getLookupMethod(g,b),x=this.getSubstitutionType(g,b);if(x==="12")for(var w=0;w<r.length;w++){var M=t.get(w),k=y(M);k&&f.push(k)}}return f}function lo(t,e){var n=t.current,r=W5(n,e.coverage);if(r===-1)return null;for(var c,a=e.ligatureSets[r],s=0;s<a.length;s++){c=a[s];for(var o=0;o<c.components.length;o++){var i=t.lookahead[o],l=c.components[o];if(i!==l)break;if(o===c.components.length-1)return c}}return null}function ho(t,e){var n=W5(t,e.coverage);return n===-1?null:e.sequences[n]}s2.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[]};s2.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 c=n[r];if(c.tag===t&&c.script.defaultLangSys)return c.script.defaultLangSys.featureIndexes;var a=c.langSysRecords;if(a)for(var s=0;s<a.length;s++){var o=a[s];if(o.tag===t){var i=o.langSys;return i.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};s2.prototype.mapTagsToFeatures=function(t,e){for(var n={},r=0;r<t.length;r++){var c=t[r].tag,a=t[r].feature;n[c]=a}this.features[e].tags=n};s2.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(c){return r.features[c]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};s2.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),r=e.substFormat.toString();return n+r};s2.prototype.getLookupMethod=function(t,e){var n=this,r=this.getSubstitutionType(t,e);switch(r){case"11":return function(c){return so.apply(n,[c,e])};case"12":return function(c){return oo.apply(n,[c,e])};case"63":return function(c){return io.apply(n,[c,e])};case"41":return function(c){return lo.apply(n,[c,e])};case"21":return function(c){return ho.apply(n,[c,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};s2.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 c=this.getFeatureLookups(r),a=[].concat(e.context),s=0;s<c.length;s++)for(var o=c[s],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&&a.splice(n,1,new w3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new w3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new w3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new w3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new w3({id:21,tag:t.tag,substitution:d}));break}e=new v2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};s2.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};s2.prototype.getLookupSubtables=function(t){return t.subtables||null};s2.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};s2.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};s2.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 uo(t){var e=t.current,n=t.get(-1);return n===null&&r3(e)||!r3(n)&&r3(e)}function fo(t){var e=t.get(1);return e===null||!r3(e)}var mo={startCheck:uo,endCheck:fo};function po(t){var e=t.current,n=t.get(-1);return(r3(e)||c3(e))&&!r3(n)}function go(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!r3(e)&&!c3(e)):var n=ao(e);if(!n)return!0;if(n){var r=!1;if(r=t.lookahead.some(function(c){return r3(c)||c3(c)}),!r)return!0}break;default:return!1}}var vo={startCheck:po,endCheck:go};function yo(t,e,n){e[n].setState(t.tag,t.substitution)}function bo(t,e,n){e[n].setState(t.tag,t.substitution)}function xo(t,e,n){t.substitution.forEach(function(r,c){var a=e[n+c];a.setState(t.tag,r)})}function Mo(t,e,n){var r=e[n];r.setState(t.tag,t.substitution.ligGlyph);for(var c=t.substitution.components.length,a=0;a<c;a++)r=e[n+a+1],r.setState("deleted",!0)}var m7={11:yo,12:bo,63:xo,41:Mo};function kt(t,e,n){t instanceof w3&&m7[t.id]&&m7[t.id](t,e,n)}function wo(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],c=i8(r),a=c3(r);if(!c&&!a)return!0;if(c)return!1}return!1}function ko(t){if(i8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],r=c3(n);if(!r)return!0}return!1}function zo(t){var e=this,n="arab",r=this.featuresTags[n],c=this.tokenizer.getRangeTokens(t);if(c.length!==1){var a=new v2(c.map(function(o){return o.getState("glyphIndex")}),0),s=new v2(c.map(function(o){return o.char}),0);c.forEach(function(o,i){if(!c3(o.char)){a.setCurrentIndex(i),s.setCurrentIndex(i);var l=0;wo(s)&&(l|=1),ko(s)&&(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:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof w3&&(kt(f,c,d),a.context[d]=f.substitution)})}}})}}function p7(t,e){var n=t.map(function(r){return r.activeState.value});return new v2(n,e||0)}function So(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),c=p7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var o=e.query.lookupFeature({tag:"rlig",script:n,contextParams:c});o.length&&(o.forEach(function(i){return kt(i,r,s)}),c=p7(r))})}function Ao(t){var e=t.current,n=t.get(-1);return n===null&&$e(e)||!$e(n)&&$e(e)}function Lo(t){var e=t.get(1);return e===null||!$e(e)}var Co={startCheck:Ao,endCheck:Lo};function g7(t,e){var n=t.map(function(r){return r.activeState.value});return new v2(n,e||0)}function Po(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),c=g7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var o=e.query.lookupFeature({tag:"liga",script:n,contextParams:c});o.length&&(o.forEach(function(i){return kt(i,r,s)}),c=g7(r))})}function x2(t){this.baseDir=t||"ltr",this.tokenizer=new x0,this.featuresTags={}}x2.prototype.setText=function(t){this.text=t};x2.prototype.contextChecks={latinWordCheck:Co,arabicWordCheck:mo,arabicSentenceCheck:vo};function ct(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function Eo(){return ct.call(this,"latinWord"),ct.call(this,"arabicWord"),ct.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function To(){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())})}x2.prototype.registerFeatures=function(t,e){var n=this,r=e.filter(function(c){return n.query.supports({script:t,tag:c})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(r):this.featuresTags[t]=r};x2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new s2(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)}};x2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function zt(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Io(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){zt.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){zo.call(t,r)})}}function Vo(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){zt.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(c){So.call(t,c)})}}}function Ho(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){zt.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(c){Po.call(t,c)})}}}x2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};x2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Io.call(this),Vo.call(this)),this.checkContextReady("latinWord")&&Ho.call(this),this.checkContextReady("arabicSentence")&&To.call(this)};x2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),Eo.call(this),this.applyFeaturesToContexts())};x2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};x2.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 c=r.activeState.value;e.push(Array.isArray(c)?c[0]:c)}}return e};function a0(t){t=t||{},t.tables=t.tables||{},t.empty||(R5(t.familyName,"When creating a new Font object, familyName is required."),R5(t.styleName,"When creating a new Font object, styleName is required."),R5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),R5(t.ascender,"When creating a new Font object, ascender is required."),R5(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 I2.GlyphSet(this,t.glyphs||[]),this.encoding=new L7(this),this.position=new _5(this),this.substitution=new a2(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 c8(this)}})}a0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};a0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};a0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};a0.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})};a0.prototype.stringToGlyphs=function(t,e){var n=this,r=new x2,c=function(u){return n.charToGlyphIndex(u.char)};r.registerModifier("glyphIndex",null,c);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;r.applyFeatures(this,a);for(var s=r.getTextGlyphs(t),o=s.length,i=new Array(o),l=this.glyphs.get(0),h=0;h<o;h+=1)i[h]=this.glyphs.get(s[h])||l;return i};a0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};a0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};a0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};a0.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};a0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};a0.prototype.forEachGlyph=function(t,e,n,r,c,a){e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:72,c=Object.assign({},this.defaultRenderOptions,c);var s=1/this.unitsPerEm*r,o=this.stringToGlyphs(t,c),i;if(c.kerning){var l=c.script||this.position.getDefaultScriptName();i=this.position.getKerningTables(l,c.language)}for(var h=0;h<o.length;h+=1){var u=o[h];if(a.call(this,u,e,n,r,c),u.advanceWidth&&(e+=u.advanceWidth*s),c.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*s}c.letterSpacing?e+=c.letterSpacing*r:c.tracking&&(e+=c.tracking/1e3*r)}return e};a0.prototype.getPath=function(t,e,n,r,c){var a=new P0;return this.forEachGlyph(t,e,n,r,c,function(s,o,i,l){var h=s.getPath(o,i,l,c,this);a.extend(h)}),a};a0.prototype.getPaths=function(t,e,n,r,c){var a=[];return this.forEachGlyph(t,e,n,r,c,function(s,o,i,l){var h=s.getPath(o,i,l,c,this);a.push(h)}),a};a0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};a0.prototype.draw=function(t,e,n,r,c,a){this.getPath(e,n,r,c,a).draw(t)};a0.prototype.drawPoints=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,o,i,l){s.drawPoints(t,o,i,l)})};a0.prototype.drawMetrics=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,o,i,l){s.drawMetrics(t,o,i,l)})};a0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};a0.prototype.validate=function(){var t=this;function e(r,c){}function n(r){var c=t.getEnglishName(r);c&&c.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};a0.prototype.toTables=function(){return xa.fontToTable(this)};a0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};a0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),r=new Uint8Array(n),c=0;c<e.length;c++)r[c]=e[c];return n};a0.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(wa())if(window.URL=window.URL||window.webkitURL,window.URL){var c=new DataView(r),a=new Blob([c],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(a),s.download=t;var o=document.createEvent("MouseEvents");o.initEvent("click",!0,!1),s.dispatchEvent(o)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var i=In(),l=ka(r);i.writeFileSync(t,l)}};a0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};a0.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};a0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function l8(t,e){var n=JSON.stringify(t),r=256;for(var c in e){var a=parseInt(c);if(!(!a||a<256)){if(JSON.stringify(e[c])===n)return a;r<=a&&(r=a+1)}}return e[r]=t,r}function Oo(t,e,n){var r=l8(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 $o(t,e,n){var r={},c=new d1.Parser(t,e);return r.tag=c.parseTag(),r.minValue=c.parseFixed(),r.defaultValue=c.parseFixed(),r.maxValue=c.parseFixed(),c.skip("uShort",1),r.name=n[c.parseUShort()]||{},r}function Ro(t,e,n,r){for(var c=l8(e.name,r),a=[{name:"nameID_"+t,type:"USHORT",value:c},{name:"flags_"+t,type:"USHORT",value:0}],s=0;s<n.length;++s){var o=n[s].tag;a.push({name:"axis_"+t+" "+o,type:"FIXED",value:e.coordinates[o]<<16})}return a}function Fo(t,e,n,r){var c={},a=new d1.Parser(t,e);c.name=r[a.parseUShort()]||{},a.skip("uShort",1),c.coordinates={};for(var s=0;s<n.length;++s)c.coordinates[n[s].tag]=a.parseFixed();return c}function Do(t,e){var n=new o1.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(Oo(r,t.axes[r],e));for(var c=0;c<t.instances.length;c++)n.fields=n.fields.concat(Ro(c,t.instances[c],t.axes,e));return n}function qo(t,e,n){var r=new d1.Parser(t,e),c=r.parseULong();T1.argument(c===65536,"Unsupported fvar table version.");var a=r.parseOffset16();r.skip("uShort",1);for(var s=r.parseUShort(),o=r.parseUShort(),i=r.parseUShort(),l=r.parseUShort(),h=[],u=0;u<s;u++)h.push($o(t,e+a+u*o,n));for(var f=[],d=e+a+s*o,p=0;p<i;p++)f.push(Fo(t,d+p*l,h,n));return{axes:h,instances:f}}var No={make:Do,parse:qo},Uo=function(){return{coverage:this.parsePointer(N.coverage),attachPoints:this.parseList(N.pointer(N.uShortList))}},Bo=function(){var t=this.parseUShort();if(T1.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()}},_o=function(){return this.parseList(N.pointer(Bo))},jo=function(){return{coverage:this.parsePointer(N.coverage),ligGlyphs:this.parseList(N.pointer(_o))}},Go=function(){return this.parseUShort(),this.parseList(N.pointer(N.coverage))};function Wo(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);T1.argument(r===1||r===1.2||r===1.3,"Unsupported GDEF table version.");var c={version:r,classDef:n.parsePointer(N.classDef),attachList:n.parsePointer(Uo),ligCaretList:n.parsePointer(jo),markAttachClassDef:n.parsePointer(N.classDef)};return r>=1.2&&(c.markGlyphSets=n.parsePointer(Go)),c}var Xo={parse:Wo},y2=new Array(10);y2[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()};T1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};y2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();T1.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),c=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,pairSets:this.parseList(N.pointer(N.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(N.classDef),o=this.parsePointer(N.classDef),i=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,classDef1:s,classDef2:o,class1Count:i,class2Count:l,classRecords:this.parseList(i,N.list(l,function(){return{value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}}))}}};y2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};y2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};y2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};y2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};y2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};y2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};y2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Zo(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return T1.argument(r===1||r===1.1,"Unsupported GPOS table version "+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(y2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(y2),variations:n.parseFeatureVariationsList()}}var Yo=new Array(10);function Jo(t){return new o1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new o1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new o1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new o1.LookupList(t.lookups,Yo)}])}var Ko={parse:Zo,make:Jo};function Qo(t){var e={};t.skip("uShort");var n=t.parseUShort();T1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var r=t.parseUShort();t.skip("uShort",3);for(var c=0;c<r;c+=1){var a=t.parseUShort(),s=t.parseUShort(),o=t.parseShort();e[a+","+s]=o}return e}function ei(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(),c=r&255;if(t.skip("uShort"),c===0){var a=t.parseUShort();t.skip("uShort",3);for(var s=0;s<a;s+=1){var o=t.parseUShort(),i=t.parseUShort(),l=t.parseShort();e[o+","+i]=l}}return e}function ti(t,e){var n=new d1.Parser(t,e),r=n.parseUShort();if(r===0)return Qo(n);if(r===1)return ei(n);throw new Error("Unsupported kern table version ("+r+").")}var ni={parse:ti};function ri(t,e,n,r){for(var c=new d1.Parser(t,e),a=r?c.parseUShort:c.parseULong,s=[],o=0;o<n+1;o+=1){var i=a.call(c);r&&(i*=2),s.push(i)}return s}var ci={parse:ri};function v7(t,e){for(var n=[],r=12,c=0;c<e;c+=1){var a=d1.getTag(t,r),s=d1.getULong(t,r+4),o=d1.getULong(t,r+8),i=d1.getULong(t,r+12);n.push({tag:a,checksum:s,offset:o,length:i,compression:!1}),r+=16}return n}function ai(t,e){for(var n=[],r=44,c=0;c<e;c+=1){var a=d1.getTag(t,r),s=d1.getULong(t,r+4),o=d1.getULong(t,r+8),i=d1.getULong(t,r+12),l=void 0;o<i?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:o,length:i}),r+=20}return n}function k0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),r=new Uint8Array(e.length);if(Jr(n,r),r.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var c=new DataView(r.buffer,0);return{data:c,offset:0}}else return{data:t,offset:e.offset}}function h8(t,e){e=e??{};var n,r,c=new a0({empty:!0}),a=new DataView(t,0),s,o=[],i=d1.getTag(a,0);if(i==="\0\0\0"||i==="true"||i==="typ1")c.outlinesFormat="truetype",s=d1.getUShort(a,4),o=v7(a,s);else if(i==="OTTO")c.outlinesFormat="cff",s=d1.getUShort(a,4),o=v7(a,s);else if(i==="wOFF"){var l=d1.getTag(a,4);if(l==="\0\0\0")c.outlinesFormat="truetype";else if(l==="OTTO")c.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+i);s=d1.getUShort(a,12),o=ai(a,s)}else throw new Error("Unsupported OpenType signature "+i);for(var h,u,f,d,p,m,g,v,b,y,x,w,M=0;M<s;M+=1){var k=o[M],z=void 0;switch(k.tag){case"cmap":z=k0(a,k),c.tables.cmap=A7.parse(z.data,z.offset),c.encoding=new C7(c.tables.cmap);break;case"cvt ":z=k0(a,k),w=new d1.Parser(z.data,z.offset),c.tables.cvt=w.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=k0(a,k),w=new d1.Parser(z.data,z.offset),c.tables.fpgm=w.parseByteList(k.length);break;case"head":z=k0(a,k),c.tables.head=F7.parse(z.data,z.offset),c.unitsPerEm=c.tables.head.unitsPerEm,n=c.tables.head.indexToLocFormat;break;case"hhea":z=k0(a,k),c.tables.hhea=D7.parse(z.data,z.offset),c.ascender=c.tables.hhea.ascender,c.descender=c.tables.hhea.descender,c.numberOfHMetrics=c.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":z=k0(a,k),r=N7.parse(z.data,z.offset);break;case"maxp":z=k0(a,k),c.tables.maxp=U7.parse(z.data,z.offset),c.numGlyphs=c.tables.maxp.numGlyphs;break;case"name":y=k;break;case"OS/2":z=k0(a,k),c.tables.os2=ft.parse(z.data,z.offset);break;case"post":z=k0(a,k),c.tables.post=X7.parse(z.data,z.offset),c.glyphNames=new yt(c.tables.post);break;case"prep":z=k0(a,k),w=new d1.Parser(z.data,z.offset),c.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":p=k;break;case"GSUB":m=k;break;case"meta":x=k;break}}var A=k0(a,y);if(c.tables.name=W7.parse(A.data,A.offset,r),c.names=c.tables.name,f&&b){var S=n===0,C=k0(a,b),I=ci.parse(C.data,C.offset,c.numGlyphs,S),L=k0(a,f);c.glyphs=t8.parse(L.data,L.offset,I,c,e)}else if(h){var T=k0(a,h);R7.parse(T.data,T.offset,c,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var q=k0(a,g);if(q7.parse(c,q.data,q.offset,c.numberOfHMetrics,c.numGlyphs,c.glyphs,e),yc(c,e),v){var P=k0(a,v);c.kerningPairs=ni.parse(P.data,P.offset)}else c.kerningPairs={};if(d){var F=k0(a,d);c.tables.gdef=Xo.parse(F.data,F.offset)}if(p){var j=k0(a,p);c.tables.gpos=Ko.parse(j.data,j.offset),c.position.init()}if(m){var _=k0(a,m);c.tables.gsub=Z7.parse(_.data,_.offset)}if(u){var Q=k0(a,u);c.tables.fvar=No.parse(Q.data,Q.offset,c.names)}if(x){var H=k0(a,x);c.tables.meta=Y7.parse(H.data,H.offset),c.metas=c.tables.meta}return c}function u8(t,e){let n=t.tables?.os2?.sCapHeight;if(n&&n>0)return n/t.unitsPerEm*e;let r=w0(St(t,"H",{size:e,font:"",halign:"left",valign:"baseline",spacing:1}).polys);return r?r[3]:t.ascender/t.unitsPerEm*e}var je=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 c=K0(this.sources,n);if(!c)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let a=c instanceof Uint8Array?c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength):c,s=h8(a);return this.parsed.set(n,s),s}};function si(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 c=[],a=0,s=[...e];return s.forEach((o,i)=>{c.push(...t.getPath(o,a,0,n.size,r).commands),a+=t.getAdvanceWidth(o,n.size,r)*(i<s.length-1?n.spacing:1)}),{cmds:c,advance:a}}function St(t,e,n){let{cmds:r,advance:c}=si(t,e,n),a=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}),s=G3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(o=>o.length>=3)],advance:c}}function Ge(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:c,advance:a}=St(r,e,n),s=s1(c),o=w0(s);if(!o)return[];let i=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-o[3]:n.valign==="center"?-(o[1]+o[3])/2:n.valign==="bottom"?-o[1]:n.valign==="cap"?-u8(r,n.size)/2:0;return s.map(h=>h.map(([u,f])=>[u+i,f+l]))}function At(t,e,n){let r=t.get(n.font),{polys:c,advance:a}=St(r,e,n),s=w0(c)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:r.ascender/r.unitsPerEm*n.size,descent:r.descender/r.unitsPerEm*n.size,cap:u8(r,n.size)}}var f8=Math.PI/180,Lt=128,We=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],m8={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function oi(t,e){if(!t||K0(Tt,t)!==void 0)return;let n=t.split("\\").join("/"),r=e.split("\\").join("/");if(r.startsWith("/")||/^[A-Za-z]:\//.test(r))return;let c=n.lastIndexOf("/");if(c<0)return;let a=[...n.slice(0,c).split("/"),...r.split("/")],s=[];for(let o of a)o===".."&&s.length&&s[s.length-1]!==".."?s.pop():o!=="."&&o!==""&&s.push(o);return(n.startsWith("/")?"/":"")+s.join("/")}var ii=100,li={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},Q3=4,d8=8,hi=t=>{let e=ii,n=r=>{for(let c of r.values()){for(let a of c.regions)e+=a.length;for(let a of c.lines)e+=a.length}};n(t.layers);for(let r of t.parts)n(r.layers);return e},E0=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}},Ct=t=>t?`.${t}`:"",Pt=(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`,ui={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."},Et=["echo","assert","text_width","text_metrics","text_size","finger_count"];function z3(t,e){let n="",r=Math.min(2,Math.floor(t.length/3))+.5;for(let c of new Set(e)){if(c===t)continue;let a=c.toLowerCase()===t.toLowerCase()?0:fi(t,c);a<r&&([n,r]=[c,a])}return n?` Did you mean "${n}"?`:""}function fi(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(r,c)=>[c,...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 c=1;c<=e.length;c++)n[r][c]=Math.min(n[r-1][c]+1,n[r][c-1]+1,n[r-1][c-1]+(t[r-1]===e[c-1]?0:1)),r>1&&c>1&&t[r-1]===e[c-2]&&t[r-2]===e[c-1]&&(n[r][c]=Math.min(n[r][c],n[r-2][c-2]+1));return n[t.length][e.length]}var Tt=$5,s3=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=$4;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(We.map(e=>[e.name,e]));this.loaded=new Map;this.clashed=new Set;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...m8,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new E0,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 c=new E0(n),a=this.block(e.body,c,!0),s=c.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${r2(this.unscaled,!1)})`),{shape:a,globals:c,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new l1(`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=oi(n.file,e),c=e,a=K0(Tt,e);if(a===void 0&&r!==void 0){let o=this.loaded.get(r);if(o)return o;a=this.opts.resolve?.(r),typeof a=="string"&&(c=r)}if(c===e){let o=this.loaded.get(e);if(o)return o;a??(a=this.opts.resolve?.(e))}if(typeof a!="string")throw new l1(`Library <${e}> not found`,n);this.loaded.set(c,{body:[]});let{program:s}=c2(a,c);return this.loaded.set(c,s),s}hoist(e,n){for(let r of e)if((r.kind==="module"||r.kind==="function")&&(r.pos.file===void 0||K0(Tt,r.pos.file)===void 0)&&(r.kind==="module"?K0(this.builtins,r.name)!==void 0:K0(T5,r.name)!==void 0||Et.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${r2(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 c=this.included(this.load(r.path,r.pos).body,new Set([r.path])),a=new E0(n);this.hoist(c,a);for(let s of c)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,o]of a.mods)this.clash("module",s,n.mods.get(s),o),n.mods.set(s,o);for(let[s,o]of a.fns)this.clash("function",s,n.fns.get(s),o),n.fns.set(s,o)}finally{this.using.pop()}}}clash(e,n,r,c){!r||r.body===c.body||!r.pos?.file||!c.pos?.file||r.pos.file===c.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 <${c.pos.file}> (line ${c.pos.line}); the one in <${c.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 c=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,o=[];for(let l=c.length-1;l>=0;l--)o.push({text:";"},c[l][1],{text:`${c[l][0]}=`});for(;o.length;){if(s>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(h2(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(G0(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"";a.push(h),s+=h.length}let i=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${this.layerDefs}|${i}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies},${this.layerDefs}`}enter(e,n,r,c){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new l1(a.length===2?`Library ${a[0]} ${c}s itself`:`Libraries ${c} each other in a loop: ${a.join(" \u2192 ")}`,r)}e.push(n)}included(e,n){let r=[];for(let c of e)if(c.kind!=="use"||!c.include)r.push(c);else if(!n.has(c.path)){n.add(c.path);for(let a of this.included(this.load(c.path,c.pos).body,n))r.push(a)}return r}assign(e,n,r){r.vars.set(e,n)}block(e,n,r=!1){this.hoist(e,n);let c=[];for(let a of e){let s=this.stmt(a,n,r);s&&!R6(s)&&c.push(s)}return c.length===1?c[0]:C2(c)}stmt(e,n,r=!1){switch(this.tick(e.pos),e.kind){case"assign":{let c=this.opts.overrides,a=r&&c&&Object.prototype.hasOwnProperty.call(c,e.name)?c[e.name]:this.expr(e.value,n);return this.assign(e.name,a,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 E0(n));case"if":return y0(this.expr(e.cond,n))?this.block(e.then,new E0(n)):this.block(e.else,new E0(n));case"let":{let c=new E0(n);return this.bindSeq(e.assigns,c),this.block(e.body,c)}case"for":{let c=[];return this.loop(e.assigns,n,a=>c.push(this.block(e.body,a))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:n,children:()=>C2(c),childList:()=>c,childSeq:()=>c,childItems:()=>c}):C2(c)}case"call":if(e.modifier==="*")return null;{let c=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?S5(c,"guide"):c}}}bindSeq(e,n){for(let r of e)this.assign(r.name,this.expr(r.value,n),n)}iterable(e,n){if(h2(e))try{return Ae(e,this.limits.maxListLength)}catch(r){throw new l1(r.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,r,c=0,a=new E0(n)){if(c===e.length)return r(a);let s=e[c];for(let o of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let i=new E0(a);i.vars.set(s.name,o),this.loop(e,n,r,c+1,i)}}evalArgs(e,n,r){let c=[],a=new Map,s=[];for(let o of e){let i=this.expr(o.value,n);o.name===null?c.push(i):a.set(o.name,i),s.push({name:o.name,value:i})}return{pos:c,named:a,all:s,at:r}}bindParams(e,n,r,c,a){let s=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("$")&&!s.includes(o)&&this.unknownArg(a,o,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let r=O5(e);if(!r)return;let c=r.params.map(a=>a.name);if(!r.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!c.includes(a)&&this.unknownArg(`${e}()`,a,n.at,c);r.rest||this.checkCount(`${e}()`,r.params.filter(a=>!a.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 (${r2(r.at,!1)})`)}unknownArg(e,n,r,c){this.warn(`${e}: unknown argument "${n}"${Ct(z3(n,c))} (${r2(r,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let r=e.args.findIndex(s=>s.name==="name"),c=r>=0?r:e.args.findIndex(s=>s.name===null);if(c<0)throw new l1("call() needs the name of a module",e.pos);let a=this.expr(e.args[c].value,n);if(typeof a!="string")throw new l1(`call() needs a module's name as a string, got ${F0(a)}`,e.pos);if(a==="call")throw new l1("call() can't call itself",e.pos);return this.callModule({...e,name:a,args:e.args.filter((s,o)=>o!==c)},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),c=n.mod(e.name);if(c){if(++this.depth>1e3)throw new l1(Pt("module",e.name),e.pos);try{let d=new E0(c.env,n);return this.bindParams(c.params,r,d,c.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(c.body,d)}catch(d){throw this.inCall(d,"module",e.name,e.pos)}finally{this.depth--}}let a=K0(this.builtins,e.name),s=K0(ui,e.name);if(!a&&s)return this.warn(`${e.name}() is ignored: ${s} (${r2(e.pos,!1)})`),e.children.length?this.block(e.children,new E0(n,n)):T0();if(!a){let d=z3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new l1(`Unknown module ${e.name}().${d}`,e.pos)}this.checkArgs(e.name,r);let o=new E0(n,n);for(let[d,p]of r.named)d.startsWith("$")&&o.vars.set(d,p);let i=this.childStmts(e.children),l=()=>new E0(n,o),h={args:r,env:o,children:()=>e.children.length?this.block(e.children,l()):T0(),childList:()=>{let d=l();this.hoist(e.children,d);let p=[];for(let m of e.children){let g=this.stmt(m,d);i.includes(m)&&p.push(g??T0())}return p},childItems:()=>{let d=l();this.hoist(e.children,d);let p=[];for(let m of e.children){if(i.includes(m)&&m.kind==="for"&&!m.intersect){this.tick(m.pos),this.loop(m.assigns,d,v=>p.push(this.block(m.body,v)));continue}let g=this.stmt(m,d);i.includes(m)&&p.push(g??T0())}return p},childSeq:d=>{let p=l();this.hoist(e.children,p);let m=[];for(let g of e.children){let v=this.stmt(g,p);i.includes(g)&&(m.push(v??T0()),d(m.length-1,v??T0()))}return m}},u;try{u=a(h)}catch(d){if(d instanceof l1||d instanceof RangeError)throw d;let p=new l1(`${e.name}(): ${d.message}`,e.pos);throw p.call=e.name,p}let f=hi(u);if(e.name!=="children"&&(this.pointCount+=f),f>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new l1(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,c){if(++this.depth>2e3)throw new l1(Pt("function",c),n.at);try{this.tick(n.at);let a=p2(e)?e.scope:e.env,s=new E0(a,r);return this.bindParams(e.params,n,s,a,`${c}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",c,n.at)}finally{this.depth--}}inCall(e,n,r,c){return e instanceof Error&&!(e instanceof l1)&&e.message.includes("call stack")?new l1(Pt(n,r),c):(e instanceof l1&&e.addFrame(n,r,c),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":{let r=n.get(e.name);if(r.found)return r.value;let c=n.fn(e.name);if(c)return{type:"function",params:c.params,body:c.body,scope:c.env,name:e.name};if(e.name.startsWith("$"))return;throw new l1(`Unknown variable "${e.name}"${Ct(z3(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let r=[];for(let c of e.items)this.listItem(c,n,r,e.pos);return this.charge(Q3,e.pos),r}case"range":{let r=this.expr(e.start,n),c=this.expr(e.end,n),a=e.step?this.expr(e.step,n):1;if(typeof r!="number"||typeof c!="number"||typeof a!="number")throw new l1("Range values must be numbers",e.pos);return{type:"range",start:r,step:a,end:c}}case"unary":{let r=this.expr(e.arg,n);return e.op==="!"?!y0(r):e.op==="+"?r:this.arith("*",-1,r,e.pos)}case"binary":{if(e.op==="&&")return y0(this.expr(e.left,n))&&y0(this.expr(e.right,n));if(e.op==="||")return y0(this.expr(e.left,n))||y0(this.expr(e.right,n));let r=this.expr(e.left,n),c=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return _3(r,c,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof r=="number"&&typeof c=="number"||typeof r=="string"&&typeof c=="string"))throw new l1(`Can't compare ${F0(r)} ${e.op} ${F0(c)}`,e.pos);return e.op==="<"?r<c:e.op==="<="?r<=c:e.op===">"?r>c:r>=c}return this.arith(e.op,r,c,e.pos)}case"ternary":return y0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let r=this.expr(e.target,n),c=this.expr(e.index,n);if(G0(r)&&typeof c=="string")return r.fields.get(c);if(typeof c!="number")throw new l1(`List index must be a number, got ${F0(c)}`,e.pos);return Array.isArray(r)?r[Math.floor(c)]:typeof r=="string"?[...r][Math.floor(c)]:h2(r)?[r.start,r.step,r.end][Math.floor(c)]:void 0}case"record":return this.record(e,n);case"member":{let r=this.expr(e.target,n);if(G0(r))return r.fields.get(e.name);let c={x:0,y:1,z:2}[e.name];return Array.isArray(r)&&c!==void 0?r[c]:h2(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 E0(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,c){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(r,1,c),r.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),c);this.grow(r,a.length,c);for(let s of a)r.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,r,c));return;case"if":y0(this.expr(e.cond,n))?this.listItem(e.then,n,r,c):e.else&&this.listItem(e.else,n,r,c);return;case"let":{let a=new E0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,r,c)}}}grow(e,n,r){if(e.length+n>this.limits.maxListLength)throw new l1(`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 l1(`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 c=e.callee.name,a=n.get(c),s=a.found&&!p2(a.value);if(!a.found||s&&this.callable(c,n)){let o=n.fn(c);if(o)return this.callFunction(o,this.evalArgs(e.args,n,e.pos),n,c);let i=this.specialFunction(c,e,n);if(i.handled)return i.value;let l=K0(T5,c);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(c,h);for(let p of kn(l,h.pos,h.named))this.warn(`${c}(): "${p}" is given by position and by name; the named value is used (${r2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:p=>this.tick(e.pos,p),given:h.pos.length+l.params.filter(p=>h.named.has(p)).length,apply:(p,m)=>{if(!p2(p))throw new Error(`${c}() needs a function, got ${F0(p)}`);return this.callFunction(p,{pos:m,named:new Map,all:m.map(g=>({name:null,value:g})),at:e.pos},n,"function")}},f=zn(l,h.pos,h.named);this.tick(e.pos,Sn(c,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(p){if(p instanceof l1)throw p;let m=new l1(p instanceof RangeError?`${c}(): the result is too large`:p.message,e.pos);throw m.call=c,m}return this.checkValue(d,e.pos,c),d}throw new l1(`Unknown function ${c}()${Ct(z3(c,[...n.names("fns"),...n.names("vars"),...Object.keys(T5),...Et]))}`,e.pos)}if(!p2(a.value))throw new l1(`"${c}" is a ${F0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,c)}let r=this.expr(e.callee,n);if(!p2(r))throw new l1(`Can't call a ${F0(r)}`,e.pos);return this.callFunction(r,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,r,c){let a=s=>Array.isArray(r)?String(r[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let o=a(s),i=s1(e.flatMap((h,u)=>u<s&&a(u)===o?n[u]:[]));!i.length||g0(n[s],i).reduce((h,u)=>h+Math.abs(b1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(r)&&o?` "${o}"`:""} under it, so it can't be seen (${r2(c,!1)})`)}}record(e,n){let r=new Map;for(let c of e.fields)r.set(c.name,this.expr(c.value,n));return{type:"record",fields:r}}length(e,n){let r=U0(n.get("$scale").value??1);if(!(r>0))throw new l1("$scale must be a number more than 0",e.pos);return r===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*li[e.unit]/r}callable(e,n){return!!n.fn(e)||Et.includes(e)||!!K0(T5,e)}specialFunction(e,n,r){if(e==="echo"){let c=this.evalArgs(n.args,r,n.pos);return this.echo(this.echoText(c),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let c=this.evalArgs(n.args,r,n.pos);return this.checkArgs(e,c),this.assert(c),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"||e==="text_size"){let c=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,c);let a=this.measure(c,r);return e==="text_width"?{handled:!0,value:a.advance}:e==="text_size"?{handled:!0,value:{type:"record",fields:new Map([["width",a.advance],["height",a.bounds[1][1]-a.bounds[0][1]],["bounds",a.bounds],["cap",a.cap],["ascent",a.ascent],["descent",a.descent],["size",a.size]])}}:{handled:!0,value:[a.advance,a.bounds,a.ascent,a.descent]}}if(e==="finger_count"){let c=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,c);let a=this.num(this.arg(c,"length",0),"finger_count","length");return{handled:!0,value:v3(a,this.fingerWidth(c,r,1))}}return{handled:!1}}assert(e){if(y0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new l1(`Assertion failed${n===void 0?"":": "+b0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/d8);this.charge(r,n),this.retained+=r,this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,r=[],c=0,a=(s,o,i)=>{r.length&&(c+=2);let l=j3(o,n-c-s.length,i);if(c+=s.length+l.text.length,!l.whole)throw new l1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);r.push(s+l.text)};for(let{name:s,value:o}of e.all)s===null?a("",o,!1):a(`${s} = `,o,!0);return r.join(", ")}arith(e,n,r,c){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,c),n+r;if(Array.isArray(n)&&Array.isArray(r)){if(e==="+"||e==="-"){if(n.length!==r.length)throw new l1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${r.length}`,c);return this.charge(n.length+Q3,c),n.map((s,o)=>this.arith(e,s,r[o],c))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+Q3,c),n.map(o=>this.arith("*",o,r,c));let s=(o,i)=>{let l=this.arith("*",o,i,c);if(typeof l!="number")throw new l1("Can't multiply these lists: an item times an item is not a number",c);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 l1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,c);return this.checkSize(o,!1,c),this.tick(c,o*n.length),Array.from({length:o},(i,l)=>n.reduce((h,u,f)=>h+s(u,r[f][l]),0))}if(n.length!==r.length)throw new l1(`Can't multiply lists of length ${n.length} and ${r.length}`,c);return this.tick(c,n.length),n.reduce((o,i,l)=>o+s(i,r[l]),0)}}if(Array.isArray(n)&&typeof r=="number"&&(e==="*"||e==="/"))return this.charge(n.length+Q3,c),n.map(s=>this.arith(e,s,r,c));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+Q3,c),r.map(s=>this.arith(e,n,s,c));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new l1(`Can't ${a[e]??e} ${F0(n)} and ${F0(r)}`,c)}fieldFn(e,n,r,c){if(!p2(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${C0(e)}`);return a=>{let s=this.itemCount,o=this.retained,i=this.callFunction(e,{pos:[a],named:new Map,all:[{name:null,value:a}],at:c},r,"field");return(!Array.isArray(i)||i.length<=3)&&(this.itemCount=s+this.retained-o),i}}arg(e,n,r,c){return e.named.has(n)?e.named.get(n):r>=0&&r<e.pos.length?e.pos[r]:c}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 c=a=>typeof a=="number"&&Number.isFinite(a);if(c(e)&&r)return[e,e];if(Array.isArray(e)&&c(e[0])&&(e[1]===void 0||c(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=c=>typeof c=="number"&&Number.isFinite(c);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 c=(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)],a=c(e,"at"),s=c(n,"rotate");for(let[o,i]of[[a,"at"],[s,"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:a[a.length===1?0:i],rotate:s[s.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,c)=>{if(!Array.isArray(r)||!Number.isFinite(r[0])||!Number.isFinite(r[1]))throw new Error(`${n}[${c}] 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,c){if(e>this.limits.maxListLength)throw new l1(`${c?`${c}(): `:""}${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/d8):e+Q3,r)}segs(e){let n=U0(this.dyn(e,"$fn"))||0,r=U0(this.dyn(e,"$fa"))||2,c=U0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let o=q6(s,n,r,c);if(!(o<=a))throw new Error(`a circle with ${o} segments is more than the limit of ${a}. Lower $fn, or raise $fa or $fs.`);return o}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||n<=0)throw new Error("$thickness must be a positive number");return n}fingerWidth(e,n,r){let c=this.arg(e,"finger",r);return typeof c=="number"&&c>0?c:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new l1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let r=j3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!r.whole)throw new l1(`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 c=this.textOpts(e,n,r.text);return{...At(this.opts.fonts,r.text,c),size:c.size}}catch(c){throw c instanceof l1?c:new l1(c.message,e.at)}}textOpts(e,n,r){let c={size:this.num(this.arg(e,"size",1,10),"text","size"),font:b0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:b0(this.arg(e,"halign",-1,"left")),valign:b0(this.arg(e,"valign",-1,"baseline")),spacing:U0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&r!==void 0&&this.opts.fonts){let[s,o]=Array.isArray(a)?[a[0],a[1]]:[a,void 0],i=(d,p)=>{if(d===void 0)return;let m=this.num(d,"text","fit");if(!(m>0))throw new Error(`fit must be a ${p} more than 0`);return m},l=i(s,"width"),h=i(o,"height");if(Array.isArray(a)&&(a.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=At(this.opts.fonts,r,{...c,size:1}),f=[...l!==void 0&&u.advance>0?[l/u.advance]:[],...h!==void 0&&u.cap>0?[h/u.cap]:[]];if(f.length){let d=this.arg(e,"size",1);c.size=Math.min(...f,...d===void 0?[]:[c.size])}}return c}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 c=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...c,name:n,side:"back"}),this.layerDefs++}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((r,c)=>{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 ${c}`:""}`);let[a,s,o]=r;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${C0(r)}`);return{x0:a,x1:s,angle:o}})}makeBuiltins(){let e=(s,o)=>g3(s.children(),o),n=s=>o=>S5(o.children(),s),r=s=>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",!y0(this.dyn(o.env,"$mirrored"))),S5(o.children(),i==="back"?this.backLayer(s):s)};return{rect:s=>{let[o,i]=this.vec2(this.arg(s.args,"size",0,1),"size"),l=U0(this.arg(s.args,"r",-1,0))||0,h=y0(this.arg(s.args,"center",1,!1)),u=N6(o,i,l,this.segs(s.env));return L0(s1([h?u.map(([f,d])=>[f-o/2,d-i/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let o=this.arg(s.args,"d",-1),i=o!==void 0?this.num(o,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return L0([F3(i,i,this.segs(s.env)(i))])},ellipse:s=>{let o=this.arg(s.args,"d",-1),[i,l]=o!==void 0?this.vec2(o,"d").map(h=>h/2):this.vec2(this.arg(s.args,"r",0,1),"r");return L0([F3(i,l,this.segs(s.env)(Math.max(i,l)))])},regular_polygon:s=>{let o=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),i=this.num(this.arg(s.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 L0([F3(i,i,o)])},star:s=>{let o=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),i=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.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 L0(s1([h]))},polygon:s=>{let o=this.points(this.arg(s.args,"points",0),"points"),i=this.arg(s.args,"paths",1),l=Array.isArray(i)?i.map(h=>(Array.isArray(h)?h:[]).map(u=>o[U0(u)]).filter(Boolean)):[o];return L0(s1(l,"evenodd"))},path:s=>{let o=this.arg(s.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=G3(W3(o),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return y0(this.arg(s.args,"close",-1,!1))?L0(s1([...i.closed,...i.open.filter(h=>h.length>2)],l)):C2([L0(s1(i.closed,l)),L2(i.open)])},line:s=>{let o=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),i=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return L2([[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 T0();let f=-(i[1]-o[1])/u*(h/2),d=(i[0]-o[0])/u*(h/2);return L0(s1([[[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:s=>{let o=this.points(this.arg(s.args,"points",0),"points"),i=y0(this.arg(s.args,"closed",1,!1));return L2([i&&o.length?[...o,o[0]]:o])},arc:s=>{let o=this.num(this.arg(s.args,"r",0,10),"arc","r"),i=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.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 L2([u])},text:s=>{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(s.args,"text",0,""),i=j3(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(s.args.at,i.text.length);let l=this.textOpts(s.args,s.env,i.text),h=Ge(this.opts.fonts,i.text,l),u=this.arg(s.args,"weight",-1),f=this.arg(s.args,"bridge",-1);if(u!==void 0&&u!=="regular"){let d=u==="bold"?.035*l.size:this.num(u,"text","weight");d&&(h=c0(s1(h),d,"round"))}if(f!==void 0&&(h=I4(h,this.num(f,"text","bridge"))),y0(this.dyn(s.env,"$mirrored"))){let[d,p]=[1/0,-1/0];for(let m of h)for(let[g]of m)[d,p]=[Math.min(d,g),Math.max(p,g)];return L0(s1(h.map(m=>m.map(([g,v])=>[d+p-g,v]))))}return L0(h)},translate:s=>{let[o,i]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,o,i])},rotate:s=>{let o=this.arg(s.args,"a",0,0),l=(Array.isArray(o)?U0(o[2]??0):this.num(o,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[p,m]=this.vec2(f,"center",!1);d=[h,u,-u,h,p-h*p+u*m,m-u*p-h*m]}return e(s,d)},scale:s=>{let[o,i]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[o,0,0,i,0,0])},mirror:s=>{let[o,i]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(o,i)||1,h=o/l,u=i/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let o=this.arg(s.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(s,[i[0],l[0],i[1],l[1],i[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[o,...i]=s.childList();if(!o)return T0();let l=c(i,"difference");return a(o,h=>({regions:g0(h.regions,l.regions),lines:Y0(h.lines,s1(l.regions),"outside")}))},intersection:s=>{let o=s.childList();if(!o.length)return T0();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===n2?[]:y.regions)),u=g=>{let v;for(let b of o){if(b===g||!l(b))continue;let y=s1(h(b));v=v?K1(v,y):y}return v},f=o[0],d=o.every(l),p=u(f),m=a(f,g=>({regions:d?p?K1(g.regions,p):g.regions:[],lines:p?Y0(g.lines,p,"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[x,w]of g.layers)w.lines.length&&b.set(x,{regions:[],lines:v?Y0(w.lines,v,"inside"):w.lines});if(!b.size)continue;let y=m.parts.length===1&&!i(f)?m.parts[0]:void 0;if(y){let x=new Map(y.layers);for(let[w,M]of b){let k=x.get(w);x.set(w,{regions:k?.regions??[],lines:[...k?.lines??[],...M.lines]})}m={layers:m.layers,parts:[{...y,layers:x}]}}else m=C2([m,{layers:b,parts:[]}])}return f.parts.forEach((g,v)=>{let b=[...g.layers.values()].some(x=>x.regions.length),y=[...m.parts[v]?.layers.values()??[]].some(x=>x.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"} (${r2(s.args.at,!1)})`)}),m},hull:s=>{let o=s.children(),i=l=>{let h=[],u="cut",f=!0;for(let[p,m]of l){f&&(m.regions.length||m.lines.length)&&(u=p,f=!1);for(let g of[...m.regions,...m.lines])for(let v of g)h.push(v)}let d=pe(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:s=>{let o=this.arg(s.args,"r",0),i=this.arg(s.args,"delta",-1),l=y0(this.arg(s.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 a(s.children(),f=>({regions:c0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[o,i]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(o>0&&i>0))throw new Error("spacing must be more than 0");let[h,...u]=s.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=s1(c(u,"pattern").regions),d=J0(h.layers),p=w0(f);if(!d||!p)return T0();let m=Math.floor((p[1]-d[3])/i),g=Math.ceil((p[3]-d[1])/i),v=Math.floor((p[0]-d[2])/o)-1,b=Math.ceil((p[2]-d[0])/o)+1,y=(g-m+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(s.args.at,y);let x=R0(f).map(A=>({polys:A,box:w0(A)})),w=f,M=(A,S)=>{let C=0;for(let I of w)for(let L=0,T=I.length-1;L<I.length;T=L++){let[q,P]=I[T],[F,j]=I[L];P<=S?j>S&&(F-q)*(S-P)-(A-q)*(j-P)>0&&C++:j<=S&&(F-q)*(S-P)-(A-q)*(j-P)<0&&C--}return C!==0},k=new Map,z=(A,S)=>{let C=k.get(A)??{regions:[],lines:[]};for(let I of S.regions)C.regions.push(I);for(let I of S.lines)C.lines.push(I);k.set(A,C)};for(let A=m;A<=g;A++)for(let S=v;S<=b;S++){let C=S*o+(A%2?l*o:0),I=A*i,L=[d[0]+C,d[1]+I,d[2]+C,d[3]+I];if(L[2]<p[0]||L[0]>p[2]||L[3]<p[1]||L[1]>p[3])continue;let T=x.filter(_=>!(L[2]<_.box[0]||L[0]>_.box[2]||L[3]<_.box[1]||L[1]>_.box[3]));if(!T.length)continue;w=T.length===x.length?f:T.flatMap(_=>_.polys);let q=[M(L[0],L[1]),M(L[2],L[1]),M(L[2],L[3]),M(L[0],L[3])],P=w.some(_=>_.some(([Q,H])=>Q>L[0]&&Q<L[2]&&H>L[1]&&H<L[3])),F=q.every(Boolean)&&!P,j=[1,0,0,1,C,I];for(let[_,Q]of g3({layers:h.layers,parts:[]},j).layers)z(_,F?Q:{regions:K1(Q.regions,w),lines:Y0(Q.lines,w,"inside")})}return{layers:k,parts:[]}},spline:s=>{let o=this.points(this.arg(s.args,"points",0),"points"),i=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=y0(this.arg(s.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=_4(o,l,h);if(i===void 0)return L2([u]);let f=this.num(i,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return L0(s1(p3([u],f)))},hatch:s=>{let o=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),i=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(i>0))throw new Error("pitch must be more than 0");let h=s1(c([s.children()],"hatch").regions),u=w0(h);if(!u)return T0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],p=Math.hypot(u[2]-u[0],u[3]-u[1])/2+i,m=o*Math.PI/180,[g,v]=[Math.cos(m),Math.sin(m)],[b,y]=[-v,g],x=Math.ceil(p/i);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let w=[],M=Math.round((f*b+d*y)/i);for(let z=M-x;z<=M+x;z++){let A=z*i-(f*b+d*y),[S,C]=[f+b*A,d+y*A];w.push([[S-g*p,C-v*p],[S+g*p,C+v*p]])}if(l===void 0)return L2(Y0(w,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return L0(K1(s1(p3(w,k).map(z=>z)),h))},flow:s=>{let o=this.arg(s.args,"field",0),i=this.num(this.arg(s.args,"spacing",1,2),"flow","spacing");if(!(i>0))throw new Error("spacing must be more than 0");let l=this.num(this.arg(s.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(s.args,"min_length",-1,2*i),"flow","min_length"),u=this.num(this.arg(s.args,"seed",-1,1),"flow","seed"),f=s1(c([s.children()],"flow").regions),d=w0(f);if(!d)return T0();let p=b=>[Math.cos(b*f8),Math.sin(b*f8)],m;if(typeof o=="number"){let b=p(o);m=()=>b}else{let b=this.fieldFn(o,"flow",s.env,s.args.at);m=y=>{let x=b(y);if(x===void 0)return null;if(typeof x=="number"&&Number.isFinite(x))return p(x);if(Array.isArray(x)&&typeof x[0]=="number"&&typeof x[1]=="number"&&Number.isFinite(x[0])&&Number.isFinite(x[1])){let w=Math.hypot(x[0],x[1]);return w>1e-12?[x[0]/w,x[1]/w]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${C0(x)}`)}}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=U6({spacing:i,step:l,minLength:h,seed:u,box:d,inside:j6(f),dir:m,tick:()=>this.tick(s.args.at),maxPoints:this.limits.maxPoints});return L2(Y0(v,f,"inside"))},contours:s=>{let o=this.arg(s.args,"field",0),i=this.fieldFn(o,"contours",s.env,s.args.at),l=this.arg(s.args,"levels",1,10),h=this.arg(s.args,"interval",-1),u=this.num(this.arg(s.args,"cell",-1,1),"contours","cell");if(!(u>0))throw new Error("cell must be more than 0");let f=s1(c([s.children()],"contours").regions),d=w0(f);if(!d)return T0();let p=Math.ceil((d[2]-d[0])/u)+1,m=Math.ceil((d[3]-d[1])/u)+1;if(!(p*m<=this.limits.maxPoints/2))throw new Error(`a cell of ${u} samples the area at ${p*m} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let g=new Float64Array(p*m),v=1/0,b=-1/0;for(let M=0;M<m;M++)for(let k=0;k<p;k++){let z=i([d[0]+k*u,d[1]+M*u]);if(z===void 0){g[M*p+k]=NaN;continue}if(typeof z!="number"||!Number.isFinite(z))throw new Error(`field() must give a number or undef, got ${C0(z)}`);g[M*p+k]=z,v=Math.min(v,z),b=Math.max(b,z)}if(!(v<=b))return T0();let y;if(h!==void 0){let M=this.num(h,"contours","interval");if(!(M>0))throw new Error("interval must be more than 0");let k=Math.ceil(v/M),z=Math.floor(b/M);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(z))throw new Error(`the heights are too large for an interval of ${M}`);let A=Math.max(0,z-k+1);if(!(A<=1e4))throw new Error(`interval ${M} gives ${A} levels: use a larger interval`);y=Array.from({length:A},(S,C)=>(k+C)*M)}else if(Array.isArray(l))y=l.map(M=>this.num(M,"contours","levels"));else{let M=Math.floor(this.num(l,"contours","levels"));if(!(M>=1&&M<=1e4))throw new Error("levels must be 1 to 10000");y=Array.from({length:M},(k,z)=>v+(b-v)*(z+1)/(M+1))}let x=[],w=0;for(let M of y){this.tick(s.args.at,Math.ceil(p*m/100));let k=B6(g,p,m,d[0],d[1],u,M),z=k.reduce((A,S)=>A+S.length,0);if(!((w+=z)<=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(z);for(let A of k)x.push(A)}return L2(Y0(x,f,"inside"))},occlude:s=>{let o;this.occluding++;try{o=s.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[m,g]of f.layers){if(m===n2)continue;let v=i(m);!h.length||v==="cut"||v==="guide"?d.set(m,g):v==="line"?d.set(m,{regions:[],lines:Y0([...g.lines,...s1(g.regions).map(b=>[...b,b[0]])],h,"outside")}):d.set(m,{regions:g0(g.regions,h),lines:Y0(g.lines,h,"outside")})}l.push({layers:d,parts:[]});let p=[...f.layers].filter(([m])=>i(m)!=="guide").flatMap(([,m])=>m.regions);p.length&&(h=s1([...h,...p]))}return C2(l.reverse())},hide:s=>this.occluding?L0(s1(c([s.children()],"hide").regions),n2):(this.warn(`hide() only works inside occlude(); it draws nothing (${r2(s.args.at,!1)})`),T0()),paint:s=>{let o=this.arg(s.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=s.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 p=h,m=s1(c([d],"paint").regions);u[f]=m,h=p.length?s1([...p,...m]):m;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(L0(p.length?g0(m,p):m,g));let v=d.layers.get(n2);v&&l.push({layers:new Map([[n2,v]]),parts:[]})}else l.push(p.length?a(d,v=>({regions:g0(v.regions,p),lines:Y0(v.lines,p,"outside")})):d)}return this.invisiblePaint(i,u,o,s.args.at),C2(l.reverse())},measure:s=>{let o=y0(this.arg(s.args,"draw",0,!1)),i=s.childSeq((l,h)=>{if(l!==0)return;let u=J0(h.layers)??w0(h.parts.flatMap(g=>[...g.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(g=>g.layers)],d=f.flatMap(g=>g.get("cut")?.regions??[]),p=d.length?d:f.flatMap(g=>[...g].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),m=D6(s1(p));s.env.vars.set("$area",m.area),s.env.vars.set("$centroid",m.area>0?m.centroid:void 0)});return C2(o?i:i.slice(1))},fill_holes:s=>{let o=this.arg(s.args,"min_area",0),i=o===void 0?1/0:this.num(o,"fill_holes","min_area");return a(s.children(),l=>({regions:s1(l.regions).filter(h=>!(b1(h)<0&&-b1(h)<i)),lines:l.lines}))},join_islands:s=>{let o=this.num(this.arg(s.args,"width",0,1),"join_islands","width");if(!(o>0))throw new Error("join_islands(): width must be more than 0");let i=s.children(),l=h=>new Map([...h].map(([u,f])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:I4(f.regions,o),lines:f.lines}:f]));return{layers:l(i.layers),parts:i.parts.map(h=>({...h,layers:l(h.layers)}))}},largest:s=>{let o=Math.floor(this.num(this.arg(s.args,"n",0,1),"largest","n"));if(!(o>=1))throw new Error("largest(): n must be 1 or more");let i=u=>R0(u).map(f=>({g:f,a:f.reduce((d,p)=>d+b1(p),0)})).sort((f,d)=>d.a-f.a).slice(0,o).flatMap(({g:f})=>f),l=s.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:s=>{let o=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),i=>({regions:c0(c0(i.regions,o,"round"),-o,"round"),lines:i.lines}))},stroke:s=>{let o=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),i=>({regions:s1([...i.regions,...p3(i.lines,o)]),lines:[]}))},outline:s=>a(s.children(),o=>({regions:[],lines:[...o.lines,...s1(o.regions).map(i=>[...i,i[0]])]})),cut:n("cut"),score:r("score"),engrave:r("engrave"),guide:n("guide"),layer:s=>{let o=this.arg(s.args,"name",0);if(typeof o!="string"||!o)throw new Error("layer() needs a name");let i=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(o),u=this.arg(s.args,"order",-1),f=this.arg(s.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 p=i??h?.mode??"line";if(!["cut","line","fill","guide"].includes(p))throw new Error('mode must be "cut", "line", "fill" or "guide"');let m=b0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(m))throw new Error('color must look like "#00aa00"');let g=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&p==="cut")throw new Error("a cut layer has no bleed");this.layerDefs++,this.layers.set(o,{name:o,mode:p,color:m,...g!==void 0&&{order:g},...v!==void 0&&{bleed:v}})}let d=this.arg(s.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"&&s.env.vars.set("$mirrored",!y0(this.dyn(s.env,"$mirrored"))),S5(s.children(),d==="back"?this.backLayer(o):o)},part:s=>{let o=b0(this.arg(s.args,"name",0,"part")),i=this.arg(s.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(s.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(s.args,"at",-1),d=this.arg(s.args,"rotate",-1),p=this.arg(s.args,"glue",-1),m=p===void 0?void 0:b0(p),g=b0(this.arg(s.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!==$4&&m===void 0,b=this.arg(s.args,"bend",-1),y=f===void 0&&d===void 0&&!v&&m===void 0&&b===void 0?void 0:this.placements(f,d,l),x=this.arg(s.args,"material",-1);x!==void 0&&s.env.vars.set("$material",b0(x));let w=this.thickness(s.env);y&&(v||u>1)&&(y=y.flatMap(p1=>{let G1=m===void 0?D1(this.frame,N0(p1)):N0(p1),F1=m!==void 0&&g==="bottom"?-w:w;return Array.from({length:u},(V,U)=>({...p1,matrix:D1(G1,j0(0,0,U*F1))}))}));let M=this.arg(s.args,"mirror",-1,!1),k;if(Array.isArray(M)){if(M.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${M.length}`);k=M.map(p1=>y0(p1))}else k=Array.from({length:l},()=>y0(M));let z=k.some(p1=>p1)&&!k.every(p1=>p1);if(z&&m!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let A=k[0],S=p1=>{let G1=s.env.vars.get("$mirrored"),F1=s.env.vars.has("$mirrored");p1&&s.env.vars.set("$mirrored",!0);try{let V=s.children();return p1?g3(V,[-1,0,0,1,0,0]):V}finally{p1&&(F1?s.env.vars.set("$mirrored",G1):s.env.vars.delete("$mirrored"))}},C=S(A),I=this.bends(b),L=this.arg(s.args,"on",-1),T=this.arg(s.args,"slots",-1),q=T===void 0?void 0:(Array.isArray(T)?T:[T]).map(p1=>{if(typeof p1!="string")throw new Error("slots must be part names");return p1}),P=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),F=this.arg(s.args,"slot_extra",-1),j=F===void 0?void 0:this.vec2(F,"slot_extra",!1),_=this.arg(s.args,"bores",-1),Q=_===void 0?void 0:(Array.isArray(_)?_:[_]).map(p1=>{if(typeof p1!="string")throw new Error("bores must be hardware labels or kinds");return p1}),H=this.arg(s.args,"halving",-1),B=H===void 0?void 0:(Array.isArray(H)?H:[H]).map(p1=>{if(typeof p1!="string")throw new Error("halving must be part names");return p1}),Y=this.arg(s.args,"fit",-1,"turn");if(typeof Y!="number"&&!Object.prototype.hasOwnProperty.call(P5,b0(Y)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${C0(Y)}`);let e1=typeof Y=="number"?Y:P5[b0(Y)],X=(p1,G1,F1)=>{let V=F1.length===l,U=y?.filter((r1,h1)=>F1.includes(Math.floor(h1/u)+1));return{name:o,qty:F1.length*u,layers:p1,thickness:w,kerf:U0(this.dyn(s.env,"$kerf"))||0,material:b0(this.dyn(s.env,"$material")??"material"),...U?{placements:U}:{},...u>1?{stack:u}:{},...I.length?{bends:G1?I.map(r1=>({...r1,mirrored:!0})):I}:{},...L!==void 0?{on:b0(L)}:{},...q?{slots:q,clearance:P}:{},...q&&j?{slotExtra:j}:{},...Q?{bores:Q,fit:e1}:{},...B?{halving:B,clearance:P}:{},...this.step?{step:this.step}:{},...m!==void 0&&{glue:{host:m,face:g}},...G1&&{mirrored:!0},...!V&&{copies:F1}}},M1=p1=>k.flatMap((G1,F1)=>G1===p1?[F1+1]:[]),v1=z?[X(C.layers,A,M1(A)),X(S(!A).layers,!A,M1(!A))]:[X(C.layers,A,M1(A))];return{layers:new Map,parts:[...C.parts,...v1]}},place:s=>{let o=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),i=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=D1(l,N0({at:o,rotate:i}));try{return s.children()}finally{this.frame=l}},step:s=>{let o=b0(this.arg(s.args,"text",0,"")),i=y0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.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 s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let o=b0(this.arg(s.args,"kind",0,"dowel"));K0(K2,o)===void 0&&K0(y3,o)===void 0&&this.warn(`hardware(): unknown kind "${o}"; the 3D view shows it grey (${r2(s.args.at,!1)})${z3(o,Object.keys(K2))}`);let i=b0(this.arg(s.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(s.args,"sides",-1),h=i==="ball"||l===0,u=this.vec3(this.arg(s.args,"from",1),"from"),f=this.arg(s.args,"to",2),d=h&&f===void 0?u:this.vec3(f,"to"),p=this.arg(s.args,"size",3,6),m=typeof p=="number"?p:this.vec2(p,"size",!1);if(h){if(typeof m!="number"||!(m>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let g=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(g[2])>.9*Math.hypot(...g),b=this.arg(s.args,"up",-1),y=b===void 0?v?[0,1,0]:[0,0,1]:this.vec3(b,"up"),x=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(x>=3&&x<=Lt))throw new Error(`sides must be from 3 to ${Lt} (or 0 for a ball), got ${C0(x)}`);if(this.pointCount+=h?2*Lt:x*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 w=this.arg(s.args,"label",-1),M=this.frame,k=A=>[M[0]*A[0]+M[1]*A[1]+M[2]*A[2]+M[3],M[4]*A[0]+M[5]*A[1]+M[6]*A[2]+M[7],M[8]*A[0]+M[9]*A[1]+M[10]*A[2]+M[11]],z=A=>[M[0]*A[0]+M[1]*A[1]+M[2]*A[2],M[4]*A[0]+M[5]*A[1]+M[6]*A[2],M[8]*A[0]+M[9]*A[1]+M[10]*A[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:o,from:k(u),to:k(d),size:m,up:z(y),sides:x,step:this.step,...w!==void 0?{label:b0(w)}:{}}),s.children()},material:s=>{let o=this.arg(s.args,"thickness",0),i=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return o!==void 0&&s.env.vars.set("$thickness",this.num(o,"material","thickness")),i!==void 0&&s.env.vars.set("$kerf",this.num(i,"material","kerf")),l!==void 0&&s.env.vars.set("$material",b0(l)),s.children()},children:s=>{let o=s.env.childCtx();if(!o)return T0();let i=this.childStmts(o.stmts),l=this.arg(s.args,"index",0),h=new E0(o.env,s.env);this.hoist(o.stmts,h);let u=new Set;if(l===void 0)i.forEach(m=>u.add(m));else for(let m of this.iterable(l,s.args.at)){let g=U0(m);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"} (${r2(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 p=this.childKey(h);for(let m of o.stmts)if(m.kind==="assign")this.stmt(m,h);else if(u.has(m)){let g=p&&d.get(m);if(g&&g.key===p){g.shape&&f.push(g.shape);continue}let v=this.effects(),b=this.stmt(m,h);b&&f.push(b),p&&this.effects()===v&&!b?.parts.length&&d.set(m,{key:p,shape:b})}return C2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[o,i]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(o)+Math.abs(i))/u*4),L0(Ce(o,i,l,h,u))},finger_holes:s=>{let o=this.num(this.arg(s.args,"length",0),"finger_holes","length"),i=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(i==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(o)/l*4),L0(Ln(o,i,this.thickness(s.env),l))},tslot:s=>{let o=this.num(this.arg(s.args,"d",0,3),"tslot","d"),i=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[o*1.85,o*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,i/2),"tslot","nut_at");return L0(s1(Cn(o,i,l,h,u)))},living_hinge:s=>{let[o,i]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.num(this.arg(s.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(s.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(s.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),L2(Pn(o,i,l,h,u))}};function c(s,o){let i={regions:[],lines:[]};for(let l of s){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!==n2)for(let f of u.regions)i.regions.push(f)}return i}function a(s,o){let i=l=>{let h=new Map;for(let[u,f]of l)h.set(u,o(f));return h};return{layers:i(s.layers),parts:s.parts.map(l=>({...l,layers:i(l.layers)}))}}}};var e5=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},It=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function Vt(t,e){let n=[];for(let[r,c]of t){let a=[e5(r),e5(c)],s=n[n.length-1];(!s||s[0]!==a[0]||s[1]!==a[1])&&n.push(a)}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 t5=(t,e)=>`M${Vt(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function Xe(t,e){let n=[];for(let r of e){let c=[],a=[],s=[];for(let o of t){let i=o.layers.get(r.name);if(i){for(let l of i.lines)c.push(t5(l,!1));for(let l of i.regions)(b1(l)<0?a:s).push(t5(l,!0))}}(c.length||a.length||s.length)&&n.push({name:r.name,mode:r.mode,color:r.color,d:[...c,...a,...s].join(""),regions:[...a,...s].join(""),lines:c.join("")})}return n}function Ze(t,e,n,r){let c=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${e5(e)}mm" height="${e5(n)}mm" viewBox="0 0 ${e5(e)} ${e5(n)}">`];for(let a of r){let s=[],o=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${It(l.part)}"`;if(a.mode==="fill"){h.regions.length&&o.push(`<path${u} d="${h.regions.map(f=>t5(f,!0)).join("")}"/>`);for(let f of h.lines)o.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${t5(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${t5(f,!1)}"/>`);for(let f of h.regions)(b1(f)<0?s:o).push(`<path${u} d="${t5(f,!0)}"/>`)}if(!s.length&&!o.length)continue;let i=a.mode==="fill"?`fill="${a.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${a.color}" stroke-width="0.1"${a.mode==="guide"?' stroke-dasharray="1 1"':""}`;c.push(`<g id="${It(a.name)}" inkscape:groupmode="layer" inkscape:label="${It(a.name)}" data-mode="${a.mode}" ${i}>`,...s,...o,"</g>")}return c.push("</svg>",""),c.join(`
|
|
3022
|
+
`)}var di={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},mi=t=>{let e=di[t.toLowerCase()];if(e)return e;let[n,r,c]=[1,3,5].map(a=>parseInt(t.slice(a,a+2),16));return n>r&&n>c?1:r>n&&r>c?3:c>n&&c>r?5:7};function pi(t){let e=o=>o.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(We.map(o=>o.name)),r=new Set(t.map(o=>e(o.name))),c=new Set,a=new Map,s=[...t.filter(o=>n.has(o.name)),...t.filter(o=>!n.has(o.name))];for(let o of s){let i=e(o.name);if(c.has(i)){let l=2;for(;r.has(`${i}_${l}`)||c.has(`${i}_${l}`);)l++;i=`${i}_${l}`}c.add(i),a.set(o.name,i)}return a}function Ht(t,e,n,r){let c=[],a=(i,l)=>c.push(String(i),String(l)),s=pi(r);a(0,"SECTION"),a(2,"HEADER"),a(9,"$ACADVER"),a(1,"AC1009"),a(9,"$INSUNITS"),a(70,4),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"TABLES"),a(0,"TABLE"),a(2,"LAYER"),a(70,r.length);for(let i of r)a(0,"LAYER"),a(2,s.get(i.name)),a(70,0),a(62,mi(i.color)),a(6,"CONTINUOUS");a(0,"ENDTAB"),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"ENTITIES");let o=(i,l,h)=>{a(0,"POLYLINE"),a(8,i),a(66,1),a(10,0),a(20,0),a(30,0),a(70,h?1:0);for(let[u,f]of Vt(l.map(([d,p])=>[d,n-p]),h))a(0,"VERTEX"),a(8,i),a(10,u),a(20,f),a(30,0);a(0,"SEQEND"),a(8,i)};for(let i of r){let l=s.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)b1(d)<0?o(l,d,!0):h.push(d)}}for(let u of h)o(l,u,!0)}return a(0,"ENDSEC"),a(0,"EOF"),c.join(`
|
|
2565
3023
|
`)+`
|
|
2566
|
-
`}var i8=(t,e)=>{let n=0;for(let c=1;c<t.length;c++)n+=Math.hypot(t[c][0]-t[c-1][0],t[c][1]-t[c-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},w0=t=>Math.round(t*100)/100;function Us(t,e={}){for(let[C,_]of Object.entries(e.params??{}))try{de(C,_)}catch(U){throw new i1(U.message)}let{program:n}=a2(t),c=new Set(n.body.flatMap(C=>C.kind==="assign"?[C.name]:[])),r=Object.keys(e.params??{}).filter(C=>!C.startsWith("$")&&!c.has(C)),a=e.fonts?new x4(e.fonts,e.defaultFont):void 0,s=new D3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(n)}catch(C){let _=C instanceof RangeError?new i1(/call stack/i.test(C.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):C;throw _ instanceof i1&&(_.echoes=s.echoes,_.warnings=[...s.warnings],a?.missing.size&&(_.missingFonts=[...a.missing])),_}let l=C=>o.globals.get(C).value,h=o.warnings;for(let C of r)h.push(`Setting "${C}" is not a variable of the program, so it is ignored.${l3(C,c)}`);let u=o.layers,f=C=>u.get(C)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(C=>C.regions.length||C.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:A0(l("$thickness"))||3,kerf:A0(l("$kerf"))||0,material:g0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let m=C=>JSON.stringify([C.thickness,C.material,[...C.layers].map(([_,U])=>[_,U.regions.map(s1=>s1.map(([Q,L1])=>[Math.round(Q*100),Math.round(L1*100)])),U.lines.map(s1=>s1.map(([Q,L1])=>[Math.round(Q*100),Math.round(L1*100)]))])]),g=new Map,v=new Set;for(let C of d){let _=m(C),U=C.mirrored?`${C.name}\0mirrored`:C.name,s1=g.get(U);s1===void 0?g.set(U,_):s1!==_&&v.add(C.name)}for(let C of v)h.push(`Two different parts are named "${C}"; slots, glue and on = find parts by name, so give each its own.`);Zs(d,h),_s(d,f,h);let y=[],b=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],M=new Map,w=[],k=new Set,z=[],S=l("$min_width"),L=S===void 0?1.5:A0(S),I=l("$label_parts")===!0,q=0;I&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");I&&a&&R&&R.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 N=I&&!!a&&(!R||R.side==="back");if(N){let C=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:C?.color??"#000000",side:"back"})}let G=[];for(let C of d){let _=x1([...C.layers].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.regions)),U;if(C.bends&&_.length){let l1=1/0,z1=-1/0;for(let g1 of _)for(let[d1]of g1)l1=Math.min(l1,d1),z1=Math.max(z1,d1);for(let g1 of C.bends)(g1.x0<l1-.001||g1.x1>z1+.001)&&h.push(`Part "${C.name}" bends from x = ${C2(g1.x0)} to ${C2(g1.x1)}, beyond the part (x = ${C2(l1)} to ${C2(z1)}); only the part itself bends.`)}if(N&&_.length){U=++q;let l1=Ys(_,String(U),a,g0(l("$font")??""));if(l1.length){let z1=C.layers.get("engrave-back")??{regions:[],lines:[]};C.layers=new Map(C.layers).set("engrave-back",{regions:[...z1.regions,...l1],lines:z1.lines})}else h.push(`Part "${C.name}" is too small to take its number ${U}.`)}if(L>0&&_.length){let l1=m0(m0(_,-L/2,"round"),L/2,"round"),z1=_0(b0(_,l1)).filter(g1=>g1.reduce((d1,v1)=>d1+H1(v1),0)>2*L*L);if(z1.length){let g1=z1.slice(0,3).map(d1=>{let[v1,U1,l0,z0]=D0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${w0((v1+l0)/2)}, ${w0((U1+z0)/2)}]`});h.push(`Part "${C.name}" is narrower than ${L} mm ($min_width) in ${z1.length} place${z1.length>1?"s":""}, at ${g1.join(", ")}${z1.length>3?" and more":""} in the part's coordinates.`)}}let s1=new Map;for(let[l1,z1]of C.layers){if(f(l1)==="guide"&&!e.guides)continue;let g1=x1(z1.regions),d1=z1.lines.filter(v1=>v1.length>=2);if((f(l1)==="line"||f(l1)==="guide")&&(d1=[...d1,...g1.map(v1=>[...v1,v1[0]])],g1=[]),_.length&&f(l1)!=="guide"){let v1=u.get(l1)?.bleed??0,U1=v1>0?m0(_,v1,"round"):_;f(l1)!=="cut"&&(g1=x0(g1,U1)),d1=v2(d1,U1,"inside")}(g1.length||d1.length)&&s1.set(l1,{regions:g1,lines:d1})}if(G.push(...Ws(C.name,s1,u)),_.length){let l1=[];for(let[g1,d1]of s1){let v1=u.get(g1);if(v1?.mode==="cut"&&d1.lines.length)for(let U1 of["front","back"])l1.push({layer:g1,mode:"line",color:"#000000",side:U1,regions:[],lines:d1.lines});!v1||v1.mode!=="fill"&&v1.mode!=="line"||l1.push({layer:g1,mode:v1.mode,color:v1.color,side:v1.side??"front",regions:d1.regions,lines:d1.lines})}let z1={name:C.name,thickness:C.thickness,material:C.material,outline:_,...l1.length&&{marks:l1}};if(C.placements){let g1=new Set;C.placements.forEach((d1,v1)=>{let U1={...z1,copy:o8(C,v1),matrix:K0(d1),placed:!0,...C.bends&&{bends:C.bends},...C.step&&{step:C.step},...C.stack&&{stack:C.stack}};x.push(U1),C.on!==void 0&&M.set(U1,C.on);let l0=U1.matrix.map(z0=>z0.toFixed(6)).join(",");g1.has(l0)&&k.add(U1),g1.add(l0)}),g1.size<C.placements.length&&h.push(`Copies of part "${C.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 g1=0;g1<C.qty;g1++)w.push({...z1,copy:o8(C,g1),matrix:K0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...C.step&&{step:C.step}})}let Q=_0(_),L1=Q.length;if(L1>1){let l1=d1=>d1.reduce((v1,U1)=>v1+H1(U1),0),g1=[...Q].sort((d1,v1)=>l1(v1)-l1(d1)).slice(1,4).map(d1=>{let[v1,U1,l0,z0]=D0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${w0(v1)}, ${w0(U1)}] to [${w0(l0)}, ${w0(z0)}]`}).join(", ");h.push(`Part "${C.name}" cuts into ${L1} separate pieces. Join them, or make them separate parts. The smaller ${L1===2?"one is":"ones are"} at ${g1}${L1>4?" and more":""}, in the part's coordinates.`)}let Y1=0;for(let[l1,z1]of s1)if(f(l1)==="cut"){for(let g1 of z1.regions)Y1+=i8(g1,!0);for(let g1 of z1.lines)Y1+=i8(g1,!1)}let G1=D0(s1)??[0,0,0,0],A1=e.kerf??C.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new i1("$kerf must be a number, 0 or more");let _1={name:C.name,qty:C.qty,width:w0(G1[2]-G1[0]),height:w0(G1[3]-G1[1]),pieces:L1,cutLength:Math.round(Y1),thickness:C.thickness,kerf:A1,material:C.material,...C.stack&&{stack:C.stack},...C.glue&&{glued:C.glue.host},...C.mirrored&&{mirrored:!0},...U!==void 0&&{label:U}};if(b&&b.parts.push({name:C.name,kerf:A1,qty:C.qty,...C.stack&&{stack:C.stack},...C.glue&&{glue:C.glue},...C.on&&{on:C.on},cutRegions:_.map(l1=>l1.map(([z1,g1])=>[z1,g1])),cutLines:[...s1].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.lines.map(z1=>z1.map(([g1,d1])=>[g1,d1])))}),A1>0){for(let[l1,z1]of s1)if(f(l1)==="cut"){let g1=z1.regions.filter(U1=>H1(U1)<0);z1.regions=m0(z1.regions,A1/2,"round",Math.min(.01,A1/20));let d1=z1.regions.filter(U1=>H1(U1)<0),v1=g1.length-d1.length;if(v1>0){let U1=z0=>{let[$2,e3,gn,vn]=D0(new Map([["cut",{regions:[z0],lines:[]}]]));return[($2+gn)/2,(e3+vn)/2]},l0=g1.map(U1).filter(([z0,$2])=>!d1.some(e3=>l8(e3,z0,$2))).slice(0,3).map(([z0,$2])=>`[${w0(z0)}, ${w0($2)}]`);h.push(`Part "${C.name}": ${v1} hole${v1===1?" is":"s are"} narrower than the ${A1} mm kerf and will not be cut${l0.length?`, at ${l0.join(", ")}${v1>l0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(_1),z.push({info:_1,layers:s1})}Gs(x,M,h);let V=new Map,J=x.filter(C=>!k.has(C)).flatMap(C=>{let _=e4(C);for(let U of _)V.set(U,C);return _}),{found:o1,complete:Z}=c7(J,i.maxCollisionPairs),p1=o1.filter(([C,_])=>V.get(C)!==V.get(_)).map(([C,_])=>[V.get(C)??C,V.get(_)??_]).filter(([C,_],U,s1)=>s1.findIndex(([Q,L1])=>Q===C&&L1===_)===U);Z||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[C,_]of p1.slice(0,5)){let[U,s1]=l5(C),[Q,L1]=l5(_),Y1=[0,1,2].map(G1=>w0((Math.max(U[G1],Q[G1])+Math.min(s1[G1],L1[G1]))/2));h.push(`Parts "${C.name}"${C.copy>1?` (copy ${C.copy})`:""} and "${_.name}"${_.copy>1?` (copy ${_.copy})`:""} collide in the assembly, around [${Y1.join(", ")}]. Check their edges and where they are placed.`)}if(p1.length>5&&h.push(`${p1.length-5} more pairs of parts collide in the assembly.`),Xs(G,h),x.length&&w.length){let C=[...new Set(w.map(_=>`"${_.name}"`))];h.push(`${C.length===1?"Part":"Parts"} ${C.slice(0,5).join(", ")}${C.length>5?` and ${C.length-5} more`:""} ${C.length===1?"has":"have"} no at or rotate, so ${C.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...n7(x,w))}let E=0;for(let C of z){let _=0;for(let U of C.layers.values()){for(let s1 of U.regions)_+=s1.length;for(let s1 of U.lines)_+=s1.length}E+=_*C.info.qty}if(E>i.maxOutputPoints)throw new i1(`The files would have ${E} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let $=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray($)||!(Number.isFinite($[0])&&$[0]>0)||!(Number.isFinite($[1])&&$[1]>0))throw new i1("$sheet must be [width, height], both more than 0");let X=e.gap??A0(l("$gap")??3),j=e.margin??X;if(!(Number.isFinite(X)&&X>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(j)&&j>=0))throw new i1("margin must be a number, 0 or more");let w1=e.nest??l("$nest")===!0,W1=e.layout??(l("$layout")==="none"?"none":"pack"),E1=[...u.keys()].filter(C=>!["engrave","score","cut","guide"].includes(C)),Z1=C=>(u.get(C)?.order??0)*2+(f(C)==="fill"?0:1),o0=["engrave",...E1.map((C,_)=>[C,_]).sort((C,_)=>Z1(C[0])-Z1(_[0])||C[1]-_[1]).map(([C])=>C),"score","cut","guide"].map(C=>u.get(C)).filter(Boolean),A=o0.filter(C=>C.side!=="back"),F=[...o0.filter(C=>C.side==="back")],t1=l("$registration")===!0;t1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),t1&&!A.some(C=>C.name==="registration")&&A.push(u.get("registration"));let r1=[],y1=[1,0,0,-1,0,0],P=C=>D0(C)??[0,0,0,0],Y=(C,_)=>z3({layers:C,parts:[]},_).layers;if(W1==="none"){let C=[];for(let Q of z)for(let L1=0;L1<Q.info.qty;L1++)C.push({part:Q.info.name,copy:L1+1,layers:Y(Q.layers,y1),rotated:!1});let _=new Map;for(let Q of C)for(let[L1,Y1]of Q.layers){let G1=_.get(L1)??{regions:[],lines:[]};for(let A1 of Y1.regions)G1.regions.push(A1);for(let A1 of Y1.lines)G1.lines.push(A1);_.set(L1,G1)}let U=P(_),s1=[1,0,0,1,j-U[0],j-U[1]];for(let Q of C)Q.layers=Y(Q.layers,s1),Q.offset=[s1[4],s1[5]];r1.push(W(C,U[2]-U[0]+2*j,U[3]-U[1]+2*j,z[0]?.info))}else{let C=new Map;for(let _ of z){let U=`${_.info.material}|${_.info.thickness}`;C.set(U,[...C.get(U)??[],_])}for(let _ of C.values()){let[U,s1]=$,Q=[];for(let d1 of _){let v1=Y(d1.layers,y1),U1=P(v1),l0=U1[2]-U1[0],z0=U1[3]-U1[1],$2=!1;(l0>U-2*j||z0>s1-2*j)&&z0<=U-2*j&&l0<=s1-2*j&&(v1=Y(v1,[0,1,-1,0,0,0]),U1=P(v1),l0=U1[2]-U1[0],z0=U1[3]-U1[1],$2=!0),(l0>U-2*j||z0>s1-2*j)&&h.push(`Part "${d1.info.name}" (${w0(l0)} x ${w0(z0)} mm) is bigger than the ${U} x ${s1} mm sheet.`),v1=Y(v1,[1,0,0,1,-U1[0],-U1[1]]);for(let e3=0;e3<d1.info.qty;e3++)Q.push({info:d1.info,layers:v1,w:l0,h:z0,copy:e3+1,rotated:$2})}Q.sort((d1,v1)=>v1.h-d1.h||v1.w-d1.w);let L1=w1?js(Q,X,d1=>f(d1)==="cut"):Q,Y1=[],G1=j,A1=j,_1=0,l1=0,z1=0,g1=()=>{if(Y1.length&&r1.length>=i.maxSheets)throw new i1(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);Y1.length&&r1.push(W(Y1,Math.max(l1+j,1),Math.max(z1+j,1),_[0].info)),Y1=[],G1=j,A1=j,_1=0,l1=0,z1=0};for(let d1 of L1){G1>j&&G1+d1.w>U-j&&(G1=j,A1+=_1+X,_1=0),Y1.length&&A1+d1.h>s1-j&&g1(),Y1.push({part:d1.info.name,copy:d1.copy,layers:Y(d1.layers,[1,0,0,1,G1,A1]),rotated:d1.rotated});for(let v1 of d1.inner??[])Y1.push({part:v1.item.info.name,copy:v1.item.copy,layers:Y(v1.item.layers,[1,0,0,1,G1+v1.dx,A1+v1.dy]),rotated:v1.item.rotated});l1=Math.max(l1,G1+d1.w),z1=Math.max(z1,A1+d1.h),G1+=d1.w+X,_1=Math.max(_1,d1.h)}g1()}}function W(C,_,U,s1){let Q=w0(_),L1=w0(U);if(t1){let A1=Math.min(5,j-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let _1=(l1,z1)=>[[l1,z1],[l1+A1,z1],[l1+A1,z1+A1],[l1,z1+A1]];C=[...C,{part:"registration",copy:1,layers:new Map([["registration",{regions:[_1(.5,.5),_1(Q-.5-A1,.5),_1(.5,L1-.5-A1)],lines:[]}]]),rotated:!1}]}}let Y1=C.some(A1=>F.some(_1=>A1.layers.has(_1.name))),G1=Y1?C.map(A1=>({...A1,layers:Y(A1.layers,[-1,0,0,1,Q,0])})):[];return{width:Q,height:L1,material:s1?.material??"material",thickness:s1?.thickness??0,items:C,paths:z4(C,A),svg:k4(C,Q,L1,A),dxf:c6(C,Q,L1,A),...Y1&&{back:{paths:z4(G1,F),svg:k4(G1,Q,L1,F),dxf:c6(G1,Q,L1,F)}}}}let b1=r1.length===1?r1[0]:void 0,a1=b1?[]:r1.flatMap((C,_)=>{let U=r1.slice(0,_).reduce((s1,Q)=>s1+Q.height+10,0);return C.items.map(s1=>({...s1,layers:Y(s1.layers,[1,0,0,1,0,U])}))}),$1=w0(Math.max(1,...r1.map(C=>C.width))),e1=w0(Math.max(1,r1.reduce((C,_)=>C+_.height,0)+10*Math.max(0,r1.length-1))),I1=b1?b1.svg:k4(a1,$1,e1,A),r0=b1?b1.paths:z4(a1,A);return{sheets:r1,width:b1?.width??$1,height:b1?.height??e1,paths:r0,svg:I1,parts:y,assembly:x,layers:[...A,...F],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function Bs(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 _s(t,e,n){if(!t.some(l=>l.slots))return;let c=new Map,r=l=>{let h=c.get(l);return h||(h=x1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},a=l=>(l.placements??[]).flatMap(h=>e4({name:l.name,copy:0,placed:!0,matrix:K0(h),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),s=new Map,i=new Map;for(let l of t){if(!l.slots)continue;if(!l.placements){n.push(`Part "${l.name}" has slots but no at or rotate, so they can't be found.`);continue}let h=new Set;for(let g of l.slots){let v=g.startsWith("!"),y=Bs(v?g.slice(1):g),b=t.filter(x=>x!==l&&y(x.name));!b.length&&!v&&n.push(`Part "${l.name}": no part "${g}" to cut slots for.`);for(let x of b)v?h.delete(x):h.add(x)}let u=[...h].flatMap(a),f=(l.placements??[]).map(g=>x1(e4({name:l.name,copy:0,placed:!0,matrix:K0(g),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).flatMap(v=>{let y=i7(v,u,l.clearance??.1);return l.bends?x0(y,m0(v.outline,1,"miter")):y}))),d=(g,v)=>M3(g,v).reduce((y,b)=>y+Math.abs(H1(b)),0)>.001,p=l.stack??1;if(p>1){let g=y=>f.filter((b,x)=>x%p===y),v=Array.from({length:p},(y,b)=>x1(g(b).flat()));if(v.slice(1).some(y=>d(v[0],y))){Array.from({length:p},(y,b)=>g(b)).some(y=>y.slice(1).some(b=>d(y[0],b)))&&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,v);continue}}f.slice(1).some(g=>d(f[0],g))&&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.`);let m=x1(f.flat());if(!m.length){l.slots.some(g=>g.includes("*"))||n.push(`Part "${l.name}": none of ${l.slots.map(g=>`"${g}"`).join(", ")} pass through it, so it has no slots.`);continue}s.set(l,m)}let o=(l,h)=>{let u=new Map(l);for(let[f,d]of l)u.set(f,{regions:b0(d.regions,h),lines:v2(d.lines,h,"outside")});return u};for(let[l,h]of s)l.layers=o(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,p)=>({...l,name:`${l.name}, layer ${p+1}`,qty:l.qty/u,layers:d.length?o(l.layers,d):l.layers,placements:l.placements.filter((m,g)=>g%u===p),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function Gs(t,e,n){let c=new Map;for(let[r,a]of e){let s=t.filter(M=>M.name===a&&M.placed);if(!s.length){c.has(a)||n.push(`Part "${r.name}" is on "${a}", which is not a placed part.`),c.set(a,0);continue}let i=[...e].filter(([M,w])=>M.name===r.name&&w===a).length,o=s.length===i?s[r.copy-1]:s[0];if(!o?.bends?.length)continue;let[l,h,u,f]=[1/0,1/0,-1/0,-1/0];for(let M of r.outline)for(let[w,k]of M)l=Math.min(l,w),h=Math.min(h,k),u=Math.max(u,w),f=Math.max(f,k);let d=r.matrix,[p,m,g]=[(l+u)/2,(h+f)/2,r.thickness/2],v=[d[0]*p+d[1]*m+d[2]*g+d[3],d[4]*p+d[5]*m+d[6]*g+d[7],d[8]*p+d[9]*m+d[10]*g+d[11]],y=L0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=Q5(o.bends,o.thickness)[a7(o.bends,b)];r.matrix=O1(o.matrix,O1(x,O1(y,r.matrix)))}}function js(t,e,n){var l;let c=[],r=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)H1(p)<0&&u.push([...p].reverse());return u.length?m0(x1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let p of h)for(let m=0,g=p.length-1;m<p.length;g=m++){let[v,y]=p[g],[b,x]=p[m];y<=f?x>f&&(b-v)*(f-y)-(u-v)*(x-y)>0&&d++:x<=f&&(b-v)*(f-y)-(u-v)*(x-y)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)H1(p)>0&&u.push(p);return x1(u)},i=(h,u)=>{let{w:f,h:d}=u,p=s(u),m=[];for(let g of p)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))m.push(g[v]);for(let g of h){if(H1(g)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[w,k]of g)v=Math.min(v,w),y=Math.min(y,k),b=Math.max(b,w),x=Math.max(x,k);if(b-v<f||x-y<d)continue;let M=Math.max(.5,Math.min(f,d,b-v-f+1,x-y-d+1)/4);for(let w=y;w<=x-d+1e-9;w+=M)for(let k=v;k<=b-f+1e-9;k+=M){if(!m.every(([S,L])=>a(h,S+k,L+w)))continue;let z=p.map(S=>S.map(([L,I])=>[L+k,I+w]));if(b0(z,h).reduce((S,L)=>S+Math.abs(H1(L)),0)<.01)return[k,w]}}},o=[];for(let h of t){let u=!1;for(let d of c){let p=i(d.region,h);if(!p)continue;let[m,g]=p;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+m,dy:d.oy+g}),d.region=b0(d.region,m0(s(h).map(y=>y.map(([b,x])=>[b+m,x+g])),e,"miter"));let v=r(h);v.length&&c.push({host:d.host,ox:d.ox+m,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;o.push(h);let f=r(h);f.length&&c.push({host:h,ox:0,oy:0,region:f})}return o}function o8(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 Ws(t,e,n){let c=[...n.keys()],r=[...e.keys()].filter(i=>n.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),a=[];if(r.length<2)return a;let s=i=>i==="engrave"?-1/0:(n.get(i)?.order??0)*2+c.indexOf(i)/c.length;r.sort((i,o)=>s(i)-s(o));for(let i=0;i<r.length-1;i++){let o=n.get(r[i]).side??"front",l=r.slice(i+1).filter(u=>(n.get(u).side??"front")===o);if(!l.length)continue;let h;for(let u of _0(e.get(r[i]).regions)){let f=u.reduce((M,w)=>M+H1(w),0);if(!(f>.001)||!m0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=b0(d,e.get(M).regions));if(d.reduce((M,w)=>M+H1(w),0)>.001*Math.max(1,f))continue;let m=l.filter(M=>x0(u,e.get(M).regions).length),g=m.length?m:l;if(h){h.count++;for(let M of g)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=D0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:r[i],under:g,count:1,at:[w0((v+b)/2),w0((y+x)/2)]}}h&&a.push(h)}return a}function Xs(t,e){for(let n of t.slice(0,5)){let c=n.under.map(a=>`"${a}"`),r=c.length>1?`${c.slice(0,-1).join(", ")} and ${c.at(-1)}`:c[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 ${r}, 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),c=new Set(n.map(a=>a.part)).size,r=[...new Set(n.map(a=>`"${a.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${c} part${c>1?"s":""} (layer${r.length>1?"s":""} ${r.slice(0,5).join(", ")}${r.length>5?" and more":""}).`)}}function Zs(t,e){let n=new Set,c=(r,a)=>{if(!r.glue||n.has(r))return;if(a.includes(r)){e.push(`Part "${r.name}" is glued in a loop of parts; it is left where it is.`),n.add(r);return}let s=t.find(h=>h.name===r.glue.host&&h!==r);if(!s?.placements){e.push(`Part "${r.name}" is glued to "${r.glue.host}", which is not a placed part.`),n.add(r);return}c(s,[...a,r]);let i=s.placements.map(K0),o=r.glue.face==="top"?s.thickness:-r.thickness,l=r.placements.length/(r.stack??1);r.placements=r.placements.map((h,u)=>{let f=i.length===l?i[Math.floor(u/(r.stack??1))]:i[0];return{...h,matrix:O1(f,O1(R0(0,0,o),K0(h)))}}),n.add(r)};for(let r of t)c(r,[])}function Ys(t,e,n,c){let r=0,a=50;for(let m=0;m<14;m++){let g=(r+a)/2;m0(t,-g,"round").length?r=g:a=g}if(r<1)return[];let s=m0(t,-r*.98,"round"),i=D0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((m,g)=>s.reduce((v,y)=>v+(l8(y,m,g)?H1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((m,g)=>H1(g)>H1(m)?g:m)[0]);let u=Math.min(6,Math.max(2,r*.9)),f=M4(n,e,{size:u,font:c,halign:"center",valign:"center",spacing:1}),d=D0(new Map([["t",{regions:f,lines:[]}]])),p=d?Math.min(1,1.6*r/Math.max(d[2]-d[0],1e-9)):1;return f.map(m=>m.map(([g,v])=>[o-g*p,l+v*p]).reverse())}function l8(t,e,n){let c=!1;for(let r=0,a=t.length-1;r<t.length;a=r++){let[s,i]=t[r],[o,l]=t[a];i>n!=l>n&&e<(o-s)*(n-i)/(l-i)+s&&(c=!c)}return c}function u8(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 c=u8(n.expr);if(!c.ok||typeof c.value!="number")return{ok:!1};e.push(c.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function h8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function Js(t){let{program:e,comments:n}=a2(t),c=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),r=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),a=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),s=[];for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let o=u8(i.value);if(!o.ok)continue;let l=c.filter(m=>m.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(l.toLowerCase()==="hidden")continue;let h=r.get(i.pos.line),u=a.get(i.pos.line-1)??"",f=o.value,d={name:i.name,caption:u,group:l,type:typeof f=="number"||Array.isArray(f)?"number":typeof f=="boolean"?"boolean":"string",initial:f,span:i.span},p=h?/^\[(.*)\]$/.exec(h.trim()):null;if(p){let m=p[1];if(m.includes(",")||/[a-zA-Z"]/.test(m)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(m))d.options=m.split(",").map(g=>{let[v,y]=g.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=h8(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let g=m.split(":").map(h8);g.every(v=>v!==void 0)&&(g.length===1?d.max=g[0]:g.length===2?(d.min=g[0],d.max=g[1]):(d.min=g[0],d.step=g[1],d.max=g[2]))}}s.push(d)}return{parameters:s}}var Ks=8,Qs=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,ei=(t,e)=>Math.max(1,Qs.exec(t.slice(e-1))?.[0].length??1);function ti(t,e,n={}){if(!(t instanceof i1))return`error: ${t instanceof Error?t.message:String(t)}`;let c=n.file??"design.kerf",r=(o,l,h)=>`${o?`<${o}>`:c}:${l}:${h}`,a=o=>o===void 0?e:(Object.prototype.hasOwnProperty.call(y5,o)?y5[o]:void 0)??n.resolve?.(o),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${r(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
|
|
2567
|
-
`)
|
|
2568
|
-
`)}function ni(t,e){let n=a=>`in ${a.kind==="module"?"module ":""}${a.name}(), called at ${e(a.file,a.line,a.col)}${a.count>1?` (${a.count} times)`:""}`,c=t.trace.slice(0,Ks).map(n),r=t.trace.length-c.length+t.traceMore;return r&&c.push(`and ${r} more call${r===1?"":"s"}`),c}var f8=new Set(["module","function","if","else","for","let","each","use","include"]),ci=new Set(["true","false","undef"]),ri=new Set(["for","if","let","function"]),r6={"(":")","[":"]","{":"}"},ai=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function si(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let c=n+1;for(;t[c]!=='"';)c+=t[c]==="\\"?2:1;return t.slice(n,c+1)}function a6(t){let{tokens:e}=p5(t),n=[],c=0,r=0,a=s=>{for(;c<s;)if(t[c]===`
|
|
2569
|
-
`)r
|
|
2570
|
-
|
|
2571
|
-
`)
|
|
3024
|
+
`}function v8(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=v8(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 p8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function X5(t){let{program:e,comments:n}=c2(t),r=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),c=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),a=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),s=[],o=new Set;for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let l=v8(i.value);if(!l.ok)continue;let h=r.filter(b=>b.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(h.toLowerCase()==="hidden")continue;let u=c.get(i.pos.line),f=a.get(i.pos.line-1)??"",d=l.value,p={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},m=u?/^((?:\[.*\](?:\s+drive)?)?)\s*when\s+(.+)$/.exec(u.trim()):null;m&&(p.when=m[2].trim()),m?.[1]&&o.add(p);let g=m?m[1].trim():u?.trim(),v=g?/^\[(.*)\](\s+drive)?$/.exec(g):null;if(v?.[2]&&p.type==="number"&&typeof d=="number"&&(p.drive=!0),v){let b=v[1];if(b.includes(",")||/[a-zA-Z"]/.test(b)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(b))p.options=b.split(",").map(y=>{let[x,w]=y.split(":").map(z=>z.trim().replace(/^"|"$/g,"")),M=p8(x),k=p.type==="number"&&M!==void 0?M:x;return{name:w??x,value:k}});else{let y=b.split(":").map(p8);y.every(x=>x!==void 0)&&(y.length===1?p.max=y[0]:y.length===2?(p.min=y[0],p.max=y[1]):(p.min=y[0],p.step=y[1],p.max=y[2]))}}s.push(p)}for(let i of s){if(i.when===void 0)continue;if(!o.has(i)&&typeof y8(i.when)=="string"){delete i.when;continue}let l=gi(i.when,s);l&&(i.whenProblem=l,delete i.when)}return{parameters:s}}function y8(t){try{let e=c2(`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 g8=new Set(["==","!=","<","<=",">",">=","&&","||","+","-","*","/","%","!"]);function gi(t,e){let n=y8(t);if(typeof n=="string")return`its condition (${t}) is not an expression: ${n}`;let r=new Set(e.map(s=>s.name)),c=s=>{switch(s.kind){case"num":case"str":case"bool":case"undef":return;case"var":return r.has(s.name)?void 0:`uses ${s.name}, which is not a setting`;case"list":for(let o of s.items){if(o.kind!=="item")return"uses a list comprehension";let i=c(o.expr);if(i)return i}return;case"unary":return g8.has(s.op)?c(s.arg):`uses ${s.op}`;case"binary":return g8.has(s.op)?c(s.left)??c(s.right):`uses ${s.op}`;case"ternary":return c(s.cond)??c(s.then)??c(s.else);case"index":return c(s.target)??c(s.index);default:return"uses more than settings, values and operators"}},a=c(n);return a?`its condition (${t}) ${a}`:void 0}function Ot(t,e,n){if(t.when===void 0)return!0;let r=Object.fromEntries(n.map(a=>[a.name,a.initial])),c=Object.fromEntries(Object.entries(e).filter(([a])=>Object.prototype.hasOwnProperty.call(r,a)));try{let a=[...n.map(o=>`${o.name} = undef;`),`echo((${t.when}) ? 1 : 0);`];return new s3({overrides:{...r,...c},maxSteps:1e5}).run(c2(a.join(`
|
|
3025
|
+
`)).program).echoes[0]!=="0"}catch{return!0}}var b8=(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},p0=t=>Math.round(t*100)/100;function Ft(t,e={}){for(let[E,R]of Object.entries(e.params??{}))try{D4(E,R)}catch(Z){throw new l1(Z.message)}let{program:n}=c2(t),r=new Set(n.body.flatMap(E=>E.kind==="assign"?[E.name]:[])),c=Object.keys(e.params??{}).filter(E=>!E.startsWith("$")&&!r.has(E)),a=e.fonts?new je(e.fonts,e.defaultFont):void 0,s=new s3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),o=s.limits,i;try{i=s.run(n)}catch(E){let R=E instanceof RangeError?new l1(/call stack/i.test(E.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?"):E;throw R instanceof l1&&(R.echoes=s.echoes,R.warnings=[...s.warnings],a?.missing.size&&(R.missingFonts=[...a.missing])),R}let l=E=>i.globals.get(E).value,h=i.warnings;for(let E of c)h.push(`Setting "${E}" is not a variable of the program, so it is ignored.${z3(E,r)}`);let u=i.layers,f=E=>u.get(E)?.mode??"line",d=[...i.shape.parts];[...i.shape.layers.values()].some(E=>E.regions.length||E.lines.length)&&d.unshift({name:"part",qty:1,layers:i.shape.layers,thickness:U0(l("$thickness"))||3,kerf:U0(l("$kerf"))||0,material:b0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");try{for(let E of X5(t).parameters)E.whenProblem&&h.push(`Setting ${E.name} is always shown: ${E.whenProblem} (line ${t.slice(0,E.span[0]).split(`
|
|
3026
|
+
`).length})`)}catch{}let m=E=>JSON.stringify([E.thickness,E.material,[...E.layers].map(([R,Z])=>[R,Z.regions.map(K=>K.map(([k1,O1])=>[Math.round(k1*100),Math.round(O1*100)])),Z.lines.map(K=>K.map(([k1,O1])=>[Math.round(k1*100),Math.round(O1*100)]))])]),g=new Map,v=new Set;for(let E of d){let R=m(E),Z=E.mirrored?`${E.name}\0mirrored`:E.name,K=g.get(Z);K===void 0?g.set(Z,R):K!==R&&v.add(E.name)}for(let E of v)h.push(`Two different parts are named "${E}"; slots, glue and on = find parts by name, so give each its own.`);Li(d,h),xi(d,f,h),yi(d,f,h,i.hardware),bi(d,f,h);let b=[],y=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],w=[],M=[],k=new Set,z=[],A=l("$min_width"),S=A===void 0?1.5:U0(A),C=l("$label_parts")===!0,I=l("$join_lines")===!0,L=0;C&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let T=u.get("engrave-back");C&&a&&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 q=C&&!!a&&(!T||T.side==="back");if(q){let E=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:E?.color??"#000000",side:"back"})}let P=[];for(let E of d){let R=s1([...E.layers].filter(([g1])=>f(g1)==="cut").flatMap(([,g1])=>g1.regions)),Z;if(E.bends&&R.length){let g1=1/0,L1=-1/0;for(let z1 of R)for(let[m1]of z1)g1=Math.min(g1,m1),L1=Math.max(L1,m1);for(let[z1,m1]of R4(E.bends))(z1<g1-.001||m1>L1+.001)&&h.push(`Part "${E.name}" bends from x = ${q2(z1)} to ${q2(m1)}, beyond the part (x = ${q2(g1)} to ${q2(L1)}); only the part itself bends.`)}if(q&&R.length){Z=++L;let g1=Ci(R,String(Z),a,b0(l("$font")??""));if(g1.length){let L1=E.layers.get("engrave-back")??{regions:[],lines:[]};E.layers=new Map(E.layers).set("engrave-back",{regions:[...L1.regions,...g1],lines:L1.lines})}else h.push(`Part "${E.name}" is too small to take its number ${Z}.`)}if(S>0&&R.length){let g1=c0(c0(R,-S/2,"round"),S/2,"round"),L1=R0(g0(R,g1)).filter(z1=>z1.reduce((m1,S1)=>m1+b1(S1),0)>2*S*S);if(L1.length){let z1=L1.slice(0,3).map(m1=>{let[S1,Z1,i0,V1]=J0(new Map([["cut",{regions:m1,lines:[]}]]));return`[${p0((S1+i0)/2)}, ${p0((Z1+V1)/2)}]`});h.push(`Part "${E.name}" is narrower than ${S} mm ($min_width) in ${L1.length} place${L1.length>1?"s":""}, at ${z1.join(", ")}${L1.length>3?" and more":""} in the part's coordinates.`)}}let K=new Map;for(let[g1,L1]of E.layers){if(g1===n2||f(g1)==="guide"&&!e.guides)continue;let z1=s1(L1.regions),m1=L1.lines.filter(S1=>S1.length>=2);if((f(g1)==="line"||f(g1)==="guide")&&(m1=[...m1,...z1.map(S1=>[...S1,S1[0]])],z1=[]),R.length&&f(g1)!=="guide"){let S1=u.get(g1)?.bleed??0,Z1=S1>0?c0(R,S1,"round"):R;f(g1)!=="cut"&&(z1=K1(z1,Z1)),m1=Y0(m1,Z1,"inside")}I&&m1.length>1&&f(g1)!=="guide"&&(m1=_6(m1)),(z1.length||m1.length)&&K.set(g1,{regions:z1,lines:m1})}if(P.push(...Si(E.name,K,u)),R.length){let g1=[];for(let[z1,m1]of K){let S1=u.get(z1);if(S1?.mode==="cut"&&m1.lines.length)for(let Z1 of["front","back"])g1.push({layer:z1,mode:"line",color:"#000000",side:Z1,regions:[],lines:m1.lines});!S1||S1.mode!=="fill"&&S1.mode!=="line"||g1.push({layer:z1,mode:S1.mode,color:S1.color,side:S1.side??"front",regions:m1.regions,lines:m1.lines})}let L1={name:E.name,thickness:E.thickness,material:E.material,outline:R,...g1.length&&{marks:g1}};for(let z1=0;z1<(E.placements?.length??E.qty);z1++)M.push({...L1,copy:n5(E,z1),matrix:N0({at:[0,0,0],rotate:[0,0,0]}),placed:!1});if(E.placements){let z1=new Set;E.placements.forEach((m1,S1)=>{let Z1={...L1,copy:n5(E,S1),matrix:N0(m1),placed:!0,...E.bends&&{bends:E.bends},...E.step&&{step:E.step},...E.stack&&{stack:E.stack}};x.push(Z1);let i0=Z1.matrix.map(V1=>V1.toFixed(6)).join(",");z1.has(i0)&&k.add(Z1),z1.add(i0)}),z1.size<E.placements.length&&h.push(`Copies of part "${E.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 z1=0;z1<E.qty;z1++)w.push({...L1,copy:n5(E,z1),matrix:N0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...E.step&&{step:E.step}})}let k1=R0(R),O1=k1.length;if(O1>1){let g1=m1=>m1.reduce((S1,Z1)=>S1+b1(Z1),0),z1=[...k1].sort((m1,S1)=>g1(S1)-g1(m1)).slice(1,4).map(m1=>{let[S1,Z1,i0,V1]=J0(new Map([["cut",{regions:m1,lines:[]}]]));return`[${p0(S1)}, ${p0(Z1)}] to [${p0(i0)}, ${p0(V1)}]`}).join(", ");h.push(`Part "${E.name}" cuts into ${O1} separate pieces. Join them, or make them separate parts. The smaller ${O1===2?"one is":"ones are"} at ${z1}${O1>4?" and more":""}, in the part's coordinates.`)}let z0=0;for(let[g1,L1]of K)if(f(g1)==="cut"){for(let z1 of L1.regions)z0+=b8(z1,!0);for(let z1 of L1.lines)z0+=b8(z1,!1)}let n0=J0(K)??[0,0,0,0],j1=e.kerf??E.kerf;if(!(Number.isFinite(j1)&&j1>=0))throw new l1("$kerf must be a number, 0 or more");let X0={name:E.name,qty:E.qty,width:p0(n0[2]-n0[0]),height:p0(n0[3]-n0[1]),pieces:O1,cutLength:Math.round(z0),thickness:E.thickness,kerf:j1,material:E.material,...E.stack&&{stack:E.stack},...E.glue&&{glued:E.glue.host},...E.mirrored&&{mirrored:!0},...Z!==void 0&&{label:Z}};if(y&&y.parts.push({name:E.name,kerf:j1,qty:E.qty,...E.stack&&{stack:E.stack},...E.glue&&{glue:E.glue},...E.on&&{on:E.on},cutRegions:R.map(g1=>g1.map(([L1,z1])=>[L1,z1])),cutLines:[...K].filter(([g1])=>f(g1)==="cut").flatMap(([,g1])=>g1.lines.map(L1=>L1.map(([z1,m1])=>[z1,m1])))}),j1>0){for(let[g1,L1]of K)if(f(g1)==="cut"){let z1=L1.regions.filter(Z1=>b1(Z1)<0);L1.regions=c0(L1.regions,j1/2,"round",Math.min(.01,j1/20));let m1=L1.regions.filter(Z1=>b1(Z1)<0),S1=z1.length-m1.length;if(S1>0){let Z1=V1=>{let[X1,d0,O0,Z0]=J0(new Map([["cut",{regions:[V1],lines:[]}]]));return[(X1+O0)/2,(d0+Z0)/2]},i0=z1.map(Z1).filter(([V1,X1])=>!m1.some(d0=>x8(d0,V1,X1))).slice(0,3).map(([V1,X1])=>`[${p0(V1)}, ${p0(X1)}]`);h.push(`Part "${E.name}": ${S1} hole${S1===1?" is":"s are"} narrower than the ${j1} mm kerf and will not be cut${i0.length?`, at ${i0.join(", ")}${S1>i0.length?" and more":""} in the part's coordinates`:""}.`)}}}b.push(X0),z.push({info:X0,layers:K,copy:g1=>n5(E,g1)})}let F=new Map,j=x.filter(E=>!k.has(E)).flatMap(E=>{let R=ke(E);for(let Z of R)F.set(Z,E);return R}),{found:_,complete:Q}=en(j,o.maxCollisionPairs),H=_.filter(([E,R])=>F.get(E)!==F.get(R)).map(([E,R,Z])=>[F.get(E)??E,F.get(R)??R,Z,E,R]).filter(([E,R],Z,K)=>K.findIndex(([k1,O1])=>k1===E&&O1===R)===Z);Q||h.push(`The assembly has more than ${o.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[E,R,Z,K,k1]of H.slice(0,5)){let O1=(tn(K,k1)??Z).map(p0);h.push(`Parts "${E.name}"${E.copy>1?` (copy ${E.copy})`:""} and "${R.name}"${R.copy>1?` (copy ${R.copy})`:""} collide in the assembly, around [${O1.join(", ")}]. Check their edges and where they are placed.`)}if(H.length>5&&h.push(`${H.length-5} more pairs of parts collide in the assembly.`),Ai(P,h),x.length&&w.length){let E=[...new Set(w.map(R=>`"${R.name}"`))];h.push(`${E.length===1?"Part":"Parts"} ${E.slice(0,5).join(", ")}${E.length>5?` and ${E.length-5} more`:""} ${E.length===1?"has":"have"} no at or rotate, so ${E.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...J6(x,w))}let B=0;for(let E of z){let R=0;for(let Z of E.layers.values()){for(let K of Z.regions)R+=K.length;for(let K of Z.lines)R+=K.length}B+=R*E.info.qty}if(B>o.maxOutputPoints)throw new l1(`The files would have ${B} points, more than the limit of ${o.maxOutputPoints}. Use fewer copies or simpler shapes.`);let Y=e.sheet??(i.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(Y)||!(Number.isFinite(Y[0])&&Y[0]>0)||!(Number.isFinite(Y[1])&&Y[1]>0))throw new l1("$sheet must be [width, height], both more than 0");let e1=e.gap??U0(l("$gap")??3),X=e.margin??e1;if(!(Number.isFinite(e1)&&e1>=0))throw new l1("$gap must be a number, 0 or more");if(!(Number.isFinite(X)&&X>=0))throw new l1("margin must be a number, 0 or more");let M1=e.nest??l("$nest")===!0,v1=e.layout??(l("$layout")==="none"?"none":"pack"),p1=[...u.keys()].filter(E=>!["engrave","score","cut","guide"].includes(E)),G1=E=>(u.get(E)?.order??0)*2+(f(E)==="fill"?0:1),V=["engrave",...p1.map((E,R)=>[E,R]).sort((E,R)=>G1(E[0])-G1(R[0])||E[1]-R[1]).map(([E])=>E),"score","cut","guide"].map(E=>u.get(E)).filter(Boolean),U=V.filter(E=>E.side!=="back"),r1=[...V.filter(E=>E.side==="back")],h1=l("$registration")===!0;h1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),h1&&!U.some(E=>E.name==="registration")&&U.push(u.get("registration"));let a1=[],x1=[1,0,0,-1,0,0],J1=E=>J0(E)??[0,0,0,0],q1=(E,R)=>g3({layers:E,parts:[]},R).layers;if(v1==="none"){let E=[];for(let k1 of z)for(let O1=0;O1<k1.info.qty;O1++)E.push({part:k1.info.name,copy:k1.copy(O1),layers:q1(k1.layers,x1),rotated:!1});let R=new Map;for(let k1 of E)for(let[O1,z0]of k1.layers){let n0=R.get(O1)??{regions:[],lines:[]};for(let j1 of z0.regions)n0.regions.push(j1);for(let j1 of z0.lines)n0.lines.push(j1);R.set(O1,n0)}let Z=J1(R),K=[1,0,0,1,X-Z[0],X-Z[1]];for(let k1 of E)k1.layers=q1(k1.layers,K),k1.offset=[K[4],K[5]];a1.push(f0(E,Z[2]-Z[0]+2*X,Z[3]-Z[1]+2*X,z[0]?.info))}else{let E=new Map;for(let R of z){let Z=`${R.info.material}|${R.info.thickness}`;E.set(Z,[...E.get(Z)??[],R])}for(let R of E.values()){let[Z,K]=Y,k1=[];for(let V1 of R){let X1=q1(V1.layers,x1),d0=J1(X1),O0=d0[2]-d0[0],Z0=d0[3]-d0[1],H3=!1;(O0>Z-2*X||Z0>K-2*X)&&Z0<=Z-2*X&&O0<=K-2*X&&(X1=q1(X1,[0,1,-1,0,0,0]),d0=J1(X1),O0=d0[2]-d0[0],Z0=d0[3]-d0[1],H3=!0),(O0>Z-2*X||Z0>K-2*X)&&h.push(`Part "${V1.info.name}" (${p0(O0)} x ${p0(Z0)} mm) is bigger than the ${Z} x ${K} mm sheet.`),X1=q1(X1,[1,0,0,1,-d0[0],-d0[1]]);for(let X2=0;X2<V1.info.qty;X2++)k1.push({info:V1.info,layers:X1,w:O0,h:Z0,copy:V1.copy(X2),rotated:H3})}let O1=(V1,X1)=>X1.h-V1.h||X1.w-V1.w,z0=V1=>{let X1=0,d0=X,O0=X,Z0=0,H3=!1;for(let X2 of V1)d0>X&&d0+X2.w>Z-X&&(d0=X,O0+=Z0+e1,Z0=0),H3&&O0+X2.h>K-X&&(X1++,[d0,O0,Z0]=[X,X,0]),H3=!0,d0+=X2.w+e1,Z0=Math.max(Z0,X2.h);return X1+(H3?1:0)};k1.sort(O1);let n0=wi(k1,e1,V1=>f(V1)==="cut",[Z-2*X,K-2*X]).sort(O1),j1=n0.length<k1.length&&z0(n0)<z0(k1)?n0:k1,X0=M1?Mi(j1,e1,V1=>f(V1)==="cut"):j1,g1=[],L1=X,z1=X,m1=0,S1=0,Z1=0,i0=()=>{if(g1.length&&a1.length>=o.maxSheets)throw new l1(`The parts need more than ${o.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);g1.length&&a1.push(f0(g1,Math.max(S1+X,1),Math.max(Z1+X,1),R[0].info)),g1=[],L1=X,z1=X,m1=0,S1=0,Z1=0};for(let V1 of X0){L1>X&&L1+V1.w>Z-X&&(L1=X,z1+=m1+e1,m1=0),g1.length&&z1+V1.h>K-X&&i0(),g1.push({part:V1.info.name,copy:V1.copy,layers:q1(V1.layers,[1,0,0,1,L1,z1]),rotated:V1.rotated});for(let X1 of V1.inner??[])g1.push({part:X1.item.info.name,copy:X1.item.copy,layers:q1(X1.item.layers,[1,0,0,1,L1+X1.dx,z1+X1.dy]),rotated:X1.item.rotated});S1=Math.max(S1,L1+V1.w),Z1=Math.max(Z1,z1+V1.h),L1+=V1.w+e1,m1=Math.max(m1,V1.h)}i0()}}function f0(E,R,Z,K){let k1=p0(R),O1=p0(Z);if(h1){let j1=Math.min(5,X-1);if(!(j1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let X0=(g1,L1)=>[[g1,L1],[g1+j1,L1],[g1+j1,L1+j1],[g1,L1+j1]];E=[...E,{part:"registration",copy:1,layers:new Map([["registration",{regions:[X0(.5,.5),X0(k1-.5-j1,.5),X0(.5,O1-.5-j1)],lines:[]}]]),rotated:!1}]}}let z0=E.some(j1=>r1.some(X0=>j1.layers.has(X0.name))),n0=z0?E.map(j1=>({...j1,layers:q1(j1.layers,[-1,0,0,1,k1,0])})):[];return{width:k1,height:O1,material:K?.material??"material",thickness:K?.thickness??0,items:E,paths:Xe(E,U),svg:Ze(E,k1,O1,U),dxf:Ht(E,k1,O1,U),...z0&&{back:{paths:Xe(n0,r1),svg:Ze(n0,k1,O1,r1),dxf:Ht(n0,k1,O1,r1)}}}}let m0=a1.length===1?a1[0]:void 0,D=m0?[]:a1.flatMap((E,R)=>{let Z=a1.slice(0,R).reduce((K,k1)=>K+k1.height+10,0);return E.items.map(K=>({...K,layers:q1(K.layers,[1,0,0,1,0,Z])}))}),J=p0(Math.max(1,...a1.map(E=>E.width))),t1=p0(Math.max(1,a1.reduce((E,R)=>E+R.height,0)+10*Math.max(0,a1.length-1))),w1=m0?m0.svg:Ze(D,J,t1,U),n1=m0?m0.paths:Xe(D,U);return{sheets:a1,width:m0?.width??J,height:m0?.height??t1,paths:n1,svg:w1,parts:b,assembly:x,flat:M,layers:[...U,...r1],warnings:h,echoes:i.echoes,...y&&{analysis:y},hardware:i.hardware,steps:i.steps}}function $t(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 vi(t,e){if(!e||!t.length||e[0]===0&&e[1]===0)return t;let n=[...t];for(let r of t){let c=r.map(([a,s])=>[a+e[0],s+e[1]]);n.push(c);for(let a=0;a<r.length;a++){let s=(a+1)%r.length,o=[r[a],r[s],c[s],c[a]];Math.abs(b1(o))>1e-9&&n.push(b1(o)<0?o.reverse():o)}}return s1(n,"nonzero")}function Rt(t,e){let n=new Map(t);for(let[r,c]of t)n.set(r,{regions:g0(c.regions,e),lines:Y0(c.lines,e,"outside")});return n}function yi(t,e,n,r=[]){if(!t.some(l=>l.slots||l.bores))return;let c=new Map,a=l=>{let h=c.get(l);return h||(h=s1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},s=l=>(l.placements??[]).flatMap(h=>ke({name:l.name,copy:0,placed:!0,matrix:N0(h),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).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 x of l.bores??[]){let w=x.startsWith("!"),M=$t(w?x.slice(1):x),k=r.filter(z=>M(z.label??"")||M(z.kind));!k.length&&!w&&n.push(`Part "${l.name}": no hardware "${x}" to bore for.`);for(let z of k)w?h.splice(0,h.length,...h.filter(A=>A!==z)):h.includes(z)||h.push(z)}let u=!1,f=new Set;for(let x of l.slots??[]){let w=x.startsWith("!"),M=$t(w?x.slice(1):x),k=t.filter(z=>z!==l&&M(z.name));!k.length&&!w&&n.push(`Part "${l.name}": no part "${x}" to cut slots for.`);for(let z of k)w?f.delete(z):f.add(z)}let d=new Map,p=[...f].flatMap(x=>s(x).map(w=>(d.set(w,x.name),w))),m=new Set,g=(l.placements??[]).map(x=>s1(ke({name:l.name,copy:0,placed:!0,matrix:N0(x),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).flatMap(w=>{let M=[];if(l.slots){let k=p.map(A=>cn(w,[A],0));for(let A=0;A<k.length;A++)for(let S=A+1;S<k.length;S++){let[C,I]=[d.get(p[A]),d.get(p[S])];if(!k[A].length||!k[S].length||C===I||!C||!I)continue;let L=K1(k[A],k[S]);if(L.reduce((T,q)=>T+Math.abs(b1(q)),0)>.01){let T=L.flat().map(Q=>Q[0]),q=L.flat().map(Q=>Q[1]),[P,F,j,_]=[Math.min(...T),Math.min(...q),Math.max(...T),Math.max(...q)];m.add(`Tabs of "${C}" and "${I}" meet in the same slot in "${l.name}", at [${p0(P)}, ${p0(F)}] to [${p0(j)}, ${p0(_)}] in its coordinates. Move one's tabs along the edge.`)}}let z=k.flat();M=z.length?vi(c0(s1(z),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let z=on(w,k,l.fit??P5.turn);z&&K1([z],w.outline).some(A=>Math.abs(b1(A))>1e-4)&&(M.push(z),u=!0)}return l.bends?K1(M,c0(w.outline,1,"miter")):M}))),v=(x,w)=>m3(x,w).reduce((M,k)=>M+Math.abs(b1(k)),0)>.001,b=l.stack??1;if(b>1){let x=M=>g.filter((k,z)=>z%b===M),w=Array.from({length:b},(M,k)=>s1(x(k).flat()));if(w.slice(1).some(M=>v(w[0],M))){Array.from({length:b},(M,k)=>x(k)).some(M=>M.slice(1).some(k=>v(M[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(x=>v(g[0],x))&&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 x of m)n.push(x);l.bores&&h.length&&!u&&n.push(`Part "${l.name}": none of ${l.bores.map(x=>`"${x}"`).join(", ")} pass through it, so it has no bores.`);let y=s1(g.flat());if(!y.length){l.slots&&!l.slots.some(x=>x.includes("*"))&&n.push(`Part "${l.name}": none of ${l.slots.map(x=>`"${x}"`).join(", ")} pass through it, so it has no slots.`);continue}o.set(l,y)}for(let[l,h]of o)l.layers=Rt(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,p)=>({...l,name:`${l.name}, layer ${p+1}`,qty:l.qty/u,layers:d.length?Rt(l.layers,d):l.layers,placements:l.placements.filter((m,g)=>g%u===p),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function bi(t,e,n){if(!t.some(o=>o.halving))return;let r=o=>s1([...o.layers].filter(([i])=>e(i)==="cut").flatMap(([,i])=>i.regions)),c=o=>{let i=r(o);return(o.placements??[]).map(l=>({matrix:N0(l),thickness:o.thickness,outline:i}))},a=new Map,s=(o,i,l)=>{let h=a.get(o)??(o.placements??[]).map(()=>[]);h[i].push(...l),a.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("!"),p=$t(d?f.slice(1):f),m=t.filter(g=>g!==o&&p(g.name));!m.length&&!d&&n.push(`Part "${o.name}": no part "${f}" to halve with.`);for(let g of m)d?i.delete(g):i.add(g)}let l=0,h=0,u=c(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=c(f);u.forEach((p,m)=>d.forEach((g,v)=>{let b=dn(p,g,o.clearance??.1);h+=b.thin,b.a.length&&(l++,s(o,m,b.a),s(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 a){let l=i.map(h=>s1(h));l.slice(1).some(h=>m3(l[0],h).reduce((u,f)=>u+Math.abs(b1(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=Rt(o.layers,s1(l.flat()))}}function xi(t,e,n){let r=new Set;for(let c of t){if(c.on===void 0||!c.placements?.length)continue;let a=c.on,s=t.filter(m=>m.name===a&&m.placements?.length).flatMap(m=>m.placements.map((g,v)=>({q:m,m:N0(g),copy:n5(m,v)}))),o=t.filter(m=>m.name===c.name&&m.on===a).reduce((m,g)=>m+(g.placements?.length??0),0);if(!s.length){r.has(a)||n.push(`Part "${c.name}" is on "${a}", which is not a placed part.`),r.add(a);continue}let[i,l,h,u]=[1/0,1/0,-1/0,-1/0];for(let[m,g]of c.layers)if(e(m)==="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,p]=[(i+h)/2,(l+u)/2,c.thickness/2];c.placements=c.placements.map((m,g)=>{let v=n5(c,g),b=s.length===o&&s.find(z=>z.copy===v)||s[0];if(!b.q.bends?.length)return m;let y=N0(m),x=[y[0]*f+y[1]*d+y[2]*p+y[3],y[4]*f+y[5]*d+y[6]*p+y[7],y[8]*f+y[9]*d+y[10]*p+y[11]],w=v0(b.m),M=w[0]*x[0]+w[1]*x[1]+w[2]*x[2]+w[3],k=we(b.q.bends,b.q.thickness)[rn(b.q.bends,M)];return{...m,matrix:D1(b.m,D1(k,D1(w,y)))}})}}function Mi(t,e,n){var l;let r=[],c=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)b1(p)<0&&u.push([...p].reverse());return u.length?c0(s1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let p of h)for(let m=0,g=p.length-1;m<p.length;g=m++){let[v,b]=p[g],[y,x]=p[m];b<=f?x>f&&(y-v)*(f-b)-(u-v)*(x-b)>0&&d++:x<=f&&(y-v)*(f-b)-(u-v)*(x-b)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)b1(p)>0&&u.push(p);return s1(u)},o=(h,u)=>{let{w:f,h:d}=u,p=s(u),m=[];for(let g of p)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))m.push(g[v]);for(let g of h){if(b1(g)<=0)continue;let[v,b,y,x]=[1/0,1/0,-1/0,-1/0];for(let[M,k]of g)v=Math.min(v,M),b=Math.min(b,k),y=Math.max(y,M),x=Math.max(x,k);if(y-v<f||x-b<d)continue;let w=Math.max(.5,Math.min(f,d,y-v-f+1,x-b-d+1)/4);for(let M=b;M<=x-d+1e-9;M+=w)for(let k=v;k<=y-f+1e-9;k+=w){if(!m.every(([A,S])=>a(h,A+k,S+M)))continue;let z=p.map(A=>A.map(([S,C])=>[S+k,C+M]));if(g0(z,h).reduce((A,S)=>A+Math.abs(b1(S)),0)<.01)return[k,M]}}},i=[];for(let h of t){let u=!1;for(let d of h.inner?.length?[]:r){let p=o(d.region,h);if(!p)continue;let[m,g]=p;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+m,dy:d.oy+g}),d.region=g0(d.region,c0(s(h).map(b=>b.map(([y,x])=>[y+m,x+g])),e,"miter"));let v=c(h);v.length&&r.push({host:d.host,ox:d.ox+m,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;i.push(h);let f=c(h);f.length&&r.push({host:h,ox:0,oy:0,region:f})}return i}function wi(t,e,n,r){let c=new Map;for(let o of t)c.set(o.info,[...c.get(o.info)??[],o]);let a=[],s=(o,i)=>g3({layers:o,parts:[]},i).layers;for(let[,o]of c){let i=o[0],l=s1([...i.layers].filter(([d])=>n(d)).flatMap(([,d])=>d.regions.filter(p=>b1(p)>0))),h=l.reduce((d,p)=>d+b1(p),0)/(i.w*i.h),u=o.length>=2&&l.length&&h<.75?ki(l,i.w,i.h,e,r):void 0;if(!u){a.push(...o);continue}let f=s(i.layers,[-1,0,0,-1,i.w,i.h]);for(let d=0;d<o.length;d+=u.n){let p=o.slice(d,d+u.n);if(p.length===1){a.push(p[0]);continue}let m=u.at.slice(0,p.length),g=Math.min(...m.map(x=>x[0])),v=Math.min(...m.map(x=>x[1])),b=Math.max(...m.map(x=>x[0]+i.w))-g,y=Math.max(...m.map(x=>x[1]+i.h))-v;a.push({...p[0],layers:s(p[0].layers,[1,0,0,1,m[0][0]-g,m[0][1]-v]),w:b,h:y,inner:p.slice(1).map((x,w)=>({item:{...x,layers:(w+1)%2?f:x.layers},dx:m[w+1][0]-g,dy:m[w+1][1]-v}))})}}return a}function ki(t,e,n,r,c){let s=c0(t.map(y=>zi(y,.25)).filter(y=>y.length>=3),.25,"miter"),o=c0(s,r,"miter"),i=s.map(y=>y.map(([x,w])=>[e-x,n-w])),l=(y,[x,w])=>y.map(M=>M.map(([k,z])=>[k+x,z+w])),h=(y,x)=>!K1(y,x).some(w=>Math.abs(b1(w))>.001),u=(y,x,w,M)=>{let[k,z]=[0,M];if(h(y,l(x,w(z)))){if(h(y,l(x,w(k))))return w(k);for(let A=0;A<10;A++){let S=(k+z)/2;h(y,l(x,w(S)))?z=S:k=S}return w(z)}},f;for(let y of[!1,!0])for(let x=-10;x<=10;x++){let w=x/10*(y?e:n),M=u(o,i,A=>y?[w,A]:[A,w],(y?n:e)+r);if(!M)continue;let k=Math.max(e,M[0]+e)-Math.min(0,M[0]),z=Math.max(n,M[1]+n)-Math.min(0,M[1]);k>c[0]||z>c[1]||k*z<.85*2*e*n&&(!f||k*z<f.area)&&(f={d:M,across:y,area:k*z})}if(!f)return;let{d,across:p}=f,m=s1([...o,...c0(l(i,d),r,"miter")]),v=u(m,s,y=>p?[0,y]:[y,0],2*((p?n:e)+r)+Math.abs(p?d[1]:d[0])),b=[[0,0],[d[0],d[1]]];if(v){let y=x=>Math.max(...x.map(w=>w[0]+e))-Math.min(...x.map(w=>w[0]))<=c[0]&&Math.max(...x.map(w=>w[1]+n))-Math.min(...x.map(w=>w[1]))<=c[1];for(let x=2;x<500;x++){let w=Math.floor(x/2),M=x%2?[d[0]+w*v[0],d[1]+w*v[1]]:[w*v[0],w*v[1]];if(!y([...b,M]))break;let k=l(x%2?i:s,M),z=s1(b.slice(Math.max(0,b.length-3)).map((A,S,C)=>{let I=b.length-C.length+S;return c0(l(I%2?i:s,A),r,"miter")}).flat());if(!h(z,k))break;b.push(M)}}return{at:b,n:b.length}}function zi(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],[p,m]=o[u],g=Math.hypot(p-f,m-d),v=-1,b=-1;for(let y=h+1;y<u;y++){let[x,w]=o[y],M=g?Math.abs((p-f)*(d-w)-(f-x)*(m-d))/g:Math.hypot(x-f,w-d);M>v&&([v,b]=[M,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]),c=1;for(let o=2;o<t.length;o++)r(t[o])>r(t[c])&&(c=o);let a=n(t.slice(0,c+1)),s=n([...t.slice(c),t[0]]);return[...a,...s.slice(1,-1)]}function n5(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 Si(t,e,n){let r=[...n.keys()],c=[...e.keys()].filter(o=>n.get(o)?.mode==="fill"&&e.get(o).regions.length&&!["score","cut","guide"].includes(o)),a=[];if(c.length<2)return a;let s=o=>o==="engrave"?-1/0:(n.get(o)?.order??0)*2+r.indexOf(o)/r.length;c.sort((o,i)=>s(o)-s(i));for(let o=0;o<c.length-1;o++){let i=n.get(c[o]).side??"front",l=c.slice(o+1).filter(u=>(n.get(u).side??"front")===i);if(!l.length)continue;let h;for(let u of R0(e.get(c[o]).regions)){let f=u.reduce((w,M)=>w+b1(M),0);if(!(f>.001)||!c0(u,-.5,"round").length)continue;let d=u;for(let w of l)d.length&&(d=g0(d,e.get(w).regions));if(d.reduce((w,M)=>w+b1(M),0)>.001*Math.max(1,f))continue;let m=l.filter(w=>K1(u,e.get(w).regions).length),g=m.length?m:l;if(h){h.count++;for(let w of g)h.under.includes(w)||h.under.push(w);continue}let[v,b,y,x]=J0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:c[o],under:g,count:1,at:[p0((v+y)/2),p0((b+x)/2)]}}h&&a.push(h)}return a}function Ai(t,e){for(let n of t.slice(0,5)){let r=n.under.map(a=>`"${a}"`),c=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 ${c}, 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(a=>a.part)).size,c=[...new Set(n.map(a=>`"${a.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${c.length>1?"s":""} ${c.slice(0,5).join(", ")}${c.length>5?" and more":""}).`)}}function Li(t,e){let n=new Set,r=(c,a)=>{if(!c.glue||n.has(c))return;if(a.includes(c)){e.push(`Part "${c.name}" is glued in a loop of parts; it is left where it is.`),n.add(c);return}let s=t.find(h=>h.name===c.glue.host&&h!==c);if(!s?.placements){e.push(`Part "${c.name}" is glued to "${c.glue.host}", which is not a placed part.`),n.add(c);return}r(s,[...a,c]);let o=s.placements.map(N0),i=c.glue.face==="top"?s.thickness:-c.thickness,l=c.placements.length/(c.stack??1);c.placements=c.placements.map((h,u)=>{let f=o.length===l?o[Math.floor(u/(c.stack??1))]:o[0];return{...h,matrix:D1(f,D1(j0(0,0,i),N0(h)))}}),n.add(c)};for(let c of t)r(c,[])}function Ci(t,e,n,r){let c=0,a=50;for(let m=0;m<14;m++){let g=(c+a)/2;c0(t,-g,"round").length?c=g:a=g}if(c<1)return[];let s=c0(t,-c*.98,"round"),o=J0(new Map([["cut",{regions:s,lines:[]}]]));if(!o)return[];let[i,l]=[(o[0]+o[2])/2,(o[1]+o[3])/2];((m,g)=>s.reduce((v,b)=>v+(x8(b,m,g)?b1(b)>0?1:-1:0),0)>0)(i,l)||([i,l]=s.reduce((m,g)=>b1(g)>b1(m)?g:m)[0]);let u=Math.min(6,Math.max(2,c*.9)),f=Ge(n,e,{size:u,font:r,halign:"center",valign:"center",spacing:1}),d=J0(new Map([["t",{regions:f,lines:[]}]])),p=d?Math.min(1,1.6*c/Math.max(d[2]-d[0],1e-9)):1;return f.map(m=>m.map(([g,v])=>[i-g*p,l+v*p]).reverse())}function x8(t,e,n){let r=!1;for(let c=0,a=t.length-1;c<t.length;a=c++){let[s,o]=t[c],[i,l]=t[a];o>n!=l>n&&e<(i-s)*(n-o)/(l-o)+s&&(r=!r)}return r}var Pi=8,Ei=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,Ti=(t,e)=>Math.max(1,Ei.exec(t.slice(e-1))?.[0].length??1);function Ii(t,e,n={}){if(!(t instanceof l1))return`error: ${t instanceof Error?t.message:String(t)}`;let r=n.file??"design.kerf",c=(i,l,h)=>`${i?`<${i}>`:r}:${l}:${h}`,a=i=>i===void 0?e:(Object.prototype.hasOwnProperty.call($5,i)?$5[i]:void 0)??n.resolve?.(i),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${c(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
|
|
3027
|
+
`)?.[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=Ti(l,t.col),p=f.replace(/[^\t]/g," ");s.push(`${u} |`,`${h} | ${l}`,`${u} | ${p}${"^".repeat(d)}`)}}for(let i of Vi(t,c))s.push(` = ${i}`);let o=t.call?O5(t.call):void 0;return o&&s.push(` = ${Z4(o)}: ${o.doc}`),s.join(`
|
|
3028
|
+
`)}function Vi(t,e){let n=a=>`in ${a.kind==="module"?"module ":""}${a.name}(), called at ${e(a.file,a.line,a.col)}${a.count>1?` (${a.count} times)`:""}`,r=t.trace.slice(0,Pi).map(n),c=t.trace.length-r.length+t.traceMore;return c&&r.push(`and ${c} more call${c===1?"":"s"}`),r}var M8=new Set(["module","function","if","else","for","let","each","use","include"]),Hi=new Set(["true","false","undef"]),Oi=new Set(["for","if","let","function"]),Dt={"(":")","[":"]","{":"}"},$i=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function Ri(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 qt(t){let{tokens:e}=V5(t),n=[],r=0,c=0,a=s=>{for(;r<s;)if(t[r]===`
|
|
3029
|
+
`)c++,r++;else if(t.startsWith("//",r)){let o=t.indexOf(`
|
|
3030
|
+
`,r),i=o<0?t.length:o;n.push({kind:"line",text:t.slice(r,i).trimEnd(),breaks:c}),[c,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,`
|
|
3031
|
+
`);n.push({kind:"block",text:i,breaks:c}),[c,r]=[0,o]}else r++};for(let s of e){if(a(s.pos.offset),s.type==="eof")break;let o=Ri(t,s);n.push({kind:"token",text:o,token:s,breaks:c}),c=0,r=s.pos.offset+o.length}return n}function Nt(t,e={}){c2(t);let n=" ".repeat(e.indent??2),r=qt(t),c=[],a=null,s=-1,o=0,i=[],l=0,h=!0,u=0,f=!1,d=0,p=0,m,g,v=()=>i[i.length-1],b=()=>!v()||v().open==="{"&&!v().record,y=z=>z.kind==="token"&&!!v()&&z.text===Dt[v().open],x=(z,A)=>{a!==null&&c.push(a.trimEnd()),A&&c.length&&c[c.length-1]!==""&&c.push(""),s++,o=z,a=n.repeat(z),g=void 0},w=z=>{if(y(z))return v().outer;if(!b())return!m||m.text===","||Dt[m.text]?v().inner:m.role==="header"?p+1:v().inner+1;let A=v()?v().inner:0;return h?A:f?u+1:d+1},M=z=>r.slice(z).find(A=>A.kind==="token");for(let z=0;z<r.length;z++){let A=r[z],S=s<0||A.breaks>0;if(A.kind!=="token"){if(S){let L=M(z),T=L?y(L)?v().inner:w(L):0;x(T,A.breaks>1&&s>=0)}else a+=" ";a+=A.text,g=A;continue}let C=A.text,I=A.token.type;if("*!#%".includes(C)&&b()&&!f&&(h||m?.text===")"||m?.text==="else")?A.role="modifier":(C==="!"||(C==="-"||C==="+")&&(!m||Fi(m)))&&(A.role="unary"),C===":"){let L=v();(L?L.ternaries:l)?L?L.ternaries--:l--:L?.open==="["&&(A.role="range")}if((C==="}"&&v()?.record||C==="{"&&m&&["=","(",",","[","?",":"].includes(m.text))&&(A.role="record"),S){let L=w(A);x(L,A.breaks>1&&s>=0),b()&&!y(A)&&(d=L)}else g&&Di(g,A)&&(a+=" ");if(b()&&h&&!y(A)&&(u=o,f=I==="id"&&r[z+1]?.kind==="token"&&r[z+1].text==="="||C==="function",h=!1),a+=C,Dt[C]){let L=v(),T=A.role==="record",q=L&&L.line===s&&(L.open!=="{"||L.record)&&(C!=="{"||T);i.push({record:T,open:C,outer:o,inner:q?L.inner:o+1,line:s,ternaries:0,header:C==="("&&!!m&&Oi.has(m.text)&&m.token?.type==="id"}),C==="{"&&!T&&(h=!0)}else if(y(A)){let L=i.pop();L.header&&(A.role="header",p=L.outer),C==="}"&&!L.record&&(h=!0)}else C===";"&&b()||I==="str"&&C.startsWith("<")&&b()?h=!0:C==="?"&&(v()?v().ternaries++:l++);m=A,g=A}for(a!==null&&c.push(a.trimEnd());c.length&&c[c.length-1]==="";)c.pop();let k=c.length?c.join(`
|
|
2572
3032
|
`)+`
|
|
2573
|
-
`:"";return
|
|
2574
|
-
<h2><span>${p}</span> ${
|
|
2575
|
-
<div class="view">${
|
|
2576
|
-
${g.size?`<h3>Parts</h3>${
|
|
2577
|
-
${v.size?`<h3>Hardware</h3>${
|
|
2578
|
-
</section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${
|
|
3033
|
+
`:"";return qi(t,k),k}var Fi=t=>$i.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&M8.has(t.text)||t.role==="unary"||t.role==="modifier";function Di(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 c=t.token,a=c.type==="num"||c.type==="str"&&!n.startsWith("<")||c.type==="id"&&(!M8.has(n)||Hi.has(n))||n===")"&&t.role!=="header"||n==="]";return r==="("?n==="for"||n==="if"||n==="let"||!a&&n!=="function":r==="["?!a:!0}function qi(t,e){let n=qt(t),r=qt(e);if(!(n.length===r.length&&n.every((a,s)=>a.kind===r[s].kind&&a.text===r[s].text)))throw new l1("The formatter would change the program, so it was left as it is")}function w8(t){let e=new Map;for(let n of t.sheets)for(let r of n.items){let[c,a]=r.offset??[0,0],s=i=>i.map(([l,h])=>[l-c,a-h]),o=new Map;for(let[i,l]of r.layers)o.set(i,{regions:l.regions.map(s),lines:l.lines.map(s)});e.set(`${r.part}\0${r.copy}`,o)}return e}var k8=t=>Math.round(t*100)/100,Ye=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function Ni(t,e,n=.01){let r=w8(t),c=w8(e),a=[],s=o=>{let[i,l]=o.split("\0");return{part:i,copy:Number(l)}};for(let o of new Set([...r.keys(),...c.keys()])){let i=r.get(o),l=c.get(o);if(!i||!l){a.push({...s(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=m3(u.regions,f.regions),p=d.reduce((x,w)=>x+Math.abs(b1(w)),0),m=new Set(u.lines.map(Ye)),g=new Set(f.lines.map(Ye)),v=u.lines.filter(x=>!g.has(Ye(x))),b=f.lines.filter(x=>!m.has(Ye(x)));if(p<=n&&!v.length&&!b.length)continue;let y=J0(new Map([[h,{regions:p>n?d:[],lines:[...v,...b]}]]));a.push({...s(o),layer:h,change:i.has(h)?l.has(h)?"changed":"removed":"added",...p>n&&{area:k8(p)},...v.length&&{linesRemoved:v.length},...b.length&&{linesAdded:b.length},...y&&{at:y.map(k8)}})}}return a}var Ui=[Math.SQRT1_2,Math.SQRT1_2,0],Bi=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],Ut=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],_i=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),r5=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],z8=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ji=(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]],Gi=(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]],B2=t=>t.replace(/[&<>"]/g,e=>({"&":"&","<":"<",">":">",'"':"""})[e]);function S8(t,e){let n=parseInt(t.slice(1),16),r=c=>Math.max(0,Math.min(255,Math.round(c*e))).toString(16).padStart(2,"0");return`#${r(n>>16)}${r(n>>8&255)}${r(n&255)}`}function Wi(t,e,n){let r=(o,i,l)=>Gi(t.matrix,t.bends?.length?U3(t.bends,t.thickness,[o,i,l]):[o,i,l]),c=[],a=(o,i)=>{if(o.length<3)return;let l=ji(z8(o[1],o[0]),z8(o[2],o[0])),h=[0,0,0];for(let p=0;p<o.length;p++){let m=o[p],g=o[(p+1)%o.length];h[0]+=(m[1]-g[1])*(m[2]+g[2]),h[1]+=(m[2]-g[2])*(m[0]+g[0]),h[2]+=(m[0]-g[0])*(m[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(r5(f,Ut)<=0)return;let d=o.reduce((p,m)=>[p[0]+m[0],p[1]+m[1],p[2]+m[2]],[0,0,0]);c.push({pts:o,holes:i,color:S8(e,.55+.45*Math.max(0,r5(f,_i))),depth:r5([d[0]/o.length,d[1]/o.length,d[2]/o.length],Ut),stroke:n})},s=t.thickness;for(let o of B3(t.outline,t.bends)){let i=u=>u.reduce((f,d,p)=>f+d[0]*u[(p+1)%u.length][1]-u[(p+1)%u.length][0]*d[1],0),l=o.find(u=>i(u)>0)??o[0],h=o.filter(u=>u!==l);a(l.map(([u,f])=>r(u,f,s)),h.map(u=>u.map(([f,d])=>r(f,d,s)))),a([...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,p]=u[f],[m,g]=u[(f+1)%u.length];a([r(d,p,0),r(m,g,0),r(m,g,s),r(d,p,s)])}}return c}function Xi(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:r5(r,Ut)+n/2,stroke:String(n)}]}function Zi(t,e=640,n=420){let r=m=>[r5(m,Ui),-r5(m,Bi)],c=1/0,a=1/0,s=-1/0,o=-1/0;for(let m of t)for(let g of m.pts){let[v,b]=r(g);c=Math.min(c,v),s=Math.max(s,v),a=Math.min(a,b),o=Math.max(o,b)}if(!Number.isFinite(c))return"";let i=Math.max(s-c,o-a)*.04+1,l=Math.min(e/(s-c+2*i),n/(o-a+2*i)),h=m=>{let[g,v]=r(m);return`${((g-c+i)*l).toFixed(1)} ${((v-a+i)*l).toFixed(1)}`},u=m=>`M${m.map(h).join("L")}Z`,f=[...t].sort((m,g)=>m.depth-g.depth).map(m=>m.pts.length===2?`<path d="M${h(m.pts[0])}L${h(m.pts[1])}" stroke="${m.color}" stroke-width="${(Number(m.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(m.pts)}${(m.holes??[]).map(u).join("")}" fill="${m.color}" fill-rule="evenodd" stroke="${m.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((s-c+2*i)*l).toFixed(0),p=((o-a+2*i)*l).toFixed(0);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d} ${p}" width="${d}" height="${p}">${f.join("")}</svg>`}var Yi="#d9bf91",Ji="#cfc6b8",Ki="#e08a3c";function Qi(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),c=t.steps.length?t.steps:["Put the parts together"],a=f=>t.steps.length?f??0:1,s=f=>y3[f]??K2[f]?.color??"#9a9a9a",o=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",i=[],l=r.filter(f=>a(f.step)===0);c.forEach((f,d)=>{let p=d+1,m=[];for(let b of r){let y=a(b.step);y>p||m.push(...Wi(b,y===p?Ki:b.step===void 0&&!t.steps.length?Yi:Ji,y===p?"#7a3e0c":"#8a8274"))}for(let b of t.hardware){let y=t.steps.length?b.step:1;y<=p&&m.push(...Xi(b,y===p?s(b.kind):S8(s(b.kind),.8)))}let g=new Map;for(let b of r)a(b.step)===p&&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)===p){let y=typeof b.size=="number"?`${b.size} mm`:`${b.size[0]} x ${b.size[1]} mm`,x=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?`${B2(b.label)}: `:""}${B2(b.kind)}, ${y}, ${x} mm long`;v.set(w,(v.get(w)??0)+1)}i.push(`<section>
|
|
3034
|
+
<h2><span>${p}</span> ${B2(f)}</h2>
|
|
3035
|
+
<div class="view">${Zi(m)}</div>
|
|
3036
|
+
${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> ${B2(b)}${y>1?` × ${y}`:""}`))}`:""}
|
|
3037
|
+
${v.size?`<h3>Hardware</h3>${o([...v].map(([b,y])=>`${b}${y>1?` × ${y}`:""}`))}`:""}
|
|
3038
|
+
</section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${B2(f.name)}${f.mirrored?" (mirrored)":""}</td><td>${f.qty}</td><td>${f.width} × ${f.height} mm</td><td>${f.thickness} mm ${B2(f.material)}</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} × ${f.height} mm, ${f.thickness} mm ${B2(f.material)}</figcaption></figure>`).join("");return`<!doctype html>
|
|
2579
3039
|
<html lang="en">
|
|
2580
3040
|
<head>
|
|
2581
3041
|
<meta charset="utf-8">
|
|
2582
3042
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2583
|
-
<title>${
|
|
3043
|
+
<title>${B2(e)}: assembly</title>
|
|
2584
3044
|
<style>
|
|
2585
3045
|
body { font: 15px/1.45 system-ui, sans-serif; color: #222; margin: 24px auto; max-width: 760px; padding: 0 16px; }
|
|
2586
3046
|
h1 { font-size: 26px; margin: 0 0 4px; }
|
|
@@ -2597,55 +3057,61 @@ figure { margin: 12px 0; } figcaption { color: #666; font-size: 13px; }
|
|
|
2597
3057
|
</style>
|
|
2598
3058
|
</head>
|
|
2599
3059
|
<body>
|
|
2600
|
-
<h1>${
|
|
2601
|
-
<p class="note">${t.parts.reduce((f,d)=>f+d.qty,0)} parts on ${t.sheets.length} sheet${t.sheets.length===1?"":"s"}, ${
|
|
3060
|
+
<h1>${B2(e)}</h1>
|
|
3061
|
+
<p class="note">${t.parts.reduce((f,d)=>f+d.qty,0)} parts on ${t.sheets.length} sheet${t.sheets.length===1?"":"s"}, ${c.length} step${c.length===1?"":"s"}.${l.length?" Some parts are in place before the first step.":""} The parts of each step are drawn in orange.</p>
|
|
2602
3062
|
<h3>Parts</h3>
|
|
2603
3063
|
<table><tr><th>#</th><th>Part</th><th>Qty</th><th>Size</th><th>Material</th></tr>${h}</table>
|
|
2604
3064
|
${u}
|
|
2605
|
-
${
|
|
3065
|
+
${i.join(`
|
|
2606
3066
|
`)}
|
|
2607
3067
|
</body>
|
|
2608
3068
|
</html>
|
|
2609
|
-
`}var
|
|
2610
|
-
`).length;throw new Error(`${o} (line ${l})`)};for(;a<t.length;){let o=t.indexOf("<",a),l=o<0?t.length:o;if(l>a&&(r[r.length-1].text+=v8(t.slice(a,l),n)),o<0)break;if(a=o,t.startsWith("<!--",a)){let h=t.indexOf("-->",a+4);h<0&&s("Unclosed comment"),e.push(t.slice(a+4,h)),a=h+3}else if(t.startsWith("<![CDATA[",a)){let h=t.indexOf("]]>",a+9);h<0&&s("Unclosed CDATA section"),r[r.length-1].text+=t.slice(a+9,h),a=h+3}else if(t.startsWith("<?",a)){let h=t.indexOf("?>",a+2);h<0&&s("Unclosed processing instruction"),a=h+2}else if(t.startsWith("<!",a)){let h=0,u=a+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(a,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];a=u+1}else if(t[a+1]==="/"){let h=t.indexOf(">",a);h<0&&s("Unclosed end tag");let u=t.slice(a+2,h).trim(),f=r.pop();(!f||f===c||f.name!==u)&&s(`</${u}> does not match <${f?.name??"nothing"}>`),a=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(a,a+256));h||s("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};a+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=a;let d=f.exec(t);if(d||s(`Bad attribute in <${u.name}>`),a=f.lastIndex,d[5]){r[r.length-1].children.push(u),d[5]===">"&&r.push(u);break}u.attrs[d[1]]=v8(d[3]??d[4]??"",n)}}}r.length>1&&s(`<${r[r.length-1].name}> is not closed`);let i=c.children[0];if(!i)throw new Error("The file has no elements");return{root:i,comments:e}}var t2={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"}},l6={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"},ki=Object.fromEntries(Object.entries(l6).reverse().map(([t,e])=>[e,t]));function T5(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(l6[t])return l6[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let c=n[1];if(c.length===3||c.length===4)return"#"+[...c.slice(0,3)].map(r=>r+r).join("");if(c.length===6||c.length===8)return"#"+c.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let c=n[1].split(/[\s,/]+/).filter(Boolean);if(c.length>=3){let r=c.slice(0,3).map(a=>{let s=a.endsWith("%")?parseFloat(a)*255/100:parseFloat(a);return Math.max(0,Math.min(255,Math.round(s||0)))});return c[3]!==void 0&&parseFloat(c[3])===0?"none":"#"+r.map(a=>a.toString(16).padStart(2,"0")).join("")}}return"#000000"}var B3=(t,e)=>E3(t,Math.PI/12,e),E5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function Si(t){let e=ae;if(!t)return e;for(let[,n,c]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let r=E5(c),a=(r[0]??0)*Math.PI/180,s=ae;if(n==="matrix"&&r.length===6)s=r;else if(n==="translate")s=[1,0,0,1,r[0]??0,r[1]??0];else if(n==="scale")s=[r[0]??1,0,0,r[1]??r[0]??1,0,0];else if(n==="rotate"){let i=Math.cos(a),o=Math.sin(a),[l,h]=[r[1]??0,r[2]??0];s=[i,o,-o,i,l-i*l+o*h,h-o*l-i*h]}else n==="skewX"?s=[1,0,Math.tan(a),1,0,0]:n==="skewY"&&(s=[1,Math.tan(a),0,1,0,0]);e=w3(e,s)}return e}function Li(t,e){let n=[],c=[],r=[0,0],a=[0,0],s=(l,h)=>s5(e,[l,h]),i=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,o=l=>{c.length&&n.push({segs:c,closed:l}),c=[]};for(let l of t)if(l.type==="M")o(!1),r=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);i(a,h)||c.push({c:"L",a,b:h}),a=h}else if(l.type==="Q"){let h=s(l.x1,l.y1),u=s(l.x,l.y);c.push({c:"C",a,p1:[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),a=u}else if(l.type==="C"){let h=s(l.x,l.y);c.push({c:"C",a,p1:s(l.x1,l.y1),p2:s(l.x2,l.y2),b:h}),a=h}else c.length&&!i(a,r)&&c.push({c:"L",a,b:r}),o(!0),a=r;return o(!1),n}var Ai=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],Ci=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function b8(t){let e={};for(let n of t.split(";")){let c=n.indexOf(":");if(c<0)continue;let r=n.slice(0,c).trim().toLowerCase(),a=n.slice(c+1).replace(/!important/i,"").trim();r&&a&&(e[r]=a)}return e}function Pi(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,c]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let r=b8(c);for(let a of n.split(",")){let s=a.trim(),i=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(s);if(!i)continue;let o=[],l;for(let[,h,u]of i[2].matchAll(/([.#])([\w-]+)/g))h==="."?o.push(u):l=u;e.push({tag:i[1]&&i[1]!=="*"?i[1]:void 0,id:l,classes:o,decls:r})}}return e}function Ti(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 o6(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])*Ti(n[2].toLowerCase(),e)}var Ei=/^(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 Ii(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Ei.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Vi(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return t2.score;if(/engrav|raster|etch/.test(e))return t2.engrave;if(/\bguide/.test(e))return t2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return t2.cut}function x8(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=y8(t),c=n.root;if(c.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let r=[],a=n.comments.some(P=>/Adobe Illustrator/i.test(P)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&r.push("Adobe Illustrator file: px measured at 72 per inch.");let i=E5(c.attrs.viewBox??""),o=o6(c.attrs.width,s),l=o6(c.attrs.height,s),h=25.4/s,u=h,f=h,d=0,p=0;i.length===4&&i[2]>0&&i[3]>0&&(u=o!==void 0?o/i[2]:l!==void 0?l/i[3]:h,f=l!==void 0?l/i[3]:u,d=i[0],p=i[1]),o===void 0&&l===void 0&&e.dpi===void 0&&!a&&r.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let m=l??(i.length===4?i[3]*f:0),g=w3([1,0,0,-1,0,m],[u,0,0,f,-d*u,-p*f]),v=[],y=new Map,b=P=>{P.name==="style"&&v.push(...Pi(P.text)),P.attrs.id&&y.set(P.attrs.id,P),P.children.forEach(b)};b(c);let x=(P,Y)=>{let W={};for(let a1 of Object.keys(Y))Ci.has(a1)&&(W[a1]=Y[a1]);for(let a1 of Ai)P.attrs[a1]!==void 0&&(W[a1]=P.attrs[a1]);let b1=(P.attrs.class??"").split(/\s+/).filter(Boolean);for(let a1 of v)(!a1.tag||a1.tag===P.name)&&(!a1.id||a1.id===P.attrs.id)&&a1.classes.every($1=>b1.includes($1))&&Object.assign(W,a1.decls);return P.attrs.style&&Object.assign(W,b8(P.attrs.style)),W},M=[],w=[],k=0,z=0,S=0,L=0,I=0,q=0,R=2e4,N=[],G=P=>Number.isFinite(P[0])&&Number.isFinite(P[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],J=P=>[...V,"x1","y1","x2","y2","points"].some(Y=>P.attrs[Y]!==void 0&&E5(P.attrs[Y]).some(W=>!Number.isFinite(W))),o1=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),Z=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),p1=P=>{let Y=W=>parseFloat(P.attrs[W]??"0")||0;switch(P.name){case"path":return B3(P.attrs.d??"",()=>S++);case"rect":{let[W,b1,a1,$1]=[Y("x"),Y("y"),Y("width"),Y("height")];if(a1<=0||$1<=0)return[];let e1=P.attrs.rx!==void 0?Y("rx"):P.attrs.ry!==void 0?Y("ry"):0,I1=P.attrs.ry!==void 0?Y("ry"):e1;return e1=Math.min(Math.abs(e1),a1/2),I1=Math.min(Math.abs(I1),$1/2),e1<=0||I1<=0?B3(`M${W} ${b1}H${W+a1}V${b1+$1}H${W}Z`):B3(`M${W+e1} ${b1}H${W+a1-e1}A${e1} ${I1} 0 0 1 ${W+a1} ${b1+I1}V${b1+$1-I1}A${e1} ${I1} 0 0 1 ${W+a1-e1} ${b1+$1}H${W+e1}A${e1} ${I1} 0 0 1 ${W} ${b1+$1-I1}V${b1+I1}A${e1} ${I1} 0 0 1 ${W+e1} ${b1}Z`)}case"circle":case"ellipse":{let[W,b1]=[Y("cx"),Y("cy")],a1=P.name==="circle"?Y("r"):Y("rx"),$1=P.name==="circle"?Y("r"):P.attrs.ry!==void 0?Y("ry"):a1;return a1<=0||$1<=0?[]:B3(`M${W+a1} ${b1}A${a1} ${$1} 0 0 1 ${W} ${b1+$1}A${a1} ${$1} 0 0 1 ${W-a1} ${b1}A${a1} ${$1} 0 0 1 ${W} ${b1-$1}A${a1} ${$1} 0 0 1 ${W+a1} ${b1}Z`)}case"line":return B3(`M${Y("x1")} ${Y("y1")}L${Y("x2")} ${Y("y2")}`);case"polyline":case"polygon":{let W=E5(P.attrs.points??"");if(W.length<4)return[];let b1=`M${W[0]} ${W[1]}`;for(let a1=2;a1+1<W.length;a1+=2)b1+=`L${W[a1]} ${W[a1+1]}`;return B3(P.name==="polygon"?b1+"Z":b1)}}},E=P=>(P.text+P.children.map(Y=>Y.name==="tspan"?" "+E(Y):"").join("")).replace(/\s+/g," ").trim(),$=(P,Y,W,b1,a1,$1)=>{if($1>64||o1.has(P.name)||I&&++q>R)return;let e1=x(P,W);if(e1.display==="none"||e1.visibility==="hidden"||e1.opacity==="0"){(P.children.length||Z.has(P.name))&&z++;return}let I1=w3(Y,Si(P.attrs.transform));if(!I1.every(Number.isFinite)){L++;return}let r0=Ii(P),C=P.attrs["inkscape:groupmode"]==="layer",_=b1;if(P.name==="g"||P.name==="svg"||P.name==="a"||P.name==="switch"){let _1=P.attrs["inkscape:label"]??P.attrs["data-name"]??P.attrs.id,l1=Vi(_1);if(P.attrs["data-mode"]&&_1&&/^(cut|line|fill|guide)$/.test(P.attrs["data-mode"])){let g1=T5(e1.stroke,"#000000"),d1=T5(e1.fill,"#000000"),v1=P.attrs["data-mode"]==="fill"?d1:g1;_=t2[_1]??{name:_1,mode:P.attrs["data-mode"],color:v1&&v1.startsWith("#")?v1:"#00aa00"}}else l1&&(_=l1);if(P!==c&&P.name==="svg"){let g1=d1=>parseFloat(P.attrs[d1]??"0")||0;I1=w3(I1,[1,0,0,1,g1("x"),g1("y")])}let z1=C||l1||P===c||!r0?a1:[r0,...a1];N.push(P);for(let g1 of P.children)$(g1,I1,e1,_,z1,$1+1);N.pop();return}if(P.name==="use"){let _1=y.get((P.attrs.href??P.attrs["xlink:href"]??"").replace(/^#/,""));if(!_1||N.includes(_1))return;let l1=d1=>parseFloat(P.attrs[d1]??"0")||0,z1=w3(I1,[1,0,0,1,l1("x"),l1("y")]),g1=_1.name==="symbol"?{..._1,name:"g"}:_1;N.push(_1),I++,$(g1,z1,e1,_,r0?[r0,...a1]:a1,$1+1),I--,N.pop();return}if(P.name==="image"){k++;return}let U=T5(e1.color,"#000000")??"#000000",s1=parseFloat(e1["stroke-width"]??"1"),Q=T5(e1.stroke,U);Q&&(s1===0||e1["stroke-opacity"]==="0")&&(Q="none");let L1=T5(e1.fill??"black",U);if(e1["fill-opacity"]==="0"&&(L1="none"),P.name==="text"){let _1=E(P);if(!_1)return;let l1=P.children.find(l0=>l0.name==="tspan"),z1=l0=>E5(P.attrs[l0]??l1?.attrs[l0]??"0")[0]??0,g1=s5(I1,[z1("x"),z1("y")]),d1=Math.sqrt(Math.abs(I1[0]*I1[3]-I1[1]*I1[2])),v1=(o6(e1["font-size"],96)??16*h)/h;if(!G(g1)||!Number.isFinite(v1*d1)){L++;return}let U1=e1["text-anchor"];w.push({text:_1,at:g1,size:v1*d1,angle:Math.atan2(-I1[1],I1[0])*180/Math.PI,font:(e1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:U1==="middle"?"center":U1==="end"?"right":"left",stroke:Q,fill:L1,layer:_});return}if(P.name!=="path"&&J(P)){L++;return}let Y1=p1(P);if(!Y1){for(let _1 of P.children)$(_1,I1,e1,_,a1,$1+1);return}let G1=Li(Y1,I1),A1=G1.filter(_1=>_1.segs.every(l1=>G(l1.a)&&G(l1.b)&&(l1.c==="L"||G(l1.p1)&&G(l1.p2))));A1.length<G1.length&&L++,A1.length&&M.push({subs:A1,stroke:Q,fill:P.name==="line"||P.name==="polyline"?"none":L1,fillRule:e1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:_,names:r0?[r0,...a1]:a1})};$(c,g,{},void 0,[],0),k&&r.push(`${k} embedded image${k===1?" was":"s were"} left out: trace ${k===1?"it":"them"} to paths first.`),z&&r.push(`${z} hidden element${z===1?" was":"s were"} left out.`),S&&r.push(`${S} path${S===1?" has":"s have"} bad data: read up to the error, as browsers draw ${S===1?"it":"them"}.`),L&&r.push(`${L} element${L===1?" was":"s were"} left out: ${L===1?"its":"their"} numbers are too large to draw.`),q>R&&r.push(`The drawing repeats its elements with <use> more than ${R.toLocaleString("en")} times: only the first ${R.toLocaleString("en")} copies were read.`);let X=P=>{let[Y,W,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return Y>=200&&W<=80&&b1<=80},j=P=>{let[Y,W,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return b1>=200&&Y<=80&&W<=80},w1=P=>!!P.stroke&&P.stroke!=="none",W1=M.filter(P=>!P.layer),E1=new Map;for(let P of W1)w1(P)&&P.stroke.startsWith("#")&&E1.set(P.stroke,(E1.get(P.stroke)??0)+P.subs.length);let Z1=[...E1.keys()],p0=Z1.filter(X),o0=new Set(p0.length?p0:Z1.length?[Z1.reduce((P,Y)=>(E1.get(Y)??0)>(E1.get(P)??0)?Y:P)]:[]),A=M.some(P=>w1(P)&&!P.layer)||M.some(P=>P.layer),F=new Map,t1=(P,Y)=>{if(P&&P!=="none"){let W=P.startsWith("#")?P:"#000000";if(o0.has(W))return t2.cut;if(W==="#00a0ff")return t2.guide;if(j(W))return t2.score;if(!F.has(W)){let b1=ki[W]??"color_"+W.slice(1);F.set(W,{name:b1,mode:"line",color:W})}return F.get(W)}if(Y&&Y!=="none")return A?t2.engrave:t2.cut};!A&&M.some(P=>P.fill&&P.fill!=="none")?r.push("The file has filled shapes and no strokes: the shapes are cut out."):!p0.length&&o0.size&&r.push(`No red lines: ${[...o0][0]} lines, the most common colour, are cut.`),F.size&&r.push(`Lines in ${[...F.values()].map(P=>P.color).join(", ")} went on their own layer${F.size===1?"":"s"}, set to mark, not cut.`);let r1=[];for(let P of M){let Y=P.layer??t1(P.stroke,P.fill);if(!Y)continue;let W=!P.layer&&Y===t2.cut&&!w1(P);r1.push({subs:P.subs,layer:Y,fillRule:P.fillRule,names:P.names,filled:W})}let y1=[];for(let P of w){let Y=P.layer??t1(P.fill!=="none"?void 0:P.stroke,P.fill);Y&&y1.push({...P,layer:Y.mode==="cut"&&A?t2.engrave:Y})}return{items:r1,texts:y1,notes:r}}var F1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),u2=([t,e],n)=>{let c=n*Math.PI/180,r=Math.cos(c),a=Math.sin(c);return[t*r-e*a,t*a+e*r]},u6=(t,e)=>[t[0]+e[0],t[1]+e[1]],f2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function u3(t,e=.005){let n=[t.segs[0].a];for(let c of t.segs)if(c.c==="L")n.push(c.b);else{let r=F1(c.a,c.p1)+F1(c.p1,c.p2)+F1(c.p2,c.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(r/e))));for(let s=1;s<=a;s++){let i=s/a,o=1-i;n.push([o*o*o*c.a[0]+3*o*o*i*c.p1[0]+3*o*i*i*c.p2[0]+i*i*i*c.b[0],o*o*o*c.a[1]+3*o*o*i*c.p1[1]+3*o*i*i*c.p2[1]+i*i*i*c.b[1]])}}return t.closed&&n.length>1&&F1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function w2(t,e=!0){let n=0;for(let c=1;c<t.length;c++)n+=F1(t[c-1],t[c]);return e&&t.length>2?n+F1(t[t.length-1],t[0]):n}function O2(t,e,n){let c=[],r=e?t.length:t.length-1;for(let a=0;a<r;a++){let s=t[a],i=t[(a+1)%t.length];c.push(s);let o=Math.floor(F1(s,i)/n);for(let l=1;l<o;l++)c.push([s[0]+(i[0]-s[0])*l/o,s[1]+(i[1]-s[1])*l/o])}return!e&&t.length&&c.push(t[t.length-1]),c}function Z2(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?((t[0]-e[0])*c+(t[1]-e[1])*r)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}var h3=class{constructor(e,n,c){this.size=c;this.cells=new Map;for(let r of e){let a=n?r.length:r.length-1;for(let s=0;s<a;s++){let i=r[s],o=r[(s+1)%r.length],l=Math.max(1,Math.ceil(F1(i,o)/(c*2)));for(let h=0;h<l;h++){let u=[i[0]+(o[0]-i[0])*h/l,i[1]+(o[1]-i[1])*h/l],f=[i[0]+(o[0]-i[0])*(h+1)/l,i[1]+(o[1]-i[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/c),p=Math.floor(Math.max(u[0],f[0])/c),m=Math.floor(Math.min(u[1],f[1])/c),g=Math.floor(Math.max(u[1],f[1])/c);for(let v=d;v<=p;v++)for(let y=m;y<=g;y++){let b=`${v},${y}`,x=this.cells.get(b);x?x.push([u,f]):this.cells.set(b,[[u,f]])}}}}}near(e,n){let c=Math.floor((e[0]-n)/this.size),r=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let i=c;i<=r;i++)for(let o=a;o<=s;o++)for(let[l,h]of this.cells.get(`${i},${o}`)??[])if(Z2(e,l,h)<=n)return!0;return!1}meets(e,n,c){let r=Math.max(1,Math.ceil(F1(e,n)/(this.size*2)));for(let a=0;a<r;a++){let s=[e[0]+(n[0]-e[0])*a/r,e[1]+(n[1]-e[1])*a/r],i=[e[0]+(n[0]-e[0])*(a+1)/r,e[1]+(n[1]-e[1])*(a+1)/r],o=Math.floor((Math.min(s[0],i[0])-c)/this.size),l=Math.floor((Math.max(s[0],i[0])+c)/this.size),h=Math.floor((Math.min(s[1],i[1])-c)/this.size),u=Math.floor((Math.max(s[1],i[1])+c)/this.size);for(let f=o;f<=l;f++)for(let d=h;d<=u;d++)for(let[p,m]of this.cells.get(`${f},${d}`)??[])if(w8(s,i,p,m)<=c)return!0}return!1}};function w8(t,e,n,c){let r=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),a=r(n,c,t),s=r(n,c,e),i=r(t,e,n),o=r(t,e,c);return a*s<0&&i*o<0?0:Math.min(Z2(t,n,c),Z2(e,n,c),Z2(n,t,e),Z2(c,t,e))}function Hi(t,e,n=.2){let c=t.length;if(c<4)return!1;let r=[0];for(let h=1;h<=c;h++)r.push(r[h-1]+F1(t[h-1],t[h%c]));let a=r[c],s=S0([t]),i=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(c)),o=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/i),p=Math.floor((Math.max(h[0],u[0])+e)/i),m=Math.floor((Math.min(h[1],u[1])-e)/i),g=Math.floor((Math.max(h[1],u[1])+e)/i);if((p-d+1)*(g-m+1)>4096)return null;for(let v=d;v<=p;v++)for(let y=m;y<=g;y++)f.push(`${v},${y}`);return f};for(let h=0;h<c;h++){let u=t[h],f=t[(h+1)%c],d=l(u,f);if(!d)return!1;for(let p of d)for(let m of o.get(p)??[]){let g=Math.abs(r[h]-r[m]);if(!(Math.min(g,a-g)-F1(u,f)-F1(t[m],t[(m+1)%c])<n)&&w8(u,f,t[m],t[(m+1)%c])<=e)return!0}for(let p of d){let m=o.get(p);m?m.push(h):o.set(p,[h])}}return!1}function z8(t,e){let n=t.map(()=>!1),c=[],r=t.map(l=>S0([l]));t.forEach((l,h)=>{let u=x1([l]),f=u.reduce((m,g)=>m+H1(g),0),d=w2(l),p=u.reduce((m,g)=>m+w2(g),0);(u.length!==1||Math.abs(f-Math.abs(H1(l)))>d*.001+1e-6||Math.abs(p-d)>d*.001+.05||Hi(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new h3([t[l]],!0,Math.max(e*4,1))),h},i=t.map((l,h)=>h).sort((l,h)=>r[l][0]-r[h][0]),o=[];for(let l of i){let[h,u,f,d]=r[l];for(let p=o.length-1;p>=0;p--)r[o[p]][2]<h-e&&o.splice(p,1);for(let p of o){let m=r[p];if(m[1]>d+e||m[3]<u-e)continue;let[g,v]=t[l].length<=t[p].length?[l,p]:[p,l],y=t[g],b=s(v);for(let x=0;x<y.length;x++)if(b.meets(y[x],y[(x+1)%y.length],e)){c.push([l,p]);break}}o.push(l)}return{self:n,pairs:c}}function f3(t,e,n,c=!0){if(!t.length||!e.length)return t.length===e.length;let r=Math.max(n*2,.2),a=new h3(t,c,Math.max(n*4,1)),s=new h3(e,c,Math.max(n*4,1));for(let i of t)for(let o of O2(i,c,r))if(!s.near(o,n))return!1;for(let i of e)for(let o of O2(i,c,r))if(!a.near(o,n))return!1;return!0}function k8(t,e,n){let c=new h3([t,...e],!0,Math.max(n*4,1)),r=a=>H2(a,t)&&!e.some(s=>H2(a,s));return(a,s)=>{let i=s?a.length:a.length-1;if(i<1)return!1;let o;for(let l=0;l<i;l++){let h=a[l],u=a[(l+1)%a.length];if(!c.meets(h,u,n)){o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==i-1)return!1;let f=F1(h,u),d=Math.min(n*3,f/3)/f,p=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,m=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(c.meets(p,m,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?r(o):!0}}function S8(t,e,n){if(!t.length)return!1;let c=new h3([e],!0,Math.max(n*4,1));return t.some(r=>O2(r,!1,Math.max(n*2,.2)).some(a=>c.near(a,n)))}function H2(t,e){let n=!1;for(let c=0,r=e.length-1;c<e.length;r=c++){let[a,s]=e[c],[i,o]=e[r];s>t[1]!=o>t[1]&&t[0]<(i-a)*(t[1]-s)/(o-s)+a&&(n=!n)}return n}function P4(t){let e=t.length;if(e<3)return null;let n=0,c=0;for(let[g,v]of t)n+=g,c+=v;n/=e,c/=e;let r=0,a=0,s=0,i=0,o=0,l=0,h=0;for(let[g,v]of t){let y=g-n,b=v-c;r+=y*y,a+=y*b,s+=b*b,i+=y*y*y,o+=b*b*b,l+=y*b*b,h+=b*y*y}let u=r*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(i+l)/2,d=(o+h)/2,p=(f*s-d*a)/u,m=(d*r-f*a)/u;return{c:[p+n,m+c],r:Math.sqrt(p*p+m*m+(r+s)/e)}}function _3(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)F1(t[0],t[o])>F1(t[0],t[n])&&(n=o);let c=o=>{if(o.length<3)return o;let l=0,h=0;for(let f=1;f<o.length-1;f++){let d=Z2(o[f],o[0],o[o.length-1]);d>l&&(l=d,h=f)}return l<=e?[o[0],o[o.length-1]]:[...c(o.slice(0,h+1)).slice(0,-1),...c(o.slice(h))]},r=c(t.slice(0,n+1)),a=c([...t.slice(n),t[0]]),s=[...r.slice(0,-1),...a.slice(0,-1)],i=[];for(let o=0;o<s.length;o++){let l=s[(o-1+s.length)%s.length],h=s[(o+1)%s.length];Z2(s[o],l,h)>e&&i.push(s[o])}return i.length>=3?i:s}function L8(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=_3(a,.002),i=s.length,o=s.findIndex((u,f)=>F1(u,s[(f+1)%i])>=.5);if(i<4||o<0)continue;let l=H1(a)>0,h=[];for(let u=1;u<=i;u++){let f=(o+u)%i,d=s[f],p=s[(f+1)%i];if(F1(d,p)<.3){h.length||h.push(d),h.push(p);continue}if(h.length>=3){let m=P4(h),[g,v,y]=[h[0],h[1],h[h.length-1]],b=(v[0]-g[0])*(y[1]-g[1])-(v[1]-g[1])*(y[0]-g[0]);m&&m.r>.005&&m.r<.6&&(b>0===l?e:n).push(m.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let c=e[Math.floor(e.length/2)],r=a=>Math.abs(a-c)<=Math.max(.005,c*.1);if(!(c>.2||n.filter(r).length>e.length*.2))return e.filter(r).length>=e.length*.8?c:void 0}function f6(t,e){let n=t.length,c=i=>F1(t[i],t[(i+1)%n])<e*1.5,r=t.findIndex((i,o)=>!c(o));if(r<0)return t;let a=[],s=r;do{let i=(s+1)%n;for(;c(i)&&i!==s;)i=(i+1)%n;let o=(i-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[i],f=t[(i+1)%n],d;if(o>0){let p=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(p)>1e-12){let m=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/p,g=[l[0]+m*(h[0]-l[0]),l[1]+m*(h[1]-l[1])],v=t[(s+1+Math.floor(o/2))%n],y=[];for(let M=1;M<=o+1;M++)y.push(t[(s+M)%n]);let b=y.length>=3?P4(y):{c:g,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&F1(g,v)<=e*2&&m>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let p=1;p<=o;p++)a.push(t[(s+p)%n]);s=i}while(s!==r);return a}function T1(t){for(let c of[0,1,2]){let r=10**c,a=Math.round(t*r)/r;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var S1=t=>String(T1(t)),n0=t=>`[${S1(t[0])}, ${S1(t[1])}]`;function Oi(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 z2(t,e,n){let c=[];(T1(t[0])!==0||T1(t[1])!==0)&&c.push(`translate(${n0(t)})`);let r=Oi(e);return r!==0&&c.push(`rotate(${r})`),[...c,n].join(" ")}function I5(t,e){return{poly:t,area:Math.abs(H1(t)),box:S0([t]),ends:e?.segs.map(n=>n.a)}}var C4=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function T4(t,e){let n=w2(t.poly),c=O2(t.poly,!0,Math.min(.5,n/256)),r=P4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:c);if(!r||r.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,r.r*3e-4));for(let i of t.poly)if(Math.abs(F1(i,r.c)-r.r)>a)return;let s=a+r.r*2e-4;for(let i of c)if(Math.abs(F1(i,r.c)-r.r)>s)return;if(!(Math.abs(t.area-Math.PI*r.r*r.r)>n*a*2))return{kind:"circle",body:`circle(d = ${S1(r.r*2)})`,at:r.c,angle:0,center:r.c,circle:r,radius:r.r}}function A8(t){let e=0,n=0;for(let[s,i]of t)e+=s,n+=i;e/=t.length,n/=t.length;let c=0,r=0,a=0;for(let[s,i]of t)c+=(s-e)**2,r+=(i-n)**2,a+=(s-e)*(i-n);return .5*Math.atan2(2*a,c-r)*180/Math.PI}function E4(t,e){let n=w2(t.poly),c=O2(t.poly,!0,Math.min(.5,n/256)),r=A8(c),a=c.map(m=>u2(m,-r)),[s,i,o,l]=S0([a]),h=(o-s)/2,u=(l-i)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+o)/2,(i+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[m,g]of a){let v=Math.hypot((m-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 p=u2(f,r);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${n0([h,u])})`,at:p,angle:r,center:p}}function C8(t){let e=0,n=0;for(let c=0;c<t.length;c++){let r=t[c],a=t[(c+1)%t.length],s=F1(r,a);s>e&&(e=s,n=Math.atan2(a[1]-r[1],a[0]-r[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function I4(t,e){let n=_3(t.poly,e/4),c=C8(n),r=w2(t.poly),a=O2(t.poly,!0,Math.min(.5,r/256)).map(y=>u2(y,-c)),[s,i,o,l]=S0([a]),h=o-s,u=l-i;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,i],[o,i],[o,l],[s,l]].map(y=>Math.min(...a.map(b=>F1(b,y)))*f),p=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;p<e&&(p=0),p=Math.min(p,h/2,u/2);let m=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-m[0])-(h/2-p),M=Math.abs(b-m[1])-(u/2-p),w=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-p;if(Math.abs(w)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*p*p))>r*e)return;let g=u2(m,c),v=T1(p)>0?`, r = ${S1(p)}`:"";return{kind:"rect",radius:p,body:`rect(${n0([h,u])}, center = true${v})`,at:g,angle:c,center:g,rect:{w:h,h:u,r:p}}}function V4(t,e){let n=_3(t.poly,e/4),c=n.length;if(c<3||c>48)return;let r=0,a=0;for(let[u,f]of n)r+=u/c,a+=f/c;let s=[r,a],i=n.map(u=>F1(u,s)),o=n.map((u,f)=>F1(u,n[(f+1)%c])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-r)*180/Math.PI);if(l(o)<=e&&l(i)<=e&&c<=24){let u=i.reduce((p,m)=>p+m,0)/c,f=360/c,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${c}, ${S1(u)})`,at:s,angle:d,center:s}}if(c%2===0&&c>=4&&l(o)<=e){let u=i.filter((x,M)=>M%2===0),f=i.filter((x,M)=>M%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,M)=>x+M,0)/u.length,p=f.reduce((x,M)=>x+M,0)/f.length,m=h[0];if(p>d&&([d,p]=[p,d],m=h[1]),d-p<e)return;let g=c/2,v=360/g,y=((m-90)%v+v)%v;v-y<.01&&(y=0);let b=T1(p)===T1(d*.45);return{kind:"star",body:`star(${g}, ${S1(d)}${b?"":`, ${S1(p)}`})`,at:s,angle:y,center:s}}}function Ri(t,e,n){let[c,r,a,s]=e,i=[[],[],[],[]],o=[[],[],[],[]];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 p=f[1];Math.abs(p-r)<=n?i[0].push(L4(f[0]-c,d[0]-c)):Math.abs(p-s)<=n?i[2].push(L4(a-f[0],a-d[0])):(o[0].push(p-r),o[2].push(s-p))}else{let p=f[0];Math.abs(p-a)<=n?i[1].push(L4(f[1]-r,d[1]-r)):Math.abs(p-c)<=n?i[3].push(L4(s-f[1],s-d[1])):(o[1].push(a-p),o[3].push(p-c))}}let l=[a-c,s-r,a-c,s-r],h=o.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:i.map(u=>Fi(u,n)),depth:h,length:l}}var L4=(t,e)=>t<e?[t,e]:[e,t];function Fi(t,e){t.sort((c,r)=>c[0]-r[0]);let n=[];for(let[c,r]of t){let a=n[n.length-1];a&&c<=a[1]+e?a[1]=Math.max(a[1],r):n.push([c,r])}return n}var h6=t=>t.reduce((e,[n,c])=>e+c-n,0);function $i(t,e,n,c,r,a){let s=[C4(0,0,t,e)],i=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],o=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=o[h];for(let f=0;f<c[h];f++){let d=u*(f+.5)/c[h];s.push(C4(d-r[h]/2,-a,d+r[h]/2,0).map(i[h]))}}),x1(s)}function d6(t,e,n){let c=_3(t.poly,e/4);if(c.length<8)return;let r=C8(c),a=c.map(E=>u2(E,-r)),s=e/2;for(let E=0;E<a.length;E++){let $=a[E],X=a[(E+1)%a.length];if(Math.abs($[0]-X[0])>s&&Math.abs($[1]-X[1])>s)return}let i=S0([a]),o=Ri(a,i,s),l=(E,$)=>E.map(X=>X.map(j=>u6(j,$))),h=(E,$)=>f3([a],l(E,$),e),u=(E,$,X)=>{let j=u2(E,r);return{kind:"tabs",body:$,at:j,angle:r,center:u2([(i[0]+i[2])/2,(i[1]+i[3])/2],r),...X}},f=w2(t.poly),d=[0,1,2,3].filter(E=>h6(o.outer[E])<o.length[E]-s);if(!d.length)return;let p=d.map(E=>o.depth[E]).filter(E=>E!==void 0);if(!p.length)return;let m=[...new Set([n,...p].filter(E=>!!E).map(T1))];for(let E of m){let $=T1(i[2]-i[0]),X=T1(i[3]-i[1]),j=[[]];for(let U=0;U<4;U++){let Q=h6(o.outer[U])>=o.length[U]-2*E-s?["flat"]:["out","in"],L1=[];for(let Y1 of j)for(let G1 of Q)L1.push([...Y1,G1]);j.splice(0,j.length,...L1)}let w1=Math.max(3*E,6),W1=new Set([w1]);for(let U of d){let s1=o.outer[U].length;for(let Q of[2*s1-1,2*s1+1,2*s1-3,2*s1+3])Q>=3&&W1.add(T1(o.length[U]/Q))}for(let U of W1)for(let s1 of j){if(s1.every(A1=>A1==="flat"))continue;let Q=c4($,X,s1,E,U);if(Math.abs(Math.abs(Q.reduce((A1,_1)=>A1+H1(_1),0))-t.area)>f*e||!h(Q,[i[0],i[1]]))continue;let Y1=s1.every(A1=>A1===s1[0])?`"${s1[0]}"`:`[${s1.map(A1=>`"${A1}"`).join(", ")}]`,G1=U===w1||[0,1].every(A1=>c3(o.length[A1],U)===c3(o.length[A1],w1));return u([i[0],i[1]],`finger_rect(${n0([$,X])}, ${Y1}${G1?"":`, finger = ${S1(U)}`})`,{kind:"fingers",thickness:E,edges:s1,finger:G1?w1:U})}let E1=[0,1,2,3].map(U=>d.includes(U)&&o.depth[U]!==void 0&&Math.abs(o.depth[U]-E)<=s);if(!E1.some(Boolean))continue;let Z1=i[0]+(E1[3]?E:0),p0=i[1]+(E1[0]?E:0),o0=T1(i[2]-(E1[1]?E:0)-Z1),A=T1(i[3]-(E1[2]?E:0)-p0),F=[o0,A,o0,A],t1=[E1[3]?E:0,E1[0]?E:0,E1[1]?E:0,E1[2]?E:0],r1=[0,0,0,0],y1=[0,0,0,0],P=!0;for(let U=0;U<4&&P;U++){if(!E1[U])continue;let s1=o.outer[U].map(([Q,L1])=>[Q-t1[U],L1-t1[U]]);r1[U]=s1.length,y1[U]=s1.length?T1(s1.reduce((Q,[L1,Y1])=>Q+Y1-L1,0)/s1.length):0,s1.forEach(([Q,L1],Y1)=>{(Math.abs((Q+L1)/2-F[U]*(Y1+.5)/r1[U])>s||Math.abs(L1-Q-y1[U])>s)&&(P=!1)})}if(!P||!h($i(o0,A,E1,r1,y1,E),[Z1,p0]))continue;let Y=E1.every(Boolean)?"":`[${E1.join(", ")}]`,W=[0,1,2,3].filter(U=>E1[U]),b1=U=>Math.max(1,Math.round(F[U]/50)),a1=W.every(U=>r1[U]===b1(U)),$1=W.every(U=>r1[U]===r1[W[0]]),e1=a1?void 0:$1?r1[W[0]]:null,I1=W.every(U=>Math.abs(y1[U]-F[U]/(2*r1[U]))<=s),r0=W.every(U=>Math.abs(y1[U]-y1[W[0]])<=s),C=I1?void 0:r0?y1[W[0]]:null,_;if(e1!==null&&C!==null){let U=[n0([o0,A])];Y?U.push(Y):(e1!==void 0||C!==void 0)&&U.push("true"),e1!==void 0&&U.push(`count = ${e1}`),C!==void 0&&U.push(`width = ${S1(C)}`),_=`tab_rect(${U.join(", ")})`}else{let U=[Q=>Q,Q=>`translate(${n0([o0,0])}) rotate(90) ${Q}`,Q=>`translate(${n0([o0,A])}) rotate(180) ${Q}`,Q=>`translate(${n0([0,A])}) rotate(270) ${Q}`],s1=[`rect(${n0([o0,A])});`];for(let Q of W){let L1=[S1(F[Q])];r1[Q]!==b1(Q)&&L1.push(`count = ${r1[Q]}`),Math.abs(y1[Q]-F[Q]/(2*r1[Q]))>s&&L1.push(`width = ${S1(y1[Q])}`),s1.push(U[Q](`tabs(${L1.join(", ")});`))}_=`{
|
|
2611
|
-
${
|
|
3069
|
+
`}var el={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function A8(t,e={}){return t.replace(/&(#x[0-9a-fA-F]+|#\d+|[A-Za-z_][\w.-]*);/g,(n,r)=>{if(r[0]==="#"){let c=r[1]==="x"?parseInt(r.slice(2),16):parseInt(r.slice(1),10);return Number.isFinite(c)&&c<=1114111?String.fromCodePoint(c):n}return el[r]??e[r]??n})}function L8(t){let e=[],n={},r={name:"#document",attrs:{},children:[],text:""},c=[r],a=0,s=i=>{let l=t.slice(0,a).split(`
|
|
3070
|
+
`).length;throw new Error(`${i} (line ${l})`)};for(;a<t.length;){let i=t.indexOf("<",a),l=i<0?t.length:i;if(l>a&&(c[c.length-1].text+=A8(t.slice(a,l),n)),i<0)break;if(a=i,t.startsWith("<!--",a)){let h=t.indexOf("-->",a+4);h<0&&s("Unclosed comment"),e.push(t.slice(a+4,h)),a=h+3}else if(t.startsWith("<![CDATA[",a)){let h=t.indexOf("]]>",a+9);h<0&&s("Unclosed CDATA section"),c[c.length-1].text+=t.slice(a+9,h),a=h+3}else if(t.startsWith("<?",a)){let h=t.indexOf("?>",a+2);h<0&&s("Unclosed processing instruction"),a=h+2}else if(t.startsWith("<!",a)){let h=0,u=a+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(a,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];a=u+1}else if(t[a+1]==="/"){let h=t.indexOf(">",a);h<0&&s("Unclosed end tag");let u=t.slice(a+2,h).trim(),f=c.pop();(!f||f===r||f.name!==u)&&s(`</${u}> does not match <${f?.name??"nothing"}>`),a=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(a,a+256));h||s("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};a+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=a;let d=f.exec(t);if(d||s(`Bad attribute in <${u.name}>`),a=f.lastIndex,d[5]){c[c.length-1].children.push(u),d[5]===">"&&c.push(u);break}u.attrs[d[1]]=A8(d[3]??d[4]??"",n)}}}c.length>1&&s(`<${c[c.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 d2={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"}},_t={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"},tl=Object.fromEntries(Object.entries(_t).reverse().map(([t,e])=>[e,t]));function Z5(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(_t[t])return _t[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(c=>c+c).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 c=r.slice(0,3).map(a=>{let s=a.endsWith("%")?parseFloat(a)*255/100:parseFloat(a);return Math.max(0,Math.min(255,Math.round(s||0)))});return r[3]!==void 0&&parseFloat(r[3])===0?"none":"#"+c.map(a=>a.toString(16).padStart(2,"0")).join("")}}return"#000000"}var c5=(t,e)=>W3(t,Math.PI/12,e),Y5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function nl(t){let e=E4;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let c=Y5(r),a=(c[0]??0)*Math.PI/180,s=E4;if(n==="matrix"&&c.length===6)s=c;else if(n==="translate")s=[1,0,0,1,c[0]??0,c[1]??0];else if(n==="scale")s=[c[0]??1,0,0,c[1]??c[0]??1,0,0];else if(n==="rotate"){let o=Math.cos(a),i=Math.sin(a),[l,h]=[c[1]??0,c[2]??0];s=[o,i,-i,o,l-o*l+i*h,h-i*l-o*h]}else n==="skewX"?s=[1,0,Math.tan(a),1,0,0]:n==="skewY"&&(s=[1,Math.tan(a),0,1,0,0]);e=R3(e,s)}return e}function rl(t,e){let n=[],r=[],c=[0,0],a=[0,0],s=(l,h)=>k5(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),c=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);o(a,h)||r.push({c:"L",a,b:h}),a=h}else if(l.type==="Q"){let h=s(l.x1,l.y1),u=s(l.x,l.y);r.push({c:"C",a,p1:[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),a=u}else if(l.type==="C"){let h=s(l.x,l.y);r.push({c:"C",a,p1:s(l.x1,l.y1),p2:s(l.x2,l.y2),b:h}),a=h}else r.length&&!o(a,c)&&r.push({c:"L",a,b:c}),i(!0),a=c;return i(!1),n}var cl=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],al=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function C8(t){let e={};for(let n of t.split(";")){let r=n.indexOf(":");if(r<0)continue;let c=n.slice(0,r).trim().toLowerCase(),a=n.slice(r+1).replace(/!important/i,"").trim();c&&a&&(e[c]=a)}return e}function sl(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let c=C8(r);for(let a of n.split(",")){let s=a.trim(),o=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(s);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:c})}}return e}function P8(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 Bt(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])*P8(n[2].toLowerCase(),e)}var ol=/^(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 il(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!ol.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function ll(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return d2.score;if(/engrav|raster|etch/.test(e))return d2.engrave;if(/\bguide/.test(e))return d2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return d2.cut}function E8(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=L8(t),r=n.root;if(r.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let c=[],a=n.comments.some(D=>/Adobe Illustrator/i.test(D)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&c.push("Adobe Illustrator file: px measured at 72 per inch.");let o=Y5(r.attrs.viewBox??""),i=Bt(r.attrs.width,s),l=Bt(r.attrs.height,s),h=25.4/s,u=h,f=h,d=0,p=0,m=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],p=o[1],i!==void 0&&l!==void 0)){let D=(r.attrs.preserveAspectRatio??"").trim().split(/\s+/).filter(Boolean);D[0]==="defer"&&D.shift();let J=D[0]??"xMidYMid";if(J!=="none"){let t1=D[1]==="slice"?Math.max(u,f):Math.min(u,f),w1=(n1,E)=>n1.test(J)?0:E.test(J)?1:.5;m=(i-o[2]*t1)*w1(/xMin/,/xMax/),g=(l-o[3]*t1)*w1(/YMin/,/YMax/),u=f=t1}}i===void 0&&l===void 0&&e.dpi===void 0&&!a&&c.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let v=l??(o.length===4?o[3]*f:0),b=R3([1,0,0,-1,0,v],[u,0,0,f,-d*u+m,-p*f+g]),y=o.length===4?o[2]:(i??0)/h,x=o.length===4?o[3]:(l??0)/h,w=(D,J)=>{if(D===void 0)return 0;let t1=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(D);if(!t1)return parseFloat(D)||0;let w1=Number(t1[1]),n1=t1[2].toLowerCase();return n1==="%"?w1/100*(J==="x"?y:J==="y"?x:Math.hypot(y,x)/Math.SQRT2):n1===""||n1==="px"?w1:w1*P8(n1,s)/h},M=[],k=new Map,z=D=>{D.name==="style"&&M.push(...sl(D.text)),D.attrs.id&&k.set(D.attrs.id,D),D.children.forEach(z)};z(r);let A=(D,J)=>{let t1={};for(let n1 of Object.keys(J))al.has(n1)&&(t1[n1]=J[n1]);for(let n1 of cl)D.attrs[n1]!==void 0&&(t1[n1]=D.attrs[n1]);let w1=(D.attrs.class??"").split(/\s+/).filter(Boolean);for(let n1 of M)(!n1.tag||n1.tag===D.name)&&(!n1.id||n1.id===D.attrs.id)&&n1.classes.every(E=>w1.includes(E))&&Object.assign(t1,n1.decls);return D.attrs.style&&Object.assign(t1,C8(D.attrs.style)),t1},S=[],C=[],I=0,L=0,T=0,q=0,P=0,F=0,j=2e4,_=[],Q=D=>Number.isFinite(D[0])&&Number.isFinite(D[1]),H=["x","y","width","height","rx","ry","cx","cy","r"],B=D=>[...H,"x1","y1","x2","y2","points"].some(J=>D.attrs[J]!==void 0&&Y5(D.attrs[J]).some(t1=>!Number.isFinite(t1))),Y=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),e1=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),X=D=>{let J=t1=>w(D.attrs[t1],/^(x|cx|rx|x1|x2|width)$/.test(t1)?"x":/^(y|cy|ry|y1|y2|height)$/.test(t1)?"y":"r");switch(D.name){case"path":return c5(D.attrs.d??"",()=>T++);case"rect":{let[t1,w1,n1,E]=[J("x"),J("y"),J("width"),J("height")];if(n1<=0||E<=0)return[];let R=D.attrs.rx!==void 0?J("rx"):D.attrs.ry!==void 0?J("ry"):0,Z=D.attrs.ry!==void 0?J("ry"):R;return R=Math.min(Math.abs(R),n1/2),Z=Math.min(Math.abs(Z),E/2),R<=0||Z<=0?c5(`M${t1} ${w1}H${t1+n1}V${w1+E}H${t1}Z`):c5(`M${t1+R} ${w1}H${t1+n1-R}A${R} ${Z} 0 0 1 ${t1+n1} ${w1+Z}V${w1+E-Z}A${R} ${Z} 0 0 1 ${t1+n1-R} ${w1+E}H${t1+R}A${R} ${Z} 0 0 1 ${t1} ${w1+E-Z}V${w1+Z}A${R} ${Z} 0 0 1 ${t1+R} ${w1}Z`)}case"circle":case"ellipse":{let[t1,w1]=[J("cx"),J("cy")],n1=D.name==="circle"?J("r"):J("rx"),E=D.name==="circle"?J("r"):D.attrs.ry!==void 0?J("ry"):n1;return n1<=0||E<=0?[]:c5(`M${t1+n1} ${w1}A${n1} ${E} 0 0 1 ${t1} ${w1+E}A${n1} ${E} 0 0 1 ${t1-n1} ${w1}A${n1} ${E} 0 0 1 ${t1} ${w1-E}A${n1} ${E} 0 0 1 ${t1+n1} ${w1}Z`)}case"line":return c5(`M${J("x1")} ${J("y1")}L${J("x2")} ${J("y2")}`);case"polyline":case"polygon":{let t1=Y5(D.attrs.points??"");if(t1.length<4)return[];let w1=`M${t1[0]} ${t1[1]}`;for(let n1=2;n1+1<t1.length;n1+=2)w1+=`L${t1[n1]} ${t1[n1+1]}`;return c5(D.name==="polygon"?w1+"Z":w1)}}},M1=D=>(D.text+D.children.map(J=>J.name==="tspan"?" "+M1(J):"").join("")).replace(/\s+/g," ").trim(),v1=(D,J,t1,w1,n1,E)=>{if(E>64||Y.has(D.name)||P&&++F>j)return;let R=A(D,t1);if(R.display==="none"||R.visibility==="hidden"||R.opacity==="0"){(D.children.length||e1.has(D.name))&&L++;return}let Z=R3(J,nl(D.attrs.transform));if(!Z.every(Number.isFinite)){q++;return}let K=il(D),k1=D.attrs["inkscape:groupmode"]==="layer",O1=w1;if(D.name==="g"||D.name==="svg"||D.name==="a"||D.name==="switch"){let m1=D.attrs["inkscape:label"]??D.attrs["data-name"]??D.attrs.id,S1=ll(m1);if(D.attrs["data-mode"]&&m1&&/^(cut|line|fill|guide)$/.test(D.attrs["data-mode"])){let i0=Z5(R.stroke,"#000000"),V1=Z5(R.fill,"#000000"),X1=D.attrs["data-mode"]==="fill"?V1:i0;O1=d2[m1]??{name:m1,mode:D.attrs["data-mode"],color:X1&&X1.startsWith("#")?X1:"#00aa00"}}else S1&&(O1=S1);if(D!==r&&D.name==="svg"){let i0=V1=>parseFloat(D.attrs[V1]??"0")||0;Z=R3(Z,[1,0,0,1,i0("x"),i0("y")])}let Z1=k1||S1||D===r||!K?n1:[K,...n1];_.push(D);for(let i0 of D.children)v1(i0,Z,R,O1,Z1,E+1);_.pop();return}if(D.name==="use"){let m1=k.get((D.attrs.href??D.attrs["xlink:href"]??"").replace(/^#/,""));if(!m1||_.includes(m1))return;let S1=V1=>parseFloat(D.attrs[V1]??"0")||0,Z1=R3(Z,[1,0,0,1,S1("x"),S1("y")]),i0=m1.name==="symbol"?{...m1,name:"g"}:m1;_.push(m1),P++,v1(i0,Z1,R,O1,K?[K,...n1]:n1,E+1),P--,_.pop();return}if(D.name==="image"){I++;return}let z0=Z5(R.color,"#000000")??"#000000",n0=parseFloat(R["stroke-width"]??"1"),j1=Z5(R.stroke,z0);j1&&(n0===0||R["stroke-opacity"]==="0")&&(j1="none");let X0=Z5(R.fill??"black",z0);if(R["fill-opacity"]==="0"&&(X0="none"),D.name==="text"){let m1=M1(D);if(!m1)return;let S1=D.children.find(O0=>O0.name==="tspan"),Z1=O0=>Y5(D.attrs[O0]??S1?.attrs[O0]??"0")[0]??0,i0=k5(Z,[Z1("x"),Z1("y")]),V1=Math.sqrt(Math.abs(Z[0]*Z[3]-Z[1]*Z[2])),X1=(Bt(R["font-size"],96)??16*h)/h;if(!Q(i0)||!Number.isFinite(X1*V1)){q++;return}let d0=R["text-anchor"];C.push({text:m1,at:i0,size:X1*V1,angle:Math.atan2(-Z[1],Z[0])*180/Math.PI,font:(R["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:d0==="middle"?"center":d0==="end"?"right":"left",stroke:j1,fill:X0,layer:O1});return}if(D.name!=="path"&&B(D)){q++;return}let g1=X(D);if(!g1){for(let m1 of D.children)v1(m1,Z,R,O1,n1,E+1);return}let L1=rl(g1,Z),z1=L1.filter(m1=>m1.segs.every(S1=>Q(S1.a)&&Q(S1.b)&&(S1.c==="L"||Q(S1.p1)&&Q(S1.p2))));z1.length<L1.length&&q++,z1.length&&S.push({subs:z1,stroke:j1,fill:D.name==="line"||D.name==="polyline"?"none":X0,fillRule:R["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:O1,names:K?[K,...n1]:n1})};v1(r,b,{},void 0,[],0),I&&c.push(`${I} embedded image${I===1?" was":"s were"} left out: trace ${I===1?"it":"them"} to paths first.`),L&&c.push(`${L} hidden element${L===1?" was":"s were"} left out.`),T&&c.push(`${T} path${T===1?" has":"s have"} bad data: read up to the error, as browsers draw ${T===1?"it":"them"}.`),q&&c.push(`${q} element${q===1?" was":"s were"} left out: ${q===1?"its":"their"} numbers are too large to draw.`),F>j&&c.push(`The drawing repeats its elements with <use> more than ${j.toLocaleString("en")} times: only the first ${j.toLocaleString("en")} copies were read.`);let p1=D=>{let[J,t1,w1]=[1,3,5].map(n1=>parseInt(D.slice(n1,n1+2),16));return J>=200&&t1<=80&&w1<=80},G1=D=>{let[J,t1,w1]=[1,3,5].map(n1=>parseInt(D.slice(n1,n1+2),16));return w1>=200&&J<=80&&t1<=80},F1=D=>!!D.stroke&&D.stroke!=="none",V=S.filter(D=>!D.layer),U=new Map;for(let D of V)F1(D)&&D.stroke.startsWith("#")&&U.set(D.stroke,(U.get(D.stroke)??0)+D.subs.length);let r1=[...U.keys()],h1=r1.filter(p1),a1=new Set(h1.length?h1:r1.length?[r1.reduce((D,J)=>(U.get(J)??0)>(U.get(D)??0)?J:D)]:[]),x1=S.some(D=>F1(D)&&!D.layer)||S.some(D=>D.layer),J1=new Map,q1=(D,J)=>{if(D&&D!=="none"){let t1=D.startsWith("#")?D:"#000000";if(a1.has(t1))return d2.cut;if(t1==="#00a0ff")return d2.guide;if(G1(t1))return d2.score;if(!J1.has(t1)){let w1=tl[t1]??"color_"+t1.slice(1);J1.set(t1,{name:w1,mode:"line",color:t1})}return J1.get(t1)}if(J&&J!=="none")return x1?d2.engrave:d2.cut};!x1&&S.some(D=>D.fill&&D.fill!=="none")?c.push("The file has filled shapes and no strokes: the shapes are cut out."):!h1.length&&a1.size&&c.push(`No red lines: ${[...a1][0]} lines, the most common colour, are cut.`),J1.size&&c.push(`Lines in ${[...J1.values()].map(D=>D.color).join(", ")} went on their own layer${J1.size===1?"":"s"}, set to mark, not cut.`);let f0=[];for(let D of S){let J=D.layer??q1(D.stroke,D.fill);if(!J)continue;let t1=!D.layer&&J===d2.cut&&!F1(D);f0.push({subs:D.subs,layer:J,fillRule:D.fillRule,names:D.names,filled:t1})}let m0=[];for(let D of C){let J=D.layer??q1(D.fill!=="none"?void 0:D.stroke,D.fill);J&&m0.push({...D,layer:J.mode==="cut"&&x1?d2.engrave:J})}return{items:f0,texts:m0,notes:c}}var N1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),M2=([t,e],n)=>{let r=n*Math.PI/180,c=Math.cos(r),a=Math.sin(r);return[t*c-e*a,t*a+e*c]},Gt=(t,e)=>[t[0]+e[0],t[1]+e[1]],w2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function A3(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 c=N1(r.a,r.p1)+N1(r.p1,r.p2)+N1(r.p2,r.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(c/e))));for(let s=1;s<=a;s++){let o=s/a,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&&N1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function V2(t,e=!0){let n=0;for(let r=1;r<t.length;r++)n+=N1(t[r-1],t[r]);return e&&t.length>2?n+N1(t[t.length-1],t[0]):n}function j2(t,e,n){let r=[],c=e?t.length:t.length-1;for(let a=0;a<c;a++){let s=t[a],o=t[(a+1)%t.length];r.push(s);let i=Math.floor(N1(s,o)/n);for(let l=1;l<i;l++)r.push([s[0]+(o[0]-s[0])*l/i,s[1]+(o[1]-s[1])*l/i])}return!e&&t.length&&r.push(t[t.length-1]),r}function o3(t,e,n){let r=n[0]-e[0],c=n[1]-e[1],a=r*r+c*c,s=a?((t[0]-e[0])*r+(t[1]-e[1])*c)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*r,t[1]-e[1]-s*c)}var S3=class{constructor(e,n,r){this.size=r;this.cells=new Map;for(let c of e){let a=n?c.length:c.length-1;for(let s=0;s<a;s++){let o=c[s],i=c[(s+1)%c.length],l=Math.max(1,Math.ceil(N1(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),p=Math.floor(Math.max(u[0],f[0])/r),m=Math.floor(Math.min(u[1],f[1])/r),g=Math.floor(Math.max(u[1],f[1])/r);for(let v=d;v<=p;v++)for(let b=m;b<=g;b++){let y=`${v},${b}`,x=this.cells.get(y);x?x.push([u,f]):this.cells.set(y,[[u,f]])}}}}}near(e,n){let r=Math.floor((e[0]-n)/this.size),c=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let o=r;o<=c;o++)for(let i=a;i<=s;i++)for(let[l,h]of this.cells.get(`${o},${i}`)??[])if(o3(e,l,h)<=n)return!0;return!1}meets(e,n,r){let c=Math.max(1,Math.ceil(N1(e,n)/(this.size*2)));for(let a=0;a<c;a++){let s=[e[0]+(n[0]-e[0])*a/c,e[1]+(n[1]-e[1])*a/c],o=[e[0]+(n[0]-e[0])*(a+1)/c,e[1]+(n[1]-e[1])*(a+1)/c],i=Math.floor((Math.min(s[0],o[0])-r)/this.size),l=Math.floor((Math.max(s[0],o[0])+r)/this.size),h=Math.floor((Math.min(s[1],o[1])-r)/this.size),u=Math.floor((Math.max(s[1],o[1])+r)/this.size);for(let f=i;f<=l;f++)for(let d=h;d<=u;d++)for(let[p,m]of this.cells.get(`${f},${d}`)??[])if(I8(s,o,p,m)<=r)return!0}return!1}};function I8(t,e,n,r){let c=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),a=c(n,r,t),s=c(n,r,e),o=c(t,e,n),i=c(t,e,r);return a*s<0&&o*i<0?0:Math.min(o3(t,n,r),o3(e,n,r),o3(n,t,e),o3(r,t,e))}function hl(t,e,n=.2){let r=t.length;if(r<4)return!1;let c=[0];for(let h=1;h<=r;h++)c.push(c[h-1]+N1(t[h-1],t[h%r]));let a=c[r],s=w0([t]),o=Math.max(s[2]-s[0],s[3]-s[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),p=Math.floor((Math.max(h[0],u[0])+e)/o),m=Math.floor((Math.min(h[1],u[1])-e)/o),g=Math.floor((Math.max(h[1],u[1])+e)/o);if((p-d+1)*(g-m+1)>4096)return null;for(let v=d;v<=p;v++)for(let b=m;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 p of d)for(let m of i.get(p)??[]){let g=Math.abs(c[h]-c[m]);if(!(Math.min(g,a-g)-N1(u,f)-N1(t[m],t[(m+1)%r])<n)&&I8(u,f,t[m],t[(m+1)%r])<=e)return!0}for(let p of d){let m=i.get(p);m?m.push(h):i.set(p,[h])}}return!1}function V8(t,e){let n=t.map(()=>!1),r=[],c=t.map(l=>w0([l]));t.forEach((l,h)=>{let u=s1([l]),f=u.reduce((m,g)=>m+b1(g),0),d=V2(l),p=u.reduce((m,g)=>m+V2(g),0);(u.length!==1||Math.abs(f-Math.abs(b1(l)))>d*.001+1e-6||Math.abs(p-d)>d*.001+.05||hl(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new S3([t[l]],!0,Math.max(e*4,1))),h},o=t.map((l,h)=>h).sort((l,h)=>c[l][0]-c[h][0]),i=[];for(let l of o){let[h,u,f,d]=c[l];for(let p=i.length-1;p>=0;p--)c[i[p]][2]<h-e&&i.splice(p,1);for(let p of i){let m=c[p];if(m[1]>d+e||m[3]<u-e)continue;let[g,v]=t[l].length<=t[p].length?[l,p]:[p,l],b=t[g],y=s(v);for(let x=0;x<b.length;x++)if(y.meets(b[x],b[(x+1)%b.length],e)){r.push([l,p]);break}}i.push(l)}return{self:n,pairs:r}}function L3(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let c=Math.max(n*2,.2),a=new S3(t,r,Math.max(n*4,1)),s=new S3(e,r,Math.max(n*4,1));for(let o of t)for(let i of j2(o,r,c))if(!s.near(i,n))return!1;for(let o of e)for(let i of j2(o,r,c))if(!a.near(i,n))return!1;return!0}function H8(t,e,n){let r=new S3([t,...e],!0,Math.max(n*4,1)),c=a=>_2(a,t)&&!e.some(s=>_2(a,s));return(a,s)=>{let o=s?a.length:a.length-1;if(o<1)return!1;let i;for(let l=0;l<o;l++){let h=a[l],u=a[(l+1)%a.length];if(!r.meets(h,u,n)){i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==o-1)return!1;let f=N1(h,u),d=Math.min(n*3,f/3)/f,p=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,m=l===o-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(r.meets(p,m,n))return!1;i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return i?c(i):!0}}function O8(t,e,n){if(!t.length)return!1;let r=new S3([e],!0,Math.max(n*4,1));return t.some(c=>j2(c,!1,Math.max(n*2,.2)).some(a=>r.near(a,n)))}function _2(t,e){let n=!1;for(let r=0,c=e.length-1;r<e.length;c=r++){let[a,s]=e[r],[o,i]=e[c];s>t[1]!=i>t[1]&&t[0]<(o-a)*(t[1]-s)/(i-s)+a&&(n=!n)}return n}function e4(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 c=0,a=0,s=0,o=0,i=0,l=0,h=0;for(let[g,v]of t){let b=g-n,y=v-r;c+=b*b,a+=b*y,s+=y*y,o+=b*b*b,i+=y*y*y,l+=b*y*y,h+=y*b*b}let u=c*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(o+l)/2,d=(i+h)/2,p=(f*s-d*a)/u,m=(d*c-f*a)/u;return{c:[p+n,m+r],r:Math.sqrt(p*p+m*m+(c+s)/e)}}function a5(t,e=.01){if(t.length<4)return t;let n=0;for(let i=1;i<t.length;i++)N1(t[0],t[i])>N1(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=o3(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))]},c=r(t.slice(0,n+1)),a=r([...t.slice(n),t[0]]),s=[...c.slice(0,-1),...a.slice(0,-1)],o=[];for(let i=0;i<s.length;i++){let l=s[(i-1+s.length)%s.length],h=s[(i+1)%s.length];o3(s[i],l,h)>e&&o.push(s[i])}return o.length>=3?o:s}function $8(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=a5(a,.002),o=s.length,i=s.findIndex((u,f)=>N1(u,s[(f+1)%o])>=.5);if(o<4||i<0)continue;let l=b1(a)>0,h=[];for(let u=1;u<=o;u++){let f=(i+u)%o,d=s[f],p=s[(f+1)%o];if(N1(d,p)<.3){h.length||h.push(d),h.push(p);continue}if(h.length>=3){let m=e4(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]);m&&m.r>.005&&m.r<.6&&(y>0===l?e:n).push(m.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let r=e[Math.floor(e.length/2)],c=a=>Math.abs(a-r)<=Math.max(.005,r*.1);if(!(r>.2||n.filter(c).length>e.length*.2))return e.filter(c).length>=e.length*.8?r:void 0}function Wt(t,e){let n=t.length,r=o=>N1(t[o],t[(o+1)%n])<e*1.5,c=t.findIndex((o,i)=>!r(i));if(c<0)return t;let a=[],s=c;do{let o=(s+1)%n;for(;r(o)&&o!==s;)o=(o+1)%n;let i=(o-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[o],f=t[(o+1)%n],d;if(i>0){let p=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(p)>1e-12){let m=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/p,g=[l[0]+m*(h[0]-l[0]),l[1]+m*(h[1]-l[1])],v=t[(s+1+Math.floor(i/2))%n],b=[];for(let w=1;w<=i+1;w++)b.push(t[(s+w)%n]);let y=b.length>=3?e4(b):{c:g,r:e};!!y&&Math.abs(y.r-e)<=e*.3&&N1(g,v)<=e*2&&m>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let p=1;p<=i;p++)a.push(t[(s+p)%n]);s=o}while(s!==c);return a}function $1(t){for(let r of[0,1,2]){let c=10**r,a=Math.round(t*c)/c;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var I1=t=>String($1(t)),s0=t=>`[${I1(t[0])}, ${I1(t[1])}]`;function ul(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 H2(t,e,n){let r=[];($1(t[0])!==0||$1(t[1])!==0)&&r.push(`translate(${s0(t)})`);let c=ul(e);return c!==0&&r.push(`rotate(${c})`),[...r,n].join(" ")}function J5(t,e){return{poly:t,area:Math.abs(b1(t)),box:w0([t]),ends:e?.segs.map(n=>n.a)}}var Qe=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function t4(t,e){let n=V2(t.poly),r=j2(t.poly,!0,Math.min(.5,n/256)),c=e4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:r);if(!c||c.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,c.r*3e-4));for(let o of t.poly)if(Math.abs(N1(o,c.c)-c.r)>a)return;let s=a+c.r*2e-4;for(let o of r)if(Math.abs(N1(o,c.c)-c.r)>s)return;if(!(Math.abs(t.area-Math.PI*c.r*c.r)>n*a*2))return{kind:"circle",body:`circle(d = ${I1(c.r*2)})`,at:c.c,angle:0,center:c.c,circle:c,radius:c.r}}function R8(t){let e=0,n=0;for(let[s,o]of t)e+=s,n+=o;e/=t.length,n/=t.length;let r=0,c=0,a=0;for(let[s,o]of t)r+=(s-e)**2,c+=(o-n)**2,a+=(s-e)*(o-n);return .5*Math.atan2(2*a,r-c)*180/Math.PI}function n4(t,e){let n=V2(t.poly),r=j2(t.poly,!0,Math.min(.5,n/256)),c=R8(r),a=r.map(m=>M2(m,-c)),[s,o,i,l]=w0([a]),h=(i-s)/2,u=(l-o)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+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[m,g]of a){let v=Math.hypot((m-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 p=M2(f,c);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${s0([h,u])})`,at:p,angle:c,center:p}}function F8(t){let e=0,n=0;for(let r=0;r<t.length;r++){let c=t[r],a=t[(r+1)%t.length],s=N1(c,a);s>e&&(e=s,n=Math.atan2(a[1]-c[1],a[0]-c[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function r4(t,e){let n=a5(t.poly,e/4),r=F8(n),c=V2(t.poly),a=j2(t.poly,!0,Math.min(.5,c/256)).map(b=>M2(b,-r)),[s,o,i,l]=w0([a]),h=i-s,u=l-o;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,o],[i,o],[i,l],[s,l]].map(b=>Math.min(...a.map(y=>N1(y,b)))*f),p=d.reduce((b,y)=>b+y,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;p<e&&(p=0),p=Math.min(p,h/2,u/2);let m=[(s+i)/2,(o+l)/2];for(let[b,y]of a){let x=Math.abs(b-m[0])-(h/2-p),w=Math.abs(y-m[1])-(u/2-p),M=Math.hypot(Math.max(x,0),Math.max(w,0))+Math.min(Math.max(x,w),0)-p;if(Math.abs(M)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*p*p))>c*e)return;let g=M2(m,r),v=$1(p)>0?`, r = ${I1(p)}`:"";return{kind:"rect",radius:p,body:`rect(${s0([h,u])}, center = true${v})`,at:g,angle:r,center:g,rect:{w:h,h:u,r:p}}}function c4(t,e){let n=a5(t.poly,e/4),r=n.length;if(r<3||r>48)return;let c=0,a=0;for(let[u,f]of n)c+=u/r,a+=f/r;let s=[c,a],o=n.map(u=>N1(u,s)),i=n.map((u,f)=>N1(u,n[(f+1)%r])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-c)*180/Math.PI);if(l(i)<=e&&l(o)<=e&&r<=24){let u=o.reduce((p,m)=>p+m,0)/r,f=360/r,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${r}, ${I1(u)})`,at:s,angle:d,center:s}}if(r%2===0&&r>=4&&l(i)<=e){let u=o.filter((x,w)=>w%2===0),f=o.filter((x,w)=>w%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,w)=>x+w,0)/u.length,p=f.reduce((x,w)=>x+w,0)/f.length,m=h[0];if(p>d&&([d,p]=[p,d],m=h[1]),d-p<e)return;let g=r/2,v=360/g,b=((m-90)%v+v)%v;v-b<.01&&(b=0);let y=$1(p)===$1(d*.45);return{kind:"star",body:`star(${g}, ${I1(d)}${y?"":`, ${I1(p)}`})`,at:s,angle:b,center:s}}}function fl(t,e,n){let[r,c,a,s]=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 p=f[1];Math.abs(p-c)<=n?o[0].push(Je(f[0]-r,d[0]-r)):Math.abs(p-s)<=n?o[2].push(Je(a-f[0],a-d[0])):(i[0].push(p-c),i[2].push(s-p))}else{let p=f[0];Math.abs(p-a)<=n?o[1].push(Je(f[1]-c,d[1]-c)):Math.abs(p-r)<=n?o[3].push(Je(s-f[1],s-d[1])):(i[1].push(a-p),i[3].push(p-r))}}let l=[a-r,s-c,a-r,s-c],h=i.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:o.map(u=>dl(u,n)),depth:h,length:l}}var Je=(t,e)=>t<e?[t,e]:[e,t];function dl(t,e){t.sort((r,c)=>r[0]-c[0]);let n=[];for(let[r,c]of t){let a=n[n.length-1];a&&r<=a[1]+e?a[1]=Math.max(a[1],c):n.push([r,c])}return n}var jt=t=>t.reduce((e,[n,r])=>e+r-n,0);function ml(t,e,n,r,c,a){let s=[Qe(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];s.push(Qe(d-c[h]/2,-a,d+c[h]/2,0).map(o[h]))}}),s1(s)}function Xt(t,e,n){let r=a5(t.poly,e/4);if(r.length<8)return;let c=F8(r),a=r.map(H=>M2(H,-c)),s=e/2;for(let H=0;H<a.length;H++){let B=a[H],Y=a[(H+1)%a.length];if(Math.abs(B[0]-Y[0])>s&&Math.abs(B[1]-Y[1])>s)return}let o=w0([a]),i=fl(a,o,s),l=(H,B)=>H.map(Y=>Y.map(e1=>Gt(e1,B))),h=(H,B)=>L3([a],l(H,B),e),u=(H,B,Y)=>{let e1=M2(H,c);return{kind:"tabs",body:B,at:e1,angle:c,center:M2([(o[0]+o[2])/2,(o[1]+o[3])/2],c),...Y}},f=V2(t.poly),d=[0,1,2,3].filter(H=>jt(i.outer[H])<i.length[H]-s);if(!d.length)return;let p=d.map(H=>i.depth[H]).filter(H=>H!==void 0);if(!p.length)return;let m=[...new Set([n,...p].filter(H=>!!H).map($1))];for(let H of m){let B=$1(o[2]-o[0]),Y=$1(o[3]-o[1]),e1=[[]];for(let R=0;R<4;R++){let K=jt(i.outer[R])>=i.length[R]-2*H-s?["flat"]:["out","in"],k1=[];for(let O1 of e1)for(let z0 of K)k1.push([...O1,z0]);e1.splice(0,e1.length,...k1)}let X=Math.max(3*H,6),M1=new Set([X]);for(let R of d){let Z=i.outer[R].length;for(let K of[2*Z-1,2*Z+1,2*Z-3,2*Z+3])K>=3&&M1.add($1(i.length[R]/K))}for(let R of M1)for(let Z of e1){if(Z.every(n0=>n0==="flat"))continue;let K=Ce(B,Y,Z,H,R);if(Math.abs(Math.abs(K.reduce((n0,j1)=>n0+b1(j1),0))-t.area)>f*e||!h(K,[o[0],o[1]]))continue;let O1=Z.every(n0=>n0===Z[0])?`"${Z[0]}"`:`[${Z.map(n0=>`"${n0}"`).join(", ")}]`,z0=R===X||[0,1].every(n0=>v3(i.length[n0],R)===v3(i.length[n0],X));return u([o[0],o[1]],`finger_rect(${s0([B,Y])}, ${O1}${z0?"":`, finger = ${I1(R)}`})`,{kind:"fingers",thickness:H,edges:Z,finger:z0?X:R})}let v1=[0,1,2,3].map(R=>d.includes(R)&&i.depth[R]!==void 0&&Math.abs(i.depth[R]-H)<=s);if(!v1.some(Boolean))continue;let p1=o[0]+(v1[3]?H:0),G1=o[1]+(v1[0]?H:0),F1=$1(o[2]-(v1[1]?H:0)-p1),V=$1(o[3]-(v1[2]?H:0)-G1),U=[F1,V,F1,V],r1=[v1[3]?H:0,v1[0]?H:0,v1[1]?H:0,v1[2]?H:0],h1=[0,0,0,0],a1=[0,0,0,0],x1=!0;for(let R=0;R<4&&x1;R++){if(!v1[R])continue;let Z=i.outer[R].map(([K,k1])=>[K-r1[R],k1-r1[R]]);h1[R]=Z.length,a1[R]=Z.length?$1(Z.reduce((K,[k1,O1])=>K+O1-k1,0)/Z.length):0,Z.forEach(([K,k1],O1)=>{(Math.abs((K+k1)/2-U[R]*(O1+.5)/h1[R])>s||Math.abs(k1-K-a1[R])>s)&&(x1=!1)})}if(!x1||!h(ml(F1,V,v1,h1,a1,H),[p1,G1]))continue;let J1=v1.every(Boolean)?"":`[${v1.join(", ")}]`,q1=[0,1,2,3].filter(R=>v1[R]),f0=R=>Math.max(1,Math.round(U[R]/50)),m0=q1.every(R=>h1[R]===f0(R)),D=q1.every(R=>h1[R]===h1[q1[0]]),J=m0?void 0:D?h1[q1[0]]:null,t1=q1.every(R=>Math.abs(a1[R]-U[R]/(2*h1[R]))<=s),w1=q1.every(R=>Math.abs(a1[R]-a1[q1[0]])<=s),n1=t1?void 0:w1?a1[q1[0]]:null,E;if(J!==null&&n1!==null){let R=[s0([F1,V])];J1?R.push(J1):(J!==void 0||n1!==void 0)&&R.push("true"),J!==void 0&&R.push(`count = ${J}`),n1!==void 0&&R.push(`width = ${I1(n1)}`),E=`tab_rect(${R.join(", ")})`}else{let R=[K=>K,K=>`translate(${s0([F1,0])}) rotate(90) ${K}`,K=>`translate(${s0([F1,V])}) rotate(180) ${K}`,K=>`translate(${s0([0,V])}) rotate(270) ${K}`],Z=[`rect(${s0([F1,V])});`];for(let K of q1){let k1=[I1(U[K])];h1[K]!==f0(K)&&k1.push(`count = ${h1[K]}`),Math.abs(a1[K]-U[K]/(2*h1[K]))>s&&k1.push(`width = ${I1(a1[K])}`),Z.push(R[K](`tabs(${k1.join(", ")});`))}E=`{
|
|
3071
|
+
${Z.map(K=>" "+K).join(`
|
|
2612
3072
|
`)}
|
|
2613
|
-
}`}return u([
|
|
2614
|
-
${[`rect(${
|
|
3073
|
+
}`}return u([p1,G1],E,{kind:"tabs",thickness:H,library:"tabs",label:`tabs ${I1(H)} mm deep`})}let g=i.depth;if(d.some(H=>g[H]===void 0))return;let v=[0,1,2,3].map(H=>d.includes(H)&&jt(i.outer[H])<i.length[H]*.4),b=o[0]+(v[3]?g[3]:0),y=o[1]+(v[0]?g[0]:0),x=o[2]-(v[1]?g[1]:0)-b,w=o[3]-(v[2]?g[2]:0)-y,M=(H,B,Y,e1,X)=>H===0?[o[0]+B-b,e1,Y-B,X-e1]:H===1?[x-X,o[1]+B-y,X-e1,Y-B]:H===2?[o[2]-Y-b,w-X,Y-B,X-e1]:[e1,o[3]-Y-y,X-e1,Y-B],k=[[],[],[],[]],z=[[],[],[],[]],A=[],S=[[b-o[0],b-o[0]+x],[y-o[1],y-o[1]+w],[o[2]-(b+x),o[2]-b],[o[3]-(y+w),o[3]-y]];for(let H of d)if(v[H])for(let[B,Y]of i.outer[H])k[H].push(M(H,B,Y,-g[H],0));else{let B=S[H][0];for(let[Y,e1]of[...i.outer[H],[S[H][1],S[H][1]]]){let[X,M1]=[Math.max(B,S[H][0]),Math.min(Y,S[H][1])];M1-X>s&&((X-S[H][0]<=s||S[H][1]-M1<=s)&&A.push([H,z[H].length]),z[H].push(M(H,X,M1,-1,g[H]))),B=Math.max(B,e1)}}let C=([H,B,Y,e1])=>Qe(H,B,H+Y,B+e1),I=s1([Qe(0,0,x,w),...k.flat().map(C)]),L=()=>h(g0(I,z.flat().map(C)),[b,y]);if(!L())return;for(let[H,B]of A.reverse()){let[Y]=z[H].splice(B,1);L()||z[H].splice(B,0,Y)}let T=(H,B)=>{let Y=B%2===0,e1=V=>Y?V[0]:V[1];H.sort((V,U)=>e1(V)-e1(U));let X=H.every(V=>Math.abs(V[2]-H[0][2])<=s&&Math.abs(V[3]-H[0][3])<=s),M1=H.length>1?e1(H[1])-e1(H[0]):0,v1=H.every((V,U)=>Math.abs(e1(V)-e1(H[0])-U*M1)<=s),p1=$1(M1),G1=$1(e1(H[0])),F1=$1(G1+p1*(H.length-1));if(H.length>=3&&X&&v1&&p1>0&&Math.floor((F1-G1)/p1+1e-9)+1===H.length){let[,,V,U]=H[0],r1=Y?`[x, ${I1(H[0][1])}]`:`[${I1(H[0][0])}, y]`;return[`for (${Y?"x":"y"} = [${I1(G1)}:${I1(p1)}:${I1(F1)}]) translate(${r1}) rect(${s0([V,U])});`]}return H.map(([V,U,r1,h1])=>`translate(${s0([V,U])}) rect(${s0([r1,h1])});`)},q=[0,1,2,3].flatMap(H=>k[H].length?T(k[H],H):[]),P=[0,1,2,3].flatMap(H=>z[H].length?T(z[H],H):[]),F=q.length?`union() {
|
|
3074
|
+
${[`rect(${s0([x,w])});`,...q].join(`
|
|
2615
3075
|
`)}
|
|
2616
|
-
}`:`rect(${
|
|
2617
|
-
${[
|
|
3076
|
+
}`:`rect(${s0([x,w])})`,j=P.length?`difference() {
|
|
3077
|
+
${[F.endsWith("}")?F:F+";",...P].join(`
|
|
2618
3078
|
`)}
|
|
2619
|
-
}`:J,Z=d.map(E=>T1(g[E])),p1=Z.sort((E,$)=>Z.filter(X=>X===$).length-Z.filter(X=>X===E).length)[0];return u([y,b],o1,{kind:V.length?"fingers":"tabs",thickness:p1,generic:!0,label:`${V.length?"finger joints":"tabs"} ${S1(p1)} mm deep`})}function Di(t){let[e,n,c,r]=S0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,Z2(h,t[d],t[f]));return u},s=[(e+c)/2,(n+r)/2],i=H2(s,t)?a(s):0,o=24;for(let h=0;h<=o;h++)for(let u=0;u<=o;u++){let f=[e+(c-e)*h/o,n+(r-n)*u/o];if(!H2(f,t))continue;let d=a(f);d>i&&(s=f,i=d)}let l=Math.max(c-e,r-n)/o;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!H2(d,t))continue;let p=a(d);p>i&&(s=d,i=p,h=!0)}h||(l/=2)}return{c:s,r:i}}function qi(t,e,n){let r=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let i=r+Math.PI/2+Math.PI*s/64;a.push([t[0]+n*Math.cos(i),t[1]+n*Math.sin(i)])}for(let s=0;s<=64;s++){let i=r-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(i),e[1]+n*Math.sin(i)])}return a}function P8(t,e){let[n,c,r,a]=t.box;if(Math.max(r-n,a-c)>80)return;let s=w2(t.poly),i=O2(t.poly,!0,Math.min(.25,s/400)),o=Di(t.poly),l=i.filter(V=>Math.abs(F1(V,o.c)-o.r)<=e),h=P4(l);if(!h||l.length<8)return;let u=i[0];for(let V of i)F1(V,h.c)>F1(u,h.c)&&(u=V);let f=F1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],p=V=>(V[0]-h.c[0])*d[0]+(V[1]-h.c[1])*d[1],m=V=>-(V[0]-h.c[0])*d[1]+(V[1]-h.c[1])*d[0],g=i.filter(V=>p(V)>h.r+e&&p(V)<f-h.r);if(g.length<4)return;let v=[g.filter(V=>m(V)>0),g.filter(V=>m(V)<0)];if(v.some(V=>V.length<2))return;let y=v.map(V=>u2([1,0],A8(V))).map(V=>V[0]*d[0]+V[1]*d[1]<0?[-V[0],-V[1]]:V),b=[y[0][0]+y[1][0],y[0][1]+y[1][1]],x=Math.hypot(b[0],b[1]);if(d=[b[0]/x,b[1]/x],g=i.filter(V=>p(V)>h.r+e&&p(V)<f-h.r),g.length<4||Math.abs(g.reduce((V,J)=>V+m(J),0)/g.length)>e)return;let M=g.map(V=>Math.abs(m(V))).sort((V,J)=>V-J),w=M[Math.floor(M.length/2)]*2;if(w>=h.r*2-e||w<.3)return;let k=Math.max(...i.map(p)),z=u6(h.c,[d[0]*(k-w/2),d[1]*(k-w/2)]),S=x1([k3(h.r,h.r,256).map(V=>u6(V,h.c)),qi(h.c,z,w/2)]);if(!f3([t.poly],S,e))return;let L=k-w/2,I=h.r*2,q=Math.atan2(d[1],d[0])*180/Math.PI-90,R=[];T1(I)!==9&&R.push(`head = ${S1(I)}`),T1(w)!==4.5&&R.push(`shank = ${S1(w)}`),T1(L)!==10&&R.push(`drop = ${S1(L)}`);let N=L>=(I+w)/2-1e-9,G=N?`keyhole(${R.join(", ")})`:`{ translate(${n0([0,-L])}) circle(d = ${S1(I)}); hull() { circle(d = ${S1(w)}); translate(${n0([0,-L])}) circle(d = ${S1(w)}); } }`;return{kind:"keyhole",radius:I/2,body:G,at:z,angle:q,center:z,label:"keyhole",keyhole:{head:I,shank:w,drop:L,top:z},library:N?"hanging":void 0}}var M8=.0025,A4=(t,e)=>Math.abs(t[0]-e[0])>M8||Math.abs(t[1]-e[1])>M8;function G3(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(a=>a.a);t.closed||n.push(t.segs[t.segs.length-1].b);let c=[n[0]];for(let a of n.slice(1))A4(a,c[c.length-1])&&c.push(a);!t.closed&&c.length<2&&c.push(n[n.length-1]);let r=`[${c.map(a=>n0(f2(a,e))).join(", ")}]`;return t.closed?`polygon(${r})`:c.length===2?`line(${n0(f2(c[0],e))}, ${n0(f2(c[1],e))})`:`polyline(${r})`}return`path("${p6([t],e)}")`}function p6(t,e){let n=c=>`${S1(c[0]-e[0])} ${S1(c[1]-e[1])}`;return t.map(c=>{let r=`M${n(c.segs[0].a)}`,a=c.segs[0].a;for(let s of c.segs)!A4(s.b,a)&&(s.c==="L"||!A4(s.p1,a)&&!A4(s.p2,a))||(r+=s.c==="L"?`L${n(s.b)}`:`C${n(s.p1)} ${n(s.p2)} ${n(s.b)}`,a=s.b);return c.closed?r+"Z":r}).join("")}var V0=.01;function T8(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 j3=t=>t.segs[0].a,E8=t=>t.segs[t.segs.length-1].b;function Ni(t){let e=new Set,n=[],c=s=>`${Math.round(s[0]/V0)},${Math.round(s[1]/V0)}`,r=new Map;t.forEach((s,i)=>{for(let o of[j3(s),E8(s)]){let l=c(o);r.set(l,[...r.get(l)??[],i])}});let a=s=>{let[i,o]=[Math.round(s[0]/V0),Math.round(s[1]/V0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of r.get(`${i+l},${o+h}`)??[])if(!e.has(u)&&(F1(j3(t[u]),s)<=V0||F1(E8(t[u]),s)<=V0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let i=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=i[i.length-1].b;if(F1(h,i[0].a)<=V0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=F1(j3(t[u]),h)<=V0?t[u]:T8(t[u]);i=i.concat(f.segs)}i=T8({segs:i,closed:!1}).segs}let o=i.length>1&&F1(i[i.length-1].b,i[0].a)<=V0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var V8=.05;function Ui(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 Bi(t,e={}){let n=e.tolerance??V8,c=typeof t=="string"?t:Ui(t),r=x8(c,{dpi:e.dpi}),a=[...r.notes],s={},i=(A,F=1)=>s[A]=(s[A]??0)+F,o=[],l=[],h=new Map;for(let A of r.items)if(A.layer.mode==="cut")for(let F of A.subs)F.closed?o.push({sub:F,names:A.names,group:A.filled?A:void 0}):(l.push(F),h.set(F,A.names));let u=Ni(l);l=[];for(let{sub:A,from:F}of u)A.closed?o.push({sub:A,names:h.get(F)??[],line:{segs:A.segs,closed:!1}}):l.push(A);let f=o.map(A=>({...A,outline:I5(u3(A.sub),A.sub)})),d=f.filter(A=>A.outline.poly.length>=3&&A.outline.area>w2(A.outline.poly)*V0);for(let A of f)d.includes(A)||l.push(A.line??{segs:A.sub.segs,closed:!1});let p=(A,F,t1,r1)=>{if(t1!==r1)return!1;let[y1,P,Y,W]=A.box,[b1,a1,$1,e1]=F.box;if(y1<b1-V0||P<a1-V0||Y>$1+V0||W>e1+V0)return!1;let I1=A.poly.length;return[0,Math.floor(I1/3),Math.floor(2*I1/3)].filter(C=>H2(A.poly[C],F.poly)).length>=2},m=A=>{let F=d.map((y1,P)=>P).filter(y1=>!A.has(y1)).sort((y1,P)=>d[P].outline.area-d[y1].outline.area),t1=new Map,r1=new Map;return F.forEach((y1,P)=>{let Y=-1;for(let W=P-1;W>=0;W--){let b1=F[W];if(d[b1].outline.area>d[y1].outline.area&&p(d[y1].outline,d[b1].outline,d[y1].group,d[b1].group)){Y=b1;break}}t1.set(y1,Y),r1.set(y1,Y<0?0:r1.get(Y)+1)}),{order:F,parent:t1,depth:r1}},g=z8(d.map(A=>A.outline.poly),V0*2),v=m(new Set),{parent:y,depth:b}=v,x=A=>b.get(A)%2===0?A:y.get(A),M=new Set(d.map((A,F)=>F).filter(A=>g.self[A]));for(let[A,F]of g.pairs)x(A)===x(F)&&M.add(A).add(F);for(let A of v.order)b.get(A)%2===1&&M.has(y.get(A))&&M.add(A);for(let A of M)l.push(d[A].line??{segs:d[A].sub.segs,closed:!1});M.size&&a.push(`${M.size} outline${M.size===1?" touches or crosses":"s touch or cross"} a hole or ${M.size===1?"itself":"themselves"}, so ${M.size===1?"it is":"they are"} kept as cut lines.`);let w=[],k=new Map;for(let A of v.order){if(M.has(A))continue;let F=d[A];if(b.get(A)%2===0){let t1={sub:F.sub,outline:F.outline,names:F.names,holes:[],lines:[],marks:new Map,texts:[]};w.push(t1),k.set(A,t1)}else k.get(y.get(A)).holes.push({sub:F.sub,outline:F.outline,line:F.line})}let z=e.kerf!==void 0?e.kerf/2:L8(w.map(A=>A.outline.poly)),S=0;if(z&&z>0){let A=F=>({closed:!0,segs:F.map((t1,r1)=>({c:"L",a:t1,b:F[(r1+1)%F.length]}))});for(let F of w){let t1=b0([f6(F.outline.poly,z)],F.holes.map(e1=>f6(e1.outline.poly,z))),r1=_0(m0(t1,-z,"miter")),y1=m0(r1.flat(),z,"round",Math.min(.01,z/10)),P=b0([F.outline.poly],F.holes.map(e1=>e1.outline.poly)),Y=e1=>Math.abs(H1(e1))<=w2(e1)*V0;if(r1.length!==1||r1[0].length!==F.holes.length+1||r1[0].some(Y)||!f3(y1,P,n)){F.noKerf=!0;continue}F.drawn=[F.sub,...F.holes.map(e1=>e1.sub)];let[W,...b1]=r1[0].map(e1=>_3(e1,.001));F.outline=I5(W),F.sub=A(W);let a1=e1=>[(e1.box[0]+e1.box[2])/2,(e1.box[1]+e1.box[3])/2],$1=b1.map(e1=>I5(e1));for(let e1 of F.holes){let I1=a1(e1.outline),r0=$1.reduce((C,_)=>F1(a1(_),I1)<F1(a1(C),I1)?_:C);$1.splice($1.indexOf(r0),1),e1.outline=r0,e1.sub=A(r0.poly),e1.line=void 0}}S=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${S1(S)} mm kerf: they are moved back, and $kerf is set.`)}let L=A=>{let F;for(let t1 of w){let[r1,y1,P,Y]=t1.outline.box;A[0]<r1||A[0]>P||A[1]<y1||A[1]>Y||H2(A,t1.outline.poly)&&(!F||t1.outline.area<F.outline.area)&&(F=t1)}return F},I={lines:[],marks:new Map,texts:[]},q=new Map,R=A=>{let F=L(j3(A));if(!F)return;let t1=q.get(F);return t1||(t1=k8(F.outline.poly,F.holes.map(r1=>r1.outline.poly),n),q.set(F,t1)),t1(u3(A,.02),A.closed)?F:void 0};for(let A of l){let F=R(A);(F?F.lines:I.lines).push(A)}for(let A of r.items)if(A.layer.mode!=="cut")for(let F of A.subs){let t1=(R(F)??I).marks;t1.set(A,[...t1.get(A)??[],F])}for(let A of r.texts)(L(A.at)??I).texts.push(A);r.texts.some(A=>A.layer.mode==="cut")&&a.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 A of w){let F=A.lines.map(t1=>u3(t1));A.holes=A.holes.filter(t1=>{if(!t1.line)return!0;let r1=P=>H2(P,t1.outline.poly),y1=S8(F,t1.outline.poly,V0*2)||A.lines.some(P=>r1(j3(P)))||[...A.marks.values()].some(P=>P.some(Y=>r1(j3(Y))))||A.texts.some(P=>r1(P.at))||w.some(P=>P!==A&&P.outline.area<t1.outline.area&&r1(P.outline.poly[0]));return y1&&A.lines.push(t1.line),!y1})}let N=A=>T4(A,n)??I4(A,n)??E4(A,n)??V4(A,n)??P8(A,n),G=new Map;for(let A of w){let F=T4(A.outline,n)??I4(A.outline,n)??E4(A.outline,n)??V4(A.outline,n)??d6(A.outline,n);G.set(A,F);for(let t1 of A.holes)t1.found=N(t1.outline)}let V=new Map,J=[...G.values()].some(A=>A?.thickness&&!A.generic);for(let A of G.values())A?.thickness&&A.thickness<=10&&(!J||!A.generic)&&V.set(A.thickness,(V.get(A.thickness)??0)+1);let o1=[...V.entries()].sort((A,F)=>F[1]-A[1])[0]?.[0];if(o1!==void 0)for(let A of w){let F=G.get(A);if(F?.thickness!==void 0&&F.thickness!==o1){let t1=d6(A.outline,n,o1);t1&&t1.thickness===o1&&G.set(A,t1)}}let Z=new Set;for(let A of G.values())A?.kind==="fingers"&&A.finger&&Z.add(T1(A.finger));w.sort((A,F)=>{let t1=F.outline.box[3]-A.outline.box[3];return Math.abs(t1)>1?t1:A.outline.box[0]-F.outline.box[0]});let p1=new Set,E=new Map,$=[];for(let[A,F]of w.entries()){let t1=F.names[0]??`part ${A+1}`,r1=(E.get(t1)??0)+1;E.set(t1,r1);let y1=r1>1?`${t1} ${r1}`:t1,P;for(let r0 of[2,1,0]){let C=Gi(F,G.get(F),r0,o1,Z,n);if(Xi(C,F,n)){P=C,r0<2&&a.push(r0===1?`Part "${y1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${y1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!P){let r0=F.drawn??[F.sub,...F.holes.map(C=>C.sub)];I.lines.push(...r0.map(C=>({segs:C.segs,closed:!1})),...F.lines);for(let[C,_]of F.marks)I.marks.set(C,[...I.marks.get(C)??[],..._]);I.texts.push(...F.texts),a.push(`Part "${y1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let r0 of P.found)i(r0);for(let r0 of P.libraries)p1.add(r0);let Y=I8(F.marks,[],F.texts,P.origin),W=[...P.cut,...Y],b1=P.thickness,a1=[...b1!==void 0&&(o1===void 0||T1(b1)!==T1(o1))?[`thickness = ${S1(b1)}`]:[],...F.noKerf&&S>0?["kerf = 0"]:[]],$1=a1.length?`material(${a1.join(", ")}) `:"",e1=`part("${y1.replace(/["\\]/g,"")}")`,I1=W.length===1&&!W[0].includes(`
|
|
2620
|
-
`)?`${
|
|
2621
|
-
${
|
|
3079
|
+
}`:F,_=d.map(H=>$1(g[H])),Q=_.sort((H,B)=>_.filter(Y=>Y===B).length-_.filter(Y=>Y===H).length)[0];return u([b,y],j,{kind:P.length?"fingers":"tabs",thickness:Q,generic:!0,label:`${P.length?"finger joints":"tabs"} ${I1(Q)} mm deep`})}function pl(t){let[e,n,r,c]=w0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,o3(h,t[d],t[f]));return u},s=[(e+r)/2,(n+c)/2],o=_2(s,t)?a(s):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+(c-n)*u/i];if(!_2(f,t))continue;let d=a(f);d>o&&(s=f,o=d)}let l=Math.max(r-e,c-n)/i;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!_2(d,t))continue;let p=a(d);p>o&&(s=d,o=p,h=!0)}h||(l/=2)}return{c:s,r:o}}function gl(t,e,n){let c=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let o=c+Math.PI/2+Math.PI*s/64;a.push([t[0]+n*Math.cos(o),t[1]+n*Math.sin(o)])}for(let s=0;s<=64;s++){let o=c-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(o),e[1]+n*Math.sin(o)])}return a}function D8(t,e){let[n,r,c,a]=t.box;if(Math.max(c-n,a-r)>80)return;let s=V2(t.poly),o=j2(t.poly,!0,Math.min(.25,s/400)),i=pl(t.poly),l=o.filter(P=>Math.abs(N1(P,i.c)-i.r)<=e),h=e4(l);if(!h||l.length<8)return;let u=o[0];for(let P of o)N1(P,h.c)>N1(u,h.c)&&(u=P);let f=N1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],p=P=>(P[0]-h.c[0])*d[0]+(P[1]-h.c[1])*d[1],m=P=>-(P[0]-h.c[0])*d[1]+(P[1]-h.c[1])*d[0],g=o.filter(P=>p(P)>h.r+e&&p(P)<f-h.r);if(g.length<4)return;let v=[g.filter(P=>m(P)>0),g.filter(P=>m(P)<0)];if(v.some(P=>P.length<2))return;let b=v.map(P=>M2([1,0],R8(P))).map(P=>P[0]*d[0]+P[1]*d[1]<0?[-P[0],-P[1]]:P),y=[b[0][0]+b[1][0],b[0][1]+b[1][1]],x=Math.hypot(y[0],y[1]);if(d=[y[0]/x,y[1]/x],g=o.filter(P=>p(P)>h.r+e&&p(P)<f-h.r),g.length<4||Math.abs(g.reduce((P,F)=>P+m(F),0)/g.length)>e)return;let w=g.map(P=>Math.abs(m(P))).sort((P,F)=>P-F),M=w[Math.floor(w.length/2)]*2;if(M>=h.r*2-e||M<.3)return;let k=Math.max(...o.map(p)),z=Gt(h.c,[d[0]*(k-M/2),d[1]*(k-M/2)]),A=s1([F3(h.r,h.r,256).map(P=>Gt(P,h.c)),gl(h.c,z,M/2)]);if(!L3([t.poly],A,e))return;let S=k-M/2,C=h.r*2,I=Math.atan2(d[1],d[0])*180/Math.PI-90,L=[];$1(C)!==9&&L.push(`head = ${I1(C)}`),$1(M)!==4.5&&L.push(`shank = ${I1(M)}`),$1(S)!==10&&L.push(`drop = ${I1(S)}`);let T=S>=(C+M)/2-1e-9,q=T?`keyhole(${L.join(", ")})`:`{ translate(${s0([0,-S])}) circle(d = ${I1(C)}); hull() { circle(d = ${I1(M)}); translate(${s0([0,-S])}) circle(d = ${I1(M)}); } }`;return{kind:"keyhole",radius:C/2,body:q,at:z,angle:I,center:z,label:"keyhole",keyhole:{head:C,shank:M,drop:S,top:z},library:T?"hanging":void 0}}var T8=.0025,Ke=(t,e)=>Math.abs(t[0]-e[0])>T8||Math.abs(t[1]-e[1])>T8;function s5(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(a=>a.a);t.closed||n.push(t.segs[t.segs.length-1].b);let r=[n[0]];for(let a of n.slice(1))Ke(a,r[r.length-1])&&r.push(a);!t.closed&&r.length<2&&r.push(n[n.length-1]);let c=`[${r.map(a=>s0(w2(a,e))).join(", ")}]`;return t.closed?`polygon(${c})`:r.length===2?`line(${s0(w2(r[0],e))}, ${s0(w2(r[1],e))})`:`polyline(${c})`}return`path("${Zt([t],e)}")`}function Zt(t,e){let n=r=>`${I1(r[0]-e[0])} ${I1(r[1]-e[1])}`;return t.map(r=>{let c=`M${n(r.segs[0].a)}`,a=r.segs[0].a;for(let s of r.segs)!Ke(s.b,a)&&(s.c==="L"||!Ke(s.p1,a)&&!Ke(s.p2,a))||(c+=s.c==="L"?`L${n(s.b)}`:`C${n(s.p1)} ${n(s.p2)} ${n(s.b)}`,a=s.b);return r.closed?c+"Z":c}).join("")}var q0=.01;function q8(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 o5=t=>t.segs[0].a,N8=t=>t.segs[t.segs.length-1].b;function vl(t){let e=new Set,n=[],r=s=>`${Math.round(s[0]/q0)},${Math.round(s[1]/q0)}`,c=new Map;t.forEach((s,o)=>{for(let i of[o5(s),N8(s)]){let l=r(i);c.set(l,[...c.get(l)??[],o])}});let a=s=>{let[o,i]=[Math.round(s[0]/q0),Math.round(s[1]/q0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of c.get(`${o+l},${i+h}`)??[])if(!e.has(u)&&(N1(o5(t[u]),s)<=q0||N1(N8(t[u]),s)<=q0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let o=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=o[o.length-1].b;if(N1(h,o[0].a)<=q0&&o.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=N1(o5(t[u]),h)<=q0?t[u]:q8(t[u]);o=o.concat(f.segs)}o=q8({segs:o,closed:!1}).segs}let i=o.length>1&&N1(o[o.length-1].b,o[0].a)<=q0;n.push({sub:{segs:o,closed:i},from:t[s]})}return n}var B8=.05;function yl(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 bl(t,e={}){let n=e.tolerance??B8,r=typeof t=="string"?t:yl(t),c=E8(r,{dpi:e.dpi}),a=[...c.notes],s={},o=(V,U=1)=>s[V]=(s[V]??0)+U,i=[],l=[],h=new Map;for(let V of c.items)if(V.layer.mode==="cut")for(let U of V.subs)U.closed?i.push({sub:U,names:V.names,group:V.filled?V:void 0}):(l.push(U),h.set(U,V.names));let u=vl(l);l=[];for(let{sub:V,from:U}of u)V.closed?i.push({sub:V,names:h.get(U)??[],line:{segs:V.segs,closed:!1}}):l.push(V);let f=i.map(V=>({...V,outline:J5(A3(V.sub),V.sub)})),d=f.filter(V=>V.outline.poly.length>=3&&V.outline.area>V2(V.outline.poly)*q0);for(let V of f)d.includes(V)||l.push(V.line??{segs:V.sub.segs,closed:!1});let p=(V,U,r1,h1)=>{if(r1!==h1)return!1;let[a1,x1,J1,q1]=V.box,[f0,m0,D,J]=U.box;if(a1<f0-q0||x1<m0-q0||J1>D+q0||q1>J+q0)return!1;let t1=V.poly.length;return[0,Math.floor(t1/3),Math.floor(2*t1/3)].filter(n1=>_2(V.poly[n1],U.poly)).length>=2},m=V=>{let U=d.map((a1,x1)=>x1).filter(a1=>!V.has(a1)).sort((a1,x1)=>d[x1].outline.area-d[a1].outline.area),r1=new Map,h1=new Map;return U.forEach((a1,x1)=>{let J1=-1;for(let q1=x1-1;q1>=0;q1--){let f0=U[q1];if(d[f0].outline.area>d[a1].outline.area&&p(d[a1].outline,d[f0].outline,d[a1].group,d[f0].group)){J1=f0;break}}r1.set(a1,J1),h1.set(a1,J1<0?0:h1.get(J1)+1)}),{order:U,parent:r1,depth:h1}},g=V8(d.map(V=>V.outline.poly),q0*2),v=m(new Set),{parent:b,depth:y}=v,x=V=>y.get(V)%2===0?V:b.get(V),w=new Set(d.map((V,U)=>U).filter(V=>g.self[V]));for(let[V,U]of g.pairs)x(V)===x(U)&&w.add(V).add(U);for(let V of v.order)y.get(V)%2===1&&w.has(b.get(V))&&w.add(V);for(let V of w)l.push(d[V].line??{segs:d[V].sub.segs,closed:!1});w.size&&a.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 M=[],k=new Map;for(let V of v.order){if(w.has(V))continue;let U=d[V];if(y.get(V)%2===0){let r1={sub:U.sub,outline:U.outline,names:U.names,holes:[],lines:[],marks:new Map,texts:[]};M.push(r1),k.set(V,r1)}else k.get(b.get(V)).holes.push({sub:U.sub,outline:U.outline,line:U.line})}let z=e.kerf!==void 0?e.kerf/2:$8(M.map(V=>V.outline.poly)),A=0;if(z&&z>0){let V=U=>({closed:!0,segs:U.map((r1,h1)=>({c:"L",a:r1,b:U[(h1+1)%U.length]}))});for(let U of M){let r1=g0([Wt(U.outline.poly,z)],U.holes.map(J=>Wt(J.outline.poly,z))),h1=R0(c0(r1,-z,"miter")),a1=c0(h1.flat(),z,"round",Math.min(.01,z/10)),x1=g0([U.outline.poly],U.holes.map(J=>J.outline.poly)),J1=J=>Math.abs(b1(J))<=V2(J)*q0;if(h1.length!==1||h1[0].length!==U.holes.length+1||h1[0].some(J1)||!L3(a1,x1,n)){U.noKerf=!0;continue}U.drawn=[U.sub,...U.holes.map(J=>J.sub)];let[q1,...f0]=h1[0].map(J=>a5(J,.001));U.outline=J5(q1),U.sub=V(q1);let m0=J=>[(J.box[0]+J.box[2])/2,(J.box[1]+J.box[3])/2],D=f0.map(J=>J5(J));for(let J of U.holes){let t1=m0(J.outline),w1=D.reduce((n1,E)=>N1(m0(E),t1)<N1(m0(n1),t1)?E:n1);D.splice(D.indexOf(w1),1),J.outline=w1,J.sub=V(w1.poly),J.line=void 0}}A=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${I1(A)} mm kerf: they are moved back, and $kerf is set.`)}let S=V=>{let U;for(let r1 of M){let[h1,a1,x1,J1]=r1.outline.box;V[0]<h1||V[0]>x1||V[1]<a1||V[1]>J1||_2(V,r1.outline.poly)&&(!U||r1.outline.area<U.outline.area)&&(U=r1)}return U},C={lines:[],marks:new Map,texts:[]},I=new Map,L=V=>{let U=S(o5(V));if(!U)return;let r1=I.get(U);return r1||(r1=H8(U.outline.poly,U.holes.map(h1=>h1.outline.poly),n),I.set(U,r1)),r1(A3(V,.02),V.closed)?U:void 0};for(let V of l){let U=L(V);(U?U.lines:C.lines).push(V)}for(let V of c.items)if(V.layer.mode!=="cut")for(let U of V.subs){let r1=(L(U)??C).marks;r1.set(V,[...r1.get(V)??[],U])}for(let V of c.texts)(S(V.at)??C).texts.push(V);c.texts.some(V=>V.layer.mode==="cut")&&a.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 V of M){let U=V.lines.map(r1=>A3(r1));V.holes=V.holes.filter(r1=>{if(!r1.line)return!0;let h1=x1=>_2(x1,r1.outline.poly),a1=O8(U,r1.outline.poly,q0*2)||V.lines.some(x1=>h1(o5(x1)))||[...V.marks.values()].some(x1=>x1.some(J1=>h1(o5(J1))))||V.texts.some(x1=>h1(x1.at))||M.some(x1=>x1!==V&&x1.outline.area<r1.outline.area&&h1(x1.outline.poly[0]));return a1&&V.lines.push(r1.line),!a1})}let T=V=>t4(V,n)??r4(V,n)??n4(V,n)??c4(V,n)??D8(V,n),q=new Map;for(let V of M){let U=t4(V.outline,n)??r4(V.outline,n)??n4(V.outline,n)??c4(V.outline,n)??Xt(V.outline,n);q.set(V,U);for(let r1 of V.holes)r1.found=T(r1.outline)}let P=new Map,F=[...q.values()].some(V=>V?.thickness&&!V.generic);for(let V of q.values())V?.thickness&&V.thickness<=10&&(!F||!V.generic)&&P.set(V.thickness,(P.get(V.thickness)??0)+1);let j=[...P.entries()].sort((V,U)=>U[1]-V[1])[0]?.[0];if(j!==void 0)for(let V of M){let U=q.get(V);if(U?.thickness!==void 0&&U.thickness!==j){let r1=Xt(V.outline,n,j);r1&&r1.thickness===j&&q.set(V,r1)}}let _=new Set;for(let V of q.values())V?.kind==="fingers"&&V.finger&&_.add($1(V.finger));M.sort((V,U)=>{let r1=U.outline.box[3]-V.outline.box[3];return Math.abs(r1)>1?r1:V.outline.box[0]-U.outline.box[0]});let Q=new Set,H=new Map,B=[];for(let[V,U]of M.entries()){let r1=U.names[0]??`part ${V+1}`,h1=(H.get(r1)??0)+1;H.set(r1,h1);let a1=h1>1?`${r1} ${h1}`:r1,x1;for(let w1 of[2,1,0]){let n1=Ml(U,q.get(U),w1,j,_,n);if(zl(n1,U,n)){x1=n1,w1<2&&a.push(w1===1?`Part "${a1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${a1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!x1){let w1=U.drawn??[U.sub,...U.holes.map(n1=>n1.sub)];C.lines.push(...w1.map(n1=>({segs:n1.segs,closed:!1})),...U.lines);for(let[n1,E]of U.marks)C.marks.set(n1,[...C.marks.get(n1)??[],...E]);C.texts.push(...U.texts),a.push(`Part "${a1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let w1 of x1.found)o(w1);for(let w1 of x1.libraries)Q.add(w1);let J1=U8(U.marks,[],U.texts,x1.origin),q1=[...x1.cut,...J1],f0=x1.thickness,m0=[...f0!==void 0&&(j===void 0||$1(f0)!==$1(j))?[`thickness = ${I1(f0)}`]:[],...U.noKerf&&A>0?["kerf = 0"]:[]],D=m0.length?`material(${m0.join(", ")}) `:"",J=`part("${a1.replace(/["\\]/g,"")}")`,t1=q1.length===1&&!q1[0].includes(`
|
|
3080
|
+
`)?`${D}${J} ${q1[0]}`:`${D}${J} {
|
|
3081
|
+
${q1.join(`
|
|
2622
3082
|
`)}
|
|
2623
|
-
}
|
|
2624
|
-
`),
|
|
2625
|
-
`),
|
|
3083
|
+
}`;B.push({name:a1,code:H2(x1.origin,0,t1),local:t1,thickness:f0})}let Y=U8(C.marks,C.lines,C.texts,[0,0]);Y.length&&M.length&&a.push("Some lines or marks are outside every part; they are kept on their own.");let e1;if(e.pack){let V=new Map;for(let r1 of B){let h1=r1.local.replace(/part\("[^"]*"\)/,"part()"),a1=V.get(h1);a1?a1.qty++:V.set(h1,{name:r1.name,qty:1})}e1=[...V.entries()].map(([r1,h1])=>r1.replace("part()",`part("${h1.name.replace(/["\\]/g,"")}"${h1.qty>1?`, qty = ${h1.qty}`:""})`));let U=B.length-V.size;U&&a.push(`${U} part${U===1?" is":"s are"} the same as another and became a quantity.`)}else e1=B.map(V=>V.code);let X=Object.entries(s).filter(([V])=>V!=="outline").map(([V,U])=>`${U} ${V}${U===1?"":xl[V]??"s"}`).join(", "),M1=`${B.length} part${B.length===1?"":"s"}${X?`; found ${X}`:""}.`,v1=[`// ${e.name?e.name+": ":""}imported from an SVG drawing.`,`// ${M1}`,...a.map(V=>`// ${V}`),"",...[...Q].sort().map(V=>`use <kerf/${V}>`),...Q.size?[""]:[]],p1=[];j!==void 0&&p1.push(`$thickness = ${I1(j)}; // from the joints`),A>0&&p1.push(`$kerf = ${I1(A)}; // the drawing's outlines were offset by half of this`),!e.pack&&B.length&&p1.push('$layout = "none"; // keep the parts where the drawing has them');let F1=[v1.join(`
|
|
3084
|
+
`),p1.join(`
|
|
3085
|
+
`),e1.join(`
|
|
2626
3086
|
|
|
2627
|
-
`),
|
|
3087
|
+
`),Y.join(`
|
|
2628
3088
|
`)].filter(Boolean).join(`
|
|
2629
3089
|
|
|
2630
3090
|
`).replace(/\n{3,}/g,`
|
|
2631
3091
|
|
|
2632
3092
|
`)+`
|
|
2633
|
-
`;try{
|
|
2634
|
-
${[x,...d].map(
|
|
3093
|
+
`;try{F1=Nt(F1)}catch{}return{source:F1,parts:B.length,found:s,summary:M1,notes:a}}var xl={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},K5=t=>t.trimEnd().endsWith("}")?t:t+";";function Ml(t,e,n,r,c,a){let s=[],o=new Set,i=n>0?e:void 0,l=t.outline.box,h,u;if(i?.kind==="rect"){let{w:S,h:C,r:I}=i.rect;h=w2(i.center,M2([S/2,C/2],i.angle)),h=[$1(h[0]),$1(h[1])],u=H2([0,0],i.angle,`rect(${s0([S,C])}${$1(I)>0?`, r = ${I1(I)}`:""})`),s.push("rectangle")}else i?(h=[$1(i.at[0]),$1(i.at[1])],u=H2(w2(i.at,h),i.angle,i.body),s.push(Yt[i.kind]),i.library&&o.add(i.library)):(h=[$1(l[0]),$1(l[1])],u=s5(t.sub,h),s.push("outline"));let f=t.holes.map(S=>({...S,found:n>0?S.found:void 0})),d=[],p=S=>w2(S,h),m=S=>S,g=0,v=new Set(f);if(n===2&&!i)for(let S of f){let C=S.found?.circle;if(!C||C.r*2>15)continue;let I=j2(t.outline.poly,!0,.25),L=Math.min(...I.map(F=>N1(F,C.c))),T=L-C.r;if(T<.5||I.filter(F=>Math.abs(N1(F,C.c)-L)<=a).length*.25<L*Math.PI*.8)continue;let P=[s0(p(C.c))];$1(C.r*2)!==4&&P.push(`d = ${I1(C.r*2)}`),$1(T)!==3&&P.push(`wall = ${I1(T)}`),m=F=>`hanging_loop(${P.join(", ")}) ${F}`,g=L,o.add("hanging"),s.push("hanging loop"),v.delete(S);break}if(n===2){let[S,C,I,L]=l,T=(S+I)/2,q=I-S,P=L-C,F=B=>B[1]>=C+P*.66,j=B=>[...v].filter(Y=>Y.found?.circle&&$1(Y.found.circle.r)===$1(B.found.circle.r)).length,_=[...v].filter(B=>B.found?.circle&&B.found.circle.r*2>=1.5&&B.found.circle.r*2<=15&&F(B.found.circle.c)&&j(B)<=2),Q=!1;for(let B of _){let Y=B.found.circle;if(Math.abs(Y.c[0]-T)>Math.max(.5,q*.02))continue;let e1=Y.r*2;d.push(`hanging_hole(${s0(p(Y.c))}${$1(e1)!==5?`, d = ${I1(e1)}`:""})`),v.delete(B),Q=!0;break}if(!Q)for(let B of _)for(let Y of _){if(Q||B===Y)continue;let[e1,X]=[B.found.circle,Y.found.circle];if(Math.abs(e1.r-X.r)>a||Math.abs(e1.c[1]-X.c[1])>a||e1.c[0]>=X.c[0])continue;let M1=[(e1.c[0]+X.c[0])/2,e1.c[1]];if(Math.abs(M1[0]-T)>Math.max(1,q*.02))continue;let v1=e1.r*2;d.push(`hanging_hole(${s0(p(M1))}${$1(v1)!==5?`, d = ${I1(v1)}`:""}, spacing = ${I1(X.c[0]-e1.c[0])})`),v.delete(B),v.delete(Y),Q=!0}Q&&(o.add("hanging"),s.push("hanger hole"));let H=[...v].filter(B=>B.found?.kind==="keyhole"&&B.found.library&&Math.abs(B.found.angle)<.01);for(let B of H)for(let Y of H){if(!v.has(B)||!v.has(Y)||B===Y)continue;let[e1,X]=[B.found,Y.found];if(e1.body!==X.body||Math.abs(e1.at[1]-X.at[1])>a||e1.at[0]>=X.at[0])continue;let M1=[I1(X.at[0]-e1.at[0])],v1=p([(e1.at[0]+X.at[0])/2,e1.at[1]]),p1=e1.body.slice(8,-1);M1.push($1(v1[0])||$1(v1[1])?`at = ${s0(v1)}`:""),p1&&M1.push(p1),d.push(`keyholes(${M1.filter(Boolean).join(", ")})`),v.delete(B),v.delete(Y),o.add("hanging"),s.push("keyhole","keyhole")}if(r!==void 0){let B=[...v].filter(Y=>Y.found?.kind==="rect"&&$1(Y.found.rect.r)===0);for(let Y of wl(B,a)){let{items:e1,dir:X,spacing:M1,along:v1,across:p1}=Y,G1=e1.length,F1=r,V=p1-F1,U=w2(e1[0].found.center,[X[0]*M1/2,X[1]*M1/2]),r1=Math.atan2(X[1],X[0])*180/Math.PI,h1=G1*M1;if(Math.abs(V)<=a&&Math.abs(v1-M1/2)<=a&&G1>=2){let a1=2*G1-1,x1=a1*v1,J1=Math.max(3*F1,6),q1=(D,J)=>{let t1=Math.round(D/J);return t1%2===0&&(t1+=D/J>t1?1:-1),Math.max(3,t1)};if(q1(x1,J1)!==a1&&q1(x1,v1)!==a1)continue;let f0=w2(e1[0].found.center,[X[0]*v1/2,X[1]*v1/2]),m0=q1(x1,J1)===a1?"":`, finger = ${I1(v1)}`;d.push(H2(p(f0),r1,`finger_holes(${I1(x1)}${m0})`)),s.push("finger joint slot row")}else if(V>=-a&&V<=1){let a1=[I1(h1)];G1!==Math.max(1,Math.round(h1/50))&&a1.push(`count = ${G1}`);let x1=v1-V;Math.abs(x1-h1/(2*G1))>a&&a1.push(`width = ${I1(x1)}`),Math.abs(V-.1)>.001&&a1.push(`clearance = ${I1(V)}`),d.push(H2(p(U),r1,`slots(${a1.join(", ")})`)),o.add("tabs"),s.push("slot row")}else continue;for(let a1 of e1)v.delete(a1)}}}let b=[...v].filter(S=>S.found),y=[...v].filter(S=>!S.found);if(n===2){let S=new Map;for(let C of b){let I=H2([0,0],C.found.angle,C.found.body);S.set(I,[...S.get(I)??[],C])}for(let[C,I]of S){let L=kl(I.map(T=>p(T.found.at)),a);if(L){d.push(`${L} ${C}`);for(let T of I)s.push(Yt[T.found.kind]),T.found.library&&o.add(T.found.library);s.push("hole pattern");for(let T of I)v.delete(T)}}}for(let S of v)S.found&&(d.push(H2(p(S.found.at),S.found.angle,S.found.body)),s.push(Yt[S.found.kind]),S.found.library&&o.add(S.found.library));for(let S of y)d.push(s5(S.sub,h)),s.push("outline");let x=m(u),w=d.length?[`difference() {
|
|
3094
|
+
${[x,...d].map(K5).join(`
|
|
2635
3095
|
`)}
|
|
2636
|
-
}`]:[
|
|
2637
|
-
${[...M
|
|
3096
|
+
}`]:[K5(x)],M=t.lines.map(S=>K5(s5(S,h))),k=e?.thickness??r,z=[...[...o].map(S=>`use <kerf/${S}>`),`$thickness = ${k??3};`,`translate(${s0(h)}) {
|
|
3097
|
+
${[...w,...M].join(`
|
|
2638
3098
|
`)}
|
|
2639
3099
|
}`].join(`
|
|
2640
|
-
`),
|
|
2641
|
-
${
|
|
3100
|
+
`),A=Math.max(0,g,i?.radius??0,...f.map(S=>n>0?S.found?.radius??0:0));return{origin:h,round:A,cut:[...w,...M],check:z,found:s,libraries:o,thickness:i?.thickness}}var Yt={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function wl(t,e){let n=[],r=new Set,c=s=>{let o=s.found.rect;return`${Math.round((s.found.angle%180+180)%180)}|${$1(o.w)}|${$1(o.h)}`},a=new Map;for(let s of t)a.set(c(s),[...a.get(c(s))??[],s]);for(let s of a.values()){if(s.length<2)continue;let{w:o,h:i}=s[0].found.rect,l=s[0].found.angle;for(let[h,u,f]of[[l,o,i],[l+90,i,o]]){let d=M2([1,0],h),p=[-d[1],d[0]],m=s.filter(v=>!r.has(v)),g=new Map;for(let v of m){let b=v.found.center,y=Math.round((b[0]*p[0]+b[1]*p[1])/e),x=[...g.keys()].find(w=>Math.abs(w-y)<=1)??y;g.set(x,[...g.get(x)??[],v])}for(let v of g.values()){let b=x=>x.found.center[0]*d[0]+x.found.center[1]*d[1];v.sort((x,w)=>b(x)-b(w));let y=0;for(;y<v.length-1;){let x=b(v[y+1])-b(v[y]),w=y+1;for(;w+1<v.length&&Math.abs(b(v[w+1])-b(v[w])-x)<=e;)w++;if(w>y&&x>u){let M=v.slice(y,w+1);for(let k of M)r.add(k);n.push({items:M,dir:d,spacing:x,along:u,across:f})}y=w}}}}return n}function kl(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let m of[...h].sort((g,v)=>g-v))(!u.length||m-u[u.length-1]>e*2)&&u.push(m);if(u.length===1)return;let[f,d]=[$1(u[0]),$1((u[u.length-1]-u[0])/(u.length-1))],p=$1(f+d*(u.length-1));if(!(d<=0||Math.floor((p-f)/d+1e-9)+1!==u.length)&&!u.some((m,g)=>Math.abs(m-(f+g*d))>e))return`[${I1(f)}:${I1(d)}:${I1(p)}]`},r=t.map(h=>h[0]),c=t.map(h=>h[1]),a=h=>new Set(h.map(u=>Math.round(u/(e*2)))).size,s=a(r),o=a(c);if(o===1||s===1){let h=o===1?r:c;if(a(h)!==t.length)return;let u=n(h);return u?o===1?`for (x = ${u}) translate([x, ${I1(c[0])}])`:`for (y = ${u}) translate([${I1(r[0])}, y])`:void 0}if(s*o!==t.length)return;let i=n(r),l=n(c);if(!(!i||!l))return`for (x = ${i}, y = ${l}) translate([x, y])`}function U8(t,e,n,r){let c=[];for(let o of e)c.push(K5(s5(o,r)));let a=new Map,s=(o,i,l)=>{let h=o.name,u=a.get(h)??{layer:o,code:[]};u.code.push(K5(i)+(l?` // ${l}`:"")),a.set(h,u)};for(let[o,i]of t){let l=B8;if(i.length===1&&i[0].closed){let d=J5(A3(i[0]),i[0]),p=d.area>1e-6?t4(d,l)??r4(d,l)??n4(d,l)??c4(d,l):void 0;if(p){s(o.layer,H2(w2(p.at,r),p.angle,p.body));continue}}if(o.layer.mode!=="fill"||i.every(d=>!d.closed)){for(let d of i)s(o.layer,s5(d,r));continue}let h=Zt(i,r),u=i.filter(d=>d.closed).map(d=>A3(d)),f=o.fillRule==="evenodd"||L3(s1(u,"nonzero"),s1(u,"evenodd"),.01);s(o.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let o of n){let i=[JSON.stringify(o.text),`size = ${I1(o.size)}`];o.anchor!=="left"&&i.push(`halign = "${o.anchor}"`),s(o.layer,H2(w2(o.at,r),o.angle,`text(${i.join(", ")})`),o.font?`${o.font} in the drawing`:void 0)}for(let{layer:o,code:i}of a.values()){let l=["cut","score","engrave","guide"].includes(o.name)?`${o.name}()`:`layer("${o.name}", mode = "${o.mode}", color = "${o.color}")`;c.push(i.length===1&&!i[0].includes("//")?`${l} ${i[0]}`:`${l} {
|
|
3101
|
+
${i.join(`
|
|
2642
3102
|
`)}
|
|
2643
|
-
}`)}return r}function Xi(t,e,n){let c;try{c=new D3({maxSteps:2e6}).run(a2(t.check).program).shape}catch{return!1}let r=c.layers.get("cut");if(!r)return!1;let a=b0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=x1(r.regions),i=n+t.round*16e-5;if(!f3(a,s,i))return!1;let o=e.lines.map(l=>u3(l));return!(o.length&&!f3(o,r.lines,i,!1))}var B=.001,J1=(t,e)=>t.reduce((n,c,r)=>n+c*e[r],0),m1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],M1=t=>Math.hypot(...t),R8=t=>[t[2],t[6],t[10]],i0=(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]),g6=(t,e)=>O1(L0(t.matrix),e.matrix);function d3(t){let[e,n]=t[0],c=0;for(let r=1;r<t.length-1;r++)c+=(t[r][0]-e)*(t[r+1][1]-n)-(t[r][1]-n)*(t[r+1][0]-e);return c/2}var Y2=t=>Math.abs(t.reduce((e,n)=>e+d3(n),0)),v6=t=>t.reduce((e,n)=>e+n.reduce((c,r,a)=>c+Math.hypot(r[0]-n[(a+1)%n.length][0],r[1]-n[(a+1)%n.length][1]),0),0);function H4(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 F8=([t,e,n,c])=>[[t,e],[n,e],[n,c],[t,c]];function y6(t){if(t.length!==1)return!1;let e=H4(t);return Y2(M3(t,[F8(e)]))<B*B}var b6=(t,e)=>x0(t,[F8(e)]);function $8(t,e,n=0){let c=e[0]*e[5]-e[1]*e[4]<0;return t.map(r=>{let a=r.map(([s,i])=>i0(e,[s,i,n]).slice(0,2));return c?a.reverse():a})}function Zi(t,e){let n=!1;for(let c=0,r=t.length-1;c<t.length;r=c++){let[a,s]=t[c],[i,o]=t[r];s>e[1]!=o>e[1]&&e[0]<(i-a)*(e[1]-s)/(o-s)+a&&(n=!n)}return n}function W3(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?Math.max(0,Math.min(1,((t[0]-e[0])*c+(t[1]-e[1])*r)/a)):0;return Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}function D8(t,e){let n=1/0;for(let c of t)for(let r=0;r<e.length;r++)n=Math.min(n,W3(c,e[r],e[(r+1)%e.length]));for(let c of e)for(let r=0;r<t.length;r++)n=Math.min(n,W3(c,t[r],t[(r+1)%t.length]));return n}var x6=(t,e)=>t.filter(n=>d3(n)<0&&Zi(n,e));function X3(t){return t.placed?t.bends.length?"Flexible or bent 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 q8(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 O4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&H8(t.regions)===H8(e.regions)&&O8(t.cutLines)===O8(e.cutLines)}function H8(t){let e=n=>{let c=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,r=[c,[...c].reverse()].map(a=>{let s=0;for(let i=1;i<a.length;i++)(a[i][0]<a[s][0]||a[i][0]===a[s][0]&&a[i][1]<a[s][1])&&(s=i);return JSON.stringify([...a.slice(s),...a.slice(0,s)])});return JSON.stringify([Math.sign(d3(n)),r.sort()[0]])};return JSON.stringify(t.map(e).sort())}function O8(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),c=JSON.stringify([...e].reverse());return n<c?n:c}).sort())}var q1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),v0=t=>typeof t=="string"&&t.length>0,S2=t=>typeof t=="number"&&Number.isFinite(t),F2=t=>S2(t)&&t>=0,k2=t=>S2(t)&&t>0,p3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(S2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,g3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(S2),d2=t=>g3(t,3)&&t.every(e=>Math.abs(e)<=1e7),J2=t=>q1(t)&&v0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),R4=t=>q1(t)&&v0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),Z3=t=>J2(t)||R4(t),R2=t=>Array.isArray(t)&&t.every(Z3),m3=t=>d2(t)&&Math.hypot(...t)>1e-9,Yi=t=>q1(t)&&(t.kind==="translate"&&d2(t.by)||t.kind==="rotate"&&d2(t.origin)&&m3(t.axis)&&S2(t.angle)&&Math.abs(t.angle)<=1e6),M6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),N8=t=>q1(t)&&Object.values(t).every(M6),B8=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||S2(t)||Array.isArray(t)&&t.every(n=>B8(n,e+1))),w6=t=>q1(t)&&Object.values(t).every(e=>B8(e)),Ji=t=>t===null||q1(t)&&M6(t.sourceHash)&&M6(t.engineHash)&&N8(t.dependencies)&&N8(t.fonts);function H5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!q1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let c=(s,i,o)=>{for(let l of Object.keys(s))i.includes(l)||n(o?`${o}.${l}`:l,"Unknown specification field.")};c(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),v0(t.model)||n("model","Give the model a nonempty name.");let r=new Set,a=(s,i)=>{if(!q1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!q1(l)||!p3(l.thickness,Number.MIN_VALUE)||!p3(l.kerf)||l.edgeError!==void 0&&!F2(l.edgeError)||l.lot!==void 0&&!v0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),q1(l)&&c(l,["thickness","kerf","edgeError","lot"],`${i}.${o}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[s,i]of t.configurations.entries())!q1(i)||!v0(i.id)||i.params!==void 0&&!w6(i.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):r.has(i.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(r.add(i.id),c(i,["id","params","materials"],`configurations[${s}]`),i.materials!==void 0&&a(i.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,i=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!q1(h)||!v0(h.id)||!v0(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(c(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),s.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."),s.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&i++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(p=>typeof p=="string"&&r.has(p)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!J2(h.a)||!J2(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!k2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!J2(h.tab)||!J2(h.receiver)||!g3(h.region,4)||h.region.some(p=>Math.abs(p)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!p3(h.clearance)||!F2(h.flushTolerance)||!F2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let p=h.stops;if(!R4(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(J2)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(J2)||!p3(h.clearance)||!p3(h.endplay)||!k2(h.minimumOverlap)||!F2(h.maximumStopGap)||!Array.isArray(p)||p.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let m of p){if(!q1(m)||!R4(m.body)||!q1(m.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}c(m,["body","attachment"],u+".stops");let g=m.attachment;c(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!R4(g.thread)||!k2(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":(!F2(h.minimumGap)||h.bodies!==void 0&&(!R2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!v0(h.from)||!r.has(h.from)||!v0(h.to)||!r.has(h.to)||h.from===h.to||!F2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(p=>q1(p)&&Z3(p.body)&&Yi(p.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&&!v0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!R2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!R2(h.scope)||!h.scope.length)||!F2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(p=>q1(p)&&v0(p.id)&&Z3(p.part)&&d2(p.from)&&typeof p.held=="boolean"&&(p.fasten===void 0||Array.isArray(p.fasten)&&p.fasten.every(v0))&&(p.tool===void 0||q1(p.tool)&&d2(p.tool.from)&&d2(p.tool.to)&&k2(p.tool.diameter)&&p.tool.diameter<=1e6&&d2(p.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":(!R2(h.roots)||!h.roots.length||h.removable!==void 0&&!R2(h.removable)||!Array.isArray(h.links)||!h.links.every(p=>q1(p)&&v0(p.claim)&&["glued","locked","captured"].includes(p.fastening)&&typeof p.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!R2(h.bodies)||!h.bodies.length||!R2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(p=>q1(p)&&Z3(p.a)&&Z3(p.b)&&(p.kind==="fixed"||p.kind==="revolute"&&d2(p.anchorA)&&d2(p.anchorB)&&m3(p.axisA)&&m3(p.axisB)&&(p.range===void 0||p3(p.range,-1e6))||p.kind==="prismatic"&&m3(p.axisA)&&p3(p.travel,-1e6)||p.kind==="gear"&&m3(p.axisA)&&m3(p.axisB)&&k2(p.ratio)&&p.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!R2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!S2(h.ground)||Math.abs(h.ground)>1e7||!m3(h.gravity)||h.gravity[2]>=0||!F2(h.minimumMargin)||!h.loads.every(p=>q1(p)&&Z3(p.body)&&k2(p.mass)&&(p.center===void 0||d2(p.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!v0(h.plan)||!v0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(p=>q1(p)&&v0(p.step)&&R2(p.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=(p,m,g)=>{q1(p)&&c(p,m,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[p,m]of h.moving.entries())q1(m)&&(d(m,["body","trajectory"],`${u}.moving[${p}]`),d(m.trajectory,q1(m.trajectory)&&m.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${p}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[p,m]of h.steps.entries())q1(m)&&(d(m,["id","part","from","held","fasten","tool"],`${u}.steps[${p}]`),d(m.tool,["from","to","diameter","travel"],`${u}.steps[${p}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[p,m]of h.joints.entries())q1(m)&&d(m,["kind","a","b",...m.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:m.kind==="prismatic"?["axisA","travel"]:m.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${p}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((p,m)=>d(p,["claim","fastening","installed"],`${u}.links[${m}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((p,m)=>d(p,["body","mass","center"],`${u}.loads[${m}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((p,m)=>d(p,["step","bodies"],`${u}.holds[${m}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(q1);for(let l of o){let h=(u,f)=>o.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=o.find(m=>m.id===l.plan&&m.kind==="assembly-access"),f=o.find(m=>m.id===l.retention&&m.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(q1).map(m=>m.id)),p=new Set((Array.isArray(f?.links)?f.links:[]).filter(q1).map(m=>m.claim));if(Array.isArray(l.holds))for(let m of l.holds)q1(m)&&!d.has(m.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(m.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let m of u.steps)if(q1(m)&&Array.isArray(m.fasten))for(let g of m.fasten)p.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(m.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(q1(f)){let d=q1(f.body)?f.body:{},p=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(p)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(p)}}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)q1(u)&&!o.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 z6(t){let e=[],n=(r,a)=>e.push({code:"invalid-snapshot",path:r,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let c=new Set;for(let[r,a]of t.entries()){let s=`snapshots[${r}]`;if(!q1(a)||a.schemaVersion!==1||!v0(a.configuration)||!w6(a.params)||!w6(a.renderSettings)||!Ji(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(o=>typeof o=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}c.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),c.add(a.configuration);let i=new Set;for(let[o,l]of a.parts.entries()){if(!q1(l)||!v0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!k2(l.thickness)||l.glue!==void 0&&(!J2(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!v0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!F2(l.kerf)||l.kerf>1e6)||!Ki(l.matrix)||typeof l.placed!="boolean"||!U8(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!U8(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>q1(u)&&S2(u.x0)&&S2(u.x1)&&u.x1>u.x0&&S2(u.angle))){n(`${s}.parts[${o}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);i.has(h)&&n(`${s}.parts[${o}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),i.add(h)}for(let[o,l]of a.hardware.entries())(!q1(l)||l.label!==null&&!v0(l.label)||typeof l.kind!="string"||!g3(l.from,3)||!g3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!d2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!k2(l.size))||!(k2(l.size)&&l.size<=1e6||g3(l.size,2)&&l.size.every(h=>k2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function U8(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(c=>g3(c,2)&&c.every(r=>Math.abs(r)<=1e6)))}function Ki(t){if(!g3(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(c=>Math.abs(c)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let c=0;c<3;c++)for(let r=0;r<3;r++){let a=e[c]*e[r]+e[4+c]*e[4+r]+e[8+c]*e[8+r];if(Math.abs(a-(c===r?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 _8(t){let e=[];for(let n of t.claims){let c=r=>e.push({claim:n.id,ref:r});n.kind==="glue-contact"&&(c(n.a),c(n.b)),n.kind==="tab-slot"&&(c(n.tab),c(n.receiver)),n.kind==="captured-shaft"&&(c(n.shaft),n.bearings.forEach(c),n.stack.forEach(c),n.stops.forEach(r=>{c(r.body),r.attachment.kind==="threaded"&&c(r.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(c),n.kind==="motion-clearance"&&n.moving.forEach(r=>c(r.body)),n.kind==="assembly-access"&&(n.initial.forEach(c),n.scope?.forEach(c),n.steps.forEach(r=>c(r.part))),n.kind==="retention"&&(n.roots.forEach(c),n.removable?.forEach(c)),n.kind==="joint-constraints"&&(n.bodies.forEach(c),n.roots.forEach(c),n.joints.forEach(r=>{c(r.a),c(r.b)})),n.kind==="stability"&&(n.supports.forEach(c),n.loads.forEach(r=>c(r.body))),n.kind==="assembly-support"&&n.holds?.forEach(r=>r.bodies.forEach(c))}return e}var Z0=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),L2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var Q1=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),c1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),C6=(t,e,n=[],c="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:c}),R5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,O5=(t,e)=>R5(t,e)?.thickness??[e.thickness,e.thickness];function $4(t,e){let n=R5(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 L6=(t,e)=>t[0]>=e[0]+B&&t[1]<=e[1]-B,A6=(t,e)=>t[0]<e[0]-B||t[1]>e[1]+B,P6=(...t)=>t.map(X3).find(Boolean);function q4(t,e){let n=Z0(e,t.a),c=Z0(e,t.b);if(n===c)return Q1("A glue contact needs two different physical instances.");let r=P6(n,c);if(r)return c1(r);let a=g6(n,c),s=t.faceA==="top"?n.thickness:0,i=t.faceB==="top"?c.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return Q1("The selected faces are not parallel.");let o=Math.abs(a[11]+a[10]*i-s);if(o>B)return Q1("The selected faces are separated.",{faceGap:o});if(o>1e-7)return c1("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*a[10]>-1+1e-7)return Q1("The selected surfaces face the same way, rather than meeting.");let u=$8(c.regions,a,i),f=Y2(x0(n.regions,u)),d=B*(v6(n.regions)+v6(u)),p={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?Q1("There is insufficient geometric glue contact.",p):f<t.minimumArea+d?{...c1("Contact area is on the numerical acceptance boundary."),measurements:p}:C6("The selected nominal faces have the required geometric contact.",p,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function G8(t,e,n){let c=Z0(e,t.tab),r=Z0(e,t.receiver);if(c===r)return Q1("A tongue and its receiving panel must be different instances.");let a=P6(c,r);if(a)return c1(a);let s=g6(r,c);if(!q8(s)||Math.abs(s[10])>B)return c1("Only orthogonal tab/slot geometry is supported.");let i=b6(c.regions,t.region);if(!y6(i))return c1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=H4(i),f=4*B,d=B,m=[[o-f,l+d,o,u-d],[h,l+d,h+f,u-d],[o+d,l-f,h-d,l],[o+d,u,h-d,u+f]].map(V=>Y2(b6(c.regions,V))>B*B).flatMap((V,J)=>V?[J]:[]);if(m.length>1)return c1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(m.length&&Math.abs(m[0]<2?s[8]:s[9])<.5)return c1("The tongue must join its parent along the insertion direction.");let g;if(m.length){let V=m[0],J=V<2?[V===0?o:h,(l+u)/2,0]:[(o+h)/2,V===2?l:u,0],o1=i0(s,J)[2],Z=(V<2?s[8]:s[9])*(V%2===0?-1:1);g={z:o1,outward:Z}}let v=[];for(let V of[o,h])for(let J of[l,u])for(let o1 of[0,c.thickness])v.push(i0(s,[V,J,o1]));let y=[0,1,2].map(V=>Math.min(...v.map(J=>J[V]))),b=[0,1,2].map(V=>Math.max(...v.map(J=>J[V]))),x=x6(r.regions,[(y[0]+b[0])/2,(y[1]+b[1])/2]);if(!x.length)return Q1("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!y6([x[0]]))return c1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],w=H4([M]),k=$4(n,c),z=$4(n,r);if(![...k,...z].every(Number.isFinite))return c1("Compensated kerf metadata is needed for manufacturing bounds.");let S={},L=!1;for(let V=0;V<2;V++){let J=Math.abs(s[V*4+2])>.5,o1=J?O5(n,c):[b[V]-y[V]+k[0],b[V]-y[V]+k[1]],Z=w[V+2]-w[V],p1=[Z-z[1]-o1[1],Z-z[0]-o1[0]];if(S[V?"clearanceY":"clearanceX"]=p1,A6(p1,t.clearance))return Q1("Tab/slot clearance is outside the required range.",S);L||(L=!L6(p1,t.clearance));let E=y[V],$=b[V];J?s[V*4+2]>0?$+=o1[1]-c.thickness:E-=o1[1]-c.thickness:(E-=Math.max(0,k[1])/2,$+=Math.max(0,k[1])/2);let X=Math.min(E-w[V],w[V+2]-$)-Math.max(0,z[1])/2;if(S[V?"minimumSideGapY":"minimumSideGapX"]=X,X<-B)return Q1("The tongue is offset into the edge of its slot.",S);X<B&&(L=!0)}let I=Math.max(0,-k[0])/2,q=O5(n,r);if(t.flushTolerance>=q[0]-B)return c1("flushTolerance must be smaller than the receiving thickness.");let R=Math.max(0,Math.min(b[2]-I,q[1])-Math.max(y[2]+I,0)),N=q[1]-t.flushTolerance;if(S.engagement=R,S.requiredEngagement=N,R<=B)return Q1("The tongue does not engage the receiving panel.",S);if(R<N-B)return Q1("The tongue does not engage through the receiving panel.",S);if(R<N+B&&(L=!0),g&&(g.outward>0&&g.z<q[1]-B||g.outward<0&&g.z>B))return Q1("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",S);let G=Math.min(...r.regions.filter(V=>V!==M).map(V=>D8(M,V)))-Math.max(0,-z[0]);return S.minimumLigament=G,G<t.minimumLigament-B?Q1("Too little material remains around the slot.",S):(G<t.minimumLigament+B&&(L=!0),L?{...c1("A fit condition is on its numerical acceptance boundary."),measurements:S}:C6("The rectangular tongue fits and engages its receiving slot.",S,["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."],R5(n,c)||R5(n,r)?"bounded-fit":"nominal"))}function F4(t){let e=m1(t.to,t.from),n=M1(e);return typeof t.size=="number"&&n>B?{start:t.from,dir:e.map(c=>c/n),length:n,diameter:t.size}:null}function k6(t,e){let n=F4(e);if(!n||M1([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 c=m1(n.start,t.start),r=J1(c,t.dir);return M1(c.map((a,s)=>a-r*t.dir[s]))<B}var D4=(t,e)=>J1(m1(e,t.start),t.dir),S6=(t,e)=>[D4(t,e.from),D4(t,e.to)].sort((n,c)=>n-c);function Qi(t,e){let n=R8(e.matrix);if(J1(n,t.dir)<0||M1([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 c=i0(L0(e.matrix),t.start),r=[c[0],c[1]],a=x6(e.regions,r);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],i=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,o=[i.reduce((p,m)=>p+m[0],0)/i.length,i.reduce((p,m)=>p+m[1],0)/i.length];if(Math.hypot(o[0]-r[0],o[1]-r[1])>B)return"The shaft is not centered in the bore.";let l=s.map(p=>Math.hypot(p[0]-o[0],p[1]-o[1]));if(Math.max(...l)-Math.min(...l)>B)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((p,m)=>W3(r,p,s[(m+1)%s.length]))),u=Math.max(...s.map(p=>Math.hypot(p[0]-r[0],p[1]-r[1]))),f=D4(t,i0(e.matrix,[0,0,0])),d=D4(t,i0(e.matrix,[0,0,e.thickness]));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u]}}function j8(t,e,n){let c=L2(e,t.shaft),r=F4(c);if(!r)return c1("The shaft must have a nonzero cylindrical physical envelope.");let a=[...t.bearings,...t.stack],s=a.map(x=>JSON.stringify([x.part,x.copy??1]));if(new Set(s).size!==s.length)return Q1("Bearing and stack references must name distinct physical parts.");let i=a.map(x=>Z0(e,x)),o=P6(...i);if(o)return c1(o);let l={shaftDiameter:r.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],w=Qi(r,M);if(typeof w=="string")return/unsupported|supported/.test(w)?c1(`${M.name}: ${w}`):Q1(`${M.name}: ${w}`);let k=$4(n,M);if(!k.every(Number.isFinite))return c1("Kerf metadata is required for bore tolerance bounds.");let z=[w.hole[0]-k[1]-r.diameter,w.hole[1]-k[0]-r.diameter];if(l[`clearance${x+1}`]=z,A6(z,t.clearance))return Q1(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!L6(z,t.clearance)),w.lo<-B||w.lo+O5(n,M)[1]>r.length+B)return Q1(`${M.name}: the shaft does not extend through this part.`,l);h.push(w)}let f=h.slice(0,2).sort((x,M)=>x.lo-M.lo),d=h.slice(2).sort((x,M)=>x.lo-M.lo);if(f.some(x=>O5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>B)))return c1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-B)return Q1("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-B||d[x].hi>f[1].lo+B||x&&d[x-1].hi>d[x].lo+B)return Q1("The axial stack overlaps another component or its supports.");let p=f[1].lo-f[0].lo,g=[f[0].part,...d.map(x=>x.part)].map(x=>O5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[p-g[1],p-g[0]];if(l.endplay=v,A6(v,t.endplay))return Q1("The axial stack has insufficient or excessive endplay.",l);u||(u=!L6(v,t.endplay));let y=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],b=t.stops.map(x=>({stop:x,h:L2(e,x.body)})).map(x=>({...x,at:x.h&&k6(r,x.h)?S6(r,x.h):void 0}));if(b.some(x=>!x.at))return Q1("A retainer is not coaxial with the shaft.");b.sort((x,M)=>x.at[0]+x.at[1]-(M.at[0]+M.at[1]));for(let x=0;x<2;x++){let{stop:M,h:w}=b[x];if(!k6(r,w))return Q1("A retainer is not coaxial with the shaft.");let k=F4(w),z=S6(r,w),S=f[x],L=x===0?z[1]:z[0],I=x===0?S.lo:S.hi,q=x===0?I-L:L-I;l[`stopGap${x+1}`]=q;let R=$4(n,S.part),N=(k.diameter-(S.hole[1]-R[0]))/2;if(l[`stopOverlap${x+1}`]=N,q<-B||q>t.maximumStopGap+B)return Q1("A retainer is misplaced relative to the outside bearing face.",l);if((q<-1e-7||q>t.maximumStopGap+1e-7)&&(u=!0),N<t.minimumOverlap-B)return Q1("A retainer can pass through its bearing opening.",l);N<t.minimumOverlap+B&&(u=!0);let G=M.attachment;if(G.kind==="unknown")return{...c1("The stop is present but its fastening is unverified."),measurements:l};if(G.kind==="integral"){if(Math.min(Math.abs(L),Math.abs(L-r.length))>B)return Q1("An integral head must meet an end of its shaft.",l);y.push("The specified head and shaft are one integral purchased component.")}else{let V=L2(e,G.thread);if(!k6(r,V))return Q1("The threaded attachment is off the shaft axis.");if(F4(V).diameter>r.diameter+B)return Q1("The declared threaded section exceeds the shaft envelope.");let J=S6(r,V),o1=Math.max(0,Math.min(z[1],J[1])-Math.max(z[0],J[0]));if(J[0]<-B||J[1]>r.length+B)return Q1("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=o1,o1<G.minimumEngagement-B)return Q1("The threaded stop has insufficient declared thread engagement.",l);if(o1<G.minimumEngagement+B&&(u=!0),!G.secured)return{...c1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};y.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?{...c1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:C6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>R5(n,x))?"bounded-fit":"nominal")}var N4=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},u1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),E0=(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]],y0=(t,e)=>t.map(n=>n*e),Z8=(t,e)=>t.map((n,c)=>n+e[c]),j1=t=>y0(t,1/M1(t)),Y8=()=>R0(0,0,0);function T6(t,e){let n=c=>c.kind==="translate"?M1(c.by)<1e-9:Math.abs(c.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?M1(m1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?M1(m1(y0(j1(t.axis),t.angle),y0(j1(e.axis),e.angle)))<1e-9&&M1(E0(m1(t.origin,e.origin),j1(t.axis)))<1e-9:!1}function eo(t,e){let n=new Map;for(let c of e)for(let r=0;r<c.length;r++){let a=c[r],s=c[(r+1)%c.length],i=a<s?[a,s]:[s,a];n.set(i.join(","),i)}return{vertices:t,faces:e,edges:[...n.values()]}}function Y3(t,e,n){let c=t.length,r=[];for(let a of[0,e])for(let[s,i]of t)r.push(i0(n,[s,i,a]));return eo(r,[t.map((a,s)=>s).reverse(),t.map((a,s)=>c+s),...t.map((a,s)=>[s,(s+1)%c,(s+1)%c+c,s+c])])}function to(t,e){let n=x1(t),c=[...new Set(n.flat().map(i=>i[0]))].sort((i,o)=>i-o),r=n.flatMap(i=>i.map((o,l)=>({a:o,b:i[(l+1)%i.length]}))),a=[],s=(i,o)=>i.a[1]+(o-i.a[0])*(i.b[1]-i.a[1])/(i.b[0]-i.a[0]);for(let i=1;i<c.length;i++){let o=c[i-1],l=c[i],h=(o+l)/2;e.tick(r.length);let u=r.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(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],p=u[f+1],m=[[o,s(d,o)],[l,s(d,l)],[l,s(p,l)],[o,s(p,o)]],g=m.filter((v,y)=>M1([v[0]-m[(y+1)%m.length][0],v[1]-m[(y+1)%m.length][1],0])>1e-10);if(g.length<3||Math.abs(d3(g))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(a.push(g),a.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!a.length||Math.abs(Y2(a)-Y2(n))>B*B*Math.max(1,Y2(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function v3(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(u1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function F5(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 c0(t,e){if("part"in e)return Z0(t,e).matrix;let n=L2(t,e),[c,r]=F5(n),a={...n,from:c,to:r},s=j1(m1(a.to,a.from));if(!M1(m1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let i=m1(a.up,y0(s,J1(a.up,s)));if(M1(i)<1e-9){if(Array.isArray(a.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(s[0])<.8?[1,0,0]:[0,1,0];i=m1(l,y0(s,J1(l,s)))}i=j1(i);let o=E0(i,s);return[o[0],i[0],s[0],a.from[0],o[1],i[1],s[1],a.from[1],o[2],i[2],s[2],a.from[2],0,0,0,1]}function K2(t,e,n){if(n.tick(),"part"in e){let h=Z0(t,e),u=X3(h);if(u)throw new Error(u);let d=to(h.regions,n).map(p=>Y3(p,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let c=L2(t,e),r=c0(t,e),[a,s]=F5(c),i=M1(m1(s,a));if(i<B)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(c.size)){let[h,u]=c.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[Y3(f,i,r)];return{ref:e,outer:d,inner:d}}let o=32,l=h=>Array.from({length:o},(u,f)=>[h*Math.cos(f*2*Math.PI/o),h*Math.sin(f*2*Math.PI/o)]);if(c.shape==="ball"){let h=c.size/2,u=h/Math.SQRT2,f=R0(0,0,h-u);return{ref:e,inner:[Y3(l(u),2*u,O1(r,f))],outer:[Y3(l(h/Math.cos(Math.PI/o)),i,r)]}}return{ref:e,inner:[Y3(l(c.size/2),i,r)],outer:[Y3(l(c.size/2/Math.cos(Math.PI/o)),i,r)]}}function U4(t,e){let n=r=>r.map(a=>({...a,vertices:a.vertices.map(s=>i0(e,s))})),c=n(t.outer);return{ref:t.ref,outer:c,inner:t.inner===t.outer?c:n(t.inner)}}function y3(t,e){if(t.kind==="translate")return R0(...y0(t.by,e));let[n,c,r]=j1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),i=Math.sin(a),o=1-s,l=[s+n*n*o,n*c*o-r*i,n*r*o+c*i,0,c*n*o+r*i,s+c*c*o,c*r*o-n*i,0,r*n*o-c*i,r*c*o+n*i,s+r*r*o,0,0,0,0,1];return O1(R0(...t.origin),O1(l,R0(...y0(t.origin,-1))))}function E6(t,e){if(e.kind==="translate")return M1(e.by);let n=j1(e.axis),c=0;for(let r of t.outer)for(let a of r.vertices){let s=m1(a,e.origin);c=Math.max(c,M1(m1(s,y0(n,J1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*c}function W8(t){return t.faces.map(e=>E0(m1(t.vertices[e[1]],t.vertices[e[0]]),m1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>M1(e)>1e-12).map(j1)}function J8(t,e){let n=[...W8(t),...W8(e)];for(let[c,r]of t.edges)for(let[a,s]of e.edges){let i=E0(m1(t.vertices[r],t.vertices[c]),m1(e.vertices[s],e.vertices[a]));M1(i)>1e-12&&n.push(j1(i))}return n}var J3=(t,e)=>{let n=t.vertices.map(c=>J1(c,e));return[Math.min(...n),Math.max(...n)]};function no(t,e,n){let c=-1/0;for(let r of J8(t,e)){n.tick();let a=J3(t,r),s=J3(e,r);c=Math.max(c,s[0]-a[1],a[0]-s[1])}return c}function co(t,e){let n=0;for(let c=0;c<3;c++){let r=t.vertices.map(i=>i[c]),a=e.vertices.map(i=>i[c]),s=Math.max(0,Math.min(...a)-Math.max(...r),Math.min(...r)-Math.max(...a));n+=s*s}return Math.sqrt(n)}function ro(t,e,n,c){let r=m1(n,e),a=m1(c,e),s=m1(t,e),i=J1(r,s),o=J1(a,s);if(i<=0&&o<=0)return M1(s);let l=m1(t,n),h=J1(r,l),u=J1(a,l);if(h>=0&&u<=h)return M1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return M1(m1(s,y0(r,i/(i-h))));let d=m1(t,c),p=J1(r,d),m=J1(a,d);if(m>=0&&p<=m)return M1(d);let g=p*o-i*m;if(g<=0&&o>=0&&m<=0)return M1(m1(s,y0(a,o/(o-m))));let v=h*m-p*u;if(v<=0&&u-h>=0&&p-m>=0)return M1(m1(l,y0(m1(c,n),(u-h)/(u-h+p-m))));let y=v+g+f;if(Math.abs(y)<1e-20)return 1/0;let b=Math.max(0,Math.min(1,g/y)),x=Math.max(0,Math.min(1-b,f/y));return M1(m1(s,Z8(y0(r,b),y0(a,x))))}function ao(t,e,n,c){let r=m1(e,t),a=m1(c,n),s=m1(t,n),i=J1(r,r),o=J1(r,a),l=J1(a,a),h=J1(r,s),u=J1(a,s);if(i<1e-20||l<1e-20)return 1/0;let f=i*l-o*o,d=f>1e-20?Math.max(0,Math.min(1,(o*u-l*h)/f)):0,p=(o*d+u)/l;return p<0&&(p=0,d=Math.max(0,Math.min(1,-h/i))),p>1&&(p=1,d=Math.max(0,Math.min(1,(o-h)/i))),M1(Z8(s,m1(y0(r,d),y0(a,p))))}function so(t,e,n){let c=1/0;for(let[r,a]of[[t,e],[e,t]])for(let s of r.vertices)for(let i of a.faces)for(let o=1;o<i.length-1;o++)n.tick(),c=Math.min(c,ro(s,a.vertices[i[0]],a.vertices[i[o]],a.vertices[i[o+1]]));for(let[r,a]of t.edges)for(let[s,i]of e.edges)n.tick(),c=Math.min(c,ao(t.vertices[r],t.vertices[a],e.vertices[s],e.vertices[i]));return c}function X8(t,e,n,c){let r=1/0,a=1/0,s=!1,i=!0;for(let o of t)for(let l of e){n.tick();let h=co(o,l);if(h>Math.min(a,c)){r=Math.min(r,h);continue}let u=no(o,l,n);u<-B&&(s=!0),u<0&&(i=!1),r=Math.min(r,Math.max(0,h,u)),u<-B?a=0:u<=Math.min(a,c)&&(a=Math.min(a,so(o,l,n)))}return{lower:r,upper:a,penetration:s,touchSafe:i}}function B4(t,e,n,c){let r=X8(t.outer,e.outer,n,c+B),a=t.outer===t.inner&&e.outer===e.inner;if(r.lower>c+B)return{lower:r.lower-B,upper:1/0,penetration:!1,touchSafe:!0};let s=a?r:X8(t.inner,e.inner,n,1/0);return{lower:Math.max(0,r.lower-B),upper:s.upper+B,penetration:s.penetration,touchSafe:r.touchSafe}}function K8(t,e,n,c,r,a){for(let s=0;s<t.outer.length;s++)for(let i=0;i<n.outer.length;i++){let o=t.outer[s],l=n.outer[i],h=e.outer[s],u=c.outer[i],f=!1;for(let d of J8(o,l)){a.tick();let p=J3(o,d),m=J3(l,d),g=J3(h,d),v=J3(u,d);if(Math.min(m[0]-p[1],v[0]-g[1])>=r||Math.min(p[0]-m[1],g[0]-v[1])>=r){f=!0;break}}if(!f)return!1}return!0}function _4(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let c={part:n.name,copy:n.copy},r=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(r>1&&(n.copy-1)%r!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:c,faceA:a?"bottom":"top",faceB:a?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:c,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var p2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),$5=(t,e)=>t.every((n,c)=>Math.abs(n-e[c])<B);function Q8(t,e,n){if(new Set(e.map(u1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(c=>K2(t,c,n))}function en(t,e,n){let c=Q8(e,t.bodies??v3(e),n);if(c.length<2)return c1("Rigid clearance requires at least two physical bodies.");let r=1/0;for(let a=0;a<c.length;a++)for(let s=a+1;s<c.length;s++){let i=B4(c[a],c[s],n,t.minimumGap);if(r=Math.min(r,i.lower),i.penetration||i.upper<t.minimumGap-B)return p2("Physical bodies interfere or violate the required clearance.",{gapUpper:i.upper},[c[a].ref,c[s].ref]);if(!(i.lower>t.minimumGap||t.minimumGap===0&&i.touchSafe))return{...c1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[c[a].ref,c[s].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:r},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function I6(t,e,n,c,r=1e3){let a=o=>({solid:o,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let o=0;o<t.length;o++){for(let l of e)yield{a:t[o],b:a(l)};for(let l=o+1;l<t.length;l++)yield{a:t[o],b:t[l]}}}let i=0;for(let{a:o,b:l}of s()){c.tick();let h=(d,p)=>U4(d.solid,y3(d.trajectory,p));if(T6(o.trajectory,l.trajectory)){let d=B4(o.solid,l.solid,c,n);if(d.penetration||d.upper<n-B)return p2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[o.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...c1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&K8(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+B,c))continue;let u=E6(o.solid,o.trajectory)+E6(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>r)return{...c1("Continuous clearance interval budget exhausted."),measurements:{intervals:i},entities:[o.solid.ref,l.solid.ref]};c.tick();let[d,p]=f.shift(),m=(d+p)/2,g=u*(p-d)/2,v=B4(h(o,m),h(l,m),c,n+g);if(v.penetration||v.upper<n-B)return p2("The specified path has physical interference.",{phase:m,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(p-d<1e-9)return{...c1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,p]},entities:[o.solid.ref,l.solid.ref]};f.push([d,m],[m,p])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function io(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 c=e.parts.find(r=>r.name===n.name&&r.copy===n.copy);if(!c||n.cutLines===null||c.cutLines===null||!O4(n,c))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([c.stack,c.glue,c.glueFace,c.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let c=e.hardware.find(r=>r.label===n.label);if(!n.label||!c||n.kind!==c.kind||JSON.stringify(n.size)!==JSON.stringify(c.size)||Math.abs(M1(m1(n.to,n.from))-M1(m1(c.to,c.from)))>B)return"Hardware identities and dimensions must remain invariant."}return null}function tn(t,e,n,c,r=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return c1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=io(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=v3(e),i=new Set(t.moving.map(l=>u1(l.body)));if(i.size!==t.moving.length)return p2("A body has conflicting simultaneous trajectories.");let o=l=>t.moving.find(h=>u1(h.body)===u1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[..._4(e),...r]){let h=O1(L0(c0(e,l.a)),c0(e,l.b)),u=O1(L0(c0(n,l.a)),c0(n,l.b));if(!$5(h,u)||!T6(o(l.a),o(l.b)))return p2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>u1(f.body)===u1(l))?.trajectory,u=h?y3(h,1):Y8();if("part"in l){if(!$5(O1(u,c0(e,l)),c0(n,l)))return p2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=L2(e,l),d=L2(n,l);if(typeof f.size=="number"){if(!$5(i0(u,f.from),d.from)||!$5(i0(u,f.to),d.to))return p2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!$5(O1(u,c0(e,l)),c0(n,l)))return p2("A box trajectory does not match its rendered destination.",{},[l])}}return I6(t.moving.map(l=>({solid:K2(e,l.body,c),trajectory:l.trajectory})),Q8(e,s.filter(l=>!i.has(u1(l))),c),t.minimumGap,c,t.maxIntervals)}function nn(t,e,n){let c=t.scope??v3(e),r=new Set(c.map(u1)),a=new Map(t.initial.map(o=>[u1(o),K2(e,o,n)]));if(r.size!==c.length||a.size!==t.initial.length||t.initial.some(o=>!r.has(u1(o))))return p2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,i=0;for(let o of t.steps){if(s.has(o.id)||!r.has(u1(o.part))||a.has(u1(o.part)))return p2("An assembly step duplicates or misidentifies a required installation.");if(s.add(o.id),!o.held)return{...c1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=K2(e,o.part,n),h=U4(l,y3({kind:"translate",by:o.from},1)),u=I6([{solid:h,trajectory:{kind:"translate",by:o.from.map(f=>-f)}}],[...a.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:o.id,message:`Assembly step ${o.id}: ${u.message}`};if(i+=u.measurements?.intervals??0,a.set(u1(o.part),l),o.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:o.tool.from,to:o.tool.to,size:o.tool.diameter,up:[0,1,0]}]},p=K2(d,{hardware:f},n),m=U4(p,y3({kind:"translate",by:o.tool.travel},1)),g=I6([{solid:m,trajectory:{kind:"translate",by:o.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:o.id,message:`Tool access at step ${o.id}: ${g.message}`}}}return a.size!==r.size?p2("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:a.size,intervals:i},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 K1=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),B0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),$0=t=>[t[3],t[7],t[11]],V6=t=>{let e=j1(t),n=j1(E0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,E0(e,n)]},G4=(t,e,n)=>{let c=V6(n)[0],r=j1(B0(e,c)),a=j1(B0(t,c)),s=j1(B0(e,n));return Math.atan2(J1(s,E0(r,a)),J1(r,a))*180/Math.PI},cn=(t,e,n)=>{let c=[],r=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let i=r;i<=a&&c.length<64;i++)c.push(t+360*i);let s=(e[0]+e[1])/2;return c.sort((i,o)=>Math.abs(i-s)-Math.abs(o-s))};function rn(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(c=>c.body)];for(let c of t.stops)c.attachment.kind==="threaded"&&n.push(c.attachment.thread);return n}}function an(t,e,n,c){let r=v3(e),a=new Set(r.map(u1));for(let f of t.removable??[])a.delete(u1(f));if(t.roots.some(f=>!a.has(u1(f))))return K1("A retention root cannot be excluded as removable.");let s=new Map,i=f=>{for(let d of f)for(let p of f){let m=u1(d),g=s.get(m)??new Set;g.add(u1(p)),s.set(m,g)}},o=["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),p=c.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!p)return c1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(p.status==="fail")return K1(`Attachment ${f.claim} fails its geometric contract.`);if(p.status!=="pass")return c1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return K1(`The fastening for ${f.claim} is explicitly not installed.`);let m=rn(d,f.fastening);if(!m)return c1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(m),d.kind==="glue-contact"&&o.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(u1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=r.filter(f=>a.has(u1(f))&&!l.has(u1(f)));return u.length?{...K1("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:a.size,removableComponents:t.removable?.length??0},assumptions:o}}function oo(t,e){if("hardware"in e){let i=c0(t,e),o=t.hardware.find(l=>l.label===e.hardware);return i0(i,[0,0,M1(m1(F5(o)[1],F5(o)[0]))/2])}let n=Z0(t,e),c=X3(n);if(c)throw new Error(c);let r=0,a=0,s=0;for(let i of n.regions){let[o,l]=i[0],h=0,u=0,f=0;for(let p=0;p<i.length;p++){let m=i[p],g=i[(p+1)%i.length],v=m[0]-o,y=m[1]-l,b=g[0]-o,x=g[1]-l,M=v*x-b*y;h+=M,u+=(v+b)*M,f+=(y+x)*M}if(Math.abs(h)<1e-12)continue;let d=d3(i);r+=d,a+=(o+u/(3*h))*d,s+=(l+f/(3*h))*d}if(r<=B*B)throw new Error("Material centroid is numerically unresolved.");return i0(n.matrix,[a/r,s/r,n.thickness/2])}function lo(t){let e=[...t].sort((s,i)=>s[0]-i[0]||s[1]-i[1]),n=(s,i,o)=>(i[0]-s[0])*(o[1]-s[1])-(i[1]-s[1])*(o[0]-s[0]),c=s=>{let i=[];for(let o of s){for(;i.length>1&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return i},r=c(e),a=c([...e].reverse());return[...r.slice(0,-1),...a.slice(0,-1)]}function ho(t,e,n){let c=new Map,r=i=>{for(let o of i)for(let l of i){let h=c.get(u1(o))??new Set;h.add(u1(l)),c.set(u1(o),h)}};for(let i of t.links){let o=rn(e.claims.find(l=>l.id===i.claim),i.fastening);o&&r(o)}if(!n.length)return!0;let a=new Set([u1(n[0])]),s=[...a];for(;s.length;)for(let i of c.get(s.pop())??[])a.has(i)||(a.add(i),s.push(i));return n.every(i=>a.has(u1(i)))}function sn(t,e,n,c=[],r){let a=v3(e),s=t.loads.map(m=>u1(m.body));if(new Set(s).size!==s.length||a.some(m=>!s.includes(u1(m))))return c1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let m=c.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=r?.claims.find(v=>v.id===t.retention);if(!m||m.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return c1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!ho(g,r,a))return c1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let i=0,o=[0,0,0];for(let m of t.loads){let g=m.center?i0(c0(e,m.body),m.center):oo(e,m.body);i+=m.mass,o=o.map((v,y)=>v+m.mass*g[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return c1("Mass/centroid calculation exceeds its numerical range.");o=y0(o,1/i);let l=[];for(let m of a){let g=K2(e,m,n),v=Math.min(...g.inner.flatMap(b=>b.vertices.map(x=>x[2]))),y=Math.min(...g.outer.flatMap(b=>b.vertices.map(x=>x[2])));if(v<t.ground-B)return K1("A physical component penetrates the ground plane.");if(y<t.ground-B)return c1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(b=>u1(b)===u1(m))){if(Math.abs(v-t.ground)>1e-8)return c1("Ground contact is separated or within physical-envelope uncertainty.");for(let b of g.inner)for(let x of b.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=lo(l);if(h.length<3)return c1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-o[2])/t.gravity[2],f=[o[0]+u*t.gravity[0],o[1]+u*t.gravity[1]],d=1/0;for(let m=0;m<h.length;m++){let g=h[m],v=h[(m+1)%h.length],y=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),b=W3(f,g,v);d=Math.min(d,y<0?-b:b)}let p={supportMargin:d,mass:i,centerX:o[0],centerY:o[1],centerZ:o[2]};return d<t.minimumMargin-B?K1("The gravity line lies outside the required support margin.",p):d<t.minimumMargin+B?{...c1("Stability is on its numerical support boundary."),measurements:p}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:p,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 on(t,e,n,c){let r=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>c.find(p=>p.id===d&&p.configurations.includes(e.configuration));if(!r||r.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return c1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return c1("Per-step support of removable objects needs an explicit contact model.");let i=new Set(a.roots.map(u1)),o=new Set(r.initial.map(u1));if(r.initial.some(d=>!i.has(u1(d))))return c1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let p=n.claims.find(m=>m.id===d.claim);if(p?.kind==="glue-contact")l.set(d.claim,[p.a,p.b]);else if(p?.kind==="captured-shaft"){let m=[p.shaft,...p.bearings,...p.stack,...p.stops.map(g=>g.body)];p.stops.forEach(g=>{g.attachment.kind==="threaded"&&m.push(g.attachment.thread)}),l.set(d.claim,m)}}let h=new Set,u=new Set(r.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 K1("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 y of l.get(g)??[]){let b=d.get(u1(v))??new Set;b.add(u1(y)),d.set(u1(v),b)}let p=new Set([...i].filter(g=>o.has(g))),m=[...p];for(;m.length;)for(let g of d.get(m.pop())??[])p.has(g)||(p.add(g),m.push(g));return p};for(let d of r.steps){o.add(u1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return K1(`Step ${d.id} names an unknown fastening.`);if(v.some(y=>!o.has(u1(y))))return K1(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let p=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(u1));if([...p].some(g=>!o.has(g)))return K1(`Step ${d.id} holds an uninstalled body.`);let m=f();if([...o].some(g=>!m.has(g)&&!p.has(g)))return K1(`Step ${d.id} releases a component before it is retained or supported.`)}return[...o].some(d=>!f().has(d))?K1("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 uo(t){let e=t.map(r=>{let a=Math.max(...r.map(Math.abs),1e-20);return r.map(s=>s/a)}),n=0,c=!1;for(let r=0;r<(e[0]?.length??0)&&n<e.length;r++){let a=n;for(let o=n+1;o<e.length;o++)Math.abs(e[o][r])>Math.abs(e[a][r])&&(a=o);let s=Math.abs(e[a][r]);if(s<1e-10)continue;s<1e-7&&(c=!0),[e[n],e[a]]=[e[a],e[n]];let i=e[n][r];for(let o=r;o<e[n].length;o++)e[n][o]/=i;for(let o=n+1;o<e.length;o++){let l=e[o][r];for(let h=r;h<e[o].length;h++)e[o][h]-=l*e[n][h]}n++}return{rank:n,uncertain:c}}function ln(t,e,n,c,r,a=[]){if(t.bodies.length>64)return c1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(u1),i=t.roots.map(u1);if(new Set(s).size!==s.length||new Set(i).size!==i.length||i.some(v=>!s.includes(v)))return K1("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>c0(e,v).some((y,b)=>Math.abs(y-c0(n,v)[b])>B)))return K1("A grounded kinematic root changes pose.");let o=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,y,b,x,M=1)=>{let w=s.indexOf(u1(y));if(w<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[w*6+b+k]+=M*x[k]};for(let v of t.roots)for(let y=0;y<6;y++){let b=h();b[s.indexOf(u1(v))*6+y]=1,o.push(b)}let f=_4({...e,parts:e.parts.filter(v=>s.includes(u1({part:v.name,copy:v.copy})))});for(let v of r?.claims??[])if(v.kind==="retention")for(let y of v.links){let b=r.claims.find(x=>x.id===y.claim);y.installed&&y.fastening==="glued"&&b?.kind==="glue-contact"&&a.some(x=>x.id===b.id&&x.configurations.includes(e.configuration)&&x.status==="pass")&&f.push({a:b.a,b:b.b})}for(let v of f)if(!(!s.includes(u1(v.a))&&!s.includes(u1(v.b)))){if(!s.includes(u1(v.a))||!s.includes(u1(v.b)))return c1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=q4({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:B*B*4},e);if(y.status!=="pass")return{...y,message:`A native glue/stack bond is not physically established: ${y.message}`}}}let d=[...t.joints,...f.filter(v=>s.includes(u1(v.a))&&s.includes(u1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(c.tick(),u1(v.a)===u1(v.b))return K1("A joint cannot connect a body to itself.");let y=c0(e,v.a),b=c0(e,v.b),x=c0(n,v.a),M=c0(n,v.b),w=O1(L0(y),b),k=O1(L0(x),M),z=L=>{let I=h();u(I,v.b,3,L),u(I,v.a,3,L,-1),o.push(I)},S=(L,I,q)=>{let R=h();u(R,v.b,0,L),u(R,v.a,0,L,-1),u(R,v.b,3,E0(q,L)),u(R,v.a,3,E0(I,L),-1),o.push(R)};if(v.kind==="fixed"){if(w.some((L,I)=>Math.abs(L-k[I])>B))return K1("A fixed joint changes its relative transform.");l.forEach(L=>z(L)),l.forEach(L=>S(L,m1($0(b),$0(y)),[0,0,0]))}else if(v.kind==="revolute"){let L=i0(y,v.anchorA),I=i0(b,v.anchorB),q=j1(B0(y,v.axisA)),R=j1(B0(b,v.axisB)),N=J1(j1(B0(x,v.axisA)),j1(B0(M,v.axisB)));if(M1(m1(L,I))>B||M1(E0(q,R))>1e-7||Math.abs(J1(q,R)-N)>1e-7)return K1("Revolute anchors or axes do not coincide.");if(v.range){let G=G4(w,k,v.axisB);if(!cn(G,v.range,B).length)return K1("A revolute joint exceeds its declared angular travel.",{angle:G})}l.forEach(G=>S(G,m1(L,$0(y)),m1(I,$0(b)))),V6(q).forEach(z)}else if(v.kind==="prismatic"){let L=m1($0(w),$0(k)),I=j1(v.axisA),q=J1(L,I);if([0,1,2,4,5,6,8,9,10].some(R=>Math.abs(w[R]-k[R])>B)||M1(m1(L,y0(I,q)))>B)return K1("A slider rotates or moves away from its guide axis.");if(q<v.travel[0]-B||q>v.travel[1]+B)return K1("The slider exceeds its allowed travel.",{travel:q});l.forEach(z),V6(j1(B0(y,v.axisA))).forEach(R=>S(R,m1($0(b),$0(y)),[0,0,0]))}else{let L=j1(B0(y,v.axisA)),I=j1(B0(b,v.axisB));if(M1(E0(L,I))>1e-7||M1(m1($0(y),$0(x)))>B||M1(m1($0(b),$0(M)))>B)return K1("The scoped gear axes/centers are not fixed and parallel.");let q=G4(y,x,v.axisA),R=G4(b,M,v.axisB);if(Math.abs(q)>90||Math.abs(R)>90)return c1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(R+v.ratio*q)>1e-6)return K1("The rendered gears do not obey their declared angular ratio.");let N=h();u(N,v.a,3,L,v.ratio),u(N,v.b,3,I),o.push(N)}}c.tick(o.length*s.length*6);let p=uo(o),m=s.length*6-p.rank;if(p.uncertain)return c1("Constraint rank is numerically singular.");let g={degreesOfFreedom:m,constraintRank:p.rank,redundantRows:o.length-p.rank};return m!==t.expectedDof?K1("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 hn(t,e,n,c){let r=o=>t.moving.find(l=>u1(l.body)===u1(o))?.trajectory??{kind:"translate",by:[0,0,0]},a=o=>o.kind==="translate"?M1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?M1(m1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?M1(m1(y0(j1(o.axis),o.angle),y0(j1(l.axis),l.angle)))<1e-9&&M1(E0(m1(o.origin,l.origin),j1(o.axis)))<1e-9:!1;if(e.roots.some(o=>!a(r(o))))return K1("The analytic path moves a grounded joint root.");let i=new Map;for(let o of e.joints.filter(l=>l.kind!=="gear")){if(i.has(u1(o.b)))return c1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");i.set(u1(o.b),u1(o.a))}for(let o of i.keys()){let l=new Set,h=o;for(;h&&i.has(h);){if(l.has(h))return c1("Continuous closed-linkage constraints need a solver.");l.add(h),h=i.get(h)}}for(let o of e.joints){let l=r(o.a),h=r(o.b),u=c0(n,o.a),f=c0(n,o.b);if(o.kind==="fixed"){if(!s(l,h))return K1("The analytic path separates a fixed joint.");continue}if(o.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return c1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=i0(u,o.anchorA),p=j1(B0(u,o.axisA)),m=j1(h.axis);if(M1(E0(p,m))>1e-9||M1(E0(m1(h.origin,d),p))>B)return K1("The trajectory does not rotate about the actual hinge.");if(o.range){let g=O1(L0(u),f),v=O1(L0(c0(c,o.a)),c0(c,o.b)),y=h.angle*J1(j1(B0(f,o.axisB)),m),b=o.range;if(!cn(G4(g,v,o.axisB),b,B).some(M=>Math.min(M,M+y)>=b[0]-B&&Math.max(M,M+y)<=b[1]+B))return K1("The continuous hinge path exceeds its angular stops.")}}else if(o.kind==="prismatic"){if(s(l,h))continue;if(!a(l)||h.kind!=="translate")return c1("This slider trajectory composition needs a richer constraint solver.");let d=j1(B0(u,o.axisA));if(M1(E0(h.by,d))>B)return K1("The analytic slider path leaves its guide.");let p=O1(L0(u),f),m=O1(L0(c0(c,o.a)),c0(c,o.b)),g=J1(m1($0(p),$0(m)),j1(o.axisA)),v=g+J1(h.by,d);if(Math.min(g,v)<o.travel[0]-B||Math.max(g,v)>o.travel[1]+B)return K1("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,y)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let b=c0(n,g),x=j1(B0(b,y));return M1(E0(j1(v.axis),x))>1e-9||M1(E0(m1(v.origin,$0(b)),x))>B?null:v.angle*J1(j1(v.axis),x)},p=d(o.a,l,o.axisA),m=d(o.b,h,o.axisB);if(p===null||m===null)return c1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(m+o.ratio*p)>1e-7)return K1("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 un(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return fn(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(c=>{let r=n?.parts.filter(l=>l.name===c.name),a=r?.length===1?r[0]:void 0,s=a?.glue?.host,o=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((c.copy-1)/(a?.stack??1))+1:1;return{name:c.name,copy:c.copy,thickness:c.thickness,material:c.material??"",matrix:c.matrix,placed:c.placed,regions:a?.cutRegions??c.outline,bends:c.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:o},glueFace:a.glue.face},...a?.on&&{on:a.on}}}),hardware:t.hardware.map(c=>({label:c.label??null,kind:c.kind,from:c.from,to:c.to,size:c.size,up:c.up,...c.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(c=>c.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function fn(t){if(t&&typeof t=="object"){for(let e of Object.values(t))fn(e);Object.freeze(t)}return t}function dn(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let c=H5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(c.length)throw new Error(c[0].message);let r=new Map;for(let a of e){let s=a.body,i=u1(s);if(("part"in s?t.assembly.filter(l=>l.name===s.part&&l.copy===(s.copy??1)).length:t.hardware.filter(l=>l.label===s.hardware).length)!==1||r.has(i))throw new Error("Pose controls must identify one unique physical instance each.");r.set(i,y3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=r.get(u1({part:a.name,copy:a.copy}));return s?{...a,matrix:O1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},i=r.get(u1(s));return i?{...a,from:i0(i,a.from),to:i0(i,a.to),up:m1(i0(i,a.up),i0(i,[0,0,0]))}:a})}}function fo(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==B||H5(e).length||z6(n).length||n.some(r=>r.error!==void 0||!r.provenance)||!Array.isArray(t.inputs))return!1;let c=r=>JSON.stringify(r,(a,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.fromEntries(Object.keys(s).sort().map(i=>[i,s[i]])):s);try{let r=n.map(s=>({configuration:s.configuration,params:s.params,renderSettings:s.renderSettings,provenance:s.provenance})),a=s=>[...s].sort((i,o)=>i.configuration.localeCompare(o.configuration));return c(e)===c(t.specification)&&c(a(r))===c(a(t.inputs))}catch{return!1}}function po(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 c=H5(t);if(c.length)return{kind:"invalid-spec",issues:c};let r=z6(e);if(r.length)return{kind:"invalid-snapshot",issues:r};let a=t,s=e,i=[];for(let[g,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(g)||!Number.isSafeInteger(v)||!(v>0))&&i.push({code:"invalid-limits",path:`limits.${g}`,message:"Verification limits must be positive safe integers."});if(i.length)return{kind:"invalid-spec",issues:i};let o={schemaVersion:1,model:a.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:B,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.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(s.reduce((g,v)=>g+v.hardware.reduce((y,b)=>y+(typeof b.size=="number"?128:8),0)+v.parts.reduce((y,b)=>y+b.regions.reduce((x,M)=>x+M.length,0)+(b.cutLines??[]).reduce((x,M)=>x+M.length,0),0),0)>(n.maxPoints??2e5)||a.claims.length>(n.maxClaims??1e3)||a.configurations.length>(n.maxConfigurations??100))return o.claims.push(Q2("$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:o};let h=new Set(a.configurations.map(g=>g.id));for(let g of s)h.has(g.configuration)||i.push({code:"unknown-configuration",message:`Snapshot ${g.configuration} is not declared.`});for(let g of s){let v=a.configurations.find(y=>y.id===g.configuration)?.params??{};for(let[y,b]of Object.entries(v))JSON.stringify(g.params[y])!==JSON.stringify(b)&&i.push({code:"configuration-mismatch",message:`${g.configuration}: captured parameter ${y} differs from its required value.`})}let u=new Map(a.claims.map(g=>[g.id,g]));for(let{claim:g,ref:v}of _8(a)){let y=u.get(g);for(let b of s.filter(x=>x.error===void 0&&(!y.configurations||y.configurations.includes(x.configuration)))){let x="part"in v?b.parts.filter(M=>M.name===v.part&&M.copy===(v.copy??1)):b.hardware.filter(M=>M.label===v.hardware);x.length!==1&&i.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${b.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(i.length)return{kind:"invalid-spec",issues:i};for(let g of a.configurations){let v=s.find(b=>b.configuration===g.id),y=v&&v.error===void 0;o.claims.push(Q2(`$configuration:${g.id}`,"configuration",!0,[g.id],y?{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."})),y&&(o.claims.push(Q2(`$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&&o.claims.push(Q2(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
|
|
2644
|
-
`)})),v.legacyHardware&&
|
|
2645
|
-
`;let e=
|
|
2646
|
-
`;let n=
|
|
3103
|
+
}`)}return c}function zl(t,e,n){let r;try{r=new s3({maxSteps:2e6}).run(c2(t.check).program).shape}catch{return!1}let c=r.layers.get("cut");if(!c)return!1;let a=g0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=s1(c.regions),o=n+t.round*16e-5;if(!L3(a,s,o))return!1;let i=e.lines.map(l=>A3(l));return!(i.length&&!L3(i,c.lines,o,!1))}var W=.001,Q1=(t,e)=>t.reduce((n,r,c)=>n+r*e[c],0),y1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],P1=t=>Math.hypot(...t),G8=t=>[t[2],t[6],t[10]],u0=(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]),Jt=(t,e)=>D1(v0(t.matrix),e.matrix);function C3(t){let[e,n]=t[0],r=0;for(let c=1;c<t.length-1;c++)r+=(t[c][0]-e)*(t[c+1][1]-n)-(t[c][1]-n)*(t[c+1][0]-e);return r/2}var i3=t=>Math.abs(t.reduce((e,n)=>e+C3(n),0)),Kt=t=>t.reduce((e,n)=>e+n.reduce((r,c,a)=>r+Math.hypot(c[0]-n[(a+1)%n.length][0],c[1]-n[(a+1)%n.length][1]),0),0);function a4(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 W8=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function Qt(t){if(t.length!==1)return!1;let e=a4(t);return i3(m3(t,[W8(e)]))<W*W}var e6=(t,e)=>K1(t,[W8(e)]);function X8(t,e,n=0){let r=e[0]*e[5]-e[1]*e[4]<0;return t.map(c=>{let a=c.map(([s,o])=>u0(e,[s,o,n]).slice(0,2));return r?a.reverse():a})}function Sl(t,e){let n=!1;for(let r=0,c=t.length-1;r<t.length;c=r++){let[a,s]=t[r],[o,i]=t[c];s>e[1]!=i>e[1]&&e[0]<(o-a)*(e[1]-s)/(i-s)+a&&(n=!n)}return n}function i5(t,e,n){let r=n[0]-e[0],c=n[1]-e[1],a=r*r+c*c,s=a?Math.max(0,Math.min(1,((t[0]-e[0])*r+(t[1]-e[1])*c)/a)):0;return Math.hypot(t[0]-e[0]-s*r,t[1]-e[1]-s*c)}function Z8(t,e){let n=1/0;for(let r of t)for(let c=0;c<e.length;c++)n=Math.min(n,i5(r,e[c],e[(c+1)%e.length]));for(let r of e)for(let c=0;c<t.length;c++)n=Math.min(n,i5(r,t[c],t[(c+1)%t.length]));return n}var t6=(t,e)=>t.filter(n=>C3(n)<0&&Sl(n,e));function l5(t){return t.placed?t.bends.length?"Flexible or bent 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 Y8(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 s4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&_8(t.regions)===_8(e.regions)&&j8(t.cutLines)===j8(e.cutLines)}function _8(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,c=[r,[...r].reverse()].map(a=>{let s=0;for(let o=1;o<a.length;o++)(a[o][0]<a[s][0]||a[o][0]===a[s][0]&&a[o][1]<a[s][1])&&(s=o);return JSON.stringify([...a.slice(s),...a.slice(0,s)])});return JSON.stringify([Math.sign(C3(n)),c.sort()[0]])};return JSON.stringify(t.map(e).sort())}function j8(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),r=JSON.stringify([...e].reverse());return n<r?n:r}).sort())}var B1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),S0=t=>typeof t=="string"&&t.length>0,$2=t=>typeof t=="number"&&Number.isFinite(t),W2=t=>$2(t)&&t>=0,O2=t=>$2(t)&&t>0,P3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every($2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,T3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every($2),k2=t=>T3(t,3)&&t.every(e=>Math.abs(e)<=1e7),l3=t=>B1(t)&&S0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),o4=t=>B1(t)&&S0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),h5=t=>l3(t)||o4(t),G2=t=>Array.isArray(t)&&t.every(h5),E3=t=>k2(t)&&Math.hypot(...t)>1e-9,Al=t=>B1(t)&&(t.kind==="translate"&&k2(t.by)||t.kind==="rotate"&&k2(t.origin)&&E3(t.axis)&&$2(t.angle)&&Math.abs(t.angle)<=1e6),n6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),J8=t=>B1(t)&&Object.values(t).every(n6),Q8=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||$2(t)||Array.isArray(t)&&t.every(n=>Q8(n,e+1))),r6=t=>B1(t)&&Object.values(t).every(e=>Q8(e)),Ll=t=>t===null||B1(t)&&n6(t.sourceHash)&&n6(t.engineHash)&&J8(t.dependencies)&&J8(t.fonts);function Q5(t){let e=[],n=(s,o)=>e.push({code:"invalid-spec",path:s,message:o});if(!B1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let r=(s,o,i)=>{for(let l of Object.keys(s))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."),S0(t.model)||n("model","Give the model a nonempty name.");let c=new Set,a=(s,o)=>{if(!B1(s)){n(o,"Materials must map material names to measured profiles.");return}for(let[i,l]of Object.entries(s))(!i||!B1(l)||!P3(l.thickness,Number.MIN_VALUE)||!P3(l.kerf)||l.edgeError!==void 0&&!W2(l.edgeError)||l.lot!==void 0&&!S0(l.lot))&&n(`${o}.${i}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),B1(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[s,o]of t.configurations.entries())!B1(o)||!S0(o.id)||o.params!==void 0&&!r6(o.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):c.has(o.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(c.add(o.id),r(o,["id","params","materials"],`configurations[${s}]`),o.materials!==void 0&&a(o.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,o=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!B1(h)||!S0(h.id)||!S0(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),s.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."),s.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(p=>typeof p=="string"&&c.has(p)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!l3(h.a)||!l3(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!O2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!l3(h.tab)||!l3(h.receiver)||!T3(h.region,4)||h.region.some(p=>Math.abs(p)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!P3(h.clearance)||!W2(h.flushTolerance)||!W2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let p=h.stops;if(!o4(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(l3)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(l3)||!P3(h.clearance)||!P3(h.endplay)||!O2(h.minimumOverlap)||!W2(h.maximumStopGap)||!Array.isArray(p)||p.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let m of p){if(!B1(m)||!o4(m.body)||!B1(m.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}r(m,["body","attachment"],u+".stops");let g=m.attachment;r(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!o4(g.thread)||!O2(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":(!W2(h.minimumGap)||h.bodies!==void 0&&(!G2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!S0(h.from)||!c.has(h.from)||!S0(h.to)||!c.has(h.to)||h.from===h.to||!W2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(p=>B1(p)&&h5(p.body)&&Al(p.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&&!S0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!G2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!G2(h.scope)||!h.scope.length)||!W2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(p=>B1(p)&&S0(p.id)&&h5(p.part)&&k2(p.from)&&typeof p.held=="boolean"&&(p.fasten===void 0||Array.isArray(p.fasten)&&p.fasten.every(S0))&&(p.tool===void 0||B1(p.tool)&&k2(p.tool.from)&&k2(p.tool.to)&&O2(p.tool.diameter)&&p.tool.diameter<=1e6&&k2(p.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":(!G2(h.roots)||!h.roots.length||h.removable!==void 0&&!G2(h.removable)||!Array.isArray(h.links)||!h.links.every(p=>B1(p)&&S0(p.claim)&&["glued","locked","captured"].includes(p.fastening)&&typeof p.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!G2(h.bodies)||!h.bodies.length||!G2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(p=>B1(p)&&h5(p.a)&&h5(p.b)&&(p.kind==="fixed"||p.kind==="revolute"&&k2(p.anchorA)&&k2(p.anchorB)&&E3(p.axisA)&&E3(p.axisB)&&(p.range===void 0||P3(p.range,-1e6))||p.kind==="prismatic"&&E3(p.axisA)&&P3(p.travel,-1e6)||p.kind==="gear"&&E3(p.axisA)&&E3(p.axisB)&&O2(p.ratio)&&p.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!G2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!$2(h.ground)||Math.abs(h.ground)>1e7||!E3(h.gravity)||h.gravity[2]>=0||!W2(h.minimumMargin)||!h.loads.every(p=>B1(p)&&h5(p.body)&&O2(p.mass)&&(p.center===void 0||k2(p.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!S0(h.plan)||!S0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(p=>B1(p)&&S0(p.step)&&G2(p.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=(p,m,g)=>{B1(p)&&r(p,m,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[p,m]of h.moving.entries())B1(m)&&(d(m,["body","trajectory"],`${u}.moving[${p}]`),d(m.trajectory,B1(m.trajectory)&&m.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${p}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[p,m]of h.steps.entries())B1(m)&&(d(m,["id","part","from","held","fasten","tool"],`${u}.steps[${p}]`),d(m.tool,["from","to","diameter","travel"],`${u}.steps[${p}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[p,m]of h.joints.entries())B1(m)&&d(m,["kind","a","b",...m.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:m.kind==="prismatic"?["axisA","travel"]:m.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${p}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((p,m)=>d(p,["claim","fastening","installed"],`${u}.links[${m}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((p,m)=>d(p,["body","mass","center"],`${u}.loads[${m}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((p,m)=>d(p,["step","bodies"],`${u}.holds[${m}]`))}o||n("claims","At least one claim must be required.");let i=t.claims.filter(B1);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(m=>m.id===l.plan&&m.kind==="assembly-access"),f=i.find(m=>m.id===l.retention&&m.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(B1).map(m=>m.id)),p=new Set((Array.isArray(f?.links)?f.links:[]).filter(B1).map(m=>m.claim));if(Array.isArray(l.holds))for(let m of l.holds)B1(m)&&!d.has(m.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(m.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let m of u.steps)if(B1(m)&&Array.isArray(m.fasten))for(let g of m.fasten)p.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(m.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(B1(f)){let d=B1(f.body)?f.body:{},p=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(p)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(p)}}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)B1(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 c6(t){let e=[],n=(c,a)=>e.push({code:"invalid-snapshot",path:c,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let r=new Set;for(let[c,a]of t.entries()){let s=`snapshots[${c}]`;if(!B1(a)||a.schemaVersion!==1||!S0(a.configuration)||!r6(a.params)||!r6(a.renderSettings)||!Ll(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(i=>typeof i=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}r.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),r.add(a.configuration);let o=new Set;for(let[i,l]of a.parts.entries()){if(!B1(l)||!S0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!O2(l.thickness)||l.glue!==void 0&&(!l3(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!S0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!W2(l.kerf)||l.kerf>1e6)||!Cl(l.matrix)||typeof l.placed!="boolean"||!K8(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!K8(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>B1(u)&&$2(u.x0)&&$2(u.x1)&&u.x1>u.x0&&$2(u.angle))){n(`${s}.parts[${i}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);o.has(h)&&n(`${s}.parts[${i}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),o.add(h)}for(let[i,l]of a.hardware.entries())(!B1(l)||l.label!==null&&!S0(l.label)||typeof l.kind!="string"||!T3(l.from,3)||!T3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!k2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!O2(l.size))||!(O2(l.size)&&l.size<=1e6||T3(l.size,2)&&l.size.every(h=>O2(h)&&h<=1e6)))&&n(`${s}.hardware[${i}]`,"Malformed hardware geometry or label.")}return e}function K8(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>T3(r,2)&&r.every(c=>Math.abs(c)<=1e6)))}function Cl(t){if(!T3(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 c=0;c<3;c++){let a=e[r]*e[c]+e[4+r]*e[4+c]+e[8+r]*e[8+c];if(Math.abs(a-(r===c?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 e9(t){let e=[];for(let n of t.claims){let r=c=>e.push({claim:n.id,ref:c});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(c=>{r(c.body),c.attachment.kind==="threaded"&&r(c.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(r),n.kind==="motion-clearance"&&n.moving.forEach(c=>r(c.body)),n.kind==="assembly-access"&&(n.initial.forEach(r),n.scope?.forEach(r),n.steps.forEach(c=>r(c.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(c=>{r(c.a),r(c.b)})),n.kind==="stability"&&(n.supports.forEach(r),n.loads.forEach(c=>r(c.body))),n.kind==="assembly-support"&&n.holds?.forEach(c=>c.bodies.forEach(r))}return e}var o2=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),R2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var e0=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),i1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),l6=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),ne=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,te=(t,e)=>ne(t,e)?.thickness??[e.thickness,e.thickness];function u5(t,e){let n=ne(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 o6=(t,e)=>t[0]>=e[0]+W&&t[1]<=e[1]-W,i6=(t,e)=>t[0]<e[0]-W||t[1]>e[1]+W,h6=(...t)=>t.map(l5).find(Boolean);function l4(t,e){let n=o2(e,t.a),r=o2(e,t.b);if(n===r)return e0("A glue contact needs two different physical instances.");let c=h6(n,r);if(c)return i1(c);let a=Jt(n,r),s=t.faceA==="top"?n.thickness:0,o=t.faceB==="top"?r.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return e0("The selected faces are not parallel.");let i=Math.abs(a[11]+a[10]*o-s);if(i>W)return e0("The selected faces are separated.",{faceGap:i});if(i>1e-7)return i1("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*a[10]>-1+1e-7)return e0("The selected surfaces face the same way, rather than meeting.");let u=X8(r.regions,a,o),f=i3(K1(n.regions,u)),d=W*(Kt(n.regions)+Kt(u)),p={contactArea:f,requiredArea:t.minimumArea,faceGap:i,areaUncertainty:d};return f<t.minimumArea-d?e0("There is insufficient geometric glue contact.",p):f<t.minimumArea+d?{...i1("Contact area is on the numerical acceptance boundary."),measurements:p}:l6("The selected nominal faces have the required geometric contact.",p,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function t9(t,e,n){let r=o2(e,t.tab),c=o2(e,t.receiver);if(r===c)return e0("A tongue and its receiving panel must be different instances.");let a=h6(r,c);if(a)return i1(a);let s=Jt(c,r);if(!Y8(s)||Math.abs(s[10])>W)return i1("Only orthogonal tab/slot geometry is supported.");let o=e6(r.regions,t.region);if(!Qt(o))return i1("The selected tongue is not one solid rectangle.");let[i,l,h,u]=a4(o),f=4*W,d=W,m=[[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(P=>i3(e6(r.regions,P))>W*W).flatMap((P,F)=>P?[F]:[]);if(m.length>1)return i1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(m.length&&Math.abs(m[0]<2?s[8]:s[9])<.5)return i1("The tongue must join its parent along the insertion direction.");let g;if(m.length){let P=m[0],F=P<2?[P===0?i:h,(l+u)/2,0]:[(i+h)/2,P===2?l:u,0],j=u0(s,F)[2],_=(P<2?s[8]:s[9])*(P%2===0?-1:1);g={z:j,outward:_}}let v=[];for(let P of[i,h])for(let F of[l,u])for(let j of[0,r.thickness])v.push(u0(s,[P,F,j]));let b=[0,1,2].map(P=>Math.min(...v.map(F=>F[P]))),y=[0,1,2].map(P=>Math.max(...v.map(F=>F[P]))),x=t6(c.regions,[(b[0]+y[0])/2,(b[1]+y[1])/2]);if(!x.length)return e0("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!Qt([x[0]]))return i1("The receiving feature must be an unambiguous rectangular closed slot.");let w=x[0],M=a4([w]),k=u5(n,r),z=u5(n,c);if(![...k,...z].every(Number.isFinite))return i1("Compensated kerf metadata is needed for manufacturing bounds.");let A={},S=!1;for(let P=0;P<2;P++){let F=Math.abs(s[P*4+2])>.5,j=F?te(n,r):[y[P]-b[P]+k[0],y[P]-b[P]+k[1]],_=M[P+2]-M[P],Q=[_-z[1]-j[1],_-z[0]-j[0]];if(A[P?"clearanceY":"clearanceX"]=Q,i6(Q,t.clearance))return e0("Tab/slot clearance is outside the required range.",A);S||(S=!o6(Q,t.clearance));let H=b[P],B=y[P];F?s[P*4+2]>0?B+=j[1]-r.thickness:H-=j[1]-r.thickness:(H-=Math.max(0,k[1])/2,B+=Math.max(0,k[1])/2);let Y=Math.min(H-M[P],M[P+2]-B)-Math.max(0,z[1])/2;if(A[P?"minimumSideGapY":"minimumSideGapX"]=Y,Y<-W)return e0("The tongue is offset into the edge of its slot.",A);Y<W&&(S=!0)}let C=Math.max(0,-k[0])/2,I=te(n,c);if(t.flushTolerance>=I[0]-W)return i1("flushTolerance must be smaller than the receiving thickness.");let L=Math.max(0,Math.min(y[2]-C,I[1])-Math.max(b[2]+C,0)),T=I[1]-t.flushTolerance;if(A.engagement=L,A.requiredEngagement=T,L<=W)return e0("The tongue does not engage the receiving panel.",A);if(L<T-W)return e0("The tongue does not engage through the receiving panel.",A);if(L<T+W&&(S=!0),g&&(g.outward>0&&g.z<I[1]-W||g.outward<0&&g.z>W))return e0("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",A);let q=Math.min(...c.regions.filter(P=>P!==w).map(P=>Z8(w,P)))-Math.max(0,-z[0]);return A.minimumLigament=q,q<t.minimumLigament-W?e0("Too little material remains around the slot.",A):(q<t.minimumLigament+W&&(S=!0),S?{...i1("A fit condition is on its numerical acceptance boundary."),measurements:A}:l6("The rectangular tongue fits and engages its receiving slot.",A,["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."],ne(n,r)||ne(n,c)?"bounded-fit":"nominal"))}function ee(t){let e=y1(t.to,t.from),n=P1(e);return typeof t.size=="number"&&n>W?{start:t.from,dir:e.map(r=>r/n),length:n,diameter:t.size}:null}function a6(t,e){let n=ee(e);if(!n||P1([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=y1(n.start,t.start),c=Q1(r,t.dir);return P1(r.map((a,s)=>a-c*t.dir[s]))<W}var i4=(t,e)=>Q1(y1(e,t.start),t.dir),s6=(t,e)=>[i4(t,e.from),i4(t,e.to)].sort((n,r)=>n-r);function Pl(t,e){let n=G8(e.matrix);if(Q1(n,t.dir)<0||P1([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=u0(v0(e.matrix),t.start),c=[r[0],r[1]],a=t6(e.regions,c);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],o=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,i=[o.reduce((m,g)=>m+g[0],0)/o.length,o.reduce((m,g)=>m+g[1],0)/o.length];if(Math.hypot(i[0]-c[0],i[1]-c[1])>W)return"The shaft is not centered in the bore.";let l=s.map(m=>Math.hypot(m[0]-i[0],m[1]-i[1]));if(Math.max(...l)-Math.min(...l)>W)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((m,g)=>i5(c,m,s[(g+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-c[0],m[1]-c[1]))),f=i4(t,u0(e.matrix,[0,0,0])),d=i4(t,u0(e.matrix,[0,0,e.thickness])),p=Math.max(...e.regions.flatMap(m=>m.map(g=>Math.hypot(g[0]-c[0],g[1]-c[1]))));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u],reach:p}}function n9(t,e,n){let r=R2(e,t.shaft),c=ee(r);if(!c)return i1("The shaft must have a nonzero cylindrical physical envelope.");let a=[...t.bearings,...t.stack],s=a.map(M=>JSON.stringify([M.part,M.copy??1]));if(new Set(s).size!==s.length)return e0("Bearing and stack references must name distinct physical parts.");let o=a.map(M=>o2(e,M)),i=h6(...o);if(i)return i1(i);let l={shaftDiameter:c.diameter},h=[],u=!1;for(let M=0;M<o.length;M++){let k=o[M],z=Pl(c,k);if(typeof z=="string")return/unsupported|supported/.test(z)?i1(`${k.name}: ${z}`):e0(`${k.name}: ${z}`);let A=u5(n,k);if(!A.every(Number.isFinite))return i1("Kerf metadata is required for bore tolerance bounds.");let S=[z.hole[0]-A[1]-c.diameter,z.hole[1]-A[0]-c.diameter];if(l[`clearance${M+1}`]=S,i6(S,t.clearance))return e0(`${k.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!o6(S,t.clearance)),z.lo<-W||z.lo+te(n,k)[1]>c.length+W)return e0(`${k.name}: the shaft does not extend through this part.`,l);h.push(z)}let f=h.slice(0,2).sort((M,k)=>M.lo-k.lo),d=h.slice(2).sort((M,k)=>M.lo-k.lo);if(f.some(M=>te(n,M.part).some(k=>Math.abs(k-M.part.thickness)>W)))return i1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-W)return e0("Bearing panels overlap or leave no stack cavity.");for(let M=0;M<d.length;M++)if(d[M].lo<f[0].hi-W||d[M].hi>f[1].lo+W||M&&d[M-1].hi>d[M].lo+W)return e0("The axial stack overlaps another component or its supports.");let p=f[1].lo-f[0].lo,g=[f[0].part,...d.map(M=>M.part)].map(M=>te(n,M)).reduce((M,k)=>[M[0]+k[0],M[1]+k[1]],[0,0]),v=[p-g[1],p-g[0]];if(l.endplay=v,i6(v,t.endplay))return e0("The axial stack has insufficient or excessive endplay.",l);u||(u=!o6(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(M=>({stop:M,h:R2(e,M.body)})).map(M=>({...M,at:M.h&&a6(c,M.h)?s6(c,M.h):void 0}));if(y.some(M=>!M.at))return e0("A retainer is not coaxial with the shaft.");y.sort((M,k)=>M.at[0]+M.at[1]-(k.at[0]+k.at[1]));let x=M=>M.hole[1]-u5(n,M.part)[0],w=M=>2*M.reach+u5(n,M.part)[0];for(let M=0;M<2;M++){let k=Math.max(w(f[M]),ee(y[M].h)?.diameter??0),z=M===0?d.map((S,C)=>C):d.map((S,C)=>d.length-1-C),A=[];for(let S=0;S<z.length;S++){let C=d[z[S]],I=x(C),L=z.slice(0,S).map((F,j)=>({b:d[F],gone:A[j]})),T=F=>I>F+W,q=F=>Math.abs(I-F)<=W,P=T(k)&&L.every(F=>F.gone||T(w(F.b)));if(A.push(P),P)return e0(`${C.part.name} can slide off over ${f[M].part.name} and its retainer: its bore is wider than all that holds it on that side.`,l);(q(k)||L.some(F=>!F.gone&&q(w(F.b))))&&(u=!0)}}for(let M=0;M<2;M++){let{stop:k,h:z}=y[M];if(!a6(c,z))return e0("A retainer is not coaxial with the shaft.");let A=ee(z),S=s6(c,z),C=f[M],I=M===0?S[1]:S[0],L=M===0?C.lo:C.hi,T=M===0?L-I:I-L;l[`stopGap${M+1}`]=T;let q=u5(n,C.part),P=(A.diameter-(C.hole[1]-q[0]))/2;if(l[`stopOverlap${M+1}`]=P,T<-W||T>t.maximumStopGap+W)return e0("A retainer is misplaced relative to the outside bearing face.",l);if((T<-1e-7||T>t.maximumStopGap+1e-7)&&(u=!0),P<t.minimumOverlap-W)return e0("A retainer can pass through its bearing opening.",l);P<t.minimumOverlap+W&&(u=!0);let F=k.attachment;if(F.kind==="unknown")return{...i1("The stop is present but its fastening is unverified."),measurements:l};if(F.kind==="integral"){if(Math.min(Math.abs(I),Math.abs(I-c.length))>W)return e0("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 j=R2(e,F.thread);if(!a6(c,j))return e0("The threaded attachment is off the shaft axis.");if(ee(j).diameter>c.diameter+W)return e0("The declared threaded section exceeds the shaft envelope.");let _=s6(c,j),Q=Math.max(0,Math.min(S[1],_[1])-Math.max(S[0],_[0]));if(_[0]<-W||_[1]>c.length+W)return e0("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=Q,Q<F.minimumEngagement-W)return e0("The threaded stop has insufficient declared thread engagement.",l);if(Q<F.minimumEngagement+W&&(u=!0),!F.secured)return{...i1("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?{...i1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:l6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,b,o.some(M=>ne(n,M))?"bounded-fit":"nominal")}var h4=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},f1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),H0=(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]],A0=(t,e)=>t.map(n=>n*e),a9=(t,e)=>t.map((n,r)=>n+e[r]),W1=t=>A0(t,1/P1(t)),s9=()=>j0(0,0,0);function u6(t,e){let n=r=>r.kind==="translate"?P1(r.by)<1e-9:Math.abs(r.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?P1(y1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?P1(y1(A0(W1(t.axis),t.angle),A0(W1(e.axis),e.angle)))<1e-9&&P1(H0(y1(t.origin,e.origin),W1(t.axis)))<1e-9:!1}function El(t,e){let n=new Map;for(let r of e)for(let c=0;c<r.length;c++){let a=r[c],s=r[(c+1)%r.length],o=a<s?[a,s]:[s,a];n.set(o.join(","),o)}return{vertices:t,faces:e,edges:[...n.values()]}}function f5(t,e,n){let r=t.length,c=[];for(let a of[0,e])for(let[s,o]of t)c.push(u0(n,[s,o,a]));return El(c,[t.map((a,s)=>s).reverse(),t.map((a,s)=>r+s),...t.map((a,s)=>[s,(s+1)%r,(s+1)%r+r,s+r])])}function Tl(t,e){let n=s1(t),r=[...new Set(n.flat().map(o=>o[0]))].sort((o,i)=>o-i),c=n.flatMap(o=>o.map((i,l)=>({a:i,b:o[(l+1)%o.length]}))),a=[],s=(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(c.length);let u=c.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(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],p=u[f+1],m=[[i,s(d,i)],[l,s(d,l)],[l,s(p,l)],[i,s(p,i)]],g=m.filter((v,b)=>P1([v[0]-m[(b+1)%m.length][0],v[1]-m[(b+1)%m.length][1],0])>1e-10);if(g.length<3||Math.abs(C3(g))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(a.push(g),a.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!a.length||Math.abs(i3(a)-i3(n))>W*W*Math.max(1,i3(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function I3(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(f1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function re(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 o0(t,e){if("part"in e)return o2(t,e).matrix;let n=R2(t,e),[r,c]=re(n),a={...n,from:r,to:c},s=W1(y1(a.to,a.from));if(!P1(y1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let o=y1(a.up,A0(s,Q1(a.up,s)));if(P1(o)<1e-9){if(Array.isArray(a.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(s[0])<.8?[1,0,0]:[0,1,0];o=y1(l,A0(s,Q1(l,s)))}o=W1(o);let i=H0(o,s);return[i[0],o[0],s[0],a.from[0],i[1],o[1],s[1],a.from[1],i[2],o[2],s[2],a.from[2],0,0,0,1]}function h3(t,e,n){if(n.tick(),"part"in e){let h=o2(t,e),u=l5(h);if(u)throw new Error(u);let d=Tl(h.regions,n).map(p=>f5(p,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=R2(t,e),c=o0(t,e),[a,s]=re(r),o=P1(y1(s,a));if(o<W)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=[f5(f,o,c)];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=j0(0,0,h-u);return{ref:e,inner:[f5(l(u),2*u,D1(c,f))],outer:[f5(l(h/Math.cos(Math.PI/i)),o,c)]}}return{ref:e,inner:[f5(l(r.size/2),o,c)],outer:[f5(l(r.size/2/Math.cos(Math.PI/i)),o,c)]}}function u4(t,e){let n=c=>c.map(a=>({...a,vertices:a.vertices.map(s=>u0(e,s))})),r=n(t.outer);return{ref:t.ref,outer:r,inner:t.inner===t.outer?r:n(t.inner)}}function V3(t,e){if(t.kind==="translate")return j0(...A0(t.by,e));let[n,r,c]=W1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),o=Math.sin(a),i=1-s,l=[s+n*n*i,n*r*i-c*o,n*c*i+r*o,0,r*n*i+c*o,s+r*r*i,r*c*i-n*o,0,c*n*i-r*o,c*r*i+n*o,s+c*c*i,0,0,0,0,1];return D1(j0(...t.origin),D1(l,j0(...A0(t.origin,-1))))}function f6(t,e){if(e.kind==="translate")return P1(e.by);let n=W1(e.axis),r=0;for(let c of t.outer)for(let a of c.vertices){let s=y1(a,e.origin);r=Math.max(r,P1(y1(s,A0(n,Q1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*r}function r9(t){return t.faces.map(e=>H0(y1(t.vertices[e[1]],t.vertices[e[0]]),y1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>P1(e)>1e-12).map(W1)}function o9(t,e){let n=[...r9(t),...r9(e)];for(let[r,c]of t.edges)for(let[a,s]of e.edges){let o=H0(y1(t.vertices[c],t.vertices[r]),y1(e.vertices[s],e.vertices[a]));P1(o)>1e-12&&n.push(W1(o))}return n}var d5=(t,e)=>{let n=t.vertices.map(r=>Q1(r,e));return[Math.min(...n),Math.max(...n)]};function Il(t,e,n){let r=-1/0;for(let c of o9(t,e)){n.tick();let a=d5(t,c),s=d5(e,c);r=Math.max(r,s[0]-a[1],a[0]-s[1])}return r}function Vl(t,e){let n=0;for(let r=0;r<3;r++){let c=t.vertices.map(o=>o[r]),a=e.vertices.map(o=>o[r]),s=Math.max(0,Math.min(...a)-Math.max(...c),Math.min(...c)-Math.max(...a));n+=s*s}return Math.sqrt(n)}function Hl(t,e,n,r){let c=y1(n,e),a=y1(r,e),s=y1(t,e),o=Q1(c,s),i=Q1(a,s);if(o<=0&&i<=0)return P1(s);let l=y1(t,n),h=Q1(c,l),u=Q1(a,l);if(h>=0&&u<=h)return P1(l);let f=o*u-h*i;if(f<=0&&o>=0&&h<=0)return P1(y1(s,A0(c,o/(o-h))));let d=y1(t,r),p=Q1(c,d),m=Q1(a,d);if(m>=0&&p<=m)return P1(d);let g=p*i-o*m;if(g<=0&&i>=0&&m<=0)return P1(y1(s,A0(a,i/(i-m))));let v=h*m-p*u;if(v<=0&&u-h>=0&&p-m>=0)return P1(y1(l,A0(y1(r,n),(u-h)/(u-h+p-m))));let b=v+g+f;if(Math.abs(b)<1e-20)return 1/0;let y=Math.max(0,Math.min(1,g/b)),x=Math.max(0,Math.min(1-y,f/b));return P1(y1(s,a9(A0(c,y),A0(a,x))))}function Ol(t,e,n,r){let c=y1(e,t),a=y1(r,n),s=y1(t,n),o=Q1(c,c),i=Q1(c,a),l=Q1(a,a),h=Q1(c,s),u=Q1(a,s);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,p=(i*d+u)/l;return p<0&&(p=0,d=Math.max(0,Math.min(1,-h/o))),p>1&&(p=1,d=Math.max(0,Math.min(1,(i-h)/o))),P1(a9(s,y1(A0(c,d),A0(a,p))))}function $l(t,e,n){let r=1/0;for(let[c,a]of[[t,e],[e,t]])for(let s of c.vertices)for(let o of a.faces)for(let i=1;i<o.length-1;i++)n.tick(),r=Math.min(r,Hl(s,a.vertices[o[0]],a.vertices[o[i]],a.vertices[o[i+1]]));for(let[c,a]of t.edges)for(let[s,o]of e.edges)n.tick(),r=Math.min(r,Ol(t.vertices[c],t.vertices[a],e.vertices[s],e.vertices[o]));return r}function c9(t,e,n,r){let c=1/0,a=1/0,s=!1,o=!0;for(let i of t)for(let l of e){n.tick();let h=Vl(i,l);if(h>Math.min(a,r)){c=Math.min(c,h);continue}let u=Il(i,l,n);u<-W&&(s=!0),u<0&&(o=!1),c=Math.min(c,Math.max(0,h,u)),u<-W?a=0:u<=Math.min(a,r)&&(a=Math.min(a,$l(i,l,n)))}return{lower:c,upper:a,penetration:s,touchSafe:o}}function f4(t,e,n,r){let c=c9(t.outer,e.outer,n,r+W),a=t.outer===t.inner&&e.outer===e.inner;if(c.lower>r+W)return{lower:c.lower-W,upper:1/0,penetration:!1,touchSafe:!0};let s=a?c:c9(t.inner,e.inner,n,1/0);return{lower:Math.max(0,c.lower-W),upper:s.upper+W,penetration:s.penetration,touchSafe:c.touchSafe}}function i9(t,e,n,r,c,a){for(let s=0;s<t.outer.length;s++)for(let o=0;o<n.outer.length;o++){let i=t.outer[s],l=n.outer[o],h=e.outer[s],u=r.outer[o],f=!1;for(let d of o9(i,l)){a.tick();let p=d5(i,d),m=d5(l,d),g=d5(h,d),v=d5(u,d);if(Math.min(m[0]-p[1],v[0]-g[1])>=c||Math.min(p[0]-m[1],g[0]-v[1])>=c){f=!0;break}}if(!f)return!1}return!0}function d4(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},c=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(c>1&&(n.copy-1)%c!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:r,faceA:a?"bottom":"top",faceB:a?"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 z2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),ce=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<W);function l9(t,e,n){if(new Set(e.map(f1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(r=>h3(t,r,n))}function h9(t,e,n){let r=l9(e,t.bodies??I3(e),n);if(r.length<2)return i1("Rigid clearance requires at least two physical bodies.");let c=1/0;for(let a=0;a<r.length;a++)for(let s=a+1;s<r.length;s++){let o=f4(r[a],r[s],n,t.minimumGap);if(c=Math.min(c,o.lower),o.penetration||o.upper<t.minimumGap-W)return z2("Physical bodies interfere or violate the required clearance.",{gapUpper:o.upper},[r[a].ref,r[s].ref]);if(!(o.lower>t.minimumGap||t.minimumGap===0&&o.touchSafe))return{...i1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[r[a].ref,r[s].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:c},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function d6(t,e,n,r,c=1e3){let a=i=>({solid:i,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let i=0;i<t.length;i++){for(let l of e)yield{a:t[i],b:a(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 s()){r.tick();let h=(d,p)=>u4(d.solid,V3(d.trajectory,p));if(u6(i.trajectory,l.trajectory)){let d=f4(i.solid,l.solid,r,n);if(d.penetration||d.upper<n-W)return z2("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{...i1("The fixed relative clearance is within geometric uncertainty."),entities:[i.solid.ref,l.solid.ref]}}if(i.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&i9(h(i,0),h(i,1),h(l,0),h(l,1),n===0?0:n+W,r))continue;let u=f6(i.solid,i.trajectory)+f6(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++o>c)return{...i1("Continuous clearance interval budget exhausted."),measurements:{intervals:o},entities:[i.solid.ref,l.solid.ref]};r.tick();let[d,p]=f.shift(),m=(d+p)/2,g=u*(p-d)/2,v=f4(h(i,m),h(l,m),r,n+g);if(v.penetration||v.upper<n-W)return z2("The specified path has physical interference.",{phase:m,gapUpper:v.upper},[i.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(p-d<1e-9)return{...i1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,p]},entities:[i.solid.ref,l.solid.ref]};f.push([d,m],[m,p])}}}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 Rl(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(c=>c.name===n.name&&c.copy===n.copy);if(!r||n.cutLines===null||r.cutLines===null||!s4(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(c=>c.label===n.label);if(!n.label||!r||n.kind!==r.kind||JSON.stringify(n.size)!==JSON.stringify(r.size)||Math.abs(P1(y1(n.to,n.from))-P1(y1(r.to,r.from)))>W)return"Hardware identities and dimensions must remain invariant."}return null}function u9(t,e,n,r,c=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return i1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=Rl(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=I3(e),o=new Set(t.moving.map(l=>f1(l.body)));if(o.size!==t.moving.length)return z2("A body has conflicting simultaneous trajectories.");let i=l=>t.moving.find(h=>f1(h.body)===f1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...d4(e),...c]){let h=D1(v0(o0(e,l.a)),o0(e,l.b)),u=D1(v0(o0(n,l.a)),o0(n,l.b));if(!ce(h,u)||!u6(i(l.a),i(l.b)))return z2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>f1(f.body)===f1(l))?.trajectory,u=h?V3(h,1):s9();if("part"in l){if(!ce(D1(u,o0(e,l)),o0(n,l)))return z2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=R2(e,l),d=R2(n,l);if(typeof f.size=="number"){if(!ce(u0(u,f.from),d.from)||!ce(u0(u,f.to),d.to))return z2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!ce(D1(u,o0(e,l)),o0(n,l)))return z2("A box trajectory does not match its rendered destination.",{},[l])}}return d6(t.moving.map(l=>({solid:h3(e,l.body,r),trajectory:l.trajectory})),l9(e,s.filter(l=>!o.has(f1(l))),r),t.minimumGap,r,t.maxIntervals)}function f9(t,e,n){let r=t.scope??I3(e),c=new Set(r.map(f1)),a=new Map(t.initial.map(i=>[f1(i),h3(e,i,n)]));if(c.size!==r.length||a.size!==t.initial.length||t.initial.some(i=>!c.has(f1(i))))return z2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,o=0;for(let i of t.steps){if(s.has(i.id)||!c.has(f1(i.part))||a.has(f1(i.part)))return z2("An assembly step duplicates or misidentifies a required installation.");if(s.add(i.id),!i.held)return{...i1(`Step ${i.id} needs an explicit temporary holding/support assumption.`),assemblyStep:i.id};let l=h3(e,i.part,n),h=u4(l,V3({kind:"translate",by:i.from},1)),u=d6([{solid:h,trajectory:{kind:"translate",by:i.from.map(f=>-f)}}],[...a.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,a.set(f1(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]}]},p=h3(d,{hardware:f},n),m=u4(p,V3({kind:"translate",by:i.tool.travel},1)),g=d6([{solid:m,trajectory:{kind:"translate",by:i.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:i.id,message:`Tool access at step ${i.id}: ${g.message}`}}}return a.size!==c.size?z2("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:a.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 t0=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),t2=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),W0=t=>[t[3],t[7],t[11]],m6=t=>{let e=W1(t),n=W1(H0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,H0(e,n)]},m4=(t,e,n)=>{let r=m6(n)[0],c=W1(t2(e,r)),a=W1(t2(t,r)),s=W1(t2(e,n));return Math.atan2(Q1(s,H0(c,a)),Q1(c,a))*180/Math.PI},d9=(t,e,n)=>{let r=[],c=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let o=c;o<=a&&r.length<64;o++)r.push(t+360*o);let s=(e[0]+e[1])/2;return r.sort((o,i)=>Math.abs(o-s)-Math.abs(i-s))};function m9(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 p9(t,e,n,r){let c=I3(e),a=new Set(c.map(f1));for(let f of t.removable??[])a.delete(f1(f));if(t.roots.some(f=>!a.has(f1(f))))return t0("A retention root cannot be excluded as removable.");let s=new Map,o=f=>{for(let d of f)for(let p of f){let m=f1(d),g=s.get(m)??new Set;g.add(f1(p)),s.set(m,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),p=r.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!p)return i1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(p.status==="fail")return t0(`Attachment ${f.claim} fails its geometric contract.`);if(p.status!=="pass")return i1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return t0(`The fastening for ${f.claim} is explicitly not installed.`);let m=m9(d,f.fastening);if(!m)return i1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);o(m),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(f1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=c.filter(f=>a.has(f1(f))&&!l.has(f1(f)));return u.length?{...t0("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:a.size,removableComponents:t.removable?.length??0},assumptions:i}}function Fl(t,e){if("hardware"in e){let o=o0(t,e),i=t.hardware.find(l=>l.label===e.hardware);return u0(o,[0,0,P1(y1(re(i)[1],re(i)[0]))/2])}let n=o2(t,e),r=l5(n);if(r)throw new Error(r);let c=0,a=0,s=0;for(let o of n.regions){let[i,l]=o[0],h=0,u=0,f=0;for(let p=0;p<o.length;p++){let m=o[p],g=o[(p+1)%o.length],v=m[0]-i,b=m[1]-l,y=g[0]-i,x=g[1]-l,w=v*x-y*b;h+=w,u+=(v+y)*w,f+=(b+x)*w}if(Math.abs(h)<1e-12)continue;let d=C3(o);c+=d,a+=(i+u/(3*h))*d,s+=(l+f/(3*h))*d}if(c<=W*W)throw new Error("Material centroid is numerically unresolved.");return u0(n.matrix,[a/c,s/c,n.thickness/2])}function Dl(t){let e=[...t].sort((s,o)=>s[0]-o[0]||s[1]-o[1]),n=(s,o,i)=>(o[0]-s[0])*(i[1]-s[1])-(o[1]-s[1])*(i[0]-s[0]),r=s=>{let o=[];for(let i of s){for(;o.length>1&&n(o[o.length-2],o[o.length-1],i)<=0;)o.pop();o.push(i)}return o},c=r(e),a=r([...e].reverse());return[...c.slice(0,-1),...a.slice(0,-1)]}function ql(t,e,n){let r=new Map,c=o=>{for(let i of o)for(let l of o){let h=r.get(f1(i))??new Set;h.add(f1(l)),r.set(f1(i),h)}};for(let o of t.links){let i=m9(e.claims.find(l=>l.id===o.claim),o.fastening);i&&c(i)}if(!n.length)return!0;let a=new Set([f1(n[0])]),s=[...a];for(;s.length;)for(let o of r.get(s.pop())??[])a.has(o)||(a.add(o),s.push(o));return n.every(o=>a.has(f1(o)))}function g9(t,e,n,r=[],c){let a=I3(e),s=t.loads.map(m=>f1(m.body));if(new Set(s).size!==s.length||a.some(m=>!s.includes(f1(m))))return i1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let m=r.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=c?.claims.find(v=>v.id===t.retention);if(!m||m.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return i1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!ql(g,c,a))return i1("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 m of t.loads){let g=m.center?u0(o0(e,m.body),m.center):Fl(e,m.body);o+=m.mass,i=i.map((v,b)=>v+m.mass*g[b])}if(!Number.isFinite(o)||!i.every(Number.isFinite))return i1("Mass/centroid calculation exceeds its numerical range.");i=A0(i,1/o);let l=[];for(let m of a){let g=h3(e,m,n),v=Math.min(...g.inner.flatMap(y=>y.vertices.map(x=>x[2]))),b=Math.min(...g.outer.flatMap(y=>y.vertices.map(x=>x[2])));if(v<t.ground-W)return t0("A physical component penetrates the ground plane.");if(b<t.ground-W)return i1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(y=>f1(y)===f1(m))){if(Math.abs(v-t.ground)>1e-8)return i1("Ground contact is separated or within physical-envelope uncertainty.");for(let y of g.inner)for(let x of y.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=Dl(l);if(h.length<3)return i1("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 m=0;m<h.length;m++){let g=h[m],v=h[(m+1)%h.length],b=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),y=i5(f,g,v);d=Math.min(d,b<0?-y:y)}let p={supportMargin:d,mass:o,centerX:i[0],centerY:i[1],centerZ:i[2]};return d<t.minimumMargin-W?t0("The gravity line lies outside the required support margin.",p):d<t.minimumMargin+W?{...i1("Stability is on its numerical support boundary."),measurements:p}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:p,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 v9(t,e,n,r){let c=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>r.find(p=>p.id===d&&p.configurations.includes(e.configuration));if(!c||c.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return i1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return i1("Per-step support of removable objects needs an explicit contact model.");let o=new Set(a.roots.map(f1)),i=new Set(c.initial.map(f1));if(c.initial.some(d=>!o.has(f1(d))))return i1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let p=n.claims.find(m=>m.id===d.claim);if(p?.kind==="glue-contact")l.set(d.claim,[p.a,p.b]);else if(p?.kind==="captured-shaft"){let m=[p.shaft,...p.bearings,...p.stack,...p.stops.map(g=>g.body)];p.stops.forEach(g=>{g.attachment.kind==="threaded"&&m.push(g.attachment.thread)}),l.set(d.claim,m)}}let h=new Set,u=new Set(c.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 t0("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(f1(v))??new Set;y.add(f1(b)),d.set(f1(v),y)}let p=new Set([...o].filter(g=>i.has(g))),m=[...p];for(;m.length;)for(let g of d.get(m.pop())??[])p.has(g)||(p.add(g),m.push(g));return p};for(let d of c.steps){i.add(f1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return t0(`Step ${d.id} names an unknown fastening.`);if(v.some(b=>!i.has(f1(b))))return t0(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let p=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(f1));if([...p].some(g=>!i.has(g)))return t0(`Step ${d.id} holds an uninstalled body.`);let m=f();if([...i].some(g=>!m.has(g)&&!p.has(g)))return t0(`Step ${d.id} releases a component before it is retained or supported.`)}return[...i].some(d=>!f().has(d))?t0("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 Nl(t){let e=t.map(c=>{let a=Math.max(...c.map(Math.abs),1e-20);return c.map(s=>s/a)}),n=0,r=!1;for(let c=0;c<(e[0]?.length??0)&&n<e.length;c++){let a=n;for(let i=n+1;i<e.length;i++)Math.abs(e[i][c])>Math.abs(e[a][c])&&(a=i);let s=Math.abs(e[a][c]);if(s<1e-10)continue;s<1e-7&&(r=!0),[e[n],e[a]]=[e[a],e[n]];let o=e[n][c];for(let i=c;i<e[n].length;i++)e[n][i]/=o;for(let i=n+1;i<e.length;i++){let l=e[i][c];for(let h=c;h<e[i].length;h++)e[i][h]-=l*e[n][h]}n++}return{rank:n,uncertain:r}}function y9(t,e,n,r,c,a=[]){if(t.bodies.length>64)return i1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(f1),o=t.roots.map(f1);if(new Set(s).size!==s.length||new Set(o).size!==o.length||o.some(v=>!s.includes(v)))return t0("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>o0(e,v).some((b,y)=>Math.abs(b-o0(n,v)[y])>W)))return t0("A grounded kinematic root changes pose.");let i=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,b,y,x,w=1)=>{let M=s.indexOf(f1(b));if(M<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[M*6+y+k]+=w*x[k]};for(let v of t.roots)for(let b=0;b<6;b++){let y=h();y[s.indexOf(f1(v))*6+b]=1,i.push(y)}let f=d4({...e,parts:e.parts.filter(v=>s.includes(f1({part:v.name,copy:v.copy})))});for(let v of c?.claims??[])if(v.kind==="retention")for(let b of v.links){let y=c.claims.find(x=>x.id===b.claim);b.installed&&b.fastening==="glued"&&y?.kind==="glue-contact"&&a.some(x=>x.id===y.id&&x.configurations.includes(e.configuration)&&x.status==="pass")&&f.push({a:y.a,b:y.b})}for(let v of f)if(!(!s.includes(f1(v.a))&&!s.includes(f1(v.b)))){if(!s.includes(f1(v.a))||!s.includes(f1(v.b)))return i1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let b=l4({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:W*W*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=>s.includes(f1(v.a))&&s.includes(f1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(r.tick(),f1(v.a)===f1(v.b))return t0("A joint cannot connect a body to itself.");let b=o0(e,v.a),y=o0(e,v.b),x=o0(n,v.a),w=o0(n,v.b),M=D1(v0(b),y),k=D1(v0(x),w),z=S=>{let C=h();u(C,v.b,3,S),u(C,v.a,3,S,-1),i.push(C)},A=(S,C,I)=>{let L=h();u(L,v.b,0,S),u(L,v.a,0,S,-1),u(L,v.b,3,H0(I,S)),u(L,v.a,3,H0(C,S),-1),i.push(L)};if(v.kind==="fixed"){if(M.some((S,C)=>Math.abs(S-k[C])>W))return t0("A fixed joint changes its relative transform.");l.forEach(S=>z(S)),l.forEach(S=>A(S,y1(W0(y),W0(b)),[0,0,0]))}else if(v.kind==="revolute"){let S=u0(b,v.anchorA),C=u0(y,v.anchorB),I=W1(t2(b,v.axisA)),L=W1(t2(y,v.axisB)),T=Q1(W1(t2(x,v.axisA)),W1(t2(w,v.axisB)));if(P1(y1(S,C))>W||P1(H0(I,L))>1e-7||Math.abs(Q1(I,L)-T)>1e-7)return t0("Revolute anchors or axes do not coincide.");if(v.range){let q=m4(M,k,v.axisB);if(!d9(q,v.range,W).length)return t0("A revolute joint exceeds its declared angular travel.",{angle:q})}l.forEach(q=>A(q,y1(S,W0(b)),y1(C,W0(y)))),m6(I).forEach(z)}else if(v.kind==="prismatic"){let S=y1(W0(M),W0(k)),C=W1(v.axisA),I=Q1(S,C);if([0,1,2,4,5,6,8,9,10].some(L=>Math.abs(M[L]-k[L])>W)||P1(y1(S,A0(C,I)))>W)return t0("A slider rotates or moves away from its guide axis.");if(I<v.travel[0]-W||I>v.travel[1]+W)return t0("The slider exceeds its allowed travel.",{travel:I});l.forEach(z),m6(W1(t2(b,v.axisA))).forEach(L=>A(L,y1(W0(y),W0(b)),[0,0,0]))}else{let S=W1(t2(b,v.axisA)),C=W1(t2(y,v.axisB));if(P1(H0(S,C))>1e-7||P1(y1(W0(b),W0(x)))>W||P1(y1(W0(y),W0(w)))>W)return t0("The scoped gear axes/centers are not fixed and parallel.");let I=m4(b,x,v.axisA),L=m4(y,w,v.axisB);if(Math.abs(I)>90||Math.abs(L)>90)return i1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(L+v.ratio*I)>1e-6)return t0("The rendered gears do not obey their declared angular ratio.");let T=h();u(T,v.a,3,S,v.ratio),u(T,v.b,3,C),i.push(T)}}r.tick(i.length*s.length*6);let p=Nl(i),m=s.length*6-p.rank;if(p.uncertain)return i1("Constraint rank is numerically singular.");let g={degreesOfFreedom:m,constraintRank:p.rank,redundantRows:i.length-p.rank};return m!==t.expectedDof?t0("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 b9(t,e,n,r){let c=i=>t.moving.find(l=>f1(l.body)===f1(i))?.trajectory??{kind:"translate",by:[0,0,0]},a=i=>i.kind==="translate"?P1(i.by)<1e-9:Math.abs(i.angle)<1e-9,s=(i,l)=>a(i)&&a(l)?!0:i.kind==="translate"&&l.kind==="translate"?P1(y1(i.by,l.by))<1e-9:i.kind==="rotate"&&l.kind==="rotate"?P1(y1(A0(W1(i.axis),i.angle),A0(W1(l.axis),l.angle)))<1e-9&&P1(H0(y1(i.origin,l.origin),W1(i.axis)))<1e-9:!1;if(e.roots.some(i=>!a(c(i))))return t0("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(f1(i.b)))return i1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");o.set(f1(i.b),f1(i.a))}for(let i of o.keys()){let l=new Set,h=i;for(;h&&o.has(h);){if(l.has(h))return i1("Continuous closed-linkage constraints need a solver.");l.add(h),h=o.get(h)}}for(let i of e.joints){let l=c(i.a),h=c(i.b),u=o0(n,i.a),f=o0(n,i.b);if(i.kind==="fixed"){if(!s(l,h))return t0("The analytic path separates a fixed joint.");continue}if(i.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return i1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=u0(u,i.anchorA),p=W1(t2(u,i.axisA)),m=W1(h.axis);if(P1(H0(p,m))>1e-9||P1(H0(y1(h.origin,d),p))>W)return t0("The trajectory does not rotate about the actual hinge.");if(i.range){let g=D1(v0(u),f),v=D1(v0(o0(r,i.a)),o0(r,i.b)),b=h.angle*Q1(W1(t2(f,i.axisB)),m),y=i.range;if(!d9(m4(g,v,i.axisB),y,W).some(w=>Math.min(w,w+b)>=y[0]-W&&Math.max(w,w+b)<=y[1]+W))return t0("The continuous hinge path exceeds its angular stops.")}}else if(i.kind==="prismatic"){if(s(l,h))continue;if(!a(l)||h.kind!=="translate")return i1("This slider trajectory composition needs a richer constraint solver.");let d=W1(t2(u,i.axisA));if(P1(H0(h.by,d))>W)return t0("The analytic slider path leaves its guide.");let p=D1(v0(u),f),m=D1(v0(o0(r,i.a)),o0(r,i.b)),g=Q1(y1(W0(p),W0(m)),W1(i.axisA)),v=g+Q1(h.by,d);if(Math.min(g,v)<i.travel[0]-W||Math.max(g,v)>i.travel[1]+W)return t0("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,b)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let y=o0(n,g),x=W1(t2(y,b));return P1(H0(W1(v.axis),x))>1e-9||P1(H0(y1(v.origin,W0(y)),x))>W?null:v.angle*Q1(W1(v.axis),x)},p=d(i.a,l,i.axisA),m=d(i.b,h,i.axisB);if(p===null||m===null)return i1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(m+i.ratio*p)>1e-7)return t0("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 x9(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return M9(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 c=n?.parts.filter(l=>l.name===r.name),a=c?.length===1?c[0]:void 0,s=a?.glue?.host,i=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((r.copy-1)/(a?.stack??1))+1:1;return{name:r.name,copy:r.copy,thickness:r.thickness,material:r.material??"",matrix:r.matrix,placed:r.placed,regions:a?.cutRegions??r.outline,bends:r.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:i},glueFace:a.glue.face},...a?.on&&{on:a.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 M9(t){if(t&&typeof t=="object"){for(let e of Object.values(t))M9(e);Object.freeze(t)}return t}function w9(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=Q5({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 c=new Map;for(let a of e){let s=a.body,o=f1(s);if(("part"in s?t.assembly.filter(l=>l.name===s.part&&l.copy===(s.copy??1)).length:t.hardware.filter(l=>l.label===s.hardware).length)!==1||c.has(o))throw new Error("Pose controls must identify one unique physical instance each.");c.set(o,V3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=c.get(f1({part:a.name,copy:a.copy}));return s?{...a,matrix:D1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},o=c.get(f1(s));return o?{...a,from:u0(o,a.from),to:u0(o,a.to),up:y1(u0(o,a.up),u0(o,[0,0,0]))}:a})}}function Ul(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==W||Q5(e).length||c6(n).length||n.some(c=>c.error!==void 0||!c.provenance)||!Array.isArray(t.inputs))return!1;let r=c=>JSON.stringify(c,(a,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.fromEntries(Object.keys(s).sort().map(o=>[o,s[o]])):s);try{let c=n.map(s=>({configuration:s.configuration,params:s.params,renderSettings:s.renderSettings,provenance:s.provenance})),a=s=>[...s].sort((o,i)=>o.configuration.localeCompare(i.configuration));return r(e)===r(t.specification)&&r(a(c))===r(a(t.inputs))}catch{return!1}}function Bl(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=Q5(t);if(r.length)return{kind:"invalid-spec",issues:r};let c=c6(e);if(c.length)return{kind:"invalid-snapshot",issues:c};let a=t,s=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:a.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:W,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.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(s.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((x,w)=>x+w.length,0)+(y.cutLines??[]).reduce((x,w)=>x+w.length,0),0),0)>(n.maxPoints??2e5)||a.claims.length>(n.maxClaims??1e3)||a.configurations.length>(n.maxConfigurations??100))return i.claims.push(u3("$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(a.configurations.map(g=>g.id));for(let g of s)h.has(g.configuration)||o.push({code:"unknown-configuration",message:`Snapshot ${g.configuration} is not declared.`});for(let g of s){let v=a.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(a.claims.map(g=>[g.id,g]));for(let{claim:g,ref:v}of e9(a)){let b=u.get(g);for(let y of s.filter(x=>x.error===void 0&&(!b.configurations||b.configurations.includes(x.configuration)))){let x="part"in v?y.parts.filter(w=>w.name===v.part&&w.copy===(v.copy??1)):y.hardware.filter(w=>w.label===v.hardware);x.length!==1&&o.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${y.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(o.length)return{kind:"invalid-spec",issues:o};for(let g of a.configurations){let v=s.find(y=>y.configuration===g.id),b=v&&v.error===void 0;i.claims.push(u3(`$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(u3(`$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(u3(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
|
|
3104
|
+
`)})),v.legacyHardware&&i.claims.push(u3(`$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 h4(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,p=[...a.claims].sort((g,v)=>d(g)-d(v));for(let g of p){let v=g.configurations??a.configurations.map(b=>b.id);if(g.kind==="cut-invariant"){let b=v.map(y=>s.find(x=>x.configuration===y));i.claims.push(u3(g.id,g.kind,g.required!==!1,v,b.some(y=>!y||y.error!==void 0)?i1("A required configuration is unavailable."):_l(b)));continue}if(g.kind==="motion-clearance"){let b=s.find(w=>w.configuration===g.from),y=s.find(w=>w.configuration===g.to),x;if(!b||!y||b.error!==void 0||y.error!==void 0)x=i1("Motion endpoints are unavailable.");else try{if(x={status:"pass"},g.constraints){let w=a.claims.find(k=>k.id===g.constraints),M=i.claims.filter(k=>k.id===g.constraints);if(!w||w.kind!=="joint-constraints"||!M.length||M.some(k=>k.status!=="pass")||![g.from,g.to].every(k=>M.some(z=>z.configurations.includes(k))))x=i1("The motion needs verified endpoint joint constraints.");else{let k=s.find(z=>z.configuration===(w.configurations??a.configurations.map(A=>A.id))[0]);x=b9(g,w,b,k)}}if(x.status==="pass"){let w=[];for(let M of a.claims)if(M.kind==="retention")for(let k of M.links){let z=a.claims.find(A=>A.id===k.claim);k.installed&&k.fastening==="glued"&&z?.kind==="glue-contact"&&[g.from,g.to].every(A=>i.claims.some(S=>S.id===z.id&&S.configurations.includes(A)&&S.status==="pass"))&&w.push({a:z.a,b:z.b})}x=u9(g,b,y,f,w)}}catch(w){x={status:"unverified",code:"geometry-unresolved",message:w.message}}i.claims.push(u3(g.id,g.kind,g.required!==!1,[g.from,g.to],x,k9(g)));continue}for(let b of v){let y=s.find(k=>k.configuration===b),x=a.configurations.find(k=>k.id===b)?.materials,w=x?{...a,materials:{...a.materials,...x}}:a,M;if(!y||y.error!==void 0)M=i1("The configuration is unavailable.");else try{switch(g.kind){case"glue-contact":M=l4(g,y);break;case"tab-slot":M=t9(g,y,w);break;case"captured-shaft":M=n9(g,y,w);break;case"material-assignment":M=jl(y,w);break;case"rigid-clearance":M=h9(g,y,f);break;case"assembly-access":M=f9(g,y,f);break;case"joint-constraints":{let k=s.find(z=>z.configuration===v[0]);M=k&&k.error===void 0?y9(g,y,k,f,a,i.claims):i1("The kinematic reference configuration is unavailable.");break}case"retention":M=p9(g,y,a,i.claims);break;case"stability":M=g9(g,y,f,i.claims,a);break;case"assembly-support":M=v9(g,y,a,i.claims);break;default:M=i1(`The ${g.kind} capability is not implemented; it cannot inherit a geometric-fit pass.`)}}catch(k){M={status:"unverified",code:"geometry-unresolved",message:`The geometric check could not complete: ${k.message}`}}i.claims.push(u3(g.id,g.kind,g.required!==!1,[b],M,k9(g)))}}let m=i.claims.filter(g=>g.required);i.status=m.some(g=>g.status==="fail")?"fail":m.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(x=>x.kind===g&&x.required),y=new Set(b.filter(x=>x.status==="pass").flatMap(x=>x.configurations));(!b.length||b.some(x=>x.status!=="pass")||a.configurations.some(x=>!y.has(x.id)))&&i.uncovered.push(v)}return{kind:"report",report:i}}function u3(t,e,n,r,c,a=[]){return{id:t,kind:e,required:n,configurations:r,status:"unverified",code:"unverified",message:"",entities:a,measurements:{},assumptions:[],coverage:"none",...c}}function k9(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 _l(t){if(t.length<2)return i1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return i1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(r=>r.cutLines===null||r.kerf===null)))return i1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(r=>!r.label)))return i1("Cross-pose hardware requires unique native labels.");for(let n of t){let r=n.hardware.map(c=>c.label);if(new Set(r).size!==r.length)return i1("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 c of e.parts){let a=o2(n,{part:c.name,copy:c.copy});if(!a||!s4(c,a))return{status:"fail",code:"cut-geometry-changed",message:`Operating motion changed cut geometry/material for ${c.name} copy ${c.copy}.`}}for(let c of e.hardware){let a=n.hardware.find(s=>s.label===c.label);if(!a||c.kind!==a.kind||JSON.stringify(c.size)!==JSON.stringify(a.size)||Math.abs(P1(y1(c.to,c.from))-P1(y1(a.to,a.from)))>W)return{status:"fail",code:"hardware-changed",message:`Operating motion changed hardware ${c.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 jl(t,e){if(!t.parts.length)return i1("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 i1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<r.thickness[0]-W||n.thickness>r.thickness[1]+W)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return i1("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 Gl=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function z9(t){if(t.kind!=="report")return[];let e=new Map;for(let r of t.report.claims){if(r.status==="pass")continue;let c=`${r.status}\0${r.code}`,a=e.get(c)??{status:r.status,code:r.code,message:r.message,claims:[]};a.claims.push({id:r.id,configurations:r.configurations,bodies:r.entities.map(Gl),measurements:r.measurements}),e.set(c,a)}let n=r=>r==="fail"?0:1;return[...e.values()].sort((r,c)=>n(r.status)-n(c.status)||c.claims.length-r.claims.length)}function Wl(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(c=>c.message).join("; ")}
|
|
3105
|
+
`;let e=z9(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
|
|
3106
|
+
`;let n=c=>Array.isArray(c)?`${+c[0].toFixed(3)}..${+c[1].toFixed(3)}`:`${+c.toFixed(3)}`,r=[];for(let c of e){r.push(`${c.status} ${c.code} (${c.claims.length}): ${c.message}`);for(let a of c.claims){let s=Object.entries(a.measurements).slice(0,4).map(([o,i])=>`${o} ${n(i)}`).join(", ");r.push(` ${a.id}${a.configurations.length?` [${a.configurations.join(", ")}]`:""}${a.bodies.length?`: ${a.bodies.join(" / ")}`:""}${s?`; ${s}`:""}`)}}return r.join(`
|
|
2647
3107
|
`)+`
|
|
2648
|
-
`}var zf="0.8.0",kf="0.3";export{w4 as DEFAULT_LAYERS,s8 as DEFAULT_LIMITS,m5 as HARDWARE_COLORS,I3 as HARDWARE_KINDS,i1 as KerfError,kf as LANGUAGE_VERSION,z7 as SIGNATURES,zf as VERSION,ue as bendPoint,hi as diffRenders,s6 as format,ti as formatError,xe as formatSignature,Bi as importSvg,wi as instructionsHtml,fe as meshPieces,Js as parameters,a2 as parse,K0 as placementMatrix,dn as poseAssembly,Us as render,v5 as signature,un as snapshotFromRender,p5 as tokenize,mn as triage,yo as triageText,fo as verificationIsCurrent,po as verify};
|
|
3108
|
+
`}var Xl=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},i2=(t,e,n)=>(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x),m5=(t,e)=>t.x===e.x&&t.y===e.y;function g6(t,e,n){let r={i:t,x:e,y:n};return r.prev=r,r.next=r,r}function Zl(t,e){return t&&(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e),e}function S9(t,e,n){let r=null,c=Xl(t)>0===n;for(let a=0;a<t.length;a++){let s=c?a:t.length-1-a;r=Zl(r,g6(e+s,t[s][0],t[s][1]))}if(r&&m5(r,r.next)){let a=r.next;p4(r),r=a}return r?r.next:null}function p4(t){t.next.prev=t.prev,t.prev.next=t.next}function p6(t,e){let n=e??t,r=t,c;do if(c=!1,m5(r,r.next)||m5(r.prev,r.next)){if(p4(r),r=n=r.prev,r===r.next)break;c=!0}else r=r.next;while(c||r!==n);return n}function Yl(t,e){let n=g6(t.i,t.x,t.y),r=g6(e.i,e.x,e.y),c=t.next,a=e.prev;return t.next=e,e.prev=t,n.next=c,c.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function v6(t,e,n,r,c,a,s,o){return(n-t)*(o-e)-(r-e)*(s-t)>=0&&(c-n)*(o-r)-(a-r)*(s-n)>=0&&(t-c)*(o-a)-(e-a)*(s-c)>=0}function Jl(t,e){return i2(t.prev,t,t.next)>0?i2(t,e,t.next)<=0&&i2(t,t.prev,e)<=0:i2(t,e,t.prev)>0||i2(t,t.next,e)>0}function Kl(t,e){let n=t.x,r=t.y,c=e,a=-1/0,s=null;do{if(r<=c.y&&r>=c.next.y&&c.next.y!==c.y){let u=c.x+(r-c.y)*(c.next.x-c.x)/(c.next.y-c.y);if(u<=n&&u>a&&(a=u,s=c.x<c.next.x?c:c.next,u===n))return s}c=c.next}while(c!==e);if(!s)return null;let o=s,i=s.x,l=s.y,h=1/0;c=s;do{if(n>=c.x&&c.x>=i&&n!==c.x&&(r<l?v6(n,r,i,l,a,r,c.x,c.y):v6(a,r,i,l,n,r,c.x,c.y))){let u=Math.abs(r-c.y)/(n-c.x);Jl(c,t)&&(u<h||u===h&&(c.x>s.x||c.x===s.x&&i2(s.prev,s,c.prev)>0&&i2(c.next,s,s.next)>0))&&(s=c,h=u)}c=c.next}while(c!==o);return s}function Ql(t){let e=t.prev,n=t.next;if(i2(e,t,n)<=0)return!1;for(let r=n.next;r!==e;r=r.next)if(!m5(r,e)&&!m5(r,n)&&!m5(r,t)&&v6(e.x,e.y,t.x,t.y,n.x,n.y,r.x,r.y)&&i2(r.prev,r,r.next)<=0)return!1;return!0}function y6(t,e=[]){let n=[];if(t.length<3)return n;let r=S9(t,0,!0);if(!r||r===r.next)return n;let c=t.length,a=[];for(let h of e){let u=h.length>=3?S9(h,c,!1):null;if(c+=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);a.push(f)}a.sort((h,u)=>h.x-u.x||h.y-u.y);for(let h of a){let u=Kl(h,r);if(!u)continue;let f=Yl(u,h);p6(f,f.next),r=p6(u,u.next)}let s=p6(r),o=0,i=s;do o++,i=i.next;while(i!==s);let l=0;for(;o>3;){if(Ql(s)){n.push([s.prev.i,s.i,s.next.i]);let h=s.next;p4(s),o--,s=h,l=0;continue}if(s=s.next,++l>o){let h=s,u=s;do i2(u.prev,u,u.next)>i2(h.prev,h,h.next)&&(h=u),u=u.next;while(u!==s);i2(h.prev,h,h.next)>0&&n.push([h.prev.i,h.i,h.next.i]);let f=h.next;p4(h),o--,s=f,l=0}}return o===3&&i2(s.prev,s,s.next)>0&&n.push([s.prev.i,s.i,s.next.i]),n}var eh=[[/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"],[/clear|acrylic|perspex|glass/i,"#cfe6ee"]];function C9(t){return eh.find(([e])=>e.test(t))?.[1]??"#dcc39a"}var th=t=>/clear|acrylic|perspex|glass/i.test(t),A9=.01,nh=(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]],rh=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]),L9=(t,e)=>b1(t)>0===e?t:[...t].reverse();function b6(t,e,n,r,c,a){let[s,...o]=e;if(!s||s.length<3)return;let i=[L9(s,!0),...o.map(m=>L9(m,!1))],l=i.flat(),h=y6(i[0],i.slice(1));if(!h.length)return;let u=l.length,f=t.positions.length/3;for(let[m,g]of l)t.positions.push(...c([m,g,n]));for(let[m,g]of l)t.positions.push(...c([m,g,r]));let d=(m,g,v)=>a?t.indices.push(m,v,g):t.indices.push(m,g,v);for(let[m,g,v]of h)d(f+u+m,f+u+g,f+u+v),d(f+v,f+g,f+m);let p=0;for(let m of i){for(let g=0;g<m.length;g++){let v=f+p+g,b=f+p+(g+1)%m.length;d(v,b,b+u),d(v,b+u,v+u)}p+=m.length}}var x6=(t,e,n,r,c={})=>({name:t,kind:e,material:n,color:r,positions:[],indices:[],...c});function ch(t,e,n,r){let c=[];for(let a of t.marks??[]){if(r.has(a.layer))continue;let s=a.mode==="line"?[...a.lines,...a.regions.map(l=>[...l,l[0]])]:a.lines,o=s1([...a.mode==="fill"?a.regions:[],...p3(s,n)]),i=K1(o,e);i.length&&c.push({layer:a.layer,color:a.color,side:a.side,regions:i})}return c}function ah(t,e,n,r,c,a){let s=t.thickness,o=(t.marks??[]).filter(m=>c.has(m.layer)&&m.side==="front"),i=o.length?g0(t.outline,p3(o.flatMap(m=>m.lines),n.slitWidth)):t.outline,l=r?t.bends:void 0,h=m=>nh(e,l?.length?U3(l,s,m):m),u=rh(e)<0,f=t.material??"material",d=[],p=x6(t.name,"part",f,C9(f),{part:t.name,copy:t.copy,instance:a,clear:th(f)});for(let m of B3(i,l))b6(p,m,0,s,h,u);if(d.push(p),n.markHeight>0)for(let m of ch(t,i,n.lineWidth,c)){if(m.side==="back"&&n.layout==="flat")continue;let[g,v]=m.side==="front"?[s-A9,s+n.markHeight]:[-n.markHeight,A9],b=x6(`${t.name} ${m.layer}`,"mark",m.layer,m.color,{part:t.name,copy:t.copy,instance:a});for(let y of B3(m.regions,l))b6(b,y,g,v,h,u);b.indices.length&&d.push(b)}return d}function sh(t){let e=K2[t.kind],n=y3[t.kind]??e?.color??"#c8c8c8",r=x6(t.label??t.kind,"hardware",t.kind,n,{metal:e?.metal,clear:t.kind==="glass"}),c=t.to.map((d,p)=>d-t.from[p]),a=Math.hypot(...c),s=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,p=12,m=24;for(let g=0;g<=p;g++)for(let v=0;v<m;v++){let b=Math.PI*g/p,y=2*Math.PI*v/m;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<p;g++)for(let v=0;v<m;v++){let b=g*m+v,y=g*m+(v+1)%m;r.indices.push(b,b+m,y+m,b,y+m,y)}return r}if(!(a>0)||!(s[0]>0))return null;let{axis:o,u:i,v:l}=F4(t),h=Array.isArray(t.size)?4:Math.min(128,Math.max(3,Math.floor(t.sides)||24)),u=Array.isArray(t.size)?[[-s[0]/2,-s[1]/2],[s[0]/2,-s[1]/2],[s[0]/2,s[1]/2],[-s[0]/2,s[1]/2]]:Array.from({length:h},(d,p)=>{let m=2*Math.PI*p/h;return[s[0]/2*Math.sin(m),s[0]/2*Math.cos(m)]});return b6(r,[u],0,a,([d,p,m])=>[t.from[0]+d*i[0]+p*l[0]+m*o[0],t.from[1]+d*i[1]+p*l[1]+m*o[1],t.from[2]+d*i[2]+p*l[2]+m*o[2]],!1),r}function oh(t,e){let n=u=>{let[f,d,p,m]=[1/0,1/0,-1/0,-1/0];for(let g of u.outline)for(let[v,b]of g)f=Math.min(f,v),d=Math.min(d,b),p=Math.max(p,v),m=Math.max(m,b);return[f,d,p,m]},r=t.map(n),c=r.reduce((u,[f,d,p,m])=>u+(p-f+e)*(m-d+e),0),a=Math.max(Math.sqrt(c)*1.3,...r.map(([u,,f])=>f-u)),s=t.map((u,f)=>f).sort((u,f)=>r[f][3]-r[f][1]-(r[u][3]-r[u][1])),o=new Array(t.length),i=0,l=0,h=0;for(let u of s){let[f,d,p,m]=r[u];i>0&&i+(p-f)>a&&(i=0,l+=h+e,h=0),o[u]=[1,0,0,i-f,0,1,0,l-d,0,0,1,0,0,0,0,1],i+=p-f+e,h=Math.max(h,m-d)}return o}function M6(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)),c=n.layout==="flat"||!t.assembly.length,a=(c?t.flat??t.assembly:t.assembly).filter(i=>i.outline.length),s=c?oh(a,n.gap):a.map(i=>i.matrix),o=a.flatMap((i,l)=>ah(i,s[l],{...n,layout:c?"flat":"assembled"},!c,r,l));if(!c&&n.hardware)for(let i of t.hardware??[]){let l=sh(i);l&&o.push(l)}return o}var ih=(()=>{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 lh(t){let e=4294967295;for(let n=0;n<t.length;n++)e=ih[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function P9(t){let e=new TextEncoder,n=[],r=[],c=0,a=0,s=23585;for(let f of t){let d=e.encode(f.name),p=lh(f.data),m=new DataView(new ArrayBuffer(30));m.setUint32(0,67324752,!0),m.setUint16(4,20,!0),m.setUint16(6,2048,!0),m.setUint16(8,0,!0),m.setUint16(10,a,!0),m.setUint16(12,s,!0),m.setUint32(14,p,!0),m.setUint32(18,f.data.length,!0),m.setUint32(22,f.data.length,!0),m.setUint16(26,d.length,!0),m.setUint16(28,0,!0),n.push(new Uint8Array(m.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,a,!0),g.setUint16(14,s,!0),g.setUint32(16,p,!0),g.setUint32(20,f.data.length,!0),g.setUint32(24,f.data.length,!0),g.setUint16(28,d.length,!0),g.setUint32(42,c,!0),r.push(new Uint8Array(g.buffer),d),c+=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,c,!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 E9=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]},w6=t=>{let e=(Math.abs(t)<5e-7?0:t).toFixed(4);return e.includes(".")?e.replace(/\.?0+$/,""):e},g4=t=>t.copy&&t.copy>1?`${t.name} (${t.copy})`:t.name;function T9(t,e,n,r){let c=t[n*3]-t[e*3],a=t[n*3+1]-t[e*3+1],s=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=a*l-s*i,u=s*o-c*l,f=c*i-a*o,d=Math.hypot(h,u,f)||1;return[h/d,u/d,f/d]}function I9(t){let e=t.reduce((a,s)=>a+s.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 c=84;for(let a of t)for(let s=0;s<a.indices.length;s+=3){let[o,i,l]=[a.indices[s],a.indices[s+1],a.indices[s+2]];for(let h of T9(a.positions,o,i,l))n.setFloat32(c,h,!0),c+=4;for(let h of[o,i,l])for(let u=0;u<3;u++)n.setFloat32(c,a.positions[h*3+u],!0),c+=4;c+=2}return new Uint8Array(n.buffer)}var k6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function V9(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=[],c=[],a=new Map;t.forEach((h,u)=>{let f=h.instance===void 0?`h${u}`:`p${h.instance}`;a.set(f,[...a.get(f)??[],h])});let s=2;for(let h of a.values()){let u=[];for(let f of h){let d=[];for(let m=0;m<f.positions.length;m+=3)d.push(`<vertex x="${w6(f.positions[m])}" y="${w6(f.positions[m+1])}" z="${w6(f.positions[m+2])}"/>`);let p=[];for(let m=0;m<f.indices.length;m+=3)p.push(`<triangle v1="${f.indices[m]}" v2="${f.indices[m+1]}" v3="${f.indices[m+2]}"/>`);r.push(`<object id="${s}" type="model" name="${k6(g4(f))}" pid="1" pindex="${n(f)}"><mesh><vertices>${d.join("")}</vertices><triangles>${p.join("")}</triangles></mesh></object>`),u.push(s++)}u.length===1?c.push(`<item objectid="${u[0]}"/>`):(r.push(`<object id="${s}" type="model" name="${k6(g4(h[0]))}"><components>${u.map(f=>`<component objectid="${f}"/>`).join("")}</components></object>`),c.push(`<item objectid="${s++}"/>`))}let i=`<?xml version="1.0" encoding="UTF-8"?>
|
|
3109
|
+
<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,p,m]=E9(f),g=[d,p,m].map(v=>v.toString(16).padStart(2,"0")).join("").toUpperCase();return`<base name="${k6(u)}" displaycolor="#${g}FF"/>`}).join("")}</basematerials>${r.join("")}</resources><build>${c.join("")}</build></model>
|
|
3110
|
+
`,l=new TextEncoder;return P9([{name:"[Content_Types].xml",data:l.encode(`<?xml version="1.0" encoding="UTF-8"?>
|
|
3111
|
+
<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>
|
|
3112
|
+
`)},{name:"_rels/.rels",data:l.encode(`<?xml version="1.0" encoding="UTF-8"?>
|
|
3113
|
+
<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>
|
|
3114
|
+
`)},{name:"3D/3dmodel.model",data:l.encode(i)}])}var z6=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)};function H9(t){let e=[],n=0,r=[],c=[],a=[],s=[],o=[],i=[],l=y=>{let x=new Uint8Array(y.buffer,y.byteOffset,y.byteLength);return r.push({buffer:0,byteOffset:n,byteLength:x.length,target:34962}),e.push(x),n+=x.length,r.length-1};for(let y of t){if(!y.indices.length)continue;let x=y.indices.length,w=new Float32Array(x*3),M=new Float32Array(x*3),k=[1/0,1/0,1/0],z=[-1/0,-1/0,-1/0];for(let L=0;L<x;L+=3){let[T,q,P]=[y.indices[L],y.indices[L+1],y.indices[L+2]],[F,j,_]=T9(y.positions,T,q,P);[T,q,P].forEach((Q,H)=>{let B=y.positions[Q*3]/1e3,Y=y.positions[Q*3+2]/1e3,e1=-y.positions[Q*3+1]/1e3,X=(L+H)*3;w.set([B,Y,e1],X),M.set([F,_,-j],X),[B,Y,e1].forEach((M1,v1)=>{k[v1]=Math.min(k[v1],M1),z[v1]=Math.max(z[v1],M1)})})}let A=l(w);c.push({bufferView:A,componentType:5126,count:x,type:"VEC3",min:k,max:z});let S=l(M);c.push({bufferView:S,componentType:5126,count:x,type:"VEC3"});let C=`${y.material}\0${y.color}\0${y.metal?1:0}\0${y.clear?1:0}`,I=i.indexOf(C);if(I<0){let[L,T,q]=E9(y.color);o.push({name:y.material,pbrMetallicRoughness:{baseColorFactor:[z6(L),z6(T),z6(q),y.clear?.45:1],metallicFactor:y.metal?.6:0,roughnessFactor:y.metal?.35:.85},...y.clear&&{alphaMode:"BLEND"}}),I=i.push(C)-1}a.push({name:g4(y),primitives:[{attributes:{POSITION:c.length-2,NORMAL:c.length-1},material:I}]}),s.push({name:g4(y),mesh:a.length-1,extras:{kind:y.kind,material:y.material,...y.part!==void 0&&{part:y.part,copy:y.copy}}})}let h={asset:{version:"2.0",generator:"KerfScript"},scene:0,scenes:[{nodes:s.map((y,x)=>x)}],nodes:s,meshes:a,materials:o,accessors:c,bufferViews:r,buffers:[{byteLength:n}]},f=new TextEncoder().encode(JSON.stringify(h)),d=(4-f.length%4)%4,p=(4-n%4)%4,m=20+f.length+d+8+n+p,g=new Uint8Array(m),v=new DataView(g.buffer);v.setUint32(0,1179937895,!0),v.setUint32(4,2,!0),v.setUint32(8,m,!0),v.setUint32(12,f.length+d,!0),v.setUint32(16,1313821514,!0),g.set(f,20),g.fill(32,20+f.length,20+f.length+d);let b=20+f.length+d;v.setUint32(b,n+p,!0),v.setUint32(b+4,5130562,!0),b+=8;for(let y of e)g.set(y,b),b+=y.length;return g}function hh(t,e,n={}){let r=M6(t,n);return e==="stl"?I9(r):e==="3mf"?V9(r):H9(r)}function O9(t){let e=2166136261,n=16777619;for(let r=0;r<t.length;r++){let c=t.charCodeAt(r);e=Math.imul(e^c,16777619),n=Math.imul(n^c,1540483477)}return`${(e>>>0).toString(36)}${(n>>>0).toString(36)}${t.length}`}var ae=t=>Math.round(t*1e3)/1e3,S6=t=>t.map(e=>e.map(([n,r])=>[ae(n),ae(r)]));function uh(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(ae),r.bends,r.step,S6(r.outline),(r.marks??[]).map(c=>[c.layer,c.side,S6(c.regions),S6(c.lines)])]),t.hardware,t.steps]);return{files:O9(e),view:O9(n)}}function fh(t,e){let n=t.initial;if(t.options)return t.options.map(a=>a.value);if(t.type==="boolean")return[!0,!1];if(t.type==="string"){let a=String(n??"");if(!a)return["","Sample"];let s=[...a].reverse().join("");return[...new Set([a,a.slice(0,Math.ceil(a.length/2)),s===a?a+a:s])]}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 a=Math.abs(n)>0?Math.abs(n)/2:1;return[n-a,n,n+a]}let r=a=>t.step?ae(t.min+Math.round((a-t.min)/t.step)*t.step):ae(a),c=Array.from({length:e},(a,s)=>r(t.min+(t.max-t.min)*s/(e-1)));return[...new Set([...c,n])].sort((a,s)=>a-s)}function dh(t,e={},n=5){let r=X5(t).parameters,c={...e.params},a=[];for(let s of r){if(s.drive){a.push({name:s.name,tried:[],effect:"skipped",reason:"it drives the motion"});continue}if(!Ot(s,c,r)){a.push({name:s.name,tried:[],effect:"skipped",reason:`it applies only when ${s.when}`});continue}let o=fh(s,Math.max(3,n));if(typeof o=="string"){a.push({name:s.name,tried:[],effect:"skipped",reason:`it is ${o}`});continue}let i=[],l=[];for(let p of o)try{i.push(uh(Ft(t,{...e,params:{...c,[s.name]:p}})))}catch(m){i.push(null),l.push({value:p,message:m.message})}let h=i.filter(p=>p!==null),u=new Set(h.map(p=>p.files)).size>1,f=new Set(h.map(p=>`${p.files} ${p.view}`)).size>1,d={name:s.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 p=g=>i[g]?`${i[g].files} ${i[g].view}`:`x${g}`,m=[];if(s.options){let g=new Map;o.forEach((v,b)=>g.set(p(b),[...g.get(p(b))??[],v]));for(let[v,b]of g)b.length>1&&!v.startsWith("x")&&m.push(b)}else{let g=0;for(let v=1;v<=o.length;v++)(v===o.length||p(v)!==p(g))&&(v-g>1&&i[g]&&m.push(o.slice(g,v)),g=v)}m.length&&(d.same=m)}a.push(d)}return a}function mh(t){let e=c=>JSON.stringify(c),n=["Each setting tried across its range, the others as they are:"],r=!1;for(let c of t){if(c.effect==="skipped"){n.push(`${c.name}: not tried, as ${c.reason}`);continue}c.effect==="failed"?(r=!0,n.push(`${c.name}: the program stops at ${c.errors?.length??0} of the ${c.tried.length} values tried`)):c.effect==="nothing"?(r=!0,n.push(`${c.name}: changes nothing at ${c.tried.map(e).join(", ")}`)):c.effect==="view"?n.push(`${c.name}: changes only the assembled view, not the files`):n.push(`${c.name}: changes the files`);for(let a of c.same??[])n.push(typeof a[0]=="number"?` from ${e(a[0])} to ${e(a[a.length-1])} it changes nothing`:` ${a.slice(0,-1).map(e).join(", ")} and ${e(a[a.length-1])} give the same result`);for(let a of c.errors??[])n.push(` at ${e(a.value)}: ${a.message}`)}return{lines:n,idle:r}}var Xm="0.10.0",Zm="0.3";export{We as DEFAULT_LAYERS,m8 as DEFAULT_LIMITS,y3 as HARDWARE_COLORS,K2 as HARDWARE_KINDS,l1 as KerfError,Zm as LANGUAGE_VERSION,En as SIGNATURES,Xm as VERSION,U3 as bendPoint,Ni as diffRenders,mh as effectsText,Nt as format,Ii as formatError,Z4 as formatSignature,bl as importSvg,Qi as instructionsHtml,C9 as materialColor,M6 as meshBodies,B3 as meshPieces,X5 as parameters,c2 as parse,N0 as placementMatrix,w9 as poseAssembly,Ft as render,dh as settingEffects,Ot as shown,O5 as signature,x9 as snapshotFromRender,V9 as to3mf,H9 as toGlb,hh as toModel,I9 as toStl,V5 as tokenize,z9 as triage,Wl as triageText,y6 as triangulate,Ul as verificationIsCurrent,Bl as verify};
|
|
2649
3115
|
/*! Bundled license information:
|
|
2650
3116
|
|
|
2651
3117
|
opentype.js/dist/opentype.module.js:
|