@mylasertools/kerfscript 0.7.0 → 0.9.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 +103 -0
- package/LANGUAGE.md +201 -84
- package/README.md +2 -2
- package/dist/assembly.d.cts +2 -1
- package/dist/assembly.d.ts +2 -1
- package/dist/ast.d.cts +6 -0
- package/dist/ast.d.ts +6 -0
- package/dist/bores.d.cts +5 -0
- package/dist/bores.d.ts +5 -0
- package/dist/cli.js +2098 -285
- package/dist/customizer.d.cts +1 -0
- package/dist/customizer.d.ts +1 -0
- package/dist/evaluator.d.cts +9 -0
- package/dist/evaluator.d.ts +9 -0
- package/dist/functions.d.cts +2 -0
- package/dist/functions.d.ts +2 -0
- package/dist/geometry.d.cts +11 -0
- package/dist/geometry.d.ts +11 -0
- package/dist/halving.d.cts +8 -0
- package/dist/halving.d.ts +8 -0
- package/dist/highlight.cjs +2 -1
- package/dist/highlight.js +2 -1
- package/dist/index.cjs +474 -58
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +474 -58
- package/dist/language.cjs +462 -46
- package/dist/language.js +462 -46
- package/dist/libraries.cjs +435 -19
- package/dist/libraries.js +435 -19
- package/dist/plot.d.cts +16 -0
- package/dist/plot.d.ts +16 -0
- package/dist/signatures.cjs +189 -5
- package/dist/signatures.js +189 -5
- package/dist/verify/solids.d.cts +2 -1
- package/dist/verify/solids.d.ts +2 -1
- package/dist/verify/types.d.cts +2 -0
- package/dist/verify/types.d.ts +2 -0
- package/docs/cli.md +1 -0
- package/docs/compatibility.md +0 -8
- package/docs/customizer.md +18 -0
- package/docs/library.md +248 -5
- package/docs/parts-and-sheets.md +86 -18
- 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 p9=Object.defineProperty;var g9=(t,e,n)=>e in t?p9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var v9=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var D=(t,e,n)=>g9(t,typeof e!="symbol"?e+"":e,n);var w7=v9((dh,M7)=>{M7.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 F1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(F1||(F1={}));var q1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(q1||(q1={}));var b3=Number.MAX_SAFE_INTEGER,f0=Math.floor(Math.sqrt(b3));function R5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=b3/Math.abs(e)}function Ie(t,e){return Math.abs(t)+Math.abs(e)<=b3}function j4(t,e,n,c){if(R5(t,e)&&R5(n,c)){let r=t*e,a=n*c;if(Ie(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 _4(t,e,n,c){if(R5(t,e)&&R5(n,c)){let r=t*e,a=n*c;if(Ie(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 W4=BigInt(0),F5=BigInt(2),y9=BigInt(4),b9=BigInt(64),x9=BigInt("0xFFFFFFFFFFFFFFFF"),Y4=BigInt("9223372036854775807"),J3=Number(Y4/y9),Ve=Number(Y4),He=1e-12,M9=.1,X4=Math.floor(f0/2),w9=Math.floor(Math.sqrt(Math.sqrt(b3/4)));function z9(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 k9(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function S9(t,e){if(!Number.isFinite(t)||Math.abs(t)>b3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function L9(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 A9(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function C9(t){return Math.abs(t)<=He}function P9(t){return t<0?-1:t>0?1:0}function E9(t,e){let n=BigInt(t),c=BigInt(e),r=n*c;return{lo64:r&x9,hi64:r>>b9}}function Oe(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 T9(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 Oe(c,r,a,s)}function I9(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:_4(c,r,a,s)}function V9(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===W4?0:i>W4?1:-1}function H9(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 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=W4;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 O9(t,e){return t.y*e.x-e.y*t.x}function R9(t,e){return t.x*e.x+t.y*e.y}function F9(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function $9(t){return t>=J3||t<=-J3?Ve:Math.round(t)}function D9(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 q9(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 N9(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 Re(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 U9(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=_4(t.x-e.x,c,t.y-e.y,r)/_4(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 Z4(t,e){let n=e.length,c=0;if(n<3)return q1.IsOutside;for(;c<n&&e[c].y===t.y;)c++;if(c===n)return q1.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 q1.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 q1.IsOn;f<0===r&&(s=1-s)}r=!r,i++}if(r===a)return s===0?q1.IsOutside:q1.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?q1.IsOn:(l<0===r&&(s=1-s),s===0?q1.IsOutside:q1.IsInside)}function B9(t,e){let n=q1.IsOn;for(let i of t)switch(Z4(i,e)){case q1.IsOutside:if(n===q1.IsOutside)return!1;n=q1.IsOutside;break;case q1.IsInside:if(n===q1.IsInside)return!0;n=q1.IsInside;break;default:break}let c=Re(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))/F5),a=Number((BigInt(c.top)+BigInt(c.bottom))/F5)):(r=Math.round((c.left+c.right)/2),a=Math.round((c.top+c.bottom)/2)),Z4({x:r,y:a},e)!==q1.IsOutside}var V1={MaxInt64:Y4,MaxCoord:J3,max_coord:J3,min_coord:-J3,Invalid64:Ve,floatingPointTolerance:He,defaultMinimumEdgeLength:M9,maxCoordForSafeAreaProduct:X4,maxCoordForSafeCrossSq:w9,maxSafeCoordinateForScale:z9,checkSafeScaleValue:k9,ensureSafeInteger:S9,crossProduct:L9,crossProductSign:Y0,checkPrecision:A9,isAlmostZero:C9,triSign:P9,multiplyUInt64:E9,productsAreEqual:Oe,isCollinear:T9,dotProduct:I9,dotProductSign:V9,area:H9,crossProductD:O9,dotProductD:R9,roundToEven:F9,checkCastInt64:$9,getLineIntersectPt:D9,getLineIntersectPtD:q9,segsIntersect:N9,getBounds:Re,getClosestPtOnSegment:U9,pointInPolygon:Z4,path2ContainsPath1:B9},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} `}},$5={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))/F5),n=Number((BigInt(t.top)+BigInt(t.bottom))/F5);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}]}},J4={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 Fe=Object.freeze(t3.createInvalid()),$e=Object.freeze(J4.createInvalid());var K3=BigInt(0),G9=BigInt(2),De=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 K4=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}},Q3=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}},e5=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 qe(t,e,n){return{pt:t,edge1:e,edge2:n}}var S2=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 Q4;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(Q4||(Q4={}));var D5=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)}},q5=class{constructor(e){D(this,"leftOp");D(this,"rightOp");D(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},t5=class{constructor(e,n){D(this,"op1");D(this,"op2");this.op1=e,this.op2=n}};function j9(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function _9(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 n5=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 e5(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 m=0,p=i.length;m<p;m++){let g=i[m];if(o===null)o=new Q3(g,X1.None,null),r.push(o),l=o,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new Q3(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 m=o.next;for(;m!==o&&m.pt.y===o.pt.y;)m=m.next;u=m.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 N5=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
|
-
`}},U5=class t extends N5{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:e6.area(this.polygon);for(let c of this.children)n+=c.area();return n}};var c5=class extends U5{};var E=class E{constructor(){D(this,"cliptype",e0.NoClip);D(this,"fillrule",F1.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 K4);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&&(E.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 E.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return E.openPathsEnabled&&e.localMin.isOpen&&E.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(X1.OpenStart|X1.OpenEnd))!==X1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!E.openPathsEnabled){for(;n!==null&&!E.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!E.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=E.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 e5(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;E.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 n5,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,E.setDx(c));let r;if((n.vertex.flags&X1.OpenEnd)!==X1.None?r=null:(r=new n5,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,E.setDx(r)),c!==null&&r!==null){if(E.isHorizontal(c)){if(E.isHeadingRightHorz(c)){let s=c;c=r,r=s}}else if(E.isHorizontal(r)){if(E.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),E.openPathsEnabled?E.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),E.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);E.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else a&&E.openPathsEnabled&&this.startOpenPath(c,c.bot);E.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(!E.openPathsEnabled){this.doHorizontalClosed(e);return}let n=E.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(E.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(E.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),E.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||E.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!E.isHorizontal(h)){let d=E.nextVertex(e).pt;if(E.isOpen(h)&&!E.isSamePolyType(h,e)&&!E.isHotEdge(h)){if(a&&E.topX(h,d.y)>d.x||!a&&E.topX(h,d.y)<d.x)break}else if(a&&E.topX(h,d.y)>=d.x||!a&&E.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),E.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&E.isOpenEnd(e)){E.isHotEdge(e)&&(this.addOutPt(e,e.top),E.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(E.nextVertex(e).pt.y!==e.top.y)break;E.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,r);o=u.leftX,l=u.rightX}if(E.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(E.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(E.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),E.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&&!E.isHorizontal(l)){let f=E.nextVertex(e).pt,d=E.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),E.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(E.nextVertex(e).pt.y!==e.top.y)break;E.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(E.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(j9);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 t5(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 t5(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 S2(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,E.isMaximaEdge(c)){c=this.doMaxima(c);continue}else E.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),E.isHorizontal(c)&&this.pushHorz(c);else n||(c.curX=E.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=q1.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,n)){case q1.IsOutside:if(c===q1.IsOutside)return!1;c=q1.IsOutside;break;case q1.IsInside:if(c===q1.IsInside)return!0;c=q1.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 q1.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 q1.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 q1.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 q1.IsOn;i<0===r&&(s=1-s)}r=!r,c=c.next}if(r===a)return s===0?q1.IsOutside:q1.IsInside;{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return q1.IsOn;i<0===r&&(s=1-s)}return s===0?q1.IsOutside:q1.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(_9);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=E.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(E.isOpenEnd(e))return E.isHotEdge(e)&&this.addOutPt(e,e.top),E.isHorizontal(e)||(E.isHotEdge(e)&&(E.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let r=E.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 E.isOpen(e)?(E.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(r),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(E.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=E.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,E.setDx(e),this.isJoined(e)&&this.split(e,e.bot),E.isHorizontal(e)){E.openPathsEnabled?E.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=E.nextVertex(e).pt;for(;r.y===e.top.y&&!(n&&r.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=E.nextVertex(e),e.top=r,c=!0,E.isMaximaVertex(e.vertexTop)));)r=E.nextVertex(e).pt;c&&E.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new q5(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=E.topX(e,r.y):r.x=E.topX(n,r.y))}let a=qe(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 E.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 E.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===F1.EvenOdd){let c=0,r=0;for(;n!==e;)E.getPolyType(n)===I0.Clip?r++:E.isOpen(n)||c++,n=n.nextInAEL;e.windCount=E.isOdd(c)?1:0,e.windCount2=E.isOdd(r)?1:0}else for(;n!==e;)E.getPolyType(n)===I0.Clip?e.windCount2+=n.windDx:E.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,c=E.getPolyType(e);if(!E.openPathsEnabled){for(;n!==null&&E.getPolyType(n)!==c;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===F1.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===F1.EvenOdd)for(;n!==e;)E.getPolyType(n)!==c&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)E.getPolyType(n)!==c&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(E.getPolyType(n)!==c||E.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===F1.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.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===F1.EvenOdd)for(;n!==e;)E.getPolyType(n)!==c&&!E.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)E.getPolyType(n)!==c&&!E.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,c;switch(this.fillrule){case F1.Positive:c=e.windCount>0,n=e.windCount2>0;break;case F1.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 F1.Positive:if(e.windCount!==1)return!1;break;case F1.Negative:if(e.windCount!==-1)return!1;break;case F1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case e0.Intersection:return this.fillrule===F1.Positive?e.windCount2>0:this.fillrule===F1.Negative?e.windCount2<0:e.windCount2!==0;case e0.Union:return this.fillrule===F1.Positive?e.windCount2<=0:this.fillrule===F1.Negative?e.windCount2>=0:e.windCount2===0;case e0.Difference:{let n=this.fillrule===F1.Positive?e.windCount2<=0:this.fillrule===F1.Negative?e.windCount2>=0:e.windCount2===0;return E.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,E.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=E.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 S2(c,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new D5;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 S2(n,c);return c.pts=r,r}checkJoinLeft(e,n,c=!1){let r=e.prevInAEL;r!==null&&(!c&&e.curX!==r.curX||!E.isHotEdge(e)||!E.isHotEdge(r)||E.isHorizontal(e)||E.isHorizontal(r)||E.isOpen(e)||E.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||!E.isHotEdge(e)||!E.isHotEdge(r)||E.isHorizontal(e)||E.isHorizontal(r)||E.isOpen(e)||E.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 De*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&&(E.isOpen(e)||E.isOpen(n))){if(E.isOpen(e)&&E.isOpen(n))return;if(E.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,c),this.cliptype===e0.Union){if(!E.isHotEdge(n))return}else if(n.localMin.polytype===I0.Subject)return;switch(this.fillrule){case F1.Positive:if(n.windCount!==1)return;break;case F1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(E.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),E.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&&!E.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&E.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===F1.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!==F1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==F1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case F1.Positive:a=e.windCount,s=n.windCount;break;case F1.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(!(!E.isHotEdge(e)&&!i||!E.isHotEdge(n)&&!o))if(E.isHotEdge(e)&&E.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(E.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(E.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else if(E.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 F1.Positive:l=e.windCount2,h=n.windCount2;break;case F1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!E.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:(E.getPolyType(e)===I0.Clip&&l>0&&h>0||E.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(!E.isMaximaEdge(e)&&e.top.y>n.top.y)return V1.crossProductSign(n.bot,e.top,E.nextVertex(e).pt)<=0;if(!E.isMaximaEdge(n)&&n.top.y>e.top.y)return V1.crossProductSign(n.bot,n.top,E.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(E.prevPrevVertex(e).pt,e.bot,e.top)?!0:V1.crossProductSign(E.prevPrevVertex(e).pt,n.bot,E.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;!E.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(!E.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=E.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 S2(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),E.isFront(e)===E.isFront(n))if(E.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(E.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=E.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else E.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;E.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),E.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&&(E.ptsReallyClose(e.prev.pt,e.next.pt)||E.ptsReallyClose(e.pt,e.next.pt)||E.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||!E.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?E.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(r),E.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=[];E.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||!E.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||!E.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=E.areaOutPt(c),i=s<K3?-s:s;if(i<De){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<K3?-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 S2(a,e);f.prev=c,f.next=r,r.prev=f,c.next=f}if(!(l>G9)||!(l>i)&&o>K3!=s>K3)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new S2(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=K3;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(E,"openPathsEnabled",!0);var B5=E,p2=class extends B5{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 e6={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(e6.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(e6.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 t6=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 t6(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?F1.Negative:F1.Positive,r=new p2;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&&$5.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 Po=BigInt(2);function c6(t,e,n){return typeof e=="number"?n6(e0.Union,t,null,e):n6(e0.Union,t,e,n)}function n6(t,e,n,c){let r=[];if(e===null)return r;let a=new p2;return a.addPaths(e,I0.Subject),n!==null&&a.addPaths(n,I0.Clip),a.execute(t,c,r),r}function G5(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,r6=[1,0,0,1,0,0];function J0(){return{layers:new Map,parts:[]}}function z0(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 Be(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 Ge=t=>t.map(e=>e.map(([n,c])=>({x:Math.round(n*n2),y:Math.round(c*n2)})));function Z9(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 r5=t=>Ge(t).map(Z9),s5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/n2,n.y/n2]));function w1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?F1.EvenOdd:F1.NonZero;return s5(c6(r5(t),n)).filter(c=>c.length>=3)}function a6(t,e,n){if(!e.length)return[];let c=new p2;c.addSubject(r5(e)),n.length&&c.addClip(r5(n));let r=[];return c.execute(t,F1.NonZero,r),s5(r).filter(a=>a.length>=3)}var y0=(t,e)=>e.length?a6(e0.Difference,t,e):w1(t),b0=(t,e)=>a6(e0.Intersection,t,e),M3=(t,e)=>a6(e0.Xor,t,e);function g2(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let c=[];for(let p of e)for(let g=0;g<p.length;g++){let v=p[g],y=p[(g+1)%p.length];(v[0]!==y[0]||v[1]!==y[1])&&c.push([v,y])}if(!c.length)return n==="outside"?t:[];let r=k0(e),a=Math.max(r[2]-r[0],r[3]-r[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=p=>Math.floor(p/a),i=new Map,o=new Map,l=(p,g,v)=>{let y=p.get(g);y?y[y.length-1]!==v&&y.push(v):p.set(g,[v])};c.forEach(([p,g],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(g[0]-p[0],g[1]-p[1])/a*2));for(let b=0;b<=y;b++){let x=p[0]+(g[0]-p[0])*b/y,M=p[1]+(g[1]-p[1])*b/y;for(let S of[-1,0,1])for(let w of[-1,0,1])l(i,`${s(x)+S},${s(M)+w}`,v)}for(let b=s(Math.min(p[1],g[1]));b<=s(Math.max(p[1],g[1]));b++)l(o,b,v)});let h=(p,g)=>{let v=new Set,y=Math.max(1,Math.ceil(Math.hypot(g[0]-p[0],g[1]-p[1])/a*2));for(let b=0;b<=y;b++){let x=p[0]+(g[0]-p[0])*b/y,M=p[1]+(g[1]-p[1])*b/y;for(let S of i.get(`${s(x)},${s(M)}`)??[])v.add(S)}return v},u=.5/n2,f=p=>{for(let v of i.get(`${s(p[0])},${s(p[1])}`)??[]){let[y,b]=c[v],x=b[0]-y[0],M=b[1]-y[1],S=Math.max(0,Math.min(1,((p[0]-y[0])*x+(p[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(p[0]-y[0]-S*x,p[1]-y[1]-S*M)<=u)return}let g=0;for(let v of o.get(s(p[1]))??[]){let[y,b]=c[v],x=(b[0]-y[0])*(p[1]-y[1])-(p[0]-y[0])*(b[1]-y[1]);y[1]<=p[1]?b[1]>p[1]&&x>0&&g++:b[1]<=p[1]&&x<0&&g--}return g!==0},d=p=>Math.round(p*n2)/n2,m=[];for(let p of t){let g=null,v=()=>{g&&g.length>=2&&m.push(g),g=null};for(let y=1;y<p.length;y++){let b=p[y-1],x=p[y],M=x[0]-b[0],S=x[1]-b[1];if(!M&&!S)continue;let w=[0,1];for(let z of h(b,x)){let[C,k]=c[z],T=k[0]-C[0],q=k[1]-C[1],R=M*q-S*T;if(Math.abs(R)>1e-15){let U=((C[0]-b[0])*q-(C[1]-b[1])*T)/R,j=((C[0]-b[0])*S-(C[1]-b[1])*M)/R;U>0&&U<1&&j>=0&&j<=1&&w.push(U)}else{let U=M*M+S*S;for(let j of[C,k]){let V=((j[0]-b[0])*M+(j[1]-b[1])*S)/U,Q=Math.abs((j[0]-b[0])*S-(j[1]-b[1])*M)/Math.sqrt(U);V>0&&V<1&&Q<=u&&w.push(V)}}}w.sort((z,C)=>z-C);for(let z=1;z<w.length;z++){if(w[z]-w[z-1]<1e-12)continue;let C=[d(b[0]+M*w[z-1]),d(b[1]+S*w[z-1])],k=[d(b[0]+M*w[z]),d(b[1]+S*w[z])],T=(w[z-1]+w[z])/2,q=f([b[0]+M*T,b[1]+S*T]);if(q!==void 0&&q===(n==="inside")){let R=g?g[g.length-1]:void 0;g&&R&&R[0]===C[0]&&R[1]===C[1]?(k[0]!==R[0]||k[1]!==R[1])&&g.push(k):(v(),g=[C,k])}else v()}}v()}return m}function p0(t,e,n="round",c=.01){if(!t.length)return[];if(e===0)return w1(t);let r=n==="round"?O0.Round:n==="square"?O0.Square:O0.Miter,a=G5(r5(w1(t)),e*n2,r,s0.Polygon,2,c*n2);return s5(a).filter(s=>s.length>=3)}function j5(t,e){if(!t.length||e<=0)return[];let n=G5(Ge(t),e/2*n2,O0.Round,s0.Round,2,.01*n2);return s5(n)}function B0(t){if(!t.length)return[];let e=new c5,n=new p2;n.addSubject(r5(t)),n.execute(e0.Union,F1.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(s5(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 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 a5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function Ne(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=>a5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>a5(e,i)))});return c}function z3(t,e){return{layers:Ne(t.layers,e),parts:t.parts.map(n=>({...n,layers:Ne(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 Ue(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 i5(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:Ue(t.layers,e),parts:t.parts.map(n=>({...n,layers:Ue(n.layers,e)}))}}function k0(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 $0(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 k0(n)}function je(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 _e(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 We(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 Xe=Math.PI/180;function $1(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 _5(t,e){let n=Math.cos(e*Xe),c=Math.sin(e*Xe);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 s6=t=>Math.abs(t)<1e-12?0:t;function K0(t){if(t.matrix)return t.matrix.map(s6);let[e,n,c]=t.rotate,r=$1(_5(2,c),$1(_5(1,n),_5(0,e)));return r[3]=t.at[0],r[7]=t.at[1],r[11]=t.at[2],r.map(s6)}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 Ke(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 W5(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 o5(t){let[e,n,c,r]=W5(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 Qe(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(o5))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=>W5(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,m,p]=a[u];i>0&&i+m-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+=m-f+n,l=Math.max(l,p-d),{...h,matrix:g.map(s6)}})}var Y9=(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],i6=(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]],Ze=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],X5=t=>[t[2],t[6],t[10]],Ye=t=>[t[3],t[7],t[11]],J9=(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],m=o[1]+(l[1]-o[1])*f-e[1];r.push((d*n[0]+m*n[1])/c)}return r.sort((a,s)=>a-s)}function o6(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 Z5(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 Je(t,e,n){let c=A3(t,e[0],e[1],e[2]),r=J9(t,n);return[[c[0],c[1]],[r[0],r[1]]]}function K9(t,e,n,c,r,a,s){let i=X5(t.matrix),o=X5(e.matrix),l=i6(i,o),h=Math.hypot(...l),u=[l[0]/h,l[1]/h,l[2]/h],f=i6(u,i),d=S3(o,f),m=Ye(t.matrix),p=S3(o,Ye(e.matrix)),g=1/0,v=-1/0;for(let S of e.outline)for(let[w,z]of S)for(let C of[0,e.thickness]){let k=A3(e.matrix,w,z,C),T=S3(i,[k[0]-m[0],k[1]-m[1],k[2]-m[2]]);T<g&&(g=T),T>v&&(v=T)}let y=Z5(Math.max(0,g),Math.min(t.thickness,v),r,a),b=1/0,x=-1/0;for(let S of t.outline)for(let[w,z]of S){let C=A3(t.matrix,w,z,0),k=S3(f,[C[0]-m[0],C[1]-m[1],C[2]-m[2]]);k<b&&(b=k),k>x&&(x=k)}let M=0;for(let S of y.at){let w=Ze(m,i,S),z=(p-S3(o,w))/d,C=(p+e.thickness-S3(o,w))/d,k=Z5(Math.max(b,Math.min(z,C)),Math.min(x,Math.max(z,C)),r,a);for(let T of k.at){let q=Ze(w,f,T),[R,U]=Je(n,q,u),[j,V]=Je(c,q,u);if(M+=o6(L3(t.outline,R,U),L3(e.outline,j,V),r)*y.size*k.size,M>s)return!0}}return!1}function Q9(t,e,n,c,r,a){let s=[0,1,2,3].flatMap(w=>[0,1,2,3].map(z=>{let C=0;for(let k=0;k<4;k++)C+=n[w*4+k]*e.matrix[k*4+z];return C})),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(w=>w.map(([z,C])=>[s[0]*z+s[1]*C+s[3],s[4]*z+s[5]*C+s[7]])),[u,f,d,m]=W5(t.outline),[p,g,v,y]=W5(h),b=Z5(Math.max(f,g),Math.min(m,y),c,r),x=0;for(let w of b.at)if(x+=o6(L3(t.outline,[0,w],[1,0]),L3(h,[0,w],[1,0]),c)*b.size*l,x>a)return!0;let M=Z5(Math.max(u,p),Math.min(d,v),c,r),S=0;for(let w of M.at)if(S+=o6(L3(t.outline,[w,0],[0,1]),L3(h,[w,0],[0,1]),c)*M.size*l,S>a)return!0;return!1}function e7(t,e=1/0,n=.05,c=.25,r=.1){let a=t.map(o5),s=t.map(h=>Ke(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(!Y9(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[m,p]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]];(Math.hypot(...i6(X5(m.matrix),X5(p.matrix)))<1e-9?Q9(m,p,g,n,c,r):K9(m,p,g,v,n,c,r))&&o.push([m,p])}return{found:o,complete:!0}}function D0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var l6=D0(0,0,0);function S0(t){return Ke(t)}function t7(t,e,n=t.angle,c=t.x1){let r=c-t.x0;if(!n||!(r>0))return D0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return $1(D0(t.x0,0,s),$1(_5(1,-n),D0(-t.x0-r,0,-s)))}function l5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function Y5(t,e){let n=[D0(0,0,0)];for(let c of l5(t))n.push($1(n[n.length-1],t7(c,e)));return n}function h6(t,e,n){let c=l5(t),r=Y5(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=$1(r[a],t7(s,e,s.angle*i,n[0]));return A3(o,...n)}}return n}function n7(t,e){return l5(t).filter(n=>(n.x0+n.x1)/2<e).length}function J5(t){if(!t.bends?.length)return[t];let e=l5(t.bends),n=Y5(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=b0(t.outline,[o]);l.length&&r.push({...t,outline:l,bends:void 0,matrix:$1(t.matrix,n[a])})}return r}var en=2e3;function u6(t,e,n=2){if(!e?.length)return B0(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=l5(e).map(f=>[Math.max(f.x0,r),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,m])=>f+(m-d),0),o=Math.max(n,i/en),l=[];for(let[f,d]of s){let m=Math.max(1,Math.ceil((d-f)/o));for(let p=0;p<=m;p++)l.push(f+(d-f)*p/m)}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 m of B0(b0(t,[d])))u.push(m)}return u}var N2=1e6,K5=.01,c7=t=>H1(t)<0?[...t].reverse():t;function tn(t,e){let n=$1(S0(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=w=>(-n[11]-Math.max(n[10]*s,n[10]*i)+w)/a,l=w=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-w)/a;if(!(l(K5)>o(K5)))return[];let[h,u]=[c/a,r/a],[f,d]=[-u,h],m=(w,z)=>[[h*w-f*N2,u*w-d*N2],[h*z-f*N2,u*z-d*N2],[h*z+f*N2,u*z+d*N2],[h*w+f*N2,u*w+d*N2]],p=1/0,g=-1/0;for(let w of e.outline)for(let[z,C]of w)for(let k of[s,i]){let T=n[8]*z+n[9]*C+n[10]*k+n[11];T<p&&(p=T),T>g&&(g=T)}if(Math.min(t.thickness,g)-Math.max(0,p)<Math.min(1,t.thickness/2))return[];let v=(w,z)=>b0(e.outline,[c7(m(w,z))]).filter(C=>Math.abs(H1(C))>1e-6);if(!v(o(K5),l(K5)).length)return[];let y=v(o(0),l(0));if(!y.length)return[];let b=w=>([z,C])=>[n[0]*z+n[1]*C+n[2]*w+n[3],n[4]*z+n[5]*C+n[6]*w+n[7]],x=n[0]*n[5]-n[1]*n[4]<0,M=w=>y.map(z=>{let C=z.map(b(w));return x?C.reverse():C}),S=[];for(let w of y)for(let z=0;z<w.length;z++){let C=w[z],k=w[(z+1)%w.length],T=[b(s)(C),b(s)(k),b(i)(k),b(i)(C)];Math.abs(H1(T))>1e-9&&S.push(c7(T))}return w1([...M(s),...M(i),...S],"nonzero")}function r7(t,e,n){let c=[];for(let a of e)for(let s of tn(t,a))c.push(s);if(!c.length)return[];let r=B0(b0(w1(c),t.outline)).filter(a=>a.reduce((s,i)=>s+H1(i),0)>1e-4);return r.length?p0(r.flat(),n/2,"miter"):[]}var Q0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",A2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",s7=t=>typeof t=="number",R0=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 f6(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let c of e)f6(t,c,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function Q5(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 a7=(t,e,n)=>Q0(t)&&Q0(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:R0(t)&&R0(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 a7(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):!a7(i,o,n))return!1}return!0}function j0(t){return t===void 0?"undef":Array.isArray(t)?"list":Q0(t)?"range":A2(t)?"function":R0(t)?"record":typeof t}function nn(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?L2(t):Q0(t)?`[${L2(t.start)}:${L2(t.step)}:${L2(t.end)}]`:A2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:R0(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:"]"})):R0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(nn(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 i7(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 _0(t){let e=P3(t,200,!0);return e.whole?e.text:e.text+"..."}var L0=t=>typeof t=="string"?t:_0(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 L2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function E3(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 m=d/f,p=1-m;r.push([p*p*h+2*p*m*l.x1+m*m*l.x,p*p*u+2*p*m*l.y1+m*m*l.y])}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 m=d/f,p=1-m;r.push([p*p*p*h+3*p*p*m*l.x1+3*p*m*m*l.x2+m*m*m*l.x,p*p*p*u+3*p*p*m*l.y1+3*p*m*m*l.y2+m*m*m*l.y])}s=[l.x,l.y]}else i(!0),s=a,r=[a];return i(!1),{closed:n,open:c}}function T3(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,m=0,p=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(),S=x?o:0,w=x?l:0;if(M==="M")o=S+v(),l=w+v(),h=o,u=l,a.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=S+v(),l=w+v(),a.push({type:"L",x:o,y:l});else if(M==="H")o=S+v(),a.push({type:"L",x:o,y:l});else if(M==="V")l=w+v(),a.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let z,C;if(M==="C")z=S+v(),C=w+v();else{let q=g==="C"||g==="S";z=q?2*o-f:o,C=q?2*l-d:l}let k=S+v(),T=w+v();o=S+v(),l=w+v(),f=k,d=T,a.push({type:"C",x1:z,y1:C,x2:k,y2:T,x:o,y:l})}else if(M==="Q"||M==="T"){let z,C;if(M==="Q")z=S+v(),C=w+v();else{let k=g==="Q"||g==="T";z=k?2*o-m:o,C=k?2*l-p:l}o=S+v(),l=w+v(),m=z,p=C,a.push({type:"Q",x1:z,y1:C,x:o,y:l})}else if(M==="A"){let z=v(),C=v(),k=v(),T=y(),q=y(),R=S+v(),U=w+v();a.push(...cn(o,l,z,C,k,T,q,R,U,e)),o=R,l=U}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);g=M}}}function cn(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,m=(e-o)/2,p=u*d+f*m,g=-f*d+u*m,v=p*p/(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*p*p,b=n*n*g*g+c*c*p*p,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*g/c,S=-x*c*p/n,w=u*M-f*S+(t+i)/2,z=f*M+u*S+(e+o)/2,C=(V,Q,W,o1)=>Math.atan2(V*o1-Q*W,V*W+Q*o1),k=C(1,0,(p-M)/n,(g-S)/c),T=C((p-M)/n,(g-S)/c,(-p-M)/n,(-g-S)/c);!s&&T>0&&(T-=2*Math.PI),s&&T<0&&(T+=2*Math.PI);let q=Math.ceil(Math.abs(T)/l),R=[],U=V=>[w+n*Math.cos(V)*u-c*Math.sin(V)*f,z+n*Math.cos(V)*f+c*Math.sin(V)*u],j=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 Q=k+T*V/q,W=k+T*(V+1)/q,o1=4/3*Math.tan((W-Q)/4),m1=U(Q),I=U(W),$=j(Q),Z=j(W);R.push({type:"C",x1:m1[0]+o1*$[0],y1:m1[1]+o1*$[1],x2:I[0]-o1*Z[0],y2:I[1]-o1*Z[1],x:I[0],y:I[1]})}return R}var C0=Math.PI/180,I1=(t,e,n)=>({params:t.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function d7(t,e,n){return t.order?[]:t.params.filter((c,r)=>r<e.length&&n.has(c))}function m7(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 d6(t,e,n,c){let r=i7(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 U1(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 Q5(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${j0(t)}`)}var rn=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function p7(t,e,n){if(rn.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 q0=t=>I1("x",e=>typeof e[0]=="number"?C2(t(e[0])):void 0);function C2(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}}function o7(t,e,n){let c=t.length===1&&Array.isArray(t[0])?t[0]:t;if(c.length)return e(c.map(r=>U1(r,n)))}var h5={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:I1("x, base",(t,e)=>e.given<2?C2(Math.log10(U1(t[0],"log"))):Math.log(U1(t[0],"log"))/Math.log(U1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:q0(t=>Math.sin(t*C0)),cos:q0(t=>Math.cos(t*C0)),tan:q0(t=>Math.tan(t*C0)),asin:q0(t=>Math.asin(t)/C0),acos:q0(t=>Math.acos(t)/C0),atan:q0(t=>Math.atan(t)/C0),atan2:I1("y, x",t=>C2(Math.atan2(U1(t[0],"atan2"),U1(t[1],"atan2"))/C0)),pow:I1("x, y",t=>Math.pow(U1(t[0],"pow"),U1(t[1],"pow"))),min:I1("values...",t=>o7(t,e=>e.reduce((n,c)=>c<n?c:n,1/0),"min")),max:I1("values...",t=>o7(t,e=>e.reduce((n,c)=>c>n?c:n,-1/0),"max")),clamp:I1("x, low, high",t=>Math.min(Math.max(U1(t[0],"clamp"),U1(t[1],"clamp")),U1(t[2],"clamp"))),lerp:I1("a, b, t",t=>{let e=U1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((c,r)=>U1(c,"lerp")+(U1(n[r],"lerp")-U1(c,"lerp"))*e)}return U1(t[0],"lerp")+(U1(t[1],"lerp")-U1(t[0],"lerp"))*e}),norm:I1("v",(t,e)=>Math.sqrt(c2(t[0],"norm",e).reduce((n,c)=>n+U1(c,"norm")**2,0))),cross:I1("a, b",(t,e)=>{let n=c2(t[0],"cross",e).map(r=>U1(r,"cross")),c=c2(t[1],"cross",e).map(r=>U1(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:I1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:R0(t[0])?t[0].fields.size:void 0),keys:I1("record",t=>R0(t[0])?[...t[0].fields.keys()]:void 0),merge:I1("a, b",t=>{if(!R0(t[0])||!R0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:I1("...",(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:I1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...c2(t[0],"reverse",e)].reverse()),sum:I1("values",(t,e)=>c2(t[0],"sum",e).reduce((n,c)=>n+U1(c,"sum"),0)),slice:I1("value, start, end",(t,e)=>{let c=(typeof t[0]=="string"?[...t[0]]:c2(t[0],"slice",e)).slice(U1(t[1]??0,"slice"),t[2]===void 0?void 0:U1(t[2],"slice"));return typeof t[0]=="string"?c.join(""):c}),str:I1("...",(t,e)=>d6(t,"",e,"str")),chr:I1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(U1(e,"chr"))).join("")),ord:I1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:I1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:I1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:I1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:I1("values, separator",(t,e)=>d6(c2(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:I1("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:I1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(d6([t[1]],"",e,"contains")):c2(t[0],"contains",e).some(n=>C3(n,t[1],e.step))),lookup:I1("x, table",(t,e)=>{let n=U1(t[0],"lookup"),c=c2(t[1],"lookup",e);if(!c.length)return;let r=c.map(a=>[U1(a[0],"lookup"),U1(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:I1("min, max, count, seed",t=>{let e=U1(t[0],"rands"),n=U1(t[1],"rands"),c=U1(t[2],"rands"),r=an(t[3]===void 0?1:U1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(n-e)*r())}),is_num:I1("value",t=>s7(t[0])&&!Number.isNaN(t[0])),is_string:I1("value",t=>typeof t[0]=="string"),is_bool:I1("value",t=>typeof t[0]=="boolean"),is_list:I1("value",t=>Array.isArray(t[0])),is_record:I1("value",t=>R0(t[0])),is_undef:I1("value",t=>t[0]===void 0),is_function:I1("value",t=>A2(t[0])),type_of:I1("value",t=>j0(t[0])),path_length:I1("points",(t,e)=>{let n=e4(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:I1("points, s",(t,e)=>l7(e4(t[0],"point_at",e),U1(t[1],"point_at")).point),heading_at:I1("points, s",(t,e)=>C2(l7(e4(t[0],"heading_at",e),U1(t[1],"heading_at")).heading)),path_points:I1("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:U1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let c=E3(T3(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:I1("points, steps, closed",(t,e)=>{let n=e4(t[0],"spline_points",e),c=t[1]===void 0?8:Math.floor(U1(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),p6(n,c,t[2]===!0)}),rotation:I1("angles",t=>{let[e,n,c]=m6(t[0],"rotation");return un(u7(hn(c),u7(ln(n),on(e))))}),euler:I1("matrix",t=>f7(sn(t[0],"euler"))),orient:I1("x, z",t=>{let e=h7(m6(t[0],"orient"),"orient"),n=m6(t[1]??[0,0,1],"orient"),c=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=h7([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 f7([[e[0],r[0],n[0]],[e[1],r[1],n[1]],[e[2],r[2],n[2]]])})};function e4(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 l7(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 m6(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 h7(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 sn(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 on=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[1,0,0],[0,e,-n],[0,n,e]]},ln=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,0,n],[0,1,0],[-n,0,e]]},hn=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,-n,0],[n,e,0],[0,0,1]]},u7=(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])),un=t=>t.map(e=>e.map(C2));function f7(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,C2(c)]}return[C2(Math.atan2(t[2][1],t[2][2])/C0),C2(Math.asin(e)/C0),C2(Math.atan2(t[1][0],t[0][0])/C0)]}function p6(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,m=d*f;r.push([0,1].map(p=>.5*(2*o[p]+(-i[p]+l[p])*f+(2*i[p]-5*o[p]+4*l[p]-h[p])*d+(-i[p]+3*o[p]-3*l[p]+h[p])*m)))}}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 u5=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function fn(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(u5(i*a,-1,(i+1)*a,n));return s}function t4(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 fn(s[l],o,c,r))i.push(h.map(a[l]))}),y0([u5(0,0,t,e)],i)}function g7(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(u5(i*a,-n/2,(i+1)*a,n/2));return s}function v7(t,e,n,c,r){let a=u5(-t/2,-1,t/2,e),s=u5(-n/2,r,n/2,r+c);return[a,s]}function y7(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),m=Math.min(f+r,e-(l%2===0?c:0));m-d>=c/2&&a.push([[h,d],[h,m]])}}return a}var P2=(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} (${P2(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})}},dn=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function f5(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
|
-
`){o(1);continue}if(l==="/"&&t[
|
|
9
|
-
`,
|
|
10
|
-
`,
|
|
11
|
-
`;else if(d==="t")f+=" ";else if(d==="u"){let m=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=dn.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"},white:{color:"#f7f7f4",doc:"anything white"}},d5={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var g6=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function r2(t,e){let{tokens:n,comments:c}=f5(t,e),r=new v6(n),a=[];for(;!r.at("eof");)a.push(...r.statement());return{program:{body:a},comments:c}}var m5=class m5{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"||g6.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"||g6.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>=m5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&m5.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}):(g6.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()}}};m5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var v6=m5;var O=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),j1=(t,e,n)=>({...O(t,e,n),named:!0}),y6="max(3 * $thickness, 6)",n4=[O("value")],mn=[O("x")],N0=(t,e)=>({name:t,kind:"function",params:mn,section:"Numbers and vectors",doc:e}),r3=(t,e)=>({name:t,kind:"function",params:n4,section:"Types",doc:`Whether the value is ${e}`}),b7=(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"),j1("halign","left, center or right",'"left"'),j1("valign","baseline, top, center or bottom",'"baseline"'),j1("spacing","Letter spacing factor","1"),j1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),x7=[{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"),j1("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"),j1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[O("r","Radius","1"),j1("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")],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"'),j1("fill",'"evenodd" or "nonzero"','"evenodd"'),j1("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"),j1("halign","left, center or right",'"left"'),j1("valign","baseline, top, center or bottom",'"baseline"'),j1("spacing","Letter spacing factor","1"),j1("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:[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"),j1("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"),j1("delta","Grow or shrink areas with sharp corners","0"),j1("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"),j1("steps","Points between each two given ones","8"),j1("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:"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] 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:"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"'),j1("order","Where it goes among the custom layers in the files, lowest first","0"),j1("bleed","How far past the part's edge it may print","0"),j1("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"),j1("at","Where the part goes in the assembled view, [x, y, z]"),j1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),j1("stack","Layers glued in a stack at each placement, one thickness apart","1"),j1("mirror","Cut the part mirrored left to right, its text still reading","false"),j1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),j1("on","The name of a bent part this one is glued to, to move with it"),j1("slots","Names of parts whose tabs pass through this one: their slots are cut"),j1("clearance","Added to the slots, in total across each","0.1"),j1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),j1("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]"),O("to","The other end, [x, y, z]"),O("size","Diameter, or [width, height] for a flat section","6"),j1("up","The direction a [width, height] section's height points"),j1("sides","Sides of a round section in the 3D view","24"),j1("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",y6)],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",y6)],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"},N0("abs","Absolute value"),N0("sign","Sign as -1, 0 or 1"),N0("floor","Round down"),N0("ceil","Round up"),N0("round","Round to the nearest integer, halves away from zero"),N0("sqrt","Square root"),N0("exp","e raised to x"),N0("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"},N0("sin","Sine of an angle in degrees"),N0("cos","Cosine of an angle in degrees"),N0("tan","Tangent of an angle in degrees"),N0("asin","Inverse sine, in degrees"),N0("acos","Inverse cosine, in degrees"),N0("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:"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:"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:n4,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:n4,section:"Lists and strings",doc:"A list or string in reverse order"},{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"},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:n4,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{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"},b7("text_width","The advance width of the text, including spacing"),b7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[O("length","Edge length"),O("finger","Finger width",y6)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],pn=new Map(x7.map(t=>[t.name,t])),p5=t=>pn.get(t);function b6(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 g5={"kerf/box":`// kerf/box: finger-jointed boxes.
|
|
2
|
+
var Jn=Object.defineProperty;var Kn=(t,e,n)=>e in t?Jn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Qn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var _=(t,e,n)=>Kn(t,typeof e!="symbol"?e+"":e,n);var s7=Qn((fu,a7)=>{a7.exports={}});var t0;(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"})(t0||(t0={}));var H0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(H0||(H0={}));var _1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(_1||(_1={}));var G1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(G1||(G1={}));var P3=Number.MAX_SAFE_INTEGER,x0=Math.floor(Math.sqrt(P3));function Y5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=P3/Math.abs(e)}function tt(t,e){return Math.abs(t)+Math.abs(e)<=P3}function ie(t,e,n,r){if(Y5(t,e)&&Y5(n,r)){let c=t*e,a=n*r;if(tt(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 oe(t,e,n,r){if(Y5(t,e)&&Y5(n,r)){let c=t*e,a=n*r;if(tt(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 le=BigInt(0),J5=BigInt(2),e9=BigInt(4),t9=BigInt(64),n9=BigInt("0xFFFFFFFFFFFFFFFF"),fe=BigInt("9223372036854775807"),s5=Number(fe/e9),nt=Number(fe),rt=1e-12,r9=.1,he=Math.floor(x0/2),c9=Math.floor(Math.sqrt(Math.sqrt(P3/4)));function a9(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:P3/e}function s9(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function i9(t,e){if(!Number.isFinite(t)||Math.abs(t)>P3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function o9(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)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0?r*c-a*s:ie(r,c,a,s)}function a2(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)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0){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 i=BigInt(r)*BigInt(c),o=BigInt(a)*BigInt(s);return i===o?0:i>o?1:-1}function l9(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function h9(t){return Math.abs(t)<=rt}function u9(t){return t<0?-1:t>0?1:0}function f9(t,e){let n=BigInt(t),r=BigInt(e),c=n*r;return{lo64:c&n9,hi64:c>>t9}}function ct(t,e,n,r){let c=Math.abs(t),a=Math.abs(e),s=Math.abs(n),i=Math.abs(r);if(c<x0&&a<x0&&s<x0&&i<x0)return t*e===n*r;let o=(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(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return t*e===n*r;let h=BigInt(c),u=BigInt(a),f=BigInt(s),d=BigInt(i);return h*u===f*d}function d9(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 ct(r,c,a,s)}function m9(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)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0?r*c+a*s:oe(r,c,a,s)}function p9(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)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0){let o=r*c+a*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let o=r*c+a*s;return o>0?1:o<0?-1:0}let i=BigInt(r)*BigInt(c)+BigInt(a)*BigInt(s);return i===le?0:i>le?1:-1}function g9(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)>=he||Math.abs(s.y)>=he)&&(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=le;for(let a of t){let s=r.y+a.y,i=r.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))c+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(a.x)){let o=BigInt(r.y)+BigInt(a.y),l=BigInt(r.x)-BigInt(a.x);c+=o*l}else c+=BigInt(Math.round(s*i));r=a}return Number(c)*.5}function v9(t,e){return t.y*e.x-e.y*t.x}function y9(t,e){return t.x*e.x+t.y*e.y}function b9(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function x9(t){return t>=s5||t<=-s5?nt:Math.round(t)}function M9(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,i=r.x-n.x,o=ie(c,i,s,a);if(o===0)return null;let l=ie(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*c),z:0}}function w9(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,i=r.x-n.x,o=c*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*c,z:0},{success:!0,ip:h}}function k9(t,e,n,r,c=!1){if(!c){let l=a2(t,n,r),h=a2(e,n,r),u=a2(n,t,e),f=a2(r,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=a2(t,n,r),s=a2(e,n,r);if(a!==0&&a===s)return!1;let i=a2(n,t,e),o=a2(r,t,e);return i!==0&&i===o?!1:a!==0||s!==0||i!==0||o!==0}function at(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 z9(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=oe(t.x-e.x,r,t.y-e.y,c)/oe(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 ue(t,e){let n=e.length,r=0;if(n<3)return G1.IsOutside;for(;r<n&&e[r].y===t.y;)r++;if(r===n)return G1.IsOutside;let c=e[r].y<t.y,a=c,s=0,i=r+1,o=n;for(;;){if(i===o){if(o===0||r===0)break;o=r,i=0}if(c)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 G1.IsOn;if(i++,i===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=a2(u,h,t);if(f===0)return G1.IsOn;f<0===c&&(s=1-s)}c=!c,i++}if(c===a)return s===0?G1.IsOutside:G1.IsInside;i===n&&(i=0);let l=i===0?a2(e[n-1],e[0],t):a2(e[i-1],e[i],t);return l===0?G1.IsOn:(l<0===c&&(s=1-s),s===0?G1.IsOutside:G1.IsInside)}function S9(t,e){let n=G1.IsOn;for(let i of t)switch(ue(i,e)){case G1.IsOutside:if(n===G1.IsOutside)return!1;n=G1.IsOutside;break;case G1.IsInside:if(n===G1.IsInside)return!0;n=G1.IsInside;break;default:break}let r=at(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))/J5),a=Number((BigInt(r.top)+BigInt(r.bottom))/J5)):(c=Math.round((r.left+r.right)/2),a=Math.round((r.top+r.bottom)/2)),ue({x:c,y:a},e)!==G1.IsOutside}var O1={MaxInt64:fe,MaxCoord:s5,max_coord:s5,min_coord:-s5,Invalid64:nt,floatingPointTolerance:rt,defaultMinimumEdgeLength:r9,maxCoordForSafeAreaProduct:he,maxCoordForSafeCrossSq:c9,maxSafeCoordinateForScale:a9,checkSafeScaleValue:s9,ensureSafeInteger:i9,crossProduct:o9,crossProductSign:a2,checkPrecision:l9,isAlmostZero:h9,triSign:u9,multiplyUInt64:f9,productsAreEqual:ct,isCollinear:d9,dotProduct:m9,dotProductSign:p9,area:g9,crossProductD:v9,dotProductD:y9,roundToEven:b9,checkCastInt64:x9,getLineIntersectPt:M9,getLineIntersectPtD:w9,segsIntersect:k9,getBounds:at,getClosestPtOnSegment:z9,pointInPolygon:ue,path2ContainsPath1:S9},z2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return O1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),O1.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} `}},K5={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 O1.isAlmostZero(t.x-e.x)&&O1.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)}`}},o3={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))/J5),n=Number((BigInt(t.top)+BigInt(t.bottom))/J5);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}]}},de={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 st=Object.freeze(o3.createInvalid()),it=Object.freeze(de.createInvalid());var i5=BigInt(0),L9=BigInt(2),ot=BigInt(4),Z1;(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"})(Z1||(Z1={}));var me=class{constructor(){_(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}},o5=class{constructor(e,n,r){_(this,"pt");_(this,"next",null);_(this,"prev",null);_(this,"flags");this.pt=e,this.flags=n,this.prev=r}},l5=class{constructor(e,n,r=!1){_(this,"vertex");_(this,"polytype");_(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=r}equals(e){return e!==null&&this.vertex===e.vertex}};function lt(t,e,n){return{pt:t,edge1:e,edge2:n}}var R2=class{constructor(e,n){_(this,"pt");_(this,"next");_(this,"prev");_(this,"outrec");_(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},N0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(N0||(N0={}));var pe;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(pe||(pe={}));var Q5=class{constructor(){_(this,"idx",0);_(this,"owner",null);_(this,"frontEdge",null);_(this,"backEdge",null);_(this,"pts",null);_(this,"polypath",null);_(this,"bounds",{left:0,top:0,right:0,bottom:0});_(this,"path",[]);_(this,"isOpen",!1);_(this,"splits",null);_(this,"recursiveSplit",null)}},e4=class{constructor(e){_(this,"leftOp");_(this,"rightOp");_(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},h5=class{constructor(e,n){_(this,"op1");_(this,"op2");this.op1=e,this.op2=n}};function A9(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function C9(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 u5=class{constructor(){_(this,"bot",{x:0,y:0});_(this,"top",{x:0,y:0});_(this,"curX",0);_(this,"dx",0);_(this,"windDx",0);_(this,"windCount",0);_(this,"windCount2",0);_(this,"outrec",null);_(this,"prevInAEL",null);_(this,"nextInAEL",null);_(this,"prevInSEL",null);_(this,"nextInSEL",null);_(this,"jump",null);_(this,"vertexTop",null);_(this,"localMin",null);_(this,"isLeftBound",!1);_(this,"joinWith",N0.None)}},E3={addLocMin(t,e,n,r){if((t.flags&Z1.LocalMin)!==Z1.None)return;t.flags|=Z1.LocalMin;let c=new l5(t,e,n);r.push(c)},addPathsToVertexList(t,e,n,r,c){for(let a=0,s=t.length;a<s;a++){let i=t[a],o=null,l=null,h=null;for(let m=0,g=i.length;m<g;m++){let p=i[m];if(o===null)o=new o5(p,Z1.None,null),c.push(o),l=o,h=p;else if(!(h.x===p.x&&h.y===p.y)){let v=new o5(p,Z1.None,l);l.next=v,l=v,h=p}}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 m=o.next;for(;m!==o&&m.pt.y===o.pt.y;)m=m.next;u=m.pt.y<=o.pt.y,u?(o.flags=Z1.OpenStart,E3.addLocMin(o,e,!0,r)):o.flags=Z1.OpenStart|Z1.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|=Z1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,E3.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=Z1.OpenEnd,u?l.flags|=Z1.LocalMax:E3.addLocMin(l,e,n,r)):u!==f&&(f?E3.addLocMin(l,e,!1,r):l.flags|=Z1.LocalMax)}}};var t4=class{constructor(e=null){_(this,"parent");_(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
|
+
`}},n4=class t extends t4{constructor(n=null){super(n);_(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:ge.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var f5=class extends n4{};var F=class F{constructor(){_(this,"cliptype",t0.NoClip);_(this,"fillrule",_1.EvenOdd);_(this,"actives",null);_(this,"sel",null);_(this,"minimaList",[]);_(this,"intersectList",[]);_(this,"vertexList",[]);_(this,"outrecList",[]);_(this,"scanlineHeap",new me);_(this,"scanlineSet",new Set);_(this,"scanlineArr",[]);_(this,"useScanlineArray",!1);_(this,"horzSegList",[]);_(this,"horzJoinList",[]);_(this,"currentLocMin",0);_(this,"currentBotY",0);_(this,"curXValidAtTop",!1);_(this,"isSortedMinimaList",!1);_(this,"hasOpenPaths",!1);_(this,"usingPolytree",!1);_(this,"succeeded",!1);_(this,"zCallbackInternal");_(this,"preserveCollinear",!0);_(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&&(F.getPolyType(e)===H0.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 F.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return F.openPathsEnabled&&e.localMin.isOpen&&F.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(Z1.OpenStart|Z1.OpenEnd))!==Z1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!F.openPathsEnabled){for(;n!==null&&!F.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!F.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let r=n.y-e.y;return r!==0?(n.x-e.x)/r:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:O1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=F.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&Z1.LocalMax)!==Z1.None}static isMaximaEdge(e){return(e.vertexTop.flags&Z1.LocalMax)!==Z1.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 i=e.x>n.x?e.x:n.x,o=r.x<c.x?r.x:c.x;if(i<o)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 i=n[s];i>a&&(a=i,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,E3.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 l5(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 o3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===t0.NoClip)return;F.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let r=this.popScanline();if(r!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(r);let 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&Z1.OpenStart)!==Z1.None?r=null:(r=new u5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=-1,r.vertexTop=n.vertex.prev,r.top=n.vertex.prev.pt,r.outrec=null,r.localMin=n,F.setDx(r));let c;if((n.vertex.flags&Z1.OpenEnd)!==Z1.None?c=null:(c=new u5,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,F.setDx(c)),r!==null&&c!==null){if(F.isHorizontal(r)){if(F.isHeadingRightHorz(r)){let s=r;r=c,c=s}}else if(F.isHorizontal(c)){if(F.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),F.openPathsEnabled?F.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),F.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);F.isHorizontal(c)?this.pushHorz(c):(this.checkJoinRight(c,c.bot),this.insertScanline(c.top.y))}else a&&F.openPathsEnabled&&this.startOpenPath(r,r.bot);F.isHorizontal(r)?this.pushHorz(r):this.insertScanline(r.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!F.openPathsEnabled){this.doHorizontalClosed(e);return}let n=F.isOpen(e),r=e.bot.y,c=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:i}=this.resetHorzDirection(e,c),o=s,l=i;if(F.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(F.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),F.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||F.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!F.isHorizontal(h)){let d=F.nextVertex(e).pt;if(F.isOpen(h)&&!F.isSamePolyType(h,e)&&!F.isHotEdge(h)){if(a&&F.topX(h,d.y)>d.x||!a&&F.topX(h,d.y)<d.x)break}else if(a&&F.topX(h,d.y)>=d.x||!a&&F.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),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&F.isOpenEnd(e)){F.isHotEdge(e)&&(this.addOutPt(e,e.top),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,c);o=u.leftX,l=u.rightX}if(F.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,r=this.getCurrYMaximaVertex(e),{isLeftToRight:c,leftX:a,rightX:s}=this.resetHorzDirection(e,r),i=a,o=s;if(F.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(F.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),F.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);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>o||!c&&l.curX<i)break;if(l.curX===e.top.x&&!F.isHorizontal(l)){let f=F.nextVertex(e).pt,d=F.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),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,r);i=h.leftX,o=h.rightX}if(F.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let r=0,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(A9);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 i=c.leftOp.pt.y;if(c.leftToRight){for(;c.leftOp.next.pt.y===i&&c.leftOp.next.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new h5(this.duplicateOp(c.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;c.leftOp.prev.pt.y===i&&c.leftOp.prev.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new h5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(c.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let n=e.leftOp,r=this.getRealOutRec(n.outrec),c=r.frontEdge!==null,a=n.pt.y,s=n,i=n;if(c){let l=r.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,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 R2(e.pt,e.outrec);return n?(r.next=e.next,r.next.prev=r,r.prev=e,e.next=r):(r.prev=e.prev,r.prev.next=r,r.next=e,e.prev=r),r}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let r=this.actives;for(;r!==null;){if(r.top.y===e)if(r.curX=r.top.x,F.isMaximaEdge(r)){r=this.doMaxima(r);continue}else F.isHotEdge(r)&&this.addOutPt(r,r.top),this.updateEdgeIntoAEL(r),F.isHorizontal(r)&&this.pushHorz(r);else n||(r.curX=F.topX(r,e));r=r.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),r=this.getRealOutRec(e.op2.outrec),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=G1.IsOn,c=e;do{switch(this.pointInOpPolygon(c.pt,n)){case G1.IsOutside:if(r===G1.IsOutside)return!1;r=G1.IsOutside;break;case G1.IsInside:if(r===G1.IsInside)return!0;r=G1.IsInside;break;default:break}c=c.next}while(c!==e);return O1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return G1.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 G1.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 G1.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 i=O1.crossProductSign(r.prev.pt,r.pt,e);if(i===0)return G1.IsOn;i<0===c&&(s=1-s)}c=!c,r=r.next}if(c===a)return s===0?G1.IsOutside:G1.IsInside;{let i=O1.crossProductSign(r.prev.pt,r.pt,e);if(i===0)return G1.IsOn;i<0===c&&(s=1-s)}return s===0?G1.IsOutside:G1.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,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!==c)continue;c=o,c.jump=i,r===null?this.sel=c:r.jump=c}else n=n.nextInSEL;r=c,n=i}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(C9);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=F.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(F.isOpenEnd(e))return F.isHotEdge(e)&&this.addOutPt(e,e.top),F.isHorizontal(e)||(F.isHotEdge(e)&&(F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),r;let c=F.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 F.isOpen(e)?(F.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(c),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(F.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=F.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,F.setDx(e),this.isJoined(e)&&this.split(e,e.bot),F.isHorizontal(e)){F.openPathsEnabled?F.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let r=!1,c=F.nextVertex(e).pt;for(;c.y===e.top.y&&!(n&&c.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=F.nextVertex(e),e.top=c,r=!0,F.isMaximaVertex(e.vertexTop)));)c=F.nextVertex(e).pt;r&&F.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new e4(e))}addNewIntersectNode(e,n,r){let c=O1.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),i=Math.abs(n.dx);s>100&&i>100?s>i?c=O1.getClosestPtOnSegment(c,e.bot,e.top):c=O1.getClosestPtOnSegment(c,n.bot,n.top):s>100?c=O1.getClosestPtOnSegment(c,e.bot,e.top):i>100?c=O1.getClosestPtOnSegment(c,n.bot,n.top):(c.y<r?c.y=r:c.y=this.currentBotY,s<i?c.x=F.topX(e,c.y):c.x=F.topX(n,c.y))}let a=lt(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&(Z1.OpenEnd|Z1.LocalMax))===Z1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(Z1.OpenEnd|Z1.LocalMax))===Z1.None;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let r=e.curX,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===N0.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===_1.EvenOdd){let r=0,c=0;for(;n!==e;)F.getPolyType(n)===H0.Clip?c++:F.isOpen(n)||r++,n=n.nextInAEL;e.windCount=F.isOdd(r)?1:0,e.windCount2=F.isOdd(c)?1:0}else for(;n!==e;)F.getPolyType(n)===H0.Clip?e.windCount2+=n.windDx:F.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,r=F.getPolyType(e);if(!F.openPathsEnabled){for(;n!==null&&F.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===_1.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===_1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(F.getPolyType(n)!==r||F.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===_1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=F.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===_1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,r;switch(this.fillrule){case _1.Positive:r=e.windCount>0,n=e.windCount2>0;break;case _1.Negative:r=e.windCount<0,n=e.windCount2<0;break;default:r=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case t0.Intersection:return n;case t0.Union:return!r&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case _1.Positive:if(e.windCount!==1)return!1;break;case _1.Negative:if(e.windCount!==-1)return!1;break;case _1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case t0.Intersection:return this.fillrule===_1.Positive?e.windCount2>0:this.fillrule===_1.Negative?e.windCount2<0:e.windCount2!==0;case t0.Union:return this.fillrule===_1.Positive?e.windCount2<=0:this.fillrule===_1.Negative?e.windCount2>=0:e.windCount2===0;case t0.Difference:{let n=this.fillrule===_1.Positive?e.windCount2<=0:this.fillrule===_1.Negative?e.windCount2>=0:e.windCount2===0;return F.getPolyType(e)===H0.Subject?n:!n}case t0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,r,c=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,F.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=F.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(a,i.outrec),a.owner=i.outrec,this.outrecIsAscending(i)===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 R2(r,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new Q5;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 R2(n,r);return r.pts=c,c}checkJoinLeft(e,n,r=!1){let c=e.prevInAEL;c!==null&&(!r&&e.curX!==c.curX||!F.isHotEdge(e)||!F.isHotEdge(c)||F.isHorizontal(e)||F.isHorizontal(c)||F.isOpen(e)||F.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)||O1.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=N0.Right,e.joinWith=N0.Left))}checkJoinRight(e,n,r=!1){let c=e.nextInAEL;c!==null&&(!r&&e.curX!==c.curX||!F.isHotEdge(e)||!F.isHotEdge(c)||F.isHorizontal(e)||F.isHorizontal(c)||F.isOpen(e)||F.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)||O1.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=N0.Right,c.joinWith=N0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,r){let c=e.x-n.x,a=e.y-n.y,s=r.x-n.x,i=r.y-n.y;if(s===0&&i===0)return!1;let o=O1.maxCoordForSafeCrossSq;if(Math.abs(c)<o&&Math.abs(a)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=c*i-s*a;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(c)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(c)*BigInt(i)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return ot*u>f}let l=c*i-s*a;return l*l/(s*s+i*i)>.25}intersectEdges(e,n,r){let c;if(this.hasOpenPaths&&(F.isOpen(e)||F.isOpen(n))){if(F.isOpen(e)&&F.isOpen(n))return;if(F.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,r),this.cliptype===t0.Union){if(!F.isHotEdge(n))return}else if(n.localMin.polytype===H0.Subject)return;switch(this.fillrule){case _1.Positive:if(n.windCount!==1)return;break;case _1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(F.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(r.x===e.localMin.vertex.pt.x&&r.y===e.localMin.vertex.pt.y&&!F.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&F.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}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===_1.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!==_1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==_1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case _1.Positive:a=e.windCount,s=n.windCount;break;case _1.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(!(!F.isHotEdge(e)&&!i||!F.isHotEdge(n)&&!o))if(F.isHotEdge(e)&&F.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==t0.Xor)c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);else if(F.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(F.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else if(F.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 _1.Positive:l=e.windCount2,h=n.windCount2;break;case _1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!F.isSamePolyType(e,n))c=this.addLocalMinPoly(e,n,r),this.setZ(e,n,c.pt);else if(a===1&&s===1){switch(c=null,this.cliptype){case t0.Union:if(l>0&&h>0)return;c=this.addLocalMinPoly(e,n,r);break;case t0.Difference:(F.getPolyType(e)===H0.Clip&&l>0&&h>0||F.getPolyType(e)===H0.Subject&&l<=0&&h<=0)&&(c=this.addLocalMinPoly(e,n,r));break;case t0.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=O1.crossProductSign(e.top,n.bot,n.top);if(r!==0)return r<0;if(!F.isMaximaEdge(e)&&e.top.y>n.top.y)return O1.crossProductSign(n.bot,e.top,F.nextVertex(e).pt)<=0;if(!F.isMaximaEdge(n)&&n.top.y>e.top.y)return O1.crossProductSign(n.bot,n.top,F.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:O1.isCollinear(F.prevPrevVertex(e).pt,e.bot,e.top)?!0:O1.crossProductSign(F.prevPrevVertex(e).pt,n.bot,F.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==N0.None}split(e,n){e.joinWith===N0.Right?(e.joinWith=N0.None,e.nextInAEL.joinWith=N0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=N0.None,e.prevInAEL.joinWith=N0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,r){e.frontEdge=n,e.backEdge=r}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let r=e.outrec,c=F.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 i=new R2(n,r);return s.prev=i,i.prev=a,i.next=s,a.next=i,c&&(r.pts=i),i}addLocalMaxPoly(e,n,r){if(this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r),F.isFront(e)===F.isFront(n))if(F.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(F.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let c=this.addOutPt(e,r);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=c,this.usingPolytree){let s=F.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else F.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return 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;F.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),F.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let r=e.outrec,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&&(F.ptsReallyClose(e.prev.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,r,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||!F.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?F.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(c),F.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=[];F.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:o3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!F.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=O1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||o3.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&&O1.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||O1.dotProductSign(r.prev.pt,r.pt,r.next.pt)<0)){if(r===e.pts&&(e.pts=r.prev),r=this.disposeOutPt(r),!this.isValidClosedPath(r)){e.pts=null;return}n=r;continue}if(r===null||(r=r.next,r===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!F.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&O1.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=O1.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=F.areaOutPt(r),i=s<i5?-s:s;if(i<ot){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<i5?-o:o;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 R2(a,e);f.prev=r,f.next=c,c.prev=f,r.next=f}if(!(l>L9)||!(l>i)&&o>i5!=s>i5)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new R2(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=O1.maxCoordForSafeAreaProduct,r=0,c=!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){c=!1;break}r+=(i.pt.y+o.y)*(i.pt.x-o.x),a=a.next}while(a!==e);if(c)return BigInt(Math.round(r));let s=i5;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,r){let c=O1.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)),i=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),o=(BigInt(n.y)+BigInt(r.y))*(BigInt(n.x)-BigInt(r.x));return s+i+o}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}};_(F,"openPathsEnabled",!0);var r4=F,S2=class extends r4{constructor(){super(...arguments);_(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,H0.Subject)}addOpenSubject(n){this.addPaths(n,H0.Subject,!0)}addClip(n){this.addPaths(n,H0.Clip)}execute(n,r,c,a){if(Array.isArray(c)){let s=c,i=a;s.length=0,i&&(i.length=0);try{this.executeInternal(n,r),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=c,i=a;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(n,r),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var ge={area(t){return O1.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=O1.maxSafeCoordinateForScale(e),r=[];for(let c of t)O1.checkSafeScaleValue(c.x,n,"scalePath64"),O1.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(ge.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(ge.scalePathD(r,e));return n}};var U0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(U0||(U0={}));var u0;(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"})(u0||(u0={}));var ve=class{constructor(e,n,r=u0.Polygon){_(this,"inPaths");_(this,"joinType");_(this,"endType");_(this,"pathsReversed");_(this,"lowestPathIdx");this.joinType=n,this.endType=r;let c=r===u0.Polygon||r===u0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(l3.stripDuplicates(a,c));if(r===u0.Polygon){let a=l3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},h0=class h0{constructor(e=2,n=0,r=!1,c=!1){_(this,"groupList",[]);_(this,"pathOut",[]);_(this,"normals",[]);_(this,"solution",[]);_(this,"solutionTree",null);_(this,"groupDelta",0);_(this,"delta",0);_(this,"mitLimSqr",0);_(this,"stepsPerRad",0);_(this,"stepSin",0);_(this,"stepCos",0);_(this,"joinType",U0.Bevel);_(this,"endType",u0.Polygon);_(this,"arcTolerance",0);_(this,"mergeGroups",!0);_(this,"miterLimit",2);_(this,"preserveCollinear",!1);_(this,"reverseSolution",!1);_(this,"zCallback");_(this,"deltaCallback",null);_(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 ve(e,n,r))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===u0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===u0.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/h0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),r=n?_1.Negative:_1.Positive,c=new S2;c.preserveCollinear=this.preserveCollinear,c.reverseSolution=this.reverseSolution!==n,c.zCallback=this.ZCB,c.addSubject(this.solution),this.solutionTree!==null?c.execute(t0.Union,r,this.solutionTree):c.execute(t0.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 i of e[a])if(!(i.y<c.y||i.y===c.y&&i.x>=c.x)){if(s===Number.MAX_VALUE){if(s=h0.area(e[a]),s===0)break;r=s<0}n=a,c.x=i.x,c.y=i.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=h0.hypotenuse(e.x,e.y);if(h0.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 h0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,r,c){if(O1.isAlmostZero(e.x-n.x)){if(O1.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(O1.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,i=(c.y-r.y)/(c.x-r.x),o=r.y-i*r.x;if(O1.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,r){let c,a,s=e[n].z||0;if(n===r){let i=Math.abs(this.groupDelta);c={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 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=h0.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=h0.translatePoint(s,a*c.x,a*c.y);let i=h0.translatePoint(s,this.groupDelta*c.y,this.groupDelta*-c.x),o=h0.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=h0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(z2.fromPointD(h0.reflectPoint(u,s))),this.pathOut.push(z2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[r]),u=h0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(z2.fromPointD(u)),this.pathOut.push(z2.fromPointD(h0.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*h0.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[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&K5.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(c));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 r=0;r<n-1;r++)this.normals.push(h0.getUnitNormal(e[r],e[r+1]));this.normals.push(h0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,r,c){if(z2.equals(n[r],n[c]))return;let a=O1.crossProductD(this.normals[r],this.normals[c]),s=O1.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)<h0.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!==U0.Round)this.doMiter(n,r,c,s);else switch(this.joinType){case U0.Miter:s>this.mitLimSqr-1?this.doMiter(n,r,c,s):this.doSquare(n,r,c);break;case U0.Round:this.doRound(n,r,c,Math.atan2(a,s));break;case U0.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)<h0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case u0.Butt:this.doBevel(n,0,0);break;case u0.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)<h0.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case u0.Butt:this.doBevel(n,r,r);break;case u0.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===u0.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===U0.Round||e.endType===u0.Round){let r=this.arcTolerance>.01?this.arcTolerance:n*h0.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===u0.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=h0.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(c===2&&e.endType===u0.Joined&&(this.endType=e.joinType===U0.Round?u0.Round:u0.Square),this.buildNormals(r),this.endType){case u0.Polygon:this.offsetPolygon(e,r);break;case u0.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++)z2.equals(a,e[s])||(a=e[s],c.push(a));return n&&z2.equals(a,c[0])&&c.pop(),c}static area(e){return O1.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),i=s,o=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*i),y:Math.round(e.y+r*o)});let u=i*s-o*a;o=o*s+i*a,i=u}return l}};_(h0,"Tolerance",1e-12),_(h0,"arc_const",.002);var l3=h0;var Ml=BigInt(2);function be(t,e,n){return typeof e=="number"?ye(t0.Union,t,null,e):ye(t0.Union,t,e,n)}function ye(t,e,n,r){let c=[];if(e===null)return c;let a=new S2;return a.addPaths(e,H0.Subject),n!==null&&a.addPaths(n,H0.Clip),a.execute(t,r,c),c}function c4(t,e,n,r,c=2,a=0){let s=new l3(c,a);s.addPaths(t,n,r);let i=[];return s.execute(e,i),i}var u2=1e4,xe=[1,0,0,1,0,0];function O0(){return{layers:new Map,parts:[]}}function A0(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 ft(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 dt=t=>t.map(e=>e.map(([n,r])=>({x:Math.round(n*u2),y:Math.round(r*u2)})));function T9(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 d5=t=>dt(t).map(T9),p5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/u2,n.y/u2]));function i1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?_1.EvenOdd:_1.NonZero;return p5(be(d5(t),n)).filter(r=>r.length>=3)}function Me(t,e,n){if(!e.length)return[];let r=new S2;r.addSubject(d5(e)),n.length&&r.addClip(d5(n));let c=[];return r.execute(t,_1.NonZero,c),p5(c).filter(a=>a.length>=3)}var k0=(t,e)=>e.length?Me(t0.Difference,t,e):i1(t),a0=(t,e)=>Me(t0.Intersection,t,e),h3=(t,e)=>Me(t0.Xor,t,e);function W0(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let r=[];for(let g of e)for(let p=0;p<g.length;p++){let v=g[p],y=g[(p+1)%g.length];(v[0]!==y[0]||v[1]!==y[1])&&r.push([v,y])}if(!r.length)return n==="outside"?t:[];let c=z0(e),a=Math.max(c[2]-c[0],c[3]-c[1],1e-6)/Math.max(1,Math.sqrt(r.length)),s=g=>Math.floor(g/a),i=new Map,o=new Map,l=(g,p,v)=>{let y=g.get(p);y?y[y.length-1]!==v&&y.push(v):g.set(p,[v])};r.forEach(([g,p],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(p[0]-g[0],p[1]-g[1])/a*2));for(let b=0;b<=y;b++){let x=g[0]+(p[0]-g[0])*b/y,M=g[1]+(p[1]-g[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(g[1],p[1]));b<=s(Math.max(g[1],p[1]));b++)l(o,b,v)});let h=(g,p)=>{let v=new Set,y=0,b=1;for(let k of[0,1]){let z=p[k]-g[k],S=c[k]-a,A=c[k+2]+a;if(z===0){if(g[k]<S||g[k]>A)return v;continue}let L=(S-g[k])/z,C=(A-g[k])/z;y=Math.max(y,Math.min(L,C)),b=Math.min(b,Math.max(L,C))}if(!(y<=b))return v;let x=[g[0]+(p[0]-g[0])*y,g[1]+(p[1]-g[1])*y],M=[g[0]+(p[0]-g[0])*b,g[1]+(p[1]-g[1])*b],w=Math.max(1,Math.ceil(Math.hypot(M[0]-x[0],M[1]-x[1])/a*2));for(let k=0;k<=w;k++){let z=x[0]+(M[0]-x[0])*k/w,S=x[1]+(M[1]-x[1])*k/w;for(let A of i.get(`${s(z)},${s(S)}`)??[])v.add(A)}return v},u=.5/u2,f=g=>{for(let v of i.get(`${s(g[0])},${s(g[1])}`)??[]){let[y,b]=r[v],x=b[0]-y[0],M=b[1]-y[1],w=Math.max(0,Math.min(1,((g[0]-y[0])*x+(g[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(g[0]-y[0]-w*x,g[1]-y[1]-w*M)<=u)return}let p=0;for(let v of o.get(s(g[1]))??[]){let[y,b]=r[v],x=(b[0]-y[0])*(g[1]-y[1])-(g[0]-y[0])*(b[1]-y[1]);y[1]<=g[1]?b[1]>g[1]&&x>0&&p++:b[1]<=g[1]&&x<0&&p--}return p!==0},d=g=>Math.round(g*u2)/u2,m=[];for(let g of t){let p=null,v=()=>{p&&p.length>=2&&m.push(p),p=null};for(let y=1;y<g.length;y++){let b=g[y-1],x=g[y],M=x[0]-b[0],w=x[1]-b[1];if(!M&&!w)continue;let k=[0,1];for(let S of h(b,x)){let[A,L]=r[S],C=L[0]-A[0],P=L[1]-A[1],R=M*P-w*C;if(Math.abs(R)>1e-15){let q=((A[0]-b[0])*P-(A[1]-b[1])*C)/R,T=((A[0]-b[0])*w-(A[1]-b[1])*M)/R;q>0&&q<1&&T>=0&&T<=1&&k.push(q)}else{let q=M*M+w*w;for(let T of[A,L]){let B=((T[0]-b[0])*M+(T[1]-b[1])*w)/q,X=Math.abs((T[0]-b[0])*w-(T[1]-b[1])*M)/Math.sqrt(q);B>0&&B<1&&X<=u&&k.push(B)}}}k.sort((S,A)=>S-A);let z=Math.hypot(M,w);for(let S=1;S<k.length;S++){if((k[S]-k[S-1])*z<1e-9||k[S]-k[S-1]<1e-300)continue;let A=[d(b[0]+M*k[S-1]),d(b[1]+w*k[S-1])],L=[d(b[0]+M*k[S]),d(b[1]+w*k[S])],C=(k[S-1]+k[S])/2,P=f([b[0]+M*C,b[1]+w*C]);if(P!==void 0&&P===(n==="inside")){let R=p?p[p.length-1]:void 0;p&&R&&R[0]===A[0]&&R[1]===A[1]?(L[0]!==R[0]||L[1]!==R[1])&&p.push(L):(v(),p=[A,L])}else v()}}v()}return m}function n0(t,e,n="round",r=.01){if(!t.length)return[];if(e===0)return i1(t);let c=n==="round"?U0.Round:n==="square"?U0.Square:U0.Miter,a=c4(d5(i1(t)),e*u2,c,u0.Polygon,2,r*u2);return p5(a).filter(s=>s.length>=3)}function a4(t,e){if(!t.length||e<=0)return[];let n=c4(dt(t),e/2*u2,U0.Round,u0.Round,2,.01*u2);return p5(n)}function F0(t){if(!t.length)return[];let e=new f5,n=new S2;n.addSubject(d5(t)),n.execute(t0.Union,_1.NonZero,e);let r=[],c=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),c(h)}r.push(p5(o))}};return c(e),r}function M1(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 mt(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 i=0,o=c.length-1;i<c.length;o=i++){let l=c[o][0]-a,h=c[o][1]-s,u=c[i][0]-a,f=c[i][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 T3(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 m5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function ht(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 i=s.map(o=>m5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>m5(e,i)))});return r}function u3(t,e){return{layers:ht(t.layers,e),parts:t.parts.map(n=>({...n,layers:ht(n.layers,e)}))}}function A2(t){let e=O0();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 s2="\0hidden";function ut(t,e){let n={regions:[],lines:[]};for(let[a,s]of t)if(a!==s2){for(let i of s.regions)n.regions.push(i);for(let i of s.lines)n.lines.push(i)}let r=new Map([[e,n]]),c=t.get(s2);return c&&e!==s2&&r.set(s2,c),r}function g5(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:ut(t.layers,e),parts:t.parts.map(n=>({...n,layers:ut(n.layers,e)}))}}function z0(t){let e=1/0,n=1/0,r=-1/0,c=-1/0;for(let a of t)for(let[s,i]of a)s<e&&(e=s),i<n&&(n=i),s>r&&(r=s),i>c&&(c=i);return e===1/0?null:[e,n,r,c]}function X0(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 z0(n)}function s4(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]),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 pt(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 I3(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 gt(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[i,o,l]of s)for(let h=0;h<=c;h++){let u=(l+90*h/c)*Math.PI/180;a.push([i+n*Math.cos(u),o+n*Math.sin(u)])}return a}function we(t,e){let n=i1(t);for(let r=0;r<100;r++){let c=F0(n);if(c.length<=1)return n;let a=i=>i.reduce((o,l)=>o+M1(l),0);c.sort((i,o)=>a(o)-a(i));let s=[];for(let i=1;i<c.length;i++){let o=1/0,l=[0,0],h=[0,0];for(let[b,x]of c[i][0])for(let M=0;M<c.length;M++)if(M!==i)for(let w of c[M])for(let k=0,z=w.length-1;k<w.length;z=k++){let[S,A]=w[z],[L,C]=w[k],P=L-S,R=C-A,q=P*P+R*R,T=q?Math.max(0,Math.min(1,((b-S)*P+(x-A)*R)/q)):0,B=S+T*P,X=A+T*R,Z=Math.hypot(b-B,x-X);Z<o&&([o,l,h]=[Z,[b,x],[B,X]])}if(!Number.isFinite(o))continue;let u=h[0]-l[0],f=h[1]-l[1],d=Math.hypot(u,f);d<1e-9?[u,f]=[0,1]:[u,f]=[u/d,f/d];let[m,g]=[-f*(e/2),u*(e/2)],p=[l[0]-u*(e/2),l[1]-f*(e/2)],v=[h[0]+u*(e/2),h[1]+f*(e/2)],y=[[p[0]-m,p[1]-g],[v[0]-m,v[1]-g],[v[0]+m,v[1]+g],[p[0]+m,p[1]+g]];s.push(M1(y)<0?y.reverse():y)}if(!s.length)return n;n=i1([...n,...s])}return n}function I9(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 vt(t){let{spacing:e,step:n,box:r}=t,c=e/2,a=e,s=new Map,i=[],o=[],l=[],h=[],u=[],f=(C,P)=>Math.floor((C-r[0])/a)*1000003+Math.floor((P-r[1])/a),d=(C,P,R)=>{let q=f(C[0],C[1]),T=i.length;i.push(C[0]),o.push(C[1]),l.push(P),h.push(R);let B=s.get(q);B?B.push(T):s.set(q,[T])},m=Math.ceil(2*e/n)+2,g=(C,P,R=-1,q=0)=>{let T=Math.floor((C[0]-r[0])/a),B=Math.floor((C[1]-r[1])/a);for(let X=T-1;X<=T+1;X++)for(let Z=B-1;Z<=B+1;Z++){let h1=s.get(X*1000003+Z);if(h1)for(let H of h1){let U=l[H];if(!(!u[U]&&U!==R)&&!(U===R&&Math.abs(h[H]-q)<m)&&Math.hypot(i[H]-C[0],o[H]-C[1])<P)return!1}}return!0},p=[],v=0,y=Math.ceil(4*(r[2]-r[0]+r[3]-r[1]+e)/n+2*m),b=(C,P)=>{let R=t.dir(C);if(!R)return null;let q=[C[0]+P*R[0]*n/2,C[1]+P*R[1]*n/2],T=t.dir(q)??R;return T[0]*R[0]+T[1]*R[1]<0?null:[C[0]+P*T[0]*n,C[1]+P*T[1]*n]},x=C=>{let P=p.length;u[P]=!1,d(C,P,0);let R=[[],[]];for(let[B,X]of[[0,1],[1,-1]]){let Z=C;for(let h1=1;h1<=y;h1++){let H=b(Z,X);if(!H)break;let U=X*h1;if(!t.inside(H)){R[B].push(H);break}if(!g(H,c,P,U))break;if(R[B].push(H),d(H,P,U),++v>t.maxPoints)throw new Error(`the lines have more than ${t.maxPoints} points: use a larger spacing or step`);t.tick(),Z=H}}let q=[...R[1].reverse(),C,...R[0]],T=0;for(let B=1;B<q.length;B++)T+=Math.hypot(q[B][0]-q[B-1][0],q[B][1]-q[B-1][1]);return p.push(q),q.length<2||T<t.minLength?null:(u[P]=!0,q)},M=I9(t.seed),w=[];for(let C=r[0]+e/2;C<r[2];C+=e)for(let P=r[1]+e/2;P<r[3];P+=e)w.push([C+(M()-.5)*e,P+(M()-.5)*e]);for(let C=w.length-1;C>0;C--){let P=Math.floor(M()*(C+1));[w[C],w[P]]=[w[P],w[C]]}let k=[],z=[],S=Math.max(1,Math.round(e/(2*n))),A=C=>{if(!t.inside(C)||!g(C,e)||!t.dir(C))return;let P=x(C);P&&(k.push(P),z.push(P))},L=0;for(;;){for(;z.length;){let C=z.shift();for(let P=0;P<C.length;P+=S){let R=C[Math.max(0,P-1)],q=C[Math.min(C.length-1,P+1)],T=Math.hypot(q[0]-R[0],q[1]-R[1]);if(T===0)continue;let B=-(q[1]-R[1])/T,X=(q[0]-R[0])/T;for(let Z of[1,-1])A([C[P][0]+Z*B*e,C[P][1]+Z*X*e])}}if(L>=w.length)break;A(w[L++])}return k}function yt(t,e,n,r,c,a,s){let i=(p,v)=>t[v*e+p],o=(p,v)=>(v*e+p)*2,l=(p,v)=>(v*e+p)*2+1,h=p=>{let v=p>>1,y=v%e,b=(v-y)/e,x=i(y,b),M=p&1?i(y,b+1):i(y+1,b),w=x===M?.5:(s-x)/(M-x);return p&1?[r+y*a,c+(b+w)*a]:[r+(y+w)*a,c+b*a]},u=new Map,f=(p,v)=>{for(let[y,b]of[[p,v],[v,p]]){let x=u.get(y);x?x.push(b):u.set(y,[b])}};for(let p=0;p+1<n;p++)for(let v=0;v+1<e;v++){let y=i(v,p),b=i(v+1,p),x=i(v+1,p+1),M=i(v,p+1);if(Number.isNaN(y+b+x+M))continue;let w=(y>=s?1:0)|(b>=s?2:0)|(x>=s?4:0)|(M>=s?8:0);if(w===0||w===15)continue;let k=o(v,p),z=l(v+1,p),S=o(v,p+1),A=l(v,p);if(w===5||w===10){let C=(y+b+x+M)/4>=s;w===5===C?(f(k,z),f(A,S)):(f(A,k),f(z,S));continue}let L=[];(w&1)!==(w&2)>>1&&L.push(k),(w&2)>>1!==(w&4)>>2&&L.push(z),(w&4)>>2!==(w&8)>>3&&L.push(S),(w&8)>>3!==(w&1)&&L.push(A),L.length===2&&f(L[0],L[1])}let d=new Set,m=p=>{let v=[h(p)];d.add(p);let y=p;for(;;){let b=(u.get(y)??[]).find(x=>!d.has(x));if(b===void 0)return(u.get(y)??[]).includes(p)&&v.length>2&&v.push(v[0]),v;d.add(b),v.push(h(b)),y=b}},g=[];for(let[p,v]of u)v.length===1&&!d.has(p)&&g.push(m(p));for(let p of u.keys())d.has(p)||g.push(m(p));return g.map(p=>p.filter((v,y)=>y===0||v[0]!==p[y-1][0]||v[1]!==p[y-1][1])).filter(p=>p.length>=2&&!(p.length===2&&p[0][0]===p[1][0]&&p[0][1]===p[1][1]))}function bt(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),i=l=>r(l[0])===r(l[l.length-1]),o=[];for(let l=0;l<n.length;l++){if(s[l])continue;s[l]=!0;let h=n[l];if(!i(h))for(let u=0;u<2;u++){for(;;){let f=h[h.length-1],d=(c.get(r(f))??[]).find(p=>!s[p]);if(d===void 0)break;s[d]=!0;let m=n[d],g=r(m[0])===r(f)?m:[...m].reverse();if(h=h.concat(g.slice(1)),i(h))break}if(i(h))break;h=h.reverse()}o.push(h)}return V9(o)}function V9(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 g of t)for(let p of[g[0],g[g.length-1]])n=Math.min(n,p[0]),r=Math.min(r,p[1]),c=Math.max(c,p[0]),a=Math.max(a,p[1]);let s=Math.max((c-n+a-r)/Math.sqrt(e),1e-6),i=g=>Math.floor((g-n)/s),o=g=>Math.floor((g-r)/s),l=i(c)+1,h=o(a)+1,u=new Map;t.forEach((g,p)=>{for(let v of[g[0],g[g.length-1]]){let y=o(v[1])*l+i(v[0]),b=u.get(y);b?b[b.length-1]!==p&&b.push(p):u.set(y,[p])}});let f=new Array(e).fill(!1),d=[],m=[0,0];for(let g=0;g<e;g++){let p=-1,v=1/0,y=!1,b=Math.min(Math.max(i(m[0]),0),l-1),x=Math.min(Math.max(o(m[1]),0),h-1);for(let w=0;w<=Math.max(l,h);w++){for(let k=b-w;k<=b+w;k++)for(let z=x-w;z<=x+w;z++)if(Math.max(Math.abs(k-b),Math.abs(z-x))===w&&!(k<0||z<0||k>=l||z>=h))for(let S of u.get(z*l+k)??[]){if(f[S])continue;let A=t[S],L=Math.hypot(A[0][0]-m[0],A[0][1]-m[1]),C=Math.hypot(A[A.length-1][0]-m[0],A[A.length-1][1]-m[1]);L<v&&([p,v,y]=[S,L,!1]),C<v&&([p,v,y]=[S,C,!0])}if(p>=0&&v<=w*s)break}if(p<0){for(let w=0;w<e;w++)if(!f[w]){p=w;break}}f[p]=!0;let M=y?[...t[p]].reverse():t[p];d.push(M),m=M[M.length-1]}return d}function xt(t){let e=[],n=1/0,r=-1/0;for(let i of t)for(let o=0,l=i.length-1;o<i.length;l=o++)e.push([i[l][0],i[l][1],i[o][0],i[o][1]]),n=Math.min(n,i[o][1]),r=Math.max(r,i[o][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(([,i,,o],l)=>{let h=Math.max(0,Math.min(c-1,Math.floor((Math.min(i,o)-n)/a))),u=Math.max(0,Math.min(c-1,Math.floor((Math.max(i,o)-n)/a)));for(let f=h;f<=u;f++)s[f].push(l)}),([i,o])=>{if(o<n||o>r)return!1;let l=0;for(let h of s[Math.max(0,Math.min(c-1,Math.floor((o-n)/a)))]){let[u,f,d,m]=e[h];f<=o?m>o&&(d-u)*(o-f)-(i-u)*(m-f)>0&&l++:m<=o&&(d-u)*(o-f)-(i-u)*(m-f)<0&&l--}return l!==0}}var Mt=Math.PI/180;function q1(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 i4(t,e){let n=Math.cos(e*Mt),r=Math.sin(e*Mt);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 ze=t=>Math.abs(t)<1e-12?0:t;function Q0(t){if(t.matrix)return t.matrix.map(ze);let[e,n,r]=t.rotate,c=q1(i4(2,r),q1(i4(1,n),i4(0,e)));return c[3]=t.at[0],c[7]=t.at[1],c[11]=t.at[2],c.map(ze)}function $2(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 v5(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 o4(t){let[e,n,r,c]=[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),r=Math.max(r,s),c=Math.max(c,i);return[e,n,r,c]}function zt(t){let[e,n,r,c]=o4(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,r])for(let o of[n,c])for(let l of[0,t.thickness]){let h=$2(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 St(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(zt))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=>o4(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),c[0]-r[0]),i=0,o=0,l=0;return e.map((h,u)=>{let[f,d,m,g]=a[u];i>0&&i+m-f>s&&(i=0,o+=l+n,l=0);let p=[1,0,0,c[0]+n+i-f,0,1,0,r[1]+o-d,0,0,1,r[2],0,0,0,1];return i+=m-f+n,l=Math.max(l,g-d),{...h,matrix:p.map(ze)}})}var H9=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),V3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],l4=(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]],ke=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],O3=t=>[t[2],t[6],t[10]],wt=t=>[t[3],t[7],t[11]],O9=(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 H3(t,e,n){let r=n[0]*n[0]+n[1]*n[1],c=[];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],m=o[1]+(l[1]-o[1])*f-e[1];c.push((d*n[0]+m*n[1])/r)}return c.sort((a,s)=>a-s)}function Se(t,e,n){let r=0,c=0,a=0,s=0,i=0;for(;s+1<t.length&&i+1<e.length;){let o=Math.max(t[s],e[i]),l=Math.min(t[s+1],e[i+1])-o;l>n&&(r+=l,l>a&&(a=l,c=o+l/2)),t[s+1]<e[i+1]?s+=2:i+=2}return{total:r,mid:c,run:a}}function F9(t,e){let[n,r,c]=$2(v5(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 i=0,o=s.length-1;i<s.length;o=i++){let[l,h]=s[o],[u,f]=s[i];h>r!=f>r&&n<l+(u-l)*(r-h)/(f-h)&&(a=!a)}return a}var h4=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 i=0;i<3;i++)n[i]+=a[i]*s;e+=s}for(let a=0;a<3;a++)n[a]/=e;if(this.parts.length&&this.parts.every(a=>F9(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 u4(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},(i,o)=>c+(a-c)*(o+.5)/s),size:(a-c)/s}}function kt(t,e,n){let r=$2(t,e[0],e[1],e[2]),c=O9(t,n);return[[r[0],r[1]],[c[0],c[1]]]}function Lt(t,e,n,r,c,a,s,i=!1){let o=O3(t.matrix),l=O3(e.matrix),h=l4(o,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=l4(f,o),m=V3(l,d),g=wt(t.matrix),p=V3(l,wt(e.matrix)),v=1/0,y=-1/0;for(let z of e.outline)for(let[S,A]of z)for(let L of[0,e.thickness]){let C=$2(e.matrix,S,A,L),P=V3(o,[C[0]-g[0],C[1]-g[1],C[2]-g[2]]);P<v&&(v=P),P>y&&(y=P)}let b=u4(Math.max(0,v),Math.min(t.thickness,y),c,a),x=1/0,M=-1/0;for(let z of t.outline)for(let[S,A]of z){let L=$2(t.matrix,S,A,0),C=V3(d,[L[0]-g[0],L[1]-g[1],L[2]-g[2]]);C<x&&(x=C),C>M&&(M=C)}let w=0,k=new h4([t,e]);for(let z of b.at){let S=ke(g,o,z),A=(p-V3(l,S))/m,L=(p+e.thickness-V3(l,S))/m,C=u4(Math.max(x,Math.min(A,L)),Math.min(M,Math.max(A,L)),c,a);for(let P of C.at){let R=ke(S,d,P),[q,T]=kt(n,R,f),[B,X]=kt(r,R,f),Z=Se(H3(t.outline,q,T),H3(e.outline,B,X),c);if(w+=Z.total*b.size*C.size,k.see(Z.run,()=>ke(R,f,Z.mid)),w>s&&!i)return k.at}}return w>s?k.at:void 0}function At(t,e,n,r,c,a,s=!1){let i=[0,1,2,3].flatMap(A=>[0,1,2,3].map(L=>{let C=0;for(let P=0;P<4;P++)C+=n[A*4+P]*e.matrix[P*4+L];return C})),o=i[11],l=i[11]+i[10]*e.thickness,h=Math.min(t.thickness,Math.max(o,l))-Math.max(0,Math.min(o,l));if(h<=r)return;let u=Math.max(0,Math.min(o,l))+h/2,f=new h4([t,e]),d=e.outline.map(A=>A.map(([L,C])=>[i[0]*L+i[1]*C+i[3],i[4]*L+i[5]*C+i[7]])),[m,g,p,v]=o4(t.outline),[y,b,x,M]=o4(d),w=u4(Math.max(g,b),Math.min(v,M),r,c),k=0;for(let A of w.at){let L=Se(H3(t.outline,[0,A],[1,0]),H3(d,[0,A],[1,0]),r);if(k+=L.total*w.size*h,f.see(L.run,()=>$2(t.matrix,L.mid,A,u)),k>a&&!s)return f.at}let z=u4(Math.max(m,y),Math.min(p,x),r,c),S=0;for(let A of z.at){let L=Se(H3(t.outline,[A,0],[0,1]),H3(d,[A,0],[0,1]),r);if(S+=L.total*z.size*h,f.see(L.run,()=>$2(t.matrix,A,L.mid,u)),S>a&&!s)return f.at}return k>a||S>a?f.at:void 0}function Ct(t,e=1/0,n=.05,r=.25,c=.1){let a=t.map(zt),s=t.map(h=>v5(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(!H9(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[m,g]=f<d?[t[f],t[d]]:[t[d],t[f]],[p,v]=f<d?[s[f],s[d]]:[s[d],s[f]],b=Math.hypot(...l4(O3(m.matrix),O3(g.matrix)))<1e-9?At(m,g,p,n,r,c):Lt(m,g,p,v,n,r,c);b&&o.push([m,g,b])}return{found:o,complete:!0}}function Pt(t,e,n=.05,r=.25,c=.1){let a=Math.hypot(...l4(O3(t.matrix),O3(e.matrix)))<1e-9,s=v5(t.matrix);return a?At(t,e,s,n,r,c,!0):Lt(t,e,s,v5(e.matrix),n,r,c,!0)}function B0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var Le=B0(0,0,0);function p0(t){return v5(t)}function Et(t,e,n=t.angle,r=t.x1){let c=r-t.x0;if(!n||!(c>0))return B0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return q1(B0(t.x0,0,s),q1(i4(1,-n),B0(-t.x0-c,0,-s)))}function y5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function f4(t,e){let n=[B0(0,0,0)];for(let r of y5(t))n.push(q1(n[n.length-1],Et(r,e)));return n}function Ae(t,e,n){let r=y5(t),c=f4(r,e);for(let a=r.length-1;a>=0;a--){let s=r[a];if(n[0]>=s.x1)return $2(c[a+1],...n);if(n[0]>s.x0){let i=(n[0]-s.x0)/(s.x1-s.x0),o=q1(c[a],Et(s,e,s.angle*i,n[0]));return $2(o,...n)}}return n}function Tt(t,e){return y5(t).filter(n=>(n.x0+n.x1)/2<e).length}function d4(t){if(!t.bends?.length)return[t];let e=y5(t.bends),n=f4(e,t.thickness),r=1e7,c=[];for(let a=0;a<=e.length;a++){let s=a===0?-r:e[a-1].x1,i=a===e.length?r:e[a].x0;if(!(i>s))continue;let o=[[s,-r],[i,-r],[i,r],[s,r]],l=a0(t.outline,[o]);l.length&&c.push({...t,outline:l,bends:void 0,matrix:q1(t.matrix,n[a])})}return c}var R9=2e3;function Ce(t,e,n=2){if(!e?.length)return F0(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=y5(e).map(f=>[Math.max(f.x0,c),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,m])=>f+(m-d),0),o=Math.max(n,i/R9),l=[];for(let[f,d]of s){let m=Math.max(1,Math.ceil((d-f)/o));for(let g=0;g<=m;g++)l.push(f+(d-f)*g/m)}let h=[-r,...l.sort((f,d)=>f-d),r],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-r],[h[f+1],-r],[h[f+1],r],[h[f],r]];for(let m of F0(a0(t,[d])))u.push(m)}return u}var X2=1e6,m4=.01,b5=t=>M1(t)<0?[...t].reverse():t;function $9(t,e){let n=q1(p0(t.matrix),e.matrix),[r,c]=[n[8],n[9]],a=Math.hypot(r,c);if(a<1e-9)return[];let s=0,i=e.thickness,o=L=>(-n[11]-Math.max(n[10]*s,n[10]*i)+L)/a,l=L=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-L)/a;if(!(l(m4)>o(m4)))return[];let[h,u]=[r/a,c/a],[f,d]=[-u,h],m=(L,C)=>[[h*L-f*X2,u*L-d*X2],[h*C-f*X2,u*C-d*X2],[h*C+f*X2,u*C+d*X2],[h*L+f*X2,u*L+d*X2]],g=1/0,p=-1/0;for(let L of e.outline)for(let[C,P]of L)for(let R of[s,i]){let q=n[8]*C+n[9]*P+n[10]*R+n[11];q<g&&(g=q),q>p&&(p=q)}if(Math.min(t.thickness,p)-Math.max(0,g)<Math.min(1,t.thickness/2))return[];let v=(L,C)=>a0(e.outline,[b5(m(L,C))]).filter(P=>Math.abs(M1(P))>1e-6),y=v(o(m4),l(m4));if(!y.length)return[];let b=Math.abs(l(0)-o(0))+1,x=L=>{let C=L.map(([q,T])=>[q-h*b,T-u*b]),P=L.map(([q,T])=>[q+h*b,T+u*b]),R=[b5(C),b5(P)];for(let q=0;q<L.length;q++){let T=(q+1)%L.length,B=[C[q],C[T],P[T],P[q]];Math.abs(M1(B))>1e-12&&R.push(b5(B))}return R},M=i1(y.flatMap(x),"nonzero"),w=a0(v(o(0),l(0)),M).filter(L=>Math.abs(M1(L))>1e-6);if(!w.length)return[];let k=L=>([C,P])=>[n[0]*C+n[1]*P+n[2]*L+n[3],n[4]*C+n[5]*P+n[6]*L+n[7]],z=n[0]*n[5]-n[1]*n[4]<0,S=L=>w.map(C=>{let P=C.map(k(L));return z?P.reverse():P}),A=[];for(let L of w)for(let C=0;C<L.length;C++){let P=L[C],R=L[(C+1)%L.length],q=[k(s)(P),k(s)(R),k(i)(R),k(i)(P)];Math.abs(M1(q))>1e-9&&A.push(b5(q))}return i1([...S(s),...S(i),...A],"nonzero")}function It(t,e,n){let r=[];for(let a of e)for(let s of $9(t,a))r.push(s);if(!r.length)return[];let c=F0(a0(i1(r),t.outline)).filter(a=>a.reduce((s,i)=>s+M1(i),0)>1e-4);return c.length?n0(c.flat(),n/2,"miter"):[]}var x5=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Vt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],D9=(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]],Ht=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},M5={turn:.3,press:-.1};function q9(t,e){let n=Ht(x5(t.to,t.from)),r=x5(t.up,n.map(o=>o*Vt(t.up,n)));Math.hypot(...r)<1e-9&&(r=Math.abs(n[0])<.9?[1,0,0]:[0,1,0]);let c=Ht(x5(r,n.map(o=>o*Vt(r,n)))),a=D9(c,n);if(Array.isArray(t.size)){let[o,l]=[t.size[0]/2+e/2,t.size[1]/2+e/2];return[[-o,-l],[o,-l],[o,l],[-o,l]].map(([h,u])=>[a[0]*h+c[0]*u,a[1]*h+c[1]*u,a[2]*h+c[2]*u])}let s=t.size/2+e/2,i=t.sides<12?t.sides:64;return Array.from({length:i},(o,l)=>{let h=2*Math.PI*l/i,[u,f]=[Math.cos(h)*s,Math.sin(h)*s];return[a[0]*f+c[0]*u,a[1]*f+c[1]*u,a[2]*f+c[2]*u]})}function Ot(t,e,n){let r=x5(e.to,e.from);if(!(Math.hypot(...r)>1e-9))return;let c=p0(t.matrix),a=o=>[c[0]*o[0]+c[1]*o[1]+c[2]*o[2]+c[3],c[4]*o[0]+c[5]*o[1]+c[6]*o[2]+c[7],c[8]*o[0]+c[9]*o[1]+c[10]*o[2]+c[11]],s=x5(a(r),a([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let i=[];for(let o of q9(e,n)){let l=a([e.from[0]+o[0],e.from[1]+o[1],e.from[2]+o[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])i.push([l[0]+s[0]*f,l[1]+s[1]*f])}return i.length>=3?s4(i):void 0}var p4=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],N9=(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]],Ft=t=>[t[2],t[6],t[10]],Rt=t=>[t[3],t[7],t[11]];function $t(t,e,n){let r=[];for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let i=c[s],o=c[a],l=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]),h=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]);if(l>0==h>0)continue;let u=l/(l-h);r.push((i[0]+(o[0]-i[0])*u-e[0])*n[0]+(i[1]+(o[1]-i[1])*u-e[1])*n[1])}return r.sort((c,a)=>c-a)}function Dt(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 U9(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[i,o]=c[s],[l,h]=c[a];o>n!=h>n&&e<i+(l-i)*(n-o)/(h-o)&&(r=!r)}return r}function qt(t,e,n){let r={a:[],b:[],thin:0},c=Ft(t.matrix),a=Ft(e.matrix),s=N9(c,a),i=Math.hypot(...s);if(i<1e-6)return r;let o=Math.abs(p4(c,a)),l=[s[0]/i,s[1]/i,s[2]/i],h=p4(c,Rt(t.matrix))+t.thickness/2,u=p4(a,Rt(e.matrix))+e.thickness/2,f=p4(c,a),d=1-f*f,m=(h-u*f)/d,g=(u-h*f)/d,p=[m*c[0]+g*a[0],m*c[1]+g*a[1],m*c[2]+g*a[2]],v=A=>{let L=p0(A.matrix);return[[L[0]*p[0]+L[1]*p[1]+L[2]*p[2]+L[3],L[4]*p[0]+L[5]*p[1]+L[6]*p[2]+L[7]],[L[0]*l[0]+L[1]*l[1]+L[2]*l[2],L[4]*l[0]+L[5]*l[1]+L[6]*l[2]]]},[y,b]=v(t),[x,M]=v(e),w=$t(t.outline,y,b),k=$t(e.outline,x,M),z=(e.thickness+t.thickness*o)/i+n,S=(t.thickness+e.thickness*o)/i+n;for(let A=0;A+1<w.length;A+=2)for(let L=0;L+1<k.length;L+=2){let C=Math.max(w[A],k[L]),P=Math.min(w[A+1],k[L+1]);if(!(P-C>.01))continue;let R=(C+P)/2,[q,T]=Dt(w,R),[B,X]=Dt(k,R),Z=Math.max(T-R,R-B)<=Math.max(R-q,X-R),h1=(Y,Q,W,F1,L1,g1)=>{let X1=[-W[1],W[0]],D1=(t1,V)=>[Q[0]+W[0]*(R+L1*t1)+X1[0]*V,Q[1]+W[1]*(R+L1*t1)+X1[1]*V],E=g1+F1+1,D=[D1(0,-F1/2),D1(E,-F1/2),D1(E,F1/2),D1(0,F1/2)];M1(D)<0&&D.reverse();let e1=D1(Math.min(.01,g1/2),0),u1=F0(a0([D],Y.outline)).find(t1=>U9(t1,e1));if(!(!u1||!(u1.reduce((t1,V)=>t1+M1(V),0)>1e-4)))return a0(n0(u1,.05,"miter"),[D])},H=h1(t,y,b,z,Z?1:-1,Z?T-R:R-q),U=h1(e,x,M,S,Z?-1:1,Z?R-B:X-R);if(!H||!U){r.thin++;continue}r.a.push(...H),r.b.push(...U)}return r}var i2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",f2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",Ut=t=>typeof t=="number",_0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",e2=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Pe(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)Pe(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function g4(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 g0(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 Nt=(t,e,n)=>i2(t)&&i2(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:_0(t)&&_0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([r,c])=>e.fields.has(r)&&F3(c,e.fields.get(r),n)):t===e;function F3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return Nt(t,e,n);let r=new Map,c=[],a=(s,i)=>{let o=r.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||r.set(s,o=new Set),o.add(i),c.push([s,i,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 i=s[0][s[2]],o=s[1][s[2]++];if(n?.(),Array.isArray(i)&&Array.isArray(o)?!a(i,o):!Nt(i,o,n))return!1}return!0}function R0(t){return t===void 0?"undef":Array.isArray(t)?"list":i2(t)?"range":f2(t)?"function":_0(t)?"record":typeof t}function B9(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?D2(t):i2(t)?`[${D2(t.start)}:${D2(t.step)}:${D2(t.end)}]`:f2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:_0(t)?"{}":String(t)}function R3(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=[],i=t;for(;;){Array.isArray(i)?(a("["),s.push({items:i,i:0,close:"]"})):_0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(B9(i));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]} = `),i=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||c>e)break}let o=r.join("");return c>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function Bt(t,e,n){let r=[],c=0;for(let a of t){r.length&&(c+=e.length);let s=R3(a,n-c);if(!s.whole)return;c+=s.text.length,r.push(s.text)}return r.join(e)}function C0(t){let e=R3(t,200,!0);return e.whole?e.text:e.text+"..."}var v0=t=>typeof t=="string"?t:C0(t);function q0(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 D2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function $3(t,e=.02){let n=[],r=[],c=[],a=[0,0],s=[0,0],i=l=>{c.length>=2&&(l?n:r).push(c),c=[]},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],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=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 m=d/f,g=1-m;c.push([g*g*h+2*g*m*l.x1+m*m*l.x,g*g*u+2*g*m*l.y1+m*m*l.y])}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 m=d/f,g=1-m;c.push([g*g*g*h+3*g*g*m*l.x1+3*g*m*m*l.x2+m*m*m*l.x,g*g*g*u+3*g*g*m*l.y1+3*g*m*m*l.y2+m*m*m*l.y])}s=[l.x,l.y]}else i(!0),s=a,c=[a];return i(!1),{closed:n,open:r}}function D3(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,i="",o=0,l=0,h=0,u=0,f=0,d=0,m=0,g=0,p="",v=()=>{let x=c[s++];if(x===void 0||r(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},y=()=>{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{b()}catch(x){if(!n)throw x;n(x.message)}return a;function b(){for(;s<c.length;){if(r(c[s]))i=c[s++];else if(i){if(i==="Z"||i==="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=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 C=p==="C"||p==="S";z=C?2*o-f:o,S=C?2*l-d:l}let A=w+v(),L=k+v();o=w+v(),l=k+v(),f=A,d=L,a.push({type:"C",x1:z,y1:S,x2:A,y2:L,x:o,y:l})}else if(M==="Q"||M==="T"){let z,S;if(M==="Q")z=w+v(),S=k+v();else{let A=p==="Q"||p==="T";z=A?2*o-m:o,S=A?2*l-g:l}o=w+v(),l=k+v(),m=z,g=S,a.push({type:"Q",x1:z,y1:S,x:o,y:l})}else if(M==="A"){let z=v(),S=v(),A=v(),L=y(),C=y(),P=w+v(),R=k+v();a.push(..._9(o,l,z,S,A,L,C,P,R,e)),o=P,l=R}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);p=M}}}function _9(t,e,n,r,c,a,s,i,o,l=Math.PI/2){if(n===0||r===0||t===i&&e===o)return[{type:"L",x:i,y:o}];n=Math.abs(n),r=Math.abs(r);let h=c*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-i)/2,m=(e-o)/2,g=u*d+f*m,p=-f*d+u*m,v=g*g/(n*n)+p*p/(r*r);v>1&&(n*=Math.sqrt(v),r*=Math.sqrt(v));let y=n*n*r*r-n*n*p*p-r*r*g*g,b=n*n*p*p+r*r*g*g,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*p/r,w=-x*r*g/n,k=u*M-f*w+(t+i)/2,z=f*M+u*w+(e+o)/2,S=(T,B,X,Z)=>Math.atan2(T*Z-B*X,T*X+B*Z),A=S(1,0,(g-M)/n,(p-w)/r),L=S((g-M)/n,(p-w)/r,(-g-M)/n,(-p-w)/r);!s&&L>0&&(L-=2*Math.PI),s&&L<0&&(L+=2*Math.PI);let C=Math.ceil(Math.abs(L)/l),P=[],R=T=>[k+n*Math.cos(T)*u-r*Math.sin(T)*f,z+n*Math.cos(T)*f+r*Math.sin(T)*u],q=T=>[-n*Math.sin(T)*u-r*Math.cos(T)*f,-n*Math.sin(T)*f+r*Math.cos(T)*u];for(let T=0;T<C;T++){let B=A+L*T/C,X=A+L*(T+1)/C,Z=4/3*Math.tan((X-B)/4),h1=R(B),H=R(X),U=q(B),Y=q(X);P.push({type:"C",x1:h1[0]+Z*U[0],y1:h1[1]+Z*U[1],x2:H[0]-Z*Y[0],y2:H[1]-Z*Y[1],x:H[0],y:H[1]})}return P}var E0=Math.PI/180;function Zt(t,e,n){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 r=0;r<Math.min(t.length,e.length);r++){let c=Zt(t[r],e[r],n);if(c)return c}return t.length-e.length}throw new Error(`${n}() can only order numbers, strings or lists of them, not ${R0(t)} and ${R0(e)}`)}function Ve(t,e,n){let r=$0(t,e,n);return(r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.flatMap(a=>$0(a,e,n)):r).map(a=>{if(!Array.isArray(a)||a.length<2)throw new Error(`${e}() needs points [x, y], got ${R0(a)}`);return[z1(a[0],e),z1(a[1],e)]})}function j9(t,e,n){let r=$0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(c=>Ve(c,e,n)):[Ve(r,e,n)]}var w1=(t,e,n)=>({params:t.replace("...","").split(",").map(r=>r.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function Yt(t,e,n){return t.order?[]:t.params.filter((r,c)=>c<e.length&&n.has(r))}function Jt(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 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 Ee(t,e,n,r){let c=Bt(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 z1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${R0(t)}`);return t}function $0(t,e,n){if(Array.isArray(t))return t;if(i2(t))return g4(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${R0(t)}`)}var G9=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function Kt(t,e,n){if(G9.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(i2(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 Z0=t=>w1("x",e=>typeof e[0]=="number"?o2(t(e[0])):void 0);function o2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function Qt(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 v4=new Map;function W9(t){let e=v4.get(t);if(e)return e;let n=Qt(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 v4.size>64&&v4.clear(),v4.set(t,e),e}var Te=t=>t*t*t*(t*(t*6-15)+10);function Z2(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 X9(t,e,n,r){let c=W9(r),a=Math.floor(t),s=Math.floor(e),i=Math.floor(n);t-=a,e-=s,n-=i;let o=a&255,l=s&255,h=i&255,u=Te(t),f=Te(e),d=Te(n),m=c[o]+l,g=c[m]+h,p=c[m+1]+h,v=c[o+1]+l,y=c[v]+h,b=c[v+1]+h,x=(M,w,k)=>w+M*(k-w);return x(d,x(f,x(u,Z2(c[g],t,e,n),Z2(c[y],t-1,e,n)),x(u,Z2(c[p],t,e-1,n),Z2(c[b],t-1,e-1,n))),x(f,x(u,Z2(c[g+1],t,e,n-1),Z2(c[y+1],t-1,e,n-1)),x(u,Z2(c[p+1],t,e-1,n-1),Z2(c[b+1],t-1,e-1,n-1))))}function _t(t,e,n){let r=t.length===1&&Array.isArray(t[0])?t[0]:t;if(r.length)return e(r.map(c=>z1(c,n)))}var k5={abs:Z0(Math.abs),sign:Z0(Math.sign),floor:Z0(Math.floor),ceil:Z0(Math.ceil),round:Z0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:Z0(Math.sqrt),exp:Z0(Math.exp),ln:Z0(Math.log),log:w1("x, base",(t,e)=>e.given<2?o2(Math.log10(z1(t[0],"log"))):Math.log(z1(t[0],"log"))/Math.log(z1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:Z0(t=>Math.sin(t*E0)),cos:Z0(t=>Math.cos(t*E0)),tan:Z0(t=>Math.tan(t*E0)),asin:Z0(t=>Math.asin(t)/E0),acos:Z0(t=>Math.acos(t)/E0),atan:Z0(t=>Math.atan(t)/E0),atan2:w1("y, x",t=>o2(Math.atan2(z1(t[0],"atan2"),z1(t[1],"atan2"))/E0)),pow:w1("x, y",t=>Math.pow(z1(t[0],"pow"),z1(t[1],"pow"))),min:w1("values...",t=>_t(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:w1("values...",t=>_t(t,e=>e.reduce((n,r)=>r>n?r:n,-1/0),"max")),clamp:w1("x, low, high",t=>Math.min(Math.max(z1(t[0],"clamp"),z1(t[1],"clamp")),z1(t[2],"clamp"))),lerp:w1("a, b, t",t=>{let e=z1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((r,c)=>z1(r,"lerp")+(z1(n[c],"lerp")-z1(r,"lerp"))*e)}return z1(t[0],"lerp")+(z1(t[1],"lerp")-z1(t[0],"lerp"))*e}),norm:w1("v",(t,e)=>Math.sqrt($0(t[0],"norm",e).reduce((n,r)=>n+z1(r,"norm")**2,0))),cross:w1("a, b",(t,e)=>{let n=$0(t[0],"cross",e).map(c=>z1(c,"cross")),r=$0(t[1],"cross",e).map(c=>z1(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:w1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:_0(t[0])?t[0].fields.size:void 0),keys:w1("record",t=>_0(t[0])?[...t[0].fields.keys()]:void 0),merge:w1("a, b",t=>{if(!_0(t[0])||!_0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:w1("...",(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:w1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...$0(t[0],"reverse",e)].reverse()),sort:w1("values, key",(t,e)=>{let n=$0(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)=>Zt(a[0],s[0],"sort")).map(([,a])=>a)}),fold:w1("values, initial, fn",(t,e)=>{let n=t[1];for(let r of $0(t[0],"fold",e))n=e.apply(t[2],[n,r]);return n}),scan:w1("values, initial, fn",(t,e)=>{let n=t[1];return $0(t[0],"scan",e).map(r=>n=e.apply(t[2],[n,r]))}),bounds:w1("points",(t,e)=>{let n=Ve(t[0],"bounds",e);if(!n.length)return;let[r,c,a,s]=[1/0,1/0,-1/0,-1/0];for(let[i,o]of n)r=Math.min(r,i),c=Math.min(c,o),a=Math.max(a,i),s=Math.max(s,o);return[r,c,a,s]}),crossings:w1("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=z1(n?t[2]:t[1],"crossings"),c=[];for(let a of j9(t[0],"crossings",e))for(let s=0,i=a.length-1;s<a.length;i=s++){let[o,l]=n?[a[i][1],a[i][0]]:a[i],[h,u]=n?[a[s][1],a[s][0]]:a[s];o>r!=h>r&&c.push(l+(u-l)*(r-o)/(h-o))}return c.sort((a,s)=>a-s)}),sum:w1("values",(t,e)=>$0(t[0],"sum",e).reduce((n,r)=>n+z1(r,"sum"),0)),slice:w1("value, start, end",(t,e)=>{let r=(typeof t[0]=="string"?[...t[0]]:$0(t[0],"slice",e)).slice(z1(t[1]??0,"slice"),t[2]===void 0?void 0:z1(t[2],"slice"));return typeof t[0]=="string"?r.join(""):r}),str:w1("...",(t,e)=>Ee(t,"",e,"str")),chr:w1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(z1(e,"chr"))).join("")),ord:w1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:w1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:w1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:w1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:w1("values, separator",(t,e)=>Ee($0(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:w1("value, list",(t,e)=>{let r=(typeof t[1]=="string"?[...t[1]]:$0(t[1],"search",e)).findIndex(c=>F3(c,t[0],e.step));return r<0?void 0:r}),contains:w1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(Ee([t[1]],"",e,"contains")):$0(t[0],"contains",e).some(n=>F3(n,t[1],e.step))),lookup:w1("x, table",(t,e)=>{let n=z1(t[0],"lookup"),r=$0(t[1],"lookup",e);if(!r.length)return;let c=r.map(a=>[z1(a[0],"lookup"),z1(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,i]=c[a-1],[o,l]=c[a];return i+(n-s)/(o-s)*(l-i)}return c[c.length-1][1]}),rands:w1("min, max, count, seed",t=>{let e=z1(t[0],"rands"),n=z1(t[1],"rands"),r=z1(t[2],"rands"),c=Qt(t[3]===void 0?1:z1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(r)),1e6)},()=>e+(n-e)*c())}),noise:w1("x, y, z, seed, octaves",t=>{let e,n=0,r=0;if(Array.isArray(t[0])){let h=t[0];e=z1(h[0],"noise"),n=h[1]===void 0?0:z1(h[1],"noise"),r=h[2]===void 0?0:z1(h[2],"noise")}else e=z1(t[0],"noise"),t[1]!==void 0&&(n=z1(t[1],"noise")),t[2]!==void 0&&(r=z1(t[2],"noise"));let c=Math.floor(t[3]===void 0?1:z1(t[3],"noise")),a=t[4]===void 0?1:Math.floor(z1(t[4],"noise"));if(!(a>=1&&a<=8))throw new Error("noise(): octaves must be 1 to 8");let s=0,i=1,o=0,l=1;for(let h=0;h<a;h++)s+=i*X9(e*l+h*.3713,n*l+h*.6271,r*l+h*.1943,c+h*7919),o+=i,i/=2,l*=2;return o2(s/o)}),is_num:w1("value",t=>Ut(t[0])&&!Number.isNaN(t[0])),is_string:w1("value",t=>typeof t[0]=="string"),is_bool:w1("value",t=>typeof t[0]=="boolean"),is_list:w1("value",t=>Array.isArray(t[0])),is_record:w1("value",t=>_0(t[0])),is_undef:w1("value",t=>t[0]===void 0),is_function:w1("value",t=>f2(t[0])),type_of:w1("value",t=>R0(t[0])),path_length:w1("points",(t,e)=>{let n=w5(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:w1("points, s",(t,e)=>jt(w5(t[0],"point_at",e),z1(t[1],"point_at")).point),heading_at:w1("points, s",(t,e)=>o2(jt(w5(t[0],"heading_at",e),z1(t[1],"heading_at")).heading)),offset_path:w1("points, d, closed",(t,e)=>{let n=w5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),r=z1(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,i=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],m=Math.hypot(f-h,d-u);return[-(d-u)/m,(f-h)/m]},o=n.map(([l,h],u)=>{let f=!c&&u===0,d=!c&&u===s-1,m=i(f?0:(u-1+s)%s),g=i(d?s-2:u),[p,v]=[m[0]+g[0],m[1]+g[1]],y=Math.hypot(p,v);if(y<1e-9)[p,v]=m;else{let b=Math.min(2/(y*y),4/y);[p,v]=[p*b,v*b]}return[o2(l+r*p),o2(h+r*v)]});return a?[...o,o[0]]:o}),train_for:w1("ratio, stages, pinion, wheel",(t,e)=>{let n=z1(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:z1(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,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]=c(t[2],[10,20],"pinion"),[i,o]=c(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})},m=(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(r===1)m([],h);else for(let v=0;v<u.length;v++){let y=u[v][1]/u[v][0];if(r===2)m([u[v]],h/y);else for(let b=v;b<u.length;b++)m([u[v],u[b]],h/y/(u[b][1]/u[b][0]))}if(!f)throw new Error(`train_for(): no train of ${r} stages reaches a ratio of ${n}`);let g=f.stages.map(([v,y])=>l?[y,v]:[v,y]),p=g.reduce((v,[y,b])=>v*b/y,1);return{type:"record",fields:new Map([["stages",g],["ratio",p],["error",p/n-1]])}}),path_points:w1("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:z1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let r=$3(D3(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,i])=>[s,i]))}),spline_points:w1("points, steps, closed",(t,e)=>{let n=w5(t[0],"spline_points",e),r=t[1]===void 0?8:Math.floor(z1(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),He(n,r,t[2]===!0)}),rotation:w1("angles",t=>{let[e,n,r]=Ie(t[0],"rotation");return Q9(Wt(K9(r),Wt(J9(n),Y9(e))))}),euler:w1("matrix",t=>Xt(Z9(t[0],"euler"))),orient:w1("x, z",t=>{let e=Gt(Ie(t[0],"orient"),"orient"),n=Ie(t[1]??[0,0,1],"orient"),r=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=Gt([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 Xt([[e[0],c[0],n[0]],[e[1],c[1],n[1]],[e[2],c[2],n[2]]])})};function w5(t,e,n){return $0(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 jt(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 r=0,c=0;for(;r<n.length-2;r++){let o=Math.hypot(n[r+1][0]-n[r][0],n[r+1][1]-n[r][1]);if(c+o>=e)break;c+=o}let[a,s]=[n[r],n[r+1]],i=(e-c)/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])/E0}}function Ie(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 Gt(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 Z9(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 Y9=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[1,0,0],[0,e,-n],[0,n,e]]},J9=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[e,0,n],[0,1,0],[-n,0,e]]},K9=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[e,-n,0],[n,e,0],[0,0,1]]},Wt=(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])),Q9=t=>t.map(e=>e.map(o2));function Xt(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])/E0;return[0,n,o2(r)]}return[o2(Math.atan2(t[2][1],t[2][2])/E0),o2(Math.asin(e)/E0),o2(Math.atan2(t[1][0],t[0][0])/E0)]}function He(t,e,n=!1){if(t.length<3)return t.map(([s,i])=>[s,i]);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[i,o]=[t[t.length-1],t[t.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return t[s]},c=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[i,o,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,m=d*f;c.push([0,1].map(g=>.5*(2*o[g]+(-i[g]+l[g])*f+(2*i[g]-5*o[g]+4*l[g]-h[g])*d+(-i[g]+3*o[g]-3*l[g]+h[g])*m)))}}return c.push(n?c[0]:[t[t.length-1][0],t[t.length-1][1]]),c}function f3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var z5=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function er(t,e,n,r){if(e==="flat")return[];let c=f3(t,r),a=t/c,s=[];for(let i=0;i<c;i++)(e==="out"?i%2===1:i%2===0)&&s.push(z5(i*a,-1,(i+1)*a,n));return s}function y4(t,e,n,r,c){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 er(s[l],o,r,c))i.push(h.map(a[l]))}),k0([z5(0,0,t,e)],i)}function e7(t,e,n,r){let c=f3(t,r),a=t/c,s=[];for(let i=0;i<c;i++)(e==="out"?i%2===0:i%2===1)&&s.push(z5(i*a,-n/2,(i+1)*a,n/2));return s}function t7(t,e,n,r,c){let a=z5(-t/2,-1,t/2,e),s=z5(-n/2,c,n/2,c+r);return[a,s]}function n7(t,e,n,r,c){let a=[],s=c+r,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?r:r-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?r:0),m=Math.min(f+c,e-(l%2===0?r:0));m-d>=r/2&&a.push([[h,d],[h,m]])}}return a}var d2=(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} (${d2(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})}},tr=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function S5(t,e){let n=[],r=[],c=0,a=1,s=0,i=()=>({line:a,col:c-s+1,offset:c,...e&&{file:e}}),o=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
|
+
`){o(1);continue}if(l==="/"&&t[c+1]==="/"){let f=t.indexOf(`
|
|
9
|
+
`,c),d=f<0?t.length:f,m=/^[ \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:m,start:c,end:d}),c=d;continue}if(l==="/"&&t[c+1]==="*"){let f=i(),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}),o(d+2-c);continue}let h=i();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}),o(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}),o(f[0].length);continue}if(l==='"'){let f="";for(o(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 m=t.slice(c+2,c+6);if(!/^[0-9a-fA-F]{4}$/.test(m))throw new l1("Bad \\u escape",i());f+=String.fromCharCode(parseInt(m,16)),o(4)}else f+=d;o(2);continue}if(t[c]===`
|
|
12
|
+
`)throw new l1("Unclosed string",h);f+=t[c],o(1)}if(c>=t.length)throw new l1("Unclosed string",h);o(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}),o(d[0].length);continue}}let u=tr.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}),o(u.length)}return n.push({type:"eof",value:"",pos:i(),end:c}),{tokens:n,comments:r}}var q3={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"}},L5={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var Oe=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function m2(t,e){let{tokens:n,comments:r}=S5(t,e),c=new Fe(n),a=[];for(;!c.at("eof");)a.push(...c.statement());return{program:{body:a},comments:r}}var A5=class A5{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"||Oe.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("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 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 r=this.peek();(r.type!=="id"||Oe.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>=A5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&A5.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}):(Oe.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()}}};A5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var Fe=A5;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}),Re="max(3 * $thickness, 6)",b4=[O("value")],nr=[O("x")],Y0=(t,e)=>({name:t,kind:"function",params:nr,section:"Numbers and vectors",doc:e}),d3=(t,e)=>({name:t,kind:"function",params:b4,section:"Types",doc:`Whether the value is ${e}`}),r7=(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 or bottom",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),c7=[{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")],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 or bottom",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Shrink the size so the text is no wider than this"),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",Re)],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",Re)],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"},Y0("abs","Absolute value"),Y0("sign","Sign as -1, 0 or 1"),Y0("floor","Round down"),Y0("ceil","Round up"),Y0("round","Round to the nearest integer, halves away from zero"),Y0("sqrt","Square root"),Y0("exp","e raised to x"),Y0("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"},Y0("sin","Sine of an angle in degrees"),Y0("cos","Cosine of an angle in degrees"),Y0("tan","Tangent of an angle in degrees"),Y0("asin","Inverse sine, in degrees"),Y0("acos","Inverse cosine, in degrees"),Y0("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:b4,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:b4,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"},d3("is_num","a number other than NaN"),d3("is_string","a string"),d3("is_bool","true or false"),d3("is_list","a list"),d3("is_undef","undef"),d3("is_function","a function"),d3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:b4,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"},r7("text_width","The advance width of the text, including spacing"),r7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[O("length","Edge length"),O("finger","Finger width",Re)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],rr=new Map(c7.map(t=>[t.name,t])),C5=t=>rr.get(t);function $e(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 P5={"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.
|
|
@@ -101,6 +101,62 @@ module joint_test(kerfs = [0.1, 0.15, 0.2], size = [40, 20], finger = undef, lab
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
`,"kerf/cones":`// kerf/cones: cones and cut-off cones cut flat, to roll up from thin sheet.
|
|
105
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
106
|
+
//
|
|
107
|
+
// A cone rolled from paper, card, veneer or thin plastic is a ring sector
|
|
108
|
+
// when flat. Gramophone horns, lampshades, funnels and party hats all start
|
|
109
|
+
// as one. The sector's apex is at the origin and it opens from +x
|
|
110
|
+
// anticlockwise; the glue tab runs along its far edge.
|
|
111
|
+
|
|
112
|
+
// The flat pattern of a cone of radius r1 at one end, r2 at the other and h
|
|
113
|
+
// high: [outer radius, inner radius, angle in degrees, slant length]. A
|
|
114
|
+
// cylinder (r1 == r2) has no apex: it gives [undef, undef, 0, h] and is a
|
|
115
|
+
// rectangle 2 * PI * r1 wide.
|
|
116
|
+
function cone_pattern(r1, r2, h) =
|
|
117
|
+
let (
|
|
118
|
+
big = max(r1, r2),
|
|
119
|
+
small = min(r1, r2),
|
|
120
|
+
s = sqrt(h * h + pow(big - small, 2))
|
|
121
|
+
)
|
|
122
|
+
big == small ? [undef, undef, 0, h]
|
|
123
|
+
: [s * big / (big - small), s * small / (big - small), 360 * (big - small) / s, s];
|
|
124
|
+
|
|
125
|
+
// A cone or cut-off cone cut flat: rolled up so the far edge lies on the
|
|
126
|
+
// glue tab, it has radius r1 at one end, r2 at the other, and is h high.
|
|
127
|
+
// \`tab\` adds a glue tab that wide along the far edge, its fold scored; a
|
|
128
|
+
// cylinder becomes a rectangle with the tab on its right.
|
|
129
|
+
module cone_flat(r1, r2, h, tab = 0, steps = 0) {
|
|
130
|
+
p = cone_pattern(r1, r2, h);
|
|
131
|
+
if (is_undef(p[0])) {
|
|
132
|
+
w = 2 * PI * r1;
|
|
133
|
+
rect([w, h]);
|
|
134
|
+
if (tab > 0) {
|
|
135
|
+
polygon([[w, 0], [w + tab, min(tab, h / 4)], [w + tab, h - min(tab, h / 4)], [w, h]]);
|
|
136
|
+
score() line([w, 0], [w, h]);
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
a = p[2];
|
|
140
|
+
n = steps > 0 ? steps : max(8, ceil(a / 3));
|
|
141
|
+
arc_pts = function(r) [for (i = [0:n]) [r * cos(a * i / n), r * sin(a * i / n)]];
|
|
142
|
+
polygon(concat(arc_pts(p[0]), p[1] > 0 ? reverse(arc_pts(p[1])) : [[0, 0]]));
|
|
143
|
+
if (tab > 0) {
|
|
144
|
+
// The tab beyond the far edge, its ends cut in so it hides when rolled
|
|
145
|
+
ux = cos(a);
|
|
146
|
+
uy = sin(a);
|
|
147
|
+
nx = -uy;
|
|
148
|
+
ny = ux;
|
|
149
|
+
c = min(tab, p[3] / 4);
|
|
150
|
+
polygon([
|
|
151
|
+
[p[1] * ux, p[1] * uy],
|
|
152
|
+
[p[0] * ux, p[0] * uy],
|
|
153
|
+
[(p[0] - c) * ux + tab * nx, (p[0] - c) * uy + tab * ny],
|
|
154
|
+
[(p[1] + (p[1] > 0 ? c : tab)) * ux + tab * nx, (p[1] + (p[1] > 0 ? c : tab)) * uy + tab * ny],
|
|
155
|
+
]);
|
|
156
|
+
score() line([p[1] * ux, p[1] * uy], [p[0] * ux, p[0] * uy]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
104
160
|
`,"kerf/dividers":`// kerf/dividers: dividers that slot into each other like an egg crate.
|
|
105
161
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
106
162
|
|
|
@@ -223,6 +279,70 @@ module vents(size, slot = 3, pitch = 6) {
|
|
|
223
279
|
translate([0, ends]) circle(d = slot, $fn = 24);
|
|
224
280
|
}
|
|
225
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
|
+
}
|
|
226
346
|
`,"kerf/gears":`// kerf/gears: gears, racks, lantern gears and cams for moving models.
|
|
227
347
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
228
348
|
//
|
|
@@ -374,6 +494,209 @@ module tappets(n, r, w = 10, hub = 14, bore = 6, square = false) {
|
|
|
374
494
|
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
375
495
|
}
|
|
376
496
|
}
|
|
497
|
+
|
|
498
|
+
// Cams from a lift curve. The follower rides on the cam's top (+y) and
|
|
499
|
+
// moves straight up and down; turned anticlockwise by \`a\` degrees (rotate =
|
|
500
|
+
// [0, 0, a]), the cam lifts it lift(a) above the base circle. \`lift\` is a
|
|
501
|
+
// function of the angle, 0 to 360, that comes back to where it started.
|
|
502
|
+
|
|
503
|
+
// A smooth rise of \`height\` from angle a0 to a1 (cycloidal: it starts and
|
|
504
|
+
// stops gently): 0 before a0, height after a1. Add and take away rises to
|
|
505
|
+
// make dwells, rises and falls: two pecks then a rest is
|
|
506
|
+
// function(a) cam_rise(a, 0, 40, 8) - cam_rise(a, 40, 80, 8) + cam_rise(a, 100, 140, 8) - cam_rise(a, 140, 180, 8).
|
|
507
|
+
function cam_rise(a, a0, a1, height) =
|
|
508
|
+
a <= a0 ? 0
|
|
509
|
+
: a >= a1 ? height
|
|
510
|
+
: let (u = (a - a0) / (a1 - a0)) height * (u - sin(360 * u) / (2 * PI));
|
|
511
|
+
|
|
512
|
+
// The cam's pitch curve: where the follower's tip (or its roller's centre)
|
|
513
|
+
// sits, in the cam's own turn, \`steps\` points round
|
|
514
|
+
function cam_pitch(lift, base_r, roller_d = 0, steps = 180) =
|
|
515
|
+
[for (i = [0:steps - 1])
|
|
516
|
+
let (f = i * 360 / steps, a = (450 - f) % 360, r = base_r + roller_d / 2 + lift(a))
|
|
517
|
+
[r * cos(f), r * sin(f)]];
|
|
518
|
+
|
|
519
|
+
// How high the follower's tip (or its roller's centre) is above the cam's
|
|
520
|
+
// axle when the cam is turned to \`angle\`, to place the follower
|
|
521
|
+
function cam_follower(lift, base_r, angle, roller_d = 0) =
|
|
522
|
+
base_r + roller_d / 2 + lift(((angle % 360) + 360) % 360);
|
|
523
|
+
|
|
524
|
+
// The steepest pressure angle over a turn, in degrees: how hard the cam
|
|
525
|
+
// pushes the follower sideways. Keep it under about 30, by a bigger base
|
|
526
|
+
// circle or a longer rise.
|
|
527
|
+
function cam_pressure(lift, base_r, roller_d = 0, steps = 360) =
|
|
528
|
+
max([for (i = [0:steps - 1])
|
|
529
|
+
let (
|
|
530
|
+
a = i * 360 / steps,
|
|
531
|
+
r = base_r + roller_d / 2 + lift(a),
|
|
532
|
+
slope = (lift((a + 0.5) % 360) - lift((a + 359.5) % 360)) / (PI / 180)
|
|
533
|
+
)
|
|
534
|
+
atan(abs(slope) / r)]);
|
|
535
|
+
|
|
536
|
+
// A cam that lifts a follower lift(a) at angle a, with a hole for its
|
|
537
|
+
// axle. A "knife" follower rides the pitch curve itself; a "roller" one of
|
|
538
|
+
// diameter roller_d rolls on a profile inside it. Check cam_pressure().
|
|
539
|
+
module cam(lift, base_r, follower = "knife", roller_d = 0, bore = 6, steps = 180, square = false) {
|
|
540
|
+
assert(follower == "knife" || follower == "roller", "follower must be \\"knife\\" or \\"roller\\"");
|
|
541
|
+
assert(follower == "knife" || roller_d > 0, "a roller follower needs roller_d");
|
|
542
|
+
difference() {
|
|
543
|
+
if (follower == "roller") offset(r = -roller_d / 2) polygon(cam_pitch(lift, base_r, roller_d, steps));
|
|
544
|
+
else polygon(cam_pitch(lift, base_r, 0, steps));
|
|
545
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// A Geneva drive: a driver turning all the time steps a wheel of \`slots\`
|
|
550
|
+
// slots on by one slot each turn, and locks it between steps. The driver's
|
|
551
|
+
// axle is at the origin and the wheel's at [distance, 0]. Cut the wheel and
|
|
552
|
+
// the locking disc from the same sheet, side by side in one plane, and the
|
|
553
|
+
// crank above them; a dowel pin of pin_d through the crank's outer hole
|
|
554
|
+
// runs in the wheel's slots.
|
|
555
|
+
|
|
556
|
+
// The radius of the circle the driver's pin turns on
|
|
557
|
+
function geneva_pin_radius(slots, distance) = distance * sin(180 / slots);
|
|
558
|
+
// The wheel's outer radius
|
|
559
|
+
function geneva_wheel_radius(slots, distance, pin_d) =
|
|
560
|
+
sqrt(pow(distance * cos(180 / slots), 2) + pow(pin_d / 2, 2));
|
|
561
|
+
// The locking disc's radius
|
|
562
|
+
function geneva_lock_radius(slots, distance, pin_d) = geneva_pin_radius(slots, distance) - pin_d;
|
|
563
|
+
|
|
564
|
+
// How far the wheel has turned when the driver has turned \`angle\`
|
|
565
|
+
// anticlockwise from its pin pointing at the wheel: it turns clockwise,
|
|
566
|
+
// 360 / slots each turn of the driver, and stands still between steps
|
|
567
|
+
function geneva_turn(slots, distance, angle) =
|
|
568
|
+
let (
|
|
569
|
+
k = floor((angle + 180) / 360),
|
|
570
|
+
t = angle - 360 * k,
|
|
571
|
+
rc = geneva_pin_radius(slots, distance),
|
|
572
|
+
on = 90 - 180 / slots,
|
|
573
|
+
step = abs(t) <= on ? atan2(-rc * sin(t), distance - rc * cos(t))
|
|
574
|
+
: t < 0 ? 180 / slots : -180 / slots
|
|
575
|
+
)
|
|
576
|
+
step - k * 360 / slots;
|
|
577
|
+
|
|
578
|
+
// The wheel, centred on the origin, a slot along -x (towards the driver
|
|
579
|
+
// when geneva_turn() is 0)
|
|
580
|
+
module geneva_wheel(slots, distance, pin_d = 6, bore = 6, clearance = 0.2, square = false) {
|
|
581
|
+
rc = geneva_pin_radius(slots, distance);
|
|
582
|
+
ro = geneva_wheel_radius(slots, distance, pin_d);
|
|
583
|
+
rl = geneva_lock_radius(slots, distance, pin_d);
|
|
584
|
+
w = pin_d + clearance;
|
|
585
|
+
inner = distance - rc - clearance;
|
|
586
|
+
assert(rl > 0, "the pin is too thick to leave a locking disc: make the distance longer or the pin thinner");
|
|
587
|
+
assert(inner - w / 2 > bore / 2 + 3, "the slots reach the axle: use more slots, a longer distance or a smaller bore");
|
|
588
|
+
difference() {
|
|
589
|
+
circle(r = ro);
|
|
590
|
+
for (j = [0:slots - 1]) rotate(180 + j * 360 / slots) {
|
|
591
|
+
hull() {
|
|
592
|
+
translate([inner, 0]) circle(d = w);
|
|
593
|
+
translate([ro + 1, -w / 2]) rect([1, w]);
|
|
594
|
+
}
|
|
595
|
+
// The locking arc between this slot and the next
|
|
596
|
+
rotate(180 / slots) translate([distance, 0]) circle(r = rl + clearance);
|
|
597
|
+
}
|
|
598
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// The locking disc that turns with the driver, its relief facing the pin's
|
|
603
|
+
// side (+x): cut away wherever the wheel's rim passes while the pin is in a
|
|
604
|
+
// slot, so the wheel turns then
|
|
605
|
+
module geneva_lock(slots, distance, pin_d = 6, bore = 6, clearance = 0.2, square = false) {
|
|
606
|
+
assert(geneva_lock_radius(slots, distance, pin_d) > bore / 2 + 3, "the locking disc is too small for its axle: make the distance longer, the pin thinner or the bore smaller");
|
|
607
|
+
ro = geneva_wheel_radius(slots, distance, pin_d);
|
|
608
|
+
assert(distance - ro - clearance >= bore / 2 + 2, str("the wheel passes within ", round(10 * (distance - ro - clearance)) / 10, " mm of the driver's axle: use a bore of at most ", floor(20 * (distance - ro - clearance - 2)) / 10, " mm or fewer slots"));
|
|
609
|
+
difference() {
|
|
610
|
+
circle(r = geneva_lock_radius(slots, distance, pin_d));
|
|
611
|
+
// Everywhere the wheel's rim passes while the pin is in a slot
|
|
612
|
+
on = 90 - 180 / slots;
|
|
613
|
+
n = max(2, ceil(2 * on / 3));
|
|
614
|
+
for (i = [0:n - 1]) hull() for (t = [-on + 2 * on * i / n, -on + 2 * on * (i + 1) / n])
|
|
615
|
+
translate([distance * cos(t), distance * sin(t)]) circle(r = ro + clearance);
|
|
616
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// The crank above the locking disc that carries the pin, along +x
|
|
621
|
+
module geneva_crank(slots, distance, pin_d = 6, bore = 6, width = 0, square = false) {
|
|
622
|
+
rc = geneva_pin_radius(slots, distance);
|
|
623
|
+
w = width > 0 ? width : max(pin_d, bore) + 8;
|
|
624
|
+
difference() {
|
|
625
|
+
hull() {
|
|
626
|
+
circle(d = w);
|
|
627
|
+
translate([rc, 0]) circle(d = pin_d + 8);
|
|
628
|
+
}
|
|
629
|
+
translate([rc, 0]) circle(d = pin_d);
|
|
630
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// A ratchet wheel of \`teeth\` teeth, radius r at their tips, \`depth\` deep,
|
|
635
|
+
// centred on the origin with a hole for its axle. It turns anticlockwise
|
|
636
|
+
// freely; a pawl() stops it turning back.
|
|
637
|
+
module ratchet(teeth, r, depth, bore = 6, square = false) {
|
|
638
|
+
p = 360 / teeth;
|
|
639
|
+
difference() {
|
|
640
|
+
polygon([for (k = [0:teeth - 1], j = [0, 1])
|
|
641
|
+
j == 0 ? [r * cos(k * p), r * sin(k * p)]
|
|
642
|
+
: [(r - depth) * cos((k + 1) * p), (r - depth) * sin((k + 1) * p)]]);
|
|
643
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// The angle of the tooth face a pawl rests on, nearest \`at\` degrees
|
|
648
|
+
function pawl_face(teeth, at = 90) = round(at / (360 / teeth)) * 360 / teeth;
|
|
649
|
+
|
|
650
|
+
// How far the pawl leans out from the wheel's edge, in degrees: past the
|
|
651
|
+
// teeth's slope, so it clears them
|
|
652
|
+
function pawl_lean(teeth, r, depth) = atan(depth / ((r - depth / 2) * 2 * PI / teeth)) + 15;
|
|
653
|
+
|
|
654
|
+
// The shortest pawl of this width that clears the teeth: its tip edge,
|
|
655
|
+
// along the tooth face, must end before its far end does
|
|
656
|
+
function pawl_min_length(teeth, r, depth, width = 8) =
|
|
657
|
+
width * (0.5 + tan(pawl_lean(teeth, r, depth))) + 2;
|
|
658
|
+
|
|
659
|
+
// The pawl's outline round the wheel's centre: its tip on the root by the
|
|
660
|
+
// tooth face, its far end, and back along the face. Its pivot is the
|
|
661
|
+
// middle of its far end. A length of 0 picks 0.8 * r, or longer if the
|
|
662
|
+
// pawl must be to clear the teeth; pawl() refuses a length given shorter
|
|
663
|
+
// than pawl_min_length().
|
|
664
|
+
function pawl_points(teeth, r, depth, length = 0, width = 8, at = 90, clearance = 0.2) =
|
|
665
|
+
let (
|
|
666
|
+
f = pawl_face(teeth, at),
|
|
667
|
+
g = pawl_lean(teeth, r, depth),
|
|
668
|
+
shortest = pawl_min_length(teeth, r, depth, width),
|
|
669
|
+
L = length > 0 ? length : max(r * 0.8, shortest),
|
|
670
|
+
n = [cos(f), sin(f)],
|
|
671
|
+
tc = [sin(f), -cos(f)],
|
|
672
|
+
u = cos(g) * tc + sin(g) * n,
|
|
673
|
+
v = cos(g) * n - sin(g) * tc,
|
|
674
|
+
T = (r - depth + clearance) * n + clearance * tc
|
|
675
|
+
)
|
|
676
|
+
[T, T + (L - width / 2) * u, T + (L - width / 2) * u + width * v, T + width / cos(g) * n];
|
|
677
|
+
|
|
678
|
+
// Where a pawl()'s pivot is, round the wheel's centre
|
|
679
|
+
function pawl_pivot(teeth, r, depth, length = 0, width = 8, at = 90, clearance = 0.2) =
|
|
680
|
+
let (p = pawl_points(teeth, r, depth, length, width, at, clearance)) (p[1] + p[2]) / 2;
|
|
681
|
+
|
|
682
|
+
// A pawl for a ratchet() of the same sizes, drawn where it works round
|
|
683
|
+
// the wheel's centre: give it the wheel's placement. Its tip rests against
|
|
684
|
+
// the tooth face nearest \`at\` degrees, and it turns on a pin through the
|
|
685
|
+
// hole at pawl_pivot(). Gravity, a rubber band or a spring wire holds it
|
|
686
|
+
// down on the teeth.
|
|
687
|
+
module pawl(teeth, r, depth, length = 0, width = 8, bore = 3, at = 90, clearance = 0.2) {
|
|
688
|
+
shortest = pawl_min_length(teeth, r, depth, width);
|
|
689
|
+
assert(length == 0 || length >= shortest, str("a pawl ", width, " mm wide must be at least ", ceil(2 * shortest) / 2, " mm long to clear the teeth: make it longer or narrower"));
|
|
690
|
+
p = pawl_points(teeth, r, depth, length, width, at, clearance);
|
|
691
|
+
H = (p[1] + p[2]) / 2;
|
|
692
|
+
difference() {
|
|
693
|
+
union() {
|
|
694
|
+
polygon(p);
|
|
695
|
+
translate(H) circle(d = width);
|
|
696
|
+
}
|
|
697
|
+
translate(H) circle(d = bore);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
377
700
|
`,"kerf/geo":`// kerf/geo: the world's land, for maps, globes and country-shaped pieces.
|
|
378
701
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
379
702
|
// The land data is Natural Earth's 1:110m land (public domain,
|
|
@@ -1004,6 +1327,60 @@ module halved_pair(name, at = [0, 0, 0], cap = undef, feet = [], side_feet = und
|
|
|
1004
1327
|
}
|
|
1005
1328
|
}
|
|
1006
1329
|
}
|
|
1330
|
+
`,"kerf/linkage":`// kerf/linkage: where the joints of a linkage are at a crank angle.
|
|
1331
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1332
|
+
//
|
|
1333
|
+
// Each function gives the joint points of a linkage drawn flat, so a part
|
|
1334
|
+
// placed on a link and the link's length come from the same numbers. Use
|
|
1335
|
+
// them to place moving parts at a drive angle, and to check a linkage closes
|
|
1336
|
+
// over a whole turn.
|
|
1337
|
+
|
|
1338
|
+
// Where a circle of radius ra round a meets one of radius rb round b: the
|
|
1339
|
+
// point left of the line from a to b (side = 1) or right of it (side = -1).
|
|
1340
|
+
// undef when the circles don't meet: the links are too short or too long.
|
|
1341
|
+
function circle_meet(a, ra, b, rb, side = 1) =
|
|
1342
|
+
let (
|
|
1343
|
+
dx = b[0] - a[0],
|
|
1344
|
+
dy = b[1] - a[1],
|
|
1345
|
+
d = sqrt(dx * dx + dy * dy),
|
|
1346
|
+
along = d > 0 ? (ra * ra - rb * rb + d * d) / (2 * d) : 0,
|
|
1347
|
+
h2 = ra * ra - along * along
|
|
1348
|
+
)
|
|
1349
|
+
d == 0 || h2 < -1e-9 ? undef
|
|
1350
|
+
: let (h = sqrt(max(0, h2)), ux = dx / d, uy = dy / d)
|
|
1351
|
+
[a[0] + along * ux - side * h * uy, a[1] + along * uy + side * h * ux];
|
|
1352
|
+
|
|
1353
|
+
// A crank of radius r turning round the origin drives a slider along the
|
|
1354
|
+
// line y = offset through a connecting rod of length l. At the crank's
|
|
1355
|
+
// angle it gives [crank pin, slider pin]; undef if the rod can't reach.
|
|
1356
|
+
function slider_crank(r, l, angle, offset = 0) =
|
|
1357
|
+
let (
|
|
1358
|
+
pin = [r * cos(angle), r * sin(angle)],
|
|
1359
|
+
dy = offset - pin[1]
|
|
1360
|
+
)
|
|
1361
|
+
abs(dy) > l ? undef : [pin, [pin[0] + sqrt(l * l - dy * dy), offset]];
|
|
1362
|
+
|
|
1363
|
+
// How far the slider of slider_crank() travels from end to end
|
|
1364
|
+
function slider_stroke(r, l, offset = 0) =
|
|
1365
|
+
sqrt(pow(l + r, 2) - offset * offset) - sqrt(pow(l - r, 2) - offset * offset);
|
|
1366
|
+
|
|
1367
|
+
// A four-bar linkage: the crank turns round the origin, the rocker round
|
|
1368
|
+
// [ground, 0], and the coupler joins their ends. At the crank's angle it
|
|
1369
|
+
// gives [crank end, rocker end], the rocker end on the side \`side\` of the
|
|
1370
|
+
// line from the crank end to the rocker's pivot; undef where the links
|
|
1371
|
+
// can't close.
|
|
1372
|
+
function four_bar(ground, crank, coupler, rocker, angle, side = 1) =
|
|
1373
|
+
let (b = [crank * cos(angle), crank * sin(angle)], c = circle_meet(b, coupler, [ground, 0], rocker, side))
|
|
1374
|
+
is_undef(c) ? undef : [b, c];
|
|
1375
|
+
|
|
1376
|
+
// True when the crank of a four-bar linkage turns all the way round
|
|
1377
|
+
// (Grashof's rule, with the crank the shortest link)
|
|
1378
|
+
function four_bar_turns(ground, crank, coupler, rocker) =
|
|
1379
|
+
let (s = min(ground, crank, coupler, rocker), l = max(ground, crank, coupler, rocker))
|
|
1380
|
+
crank == s && s + l <= ground + crank + coupler + rocker - s - l;
|
|
1381
|
+
|
|
1382
|
+
// The angle in degrees of the line from a to b, from +x
|
|
1383
|
+
function link_angle(a, b) = atan2(b[1] - a[1], b[0] - a[0]);
|
|
1007
1384
|
`,"kerf/lock":`// kerf/lock: a lock with a key, for boxes, diaries, chests and money boxes.
|
|
1008
1385
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1009
1386
|
//
|
|
@@ -1188,11 +1565,20 @@ function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
|
|
|
1188
1565
|
is_undef(s) ? assert(false, str("Unknown card size \\"", name, "\\". Known: ", size_names(CARD_SIZES))) : s;
|
|
1189
1566
|
|
|
1190
1567
|
// Photo print sizes as [width, height], landscape: "4x6", "5x7", "8x10",
|
|
1191
|
-
// "10x15" (cm), "13x18" (cm),
|
|
1192
|
-
// "
|
|
1193
|
-
function photo_size(name) = let (s = lookup_size(name, PHOTO_SIZES))
|
|
1568
|
+
// "10x15" (cm), "13x18" (cm), and instant film: "instant mini", "instant
|
|
1569
|
+
// square", "instant wide" and "instant classic".
|
|
1570
|
+
function photo_size(name) = let (s = lookup_size(lookup_alias(name, PHOTO_ALIASES), PHOTO_SIZES))
|
|
1194
1571
|
is_undef(s) ? assert(false, str("Unknown photo size \\"", name, "\\". Known: ", size_names(PHOTO_SIZES))) : s;
|
|
1195
1572
|
|
|
1573
|
+
// A bought part's sizes by name, as a record: \`body\` [width, depth,
|
|
1574
|
+
// height], and for parts with one, the \`shaft\` diameter, the \`shaft_length\`
|
|
1575
|
+
// it stands out of the body and the \`hole\` to cut for it. Retail sizes vary:
|
|
1576
|
+
// measure yours. "music-18" (an 18-note wind-up music box movement, shaft
|
|
1577
|
+
// the winding key's), "quartz-clock" (a 56 mm quartz clock movement with
|
|
1578
|
+
// the 16.5 mm shaft for dials up to 8 mm thick), "marble-16" and "marble-25".
|
|
1579
|
+
function part_size(name) = let (s = lookup_size(name, PART_SIZES))
|
|
1580
|
+
is_undef(s) ? assert(false, str("Unknown part \\"", name, "\\". Known: ", size_names(PART_SIZES))) : s;
|
|
1581
|
+
|
|
1196
1582
|
// A size turned to lie wider than tall
|
|
1197
1583
|
function landscape(size) = size[0] >= size[1] ? size : [size[1], size[0]];
|
|
1198
1584
|
// A size turned to stand taller than wide
|
|
@@ -1214,13 +1600,28 @@ CARD_SIZES = [
|
|
|
1214
1600
|
];
|
|
1215
1601
|
PHOTO_SIZES = [
|
|
1216
1602
|
["4x6", [152.4, 101.6]], ["5x7", [177.8, 127]], ["8x10", [254, 203.2]],
|
|
1217
|
-
["10x15", [150, 100]], ["13x18", [180, 130]], ["
|
|
1218
|
-
["
|
|
1603
|
+
["10x15", [150, 100]], ["13x18", [180, 130]], ["instant mini", [54, 86]],
|
|
1604
|
+
["instant square", [72, 86]], ["instant wide", [108, 86]], ["instant classic", [88, 107]]
|
|
1605
|
+
];
|
|
1606
|
+
// Older names that still work, left out of the list of known names
|
|
1607
|
+
PHOTO_ALIASES = [
|
|
1608
|
+
["instax mini", "instant mini"], ["instax square", "instant square"],
|
|
1609
|
+
["instax wide", "instant wide"], ["polaroid", "instant classic"]
|
|
1610
|
+
];
|
|
1611
|
+
PART_SIZES = [
|
|
1612
|
+
["music-18", {body = [50, 44, 20], shaft = 3.5, hole = 6}],
|
|
1613
|
+
["quartz-clock", {body = [56, 56, 16], shaft = 7.6, shaft_length = 16.5, hole = 8, dial = 8}],
|
|
1614
|
+
["marble-16", {body = [16, 16, 16]}],
|
|
1615
|
+
["marble-25", {body = [25, 25, 25]}]
|
|
1219
1616
|
];
|
|
1220
1617
|
|
|
1221
1618
|
// The size of that name in a table of [name, size], ignoring case
|
|
1222
1619
|
function lookup_size(name, table) = let (k = lower(name), hit = [for (e = table) if (lower(e[0]) == k) e[1]])
|
|
1223
1620
|
len(hit) ? hit[0] : undef;
|
|
1621
|
+
// The name an older name stands for in a table of [old, new], or the name
|
|
1622
|
+
// itself
|
|
1623
|
+
function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = aliases) if (lower(e[0]) == k) e[1]])
|
|
1624
|
+
len(hit) ? hit[0] : name;
|
|
1224
1625
|
// The names in a table, for messages
|
|
1225
1626
|
function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
1226
1627
|
`,"kerf/symbols":`// kerf/symbols: 867 pictograms by name, for engraving and cutting.
|
|
@@ -1235,14 +1636,29 @@ function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
|
1235
1636
|
// symbol_names() lists them: "heart", "star", "paw", "tree" and the like.
|
|
1236
1637
|
// box = "grid" sizes and places it by its icon set's grid (24 x 24 for
|
|
1237
1638
|
// Material Design Icons) instead, so icons of one set line up as drawn.
|
|
1238
|
-
|
|
1639
|
+
// solid = true cuts it as one silhouette, gaps narrower than 2 * close
|
|
1640
|
+
// closed and its holes filled, with the drawing's detail engraved on it:
|
|
1641
|
+
// a pictogram drawn as separate strokes (a moon and stars, yarn) cut out
|
|
1642
|
+
// in one piece. bridge = w also joins pieces too far apart to close, by
|
|
1643
|
+
// strips w wide.
|
|
1644
|
+
module symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close = undef, bridge = undef) {
|
|
1239
1645
|
assert(box == "drawn" || box == "grid", "box is \\"drawn\\" or \\"grid\\"");
|
|
1240
1646
|
s = symbol_entry(name);
|
|
1241
1647
|
vb = box == "grid" ? s[5] : s[2];
|
|
1242
1648
|
k = size / max(vb[2], vb[3]);
|
|
1243
|
-
translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
1649
|
+
module drawn() translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
1244
1650
|
scale([k, -k]) translate([-vb[0] - vb[2] / 2, -vb[1] - vb[3] / 2])
|
|
1245
1651
|
path(s[4], fill = fill, close = true);
|
|
1652
|
+
r = is_undef(close) ? size / 30 : close;
|
|
1653
|
+
module silhouette() if (is_undef(bridge)) fill_holes() close(r) drawn();
|
|
1654
|
+
else join_islands(bridge) fill_holes() close(r) drawn();
|
|
1655
|
+
if (solid) {
|
|
1656
|
+
silhouette();
|
|
1657
|
+
engrave() difference() {
|
|
1658
|
+
silhouette();
|
|
1659
|
+
drawn();
|
|
1660
|
+
}
|
|
1661
|
+
} else drawn();
|
|
1246
1662
|
}
|
|
1247
1663
|
|
|
1248
1664
|
// [width, height] of what a symbol draws when it is \`size\` across its
|
|
@@ -2223,27 +2639,27 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
|
|
|
2223
2639
|
if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
|
|
2224
2640
|
if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
|
|
2225
2641
|
}
|
|
2226
|
-
`};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 $6=0,o8=-3;function b5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function gn(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new b5,this.dtree=new b5}var l8=new b5,h8=new b5,D6=new Uint8Array(30),q6=new Uint16Array(30),u8=new Uint8Array(30),f8=new Uint16Array(30),vn=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),z7=new b5,v2=new Uint8Array(320);function d8(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 yn(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 k7=new Uint16Array(16);function x6(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)k7[r]=a,a+=t.table[r];for(r=0;r<c;++r)e[n+r]&&(t.trans[k7[e[n+r]]++]=r)}function bn(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function y2(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 P6(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 xn(t,e,n){var c,r,a,s,i,o;for(c=y2(t,5,257),r=y2(t,5,1),a=y2(t,4,4),s=0;s<19;++s)v2[s]=0;for(s=0;s<a;++s){var l=y2(t,3,0);v2[vn[s]]=l}for(x6(z7,v2,0,19),i=0;i<c+r;){var h=P6(t,z7);switch(h){case 16:var u=v2[i-1];for(o=y2(t,2,3);o;--o)v2[i++]=u;break;case 17:for(o=y2(t,3,3);o;--o)v2[i++]=0;break;case 18:for(o=y2(t,7,11);o;--o)v2[i++]=0;break;default:v2[i++]=h;break}}x6(e,v2,0,c),x6(n,v2,c,r)}function S7(t,e,n){for(;;){var c=P6(t,e);if(c===256)return $6;if(c<256)t.dest[t.destLen++]=c;else{var r,a,s,i;for(c-=257,r=y2(t,D6[c],q6[c]),a=P6(t,n),s=t.destLen-y2(t,u8[a],f8[a]),i=s;i<s+r;++i)t.dest[t.destLen++]=t.dest[i]}}}function Mn(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 o8;for(t.sourceIndex+=4,c=e;c;--c)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,$6}function wn(t,e){var n=new gn(t,e),c,r,a;do{switch(c=bn(n),r=y2(n,2,0),r){case 0:a=Mn(n);break;case 1:a=S7(n,l8,h8);break;case 2:xn(n,n.ltree,n.dtree),a=S7(n,n.ltree,n.dtree);break;default:a=o8}if(a!==$6)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}yn(l8,h8);d8(D6,q6,4,3);d8(u8,f8,2,1);D6[28]=0;q6[28]=258;var zn=wn;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],m=-3*o[f]+9*l[f]-9*h[f]+3*u[f],p=3*l[f]-3*o[f];if(m===0){if(d===0)continue;var g=-p/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*p*m;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*m);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*m);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 x0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}x0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};x0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};x0.prototype.curveTo=x0.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})};x0.prototype.quadTo=x0.prototype.quadraticCurveTo=function(t,e,n,c){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:c})};x0.prototype.close=x0.prototype.closePath=function(){this.commands.push({type:"Z"})};x0.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)};x0.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};x0.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())};x0.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};x0.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};x0.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 m8(t){throw new Error(t)}function L7(t,e){t||m8(e)}var z1={fail:m8,argument:L7,assert:L7},A7=32768,C7=2147483648,O3={},J={},C1={};function o2(t){return function(){return t}}J.BYTE=function(t){return z1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};C1.BYTE=o2(1);J.CHAR=function(t){return[t.charCodeAt(0)]};C1.CHAR=o2(1);J.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};J.USHORT=function(t){return[t>>8&255,t&255]};C1.USHORT=o2(2);J.SHORT=function(t){return t>=A7&&(t=-(2*A7-t)),[t>>8&255,t&255]};C1.SHORT=o2(2);J.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};C1.UINT24=o2(3);J.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.ULONG=o2(4);J.LONG=function(t){return t>=C7&&(t=-(2*C7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONG=o2(4);J.FIXED=J.ULONG;C1.FIXED=C1.ULONG;J.FWORD=J.SHORT;C1.FWORD=C1.SHORT;J.UFWORD=J.USHORT;C1.UFWORD=C1.USHORT;J.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONGDATETIME=o2(8);J.TAG=function(t){return z1.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=o2(4);J.Card8=J.BYTE;C1.Card8=C1.BYTE;J.Card16=J.USHORT;C1.Card16=C1.USHORT;J.OffSize=J.BYTE;C1.OffSize=C1.BYTE;J.SID=J.USHORT;C1.SID=C1.USHORT;J.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?J.NUMBER16(t):J.NUMBER32(t)};C1.NUMBER=function(t){return J.NUMBER(t).length};J.NUMBER16=function(t){return[28,t>>8&255,t&255]};C1.NUMBER16=o2(3);J.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.NUMBER32=o2(5);J.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 J.REAL(t).length};J.NAME=J.CHARARRAY;C1.NAME=C1.CHARARRAY;J.STRING=J.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)};J.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 E6={"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=E6[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 c4=typeof WeakMap=="function"&&new WeakMap,r4,kn=function(t){if(!r4){r4={};for(var e in E6)r4[e]=new String(e)}var n=r4[t];if(n!==void 0){if(c4){var c=c4.get(n);if(c!==void 0)return c}var r=E6[t];if(r!==void 0){for(var a={},s=0;s<r.length;s++)a[r.charCodeAt(s)]=s+128;return c4&&c4.set(n,a),a}}};J.MACSTRING=function(t,e){var n=kn(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=J.MACSTRING(t,e);return n!==void 0?n.length:0};function T6(t){return t>=-128&&t<=127}function Sn(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 Ln(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(!T6(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 An(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(s===0||T6(s)&&a+1<r&&T6(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}J.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var c=t[e];c===0?e=Sn(t,e,n):c>=-128&&c<=127?e=Ln(t,e,n):e=An(t,e,n)}return n};J.INDEX=function(t){for(var e=1,n=[e],c=[],r=0;r<t.length;r+=1){var a=J.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,J.BYTE,J.USHORT,J.UINT24,J.ULONG][i],l=0;l<n.length;l+=1){var h=o(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(J.Card16(t.length),J.OffSize(i),s,c)};C1.INDEX=function(t){return J.INDEX(t).length};J.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(J.OPERAND(s.value,s.type)),e=e.concat(J.OPERATOR(a))}return e};C1.DICT=function(t){return J.DICT(t).length};J.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};J.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)z1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(J.OPERAND(t[c],e[c]));else if(e==="SID")n=n.concat(J.NUMBER(t));else if(e==="offset")n=n.concat(J.NUMBER32(t));else if(e==="number")n=n.concat(J.NUMBER(t));else if(e==="real")n=n.concat(J.REAL(t));else throw new Error("Unknown operand type "+e);return n};J.OP=J.BYTE;C1.OP=C1.BYTE;var a4=typeof WeakMap=="function"&&new WeakMap;J.CHARSTRING=function(t){if(a4){var e=a4.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(J[a.type](a.value))}return a4&&a4.set(t,n),n};C1.CHARSTRING=function(t){return J.CHARSTRING(t).length};J.OBJECT=function(t){var e=J[t.type];return z1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};C1.OBJECT=function(t){var e=C1[t.type];return z1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};J.TABLE=function(t){for(var e=[],n=t.fields.length,c=[],r=[],a=0;a<n;a+=1){var s=t.fields[a],i=J[s.type];z1.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;z1.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];z1.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};J.RECORD=J.TABLE;C1.RECORD=C1.TABLE;J.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 J.TABLE(this)};P0.prototype.sizeOf=function(){return C1.TABLE(this)};function x5(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 I6(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 M5(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 h4(t){t.format===1?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(x5("glyph",t.glyphs))):t.format===2?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(M5("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}]}))):z1.assert(!1,"Coverage format must be 1 or 2.")}h4.prototype=Object.create(P0.prototype);h4.prototype.constructor=h4;function u4(t){P0.call(this,"scriptListTable",M5("scriptRecord",t,function(e,n){var c=e.script,r=c.defaultLangSys;return z1.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(x5("featureIndex",r.featureIndexes)))}].concat(M5("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(x5("featureIndex",i.featureIndexes)))}]})))}]}))}u4.prototype=Object.create(P0.prototype);u4.prototype.constructor=u4;function f4(t){P0.call(this,"featureListTable",M5("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(x5("lookupListIndex",c.lookupListIndexes)))}]}))}f4.prototype=Object.create(P0.prototype);f4.prototype.constructor=f4;function d4(t,e){P0.call(this,"lookupListTable",I6("lookup",t,function(n){var c=e[n.lookupType];return z1.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(I6("subtable",n.subtables,c)))}))}d4.prototype=Object.create(P0.prototype);d4.prototype.constructor=d4;var n1={Table:P0,Record:P0,Coverage:h4,ScriptList:u4,FeatureList:f4,LookupList:d4,ushortList:x5,tableList:I6,recordList:M5};function P7(t,e){return t.getUint8(e)}function m4(t,e){return t.getUint16(e,!1)}function Cn(t,e){return t.getInt16(e,!1)}function N6(t,e){return t.getUint32(e,!1)}function p8(t,e){var n=t.getInt16(e,!1),c=t.getUint16(e+2,!1);return n+c/65535}function Pn(t,e){for(var n="",c=e;c<e+4;c+=1)n+=String.fromCharCode(t.getInt8(c));return n}function En(t,e,n){for(var c=0,r=0;r<n;r+=1)c<<=8,c+=t.getUint8(e+r);return c}function Tn(t,e,n){for(var c=[],r=e;r<n;r+=1)c.push(t.getUint8(r));return c}function In(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var Vn={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function H(t,e){this.data=t,this.offset=e,this.relativeOffset=0}H.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};H.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};H.prototype.parseCard8=H.prototype.parseByte;H.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};H.prototype.parseCard16=H.prototype.parseUShort;H.prototype.parseSID=H.prototype.parseUShort;H.prototype.parseOffset16=H.prototype.parseUShort;H.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};H.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};H.prototype.parseULong=function(){var t=N6(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};H.prototype.parseOffset32=H.prototype.parseULong;H.prototype.parseFixed=function(){var t=p8(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};H.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};H.prototype.parseTag=function(){return this.parseString(4)};H.prototype.parseLongDateTime=function(){var t=N6(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};H.prototype.parseVersion=function(t){var e=m4(this.data,this.offset+this.relativeOffset),n=m4(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};H.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=Vn[t]*e};H.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};H.prototype.parseOffset16List=H.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};H.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};H.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};H.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};H.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};H.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};H.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};H.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};H.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}};H.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};H.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new H(this.data,this.offset+e).parseStruct(t)};H.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new H(this.data,this.offset+e).parseStruct(t)};H.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};H.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.")};H.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:H.uShort,end:H.uShort,classId:H.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};H.list=function(t,e){return function(){return this.parseList(t,e)}};H.list32=function(t,e){return function(){return this.parseList32(t,e)}};H.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};H.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};H.pointer=function(t){return function(){return this.parsePointer(t)}};H.pointer32=function(t){return function(){return this.parsePointer32(t)}};H.tag=H.prototype.parseTag;H.byte=H.prototype.parseByte;H.uShort=H.offset16=H.prototype.parseUShort;H.uShortList=H.prototype.parseUShortList;H.uLong=H.offset32=H.prototype.parseULong;H.uLongList=H.prototype.parseULongList;H.struct=H.prototype.parseStruct;H.coverage=H.prototype.parseCoverage;H.classDef=H.prototype.parseClassDef;var E7={reserved:H.uShort,reqFeatureIndex:H.uShort,featureIndexes:H.uShortList};H.prototype.parseScriptList=function(){return this.parsePointer(H.recordList({tag:H.tag,script:H.pointer({defaultLangSys:H.pointer(E7),langSysRecords:H.recordList({tag:H.tag,langSys:H.pointer(E7)})})}))||[]};H.prototype.parseFeatureList=function(){return this.parsePointer(H.recordList({tag:H.tag,feature:H.pointer({featureParams:H.offset16,lookupListIndexes:H.uShortList})}))||[]};H.prototype.parseLookupList=function(t){return this.parsePointer(H.list(H.pointer(function(){var e=this.parseUShort();z1.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(H.pointer(t[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};H.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();z1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:H.offset32,featureTableSubstitutionOffset:H.offset32});return n})||[]};var f1={getByte:P7,getCard8:P7,getUShort:m4,getCard16:m4,getShort:Cn,getULong:N6,getFixed:p8,getTag:Pn,getOffset:En,getBytes:Tn,bytesToString:In,Parser:H};function Hn(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 On(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(),m=i.parseUShort(),p=o.parseShort(),g=l.parseUShort(),v=m;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-m)*2,f=f1.getUShort(n,h),f!==0&&(f=f+p&65535)):f=v+p&65535,t.glyphIndexMap[v]=f}function Rn(t,e){var n={};n.version=f1.getUShort(t,e),z1.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)Hn(n,i);else if(n.format===4)On(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 Fn(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function $n(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function Dn(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)Fn(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}$n(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],m=[],p=[];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&&(m=m.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(p=p.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),p=p.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),p=p.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(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(m),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+m.length*2,!e){var v=16+p.length*4;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:p.length/3}]),a.fields=a.fields.concat(p)}return a}var g8={parse:Rn,make:Dn},o4=[".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"],qn=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],Nn=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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 v8(t){this.font=t}v8.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 y8(t){this.cmap=t}y8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function p4(t,e){this.encoding=t,this.charset=e}p4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function U6(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}}U6.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};U6.prototype.glyphIndexToName=function(t){return this.names[t]};function Un(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 Bn(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 Gn(t,e){e.lowMemory?Bn(t):Un(t)}function jn(t,e,n,c,r){t.beginPath(),t.moveTo(e,n),t.lineTo(c,r),t.stroke()}var a3={line:jn};function _n(t,e){var n=e||new x0;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",_n(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 x0,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 z1.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,m){t.beginPath();for(var p=0;p<u.length;p+=1)t.moveTo(f+u[p].x*m,d+u[p].y*m),t.arc(f+u[p].x*m,d+u[p].y*m,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,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 s4(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 B6(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}B6.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]};B6.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Wn(t,e){return new e2({index:e,font:t})}function Xn(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},s4(s,"xMin","_xMin"),s4(s,"xMax","_xMax"),s4(s,"yMin","_yMin"),s4(s,"yMax","_yMax"),s}}function Zn(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 x2={GlyphSet:B6,glyphLoader:Wn,ttfGlyphLoader:Xn,cffGlyphLoader:Zn};function b8(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(!b8(t[n],e[n]))return!1;return!0}else return!1}function V6(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function G2(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 Yn(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 Jn(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 Kn(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 Qn(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 Kn(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 ec(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 x8(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(Qn(c,s))}return ec(r)}function y5(t,e){return e<=390?e=o4[e]:e=t[e-391],e}function M8(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=y5(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=y5(n,r)),c[s.name]=r}return c}function tc(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 w8=[{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"}],z8=[{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 nc(t,e){var n=x8(t,0,t.byteLength);return M8(n,w8,e)}function k8(t,e,n,c){var r=x8(t,e,n);return M8(r,z8,c)}function T7(t,e,n,c){for(var r=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=nc(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=k8(t,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=G2(t,u+e);i._subrs=f.objects,i._subrsBias=V6(i._subrs)}i._privateDict=h}r.push(i)}return r}function cc(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(y5(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(y5(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(y5(c,r)),r+=1}else throw new Error("Unknown charset format "+o);return i}function rc(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 p4(r,n)}function I7(t,e,n){var c,r,a,s,i=new x0,o=[],l=0,h=!1,u=!1,f=0,d=0,m,p,g,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];m=b._subrs,p=b._subrsBias,g=b._defaultWidthX,v=b._nominalWidthX}else m=t.tables.cff.topDict._subrs,p=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function M(z,C){u&&i.closePath(),i.moveTo(z,C),u=!0}function S(){var z;z=o.length%2!==0,z&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function w(z){for(var C,k,T,q,R,U,j,V,Q,W,o1,m1,I=0;I<z.length;){var $=z[I];switch(I+=1,$){case 1:S();break;case 3:S();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()+p,U=m[R],U&&w(U);break;case 11:return;case 12:switch($=z[I],I+=1,$){case 35:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s+o.shift(),Q=j+o.shift(),W=V+o.shift(),o1=Q+o.shift(),m1=W+o.shift(),f=o1+o.shift(),d=m1+o.shift(),o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;case 34:c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s,Q=j+o.shift(),W=s,o1=Q+o.shift(),m1=d,f=o1+o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;case 36:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s,Q=j+o.shift(),W=s,o1=Q+o.shift(),m1=W+o.shift(),f=o1+o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;case 37:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s+o.shift(),Q=j+o.shift(),W=V+o.shift(),o1=Q+o.shift(),m1=W+o.shift(),Math.abs(o1-f)>Math.abs(m1-d)?f=o1+o.shift():d=m1+o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,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:S();break;case 19:case 20:S(),I+=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:S();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:C=z[I],k=z[I+1],o.push((C<<24|k<<16)>>16),I+=2;break;case 29:R=o.pop()+t.gsubrsBias,U=t.gsubrs[R],U&&w(U);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?(C=z[I],I+=1,o.push(($-247)*256+C+108)):$<255?(C=z[I],I+=1,o.push(-($-251)*256-C-108)):(C=z[I],k=z[I+1],T=z[I+2],q=z[I+3],I+=4,o.push((C<<24|k<<16|T<<8|q)/65536))}}}return w(n),e.advanceWidth=x,i}function ac(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 sc(t,e,n,c){n.tables.cff={};var r=tc(t,e),a=G2(t,r.endOffset,f1.bytesToString),s=G2(t,a.endOffset),i=G2(t,s.endOffset,f1.bytesToString),o=G2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=V6(n.gsubrs);var l=T7(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=G2(t,u),m=T7(t,e,d.objects,i.objects);h._fdArray=m,f+=e,h._fdSelect=ac(t,f,n.numGlyphs,m.length)}var p=e+h.private[1],g=k8(t,p,h.private[0],i.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=p+g.subrs,y=G2(t,v);n.subrs=y.objects,n.subrsBias=V6(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;c.lowMemory?(b=Yn(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=G2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=cc(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new p4(qn,x):h.encoding===1?n.cffEncoding=new p4(Nn,x):n.cffEncoding=rc(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new x2.GlyphSet(n),c.lowMemory)n._push=function(w){var z=Jn(w,b.offsets,t,e+h.charStrings);n.glyphs.push(w,x2.cffGlyphLoader(n,w,I7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var S=b.objects[M];n.glyphs.push(M,x2.cffGlyphLoader(n,M,I7,S))}}function S8(t,e){var n,c=o4.indexOf(t);return c>=0&&(n=c),c=e.indexOf(t),c>=0?n=c+o4.length:(n=o4.length+e.length,e.push(t)),n}function ic(){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 oc(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 L8(t,e,n){for(var c={},r=0;r<t.length;r+=1){var a=t[r],s=e[a.name];s!==void 0&&!b8(s,a.value)&&(a.type==="SID"&&(s=S8(s,n)),c[a.op]={name:a.name,type:a.type,value:s})}return c}function V7(t,e){var n=new n1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=L8(w8,t,e),n}function H7(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 lc(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 hc(){return new n1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function uc(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=S8(r,e);n.fields.push({name:"glyph_"+c,type:"SID",value:a})}return n}function fc(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),m=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:m}),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 dc(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=fc(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:r})}return e}function mc(t,e){var n=new n1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=L8(z8,t,e),n}function pc(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=ic(),n.nameIndex=oc([e.postScriptName]);var h=V7(r,l);n.topDictIndex=H7(h),n.globalSubrIndex=hc(),n.charsets=uc(s,l),n.charStringsIndex=dc(t),n.privateDict=mc(a,l),n.stringIndex=lc(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=V7(r,l),n.topDictIndex=H7(h),n}var A8={parse:sc,make:pc};function gc(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(),z1.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 vc(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 C8={parse:gc,make:vc};function yc(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 bc(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 P8={parse:yc,make:bc};function xc(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 Mc(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 wc(t,e,n,c,r,a,s){s.lowMemory?Mc(t,e,n,c,r):xc(e,n,c,r,a)}function zc(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 E8={parse:wc,make:zc};function kc(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 Sc(t,e){var n=new f1.Parser(t,e),c=n.parseULong();z1.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 T8={make:kc,parse:Sc};function Lc(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 Ac(t){return new n1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var I8={parse:Lc,make:Ac},V8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],H8={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"},Cc={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},O8={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 Pc(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return H8[e];case 3:return O8[e]}}var H6="utf-16",Ec={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"},Tc={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 R8(t,e,n){switch(t){case 0:return H6;case 1:return Tc[n]||Ec[e];case 3:if(e===1||e===10)return H6;break}}function Ic(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=V8[f]||f,m=r.parseUShort(),p=r.parseUShort(),g=Pc(l,u,n),v=R8(l,h,u);if(v!==void 0&&g!==void 0){var y=void 0;if(v===H6?y=O3.UTF16(t,i+p,m):y=O3.MACSTRING(t,i+p,m,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 M6(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function O7(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 Vc(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 R7(t,e){var n=Vc(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 Hc(t,e){var n,c=[],r={},a=M6(V8);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=M6(H8),l=M6(O8),h=[],u=[],f=0;f<c.length;f++){n=c[f];var d=r[n];for(var m in d){var p=d[m],g=1,v=o[m],y=Cc[v],b=R8(g,y,v),x=J.MACSTRING(p,b);x===void 0&&(g=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),y=4,x=J.UTF16(p));var M=R7(x,u);h.push(O7(g,y,v,n,x.length,M));var S=l[m];if(S!==void 0){var w=J.UTF16(p),z=R7(w,u);h.push(O7(3,1,S,n,w.length,z))}}}h.sort(function(T,q){return T.platformID-q.platformID||T.encodingID-q.encodingID||T.languageID-q.languageID||T.nameID-q.nameID});for(var C=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}]),k=0;k<h.length;k++)C.fields.push({name:"record_"+k,type:"RECORD",value:h[k]});return C.fields.push({name:"strings",type:"LITERAL",value:u}),C}var F8={parse:Ic,make:Hc},O6=[{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 Oc(t){for(var e=0;e<O6.length;e+=1){var n=O6[e];if(t>=n.begin&&t<n.end)return e}return-1}function Rc(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 Fc(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 R6={parse:Rc,make:Fc,unicodeRanges:O6,getUnicodeRange:Oc};function $c(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 Dc(){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 $8={parse:$c,make:Dc},a2=new Array(9);a2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(H.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(H.coverage),substitute:this.parseOffset16List()};z1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};a2[2]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),sequences:this.parseListOfLists()}};a2[3]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),alternateSets:this.parseListOfLists()}};a2[4]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var H3={sequenceIndex:H.uShort,lookupListIndex:H.uShort};a2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(H.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(H.coverage),classDef:this.parsePointer(H.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,H.pointer(H.coverage)),lookupRecords:this.parseRecordList(r,H3)}}z1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};a2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(H.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(H.coverage),backtrackClassDef:this.parsePointer(H.classDef),inputClassDef:this.parsePointer(H.classDef),lookaheadClassDef:this.parsePointer(H.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(H.pointer(H.coverage)),inputCoverage:this.parseList(H.pointer(H.coverage)),lookaheadCoverage:this.parseList(H.pointer(H.coverage)),lookupRecords:this.parseRecordList(H3)};z1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};a2[7]=function(){var e=this.parseUShort();z1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),c=new H(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:a2[n].call(c)}};a2[8]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),backtrackCoverage:this.parseList(H.pointer(H.coverage)),lookaheadCoverage:this.parseList(H.pointer(H.coverage)),substitutes:this.parseUShortList()}};function qc(t,e){e=e||0;var n=new H(t,e),c=n.parseVersion(1);return z1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(a2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(a2),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 z1.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 z1.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 z1.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)z1.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}z1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Nc(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 D8={parse:qc,make:Nc};function Uc(t,e){var n=new f1.Parser(t,e),c=n.parseULong();z1.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 Bc(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 q8={parse:Uc,make:Bc};function F7(t){return Math.log(t)/Math.log(2)|0}function G6(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 $7(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 N8(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,F7(e.numTables));e.searchRange=16*n,e.entrySelector=F7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],r=[],a=e.sizeOf()+$7().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];z1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=$7(i.tableName,G6(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,z1.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 D7(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 Gc(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function jc(t){for(var e=[],n=[],c=[],r=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,m=0;m<t.glyphs.length;m+=1){var p=t.glyphs.get(m),g=p.unicode|0;if(isNaN(p.advanceWidth))throw new Error("Glyph "+p.name+" ("+m+"): advanceWidth is not a number.");(o>g||o===void 0)&&g>0&&(o=g),l<g&&(l=g);var v=R6.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(p.name!==".notdef"){var y=p.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(p.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:Gc(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=C8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=P8.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}),S=I8.make(t.glyphs.length),w=R6.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:D7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:D7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=E8.make(t.glyphs),C=g8.make(t.glyphs),k=t.getEnglishName("fontFamily"),T=t.getEnglishName("fontSubfamily"),q=k+" "+T,R=t.getEnglishName("postScriptName");R||(R=k.replace(/\s/g,"")+"-"+T);var U={};for(var j in t.names)U[j]=t.names[j];U.uniqueID||(U.uniqueID={en:t.getEnglishName("manufacturer")+":"+q}),U.postScriptName||(U.postScriptName={en:R}),U.preferredFamily||(U.preferredFamily=t.names.fontFamily),U.preferredSubfamily||(U.preferredSubfamily=t.names.fontSubfamily);var V=[],Q=F8.make(U,V),W=V.length>0?T8.make(V):void 0,o1=$8.make(),m1=A8.make(t.glyphs,{version:t.getEnglishName("version"),fullName:q,familyName:k,weightName:T,postScriptName:R,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),I=t.metas&&Object.keys(t.metas).length>0?q8.make(t.metas):void 0,$=[x,M,S,w,Q,C,o1,m1,z];W&&$.push(W),t.tables.gsub&&$.push(D8.make(t.tables.gsub)),I&&$.push(I);for(var Z=N8($),_=Z.encode(),L1=G6(_),W1=Z.fields,E1=!1,Z1=0;Z1<W1.length;Z1+=1)if(W1[Z1].name==="head table"){W1[Z1].value.checkSumAdjustment=2981146554-L1,E1=!0;break}if(!E1)throw new Error("Could not find head table with checkSum to adjust.");return Z}var _c={make:N8,fontToTable:jc,computeCheckSum:G6};function w6(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 q7(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 N7(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 z5(t,e){this.font=t,this.tableName=e}z5.prototype={searchTag:w6,binSearch:q7,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=w6(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=w6(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 z1.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=N7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=q7(t.glyphs,e);return n>=0?n:-1;case 2:var c=N7(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 k5(t){z5.call(this,t,"gpos")}k5.prototype=z5.prototype;k5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};k5.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};k5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function W0(t){z5.call(this,t,"gsub")}function Wc(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 j6(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=z5.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],m=0;m<d.length;m++){var p=d[m];c.push({sub:[f].concat(p.components),by:p.ligGlyph})}return c};W0.prototype.addSingle=function(t,e,n,c){var r=this.getLookupTables(n,c,t,1,!0)[0],a=j6(r,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});z1.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){z1.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=j6(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});z1.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=j6(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});z1.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),z1.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(Wc(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 Xc(){return typeof window<"u"}function Zc(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 v5(t,e){if(!t)throw e}function U7(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 U8(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(z1.argument(r.length===l,"Bad flags."),s.length>0){var d=[],m;if(l>0){for(var p=0;p<l;p+=1)a=r[p],m={},m.onCurve=!!(a&1),m.lastPointOfContour=s.indexOf(p)>=0,d.push(m);for(var g=0,v=0;v<l;v+=1)a=r[v],m=d[v],m.x=U7(c,a,g,2,16),g=m.x;for(var y=0,b=0;b<l;b+=1)a=r[b],m=d[b],m.y=U7(c,a,y,4,32),y=m.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var 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 S=0;S<t.instructionLength;S+=1)t.instructions.push(c.parseByte())}}}function z6(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 Yc(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 z1.argument(n.length===0,"There are still points left in the current contour."),e}function B8(t){var e=new x0;if(!t)return e;for(var n=Yc(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 G8(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=z6(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=z6([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=z6(r.points,o)}e.points=e.points.concat(a)}}return B8(e.points)}function Jc(t,e,n,c){for(var r=new x2.GlyphSet(c),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?r.push(a,x2.ttfGlyphLoader(c,a,U8,t,e+s,G8)):r.push(a,x2.glyphLoader(c,a))}return r}function Kc(t,e,n,c){var r=new x2.GlyphSet(c);return c._push=function(a){var s=n[a],i=n[a+1];s!==i?r.push(a,x2.ttfGlyphLoader(c,a,U8,t,e+s,G8)):r.push(a,x2.glyphLoader(c,a))},r}function Qc(t,e,n,c,r){return r.lowMemory?Kc(t,e,n,c):Jc(t,e,n,c)}var j8={getPath:B8,parse:Qc},_8,o3,W8,F6;function X8(t){this.font=t,this.getCommands=function(e){return j8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function er(t){return t}function Z8(t){return Math.sign(t)*Math.round(Math.abs(t))}function tr(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function nr(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function cr(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function rr(t){return Math.sign(t)*Math.floor(Math.abs(t))}var Y8=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},b2={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){b2.setRelative(t,t,(o+l)/2,c,!0);return}b2.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(b2);Object.freeze(E2);function S5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}S5.prototype.distance=function(t,e,n,c){return this.x*b2.distance(t,e,n,c)+this.y*E2.distance(t,e,n,c)};S5.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)};S5.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};S5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function L5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?b2:t===0&&e===1?E2:new S5(t,e)}function T2(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)}T2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};T2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var w5=Object.freeze(new T2(0,0)),ar={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function j2(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=b2,this.round=Z8}}X8.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){j2.prototype=ar,r=this._fpgmState=new j2("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}}j2.prototype=r,c=this._prepState=new j2("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 W8(t,c)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};W8=function(t,e){var n=e.ppem/e.font.unitsPerEm,c=n,r=t.components,a,s,i;if(j2.prototype=e,!r)i=new j2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),F6(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 j2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),F6(u,i,n,c);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*c),m=i.gZone,p=i.contours,g=0;g<m.length;g++){var v=m[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,m);for(var b=0;b<p.length;b++)a.push(p[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new j2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new T2(0,0),new T2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),o3(i),s.length-=2)}return s};F6=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 T2(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 T2(0,0),new T2(Math.round(t.advanceWidth*n),0)),o3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<a;m++)console.log(m,s[m].x,s[m].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=_8[e[t.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));c(t)}}};function g4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new T2(0,0)}function J8(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 B7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function G7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function j7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function _7(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=L5(i,o)}function W7(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=L5(i,o)}function sr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.pv=t.dpv=L5(c,n)}function ir(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.fv=L5(c,n)}function or(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 lr(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 hr(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function ur(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 m=l.x,p=l.y,g=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,S=(m-g)*(b-M)-(p-v)*(y-x),w=m*v-p*g,z=y*M-b*x;d.x=(w*(y-x)-z*(m-g))/S,d.y=(w*(b-M)-z*(p-v))/S}function fr(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function dr(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function mr(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function pr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||g4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function gr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||g4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function vr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||g4(t),t.z2=t.tZone;break;case 1:t.z2=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,"SZPS[]",e),t.zp0=t.zp1=t.zp2=e,e){case 0:t.tZone||g4(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 br(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function xr(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=Z8}function Mr(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=nr}function wr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function zr(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),J8(t,!1)}function kr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Sr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Lr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function k6(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function Ar(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Cr(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 Pr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Er(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 Tr(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 Ir(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Vr(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 Hr(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 X7(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,w5);t&&(s=e.round(s)),r.setRelative(c,w5,s,a),r.touch(c),e.rp0=e.rp1=n}function Z7(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 Y7(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 J7(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 K7(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 Or(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 Rr(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 Q7(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 Fr(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 $r(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=tr}function e8(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,w5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,w5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=r}function Dr(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 qr(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 Nr(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 Ur(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 Br(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 Gr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function t8(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,w5,t,!1)*64)}function n8(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 jr(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function _r(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Wr(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 Xr(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 Zr(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 Yr(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 Jr(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 Kr(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 Qr(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 ea(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 ta(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(J8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function na(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function ca(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 ra(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 aa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function S6(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 m=(f&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",m*o);var p=l[u];r.setRelative(p,p,m*o,a)}}}function sa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function oa(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 la(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 ha(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 ua(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 fa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function da(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function ma(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function pa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function i4(t,e){var n=e.stack,c=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(c/64)*64)}function ga(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 L6(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 va(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=Y8;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 ya(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=Y8;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 ba(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=er}function xa(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=cr}function Ma(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=rr}function wa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function c8(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=L5(i,o)}function za(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 ka(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 Sa(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 La(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 Aa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ca(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,m=a.dpv,p,g,v,y;g=p=m.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,m),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 =",p,"->",v*g,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}_8=[B7.bind(void 0,E2),B7.bind(void 0,b2),G7.bind(void 0,E2),G7.bind(void 0,b2),j7.bind(void 0,E2),j7.bind(void 0,b2),_7.bind(void 0,0),_7.bind(void 0,1),W7.bind(void 0,0),W7.bind(void 0,1),sr,ir,or,lr,hr,ur,fr,dr,mr,pr,gr,vr,yr,br,xr,Mr,wr,zr,kr,Sr,void 0,void 0,Lr,k6,Ar,Cr,Pr,Ir,Vr,void 0,void 0,void 0,Er,Tr,Hr,void 0,X7.bind(void 0,0),X7.bind(void 0,1),Z7.bind(void 0,E2),Z7.bind(void 0,b2),Y7.bind(void 0,0),Y7.bind(void 0,1),J7.bind(void 0,0),J7.bind(void 0,1),K7.bind(void 0,0),K7.bind(void 0,1),Or,Rr,Q7.bind(void 0,0),Q7.bind(void 0,1),Fr,$r,e8.bind(void 0,0),e8.bind(void 0,1),Dr,qr,Nr,Ur,Br,Gr,t8.bind(void 0,0),t8.bind(void 0,1),void 0,n8.bind(void 0,0),n8.bind(void 0,1),jr,void 0,_r,void 0,void 0,Wr,Xr,Zr,Yr,Jr,Kr,Qr,ea,ta,na,ca,ra,aa,S6.bind(void 0,1),sa,ia,oa,la,ha,ua,fa,da,ma,pa,i4.bind(void 0,0),i4.bind(void 0,1),i4.bind(void 0,2),i4.bind(void 0,3),void 0,void 0,void 0,void 0,ga,S6.bind(void 0,2),S6.bind(void 0,3),L6.bind(void 0,1),L6.bind(void 0,2),L6.bind(void 0,3),va,ya,void 0,void 0,ba,void 0,xa,Ma,k6,k6,void 0,void 0,void 0,void 0,void 0,wa,c8.bind(void 0,0),c8.bind(void 0,1),za,void 0,ka,Sa,La,Aa,Ca,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 _6(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function Pa(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function s2(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 v4(t){this.eventId=t,this.subscribers=[]}function Ea(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 v4(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=[],Ea.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)};v4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};v4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};s2.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)};s2.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 _6)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 v4&&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 Pa(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 s2(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 _6(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 _6(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 s2(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 _2(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function K8(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 l4(t){return/[A-z]/.test(t)}function Ta(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 A5(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 Ia(t,e){var n=A5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Va(t,e){var n=A5(t,e.coverage);return n===-1?null:e.substitute[n]}function A6(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=A5(a,r);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function Ha(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var c=A6(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 s2(a,0),i=A6(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 s2(o,0),h=A6(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 m=e.lookupRecords[d],p=m.lookupListIndex,g=this.getLookupByIndex(p),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 S=t.get(M),w=b(S);w&&f.push(w)}}return f}function Oa(t,e){var n=t.current,c=A5(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 Ra(t,e){var n=A5(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 Ia.apply(n,[r,e])};case"12":return function(r){return Va.apply(n,[r,e])};case"63":return function(r){return Ha.apply(n,[r,e])};case"41":return function(r){return Oa.apply(n,[r,e])};case"21":return function(r){return Ra.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 s2(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 Fa(t){var e=t.current,n=t.get(-1);return n===null&&_2(e)||!_2(n)&&_2(e)}function $a(t){var e=t.get(1);return e===null||!_2(e)}var Da={startCheck:Fa,endCheck:$a};function qa(t){var e=t.current,n=t.get(-1);return(_2(e)||W2(e))&&!_2(n)}function Na(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!_2(e)&&!W2(e)):var n=Ta(e);if(!n)return!0;if(n){var c=!1;if(c=t.lookahead.some(function(r){return _2(r)||W2(r)}),!c)return!0}break;default:return!1}}var Ua={startCheck:qa,endCheck:Na};function Ba(t,e,n){e[n].setState(t.tag,t.substitution)}function Ga(t,e,n){e[n].setState(t.tag,t.substitution)}function ja(t,e,n){t.substitution.forEach(function(c,r){var a=e[n+r];a.setState(t.tag,c)})}function _a(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 r8={11:Ba,12:Ga,63:ja,41:_a};function W6(t,e,n){t instanceof i3&&r8[t.id]&&r8[t.id](t,e,n)}function Wa(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var c=e[n],r=K8(c),a=W2(c);if(!r&&!a)return!0;if(r)return!1}return!1}function Xa(t){if(K8(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 Za(t){var e=this,n="arab",c=this.featuresTags[n],r=this.tokenizer.getRangeTokens(t);if(r.length!==1){var a=new s2(r.map(function(i){return i.getState("glyphIndex")}),0),s=new s2(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;Wa(s)&&(l|=1),Xa(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&&(W6(f,r,d),a.context[d]=f.substitution)})}}})}}function a8(t,e){var n=t.map(function(c){return c.activeState.value});return new s2(n,e||0)}function Ya(t){var e=this,n="arab",c=this.tokenizer.getRangeTokens(t),r=a8(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 W6(o,c,s)}),r=a8(c))})}function Ja(t){var e=t.current,n=t.get(-1);return n===null&&l4(e)||!l4(n)&&l4(e)}function Ka(t){var e=t.get(1);return e===null||!l4(e)}var Qa={startCheck:Ja,endCheck:Ka};function s8(t,e){var n=t.map(function(c){return c.activeState.value});return new s2(n,e||0)}function es(t){var e=this,n="latn",c=this.tokenizer.getRangeTokens(t),r=s8(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 W6(o,c,s)}),r=s8(c))})}function l2(t){this.baseDir=t||"ltr",this.tokenizer=new u0,this.featuresTags={}}l2.prototype.setText=function(t){this.text=t};l2.prototype.contextChecks={latinWordCheck:Qa,arabicWordCheck:Da,arabicSentenceCheck:Ua};function C6(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function ts(){return C6.call(this,"latinWord"),C6.call(this,"arabicWord"),C6.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function ns(){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())})}l2.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};l2.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)}};l2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function X6(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function cs(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){X6.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(c){Za.call(t,c)})}}function rs(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){X6.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(r){Ya.call(t,r)})}}}function as(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){X6.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(r){es.call(t,r)})}}}l2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};l2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(cs.call(this),rs.call(this)),this.checkContextReady("latinWord")&&as.call(this),this.checkContextReady("arabicSentence")&&ns.call(this)};l2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),ts.call(this),this.applyFeaturesToContexts())};l2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};l2.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||(v5(t.familyName,"When creating a new Font object, familyName is required."),v5(t.styleName,"When creating a new Font object, styleName is required."),v5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),v5(t.ascender,"When creating a new Font object, ascender is required."),v5(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 x2.GlyphSet(this,t.glyphs||[]),this.encoding=new v8(this),this.position=new k5(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 X8(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 l2,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 x0;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 _c.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(Xc())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=w7(),l=Zc(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 Q8(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 ss(t,e,n){var c=Q8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:c}]}function is(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 os(t,e,n,c){for(var r=Q8(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 ls(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 hs(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(ss(c,t.axes[c],e));for(var r=0;r<t.instances.length;r++)n.fields=n.fields.concat(os(r,t.instances[r],t.axes,e));return n}function us(t,e,n){var c=new f1.Parser(t,e),r=c.parseULong();z1.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(is(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,m=0;m<o;m++)f.push(ls(t,d+m*l,h,n));return{axes:h,instances:f}}var fs={make:hs,parse:us},ds=function(){return{coverage:this.parsePointer(H.coverage),attachPoints:this.parseList(H.pointer(H.uShortList))}},ms=function(){var t=this.parseUShort();if(z1.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()}},ps=function(){return this.parseList(H.pointer(ms))},gs=function(){return{coverage:this.parsePointer(H.coverage),ligGlyphs:this.parseList(H.pointer(ps))}},vs=function(){return this.parseUShort(),this.parseList(H.pointer(H.coverage))};function ys(t,e){e=e||0;var n=new H(t,e),c=n.parseVersion(1);z1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var r={version:c,classDef:n.parsePointer(H.classDef),attachList:n.parsePointer(ds),ligCaretList:n.parsePointer(gs),markAttachClassDef:n.parsePointer(H.classDef)};return c>=1.2&&(r.markGlyphSets=n.parsePointer(vs)),r}var bs={parse:ys},i2=new Array(10);i2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(H.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(H.coverage),values:this.parseValueRecordList()};z1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};i2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();z1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(H.coverage),r=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,pairSets:this.parseList(H.pointer(H.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(H.classDef),i=this.parsePointer(H.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,H.list(l,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}}))}}};i2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};i2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};i2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};i2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};i2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};i2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};i2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function xs(t,e){e=e||0;var n=new H(t,e),c=n.parseVersion(1);return z1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(i2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(i2),variations:n.parseFeatureVariationsList()}}var Ms=new Array(10);function ws(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,Ms)}])}var zs={parse:xs,make:ws};function ks(t){var e={};t.skip("uShort");var n=t.parseUShort();z1.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 Ss(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 Ls(t,e){var n=new f1.Parser(t,e),c=n.parseUShort();if(c===0)return ks(n);if(c===1)return Ss(n);throw new Error("Unsupported kern table version ("+c+").")}var As={parse:Ls};function Cs(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 Ps={parse:Cs};function i8(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 Es(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(zn(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 et(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=i8(a,s);else if(o==="OTTO")r.outlinesFormat="cff",s=f1.getUShort(a,4),i=i8(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=Es(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,m,p,g,v,y,b,x,M,S=0;S<s;S+=1){var w=i[S],z=void 0;switch(w.tag){case"cmap":z=d0(a,w),r.tables.cmap=g8.parse(z.data,z.offset),r.encoding=new y8(r.tables.cmap);break;case"cvt ":z=d0(a,w),M=new f1.Parser(z.data,z.offset),r.tables.cvt=M.parseShortList(w.length/2);break;case"fvar":u=w;break;case"fpgm":z=d0(a,w),M=new f1.Parser(z.data,z.offset),r.tables.fpgm=M.parseByteList(w.length);break;case"head":z=d0(a,w),r.tables.head=C8.parse(z.data,z.offset),r.unitsPerEm=r.tables.head.unitsPerEm,n=r.tables.head.indexToLocFormat;break;case"hhea":z=d0(a,w),r.tables.hhea=P8.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=w;break;case"ltag":z=d0(a,w),c=T8.parse(z.data,z.offset);break;case"maxp":z=d0(a,w),r.tables.maxp=I8.parse(z.data,z.offset),r.numGlyphs=r.tables.maxp.numGlyphs;break;case"name":b=w;break;case"OS/2":z=d0(a,w),r.tables.os2=R6.parse(z.data,z.offset);break;case"post":z=d0(a,w),r.tables.post=$8.parse(z.data,z.offset),r.glyphNames=new U6(r.tables.post);break;case"prep":z=d0(a,w),M=new f1.Parser(z.data,z.offset),r.tables.prep=M.parseByteList(w.length);break;case"glyf":f=w;break;case"loca":y=w;break;case"CFF ":h=w;break;case"kern":v=w;break;case"GDEF":d=w;break;case"GPOS":m=w;break;case"GSUB":p=w;break;case"meta":x=w;break}}var C=d0(a,b);if(r.tables.name=F8.parse(C.data,C.offset,c),r.names=r.tables.name,f&&y){var k=n===0,T=d0(a,y),q=Ps.parse(T.data,T.offset,r.numGlyphs,k),R=d0(a,f);r.glyphs=j8.parse(R.data,R.offset,q,r,e)}else if(h){var U=d0(a,h);A8.parse(U.data,U.offset,r,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var j=d0(a,g);if(E8.parse(r,j.data,j.offset,r.numberOfHMetrics,r.numGlyphs,r.glyphs,e),Gn(r,e),v){var V=d0(a,v);r.kerningPairs=As.parse(V.data,V.offset)}else r.kerningPairs={};if(d){var Q=d0(a,d);r.tables.gdef=bs.parse(Q.data,Q.offset)}if(m){var W=d0(a,m);r.tables.gpos=zs.parse(W.data,W.offset),r.position.init()}if(p){var o1=d0(a,p);r.tables.gsub=D8.parse(o1.data,o1.offset)}if(u){var m1=d0(a,u);r.tables.fvar=fs.parse(m1.data,m1.offset,r.names)}if(x){var I=d0(a,x);r.tables.meta=q8.parse(I.data,I.offset),r.metas=r.tables.meta}return r}var y4=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=et(a);return this.parsed.set(n,s),s}};function Ts(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 tt(t,e,n){let{cmds:c,advance:r}=Ts(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=E3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:r}}function b4(t,e,n){if(!e)return[];let c=t.get(n.font),{polys:r,advance:a}=tt(c,e,n),s=w1(r),i=k0(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 Z6(t,e,n){let c=t.get(n.font),{polys:r,advance:a}=tt(c,e,n),s=k0(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 nt=128,x4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],rt={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Is(t,e){if(!t||G0(K6,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 Vs=100,Hs={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},$3=4,ct=8,Os=t=>{let e=Vs,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},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,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}},Y6=t=>t?`.${t}`:"",J6=["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:Rs(t,r);a<c&&([n,c]=[r,a])}return n?` Did you mean "${n}"?`:""}function Rs(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 K6=g5,D3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.pointCount=0;this.itemCount=0;this.copies=0;this.frame=l6;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(x4.map(e=>[e.name,e]));this.loaded=new Map;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...rt,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new E0,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 E0(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 (${P2(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=Is(n.file,e),r=e,a=G0(K6,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}=r2(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(K6,c.pos.file)===void 0)&&(c.kind==="module"?G0(this.builtins,c.name)!==void 0:G0(h5,c.name)!==void 0||J6.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${P2(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 E0(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(R0(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&&!Be(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 E0(n));case"if":return h0(this.expr(e.cond,n))?this.block(e.then,new E0(n)):this.block(e.else,new E0(n));case"let":{let r=new E0(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==="%"?i5(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 Q5(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 E0(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 E0(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=p5(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 (${P2(c.at,!1)})`)}unknownArg(e,n,c,r){this.warn(`${e}: unknown argument "${n}"${Y6(l3(n,r))} (${P2(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 E0(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 E0(n,n);for(let[f,d]of c.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new E0(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 m of e.children){let p=this.stmt(m,f);i.includes(m)&&d.push(p??J0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let m=[];for(let p of e.children){let g=this.stmt(p,d);i.includes(p)&&(m.push(g??J0()),f(m.length-1,g??J0()))}return m}},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=Os(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=A2(e)?e.scope:e.env,s=new E0(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}"${Y6(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(R0(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(R0(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 E0(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 E0(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&&!A2(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(h5,r);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(r,h);for(let m of d7(l,h.pos,h.named))this.warn(`${r}(): "${m}" is given by position and by name; the named value is used (${P2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:m=>this.tick(e.pos,m),given:h.pos.length+l.params.filter(m=>h.named.has(m)).length},f=m7(l,h.pos,h.named);this.tick(e.pos,p7(r,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof i1)throw m;let p=new i1(m instanceof RangeError?`${r}(): the result is too large`:m.message,e.pos);throw p.call=r,p}return this.checkValue(d,e.pos,r),d}throw new i1(`Unknown function ${r}()${Y6(l3(r,[...n.names("fns"),...n.names("vars"),...Object.keys(h5),...J6]))}`,e.pos)}if(!A2(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(!A2(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=w1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||y0(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 (${P2(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*Hs[e.unit]/c}callable(e,n){return!!n.fn(e)||J6.includes(e)||!!G0(h5,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?"":": "+L0(n)}`,e.at)}echo(e,n){this.charge(Math.ceil(e.length/ct),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 ${_0(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 ${_0(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 ${_0(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 ${_0(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/ct):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=_e(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 Z6(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:L0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:L0(this.arg(e,"halign",-1,"left")),valign:L0(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=Z6(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 ${_0(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 ${_0(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 ${_0(c)}`);return{x0:a,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>z3(s.children(),i),n=s=>i=>i5(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 ${_0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!h0(this.dyn(i.env,"$mirrored"))),i5(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=We(i,o,l,this.segs(s.env));return z0(w1([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 z0([k3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return z0([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 z0([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 z0(w1([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 z0(w1(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=E3(T3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return h0(this.arg(s.args,"close",-1,!1))?z0(w1([...o.closed,...o.open.filter(h=>h.length>2)],l)):q2([z0(w1(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 z0(w1([[[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=b4(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 z0(w1(l.map(f=>f.map(([d,m])=>[h+u-d,m]))))}return z0(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[m,p]=this.vec2(f,"center",!1);d=[h,u,-u,h,m-h*m+u*p,p-u*m-h*p]}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:y0(h.regions,l.regions),lines:g2(h.lines,w1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return J0();let o=m=>[...m.layers.values()].some(p=>p.regions.length),l=m=>{let p;for(let g of i){if(g===m||!o(g))continue;let v=w1(r([g],"intersection").regions);p=p?b0(p,v):v}return p},h=i[0],u=i.every(o),f=l(h),d=a(h,m=>({regions:u?f?b0(m.regions,f):m.regions:[],lines:f?g2(m.lines,f,"inside"):m.lines}));for(let m of i){if(m===h)continue;if(m.parts.length)throw new Error("part() can only be the first child of intersection()");let p=l(m),g=new Map;for(let[v,y]of m.layers)y.lines.length&&g.set(v,{regions:[],lines:p?g2(y.lines,p,"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[m,p]of l){f&&(p.regions.length||p.lines.length)&&(u=m,f=!1);for(let g of[...p.regions,...p.lines])for(let v of g)h.push(v)}let d=je(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:p0(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=w1(r(u,"pattern").regions),d=$0(h.layers),m=k0(f);if(!d||!m)return J0();let p=Math.floor((m[1]-d[3])/o),g=Math.ceil((m[3]-d[1])/o),v=Math.floor((m[0]-d[2])/i)-1,y=Math.ceil((m[2]-d[0])/i)+1,b=(g-p+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=B0(f).map(C=>({polys:C,box:k0(C)})),M=f,S=(C,k)=>{let T=0;for(let q of M)for(let R=0,U=q.length-1;R<q.length;U=R++){let[j,V]=q[U],[Q,W]=q[R];V<=k?W>k&&(Q-j)*(k-V)-(C-j)*(W-V)>0&&T++:W<=k&&(Q-j)*(k-V)-(C-j)*(W-V)<0&&T--}return T!==0},w=new Map,z=(C,k)=>{let T=w.get(C)??{regions:[],lines:[]};for(let q of k.regions)T.regions.push(q);for(let q of k.lines)T.lines.push(q);w.set(C,T)};for(let C=p;C<=g;C++)for(let k=v;k<=y;k++){let T=k*i+(C%2?l*i:0),q=C*o,R=[d[0]+T,d[1]+q,d[2]+T,d[3]+q];if(R[2]<m[0]||R[0]>m[2]||R[3]<m[1]||R[1]>m[3])continue;let U=x.filter(o1=>!(R[2]<o1.box[0]||R[0]>o1.box[2]||R[3]<o1.box[1]||R[1]>o1.box[3]));if(!U.length)continue;M=U.length===x.length?f:U.flatMap(o1=>o1.polys);let j=[S(R[0],R[1]),S(R[2],R[1]),S(R[2],R[3]),S(R[0],R[3])],V=M.some(o1=>o1.some(([m1,I])=>m1>R[0]&&m1<R[2]&&I>R[1]&&I<R[3])),Q=j.every(Boolean)&&!V,W=[1,0,0,1,T,q];for(let[o1,m1]of z3({layers:h.layers,parts:[]},W).layers)z(o1,Q?m1:{regions:b0(m1.regions,M),lines:g2(m1.lines,M,"inside")})}return{layers:w,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=p6(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 z0(w1(j5([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=w1(r([s.children()],"hatch").regions),u=k0(h);if(!u)return J0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],m=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,p=i*Math.PI/180,[g,v]=[Math.cos(p),Math.sin(p)],[y,b]=[-v,g],x=Math.ceil(m/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=[],S=Math.round((f*y+d*b)/o);for(let z=S-x;z<=S+x;z++){let C=z*o-(f*y+d*b),[k,T]=[f+y*C,d+b*C];M.push([[k-g*m,T-v*m],[k+g*m,T+v*m]])}if(l===void 0)return D2(g2(M,h,"inside"));let w=this.num(l,"hatch","width");if(!(w>0))throw new Error("width must be more than 0");return z0(b0(w1(j5(M,w).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 m=h,p=w1(r([d],"paint").regions);u[f]=p,h=m.length?w1([...m,...p]):p;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(z0(m.length?y0(p,m):p,g))):l.push(m.length?a(d,v=>({regions:y0(v.regions,m),lines:g2(v.lines,m,"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=$0(h.layers)??k0(h.parts.flatMap(f=>[...f.layers.values()].flatMap(d=>[...d.regions,...d.lines])));s.env.vars.set("$bounds",u?[...u]: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:w1(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:p0(p0(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:w1([...o.regions,...j5(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...w1(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 m=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(m))throw new Error('mode must be "cut", "line", "fill" or "guide"');let p=L0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(p))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&&m==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:m,color:p,...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 ${_0(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"))),i5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=L0(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),m=d===void 0?void 0:L0(d),p=L0(this.arg(s.args,"face",-1,"top"));if(p!=="top"&&p!=="bottom")throw new Error(`face must be "top" or "bottom", got ${_0(p)}`);let g=this.frame!==l6&&m===void 0,v=this.arg(s.args,"bend",-1),y=u===void 0&&f===void 0&&!g&&m===void 0&&v===void 0?void 0:this.placements(u,f,o),b=this.thickness(s.env);y&&(g||h>1)&&(y=y.flatMap(W=>{let o1=m===void 0?$1(this.frame,K0(W)):K0(W),m1=m!==void 0&&p==="bottom"?-b:b;return Array.from({length:h},(I,$)=>({...W,matrix:$1(o1,D0(0,0,$*m1))}))}));let x=this.arg(s.args,"mirror",-1,!1),M;if(Array.isArray(x)){if(x.length!==o)throw new Error(`mirror needs one true or false per copy: qty is ${o} but mirror has ${x.length}`);M=x.map(W=>h0(W))}else M=Array.from({length:o},()=>h0(x));let S=M.some(W=>W)&&!M.every(W=>W);if(S&&m!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let w=M[0],z=W=>{let o1=s.env.vars.get("$mirrored"),m1=s.env.vars.has("$mirrored");W&&s.env.vars.set("$mirrored",!0);try{let I=s.children();return W?z3(I,[-1,0,0,1,0,0]):I}finally{W&&(m1?s.env.vars.set("$mirrored",o1):s.env.vars.delete("$mirrored"))}},C=z(w),k=this.bends(v),T=this.arg(s.args,"on",-1),q=this.arg(s.args,"slots",-1),R=q===void 0?void 0:(Array.isArray(q)?q:[q]).map(W=>{if(typeof W!="string")throw new Error("slots must be part names");return W}),U=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),j=(W,o1,m1)=>{let I=m1.length===o,$=y?.filter((Z,_)=>m1.includes(Math.floor(_/h)+1));return{name:i,qty:m1.length*h,layers:W,thickness:b,kerf:A0(this.dyn(s.env,"$kerf"))||0,material:L0(this.dyn(s.env,"$material")??"material"),...$?{placements:$}:{},...h>1?{stack:h}:{},...k.length?{bends:k}:{},...T!==void 0?{on:L0(T)}:{},...R?{slots:R,clearance:U}:{},...this.step?{step:this.step}:{},...m!==void 0&&{glue:{host:m,face:p}},...o1&&{mirrored:!0},...!I&&{copies:m1}}},V=W=>M.flatMap((o1,m1)=>o1===W?[m1+1]:[]),Q=S?[j(C.layers,w,V(w)),j(z(!w).layers,!w,V(!w))]:[j(C.layers,w,V(w))];return{layers:new Map,parts:[...C.parts,...Q]}},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=$1(l,K0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=L0(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=L0(this.arg(s.args,"kind",0,"dowel"));G0(I3,i)===void 0&&G0(d5,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${P2(s.args.at,!1)})${l3(i,Object.keys(I3))}`);let o=this.vec3(this.arg(s.args,"from",1),"from"),l=this.vec3(this.arg(s.args,"to",2),"to"),h=this.arg(s.args,"size",3,6),u=typeof h=="number"?h:this.vec2(h,"size",!1),f=[l[0]-o[0],l[1]-o[1],l[2]-o[2]],d=Math.abs(f[2])>.9*Math.hypot(...f),m=this.arg(s.args,"up",-1),p=m===void 0?d?[0,1,0]:[0,0,1]:this.vec3(m,"up"),g=Math.floor(this.num(this.arg(s.args,"sides",-1,24),"hardware","sides"));if(!(g>=3&&g<=nt))throw new Error(`sides must be from 3 to ${nt}, got ${_0(g)}`);if(this.pointCount+=g*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 v=this.arg(s.args,"label",-1),y=this.frame,b=M=>[y[0]*M[0]+y[1]*M[1]+y[2]*M[2]+y[3],y[4]*M[0]+y[5]*M[1]+y[6]*M[2]+y[7],y[8]*M[0]+y[9]*M[1]+y[10]*M[2]+y[11]],x=M=>[y[0]*M[0]+y[1]*M[1]+y[2]*M[2],y[4]*M[0]+y[5]*M[1]+y[6]*M[2],y[8]*M[0]+y[9]*M[1]+y[10]*M[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:b(o),to:b(l),size:u,up:x(p),sides:g,step:this.step,...v!==void 0?{label:L0(v)}:{}}),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",L0(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 E0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(p=>u.add(p));else for(let p of this.iterable(l,s.args.at))o[A0(p)]&&u.add(o[A0(p)]);let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let m=this.childKey(h);for(let p of i.stmts)if(p.kind==="assign")this.stmt(p,h);else if(u.has(p)){let g=m&&d.get(p);if(g&&g.key===m){g.shape&&f.push(g.shape);continue}let v=this.effects(),y=this.stmt(p,h);y&&f.push(y),m&&this.effects()===v&&!y?.parts.length&&d.set(p,{key:m,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),z0(t4(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),z0(g7(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 z0(w1(v7(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(y7(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)},Q6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function ee(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${ee(t,e).map(([n,c])=>`${n} ${c}`).join("L")}${e?"Z":""}`;function M4(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 w4(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="${Q6(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="${Q6(a.name)}" inkscape:groupmode="layer" inkscape:label="${Q6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return r.push("</svg>",""),r.join(`
|
|
2227
|
-
`)}var
|
|
2642
|
+
`};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),i;return s>=55296&&s<=56319&&c>a+1&&(i=r.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 r6=0,G7=-3;function I5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function cr(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new I5,this.dtree=new I5}var W7=new I5,X7=new I5,c6=new Uint8Array(30),a6=new Uint16Array(30),Z7=new Uint8Array(30),Y7=new Uint16Array(30),ar=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),i7=new I5,C2=new Uint8Array(320);function J7(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 sr(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 o7=new Uint16Array(16);function De(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)o7[c]=a,a+=t.table[c];for(c=0;c<r;++c)e[n+c]&&(t.trans[o7[e[n+c]]++]=c)}function ir(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function P2(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 Xe(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 or(t,e,n){var r,c,a,s,i,o;for(r=P2(t,5,257),c=P2(t,5,1),a=P2(t,4,4),s=0;s<19;++s)C2[s]=0;for(s=0;s<a;++s){var l=P2(t,3,0);C2[ar[s]]=l}for(De(i7,C2,0,19),i=0;i<r+c;){var h=Xe(t,i7);switch(h){case 16:var u=C2[i-1];for(o=P2(t,2,3);o;--o)C2[i++]=u;break;case 17:for(o=P2(t,3,3);o;--o)C2[i++]=0;break;case 18:for(o=P2(t,7,11);o;--o)C2[i++]=0;break;default:C2[i++]=h;break}}De(e,C2,0,r),De(n,C2,r,c)}function l7(t,e,n){for(;;){var r=Xe(t,e);if(r===256)return r6;if(r<256)t.dest[t.destLen++]=r;else{var c,a,s,i;for(r-=257,c=P2(t,c6[r],a6[r]),a=Xe(t,n),s=t.destLen-P2(t,Z7[a],Y7[a]),i=s;i<s+c;++i)t.dest[t.destLen++]=t.dest[i]}}}function lr(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 G7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,r6}function hr(t,e){var n=new cr(t,e),r,c,a;do{switch(r=ir(n),c=P2(n,2,0),c){case 0:a=lr(n);break;case 1:a=l7(n,W7,X7);break;case 2:or(n,n.ltree,n.dtree),a=l7(n,n.ltree,n.dtree);break;default:a=G7}if(a!==r6)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}sr(W7,X7);J7(c6,a6,4,3);J7(Z7,Y7,2,1);c6[28]=0;a6[28]=258;var ur=hr;function N3(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 n3(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}n3.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};n3.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))};n3.prototype.addX=function(t){this.addPoint(t,null)};n3.prototype.addY=function(t){this.addPoint(null,t)};n3.prototype.addBezier=function(t,e,n,r,c,a,s,i){var o=[t,e],l=[n,r],h=[c,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],m=-3*o[f]+9*l[f]-9*h[f]+3*u[f],g=3*l[f]-3*o[f];if(m===0){if(d===0)continue;var p=-g/d;0<p&&p<1&&(f===0&&this.addX(N3(o[f],l[f],h[f],u[f],p)),f===1&&this.addY(N3(o[f],l[f],h[f],u[f],p)));continue}var v=Math.pow(d,2)-4*g*m;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*m);0<y&&y<1&&(f===0&&this.addX(N3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(N3(o[f],l[f],h[f],u[f],y)));var b=(-d-Math.sqrt(v))/(2*m);0<b&&b<1&&(f===0&&this.addX(N3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(N3(o[f],l[f],h[f],u[f],b)))}}};n3.prototype.addQuad=function(t,e,n,r,c,a){var s=t+.6666666666666666*(n-t),i=e+2/3*(r-e),o=s+1/3*(c-t),l=i+1/3*(a-e);this.addBezier(t,e,s,i,o,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 n3){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 n3,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,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}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 K7(t){throw new Error(t)}function h7(t,e){t||K7(e)}var C1={fail:K7,argument:h7,assert:h7},u7=32768,f7=2147483648,B3={},K={},I1={};function y2(t){return function(){return t}}K.BYTE=function(t){return C1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};I1.BYTE=y2(1);K.CHAR=function(t){return[t.charCodeAt(0)]};I1.CHAR=y2(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};I1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};K.USHORT=function(t){return[t>>8&255,t&255]};I1.USHORT=y2(2);K.SHORT=function(t){return t>=u7&&(t=-(2*u7-t)),[t>>8&255,t&255]};I1.SHORT=y2(2);K.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};I1.UINT24=y2(3);K.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};I1.ULONG=y2(4);K.LONG=function(t){return t>=f7&&(t=-(2*f7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};I1.LONG=y2(4);K.FIXED=K.ULONG;I1.FIXED=I1.ULONG;K.FWORD=K.SHORT;I1.FWORD=I1.SHORT;K.UFWORD=K.USHORT;I1.UFWORD=I1.USHORT;K.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};I1.LONGDATETIME=y2(8);K.TAG=function(t){return C1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};I1.TAG=y2(4);K.Card8=K.BYTE;I1.Card8=I1.BYTE;K.Card16=K.USHORT;I1.Card16=I1.USHORT;K.OffSize=K.BYTE;I1.OffSize=I1.BYTE;K.SID=K.USHORT;I1.SID=I1.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)};I1.NUMBER=function(t){return K.NUMBER(t).length};K.NUMBER16=function(t){return[28,t>>8&255,t&255]};I1.NUMBER16=y2(3);K.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};I1.NUMBER32=y2(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 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 i=e[a];i==="e"?c+=e[++a]==="-"?"c":"b":i==="."?c+="a":i==="-"?c+="e":c+=i}c+=c.length&1?"f":"ff";for(var o=[30],l=0,h=c.length;l<h;l+=2)o.push(parseInt(c.substr(l,2),16));return o};I1.REAL=function(t){return K.REAL(t).length};K.NAME=K.CHARARRAY;I1.NAME=I1.CHARARRAY;K.STRING=K.CHARARRAY;I1.STRING=I1.CHARARRAY;B3.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)};B3.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)};K.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};I1.UTF16=function(t){return t.length*2};var Ze={"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"};B3.MACSTRING=function(t,e,n,r){var c=Ze[r];if(c!==void 0){for(var a="",s=0;s<n;s++){var i=t.getUint8(e+s);i<=127?a+=String.fromCharCode(i):a+=c[i&127]}return a}};var x4=typeof WeakMap=="function"&&new WeakMap,M4,fr=function(t){if(!M4){M4={};for(var e in Ze)M4[e]=new String(e)}var n=M4[t];if(n!==void 0){if(x4){var r=x4.get(n);if(r!==void 0)return r}var c=Ze[t];if(c!==void 0){for(var a={},s=0;s<c.length;s++)a[c.charCodeAt(s)]=s+128;return x4&&x4.set(n,a),a}}};K.MACSTRING=function(t,e){var n=fr(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}};I1.MACSTRING=function(t,e){var n=K.MACSTRING(t,e);return n!==void 0?n.length:0};function Ye(t){return t>=-128&&t<=127}function dr(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 mr(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(!Ye(s)||s===0&&a+1<c&&t[a+1]===0)break;++a,++r}n.push(r-1);for(var i=e;i<a;++i)n.push(t[i]+256&255);return a}function pr(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(s===0||Ye(s)&&a+1<c&&Ye(t[a+1]))break;++a,++r}n.push(64|r-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 r=t[e];r===0?e=dr(t,e,n):r>=-128&&r<=127?e=mr(t,e,n):e=pr(t,e,n)}return n};K.INDEX=function(t){for(var e=1,n=[e],r=[],c=0;c<t.length;c+=1){var a=K.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=[],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,r)};I1.INDEX=function(t){return K.INDEX(t).length};K.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(K.OPERAND(s.value,s.type)),e=e.concat(K.OPERATOR(a))}return e};I1.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 r=0;r<e.length;r+=1)C1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(K.OPERAND(t[r],e[r]));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;I1.OP=I1.BYTE;var w4=typeof WeakMap=="function"&&new WeakMap;K.CHARSTRING=function(t){if(w4){var e=w4.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(K[a.type](a.value))}return w4&&w4.set(t,n),n};I1.CHARSTRING=function(t){return K.CHARSTRING(t).length};K.OBJECT=function(t){var e=K[t.type];return C1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};I1.OBJECT=function(t){var e=I1[t.type];return C1.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,r=[],c=[],a=0;a<n;a+=1){var s=t.fields[a],i=K[s.type];C1.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"?(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;C1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(r[h])}return e};I1.TABLE=function(t){for(var e=0,n=t.fields.length,r=0;r<n;r+=1){var c=t.fields[r],a=I1[c.type];C1.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};K.RECORD=K.TABLE;I1.RECORD=I1.TABLE;K.LITERAL=function(t){return t};I1.LITERAL=function(t){return t.length};function T0(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 i=a[s],o=n[i];this[i]!==void 0&&(this[i]=o)}}T0.prototype.encode=function(){return K.TABLE(this)};T0.prototype.sizeOf=function(){return I1.TABLE(this)};function V5(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 Je(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 H5(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 A4(t){t.format===1?T0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(V5("glyph",t.glyphs))):t.format===2?T0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(H5("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}]}))):C1.assert(!1,"Coverage format must be 1 or 2.")}A4.prototype=Object.create(T0.prototype);A4.prototype.constructor=A4;function C4(t){T0.call(this,"scriptListTable",H5("scriptRecord",t,function(e,n){var r=e.script,c=r.defaultLangSys;return C1.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 T0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new T0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:c.reqFeatureIndex}].concat(V5("featureIndex",c.featureIndexes)))}].concat(H5("langSys",r.langSysRecords,function(a,s){var i=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new T0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(V5("featureIndex",i.featureIndexes)))}]})))}]}))}C4.prototype=Object.create(T0.prototype);C4.prototype.constructor=C4;function P4(t){T0.call(this,"featureListTable",H5("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 T0("featureTable",[{name:"featureParams",type:"USHORT",value:r.featureParams}].concat(V5("lookupListIndex",r.lookupListIndexes)))}]}))}P4.prototype=Object.create(T0.prototype);P4.prototype.constructor=P4;function E4(t,e){T0.call(this,"lookupListTable",Je("lookup",t,function(n){var r=e[n.lookupType];return C1.assert(!!r,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new T0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(Je("subtable",n.subtables,r)))}))}E4.prototype=Object.create(T0.prototype);E4.prototype.constructor=E4;var s1={Table:T0,Record:T0,Coverage:A4,ScriptList:C4,FeatureList:P4,LookupList:E4,ushortList:V5,tableList:Je,recordList:H5};function d7(t,e){return t.getUint8(e)}function T4(t,e){return t.getUint16(e,!1)}function gr(t,e){return t.getInt16(e,!1)}function s6(t,e){return t.getUint32(e,!1)}function Q7(t,e){var n=t.getInt16(e,!1),r=t.getUint16(e+2,!1);return n+r/65535}function vr(t,e){for(var n="",r=e;r<e+4;r+=1)n+=String.fromCharCode(t.getInt8(r));return n}function yr(t,e,n){for(var r=0,c=0;c<n;c+=1)r<<=8,r+=t.getUint8(e+c);return r}function br(t,e,n){for(var r=[],c=e;c<n;c+=1)r.push(t.getUint8(c));return r}function xr(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var Mr={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function $(t,e){this.data=t,this.offset=e,this.relativeOffset=0}$.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};$.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};$.prototype.parseCard8=$.prototype.parseByte;$.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};$.prototype.parseCard16=$.prototype.parseUShort;$.prototype.parseSID=$.prototype.parseUShort;$.prototype.parseOffset16=$.prototype.parseUShort;$.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};$.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};$.prototype.parseULong=function(){var t=s6(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};$.prototype.parseOffset32=$.prototype.parseULong;$.prototype.parseFixed=function(){var t=Q7(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};$.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};$.prototype.parseTag=function(){return this.parseString(4)};$.prototype.parseLongDateTime=function(){var t=s6(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};$.prototype.parseVersion=function(t){var e=T4(this.data,this.offset+this.relativeOffset),n=T4(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};$.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=Mr[t]*e};$.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};$.prototype.parseOffset16List=$.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};$.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};$.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};$.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};$.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};$.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 i=r[s],o=e[i];a[i]=o.call(this)}n[c]=a}return 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 i=r[s],o=e[i];a[i]=o.call(this)}n[c]=a}return 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};$.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}};$.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};$.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new $(this.data,this.offset+e).parseStruct(t)};$.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new $(this.data,this.offset+e).parseStruct(t)};$.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 i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=t.call(this);c[a]=o}else c[a]=this.parseUShortList()}return this.relativeOffset=r,c};$.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.")};$.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:$.uShort,end:$.uShort,classId:$.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};$.list=function(t,e){return function(){return this.parseList(t,e)}};$.list32=function(t,e){return function(){return this.parseList32(t,e)}};$.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};$.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};$.pointer=function(t){return function(){return this.parsePointer(t)}};$.pointer32=function(t){return function(){return this.parsePointer32(t)}};$.tag=$.prototype.parseTag;$.byte=$.prototype.parseByte;$.uShort=$.offset16=$.prototype.parseUShort;$.uShortList=$.prototype.parseUShortList;$.uLong=$.offset32=$.prototype.parseULong;$.uLongList=$.prototype.parseULongList;$.struct=$.prototype.parseStruct;$.coverage=$.prototype.parseCoverage;$.classDef=$.prototype.parseClassDef;var m7={reserved:$.uShort,reqFeatureIndex:$.uShort,featureIndexes:$.uShortList};$.prototype.parseScriptList=function(){return this.parsePointer($.recordList({tag:$.tag,script:$.pointer({defaultLangSys:$.pointer(m7),langSysRecords:$.recordList({tag:$.tag,langSys:$.pointer(m7)})})}))||[]};$.prototype.parseFeatureList=function(){return this.parsePointer($.recordList({tag:$.tag,feature:$.pointer({featureParams:$.offset16,lookupListIndexes:$.uShortList})}))||[]};$.prototype.parseLookupList=function(t){return this.parsePointer($.list($.pointer(function(){var e=this.parseUShort();C1.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($.pointer(t[e])),markFilteringSet:r?this.parseUShort():void 0}})))||[]};$.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();C1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:$.offset32,featureTableSubstitutionOffset:$.offset32});return n})||[]};var p1={getByte:d7,getCard8:d7,getUShort:T4,getCard16:T4,getShort:gr,getULong:s6,getFixed:Q7,getTag:vr,getOffset:yr,getBytes:br,bytesToString:xr,Parser:$};function wr(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(),i=c;i<=a;i+=1)t.glyphIndexMap[i]=s,s++}function kr(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 p1.Parser(n,r+c+14),i=new p1.Parser(n,r+c+16+a*2),o=new p1.Parser(n,r+c+16+a*4),l=new p1.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(),m=i.parseUShort(),g=o.parseShort(),p=l.parseUShort(),v=m;v<=d;v+=1)p!==0?(h=l.offset+l.relativeOffset-2,h+=p,h+=(v-m)*2,f=p1.getUShort(n,h),f!==0&&(f=f+g&65535)):f=v+g&65535,t.glyphIndexMap[v]=f}function zr(t,e){var n={};n.version=p1.getUShort(t,e),C1.argument(n.version===0,"cmap table version should be 0."),n.numTables=p1.getUShort(t,e+2);for(var r=-1,c=n.numTables-1;c>=0;c-=1){var a=p1.getUShort(t,e+4+c*8),s=p1.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=p1.getULong(t,e+4+c*8+4);break}}if(r===-1)throw new Error("No valid cmap sub-tables found.");var i=new p1.Parser(t,e+r);if(n.format=i.parseUShort(),n.format===12)wr(n,i);else if(n.format===4)kr(n,i,t,e,r);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function Sr(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function Lr(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function Ar(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 s1.Table("cmap",c);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)Sr(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}Lr(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],m=[],g=[];for(n=0;n<o;n+=1){var p=a.segments[n];p.end<=65535&&p.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:p.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:p.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:p.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:p.offset}),p.glyphId!==void 0&&(m=m.concat({name:"glyph_"+n,type:"USHORT",value:p.glyphId}))):l+=1,!e&&p.glyphIndex!==void 0&&(g=g.concat({name:"cmap12Start_"+n,type:"ULONG",value:p.start}),g=g.concat({name:"cmap12End_"+n,type:"ULONG",value:p.end}),g=g.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:p.glyphIndex}))}if(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(m),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+m.length*2,!e){var v=16+g.length*4;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:g.length/3}]),a.fields=a.fields.concat(g)}return a}var e8={parse:zr,make:Ar},S4=[".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"],Cr=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],Pr=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],p3=[".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 t8(t){this.font=t}t8.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 n8(t){this.cmap=t}n8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function I4(t,e){this.encoding=t,this.charset=e}I4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function i6(t){switch(t.version){case 1:this.names=p3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<p3.length?this.names[e]=p3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-p3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=p3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}i6.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};i6.prototype.glyphIndexToName=function(t){return this.names[t]};function Er(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 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 Tr(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 Ir(t,e){e.lowMemory?Tr(t):Er(t)}function Vr(t,e,n,r,c){t.beginPath(),t.moveTo(e,n),t.lineTo(r,c),t.stroke()}var m3={line:Vr};function Hr(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 l2(t){this.bindConstructorValues(t)}l2.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",Hr(this,t.path))};l2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};l2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};l2.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 i=r.xScale,o=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),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 P0,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};l2.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 C1.argument(e.length===0,"There are still points left in the current contour."),t};l2.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};l2.prototype.draw=function(t,e,n,r,c){this.getPath(e,n,r,c).draw(t)};l2.prototype.drawPoints=function(t,e,n,r){function c(u,f,d,m){t.beginPath();for(var g=0;g<u.length;g+=1)t.moveTo(f+u[g].x*m,d+u[g].y*m),t.arc(f+u[g].x*m,d+u[g].y*m,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24;for(var a=1/this.path.unitsPerEm*r,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",c(s,e,n,a),t.fillStyle="red",c(i,e,n,a)};l2.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",m3.line(t,e,-1e4,e,1e4),m3.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",m3.line(t,e+a*c,-1e4,e+a*c,1e4),m3.line(t,e+i*c,-1e4,e+i*c,1e4),m3.line(t,-1e4,n+-s*c,1e4,n+-s*c),m3.line(t,-1e4,n+-o*c,1e4,n+-o*c),t.strokeStyle="green",m3.line(t,e+l*c,-1e4,e+l*c,1e4)};function k4(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 o6(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}o6.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]};o6.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Or(t,e){return new l2({index:e,font:t})}function Fr(t,e,n,r,c,a){return function(){var s=new l2({index:e,font:t});return s.path=function(){n(s,r,c);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},k4(s,"xMin","_xMin"),k4(s,"xMax","_xMax"),k4(s,"yMin","_yMin"),k4(s,"yMax","_yMax"),s}}function Rr(t,e,n,r){return function(){var c=new l2({index:e,font:t});return c.path=function(){var a=n(t,c,r);return a.unitsPerEm=t.unitsPerEm,a},c}}var T2={GlyphSet:o6,glyphLoader:Or,ttfGlyphLoader:Fr,cffGlyphLoader:Rr};function r8(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(!r8(t[n],e[n]))return!1;return!0}else return!1}function Ke(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function K2(t,e,n){var r=[],c=[],a=p1.getCard16(t,e),s,i;if(a!==0){var o=p1.getByte(t,e+2);s=e+(a+1)*o+2;for(var l=e+3,h=0;h<a+1;h+=1)r.push(p1.getOffset(t,l,o)),l+=o;i=s+r[a]}else i=e+2;for(var u=0;u<r.length-1;u+=1){var f=p1.getBytes(t,s+r[u],s+r[u+1]);n&&(f=n(f)),c.push(f)}return{objects:c,startOffset:e,endOffset:i}}function $r(t,e){var n=[],r=p1.getCard16(t,e),c,a;if(r!==0){var s=p1.getByte(t,e+2);c=e+(r+1)*s+2;for(var i=e+3,o=0;o<r+1;o+=1)n.push(p1.getOffset(t,i,s)),i+=s;a=c+n[r]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function Dr(t,e,n,r,c){var a=p1.getCard16(n,r),s=0;if(a!==0){var i=p1.getByte(n,r+2);s=r+(a+1)*i+2}var o=p1.getBytes(n,s+e[t],s+e[t+1]);return c&&(o=c(o)),o}function qr(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 Nr(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 qr(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 Ur(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 c8(t,e,n){e=e!==void 0?e:0;var r=new p1.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(Nr(r,s))}return Ur(c)}function T5(t,e){return e<=390?e=S4[e]:e=t[e-391],e}function a8(t,e,n){for(var r={},c,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++)c=t[s.op]!==void 0?t[s.op][o]:void 0,c===void 0&&(c=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(c=T5(n,c)),i[o]=c;r[s.name]=i}else c=t[s.op],c===void 0&&(c=s.value!==void 0?s.value:null),s.type==="SID"&&(c=T5(n,c)),r[s.name]=c}return r}function Br(t,e){var n={};return n.formatMajor=p1.getCard8(t,e),n.formatMinor=p1.getCard8(t,e+1),n.size=p1.getCard8(t,e+2),n.offsetSize=p1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var s8=[{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"}],i8=[{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 _r(t,e){var n=c8(t,0,t.byteLength);return a8(n,s8,e)}function o8(t,e,n,r){var c=c8(t,e,n);return a8(c,i8,r)}function p7(t,e,n,r){for(var c=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=_r(s,r);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=o8(t,l+e,o,r);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=K2(t,u+e);i._subrs=f.objects,i._subrsBias=Ke(i._subrs)}i._privateDict=h}c.push(i)}return c}function jr(t,e,n,r){var c,a,s=new p1.Parser(t,e);n-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<n;l+=1)c=s.parseSID(),i.push(T5(r,c));else if(o===1)for(;i.length<=n;){c=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)i.push(T5(r,c)),c+=1}else if(o===2)for(;i.length<=n;){c=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)i.push(T5(r,c)),c+=1}else throw new Error("Unknown charset format "+o);return i}function Gr(t,e,n){var r,c={},a=new p1.Parser(t,e),s=a.parseCard8();if(s===0)for(var i=a.parseCard8(),o=0;o<i;o+=1)r=a.parseCard8(),c[r]=o;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 I4(c,n)}function g7(t,e,n){var r,c,a,s,i=new P0,o=[],l=0,h=!1,u=!1,f=0,d=0,m,g,p,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];m=b._subrs,g=b._subrsBias,p=b._defaultWidthX,v=b._nominalWidthX}else m=t.tables.cff.topDict._subrs,g=t.tables.cff.topDict._subrsBias,p=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=p;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,A,L,C,P,R,q,T,B,X,Z,h1,H=0;H<z.length;){var U=z[H];switch(H+=1,U){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;)r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(r,c,a,s,f,d);break;case 10:P=o.pop()+g,R=m[P],R&&k(R);break;case 11:return;case 12:switch(U=z[H],H+=1,U){case 35:r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s+o.shift(),B=q+o.shift(),X=T+o.shift(),Z=B+o.shift(),h1=X+o.shift(),f=Z+o.shift(),d=h1+o.shift(),o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;case 34:r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s,B=q+o.shift(),X=s,Z=B+o.shift(),h1=d,f=Z+o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;case 36:r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s,B=q+o.shift(),X=s,Z=B+o.shift(),h1=X+o.shift(),f=Z+o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;case 37:r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s+o.shift(),B=q+o.shift(),X=T+o.shift(),Z=B+o.shift(),h1=X+o.shift(),Math.abs(Z-f)>Math.abs(h1-d)?f=Z+o.shift():d=h1+o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+U),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(),H+=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;)r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(r,c,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);r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(r,c,a,s,f,d);break;case 26:for(o.length%2&&(f+=o.shift());o.length>0;)r=f,c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a,d=s+o.shift(),i.curveTo(r,c,a,s,f,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s,i.curveTo(r,c,a,s,f,d);break;case 28:S=z[H],A=z[H+1],o.push((S<<24|A<<16)>>16),H+=2;break;case 29:P=o.pop()+t.gsubrsBias,R=t.gsubrs[P],R&&k(R);break;case 30:for(;o.length>0&&(r=f,c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d),o.length!==0);)r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d);break;case 31:for(;o.length>0&&(r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d),o.length!==0);)r=f,c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d);break;default:U<32?console.log("Glyph "+e.index+": unknown operator "+U):U<247?o.push(U-139):U<251?(S=z[H],H+=1,o.push((U-247)*256+S+108)):U<255?(S=z[H],H+=1,o.push(-(U-251)*256-S-108)):(S=z[H],A=z[H+1],L=z[H+2],C=z[H+3],H+=4,o.push((S<<24|A<<16|L<<8|C)/65536))}}}return k(n),e.advanceWidth=x,i}function Wr(t,e,n,r){var c=[],a,s=new p1.Parser(t,e),i=s.parseCard8();if(i===0)for(var o=0;o<n;o++){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(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>=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 "+i);return c}function Xr(t,e,n,r){n.tables.cff={};var c=Br(t,e),a=K2(t,c.endOffset,p1.bytesToString),s=K2(t,a.endOffset),i=K2(t,s.endOffset,p1.bytesToString),o=K2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=Ke(n.gsubrs);var l=p7(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=K2(t,u),m=p7(t,e,d.objects,i.objects);h._fdArray=m,f+=e,h._fdSelect=Wr(t,f,n.numGlyphs,m.length)}var g=e+h.private[1],p=o8(t,g,h.private[0],i.objects);if(n.defaultWidthX=p.defaultWidthX,n.nominalWidthX=p.nominalWidthX,p.subrs!==0){var v=g+p.subrs,y=K2(t,v);n.subrs=y.objects,n.subrsBias=Ke(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;r.lowMemory?(b=$r(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=K2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=jr(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new I4(Cr,x):h.encoding===1?n.cffEncoding=new I4(Pr,x):n.cffEncoding=Gr(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new T2.GlyphSet(n),r.lowMemory)n._push=function(k){var z=Dr(k,b.offsets,t,e+h.charStrings);n.glyphs.push(k,T2.cffGlyphLoader(n,k,g7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var w=b.objects[M];n.glyphs.push(M,T2.cffGlyphLoader(n,M,g7,w))}}function l8(t,e){var n,r=S4.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+S4.length:(n=S4.length+e.length,e.push(t)),n}function Zr(){return new s1.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 Yr(t){var e=new s1.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 h8(t,e,n){for(var r={},c=0;c<t.length;c+=1){var a=t[c],s=e[a.name];s!==void 0&&!r8(s,a.value)&&(a.type==="SID"&&(s=l8(s,n)),r[a.op]={name:a.name,type:a.type,value:s})}return r}function v7(t,e){var n=new s1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=h8(s8,t,e),n}function y7(t){var e=new s1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function Jr(t){var e=new s1.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 Kr(){return new s1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function Qr(t,e){for(var n=new s1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),r=0;r<t.length;r+=1){var c=t[r],a=l8(c,e);n.fields.push({name:"glyph_"+r,type:"SID",value:a})}return n}function ec(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,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*r+h*o.x1),y1:Math.round(l*c+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-r),i=Math.round(o.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),r=Math.round(o.x),c=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-r),i=Math.round(o.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),r=Math.round(o.x),c=Math.round(o.y);else if(o.type==="C"){var u=Math.round(o.x1-r),f=Math.round(o.y1-c),d=Math.round(o.x2-o.x1),m=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:m}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),r=Math.round(o.x),c=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function tc(t){for(var e=new s1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var r=t.get(n),c=ec(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:c})}return e}function nc(t,e){var n=new s1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=h8(i8,t,e),n}function rc(t,e){for(var n=new s1.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=[],i,o=1;o<t.length;o+=1)i=t.get(o),s.push(i.name);var l=[];n.header=Zr(),n.nameIndex=Yr([e.postScriptName]);var h=v7(c,l);n.topDictIndex=y7(h),n.globalSubrIndex=Kr(),n.charsets=Qr(s,l),n.charStringsIndex=tc(t),n.privateDict=nc(a,l),n.stringIndex=Jr(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=v7(c,l),n.topDictIndex=y7(h),n}var u8={parse:Xr,make:rc};function cc(t,e){var n={},r=new p1.Parser(t,e);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),C1.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 ac(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new s1.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 f8={parse:cc,make:ac};function sc(t,e){var n={},r=new p1.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 ic(t){return new s1.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 d8={parse:sc,make:ic};function oc(t,e,n,r,c){for(var a,s,i=new p1.Parser(t,e),o=0;o<r;o+=1){o<n&&(a=i.parseUShort(),s=i.parseShort());var l=c.get(o);l.advanceWidth=a,l.leftSideBearing=s}}function lc(t,e,n,r,c){t._hmtxTableData={};for(var a,s,i=new p1.Parser(e,n),o=0;o<c;o+=1)o<r&&(a=i.parseUShort(),s=i.parseShort()),t._hmtxTableData[o]={advanceWidth:a,leftSideBearing:s}}function hc(t,e,n,r,c,a,s){s.lowMemory?lc(t,e,n,r,c):oc(e,n,r,c,a)}function uc(t){for(var e=new s1.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 m8={parse:hc,make:uc};function fc(t){for(var e=new s1.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 dc(t,e){var n=new p1.Parser(t,e),r=n.parseULong();C1.argument(r===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var c=n.parseULong(),a=[],s=0;s<c;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 p8={make:fc,parse:dc};function mc(t,e){var n={},r=new p1.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 pc(t){return new s1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var g8={parse:mc,make:pc},v8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],y8={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"},gc={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},b8={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 vc(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return y8[e];case 3:return b8[e]}}var Qe="utf-16",yc={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"},bc={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 x8(t,e,n){switch(t){case 0:return Qe;case 1:return bc[n]||yc[e];case 3:if(e===1||e===10)return Qe;break}}function xc(t,e,n){for(var r={},c=new p1.Parser(t,e),a=c.parseUShort(),s=c.parseUShort(),i=c.offset+c.parseUShort(),o=0;o<s;o++){var l=c.parseUShort(),h=c.parseUShort(),u=c.parseUShort(),f=c.parseUShort(),d=v8[f]||f,m=c.parseUShort(),g=c.parseUShort(),p=vc(l,u,n),v=x8(l,h,u);if(v!==void 0&&p!==void 0){var y=void 0;if(v===Qe?y=B3.UTF16(t,i+g,m):y=B3.MACSTRING(t,i+g,m,v),y){var b=r[d];b===void 0&&(b=r[d]={}),b[p]=y}}}var x=0;return a===1&&(x=c.parseUShort()),r}function qe(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function b7(t,e,n,r,c,a){return new s1.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 Mc(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 x7(t,e){var n=Mc(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 wc(t,e){var n,r=[],c={},a=qe(v8);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.');c[n]=t[s],r.push(n)}for(var o=qe(y8),l=qe(b8),h=[],u=[],f=0;f<r.length;f++){n=r[f];var d=c[n];for(var m in d){var g=d[m],p=1,v=o[m],y=gc[v],b=x8(p,y,v),x=K.MACSTRING(g,b);x===void 0&&(p=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),y=4,x=K.UTF16(g));var M=x7(x,u);h.push(b7(p,y,v,n,x.length,M));var w=l[m];if(w!==void 0){var k=K.UTF16(g),z=x7(k,u);h.push(b7(3,1,w,n,k.length,z))}}}h.sort(function(L,C){return L.platformID-C.platformID||L.encodingID-C.encodingID||L.languageID-C.languageID||L.nameID-C.nameID});for(var S=new s1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),A=0;A<h.length;A++)S.fields.push({name:"record_"+A,type:"RECORD",value:h[A]});return S.fields.push({name:"strings",type:"LITERAL",value:u}),S}var M8={parse:xc,make:wc},e6=[{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 kc(t){for(var e=0;e<e6.length;e+=1){var n=e6[e];if(t>=n.begin&&t<n.end)return e}return-1}function zc(t,e){var n={},r=new p1.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 Sc(t){return new s1.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 t6={parse:zc,make:Sc,unicodeRanges:e6,getUnicodeRange:kc};function Lc(t,e){var n={},r=new p1.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=p3.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]>=p3.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 i=0;i<n.numberOfGlyphs;i++)n.offset[i]=r.parseChar();break}return n}function Ac(){return new s1.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 w8={parse:Lc,make:Ac},p2=new Array(9);p2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer($.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer($.coverage),substitute:this.parseOffset16List()};C1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};p2[2]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),sequences:this.parseListOfLists()}};p2[3]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),alternateSets:this.parseListOfLists()}};p2[4]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var U3={sequenceIndex:$.uShort,lookupListIndex:$.uShort};p2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer($.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,U3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer($.coverage),classDef:this.parsePointer($.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,U3)}})};if(n===3){var r=this.parseUShort(),c=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,$.pointer($.coverage)),lookupRecords:this.parseRecordList(c,U3)}}C1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};p2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer($.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(U3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer($.coverage),backtrackClassDef:this.parsePointer($.classDef),inputClassDef:this.parsePointer($.classDef),lookaheadClassDef:this.parsePointer($.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(U3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList($.pointer($.coverage)),inputCoverage:this.parseList($.pointer($.coverage)),lookaheadCoverage:this.parseList($.pointer($.coverage)),lookupRecords:this.parseRecordList(U3)};C1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};p2[7]=function(){var e=this.parseUShort();C1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),r=new $(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:p2[n].call(r)}};p2[8]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),backtrackCoverage:this.parseList($.pointer($.coverage)),lookaheadCoverage:this.parseList($.pointer($.coverage)),substitutes:this.parseUShortList()}};function Cc(t,e){e=e||0;var n=new $(t,e),r=n.parseVersion(1);return C1.argument(r===1||r===1.1,"Unsupported GSUB table version."),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(p2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(p2),variations:n.parseFeatureVariationsList()}}var _3=new Array(9);_3[1]=function(e){return e.substFormat===1?new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.ushortList("substitute",e.substitute)))};_3[2]=function(e){return C1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("seqSet",e.sequences,function(n){return new s1.Table("sequenceSetTable",s1.ushortList("sequence",n))})))};_3[3]=function(e){return C1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("altSet",e.alternateSets,function(n){return new s1.Table("alternateSetTable",s1.ushortList("alternate",n))})))};_3[4]=function(e){return C1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("ligSet",e.ligatureSets,function(n){return new s1.Table("ligatureSetTable",s1.tableList("ligature",n,function(r){return new s1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:r.ligGlyph}].concat(s1.ushortList("component",r.components,r.components.length+1)))}))})))};_3[6]=function(e){if(e.substFormat===1){var n=new s1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new s1.Table("chainRuleSetTable",s1.tableList("chainRule",a,function(s){var i=s1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(s1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(s1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(s1.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 s1.Table("chainRuleTable",i)}))})));return n}else if(e.substFormat===2)C1.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 s1.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 s1.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 s1.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 s1.Table("chainContextTable",r);return c}C1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Pc(t){return new s1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new s1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new s1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new s1.LookupList(t.lookups,_3)}])}var k8={parse:Cc,make:Pc};function Ec(t,e){var n=new p1.Parser(t,e),r=n.parseULong();C1.argument(r===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var c=n.parseULong(),a={},s=0;s<c;s++){var i=n.parseTag(),o=n.parseULong(),l=n.parseULong(),h=B3.UTF8(t,e+o,l);a[i]=h}return a}function Tc(t){var e=Object.keys(t).length,n="",r=16+e*12,c=new s1.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 z8={parse:Ec,make:Tc};function M7(t){return Math.log(t)/Math.log(2)|0}function l6(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 w7(t,e,n,r){return new s1.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 S8(t){var e=new s1.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,M7(e.numTables));e.searchRange=16*n,e.entrySelector=M7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],c=[],a=e.sizeOf()+w7().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 i=t[s];C1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=w7(i.tableName,l6(i.encode()),a,o);for(r.push({name:l.tag+" Table Record",type:"RECORD",value:l}),c.push({name:i.tableName+" table",type:"RECORD",value:i}),a+=o,C1.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 k7(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 Ic(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function Vc(t){for(var e=[],n=[],r=[],c=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,m=0;m<t.glyphs.length;m+=1){var g=t.glyphs.get(m),p=g.unicode|0;if(isNaN(g.advanceWidth))throw new Error("Glyph "+g.name+" ("+m+"): advanceWidth is not a number.");(o>p||o===void 0)&&p>0&&(o=p),l<p&&(l=p);var v=t6.getUnicodeRange(p);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(g.name!==".notdef"){var y=g.getMetrics();e.push(y.xMin),n.push(y.yMin),r.push(y.xMax),c.push(y.yMax),s.push(y.leftSideBearing),i.push(y.rightSideBearing),a.push(g.advanceWidth)}}var b={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:Ic(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=f8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=d8.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=g8.make(t.glyphs.length),k=t6.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:k7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:k7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=m8.make(t.glyphs),S=e8.make(t.glyphs),A=t.getEnglishName("fontFamily"),L=t.getEnglishName("fontSubfamily"),C=A+" "+L,P=t.getEnglishName("postScriptName");P||(P=A.replace(/\s/g,"")+"-"+L);var R={};for(var q in t.names)R[q]=t.names[q];R.uniqueID||(R.uniqueID={en:t.getEnglishName("manufacturer")+":"+C}),R.postScriptName||(R.postScriptName={en:P}),R.preferredFamily||(R.preferredFamily=t.names.fontFamily),R.preferredSubfamily||(R.preferredSubfamily=t.names.fontSubfamily);var T=[],B=M8.make(R,T),X=T.length>0?p8.make(T):void 0,Z=w8.make(),h1=u8.make(t.glyphs,{version:t.getEnglishName("version"),fullName:C,familyName:A,weightName:L,postScriptName:P,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),H=t.metas&&Object.keys(t.metas).length>0?z8.make(t.metas):void 0,U=[x,M,w,k,B,S,Z,h1,z];X&&U.push(X),t.tables.gsub&&U.push(k8.make(t.tables.gsub)),H&&U.push(H);for(var Y=S8(U),Q=Y.encode(),W=l6(Q),F1=Y.fields,L1=!1,g1=0;g1<F1.length;g1+=1)if(F1[g1].name==="head table"){F1[g1].value.checkSumAdjustment=2981146554-W,L1=!0;break}if(!L1)throw new Error("Could not find head table with checkSum to adjust.");return Y}var Hc={make:S8,fontToTable:Vc,computeCheckSum:l6};function Ne(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 z7(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 S7(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 F5(t,e){this.font=t,this.tableName=e}F5.prototype={searchTag:Ne,binSearch:z7,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=Ne(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=Ne(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,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(r){var l=i.length;return C1.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,r,c){var a=this.getFeatureTable(t,e,n,c),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===r&&s.push(i);if(s.length===0&&c){i={lookupType:r,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=S7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=z7(t.glyphs,e);return n>=0?n:-1;case 2:var r=S7(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,i=a;i<=s;i++)e.push(i);return e}};function R5(t){F5.call(this,t,"gpos")}R5.prototype=F5.prototype;R5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};R5.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],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};R5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function t2(t){F5.call(this,t,"gsub")}function Oc(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 h6(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}t2.prototype=F5.prototype;t2.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};t2.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,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];r.push({sub:f,by:f+u})}}else{var d=o.substitute;for(h=0;h<l.length;h++)r.push({sub:l[h],by:d[h]})}}return r};t2.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,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];r.push({sub:u,by:f})}}return r};t2.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,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++)r.push({sub:l[u],by:h[u]});return r};t2.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,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],m=0;m<d.length;m++){var g=d[m];r.push({sub:[f].concat(g.components),by:g.ligGlyph})}return r};t2.prototype.addSingle=function(t,e,n,r){var c=this.getLookupTables(n,r,t,1,!0)[0],a=h6(c,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});C1.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};t2.prototype.addMultiple=function(t,e,n,r){C1.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=h6(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});C1.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};t2.prototype.addAlternate=function(t,e,n,r){var c=this.getLookupTables(n,r,t,3,!0)[0],a=h6(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});C1.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};t2.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),C1.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(Oc(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])};t2.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)}};t2.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 Fc(){return typeof window<"u"}function Rc(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),r=0;r<e.length;++r)e[r]=n[r];return e}function E5(t,e){if(!t)throw e}function L7(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 L8(t,e,n){var r=new p1.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=[],i=0;i<t.numberOfContours;i+=1)s.push(r.parseUShort());t.instructionLength=r.parseUShort(),t.instructions=[];for(var o=0;o<t.instructionLength;o+=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(C1.argument(c.length===l,"Bad flags."),s.length>0){var d=[],m;if(l>0){for(var g=0;g<l;g+=1)a=c[g],m={},m.onCurve=!!(a&1),m.lastPointOfContour=s.indexOf(g)>=0,d.push(m);for(var p=0,v=0;v<l;v+=1)a=c[v],m=d[v],m.x=L7(r,a,p,2,16),p=m.x;for(var y=0,b=0;b<l;b+=1)a=c[b],m=d[b],m.y=L7(r,a,y,4,32),y=m.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){c=r.parseUShort();var M={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(c&1)>0?(c&2)>0?(M.dx=r.parseShort(),M.dy=r.parseShort()):M.matchedPoints=[r.parseUShort(),r.parseUShort()]:(c&2)>0?(M.dx=r.parseChar(),M.dy=r.parseChar()):M.matchedPoints=[r.parseByte(),r.parseByte()],(c&8)>0?M.xScale=M.yScale=r.parseF2Dot14():(c&64)>0?(M.xScale=r.parseF2Dot14(),M.yScale=r.parseF2Dot14()):(c&128)>0&&(M.xScale=r.parseF2Dot14(),M.scale01=r.parseF2Dot14(),M.scale10=r.parseF2Dot14(),M.yScale=r.parseF2Dot14()),t.components.push(M),x=!!(c&32)}if(c&256){t.instructionLength=r.parseUShort(),t.instructions=[];for(var w=0;w<t.instructionLength;w+=1)t.instructions.push(r.parseByte())}}}function Ue(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 $c(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 C1.argument(n.length===0,"There are still points left in the current contour."),e}function A8(t){var e=new P0;if(!t)return e;for(var n=$c(t),r=0;r<n.length;++r){var c=n[r],a=null,s=c[c.length-1],i=c[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<c.length;++l)if(a=s,s=i,i=c[(l+1)%c.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 C8(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=Ue(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]],i=c.points[r.matchedPoints[1]],o={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};i=Ue([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=Ue(c.points,o)}e.points=e.points.concat(a)}}return A8(e.points)}function Dc(t,e,n,r){for(var c=new T2.GlyphSet(r),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?c.push(a,T2.ttfGlyphLoader(r,a,L8,t,e+s,C8)):c.push(a,T2.glyphLoader(r,a))}return c}function qc(t,e,n,r){var c=new T2.GlyphSet(r);return r._push=function(a){var s=n[a],i=n[a+1];s!==i?c.push(a,T2.ttfGlyphLoader(r,a,L8,t,e+s,C8)):c.push(a,T2.glyphLoader(r,a))},c}function Nc(t,e,n,r,c){return c.lowMemory?qc(t,e,n,r):Dc(t,e,n,r)}var P8={getPath:A8,parse:Nc},E8,v3,T8,n6;function I8(t){this.font=t,this.getCommands=function(e){return P8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function Uc(t){return t}function V8(t){return Math.sign(t)*Math.round(Math.abs(t))}function Bc(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function _c(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function jc(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function Gc(t){return Math.sign(t)*Math.floor(Math.abs(t))}var H8=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},E2={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,i,o,l,h;if(!r||r===this){if(c=t.xo-e.xo,a=t.xo-n.xo,o=e.x-e.xo,l=n.x-n.xo,s=Math.abs(c),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(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),o=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),i=Math.abs(a),h=s+i,h===0){E2.setRelative(t,t,(o+l)/2,r,!0);return}E2.setRelative(t,t,(o*i+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,i=a+n*r.x,o=s+n*r.y;t.x=i+(t.y-o)/r.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},q2={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,i,o,l,h;if(!r||r===this){if(c=t.yo-e.yo,a=t.yo-n.yo,o=e.y-e.yo,l=n.y-n.yo,s=Math.abs(c),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(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),o=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),i=Math.abs(a),h=s+i,h===0){q2.setRelative(t,t,(o+l)/2,r,!0);return}q2.setRelative(t,t,(o*i+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,i=a+n*r.x,o=s+n*r.y;t.y=o+r.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(E2);Object.freeze(q2);function $5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}$5.prototype.distance=function(t,e,n,r){return this.x*E2.distance(t,e,n,r)+this.y*q2.distance(t,e,n,r)};$5.prototype.interpolate=function(t,e,n,r){var c,a,s,i,o,l,h;if(s=r.distance(t,e,!0,!0),i=r.distance(t,n,!0,!0),c=r.distance(e,e,!1,!0),a=r.distance(n,n,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(t,t,(c+a)/2,r,!0);return}this.setRelative(t,t,(c*l+a*o)/h,r,!0)};$5.prototype.setRelative=function(t,e,n,r,c){r=r||this;var a=c?e.xo:e.x,s=c?e.yo:e.y,i=a+n*r.x,o=s+n*r.y,l=r.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};$5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function D5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?E2:t===0&&e===1?q2:new $5(t,e)}function N2(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)}N2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};N2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var O5=Object.freeze(new N2(0,0)),Wc={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function Q2(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=E2,this.round=V8}}I8.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){Q2.prototype=Wc,c=this._fpgmState=new Q2("fpgm",n.tables.fpgm),c.funcs=[],c.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),c.step=-1);try{v3(c)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}Q2.prototype=c,r=this._prepState=new Q2("prep",n.tables.prep),r.ppem=e;var a=n.tables.cvt;if(a)for(var s=r.cvt=new Array(a.length),i=e/n.unitsPerEm,o=0;o<a.length;o++)s[o]=a[o]*i;else r.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),r.step=-1);try{v3(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return T8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};T8=function(t,e){var n=e.ppem/e.font.unitsPerEm,r=n,c=t.components,a,s,i;if(Q2.prototype=e,!c)i=new Q2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),n6(t,i,n,r),s=i.gZone;else{var o=e.font;s=[],a=[];for(var l=0;l<c.length;l++){var h=c[l],u=o.glyphs.get(h.glyphIndex);i=new Q2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),n6(u,i,n,r);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*r),m=i.gZone,g=i.contours,p=0;p<m.length;p++){var v=m[p];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,m);for(var b=0;b<g.length;b++)a.push(g[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new Q2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new N2(0,0),new N2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),v3(i),s.length-=2)}return s};n6=function(t,e,n,r){for(var c=t.points||[],a=c.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<a;l++)o=c[l],s[l]=new N2(o.x*n,o.y*r,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 N2(0,0),new N2(Math.round(t.advanceWidth*n),0)),v3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<a;m++)console.log(m,s[m].x,s[m].y)}}};v3=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=E8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function V4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new N2(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 A7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function C7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function P7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function E7(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 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=D5(i,o)}function T7(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 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=D5(i,o)}function Xc(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.pv=t.dpv=D5(r,n)}function Zc(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.fv=D5(r,n)}function Yc(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 Jc(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 Kc(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function Qc(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop(),a=e.pop(),s=e.pop(),i=t.z0,o=t.z1,l=i[n],h=i[r],u=o[c],f=o[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,r,c,a,s);var m=l.x,g=l.y,p=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,w=(m-p)*(b-M)-(g-v)*(y-x),k=m*v-g*p,z=y*M-b*x;d.x=(k*(y-x)-z*(m-p))/w,d.y=(k*(b-M)-z*(g-v))/w}function ea(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function ta(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function na(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function ra(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||V4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function ca(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||V4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function aa(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||V4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function sa(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||V4(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 ia(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function oa(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=V8}function la(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=_c}function ha(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function ua(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),O8(t,!1)}function fa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function da(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function ma(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function Be(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function pa(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function ga(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 va(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function ya(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++)v3(t),exports.DEBUG&&console.log(++t.step,s+1<r?"next loopcall":"done loopcall",s);t.ip=c,t.prog=a}function ba(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],v3(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function xa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Ma(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 wa(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 I7(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,O5);t&&(s=e.round(s)),c.setRelative(r,O5,s,a),c.touch(r),e.rp0=e.rp1=n}function V7(t,e){var n=e.z2,r=n.length-2,c,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var i=0;i<r;i++)c=n[i],!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 H7(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,i=e.loop,o=e.z2;i--;){var l=n.pop(),h=o[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-i)+": ":"")+"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,i=n.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",i);var h=s.distance(c,c,!1,!0);do l!==c&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function F7(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,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(c,c,!1,!0),u=o.length-2,f=0;f<u;f++)l=o[f],a.setRelative(l,l,h,s)}function ka(t){for(var e=t.stack,n=t.loop,r=t.fv,c=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,c),r.setRelative(i,i,c),r.touch(i)}t.loop=1}function za(t){for(var e=t.stack,n=t.rp1,r=t.rp2,c=t.loop,a=t.z0[n],s=t.z1[r],i=t.fv,o=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),i.interpolate(u,a,s,o),i.touch(u)}t.loop=1}function R7(t,e){var n=e.stack,r=n.pop()/64,c=n.pop(),a=e.z1[c],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(a,s,r,o),i.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",r,c),e.rp1=e.rp0,e.rp2=c,t&&(e.rp0=c)}function Sa(t){for(var e=t.stack,n=t.rp0,r=t.z0[n],c=t.loop,a=t.fv,s=t.pv,i=t.z1;c--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"ALIGNRP[]",o),a.setRelative(l,r,0,s),a.touch(l)}t.loop=1}function La(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=Bc}function $7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z0[c],s=e.fv,i=e.pv,o=e.cvt[r];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",r,"(",o,")",c);var l=i.distance(a,O5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,O5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=c}function Aa(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 Ca(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 Pa(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 Ea(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 Ta(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 Ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function D7(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,O5,t,!1)*64)}function q7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z1[r],s=e.z0[c],i=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",r,c,"->",i),e.stack.push(Math.round(i*64))}function Va(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Ha(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Oa(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 Fa(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 Ra(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 $a(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 Da(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 qa(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 Na(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 Ua(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 Ba(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 _a(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function ja(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 Ga(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 Wa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function _e(t,e){var n=e.stack,r=n.pop(),c=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+"]",r,n);for(var h=0;h<r;h++){var u=n.pop(),f=n.pop(),d=i+((f&240)>>4);if(d===s){var m=(f&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",m*o);var g=l[u];c.setRelative(g,g,m*o,a)}}}function Xa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function Za(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function Ya(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 Ja(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 Ka(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 Qa(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 es(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function ts(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function ns(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function rs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function z4(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function cs(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 je(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 i=0;i<r;i++){var o=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",o,"by",f),e.cvt[o]+=f}}}function as(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=H8;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 ss(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=H8;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 is(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=Uc}function os(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=jc}function ls(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=Gc}function hs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}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(e.step,"SDPVTL["+t+"]",r,c);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=D5(i,o)}function us(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 fs(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 ds(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 ms(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 ps(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function gs(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 Y2(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 J2(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 f1(t,e,n,r,c,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,m=a.dpv,g,p,v,y;p=g=m.distance(u,h,!0,!0),v=p>=0?1:-1,p=Math.abs(p),t&&(y=a.cvt[i],r&&Math.abs(p-y)<a.cvCutIn&&(p=y)),n&&p<f&&(p=f),r&&(p=a.round(p)),d.setRelative(u,h,v*p,m),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?i+"("+a.cvt[i]+","+y+")":"",o,"(d =",g,"->",v*p,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}E8=[A7.bind(void 0,q2),A7.bind(void 0,E2),C7.bind(void 0,q2),C7.bind(void 0,E2),P7.bind(void 0,q2),P7.bind(void 0,E2),E7.bind(void 0,0),E7.bind(void 0,1),T7.bind(void 0,0),T7.bind(void 0,1),Xc,Zc,Yc,Jc,Kc,Qc,ea,ta,na,ra,ca,aa,sa,ia,oa,la,ha,ua,fa,da,void 0,void 0,ma,Be,pa,ga,va,xa,Ma,void 0,void 0,void 0,ya,ba,wa,void 0,I7.bind(void 0,0),I7.bind(void 0,1),V7.bind(void 0,q2),V7.bind(void 0,E2),H7.bind(void 0,0),H7.bind(void 0,1),O7.bind(void 0,0),O7.bind(void 0,1),F7.bind(void 0,0),F7.bind(void 0,1),ka,za,R7.bind(void 0,0),R7.bind(void 0,1),Sa,La,$7.bind(void 0,0),$7.bind(void 0,1),Aa,Ca,Pa,Ea,Ta,Ia,D7.bind(void 0,0),D7.bind(void 0,1),void 0,q7.bind(void 0,0),q7.bind(void 0,1),Va,void 0,Ha,void 0,void 0,Oa,Fa,Ra,$a,Da,qa,Na,Ua,Ba,_a,ja,Ga,Wa,_e.bind(void 0,1),Xa,Za,Ya,Ja,Ka,Qa,es,ts,ns,rs,z4.bind(void 0,0),z4.bind(void 0,1),z4.bind(void 0,2),z4.bind(void 0,3),void 0,void 0,void 0,void 0,cs,_e.bind(void 0,2),_e.bind(void 0,3),je.bind(void 0,1),je.bind(void 0,2),je.bind(void 0,3),as,ss,void 0,void 0,is,void 0,os,ls,Be,Be,void 0,void 0,void 0,void 0,void 0,hs,N7.bind(void 0,0),N7.bind(void 0,1),us,void 0,fs,ds,ms,ps,gs,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,Y2.bind(void 0,1),Y2.bind(void 0,2),Y2.bind(void 0,3),Y2.bind(void 0,4),Y2.bind(void 0,5),Y2.bind(void 0,6),Y2.bind(void 0,7),Y2.bind(void 0,8),J2.bind(void 0,1),J2.bind(void 0,2),J2.bind(void 0,3),J2.bind(void 0,4),J2.bind(void 0,5),J2.bind(void 0,6),J2.bind(void 0,7),J2.bind(void 0,8),f1.bind(void 0,0,0,0,0,0),f1.bind(void 0,0,0,0,0,1),f1.bind(void 0,0,0,0,0,2),f1.bind(void 0,0,0,0,0,3),f1.bind(void 0,0,0,0,1,0),f1.bind(void 0,0,0,0,1,1),f1.bind(void 0,0,0,0,1,2),f1.bind(void 0,0,0,0,1,3),f1.bind(void 0,0,0,1,0,0),f1.bind(void 0,0,0,1,0,1),f1.bind(void 0,0,0,1,0,2),f1.bind(void 0,0,0,1,0,3),f1.bind(void 0,0,0,1,1,0),f1.bind(void 0,0,0,1,1,1),f1.bind(void 0,0,0,1,1,2),f1.bind(void 0,0,0,1,1,3),f1.bind(void 0,0,1,0,0,0),f1.bind(void 0,0,1,0,0,1),f1.bind(void 0,0,1,0,0,2),f1.bind(void 0,0,1,0,0,3),f1.bind(void 0,0,1,0,1,0),f1.bind(void 0,0,1,0,1,1),f1.bind(void 0,0,1,0,1,2),f1.bind(void 0,0,1,0,1,3),f1.bind(void 0,0,1,1,0,0),f1.bind(void 0,0,1,1,0,1),f1.bind(void 0,0,1,1,0,2),f1.bind(void 0,0,1,1,0,3),f1.bind(void 0,0,1,1,1,0),f1.bind(void 0,0,1,1,1,1),f1.bind(void 0,0,1,1,1,2),f1.bind(void 0,0,1,1,1,3),f1.bind(void 0,1,0,0,0,0),f1.bind(void 0,1,0,0,0,1),f1.bind(void 0,1,0,0,0,2),f1.bind(void 0,1,0,0,0,3),f1.bind(void 0,1,0,0,1,0),f1.bind(void 0,1,0,0,1,1),f1.bind(void 0,1,0,0,1,2),f1.bind(void 0,1,0,0,1,3),f1.bind(void 0,1,0,1,0,0),f1.bind(void 0,1,0,1,0,1),f1.bind(void 0,1,0,1,0,2),f1.bind(void 0,1,0,1,0,3),f1.bind(void 0,1,0,1,1,0),f1.bind(void 0,1,0,1,1,1),f1.bind(void 0,1,0,1,1,2),f1.bind(void 0,1,0,1,1,3),f1.bind(void 0,1,1,0,0,0),f1.bind(void 0,1,1,0,0,1),f1.bind(void 0,1,1,0,0,2),f1.bind(void 0,1,1,0,0,3),f1.bind(void 0,1,1,0,1,0),f1.bind(void 0,1,1,0,1,1),f1.bind(void 0,1,1,0,1,2),f1.bind(void 0,1,1,0,1,3),f1.bind(void 0,1,1,1,0,0),f1.bind(void 0,1,1,1,0,1),f1.bind(void 0,1,1,1,0,2),f1.bind(void 0,1,1,1,0,3),f1.bind(void 0,1,1,1,1,0),f1.bind(void 0,1,1,1,1,1),f1.bind(void 0,1,1,1,1,2),f1.bind(void 0,1,1,1,1,3)];function j3(t){this.char=t,this.state={},this.activeState=null}function u6(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function vs(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function g2(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 H4(t){this.eventId=t,this.subscribers=[]}function ys(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 H4(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 y0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],ys.call(this,t)}j3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};j3.prototype.getState=function(t){return this.state[t]||null};y0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};y0.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)})])};y0.prototype.replaceRange=function(t,e,n,r){e=e!==null?e:this.tokens.length;var c=n.every(function(s){return s instanceof j3});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."}};y0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof j3){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."}};y0.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};y0.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."}};y0.prototype.insertToken=function(t,e,n){var r=t.every(function(c){return c instanceof j3});return r?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};y0.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,i=[r,c];if(s){var o=n.apply(this,i);r.setState(t,o)}}),this.registeredModifiers.push(t)};H4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};H4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};g2.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)};g2.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}};y0.prototype.rangeToText=function(t){if(t instanceof u6)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};y0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};y0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};y0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};y0.prototype.dispatch=function(t,e){var n=this,r=this.events[t];r instanceof H4&&r.subscribers.forEach(function(c){c.apply(n,e||[])})};y0.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 vs(t,e,n);return this.registeredContexts[t]=r,this.contextCheckers.push(r),r};y0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};y0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};y0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};y0.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 g2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};y0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,r=new u6(n,t,e),c=this.getContext(e).ranges;return r.rangeId=e+"."+c.length,c.push(r),this.getContext(e).openRange=null,r};y0.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 u6(n,null,c),e.getContext(c).openRange=a,e.dispatch("contextStart",[c,n])),a&&r.checkEnd(t)){var s=n-a.startIndex+1,i=e.setEndOffset(s,c);e.dispatch("contextEnd",[c,i])}})};y0.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 g2(e,n);this.dispatch("next",[c]),this.runContextCheck(c);var a=new j3(r);this.tokens.push(a),this.dispatch("newToken",[a,c])}return this.dispatch("end",[this.tokens]),this.tokens};function e3(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function F8(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 t3(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function L4(t){return/[A-z]/.test(t)}function bs(t){return/\s/.test(t)}function n2(t){this.font=t,this.features={}}function g3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function q5(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 xs(t,e){var n=q5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Ms(t,e){var n=q5(t,e.coverage);return n===-1?null:e.substitute[n]}function Ge(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=q5(a,c);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function ws(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=Ge(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&&t3(a[0].char);)a.shift();var s=new g2(a,0),i=Ge(e.lookaheadCoverage,s),o=[].concat(t.backtrack);for(o.reverse();o.length&&t3(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new g2(o,0),h=Ge(e.backtrackCoverage,l),u=r.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 m=e.lookupRecords[d],g=m.lookupListIndex,p=this.getLookupByIndex(g),v=0;v<p.subtables.length;v++){var y=p.subtables[v],b=this.getLookupMethod(p,y),x=this.getSubstitutionType(p,y);if(x==="12")for(var M=0;M<r.length;M++){var w=t.get(M),k=b(w);k&&f.push(k)}}return f}function ks(t,e){var n=t.current,r=q5(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 i=0;i<c.components.length;i++){var o=t.lookahead[i],l=c.components[i];if(o!==l)break;if(i===c.components.length-1)return c}}return null}function zs(t,e){var n=q5(t,e.coverage);return n===-1?null:e.sequences[n]}n2.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[]};n2.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 i=a[s];if(i.tag===t){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};n2.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};n2.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};n2.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),r=e.substFormat.toString();return n+r};n2.prototype.getLookupMethod=function(t,e){var n=this,r=this.getSubstitutionType(t,e);switch(r){case"11":return function(c){return xs.apply(n,[c,e])};case"12":return function(c){return Ms.apply(n,[c,e])};case"63":return function(c){return ws.apply(n,[c,e])};case"41":return function(c){return ks.apply(n,[c,e])};case"21":return function(c){return zs.apply(n,[c,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};n2.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 i=c[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 g3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new g3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new g3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new g3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new g3({id:21,tag:t.tag,substitution:d}));break}e=new g2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};n2.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};n2.prototype.getLookupSubtables=function(t){return t.subtables||null};n2.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};n2.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};n2.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 Ss(t){var e=t.current,n=t.get(-1);return n===null&&e3(e)||!e3(n)&&e3(e)}function Ls(t){var e=t.get(1);return e===null||!e3(e)}var As={startCheck:Ss,endCheck:Ls};function Cs(t){var e=t.current,n=t.get(-1);return(e3(e)||t3(e))&&!e3(n)}function Ps(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!e3(e)&&!t3(e)):var n=bs(e);if(!n)return!0;if(n){var r=!1;if(r=t.lookahead.some(function(c){return e3(c)||t3(c)}),!r)return!0}break;default:return!1}}var Es={startCheck:Cs,endCheck:Ps};function Ts(t,e,n){e[n].setState(t.tag,t.substitution)}function Is(t,e,n){e[n].setState(t.tag,t.substitution)}function Vs(t,e,n){t.substitution.forEach(function(r,c){var a=e[n+c];a.setState(t.tag,r)})}function Hs(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 U7={11:Ts,12:Is,63:Vs,41:Hs};function f6(t,e,n){t instanceof g3&&U7[t.id]&&U7[t.id](t,e,n)}function Os(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],c=F8(r),a=t3(r);if(!c&&!a)return!0;if(c)return!1}return!1}function Fs(t){if(F8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],r=t3(n);if(!r)return!0}return!1}function Rs(t){var e=this,n="arab",r=this.featuresTags[n],c=this.tokenizer.getRangeTokens(t);if(c.length!==1){var a=new g2(c.map(function(i){return i.getState("glyphIndex")}),0),s=new g2(c.map(function(i){return i.char}),0);c.forEach(function(i,o){if(!t3(i.char)){a.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;Os(s)&&(l|=1),Fs(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 g3&&(f6(f,c,d),a.context[d]=f.substitution)})}}})}}function B7(t,e){var n=t.map(function(r){return r.activeState.value});return new g2(n,e||0)}function $s(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),c=B7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:n,contextParams:c});i.length&&(i.forEach(function(o){return f6(o,r,s)}),c=B7(r))})}function Ds(t){var e=t.current,n=t.get(-1);return n===null&&L4(e)||!L4(n)&&L4(e)}function qs(t){var e=t.get(1);return e===null||!L4(e)}var Ns={startCheck:Ds,endCheck:qs};function _7(t,e){var n=t.map(function(r){return r.activeState.value});return new g2(n,e||0)}function Us(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),c=_7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:n,contextParams:c});i.length&&(i.forEach(function(o){return f6(o,r,s)}),c=_7(r))})}function b2(t){this.baseDir=t||"ltr",this.tokenizer=new y0,this.featuresTags={}}b2.prototype.setText=function(t){this.text=t};b2.prototype.contextChecks={latinWordCheck:Ns,arabicWordCheck:As,arabicSentenceCheck:Es};function We(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function Bs(){return We.call(this,"latinWord"),We.call(this,"arabicWord"),We.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function _s(){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())})}b2.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};b2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new n2(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)}};b2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function d6(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function js(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){d6.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){Rs.call(t,r)})}}function Gs(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){d6.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(c){$s.call(t,c)})}}}function Ws(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){d6.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(c){Us.call(t,c)})}}}b2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};b2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(js.call(this),Gs.call(this)),this.checkContextReady("latinWord")&&Ws.call(this),this.checkContextReady("arabicSentence")&&_s.call(this)};b2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),Bs.call(this),this.applyFeaturesToContexts())};b2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};b2.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 r0(t){t=t||{},t.tables=t.tables||{},t.empty||(E5(t.familyName,"When creating a new Font object, familyName is required."),E5(t.styleName,"When creating a new Font object, styleName is required."),E5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),E5(t.ascender,"When creating a new Font object, ascender is required."),E5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new T2.GlyphSet(this,t.glyphs||[]),this.encoding=new t8(this),this.position=new R5(this),this.substitution=new t2(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 I8(this)}})}r0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};r0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};r0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};r0.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})};r0.prototype.stringToGlyphs=function(t,e){var n=this,r=new b2,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),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};r0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};r0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};r0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};r0.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};r0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};r0.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,i=this.stringToGlyphs(t,c),o;if(c.kerning){var l=c.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,c.language)}for(var h=0;h<i.length;h+=1){var u=i[h];if(a.call(this,u,e,n,r,c),u.advanceWidth&&(e+=u.advanceWidth*s),c.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}c.letterSpacing?e+=c.letterSpacing*r:c.tracking&&(e+=c.tracking/1e3*r)}return e};r0.prototype.getPath=function(t,e,n,r,c){var a=new P0;return this.forEachGlyph(t,e,n,r,c,function(s,i,o,l){var h=s.getPath(i,o,l,c,this);a.extend(h)}),a};r0.prototype.getPaths=function(t,e,n,r,c){var a=[];return this.forEachGlyph(t,e,n,r,c,function(s,i,o,l){var h=s.getPath(i,o,l,c,this);a.push(h)}),a};r0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};r0.prototype.draw=function(t,e,n,r,c,a){this.getPath(e,n,r,c,a).draw(t)};r0.prototype.drawPoints=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,i,o,l){s.drawPoints(t,i,o,l)})};r0.prototype.drawMetrics=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,i,o,l){s.drawMetrics(t,i,o,l)})};r0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};r0.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};r0.prototype.toTables=function(){return Hc.fontToTable(this)};r0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};r0.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};r0.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(Fc())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 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=Rc(r);o.writeFileSync(t,l)}};r0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};r0.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};r0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function R8(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 Xs(t,e,n){var r=R8(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 Zs(t,e,n){var r={},c=new p1.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 Ys(t,e,n,r){for(var c=R8(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 i=n[s].tag;a.push({name:"axis_"+t+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return a}function Js(t,e,n,r){var c={},a=new p1.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 Ks(t,e){var n=new s1.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(Xs(r,t.axes[r],e));for(var c=0;c<t.instances.length;c++)n.fields=n.fields.concat(Ys(c,t.instances[c],t.axes,e));return n}function Qs(t,e,n){var r=new p1.Parser(t,e),c=r.parseULong();C1.argument(c===65536,"Unsupported fvar table version.");var a=r.parseOffset16();r.skip("uShort",1);for(var s=r.parseUShort(),i=r.parseUShort(),o=r.parseUShort(),l=r.parseUShort(),h=[],u=0;u<s;u++)h.push(Zs(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,m=0;m<o;m++)f.push(Js(t,d+m*l,h,n));return{axes:h,instances:f}}var ei={make:Ks,parse:Qs},ti=function(){return{coverage:this.parsePointer($.coverage),attachPoints:this.parseList($.pointer($.uShortList))}},ni=function(){var t=this.parseUShort();if(C1.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()}},ri=function(){return this.parseList($.pointer(ni))},ci=function(){return{coverage:this.parsePointer($.coverage),ligGlyphs:this.parseList($.pointer(ri))}},ai=function(){return this.parseUShort(),this.parseList($.pointer($.coverage))};function si(t,e){e=e||0;var n=new $(t,e),r=n.parseVersion(1);C1.argument(r===1||r===1.2||r===1.3,"Unsupported GDEF table version.");var c={version:r,classDef:n.parsePointer($.classDef),attachList:n.parsePointer(ti),ligCaretList:n.parsePointer(ci),markAttachClassDef:n.parsePointer($.classDef)};return r>=1.2&&(c.markGlyphSets=n.parsePointer(ai)),c}var ii={parse:si},v2=new Array(10);v2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer($.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer($.coverage),values:this.parseValueRecordList()};C1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};v2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();C1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer($.coverage),c=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,pairSets:this.parseList($.pointer($.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer($.classDef),i=this.parsePointer($.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,$.list(l,function(){return{value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}}))}}};v2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};v2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};v2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};v2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};v2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};v2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};v2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function oi(t,e){e=e||0;var n=new $(t,e),r=n.parseVersion(1);return C1.argument(r===1||r===1.1,"Unsupported GPOS table version "+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(v2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(v2),variations:n.parseFeatureVariationsList()}}var li=new Array(10);function hi(t){return new s1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new s1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new s1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new s1.LookupList(t.lookups,li)}])}var ui={parse:oi,make:hi};function fi(t){var e={};t.skip("uShort");var n=t.parseUShort();C1.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(),i=t.parseShort();e[a+","+s]=i}return e}function di(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 i=t.parseUShort(),o=t.parseUShort(),l=t.parseShort();e[i+","+o]=l}}return e}function mi(t,e){var n=new p1.Parser(t,e),r=n.parseUShort();if(r===0)return fi(n);if(r===1)return di(n);throw new Error("Unsupported kern table version ("+r+").")}var pi={parse:mi};function gi(t,e,n,r){for(var c=new p1.Parser(t,e),a=r?c.parseUShort:c.parseULong,s=[],i=0;i<n+1;i+=1){var o=a.call(c);r&&(o*=2),s.push(o)}return s}var vi={parse:gi};function j7(t,e){for(var n=[],r=12,c=0;c<e;c+=1){var a=p1.getTag(t,r),s=p1.getULong(t,r+4),i=p1.getULong(t,r+8),o=p1.getULong(t,r+12);n.push({tag:a,checksum:s,offset:i,length:o,compression:!1}),r+=16}return n}function yi(t,e){for(var n=[],r=44,c=0;c<e;c+=1){var a=p1.getTag(t,r),s=p1.getULong(t,r+4),i=p1.getULong(t,r+8),o=p1.getULong(t,r+12),l=void 0;i<o?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:i,length:o}),r+=20}return n}function M0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),r=new Uint8Array(e.length);if(ur(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 $8(t,e){e=e??{};var n,r,c=new r0({empty:!0}),a=new DataView(t,0),s,i=[],o=p1.getTag(a,0);if(o==="\0\0\0"||o==="true"||o==="typ1")c.outlinesFormat="truetype",s=p1.getUShort(a,4),i=j7(a,s);else if(o==="OTTO")c.outlinesFormat="cff",s=p1.getUShort(a,4),i=j7(a,s);else if(o==="wOFF"){var l=p1.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 "+o);s=p1.getUShort(a,12),i=yi(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,m,g,p,v,y,b,x,M,w=0;w<s;w+=1){var k=i[w],z=void 0;switch(k.tag){case"cmap":z=M0(a,k),c.tables.cmap=e8.parse(z.data,z.offset),c.encoding=new n8(c.tables.cmap);break;case"cvt ":z=M0(a,k),M=new p1.Parser(z.data,z.offset),c.tables.cvt=M.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=M0(a,k),M=new p1.Parser(z.data,z.offset),c.tables.fpgm=M.parseByteList(k.length);break;case"head":z=M0(a,k),c.tables.head=f8.parse(z.data,z.offset),c.unitsPerEm=c.tables.head.unitsPerEm,n=c.tables.head.indexToLocFormat;break;case"hhea":z=M0(a,k),c.tables.hhea=d8.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":p=k;break;case"ltag":z=M0(a,k),r=p8.parse(z.data,z.offset);break;case"maxp":z=M0(a,k),c.tables.maxp=g8.parse(z.data,z.offset),c.numGlyphs=c.tables.maxp.numGlyphs;break;case"name":b=k;break;case"OS/2":z=M0(a,k),c.tables.os2=t6.parse(z.data,z.offset);break;case"post":z=M0(a,k),c.tables.post=w8.parse(z.data,z.offset),c.glyphNames=new i6(c.tables.post);break;case"prep":z=M0(a,k),M=new p1.Parser(z.data,z.offset),c.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":m=k;break;case"GSUB":g=k;break;case"meta":x=k;break}}var S=M0(a,b);if(c.tables.name=M8.parse(S.data,S.offset,r),c.names=c.tables.name,f&&y){var A=n===0,L=M0(a,y),C=vi.parse(L.data,L.offset,c.numGlyphs,A),P=M0(a,f);c.glyphs=P8.parse(P.data,P.offset,C,c,e)}else if(h){var R=M0(a,h);u8.parse(R.data,R.offset,c,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var q=M0(a,p);if(m8.parse(c,q.data,q.offset,c.numberOfHMetrics,c.numGlyphs,c.glyphs,e),Ir(c,e),v){var T=M0(a,v);c.kerningPairs=pi.parse(T.data,T.offset)}else c.kerningPairs={};if(d){var B=M0(a,d);c.tables.gdef=ii.parse(B.data,B.offset)}if(m){var X=M0(a,m);c.tables.gpos=ui.parse(X.data,X.offset),c.position.init()}if(g){var Z=M0(a,g);c.tables.gsub=k8.parse(Z.data,Z.offset)}if(u){var h1=M0(a,u);c.tables.fvar=ei.parse(h1.data,h1.offset,c.names)}if(x){var H=M0(a,x);c.tables.meta=z8.parse(H.data,H.offset),c.metas=c.tables.meta}return c}var O4=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=e2(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=$8(a);return this.parsed.set(n,s),s}};function bi(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((i,o)=>{c.push(...t.getPath(i,a,0,n.size,r).commands),a+=t.getAdvanceWidth(i,n.size,r)*(o<s.length-1?n.spacing:1)}),{cmds:c,advance:a}}function D8(t,e,n){let{cmds:r,advance:c}=bi(t,e,n),a=r.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=$3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:c}}function F4(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:c,advance:a}=D8(r,e,n),s=i1(c),i=z0(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 m6(t,e,n){let r=t.get(n.font),{polys:c,advance:a}=D8(r,e,n),s=z0(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}}var q8=Math.PI/180,p6=128,R4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],U8={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function xi(t,e){if(!t||e2(y6,t)!==void 0||e.startsWith("/"))return;let n=t.lastIndexOf("/");if(n<0)return;let r=[...t.slice(0,n).split("/"),...e.split("/")],c=[];for(let a of r)a===".."&&c.length&&c[c.length-1]!==".."?c.pop():a!=="."&&a!==""&&c.push(a);return(t.startsWith("/")?"/":"")+c.join("/")}var Mi=100,wi={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},G3=4,N8=8,ki=t=>{let e=Mi,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},I0=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}},g6=t=>t?`.${t}`:"",v6=["echo","assert","text_width","text_metrics","finger_count"];function y3(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:zi(t,c);a<r&&([n,r]=[c,a])}return n?` Did you mean "${n}"?`:""}function zi(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 y6=P5,W3=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.frame=Le;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(R4.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={...U8,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new I0,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[i,o]of Object.entries(r))n.vars.set(i,o);let c=new I0(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 (${d2(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?`,e)}load(e,n){let r=xi(n.file,e),c=e,a=e2(y6,e);if(a===void 0&&r!==void 0){let i=this.loaded.get(r);if(i)return i;a=this.opts.resolve?.(r),typeof a=="string"&&(c=r)}if(c===e){let i=this.loaded.get(e);if(i)return i;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}=m2(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||e2(y6,r.pos.file)===void 0)&&(r.kind==="module"?e2(this.builtins,r.name)!==void 0:e2(k5,r.name)!==void 0||v6.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${d2(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 I0(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,i]of a.mods)this.clash("module",s,n.mods.get(s),i),n.mods.set(s,i);for(let[s,i]of a.fns)this.clash("function",s,n.fns.get(s),i),n.fns.set(s,i)}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,i=[];for(let l=c.length-1;l>=0;l--)i.push({text:";"},c[l][1],{text:`${c[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(i2(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(_0(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,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&&!ft(s)&&c.push(s)}return c.length===1?c[0]:A2(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 I0(n));case"if":return g0(this.expr(e.cond,n))?this.block(e.then,new I0(n)):this.block(e.else,new I0(n));case"let":{let c=new I0(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:()=>A2(c),childList:()=>c,childSeq:()=>c,childItems:()=>c}):A2(c)}case"call":if(e.modifier==="*")return null;{let c=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?g5(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(i2(e))try{return g4(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 I0(n)){if(c===e.length)return r(a);let s=e[c];for(let i of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let o=new I0(a);o.vars.set(s.name,i),this.loop(e,n,r,c+1,o)}}evalArgs(e,n,r){let c=[],a=new Map,s=[];for(let i of e){let o=this.expr(i.value,n);i.name===null?c.push(o):a.set(i.name,o),s.push({name:i.name,value:o})}return{pos:c,named:a,all:s,at:r}}bindParams(e,n,r,c,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,r):void 0,r.vars.set(i.name,l)});for(let i of n.named.keys())i.startsWith("$")?r.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 r=C5(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 (${d2(r.at,!1)})`)}unknownArg(e,n,r,c){this.warn(`${e}: unknown argument "${n}"${g6(y3(n,c))} (${d2(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 ${R0(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,i)=>i!==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(`Recursion too deep in module ${e.name}(): it calls itself without stopping`,e.pos);try{let f=new I0(c.env,n);return this.bindParams(c.params,r,f,c.env,`${e.name}()`),f.children={stmts:e.children,env:n,module:e.name,pos:e.pos},f.vars.set("$children",this.childStmts(e.children).length),this.block(c.body,f)}catch(f){throw this.inCall(f,"module",e.name,e.pos)}finally{this.depth--}}let a=e2(this.builtins,e.name);if(!a){let f=e.name==="color"?" Use layer(), cut(), score() or engrave() instead.":y3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new l1(`Unknown module ${e.name}().${f}`,e.pos)}this.checkArgs(e.name,r);let s=new I0(n,n);for(let[f,d]of r.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new I0(n,s),l={args:r,env:s,children:()=>e.children.length?this.block(e.children,o()):O0(),childList:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let m of e.children){let g=this.stmt(m,f);i.includes(m)&&d.push(g??O0())}return d},childItems:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let m of e.children){if(i.includes(m)&&m.kind==="for"&&!m.intersect){this.tick(m.pos),this.loop(m.assigns,f,p=>d.push(this.block(m.body,p)));continue}let g=this.stmt(m,f);i.includes(m)&&d.push(g??O0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let m=[];for(let g of e.children){let p=this.stmt(g,d);i.includes(g)&&(m.push(p??O0()),f(m.length-1,p??O0()))}return m}},h;try{h=a(l)}catch(f){if(f instanceof l1||f instanceof RangeError)throw f;let d=new l1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=ki(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new l1(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,r,c){if(++this.depth>2e3)throw new l1(`Recursion too deep in ${c}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=f2(e)?e.scope:e.env,s=new I0(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(`Recursion too deep in ${n==="module"?"module ":""}${r}(): it calls itself without stopping`,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}"${g6(y3(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(G3,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==="!"?!g0(r):e.op==="+"?r:this.arith("*",-1,r,e.pos)}case"binary":{if(e.op==="&&")return g0(this.expr(e.left,n))&&g0(this.expr(e.right,n));if(e.op==="||")return g0(this.expr(e.left,n))||g0(this.expr(e.right,n));let r=this.expr(e.left,n),c=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return F3(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 ${R0(r)} ${e.op} ${R0(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 g0(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(_0(r)&&typeof c=="string")return r.fields.get(c);if(typeof c!="number")throw new l1(`List index must be a number, got ${R0(c)}`,e.pos);return Array.isArray(r)?r[Math.floor(c)]:typeof r=="string"?[...r][Math.floor(c)]:i2(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(_0(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]:i2(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 I0(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":g0(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 I0(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&&!f2(a.value);if(!a.found||s&&this.callable(c,n)){let i=n.fn(c);if(i)return this.callFunction(i,this.evalArgs(e.args,n,e.pos),n,c);let o=this.specialFunction(c,e,n);if(o.handled)return o.value;let l=e2(k5,c);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(c,h);for(let m of Yt(l,h.pos,h.named))this.warn(`${c}(): "${m}" is given by position and by name; the named value is used (${d2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:m=>this.tick(e.pos,m),given:h.pos.length+l.params.filter(m=>h.named.has(m)).length,apply:(m,g)=>{if(!f2(m))throw new Error(`${c}() needs a function, got ${R0(m)}`);return this.callFunction(m,{pos:g,named:new Map,all:g.map(p=>({name:null,value:p})),at:e.pos},n,"function")}},f=Jt(l,h.pos,h.named);this.tick(e.pos,Kt(c,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof l1)throw m;let g=new l1(m instanceof RangeError?`${c}(): the result is too large`:m.message,e.pos);throw g.call=c,g}return this.checkValue(d,e.pos,c),d}throw new l1(`Unknown function ${c}()${g6(y3(c,[...n.names("fns"),...n.names("vars"),...Object.keys(k5),...v6]))}`,e.pos)}if(!f2(a.value))throw new l1(`"${c}" is a ${R0(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(!f2(r))throw new l1(`Can't call a ${R0(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 i=a(s),o=i1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||k0(n[s],o).reduce((h,u)=>h+Math.abs(M1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(r)&&i?` "${i}"`:""} under it, so it can't be seen (${d2(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=q0(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*wi[e.unit]/r}callable(e,n){return!!n.fn(e)||v6.includes(e)||!!e2(k5,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"){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}:{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:f3(a,this.fingerWidth(c,r,1))}}return{handled:!1}}assert(e){if(g0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new l1(`Assertion failed${n===void 0?"":": "+v0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/N8);this.charge(r,n),this.retained+=r,this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,r=[],c=0,a=(s,i,o)=>{r.length&&(c+=2);let l=R3(i,n-c-s.length,o);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:i}of e.all)s===null?a("",i,!1):a(`${s} = `,i,!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+G3,c),n.map((s,i)=>this.arith(e,s,r[i],c))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+G3,c),n.map(i=>this.arith("*",i,r,c));let s=(i,o)=>{let l=this.arith("*",i,o,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 i=r[0].length;if(n.length!==r.length||r.some(o=>!Array.isArray(o)||o.length!==i))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(i,!1,c),this.tick(c,i*n.length),Array.from({length:i},(o,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((i,o,l)=>i+s(o,r[l]),0)}}if(Array.isArray(n)&&typeof r=="number"&&(e==="*"||e==="/"))return this.charge(n.length+G3,c),n.map(s=>this.arith(e,s,r,c));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+G3,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} ${R0(n)} and ${R0(r)}`,c)}fieldFn(e,n,r,c){if(!f2(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${C0(e)}`);return a=>{let s=this.itemCount,i=this.retained,o=this.callFunction(e,{pos:[a],named:new Map,all:[{name:null,value:a}],at:c},r,"field");return(!Array.isArray(o)||o.length<=3)&&(this.itemCount=s+this.retained-i),o}}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=(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=c(e,"at"),s=c(n,"rotate");for(let[i,o]of[[a,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==r)throw new Error(`${o} needs one placement per copy: qty is ${r} but ${o} has ${i.length}`);return Array.from({length:r},(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((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/N8):e+G3,r)}segs(e){let n=q0(this.dyn(e,"$fn"))||0,r=q0(this.dyn(e,"$fa"))||2,c=q0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let i=pt(s,n,r,c);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,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=R3(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{return m6(this.opts.fonts,r.text,this.textOpts(e,n,r.text))}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:v0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:v0(this.arg(e,"halign",-1,"left")),valign:v0(this.arg(e,"valign",-1,"baseline")),spacing:q0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&r!==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=m6(this.opts.fonts,r,{...c,size:1}).advance;if(i>0){let o=this.arg(e,"size",1);c.size=o===void 0?s/i:Math.min(c.size,s/i)}}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"})}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(o=>typeof o=="number"&&Number.isFinite(o)))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,i]=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:i}})}makeBuiltins(){let e=(s,i)=>u3(s.children(),i),n=s=>i=>g5(i.children(),s),r=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 ${C0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!g0(this.dyn(i.env,"$mirrored"))),g5(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=q0(this.arg(s.args,"r",-1,0))||0,h=g0(this.arg(s.args,"center",1,!1)),u=gt(i,o,l,this.segs(s.env));return A0(i1([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 A0([I3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return A0([I3(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 A0([I3(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 A0(i1([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[q0(u)]).filter(Boolean)):[i];return A0(i1(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=$3(D3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return g0(this.arg(s.args,"close",-1,!1))?A0(i1([...o.closed,...o.open.filter(h=>h.length>2)],l)):A2([A0(i1(o.closed,l)),L2(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 L2([[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 O0();let f=-(o[1]-i[1])/u*(h/2),d=(o[0]-i[0])/u*(h/2);return A0(i1([[[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=g0(this.arg(s.args,"closed",1,!1));return L2([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 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 i=this.arg(s.args,"text",0,""),o=R3(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=this.textOpts(s.args,s.env,o.text),h=F4(this.opts.fonts,o.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=n0(i1(h),d,"round"))}if(f!==void 0&&(h=we(h,this.num(f,"text","bridge"))),g0(this.dyn(s.env,"$mirrored"))){let[d,m]=[1/0,-1/0];for(let g of h)for(let[p]of g)[d,m]=[Math.min(d,p),Math.max(m,p)];return A0(i1(h.map(g=>g.map(([p,v])=>[d+m-p,v]))))}return A0(h)},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)?q0(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[m,g]=this.vec2(f,"center",!1);d=[h,u,-u,h,m-h*m+u*g,g-u*m-h*g]}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 O0();let l=c(o,"difference");return a(i,h=>({regions:k0(h.regions,l.regions),lines:W0(h.lines,i1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return O0();let o=m=>[...m.layers.values()].some(g=>g.regions.length),l=m=>{let g;for(let p of i){if(p===m||!o(p))continue;let v=i1(c([p],"intersection").regions);g=g?a0(g,v):v}return g},h=i[0],u=i.every(o),f=l(h),d=a(h,m=>({regions:u?f?a0(m.regions,f):m.regions:[],lines:f?W0(m.lines,f,"inside"):m.lines}));for(let m of i){if(m===h)continue;if(m.parts.length)throw new Error("part() can only be the first child of intersection()");let g=l(m),p=new Map;for(let[v,y]of m.layers)y.lines.length&&p.set(v,{regions:[],lines:g?W0(y.lines,g,"inside"):y.lines});p.size&&(d=A2([d,{layers:p,parts:[]}]))}return d},hull:s=>{let i=s.children(),o=l=>{let h=[],u="cut",f=!0;for(let[m,g]of l){f&&(g.regions.length||g.lines.length)&&(u=m,f=!1);for(let p of[...g.regions,...g.lines])for(let v of p)h.push(v)}let d=s4(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=g0(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:n0(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=i1(c(u,"pattern").regions),d=X0(h.layers),m=z0(f);if(!d||!m)return O0();let g=Math.floor((m[1]-d[3])/o),p=Math.ceil((m[3]-d[1])/o),v=Math.floor((m[0]-d[2])/i)-1,y=Math.ceil((m[2]-d[0])/i)+1,b=(p-g+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=F0(f).map(S=>({polys:S,box:z0(S)})),M=f,w=(S,A)=>{let L=0;for(let C of M)for(let P=0,R=C.length-1;P<C.length;R=P++){let[q,T]=C[R],[B,X]=C[P];T<=A?X>A&&(B-q)*(A-T)-(S-q)*(X-T)>0&&L++:X<=A&&(B-q)*(A-T)-(S-q)*(X-T)<0&&L--}return L!==0},k=new Map,z=(S,A)=>{let L=k.get(S)??{regions:[],lines:[]};for(let C of A.regions)L.regions.push(C);for(let C of A.lines)L.lines.push(C);k.set(S,L)};for(let S=g;S<=p;S++)for(let A=v;A<=y;A++){let L=A*i+(S%2?l*i:0),C=S*o,P=[d[0]+L,d[1]+C,d[2]+L,d[3]+C];if(P[2]<m[0]||P[0]>m[2]||P[3]<m[1]||P[1]>m[3])continue;let R=x.filter(Z=>!(P[2]<Z.box[0]||P[0]>Z.box[2]||P[3]<Z.box[1]||P[1]>Z.box[3]));if(!R.length)continue;M=R.length===x.length?f:R.flatMap(Z=>Z.polys);let q=[w(P[0],P[1]),w(P[2],P[1]),w(P[2],P[3]),w(P[0],P[3])],T=M.some(Z=>Z.some(([h1,H])=>h1>P[0]&&h1<P[2]&&H>P[1]&&H<P[3])),B=q.every(Boolean)&&!T,X=[1,0,0,1,L,C];for(let[Z,h1]of u3({layers:h.layers,parts:[]},X).layers)z(Z,B?h1:{regions:a0(h1.regions,M),lines:W0(h1.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=g0(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=He(i,l,h);if(o===void 0)return L2([u]);let f=this.num(o,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return A0(i1(a4([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=i1(c([s.children()],"hatch").regions),u=z0(h);if(!u)return O0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],m=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,g=i*Math.PI/180,[p,v]=[Math.cos(g),Math.sin(g)],[y,b]=[-v,p],x=Math.ceil(m/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),[A,L]=[f+y*S,d+b*S];M.push([[A-p*m,L-v*m],[A+p*m,L+v*m]])}if(l===void 0)return L2(W0(M,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return A0(a0(i1(a4(M,k).map(z=>z)),h))},flow:s=>{let i=this.arg(s.args,"field",0),o=this.num(this.arg(s.args,"spacing",1,2),"flow","spacing");if(!(o>0))throw new Error("spacing must be more than 0");let l=this.num(this.arg(s.args,"step",2,Math.min(.5,o/4)),"flow","step");if(!(l>0&&l<=o))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*o),"flow","min_length"),u=this.num(this.arg(s.args,"seed",-1,1),"flow","seed"),f=i1(c([s.children()],"flow").regions),d=z0(f);if(!d)return O0();let m=y=>[Math.cos(y*q8),Math.sin(y*q8)],g;if(typeof i=="number"){let y=m(i);g=()=>y}else{let y=this.fieldFn(i,"flow",s.env,s.args.at);g=b=>{let x=y(b);if(x===void 0)return null;if(typeof x=="number"&&Number.isFinite(x))return m(x);if(Array.isArray(x)&&typeof x[0]=="number"&&typeof x[1]=="number"&&Number.isFinite(x[0])&&Number.isFinite(x[1])){let M=Math.hypot(x[0],x[1]);return M>1e-12?[x[0]/M,x[1]/M]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${C0(x)}`)}}if(!((d[2]-d[0])/o*((d[3]-d[1])/o)<=this.limits.maxPoints/10))throw new Error("spacing is too small for the area");let v=vt({spacing:o,step:l,minLength:h,seed:u,box:d,inside:xt(f),dir:g,tick:()=>this.tick(s.args.at),maxPoints:this.limits.maxPoints});return L2(W0(v,f,"inside"))},contours:s=>{let i=this.arg(s.args,"field",0),o=this.fieldFn(i,"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=i1(c([s.children()],"contours").regions),d=z0(f);if(!d)return O0();let m=Math.ceil((d[2]-d[0])/u)+1,g=Math.ceil((d[3]-d[1])/u)+1;if(!(m*g<=this.limits.maxPoints/2))throw new Error(`a cell of ${u} samples the area at ${m*g} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let p=new Float64Array(m*g),v=1/0,y=-1/0;for(let w=0;w<g;w++)for(let k=0;k<m;k++){let z=o([d[0]+k*u,d[1]+w*u]);if(z===void 0){p[w*m+k]=NaN;continue}if(typeof z!="number"||!Number.isFinite(z))throw new Error(`field() must give a number or undef, got ${C0(z)}`);p[w*m+k]=z,v=Math.min(v,z),y=Math.max(y,z)}if(!(v<=y))return O0();let b;if(h!==void 0){let w=this.num(h,"contours","interval");if(!(w>0))throw new Error("interval must be more than 0");let k=Math.ceil(v/w),z=Math.floor(y/w);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(z))throw new Error(`the heights are too large for an interval of ${w}`);let S=Math.max(0,z-k+1);if(!(S<=1e4))throw new Error(`interval ${w} gives ${S} levels: use a larger interval`);b=Array.from({length:S},(A,L)=>(k+L)*w)}else if(Array.isArray(l))b=l.map(w=>this.num(w,"contours","levels"));else{let w=Math.floor(this.num(l,"contours","levels"));if(!(w>=1&&w<=1e4))throw new Error("levels must be 1 to 10000");b=Array.from({length:w},(k,z)=>v+(y-v)*(z+1)/(w+1))}let x=[],M=0;for(let w of b){this.tick(s.args.at,Math.ceil(m*g/100));let k=yt(p,m,g,d[0],d[1],u,w),z=k.reduce((S,A)=>S+A.length,0);if(!((M+=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 S of k)x.push(S)}return L2(W0(x,f,"inside"))},occlude:s=>{let i;this.occluding++;try{i=s.childItems()}finally{this.occluding--}let o=u=>this.layers.get(u)?.mode??"cut",l=[],h=[];for(let u=i.length-1;u>=0;u--){let f=i[u];if(f.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[g,p]of f.layers){if(g===s2)continue;let v=o(g);!h.length||v==="cut"||v==="guide"?d.set(g,p):v==="line"?d.set(g,{regions:[],lines:W0([...p.lines,...i1(p.regions).map(y=>[...y,y[0]])],h,"outside")}):d.set(g,{regions:k0(p.regions,h),lines:W0(p.lines,h,"outside")})}l.push({layers:d,parts:[]});let m=[...f.layers].filter(([g])=>o(g)!=="guide").flatMap(([,g])=>g.regions);m.length&&(h=i1([...h,...m]))}return A2(l.reverse())},hide:s=>this.occluding?A0(i1(c([s.children()],"hide").regions),s2):(this.warn(`hide() only works inside occlude(); it draws nothing (${d2(s.args.at,!1)})`),O0()),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 m=h,g=i1(c([d],"paint").regions);u[f]=g,h=m.length?i1([...m,...g]):g;let p=Array.isArray(i)?i[f]:void 0;if(p!=="")if(p!==void 0){this.layers.has(p)||this.layers.set(p,{name:p,mode:"fill",color:"#000000"}),l.push(A0(m.length?k0(g,m):g,p));let v=d.layers.get(s2);v&&l.push({layers:new Map([[s2,v]]),parts:[]})}else l.push(m.length?a(d,v=>({regions:k0(v.regions,m),lines:W0(v.lines,m,"outside")})):d)}return this.invisiblePaint(o,u,i,s.args.at),A2(l.reverse())},measure:s=>{let i=g0(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let u=X0(h.layers)??z0(h.parts.flatMap(p=>[...p.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(p=>p.layers)],d=f.flatMap(p=>p.get("cut")?.regions??[]),m=d.length?d:f.flatMap(p=>[...p].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),g=mt(i1(m));s.env.vars.set("$area",g.area),s.env.vars.set("$centroid",g.area>0?g.centroid:void 0)});return A2(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:i1(l.regions).filter(h=>!(M1(h)<0&&-M1(h)<o)),lines:l.lines}))},join_islands:s=>{let i=this.num(this.arg(s.args,"width",0,1),"join_islands","width");if(!(i>0))throw new Error("join_islands(): width must be more than 0");let o=s.children(),l=h=>new Map([...h].map(([u,f])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:we(f.regions,i),lines:f.lines}:f]));return{layers:l(o.layers),parts:o.parts.map(h=>({...h,layers:l(h.layers)}))}},largest:s=>{let i=Math.floor(this.num(this.arg(s.args,"n",0,1),"largest","n"));if(!(i>=1))throw new Error("largest(): n must be 1 or more");let o=u=>F0(u).map(f=>({g:f,a:f.reduce((d,m)=>d+M1(m),0)})).sort((f,d)=>d.a-f.a).slice(0,i).flatMap(({g:f})=>f),l=s.children(),h=u=>new Map([...u].map(([f,d])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:o(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(u=>({...u,layers:h(u.layers)}))}},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),o=>({regions:n0(n0(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:i1([...o.regions,...a4(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...i1(i.regions).map(o=>[...o,o[0]])]})),cut:n("cut"),score:r("score"),engrave:r("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 m=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(m))throw new Error('mode must be "cut", "line", "fill" or "guide"');let g=v0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(g))throw new Error('color must look like "#00aa00"');let p=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&&m==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:m,color:g,...p!==void 0&&{order:p},...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(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",!g0(this.dyn(s.env,"$mirrored"))),g5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=v0(this.arg(s.args,"name",0,"part")),o=this.arg(s.args,"qty",1,1),l=typeof o=="number"?Math.floor(o):1;if(!(l>=0))throw new Error(`qty must be 0 or more, got ${C0(o)}`);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),m=this.arg(s.args,"glue",-1),g=m===void 0?void 0:v0(m),p=v0(this.arg(s.args,"face",-1,"top"));if(p!=="top"&&p!=="bottom")throw new Error(`face must be "top" or "bottom", got ${C0(p)}`);let v=this.frame!==Le&&g===void 0,y=this.arg(s.args,"bend",-1),b=f===void 0&&d===void 0&&!v&&g===void 0&&y===void 0?void 0:this.placements(f,d,l),x=this.arg(s.args,"material",-1);x!==void 0&&s.env.vars.set("$material",v0(x));let M=this.thickness(s.env);b&&(v||u>1)&&(b=b.flatMap(g1=>{let X1=g===void 0?q1(this.frame,Q0(g1)):Q0(g1),D1=g!==void 0&&p==="bottom"?-M:M;return Array.from({length:u},(E,D)=>({...g1,matrix:q1(X1,B0(0,0,D*D1))}))}));let w=this.arg(s.args,"mirror",-1,!1),k;if(Array.isArray(w)){if(w.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${w.length}`);k=w.map(g1=>g0(g1))}else k=Array.from({length:l},()=>g0(w));let z=k.some(g1=>g1)&&!k.every(g1=>g1);if(z&&g!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let S=k[0],A=g1=>{let X1=s.env.vars.get("$mirrored"),D1=s.env.vars.has("$mirrored");g1&&s.env.vars.set("$mirrored",!0);try{let E=s.children();return g1?u3(E,[-1,0,0,1,0,0]):E}finally{g1&&(D1?s.env.vars.set("$mirrored",X1):s.env.vars.delete("$mirrored"))}},L=A(S),C=this.bends(y),P=this.arg(s.args,"on",-1),R=this.arg(s.args,"slots",-1),q=R===void 0?void 0:(Array.isArray(R)?R:[R]).map(g1=>{if(typeof g1!="string")throw new Error("slots must be part names");return g1}),T=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),B=this.arg(s.args,"slot_extra",-1),X=B===void 0?void 0:this.vec2(B,"slot_extra",!1),Z=this.arg(s.args,"bores",-1),h1=Z===void 0?void 0:(Array.isArray(Z)?Z:[Z]).map(g1=>{if(typeof g1!="string")throw new Error("bores must be hardware labels or kinds");return g1}),H=this.arg(s.args,"halving",-1),U=H===void 0?void 0:(Array.isArray(H)?H:[H]).map(g1=>{if(typeof g1!="string")throw new Error("halving must be part names");return g1}),Y=this.arg(s.args,"fit",-1,"turn");if(typeof Y!="number"&&!Object.prototype.hasOwnProperty.call(M5,v0(Y)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${C0(Y)}`);let Q=typeof Y=="number"?Y:M5[v0(Y)],W=(g1,X1,D1)=>{let E=D1.length===l,D=b?.filter((e1,u1)=>D1.includes(Math.floor(u1/u)+1));return{name:i,qty:D1.length*u,layers:g1,thickness:M,kerf:q0(this.dyn(s.env,"$kerf"))||0,material:v0(this.dyn(s.env,"$material")??"material"),...D?{placements:D}:{},...u>1?{stack:u}:{},...C.length?{bends:C}:{},...P!==void 0?{on:v0(P)}:{},...q?{slots:q,clearance:T}:{},...q&&X?{slotExtra:X}:{},...h1?{bores:h1,fit:Q}:{},...U?{halving:U,clearance:T}:{},...this.step?{step:this.step}:{},...g!==void 0&&{glue:{host:g,face:p}},...X1&&{mirrored:!0},...!E&&{copies:D1}}},F1=g1=>k.flatMap((X1,D1)=>X1===g1?[D1+1]:[]),L1=z?[W(L.layers,S,F1(S)),W(A(!S).layers,!S,F1(!S))]:[W(L.layers,S,F1(S))];return{layers:new Map,parts:[...L.parts,...L1]}},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=q1(l,Q0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=v0(this.arg(s.args,"text",0,"")),o=g0(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=v0(this.arg(s.args,"kind",0,"dowel"));e2(q3,i)===void 0&&e2(L5,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${d2(s.args.at,!1)})${y3(i,Object.keys(q3))}`);let o=v0(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${C0(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"),m=this.arg(s.args,"size",3,6),g=typeof m=="number"?m:this.vec2(m,"size",!1);if(h){if(typeof g!="number"||!(g>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let p=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(p[2])>.9*Math.hypot(...p),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<=p6))throw new Error(`sides must be from 3 to ${p6} (or 0 for a ball), got ${C0(x)}`);if(this.pointCount+=h?2*p6: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:g,up:z(b),sides:x,step:this.step,...M!==void 0?{label:v0(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",v0(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return O0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new I0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(g=>u.add(g));else for(let g of this.iterable(l,s.args.at)){let p=q0(g);o[p]?u.add(o[p]):o.length&&p>=o.length&&i.module&&i.pos&&this.warn(`${i.module}() uses children(${p}) but was given ${o.length} child${o.length===1?"":"ren"} (${d2(i.pos,!1)}). A module call takes one statement as its child: put several in braces, ${i.module}() { a(); b(); }`)}let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let m=this.childKey(h);for(let g of i.stmts)if(g.kind==="assign")this.stmt(g,h);else if(u.has(g)){let p=m&&d.get(g);if(p&&p.key===m){p.shape&&f.push(p.shape);continue}let v=this.effects(),y=this.stmt(g,h);y&&f.push(y),m&&this.effects()===v&&!y?.parts.length&&d.set(g,{key:m,shape:y})}return A2(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),A0(y4(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),A0(e7(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 A0(i1(t7(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),L2(n7(i,o,l,h,u))}};function c(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,u]of l.layers)if(h!==s2)for(let f of u.regions)o.regions.push(f)}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 X3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},b6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function x6(t,e){let n=[];for(let[r,c]of t){let a=[X3(r),X3(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 Z3=(t,e)=>`M${x6(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function $4(t,e){let n=[];for(let r of e){let c=[],a=[],s=[];for(let i of t){let o=i.layers.get(r.name);if(o){for(let l of o.lines)c.push(Z3(l,!1));for(let l of o.regions)(M1(l)<0?a:s).push(Z3(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 D4(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="${X3(e)}mm" height="${X3(n)}mm" viewBox="0 0 ${X3(e)} ${X3(n)}">`];for(let a of r){let s=[],i=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${b6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>Z3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${Z3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${Z3(f,!1)}"/>`);for(let f of h.regions)(M1(f)<0?s:i).push(`<path${u} d="${Z3(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"':""}`;c.push(`<g id="${b6(a.name)}" inkscape:groupmode="layer" inkscape:label="${b6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return c.push("</svg>",""),c.join(`
|
|
2643
|
+
`)}var Si={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},Li=t=>{let e=Si[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 Ai(t){let e=i=>i.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(R4.map(i=>i.name)),r=new Set(t.map(i=>e(i.name))),c=new Set,a=new Map,s=[...t.filter(i=>n.has(i.name)),...t.filter(i=>!n.has(i.name))];for(let i of s){let o=e(i.name);if(c.has(o)){let l=2;for(;r.has(`${o}_${l}`)||c.has(`${o}_${l}`);)l++;o=`${o}_${l}`}c.add(o),a.set(i.name,o)}return a}function M6(t,e,n,r){let c=[],a=(o,l)=>c.push(String(o),String(l)),s=Ai(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 o of r)a(0,"LAYER"),a(2,s.get(o.name)),a(70,0),a(62,Li(o.color)),a(6,"CONTINUOUS");a(0,"ENDTAB"),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"ENTITIES");let i=(o,l,h)=>{a(0,"POLYLINE"),a(8,o),a(66,1),a(10,0),a(20,0),a(30,0),a(70,h?1:0);for(let[u,f]of x6(l.map(([d,m])=>[d,n-m]),h))a(0,"VERTEX"),a(8,o),a(10,u),a(20,f),a(30,0);a(0,"SEQEND"),a(8,o)};for(let o of r){let l=s.get(o.name),h=[];for(let u of t){let f=u.layers.get(o.name);if(f){for(let d of f.lines)i(l,d,!1);for(let d of f.regions)M1(d)<0?i(l,d,!0):h.push(d)}}for(let u of h)i(l,u,!0)}return a(0,"ENDSEC"),a(0,"EOF"),c.join(`
|
|
2228
2644
|
`)+`
|
|
2229
|
-
`}var at=(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},M0=t=>Math.round(t*100)/100;function qs(t,e={}){for(let[A,G]of Object.entries(e.params??{}))try{f6(A,G)}catch(N){throw new i1(N.message)}let{program:n}=r2(t),c=new Set(n.body.flatMap(A=>A.kind==="assign"?[A.name]:[])),r=Object.keys(e.params??{}).filter(A=>!A.startsWith("$")&&!c.has(A)),a=e.fonts?new y4(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(A){let G=A instanceof RangeError?new i1(/call stack/i.test(A.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):A;throw G instanceof i1&&(G.echoes=s.echoes,G.warnings=[...s.warnings],a?.missing.size&&(G.missingFonts=[...a.missing])),G}let l=A=>o.globals.get(A).value,h=o.warnings;for(let A of r)h.push(`Setting "${A}" is not a variable of the program, so it is ignored.${l3(A,c)}`);let u=o.layers,f=A=>u.get(A)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(A=>A.regions.length||A.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:A0(l("$thickness"))||3,kerf:A0(l("$kerf"))||0,material:L0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let p=A=>JSON.stringify([A.thickness,A.material,[...A.layers].map(([G,N])=>[G,N.regions.map(s1=>s1.map(([K,S1])=>[Math.round(K*100),Math.round(S1*100)])),N.lines.map(s1=>s1.map(([K,S1])=>[Math.round(K*100),Math.round(S1*100)]))])]),g=new Map,v=new Set;for(let A of d){let G=p(A),N=A.mirrored?`${A.name}\0mirrored`:A.name,s1=g.get(N);s1===void 0?g.set(N,G):s1!==G&&v.add(A.name)}for(let A of v)h.push(`Two different parts are named "${A}"; slots, glue and on = find parts by name, so give each its own.`);Ws(d,h),Us(d,f,h);let y=[],b=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],M=new Map,S=[],w=new Set,z=[],C=l("$min_width"),k=C===void 0?1.5:A0(C),T=l("$label_parts")===!0,q=0;T&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");T&&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 U=T&&!!a&&(!R||R.side==="back");if(U){let A=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:A?.color??"#000000",side:"back"})}let j=[];for(let A of d){let G=w1([...A.layers].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.regions)),N;if(A.bends&&G.length){let l1=1/0,M1=-1/0;for(let g1 of G)for(let[d1]of g1)l1=Math.min(l1,d1),M1=Math.max(M1,d1);for(let g1 of A.bends)(g1.x0<l1-.001||g1.x1>M1+.001)&&h.push(`Part "${A.name}" bends from x = ${L2(g1.x0)} to ${L2(g1.x1)}, beyond the part (x = ${L2(l1)} to ${L2(M1)}); only the part itself bends.`)}if(U&&G.length){N=++q;let l1=Xs(G,String(N),a,L0(l("$font")??""));if(l1.length){let M1=A.layers.get("engrave-back")??{regions:[],lines:[]};A.layers=new Map(A.layers).set("engrave-back",{regions:[...M1.regions,...l1],lines:M1.lines})}else h.push(`Part "${A.name}" is too small to take its number ${N}.`)}if(k>0&&G.length){let l1=p0(p0(G,-k/2,"round"),k/2,"round"),M1=B0(y0(G,l1)).filter(g1=>g1.reduce((d1,v1)=>d1+H1(v1),0)>2*k*k);if(M1.length){let g1=M1.slice(0,3).map(d1=>{let[v1,N1,l0,w0]=$0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${M0((v1+l0)/2)}, ${M0((N1+w0)/2)}]`});h.push(`Part "${A.name}" is narrower than ${k} mm ($min_width) in ${M1.length} place${M1.length>1?"s":""}, at ${g1.join(", ")}${M1.length>3?" and more":""} in the part's coordinates.`)}}let s1=new Map;for(let[l1,M1]of A.layers){if(f(l1)==="guide"&&!e.guides)continue;let g1=w1(M1.regions),d1=M1.lines.filter(v1=>v1.length>=2);if((f(l1)==="line"||f(l1)==="guide")&&(d1=[...d1,...g1.map(v1=>[...v1,v1[0]])],g1=[]),G.length&&f(l1)!=="guide"){let v1=u.get(l1)?.bleed??0,N1=v1>0?p0(G,v1,"round"):G;f(l1)!=="cut"&&(g1=b0(g1,N1)),d1=g2(d1,N1,"inside")}(g1.length||d1.length)&&s1.set(l1,{regions:g1,lines:d1})}if(j.push(...js(A.name,s1,u)),G.length){let l1=[];for(let[g1,d1]of s1){let v1=u.get(g1);if(v1?.mode==="cut"&&d1.lines.length)for(let N1 of["front","back"])l1.push({layer:g1,mode:"line",color:"#000000",side:N1,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 M1={name:A.name,thickness:A.thickness,material:A.material,outline:G,...l1.length&&{marks:l1}};if(A.placements){let g1=new Set;A.placements.forEach((d1,v1)=>{let N1={...M1,copy:st(A,v1),matrix:K0(d1),placed:!0,...A.bends&&{bends:A.bends},...A.step&&{step:A.step},...A.stack&&{stack:A.stack}};x.push(N1),A.on!==void 0&&M.set(N1,A.on);let l0=N1.matrix.map(w0=>w0.toFixed(6)).join(",");g1.has(l0)&&w.add(N1),g1.add(l0)}),g1.size<A.placements.length&&h.push(`Copies of part "${A.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<A.qty;g1++)S.push({...M1,copy:st(A,g1),matrix:K0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...A.step&&{step:A.step}})}let K=B0(G),S1=K.length;if(S1>1){let l1=d1=>d1.reduce((v1,N1)=>v1+H1(N1),0),g1=[...K].sort((d1,v1)=>l1(v1)-l1(d1)).slice(1,4).map(d1=>{let[v1,N1,l0,w0]=$0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${M0(v1)}, ${M0(N1)}] to [${M0(l0)}, ${M0(w0)}]`}).join(", ");h.push(`Part "${A.name}" cuts into ${S1} separate pieces. Join them, or make them separate parts. The smaller ${S1===2?"one is":"ones are"} at ${g1}${S1>4?" and more":""}, in the part's coordinates.`)}let Y1=0;for(let[l1,M1]of s1)if(f(l1)==="cut"){for(let g1 of M1.regions)Y1+=at(g1,!0);for(let g1 of M1.lines)Y1+=at(g1,!1)}let G1=$0(s1)??[0,0,0,0],A1=e.kerf??A.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new i1("$kerf must be a number, 0 or more");let B1={name:A.name,qty:A.qty,width:M0(G1[2]-G1[0]),height:M0(G1[3]-G1[1]),pieces:S1,cutLength:Math.round(Y1),thickness:A.thickness,kerf:A1,material:A.material,...A.stack&&{stack:A.stack},...A.glue&&{glued:A.glue.host},...A.mirrored&&{mirrored:!0},...N!==void 0&&{label:N}};if(b&&b.parts.push({name:A.name,kerf:A1,qty:A.qty,...A.stack&&{stack:A.stack},...A.glue&&{glue:A.glue},...A.on&&{on:A.on},cutRegions:G.map(l1=>l1.map(([M1,g1])=>[M1,g1])),cutLines:[...s1].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.lines.map(M1=>M1.map(([g1,d1])=>[g1,d1])))}),A1>0){for(let[l1,M1]of s1)if(f(l1)==="cut"){let g1=M1.regions.filter(N1=>H1(N1)<0);M1.regions=p0(M1.regions,A1/2,"round",Math.min(.01,A1/20));let d1=M1.regions.filter(N1=>H1(N1)<0),v1=g1.length-d1.length;if(v1>0){let N1=w0=>{let[$2,e3,d9,m9]=$0(new Map([["cut",{regions:[w0],lines:[]}]]));return[($2+d9)/2,(e3+m9)/2]},l0=g1.map(N1).filter(([w0,$2])=>!d1.some(e3=>it(e3,w0,$2))).slice(0,3).map(([w0,$2])=>`[${M0(w0)}, ${M0($2)}]`);h.push(`Part "${A.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(B1),z.push({info:B1,layers:s1})}Bs(x,M,h);let V=new Map,Q=x.filter(A=>!w.has(A)).flatMap(A=>{let G=J5(A);for(let N of G)V.set(N,A);return G}),{found:W,complete:o1}=e7(Q,i.maxCollisionPairs),m1=W.filter(([A,G])=>V.get(A)!==V.get(G)).map(([A,G])=>[V.get(A)??A,V.get(G)??G]).filter(([A,G],N,s1)=>s1.findIndex(([K,S1])=>K===A&&S1===G)===N);o1||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[A,G]of m1.slice(0,5)){let[N,s1]=o5(A),[K,S1]=o5(G),Y1=[0,1,2].map(G1=>M0((Math.max(N[G1],K[G1])+Math.min(s1[G1],S1[G1]))/2));h.push(`Parts "${A.name}"${A.copy>1?` (copy ${A.copy})`:""} and "${G.name}"${G.copy>1?` (copy ${G.copy})`:""} collide in the assembly, around [${Y1.join(", ")}]. Check their edges and where they are placed.`)}if(m1.length>5&&h.push(`${m1.length-5} more pairs of parts collide in the assembly.`),_s(j,h),x.length&&S.length){let A=[...new Set(S.map(G=>`"${G.name}"`))];h.push(`${A.length===1?"Part":"Parts"} ${A.slice(0,5).join(", ")}${A.length>5?` and ${A.length-5} more`:""} ${A.length===1?"has":"have"} no at or rotate, so ${A.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...Qe(x,S))}let I=0;for(let A of z){let G=0;for(let N of A.layers.values()){for(let s1 of N.regions)G+=s1.length;for(let s1 of N.lines)G+=s1.length}I+=G*A.info.qty}if(I>i.maxOutputPoints)throw new i1(`The files would have ${I} 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 Z=e.gap??A0(l("$gap")??3),_=e.margin??Z;if(!(Number.isFinite(Z)&&Z>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(_)&&_>=0))throw new i1("margin must be a number, 0 or more");let L1=e.nest??l("$nest")===!0,W1=e.layout??(l("$layout")==="none"?"none":"pack"),E1=[...u.keys()].filter(A=>!["engrave","score","cut","guide"].includes(A)),Z1=A=>(u.get(A)?.order??0)*2+(f(A)==="fill"?0:1),o0=["engrave",...E1.map((A,G)=>[A,G]).sort((A,G)=>Z1(A[0])-Z1(G[0])||A[1]-G[1]).map(([A])=>A),"score","cut","guide"].map(A=>u.get(A)).filter(Boolean),L=o0.filter(A=>A.side!=="back"),F=[...o0.filter(A=>A.side==="back")],t1=l("$registration")===!0;t1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),t1&&!L.some(A=>A.name==="registration")&&L.push(u.get("registration"));let r1=[],y1=[1,0,0,-1,0,0],P=A=>$0(A)??[0,0,0,0],Y=(A,G)=>z3({layers:A,parts:[]},G).layers;if(W1==="none"){let A=[];for(let K of z)for(let S1=0;S1<K.info.qty;S1++)A.push({part:K.info.name,copy:S1+1,layers:Y(K.layers,y1),rotated:!1});let G=new Map;for(let K of A)for(let[S1,Y1]of K.layers){let G1=G.get(S1)??{regions:[],lines:[]};for(let A1 of Y1.regions)G1.regions.push(A1);for(let A1 of Y1.lines)G1.lines.push(A1);G.set(S1,G1)}let N=P(G),s1=[1,0,0,1,_-N[0],_-N[1]];for(let K of A)K.layers=Y(K.layers,s1),K.offset=[s1[4],s1[5]];r1.push(X(A,N[2]-N[0]+2*_,N[3]-N[1]+2*_,z[0]?.info))}else{let A=new Map;for(let G of z){let N=`${G.info.material}|${G.info.thickness}`;A.set(N,[...A.get(N)??[],G])}for(let G of A.values()){let[N,s1]=$,K=[];for(let d1 of G){let v1=Y(d1.layers,y1),N1=P(v1),l0=N1[2]-N1[0],w0=N1[3]-N1[1],$2=!1;(l0>N-2*_||w0>s1-2*_)&&w0<=N-2*_&&l0<=s1-2*_&&(v1=Y(v1,[0,1,-1,0,0,0]),N1=P(v1),l0=N1[2]-N1[0],w0=N1[3]-N1[1],$2=!0),(l0>N-2*_||w0>s1-2*_)&&h.push(`Part "${d1.info.name}" (${M0(l0)} x ${M0(w0)} mm) is bigger than the ${N} x ${s1} mm sheet.`),v1=Y(v1,[1,0,0,1,-N1[0],-N1[1]]);for(let e3=0;e3<d1.info.qty;e3++)K.push({info:d1.info,layers:v1,w:l0,h:w0,copy:e3+1,rotated:$2})}K.sort((d1,v1)=>v1.h-d1.h||v1.w-d1.w);let S1=L1?Gs(K,Z,d1=>f(d1)==="cut"):K,Y1=[],G1=_,A1=_,B1=0,l1=0,M1=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(X(Y1,Math.max(l1+_,1),Math.max(M1+_,1),G[0].info)),Y1=[],G1=_,A1=_,B1=0,l1=0,M1=0};for(let d1 of S1){G1>_&&G1+d1.w>N-_&&(G1=_,A1+=B1+Z,B1=0),Y1.length&&A1+d1.h>s1-_&&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),M1=Math.max(M1,A1+d1.h),G1+=d1.w+Z,B1=Math.max(B1,d1.h)}g1()}}function X(A,G,N,s1){let K=M0(G),S1=M0(N);if(t1){let A1=Math.min(5,_-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let B1=(l1,M1)=>[[l1,M1],[l1+A1,M1],[l1+A1,M1+A1],[l1,M1+A1]];A=[...A,{part:"registration",copy:1,layers:new Map([["registration",{regions:[B1(.5,.5),B1(K-.5-A1,.5),B1(.5,S1-.5-A1)],lines:[]}]]),rotated:!1}]}}let Y1=A.some(A1=>F.some(B1=>A1.layers.has(B1.name))),G1=Y1?A.map(A1=>({...A1,layers:Y(A1.layers,[-1,0,0,1,K,0])})):[];return{width:K,height:S1,material:s1?.material??"material",thickness:s1?.thickness??0,items:A,paths:M4(A,L),svg:w4(A,K,S1,L),dxf:te(A,K,S1,L),...Y1&&{back:{paths:M4(G1,F),svg:w4(G1,K,S1,F),dxf:te(G1,K,S1,F)}}}}let b1=r1.length===1?r1[0]:void 0,a1=b1?[]:r1.flatMap((A,G)=>{let N=r1.slice(0,G).reduce((s1,K)=>s1+K.height+10,0);return A.items.map(s1=>({...s1,layers:Y(s1.layers,[1,0,0,1,0,N])}))}),R1=M0(Math.max(1,...r1.map(A=>A.width))),e1=M0(Math.max(1,r1.reduce((A,G)=>A+G.height,0)+10*Math.max(0,r1.length-1))),T1=b1?b1.svg:w4(a1,R1,e1,L),r0=b1?b1.paths:M4(a1,L);return{sheets:r1,width:b1?.width??R1,height:b1?.height??e1,paths:r0,svg:T1,parts:y,assembly:x,layers:[...L,...F],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function Ns(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 Us(t,e,n){if(!t.some(l=>l.slots))return;let c=new Map,r=l=>{let h=c.get(l);return h||(h=w1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},a=l=>(l.placements??[]).flatMap(h=>J5({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=Ns(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=>w1(J5({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=r7(v,u,l.clearance??.1);return l.bends?b0(y,p0(v.outline,1,"miter")):y}))),d=(g,v)=>M3(g,v).reduce((y,b)=>y+Math.abs(H1(b)),0)>.001,m=l.stack??1;if(m>1){let g=y=>f.filter((b,x)=>x%m===y),v=Array.from({length:m},(y,b)=>w1(g(b).flat()));if(v.slice(1).some(y=>d(v[0],y))){Array.from({length:m},(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 p=w1(f.flat());if(!p.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,p)}let o=(l,h)=>{let u=new Map(l);for(let[f,d]of l)u.set(f,{regions:y0(d.regions,h),lines:g2(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,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/u,layers:d.length?o(l.layers,d):l.layers,placements:l.placements.filter((p,g)=>g%u===m),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function Bs(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,S])=>M.name===r.name&&S===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[S,w]of M)l=Math.min(l,S),h=Math.min(h,w),u=Math.max(u,S),f=Math.max(f,w);let d=r.matrix,[m,p,g]=[(l+u)/2,(h+f)/2,r.thickness/2],v=[d[0]*m+d[1]*p+d[2]*g+d[3],d[4]*m+d[5]*p+d[6]*g+d[7],d[8]*m+d[9]*p+d[10]*g+d[11]],y=S0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=Y5(o.bends,o.thickness)[n7(o.bends,b)];r.matrix=$1(o.matrix,$1(x,$1(y,r.matrix)))}}function Gs(t,e,n){var l;let c=[],r=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)H1(m)<0&&u.push([...m].reverse());return u.length?p0(w1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let m of h)for(let p=0,g=m.length-1;p<m.length;g=p++){let[v,y]=m[g],[b,x]=m[p];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 m of d.regions)H1(m)>0&&u.push(m);return w1(u)},i=(h,u)=>{let{w:f,h:d}=u,m=s(u),p=[];for(let g of m)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))p.push(g[v]);for(let g of h){if(H1(g)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[S,w]of g)v=Math.min(v,S),y=Math.min(y,w),b=Math.max(b,S),x=Math.max(x,w);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 S=y;S<=x-d+1e-9;S+=M)for(let w=v;w<=b-f+1e-9;w+=M){if(!p.every(([C,k])=>a(h,C+w,k+S)))continue;let z=m.map(C=>C.map(([k,T])=>[k+w,T+S]));if(y0(z,h).reduce((C,k)=>C+Math.abs(H1(k)),0)<.01)return[w,S]}}},o=[];for(let h of t){let u=!1;for(let d of c){let m=i(d.region,h);if(!m)continue;let[p,g]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+p,dy:d.oy+g}),d.region=y0(d.region,p0(s(h).map(y=>y.map(([b,x])=>[b+p,x+g])),e,"miter"));let v=r(h);v.length&&c.push({host:d.host,ox:d.ox+p,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 st(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 js(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 B0(e.get(r[i]).regions)){let f=u.reduce((M,S)=>M+H1(S),0);if(!(f>.001)||!p0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=y0(d,e.get(M).regions));if(d.reduce((M,S)=>M+H1(S),0)>.001*Math.max(1,f))continue;let p=l.filter(M=>b0(u,e.get(M).regions).length),g=p.length?p:l;if(h){h.count++;for(let M of g)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=$0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:r[i],under:g,count:1,at:[M0((v+b)/2),M0((y+x)/2)]}}h&&a.push(h)}return a}function _s(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 Ws(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:$1(f,$1(D0(0,0,o),K0(h)))}}),n.add(r)};for(let r of t)c(r,[])}function Xs(t,e,n,c){let r=0,a=50;for(let p=0;p<14;p++){let g=(r+a)/2;p0(t,-g,"round").length?r=g:a=g}if(r<1)return[];let s=p0(t,-r*.98,"round"),i=$0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((p,g)=>s.reduce((v,y)=>v+(it(y,p,g)?H1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((p,g)=>H1(g)>H1(p)?g:p)[0]);let u=Math.min(6,Math.max(2,r*.9)),f=b4(n,e,{size:u,font:c,halign:"center",valign:"center",spacing:1}),d=$0(new Map([["t",{regions:f,lines:[]}]])),m=d?Math.min(1,1.6*r/Math.max(d[2]-d[0],1e-9)):1;return f.map(p=>p.map(([g,v])=>[o-g*m,l+v*m]).reverse())}function it(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 lt(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=lt(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 ot(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function Zs(t){let{program:e,comments:n}=r2(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=lt(i.value);if(!o.ok)continue;let l=c.filter(p=>p.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},m=h?/^\[(.*)\]$/.exec(h.trim()):null;if(m){let p=m[1];if(p.includes(",")||/[a-zA-Z"]/.test(p)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(p))d.options=p.split(",").map(g=>{let[v,y]=g.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=ot(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let g=p.split(":").map(ot);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 Ys=8,Js=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,Ks=(t,e)=>Math.max(1,Js.exec(t.slice(e-1))?.[0].length??1);function Qs(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(g5,o)?g5[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(`
|
|
2230
|
-
`)?.[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=
|
|
2231
|
-
`)}function
|
|
2232
|
-
`)r
|
|
2233
|
-
`,
|
|
2234
|
-
`);n.push({kind:"block",text:o,breaks:
|
|
2645
|
+
`}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},m0=t=>Math.round(t*100)/100;function Ci(t,e={}){for(let[I,N]of Object.entries(e.params??{}))try{Pe(I,N)}catch(a1){throw new l1(a1.message)}let{program:n}=m2(t),r=new Set(n.body.flatMap(I=>I.kind==="assign"?[I.name]:[])),c=Object.keys(e.params??{}).filter(I=>!I.startsWith("$")&&!r.has(I)),a=e.fonts?new O4(e.fonts,e.defaultFont):void 0,s=new W3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(n)}catch(I){let N=I instanceof RangeError?new l1(/call stack/i.test(I.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):I;throw N instanceof l1&&(N.echoes=s.echoes,N.warnings=[...s.warnings],a?.missing.size&&(N.missingFonts=[...a.missing])),N}let l=I=>o.globals.get(I).value,h=o.warnings;for(let I of c)h.push(`Setting "${I}" is not a variable of the program, so it is ignored.${y3(I,r)}`);let u=o.layers,f=I=>u.get(I)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(I=>I.regions.length||I.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:q0(l("$thickness"))||3,kerf:q0(l("$kerf"))||0,material:v0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let g=I=>JSON.stringify([I.thickness,I.material,[...I.layers].map(([N,a1])=>[N,a1.regions.map(J=>J.map(([x1,R1])=>[Math.round(x1*100),Math.round(R1*100)])),a1.lines.map(J=>J.map(([x1,R1])=>[Math.round(x1*100),Math.round(R1*100)]))])]),p=new Map,v=new Set;for(let I of d){let N=g(I),a1=I.mirrored?`${I.name}\0mirrored`:I.name,J=p.get(a1);J===void 0?p.set(a1,N):J!==N&&v.add(I.name)}for(let I of v)h.push(`Two different parts are named "${I}"; slots, glue and on = find parts by name, so give each its own.`);Di(d,h),Ei(d,f,h,o.hardware),Ti(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"),A=S===void 0?1.5:q0(S),L=l("$label_parts")===!0,C=l("$join_lines")===!0,P=0;L&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");L&&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 q=L&&!!a&&(!R||R.side==="back");if(q){let I=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:I?.color??"#000000",side:"back"})}let T=[];for(let I of d){let N=i1([...I.layers].filter(([m1])=>f(m1)==="cut").flatMap(([,m1])=>m1.regions)),a1;if(I.bends&&N.length){let m1=1/0,v1=-1/0;for(let y1 of N)for(let[T1]of y1)m1=Math.min(m1,T1),v1=Math.max(v1,T1);for(let y1 of I.bends)(y1.x0<m1-.001||y1.x1>v1+.001)&&h.push(`Part "${I.name}" bends from x = ${D2(y1.x0)} to ${D2(y1.x1)}, beyond the part (x = ${D2(m1)} to ${D2(v1)}); only the part itself bends.`)}if(q&&N.length){a1=++P;let m1=qi(N,String(a1),a,v0(l("$font")??""));if(m1.length){let v1=I.layers.get("engrave-back")??{regions:[],lines:[]};I.layers=new Map(I.layers).set("engrave-back",{regions:[...v1.regions,...m1],lines:v1.lines})}else h.push(`Part "${I.name}" is too small to take its number ${a1}.`)}if(A>0&&N.length){let m1=n0(n0(N,-A/2,"round"),A/2,"round"),v1=F0(k0(N,m1)).filter(y1=>y1.reduce((T1,$1)=>T1+M1($1),0)>2*A*A);if(v1.length){let y1=v1.slice(0,3).map(T1=>{let[$1,J1,K0,B1]=X0(new Map([["cut",{regions:T1,lines:[]}]]));return`[${m0(($1+K0)/2)}, ${m0((J1+B1)/2)}]`});h.push(`Part "${I.name}" is narrower than ${A} mm ($min_width) in ${v1.length} place${v1.length>1?"s":""}, at ${y1.join(", ")}${v1.length>3?" and more":""} in the part's coordinates.`)}}let J=new Map;for(let[m1,v1]of I.layers){if(m1===s2||f(m1)==="guide"&&!e.guides)continue;let y1=i1(v1.regions),T1=v1.lines.filter($1=>$1.length>=2);if((f(m1)==="line"||f(m1)==="guide")&&(T1=[...T1,...y1.map($1=>[...$1,$1[0]])],y1=[]),N.length&&f(m1)!=="guide"){let $1=u.get(m1)?.bleed??0,J1=$1>0?n0(N,$1,"round"):N;f(m1)!=="cut"&&(y1=a0(y1,J1)),T1=W0(T1,J1,"inside")}C&&T1.length>1&&f(m1)!=="guide"&&(T1=bt(T1)),(y1.length||T1.length)&&J.set(m1,{regions:y1,lines:T1})}if(T.push(...Ri(I.name,J,u)),N.length){let m1=[];for(let[y1,T1]of J){let $1=u.get(y1);if($1?.mode==="cut"&&T1.lines.length)for(let J1 of["front","back"])m1.push({layer:y1,mode:"line",color:"#000000",side:J1,regions:[],lines:T1.lines});!$1||$1.mode!=="fill"&&$1.mode!=="line"||m1.push({layer:y1,mode:$1.mode,color:$1.color,side:$1.side??"front",regions:T1.regions,lines:T1.lines})}let v1={name:I.name,thickness:I.thickness,material:I.material,outline:N,...m1.length&&{marks:m1}};if(I.placements){let y1=new Set;I.placements.forEach((T1,$1)=>{let J1={...v1,copy:w6(I,$1),matrix:Q0(T1),placed:!0,...I.bends&&{bends:I.bends},...I.step&&{step:I.step},...I.stack&&{stack:I.stack}};x.push(J1),I.on!==void 0&&M.set(J1,I.on);let K0=J1.matrix.map(B1=>B1.toFixed(6)).join(",");y1.has(K0)&&k.add(J1),y1.add(K0)}),y1.size<I.placements.length&&h.push(`Copies of part "${I.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 y1=0;y1<I.qty;y1++)w.push({...v1,copy:w6(I,y1),matrix:Q0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...I.step&&{step:I.step}})}let x1=F0(N),R1=x1.length;if(R1>1){let m1=T1=>T1.reduce(($1,J1)=>$1+M1(J1),0),y1=[...x1].sort((T1,$1)=>m1($1)-m1(T1)).slice(1,4).map(T1=>{let[$1,J1,K0,B1]=X0(new Map([["cut",{regions:T1,lines:[]}]]));return`[${m0($1)}, ${m0(J1)}] to [${m0(K0)}, ${m0(B1)}]`}).join(", ");h.push(`Part "${I.name}" cuts into ${R1} separate pieces. Join them, or make them separate parts. The smaller ${R1===2?"one is":"ones are"} at ${y1}${R1>4?" and more":""}, in the part's coordinates.`)}let w0=0;for(let[m1,v1]of J)if(f(m1)==="cut"){for(let y1 of v1.regions)w0+=B8(y1,!0);for(let y1 of v1.lines)w0+=B8(y1,!1)}let Y1=X0(J)??[0,0,0,0],A1=e.kerf??I.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new l1("$kerf must be a number, 0 or more");let l0={name:I.name,qty:I.qty,width:m0(Y1[2]-Y1[0]),height:m0(Y1[3]-Y1[1]),pieces:R1,cutLength:Math.round(w0),thickness:I.thickness,kerf:A1,material:I.material,...I.stack&&{stack:I.stack},...I.glue&&{glued:I.glue.host},...I.mirrored&&{mirrored:!0},...a1!==void 0&&{label:a1}};if(b&&b.parts.push({name:I.name,kerf:A1,qty:I.qty,...I.stack&&{stack:I.stack},...I.glue&&{glue:I.glue},...I.on&&{on:I.on},cutRegions:N.map(m1=>m1.map(([v1,y1])=>[v1,y1])),cutLines:[...J].filter(([m1])=>f(m1)==="cut").flatMap(([,m1])=>m1.lines.map(v1=>v1.map(([y1,T1])=>[y1,T1])))}),A1>0){for(let[m1,v1]of J)if(f(m1)==="cut"){let y1=v1.regions.filter(J1=>M1(J1)<0);v1.regions=n0(v1.regions,A1/2,"round",Math.min(.01,A1/20));let T1=v1.regions.filter(J1=>M1(J1)<0),$1=y1.length-T1.length;if($1>0){let J1=B1=>{let[c0,b0,c2,G0]=X0(new Map([["cut",{regions:[B1],lines:[]}]]));return[(c0+c2)/2,(b0+G0)/2]},K0=y1.map(J1).filter(([B1,c0])=>!T1.some(b0=>_8(b0,B1,c0))).slice(0,3).map(([B1,c0])=>`[${m0(B1)}, ${m0(c0)}]`);h.push(`Part "${I.name}": ${$1} hole${$1===1?" is":"s are"} narrower than the ${A1} mm kerf and will not be cut${K0.length?`, at ${K0.join(", ")}${$1>K0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(l0),z.push({info:l0,layers:J,copy:m1=>w6(I,m1)})}Ii(x,M,h);let B=new Map,X=x.filter(I=>!k.has(I)).flatMap(I=>{let N=d4(I);for(let a1 of N)B.set(a1,I);return N}),{found:Z,complete:h1}=Ct(X,i.maxCollisionPairs),H=Z.filter(([I,N])=>B.get(I)!==B.get(N)).map(([I,N,a1])=>[B.get(I)??I,B.get(N)??N,a1,I,N]).filter(([I,N],a1,J)=>J.findIndex(([x1,R1])=>x1===I&&R1===N)===a1);h1||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[I,N,a1,J,x1]of H.slice(0,5)){let R1=(Pt(J,x1)??a1).map(m0);h.push(`Parts "${I.name}"${I.copy>1?` (copy ${I.copy})`:""} and "${N.name}"${N.copy>1?` (copy ${N.copy})`:""} collide in the assembly, around [${R1.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.`),$i(T,h),x.length&&w.length){let I=[...new Set(w.map(N=>`"${N.name}"`))];h.push(`${I.length===1?"Part":"Parts"} ${I.slice(0,5).join(", ")}${I.length>5?` and ${I.length-5} more`:""} ${I.length===1?"has":"have"} no at or rotate, so ${I.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...St(x,w))}let U=0;for(let I of z){let N=0;for(let a1 of I.layers.values()){for(let J of a1.regions)N+=J.length;for(let J of a1.lines)N+=J.length}U+=N*I.info.qty}if(U>i.maxOutputPoints)throw new l1(`The files would have ${U} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let Y=e.sheet??(o.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 Q=e.gap??q0(l("$gap")??3),W=e.margin??Q;if(!(Number.isFinite(Q)&&Q>=0))throw new l1("$gap must be a number, 0 or more");if(!(Number.isFinite(W)&&W>=0))throw new l1("margin must be a number, 0 or more");let F1=e.nest??l("$nest")===!0,L1=e.layout??(l("$layout")==="none"?"none":"pack"),g1=[...u.keys()].filter(I=>!["engrave","score","cut","guide"].includes(I)),X1=I=>(u.get(I)?.order??0)*2+(f(I)==="fill"?0:1),E=["engrave",...g1.map((I,N)=>[I,N]).sort((I,N)=>X1(I[0])-X1(N[0])||I[1]-N[1]).map(([I])=>I),"score","cut","guide"].map(I=>u.get(I)).filter(Boolean),D=E.filter(I=>I.side!=="back"),e1=[...E.filter(I=>I.side==="back")],u1=l("$registration")===!0;u1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),u1&&!D.some(I=>I.name==="registration")&&D.push(u.get("registration"));let t1=[],V=[1,0,0,-1,0,0],n1=I=>X0(I)??[0,0,0,0],G=(I,N)=>u3({layers:I,parts:[]},N).layers;if(L1==="none"){let I=[];for(let x1 of z)for(let R1=0;R1<x1.info.qty;R1++)I.push({part:x1.info.name,copy:x1.copy(R1),layers:G(x1.layers,V),rotated:!1});let N=new Map;for(let x1 of I)for(let[R1,w0]of x1.layers){let Y1=N.get(R1)??{regions:[],lines:[]};for(let A1 of w0.regions)Y1.regions.push(A1);for(let A1 of w0.lines)Y1.lines.push(A1);N.set(R1,Y1)}let a1=n1(N),J=[1,0,0,1,W-a1[0],W-a1[1]];for(let x1 of I)x1.layers=G(x1.layers,J),x1.offset=[J[4],J[5]];t1.push(k1(I,a1[2]-a1[0]+2*W,a1[3]-a1[1]+2*W,z[0]?.info))}else{let I=new Map;for(let N of z){let a1=`${N.info.material}|${N.info.thickness}`;I.set(a1,[...I.get(a1)??[],N])}for(let N of I.values()){let[a1,J]=Y,x1=[];for(let B1 of N){let c0=G(B1.layers,V),b0=n1(c0),c2=b0[2]-b0[0],G0=b0[3]-b0[1],C3=!1;(c2>a1-2*W||G0>J-2*W)&&G0<=a1-2*W&&c2<=J-2*W&&(c0=G(c0,[0,1,-1,0,0,0]),b0=n1(c0),c2=b0[2]-b0[0],G0=b0[3]-b0[1],C3=!0),(c2>a1-2*W||G0>J-2*W)&&h.push(`Part "${B1.info.name}" (${m0(c2)} x ${m0(G0)} mm) is bigger than the ${a1} x ${J} mm sheet.`),c0=G(c0,[1,0,0,1,-b0[0],-b0[1]]);for(let W2=0;W2<B1.info.qty;W2++)x1.push({info:B1.info,layers:c0,w:c2,h:G0,copy:B1.copy(W2),rotated:C3})}let R1=(B1,c0)=>c0.h-B1.h||c0.w-B1.w,w0=B1=>{let c0=0,b0=W,c2=W,G0=0,C3=!1;for(let W2 of B1)b0>W&&b0+W2.w>a1-W&&(b0=W,c2+=G0+Q,G0=0),C3&&c2+W2.h>J-W&&(c0++,[b0,c2,G0]=[W,W,0]),C3=!0,b0+=W2.w+Q,G0=Math.max(G0,W2.h);return c0+(C3?1:0)};x1.sort(R1);let Y1=Hi(x1,Q,B1=>f(B1)==="cut",[a1-2*W,J-2*W]).sort(R1),A1=Y1.length<x1.length&&w0(Y1)<w0(x1)?Y1:x1,l0=F1?Vi(A1,Q,B1=>f(B1)==="cut"):A1,m1=[],v1=W,y1=W,T1=0,$1=0,J1=0,K0=()=>{if(m1.length&&t1.length>=i.maxSheets)throw new l1(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);m1.length&&t1.push(k1(m1,Math.max($1+W,1),Math.max(J1+W,1),N[0].info)),m1=[],v1=W,y1=W,T1=0,$1=0,J1=0};for(let B1 of l0){v1>W&&v1+B1.w>a1-W&&(v1=W,y1+=T1+Q,T1=0),m1.length&&y1+B1.h>J-W&&K0(),m1.push({part:B1.info.name,copy:B1.copy,layers:G(B1.layers,[1,0,0,1,v1,y1]),rotated:B1.rotated});for(let c0 of B1.inner??[])m1.push({part:c0.item.info.name,copy:c0.item.copy,layers:G(c0.item.layers,[1,0,0,1,v1+c0.dx,y1+c0.dy]),rotated:c0.item.rotated});$1=Math.max($1,v1+B1.w),J1=Math.max(J1,y1+B1.h),v1+=B1.w+Q,T1=Math.max(T1,B1.h)}K0()}}function k1(I,N,a1,J){let x1=m0(N),R1=m0(a1);if(u1){let A1=Math.min(5,W-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let l0=(m1,v1)=>[[m1,v1],[m1+A1,v1],[m1+A1,v1+A1],[m1,v1+A1]];I=[...I,{part:"registration",copy:1,layers:new Map([["registration",{regions:[l0(.5,.5),l0(x1-.5-A1,.5),l0(.5,R1-.5-A1)],lines:[]}]]),rotated:!1}]}}let w0=I.some(A1=>e1.some(l0=>A1.layers.has(l0.name))),Y1=w0?I.map(A1=>({...A1,layers:G(A1.layers,[-1,0,0,1,x1,0])})):[];return{width:x1,height:R1,material:J?.material??"material",thickness:J?.thickness??0,items:I,paths:$4(I,D),svg:D4(I,x1,R1,D),dxf:M6(I,x1,R1,D),...w0&&{back:{paths:$4(Y1,e1),svg:D4(Y1,x1,R1,e1),dxf:M6(Y1,x1,R1,e1)}}}}let r1=t1.length===1?t1[0]:void 0,U1=r1?[]:t1.flatMap((I,N)=>{let a1=t1.slice(0,N).reduce((J,x1)=>J+x1.height+10,0);return I.items.map(J=>({...J,layers:G(J.layers,[1,0,0,1,0,a1])}))}),c1=m0(Math.max(1,...t1.map(I=>I.width))),V1=m0(Math.max(1,t1.reduce((I,N)=>I+N.height,0)+10*Math.max(0,t1.length-1))),o0=r1?r1.svg:D4(U1,c1,V1,D),d0=r1?r1.paths:$4(U1,D);return{sheets:t1,width:r1?.width??c1,height:r1?.height??V1,paths:d0,svg:o0,parts:y,assembly:x,layers:[...D,...e1],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function k6(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 Pi(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,i=[r[a],r[s],c[s],c[a]];Math.abs(M1(i))>1e-9&&n.push(M1(i)<0?i.reverse():i)}}return i1(n,"nonzero")}function z6(t,e){let n=new Map(t);for(let[r,c]of t)n.set(r,{regions:k0(c.regions,e),lines:W0(c.lines,e,"outside")});return n}function Ei(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=i1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},s=l=>(l.placements??[]).flatMap(h=>d4({name:l.name,copy:0,placed:!0,matrix:Q0(h),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),i=new Map,o=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 M=x.startsWith("!"),w=k6(M?x.slice(1):x),k=r.filter(z=>w(z.label??"")||w(z.kind));!k.length&&!M&&n.push(`Part "${l.name}": no hardware "${x}" to bore for.`);for(let z of k)M?h.splice(0,h.length,...h.filter(S=>S!==z)):h.includes(z)||h.push(z)}let u=!1,f=new Set;for(let x of l.slots??[]){let M=x.startsWith("!"),w=k6(M?x.slice(1):x),k=t.filter(z=>z!==l&&w(z.name));!k.length&&!M&&n.push(`Part "${l.name}": no part "${x}" to cut slots for.`);for(let z of k)M?f.delete(z):f.add(z)}let d=new Map,m=[...f].flatMap(x=>s(x).map(M=>(d.set(M,x.name),M))),g=new Set,p=(l.placements??[]).map(x=>i1(d4({name:l.name,copy:0,placed:!0,matrix:Q0(x),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).flatMap(M=>{let w=[];if(l.slots){let k=m.map(S=>It(M,[S],0));for(let S=0;S<k.length;S++)for(let A=S+1;A<k.length;A++){let[L,C]=[d.get(m[S]),d.get(m[A])];if(!k[S].length||!k[A].length||L===C||!L||!C)continue;let P=a0(k[S],k[A]);if(P.reduce((R,q)=>R+Math.abs(M1(q)),0)>.01){let R=P.flat().map(h1=>h1[0]),q=P.flat().map(h1=>h1[1]),[T,B,X,Z]=[Math.min(...R),Math.min(...q),Math.max(...R),Math.max(...q)];g.add(`Tabs of "${L}" and "${C}" meet in the same slot in "${l.name}", at [${m0(T)}, ${m0(B)}] to [${m0(X)}, ${m0(Z)}] in its coordinates. Move one's tabs along the edge.`)}}let z=k.flat();w=z.length?Pi(n0(i1(z),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let z=Ot(M,k,l.fit??M5.turn);z&&a0([z],M.outline).some(S=>Math.abs(M1(S))>1e-4)&&(w.push(z),u=!0)}return l.bends?a0(w,n0(M.outline,1,"miter")):w}))),v=(x,M)=>h3(x,M).reduce((w,k)=>w+Math.abs(M1(k)),0)>.001,y=l.stack??1;if(y>1){let x=w=>p.filter((k,z)=>z%y===w),M=Array.from({length:y},(w,k)=>i1(x(k).flat()));if(M.slice(1).some(w=>v(M[0],w))){Array.from({length:y},(w,k)=>x(k)).some(w=>w.slice(1).some(k=>v(w[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.`),o.set(l,M);continue}}p.slice(1).some(x=>v(p[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 g)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 b=i1(p.flat());if(!b.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}i.set(l,b)}for(let[l,h]of i)l.layers=z6(l.layers,h);for(let[l,h]of o){let u=h.length,f=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/u,layers:d.length?z6(l.layers,d):l.layers,placements:l.placements.filter((g,p)=>p%u===m),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function Ti(t,e,n){if(!t.some(i=>i.halving))return;let r=i=>i1([...i.layers].filter(([o])=>e(o)==="cut").flatMap(([,o])=>o.regions)),c=i=>{let o=r(i);return(i.placements??[]).map(l=>({matrix:Q0(l),thickness:i.thickness,outline:o}))},a=new Map,s=(i,o,l)=>{let h=a.get(i)??(i.placements??[]).map(()=>[]);h[o].push(...l),a.set(i,h)};for(let i of t){if(!i.halving)continue;if(!i.placements){n.push(`Part "${i.name}" has halving but no at or rotate, so the crossings can't be found.`);continue}let o=new Set;for(let f of i.halving){let d=f.startsWith("!"),m=k6(d?f.slice(1):f),g=t.filter(p=>p!==i&&m(p.name));!g.length&&!d&&n.push(`Part "${i.name}": no part "${f}" to halve with.`);for(let p of g)d?o.delete(p):o.add(p)}let l=0,h=0,u=c(i);for(let f of o){if(i.bends||f.bends){n.push(`Parts "${i.name}" and "${f.name}": halving joints can't go in a bent part.`);continue}if(!f.placements)continue;let d=c(f);u.forEach((m,g)=>d.forEach((p,v)=>{let y=qt(m,p,i.clearance??.1);h+=y.thin,y.a.length&&(l++,s(i,g,y.a),s(f,v,y.b))}))}h&&n.push(`Part "${i.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&o.size&&!i.halving.some(f=>f.includes("*"))&&n.push(`Part "${i.name}" crosses none of ${i.halving.map(f=>`"${f}"`).join(", ")}, so it has no halving slots.`)}for(let[i,o]of a){let l=o.map(h=>i1(h));l.slice(1).some(h=>h3(l[0],h).reduce((u,f)=>u+Math.abs(M1(f)),0)>.001)&&n.push(`Copies of part "${i.name}" are halved in different places; they all get every slot. Make them separate parts to cut each its own.`),i.layers=z6(i.layers,i1(l.flat()))}}function Ii(t,e,n){let r=new Map;for(let[c,a]of e){let s=t.filter(M=>M.name===a&&M.placed);if(!s.length){r.has(a)||n.push(`Part "${c.name}" is on "${a}", which is not a placed part.`),r.set(a,0);continue}let i=[...e].filter(([M,w])=>M.name===c.name&&w===a).length,o=s.length===i?s[c.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 c.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=c.matrix,[m,g,p]=[(l+u)/2,(h+f)/2,c.thickness/2],v=[d[0]*m+d[1]*g+d[2]*p+d[3],d[4]*m+d[5]*g+d[6]*p+d[7],d[8]*m+d[9]*g+d[10]*p+d[11]],y=p0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=f4(o.bends,o.thickness)[Tt(o.bends,b)];c.matrix=q1(o.matrix,q1(x,q1(y,c.matrix)))}}function Vi(t,e,n){var l;let r=[],c=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)M1(m)<0&&u.push([...m].reverse());return u.length?n0(i1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let m of h)for(let g=0,p=m.length-1;g<m.length;p=g++){let[v,y]=m[p],[b,x]=m[g];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 m of d.regions)M1(m)>0&&u.push(m);return i1(u)},i=(h,u)=>{let{w:f,h:d}=u,m=s(u),g=[];for(let p of m)for(let v=0;v<p.length;v+=Math.max(1,Math.floor(p.length/12)))g.push(p[v]);for(let p of h){if(M1(p)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[w,k]of p)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(!g.every(([S,A])=>a(h,S+k,A+w)))continue;let z=m.map(S=>S.map(([A,L])=>[A+k,L+w]));if(k0(z,h).reduce((S,A)=>S+Math.abs(M1(A)),0)<.01)return[k,w]}}},o=[];for(let h of t){let u=!1;for(let d of h.inner?.length?[]:r){let m=i(d.region,h);if(!m)continue;let[g,p]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+g,dy:d.oy+p}),d.region=k0(d.region,n0(s(h).map(y=>y.map(([b,x])=>[b+g,x+p])),e,"miter"));let v=c(h);v.length&&r.push({host:d.host,ox:d.ox+g,oy:d.oy+p,region:v}),u=!0;break}if(u)continue;o.push(h);let f=c(h);f.length&&r.push({host:h,ox:0,oy:0,region:f})}return o}function Hi(t,e,n,r){let c=new Map;for(let i of t)c.set(i.info,[...c.get(i.info)??[],i]);let a=[],s=(i,o)=>u3({layers:i,parts:[]},o).layers;for(let[,i]of c){let o=i[0],l=i1([...o.layers].filter(([d])=>n(d)).flatMap(([,d])=>d.regions.filter(m=>M1(m)>0))),h=l.reduce((d,m)=>d+M1(m),0)/(o.w*o.h),u=i.length>=2&&l.length&&h<.75?Oi(l,o.w,o.h,e,r):void 0;if(!u){a.push(...i);continue}let f=s(o.layers,[-1,0,0,-1,o.w,o.h]);for(let d=0;d<i.length;d+=u.n){let m=i.slice(d,d+u.n);if(m.length===1){a.push(m[0]);continue}let g=u.at.slice(0,m.length),p=Math.min(...g.map(x=>x[0])),v=Math.min(...g.map(x=>x[1])),y=Math.max(...g.map(x=>x[0]+o.w))-p,b=Math.max(...g.map(x=>x[1]+o.h))-v;a.push({...m[0],layers:s(m[0].layers,[1,0,0,1,g[0][0]-p,g[0][1]-v]),w:y,h:b,inner:m.slice(1).map((x,M)=>({item:{...x,layers:(M+1)%2?f:x.layers},dx:g[M+1][0]-p,dy:g[M+1][1]-v}))})}}return a}function Oi(t,e,n,r,c){let s=n0(t.map(b=>Fi(b,.25)).filter(b=>b.length>=3),.25,"miter"),i=n0(s,r,"miter"),o=s.map(b=>b.map(([x,M])=>[e-x,n-M])),l=(b,[x,M])=>b.map(w=>w.map(([k,z])=>[k+x,z+M])),h=(b,x)=>!a0(b,x).some(M=>Math.abs(M1(M))>.001),u=(b,x,M,w)=>{let[k,z]=[0,w];if(h(b,l(x,M(z)))){if(h(b,l(x,M(k))))return M(k);for(let S=0;S<10;S++){let A=(k+z)/2;h(b,l(x,M(A)))?z=A:k=A}return M(z)}},f;for(let b of[!1,!0])for(let x=-10;x<=10;x++){let M=x/10*(b?e:n),w=u(i,o,S=>b?[M,S]:[S,M],(b?n:e)+r);if(!w)continue;let k=Math.max(e,w[0]+e)-Math.min(0,w[0]),z=Math.max(n,w[1]+n)-Math.min(0,w[1]);k>c[0]||z>c[1]||k*z<.85*2*e*n&&(!f||k*z<f.area)&&(f={d:w,across:b,area:k*z})}if(!f)return;let{d,across:m}=f,g=i1([...i,...n0(l(o,d),r,"miter")]),v=u(g,s,b=>m?[0,b]:[b,0],2*((m?n:e)+r)+Math.abs(m?d[1]:d[0])),y=[[0,0],[d[0],d[1]]];if(v){let b=x=>Math.max(...x.map(M=>M[0]+e))-Math.min(...x.map(M=>M[0]))<=c[0]&&Math.max(...x.map(M=>M[1]+n))-Math.min(...x.map(M=>M[1]))<=c[1];for(let x=2;x<500;x++){let M=Math.floor(x/2),w=x%2?[d[0]+M*v[0],d[1]+M*v[1]]:[M*v[0],M*v[1]];if(!b([...y,w]))break;let k=l(x%2?o:s,w),z=i1(y.slice(Math.max(0,y.length-3)).map((S,A,L)=>{let C=y.length-L.length+A;return n0(l(C%2?o:s,S),r,"miter")}).flat());if(!h(z,k))break;y.push(w)}}return{at:y,n:y.length}}function Fi(t,e){if(t.length<8)return t;let n=i=>{let o=new Uint8Array(i.length);o[0]=o[i.length-1]=1;let l=[[0,i.length-1]];for(;l.length;){let[h,u]=l.pop(),[f,d]=i[h],[m,g]=i[u],p=Math.hypot(m-f,g-d),v=-1,y=-1;for(let b=h+1;b<u;b++){let[x,M]=i[b],w=p?Math.abs((m-f)*(d-M)-(f-x)*(g-d))/p:Math.hypot(x-f,M-d);w>v&&([v,y]=[w,b])}v>e&&(o[y]=1,l.push([h,y],[y,u]))}return i.filter((h,u)=>o[u])},r=i=>Math.hypot(i[0]-t[0][0],i[1]-t[0][1]),c=1;for(let i=2;i<t.length;i++)r(t[i])>r(t[c])&&(c=i);let a=n(t.slice(0,c+1)),s=n([...t.slice(c),t[0]]);return[...a,...s.slice(1,-1)]}function w6(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 Ri(t,e,n){let r=[...n.keys()],c=[...e.keys()].filter(i=>n.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),a=[];if(c.length<2)return a;let s=i=>i==="engrave"?-1/0:(n.get(i)?.order??0)*2+r.indexOf(i)/r.length;c.sort((i,o)=>s(i)-s(o));for(let i=0;i<c.length-1;i++){let o=n.get(c[i]).side??"front",l=c.slice(i+1).filter(u=>(n.get(u).side??"front")===o);if(!l.length)continue;let h;for(let u of F0(e.get(c[i]).regions)){let f=u.reduce((M,w)=>M+M1(w),0);if(!(f>.001)||!n0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=k0(d,e.get(M).regions));if(d.reduce((M,w)=>M+M1(w),0)>.001*Math.max(1,f))continue;let g=l.filter(M=>a0(u,e.get(M).regions).length),p=g.length?g:l;if(h){h.count++;for(let M of p)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=X0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:c[i],under:p,count:1,at:[m0((v+b)/2),m0((y+x)/2)]}}h&&a.push(h)}return a}function $i(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 Di(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 i=s.placements.map(Q0),o=c.glue.face==="top"?s.thickness:-c.thickness,l=c.placements.length/(c.stack??1);c.placements=c.placements.map((h,u)=>{let f=i.length===l?i[Math.floor(u/(c.stack??1))]:i[0];return{...h,matrix:q1(f,q1(B0(0,0,o),Q0(h)))}}),n.add(c)};for(let c of t)r(c,[])}function qi(t,e,n,r){let c=0,a=50;for(let g=0;g<14;g++){let p=(c+a)/2;n0(t,-p,"round").length?c=p:a=p}if(c<1)return[];let s=n0(t,-c*.98,"round"),i=X0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((g,p)=>s.reduce((v,y)=>v+(_8(y,g,p)?M1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((g,p)=>M1(p)>M1(g)?p:g)[0]);let u=Math.min(6,Math.max(2,c*.9)),f=F4(n,e,{size:u,font:r,halign:"center",valign:"center",spacing:1}),d=X0(new Map([["t",{regions:f,lines:[]}]])),m=d?Math.min(1,1.6*c/Math.max(d[2]-d[0],1e-9)):1;return f.map(g=>g.map(([p,v])=>[o-p*m,l+v*m]).reverse())}function _8(t,e,n){let r=!1;for(let c=0,a=t.length-1;c<t.length;a=c++){let[s,i]=t[c],[o,l]=t[a];i>n!=l>n&&e<(o-s)*(n-i)/(l-i)+s&&(r=!r)}return r}function G8(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=G8(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 j8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function Ni(t){let{program:e,comments:n}=m2(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=[];for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let o=G8(i.value);if(!o.ok)continue;let l=r.filter(g=>g.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(l.toLowerCase()==="hidden")continue;let h=c.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},m=h?/^\[(.*)\](\s+drive)?$/.exec(h.trim()):null;if(m?.[2]&&d.type==="number"&&typeof f=="number"&&(d.drive=!0),m){let g=m[1];if(g.includes(",")||/[a-zA-Z"]/.test(g)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(g))d.options=g.split(",").map(p=>{let[v,y]=p.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=j8(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let p=g.split(":").map(j8);p.every(v=>v!==void 0)&&(p.length===1?d.max=p[0]:p.length===2?(d.min=p[0],d.max=p[1]):(d.min=p[0],d.step=p[1],d.max=p[2]))}}s.push(d)}return{parameters:s}}var Ui=8,Bi=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,_i=(t,e)=>Math.max(1,Bi.exec(t.slice(e-1))?.[0].length??1);function ji(t,e,n={}){if(!(t instanceof l1))return`error: ${t instanceof Error?t.message:String(t)}`;let r=n.file??"design.kerf",c=(o,l,h)=>`${o?`<${o}>`:r}:${l}:${h}`,a=o=>o===void 0?e:(Object.prototype.hasOwnProperty.call(P5,o)?P5[o]:void 0)??n.resolve?.(o),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(`
|
|
2646
|
+
`)?.[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=_i(l,t.col),m=f.replace(/[^\t]/g," ");s.push(`${u} |`,`${h} | ${l}`,`${u} | ${m}${"^".repeat(d)}`)}}for(let o of Gi(t,c))s.push(` = ${o}`);let i=t.call?C5(t.call):void 0;return i&&s.push(` = ${$e(i)}: ${i.doc}`),s.join(`
|
|
2647
|
+
`)}function Gi(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,Ui).map(n),c=t.trace.length-r.length+t.traceMore;return c&&r.push(`and ${c} more call${c===1?"":"s"}`),r}var W8=new Set(["module","function","if","else","for","let","each","use","include"]),Wi=new Set(["true","false","undef"]),Xi=new Set(["for","if","let","function"]),S6={"(":")","[":"]","{":"}"},Zi=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function Yi(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 L6(t){let{tokens:e}=S5(t),n=[],r=0,c=0,a=s=>{for(;r<s;)if(t[r]===`
|
|
2648
|
+
`)c++,r++;else if(t.startsWith("//",r)){let i=t.indexOf(`
|
|
2649
|
+
`,r),o=i<0?t.length:i;n.push({kind:"line",text:t.slice(r,o).trimEnd(),breaks:c}),[c,r]=[0,o]}else if(t.startsWith("/*",r)){let i=t.indexOf("*/",r+2)+2,o=t.slice(r,i).replace(/[ \t\r]+\n/g,`
|
|
2650
|
+
`);n.push({kind:"block",text:o,breaks:c}),[c,r]=[0,i]}else r++};for(let s of e){if(a(s.pos.offset),s.type==="eof")break;let i=Yi(t,s);n.push({kind:"token",text:i,token:s,breaks:c}),c=0,r=s.pos.offset+i.length}return n}function A6(t,e={}){m2(t);let n=" ".repeat(e.indent??2),r=L6(t),c=[],a=null,s=-1,i=0,o=[],l=0,h=!0,u=0,f=!1,d=0,m=0,g,p,v=()=>o[o.length-1],y=()=>!v()||v().open==="{"&&!v().record,b=z=>z.kind==="token"&&!!v()&&z.text===S6[v().open],x=(z,S)=>{a!==null&&c.push(a.trimEnd()),S&&c.length&&c[c.length-1]!==""&&c.push(""),s++,i=z,a=n.repeat(z),p=void 0},M=z=>{if(b(z))return v().outer;if(!y())return!g||g.text===","||S6[g.text]?v().inner:g.role==="header"?m+1:v().inner+1;let S=v()?v().inner:0;return h?S:f?u+1:d+1},w=z=>r.slice(z).find(S=>S.kind==="token");for(let z=0;z<r.length;z++){let S=r[z],A=s<0||S.breaks>0;if(S.kind!=="token"){if(A){let P=w(z),R=P?b(P)?v().inner:M(P):0;x(R,S.breaks>1&&s>=0)}else a+=" ";a+=S.text,p=S;continue}let L=S.text,C=S.token.type;if("*!#%".includes(L)&&y()&&!f&&(h||g?.text===")"||g?.text==="else")?S.role="modifier":(L==="!"||(L==="-"||L==="+")&&(!g||Ji(g)))&&(S.role="unary"),L===":"){let P=v();(P?P.ternaries:l)?P?P.ternaries--:l--:P?.open==="["&&(S.role="range")}if((L==="}"&&v()?.record||L==="{"&&g&&["=","(",",","[","?",":"].includes(g.text))&&(S.role="record"),A){let P=M(S);x(P,S.breaks>1&&s>=0),y()&&!b(S)&&(d=P)}else p&&Ki(p,S)&&(a+=" ");if(y()&&h&&!b(S)&&(u=i,f=C==="id"&&r[z+1]?.kind==="token"&&r[z+1].text==="="||L==="function",h=!1),a+=L,S6[L]){let P=v(),R=S.role==="record",q=P&&P.line===s&&(P.open!=="{"||P.record)&&(L!=="{"||R);o.push({record:R,open:L,outer:i,inner:q?P.inner:i+1,line:s,ternaries:0,header:L==="("&&!!g&&Xi.has(g.text)&&g.token?.type==="id"}),L==="{"&&!R&&(h=!0)}else if(b(S)){let P=o.pop();P.header&&(S.role="header",m=P.outer),L==="}"&&!P.record&&(h=!0)}else L===";"&&y()||C==="str"&&L.startsWith("<")&&y()?h=!0:L==="?"&&(v()?v().ternaries++:l++);g=S,p=S}for(a!==null&&c.push(a.trimEnd());c.length&&c[c.length-1]==="";)c.pop();let k=c.length?c.join(`
|
|
2235
2651
|
`)+`
|
|
2236
|
-
`:"";return
|
|
2237
|
-
<h2><span>${m}</span> ${
|
|
2238
|
-
<div class="view">${
|
|
2239
|
-
${
|
|
2652
|
+
`:"";return Qi(t,k),k}var Ji=t=>Zi.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&W8.has(t.text)||t.role==="unary"||t.role==="modifier";function Ki(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"&&(!W8.has(n)||Wi.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=L6(t),r=L6(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 X8(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=o=>o.map(([l,h])=>[l-c,a-h]),i=new Map;for(let[o,l]of r.layers)i.set(o,{regions:l.regions.map(s),lines:l.lines.map(s)});e.set(`${r.part}\0${r.copy}`,i)}return e}var Z8=t=>Math.round(t*100)/100,q4=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function eo(t,e,n=.01){let r=X8(t),c=X8(e),a=[],s=i=>{let[o,l]=i.split("\0");return{part:o,copy:Number(l)}};for(let i of new Set([...r.keys(),...c.keys()])){let o=r.get(i),l=c.get(i);if(!o||!l){a.push({...s(i),change:o?"removed":"added"});continue}for(let h of new Set([...o.keys(),...l.keys()])){let u=o.get(h)??{regions:[],lines:[]},f=l.get(h)??{regions:[],lines:[]},d=h3(u.regions,f.regions),m=d.reduce((x,M)=>x+Math.abs(M1(M)),0),g=new Set(u.lines.map(q4)),p=new Set(f.lines.map(q4)),v=u.lines.filter(x=>!p.has(q4(x))),y=f.lines.filter(x=>!g.has(q4(x)));if(m<=n&&!v.length&&!y.length)continue;let b=X0(new Map([[h,{regions:m>n?d:[],lines:[...v,...y]}]]));a.push({...s(i),layer:h,change:o.has(h)?l.has(h)?"changed":"removed":"added",...m>n&&{area:Z8(m)},...v.length&&{linesRemoved:v.length},...y.length&&{linesAdded:y.length},...b&&{at:b.map(Z8)}})}}return a}var to=[Math.SQRT1_2,Math.SQRT1_2,0],no=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],C6=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],ro=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),Y3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Y8=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],co=(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]],ao=(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]],U2=t=>t.replace(/[&<>"]/g,e=>({"&":"&","<":"<",">":">",'"':"""})[e]);function J8(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 so(t,e,n){let r=(i,o,l)=>ao(t.matrix,t.bends?.length?Ae(t.bends,t.thickness,[i,o,l]):[i,o,l]),c=[],a=(i,o)=>{if(i.length<3)return;let l=co(Y8(i[1],i[0]),Y8(i[2],i[0])),h=[0,0,0];for(let m=0;m<i.length;m++){let g=i[m],p=i[(m+1)%i.length];h[0]+=(g[1]-p[1])*(g[2]+p[2]),h[1]+=(g[2]-p[2])*(g[0]+p[0]),h[2]+=(g[0]-p[0])*(g[1]+p[1])}let u=Math.hypot(...h)||Math.hypot(...l);if(!u)return;let f=[h[0]/u,h[1]/u,h[2]/u];if(Y3(f,C6)<=0)return;let d=i.reduce((m,g)=>[m[0]+g[0],m[1]+g[1],m[2]+g[2]],[0,0,0]);c.push({pts:i,holes:o,color:J8(e,.55+.45*Math.max(0,Y3(f,ro))),depth:Y3([d[0]/i.length,d[1]/i.length,d[2]/i.length],C6),stroke:n})},s=t.thickness;for(let i of Ce(t.outline,t.bends)){let o=u=>u.reduce((f,d,m)=>f+d[0]*u[(m+1)%u.length][1]-u[(m+1)%u.length][0]*d[1],0),l=i.find(u=>o(u)>0)??i[0],h=i.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 i)for(let f=0;f<u.length;f++){let[d,m]=u[f],[g,p]=u[(f+1)%u.length];a([r(d,m,0),r(g,p,0),r(g,p,s),r(d,m,s)])}}return c}function io(t,e){let n=typeof t.size=="number"?t.size:Math.max(...t.size),r=[(t.from[0]+t.to[0])/2,(t.from[1]+t.to[1])/2,(t.from[2]+t.to[2])/2];return[{pts:[t.from,t.to],color:e,depth:Y3(r,C6)+n/2,stroke:String(n)}]}function oo(t,e=640,n=420){let r=g=>[Y3(g,to),-Y3(g,no)],c=1/0,a=1/0,s=-1/0,i=-1/0;for(let g of t)for(let p of g.pts){let[v,y]=r(p);c=Math.min(c,v),s=Math.max(s,v),a=Math.min(a,y),i=Math.max(i,y)}if(!Number.isFinite(c))return"";let o=Math.max(s-c,i-a)*.04+1,l=Math.min(e/(s-c+2*o),n/(i-a+2*o)),h=g=>{let[p,v]=r(g);return`${((p-c+o)*l).toFixed(1)} ${((v-a+o)*l).toFixed(1)}`},u=g=>`M${g.map(h).join("L")}Z`,f=[...t].sort((g,p)=>g.depth-p.depth).map(g=>g.pts.length===2?`<path d="M${h(g.pts[0])}L${h(g.pts[1])}" stroke="${g.color}" stroke-width="${(Number(g.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(g.pts)}${(g.holes??[]).map(u).join("")}" fill="${g.color}" fill-rule="evenodd" stroke="${g.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((s-c+2*o)*l).toFixed(0),m=((i-a+2*o)*l).toFixed(0);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d} ${m}" width="${d}" height="${m}">${f.join("")}</svg>`}var lo="#d9bf91",ho="#cfc6b8",uo="#e08a3c";function fo(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=>L5[f]??q3[f]?.color??"#9a9a9a",i=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",o=[],l=r.filter(f=>a(f.step)===0);c.forEach((f,d)=>{let m=d+1,g=[];for(let y of r){let b=a(y.step);b>m||g.push(...so(y,b===m?uo:y.step===void 0&&!t.steps.length?lo:ho,b===m?"#7a3e0c":"#8a8274"))}for(let y of t.hardware){let b=t.steps.length?y.step:1;b<=m&&g.push(...io(y,b===m?s(y.kind):J8(s(y.kind),.8)))}let p=new Map;for(let y of r)a(y.step)===m&&p.set(y.name,(p.get(y.name)??0)+1);let v=new Map;for(let y of t.hardware)if((t.steps.length?y.step:1)===m){let b=typeof y.size=="number"?`${y.size} mm`:`${y.size[0]} x ${y.size[1]} mm`,x=Math.round(Math.hypot(y.to[0]-y.from[0],y.to[1]-y.from[1],y.to[2]-y.from[2])),M=`${y.label?`${U2(y.label)}: `:""}${U2(y.kind)}, ${b}, ${x} mm long`;v.set(M,(v.get(M)??0)+1)}o.push(`<section>
|
|
2653
|
+
<h2><span>${m}</span> ${U2(f)}</h2>
|
|
2654
|
+
<div class="view">${oo(g)}</div>
|
|
2655
|
+
${p.size?`<h3>Parts</h3>${i([...p].sort((y,b)=>(n.get(y[0])??0)-(n.get(b[0])??0)).map(([y,b])=>`<b>${n.get(y)??""}</b> ${U2(y)}${b>1?` × ${b}`:""}`))}`:""}
|
|
2240
2656
|
${v.size?`<h3>Hardware</h3>${i([...v].map(([y,b])=>`${y}${b>1?` × ${b}`:""}`))}`:""}
|
|
2241
|
-
</section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${
|
|
2657
|
+
</section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${U2(f.name)}${f.mirrored?" (mirrored)":""}</td><td>${f.qty}</td><td>${f.width} × ${f.height} mm</td><td>${f.thickness} mm ${U2(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 ${U2(f.material)}</figcaption></figure>`).join("");return`<!doctype html>
|
|
2242
2658
|
<html lang="en">
|
|
2243
2659
|
<head>
|
|
2244
2660
|
<meta charset="utf-8">
|
|
2245
2661
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2246
|
-
<title>${
|
|
2662
|
+
<title>${U2(e)}: assembly</title>
|
|
2247
2663
|
<style>
|
|
2248
2664
|
body { font: 15px/1.45 system-ui, sans-serif; color: #222; margin: 24px auto; max-width: 760px; padding: 0 16px; }
|
|
2249
2665
|
h1 { font-size: 26px; margin: 0 0 4px; }
|
|
@@ -2260,8 +2676,8 @@ figure { margin: 12px 0; } figcaption { color: #666; font-size: 13px; }
|
|
|
2260
2676
|
</style>
|
|
2261
2677
|
</head>
|
|
2262
2678
|
<body>
|
|
2263
|
-
<h1>${
|
|
2264
|
-
<p class="note">${t.parts.reduce((f,d)=>f+d.qty,0)} parts on ${t.sheets.length} sheet${t.sheets.length===1?"":"s"}, ${
|
|
2679
|
+
<h1>${U2(e)}</h1>
|
|
2680
|
+
<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>
|
|
2265
2681
|
<h3>Parts</h3>
|
|
2266
2682
|
<table><tr><th>#</th><th>Part</th><th>Qty</th><th>Size</th><th>Material</th></tr>${h}</table>
|
|
2267
2683
|
${u}
|
|
@@ -2269,46 +2685,46 @@ ${o.join(`
|
|
|
2269
2685
|
`)}
|
|
2270
2686
|
</body>
|
|
2271
2687
|
</html>
|
|
2272
|
-
`}var
|
|
2273
|
-
`).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+=pt(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]]=pt(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"}},ie={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"},wi=Object.fromEntries(Object.entries(ie).reverse().map(([t,e])=>[e,t]));function C5(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(ie[t])return ie[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)=>T3(t,Math.PI/12,e),P5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function zi(t){let e=r6;if(!t)return e;for(let[,n,c]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let r=P5(c),a=(r[0]??0)*Math.PI/180,s=r6;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 ki(t,e){let n=[],c=[],r=[0,0],a=[0,0],s=(l,h)=>a5(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 Si=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],Li=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function vt(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 Ai(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,c]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let r=vt(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 Ci(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 se(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])*Ci(n[2].toLowerCase(),e)}var Pi=/^(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 Ei(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Pi.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Ti(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 yt(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=gt(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=P5(c.attrs.viewBox??""),o=se(c.attrs.width,s),l=se(c.attrs.height,s),h=25.4/s,u=h,f=h,d=0,m=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],m=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 p=l??(i.length===4?i[3]*f:0),g=w3([1,0,0,-1,0,p],[u,0,0,f,-d*u,-m*f]),v=[],y=new Map,b=P=>{P.name==="style"&&v.push(...Ai(P.text)),P.attrs.id&&y.set(P.attrs.id,P),P.children.forEach(b)};b(c);let x=(P,Y)=>{let X={};for(let a1 of Object.keys(Y))Li.has(a1)&&(X[a1]=Y[a1]);for(let a1 of Si)P.attrs[a1]!==void 0&&(X[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(R1=>b1.includes(R1))&&Object.assign(X,a1.decls);return P.attrs.style&&Object.assign(X,vt(P.attrs.style)),X},M=[],S=[],w=0,z=0,C=0,k=0,T=0,q=0,R=2e4,U=[],j=P=>Number.isFinite(P[0])&&Number.isFinite(P[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],Q=P=>[...V,"x1","y1","x2","y2","points"].some(Y=>P.attrs[Y]!==void 0&&P5(P.attrs[Y]).some(X=>!Number.isFinite(X))),W=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),o1=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),m1=P=>{let Y=X=>parseFloat(P.attrs[X]??"0")||0;switch(P.name){case"path":return B3(P.attrs.d??"",()=>C++);case"rect":{let[X,b1,a1,R1]=[Y("x"),Y("y"),Y("width"),Y("height")];if(a1<=0||R1<=0)return[];let e1=P.attrs.rx!==void 0?Y("rx"):P.attrs.ry!==void 0?Y("ry"):0,T1=P.attrs.ry!==void 0?Y("ry"):e1;return e1=Math.min(Math.abs(e1),a1/2),T1=Math.min(Math.abs(T1),R1/2),e1<=0||T1<=0?B3(`M${X} ${b1}H${X+a1}V${b1+R1}H${X}Z`):B3(`M${X+e1} ${b1}H${X+a1-e1}A${e1} ${T1} 0 0 1 ${X+a1} ${b1+T1}V${b1+R1-T1}A${e1} ${T1} 0 0 1 ${X+a1-e1} ${b1+R1}H${X+e1}A${e1} ${T1} 0 0 1 ${X} ${b1+R1-T1}V${b1+T1}A${e1} ${T1} 0 0 1 ${X+e1} ${b1}Z`)}case"circle":case"ellipse":{let[X,b1]=[Y("cx"),Y("cy")],a1=P.name==="circle"?Y("r"):Y("rx"),R1=P.name==="circle"?Y("r"):P.attrs.ry!==void 0?Y("ry"):a1;return a1<=0||R1<=0?[]:B3(`M${X+a1} ${b1}A${a1} ${R1} 0 0 1 ${X} ${b1+R1}A${a1} ${R1} 0 0 1 ${X-a1} ${b1}A${a1} ${R1} 0 0 1 ${X} ${b1-R1}A${a1} ${R1} 0 0 1 ${X+a1} ${b1}Z`)}case"line":return B3(`M${Y("x1")} ${Y("y1")}L${Y("x2")} ${Y("y2")}`);case"polyline":case"polygon":{let X=P5(P.attrs.points??"");if(X.length<4)return[];let b1=`M${X[0]} ${X[1]}`;for(let a1=2;a1+1<X.length;a1+=2)b1+=`L${X[a1]} ${X[a1+1]}`;return B3(P.name==="polygon"?b1+"Z":b1)}}},I=P=>(P.text+P.children.map(Y=>Y.name==="tspan"?" "+I(Y):"").join("")).replace(/\s+/g," ").trim(),$=(P,Y,X,b1,a1,R1)=>{if(R1>64||W.has(P.name)||T&&++q>R)return;let e1=x(P,X);if(e1.display==="none"||e1.visibility==="hidden"||e1.opacity==="0"){(P.children.length||o1.has(P.name))&&z++;return}let T1=w3(Y,zi(P.attrs.transform));if(!T1.every(Number.isFinite)){k++;return}let r0=Ei(P),A=P.attrs["inkscape:groupmode"]==="layer",G=b1;if(P.name==="g"||P.name==="svg"||P.name==="a"||P.name==="switch"){let B1=P.attrs["inkscape:label"]??P.attrs["data-name"]??P.attrs.id,l1=Ti(B1);if(P.attrs["data-mode"]&&B1&&/^(cut|line|fill|guide)$/.test(P.attrs["data-mode"])){let g1=C5(e1.stroke,"#000000"),d1=C5(e1.fill,"#000000"),v1=P.attrs["data-mode"]==="fill"?d1:g1;G=t2[B1]??{name:B1,mode:P.attrs["data-mode"],color:v1&&v1.startsWith("#")?v1:"#00aa00"}}else l1&&(G=l1);if(P!==c&&P.name==="svg"){let g1=d1=>parseFloat(P.attrs[d1]??"0")||0;T1=w3(T1,[1,0,0,1,g1("x"),g1("y")])}let M1=A||l1||P===c||!r0?a1:[r0,...a1];U.push(P);for(let g1 of P.children)$(g1,T1,e1,G,M1,R1+1);U.pop();return}if(P.name==="use"){let B1=y.get((P.attrs.href??P.attrs["xlink:href"]??"").replace(/^#/,""));if(!B1||U.includes(B1))return;let l1=d1=>parseFloat(P.attrs[d1]??"0")||0,M1=w3(T1,[1,0,0,1,l1("x"),l1("y")]),g1=B1.name==="symbol"?{...B1,name:"g"}:B1;U.push(B1),T++,$(g1,M1,e1,G,r0?[r0,...a1]:a1,R1+1),T--,U.pop();return}if(P.name==="image"){w++;return}let N=C5(e1.color,"#000000")??"#000000",s1=parseFloat(e1["stroke-width"]??"1"),K=C5(e1.stroke,N);K&&(s1===0||e1["stroke-opacity"]==="0")&&(K="none");let S1=C5(e1.fill??"black",N);if(e1["fill-opacity"]==="0"&&(S1="none"),P.name==="text"){let B1=I(P);if(!B1)return;let l1=P.children.find(l0=>l0.name==="tspan"),M1=l0=>P5(P.attrs[l0]??l1?.attrs[l0]??"0")[0]??0,g1=a5(T1,[M1("x"),M1("y")]),d1=Math.sqrt(Math.abs(T1[0]*T1[3]-T1[1]*T1[2])),v1=(se(e1["font-size"],96)??16*h)/h;if(!j(g1)||!Number.isFinite(v1*d1)){k++;return}let N1=e1["text-anchor"];S.push({text:B1,at:g1,size:v1*d1,angle:Math.atan2(-T1[1],T1[0])*180/Math.PI,font:(e1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:N1==="middle"?"center":N1==="end"?"right":"left",stroke:K,fill:S1,layer:G});return}if(P.name!=="path"&&Q(P)){k++;return}let Y1=m1(P);if(!Y1){for(let B1 of P.children)$(B1,T1,e1,G,a1,R1+1);return}let G1=ki(Y1,T1),A1=G1.filter(B1=>B1.segs.every(l1=>j(l1.a)&&j(l1.b)&&(l1.c==="L"||j(l1.p1)&&j(l1.p2))));A1.length<G1.length&&k++,A1.length&&M.push({subs:A1,stroke:K,fill:P.name==="line"||P.name==="polyline"?"none":S1,fillRule:e1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:G,names:r0?[r0,...a1]:a1})};$(c,g,{},void 0,[],0),w&&r.push(`${w} embedded image${w===1?" was":"s were"} left out: trace ${w===1?"it":"them"} to paths first.`),z&&r.push(`${z} hidden element${z===1?" was":"s were"} left out.`),C&&r.push(`${C} path${C===1?" has":"s have"} bad data: read up to the error, as browsers draw ${C===1?"it":"them"}.`),k&&r.push(`${k} element${k===1?" was":"s were"} left out: ${k===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 Z=P=>{let[Y,X,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return Y>=200&&X<=80&&b1<=80},_=P=>{let[Y,X,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return b1>=200&&Y<=80&&X<=80},L1=P=>!!P.stroke&&P.stroke!=="none",W1=M.filter(P=>!P.layer),E1=new Map;for(let P of W1)L1(P)&&P.stroke.startsWith("#")&&E1.set(P.stroke,(E1.get(P.stroke)??0)+P.subs.length);let Z1=[...E1.keys()],m0=Z1.filter(Z),o0=new Set(m0.length?m0:Z1.length?[Z1.reduce((P,Y)=>(E1.get(Y)??0)>(E1.get(P)??0)?Y:P)]:[]),L=M.some(P=>L1(P)&&!P.layer)||M.some(P=>P.layer),F=new Map,t1=(P,Y)=>{if(P&&P!=="none"){let X=P.startsWith("#")?P:"#000000";if(o0.has(X))return t2.cut;if(X==="#00a0ff")return t2.guide;if(_(X))return t2.score;if(!F.has(X)){let b1=wi[X]??"color_"+X.slice(1);F.set(X,{name:b1,mode:"line",color:X})}return F.get(X)}if(Y&&Y!=="none")return L?t2.engrave:t2.cut};!L&&M.some(P=>P.fill&&P.fill!=="none")?r.push("The file has filled shapes and no strokes: the shapes are cut out."):!m0.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 X=!P.layer&&Y===t2.cut&&!L1(P);r1.push({subs:P.subs,layer:Y,fillRule:P.fillRule,names:P.names,filled:X})}let y1=[];for(let P of S){let Y=P.layer??t1(P.fill!=="none"?void 0:P.stroke,P.fill);Y&&y1.push({...P,layer:Y.mode==="cut"&&L?t2.engrave:Y})}return{items:r1,texts:y1,notes:r}}var O1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),h2=([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]},le=(t,e)=>[t[0]+e[0],t[1]+e[1]],u2=(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=O1(c.a,c.p1)+O1(c.p1,c.p2)+O1(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&&O1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function M2(t,e=!0){let n=0;for(let c=1;c<t.length;c++)n+=O1(t[c-1],t[c]);return e&&t.length>2?n+O1(t[t.length-1],t[0]):n}function H2(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(O1(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(O1(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),m=Math.floor(Math.max(u[0],f[0])/c),p=Math.floor(Math.min(u[1],f[1])/c),g=Math.floor(Math.max(u[1],f[1])/c);for(let v=d;v<=m;v++)for(let y=p;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(O1(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[m,p]of this.cells.get(`${f},${d}`)??[])if(xt(s,i,m,p)<=c)return!0}return!1}};function xt(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 Ii(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]+O1(t[h-1],t[h%c]));let a=r[c],s=k0([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),m=Math.floor((Math.max(h[0],u[0])+e)/i),p=Math.floor((Math.min(h[1],u[1])-e)/i),g=Math.floor((Math.max(h[1],u[1])+e)/i);if((m-d+1)*(g-p+1)>4096)return null;for(let v=d;v<=m;v++)for(let y=p;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 m of d)for(let p of o.get(m)??[]){let g=Math.abs(r[h]-r[p]);if(!(Math.min(g,a-g)-O1(u,f)-O1(t[p],t[(p+1)%c])<n)&&xt(u,f,t[p],t[(p+1)%c])<=e)return!0}for(let m of d){let p=o.get(m);p?p.push(h):o.set(m,[h])}}return!1}function Mt(t,e){let n=t.map(()=>!1),c=[],r=t.map(l=>k0([l]));t.forEach((l,h)=>{let u=w1([l]),f=u.reduce((p,g)=>p+H1(g),0),d=M2(l),m=u.reduce((p,g)=>p+M2(g),0);(u.length!==1||Math.abs(f-Math.abs(H1(l)))>d*.001+1e-6||Math.abs(m-d)>d*.001+.05||Ii(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 m=o.length-1;m>=0;m--)r[o[m]][2]<h-e&&o.splice(m,1);for(let m of o){let p=r[m];if(p[1]>d+e||p[3]<u-e)continue;let[g,v]=t[l].length<=t[m].length?[l,m]:[m,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,m]);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 H2(i,c,r))if(!s.near(o,n))return!1;for(let i of e)for(let o of H2(i,c,r))if(!a.near(o,n))return!1;return!0}function wt(t,e,n){let c=new h3([t,...e],!0,Math.max(n*4,1)),r=a=>V2(a,t)&&!e.some(s=>V2(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=O1(h,u),d=Math.min(n*3,f/3)/f,m=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,p=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(c.meets(m,p,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?r(o):!0}}function zt(t,e,n){if(!t.length)return!1;let c=new h3([e],!0,Math.max(n*4,1));return t.some(r=>H2(r,!1,Math.max(n*2,.2)).some(a=>c.near(a,n)))}function V2(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 A4(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,m=(f*s-d*a)/u,p=(d*r-f*a)/u;return{c:[m+n,p+c],r:Math.sqrt(m*m+p*p+(r+s)/e)}}function G3(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)O1(t[0],t[o])>O1(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 kt(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=G3(a,.002),i=s.length,o=s.findIndex((u,f)=>O1(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],m=s[(f+1)%i];if(O1(d,m)<.3){h.length||h.push(d),h.push(m);continue}if(h.length>=3){let p=A4(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]);p&&p.r>.005&&p.r<.6&&(b>0===l?e:n).push(p.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 he(t,e){let n=t.length,c=i=>O1(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 m=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(m)>1e-12){let p=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/m,g=[l[0]+p*(h[0]-l[0]),l[1]+p*(h[1]-l[1])],v=t[(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?A4(y):{c:g,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&O1(g,v)<=e*2&&p>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let m=1;m<=o;m++)a.push(t[(s+m)%n]);s=i}while(s!==r);return a}function P1(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 k1=t=>String(P1(t)),n0=t=>`[${k1(t[0])}, ${k1(t[1])}]`;function Vi(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 w2(t,e,n){let c=[];(P1(t[0])!==0||P1(t[1])!==0)&&c.push(`translate(${n0(t)})`);let r=Vi(e);return r!==0&&c.push(`rotate(${r})`),[...c,n].join(" ")}function E5(t,e){return{poly:t,area:Math.abs(H1(t)),box:k0([t]),ends:e?.segs.map(n=>n.a)}}var L4=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function C4(t,e){let n=M2(t.poly),c=H2(t.poly,!0,Math.min(.5,n/256)),r=A4(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(O1(i,r.c)-r.r)>a)return;let s=a+r.r*2e-4;for(let i of c)if(Math.abs(O1(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 = ${k1(r.r*2)})`,at:r.c,angle:0,center:r.c,circle:r,radius:r.r}}function St(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 P4(t,e){let n=M2(t.poly),c=H2(t.poly,!0,Math.min(.5,n/256)),r=St(c),a=c.map(p=>h2(p,-r)),[s,i,o,l]=k0([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[p,g]of a){let v=Math.hypot((p-f[0])/h,(g-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let m=h2(f,r);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${n0([h,u])})`,at:m,angle:r,center:m}}function Lt(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=O1(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 E4(t,e){let n=G3(t.poly,e/4),c=Lt(n),r=M2(t.poly),a=H2(t.poly,!0,Math.min(.5,r/256)).map(y=>h2(y,-c)),[s,i,o,l]=k0([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=>O1(b,y)))*f),m=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;m<e&&(m=0),m=Math.min(m,h/2,u/2);let p=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-p[0])-(h/2-m),M=Math.abs(b-p[1])-(u/2-m),S=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-m;if(Math.abs(S)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*m*m))>r*e)return;let g=h2(p,c),v=P1(m)>0?`, r = ${k1(m)}`:"";return{kind:"rect",radius:m,body:`rect(${n0([h,u])}, center = true${v})`,at:g,angle:c,center:g,rect:{w:h,h:u,r:m}}}function T4(t,e){let n=G3(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=>O1(u,s)),o=n.map((u,f)=>O1(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((m,p)=>m+p,0)/c,f=360/c,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${c}, ${k1(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,m=f.reduce((x,M)=>x+M,0)/f.length,p=h[0];if(m>d&&([d,m]=[m,d],p=h[1]),d-m<e)return;let g=c/2,v=360/g,y=((p-90)%v+v)%v;v-y<.01&&(y=0);let b=P1(m)===P1(d*.45);return{kind:"star",body:`star(${g}, ${k1(d)}${b?"":`, ${k1(m)}`})`,at:s,angle:y,center:s}}}function Hi(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 m=f[1];Math.abs(m-r)<=n?i[0].push(k4(f[0]-c,d[0]-c)):Math.abs(m-s)<=n?i[2].push(k4(a-f[0],a-d[0])):(o[0].push(m-r),o[2].push(s-m))}else{let m=f[0];Math.abs(m-a)<=n?i[1].push(k4(f[1]-r,d[1]-r)):Math.abs(m-c)<=n?i[3].push(k4(s-f[1],s-d[1])):(o[1].push(a-m),o[3].push(m-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=>Oi(u,n)),depth:h,length:l}}var k4=(t,e)=>t<e?[t,e]:[e,t];function Oi(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 oe=t=>t.reduce((e,[n,c])=>e+c-n,0);function Ri(t,e,n,c,r,a){let s=[L4(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(L4(d-r[h]/2,-a,d+r[h]/2,0).map(i[h]))}}),w1(s)}function ue(t,e,n){let c=G3(t.poly,e/4);if(c.length<8)return;let r=Lt(c),a=c.map(I=>h2(I,-r)),s=e/2;for(let I=0;I<a.length;I++){let $=a[I],Z=a[(I+1)%a.length];if(Math.abs($[0]-Z[0])>s&&Math.abs($[1]-Z[1])>s)return}let i=k0([a]),o=Hi(a,i,s),l=(I,$)=>I.map(Z=>Z.map(_=>le(_,$))),h=(I,$)=>f3([a],l(I,$),e),u=(I,$,Z)=>{let _=h2(I,r);return{kind:"tabs",body:$,at:_,angle:r,center:h2([(i[0]+i[2])/2,(i[1]+i[3])/2],r),...Z}},f=M2(t.poly),d=[0,1,2,3].filter(I=>oe(o.outer[I])<o.length[I]-s);if(!d.length)return;let m=d.map(I=>o.depth[I]).filter(I=>I!==void 0);if(!m.length)return;let p=[...new Set([n,...m].filter(I=>!!I).map(P1))];for(let I of p){let $=P1(i[2]-i[0]),Z=P1(i[3]-i[1]),_=[[]];for(let N=0;N<4;N++){let K=oe(o.outer[N])>=o.length[N]-2*I-s?["flat"]:["out","in"],S1=[];for(let Y1 of _)for(let G1 of K)S1.push([...Y1,G1]);_.splice(0,_.length,...S1)}let L1=Math.max(3*I,6),W1=new Set([L1]);for(let N of d){let s1=o.outer[N].length;for(let K of[2*s1-1,2*s1+1,2*s1-3,2*s1+3])K>=3&&W1.add(P1(o.length[N]/K))}for(let N of W1)for(let s1 of _){if(s1.every(A1=>A1==="flat"))continue;let K=t4($,Z,s1,I,N);if(Math.abs(Math.abs(K.reduce((A1,B1)=>A1+H1(B1),0))-t.area)>f*e||!h(K,[i[0],i[1]]))continue;let Y1=s1.every(A1=>A1===s1[0])?`"${s1[0]}"`:`[${s1.map(A1=>`"${A1}"`).join(", ")}]`,G1=N===L1||[0,1].every(A1=>c3(o.length[A1],N)===c3(o.length[A1],L1));return u([i[0],i[1]],`finger_rect(${n0([$,Z])}, ${Y1}${G1?"":`, finger = ${k1(N)}`})`,{kind:"fingers",thickness:I,edges:s1,finger:G1?L1:N})}let E1=[0,1,2,3].map(N=>d.includes(N)&&o.depth[N]!==void 0&&Math.abs(o.depth[N]-I)<=s);if(!E1.some(Boolean))continue;let Z1=i[0]+(E1[3]?I:0),m0=i[1]+(E1[0]?I:0),o0=P1(i[2]-(E1[1]?I:0)-Z1),L=P1(i[3]-(E1[2]?I:0)-m0),F=[o0,L,o0,L],t1=[E1[3]?I:0,E1[0]?I:0,E1[1]?I:0,E1[2]?I:0],r1=[0,0,0,0],y1=[0,0,0,0],P=!0;for(let N=0;N<4&&P;N++){if(!E1[N])continue;let s1=o.outer[N].map(([K,S1])=>[K-t1[N],S1-t1[N]]);r1[N]=s1.length,y1[N]=s1.length?P1(s1.reduce((K,[S1,Y1])=>K+Y1-S1,0)/s1.length):0,s1.forEach(([K,S1],Y1)=>{(Math.abs((K+S1)/2-F[N]*(Y1+.5)/r1[N])>s||Math.abs(S1-K-y1[N])>s)&&(P=!1)})}if(!P||!h(Ri(o0,L,E1,r1,y1,I),[Z1,m0]))continue;let Y=E1.every(Boolean)?"":`[${E1.join(", ")}]`,X=[0,1,2,3].filter(N=>E1[N]),b1=N=>Math.max(1,Math.round(F[N]/50)),a1=X.every(N=>r1[N]===b1(N)),R1=X.every(N=>r1[N]===r1[X[0]]),e1=a1?void 0:R1?r1[X[0]]:null,T1=X.every(N=>Math.abs(y1[N]-F[N]/(2*r1[N]))<=s),r0=X.every(N=>Math.abs(y1[N]-y1[X[0]])<=s),A=T1?void 0:r0?y1[X[0]]:null,G;if(e1!==null&&A!==null){let N=[n0([o0,L])];Y?N.push(Y):(e1!==void 0||A!==void 0)&&N.push("true"),e1!==void 0&&N.push(`count = ${e1}`),A!==void 0&&N.push(`width = ${k1(A)}`),G=`tab_rect(${N.join(", ")})`}else{let N=[K=>K,K=>`translate(${n0([o0,0])}) rotate(90) ${K}`,K=>`translate(${n0([o0,L])}) rotate(180) ${K}`,K=>`translate(${n0([0,L])}) rotate(270) ${K}`],s1=[`rect(${n0([o0,L])});`];for(let K of X){let S1=[k1(F[K])];r1[K]!==b1(K)&&S1.push(`count = ${r1[K]}`),Math.abs(y1[K]-F[K]/(2*r1[K]))>s&&S1.push(`width = ${k1(y1[K])}`),s1.push(N[K](`tabs(${S1.join(", ")});`))}G=`{
|
|
2274
|
-
${
|
|
2688
|
+
`}var mo={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function K8(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 mo[r]??e[r]??n})}function Q8(t){let e=[],n={},r={name:"#document",attrs:{},children:[],text:""},c=[r],a=0,s=o=>{let l=t.slice(0,a).split(`
|
|
2689
|
+
`).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&&(c[c.length-1].text+=K8(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"),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]]=K8(d[3]??d[4]??"",n)}}}c.length>1&&s(`<${c[c.length-1].name}> is not closed`);let i=r.children[0];if(!i)throw new Error("The file has no elements");return{root:i,comments:e}}var h2={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"}},E6={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"},po=Object.fromEntries(Object.entries(E6).reverse().map(([t,e])=>[e,t]));function N5(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(E6[t])return E6[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 J3=(t,e)=>D3(t,Math.PI/12,e),U5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function go(t){let e=xe;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let c=U5(r),a=(c[0]??0)*Math.PI/180,s=xe;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 i=Math.cos(a),o=Math.sin(a),[l,h]=[c[1]??0,c[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=T3(e,s)}return e}function vo(t,e){let n=[],r=[],c=[0,0],a=[0,0],s=(l,h)=>m5(e,[l,h]),i=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,o=l=>{r.length&&n.push({segs:r,closed:l}),r=[]};for(let l of t)if(l.type==="M")o(!1),c=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);i(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&&!i(a,c)&&r.push({c:"L",a,b:c}),o(!0),a=c;return o(!1),n}var yo=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],bo=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function en(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 xo(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let c=en(r);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:c})}}return e}function Mo(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 P6(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])*Mo(n[2].toLowerCase(),e)}var wo=/^(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 ko(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!wo.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function zo(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return h2.score;if(/engrav|raster|etch/.test(e))return h2.engrave;if(/\bguide/.test(e))return h2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return h2.cut}function tn(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=Q8(t),r=n.root;if(r.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let c=[],a=n.comments.some(V=>/Adobe Illustrator/i.test(V)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&c.push("Adobe Illustrator file: px measured at 72 per inch.");let i=U5(r.attrs.viewBox??""),o=P6(r.attrs.width,s),l=P6(r.attrs.height,s),h=25.4/s,u=h,f=h,d=0,m=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],m=i[1]),o===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 g=l??(i.length===4?i[3]*f:0),p=T3([1,0,0,-1,0,g],[u,0,0,f,-d*u,-m*f]),v=[],y=new Map,b=V=>{V.name==="style"&&v.push(...xo(V.text)),V.attrs.id&&y.set(V.attrs.id,V),V.children.forEach(b)};b(r);let x=(V,n1)=>{let G={};for(let r1 of Object.keys(n1))bo.has(r1)&&(G[r1]=n1[r1]);for(let r1 of yo)V.attrs[r1]!==void 0&&(G[r1]=V.attrs[r1]);let k1=(V.attrs.class??"").split(/\s+/).filter(Boolean);for(let r1 of v)(!r1.tag||r1.tag===V.name)&&(!r1.id||r1.id===V.attrs.id)&&r1.classes.every(U1=>k1.includes(U1))&&Object.assign(G,r1.decls);return V.attrs.style&&Object.assign(G,en(V.attrs.style)),G},M=[],w=[],k=0,z=0,S=0,A=0,L=0,C=0,P=2e4,R=[],q=V=>Number.isFinite(V[0])&&Number.isFinite(V[1]),T=["x","y","width","height","rx","ry","cx","cy","r"],B=V=>[...T,"x1","y1","x2","y2","points"].some(n1=>V.attrs[n1]!==void 0&&U5(V.attrs[n1]).some(G=>!Number.isFinite(G))),X=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"]),h1=V=>{let n1=G=>parseFloat(V.attrs[G]??"0")||0;switch(V.name){case"path":return J3(V.attrs.d??"",()=>S++);case"rect":{let[G,k1,r1,U1]=[n1("x"),n1("y"),n1("width"),n1("height")];if(r1<=0||U1<=0)return[];let c1=V.attrs.rx!==void 0?n1("rx"):V.attrs.ry!==void 0?n1("ry"):0,V1=V.attrs.ry!==void 0?n1("ry"):c1;return c1=Math.min(Math.abs(c1),r1/2),V1=Math.min(Math.abs(V1),U1/2),c1<=0||V1<=0?J3(`M${G} ${k1}H${G+r1}V${k1+U1}H${G}Z`):J3(`M${G+c1} ${k1}H${G+r1-c1}A${c1} ${V1} 0 0 1 ${G+r1} ${k1+V1}V${k1+U1-V1}A${c1} ${V1} 0 0 1 ${G+r1-c1} ${k1+U1}H${G+c1}A${c1} ${V1} 0 0 1 ${G} ${k1+U1-V1}V${k1+V1}A${c1} ${V1} 0 0 1 ${G+c1} ${k1}Z`)}case"circle":case"ellipse":{let[G,k1]=[n1("cx"),n1("cy")],r1=V.name==="circle"?n1("r"):n1("rx"),U1=V.name==="circle"?n1("r"):V.attrs.ry!==void 0?n1("ry"):r1;return r1<=0||U1<=0?[]:J3(`M${G+r1} ${k1}A${r1} ${U1} 0 0 1 ${G} ${k1+U1}A${r1} ${U1} 0 0 1 ${G-r1} ${k1}A${r1} ${U1} 0 0 1 ${G} ${k1-U1}A${r1} ${U1} 0 0 1 ${G+r1} ${k1}Z`)}case"line":return J3(`M${n1("x1")} ${n1("y1")}L${n1("x2")} ${n1("y2")}`);case"polyline":case"polygon":{let G=U5(V.attrs.points??"");if(G.length<4)return[];let k1=`M${G[0]} ${G[1]}`;for(let r1=2;r1+1<G.length;r1+=2)k1+=`L${G[r1]} ${G[r1+1]}`;return J3(V.name==="polygon"?k1+"Z":k1)}}},H=V=>(V.text+V.children.map(n1=>n1.name==="tspan"?" "+H(n1):"").join("")).replace(/\s+/g," ").trim(),U=(V,n1,G,k1,r1,U1)=>{if(U1>64||X.has(V.name)||L&&++C>P)return;let c1=x(V,G);if(c1.display==="none"||c1.visibility==="hidden"||c1.opacity==="0"){(V.children.length||Z.has(V.name))&&z++;return}let V1=T3(n1,go(V.attrs.transform));if(!V1.every(Number.isFinite)){A++;return}let o0=ko(V),d0=V.attrs["inkscape:groupmode"]==="layer",I=k1;if(V.name==="g"||V.name==="svg"||V.name==="a"||V.name==="switch"){let A1=V.attrs["inkscape:label"]??V.attrs["data-name"]??V.attrs.id,l0=zo(A1);if(V.attrs["data-mode"]&&A1&&/^(cut|line|fill|guide)$/.test(V.attrs["data-mode"])){let v1=N5(c1.stroke,"#000000"),y1=N5(c1.fill,"#000000"),T1=V.attrs["data-mode"]==="fill"?y1:v1;I=h2[A1]??{name:A1,mode:V.attrs["data-mode"],color:T1&&T1.startsWith("#")?T1:"#00aa00"}}else l0&&(I=l0);if(V!==r&&V.name==="svg"){let v1=y1=>parseFloat(V.attrs[y1]??"0")||0;V1=T3(V1,[1,0,0,1,v1("x"),v1("y")])}let m1=d0||l0||V===r||!o0?r1:[o0,...r1];R.push(V);for(let v1 of V.children)U(v1,V1,c1,I,m1,U1+1);R.pop();return}if(V.name==="use"){let A1=y.get((V.attrs.href??V.attrs["xlink:href"]??"").replace(/^#/,""));if(!A1||R.includes(A1))return;let l0=y1=>parseFloat(V.attrs[y1]??"0")||0,m1=T3(V1,[1,0,0,1,l0("x"),l0("y")]),v1=A1.name==="symbol"?{...A1,name:"g"}:A1;R.push(A1),L++,U(v1,m1,c1,I,o0?[o0,...r1]:r1,U1+1),L--,R.pop();return}if(V.name==="image"){k++;return}let N=N5(c1.color,"#000000")??"#000000",a1=parseFloat(c1["stroke-width"]??"1"),J=N5(c1.stroke,N);J&&(a1===0||c1["stroke-opacity"]==="0")&&(J="none");let x1=N5(c1.fill??"black",N);if(c1["fill-opacity"]==="0"&&(x1="none"),V.name==="text"){let A1=H(V);if(!A1)return;let l0=V.children.find(J1=>J1.name==="tspan"),m1=J1=>U5(V.attrs[J1]??l0?.attrs[J1]??"0")[0]??0,v1=m5(V1,[m1("x"),m1("y")]),y1=Math.sqrt(Math.abs(V1[0]*V1[3]-V1[1]*V1[2])),T1=(P6(c1["font-size"],96)??16*h)/h;if(!q(v1)||!Number.isFinite(T1*y1)){A++;return}let $1=c1["text-anchor"];w.push({text:A1,at:v1,size:T1*y1,angle:Math.atan2(-V1[1],V1[0])*180/Math.PI,font:(c1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:$1==="middle"?"center":$1==="end"?"right":"left",stroke:J,fill:x1,layer:I});return}if(V.name!=="path"&&B(V)){A++;return}let R1=h1(V);if(!R1){for(let A1 of V.children)U(A1,V1,c1,I,r1,U1+1);return}let w0=vo(R1,V1),Y1=w0.filter(A1=>A1.segs.every(l0=>q(l0.a)&&q(l0.b)&&(l0.c==="L"||q(l0.p1)&&q(l0.p2))));Y1.length<w0.length&&A++,Y1.length&&M.push({subs:Y1,stroke:J,fill:V.name==="line"||V.name==="polyline"?"none":x1,fillRule:c1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:I,names:o0?[o0,...r1]:r1})};U(r,p,{},void 0,[],0),k&&c.push(`${k} embedded image${k===1?" was":"s were"} left out: trace ${k===1?"it":"them"} to paths first.`),z&&c.push(`${z} hidden element${z===1?" was":"s were"} left out.`),S&&c.push(`${S} path${S===1?" has":"s have"} bad data: read up to the error, as browsers draw ${S===1?"it":"them"}.`),A&&c.push(`${A} element${A===1?" was":"s were"} left out: ${A===1?"its":"their"} numbers are too large to draw.`),C>P&&c.push(`The drawing repeats its elements with <use> more than ${P.toLocaleString("en")} times: only the first ${P.toLocaleString("en")} copies were read.`);let Y=V=>{let[n1,G,k1]=[1,3,5].map(r1=>parseInt(V.slice(r1,r1+2),16));return n1>=200&&G<=80&&k1<=80},Q=V=>{let[n1,G,k1]=[1,3,5].map(r1=>parseInt(V.slice(r1,r1+2),16));return k1>=200&&n1<=80&&G<=80},W=V=>!!V.stroke&&V.stroke!=="none",F1=M.filter(V=>!V.layer),L1=new Map;for(let V of F1)W(V)&&V.stroke.startsWith("#")&&L1.set(V.stroke,(L1.get(V.stroke)??0)+V.subs.length);let g1=[...L1.keys()],X1=g1.filter(Y),D1=new Set(X1.length?X1:g1.length?[g1.reduce((V,n1)=>(L1.get(n1)??0)>(L1.get(V)??0)?n1:V)]:[]),E=M.some(V=>W(V)&&!V.layer)||M.some(V=>V.layer),D=new Map,e1=(V,n1)=>{if(V&&V!=="none"){let G=V.startsWith("#")?V:"#000000";if(D1.has(G))return h2.cut;if(G==="#00a0ff")return h2.guide;if(Q(G))return h2.score;if(!D.has(G)){let k1=po[G]??"color_"+G.slice(1);D.set(G,{name:k1,mode:"line",color:G})}return D.get(G)}if(n1&&n1!=="none")return E?h2.engrave:h2.cut};!E&&M.some(V=>V.fill&&V.fill!=="none")?c.push("The file has filled shapes and no strokes: the shapes are cut out."):!X1.length&&D1.size&&c.push(`No red lines: ${[...D1][0]} lines, the most common colour, are cut.`),D.size&&c.push(`Lines in ${[...D.values()].map(V=>V.color).join(", ")} went on their own layer${D.size===1?"":"s"}, set to mark, not cut.`);let u1=[];for(let V of M){let n1=V.layer??e1(V.stroke,V.fill);if(!n1)continue;let G=!V.layer&&n1===h2.cut&&!W(V);u1.push({subs:V.subs,layer:n1,fillRule:V.fillRule,names:V.names,filled:G})}let t1=[];for(let V of w){let n1=V.layer??e1(V.fill!=="none"?void 0:V.stroke,V.fill);n1&&t1.push({...V,layer:n1.mode==="cut"&&E?h2.engrave:n1})}return{items:u1,texts:t1,notes:c}}var N1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),x2=([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]},I6=(t,e)=>[t[0]+e[0],t[1]+e[1]],M2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function x3(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 i=s/a,o=1-i;n.push([o*o*o*r.a[0]+3*o*o*i*r.p1[0]+3*o*i*i*r.p2[0]+i*i*i*r.b[0],o*o*o*r.a[1]+3*o*o*i*r.p1[1]+3*o*i*i*r.p2[1]+i*i*i*r.b[1]])}}return t.closed&&n.length>1&&N1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function I2(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 _2(t,e,n){let r=[],c=e?t.length:t.length-1;for(let a=0;a<c;a++){let s=t[a],i=t[(a+1)%t.length];r.push(s);let o=Math.floor(N1(s,i)/n);for(let l=1;l<o;l++)r.push([s[0]+(i[0]-s[0])*l/o,s[1]+(i[1]-s[1])*l/o])}return!e&&t.length&&r.push(t[t.length-1]),r}function r3(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 b3=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 i=c[s],o=c[(s+1)%c.length],l=Math.max(1,Math.ceil(N1(i,o)/(r*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])/r),m=Math.floor(Math.max(u[0],f[0])/r),g=Math.floor(Math.min(u[1],f[1])/r),p=Math.floor(Math.max(u[1],f[1])/r);for(let v=d;v<=m;v++)for(let y=g;y<=p;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 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 i=r;i<=c;i++)for(let o=a;o<=s;o++)for(let[l,h]of this.cells.get(`${i},${o}`)??[])if(r3(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],i=[e[0]+(n[0]-e[0])*(a+1)/c,e[1]+(n[1]-e[1])*(a+1)/c],o=Math.floor((Math.min(s[0],i[0])-r)/this.size),l=Math.floor((Math.max(s[0],i[0])+r)/this.size),h=Math.floor((Math.min(s[1],i[1])-r)/this.size),u=Math.floor((Math.max(s[1],i[1])+r)/this.size);for(let f=o;f<=l;f++)for(let d=h;d<=u;d++)for(let[m,g]of this.cells.get(`${f},${d}`)??[])if(rn(s,i,m,g)<=r)return!0}return!1}};function rn(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),i=c(t,e,n),o=c(t,e,r);return a*s<0&&i*o<0?0:Math.min(r3(t,n,r),r3(e,n,r),r3(n,t,e),r3(r,t,e))}function So(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=z0([t]),i=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(r)),o=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/i),m=Math.floor((Math.max(h[0],u[0])+e)/i),g=Math.floor((Math.min(h[1],u[1])-e)/i),p=Math.floor((Math.max(h[1],u[1])+e)/i);if((m-d+1)*(p-g+1)>4096)return null;for(let v=d;v<=m;v++)for(let y=g;y<=p;y++)f.push(`${v},${y}`);return f};for(let h=0;h<r;h++){let u=t[h],f=t[(h+1)%r],d=l(u,f);if(!d)return!1;for(let m of d)for(let g of o.get(m)??[]){let p=Math.abs(c[h]-c[g]);if(!(Math.min(p,a-p)-N1(u,f)-N1(t[g],t[(g+1)%r])<n)&&rn(u,f,t[g],t[(g+1)%r])<=e)return!0}for(let m of d){let g=o.get(m);g?g.push(h):o.set(m,[h])}}return!1}function cn(t,e){let n=t.map(()=>!1),r=[],c=t.map(l=>z0([l]));t.forEach((l,h)=>{let u=i1([l]),f=u.reduce((g,p)=>g+M1(p),0),d=I2(l),m=u.reduce((g,p)=>g+I2(p),0);(u.length!==1||Math.abs(f-Math.abs(M1(l)))>d*.001+1e-6||Math.abs(m-d)>d*.001+.05||So(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new b3([t[l]],!0,Math.max(e*4,1))),h},i=t.map((l,h)=>h).sort((l,h)=>c[l][0]-c[h][0]),o=[];for(let l of i){let[h,u,f,d]=c[l];for(let m=o.length-1;m>=0;m--)c[o[m]][2]<h-e&&o.splice(m,1);for(let m of o){let g=c[m];if(g[1]>d+e||g[3]<u-e)continue;let[p,v]=t[l].length<=t[m].length?[l,m]:[m,l],y=t[p],b=s(v);for(let x=0;x<y.length;x++)if(b.meets(y[x],y[(x+1)%y.length],e)){r.push([l,m]);break}}o.push(l)}return{self:n,pairs:r}}function M3(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let c=Math.max(n*2,.2),a=new b3(t,r,Math.max(n*4,1)),s=new b3(e,r,Math.max(n*4,1));for(let i of t)for(let o of _2(i,r,c))if(!s.near(o,n))return!1;for(let i of e)for(let o of _2(i,r,c))if(!a.near(o,n))return!1;return!0}function an(t,e,n){let r=new b3([t,...e],!0,Math.max(n*4,1)),c=a=>B2(a,t)&&!e.some(s=>B2(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(!r.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=N1(h,u),d=Math.min(n*3,f/3)/f,m=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,g=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(r.meets(m,g,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?c(o):!0}}function sn(t,e,n){if(!t.length)return!1;let r=new b3([e],!0,Math.max(n*4,1));return t.some(c=>_2(c,!1,Math.max(n*2,.2)).some(a=>r.near(a,n)))}function B2(t,e){let n=!1;for(let r=0,c=e.length-1;r<e.length;c=r++){let[a,s]=e[r],[i,o]=e[c];s>t[1]!=o>t[1]&&t[0]<(i-a)*(t[1]-s)/(o-s)+a&&(n=!n)}return n}function _4(t){let e=t.length;if(e<3)return null;let n=0,r=0;for(let[p,v]of t)n+=p,r+=v;n/=e,r/=e;let c=0,a=0,s=0,i=0,o=0,l=0,h=0;for(let[p,v]of t){let y=p-n,b=v-r;c+=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=c*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(i+l)/2,d=(o+h)/2,m=(f*s-d*a)/u,g=(d*c-f*a)/u;return{c:[m+n,g+r],r:Math.sqrt(m*m+g*g+(c+s)/e)}}function K3(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)N1(t[0],t[o])>N1(t[0],t[n])&&(n=o);let r=o=>{if(o.length<3)return o;let l=0,h=0;for(let f=1;f<o.length-1;f++){let d=r3(o[f],o[0],o[o.length-1]);d>l&&(l=d,h=f)}return l<=e?[o[0],o[o.length-1]]:[...r(o.slice(0,h+1)).slice(0,-1),...r(o.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)],i=[];for(let o=0;o<s.length;o++){let l=s[(o-1+s.length)%s.length],h=s[(o+1)%s.length];r3(s[o],l,h)>e&&i.push(s[o])}return i.length>=3?i:s}function on(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=K3(a,.002),i=s.length,o=s.findIndex((u,f)=>N1(u,s[(f+1)%i])>=.5);if(i<4||o<0)continue;let l=M1(a)>0,h=[];for(let u=1;u<=i;u++){let f=(o+u)%i,d=s[f],m=s[(f+1)%i];if(N1(d,m)<.3){h.length||h.push(d),h.push(m);continue}if(h.length>=3){let g=_4(h),[p,v,y]=[h[0],h[1],h[h.length-1]],b=(v[0]-p[0])*(y[1]-p[1])-(v[1]-p[1])*(y[0]-p[0]);g&&g.r>.005&&g.r<.6&&(b>0===l?e:n).push(g.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 V6(t,e){let n=t.length,r=i=>N1(t[i],t[(i+1)%n])<e*1.5,c=t.findIndex((i,o)=>!r(o));if(c<0)return t;let a=[],s=c;do{let i=(s+1)%n;for(;r(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 m=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(m)>1e-12){let g=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/m,p=[l[0]+g*(h[0]-l[0]),l[1]+g*(h[1]-l[1])],v=t[(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?_4(y):{c:p,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&N1(p,v)<=e*2&&g>=1-1e-9&&(d=p)}}if(a.push(l),d)a.push(d);else for(let m=1;m<=o;m++)a.push(t[(s+m)%n]);s=i}while(s!==c);return a}function H1(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 P1=t=>String(H1(t)),s0=t=>`[${P1(t[0])}, ${P1(t[1])}]`;function Lo(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 V2(t,e,n){let r=[];(H1(t[0])!==0||H1(t[1])!==0)&&r.push(`translate(${s0(t)})`);let c=Lo(e);return c!==0&&r.push(`rotate(${c})`),[...r,n].join(" ")}function B5(t,e){return{poly:t,area:Math.abs(M1(t)),box:z0([t]),ends:e?.segs.map(n=>n.a)}}var B4=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function j4(t,e){let n=I2(t.poly),r=_2(t.poly,!0,Math.min(.5,n/256)),c=_4(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 i of t.poly)if(Math.abs(N1(i,c.c)-c.r)>a)return;let s=a+c.r*2e-4;for(let i of r)if(Math.abs(N1(i,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 = ${P1(c.r*2)})`,at:c.c,angle:0,center:c.c,circle:c,radius:c.r}}function ln(t){let e=0,n=0;for(let[s,i]of t)e+=s,n+=i;e/=t.length,n/=t.length;let r=0,c=0,a=0;for(let[s,i]of t)r+=(s-e)**2,c+=(i-n)**2,a+=(s-e)*(i-n);return .5*Math.atan2(2*a,r-c)*180/Math.PI}function G4(t,e){let n=I2(t.poly),r=_2(t.poly,!0,Math.min(.5,n/256)),c=ln(r),a=r.map(g=>x2(g,-c)),[s,i,o,l]=z0([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[g,p]of a){let v=Math.hypot((g-f[0])/h,(p-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let m=x2(f,c);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${s0([h,u])})`,at:m,angle:c,center:m}}function hn(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 W4(t,e){let n=K3(t.poly,e/4),r=hn(n),c=I2(t.poly),a=_2(t.poly,!0,Math.min(.5,c/256)).map(y=>x2(y,-r)),[s,i,o,l]=z0([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=>N1(b,y)))*f),m=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;m<e&&(m=0),m=Math.min(m,h/2,u/2);let g=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-g[0])-(h/2-m),M=Math.abs(b-g[1])-(u/2-m),w=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-m;if(Math.abs(w)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*m*m))>c*e)return;let p=x2(g,r),v=H1(m)>0?`, r = ${P1(m)}`:"";return{kind:"rect",radius:m,body:`rect(${s0([h,u])}, center = true${v})`,at:p,angle:r,center:p,rect:{w:h,h:u,r:m}}}function X4(t,e){let n=K3(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],i=n.map(u=>N1(u,s)),o=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(o)<=e&&l(i)<=e&&r<=24){let u=i.reduce((m,g)=>m+g,0)/r,f=360/r,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${r}, ${P1(u)})`,at:s,angle:d,center:s}}if(r%2===0&&r>=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,m=f.reduce((x,M)=>x+M,0)/f.length,g=h[0];if(m>d&&([d,m]=[m,d],g=h[1]),d-m<e)return;let p=r/2,v=360/p,y=((g-90)%v+v)%v;v-y<.01&&(y=0);let b=H1(m)===H1(d*.45);return{kind:"star",body:`star(${p}, ${P1(d)}${b?"":`, ${P1(m)}`})`,at:s,angle:y,center:s}}}function Ao(t,e,n){let[r,c,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 m=f[1];Math.abs(m-c)<=n?i[0].push(N4(f[0]-r,d[0]-r)):Math.abs(m-s)<=n?i[2].push(N4(a-f[0],a-d[0])):(o[0].push(m-c),o[2].push(s-m))}else{let m=f[0];Math.abs(m-a)<=n?i[1].push(N4(f[1]-c,d[1]-c)):Math.abs(m-r)<=n?i[3].push(N4(s-f[1],s-d[1])):(o[1].push(a-m),o[3].push(m-r))}}let l=[a-r,s-c,a-r,s-c],h=o.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:i.map(u=>Co(u,n)),depth:h,length:l}}var N4=(t,e)=>t<e?[t,e]:[e,t];function Co(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 T6=t=>t.reduce((e,[n,r])=>e+r-n,0);function Po(t,e,n,r,c,a){let s=[B4(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<r[h];f++){let d=u*(f+.5)/r[h];s.push(B4(d-c[h]/2,-a,d+c[h]/2,0).map(i[h]))}}),i1(s)}function H6(t,e,n){let r=K3(t.poly,e/4);if(r.length<8)return;let c=hn(r),a=r.map(H=>x2(H,-c)),s=e/2;for(let H=0;H<a.length;H++){let U=a[H],Y=a[(H+1)%a.length];if(Math.abs(U[0]-Y[0])>s&&Math.abs(U[1]-Y[1])>s)return}let i=z0([a]),o=Ao(a,i,s),l=(H,U)=>H.map(Y=>Y.map(Q=>I6(Q,U))),h=(H,U)=>M3([a],l(H,U),e),u=(H,U,Y)=>{let Q=x2(H,c);return{kind:"tabs",body:U,at:Q,angle:c,center:x2([(i[0]+i[2])/2,(i[1]+i[3])/2],c),...Y}},f=I2(t.poly),d=[0,1,2,3].filter(H=>T6(o.outer[H])<o.length[H]-s);if(!d.length)return;let m=d.map(H=>o.depth[H]).filter(H=>H!==void 0);if(!m.length)return;let g=[...new Set([n,...m].filter(H=>!!H).map(H1))];for(let H of g){let U=H1(i[2]-i[0]),Y=H1(i[3]-i[1]),Q=[[]];for(let N=0;N<4;N++){let J=T6(o.outer[N])>=o.length[N]-2*H-s?["flat"]:["out","in"],x1=[];for(let R1 of Q)for(let w0 of J)x1.push([...R1,w0]);Q.splice(0,Q.length,...x1)}let W=Math.max(3*H,6),F1=new Set([W]);for(let N of d){let a1=o.outer[N].length;for(let J of[2*a1-1,2*a1+1,2*a1-3,2*a1+3])J>=3&&F1.add(H1(o.length[N]/J))}for(let N of F1)for(let a1 of Q){if(a1.every(Y1=>Y1==="flat"))continue;let J=y4(U,Y,a1,H,N);if(Math.abs(Math.abs(J.reduce((Y1,A1)=>Y1+M1(A1),0))-t.area)>f*e||!h(J,[i[0],i[1]]))continue;let R1=a1.every(Y1=>Y1===a1[0])?`"${a1[0]}"`:`[${a1.map(Y1=>`"${Y1}"`).join(", ")}]`,w0=N===W||[0,1].every(Y1=>f3(o.length[Y1],N)===f3(o.length[Y1],W));return u([i[0],i[1]],`finger_rect(${s0([U,Y])}, ${R1}${w0?"":`, finger = ${P1(N)}`})`,{kind:"fingers",thickness:H,edges:a1,finger:w0?W:N})}let L1=[0,1,2,3].map(N=>d.includes(N)&&o.depth[N]!==void 0&&Math.abs(o.depth[N]-H)<=s);if(!L1.some(Boolean))continue;let g1=i[0]+(L1[3]?H:0),X1=i[1]+(L1[0]?H:0),D1=H1(i[2]-(L1[1]?H:0)-g1),E=H1(i[3]-(L1[2]?H:0)-X1),D=[D1,E,D1,E],e1=[L1[3]?H:0,L1[0]?H:0,L1[1]?H:0,L1[2]?H:0],u1=[0,0,0,0],t1=[0,0,0,0],V=!0;for(let N=0;N<4&&V;N++){if(!L1[N])continue;let a1=o.outer[N].map(([J,x1])=>[J-e1[N],x1-e1[N]]);u1[N]=a1.length,t1[N]=a1.length?H1(a1.reduce((J,[x1,R1])=>J+R1-x1,0)/a1.length):0,a1.forEach(([J,x1],R1)=>{(Math.abs((J+x1)/2-D[N]*(R1+.5)/u1[N])>s||Math.abs(x1-J-t1[N])>s)&&(V=!1)})}if(!V||!h(Po(D1,E,L1,u1,t1,H),[g1,X1]))continue;let n1=L1.every(Boolean)?"":`[${L1.join(", ")}]`,G=[0,1,2,3].filter(N=>L1[N]),k1=N=>Math.max(1,Math.round(D[N]/50)),r1=G.every(N=>u1[N]===k1(N)),U1=G.every(N=>u1[N]===u1[G[0]]),c1=r1?void 0:U1?u1[G[0]]:null,V1=G.every(N=>Math.abs(t1[N]-D[N]/(2*u1[N]))<=s),o0=G.every(N=>Math.abs(t1[N]-t1[G[0]])<=s),d0=V1?void 0:o0?t1[G[0]]:null,I;if(c1!==null&&d0!==null){let N=[s0([D1,E])];n1?N.push(n1):(c1!==void 0||d0!==void 0)&&N.push("true"),c1!==void 0&&N.push(`count = ${c1}`),d0!==void 0&&N.push(`width = ${P1(d0)}`),I=`tab_rect(${N.join(", ")})`}else{let N=[J=>J,J=>`translate(${s0([D1,0])}) rotate(90) ${J}`,J=>`translate(${s0([D1,E])}) rotate(180) ${J}`,J=>`translate(${s0([0,E])}) rotate(270) ${J}`],a1=[`rect(${s0([D1,E])});`];for(let J of G){let x1=[P1(D[J])];u1[J]!==k1(J)&&x1.push(`count = ${u1[J]}`),Math.abs(t1[J]-D[J]/(2*u1[J]))>s&&x1.push(`width = ${P1(t1[J])}`),a1.push(N[J](`tabs(${x1.join(", ")});`))}I=`{
|
|
2690
|
+
${a1.map(J=>" "+J).join(`
|
|
2275
2691
|
`)}
|
|
2276
|
-
}`}return u([
|
|
2277
|
-
${[`rect(${
|
|
2692
|
+
}`}return u([g1,X1],I,{kind:"tabs",thickness:H,library:"tabs",label:`tabs ${P1(H)} mm deep`})}let p=o.depth;if(d.some(H=>p[H]===void 0))return;let v=[0,1,2,3].map(H=>d.includes(H)&&T6(o.outer[H])<o.length[H]*.4),y=i[0]+(v[3]?p[3]:0),b=i[1]+(v[0]?p[0]:0),x=i[2]-(v[1]?p[1]:0)-y,M=i[3]-(v[2]?p[2]:0)-b,w=(H,U,Y,Q,W)=>H===0?[i[0]+U-y,Q,Y-U,W-Q]:H===1?[x-W,i[1]+U-b,W-Q,Y-U]:H===2?[i[2]-Y-y,M-W,Y-U,W-Q]:[Q,i[3]-Y-b,W-Q,Y-U],k=[[],[],[],[]],z=[[],[],[],[]],S=[],A=[[y-i[0],y-i[0]+x],[b-i[1],b-i[1]+M],[i[2]-(y+x),i[2]-y],[i[3]-(b+M),i[3]-b]];for(let H of d)if(v[H])for(let[U,Y]of o.outer[H])k[H].push(w(H,U,Y,-p[H],0));else{let U=A[H][0];for(let[Y,Q]of[...o.outer[H],[A[H][1],A[H][1]]]){let[W,F1]=[Math.max(U,A[H][0]),Math.min(Y,A[H][1])];F1-W>s&&((W-A[H][0]<=s||A[H][1]-F1<=s)&&S.push([H,z[H].length]),z[H].push(w(H,W,F1,-1,p[H]))),U=Math.max(U,Q)}}let L=([H,U,Y,Q])=>B4(H,U,H+Y,U+Q),C=i1([B4(0,0,x,M),...k.flat().map(L)]),P=()=>h(k0(C,z.flat().map(L)),[y,b]);if(!P())return;for(let[H,U]of S.reverse()){let[Y]=z[H].splice(U,1);P()||z[H].splice(U,0,Y)}let R=(H,U)=>{let Y=U%2===0,Q=E=>Y?E[0]:E[1];H.sort((E,D)=>Q(E)-Q(D));let W=H.every(E=>Math.abs(E[2]-H[0][2])<=s&&Math.abs(E[3]-H[0][3])<=s),F1=H.length>1?Q(H[1])-Q(H[0]):0,L1=H.every((E,D)=>Math.abs(Q(E)-Q(H[0])-D*F1)<=s),g1=H1(F1),X1=H1(Q(H[0])),D1=H1(X1+g1*(H.length-1));if(H.length>=3&&W&&L1&&g1>0&&Math.floor((D1-X1)/g1+1e-9)+1===H.length){let[,,E,D]=H[0],e1=Y?`[x, ${P1(H[0][1])}]`:`[${P1(H[0][0])}, y]`;return[`for (${Y?"x":"y"} = [${P1(X1)}:${P1(g1)}:${P1(D1)}]) translate(${e1}) rect(${s0([E,D])});`]}return H.map(([E,D,e1,u1])=>`translate(${s0([E,D])}) rect(${s0([e1,u1])});`)},q=[0,1,2,3].flatMap(H=>k[H].length?R(k[H],H):[]),T=[0,1,2,3].flatMap(H=>z[H].length?R(z[H],H):[]),B=q.length?`union() {
|
|
2693
|
+
${[`rect(${s0([x,M])});`,...q].join(`
|
|
2278
2694
|
`)}
|
|
2279
|
-
}`:`rect(${
|
|
2280
|
-
${[
|
|
2695
|
+
}`:`rect(${s0([x,M])})`,X=T.length?`difference() {
|
|
2696
|
+
${[B.endsWith("}")?B:B+";",...T].join(`
|
|
2281
2697
|
`)}
|
|
2282
|
-
}`:Q,o1=d.map(I=>P1(g[I])),m1=o1.sort((I,$)=>o1.filter(Z=>Z===$).length-o1.filter(Z=>Z===I).length)[0];return u([y,b],W,{kind:V.length?"fingers":"tabs",thickness:m1,generic:!0,label:`${V.length?"finger joints":"tabs"} ${k1(m1)} mm deep`})}function Fi(t){let[e,n,c,r]=k0([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=V2(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(!V2(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(!V2(d,t))continue;let m=a(d);m>i&&(s=d,i=m,h=!0)}h||(l/=2)}return{c:s,r:i}}function $i(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 At(t,e){let[n,c,r,a]=t.box;if(Math.max(r-n,a-c)>80)return;let s=M2(t.poly),i=H2(t.poly,!0,Math.min(.25,s/400)),o=Fi(t.poly),l=i.filter(V=>Math.abs(O1(V,o.c)-o.r)<=e),h=A4(l);if(!h||l.length<8)return;let u=i[0];for(let V of i)O1(V,h.c)>O1(u,h.c)&&(u=V);let f=O1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],m=V=>(V[0]-h.c[0])*d[0]+(V[1]-h.c[1])*d[1],p=V=>-(V[0]-h.c[0])*d[1]+(V[1]-h.c[1])*d[0],g=i.filter(V=>m(V)>h.r+e&&m(V)<f-h.r);if(g.length<4)return;let v=[g.filter(V=>p(V)>0),g.filter(V=>p(V)<0)];if(v.some(V=>V.length<2))return;let y=v.map(V=>h2([1,0],St(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=>m(V)>h.r+e&&m(V)<f-h.r),g.length<4||Math.abs(g.reduce((V,Q)=>V+p(Q),0)/g.length)>e)return;let M=g.map(V=>Math.abs(p(V))).sort((V,Q)=>V-Q),S=M[Math.floor(M.length/2)]*2;if(S>=h.r*2-e||S<.3)return;let w=Math.max(...i.map(m)),z=le(h.c,[d[0]*(w-S/2),d[1]*(w-S/2)]),C=w1([k3(h.r,h.r,256).map(V=>le(V,h.c)),$i(h.c,z,S/2)]);if(!f3([t.poly],C,e))return;let k=w-S/2,T=h.r*2,q=Math.atan2(d[1],d[0])*180/Math.PI-90,R=[];P1(T)!==9&&R.push(`head = ${k1(T)}`),P1(S)!==4.5&&R.push(`shank = ${k1(S)}`),P1(k)!==10&&R.push(`drop = ${k1(k)}`);let U=k>=(T+S)/2-1e-9,j=U?`keyhole(${R.join(", ")})`:`{ translate(${n0([0,-k])}) circle(d = ${k1(T)}); hull() { circle(d = ${k1(S)}); translate(${n0([0,-k])}) circle(d = ${k1(S)}); } }`;return{kind:"keyhole",radius:T/2,body:j,at:z,angle:q,center:z,label:"keyhole",keyhole:{head:T,shank:S,drop:k,top:z},library:U?"hanging":void 0}}var bt=.0025,S4=(t,e)=>Math.abs(t[0]-e[0])>bt||Math.abs(t[1]-e[1])>bt;function j3(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))S4(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(u2(a,e))).join(", ")}]`;return t.closed?`polygon(${r})`:c.length===2?`line(${n0(u2(c[0],e))}, ${n0(u2(c[1],e))})`:`polyline(${r})`}return`path("${fe([t],e)}")`}function fe(t,e){let n=c=>`${k1(c[0]-e[0])} ${k1(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)!S4(s.b,a)&&(s.c==="L"||!S4(s.p1,a)&&!S4(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 Ct(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 _3=t=>t.segs[0].a,Pt=t=>t.segs[t.segs.length-1].b;function Di(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[_3(s),Pt(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)&&(O1(_3(t[u]),s)<=V0||O1(Pt(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(O1(h,i[0].a)<=V0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=O1(_3(t[u]),h)<=V0?t[u]:Ct(t[u]);i=i.concat(f.segs)}i=Ct({segs:i,closed:!1}).segs}let o=i.length>1&&O1(i[i.length-1].b,i[0].a)<=V0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var Tt=.05;function qi(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 Ni(t,e={}){let n=e.tolerance??Tt,c=typeof t=="string"?t:qi(t),r=yt(c,{dpi:e.dpi}),a=[...r.notes],s={},i=(L,F=1)=>s[L]=(s[L]??0)+F,o=[],l=[],h=new Map;for(let L of r.items)if(L.layer.mode==="cut")for(let F of L.subs)F.closed?o.push({sub:F,names:L.names,group:L.filled?L:void 0}):(l.push(F),h.set(F,L.names));let u=Di(l);l=[];for(let{sub:L,from:F}of u)L.closed?o.push({sub:L,names:h.get(F)??[],line:{segs:L.segs,closed:!1}}):l.push(L);let f=o.map(L=>({...L,outline:E5(u3(L.sub),L.sub)})),d=f.filter(L=>L.outline.poly.length>=3&&L.outline.area>M2(L.outline.poly)*V0);for(let L of f)d.includes(L)||l.push(L.line??{segs:L.sub.segs,closed:!1});let m=(L,F,t1,r1)=>{if(t1!==r1)return!1;let[y1,P,Y,X]=L.box,[b1,a1,R1,e1]=F.box;if(y1<b1-V0||P<a1-V0||Y>R1+V0||X>e1+V0)return!1;let T1=L.poly.length;return[0,Math.floor(T1/3),Math.floor(2*T1/3)].filter(A=>V2(L.poly[A],F.poly)).length>=2},p=L=>{let F=d.map((y1,P)=>P).filter(y1=>!L.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 X=P-1;X>=0;X--){let b1=F[X];if(d[b1].outline.area>d[y1].outline.area&&m(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=Mt(d.map(L=>L.outline.poly),V0*2),v=p(new Set),{parent:y,depth:b}=v,x=L=>b.get(L)%2===0?L:y.get(L),M=new Set(d.map((L,F)=>F).filter(L=>g.self[L]));for(let[L,F]of g.pairs)x(L)===x(F)&&M.add(L).add(F);for(let L of v.order)b.get(L)%2===1&&M.has(y.get(L))&&M.add(L);for(let L of M)l.push(d[L].line??{segs:d[L].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 S=[],w=new Map;for(let L of v.order){if(M.has(L))continue;let F=d[L];if(b.get(L)%2===0){let t1={sub:F.sub,outline:F.outline,names:F.names,holes:[],lines:[],marks:new Map,texts:[]};S.push(t1),w.set(L,t1)}else w.get(y.get(L)).holes.push({sub:F.sub,outline:F.outline,line:F.line})}let z=e.kerf!==void 0?e.kerf/2:kt(S.map(L=>L.outline.poly)),C=0;if(z&&z>0){let L=F=>({closed:!0,segs:F.map((t1,r1)=>({c:"L",a:t1,b:F[(r1+1)%F.length]}))});for(let F of S){let t1=y0([he(F.outline.poly,z)],F.holes.map(e1=>he(e1.outline.poly,z))),r1=B0(p0(t1,-z,"miter")),y1=p0(r1.flat(),z,"round",Math.min(.01,z/10)),P=y0([F.outline.poly],F.holes.map(e1=>e1.outline.poly)),Y=e1=>Math.abs(H1(e1))<=M2(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[X,...b1]=r1[0].map(e1=>G3(e1,.001));F.outline=E5(X),F.sub=L(X);let a1=e1=>[(e1.box[0]+e1.box[2])/2,(e1.box[1]+e1.box[3])/2],R1=b1.map(e1=>E5(e1));for(let e1 of F.holes){let T1=a1(e1.outline),r0=R1.reduce((A,G)=>O1(a1(G),T1)<O1(a1(A),T1)?G:A);R1.splice(R1.indexOf(r0),1),e1.outline=r0,e1.sub=L(r0.poly),e1.line=void 0}}C=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${k1(C)} mm kerf: they are moved back, and $kerf is set.`)}let k=L=>{let F;for(let t1 of S){let[r1,y1,P,Y]=t1.outline.box;L[0]<r1||L[0]>P||L[1]<y1||L[1]>Y||V2(L,t1.outline.poly)&&(!F||t1.outline.area<F.outline.area)&&(F=t1)}return F},T={lines:[],marks:new Map,texts:[]},q=new Map,R=L=>{let F=k(_3(L));if(!F)return;let t1=q.get(F);return t1||(t1=wt(F.outline.poly,F.holes.map(r1=>r1.outline.poly),n),q.set(F,t1)),t1(u3(L,.02),L.closed)?F:void 0};for(let L of l){let F=R(L);(F?F.lines:T.lines).push(L)}for(let L of r.items)if(L.layer.mode!=="cut")for(let F of L.subs){let t1=(R(F)??T).marks;t1.set(L,[...t1.get(L)??[],F])}for(let L of r.texts)(k(L.at)??T).texts.push(L);r.texts.some(L=>L.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 L of S){let F=L.lines.map(t1=>u3(t1));L.holes=L.holes.filter(t1=>{if(!t1.line)return!0;let r1=P=>V2(P,t1.outline.poly),y1=zt(F,t1.outline.poly,V0*2)||L.lines.some(P=>r1(_3(P)))||[...L.marks.values()].some(P=>P.some(Y=>r1(_3(Y))))||L.texts.some(P=>r1(P.at))||S.some(P=>P!==L&&P.outline.area<t1.outline.area&&r1(P.outline.poly[0]));return y1&&L.lines.push(t1.line),!y1})}let U=L=>C4(L,n)??E4(L,n)??P4(L,n)??T4(L,n)??At(L,n),j=new Map;for(let L of S){let F=C4(L.outline,n)??E4(L.outline,n)??P4(L.outline,n)??T4(L.outline,n)??ue(L.outline,n);j.set(L,F);for(let t1 of L.holes)t1.found=U(t1.outline)}let V=new Map,Q=[...j.values()].some(L=>L?.thickness&&!L.generic);for(let L of j.values())L?.thickness&&L.thickness<=10&&(!Q||!L.generic)&&V.set(L.thickness,(V.get(L.thickness)??0)+1);let W=[...V.entries()].sort((L,F)=>F[1]-L[1])[0]?.[0];if(W!==void 0)for(let L of S){let F=j.get(L);if(F?.thickness!==void 0&&F.thickness!==W){let t1=ue(L.outline,n,W);t1&&t1.thickness===W&&j.set(L,t1)}}let o1=new Set;for(let L of j.values())L?.kind==="fingers"&&L.finger&&o1.add(P1(L.finger));S.sort((L,F)=>{let t1=F.outline.box[3]-L.outline.box[3];return Math.abs(t1)>1?t1:L.outline.box[0]-F.outline.box[0]});let m1=new Set,I=new Map,$=[];for(let[L,F]of S.entries()){let t1=F.names[0]??`part ${L+1}`,r1=(I.get(t1)??0)+1;I.set(t1,r1);let y1=r1>1?`${t1} ${r1}`:t1,P;for(let r0 of[2,1,0]){let A=Bi(F,j.get(F),r0,W,o1,n);if(_i(A,F,n)){P=A,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(A=>A.sub)];T.lines.push(...r0.map(A=>({segs:A.segs,closed:!1})),...F.lines);for(let[A,G]of F.marks)T.marks.set(A,[...T.marks.get(A)??[],...G]);T.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)m1.add(r0);let Y=Et(F.marks,[],F.texts,P.origin),X=[...P.cut,...Y],b1=P.thickness,a1=[...b1!==void 0&&(W===void 0||P1(b1)!==P1(W))?[`thickness = ${k1(b1)}`]:[],...F.noKerf&&C>0?["kerf = 0"]:[]],R1=a1.length?`material(${a1.join(", ")}) `:"",e1=`part("${y1.replace(/["\\]/g,"")}")`,T1=X.length===1&&!X[0].includes(`
|
|
2283
|
-
`)?`${
|
|
2284
|
-
${
|
|
2698
|
+
}`:B,Z=d.map(H=>H1(p[H])),h1=Z.sort((H,U)=>Z.filter(Y=>Y===U).length-Z.filter(Y=>Y===H).length)[0];return u([y,b],X,{kind:T.length?"fingers":"tabs",thickness:h1,generic:!0,label:`${T.length?"finger joints":"tabs"} ${P1(h1)} mm deep`})}function Eo(t){let[e,n,r,c]=z0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,r3(h,t[d],t[f]));return u},s=[(e+r)/2,(n+c)/2],i=B2(s,t)?a(s):0,o=24;for(let h=0;h<=o;h++)for(let u=0;u<=o;u++){let f=[e+(r-e)*h/o,n+(c-n)*u/o];if(!B2(f,t))continue;let d=a(f);d>i&&(s=f,i=d)}let l=Math.max(r-e,c-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(!B2(d,t))continue;let m=a(d);m>i&&(s=d,i=m,h=!0)}h||(l/=2)}return{c:s,r:i}}function To(t,e,n){let c=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let i=c+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=c-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(i),e[1]+n*Math.sin(i)])}return a}function un(t,e){let[n,r,c,a]=t.box;if(Math.max(c-n,a-r)>80)return;let s=I2(t.poly),i=_2(t.poly,!0,Math.min(.25,s/400)),o=Eo(t.poly),l=i.filter(T=>Math.abs(N1(T,o.c)-o.r)<=e),h=_4(l);if(!h||l.length<8)return;let u=i[0];for(let T of i)N1(T,h.c)>N1(u,h.c)&&(u=T);let f=N1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],m=T=>(T[0]-h.c[0])*d[0]+(T[1]-h.c[1])*d[1],g=T=>-(T[0]-h.c[0])*d[1]+(T[1]-h.c[1])*d[0],p=i.filter(T=>m(T)>h.r+e&&m(T)<f-h.r);if(p.length<4)return;let v=[p.filter(T=>g(T)>0),p.filter(T=>g(T)<0)];if(v.some(T=>T.length<2))return;let y=v.map(T=>x2([1,0],ln(T))).map(T=>T[0]*d[0]+T[1]*d[1]<0?[-T[0],-T[1]]:T),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],p=i.filter(T=>m(T)>h.r+e&&m(T)<f-h.r),p.length<4||Math.abs(p.reduce((T,B)=>T+g(B),0)/p.length)>e)return;let M=p.map(T=>Math.abs(g(T))).sort((T,B)=>T-B),w=M[Math.floor(M.length/2)]*2;if(w>=h.r*2-e||w<.3)return;let k=Math.max(...i.map(m)),z=I6(h.c,[d[0]*(k-w/2),d[1]*(k-w/2)]),S=i1([I3(h.r,h.r,256).map(T=>I6(T,h.c)),To(h.c,z,w/2)]);if(!M3([t.poly],S,e))return;let A=k-w/2,L=h.r*2,C=Math.atan2(d[1],d[0])*180/Math.PI-90,P=[];H1(L)!==9&&P.push(`head = ${P1(L)}`),H1(w)!==4.5&&P.push(`shank = ${P1(w)}`),H1(A)!==10&&P.push(`drop = ${P1(A)}`);let R=A>=(L+w)/2-1e-9,q=R?`keyhole(${P.join(", ")})`:`{ translate(${s0([0,-A])}) circle(d = ${P1(L)}); hull() { circle(d = ${P1(w)}); translate(${s0([0,-A])}) circle(d = ${P1(w)}); } }`;return{kind:"keyhole",radius:L/2,body:q,at:z,angle:C,center:z,label:"keyhole",keyhole:{head:L,shank:w,drop:A,top:z},library:R?"hanging":void 0}}var nn=.0025,U4=(t,e)=>Math.abs(t[0]-e[0])>nn||Math.abs(t[1]-e[1])>nn;function Q3(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))U4(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(M2(a,e))).join(", ")}]`;return t.closed?`polygon(${c})`:r.length===2?`line(${s0(M2(r[0],e))}, ${s0(M2(r[1],e))})`:`polyline(${c})`}return`path("${O6([t],e)}")`}function O6(t,e){let n=r=>`${P1(r[0]-e[0])} ${P1(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)!U4(s.b,a)&&(s.c==="L"||!U4(s.p1,a)&&!U4(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 D0=.01;function fn(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 e5=t=>t.segs[0].a,dn=t=>t.segs[t.segs.length-1].b;function Io(t){let e=new Set,n=[],r=s=>`${Math.round(s[0]/D0)},${Math.round(s[1]/D0)}`,c=new Map;t.forEach((s,i)=>{for(let o of[e5(s),dn(s)]){let l=r(o);c.set(l,[...c.get(l)??[],i])}});let a=s=>{let[i,o]=[Math.round(s[0]/D0),Math.round(s[1]/D0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of c.get(`${i+l},${o+h}`)??[])if(!e.has(u)&&(N1(e5(t[u]),s)<=D0||N1(dn(t[u]),s)<=D0))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(N1(h,i[0].a)<=D0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=N1(e5(t[u]),h)<=D0?t[u]:fn(t[u]);i=i.concat(f.segs)}i=fn({segs:i,closed:!1}).segs}let o=i.length>1&&N1(i[i.length-1].b,i[0].a)<=D0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var pn=.05;function Vo(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 Ho(t,e={}){let n=e.tolerance??pn,r=typeof t=="string"?t:Vo(t),c=tn(r,{dpi:e.dpi}),a=[...c.notes],s={},i=(E,D=1)=>s[E]=(s[E]??0)+D,o=[],l=[],h=new Map;for(let E of c.items)if(E.layer.mode==="cut")for(let D of E.subs)D.closed?o.push({sub:D,names:E.names,group:E.filled?E:void 0}):(l.push(D),h.set(D,E.names));let u=Io(l);l=[];for(let{sub:E,from:D}of u)E.closed?o.push({sub:E,names:h.get(D)??[],line:{segs:E.segs,closed:!1}}):l.push(E);let f=o.map(E=>({...E,outline:B5(x3(E.sub),E.sub)})),d=f.filter(E=>E.outline.poly.length>=3&&E.outline.area>I2(E.outline.poly)*D0);for(let E of f)d.includes(E)||l.push(E.line??{segs:E.sub.segs,closed:!1});let m=(E,D,e1,u1)=>{if(e1!==u1)return!1;let[t1,V,n1,G]=E.box,[k1,r1,U1,c1]=D.box;if(t1<k1-D0||V<r1-D0||n1>U1+D0||G>c1+D0)return!1;let V1=E.poly.length;return[0,Math.floor(V1/3),Math.floor(2*V1/3)].filter(d0=>B2(E.poly[d0],D.poly)).length>=2},g=E=>{let D=d.map((t1,V)=>V).filter(t1=>!E.has(t1)).sort((t1,V)=>d[V].outline.area-d[t1].outline.area),e1=new Map,u1=new Map;return D.forEach((t1,V)=>{let n1=-1;for(let G=V-1;G>=0;G--){let k1=D[G];if(d[k1].outline.area>d[t1].outline.area&&m(d[t1].outline,d[k1].outline,d[t1].group,d[k1].group)){n1=k1;break}}e1.set(t1,n1),u1.set(t1,n1<0?0:u1.get(n1)+1)}),{order:D,parent:e1,depth:u1}},p=cn(d.map(E=>E.outline.poly),D0*2),v=g(new Set),{parent:y,depth:b}=v,x=E=>b.get(E)%2===0?E:y.get(E),M=new Set(d.map((E,D)=>D).filter(E=>p.self[E]));for(let[E,D]of p.pairs)x(E)===x(D)&&M.add(E).add(D);for(let E of v.order)b.get(E)%2===1&&M.has(y.get(E))&&M.add(E);for(let E of M)l.push(d[E].line??{segs:d[E].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 E of v.order){if(M.has(E))continue;let D=d[E];if(b.get(E)%2===0){let e1={sub:D.sub,outline:D.outline,names:D.names,holes:[],lines:[],marks:new Map,texts:[]};w.push(e1),k.set(E,e1)}else k.get(y.get(E)).holes.push({sub:D.sub,outline:D.outline,line:D.line})}let z=e.kerf!==void 0?e.kerf/2:on(w.map(E=>E.outline.poly)),S=0;if(z&&z>0){let E=D=>({closed:!0,segs:D.map((e1,u1)=>({c:"L",a:e1,b:D[(u1+1)%D.length]}))});for(let D of w){let e1=k0([V6(D.outline.poly,z)],D.holes.map(c1=>V6(c1.outline.poly,z))),u1=F0(n0(e1,-z,"miter")),t1=n0(u1.flat(),z,"round",Math.min(.01,z/10)),V=k0([D.outline.poly],D.holes.map(c1=>c1.outline.poly)),n1=c1=>Math.abs(M1(c1))<=I2(c1)*D0;if(u1.length!==1||u1[0].length!==D.holes.length+1||u1[0].some(n1)||!M3(t1,V,n)){D.noKerf=!0;continue}D.drawn=[D.sub,...D.holes.map(c1=>c1.sub)];let[G,...k1]=u1[0].map(c1=>K3(c1,.001));D.outline=B5(G),D.sub=E(G);let r1=c1=>[(c1.box[0]+c1.box[2])/2,(c1.box[1]+c1.box[3])/2],U1=k1.map(c1=>B5(c1));for(let c1 of D.holes){let V1=r1(c1.outline),o0=U1.reduce((d0,I)=>N1(r1(I),V1)<N1(r1(d0),V1)?I:d0);U1.splice(U1.indexOf(o0),1),c1.outline=o0,c1.sub=E(o0.poly),c1.line=void 0}}S=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${P1(S)} mm kerf: they are moved back, and $kerf is set.`)}let A=E=>{let D;for(let e1 of w){let[u1,t1,V,n1]=e1.outline.box;E[0]<u1||E[0]>V||E[1]<t1||E[1]>n1||B2(E,e1.outline.poly)&&(!D||e1.outline.area<D.outline.area)&&(D=e1)}return D},L={lines:[],marks:new Map,texts:[]},C=new Map,P=E=>{let D=A(e5(E));if(!D)return;let e1=C.get(D);return e1||(e1=an(D.outline.poly,D.holes.map(u1=>u1.outline.poly),n),C.set(D,e1)),e1(x3(E,.02),E.closed)?D:void 0};for(let E of l){let D=P(E);(D?D.lines:L.lines).push(E)}for(let E of c.items)if(E.layer.mode!=="cut")for(let D of E.subs){let e1=(P(D)??L).marks;e1.set(E,[...e1.get(E)??[],D])}for(let E of c.texts)(A(E.at)??L).texts.push(E);c.texts.some(E=>E.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 E of w){let D=E.lines.map(e1=>x3(e1));E.holes=E.holes.filter(e1=>{if(!e1.line)return!0;let u1=V=>B2(V,e1.outline.poly),t1=sn(D,e1.outline.poly,D0*2)||E.lines.some(V=>u1(e5(V)))||[...E.marks.values()].some(V=>V.some(n1=>u1(e5(n1))))||E.texts.some(V=>u1(V.at))||w.some(V=>V!==E&&V.outline.area<e1.outline.area&&u1(V.outline.poly[0]));return t1&&E.lines.push(e1.line),!t1})}let R=E=>j4(E,n)??W4(E,n)??G4(E,n)??X4(E,n)??un(E,n),q=new Map;for(let E of w){let D=j4(E.outline,n)??W4(E.outline,n)??G4(E.outline,n)??X4(E.outline,n)??H6(E.outline,n);q.set(E,D);for(let e1 of E.holes)e1.found=R(e1.outline)}let T=new Map,B=[...q.values()].some(E=>E?.thickness&&!E.generic);for(let E of q.values())E?.thickness&&E.thickness<=10&&(!B||!E.generic)&&T.set(E.thickness,(T.get(E.thickness)??0)+1);let X=[...T.entries()].sort((E,D)=>D[1]-E[1])[0]?.[0];if(X!==void 0)for(let E of w){let D=q.get(E);if(D?.thickness!==void 0&&D.thickness!==X){let e1=H6(E.outline,n,X);e1&&e1.thickness===X&&q.set(E,e1)}}let Z=new Set;for(let E of q.values())E?.kind==="fingers"&&E.finger&&Z.add(H1(E.finger));w.sort((E,D)=>{let e1=D.outline.box[3]-E.outline.box[3];return Math.abs(e1)>1?e1:E.outline.box[0]-D.outline.box[0]});let h1=new Set,H=new Map,U=[];for(let[E,D]of w.entries()){let e1=D.names[0]??`part ${E+1}`,u1=(H.get(e1)??0)+1;H.set(e1,u1);let t1=u1>1?`${e1} ${u1}`:e1,V;for(let o0 of[2,1,0]){let d0=Fo(D,q.get(D),o0,X,Z,n);if(Do(d0,D,n)){V=d0,o0<2&&a.push(o0===1?`Part "${t1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${t1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!V){let o0=D.drawn??[D.sub,...D.holes.map(d0=>d0.sub)];L.lines.push(...o0.map(d0=>({segs:d0.segs,closed:!1})),...D.lines);for(let[d0,I]of D.marks)L.marks.set(d0,[...L.marks.get(d0)??[],...I]);L.texts.push(...D.texts),a.push(`Part "${t1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let o0 of V.found)i(o0);for(let o0 of V.libraries)h1.add(o0);let n1=mn(D.marks,[],D.texts,V.origin),G=[...V.cut,...n1],k1=V.thickness,r1=[...k1!==void 0&&(X===void 0||H1(k1)!==H1(X))?[`thickness = ${P1(k1)}`]:[],...D.noKerf&&S>0?["kerf = 0"]:[]],U1=r1.length?`material(${r1.join(", ")}) `:"",c1=`part("${t1.replace(/["\\]/g,"")}")`,V1=G.length===1&&!G[0].includes(`
|
|
2699
|
+
`)?`${U1}${c1} ${G[0]}`:`${U1}${c1} {
|
|
2700
|
+
${G.join(`
|
|
2285
2701
|
`)}
|
|
2286
|
-
}
|
|
2287
|
-
`),
|
|
2288
|
-
`),
|
|
2702
|
+
}`;U.push({name:t1,code:V2(V.origin,0,V1),local:V1,thickness:k1})}let Y=mn(L.marks,L.lines,L.texts,[0,0]);Y.length&&w.length&&a.push("Some lines or marks are outside every part; they are kept on their own.");let Q;if(e.pack){let E=new Map;for(let e1 of U){let u1=e1.local.replace(/part\("[^"]*"\)/,"part()"),t1=E.get(u1);t1?t1.qty++:E.set(u1,{name:e1.name,qty:1})}Q=[...E.entries()].map(([e1,u1])=>e1.replace("part()",`part("${u1.name.replace(/["\\]/g,"")}"${u1.qty>1?`, qty = ${u1.qty}`:""})`));let D=U.length-E.size;D&&a.push(`${D} part${D===1?" is":"s are"} the same as another and became a quantity.`)}else Q=U.map(E=>E.code);let W=Object.entries(s).filter(([E])=>E!=="outline").map(([E,D])=>`${D} ${E}${D===1?"":Oo[E]??"s"}`).join(", "),F1=`${U.length} part${U.length===1?"":"s"}${W?`; found ${W}`:""}.`,L1=[`// ${e.name?e.name+": ":""}imported from an SVG drawing.`,`// ${F1}`,...a.map(E=>`// ${E}`),"",...[...h1].sort().map(E=>`use <kerf/${E}>`),...h1.size?[""]:[]],g1=[];X!==void 0&&g1.push(`$thickness = ${P1(X)}; // from the joints`),S>0&&g1.push(`$kerf = ${P1(S)}; // the drawing's outlines were offset by half of this`),!e.pack&&U.length&&g1.push('$layout = "none"; // keep the parts where the drawing has them');let D1=[L1.join(`
|
|
2703
|
+
`),g1.join(`
|
|
2704
|
+
`),Q.join(`
|
|
2289
2705
|
|
|
2290
|
-
`),
|
|
2706
|
+
`),Y.join(`
|
|
2291
2707
|
`)].filter(Boolean).join(`
|
|
2292
2708
|
|
|
2293
2709
|
`).replace(/\n{3,}/g,`
|
|
2294
2710
|
|
|
2295
2711
|
`)+`
|
|
2296
|
-
`;try{
|
|
2297
|
-
${[x,...d].map(
|
|
2712
|
+
`;try{D1=A6(D1)}catch{}return{source:D1,parts:U.length,found:s,summary:F1,notes:a}}var Oo={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},_5=t=>t.trimEnd().endsWith("}")?t:t+";";function Fo(t,e,n,r,c,a){let s=[],i=new Set,o=n>0?e:void 0,l=t.outline.box,h,u;if(o?.kind==="rect"){let{w:A,h:L,r:C}=o.rect;h=M2(o.center,x2([A/2,L/2],o.angle)),h=[H1(h[0]),H1(h[1])],u=V2([0,0],o.angle,`rect(${s0([A,L])}${H1(C)>0?`, r = ${P1(C)}`:""})`),s.push("rectangle")}else o?(h=[H1(o.at[0]),H1(o.at[1])],u=V2(M2(o.at,h),o.angle,o.body),s.push(F6[o.kind]),o.library&&i.add(o.library)):(h=[H1(l[0]),H1(l[1])],u=Q3(t.sub,h),s.push("outline"));let f=t.holes.map(A=>({...A,found:n>0?A.found:void 0})),d=[],m=A=>M2(A,h),g=A=>A,p=0,v=new Set(f);if(n===2&&!o)for(let A of f){let L=A.found?.circle;if(!L||L.r*2>15)continue;let C=_2(t.outline.poly,!0,.25),P=Math.min(...C.map(B=>N1(B,L.c))),R=P-L.r;if(R<.5||C.filter(B=>Math.abs(N1(B,L.c)-P)<=a).length*.25<P*Math.PI*.8)continue;let T=[s0(m(L.c))];H1(L.r*2)!==4&&T.push(`d = ${P1(L.r*2)}`),H1(R)!==3&&T.push(`wall = ${P1(R)}`),g=B=>`hanging_loop(${T.join(", ")}) ${B}`,p=P,i.add("hanging"),s.push("hanging loop"),v.delete(A);break}if(n===2){let[A,L,C,P]=l,R=(A+C)/2,q=C-A,T=P-L,B=U=>U[1]>=L+T*.66,X=U=>[...v].filter(Y=>Y.found?.circle&&H1(Y.found.circle.r)===H1(U.found.circle.r)).length,Z=[...v].filter(U=>U.found?.circle&&U.found.circle.r*2>=1.5&&U.found.circle.r*2<=15&&B(U.found.circle.c)&&X(U)<=2),h1=!1;for(let U of Z){let Y=U.found.circle;if(Math.abs(Y.c[0]-R)>Math.max(.5,q*.02))continue;let Q=Y.r*2;d.push(`hanging_hole(${s0(m(Y.c))}${H1(Q)!==5?`, d = ${P1(Q)}`:""})`),v.delete(U),h1=!0;break}if(!h1)for(let U of Z)for(let Y of Z){if(h1||U===Y)continue;let[Q,W]=[U.found.circle,Y.found.circle];if(Math.abs(Q.r-W.r)>a||Math.abs(Q.c[1]-W.c[1])>a||Q.c[0]>=W.c[0])continue;let F1=[(Q.c[0]+W.c[0])/2,Q.c[1]];if(Math.abs(F1[0]-R)>Math.max(1,q*.02))continue;let L1=Q.r*2;d.push(`hanging_hole(${s0(m(F1))}${H1(L1)!==5?`, d = ${P1(L1)}`:""}, spacing = ${P1(W.c[0]-Q.c[0])})`),v.delete(U),v.delete(Y),h1=!0}h1&&(i.add("hanging"),s.push("hanger hole"));let H=[...v].filter(U=>U.found?.kind==="keyhole"&&U.found.library&&Math.abs(U.found.angle)<.01);for(let U of H)for(let Y of H){if(!v.has(U)||!v.has(Y)||U===Y)continue;let[Q,W]=[U.found,Y.found];if(Q.body!==W.body||Math.abs(Q.at[1]-W.at[1])>a||Q.at[0]>=W.at[0])continue;let F1=[P1(W.at[0]-Q.at[0])],L1=m([(Q.at[0]+W.at[0])/2,Q.at[1]]),g1=Q.body.slice(8,-1);F1.push(H1(L1[0])||H1(L1[1])?`at = ${s0(L1)}`:""),g1&&F1.push(g1),d.push(`keyholes(${F1.filter(Boolean).join(", ")})`),v.delete(U),v.delete(Y),i.add("hanging"),s.push("keyhole","keyhole")}if(r!==void 0){let U=[...v].filter(Y=>Y.found?.kind==="rect"&&H1(Y.found.rect.r)===0);for(let Y of Ro(U,a)){let{items:Q,dir:W,spacing:F1,along:L1,across:g1}=Y,X1=Q.length,D1=r,E=g1-D1,D=M2(Q[0].found.center,[W[0]*F1/2,W[1]*F1/2]),e1=Math.atan2(W[1],W[0])*180/Math.PI,u1=X1*F1;if(Math.abs(E)<=a&&Math.abs(L1-F1/2)<=a&&X1>=2){let t1=2*X1-1,V=t1*L1,n1=Math.max(3*D1,6),G=(U1,c1)=>{let V1=Math.round(U1/c1);return V1%2===0&&(V1+=U1/c1>V1?1:-1),Math.max(3,V1)};if(G(V,n1)!==t1&&G(V,L1)!==t1)continue;let k1=M2(Q[0].found.center,[W[0]*L1/2,W[1]*L1/2]),r1=G(V,n1)===t1?"":`, finger = ${P1(L1)}`;d.push(V2(m(k1),e1,`finger_holes(${P1(V)}${r1})`)),s.push("finger joint slot row")}else if(E>=-a&&E<=1){let t1=[P1(u1)];X1!==Math.max(1,Math.round(u1/50))&&t1.push(`count = ${X1}`);let V=L1-E;Math.abs(V-u1/(2*X1))>a&&t1.push(`width = ${P1(V)}`),Math.abs(E-.1)>.001&&t1.push(`clearance = ${P1(E)}`),d.push(V2(m(D),e1,`slots(${t1.join(", ")})`)),i.add("tabs"),s.push("slot row")}else continue;for(let t1 of Q)v.delete(t1)}}}let y=[...v].filter(A=>A.found),b=[...v].filter(A=>!A.found);if(n===2){let A=new Map;for(let L of y){let C=V2([0,0],L.found.angle,L.found.body);A.set(C,[...A.get(C)??[],L])}for(let[L,C]of A){let P=$o(C.map(R=>m(R.found.at)),a);if(P){d.push(`${P} ${L}`);for(let R of C)s.push(F6[R.found.kind]),R.found.library&&i.add(R.found.library);s.push("hole pattern");for(let R of C)v.delete(R)}}}for(let A of v)A.found&&(d.push(V2(m(A.found.at),A.found.angle,A.found.body)),s.push(F6[A.found.kind]),A.found.library&&i.add(A.found.library));for(let A of b)d.push(Q3(A.sub,h)),s.push("outline");let x=g(u),M=d.length?[`difference() {
|
|
2713
|
+
${[x,...d].map(_5).join(`
|
|
2298
2714
|
`)}
|
|
2299
|
-
}`]:[
|
|
2300
|
-
${[...M,...
|
|
2715
|
+
}`]:[_5(x)],w=t.lines.map(A=>_5(Q3(A,h))),k=e?.thickness??r,z=[...[...i].map(A=>`use <kerf/${A}>`),`$thickness = ${k??3};`,`translate(${s0(h)}) {
|
|
2716
|
+
${[...M,...w].join(`
|
|
2301
2717
|
`)}
|
|
2302
2718
|
}`].join(`
|
|
2303
|
-
`),
|
|
2719
|
+
`),S=Math.max(0,p,o?.radius??0,...f.map(A=>n>0?A.found?.radius??0:0));return{origin:h,round:S,cut:[...M,...w],check:z,found:s,libraries:i,thickness:o?.thickness}}var F6={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function Ro(t,e){let n=[],r=new Set,c=s=>{let i=s.found.rect;return`${Math.round((s.found.angle%180+180)%180)}|${H1(i.w)}|${H1(i.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:i,h:o}=s[0].found.rect,l=s[0].found.angle;for(let[h,u,f]of[[l,i,o],[l+90,o,i]]){let d=x2([1,0],h),m=[-d[1],d[0]],g=s.filter(v=>!r.has(v)),p=new Map;for(let v of g){let y=v.found.center,b=Math.round((y[0]*m[0]+y[1]*m[1])/e),x=[...p.keys()].find(M=>Math.abs(M-b)<=1)??b;p.set(x,[...p.get(x)??[],v])}for(let v of p.values()){let y=x=>x.found.center[0]*d[0]+x.found.center[1]*d[1];v.sort((x,M)=>y(x)-y(M));let b=0;for(;b<v.length-1;){let x=y(v[b+1])-y(v[b]),M=b+1;for(;M+1<v.length&&Math.abs(y(v[M+1])-y(v[M])-x)<=e;)M++;if(M>b&&x>u){let w=v.slice(b,M+1);for(let k of w)r.add(k);n.push({items:w,dir:d,spacing:x,along:u,across:f})}b=M}}}}return n}function $o(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let g of[...h].sort((p,v)=>p-v))(!u.length||g-u[u.length-1]>e*2)&&u.push(g);if(u.length===1)return;let[f,d]=[H1(u[0]),H1((u[u.length-1]-u[0])/(u.length-1))],m=H1(f+d*(u.length-1));if(!(d<=0||Math.floor((m-f)/d+1e-9)+1!==u.length)&&!u.some((g,p)=>Math.abs(g-(f+p*d))>e))return`[${P1(f)}:${P1(d)}:${P1(m)}]`},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),i=a(c);if(i===1||s===1){let h=i===1?r:c;if(a(h)!==t.length)return;let u=n(h);return u?i===1?`for (x = ${u}) translate([x, ${P1(c[0])}])`:`for (y = ${u}) translate([${P1(r[0])}, y])`:void 0}if(s*i!==t.length)return;let o=n(r),l=n(c);if(!(!o||!l))return`for (x = ${o}, y = ${l}) translate([x, y])`}function mn(t,e,n,r){let c=[];for(let i of e)c.push(_5(Q3(i,r)));let a=new Map,s=(i,o,l)=>{let h=i.name,u=a.get(h)??{layer:i,code:[]};u.code.push(_5(o)+(l?` // ${l}`:"")),a.set(h,u)};for(let[i,o]of t){let l=pn;if(o.length===1&&o[0].closed){let d=B5(x3(o[0]),o[0]),m=d.area>1e-6?j4(d,l)??W4(d,l)??G4(d,l)??X4(d,l):void 0;if(m){s(i.layer,V2(M2(m.at,r),m.angle,m.body));continue}}if(i.layer.mode!=="fill"||o.every(d=>!d.closed)){for(let d of o)s(i.layer,Q3(d,r));continue}let h=O6(o,r),u=o.filter(d=>d.closed).map(d=>x3(d)),f=i.fillRule==="evenodd"||M3(i1(u,"nonzero"),i1(u,"evenodd"),.01);s(i.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let i of n){let o=[JSON.stringify(i.text),`size = ${P1(i.size)}`];i.anchor!=="left"&&o.push(`halign = "${i.anchor}"`),s(i.layer,V2(M2(i.at,r),i.angle,`text(${o.join(", ")})`),i.font?`${i.font} in the drawing`:void 0)}for(let{layer:i,code:o}of a.values()){let l=["cut","score","engrave","guide"].includes(i.name)?`${i.name}()`:`layer("${i.name}", mode = "${i.mode}", color = "${i.color}")`;c.push(o.length===1&&!o[0].includes("//")?`${l} ${o[0]}`:`${l} {
|
|
2304
2720
|
${o.join(`
|
|
2305
2721
|
`)}
|
|
2306
|
-
}`)}return r}function _i(t,e,n){let c;try{c=new D3({maxSteps:2e6}).run(r2(t.check).program).shape}catch{return!1}let r=c.layers.get("cut");if(!r)return!1;let a=y0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=w1(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),p1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],x1=t=>Math.hypot(...t),Ht=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]),me=(t,e)=>$1(S0(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)),pe=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 I4(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 Ot=([t,e,n,c])=>[[t,e],[n,e],[n,c],[t,c]];function ge(t){if(t.length!==1)return!1;let e=I4(t);return Y2(M3(t,[Ot(e)]))<B*B}var ve=(t,e)=>b0(t,[Ot(e)]);function Rt(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 Wi(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 Ft(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 ye=(t,e)=>t.filter(n=>d3(n)<0&&Wi(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 $t(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 V4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&It(t.regions)===It(e.regions)&&Vt(t.cutLines)===Vt(e.cutLines)}function It(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 Vt(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),c=JSON.stringify([...e].reverse());return n<c?n:c}).sort())}var D1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),g0=t=>typeof t=="string"&&t.length>0,z2=t=>typeof t=="number"&&Number.isFinite(t),R2=t=>z2(t)&&t>=0,F2=t=>z2(t)&&t>0,m3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(z2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,g3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(z2),f2=t=>g3(t,3)&&t.every(e=>Math.abs(e)<=1e7),J2=t=>D1(t)&&g0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),H4=t=>D1(t)&&g0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),Z3=t=>J2(t)||H4(t),O2=t=>Array.isArray(t)&&t.every(Z3),p3=t=>f2(t)&&Math.hypot(...t)>1e-9,Xi=t=>D1(t)&&(t.kind==="translate"&&f2(t.by)||t.kind==="rotate"&&f2(t.origin)&&p3(t.axis)&&z2(t.angle)&&Math.abs(t.angle)<=1e6),be=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),Dt=t=>D1(t)&&Object.values(t).every(be),Nt=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||z2(t)||Array.isArray(t)&&t.every(n=>Nt(n,e+1))),xe=t=>D1(t)&&Object.values(t).every(e=>Nt(e)),Zi=t=>t===null||D1(t)&&be(t.sourceHash)&&be(t.engineHash)&&Dt(t.dependencies)&&Dt(t.fonts);function I5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!D1(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."),g0(t.model)||n("model","Give the model a nonempty name.");let r=new Set,a=(s,i)=>{if(!D1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!D1(l)||!m3(l.thickness,Number.MIN_VALUE)||!m3(l.kerf)||l.edgeError!==void 0&&!R2(l.edgeError)||l.lot!==void 0&&!g0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),D1(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())!D1(i)||!g0(i.id)||i.params!==void 0&&!xe(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(!D1(h)||!g0(h.id)||!g0(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(m=>typeof m=="string"&&r.has(m)))&&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)||!F2(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(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!m3(h.clearance)||!R2(h.flushTolerance)||!R2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let m=h.stops;if(!H4(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)||!m3(h.clearance)||!m3(h.endplay)||!F2(h.minimumOverlap)||!R2(h.maximumStopGap)||!Array.isArray(m)||m.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let p of m){if(!D1(p)||!H4(p.body)||!D1(p.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}c(p,["body","attachment"],u+".stops");let g=p.attachment;c(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!H4(g.thread)||!F2(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":(!R2(h.minimumGap)||h.bodies!==void 0&&(!O2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!g0(h.from)||!r.has(h.from)||!g0(h.to)||!r.has(h.to)||h.from===h.to||!R2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(m=>D1(m)&&Z3(m.body)&&Xi(m.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!g0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!O2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!O2(h.scope)||!h.scope.length)||!R2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(m=>D1(m)&&g0(m.id)&&Z3(m.part)&&f2(m.from)&&typeof m.held=="boolean"&&(m.fasten===void 0||Array.isArray(m.fasten)&&m.fasten.every(g0))&&(m.tool===void 0||D1(m.tool)&&f2(m.tool.from)&&f2(m.tool.to)&&F2(m.tool.diameter)&&m.tool.diameter<=1e6&&f2(m.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!O2(h.roots)||!h.roots.length||h.removable!==void 0&&!O2(h.removable)||!Array.isArray(h.links)||!h.links.every(m=>D1(m)&&g0(m.claim)&&["glued","locked","captured"].includes(m.fastening)&&typeof m.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!O2(h.bodies)||!h.bodies.length||!O2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(m=>D1(m)&&Z3(m.a)&&Z3(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&f2(m.anchorA)&&f2(m.anchorB)&&p3(m.axisA)&&p3(m.axisB)&&(m.range===void 0||m3(m.range,-1e6))||m.kind==="prismatic"&&p3(m.axisA)&&m3(m.travel,-1e6)||m.kind==="gear"&&p3(m.axisA)&&p3(m.axisB)&&F2(m.ratio)&&m.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!O2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!z2(h.ground)||Math.abs(h.ground)>1e7||!p3(h.gravity)||h.gravity[2]>=0||!R2(h.minimumMargin)||!h.loads.every(m=>D1(m)&&Z3(m.body)&&F2(m.mass)&&(m.center===void 0||f2(m.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!g0(h.plan)||!g0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(m=>D1(m)&&g0(m.step)&&O2(m.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(m,p,g)=>{D1(m)&&c(m,p,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[m,p]of h.moving.entries())D1(p)&&(d(p,["body","trajectory"],`${u}.moving[${m}]`),d(p.trajectory,D1(p.trajectory)&&p.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${m}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[m,p]of h.steps.entries())D1(p)&&(d(p,["id","part","from","held","fasten","tool"],`${u}.steps[${m}]`),d(p.tool,["from","to","diameter","travel"],`${u}.steps[${m}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[m,p]of h.joints.entries())D1(p)&&d(p,["kind","a","b",...p.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:p.kind==="prismatic"?["axisA","travel"]:p.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${m}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((m,p)=>d(m,["claim","fastening","installed"],`${u}.links[${p}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((m,p)=>d(m,["body","mass","center"],`${u}.loads[${p}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((m,p)=>d(m,["step","bodies"],`${u}.holds[${p}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(D1);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(p=>p.id===l.plan&&p.kind==="assembly-access"),f=o.find(p=>p.id===l.retention&&p.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(D1).map(p=>p.id)),m=new Set((Array.isArray(f?.links)?f.links:[]).filter(D1).map(p=>p.claim));if(Array.isArray(l.holds))for(let p of l.holds)D1(p)&&!d.has(p.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(p.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let p of u.steps)if(D1(p)&&Array.isArray(p.fasten))for(let g of p.fasten)m.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(p.id)} fastens ${String(g)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(D1(f)){let d=D1(f.body)?f.body:{},m=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(m)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(m)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)D1(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 Me(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(!D1(a)||a.schemaVersion!==1||!g0(a.configuration)||!xe(a.params)||!xe(a.renderSettings)||!Zi(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(!D1(l)||!g0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!F2(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&&!g0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!R2(l.kerf)||l.kerf>1e6)||!Yi(l.matrix)||typeof l.placed!="boolean"||!qt(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!qt(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>D1(u)&&z2(u.x0)&&z2(u.x1)&&u.x1>u.x0&&z2(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())(!D1(l)||l.label!==null&&!g0(l.label)||typeof l.kind!="string"||!g3(l.from,3)||!g3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!f2(l.up)||!(F2(l.size)&&l.size<=1e6||g3(l.size,2)&&l.size.every(h=>F2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function qt(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 Yi(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 Ut(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)),k2=(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}),Le=(t,e,n=[],c="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:c}),H5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,V5=(t,e)=>H5(t,e)?.thickness??[e.thickness,e.thickness];function R4(t,e){let n=H5(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 ke=(t,e)=>t[0]>=e[0]+B&&t[1]<=e[1]-B,Se=(t,e)=>t[0]<e[0]-B||t[1]>e[1]+B,Ae=(...t)=>t.map(X3).find(Boolean);function $4(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=Ae(n,c);if(r)return c1(r);let a=me(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=Rt(c.regions,a,i),f=Y2(b0(n.regions,u)),d=B*(pe(n.regions)+pe(u)),m={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?Q1("There is insufficient geometric glue contact.",m):f<t.minimumArea+d?{...c1("Contact area is on the numerical acceptance boundary."),measurements:m}:Le("The selected nominal faces have the required geometric contact.",m,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function Bt(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=Ae(c,r);if(a)return c1(a);let s=me(r,c);if(!$t(s)||Math.abs(s[10])>B)return c1("Only orthogonal tab/slot geometry is supported.");let i=ve(c.regions,t.region);if(!ge(i))return c1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=I4(i),f=4*B,d=B,p=[[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(ve(c.regions,V))>B*B).flatMap((V,Q)=>V?[Q]:[]);if(p.length>1)return c1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(p.length&&Math.abs(p[0]<2?s[8]:s[9])<.5)return c1("The tongue must join its parent along the insertion direction.");let g;if(p.length){let V=p[0],Q=V<2?[V===0?o:h,(l+u)/2,0]:[(o+h)/2,V===2?l:u,0],W=i0(s,Q)[2],o1=(V<2?s[8]:s[9])*(V%2===0?-1:1);g={z:W,outward:o1}}let v=[];for(let V of[o,h])for(let Q of[l,u])for(let W of[0,c.thickness])v.push(i0(s,[V,Q,W]));let y=[0,1,2].map(V=>Math.min(...v.map(Q=>Q[V]))),b=[0,1,2].map(V=>Math.max(...v.map(Q=>Q[V]))),x=ye(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||!ge([x[0]]))return c1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],S=I4([M]),w=R4(n,c),z=R4(n,r);if(![...w,...z].every(Number.isFinite))return c1("Compensated kerf metadata is needed for manufacturing bounds.");let C={},k=!1;for(let V=0;V<2;V++){let Q=Math.abs(s[V*4+2])>.5,W=Q?V5(n,c):[b[V]-y[V]+w[0],b[V]-y[V]+w[1]],o1=S[V+2]-S[V],m1=[o1-z[1]-W[1],o1-z[0]-W[0]];if(C[V?"clearanceY":"clearanceX"]=m1,Se(m1,t.clearance))return Q1("Tab/slot clearance is outside the required range.",C);k||(k=!ke(m1,t.clearance));let I=y[V],$=b[V];Q?s[V*4+2]>0?$+=W[1]-c.thickness:I-=W[1]-c.thickness:(I-=Math.max(0,w[1])/2,$+=Math.max(0,w[1])/2);let Z=Math.min(I-S[V],S[V+2]-$)-Math.max(0,z[1])/2;if(C[V?"minimumSideGapY":"minimumSideGapX"]=Z,Z<-B)return Q1("The tongue is offset into the edge of its slot.",C);Z<B&&(k=!0)}let T=Math.max(0,-w[0])/2,q=V5(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]-T,q[1])-Math.max(y[2]+T,0)),U=q[1]-t.flushTolerance;if(C.engagement=R,C.requiredEngagement=U,R<=B)return Q1("The tongue does not engage the receiving panel.",C);if(R<U-B)return Q1("The tongue does not engage through the receiving panel.",C);if(R<U+B&&(k=!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.",C);let j=Math.min(...r.regions.filter(V=>V!==M).map(V=>Ft(M,V)))-Math.max(0,-z[0]);return C.minimumLigament=j,j<t.minimumLigament-B?Q1("Too little material remains around the slot.",C):(j<t.minimumLigament+B&&(k=!0),k?{...c1("A fit condition is on its numerical acceptance boundary."),measurements:C}:Le("The rectangular tongue fits and engages its receiving slot.",C,["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."],H5(n,c)||H5(n,r)?"bounded-fit":"nominal"))}function O4(t){let e=p1(t.to,t.from),n=x1(e);return typeof t.size=="number"&&n>B?{start:t.from,dir:e.map(c=>c/n),length:n,diameter:t.size}:null}function we(t,e){let n=O4(e);if(!n||x1([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=p1(n.start,t.start),r=J1(c,t.dir);return x1(c.map((a,s)=>a-r*t.dir[s]))<B}var F4=(t,e)=>J1(p1(e,t.start),t.dir),ze=(t,e)=>[F4(t,e.from),F4(t,e.to)].sort((n,c)=>n-c);function Ji(t,e){let n=Ht(e.matrix);if(J1(n,t.dir)<0||x1([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(S0(e.matrix),t.start),r=[c[0],c[1]],a=ye(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((m,p)=>m+p[0],0)/i.length,i.reduce((m,p)=>m+p[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(m=>Math.hypot(m[0]-o[0],m[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((m,p)=>W3(r,m,s[(p+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-r[0],m[1]-r[1]))),f=F4(t,i0(e.matrix,[0,0,0])),d=F4(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 Gt(t,e,n){let c=k2(e,t.shaft),r=O4(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=Ae(...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],S=Ji(r,M);if(typeof S=="string")return/unsupported|supported/.test(S)?c1(`${M.name}: ${S}`):Q1(`${M.name}: ${S}`);let w=R4(n,M);if(!w.every(Number.isFinite))return c1("Kerf metadata is required for bore tolerance bounds.");let z=[S.hole[0]-w[1]-r.diameter,S.hole[1]-w[0]-r.diameter];if(l[`clearance${x+1}`]=z,Se(z,t.clearance))return Q1(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!ke(z,t.clearance)),S.lo<-B||S.lo+V5(n,M)[1]>r.length+B)return Q1(`${M.name}: the shaft does not extend through this part.`,l);h.push(S)}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=>V5(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 m=f[1].lo-f[0].lo,g=[f[0].part,...d.map(x=>x.part)].map(x=>V5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[m-g[1],m-g[0]];if(l.endplay=v,Se(v,t.endplay))return Q1("The axial stack has insufficient or excessive endplay.",l);u||(u=!ke(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:k2(e,x.body)})).map(x=>({...x,at:x.h&&we(r,x.h)?ze(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:S}=b[x];if(!we(r,S))return Q1("A retainer is not coaxial with the shaft.");let w=O4(S),z=ze(r,S),C=f[x],k=x===0?z[1]:z[0],T=x===0?C.lo:C.hi,q=x===0?T-k:k-T;l[`stopGap${x+1}`]=q;let R=R4(n,C.part),U=(w.diameter-(C.hole[1]-R[0]))/2;if(l[`stopOverlap${x+1}`]=U,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),U<t.minimumOverlap-B)return Q1("A retainer can pass through its bearing opening.",l);U<t.minimumOverlap+B&&(u=!0);let j=M.attachment;if(j.kind==="unknown")return{...c1("The stop is present but its fastening is unverified."),measurements:l};if(j.kind==="integral"){if(Math.min(Math.abs(k),Math.abs(k-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=k2(e,j.thread);if(!we(r,V))return Q1("The threaded attachment is off the shaft axis.");if(O4(V).diameter>r.diameter+B)return Q1("The declared threaded section exceeds the shaft envelope.");let Q=ze(r,V),W=Math.max(0,Math.min(z[1],Q[1])-Math.max(z[0],Q[0]));if(Q[0]<-B||Q[1]>r.length+B)return Q1("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=W,W<j.minimumEngagement-B)return Q1("The threaded stop has insufficient declared thread engagement.",l);if(W<j.minimumEngagement+B&&(u=!0),!j.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}:Le("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>H5(n,x))?"bounded-fit":"nominal")}var q4=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]),T0=(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]],v0=(t,e)=>t.map(n=>n*e),Wt=(t,e)=>t.map((n,c)=>n+e[c]),_1=t=>v0(t,1/x1(t)),Xt=()=>D0(0,0,0);function Ce(t,e){let n=c=>c.kind==="translate"?x1(c.by)<1e-9:Math.abs(c.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?x1(p1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?x1(p1(v0(_1(t.axis),t.angle),v0(_1(e.axis),e.angle)))<1e-9&&x1(T0(p1(t.origin,e.origin),_1(t.axis)))<1e-9:!1}function Ki(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 D4(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 Ki(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 Qi(t,e){let n=w1(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],m=u[f+1],p=[[o,s(d,o)],[l,s(d,l)],[l,s(m,l)],[o,s(m,o)]],g=p.filter((v,y)=>x1([v[0]-p[(y+1)%p.length][0],v[1]-p[(y+1)%p.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 c0(t,e){if("part"in e)return Z0(t,e).matrix;let n=k2(t,e),c=_1(p1(n.to,n.from));if(!x1(p1(n.to,n.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let r=p1(n.up,v0(c,J1(n.up,c)));if(x1(r)<1e-9){if(Array.isArray(n.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let s=Math.abs(c[0])<.8?[1,0,0]:[0,1,0];r=p1(s,v0(c,J1(s,c)))}r=_1(r);let a=T0(r,c);return[a[0],r[0],c[0],n.from[0],a[1],r[1],c[1],n.from[1],a[2],r[2],c[2],n.from[2],0,0,0,1]}function K2(t,e,n){if(n.tick(),"part"in e){let o=Z0(t,e),l=X3(o);if(l)throw new Error(l);let u=Qi(o.regions,n).map(f=>D4(f,o.thickness,o.matrix));return{ref:e,outer:u,inner:u}}let c=k2(t,e),r=c0(t,e),a=x1(p1(c.to,c.from));if(a<B)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(c.size)){let[o,l]=c.size,h=[[-o/2,-l/2],[o/2,-l/2],[o/2,l/2],[-o/2,l/2]],u=[D4(h,a,r)];return{ref:e,outer:u,inner:u}}let s=32,i=o=>Array.from({length:s},(l,h)=>[o*Math.cos(h*2*Math.PI/s),o*Math.sin(h*2*Math.PI/s)]);return{ref:e,inner:[D4(i(c.size/2),a,r)],outer:[D4(i(c.size/2/Math.cos(Math.PI/s)),a,r)]}}function N4(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 D0(...v0(t.by,e));let[n,c,r]=_1(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 $1(D0(...t.origin),$1(l,D0(...v0(t.origin,-1))))}function Pe(t,e){if(e.kind==="translate")return x1(e.by);let n=_1(e.axis),c=0;for(let r of t.outer)for(let a of r.vertices){let s=p1(a,e.origin);c=Math.max(c,x1(p1(s,v0(n,J1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*c}function jt(t){return t.faces.map(e=>T0(p1(t.vertices[e[1]],t.vertices[e[0]]),p1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>x1(e)>1e-12).map(_1)}function Zt(t,e){let n=[...jt(t),...jt(e)];for(let[c,r]of t.edges)for(let[a,s]of e.edges){let i=T0(p1(t.vertices[r],t.vertices[c]),p1(e.vertices[s],e.vertices[a]));x1(i)>1e-12&&n.push(_1(i))}return n}var Y3=(t,e)=>{let n=t.vertices.map(c=>J1(c,e));return[Math.min(...n),Math.max(...n)]};function eo(t,e,n){let c=-1/0;for(let r of Zt(t,e)){n.tick();let a=Y3(t,r),s=Y3(e,r);c=Math.max(c,s[0]-a[1],a[0]-s[1])}return c}function to(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 no(t,e,n,c){let r=p1(n,e),a=p1(c,e),s=p1(t,e),i=J1(r,s),o=J1(a,s);if(i<=0&&o<=0)return x1(s);let l=p1(t,n),h=J1(r,l),u=J1(a,l);if(h>=0&&u<=h)return x1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return x1(p1(s,v0(r,i/(i-h))));let d=p1(t,c),m=J1(r,d),p=J1(a,d);if(p>=0&&m<=p)return x1(d);let g=m*o-i*p;if(g<=0&&o>=0&&p<=0)return x1(p1(s,v0(a,o/(o-p))));let v=h*p-m*u;if(v<=0&&u-h>=0&&m-p>=0)return x1(p1(l,v0(p1(c,n),(u-h)/(u-h+m-p))));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 x1(p1(s,Wt(v0(r,b),v0(a,x))))}function co(t,e,n,c){let r=p1(e,t),a=p1(c,n),s=p1(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,m=(o*d+u)/l;return m<0&&(m=0,d=Math.max(0,Math.min(1,-h/i))),m>1&&(m=1,d=Math.max(0,Math.min(1,(o-h)/i))),x1(Wt(s,p1(v0(r,d),v0(a,m))))}function ro(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,no(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,co(t.vertices[r],t.vertices[a],e.vertices[s],e.vertices[i]));return c}function _t(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=to(o,l);if(h>Math.min(a,c)){r=Math.min(r,h);continue}let u=eo(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,ro(o,l,n)))}return{lower:r,upper:a,penetration:s,touchSafe:i}}function U4(t,e,n,c){let r=_t(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:_t(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 Yt(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 Zt(o,l)){a.tick();let m=Y3(o,d),p=Y3(l,d),g=Y3(h,d),v=Y3(u,d);if(Math.min(p[0]-m[1],v[0]-g[1])>=r||Math.min(m[0]-p[1],g[0]-v[1])>=r){f=!0;break}}if(!f)return!1}return!0}function B4(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 d2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),O5=(t,e)=>t.every((n,c)=>Math.abs(n-e[c])<B);function Jt(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 Kt(t,e,n){let c=Jt(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=U4(c[a],c[s],n,t.minimumGap);if(r=Math.min(r,i.lower),i.penetration||i.upper<t.minimumGap-B)return d2("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 Ee(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,m)=>N4(d.solid,y3(d.trajectory,m));if(Ce(o.trajectory,l.trajectory)){let d=U4(o.solid,l.solid,c,n);if(d.penetration||d.upper<n-B)return d2("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"&&Yt(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+B,c))continue;let u=Pe(o.solid,o.trajectory)+Pe(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,m]=f.shift(),p=(d+m)/2,g=u*(m-d)/2,v=U4(h(o,p),h(l,p),c,n+g);if(v.penetration||v.upper<n-B)return d2("The specified path has physical interference.",{phase:p,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(m-d<1e-9)return{...c1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,m]},entities:[o.solid.ref,l.solid.ref]};f.push([d,p],[p,m])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function ao(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||!V4(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(x1(p1(n.to,n.from))-x1(p1(c.to,c.from)))>B)return"Hardware identities and dimensions must remain invariant."}return null}function Qt(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=ao(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 d2("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[...B4(e),...r]){let h=$1(S0(c0(e,l.a)),c0(e,l.b)),u=$1(S0(c0(n,l.a)),c0(n,l.b));if(!O5(h,u)||!Ce(o(l.a),o(l.b)))return d2("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):Xt();if("part"in l){if(!O5($1(u,c0(e,l)),c0(n,l)))return d2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=k2(e,l),d=k2(n,l);if(typeof f.size=="number"){if(!O5(i0(u,f.from),d.from)||!O5(i0(u,f.to),d.to))return d2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!O5($1(u,c0(e,l)),c0(n,l)))return d2("A box trajectory does not match its rendered destination.",{},[l])}}return Ee(t.moving.map(l=>({solid:K2(e,l.body,c),trajectory:l.trajectory})),Jt(e,s.filter(l=>!i.has(u1(l))),c),t.minimumGap,c,t.maxIntervals)}function e9(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 d2("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 d2("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=N4(l,y3({kind:"translate",by:o.from},1)),u=Ee([{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]}]},m=K2(d,{hardware:f},n),p=N4(m,y3({kind:"translate",by:o.tool.travel},1)),g=Ee([{solid:p,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?d2("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}),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]),F0=t=>[t[3],t[7],t[11]],Te=t=>{let e=_1(t),n=_1(T0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,T0(e,n)]},G4=(t,e,n)=>{let c=Te(n)[0],r=_1(U0(e,c)),a=_1(U0(t,c)),s=_1(U0(e,n));return Math.atan2(J1(s,T0(r,a)),J1(r,a))*180/Math.PI},t9=(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 n9(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 c9(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 m of f){let p=u1(d),g=s.get(p)??new Set;g.add(u1(m)),s.set(p,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),m=c.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!m)return c1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(m.status==="fail")return K1(`Attachment ${f.claim} fails its geometric contract.`);if(m.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 p=n9(d,f.fastening);if(!p)return c1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(p),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 so(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,x1(p1(o.to,o.from))/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 m=0;m<i.length;m++){let p=i[m],g=i[(m+1)%i.length],v=p[0]-o,y=p[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 io(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 oo(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=n9(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 r9(t,e,n,c=[],r){let a=v3(e),s=t.loads.map(p=>u1(p.body));if(new Set(s).size!==s.length||a.some(p=>!s.includes(u1(p))))return c1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let p=c.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=r?.claims.find(v=>v.id===t.retention);if(!p||p.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(!oo(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 p of t.loads){let g=p.center?i0(c0(e,p.body),p.center):so(e,p.body);i+=p.mass,o=o.map((v,y)=>v+p.mass*g[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return c1("Mass/centroid calculation exceeds its numerical range.");o=v0(o,1/i);let l=[];for(let p of a){let g=K2(e,p,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(p))){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=io(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 p=0;p<h.length;p++){let g=h[p],v=h[(p+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 m={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.",m):d<t.minimumMargin+B?{...c1("Stability is on its numerical support boundary."),measurements:m}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:m,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function a9(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(m=>m.id===d&&m.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 m=n.claims.find(p=>p.id===d.claim);if(m?.kind==="glue-contact")l.set(d.claim,[m.a,m.b]);else if(m?.kind==="captured-shaft"){let p=[m.shaft,...m.bearings,...m.stack,...m.stops.map(g=>g.body)];m.stops.forEach(g=>{g.attachment.kind==="threaded"&&p.push(g.attachment.thread)}),l.set(d.claim,p)}}let h=new Set,u=new Set(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 m=new Set([...i].filter(g=>o.has(g))),p=[...m];for(;p.length;)for(let g of d.get(p.pop())??[])m.has(g)||(m.add(g),p.push(g));return m};for(let d of 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 m=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(u1));if([...m].some(g=>!o.has(g)))return K1(`Step ${d.id} holds an uninstalled body.`);let p=f();if([...o].some(g=>!p.has(g)&&!m.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 lo(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 s9(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 S=s.indexOf(u1(y));if(S<0)throw new Error("A joint references a body outside its scope.");for(let w=0;w<3;w++)v[S*6+b+w]+=M*x[w]};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=B4({...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=$4({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),S=$1(S0(y),b),w=$1(S0(x),M),z=k=>{let T=h();u(T,v.b,3,k),u(T,v.a,3,k,-1),o.push(T)},C=(k,T,q)=>{let R=h();u(R,v.b,0,k),u(R,v.a,0,k,-1),u(R,v.b,3,T0(q,k)),u(R,v.a,3,T0(T,k),-1),o.push(R)};if(v.kind==="fixed"){if(S.some((k,T)=>Math.abs(k-w[T])>B))return K1("A fixed joint changes its relative transform.");l.forEach(k=>z(k)),l.forEach(k=>C(k,p1(F0(b),F0(y)),[0,0,0]))}else if(v.kind==="revolute"){let k=i0(y,v.anchorA),T=i0(b,v.anchorB),q=_1(U0(y,v.axisA)),R=_1(U0(b,v.axisB)),U=J1(_1(U0(x,v.axisA)),_1(U0(M,v.axisB)));if(x1(p1(k,T))>B||x1(T0(q,R))>1e-7||Math.abs(J1(q,R)-U)>1e-7)return K1("Revolute anchors or axes do not coincide.");if(v.range){let j=G4(S,w,v.axisB);if(!t9(j,v.range,B).length)return K1("A revolute joint exceeds its declared angular travel.",{angle:j})}l.forEach(j=>C(j,p1(k,F0(y)),p1(T,F0(b)))),Te(q).forEach(z)}else if(v.kind==="prismatic"){let k=p1(F0(S),F0(w)),T=_1(v.axisA),q=J1(k,T);if([0,1,2,4,5,6,8,9,10].some(R=>Math.abs(S[R]-w[R])>B)||x1(p1(k,v0(T,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),Te(_1(U0(y,v.axisA))).forEach(R=>C(R,p1(F0(b),F0(y)),[0,0,0]))}else{let k=_1(U0(y,v.axisA)),T=_1(U0(b,v.axisB));if(x1(T0(k,T))>1e-7||x1(p1(F0(y),F0(x)))>B||x1(p1(F0(b),F0(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 U=h();u(U,v.a,3,k,v.ratio),u(U,v.b,3,T),o.push(U)}}c.tick(o.length*s.length*6);let m=lo(o),p=s.length*6-m.rank;if(m.uncertain)return c1("Constraint rank is numerically singular.");let g={degreesOfFreedom:p,constraintRank:m.rank,redundantRows:o.length-m.rank};return p!==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 i9(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"?x1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?x1(p1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?x1(p1(v0(_1(o.axis),o.angle),v0(_1(l.axis),l.angle)))<1e-9&&x1(T0(p1(o.origin,l.origin),_1(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),m=_1(U0(u,o.axisA)),p=_1(h.axis);if(x1(T0(m,p))>1e-9||x1(T0(p1(h.origin,d),m))>B)return K1("The trajectory does not rotate about the actual hinge.");if(o.range){let g=$1(S0(u),f),v=$1(S0(c0(c,o.a)),c0(c,o.b)),y=h.angle*J1(_1(U0(f,o.axisB)),p),b=o.range;if(!t9(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=_1(U0(u,o.axisA));if(x1(T0(h.by,d))>B)return K1("The analytic slider path leaves its guide.");let m=$1(S0(u),f),p=$1(S0(c0(c,o.a)),c0(c,o.b)),g=J1(p1(F0(m),F0(p)),_1(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=_1(U0(b,y));return x1(T0(_1(v.axis),x))>1e-9||x1(T0(p1(v.origin,F0(b)),x))>B?null:v.angle*J1(_1(v.axis),x)},m=d(o.a,l,o.axisA),p=d(o.b,h,o.axisB);if(m===null||p===null)return c1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(p+o.ratio*m)>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 o9(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return l9(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})),warnings:t.warnings,legacyHardware:t.echoes.some(c=>c.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function l9(t){if(t&&typeof t=="object"){for(let e of Object.values(t))l9(e);Object.freeze(t)}return t}function h9(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let c=I5({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:$1(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:p1(i0(i,a.up),i0(i,[0,0,0]))}:a})}}function ho(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==B||I5(e).length||Me(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 uo(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=I5(t);if(c.length)return{kind:"invalid-spec",issues:c};let r=Me(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 Ut(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(`
|
|
2307
|
-
`)})),v.legacyHardware&&o.claims.push(
|
|
2308
|
-
`;let e=
|
|
2309
|
-
`;let n=
|
|
2722
|
+
}`)}return c}function Do(t,e,n){let r;try{r=new W3({maxSteps:2e6}).run(m2(t.check).program).shape}catch{return!1}let c=r.layers.get("cut");if(!c)return!1;let a=k0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=i1(c.regions),i=n+t.round*16e-5;if(!M3(a,s,i))return!1;let o=e.lines.map(l=>x3(l));return!(o.length&&!M3(o,c.lines,i,!1))}var j=.001,K1=(t,e)=>t.reduce((n,r,c)=>n+r*e[c],0),b1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],S1=t=>Math.hypot(...t),yn=t=>[t[2],t[6],t[10]],f0=(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]),R6=(t,e)=>q1(p0(t.matrix),e.matrix);function w3(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 c3=t=>Math.abs(t.reduce((e,n)=>e+w3(n),0)),$6=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 Z4(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 bn=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function D6(t){if(t.length!==1)return!1;let e=Z4(t);return c3(h3(t,[bn(e)]))<j*j}var q6=(t,e)=>a0(t,[bn(e)]);function xn(t,e,n=0){let r=e[0]*e[5]-e[1]*e[4]<0;return t.map(c=>{let a=c.map(([s,i])=>f0(e,[s,i,n]).slice(0,2));return r?a.reverse():a})}function qo(t,e){let n=!1;for(let r=0,c=t.length-1;r<t.length;c=r++){let[a,s]=t[r],[i,o]=t[c];s>e[1]!=o>e[1]&&e[0]<(i-a)*(e[1]-s)/(o-s)+a&&(n=!n)}return n}function t5(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 Mn(t,e){let n=1/0;for(let r of t)for(let c=0;c<e.length;c++)n=Math.min(n,t5(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,t5(r,t[c],t[(c+1)%t.length]));return n}var N6=(t,e)=>t.filter(n=>w3(n)<0&&qo(n,e));function n5(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 wn(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 Y4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&gn(t.regions)===gn(e.regions)&&vn(t.cutLines)===vn(e.cutLines)}function gn(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 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(w3(n)),c.sort()[0]])};return JSON.stringify(t.map(e).sort())}function vn(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),r=JSON.stringify([...e].reverse());return n<r?n:r}).sort())}var j1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),S0=t=>typeof t=="string"&&t.length>0,O2=t=>typeof t=="number"&&Number.isFinite(t),G2=t=>O2(t)&&t>=0,H2=t=>O2(t)&&t>0,k3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(O2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,S3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(O2),w2=t=>S3(t,3)&&t.every(e=>Math.abs(e)<=1e7),a3=t=>j1(t)&&S0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),J4=t=>j1(t)&&S0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),r5=t=>a3(t)||J4(t),j2=t=>Array.isArray(t)&&t.every(r5),z3=t=>w2(t)&&Math.hypot(...t)>1e-9,No=t=>j1(t)&&(t.kind==="translate"&&w2(t.by)||t.kind==="rotate"&&w2(t.origin)&&z3(t.axis)&&O2(t.angle)&&Math.abs(t.angle)<=1e6),U6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),kn=t=>j1(t)&&Object.values(t).every(U6),Sn=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||O2(t)||Array.isArray(t)&&t.every(n=>Sn(n,e+1))),B6=t=>j1(t)&&Object.values(t).every(e=>Sn(e)),Uo=t=>t===null||j1(t)&&U6(t.sourceHash)&&U6(t.engineHash)&&kn(t.dependencies)&&kn(t.fonts);function j5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!j1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let r=(s,i,o)=>{for(let l of Object.keys(s))i.includes(l)||n(o?`${o}.${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,i)=>{if(!j1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!j1(l)||!k3(l.thickness,Number.MIN_VALUE)||!k3(l.kerf)||l.edgeError!==void 0&&!G2(l.edgeError)||l.lot!==void 0&&!S0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),j1(l)&&r(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())!j1(i)||!S0(i.id)||i.params!==void 0&&!B6(i.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):c.has(i.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(c.add(i.id),r(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(!j1(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&&i++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(m=>typeof m=="string"&&c.has(m)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!a3(h.a)||!a3(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!H2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!a3(h.tab)||!a3(h.receiver)||!S3(h.region,4)||h.region.some(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!k3(h.clearance)||!G2(h.flushTolerance)||!G2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let m=h.stops;if(!J4(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(a3)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(a3)||!k3(h.clearance)||!k3(h.endplay)||!H2(h.minimumOverlap)||!G2(h.maximumStopGap)||!Array.isArray(m)||m.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let g of m){if(!j1(g)||!J4(g.body)||!j1(g.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}r(g,["body","attachment"],u+".stops");let p=g.attachment;r(p,p.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(p.kind)||p.kind==="threaded"&&(!J4(p.thread)||!H2(p.minimumEngagement)||typeof p.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!G2(h.minimumGap)||h.bodies!==void 0&&(!j2(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||!G2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(m=>j1(m)&&r5(m.body)&&No(m.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!S0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!j2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!j2(h.scope)||!h.scope.length)||!G2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(m=>j1(m)&&S0(m.id)&&r5(m.part)&&w2(m.from)&&typeof m.held=="boolean"&&(m.fasten===void 0||Array.isArray(m.fasten)&&m.fasten.every(S0))&&(m.tool===void 0||j1(m.tool)&&w2(m.tool.from)&&w2(m.tool.to)&&H2(m.tool.diameter)&&m.tool.diameter<=1e6&&w2(m.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!j2(h.roots)||!h.roots.length||h.removable!==void 0&&!j2(h.removable)||!Array.isArray(h.links)||!h.links.every(m=>j1(m)&&S0(m.claim)&&["glued","locked","captured"].includes(m.fastening)&&typeof m.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!j2(h.bodies)||!h.bodies.length||!j2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(m=>j1(m)&&r5(m.a)&&r5(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&w2(m.anchorA)&&w2(m.anchorB)&&z3(m.axisA)&&z3(m.axisB)&&(m.range===void 0||k3(m.range,-1e6))||m.kind==="prismatic"&&z3(m.axisA)&&k3(m.travel,-1e6)||m.kind==="gear"&&z3(m.axisA)&&z3(m.axisB)&&H2(m.ratio)&&m.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!j2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!O2(h.ground)||Math.abs(h.ground)>1e7||!z3(h.gravity)||h.gravity[2]>=0||!G2(h.minimumMargin)||!h.loads.every(m=>j1(m)&&r5(m.body)&&H2(m.mass)&&(m.center===void 0||w2(m.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(m=>j1(m)&&S0(m.step)&&j2(m.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(m,g,p)=>{j1(m)&&r(m,g,p)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[m,g]of h.moving.entries())j1(g)&&(d(g,["body","trajectory"],`${u}.moving[${m}]`),d(g.trajectory,j1(g.trajectory)&&g.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${m}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[m,g]of h.steps.entries())j1(g)&&(d(g,["id","part","from","held","fasten","tool"],`${u}.steps[${m}]`),d(g.tool,["from","to","diameter","travel"],`${u}.steps[${m}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[m,g]of h.joints.entries())j1(g)&&d(g,["kind","a","b",...g.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:g.kind==="prismatic"?["axisA","travel"]:g.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${m}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((m,g)=>d(m,["claim","fastening","installed"],`${u}.links[${g}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((m,g)=>d(m,["body","mass","center"],`${u}.loads[${g}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((m,g)=>d(m,["step","bodies"],`${u}.holds[${g}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(j1);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(g=>g.id===l.plan&&g.kind==="assembly-access"),f=o.find(g=>g.id===l.retention&&g.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(j1).map(g=>g.id)),m=new Set((Array.isArray(f?.links)?f.links:[]).filter(j1).map(g=>g.claim));if(Array.isArray(l.holds))for(let g of l.holds)j1(g)&&!d.has(g.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(g.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let g of u.steps)if(j1(g)&&Array.isArray(g.fasten))for(let p of g.fasten)m.has(p)||n(`claims.${String(u.id)}.steps`,`Step ${String(g.id)} fastens ${String(p)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(j1(f)){let d=j1(f.body)?f.body:{},m=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(m)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(m)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)j1(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 _6(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(!j1(a)||a.schemaVersion!==1||!S0(a.configuration)||!B6(a.params)||!B6(a.renderSettings)||!Uo(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}r.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),r.add(a.configuration);let i=new Set;for(let[o,l]of a.parts.entries()){if(!j1(l)||!S0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!H2(l.thickness)||l.glue!==void 0&&(!a3(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&&(!G2(l.kerf)||l.kerf>1e6)||!Bo(l.matrix)||typeof l.placed!="boolean"||!zn(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!zn(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>j1(u)&&O2(u.x0)&&O2(u.x1)&&u.x1>u.x0&&O2(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())(!j1(l)||l.label!==null&&!S0(l.label)||typeof l.kind!="string"||!S3(l.from,3)||!S3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!w2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!H2(l.size))||!(H2(l.size)&&l.size<=1e6||S3(l.size,2)&&l.size.every(h=>H2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function zn(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>S3(r,2)&&r.every(c=>Math.abs(c)<=1e6)))}function Bo(t){if(!S3(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 Ln(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 r2=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),F2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var e0=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),o1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),Z6=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),W5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,G5=(t,e)=>W5(t,e)?.thickness??[e.thickness,e.thickness];function Q4(t,e){let n=W5(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 W6=(t,e)=>t[0]>=e[0]+j&&t[1]<=e[1]-j,X6=(t,e)=>t[0]<e[0]-j||t[1]>e[1]+j,Y6=(...t)=>t.map(n5).find(Boolean);function te(t,e){let n=r2(e,t.a),r=r2(e,t.b);if(n===r)return e0("A glue contact needs two different physical instances.");let c=Y6(n,r);if(c)return o1(c);let a=R6(n,r),s=t.faceA==="top"?n.thickness:0,i=t.faceB==="top"?r.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return e0("The selected faces are not parallel.");let o=Math.abs(a[11]+a[10]*i-s);if(o>j)return e0("The selected faces are separated.",{faceGap:o});if(o>1e-7)return o1("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=xn(r.regions,a,i),f=c3(a0(n.regions,u)),d=j*($6(n.regions)+$6(u)),m={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?e0("There is insufficient geometric glue contact.",m):f<t.minimumArea+d?{...o1("Contact area is on the numerical acceptance boundary."),measurements:m}:Z6("The selected nominal faces have the required geometric contact.",m,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function An(t,e,n){let r=r2(e,t.tab),c=r2(e,t.receiver);if(r===c)return e0("A tongue and its receiving panel must be different instances.");let a=Y6(r,c);if(a)return o1(a);let s=R6(c,r);if(!wn(s)||Math.abs(s[10])>j)return o1("Only orthogonal tab/slot geometry is supported.");let i=q6(r.regions,t.region);if(!D6(i))return o1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=Z4(i),f=4*j,d=j,g=[[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(T=>c3(q6(r.regions,T))>j*j).flatMap((T,B)=>T?[B]:[]);if(g.length>1)return o1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(g.length&&Math.abs(g[0]<2?s[8]:s[9])<.5)return o1("The tongue must join its parent along the insertion direction.");let p;if(g.length){let T=g[0],B=T<2?[T===0?o:h,(l+u)/2,0]:[(o+h)/2,T===2?l:u,0],X=f0(s,B)[2],Z=(T<2?s[8]:s[9])*(T%2===0?-1:1);p={z:X,outward:Z}}let v=[];for(let T of[o,h])for(let B of[l,u])for(let X of[0,r.thickness])v.push(f0(s,[T,B,X]));let y=[0,1,2].map(T=>Math.min(...v.map(B=>B[T]))),b=[0,1,2].map(T=>Math.max(...v.map(B=>B[T]))),x=N6(c.regions,[(y[0]+b[0])/2,(y[1]+b[1])/2]);if(!x.length)return e0("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!D6([x[0]]))return o1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],w=Z4([M]),k=Q4(n,r),z=Q4(n,c);if(![...k,...z].every(Number.isFinite))return o1("Compensated kerf metadata is needed for manufacturing bounds.");let S={},A=!1;for(let T=0;T<2;T++){let B=Math.abs(s[T*4+2])>.5,X=B?G5(n,r):[b[T]-y[T]+k[0],b[T]-y[T]+k[1]],Z=w[T+2]-w[T],h1=[Z-z[1]-X[1],Z-z[0]-X[0]];if(S[T?"clearanceY":"clearanceX"]=h1,X6(h1,t.clearance))return e0("Tab/slot clearance is outside the required range.",S);A||(A=!W6(h1,t.clearance));let H=y[T],U=b[T];B?s[T*4+2]>0?U+=X[1]-r.thickness:H-=X[1]-r.thickness:(H-=Math.max(0,k[1])/2,U+=Math.max(0,k[1])/2);let Y=Math.min(H-w[T],w[T+2]-U)-Math.max(0,z[1])/2;if(S[T?"minimumSideGapY":"minimumSideGapX"]=Y,Y<-j)return e0("The tongue is offset into the edge of its slot.",S);Y<j&&(A=!0)}let L=Math.max(0,-k[0])/2,C=G5(n,c);if(t.flushTolerance>=C[0]-j)return o1("flushTolerance must be smaller than the receiving thickness.");let P=Math.max(0,Math.min(b[2]-L,C[1])-Math.max(y[2]+L,0)),R=C[1]-t.flushTolerance;if(S.engagement=P,S.requiredEngagement=R,P<=j)return e0("The tongue does not engage the receiving panel.",S);if(P<R-j)return e0("The tongue does not engage through the receiving panel.",S);if(P<R+j&&(A=!0),p&&(p.outward>0&&p.z<C[1]-j||p.outward<0&&p.z>j))return e0("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",S);let q=Math.min(...c.regions.filter(T=>T!==M).map(T=>Mn(M,T)))-Math.max(0,-z[0]);return S.minimumLigament=q,q<t.minimumLigament-j?e0("Too little material remains around the slot.",S):(q<t.minimumLigament+j&&(A=!0),A?{...o1("A fit condition is on its numerical acceptance boundary."),measurements:S}:Z6("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."],W5(n,r)||W5(n,c)?"bounded-fit":"nominal"))}function K4(t){let e=b1(t.to,t.from),n=S1(e);return typeof t.size=="number"&&n>j?{start:t.from,dir:e.map(r=>r/n),length:n,diameter:t.size}:null}function j6(t,e){let n=K4(e);if(!n||S1([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=b1(n.start,t.start),c=K1(r,t.dir);return S1(r.map((a,s)=>a-c*t.dir[s]))<j}var ee=(t,e)=>K1(b1(e,t.start),t.dir),G6=(t,e)=>[ee(t,e.from),ee(t,e.to)].sort((n,r)=>n-r);function _o(t,e){let n=yn(e.matrix);if(K1(n,t.dir)<0||S1([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=f0(p0(e.matrix),t.start),c=[r[0],r[1]],a=N6(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],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((m,g)=>m+g[0],0)/i.length,i.reduce((m,g)=>m+g[1],0)/i.length];if(Math.hypot(o[0]-c[0],o[1]-c[1])>j)return"The shaft is not centered in the bore.";let l=s.map(m=>Math.hypot(m[0]-o[0],m[1]-o[1]));if(Math.max(...l)-Math.min(...l)>j)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((m,g)=>t5(c,m,s[(g+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-c[0],m[1]-c[1]))),f=ee(t,f0(e.matrix,[0,0,0])),d=ee(t,f0(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 Cn(t,e,n){let r=F2(e,t.shaft),c=K4(r);if(!c)return o1("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 e0("Bearing and stack references must name distinct physical parts.");let i=a.map(x=>r2(e,x)),o=Y6(...i);if(o)return o1(o);let l={shaftDiameter:c.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],w=_o(c,M);if(typeof w=="string")return/unsupported|supported/.test(w)?o1(`${M.name}: ${w}`):e0(`${M.name}: ${w}`);let k=Q4(n,M);if(!k.every(Number.isFinite))return o1("Kerf metadata is required for bore tolerance bounds.");let z=[w.hole[0]-k[1]-c.diameter,w.hole[1]-k[0]-c.diameter];if(l[`clearance${x+1}`]=z,X6(z,t.clearance))return e0(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!W6(z,t.clearance)),w.lo<-j||w.lo+G5(n,M)[1]>c.length+j)return e0(`${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=>G5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>j)))return o1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-j)return e0("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-j||d[x].hi>f[1].lo+j||x&&d[x-1].hi>d[x].lo+j)return e0("The axial stack overlaps another component or its supports.");let m=f[1].lo-f[0].lo,p=[f[0].part,...d.map(x=>x.part)].map(x=>G5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[m-p[1],m-p[0]];if(l.endplay=v,X6(v,t.endplay))return e0("The axial stack has insufficient or excessive endplay.",l);u||(u=!W6(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:F2(e,x.body)})).map(x=>({...x,at:x.h&&j6(c,x.h)?G6(c,x.h):void 0}));if(b.some(x=>!x.at))return e0("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(!j6(c,w))return e0("A retainer is not coaxial with the shaft.");let k=K4(w),z=G6(c,w),S=f[x],A=x===0?z[1]:z[0],L=x===0?S.lo:S.hi,C=x===0?L-A:A-L;l[`stopGap${x+1}`]=C;let P=Q4(n,S.part),R=(k.diameter-(S.hole[1]-P[0]))/2;if(l[`stopOverlap${x+1}`]=R,C<-j||C>t.maximumStopGap+j)return e0("A retainer is misplaced relative to the outside bearing face.",l);if((C<-1e-7||C>t.maximumStopGap+1e-7)&&(u=!0),R<t.minimumOverlap-j)return e0("A retainer can pass through its bearing opening.",l);R<t.minimumOverlap+j&&(u=!0);let q=M.attachment;if(q.kind==="unknown")return{...o1("The stop is present but its fastening is unverified."),measurements:l};if(q.kind==="integral"){if(Math.min(Math.abs(A),Math.abs(A-c.length))>j)return e0("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 T=F2(e,q.thread);if(!j6(c,T))return e0("The threaded attachment is off the shaft axis.");if(K4(T).diameter>c.diameter+j)return e0("The declared threaded section exceeds the shaft envelope.");let B=G6(c,T),X=Math.max(0,Math.min(z[1],B[1])-Math.max(z[0],B[0]));if(B[0]<-j||B[1]>c.length+j)return e0("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=X,X<q.minimumEngagement-j)return e0("The threaded stop has insufficient declared thread engagement.",l);if(X<q.minimumEngagement+j&&(u=!0),!q.secured)return{...o1("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?{...o1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:Z6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>W5(n,x))?"bounded-fit":"nominal")}var ne=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},d1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),V0=(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]],L0=(t,e)=>t.map(n=>n*e),Tn=(t,e)=>t.map((n,r)=>n+e[r]),W1=t=>L0(t,1/S1(t)),In=()=>B0(0,0,0);function J6(t,e){let n=r=>r.kind==="translate"?S1(r.by)<1e-9:Math.abs(r.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?S1(b1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?S1(b1(L0(W1(t.axis),t.angle),L0(W1(e.axis),e.angle)))<1e-9&&S1(V0(b1(t.origin,e.origin),W1(t.axis)))<1e-9:!1}function jo(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],i=a<s?[a,s]:[s,a];n.set(i.join(","),i)}return{vertices:t,faces:e,edges:[...n.values()]}}function c5(t,e,n){let r=t.length,c=[];for(let a of[0,e])for(let[s,i]of t)c.push(f0(n,[s,i,a]));return jo(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 Go(t,e){let n=i1(t),r=[...new Set(n.flat().map(i=>i[0]))].sort((i,o)=>i-o),c=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<r.length;i++){let o=r[i-1],l=r[i],h=(o+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],m=u[f+1],g=[[o,s(d,o)],[l,s(d,l)],[l,s(m,l)],[o,s(m,o)]],p=g.filter((v,y)=>S1([v[0]-g[(y+1)%g.length][0],v[1]-g[(y+1)%g.length][1],0])>1e-10);if(p.length<3||Math.abs(w3(p))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(a.push(p),a.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!a.length||Math.abs(c3(a)-c3(n))>j*j*Math.max(1,c3(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function L3(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(d1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function X5(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function i0(t,e){if("part"in e)return r2(t,e).matrix;let n=F2(t,e),[r,c]=X5(n),a={...n,from:r,to:c},s=W1(b1(a.to,a.from));if(!S1(b1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let i=b1(a.up,L0(s,K1(a.up,s)));if(S1(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=b1(l,L0(s,K1(l,s)))}i=W1(i);let o=V0(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 s3(t,e,n){if(n.tick(),"part"in e){let h=r2(t,e),u=n5(h);if(u)throw new Error(u);let d=Go(h.regions,n).map(m=>c5(m,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=F2(t,e),c=i0(t,e),[a,s]=X5(r),i=S1(b1(s,a));if(i<j)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=[c5(f,i,c)];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(r.shape==="ball"){let h=r.size/2,u=h/Math.SQRT2,f=B0(0,0,h-u);return{ref:e,inner:[c5(l(u),2*u,q1(c,f))],outer:[c5(l(h/Math.cos(Math.PI/o)),i,c)]}}return{ref:e,inner:[c5(l(r.size/2),i,c)],outer:[c5(l(r.size/2/Math.cos(Math.PI/o)),i,c)]}}function re(t,e){let n=c=>c.map(a=>({...a,vertices:a.vertices.map(s=>f0(e,s))})),r=n(t.outer);return{ref:t.ref,outer:r,inner:t.inner===t.outer?r:n(t.inner)}}function A3(t,e){if(t.kind==="translate")return B0(...L0(t.by,e));let[n,r,c]=W1(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*r*o-c*i,n*c*o+r*i,0,r*n*o+c*i,s+r*r*o,r*c*o-n*i,0,c*n*o-r*i,c*r*o+n*i,s+c*c*o,0,0,0,0,1];return q1(B0(...t.origin),q1(l,B0(...L0(t.origin,-1))))}function K6(t,e){if(e.kind==="translate")return S1(e.by);let n=W1(e.axis),r=0;for(let c of t.outer)for(let a of c.vertices){let s=b1(a,e.origin);r=Math.max(r,S1(b1(s,L0(n,K1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*r}function Pn(t){return t.faces.map(e=>V0(b1(t.vertices[e[1]],t.vertices[e[0]]),b1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>S1(e)>1e-12).map(W1)}function Vn(t,e){let n=[...Pn(t),...Pn(e)];for(let[r,c]of t.edges)for(let[a,s]of e.edges){let i=V0(b1(t.vertices[c],t.vertices[r]),b1(e.vertices[s],e.vertices[a]));S1(i)>1e-12&&n.push(W1(i))}return n}var a5=(t,e)=>{let n=t.vertices.map(r=>K1(r,e));return[Math.min(...n),Math.max(...n)]};function Wo(t,e,n){let r=-1/0;for(let c of Vn(t,e)){n.tick();let a=a5(t,c),s=a5(e,c);r=Math.max(r,s[0]-a[1],a[0]-s[1])}return r}function Xo(t,e){let n=0;for(let r=0;r<3;r++){let c=t.vertices.map(i=>i[r]),a=e.vertices.map(i=>i[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 Zo(t,e,n,r){let c=b1(n,e),a=b1(r,e),s=b1(t,e),i=K1(c,s),o=K1(a,s);if(i<=0&&o<=0)return S1(s);let l=b1(t,n),h=K1(c,l),u=K1(a,l);if(h>=0&&u<=h)return S1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return S1(b1(s,L0(c,i/(i-h))));let d=b1(t,r),m=K1(c,d),g=K1(a,d);if(g>=0&&m<=g)return S1(d);let p=m*o-i*g;if(p<=0&&o>=0&&g<=0)return S1(b1(s,L0(a,o/(o-g))));let v=h*g-m*u;if(v<=0&&u-h>=0&&m-g>=0)return S1(b1(l,L0(b1(r,n),(u-h)/(u-h+m-g))));let y=v+p+f;if(Math.abs(y)<1e-20)return 1/0;let b=Math.max(0,Math.min(1,p/y)),x=Math.max(0,Math.min(1-b,f/y));return S1(b1(s,Tn(L0(c,b),L0(a,x))))}function Yo(t,e,n,r){let c=b1(e,t),a=b1(r,n),s=b1(t,n),i=K1(c,c),o=K1(c,a),l=K1(a,a),h=K1(c,s),u=K1(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,m=(o*d+u)/l;return m<0&&(m=0,d=Math.max(0,Math.min(1,-h/i))),m>1&&(m=1,d=Math.max(0,Math.min(1,(o-h)/i))),S1(Tn(s,b1(L0(c,d),L0(a,m))))}function Jo(t,e,n){let r=1/0;for(let[c,a]of[[t,e],[e,t]])for(let s of c.vertices)for(let i of a.faces)for(let o=1;o<i.length-1;o++)n.tick(),r=Math.min(r,Zo(s,a.vertices[i[0]],a.vertices[i[o]],a.vertices[i[o+1]]));for(let[c,a]of t.edges)for(let[s,i]of e.edges)n.tick(),r=Math.min(r,Yo(t.vertices[c],t.vertices[a],e.vertices[s],e.vertices[i]));return r}function En(t,e,n,r){let c=1/0,a=1/0,s=!1,i=!0;for(let o of t)for(let l of e){n.tick();let h=Xo(o,l);if(h>Math.min(a,r)){c=Math.min(c,h);continue}let u=Wo(o,l,n);u<-j&&(s=!0),u<0&&(i=!1),c=Math.min(c,Math.max(0,h,u)),u<-j?a=0:u<=Math.min(a,r)&&(a=Math.min(a,Jo(o,l,n)))}return{lower:c,upper:a,penetration:s,touchSafe:i}}function ce(t,e,n,r){let c=En(t.outer,e.outer,n,r+j),a=t.outer===t.inner&&e.outer===e.inner;if(c.lower>r+j)return{lower:c.lower-j,upper:1/0,penetration:!1,touchSafe:!0};let s=a?c:En(t.inner,e.inner,n,1/0);return{lower:Math.max(0,c.lower-j),upper:s.upper+j,penetration:s.penetration,touchSafe:c.touchSafe}}function Hn(t,e,n,r,c,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=r.outer[i],f=!1;for(let d of Vn(o,l)){a.tick();let m=a5(o,d),g=a5(l,d),p=a5(h,d),v=a5(u,d);if(Math.min(g[0]-m[1],v[0]-p[1])>=c||Math.min(m[0]-g[1],p[0]-v[1])>=c){f=!0;break}}if(!f)return!1}return!0}function ae(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 k2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),Z5=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<j);function On(t,e,n){if(new Set(e.map(d1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(r=>s3(t,r,n))}function Fn(t,e,n){let r=On(e,t.bodies??L3(e),n);if(r.length<2)return o1("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 i=ce(r[a],r[s],n,t.minimumGap);if(c=Math.min(c,i.lower),i.penetration||i.upper<t.minimumGap-j)return k2("Physical bodies interfere or violate the required clearance.",{gapUpper:i.upper},[r[a].ref,r[s].ref]);if(!(i.lower>t.minimumGap||t.minimumGap===0&&i.touchSafe))return{...o1("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 Q6(t,e,n,r,c=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()){r.tick();let h=(d,m)=>re(d.solid,A3(d.trajectory,m));if(J6(o.trajectory,l.trajectory)){let d=ce(o.solid,l.solid,r,n);if(d.penetration||d.upper<n-j)return k2("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{...o1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&Hn(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+j,r))continue;let u=K6(o.solid,o.trajectory)+K6(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>c)return{...o1("Continuous clearance interval budget exhausted."),measurements:{intervals:i},entities:[o.solid.ref,l.solid.ref]};r.tick();let[d,m]=f.shift(),g=(d+m)/2,p=u*(m-d)/2,v=ce(h(o,g),h(l,g),r,n+p);if(v.penetration||v.upper<n-j)return k2("The specified path has physical interference.",{phase:g,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-p>n)){if(m-d<1e-9)return{...o1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,m]},entities:[o.solid.ref,l.solid.ref]};f.push([d,g],[g,m])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function Ko(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||!Y4(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(S1(b1(n.to,n.from))-S1(b1(r.to,r.from)))>j)return"Hardware identities and dimensions must remain invariant."}return null}function Rn(t,e,n,r,c=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return o1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=Ko(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=L3(e),i=new Set(t.moving.map(l=>d1(l.body)));if(i.size!==t.moving.length)return k2("A body has conflicting simultaneous trajectories.");let o=l=>t.moving.find(h=>d1(h.body)===d1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...ae(e),...c]){let h=q1(p0(i0(e,l.a)),i0(e,l.b)),u=q1(p0(i0(n,l.a)),i0(n,l.b));if(!Z5(h,u)||!J6(o(l.a),o(l.b)))return k2("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=>d1(f.body)===d1(l))?.trajectory,u=h?A3(h,1):In();if("part"in l){if(!Z5(q1(u,i0(e,l)),i0(n,l)))return k2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=F2(e,l),d=F2(n,l);if(typeof f.size=="number"){if(!Z5(f0(u,f.from),d.from)||!Z5(f0(u,f.to),d.to))return k2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!Z5(q1(u,i0(e,l)),i0(n,l)))return k2("A box trajectory does not match its rendered destination.",{},[l])}}return Q6(t.moving.map(l=>({solid:s3(e,l.body,r),trajectory:l.trajectory})),On(e,s.filter(l=>!i.has(d1(l))),r),t.minimumGap,r,t.maxIntervals)}function $n(t,e,n){let r=t.scope??L3(e),c=new Set(r.map(d1)),a=new Map(t.initial.map(o=>[d1(o),s3(e,o,n)]));if(c.size!==r.length||a.size!==t.initial.length||t.initial.some(o=>!c.has(d1(o))))return k2("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)||!c.has(d1(o.part))||a.has(d1(o.part)))return k2("An assembly step duplicates or misidentifies a required installation.");if(s.add(o.id),!o.held)return{...o1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=s3(e,o.part,n),h=re(l,A3({kind:"translate",by:o.from},1)),u=Q6([{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(d1(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]}]},m=s3(d,{hardware:f},n),g=re(m,A3({kind:"translate",by:o.tool.travel},1)),p=Q6([{solid:g,trajectory:{kind:"translate",by:o.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(p.status!=="pass")return{...p,assemblyStep:o.id,message:`Tool access at step ${o.id}: ${p.message}`}}}return a.size!==c.size?k2("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 Q1=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),J0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),j0=t=>[t[3],t[7],t[11]],et=t=>{let e=W1(t),n=W1(V0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,V0(e,n)]},se=(t,e,n)=>{let r=et(n)[0],c=W1(J0(e,r)),a=W1(J0(t,r)),s=W1(J0(e,n));return Math.atan2(K1(s,V0(c,a)),K1(c,a))*180/Math.PI},Dn=(t,e,n)=>{let r=[],c=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let i=c;i<=a&&r.length<64;i++)r.push(t+360*i);let s=(e[0]+e[1])/2;return r.sort((i,o)=>Math.abs(i-s)-Math.abs(o-s))};function qn(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 Nn(t,e,n,r){let c=L3(e),a=new Set(c.map(d1));for(let f of t.removable??[])a.delete(d1(f));if(t.roots.some(f=>!a.has(d1(f))))return Q1("A retention root cannot be excluded as removable.");let s=new Map,i=f=>{for(let d of f)for(let m of f){let g=d1(d),p=s.get(g)??new Set;p.add(d1(m)),s.set(g,p)}},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(p=>p.id===f.claim),m=r.find(p=>p.id===f.claim&&p.configurations.includes(e.configuration));if(!d||!m)return o1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(m.status==="fail")return Q1(`Attachment ${f.claim} fails its geometric contract.`);if(m.status!=="pass")return o1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return Q1(`The fastening for ${f.claim} is explicitly not installed.`);let g=qn(d,f.fastening);if(!g)return o1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(g),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(d1)),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(d1(f))&&!l.has(d1(f)));return u.length?{...Q1("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 Qo(t,e){if("hardware"in e){let i=i0(t,e),o=t.hardware.find(l=>l.label===e.hardware);return f0(i,[0,0,S1(b1(X5(o)[1],X5(o)[0]))/2])}let n=r2(t,e),r=n5(n);if(r)throw new Error(r);let c=0,a=0,s=0;for(let i of n.regions){let[o,l]=i[0],h=0,u=0,f=0;for(let m=0;m<i.length;m++){let g=i[m],p=i[(m+1)%i.length],v=g[0]-o,y=g[1]-l,b=p[0]-o,x=p[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=w3(i);c+=d,a+=(o+u/(3*h))*d,s+=(l+f/(3*h))*d}if(c<=j*j)throw new Error("Material centroid is numerically unresolved.");return f0(n.matrix,[a/c,s/c,n.thickness/2])}function el(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]),r=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},c=r(e),a=r([...e].reverse());return[...c.slice(0,-1),...a.slice(0,-1)]}function tl(t,e,n){let r=new Map,c=i=>{for(let o of i)for(let l of i){let h=r.get(d1(o))??new Set;h.add(d1(l)),r.set(d1(o),h)}};for(let i of t.links){let o=qn(e.claims.find(l=>l.id===i.claim),i.fastening);o&&c(o)}if(!n.length)return!0;let a=new Set([d1(n[0])]),s=[...a];for(;s.length;)for(let i of r.get(s.pop())??[])a.has(i)||(a.add(i),s.push(i));return n.every(i=>a.has(d1(i)))}function Un(t,e,n,r=[],c){let a=L3(e),s=t.loads.map(g=>d1(g.body));if(new Set(s).size!==s.length||a.some(g=>!s.includes(d1(g))))return o1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let g=r.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),p=c?.claims.find(v=>v.id===t.retention);if(!g||g.status!=="pass"||!p||p.kind!=="retention"||p.removable?.length)return o1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!tl(p,c,a))return o1("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 g of t.loads){let p=g.center?f0(i0(e,g.body),g.center):Qo(e,g.body);i+=g.mass,o=o.map((v,y)=>v+g.mass*p[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return o1("Mass/centroid calculation exceeds its numerical range.");o=L0(o,1/i);let l=[];for(let g of a){let p=s3(e,g,n),v=Math.min(...p.inner.flatMap(b=>b.vertices.map(x=>x[2]))),y=Math.min(...p.outer.flatMap(b=>b.vertices.map(x=>x[2])));if(v<t.ground-j)return Q1("A physical component penetrates the ground plane.");if(y<t.ground-j)return o1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(b=>d1(b)===d1(g))){if(Math.abs(v-t.ground)>1e-8)return o1("Ground contact is separated or within physical-envelope uncertainty.");for(let b of p.inner)for(let x of b.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=el(l);if(h.length<3)return o1("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 g=0;g<h.length;g++){let p=h[g],v=h[(g+1)%h.length],y=(v[0]-p[0])*(f[1]-p[1])-(v[1]-p[1])*(f[0]-p[0]),b=t5(f,p,v);d=Math.min(d,y<0?-b:b)}let m={supportMargin:d,mass:i,centerX:o[0],centerY:o[1],centerZ:o[2]};return d<t.minimumMargin-j?Q1("The gravity line lies outside the required support margin.",m):d<t.minimumMargin+j?{...o1("Stability is on its numerical support boundary."),measurements:m}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:m,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function Bn(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(m=>m.id===d&&m.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 o1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return o1("Per-step support of removable objects needs an explicit contact model.");let i=new Set(a.roots.map(d1)),o=new Set(c.initial.map(d1));if(c.initial.some(d=>!i.has(d1(d))))return o1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let m=n.claims.find(g=>g.id===d.claim);if(m?.kind==="glue-contact")l.set(d.claim,[m.a,m.b]);else if(m?.kind==="captured-shaft"){let g=[m.shaft,...m.bearings,...m.stack,...m.stops.map(p=>p.body)];m.stops.forEach(p=>{p.attachment.kind==="threaded"&&g.push(p.attachment.thread)}),l.set(d.claim,g)}}let h=new Set,u=new Set(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 Q1("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let p of h)for(let v of l.get(p)??[])for(let y of l.get(p)??[]){let b=d.get(d1(v))??new Set;b.add(d1(y)),d.set(d1(v),b)}let m=new Set([...i].filter(p=>o.has(p))),g=[...m];for(;g.length;)for(let p of d.get(g.pop())??[])m.has(p)||(m.add(p),g.push(p));return m};for(let d of c.steps){o.add(d1(d.part));for(let p of d.fasten??[]){let v=l.get(p);if(!v)return Q1(`Step ${d.id} names an unknown fastening.`);if(v.some(y=>!o.has(d1(y))))return Q1(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(p)}let m=new Set((t.holds?.find(p=>p.step===d.id)?.bodies??[]).map(d1));if([...m].some(p=>!o.has(p)))return Q1(`Step ${d.id} holds an uninstalled body.`);let g=f();if([...o].some(p=>!g.has(p)&&!m.has(p)))return Q1(`Step ${d.id} releases a component before it is retained or supported.`)}return[...o].some(d=>!f().has(d))?Q1("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 o=n+1;o<e.length;o++)Math.abs(e[o][c])>Math.abs(e[a][c])&&(a=o);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 i=e[n][c];for(let o=c;o<e[n].length;o++)e[n][o]/=i;for(let o=n+1;o<e.length;o++){let l=e[o][c];for(let h=c;h<e[o].length;h++)e[o][h]-=l*e[n][h]}n++}return{rank:n,uncertain:r}}function _n(t,e,n,r,c,a=[]){if(t.bodies.length>64)return o1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(d1),i=t.roots.map(d1);if(new Set(s).size!==s.length||new Set(i).size!==i.length||i.some(v=>!s.includes(v)))return Q1("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>i0(e,v).some((y,b)=>Math.abs(y-i0(n,v)[b])>j)))return Q1("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(d1(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(d1(v))*6+y]=1,o.push(b)}let f=ae({...e,parts:e.parts.filter(v=>s.includes(d1({part:v.name,copy:v.copy})))});for(let v of c?.claims??[])if(v.kind==="retention")for(let y of v.links){let b=c.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(d1(v.a))&&!s.includes(d1(v.b)))){if(!s.includes(d1(v.a))||!s.includes(d1(v.b)))return o1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=te({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:j*j*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(d1(v.a))&&s.includes(d1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(r.tick(),d1(v.a)===d1(v.b))return Q1("A joint cannot connect a body to itself.");let y=i0(e,v.a),b=i0(e,v.b),x=i0(n,v.a),M=i0(n,v.b),w=q1(p0(y),b),k=q1(p0(x),M),z=A=>{let L=h();u(L,v.b,3,A),u(L,v.a,3,A,-1),o.push(L)},S=(A,L,C)=>{let P=h();u(P,v.b,0,A),u(P,v.a,0,A,-1),u(P,v.b,3,V0(C,A)),u(P,v.a,3,V0(L,A),-1),o.push(P)};if(v.kind==="fixed"){if(w.some((A,L)=>Math.abs(A-k[L])>j))return Q1("A fixed joint changes its relative transform.");l.forEach(A=>z(A)),l.forEach(A=>S(A,b1(j0(b),j0(y)),[0,0,0]))}else if(v.kind==="revolute"){let A=f0(y,v.anchorA),L=f0(b,v.anchorB),C=W1(J0(y,v.axisA)),P=W1(J0(b,v.axisB)),R=K1(W1(J0(x,v.axisA)),W1(J0(M,v.axisB)));if(S1(b1(A,L))>j||S1(V0(C,P))>1e-7||Math.abs(K1(C,P)-R)>1e-7)return Q1("Revolute anchors or axes do not coincide.");if(v.range){let q=se(w,k,v.axisB);if(!Dn(q,v.range,j).length)return Q1("A revolute joint exceeds its declared angular travel.",{angle:q})}l.forEach(q=>S(q,b1(A,j0(y)),b1(L,j0(b)))),et(C).forEach(z)}else if(v.kind==="prismatic"){let A=b1(j0(w),j0(k)),L=W1(v.axisA),C=K1(A,L);if([0,1,2,4,5,6,8,9,10].some(P=>Math.abs(w[P]-k[P])>j)||S1(b1(A,L0(L,C)))>j)return Q1("A slider rotates or moves away from its guide axis.");if(C<v.travel[0]-j||C>v.travel[1]+j)return Q1("The slider exceeds its allowed travel.",{travel:C});l.forEach(z),et(W1(J0(y,v.axisA))).forEach(P=>S(P,b1(j0(b),j0(y)),[0,0,0]))}else{let A=W1(J0(y,v.axisA)),L=W1(J0(b,v.axisB));if(S1(V0(A,L))>1e-7||S1(b1(j0(y),j0(x)))>j||S1(b1(j0(b),j0(M)))>j)return Q1("The scoped gear axes/centers are not fixed and parallel.");let C=se(y,x,v.axisA),P=se(b,M,v.axisB);if(Math.abs(C)>90||Math.abs(P)>90)return o1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(P+v.ratio*C)>1e-6)return Q1("The rendered gears do not obey their declared angular ratio.");let R=h();u(R,v.a,3,A,v.ratio),u(R,v.b,3,L),o.push(R)}}r.tick(o.length*s.length*6);let m=nl(o),g=s.length*6-m.rank;if(m.uncertain)return o1("Constraint rank is numerically singular.");let p={degreesOfFreedom:g,constraintRank:m.rank,redundantRows:o.length-m.rank};return g!==t.expectedDof?Q1("The joint graph has unintended freedom or is overconstrained.",p):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:p,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function jn(t,e,n,r){let c=o=>t.moving.find(l=>d1(l.body)===d1(o))?.trajectory??{kind:"translate",by:[0,0,0]},a=o=>o.kind==="translate"?S1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?S1(b1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?S1(b1(L0(W1(o.axis),o.angle),L0(W1(l.axis),l.angle)))<1e-9&&S1(V0(b1(o.origin,l.origin),W1(o.axis)))<1e-9:!1;if(e.roots.some(o=>!a(c(o))))return Q1("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(d1(o.b)))return o1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");i.set(d1(o.b),d1(o.a))}for(let o of i.keys()){let l=new Set,h=o;for(;h&&i.has(h);){if(l.has(h))return o1("Continuous closed-linkage constraints need a solver.");l.add(h),h=i.get(h)}}for(let o of e.joints){let l=c(o.a),h=c(o.b),u=i0(n,o.a),f=i0(n,o.b);if(o.kind==="fixed"){if(!s(l,h))return Q1("The analytic path separates a fixed joint.");continue}if(o.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return o1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=f0(u,o.anchorA),m=W1(J0(u,o.axisA)),g=W1(h.axis);if(S1(V0(m,g))>1e-9||S1(V0(b1(h.origin,d),m))>j)return Q1("The trajectory does not rotate about the actual hinge.");if(o.range){let p=q1(p0(u),f),v=q1(p0(i0(r,o.a)),i0(r,o.b)),y=h.angle*K1(W1(J0(f,o.axisB)),g),b=o.range;if(!Dn(se(p,v,o.axisB),b,j).some(M=>Math.min(M,M+y)>=b[0]-j&&Math.max(M,M+y)<=b[1]+j))return Q1("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 o1("This slider trajectory composition needs a richer constraint solver.");let d=W1(J0(u,o.axisA));if(S1(V0(h.by,d))>j)return Q1("The analytic slider path leaves its guide.");let m=q1(p0(u),f),g=q1(p0(i0(r,o.a)),i0(r,o.b)),p=K1(b1(j0(m),j0(g)),W1(o.axisA)),v=p+K1(h.by,d);if(Math.min(p,v)<o.travel[0]-j||Math.max(p,v)>o.travel[1]+j)return Q1("The continuous slider path exceeds its travel stops.")}else{let d=(p,v,y)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let b=i0(n,p),x=W1(J0(b,y));return S1(V0(W1(v.axis),x))>1e-9||S1(V0(b1(v.origin,j0(b)),x))>j?null:v.angle*K1(W1(v.axis),x)},m=d(o.a,l,o.axisA),g=d(o.b,h,o.axisB);if(m===null||g===null)return o1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(g+o.ratio*m)>1e-7)return Q1("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 Gn(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return Wn(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,o=(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:o},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 Wn(t){if(t&&typeof t=="object"){for(let e of Object.values(t))Wn(e);Object.freeze(t)}return t}function Xn(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=j5({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,i=d1(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(i))throw new Error("Pose controls must identify one unique physical instance each.");c.set(i,A3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=c.get(d1({part:a.name,copy:a.copy}));return s?{...a,matrix:q1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},i=c.get(d1(s));return i?{...a,from:f0(i,a.from),to:f0(i,a.to),up:b1(f0(i,a.up),f0(i,[0,0,0]))}:a})}}function rl(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==j||j5(e).length||_6(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(i=>[i,s[i]])):s);try{let c=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 r(e)===r(t.specification)&&r(a(c))===r(a(t.inputs))}catch{return!1}}function cl(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=j5(t);if(r.length)return{kind:"invalid-spec",issues:r};let c=_6(e);if(c.length)return{kind:"invalid-snapshot",issues:c};let a=t,s=e,i=[];for(let[p,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(p)||!Number.isSafeInteger(v)||!(v>0))&&i.push({code:"invalid-limits",path:`limits.${p}`,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:j,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.map(p=>({configuration:p.configuration,params:p.params,renderSettings:p.renderSettings,provenance:p.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(s.reduce((p,v)=>p+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(i3("$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(p=>p.id));for(let p of s)h.has(p.configuration)||i.push({code:"unknown-configuration",message:`Snapshot ${p.configuration} is not declared.`});for(let p of s){let v=a.configurations.find(y=>y.id===p.configuration)?.params??{};for(let[y,b]of Object.entries(v))JSON.stringify(p.params[y])!==JSON.stringify(b)&&i.push({code:"configuration-mismatch",message:`${p.configuration}: captured parameter ${y} differs from its required value.`})}let u=new Map(a.claims.map(p=>[p.id,p]));for(let{claim:p,ref:v}of Ln(a)){let y=u.get(p);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.${p}`,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 p of a.configurations){let v=s.find(b=>b.configuration===p.id),y=v&&v.error===void 0;o.claims.push(i3(`$configuration:${p.id}`,"configuration",!0,[p.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(i3(`$provenance:${p.id}`,"provenance",!0,[p.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&o.claims.push(i3(`$compiler:${p.id}`,"compiler-diagnostics",!0,[p.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
|
|
2723
|
+
`)})),v.legacyHardware&&o.claims.push(i3(`$legacy:${p.id}`,"hardware-inventory",!0,[p.id],{status:"unverified",code:"legacy-hardware",message:"echo hardware is not authoritative physical inventory. Migrate it to native hardware before verification."})))}let f=new ne(n.maxOperations),d=p=>p.kind==="retention"?3:p.kind==="stability"||p.kind==="assembly-support"?4:p.kind==="motion-clearance"||p.kind==="assembly-access"?2:p.kind==="joint-constraints"?1:0,m=[...a.claims].sort((p,v)=>d(p)-d(v));for(let p of m){let v=p.configurations??a.configurations.map(y=>y.id);if(p.kind==="cut-invariant"){let y=v.map(b=>s.find(x=>x.configuration===b));o.claims.push(i3(p.id,p.kind,p.required!==!1,v,y.some(b=>!b||b.error!==void 0)?o1("A required configuration is unavailable."):al(y)));continue}if(p.kind==="motion-clearance"){let y=s.find(M=>M.configuration===p.from),b=s.find(M=>M.configuration===p.to),x;if(!y||!b||y.error!==void 0||b.error!==void 0)x=o1("Motion endpoints are unavailable.");else try{if(x={status:"pass"},p.constraints){let M=a.claims.find(k=>k.id===p.constraints),w=o.claims.filter(k=>k.id===p.constraints);if(!M||M.kind!=="joint-constraints"||!w.length||w.some(k=>k.status!=="pass")||![p.from,p.to].every(k=>w.some(z=>z.configurations.includes(k))))x=o1("The motion needs verified endpoint joint constraints.");else{let k=s.find(z=>z.configuration===(M.configurations??a.configurations.map(S=>S.id))[0]);x=jn(p,M,y,k)}}if(x.status==="pass"){let M=[];for(let w of a.claims)if(w.kind==="retention")for(let k of w.links){let z=a.claims.find(S=>S.id===k.claim);k.installed&&k.fastening==="glued"&&z?.kind==="glue-contact"&&[p.from,p.to].every(S=>o.claims.some(A=>A.id===z.id&&A.configurations.includes(S)&&A.status==="pass"))&&M.push({a:z.a,b:z.b})}x=Rn(p,y,b,f,M)}}catch(M){x={status:"unverified",code:"geometry-unresolved",message:M.message}}o.claims.push(i3(p.id,p.kind,p.required!==!1,[p.from,p.to],x,Zn(p)));continue}for(let y of v){let b=s.find(k=>k.configuration===y),x=a.configurations.find(k=>k.id===y)?.materials,M=x?{...a,materials:{...a.materials,...x}}:a,w;if(!b||b.error!==void 0)w=o1("The configuration is unavailable.");else try{switch(p.kind){case"glue-contact":w=te(p,b);break;case"tab-slot":w=An(p,b,M);break;case"captured-shaft":w=Cn(p,b,M);break;case"material-assignment":w=sl(b,M);break;case"rigid-clearance":w=Fn(p,b,f);break;case"assembly-access":w=$n(p,b,f);break;case"joint-constraints":{let k=s.find(z=>z.configuration===v[0]);w=k&&k.error===void 0?_n(p,b,k,f,a,o.claims):o1("The kinematic reference configuration is unavailable.");break}case"retention":w=Nn(p,b,a,o.claims);break;case"stability":w=Un(p,b,f,o.claims,a);break;case"assembly-support":w=Bn(p,b,a,o.claims);break;default:w=o1(`The ${p.kind} capability is not implemented; it cannot inherit a geometric-fit pass.`)}}catch(k){w={status:"unverified",code:"geometry-unresolved",message:`The geometric check could not complete: ${k.message}`}}o.claims.push(i3(p.id,p.kind,p.required!==!1,[y],w,Zn(p)))}}let g=o.claims.filter(p=>p.required);o.status=g.some(p=>p.status==="fail")?"fail":g.some(p=>p.status==="unverified")?"unverified":"pass";for(let[p,v]of[["retention","Retention of permanent inventory."],["stability","Static stability under declared masses and gravity."],["assembly-access","Authored insertion and tool access paths."],["assembly-support","Support throughout the installation sequence."],["motion-clearance","Continuous nominal operating motion clearance."],["joint-constraints","Mechanism constraints and intended mobility."]]){let y=o.claims.filter(x=>x.kind===p&&x.required),b=new Set(y.filter(x=>x.status==="pass").flatMap(x=>x.configurations));(!y.length||y.some(x=>x.status!=="pass")||a.configurations.some(x=>!b.has(x.id)))&&o.uncovered.push(v)}return{kind:"report",report:o}}function i3(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 Zn(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 al(t){if(t.length<2)return o1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return o1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(r=>r.cutLines===null||r.kerf===null)))return o1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(r=>!r.label)))return o1("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 o1("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=r2(n,{part:c.name,copy:c.copy});if(!a||!Y4(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(S1(b1(c.to,c.from))-S1(b1(a.to,a.from)))>j)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 sl(t,e){if(!t.parts.length)return o1("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 o1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<r.thickness[0]-j||n.thickness>r.thickness[1]+j)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return o1("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 il=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function Yn(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(il),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 ol(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(c=>c.message).join("; ")}
|
|
2724
|
+
`;let e=Yn(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
|
|
2725
|
+
`;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(([i,o])=>`${i} ${n(o)}`).join(", ");r.push(` ${a.id}${a.configurations.length?` [${a.configurations.join(", ")}]`:""}${a.bodies.length?`: ${a.bodies.join(" / ")}`:""}${s?`; ${s}`:""}`)}}return r.join(`
|
|
2310
2726
|
`)+`
|
|
2311
|
-
`}var
|
|
2727
|
+
`}var Ld="0.9.0",Ad="0.3";export{R4 as DEFAULT_LAYERS,U8 as DEFAULT_LIMITS,L5 as HARDWARE_COLORS,q3 as HARDWARE_KINDS,l1 as KerfError,Ad as LANGUAGE_VERSION,c7 as SIGNATURES,Ld as VERSION,Ae as bendPoint,eo as diffRenders,A6 as format,ji as formatError,$e as formatSignature,Ho as importSvg,fo as instructionsHtml,Ce as meshPieces,Ni as parameters,m2 as parse,Q0 as placementMatrix,Xn as poseAssembly,Ci as render,C5 as signature,Gn as snapshotFromRender,S5 as tokenize,Yn as triage,ol as triageText,rl as verificationIsCurrent,cl as verify};
|
|
2312
2728
|
/*! Bundled license information:
|
|
2313
2729
|
|
|
2314
2730
|
opentype.js/dist/opentype.module.js:
|