@mylasertools/kerfscript 0.8.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 +69 -0
- package/LANGUAGE.md +189 -81
- 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 +1900 -274
- 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 +6 -0
- package/dist/geometry.d.ts +6 -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 +131 -52
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +131 -52
- package/dist/language.cjs +111 -32
- package/dist/language.js +111 -32
- package/dist/libraries.cjs +93 -14
- package/dist/libraries.js +93 -14
- package/dist/plot.d.cts +16 -0
- package/dist/plot.d.ts +16 -0
- package/dist/signatures.cjs +160 -1
- package/dist/signatures.js +160 -1
- package/docs/cli.md +1 -0
- package/docs/compatibility.md +0 -8
- package/docs/customizer.md +18 -0
- package/docs/library.md +42 -1
- package/docs/parts-and-sheets.md +55 -0
- package/docs/versions.md +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*! @mylasertools/kerfscript | (c) MyLaserTools | AGPL-3.0-only or commercial licence, see COMMERCIAL-LICENSE.md. Includes Clipper2 (BSL-1.0), opentype.js, tiny-inflate and string.prototype.codepointat (MIT), see THIRD-PARTY-NOTICES.md. */
|
|
2
|
-
"use strict";var q5=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Tn=Object.prototype.hasOwnProperty;var En=(t,e,n)=>e in t?q5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var In=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Vn=(t,e)=>{for(var n in e)q5(t,n,{get:e[n],enumerable:!0})},Hn=(t,e,n,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Pn(e))!Tn.call(t,r)&&r!==n&&q5(t,r,{get:()=>e[r],enumerable:!(c=Cn(e,r))||c.enumerable});return t};var On=t=>Hn(q5({},"__esModule",{value:!0}),t);var D=(t,e,n)=>En(t,typeof e!="symbol"?e+"":e,n);var T7=In((kh,P7)=>{P7.exports={}});var Ao={};Vn(Ao,{DEFAULT_LAYERS:()=>T5,DEFAULT_LIMITS:()=>r6,HARDWARE_COLORS:()=>H3,HARDWARE_KINDS:()=>r3,KerfError:()=>c1,LANGUAGE_VERSION:()=>Lo,SIGNATURES:()=>ze,VERSION:()=>So,bendPoint:()=>n4,diffRenders:()=>w8,format:()=>P4,formatError:()=>y8,formatSignature:()=>l4,importSvg:()=>B8,instructionsHtml:()=>S8,meshPieces:()=>r4,parameters:()=>v8,parse:()=>e2,placementMatrix:()=>G0,poseAssembly:()=>$6,render:()=>d8,signature:()=>O3,snapshotFromRender:()=>F6,tokenize:()=>V3,triage:()=>D6,triageText:()=>Sn,verificationIsCurrent:()=>zn,verify:()=>kn});module.exports=On(Ao);var e0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(e0||(e0={}));var I0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(I0||(I0={}));var D1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(D1||(D1={}));var N1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(N1||(N1={}));var x3=Number.MAX_SAFE_INTEGER,f0=Math.floor(Math.sqrt(x3));function N5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=x3/Math.abs(e)}function q6(t,e){return Math.abs(t)+Math.abs(e)<=x3}function J4(t,e,n,c){if(N5(t,e)&&N5(n,c)){let r=t*e,a=n*c;if(q6(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 K4(t,e,n,c){if(N5(t,e)&&N5(n,c)){let r=t*e,a=n*c;if(q6(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 Q4=BigInt(0),U5=BigInt(2),Rn=BigInt(4),Fn=BigInt(64),$n=BigInt("0xFFFFFFFFFFFFFFFF"),ne=BigInt("9223372036854775807"),t5=Number(ne/Rn),N6=Number(ne),U6=1e-12,Dn=.1,ee=Math.floor(f0/2),qn=Math.floor(Math.sqrt(Math.sqrt(x3/4)));function Nn(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:x3/e}function Un(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function Bn(t,e){if(!Number.isFinite(t)||Math.abs(t)>x3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function _n(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 J0(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 Gn(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function jn(t){return Math.abs(t)<=U6}function Wn(t){return t<0?-1:t>0?1:0}function Xn(t,e){let n=BigInt(t),c=BigInt(e),r=n*c;return{lo64:r&$n,hi64:r>>Fn}}function B6(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 Zn(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 B6(c,r,a,s)}function Yn(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:K4(c,r,a,s)}function Jn(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===Q4?0:i>Q4?1:-1}function Kn(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)>=ee||Math.abs(s.y)>=ee)&&(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=Q4;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 Qn(t,e){return t.y*e.x-e.y*t.x}function e9(t,e){return t.x*e.x+t.y*e.y}function t9(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function n9(t){return t>=t5||t<=-t5?N6:Math.round(t)}function c9(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 r9(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 a9(t,e,n,c,r=!1){if(!r){let l=J0(t,n,c),h=J0(e,n,c),u=J0(n,t,e),f=J0(c,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=J0(t,n,c),s=J0(e,n,c);if(a!==0&&a===s)return!1;let i=J0(n,t,e),o=J0(c,t,e);return i!==0&&i===o?!1:a!==0||s!==0||i!==0||o!==0}function _6(t){if(t.length===0)return{left:0,top:0,right:0,bottom:0};let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of t)n.x<e.left&&(e.left=n.x),n.x>e.right&&(e.right=n.x),n.y<e.top&&(e.top=n.y),n.y>e.bottom&&(e.bottom=n.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function s9(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=K4(t.x-e.x,c,t.y-e.y,r)/K4(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 te(t,e){let n=e.length,c=0;if(n<3)return N1.IsOutside;for(;c<n&&e[c].y===t.y;)c++;if(c===n)return N1.IsOutside;let r=e[c].y<t.y,a=r,s=0,i=c+1,o=n;for(;;){if(i===o){if(o===0||c===0)break;o=c,i=0}if(r)for(;i<o&&e[i].y<t.y;)i++;else for(;i<o&&e[i].y>t.y;)i++;if(i===o)continue;let h=e[i],u=i>0?e[i-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return N1.IsOn;if(i++,i===c)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)s=1-s;else{let f=J0(u,h,t);if(f===0)return N1.IsOn;f<0===r&&(s=1-s)}r=!r,i++}if(r===a)return s===0?N1.IsOutside:N1.IsInside;i===n&&(i=0);let l=i===0?J0(e[n-1],e[0],t):J0(e[i-1],e[i],t);return l===0?N1.IsOn:(l<0===r&&(s=1-s),s===0?N1.IsOutside:N1.IsInside)}function i9(t,e){let n=N1.IsOn;for(let i of t)switch(te(i,e)){case N1.IsOutside:if(n===N1.IsOutside)return!1;n=N1.IsOutside;break;case N1.IsInside:if(n===N1.IsInside)return!0;n=N1.IsInside;break;default:break}let c=_6(t),r,a;return Number.isSafeInteger(c.left)&&Number.isSafeInteger(c.right)&&Math.abs(c.left)+Math.abs(c.right)>Number.MAX_SAFE_INTEGER?(r=Number((BigInt(c.left)+BigInt(c.right))/U5),a=Number((BigInt(c.top)+BigInt(c.bottom))/U5)):(r=Math.round((c.left+c.right)/2),a=Math.round((c.top+c.bottom)/2)),te({x:r,y:a},e)!==N1.IsOutside}var V1={MaxInt64:ne,MaxCoord:t5,max_coord:t5,min_coord:-t5,Invalid64:N6,floatingPointTolerance:U6,defaultMinimumEdgeLength:Dn,maxCoordForSafeAreaProduct:ee,maxCoordForSafeCrossSq:qn,maxSafeCoordinateForScale:Nn,checkSafeScaleValue:Un,ensureSafeInteger:Bn,crossProduct:_n,crossProductSign:J0,checkPrecision:Gn,isAlmostZero:jn,triSign:Wn,multiplyUInt64:Xn,productsAreEqual:B6,isCollinear:Zn,dotProduct:Yn,dotProductSign:Jn,area:Kn,crossProductD:Qn,dotProductD:e9,roundToEven:t9,checkCastInt64:n9,getLineIntersectPt:c9,getLineIntersectPtD:r9,segsIntersect:a9,getBounds:_6,getClosestPtOnSegment:s9,pointInPolygon:te,path2ContainsPath1:i9},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} `}},B5={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))/U5),n=Number((BigInt(t.top)+BigInt(t.bottom))/U5);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}]}},ce={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 G6=Object.freeze(t3.createInvalid()),j6=Object.freeze(ce.createInvalid());var n5=BigInt(0),o9=BigInt(2),W6=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 re=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}},c5=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}},r5=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 X6(t,e,n){return{pt:t,edge1:e,edge2:n}}var A2=class{constructor(e,n){D(this,"pt");D(this,"next");D(this,"prev");D(this,"outrec");D(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},H0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(H0||(H0={}));var ae;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(ae||(ae={}));var _5=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)}},G5=class{constructor(e){D(this,"leftOp");D(this,"rightOp");D(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},a5=class{constructor(e,n){D(this,"op1");D(this,"op2");this.op1=e,this.op2=n}};function l9(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function h9(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 s5=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)}},M3={addLocMin(t,e,n,c){if((t.flags&X1.LocalMin)!==X1.None)return;t.flags|=X1.LocalMin;let r=new r5(t,e,n);c.push(r)},addPathsToVertexList(t,e,n,c,r){for(let a=0,s=t.length;a<s;a++){let i=t[a],o=null,l=null,h=null;for(let p=0,m=i.length;p<m;p++){let g=i[p];if(o===null)o=new c5(g,X1.None,null),r.push(o),l=o,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new c5(g,X1.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!n&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!n&&l.next===l))continue;let u;if(n){let p=o.next;for(;p!==o&&p.pt.y===o.pt.y;)p=p.next;u=p.pt.y<=o.pt.y,u?(o.flags=X1.OpenStart,M3.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,M3.addLocMin(l,e,n,c)),l=d,d=d.next;n?(l.flags|=X1.OpenEnd,u?l.flags|=X1.LocalMax:M3.addLocMin(l,e,n,c)):u!==f&&(f?M3.addLocMin(l,e,!1,c):l.flags|=X1.LocalMax)}}};var j5=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
|
-
`}},W5=class t extends j5{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:se.area(this.polygon);for(let c of this.children)n+=c.area();return n}};var i5=class extends W5{};var T=class T{constructor(){D(this,"cliptype",e0.NoClip);D(this,"fillrule",D1.EvenOdd);D(this,"actives",null);D(this,"sel",null);D(this,"minimaList",[]);D(this,"intersectList",[]);D(this,"vertexList",[]);D(this,"outrecList",[]);D(this,"scanlineHeap",new re);D(this,"scanlineSet",new Set);D(this,"scanlineArr",[]);D(this,"useScanlineArray",!1);D(this,"horzSegList",[]);D(this,"horzJoinList",[]);D(this,"currentLocMin",0);D(this,"currentBotY",0);D(this,"curXValidAtTop",!1);D(this,"isSortedMinimaList",!1);D(this,"hasOpenPaths",!1);D(this,"usingPolytree",!1);D(this,"succeeded",!1);D(this,"zCallbackInternal");D(this,"preserveCollinear",!0);D(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,c){let r=this.zCallbackInternal;r&&(T.getPolyType(e)===I0.Subject?(this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:c.z=0,r(e.bot,e.top,n.bot,n.top,c)):(this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:c.z=0,r(n.bot,n.top,e.bot,e.top,c)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return T.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return T.openPathsEnabled&&e.localMin.isOpen&&T.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(X1.OpenStart|X1.OpenEnd))!==X1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!T.openPathsEnabled){for(;n!==null&&!T.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!T.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let c=n.y-e.y;return c!==0?(n.x-e.x)/c:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:V1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=T.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&X1.LocalMax)!==X1.None}static isMaximaEdge(e){return(e.vertexTop.flags&X1.LocalMax)!==X1.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,c,r){let a=e.x<n.x?e.x:n.x;if((c.x>r.x?c.x:r.x)<a)return!1;let i=e.x>n.x?e.x:n.x,o=c.x<r.x?c.x:r.x;if(i<o)return!1;let l=e.y<n.y?e.y:n.y;if((c.y>r.y?c.y:r.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=c.y<r.y?c.y:r.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,c=e.length;n<c;n++){let r=e[n];this.scanlineSet.add(r),this.scanlineHeap.push(r)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let c=0,r=n.length;c<r;c++)if(n[c]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,c=n.length;if(c===0)return null;let r=0,a=n[0];for(let s=1;s<c;s++){let i=n[s];i>a&&(a=i,r=s)}return n[r]=n[c-1],n.pop(),a}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,c=!1){let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c=!1){c&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,M3.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 r5(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,c=e.nextInAEL;n===null&&c===null&&e!==this.actives||(n!==null?n.nextInAEL=c:this.actives=c,c!==null&&(c.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let c=n;do c.pt.x<e.left&&(e.left=c.pt.x),c.pt.x>e.right&&(e.right=c.pt.x),c.pt.y<e.top&&(e.top=c.pt.y),c.pt.y>e.bottom&&(e.bottom=c.pt.y),c=c.next;while(c!==n)}return t3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===e0.NoClip)return;T.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let c=this.popScanline();if(c!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(c);let r;for(;(r=this.popHorz())!==null;)this.doHorizontal(r);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=c;let a=this.popScanline();if(a===null)break;for(c=a,this.doIntersections(c),this.doTopOfScanbeam(c);(r=this.popHorz())!==null;)this.doHorizontal(r)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),c;(n.vertex.flags&X1.OpenStart)!==X1.None?c=null:(c=new s5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=-1,c.vertexTop=n.vertex.prev,c.top=n.vertex.prev.pt,c.outrec=null,c.localMin=n,T.setDx(c));let r;if((n.vertex.flags&X1.OpenEnd)!==X1.None?r=null:(r=new s5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=1,r.vertexTop=n.vertex.next,r.top=n.vertex.next.pt,r.outrec=null,r.localMin=n,T.setDx(r)),c!==null&&r!==null){if(T.isHorizontal(c)){if(T.isHeadingRightHorz(c)){let s=c;c=r,r=s}}else if(T.isHorizontal(r)){if(T.isHeadingLeftHorz(r)){let s=c;c=r,r=s}}else if(c.dx<r.dx){let s=c;c=r,r=s}}else c===null&&(c=r,r=null);let a;if(c.isLeftBound=!0,this.insertLeftEdge(c),T.openPathsEnabled?T.isOpen(c)?(this.setWindCountForOpenPathEdge(c),a=this.isContributingOpen(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)),r!==null){for(r.windCount=c.windCount,r.windCount2=c.windCount2,this.insertRightEdge(c,r),a&&(this.addLocalMinPoly(c,r,c.bot,!0),T.isHorizontal(c)||this.checkJoinLeft(c,c.bot));r.nextInAEL!==null&&this.isValidAelOrder(r.nextInAEL,r);)this.intersectEdges(r,r.nextInAEL,r.bot),this.swapPositionsInAEL(r,r.nextInAEL);T.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else a&&T.openPathsEnabled&&this.startOpenPath(c,c.bot);T.isHorizontal(c)?this.pushHorz(c):this.insertScanline(c.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!T.openPathsEnabled){this.doHorizontalClosed(e);return}let n=T.isOpen(e),c=e.bot.y,r=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:i}=this.resetHorzDirection(e,r),o=s,l=i;if(T.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:c});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===r){if(T.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),T.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(r!==e.vertexTop||T.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!T.isHorizontal(h)){let d=T.nextVertex(e).pt;if(T.isOpen(h)&&!T.isSamePolyType(h,e)&&!T.isHotEdge(h)){if(a&&T.topX(h,d.y)>d.x||!a&&T.topX(h,d.y)<d.x)break}else if(a&&T.topX(h,d.y)>=d.x||!a&&T.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:c};a?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),T.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&T.isOpenEnd(e)){T.isHotEdge(e)&&(this.addOutPt(e,e.top),T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(T.nextVertex(e).pt.y!==e.top.y)break;T.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,r);o=u.leftX,l=u.rightX}if(T.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,c=this.getCurrYMaximaVertex(e),{isLeftToRight:r,leftX:a,rightX:s}=this.resetHorzDirection(e,c),i=a,o=s;if(T.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=r?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===c){if(T.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),T.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);r?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(c!==e.vertexTop){if(r&&l.curX>o||!r&&l.curX<i)break;if(l.curX===e.top.x&&!T.isHorizontal(l)){let f=T.nextVertex(e).pt,d=T.topX(l,f.y);if(r&&d>=f.x||!r&&d<=f.x)break}}let u={x:l.curX,y:n};r?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),T.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(T.nextVertex(e).pt.y!==e.top.y)break;T.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(T.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let c=0,r=e.length;c<r;c++){let a=e[c];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(l9);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 a5(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 a5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(r.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let n=e.leftOp,c=this.getRealOutRec(n.outrec),r=c.frontEdge!==null,a=n.pt.y,s=n,i=n;if(r){let l=c.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;i!==l&&i.next.pt.y===a;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===a;)s=s.prev;for(;i.next!==s&&i.next.pt.y===a;)i=i.next}let o=this.setHorzSegHeadingForward(e,s,i)&&e.leftOp.horz===null;return o?e.leftOp.horz=e:e.rightOp=null,o}setHorzSegHeadingForward(e,n,c){return n.pt.x===c.pt.x?!1:(n.pt.x<c.pt.x?(e.leftOp=n,e.rightOp=c,e.leftToRight=!0):(e.leftOp=c,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let c=new A2(e.pt,e.outrec);return n?(c.next=e.next,c.next.prev=c,c.prev=e,e.next=c):(c.prev=e.prev,c.prev.next=c,c.next=e,e.prev=c),c}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let c=this.actives;for(;c!==null;){if(c.top.y===e)if(c.curX=c.top.x,T.isMaximaEdge(c)){c=this.doMaxima(c);continue}else T.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),T.isHorizontal(c)&&this.pushHorz(c);else n||(c.curX=T.topX(c,e));c=c.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),c=this.getRealOutRec(e.op2.outrec),r=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,r.prev=a,a.next=r,n===c){let s=this.newOutRec();s.pts=r,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.owner=n}else c.pts=null,this.usingPolytree?(this.setOwner(c,n),this.moveSplits(c,n)):c.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let c=N1.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,n)){case N1.IsOutside:if(c===N1.IsOutside)return!1;c=N1.IsOutside;break;case N1.IsInside:if(c===N1.IsInside)return!0;c=N1.IsInside;break;default:break}r=r.next}while(r!==e);return V1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return N1.IsOutside;let c=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==c);if(n.pt.y===e.y)return N1.IsOutside;let r=n.pt.y<e.y,a=r,s=0;for(c=n.next;c!==n;){if(r)for(;c!==n&&c.pt.y<e.y;)c=c.next;else for(;c!==n&&c.pt.y>e.y;)c=c.next;if(c===n)break;if(c.pt.y===e.y){if(c.pt.x===e.x||c.pt.y===c.prev.pt.y&&e.x<c.prev.pt.x!=e.x<c.pt.x)return N1.IsOn;if(c=c.next,c===n)break;continue}if(c.pt.x<=e.x||c.prev.pt.x<=e.x)if(c.prev.pt.x<e.x&&c.pt.x<e.x)s=1-s;else{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return N1.IsOn;i<0===r&&(s=1-s)}r=!r,c=c.next}if(r===a)return s===0?N1.IsOutside:N1.IsInside;{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return N1.IsOn;i<0===r&&(s=1-s)}return s===0?N1.IsOutside:N1.IsInside}getCleanPath(e){let n=[],c=e;for(;c.next!==e&&(c.pt.x===c.next.pt.x&&c.pt.x===c.prev.pt.x||c.pt.y===c.next.pt.y&&c.pt.y===c.prev.pt.y);)c=c.next;n.push(c.pt);let r=c;for(c=c.next;c!==e;)(c.pt.x!==c.next.pt.x||c.pt.x!==r.pt.x)&&(c.pt.y!==c.next.pt.y||c.pt.y!==r.pt.y)&&(n.push(c.pt),r=c),c=c.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let c of e.splits)c!==n.idx&&n.splits.push(c);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let c=null;for(;n!==null&&n.jump!==null;){let r=n,a=n.jump,s=a,i=a?.jump||null;for(n.jump=i;n!==s&&a!==i;)if(a.curX<n.curX){let o=a.prevInSEL;for(;this.addNewIntersectNode(o,a,e),o!==n;)o=o.prevInSEL;if(o=a,a=this.extractFromSEL(o),s=a,n!==null&&this.insert1Before2InSEL(o,n),n!==r)continue;r=o,r.jump=i,c===null?this.sel=r:c.jump=r}else n=n.nextInSEL;c=r,n=i}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(h9);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let c=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[c]);)c++;[this.intersectList[c],this.intersectList[e]]=[this.intersectList[e],this.intersectList[c]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let c=Number.NEGATIVE_INFINITY,r=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=T.topX(n,e);n.curX=a,a<c&&(r=!0),c=a,n=n.nextInAEL}return r}doMaxima(e){let n=e.prevInAEL,c=e.nextInAEL;if(T.isOpenEnd(e))return T.isHotEdge(e)&&this.addOutPt(e,e.top),T.isHorizontal(e)||(T.isHotEdge(e)&&(T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let r=T.getMaximaPair(e);if(r===null)return c;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(r)&&this.split(r,r.top);c!==r;)this.intersectEdges(e,c,e.top),this.swapPositionsInAEL(e,c),c=e.nextInAEL;return T.isOpen(e)?(T.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(r),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(T.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(e),this.deleteFromAEL(r),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=T.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,T.setDx(e),this.isJoined(e)&&this.split(e,e.bot),T.isHorizontal(e)){T.openPathsEnabled?T.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let c=!1,r=T.nextVertex(e).pt;for(;r.y===e.top.y&&!(n&&r.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=T.nextVertex(e),e.top=r,c=!0,T.isMaximaVertex(e.vertexTop)));)r=T.nextVertex(e).pt;c&&T.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new G5(e))}addNewIntersectNode(e,n,c){let r=V1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(r===null&&(r={x:e.curX,y:c}),r.y>this.currentBotY||r.y<c){let s=Math.abs(e.dx),i=Math.abs(n.dx);s>100&&i>100?s>i?r=V1.getClosestPtOnSegment(r,e.bot,e.top):r=V1.getClosestPtOnSegment(r,n.bot,n.top):s>100?r=V1.getClosestPtOnSegment(r,e.bot,e.top):i>100?r=V1.getClosestPtOnSegment(r,n.bot,n.top):(r.y<c?r.y=c:r.y=this.currentBotY,s<i?r.x=T.topX(e,r.y):r.x=T.topX(n,r.y))}let a=X6(r,e,n);this.intersectList.push(a)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.prev;return T.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return T.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let c=e.curX,r=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:c,rightX:r}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===H0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===D1.EvenOdd){let c=0,r=0;for(;n!==e;)T.getPolyType(n)===I0.Clip?r++:T.isOpen(n)||c++,n=n.nextInAEL;e.windCount=T.isOdd(c)?1:0,e.windCount2=T.isOdd(r)?1:0}else for(;n!==e;)T.getPolyType(n)===I0.Clip?e.windCount2+=n.windDx:T.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,c=T.getPolyType(e);if(!T.openPathsEnabled){for(;n!==null&&T.getPolyType(n)!==c;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===D1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===D1.EvenOdd)for(;n!==e;)T.getPolyType(n)!==c&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)T.getPolyType(n)!==c&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(T.getPolyType(n)!==c||T.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===D1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=T.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===D1.EvenOdd)for(;n!==e;)T.getPolyType(n)!==c&&!T.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)T.getPolyType(n)!==c&&!T.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,c;switch(this.fillrule){case D1.Positive:c=e.windCount>0,n=e.windCount2>0;break;case D1.Negative:c=e.windCount<0,n=e.windCount2<0;break;default:c=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case e0.Intersection:return n;case e0.Union:return!c&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case D1.Positive:if(e.windCount!==1)return!1;break;case D1.Negative:if(e.windCount!==-1)return!1;break;case D1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case e0.Intersection:return this.fillrule===D1.Positive?e.windCount2>0:this.fillrule===D1.Negative?e.windCount2<0:e.windCount2!==0;case e0.Union:return this.fillrule===D1.Positive?e.windCount2<=0:this.fillrule===D1.Negative?e.windCount2>=0:e.windCount2===0;case e0.Difference:{let n=this.fillrule===D1.Positive?e.windCount2<=0:this.fillrule===D1.Negative?e.windCount2>=0:e.windCount2===0;return T.getPolyType(e)===I0.Subject?n:!n}case e0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,c,r=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,T.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let i=T.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(a,i.outrec),a.owner=i.outrec,this.outrecIsAscending(i)===r?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,r?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new A2(c,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new _5;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let c=this.newOutRec();c.isOpen=!0,e.windDx>0?(c.frontEdge=e,c.backEdge=null):(c.frontEdge=null,c.backEdge=e),e.outrec=c;let r=new A2(n,c);return c.pts=r,r}checkJoinLeft(e,n,c=!1){let r=e.prevInAEL;r!==null&&(!c&&e.curX!==r.curX||!T.isHotEdge(e)||!T.isHotEdge(r)||T.isHorizontal(e)||T.isHorizontal(r)||T.isOpen(e)||T.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(r,e,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),r.joinWith=H0.Right,e.joinWith=H0.Left))}checkJoinRight(e,n,c=!1){let r=e.nextInAEL;r!==null&&(!c&&e.curX!==r.curX||!T.isHotEdge(e)||!T.isHotEdge(r)||T.isHorizontal(e)||T.isHorizontal(r)||T.isOpen(e)||T.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(e,r,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),e.joinWith=H0.Right,r.joinWith=H0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,c){let r=e.x-n.x,a=e.y-n.y,s=c.x-n.x,i=c.y-n.y;if(s===0&&i===0)return!1;let o=V1.maxCoordForSafeCrossSq;if(Math.abs(r)<o&&Math.abs(a)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=r*i-s*a;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(r)*BigInt(i)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return W6*u>f}let l=r*i-s*a;return l*l/(s*s+i*i)>.25}intersectEdges(e,n,c){let r;if(this.hasOpenPaths&&(T.isOpen(e)||T.isOpen(n))){if(T.isOpen(e)&&T.isOpen(n))return;if(T.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,c),this.cliptype===e0.Union){if(!T.isHotEdge(n))return}else if(n.localMin.polytype===I0.Subject)return;switch(this.fillrule){case D1.Positive:if(n.windCount!==1)return;break;case D1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(T.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(c.x===e.localMin.vertex.pt.x&&c.y===e.localMin.vertex.pt.y&&!T.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&T.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}r=this.startOpenPath(e,c)}else r=this.startOpenPath(e,c);this.setZ(e,n,r.pt);return}this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===D1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==D1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==D1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case D1.Positive:a=e.windCount,s=n.windCount;break;case D1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let i=a===0||a===1,o=s===0||s===1;if(!(!T.isHotEdge(e)&&!i||!T.isHotEdge(n)&&!o))if(T.isHotEdge(e)&&T.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==e0.Xor)r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);else if(T.isFront(e)||e.outrec===n.outrec){r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);let l=this.addLocalMinPoly(e,n,c);this.setZ(e,n,l.pt)}else{r=this.addOutPt(e,c),this.setZ(e,n,r.pt);let l=this.addOutPt(n,c);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(T.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else if(T.isHotEdge(n))r=this.addOutPt(n,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case D1.Positive:l=e.windCount2,h=n.windCount2;break;case D1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!T.isSamePolyType(e,n))r=this.addLocalMinPoly(e,n,c),this.setZ(e,n,r.pt);else if(a===1&&s===1){switch(r=null,this.cliptype){case e0.Union:if(l>0&&h>0)return;r=this.addLocalMinPoly(e,n,c);break;case e0.Difference:(T.getPolyType(e)===I0.Clip&&l>0&&h>0||T.getPolyType(e)===I0.Subject&&l<=0&&h<=0)&&(r=this.addLocalMinPoly(e,n,c));break;case e0.Xor:r=this.addLocalMinPoly(e,n,c);break;default:if(l<=0||h<=0)return;r=this.addLocalMinPoly(e,n,c);break}r&&this.setZ(e,n,r.pt)}}}swapPositionsInAEL(e,n){let c=n.nextInAEL;c!==null&&(c.prevInAEL=e);let r=e.prevInAEL;r!==null&&(r.nextInAEL=n),n.prevInAEL=r,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=c,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let c=V1.crossProductSign(e.top,n.bot,n.top);if(c!==0)return c<0;if(!T.isMaximaEdge(e)&&e.top.y>n.top.y)return V1.crossProductSign(n.bot,e.top,T.nextVertex(e).pt)<=0;if(!T.isMaximaEdge(n)&&n.top.y>e.top.y)return V1.crossProductSign(n.bot,n.top,T.nextVertex(n).pt)>=0;let r=n.bot.y,a=n.isLeftBound;return e.bot.y!==r||e.localMin.vertex.pt.y!==r?n.isLeftBound:e.isLeftBound!==a?a:V1.isCollinear(T.prevPrevVertex(e).pt,e.bot,e.top)?!0:V1.crossProductSign(T.prevPrevVertex(e).pt,n.bot,T.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==H0.None}split(e,n){e.joinWith===H0.Right?(e.joinWith=H0.None,e.nextInAEL.joinWith=H0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=H0.None,e.prevInAEL.joinWith=H0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,c){e.frontEdge=n,e.backEdge=c}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!T.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!T.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let c=e.outrec,r=T.isFront(e),a=c.pts,s=a.next;if(r&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!r&&n.x===s.pt.x&&n.y===s.pt.y)return s;let i=new A2(n,c);return s.prev=i,i.prev=a,i.next=s,a.next=i,r&&(c.pts=i),i}addLocalMaxPoly(e,n,c){if(this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c),T.isFront(e)===T.isFront(n))if(T.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(T.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let r=this.addOutPt(e,c);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=r,this.usingPolytree){let s=T.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else T.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return r}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let c=n;for(;c!==null&&c!==e;)c=c.owner;c!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let c=e.outrec.pts,r=n.outrec.pts,a=c.next,s=r.next;T.isFront(e)?(s.prev=c,c.next=s,r.next=a,a.prev=r,e.outrec.pts=r,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=r,r.next=a,c.next=s,s.prev=c,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),T.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let c=e.outrec,r=n.outrec;if(c===r){let a=c.frontEdge;c.frontEdge=c.backEdge,c.backEdge=a;return}c!==null&&(e===c.frontEdge?c.frontEdge=n:c.backEdge=n),r!==null&&(n===r.frontEdge?r.frontEdge=e:r.backEdge=e),e.outrec=r,n.outrec=c}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(T.ptsReallyClose(e.prev.pt,e.next.pt)||T.ptsReallyClose(e.pt,e.next.pt)||T.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,c,r){if(e===null||e.next===e||!c&&e.next===e.prev)return!1;r.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),r.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,r.push(a)),n?s=s.prev:s=s.next;return r.length!==3||c||!T.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts===null)continue;let a=[];r.isOpen?T.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(r),T.buildPath(r.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts!==null){if(r.isOpen){let a=[];T.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(r)&&this.recursiveCheckOwners(r,e)}}}checkBounds(e){return e.pts===null?!1:t3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!T.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=V1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||t3.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,c=n;for(;;){if(c!==null&&V1.isCollinear(c.prev.pt,c.pt,c.next.pt)&&(c.pt.x===c.prev.pt.x&&c.pt.y===c.prev.pt.y||c.pt.x===c.next.pt.x&&c.pt.y===c.next.pt.y||!this.preserveCollinear||V1.dotProductSign(c.prev.pt,c.pt,c.next.pt)<0)){if(c===e.pts&&(e.pts=c.prev),c=this.disposeOutPt(c),!this.isValidClosedPath(c)){e.pts=null;return}n=c;continue}if(c===null||(c=c.next,c===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!T.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&V1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let c=n.prev,r=n.next.next;e.pts=c;let a=V1.getLineIntersectPt(c.pt,n.pt,n.next.pt,r.pt);this.zCallbackInternal&&this.zCallbackInternal(c.pt,n.pt,n.next.pt,r.pt,a);let s=T.areaOutPt(c),i=s<n5?-s:s;if(i<W6){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<n5?-o:o;if(a.x===c.pt.x&&a.y===c.pt.y||a.x===r.pt.x&&a.y===r.pt.y)r.prev=c,c.next=r;else{let f=new A2(a,e);f.prev=c,f.next=r,r.prev=f,c.next=f}if(!(l>o9)||!(l>i)&&o>n5!=s>n5)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new A2(a,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(c,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=V1.maxCoordForSafeAreaProduct,c=0,r=!0,a=e;do{let i=a.prev,o=a.pt;if(Math.abs(i.pt.x)>=n||Math.abs(i.pt.y)>=n||Math.abs(o.x)>=n||Math.abs(o.y)>=n){r=!1;break}c+=(i.pt.y+o.y)*(i.pt.x-o.x),a=a.next}while(a!==e);if(r)return BigInt(Math.round(c));let s=n5;a=e;do{let i=a.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(a.pt.x)){let o=BigInt(i.pt.y)+BigInt(a.pt.y),l=BigInt(i.pt.x)-BigInt(a.pt.x);s+=o*l}else{let o=i.pt.y+a.pt.y,l=i.pt.x-a.pt.x;s+=BigInt(Math.round(o*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,c){let r=V1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<r&&Math.abs(e.y)<r&&Math.abs(n.x)<r&&Math.abs(n.y)<r&&Math.abs(c.x)<r&&Math.abs(c.y)<r){let s=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(c.y)){let s=(BigInt(c.y)+BigInt(e.y))*(BigInt(c.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),o=(BigInt(n.y)+BigInt(c.y))*(BigInt(n.x)-BigInt(c.x));return s+i+o}let a=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(a))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let c=0;c<n.length;c++){let r=this.outrecList[n[c]];if(r.pts===null&&r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(r=this.getRealOutRec(r),!(r===null||r===e||r.recursiveSplit===e)){if(r.recursiveSplit=e,r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(!(!this.checkBounds(r)||!this.containsRect(r.bounds,e.bounds)||!this.path1InsidePath2(e.pts,r.pts)))return this.isValidOwner(e,r)||(r.owner=e.owner),e.owner=r,!0}}return!1}};D(T,"openPathsEnabled",!0);var X5=T,g2=class extends X5{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 se={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(se.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(se.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 ie=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 ie(e,n,c))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===s0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===s0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/a0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),c=n?D1.Negative:D1.Positive,r=new g2;r.preserveCollinear=this.preserveCollinear,r.reverseSolution=this.reverseSolution!==n,r.zCallback=this.ZCB,r.addSubject(this.solution),this.solutionTree!==null?r.execute(e0.Union,c,this.solutionTree):r.execute(e0.Union,c,this.solution)}execute(e,n){if(Array.isArray(n)){let c=n;c.length=0,this.solution=c,this.executeInternal(e)}else{let c=n;c.clear(),this.solutionTree=c,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let c=n.x-e.x,r=n.y-e.y;if(c===0&&r===0)return{x:0,y:0};let a=1/Math.sqrt(c*c+r*r);return{x:r*a,y:-c*a}}static getLowestPathInfo(e){let n=-1,c=!1,r={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let i of e[a])if(!(i.y<r.y||i.y===r.y&&i.x>=r.x)){if(s===Number.MAX_VALUE){if(s=a0.area(e[a]),s===0)break;c=s<0}n=a,r.x=i.x,r.y=i.y}}return{idx:n,isNegArea:c}}static translatePoint(e,n,c){return{x:e.x+n,y:e.y+c,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=a0.hypotenuse(e.x,e.y);if(a0.almostZero(n))return{x:0,y:0};let c=1/n;return{x:e.x*c,y:e.y*c}}static getAvgUnitVector(e,n){return a0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,c,r){if(V1.isAlmostZero(e.x-n.x)){if(V1.isAlmostZero(c.x-r.x))return{x:0,y:0};let a=(r.y-c.y)/(r.x-c.x),s=c.y-a*c.x;return{x:e.x,y:a*e.x+s}}if(V1.isAlmostZero(c.x-r.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:c.x,y:a*c.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,i=(r.y-c.y)/(r.x-c.x),o=c.y-i*c.x;if(V1.isAlmostZero(a-i))return{x:0,y:0};let l=(o-s)/(a-i);return{x:l,y:a*l+s}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,c){let r,a,s=e[n].z||0;if(n===c){let i=Math.abs(this.groupDelta);r={x:Math.round(e[n].x-i*this.normals[n].x),y:Math.round(e[n].y-i*this.normals[n].y),z:s},a={x:Math.round(e[n].x+i*this.normals[n].x),y:Math.round(e[n].y+i*this.normals[n].y),z:s}}else r={x:Math.round(e[n].x+this.groupDelta*this.normals[c].x),y:Math.round(e[n].y+this.groupDelta*this.normals[c].y),z:s},a={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:s};this.pathOut.push(r),this.pathOut.push(a)}doSquare(e,n,c){let r;n===c?r={x:this.normals[n].y,y:-this.normals[n].x}:r=a0.getAvgUnitVector({x:-this.normals[c].y,y:this.normals[c].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=a0.translatePoint(s,a*r.x,a*r.y);let i=a0.translatePoint(s,this.groupDelta*r.y,this.groupDelta*-r.x),o=a0.translatePoint(s,this.groupDelta*-r.y,this.groupDelta*r.x),l=this.getPerpendicD(e[c],this.normals[c]);if(n===c){let h={x:l.x+r.x*this.groupDelta,y:l.y+r.y*this.groupDelta},u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s))),this.pathOut.push(m2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[c]),u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(u)),this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s)))}}doMiter(e,n,c,r){let a=this.groupDelta/(r+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[c].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[c].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,c,r){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*a0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let a=e[n],s=a.z||0,i={x:this.normals[c].x*this.groupDelta,y:this.normals[c].y*this.groupDelta};n===c&&B5.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 qo=BigInt(2);function le(t,e,n){return typeof e=="number"?oe(e0.Union,t,null,e):oe(e0.Union,t,e,n)}function oe(t,e,n,c){let r=[];if(e===null)return r;let a=new g2;return a.addPaths(e,I0.Subject),n!==null&&a.addPaths(n,I0.Clip),a.execute(t,c,r),r}function Z5(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 c2=1e4,he=[1,0,0,1,0,0];function K0(){return{layers:new Map,parts:[]}}function k0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function D2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function J6(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 K6=t=>t.map(e=>e.map(([n,c])=>({x:Math.round(n*c2),y:Math.round(c*c2)})));function d9(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 o5=t=>K6(t).map(d9),h5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/c2,n.y/c2]));function x1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?D1.EvenOdd:D1.NonZero;return h5(le(o5(t),n)).filter(c=>c.length>=3)}function ue(t,e,n){if(!e.length)return[];let c=new g2;c.addSubject(o5(e)),n.length&&c.addClip(o5(n));let r=[];return c.execute(t,D1.NonZero,r),h5(r).filter(a=>a.length>=3)}var b0=(t,e)=>e.length?ue(e0.Difference,t,e):x1(t),x0=(t,e)=>ue(e0.Intersection,t,e),w3=(t,e)=>ue(e0.Xor,t,e);function v2(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let c=[];for(let m of e)for(let g=0;g<m.length;g++){let v=m[g],y=m[(g+1)%m.length];(v[0]!==y[0]||v[1]!==y[1])&&c.push([v,y])}if(!c.length)return n==="outside"?t:[];let r=S0(e),a=Math.max(r[2]-r[0],r[3]-r[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=m=>Math.floor(m/a),i=new Map,o=new Map,l=(m,g,v)=>{let y=m.get(g);y?y[y.length-1]!==v&&y.push(v):m.set(g,[v])};c.forEach(([m,g],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let b=0;b<=y;b++){let x=m[0]+(g[0]-m[0])*b/y,M=m[1]+(g[1]-m[1])*b/y;for(let w of[-1,0,1])for(let k of[-1,0,1])l(i,`${s(x)+w},${s(M)+k}`,v)}for(let b=s(Math.min(m[1],g[1]));b<=s(Math.max(m[1],g[1]));b++)l(o,b,v)});let h=(m,g)=>{let v=new Set,y=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let b=0;b<=y;b++){let x=m[0]+(g[0]-m[0])*b/y,M=m[1]+(g[1]-m[1])*b/y;for(let w of i.get(`${s(x)},${s(M)}`)??[])v.add(w)}return v},u=.5/c2,f=m=>{for(let v of i.get(`${s(m[0])},${s(m[1])}`)??[]){let[y,b]=c[v],x=b[0]-y[0],M=b[1]-y[1],w=Math.max(0,Math.min(1,((m[0]-y[0])*x+(m[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(m[0]-y[0]-w*x,m[1]-y[1]-w*M)<=u)return}let g=0;for(let v of o.get(s(m[1]))??[]){let[y,b]=c[v],x=(b[0]-y[0])*(m[1]-y[1])-(m[0]-y[0])*(b[1]-y[1]);y[1]<=m[1]?b[1]>m[1]&&x>0&&g++:b[1]<=m[1]&&x<0&&g--}return g!==0},d=m=>Math.round(m*c2)/c2,p=[];for(let m of t){let g=null,v=()=>{g&&g.length>=2&&p.push(g),g=null};for(let y=1;y<m.length;y++){let b=m[y-1],x=m[y],M=x[0]-b[0],w=x[1]-b[1];if(!M&&!w)continue;let k=[0,1];for(let z of h(b,x)){let[S,L]=c[z],I=L[0]-S[0],q=L[1]-S[1],R=M*q-w*I;if(Math.abs(R)>1e-15){let N=((S[0]-b[0])*q-(S[1]-b[1])*I)/R,G=((S[0]-b[0])*w-(S[1]-b[1])*M)/R;N>0&&N<1&&G>=0&&G<=1&&k.push(N)}else{let N=M*M+w*w;for(let G of[S,L]){let V=((G[0]-b[0])*M+(G[1]-b[1])*w)/N,J=Math.abs((G[0]-b[0])*w-(G[1]-b[1])*M)/Math.sqrt(N);V>0&&V<1&&J<=u&&k.push(V)}}}k.sort((z,S)=>z-S);for(let z=1;z<k.length;z++){if(k[z]-k[z-1]<1e-12)continue;let S=[d(b[0]+M*k[z-1]),d(b[1]+w*k[z-1])],L=[d(b[0]+M*k[z]),d(b[1]+w*k[z])],I=(k[z-1]+k[z])/2,q=f([b[0]+M*I,b[1]+w*I]);if(q!==void 0&&q===(n==="inside")){let R=g?g[g.length-1]:void 0;g&&R&&R[0]===S[0]&&R[1]===S[1]?(L[0]!==R[0]||L[1]!==R[1])&&g.push(L):(v(),g=[S,L])}else v()}}v()}return p}function m0(t,e,n="round",c=.01){if(!t.length)return[];if(e===0)return x1(t);let r=n==="round"?O0.Round:n==="square"?O0.Square:O0.Miter,a=Z5(o5(x1(t)),e*c2,r,s0.Polygon,2,c*c2);return h5(a).filter(s=>s.length>=3)}function Y5(t,e){if(!t.length||e<=0)return[];let n=Z5(K6(t),e/2*c2,O0.Round,s0.Round,2,.01*c2);return h5(n)}function _0(t){if(!t.length)return[];let e=new i5,n=new g2;n.addSubject(o5(t)),n.execute(e0.Union,D1.NonZero,e);let c=[],r=a=>{for(let s=0;s<a.count;s++){let i=a.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),r(h)}c.push(h5(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 Q6(t){let e=0,n=0,c=0;for(let r of t){if(r.length<3)continue;let[a,s]=r[0];for(let i=0,o=r.length-1;i<r.length;o=i++){let l=r[o][0]-a,h=r[o][1]-s,u=r[i][0]-a,f=r[i][1]-s,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+a*d/2,c+=(h+f)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,c/e]}}function z3(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 l5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function Z6(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=>l5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>l5(e,i)))});return c}function k3(t,e){return{layers:Z6(t.layers,e),parts:t.parts.map(n=>({...n,layers:Z6(n.layers,e)}))}}function q2(t){let e=K0();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 Y6(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 u5(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:Y6(t.layers,e),parts:t.parts.map(n=>({...n,layers:Y6(n.layers,e)}))}}function S0(t){let e=1/0,n=1/0,c=-1/0,r=-1/0;for(let a of t)for(let[s,i]of a)s<e&&(e=s),i<n&&(n=i),s>c&&(c=s),i>r&&(r=i);return e===1/0?null:[e,n,c,r]}function D0(t,e){let n=[];for(let[c,r]of t)if(!e?.(c))for(let a of[...r.regions,...r.lines])n.push(a);return S0(n)}function e7(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 t7(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 S3(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 n7(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 c7=Math.PI/180;function O1(t,e){let n=new Array(16).fill(0);for(let c=0;c<4;c++)for(let r=0;r<4;r++)for(let a=0;a<4;a++)n[c*4+r]+=t[c*4+a]*e[a*4+r];return n}function J5(t,e){let n=Math.cos(e*c7),c=Math.sin(e*c7);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 fe=t=>Math.abs(t)<1e-12?0:t;function G0(t){if(t.matrix)return t.matrix.map(fe);let[e,n,c]=t.rotate,r=O1(J5(2,c),O1(J5(1,n),J5(0,e)));return r[3]=t.at[0],r[7]=t.at[1],r[11]=t.at[2],r.map(fe)}function C3(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 i7(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 K5(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 f5(t){let[e,n,c,r]=K5(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=C3(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 o7(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(f5))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=>K5(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),r[0]-c[0]),i=0,o=0,l=0;return e.map((h,u)=>{let[f,d,p,m]=a[u];i>0&&i+p-f>s&&(i=0,o+=l+n,l=0);let g=[1,0,0,r[0]+n+i-f,0,1,0,c[1]+o-d,0,0,1,c[2],0,0,0,1];return i+=p-f+n,l=Math.max(l,m-d),{...h,matrix:g.map(fe)}})}var p9=(t,e,n)=>[0,1,2].every(c=>t[0][c]<e[1][c]-n&&e[0][c]<t[1][c]-n),L3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],de=(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]],r7=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],Q5=t=>[t[2],t[6],t[10]],a7=t=>[t[3],t[7],t[11]],m9=(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 A3(t,e,n){let c=n[0]*n[0]+n[1]*n[1],r=[];for(let a of t)for(let s=0,i=a.length-1;s<a.length;i=s++){let o=a[i],l=a[s],h=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=o[0]+(l[0]-o[0])*f-e[0],p=o[1]+(l[1]-o[1])*f-e[1];r.push((d*n[0]+p*n[1])/c)}return r.sort((a,s)=>a-s)}function pe(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 e4(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 s7(t,e,n){let c=C3(t,e[0],e[1],e[2]),r=m9(t,n);return[[c[0],c[1]],[r[0],r[1]]]}function g9(t,e,n,c,r,a,s){let i=Q5(t.matrix),o=Q5(e.matrix),l=de(i,o),h=Math.hypot(...l),u=[l[0]/h,l[1]/h,l[2]/h],f=de(u,i),d=L3(o,f),p=a7(t.matrix),m=L3(o,a7(e.matrix)),g=1/0,v=-1/0;for(let w of e.outline)for(let[k,z]of w)for(let S of[0,e.thickness]){let L=C3(e.matrix,k,z,S),I=L3(i,[L[0]-p[0],L[1]-p[1],L[2]-p[2]]);I<g&&(g=I),I>v&&(v=I)}let y=e4(Math.max(0,g),Math.min(t.thickness,v),r,a),b=1/0,x=-1/0;for(let w of t.outline)for(let[k,z]of w){let S=C3(t.matrix,k,z,0),L=L3(f,[S[0]-p[0],S[1]-p[1],S[2]-p[2]]);L<b&&(b=L),L>x&&(x=L)}let M=0;for(let w of y.at){let k=r7(p,i,w),z=(m-L3(o,k))/d,S=(m+e.thickness-L3(o,k))/d,L=e4(Math.max(b,Math.min(z,S)),Math.min(x,Math.max(z,S)),r,a);for(let I of L.at){let q=r7(k,f,I),[R,N]=s7(n,q,u),[G,V]=s7(c,q,u);if(M+=pe(A3(t.outline,R,N),A3(e.outline,G,V),r)*y.size*L.size,M>s)return!0}}return!1}function v9(t,e,n,c,r,a){let s=[0,1,2,3].flatMap(k=>[0,1,2,3].map(z=>{let S=0;for(let L=0;L<4;L++)S+=n[k*4+L]*e.matrix[L*4+z];return S})),i=s[11],o=s[11]+s[10]*e.thickness,l=Math.min(t.thickness,Math.max(i,o))-Math.max(0,Math.min(i,o));if(l<=c)return!1;let h=e.outline.map(k=>k.map(([z,S])=>[s[0]*z+s[1]*S+s[3],s[4]*z+s[5]*S+s[7]])),[u,f,d,p]=K5(t.outline),[m,g,v,y]=K5(h),b=e4(Math.max(f,g),Math.min(p,y),c,r),x=0;for(let k of b.at)if(x+=pe(A3(t.outline,[0,k],[1,0]),A3(h,[0,k],[1,0]),c)*b.size*l,x>a)return!0;let M=e4(Math.max(u,m),Math.min(d,v),c,r),w=0;for(let k of M.at)if(w+=pe(A3(t.outline,[k,0],[0,1]),A3(h,[k,0],[0,1]),c)*M.size*l,w>a)return!0;return!1}function l7(t,e=1/0,n=.05,c=.25,r=.1){let a=t.map(f5),s=t.map(h=>i7(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(!p9(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[p,m]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]];(Math.hypot(...de(Q5(p.matrix),Q5(m.matrix)))<1e-9?v9(p,m,g,n,c,r):g9(p,m,g,v,n,c,r))&&o.push([p,m])}return{found:o,complete:!0}}function R0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var me=R0(0,0,0);function L0(t){return i7(t)}function h7(t,e,n=t.angle,c=t.x1){let r=c-t.x0;if(!n||!(r>0))return R0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return O1(R0(t.x0,0,s),O1(J5(1,-n),R0(-t.x0-r,0,-s)))}function d5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function t4(t,e){let n=[R0(0,0,0)];for(let c of d5(t))n.push(O1(n[n.length-1],h7(c,e)));return n}function n4(t,e,n){let c=d5(t),r=t4(c,e);for(let a=c.length-1;a>=0;a--){let s=c[a];if(n[0]>=s.x1)return C3(r[a+1],...n);if(n[0]>s.x0){let i=(n[0]-s.x0)/(s.x1-s.x0),o=O1(r[a],h7(s,e,s.angle*i,n[0]));return C3(o,...n)}}return n}function u7(t,e){return d5(t).filter(n=>(n.x0+n.x1)/2<e).length}function c4(t){if(!t.bends?.length)return[t];let e=d5(t.bends),n=t4(e,t.thickness),c=1e7,r=[];for(let a=0;a<=e.length;a++){let s=a===0?-c:e[a-1].x1,i=a===e.length?c:e[a].x0;if(!(i>s))continue;let o=[[s,-c],[i,-c],[i,c],[s,c]],l=x0(t.outline,[o]);l.length&&r.push({...t,outline:l,bends:void 0,matrix:O1(t.matrix,n[a])})}return r}var y9=2e3;function r4(t,e,n=2){if(!e?.length)return _0(t);let c=1e7,r=1/0,a=-1/0;for(let f of t)for(let[d]of f)r=Math.min(r,d),a=Math.max(a,d);let s=d5(e).map(f=>[Math.max(f.x0,r),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,p])=>f+(p-d),0),o=Math.max(n,i/y9),l=[];for(let[f,d]of s){let p=Math.max(1,Math.ceil((d-f)/o));for(let m=0;m<=p;m++)l.push(f+(d-f)*m/p)}let h=[-c,...l.sort((f,d)=>f-d),c],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-c],[h[f+1],-c],[h[f+1],c],[h[f],c]];for(let p of _0(x0(t,[d])))u.push(p)}return u}var N2=1e6,a4=.01,f7=t=>H1(t)<0?[...t].reverse():t;function b9(t,e){let n=O1(L0(t.matrix),e.matrix),[c,r]=[n[8],n[9]],a=Math.hypot(c,r);if(a<1e-9)return[];let s=0,i=e.thickness,o=k=>(-n[11]-Math.max(n[10]*s,n[10]*i)+k)/a,l=k=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-k)/a;if(!(l(a4)>o(a4)))return[];let[h,u]=[c/a,r/a],[f,d]=[-u,h],p=(k,z)=>[[h*k-f*N2,u*k-d*N2],[h*z-f*N2,u*z-d*N2],[h*z+f*N2,u*z+d*N2],[h*k+f*N2,u*k+d*N2]],m=1/0,g=-1/0;for(let k of e.outline)for(let[z,S]of k)for(let L of[s,i]){let I=n[8]*z+n[9]*S+n[10]*L+n[11];I<m&&(m=I),I>g&&(g=I)}if(Math.min(t.thickness,g)-Math.max(0,m)<Math.min(1,t.thickness/2))return[];let v=(k,z)=>x0(e.outline,[f7(p(k,z))]).filter(S=>Math.abs(H1(S))>1e-6);if(!v(o(a4),l(a4)).length)return[];let y=v(o(0),l(0));if(!y.length)return[];let b=k=>([z,S])=>[n[0]*z+n[1]*S+n[2]*k+n[3],n[4]*z+n[5]*S+n[6]*k+n[7]],x=n[0]*n[5]-n[1]*n[4]<0,M=k=>y.map(z=>{let S=z.map(b(k));return x?S.reverse():S}),w=[];for(let k of y)for(let z=0;z<k.length;z++){let S=k[z],L=k[(z+1)%k.length],I=[b(s)(S),b(s)(L),b(i)(L),b(i)(S)];Math.abs(H1(I))>1e-9&&w.push(f7(I))}return x1([...M(s),...M(i),...w],"nonzero")}function d7(t,e,n){let c=[];for(let a of e)for(let s of b9(t,a))c.push(s);if(!c.length)return[];let r=_0(x0(x1(c),t.outline)).filter(a=>a.reduce((s,i)=>s+H1(i),0)>1e-4);return r.length?m0(r.flat(),n/2,"miter"):[]}var Q0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",P2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",m7=t=>typeof t=="number",F0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",j0=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function ge(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let c of e)ge(t,c,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function s4(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 p7=(t,e,n)=>Q0(t)&&Q0(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:F0(t)&&F0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([c,r])=>e.fields.has(c)&&P3(r,e.fields.get(c),n)):t===e;function P3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return p7(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):!p7(i,o,n))return!1}return!0}function W0(t){return t===void 0?"undef":Array.isArray(t)?"list":Q0(t)?"range":P2(t)?"function":F0(t)?"record":typeof t}function x9(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?C2(t):Q0(t)?`[${C2(t.start)}:${C2(t.step)}:${C2(t.end)}]`:P2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:F0(t)?"{}":String(t)}function T3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let c=[],r=0,a=l=>{c.push(l),r+=l.length},s=[],i=t;for(;;){Array.isArray(i)?(a("["),s.push({items:i,i:0,close:"]"})):F0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(x9(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 g7(t,e,n){let c=[],r=0;for(let a of t){c.length&&(r+=e.length);let s=T3(a,n-r);if(!s.whole)return;r+=s.text.length,c.push(s.text)}return c.join(e)}function q0(t){let e=T3(t,200,!0);return e.whole?e.text:e.text+"..."}var g0=t=>typeof t=="string"?t:q0(t);function A0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function C2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function 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 p=d/f,m=1-p;r.push([m*m*h+2*m*p*l.x1+p*p*l.x,m*m*u+2*m*p*l.y1+p*p*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let p=d/f,m=1-p;r.push([m*m*m*h+3*m*m*p*l.x1+3*m*p*p*l.x2+p*p*p*l.x,m*m*m*u+3*m*m*p*l.y1+3*m*p*p*l.y2+p*p*p*l.y])}s=[l.x,l.y]}else i(!0),s=a,r=[a];return i(!1),{closed:n,open:c}}function I3(t,e=Math.PI/2,n){let c=x=>/^[a-zA-Z]$/.test(x),r=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,i="",o=0,l=0,h=0,u=0,f=0,d=0,p=0,m=0,g="",v=()=>{let x=r[s++];if(x===void 0||c(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},y=()=>{let x=r[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(r[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{b()}catch(x){if(!n)throw x;n(x.message)}return a;function b(){for(;s<r.length;){if(c(r[s]))i=r[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${r[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=i===i.toLowerCase(),M=i.toUpperCase(),w=x?o:0,k=x?l:0;if(M==="M")o=w+v(),l=k+v(),h=o,u=l,a.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=w+v(),l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="H")o=w+v(),a.push({type:"L",x:o,y:l});else if(M==="V")l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let z,S;if(M==="C")z=w+v(),S=k+v();else{let q=g==="C"||g==="S";z=q?2*o-f:o,S=q?2*l-d:l}let L=w+v(),I=k+v();o=w+v(),l=k+v(),f=L,d=I,a.push({type:"C",x1:z,y1:S,x2:L,y2:I,x:o,y:l})}else if(M==="Q"||M==="T"){let z,S;if(M==="Q")z=w+v(),S=k+v();else{let L=g==="Q"||g==="T";z=L?2*o-p:o,S=L?2*l-m:l}o=w+v(),l=k+v(),p=z,m=S,a.push({type:"Q",x1:z,y1:S,x:o,y:l})}else if(M==="A"){let z=v(),S=v(),L=v(),I=y(),q=y(),R=w+v(),N=k+v();a.push(...M9(o,l,z,S,L,I,q,R,N,e)),o=R,l=N}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);g=M}}}function M9(t,e,n,c,r,a,s,i,o,l=Math.PI/2){if(n===0||c===0||t===i&&e===o)return[{type:"L",x:i,y:o}];n=Math.abs(n),c=Math.abs(c);let h=r*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-i)/2,p=(e-o)/2,m=u*d+f*p,g=-f*d+u*p,v=m*m/(n*n)+g*g/(c*c);v>1&&(n*=Math.sqrt(v),c*=Math.sqrt(v));let y=n*n*c*c-n*n*g*g-c*c*m*m,b=n*n*g*g+c*c*m*m,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*g/c,w=-x*c*m/n,k=u*M-f*w+(t+i)/2,z=f*M+u*w+(e+o)/2,S=(V,J,o1,Z)=>Math.atan2(V*Z-J*o1,V*o1+J*Z),L=S(1,0,(m-M)/n,(g-w)/c),I=S((m-M)/n,(g-w)/c,(-m-M)/n,(-g-w)/c);!s&&I>0&&(I-=2*Math.PI),s&&I<0&&(I+=2*Math.PI);let q=Math.ceil(Math.abs(I)/l),R=[],N=V=>[k+n*Math.cos(V)*u-c*Math.sin(V)*f,z+n*Math.cos(V)*f+c*Math.sin(V)*u],G=V=>[-n*Math.sin(V)*u-c*Math.cos(V)*f,-n*Math.sin(V)*f+c*Math.cos(V)*u];for(let V=0;V<q;V++){let J=L+I*V/q,o1=L+I*(V+1)/q,Z=4/3*Math.tan((o1-J)/4),p1=N(J),E=N(o1),$=G(J),X=G(o1);R.push({type:"C",x1:p1[0]+Z*$[0],y1:p1[1]+Z*$[1],x2:E[0]-Z*X[0],y2:E[1]-Z*X[1],x:E[0],y:E[1]})}return R}var C0=Math.PI/180,P1=(t,e,n)=>({params:t.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function w7(t,e,n){return t.order?[]:t.params.filter((c,r)=>r<e.length&&n.has(c))}function z7(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 ve(t,e,n,c){let r=g7(t,e,n.maxLength);if(r===void 0)throw new Error(`${c}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(r.length/8)),r}function R1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${W0(t)}`);return t}function r2(t,e,n){if(Array.isArray(t))return t;if(Q0(t))return s4(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${W0(t)}`)}var w9=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function k7(t,e,n){if(w9.has(t))return 0;let c=0;for(let r of e)if(typeof r=="string")c+=r.length;else if(Array.isArray(r))c+=t==="len"?0:r.length;else if(Q0(r)&&r.step!==0){let a=Math.floor((r.end-r.start)/r.step)+1;a>0&&(c+=Math.min(a,n+1))}return c}var N0=t=>P1("x",e=>typeof e[0]=="number"?a2(t(e[0])):void 0);function a2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function z9(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 v7(t,e,n){let c=t.length===1&&Array.isArray(t[0])?t[0]:t;if(c.length)return e(c.map(r=>R1(r,n)))}var m5={abs:N0(Math.abs),sign:N0(Math.sign),floor:N0(Math.floor),ceil:N0(Math.ceil),round:N0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:N0(Math.sqrt),exp:N0(Math.exp),ln:N0(Math.log),log:P1("x, base",(t,e)=>e.given<2?a2(Math.log10(R1(t[0],"log"))):Math.log(R1(t[0],"log"))/Math.log(R1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:N0(t=>Math.sin(t*C0)),cos:N0(t=>Math.cos(t*C0)),tan:N0(t=>Math.tan(t*C0)),asin:N0(t=>Math.asin(t)/C0),acos:N0(t=>Math.acos(t)/C0),atan:N0(t=>Math.atan(t)/C0),atan2:P1("y, x",t=>a2(Math.atan2(R1(t[0],"atan2"),R1(t[1],"atan2"))/C0)),pow:P1("x, y",t=>Math.pow(R1(t[0],"pow"),R1(t[1],"pow"))),min:P1("values...",t=>v7(t,e=>e.reduce((n,c)=>c<n?c:n,1/0),"min")),max:P1("values...",t=>v7(t,e=>e.reduce((n,c)=>c>n?c:n,-1/0),"max")),clamp:P1("x, low, high",t=>Math.min(Math.max(R1(t[0],"clamp"),R1(t[1],"clamp")),R1(t[2],"clamp"))),lerp:P1("a, b, t",t=>{let e=R1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((c,r)=>R1(c,"lerp")+(R1(n[r],"lerp")-R1(c,"lerp"))*e)}return R1(t[0],"lerp")+(R1(t[1],"lerp")-R1(t[0],"lerp"))*e}),norm:P1("v",(t,e)=>Math.sqrt(r2(t[0],"norm",e).reduce((n,c)=>n+R1(c,"norm")**2,0))),cross:P1("a, b",(t,e)=>{let n=r2(t[0],"cross",e).map(r=>R1(r,"cross")),c=r2(t[1],"cross",e).map(r=>R1(r,"cross"));return n.length===2?n[0]*c[1]-n[1]*c[0]:[n[1]*c[2]-n[2]*c[1],n[2]*c[0]-n[0]*c[2],n[0]*c[1]-n[1]*c[0]]}),len:P1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:F0(t[0])?t[0].fields.size:void 0),keys:P1("record",t=>F0(t[0])?[...t[0].fields.keys()]:void 0),merge:P1("a, b",t=>{if(!F0(t[0])||!F0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:P1("...",(t,e)=>{let n=t.reduce((c,r)=>c+(Array.isArray(r)?r.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(c=>Array.isArray(c)?c:[c])}),reverse:P1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...r2(t[0],"reverse",e)].reverse()),sum:P1("values",(t,e)=>r2(t[0],"sum",e).reduce((n,c)=>n+R1(c,"sum"),0)),slice:P1("value, start, end",(t,e)=>{let c=(typeof t[0]=="string"?[...t[0]]:r2(t[0],"slice",e)).slice(R1(t[1]??0,"slice"),t[2]===void 0?void 0:R1(t[2],"slice"));return typeof t[0]=="string"?c.join(""):c}),str:P1("...",(t,e)=>ve(t,"",e,"str")),chr:P1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(R1(e,"chr"))).join("")),ord:P1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:P1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:P1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:P1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:P1("values, separator",(t,e)=>ve(r2(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:P1("value, list",(t,e)=>{let c=(typeof t[1]=="string"?[...t[1]]:r2(t[1],"search",e)).findIndex(r=>P3(r,t[0],e.step));return c<0?void 0:c}),contains:P1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(ve([t[1]],"",e,"contains")):r2(t[0],"contains",e).some(n=>P3(n,t[1],e.step))),lookup:P1("x, table",(t,e)=>{let n=R1(t[0],"lookup"),c=r2(t[1],"lookup",e);if(!c.length)return;let r=c.map(a=>[R1(a[0],"lookup"),R1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=r[0][0])return r[0][1];for(let a=1;a<r.length;a++)if(n<=r[a][0]){let[s,i]=r[a-1],[o,l]=r[a];return i+(n-s)/(o-s)*(l-i)}return r[r.length-1][1]}),rands:P1("min, max, count, seed",t=>{let e=R1(t[0],"rands"),n=R1(t[1],"rands"),c=R1(t[2],"rands"),r=z9(t[3]===void 0?1:R1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(n-e)*r())}),is_num:P1("value",t=>m7(t[0])&&!Number.isNaN(t[0])),is_string:P1("value",t=>typeof t[0]=="string"),is_bool:P1("value",t=>typeof t[0]=="boolean"),is_list:P1("value",t=>Array.isArray(t[0])),is_record:P1("value",t=>F0(t[0])),is_undef:P1("value",t=>t[0]===void 0),is_function:P1("value",t=>P2(t[0])),type_of:P1("value",t=>W0(t[0])),path_length:P1("points",(t,e)=>{let n=p5(t[0],"path_length",e),c=0;for(let r=1;r<n.length;r++)c+=Math.hypot(n[r][0]-n[r-1][0],n[r][1]-n[r-1][1]);return c}),point_at:P1("points, s",(t,e)=>y7(p5(t[0],"point_at",e),R1(t[1],"point_at")).point),heading_at:P1("points, s",(t,e)=>a2(y7(p5(t[0],"heading_at",e),R1(t[1],"heading_at")).heading)),offset_path:P1("points, d, closed",(t,e)=>{let n=p5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),c=R1(t[1],"offset_path"),r=t[2]===!0,a=r&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(a&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let s=n.length,i=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],p=Math.hypot(f-h,d-u);return[-(d-u)/p,(f-h)/p]},o=n.map(([l,h],u)=>{let f=!r&&u===0,d=!r&&u===s-1,p=i(f?0:(u-1+s)%s),m=i(d?s-2:u),[g,v]=[p[0]+m[0],p[1]+m[1]],y=Math.hypot(g,v);if(y<1e-9)[g,v]=p;else{let b=Math.min(2/(y*y),4/y);[g,v]=[g*b,v*b]}return[a2(l+c*g),a2(h+c*v)]});return a?[...o,o[0]]:o}),train_for:P1("ratio, stages, pinion, wheel",(t,e)=>{let n=R1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let c=t[1]===void 0?2:R1(t[1],"train_for");if(!(c===1||c===2||c===3))throw new Error("train_for(): stages must be 1, 2 or 3");let r=(v,y,b)=>{if(v===void 0)return y;if(!Array.isArray(v)||v.length!==2||!v.every(w=>typeof w=="number"))throw new Error(`train_for(): ${b} must be [fewest, most] teeth`);let[x,M]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(x>=6&&M>=x&&M<=400))throw new Error(`train_for(): ${b} teeth must be from 6 to 400, fewest first`);return[x,M]},[a,s]=r(t[2],[10,20],"pinion"),[i,o]=r(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=a;v<=s;v++)for(let y=Math.max(i,v);y<=o;y++)u.push([v,y]);let f,d=v=>{let y=v.reduce((M,[w,k])=>M*k/w,1),b=Math.abs(y/h-1),x=v.reduce((M,[w,k])=>M+w+k,0);(!f||b<f.err-1e-12||Math.abs(b-f.err)<=1e-12&&x<f.teeth)&&(f={stages:v.map(M=>[...M]),err:b,teeth:x})},p=(v,y)=>{e.step();for(let b=a;b<=s;b++)for(let x of[Math.floor(y*b),Math.ceil(y*b)])x>=Math.max(i,b)&&x<=o&&d([...v,[b,x]])};if(c===1)p([],h);else for(let v=0;v<u.length;v++){let y=u[v][1]/u[v][0];if(c===2)p([u[v]],h/y);else for(let b=v;b<u.length;b++)p([u[v],u[b]],h/y/(u[b][1]/u[b][0]))}if(!f)throw new Error(`train_for(): no train of ${c} stages reaches a ratio of ${n}`);let m=f.stages.map(([v,y])=>l?[y,v]:[v,y]),g=m.reduce((v,[y,b])=>v*b/y,1);return{type:"record",fields:new Map([["stages",m],["ratio",g],["error",g/n-1]])}}),path_points:P1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:R1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let c=E3(I3(t[0]),n),r=[...c.closed.map(a=>[...a,a[0]]),...c.open];return e.step(r.reduce((a,s)=>a+s.length,0)),r.map(a=>a.map(([s,i])=>[s,i]))}),spline_points:P1("points, steps, closed",(t,e)=>{let n=p5(t[0],"spline_points",e),c=t[1]===void 0?8:Math.floor(R1(t[1],"spline_points"));if(!(c>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*c>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*c),be(n,c,t[2]===!0)}),rotation:P1("angles",t=>{let[e,n,c]=ye(t[0],"rotation");return C9(x7(A9(c),x7(L9(n),S9(e))))}),euler:P1("matrix",t=>M7(k9(t[0],"euler"))),orient:P1("x, z",t=>{let e=b7(ye(t[0],"orient"),"orient"),n=ye(t[1]??[0,0,1],"orient"),c=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=b7([n[0]-c*e[0],n[1]-c*e[1],n[2]-c*e[2]],"orient");let r=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return M7([[e[0],r[0],n[0]],[e[1],r[1],n[1]],[e[2],r[2],n[2]]])})};function p5(t,e,n){return r2(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 y7(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 ye(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 b7(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 k9(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 S9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[1,0,0],[0,e,-n],[0,n,e]]},L9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,0,n],[0,1,0],[-n,0,e]]},A9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,-n,0],[n,e,0],[0,0,1]]},x7=(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])),C9=t=>t.map(e=>e.map(a2));function M7(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,c=Math.atan2(-t[0][1],t[1][1])/C0;return[0,n,a2(c)]}return[a2(Math.atan2(t[2][1],t[2][2])/C0),a2(Math.asin(e)/C0),a2(Math.atan2(t[1][0],t[0][0])/C0)]}function be(t,e,n=!1){if(t.length<3)return t.map(([s,i])=>[s,i]);let c=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=t.length){let[i,o]=[t[t.length-1],t[t.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return t[s]},r=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[i,o,l,h]=[c(s-1),c(s),c(s+1),c(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,p=d*f;r.push([0,1].map(m=>.5*(2*o[m]+(-i[m]+l[m])*f+(2*i[m]-5*o[m]+4*l[m]-h[m])*d+(-i[m]+3*o[m]-3*l[m]+h[m])*p)))}}return r.push(n?r[0]:[t[t.length-1][0],t[t.length-1][1]]),r}function c3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var g5=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function P9(t,e,n,c){if(e==="flat")return[];let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===1:i%2===0)&&s.push(g5(i*a,-1,(i+1)*a,n));return s}function i4(t,e,n,c,r){let a=[([o,l])=>[o,l],([o,l])=>[t-l,o],([o,l])=>[t-o,e-l],([o,l])=>[l,e-o]],s=[t,e,t,e],i=[];return n.forEach((o,l)=>{for(let h of P9(s[l],o,c,r))i.push(h.map(a[l]))}),b0([g5(0,0,t,e)],i)}function S7(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(g5(i*a,-n/2,(i+1)*a,n/2));return s}function L7(t,e,n,c,r){let a=g5(-t/2,-1,t/2,e),s=g5(-n/2,r,n/2,r+c);return[a,s]}function A7(t,e,n,c,r){let a=[],s=r+c,i=Math.floor(t/n),o=(t-i*n)/2;for(let l=0;l<=i;l++){let h=o+l*n,u=l%2===0?c:c-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?c:0),p=Math.min(f+r,e-(l%2===0?c:0));p-d>=c/2&&a.push([[h,d],[h,p]])}}return a}var T2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var c1=class extends Error{constructor(n,c){super(c?`${n} (${T2(c)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,c&&(this.line=c.line,this.col=c.col,this.file=c.file)}addFrame(n,c,r){let a=this.trace.find(s=>s.name===c&&s.line===r.line&&s.col===r.col&&s.file===r.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:c,line:r.line,col:r.col,...r.file&&{file:r.file},count:1})}},T9=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function V3(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
|
|
12
|
-
`)throw new c1("Unclosed string",h);f+=t[r],o(1)}if(r>=t.length)throw new c1("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=T9.find(f=>t.startsWith(f,r));if(!u)throw new c1(`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 r3={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"}},H3={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var xe=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function e2(t,e){let{tokens:n,comments:c}=V3(t,e),r=new Me(n),a=[];for(;!r.at("eof");)a.push(...r.statement());return{program:{body:a},comments:c}}var v5=class v5{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 c1(`${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"||xe.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"||xe.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>=v5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&v5.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}):(xe.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 c1(`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()}}};v5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var Me=v5;var H=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),B1=(t,e,n)=>({...H(t,e,n),named:!0}),we="max(3 * $thickness, 6)",o4=[H("value")],E9=[H("x")],U0=(t,e)=>({name:t,kind:"function",params:E9,section:"Numbers and vectors",doc:e}),a3=(t,e)=>({name:t,kind:"function",params:o4,section:"Types",doc:`Whether the value is ${e}`}),C7=(t,e)=>({name:t,kind:"function",params:[H("text","The text to measure",'""'),H("size","Font size in millimetres","10"),H("font","Font name","$font"),B1("halign","left, center or right",'"left"'),B1("valign","baseline, top, center or bottom",'"baseline"'),B1("spacing","Letter spacing factor","1"),B1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),ze=[{name:"rect",kind:"module",params:[H("size","A number, or [width, height]","1"),H("center","Centre the rectangle on the origin instead of its corner","false"),B1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[H("size","A number, or [width, height]","1"),H("center","Centre the square on the origin instead of its corner","false"),B1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[H("r","Radius","1"),B1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[H("r","[rx, ry], or one radius for both","1")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[H("n","Number of corners","6"),H("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[H("n","Number of points","5"),H("r","Radius of the points","10"),H("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[H("points","A list of [x, y] points"),H("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[H("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),B1("fill",'"evenodd" or "nonzero"','"evenodd"'),B1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[H("text","The text",'""'),H("size","Font size in millimetres","10"),H("font","Font name","$font"),B1("halign","left, center or right",'"left"'),B1("valign","baseline, top, center or bottom",'"baseline"'),B1("spacing","Letter spacing factor","1"),B1("fit","Shrink the size so the text is no wider than this")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[H("from","Start point","[0, 0]"),H("to","End point","[10, 0]"),H("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[H("points","A list of [x, y] points"),H("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[H("r","Radius","10"),H("start","Start angle in degrees","0"),H("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[H("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[H("a","Angle in degrees, anticlockwise","0"),B1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[H("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[H("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[H("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[H("r","Grow (positive) or shrink areas with rounded corners"),B1("delta","Grow or shrink areas with sharp corners","0"),B1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[H("spacing","Distance between copies, a number or [x, y]","10"),H("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[H("points","The [x, y] points the curve goes through"),H("width","Make an area this wide along the curve, instead of a line"),B1("steps","Points between each two given ones","8"),B1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[H("angle","Direction of the lines, in degrees from +x","45"),H("pitch","Distance between the lines","5"),H("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"paint",kind:"module",params:[H("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[H("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1], $area and $centroid = [x, y] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[H("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"close",kind:"module",params:[H("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[H("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[H("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[H("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[H("name","Layer name"),H("mode",'"cut", "line", "fill" or "guide"'),H("color",'Colour in the output, as "#00aa00"'),B1("order","Where it goes among the custom layers in the files, lowest first","0"),B1("bleed","How far past the part's edge it may print","0"),B1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[H("name","Part name",'"part"'),H("qty","Number of copies to cut","1"),B1("at","Where the part goes in the assembled view, [x, y, z]"),B1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),B1("stack","Layers glued in a stack at each placement, one thickness apart","1"),B1("mirror","Cut the part mirrored left to right, its text still reading","false"),B1("material","The material it is cut from, as material(name = ...) sets it"),B1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),B1("on","The name of a bent part this one is glued to, to move with it"),B1("slots","Names of parts whose tabs pass through this one: their slots are cut"),B1("clearance","Added to the slots, in total across each","0.1"),B1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),B1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[H("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),H("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[H("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[H("text","What to do in this step",'""'),H("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[H("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),H("from","One end, [x, y, z]; a ball sits midway between from and to"),H("to","The other end, [x, y, z]; a ball may leave it out"),H("size","Diameter, or [width, height] for a flat section","6"),B1("up","The direction a [width, height] section's height points"),B1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),B1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),B1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[H("thickness","Sets $thickness"),H("kerf","Sets $kerf"),H("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[H("size","[width, height]"),H("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),H("finger","Finger width",we)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[H("length","Length of the edge that plugs in"),H("edge",'"out" or "in", the kind of edge that plugs in','"out"'),H("finger","Finger width",we)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[H("d","Screw diameter","3"),H("length","Screw length into the panel","12"),H("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),H("nut_at","Distance of the nut from the edge","length / 2")],section:"Joinery",doc:"A T-slot for a screw and nut, opening at y = 0; subtract it from a panel edge"},{name:"living_hinge",kind:"module",params:[H("size","[width, height]"),H("spacing","Distance between the rows of cuts","1.5"),H("bridge","Uncut length between cuts","3"),H("cut","Length of each cut","max(bridge * 2, (height - 3 * bridge) / 2)")],section:"Joinery",doc:"A straight-line flex pattern of cut lines filling [width, height]"},{name:"children",kind:"module",params:[H("index","Which child, from 0, or a list of them")],section:"Other",doc:"Run the child statements passed to the current module"},{name:"echo",kind:"both",params:[],rest:!0,anyNamed:!0,section:"Other",doc:"Write values to the output without making shapes"},{name:"assert",kind:"both",params:[H("condition","Stops the program when false"),H("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},U0("abs","Absolute value"),U0("sign","Sign as -1, 0 or 1"),U0("floor","Round down"),U0("ceil","Round up"),U0("round","Round to the nearest integer, halves away from zero"),U0("sqrt","Square root"),U0("exp","e raised to x"),U0("ln","Natural logarithm"),{name:"log",kind:"function",params:[H("x"),H("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},U0("sin","Sine of an angle in degrees"),U0("cos","Cosine of an angle in degrees"),U0("tan","Tangent of an angle in degrees"),U0("asin","Inverse sine, in degrees"),U0("acos","Inverse cosine, in degrees"),U0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[H("y"),H("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[H("x"),H("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[H("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[H("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[H("x"),H("low"),H("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[H("a"),H("b"),H("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[H("ratio","Turns in for one turn out; under 1 speeds up"),H("stages","Pairs of gears, 1 to 3","2"),H("pinion","Fewest and most teeth of the small gears","[10, 20]"),H("wheel","Fewest and most teeth of the big gears","[20, 80]")],section:"Numbers and vectors",doc:"Tooth counts for a gear train nearest a ratio: {stages = [[driver, driven], ...], ratio, error}"},{name:"norm",kind:"function",params:[H("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[H("a"),H("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[H("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"offset_path",kind:"function",params:[H("points","A list of [x, y] points"),H("d","How far to move it: to the left going along it, or the right when less than 0"),H("closed","The path goes round, its last point joined to its first","false")],section:"Paths and rotations",doc:"The path moved sideways, each corner mitred: the two edges of a strip along a curve"},{name:"point_at",kind:"function",params:[H("points","A list of [x, y] points"),H("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[H("points","A list of [x, y] points"),H("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[H("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),H("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[H("points","The [x, y] points the curve goes through"),H("steps","Points between each two given ones","8"),H("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[H("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[H("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[H("x","Where the part's own x axis points"),H("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:o4,section:"Lists and strings",doc:"Number of items in a list, characters in a string or fields in a record"},{name:"keys",kind:"function",params:[H("record","A record, as {name = value}")],section:"Lists and strings",doc:"A record's field names, in the order they were written"},{name:"merge",kind:"function",params:[H("a","A record"),H("b","A record whose fields add to or replace those of a")],section:"Lists and strings",doc:"A record with the fields of a and b, b winning where both have one"},{name:"concat",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Join lists and single values into one list"},{name:"reverse",kind:"function",params:o4,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sum",kind:"function",params:[H("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[H("value","A list or string"),H("start","First index","0"),H("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[H("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[H("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[H("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[H("text"),H("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[H("values"),H("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[H("value"),H("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[H("value","A list or string"),H("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[H("x"),H("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},a3("is_num","a number other than NaN"),a3("is_string","a string"),a3("is_bool","true or false"),a3("is_list","a list"),a3("is_undef","undef"),a3("is_function","a function"),a3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:o4,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"rands",kind:"function",params:[H("min"),H("max"),H("count"),H("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},C7("text_width","The advance width of the text, including spacing"),C7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[H("length","Edge length"),H("finger","Finger width",we)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],I9=new Map(ze.map(t=>[t.name,t])),O3=t=>I9.get(t);function l4(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var y5={"kerf/box":`// kerf/box: finger-jointed boxes.
|
|
2
|
+
"use strict";var J5=Object.defineProperty;var i9=Object.getOwnPropertyDescriptor;var o9=Object.getOwnPropertyNames;var l9=Object.prototype.hasOwnProperty;var h9=(t,e,n)=>e in t?J5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u9=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f9=(t,e)=>{for(var n in e)J5(t,n,{get:e[n],enumerable:!0})},d9=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of o9(e))!l9.call(t,c)&&c!==n&&J5(t,c,{get:()=>e[c],enumerable:!(r=i9(e,c))||r.enumerable});return t};var m9=t=>d9(J5({},"__esModule",{value:!0}),t);var _=(t,e,n)=>h9(t,typeof e!="symbol"?e+"":e,n);var u7=u9((Mu,h7)=>{h7.exports={}});var vl={};f9(vl,{DEFAULT_LAYERS:()=>N5,DEFAULT_LIMITS:()=>w6,HARDWARE_COLORS:()=>U3,HARDWARE_KINDS:()=>d3,KerfError:()=>o1,LANGUAGE_VERSION:()=>gl,SIGNATURES:()=>Ne,VERSION:()=>pl,bendPoint:()=>p4,diffRenders:()=>rn,format:()=>_4,formatError:()=>Q8,formatSignature:()=>z4,importSvg:()=>Sn,instructionsHtml:()=>sn,meshPieces:()=>v4,parameters:()=>K8,parse:()=>l2,placementMatrix:()=>Z0,poseAssembly:()=>at,render:()=>X8,signature:()=>B3,snapshotFromRender:()=>ct,tokenize:()=>N3,triage:()=>st,triageText:()=>s9,verificationIsCurrent:()=>c9,verify:()=>a9});module.exports=m9(vl);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 E3=Number.MAX_SAFE_INTEGER,x0=Math.floor(Math.sqrt(E3));function K5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=E3/Math.abs(e)}function it(t,e){return Math.abs(t)+Math.abs(e)<=E3}function fe(t,e,n,r){if(K5(t,e)&&K5(n,r)){let c=t*e,a=n*r;if(it(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 de(t,e,n,r){if(K5(t,e)&&K5(n,r)){let c=t*e,a=n*r;if(it(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 me=BigInt(0),Q5=BigInt(2),p9=BigInt(4),g9=BigInt(64),v9=BigInt("0xFFFFFFFFFFFFFFFF"),ve=BigInt("9223372036854775807"),l5=Number(ve/p9),ot=Number(ve),lt=1e-12,y9=.1,pe=Math.floor(x0/2),b9=Math.floor(Math.sqrt(Math.sqrt(E3/4)));function x9(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:E3/e}function M9(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function w9(t,e){if(!Number.isFinite(t)||Math.abs(t)>E3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function k9(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(r)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0?r*c-a*s:fe(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 z9(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function S9(t){return Math.abs(t)<=lt}function L9(t){return t<0?-1:t>0?1:0}function A9(t,e){let n=BigInt(t),r=BigInt(e),c=n*r;return{lo64:c&v9,hi64:c>>g9}}function ht(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 C9(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 ht(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;return Math.abs(r)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0?r*c+a*s:de(r,c,a,s)}function E9(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===me?0:i>me?1:-1}function T9(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)>=pe||Math.abs(s.y)>=pe)&&(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=me;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 I9(t,e){return t.y*e.x-e.y*t.x}function V9(t,e){return t.x*e.x+t.y*e.y}function H9(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function O9(t){return t>=l5||t<=-l5?ot:Math.round(t)}function F9(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=fe(c,i,s,a);if(o===0)return null;let l=fe(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 R9(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 $9(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 ut(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 D9(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=de(t.x-e.x,r,t.y-e.y,c)/de(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 ge(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 q9(t,e){let n=G1.IsOn;for(let i of t)switch(ge(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=ut(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))/Q5),a=Number((BigInt(r.top)+BigInt(r.bottom))/Q5)):(c=Math.round((r.left+r.right)/2),a=Math.round((r.top+r.bottom)/2)),ge({x:c,y:a},e)!==G1.IsOutside}var O1={MaxInt64:ve,MaxCoord:l5,max_coord:l5,min_coord:-l5,Invalid64:ot,floatingPointTolerance:lt,defaultMinimumEdgeLength:y9,maxCoordForSafeAreaProduct:pe,maxCoordForSafeCrossSq:b9,maxSafeCoordinateForScale:x9,checkSafeScaleValue:M9,ensureSafeInteger:w9,crossProduct:k9,crossProductSign:a2,checkPrecision:z9,isAlmostZero:S9,triSign:L9,multiplyUInt64:A9,productsAreEqual:ht,isCollinear:C9,dotProduct:P9,dotProductSign:E9,area:T9,crossProductD:I9,dotProductD:V9,roundToEven:H9,checkCastInt64:O9,getLineIntersectPt:F9,getLineIntersectPtD:R9,segsIntersect:$9,getBounds:ut,getClosestPtOnSegment:D9,pointInPolygon:ge,path2ContainsPath1:q9},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} `}},e4={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))/Q5),n=Number((BigInt(t.top)+BigInt(t.bottom))/Q5);return{x:e,y:n}}return{x:Math.round((t.left+t.right)/2),y:Math.round((t.top+t.bottom)/2)}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<=Math.min(t.right,e.right)&&Math.max(t.top,e.top)<=Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}},ye={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 ft=Object.freeze(o3.createInvalid()),dt=Object.freeze(ye.createInvalid());var h5=BigInt(0),N9=BigInt(2),mt=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 be=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}},u5=class{constructor(e,n,r){_(this,"pt");_(this,"next",null);_(this,"prev",null);_(this,"flags");this.pt=e,this.flags=n,this.prev=r}},f5=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 pt(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 xe;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(xe||(xe={}));var t4=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)}},n4=class{constructor(e){_(this,"leftOp");_(this,"rightOp");_(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},d5=class{constructor(e,n){_(this,"op1");_(this,"op2");this.op1=e,this.op2=n}};function U9(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function B9(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 m5=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)}},T3={addLocMin(t,e,n,r){if((t.flags&Z1.LocalMin)!==Z1.None)return;t.flags|=Z1.LocalMin;let c=new f5(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 u5(p,Z1.None,null),c.push(o),l=o,h=p;else if(!(h.x===p.x&&h.y===p.y)){let v=new u5(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,T3.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,T3.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=Z1.OpenEnd,u?l.flags|=Z1.LocalMax:T3.addLocMin(l,e,n,r)):u!==f&&(f?T3.addLocMin(l,e,!1,r):l.flags|=Z1.LocalMax)}}};var r4=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
|
+
`}},c4=class t extends r4{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:Me.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var p5=class extends c4{};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 be);_(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,T3.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 f5(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 m5,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 m5,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(U9);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 d5(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 d5(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(B9);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 n4(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=pt(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 t4;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 mt*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<h5?-s:s;if(i<mt){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<h5?-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>N9)||!(l>i)&&o>h5!=s>h5)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=h5;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 a4=F,S2=class extends a4{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 Me={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(Me.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(Me.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 we=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 we(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&&e4.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 El=BigInt(2);function ze(t,e,n){return typeof e=="number"?ke(t0.Union,t,null,e):ke(t0.Union,t,e,n)}function ke(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 s4(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 f2=1e4,Se=[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 yt(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 bt=t=>t.map(e=>e.map(([n,r])=>({x:Math.round(n*f2),y:Math.round(r*f2)})));function G9(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 g5=t=>bt(t).map(G9),y5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/f2,n.y/f2]));function i1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?_1.EvenOdd:_1.NonZero;return y5(ze(g5(t),n)).filter(r=>r.length>=3)}function Le(t,e,n){if(!e.length)return[];let r=new S2;r.addSubject(g5(e)),n.length&&r.addClip(g5(n));let c=[];return r.execute(t,_1.NonZero,c),y5(c).filter(a=>a.length>=3)}var k0=(t,e)=>e.length?Le(t0.Difference,t,e):i1(t),a0=(t,e)=>Le(t0.Intersection,t,e),h3=(t,e)=>Le(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/f2,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*f2)/f2,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=s4(g5(i1(t)),e*f2,c,u0.Polygon,2,r*f2);return y5(a).filter(s=>s.length>=3)}function i4(t,e){if(!t.length||e<=0)return[];let n=s4(bt(t),e/2*f2,U0.Round,u0.Round,2,.01*f2);return y5(n)}function F0(t){if(!t.length)return[];let e=new p5,n=new S2;n.addSubject(g5(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(y5(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 xt(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 I3(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 v5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function gt(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=>v5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>v5(e,i)))});return r}function u3(t,e){return{layers:gt(t.layers,e),parts:t.parts.map(n=>({...n,layers:gt(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 vt(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 b5(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:vt(t.layers,e),parts:t.parts.map(n=>({...n,layers:vt(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 o4(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 Mt(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 V3(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 wt(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 Ae(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 W9(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 kt(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=W9(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 zt(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 St(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 X9(o)}function X9(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 Lt(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 At=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 l4(t,e){let n=Math.cos(e*At),r=Math.sin(e*At);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 Pe=t=>Math.abs(t)<1e-12?0:t;function Z0(t){if(t.matrix)return t.matrix.map(Pe);let[e,n,r]=t.rotate,c=q1(l4(2,r),q1(l4(1,n),l4(0,e)));return c[3]=t.at[0],c[7]=t.at[1],c[11]=t.at[2],c.map(Pe)}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 x5(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 h4(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 Et(t){let[e,n,r,c]=h4(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 Tt(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(Et))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=>h4(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(Pe)}})}var Z9=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),H3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],u4=(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]],Ce=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],F3=t=>[t[2],t[6],t[10]],Ct=t=>[t[3],t[7],t[11]],Y9=(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 O3(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 Ee(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 J9(t,e){let[n,r,c]=$2(x5(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 f4=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=>J9(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 d4(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 Pt(t,e,n){let r=$2(t,e[0],e[1],e[2]),c=Y9(t,n);return[[r[0],r[1]],[c[0],c[1]]]}function It(t,e,n,r,c,a,s,i=!1){let o=F3(t.matrix),l=F3(e.matrix),h=u4(o,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=u4(f,o),m=H3(l,d),g=Ct(t.matrix),p=H3(l,Ct(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=H3(o,[C[0]-g[0],C[1]-g[1],C[2]-g[2]]);P<v&&(v=P),P>y&&(y=P)}let b=d4(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=H3(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 f4([t,e]);for(let z of b.at){let S=Ce(g,o,z),A=(p-H3(l,S))/m,L=(p+e.thickness-H3(l,S))/m,C=d4(Math.max(x,Math.min(A,L)),Math.min(M,Math.max(A,L)),c,a);for(let P of C.at){let R=Ce(S,d,P),[q,T]=Pt(n,R,f),[B,X]=Pt(r,R,f),Z=Ee(O3(t.outline,q,T),O3(e.outline,B,X),c);if(w+=Z.total*b.size*C.size,k.see(Z.run,()=>Ce(R,f,Z.mid)),w>s&&!i)return k.at}}return w>s?k.at:void 0}function Vt(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 f4([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]=h4(t.outline),[y,b,x,M]=h4(d),w=d4(Math.max(g,b),Math.min(v,M),r,c),k=0;for(let A of w.at){let L=Ee(O3(t.outline,[0,A],[1,0]),O3(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=d4(Math.max(m,y),Math.min(p,x),r,c),S=0;for(let A of z.at){let L=Ee(O3(t.outline,[A,0],[0,1]),O3(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 Ht(t,e=1/0,n=.05,r=.25,c=.1){let a=t.map(Et),s=t.map(h=>x5(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(!Z9(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(...u4(F3(m.matrix),F3(g.matrix)))<1e-9?Vt(m,g,p,n,r,c):It(m,g,p,v,n,r,c);b&&o.push([m,g,b])}return{found:o,complete:!0}}function Ot(t,e,n=.05,r=.25,c=.1){let a=Math.hypot(...u4(F3(t.matrix),F3(e.matrix)))<1e-9,s=x5(t.matrix);return a?Vt(t,e,s,n,r,c,!0):It(t,e,s,x5(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 Te=B0(0,0,0);function p0(t){return x5(t)}function Ft(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(l4(1,-n),B0(-t.x0-c,0,-s)))}function M5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function m4(t,e){let n=[B0(0,0,0)];for(let r of M5(t))n.push(q1(n[n.length-1],Ft(r,e)));return n}function p4(t,e,n){let r=M5(t),c=m4(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],Ft(s,e,s.angle*i,n[0]));return $2(o,...n)}}return n}function Rt(t,e){return M5(t).filter(n=>(n.x0+n.x1)/2<e).length}function g4(t){if(!t.bends?.length)return[t];let e=M5(t.bends),n=m4(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 K9=2e3;function v4(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=M5(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/K9),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,y4=.01,w5=t=>M1(t)<0?[...t].reverse():t;function Q9(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(y4)>o(y4)))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,[w5(m(L,C))]).filter(P=>Math.abs(M1(P))>1e-6),y=v(o(y4),l(y4));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=[w5(C),w5(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(w5(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(w5(q))}return i1([...S(s),...S(i),...A],"nonzero")}function $t(t,e,n){let r=[];for(let a of e)for(let s of Q9(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 k5=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Dt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],er=(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]],qt=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},z5={turn:.3,press:-.1};function tr(t,e){let n=qt(k5(t.to,t.from)),r=k5(t.up,n.map(o=>o*Dt(t.up,n)));Math.hypot(...r)<1e-9&&(r=Math.abs(n[0])<.9?[1,0,0]:[0,1,0]);let c=qt(k5(r,n.map(o=>o*Dt(r,n)))),a=er(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 Nt(t,e,n){let r=k5(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=k5(a(r),a([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let i=[];for(let o of tr(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?o4(i):void 0}var b4=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],nr=(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]],Ut=t=>[t[2],t[6],t[10]],Bt=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 jt(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 rr(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 Gt(t,e,n){let r={a:[],b:[],thin:0},c=Ut(t.matrix),a=Ut(e.matrix),s=nr(c,a),i=Math.hypot(...s);if(i<1e-6)return r;let o=Math.abs(b4(c,a)),l=[s[0]/i,s[1]/i,s[2]/i],h=b4(c,Bt(t.matrix))+t.thickness/2,u=b4(a,Bt(e.matrix))+e.thickness/2,f=b4(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]=jt(w,R),[B,X]=jt(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=>rr(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",d2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",Xt=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 Ie(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)Ie(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function x4(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 Wt=(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)&&R3(c,e.fields.get(r),n)):t===e;function R3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return Wt(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):!Wt(i,o,n))return!1}return!0}function R0(t){return t===void 0?"undef":Array.isArray(t)?"list":i2(t)?"range":d2(t)?"function":_0(t)?"record":typeof t}function cr(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)}]`:d2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:_0(t)?"{}":String(t)}function $3(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(cr(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 Zt(t,e,n){let r=[],c=0;for(let a of t){r.length&&(c+=e.length);let s=$3(a,n-c);if(!s.whole)return;c+=s.text.length,r.push(s.text)}return r.join(e)}function C0(t){let e=$3(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 D3(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 q3(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(...ar(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 ar(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 t7(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=t7(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 Fe(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 sr(t,e,n){let r=$0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(c=>Fe(c,e,n)):[Fe(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 n7(t,e,n){return t.order?[]:t.params.filter((r,c)=>c<e.length&&n.has(r))}function r7(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 Ve(t,e,n,r){let c=Zt(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 x4(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${R0(t)}`)}var ir=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function c7(t,e,n){if(ir.has(t))return 0;let r=0;for(let c of e)if(typeof c=="string")r+=c.length;else if(Array.isArray(c))r+=t==="len"?0:c.length;else if(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 Y0=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 a7(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 M4=new Map;function or(t){let e=M4.get(t);if(e)return e;let n=a7(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 M4.size>64&&M4.clear(),M4.set(t,e),e}var He=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 lr(t,e,n,r){let c=or(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=He(t),f=He(e),d=He(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 Yt(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 L5={abs:Y0(Math.abs),sign:Y0(Math.sign),floor:Y0(Math.floor),ceil:Y0(Math.ceil),round:Y0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:Y0(Math.sqrt),exp:Y0(Math.exp),ln:Y0(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:Y0(t=>Math.sin(t*E0)),cos:Y0(t=>Math.cos(t*E0)),tan:Y0(t=>Math.tan(t*E0)),asin:Y0(t=>Math.asin(t)/E0),acos:Y0(t=>Math.acos(t)/E0),atan:Y0(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=>Yt(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:w1("values...",t=>Yt(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)=>t7(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=Fe(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 sr(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)=>Ve(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)=>Ve($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=>R3(c,t[0],e.step));return r<0?void 0:r}),contains:w1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(Ve([t[1]],"",e,"contains")):$0(t[0],"contains",e).some(n=>R3(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=a7(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*lr(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=>Xt(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=>d2(t[0])),type_of:w1("value",t=>R0(t[0])),path_length:w1("points",(t,e)=>{let n=S5(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(S5(t[0],"point_at",e),z1(t[1],"point_at")).point),heading_at:w1("points, s",(t,e)=>o2(Jt(S5(t[0],"heading_at",e),z1(t[1],"heading_at")).heading)),offset_path:w1("points, d, closed",(t,e)=>{let n=S5(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=D3(q3(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=S5(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),Re(n,r,t[2]===!0)}),rotation:w1("angles",t=>{let[e,n,r]=Oe(t[0],"rotation");return mr(Qt(dr(r),Qt(fr(n),ur(e))))}),euler:w1("matrix",t=>e7(hr(t[0],"euler"))),orient:w1("x, z",t=>{let e=Kt(Oe(t[0],"orient"),"orient"),n=Oe(t[1]??[0,0,1],"orient"),r=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=Kt([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 e7([[e[0],c[0],n[0]],[e[1],c[1],n[1]],[e[2],c[2],n[2]]])})};function S5(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 Oe(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 Kt(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 hr(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 ur=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[1,0,0],[0,e,-n],[0,n,e]]},fr=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[e,0,n],[0,1,0],[-n,0,e]]},dr=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[e,-n,0],[n,e,0],[0,0,1]]},Qt=(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])),mr=t=>t.map(e=>e.map(o2));function e7(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 Re(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 A5=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function pr(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(A5(i*a,-1,(i+1)*a,n));return s}function w4(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 pr(s[l],o,r,c))i.push(h.map(a[l]))}),k0([A5(0,0,t,e)],i)}function s7(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(A5(i*a,-n/2,(i+1)*a,n/2));return s}function i7(t,e,n,r,c){let a=A5(-t/2,-1,t/2,e),s=A5(-n/2,c,n/2,c+r);return[a,s]}function o7(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 m2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var o1=class extends Error{constructor(n,r){super(r?`${n} (${m2(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})}},gr=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function N3(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 o1("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 o1("Bad \\u escape",i());f+=String.fromCharCode(parseInt(m,16)),o(4)}else f+=d;o(2);continue}if(t[c]===`
|
|
12
|
+
`)throw new o1("Unclosed string",h);f+=t[c],o(1)}if(c>=t.length)throw new o1("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=gr.find(f=>t.startsWith(f,c));if(!u)throw new o1(`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 d3={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"}},U3={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var $e=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function l2(t,e){let{tokens:n,comments:r}=N3(t,e),c=new De(n),a=[];for(;!c.at("eof");)a.push(...c.statement());return{program:{body:a},comments:r}}var C5=class C5{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 o1(`${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"||$e.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"||$e.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>=C5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&C5.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}):($e.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 o1(`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()}}};C5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var De=C5;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}),qe="max(3 * $thickness, 6)",k4=[O("value")],vr=[O("x")],J0=(t,e)=>({name:t,kind:"function",params:vr,section:"Numbers and vectors",doc:e}),m3=(t,e)=>({name:t,kind:"function",params:k4,section:"Types",doc:`Whether the value is ${e}`}),l7=(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}),Ne=[{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",qe)],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",qe)],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"},J0("abs","Absolute value"),J0("sign","Sign as -1, 0 or 1"),J0("floor","Round down"),J0("ceil","Round up"),J0("round","Round to the nearest integer, halves away from zero"),J0("sqrt","Square root"),J0("exp","e raised to x"),J0("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"},J0("sin","Sine of an angle in degrees"),J0("cos","Cosine of an angle in degrees"),J0("tan","Tangent of an angle in degrees"),J0("asin","Inverse sine, in degrees"),J0("acos","Inverse cosine, in degrees"),J0("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:k4,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:k4,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"},m3("is_num","a number other than NaN"),m3("is_string","a string"),m3("is_bool","true or false"),m3("is_list","a list"),m3("is_undef","undef"),m3("is_function","a function"),m3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:k4,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"},l7("text_width","The advance width of the text, including spacing"),l7("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",qe)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],yr=new Map(Ne.map(t=>[t.name,t])),B3=t=>yr.get(t);function z4(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var 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.
|
|
@@ -279,6 +279,70 @@ module vents(size, slot = 3, pitch = 6) {
|
|
|
279
279
|
translate([0, ends]) circle(d = slot, $fn = 24);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
+
`,"kerf/fit":`// kerf/fit: drawings scaled to a size and placed by a point of their box.
|
|
283
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
284
|
+
//
|
|
285
|
+
// For any drawing whose size you don't know beforehand: an imported SVG
|
|
286
|
+
// path, a silhouette, a symbol, a line of text. Each measures its children
|
|
287
|
+
// and moves or scales them, keeping their layers, so cut, score and
|
|
288
|
+
// engrave stay together. They are for drawings, not for parts: scaling a
|
|
289
|
+
// part would scale its joints and leave its thickness.
|
|
290
|
+
|
|
291
|
+
// The fractions of a box an anchor names, [0, 0] the bottom left and
|
|
292
|
+
// [1, 1] the top right: "center", "left", "right", "top", "bottom",
|
|
293
|
+
// "top-left", "top-right", "bottom-left", "bottom-right", or [fx, fy]
|
|
294
|
+
function anchor_point(anchor) =
|
|
295
|
+
is_list(anchor) ? anchor
|
|
296
|
+
: let (
|
|
297
|
+
a = lower(anchor),
|
|
298
|
+
fx = contains(a, "left") ? 0 : contains(a, "right") ? 1 : 0.5,
|
|
299
|
+
fy = contains(a, "bottom") ? 0 : contains(a, "top") ? 1 : 0.5
|
|
300
|
+
)
|
|
301
|
+
assert(
|
|
302
|
+
len([for (w = split(a, "-")) if (w != "center" && w != "left" && w != "right" && w != "top" && w != "bottom") w]) == 0,
|
|
303
|
+
str("Unknown anchor \\"", anchor, "\\": use center, left, right, top, bottom or a corner such as top-left")
|
|
304
|
+
)
|
|
305
|
+
[fx, fy];
|
|
306
|
+
|
|
307
|
+
// The children moved so the point of their box that \`anchor\` names is at
|
|
308
|
+
// the origin: align("bottom-left") puts their box's corner there, and
|
|
309
|
+
// align() centres them.
|
|
310
|
+
module align(anchor = "center") {
|
|
311
|
+
f = anchor_point(anchor);
|
|
312
|
+
measure() {
|
|
313
|
+
children();
|
|
314
|
+
if (!is_undef($bounds))
|
|
315
|
+
translate([-($bounds[0] + f[0] * ($bounds[2] - $bounds[0])), -($bounds[1] + f[1] * ($bounds[3] - $bounds[1]))])
|
|
316
|
+
children();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// The children scaled to \`size\` = [w, h] (or one number for a square):
|
|
321
|
+
// mode = "contain" keeps their proportions and fits them inside, "stretch"
|
|
322
|
+
// fills the size exactly. A drawing with no width or no height (a line)
|
|
323
|
+
// is scaled by the other side. They are then placed by \`anchor\` as
|
|
324
|
+
// align() does, the box's bottom left at the origin by default.
|
|
325
|
+
module fit(size, mode = "contain", anchor = "bottom-left") {
|
|
326
|
+
s = is_list(size) ? size : [size, size];
|
|
327
|
+
assert(s[0] > 0 && s[1] > 0, "fit(): size must be more than 0");
|
|
328
|
+
assert(mode == "contain" || mode == "stretch", "fit(): mode is \\"contain\\" or \\"stretch\\"");
|
|
329
|
+
f = anchor_point(anchor);
|
|
330
|
+
measure() {
|
|
331
|
+
children();
|
|
332
|
+
if (!is_undef($bounds)) {
|
|
333
|
+
w = $bounds[2] - $bounds[0];
|
|
334
|
+
h = $bounds[3] - $bounds[1];
|
|
335
|
+
kx = w > 0 ? s[0] / w : undef;
|
|
336
|
+
ky = h > 0 ? s[1] / h : undef;
|
|
337
|
+
k = mode == "stretch"
|
|
338
|
+
? [is_undef(kx) ? 1 : kx, is_undef(ky) ? 1 : ky]
|
|
339
|
+
: let (one = is_undef(kx) ? ky : is_undef(ky) ? kx : min(kx, ky)) [one, one];
|
|
340
|
+
if (!is_undef(k[0]))
|
|
341
|
+
translate([-f[0] * w * k[0], -f[1] * h * k[1]])
|
|
342
|
+
scale(k) translate([-$bounds[0], -$bounds[1]]) children();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
282
346
|
`,"kerf/gears":`// kerf/gears: gears, racks, lantern gears and cams for moving models.
|
|
283
347
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
284
348
|
//
|
|
@@ -1572,14 +1636,29 @@ function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
|
1572
1636
|
// symbol_names() lists them: "heart", "star", "paw", "tree" and the like.
|
|
1573
1637
|
// box = "grid" sizes and places it by its icon set's grid (24 x 24 for
|
|
1574
1638
|
// Material Design Icons) instead, so icons of one set line up as drawn.
|
|
1575
|
-
|
|
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) {
|
|
1576
1645
|
assert(box == "drawn" || box == "grid", "box is \\"drawn\\" or \\"grid\\"");
|
|
1577
1646
|
s = symbol_entry(name);
|
|
1578
1647
|
vb = box == "grid" ? s[5] : s[2];
|
|
1579
1648
|
k = size / max(vb[2], vb[3]);
|
|
1580
|
-
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])
|
|
1581
1650
|
scale([k, -k]) translate([-vb[0] - vb[2] / 2, -vb[1] - vb[3] / 2])
|
|
1582
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();
|
|
1583
1662
|
}
|
|
1584
1663
|
|
|
1585
1664
|
// [width, height] of what a symbol draws when it is \`size\` across its
|
|
@@ -2560,27 +2639,27 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
|
|
|
2560
2639
|
if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
|
|
2561
2640
|
if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
|
|
2562
2641
|
}
|
|
2563
|
-
`};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},c=Object.defineProperty,r=c(n,n,n)&&c}catch{}return r})(),e=function(n){if(this==null)throw TypeError();var c=String(this),r=c.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=r)){var s=c.charCodeAt(a),i;return s>=55296&&s<=56319&&r>a+1&&(i=c.charCodeAt(a+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var Ue=0,gt=-3;function M5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function V9(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new M5,this.dtree=new M5}var vt=new M5,yt=new M5,Be=new Uint8Array(30),_e=new Uint16Array(30),bt=new Uint8Array(30),xt=new Uint16Array(30),H9=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),E7=new M5,y2=new Uint8Array(320);function Mt(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 O9(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 I7=new Uint16Array(16);function ke(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)I7[r]=a,a+=t.table[r];for(r=0;r<c;++r)e[n+r]&&(t.trans[I7[e[n+r]]++]=r)}function R9(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function b2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var c=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,c+n}function Ve(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 F9(t,e,n){var c,r,a,s,i,o;for(c=b2(t,5,257),r=b2(t,5,1),a=b2(t,4,4),s=0;s<19;++s)y2[s]=0;for(s=0;s<a;++s){var l=b2(t,3,0);y2[H9[s]]=l}for(ke(E7,y2,0,19),i=0;i<c+r;){var h=Ve(t,E7);switch(h){case 16:var u=y2[i-1];for(o=b2(t,2,3);o;--o)y2[i++]=u;break;case 17:for(o=b2(t,3,3);o;--o)y2[i++]=0;break;case 18:for(o=b2(t,7,11);o;--o)y2[i++]=0;break;default:y2[i++]=h;break}}ke(e,y2,0,c),ke(n,y2,c,r)}function V7(t,e,n){for(;;){var c=Ve(t,e);if(c===256)return Ue;if(c<256)t.dest[t.destLen++]=c;else{var r,a,s,i;for(c-=257,r=b2(t,Be[c],_e[c]),a=Ve(t,n),s=t.destLen-b2(t,bt[a],xt[a]),i=s;i<s+r;++i)t.dest[t.destLen++]=t.dest[i]}}}function $9(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 gt;for(t.sourceIndex+=4,c=e;c;--c)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,Ue}function D9(t,e){var n=new V9(t,e),c,r,a;do{switch(c=R9(n),r=b2(n,2,0),r){case 0:a=$9(n);break;case 1:a=V7(n,vt,yt);break;case 2:F9(n,n.ltree,n.dtree),a=V7(n,n.ltree,n.dtree);break;default:a=gt}if(a!==Ue)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}O9(vt,yt);Mt(Be,_e,4,3);Mt(bt,xt,2,1);Be[28]=0;_e[28]=258;var q9=D9;function R3(t,e,n,c,r){return Math.pow(1-r,3)*t+3*Math.pow(1-r,2)*r*e+3*(1-r)*Math.pow(r,2)*n+Math.pow(r,3)*c}function X2(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}X2.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};X2.prototype.addPoint=function(t,e){typeof t=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};X2.prototype.addX=function(t){this.addPoint(t,null)};X2.prototype.addY=function(t){this.addPoint(null,t)};X2.prototype.addBezier=function(t,e,n,c,r,a,s,i){var o=[t,e],l=[n,c],h=[r,a],u=[s,i];this.addPoint(t,e),this.addPoint(s,i);for(var f=0;f<=1;f++){var d=6*o[f]-12*l[f]+6*h[f],p=-3*o[f]+9*l[f]-9*h[f]+3*u[f],m=3*l[f]-3*o[f];if(p===0){if(d===0)continue;var g=-m/d;0<g&&g<1&&(f===0&&this.addX(R3(o[f],l[f],h[f],u[f],g)),f===1&&this.addY(R3(o[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*m*p;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*p);0<y&&y<1&&(f===0&&this.addX(R3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(R3(o[f],l[f],h[f],u[f],y)));var b=(-d-Math.sqrt(v))/(2*p);0<b&&b<1&&(f===0&&this.addX(R3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(R3(o[f],l[f],h[f],u[f],b)))}}};X2.prototype.addQuad=function(t,e,n,c,r,a){var s=t+.6666666666666666*(n-t),i=e+2/3*(c-e),o=s+1/3*(r-t),l=i+1/3*(a-e);this.addBezier(t,e,s,i,o,l,r,a)};function M0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}M0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};M0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};M0.prototype.curveTo=M0.prototype.bezierCurveTo=function(t,e,n,c,r,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:c,x:r,y:a})};M0.prototype.quadTo=M0.prototype.quadraticCurveTo=function(t,e,n,c){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:c})};M0.prototype.close=M0.prototype.closePath=function(){this.commands.push({type:"Z"})};M0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof X2){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};M0.prototype.getBoundingBox=function(){for(var t=new X2,e=0,n=0,c=0,r=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=c=s.x,n=r=s.y;break;case"L":t.addPoint(s.x,s.y),c=s.x,r=s.y;break;case"Q":t.addQuad(c,r,s.x1,s.y1,s.x,s.y),c=s.x,r=s.y;break;case"C":t.addBezier(c,r,s.x1,s.y1,s.x2,s.y2,s.x,s.y),c=s.x,r=s.y;break;case"Z":c=e,r=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};M0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};M0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var c="",r=0;r<this.commands.length;r+=1){var a=this.commands[r];a.type==="M"?c+="M"+n(a.x,a.y):a.type==="L"?c+="L"+n(a.x,a.y):a.type==="C"?c+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?c+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(c+="Z")}return c};M0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};M0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function wt(t){throw new Error(t)}function H7(t,e){t||wt(e)}var k1={fail:wt,argument:H7,assert:H7},O7=32768,R7=2147483648,$3={},K={},C1={};function l2(t){return function(){return t}}K.BYTE=function(t){return k1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};C1.BYTE=l2(1);K.CHAR=function(t){return[t.charCodeAt(0)]};C1.CHAR=l2(1);K.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};C1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};K.USHORT=function(t){return[t>>8&255,t&255]};C1.USHORT=l2(2);K.SHORT=function(t){return t>=O7&&(t=-(2*O7-t)),[t>>8&255,t&255]};C1.SHORT=l2(2);K.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};C1.UINT24=l2(3);K.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.ULONG=l2(4);K.LONG=function(t){return t>=R7&&(t=-(2*R7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONG=l2(4);K.FIXED=K.ULONG;C1.FIXED=C1.ULONG;K.FWORD=K.SHORT;C1.FWORD=C1.SHORT;K.UFWORD=K.USHORT;C1.UFWORD=C1.USHORT;K.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONGDATETIME=l2(8);K.TAG=function(t){return k1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};C1.TAG=l2(4);K.Card8=K.BYTE;C1.Card8=C1.BYTE;K.Card16=K.USHORT;C1.Card16=C1.USHORT;K.OffSize=K.BYTE;C1.OffSize=C1.BYTE;K.SID=K.USHORT;C1.SID=C1.USHORT;K.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?K.NUMBER16(t):K.NUMBER32(t)};C1.NUMBER=function(t){return K.NUMBER(t).length};K.NUMBER16=function(t){return[28,t>>8&255,t&255]};C1.NUMBER16=l2(3);K.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.NUMBER32=l2(5);K.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var c=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*c)/c).toString()}for(var r="",a=0,s=e.length;a<s;a+=1){var i=e[a];i==="e"?r+=e[++a]==="-"?"c":"b":i==="."?r+="a":i==="-"?r+="e":r+=i}r+=r.length&1?"f":"ff";for(var o=[30],l=0,h=r.length;l<h;l+=2)o.push(parseInt(r.substr(l,2),16));return o};C1.REAL=function(t){return K.REAL(t).length};K.NAME=K.CHARARRAY;C1.NAME=C1.CHARARRAY;K.STRING=K.CHARARRAY;C1.STRING=C1.CHARARRAY;$3.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)};$3.UTF16=function(t,e,n){for(var c=[],r=n/2,a=0;a<r;a++,e+=2)c[a]=t.getUint16(e);return String.fromCharCode.apply(null,c)};K.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var c=t.charCodeAt(n);e[e.length]=c>>8&255,e[e.length]=c&255}return e};C1.UTF16=function(t){return t.length*2};var He={"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"};$3.MACSTRING=function(t,e,n,c){var r=He[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 h4=typeof WeakMap=="function"&&new WeakMap,u4,N9=function(t){if(!u4){u4={};for(var e in He)u4[e]=new String(e)}var n=u4[t];if(n!==void 0){if(h4){var c=h4.get(n);if(c!==void 0)return c}var r=He[t];if(r!==void 0){for(var a={},s=0;s<r.length;s++)a[r.charCodeAt(s)]=s+128;return h4&&h4.set(n,a),a}}};K.MACSTRING=function(t,e){var n=N9(e);if(n!==void 0){for(var c=[],r=0;r<t.length;r++){var a=t.charCodeAt(r);if(a>=128&&(a=n[a],a===void 0))return;c[r]=a}return c}};C1.MACSTRING=function(t,e){var n=K.MACSTRING(t,e);return n!==void 0?n.length:0};function Oe(t){return t>=-128&&t<=127}function U9(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 B9(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(!Oe(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 _9(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(s===0||Oe(s)&&a+1<r&&Oe(t[a+1]))break;++a,++c}n.push(64|c-1);for(var i=e;i<a;++i){var o=t[i];n.push(o+65536>>8&255,o+256&255)}return a}K.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var c=t[e];c===0?e=U9(t,e,n):c>=-128&&c<=127?e=B9(t,e,n):e=_9(t,e,n)}return n};K.INDEX=function(t){for(var e=1,n=[e],c=[],r=0;r<t.length;r+=1){var a=K.OBJECT(t[r]);Array.prototype.push.apply(c,a),e+=a.length,n.push(e)}if(c.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,K.BYTE,K.USHORT,K.UINT24,K.ULONG][i],l=0;l<n.length;l+=1){var h=o(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(K.Card16(t.length),K.OffSize(i),s,c)};C1.INDEX=function(t){return K.INDEX(t).length};K.DICT=function(t){for(var e=[],n=Object.keys(t),c=n.length,r=0;r<c;r+=1){var a=parseInt(n[r],0),s=t[a];e=e.concat(K.OPERAND(s.value,s.type)),e=e.concat(K.OPERATOR(a))}return e};C1.DICT=function(t){return K.DICT(t).length};K.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};K.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)k1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(K.OPERAND(t[c],e[c]));else if(e==="SID")n=n.concat(K.NUMBER(t));else if(e==="offset")n=n.concat(K.NUMBER32(t));else if(e==="number")n=n.concat(K.NUMBER(t));else if(e==="real")n=n.concat(K.REAL(t));else throw new Error("Unknown operand type "+e);return n};K.OP=K.BYTE;C1.OP=C1.BYTE;var f4=typeof WeakMap=="function"&&new WeakMap;K.CHARSTRING=function(t){if(f4){var e=f4.get(t);if(e!==void 0)return e}for(var n=[],c=t.length,r=0;r<c;r+=1){var a=t[r];n=n.concat(K[a.type](a.value))}return f4&&f4.set(t,n),n};C1.CHARSTRING=function(t){return K.CHARSTRING(t).length};K.OBJECT=function(t){var e=K[t.type];return k1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};C1.OBJECT=function(t){var e=C1[t.type];return k1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};K.TABLE=function(t){for(var e=[],n=t.fields.length,c=[],r=[],a=0;a<n;a+=1){var s=t.fields[a],i=K[s.type];k1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=t[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(r.push(e.length),e=e.concat([0,0]),c.push(l)):e=e.concat(l)}for(var h=0;h<c.length;h+=1){var u=r[h],f=e.length;k1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(c[h])}return e};C1.TABLE=function(t){for(var e=0,n=t.fields.length,c=0;c<n;c+=1){var r=t.fields[c],a=C1[r.type];k1.argument(a!==void 0,"No sizeOf function for field type "+r.type+" ("+r.name+")");var s=t[r.name];s===void 0&&(s=r.value),e+=a(s),r.type==="TABLE"&&(e+=2)}return e};K.RECORD=K.TABLE;C1.RECORD=C1.TABLE;K.LITERAL=function(t){return t};C1.LITERAL=function(t){return t.length};function P0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var c=0;c<e.length;c+=1){var r=e[c];this[r.name]=r.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var i=a[s],o=n[i];this[i]!==void 0&&(this[i]=o)}}P0.prototype.encode=function(){return K.TABLE(this)};P0.prototype.sizeOf=function(){return C1.TABLE(this)};function w5(t,e,n){n===void 0&&(n=e.length);var c=new Array(e.length+1);c[0]={name:t+"Count",type:"USHORT",value:n};for(var r=0;r<e.length;r++)c[r+1]={name:t+r,type:"USHORT",value:e[r]};return c}function Re(t,e,n){var c=e.length,r=new Array(c+1);r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return r}function z5(t,e,n){var c=e.length,r=[];r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r=r.concat(n(e[a],a));return r}function v4(t){t.format===1?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(w5("glyph",t.glyphs))):t.format===2?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(z5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):k1.assert(!1,"Coverage format must be 1 or 2.")}v4.prototype=Object.create(P0.prototype);v4.prototype.constructor=v4;function y4(t){P0.call(this,"scriptListTable",z5("scriptRecord",t,function(e,n){var c=e.script,r=c.defaultLangSys;return k1.assert(!!r,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new P0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new P0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:r.reqFeatureIndex}].concat(w5("featureIndex",r.featureIndexes)))}].concat(z5("langSys",c.langSysRecords,function(a,s){var i=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new P0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(w5("featureIndex",i.featureIndexes)))}]})))}]}))}y4.prototype=Object.create(P0.prototype);y4.prototype.constructor=y4;function b4(t){P0.call(this,"featureListTable",z5("featureRecord",t,function(e,n){var c=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new P0("featureTable",[{name:"featureParams",type:"USHORT",value:c.featureParams}].concat(w5("lookupListIndex",c.lookupListIndexes)))}]}))}b4.prototype=Object.create(P0.prototype);b4.prototype.constructor=b4;function x4(t,e){P0.call(this,"lookupListTable",Re("lookup",t,function(n){var c=e[n.lookupType];return k1.assert(!!c,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new P0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(Re("subtable",n.subtables,c)))}))}x4.prototype=Object.create(P0.prototype);x4.prototype.constructor=x4;var n1={Table:P0,Record:P0,Coverage:v4,ScriptList:y4,FeatureList:b4,LookupList:x4,ushortList:w5,tableList:Re,recordList:z5};function F7(t,e){return t.getUint8(e)}function M4(t,e){return t.getUint16(e,!1)}function G9(t,e){return t.getInt16(e,!1)}function Ge(t,e){return t.getUint32(e,!1)}function zt(t,e){var n=t.getInt16(e,!1),c=t.getUint16(e+2,!1);return n+c/65535}function j9(t,e){for(var n="",c=e;c<e+4;c+=1)n+=String.fromCharCode(t.getInt8(c));return n}function W9(t,e,n){for(var c=0,r=0;r<n;r+=1)c<<=8,c+=t.getUint8(e+r);return c}function X9(t,e,n){for(var c=[],r=e;r<n;r+=1)c.push(t.getUint8(r));return c}function Z9(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var Y9={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function O(t,e){this.data=t,this.offset=e,this.relativeOffset=0}O.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};O.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};O.prototype.parseCard8=O.prototype.parseByte;O.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};O.prototype.parseCard16=O.prototype.parseUShort;O.prototype.parseSID=O.prototype.parseUShort;O.prototype.parseOffset16=O.prototype.parseUShort;O.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};O.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};O.prototype.parseULong=function(){var t=Ge(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};O.prototype.parseOffset32=O.prototype.parseULong;O.prototype.parseFixed=function(){var t=zt(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};O.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,c="";this.relativeOffset+=t;for(var r=0;r<t;r++)c+=String.fromCharCode(e.getUint8(n+r));return c};O.prototype.parseTag=function(){return this.parseString(4)};O.prototype.parseLongDateTime=function(){var t=Ge(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};O.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};O.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=Y9[t]*e};O.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint32(c),c+=4;return this.relativeOffset+=t*4,e};O.prototype.parseOffset16List=O.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint16(c),c+=2;return this.relativeOffset+=t*2,e};O.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getInt16(c),c+=2;return this.relativeOffset+=t*2,e};O.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint8(c++);return this.relativeOffset+=t,e};O.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};O.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};O.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};O.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};O.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},c=0;c<e.length;c++){var r=e[c],a=t[r];n[r]=a.call(this)}return n};O.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};O.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),c=0;c<e;c++)n[c]=this.parseValueRecord(t);return n};O.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new O(this.data,this.offset+e).parseStruct(t)};O.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new O(this.data,this.offset+e).parseStruct(t)};O.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,c=this.relativeOffset,r=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){r[a]=void 0;continue}if(this.relativeOffset=s,t){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=t.call(this);r[a]=o}else r[a]=this.parseUShortList()}return this.relativeOffset=c,r};O.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var c=new Array(n),r=0;r<n;r++)c[r]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:c}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};O.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:O.uShort,end:O.uShort,classId:O.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};O.list=function(t,e){return function(){return this.parseList(t,e)}};O.list32=function(t,e){return function(){return this.parseList32(t,e)}};O.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};O.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};O.pointer=function(t){return function(){return this.parsePointer(t)}};O.pointer32=function(t){return function(){return this.parsePointer32(t)}};O.tag=O.prototype.parseTag;O.byte=O.prototype.parseByte;O.uShort=O.offset16=O.prototype.parseUShort;O.uShortList=O.prototype.parseUShortList;O.uLong=O.offset32=O.prototype.parseULong;O.uLongList=O.prototype.parseULongList;O.struct=O.prototype.parseStruct;O.coverage=O.prototype.parseCoverage;O.classDef=O.prototype.parseClassDef;var $7={reserved:O.uShort,reqFeatureIndex:O.uShort,featureIndexes:O.uShortList};O.prototype.parseScriptList=function(){return this.parsePointer(O.recordList({tag:O.tag,script:O.pointer({defaultLangSys:O.pointer($7),langSysRecords:O.recordList({tag:O.tag,langSys:O.pointer($7)})})}))||[]};O.prototype.parseFeatureList=function(){return this.parsePointer(O.recordList({tag:O.tag,feature:O.pointer({featureParams:O.offset16,lookupListIndexes:O.uShortList})}))||[]};O.prototype.parseLookupList=function(t){return this.parsePointer(O.list(O.pointer(function(){var e=this.parseUShort();k1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),c=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(O.pointer(t[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};O.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();k1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:O.offset32,featureTableSubstitutionOffset:O.offset32});return n})||[]};var f1={getByte:F7,getCard8:F7,getUShort:M4,getCard16:M4,getShort:G9,getULong:Ge,getFixed:zt,getTag:j9,getOffset:W9,getBytes:X9,bytesToString:Z9,Parser:O};function J9(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 K9(t,e,n,c,r){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new f1.Parser(n,c+r+14),i=new f1.Parser(n,c+r+16+a*2),o=new f1.Parser(n,c+r+16+a*4),l=new f1.Parser(n,c+r+16+a*6),h=c+r+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),p=i.parseUShort(),m=o.parseShort(),g=l.parseUShort(),v=p;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-p)*2,f=f1.getUShort(n,h),f!==0&&(f=f+m&65535)):f=v+m&65535,t.glyphIndexMap[v]=f}function Q9(t,e){var n={};n.version=f1.getUShort(t,e),k1.argument(n.version===0,"cmap table version should be 0."),n.numTables=f1.getUShort(t,e+2);for(var c=-1,r=n.numTables-1;r>=0;r-=1){var a=f1.getUShort(t,e+4+r*8),s=f1.getUShort(t,e+4+r*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){c=f1.getULong(t,e+4+r*8+4);break}}if(c===-1)throw new Error("No valid cmap sub-tables found.");var i=new f1.Parser(t,e+c);if(n.format=i.parseUShort(),n.format===12)J9(n,i);else if(n.format===4)K9(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 ec(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function tc(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function nc(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)ec(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}tc(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],p=[],m=[];for(n=0;n<o;n+=1){var g=a.segments[n];g.end<=65535&&g.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:g.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:g.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:g.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:g.offset}),g.glyphId!==void 0&&(p=p.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),m=m.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),m=m.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(a.segCountX2=(o-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(p),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+p.length*2,!e){var v=16+m.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:m.length/3}]),a.fields=a.fields.concat(m)}return a}var kt={parse:Q9,make:nc},m4=[".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"],cc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],rc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],i3=[".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 St(t){this.font=t}St.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 Lt(t){this.cmap=t}Lt.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function w4(t,e){this.encoding=t,this.charset=e}w4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function je(t){switch(t.version){case 1:this.names=i3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<i3.length?this.names[e]=i3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-i3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=i3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}je.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};je.prototype.glyphIndexToName=function(t){return this.names[t]};function ac(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 sc(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 ic(t,e){e.lowMemory?sc(t):ac(t)}function oc(t,e,n,c,r){t.beginPath(),t.moveTo(e,n),t.lineTo(c,r),t.stroke()}var s3={line:oc};function lc(t,e){var n=e||new M0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(c){n=c}}}function t2(t){this.bindConstructorValues(t)}t2.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",lc(this,t.path))};t2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};t2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};t2.prototype.getPath=function(t,e,n,c,r){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;c||(c={});var i=c.xScale,o=c.yScale;if(c.hinting&&r&&r.hinting&&(s=this.path&&r.hinting.exec(this,n)),s)a=r.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),i=o=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new M0,u=0;u<a.length;u+=1){var f=a[u];f.type==="M"?h.moveTo(t+f.x*i,e+-f.y*o):f.type==="L"?h.lineTo(t+f.x*i,e+-f.y*o):f.type==="Q"?h.quadraticCurveTo(t+f.x1*i,e+-f.y1*o,t+f.x*i,e+-f.y*o):f.type==="C"?h.curveTo(t+f.x1*i,e+-f.y1*o,t+f.x2*i,e+-f.y2*o,t+f.x*i,e+-f.y*o):f.type==="Z"&&h.closePath()}return h};t2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var c=this.points[n];e.push(c),c.lastPointOfContour&&(t.push(e),e=[])}return k1.argument(e.length===0,"There are still points left in the current contour."),t};t2.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};t2.prototype.draw=function(t,e,n,c,r){this.getPath(e,n,c,r).draw(t)};t2.prototype.drawPoints=function(t,e,n,c){function r(u,f,d,p){t.beginPath();for(var m=0;m<u.length;m+=1)t.moveTo(f+u[m].x*p,d+u[m].y*p),t.arc(f+u[m].x*p,d+u[m].y*p,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24;for(var a=1/this.path.unitsPerEm*c,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",r(s,e,n,a),t.fillStyle="red",r(i,e,n,a)};t2.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",s3.line(t,e,-1e4,e,1e4),s3.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",s3.line(t,e+a*r,-1e4,e+a*r,1e4),s3.line(t,e+i*r,-1e4,e+i*r,1e4),s3.line(t,-1e4,n+-s*r,1e4,n+-s*r),s3.line(t,-1e4,n+-o*r,1e4,n+-o*r),t.strokeStyle="green",s3.line(t,e+l*r,-1e4,e+l*r,1e4)};function d4(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 We(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}We.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]};We.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function hc(t,e){return new t2({index:e,font:t})}function uc(t,e,n,c,r,a){return function(){var s=new t2({index:e,font:t});return s.path=function(){n(s,c,r);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},d4(s,"xMin","_xMin"),d4(s,"xMax","_xMax"),d4(s,"yMin","_yMin"),d4(s,"yMax","_yMax"),s}}function fc(t,e,n,c){return function(){var r=new t2({index:e,font:t});return r.path=function(){var a=n(t,r,c);return a.unitsPerEm=t.unitsPerEm,a},r}}var M2={GlyphSet:We,glyphLoader:hc,ttfGlyphLoader:uc,cffGlyphLoader:fc};function At(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(!At(t[n],e[n]))return!1;return!0}else return!1}function Fe(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function _2(t,e,n){var c=[],r=[],a=f1.getCard16(t,e),s,i;if(a!==0){var o=f1.getByte(t,e+2);s=e+(a+1)*o+2;for(var l=e+3,h=0;h<a+1;h+=1)c.push(f1.getOffset(t,l,o)),l+=o;i=s+c[a]}else i=e+2;for(var u=0;u<c.length-1;u+=1){var f=f1.getBytes(t,s+c[u],s+c[u+1]);n&&(f=n(f)),r.push(f)}return{objects:r,startOffset:e,endOffset:i}}function dc(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 pc(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 mc(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 gc(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 mc(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 vc(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 Ct(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(gc(c,s))}return vc(r)}function x5(t,e){return e<=390?e=m4[e]:e=t[e-391],e}function Pt(t,e,n){for(var c={},r,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)r=t[s.op]!==void 0?t[s.op][o]:void 0,r===void 0&&(r=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(r=x5(n,r)),i[o]=r;c[s.name]=i}else r=t[s.op],r===void 0&&(r=s.value!==void 0?s.value:null),s.type==="SID"&&(r=x5(n,r)),c[s.name]=r}return c}function yc(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 Tt=[{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"}],Et=[{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 bc(t,e){var n=Ct(t,0,t.byteLength);return Pt(n,Tt,e)}function It(t,e,n,c){var r=Ct(t,e,n);return Pt(r,Et,c)}function D7(t,e,n,c){for(var r=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=bc(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=It(t,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=_2(t,u+e);i._subrs=f.objects,i._subrsBias=Fe(i._subrs)}i._privateDict=h}r.push(i)}return r}function xc(t,e,n,c){var r,a,s=new f1.Parser(t,e);n-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<n;l+=1)r=s.parseSID(),i.push(x5(c,r));else if(o===1)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)i.push(x5(c,r)),r+=1}else if(o===2)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)i.push(x5(c,r)),r+=1}else throw new Error("Unknown charset format "+o);return i}function Mc(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 w4(r,n)}function q7(t,e,n){var c,r,a,s,i=new M0,o=[],l=0,h=!1,u=!1,f=0,d=0,p,m,g,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];p=b._subrs,m=b._subrsBias,g=b._defaultWidthX,v=b._nominalWidthX}else p=t.tables.cff.topDict._subrs,m=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function M(z,S){u&&i.closePath(),i.moveTo(z,S),u=!0}function w(){var z;z=o.length%2!==0,z&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function k(z){for(var S,L,I,q,R,N,G,V,J,o1,Z,p1,E=0;E<z.length;){var $=z[E];switch(E+=1,$){case 1:w();break;case 3:w();break;case 4:o.length>1&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),M(f,d);break;case 5:for(;o.length>0;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 6:for(;o.length>0&&(f+=o.shift(),i.lineTo(f,d),o.length!==0);)d+=o.shift(),i.lineTo(f,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(f,d),o.length!==0);)f+=o.shift(),i.lineTo(f,d);break;case 8:for(;o.length>0;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 10:R=o.pop()+m,N=p[R],N&&k(N);break;case 11:return;case 12:switch($=z[E],E+=1,$){case 35:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s+o.shift(),J=G+o.shift(),o1=V+o.shift(),Z=J+o.shift(),p1=o1+o.shift(),f=Z+o.shift(),d=p1+o.shift(),o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 34:c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s,J=G+o.shift(),o1=s,Z=J+o.shift(),p1=d,f=Z+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 36:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s,J=G+o.shift(),o1=s,Z=J+o.shift(),p1=o1+o.shift(),f=Z+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 37:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s+o.shift(),J=G+o.shift(),o1=V+o.shift(),Z=J+o.shift(),p1=o1+o.shift(),Math.abs(Z-f)>Math.abs(p1-d)?f=Z+o.shift():d=p1+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+$),o.length=0}break;case 14:o.length>0&&!h&&(x=o.shift()+v,h=!0),u&&(i.closePath(),u=!1);break;case 18:w();break;case 19:case 20:w(),E+=l+7>>3;break;case 21:o.length>2&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),f+=o.pop(),M(f,d);break;case 22:o.length>1&&!h&&(x=o.shift()+v,h=!0),f+=o.pop(),M(f,d);break;case 23:w();break;case 24:for(;o.length>2;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 25:for(;o.length>6;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 26:for(o.length%2&&(f+=o.shift());o.length>0;)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a,d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s,i.curveTo(c,r,a,s,f,d);break;case 28:S=z[E],L=z[E+1],o.push((S<<24|L<<16)>>16),E+=2;break;case 29:R=o.pop()+t.gsubrsBias,N=t.gsubrs[R],N&&k(N);break;case 30:for(;o.length>0&&(c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;case 31:for(;o.length>0&&(c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;default:$<32?console.log("Glyph "+e.index+": unknown operator "+$):$<247?o.push($-139):$<251?(S=z[E],E+=1,o.push(($-247)*256+S+108)):$<255?(S=z[E],E+=1,o.push(-($-251)*256-S-108)):(S=z[E],L=z[E+1],I=z[E+2],q=z[E+3],E+=4,o.push((S<<24|L<<16|I<<8|q)/65536))}}}return k(n),e.advanceWidth=x,i}function wc(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 zc(t,e,n,c){n.tables.cff={};var r=yc(t,e),a=_2(t,r.endOffset,f1.bytesToString),s=_2(t,a.endOffset),i=_2(t,s.endOffset,f1.bytesToString),o=_2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=Fe(n.gsubrs);var l=D7(t,e,s.objects,i.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=_2(t,u),p=D7(t,e,d.objects,i.objects);h._fdArray=p,f+=e,h._fdSelect=wc(t,f,n.numGlyphs,p.length)}var m=e+h.private[1],g=It(t,m,h.private[0],i.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=m+g.subrs,y=_2(t,v);n.subrs=y.objects,n.subrsBias=Fe(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;c.lowMemory?(b=dc(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=_2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=xc(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new w4(cc,x):h.encoding===1?n.cffEncoding=new w4(rc,x):n.cffEncoding=Mc(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new M2.GlyphSet(n),c.lowMemory)n._push=function(k){var z=pc(k,b.offsets,t,e+h.charStrings);n.glyphs.push(k,M2.cffGlyphLoader(n,k,q7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var w=b.objects[M];n.glyphs.push(M,M2.cffGlyphLoader(n,M,q7,w))}}function Vt(t,e){var n,c=m4.indexOf(t);return c>=0&&(n=c),c=e.indexOf(t),c>=0?n=c+m4.length:(n=m4.length+e.length,e.push(t)),n}function kc(){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 Sc(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 Ht(t,e,n){for(var c={},r=0;r<t.length;r+=1){var a=t[r],s=e[a.name];s!==void 0&&!At(s,a.value)&&(a.type==="SID"&&(s=Vt(s,n)),c[a.op]={name:a.name,type:a.type,value:s})}return c}function N7(t,e){var n=new n1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=Ht(Tt,t,e),n}function U7(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 Ac(){return new n1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function Cc(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=Vt(r,e);n.fields.push({name:"glyph_"+c,type:"SID",value:a})}return n}function Pc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var c=0,r=0,a=0;a<n.commands.length;a+=1){var s=void 0,i=void 0,o=n.commands[a];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*c+h*o.x1),y1:Math.round(l*r+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="C"){var u=Math.round(o.x1-c),f=Math.round(o.y1-r),d=Math.round(o.x2-o.x1),p=Math.round(o.y2-o.y1);s=Math.round(o.x-o.x2),i=Math.round(o.y-o.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:p}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),c=Math.round(o.x),r=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function Tc(t){for(var e=new n1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var c=t.get(n),r=Pc(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:r})}return e}function Ec(t,e){var n=new n1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=Ht(Et,t,e),n}function Ic(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=kc(),n.nameIndex=Sc([e.postScriptName]);var h=N7(r,l);n.topDictIndex=U7(h),n.globalSubrIndex=Ac(),n.charsets=Cc(s,l),n.charStringsIndex=Tc(t),n.privateDict=Ec(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=N7(r,l),n.topDictIndex=U7(h),n}var Ot={parse:zc,make:Ic};function Vc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.fontRevision=Math.round(c.parseFixed()*1e3)/1e3,n.checkSumAdjustment=c.parseULong(),n.magicNumber=c.parseULong(),k1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=c.parseUShort(),n.unitsPerEm=c.parseUShort(),n.created=c.parseLongDateTime(),n.modified=c.parseLongDateTime(),n.xMin=c.parseShort(),n.yMin=c.parseShort(),n.xMax=c.parseShort(),n.yMax=c.parseShort(),n.macStyle=c.parseUShort(),n.lowestRecPPEM=c.parseUShort(),n.fontDirectionHint=c.parseShort(),n.indexToLocFormat=c.parseShort(),n.glyphDataFormat=c.parseShort(),n}function Hc(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 Rt={parse:Vc,make:Hc};function Oc(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 Rc(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 Ft={parse:Oc,make:Rc};function Fc(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 $c(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 Dc(t,e,n,c,r,a,s){s.lowMemory?$c(t,e,n,c,r):Fc(e,n,c,r,a)}function qc(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 $t={parse:Dc,make:qc};function Nc(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 Uc(t,e){var n=new f1.Parser(t,e),c=n.parseULong();k1.argument(c===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var r=n.parseULong(),a=[],s=0;s<r;s++){for(var i="",o=e+n.parseUShort(),l=n.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(t.getInt8(h));a.push(i)}return a}var Dt={make:Nc,parse:Uc};function Bc(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 _c(t){return new n1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var qt={parse:Bc,make:_c},Nt=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Ut={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},Bt={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 jc(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return Ut[e];case 3:return Bt[e]}}var $e="utf-16",Wc={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"},Xc={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 _t(t,e,n){switch(t){case 0:return $e;case 1:return Xc[n]||Wc[e];case 3:if(e===1||e===10)return $e;break}}function Zc(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=Nt[f]||f,p=r.parseUShort(),m=r.parseUShort(),g=jc(l,u,n),v=_t(l,h,u);if(v!==void 0&&g!==void 0){var y=void 0;if(v===$e?y=$3.UTF16(t,i+m,p):y=$3.MACSTRING(t,i+m,p,v),y){var b=c[d];b===void 0&&(b=c[d]={}),b[g]=y}}}var x=0;return a===1&&(x=r.parseUShort()),c}function Se(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function B7(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 Yc(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 _7(t,e){var n=Yc(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 Jc(t,e){var n,c=[],r={},a=Se(Nt);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=Se(Ut),l=Se(Bt),h=[],u=[],f=0;f<c.length;f++){n=c[f];var d=r[n];for(var p in d){var m=d[p],g=1,v=o[p],y=Gc[v],b=_t(g,y,v),x=K.MACSTRING(m,b);x===void 0&&(g=0,v=e.indexOf(p),v<0&&(v=e.length,e.push(p)),y=4,x=K.UTF16(m));var M=_7(x,u);h.push(B7(g,y,v,n,x.length,M));var w=l[p];if(w!==void 0){var k=K.UTF16(m),z=_7(k,u);h.push(B7(3,1,w,n,k.length,z))}}}h.sort(function(I,q){return I.platformID-q.platformID||I.encodingID-q.encodingID||I.languageID-q.languageID||I.nameID-q.nameID});for(var S=new n1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),L=0;L<h.length;L++)S.fields.push({name:"record_"+L,type:"RECORD",value:h[L]});return S.fields.push({name:"strings",type:"LITERAL",value:u}),S}var Gt={parse:Zc,make:Jc},De=[{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<De.length;e+=1){var n=De[e];if(t>=n.begin&&t<n.end)return e}return-1}function Qc(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 er(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 qe={parse:Qc,make:er,unicodeRanges:De,getUnicodeRange:Kc};function tr(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=i3.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]>=i3.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 nr(){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 jt={parse:tr,make:nr},s2=new Array(9);s2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(O.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(O.coverage),substitute:this.parseOffset16List()};k1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};s2[2]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),sequences:this.parseListOfLists()}};s2[3]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),alternateSets:this.parseListOfLists()}};s2[4]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var F3={sequenceIndex:O.uShort,lookupListIndex:O.uShort};s2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(O.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,F3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(O.coverage),classDef:this.parsePointer(O.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,F3)}})};if(n===3){var c=this.parseUShort(),r=this.parseUShort();return{substFormat:n,coverages:this.parseList(c,O.pointer(O.coverage)),lookupRecords:this.parseRecordList(r,F3)}}k1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};s2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(O.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(F3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(O.coverage),backtrackClassDef:this.parsePointer(O.classDef),inputClassDef:this.parsePointer(O.classDef),lookaheadClassDef:this.parsePointer(O.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(F3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(O.pointer(O.coverage)),inputCoverage:this.parseList(O.pointer(O.coverage)),lookaheadCoverage:this.parseList(O.pointer(O.coverage)),lookupRecords:this.parseRecordList(F3)};k1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};s2[7]=function(){var e=this.parseUShort();k1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),c=new O(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:s2[n].call(c)}};s2[8]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),backtrackCoverage:this.parseList(O.pointer(O.coverage)),lookaheadCoverage:this.parseList(O.pointer(O.coverage)),substitutes:this.parseUShortList()}};function cr(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);return k1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(s2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(s2),variations:n.parseFeatureVariationsList()}}var D3=new Array(9);D3[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)))};D3[2]=function(e){return k1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("seqSet",e.sequences,function(n){return new n1.Table("sequenceSetTable",n1.ushortList("sequence",n))})))};D3[3]=function(e){return k1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("altSet",e.alternateSets,function(n){return new n1.Table("alternateSetTable",n1.ushortList("alternate",n))})))};D3[4]=function(e){return k1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("ligSet",e.ligatureSets,function(n){return new n1.Table("ligatureSetTable",n1.tableList("ligature",n,function(c){return new n1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:c.ligGlyph}].concat(n1.ushortList("component",c.components,c.components.length+1)))}))})))};D3[6]=function(e){if(e.substFormat===1){var n=new n1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new n1.Table("chainRuleSetTable",n1.tableList("chainRule",a,function(s){var i=n1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(n1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(n1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(n1.ushortList("substitution",[],s.lookupRecords.length));return s.lookupRecords.forEach(function(o,l){i=i.concat({name:"sequenceIndex"+l,type:"USHORT",value:o.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:o.lookupListIndex})}),new n1.Table("chainRuleTable",i)}))})));return n}else if(e.substFormat===2)k1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var c=[{name:"substFormat",type:"USHORT",value:e.substFormat}];c.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(a,s){c.push({name:"backtrackCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){c.push({name:"inputCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){c.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){c=c.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var r=new n1.Table("chainContextTable",c);return r}k1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function rr(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,D3)}])}var Wt={parse:cr,make:rr};function ar(t,e){var n=new f1.Parser(t,e),c=n.parseULong();k1.argument(c===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var r=n.parseULong(),a={},s=0;s<r;s++){var i=n.parseTag(),o=n.parseULong(),l=n.parseULong(),h=$3.UTF8(t,e+o,l);a[i]=h}return a}function sr(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 Xt={parse:ar,make:sr};function G7(t){return Math.log(t)/Math.log(2)|0}function Xe(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 j7(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 Zt(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,G7(e.numTables));e.searchRange=16*n,e.entrySelector=G7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],r=[],a=e.sizeOf()+j7().sizeOf()*e.numTables;a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var i=t[s];k1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=j7(i.tableName,Xe(i.encode()),a,o);for(c.push({name:l.tag+" Table Record",type:"RECORD",value:l}),r.push({name:i.tableName+" table",type:"RECORD",value:i}),a+=o,k1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0})}return c.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(c),e.fields=e.fields.concat(r),e}function W7(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 ir(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function or(t){for(var e=[],n=[],c=[],r=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,p=0;p<t.glyphs.length;p+=1){var m=t.glyphs.get(p),g=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+p+"): advanceWidth is not a number.");(o>g||o===void 0)&&g>0&&(o=g),l<g&&(l=g);var v=qe.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(m.name!==".notdef"){var y=m.getMetrics();e.push(y.xMin),n.push(y.yMin),c.push(y.xMax),r.push(y.yMax),s.push(y.leftSideBearing),i.push(y.rightSideBearing),a.push(m.advanceWidth)}}var b={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,c),yMax:Math.max.apply(null,r),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:ir(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=Rt.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=Ft.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=qt.make(t.glyphs.length),k=qe.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:W7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:W7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=$t.make(t.glyphs),S=kt.make(t.glyphs),L=t.getEnglishName("fontFamily"),I=t.getEnglishName("fontSubfamily"),q=L+" "+I,R=t.getEnglishName("postScriptName");R||(R=L.replace(/\s/g,"")+"-"+I);var N={};for(var G in t.names)N[G]=t.names[G];N.uniqueID||(N.uniqueID={en:t.getEnglishName("manufacturer")+":"+q}),N.postScriptName||(N.postScriptName={en:R}),N.preferredFamily||(N.preferredFamily=t.names.fontFamily),N.preferredSubfamily||(N.preferredSubfamily=t.names.fontSubfamily);var V=[],J=Gt.make(N,V),o1=V.length>0?Dt.make(V):void 0,Z=jt.make(),p1=Ot.make(t.glyphs,{version:t.getEnglishName("version"),fullName:q,familyName:L,weightName:I,postScriptName:R,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),E=t.metas&&Object.keys(t.metas).length>0?Xt.make(t.metas):void 0,$=[x,M,w,k,J,S,Z,p1,z];o1&&$.push(o1),t.tables.gsub&&$.push(Wt.make(t.tables.gsub)),E&&$.push(E);for(var X=Zt($),j=X.encode(),w1=Xe(j),W1=X.fields,E1=!1,Z1=0;Z1<W1.length;Z1+=1)if(W1[Z1].name==="head table"){W1[Z1].value.checkSumAdjustment=2981146554-w1,E1=!0;break}if(!E1)throw new Error("Could not find head table with checkSum to adjust.");return X}var lr={make:Zt,fontToTable:or,computeCheckSum:Xe};function Le(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 X7(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 Z7(t,e){for(var n,c=0,r=t.length-1;c<=r;){var a=c+r>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?c=a+1:r=a-1}if(c>0)return n=t[c-1],e>n.end?0:n}function S5(t,e){this.font=t,this.tableName=e}S5.prototype={searchTag:Le,binSearch:X7,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=Le(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=Le(c.langSysRecords,e);if(r>=0)return c.langSysRecords[r].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return c.langSysRecords.splice(-1-r,0,a),a.langSys}}},getFeatureTable:function(t,e,n,c){var r=this.getLangSysTable(t,e,c);if(r){for(var a,s=r.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(a=i[s[o]],a.tag===n)return a.feature;if(c){var l=i.length;return k1.assert(l===0||n>=i[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},i.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,c,r){var a=this.getFeatureTable(t,e,n,r),s=[];if(a){for(var i,o=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===c&&s.push(i);if(s.length===0&&r){i={lookupType:c,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(i),o.push(u),[i]}}return s},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=Z7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=X7(t.glyphs,e);return n>=0?n:-1;case 2:var c=Z7(t.ranges,e);return c?c.index+e-c.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,c=0;c<n.length;c++)for(var r=n[c],a=r.start,s=r.end,i=a;i<=s;i++)e.push(i);return e}};function L5(t){S5.call(this,t,"gpos")}L5.prototype=S5.prototype;L5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};L5.prototype.getKerningValue=function(t,e,n){for(var c=0;c<t.length;c++)for(var r=t[c].subtables,a=0;a<r.length;a++){var s=r[a],i=this.getCoverageIndex(s.coverage,e);if(!(i<0))switch(s.posFormat){case 1:for(var o=s.pairSets[i],l=0;l<o.length;l++){var h=o[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};L5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function X0(t){S5.call(this,t,"gsub")}function hr(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 Ze(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}X0.prototype=S5.prototype;X0.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};X0.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};X0.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};X0.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};X0.prototype.getLigatures=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,4),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],p=0;p<d.length;p++){var m=d[p];c.push({sub:[f].concat(m.components),by:m.ligGlyph})}return c};X0.prototype.addSingle=function(t,e,n,c){var r=this.getLookupTables(n,c,t,1,!0)[0],a=Ze(r,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});k1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.substitute.splice(i,0,0)),a.substitute[i]=e.by};X0.prototype.addMultiple=function(t,e,n,c){k1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var r=this.getLookupTables(n,c,t,2,!0)[0],a=Ze(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});k1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.sequences.splice(i,0,0)),a.sequences[i]=e.by};X0.prototype.addAlternate=function(t,e,n,c){var r=this.getLookupTables(n,c,t,3,!0)[0],a=Ze(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});k1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.alternateSets.splice(i,0,0)),a.alternateSets[i]=e.by};X0.prototype.addLigature=function(t,e,n,c){var r=this.getLookupTables(n,c,t,4,!0)[0],a=r.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},r.subtables[0]=a),k1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(hr(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])};X0.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)}};X0.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 ur(){return typeof window<"u"}function fr(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),c=0;c<e.length;++c)e[c]=n[c];return e}function b5(t,e){if(!t)throw e}function Y7(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 Yt(t,e,n){var c=new f1.Parser(e,n);t.numberOfContours=c.parseShort(),t._xMin=c.parseShort(),t._yMin=c.parseShort(),t._xMax=c.parseShort(),t._yMax=c.parseShort();var r,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],i=0;i<t.numberOfContours;i+=1)s.push(c.parseUShort());t.instructionLength=c.parseUShort(),t.instructions=[];for(var o=0;o<t.instructionLength;o+=1)t.instructions.push(c.parseByte());var l=s[s.length-1]+1;r=[];for(var h=0;h<l;h+=1)if(a=c.parseByte(),r.push(a),(a&8)>0)for(var u=c.parseByte(),f=0;f<u;f+=1)r.push(a),h+=1;if(k1.argument(r.length===l,"Bad flags."),s.length>0){var d=[],p;if(l>0){for(var m=0;m<l;m+=1)a=r[m],p={},p.onCurve=!!(a&1),p.lastPointOfContour=s.indexOf(m)>=0,d.push(p);for(var g=0,v=0;v<l;v+=1)a=r[v],p=d[v],p.x=Y7(c,a,g,2,16),g=p.x;for(var y=0,b=0;b<l;b+=1)a=r[b],p=d[b],p.y=Y7(c,a,y,4,32),y=p.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){r=c.parseUShort();var M={glyphIndex:c.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(r&1)>0?(r&2)>0?(M.dx=c.parseShort(),M.dy=c.parseShort()):M.matchedPoints=[c.parseUShort(),c.parseUShort()]:(r&2)>0?(M.dx=c.parseChar(),M.dy=c.parseChar()):M.matchedPoints=[c.parseByte(),c.parseByte()],(r&8)>0?M.xScale=M.yScale=c.parseF2Dot14():(r&64)>0?(M.xScale=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()):(r&128)>0&&(M.xScale=c.parseF2Dot14(),M.scale01=c.parseF2Dot14(),M.scale10=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()),t.components.push(M),x=!!(r&32)}if(r&256){t.instructionLength=c.parseUShort(),t.instructions=[];for(var w=0;w<t.instructionLength;w+=1)t.instructions.push(c.parseByte())}}}function Ae(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 dr(t){for(var e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];n.push(r),r.lastPointOfContour&&(e.push(n),n=[])}return k1.argument(n.length===0,"There are still points left in the current contour."),e}function Jt(t){var e=new M0;if(!t)return e;for(var n=dr(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 Kt(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=Ae(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=Ae([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=Ae(r.points,o)}e.points=e.points.concat(a)}}return Jt(e.points)}function pr(t,e,n,c){for(var r=new M2.GlyphSet(c),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?r.push(a,M2.ttfGlyphLoader(c,a,Yt,t,e+s,Kt)):r.push(a,M2.glyphLoader(c,a))}return r}function mr(t,e,n,c){var r=new M2.GlyphSet(c);return c._push=function(a){var s=n[a],i=n[a+1];s!==i?r.push(a,M2.ttfGlyphLoader(c,a,Yt,t,e+s,Kt)):r.push(a,M2.glyphLoader(c,a))},r}function gr(t,e,n,c,r){return r.lowMemory?mr(t,e,n,c):pr(t,e,n,c)}var Qt={getPath:Jt,parse:gr},e8,l3,t8,Ne;function n8(t){this.font=t,this.getCommands=function(e){return Qt.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function vr(t){return t}function c8(t){return Math.sign(t)*Math.round(Math.abs(t))}function yr(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function br(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function xr(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function Mr(t){return Math.sign(t)*Math.floor(Math.abs(t))}var r8=function(t){var e=this.srPeriod,n=this.srPhase,c=this.srThreshold,r=1;return t<0&&(t=-t,r=-1),t+=c-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*r:t*r},x2={x:1,y:0,axis:"x",distance:function(t,e,n,c){return(n?t.xo:t.x)-(c?e.xo:e.x)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.xo-e.xo,a=t.xo-n.xo,o=e.x-e.xo,l=n.x-n.xo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.x=t.xo+(o+l)/2;return}t.x=t.xo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){x2.setRelative(t,t,(o+l)/2,c,!0);return}x2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,c,r){if(!c||c===this){t.x=(r?e.xo:e.x)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.x=i+(t.y-o)/c.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},E2={x:0,y:1,axis:"y",distance:function(t,e,n,c){return(n?t.yo:t.y)-(c?e.yo:e.y)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.yo-e.yo,a=t.yo-n.yo,o=e.y-e.yo,l=n.y-n.yo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.y=t.yo+(o+l)/2;return}t.y=t.yo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){E2.setRelative(t,t,(o+l)/2,c,!0);return}E2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:0,setRelative:function(t,e,n,c,r){if(!c||c===this){t.y=(r?e.yo:e.y)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.y=o+c.normalSlope*(t.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(x2);Object.freeze(E2);function A5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}A5.prototype.distance=function(t,e,n,c){return this.x*x2.distance(t,e,n,c)+this.y*E2.distance(t,e,n,c)};A5.prototype.interpolate=function(t,e,n,c){var r,a,s,i,o,l,h;if(s=c.distance(t,e,!0,!0),i=c.distance(t,n,!0,!0),r=c.distance(e,e,!1,!0),a=c.distance(n,n,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(t,t,(r+a)/2,c,!0);return}this.setRelative(t,t,(r*l+a*o)/h,c,!0)};A5.prototype.setRelative=function(t,e,n,c,r){c=c||this;var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y,l=c.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*i+o-f)/(h-l),t.y=h*(t.x-u)+f};A5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function C5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?x2:t===0&&e===1?E2:new A5(t,e)}function I2(t,e,n,c){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=c,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}I2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};I2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var k5=Object.freeze(new I2(0,0)),wr={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function G2(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=x2,this.round=c8}}n8.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,c=this._prepState;if(!c||c.ppem!==e){var r=this._fpgmState;if(!r){G2.prototype=wr,r=this._fpgmState=new G2("fpgm",n.tables.fpgm),r.funcs=[],r.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),r.step=-1);try{l3(r)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}G2.prototype=r,c=this._prepState=new G2("prep",n.tables.prep),c.ppem=e;var a=n.tables.cvt;if(a)for(var s=c.cvt=new Array(a.length),i=e/n.unitsPerEm,o=0;o<a.length;o++)s[o]=a[o]*i;else c.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),c.step=-1);try{l3(c)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return t8(t,c)}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,c=n,r=t.components,a,s,i;if(G2.prototype=e,!r)i=new G2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),Ne(t,i,n,c),s=i.gZone;else{var o=e.font;s=[],a=[];for(var l=0;l<r.length;l++){var h=r[l],u=o.glyphs.get(h.glyphIndex);i=new G2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),Ne(u,i,n,c);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*c),p=i.gZone,m=i.contours,g=0;g<p.length;g++){var v=p[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,p);for(var b=0;b<m.length;b++)a.push(m[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new G2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new I2(0,0),new I2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),l3(i),s.length-=2)}return s};Ne=function(t,e,n,c){for(var r=t.points||[],a=r.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<a;l++)o=r[l],s[l]=new I2(o.x*n,o.y*c,o.lastPointOfContour,o.onCurve);for(var h,u,f=0;f<a;f++)o=s[f],h||(h=o,i.push(f)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(u=s[f+1],o.nextPointOnContour=u,u.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new I2(0,0),new I2(Math.round(t.advanceWidth*n),0)),l3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var p=0;p<a;p++)console.log(p,s[p].x,s[p].y)}}};l3=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=e8[e[t.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));c(t)}}};function z4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new I2(0,0)}function a8(t,e){var n=t.prog,c=t.ip,r=1,a;do if(a=n[++c],a===88)r++;else if(a===89)r--;else if(a===64)c+=n[c+1]+1;else if(a===65)c+=2*n[c+1]+1;else if(a>=176&&a<=183)c+=a-176+1;else if(a>=184&&a<=191)c+=(a-184+1)*2;else if(e&&r===1&&a===27)break;while(r>0);t.ip=c}function J7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function K7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function Q7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function et(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.pv=e.dpv=C5(i,o)}function tt(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SFVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.fv=C5(i,o)}function zr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.pv=t.dpv=C5(c,n)}function kr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.fv=C5(c,n)}function Sr(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 Ar(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function Cr(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop(),a=e.pop(),s=e.pop(),i=t.z0,o=t.z1,l=i[n],h=i[c],u=o[r],f=o[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,c,r,a,s);var p=l.x,m=l.y,g=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,w=(p-g)*(b-M)-(m-v)*(y-x),k=p*v-m*g,z=y*M-b*x;d.x=(k*(y-x)-z*(p-g))/w,d.y=(k*(b-M)-z*(m-v))/w}function Pr(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function Tr(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function Er(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function Ir(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||z4(t),t.z0=t.tZone;break;case 1:t.z0=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,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||z4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function Hr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||z4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function Or(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||z4(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 Rr(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function Fr(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=c8}function $r(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=br}function Dr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function qr(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),a8(t,!1)}function Nr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Ur(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Br(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function Ce(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function _r(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Gr(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 jr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Wr(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++)l3(t),exports.DEBUG&&console.log(++t.step,s+1<c?"next loopcall":"done loopcall",s);t.ip=r,t.prog=a}function Xr(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],l3(t),t.ip=n,t.prog=c,exports.DEBUG&&console.log(++t.step,"returning from",e)}function Zr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Yr(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 Jr(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 nt(t,e){var n=e.stack.pop(),c=e.z0[n],r=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(c,k5);t&&(s=e.round(s)),r.setRelative(c,k5,s,a),r.touch(c),e.rp0=e.rp1=n}function ct(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 rt(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 at(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 st(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 Kr(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 Qr(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 it(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 ea(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 ta(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=yr}function ot(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z0[r],s=e.fv,i=e.pv,o=e.cvt[c];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",c,"(",o,")",r);var l=i.distance(a,k5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,k5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=r}function na(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 ca(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 ra(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 aa(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 sa(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 ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function lt(t,e){var n=e.stack,c=n.pop(),r=e.z2[c];exports.DEBUG&&console.log(e.step,"GC["+t+"]",c),n.push(e.dpv.distance(r,k5,t,!1)*64)}function ht(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 oa(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function la(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function ha(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 ua(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 fa(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 da(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 pa(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 ma(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 ga(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 va(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 ya(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(a8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function ba(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function xa(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 Ma(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 wa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function Pe(t,e){var n=e.stack,c=n.pop(),r=e.fv,a=e.pv,s=e.ppem,i=e.deltaBase+(t-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",c,n);for(var h=0;h<c;h++){var u=n.pop(),f=n.pop(),d=i+((f&240)>>4);if(d===s){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",p*o);var m=l[u];r.setRelative(m,m,p*o,a)}}}function za(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function ka(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function Sa(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 Aa(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 Ca(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,c),e.push(c*n/64)}function Pa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function Ta(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function Ea(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function Ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function p4(t,e){var n=e.stack,c=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(c/64)*64)}function Va(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 Te(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 Ha(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=r8;var n;switch(e&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw new Error("invalid SROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Oa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=r8;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Ra(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=vr}function Fa(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=xr}function $a(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=Mr}function Da(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function ut(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.dpv=C5(i,o)}function qa(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 Na(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 Ua(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 Ba(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 _a(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ga(t){var e=t.stack.pop(),n=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"INSTCTRL[]",e,n),e){case 1:t.inhibitGridFit=!!n;return;case 2:t.ignoreCvt=!!n;return;default:throw new Error("invalid INSTCTRL[] selector")}}function U2(t,e){var n=e.stack,c=e.prog,r=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(c[++r]);e.ip=r}function B2(t,e){var n=e.ip,c=e.prog,r=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=c[++n]<<8|c[++n];s&32768&&(s=-((s^65535)+1)),r.push(s)}e.ip=n}function h1(t,e,n,c,r,a){var s=a.stack,i=t&&s.pop(),o=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[o],f=a.minDis,d=a.fv,p=a.dpv,m,g,v,y;g=m=p.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(y=a.cvt[i],c&&Math.abs(g-y)<a.cvCutIn&&(g=y)),n&&g<f&&(g=f),c&&(g=a.round(g)),d.setRelative(u,h,v*g,p),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(c?"R":"_")+(r===0?"Gr":r===1?"Bl":r===2?"Wh":"")+"]",t?i+"("+a.cvt[i]+","+y+")":"",o,"(d =",m,"->",v*g,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}e8=[J7.bind(void 0,E2),J7.bind(void 0,x2),K7.bind(void 0,E2),K7.bind(void 0,x2),Q7.bind(void 0,E2),Q7.bind(void 0,x2),et.bind(void 0,0),et.bind(void 0,1),tt.bind(void 0,0),tt.bind(void 0,1),zr,kr,Sr,Lr,Ar,Cr,Pr,Tr,Er,Ir,Vr,Hr,Or,Rr,Fr,$r,Dr,qr,Nr,Ur,void 0,void 0,Br,Ce,_r,Gr,jr,Zr,Yr,void 0,void 0,void 0,Wr,Xr,Jr,void 0,nt.bind(void 0,0),nt.bind(void 0,1),ct.bind(void 0,E2),ct.bind(void 0,x2),rt.bind(void 0,0),rt.bind(void 0,1),at.bind(void 0,0),at.bind(void 0,1),st.bind(void 0,0),st.bind(void 0,1),Kr,Qr,it.bind(void 0,0),it.bind(void 0,1),ea,ta,ot.bind(void 0,0),ot.bind(void 0,1),na,ca,ra,aa,sa,ia,lt.bind(void 0,0),lt.bind(void 0,1),void 0,ht.bind(void 0,0),ht.bind(void 0,1),oa,void 0,la,void 0,void 0,ha,ua,fa,da,pa,ma,ga,va,ya,ba,xa,Ma,wa,Pe.bind(void 0,1),za,ka,Sa,La,Aa,Ca,Pa,Ta,Ea,Ia,p4.bind(void 0,0),p4.bind(void 0,1),p4.bind(void 0,2),p4.bind(void 0,3),void 0,void 0,void 0,void 0,Va,Pe.bind(void 0,2),Pe.bind(void 0,3),Te.bind(void 0,1),Te.bind(void 0,2),Te.bind(void 0,3),Ha,Oa,void 0,void 0,Ra,void 0,Fa,$a,Ce,Ce,void 0,void 0,void 0,void 0,void 0,Da,ut.bind(void 0,0),ut.bind(void 0,1),qa,void 0,Na,Ua,Ba,_a,Ga,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 q3(t){this.char=t,this.state={},this.activeState=null}function Ye(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function ja(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function i2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function k4(t){this.eventId=t,this.subscribers=[]}function Wa(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 k4(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=[],Wa.call(this,t)}q3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};q3.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 q3});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 q3){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 q3});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)};k4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};k4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};i2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};i2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};u0.prototype.rangeToText=function(t){if(t instanceof Ye)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 k4&&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 ja(t,e,n);return this.registeredContexts[t]=c,this.contextCheckers.push(c),c};u0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};u0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};u0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};u0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(c){return c.char}),e=0;e<t.length;e++){var n=new i2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};u0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,c=new Ye(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 Ye(n,null,r),e.getContext(r).openRange=a,e.dispatch("contextStart",[r,n])),a&&c.checkEnd(t)){var s=n-a.startIndex+1,i=e.setEndOffset(s,r);e.dispatch("contextEnd",[r,i])}})};u0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var c=e[n],r=new i2(e,n);this.dispatch("next",[r]),this.runContextCheck(r);var a=new q3(c);this.tokens.push(a),this.dispatch("newToken",[a,r])}return this.dispatch("end",[this.tokens]),this.tokens};function j2(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function s8(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 g4(t){return/[A-z]/.test(t)}function Xa(t){return/\s/.test(t)}function Z0(t){this.font=t,this.features={}}function o3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function P5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,c=0;c<n.length;c++){var r=n[c];if(t>=r.start&&t<=r.end){var a=t-r.start;return r.index+a}}break;default:return-1}return-1}function Za(t,e){var n=P5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Ya(t,e){var n=P5(t,e.coverage);return n===-1?null:e.substitute[n]}function Ee(t,e){for(var n=[],c=0;c<t.length;c++){var r=t[c],a=e.current;a=Array.isArray(a)?a[0]:a;var s=P5(a,r);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function Ja(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var c=Ee(e.inputCoverage,t);if(c===-1)return[];var r=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(r);a.length&&W2(a[0].char);)a.shift();var s=new i2(a,0),i=Ee(e.lookaheadCoverage,s),o=[].concat(t.backtrack);for(o.reverse();o.length&&W2(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new i2(o,0),h=Ee(e.backtrackCoverage,l),u=c.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var p=e.lookupRecords[d],m=p.lookupListIndex,g=this.getLookupByIndex(m),v=0;v<g.subtables.length;v++){var y=g.subtables[v],b=this.getLookupMethod(g,y),x=this.getSubstitutionType(g,y);if(x==="12")for(var M=0;M<c.length;M++){var w=t.get(M),k=b(w);k&&f.push(k)}}return f}function Ka(t,e){var n=t.current,c=P5(n,e.coverage);if(c===-1)return null;for(var r,a=e.ligatureSets[c],s=0;s<a.length;s++){r=a[s];for(var i=0;i<r.components.length;i++){var o=t.lookahead[i],l=r.components[i];if(o!==l)break;if(i===r.components.length-1)return r}}return null}function Qa(t,e){var n=P5(t,e.coverage);return n===-1?null:e.sequences[n]}Z0.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[]};Z0.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()};Z0.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};Z0.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};Z0.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),c=e.substFormat.toString();return n+c};Z0.prototype.getLookupMethod=function(t,e){var n=this,c=this.getSubstitutionType(t,e);switch(c){case"11":return function(r){return Za.apply(n,[r,e])};case"12":return function(r){return Ya.apply(n,[r,e])};case"63":return function(r){return Ja.apply(n,[r,e])};case"41":return function(r){return Ka.apply(n,[r,e])};case"21":return function(r){return Qa.apply(n,[r,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};Z0.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 o3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new o3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new o3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new o3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new o3({id:21,tag:t.tag,substitution:d}));break}e=new i2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};Z0.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};Z0.prototype.getLookupSubtables=function(t){return t.subtables||null};Z0.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};Z0.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};Z0.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 es(t){var e=t.current,n=t.get(-1);return n===null&&j2(e)||!j2(n)&&j2(e)}function ts(t){var e=t.get(1);return e===null||!j2(e)}var ns={startCheck:es,endCheck:ts};function cs(t){var e=t.current,n=t.get(-1);return(j2(e)||W2(e))&&!j2(n)}function rs(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!j2(e)&&!W2(e)):var n=Xa(e);if(!n)return!0;if(n){var c=!1;if(c=t.lookahead.some(function(r){return j2(r)||W2(r)}),!c)return!0}break;default:return!1}}var as={startCheck:cs,endCheck:rs};function ss(t,e,n){e[n].setState(t.tag,t.substitution)}function is(t,e,n){e[n].setState(t.tag,t.substitution)}function os(t,e,n){t.substitution.forEach(function(c,r){var a=e[n+r];a.setState(t.tag,c)})}function ls(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 ft={11:ss,12:is,63:os,41:ls};function Je(t,e,n){t instanceof o3&&ft[t.id]&&ft[t.id](t,e,n)}function hs(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var c=e[n],r=s8(c),a=W2(c);if(!r&&!a)return!0;if(r)return!1}return!1}function us(t){if(s8(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 fs(t){var e=this,n="arab",c=this.featuresTags[n],r=this.tokenizer.getRangeTokens(t);if(r.length!==1){var a=new i2(r.map(function(i){return i.getState("glyphIndex")}),0),s=new i2(r.map(function(i){return i.char}),0);r.forEach(function(i,o){if(!W2(i.char)){a.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;hs(s)&&(l|=1),us(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 o3&&(Je(f,r,d),a.context[d]=f.substitution)})}}})}}function dt(t,e){var n=t.map(function(c){return c.activeState.value});return new i2(n,e||0)}function ds(t){var e=this,n="arab",c=this.tokenizer.getRangeTokens(t),r=dt(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 Je(o,c,s)}),r=dt(c))})}function ps(t){var e=t.current,n=t.get(-1);return n===null&&g4(e)||!g4(n)&&g4(e)}function ms(t){var e=t.get(1);return e===null||!g4(e)}var gs={startCheck:ps,endCheck:ms};function pt(t,e){var n=t.map(function(c){return c.activeState.value});return new i2(n,e||0)}function vs(t){var e=this,n="latn",c=this.tokenizer.getRangeTokens(t),r=pt(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 Je(o,c,s)}),r=pt(c))})}function h2(t){this.baseDir=t||"ltr",this.tokenizer=new u0,this.featuresTags={}}h2.prototype.setText=function(t){this.text=t};h2.prototype.contextChecks={latinWordCheck:gs,arabicWordCheck:ns,arabicSentenceCheck:as};function Ie(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function ys(){return Ie.call(this,"latinWord"),Ie.call(this,"arabicWord"),Ie.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function bs(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var c=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,c.reverse())})}h2.prototype.registerFeatures=function(t,e){var n=this,c=e.filter(function(r){return n.query.supports({script:t,tag:r})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(c):this.featuresTags[t]=c};h2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new Z0(t));for(var n=0;n<e.length;n++){var c=e[n];this.query.supports({script:c.script})&&this.registerFeatures(c.script,c.tags)}};h2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function Ke(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function xs(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){Ke.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(c){fs.call(t,c)})}}function Ms(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){Ke.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(r){ds.call(t,r)})}}}function ws(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){Ke.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(r){vs.call(t,r)})}}}h2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};h2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(xs.call(this),Ms.call(this)),this.checkContextReady("latinWord")&&ws.call(this),this.checkContextReady("arabicSentence")&&bs.call(this)};h2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),ys.call(this),this.applyFeaturesToContexts())};h2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};h2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var c=this.tokenizer.tokens[n];if(!c.state.deleted){var r=c.activeState.value;e.push(Array.isArray(r)?r[0]:r)}}return e};function t0(t){t=t||{},t.tables=t.tables||{},t.empty||(b5(t.familyName,"When creating a new Font object, familyName is required."),b5(t.styleName,"When creating a new Font object, styleName is required."),b5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),b5(t.ascender,"When creating a new Font object, ascender is required."),b5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new M2.GlyphSet(this,t.glyphs||[]),this.encoding=new St(this),this.position=new L5(this),this.substitution=new X0(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 n8(this)}})}t0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};t0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};t0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};t0.prototype.stringToGlyphs=function(t,e){var n=this,c=new h2,r=function(u){return n.charToGlyphIndex(u.char)};c.registerModifier("glyphIndex",null,r);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;c.applyFeatures(this,a);for(var s=c.getTextGlyphs(t),i=s.length,o=new Array(i),l=this.glyphs.get(0),h=0;h<i;h+=1)o[h]=this.glyphs.get(s[h])||l;return o};t0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};t0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};t0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};t0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};t0.prototype.forEachGlyph=function(t,e,n,c,r,a){e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:72,r=Object.assign({},this.defaultRenderOptions,r);var s=1/this.unitsPerEm*c,i=this.stringToGlyphs(t,r),o;if(r.kerning){var l=r.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,r.language)}for(var h=0;h<i.length;h+=1){var u=i[h];if(a.call(this,u,e,n,c,r),u.advanceWidth&&(e+=u.advanceWidth*s),r.kerning&&h<i.length-1){var f=o?this.position.getKerningValue(o,u.index,i[h+1].index):this.getKerningValue(u,i[h+1]);e+=f*s}r.letterSpacing?e+=r.letterSpacing*c:r.tracking&&(e+=r.tracking/1e3*c)}return e};t0.prototype.getPath=function(t,e,n,c,r){var a=new M0;return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.extend(h)}),a};t0.prototype.getPaths=function(t,e,n,c,r){var a=[];return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.push(h)}),a};t0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};t0.prototype.draw=function(t,e,n,c,r,a){this.getPath(e,n,c,r,a).draw(t)};t0.prototype.drawPoints=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawPoints(t,i,o,l)})};t0.prototype.drawMetrics=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawMetrics(t,i,o,l)})};t0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};t0.prototype.validate=function(){var t=this;function e(c,r){}function n(c){var r=t.getEnglishName(c);r&&r.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};t0.prototype.toTables=function(){return lr.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(ur())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=T7(),l=fr(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 i8(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 zs(t,e,n){var c=i8(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 ks(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 Ss(t,e,n,c){for(var r=i8(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 As(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(zs(c,t.axes[c],e));for(var r=0;r<t.instances.length;r++)n.fields=n.fields.concat(Ss(r,t.instances[r],t.axes,e));return n}function Cs(t,e,n){var c=new f1.Parser(t,e),r=c.parseULong();k1.argument(r===65536,"Unsupported fvar table version.");var a=c.parseOffset16();c.skip("uShort",1);for(var s=c.parseUShort(),i=c.parseUShort(),o=c.parseUShort(),l=c.parseUShort(),h=[],u=0;u<s;u++)h.push(ks(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,p=0;p<o;p++)f.push(Ls(t,d+p*l,h,n));return{axes:h,instances:f}}var Ps={make:As,parse:Cs},Ts=function(){return{coverage:this.parsePointer(O.coverage),attachPoints:this.parseList(O.pointer(O.uShortList))}},Es=function(){var t=this.parseUShort();if(k1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},Is=function(){return this.parseList(O.pointer(Es))},Vs=function(){return{coverage:this.parsePointer(O.coverage),ligGlyphs:this.parseList(O.pointer(Is))}},Hs=function(){return this.parseUShort(),this.parseList(O.pointer(O.coverage))};function Os(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);k1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var r={version:c,classDef:n.parsePointer(O.classDef),attachList:n.parsePointer(Ts),ligCaretList:n.parsePointer(Vs),markAttachClassDef:n.parsePointer(O.classDef)};return c>=1.2&&(r.markGlyphSets=n.parsePointer(Hs)),r}var Rs={parse:Os},o2=new Array(10);o2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(O.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(O.coverage),values:this.parseValueRecordList()};k1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};o2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();k1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(O.coverage),r=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,pairSets:this.parseList(O.pointer(O.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(O.classDef),i=this.parsePointer(O.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,O.list(l,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}}))}}};o2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};o2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};o2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};o2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};o2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};o2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};o2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Fs(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);return k1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(o2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(o2),variations:n.parseFeatureVariationsList()}}var $s=new Array(10);function Ds(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,$s)}])}var qs={parse:Fs,make:Ds};function Ns(t){var e={};t.skip("uShort");var n=t.parseUShort();k1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var c=t.parseUShort();t.skip("uShort",3);for(var r=0;r<c;r+=1){var a=t.parseUShort(),s=t.parseUShort(),i=t.parseShort();e[a+","+s]=i}return e}function Us(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 Bs(t,e){var n=new f1.Parser(t,e),c=n.parseUShort();if(c===0)return Ns(n);if(c===1)return Us(n);throw new Error("Unsupported kern table version ("+c+").")}var _s={parse:Bs};function Gs(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 js={parse:Gs};function mt(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 Ws(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(q9(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 o8(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=mt(a,s);else if(o==="OTTO")r.outlinesFormat="cff",s=f1.getUShort(a,4),i=mt(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=Ws(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,p,m,g,v,y,b,x,M,w=0;w<s;w+=1){var k=i[w],z=void 0;switch(k.tag){case"cmap":z=d0(a,k),r.tables.cmap=kt.parse(z.data,z.offset),r.encoding=new Lt(r.tables.cmap);break;case"cvt ":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.cvt=M.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.fpgm=M.parseByteList(k.length);break;case"head":z=d0(a,k),r.tables.head=Rt.parse(z.data,z.offset),r.unitsPerEm=r.tables.head.unitsPerEm,n=r.tables.head.indexToLocFormat;break;case"hhea":z=d0(a,k),r.tables.hhea=Ft.parse(z.data,z.offset),r.ascender=r.tables.hhea.ascender,r.descender=r.tables.hhea.descender,r.numberOfHMetrics=r.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":z=d0(a,k),c=Dt.parse(z.data,z.offset);break;case"maxp":z=d0(a,k),r.tables.maxp=qt.parse(z.data,z.offset),r.numGlyphs=r.tables.maxp.numGlyphs;break;case"name":b=k;break;case"OS/2":z=d0(a,k),r.tables.os2=qe.parse(z.data,z.offset);break;case"post":z=d0(a,k),r.tables.post=jt.parse(z.data,z.offset),r.glyphNames=new je(r.tables.post);break;case"prep":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.prep=M.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":y=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":p=k;break;case"GSUB":m=k;break;case"meta":x=k;break}}var S=d0(a,b);if(r.tables.name=Gt.parse(S.data,S.offset,c),r.names=r.tables.name,f&&y){var L=n===0,I=d0(a,y),q=js.parse(I.data,I.offset,r.numGlyphs,L),R=d0(a,f);r.glyphs=Qt.parse(R.data,R.offset,q,r,e)}else if(h){var N=d0(a,h);Ot.parse(N.data,N.offset,r,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var G=d0(a,g);if($t.parse(r,G.data,G.offset,r.numberOfHMetrics,r.numGlyphs,r.glyphs,e),ic(r,e),v){var V=d0(a,v);r.kerningPairs=_s.parse(V.data,V.offset)}else r.kerningPairs={};if(d){var J=d0(a,d);r.tables.gdef=Rs.parse(J.data,J.offset)}if(p){var o1=d0(a,p);r.tables.gpos=qs.parse(o1.data,o1.offset),r.position.init()}if(m){var Z=d0(a,m);r.tables.gsub=Wt.parse(Z.data,Z.offset)}if(u){var p1=d0(a,u);r.tables.fvar=Ps.parse(p1.data,p1.offset,r.names)}if(x){var E=d0(a,x);r.tables.meta=Xt.parse(E.data,E.offset),r.metas=r.tables.meta}return r}var S4=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=j0(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=o8(a);return this.parsed.set(n,s),s}};function Xs(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 l8(t,e,n){let{cmds:c,advance:r}=Xs(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 L4(t,e,n){if(!e)return[];let c=t.get(n.font),{polys:r,advance:a}=l8(c,e,n),s=x1(r),i=S0(s);if(!i)return[];let o=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-i[3]:n.valign==="center"?-(i[1]+i[3])/2:n.valign==="bottom"?-i[1]:0;return s.map(h=>h.map(([u,f])=>[u+o,f+l]))}function Qe(t,e,n){let c=t.get(n.font),{polys:r,advance:a}=l8(c,e,n),s=S0(r)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:c.ascender/c.unitsPerEm*n.size,descent:c.descender/c.unitsPerEm*n.size}}var e6=128,T5=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],r6={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Zs(t,e){if(!t||j0(c6,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 Ys=100,Js={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},N3=4,h8=8,Ks=t=>{let e=Ys,n=c=>{for(let r of c.values()){for(let a of r.regions)e+=a.length;for(let a of r.lines)e+=a.length}};n(t.layers);for(let c of t.parts)n(c.layers);return e},T0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,c=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=c?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let c=n.fns.get(e);if(c)return c}}mod(e){for(let n=this;n;n=n.parent){let c=n.mods.get(e);if(c)return c}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let c=this;c;c=c.parent)n.push(...c[e].keys());return n}},t6=t=>t?`.${t}`:"",n6=["echo","assert","text_width","text_metrics","finger_count"];function h3(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:Qs(t,r);a<c&&([n,c]=[r,a])}return n?` Did you mean "${n}"?`:""}function Qs(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 c6=y5,U3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.pointCount=0;this.itemCount=0;this.copies=0;this.frame=me;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(T5.map(e=>[e.name,e]));this.loaded=new Map;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...r6,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new T0,c={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[i,o]of Object.entries(c))n.vars.set(i,o);let r=new T0(n),a=this.block(e.body,r,!0),s=r.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${T2(this.unscaled,!1)})`),{shape:a,globals:r,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new c1(`Stopped after ${this.maxSteps} steps. Is there an endless loop?`,e)}load(e,n){let c=Zs(n.file,e),r=e,a=j0(c6,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 c1(`Library <${e}> not found`,n);this.loaded.set(r,{body:[]});let{program:s}=e2(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||j0(c6,c.pos.file)===void 0)&&(c.kind==="module"?j0(this.builtins,c.name)!==void 0:j0(m5,c.name)!==void 0||n6.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${T2(c.pos,!1)})`),c.kind==="module")n.mods.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="function")n.fns.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="use"&&!c.include){this.enter(this.using,c.path,c.pos,"use");try{let r=this.included(this.load(c.path,c.pos).body,new Set([c.path])),a=new T0(n);this.hoist(r,a);for(let s of r)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,i]of a.mods)n.mods.set(s,i);for(let[s,i]of a.fns)n.fns.set(s,i)}finally{this.using.pop()}}}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let r=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,i=[];for(let l=r.length-1;l>=0;l--)i.push({text:";"},r[l][1],{text:`${r[l][0]}=`});for(;i.length;){if(s>2e4)return"";let l=i.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){i.push({text:"]"});for(let u=l.length-1;u>=0;u--)i.push(l[u],{text:","});h="["}else if(Q0(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(F0(l)){i.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)i.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";a.push(h),s+=h.length}let o=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies}`}enter(e,n,c,r){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new c1(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&&!J6(s)&&r.push(s)}return r.length===1?r[0]:q2(r)}stmt(e,n,c=!1){switch(this.tick(e.pos),e.kind){case"assign":{let r=this.opts.overrides,a=c&&r&&Object.prototype.hasOwnProperty.call(r,e.name)?r[e.name]:this.expr(e.value,n);return this.assign(e.name,a,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new T0(n));case"if":return h0(this.expr(e.cond,n))?this.block(e.then,new T0(n)):this.block(e.else,new T0(n));case"let":{let r=new T0(n);return this.bindSeq(e.assigns,r),this.block(e.body,r)}case"for":{let r=[];return this.loop(e.assigns,n,a=>r.push(this.block(e.body,a))),q2(r)}case"call":if(e.modifier==="*")return null;{let r=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?u5(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 s4(e,this.limits.maxListLength)}catch(c){throw new c1(c.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,c,r=0,a=new T0(n)){if(r===e.length)return c(a);let s=e[r];for(let i of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let o=new T0(a);o.vars.set(s.name,i),this.loop(e,n,c,r+1,o)}}evalArgs(e,n,c){let r=[],a=new Map,s=[];for(let i of e){let o=this.expr(i.value,n);i.name===null?r.push(o):a.set(i.name,o),s.push({name:i.name,value:o})}return{pos:r,named:a,all:s,at:c}}bindParams(e,n,c,r,a){let s=e.map(i=>i.name);e.forEach((i,o)=>{let l;n.named.has(i.name)?l=n.named.get(i.name):o<n.pos.length?l=n.pos[o]:l=i.default?this.expr(i.default,c):void 0,c.vars.set(i.name,l)});for(let i of n.named.keys())i.startsWith("$")?c.vars.set(i,n.named.get(i)):s.includes(i)||this.unknownArg(a,i,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let c=O3(e);if(!c)return;let r=c.params.map(a=>a.name);if(!c.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!r.includes(a)&&this.unknownArg(`${e}()`,a,n.at,r);c.rest||this.checkCount(`${e}()`,c.params.filter(a=>!a.named).length,n)}checkCount(e,n,c){c.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${c.pos.length}; the rest are ignored (${T2(c.at,!1)})`)}unknownArg(e,n,c,r){this.warn(`${e}: unknown argument "${n}"${t6(h3(n,r))} (${T2(c,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let c=e.args.findIndex(s=>s.name==="name"),r=c>=0?c:e.args.findIndex(s=>s.name===null);if(r<0)throw new c1("call() needs the name of a module",e.pos);let a=this.expr(e.args[r].value,n);if(typeof a!="string")throw new c1(`call() needs a module's name as a string, got ${W0(a)}`,e.pos);if(a==="call")throw new c1("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 c1(`Recursion too deep in module ${e.name}(): it calls itself without stopping`,e.pos);try{let f=new T0(r.env,n);return this.bindParams(r.params,c,f,r.env,`${e.name}()`),f.children={stmts:e.children,env:n},f.vars.set("$children",this.childStmts(e.children).length),this.block(r.body,f)}catch(f){throw this.inCall(f,"module",e.name,e.pos)}finally{this.depth--}}let a=j0(this.builtins,e.name);if(!a){let f=e.name==="color"?" Use layer(), cut(), score() or engrave() instead.":h3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new c1(`Unknown module ${e.name}().${f}`,e.pos)}this.checkArgs(e.name,c);let s=new T0(n,n);for(let[f,d]of c.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new T0(n,s),l={args:c,env:s,children:()=>e.children.length?this.block(e.children,o()):K0(),childList:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let p of e.children){let m=this.stmt(p,f);i.includes(p)&&d.push(m??K0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let p=[];for(let m of e.children){let g=this.stmt(m,d);i.includes(m)&&(p.push(g??K0()),f(p.length-1,g??K0()))}return p}},h;try{h=a(l)}catch(f){if(f instanceof c1||f instanceof RangeError)throw f;let d=new c1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=Ks(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new c1(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 c1(`Recursion too deep in ${r}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=P2(e)?e.scope:e.env,s=new T0(a,c);return this.bindParams(e.params,n,s,a,`${r}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",r,n.at)}finally{this.depth--}}inCall(e,n,c,r){return e instanceof Error&&!(e instanceof c1)&&e.message.includes("call stack")?new c1(`Recursion too deep in ${n==="module"?"module ":""}${c}(): it calls itself without stopping`,r):(e instanceof c1&&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 c1(`Unknown variable "${e.name}"${t6(h3(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(N3,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 c1("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 P3(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 c1(`Can't compare ${W0(c)} ${e.op} ${W0(r)}`,e.pos);return e.op==="<"?c<r:e.op==="<="?c<=r:e.op===">"?c>r:c>=r}return this.arith(e.op,c,r,e.pos)}case"ternary":return h0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let c=this.expr(e.target,n),r=this.expr(e.index,n);if(F0(c)&&typeof r=="string")return c.fields.get(r);if(typeof r!="number")throw new c1(`List index must be a number, got ${W0(r)}`,e.pos);return Array.isArray(c)?c[Math.floor(r)]:typeof c=="string"?[...c][Math.floor(r)]:Q0(c)?[c.start,c.step,c.end][Math.floor(r)]:void 0}case"record":return this.record(e,n);case"member":{let c=this.expr(e.target,n);if(F0(c))return c.fields.get(e.name);let r={x:0,y:1,z:2}[e.name];return Array.isArray(c)&&r!==void 0?c[r]:Q0(c)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?c.start:e.name==="step"?c.step:c.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let c=new T0(n);return this.bindSeq(e.assigns,c),this.expr(e.body,c)}}}listItem(e,n,c,r){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(c,1,r),c.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),r);this.grow(c,a.length,r);for(let s of a)c.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,c,r));return;case"if":h0(this.expr(e.cond,n))?this.listItem(e.then,n,c,r):e.else&&this.listItem(e.else,n,c,r);return;case"let":{let a=new T0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,c,r)}}}grow(e,n,c){if(e.length+n>this.limits.maxListLength)throw new c1(`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 c1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let r=e.callee.name,a=n.get(r),s=a.found&&!P2(a.value);if(!a.found||s&&this.callable(r,n)){let i=n.fn(r);if(i)return this.callFunction(i,this.evalArgs(e.args,n,e.pos),n,r);let o=this.specialFunction(r,e,n);if(o.handled)return o.value;let l=j0(m5,r);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(r,h);for(let p of w7(l,h.pos,h.named))this.warn(`${r}(): "${p}" is given by position and by name; the named value is used (${T2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:p=>this.tick(e.pos,p),given:h.pos.length+l.params.filter(p=>h.named.has(p)).length},f=z7(l,h.pos,h.named);this.tick(e.pos,k7(r,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(p){if(p instanceof c1)throw p;let m=new c1(p instanceof RangeError?`${r}(): the result is too large`:p.message,e.pos);throw m.call=r,m}return this.checkValue(d,e.pos,r),d}throw new c1(`Unknown function ${r}()${t6(h3(r,[...n.names("fns"),...n.names("vars"),...Object.keys(m5),...n6]))}`,e.pos)}if(!P2(a.value))throw new c1(`"${r}" is a ${W0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,r)}let c=this.expr(e.callee,n);if(!P2(c))throw new c1(`Can't call a ${W0(c)}`,e.pos);return this.callFunction(c,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,c,r){let a=s=>Array.isArray(c)?String(c[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let i=a(s),o=x1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||b0(n[s],o).reduce((h,u)=>h+Math.abs(H1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(c)&&i?` "${i}"`:""} under it, so it can't be seen (${T2(r,!1)})`)}}record(e,n){let c=new Map;for(let r of e.fields)c.set(r.name,this.expr(r.value,n));return{type:"record",fields:c}}length(e,n){let c=A0(n.get("$scale").value??1);if(!(c>0))throw new c1("$scale must be a number more than 0",e.pos);return c===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Js[e.unit]/c}callable(e,n){return!!n.fn(e)||n6.includes(e)||!!j0(m5,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 c1(`Assertion failed${n===void 0?"":": "+g0(n)}`,e.at)}echo(e,n){this.charge(Math.ceil(e.length/h8),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=T3(i,n-r-s.length,o);if(r+=s.length+l.text.length,!l.whole)throw new c1(`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 c1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${c.length}`,r);return this.charge(n.length+N3,r),n.map((s,i)=>this.arith(e,s,c[i],r))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+N3,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 c1("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 c1(`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 c1(`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+N3,r),n.map(s=>this.arith(e,s,c,r));if(typeof n=="number"&&Array.isArray(c)&&e==="*")return this.charge(c.length+N3,r),c.map(s=>this.arith(e,n,s,r));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new c1(`Can't ${a[e]??e} ${W0(n)} and ${W0(c)}`,r)}arg(e,n,c,r){return e.named.has(n)?e.named.get(n):c>=0&&c<e.pos.length?e.pos[c]:r}num(e,n,c){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${c} must be a finite number, got ${q0(e)}`);return e}vec2(e,n,c=!0){let r=a=>typeof a=="number"&&Number.isFinite(a);if(r(e)&&c)return[e,e];if(Array.isArray(e)&&r(e[0])&&(e[1]===void 0||r(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${q0(e)}`)}vec3(e,n){let c=r=>typeof r=="number"&&Number.isFinite(r);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(c))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${q0(e)}`)}placements(e,n,c){let r=(i,o)=>i===void 0?[[0,0,0]]:Array.isArray(i)&&i.length>0&&Array.isArray(i[0])?i.map((l,h)=>this.vec3(l,`${o}[${h}]`)):[this.vec3(i,o)],a=r(e,"at"),s=r(n,"rotate");for(let[i,o]of[[a,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==c)throw new Error(`${o} needs one placement per copy: qty is ${c} but ${o} has ${i.length}`);return Array.from({length:c},(i,o)=>({at:a[a.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((c,r)=>{if(!Array.isArray(c)||!Number.isFinite(c[0])||!Number.isFinite(c[1]))throw new Error(`${n}[${r}] must be an [x, y] point, got ${q0(c)}`);return[c[0],c[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,c){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,c)}checkSize(e,n,c,r){if(e>this.limits.maxListLength)throw new c1(`${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/h8):e+N3,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=t7(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 c1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let c=T3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!c.whole)throw new c1(`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 Qe(this.opts.fonts,c.text,this.textOpts(e,n,c.text))}catch(r){throw r instanceof c1?r:new c1(r.message,e.at)}}textOpts(e,n,c){let r={size:this.num(this.arg(e,"size",1,10),"text","size"),font:g0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:g0(this.arg(e,"halign",-1,"left")),valign:g0(this.arg(e,"valign",-1,"baseline")),spacing:A0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&c!==void 0&&this.opts.fonts){let s=this.num(a,"text","fit");if(!(s>0))throw new Error("fit must be a width more than 0");let i=Qe(this.opts.fonts,c,{...r,size:1}).advance;if(i>0){let o=this.arg(e,"size",1);r.size=o===void 0?s/i:Math.min(r.size,s/i)}}return r}edges(e){let n=c=>{if(c==="out"||c==="in"||c==="flat")return c;throw new Error(`edges must be "out", "in" or "flat", got ${q0(c)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,c=this.layers.get(n);if(c&&c.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!c){let r=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...r,name:n,side:"back"})}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((c,r)=>{if(!Array.isArray(c)||c.length!==3||!c.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${q0(c)}${n.length>1?` at ${r}`:""}`);let[a,s,i]=c;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${q0(c)}`);return{x0:a,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>k3(s.children(),i),n=s=>i=>u5(i.children(),s),c=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${q0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!h0(this.dyn(i.env,"$mirrored"))),u5(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=n7(i,o,l,this.segs(s.env));return k0(x1([h?u.map(([f,d])=>[f-i/2,d-o/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let i=this.arg(s.args,"d",-1),o=i!==void 0?this.num(i,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return k0([S3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return k0([S3(i,o,this.segs(s.env)(Math.max(i,o)))])},regular_polygon:s=>{let i=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),o=this.num(this.arg(s.args,"r",1,10),"regular_polygon","r");if(!(i<=this.limits.maxSegments))throw new Error(`${i} corners is more than the limit of ${this.limits.maxSegments}`);return k0([S3(o,o,i)])},star:s=>{let i=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),o=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.args,"inner",2,o*.45),"star","inner");if(!(i*2<=this.limits.maxSegments))throw new Error(`${i} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<i*2;u++){let f=Math.PI/2+Math.PI*u/i,d=u%2?l:o;h.push([d*Math.cos(f),d*Math.sin(f)])}return k0(x1([h]))},polygon:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"paths",1),l=Array.isArray(o)?o.map(h=>(Array.isArray(h)?h:[]).map(u=>i[A0(u)]).filter(Boolean)):[i];return k0(x1(l,"evenodd"))},path:s=>{let i=this.arg(s.args,"d",0);if(typeof i!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let o=E3(I3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return h0(this.arg(s.args,"close",-1,!1))?k0(x1([...o.closed,...o.open.filter(h=>h.length>2)],l)):q2([k0(x1(o.closed,l)),D2(o.open)])},line:s=>{let i=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),o=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return D2([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!u)return K0();let f=-(o[1]-i[1])/u*(h/2),d=(o[0]-i[0])/u*(h/2);return k0(x1([[[i[0]+f,i[1]+d],[i[0]-f,i[1]-d],[o[0]-f,o[1]-d],[o[0]+f,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=h0(this.arg(s.args,"closed",1,!1));return D2([o&&i.length?[...i,i[0]]:i])},arc:s=>{let i=this.num(this.arg(s.args,"r",0,10),"arc","r"),o=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.env)(i)*Math.abs(l-o)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(o+(l-o)*f/h)*Math.PI/180;u.push([i*Math.cos(d),i*Math.sin(d)])}return D2([u])},text:s=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let i=this.arg(s.args,"text",0,""),o=T3(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=L4(this.opts.fonts,o.text,this.textOpts(s.args,s.env,o.text));if(h0(this.dyn(s.env,"$mirrored"))){let[h,u]=[1/0,-1/0];for(let f of l)for(let[d]of f)[h,u]=[Math.min(h,d),Math.max(u,d)];return k0(x1(l.map(f=>f.map(([d,p])=>[h+u-d,p]))))}return k0(l)},translate:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,i,o])},rotate:s=>{let i=this.arg(s.args,"a",0,0),l=(Array.isArray(i)?A0(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[p,m]=this.vec2(f,"center",!1);d=[h,u,-u,h,p-h*p+u*m,m-u*p-h*m]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,u=o/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let i=this.arg(s.args,"m",0);if(!Array.isArray(i)||i.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let o=i[0],l=i[1];return e(s,[o[0],l[0],o[1],l[1],o[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[i,...o]=s.childList();if(!i)return K0();let l=r(o,"difference");return a(i,h=>({regions:b0(h.regions,l.regions),lines:v2(h.lines,x1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return K0();let o=p=>[...p.layers.values()].some(m=>m.regions.length),l=p=>{let m;for(let g of i){if(g===p||!o(g))continue;let v=x1(r([g],"intersection").regions);m=m?x0(m,v):v}return m},h=i[0],u=i.every(o),f=l(h),d=a(h,p=>({regions:u?f?x0(p.regions,f):p.regions:[],lines:f?v2(p.lines,f,"inside"):p.lines}));for(let p of i){if(p===h)continue;if(p.parts.length)throw new Error("part() can only be the first child of intersection()");let m=l(p),g=new Map;for(let[v,y]of p.layers)y.lines.length&&g.set(v,{regions:[],lines:m?v2(y.lines,m,"inside"):y.lines});g.size&&(d=q2([d,{layers:g,parts:[]}]))}return d},hull:s=>{let i=s.children(),o=l=>{let h=[],u="cut",f=!0;for(let[p,m]of l){f&&(m.regions.length||m.lines.length)&&(u=p,f=!1);for(let g of[...m.regions,...m.lines])for(let v of g)h.push(v)}let d=e7(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:o(i.layers),parts:i.parts.map(l=>({...l,layers:o(l.layers)}))}},offset:s=>{let i=this.arg(s.args,"r",0),o=this.arg(s.args,"delta",-1),l=h0(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),u=i!==void 0?"round":l?"square":"miter";return a(s.children(),f=>({regions:m0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[i,o]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(i>0&&o>0))throw new Error("spacing must be more than 0");let[h,...u]=s.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=x1(r(u,"pattern").regions),d=D0(h.layers),p=S0(f);if(!d||!p)return K0();let m=Math.floor((p[1]-d[3])/o),g=Math.ceil((p[3]-d[1])/o),v=Math.floor((p[0]-d[2])/i)-1,y=Math.ceil((p[2]-d[0])/i)+1,b=(g-m+1)*(y-v+1);if(!(b<=this.limits.maxParts*10))throw new Error(`the pattern would have ${b} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(s.args.at,b);let x=_0(f).map(S=>({polys:S,box:S0(S)})),M=f,w=(S,L)=>{let I=0;for(let q of M)for(let R=0,N=q.length-1;R<q.length;N=R++){let[G,V]=q[N],[J,o1]=q[R];V<=L?o1>L&&(J-G)*(L-V)-(S-G)*(o1-V)>0&&I++:o1<=L&&(J-G)*(L-V)-(S-G)*(o1-V)<0&&I--}return I!==0},k=new Map,z=(S,L)=>{let I=k.get(S)??{regions:[],lines:[]};for(let q of L.regions)I.regions.push(q);for(let q of L.lines)I.lines.push(q);k.set(S,I)};for(let S=m;S<=g;S++)for(let L=v;L<=y;L++){let I=L*i+(S%2?l*i:0),q=S*o,R=[d[0]+I,d[1]+q,d[2]+I,d[3]+q];if(R[2]<p[0]||R[0]>p[2]||R[3]<p[1]||R[1]>p[3])continue;let N=x.filter(Z=>!(R[2]<Z.box[0]||R[0]>Z.box[2]||R[3]<Z.box[1]||R[1]>Z.box[3]));if(!N.length)continue;M=N.length===x.length?f:N.flatMap(Z=>Z.polys);let G=[w(R[0],R[1]),w(R[2],R[1]),w(R[2],R[3]),w(R[0],R[3])],V=M.some(Z=>Z.some(([p1,E])=>p1>R[0]&&p1<R[2]&&E>R[1]&&E<R[3])),J=G.every(Boolean)&&!V,o1=[1,0,0,1,I,q];for(let[Z,p1]of k3({layers:h.layers,parts:[]},o1).layers)z(Z,J?p1:{regions:x0(p1.regions,M),lines:v2(p1.lines,M,"inside")})}return{layers:k,parts:[]}},spline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=h0(this.arg(s.args,"closed",-1,!1));if(!(i.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=be(i,l,h);if(o===void 0)return D2([u]);let f=this.num(o,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return k0(x1(Y5([u],f)))},hatch:s=>{let i=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),o=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(o>0))throw new Error("pitch must be more than 0");let h=x1(r([s.children()],"hatch").regions),u=S0(h);if(!u)return K0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],p=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,m=i*Math.PI/180,[g,v]=[Math.cos(m),Math.sin(m)],[y,b]=[-v,g],x=Math.ceil(p/o);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let M=[],w=Math.round((f*y+d*b)/o);for(let z=w-x;z<=w+x;z++){let S=z*o-(f*y+d*b),[L,I]=[f+y*S,d+b*S];M.push([[L-g*p,I-v*p],[L+g*p,I+v*p]])}if(l===void 0)return D2(v2(M,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return k0(x0(x1(Y5(M,k).map(z=>z)),h))},paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],u=[];for(let f=o.length-1;f>=0;f--){let d=o[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let p=h,m=x1(r([d],"paint").regions);u[f]=m,h=p.length?x1([...p,...m]):m;let g=Array.isArray(i)?i[f]:void 0;g!==""&&(g!==void 0?(this.layers.has(g)||this.layers.set(g,{name:g,mode:"fill",color:"#000000"}),l.push(k0(p.length?b0(m,p):m,g))):l.push(p.length?a(d,v=>({regions:b0(v.regions,p),lines:v2(v.lines,p,"outside")})):d))}return this.invisiblePaint(o,u,i,s.args.at),q2(l.reverse())},measure:s=>{let i=h0(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let u=D0(h.layers)??S0(h.parts.flatMap(g=>[...g.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(g=>g.layers)],d=f.flatMap(g=>g.get("cut")?.regions??[]),p=d.length?d:f.flatMap(g=>[...g].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),m=Q6(x1(p));s.env.vars.set("$area",m.area),s.env.vars.set("$centroid",m.area>0?m.centroid:void 0)});return q2(i?o:o.slice(1))},fill_holes:s=>{let i=this.arg(s.args,"min_area",0),o=i===void 0?1/0:this.num(i,"fill_holes","min_area");return a(s.children(),l=>({regions:x1(l.regions).filter(h=>!(H1(h)<0&&-H1(h)<o)),lines:l.lines}))},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),o=>({regions:m0(m0(o.regions,i,"round"),-i,"round"),lines:o.lines}))},stroke:s=>{let i=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),o=>({regions:x1([...o.regions,...Y5(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...x1(i.regions).map(o=>[...o,o[0]])]})),cut:n("cut"),score:c("score"),engrave:c("engrave"),guide:n("guide"),layer:s=>{let i=this.arg(s.args,"name",0);if(typeof i!="string"||!i)throw new Error("layer() needs a name");let o=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(i),u=this.arg(s.args,"order",-1),f=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${i}" is the back of layer "${i.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let p=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(p))throw new Error('mode must be "cut", "line", "fill" or "guide"');let m=g0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(m))throw new Error('color must look like "#00aa00"');let g=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&p==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:p,color:m,...g!==void 0&&{order:g},...v!==void 0&&{bleed:v}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${q0(d)}`);if(d==="back"&&this.layers.get(i)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&s.env.vars.set("$mirrored",!h0(this.dyn(s.env,"$mirrored"))),u5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=g0(this.arg(s.args,"name",0,"part")),o=Math.max(1,Math.floor(A0(this.arg(s.args,"qty",1,1))||1)),l=this.arg(s.args,"stack",-1),h=l===void 0?1:Math.floor(this.num(l,"part","stack"));if(!(h>=1))throw new Error("stack must be 1 or more");if(this.copies+=o*h,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let u=this.arg(s.args,"at",-1),f=this.arg(s.args,"rotate",-1),d=this.arg(s.args,"glue",-1),p=d===void 0?void 0:g0(d),m=g0(this.arg(s.args,"face",-1,"top"));if(m!=="top"&&m!=="bottom")throw new Error(`face must be "top" or "bottom", got ${q0(m)}`);let g=this.frame!==me&&p===void 0,v=this.arg(s.args,"bend",-1),y=u===void 0&&f===void 0&&!g&&p===void 0&&v===void 0?void 0:this.placements(u,f,o),b=this.arg(s.args,"material",-1);b!==void 0&&s.env.vars.set("$material",g0(b));let x=this.thickness(s.env);y&&(g||h>1)&&(y=y.flatMap(Z=>{let p1=p===void 0?O1(this.frame,G0(Z)):G0(Z),E=p!==void 0&&m==="bottom"?-x:x;return Array.from({length:h},($,X)=>({...Z,matrix:O1(p1,R0(0,0,X*E))}))}));let M=this.arg(s.args,"mirror",-1,!1),w;if(Array.isArray(M)){if(M.length!==o)throw new Error(`mirror needs one true or false per copy: qty is ${o} but mirror has ${M.length}`);w=M.map(Z=>h0(Z))}else w=Array.from({length:o},()=>h0(M));let k=w.some(Z=>Z)&&!w.every(Z=>Z);if(k&&p!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let z=w[0],S=Z=>{let p1=s.env.vars.get("$mirrored"),E=s.env.vars.has("$mirrored");Z&&s.env.vars.set("$mirrored",!0);try{let $=s.children();return Z?k3($,[-1,0,0,1,0,0]):$}finally{Z&&(E?s.env.vars.set("$mirrored",p1):s.env.vars.delete("$mirrored"))}},L=S(z),I=this.bends(v),q=this.arg(s.args,"on",-1),R=this.arg(s.args,"slots",-1),N=R===void 0?void 0:(Array.isArray(R)?R:[R]).map(Z=>{if(typeof Z!="string")throw new Error("slots must be part names");return Z}),G=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),V=(Z,p1,E)=>{let $=E.length===o,X=y?.filter((j,w1)=>E.includes(Math.floor(w1/h)+1));return{name:i,qty:E.length*h,layers:Z,thickness:x,kerf:A0(this.dyn(s.env,"$kerf"))||0,material:g0(this.dyn(s.env,"$material")??"material"),...X?{placements:X}:{},...h>1?{stack:h}:{},...I.length?{bends:I}:{},...q!==void 0?{on:g0(q)}:{},...N?{slots:N,clearance:G}:{},...this.step?{step:this.step}:{},...p!==void 0&&{glue:{host:p,face:m}},...p1&&{mirrored:!0},...!$&&{copies:E}}},J=Z=>w.flatMap((p1,E)=>p1===Z?[E+1]:[]),o1=k?[V(L.layers,z,J(z)),V(S(!z).layers,!z,J(!z))]:[V(L.layers,z,J(z))];return{layers:new Map,parts:[...L.parts,...o1]}},place:s=>{let i=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),o=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=O1(l,G0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=g0(this.arg(s.args,"text",0,"")),o=h0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.children();let l=this.step,h=l&&i?`${this.stepNames[l-1]}: ${i}`:i,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=g0(this.arg(s.args,"kind",0,"dowel"));j0(r3,i)===void 0&&j0(H3,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${T2(s.args.at,!1)})${h3(i,Object.keys(r3))}`);let o=g0(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${q0(o)}`);let l=this.arg(s.args,"sides",-1),h=o==="ball"||l===0,u=this.vec3(this.arg(s.args,"from",1),"from"),f=this.arg(s.args,"to",2),d=h&&f===void 0?u:this.vec3(f,"to"),p=this.arg(s.args,"size",3,6),m=typeof p=="number"?p:this.vec2(p,"size",!1);if(h){if(typeof m!="number"||!(m>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let g=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(g[2])>.9*Math.hypot(...g),y=this.arg(s.args,"up",-1),b=y===void 0?v?[0,1,0]:[0,0,1]:this.vec3(y,"up"),x=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(x>=3&&x<=e6))throw new Error(`sides must be from 3 to ${e6} (or 0 for a ball), got ${q0(x)}`);if(this.pointCount+=h?2*e6:x*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let M=this.arg(s.args,"label",-1),w=this.frame,k=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2]+w[3],w[4]*S[0]+w[5]*S[1]+w[6]*S[2]+w[7],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]+w[11]],z=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2],w[4]*S[0]+w[5]*S[1]+w[6]*S[2],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:i,from:k(u),to:k(d),size:m,up:z(b),sides:x,step:this.step,...M!==void 0?{label:g0(M)}:{}}),s.children()},material:s=>{let i=this.arg(s.args,"thickness",0),o=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return i!==void 0&&s.env.vars.set("$thickness",this.num(i,"material","thickness")),o!==void 0&&s.env.vars.set("$kerf",this.num(o,"material","kerf")),l!==void 0&&s.env.vars.set("$material",g0(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return K0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new T0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(m=>u.add(m));else for(let m of this.iterable(l,s.args.at))o[A0(m)]&&u.add(o[A0(m)]);let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let p=this.childKey(h);for(let m of i.stmts)if(m.kind==="assign")this.stmt(m,h);else if(u.has(m)){let g=p&&d.get(m);if(g&&g.key===p){g.shape&&f.push(g.shape);continue}let v=this.effects(),y=this.stmt(m,h);y&&f.push(y),p&&this.effects()===v&&!y?.parts.length&&d.set(m,{key:p,shape:y})}return q2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/u*4),k0(i4(i,o,l,h,u))},finger_holes:s=>{let i=this.num(this.arg(s.args,"length",0),"finger_holes","length"),o=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(o==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(i)/l*4),k0(S7(i,o,this.thickness(s.env),l))},tslot:s=>{let i=this.num(this.arg(s.args,"d",0,3),"tslot","d"),o=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[i*1.85,i*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return k0(x1(L7(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(A7(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 B3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},a6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function s6(t,e){let n=[];for(let[c,r]of t){let a=[B3(c),B3(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 _3=(t,e)=>`M${s6(t,e).map(([n,c])=>`${n} ${c}`).join("L")}${e?"Z":""}`;function A4(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(_3(l,!1));for(let l of o.regions)(H1(l)<0?a:s).push(_3(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 C4(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="${B3(e)}mm" height="${B3(n)}mm" viewBox="0 0 ${B3(e)} ${B3(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="${a6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>_3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${_3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${_3(f,!1)}"/>`);for(let f of h.regions)(H1(f)<0?s:i).push(`<path${u} d="${_3(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="${a6(a.name)}" inkscape:groupmode="layer" inkscape:label="${a6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return r.push("</svg>",""),r.join(`
|
|
2564
|
-
`)}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 s6=0,J7=-3;function I5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function br(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 K7=new I5,Q7=new I5,i6=new Uint8Array(30),o6=new Uint16Array(30),e8=new Uint8Array(30),t8=new Uint16Array(30),xr=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),f7=new I5,C2=new Uint8Array(320);function n8(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 Mr(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 d7=new Uint16Array(16);function Ue(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)d7[c]=a,a+=t.table[c];for(c=0;c<r;++c)e[n+c]&&(t.trans[d7[e[n+c]]++]=c)}function wr(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function 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 Je(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 kr(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[xr[s]]=l}for(Ue(f7,C2,0,19),i=0;i<r+c;){var h=Je(t,f7);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}}Ue(e,C2,0,r),Ue(n,C2,r,c)}function m7(t,e,n){for(;;){var r=Je(t,e);if(r===256)return s6;if(r<256)t.dest[t.destLen++]=r;else{var c,a,s,i;for(r-=257,c=P2(t,i6[r],o6[r]),a=Je(t,n),s=t.destLen-P2(t,e8[a],t8[a]),i=s;i<s+c;++i)t.dest[t.destLen++]=t.dest[i]}}}function zr(t){for(var e,n,r;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return J7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,s6}function Sr(t,e){var n=new br(t,e),r,c,a;do{switch(r=wr(n),c=P2(n,2,0),c){case 0:a=zr(n);break;case 1:a=m7(n,K7,Q7);break;case 2:kr(n,n.ltree,n.dtree),a=m7(n,n.ltree,n.dtree);break;default:a=J7}if(a!==s6)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}Mr(K7,Q7);n8(i6,o6,4,3);n8(e8,t8,2,1);i6[28]=0;o6[28]=258;var Lr=Sr;function _3(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(_3(o[f],l[f],h[f],u[f],p)),f===1&&this.addY(_3(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(_3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(_3(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(_3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(_3(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 r8(t){throw new Error(t)}function p7(t,e){t||r8(e)}var C1={fail:r8,argument:p7,assert:p7},g7=32768,v7=2147483648,G3={},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>=g7&&(t=-(2*g7-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>=v7&&(t=-(2*v7-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;G3.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)};G3.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 Ke={"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"};G3.MACSTRING=function(t,e,n,r){var c=Ke[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 S4=typeof WeakMap=="function"&&new WeakMap,L4,Ar=function(t){if(!L4){L4={};for(var e in Ke)L4[e]=new String(e)}var n=L4[t];if(n!==void 0){if(S4){var r=S4.get(n);if(r!==void 0)return r}var c=Ke[t];if(c!==void 0){for(var a={},s=0;s<c.length;s++)a[c.charCodeAt(s)]=s+128;return S4&&S4.set(n,a),a}}};K.MACSTRING=function(t,e){var n=Ar(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 Qe(t){return t>=-128&&t<=127}function Cr(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 Pr(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(!Qe(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 Er(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(s===0||Qe(s)&&a+1<c&&Qe(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=Cr(t,e,n):r>=-128&&r<=127?e=Pr(t,e,n):e=Er(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 A4=typeof WeakMap=="function"&&new WeakMap;K.CHARSTRING=function(t){if(A4){var e=A4.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 A4&&A4.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 e6(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 I4(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.")}I4.prototype=Object.create(T0.prototype);I4.prototype.constructor=I4;function V4(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)))}]})))}]}))}V4.prototype=Object.create(T0.prototype);V4.prototype.constructor=V4;function H4(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)))}]}))}H4.prototype=Object.create(T0.prototype);H4.prototype.constructor=H4;function O4(t,e){T0.call(this,"lookupListTable",e6("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(e6("subtable",n.subtables,r)))}))}O4.prototype=Object.create(T0.prototype);O4.prototype.constructor=O4;var s1={Table:T0,Record:T0,Coverage:I4,ScriptList:V4,FeatureList:H4,LookupList:O4,ushortList:V5,tableList:e6,recordList:H5};function y7(t,e){return t.getUint8(e)}function F4(t,e){return t.getUint16(e,!1)}function Tr(t,e){return t.getInt16(e,!1)}function l6(t,e){return t.getUint32(e,!1)}function c8(t,e){var n=t.getInt16(e,!1),r=t.getUint16(e+2,!1);return n+r/65535}function Ir(t,e){for(var n="",r=e;r<e+4;r+=1)n+=String.fromCharCode(t.getInt8(r));return n}function Vr(t,e,n){for(var r=0,c=0;c<n;c+=1)r<<=8,r+=t.getUint8(e+c);return r}function Hr(t,e,n){for(var r=[],c=e;c<n;c+=1)r.push(t.getUint8(c));return r}function Or(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var Fr={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=l6(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};$.prototype.parseOffset32=$.prototype.parseULong;$.prototype.parseFixed=function(){var t=c8(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=l6(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};$.prototype.parseVersion=function(t){var e=F4(this.data,this.offset+this.relativeOffset),n=F4(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+=Fr[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 b7={reserved:$.uShort,reqFeatureIndex:$.uShort,featureIndexes:$.uShortList};$.prototype.parseScriptList=function(){return this.parsePointer($.recordList({tag:$.tag,script:$.pointer({defaultLangSys:$.pointer(b7),langSysRecords:$.recordList({tag:$.tag,langSys:$.pointer(b7)})})}))||[]};$.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:y7,getCard8:y7,getUShort:F4,getCard16:F4,getShort:Tr,getULong:l6,getFixed:c8,getTag:Ir,getOffset:Vr,getBytes:Hr,bytesToString:Or,Parser:$};function Rr(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 $r(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 Dr(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)Rr(n,i);else if(n.format===4)$r(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 qr(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function Nr(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function Ur(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)qr(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}Nr(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 a8={parse:Dr,make:Ur},E4=[".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"],Br=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],_r=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],g3=[".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 s8(t){this.font=t}s8.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 i8(t){this.cmap=t}i8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function R4(t,e){this.encoding=t,this.charset=e}R4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function h6(t){switch(t.version){case 1:this.names=g3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<g3.length?this.names[e]=g3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-g3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=g3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}h6.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};h6.prototype.glyphIndexToName=function(t){return this.names[t]};function jr(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 Gr(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 Wr(t,e){e.lowMemory?Gr(t):jr(t)}function Xr(t,e,n,r,c){t.beginPath(),t.moveTo(e,n),t.lineTo(r,c),t.stroke()}var p3={line:Xr};function Zr(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 h2(t){this.bindConstructorValues(t)}h2.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",Zr(this,t.path))};h2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};h2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};h2.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};h2.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};h2.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};h2.prototype.draw=function(t,e,n,r,c){this.getPath(e,n,r,c).draw(t)};h2.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)};h2.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",p3.line(t,e,-1e4,e,1e4),p3.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",p3.line(t,e+a*c,-1e4,e+a*c,1e4),p3.line(t,e+i*c,-1e4,e+i*c,1e4),p3.line(t,-1e4,n+-s*c,1e4,n+-s*c),p3.line(t,-1e4,n+-o*c,1e4,n+-o*c),t.strokeStyle="green",p3.line(t,e+l*c,-1e4,e+l*c,1e4)};function C4(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 u6(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}u6.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]};u6.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Yr(t,e){return new h2({index:e,font:t})}function Jr(t,e,n,r,c,a){return function(){var s=new h2({index:e,font:t});return s.path=function(){n(s,r,c);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},C4(s,"xMin","_xMin"),C4(s,"xMax","_xMax"),C4(s,"yMin","_yMin"),C4(s,"yMax","_yMax"),s}}function Kr(t,e,n,r){return function(){var c=new h2({index:e,font:t});return c.path=function(){var a=n(t,c,r);return a.unitsPerEm=t.unitsPerEm,a},c}}var T2={GlyphSet:u6,glyphLoader:Yr,ttfGlyphLoader:Jr,cffGlyphLoader:Kr};function o8(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(!o8(t[n],e[n]))return!1;return!0}else return!1}function t6(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 Qr(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 ec(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 tc(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 nc(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 tc(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 rc(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 l8(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(nc(r,s))}return rc(c)}function T5(t,e){return e<=390?e=E4[e]:e=t[e-391],e}function h8(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 cc(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 u8=[{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"}],f8=[{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 ac(t,e){var n=l8(t,0,t.byteLength);return h8(n,u8,e)}function d8(t,e,n,r){var c=l8(t,e,n);return h8(c,f8,r)}function x7(t,e,n,r){for(var c=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=ac(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=d8(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=t6(i._subrs)}i._privateDict=h}c.push(i)}return c}function sc(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 ic(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 R4(c,n)}function M7(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 oc(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 lc(t,e,n,r){n.tables.cff={};var c=cc(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=t6(n.gsubrs);var l=x7(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=x7(t,e,d.objects,i.objects);h._fdArray=m,f+=e,h._fdSelect=oc(t,f,n.numGlyphs,m.length)}var g=e+h.private[1],p=d8(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=t6(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;r.lowMemory?(b=Qr(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=K2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=sc(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new R4(Br,x):h.encoding===1?n.cffEncoding=new R4(_r,x):n.cffEncoding=ic(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=ec(k,b.offsets,t,e+h.charStrings);n.glyphs.push(k,T2.cffGlyphLoader(n,k,M7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var w=b.objects[M];n.glyphs.push(M,T2.cffGlyphLoader(n,M,M7,w))}}function m8(t,e){var n,r=E4.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+E4.length:(n=E4.length+e.length,e.push(t)),n}function hc(){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 uc(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 p8(t,e,n){for(var r={},c=0;c<t.length;c+=1){var a=t[c],s=e[a.name];s!==void 0&&!o8(s,a.value)&&(a.type==="SID"&&(s=m8(s,n)),r[a.op]={name:a.name,type:a.type,value:s})}return r}function w7(t,e){var n=new s1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=p8(u8,t,e),n}function k7(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 fc(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 dc(){return new s1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function mc(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=m8(c,e);n.fields.push({name:"glyph_"+r,type:"SID",value:a})}return n}function pc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var 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 gc(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=pc(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:c})}return e}function vc(t,e){var n=new s1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=p8(f8,t,e),n}function yc(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=hc(),n.nameIndex=uc([e.postScriptName]);var h=w7(c,l);n.topDictIndex=k7(h),n.globalSubrIndex=dc(),n.charsets=mc(s,l),n.charStringsIndex=gc(t),n.privateDict=vc(a,l),n.stringIndex=fc(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=w7(c,l),n.topDictIndex=k7(h),n}var g8={parse:lc,make:yc};function bc(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 xc(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 v8={parse:bc,make:xc};function Mc(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 wc(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 y8={parse:Mc,make:wc};function kc(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 zc(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 Sc(t,e,n,r,c,a,s){s.lowMemory?zc(t,e,n,r,c):kc(e,n,r,c,a)}function Lc(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 b8={parse:Sc,make:Lc};function Ac(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 Cc(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 x8={make:Ac,parse:Cc};function Pc(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 Ec(t){return new s1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var M8={parse:Pc,make:Ec},w8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],k8={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},Tc={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},z8={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 Ic(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return k8[e];case 3:return z8[e]}}var n6="utf-16",Vc={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"},Hc={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 S8(t,e,n){switch(t){case 0:return n6;case 1:return Hc[n]||Vc[e];case 3:if(e===1||e===10)return n6;break}}function Oc(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=w8[f]||f,m=c.parseUShort(),g=c.parseUShort(),p=Ic(l,u,n),v=S8(l,h,u);if(v!==void 0&&p!==void 0){var y=void 0;if(v===n6?y=G3.UTF16(t,i+g,m):y=G3.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 Be(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function z7(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 Fc(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 S7(t,e){var n=Fc(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 Rc(t,e){var n,r=[],c={},a=Be(w8);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=Be(k8),l=Be(z8),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=Tc[v],b=S8(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=S7(x,u);h.push(z7(p,y,v,n,x.length,M));var w=l[m];if(w!==void 0){var k=K.UTF16(g),z=S7(k,u);h.push(z7(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 L8={parse:Oc,make:Rc},r6=[{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 $c(t){for(var e=0;e<r6.length;e+=1){var n=r6[e];if(t>=n.begin&&t<n.end)return e}return-1}function Dc(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 qc(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 c6={parse:Dc,make:qc,unicodeRanges:r6,getUnicodeRange:$c};function Nc(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=g3.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]>=g3.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 Uc(){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 A8={parse:Nc,make:Uc},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 j3={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,j3)}})};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,j3)}})};if(n===3){var r=this.parseUShort(),c=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,$.pointer($.coverage)),lookupRecords:this.parseRecordList(c,j3)}}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(j3)}})};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(j3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList($.pointer($.coverage)),inputCoverage:this.parseList($.pointer($.coverage)),lookaheadCoverage:this.parseList($.pointer($.coverage)),lookupRecords:this.parseRecordList(j3)};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 Bc(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 W3=new Array(9);W3[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)))};W3[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))})))};W3[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))})))};W3[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)))}))})))};W3[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 _c(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,W3)}])}var C8={parse:Bc,make:_c};function jc(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=G3.UTF8(t,e+o,l);a[i]=h}return a}function Gc(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 P8={parse:jc,make:Gc};function L7(t){return Math.log(t)/Math.log(2)|0}function f6(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 A7(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 E8(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,L7(e.numTables));e.searchRange=16*n,e.entrySelector=L7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],c=[],a=e.sizeOf()+A7().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=A7(i.tableName,f6(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 C7(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 Wc(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function Xc(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=c6.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:Wc(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=v8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=y8.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=M8.make(t.glyphs.length),k=c6.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:C7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:C7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=b8.make(t.glyphs),S=a8.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=L8.make(R,T),X=T.length>0?x8.make(T):void 0,Z=A8.make(),h1=g8.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?P8.make(t.metas):void 0,U=[x,M,w,k,B,S,Z,h1,z];X&&U.push(X),t.tables.gsub&&U.push(C8.make(t.tables.gsub)),H&&U.push(H);for(var Y=E8(U),Q=Y.encode(),W=f6(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 Zc={make:E8,fontToTable:Xc,computeCheckSum:f6};function _e(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 P7(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 E7(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:_e,binSearch:P7,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=_e(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=_e(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=E7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=P7(t.glyphs,e);return n>=0?n:-1;case 2:var r=E7(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 Yc(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 d6(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=d6(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=d6(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=d6(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(Yc(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 Jc(){return typeof window<"u"}function Kc(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 T7(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 T8(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=T7(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=T7(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 je(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 Qc(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 I8(t){var e=new P0;if(!t)return e;for(var n=Qc(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 V8(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=je(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=je([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=je(c.points,o)}e.points=e.points.concat(a)}}return I8(e.points)}function ea(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,T8,t,e+s,V8)):c.push(a,T2.glyphLoader(r,a))}return c}function ta(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,T8,t,e+s,V8)):c.push(a,T2.glyphLoader(r,a))},c}function na(t,e,n,r,c){return c.lowMemory?ta(t,e,n,r):ea(t,e,n,r)}var H8={getPath:I8,parse:na},O8,y3,F8,a6;function R8(t){this.font=t,this.getCommands=function(e){return H8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function ra(t){return t}function $8(t){return Math.sign(t)*Math.round(Math.abs(t))}function ca(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function aa(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function sa(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function ia(t){return Math.sign(t)*Math.floor(Math.abs(t))}var D8=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)),oa={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=$8}}R8.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=oa,c=this._fpgmState=new Q2("fpgm",n.tables.fpgm),c.funcs=[],c.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),c.step=-1);try{y3(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{y3(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return F8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};F8=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),a6(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),a6(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),y3(i),s.length-=2)}return s};a6=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)),y3(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)}}};y3=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=O8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function $4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new N2(0,0)}function q8(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 I7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function V7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function H7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function O7(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 F7(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 la(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 ha(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 ua(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 fa(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 da(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function ma(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 pa(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function ga(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function va(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function ya(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||$4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function ba(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||$4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function xa(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||$4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function Ma(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||$4(t),t.z0=t.z1=t.z2=t.tZone;break;case 1:t.z0=t.z1=t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function wa(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function ka(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=$8}function za(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=aa}function Sa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function La(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),q8(t,!1)}function Aa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Ca(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Pa(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function Ge(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function Ea(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Ta(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 Ia(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Va(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++)y3(t),exports.DEBUG&&console.log(++t.step,s+1<r?"next loopcall":"done loopcall",s);t.ip=c,t.prog=a}function Ha(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],y3(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function Oa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Fa(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 Ra(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 R7(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 $7(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 D7(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 q7(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 N7(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 $a(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 Da(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 U7(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 qa(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 Na(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=ca}function B7(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 Ua(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 Ba(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 _a(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 ja(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 Ga(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 Wa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function _7(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 j7(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 Xa(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Za(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Ya(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 Ja(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 Ka(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 Qa(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 es(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 ts(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 ns(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 rs(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 cs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(q8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function as(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function ss(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,r),e.push(n&&r?1:0)}function is(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,r),e.push(n||r?1:0)}function os(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function We(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 ls(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function hs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function us(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 fs(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 ds(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 ms(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 ps(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function gs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function vs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function ys(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function P4(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function bs(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 Xe(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 xs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=D8;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 Ms(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=D8;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function ws(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=ra}function ks(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=sa}function zs(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=ia}function Ss(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function G7(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 Ls(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 As(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 Cs(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 Ps(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 Es(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ts(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)}O8=[I7.bind(void 0,q2),I7.bind(void 0,E2),V7.bind(void 0,q2),V7.bind(void 0,E2),H7.bind(void 0,q2),H7.bind(void 0,E2),O7.bind(void 0,0),O7.bind(void 0,1),F7.bind(void 0,0),F7.bind(void 0,1),la,ha,ua,fa,da,ma,pa,ga,va,ya,ba,xa,Ma,wa,ka,za,Sa,La,Aa,Ca,void 0,void 0,Pa,Ge,Ea,Ta,Ia,Oa,Fa,void 0,void 0,void 0,Va,Ha,Ra,void 0,R7.bind(void 0,0),R7.bind(void 0,1),$7.bind(void 0,q2),$7.bind(void 0,E2),D7.bind(void 0,0),D7.bind(void 0,1),q7.bind(void 0,0),q7.bind(void 0,1),N7.bind(void 0,0),N7.bind(void 0,1),$a,Da,U7.bind(void 0,0),U7.bind(void 0,1),qa,Na,B7.bind(void 0,0),B7.bind(void 0,1),Ua,Ba,_a,ja,Ga,Wa,_7.bind(void 0,0),_7.bind(void 0,1),void 0,j7.bind(void 0,0),j7.bind(void 0,1),Xa,void 0,Za,void 0,void 0,Ya,Ja,Ka,Qa,es,ts,ns,rs,cs,as,ss,is,os,We.bind(void 0,1),ls,hs,us,fs,ds,ms,ps,gs,vs,ys,P4.bind(void 0,0),P4.bind(void 0,1),P4.bind(void 0,2),P4.bind(void 0,3),void 0,void 0,void 0,void 0,bs,We.bind(void 0,2),We.bind(void 0,3),Xe.bind(void 0,1),Xe.bind(void 0,2),Xe.bind(void 0,3),xs,Ms,void 0,void 0,ws,void 0,ks,zs,Ge,Ge,void 0,void 0,void 0,void 0,void 0,Ss,G7.bind(void 0,0),G7.bind(void 0,1),Ls,void 0,As,Cs,Ps,Es,Ts,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 X3(t){this.char=t,this.state={},this.activeState=null}function m6(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function Is(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 D4(t){this.eventId=t,this.subscribers=[]}function Vs(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 D4(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=[],Vs.call(this,t)}X3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};X3.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 X3});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 X3){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 X3});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)};D4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};D4.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 m6)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 D4&&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 Is(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 m6(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 m6(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 X3(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 N8(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 T4(t){return/[A-z]/.test(t)}function Hs(t){return/\s/.test(t)}function n2(t){this.font=t,this.features={}}function v3(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 Os(t,e){var n=q5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Fs(t,e){var n=q5(t,e.coverage);return n===-1?null:e.substitute[n]}function Ze(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 Rs(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=Ze(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=Ze(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=Ze(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 $s(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 Ds(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 Os.apply(n,[c,e])};case"12":return function(c){return Fs.apply(n,[c,e])};case"63":return function(c){return Rs.apply(n,[c,e])};case"41":return function(c){return $s.apply(n,[c,e])};case"21":return function(c){return Ds.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 v3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new v3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new v3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new v3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new v3({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 qs(t){var e=t.current,n=t.get(-1);return n===null&&e3(e)||!e3(n)&&e3(e)}function Ns(t){var e=t.get(1);return e===null||!e3(e)}var Us={startCheck:qs,endCheck:Ns};function Bs(t){var e=t.current,n=t.get(-1);return(e3(e)||t3(e))&&!e3(n)}function _s(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!e3(e)&&!t3(e)):var n=Hs(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 js={startCheck:Bs,endCheck:_s};function Gs(t,e,n){e[n].setState(t.tag,t.substitution)}function Ws(t,e,n){e[n].setState(t.tag,t.substitution)}function Xs(t,e,n){t.substitution.forEach(function(r,c){var a=e[n+c];a.setState(t.tag,r)})}function Zs(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 W7={11:Gs,12:Ws,63:Xs,41:Zs};function p6(t,e,n){t instanceof v3&&W7[t.id]&&W7[t.id](t,e,n)}function Ys(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],c=N8(r),a=t3(r);if(!c&&!a)return!0;if(c)return!1}return!1}function Js(t){if(N8(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 Ks(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;Ys(s)&&(l|=1),Js(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 v3&&(p6(f,c,d),a.context[d]=f.substitution)})}}})}}function X7(t,e){var n=t.map(function(r){return r.activeState.value});return new g2(n,e||0)}function Qs(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),c=X7(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 p6(o,r,s)}),c=X7(r))})}function ei(t){var e=t.current,n=t.get(-1);return n===null&&T4(e)||!T4(n)&&T4(e)}function ti(t){var e=t.get(1);return e===null||!T4(e)}var ni={startCheck:ei,endCheck:ti};function Z7(t,e){var n=t.map(function(r){return r.activeState.value});return new g2(n,e||0)}function ri(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),c=Z7(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 p6(o,r,s)}),c=Z7(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:ni,arabicWordCheck:Us,arabicSentenceCheck:js};function Ye(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function ci(){return Ye.call(this,"latinWord"),Ye.call(this,"arabicWord"),Ye.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function ai(){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 g6(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function si(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){g6.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){Ks.call(t,r)})}}function ii(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){g6.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(c){Qs.call(t,c)})}}}function oi(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){g6.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(c){ri.call(t,c)})}}}b2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};b2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(si.call(this),ii.call(this)),this.checkContextReady("latinWord")&&oi.call(this),this.checkContextReady("arabicSentence")&&ai.call(this)};b2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),ci.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 s8(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 R8(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 Zc.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(Jc())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=u7(),l=Kc(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 U8(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 li(t,e,n){var r=U8(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 hi(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 ui(t,e,n,r){for(var c=U8(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 fi(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 di(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(li(r,t.axes[r],e));for(var c=0;c<t.instances.length;c++)n.fields=n.fields.concat(ui(c,t.instances[c],t.axes,e));return n}function mi(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(hi(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,m=0;m<o;m++)f.push(fi(t,d+m*l,h,n));return{axes:h,instances:f}}var pi={make:di,parse:mi},gi=function(){return{coverage:this.parsePointer($.coverage),attachPoints:this.parseList($.pointer($.uShortList))}},vi=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()}},yi=function(){return this.parseList($.pointer(vi))},bi=function(){return{coverage:this.parsePointer($.coverage),ligGlyphs:this.parseList($.pointer(yi))}},xi=function(){return this.parseUShort(),this.parseList($.pointer($.coverage))};function Mi(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(gi),ligCaretList:n.parsePointer(bi),markAttachClassDef:n.parsePointer($.classDef)};return r>=1.2&&(c.markGlyphSets=n.parsePointer(xi)),c}var wi={parse:Mi},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 ki(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 zi=new Array(10);function Si(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,zi)}])}var Li={parse:ki,make:Si};function Ai(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 Ci(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 Pi(t,e){var n=new p1.Parser(t,e),r=n.parseUShort();if(r===0)return Ai(n);if(r===1)return Ci(n);throw new Error("Unsupported kern table version ("+r+").")}var Ei={parse:Pi};function Ti(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 Ii={parse:Ti};function Y7(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 Vi(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(Lr(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 B8(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=Y7(a,s);else if(o==="OTTO")c.outlinesFormat="cff",s=p1.getUShort(a,4),i=Y7(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=Vi(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=a8.parse(z.data,z.offset),c.encoding=new i8(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=v8.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=y8.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=x8.parse(z.data,z.offset);break;case"maxp":z=M0(a,k),c.tables.maxp=M8.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=c6.parse(z.data,z.offset);break;case"post":z=M0(a,k),c.tables.post=A8.parse(z.data,z.offset),c.glyphNames=new h6(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=L8.parse(S.data,S.offset,r),c.names=c.tables.name,f&&y){var A=n===0,L=M0(a,y),C=Ii.parse(L.data,L.offset,c.numGlyphs,A),P=M0(a,f);c.glyphs=H8.parse(P.data,P.offset,C,c,e)}else if(h){var R=M0(a,h);g8.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(b8.parse(c,q.data,q.offset,c.numberOfHMetrics,c.numGlyphs,c.glyphs,e),Wr(c,e),v){var T=M0(a,v);c.kerningPairs=Ei.parse(T.data,T.offset)}else c.kerningPairs={};if(d){var B=M0(a,d);c.tables.gdef=wi.parse(B.data,B.offset)}if(m){var X=M0(a,m);c.tables.gpos=Li.parse(X.data,X.offset),c.position.init()}if(g){var Z=M0(a,g);c.tables.gsub=C8.parse(Z.data,Z.offset)}if(u){var h1=M0(a,u);c.tables.fvar=pi.parse(h1.data,h1.offset,c.names)}if(x){var H=M0(a,x);c.tables.meta=P8.parse(H.data,H.offset),c.metas=c.tables.meta}return c}var q4=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=B8(a);return this.parsed.set(n,s),s}};function Hi(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 _8(t,e,n){let{cmds:r,advance:c}=Hi(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=D3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:c}}function N4(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:c,advance:a}=_8(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 v6(t,e,n){let r=t.get(n.font),{polys:c,advance:a}=_8(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 j8=Math.PI/180,y6=128,N5=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],w6={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Oi(t,e){if(!t||e2(M6,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 Fi=100,Ri={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},Z3=4,G8=8,$i=t=>{let e=Fi,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}},b6=t=>t?`.${t}`:"",x6=["echo","assert","text_width","text_metrics","finger_count"];function b3(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:Di(t,c);a<r&&([n,r]=[c,a])}return n?` Did you mean "${n}"?`:""}function Di(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 M6=P5,Y3=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=Te;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(N5.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={...w6,...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 (${m2(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 o1(`Stopped after ${this.maxSteps} steps. Is there an endless loop?`,e)}load(e,n){let r=Oi(n.file,e),c=e,a=e2(M6,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 o1(`Library <${e}> not found`,n);this.loaded.set(c,{body:[]});let{program:s}=l2(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(M6,r.pos.file)===void 0)&&(r.kind==="module"?e2(this.builtins,r.name)!==void 0:e2(L5,r.name)!==void 0||x6.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${m2(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 o1(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&&!yt(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==="%"?b5(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 x4(e,this.limits.maxListLength)}catch(r){throw new o1(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=B3(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 (${m2(r.at,!1)})`)}unknownArg(e,n,r,c){this.warn(`${e}: unknown argument "${n}"${b6(b3(n,c))} (${m2(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 o1("call() needs the name of a module",e.pos);let a=this.expr(e.args[c].value,n);if(typeof a!="string")throw new o1(`call() needs a module's name as a string, got ${R0(a)}`,e.pos);if(a==="call")throw new o1("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 o1(`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.":b3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new o1(`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 o1||f instanceof RangeError)throw f;let d=new o1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=$i(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new o1(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 o1(`Recursion too deep in ${c}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=d2(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 o1)&&e.message.includes("call stack")?new o1(`Recursion too deep in ${n==="module"?"module ":""}${r}(): it calls itself without stopping`,c):(e instanceof o1&&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 o1(`Unknown variable "${e.name}"${b6(b3(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(Z3,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 o1("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 R3(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 o1(`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 o1(`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 o1(`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 o1(`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&&!d2(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(L5,c);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(c,h);for(let m of n7(l,h.pos,h.named))this.warn(`${c}(): "${m}" is given by position and by name; the named value is used (${m2(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(!d2(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=r7(l,h.pos,h.named);this.tick(e.pos,c7(c,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof o1)throw m;let g=new o1(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 o1(`Unknown function ${c}()${b6(b3(c,[...n.names("fns"),...n.names("vars"),...Object.keys(L5),...x6]))}`,e.pos)}if(!d2(a.value))throw new o1(`"${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(!d2(r))throw new o1(`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 (${m2(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 o1("$scale must be a number more than 0",e.pos);return r===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Ri[e.unit]/r}callable(e,n){return!!n.fn(e)||x6.includes(e)||!!e2(L5,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 o1(`Assertion failed${n===void 0?"":": "+v0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/G8);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=$3(i,n-c-s.length,o);if(c+=s.length+l.text.length,!l.whole)throw new o1(`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 o1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${r.length}`,c);return this.charge(n.length+Z3,c),n.map((s,i)=>this.arith(e,s,r[i],c))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+Z3,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 o1("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 o1(`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 o1(`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+Z3,c),n.map(s=>this.arith(e,s,r,c));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+Z3,c),r.map(s=>this.arith(e,n,s,c));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new o1(`Can't ${a[e]??e} ${R0(n)} and ${R0(r)}`,c)}fieldFn(e,n,r,c){if(!d2(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 o1(`${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/G8):e+Z3,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=Mt(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 o1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let r=$3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!r.whole)throw new o1(`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 v6(this.opts.fonts,r.text,this.textOpts(e,n,r.text))}catch(c){throw c instanceof o1?c:new o1(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=v6(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=>b5(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"))),b5(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=wt(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([V3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return A0([V3(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([V3(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=D3(q3(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=$3(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=N4(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=Ae(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=o4(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=Re(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(i4([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(i4(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*j8),Math.sin(y*j8)],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=kt({spacing:o,step:l,minLength:h,seed:u,box:d,inside:Lt(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=zt(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 (${m2(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=xt(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:Ae(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,...i4(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"))),b5(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!==Te&&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,Z0(g1)):Z0(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(z5,v0(Y)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${C0(Y)}`);let Q=typeof Y=="number"?Y:z5[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,Z0({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(d3,i)===void 0&&e2(U3,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${m2(s.args.at,!1)})${b3(i,Object.keys(d3))}`);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<=y6))throw new Error(`sides must be from 3 to ${y6} (or 0 for a ball), got ${C0(x)}`);if(this.pointCount+=h?2*y6: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"} (${m2(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(w4(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(s7(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(i7(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(o7(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 J3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},k6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function z6(t,e){let n=[];for(let[r,c]of t){let a=[J3(r),J3(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 K3=(t,e)=>`M${z6(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function U4(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(K3(l,!1));for(let l of o.regions)(M1(l)<0?a:s).push(K3(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 B4(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="${J3(e)}mm" height="${J3(n)}mm" viewBox="0 0 ${J3(e)} ${J3(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="${k6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>K3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${K3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${K3(f,!1)}"/>`);for(let f of h.regions)(M1(f)<0?s:i).push(`<path${u} d="${K3(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="${k6(a.name)}" inkscape:groupmode="layer" inkscape:label="${k6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return c.push("</svg>",""),c.join(`
|
|
2643
|
+
`)}var qi={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},Ni=t=>{let e=qi[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 Ui(t){let e=i=>i.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(N5.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 S6(t,e,n,r){let c=[],a=(o,l)=>c.push(String(o),String(l)),s=Ui(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,Ni(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 z6(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(`
|
|
2565
2644
|
`)+`
|
|
2566
|
-
`}var u8=(t,e)=>{let n=0;for(let c=1;c<t.length;c++)n+=Math.hypot(t[c][0]-t[c-1][0],t[c][1]-t[c-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},w0=t=>Math.round(t*100)/100;function d8(t,e={}){for(let[C,_]of Object.entries(e.params??{}))try{ge(C,_)}catch(U){throw new c1(U.message)}let{program:n}=e2(t),c=new Set(n.body.flatMap(C=>C.kind==="assign"?[C.name]:[])),r=Object.keys(e.params??{}).filter(C=>!C.startsWith("$")&&!c.has(C)),a=e.fonts?new S4(e.fonts,e.defaultFont):void 0,s=new U3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(n)}catch(C){let _=C instanceof RangeError?new c1(/call stack/i.test(C.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):C;throw _ instanceof c1&&(_.echoes=s.echoes,_.warnings=[...s.warnings],a?.missing.size&&(_.missingFonts=[...a.missing])),_}let l=C=>o.globals.get(C).value,h=o.warnings;for(let C of r)h.push(`Setting "${C}" is not a variable of the program, so it is ignored.${h3(C,c)}`);let u=o.layers,f=C=>u.get(C)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(C=>C.regions.length||C.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:A0(l("$thickness"))||3,kerf:A0(l("$kerf"))||0,material:g0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let m=C=>JSON.stringify([C.thickness,C.material,[...C.layers].map(([_,U])=>[_,U.regions.map(i1=>i1.map(([Q,L1])=>[Math.round(Q*100),Math.round(L1*100)])),U.lines.map(i1=>i1.map(([Q,L1])=>[Math.round(Q*100),Math.round(L1*100)]))])]),g=new Map,v=new Set;for(let C of d){let _=m(C),U=C.mirrored?`${C.name}\0mirrored`:C.name,i1=g.get(U);i1===void 0?g.set(U,_):i1!==_&&v.add(C.name)}for(let C of v)h.push(`Two different parts are named "${C}"; slots, glue and on = find parts by name, so give each its own.`);li(d,h),ri(d,f,h);let y=[],b=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],M=new Map,w=[],k=new Set,z=[],S=l("$min_width"),L=S===void 0?1.5:A0(S),I=l("$label_parts")===!0,q=0;I&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");I&&a&&R&&R.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let N=I&&!!a&&(!R||R.side==="back");if(N){let C=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:C?.color??"#000000",side:"back"})}let G=[];for(let C of d){let _=x1([...C.layers].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.regions)),U;if(C.bends&&_.length){let l1=1/0,z1=-1/0;for(let g1 of _)for(let[d1]of g1)l1=Math.min(l1,d1),z1=Math.max(z1,d1);for(let g1 of C.bends)(g1.x0<l1-.001||g1.x1>z1+.001)&&h.push(`Part "${C.name}" bends from x = ${C2(g1.x0)} to ${C2(g1.x1)}, beyond the part (x = ${C2(l1)} to ${C2(z1)}); only the part itself bends.`)}if(N&&_.length){U=++q;let l1=hi(_,String(U),a,g0(l("$font")??""));if(l1.length){let z1=C.layers.get("engrave-back")??{regions:[],lines:[]};C.layers=new Map(C.layers).set("engrave-back",{regions:[...z1.regions,...l1],lines:z1.lines})}else h.push(`Part "${C.name}" is too small to take its number ${U}.`)}if(L>0&&_.length){let l1=m0(m0(_,-L/2,"round"),L/2,"round"),z1=_0(b0(_,l1)).filter(g1=>g1.reduce((d1,v1)=>d1+H1(v1),0)>2*L*L);if(z1.length){let g1=z1.slice(0,3).map(d1=>{let[v1,U1,l0,z0]=D0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${w0((v1+l0)/2)}, ${w0((U1+z0)/2)}]`});h.push(`Part "${C.name}" is narrower than ${L} mm ($min_width) in ${z1.length} place${z1.length>1?"s":""}, at ${g1.join(", ")}${z1.length>3?" and more":""} in the part's coordinates.`)}}let i1=new Map;for(let[l1,z1]of C.layers){if(f(l1)==="guide"&&!e.guides)continue;let g1=x1(z1.regions),d1=z1.lines.filter(v1=>v1.length>=2);if((f(l1)==="line"||f(l1)==="guide")&&(d1=[...d1,...g1.map(v1=>[...v1,v1[0]])],g1=[]),_.length&&f(l1)!=="guide"){let v1=u.get(l1)?.bleed??0,U1=v1>0?m0(_,v1,"round"):_;f(l1)!=="cut"&&(g1=x0(g1,U1)),d1=v2(d1,U1,"inside")}(g1.length||d1.length)&&i1.set(l1,{regions:g1,lines:d1})}if(G.push(...ii(C.name,i1,u)),_.length){let l1=[];for(let[g1,d1]of i1){let v1=u.get(g1);if(v1?.mode==="cut"&&d1.lines.length)for(let U1 of["front","back"])l1.push({layer:g1,mode:"line",color:"#000000",side:U1,regions:[],lines:d1.lines});!v1||v1.mode!=="fill"&&v1.mode!=="line"||l1.push({layer:g1,mode:v1.mode,color:v1.color,side:v1.side??"front",regions:d1.regions,lines:d1.lines})}let z1={name:C.name,thickness:C.thickness,material:C.material,outline:_,...l1.length&&{marks:l1}};if(C.placements){let g1=new Set;C.placements.forEach((d1,v1)=>{let U1={...z1,copy:f8(C,v1),matrix:G0(d1),placed:!0,...C.bends&&{bends:C.bends},...C.step&&{step:C.step},...C.stack&&{stack:C.stack}};x.push(U1),C.on!==void 0&&M.set(U1,C.on);let l0=U1.matrix.map(z0=>z0.toFixed(6)).join(",");g1.has(l0)&&k.add(U1),g1.add(l0)}),g1.size<C.placements.length&&h.push(`Copies of part "${C.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let g1=0;g1<C.qty;g1++)w.push({...z1,copy:f8(C,g1),matrix:G0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...C.step&&{step:C.step}})}let Q=_0(_),L1=Q.length;if(L1>1){let l1=d1=>d1.reduce((v1,U1)=>v1+H1(U1),0),g1=[...Q].sort((d1,v1)=>l1(v1)-l1(d1)).slice(1,4).map(d1=>{let[v1,U1,l0,z0]=D0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${w0(v1)}, ${w0(U1)}] to [${w0(l0)}, ${w0(z0)}]`}).join(", ");h.push(`Part "${C.name}" cuts into ${L1} separate pieces. Join them, or make them separate parts. The smaller ${L1===2?"one is":"ones are"} at ${g1}${L1>4?" and more":""}, in the part's coordinates.`)}let Y1=0;for(let[l1,z1]of i1)if(f(l1)==="cut"){for(let g1 of z1.regions)Y1+=u8(g1,!0);for(let g1 of z1.lines)Y1+=u8(g1,!1)}let G1=D0(i1)??[0,0,0,0],A1=e.kerf??C.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new c1("$kerf must be a number, 0 or more");let _1={name:C.name,qty:C.qty,width:w0(G1[2]-G1[0]),height:w0(G1[3]-G1[1]),pieces:L1,cutLength:Math.round(Y1),thickness:C.thickness,kerf:A1,material:C.material,...C.stack&&{stack:C.stack},...C.glue&&{glued:C.glue.host},...C.mirrored&&{mirrored:!0},...U!==void 0&&{label:U}};if(b&&b.parts.push({name:C.name,kerf:A1,qty:C.qty,...C.stack&&{stack:C.stack},...C.glue&&{glue:C.glue},...C.on&&{on:C.on},cutRegions:_.map(l1=>l1.map(([z1,g1])=>[z1,g1])),cutLines:[...i1].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.lines.map(z1=>z1.map(([g1,d1])=>[g1,d1])))}),A1>0){for(let[l1,z1]of i1)if(f(l1)==="cut"){let g1=z1.regions.filter(U1=>H1(U1)<0);z1.regions=m0(z1.regions,A1/2,"round",Math.min(.01,A1/20));let d1=z1.regions.filter(U1=>H1(U1)<0),v1=g1.length-d1.length;if(v1>0){let U1=z0=>{let[$2,e3,Ln,An]=D0(new Map([["cut",{regions:[z0],lines:[]}]]));return[($2+Ln)/2,(e3+An)/2]},l0=g1.map(U1).filter(([z0,$2])=>!d1.some(e3=>p8(e3,z0,$2))).slice(0,3).map(([z0,$2])=>`[${w0(z0)}, ${w0($2)}]`);h.push(`Part "${C.name}": ${v1} hole${v1===1?" is":"s are"} narrower than the ${A1} mm kerf and will not be cut${l0.length?`, at ${l0.join(", ")}${v1>l0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(_1),z.push({info:_1,layers:i1})}ai(x,M,h);let V=new Map,J=x.filter(C=>!k.has(C)).flatMap(C=>{let _=c4(C);for(let U of _)V.set(U,C);return _}),{found:o1,complete:Z}=l7(J,i.maxCollisionPairs),p1=o1.filter(([C,_])=>V.get(C)!==V.get(_)).map(([C,_])=>[V.get(C)??C,V.get(_)??_]).filter(([C,_],U,i1)=>i1.findIndex(([Q,L1])=>Q===C&&L1===_)===U);Z||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[C,_]of p1.slice(0,5)){let[U,i1]=f5(C),[Q,L1]=f5(_),Y1=[0,1,2].map(G1=>w0((Math.max(U[G1],Q[G1])+Math.min(i1[G1],L1[G1]))/2));h.push(`Parts "${C.name}"${C.copy>1?` (copy ${C.copy})`:""} and "${_.name}"${_.copy>1?` (copy ${_.copy})`:""} collide in the assembly, around [${Y1.join(", ")}]. Check their edges and where they are placed.`)}if(p1.length>5&&h.push(`${p1.length-5} more pairs of parts collide in the assembly.`),oi(G,h),x.length&&w.length){let C=[...new Set(w.map(_=>`"${_.name}"`))];h.push(`${C.length===1?"Part":"Parts"} ${C.slice(0,5).join(", ")}${C.length>5?` and ${C.length-5} more`:""} ${C.length===1?"has":"have"} no at or rotate, so ${C.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...o7(x,w))}let E=0;for(let C of z){let _=0;for(let U of C.layers.values()){for(let i1 of U.regions)_+=i1.length;for(let i1 of U.lines)_+=i1.length}E+=_*C.info.qty}if(E>i.maxOutputPoints)throw new c1(`The files would have ${E} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let $=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray($)||!(Number.isFinite($[0])&&$[0]>0)||!(Number.isFinite($[1])&&$[1]>0))throw new c1("$sheet must be [width, height], both more than 0");let X=e.gap??A0(l("$gap")??3),j=e.margin??X;if(!(Number.isFinite(X)&&X>=0))throw new c1("$gap must be a number, 0 or more");if(!(Number.isFinite(j)&&j>=0))throw new c1("margin must be a number, 0 or more");let w1=e.nest??l("$nest")===!0,W1=e.layout??(l("$layout")==="none"?"none":"pack"),E1=[...u.keys()].filter(C=>!["engrave","score","cut","guide"].includes(C)),Z1=C=>(u.get(C)?.order??0)*2+(f(C)==="fill"?0:1),o0=["engrave",...E1.map((C,_)=>[C,_]).sort((C,_)=>Z1(C[0])-Z1(_[0])||C[1]-_[1]).map(([C])=>C),"score","cut","guide"].map(C=>u.get(C)).filter(Boolean),A=o0.filter(C=>C.side!=="back"),F=[...o0.filter(C=>C.side==="back")],t1=l("$registration")===!0;t1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),t1&&!A.some(C=>C.name==="registration")&&A.push(u.get("registration"));let a1=[],y1=[1,0,0,-1,0,0],P=C=>D0(C)??[0,0,0,0],Y=(C,_)=>k3({layers:C,parts:[]},_).layers;if(W1==="none"){let C=[];for(let Q of z)for(let L1=0;L1<Q.info.qty;L1++)C.push({part:Q.info.name,copy:L1+1,layers:Y(Q.layers,y1),rotated:!1});let _=new Map;for(let Q of C)for(let[L1,Y1]of Q.layers){let G1=_.get(L1)??{regions:[],lines:[]};for(let A1 of Y1.regions)G1.regions.push(A1);for(let A1 of Y1.lines)G1.lines.push(A1);_.set(L1,G1)}let U=P(_),i1=[1,0,0,1,j-U[0],j-U[1]];for(let Q of C)Q.layers=Y(Q.layers,i1),Q.offset=[i1[4],i1[5]];a1.push(W(C,U[2]-U[0]+2*j,U[3]-U[1]+2*j,z[0]?.info))}else{let C=new Map;for(let _ of z){let U=`${_.info.material}|${_.info.thickness}`;C.set(U,[...C.get(U)??[],_])}for(let _ of C.values()){let[U,i1]=$,Q=[];for(let d1 of _){let v1=Y(d1.layers,y1),U1=P(v1),l0=U1[2]-U1[0],z0=U1[3]-U1[1],$2=!1;(l0>U-2*j||z0>i1-2*j)&&z0<=U-2*j&&l0<=i1-2*j&&(v1=Y(v1,[0,1,-1,0,0,0]),U1=P(v1),l0=U1[2]-U1[0],z0=U1[3]-U1[1],$2=!0),(l0>U-2*j||z0>i1-2*j)&&h.push(`Part "${d1.info.name}" (${w0(l0)} x ${w0(z0)} mm) is bigger than the ${U} x ${i1} mm sheet.`),v1=Y(v1,[1,0,0,1,-U1[0],-U1[1]]);for(let e3=0;e3<d1.info.qty;e3++)Q.push({info:d1.info,layers:v1,w:l0,h:z0,copy:e3+1,rotated:$2})}Q.sort((d1,v1)=>v1.h-d1.h||v1.w-d1.w);let L1=w1?si(Q,X,d1=>f(d1)==="cut"):Q,Y1=[],G1=j,A1=j,_1=0,l1=0,z1=0,g1=()=>{if(Y1.length&&a1.length>=i.maxSheets)throw new c1(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);Y1.length&&a1.push(W(Y1,Math.max(l1+j,1),Math.max(z1+j,1),_[0].info)),Y1=[],G1=j,A1=j,_1=0,l1=0,z1=0};for(let d1 of L1){G1>j&&G1+d1.w>U-j&&(G1=j,A1+=_1+X,_1=0),Y1.length&&A1+d1.h>i1-j&&g1(),Y1.push({part:d1.info.name,copy:d1.copy,layers:Y(d1.layers,[1,0,0,1,G1,A1]),rotated:d1.rotated});for(let v1 of d1.inner??[])Y1.push({part:v1.item.info.name,copy:v1.item.copy,layers:Y(v1.item.layers,[1,0,0,1,G1+v1.dx,A1+v1.dy]),rotated:v1.item.rotated});l1=Math.max(l1,G1+d1.w),z1=Math.max(z1,A1+d1.h),G1+=d1.w+X,_1=Math.max(_1,d1.h)}g1()}}function W(C,_,U,i1){let Q=w0(_),L1=w0(U);if(t1){let A1=Math.min(5,j-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let _1=(l1,z1)=>[[l1,z1],[l1+A1,z1],[l1+A1,z1+A1],[l1,z1+A1]];C=[...C,{part:"registration",copy:1,layers:new Map([["registration",{regions:[_1(.5,.5),_1(Q-.5-A1,.5),_1(.5,L1-.5-A1)],lines:[]}]]),rotated:!1}]}}let Y1=C.some(A1=>F.some(_1=>A1.layers.has(_1.name))),G1=Y1?C.map(A1=>({...A1,layers:Y(A1.layers,[-1,0,0,1,Q,0])})):[];return{width:Q,height:L1,material:i1?.material??"material",thickness:i1?.thickness??0,items:C,paths:A4(C,A),svg:C4(C,Q,L1,A),dxf:i6(C,Q,L1,A),...Y1&&{back:{paths:A4(G1,F),svg:C4(G1,Q,L1,F),dxf:i6(G1,Q,L1,F)}}}}let b1=a1.length===1?a1[0]:void 0,s1=b1?[]:a1.flatMap((C,_)=>{let U=a1.slice(0,_).reduce((i1,Q)=>i1+Q.height+10,0);return C.items.map(i1=>({...i1,layers:Y(i1.layers,[1,0,0,1,0,U])}))}),$1=w0(Math.max(1,...a1.map(C=>C.width))),e1=w0(Math.max(1,a1.reduce((C,_)=>C+_.height,0)+10*Math.max(0,a1.length-1))),I1=b1?b1.svg:C4(s1,$1,e1,A),r0=b1?b1.paths:A4(s1,A);return{sheets:a1,width:b1?.width??$1,height:b1?.height??e1,paths:r0,svg:I1,parts:y,assembly:x,layers:[...A,...F],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function ci(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 ri(t,e,n){if(!t.some(l=>l.slots))return;let c=new Map,r=l=>{let h=c.get(l);return h||(h=x1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},a=l=>(l.placements??[]).flatMap(h=>c4({name:l.name,copy:0,placed:!0,matrix:G0(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=ci(v?g.slice(1):g),b=t.filter(x=>x!==l&&y(x.name));!b.length&&!v&&n.push(`Part "${l.name}": no part "${g}" to cut slots for.`);for(let x of b)v?h.delete(x):h.add(x)}let u=[...h].flatMap(a),f=(l.placements??[]).map(g=>x1(c4({name:l.name,copy:0,placed:!0,matrix:G0(g),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).flatMap(v=>{let y=d7(v,u,l.clearance??.1);return l.bends?x0(y,m0(v.outline,1,"miter")):y}))),d=(g,v)=>w3(g,v).reduce((y,b)=>y+Math.abs(H1(b)),0)>.001,p=l.stack??1;if(p>1){let g=y=>f.filter((b,x)=>x%p===y),v=Array.from({length:p},(y,b)=>x1(g(b).flat()));if(v.slice(1).some(y=>d(v[0],y))){Array.from({length:p},(y,b)=>g(b)).some(y=>y.slice(1).some(b=>d(y[0],b)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),i.set(l,v);continue}}f.slice(1).some(g=>d(f[0],g))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);let m=x1(f.flat());if(!m.length){l.slots.some(g=>g.includes("*"))||n.push(`Part "${l.name}": none of ${l.slots.map(g=>`"${g}"`).join(", ")} pass through it, so it has no slots.`);continue}s.set(l,m)}let o=(l,h)=>{let u=new Map(l);for(let[f,d]of l)u.set(f,{regions:b0(d.regions,h),lines:v2(d.lines,h,"outside")});return u};for(let[l,h]of s)l.layers=o(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,p)=>({...l,name:`${l.name}, layer ${p+1}`,qty:l.qty/u,layers:d.length?o(l.layers,d):l.layers,placements:l.placements.filter((m,g)=>g%u===p),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function ai(t,e,n){let c=new Map;for(let[r,a]of e){let s=t.filter(M=>M.name===a&&M.placed);if(!s.length){c.has(a)||n.push(`Part "${r.name}" is on "${a}", which is not a placed part.`),c.set(a,0);continue}let i=[...e].filter(([M,w])=>M.name===r.name&&w===a).length,o=s.length===i?s[r.copy-1]:s[0];if(!o?.bends?.length)continue;let[l,h,u,f]=[1/0,1/0,-1/0,-1/0];for(let M of r.outline)for(let[w,k]of M)l=Math.min(l,w),h=Math.min(h,k),u=Math.max(u,w),f=Math.max(f,k);let d=r.matrix,[p,m,g]=[(l+u)/2,(h+f)/2,r.thickness/2],v=[d[0]*p+d[1]*m+d[2]*g+d[3],d[4]*p+d[5]*m+d[6]*g+d[7],d[8]*p+d[9]*m+d[10]*g+d[11]],y=L0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=t4(o.bends,o.thickness)[u7(o.bends,b)];r.matrix=O1(o.matrix,O1(x,O1(y,r.matrix)))}}function si(t,e,n){var l;let c=[],r=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)H1(p)<0&&u.push([...p].reverse());return u.length?m0(x1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let p of h)for(let m=0,g=p.length-1;m<p.length;g=m++){let[v,y]=p[g],[b,x]=p[m];y<=f?x>f&&(b-v)*(f-y)-(u-v)*(x-y)>0&&d++:x<=f&&(b-v)*(f-y)-(u-v)*(x-y)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)H1(p)>0&&u.push(p);return x1(u)},i=(h,u)=>{let{w:f,h:d}=u,p=s(u),m=[];for(let g of p)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))m.push(g[v]);for(let g of h){if(H1(g)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[w,k]of g)v=Math.min(v,w),y=Math.min(y,k),b=Math.max(b,w),x=Math.max(x,k);if(b-v<f||x-y<d)continue;let M=Math.max(.5,Math.min(f,d,b-v-f+1,x-y-d+1)/4);for(let w=y;w<=x-d+1e-9;w+=M)for(let k=v;k<=b-f+1e-9;k+=M){if(!m.every(([S,L])=>a(h,S+k,L+w)))continue;let z=p.map(S=>S.map(([L,I])=>[L+k,I+w]));if(b0(z,h).reduce((S,L)=>S+Math.abs(H1(L)),0)<.01)return[k,w]}}},o=[];for(let h of t){let u=!1;for(let d of c){let p=i(d.region,h);if(!p)continue;let[m,g]=p;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+m,dy:d.oy+g}),d.region=b0(d.region,m0(s(h).map(y=>y.map(([b,x])=>[b+m,x+g])),e,"miter"));let v=r(h);v.length&&c.push({host:d.host,ox:d.ox+m,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;o.push(h);let f=r(h);f.length&&c.push({host:h,ox:0,oy:0,region:f})}return o}function f8(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 ii(t,e,n){let c=[...n.keys()],r=[...e.keys()].filter(i=>n.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),a=[];if(r.length<2)return a;let s=i=>i==="engrave"?-1/0:(n.get(i)?.order??0)*2+c.indexOf(i)/c.length;r.sort((i,o)=>s(i)-s(o));for(let i=0;i<r.length-1;i++){let o=n.get(r[i]).side??"front",l=r.slice(i+1).filter(u=>(n.get(u).side??"front")===o);if(!l.length)continue;let h;for(let u of _0(e.get(r[i]).regions)){let f=u.reduce((M,w)=>M+H1(w),0);if(!(f>.001)||!m0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=b0(d,e.get(M).regions));if(d.reduce((M,w)=>M+H1(w),0)>.001*Math.max(1,f))continue;let m=l.filter(M=>x0(u,e.get(M).regions).length),g=m.length?m:l;if(h){h.count++;for(let M of g)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=D0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:r[i],under:g,count:1,at:[w0((v+b)/2),w0((y+x)/2)]}}h&&a.push(h)}return a}function oi(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 li(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(G0),o=r.glue.face==="top"?s.thickness:-r.thickness,l=r.placements.length/(r.stack??1);r.placements=r.placements.map((h,u)=>{let f=i.length===l?i[Math.floor(u/(r.stack??1))]:i[0];return{...h,matrix:O1(f,O1(R0(0,0,o),G0(h)))}}),n.add(r)};for(let r of t)c(r,[])}function hi(t,e,n,c){let r=0,a=50;for(let m=0;m<14;m++){let g=(r+a)/2;m0(t,-g,"round").length?r=g:a=g}if(r<1)return[];let s=m0(t,-r*.98,"round"),i=D0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((m,g)=>s.reduce((v,y)=>v+(p8(y,m,g)?H1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((m,g)=>H1(g)>H1(m)?g:m)[0]);let u=Math.min(6,Math.max(2,r*.9)),f=L4(n,e,{size:u,font:c,halign:"center",valign:"center",spacing:1}),d=D0(new Map([["t",{regions:f,lines:[]}]])),p=d?Math.min(1,1.6*r/Math.max(d[2]-d[0],1e-9)):1;return f.map(m=>m.map(([g,v])=>[o-g*p,l+v*p]).reverse())}function p8(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 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 c=g8(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 m8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function v8(t){let{program:e,comments:n}=e2(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=g8(i.value);if(!o.ok)continue;let l=c.filter(m=>m.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(l.toLowerCase()==="hidden")continue;let h=r.get(i.pos.line),u=a.get(i.pos.line-1)??"",f=o.value,d={name:i.name,caption:u,group:l,type:typeof f=="number"||Array.isArray(f)?"number":typeof f=="boolean"?"boolean":"string",initial:f,span:i.span},p=h?/^\[(.*)\]$/.exec(h.trim()):null;if(p){let m=p[1];if(m.includes(",")||/[a-zA-Z"]/.test(m)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(m))d.options=m.split(",").map(g=>{let[v,y]=g.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=m8(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let g=m.split(":").map(m8);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 ui=8,fi=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,di=(t,e)=>Math.max(1,fi.exec(t.slice(e-1))?.[0].length??1);function y8(t,e,n={}){if(!(t instanceof c1))return`error: ${t instanceof Error?t.message:String(t)}`;let c=n.file??"design.kerf",r=(o,l,h)=>`${o?`<${o}>`:c}:${l}:${h}`,a=o=>o===void 0?e:(Object.prototype.hasOwnProperty.call(y5,o)?y5[o]:void 0)??n.resolve?.(o),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${r(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
|
|
2567
|
-
`)?.[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=
|
|
2568
|
-
`)}function
|
|
2569
|
-
`)r
|
|
2570
|
-
`,
|
|
2571
|
-
`);n.push({kind:"block",text:o,breaks:
|
|
2645
|
+
`}var W8=(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 X8(t,e={}){for(let[I,N]of Object.entries(e.params??{}))try{Ie(I,N)}catch(a1){throw new o1(a1.message)}let{program:n}=l2(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 q4(e.fonts,e.defaultFont):void 0,s=new Y3({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 o1(/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 o1&&(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.${b3(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.`);Qi(d,h),_i(d,f,h,o.hardware),ji(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=eo(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,Q0,B1]=X0(new Map([["cut",{regions:T1,lines:[]}]]));return`[${m0(($1+Q0)/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=St(T1)),(y1.length||T1.length)&&J.set(m1,{regions:y1,lines:T1})}if(T.push(...Ji(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:L6(I,$1),matrix:Z0(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 Q0=J1.matrix.map(B1=>B1.toFixed(6)).join(",");y1.has(Q0)&&k.add(J1),y1.add(Q0)}),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:L6(I,y1),matrix:Z0({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,Q0,B1]=X0(new Map([["cut",{regions:T1,lines:[]}]]));return`[${m0($1)}, ${m0(J1)}] to [${m0(Q0)}, ${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+=W8(y1,!0);for(let y1 of v1.lines)w0+=W8(y1,!1)}let Y1=X0(J)??[0,0,0,0],A1=e.kerf??I.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new o1("$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]},Q0=y1.map(J1).filter(([B1,c0])=>!T1.some(b0=>Z8(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${Q0.length?`, at ${Q0.join(", ")}${$1>Q0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(l0),z.push({info:l0,layers:J,copy:m1=>L6(I,m1)})}Gi(x,M,h);let B=new Map,X=x.filter(I=>!k.has(I)).flatMap(I=>{let N=g4(I);for(let a1 of N)B.set(a1,I);return N}),{found:Z,complete:h1}=Ht(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=(Ot(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.`),Ki(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(...Tt(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 o1(`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 o1("$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 o1("$gap must be a number, 0 or more");if(!(Number.isFinite(W)&&W>=0))throw new o1("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],P3=!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],P3=!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:P3})}let R1=(B1,c0)=>c0.h-B1.h||c0.w-B1.w,w0=B1=>{let c0=0,b0=W,c2=W,G0=0,P3=!1;for(let W2 of B1)b0>W&&b0+W2.w>a1-W&&(b0=W,c2+=G0+Q,G0=0),P3&&c2+W2.h>J-W&&(c0++,[b0,c2,G0]=[W,W,0]),P3=!0,b0+=W2.w+Q,G0=Math.max(G0,W2.h);return c0+(P3?1:0)};x1.sort(R1);let Y1=Xi(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?Wi(A1,Q,B1=>f(B1)==="cut"):A1,m1=[],v1=W,y1=W,T1=0,$1=0,J1=0,Q0=()=>{if(m1.length&&t1.length>=i.maxSheets)throw new o1(`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&&Q0(),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)}Q0()}}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:U4(I,D),svg:B4(I,x1,R1,D),dxf:S6(I,x1,R1,D),...w0&&{back:{paths:U4(Y1,e1),svg:B4(Y1,x1,R1,e1),dxf:S6(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:B4(U1,c1,V1,D),d0=r1?r1.paths:U4(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 A6(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 Bi(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 C6(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 _i(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=>g4({name:l.name,copy:0,placed:!0,matrix:Z0(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=A6(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=A6(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(g4({name:l.name,copy:0,placed:!0,matrix:Z0(x),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).flatMap(M=>{let w=[];if(l.slots){let k=m.map(S=>$t(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?Bi(n0(i1(z),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let z=Nt(M,k,l.fit??z5.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=C6(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?C6(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 ji(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:Z0(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=A6(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=Gt(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=C6(i.layers,i1(l.flat()))}}function Gi(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=m4(o.bends,o.thickness)[Rt(o.bends,b)];c.matrix=q1(o.matrix,q1(x,q1(y,c.matrix)))}}function Wi(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 Xi(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?Zi(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 Zi(t,e,n,r,c){let s=n0(t.map(b=>Yi(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 Yi(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 L6(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 Ji(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 Ki(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 Qi(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(Z0),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),Z0(h)))}}),n.add(c)};for(let c of t)r(c,[])}function eo(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+(Z8(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=N4(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 Z8(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 J8(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=J8(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 Y8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function K8(t){let{program:e,comments:n}=l2(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=J8(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=Y8(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let p=g.split(":").map(Y8);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 to=8,no=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,ro=(t,e)=>Math.max(1,no.exec(t.slice(e-1))?.[0].length??1);function Q8(t,e,n={}){if(!(t instanceof o1))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=ro(l,t.col),m=f.replace(/[^\t]/g," ");s.push(`${u} |`,`${h} | ${l}`,`${u} | ${m}${"^".repeat(d)}`)}}for(let o of co(t,c))s.push(` = ${o}`);let i=t.call?B3(t.call):void 0;return i&&s.push(` = ${z4(i)}: ${i.doc}`),s.join(`
|
|
2647
|
+
`)}function co(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,to).map(n),c=t.trace.length-r.length+t.traceMore;return c&&r.push(`and ${c} more call${c===1?"":"s"}`),r}var en=new Set(["module","function","if","else","for","let","each","use","include"]),ao=new Set(["true","false","undef"]),so=new Set(["for","if","let","function"]),P6={"(":")","[":"]","{":"}"},io=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function oo(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 E6(t){let{tokens:e}=N3(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=oo(t,s);n.push({kind:"token",text:i,token:s,breaks:c}),c=0,r=s.pos.offset+i.length}return n}function _4(t,e={}){l2(t);let n=" ".repeat(e.indent??2),r=E6(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===P6[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===","||P6[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||lo(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&&ho(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,P6[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&&so.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(`
|
|
2572
2651
|
`)+`
|
|
2573
|
-
`:"";return
|
|
2574
|
-
<h2><span>${
|
|
2575
|
-
<div class="view">${
|
|
2576
|
-
${
|
|
2652
|
+
`:"";return uo(t,k),k}var lo=t=>io.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&en.has(t.text)||t.role==="unary"||t.role==="modifier";function ho(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"&&(!en.has(n)||ao.has(n))||n===")"&&t.role!=="header"||n==="]";return r==="("?n==="for"||n==="if"||n==="let"||!a&&n!=="function":r==="["?!a:!0}function uo(t,e){let n=E6(t),r=E6(e);if(!(n.length===r.length&&n.every((a,s)=>a.kind===r[s].kind&&a.text===r[s].text)))throw new o1("The formatter would change the program, so it was left as it is")}function tn(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 nn=t=>Math.round(t*100)/100,j4=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function rn(t,e,n=.01){let r=tn(t),c=tn(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(j4)),p=new Set(f.lines.map(j4)),v=u.lines.filter(x=>!p.has(j4(x))),y=f.lines.filter(x=>!g.has(j4(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:nn(m)},...v.length&&{linesRemoved:v.length},...y.length&&{linesAdded:y.length},...b&&{at:b.map(nn)}})}}return a}var fo=[Math.SQRT1_2,Math.SQRT1_2,0],mo=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],T6=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],po=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),Q3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],cn=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],go=(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]],vo=(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 an(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 yo(t,e,n){let r=(i,o,l)=>vo(t.matrix,t.bends?.length?p4(t.bends,t.thickness,[i,o,l]):[i,o,l]),c=[],a=(i,o)=>{if(i.length<3)return;let l=go(cn(i[1],i[0]),cn(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(Q3(f,T6)<=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:an(e,.55+.45*Math.max(0,Q3(f,po))),depth:Q3([d[0]/i.length,d[1]/i.length,d[2]/i.length],T6),stroke:n})},s=t.thickness;for(let i of v4(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 bo(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:Q3(r,T6)+n/2,stroke:String(n)}]}function xo(t,e=640,n=420){let r=g=>[Q3(g,fo),-Q3(g,mo)],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 Mo="#d9bf91",wo="#cfc6b8",ko="#e08a3c";function sn(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=>U3[f]??d3[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(...yo(y,b===m?ko:y.step===void 0&&!t.steps.length?Mo:wo,b===m?"#7a3e0c":"#8a8274"))}for(let y of t.hardware){let b=t.steps.length?y.step:1;b<=m&&g.push(...bo(y,b===m?s(y.kind):an(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">${xo(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}`:""}`))}`:""}
|
|
2577
2656
|
${v.size?`<h3>Hardware</h3>${i([...v].map(([y,b])=>`${y}${b>1?` × ${b}`:""}`))}`:""}
|
|
2578
|
-
</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>
|
|
2579
2658
|
<html lang="en">
|
|
2580
2659
|
<head>
|
|
2581
2660
|
<meta charset="utf-8">
|
|
2582
2661
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2583
|
-
<title>${
|
|
2662
|
+
<title>${U2(e)}: assembly</title>
|
|
2584
2663
|
<style>
|
|
2585
2664
|
body { font: 15px/1.45 system-ui, sans-serif; color: #222; margin: 24px auto; max-width: 760px; padding: 0 16px; }
|
|
2586
2665
|
h1 { font-size: 26px; margin: 0 0 4px; }
|
|
@@ -2597,8 +2676,8 @@ figure { margin: 12px 0; } figcaption { color: #666; font-size: 13px; }
|
|
|
2597
2676
|
</style>
|
|
2598
2677
|
</head>
|
|
2599
2678
|
<body>
|
|
2600
|
-
<h1>${
|
|
2601
|
-
<p class="note">${t.parts.reduce((f,d)=>f+d.qty,0)} parts on ${t.sheets.length} sheet${t.sheets.length===1?"":"s"}, ${
|
|
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>
|
|
2602
2681
|
<h3>Parts</h3>
|
|
2603
2682
|
<table><tr><th>#</th><th>Part</th><th>Qty</th><th>Size</th><th>Material</th></tr>${h}</table>
|
|
2604
2683
|
${u}
|
|
@@ -2606,46 +2685,46 @@ ${o.join(`
|
|
|
2606
2685
|
`)}
|
|
2607
2686
|
</body>
|
|
2608
2687
|
</html>
|
|
2609
|
-
`}var
|
|
2610
|
-
`).length;throw new Error(`${o} (line ${l})`)};for(;a<t.length;){let o=t.indexOf("<",a),l=o<0?t.length:o;if(l>a&&(r[r.length-1].text+=L8(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]]=L8(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 n2={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"}},f6={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"},Hi=Object.fromEntries(Object.entries(f6).reverse().map(([t,e])=>[e,t]));function E5(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(f6[t])return f6[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 j3=(t,e)=>I3(t,Math.PI/12,e),I5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function Oi(t){let e=he;if(!t)return e;for(let[,n,c]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let r=I5(c),a=(r[0]??0)*Math.PI/180,s=he;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=z3(e,s)}return e}function Ri(t,e){let n=[],c=[],r=[0,0],a=[0,0],s=(l,h)=>l5(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 Fi=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],$i=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function C8(t){let e={};for(let n of t.split(";")){let 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 Di(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,c]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let r=C8(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 qi(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 u6(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])*qi(n[2].toLowerCase(),e)}var Ni=/^(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 Ui(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Ni.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Bi(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return n2.score;if(/engrav|raster|etch/.test(e))return n2.engrave;if(/\bguide/.test(e))return n2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return n2.cut}function P8(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=A8(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=I5(c.attrs.viewBox??""),o=u6(c.attrs.width,s),l=u6(c.attrs.height,s),h=25.4/s,u=h,f=h,d=0,p=0;i.length===4&&i[2]>0&&i[3]>0&&(u=o!==void 0?o/i[2]:l!==void 0?l/i[3]:h,f=l!==void 0?l/i[3]:u,d=i[0],p=i[1]),o===void 0&&l===void 0&&e.dpi===void 0&&!a&&r.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let m=l??(i.length===4?i[3]*f:0),g=z3([1,0,0,-1,0,m],[u,0,0,f,-d*u,-p*f]),v=[],y=new Map,b=P=>{P.name==="style"&&v.push(...Di(P.text)),P.attrs.id&&y.set(P.attrs.id,P),P.children.forEach(b)};b(c);let x=(P,Y)=>{let W={};for(let s1 of Object.keys(Y))$i.has(s1)&&(W[s1]=Y[s1]);for(let s1 of Fi)P.attrs[s1]!==void 0&&(W[s1]=P.attrs[s1]);let b1=(P.attrs.class??"").split(/\s+/).filter(Boolean);for(let s1 of v)(!s1.tag||s1.tag===P.name)&&(!s1.id||s1.id===P.attrs.id)&&s1.classes.every($1=>b1.includes($1))&&Object.assign(W,s1.decls);return P.attrs.style&&Object.assign(W,C8(P.attrs.style)),W},M=[],w=[],k=0,z=0,S=0,L=0,I=0,q=0,R=2e4,N=[],G=P=>Number.isFinite(P[0])&&Number.isFinite(P[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],J=P=>[...V,"x1","y1","x2","y2","points"].some(Y=>P.attrs[Y]!==void 0&&I5(P.attrs[Y]).some(W=>!Number.isFinite(W))),o1=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),Z=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),p1=P=>{let Y=W=>parseFloat(P.attrs[W]??"0")||0;switch(P.name){case"path":return j3(P.attrs.d??"",()=>S++);case"rect":{let[W,b1,s1,$1]=[Y("x"),Y("y"),Y("width"),Y("height")];if(s1<=0||$1<=0)return[];let e1=P.attrs.rx!==void 0?Y("rx"):P.attrs.ry!==void 0?Y("ry"):0,I1=P.attrs.ry!==void 0?Y("ry"):e1;return e1=Math.min(Math.abs(e1),s1/2),I1=Math.min(Math.abs(I1),$1/2),e1<=0||I1<=0?j3(`M${W} ${b1}H${W+s1}V${b1+$1}H${W}Z`):j3(`M${W+e1} ${b1}H${W+s1-e1}A${e1} ${I1} 0 0 1 ${W+s1} ${b1+I1}V${b1+$1-I1}A${e1} ${I1} 0 0 1 ${W+s1-e1} ${b1+$1}H${W+e1}A${e1} ${I1} 0 0 1 ${W} ${b1+$1-I1}V${b1+I1}A${e1} ${I1} 0 0 1 ${W+e1} ${b1}Z`)}case"circle":case"ellipse":{let[W,b1]=[Y("cx"),Y("cy")],s1=P.name==="circle"?Y("r"):Y("rx"),$1=P.name==="circle"?Y("r"):P.attrs.ry!==void 0?Y("ry"):s1;return s1<=0||$1<=0?[]:j3(`M${W+s1} ${b1}A${s1} ${$1} 0 0 1 ${W} ${b1+$1}A${s1} ${$1} 0 0 1 ${W-s1} ${b1}A${s1} ${$1} 0 0 1 ${W} ${b1-$1}A${s1} ${$1} 0 0 1 ${W+s1} ${b1}Z`)}case"line":return j3(`M${Y("x1")} ${Y("y1")}L${Y("x2")} ${Y("y2")}`);case"polyline":case"polygon":{let W=I5(P.attrs.points??"");if(W.length<4)return[];let b1=`M${W[0]} ${W[1]}`;for(let s1=2;s1+1<W.length;s1+=2)b1+=`L${W[s1]} ${W[s1+1]}`;return j3(P.name==="polygon"?b1+"Z":b1)}}},E=P=>(P.text+P.children.map(Y=>Y.name==="tspan"?" "+E(Y):"").join("")).replace(/\s+/g," ").trim(),$=(P,Y,W,b1,s1,$1)=>{if($1>64||o1.has(P.name)||I&&++q>R)return;let e1=x(P,W);if(e1.display==="none"||e1.visibility==="hidden"||e1.opacity==="0"){(P.children.length||Z.has(P.name))&&z++;return}let I1=z3(Y,Oi(P.attrs.transform));if(!I1.every(Number.isFinite)){L++;return}let r0=Ui(P),C=P.attrs["inkscape:groupmode"]==="layer",_=b1;if(P.name==="g"||P.name==="svg"||P.name==="a"||P.name==="switch"){let _1=P.attrs["inkscape:label"]??P.attrs["data-name"]??P.attrs.id,l1=Bi(_1);if(P.attrs["data-mode"]&&_1&&/^(cut|line|fill|guide)$/.test(P.attrs["data-mode"])){let g1=E5(e1.stroke,"#000000"),d1=E5(e1.fill,"#000000"),v1=P.attrs["data-mode"]==="fill"?d1:g1;_=n2[_1]??{name:_1,mode:P.attrs["data-mode"],color:v1&&v1.startsWith("#")?v1:"#00aa00"}}else l1&&(_=l1);if(P!==c&&P.name==="svg"){let g1=d1=>parseFloat(P.attrs[d1]??"0")||0;I1=z3(I1,[1,0,0,1,g1("x"),g1("y")])}let z1=C||l1||P===c||!r0?s1:[r0,...s1];N.push(P);for(let g1 of P.children)$(g1,I1,e1,_,z1,$1+1);N.pop();return}if(P.name==="use"){let _1=y.get((P.attrs.href??P.attrs["xlink:href"]??"").replace(/^#/,""));if(!_1||N.includes(_1))return;let l1=d1=>parseFloat(P.attrs[d1]??"0")||0,z1=z3(I1,[1,0,0,1,l1("x"),l1("y")]),g1=_1.name==="symbol"?{..._1,name:"g"}:_1;N.push(_1),I++,$(g1,z1,e1,_,r0?[r0,...s1]:s1,$1+1),I--,N.pop();return}if(P.name==="image"){k++;return}let U=E5(e1.color,"#000000")??"#000000",i1=parseFloat(e1["stroke-width"]??"1"),Q=E5(e1.stroke,U);Q&&(i1===0||e1["stroke-opacity"]==="0")&&(Q="none");let L1=E5(e1.fill??"black",U);if(e1["fill-opacity"]==="0"&&(L1="none"),P.name==="text"){let _1=E(P);if(!_1)return;let l1=P.children.find(l0=>l0.name==="tspan"),z1=l0=>I5(P.attrs[l0]??l1?.attrs[l0]??"0")[0]??0,g1=l5(I1,[z1("x"),z1("y")]),d1=Math.sqrt(Math.abs(I1[0]*I1[3]-I1[1]*I1[2])),v1=(u6(e1["font-size"],96)??16*h)/h;if(!G(g1)||!Number.isFinite(v1*d1)){L++;return}let U1=e1["text-anchor"];w.push({text:_1,at:g1,size:v1*d1,angle:Math.atan2(-I1[1],I1[0])*180/Math.PI,font:(e1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:U1==="middle"?"center":U1==="end"?"right":"left",stroke:Q,fill:L1,layer:_});return}if(P.name!=="path"&&J(P)){L++;return}let Y1=p1(P);if(!Y1){for(let _1 of P.children)$(_1,I1,e1,_,s1,$1+1);return}let G1=Ri(Y1,I1),A1=G1.filter(_1=>_1.segs.every(l1=>G(l1.a)&&G(l1.b)&&(l1.c==="L"||G(l1.p1)&&G(l1.p2))));A1.length<G1.length&&L++,A1.length&&M.push({subs:A1,stroke:Q,fill:P.name==="line"||P.name==="polyline"?"none":L1,fillRule:e1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:_,names:r0?[r0,...s1]:s1})};$(c,g,{},void 0,[],0),k&&r.push(`${k} embedded image${k===1?" was":"s were"} left out: trace ${k===1?"it":"them"} to paths first.`),z&&r.push(`${z} hidden element${z===1?" was":"s were"} left out.`),S&&r.push(`${S} path${S===1?" has":"s have"} bad data: read up to the error, as browsers draw ${S===1?"it":"them"}.`),L&&r.push(`${L} element${L===1?" was":"s were"} left out: ${L===1?"its":"their"} numbers are too large to draw.`),q>R&&r.push(`The drawing repeats its elements with <use> more than ${R.toLocaleString("en")} times: only the first ${R.toLocaleString("en")} copies were read.`);let X=P=>{let[Y,W,b1]=[1,3,5].map(s1=>parseInt(P.slice(s1,s1+2),16));return Y>=200&&W<=80&&b1<=80},j=P=>{let[Y,W,b1]=[1,3,5].map(s1=>parseInt(P.slice(s1,s1+2),16));return b1>=200&&Y<=80&&W<=80},w1=P=>!!P.stroke&&P.stroke!=="none",W1=M.filter(P=>!P.layer),E1=new Map;for(let P of W1)w1(P)&&P.stroke.startsWith("#")&&E1.set(P.stroke,(E1.get(P.stroke)??0)+P.subs.length);let Z1=[...E1.keys()],p0=Z1.filter(X),o0=new Set(p0.length?p0:Z1.length?[Z1.reduce((P,Y)=>(E1.get(Y)??0)>(E1.get(P)??0)?Y:P)]:[]),A=M.some(P=>w1(P)&&!P.layer)||M.some(P=>P.layer),F=new Map,t1=(P,Y)=>{if(P&&P!=="none"){let W=P.startsWith("#")?P:"#000000";if(o0.has(W))return n2.cut;if(W==="#00a0ff")return n2.guide;if(j(W))return n2.score;if(!F.has(W)){let b1=Hi[W]??"color_"+W.slice(1);F.set(W,{name:b1,mode:"line",color:W})}return F.get(W)}if(Y&&Y!=="none")return A?n2.engrave:n2.cut};!A&&M.some(P=>P.fill&&P.fill!=="none")?r.push("The file has filled shapes and no strokes: the shapes are cut out."):!p0.length&&o0.size&&r.push(`No red lines: ${[...o0][0]} lines, the most common colour, are cut.`),F.size&&r.push(`Lines in ${[...F.values()].map(P=>P.color).join(", ")} went on their own layer${F.size===1?"":"s"}, set to mark, not cut.`);let a1=[];for(let P of M){let Y=P.layer??t1(P.stroke,P.fill);if(!Y)continue;let W=!P.layer&&Y===n2.cut&&!w1(P);a1.push({subs:P.subs,layer:Y,fillRule:P.fillRule,names:P.names,filled:W})}let y1=[];for(let P of w){let Y=P.layer??t1(P.fill!=="none"?void 0:P.stroke,P.fill);Y&&y1.push({...P,layer:Y.mode==="cut"&&A?n2.engrave:Y})}return{items:a1,texts:y1,notes:r}}var F1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),u2=([t,e],n)=>{let c=n*Math.PI/180,r=Math.cos(c),a=Math.sin(c);return[t*r-e*a,t*a+e*r]},p6=(t,e)=>[t[0]+e[0],t[1]+e[1]],f2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function f3(t,e=.005){let n=[t.segs[0].a];for(let c of t.segs)if(c.c==="L")n.push(c.b);else{let r=F1(c.a,c.p1)+F1(c.p1,c.p2)+F1(c.p2,c.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(r/e))));for(let s=1;s<=a;s++){let i=s/a,o=1-i;n.push([o*o*o*c.a[0]+3*o*o*i*c.p1[0]+3*o*i*i*c.p2[0]+i*i*i*c.b[0],o*o*o*c.a[1]+3*o*o*i*c.p1[1]+3*o*i*i*c.p2[1]+i*i*i*c.b[1]])}}return t.closed&&n.length>1&&F1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function w2(t,e=!0){let n=0;for(let c=1;c<t.length;c++)n+=F1(t[c-1],t[c]);return e&&t.length>2?n+F1(t[t.length-1],t[0]):n}function O2(t,e,n){let c=[],r=e?t.length:t.length-1;for(let a=0;a<r;a++){let s=t[a],i=t[(a+1)%t.length];c.push(s);let o=Math.floor(F1(s,i)/n);for(let l=1;l<o;l++)c.push([s[0]+(i[0]-s[0])*l/o,s[1]+(i[1]-s[1])*l/o])}return!e&&t.length&&c.push(t[t.length-1]),c}function Z2(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?((t[0]-e[0])*c+(t[1]-e[1])*r)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}var u3=class{constructor(e,n,c){this.size=c;this.cells=new Map;for(let r of e){let a=n?r.length:r.length-1;for(let s=0;s<a;s++){let i=r[s],o=r[(s+1)%r.length],l=Math.max(1,Math.ceil(F1(i,o)/(c*2)));for(let h=0;h<l;h++){let u=[i[0]+(o[0]-i[0])*h/l,i[1]+(o[1]-i[1])*h/l],f=[i[0]+(o[0]-i[0])*(h+1)/l,i[1]+(o[1]-i[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/c),p=Math.floor(Math.max(u[0],f[0])/c),m=Math.floor(Math.min(u[1],f[1])/c),g=Math.floor(Math.max(u[1],f[1])/c);for(let v=d;v<=p;v++)for(let y=m;y<=g;y++){let b=`${v},${y}`,x=this.cells.get(b);x?x.push([u,f]):this.cells.set(b,[[u,f]])}}}}}near(e,n){let c=Math.floor((e[0]-n)/this.size),r=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let i=c;i<=r;i++)for(let o=a;o<=s;o++)for(let[l,h]of this.cells.get(`${i},${o}`)??[])if(Z2(e,l,h)<=n)return!0;return!1}meets(e,n,c){let r=Math.max(1,Math.ceil(F1(e,n)/(this.size*2)));for(let a=0;a<r;a++){let s=[e[0]+(n[0]-e[0])*a/r,e[1]+(n[1]-e[1])*a/r],i=[e[0]+(n[0]-e[0])*(a+1)/r,e[1]+(n[1]-e[1])*(a+1)/r],o=Math.floor((Math.min(s[0],i[0])-c)/this.size),l=Math.floor((Math.max(s[0],i[0])+c)/this.size),h=Math.floor((Math.min(s[1],i[1])-c)/this.size),u=Math.floor((Math.max(s[1],i[1])+c)/this.size);for(let f=o;f<=l;f++)for(let d=h;d<=u;d++)for(let[p,m]of this.cells.get(`${f},${d}`)??[])if(E8(s,i,p,m)<=c)return!0}return!1}};function E8(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 _i(t,e,n=.2){let c=t.length;if(c<4)return!1;let r=[0];for(let h=1;h<=c;h++)r.push(r[h-1]+F1(t[h-1],t[h%c]));let a=r[c],s=S0([t]),i=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(c)),o=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/i),p=Math.floor((Math.max(h[0],u[0])+e)/i),m=Math.floor((Math.min(h[1],u[1])-e)/i),g=Math.floor((Math.max(h[1],u[1])+e)/i);if((p-d+1)*(g-m+1)>4096)return null;for(let v=d;v<=p;v++)for(let y=m;y<=g;y++)f.push(`${v},${y}`);return f};for(let h=0;h<c;h++){let u=t[h],f=t[(h+1)%c],d=l(u,f);if(!d)return!1;for(let p of d)for(let m of o.get(p)??[]){let g=Math.abs(r[h]-r[m]);if(!(Math.min(g,a-g)-F1(u,f)-F1(t[m],t[(m+1)%c])<n)&&E8(u,f,t[m],t[(m+1)%c])<=e)return!0}for(let p of d){let m=o.get(p);m?m.push(h):o.set(p,[h])}}return!1}function I8(t,e){let n=t.map(()=>!1),c=[],r=t.map(l=>S0([l]));t.forEach((l,h)=>{let u=x1([l]),f=u.reduce((m,g)=>m+H1(g),0),d=w2(l),p=u.reduce((m,g)=>m+w2(g),0);(u.length!==1||Math.abs(f-Math.abs(H1(l)))>d*.001+1e-6||Math.abs(p-d)>d*.001+.05||_i(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new u3([t[l]],!0,Math.max(e*4,1))),h},i=t.map((l,h)=>h).sort((l,h)=>r[l][0]-r[h][0]),o=[];for(let l of i){let[h,u,f,d]=r[l];for(let p=o.length-1;p>=0;p--)r[o[p]][2]<h-e&&o.splice(p,1);for(let p of o){let m=r[p];if(m[1]>d+e||m[3]<u-e)continue;let[g,v]=t[l].length<=t[p].length?[l,p]:[p,l],y=t[g],b=s(v);for(let x=0;x<y.length;x++)if(b.meets(y[x],y[(x+1)%y.length],e)){c.push([l,p]);break}}o.push(l)}return{self:n,pairs:c}}function d3(t,e,n,c=!0){if(!t.length||!e.length)return t.length===e.length;let r=Math.max(n*2,.2),a=new u3(t,c,Math.max(n*4,1)),s=new u3(e,c,Math.max(n*4,1));for(let i of t)for(let o of O2(i,c,r))if(!s.near(o,n))return!1;for(let i of e)for(let o of O2(i,c,r))if(!a.near(o,n))return!1;return!0}function V8(t,e,n){let c=new u3([t,...e],!0,Math.max(n*4,1)),r=a=>H2(a,t)&&!e.some(s=>H2(a,s));return(a,s)=>{let i=s?a.length:a.length-1;if(i<1)return!1;let o;for(let l=0;l<i;l++){let h=a[l],u=a[(l+1)%a.length];if(!c.meets(h,u,n)){o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==i-1)return!1;let f=F1(h,u),d=Math.min(n*3,f/3)/f,p=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,m=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(c.meets(p,m,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?r(o):!0}}function H8(t,e,n){if(!t.length)return!1;let c=new u3([e],!0,Math.max(n*4,1));return t.some(r=>O2(r,!1,Math.max(n*2,.2)).some(a=>c.near(a,n)))}function H2(t,e){let n=!1;for(let c=0,r=e.length-1;c<e.length;r=c++){let[a,s]=e[c],[i,o]=e[r];s>t[1]!=o>t[1]&&t[0]<(i-a)*(t[1]-s)/(o-s)+a&&(n=!n)}return n}function H4(t){let e=t.length;if(e<3)return null;let n=0,c=0;for(let[g,v]of t)n+=g,c+=v;n/=e,c/=e;let r=0,a=0,s=0,i=0,o=0,l=0,h=0;for(let[g,v]of t){let y=g-n,b=v-c;r+=y*y,a+=y*b,s+=b*b,i+=y*y*y,o+=b*b*b,l+=y*b*b,h+=b*y*y}let u=r*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(i+l)/2,d=(o+h)/2,p=(f*s-d*a)/u,m=(d*r-f*a)/u;return{c:[p+n,m+c],r:Math.sqrt(p*p+m*m+(r+s)/e)}}function W3(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)F1(t[0],t[o])>F1(t[0],t[n])&&(n=o);let c=o=>{if(o.length<3)return o;let l=0,h=0;for(let f=1;f<o.length-1;f++){let d=Z2(o[f],o[0],o[o.length-1]);d>l&&(l=d,h=f)}return l<=e?[o[0],o[o.length-1]]:[...c(o.slice(0,h+1)).slice(0,-1),...c(o.slice(h))]},r=c(t.slice(0,n+1)),a=c([...t.slice(n),t[0]]),s=[...r.slice(0,-1),...a.slice(0,-1)],i=[];for(let o=0;o<s.length;o++){let l=s[(o-1+s.length)%s.length],h=s[(o+1)%s.length];Z2(s[o],l,h)>e&&i.push(s[o])}return i.length>=3?i:s}function O8(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=W3(a,.002),i=s.length,o=s.findIndex((u,f)=>F1(u,s[(f+1)%i])>=.5);if(i<4||o<0)continue;let l=H1(a)>0,h=[];for(let u=1;u<=i;u++){let f=(o+u)%i,d=s[f],p=s[(f+1)%i];if(F1(d,p)<.3){h.length||h.push(d),h.push(p);continue}if(h.length>=3){let m=H4(h),[g,v,y]=[h[0],h[1],h[h.length-1]],b=(v[0]-g[0])*(y[1]-g[1])-(v[1]-g[1])*(y[0]-g[0]);m&&m.r>.005&&m.r<.6&&(b>0===l?e:n).push(m.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let c=e[Math.floor(e.length/2)],r=a=>Math.abs(a-c)<=Math.max(.005,c*.1);if(!(c>.2||n.filter(r).length>e.length*.2))return e.filter(r).length>=e.length*.8?c:void 0}function m6(t,e){let n=t.length,c=i=>F1(t[i],t[(i+1)%n])<e*1.5,r=t.findIndex((i,o)=>!c(o));if(r<0)return t;let a=[],s=r;do{let i=(s+1)%n;for(;c(i)&&i!==s;)i=(i+1)%n;let o=(i-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[i],f=t[(i+1)%n],d;if(o>0){let p=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(p)>1e-12){let m=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/p,g=[l[0]+m*(h[0]-l[0]),l[1]+m*(h[1]-l[1])],v=t[(s+1+Math.floor(o/2))%n],y=[];for(let M=1;M<=o+1;M++)y.push(t[(s+M)%n]);let b=y.length>=3?H4(y):{c:g,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&F1(g,v)<=e*2&&m>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let p=1;p<=o;p++)a.push(t[(s+p)%n]);s=i}while(s!==r);return a}function T1(t){for(let c of[0,1,2]){let r=10**c,a=Math.round(t*r)/r;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var S1=t=>String(T1(t)),n0=t=>`[${S1(t[0])}, ${S1(t[1])}]`;function Gi(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function z2(t,e,n){let c=[];(T1(t[0])!==0||T1(t[1])!==0)&&c.push(`translate(${n0(t)})`);let r=Gi(e);return r!==0&&c.push(`rotate(${r})`),[...c,n].join(" ")}function V5(t,e){return{poly:t,area:Math.abs(H1(t)),box:S0([t]),ends:e?.segs.map(n=>n.a)}}var V4=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function O4(t,e){let n=w2(t.poly),c=O2(t.poly,!0,Math.min(.5,n/256)),r=H4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:c);if(!r||r.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,r.r*3e-4));for(let i of t.poly)if(Math.abs(F1(i,r.c)-r.r)>a)return;let s=a+r.r*2e-4;for(let i of c)if(Math.abs(F1(i,r.c)-r.r)>s)return;if(!(Math.abs(t.area-Math.PI*r.r*r.r)>n*a*2))return{kind:"circle",body:`circle(d = ${S1(r.r*2)})`,at:r.c,angle:0,center:r.c,circle:r,radius:r.r}}function R8(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 R4(t,e){let n=w2(t.poly),c=O2(t.poly,!0,Math.min(.5,n/256)),r=R8(c),a=c.map(m=>u2(m,-r)),[s,i,o,l]=S0([a]),h=(o-s)/2,u=(l-i)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+o)/2,(i+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[m,g]of a){let v=Math.hypot((m-f[0])/h,(g-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let p=u2(f,r);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${n0([h,u])})`,at:p,angle:r,center:p}}function F8(t){let e=0,n=0;for(let c=0;c<t.length;c++){let r=t[c],a=t[(c+1)%t.length],s=F1(r,a);s>e&&(e=s,n=Math.atan2(a[1]-r[1],a[0]-r[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function F4(t,e){let n=W3(t.poly,e/4),c=F8(n),r=w2(t.poly),a=O2(t.poly,!0,Math.min(.5,r/256)).map(y=>u2(y,-c)),[s,i,o,l]=S0([a]),h=o-s,u=l-i;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,i],[o,i],[o,l],[s,l]].map(y=>Math.min(...a.map(b=>F1(b,y)))*f),p=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;p<e&&(p=0),p=Math.min(p,h/2,u/2);let m=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-m[0])-(h/2-p),M=Math.abs(b-m[1])-(u/2-p),w=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-p;if(Math.abs(w)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*p*p))>r*e)return;let g=u2(m,c),v=T1(p)>0?`, r = ${S1(p)}`:"";return{kind:"rect",radius:p,body:`rect(${n0([h,u])}, center = true${v})`,at:g,angle:c,center:g,rect:{w:h,h:u,r:p}}}function $4(t,e){let n=W3(t.poly,e/4),c=n.length;if(c<3||c>48)return;let r=0,a=0;for(let[u,f]of n)r+=u/c,a+=f/c;let s=[r,a],i=n.map(u=>F1(u,s)),o=n.map((u,f)=>F1(u,n[(f+1)%c])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-r)*180/Math.PI);if(l(o)<=e&&l(i)<=e&&c<=24){let u=i.reduce((p,m)=>p+m,0)/c,f=360/c,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${c}, ${S1(u)})`,at:s,angle:d,center:s}}if(c%2===0&&c>=4&&l(o)<=e){let u=i.filter((x,M)=>M%2===0),f=i.filter((x,M)=>M%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,M)=>x+M,0)/u.length,p=f.reduce((x,M)=>x+M,0)/f.length,m=h[0];if(p>d&&([d,p]=[p,d],m=h[1]),d-p<e)return;let g=c/2,v=360/g,y=((m-90)%v+v)%v;v-y<.01&&(y=0);let b=T1(p)===T1(d*.45);return{kind:"star",body:`star(${g}, ${S1(d)}${b?"":`, ${S1(p)}`})`,at:s,angle:y,center:s}}}function ji(t,e,n){let[c,r,a,s]=e,i=[[],[],[],[]],o=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let p=f[1];Math.abs(p-r)<=n?i[0].push(E4(f[0]-c,d[0]-c)):Math.abs(p-s)<=n?i[2].push(E4(a-f[0],a-d[0])):(o[0].push(p-r),o[2].push(s-p))}else{let p=f[0];Math.abs(p-a)<=n?i[1].push(E4(f[1]-r,d[1]-r)):Math.abs(p-c)<=n?i[3].push(E4(s-f[1],s-d[1])):(o[1].push(a-p),o[3].push(p-c))}}let l=[a-c,s-r,a-c,s-r],h=o.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:i.map(u=>Wi(u,n)),depth:h,length:l}}var E4=(t,e)=>t<e?[t,e]:[e,t];function Wi(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 d6=t=>t.reduce((e,[n,c])=>e+c-n,0);function Xi(t,e,n,c,r,a){let s=[V4(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(V4(d-r[h]/2,-a,d+r[h]/2,0).map(i[h]))}}),x1(s)}function g6(t,e,n){let c=W3(t.poly,e/4);if(c.length<8)return;let r=F8(c),a=c.map(E=>u2(E,-r)),s=e/2;for(let E=0;E<a.length;E++){let $=a[E],X=a[(E+1)%a.length];if(Math.abs($[0]-X[0])>s&&Math.abs($[1]-X[1])>s)return}let i=S0([a]),o=ji(a,i,s),l=(E,$)=>E.map(X=>X.map(j=>p6(j,$))),h=(E,$)=>d3([a],l(E,$),e),u=(E,$,X)=>{let j=u2(E,r);return{kind:"tabs",body:$,at:j,angle:r,center:u2([(i[0]+i[2])/2,(i[1]+i[3])/2],r),...X}},f=w2(t.poly),d=[0,1,2,3].filter(E=>d6(o.outer[E])<o.length[E]-s);if(!d.length)return;let p=d.map(E=>o.depth[E]).filter(E=>E!==void 0);if(!p.length)return;let m=[...new Set([n,...p].filter(E=>!!E).map(T1))];for(let E of m){let $=T1(i[2]-i[0]),X=T1(i[3]-i[1]),j=[[]];for(let U=0;U<4;U++){let Q=d6(o.outer[U])>=o.length[U]-2*E-s?["flat"]:["out","in"],L1=[];for(let Y1 of j)for(let G1 of Q)L1.push([...Y1,G1]);j.splice(0,j.length,...L1)}let w1=Math.max(3*E,6),W1=new Set([w1]);for(let U of d){let i1=o.outer[U].length;for(let Q of[2*i1-1,2*i1+1,2*i1-3,2*i1+3])Q>=3&&W1.add(T1(o.length[U]/Q))}for(let U of W1)for(let i1 of j){if(i1.every(A1=>A1==="flat"))continue;let Q=i4($,X,i1,E,U);if(Math.abs(Math.abs(Q.reduce((A1,_1)=>A1+H1(_1),0))-t.area)>f*e||!h(Q,[i[0],i[1]]))continue;let Y1=i1.every(A1=>A1===i1[0])?`"${i1[0]}"`:`[${i1.map(A1=>`"${A1}"`).join(", ")}]`,G1=U===w1||[0,1].every(A1=>c3(o.length[A1],U)===c3(o.length[A1],w1));return u([i[0],i[1]],`finger_rect(${n0([$,X])}, ${Y1}${G1?"":`, finger = ${S1(U)}`})`,{kind:"fingers",thickness:E,edges:i1,finger:G1?w1:U})}let E1=[0,1,2,3].map(U=>d.includes(U)&&o.depth[U]!==void 0&&Math.abs(o.depth[U]-E)<=s);if(!E1.some(Boolean))continue;let Z1=i[0]+(E1[3]?E:0),p0=i[1]+(E1[0]?E:0),o0=T1(i[2]-(E1[1]?E:0)-Z1),A=T1(i[3]-(E1[2]?E:0)-p0),F=[o0,A,o0,A],t1=[E1[3]?E:0,E1[0]?E:0,E1[1]?E:0,E1[2]?E:0],a1=[0,0,0,0],y1=[0,0,0,0],P=!0;for(let U=0;U<4&&P;U++){if(!E1[U])continue;let i1=o.outer[U].map(([Q,L1])=>[Q-t1[U],L1-t1[U]]);a1[U]=i1.length,y1[U]=i1.length?T1(i1.reduce((Q,[L1,Y1])=>Q+Y1-L1,0)/i1.length):0,i1.forEach(([Q,L1],Y1)=>{(Math.abs((Q+L1)/2-F[U]*(Y1+.5)/a1[U])>s||Math.abs(L1-Q-y1[U])>s)&&(P=!1)})}if(!P||!h(Xi(o0,A,E1,a1,y1,E),[Z1,p0]))continue;let Y=E1.every(Boolean)?"":`[${E1.join(", ")}]`,W=[0,1,2,3].filter(U=>E1[U]),b1=U=>Math.max(1,Math.round(F[U]/50)),s1=W.every(U=>a1[U]===b1(U)),$1=W.every(U=>a1[U]===a1[W[0]]),e1=s1?void 0:$1?a1[W[0]]:null,I1=W.every(U=>Math.abs(y1[U]-F[U]/(2*a1[U]))<=s),r0=W.every(U=>Math.abs(y1[U]-y1[W[0]])<=s),C=I1?void 0:r0?y1[W[0]]:null,_;if(e1!==null&&C!==null){let U=[n0([o0,A])];Y?U.push(Y):(e1!==void 0||C!==void 0)&&U.push("true"),e1!==void 0&&U.push(`count = ${e1}`),C!==void 0&&U.push(`width = ${S1(C)}`),_=`tab_rect(${U.join(", ")})`}else{let U=[Q=>Q,Q=>`translate(${n0([o0,0])}) rotate(90) ${Q}`,Q=>`translate(${n0([o0,A])}) rotate(180) ${Q}`,Q=>`translate(${n0([0,A])}) rotate(270) ${Q}`],i1=[`rect(${n0([o0,A])});`];for(let Q of W){let L1=[S1(F[Q])];a1[Q]!==b1(Q)&&L1.push(`count = ${a1[Q]}`),Math.abs(y1[Q]-F[Q]/(2*a1[Q]))>s&&L1.push(`width = ${S1(y1[Q])}`),i1.push(U[Q](`tabs(${L1.join(", ")});`))}_=`{
|
|
2611
|
-
${
|
|
2688
|
+
`}var zo={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function on(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 zo[r]??e[r]??n})}function ln(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+=on(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]]=on(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 u2={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"}},V6={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"},So=Object.fromEntries(Object.entries(V6).reverse().map(([t,e])=>[e,t]));function U5(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(V6[t])return V6[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 e5=(t,e)=>q3(t,Math.PI/12,e),B5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function Lo(t){let e=Se;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let c=B5(r),a=(c[0]??0)*Math.PI/180,s=Se;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=I3(e,s)}return e}function Ao(t,e){let n=[],r=[],c=[0,0],a=[0,0],s=(l,h)=>v5(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 Co=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],Po=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function hn(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 Eo(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let c=hn(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 To(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 I6(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])*To(n[2].toLowerCase(),e)}var Io=/^(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 Vo(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Io.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Ho(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return u2.score;if(/engrav|raster|etch/.test(e))return u2.engrave;if(/\bguide/.test(e))return u2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return u2.cut}function un(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=ln(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=B5(r.attrs.viewBox??""),o=I6(r.attrs.width,s),l=I6(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=I3([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(...Eo(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))Po.has(r1)&&(G[r1]=n1[r1]);for(let r1 of Co)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,hn(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&&B5(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 e5(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?e5(`M${G} ${k1}H${G+r1}V${k1+U1}H${G}Z`):e5(`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?[]:e5(`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 e5(`M${n1("x1")} ${n1("y1")}L${n1("x2")} ${n1("y2")}`);case"polyline":case"polygon":{let G=B5(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 e5(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=I3(n1,Lo(V.attrs.transform));if(!V1.every(Number.isFinite)){A++;return}let o0=Vo(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=Ho(A1);if(V.attrs["data-mode"]&&A1&&/^(cut|line|fill|guide)$/.test(V.attrs["data-mode"])){let v1=U5(c1.stroke,"#000000"),y1=U5(c1.fill,"#000000"),T1=V.attrs["data-mode"]==="fill"?y1:v1;I=u2[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=I3(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=I3(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=U5(c1.color,"#000000")??"#000000",a1=parseFloat(c1["stroke-width"]??"1"),J=U5(c1.stroke,N);J&&(a1===0||c1["stroke-opacity"]==="0")&&(J="none");let x1=U5(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=>B5(V.attrs[J1]??l0?.attrs[J1]??"0")[0]??0,v1=v5(V1,[m1("x"),m1("y")]),y1=Math.sqrt(Math.abs(V1[0]*V1[3]-V1[1]*V1[2])),T1=(I6(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=Ao(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 u2.cut;if(G==="#00a0ff")return u2.guide;if(Q(G))return u2.score;if(!D.has(G)){let k1=So[G]??"color_"+G.slice(1);D.set(G,{name:k1,mode:"line",color:G})}return D.get(G)}if(n1&&n1!=="none")return E?u2.engrave:u2.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===u2.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?u2.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]},O6=(t,e)=>[t[0]+e[0],t[1]+e[1]],M2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function M3(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 x3=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(dn(s,i,m,g)<=r)return!0}return!1}};function dn(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 Oo(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)&&dn(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 mn(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||Oo(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new x3([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 w3(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let c=Math.max(n*2,.2),a=new x3(t,r,Math.max(n*4,1)),s=new x3(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 pn(t,e,n){let r=new x3([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 gn(t,e,n){if(!t.length)return!1;let r=new x3([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 Z4(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 t5(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 vn(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=t5(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=Z4(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 F6(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?Z4(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 Fo(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=Fo(e);return c!==0&&r.push(`rotate(${c})`),[...r,n].join(" ")}function _5(t,e){return{poly:t,area:Math.abs(M1(t)),box:z0([t]),ends:e?.segs.map(n=>n.a)}}var X4=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function Y4(t,e){let n=I2(t.poly),r=_2(t.poly,!0,Math.min(.5,n/256)),c=Z4(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 yn(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 J4(t,e){let n=I2(t.poly),r=_2(t.poly,!0,Math.min(.5,n/256)),c=yn(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 bn(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 K4(t,e){let n=t5(t.poly,e/4),r=bn(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 Q4(t,e){let n=t5(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 Ro(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(G4(f[0]-r,d[0]-r)):Math.abs(m-s)<=n?i[2].push(G4(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(G4(f[1]-c,d[1]-c)):Math.abs(m-r)<=n?i[3].push(G4(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=>$o(u,n)),depth:h,length:l}}var G4=(t,e)=>t<e?[t,e]:[e,t];function $o(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 H6=t=>t.reduce((e,[n,r])=>e+r-n,0);function Do(t,e,n,r,c,a){let s=[X4(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(X4(d-c[h]/2,-a,d+c[h]/2,0).map(i[h]))}}),i1(s)}function R6(t,e,n){let r=t5(t.poly,e/4);if(r.length<8)return;let c=bn(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=Ro(a,i,s),l=(H,U)=>H.map(Y=>Y.map(Q=>O6(Q,U))),h=(H,U)=>w3([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=>H6(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=H6(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=w4(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(Do(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(`
|
|
2612
2691
|
`)}
|
|
2613
|
-
}`}return u([
|
|
2614
|
-
${[`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)&&H6(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])=>X4(H,U,H+Y,U+Q),C=i1([X4(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(`
|
|
2615
2694
|
`)}
|
|
2616
|
-
}`:`rect(${
|
|
2617
|
-
${[
|
|
2695
|
+
}`:`rect(${s0([x,M])})`,X=T.length?`difference() {
|
|
2696
|
+
${[B.endsWith("}")?B:B+";",...T].join(`
|
|
2618
2697
|
`)}
|
|
2619
|
-
}`:J,Z=d.map(E=>T1(g[E])),p1=Z.sort((E,$)=>Z.filter(X=>X===$).length-Z.filter(X=>X===E).length)[0];return u([y,b],o1,{kind:V.length?"fingers":"tabs",thickness:p1,generic:!0,label:`${V.length?"finger joints":"tabs"} ${S1(p1)} mm deep`})}function Zi(t){let[e,n,c,r]=S0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,Z2(h,t[d],t[f]));return u},s=[(e+c)/2,(n+r)/2],i=H2(s,t)?a(s):0,o=24;for(let h=0;h<=o;h++)for(let u=0;u<=o;u++){let f=[e+(c-e)*h/o,n+(r-n)*u/o];if(!H2(f,t))continue;let d=a(f);d>i&&(s=f,i=d)}let l=Math.max(c-e,r-n)/o;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!H2(d,t))continue;let p=a(d);p>i&&(s=d,i=p,h=!0)}h||(l/=2)}return{c:s,r:i}}function Yi(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 $8(t,e){let[n,c,r,a]=t.box;if(Math.max(r-n,a-c)>80)return;let s=w2(t.poly),i=O2(t.poly,!0,Math.min(.25,s/400)),o=Zi(t.poly),l=i.filter(V=>Math.abs(F1(V,o.c)-o.r)<=e),h=H4(l);if(!h||l.length<8)return;let u=i[0];for(let V of i)F1(V,h.c)>F1(u,h.c)&&(u=V);let f=F1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],p=V=>(V[0]-h.c[0])*d[0]+(V[1]-h.c[1])*d[1],m=V=>-(V[0]-h.c[0])*d[1]+(V[1]-h.c[1])*d[0],g=i.filter(V=>p(V)>h.r+e&&p(V)<f-h.r);if(g.length<4)return;let v=[g.filter(V=>m(V)>0),g.filter(V=>m(V)<0)];if(v.some(V=>V.length<2))return;let y=v.map(V=>u2([1,0],R8(V))).map(V=>V[0]*d[0]+V[1]*d[1]<0?[-V[0],-V[1]]:V),b=[y[0][0]+y[1][0],y[0][1]+y[1][1]],x=Math.hypot(b[0],b[1]);if(d=[b[0]/x,b[1]/x],g=i.filter(V=>p(V)>h.r+e&&p(V)<f-h.r),g.length<4||Math.abs(g.reduce((V,J)=>V+m(J),0)/g.length)>e)return;let M=g.map(V=>Math.abs(m(V))).sort((V,J)=>V-J),w=M[Math.floor(M.length/2)]*2;if(w>=h.r*2-e||w<.3)return;let k=Math.max(...i.map(p)),z=p6(h.c,[d[0]*(k-w/2),d[1]*(k-w/2)]),S=x1([S3(h.r,h.r,256).map(V=>p6(V,h.c)),Yi(h.c,z,w/2)]);if(!d3([t.poly],S,e))return;let L=k-w/2,I=h.r*2,q=Math.atan2(d[1],d[0])*180/Math.PI-90,R=[];T1(I)!==9&&R.push(`head = ${S1(I)}`),T1(w)!==4.5&&R.push(`shank = ${S1(w)}`),T1(L)!==10&&R.push(`drop = ${S1(L)}`);let N=L>=(I+w)/2-1e-9,G=N?`keyhole(${R.join(", ")})`:`{ translate(${n0([0,-L])}) circle(d = ${S1(I)}); hull() { circle(d = ${S1(w)}); translate(${n0([0,-L])}) circle(d = ${S1(w)}); } }`;return{kind:"keyhole",radius:I/2,body:G,at:z,angle:q,center:z,label:"keyhole",keyhole:{head:I,shank:w,drop:L,top:z},library:N?"hanging":void 0}}var T8=.0025,I4=(t,e)=>Math.abs(t[0]-e[0])>T8||Math.abs(t[1]-e[1])>T8;function X3(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))I4(a,c[c.length-1])&&c.push(a);!t.closed&&c.length<2&&c.push(n[n.length-1]);let r=`[${c.map(a=>n0(f2(a,e))).join(", ")}]`;return t.closed?`polygon(${r})`:c.length===2?`line(${n0(f2(c[0],e))}, ${n0(f2(c[1],e))})`:`polyline(${r})`}return`path("${v6([t],e)}")`}function v6(t,e){let n=c=>`${S1(c[0]-e[0])} ${S1(c[1]-e[1])}`;return t.map(c=>{let r=`M${n(c.segs[0].a)}`,a=c.segs[0].a;for(let s of c.segs)!I4(s.b,a)&&(s.c==="L"||!I4(s.p1,a)&&!I4(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 D8(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 Z3=t=>t.segs[0].a,q8=t=>t.segs[t.segs.length-1].b;function Ji(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[Z3(s),q8(s)]){let l=c(o);r.set(l,[...r.get(l)??[],i])}});let a=s=>{let[i,o]=[Math.round(s[0]/V0),Math.round(s[1]/V0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of r.get(`${i+l},${o+h}`)??[])if(!e.has(u)&&(F1(Z3(t[u]),s)<=V0||F1(q8(t[u]),s)<=V0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let i=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=i[i.length-1].b;if(F1(h,i[0].a)<=V0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=F1(Z3(t[u]),h)<=V0?t[u]:D8(t[u]);i=i.concat(f.segs)}i=D8({segs:i,closed:!1}).segs}let o=i.length>1&&F1(i[i.length-1].b,i[0].a)<=V0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var U8=.05;function Ki(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 B8(t,e={}){let n=e.tolerance??U8,c=typeof t=="string"?t:Ki(t),r=P8(c,{dpi:e.dpi}),a=[...r.notes],s={},i=(A,F=1)=>s[A]=(s[A]??0)+F,o=[],l=[],h=new Map;for(let A of r.items)if(A.layer.mode==="cut")for(let F of A.subs)F.closed?o.push({sub:F,names:A.names,group:A.filled?A:void 0}):(l.push(F),h.set(F,A.names));let u=Ji(l);l=[];for(let{sub:A,from:F}of u)A.closed?o.push({sub:A,names:h.get(F)??[],line:{segs:A.segs,closed:!1}}):l.push(A);let f=o.map(A=>({...A,outline:V5(f3(A.sub),A.sub)})),d=f.filter(A=>A.outline.poly.length>=3&&A.outline.area>w2(A.outline.poly)*V0);for(let A of f)d.includes(A)||l.push(A.line??{segs:A.sub.segs,closed:!1});let p=(A,F,t1,a1)=>{if(t1!==a1)return!1;let[y1,P,Y,W]=A.box,[b1,s1,$1,e1]=F.box;if(y1<b1-V0||P<s1-V0||Y>$1+V0||W>e1+V0)return!1;let I1=A.poly.length;return[0,Math.floor(I1/3),Math.floor(2*I1/3)].filter(C=>H2(A.poly[C],F.poly)).length>=2},m=A=>{let F=d.map((y1,P)=>P).filter(y1=>!A.has(y1)).sort((y1,P)=>d[P].outline.area-d[y1].outline.area),t1=new Map,a1=new Map;return F.forEach((y1,P)=>{let Y=-1;for(let W=P-1;W>=0;W--){let b1=F[W];if(d[b1].outline.area>d[y1].outline.area&&p(d[y1].outline,d[b1].outline,d[y1].group,d[b1].group)){Y=b1;break}}t1.set(y1,Y),a1.set(y1,Y<0?0:a1.get(Y)+1)}),{order:F,parent:t1,depth:a1}},g=I8(d.map(A=>A.outline.poly),V0*2),v=m(new Set),{parent:y,depth:b}=v,x=A=>b.get(A)%2===0?A:y.get(A),M=new Set(d.map((A,F)=>F).filter(A=>g.self[A]));for(let[A,F]of g.pairs)x(A)===x(F)&&M.add(A).add(F);for(let A of v.order)b.get(A)%2===1&&M.has(y.get(A))&&M.add(A);for(let A of M)l.push(d[A].line??{segs:d[A].sub.segs,closed:!1});M.size&&a.push(`${M.size} outline${M.size===1?" touches or crosses":"s touch or cross"} a hole or ${M.size===1?"itself":"themselves"}, so ${M.size===1?"it is":"they are"} kept as cut lines.`);let w=[],k=new Map;for(let A of v.order){if(M.has(A))continue;let F=d[A];if(b.get(A)%2===0){let t1={sub:F.sub,outline:F.outline,names:F.names,holes:[],lines:[],marks:new Map,texts:[]};w.push(t1),k.set(A,t1)}else k.get(y.get(A)).holes.push({sub:F.sub,outline:F.outline,line:F.line})}let z=e.kerf!==void 0?e.kerf/2:O8(w.map(A=>A.outline.poly)),S=0;if(z&&z>0){let A=F=>({closed:!0,segs:F.map((t1,a1)=>({c:"L",a:t1,b:F[(a1+1)%F.length]}))});for(let F of w){let t1=b0([m6(F.outline.poly,z)],F.holes.map(e1=>m6(e1.outline.poly,z))),a1=_0(m0(t1,-z,"miter")),y1=m0(a1.flat(),z,"round",Math.min(.01,z/10)),P=b0([F.outline.poly],F.holes.map(e1=>e1.outline.poly)),Y=e1=>Math.abs(H1(e1))<=w2(e1)*V0;if(a1.length!==1||a1[0].length!==F.holes.length+1||a1[0].some(Y)||!d3(y1,P,n)){F.noKerf=!0;continue}F.drawn=[F.sub,...F.holes.map(e1=>e1.sub)];let[W,...b1]=a1[0].map(e1=>W3(e1,.001));F.outline=V5(W),F.sub=A(W);let s1=e1=>[(e1.box[0]+e1.box[2])/2,(e1.box[1]+e1.box[3])/2],$1=b1.map(e1=>V5(e1));for(let e1 of F.holes){let I1=s1(e1.outline),r0=$1.reduce((C,_)=>F1(s1(_),I1)<F1(s1(C),I1)?_:C);$1.splice($1.indexOf(r0),1),e1.outline=r0,e1.sub=A(r0.poly),e1.line=void 0}}S=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${S1(S)} mm kerf: they are moved back, and $kerf is set.`)}let L=A=>{let F;for(let t1 of w){let[a1,y1,P,Y]=t1.outline.box;A[0]<a1||A[0]>P||A[1]<y1||A[1]>Y||H2(A,t1.outline.poly)&&(!F||t1.outline.area<F.outline.area)&&(F=t1)}return F},I={lines:[],marks:new Map,texts:[]},q=new Map,R=A=>{let F=L(Z3(A));if(!F)return;let t1=q.get(F);return t1||(t1=V8(F.outline.poly,F.holes.map(a1=>a1.outline.poly),n),q.set(F,t1)),t1(f3(A,.02),A.closed)?F:void 0};for(let A of l){let F=R(A);(F?F.lines:I.lines).push(A)}for(let A of r.items)if(A.layer.mode!=="cut")for(let F of A.subs){let t1=(R(F)??I).marks;t1.set(A,[...t1.get(A)??[],F])}for(let A of r.texts)(L(A.at)??I).texts.push(A);r.texts.some(A=>A.layer.mode==="cut")&&a.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let A of w){let F=A.lines.map(t1=>f3(t1));A.holes=A.holes.filter(t1=>{if(!t1.line)return!0;let a1=P=>H2(P,t1.outline.poly),y1=H8(F,t1.outline.poly,V0*2)||A.lines.some(P=>a1(Z3(P)))||[...A.marks.values()].some(P=>P.some(Y=>a1(Z3(Y))))||A.texts.some(P=>a1(P.at))||w.some(P=>P!==A&&P.outline.area<t1.outline.area&&a1(P.outline.poly[0]));return y1&&A.lines.push(t1.line),!y1})}let N=A=>O4(A,n)??F4(A,n)??R4(A,n)??$4(A,n)??$8(A,n),G=new Map;for(let A of w){let F=O4(A.outline,n)??F4(A.outline,n)??R4(A.outline,n)??$4(A.outline,n)??g6(A.outline,n);G.set(A,F);for(let t1 of A.holes)t1.found=N(t1.outline)}let V=new Map,J=[...G.values()].some(A=>A?.thickness&&!A.generic);for(let A of G.values())A?.thickness&&A.thickness<=10&&(!J||!A.generic)&&V.set(A.thickness,(V.get(A.thickness)??0)+1);let o1=[...V.entries()].sort((A,F)=>F[1]-A[1])[0]?.[0];if(o1!==void 0)for(let A of w){let F=G.get(A);if(F?.thickness!==void 0&&F.thickness!==o1){let t1=g6(A.outline,n,o1);t1&&t1.thickness===o1&&G.set(A,t1)}}let Z=new Set;for(let A of G.values())A?.kind==="fingers"&&A.finger&&Z.add(T1(A.finger));w.sort((A,F)=>{let t1=F.outline.box[3]-A.outline.box[3];return Math.abs(t1)>1?t1:A.outline.box[0]-F.outline.box[0]});let p1=new Set,E=new Map,$=[];for(let[A,F]of w.entries()){let t1=F.names[0]??`part ${A+1}`,a1=(E.get(t1)??0)+1;E.set(t1,a1);let y1=a1>1?`${t1} ${a1}`:t1,P;for(let r0 of[2,1,0]){let C=eo(F,G.get(F),r0,o1,Z,n);if(co(C,F,n)){P=C,r0<2&&a.push(r0===1?`Part "${y1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${y1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!P){let r0=F.drawn??[F.sub,...F.holes.map(C=>C.sub)];I.lines.push(...r0.map(C=>({segs:C.segs,closed:!1})),...F.lines);for(let[C,_]of F.marks)I.marks.set(C,[...I.marks.get(C)??[],..._]);I.texts.push(...F.texts),a.push(`Part "${y1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let r0 of P.found)i(r0);for(let r0 of P.libraries)p1.add(r0);let Y=N8(F.marks,[],F.texts,P.origin),W=[...P.cut,...Y],b1=P.thickness,s1=[...b1!==void 0&&(o1===void 0||T1(b1)!==T1(o1))?[`thickness = ${S1(b1)}`]:[],...F.noKerf&&S>0?["kerf = 0"]:[]],$1=s1.length?`material(${s1.join(", ")}) `:"",e1=`part("${y1.replace(/["\\]/g,"")}")`,I1=W.length===1&&!W[0].includes(`
|
|
2620
|
-
`)?`${
|
|
2621
|
-
${
|
|
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 qo(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 No(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 xn(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=qo(t.poly),l=i.filter(T=>Math.abs(N1(T,o.c)-o.r)<=e),h=Z4(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],yn(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=O6(h.c,[d[0]*(k-w/2),d[1]*(k-w/2)]),S=i1([V3(h.r,h.r,256).map(T=>O6(T,h.c)),No(h.c,z,w/2)]);if(!w3([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 fn=.0025,W4=(t,e)=>Math.abs(t[0]-e[0])>fn||Math.abs(t[1]-e[1])>fn;function n5(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))W4(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("${$6([t],e)}")`}function $6(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)!W4(s.b,a)&&(s.c==="L"||!W4(s.p1,a)&&!W4(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 Mn(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 r5=t=>t.segs[0].a,wn=t=>t.segs[t.segs.length-1].b;function Uo(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[r5(s),wn(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(r5(t[u]),s)<=D0||N1(wn(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(r5(t[u]),h)<=D0?t[u]:Mn(t[u]);i=i.concat(f.segs)}i=Mn({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 zn=.05;function Bo(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 Sn(t,e={}){let n=e.tolerance??zn,r=typeof t=="string"?t:Bo(t),c=un(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=Uo(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:_5(M3(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=mn(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:vn(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([F6(D.outline.poly,z)],D.holes.map(c1=>F6(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)||!w3(t1,V,n)){D.noKerf=!0;continue}D.drawn=[D.sub,...D.holes.map(c1=>c1.sub)];let[G,...k1]=u1[0].map(c1=>t5(c1,.001));D.outline=_5(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=>_5(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(r5(E));if(!D)return;let e1=C.get(D);return e1||(e1=pn(D.outline.poly,D.holes.map(u1=>u1.outline.poly),n),C.set(D,e1)),e1(M3(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=>M3(e1));E.holes=E.holes.filter(e1=>{if(!e1.line)return!0;let u1=V=>B2(V,e1.outline.poly),t1=gn(D,e1.outline.poly,D0*2)||E.lines.some(V=>u1(r5(V)))||[...E.marks.values()].some(V=>V.some(n1=>u1(r5(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=>Y4(E,n)??K4(E,n)??J4(E,n)??Q4(E,n)??xn(E,n),q=new Map;for(let E of w){let D=Y4(E.outline,n)??K4(E.outline,n)??J4(E.outline,n)??Q4(E.outline,n)??R6(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=R6(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=jo(D,q.get(D),o0,X,Z,n);if(Xo(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=kn(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(`
|
|
2622
2701
|
`)}
|
|
2623
|
-
}
|
|
2624
|
-
`),
|
|
2625
|
-
`),
|
|
2702
|
+
}`;U.push({name:t1,code:V2(V.origin,0,V1),local:V1,thickness:k1})}let Y=kn(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?"":_o[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(`
|
|
2626
2705
|
|
|
2627
|
-
`),
|
|
2706
|
+
`),Y.join(`
|
|
2628
2707
|
`)].filter(Boolean).join(`
|
|
2629
2708
|
|
|
2630
2709
|
`).replace(/\n{3,}/g,`
|
|
2631
2710
|
|
|
2632
2711
|
`)+`
|
|
2633
|
-
`;try{
|
|
2634
|
-
${[x,...d].map(
|
|
2712
|
+
`;try{D1=_4(D1)}catch{}return{source:D1,parts:U.length,found:s,summary:F1,notes:a}}var _o={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},j5=t=>t.trimEnd().endsWith("}")?t:t+";";function jo(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(D6[o.kind]),o.library&&i.add(o.library)):(h=[H1(l[0]),H1(l[1])],u=n5(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 Go(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=Wo(C.map(R=>m(R.found.at)),a);if(P){d.push(`${P} ${L}`);for(let R of C)s.push(D6[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(D6[A.found.kind]),A.found.library&&i.add(A.found.library));for(let A of b)d.push(n5(A.sub,h)),s.push("outline");let x=g(u),M=d.length?[`difference() {
|
|
2713
|
+
${[x,...d].map(j5).join(`
|
|
2635
2714
|
`)}
|
|
2636
|
-
}`]:[
|
|
2715
|
+
}`]:[j5(x)],w=t.lines.map(A=>j5(n5(A,h))),k=e?.thickness??r,z=[...[...i].map(A=>`use <kerf/${A}>`),`$thickness = ${k??3};`,`translate(${s0(h)}) {
|
|
2637
2716
|
${[...M,...w].join(`
|
|
2638
2717
|
`)}
|
|
2639
2718
|
}`].join(`
|
|
2640
|
-
`),S=Math.max(0,
|
|
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 D6={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function Go(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 Wo(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 kn(t,e,n,r){let c=[];for(let i of e)c.push(j5(n5(i,r)));let a=new Map,s=(i,o,l)=>{let h=i.name,u=a.get(h)??{layer:i,code:[]};u.code.push(j5(o)+(l?` // ${l}`:"")),a.set(h,u)};for(let[i,o]of t){let l=zn;if(o.length===1&&o[0].closed){let d=_5(M3(o[0]),o[0]),m=d.area>1e-6?Y4(d,l)??K4(d,l)??J4(d,l)??Q4(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,n5(d,r));continue}let h=$6(o,r),u=o.filter(d=>d.closed).map(d=>M3(d)),f=i.fillRule==="evenodd"||w3(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} {
|
|
2641
2720
|
${o.join(`
|
|
2642
2721
|
`)}
|
|
2643
|
-
}`)}return r}function co(t,e,n){let c;try{c=new U3({maxSteps:2e6}).run(e2(t.check).program).shape}catch{return!1}let r=c.layers.get("cut");if(!r)return!1;let a=b0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=x1(r.regions),i=n+t.round*16e-5;if(!d3(a,s,i))return!1;let o=e.lines.map(l=>f3(l));return!(o.length&&!d3(o,r.lines,i,!1))}var B=.001,J1=(t,e)=>t.reduce((n,c,r)=>n+c*e[r],0),m1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],M1=t=>Math.hypot(...t),j8=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]),b6=(t,e)=>O1(L0(t.matrix),e.matrix);function p3(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+p3(n),0)),x6=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 D4(t){let e=t.flat();return[Math.min(...e.map(n=>n[0])),Math.min(...e.map(n=>n[1])),Math.max(...e.map(n=>n[0])),Math.max(...e.map(n=>n[1]))]}var W8=([t,e,n,c])=>[[t,e],[n,e],[n,c],[t,c]];function M6(t){if(t.length!==1)return!1;let e=D4(t);return Y2(w3(t,[W8(e)]))<B*B}var w6=(t,e)=>x0(t,[W8(e)]);function X8(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 ro(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 Y3(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 Z8(t,e){let n=1/0;for(let c of t)for(let r=0;r<e.length;r++)n=Math.min(n,Y3(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,Y3(c,t[r],t[(r+1)%t.length]));return n}var z6=(t,e)=>t.filter(n=>p3(n)<0&&ro(n,e));function J3(t){return t.placed?t.bends.length?"Flexible or bent geometry is not supported by this rigid check.":t.cutLines===null?"Nominal cutting-line geometry is unavailable; render with analysis: true.":t.cutLines.length?"Open cutting lines may remove or weaken material; this rigid check cannot model them.":null:"The part has no physical placement."}function Y8(t){return[0,1,2,4,5,6,8,9,10].every(e=>Math.abs(t[e])<1e-9||Math.abs(Math.abs(t[e])-1)<1e-9)}function q4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&_8(t.regions)===_8(e.regions)&&G8(t.cutLines)===G8(e.cutLines)}function _8(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(p3(n)),r.sort()[0]])};return JSON.stringify(t.map(e).sort())}function G8(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),c=JSON.stringify([...e].reverse());return n<c?n:c}).sort())}var q1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),v0=t=>typeof t=="string"&&t.length>0,S2=t=>typeof t=="number"&&Number.isFinite(t),F2=t=>S2(t)&&t>=0,k2=t=>S2(t)&&t>0,m3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(S2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,v3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(S2),d2=t=>v3(t,3)&&t.every(e=>Math.abs(e)<=1e7),J2=t=>q1(t)&&v0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),N4=t=>q1(t)&&v0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),K3=t=>J2(t)||N4(t),R2=t=>Array.isArray(t)&&t.every(K3),g3=t=>d2(t)&&Math.hypot(...t)>1e-9,ao=t=>q1(t)&&(t.kind==="translate"&&d2(t.by)||t.kind==="rotate"&&d2(t.origin)&&g3(t.axis)&&S2(t.angle)&&Math.abs(t.angle)<=1e6),k6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),J8=t=>q1(t)&&Object.values(t).every(k6),Q8=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||S2(t)||Array.isArray(t)&&t.every(n=>Q8(n,e+1))),S6=t=>q1(t)&&Object.values(t).every(e=>Q8(e)),so=t=>t===null||q1(t)&&k6(t.sourceHash)&&k6(t.engineHash)&&J8(t.dependencies)&&J8(t.fonts);function O5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!q1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let c=(s,i,o)=>{for(let l of Object.keys(s))i.includes(l)||n(o?`${o}.${l}`:l,"Unknown specification field.")};c(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),v0(t.model)||n("model","Give the model a nonempty name.");let r=new Set,a=(s,i)=>{if(!q1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!q1(l)||!m3(l.thickness,Number.MIN_VALUE)||!m3(l.kerf)||l.edgeError!==void 0&&!F2(l.edgeError)||l.lot!==void 0&&!v0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),q1(l)&&c(l,["thickness","kerf","edgeError","lot"],`${i}.${o}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[s,i]of t.configurations.entries())!q1(i)||!v0(i.id)||i.params!==void 0&&!S6(i.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):r.has(i.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(r.add(i.id),c(i,["id","params","materials"],`configurations[${s}]`),i.materials!==void 0&&a(i.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,i=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!q1(h)||!v0(h.id)||!v0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(c(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),s.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),s.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&i++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(p=>typeof p=="string"&&r.has(p)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!J2(h.a)||!J2(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!k2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!J2(h.tab)||!J2(h.receiver)||!v3(h.region,4)||h.region.some(p=>Math.abs(p)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!m3(h.clearance)||!F2(h.flushTolerance)||!F2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let p=h.stops;if(!N4(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)||!k2(h.minimumOverlap)||!F2(h.maximumStopGap)||!Array.isArray(p)||p.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let m of p){if(!q1(m)||!N4(m.body)||!q1(m.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}c(m,["body","attachment"],u+".stops");let g=m.attachment;c(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!N4(g.thread)||!k2(g.minimumEngagement)||typeof g.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!F2(h.minimumGap)||h.bodies!==void 0&&(!R2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!v0(h.from)||!r.has(h.from)||!v0(h.to)||!r.has(h.to)||h.from===h.to||!F2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(p=>q1(p)&&K3(p.body)&&ao(p.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!v0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!R2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!R2(h.scope)||!h.scope.length)||!F2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(p=>q1(p)&&v0(p.id)&&K3(p.part)&&d2(p.from)&&typeof p.held=="boolean"&&(p.fasten===void 0||Array.isArray(p.fasten)&&p.fasten.every(v0))&&(p.tool===void 0||q1(p.tool)&&d2(p.tool.from)&&d2(p.tool.to)&&k2(p.tool.diameter)&&p.tool.diameter<=1e6&&d2(p.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!R2(h.roots)||!h.roots.length||h.removable!==void 0&&!R2(h.removable)||!Array.isArray(h.links)||!h.links.every(p=>q1(p)&&v0(p.claim)&&["glued","locked","captured"].includes(p.fastening)&&typeof p.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!R2(h.bodies)||!h.bodies.length||!R2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(p=>q1(p)&&K3(p.a)&&K3(p.b)&&(p.kind==="fixed"||p.kind==="revolute"&&d2(p.anchorA)&&d2(p.anchorB)&&g3(p.axisA)&&g3(p.axisB)&&(p.range===void 0||m3(p.range,-1e6))||p.kind==="prismatic"&&g3(p.axisA)&&m3(p.travel,-1e6)||p.kind==="gear"&&g3(p.axisA)&&g3(p.axisB)&&k2(p.ratio)&&p.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!R2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!S2(h.ground)||Math.abs(h.ground)>1e7||!g3(h.gravity)||h.gravity[2]>=0||!F2(h.minimumMargin)||!h.loads.every(p=>q1(p)&&K3(p.body)&&k2(p.mass)&&(p.center===void 0||d2(p.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!v0(h.plan)||!v0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(p=>q1(p)&&v0(p.step)&&R2(p.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(p,m,g)=>{q1(p)&&c(p,m,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[p,m]of h.moving.entries())q1(m)&&(d(m,["body","trajectory"],`${u}.moving[${p}]`),d(m.trajectory,q1(m.trajectory)&&m.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${p}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[p,m]of h.steps.entries())q1(m)&&(d(m,["id","part","from","held","fasten","tool"],`${u}.steps[${p}]`),d(m.tool,["from","to","diameter","travel"],`${u}.steps[${p}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[p,m]of h.joints.entries())q1(m)&&d(m,["kind","a","b",...m.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:m.kind==="prismatic"?["axisA","travel"]:m.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${p}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((p,m)=>d(p,["claim","fastening","installed"],`${u}.links[${m}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((p,m)=>d(p,["body","mass","center"],`${u}.loads[${m}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((p,m)=>d(p,["step","bodies"],`${u}.holds[${m}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(q1);for(let l of o){let h=(u,f)=>o.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=o.find(m=>m.id===l.plan&&m.kind==="assembly-access"),f=o.find(m=>m.id===l.retention&&m.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(q1).map(m=>m.id)),p=new Set((Array.isArray(f?.links)?f.links:[]).filter(q1).map(m=>m.claim));if(Array.isArray(l.holds))for(let m of l.holds)q1(m)&&!d.has(m.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(m.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let m of u.steps)if(q1(m)&&Array.isArray(m.fasten))for(let g of m.fasten)p.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(m.id)} fastens ${String(g)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(q1(f)){let d=q1(f.body)?f.body:{},p=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(p)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(p)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)q1(u)&&!o.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function L6(t){let e=[],n=(r,a)=>e.push({code:"invalid-snapshot",path:r,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let c=new Set;for(let[r,a]of t.entries()){let s=`snapshots[${r}]`;if(!q1(a)||a.schemaVersion!==1||!v0(a.configuration)||!S6(a.params)||!S6(a.renderSettings)||!so(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(o=>typeof o=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}c.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),c.add(a.configuration);let i=new Set;for(let[o,l]of a.parts.entries()){if(!q1(l)||!v0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!k2(l.thickness)||l.glue!==void 0&&(!J2(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!v0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!F2(l.kerf)||l.kerf>1e6)||!io(l.matrix)||typeof l.placed!="boolean"||!K8(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!K8(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>q1(u)&&S2(u.x0)&&S2(u.x1)&&u.x1>u.x0&&S2(u.angle))){n(`${s}.parts[${o}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);i.has(h)&&n(`${s}.parts[${o}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),i.add(h)}for(let[o,l]of a.hardware.entries())(!q1(l)||l.label!==null&&!v0(l.label)||typeof l.kind!="string"||!v3(l.from,3)||!v3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!d2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!k2(l.size))||!(k2(l.size)&&l.size<=1e6||v3(l.size,2)&&l.size.every(h=>k2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function K8(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(c=>v3(c,2)&&c.every(r=>Math.abs(r)<=1e6)))}function io(t){if(!v3(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 en(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 Y0=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),L2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var Q1=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),r1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),E6=(t,e,n=[],c="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:c}),F5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,R5=(t,e)=>F5(t,e)?.thickness??[e.thickness,e.thickness];function B4(t,e){let n=F5(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 P6=(t,e)=>t[0]>=e[0]+B&&t[1]<=e[1]-B,T6=(t,e)=>t[0]<e[0]-B||t[1]>e[1]+B,I6=(...t)=>t.map(J3).find(Boolean);function G4(t,e){let n=Y0(e,t.a),c=Y0(e,t.b);if(n===c)return Q1("A glue contact needs two different physical instances.");let r=I6(n,c);if(r)return r1(r);let a=b6(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 r1("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=X8(c.regions,a,i),f=Y2(x0(n.regions,u)),d=B*(x6(n.regions)+x6(u)),p={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?Q1("There is insufficient geometric glue contact.",p):f<t.minimumArea+d?{...r1("Contact area is on the numerical acceptance boundary."),measurements:p}:E6("The selected nominal faces have the required geometric contact.",p,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function tn(t,e,n){let c=Y0(e,t.tab),r=Y0(e,t.receiver);if(c===r)return Q1("A tongue and its receiving panel must be different instances.");let a=I6(c,r);if(a)return r1(a);let s=b6(r,c);if(!Y8(s)||Math.abs(s[10])>B)return r1("Only orthogonal tab/slot geometry is supported.");let i=w6(c.regions,t.region);if(!M6(i))return r1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=D4(i),f=4*B,d=B,m=[[o-f,l+d,o,u-d],[h,l+d,h+f,u-d],[o+d,l-f,h-d,l],[o+d,u,h-d,u+f]].map(V=>Y2(w6(c.regions,V))>B*B).flatMap((V,J)=>V?[J]:[]);if(m.length>1)return r1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(m.length&&Math.abs(m[0]<2?s[8]:s[9])<.5)return r1("The tongue must join its parent along the insertion direction.");let g;if(m.length){let V=m[0],J=V<2?[V===0?o:h,(l+u)/2,0]:[(o+h)/2,V===2?l:u,0],o1=i0(s,J)[2],Z=(V<2?s[8]:s[9])*(V%2===0?-1:1);g={z:o1,outward:Z}}let v=[];for(let V of[o,h])for(let J of[l,u])for(let o1 of[0,c.thickness])v.push(i0(s,[V,J,o1]));let y=[0,1,2].map(V=>Math.min(...v.map(J=>J[V]))),b=[0,1,2].map(V=>Math.max(...v.map(J=>J[V]))),x=z6(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||!M6([x[0]]))return r1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],w=D4([M]),k=B4(n,c),z=B4(n,r);if(![...k,...z].every(Number.isFinite))return r1("Compensated kerf metadata is needed for manufacturing bounds.");let S={},L=!1;for(let V=0;V<2;V++){let J=Math.abs(s[V*4+2])>.5,o1=J?R5(n,c):[b[V]-y[V]+k[0],b[V]-y[V]+k[1]],Z=w[V+2]-w[V],p1=[Z-z[1]-o1[1],Z-z[0]-o1[0]];if(S[V?"clearanceY":"clearanceX"]=p1,T6(p1,t.clearance))return Q1("Tab/slot clearance is outside the required range.",S);L||(L=!P6(p1,t.clearance));let E=y[V],$=b[V];J?s[V*4+2]>0?$+=o1[1]-c.thickness:E-=o1[1]-c.thickness:(E-=Math.max(0,k[1])/2,$+=Math.max(0,k[1])/2);let X=Math.min(E-w[V],w[V+2]-$)-Math.max(0,z[1])/2;if(S[V?"minimumSideGapY":"minimumSideGapX"]=X,X<-B)return Q1("The tongue is offset into the edge of its slot.",S);X<B&&(L=!0)}let I=Math.max(0,-k[0])/2,q=R5(n,r);if(t.flushTolerance>=q[0]-B)return r1("flushTolerance must be smaller than the receiving thickness.");let R=Math.max(0,Math.min(b[2]-I,q[1])-Math.max(y[2]+I,0)),N=q[1]-t.flushTolerance;if(S.engagement=R,S.requiredEngagement=N,R<=B)return Q1("The tongue does not engage the receiving panel.",S);if(R<N-B)return Q1("The tongue does not engage through the receiving panel.",S);if(R<N+B&&(L=!0),g&&(g.outward>0&&g.z<q[1]-B||g.outward<0&&g.z>B))return Q1("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",S);let G=Math.min(...r.regions.filter(V=>V!==M).map(V=>Z8(M,V)))-Math.max(0,-z[0]);return S.minimumLigament=G,G<t.minimumLigament-B?Q1("Too little material remains around the slot.",S):(G<t.minimumLigament+B&&(L=!0),L?{...r1("A fit condition is on its numerical acceptance boundary."),measurements:S}:E6("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."],F5(n,c)||F5(n,r)?"bounded-fit":"nominal"))}function U4(t){let e=m1(t.to,t.from),n=M1(e);return typeof t.size=="number"&&n>B?{start:t.from,dir:e.map(c=>c/n),length:n,diameter:t.size}:null}function A6(t,e){let n=U4(e);if(!n||M1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let c=m1(n.start,t.start),r=J1(c,t.dir);return M1(c.map((a,s)=>a-r*t.dir[s]))<B}var _4=(t,e)=>J1(m1(e,t.start),t.dir),C6=(t,e)=>[_4(t,e.from),_4(t,e.to)].sort((n,c)=>n-c);function oo(t,e){let n=j8(e.matrix);if(J1(n,t.dir)<0||M1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let c=i0(L0(e.matrix),t.start),r=[c[0],c[1]],a=z6(e.regions,r);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],i=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,o=[i.reduce((p,m)=>p+m[0],0)/i.length,i.reduce((p,m)=>p+m[1],0)/i.length];if(Math.hypot(o[0]-r[0],o[1]-r[1])>B)return"The shaft is not centered in the bore.";let l=s.map(p=>Math.hypot(p[0]-o[0],p[1]-o[1]));if(Math.max(...l)-Math.min(...l)>B)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((p,m)=>Y3(r,p,s[(m+1)%s.length]))),u=Math.max(...s.map(p=>Math.hypot(p[0]-r[0],p[1]-r[1]))),f=_4(t,i0(e.matrix,[0,0,0])),d=_4(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 nn(t,e,n){let c=L2(e,t.shaft),r=U4(c);if(!r)return r1("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=>Y0(e,x)),o=I6(...i);if(o)return r1(o);let l={shaftDiameter:r.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],w=oo(r,M);if(typeof w=="string")return/unsupported|supported/.test(w)?r1(`${M.name}: ${w}`):Q1(`${M.name}: ${w}`);let k=B4(n,M);if(!k.every(Number.isFinite))return r1("Kerf metadata is required for bore tolerance bounds.");let z=[w.hole[0]-k[1]-r.diameter,w.hole[1]-k[0]-r.diameter];if(l[`clearance${x+1}`]=z,T6(z,t.clearance))return Q1(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!P6(z,t.clearance)),w.lo<-B||w.lo+R5(n,M)[1]>r.length+B)return Q1(`${M.name}: the shaft does not extend through this part.`,l);h.push(w)}let f=h.slice(0,2).sort((x,M)=>x.lo-M.lo),d=h.slice(2).sort((x,M)=>x.lo-M.lo);if(f.some(x=>R5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>B)))return r1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-B)return Q1("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-B||d[x].hi>f[1].lo+B||x&&d[x-1].hi>d[x].lo+B)return Q1("The axial stack overlaps another component or its supports.");let p=f[1].lo-f[0].lo,g=[f[0].part,...d.map(x=>x.part)].map(x=>R5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[p-g[1],p-g[0]];if(l.endplay=v,T6(v,t.endplay))return Q1("The axial stack has insufficient or excessive endplay.",l);u||(u=!P6(v,t.endplay));let y=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],b=t.stops.map(x=>({stop:x,h:L2(e,x.body)})).map(x=>({...x,at:x.h&&A6(r,x.h)?C6(r,x.h):void 0}));if(b.some(x=>!x.at))return Q1("A retainer is not coaxial with the shaft.");b.sort((x,M)=>x.at[0]+x.at[1]-(M.at[0]+M.at[1]));for(let x=0;x<2;x++){let{stop:M,h:w}=b[x];if(!A6(r,w))return Q1("A retainer is not coaxial with the shaft.");let k=U4(w),z=C6(r,w),S=f[x],L=x===0?z[1]:z[0],I=x===0?S.lo:S.hi,q=x===0?I-L:L-I;l[`stopGap${x+1}`]=q;let R=B4(n,S.part),N=(k.diameter-(S.hole[1]-R[0]))/2;if(l[`stopOverlap${x+1}`]=N,q<-B||q>t.maximumStopGap+B)return Q1("A retainer is misplaced relative to the outside bearing face.",l);if((q<-1e-7||q>t.maximumStopGap+1e-7)&&(u=!0),N<t.minimumOverlap-B)return Q1("A retainer can pass through its bearing opening.",l);N<t.minimumOverlap+B&&(u=!0);let G=M.attachment;if(G.kind==="unknown")return{...r1("The stop is present but its fastening is unverified."),measurements:l};if(G.kind==="integral"){if(Math.min(Math.abs(L),Math.abs(L-r.length))>B)return Q1("An integral head must meet an end of its shaft.",l);y.push("The specified head and shaft are one integral purchased component.")}else{let V=L2(e,G.thread);if(!A6(r,V))return Q1("The threaded attachment is off the shaft axis.");if(U4(V).diameter>r.diameter+B)return Q1("The declared threaded section exceeds the shaft envelope.");let J=C6(r,V),o1=Math.max(0,Math.min(z[1],J[1])-Math.max(z[0],J[0]));if(J[0]<-B||J[1]>r.length+B)return Q1("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=o1,o1<G.minimumEngagement-B)return Q1("The threaded stop has insufficient declared thread engagement.",l);if(o1<G.minimumEngagement+B&&(u=!0),!G.secured)return{...r1("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?{...r1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:E6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>F5(n,x))?"bounded-fit":"nominal")}var j4=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},u1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),E0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],y0=(t,e)=>t.map(n=>n*e),an=(t,e)=>t.map((n,c)=>n+e[c]),j1=t=>y0(t,1/M1(t)),sn=()=>R0(0,0,0);function V6(t,e){let n=c=>c.kind==="translate"?M1(c.by)<1e-9:Math.abs(c.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?M1(m1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?M1(m1(y0(j1(t.axis),t.angle),y0(j1(e.axis),e.angle)))<1e-9&&M1(E0(m1(t.origin,e.origin),j1(t.axis)))<1e-9:!1}function lo(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 Q3(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 lo(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 ho(t,e){let n=x1(t),c=[...new Set(n.flat().map(i=>i[0]))].sort((i,o)=>i-o),r=n.flatMap(i=>i.map((o,l)=>({a:o,b:i[(l+1)%i.length]}))),a=[],s=(i,o)=>i.a[1]+(o-i.a[0])*(i.b[1]-i.a[1])/(i.b[0]-i.a[0]);for(let i=1;i<c.length;i++){let o=c[i-1],l=c[i],h=(o+l)/2;e.tick(r.length);let u=r.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],p=u[f+1],m=[[o,s(d,o)],[l,s(d,l)],[l,s(p,l)],[o,s(p,o)]],g=m.filter((v,y)=>M1([v[0]-m[(y+1)%m.length][0],v[1]-m[(y+1)%m.length][1],0])>1e-10);if(g.length<3||Math.abs(p3(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 y3(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 $5(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function c0(t,e){if("part"in e)return Y0(t,e).matrix;let n=L2(t,e),[c,r]=$5(n),a={...n,from:c,to:r},s=j1(m1(a.to,a.from));if(!M1(m1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let i=m1(a.up,y0(s,J1(a.up,s)));if(M1(i)<1e-9){if(Array.isArray(a.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(s[0])<.8?[1,0,0]:[0,1,0];i=m1(l,y0(s,J1(l,s)))}i=j1(i);let o=E0(i,s);return[o[0],i[0],s[0],a.from[0],o[1],i[1],s[1],a.from[1],o[2],i[2],s[2],a.from[2],0,0,0,1]}function K2(t,e,n){if(n.tick(),"part"in e){let h=Y0(t,e),u=J3(h);if(u)throw new Error(u);let d=ho(h.regions,n).map(p=>Q3(p,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let c=L2(t,e),r=c0(t,e),[a,s]=$5(c),i=M1(m1(s,a));if(i<B)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(c.size)){let[h,u]=c.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[Q3(f,i,r)];return{ref:e,outer:d,inner:d}}let o=32,l=h=>Array.from({length:o},(u,f)=>[h*Math.cos(f*2*Math.PI/o),h*Math.sin(f*2*Math.PI/o)]);if(c.shape==="ball"){let h=c.size/2,u=h/Math.SQRT2,f=R0(0,0,h-u);return{ref:e,inner:[Q3(l(u),2*u,O1(r,f))],outer:[Q3(l(h/Math.cos(Math.PI/o)),i,r)]}}return{ref:e,inner:[Q3(l(c.size/2),i,r)],outer:[Q3(l(c.size/2/Math.cos(Math.PI/o)),i,r)]}}function W4(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 b3(t,e){if(t.kind==="translate")return R0(...y0(t.by,e));let[n,c,r]=j1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),i=Math.sin(a),o=1-s,l=[s+n*n*o,n*c*o-r*i,n*r*o+c*i,0,c*n*o+r*i,s+c*c*o,c*r*o-n*i,0,r*n*o-c*i,r*c*o+n*i,s+r*r*o,0,0,0,0,1];return O1(R0(...t.origin),O1(l,R0(...y0(t.origin,-1))))}function H6(t,e){if(e.kind==="translate")return M1(e.by);let n=j1(e.axis),c=0;for(let r of t.outer)for(let a of r.vertices){let s=m1(a,e.origin);c=Math.max(c,M1(m1(s,y0(n,J1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*c}function cn(t){return t.faces.map(e=>E0(m1(t.vertices[e[1]],t.vertices[e[0]]),m1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>M1(e)>1e-12).map(j1)}function on(t,e){let n=[...cn(t),...cn(e)];for(let[c,r]of t.edges)for(let[a,s]of e.edges){let i=E0(m1(t.vertices[r],t.vertices[c]),m1(e.vertices[s],e.vertices[a]));M1(i)>1e-12&&n.push(j1(i))}return n}var e5=(t,e)=>{let n=t.vertices.map(c=>J1(c,e));return[Math.min(...n),Math.max(...n)]};function uo(t,e,n){let c=-1/0;for(let r of on(t,e)){n.tick();let a=e5(t,r),s=e5(e,r);c=Math.max(c,s[0]-a[1],a[0]-s[1])}return c}function fo(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 po(t,e,n,c){let r=m1(n,e),a=m1(c,e),s=m1(t,e),i=J1(r,s),o=J1(a,s);if(i<=0&&o<=0)return M1(s);let l=m1(t,n),h=J1(r,l),u=J1(a,l);if(h>=0&&u<=h)return M1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return M1(m1(s,y0(r,i/(i-h))));let d=m1(t,c),p=J1(r,d),m=J1(a,d);if(m>=0&&p<=m)return M1(d);let g=p*o-i*m;if(g<=0&&o>=0&&m<=0)return M1(m1(s,y0(a,o/(o-m))));let v=h*m-p*u;if(v<=0&&u-h>=0&&p-m>=0)return M1(m1(l,y0(m1(c,n),(u-h)/(u-h+p-m))));let y=v+g+f;if(Math.abs(y)<1e-20)return 1/0;let b=Math.max(0,Math.min(1,g/y)),x=Math.max(0,Math.min(1-b,f/y));return M1(m1(s,an(y0(r,b),y0(a,x))))}function mo(t,e,n,c){let r=m1(e,t),a=m1(c,n),s=m1(t,n),i=J1(r,r),o=J1(r,a),l=J1(a,a),h=J1(r,s),u=J1(a,s);if(i<1e-20||l<1e-20)return 1/0;let f=i*l-o*o,d=f>1e-20?Math.max(0,Math.min(1,(o*u-l*h)/f)):0,p=(o*d+u)/l;return p<0&&(p=0,d=Math.max(0,Math.min(1,-h/i))),p>1&&(p=1,d=Math.max(0,Math.min(1,(o-h)/i))),M1(an(s,m1(y0(r,d),y0(a,p))))}function go(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,po(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,mo(t.vertices[r],t.vertices[a],e.vertices[s],e.vertices[i]));return c}function rn(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=fo(o,l);if(h>Math.min(a,c)){r=Math.min(r,h);continue}let u=uo(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,go(o,l,n)))}return{lower:r,upper:a,penetration:s,touchSafe:i}}function X4(t,e,n,c){let r=rn(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:rn(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 ln(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 on(o,l)){a.tick();let p=e5(o,d),m=e5(l,d),g=e5(h,d),v=e5(u,d);if(Math.min(m[0]-p[1],v[0]-g[1])>=r||Math.min(p[0]-m[1],g[0]-v[1])>=r){f=!0;break}}if(!f)return!1}return!0}function Z4(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let c={part:n.name,copy:n.copy},r=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(r>1&&(n.copy-1)%r!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:c,faceA:a?"bottom":"top",faceB:a?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:c,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var p2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),D5=(t,e)=>t.every((n,c)=>Math.abs(n-e[c])<B);function hn(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 un(t,e,n){let c=hn(e,t.bodies??y3(e),n);if(c.length<2)return r1("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=X4(c[a],c[s],n,t.minimumGap);if(r=Math.min(r,i.lower),i.penetration||i.upper<t.minimumGap-B)return p2("Physical bodies interfere or violate the required clearance.",{gapUpper:i.upper},[c[a].ref,c[s].ref]);if(!(i.lower>t.minimumGap||t.minimumGap===0&&i.touchSafe))return{...r1("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 O6(t,e,n,c,r=1e3){let a=o=>({solid:o,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let o=0;o<t.length;o++){for(let l of e)yield{a:t[o],b:a(l)};for(let l=o+1;l<t.length;l++)yield{a:t[o],b:t[l]}}}let i=0;for(let{a:o,b:l}of s()){c.tick();let h=(d,p)=>W4(d.solid,b3(d.trajectory,p));if(V6(o.trajectory,l.trajectory)){let d=X4(o.solid,l.solid,c,n);if(d.penetration||d.upper<n-B)return p2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[o.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...r1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&ln(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+B,c))continue;let u=H6(o.solid,o.trajectory)+H6(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>r)return{...r1("Continuous clearance interval budget exhausted."),measurements:{intervals:i},entities:[o.solid.ref,l.solid.ref]};c.tick();let[d,p]=f.shift(),m=(d+p)/2,g=u*(p-d)/2,v=X4(h(o,m),h(l,m),c,n+g);if(v.penetration||v.upper<n-B)return p2("The specified path has physical interference.",{phase:m,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(p-d<1e-9)return{...r1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,p]},entities:[o.solid.ref,l.solid.ref]};f.push([d,m],[m,p])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function vo(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||!q4(n,c))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([c.stack,c.glue,c.glueFace,c.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let c=e.hardware.find(r=>r.label===n.label);if(!n.label||!c||n.kind!==c.kind||JSON.stringify(n.size)!==JSON.stringify(c.size)||Math.abs(M1(m1(n.to,n.from))-M1(m1(c.to,c.from)))>B)return"Hardware identities and dimensions must remain invariant."}return null}function fn(t,e,n,c,r=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return r1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=vo(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=y3(e),i=new Set(t.moving.map(l=>u1(l.body)));if(i.size!==t.moving.length)return p2("A body has conflicting simultaneous trajectories.");let o=l=>t.moving.find(h=>u1(h.body)===u1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...Z4(e),...r]){let h=O1(L0(c0(e,l.a)),c0(e,l.b)),u=O1(L0(c0(n,l.a)),c0(n,l.b));if(!D5(h,u)||!V6(o(l.a),o(l.b)))return p2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>u1(f.body)===u1(l))?.trajectory,u=h?b3(h,1):sn();if("part"in l){if(!D5(O1(u,c0(e,l)),c0(n,l)))return p2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=L2(e,l),d=L2(n,l);if(typeof f.size=="number"){if(!D5(i0(u,f.from),d.from)||!D5(i0(u,f.to),d.to))return p2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!D5(O1(u,c0(e,l)),c0(n,l)))return p2("A box trajectory does not match its rendered destination.",{},[l])}}return O6(t.moving.map(l=>({solid:K2(e,l.body,c),trajectory:l.trajectory})),hn(e,s.filter(l=>!i.has(u1(l))),c),t.minimumGap,c,t.maxIntervals)}function dn(t,e,n){let c=t.scope??y3(e),r=new Set(c.map(u1)),a=new Map(t.initial.map(o=>[u1(o),K2(e,o,n)]));if(r.size!==c.length||a.size!==t.initial.length||t.initial.some(o=>!r.has(u1(o))))return p2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,i=0;for(let o of t.steps){if(s.has(o.id)||!r.has(u1(o.part))||a.has(u1(o.part)))return p2("An assembly step duplicates or misidentifies a required installation.");if(s.add(o.id),!o.held)return{...r1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=K2(e,o.part,n),h=W4(l,b3({kind:"translate",by:o.from},1)),u=O6([{solid:h,trajectory:{kind:"translate",by:o.from.map(f=>-f)}}],[...a.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:o.id,message:`Assembly step ${o.id}: ${u.message}`};if(i+=u.measurements?.intervals??0,a.set(u1(o.part),l),o.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:o.tool.from,to:o.tool.to,size:o.tool.diameter,up:[0,1,0]}]},p=K2(d,{hardware:f},n),m=W4(p,b3({kind:"translate",by:o.tool.travel},1)),g=O6([{solid:m,trajectory:{kind:"translate",by:o.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:o.id,message:`Tool access at step ${o.id}: ${g.message}`}}}return a.size!==r.size?p2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:a.size,intervals:i},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var K1=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),B0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),$0=t=>[t[3],t[7],t[11]],R6=t=>{let e=j1(t),n=j1(E0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,E0(e,n)]},Y4=(t,e,n)=>{let c=R6(n)[0],r=j1(B0(e,c)),a=j1(B0(t,c)),s=j1(B0(e,n));return Math.atan2(J1(s,E0(r,a)),J1(r,a))*180/Math.PI},pn=(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 mn(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 gn(t,e,n,c){let r=y3(e),a=new Set(r.map(u1));for(let f of t.removable??[])a.delete(u1(f));if(t.roots.some(f=>!a.has(u1(f))))return K1("A retention root cannot be excluded as removable.");let s=new Map,i=f=>{for(let d of f)for(let p of f){let m=u1(d),g=s.get(m)??new Set;g.add(u1(p)),s.set(m,g)}},o=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(g=>g.id===f.claim),p=c.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!p)return r1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(p.status==="fail")return K1(`Attachment ${f.claim} fails its geometric contract.`);if(p.status!=="pass")return r1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return K1(`The fastening for ${f.claim} is explicitly not installed.`);let m=mn(d,f.fastening);if(!m)return r1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(m),d.kind==="glue-contact"&&o.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(u1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=r.filter(f=>a.has(u1(f))&&!l.has(u1(f)));return u.length?{...K1("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:a.size,removableComponents:t.removable?.length??0},assumptions:o}}function yo(t,e){if("hardware"in e){let i=c0(t,e),o=t.hardware.find(l=>l.label===e.hardware);return i0(i,[0,0,M1(m1($5(o)[1],$5(o)[0]))/2])}let n=Y0(t,e),c=J3(n);if(c)throw new Error(c);let r=0,a=0,s=0;for(let i of n.regions){let[o,l]=i[0],h=0,u=0,f=0;for(let p=0;p<i.length;p++){let m=i[p],g=i[(p+1)%i.length],v=m[0]-o,y=m[1]-l,b=g[0]-o,x=g[1]-l,M=v*x-b*y;h+=M,u+=(v+b)*M,f+=(y+x)*M}if(Math.abs(h)<1e-12)continue;let d=p3(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 bo(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 xo(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=mn(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 vn(t,e,n,c=[],r){let a=y3(e),s=t.loads.map(m=>u1(m.body));if(new Set(s).size!==s.length||a.some(m=>!s.includes(u1(m))))return r1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let m=c.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=r?.claims.find(v=>v.id===t.retention);if(!m||m.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return r1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!xo(g,r,a))return r1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let i=0,o=[0,0,0];for(let m of t.loads){let g=m.center?i0(c0(e,m.body),m.center):yo(e,m.body);i+=m.mass,o=o.map((v,y)=>v+m.mass*g[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return r1("Mass/centroid calculation exceeds its numerical range.");o=y0(o,1/i);let l=[];for(let m of a){let g=K2(e,m,n),v=Math.min(...g.inner.flatMap(b=>b.vertices.map(x=>x[2]))),y=Math.min(...g.outer.flatMap(b=>b.vertices.map(x=>x[2])));if(v<t.ground-B)return K1("A physical component penetrates the ground plane.");if(y<t.ground-B)return r1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(b=>u1(b)===u1(m))){if(Math.abs(v-t.ground)>1e-8)return r1("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=bo(l);if(h.length<3)return r1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-o[2])/t.gravity[2],f=[o[0]+u*t.gravity[0],o[1]+u*t.gravity[1]],d=1/0;for(let m=0;m<h.length;m++){let g=h[m],v=h[(m+1)%h.length],y=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),b=Y3(f,g,v);d=Math.min(d,y<0?-b:b)}let p={supportMargin:d,mass:i,centerX:o[0],centerY:o[1],centerZ:o[2]};return d<t.minimumMargin-B?K1("The gravity line lies outside the required support margin.",p):d<t.minimumMargin+B?{...r1("Stability is on its numerical support boundary."),measurements:p}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:p,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function yn(t,e,n,c){let r=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>c.find(p=>p.id===d&&p.configurations.includes(e.configuration));if(!r||r.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return r1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return r1("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 r1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let p=n.claims.find(m=>m.id===d.claim);if(p?.kind==="glue-contact")l.set(d.claim,[p.a,p.b]);else if(p?.kind==="captured-shaft"){let m=[p.shaft,...p.bearings,...p.stack,...p.stops.map(g=>g.body)];p.stops.forEach(g=>{g.attachment.kind==="threaded"&&m.push(g.attachment.thread)}),l.set(d.claim,m)}}let h=new Set,u=new Set(r.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return K1("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let g of h)for(let v of l.get(g)??[])for(let y of l.get(g)??[]){let b=d.get(u1(v))??new Set;b.add(u1(y)),d.set(u1(v),b)}let p=new Set([...i].filter(g=>o.has(g))),m=[...p];for(;m.length;)for(let g of d.get(m.pop())??[])p.has(g)||(p.add(g),m.push(g));return p};for(let d of r.steps){o.add(u1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return K1(`Step ${d.id} names an unknown fastening.`);if(v.some(y=>!o.has(u1(y))))return K1(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let p=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(u1));if([...p].some(g=>!o.has(g)))return K1(`Step ${d.id} holds an uninstalled body.`);let m=f();if([...o].some(g=>!m.has(g)&&!p.has(g)))return K1(`Step ${d.id} releases a component before it is retained or supported.`)}return[...o].some(d=>!f().has(d))?K1("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function Mo(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 bn(t,e,n,c,r,a=[]){if(t.bodies.length>64)return r1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(u1),i=t.roots.map(u1);if(new Set(s).size!==s.length||new Set(i).size!==i.length||i.some(v=>!s.includes(v)))return K1("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>c0(e,v).some((y,b)=>Math.abs(y-c0(n,v)[b])>B)))return K1("A grounded kinematic root changes pose.");let o=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,y,b,x,M=1)=>{let w=s.indexOf(u1(y));if(w<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[w*6+b+k]+=M*x[k]};for(let v of t.roots)for(let y=0;y<6;y++){let b=h();b[s.indexOf(u1(v))*6+y]=1,o.push(b)}let f=Z4({...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 r1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=G4({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:B*B*4},e);if(y.status!=="pass")return{...y,message:`A native glue/stack bond is not physically established: ${y.message}`}}}let d=[...t.joints,...f.filter(v=>s.includes(u1(v.a))&&s.includes(u1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(c.tick(),u1(v.a)===u1(v.b))return K1("A joint cannot connect a body to itself.");let y=c0(e,v.a),b=c0(e,v.b),x=c0(n,v.a),M=c0(n,v.b),w=O1(L0(y),b),k=O1(L0(x),M),z=L=>{let I=h();u(I,v.b,3,L),u(I,v.a,3,L,-1),o.push(I)},S=(L,I,q)=>{let R=h();u(R,v.b,0,L),u(R,v.a,0,L,-1),u(R,v.b,3,E0(q,L)),u(R,v.a,3,E0(I,L),-1),o.push(R)};if(v.kind==="fixed"){if(w.some((L,I)=>Math.abs(L-k[I])>B))return K1("A fixed joint changes its relative transform.");l.forEach(L=>z(L)),l.forEach(L=>S(L,m1($0(b),$0(y)),[0,0,0]))}else if(v.kind==="revolute"){let L=i0(y,v.anchorA),I=i0(b,v.anchorB),q=j1(B0(y,v.axisA)),R=j1(B0(b,v.axisB)),N=J1(j1(B0(x,v.axisA)),j1(B0(M,v.axisB)));if(M1(m1(L,I))>B||M1(E0(q,R))>1e-7||Math.abs(J1(q,R)-N)>1e-7)return K1("Revolute anchors or axes do not coincide.");if(v.range){let G=Y4(w,k,v.axisB);if(!pn(G,v.range,B).length)return K1("A revolute joint exceeds its declared angular travel.",{angle:G})}l.forEach(G=>S(G,m1(L,$0(y)),m1(I,$0(b)))),R6(q).forEach(z)}else if(v.kind==="prismatic"){let L=m1($0(w),$0(k)),I=j1(v.axisA),q=J1(L,I);if([0,1,2,4,5,6,8,9,10].some(R=>Math.abs(w[R]-k[R])>B)||M1(m1(L,y0(I,q)))>B)return K1("A slider rotates or moves away from its guide axis.");if(q<v.travel[0]-B||q>v.travel[1]+B)return K1("The slider exceeds its allowed travel.",{travel:q});l.forEach(z),R6(j1(B0(y,v.axisA))).forEach(R=>S(R,m1($0(b),$0(y)),[0,0,0]))}else{let L=j1(B0(y,v.axisA)),I=j1(B0(b,v.axisB));if(M1(E0(L,I))>1e-7||M1(m1($0(y),$0(x)))>B||M1(m1($0(b),$0(M)))>B)return K1("The scoped gear axes/centers are not fixed and parallel.");let q=Y4(y,x,v.axisA),R=Y4(b,M,v.axisB);if(Math.abs(q)>90||Math.abs(R)>90)return r1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(R+v.ratio*q)>1e-6)return K1("The rendered gears do not obey their declared angular ratio.");let N=h();u(N,v.a,3,L,v.ratio),u(N,v.b,3,I),o.push(N)}}c.tick(o.length*s.length*6);let p=Mo(o),m=s.length*6-p.rank;if(p.uncertain)return r1("Constraint rank is numerically singular.");let g={degreesOfFreedom:m,constraintRank:p.rank,redundantRows:o.length-p.rank};return m!==t.expectedDof?K1("The joint graph has unintended freedom or is overconstrained.",g):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:g,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function xn(t,e,n,c){let r=o=>t.moving.find(l=>u1(l.body)===u1(o))?.trajectory??{kind:"translate",by:[0,0,0]},a=o=>o.kind==="translate"?M1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?M1(m1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?M1(m1(y0(j1(o.axis),o.angle),y0(j1(l.axis),l.angle)))<1e-9&&M1(E0(m1(o.origin,l.origin),j1(o.axis)))<1e-9:!1;if(e.roots.some(o=>!a(r(o))))return K1("The analytic path moves a grounded joint root.");let i=new Map;for(let o of e.joints.filter(l=>l.kind!=="gear")){if(i.has(u1(o.b)))return r1("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 r1("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 r1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=i0(u,o.anchorA),p=j1(B0(u,o.axisA)),m=j1(h.axis);if(M1(E0(p,m))>1e-9||M1(E0(m1(h.origin,d),p))>B)return K1("The trajectory does not rotate about the actual hinge.");if(o.range){let g=O1(L0(u),f),v=O1(L0(c0(c,o.a)),c0(c,o.b)),y=h.angle*J1(j1(B0(f,o.axisB)),m),b=o.range;if(!pn(Y4(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 r1("This slider trajectory composition needs a richer constraint solver.");let d=j1(B0(u,o.axisA));if(M1(E0(h.by,d))>B)return K1("The analytic slider path leaves its guide.");let p=O1(L0(u),f),m=O1(L0(c0(c,o.a)),c0(c,o.b)),g=J1(m1($0(p),$0(m)),j1(o.axisA)),v=g+J1(h.by,d);if(Math.min(g,v)<o.travel[0]-B||Math.max(g,v)>o.travel[1]+B)return K1("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,y)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let b=c0(n,g),x=j1(B0(b,y));return M1(E0(j1(v.axis),x))>1e-9||M1(E0(m1(v.origin,$0(b)),x))>B?null:v.angle*J1(j1(v.axis),x)},p=d(o.a,l,o.axisA),m=d(o.b,h,o.axisB);if(p===null||m===null)return r1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(m+o.ratio*p)>1e-7)return K1("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function F6(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return Mn(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(c=>{let r=n?.parts.filter(l=>l.name===c.name),a=r?.length===1?r[0]:void 0,s=a?.glue?.host,o=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((c.copy-1)/(a?.stack??1))+1:1;return{name:c.name,copy:c.copy,thickness:c.thickness,material:c.material??"",matrix:c.matrix,placed:c.placed,regions:a?.cutRegions??c.outline,bends:c.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:o},glueFace:a.glue.face},...a?.on&&{on:a.on}}}),hardware:t.hardware.map(c=>({label:c.label??null,kind:c.kind,from:c.from,to:c.to,size:c.size,up:c.up,...c.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(c=>c.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function Mn(t){if(t&&typeof t=="object"){for(let e of Object.values(t))Mn(e);Object.freeze(t)}return t}function $6(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let c=O5({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,b3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=r.get(u1({part:a.name,copy:a.copy}));return s?{...a,matrix:O1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},i=r.get(u1(s));return i?{...a,from:i0(i,a.from),to:i0(i,a.to),up:m1(i0(i,a.up),i0(i,[0,0,0]))}:a})}}function zn(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==B||O5(e).length||L6(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 kn(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=O5(t);if(c.length)return{kind:"invalid-spec",issues:c};let r=L6(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 en(a)){let y=u.get(g);for(let b of s.filter(x=>x.error===void 0&&(!y.configurations||y.configurations.includes(x.configuration)))){let x="part"in v?b.parts.filter(M=>M.name===v.part&&M.copy===(v.copy??1)):b.hardware.filter(M=>M.label===v.hardware);x.length!==1&&i.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${b.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(i.length)return{kind:"invalid-spec",issues:i};for(let g of a.configurations){let v=s.find(b=>b.configuration===g.id),y=v&&v.error===void 0;o.claims.push(Q2(`$configuration:${g.id}`,"configuration",!0,[g.id],y?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),y&&(o.claims.push(Q2(`$provenance:${g.id}`,"provenance",!0,[g.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&o.claims.push(Q2(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
|
|
2644
|
-
`)})),v.legacyHardware&&o.claims.push(
|
|
2645
|
-
`;let e=
|
|
2646
|
-
`;let n=
|
|
2722
|
+
}`)}return c}function Xo(t,e,n){let r;try{r=new Y3({maxSteps:2e6}).run(l2(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(!w3(a,s,i))return!1;let o=e.lines.map(l=>M3(l));return!(o.length&&!w3(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),Cn=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]),q6=(t,e)=>q1(p0(t.matrix),e.matrix);function k3(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+k3(n),0)),N6=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 ee(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 Pn=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function U6(t){if(t.length!==1)return!1;let e=ee(t);return c3(h3(t,[Pn(e)]))<j*j}var B6=(t,e)=>a0(t,[Pn(e)]);function En(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 Zo(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 c5(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 Tn(t,e){let n=1/0;for(let r of t)for(let c=0;c<e.length;c++)n=Math.min(n,c5(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,c5(r,t[c],t[(c+1)%t.length]));return n}var _6=(t,e)=>t.filter(n=>k3(n)<0&&Zo(n,e));function a5(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 In(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 te(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&Ln(t.regions)===Ln(e.regions)&&An(t.cutLines)===An(e.cutLines)}function Ln(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(k3(n)),c.sort()[0]])};return JSON.stringify(t.map(e).sort())}function An(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,z3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(O2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,L3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(O2),w2=t=>L3(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)),ne=t=>j1(t)&&S0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),s5=t=>a3(t)||ne(t),j2=t=>Array.isArray(t)&&t.every(s5),S3=t=>w2(t)&&Math.hypot(...t)>1e-9,Yo=t=>j1(t)&&(t.kind==="translate"&&w2(t.by)||t.kind==="rotate"&&w2(t.origin)&&S3(t.axis)&&O2(t.angle)&&Math.abs(t.angle)<=1e6),j6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),Vn=t=>j1(t)&&Object.values(t).every(j6),On=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||O2(t)||Array.isArray(t)&&t.every(n=>On(n,e+1))),G6=t=>j1(t)&&Object.values(t).every(e=>On(e)),Jo=t=>t===null||j1(t)&&j6(t.sourceHash)&&j6(t.engineHash)&&Vn(t.dependencies)&&Vn(t.fonts);function G5(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)||!z3(l.thickness,Number.MIN_VALUE)||!z3(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&&!G6(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)||!L3(h.region,4)||h.region.some(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!z3(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(!ne(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)||!z3(h.clearance)||!z3(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)||!ne(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"&&(!ne(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)&&s5(m.body)&&Yo(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)&&s5(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)&&s5(m.a)&&s5(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&w2(m.anchorA)&&w2(m.anchorB)&&S3(m.axisA)&&S3(m.axisB)&&(m.range===void 0||z3(m.range,-1e6))||m.kind==="prismatic"&&S3(m.axisA)&&z3(m.travel,-1e6)||m.kind==="gear"&&S3(m.axisA)&&S3(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||!S3(h.gravity)||h.gravity[2]>=0||!G2(h.minimumMargin)||!h.loads.every(m=>j1(m)&&s5(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 W6(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)||!G6(a.params)||!G6(a.renderSettings)||!Jo(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)||!Ko(l.matrix)||typeof l.placed!="boolean"||!Hn(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!Hn(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"||!L3(l.from,3)||!L3(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||L3(l.size,2)&&l.size.every(h=>H2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function Hn(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>L3(r,2)&&r.every(c=>Math.abs(c)<=1e6)))}function Ko(t){if(!L3(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 Fn(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}),l1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),K6=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),X5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,W5=(t,e)=>X5(t,e)?.thickness??[e.thickness,e.thickness];function ce(t,e){let n=X5(t,e);return n?e.kerf===null?[-1/0,1/0]:[e.kerf-n.kerf[1]-2*(n.edgeError??0),e.kerf-n.kerf[0]+2*(n.edgeError??0)]:[0,0]}var Y6=(t,e)=>t[0]>=e[0]+j&&t[1]<=e[1]-j,J6=(t,e)=>t[0]<e[0]-j||t[1]>e[1]+j,Q6=(...t)=>t.map(a5).find(Boolean);function se(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=Q6(n,r);if(c)return l1(c);let a=q6(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 l1("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=En(r.regions,a,i),f=c3(a0(n.regions,u)),d=j*(N6(n.regions)+N6(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?{...l1("Contact area is on the numerical acceptance boundary."),measurements:m}:K6("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 Rn(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=Q6(r,c);if(a)return l1(a);let s=q6(c,r);if(!In(s)||Math.abs(s[10])>j)return l1("Only orthogonal tab/slot geometry is supported.");let i=B6(r.regions,t.region);if(!U6(i))return l1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=ee(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(B6(r.regions,T))>j*j).flatMap((T,B)=>T?[B]:[]);if(g.length>1)return l1("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 l1("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=_6(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||!U6([x[0]]))return l1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],w=ee([M]),k=ce(n,r),z=ce(n,c);if(![...k,...z].every(Number.isFinite))return l1("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?W5(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,J6(h1,t.clearance))return e0("Tab/slot clearance is outside the required range.",S);A||(A=!Y6(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=W5(n,c);if(t.flushTolerance>=C[0]-j)return l1("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=>Tn(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?{...l1("A fit condition is on its numerical acceptance boundary."),measurements:S}:K6("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."],X5(n,r)||X5(n,c)?"bounded-fit":"nominal"))}function re(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 X6(t,e){let n=re(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 ae=(t,e)=>K1(b1(e,t.start),t.dir),Z6=(t,e)=>[ae(t,e.from),ae(t,e.to)].sort((n,r)=>n-r);function Qo(t,e){let n=Cn(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=_6(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)=>c5(c,m,s[(g+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-c[0],m[1]-c[1]))),f=ae(t,f0(e.matrix,[0,0,0])),d=ae(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 $n(t,e,n){let r=F2(e,t.shaft),c=re(r);if(!c)return l1("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=Q6(...i);if(o)return l1(o);let l={shaftDiameter:c.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],w=Qo(c,M);if(typeof w=="string")return/unsupported|supported/.test(w)?l1(`${M.name}: ${w}`):e0(`${M.name}: ${w}`);let k=ce(n,M);if(!k.every(Number.isFinite))return l1("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,J6(z,t.clearance))return e0(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!Y6(z,t.clearance)),w.lo<-j||w.lo+W5(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=>W5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>j)))return l1("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=>W5(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,J6(v,t.endplay))return e0("The axial stack has insufficient or excessive endplay.",l);u||(u=!Y6(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&&X6(c,x.h)?Z6(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(!X6(c,w))return e0("A retainer is not coaxial with the shaft.");let k=re(w),z=Z6(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=ce(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{...l1("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(!X6(c,T))return e0("The threaded attachment is off the shaft axis.");if(re(T).diameter>c.diameter+j)return e0("The declared threaded section exceeds the shaft envelope.");let B=Z6(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{...l1("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?{...l1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:K6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>X5(n,x))?"bounded-fit":"nominal")}var ie=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),Nn=(t,e)=>t.map((n,r)=>n+e[r]),W1=t=>L0(t,1/S1(t)),Un=()=>B0(0,0,0);function et(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 el(t,e){let n=new Map;for(let r of e)for(let c=0;c<r.length;c++){let a=r[c],s=r[(c+1)%r.length],i=a<s?[a,s]:[s,a];n.set(i.join(","),i)}return{vertices:t,faces:e,edges:[...n.values()]}}function i5(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 el(c,[t.map((a,s)=>s).reverse(),t.map((a,s)=>r+s),...t.map((a,s)=>[s,(s+1)%r,(s+1)%r+r,s+r])])}function tl(t,e){let n=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(k3(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 A3(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 Z5(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]=Z5(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=a5(h);if(u)throw new Error(u);let d=tl(h.regions,n).map(m=>i5(m,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=F2(t,e),c=i0(t,e),[a,s]=Z5(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=[i5(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:[i5(l(u),2*u,q1(c,f))],outer:[i5(l(h/Math.cos(Math.PI/o)),i,c)]}}return{ref:e,inner:[i5(l(r.size/2),i,c)],outer:[i5(l(r.size/2/Math.cos(Math.PI/o)),i,c)]}}function oe(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 C3(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 tt(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 Dn(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 Bn(t,e){let n=[...Dn(t),...Dn(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 o5=(t,e)=>{let n=t.vertices.map(r=>K1(r,e));return[Math.min(...n),Math.max(...n)]};function nl(t,e,n){let r=-1/0;for(let c of Bn(t,e)){n.tick();let a=o5(t,c),s=o5(e,c);r=Math.max(r,s[0]-a[1],a[0]-s[1])}return r}function rl(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 cl(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,Nn(L0(c,b),L0(a,x))))}function al(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(Nn(s,b1(L0(c,d),L0(a,m))))}function sl(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,cl(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,al(t.vertices[c],t.vertices[a],e.vertices[s],e.vertices[i]));return r}function qn(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=rl(o,l);if(h>Math.min(a,r)){c=Math.min(c,h);continue}let u=nl(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,sl(o,l,n)))}return{lower:c,upper:a,penetration:s,touchSafe:i}}function le(t,e,n,r){let c=qn(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:qn(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 _n(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 Bn(o,l)){a.tick();let m=o5(o,d),g=o5(l,d),p=o5(h,d),v=o5(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 he(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}),Y5=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<j);function jn(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 Gn(t,e,n){let r=jn(e,t.bodies??A3(e),n);if(r.length<2)return l1("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=le(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{...l1("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 nt(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)=>oe(d.solid,C3(d.trajectory,m));if(et(o.trajectory,l.trajectory)){let d=le(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{...l1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&_n(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+j,r))continue;let u=tt(o.solid,o.trajectory)+tt(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>c)return{...l1("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=le(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{...l1("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 il(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||!te(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 Wn(t,e,n,r,c=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return l1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=il(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=A3(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[...he(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(!Y5(h,u)||!et(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?C3(h,1):Un();if("part"in l){if(!Y5(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(!Y5(f0(u,f.from),d.from)||!Y5(f0(u,f.to),d.to))return k2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!Y5(q1(u,i0(e,l)),i0(n,l)))return k2("A box trajectory does not match its rendered destination.",{},[l])}}return nt(t.moving.map(l=>({solid:s3(e,l.body,r),trajectory:l.trajectory})),jn(e,s.filter(l=>!i.has(d1(l))),r),t.minimumGap,r,t.maxIntervals)}function Xn(t,e,n){let r=t.scope??A3(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{...l1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=s3(e,o.part,n),h=oe(l,C3({kind:"translate",by:o.from},1)),u=nt([{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=oe(m,C3({kind:"translate",by:o.tool.travel},1)),p=nt([{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}),K0=(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]],rt=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)]},ue=(t,e,n)=>{let r=rt(n)[0],c=W1(K0(e,r)),a=W1(K0(t,r)),s=W1(K0(e,n));return Math.atan2(K1(s,V0(c,a)),K1(c,a))*180/Math.PI},Zn=(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 Yn(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 Jn(t,e,n,r){let c=A3(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 l1(`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 l1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return Q1(`The fastening for ${f.claim} is explicitly not installed.`);let g=Yn(d,f.fastening);if(!g)return l1(`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 ol(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(Z5(o)[1],Z5(o)[0]))/2])}let n=r2(t,e),r=a5(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=k3(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 ll(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 hl(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=Yn(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 Kn(t,e,n,r=[],c){let a=A3(e),s=t.loads.map(g=>d1(g.body));if(new Set(s).size!==s.length||a.some(g=>!s.includes(d1(g))))return l1("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 l1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!hl(p,c,a))return l1("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):ol(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 l1("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 l1("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 l1("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=ll(l);if(h.length<3)return l1("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=c5(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?{...l1("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 Qn(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 l1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return l1("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 l1("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 ul(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 e9(t,e,n,r,c,a=[]){if(t.bodies.length>64)return l1("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=he({...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 l1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=se({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(K0(y,v.axisA)),P=W1(K0(b,v.axisB)),R=K1(W1(K0(x,v.axisA)),W1(K0(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=ue(w,k,v.axisB);if(!Zn(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)))),rt(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),rt(W1(K0(y,v.axisA))).forEach(P=>S(P,b1(j0(b),j0(y)),[0,0,0]))}else{let A=W1(K0(y,v.axisA)),L=W1(K0(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=ue(y,x,v.axisA),P=ue(b,M,v.axisB);if(Math.abs(C)>90||Math.abs(P)>90)return l1("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=ul(o),g=s.length*6-m.rank;if(m.uncertain)return l1("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 t9(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 l1("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 l1("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 l1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=f0(u,o.anchorA),m=W1(K0(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(K0(f,o.axisB)),g),b=o.range;if(!Zn(ue(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 l1("This slider trajectory composition needs a richer constraint solver.");let d=W1(K0(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(K0(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 l1("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 ct(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return n9(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 n9(t){if(t&&typeof t=="object"){for(let e of Object.values(t))n9(e);Object.freeze(t)}return t}function at(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=G5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(r.length)throw new Error(r[0].message);let 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,C3(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 c9(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==j||G5(e).length||W6(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 a9(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let r=G5(t);if(r.length)return{kind:"invalid-spec",issues:r};let c=W6(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 Fn(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 ie(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)?l1("A required configuration is unavailable."):fl(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=l1("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=l1("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=t9(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=Wn(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,r9(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=l1("The configuration is unavailable.");else try{switch(p.kind){case"glue-contact":w=se(p,b);break;case"tab-slot":w=Rn(p,b,M);break;case"captured-shaft":w=$n(p,b,M);break;case"material-assignment":w=dl(b,M);break;case"rigid-clearance":w=Gn(p,b,f);break;case"assembly-access":w=Xn(p,b,f);break;case"joint-constraints":{let k=s.find(z=>z.configuration===v[0]);w=k&&k.error===void 0?e9(p,b,k,f,a,o.claims):l1("The kinematic reference configuration is unavailable.");break}case"retention":w=Jn(p,b,a,o.claims);break;case"stability":w=Kn(p,b,f,o.claims,a);break;case"assembly-support":w=Qn(p,b,a,o.claims);break;default:w=l1(`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,r9(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 r9(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 fl(t){if(t.length<2)return l1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return l1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(r=>r.cutLines===null||r.kerf===null)))return l1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(r=>!r.label)))return l1("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 l1("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||!te(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 dl(t,e){if(!t.parts.length)return l1("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 l1(`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 l1("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 ml=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function st(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(ml),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 s9(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(c=>c.message).join("; ")}
|
|
2724
|
+
`;let e=st(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(`
|
|
2647
2726
|
`)+`
|
|
2648
|
-
`}var
|
|
2727
|
+
`}var pl="0.9.0",gl="0.3";
|
|
2649
2728
|
/*! Bundled license information:
|
|
2650
2729
|
|
|
2651
2730
|
opentype.js/dist/opentype.module.js:
|