@mylasertools/kerfscript 0.7.0 → 0.8.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/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  /*! @mylasertools/kerfscript | (c) MyLaserTools | AGPL-3.0-only or commercial licence, see COMMERCIAL-LICENSE.md. Includes Clipper2 (BSL-1.0), opentype.js, tiny-inflate and string.prototype.codepointat (MIT), see THIRD-PARTY-NOTICES.md. */
2
- var p9=Object.defineProperty;var g9=(t,e,n)=>e in t?p9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var v9=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var D=(t,e,n)=>g9(t,typeof e!="symbol"?e+"":e,n);var w7=v9((dh,M7)=>{M7.exports={}});var e0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(e0||(e0={}));var I0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(I0||(I0={}));var F1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(F1||(F1={}));var q1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(q1||(q1={}));var b3=Number.MAX_SAFE_INTEGER,f0=Math.floor(Math.sqrt(b3));function R5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=b3/Math.abs(e)}function Ie(t,e){return Math.abs(t)+Math.abs(e)<=b3}function j4(t,e,n,c){if(R5(t,e)&&R5(n,c)){let r=t*e,a=n*c;if(Ie(r,a))return r-a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(c)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(c)):t*e-n*c}function _4(t,e,n,c){if(R5(t,e)&&R5(n,c)){let r=t*e,a=n*c;if(Ie(r,a))return r+a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(c)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(c)):t*e+n*c}var W4=BigInt(0),F5=BigInt(2),y9=BigInt(4),b9=BigInt(64),x9=BigInt("0xFFFFFFFFFFFFFFFF"),Y4=BigInt("9223372036854775807"),J3=Number(Y4/y9),Ve=Number(Y4),He=1e-12,M9=.1,X4=Math.floor(f0/2),w9=Math.floor(Math.sqrt(Math.sqrt(b3/4)));function z9(t){if(!Number.isFinite(t))throw new RangeError("Scale must be a finite number");let e=Math.abs(t);return e===0?Number.POSITIVE_INFINITY:b3/e}function k9(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function S9(t,e){if(!Number.isFinite(t)||Math.abs(t)>b3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function L9(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0?c*r-a*s:j4(c,r,a,s)}function Y0(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;if(Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0){let l=c*r,h=a*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let l=c*r,h=a*s;return l>h?1:l<h?-1:0}let i=BigInt(c)*BigInt(r),o=BigInt(a)*BigInt(s);return i===o?0:i>o?1:-1}function A9(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function C9(t){return Math.abs(t)<=He}function P9(t){return t<0?-1:t>0?1:0}function E9(t,e){let n=BigInt(t),c=BigInt(e),r=n*c;return{lo64:r&x9,hi64:r>>b9}}function Oe(t,e,n,c){let r=Math.abs(t),a=Math.abs(e),s=Math.abs(n),i=Math.abs(c);if(r<f0&&a<f0&&s<f0&&i<f0)return t*e===n*c;let o=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(c<0?-1:c>0?1:0);if(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return t*e===n*c;let h=BigInt(r),u=BigInt(a),f=BigInt(s),d=BigInt(i);return h*u===f*d}function T9(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Oe(c,r,a,s)}function I9(t,e,n){let c=e.x-t.x,r=n.x-e.x,a=e.y-t.y,s=n.y-e.y;return Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0?c*r+a*s:_4(c,r,a,s)}function V9(t,e,n){let c=e.x-t.x,r=n.x-e.x,a=e.y-t.y,s=n.y-e.y;if(Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0){let o=c*r+a*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let o=c*r+a*s;return o>0?1:o<0?-1:0}let i=BigInt(c)*BigInt(r)+BigInt(a)*BigInt(s);return i===W4?0:i>W4?1:-1}function H9(t){let e=t.length;if(e<3)return 0;let n=!0;for(let a=0;a<e&&n;a++){let s=t[a];(Math.abs(s.x)>=X4||Math.abs(s.y)>=X4)&&(n=!1)}let c=t[e-1];if(n){let a=0;for(let s of t)a+=(c.y+s.y)*(c.x-s.x),c=s;return a*.5}let r=W4;for(let a of t){let s=c.y+a.y,i=c.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))r+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(c.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(a.x)){let o=BigInt(c.y)+BigInt(a.y),l=BigInt(c.x)-BigInt(a.x);r+=o*l}else r+=BigInt(Math.round(s*i));c=a}return Number(r)*.5}function O9(t,e){return t.y*e.x-e.y*t.x}function R9(t,e){return t.x*e.x+t.y*e.y}function F9(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function $9(t){return t>=J3||t<=-J3?Ve:Math.round(t)}function D9(t,e,n,c){let r=e.y-t.y,a=e.x-t.x,s=c.y-n.y,i=c.x-n.x,o=j4(r,i,s,a);if(o===0)return null;let l=j4(t.x-n.x,s,t.y-n.y,i)/o;return l<=0?{x:t.x,y:t.y,z:t.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(t.x+l*a),y:Math.trunc(t.y+l*r),z:0}}function q9(t,e,n,c){let r=e.y-t.y,a=e.x-t.x,s=c.y-n.y,i=c.x-n.x,o=r*i-s*a;if(o===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*s-(t.y-n.y)*i)/o,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*a,y:t.y+l*r,z:0},{success:!0,ip:h}}function N9(t,e,n,c,r=!1){if(!r){let l=Y0(t,n,c),h=Y0(e,n,c),u=Y0(n,t,e),f=Y0(c,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=Y0(t,n,c),s=Y0(e,n,c);if(a!==0&&a===s)return!1;let i=Y0(n,t,e),o=Y0(c,t,e);return i!==0&&i===o?!1:a!==0||s!==0||i!==0||o!==0}function Re(t){if(t.length===0)return{left:0,top:0,right:0,bottom:0};let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of t)n.x<e.left&&(e.left=n.x),n.x>e.right&&(e.right=n.x),n.y<e.top&&(e.top=n.y),n.y>e.bottom&&(e.bottom=n.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function U9(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let c=n.x-e.x,r=n.y-e.y,a=_4(t.x-e.x,c,t.y-e.y,r)/_4(c,c,r,r),s=a<0?0:a>1?1:a;return{x:Math.round(e.x+s*c),y:Math.round(e.y+s*r),z:0}}function Z4(t,e){let n=e.length,c=0;if(n<3)return q1.IsOutside;for(;c<n&&e[c].y===t.y;)c++;if(c===n)return q1.IsOutside;let r=e[c].y<t.y,a=r,s=0,i=c+1,o=n;for(;;){if(i===o){if(o===0||c===0)break;o=c,i=0}if(r)for(;i<o&&e[i].y<t.y;)i++;else for(;i<o&&e[i].y>t.y;)i++;if(i===o)continue;let h=e[i],u=i>0?e[i-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return q1.IsOn;if(i++,i===c)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)s=1-s;else{let f=Y0(u,h,t);if(f===0)return q1.IsOn;f<0===r&&(s=1-s)}r=!r,i++}if(r===a)return s===0?q1.IsOutside:q1.IsInside;i===n&&(i=0);let l=i===0?Y0(e[n-1],e[0],t):Y0(e[i-1],e[i],t);return l===0?q1.IsOn:(l<0===r&&(s=1-s),s===0?q1.IsOutside:q1.IsInside)}function B9(t,e){let n=q1.IsOn;for(let i of t)switch(Z4(i,e)){case q1.IsOutside:if(n===q1.IsOutside)return!1;n=q1.IsOutside;break;case q1.IsInside:if(n===q1.IsInside)return!0;n=q1.IsInside;break;default:break}let c=Re(t),r,a;return Number.isSafeInteger(c.left)&&Number.isSafeInteger(c.right)&&Math.abs(c.left)+Math.abs(c.right)>Number.MAX_SAFE_INTEGER?(r=Number((BigInt(c.left)+BigInt(c.right))/F5),a=Number((BigInt(c.top)+BigInt(c.bottom))/F5)):(r=Math.round((c.left+c.right)/2),a=Math.round((c.top+c.bottom)/2)),Z4({x:r,y:a},e)!==q1.IsOutside}var V1={MaxInt64:Y4,MaxCoord:J3,max_coord:J3,min_coord:-J3,Invalid64:Ve,floatingPointTolerance:He,defaultMinimumEdgeLength:M9,maxCoordForSafeAreaProduct:X4,maxCoordForSafeCrossSq:w9,maxSafeCoordinateForScale:z9,checkSafeScaleValue:k9,ensureSafeInteger:S9,crossProduct:L9,crossProductSign:Y0,checkPrecision:A9,isAlmostZero:C9,triSign:P9,multiplyUInt64:E9,productsAreEqual:Oe,isCollinear:T9,dotProduct:I9,dotProductSign:V9,area:H9,crossProductD:O9,dotProductD:R9,roundToEven:F9,checkCastInt64:$9,getLineIntersectPt:D9,getLineIntersectPtD:q9,segsIntersect:N9,getBounds:Re,getClosestPtOnSegment:U9,pointInPolygon:Z4,path2ContainsPath1:B9},m2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return V1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),V1.ensureSafeInteger(t.y,"Point64Utils.fromPointD"),{x:Math.round(t.x),y:Math.round(t.y),z:t.z||0}},scale(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e),z:t.z||0}},equals(t,e){return t.x===e.x&&t.y===e.y},add(t,e){if(Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(e.y)){let n=t.x+e.x,c=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(c)?{x:n,y:c,z:0}:{x:Number(BigInt(t.x)+BigInt(e.x)),y:Number(BigInt(t.y)+BigInt(e.y)),z:0}}return{x:t.x+e.x,y:t.y+e.y,z:0}},subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:0}},toString(t){return t.z!==void 0&&t.z!==0?`${t.x},${t.y},${t.z} `:`${t.x},${t.y} `}},$5={create(t=0,e=0,n=0){return{x:t,y:e,z:n}},fromPoint64(t){return{x:t.x,y:t.y,z:t.z||0}},scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z||0}},equals(t,e){return V1.isAlmostZero(t.x-e.x)&&V1.isAlmostZero(t.y-e.y)},negate(t){t.x=-t.x,t.y=-t.y},toString(t,e=2){return t.z!==void 0&&t.z!==0?`${t.x.toFixed(e)},${t.y.toFixed(e)},${t.z}`:`${t.x.toFixed(e)},${t.y.toFixed(e)}`}},t3={create(t=0,e=0,n=0,c=0){return{left:t,top:e,right:n,bottom:c}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},isValid(t){return t.left<Number.MAX_SAFE_INTEGER},midPoint(t){if(Number.isSafeInteger(t.left)&&Number.isSafeInteger(t.right)&&Math.abs(t.left)+Math.abs(t.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(t.left)+BigInt(t.right))/F5),n=Number((BigInt(t.top)+BigInt(t.bottom))/F5);return{x:e,y:n}}return{x:Math.round((t.left+t.right)/2),y:Math.round((t.top+t.bottom)/2)}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<=Math.min(t.right,e.right)&&Math.max(t.top,e.top)<=Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}},J4={create(t=0,e=0,n=0,c=0){return{left:t,top:e,right:n,bottom:c}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},midPoint(t){return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<Math.min(t.right,e.right)&&Math.max(t.top,e.top)<Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}};var Fe=Object.freeze(t3.createInvalid()),$e=Object.freeze(J4.createInvalid());var K3=BigInt(0),G9=BigInt(2),De=BigInt(4),X1;(function(t){t[t.None=0]="None",t[t.OpenStart=1]="OpenStart",t[t.OpenEnd=2]="OpenEnd",t[t.LocalMax=4]="LocalMax",t[t.LocalMin=8]="LocalMin"})(X1||(X1={}));var K4=class{constructor(){D(this,"data",[])}push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],n=this.data.pop();return this.data.length>0&&(this.data[0]=n,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let n=this.data[e];for(;e>0;){let c=e-1>>1;if(this.data[c]>=n)break;this.data[e]=this.data[c],e=c}this.data[e]=n}siftDown(e){let n=this.data.length,c=this.data[e];for(;;){let r=(e<<1)+1;if(r>=n)break;let a=r+1,s=r;if(a<n&&this.data[a]>this.data[r]&&(s=a),this.data[s]<=c)break;this.data[e]=this.data[s],e=s}this.data[e]=c}},Q3=class{constructor(e,n,c){D(this,"pt");D(this,"next",null);D(this,"prev",null);D(this,"flags");this.pt=e,this.flags=n,this.prev=c}},e5=class{constructor(e,n,c=!1){D(this,"vertex");D(this,"polytype");D(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=c}equals(e){return e!==null&&this.vertex===e.vertex}};function qe(t,e,n){return{pt:t,edge1:e,edge2:n}}var S2=class{constructor(e,n){D(this,"pt");D(this,"next");D(this,"prev");D(this,"outrec");D(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},H0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(H0||(H0={}));var Q4;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(Q4||(Q4={}));var D5=class{constructor(){D(this,"idx",0);D(this,"owner",null);D(this,"frontEdge",null);D(this,"backEdge",null);D(this,"pts",null);D(this,"polypath",null);D(this,"bounds",{left:0,top:0,right:0,bottom:0});D(this,"path",[]);D(this,"isOpen",!1);D(this,"splits",null);D(this,"recursiveSplit",null)}},q5=class{constructor(e){D(this,"leftOp");D(this,"rightOp");D(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},t5=class{constructor(e,n){D(this,"op1");D(this,"op2");this.op1=e,this.op2=n}};function j9(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function _9(t,e){return t.pt.y!==e.pt.y?t.pt.y>e.pt.y?-1:1:t.pt.x!==e.pt.x?t.pt.x<e.pt.x?-1:1:t.edge1.curX!==e.edge1.curX?t.edge1.curX<e.edge1.curX?-1:1:t.edge2.curX<e.edge2.curX?-1:t.edge2.curX>e.edge2.curX?1:0}var n5=class{constructor(){D(this,"bot",{x:0,y:0});D(this,"top",{x:0,y:0});D(this,"curX",0);D(this,"dx",0);D(this,"windDx",0);D(this,"windCount",0);D(this,"windCount2",0);D(this,"outrec",null);D(this,"prevInAEL",null);D(this,"nextInAEL",null);D(this,"prevInSEL",null);D(this,"nextInSEL",null);D(this,"jump",null);D(this,"vertexTop",null);D(this,"localMin",null);D(this,"isLeftBound",!1);D(this,"joinWith",H0.None)}},x3={addLocMin(t,e,n,c){if((t.flags&X1.LocalMin)!==X1.None)return;t.flags|=X1.LocalMin;let r=new e5(t,e,n);c.push(r)},addPathsToVertexList(t,e,n,c,r){for(let a=0,s=t.length;a<s;a++){let i=t[a],o=null,l=null,h=null;for(let m=0,p=i.length;m<p;m++){let g=i[m];if(o===null)o=new Q3(g,X1.None,null),r.push(o),l=o,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new Q3(g,X1.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!n&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!n&&l.next===l))continue;let u;if(n){let m=o.next;for(;m!==o&&m.pt.y===o.pt.y;)m=m.next;u=m.pt.y<=o.pt.y,u?(o.flags=X1.OpenStart,x3.addLocMin(o,e,!0,c)):o.flags=X1.OpenStart|X1.LocalMax}else{for(l=o.prev;l!==o&&l.pt.y===o.pt.y;)l=l.prev;if(l===o)continue;u=l.pt.y>o.pt.y}let f=u;l=o;let d=o.next;for(;d!==o;)d.pt.y>l.pt.y&&u?(l.flags|=X1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,x3.addLocMin(l,e,n,c)),l=d,d=d.next;n?(l.flags|=X1.OpenEnd,u?l.flags|=X1.LocalMax:x3.addLocMin(l,e,n,c)):u!==f&&(f?x3.addLocMin(l,e,!1,c):l.flags|=X1.LocalMax)}}};var N5=class{constructor(e=null){D(this,"parent");D(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,n=this.parent;for(;n!==null;)++e,n=n.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)===0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,n){let c="",r=" ".repeat(n),a=this.children.length===1?"":"s";(n&1)===0?c+=`${r}+- hole (${e}) contains ${this.children.length} nested polygon${a}.
2
+ var yn=Object.defineProperty;var bn=(t,e,n)=>e in t?yn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var xn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var D=(t,e,n)=>bn(t,typeof e!="symbol"?e+"":e,n);var S7=xn((mh,k7)=>{k7.exports={}});var e0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(e0||(e0={}));var I0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(I0||(I0={}));var D1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(D1||(D1={}));var N1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(N1||(N1={}));var b3=Number.MAX_SAFE_INTEGER,f0=Math.floor(Math.sqrt(b3));function D5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=b3/Math.abs(e)}function H6(t,e){return Math.abs(t)+Math.abs(e)<=b3}function j4(t,e,n,c){if(D5(t,e)&&D5(n,c)){let r=t*e,a=n*c;if(H6(r,a))return r-a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(c)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(c)):t*e-n*c}function W4(t,e,n,c){if(D5(t,e)&&D5(n,c)){let r=t*e,a=n*c;if(H6(r,a))return r+a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(c)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(c)):t*e+n*c}var X4=BigInt(0),q5=BigInt(2),Mn=BigInt(4),wn=BigInt(64),zn=BigInt("0xFFFFFFFFFFFFFFFF"),J4=BigInt("9223372036854775807"),K3=Number(J4/Mn),O6=Number(J4),R6=1e-12,kn=.1,Z4=Math.floor(f0/2),Sn=Math.floor(Math.sqrt(Math.sqrt(b3/4)));function Ln(t){if(!Number.isFinite(t))throw new RangeError("Scale must be a finite number");let e=Math.abs(t);return e===0?Number.POSITIVE_INFINITY:b3/e}function An(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function Cn(t,e){if(!Number.isFinite(t)||Math.abs(t)>b3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function Pn(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0?c*r-a*s:j4(c,r,a,s)}function Y0(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;if(Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0){let l=c*r,h=a*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let l=c*r,h=a*s;return l>h?1:l<h?-1:0}let i=BigInt(c)*BigInt(r),o=BigInt(a)*BigInt(s);return i===o?0:i>o?1:-1}function Tn(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function En(t){return Math.abs(t)<=R6}function In(t){return t<0?-1:t>0?1:0}function Vn(t,e){let n=BigInt(t),c=BigInt(e),r=n*c;return{lo64:r&zn,hi64:r>>wn}}function F6(t,e,n,c){let r=Math.abs(t),a=Math.abs(e),s=Math.abs(n),i=Math.abs(c);if(r<f0&&a<f0&&s<f0&&i<f0)return t*e===n*c;let o=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(c<0?-1:c>0?1:0);if(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return t*e===n*c;let h=BigInt(r),u=BigInt(a),f=BigInt(s),d=BigInt(i);return h*u===f*d}function Hn(t,e,n){let c=e.x-t.x,r=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return F6(c,r,a,s)}function On(t,e,n){let c=e.x-t.x,r=n.x-e.x,a=e.y-t.y,s=n.y-e.y;return Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0?c*r+a*s:W4(c,r,a,s)}function Rn(t,e,n){let c=e.x-t.x,r=n.x-e.x,a=e.y-t.y,s=n.y-e.y;if(Math.abs(c)<f0&&Math.abs(r)<f0&&Math.abs(a)<f0&&Math.abs(s)<f0){let o=c*r+a*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let o=c*r+a*s;return o>0?1:o<0?-1:0}let i=BigInt(c)*BigInt(r)+BigInt(a)*BigInt(s);return i===X4?0:i>X4?1:-1}function Fn(t){let e=t.length;if(e<3)return 0;let n=!0;for(let a=0;a<e&&n;a++){let s=t[a];(Math.abs(s.x)>=Z4||Math.abs(s.y)>=Z4)&&(n=!1)}let c=t[e-1];if(n){let a=0;for(let s of t)a+=(c.y+s.y)*(c.x-s.x),c=s;return a*.5}let r=X4;for(let a of t){let s=c.y+a.y,i=c.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))r+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(c.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(a.x)){let o=BigInt(c.y)+BigInt(a.y),l=BigInt(c.x)-BigInt(a.x);r+=o*l}else r+=BigInt(Math.round(s*i));c=a}return Number(r)*.5}function $n(t,e){return t.y*e.x-e.y*t.x}function Dn(t,e){return t.x*e.x+t.y*e.y}function qn(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function Nn(t){return t>=K3||t<=-K3?O6:Math.round(t)}function Un(t,e,n,c){let r=e.y-t.y,a=e.x-t.x,s=c.y-n.y,i=c.x-n.x,o=j4(r,i,s,a);if(o===0)return null;let l=j4(t.x-n.x,s,t.y-n.y,i)/o;return l<=0?{x:t.x,y:t.y,z:t.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(t.x+l*a),y:Math.trunc(t.y+l*r),z:0}}function Bn(t,e,n,c){let r=e.y-t.y,a=e.x-t.x,s=c.y-n.y,i=c.x-n.x,o=r*i-s*a;if(o===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*s-(t.y-n.y)*i)/o,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*a,y:t.y+l*r,z:0},{success:!0,ip:h}}function _n(t,e,n,c,r=!1){if(!r){let l=Y0(t,n,c),h=Y0(e,n,c),u=Y0(n,t,e),f=Y0(c,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=Y0(t,n,c),s=Y0(e,n,c);if(a!==0&&a===s)return!1;let i=Y0(n,t,e),o=Y0(c,t,e);return i!==0&&i===o?!1:a!==0||s!==0||i!==0||o!==0}function $6(t){if(t.length===0)return{left:0,top:0,right:0,bottom:0};let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of t)n.x<e.left&&(e.left=n.x),n.x>e.right&&(e.right=n.x),n.y<e.top&&(e.top=n.y),n.y>e.bottom&&(e.bottom=n.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function Gn(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let c=n.x-e.x,r=n.y-e.y,a=W4(t.x-e.x,c,t.y-e.y,r)/W4(c,c,r,r),s=a<0?0:a>1?1:a;return{x:Math.round(e.x+s*c),y:Math.round(e.y+s*r),z:0}}function Y4(t,e){let n=e.length,c=0;if(n<3)return N1.IsOutside;for(;c<n&&e[c].y===t.y;)c++;if(c===n)return N1.IsOutside;let r=e[c].y<t.y,a=r,s=0,i=c+1,o=n;for(;;){if(i===o){if(o===0||c===0)break;o=c,i=0}if(r)for(;i<o&&e[i].y<t.y;)i++;else for(;i<o&&e[i].y>t.y;)i++;if(i===o)continue;let h=e[i],u=i>0?e[i-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return N1.IsOn;if(i++,i===c)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)s=1-s;else{let f=Y0(u,h,t);if(f===0)return N1.IsOn;f<0===r&&(s=1-s)}r=!r,i++}if(r===a)return s===0?N1.IsOutside:N1.IsInside;i===n&&(i=0);let l=i===0?Y0(e[n-1],e[0],t):Y0(e[i-1],e[i],t);return l===0?N1.IsOn:(l<0===r&&(s=1-s),s===0?N1.IsOutside:N1.IsInside)}function jn(t,e){let n=N1.IsOn;for(let i of t)switch(Y4(i,e)){case N1.IsOutside:if(n===N1.IsOutside)return!1;n=N1.IsOutside;break;case N1.IsInside:if(n===N1.IsInside)return!0;n=N1.IsInside;break;default:break}let c=$6(t),r,a;return Number.isSafeInteger(c.left)&&Number.isSafeInteger(c.right)&&Math.abs(c.left)+Math.abs(c.right)>Number.MAX_SAFE_INTEGER?(r=Number((BigInt(c.left)+BigInt(c.right))/q5),a=Number((BigInt(c.top)+BigInt(c.bottom))/q5)):(r=Math.round((c.left+c.right)/2),a=Math.round((c.top+c.bottom)/2)),Y4({x:r,y:a},e)!==N1.IsOutside}var V1={MaxInt64:J4,MaxCoord:K3,max_coord:K3,min_coord:-K3,Invalid64:O6,floatingPointTolerance:R6,defaultMinimumEdgeLength:kn,maxCoordForSafeAreaProduct:Z4,maxCoordForSafeCrossSq:Sn,maxSafeCoordinateForScale:Ln,checkSafeScaleValue:An,ensureSafeInteger:Cn,crossProduct:Pn,crossProductSign:Y0,checkPrecision:Tn,isAlmostZero:En,triSign:In,multiplyUInt64:Vn,productsAreEqual:F6,isCollinear:Hn,dotProduct:On,dotProductSign:Rn,area:Fn,crossProductD:$n,dotProductD:Dn,roundToEven:qn,checkCastInt64:Nn,getLineIntersectPt:Un,getLineIntersectPtD:Bn,segsIntersect:_n,getBounds:$6,getClosestPtOnSegment:Gn,pointInPolygon:Y4,path2ContainsPath1:jn},m2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return V1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),V1.ensureSafeInteger(t.y,"Point64Utils.fromPointD"),{x:Math.round(t.x),y:Math.round(t.y),z:t.z||0}},scale(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e),z:t.z||0}},equals(t,e){return t.x===e.x&&t.y===e.y},add(t,e){if(Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(e.y)){let n=t.x+e.x,c=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(c)?{x:n,y:c,z:0}:{x:Number(BigInt(t.x)+BigInt(e.x)),y:Number(BigInt(t.y)+BigInt(e.y)),z:0}}return{x:t.x+e.x,y:t.y+e.y,z:0}},subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:0}},toString(t){return t.z!==void 0&&t.z!==0?`${t.x},${t.y},${t.z} `:`${t.x},${t.y} `}},N5={create(t=0,e=0,n=0){return{x:t,y:e,z:n}},fromPoint64(t){return{x:t.x,y:t.y,z:t.z||0}},scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z||0}},equals(t,e){return V1.isAlmostZero(t.x-e.x)&&V1.isAlmostZero(t.y-e.y)},negate(t){t.x=-t.x,t.y=-t.y},toString(t,e=2){return t.z!==void 0&&t.z!==0?`${t.x.toFixed(e)},${t.y.toFixed(e)},${t.z}`:`${t.x.toFixed(e)},${t.y.toFixed(e)}`}},t3={create(t=0,e=0,n=0,c=0){return{left:t,top:e,right:n,bottom:c}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},isValid(t){return t.left<Number.MAX_SAFE_INTEGER},midPoint(t){if(Number.isSafeInteger(t.left)&&Number.isSafeInteger(t.right)&&Math.abs(t.left)+Math.abs(t.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(t.left)+BigInt(t.right))/q5),n=Number((BigInt(t.top)+BigInt(t.bottom))/q5);return{x:e,y:n}}return{x:Math.round((t.left+t.right)/2),y:Math.round((t.top+t.bottom)/2)}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<=Math.min(t.right,e.right)&&Math.max(t.top,e.top)<=Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}},K4={create(t=0,e=0,n=0,c=0){return{left:t,top:e,right:n,bottom:c}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},midPoint(t){return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<Math.min(t.right,e.right)&&Math.max(t.top,e.top)<Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}};var D6=Object.freeze(t3.createInvalid()),q6=Object.freeze(K4.createInvalid());var Q3=BigInt(0),Wn=BigInt(2),N6=BigInt(4),X1;(function(t){t[t.None=0]="None",t[t.OpenStart=1]="OpenStart",t[t.OpenEnd=2]="OpenEnd",t[t.LocalMax=4]="LocalMax",t[t.LocalMin=8]="LocalMin"})(X1||(X1={}));var Q4=class{constructor(){D(this,"data",[])}push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],n=this.data.pop();return this.data.length>0&&(this.data[0]=n,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let n=this.data[e];for(;e>0;){let c=e-1>>1;if(this.data[c]>=n)break;this.data[e]=this.data[c],e=c}this.data[e]=n}siftDown(e){let n=this.data.length,c=this.data[e];for(;;){let r=(e<<1)+1;if(r>=n)break;let a=r+1,s=r;if(a<n&&this.data[a]>this.data[r]&&(s=a),this.data[s]<=c)break;this.data[e]=this.data[s],e=s}this.data[e]=c}},e5=class{constructor(e,n,c){D(this,"pt");D(this,"next",null);D(this,"prev",null);D(this,"flags");this.pt=e,this.flags=n,this.prev=c}},t5=class{constructor(e,n,c=!1){D(this,"vertex");D(this,"polytype");D(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=c}equals(e){return e!==null&&this.vertex===e.vertex}};function U6(t,e,n){return{pt:t,edge1:e,edge2:n}}var A2=class{constructor(e,n){D(this,"pt");D(this,"next");D(this,"prev");D(this,"outrec");D(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},H0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(H0||(H0={}));var ee;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(ee||(ee={}));var U5=class{constructor(){D(this,"idx",0);D(this,"owner",null);D(this,"frontEdge",null);D(this,"backEdge",null);D(this,"pts",null);D(this,"polypath",null);D(this,"bounds",{left:0,top:0,right:0,bottom:0});D(this,"path",[]);D(this,"isOpen",!1);D(this,"splits",null);D(this,"recursiveSplit",null)}},B5=class{constructor(e){D(this,"leftOp");D(this,"rightOp");D(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},n5=class{constructor(e,n){D(this,"op1");D(this,"op2");this.op1=e,this.op2=n}};function Xn(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function Zn(t,e){return t.pt.y!==e.pt.y?t.pt.y>e.pt.y?-1:1:t.pt.x!==e.pt.x?t.pt.x<e.pt.x?-1:1:t.edge1.curX!==e.edge1.curX?t.edge1.curX<e.edge1.curX?-1:1:t.edge2.curX<e.edge2.curX?-1:t.edge2.curX>e.edge2.curX?1:0}var c5=class{constructor(){D(this,"bot",{x:0,y:0});D(this,"top",{x:0,y:0});D(this,"curX",0);D(this,"dx",0);D(this,"windDx",0);D(this,"windCount",0);D(this,"windCount2",0);D(this,"outrec",null);D(this,"prevInAEL",null);D(this,"nextInAEL",null);D(this,"prevInSEL",null);D(this,"nextInSEL",null);D(this,"jump",null);D(this,"vertexTop",null);D(this,"localMin",null);D(this,"isLeftBound",!1);D(this,"joinWith",H0.None)}},x3={addLocMin(t,e,n,c){if((t.flags&X1.LocalMin)!==X1.None)return;t.flags|=X1.LocalMin;let r=new t5(t,e,n);c.push(r)},addPathsToVertexList(t,e,n,c,r){for(let a=0,s=t.length;a<s;a++){let i=t[a],o=null,l=null,h=null;for(let p=0,m=i.length;p<m;p++){let g=i[p];if(o===null)o=new e5(g,X1.None,null),r.push(o),l=o,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new e5(g,X1.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!n&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!n&&l.next===l))continue;let u;if(n){let p=o.next;for(;p!==o&&p.pt.y===o.pt.y;)p=p.next;u=p.pt.y<=o.pt.y,u?(o.flags=X1.OpenStart,x3.addLocMin(o,e,!0,c)):o.flags=X1.OpenStart|X1.LocalMax}else{for(l=o.prev;l!==o&&l.pt.y===o.pt.y;)l=l.prev;if(l===o)continue;u=l.pt.y>o.pt.y}let f=u;l=o;let d=o.next;for(;d!==o;)d.pt.y>l.pt.y&&u?(l.flags|=X1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,x3.addLocMin(l,e,n,c)),l=d,d=d.next;n?(l.flags|=X1.OpenEnd,u?l.flags|=X1.LocalMax:x3.addLocMin(l,e,n,c)):u!==f&&(f?x3.addLocMin(l,e,!1,c):l.flags|=X1.LocalMax)}}};var _5=class{constructor(e=null){D(this,"parent");D(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,n=this.parent;for(;n!==null;)++e,n=n.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)===0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,n){let c="",r=" ".repeat(n),a=this.children.length===1?"":"s";(n&1)===0?c+=`${r}+- hole (${e}) contains ${this.children.length} nested polygon${a}.
3
3
  `:c+=`${r}+- polygon (${e}) contains ${this.children.length} hole${a}.
4
4
  `;for(let s=0;s<this.count;s++)this.children[s].count>0&&(c+=this.children[s].toStringInternal(s,n+1));return c}toString(){if(this.level>0)return"";let e=this.children.length===1?"":"s",n=`Polytree with ${this.children.length} polygon${e}.
5
5
  `;for(let c=0;c<this.count;c++)this.children[c].count>0&&(n+=this.children[c].toStringInternal(c,1));return n+`
6
- `}},U5=class t extends N5{constructor(n=null){super(n);D(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let c=new t(this);return c.polygon=n,this.children.push(c),c}child(n){if(n<0||n>=this.children.length)throw new Error("Index out of range");return this.children[n]}area(){let n=this.polygon===null?0:e6.area(this.polygon);for(let c of this.children)n+=c.area();return n}};var c5=class extends U5{};var E=class E{constructor(){D(this,"cliptype",e0.NoClip);D(this,"fillrule",F1.EvenOdd);D(this,"actives",null);D(this,"sel",null);D(this,"minimaList",[]);D(this,"intersectList",[]);D(this,"vertexList",[]);D(this,"outrecList",[]);D(this,"scanlineHeap",new K4);D(this,"scanlineSet",new Set);D(this,"scanlineArr",[]);D(this,"useScanlineArray",!1);D(this,"horzSegList",[]);D(this,"horzJoinList",[]);D(this,"currentLocMin",0);D(this,"currentBotY",0);D(this,"curXValidAtTop",!1);D(this,"isSortedMinimaList",!1);D(this,"hasOpenPaths",!1);D(this,"usingPolytree",!1);D(this,"succeeded",!1);D(this,"zCallbackInternal");D(this,"preserveCollinear",!0);D(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,c){let r=this.zCallbackInternal;r&&(E.getPolyType(e)===I0.Subject?(this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:c.z=0,r(e.bot,e.top,n.bot,n.top,c)):(this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:c.z=0,r(n.bot,n.top,e.bot,e.top,c)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return E.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return E.openPathsEnabled&&e.localMin.isOpen&&E.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(X1.OpenStart|X1.OpenEnd))!==X1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!E.openPathsEnabled){for(;n!==null&&!E.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!E.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let c=n.y-e.y;return c!==0?(n.x-e.x)/c:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:V1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=E.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&X1.LocalMax)!==X1.None}static isMaximaEdge(e){return(e.vertexTop.flags&X1.LocalMax)!==X1.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,c,r){let a=e.x<n.x?e.x:n.x;if((c.x>r.x?c.x:r.x)<a)return!1;let i=e.x>n.x?e.x:n.x,o=c.x<r.x?c.x:r.x;if(i<o)return!1;let l=e.y<n.y?e.y:n.y;if((c.y>r.y?c.y:r.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=c.y<r.y?c.y:r.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,c=e.length;n<c;n++){let r=e[n];this.scanlineSet.add(r),this.scanlineHeap.push(r)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let c=0,r=n.length;c<r;c++)if(n[c]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,c=n.length;if(c===0)return null;let r=0,a=n[0];for(let s=1;s<c;s++){let i=n[s];i>a&&(a=i,r=s)}return n[r]=n[c-1],n.pop(),a}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,c=!1){let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c=!1){c&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,x3.addPathsToVertexList(e,n,c,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new e5(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,c=e.nextInAEL;n===null&&c===null&&e!==this.actives||(n!==null?n.nextInAEL=c:this.actives=c,c!==null&&(c.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let c=n;do c.pt.x<e.left&&(e.left=c.pt.x),c.pt.x>e.right&&(e.right=c.pt.x),c.pt.y<e.top&&(e.top=c.pt.y),c.pt.y>e.bottom&&(e.bottom=c.pt.y),c=c.next;while(c!==n)}return t3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===e0.NoClip)return;E.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let c=this.popScanline();if(c!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(c);let r;for(;(r=this.popHorz())!==null;)this.doHorizontal(r);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=c;let a=this.popScanline();if(a===null)break;for(c=a,this.doIntersections(c),this.doTopOfScanbeam(c);(r=this.popHorz())!==null;)this.doHorizontal(r)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),c;(n.vertex.flags&X1.OpenStart)!==X1.None?c=null:(c=new n5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=-1,c.vertexTop=n.vertex.prev,c.top=n.vertex.prev.pt,c.outrec=null,c.localMin=n,E.setDx(c));let r;if((n.vertex.flags&X1.OpenEnd)!==X1.None?r=null:(r=new n5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=1,r.vertexTop=n.vertex.next,r.top=n.vertex.next.pt,r.outrec=null,r.localMin=n,E.setDx(r)),c!==null&&r!==null){if(E.isHorizontal(c)){if(E.isHeadingRightHorz(c)){let s=c;c=r,r=s}}else if(E.isHorizontal(r)){if(E.isHeadingLeftHorz(r)){let s=c;c=r,r=s}}else if(c.dx<r.dx){let s=c;c=r,r=s}}else c===null&&(c=r,r=null);let a;if(c.isLeftBound=!0,this.insertLeftEdge(c),E.openPathsEnabled?E.isOpen(c)?(this.setWindCountForOpenPathEdge(c),a=this.isContributingOpen(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)),r!==null){for(r.windCount=c.windCount,r.windCount2=c.windCount2,this.insertRightEdge(c,r),a&&(this.addLocalMinPoly(c,r,c.bot,!0),E.isHorizontal(c)||this.checkJoinLeft(c,c.bot));r.nextInAEL!==null&&this.isValidAelOrder(r.nextInAEL,r);)this.intersectEdges(r,r.nextInAEL,r.bot),this.swapPositionsInAEL(r,r.nextInAEL);E.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else a&&E.openPathsEnabled&&this.startOpenPath(c,c.bot);E.isHorizontal(c)?this.pushHorz(c):this.insertScanline(c.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!E.openPathsEnabled){this.doHorizontalClosed(e);return}let n=E.isOpen(e),c=e.bot.y,r=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:i}=this.resetHorzDirection(e,r),o=s,l=i;if(E.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:c});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===r){if(E.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),E.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(r!==e.vertexTop||E.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!E.isHorizontal(h)){let d=E.nextVertex(e).pt;if(E.isOpen(h)&&!E.isSamePolyType(h,e)&&!E.isHotEdge(h)){if(a&&E.topX(h,d.y)>d.x||!a&&E.topX(h,d.y)<d.x)break}else if(a&&E.topX(h,d.y)>=d.x||!a&&E.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:c};a?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),E.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&E.isOpenEnd(e)){E.isHotEdge(e)&&(this.addOutPt(e,e.top),E.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(E.nextVertex(e).pt.y!==e.top.y)break;E.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,r);o=u.leftX,l=u.rightX}if(E.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,c=this.getCurrYMaximaVertex(e),{isLeftToRight:r,leftX:a,rightX:s}=this.resetHorzDirection(e,c),i=a,o=s;if(E.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=r?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===c){if(E.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),E.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);r?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(c!==e.vertexTop){if(r&&l.curX>o||!r&&l.curX<i)break;if(l.curX===e.top.x&&!E.isHorizontal(l)){let f=E.nextVertex(e).pt,d=E.topX(l,f.y);if(r&&d>=f.x||!r&&d<=f.x)break}}let u={x:l.curX,y:n};r?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),E.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(E.nextVertex(e).pt.y!==e.top.y)break;E.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(E.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let c=0,r=e.length;c<r;c++){let a=e[c];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(j9);for(let c=0;c<n-1;c++){let r=this.horzSegList[c];for(let a=c+1;a<n;a++){let s=this.horzSegList[a];if(s.leftOp.pt.x>=r.rightOp.pt.x||s.leftToRight===r.leftToRight||s.rightOp.pt.x<=r.leftOp.pt.x)continue;let i=r.leftOp.pt.y;if(r.leftToRight){for(;r.leftOp.next.pt.y===i&&r.leftOp.next.pt.x<=s.leftOp.pt.x;)r.leftOp=r.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=r.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new t5(this.duplicateOp(r.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;r.leftOp.prev.pt.y===i&&r.leftOp.prev.pt.x<=s.leftOp.pt.x;)r.leftOp=r.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=r.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new t5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(r.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let n=e.leftOp,c=this.getRealOutRec(n.outrec),r=c.frontEdge!==null,a=n.pt.y,s=n,i=n;if(r){let l=c.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;i!==l&&i.next.pt.y===a;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===a;)s=s.prev;for(;i.next!==s&&i.next.pt.y===a;)i=i.next}let o=this.setHorzSegHeadingForward(e,s,i)&&e.leftOp.horz===null;return o?e.leftOp.horz=e:e.rightOp=null,o}setHorzSegHeadingForward(e,n,c){return n.pt.x===c.pt.x?!1:(n.pt.x<c.pt.x?(e.leftOp=n,e.rightOp=c,e.leftToRight=!0):(e.leftOp=c,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let c=new S2(e.pt,e.outrec);return n?(c.next=e.next,c.next.prev=c,c.prev=e,e.next=c):(c.prev=e.prev,c.prev.next=c,c.next=e,e.prev=c),c}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let c=this.actives;for(;c!==null;){if(c.top.y===e)if(c.curX=c.top.x,E.isMaximaEdge(c)){c=this.doMaxima(c);continue}else E.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),E.isHorizontal(c)&&this.pushHorz(c);else n||(c.curX=E.topX(c,e));c=c.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),c=this.getRealOutRec(e.op2.outrec),r=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,r.prev=a,a.next=r,n===c){let s=this.newOutRec();s.pts=r,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.owner=n}else c.pts=null,this.usingPolytree?(this.setOwner(c,n),this.moveSplits(c,n)):c.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let c=q1.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,n)){case q1.IsOutside:if(c===q1.IsOutside)return!1;c=q1.IsOutside;break;case q1.IsInside:if(c===q1.IsInside)return!0;c=q1.IsInside;break;default:break}r=r.next}while(r!==e);return V1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return q1.IsOutside;let c=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==c);if(n.pt.y===e.y)return q1.IsOutside;let r=n.pt.y<e.y,a=r,s=0;for(c=n.next;c!==n;){if(r)for(;c!==n&&c.pt.y<e.y;)c=c.next;else for(;c!==n&&c.pt.y>e.y;)c=c.next;if(c===n)break;if(c.pt.y===e.y){if(c.pt.x===e.x||c.pt.y===c.prev.pt.y&&e.x<c.prev.pt.x!=e.x<c.pt.x)return q1.IsOn;if(c=c.next,c===n)break;continue}if(c.pt.x<=e.x||c.prev.pt.x<=e.x)if(c.prev.pt.x<e.x&&c.pt.x<e.x)s=1-s;else{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return q1.IsOn;i<0===r&&(s=1-s)}r=!r,c=c.next}if(r===a)return s===0?q1.IsOutside:q1.IsInside;{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return q1.IsOn;i<0===r&&(s=1-s)}return s===0?q1.IsOutside:q1.IsInside}getCleanPath(e){let n=[],c=e;for(;c.next!==e&&(c.pt.x===c.next.pt.x&&c.pt.x===c.prev.pt.x||c.pt.y===c.next.pt.y&&c.pt.y===c.prev.pt.y);)c=c.next;n.push(c.pt);let r=c;for(c=c.next;c!==e;)(c.pt.x!==c.next.pt.x||c.pt.x!==r.pt.x)&&(c.pt.y!==c.next.pt.y||c.pt.y!==r.pt.y)&&(n.push(c.pt),r=c),c=c.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let c of e.splits)c!==n.idx&&n.splits.push(c);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let c=null;for(;n!==null&&n.jump!==null;){let r=n,a=n.jump,s=a,i=a?.jump||null;for(n.jump=i;n!==s&&a!==i;)if(a.curX<n.curX){let o=a.prevInSEL;for(;this.addNewIntersectNode(o,a,e),o!==n;)o=o.prevInSEL;if(o=a,a=this.extractFromSEL(o),s=a,n!==null&&this.insert1Before2InSEL(o,n),n!==r)continue;r=o,r.jump=i,c===null?this.sel=r:c.jump=r}else n=n.nextInSEL;c=r,n=i}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(_9);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let c=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[c]);)c++;[this.intersectList[c],this.intersectList[e]]=[this.intersectList[e],this.intersectList[c]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let c=Number.NEGATIVE_INFINITY,r=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=E.topX(n,e);n.curX=a,a<c&&(r=!0),c=a,n=n.nextInAEL}return r}doMaxima(e){let n=e.prevInAEL,c=e.nextInAEL;if(E.isOpenEnd(e))return E.isHotEdge(e)&&this.addOutPt(e,e.top),E.isHorizontal(e)||(E.isHotEdge(e)&&(E.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let r=E.getMaximaPair(e);if(r===null)return c;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(r)&&this.split(r,r.top);c!==r;)this.intersectEdges(e,c,e.top),this.swapPositionsInAEL(e,c),c=e.nextInAEL;return E.isOpen(e)?(E.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(r),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(E.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(e),this.deleteFromAEL(r),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=E.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,E.setDx(e),this.isJoined(e)&&this.split(e,e.bot),E.isHorizontal(e)){E.openPathsEnabled?E.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let c=!1,r=E.nextVertex(e).pt;for(;r.y===e.top.y&&!(n&&r.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=E.nextVertex(e),e.top=r,c=!0,E.isMaximaVertex(e.vertexTop)));)r=E.nextVertex(e).pt;c&&E.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new q5(e))}addNewIntersectNode(e,n,c){let r=V1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(r===null&&(r={x:e.curX,y:c}),r.y>this.currentBotY||r.y<c){let s=Math.abs(e.dx),i=Math.abs(n.dx);s>100&&i>100?s>i?r=V1.getClosestPtOnSegment(r,e.bot,e.top):r=V1.getClosestPtOnSegment(r,n.bot,n.top):s>100?r=V1.getClosestPtOnSegment(r,e.bot,e.top):i>100?r=V1.getClosestPtOnSegment(r,n.bot,n.top):(r.y<c?r.y=c:r.y=this.currentBotY,s<i?r.x=E.topX(e,r.y):r.x=E.topX(n,r.y))}let a=qe(r,e,n);this.intersectList.push(a)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.prev;return E.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return E.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let c=e.curX,r=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:c,rightX:r}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===H0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===F1.EvenOdd){let c=0,r=0;for(;n!==e;)E.getPolyType(n)===I0.Clip?r++:E.isOpen(n)||c++,n=n.nextInAEL;e.windCount=E.isOdd(c)?1:0,e.windCount2=E.isOdd(r)?1:0}else for(;n!==e;)E.getPolyType(n)===I0.Clip?e.windCount2+=n.windDx:E.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,c=E.getPolyType(e);if(!E.openPathsEnabled){for(;n!==null&&E.getPolyType(n)!==c;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===F1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===F1.EvenOdd)for(;n!==e;)E.getPolyType(n)!==c&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)E.getPolyType(n)!==c&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(E.getPolyType(n)!==c||E.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===F1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=E.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===F1.EvenOdd)for(;n!==e;)E.getPolyType(n)!==c&&!E.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)E.getPolyType(n)!==c&&!E.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,c;switch(this.fillrule){case F1.Positive:c=e.windCount>0,n=e.windCount2>0;break;case F1.Negative:c=e.windCount<0,n=e.windCount2<0;break;default:c=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case e0.Intersection:return n;case e0.Union:return!c&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case F1.Positive:if(e.windCount!==1)return!1;break;case F1.Negative:if(e.windCount!==-1)return!1;break;case F1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case e0.Intersection:return this.fillrule===F1.Positive?e.windCount2>0:this.fillrule===F1.Negative?e.windCount2<0:e.windCount2!==0;case e0.Union:return this.fillrule===F1.Positive?e.windCount2<=0:this.fillrule===F1.Negative?e.windCount2>=0:e.windCount2===0;case e0.Difference:{let n=this.fillrule===F1.Positive?e.windCount2<=0:this.fillrule===F1.Negative?e.windCount2>=0:e.windCount2===0;return E.getPolyType(e)===I0.Subject?n:!n}case e0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,c,r=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,E.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let i=E.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(a,i.outrec),a.owner=i.outrec,this.outrecIsAscending(i)===r?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,r?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new S2(c,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new D5;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let c=this.newOutRec();c.isOpen=!0,e.windDx>0?(c.frontEdge=e,c.backEdge=null):(c.frontEdge=null,c.backEdge=e),e.outrec=c;let r=new S2(n,c);return c.pts=r,r}checkJoinLeft(e,n,c=!1){let r=e.prevInAEL;r!==null&&(!c&&e.curX!==r.curX||!E.isHotEdge(e)||!E.isHotEdge(r)||E.isHorizontal(e)||E.isHorizontal(r)||E.isOpen(e)||E.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(r,e,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),r.joinWith=H0.Right,e.joinWith=H0.Left))}checkJoinRight(e,n,c=!1){let r=e.nextInAEL;r!==null&&(!c&&e.curX!==r.curX||!E.isHotEdge(e)||!E.isHotEdge(r)||E.isHorizontal(e)||E.isHorizontal(r)||E.isOpen(e)||E.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(e,r,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),e.joinWith=H0.Right,r.joinWith=H0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,c){let r=e.x-n.x,a=e.y-n.y,s=c.x-n.x,i=c.y-n.y;if(s===0&&i===0)return!1;let o=V1.maxCoordForSafeCrossSq;if(Math.abs(r)<o&&Math.abs(a)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=r*i-s*a;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(r)*BigInt(i)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return De*u>f}let l=r*i-s*a;return l*l/(s*s+i*i)>.25}intersectEdges(e,n,c){let r;if(this.hasOpenPaths&&(E.isOpen(e)||E.isOpen(n))){if(E.isOpen(e)&&E.isOpen(n))return;if(E.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,c),this.cliptype===e0.Union){if(!E.isHotEdge(n))return}else if(n.localMin.polytype===I0.Subject)return;switch(this.fillrule){case F1.Positive:if(n.windCount!==1)return;break;case F1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(E.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),E.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(c.x===e.localMin.vertex.pt.x&&c.y===e.localMin.vertex.pt.y&&!E.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&E.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}r=this.startOpenPath(e,c)}else r=this.startOpenPath(e,c);this.setZ(e,n,r.pt);return}this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===F1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==F1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==F1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case F1.Positive:a=e.windCount,s=n.windCount;break;case F1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let i=a===0||a===1,o=s===0||s===1;if(!(!E.isHotEdge(e)&&!i||!E.isHotEdge(n)&&!o))if(E.isHotEdge(e)&&E.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==e0.Xor)r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);else if(E.isFront(e)||e.outrec===n.outrec){r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);let l=this.addLocalMinPoly(e,n,c);this.setZ(e,n,l.pt)}else{r=this.addOutPt(e,c),this.setZ(e,n,r.pt);let l=this.addOutPt(n,c);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(E.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else if(E.isHotEdge(n))r=this.addOutPt(n,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case F1.Positive:l=e.windCount2,h=n.windCount2;break;case F1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!E.isSamePolyType(e,n))r=this.addLocalMinPoly(e,n,c),this.setZ(e,n,r.pt);else if(a===1&&s===1){switch(r=null,this.cliptype){case e0.Union:if(l>0&&h>0)return;r=this.addLocalMinPoly(e,n,c);break;case e0.Difference:(E.getPolyType(e)===I0.Clip&&l>0&&h>0||E.getPolyType(e)===I0.Subject&&l<=0&&h<=0)&&(r=this.addLocalMinPoly(e,n,c));break;case e0.Xor:r=this.addLocalMinPoly(e,n,c);break;default:if(l<=0||h<=0)return;r=this.addLocalMinPoly(e,n,c);break}r&&this.setZ(e,n,r.pt)}}}swapPositionsInAEL(e,n){let c=n.nextInAEL;c!==null&&(c.prevInAEL=e);let r=e.prevInAEL;r!==null&&(r.nextInAEL=n),n.prevInAEL=r,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=c,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let c=V1.crossProductSign(e.top,n.bot,n.top);if(c!==0)return c<0;if(!E.isMaximaEdge(e)&&e.top.y>n.top.y)return V1.crossProductSign(n.bot,e.top,E.nextVertex(e).pt)<=0;if(!E.isMaximaEdge(n)&&n.top.y>e.top.y)return V1.crossProductSign(n.bot,n.top,E.nextVertex(n).pt)>=0;let r=n.bot.y,a=n.isLeftBound;return e.bot.y!==r||e.localMin.vertex.pt.y!==r?n.isLeftBound:e.isLeftBound!==a?a:V1.isCollinear(E.prevPrevVertex(e).pt,e.bot,e.top)?!0:V1.crossProductSign(E.prevPrevVertex(e).pt,n.bot,E.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==H0.None}split(e,n){e.joinWith===H0.Right?(e.joinWith=H0.None,e.nextInAEL.joinWith=H0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=H0.None,e.prevInAEL.joinWith=H0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,c){e.frontEdge=n,e.backEdge=c}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!E.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!E.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let c=e.outrec,r=E.isFront(e),a=c.pts,s=a.next;if(r&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!r&&n.x===s.pt.x&&n.y===s.pt.y)return s;let i=new S2(n,c);return s.prev=i,i.prev=a,i.next=s,a.next=i,r&&(c.pts=i),i}addLocalMaxPoly(e,n,c){if(this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c),E.isFront(e)===E.isFront(n))if(E.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(E.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let r=this.addOutPt(e,c);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=r,this.usingPolytree){let s=E.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else E.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return r}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let c=n;for(;c!==null&&c!==e;)c=c.owner;c!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let c=e.outrec.pts,r=n.outrec.pts,a=c.next,s=r.next;E.isFront(e)?(s.prev=c,c.next=s,r.next=a,a.prev=r,e.outrec.pts=r,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=r,r.next=a,c.next=s,s.prev=c,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),E.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let c=e.outrec,r=n.outrec;if(c===r){let a=c.frontEdge;c.frontEdge=c.backEdge,c.backEdge=a;return}c!==null&&(e===c.frontEdge?c.frontEdge=n:c.backEdge=n),r!==null&&(n===r.frontEdge?r.frontEdge=e:r.backEdge=e),e.outrec=r,n.outrec=c}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(E.ptsReallyClose(e.prev.pt,e.next.pt)||E.ptsReallyClose(e.pt,e.next.pt)||E.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,c,r){if(e===null||e.next===e||!c&&e.next===e.prev)return!1;r.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),r.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,r.push(a)),n?s=s.prev:s=s.next;return r.length!==3||c||!E.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts===null)continue;let a=[];r.isOpen?E.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(r),E.buildPath(r.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts!==null){if(r.isOpen){let a=[];E.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(r)&&this.recursiveCheckOwners(r,e)}}}checkBounds(e){return e.pts===null?!1:t3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!E.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=V1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||t3.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,c=n;for(;;){if(c!==null&&V1.isCollinear(c.prev.pt,c.pt,c.next.pt)&&(c.pt.x===c.prev.pt.x&&c.pt.y===c.prev.pt.y||c.pt.x===c.next.pt.x&&c.pt.y===c.next.pt.y||!this.preserveCollinear||V1.dotProductSign(c.prev.pt,c.pt,c.next.pt)<0)){if(c===e.pts&&(e.pts=c.prev),c=this.disposeOutPt(c),!this.isValidClosedPath(c)){e.pts=null;return}n=c;continue}if(c===null||(c=c.next,c===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!E.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&V1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let c=n.prev,r=n.next.next;e.pts=c;let a=V1.getLineIntersectPt(c.pt,n.pt,n.next.pt,r.pt);this.zCallbackInternal&&this.zCallbackInternal(c.pt,n.pt,n.next.pt,r.pt,a);let s=E.areaOutPt(c),i=s<K3?-s:s;if(i<De){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<K3?-o:o;if(a.x===c.pt.x&&a.y===c.pt.y||a.x===r.pt.x&&a.y===r.pt.y)r.prev=c,c.next=r;else{let f=new S2(a,e);f.prev=c,f.next=r,r.prev=f,c.next=f}if(!(l>G9)||!(l>i)&&o>K3!=s>K3)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new S2(a,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(c,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=V1.maxCoordForSafeAreaProduct,c=0,r=!0,a=e;do{let i=a.prev,o=a.pt;if(Math.abs(i.pt.x)>=n||Math.abs(i.pt.y)>=n||Math.abs(o.x)>=n||Math.abs(o.y)>=n){r=!1;break}c+=(i.pt.y+o.y)*(i.pt.x-o.x),a=a.next}while(a!==e);if(r)return BigInt(Math.round(c));let s=K3;a=e;do{let i=a.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(a.pt.x)){let o=BigInt(i.pt.y)+BigInt(a.pt.y),l=BigInt(i.pt.x)-BigInt(a.pt.x);s+=o*l}else{let o=i.pt.y+a.pt.y,l=i.pt.x-a.pt.x;s+=BigInt(Math.round(o*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,c){let r=V1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<r&&Math.abs(e.y)<r&&Math.abs(n.x)<r&&Math.abs(n.y)<r&&Math.abs(c.x)<r&&Math.abs(c.y)<r){let s=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(c.y)){let s=(BigInt(c.y)+BigInt(e.y))*(BigInt(c.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),o=(BigInt(n.y)+BigInt(c.y))*(BigInt(n.x)-BigInt(c.x));return s+i+o}let a=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(a))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let c=0;c<n.length;c++){let r=this.outrecList[n[c]];if(r.pts===null&&r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(r=this.getRealOutRec(r),!(r===null||r===e||r.recursiveSplit===e)){if(r.recursiveSplit=e,r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(!(!this.checkBounds(r)||!this.containsRect(r.bounds,e.bounds)||!this.path1InsidePath2(e.pts,r.pts)))return this.isValidOwner(e,r)||(r.owner=e.owner),e.owner=r,!0}}return!1}};D(E,"openPathsEnabled",!0);var B5=E,p2=class extends B5{constructor(){super(...arguments);D(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,c,r=!1){super.addPath(n,c,r)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,c,r=!1){super.addPaths(n,c,r)}addSubject(n){this.addPaths(n,I0.Subject)}addOpenSubject(n){this.addPaths(n,I0.Subject,!0)}addClip(n){this.addPaths(n,I0.Clip)}execute(n,c,r,a){if(Array.isArray(r)){let s=r,i=a;s.length=0,i&&(i.length=0);try{this.executeInternal(n,c),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=r,i=a;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(n,c),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var e6={area(t){return V1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let c=t[n-1];for(let r of t)e+=(c.y+r.y)*(c.x-r.x),c=r;return e*.5},scalePath64(t,e){let n=V1.maxSafeCoordinateForScale(e),c=[];for(let r of t)V1.checkSafeScaleValue(r.x,n,"scalePath64"),V1.checkSafeScaleValue(r.y,n,"scalePath64"),c.push({x:Math.round(r.x*e),y:Math.round(r.y*e)});return c},scalePaths64(t,e){let n=[];for(let c of t)n.push(e6.scalePath64(c,e));return n},scalePathD(t,e){let n=[];for(let c of t)n.push({x:c.x*e,y:c.y*e});return n},scalePathsD(t,e){let n=[];for(let c of t)n.push(e6.scalePathD(c,e));return n}};var O0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(O0||(O0={}));var s0;(function(t){t[t.Polygon=0]="Polygon",t[t.Joined=1]="Joined",t[t.Butt=2]="Butt",t[t.Square=3]="Square",t[t.Round=4]="Round"})(s0||(s0={}));var t6=class{constructor(e,n,c=s0.Polygon){D(this,"inPaths");D(this,"joinType");D(this,"endType");D(this,"pathsReversed");D(this,"lowestPathIdx");this.joinType=n,this.endType=c;let r=c===s0.Polygon||c===s0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(n3.stripDuplicates(a,r));if(c===s0.Polygon){let a=n3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},a0=class a0{constructor(e=2,n=0,c=!1,r=!1){D(this,"groupList",[]);D(this,"pathOut",[]);D(this,"normals",[]);D(this,"solution",[]);D(this,"solutionTree",null);D(this,"groupDelta",0);D(this,"delta",0);D(this,"mitLimSqr",0);D(this,"stepsPerRad",0);D(this,"stepSin",0);D(this,"stepCos",0);D(this,"joinType",O0.Bevel);D(this,"endType",s0.Polygon);D(this,"arcTolerance",0);D(this,"mergeGroups",!0);D(this,"miterLimit",2);D(this,"preserveCollinear",!1);D(this,"reverseSolution",!1);D(this,"zCallback");D(this,"deltaCallback",null);D(this,"ZCB",(e,n,c,r,a)=>{(e.z||0)!==0&&(e.z===c.z||e.z===r.z)?a.z=e.z:(c.z||0)!==0&&c.z===n.z?a.z=c.z:(n.z||0)!==0&&n.z===r.z?a.z=n.z:this.zCallback&&this.zCallback(e,n,c,r,a)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=c,this.reverseSolution=r}clear(){this.groupList.length=0}addPath(e,n,c){if(e.length===0)return;let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c){e.length!==0&&this.groupList.push(new t6(e,n,c))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===s0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===s0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/a0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),c=n?F1.Negative:F1.Positive,r=new p2;r.preserveCollinear=this.preserveCollinear,r.reverseSolution=this.reverseSolution!==n,r.zCallback=this.ZCB,r.addSubject(this.solution),this.solutionTree!==null?r.execute(e0.Union,c,this.solutionTree):r.execute(e0.Union,c,this.solution)}execute(e,n){if(Array.isArray(n)){let c=n;c.length=0,this.solution=c,this.executeInternal(e)}else{let c=n;c.clear(),this.solutionTree=c,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let c=n.x-e.x,r=n.y-e.y;if(c===0&&r===0)return{x:0,y:0};let a=1/Math.sqrt(c*c+r*r);return{x:r*a,y:-c*a}}static getLowestPathInfo(e){let n=-1,c=!1,r={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let i of e[a])if(!(i.y<r.y||i.y===r.y&&i.x>=r.x)){if(s===Number.MAX_VALUE){if(s=a0.area(e[a]),s===0)break;c=s<0}n=a,r.x=i.x,r.y=i.y}}return{idx:n,isNegArea:c}}static translatePoint(e,n,c){return{x:e.x+n,y:e.y+c,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=a0.hypotenuse(e.x,e.y);if(a0.almostZero(n))return{x:0,y:0};let c=1/n;return{x:e.x*c,y:e.y*c}}static getAvgUnitVector(e,n){return a0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,c,r){if(V1.isAlmostZero(e.x-n.x)){if(V1.isAlmostZero(c.x-r.x))return{x:0,y:0};let a=(r.y-c.y)/(r.x-c.x),s=c.y-a*c.x;return{x:e.x,y:a*e.x+s}}if(V1.isAlmostZero(c.x-r.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:c.x,y:a*c.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,i=(r.y-c.y)/(r.x-c.x),o=c.y-i*c.x;if(V1.isAlmostZero(a-i))return{x:0,y:0};let l=(o-s)/(a-i);return{x:l,y:a*l+s}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,c){let r,a,s=e[n].z||0;if(n===c){let i=Math.abs(this.groupDelta);r={x:Math.round(e[n].x-i*this.normals[n].x),y:Math.round(e[n].y-i*this.normals[n].y),z:s},a={x:Math.round(e[n].x+i*this.normals[n].x),y:Math.round(e[n].y+i*this.normals[n].y),z:s}}else r={x:Math.round(e[n].x+this.groupDelta*this.normals[c].x),y:Math.round(e[n].y+this.groupDelta*this.normals[c].y),z:s},a={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:s};this.pathOut.push(r),this.pathOut.push(a)}doSquare(e,n,c){let r;n===c?r={x:this.normals[n].y,y:-this.normals[n].x}:r=a0.getAvgUnitVector({x:-this.normals[c].y,y:this.normals[c].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=a0.translatePoint(s,a*r.x,a*r.y);let i=a0.translatePoint(s,this.groupDelta*r.y,this.groupDelta*-r.x),o=a0.translatePoint(s,this.groupDelta*-r.y,this.groupDelta*r.x),l=this.getPerpendicD(e[c],this.normals[c]);if(n===c){let h={x:l.x+r.x*this.groupDelta,y:l.y+r.y*this.groupDelta},u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s))),this.pathOut.push(m2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[c]),u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(u)),this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s)))}}doMiter(e,n,c,r){let a=this.groupDelta/(r+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[c].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[c].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,c,r){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*a0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let a=e[n],s=a.z||0,i={x:this.normals[c].x*this.groupDelta,y:this.normals[c].y*this.groupDelta};n===c&&$5.negate(i),this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});let o=Math.ceil(this.stepsPerRad*Math.abs(r));for(let l=1;l<o;l++)i={x:i.x*this.stepCos-this.stepSin*i.y,y:i.x*this.stepSin+i.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});this.pathOut.push(this.getPerpendic(e[n],this.normals[n]))}buildNormals(e){let n=e.length;if(this.normals.length=0,n!==0){for(let c=0;c<n-1;c++)this.normals.push(a0.getUnitNormal(e[c],e[c+1]));this.normals.push(a0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,c,r){if(m2.equals(n[c],n[r]))return;let a=V1.crossProductD(this.normals[c],this.normals[r]),s=V1.dotProductD(this.normals[c],this.normals[r]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,c,r),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<a0.Tolerance){this.pathOut.push(n[c]);return}if(s>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[c],this.normals[r])),this.pathOut.push(n[c]),this.pathOut.push(this.getPerpendic(n[c],this.normals[c]));else if(s>.999&&this.joinType!==O0.Round)this.doMiter(n,c,r,s);else switch(this.joinType){case O0.Miter:s>this.mitLimSqr-1?this.doMiter(n,c,r,s):this.doSquare(n,c,r);break;case O0.Round:this.doRound(n,c,r,Math.atan2(a,s));break;case O0.Bevel:this.doBevel(n,c,r);break;default:this.doSquare(n,c,r);break}}offsetPolygon(e,n){this.pathOut=[];let c=n.length,r=c-1;for(let a=0;a<c;a++)this.offsetPoint(e,n,a,r),r=a;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let c=[...n].reverse();this.buildNormals(c),this.offsetPolygon(e,c)}offsetOpenPath(e,n){this.pathOut=[];let c=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<a0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case s0.Butt:this.doBevel(n,0,0);break;case s0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let r=1,a=0;r<c;r++)this.offsetPoint(e,n,r,a),a=r;for(let r=c;r>0;r--)this.normals[r]={x:-this.normals[r-1].x,y:-this.normals[r-1].y};if(this.normals[0]=this.normals[c],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,c,c)),Math.abs(this.groupDelta)<a0.Tolerance)this.pathOut.push(n[c]);else switch(this.endType){case s0.Butt:this.doBevel(n,c,c);break;case s0.Round:this.doRound(n,c,c,Math.PI);break;default:this.doSquare(n,c,c);break}for(let r=c-1,a=c;r>0;r--)this.offsetPoint(e,n,r,a),a=r;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===s0.Polygon?(e.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=e.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===O0.Round||e.endType===s0.Round){let c=this.arcTolerance>.01?this.arcTolerance:n*a0.arc_const,r=Math.PI/Math.acos(1-c/n);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}for(let c of e.inPaths){this.pathOut=[];let r=c.length;if(r===1){let a=c[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(c,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=a.z||0;if(e.endType===s0.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=a0.ellipse(a,Math.abs(this.groupDelta),Math.abs(this.groupDelta),i),s!==0)for(let o=0;o<this.pathOut.length;o++)this.pathOut[o].z=s}else{let i=Math.ceil(Math.abs(this.groupDelta)),o={left:a.x-i,top:a.y-i,right:a.x+i,bottom:a.y+i};this.pathOut=[{x:o.left,y:o.top,z:s},{x:o.right,y:o.top,z:s},{x:o.right,y:o.bottom,z:s},{x:o.left,y:o.bottom,z:s}]}this.solution.push(this.pathOut);continue}switch(r===2&&e.endType===s0.Joined&&(this.endType=e.joinType===O0.Round?s0.Round:s0.Square),this.buildNormals(c),this.endType){case s0.Polygon:this.offsetPolygon(e,c);break;case s0.Joined:this.offsetOpenJoined(e,c);break;default:this.offsetOpenPath(e,c);break}}}static stripDuplicates(e,n){let c=e.length,r=[];if(c===0)return r;let a=e[0];r.push(a);for(let s=1;s<c;s++)m2.equals(a,e[s])||(a=e[s],r.push(a));return n&&m2.equals(a,r[0])&&r.pop(),r}static area(e){return V1.area(e)}static sqr(e){return e*e}static ellipse(e,n,c=0,r=0){if(n<=0)return[];c<=0&&(c=n),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((n+c)/2)));let a=Math.sin(2*Math.PI/r),s=Math.cos(2*Math.PI/r),i=s,o=a,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<r;++h){l.push({x:Math.round(e.x+n*i),y:Math.round(e.y+c*o)});let u=i*s-o*a;o=o*s+i*a,i=u}return l}};D(a0,"Tolerance",1e-12),D(a0,"arc_const",.002);var n3=a0;var Po=BigInt(2);function c6(t,e,n){return typeof e=="number"?n6(e0.Union,t,null,e):n6(e0.Union,t,e,n)}function n6(t,e,n,c){let r=[];if(e===null)return r;let a=new p2;return a.addPaths(e,I0.Subject),n!==null&&a.addPaths(n,I0.Clip),a.execute(t,c,r),r}function G5(t,e,n,c,r=2,a=0){let s=new n3(r,a);s.addPaths(t,n,c);let i=[];return s.execute(e,i),i}var n2=1e4,r6=[1,0,0,1,0,0];function J0(){return{layers:new Map,parts:[]}}function z0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function D2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function Be(t){if(t.parts.length)return!1;for(let e of t.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var Ge=t=>t.map(e=>e.map(([n,c])=>({x:Math.round(n*n2),y:Math.round(c*n2)})));function Z9(t){let e=(c,r,a)=>(r.x-c.x)*(a.y-r.y)-(r.y-c.y)*(a.x-r.x)===0,n=[];for(let c of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],c);)n.pop();let r=n[n.length-1];(!r||r.x!==c.x||r.y!==c.y)&&n.push(c)}for(let c=!0;c&&n.length>=3;){let r=n.length;c=!0,n[r-1].x===n[0].x&&n[r-1].y===n[0].y||e(n[r-2],n[r-1],n[0])?n.pop():e(n[r-1],n[0],n[1])?n.shift():c=!1}return n}var r5=t=>Ge(t).map(Z9),s5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/n2,n.y/n2]));function w1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?F1.EvenOdd:F1.NonZero;return s5(c6(r5(t),n)).filter(c=>c.length>=3)}function a6(t,e,n){if(!e.length)return[];let c=new p2;c.addSubject(r5(e)),n.length&&c.addClip(r5(n));let r=[];return c.execute(t,F1.NonZero,r),s5(r).filter(a=>a.length>=3)}var y0=(t,e)=>e.length?a6(e0.Difference,t,e):w1(t),b0=(t,e)=>a6(e0.Intersection,t,e),M3=(t,e)=>a6(e0.Xor,t,e);function g2(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let c=[];for(let p of e)for(let g=0;g<p.length;g++){let v=p[g],y=p[(g+1)%p.length];(v[0]!==y[0]||v[1]!==y[1])&&c.push([v,y])}if(!c.length)return n==="outside"?t:[];let r=k0(e),a=Math.max(r[2]-r[0],r[3]-r[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=p=>Math.floor(p/a),i=new Map,o=new Map,l=(p,g,v)=>{let y=p.get(g);y?y[y.length-1]!==v&&y.push(v):p.set(g,[v])};c.forEach(([p,g],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(g[0]-p[0],g[1]-p[1])/a*2));for(let b=0;b<=y;b++){let x=p[0]+(g[0]-p[0])*b/y,M=p[1]+(g[1]-p[1])*b/y;for(let S of[-1,0,1])for(let w of[-1,0,1])l(i,`${s(x)+S},${s(M)+w}`,v)}for(let b=s(Math.min(p[1],g[1]));b<=s(Math.max(p[1],g[1]));b++)l(o,b,v)});let h=(p,g)=>{let v=new Set,y=Math.max(1,Math.ceil(Math.hypot(g[0]-p[0],g[1]-p[1])/a*2));for(let b=0;b<=y;b++){let x=p[0]+(g[0]-p[0])*b/y,M=p[1]+(g[1]-p[1])*b/y;for(let S of i.get(`${s(x)},${s(M)}`)??[])v.add(S)}return v},u=.5/n2,f=p=>{for(let v of i.get(`${s(p[0])},${s(p[1])}`)??[]){let[y,b]=c[v],x=b[0]-y[0],M=b[1]-y[1],S=Math.max(0,Math.min(1,((p[0]-y[0])*x+(p[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(p[0]-y[0]-S*x,p[1]-y[1]-S*M)<=u)return}let g=0;for(let v of o.get(s(p[1]))??[]){let[y,b]=c[v],x=(b[0]-y[0])*(p[1]-y[1])-(p[0]-y[0])*(b[1]-y[1]);y[1]<=p[1]?b[1]>p[1]&&x>0&&g++:b[1]<=p[1]&&x<0&&g--}return g!==0},d=p=>Math.round(p*n2)/n2,m=[];for(let p of t){let g=null,v=()=>{g&&g.length>=2&&m.push(g),g=null};for(let y=1;y<p.length;y++){let b=p[y-1],x=p[y],M=x[0]-b[0],S=x[1]-b[1];if(!M&&!S)continue;let w=[0,1];for(let z of h(b,x)){let[C,k]=c[z],T=k[0]-C[0],q=k[1]-C[1],R=M*q-S*T;if(Math.abs(R)>1e-15){let U=((C[0]-b[0])*q-(C[1]-b[1])*T)/R,j=((C[0]-b[0])*S-(C[1]-b[1])*M)/R;U>0&&U<1&&j>=0&&j<=1&&w.push(U)}else{let U=M*M+S*S;for(let j of[C,k]){let V=((j[0]-b[0])*M+(j[1]-b[1])*S)/U,Q=Math.abs((j[0]-b[0])*S-(j[1]-b[1])*M)/Math.sqrt(U);V>0&&V<1&&Q<=u&&w.push(V)}}}w.sort((z,C)=>z-C);for(let z=1;z<w.length;z++){if(w[z]-w[z-1]<1e-12)continue;let C=[d(b[0]+M*w[z-1]),d(b[1]+S*w[z-1])],k=[d(b[0]+M*w[z]),d(b[1]+S*w[z])],T=(w[z-1]+w[z])/2,q=f([b[0]+M*T,b[1]+S*T]);if(q!==void 0&&q===(n==="inside")){let R=g?g[g.length-1]:void 0;g&&R&&R[0]===C[0]&&R[1]===C[1]?(k[0]!==R[0]||k[1]!==R[1])&&g.push(k):(v(),g=[C,k])}else v()}}v()}return m}function p0(t,e,n="round",c=.01){if(!t.length)return[];if(e===0)return w1(t);let r=n==="round"?O0.Round:n==="square"?O0.Square:O0.Miter,a=G5(r5(w1(t)),e*n2,r,s0.Polygon,2,c*n2);return s5(a).filter(s=>s.length>=3)}function j5(t,e){if(!t.length||e<=0)return[];let n=G5(Ge(t),e/2*n2,O0.Round,s0.Round,2,.01*n2);return s5(n)}function B0(t){if(!t.length)return[];let e=new c5,n=new p2;n.addSubject(r5(t)),n.execute(e0.Union,F1.NonZero,e);let c=[],r=a=>{for(let s=0;s<a.count;s++){let i=a.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),r(h)}c.push(s5(o))}};return r(e),c}function H1(t){let e=0;for(let n=0,c=t.length-1;n<t.length;c=n++)e+=(t[c][0]+t[n][0])*(t[c][1]-t[n][1]);return-e/2}function w3(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}function a5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function Ne(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,c=new Map;for(let[r,a]of t)c.set(r,{regions:a.regions.map(s=>{let i=s.map(o=>a5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>a5(e,i)))});return c}function z3(t,e){return{layers:Ne(t.layers,e),parts:t.parts.map(n=>({...n,layers:Ne(n.layers,e)}))}}function q2(t){let e=J0();for(let n of t){for(let[c,r]of n.layers){let a=e.layers.get(c)??{regions:[],lines:[]};for(let s of r.regions)a.regions.push(s);for(let s of r.lines)a.lines.push(s);e.layers.set(c,a)}for(let c of n.parts)e.parts.push(c)}return e}function Ue(t,e){let n={regions:[],lines:[]};for(let c of t.values()){for(let r of c.regions)n.regions.push(r);for(let r of c.lines)n.lines.push(r)}return new Map([[e,n]])}function i5(t,e){if(t.parts.length&&e!=="guide")throw new Error(`a part cannot go on the ${e} layer as a whole. Put ${e}() inside part() instead.`);return{layers:Ue(t.layers,e),parts:t.parts.map(n=>({...n,layers:Ue(n.layers,e)}))}}function k0(t){let e=1/0,n=1/0,c=-1/0,r=-1/0;for(let a of t)for(let[s,i]of a)s<e&&(e=s),i<n&&(n=i),s>c&&(c=s),i>r&&(r=i);return e===1/0?null:[e,n,c,r]}function $0(t,e){let n=[];for(let[c,r]of t)if(!e?.(c))for(let a of[...r.regions,...r.lines])n.push(a);return k0(n)}function je(t){let e=[...t].sort((a,s)=>a[0]-s[0]||a[1]-s[1]);if(e.length<3)return e;let n=(a,s,i)=>(s[0]-a[0])*(i[1]-a[1])-(s[1]-a[1])*(i[0]-a[0]),c=[];for(let a of e){for(;c.length>=2&&n(c[c.length-2],c[c.length-1],a)<=0;)c.pop();c.push(a)}let r=[];for(let a=e.length-1;a>=0;a--){let s=e[a];for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}return r.pop(),c.pop(),c.concat(r)}function _e(t,e,n,c){return t<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/n,t*2*Math.PI/c)),5)}function k3(t,e,n){let c=[];for(let r=0;r<n;r++){let a=2*Math.PI*r/n;c.push([t*Math.cos(a),e*Math.sin(a)])}return c}function We(t,e,n,c){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let r=Math.max(1,Math.ceil(c(n)/4)),a=[],s=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[i,o,l]of s)for(let h=0;h<=r;h++){let u=(l+90*h/r)*Math.PI/180;a.push([i+n*Math.cos(u),o+n*Math.sin(u)])}return a}var Xe=Math.PI/180;function $1(t,e){let n=new Array(16).fill(0);for(let c=0;c<4;c++)for(let r=0;r<4;r++)for(let a=0;a<4;a++)n[c*4+r]+=t[c*4+a]*e[a*4+r];return n}function _5(t,e){let n=Math.cos(e*Xe),c=Math.sin(e*Xe);return t===0?[1,0,0,0,0,n,-c,0,0,c,n,0,0,0,0,1]:t===1?[n,0,c,0,0,1,0,0,-c,0,n,0,0,0,0,1]:[n,-c,0,0,c,n,0,0,0,0,1,0,0,0,0,1]}var s6=t=>Math.abs(t)<1e-12?0:t;function K0(t){if(t.matrix)return t.matrix.map(s6);let[e,n,c]=t.rotate,r=$1(_5(2,c),$1(_5(1,n),_5(0,e)));return r[3]=t.at[0],r[7]=t.at[1],r[11]=t.at[2],r.map(s6)}function A3(t,e,n,c){return[t[0]*e+t[1]*n+t[2]*c+t[3],t[4]*e+t[5]*n+t[6]*c+t[7],t[8]*e+t[9]*n+t[10]*c+t[11]]}function Ke(t){let[e,n,c]=[t[3],t[7],t[11]],r=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[r[0],r[1],r[2],-(r[0]*e+r[1]*n+r[2]*c),r[3],r[4],r[5],-(r[3]*e+r[4]*n+r[5]*c),r[6],r[7],r[8],-(r[6]*e+r[7]*n+r[8]*c),0,0,0,1]}function W5(t){let[e,n,c,r]=[1/0,1/0,-1/0,-1/0];for(let a of t)for(let[s,i]of a)e=Math.min(e,s),n=Math.min(n,i),c=Math.max(c,s),r=Math.max(r,i);return[e,n,c,r]}function o5(t){let[e,n,c,r]=W5(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,c])for(let o of[n,r])for(let l of[0,t.thickness]){let h=A3(t.matrix,i,o,l);for(let u=0;u<3;u++)a[u]=Math.min(a[u],h[u]),s[u]=Math.max(s[u],h[u])}return[a,s]}function Qe(t,e,n=10){let c=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(o5))for(let f=0;f<3;f++)c[f]=Math.min(c[f],h[f]),r[f]=Math.max(r[f],u[f]);let a=e.map(h=>W5(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),r[0]-c[0]),i=0,o=0,l=0;return e.map((h,u)=>{let[f,d,m,p]=a[u];i>0&&i+m-f>s&&(i=0,o+=l+n,l=0);let g=[1,0,0,r[0]+n+i-f,0,1,0,c[1]+o-d,0,0,1,c[2],0,0,0,1];return i+=m-f+n,l=Math.max(l,p-d),{...h,matrix:g.map(s6)}})}var Y9=(t,e,n)=>[0,1,2].every(c=>t[0][c]<e[1][c]-n&&e[0][c]<t[1][c]-n),S3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],i6=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ze=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],X5=t=>[t[2],t[6],t[10]],Ye=t=>[t[3],t[7],t[11]],J9=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[4]*e[0]+t[5]*e[1]+t[6]*e[2],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]];function L3(t,e,n){let c=n[0]*n[0]+n[1]*n[1],r=[];for(let a of t)for(let s=0,i=a.length-1;s<a.length;i=s++){let o=a[i],l=a[s],h=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=o[0]+(l[0]-o[0])*f-e[0],m=o[1]+(l[1]-o[1])*f-e[1];r.push((d*n[0]+m*n[1])/c)}return r.sort((a,s)=>a-s)}function o6(t,e,n){let c=0,r=0,a=0;for(;r+1<t.length&&a+1<e.length;){let s=Math.min(t[r+1],e[a+1])-Math.max(t[r],e[a]);s>n&&(c+=s),t[r+1]<e[a+1]?r+=2:a+=2}return c}function Z5(t,e,n,c){let r=t+n,a=e-n;if(a<=r)return{at:[],size:0};let s=Math.max(4,Math.ceil((a-r)/c));return{at:Array.from({length:s},(i,o)=>r+(a-r)*(o+.5)/s),size:(a-r)/s}}function Je(t,e,n){let c=A3(t,e[0],e[1],e[2]),r=J9(t,n);return[[c[0],c[1]],[r[0],r[1]]]}function K9(t,e,n,c,r,a,s){let i=X5(t.matrix),o=X5(e.matrix),l=i6(i,o),h=Math.hypot(...l),u=[l[0]/h,l[1]/h,l[2]/h],f=i6(u,i),d=S3(o,f),m=Ye(t.matrix),p=S3(o,Ye(e.matrix)),g=1/0,v=-1/0;for(let S of e.outline)for(let[w,z]of S)for(let C of[0,e.thickness]){let k=A3(e.matrix,w,z,C),T=S3(i,[k[0]-m[0],k[1]-m[1],k[2]-m[2]]);T<g&&(g=T),T>v&&(v=T)}let y=Z5(Math.max(0,g),Math.min(t.thickness,v),r,a),b=1/0,x=-1/0;for(let S of t.outline)for(let[w,z]of S){let C=A3(t.matrix,w,z,0),k=S3(f,[C[0]-m[0],C[1]-m[1],C[2]-m[2]]);k<b&&(b=k),k>x&&(x=k)}let M=0;for(let S of y.at){let w=Ze(m,i,S),z=(p-S3(o,w))/d,C=(p+e.thickness-S3(o,w))/d,k=Z5(Math.max(b,Math.min(z,C)),Math.min(x,Math.max(z,C)),r,a);for(let T of k.at){let q=Ze(w,f,T),[R,U]=Je(n,q,u),[j,V]=Je(c,q,u);if(M+=o6(L3(t.outline,R,U),L3(e.outline,j,V),r)*y.size*k.size,M>s)return!0}}return!1}function Q9(t,e,n,c,r,a){let s=[0,1,2,3].flatMap(w=>[0,1,2,3].map(z=>{let C=0;for(let k=0;k<4;k++)C+=n[w*4+k]*e.matrix[k*4+z];return C})),i=s[11],o=s[11]+s[10]*e.thickness,l=Math.min(t.thickness,Math.max(i,o))-Math.max(0,Math.min(i,o));if(l<=c)return!1;let h=e.outline.map(w=>w.map(([z,C])=>[s[0]*z+s[1]*C+s[3],s[4]*z+s[5]*C+s[7]])),[u,f,d,m]=W5(t.outline),[p,g,v,y]=W5(h),b=Z5(Math.max(f,g),Math.min(m,y),c,r),x=0;for(let w of b.at)if(x+=o6(L3(t.outline,[0,w],[1,0]),L3(h,[0,w],[1,0]),c)*b.size*l,x>a)return!0;let M=Z5(Math.max(u,p),Math.min(d,v),c,r),S=0;for(let w of M.at)if(S+=o6(L3(t.outline,[w,0],[0,1]),L3(h,[w,0],[0,1]),c)*M.size*l,S>a)return!0;return!1}function e7(t,e=1/0,n=.05,c=.25,r=.1){let a=t.map(o5),s=t.map(h=>Ke(h.matrix)),i=t.map((h,u)=>u).sort((h,u)=>a[h][0][0]-a[u][0][0]),o=[],l=0;for(let h=0;h<i.length;h++)for(let u=h+1;u<i.length;u++){let f=i[h],d=i[u];if(a[d][0][0]>=a[f][1][0]-n)break;if(!Y9(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[m,p]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]];(Math.hypot(...i6(X5(m.matrix),X5(p.matrix)))<1e-9?Q9(m,p,g,n,c,r):K9(m,p,g,v,n,c,r))&&o.push([m,p])}return{found:o,complete:!0}}function D0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var l6=D0(0,0,0);function S0(t){return Ke(t)}function t7(t,e,n=t.angle,c=t.x1){let r=c-t.x0;if(!n||!(r>0))return D0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return $1(D0(t.x0,0,s),$1(_5(1,-n),D0(-t.x0-r,0,-s)))}function l5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function Y5(t,e){let n=[D0(0,0,0)];for(let c of l5(t))n.push($1(n[n.length-1],t7(c,e)));return n}function h6(t,e,n){let c=l5(t),r=Y5(c,e);for(let a=c.length-1;a>=0;a--){let s=c[a];if(n[0]>=s.x1)return A3(r[a+1],...n);if(n[0]>s.x0){let i=(n[0]-s.x0)/(s.x1-s.x0),o=$1(r[a],t7(s,e,s.angle*i,n[0]));return A3(o,...n)}}return n}function n7(t,e){return l5(t).filter(n=>(n.x0+n.x1)/2<e).length}function J5(t){if(!t.bends?.length)return[t];let e=l5(t.bends),n=Y5(e,t.thickness),c=1e7,r=[];for(let a=0;a<=e.length;a++){let s=a===0?-c:e[a-1].x1,i=a===e.length?c:e[a].x0;if(!(i>s))continue;let o=[[s,-c],[i,-c],[i,c],[s,c]],l=b0(t.outline,[o]);l.length&&r.push({...t,outline:l,bends:void 0,matrix:$1(t.matrix,n[a])})}return r}var en=2e3;function u6(t,e,n=2){if(!e?.length)return B0(t);let c=1e7,r=1/0,a=-1/0;for(let f of t)for(let[d]of f)r=Math.min(r,d),a=Math.max(a,d);let s=l5(e).map(f=>[Math.max(f.x0,r),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,m])=>f+(m-d),0),o=Math.max(n,i/en),l=[];for(let[f,d]of s){let m=Math.max(1,Math.ceil((d-f)/o));for(let p=0;p<=m;p++)l.push(f+(d-f)*p/m)}let h=[-c,...l.sort((f,d)=>f-d),c],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-c],[h[f+1],-c],[h[f+1],c],[h[f],c]];for(let m of B0(b0(t,[d])))u.push(m)}return u}var N2=1e6,K5=.01,c7=t=>H1(t)<0?[...t].reverse():t;function tn(t,e){let n=$1(S0(t.matrix),e.matrix),[c,r]=[n[8],n[9]],a=Math.hypot(c,r);if(a<1e-9)return[];let s=0,i=e.thickness,o=w=>(-n[11]-Math.max(n[10]*s,n[10]*i)+w)/a,l=w=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-w)/a;if(!(l(K5)>o(K5)))return[];let[h,u]=[c/a,r/a],[f,d]=[-u,h],m=(w,z)=>[[h*w-f*N2,u*w-d*N2],[h*z-f*N2,u*z-d*N2],[h*z+f*N2,u*z+d*N2],[h*w+f*N2,u*w+d*N2]],p=1/0,g=-1/0;for(let w of e.outline)for(let[z,C]of w)for(let k of[s,i]){let T=n[8]*z+n[9]*C+n[10]*k+n[11];T<p&&(p=T),T>g&&(g=T)}if(Math.min(t.thickness,g)-Math.max(0,p)<Math.min(1,t.thickness/2))return[];let v=(w,z)=>b0(e.outline,[c7(m(w,z))]).filter(C=>Math.abs(H1(C))>1e-6);if(!v(o(K5),l(K5)).length)return[];let y=v(o(0),l(0));if(!y.length)return[];let b=w=>([z,C])=>[n[0]*z+n[1]*C+n[2]*w+n[3],n[4]*z+n[5]*C+n[6]*w+n[7]],x=n[0]*n[5]-n[1]*n[4]<0,M=w=>y.map(z=>{let C=z.map(b(w));return x?C.reverse():C}),S=[];for(let w of y)for(let z=0;z<w.length;z++){let C=w[z],k=w[(z+1)%w.length],T=[b(s)(C),b(s)(k),b(i)(k),b(i)(C)];Math.abs(H1(T))>1e-9&&S.push(c7(T))}return w1([...M(s),...M(i),...S],"nonzero")}function r7(t,e,n){let c=[];for(let a of e)for(let s of tn(t,a))c.push(s);if(!c.length)return[];let r=B0(b0(w1(c),t.outline)).filter(a=>a.reduce((s,i)=>s+H1(i),0)>1e-4);return r.length?p0(r.flat(),n/2,"miter"):[]}var Q0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",A2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",s7=t=>typeof t=="number",R0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",G0=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function f6(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let c of e)f6(t,c,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function Q5(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let c=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(c>e)throw new Error(`a range of ${c} items is more than the limit of ${e}`);for(let r=0;r<c;r++)n.push(t.start+r*t.step);return n}function h0(t){return t===void 0||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="number"?!Number.isNaN(t):!0}var a7=(t,e,n)=>Q0(t)&&Q0(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:R0(t)&&R0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([c,r])=>e.fields.has(c)&&C3(r,e.fields.get(c),n)):t===e;function C3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return a7(t,e,n);let c=new Map,r=[],a=(s,i)=>{let o=c.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||c.set(s,o=new Set),o.add(i),r.push([s,i,0]),!0)};if(!a(t,e))return!1;for(;r.length;){let s=r[r.length-1];if(s[2]===s[0].length){r.pop();continue}let i=s[0][s[2]],o=s[1][s[2]++];if(n?.(),Array.isArray(i)&&Array.isArray(o)?!a(i,o):!a7(i,o,n))return!1}return!0}function j0(t){return t===void 0?"undef":Array.isArray(t)?"list":Q0(t)?"range":A2(t)?"function":R0(t)?"record":typeof t}function nn(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?L2(t):Q0(t)?`[${L2(t.start)}:${L2(t.step)}:${L2(t.end)}]`:A2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:R0(t)?"{}":String(t)}function P3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let c=[],r=0,a=l=>{c.push(l),r+=l.length},s=[],i=t;for(;;){Array.isArray(i)?(a("["),s.push({items:i,i:0,close:"]"})):R0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(nn(i));let l=!1;for(;s.length&&!l&&r<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&a(", "),h.keys&&a(`${h.keys[h.i]} = `),i=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||r>e)break}let o=c.join("");return r>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function i7(t,e,n){let c=[],r=0;for(let a of t){c.length&&(r+=e.length);let s=P3(a,n-r);if(!s.whole)return;r+=s.text.length,c.push(s.text)}return c.join(e)}function _0(t){let e=P3(t,200,!0);return e.whole?e.text:e.text+"..."}var L0=t=>typeof t=="string"?t:_0(t);function A0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function L2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function E3(t,e=.02){let n=[],c=[],r=[],a=[0,0],s=[0,0],i=l=>{r.length>=2&&(l?n:c).push(r),r=[]},o=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")i(!1),a=s=[l.x,l.y],r=[s];else if(l.type==="L")s=[l.x,l.y],r.push(s);else if(l.type==="Q"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=f;d++){let m=d/f,p=1-m;r.push([p*p*h+2*p*m*l.x1+m*m*l.x,p*p*u+2*p*m*l.y1+m*m*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let m=d/f,p=1-m;r.push([p*p*p*h+3*p*p*m*l.x1+3*p*m*m*l.x2+m*m*m*l.x,p*p*p*u+3*p*p*m*l.y1+3*p*m*m*l.y2+m*m*m*l.y])}s=[l.x,l.y]}else i(!0),s=a,r=[a];return i(!1),{closed:n,open:c}}function T3(t,e=Math.PI/2,n){let c=x=>/^[a-zA-Z]$/.test(x),r=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,i="",o=0,l=0,h=0,u=0,f=0,d=0,m=0,p=0,g="",v=()=>{let x=r[s++];if(x===void 0||c(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},y=()=>{let x=r[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(r[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{b()}catch(x){if(!n)throw x;n(x.message)}return a;function b(){for(;s<r.length;){if(c(r[s]))i=r[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${r[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=i===i.toLowerCase(),M=i.toUpperCase(),S=x?o:0,w=x?l:0;if(M==="M")o=S+v(),l=w+v(),h=o,u=l,a.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=S+v(),l=w+v(),a.push({type:"L",x:o,y:l});else if(M==="H")o=S+v(),a.push({type:"L",x:o,y:l});else if(M==="V")l=w+v(),a.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let z,C;if(M==="C")z=S+v(),C=w+v();else{let q=g==="C"||g==="S";z=q?2*o-f:o,C=q?2*l-d:l}let k=S+v(),T=w+v();o=S+v(),l=w+v(),f=k,d=T,a.push({type:"C",x1:z,y1:C,x2:k,y2:T,x:o,y:l})}else if(M==="Q"||M==="T"){let z,C;if(M==="Q")z=S+v(),C=w+v();else{let k=g==="Q"||g==="T";z=k?2*o-m:o,C=k?2*l-p:l}o=S+v(),l=w+v(),m=z,p=C,a.push({type:"Q",x1:z,y1:C,x:o,y:l})}else if(M==="A"){let z=v(),C=v(),k=v(),T=y(),q=y(),R=S+v(),U=w+v();a.push(...cn(o,l,z,C,k,T,q,R,U,e)),o=R,l=U}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);g=M}}}function cn(t,e,n,c,r,a,s,i,o,l=Math.PI/2){if(n===0||c===0||t===i&&e===o)return[{type:"L",x:i,y:o}];n=Math.abs(n),c=Math.abs(c);let h=r*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-i)/2,m=(e-o)/2,p=u*d+f*m,g=-f*d+u*m,v=p*p/(n*n)+g*g/(c*c);v>1&&(n*=Math.sqrt(v),c*=Math.sqrt(v));let y=n*n*c*c-n*n*g*g-c*c*p*p,b=n*n*g*g+c*c*p*p,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*g/c,S=-x*c*p/n,w=u*M-f*S+(t+i)/2,z=f*M+u*S+(e+o)/2,C=(V,Q,W,o1)=>Math.atan2(V*o1-Q*W,V*W+Q*o1),k=C(1,0,(p-M)/n,(g-S)/c),T=C((p-M)/n,(g-S)/c,(-p-M)/n,(-g-S)/c);!s&&T>0&&(T-=2*Math.PI),s&&T<0&&(T+=2*Math.PI);let q=Math.ceil(Math.abs(T)/l),R=[],U=V=>[w+n*Math.cos(V)*u-c*Math.sin(V)*f,z+n*Math.cos(V)*f+c*Math.sin(V)*u],j=V=>[-n*Math.sin(V)*u-c*Math.cos(V)*f,-n*Math.sin(V)*f+c*Math.cos(V)*u];for(let V=0;V<q;V++){let Q=k+T*V/q,W=k+T*(V+1)/q,o1=4/3*Math.tan((W-Q)/4),m1=U(Q),I=U(W),$=j(Q),Z=j(W);R.push({type:"C",x1:m1[0]+o1*$[0],y1:m1[1]+o1*$[1],x2:I[0]-o1*Z[0],y2:I[1]-o1*Z[1],x:I[0],y:I[1]})}return R}var C0=Math.PI/180,I1=(t,e,n)=>({params:t.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function d7(t,e,n){return t.order?[]:t.params.filter((c,r)=>r<e.length&&n.has(c))}function m7(t,e,n){if(t.rest){let a=[...e];return t.params.forEach((s,i)=>{n.has(s)&&(a[i]=n.get(s))}),a}if(!t.order)return t.params.map((a,s)=>n.has(a)?n.get(a):e[s]);let c=e.length+t.params.filter(a=>n.has(a)).length,r=t.order(c).filter(a=>!n.has(a));return t.params.map(a=>n.has(a)?n.get(a):e[r.indexOf(a)])}function d6(t,e,n,c){let r=i7(t,e,n.maxLength);if(r===void 0)throw new Error(`${c}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(r.length/8)),r}function U1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${j0(t)}`);return t}function c2(t,e,n){if(Array.isArray(t))return t;if(Q0(t))return Q5(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${j0(t)}`)}var rn=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function p7(t,e,n){if(rn.has(t))return 0;let c=0;for(let r of e)if(typeof r=="string")c+=r.length;else if(Array.isArray(r))c+=t==="len"?0:r.length;else if(Q0(r)&&r.step!==0){let a=Math.floor((r.end-r.start)/r.step)+1;a>0&&(c+=Math.min(a,n+1))}return c}var q0=t=>I1("x",e=>typeof e[0]=="number"?C2(t(e[0])):void 0);function C2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function an(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function o7(t,e,n){let c=t.length===1&&Array.isArray(t[0])?t[0]:t;if(c.length)return e(c.map(r=>U1(r,n)))}var h5={abs:q0(Math.abs),sign:q0(Math.sign),floor:q0(Math.floor),ceil:q0(Math.ceil),round:q0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:q0(Math.sqrt),exp:q0(Math.exp),ln:q0(Math.log),log:I1("x, base",(t,e)=>e.given<2?C2(Math.log10(U1(t[0],"log"))):Math.log(U1(t[0],"log"))/Math.log(U1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:q0(t=>Math.sin(t*C0)),cos:q0(t=>Math.cos(t*C0)),tan:q0(t=>Math.tan(t*C0)),asin:q0(t=>Math.asin(t)/C0),acos:q0(t=>Math.acos(t)/C0),atan:q0(t=>Math.atan(t)/C0),atan2:I1("y, x",t=>C2(Math.atan2(U1(t[0],"atan2"),U1(t[1],"atan2"))/C0)),pow:I1("x, y",t=>Math.pow(U1(t[0],"pow"),U1(t[1],"pow"))),min:I1("values...",t=>o7(t,e=>e.reduce((n,c)=>c<n?c:n,1/0),"min")),max:I1("values...",t=>o7(t,e=>e.reduce((n,c)=>c>n?c:n,-1/0),"max")),clamp:I1("x, low, high",t=>Math.min(Math.max(U1(t[0],"clamp"),U1(t[1],"clamp")),U1(t[2],"clamp"))),lerp:I1("a, b, t",t=>{let e=U1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((c,r)=>U1(c,"lerp")+(U1(n[r],"lerp")-U1(c,"lerp"))*e)}return U1(t[0],"lerp")+(U1(t[1],"lerp")-U1(t[0],"lerp"))*e}),norm:I1("v",(t,e)=>Math.sqrt(c2(t[0],"norm",e).reduce((n,c)=>n+U1(c,"norm")**2,0))),cross:I1("a, b",(t,e)=>{let n=c2(t[0],"cross",e).map(r=>U1(r,"cross")),c=c2(t[1],"cross",e).map(r=>U1(r,"cross"));return n.length===2?n[0]*c[1]-n[1]*c[0]:[n[1]*c[2]-n[2]*c[1],n[2]*c[0]-n[0]*c[2],n[0]*c[1]-n[1]*c[0]]}),len:I1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:R0(t[0])?t[0].fields.size:void 0),keys:I1("record",t=>R0(t[0])?[...t[0].fields.keys()]:void 0),merge:I1("a, b",t=>{if(!R0(t[0])||!R0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:I1("...",(t,e)=>{let n=t.reduce((c,r)=>c+(Array.isArray(r)?r.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(c=>Array.isArray(c)?c:[c])}),reverse:I1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...c2(t[0],"reverse",e)].reverse()),sum:I1("values",(t,e)=>c2(t[0],"sum",e).reduce((n,c)=>n+U1(c,"sum"),0)),slice:I1("value, start, end",(t,e)=>{let c=(typeof t[0]=="string"?[...t[0]]:c2(t[0],"slice",e)).slice(U1(t[1]??0,"slice"),t[2]===void 0?void 0:U1(t[2],"slice"));return typeof t[0]=="string"?c.join(""):c}),str:I1("...",(t,e)=>d6(t,"",e,"str")),chr:I1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(U1(e,"chr"))).join("")),ord:I1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:I1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:I1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:I1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:I1("values, separator",(t,e)=>d6(c2(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:I1("value, list",(t,e)=>{let c=(typeof t[1]=="string"?[...t[1]]:c2(t[1],"search",e)).findIndex(r=>C3(r,t[0],e.step));return c<0?void 0:c}),contains:I1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(d6([t[1]],"",e,"contains")):c2(t[0],"contains",e).some(n=>C3(n,t[1],e.step))),lookup:I1("x, table",(t,e)=>{let n=U1(t[0],"lookup"),c=c2(t[1],"lookup",e);if(!c.length)return;let r=c.map(a=>[U1(a[0],"lookup"),U1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=r[0][0])return r[0][1];for(let a=1;a<r.length;a++)if(n<=r[a][0]){let[s,i]=r[a-1],[o,l]=r[a];return i+(n-s)/(o-s)*(l-i)}return r[r.length-1][1]}),rands:I1("min, max, count, seed",t=>{let e=U1(t[0],"rands"),n=U1(t[1],"rands"),c=U1(t[2],"rands"),r=an(t[3]===void 0?1:U1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(n-e)*r())}),is_num:I1("value",t=>s7(t[0])&&!Number.isNaN(t[0])),is_string:I1("value",t=>typeof t[0]=="string"),is_bool:I1("value",t=>typeof t[0]=="boolean"),is_list:I1("value",t=>Array.isArray(t[0])),is_record:I1("value",t=>R0(t[0])),is_undef:I1("value",t=>t[0]===void 0),is_function:I1("value",t=>A2(t[0])),type_of:I1("value",t=>j0(t[0])),path_length:I1("points",(t,e)=>{let n=e4(t[0],"path_length",e),c=0;for(let r=1;r<n.length;r++)c+=Math.hypot(n[r][0]-n[r-1][0],n[r][1]-n[r-1][1]);return c}),point_at:I1("points, s",(t,e)=>l7(e4(t[0],"point_at",e),U1(t[1],"point_at")).point),heading_at:I1("points, s",(t,e)=>C2(l7(e4(t[0],"heading_at",e),U1(t[1],"heading_at")).heading)),path_points:I1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:U1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let c=E3(T3(t[0]),n),r=[...c.closed.map(a=>[...a,a[0]]),...c.open];return e.step(r.reduce((a,s)=>a+s.length,0)),r.map(a=>a.map(([s,i])=>[s,i]))}),spline_points:I1("points, steps, closed",(t,e)=>{let n=e4(t[0],"spline_points",e),c=t[1]===void 0?8:Math.floor(U1(t[1],"spline_points"));if(!(c>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*c>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*c),p6(n,c,t[2]===!0)}),rotation:I1("angles",t=>{let[e,n,c]=m6(t[0],"rotation");return un(u7(hn(c),u7(ln(n),on(e))))}),euler:I1("matrix",t=>f7(sn(t[0],"euler"))),orient:I1("x, z",t=>{let e=h7(m6(t[0],"orient"),"orient"),n=m6(t[1]??[0,0,1],"orient"),c=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=h7([n[0]-c*e[0],n[1]-c*e[1],n[2]-c*e[2]],"orient");let r=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return f7([[e[0],r[0],n[0]],[e[1],r[1],n[1]],[e[2],r[2],n[2]]])})};function e4(t,e,n){return c2(t,e,n).map((r,a)=>{if(!Array.isArray(r)||typeof r[0]!="number"||typeof r[1]!="number")throw new Error(`${e}(): points[${a}] must be an [x, y] point`);return[r[0],r[1]]})}function l7(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([o,l],h)=>h===0||o!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let c=0,r=0;for(;c<n.length-2;c++){let o=Math.hypot(n[c+1][0]-n[c][0],n[c+1][1]-n[c][1]);if(r+o>=e)break;r+=o}let[a,s]=[n[c],n[c+1]],i=(e-r)/Math.hypot(s[0]-a[0],s[1]-a[1]);return{point:[a[0]+(s[0]-a[0])*i,a[1]+(s[1]-a[1])*i],heading:Math.atan2(s[1]-a[1],s[0]-a[0])/C0}}function m6(t,e){if(!Array.isArray(t)||t.length<2||t.length>3||!t.every(n=>typeof n=="number"))throw new Error(`${e}() needs [x, y, z]`);return[t[0],t[1],t[2]??0]}function h7(t,e){let n=Math.hypot(...t);if(!(n>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[t[0]/n,t[1]/n,t[2]/n]}function sn(t,e){if(!Array.isArray(t)||t.length<3||!t.slice(0,3).every(n=>Array.isArray(n)&&n.length>=3&&n.slice(0,3).every(c=>typeof c=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var on=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[1,0,0],[0,e,-n],[0,n,e]]},ln=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,0,n],[0,1,0],[-n,0,e]]},hn=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,-n,0],[n,e,0],[0,0,1]]},u7=(t,e)=>t.map(n=>[0,1,2].map(c=>n[0]*e[0][c]+n[1]*e[1][c]+n[2]*e[2][c])),un=t=>t.map(e=>e.map(C2));function f7(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,c=Math.atan2(-t[0][1],t[1][1])/C0;return[0,n,C2(c)]}return[C2(Math.atan2(t[2][1],t[2][2])/C0),C2(Math.asin(e)/C0),C2(Math.atan2(t[1][0],t[0][0])/C0)]}function p6(t,e,n=!1){if(t.length<3)return t.map(([s,i])=>[s,i]);let c=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=t.length){let[i,o]=[t[t.length-1],t[t.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return t[s]},r=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[i,o,l,h]=[c(s-1),c(s),c(s+1),c(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,m=d*f;r.push([0,1].map(p=>.5*(2*o[p]+(-i[p]+l[p])*f+(2*i[p]-5*o[p]+4*l[p]-h[p])*d+(-i[p]+3*o[p]-3*l[p]+h[p])*m)))}}return r.push(n?r[0]:[t[t.length-1][0],t[t.length-1][1]]),r}function c3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var u5=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function fn(t,e,n,c){if(e==="flat")return[];let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===1:i%2===0)&&s.push(u5(i*a,-1,(i+1)*a,n));return s}function t4(t,e,n,c,r){let a=[([o,l])=>[o,l],([o,l])=>[t-l,o],([o,l])=>[t-o,e-l],([o,l])=>[l,e-o]],s=[t,e,t,e],i=[];return n.forEach((o,l)=>{for(let h of fn(s[l],o,c,r))i.push(h.map(a[l]))}),y0([u5(0,0,t,e)],i)}function g7(t,e,n,c){let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===0:i%2===1)&&s.push(u5(i*a,-n/2,(i+1)*a,n/2));return s}function v7(t,e,n,c,r){let a=u5(-t/2,-1,t/2,e),s=u5(-n/2,r,n/2,r+c);return[a,s]}function y7(t,e,n,c,r){let a=[],s=r+c,i=Math.floor(t/n),o=(t-i*n)/2;for(let l=0;l<=i;l++){let h=o+l*n,u=l%2===0?c:c-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?c:0),m=Math.min(f+r,e-(l%2===0?c:0));m-d>=c/2&&a.push([[h,d],[h,m]])}}return a}var P2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var i1=class extends Error{constructor(n,c){super(c?`${n} (${P2(c)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,c&&(this.line=c.line,this.col=c.col,this.file=c.file)}addFrame(n,c,r){let a=this.trace.find(s=>s.name===c&&s.line===r.line&&s.col===r.col&&s.file===r.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:c,line:r.line,col:r.col,...r.file&&{file:r.file},count:1})}},dn=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function f5(t,e){let n=[],c=[],r=0,a=1,s=0,i=()=>({line:a,col:r-s+1,offset:r,...e&&{file:e}}),o=l=>{for(let h=0;h<l;h++)t[r]===`
6
+ `}},G5=class t extends _5{constructor(n=null){super(n);D(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let c=new t(this);return c.polygon=n,this.children.push(c),c}child(n){if(n<0||n>=this.children.length)throw new Error("Index out of range");return this.children[n]}area(){let n=this.polygon===null?0:te.area(this.polygon);for(let c of this.children)n+=c.area();return n}};var r5=class extends G5{};var T=class T{constructor(){D(this,"cliptype",e0.NoClip);D(this,"fillrule",D1.EvenOdd);D(this,"actives",null);D(this,"sel",null);D(this,"minimaList",[]);D(this,"intersectList",[]);D(this,"vertexList",[]);D(this,"outrecList",[]);D(this,"scanlineHeap",new Q4);D(this,"scanlineSet",new Set);D(this,"scanlineArr",[]);D(this,"useScanlineArray",!1);D(this,"horzSegList",[]);D(this,"horzJoinList",[]);D(this,"currentLocMin",0);D(this,"currentBotY",0);D(this,"curXValidAtTop",!1);D(this,"isSortedMinimaList",!1);D(this,"hasOpenPaths",!1);D(this,"usingPolytree",!1);D(this,"succeeded",!1);D(this,"zCallbackInternal");D(this,"preserveCollinear",!0);D(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,c){let r=this.zCallbackInternal;r&&(T.getPolyType(e)===I0.Subject?(this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:c.z=0,r(e.bot,e.top,n.bot,n.top,c)):(this.xyEqual(c,n.bot)?c.z=n.bot.z??0:this.xyEqual(c,n.top)?c.z=n.top.z??0:this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:c.z=0,r(n.bot,n.top,e.bot,e.top,c)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return T.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return T.openPathsEnabled&&e.localMin.isOpen&&T.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(X1.OpenStart|X1.OpenEnd))!==X1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!T.openPathsEnabled){for(;n!==null&&!T.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!T.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let c=n.y-e.y;return c!==0?(n.x-e.x)/c:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:V1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=T.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&X1.LocalMax)!==X1.None}static isMaximaEdge(e){return(e.vertexTop.flags&X1.LocalMax)!==X1.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,c,r){let a=e.x<n.x?e.x:n.x;if((c.x>r.x?c.x:r.x)<a)return!1;let i=e.x>n.x?e.x:n.x,o=c.x<r.x?c.x:r.x;if(i<o)return!1;let l=e.y<n.y?e.y:n.y;if((c.y>r.y?c.y:r.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=c.y<r.y?c.y:r.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,c=e.length;n<c;n++){let r=e[n];this.scanlineSet.add(r),this.scanlineHeap.push(r)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let c=0,r=n.length;c<r;c++)if(n[c]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,c=n.length;if(c===0)return null;let r=0,a=n[0];for(let s=1;s<c;s++){let i=n[s];i>a&&(a=i,r=s)}return n[r]=n[c-1],n.pop(),a}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,c=!1){let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c=!1){c&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,x3.addPathsToVertexList(e,n,c,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new t5(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,c=e.nextInAEL;n===null&&c===null&&e!==this.actives||(n!==null?n.nextInAEL=c:this.actives=c,c!==null&&(c.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let c=n;do c.pt.x<e.left&&(e.left=c.pt.x),c.pt.x>e.right&&(e.right=c.pt.x),c.pt.y<e.top&&(e.top=c.pt.y),c.pt.y>e.bottom&&(e.bottom=c.pt.y),c=c.next;while(c!==n)}return t3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===e0.NoClip)return;T.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let c=this.popScanline();if(c!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(c);let r;for(;(r=this.popHorz())!==null;)this.doHorizontal(r);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=c;let a=this.popScanline();if(a===null)break;for(c=a,this.doIntersections(c),this.doTopOfScanbeam(c);(r=this.popHorz())!==null;)this.doHorizontal(r)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),c;(n.vertex.flags&X1.OpenStart)!==X1.None?c=null:(c=new c5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=-1,c.vertexTop=n.vertex.prev,c.top=n.vertex.prev.pt,c.outrec=null,c.localMin=n,T.setDx(c));let r;if((n.vertex.flags&X1.OpenEnd)!==X1.None?r=null:(r=new c5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=1,r.vertexTop=n.vertex.next,r.top=n.vertex.next.pt,r.outrec=null,r.localMin=n,T.setDx(r)),c!==null&&r!==null){if(T.isHorizontal(c)){if(T.isHeadingRightHorz(c)){let s=c;c=r,r=s}}else if(T.isHorizontal(r)){if(T.isHeadingLeftHorz(r)){let s=c;c=r,r=s}}else if(c.dx<r.dx){let s=c;c=r,r=s}}else c===null&&(c=r,r=null);let a;if(c.isLeftBound=!0,this.insertLeftEdge(c),T.openPathsEnabled?T.isOpen(c)?(this.setWindCountForOpenPathEdge(c),a=this.isContributingOpen(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)):(this.setWindCountForClosedPathEdge(c),a=this.isContributingClosed(c)),r!==null){for(r.windCount=c.windCount,r.windCount2=c.windCount2,this.insertRightEdge(c,r),a&&(this.addLocalMinPoly(c,r,c.bot,!0),T.isHorizontal(c)||this.checkJoinLeft(c,c.bot));r.nextInAEL!==null&&this.isValidAelOrder(r.nextInAEL,r);)this.intersectEdges(r,r.nextInAEL,r.bot),this.swapPositionsInAEL(r,r.nextInAEL);T.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else a&&T.openPathsEnabled&&this.startOpenPath(c,c.bot);T.isHorizontal(c)?this.pushHorz(c):this.insertScanline(c.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!T.openPathsEnabled){this.doHorizontalClosed(e);return}let n=T.isOpen(e),c=e.bot.y,r=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:i}=this.resetHorzDirection(e,r),o=s,l=i;if(T.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:c});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===r){if(T.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),T.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(r!==e.vertexTop||T.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!T.isHorizontal(h)){let d=T.nextVertex(e).pt;if(T.isOpen(h)&&!T.isSamePolyType(h,e)&&!T.isHotEdge(h)){if(a&&T.topX(h,d.y)>d.x||!a&&T.topX(h,d.y)<d.x)break}else if(a&&T.topX(h,d.y)>=d.x||!a&&T.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:c};a?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),T.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&T.isOpenEnd(e)){T.isHotEdge(e)&&(this.addOutPt(e,e.top),T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(T.nextVertex(e).pt.y!==e.top.y)break;T.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,r);o=u.leftX,l=u.rightX}if(T.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,c=this.getCurrYMaximaVertex(e),{isLeftToRight:r,leftX:a,rightX:s}=this.resetHorzDirection(e,c),i=a,o=s;if(T.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=r?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===c){if(T.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),T.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);r?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(c!==e.vertexTop){if(r&&l.curX>o||!r&&l.curX<i)break;if(l.curX===e.top.x&&!T.isHorizontal(l)){let f=T.nextVertex(e).pt,d=T.topX(l,f.y);if(r&&d>=f.x||!r&&d<=f.x)break}}let u={x:l.curX,y:n};r?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),T.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(T.nextVertex(e).pt.y!==e.top.y)break;T.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(T.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let c=0,r=e.length;c<r;c++){let a=e[c];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(Xn);for(let c=0;c<n-1;c++){let r=this.horzSegList[c];for(let a=c+1;a<n;a++){let s=this.horzSegList[a];if(s.leftOp.pt.x>=r.rightOp.pt.x||s.leftToRight===r.leftToRight||s.rightOp.pt.x<=r.leftOp.pt.x)continue;let i=r.leftOp.pt.y;if(r.leftToRight){for(;r.leftOp.next.pt.y===i&&r.leftOp.next.pt.x<=s.leftOp.pt.x;)r.leftOp=r.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=r.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new n5(this.duplicateOp(r.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;r.leftOp.prev.pt.y===i&&r.leftOp.prev.pt.x<=s.leftOp.pt.x;)r.leftOp=r.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=r.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new n5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(r.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let n=e.leftOp,c=this.getRealOutRec(n.outrec),r=c.frontEdge!==null,a=n.pt.y,s=n,i=n;if(r){let l=c.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;i!==l&&i.next.pt.y===a;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===a;)s=s.prev;for(;i.next!==s&&i.next.pt.y===a;)i=i.next}let o=this.setHorzSegHeadingForward(e,s,i)&&e.leftOp.horz===null;return o?e.leftOp.horz=e:e.rightOp=null,o}setHorzSegHeadingForward(e,n,c){return n.pt.x===c.pt.x?!1:(n.pt.x<c.pt.x?(e.leftOp=n,e.rightOp=c,e.leftToRight=!0):(e.leftOp=c,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let c=new A2(e.pt,e.outrec);return n?(c.next=e.next,c.next.prev=c,c.prev=e,e.next=c):(c.prev=e.prev,c.prev.next=c,c.next=e,e.prev=c),c}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let c=this.actives;for(;c!==null;){if(c.top.y===e)if(c.curX=c.top.x,T.isMaximaEdge(c)){c=this.doMaxima(c);continue}else T.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),T.isHorizontal(c)&&this.pushHorz(c);else n||(c.curX=T.topX(c,e));c=c.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),c=this.getRealOutRec(e.op2.outrec),r=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,r.prev=a,a.next=r,n===c){let s=this.newOutRec();s.pts=r,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.owner=n}else c.pts=null,this.usingPolytree?(this.setOwner(c,n),this.moveSplits(c,n)):c.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let c=N1.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,n)){case N1.IsOutside:if(c===N1.IsOutside)return!1;c=N1.IsOutside;break;case N1.IsInside:if(c===N1.IsInside)return!0;c=N1.IsInside;break;default:break}r=r.next}while(r!==e);return V1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return N1.IsOutside;let c=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==c);if(n.pt.y===e.y)return N1.IsOutside;let r=n.pt.y<e.y,a=r,s=0;for(c=n.next;c!==n;){if(r)for(;c!==n&&c.pt.y<e.y;)c=c.next;else for(;c!==n&&c.pt.y>e.y;)c=c.next;if(c===n)break;if(c.pt.y===e.y){if(c.pt.x===e.x||c.pt.y===c.prev.pt.y&&e.x<c.prev.pt.x!=e.x<c.pt.x)return N1.IsOn;if(c=c.next,c===n)break;continue}if(c.pt.x<=e.x||c.prev.pt.x<=e.x)if(c.prev.pt.x<e.x&&c.pt.x<e.x)s=1-s;else{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return N1.IsOn;i<0===r&&(s=1-s)}r=!r,c=c.next}if(r===a)return s===0?N1.IsOutside:N1.IsInside;{let i=V1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return N1.IsOn;i<0===r&&(s=1-s)}return s===0?N1.IsOutside:N1.IsInside}getCleanPath(e){let n=[],c=e;for(;c.next!==e&&(c.pt.x===c.next.pt.x&&c.pt.x===c.prev.pt.x||c.pt.y===c.next.pt.y&&c.pt.y===c.prev.pt.y);)c=c.next;n.push(c.pt);let r=c;for(c=c.next;c!==e;)(c.pt.x!==c.next.pt.x||c.pt.x!==r.pt.x)&&(c.pt.y!==c.next.pt.y||c.pt.y!==r.pt.y)&&(n.push(c.pt),r=c),c=c.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let c of e.splits)c!==n.idx&&n.splits.push(c);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let c=null;for(;n!==null&&n.jump!==null;){let r=n,a=n.jump,s=a,i=a?.jump||null;for(n.jump=i;n!==s&&a!==i;)if(a.curX<n.curX){let o=a.prevInSEL;for(;this.addNewIntersectNode(o,a,e),o!==n;)o=o.prevInSEL;if(o=a,a=this.extractFromSEL(o),s=a,n!==null&&this.insert1Before2InSEL(o,n),n!==r)continue;r=o,r.jump=i,c===null?this.sel=r:c.jump=r}else n=n.nextInSEL;c=r,n=i}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(Zn);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let c=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[c]);)c++;[this.intersectList[c],this.intersectList[e]]=[this.intersectList[e],this.intersectList[c]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let c=Number.NEGATIVE_INFINITY,r=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=T.topX(n,e);n.curX=a,a<c&&(r=!0),c=a,n=n.nextInAEL}return r}doMaxima(e){let n=e.prevInAEL,c=e.nextInAEL;if(T.isOpenEnd(e))return T.isHotEdge(e)&&this.addOutPt(e,e.top),T.isHorizontal(e)||(T.isHotEdge(e)&&(T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let r=T.getMaximaPair(e);if(r===null)return c;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(r)&&this.split(r,r.top);c!==r;)this.intersectEdges(e,c,e.top),this.swapPositionsInAEL(e,c),c=e.nextInAEL;return T.isOpen(e)?(T.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(r),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(T.isHotEdge(e)&&this.addLocalMaxPoly(e,r,e.top),this.deleteFromAEL(e),this.deleteFromAEL(r),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=T.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,T.setDx(e),this.isJoined(e)&&this.split(e,e.bot),T.isHorizontal(e)){T.openPathsEnabled?T.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let c=!1,r=T.nextVertex(e).pt;for(;r.y===e.top.y&&!(n&&r.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=T.nextVertex(e),e.top=r,c=!0,T.isMaximaVertex(e.vertexTop)));)r=T.nextVertex(e).pt;c&&T.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new B5(e))}addNewIntersectNode(e,n,c){let r=V1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(r===null&&(r={x:e.curX,y:c}),r.y>this.currentBotY||r.y<c){let s=Math.abs(e.dx),i=Math.abs(n.dx);s>100&&i>100?s>i?r=V1.getClosestPtOnSegment(r,e.bot,e.top):r=V1.getClosestPtOnSegment(r,n.bot,n.top):s>100?r=V1.getClosestPtOnSegment(r,e.bot,e.top):i>100?r=V1.getClosestPtOnSegment(r,n.bot,n.top):(r.y<c?r.y=c:r.y=this.currentBotY,s<i?r.x=T.topX(e,r.y):r.x=T.topX(n,r.y))}let a=U6(r,e,n);this.intersectList.push(a)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(X1.OpenEnd|X1.LocalMax))===X1.None;)n=n.prev;return T.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return T.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let c=e.curX,r=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:c,rightX:r}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===H0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===D1.EvenOdd){let c=0,r=0;for(;n!==e;)T.getPolyType(n)===I0.Clip?r++:T.isOpen(n)||c++,n=n.nextInAEL;e.windCount=T.isOdd(c)?1:0,e.windCount2=T.isOdd(r)?1:0}else for(;n!==e;)T.getPolyType(n)===I0.Clip?e.windCount2+=n.windDx:T.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,c=T.getPolyType(e);if(!T.openPathsEnabled){for(;n!==null&&T.getPolyType(n)!==c;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===D1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===D1.EvenOdd)for(;n!==e;)T.getPolyType(n)!==c&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)T.getPolyType(n)!==c&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(T.getPolyType(n)!==c||T.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===D1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=T.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===D1.EvenOdd)for(;n!==e;)T.getPolyType(n)!==c&&!T.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)T.getPolyType(n)!==c&&!T.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,c;switch(this.fillrule){case D1.Positive:c=e.windCount>0,n=e.windCount2>0;break;case D1.Negative:c=e.windCount<0,n=e.windCount2<0;break;default:c=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case e0.Intersection:return n;case e0.Union:return!c&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case D1.Positive:if(e.windCount!==1)return!1;break;case D1.Negative:if(e.windCount!==-1)return!1;break;case D1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case e0.Intersection:return this.fillrule===D1.Positive?e.windCount2>0:this.fillrule===D1.Negative?e.windCount2<0:e.windCount2!==0;case e0.Union:return this.fillrule===D1.Positive?e.windCount2<=0:this.fillrule===D1.Negative?e.windCount2>=0:e.windCount2===0;case e0.Difference:{let n=this.fillrule===D1.Positive?e.windCount2<=0:this.fillrule===D1.Negative?e.windCount2>=0:e.windCount2===0;return T.getPolyType(e)===I0.Subject?n:!n}case e0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,c,r=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,T.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let i=T.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(a,i.outrec),a.owner=i.outrec,this.outrecIsAscending(i)===r?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,r?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new A2(c,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new U5;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let c=this.newOutRec();c.isOpen=!0,e.windDx>0?(c.frontEdge=e,c.backEdge=null):(c.frontEdge=null,c.backEdge=e),e.outrec=c;let r=new A2(n,c);return c.pts=r,r}checkJoinLeft(e,n,c=!1){let r=e.prevInAEL;r!==null&&(!c&&e.curX!==r.curX||!T.isHotEdge(e)||!T.isHotEdge(r)||T.isHorizontal(e)||T.isHorizontal(r)||T.isOpen(e)||T.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(r,e,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),r.joinWith=H0.Right,e.joinWith=H0.Left))}checkJoinRight(e,n,c=!1){let r=e.nextInAEL;r!==null&&(!c&&e.curX!==r.curX||!T.isHotEdge(e)||!T.isHotEdge(r)||T.isHorizontal(e)||T.isHorizontal(r)||T.isOpen(e)||T.isOpen(r)||(n.y<e.top.y+2||n.y<r.top.y+2)&&(e.bot.y>n.y||r.bot.y>n.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,r.bot,r.top)||V1.isCollinear(e.top,n,r.top)&&(e.outrec.idx===r.outrec.idx?this.addLocalMaxPoly(e,r,n):e.outrec.idx<r.outrec.idx?this.joinOutrecPaths(e,r):this.joinOutrecPaths(r,e),e.joinWith=H0.Right,r.joinWith=H0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,c){let r=e.x-n.x,a=e.y-n.y,s=c.x-n.x,i=c.y-n.y;if(s===0&&i===0)return!1;let o=V1.maxCoordForSafeCrossSq;if(Math.abs(r)<o&&Math.abs(a)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=r*i-s*a;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(r)*BigInt(i)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return N6*u>f}let l=r*i-s*a;return l*l/(s*s+i*i)>.25}intersectEdges(e,n,c){let r;if(this.hasOpenPaths&&(T.isOpen(e)||T.isOpen(n))){if(T.isOpen(e)&&T.isOpen(n))return;if(T.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,c),this.cliptype===e0.Union){if(!T.isHotEdge(n))return}else if(n.localMin.polytype===I0.Subject)return;switch(this.fillrule){case D1.Positive:if(n.windCount!==1)return;break;case D1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(T.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),T.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(c.x===e.localMin.vertex.pt.x&&c.y===e.localMin.vertex.pt.y&&!T.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&T.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}r=this.startOpenPath(e,c)}else r=this.startOpenPath(e,c);this.setZ(e,n,r.pt);return}this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===D1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==D1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==D1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case D1.Positive:a=e.windCount,s=n.windCount;break;case D1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let i=a===0||a===1,o=s===0||s===1;if(!(!T.isHotEdge(e)&&!i||!T.isHotEdge(n)&&!o))if(T.isHotEdge(e)&&T.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==e0.Xor)r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);else if(T.isFront(e)||e.outrec===n.outrec){r=this.addLocalMaxPoly(e,n,c),r&&this.setZ(e,n,r.pt);let l=this.addLocalMinPoly(e,n,c);this.setZ(e,n,l.pt)}else{r=this.addOutPt(e,c),this.setZ(e,n,r.pt);let l=this.addOutPt(n,c);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(T.isHotEdge(e))r=this.addOutPt(e,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else if(T.isHotEdge(n))r=this.addOutPt(n,c),this.setZ(e,n,r.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case D1.Positive:l=e.windCount2,h=n.windCount2;break;case D1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!T.isSamePolyType(e,n))r=this.addLocalMinPoly(e,n,c),this.setZ(e,n,r.pt);else if(a===1&&s===1){switch(r=null,this.cliptype){case e0.Union:if(l>0&&h>0)return;r=this.addLocalMinPoly(e,n,c);break;case e0.Difference:(T.getPolyType(e)===I0.Clip&&l>0&&h>0||T.getPolyType(e)===I0.Subject&&l<=0&&h<=0)&&(r=this.addLocalMinPoly(e,n,c));break;case e0.Xor:r=this.addLocalMinPoly(e,n,c);break;default:if(l<=0||h<=0)return;r=this.addLocalMinPoly(e,n,c);break}r&&this.setZ(e,n,r.pt)}}}swapPositionsInAEL(e,n){let c=n.nextInAEL;c!==null&&(c.prevInAEL=e);let r=e.prevInAEL;r!==null&&(r.nextInAEL=n),n.prevInAEL=r,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=c,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let c=V1.crossProductSign(e.top,n.bot,n.top);if(c!==0)return c<0;if(!T.isMaximaEdge(e)&&e.top.y>n.top.y)return V1.crossProductSign(n.bot,e.top,T.nextVertex(e).pt)<=0;if(!T.isMaximaEdge(n)&&n.top.y>e.top.y)return V1.crossProductSign(n.bot,n.top,T.nextVertex(n).pt)>=0;let r=n.bot.y,a=n.isLeftBound;return e.bot.y!==r||e.localMin.vertex.pt.y!==r?n.isLeftBound:e.isLeftBound!==a?a:V1.isCollinear(T.prevPrevVertex(e).pt,e.bot,e.top)?!0:V1.crossProductSign(T.prevPrevVertex(e).pt,n.bot,T.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==H0.None}split(e,n){e.joinWith===H0.Right?(e.joinWith=H0.None,e.nextInAEL.joinWith=H0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=H0.None,e.prevInAEL.joinWith=H0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,c){e.frontEdge=n,e.backEdge=c}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!T.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!T.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let c=e.outrec,r=T.isFront(e),a=c.pts,s=a.next;if(r&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!r&&n.x===s.pt.x&&n.y===s.pt.y)return s;let i=new A2(n,c);return s.prev=i,i.prev=a,i.next=s,a.next=i,r&&(c.pts=i),i}addLocalMaxPoly(e,n,c){if(this.isJoined(e)&&this.split(e,c),this.isJoined(n)&&this.split(n,c),T.isFront(e)===T.isFront(n))if(T.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(T.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let r=this.addOutPt(e,c);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=r,this.usingPolytree){let s=T.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else T.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return r}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let c=n;for(;c!==null&&c!==e;)c=c.owner;c!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let c=e.outrec.pts,r=n.outrec.pts,a=c.next,s=r.next;T.isFront(e)?(s.prev=c,c.next=s,r.next=a,a.prev=r,e.outrec.pts=r,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=r,r.next=a,c.next=s,s.prev=c,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),T.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let c=e.outrec,r=n.outrec;if(c===r){let a=c.frontEdge;c.frontEdge=c.backEdge,c.backEdge=a;return}c!==null&&(e===c.frontEdge?c.frontEdge=n:c.backEdge=n),r!==null&&(n===r.frontEdge?r.frontEdge=e:r.backEdge=e),e.outrec=r,n.outrec=c}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(T.ptsReallyClose(e.prev.pt,e.next.pt)||T.ptsReallyClose(e.pt,e.next.pt)||T.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,c,r){if(e===null||e.next===e||!c&&e.next===e.prev)return!1;r.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),r.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,r.push(a)),n?s=s.prev:s=s.next;return r.length!==3||c||!T.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts===null)continue;let a=[];r.isOpen?T.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(r),T.buildPath(r.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let c=0;for(;c<this.outrecList.length;){let r=this.outrecList[c++];if(r.pts!==null){if(r.isOpen){let a=[];T.buildPath(r.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(r)&&this.recursiveCheckOwners(r,e)}}}checkBounds(e){return e.pts===null?!1:t3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!T.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=V1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||t3.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,c=n;for(;;){if(c!==null&&V1.isCollinear(c.prev.pt,c.pt,c.next.pt)&&(c.pt.x===c.prev.pt.x&&c.pt.y===c.prev.pt.y||c.pt.x===c.next.pt.x&&c.pt.y===c.next.pt.y||!this.preserveCollinear||V1.dotProductSign(c.prev.pt,c.pt,c.next.pt)<0)){if(c===e.pts&&(e.pts=c.prev),c=this.disposeOutPt(c),!this.isValidClosedPath(c)){e.pts=null;return}n=c;continue}if(c===null||(c=c.next,c===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!T.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&V1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let c=n.prev,r=n.next.next;e.pts=c;let a=V1.getLineIntersectPt(c.pt,n.pt,n.next.pt,r.pt);this.zCallbackInternal&&this.zCallbackInternal(c.pt,n.pt,n.next.pt,r.pt,a);let s=T.areaOutPt(c),i=s<Q3?-s:s;if(i<N6){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<Q3?-o:o;if(a.x===c.pt.x&&a.y===c.pt.y||a.x===r.pt.x&&a.y===r.pt.y)r.prev=c,c.next=r;else{let f=new A2(a,e);f.prev=c,f.next=r,r.prev=f,c.next=f}if(!(l>Wn)||!(l>i)&&o>Q3!=s>Q3)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new A2(a,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(c,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=V1.maxCoordForSafeAreaProduct,c=0,r=!0,a=e;do{let i=a.prev,o=a.pt;if(Math.abs(i.pt.x)>=n||Math.abs(i.pt.y)>=n||Math.abs(o.x)>=n||Math.abs(o.y)>=n){r=!1;break}c+=(i.pt.y+o.y)*(i.pt.x-o.x),a=a.next}while(a!==e);if(r)return BigInt(Math.round(c));let s=Q3;a=e;do{let i=a.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(a.pt.x)){let o=BigInt(i.pt.y)+BigInt(a.pt.y),l=BigInt(i.pt.x)-BigInt(a.pt.x);s+=o*l}else{let o=i.pt.y+a.pt.y,l=i.pt.x-a.pt.x;s+=BigInt(Math.round(o*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,c){let r=V1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<r&&Math.abs(e.y)<r&&Math.abs(n.x)<r&&Math.abs(n.y)<r&&Math.abs(c.x)<r&&Math.abs(c.y)<r){let s=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(c.y)){let s=(BigInt(c.y)+BigInt(e.y))*(BigInt(c.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),o=(BigInt(n.y)+BigInt(c.y))*(BigInt(n.x)-BigInt(c.x));return s+i+o}let a=(c.y+e.y)*(c.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+c.y)*(n.x-c.x);return BigInt(Math.round(a))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let c=0;c<n.length;c++){let r=this.outrecList[n[c]];if(r.pts===null&&r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(r=this.getRealOutRec(r),!(r===null||r===e||r.recursiveSplit===e)){if(r.recursiveSplit=e,r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(!(!this.checkBounds(r)||!this.containsRect(r.bounds,e.bounds)||!this.path1InsidePath2(e.pts,r.pts)))return this.isValidOwner(e,r)||(r.owner=e.owner),e.owner=r,!0}}return!1}};D(T,"openPathsEnabled",!0);var j5=T,g2=class extends j5{constructor(){super(...arguments);D(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,c,r=!1){super.addPath(n,c,r)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,c,r=!1){super.addPaths(n,c,r)}addSubject(n){this.addPaths(n,I0.Subject)}addOpenSubject(n){this.addPaths(n,I0.Subject,!0)}addClip(n){this.addPaths(n,I0.Clip)}execute(n,c,r,a){if(Array.isArray(r)){let s=r,i=a;s.length=0,i&&(i.length=0);try{this.executeInternal(n,c),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=r,i=a;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(n,c),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var te={area(t){return V1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let c=t[n-1];for(let r of t)e+=(c.y+r.y)*(c.x-r.x),c=r;return e*.5},scalePath64(t,e){let n=V1.maxSafeCoordinateForScale(e),c=[];for(let r of t)V1.checkSafeScaleValue(r.x,n,"scalePath64"),V1.checkSafeScaleValue(r.y,n,"scalePath64"),c.push({x:Math.round(r.x*e),y:Math.round(r.y*e)});return c},scalePaths64(t,e){let n=[];for(let c of t)n.push(te.scalePath64(c,e));return n},scalePathD(t,e){let n=[];for(let c of t)n.push({x:c.x*e,y:c.y*e});return n},scalePathsD(t,e){let n=[];for(let c of t)n.push(te.scalePathD(c,e));return n}};var O0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(O0||(O0={}));var s0;(function(t){t[t.Polygon=0]="Polygon",t[t.Joined=1]="Joined",t[t.Butt=2]="Butt",t[t.Square=3]="Square",t[t.Round=4]="Round"})(s0||(s0={}));var ne=class{constructor(e,n,c=s0.Polygon){D(this,"inPaths");D(this,"joinType");D(this,"endType");D(this,"pathsReversed");D(this,"lowestPathIdx");this.joinType=n,this.endType=c;let r=c===s0.Polygon||c===s0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(n3.stripDuplicates(a,r));if(c===s0.Polygon){let a=n3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},a0=class a0{constructor(e=2,n=0,c=!1,r=!1){D(this,"groupList",[]);D(this,"pathOut",[]);D(this,"normals",[]);D(this,"solution",[]);D(this,"solutionTree",null);D(this,"groupDelta",0);D(this,"delta",0);D(this,"mitLimSqr",0);D(this,"stepsPerRad",0);D(this,"stepSin",0);D(this,"stepCos",0);D(this,"joinType",O0.Bevel);D(this,"endType",s0.Polygon);D(this,"arcTolerance",0);D(this,"mergeGroups",!0);D(this,"miterLimit",2);D(this,"preserveCollinear",!1);D(this,"reverseSolution",!1);D(this,"zCallback");D(this,"deltaCallback",null);D(this,"ZCB",(e,n,c,r,a)=>{(e.z||0)!==0&&(e.z===c.z||e.z===r.z)?a.z=e.z:(c.z||0)!==0&&c.z===n.z?a.z=c.z:(n.z||0)!==0&&n.z===r.z?a.z=n.z:this.zCallback&&this.zCallback(e,n,c,r,a)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=c,this.reverseSolution=r}clear(){this.groupList.length=0}addPath(e,n,c){if(e.length===0)return;let r=[e];this.addPaths(r,n,c)}addPaths(e,n,c){e.length!==0&&this.groupList.push(new ne(e,n,c))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===s0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===s0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/a0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),c=n?D1.Negative:D1.Positive,r=new g2;r.preserveCollinear=this.preserveCollinear,r.reverseSolution=this.reverseSolution!==n,r.zCallback=this.ZCB,r.addSubject(this.solution),this.solutionTree!==null?r.execute(e0.Union,c,this.solutionTree):r.execute(e0.Union,c,this.solution)}execute(e,n){if(Array.isArray(n)){let c=n;c.length=0,this.solution=c,this.executeInternal(e)}else{let c=n;c.clear(),this.solutionTree=c,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let c=n.x-e.x,r=n.y-e.y;if(c===0&&r===0)return{x:0,y:0};let a=1/Math.sqrt(c*c+r*r);return{x:r*a,y:-c*a}}static getLowestPathInfo(e){let n=-1,c=!1,r={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let i of e[a])if(!(i.y<r.y||i.y===r.y&&i.x>=r.x)){if(s===Number.MAX_VALUE){if(s=a0.area(e[a]),s===0)break;c=s<0}n=a,r.x=i.x,r.y=i.y}}return{idx:n,isNegArea:c}}static translatePoint(e,n,c){return{x:e.x+n,y:e.y+c,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=a0.hypotenuse(e.x,e.y);if(a0.almostZero(n))return{x:0,y:0};let c=1/n;return{x:e.x*c,y:e.y*c}}static getAvgUnitVector(e,n){return a0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,c,r){if(V1.isAlmostZero(e.x-n.x)){if(V1.isAlmostZero(c.x-r.x))return{x:0,y:0};let a=(r.y-c.y)/(r.x-c.x),s=c.y-a*c.x;return{x:e.x,y:a*e.x+s}}if(V1.isAlmostZero(c.x-r.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:c.x,y:a*c.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,i=(r.y-c.y)/(r.x-c.x),o=c.y-i*c.x;if(V1.isAlmostZero(a-i))return{x:0,y:0};let l=(o-s)/(a-i);return{x:l,y:a*l+s}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,c){let r,a,s=e[n].z||0;if(n===c){let i=Math.abs(this.groupDelta);r={x:Math.round(e[n].x-i*this.normals[n].x),y:Math.round(e[n].y-i*this.normals[n].y),z:s},a={x:Math.round(e[n].x+i*this.normals[n].x),y:Math.round(e[n].y+i*this.normals[n].y),z:s}}else r={x:Math.round(e[n].x+this.groupDelta*this.normals[c].x),y:Math.round(e[n].y+this.groupDelta*this.normals[c].y),z:s},a={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:s};this.pathOut.push(r),this.pathOut.push(a)}doSquare(e,n,c){let r;n===c?r={x:this.normals[n].y,y:-this.normals[n].x}:r=a0.getAvgUnitVector({x:-this.normals[c].y,y:this.normals[c].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=a0.translatePoint(s,a*r.x,a*r.y);let i=a0.translatePoint(s,this.groupDelta*r.y,this.groupDelta*-r.x),o=a0.translatePoint(s,this.groupDelta*-r.y,this.groupDelta*r.x),l=this.getPerpendicD(e[c],this.normals[c]);if(n===c){let h={x:l.x+r.x*this.groupDelta,y:l.y+r.y*this.groupDelta},u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s))),this.pathOut.push(m2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[c]),u=a0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(m2.fromPointD(u)),this.pathOut.push(m2.fromPointD(a0.reflectPoint(u,s)))}}doMiter(e,n,c,r){let a=this.groupDelta/(r+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[c].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[c].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,c,r){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*a0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let a=e[n],s=a.z||0,i={x:this.normals[c].x*this.groupDelta,y:this.normals[c].y*this.groupDelta};n===c&&N5.negate(i),this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});let o=Math.ceil(this.stepsPerRad*Math.abs(r));for(let l=1;l<o;l++)i={x:i.x*this.stepCos-this.stepSin*i.y,y:i.x*this.stepSin+i.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});this.pathOut.push(this.getPerpendic(e[n],this.normals[n]))}buildNormals(e){let n=e.length;if(this.normals.length=0,n!==0){for(let c=0;c<n-1;c++)this.normals.push(a0.getUnitNormal(e[c],e[c+1]));this.normals.push(a0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,c,r){if(m2.equals(n[c],n[r]))return;let a=V1.crossProductD(this.normals[c],this.normals[r]),s=V1.dotProductD(this.normals[c],this.normals[r]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,c,r),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<a0.Tolerance){this.pathOut.push(n[c]);return}if(s>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[c],this.normals[r])),this.pathOut.push(n[c]),this.pathOut.push(this.getPerpendic(n[c],this.normals[c]));else if(s>.999&&this.joinType!==O0.Round)this.doMiter(n,c,r,s);else switch(this.joinType){case O0.Miter:s>this.mitLimSqr-1?this.doMiter(n,c,r,s):this.doSquare(n,c,r);break;case O0.Round:this.doRound(n,c,r,Math.atan2(a,s));break;case O0.Bevel:this.doBevel(n,c,r);break;default:this.doSquare(n,c,r);break}}offsetPolygon(e,n){this.pathOut=[];let c=n.length,r=c-1;for(let a=0;a<c;a++)this.offsetPoint(e,n,a,r),r=a;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let c=[...n].reverse();this.buildNormals(c),this.offsetPolygon(e,c)}offsetOpenPath(e,n){this.pathOut=[];let c=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<a0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case s0.Butt:this.doBevel(n,0,0);break;case s0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let r=1,a=0;r<c;r++)this.offsetPoint(e,n,r,a),a=r;for(let r=c;r>0;r--)this.normals[r]={x:-this.normals[r-1].x,y:-this.normals[r-1].y};if(this.normals[0]=this.normals[c],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,c,c)),Math.abs(this.groupDelta)<a0.Tolerance)this.pathOut.push(n[c]);else switch(this.endType){case s0.Butt:this.doBevel(n,c,c);break;case s0.Round:this.doRound(n,c,c,Math.PI);break;default:this.doSquare(n,c,c);break}for(let r=c-1,a=c;r>0;r--)this.offsetPoint(e,n,r,a),a=r;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===s0.Polygon?(e.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=e.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===O0.Round||e.endType===s0.Round){let c=this.arcTolerance>.01?this.arcTolerance:n*a0.arc_const,r=Math.PI/Math.acos(1-c/n);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}for(let c of e.inPaths){this.pathOut=[];let r=c.length;if(r===1){let a=c[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(c,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=a.z||0;if(e.endType===s0.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=a0.ellipse(a,Math.abs(this.groupDelta),Math.abs(this.groupDelta),i),s!==0)for(let o=0;o<this.pathOut.length;o++)this.pathOut[o].z=s}else{let i=Math.ceil(Math.abs(this.groupDelta)),o={left:a.x-i,top:a.y-i,right:a.x+i,bottom:a.y+i};this.pathOut=[{x:o.left,y:o.top,z:s},{x:o.right,y:o.top,z:s},{x:o.right,y:o.bottom,z:s},{x:o.left,y:o.bottom,z:s}]}this.solution.push(this.pathOut);continue}switch(r===2&&e.endType===s0.Joined&&(this.endType=e.joinType===O0.Round?s0.Round:s0.Square),this.buildNormals(c),this.endType){case s0.Polygon:this.offsetPolygon(e,c);break;case s0.Joined:this.offsetOpenJoined(e,c);break;default:this.offsetOpenPath(e,c);break}}}static stripDuplicates(e,n){let c=e.length,r=[];if(c===0)return r;let a=e[0];r.push(a);for(let s=1;s<c;s++)m2.equals(a,e[s])||(a=e[s],r.push(a));return n&&m2.equals(a,r[0])&&r.pop(),r}static area(e){return V1.area(e)}static sqr(e){return e*e}static ellipse(e,n,c=0,r=0){if(n<=0)return[];c<=0&&(c=n),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((n+c)/2)));let a=Math.sin(2*Math.PI/r),s=Math.cos(2*Math.PI/r),i=s,o=a,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<r;++h){l.push({x:Math.round(e.x+n*i),y:Math.round(e.y+c*o)});let u=i*s-o*a;o=o*s+i*a,i=u}return l}};D(a0,"Tolerance",1e-12),D(a0,"arc_const",.002);var n3=a0;var Eo=BigInt(2);function re(t,e,n){return typeof e=="number"?ce(e0.Union,t,null,e):ce(e0.Union,t,e,n)}function ce(t,e,n,c){let r=[];if(e===null)return r;let a=new g2;return a.addPaths(e,I0.Subject),n!==null&&a.addPaths(n,I0.Clip),a.execute(t,c,r),r}function W5(t,e,n,c,r=2,a=0){let s=new n3(r,a);s.addPaths(t,n,c);let i=[];return s.execute(e,i),i}var n2=1e4,ae=[1,0,0,1,0,0];function J0(){return{layers:new Map,parts:[]}}function k0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function D2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function G6(t){if(t.parts.length)return!1;for(let e of t.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var j6=t=>t.map(e=>e.map(([n,c])=>({x:Math.round(n*n2),y:Math.round(c*n2)})));function Kn(t){let e=(c,r,a)=>(r.x-c.x)*(a.y-r.y)-(r.y-c.y)*(a.x-r.x)===0,n=[];for(let c of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],c);)n.pop();let r=n[n.length-1];(!r||r.x!==c.x||r.y!==c.y)&&n.push(c)}for(let c=!0;c&&n.length>=3;){let r=n.length;c=!0,n[r-1].x===n[0].x&&n[r-1].y===n[0].y||e(n[r-2],n[r-1],n[0])?n.pop():e(n[r-1],n[0],n[1])?n.shift():c=!1}return n}var a5=t=>j6(t).map(Kn),i5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/n2,n.y/n2]));function x1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?D1.EvenOdd:D1.NonZero;return i5(re(a5(t),n)).filter(c=>c.length>=3)}function se(t,e,n){if(!e.length)return[];let c=new g2;c.addSubject(a5(e)),n.length&&c.addClip(a5(n));let r=[];return c.execute(t,D1.NonZero,r),i5(r).filter(a=>a.length>=3)}var b0=(t,e)=>e.length?se(e0.Difference,t,e):x1(t),x0=(t,e)=>se(e0.Intersection,t,e),M3=(t,e)=>se(e0.Xor,t,e);function v2(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let c=[];for(let m of e)for(let g=0;g<m.length;g++){let v=m[g],y=m[(g+1)%m.length];(v[0]!==y[0]||v[1]!==y[1])&&c.push([v,y])}if(!c.length)return n==="outside"?t:[];let r=S0(e),a=Math.max(r[2]-r[0],r[3]-r[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=m=>Math.floor(m/a),i=new Map,o=new Map,l=(m,g,v)=>{let y=m.get(g);y?y[y.length-1]!==v&&y.push(v):m.set(g,[v])};c.forEach(([m,g],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let b=0;b<=y;b++){let x=m[0]+(g[0]-m[0])*b/y,M=m[1]+(g[1]-m[1])*b/y;for(let w of[-1,0,1])for(let k of[-1,0,1])l(i,`${s(x)+w},${s(M)+k}`,v)}for(let b=s(Math.min(m[1],g[1]));b<=s(Math.max(m[1],g[1]));b++)l(o,b,v)});let h=(m,g)=>{let v=new Set,y=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let b=0;b<=y;b++){let x=m[0]+(g[0]-m[0])*b/y,M=m[1]+(g[1]-m[1])*b/y;for(let w of i.get(`${s(x)},${s(M)}`)??[])v.add(w)}return v},u=.5/n2,f=m=>{for(let v of i.get(`${s(m[0])},${s(m[1])}`)??[]){let[y,b]=c[v],x=b[0]-y[0],M=b[1]-y[1],w=Math.max(0,Math.min(1,((m[0]-y[0])*x+(m[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(m[0]-y[0]-w*x,m[1]-y[1]-w*M)<=u)return}let g=0;for(let v of o.get(s(m[1]))??[]){let[y,b]=c[v],x=(b[0]-y[0])*(m[1]-y[1])-(m[0]-y[0])*(b[1]-y[1]);y[1]<=m[1]?b[1]>m[1]&&x>0&&g++:b[1]<=m[1]&&x<0&&g--}return g!==0},d=m=>Math.round(m*n2)/n2,p=[];for(let m of t){let g=null,v=()=>{g&&g.length>=2&&p.push(g),g=null};for(let y=1;y<m.length;y++){let b=m[y-1],x=m[y],M=x[0]-b[0],w=x[1]-b[1];if(!M&&!w)continue;let k=[0,1];for(let z of h(b,x)){let[S,L]=c[z],I=L[0]-S[0],q=L[1]-S[1],R=M*q-w*I;if(Math.abs(R)>1e-15){let N=((S[0]-b[0])*q-(S[1]-b[1])*I)/R,G=((S[0]-b[0])*w-(S[1]-b[1])*M)/R;N>0&&N<1&&G>=0&&G<=1&&k.push(N)}else{let N=M*M+w*w;for(let G of[S,L]){let V=((G[0]-b[0])*M+(G[1]-b[1])*w)/N,J=Math.abs((G[0]-b[0])*w-(G[1]-b[1])*M)/Math.sqrt(N);V>0&&V<1&&J<=u&&k.push(V)}}}k.sort((z,S)=>z-S);for(let z=1;z<k.length;z++){if(k[z]-k[z-1]<1e-12)continue;let S=[d(b[0]+M*k[z-1]),d(b[1]+w*k[z-1])],L=[d(b[0]+M*k[z]),d(b[1]+w*k[z])],I=(k[z-1]+k[z])/2,q=f([b[0]+M*I,b[1]+w*I]);if(q!==void 0&&q===(n==="inside")){let R=g?g[g.length-1]:void 0;g&&R&&R[0]===S[0]&&R[1]===S[1]?(L[0]!==R[0]||L[1]!==R[1])&&g.push(L):(v(),g=[S,L])}else v()}}v()}return p}function m0(t,e,n="round",c=.01){if(!t.length)return[];if(e===0)return x1(t);let r=n==="round"?O0.Round:n==="square"?O0.Square:O0.Miter,a=W5(a5(x1(t)),e*n2,r,s0.Polygon,2,c*n2);return i5(a).filter(s=>s.length>=3)}function X5(t,e){if(!t.length||e<=0)return[];let n=W5(j6(t),e/2*n2,O0.Round,s0.Round,2,.01*n2);return i5(n)}function _0(t){if(!t.length)return[];let e=new r5,n=new g2;n.addSubject(a5(t)),n.execute(e0.Union,D1.NonZero,e);let c=[],r=a=>{for(let s=0;s<a.count;s++){let i=a.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),r(h)}c.push(i5(o))}};return r(e),c}function H1(t){let e=0;for(let n=0,c=t.length-1;n<t.length;c=n++)e+=(t[c][0]+t[n][0])*(t[c][1]-t[n][1]);return-e/2}function W6(t){let e=0,n=0,c=0;for(let r of t){if(r.length<3)continue;let[a,s]=r[0];for(let i=0,o=r.length-1;i<r.length;o=i++){let l=r[o][0]-a,h=r[o][1]-s,u=r[i][0]-a,f=r[i][1]-s,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+a*d/2,c+=(h+f)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,c/e]}}function w3(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}function s5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function B6(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,c=new Map;for(let[r,a]of t)c.set(r,{regions:a.regions.map(s=>{let i=s.map(o=>s5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>s5(e,i)))});return c}function z3(t,e){return{layers:B6(t.layers,e),parts:t.parts.map(n=>({...n,layers:B6(n.layers,e)}))}}function q2(t){let e=J0();for(let n of t){for(let[c,r]of n.layers){let a=e.layers.get(c)??{regions:[],lines:[]};for(let s of r.regions)a.regions.push(s);for(let s of r.lines)a.lines.push(s);e.layers.set(c,a)}for(let c of n.parts)e.parts.push(c)}return e}function _6(t,e){let n={regions:[],lines:[]};for(let c of t.values()){for(let r of c.regions)n.regions.push(r);for(let r of c.lines)n.lines.push(r)}return new Map([[e,n]])}function o5(t,e){if(t.parts.length&&e!=="guide")throw new Error(`a part cannot go on the ${e} layer as a whole. Put ${e}() inside part() instead.`);return{layers:_6(t.layers,e),parts:t.parts.map(n=>({...n,layers:_6(n.layers,e)}))}}function S0(t){let e=1/0,n=1/0,c=-1/0,r=-1/0;for(let a of t)for(let[s,i]of a)s<e&&(e=s),i<n&&(n=i),s>c&&(c=s),i>r&&(r=i);return e===1/0?null:[e,n,c,r]}function D0(t,e){let n=[];for(let[c,r]of t)if(!e?.(c))for(let a of[...r.regions,...r.lines])n.push(a);return S0(n)}function X6(t){let e=[...t].sort((a,s)=>a[0]-s[0]||a[1]-s[1]);if(e.length<3)return e;let n=(a,s,i)=>(s[0]-a[0])*(i[1]-a[1])-(s[1]-a[1])*(i[0]-a[0]),c=[];for(let a of e){for(;c.length>=2&&n(c[c.length-2],c[c.length-1],a)<=0;)c.pop();c.push(a)}let r=[];for(let a=e.length-1;a>=0;a--){let s=e[a];for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}return r.pop(),c.pop(),c.concat(r)}function Z6(t,e,n,c){return t<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/n,t*2*Math.PI/c)),5)}function k3(t,e,n){let c=[];for(let r=0;r<n;r++){let a=2*Math.PI*r/n;c.push([t*Math.cos(a),e*Math.sin(a)])}return c}function Y6(t,e,n,c){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let r=Math.max(1,Math.ceil(c(n)/4)),a=[],s=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[i,o,l]of s)for(let h=0;h<=r;h++){let u=(l+90*h/r)*Math.PI/180;a.push([i+n*Math.cos(u),o+n*Math.sin(u)])}return a}var J6=Math.PI/180;function O1(t,e){let n=new Array(16).fill(0);for(let c=0;c<4;c++)for(let r=0;r<4;r++)for(let a=0;a<4;a++)n[c*4+r]+=t[c*4+a]*e[a*4+r];return n}function Z5(t,e){let n=Math.cos(e*J6),c=Math.sin(e*J6);return t===0?[1,0,0,0,0,n,-c,0,0,c,n,0,0,0,0,1]:t===1?[n,0,c,0,0,1,0,0,-c,0,n,0,0,0,0,1]:[n,-c,0,0,c,n,0,0,0,0,1,0,0,0,0,1]}var ie=t=>Math.abs(t)<1e-12?0:t;function K0(t){if(t.matrix)return t.matrix.map(ie);let[e,n,c]=t.rotate,r=O1(Z5(2,c),O1(Z5(1,n),Z5(0,e)));return r[3]=t.at[0],r[7]=t.at[1],r[11]=t.at[2],r.map(ie)}function A3(t,e,n,c){return[t[0]*e+t[1]*n+t[2]*c+t[3],t[4]*e+t[5]*n+t[6]*c+t[7],t[8]*e+t[9]*n+t[10]*c+t[11]]}function t7(t){let[e,n,c]=[t[3],t[7],t[11]],r=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[r[0],r[1],r[2],-(r[0]*e+r[1]*n+r[2]*c),r[3],r[4],r[5],-(r[3]*e+r[4]*n+r[5]*c),r[6],r[7],r[8],-(r[6]*e+r[7]*n+r[8]*c),0,0,0,1]}function Y5(t){let[e,n,c,r]=[1/0,1/0,-1/0,-1/0];for(let a of t)for(let[s,i]of a)e=Math.min(e,s),n=Math.min(n,i),c=Math.max(c,s),r=Math.max(r,i);return[e,n,c,r]}function l5(t){let[e,n,c,r]=Y5(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,c])for(let o of[n,r])for(let l of[0,t.thickness]){let h=A3(t.matrix,i,o,l);for(let u=0;u<3;u++)a[u]=Math.min(a[u],h[u]),s[u]=Math.max(s[u],h[u])}return[a,s]}function n7(t,e,n=10){let c=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(l5))for(let f=0;f<3;f++)c[f]=Math.min(c[f],h[f]),r[f]=Math.max(r[f],u[f]);let a=e.map(h=>Y5(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),r[0]-c[0]),i=0,o=0,l=0;return e.map((h,u)=>{let[f,d,p,m]=a[u];i>0&&i+p-f>s&&(i=0,o+=l+n,l=0);let g=[1,0,0,r[0]+n+i-f,0,1,0,c[1]+o-d,0,0,1,c[2],0,0,0,1];return i+=p-f+n,l=Math.max(l,m-d),{...h,matrix:g.map(ie)}})}var Qn=(t,e,n)=>[0,1,2].every(c=>t[0][c]<e[1][c]-n&&e[0][c]<t[1][c]-n),S3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],oe=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],K6=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],J5=t=>[t[2],t[6],t[10]],Q6=t=>[t[3],t[7],t[11]],e9=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[4]*e[0]+t[5]*e[1]+t[6]*e[2],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]];function L3(t,e,n){let c=n[0]*n[0]+n[1]*n[1],r=[];for(let a of t)for(let s=0,i=a.length-1;s<a.length;i=s++){let o=a[i],l=a[s],h=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=o[0]+(l[0]-o[0])*f-e[0],p=o[1]+(l[1]-o[1])*f-e[1];r.push((d*n[0]+p*n[1])/c)}return r.sort((a,s)=>a-s)}function le(t,e,n){let c=0,r=0,a=0;for(;r+1<t.length&&a+1<e.length;){let s=Math.min(t[r+1],e[a+1])-Math.max(t[r],e[a]);s>n&&(c+=s),t[r+1]<e[a+1]?r+=2:a+=2}return c}function K5(t,e,n,c){let r=t+n,a=e-n;if(a<=r)return{at:[],size:0};let s=Math.max(4,Math.ceil((a-r)/c));return{at:Array.from({length:s},(i,o)=>r+(a-r)*(o+.5)/s),size:(a-r)/s}}function e7(t,e,n){let c=A3(t,e[0],e[1],e[2]),r=e9(t,n);return[[c[0],c[1]],[r[0],r[1]]]}function t9(t,e,n,c,r,a,s){let i=J5(t.matrix),o=J5(e.matrix),l=oe(i,o),h=Math.hypot(...l),u=[l[0]/h,l[1]/h,l[2]/h],f=oe(u,i),d=S3(o,f),p=Q6(t.matrix),m=S3(o,Q6(e.matrix)),g=1/0,v=-1/0;for(let w of e.outline)for(let[k,z]of w)for(let S of[0,e.thickness]){let L=A3(e.matrix,k,z,S),I=S3(i,[L[0]-p[0],L[1]-p[1],L[2]-p[2]]);I<g&&(g=I),I>v&&(v=I)}let y=K5(Math.max(0,g),Math.min(t.thickness,v),r,a),b=1/0,x=-1/0;for(let w of t.outline)for(let[k,z]of w){let S=A3(t.matrix,k,z,0),L=S3(f,[S[0]-p[0],S[1]-p[1],S[2]-p[2]]);L<b&&(b=L),L>x&&(x=L)}let M=0;for(let w of y.at){let k=K6(p,i,w),z=(m-S3(o,k))/d,S=(m+e.thickness-S3(o,k))/d,L=K5(Math.max(b,Math.min(z,S)),Math.min(x,Math.max(z,S)),r,a);for(let I of L.at){let q=K6(k,f,I),[R,N]=e7(n,q,u),[G,V]=e7(c,q,u);if(M+=le(L3(t.outline,R,N),L3(e.outline,G,V),r)*y.size*L.size,M>s)return!0}}return!1}function n9(t,e,n,c,r,a){let s=[0,1,2,3].flatMap(k=>[0,1,2,3].map(z=>{let S=0;for(let L=0;L<4;L++)S+=n[k*4+L]*e.matrix[L*4+z];return S})),i=s[11],o=s[11]+s[10]*e.thickness,l=Math.min(t.thickness,Math.max(i,o))-Math.max(0,Math.min(i,o));if(l<=c)return!1;let h=e.outline.map(k=>k.map(([z,S])=>[s[0]*z+s[1]*S+s[3],s[4]*z+s[5]*S+s[7]])),[u,f,d,p]=Y5(t.outline),[m,g,v,y]=Y5(h),b=K5(Math.max(f,g),Math.min(p,y),c,r),x=0;for(let k of b.at)if(x+=le(L3(t.outline,[0,k],[1,0]),L3(h,[0,k],[1,0]),c)*b.size*l,x>a)return!0;let M=K5(Math.max(u,m),Math.min(d,v),c,r),w=0;for(let k of M.at)if(w+=le(L3(t.outline,[k,0],[0,1]),L3(h,[k,0],[0,1]),c)*M.size*l,w>a)return!0;return!1}function c7(t,e=1/0,n=.05,c=.25,r=.1){let a=t.map(l5),s=t.map(h=>t7(h.matrix)),i=t.map((h,u)=>u).sort((h,u)=>a[h][0][0]-a[u][0][0]),o=[],l=0;for(let h=0;h<i.length;h++)for(let u=h+1;u<i.length;u++){let f=i[h],d=i[u];if(a[d][0][0]>=a[f][1][0]-n)break;if(!Qn(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[p,m]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]];(Math.hypot(...oe(J5(p.matrix),J5(m.matrix)))<1e-9?n9(p,m,g,n,c,r):t9(p,m,g,v,n,c,r))&&o.push([p,m])}return{found:o,complete:!0}}function R0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var he=R0(0,0,0);function L0(t){return t7(t)}function r7(t,e,n=t.angle,c=t.x1){let r=c-t.x0;if(!n||!(r>0))return R0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return O1(R0(t.x0,0,s),O1(Z5(1,-n),R0(-t.x0-r,0,-s)))}function h5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function Q5(t,e){let n=[R0(0,0,0)];for(let c of h5(t))n.push(O1(n[n.length-1],r7(c,e)));return n}function ue(t,e,n){let c=h5(t),r=Q5(c,e);for(let a=c.length-1;a>=0;a--){let s=c[a];if(n[0]>=s.x1)return A3(r[a+1],...n);if(n[0]>s.x0){let i=(n[0]-s.x0)/(s.x1-s.x0),o=O1(r[a],r7(s,e,s.angle*i,n[0]));return A3(o,...n)}}return n}function a7(t,e){return h5(t).filter(n=>(n.x0+n.x1)/2<e).length}function e4(t){if(!t.bends?.length)return[t];let e=h5(t.bends),n=Q5(e,t.thickness),c=1e7,r=[];for(let a=0;a<=e.length;a++){let s=a===0?-c:e[a-1].x1,i=a===e.length?c:e[a].x0;if(!(i>s))continue;let o=[[s,-c],[i,-c],[i,c],[s,c]],l=x0(t.outline,[o]);l.length&&r.push({...t,outline:l,bends:void 0,matrix:O1(t.matrix,n[a])})}return r}var c9=2e3;function fe(t,e,n=2){if(!e?.length)return _0(t);let c=1e7,r=1/0,a=-1/0;for(let f of t)for(let[d]of f)r=Math.min(r,d),a=Math.max(a,d);let s=h5(e).map(f=>[Math.max(f.x0,r),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,p])=>f+(p-d),0),o=Math.max(n,i/c9),l=[];for(let[f,d]of s){let p=Math.max(1,Math.ceil((d-f)/o));for(let m=0;m<=p;m++)l.push(f+(d-f)*m/p)}let h=[-c,...l.sort((f,d)=>f-d),c],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-c],[h[f+1],-c],[h[f+1],c],[h[f],c]];for(let p of _0(x0(t,[d])))u.push(p)}return u}var N2=1e6,t4=.01,s7=t=>H1(t)<0?[...t].reverse():t;function r9(t,e){let n=O1(L0(t.matrix),e.matrix),[c,r]=[n[8],n[9]],a=Math.hypot(c,r);if(a<1e-9)return[];let s=0,i=e.thickness,o=k=>(-n[11]-Math.max(n[10]*s,n[10]*i)+k)/a,l=k=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-k)/a;if(!(l(t4)>o(t4)))return[];let[h,u]=[c/a,r/a],[f,d]=[-u,h],p=(k,z)=>[[h*k-f*N2,u*k-d*N2],[h*z-f*N2,u*z-d*N2],[h*z+f*N2,u*z+d*N2],[h*k+f*N2,u*k+d*N2]],m=1/0,g=-1/0;for(let k of e.outline)for(let[z,S]of k)for(let L of[s,i]){let I=n[8]*z+n[9]*S+n[10]*L+n[11];I<m&&(m=I),I>g&&(g=I)}if(Math.min(t.thickness,g)-Math.max(0,m)<Math.min(1,t.thickness/2))return[];let v=(k,z)=>x0(e.outline,[s7(p(k,z))]).filter(S=>Math.abs(H1(S))>1e-6);if(!v(o(t4),l(t4)).length)return[];let y=v(o(0),l(0));if(!y.length)return[];let b=k=>([z,S])=>[n[0]*z+n[1]*S+n[2]*k+n[3],n[4]*z+n[5]*S+n[6]*k+n[7]],x=n[0]*n[5]-n[1]*n[4]<0,M=k=>y.map(z=>{let S=z.map(b(k));return x?S.reverse():S}),w=[];for(let k of y)for(let z=0;z<k.length;z++){let S=k[z],L=k[(z+1)%k.length],I=[b(s)(S),b(s)(L),b(i)(L),b(i)(S)];Math.abs(H1(I))>1e-9&&w.push(s7(I))}return x1([...M(s),...M(i),...w],"nonzero")}function i7(t,e,n){let c=[];for(let a of e)for(let s of r9(t,a))c.push(s);if(!c.length)return[];let r=_0(x0(x1(c),t.outline)).filter(a=>a.reduce((s,i)=>s+H1(i),0)>1e-4);return r.length?m0(r.flat(),n/2,"miter"):[]}var Q0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",P2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",l7=t=>typeof t=="number",F0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",G0=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function de(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let c of e)de(t,c,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function n4(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let c=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(c>e)throw new Error(`a range of ${c} items is more than the limit of ${e}`);for(let r=0;r<c;r++)n.push(t.start+r*t.step);return n}function h0(t){return t===void 0||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="number"?!Number.isNaN(t):!0}var o7=(t,e,n)=>Q0(t)&&Q0(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:F0(t)&&F0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([c,r])=>e.fields.has(c)&&C3(r,e.fields.get(c),n)):t===e;function C3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return o7(t,e,n);let c=new Map,r=[],a=(s,i)=>{let o=c.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||c.set(s,o=new Set),o.add(i),r.push([s,i,0]),!0)};if(!a(t,e))return!1;for(;r.length;){let s=r[r.length-1];if(s[2]===s[0].length){r.pop();continue}let i=s[0][s[2]],o=s[1][s[2]++];if(n?.(),Array.isArray(i)&&Array.isArray(o)?!a(i,o):!o7(i,o,n))return!1}return!0}function j0(t){return t===void 0?"undef":Array.isArray(t)?"list":Q0(t)?"range":P2(t)?"function":F0(t)?"record":typeof t}function a9(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?C2(t):Q0(t)?`[${C2(t.start)}:${C2(t.step)}:${C2(t.end)}]`:P2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:F0(t)?"{}":String(t)}function P3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let c=[],r=0,a=l=>{c.push(l),r+=l.length},s=[],i=t;for(;;){Array.isArray(i)?(a("["),s.push({items:i,i:0,close:"]"})):F0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(a9(i));let l=!1;for(;s.length&&!l&&r<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&a(", "),h.keys&&a(`${h.keys[h.i]} = `),i=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||r>e)break}let o=c.join("");return r>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function h7(t,e,n){let c=[],r=0;for(let a of t){c.length&&(r+=e.length);let s=P3(a,n-r);if(!s.whole)return;r+=s.text.length,c.push(s.text)}return c.join(e)}function q0(t){let e=P3(t,200,!0);return e.whole?e.text:e.text+"..."}var g0=t=>typeof t=="string"?t:q0(t);function A0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function C2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function T3(t,e=.02){let n=[],c=[],r=[],a=[0,0],s=[0,0],i=l=>{r.length>=2&&(l?n:c).push(r),r=[]},o=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")i(!1),a=s=[l.x,l.y],r=[s];else if(l.type==="L")s=[l.x,l.y],r.push(s);else if(l.type==="Q"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=f;d++){let p=d/f,m=1-p;r.push([m*m*h+2*m*p*l.x1+p*p*l.x,m*m*u+2*m*p*l.y1+p*p*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let p=d/f,m=1-p;r.push([m*m*m*h+3*m*m*p*l.x1+3*m*p*p*l.x2+p*p*p*l.x,m*m*m*u+3*m*m*p*l.y1+3*m*p*p*l.y2+p*p*p*l.y])}s=[l.x,l.y]}else i(!0),s=a,r=[a];return i(!1),{closed:n,open:c}}function E3(t,e=Math.PI/2,n){let c=x=>/^[a-zA-Z]$/.test(x),r=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,i="",o=0,l=0,h=0,u=0,f=0,d=0,p=0,m=0,g="",v=()=>{let x=r[s++];if(x===void 0||c(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},y=()=>{let x=r[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(r[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{b()}catch(x){if(!n)throw x;n(x.message)}return a;function b(){for(;s<r.length;){if(c(r[s]))i=r[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${r[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=i===i.toLowerCase(),M=i.toUpperCase(),w=x?o:0,k=x?l:0;if(M==="M")o=w+v(),l=k+v(),h=o,u=l,a.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=w+v(),l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="H")o=w+v(),a.push({type:"L",x:o,y:l});else if(M==="V")l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let z,S;if(M==="C")z=w+v(),S=k+v();else{let q=g==="C"||g==="S";z=q?2*o-f:o,S=q?2*l-d:l}let L=w+v(),I=k+v();o=w+v(),l=k+v(),f=L,d=I,a.push({type:"C",x1:z,y1:S,x2:L,y2:I,x:o,y:l})}else if(M==="Q"||M==="T"){let z,S;if(M==="Q")z=w+v(),S=k+v();else{let L=g==="Q"||g==="T";z=L?2*o-p:o,S=L?2*l-m:l}o=w+v(),l=k+v(),p=z,m=S,a.push({type:"Q",x1:z,y1:S,x:o,y:l})}else if(M==="A"){let z=v(),S=v(),L=v(),I=y(),q=y(),R=w+v(),N=k+v();a.push(...s9(o,l,z,S,L,I,q,R,N,e)),o=R,l=N}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);g=M}}}function s9(t,e,n,c,r,a,s,i,o,l=Math.PI/2){if(n===0||c===0||t===i&&e===o)return[{type:"L",x:i,y:o}];n=Math.abs(n),c=Math.abs(c);let h=r*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-i)/2,p=(e-o)/2,m=u*d+f*p,g=-f*d+u*p,v=m*m/(n*n)+g*g/(c*c);v>1&&(n*=Math.sqrt(v),c*=Math.sqrt(v));let y=n*n*c*c-n*n*g*g-c*c*m*m,b=n*n*g*g+c*c*m*m,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*g/c,w=-x*c*m/n,k=u*M-f*w+(t+i)/2,z=f*M+u*w+(e+o)/2,S=(V,J,o1,Z)=>Math.atan2(V*Z-J*o1,V*o1+J*Z),L=S(1,0,(m-M)/n,(g-w)/c),I=S((m-M)/n,(g-w)/c,(-m-M)/n,(-g-w)/c);!s&&I>0&&(I-=2*Math.PI),s&&I<0&&(I+=2*Math.PI);let q=Math.ceil(Math.abs(I)/l),R=[],N=V=>[k+n*Math.cos(V)*u-c*Math.sin(V)*f,z+n*Math.cos(V)*f+c*Math.sin(V)*u],G=V=>[-n*Math.sin(V)*u-c*Math.cos(V)*f,-n*Math.sin(V)*f+c*Math.cos(V)*u];for(let V=0;V<q;V++){let J=L+I*V/q,o1=L+I*(V+1)/q,Z=4/3*Math.tan((o1-J)/4),p1=N(J),E=N(o1),$=G(J),X=G(o1);R.push({type:"C",x1:p1[0]+Z*$[0],y1:p1[1]+Z*$[1],x2:E[0]-Z*X[0],y2:E[1]-Z*X[1],x:E[0],y:E[1]})}return R}var C0=Math.PI/180,P1=(t,e,n)=>({params:t.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function g7(t,e,n){return t.order?[]:t.params.filter((c,r)=>r<e.length&&n.has(c))}function v7(t,e,n){if(t.rest){let a=[...e];return t.params.forEach((s,i)=>{n.has(s)&&(a[i]=n.get(s))}),a}if(!t.order)return t.params.map((a,s)=>n.has(a)?n.get(a):e[s]);let c=e.length+t.params.filter(a=>n.has(a)).length,r=t.order(c).filter(a=>!n.has(a));return t.params.map(a=>n.has(a)?n.get(a):e[r.indexOf(a)])}function pe(t,e,n,c){let r=h7(t,e,n.maxLength);if(r===void 0)throw new Error(`${c}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(r.length/8)),r}function R1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${j0(t)}`);return t}function c2(t,e,n){if(Array.isArray(t))return t;if(Q0(t))return n4(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${j0(t)}`)}var i9=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function y7(t,e,n){if(i9.has(t))return 0;let c=0;for(let r of e)if(typeof r=="string")c+=r.length;else if(Array.isArray(r))c+=t==="len"?0:r.length;else if(Q0(r)&&r.step!==0){let a=Math.floor((r.end-r.start)/r.step)+1;a>0&&(c+=Math.min(a,n+1))}return c}var N0=t=>P1("x",e=>typeof e[0]=="number"?r2(t(e[0])):void 0);function r2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function o9(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function u7(t,e,n){let c=t.length===1&&Array.isArray(t[0])?t[0]:t;if(c.length)return e(c.map(r=>R1(r,n)))}var f5={abs:N0(Math.abs),sign:N0(Math.sign),floor:N0(Math.floor),ceil:N0(Math.ceil),round:N0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:N0(Math.sqrt),exp:N0(Math.exp),ln:N0(Math.log),log:P1("x, base",(t,e)=>e.given<2?r2(Math.log10(R1(t[0],"log"))):Math.log(R1(t[0],"log"))/Math.log(R1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:N0(t=>Math.sin(t*C0)),cos:N0(t=>Math.cos(t*C0)),tan:N0(t=>Math.tan(t*C0)),asin:N0(t=>Math.asin(t)/C0),acos:N0(t=>Math.acos(t)/C0),atan:N0(t=>Math.atan(t)/C0),atan2:P1("y, x",t=>r2(Math.atan2(R1(t[0],"atan2"),R1(t[1],"atan2"))/C0)),pow:P1("x, y",t=>Math.pow(R1(t[0],"pow"),R1(t[1],"pow"))),min:P1("values...",t=>u7(t,e=>e.reduce((n,c)=>c<n?c:n,1/0),"min")),max:P1("values...",t=>u7(t,e=>e.reduce((n,c)=>c>n?c:n,-1/0),"max")),clamp:P1("x, low, high",t=>Math.min(Math.max(R1(t[0],"clamp"),R1(t[1],"clamp")),R1(t[2],"clamp"))),lerp:P1("a, b, t",t=>{let e=R1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((c,r)=>R1(c,"lerp")+(R1(n[r],"lerp")-R1(c,"lerp"))*e)}return R1(t[0],"lerp")+(R1(t[1],"lerp")-R1(t[0],"lerp"))*e}),norm:P1("v",(t,e)=>Math.sqrt(c2(t[0],"norm",e).reduce((n,c)=>n+R1(c,"norm")**2,0))),cross:P1("a, b",(t,e)=>{let n=c2(t[0],"cross",e).map(r=>R1(r,"cross")),c=c2(t[1],"cross",e).map(r=>R1(r,"cross"));return n.length===2?n[0]*c[1]-n[1]*c[0]:[n[1]*c[2]-n[2]*c[1],n[2]*c[0]-n[0]*c[2],n[0]*c[1]-n[1]*c[0]]}),len:P1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:F0(t[0])?t[0].fields.size:void 0),keys:P1("record",t=>F0(t[0])?[...t[0].fields.keys()]:void 0),merge:P1("a, b",t=>{if(!F0(t[0])||!F0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:P1("...",(t,e)=>{let n=t.reduce((c,r)=>c+(Array.isArray(r)?r.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(c=>Array.isArray(c)?c:[c])}),reverse:P1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...c2(t[0],"reverse",e)].reverse()),sum:P1("values",(t,e)=>c2(t[0],"sum",e).reduce((n,c)=>n+R1(c,"sum"),0)),slice:P1("value, start, end",(t,e)=>{let c=(typeof t[0]=="string"?[...t[0]]:c2(t[0],"slice",e)).slice(R1(t[1]??0,"slice"),t[2]===void 0?void 0:R1(t[2],"slice"));return typeof t[0]=="string"?c.join(""):c}),str:P1("...",(t,e)=>pe(t,"",e,"str")),chr:P1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(R1(e,"chr"))).join("")),ord:P1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:P1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:P1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:P1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:P1("values, separator",(t,e)=>pe(c2(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:P1("value, list",(t,e)=>{let c=(typeof t[1]=="string"?[...t[1]]:c2(t[1],"search",e)).findIndex(r=>C3(r,t[0],e.step));return c<0?void 0:c}),contains:P1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(pe([t[1]],"",e,"contains")):c2(t[0],"contains",e).some(n=>C3(n,t[1],e.step))),lookup:P1("x, table",(t,e)=>{let n=R1(t[0],"lookup"),c=c2(t[1],"lookup",e);if(!c.length)return;let r=c.map(a=>[R1(a[0],"lookup"),R1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=r[0][0])return r[0][1];for(let a=1;a<r.length;a++)if(n<=r[a][0]){let[s,i]=r[a-1],[o,l]=r[a];return i+(n-s)/(o-s)*(l-i)}return r[r.length-1][1]}),rands:P1("min, max, count, seed",t=>{let e=R1(t[0],"rands"),n=R1(t[1],"rands"),c=R1(t[2],"rands"),r=o9(t[3]===void 0?1:R1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(n-e)*r())}),is_num:P1("value",t=>l7(t[0])&&!Number.isNaN(t[0])),is_string:P1("value",t=>typeof t[0]=="string"),is_bool:P1("value",t=>typeof t[0]=="boolean"),is_list:P1("value",t=>Array.isArray(t[0])),is_record:P1("value",t=>F0(t[0])),is_undef:P1("value",t=>t[0]===void 0),is_function:P1("value",t=>P2(t[0])),type_of:P1("value",t=>j0(t[0])),path_length:P1("points",(t,e)=>{let n=u5(t[0],"path_length",e),c=0;for(let r=1;r<n.length;r++)c+=Math.hypot(n[r][0]-n[r-1][0],n[r][1]-n[r-1][1]);return c}),point_at:P1("points, s",(t,e)=>f7(u5(t[0],"point_at",e),R1(t[1],"point_at")).point),heading_at:P1("points, s",(t,e)=>r2(f7(u5(t[0],"heading_at",e),R1(t[1],"heading_at")).heading)),offset_path:P1("points, d, closed",(t,e)=>{let n=u5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),c=R1(t[1],"offset_path"),r=t[2]===!0,a=r&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(a&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let s=n.length,i=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],p=Math.hypot(f-h,d-u);return[-(d-u)/p,(f-h)/p]},o=n.map(([l,h],u)=>{let f=!r&&u===0,d=!r&&u===s-1,p=i(f?0:(u-1+s)%s),m=i(d?s-2:u),[g,v]=[p[0]+m[0],p[1]+m[1]],y=Math.hypot(g,v);if(y<1e-9)[g,v]=p;else{let b=Math.min(2/(y*y),4/y);[g,v]=[g*b,v*b]}return[r2(l+c*g),r2(h+c*v)]});return a?[...o,o[0]]:o}),train_for:P1("ratio, stages, pinion, wheel",(t,e)=>{let n=R1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let c=t[1]===void 0?2:R1(t[1],"train_for");if(!(c===1||c===2||c===3))throw new Error("train_for(): stages must be 1, 2 or 3");let r=(v,y,b)=>{if(v===void 0)return y;if(!Array.isArray(v)||v.length!==2||!v.every(w=>typeof w=="number"))throw new Error(`train_for(): ${b} must be [fewest, most] teeth`);let[x,M]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(x>=6&&M>=x&&M<=400))throw new Error(`train_for(): ${b} teeth must be from 6 to 400, fewest first`);return[x,M]},[a,s]=r(t[2],[10,20],"pinion"),[i,o]=r(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=a;v<=s;v++)for(let y=Math.max(i,v);y<=o;y++)u.push([v,y]);let f,d=v=>{let y=v.reduce((M,[w,k])=>M*k/w,1),b=Math.abs(y/h-1),x=v.reduce((M,[w,k])=>M+w+k,0);(!f||b<f.err-1e-12||Math.abs(b-f.err)<=1e-12&&x<f.teeth)&&(f={stages:v.map(M=>[...M]),err:b,teeth:x})},p=(v,y)=>{e.step();for(let b=a;b<=s;b++)for(let x of[Math.floor(y*b),Math.ceil(y*b)])x>=Math.max(i,b)&&x<=o&&d([...v,[b,x]])};if(c===1)p([],h);else for(let v=0;v<u.length;v++){let y=u[v][1]/u[v][0];if(c===2)p([u[v]],h/y);else for(let b=v;b<u.length;b++)p([u[v],u[b]],h/y/(u[b][1]/u[b][0]))}if(!f)throw new Error(`train_for(): no train of ${c} stages reaches a ratio of ${n}`);let m=f.stages.map(([v,y])=>l?[y,v]:[v,y]),g=m.reduce((v,[y,b])=>v*b/y,1);return{type:"record",fields:new Map([["stages",m],["ratio",g],["error",g/n-1]])}}),path_points:P1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:R1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let c=T3(E3(t[0]),n),r=[...c.closed.map(a=>[...a,a[0]]),...c.open];return e.step(r.reduce((a,s)=>a+s.length,0)),r.map(a=>a.map(([s,i])=>[s,i]))}),spline_points:P1("points, steps, closed",(t,e)=>{let n=u5(t[0],"spline_points",e),c=t[1]===void 0?8:Math.floor(R1(t[1],"spline_points"));if(!(c>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*c>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*c),ge(n,c,t[2]===!0)}),rotation:P1("angles",t=>{let[e,n,c]=me(t[0],"rotation");return d9(p7(f9(c),p7(u9(n),h9(e))))}),euler:P1("matrix",t=>m7(l9(t[0],"euler"))),orient:P1("x, z",t=>{let e=d7(me(t[0],"orient"),"orient"),n=me(t[1]??[0,0,1],"orient"),c=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=d7([n[0]-c*e[0],n[1]-c*e[1],n[2]-c*e[2]],"orient");let r=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return m7([[e[0],r[0],n[0]],[e[1],r[1],n[1]],[e[2],r[2],n[2]]])})};function u5(t,e,n){return c2(t,e,n).map((r,a)=>{if(!Array.isArray(r)||typeof r[0]!="number"||typeof r[1]!="number")throw new Error(`${e}(): points[${a}] must be an [x, y] point`);return[r[0],r[1]]})}function f7(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([o,l],h)=>h===0||o!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let c=0,r=0;for(;c<n.length-2;c++){let o=Math.hypot(n[c+1][0]-n[c][0],n[c+1][1]-n[c][1]);if(r+o>=e)break;r+=o}let[a,s]=[n[c],n[c+1]],i=(e-r)/Math.hypot(s[0]-a[0],s[1]-a[1]);return{point:[a[0]+(s[0]-a[0])*i,a[1]+(s[1]-a[1])*i],heading:Math.atan2(s[1]-a[1],s[0]-a[0])/C0}}function me(t,e){if(!Array.isArray(t)||t.length<2||t.length>3||!t.every(n=>typeof n=="number"))throw new Error(`${e}() needs [x, y, z]`);return[t[0],t[1],t[2]??0]}function d7(t,e){let n=Math.hypot(...t);if(!(n>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[t[0]/n,t[1]/n,t[2]/n]}function l9(t,e){if(!Array.isArray(t)||t.length<3||!t.slice(0,3).every(n=>Array.isArray(n)&&n.length>=3&&n.slice(0,3).every(c=>typeof c=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var h9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[1,0,0],[0,e,-n],[0,n,e]]},u9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,0,n],[0,1,0],[-n,0,e]]},f9=t=>{let[e,n]=[Math.cos(t*C0),Math.sin(t*C0)];return[[e,-n,0],[n,e,0],[0,0,1]]},p7=(t,e)=>t.map(n=>[0,1,2].map(c=>n[0]*e[0][c]+n[1]*e[1][c]+n[2]*e[2][c])),d9=t=>t.map(e=>e.map(r2));function m7(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,c=Math.atan2(-t[0][1],t[1][1])/C0;return[0,n,r2(c)]}return[r2(Math.atan2(t[2][1],t[2][2])/C0),r2(Math.asin(e)/C0),r2(Math.atan2(t[1][0],t[0][0])/C0)]}function ge(t,e,n=!1){if(t.length<3)return t.map(([s,i])=>[s,i]);let c=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=t.length){let[i,o]=[t[t.length-1],t[t.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return t[s]},r=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[i,o,l,h]=[c(s-1),c(s),c(s+1),c(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,p=d*f;r.push([0,1].map(m=>.5*(2*o[m]+(-i[m]+l[m])*f+(2*i[m]-5*o[m]+4*l[m]-h[m])*d+(-i[m]+3*o[m]-3*l[m]+h[m])*p)))}}return r.push(n?r[0]:[t[t.length-1][0],t[t.length-1][1]]),r}function c3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var d5=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function p9(t,e,n,c){if(e==="flat")return[];let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===1:i%2===0)&&s.push(d5(i*a,-1,(i+1)*a,n));return s}function c4(t,e,n,c,r){let a=[([o,l])=>[o,l],([o,l])=>[t-l,o],([o,l])=>[t-o,e-l],([o,l])=>[l,e-o]],s=[t,e,t,e],i=[];return n.forEach((o,l)=>{for(let h of p9(s[l],o,c,r))i.push(h.map(a[l]))}),b0([d5(0,0,t,e)],i)}function b7(t,e,n,c){let r=c3(t,c),a=t/r,s=[];for(let i=0;i<r;i++)(e==="out"?i%2===0:i%2===1)&&s.push(d5(i*a,-n/2,(i+1)*a,n/2));return s}function x7(t,e,n,c,r){let a=d5(-t/2,-1,t/2,e),s=d5(-n/2,r,n/2,r+c);return[a,s]}function M7(t,e,n,c,r){let a=[],s=r+c,i=Math.floor(t/n),o=(t-i*n)/2;for(let l=0;l<=i;l++){let h=o+l*n,u=l%2===0?c:c-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?c:0),p=Math.min(f+r,e-(l%2===0?c:0));p-d>=c/2&&a.push([[h,d],[h,p]])}}return a}var T2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var i1=class extends Error{constructor(n,c){super(c?`${n} (${T2(c)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,c&&(this.line=c.line,this.col=c.col,this.file=c.file)}addFrame(n,c,r){let a=this.trace.find(s=>s.name===c&&s.line===r.line&&s.col===r.col&&s.file===r.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:c,line:r.line,col:r.col,...r.file&&{file:r.file},count:1})}},m9=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function p5(t,e){let n=[],c=[],r=0,a=1,s=0,i=()=>({line:a,col:r-s+1,offset:r,...e&&{file:e}}),o=l=>{for(let h=0;h<l;h++)t[r]===`
7
7
  `&&(a++,s=r+1),r++};for(;r<t.length;){let l=t[r];if(l===" "||l===" "||l==="\r"||l===`
8
8
  `){o(1);continue}if(l==="/"&&t[r+1]==="/"){let f=t.indexOf(`
9
- `,r),d=f<0?t.length:f,m=/^[ \t]*$/.test(t.slice(t.lastIndexOf(`
10
- `,r-1)+1,r));c.push({text:t.slice(r+2,d).trim(),line:a,block:!1,own:m,start:r,end:d}),r=d;continue}if(l==="/"&&t[r+1]==="*"){let f=i(),d=t.indexOf("*/",r+2);if(d<0)throw new i1("Unclosed block comment",f);c.push({text:t.slice(r+2,d).trim(),line:f.line,block:!0,own:!0,start:r,end:d+2}),o(d+2-r);continue}let h=i();if(/[0-9]/.test(l)||l==="."&&/[0-9]/.test(t[r+1]??"")){let f=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(t.slice(r));n.push({type:"num",value:f[0],pos:h,end:r+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(r));n.push({type:"id",value:f[0],pos:h,end:r+f[0].length}),o(f[0].length);continue}if(l==='"'){let f="";for(o(1);r<t.length&&t[r]!=='"';){if(t[r]==="\\"){let d=t[r+1];if(d==="n")f+=`
11
- `;else if(d==="t")f+=" ";else if(d==="u"){let m=t.slice(r+2,r+6);if(!/^[0-9a-fA-F]{4}$/.test(m))throw new i1("Bad \\u escape",i());f+=String.fromCharCode(parseInt(m,16)),o(4)}else f+=d;o(2);continue}if(t[r]===`
12
- `)throw new i1("Unclosed string",h);f+=t[r],o(1)}if(r>=t.length)throw new i1("Unclosed string",h);o(1),n.push({type:"str",value:f,pos:h,end:r});continue}if(l==="<"&&/^<[A-Za-z0-9_./-]+>/.test(t.slice(r))){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([A-Za-z0-9_./-]+)>/.exec(t.slice(r));n.push({type:"str",value:d[1],pos:h,end:r+d[0].length}),o(d[0].length);continue}}let u=dn.find(f=>t.startsWith(f,r));if(!u)throw new i1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:r+u.length}),o(u.length)}return n.push({type:"eof",value:"",pos:i(),end:r}),{tokens:n,comments:c}}var I3={dowel:{color:"#e2c48f",doc:"a wooden dowel or axle"},steel:{color:"#a7adb3",metal:!0,doc:"a steel rod, pin or axle"},brass:{color:"#c9a227",metal:!0,doc:"a brass rod, tube or pin"},screw:{color:"#9aa0a6",metal:!0,doc:"a screw"},bolt:{color:"#9aa0a6",metal:!0,doc:"a bolt"},nut:{color:"#9aa0a6",metal:!0,doc:"a nut"},magnet:{color:"#55585c",metal:!0,doc:"a disc or block magnet"},paper:{color:"#fbfaf6",doc:"a sheet or strip of paper"},card:{color:"#f4f1e8",doc:"card stock"},felt:{color:"#6f6a64",doc:"felt pads or lining"},elastic:{color:"#262626",doc:"an elastic band or cord"},cord:{color:"#b23a3a",doc:"cord, string or thread"},ribbon:{color:"#c2485a",doc:"ribbon or tape"},wire:{color:"#b87333",metal:!0,doc:"wire"},led:{color:"#fff4c2",glow:!0,doc:"an LED or a strip of them"},white:{color:"#f7f7f4",doc:"anything white"}},d5={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var g6=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function r2(t,e){let{tokens:n,comments:c}=f5(t,e),r=new v6(n),a=[];for(;!r.at("eof");)a.push(...r.statement());return{program:{body:a},comments:c}}var m5=class m5{constructor(e){this.tokens=e;this.i=0}peek(e=0){return this.tokens[Math.min(this.i+e,this.tokens.length-1)]}at(e,n,c=0){let r=this.peek(c);return r.type===e&&(n===void 0||r.value===n)}isP(e,n=0){return this.at("punct",e,n)}isK(e,n=0){return this.at("id",e,n)}next(){return this.tokens[this.i++]}fail(e,n=this.peek()){let c=n.type==="eof"?"end of file":`"${n.value}"`;throw new i1(`${e}, found ${c}`,n.pos)}expectP(e){return this.isP(e)||this.fail(`Expected "${e}"`),this.next()}separator(e){this.isP(e)||(this.isP(",")||this.fail(`Expected "," or "${e}"`),this.next())}ident(){let e=this.peek();return(e.type!=="id"||g6.has(e.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let e=this.stmt();for(let n of e)n.end=this.last();return e}stmt(){let e=this.peek();if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let s=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),s.push(...this.statement());return this.next(),[{kind:"block",body:s,pos:e.pos}]}if(this.isK("module")){this.next();let s=this.ident(),i=this.params();return[{kind:"module",name:s.value,params:i,body:this.body(),pos:e.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),i=this.params();this.expectP("=");let o=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:i,body:o,pos:e.pos,namePos:s.pos}]}if(this.isK("use")||this.isK("include")){this.next();let s=this.peek();return s.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:s.value,include:e.value==="include",pos:e.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(this.isK("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let i=this.body(),o=[];return this.isK("else")&&(this.next(),o=this.body()),[{kind:"if",cond:s,then:i,else:o,pos:e.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(e.type==="id"&&this.isP("=",1)){let s=this.ident().value;this.next();let i=this.peek().pos.offset,o=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:o,span:[i,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let c=this.peek();(c.type!=="id"||g6.has(c.value))&&this.fail("Expected a statement"),this.next();let r=this.args(),a=this.body();return[{kind:"call",name:c.value,args:r,children:a,modifier:n,pos:c.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident(),c=null;this.isP("=")&&(this.next(),c=this.expr()),e.push({name:n.value,default:c,pos:n.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let n=this.next();this.next(),e.push({name:n.value,value:this.expr(),pos:n.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident();this.expectP("="),e.push({name:n.value,value:this.expr(),pos:n.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let c=this.params(),r=this.expr();return{kind:"lambda",params:c,body:r,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let c=this.assigns(),r=this.expr();return{kind:"let",assigns:c,body:r,pos:e.pos,end:this.last()}}let n=this.binary(0);if(this.isP("?")){this.next();let c=this.expr();this.expectP(":");let r=this.expr();return{kind:"ternary",cond:n,then:c,else:r,pos:e.pos}}return n}binary(e){if(e>=m5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&m5.LEVELS[e].includes(this.peek().value);){let c=this.next(),r=this.binary(e+1);n={kind:"binary",op:c.value,left:n,right:r,pos:c.pos}}return n}unary(){if(this.isP("-")||this.isP("!")||this.isP("+")){let e=this.next();return{kind:"unary",op:e.value,arg:this.unary(),pos:e.pos}}return this.power()}power(){let e=this.postfix();if(this.isP("^")){let n=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:n.pos}}return e}postfix(){let e=this.primary();for(;;){let n=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let c=this.expr();this.expectP("]"),e={kind:"index",target:e,index:c,pos:n.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:n.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let n=/(mm|cm|m|in|ft)$/.exec(e.value);return n?{kind:"num",value:Number(e.value.slice(0,-n[1].length)),unit:n[1],pos:e.pos}:{kind:"num",value:Number(e.value),pos:e.pos}}if(e.type==="str")return this.next(),{kind:"str",value:e.value,pos:e.pos};if(e.type==="id")return e.value==="true"||e.value==="false"?(this.next(),{kind:"bool",value:e.value==="true",pos:e.pos}):e.value==="undef"?(this.next(),{kind:"undef",pos:e.pos}):(g6.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let n=this.expr();return this.expectP(")"),n}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),n=[];for(;!this.isP("}");){let c=this.ident();if(n.some(r=>r.name===c.value))throw new i1(`Field ${c.value} is given twice`,c.pos);if(this.expectP("="),n.push({name:c.value,value:this.expr(),pos:c.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:n,pos:e.pos}}list(){let e=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:e.pos};if(!this.isK("for")&&!this.isK("if")&&!this.isK("each")&&!(this.isK("let")&&this.isP("(",1))&&!(this.isP("(")&&(this.isK("for",1)||this.isK("if",1)))){let n=this.expr();if(this.isP(":")){this.next();let r=null,a=this.expr();return this.isP(":")&&(this.next(),r=a,a=this.expr()),this.expectP("]"),{kind:"range",start:n,step:r,end:a,pos:e.pos}}let c=[{kind:"item",expr:n}];return this.listRest(c,e.pos)}return this.listRest([],e.pos)}listRest(e,n){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:n};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:n}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let n=this.assigns(),c=this.listItem();return{kind:"for",assigns:n,body:c,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let c=this.listItem(),r=null;return this.isK("else")&&(this.next(),r=this.listItem()),{kind:"if",cond:n,then:c,else:r}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),c=this.listItem();return{kind:"let",assigns:n,body:c,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let n=this.listItem();return this.expectP(")"),n}return{kind:"item",expr:this.expr()}}};m5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var v6=m5;var O=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),j1=(t,e,n)=>({...O(t,e,n),named:!0}),y6="max(3 * $thickness, 6)",n4=[O("value")],mn=[O("x")],N0=(t,e)=>({name:t,kind:"function",params:mn,section:"Numbers and vectors",doc:e}),r3=(t,e)=>({name:t,kind:"function",params:n4,section:"Types",doc:`Whether the value is ${e}`}),b7=(t,e)=>({name:t,kind:"function",params:[O("text","The text to measure",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),j1("halign","left, center or right",'"left"'),j1("valign","baseline, top, center or bottom",'"baseline"'),j1("spacing","Letter spacing factor","1"),j1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),x7=[{name:"rect",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the rectangle on the origin instead of its corner","false"),j1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the square on the origin instead of its corner","false"),j1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[O("r","Radius","1"),j1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[O("r","[rx, ry], or one radius for both","1")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[O("n","Number of corners","6"),O("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[O("n","Number of points","5"),O("r","Radius of the points","10"),O("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[O("points","A list of [x, y] points"),O("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[O("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),j1("fill",'"evenodd" or "nonzero"','"evenodd"'),j1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[O("text","The text",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),j1("halign","left, center or right",'"left"'),j1("valign","baseline, top, center or bottom",'"baseline"'),j1("spacing","Letter spacing factor","1"),j1("fit","Shrink the size so the text is no wider than this")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[O("from","Start point","[0, 0]"),O("to","End point","[10, 0]"),O("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[O("points","A list of [x, y] points"),O("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[O("r","Radius","10"),O("start","Start angle in degrees","0"),O("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[O("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[O("a","Angle in degrees, anticlockwise","0"),j1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[O("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[O("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[O("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[O("r","Grow (positive) or shrink areas with rounded corners"),j1("delta","Grow or shrink areas with sharp corners","0"),j1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[O("spacing","Distance between copies, a number or [x, y]","10"),O("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[O("points","The [x, y] points the curve goes through"),O("width","Make an area this wide along the curve, instead of a line"),j1("steps","Points between each two given ones","8"),j1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[O("angle","Direction of the lines, in degrees from +x","45"),O("pitch","Distance between the lines","5"),O("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"paint",kind:"module",params:[O("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[O("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[O("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"close",kind:"module",params:[O("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[O("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[O("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[O("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[O("name","Layer name"),O("mode",'"cut", "line", "fill" or "guide"'),O("color",'Colour in the output, as "#00aa00"'),j1("order","Where it goes among the custom layers in the files, lowest first","0"),j1("bleed","How far past the part's edge it may print","0"),j1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[O("name","Part name",'"part"'),O("qty","Number of copies to cut","1"),j1("at","Where the part goes in the assembled view, [x, y, z]"),j1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),j1("stack","Layers glued in a stack at each placement, one thickness apart","1"),j1("mirror","Cut the part mirrored left to right, its text still reading","false"),j1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),j1("on","The name of a bent part this one is glued to, to move with it"),j1("slots","Names of parts whose tabs pass through this one: their slots are cut"),j1("clearance","Added to the slots, in total across each","0.1"),j1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),j1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[O("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),O("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[O("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[O("text","What to do in this step",'""'),O("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[O("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),O("from","One end, [x, y, z]"),O("to","The other end, [x, y, z]"),O("size","Diameter, or [width, height] for a flat section","6"),j1("up","The direction a [width, height] section's height points"),j1("sides","Sides of a round section in the 3D view","24"),j1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[O("thickness","Sets $thickness"),O("kerf","Sets $kerf"),O("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[O("size","[width, height]"),O("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),O("finger","Finger width",y6)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[O("length","Length of the edge that plugs in"),O("edge",'"out" or "in", the kind of edge that plugs in','"out"'),O("finger","Finger width",y6)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[O("d","Screw diameter","3"),O("length","Screw length into the panel","12"),O("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),O("nut_at","Distance of the nut from the edge","length / 2")],section:"Joinery",doc:"A T-slot for a screw and nut, opening at y = 0; subtract it from a panel edge"},{name:"living_hinge",kind:"module",params:[O("size","[width, height]"),O("spacing","Distance between the rows of cuts","1.5"),O("bridge","Uncut length between cuts","3"),O("cut","Length of each cut","max(bridge * 2, (height - 3 * bridge) / 2)")],section:"Joinery",doc:"A straight-line flex pattern of cut lines filling [width, height]"},{name:"children",kind:"module",params:[O("index","Which child, from 0, or a list of them")],section:"Other",doc:"Run the child statements passed to the current module"},{name:"echo",kind:"both",params:[],rest:!0,anyNamed:!0,section:"Other",doc:"Write values to the output without making shapes"},{name:"assert",kind:"both",params:[O("condition","Stops the program when false"),O("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},N0("abs","Absolute value"),N0("sign","Sign as -1, 0 or 1"),N0("floor","Round down"),N0("ceil","Round up"),N0("round","Round to the nearest integer, halves away from zero"),N0("sqrt","Square root"),N0("exp","e raised to x"),N0("ln","Natural logarithm"),{name:"log",kind:"function",params:[O("x"),O("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},N0("sin","Sine of an angle in degrees"),N0("cos","Cosine of an angle in degrees"),N0("tan","Tangent of an angle in degrees"),N0("asin","Inverse sine, in degrees"),N0("acos","Inverse cosine, in degrees"),N0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[O("y"),O("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[O("x"),O("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[O("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[O("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[O("x"),O("low"),O("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[O("a"),O("b"),O("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"norm",kind:"function",params:[O("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[O("a"),O("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[O("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"point_at",kind:"function",params:[O("points","A list of [x, y] points"),O("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[O("points","A list of [x, y] points"),O("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[O("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),O("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[O("points","The [x, y] points the curve goes through"),O("steps","Points between each two given ones","8"),O("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[O("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[O("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[O("x","Where the part's own x axis points"),O("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:n4,section:"Lists and strings",doc:"Number of items in a list, characters in a string or fields in a record"},{name:"keys",kind:"function",params:[O("record","A record, as {name = value}")],section:"Lists and strings",doc:"A record's field names, in the order they were written"},{name:"merge",kind:"function",params:[O("a","A record"),O("b","A record whose fields add to or replace those of a")],section:"Lists and strings",doc:"A record with the fields of a and b, b winning where both have one"},{name:"concat",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Join lists and single values into one list"},{name:"reverse",kind:"function",params:n4,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sum",kind:"function",params:[O("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[O("value","A list or string"),O("start","First index","0"),O("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[O("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[O("text"),O("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[O("values"),O("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[O("value"),O("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[O("value","A list or string"),O("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[O("x"),O("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},r3("is_num","a number other than NaN"),r3("is_string","a string"),r3("is_bool","true or false"),r3("is_list","a list"),r3("is_undef","undef"),r3("is_function","a function"),r3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:n4,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"rands",kind:"function",params:[O("min"),O("max"),O("count"),O("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},b7("text_width","The advance width of the text, including spacing"),b7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[O("length","Edge length"),O("finger","Finger width",y6)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],pn=new Map(x7.map(t=>[t.name,t])),p5=t=>pn.get(t);function b6(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var g5={"kerf/box":`// kerf/box: finger-jointed boxes.
9
+ `,r),d=f<0?t.length:f,p=/^[ \t]*$/.test(t.slice(t.lastIndexOf(`
10
+ `,r-1)+1,r));c.push({text:t.slice(r+2,d).trim(),line:a,block:!1,own:p,start:r,end:d}),r=d;continue}if(l==="/"&&t[r+1]==="*"){let f=i(),d=t.indexOf("*/",r+2);if(d<0)throw new i1("Unclosed block comment",f);c.push({text:t.slice(r+2,d).trim(),line:f.line,block:!0,own:!0,start:r,end:d+2}),o(d+2-r);continue}let h=i();if(/[0-9]/.test(l)||l==="."&&/[0-9]/.test(t[r+1]??"")){let f=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(t.slice(r));n.push({type:"num",value:f[0],pos:h,end:r+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(r));n.push({type:"id",value:f[0],pos:h,end:r+f[0].length}),o(f[0].length);continue}if(l==='"'){let f="";for(o(1);r<t.length&&t[r]!=='"';){if(t[r]==="\\"){let d=t[r+1];if(d==="n")f+=`
11
+ `;else if(d==="t")f+=" ";else if(d==="u"){let p=t.slice(r+2,r+6);if(!/^[0-9a-fA-F]{4}$/.test(p))throw new i1("Bad \\u escape",i());f+=String.fromCharCode(parseInt(p,16)),o(4)}else f+=d;o(2);continue}if(t[r]===`
12
+ `)throw new i1("Unclosed string",h);f+=t[r],o(1)}if(r>=t.length)throw new i1("Unclosed string",h);o(1),n.push({type:"str",value:f,pos:h,end:r});continue}if(l==="<"&&/^<[A-Za-z0-9_./-]+>/.test(t.slice(r))){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([A-Za-z0-9_./-]+)>/.exec(t.slice(r));n.push({type:"str",value:d[1],pos:h,end:r+d[0].length}),o(d[0].length);continue}}let u=m9.find(f=>t.startsWith(f,r));if(!u)throw new i1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:r+u.length}),o(u.length)}return n.push({type:"eof",value:"",pos:i(),end:r}),{tokens:n,comments:c}}var I3={dowel:{color:"#e2c48f",doc:"a wooden dowel or axle"},steel:{color:"#a7adb3",metal:!0,doc:"a steel rod, pin or axle"},brass:{color:"#c9a227",metal:!0,doc:"a brass rod, tube or pin"},screw:{color:"#9aa0a6",metal:!0,doc:"a screw"},bolt:{color:"#9aa0a6",metal:!0,doc:"a bolt"},nut:{color:"#9aa0a6",metal:!0,doc:"a nut"},magnet:{color:"#55585c",metal:!0,doc:"a disc or block magnet"},paper:{color:"#fbfaf6",doc:"a sheet or strip of paper"},card:{color:"#f4f1e8",doc:"card stock"},felt:{color:"#6f6a64",doc:"felt pads or lining"},elastic:{color:"#262626",doc:"an elastic band or cord"},cord:{color:"#b23a3a",doc:"cord, string or thread"},ribbon:{color:"#c2485a",doc:"ribbon or tape"},wire:{color:"#b87333",metal:!0,doc:"wire"},led:{color:"#fff4c2",glow:!0,doc:"an LED or a strip of them"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb; give it shape = "ball"'},ball:{color:"#8fb8d8",doc:'a marble, ball or bead; give it shape = "ball"'},tube:{color:"#c9a227",metal:!0,doc:"a tube, as a hollow arbor or a sleeve"},lens:{color:"#d6ecf3",doc:"a lens, a thin disc of glass or acrylic"},mirror:{color:"#c8d3da",metal:!0,doc:"a mirror"},movement:{color:"#3d3d3d",doc:"a bought movement, as a clock, music box or motor: a labelled block"},white:{color:"#f7f7f4",doc:"anything white"}},m5={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var ve=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function a2(t,e){let{tokens:n,comments:c}=p5(t,e),r=new ye(n),a=[];for(;!r.at("eof");)a.push(...r.statement());return{program:{body:a},comments:c}}var g5=class g5{constructor(e){this.tokens=e;this.i=0}peek(e=0){return this.tokens[Math.min(this.i+e,this.tokens.length-1)]}at(e,n,c=0){let r=this.peek(c);return r.type===e&&(n===void 0||r.value===n)}isP(e,n=0){return this.at("punct",e,n)}isK(e,n=0){return this.at("id",e,n)}next(){return this.tokens[this.i++]}fail(e,n=this.peek()){let c=n.type==="eof"?"end of file":`"${n.value}"`;throw new i1(`${e}, found ${c}`,n.pos)}expectP(e){return this.isP(e)||this.fail(`Expected "${e}"`),this.next()}separator(e){this.isP(e)||(this.isP(",")||this.fail(`Expected "," or "${e}"`),this.next())}ident(){let e=this.peek();return(e.type!=="id"||ve.has(e.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let e=this.stmt();for(let n of e)n.end=this.last();return e}stmt(){let e=this.peek();if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let s=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),s.push(...this.statement());return this.next(),[{kind:"block",body:s,pos:e.pos}]}if(this.isK("module")){this.next();let s=this.ident(),i=this.params();return[{kind:"module",name:s.value,params:i,body:this.body(),pos:e.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),i=this.params();this.expectP("=");let o=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:i,body:o,pos:e.pos,namePos:s.pos}]}if(this.isK("use")||this.isK("include")){this.next();let s=this.peek();return s.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:s.value,include:e.value==="include",pos:e.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(this.isK("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let i=this.body(),o=[];return this.isK("else")&&(this.next(),o=this.body()),[{kind:"if",cond:s,then:i,else:o,pos:e.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(e.type==="id"&&this.isP("=",1)){let s=this.ident().value;this.next();let i=this.peek().pos.offset,o=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:o,span:[i,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let c=this.peek();(c.type!=="id"||ve.has(c.value))&&this.fail("Expected a statement"),this.next();let r=this.args(),a=this.body();return[{kind:"call",name:c.value,args:r,children:a,modifier:n,pos:c.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident(),c=null;this.isP("=")&&(this.next(),c=this.expr()),e.push({name:n.value,default:c,pos:n.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let n=this.next();this.next(),e.push({name:n.value,value:this.expr(),pos:n.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident();this.expectP("="),e.push({name:n.value,value:this.expr(),pos:n.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let c=this.params(),r=this.expr();return{kind:"lambda",params:c,body:r,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let c=this.assigns(),r=this.expr();return{kind:"let",assigns:c,body:r,pos:e.pos,end:this.last()}}let n=this.binary(0);if(this.isP("?")){this.next();let c=this.expr();this.expectP(":");let r=this.expr();return{kind:"ternary",cond:n,then:c,else:r,pos:e.pos}}return n}binary(e){if(e>=g5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&g5.LEVELS[e].includes(this.peek().value);){let c=this.next(),r=this.binary(e+1);n={kind:"binary",op:c.value,left:n,right:r,pos:c.pos}}return n}unary(){if(this.isP("-")||this.isP("!")||this.isP("+")){let e=this.next();return{kind:"unary",op:e.value,arg:this.unary(),pos:e.pos}}return this.power()}power(){let e=this.postfix();if(this.isP("^")){let n=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:n.pos}}return e}postfix(){let e=this.primary();for(;;){let n=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let c=this.expr();this.expectP("]"),e={kind:"index",target:e,index:c,pos:n.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:n.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let n=/(mm|cm|m|in|ft)$/.exec(e.value);return n?{kind:"num",value:Number(e.value.slice(0,-n[1].length)),unit:n[1],pos:e.pos}:{kind:"num",value:Number(e.value),pos:e.pos}}if(e.type==="str")return this.next(),{kind:"str",value:e.value,pos:e.pos};if(e.type==="id")return e.value==="true"||e.value==="false"?(this.next(),{kind:"bool",value:e.value==="true",pos:e.pos}):e.value==="undef"?(this.next(),{kind:"undef",pos:e.pos}):(ve.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let n=this.expr();return this.expectP(")"),n}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),n=[];for(;!this.isP("}");){let c=this.ident();if(n.some(r=>r.name===c.value))throw new i1(`Field ${c.value} is given twice`,c.pos);if(this.expectP("="),n.push({name:c.value,value:this.expr(),pos:c.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:n,pos:e.pos}}list(){let e=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:e.pos};if(!this.isK("for")&&!this.isK("if")&&!this.isK("each")&&!(this.isK("let")&&this.isP("(",1))&&!(this.isP("(")&&(this.isK("for",1)||this.isK("if",1)))){let n=this.expr();if(this.isP(":")){this.next();let r=null,a=this.expr();return this.isP(":")&&(this.next(),r=a,a=this.expr()),this.expectP("]"),{kind:"range",start:n,step:r,end:a,pos:e.pos}}let c=[{kind:"item",expr:n}];return this.listRest(c,e.pos)}return this.listRest([],e.pos)}listRest(e,n){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:n};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:n}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let n=this.assigns(),c=this.listItem();return{kind:"for",assigns:n,body:c,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let c=this.listItem(),r=null;return this.isK("else")&&(this.next(),r=this.listItem()),{kind:"if",cond:n,then:c,else:r}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),c=this.listItem();return{kind:"let",assigns:n,body:c,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let n=this.listItem();return this.expectP(")"),n}return{kind:"item",expr:this.expr()}}};g5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var ye=g5;var H=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),B1=(t,e,n)=>({...H(t,e,n),named:!0}),be="max(3 * $thickness, 6)",r4=[H("value")],g9=[H("x")],U0=(t,e)=>({name:t,kind:"function",params:g9,section:"Numbers and vectors",doc:e}),r3=(t,e)=>({name:t,kind:"function",params:r4,section:"Types",doc:`Whether the value is ${e}`}),w7=(t,e)=>({name:t,kind:"function",params:[H("text","The text to measure",'""'),H("size","Font size in millimetres","10"),H("font","Font name","$font"),B1("halign","left, center or right",'"left"'),B1("valign","baseline, top, center or bottom",'"baseline"'),B1("spacing","Letter spacing factor","1"),B1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),z7=[{name:"rect",kind:"module",params:[H("size","A number, or [width, height]","1"),H("center","Centre the rectangle on the origin instead of its corner","false"),B1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[H("size","A number, or [width, height]","1"),H("center","Centre the square on the origin instead of its corner","false"),B1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[H("r","Radius","1"),B1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[H("r","[rx, ry], or one radius for both","1")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[H("n","Number of corners","6"),H("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[H("n","Number of points","5"),H("r","Radius of the points","10"),H("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[H("points","A list of [x, y] points"),H("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[H("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),B1("fill",'"evenodd" or "nonzero"','"evenodd"'),B1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[H("text","The text",'""'),H("size","Font size in millimetres","10"),H("font","Font name","$font"),B1("halign","left, center or right",'"left"'),B1("valign","baseline, top, center or bottom",'"baseline"'),B1("spacing","Letter spacing factor","1"),B1("fit","Shrink the size so the text is no wider than this")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[H("from","Start point","[0, 0]"),H("to","End point","[10, 0]"),H("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[H("points","A list of [x, y] points"),H("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[H("r","Radius","10"),H("start","Start angle in degrees","0"),H("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[H("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[H("a","Angle in degrees, anticlockwise","0"),B1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[H("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[H("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[H("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[H("r","Grow (positive) or shrink areas with rounded corners"),B1("delta","Grow or shrink areas with sharp corners","0"),B1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[H("spacing","Distance between copies, a number or [x, y]","10"),H("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[H("points","The [x, y] points the curve goes through"),H("width","Make an area this wide along the curve, instead of a line"),B1("steps","Points between each two given ones","8"),B1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[H("angle","Direction of the lines, in degrees from +x","45"),H("pitch","Distance between the lines","5"),H("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"paint",kind:"module",params:[H("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[H("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1], $area and $centroid = [x, y] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[H("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"close",kind:"module",params:[H("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[H("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[H("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[H("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[H("name","Layer name"),H("mode",'"cut", "line", "fill" or "guide"'),H("color",'Colour in the output, as "#00aa00"'),B1("order","Where it goes among the custom layers in the files, lowest first","0"),B1("bleed","How far past the part's edge it may print","0"),B1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[H("name","Part name",'"part"'),H("qty","Number of copies to cut","1"),B1("at","Where the part goes in the assembled view, [x, y, z]"),B1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),B1("stack","Layers glued in a stack at each placement, one thickness apart","1"),B1("mirror","Cut the part mirrored left to right, its text still reading","false"),B1("material","The material it is cut from, as material(name = ...) sets it"),B1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),B1("on","The name of a bent part this one is glued to, to move with it"),B1("slots","Names of parts whose tabs pass through this one: their slots are cut"),B1("clearance","Added to the slots, in total across each","0.1"),B1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),B1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[H("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),H("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[H("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[H("text","What to do in this step",'""'),H("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[H("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),H("from","One end, [x, y, z]; a ball sits midway between from and to"),H("to","The other end, [x, y, z]; a ball may leave it out"),H("size","Diameter, or [width, height] for a flat section","6"),B1("up","The direction a [width, height] section's height points"),B1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),B1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),B1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[H("thickness","Sets $thickness"),H("kerf","Sets $kerf"),H("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[H("size","[width, height]"),H("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),H("finger","Finger width",be)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[H("length","Length of the edge that plugs in"),H("edge",'"out" or "in", the kind of edge that plugs in','"out"'),H("finger","Finger width",be)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[H("d","Screw diameter","3"),H("length","Screw length into the panel","12"),H("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),H("nut_at","Distance of the nut from the edge","length / 2")],section:"Joinery",doc:"A T-slot for a screw and nut, opening at y = 0; subtract it from a panel edge"},{name:"living_hinge",kind:"module",params:[H("size","[width, height]"),H("spacing","Distance between the rows of cuts","1.5"),H("bridge","Uncut length between cuts","3"),H("cut","Length of each cut","max(bridge * 2, (height - 3 * bridge) / 2)")],section:"Joinery",doc:"A straight-line flex pattern of cut lines filling [width, height]"},{name:"children",kind:"module",params:[H("index","Which child, from 0, or a list of them")],section:"Other",doc:"Run the child statements passed to the current module"},{name:"echo",kind:"both",params:[],rest:!0,anyNamed:!0,section:"Other",doc:"Write values to the output without making shapes"},{name:"assert",kind:"both",params:[H("condition","Stops the program when false"),H("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},U0("abs","Absolute value"),U0("sign","Sign as -1, 0 or 1"),U0("floor","Round down"),U0("ceil","Round up"),U0("round","Round to the nearest integer, halves away from zero"),U0("sqrt","Square root"),U0("exp","e raised to x"),U0("ln","Natural logarithm"),{name:"log",kind:"function",params:[H("x"),H("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},U0("sin","Sine of an angle in degrees"),U0("cos","Cosine of an angle in degrees"),U0("tan","Tangent of an angle in degrees"),U0("asin","Inverse sine, in degrees"),U0("acos","Inverse cosine, in degrees"),U0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[H("y"),H("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[H("x"),H("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[H("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[H("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[H("x"),H("low"),H("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[H("a"),H("b"),H("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[H("ratio","Turns in for one turn out; under 1 speeds up"),H("stages","Pairs of gears, 1 to 3","2"),H("pinion","Fewest and most teeth of the small gears","[10, 20]"),H("wheel","Fewest and most teeth of the big gears","[20, 80]")],section:"Numbers and vectors",doc:"Tooth counts for a gear train nearest a ratio: {stages = [[driver, driven], ...], ratio, error}"},{name:"norm",kind:"function",params:[H("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[H("a"),H("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[H("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"offset_path",kind:"function",params:[H("points","A list of [x, y] points"),H("d","How far to move it: to the left going along it, or the right when less than 0"),H("closed","The path goes round, its last point joined to its first","false")],section:"Paths and rotations",doc:"The path moved sideways, each corner mitred: the two edges of a strip along a curve"},{name:"point_at",kind:"function",params:[H("points","A list of [x, y] points"),H("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[H("points","A list of [x, y] points"),H("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[H("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),H("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[H("points","The [x, y] points the curve goes through"),H("steps","Points between each two given ones","8"),H("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[H("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[H("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[H("x","Where the part's own x axis points"),H("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:r4,section:"Lists and strings",doc:"Number of items in a list, characters in a string or fields in a record"},{name:"keys",kind:"function",params:[H("record","A record, as {name = value}")],section:"Lists and strings",doc:"A record's field names, in the order they were written"},{name:"merge",kind:"function",params:[H("a","A record"),H("b","A record whose fields add to or replace those of a")],section:"Lists and strings",doc:"A record with the fields of a and b, b winning where both have one"},{name:"concat",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Join lists and single values into one list"},{name:"reverse",kind:"function",params:r4,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sum",kind:"function",params:[H("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[H("value","A list or string"),H("start","First index","0"),H("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[H("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[H("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[H("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[H("text"),H("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[H("values"),H("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[H("value"),H("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[H("value","A list or string"),H("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[H("x"),H("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},r3("is_num","a number other than NaN"),r3("is_string","a string"),r3("is_bool","true or false"),r3("is_list","a list"),r3("is_undef","undef"),r3("is_function","a function"),r3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:r4,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"rands",kind:"function",params:[H("min"),H("max"),H("count"),H("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},w7("text_width","The advance width of the text, including spacing"),w7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[H("length","Edge length"),H("finger","Finger width",be)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],v9=new Map(z7.map(t=>[t.name,t])),v5=t=>v9.get(t);function xe(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var y5={"kerf/box":`// kerf/box: finger-jointed boxes.
13
13
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
14
14
 
15
15
  // Box from its outer size [width, depth, height] in the current material.
@@ -101,6 +101,62 @@ module joint_test(kerfs = [0.1, 0.15, 0.2], size = [40, 20], finger = undef, lab
101
101
  }
102
102
  }
103
103
  }
104
+ `,"kerf/cones":`// kerf/cones: cones and cut-off cones cut flat, to roll up from thin sheet.
105
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
106
+ //
107
+ // A cone rolled from paper, card, veneer or thin plastic is a ring sector
108
+ // when flat. Gramophone horns, lampshades, funnels and party hats all start
109
+ // as one. The sector's apex is at the origin and it opens from +x
110
+ // anticlockwise; the glue tab runs along its far edge.
111
+
112
+ // The flat pattern of a cone of radius r1 at one end, r2 at the other and h
113
+ // high: [outer radius, inner radius, angle in degrees, slant length]. A
114
+ // cylinder (r1 == r2) has no apex: it gives [undef, undef, 0, h] and is a
115
+ // rectangle 2 * PI * r1 wide.
116
+ function cone_pattern(r1, r2, h) =
117
+ let (
118
+ big = max(r1, r2),
119
+ small = min(r1, r2),
120
+ s = sqrt(h * h + pow(big - small, 2))
121
+ )
122
+ big == small ? [undef, undef, 0, h]
123
+ : [s * big / (big - small), s * small / (big - small), 360 * (big - small) / s, s];
124
+
125
+ // A cone or cut-off cone cut flat: rolled up so the far edge lies on the
126
+ // glue tab, it has radius r1 at one end, r2 at the other, and is h high.
127
+ // \`tab\` adds a glue tab that wide along the far edge, its fold scored; a
128
+ // cylinder becomes a rectangle with the tab on its right.
129
+ module cone_flat(r1, r2, h, tab = 0, steps = 0) {
130
+ p = cone_pattern(r1, r2, h);
131
+ if (is_undef(p[0])) {
132
+ w = 2 * PI * r1;
133
+ rect([w, h]);
134
+ if (tab > 0) {
135
+ polygon([[w, 0], [w + tab, min(tab, h / 4)], [w + tab, h - min(tab, h / 4)], [w, h]]);
136
+ score() line([w, 0], [w, h]);
137
+ }
138
+ } else {
139
+ a = p[2];
140
+ n = steps > 0 ? steps : max(8, ceil(a / 3));
141
+ arc_pts = function(r) [for (i = [0:n]) [r * cos(a * i / n), r * sin(a * i / n)]];
142
+ polygon(concat(arc_pts(p[0]), p[1] > 0 ? reverse(arc_pts(p[1])) : [[0, 0]]));
143
+ if (tab > 0) {
144
+ // The tab beyond the far edge, its ends cut in so it hides when rolled
145
+ ux = cos(a);
146
+ uy = sin(a);
147
+ nx = -uy;
148
+ ny = ux;
149
+ c = min(tab, p[3] / 4);
150
+ polygon([
151
+ [p[1] * ux, p[1] * uy],
152
+ [p[0] * ux, p[0] * uy],
153
+ [(p[0] - c) * ux + tab * nx, (p[0] - c) * uy + tab * ny],
154
+ [(p[1] + (p[1] > 0 ? c : tab)) * ux + tab * nx, (p[1] + (p[1] > 0 ? c : tab)) * uy + tab * ny],
155
+ ]);
156
+ score() line([p[1] * ux, p[1] * uy], [p[0] * ux, p[0] * uy]);
157
+ }
158
+ }
159
+ }
104
160
  `,"kerf/dividers":`// kerf/dividers: dividers that slot into each other like an egg crate.
105
161
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
106
162
 
@@ -374,6 +430,209 @@ module tappets(n, r, w = 10, hub = 14, bore = 6, square = false) {
374
430
  if (square) rect([bore, bore], center = true); else circle(d = bore);
375
431
  }
376
432
  }
433
+
434
+ // Cams from a lift curve. The follower rides on the cam's top (+y) and
435
+ // moves straight up and down; turned anticlockwise by \`a\` degrees (rotate =
436
+ // [0, 0, a]), the cam lifts it lift(a) above the base circle. \`lift\` is a
437
+ // function of the angle, 0 to 360, that comes back to where it started.
438
+
439
+ // A smooth rise of \`height\` from angle a0 to a1 (cycloidal: it starts and
440
+ // stops gently): 0 before a0, height after a1. Add and take away rises to
441
+ // make dwells, rises and falls: two pecks then a rest is
442
+ // function(a) cam_rise(a, 0, 40, 8) - cam_rise(a, 40, 80, 8) + cam_rise(a, 100, 140, 8) - cam_rise(a, 140, 180, 8).
443
+ function cam_rise(a, a0, a1, height) =
444
+ a <= a0 ? 0
445
+ : a >= a1 ? height
446
+ : let (u = (a - a0) / (a1 - a0)) height * (u - sin(360 * u) / (2 * PI));
447
+
448
+ // The cam's pitch curve: where the follower's tip (or its roller's centre)
449
+ // sits, in the cam's own turn, \`steps\` points round
450
+ function cam_pitch(lift, base_r, roller_d = 0, steps = 180) =
451
+ [for (i = [0:steps - 1])
452
+ let (f = i * 360 / steps, a = (450 - f) % 360, r = base_r + roller_d / 2 + lift(a))
453
+ [r * cos(f), r * sin(f)]];
454
+
455
+ // How high the follower's tip (or its roller's centre) is above the cam's
456
+ // axle when the cam is turned to \`angle\`, to place the follower
457
+ function cam_follower(lift, base_r, angle, roller_d = 0) =
458
+ base_r + roller_d / 2 + lift(((angle % 360) + 360) % 360);
459
+
460
+ // The steepest pressure angle over a turn, in degrees: how hard the cam
461
+ // pushes the follower sideways. Keep it under about 30, by a bigger base
462
+ // circle or a longer rise.
463
+ function cam_pressure(lift, base_r, roller_d = 0, steps = 360) =
464
+ max([for (i = [0:steps - 1])
465
+ let (
466
+ a = i * 360 / steps,
467
+ r = base_r + roller_d / 2 + lift(a),
468
+ slope = (lift((a + 0.5) % 360) - lift((a + 359.5) % 360)) / (PI / 180)
469
+ )
470
+ atan(abs(slope) / r)]);
471
+
472
+ // A cam that lifts a follower lift(a) at angle a, with a hole for its
473
+ // axle. A "knife" follower rides the pitch curve itself; a "roller" one of
474
+ // diameter roller_d rolls on a profile inside it. Check cam_pressure().
475
+ module cam(lift, base_r, follower = "knife", roller_d = 0, bore = 6, steps = 180, square = false) {
476
+ assert(follower == "knife" || follower == "roller", "follower must be \\"knife\\" or \\"roller\\"");
477
+ assert(follower == "knife" || roller_d > 0, "a roller follower needs roller_d");
478
+ difference() {
479
+ if (follower == "roller") offset(r = -roller_d / 2) polygon(cam_pitch(lift, base_r, roller_d, steps));
480
+ else polygon(cam_pitch(lift, base_r, 0, steps));
481
+ if (square) rect([bore, bore], center = true); else circle(d = bore);
482
+ }
483
+ }
484
+
485
+ // A Geneva drive: a driver turning all the time steps a wheel of \`slots\`
486
+ // slots on by one slot each turn, and locks it between steps. The driver's
487
+ // axle is at the origin and the wheel's at [distance, 0]. Cut the wheel and
488
+ // the locking disc from the same sheet, side by side in one plane, and the
489
+ // crank above them; a dowel pin of pin_d through the crank's outer hole
490
+ // runs in the wheel's slots.
491
+
492
+ // The radius of the circle the driver's pin turns on
493
+ function geneva_pin_radius(slots, distance) = distance * sin(180 / slots);
494
+ // The wheel's outer radius
495
+ function geneva_wheel_radius(slots, distance, pin_d) =
496
+ sqrt(pow(distance * cos(180 / slots), 2) + pow(pin_d / 2, 2));
497
+ // The locking disc's radius
498
+ function geneva_lock_radius(slots, distance, pin_d) = geneva_pin_radius(slots, distance) - pin_d;
499
+
500
+ // How far the wheel has turned when the driver has turned \`angle\`
501
+ // anticlockwise from its pin pointing at the wheel: it turns clockwise,
502
+ // 360 / slots each turn of the driver, and stands still between steps
503
+ function geneva_turn(slots, distance, angle) =
504
+ let (
505
+ k = floor((angle + 180) / 360),
506
+ t = angle - 360 * k,
507
+ rc = geneva_pin_radius(slots, distance),
508
+ on = 90 - 180 / slots,
509
+ step = abs(t) <= on ? atan2(-rc * sin(t), distance - rc * cos(t))
510
+ : t < 0 ? 180 / slots : -180 / slots
511
+ )
512
+ step - k * 360 / slots;
513
+
514
+ // The wheel, centred on the origin, a slot along -x (towards the driver
515
+ // when geneva_turn() is 0)
516
+ module geneva_wheel(slots, distance, pin_d = 6, bore = 6, clearance = 0.2, square = false) {
517
+ rc = geneva_pin_radius(slots, distance);
518
+ ro = geneva_wheel_radius(slots, distance, pin_d);
519
+ rl = geneva_lock_radius(slots, distance, pin_d);
520
+ w = pin_d + clearance;
521
+ inner = distance - rc - clearance;
522
+ assert(rl > 0, "the pin is too thick to leave a locking disc: make the distance longer or the pin thinner");
523
+ assert(inner - w / 2 > bore / 2 + 3, "the slots reach the axle: use more slots, a longer distance or a smaller bore");
524
+ difference() {
525
+ circle(r = ro);
526
+ for (j = [0:slots - 1]) rotate(180 + j * 360 / slots) {
527
+ hull() {
528
+ translate([inner, 0]) circle(d = w);
529
+ translate([ro + 1, -w / 2]) rect([1, w]);
530
+ }
531
+ // The locking arc between this slot and the next
532
+ rotate(180 / slots) translate([distance, 0]) circle(r = rl + clearance);
533
+ }
534
+ if (square) rect([bore, bore], center = true); else circle(d = bore);
535
+ }
536
+ }
537
+
538
+ // The locking disc that turns with the driver, its relief facing the pin's
539
+ // side (+x): cut away wherever the wheel's rim passes while the pin is in a
540
+ // slot, so the wheel turns then
541
+ module geneva_lock(slots, distance, pin_d = 6, bore = 6, clearance = 0.2, square = false) {
542
+ assert(geneva_lock_radius(slots, distance, pin_d) > bore / 2 + 3, "the locking disc is too small for its axle: make the distance longer, the pin thinner or the bore smaller");
543
+ ro = geneva_wheel_radius(slots, distance, pin_d);
544
+ assert(distance - ro - clearance >= bore / 2 + 2, str("the wheel passes within ", round(10 * (distance - ro - clearance)) / 10, " mm of the driver's axle: use a bore of at most ", floor(20 * (distance - ro - clearance - 2)) / 10, " mm or fewer slots"));
545
+ difference() {
546
+ circle(r = geneva_lock_radius(slots, distance, pin_d));
547
+ // Everywhere the wheel's rim passes while the pin is in a slot
548
+ on = 90 - 180 / slots;
549
+ n = max(2, ceil(2 * on / 3));
550
+ for (i = [0:n - 1]) hull() for (t = [-on + 2 * on * i / n, -on + 2 * on * (i + 1) / n])
551
+ translate([distance * cos(t), distance * sin(t)]) circle(r = ro + clearance);
552
+ if (square) rect([bore, bore], center = true); else circle(d = bore);
553
+ }
554
+ }
555
+
556
+ // The crank above the locking disc that carries the pin, along +x
557
+ module geneva_crank(slots, distance, pin_d = 6, bore = 6, width = 0, square = false) {
558
+ rc = geneva_pin_radius(slots, distance);
559
+ w = width > 0 ? width : max(pin_d, bore) + 8;
560
+ difference() {
561
+ hull() {
562
+ circle(d = w);
563
+ translate([rc, 0]) circle(d = pin_d + 8);
564
+ }
565
+ translate([rc, 0]) circle(d = pin_d);
566
+ if (square) rect([bore, bore], center = true); else circle(d = bore);
567
+ }
568
+ }
569
+
570
+ // A ratchet wheel of \`teeth\` teeth, radius r at their tips, \`depth\` deep,
571
+ // centred on the origin with a hole for its axle. It turns anticlockwise
572
+ // freely; a pawl() stops it turning back.
573
+ module ratchet(teeth, r, depth, bore = 6, square = false) {
574
+ p = 360 / teeth;
575
+ difference() {
576
+ polygon([for (k = [0:teeth - 1], j = [0, 1])
577
+ j == 0 ? [r * cos(k * p), r * sin(k * p)]
578
+ : [(r - depth) * cos((k + 1) * p), (r - depth) * sin((k + 1) * p)]]);
579
+ if (square) rect([bore, bore], center = true); else circle(d = bore);
580
+ }
581
+ }
582
+
583
+ // The angle of the tooth face a pawl rests on, nearest \`at\` degrees
584
+ function pawl_face(teeth, at = 90) = round(at / (360 / teeth)) * 360 / teeth;
585
+
586
+ // How far the pawl leans out from the wheel's edge, in degrees: past the
587
+ // teeth's slope, so it clears them
588
+ function pawl_lean(teeth, r, depth) = atan(depth / ((r - depth / 2) * 2 * PI / teeth)) + 15;
589
+
590
+ // The shortest pawl of this width that clears the teeth: its tip edge,
591
+ // along the tooth face, must end before its far end does
592
+ function pawl_min_length(teeth, r, depth, width = 8) =
593
+ width * (0.5 + tan(pawl_lean(teeth, r, depth))) + 2;
594
+
595
+ // The pawl's outline round the wheel's centre: its tip on the root by the
596
+ // tooth face, its far end, and back along the face. Its pivot is the
597
+ // middle of its far end. A length of 0 picks 0.8 * r, or longer if the
598
+ // pawl must be to clear the teeth; pawl() refuses a length given shorter
599
+ // than pawl_min_length().
600
+ function pawl_points(teeth, r, depth, length = 0, width = 8, at = 90, clearance = 0.2) =
601
+ let (
602
+ f = pawl_face(teeth, at),
603
+ g = pawl_lean(teeth, r, depth),
604
+ shortest = pawl_min_length(teeth, r, depth, width),
605
+ L = length > 0 ? length : max(r * 0.8, shortest),
606
+ n = [cos(f), sin(f)],
607
+ tc = [sin(f), -cos(f)],
608
+ u = cos(g) * tc + sin(g) * n,
609
+ v = cos(g) * n - sin(g) * tc,
610
+ T = (r - depth + clearance) * n + clearance * tc
611
+ )
612
+ [T, T + (L - width / 2) * u, T + (L - width / 2) * u + width * v, T + width / cos(g) * n];
613
+
614
+ // Where a pawl()'s pivot is, round the wheel's centre
615
+ function pawl_pivot(teeth, r, depth, length = 0, width = 8, at = 90, clearance = 0.2) =
616
+ let (p = pawl_points(teeth, r, depth, length, width, at, clearance)) (p[1] + p[2]) / 2;
617
+
618
+ // A pawl for a ratchet() of the same sizes, drawn where it works round
619
+ // the wheel's centre: give it the wheel's placement. Its tip rests against
620
+ // the tooth face nearest \`at\` degrees, and it turns on a pin through the
621
+ // hole at pawl_pivot(). Gravity, a rubber band or a spring wire holds it
622
+ // down on the teeth.
623
+ module pawl(teeth, r, depth, length = 0, width = 8, bore = 3, at = 90, clearance = 0.2) {
624
+ shortest = pawl_min_length(teeth, r, depth, width);
625
+ assert(length == 0 || length >= shortest, str("a pawl ", width, " mm wide must be at least ", ceil(2 * shortest) / 2, " mm long to clear the teeth: make it longer or narrower"));
626
+ p = pawl_points(teeth, r, depth, length, width, at, clearance);
627
+ H = (p[1] + p[2]) / 2;
628
+ difference() {
629
+ union() {
630
+ polygon(p);
631
+ translate(H) circle(d = width);
632
+ }
633
+ translate(H) circle(d = bore);
634
+ }
635
+ }
377
636
  `,"kerf/geo":`// kerf/geo: the world's land, for maps, globes and country-shaped pieces.
378
637
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
379
638
  // The land data is Natural Earth's 1:110m land (public domain,
@@ -1004,6 +1263,60 @@ module halved_pair(name, at = [0, 0, 0], cap = undef, feet = [], side_feet = und
1004
1263
  }
1005
1264
  }
1006
1265
  }
1266
+ `,"kerf/linkage":`// kerf/linkage: where the joints of a linkage are at a crank angle.
1267
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1268
+ //
1269
+ // Each function gives the joint points of a linkage drawn flat, so a part
1270
+ // placed on a link and the link's length come from the same numbers. Use
1271
+ // them to place moving parts at a drive angle, and to check a linkage closes
1272
+ // over a whole turn.
1273
+
1274
+ // Where a circle of radius ra round a meets one of radius rb round b: the
1275
+ // point left of the line from a to b (side = 1) or right of it (side = -1).
1276
+ // undef when the circles don't meet: the links are too short or too long.
1277
+ function circle_meet(a, ra, b, rb, side = 1) =
1278
+ let (
1279
+ dx = b[0] - a[0],
1280
+ dy = b[1] - a[1],
1281
+ d = sqrt(dx * dx + dy * dy),
1282
+ along = d > 0 ? (ra * ra - rb * rb + d * d) / (2 * d) : 0,
1283
+ h2 = ra * ra - along * along
1284
+ )
1285
+ d == 0 || h2 < -1e-9 ? undef
1286
+ : let (h = sqrt(max(0, h2)), ux = dx / d, uy = dy / d)
1287
+ [a[0] + along * ux - side * h * uy, a[1] + along * uy + side * h * ux];
1288
+
1289
+ // A crank of radius r turning round the origin drives a slider along the
1290
+ // line y = offset through a connecting rod of length l. At the crank's
1291
+ // angle it gives [crank pin, slider pin]; undef if the rod can't reach.
1292
+ function slider_crank(r, l, angle, offset = 0) =
1293
+ let (
1294
+ pin = [r * cos(angle), r * sin(angle)],
1295
+ dy = offset - pin[1]
1296
+ )
1297
+ abs(dy) > l ? undef : [pin, [pin[0] + sqrt(l * l - dy * dy), offset]];
1298
+
1299
+ // How far the slider of slider_crank() travels from end to end
1300
+ function slider_stroke(r, l, offset = 0) =
1301
+ sqrt(pow(l + r, 2) - offset * offset) - sqrt(pow(l - r, 2) - offset * offset);
1302
+
1303
+ // A four-bar linkage: the crank turns round the origin, the rocker round
1304
+ // [ground, 0], and the coupler joins their ends. At the crank's angle it
1305
+ // gives [crank end, rocker end], the rocker end on the side \`side\` of the
1306
+ // line from the crank end to the rocker's pivot; undef where the links
1307
+ // can't close.
1308
+ function four_bar(ground, crank, coupler, rocker, angle, side = 1) =
1309
+ let (b = [crank * cos(angle), crank * sin(angle)], c = circle_meet(b, coupler, [ground, 0], rocker, side))
1310
+ is_undef(c) ? undef : [b, c];
1311
+
1312
+ // True when the crank of a four-bar linkage turns all the way round
1313
+ // (Grashof's rule, with the crank the shortest link)
1314
+ function four_bar_turns(ground, crank, coupler, rocker) =
1315
+ let (s = min(ground, crank, coupler, rocker), l = max(ground, crank, coupler, rocker))
1316
+ crank == s && s + l <= ground + crank + coupler + rocker - s - l;
1317
+
1318
+ // The angle in degrees of the line from a to b, from +x
1319
+ function link_angle(a, b) = atan2(b[1] - a[1], b[0] - a[0]);
1007
1320
  `,"kerf/lock":`// kerf/lock: a lock with a key, for boxes, diaries, chests and money boxes.
1008
1321
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1009
1322
  //
@@ -1188,11 +1501,20 @@ function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
1188
1501
  is_undef(s) ? assert(false, str("Unknown card size \\"", name, "\\". Known: ", size_names(CARD_SIZES))) : s;
1189
1502
 
1190
1503
  // Photo print sizes as [width, height], landscape: "4x6", "5x7", "8x10",
1191
- // "10x15" (cm), "13x18" (cm), "instax mini", "instax square", "instax wide",
1192
- // "polaroid".
1193
- function photo_size(name) = let (s = lookup_size(name, PHOTO_SIZES))
1504
+ // "10x15" (cm), "13x18" (cm), and instant film: "instant mini", "instant
1505
+ // square", "instant wide" and "instant classic".
1506
+ function photo_size(name) = let (s = lookup_size(lookup_alias(name, PHOTO_ALIASES), PHOTO_SIZES))
1194
1507
  is_undef(s) ? assert(false, str("Unknown photo size \\"", name, "\\". Known: ", size_names(PHOTO_SIZES))) : s;
1195
1508
 
1509
+ // A bought part's sizes by name, as a record: \`body\` [width, depth,
1510
+ // height], and for parts with one, the \`shaft\` diameter, the \`shaft_length\`
1511
+ // it stands out of the body and the \`hole\` to cut for it. Retail sizes vary:
1512
+ // measure yours. "music-18" (an 18-note wind-up music box movement, shaft
1513
+ // the winding key's), "quartz-clock" (a 56 mm quartz clock movement with
1514
+ // the 16.5 mm shaft for dials up to 8 mm thick), "marble-16" and "marble-25".
1515
+ function part_size(name) = let (s = lookup_size(name, PART_SIZES))
1516
+ is_undef(s) ? assert(false, str("Unknown part \\"", name, "\\". Known: ", size_names(PART_SIZES))) : s;
1517
+
1196
1518
  // A size turned to lie wider than tall
1197
1519
  function landscape(size) = size[0] >= size[1] ? size : [size[1], size[0]];
1198
1520
  // A size turned to stand taller than wide
@@ -1214,13 +1536,28 @@ CARD_SIZES = [
1214
1536
  ];
1215
1537
  PHOTO_SIZES = [
1216
1538
  ["4x6", [152.4, 101.6]], ["5x7", [177.8, 127]], ["8x10", [254, 203.2]],
1217
- ["10x15", [150, 100]], ["13x18", [180, 130]], ["instax mini", [54, 86]],
1218
- ["instax square", [72, 86]], ["instax wide", [108, 86]], ["polaroid", [88, 107]]
1539
+ ["10x15", [150, 100]], ["13x18", [180, 130]], ["instant mini", [54, 86]],
1540
+ ["instant square", [72, 86]], ["instant wide", [108, 86]], ["instant classic", [88, 107]]
1541
+ ];
1542
+ // Older names that still work, left out of the list of known names
1543
+ PHOTO_ALIASES = [
1544
+ ["instax mini", "instant mini"], ["instax square", "instant square"],
1545
+ ["instax wide", "instant wide"], ["polaroid", "instant classic"]
1546
+ ];
1547
+ PART_SIZES = [
1548
+ ["music-18", {body = [50, 44, 20], shaft = 3.5, hole = 6}],
1549
+ ["quartz-clock", {body = [56, 56, 16], shaft = 7.6, shaft_length = 16.5, hole = 8, dial = 8}],
1550
+ ["marble-16", {body = [16, 16, 16]}],
1551
+ ["marble-25", {body = [25, 25, 25]}]
1219
1552
  ];
1220
1553
 
1221
1554
  // The size of that name in a table of [name, size], ignoring case
1222
1555
  function lookup_size(name, table) = let (k = lower(name), hit = [for (e = table) if (lower(e[0]) == k) e[1]])
1223
1556
  len(hit) ? hit[0] : undef;
1557
+ // The name an older name stands for in a table of [old, new], or the name
1558
+ // itself
1559
+ function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = aliases) if (lower(e[0]) == k) e[1]])
1560
+ len(hit) ? hit[0] : name;
1224
1561
  // The names in a table, for messages
1225
1562
  function size_names(table) = join([for (e = table) e[0]], ", ");
1226
1563
  `,"kerf/symbols":`// kerf/symbols: 867 pictograms by name, for engraving and cutting.
@@ -2223,27 +2560,27 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
2223
2560
  if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
2224
2561
  if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
2225
2562
  }
2226
- `};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},c=Object.defineProperty,r=c(n,n,n)&&c}catch{}return r})(),e=function(n){if(this==null)throw TypeError();var c=String(this),r=c.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=r)){var s=c.charCodeAt(a),i;return s>=55296&&s<=56319&&r>a+1&&(i=c.charCodeAt(a+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var $6=0,o8=-3;function b5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function gn(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new b5,this.dtree=new b5}var l8=new b5,h8=new b5,D6=new Uint8Array(30),q6=new Uint16Array(30),u8=new Uint8Array(30),f8=new Uint16Array(30),vn=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),z7=new b5,v2=new Uint8Array(320);function d8(t,e,n,c){var r,a;for(r=0;r<n;++r)t[r]=0;for(r=0;r<30-n;++r)t[r+n]=r/n|0;for(a=c,r=0;r<30;++r)e[r]=a,a+=1<<t[r]}function yn(t,e){var n;for(n=0;n<7;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;n<24;++n)t.trans[n]=256+n;for(n=0;n<144;++n)t.trans[24+n]=n;for(n=0;n<8;++n)t.trans[168+n]=280+n;for(n=0;n<112;++n)t.trans[176+n]=144+n;for(n=0;n<5;++n)e.table[n]=0;for(e.table[5]=32,n=0;n<32;++n)e.trans[n]=n}var k7=new Uint16Array(16);function x6(t,e,n,c){var r,a;for(r=0;r<16;++r)t.table[r]=0;for(r=0;r<c;++r)t.table[e[n+r]]++;for(t.table[0]=0,a=0,r=0;r<16;++r)k7[r]=a,a+=t.table[r];for(r=0;r<c;++r)e[n+r]&&(t.trans[k7[e[n+r]]++]=r)}function bn(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function y2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var c=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,c+n}function P6(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,c=0,r=0,a=t.tag;do c=2*c+(a&1),a>>>=1,++r,n+=e.table[r],c-=e.table[r];while(c>=0);return t.tag=a,t.bitcount-=r,e.trans[n+c]}function xn(t,e,n){var c,r,a,s,i,o;for(c=y2(t,5,257),r=y2(t,5,1),a=y2(t,4,4),s=0;s<19;++s)v2[s]=0;for(s=0;s<a;++s){var l=y2(t,3,0);v2[vn[s]]=l}for(x6(z7,v2,0,19),i=0;i<c+r;){var h=P6(t,z7);switch(h){case 16:var u=v2[i-1];for(o=y2(t,2,3);o;--o)v2[i++]=u;break;case 17:for(o=y2(t,3,3);o;--o)v2[i++]=0;break;case 18:for(o=y2(t,7,11);o;--o)v2[i++]=0;break;default:v2[i++]=h;break}}x6(e,v2,0,c),x6(n,v2,c,r)}function S7(t,e,n){for(;;){var c=P6(t,e);if(c===256)return $6;if(c<256)t.dest[t.destLen++]=c;else{var r,a,s,i;for(c-=257,r=y2(t,D6[c],q6[c]),a=P6(t,n),s=t.destLen-y2(t,u8[a],f8[a]),i=s;i<s+r;++i)t.dest[t.destLen++]=t.dest[i]}}}function Mn(t){for(var e,n,c;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return o8;for(t.sourceIndex+=4,c=e;c;--c)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,$6}function wn(t,e){var n=new gn(t,e),c,r,a;do{switch(c=bn(n),r=y2(n,2,0),r){case 0:a=Mn(n);break;case 1:a=S7(n,l8,h8);break;case 2:xn(n,n.ltree,n.dtree),a=S7(n,n.ltree,n.dtree);break;default:a=o8}if(a!==$6)throw new Error("Data error")}while(!c);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}yn(l8,h8);d8(D6,q6,4,3);d8(u8,f8,2,1);D6[28]=0;q6[28]=258;var zn=wn;function V3(t,e,n,c,r){return Math.pow(1-r,3)*t+3*Math.pow(1-r,2)*r*e+3*(1-r)*Math.pow(r,2)*n+Math.pow(r,3)*c}function X2(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}X2.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};X2.prototype.addPoint=function(t,e){typeof t=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};X2.prototype.addX=function(t){this.addPoint(t,null)};X2.prototype.addY=function(t){this.addPoint(null,t)};X2.prototype.addBezier=function(t,e,n,c,r,a,s,i){var o=[t,e],l=[n,c],h=[r,a],u=[s,i];this.addPoint(t,e),this.addPoint(s,i);for(var f=0;f<=1;f++){var d=6*o[f]-12*l[f]+6*h[f],m=-3*o[f]+9*l[f]-9*h[f]+3*u[f],p=3*l[f]-3*o[f];if(m===0){if(d===0)continue;var g=-p/d;0<g&&g<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],g)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*p*m;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*m);0<y&&y<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],y)));var b=(-d-Math.sqrt(v))/(2*m);0<b&&b<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],b)))}}};X2.prototype.addQuad=function(t,e,n,c,r,a){var s=t+.6666666666666666*(n-t),i=e+2/3*(c-e),o=s+1/3*(r-t),l=i+1/3*(a-e);this.addBezier(t,e,s,i,o,l,r,a)};function x0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}x0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};x0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};x0.prototype.curveTo=x0.prototype.bezierCurveTo=function(t,e,n,c,r,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:c,x:r,y:a})};x0.prototype.quadTo=x0.prototype.quadraticCurveTo=function(t,e,n,c){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:c})};x0.prototype.close=x0.prototype.closePath=function(){this.commands.push({type:"Z"})};x0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof X2){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};x0.prototype.getBoundingBox=function(){for(var t=new X2,e=0,n=0,c=0,r=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=c=s.x,n=r=s.y;break;case"L":t.addPoint(s.x,s.y),c=s.x,r=s.y;break;case"Q":t.addQuad(c,r,s.x1,s.y1,s.x,s.y),c=s.x,r=s.y;break;case"C":t.addBezier(c,r,s.x1,s.y1,s.x2,s.y2,s.x,s.y),c=s.x,r=s.y;break;case"Z":c=e,r=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};x0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};x0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var c="",r=0;r<this.commands.length;r+=1){var a=this.commands[r];a.type==="M"?c+="M"+n(a.x,a.y):a.type==="L"?c+="L"+n(a.x,a.y):a.type==="C"?c+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?c+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(c+="Z")}return c};x0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};x0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function m8(t){throw new Error(t)}function L7(t,e){t||m8(e)}var z1={fail:m8,argument:L7,assert:L7},A7=32768,C7=2147483648,O3={},J={},C1={};function o2(t){return function(){return t}}J.BYTE=function(t){return z1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};C1.BYTE=o2(1);J.CHAR=function(t){return[t.charCodeAt(0)]};C1.CHAR=o2(1);J.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};C1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};J.USHORT=function(t){return[t>>8&255,t&255]};C1.USHORT=o2(2);J.SHORT=function(t){return t>=A7&&(t=-(2*A7-t)),[t>>8&255,t&255]};C1.SHORT=o2(2);J.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};C1.UINT24=o2(3);J.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.ULONG=o2(4);J.LONG=function(t){return t>=C7&&(t=-(2*C7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONG=o2(4);J.FIXED=J.ULONG;C1.FIXED=C1.ULONG;J.FWORD=J.SHORT;C1.FWORD=C1.SHORT;J.UFWORD=J.USHORT;C1.UFWORD=C1.USHORT;J.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONGDATETIME=o2(8);J.TAG=function(t){return z1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};C1.TAG=o2(4);J.Card8=J.BYTE;C1.Card8=C1.BYTE;J.Card16=J.USHORT;C1.Card16=C1.USHORT;J.OffSize=J.BYTE;C1.OffSize=C1.BYTE;J.SID=J.USHORT;C1.SID=C1.USHORT;J.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?J.NUMBER16(t):J.NUMBER32(t)};C1.NUMBER=function(t){return J.NUMBER(t).length};J.NUMBER16=function(t){return[28,t>>8&255,t&255]};C1.NUMBER16=o2(3);J.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.NUMBER32=o2(5);J.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var c=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*c)/c).toString()}for(var r="",a=0,s=e.length;a<s;a+=1){var i=e[a];i==="e"?r+=e[++a]==="-"?"c":"b":i==="."?r+="a":i==="-"?r+="e":r+=i}r+=r.length&1?"f":"ff";for(var o=[30],l=0,h=r.length;l<h;l+=2)o.push(parseInt(r.substr(l,2),16));return o};C1.REAL=function(t){return J.REAL(t).length};J.NAME=J.CHARARRAY;C1.NAME=C1.CHARARRAY;J.STRING=J.CHARARRAY;C1.STRING=C1.CHARARRAY;O3.UTF8=function(t,e,n){for(var c=[],r=n,a=0;a<r;a++,e+=1)c[a]=t.getUint8(e);return String.fromCharCode.apply(null,c)};O3.UTF16=function(t,e,n){for(var c=[],r=n/2,a=0;a<r;a++,e+=2)c[a]=t.getUint16(e);return String.fromCharCode.apply(null,c)};J.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var c=t.charCodeAt(n);e[e.length]=c>>8&255,e[e.length]=c&255}return e};C1.UTF16=function(t){return t.length*2};var E6={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};O3.MACSTRING=function(t,e,n,c){var r=E6[c];if(r!==void 0){for(var a="",s=0;s<n;s++){var i=t.getUint8(e+s);i<=127?a+=String.fromCharCode(i):a+=r[i&127]}return a}};var c4=typeof WeakMap=="function"&&new WeakMap,r4,kn=function(t){if(!r4){r4={};for(var e in E6)r4[e]=new String(e)}var n=r4[t];if(n!==void 0){if(c4){var c=c4.get(n);if(c!==void 0)return c}var r=E6[t];if(r!==void 0){for(var a={},s=0;s<r.length;s++)a[r.charCodeAt(s)]=s+128;return c4&&c4.set(n,a),a}}};J.MACSTRING=function(t,e){var n=kn(e);if(n!==void 0){for(var c=[],r=0;r<t.length;r++){var a=t.charCodeAt(r);if(a>=128&&(a=n[a],a===void 0))return;c[r]=a}return c}};C1.MACSTRING=function(t,e){var n=J.MACSTRING(t,e);return n!==void 0?n.length:0};function T6(t){return t>=-128&&t<=127}function Sn(t,e,n){for(var c=0,r=t.length;e<r&&c<64&&t[e]===0;)++e,++c;return n.push(128|c-1),e}function Ln(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(!T6(s)||s===0&&a+1<r&&t[a+1]===0)break;++a,++c}n.push(c-1);for(var i=e;i<a;++i)n.push(t[i]+256&255);return a}function An(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(s===0||T6(s)&&a+1<r&&T6(t[a+1]))break;++a,++c}n.push(64|c-1);for(var i=e;i<a;++i){var o=t[i];n.push(o+65536>>8&255,o+256&255)}return a}J.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var c=t[e];c===0?e=Sn(t,e,n):c>=-128&&c<=127?e=Ln(t,e,n):e=An(t,e,n)}return n};J.INDEX=function(t){for(var e=1,n=[e],c=[],r=0;r<t.length;r+=1){var a=J.OBJECT(t[r]);Array.prototype.push.apply(c,a),e+=a.length,n.push(e)}if(c.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,J.BYTE,J.USHORT,J.UINT24,J.ULONG][i],l=0;l<n.length;l+=1){var h=o(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(J.Card16(t.length),J.OffSize(i),s,c)};C1.INDEX=function(t){return J.INDEX(t).length};J.DICT=function(t){for(var e=[],n=Object.keys(t),c=n.length,r=0;r<c;r+=1){var a=parseInt(n[r],0),s=t[a];e=e.concat(J.OPERAND(s.value,s.type)),e=e.concat(J.OPERATOR(a))}return e};C1.DICT=function(t){return J.DICT(t).length};J.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};J.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)z1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(J.OPERAND(t[c],e[c]));else if(e==="SID")n=n.concat(J.NUMBER(t));else if(e==="offset")n=n.concat(J.NUMBER32(t));else if(e==="number")n=n.concat(J.NUMBER(t));else if(e==="real")n=n.concat(J.REAL(t));else throw new Error("Unknown operand type "+e);return n};J.OP=J.BYTE;C1.OP=C1.BYTE;var a4=typeof WeakMap=="function"&&new WeakMap;J.CHARSTRING=function(t){if(a4){var e=a4.get(t);if(e!==void 0)return e}for(var n=[],c=t.length,r=0;r<c;r+=1){var a=t[r];n=n.concat(J[a.type](a.value))}return a4&&a4.set(t,n),n};C1.CHARSTRING=function(t){return J.CHARSTRING(t).length};J.OBJECT=function(t){var e=J[t.type];return z1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};C1.OBJECT=function(t){var e=C1[t.type];return z1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};J.TABLE=function(t){for(var e=[],n=t.fields.length,c=[],r=[],a=0;a<n;a+=1){var s=t.fields[a],i=J[s.type];z1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=t[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(r.push(e.length),e=e.concat([0,0]),c.push(l)):e=e.concat(l)}for(var h=0;h<c.length;h+=1){var u=r[h],f=e.length;z1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(c[h])}return e};C1.TABLE=function(t){for(var e=0,n=t.fields.length,c=0;c<n;c+=1){var r=t.fields[c],a=C1[r.type];z1.argument(a!==void 0,"No sizeOf function for field type "+r.type+" ("+r.name+")");var s=t[r.name];s===void 0&&(s=r.value),e+=a(s),r.type==="TABLE"&&(e+=2)}return e};J.RECORD=J.TABLE;C1.RECORD=C1.TABLE;J.LITERAL=function(t){return t};C1.LITERAL=function(t){return t.length};function P0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var c=0;c<e.length;c+=1){var r=e[c];this[r.name]=r.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var i=a[s],o=n[i];this[i]!==void 0&&(this[i]=o)}}P0.prototype.encode=function(){return J.TABLE(this)};P0.prototype.sizeOf=function(){return C1.TABLE(this)};function x5(t,e,n){n===void 0&&(n=e.length);var c=new Array(e.length+1);c[0]={name:t+"Count",type:"USHORT",value:n};for(var r=0;r<e.length;r++)c[r+1]={name:t+r,type:"USHORT",value:e[r]};return c}function I6(t,e,n){var c=e.length,r=new Array(c+1);r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return r}function M5(t,e,n){var c=e.length,r=[];r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r=r.concat(n(e[a],a));return r}function h4(t){t.format===1?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(x5("glyph",t.glyphs))):t.format===2?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(M5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):z1.assert(!1,"Coverage format must be 1 or 2.")}h4.prototype=Object.create(P0.prototype);h4.prototype.constructor=h4;function u4(t){P0.call(this,"scriptListTable",M5("scriptRecord",t,function(e,n){var c=e.script,r=c.defaultLangSys;return z1.assert(!!r,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new P0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new P0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:r.reqFeatureIndex}].concat(x5("featureIndex",r.featureIndexes)))}].concat(M5("langSys",c.langSysRecords,function(a,s){var i=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new P0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(x5("featureIndex",i.featureIndexes)))}]})))}]}))}u4.prototype=Object.create(P0.prototype);u4.prototype.constructor=u4;function f4(t){P0.call(this,"featureListTable",M5("featureRecord",t,function(e,n){var c=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new P0("featureTable",[{name:"featureParams",type:"USHORT",value:c.featureParams}].concat(x5("lookupListIndex",c.lookupListIndexes)))}]}))}f4.prototype=Object.create(P0.prototype);f4.prototype.constructor=f4;function d4(t,e){P0.call(this,"lookupListTable",I6("lookup",t,function(n){var c=e[n.lookupType];return z1.assert(!!c,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new P0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(I6("subtable",n.subtables,c)))}))}d4.prototype=Object.create(P0.prototype);d4.prototype.constructor=d4;var n1={Table:P0,Record:P0,Coverage:h4,ScriptList:u4,FeatureList:f4,LookupList:d4,ushortList:x5,tableList:I6,recordList:M5};function P7(t,e){return t.getUint8(e)}function m4(t,e){return t.getUint16(e,!1)}function Cn(t,e){return t.getInt16(e,!1)}function N6(t,e){return t.getUint32(e,!1)}function p8(t,e){var n=t.getInt16(e,!1),c=t.getUint16(e+2,!1);return n+c/65535}function Pn(t,e){for(var n="",c=e;c<e+4;c+=1)n+=String.fromCharCode(t.getInt8(c));return n}function En(t,e,n){for(var c=0,r=0;r<n;r+=1)c<<=8,c+=t.getUint8(e+r);return c}function Tn(t,e,n){for(var c=[],r=e;r<n;r+=1)c.push(t.getUint8(r));return c}function In(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var Vn={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function H(t,e){this.data=t,this.offset=e,this.relativeOffset=0}H.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};H.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};H.prototype.parseCard8=H.prototype.parseByte;H.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};H.prototype.parseCard16=H.prototype.parseUShort;H.prototype.parseSID=H.prototype.parseUShort;H.prototype.parseOffset16=H.prototype.parseUShort;H.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};H.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};H.prototype.parseULong=function(){var t=N6(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};H.prototype.parseOffset32=H.prototype.parseULong;H.prototype.parseFixed=function(){var t=p8(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};H.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,c="";this.relativeOffset+=t;for(var r=0;r<t;r++)c+=String.fromCharCode(e.getUint8(n+r));return c};H.prototype.parseTag=function(){return this.parseString(4)};H.prototype.parseLongDateTime=function(){var t=N6(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};H.prototype.parseVersion=function(t){var e=m4(this.data,this.offset+this.relativeOffset),n=m4(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};H.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=Vn[t]*e};H.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint32(c),c+=4;return this.relativeOffset+=t*4,e};H.prototype.parseOffset16List=H.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint16(c),c+=2;return this.relativeOffset+=t*2,e};H.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getInt16(c),c+=2;return this.relativeOffset+=t*2,e};H.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint8(c++);return this.relativeOffset+=t,e};H.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};H.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};H.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};H.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};H.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},c=0;c<e.length;c++){var r=e[c],a=t[r];n[r]=a.call(this)}return n};H.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};H.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),c=0;c<e;c++)n[c]=this.parseValueRecord(t);return n};H.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new H(this.data,this.offset+e).parseStruct(t)};H.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new H(this.data,this.offset+e).parseStruct(t)};H.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,c=this.relativeOffset,r=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){r[a]=void 0;continue}if(this.relativeOffset=s,t){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=t.call(this);r[a]=o}else r[a]=this.parseUShortList()}return this.relativeOffset=c,r};H.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var c=new Array(n),r=0;r<n;r++)c[r]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:c}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};H.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:H.uShort,end:H.uShort,classId:H.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};H.list=function(t,e){return function(){return this.parseList(t,e)}};H.list32=function(t,e){return function(){return this.parseList32(t,e)}};H.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};H.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};H.pointer=function(t){return function(){return this.parsePointer(t)}};H.pointer32=function(t){return function(){return this.parsePointer32(t)}};H.tag=H.prototype.parseTag;H.byte=H.prototype.parseByte;H.uShort=H.offset16=H.prototype.parseUShort;H.uShortList=H.prototype.parseUShortList;H.uLong=H.offset32=H.prototype.parseULong;H.uLongList=H.prototype.parseULongList;H.struct=H.prototype.parseStruct;H.coverage=H.prototype.parseCoverage;H.classDef=H.prototype.parseClassDef;var E7={reserved:H.uShort,reqFeatureIndex:H.uShort,featureIndexes:H.uShortList};H.prototype.parseScriptList=function(){return this.parsePointer(H.recordList({tag:H.tag,script:H.pointer({defaultLangSys:H.pointer(E7),langSysRecords:H.recordList({tag:H.tag,langSys:H.pointer(E7)})})}))||[]};H.prototype.parseFeatureList=function(){return this.parsePointer(H.recordList({tag:H.tag,feature:H.pointer({featureParams:H.offset16,lookupListIndexes:H.uShortList})}))||[]};H.prototype.parseLookupList=function(t){return this.parsePointer(H.list(H.pointer(function(){var e=this.parseUShort();z1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),c=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(H.pointer(t[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};H.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();z1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:H.offset32,featureTableSubstitutionOffset:H.offset32});return n})||[]};var f1={getByte:P7,getCard8:P7,getUShort:m4,getCard16:m4,getShort:Cn,getULong:N6,getFixed:p8,getTag:Pn,getOffset:En,getBytes:Tn,bytesToString:In,Parser:H};function Hn(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var c=0;c<n;c+=1)for(var r=e.parseULong(),a=e.parseULong(),s=e.parseULong(),i=r;i<=a;i+=1)t.glyphIndexMap[i]=s,s++}function On(t,e,n,c,r){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new f1.Parser(n,c+r+14),i=new f1.Parser(n,c+r+16+a*2),o=new f1.Parser(n,c+r+16+a*4),l=new f1.Parser(n,c+r+16+a*6),h=c+r+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),m=i.parseUShort(),p=o.parseShort(),g=l.parseUShort(),v=m;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-m)*2,f=f1.getUShort(n,h),f!==0&&(f=f+p&65535)):f=v+p&65535,t.glyphIndexMap[v]=f}function Rn(t,e){var n={};n.version=f1.getUShort(t,e),z1.argument(n.version===0,"cmap table version should be 0."),n.numTables=f1.getUShort(t,e+2);for(var c=-1,r=n.numTables-1;r>=0;r-=1){var a=f1.getUShort(t,e+4+r*8),s=f1.getUShort(t,e+4+r*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){c=f1.getULong(t,e+4+r*8+4);break}}if(c===-1)throw new Error("No valid cmap sub-tables found.");var i=new f1.Parser(t,e+c);if(n.format=i.parseUShort(),n.format===12)Hn(n,i);else if(n.format===4)On(n,i,t,e,c);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function Fn(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function $n(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function Dn(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var c=t.get(n);if(c.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var r=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(r=r.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),r=r.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var a=new n1.Table("cmap",r);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)Fn(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}$n(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],m=[],p=[];for(n=0;n<o;n+=1){var g=a.segments[n];g.end<=65535&&g.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:g.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:g.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:g.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:g.offset}),g.glyphId!==void 0&&(m=m.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(p=p.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),p=p.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),p=p.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(a.segCountX2=(o-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(m),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+m.length*2,!e){var v=16+p.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:p.length/3}]),a.fields=a.fields.concat(p)}return a}var g8={parse:Rn,make:Dn},o4=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],qn=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],Nn=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],s3=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function v8(t){this.font=t}v8.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var c=0;c<n.length;c+=1)for(var r=n.get(c),a=0;a<r.unicodes.length;a+=1)if(r.unicodes[a]===e)return c}return null};function y8(t){this.cmap=t}y8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function p4(t,e){this.encoding=t,this.charset=e}p4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function U6(t){switch(t.version){case 1:this.names=s3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<s3.length?this.names[e]=s3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-s3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=s3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}U6.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};U6.prototype.glyphIndexToName=function(t){return this.names[t]};function Un(t){for(var e,n=t.tables.cmap.glyphIndexMap,c=Object.keys(n),r=0;r<c.length;r+=1){var a=c[r],s=n[a];e=t.glyphs.get(s),e.addUnicode(parseInt(a))}for(var i=0;i<t.glyphs.length;i+=1)e=t.glyphs.get(i),t.cffEncoding?t.isCIDFont?e.name="gid"+i:e.name=t.cffEncoding.charset[i]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(i))}function Bn(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),c=0;c<n.length;c+=1){var r=n[c],a=e[r];t._IndexToUnicodeMap[a]===void 0?t._IndexToUnicodeMap[a]={unicodes:[parseInt(r)]}:t._IndexToUnicodeMap[a].unicodes.push(parseInt(r))}}function Gn(t,e){e.lowMemory?Bn(t):Un(t)}function jn(t,e,n,c,r){t.beginPath(),t.moveTo(e,n),t.lineTo(c,r),t.stroke()}var a3={line:jn};function _n(t,e){var n=e||new x0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(c){n=c}}}function e2(t){this.bindConstructorValues(t)}e2.prototype.bindConstructorValues=function(t){this.index=t.index||0,this.name=t.name||null,this.unicode=t.unicode||void 0,this.unicodes=t.unicodes||t.unicode!==void 0?[t.unicode]:[],"xMin"in t&&(this.xMin=t.xMin),"yMin"in t&&(this.yMin=t.yMin),"xMax"in t&&(this.xMax=t.xMax),"yMax"in t&&(this.yMax=t.yMax),"advanceWidth"in t&&(this.advanceWidth=t.advanceWidth),Object.defineProperty(this,"path",_n(this,t.path))};e2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};e2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};e2.prototype.getPath=function(t,e,n,c,r){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;c||(c={});var i=c.xScale,o=c.yScale;if(c.hinting&&r&&r.hinting&&(s=this.path&&r.hinting.exec(this,n)),s)a=r.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),i=o=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new x0,u=0;u<a.length;u+=1){var f=a[u];f.type==="M"?h.moveTo(t+f.x*i,e+-f.y*o):f.type==="L"?h.lineTo(t+f.x*i,e+-f.y*o):f.type==="Q"?h.quadraticCurveTo(t+f.x1*i,e+-f.y1*o,t+f.x*i,e+-f.y*o):f.type==="C"?h.curveTo(t+f.x1*i,e+-f.y1*o,t+f.x2*i,e+-f.y2*o,t+f.x*i,e+-f.y*o):f.type==="Z"&&h.closePath()}return h};e2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var c=this.points[n];e.push(c),c.lastPointOfContour&&(t.push(e),e=[])}return z1.argument(e.length===0,"There are still points left in the current contour."),t};e2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];r.type!=="Z"&&(e.push(r.x),n.push(r.y)),(r.type==="Q"||r.type==="C")&&(e.push(r.x1),n.push(r.y1)),r.type==="C"&&(e.push(r.x2),n.push(r.y2))}var a={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a};e2.prototype.draw=function(t,e,n,c,r){this.getPath(e,n,c,r).draw(t)};e2.prototype.drawPoints=function(t,e,n,c){function r(u,f,d,m){t.beginPath();for(var p=0;p<u.length;p+=1)t.moveTo(f+u[p].x*m,d+u[p].y*m),t.arc(f+u[p].x*m,d+u[p].y*m,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24;for(var a=1/this.path.unitsPerEm*c,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",r(s,e,n,a),t.fillStyle="red",r(i,e,n,a)};e2.prototype.drawMetrics=function(t,e,n,c){var r;e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24,r=1/this.path.unitsPerEm*c,t.lineWidth=1,t.strokeStyle="black",a3.line(t,e,-1e4,e,1e4),a3.line(t,-1e4,n,1e4,n);var a=this.xMin||0,s=this.yMin||0,i=this.xMax||0,o=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",a3.line(t,e+a*r,-1e4,e+a*r,1e4),a3.line(t,e+i*r,-1e4,e+i*r,1e4),a3.line(t,-1e4,n+-s*r,1e4,n+-s*r),a3.line(t,-1e4,n+-o*r,1e4,n+-o*r),t.strokeStyle="green",a3.line(t,e+l*r,-1e4,e+l*r,1e4)};function s4(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(c){t[n]=c},enumerable:!0,configurable:!0})}function B6(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var c=e[n];c.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=c}this.length=e&&e.length||0}B6.prototype.get=function(t){if(this.glyphs[t]===void 0){this.font._push(t),typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());var e=this.glyphs[t],n=this.font._IndexToUnicodeMap[t];if(n)for(var c=0;c<n.unicodes.length;c++)e.addUnicode(n.unicodes[c]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+t:e.name=this.font.cffEncoding.charset[t]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(t)),this.glyphs[t].advanceWidth=this.font._hmtxTableData[t].advanceWidth,this.glyphs[t].leftSideBearing=this.font._hmtxTableData[t].leftSideBearing}else typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());return this.glyphs[t]};B6.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Wn(t,e){return new e2({index:e,font:t})}function Xn(t,e,n,c,r,a){return function(){var s=new e2({index:e,font:t});return s.path=function(){n(s,c,r);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},s4(s,"xMin","_xMin"),s4(s,"xMax","_xMax"),s4(s,"yMin","_yMin"),s4(s,"yMax","_yMax"),s}}function Zn(t,e,n,c){return function(){var r=new e2({index:e,font:t});return r.path=function(){var a=n(t,r,c);return a.unitsPerEm=t.unitsPerEm,a},r}}var x2={GlyphSet:B6,glyphLoader:Wn,ttfGlyphLoader:Xn,cffGlyphLoader:Zn};function b8(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n+=1)if(!b8(t[n],e[n]))return!1;return!0}else return!1}function V6(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function G2(t,e,n){var c=[],r=[],a=f1.getCard16(t,e),s,i;if(a!==0){var o=f1.getByte(t,e+2);s=e+(a+1)*o+2;for(var l=e+3,h=0;h<a+1;h+=1)c.push(f1.getOffset(t,l,o)),l+=o;i=s+c[a]}else i=e+2;for(var u=0;u<c.length-1;u+=1){var f=f1.getBytes(t,s+c[u],s+c[u+1]);n&&(f=n(f)),r.push(f)}return{objects:r,startOffset:e,endOffset:i}}function Yn(t,e){var n=[],c=f1.getCard16(t,e),r,a;if(c!==0){var s=f1.getByte(t,e+2);r=e+(c+1)*s+2;for(var i=e+3,o=0;o<c+1;o+=1)n.push(f1.getOffset(t,i,s)),i+=s;a=r+n[c]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function Jn(t,e,n,c,r){var a=f1.getCard16(n,c),s=0;if(a!==0){var i=f1.getByte(n,c+2);s=c+(a+1)*i+2}var o=f1.getBytes(n,s+e[t],s+e[t+1]);return r&&(o=r(o)),o}function Kn(t){for(var e="",n=15,c=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var r=t.parseByte(),a=r>>4,s=r&15;if(a===n||(e+=c[a],s===n))break;e+=c[s]}return parseFloat(e)}function Qn(t,e){var n,c,r,a;if(e===28)return n=t.parseByte(),c=t.parseByte(),n<<8|c;if(e===29)return n=t.parseByte(),c=t.parseByte(),r=t.parseByte(),a=t.parseByte(),n<<24|c<<16|r<<8|a;if(e===30)return Kn(t);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return n=t.parseByte(),(e-247)*256+n+108;if(e>=251&&e<=254)return n=t.parseByte(),-(e-251)*256-n-108;throw new Error("Invalid b0 "+e)}function ec(t){for(var e={},n=0;n<t.length;n+=1){var c=t[n][0],r=t[n][1],a=void 0;if(r.length===1?a=r[0]:a=r,e.hasOwnProperty(c)&&!isNaN(e[c]))throw new Error("Object "+e+" already has key "+c);e[c]=a}return e}function x8(t,e,n){e=e!==void 0?e:0;var c=new f1.Parser(t,e),r=[],a=[];for(n=n!==void 0?n:t.length;c.relativeOffset<n;){var s=c.parseByte();s<=21?(s===12&&(s=1200+c.parseByte()),r.push([s,a]),a=[]):a.push(Qn(c,s))}return ec(r)}function y5(t,e){return e<=390?e=o4[e]:e=t[e-391],e}function M8(t,e,n){for(var c={},r,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)r=t[s.op]!==void 0?t[s.op][o]:void 0,r===void 0&&(r=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(r=y5(n,r)),i[o]=r;c[s.name]=i}else r=t[s.op],r===void 0&&(r=s.value!==void 0?s.value:null),s.type==="SID"&&(r=y5(n,r)),c[s.name]=r}return c}function tc(t,e){var n={};return n.formatMajor=f1.getCard8(t,e),n.formatMinor=f1.getCard8(t,e+1),n.size=f1.getCard8(t,e+2),n.offsetSize=f1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var w8=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],z8=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function nc(t,e){var n=x8(t,0,t.byteLength);return M8(n,w8,e)}function k8(t,e,n,c){var r=x8(t,e,n);return M8(r,z8,c)}function T7(t,e,n,c){for(var r=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=nc(s,c);i._subrs=[],i._subrsBias=0,i._defaultWidthX=0,i._nominalWidthX=0;var o=i.private[0],l=i.private[1];if(o!==0&&l!==0){var h=k8(t,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=G2(t,u+e);i._subrs=f.objects,i._subrsBias=V6(i._subrs)}i._privateDict=h}r.push(i)}return r}function cc(t,e,n,c){var r,a,s=new f1.Parser(t,e);n-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<n;l+=1)r=s.parseSID(),i.push(y5(c,r));else if(o===1)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)i.push(y5(c,r)),r+=1}else if(o===2)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)i.push(y5(c,r)),r+=1}else throw new Error("Unknown charset format "+o);return i}function rc(t,e,n){var c,r={},a=new f1.Parser(t,e),s=a.parseCard8();if(s===0)for(var i=a.parseCard8(),o=0;o<i;o+=1)c=a.parseCard8(),r[c]=o;else if(s===1){var l=a.parseCard8();c=1;for(var h=0;h<l;h+=1)for(var u=a.parseCard8(),f=a.parseCard8(),d=u;d<=u+f;d+=1)r[d]=c,c+=1}else throw new Error("Unknown encoding format "+s);return new p4(r,n)}function I7(t,e,n){var c,r,a,s,i=new x0,o=[],l=0,h=!1,u=!1,f=0,d=0,m,p,g,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];m=b._subrs,p=b._subrsBias,g=b._defaultWidthX,v=b._nominalWidthX}else m=t.tables.cff.topDict._subrs,p=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function M(z,C){u&&i.closePath(),i.moveTo(z,C),u=!0}function S(){var z;z=o.length%2!==0,z&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function w(z){for(var C,k,T,q,R,U,j,V,Q,W,o1,m1,I=0;I<z.length;){var $=z[I];switch(I+=1,$){case 1:S();break;case 3:S();break;case 4:o.length>1&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),M(f,d);break;case 5:for(;o.length>0;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 6:for(;o.length>0&&(f+=o.shift(),i.lineTo(f,d),o.length!==0);)d+=o.shift(),i.lineTo(f,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(f,d),o.length!==0);)f+=o.shift(),i.lineTo(f,d);break;case 8:for(;o.length>0;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 10:R=o.pop()+p,U=m[R],U&&w(U);break;case 11:return;case 12:switch($=z[I],I+=1,$){case 35:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s+o.shift(),Q=j+o.shift(),W=V+o.shift(),o1=Q+o.shift(),m1=W+o.shift(),f=o1+o.shift(),d=m1+o.shift(),o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;case 34:c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s,Q=j+o.shift(),W=s,o1=Q+o.shift(),m1=d,f=o1+o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;case 36:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s,Q=j+o.shift(),W=s,o1=Q+o.shift(),m1=W+o.shift(),f=o1+o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;case 37:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),j=a+o.shift(),V=s+o.shift(),Q=j+o.shift(),W=V+o.shift(),o1=Q+o.shift(),m1=W+o.shift(),Math.abs(o1-f)>Math.abs(m1-d)?f=o1+o.shift():d=m1+o.shift(),i.curveTo(c,r,a,s,j,V),i.curveTo(Q,W,o1,m1,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+$),o.length=0}break;case 14:o.length>0&&!h&&(x=o.shift()+v,h=!0),u&&(i.closePath(),u=!1);break;case 18:S();break;case 19:case 20:S(),I+=l+7>>3;break;case 21:o.length>2&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),f+=o.pop(),M(f,d);break;case 22:o.length>1&&!h&&(x=o.shift()+v,h=!0),f+=o.pop(),M(f,d);break;case 23:S();break;case 24:for(;o.length>2;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 25:for(;o.length>6;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 26:for(o.length%2&&(f+=o.shift());o.length>0;)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a,d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s,i.curveTo(c,r,a,s,f,d);break;case 28:C=z[I],k=z[I+1],o.push((C<<24|k<<16)>>16),I+=2;break;case 29:R=o.pop()+t.gsubrsBias,U=t.gsubrs[R],U&&w(U);break;case 30:for(;o.length>0&&(c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;case 31:for(;o.length>0&&(c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;default:$<32?console.log("Glyph "+e.index+": unknown operator "+$):$<247?o.push($-139):$<251?(C=z[I],I+=1,o.push(($-247)*256+C+108)):$<255?(C=z[I],I+=1,o.push(-($-251)*256-C-108)):(C=z[I],k=z[I+1],T=z[I+2],q=z[I+3],I+=4,o.push((C<<24|k<<16|T<<8|q)/65536))}}}return w(n),e.advanceWidth=x,i}function ac(t,e,n,c){var r=[],a,s=new f1.Parser(t,e),i=s.parseCard8();if(i===0)for(var o=0;o<n;o++){if(a=s.parseCard8(),a>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+c+")");r.push(a)}else if(i===3){var l=s.parseCard16(),h=s.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var u,f=0;f<l;f++){if(a=s.parseCard8(),u=s.parseCard16(),a>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+c+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)r.push(a);h=u}if(u!==n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+u)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);return r}function sc(t,e,n,c){n.tables.cff={};var r=tc(t,e),a=G2(t,r.endOffset,f1.bytesToString),s=G2(t,a.endOffset),i=G2(t,s.endOffset,f1.bytesToString),o=G2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=V6(n.gsubrs);var l=T7(t,e,s.objects,i.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=G2(t,u),m=T7(t,e,d.objects,i.objects);h._fdArray=m,f+=e,h._fdSelect=ac(t,f,n.numGlyphs,m.length)}var p=e+h.private[1],g=k8(t,p,h.private[0],i.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=p+g.subrs,y=G2(t,v);n.subrs=y.objects,n.subrsBias=V6(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;c.lowMemory?(b=Yn(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=G2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=cc(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new p4(qn,x):h.encoding===1?n.cffEncoding=new p4(Nn,x):n.cffEncoding=rc(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new x2.GlyphSet(n),c.lowMemory)n._push=function(w){var z=Jn(w,b.offsets,t,e+h.charStrings);n.glyphs.push(w,x2.cffGlyphLoader(n,w,I7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var S=b.objects[M];n.glyphs.push(M,x2.cffGlyphLoader(n,M,I7,S))}}function S8(t,e){var n,c=o4.indexOf(t);return c>=0&&(n=c),c=e.indexOf(t),c>=0?n=c+o4.length:(n=o4.length+e.length,e.push(t)),n}function ic(){return new n1.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function oc(t){var e=new n1.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var n=0;n<t.length;n+=1)e.names.push({name:"name_"+n,type:"NAME",value:t[n]});return e}function L8(t,e,n){for(var c={},r=0;r<t.length;r+=1){var a=t[r],s=e[a.name];s!==void 0&&!b8(s,a.value)&&(a.type==="SID"&&(s=S8(s,n)),c[a.op]={name:a.name,type:a.type,value:s})}return c}function V7(t,e){var n=new n1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=L8(w8,t,e),n}function H7(t){var e=new n1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function lc(t){var e=new n1.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var n=0;n<t.length;n+=1)e.strings.push({name:"string_"+n,type:"STRING",value:t[n]});return e}function hc(){return new n1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function uc(t,e){for(var n=new n1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),c=0;c<t.length;c+=1){var r=t[c],a=S8(r,e);n.fields.push({name:"glyph_"+c,type:"SID",value:a})}return n}function fc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var c=0,r=0,a=0;a<n.commands.length;a+=1){var s=void 0,i=void 0,o=n.commands[a];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*c+h*o.x1),y1:Math.round(l*r+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="C"){var u=Math.round(o.x1-c),f=Math.round(o.y1-r),d=Math.round(o.x2-o.x1),m=Math.round(o.y2-o.y1);s=Math.round(o.x-o.x2),i=Math.round(o.y-o.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:m}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),c=Math.round(o.x),r=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function dc(t){for(var e=new n1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var c=t.get(n),r=fc(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:r})}return e}function mc(t,e){var n=new n1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=L8(z8,t,e),n}function pc(t,e){for(var n=new n1.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),c=1/e.unitsPerEm,r={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[c,0,0,c,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},s=[],i,o=1;o<t.length;o+=1)i=t.get(o),s.push(i.name);var l=[];n.header=ic(),n.nameIndex=oc([e.postScriptName]);var h=V7(r,l);n.topDictIndex=H7(h),n.globalSubrIndex=hc(),n.charsets=uc(s,l),n.charStringsIndex=dc(t),n.privateDict=mc(a,l),n.stringIndex=lc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return r.charset=u,r.encoding=0,r.charStrings=r.charset+n.charsets.sizeOf(),r.private[1]=r.charStrings+n.charStringsIndex.sizeOf(),h=V7(r,l),n.topDictIndex=H7(h),n}var A8={parse:sc,make:pc};function gc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.fontRevision=Math.round(c.parseFixed()*1e3)/1e3,n.checkSumAdjustment=c.parseULong(),n.magicNumber=c.parseULong(),z1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=c.parseUShort(),n.unitsPerEm=c.parseUShort(),n.created=c.parseLongDateTime(),n.modified=c.parseLongDateTime(),n.xMin=c.parseShort(),n.yMin=c.parseShort(),n.xMax=c.parseShort(),n.yMax=c.parseShort(),n.macStyle=c.parseUShort(),n.lowestRecPPEM=c.parseUShort(),n.fontDirectionHint=c.parseShort(),n.indexToLocFormat=c.parseShort(),n.glyphDataFormat=c.parseShort(),n}function vc(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new n1.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:n},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],t)}var C8={parse:gc,make:vc};function yc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.ascender=c.parseShort(),n.descender=c.parseShort(),n.lineGap=c.parseShort(),n.advanceWidthMax=c.parseUShort(),n.minLeftSideBearing=c.parseShort(),n.minRightSideBearing=c.parseShort(),n.xMaxExtent=c.parseShort(),n.caretSlopeRise=c.parseShort(),n.caretSlopeRun=c.parseShort(),n.caretOffset=c.parseShort(),c.relativeOffset+=8,n.metricDataFormat=c.parseShort(),n.numberOfHMetrics=c.parseUShort(),n}function bc(t){return new n1.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],t)}var P8={parse:yc,make:bc};function xc(t,e,n,c,r){for(var a,s,i=new f1.Parser(t,e),o=0;o<c;o+=1){o<n&&(a=i.parseUShort(),s=i.parseShort());var l=r.get(o);l.advanceWidth=a,l.leftSideBearing=s}}function Mc(t,e,n,c,r){t._hmtxTableData={};for(var a,s,i=new f1.Parser(e,n),o=0;o<r;o+=1)o<c&&(a=i.parseUShort(),s=i.parseShort()),t._hmtxTableData[o]={advanceWidth:a,leftSideBearing:s}}function wc(t,e,n,c,r,a,s){s.lowMemory?Mc(t,e,n,c,r):xc(e,n,c,r,a)}function zc(t){for(var e=new n1.Table("hmtx",[]),n=0;n<t.length;n+=1){var c=t.get(n),r=c.advanceWidth||0,a=c.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:r}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:a})}return e}var E8={parse:wc,make:zc};function kc(t){for(var e=new n1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",c=12+t.length*4,r=0;r<t.length;++r){var a=n.indexOf(t[r]);a<0&&(a=n.length,n+=t[r]),e.fields.push({name:"offset "+r,type:"USHORT",value:c+a}),e.fields.push({name:"length "+r,type:"USHORT",value:t[r].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Sc(t,e){var n=new f1.Parser(t,e),c=n.parseULong();z1.argument(c===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var r=n.parseULong(),a=[],s=0;s<r;s++){for(var i="",o=e+n.parseUShort(),l=n.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(t.getInt8(h));a.push(i)}return a}var T8={make:kc,parse:Sc};function Lc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.numGlyphs=c.parseUShort(),n.version===1&&(n.maxPoints=c.parseUShort(),n.maxContours=c.parseUShort(),n.maxCompositePoints=c.parseUShort(),n.maxCompositeContours=c.parseUShort(),n.maxZones=c.parseUShort(),n.maxTwilightPoints=c.parseUShort(),n.maxStorage=c.parseUShort(),n.maxFunctionDefs=c.parseUShort(),n.maxInstructionDefs=c.parseUShort(),n.maxStackElements=c.parseUShort(),n.maxSizeOfInstructions=c.parseUShort(),n.maxComponentElements=c.parseUShort(),n.maxComponentDepth=c.parseUShort()),n}function Ac(t){return new n1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var I8={parse:Lc,make:Ac},V8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],H8={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},Cc={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},O8={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function Pc(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return H8[e];case 3:return O8[e]}}var H6="utf-16",Ec={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},Tc={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function R8(t,e,n){switch(t){case 0:return H6;case 1:return Tc[n]||Ec[e];case 3:if(e===1||e===10)return H6;break}}function Ic(t,e,n){for(var c={},r=new f1.Parser(t,e),a=r.parseUShort(),s=r.parseUShort(),i=r.offset+r.parseUShort(),o=0;o<s;o++){var l=r.parseUShort(),h=r.parseUShort(),u=r.parseUShort(),f=r.parseUShort(),d=V8[f]||f,m=r.parseUShort(),p=r.parseUShort(),g=Pc(l,u,n),v=R8(l,h,u);if(v!==void 0&&g!==void 0){var y=void 0;if(v===H6?y=O3.UTF16(t,i+p,m):y=O3.MACSTRING(t,i+p,m,v),y){var b=c[d];b===void 0&&(b=c[d]={}),b[g]=y}}}var x=0;return a===1&&(x=r.parseUShort()),c}function M6(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function O7(t,e,n,c,r,a){return new n1.Record("NameRecord",[{name:"platformID",type:"USHORT",value:t},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:n},{name:"nameID",type:"USHORT",value:c},{name:"length",type:"USHORT",value:r},{name:"offset",type:"USHORT",value:a}])}function Vc(t,e){var n=t.length,c=e.length-n+1;e:for(var r=0;r<c;r++)for(;r<c;r++){for(var a=0;a<n;a++)if(e[r+a]!==t[a])continue e;return r}return-1}function R7(t,e){var n=Vc(t,e);if(n<0){n=e.length;for(var c=0,r=t.length;c<r;++c)e.push(t[c])}return n}function Hc(t,e){var n,c=[],r={},a=M6(V8);for(var s in t){var i=a[s];if(i===void 0&&(i=s),n=parseInt(i),isNaN(n))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');r[n]=t[s],c.push(n)}for(var o=M6(H8),l=M6(O8),h=[],u=[],f=0;f<c.length;f++){n=c[f];var d=r[n];for(var m in d){var p=d[m],g=1,v=o[m],y=Cc[v],b=R8(g,y,v),x=J.MACSTRING(p,b);x===void 0&&(g=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),y=4,x=J.UTF16(p));var M=R7(x,u);h.push(O7(g,y,v,n,x.length,M));var S=l[m];if(S!==void 0){var w=J.UTF16(p),z=R7(w,u);h.push(O7(3,1,S,n,w.length,z))}}}h.sort(function(T,q){return T.platformID-q.platformID||T.encodingID-q.encodingID||T.languageID-q.languageID||T.nameID-q.nameID});for(var C=new n1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),k=0;k<h.length;k++)C.fields.push({name:"record_"+k,type:"RECORD",value:h[k]});return C.fields.push({name:"strings",type:"LITERAL",value:u}),C}var F8={parse:Ic,make:Hc},O6=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function Oc(t){for(var e=0;e<O6.length;e+=1){var n=O6[e];if(t>=n.begin&&t<n.end)return e}return-1}function Rc(t,e){var n={},c=new f1.Parser(t,e);n.version=c.parseUShort(),n.xAvgCharWidth=c.parseShort(),n.usWeightClass=c.parseUShort(),n.usWidthClass=c.parseUShort(),n.fsType=c.parseUShort(),n.ySubscriptXSize=c.parseShort(),n.ySubscriptYSize=c.parseShort(),n.ySubscriptXOffset=c.parseShort(),n.ySubscriptYOffset=c.parseShort(),n.ySuperscriptXSize=c.parseShort(),n.ySuperscriptYSize=c.parseShort(),n.ySuperscriptXOffset=c.parseShort(),n.ySuperscriptYOffset=c.parseShort(),n.yStrikeoutSize=c.parseShort(),n.yStrikeoutPosition=c.parseShort(),n.sFamilyClass=c.parseShort(),n.panose=[];for(var r=0;r<10;r++)n.panose[r]=c.parseByte();return n.ulUnicodeRange1=c.parseULong(),n.ulUnicodeRange2=c.parseULong(),n.ulUnicodeRange3=c.parseULong(),n.ulUnicodeRange4=c.parseULong(),n.achVendID=String.fromCharCode(c.parseByte(),c.parseByte(),c.parseByte(),c.parseByte()),n.fsSelection=c.parseUShort(),n.usFirstCharIndex=c.parseUShort(),n.usLastCharIndex=c.parseUShort(),n.sTypoAscender=c.parseShort(),n.sTypoDescender=c.parseShort(),n.sTypoLineGap=c.parseShort(),n.usWinAscent=c.parseUShort(),n.usWinDescent=c.parseUShort(),n.version>=1&&(n.ulCodePageRange1=c.parseULong(),n.ulCodePageRange2=c.parseULong()),n.version>=2&&(n.sxHeight=c.parseShort(),n.sCapHeight=c.parseShort(),n.usDefaultChar=c.parseUShort(),n.usBreakChar=c.parseUShort(),n.usMaxContent=c.parseUShort()),n}function Fc(t){return new n1.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],t)}var R6={parse:Rc,make:Fc,unicodeRanges:O6,getUnicodeRange:Oc};function $c(t,e){var n={},c=new f1.Parser(t,e);switch(n.version=c.parseVersion(),n.italicAngle=c.parseFixed(),n.underlinePosition=c.parseShort(),n.underlineThickness=c.parseShort(),n.isFixedPitch=c.parseULong(),n.minMemType42=c.parseULong(),n.maxMemType42=c.parseULong(),n.minMemType1=c.parseULong(),n.maxMemType1=c.parseULong(),n.version){case 1:n.names=s3.slice();break;case 2:n.numberOfGlyphs=c.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var r=0;r<n.numberOfGlyphs;r++)n.glyphNameIndex[r]=c.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=s3.length){var s=c.parseChar();n.names.push(c.parseString(s))}break;case 2.5:n.numberOfGlyphs=c.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var i=0;i<n.numberOfGlyphs;i++)n.offset[i]=c.parseChar();break}return n}function Dc(){return new n1.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var $8={parse:$c,make:Dc},a2=new Array(9);a2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(H.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(H.coverage),substitute:this.parseOffset16List()};z1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};a2[2]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),sequences:this.parseListOfLists()}};a2[3]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),alternateSets:this.parseListOfLists()}};a2[4]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var H3={sequenceIndex:H.uShort,lookupListIndex:H.uShort};a2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(H.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,H3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(H.coverage),classDef:this.parsePointer(H.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,H3)}})};if(n===3){var c=this.parseUShort(),r=this.parseUShort();return{substFormat:n,coverages:this.parseList(c,H.pointer(H.coverage)),lookupRecords:this.parseRecordList(r,H3)}}z1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};a2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(H.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(H3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(H.coverage),backtrackClassDef:this.parsePointer(H.classDef),inputClassDef:this.parsePointer(H.classDef),lookaheadClassDef:this.parsePointer(H.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(H3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(H.pointer(H.coverage)),inputCoverage:this.parseList(H.pointer(H.coverage)),lookaheadCoverage:this.parseList(H.pointer(H.coverage)),lookupRecords:this.parseRecordList(H3)};z1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};a2[7]=function(){var e=this.parseUShort();z1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),c=new H(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:a2[n].call(c)}};a2[8]=function(){var e=this.parseUShort();return z1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(H.coverage),backtrackCoverage:this.parseList(H.pointer(H.coverage)),lookaheadCoverage:this.parseList(H.pointer(H.coverage)),substitutes:this.parseUShortList()}};function qc(t,e){e=e||0;var n=new H(t,e),c=n.parseVersion(1);return z1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(a2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(a2),variations:n.parseFeatureVariationsList()}}var R3=new Array(9);R3[1]=function(e){return e.substFormat===1?new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.ushortList("substitute",e.substitute)))};R3[2]=function(e){return z1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("seqSet",e.sequences,function(n){return new n1.Table("sequenceSetTable",n1.ushortList("sequence",n))})))};R3[3]=function(e){return z1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("altSet",e.alternateSets,function(n){return new n1.Table("alternateSetTable",n1.ushortList("alternate",n))})))};R3[4]=function(e){return z1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("ligSet",e.ligatureSets,function(n){return new n1.Table("ligatureSetTable",n1.tableList("ligature",n,function(c){return new n1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:c.ligGlyph}].concat(n1.ushortList("component",c.components,c.components.length+1)))}))})))};R3[6]=function(e){if(e.substFormat===1){var n=new n1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new n1.Table("chainRuleSetTable",n1.tableList("chainRule",a,function(s){var i=n1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(n1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(n1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(n1.ushortList("substitution",[],s.lookupRecords.length));return s.lookupRecords.forEach(function(o,l){i=i.concat({name:"sequenceIndex"+l,type:"USHORT",value:o.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:o.lookupListIndex})}),new n1.Table("chainRuleTable",i)}))})));return n}else if(e.substFormat===2)z1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var c=[{name:"substFormat",type:"USHORT",value:e.substFormat}];c.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(a,s){c.push({name:"backtrackCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){c.push({name:"inputCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){c.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){c=c.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var r=new n1.Table("chainContextTable",c);return r}z1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Nc(t){return new n1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new n1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new n1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new n1.LookupList(t.lookups,R3)}])}var D8={parse:qc,make:Nc};function Uc(t,e){var n=new f1.Parser(t,e),c=n.parseULong();z1.argument(c===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var r=n.parseULong(),a={},s=0;s<r;s++){var i=n.parseTag(),o=n.parseULong(),l=n.parseULong(),h=O3.UTF8(t,e+o,l);a[i]=h}return a}function Bc(t){var e=Object.keys(t).length,n="",c=16+e*12,r=new n1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:c},{name:"numTags",type:"ULONG",value:e}]);for(var a in t){var s=n.length;n+=t[a],r.fields.push({name:"tag "+a,type:"TAG",value:a}),r.fields.push({name:"offset "+a,type:"ULONG",value:c+s}),r.fields.push({name:"length "+a,type:"ULONG",value:t[a].length})}return r.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),r}var q8={parse:Uc,make:Bc};function F7(t){return Math.log(t)/Math.log(2)|0}function G6(t){for(;t.length%4!==0;)t.push(0);for(var e=0,n=0;n<t.length;n+=4)e+=(t[n]<<24)+(t[n+1]<<16)+(t[n+2]<<8)+t[n+3];return e%=Math.pow(2,32),e}function $7(t,e,n,c){return new n1.Record("Table Record",[{name:"tag",type:"TAG",value:t!==void 0?t:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:n!==void 0?n:0},{name:"length",type:"ULONG",value:c!==void 0?c:0}])}function N8(t){var e=new n1.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=t,e.numTables=t.length;var n=Math.pow(2,F7(e.numTables));e.searchRange=16*n,e.entrySelector=F7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],r=[],a=e.sizeOf()+$7().sizeOf()*e.numTables;a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var i=t[s];z1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=$7(i.tableName,G6(i.encode()),a,o);for(c.push({name:l.tag+" Table Record",type:"RECORD",value:l}),r.push({name:i.tableName+" table",type:"RECORD",value:i}),a+=o,z1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0})}return c.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(c),e.fields=e.fields.concat(r),e}function D7(t,e,n){for(var c=0;c<e.length;c+=1){var r=t.charToGlyphIndex(e[c]);if(r>0){var a=t.glyphs.get(r);return a.getMetrics()}}return n}function Gc(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function jc(t){for(var e=[],n=[],c=[],r=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,m=0;m<t.glyphs.length;m+=1){var p=t.glyphs.get(m),g=p.unicode|0;if(isNaN(p.advanceWidth))throw new Error("Glyph "+p.name+" ("+m+"): advanceWidth is not a number.");(o>g||o===void 0)&&g>0&&(o=g),l<g&&(l=g);var v=R6.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(p.name!==".notdef"){var y=p.getMetrics();e.push(y.xMin),n.push(y.yMin),c.push(y.xMax),r.push(y.yMax),s.push(y.leftSideBearing),i.push(y.rightSideBearing),a.push(p.advanceWidth)}}var b={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,c),yMax:Math.max.apply(null,r),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:Gc(a),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,i)};b.ascender=t.ascender,b.descender=t.descender;var x=C8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=P8.make({ascender:b.ascender,descender:b.descender,advanceWidthMax:b.advanceWidthMax,minLeftSideBearing:b.minLeftSideBearing,minRightSideBearing:b.minRightSideBearing,xMaxExtent:b.maxLeftSideBearing+(b.xMax-b.xMin),numberOfHMetrics:t.glyphs.length}),S=I8.make(t.glyphs.length),w=R6.make(Object.assign({xAvgCharWidth:Math.round(b.advanceWidthAvg),usFirstCharIndex:o,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:b.ascender,sTypoDescender:b.descender,sTypoLineGap:0,usWinAscent:b.yMax,usWinDescent:Math.abs(b.yMin),ulCodePageRange1:1,sxHeight:D7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:D7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=E8.make(t.glyphs),C=g8.make(t.glyphs),k=t.getEnglishName("fontFamily"),T=t.getEnglishName("fontSubfamily"),q=k+" "+T,R=t.getEnglishName("postScriptName");R||(R=k.replace(/\s/g,"")+"-"+T);var U={};for(var j in t.names)U[j]=t.names[j];U.uniqueID||(U.uniqueID={en:t.getEnglishName("manufacturer")+":"+q}),U.postScriptName||(U.postScriptName={en:R}),U.preferredFamily||(U.preferredFamily=t.names.fontFamily),U.preferredSubfamily||(U.preferredSubfamily=t.names.fontSubfamily);var V=[],Q=F8.make(U,V),W=V.length>0?T8.make(V):void 0,o1=$8.make(),m1=A8.make(t.glyphs,{version:t.getEnglishName("version"),fullName:q,familyName:k,weightName:T,postScriptName:R,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),I=t.metas&&Object.keys(t.metas).length>0?q8.make(t.metas):void 0,$=[x,M,S,w,Q,C,o1,m1,z];W&&$.push(W),t.tables.gsub&&$.push(D8.make(t.tables.gsub)),I&&$.push(I);for(var Z=N8($),_=Z.encode(),L1=G6(_),W1=Z.fields,E1=!1,Z1=0;Z1<W1.length;Z1+=1)if(W1[Z1].name==="head table"){W1[Z1].value.checkSumAdjustment=2981146554-L1,E1=!0;break}if(!E1)throw new Error("Could not find head table with checkSum to adjust.");return Z}var _c={make:N8,fontToTable:jc,computeCheckSum:G6};function w6(t,e){for(var n=0,c=t.length-1;n<=c;){var r=n+c>>>1,a=t[r].tag;if(a===e)return r;a<e?n=r+1:c=r-1}return-n-1}function q7(t,e){for(var n=0,c=t.length-1;n<=c;){var r=n+c>>>1,a=t[r];if(a===e)return r;a<e?n=r+1:c=r-1}return-n-1}function N7(t,e){for(var n,c=0,r=t.length-1;c<=r;){var a=c+r>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?c=a+1:r=a-1}if(c>0)return n=t[c-1],e>n.end?0:n}function z5(t,e){this.font=t,this.tableName=e}z5.prototype={searchTag:w6,binSearch:q7,getTable:function(t){var e=this.font.tables[this.tableName];return!e&&t&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var t=this.getTable();return t?t.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var t=this.getTable();if(t){for(var e=!1,n=0;n<t.scripts.length;n++){var c=t.scripts[n].tag;if(c==="DFLT")return c;c==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var c=n.scripts,r=w6(n.scripts,t);if(r>=0)return c[r].script;if(e){var a={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return c.splice(-1-r,0,a),a.script}}},getLangSysTable:function(t,e,n){var c=this.getScriptTable(t,n);if(c){if(!e||e==="dflt"||e==="DFLT")return c.defaultLangSys;var r=w6(c.langSysRecords,e);if(r>=0)return c.langSysRecords[r].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return c.langSysRecords.splice(-1-r,0,a),a.langSys}}},getFeatureTable:function(t,e,n,c){var r=this.getLangSysTable(t,e,c);if(r){for(var a,s=r.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(a=i[s[o]],a.tag===n)return a.feature;if(c){var l=i.length;return z1.assert(l===0||n>=i[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},i.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,c,r){var a=this.getFeatureTable(t,e,n,r),s=[];if(a){for(var i,o=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===c&&s.push(i);if(s.length===0&&r){i={lookupType:c,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(i),o.push(u),[i]}}return s},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=N7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=q7(t.glyphs,e);return n>=0?n:-1;case 2:var c=N7(t.ranges,e);return c?c.index+e-c.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,c=0;c<n.length;c++)for(var r=n[c],a=r.start,s=r.end,i=a;i<=s;i++)e.push(i);return e}};function k5(t){z5.call(this,t,"gpos")}k5.prototype=z5.prototype;k5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};k5.prototype.getKerningValue=function(t,e,n){for(var c=0;c<t.length;c++)for(var r=t[c].subtables,a=0;a<r.length;a++){var s=r[a],i=this.getCoverageIndex(s.coverage,e);if(!(i<0))switch(s.posFormat){case 1:for(var o=s.pairSets[i],l=0;l<o.length;l++){var h=o[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};k5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function W0(t){z5.call(this,t,"gsub")}function Wc(t,e){var n=t.length;if(n!==e.length)return!1;for(var c=0;c<n;c++)if(t[c]!==e[c])return!1;return!0}function j6(t,e,n){for(var c=t.subtables,r=0;r<c.length;r++){var a=c[r];if(a.substFormat===e)return a}if(n)return c.push(n),n}W0.prototype=z5.prototype;W0.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};W0.prototype.getSingle=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,1),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;if(o.substFormat===1){var u=o.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];c.push({sub:f,by:f+u})}}else{var d=o.substitute;for(h=0;h<l.length;h++)c.push({sub:l[h],by:d[h]})}}return c};W0.prototype.getMultiple=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,2),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=o.sequences[h];c.push({sub:u,by:f})}}return c};W0.prototype.getAlternates=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,3),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.alternateSets,u=0;u<l.length;u++)c.push({sub:l[u],by:h[u]});return c};W0.prototype.getLigatures=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,4),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],m=0;m<d.length;m++){var p=d[m];c.push({sub:[f].concat(p.components),by:p.ligGlyph})}return c};W0.prototype.addSingle=function(t,e,n,c){var r=this.getLookupTables(n,c,t,1,!0)[0],a=j6(r,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});z1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.substitute.splice(i,0,0)),a.substitute[i]=e.by};W0.prototype.addMultiple=function(t,e,n,c){z1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var r=this.getLookupTables(n,c,t,2,!0)[0],a=j6(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});z1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.sequences.splice(i,0,0)),a.sequences[i]=e.by};W0.prototype.addAlternate=function(t,e,n,c){var r=this.getLookupTables(n,c,t,3,!0)[0],a=j6(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});z1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.alternateSets.splice(i,0,0)),a.alternateSets[i]=e.by};W0.prototype.addLigature=function(t,e,n,c){var r=this.getLookupTables(n,c,t,4,!0)[0],a=r.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},r.subtables[0]=a),z1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(Wc(h[u].components,i))return;h.push(o)}else l=-1-l,a.coverage.glyphs.splice(l,0,s),a.ligatureSets.splice(l,0,[o])};W0.prototype.getFeature=function(t,e,n){if(/ss\d\d/.test(t))return this.getSingle(t,e,n);switch(t){case"aalt":case"salt":return this.getSingle(t,e,n).concat(this.getAlternates(t,e,n));case"dlig":case"liga":case"rlig":return this.getLigatures(t,e,n);case"ccmp":return this.getMultiple(t,e,n).concat(this.getLigatures(t,e,n));case"stch":return this.getMultiple(t,e,n)}};W0.prototype.add=function(t,e,n,c){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,c);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,c):this.addAlternate(t,e,n,c);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,c);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,c):this.addLigature(t,e,n,c)}};function Xc(){return typeof window<"u"}function Zc(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),c=0;c<e.length;++c)e[c]=n[c];return e}function v5(t,e){if(!t)throw e}function U7(t,e,n,c,r){var a;return(e&c)>0?(a=t.parseByte(),(e&r)===0&&(a=-a),a=n+a):(e&r)>0?a=n:a=n+t.parseShort(),a}function U8(t,e,n){var c=new f1.Parser(e,n);t.numberOfContours=c.parseShort(),t._xMin=c.parseShort(),t._yMin=c.parseShort(),t._xMax=c.parseShort(),t._yMax=c.parseShort();var r,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],i=0;i<t.numberOfContours;i+=1)s.push(c.parseUShort());t.instructionLength=c.parseUShort(),t.instructions=[];for(var o=0;o<t.instructionLength;o+=1)t.instructions.push(c.parseByte());var l=s[s.length-1]+1;r=[];for(var h=0;h<l;h+=1)if(a=c.parseByte(),r.push(a),(a&8)>0)for(var u=c.parseByte(),f=0;f<u;f+=1)r.push(a),h+=1;if(z1.argument(r.length===l,"Bad flags."),s.length>0){var d=[],m;if(l>0){for(var p=0;p<l;p+=1)a=r[p],m={},m.onCurve=!!(a&1),m.lastPointOfContour=s.indexOf(p)>=0,d.push(m);for(var g=0,v=0;v<l;v+=1)a=r[v],m=d[v],m.x=U7(c,a,g,2,16),g=m.x;for(var y=0,b=0;b<l;b+=1)a=r[b],m=d[b],m.y=U7(c,a,y,4,32),y=m.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){r=c.parseUShort();var M={glyphIndex:c.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(r&1)>0?(r&2)>0?(M.dx=c.parseShort(),M.dy=c.parseShort()):M.matchedPoints=[c.parseUShort(),c.parseUShort()]:(r&2)>0?(M.dx=c.parseChar(),M.dy=c.parseChar()):M.matchedPoints=[c.parseByte(),c.parseByte()],(r&8)>0?M.xScale=M.yScale=c.parseF2Dot14():(r&64)>0?(M.xScale=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()):(r&128)>0&&(M.xScale=c.parseF2Dot14(),M.scale01=c.parseF2Dot14(),M.scale10=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()),t.components.push(M),x=!!(r&32)}if(r&256){t.instructionLength=c.parseUShort(),t.instructions=[];for(var S=0;S<t.instructionLength;S+=1)t.instructions.push(c.parseByte())}}}function z6(t,e){for(var n=[],c=0;c<t.length;c+=1){var r=t[c],a={x:e.xScale*r.x+e.scale01*r.y+e.dx,y:e.scale10*r.x+e.yScale*r.y+e.dy,onCurve:r.onCurve,lastPointOfContour:r.lastPointOfContour};n.push(a)}return n}function Yc(t){for(var e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];n.push(r),r.lastPointOfContour&&(e.push(n),n=[])}return z1.argument(n.length===0,"There are still points left in the current contour."),e}function B8(t){var e=new x0;if(!t)return e;for(var n=Yc(t),c=0;c<n.length;++c){var r=n[c],a=null,s=r[r.length-1],i=r[0];if(s.onCurve)e.moveTo(s.x,s.y);else if(i.onCurve)e.moveTo(i.x,i.y);else{var o={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5};e.moveTo(o.x,o.y)}for(var l=0;l<r.length;++l)if(a=s,s=i,i=r[(l+1)%r.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=a,u=i;a.onCurve||(h={x:(s.x+a.x)*.5,y:(s.y+a.y)*.5}),i.onCurve||(u={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5}),e.quadraticCurveTo(s.x,s.y,u.x,u.y)}e.closePath()}return e}function G8(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var c=e.components[n],r=t.get(c.glyphIndex);if(r.getPath(),r.points){var a=void 0;if(c.matchedPoints===void 0)a=z6(r.points,c);else{if(c.matchedPoints[0]>e.points.length-1||c.matchedPoints[1]>r.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[c.matchedPoints[0]],i=r.points[c.matchedPoints[1]],o={xScale:c.xScale,scale01:c.scale01,scale10:c.scale10,yScale:c.yScale,dx:0,dy:0};i=z6([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=z6(r.points,o)}e.points=e.points.concat(a)}}return B8(e.points)}function Jc(t,e,n,c){for(var r=new x2.GlyphSet(c),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?r.push(a,x2.ttfGlyphLoader(c,a,U8,t,e+s,G8)):r.push(a,x2.glyphLoader(c,a))}return r}function Kc(t,e,n,c){var r=new x2.GlyphSet(c);return c._push=function(a){var s=n[a],i=n[a+1];s!==i?r.push(a,x2.ttfGlyphLoader(c,a,U8,t,e+s,G8)):r.push(a,x2.glyphLoader(c,a))},r}function Qc(t,e,n,c,r){return r.lowMemory?Kc(t,e,n,c):Jc(t,e,n,c)}var j8={getPath:B8,parse:Qc},_8,o3,W8,F6;function X8(t){this.font=t,this.getCommands=function(e){return j8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function er(t){return t}function Z8(t){return Math.sign(t)*Math.round(Math.abs(t))}function tr(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function nr(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function cr(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function rr(t){return Math.sign(t)*Math.floor(Math.abs(t))}var Y8=function(t){var e=this.srPeriod,n=this.srPhase,c=this.srThreshold,r=1;return t<0&&(t=-t,r=-1),t+=c-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*r:t*r},b2={x:1,y:0,axis:"x",distance:function(t,e,n,c){return(n?t.xo:t.x)-(c?e.xo:e.x)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.xo-e.xo,a=t.xo-n.xo,o=e.x-e.xo,l=n.x-n.xo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.x=t.xo+(o+l)/2;return}t.x=t.xo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){b2.setRelative(t,t,(o+l)/2,c,!0);return}b2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,c,r){if(!c||c===this){t.x=(r?e.xo:e.x)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.x=i+(t.y-o)/c.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},E2={x:0,y:1,axis:"y",distance:function(t,e,n,c){return(n?t.yo:t.y)-(c?e.yo:e.y)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.yo-e.yo,a=t.yo-n.yo,o=e.y-e.yo,l=n.y-n.yo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.y=t.yo+(o+l)/2;return}t.y=t.yo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){E2.setRelative(t,t,(o+l)/2,c,!0);return}E2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:0,setRelative:function(t,e,n,c,r){if(!c||c===this){t.y=(r?e.yo:e.y)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.y=o+c.normalSlope*(t.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(b2);Object.freeze(E2);function S5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}S5.prototype.distance=function(t,e,n,c){return this.x*b2.distance(t,e,n,c)+this.y*E2.distance(t,e,n,c)};S5.prototype.interpolate=function(t,e,n,c){var r,a,s,i,o,l,h;if(s=c.distance(t,e,!0,!0),i=c.distance(t,n,!0,!0),r=c.distance(e,e,!1,!0),a=c.distance(n,n,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(t,t,(r+a)/2,c,!0);return}this.setRelative(t,t,(r*l+a*o)/h,c,!0)};S5.prototype.setRelative=function(t,e,n,c,r){c=c||this;var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y,l=c.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*i+o-f)/(h-l),t.y=h*(t.x-u)+f};S5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function L5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?b2:t===0&&e===1?E2:new S5(t,e)}function T2(t,e,n,c){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=c,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}T2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};T2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var w5=Object.freeze(new T2(0,0)),ar={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function j2(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=b2,this.round=Z8}}X8.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,c=this._prepState;if(!c||c.ppem!==e){var r=this._fpgmState;if(!r){j2.prototype=ar,r=this._fpgmState=new j2("fpgm",n.tables.fpgm),r.funcs=[],r.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),r.step=-1);try{o3(r)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}j2.prototype=r,c=this._prepState=new j2("prep",n.tables.prep),c.ppem=e;var a=n.tables.cvt;if(a)for(var s=c.cvt=new Array(a.length),i=e/n.unitsPerEm,o=0;o<a.length;o++)s[o]=a[o]*i;else c.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),c.step=-1);try{o3(c)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return W8(t,c)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};W8=function(t,e){var n=e.ppem/e.font.unitsPerEm,c=n,r=t.components,a,s,i;if(j2.prototype=e,!r)i=new j2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),F6(t,i,n,c),s=i.gZone;else{var o=e.font;s=[],a=[];for(var l=0;l<r.length;l++){var h=r[l],u=o.glyphs.get(h.glyphIndex);i=new j2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),F6(u,i,n,c);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*c),m=i.gZone,p=i.contours,g=0;g<m.length;g++){var v=m[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,m);for(var b=0;b<p.length;b++)a.push(p[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new j2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new T2(0,0),new T2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),o3(i),s.length-=2)}return s};F6=function(t,e,n,c){for(var r=t.points||[],a=r.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<a;l++)o=r[l],s[l]=new T2(o.x*n,o.y*c,o.lastPointOfContour,o.onCurve);for(var h,u,f=0;f<a;f++)o=s[f],h||(h=o,i.push(f)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(u=s[f+1],o.nextPointOnContour=u,u.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new T2(0,0),new T2(Math.round(t.advanceWidth*n),0)),o3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<a;m++)console.log(m,s[m].x,s[m].y)}}};o3=function(t){var e=t.prog;if(e){var n=e.length,c;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,c=_8[e[t.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));c(t)}}};function g4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new T2(0,0)}function J8(t,e){var n=t.prog,c=t.ip,r=1,a;do if(a=n[++c],a===88)r++;else if(a===89)r--;else if(a===64)c+=n[c+1]+1;else if(a===65)c+=2*n[c+1]+1;else if(a>=176&&a<=183)c+=a-176+1;else if(a>=184&&a<=191)c+=(a-184+1)*2;else if(e&&r===1&&a===27)break;while(r>0);t.ip=c}function B7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function G7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function j7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function _7(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.pv=e.dpv=L5(i,o)}function W7(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SFVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.fv=L5(i,o)}function sr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.pv=t.dpv=L5(c,n)}function ir(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.fv=L5(c,n)}function or(t){var e=t.stack,n=t.pv;exports.DEBUG&&console.log(t.step,"GPV[]"),e.push(n.x*16384),e.push(n.y*16384)}function lr(t){var e=t.stack,n=t.fv;exports.DEBUG&&console.log(t.step,"GFV[]"),e.push(n.x*16384),e.push(n.y*16384)}function hr(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function ur(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop(),a=e.pop(),s=e.pop(),i=t.z0,o=t.z1,l=i[n],h=i[c],u=o[r],f=o[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,c,r,a,s);var m=l.x,p=l.y,g=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,S=(m-g)*(b-M)-(p-v)*(y-x),w=m*v-p*g,z=y*M-b*x;d.x=(w*(y-x)-z*(m-g))/S,d.y=(w*(b-M)-z*(p-v))/S}function fr(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function dr(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function mr(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function pr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||g4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function gr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||g4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function vr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||g4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function yr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZPS[]",e),t.zp0=t.zp1=t.zp2=e,e){case 0:t.tZone||g4(t),t.z0=t.z1=t.z2=t.tZone;break;case 1:t.z0=t.z1=t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function br(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function xr(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=Z8}function Mr(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=nr}function wr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function zr(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),J8(t,!1)}function kr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Sr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Lr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function k6(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function Ar(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Cr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(c)}function Pr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Er(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,c);var r=t.ip,a=t.prog;t.prog=t.funcs[n];for(var s=0;s<c;s++)o3(t),exports.DEBUG&&console.log(++t.step,s+1<c?"next loopcall":"done loopcall",s);t.ip=r,t.prog=a}function Tr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,c=t.prog;t.prog=t.funcs[e],o3(t),t.ip=n,t.prog=c,exports.DEBUG&&console.log(++t.step,"returning from",e)}function Ir(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Vr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"MINDEX[]",n),e.push(e.splice(e.length-n,1)[0])}function Hr(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,c=t.ip,r=e.pop(),a=c;for(exports.DEBUG&&console.log(t.step,"FDEF[]",r);n[++c]!==45;);t.ip=c,t.funcs[r]=n.slice(a+1,c)}function X7(t,e){var n=e.stack.pop(),c=e.z0[n],r=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(c,w5);t&&(s=e.round(s)),r.setRelative(c,w5,s,a),r.touch(c),e.rp0=e.rp1=n}function Z7(t,e){var n=e.z2,c=n.length-2,r,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var i=0;i<c;i++)r=n[i],!t.touched(r)&&(a=r.prevTouched(t),a!==r&&(s=r.nextTouched(t),a===s&&t.setRelative(r,r,t.distance(a,a,!1,!0),t,!0),t.interpolate(r,a,s,t)))}function Y7(t,e){for(var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=e.loop,o=e.z2;i--;){var l=n.pop(),h=o[l],u=s.distance(r,r,!1,!0);a.setRelative(h,h,u,s),a.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-i)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function J7(t,e){var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=n.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",i);var h=s.distance(r,r,!1,!0);do l!==r&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function K7(t,e){var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",i);var o;switch(i){case 0:o=e.tZone;break;case 1:o=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=s.distance(r,r,!1,!0),u=o.length-2,f=0;f<u;f++)l=o[f],a.setRelative(l,l,h,s)}function Or(t){for(var e=t.stack,n=t.loop,c=t.fv,r=e.pop()/64,a=t.z2;n--;){var s=e.pop(),i=a[s];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",s,r),c.setRelative(i,i,r),c.touch(i)}t.loop=1}function Rr(t){for(var e=t.stack,n=t.rp1,c=t.rp2,r=t.loop,a=t.z0[n],s=t.z1[c],i=t.fv,o=t.dpv,l=t.z2;r--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-r)+": ":"")+"IP[]",h,n,"<->",c),i.interpolate(u,a,s,o),i.touch(u)}t.loop=1}function Q7(t,e){var n=e.stack,c=n.pop()/64,r=n.pop(),a=e.z1[r],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(a,s,c,o),i.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",c,r),e.rp1=e.rp0,e.rp2=r,t&&(e.rp0=r)}function Fr(t){for(var e=t.stack,n=t.rp0,c=t.z0[n],r=t.loop,a=t.fv,s=t.pv,i=t.z1;r--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-r)+": ":"")+"ALIGNRP[]",o),a.setRelative(l,c,0,s),a.touch(l)}t.loop=1}function $r(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=tr}function e8(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z0[r],s=e.fv,i=e.pv,o=e.cvt[c];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",c,"(",o,")",r);var l=i.distance(a,w5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,w5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=r}function Dr(t){var e=t.prog,n=t.ip,c=t.stack,r=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",r);for(var a=0;a<r;a++)c.push(e[++n]);t.ip=n}function qr(t){var e=t.ip,n=t.prog,c=t.stack,r=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",r);for(var a=0;a<r;a++){var s=n[++e]<<8|n[++e];s&32768&&(s=-((s^65535)+1)),c.push(s)}t.ip=e}function Nr(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var c=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WS",c,r),n[r]=c}function Ur(t){var e=t.stack,n=t.store,c=e.pop();exports.DEBUG&&console.log(t.step,"RS",c);var r=n&&n[c]||0;e.push(r)}function Br(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,c),t.cvt[c]=n/64}function Gr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function t8(t,e){var n=e.stack,c=n.pop(),r=e.z2[c];exports.DEBUG&&console.log(e.step,"GC["+t+"]",c),n.push(e.dpv.distance(r,w5,t,!1)*64)}function n8(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z1[c],s=e.z0[r],i=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",c,r,"->",i),e.stack.push(Math.round(i*64))}function jr(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function _r(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Wr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,c),e.push(c<n?1:0)}function Xr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,c),e.push(c<=n?1:0)}function Zr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,c),e.push(c>n?1:0)}function Yr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,c),e.push(c>=n?1:0)}function Jr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,c),e.push(n===c?1:0)}function Kr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,c),e.push(n!==c?1:0)}function Qr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ODD[]",n),e.push(Math.trunc(n)%2?1:0)}function ea(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"EVEN[]",n),e.push(Math.trunc(n)%2?0:1)}function ta(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(J8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function na(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function ca(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,c),e.push(n&&c?1:0)}function ra(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,c),e.push(n||c?1:0)}function aa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function S6(t,e){var n=e.stack,c=n.pop(),r=e.fv,a=e.pv,s=e.ppem,i=e.deltaBase+(t-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",c,n);for(var h=0;h<c;h++){var u=n.pop(),f=n.pop(),d=i+((f&240)>>4);if(d===s){var m=(f&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",m*o);var p=l[u];r.setRelative(p,p,m*o,a)}}}function sa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function oa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,c),e.push(c+n)}function la(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,c),e.push(c-n)}function ha(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,c),e.push(c*64/n)}function ua(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,c),e.push(c*n/64)}function fa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function da(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function ma(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function pa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function i4(t,e){var n=e.stack,c=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(c/64)*64)}function ga(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,c),t.cvt[c]=n*t.ppem/t.font.unitsPerEm}function L6(t,e){var n=e.stack,c=n.pop(),r=e.ppem,a=e.deltaBase+(t-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",c,n);for(var i=0;i<c;i++){var o=n.pop(),l=n.pop(),h=a+((l&240)>>4);if(h===r){var u=(l&15)-8;u>=0&&u++;var f=u*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",o,"by",f),e.cvt[o]+=f}}}function va(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=Y8;var n;switch(e&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw new Error("invalid SROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function ya(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=Y8;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function ba(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=er}function xa(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=cr}function Ma(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=rr}function wa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function c8(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.dpv=L5(i,o)}function za(t){var e=t.stack,n=e.pop(),c=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(c=35),n&32&&(c|=4096),e.push(c)}function ka(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(c),e.push(n),e.push(r)}function Sa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,c),e.push(Math.max(c,n))}function La(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,c),e.push(Math.min(c,n))}function Aa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ca(t){var e=t.stack.pop(),n=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"INSTCTRL[]",e,n),e){case 1:t.inhibitGridFit=!!n;return;case 2:t.ignoreCvt=!!n;return;default:throw new Error("invalid INSTCTRL[] selector")}}function U2(t,e){var n=e.stack,c=e.prog,r=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(c[++r]);e.ip=r}function B2(t,e){var n=e.ip,c=e.prog,r=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=c[++n]<<8|c[++n];s&32768&&(s=-((s^65535)+1)),r.push(s)}e.ip=n}function h1(t,e,n,c,r,a){var s=a.stack,i=t&&s.pop(),o=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[o],f=a.minDis,d=a.fv,m=a.dpv,p,g,v,y;g=p=m.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(y=a.cvt[i],c&&Math.abs(g-y)<a.cvCutIn&&(g=y)),n&&g<f&&(g=f),c&&(g=a.round(g)),d.setRelative(u,h,v*g,m),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(c?"R":"_")+(r===0?"Gr":r===1?"Bl":r===2?"Wh":"")+"]",t?i+"("+a.cvt[i]+","+y+")":"",o,"(d =",p,"->",v*g,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}_8=[B7.bind(void 0,E2),B7.bind(void 0,b2),G7.bind(void 0,E2),G7.bind(void 0,b2),j7.bind(void 0,E2),j7.bind(void 0,b2),_7.bind(void 0,0),_7.bind(void 0,1),W7.bind(void 0,0),W7.bind(void 0,1),sr,ir,or,lr,hr,ur,fr,dr,mr,pr,gr,vr,yr,br,xr,Mr,wr,zr,kr,Sr,void 0,void 0,Lr,k6,Ar,Cr,Pr,Ir,Vr,void 0,void 0,void 0,Er,Tr,Hr,void 0,X7.bind(void 0,0),X7.bind(void 0,1),Z7.bind(void 0,E2),Z7.bind(void 0,b2),Y7.bind(void 0,0),Y7.bind(void 0,1),J7.bind(void 0,0),J7.bind(void 0,1),K7.bind(void 0,0),K7.bind(void 0,1),Or,Rr,Q7.bind(void 0,0),Q7.bind(void 0,1),Fr,$r,e8.bind(void 0,0),e8.bind(void 0,1),Dr,qr,Nr,Ur,Br,Gr,t8.bind(void 0,0),t8.bind(void 0,1),void 0,n8.bind(void 0,0),n8.bind(void 0,1),jr,void 0,_r,void 0,void 0,Wr,Xr,Zr,Yr,Jr,Kr,Qr,ea,ta,na,ca,ra,aa,S6.bind(void 0,1),sa,ia,oa,la,ha,ua,fa,da,ma,pa,i4.bind(void 0,0),i4.bind(void 0,1),i4.bind(void 0,2),i4.bind(void 0,3),void 0,void 0,void 0,void 0,ga,S6.bind(void 0,2),S6.bind(void 0,3),L6.bind(void 0,1),L6.bind(void 0,2),L6.bind(void 0,3),va,ya,void 0,void 0,ba,void 0,xa,Ma,k6,k6,void 0,void 0,void 0,void 0,void 0,wa,c8.bind(void 0,0),c8.bind(void 0,1),za,void 0,ka,Sa,La,Aa,Ca,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,U2.bind(void 0,1),U2.bind(void 0,2),U2.bind(void 0,3),U2.bind(void 0,4),U2.bind(void 0,5),U2.bind(void 0,6),U2.bind(void 0,7),U2.bind(void 0,8),B2.bind(void 0,1),B2.bind(void 0,2),B2.bind(void 0,3),B2.bind(void 0,4),B2.bind(void 0,5),B2.bind(void 0,6),B2.bind(void 0,7),B2.bind(void 0,8),h1.bind(void 0,0,0,0,0,0),h1.bind(void 0,0,0,0,0,1),h1.bind(void 0,0,0,0,0,2),h1.bind(void 0,0,0,0,0,3),h1.bind(void 0,0,0,0,1,0),h1.bind(void 0,0,0,0,1,1),h1.bind(void 0,0,0,0,1,2),h1.bind(void 0,0,0,0,1,3),h1.bind(void 0,0,0,1,0,0),h1.bind(void 0,0,0,1,0,1),h1.bind(void 0,0,0,1,0,2),h1.bind(void 0,0,0,1,0,3),h1.bind(void 0,0,0,1,1,0),h1.bind(void 0,0,0,1,1,1),h1.bind(void 0,0,0,1,1,2),h1.bind(void 0,0,0,1,1,3),h1.bind(void 0,0,1,0,0,0),h1.bind(void 0,0,1,0,0,1),h1.bind(void 0,0,1,0,0,2),h1.bind(void 0,0,1,0,0,3),h1.bind(void 0,0,1,0,1,0),h1.bind(void 0,0,1,0,1,1),h1.bind(void 0,0,1,0,1,2),h1.bind(void 0,0,1,0,1,3),h1.bind(void 0,0,1,1,0,0),h1.bind(void 0,0,1,1,0,1),h1.bind(void 0,0,1,1,0,2),h1.bind(void 0,0,1,1,0,3),h1.bind(void 0,0,1,1,1,0),h1.bind(void 0,0,1,1,1,1),h1.bind(void 0,0,1,1,1,2),h1.bind(void 0,0,1,1,1,3),h1.bind(void 0,1,0,0,0,0),h1.bind(void 0,1,0,0,0,1),h1.bind(void 0,1,0,0,0,2),h1.bind(void 0,1,0,0,0,3),h1.bind(void 0,1,0,0,1,0),h1.bind(void 0,1,0,0,1,1),h1.bind(void 0,1,0,0,1,2),h1.bind(void 0,1,0,0,1,3),h1.bind(void 0,1,0,1,0,0),h1.bind(void 0,1,0,1,0,1),h1.bind(void 0,1,0,1,0,2),h1.bind(void 0,1,0,1,0,3),h1.bind(void 0,1,0,1,1,0),h1.bind(void 0,1,0,1,1,1),h1.bind(void 0,1,0,1,1,2),h1.bind(void 0,1,0,1,1,3),h1.bind(void 0,1,1,0,0,0),h1.bind(void 0,1,1,0,0,1),h1.bind(void 0,1,1,0,0,2),h1.bind(void 0,1,1,0,0,3),h1.bind(void 0,1,1,0,1,0),h1.bind(void 0,1,1,0,1,1),h1.bind(void 0,1,1,0,1,2),h1.bind(void 0,1,1,0,1,3),h1.bind(void 0,1,1,1,0,0),h1.bind(void 0,1,1,1,0,1),h1.bind(void 0,1,1,1,0,2),h1.bind(void 0,1,1,1,0,3),h1.bind(void 0,1,1,1,1,0),h1.bind(void 0,1,1,1,1,1),h1.bind(void 0,1,1,1,1,2),h1.bind(void 0,1,1,1,1,3)];function F3(t){this.char=t,this.state={},this.activeState=null}function _6(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function Pa(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function s2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function v4(t){this.eventId=t,this.subscribers=[]}function Ea(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(r){Object.defineProperty(e.events,r,{value:new v4(r)})}),t&&n.forEach(function(r){var a=t[r];typeof a=="function"&&e.events[r].subscribe(a)});var c=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];c.forEach(function(r){e.events[r].subscribe(e.updateContextsRanges)})}function u0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Ea.call(this,t)}F3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};F3.prototype.getState=function(t){return this.state[t]||null};u0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};u0.prototype.composeRUD=function(t){var e=this,n=!0,c=t.map(function(a){return e[a[0]].apply(e,a.slice(1).concat(n))}),r=function(a){return typeof a=="object"&&a.hasOwnProperty("FAIL")};if(c.every(r))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:c.filter(r)};this.dispatch("composeRUD",[c.filter(function(a){return!r(a)})])};u0.prototype.replaceRange=function(t,e,n,c){e=e!==null?e:this.tokens.length;var r=n.every(function(s){return s instanceof F3});if(!isNaN(t)&&this.inboundIndex(t)&&r){var a=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return c||this.dispatch("replaceToken",[t,e,n]),[a,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};u0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof F3){var c=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[c[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};u0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var c=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[c,t,e]),c};u0.prototype.removeToken=function(t,e){if(!isNaN(t)&&this.inboundIndex(t)){var n=this.tokens.splice(t,1);return e||this.dispatch("removeToken",[n,t]),n}else return{FAIL:"removeToken: invalid token index."}};u0.prototype.insertToken=function(t,e,n){var c=t.every(function(r){return r instanceof F3});return c?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};u0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(c,r){var a=[c,r],s=e===null||e.apply(this,a)===!0,i=[c,r];if(s){var o=n.apply(this,i);c.setState(t,o)}}),this.registeredModifiers.push(t)};v4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};v4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};s2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};s2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};u0.prototype.rangeToText=function(t){if(t instanceof _6)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};u0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};u0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};u0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};u0.prototype.dispatch=function(t,e){var n=this,c=this.events[t];c instanceof v4&&c.subscribers.forEach(function(r){r.apply(n,e||[])})};u0.prototype.registerContextChecker=function(t,e,n){if(this.getContext(t))return{FAIL:"context name '"+t+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof n!="function")return{FAIL:"missing context end check."};var c=new Pa(t,e,n);return this.registeredContexts[t]=c,this.contextCheckers.push(c),c};u0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};u0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};u0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};u0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(c){return c.char}),e=0;e<t.length;e++){var n=new s2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};u0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,c=new _6(n,t,e),r=this.getContext(e).ranges;return c.rangeId=e+"."+r.length,r.push(c),this.getContext(e).openRange=null,c};u0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(c){var r=c.contextName,a=e.getContext(r).openRange;if(!a&&c.checkStart(t)&&(a=new _6(n,null,r),e.getContext(r).openRange=a,e.dispatch("contextStart",[r,n])),a&&c.checkEnd(t)){var s=n-a.startIndex+1,i=e.setEndOffset(s,r);e.dispatch("contextEnd",[r,i])}})};u0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var c=e[n],r=new s2(e,n);this.dispatch("next",[r]),this.runContextCheck(r);var a=new F3(c);this.tokens.push(a),this.dispatch("newToken",[a,r])}return this.dispatch("end",[this.tokens]),this.tokens};function _2(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function K8(t){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(t)}function W2(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function l4(t){return/[A-z]/.test(t)}function Ta(t){return/\s/.test(t)}function X0(t){this.font=t,this.features={}}function i3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function A5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,c=0;c<n.length;c++){var r=n[c];if(t>=r.start&&t<=r.end){var a=t-r.start;return r.index+a}}break;default:return-1}return-1}function Ia(t,e){var n=A5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Va(t,e){var n=A5(t,e.coverage);return n===-1?null:e.substitute[n]}function A6(t,e){for(var n=[],c=0;c<t.length;c++){var r=t[c],a=e.current;a=Array.isArray(a)?a[0]:a;var s=A5(a,r);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function Ha(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var c=A6(e.inputCoverage,t);if(c===-1)return[];var r=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(r);a.length&&W2(a[0].char);)a.shift();var s=new s2(a,0),i=A6(e.lookaheadCoverage,s),o=[].concat(t.backtrack);for(o.reverse();o.length&&W2(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new s2(o,0),h=A6(e.backtrackCoverage,l),u=c.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var m=e.lookupRecords[d],p=m.lookupListIndex,g=this.getLookupByIndex(p),v=0;v<g.subtables.length;v++){var y=g.subtables[v],b=this.getLookupMethod(g,y),x=this.getSubstitutionType(g,y);if(x==="12")for(var M=0;M<c.length;M++){var S=t.get(M),w=b(S);w&&f.push(w)}}return f}function Oa(t,e){var n=t.current,c=A5(n,e.coverage);if(c===-1)return null;for(var r,a=e.ligatureSets[c],s=0;s<a.length;s++){r=a[s];for(var i=0;i<r.components.length;i++){var o=t.lookahead[i],l=r.components[i];if(o!==l)break;if(i===r.components.length-1)return r}}return null}function Ra(t,e){var n=A5(t,e.coverage);return n===-1?null:e.sequences[n]}X0.prototype.getDefaultScriptFeaturesIndexes=function(){for(var t=this.font.tables.gsub.scripts,e=0;e<t.length;e++){var n=t[e];if(n.tag==="DFLT")return n.script.defaultLangSys.featureIndexes}return[]};X0.prototype.getScriptFeaturesIndexes=function(t){var e=this.font.tables;if(!e.gsub)return[];if(!t)return this.getDefaultScriptFeaturesIndexes();for(var n=this.font.tables.gsub.scripts,c=0;c<n.length;c++){var r=n[c];if(r.tag===t&&r.script.defaultLangSys)return r.script.defaultLangSys.featureIndexes;var a=r.langSysRecords;if(a)for(var s=0;s<a.length;s++){var i=a[s];if(i.tag===t){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};X0.prototype.mapTagsToFeatures=function(t,e){for(var n={},c=0;c<t.length;c++){var r=t[c].tag,a=t[c].feature;n[r]=a}this.features[e].tags=n};X0.prototype.getScriptFeatures=function(t){var e=this.features[t];if(this.features.hasOwnProperty(t))return e;var n=this.getScriptFeaturesIndexes(t);if(!n)return null;var c=this.font.tables.gsub;return e=n.map(function(r){return c.features[r]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};X0.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),c=e.substFormat.toString();return n+c};X0.prototype.getLookupMethod=function(t,e){var n=this,c=this.getSubstitutionType(t,e);switch(c){case"11":return function(r){return Ia.apply(n,[r,e])};case"12":return function(r){return Va.apply(n,[r,e])};case"63":return function(r){return Ha.apply(n,[r,e])};case"41":return function(r){return Oa.apply(n,[r,e])};case"21":return function(r){return Ra.apply(n,[r,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};X0.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,c=this.getFeature({tag:t.tag,script:t.script});if(!c)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var r=this.getFeatureLookups(c),a=[].concat(e.context),s=0;s<r.length;s++)for(var i=r[s],o=this.getLookupSubtables(i),l=0;l<o.length;l++){var h=o[l],u=this.getSubstitutionType(i,h),f=this.getLookupMethod(i,h),d=void 0;switch(u){case"11":d=f(e.current),d&&a.splice(n,1,new i3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new i3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new i3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new i3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new i3({id:21,tag:t.tag,substitution:d}));break}e=new s2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};X0.prototype.supports=function(t){if(!t.script)return!1;this.getScriptFeatures(t.script);var e=this.features.hasOwnProperty(t.script);if(!t.tag)return e;var n=this.features[t.script].some(function(c){return c.tag===t.tag});return e&&n};X0.prototype.getLookupSubtables=function(t){return t.subtables||null};X0.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};X0.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};X0.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var n=this.features[e.script];return n?n.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function Fa(t){var e=t.current,n=t.get(-1);return n===null&&_2(e)||!_2(n)&&_2(e)}function $a(t){var e=t.get(1);return e===null||!_2(e)}var Da={startCheck:Fa,endCheck:$a};function qa(t){var e=t.current,n=t.get(-1);return(_2(e)||W2(e))&&!_2(n)}function Na(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!_2(e)&&!W2(e)):var n=Ta(e);if(!n)return!0;if(n){var c=!1;if(c=t.lookahead.some(function(r){return _2(r)||W2(r)}),!c)return!0}break;default:return!1}}var Ua={startCheck:qa,endCheck:Na};function Ba(t,e,n){e[n].setState(t.tag,t.substitution)}function Ga(t,e,n){e[n].setState(t.tag,t.substitution)}function ja(t,e,n){t.substitution.forEach(function(c,r){var a=e[n+r];a.setState(t.tag,c)})}function _a(t,e,n){var c=e[n];c.setState(t.tag,t.substitution.ligGlyph);for(var r=t.substitution.components.length,a=0;a<r;a++)c=e[n+a+1],c.setState("deleted",!0)}var r8={11:Ba,12:Ga,63:ja,41:_a};function W6(t,e,n){t instanceof i3&&r8[t.id]&&r8[t.id](t,e,n)}function Wa(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var c=e[n],r=K8(c),a=W2(c);if(!r&&!a)return!0;if(r)return!1}return!1}function Xa(t){if(K8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],c=W2(n);if(!c)return!0}return!1}function Za(t){var e=this,n="arab",c=this.featuresTags[n],r=this.tokenizer.getRangeTokens(t);if(r.length!==1){var a=new s2(r.map(function(i){return i.getState("glyphIndex")}),0),s=new s2(r.map(function(i){return i.char}),0);r.forEach(function(i,o){if(!W2(i.char)){a.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;Wa(s)&&(l|=1),Xa(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(c.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof i3&&(W6(f,r,d),a.context[d]=f.substitution)})}}})}}function a8(t,e){var n=t.map(function(c){return c.activeState.value});return new s2(n,e||0)}function Ya(t){var e=this,n="arab",c=this.tokenizer.getRangeTokens(t),r=a8(c);r.context.forEach(function(a,s){r.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:n,contextParams:r});i.length&&(i.forEach(function(o){return W6(o,c,s)}),r=a8(c))})}function Ja(t){var e=t.current,n=t.get(-1);return n===null&&l4(e)||!l4(n)&&l4(e)}function Ka(t){var e=t.get(1);return e===null||!l4(e)}var Qa={startCheck:Ja,endCheck:Ka};function s8(t,e){var n=t.map(function(c){return c.activeState.value});return new s2(n,e||0)}function es(t){var e=this,n="latn",c=this.tokenizer.getRangeTokens(t),r=s8(c);r.context.forEach(function(a,s){r.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:n,contextParams:r});i.length&&(i.forEach(function(o){return W6(o,c,s)}),r=s8(c))})}function l2(t){this.baseDir=t||"ltr",this.tokenizer=new u0,this.featuresTags={}}l2.prototype.setText=function(t){this.text=t};l2.prototype.contextChecks={latinWordCheck:Qa,arabicWordCheck:Da,arabicSentenceCheck:Ua};function C6(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function ts(){return C6.call(this,"latinWord"),C6.call(this,"arabicWord"),C6.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function ns(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var c=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,c.reverse())})}l2.prototype.registerFeatures=function(t,e){var n=this,c=e.filter(function(r){return n.query.supports({script:t,tag:r})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(c):this.featuresTags[t]=c};l2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new X0(t));for(var n=0;n<e.length;n++){var c=e[n];this.query.supports({script:c.script})&&this.registerFeatures(c.script,c.tags)}};l2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function X6(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function cs(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){X6.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(c){Za.call(t,c)})}}function rs(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){X6.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(r){Ya.call(t,r)})}}}function as(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){X6.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(r){es.call(t,r)})}}}l2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};l2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(cs.call(this),rs.call(this)),this.checkContextReady("latinWord")&&as.call(this),this.checkContextReady("arabicSentence")&&ns.call(this)};l2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),ts.call(this),this.applyFeaturesToContexts())};l2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};l2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var c=this.tokenizer.tokens[n];if(!c.state.deleted){var r=c.activeState.value;e.push(Array.isArray(r)?r[0]:r)}}return e};function t0(t){t=t||{},t.tables=t.tables||{},t.empty||(v5(t.familyName,"When creating a new Font object, familyName is required."),v5(t.styleName,"When creating a new Font object, styleName is required."),v5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),v5(t.ascender,"When creating a new Font object, ascender is required."),v5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new x2.GlyphSet(this,t.glyphs||[]),this.encoding=new v8(this),this.position=new k5(this),this.substitution=new W0(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new X8(this)}})}t0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};t0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};t0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};t0.prototype.stringToGlyphs=function(t,e){var n=this,c=new l2,r=function(u){return n.charToGlyphIndex(u.char)};c.registerModifier("glyphIndex",null,r);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;c.applyFeatures(this,a);for(var s=c.getTextGlyphs(t),i=s.length,o=new Array(i),l=this.glyphs.get(0),h=0;h<i;h+=1)o[h]=this.glyphs.get(s[h])||l;return o};t0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};t0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};t0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};t0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};t0.prototype.forEachGlyph=function(t,e,n,c,r,a){e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:72,r=Object.assign({},this.defaultRenderOptions,r);var s=1/this.unitsPerEm*c,i=this.stringToGlyphs(t,r),o;if(r.kerning){var l=r.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,r.language)}for(var h=0;h<i.length;h+=1){var u=i[h];if(a.call(this,u,e,n,c,r),u.advanceWidth&&(e+=u.advanceWidth*s),r.kerning&&h<i.length-1){var f=o?this.position.getKerningValue(o,u.index,i[h+1].index):this.getKerningValue(u,i[h+1]);e+=f*s}r.letterSpacing?e+=r.letterSpacing*c:r.tracking&&(e+=r.tracking/1e3*c)}return e};t0.prototype.getPath=function(t,e,n,c,r){var a=new x0;return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.extend(h)}),a};t0.prototype.getPaths=function(t,e,n,c,r){var a=[];return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.push(h)}),a};t0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};t0.prototype.draw=function(t,e,n,c,r,a){this.getPath(e,n,c,r,a).draw(t)};t0.prototype.drawPoints=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawPoints(t,i,o,l)})};t0.prototype.drawMetrics=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawMetrics(t,i,o,l)})};t0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};t0.prototype.validate=function(){var t=this;function e(c,r){}function n(c){var r=t.getEnglishName(c);r&&r.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};t0.prototype.toTables=function(){return _c.fontToTable(this)};t0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};t0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),c=new Uint8Array(n),r=0;r<e.length;r++)c[r]=e[r];return n};t0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var c=this.toArrayBuffer();if(Xc())if(window.URL=window.URL||window.webkitURL,window.URL){var r=new DataView(c),a=new Blob([r],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(a),s.download=t;var i=document.createEvent("MouseEvents");i.initEvent("click",!0,!1),s.dispatchEvent(i)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var o=w7(),l=Zc(c);o.writeFileSync(t,l)}};t0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};t0.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};t0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function Q8(t,e){var n=JSON.stringify(t),c=256;for(var r in e){var a=parseInt(r);if(!(!a||a<256)){if(JSON.stringify(e[r])===n)return a;c<=a&&(c=a+1)}}return e[c]=t,c}function ss(t,e,n){var c=Q8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:c}]}function is(t,e,n){var c={},r=new f1.Parser(t,e);return c.tag=r.parseTag(),c.minValue=r.parseFixed(),c.defaultValue=r.parseFixed(),c.maxValue=r.parseFixed(),r.skip("uShort",1),c.name=n[r.parseUShort()]||{},c}function os(t,e,n,c){for(var r=Q8(e.name,c),a=[{name:"nameID_"+t,type:"USHORT",value:r},{name:"flags_"+t,type:"USHORT",value:0}],s=0;s<n.length;++s){var i=n[s].tag;a.push({name:"axis_"+t+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return a}function ls(t,e,n,c){var r={},a=new f1.Parser(t,e);r.name=c[a.parseUShort()]||{},a.skip("uShort",1),r.coordinates={};for(var s=0;s<n.length;++s)r.coordinates[n[s].tag]=a.parseFixed();return r}function hs(t,e){var n=new n1.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:t.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:t.instances.length},{name:"instanceSize",type:"USHORT",value:4+t.axes.length*4}]);n.offsetToData=n.sizeOf();for(var c=0;c<t.axes.length;c++)n.fields=n.fields.concat(ss(c,t.axes[c],e));for(var r=0;r<t.instances.length;r++)n.fields=n.fields.concat(os(r,t.instances[r],t.axes,e));return n}function us(t,e,n){var c=new f1.Parser(t,e),r=c.parseULong();z1.argument(r===65536,"Unsupported fvar table version.");var a=c.parseOffset16();c.skip("uShort",1);for(var s=c.parseUShort(),i=c.parseUShort(),o=c.parseUShort(),l=c.parseUShort(),h=[],u=0;u<s;u++)h.push(is(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,m=0;m<o;m++)f.push(ls(t,d+m*l,h,n));return{axes:h,instances:f}}var fs={make:hs,parse:us},ds=function(){return{coverage:this.parsePointer(H.coverage),attachPoints:this.parseList(H.pointer(H.uShortList))}},ms=function(){var t=this.parseUShort();if(z1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},ps=function(){return this.parseList(H.pointer(ms))},gs=function(){return{coverage:this.parsePointer(H.coverage),ligGlyphs:this.parseList(H.pointer(ps))}},vs=function(){return this.parseUShort(),this.parseList(H.pointer(H.coverage))};function ys(t,e){e=e||0;var n=new H(t,e),c=n.parseVersion(1);z1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var r={version:c,classDef:n.parsePointer(H.classDef),attachList:n.parsePointer(ds),ligCaretList:n.parsePointer(gs),markAttachClassDef:n.parsePointer(H.classDef)};return c>=1.2&&(r.markGlyphSets=n.parsePointer(vs)),r}var bs={parse:ys},i2=new Array(10);i2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(H.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(H.coverage),values:this.parseValueRecordList()};z1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};i2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();z1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(H.coverage),r=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,pairSets:this.parseList(H.pointer(H.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(H.classDef),i=this.parsePointer(H.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,H.list(l,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}}))}}};i2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};i2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};i2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};i2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};i2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};i2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};i2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function xs(t,e){e=e||0;var n=new H(t,e),c=n.parseVersion(1);return z1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(i2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(i2),variations:n.parseFeatureVariationsList()}}var Ms=new Array(10);function ws(t){return new n1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new n1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new n1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new n1.LookupList(t.lookups,Ms)}])}var zs={parse:xs,make:ws};function ks(t){var e={};t.skip("uShort");var n=t.parseUShort();z1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var c=t.parseUShort();t.skip("uShort",3);for(var r=0;r<c;r+=1){var a=t.parseUShort(),s=t.parseUShort(),i=t.parseShort();e[a+","+s]=i}return e}function Ss(t){var e={};t.skip("uShort");var n=t.parseULong();n>1&&console.warn("Only the first kern subtable is supported."),t.skip("uLong");var c=t.parseUShort(),r=c&255;if(t.skip("uShort"),r===0){var a=t.parseUShort();t.skip("uShort",3);for(var s=0;s<a;s+=1){var i=t.parseUShort(),o=t.parseUShort(),l=t.parseShort();e[i+","+o]=l}}return e}function Ls(t,e){var n=new f1.Parser(t,e),c=n.parseUShort();if(c===0)return ks(n);if(c===1)return Ss(n);throw new Error("Unsupported kern table version ("+c+").")}var As={parse:Ls};function Cs(t,e,n,c){for(var r=new f1.Parser(t,e),a=c?r.parseUShort:r.parseULong,s=[],i=0;i<n+1;i+=1){var o=a.call(r);c&&(o*=2),s.push(o)}return s}var Ps={parse:Cs};function i8(t,e){for(var n=[],c=12,r=0;r<e;r+=1){var a=f1.getTag(t,c),s=f1.getULong(t,c+4),i=f1.getULong(t,c+8),o=f1.getULong(t,c+12);n.push({tag:a,checksum:s,offset:i,length:o,compression:!1}),c+=16}return n}function Es(t,e){for(var n=[],c=44,r=0;r<e;r+=1){var a=f1.getTag(t,c),s=f1.getULong(t,c+4),i=f1.getULong(t,c+8),o=f1.getULong(t,c+12),l=void 0;i<o?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:i,length:o}),c+=20}return n}function d0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),c=new Uint8Array(e.length);if(zn(n,c),c.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var r=new DataView(c.buffer,0);return{data:r,offset:0}}else return{data:t,offset:e.offset}}function et(t,e){e=e??{};var n,c,r=new t0({empty:!0}),a=new DataView(t,0),s,i=[],o=f1.getTag(a,0);if(o==="\0\0\0"||o==="true"||o==="typ1")r.outlinesFormat="truetype",s=f1.getUShort(a,4),i=i8(a,s);else if(o==="OTTO")r.outlinesFormat="cff",s=f1.getUShort(a,4),i=i8(a,s);else if(o==="wOFF"){var l=f1.getTag(a,4);if(l==="\0\0\0")r.outlinesFormat="truetype";else if(l==="OTTO")r.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+o);s=f1.getUShort(a,12),i=Es(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,m,p,g,v,y,b,x,M,S=0;S<s;S+=1){var w=i[S],z=void 0;switch(w.tag){case"cmap":z=d0(a,w),r.tables.cmap=g8.parse(z.data,z.offset),r.encoding=new y8(r.tables.cmap);break;case"cvt ":z=d0(a,w),M=new f1.Parser(z.data,z.offset),r.tables.cvt=M.parseShortList(w.length/2);break;case"fvar":u=w;break;case"fpgm":z=d0(a,w),M=new f1.Parser(z.data,z.offset),r.tables.fpgm=M.parseByteList(w.length);break;case"head":z=d0(a,w),r.tables.head=C8.parse(z.data,z.offset),r.unitsPerEm=r.tables.head.unitsPerEm,n=r.tables.head.indexToLocFormat;break;case"hhea":z=d0(a,w),r.tables.hhea=P8.parse(z.data,z.offset),r.ascender=r.tables.hhea.ascender,r.descender=r.tables.hhea.descender,r.numberOfHMetrics=r.tables.hhea.numberOfHMetrics;break;case"hmtx":g=w;break;case"ltag":z=d0(a,w),c=T8.parse(z.data,z.offset);break;case"maxp":z=d0(a,w),r.tables.maxp=I8.parse(z.data,z.offset),r.numGlyphs=r.tables.maxp.numGlyphs;break;case"name":b=w;break;case"OS/2":z=d0(a,w),r.tables.os2=R6.parse(z.data,z.offset);break;case"post":z=d0(a,w),r.tables.post=$8.parse(z.data,z.offset),r.glyphNames=new U6(r.tables.post);break;case"prep":z=d0(a,w),M=new f1.Parser(z.data,z.offset),r.tables.prep=M.parseByteList(w.length);break;case"glyf":f=w;break;case"loca":y=w;break;case"CFF ":h=w;break;case"kern":v=w;break;case"GDEF":d=w;break;case"GPOS":m=w;break;case"GSUB":p=w;break;case"meta":x=w;break}}var C=d0(a,b);if(r.tables.name=F8.parse(C.data,C.offset,c),r.names=r.tables.name,f&&y){var k=n===0,T=d0(a,y),q=Ps.parse(T.data,T.offset,r.numGlyphs,k),R=d0(a,f);r.glyphs=j8.parse(R.data,R.offset,q,r,e)}else if(h){var U=d0(a,h);A8.parse(U.data,U.offset,r,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var j=d0(a,g);if(E8.parse(r,j.data,j.offset,r.numberOfHMetrics,r.numGlyphs,r.glyphs,e),Gn(r,e),v){var V=d0(a,v);r.kerningPairs=As.parse(V.data,V.offset)}else r.kerningPairs={};if(d){var Q=d0(a,d);r.tables.gdef=bs.parse(Q.data,Q.offset)}if(m){var W=d0(a,m);r.tables.gpos=zs.parse(W.data,W.offset),r.position.init()}if(p){var o1=d0(a,p);r.tables.gsub=D8.parse(o1.data,o1.offset)}if(u){var m1=d0(a,u);r.tables.fvar=fs.parse(m1.data,m1.offset,r.names)}if(x){var I=d0(a,x);r.tables.meta=q8.parse(I.data,I.offset),r.metas=r.tables.meta}return r}var y4=class{constructor(e,n){this.sources=e;this.fallback=n;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let n=e||this.fallback||Object.keys(this.sources)[0];if(!n)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let c=this.parsed.get(n);if(c)return c;let r=G0(this.sources,n);if(!r)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let a=r instanceof Uint8Array?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r,s=et(a);return this.parsed.set(n,s),s}};function Ts(t,e,n){let c={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,c).commands,advance:t.getAdvanceWidth(e,n.size,c)};let r=[],a=0,s=[...e];return s.forEach((i,o)=>{r.push(...t.getPath(i,a,0,n.size,c).commands),a+=t.getAdvanceWidth(i,n.size,c)*(o<s.length-1?n.spacing:1)}),{cmds:r,advance:a}}function tt(t,e,n){let{cmds:c,advance:r}=Ts(t,e,n),a=c.map(i=>i.type==="Z"?i:i.type==="C"?{...i,y1:-i.y1,y2:-i.y2,y:-i.y}:i.type==="Q"?{...i,y1:-i.y1,y:-i.y}:{...i,y:-i.y}),s=E3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:r}}function b4(t,e,n){if(!e)return[];let c=t.get(n.font),{polys:r,advance:a}=tt(c,e,n),s=w1(r),i=k0(s);if(!i)return[];let o=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-i[3]:n.valign==="center"?-(i[1]+i[3])/2:n.valign==="bottom"?-i[1]:0;return s.map(h=>h.map(([u,f])=>[u+o,f+l]))}function Z6(t,e,n){let c=t.get(n.font),{polys:r,advance:a}=tt(c,e,n),s=k0(r)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:c.ascender/c.unitsPerEm*n.size,descent:c.descender/c.unitsPerEm*n.size}}var nt=128,x4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],rt={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Is(t,e){if(!t||G0(K6,t)!==void 0||e.startsWith("/"))return;let n=t.lastIndexOf("/");if(n<0)return;let c=[...t.slice(0,n).split("/"),...e.split("/")],r=[];for(let a of c)a===".."&&r.length&&r[r.length-1]!==".."?r.pop():a!=="."&&a!==""&&r.push(a);return(t.startsWith("/")?"/":"")+r.join("/")}var Vs=100,Hs={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},$3=4,ct=8,Os=t=>{let e=Vs,n=c=>{for(let r of c.values()){for(let a of r.regions)e+=a.length;for(let a of r.lines)e+=a.length}};n(t.layers);for(let c of t.parts)n(c.layers);return e},E0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,c=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=c?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let c=n.fns.get(e);if(c)return c}}mod(e){for(let n=this;n;n=n.parent){let c=n.mods.get(e);if(c)return c}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let c=this;c;c=c.parent)n.push(...c[e].keys());return n}},Y6=t=>t?`.${t}`:"",J6=["echo","assert","text_width","text_metrics","finger_count"];function l3(t,e){let n="",c=Math.min(2,Math.floor(t.length/3))+.5;for(let r of new Set(e)){if(r===t)continue;let a=r.toLowerCase()===t.toLowerCase()?0:Rs(t,r);a<c&&([n,c]=[r,a])}return n?` Did you mean "${n}"?`:""}function Rs(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(c,r)=>[r,...Array(e.length).fill(0)]);for(let c=1;c<=e.length;c++)n[0][c]=c;for(let c=1;c<=t.length;c++)for(let r=1;r<=e.length;r++)n[c][r]=Math.min(n[c-1][r]+1,n[c][r-1]+1,n[c-1][r-1]+(t[c-1]===e[r-1]?0:1)),c>1&&r>1&&t[c-1]===e[r-2]&&t[c-2]===e[r-1]&&(n[c][r]=Math.min(n[c][r],n[c-2][r-2]+1));return n[t.length][e.length]}var K6=g5,D3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.pointCount=0;this.itemCount=0;this.copies=0;this.frame=l6;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(x4.map(e=>[e.name,e]));this.loaded=new Map;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...rt,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new E0,c={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[i,o]of Object.entries(c))n.vars.set(i,o);let r=new E0(n),a=this.block(e.body,r,!0),s=r.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${P2(this.unscaled,!1)})`),{shape:a,globals:r,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new i1(`Stopped after ${this.maxSteps} steps. Is there an endless loop?`,e)}load(e,n){let c=Is(n.file,e),r=e,a=G0(K6,e);if(a===void 0&&c!==void 0){let i=this.loaded.get(c);if(i)return i;a=this.opts.resolve?.(c),typeof a=="string"&&(r=c)}if(r===e){let i=this.loaded.get(e);if(i)return i;a??(a=this.opts.resolve?.(e))}if(typeof a!="string")throw new i1(`Library <${e}> not found`,n);this.loaded.set(r,{body:[]});let{program:s}=r2(a,r);return this.loaded.set(r,s),s}hoist(e,n){for(let c of e)if((c.kind==="module"||c.kind==="function")&&(c.pos.file===void 0||G0(K6,c.pos.file)===void 0)&&(c.kind==="module"?G0(this.builtins,c.name)!==void 0:G0(h5,c.name)!==void 0||J6.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${P2(c.pos,!1)})`),c.kind==="module")n.mods.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="function")n.fns.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="use"&&!c.include){this.enter(this.using,c.path,c.pos,"use");try{let r=this.included(this.load(c.path,c.pos).body,new Set([c.path])),a=new E0(n);this.hoist(r,a);for(let s of r)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,i]of a.mods)n.mods.set(s,i);for(let[s,i]of a.fns)n.fns.set(s,i)}finally{this.using.pop()}}}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let r=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,i=[];for(let l=r.length-1;l>=0;l--)i.push({text:";"},r[l][1],{text:`${r[l][0]}=`});for(;i.length;){if(s>2e4)return"";let l=i.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){i.push({text:"]"});for(let u=l.length-1;u>=0;u--)i.push(l[u],{text:","});h="["}else if(Q0(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(R0(l)){i.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)i.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";a.push(h),s+=h.length}let o=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies}`}enter(e,n,c,r){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new i1(a.length===2?`Library ${a[0]} ${r}s itself`:`Libraries ${r} each other in a loop: ${a.join(" \u2192 ")}`,c)}e.push(n)}included(e,n){let c=[];for(let r of e)if(r.kind!=="use"||!r.include)c.push(r);else if(!n.has(r.path)){n.add(r.path);for(let a of this.included(this.load(r.path,r.pos).body,n))c.push(a)}return c}assign(e,n,c){c.vars.set(e,n)}block(e,n,c=!1){this.hoist(e,n);let r=[];for(let a of e){let s=this.stmt(a,n,c);s&&!Be(s)&&r.push(s)}return r.length===1?r[0]:q2(r)}stmt(e,n,c=!1){switch(this.tick(e.pos),e.kind){case"assign":{let r=this.opts.overrides,a=c&&r&&Object.prototype.hasOwnProperty.call(r,e.name)?r[e.name]:this.expr(e.value,n);return this.assign(e.name,a,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new E0(n));case"if":return h0(this.expr(e.cond,n))?this.block(e.then,new E0(n)):this.block(e.else,new E0(n));case"let":{let r=new E0(n);return this.bindSeq(e.assigns,r),this.block(e.body,r)}case"for":{let r=[];return this.loop(e.assigns,n,a=>r.push(this.block(e.body,a))),q2(r)}case"call":if(e.modifier==="*")return null;{let r=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?i5(r,"guide"):r}}}bindSeq(e,n){for(let c of e)this.assign(c.name,this.expr(c.value,n),n)}iterable(e,n){if(Q0(e))try{return Q5(e,this.limits.maxListLength)}catch(c){throw new i1(c.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,c,r=0,a=new E0(n)){if(r===e.length)return c(a);let s=e[r];for(let i of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let o=new E0(a);o.vars.set(s.name,i),this.loop(e,n,c,r+1,o)}}evalArgs(e,n,c){let r=[],a=new Map,s=[];for(let i of e){let o=this.expr(i.value,n);i.name===null?r.push(o):a.set(i.name,o),s.push({name:i.name,value:o})}return{pos:r,named:a,all:s,at:c}}bindParams(e,n,c,r,a){let s=e.map(i=>i.name);e.forEach((i,o)=>{let l;n.named.has(i.name)?l=n.named.get(i.name):o<n.pos.length?l=n.pos[o]:l=i.default?this.expr(i.default,c):void 0,c.vars.set(i.name,l)});for(let i of n.named.keys())i.startsWith("$")?c.vars.set(i,n.named.get(i)):s.includes(i)||this.unknownArg(a,i,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let c=p5(e);if(!c)return;let r=c.params.map(a=>a.name);if(!c.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!r.includes(a)&&this.unknownArg(`${e}()`,a,n.at,r);c.rest||this.checkCount(`${e}()`,c.params.filter(a=>!a.named).length,n)}checkCount(e,n,c){c.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${c.pos.length}; the rest are ignored (${P2(c.at,!1)})`)}unknownArg(e,n,c,r){this.warn(`${e}: unknown argument "${n}"${Y6(l3(n,r))} (${P2(c,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let c=e.args.findIndex(s=>s.name==="name"),r=c>=0?c:e.args.findIndex(s=>s.name===null);if(r<0)throw new i1("call() needs the name of a module",e.pos);let a=this.expr(e.args[r].value,n);if(typeof a!="string")throw new i1(`call() needs a module's name as a string, got ${j0(a)}`,e.pos);if(a==="call")throw new i1("call() can't call itself",e.pos);return this.callModule({...e,name:a,args:e.args.filter((s,i)=>i!==r)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let c=this.evalArgs(e.args,n,e.pos),r=n.mod(e.name);if(r){if(++this.depth>1e3)throw new i1(`Recursion too deep in module ${e.name}(): it calls itself without stopping`,e.pos);try{let f=new E0(r.env,n);return this.bindParams(r.params,c,f,r.env,`${e.name}()`),f.children={stmts:e.children,env:n},f.vars.set("$children",this.childStmts(e.children).length),this.block(r.body,f)}catch(f){throw this.inCall(f,"module",e.name,e.pos)}finally{this.depth--}}let a=G0(this.builtins,e.name);if(!a){let f=e.name==="color"?" Use layer(), cut(), score() or engrave() instead.":l3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new i1(`Unknown module ${e.name}().${f}`,e.pos)}this.checkArgs(e.name,c);let s=new E0(n,n);for(let[f,d]of c.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new E0(n,s),l={args:c,env:s,children:()=>e.children.length?this.block(e.children,o()):J0(),childList:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let m of e.children){let p=this.stmt(m,f);i.includes(m)&&d.push(p??J0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let m=[];for(let p of e.children){let g=this.stmt(p,d);i.includes(p)&&(m.push(g??J0()),f(m.length-1,g??J0()))}return m}},h;try{h=a(l)}catch(f){if(f instanceof i1||f instanceof RangeError)throw f;let d=new i1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=Os(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new i1(u>this.limits.maxPoints?`The shapes have more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes, or a lower $fn.`:`Making the shapes took more than ${this.limits.maxPoints*10} points of work, the limit. Use fewer or simpler shapes, or a lower $fn.`,e.pos);return h}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,c,r){if(++this.depth>2e3)throw new i1(`Recursion too deep in ${r}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=A2(e)?e.scope:e.env,s=new E0(a,c);return this.bindParams(e.params,n,s,a,`${r}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",r,n.at)}finally{this.depth--}}inCall(e,n,c,r){return e instanceof Error&&!(e instanceof i1)&&e.message.includes("call stack")?new i1(`Recursion too deep in ${n==="module"?"module ":""}${c}(): it calls itself without stopping`,r):(e instanceof i1&&e.addFrame(n,c,r),e)}expr(e,n){switch(e.kind){case"num":return e.unit?this.length(e,n):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{let c=n.get(e.name);if(c.found)return c.value;let r=n.fn(e.name);if(r)return{type:"function",params:r.params,body:r.body,scope:r.env,name:e.name};if(e.name.startsWith("$"))return;throw new i1(`Unknown variable "${e.name}"${Y6(l3(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let c=[];for(let r of e.items)this.listItem(r,n,c,e.pos);return this.charge($3,e.pos),c}case"range":{let c=this.expr(e.start,n),r=this.expr(e.end,n),a=e.step?this.expr(e.step,n):1;if(typeof c!="number"||typeof r!="number"||typeof a!="number")throw new i1("Range values must be numbers",e.pos);return{type:"range",start:c,step:a,end:r}}case"unary":{let c=this.expr(e.arg,n);return e.op==="!"?!h0(c):e.op==="+"?c:this.arith("*",-1,c,e.pos)}case"binary":{if(e.op==="&&")return h0(this.expr(e.left,n))&&h0(this.expr(e.right,n));if(e.op==="||")return h0(this.expr(e.left,n))||h0(this.expr(e.right,n));let c=this.expr(e.left,n),r=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return C3(c,r,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof c=="number"&&typeof r=="number"||typeof c=="string"&&typeof r=="string"))throw new i1(`Can't compare ${j0(c)} ${e.op} ${j0(r)}`,e.pos);return e.op==="<"?c<r:e.op==="<="?c<=r:e.op===">"?c>r:c>=r}return this.arith(e.op,c,r,e.pos)}case"ternary":return h0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let c=this.expr(e.target,n),r=this.expr(e.index,n);if(R0(c)&&typeof r=="string")return c.fields.get(r);if(typeof r!="number")throw new i1(`List index must be a number, got ${j0(r)}`,e.pos);return Array.isArray(c)?c[Math.floor(r)]:typeof c=="string"?[...c][Math.floor(r)]:Q0(c)?[c.start,c.step,c.end][Math.floor(r)]:void 0}case"record":return this.record(e,n);case"member":{let c=this.expr(e.target,n);if(R0(c))return c.fields.get(e.name);let r={x:0,y:1,z:2}[e.name];return Array.isArray(c)&&r!==void 0?c[r]:Q0(c)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?c.start:e.name==="step"?c.step:c.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let c=new E0(n);return this.bindSeq(e.assigns,c),this.expr(e.body,c)}}}listItem(e,n,c,r){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(c,1,r),c.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),r);this.grow(c,a.length,r);for(let s of a)c.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,c,r));return;case"if":h0(this.expr(e.cond,n))?this.listItem(e.then,n,c,r):e.else&&this.listItem(e.else,n,c,r);return;case"let":{let a=new E0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,c,r)}}}grow(e,n,c){if(e.length+n>this.limits.maxListLength)throw new i1(`a list of ${e.length+n} items is more than the limit of ${this.limits.maxListLength}`,c);this.charge(n,c)}charge(e,n){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new i1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let r=e.callee.name,a=n.get(r),s=a.found&&!A2(a.value);if(!a.found||s&&this.callable(r,n)){let i=n.fn(r);if(i)return this.callFunction(i,this.evalArgs(e.args,n,e.pos),n,r);let o=this.specialFunction(r,e,n);if(o.handled)return o.value;let l=G0(h5,r);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(r,h);for(let m of d7(l,h.pos,h.named))this.warn(`${r}(): "${m}" is given by position and by name; the named value is used (${P2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:m=>this.tick(e.pos,m),given:h.pos.length+l.params.filter(m=>h.named.has(m)).length},f=m7(l,h.pos,h.named);this.tick(e.pos,p7(r,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof i1)throw m;let p=new i1(m instanceof RangeError?`${r}(): the result is too large`:m.message,e.pos);throw p.call=r,p}return this.checkValue(d,e.pos,r),d}throw new i1(`Unknown function ${r}()${Y6(l3(r,[...n.names("fns"),...n.names("vars"),...Object.keys(h5),...J6]))}`,e.pos)}if(!A2(a.value))throw new i1(`"${r}" is a ${j0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,r)}let c=this.expr(e.callee,n);if(!A2(c))throw new i1(`Can't call a ${j0(c)}`,e.pos);return this.callFunction(c,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,c,r){let a=s=>Array.isArray(c)?String(c[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let i=a(s),o=w1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||y0(n[s],o).reduce((h,u)=>h+Math.abs(H1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(c)&&i?` "${i}"`:""} under it, so it can't be seen (${P2(r,!1)})`)}}record(e,n){let c=new Map;for(let r of e.fields)c.set(r.name,this.expr(r.value,n));return{type:"record",fields:c}}length(e,n){let c=A0(n.get("$scale").value??1);if(!(c>0))throw new i1("$scale must be a number more than 0",e.pos);return c===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Hs[e.unit]/c}callable(e,n){return!!n.fn(e)||J6.includes(e)||!!G0(h5,e)}specialFunction(e,n,c){if(e==="echo"){let r=this.evalArgs(n.args,c,n.pos);return this.echo(this.echoText(r),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let r=this.evalArgs(n.args,c,n.pos);return this.checkArgs(e,r),this.assert(r),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"){let r=this.evalArgs(n.args,c,n.pos);this.checkArgs(e,r);let a=this.measure(r,c);return e==="text_width"?{handled:!0,value:a.advance}:{handled:!0,value:[a.advance,a.bounds,a.ascent,a.descent]}}if(e==="finger_count"){let r=this.evalArgs(n.args,c,n.pos);this.checkArgs(e,r);let a=this.num(this.arg(r,"length",0),"finger_count","length");return{handled:!0,value:c3(a,this.fingerWidth(r,c,1))}}return{handled:!1}}assert(e){if(h0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new i1(`Assertion failed${n===void 0?"":": "+L0(n)}`,e.at)}echo(e,n){this.charge(Math.ceil(e.length/ct),n),this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,c=[],r=0,a=(s,i,o)=>{c.length&&(r+=2);let l=P3(i,n-r-s.length,o);if(r+=s.length+l.text.length,!l.whole)throw new i1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);c.push(s+l.text)};for(let{name:s,value:i}of e.all)s===null?a("",i,!1):a(`${s} = `,i,!0);return c.join(", ")}arith(e,n,c,r){if(typeof n=="number"&&typeof c=="number")switch(e){case"+":return n+c;case"-":return n-c;case"*":return n*c;case"/":return n/c;case"%":return n%c;case"^":return Math.pow(n,c)}if(e==="+"&&typeof n=="string"&&typeof c=="string")return this.checkSize(n.length+c.length,!0,r),n+c;if(Array.isArray(n)&&Array.isArray(c)){if(e==="+"||e==="-"){if(n.length!==c.length)throw new i1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${c.length}`,r);return this.charge(n.length+$3,r),n.map((s,i)=>this.arith(e,s,c[i],r))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+$3,r),n.map(i=>this.arith("*",i,c,r));let s=(i,o)=>{let l=this.arith("*",i,o,r);if(typeof l!="number")throw new i1("Can't multiply these lists: an item times an item is not a number",r);return l};if(Array.isArray(c[0])){let i=c[0].length;if(n.length!==c.length||c.some(o=>!Array.isArray(o)||o.length!==i))throw new i1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,r);return this.checkSize(i,!1,r),this.tick(r,i*n.length),Array.from({length:i},(o,l)=>n.reduce((h,u,f)=>h+s(u,c[f][l]),0))}if(n.length!==c.length)throw new i1(`Can't multiply lists of length ${n.length} and ${c.length}`,r);return this.tick(r,n.length),n.reduce((i,o,l)=>i+s(o,c[l]),0)}}if(Array.isArray(n)&&typeof c=="number"&&(e==="*"||e==="/"))return this.charge(n.length+$3,r),n.map(s=>this.arith(e,s,c,r));if(typeof n=="number"&&Array.isArray(c)&&e==="*")return this.charge(c.length+$3,r),c.map(s=>this.arith(e,n,s,r));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new i1(`Can't ${a[e]??e} ${j0(n)} and ${j0(c)}`,r)}arg(e,n,c,r){return e.named.has(n)?e.named.get(n):c>=0&&c<e.pos.length?e.pos[c]:r}num(e,n,c){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${c} must be a finite number, got ${_0(e)}`);return e}vec2(e,n,c=!0){let r=a=>typeof a=="number"&&Number.isFinite(a);if(r(e)&&c)return[e,e];if(Array.isArray(e)&&r(e[0])&&(e[1]===void 0||r(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${_0(e)}`)}vec3(e,n){let c=r=>typeof r=="number"&&Number.isFinite(r);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(c))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${_0(e)}`)}placements(e,n,c){let r=(i,o)=>i===void 0?[[0,0,0]]:Array.isArray(i)&&i.length>0&&Array.isArray(i[0])?i.map((l,h)=>this.vec3(l,`${o}[${h}]`)):[this.vec3(i,o)],a=r(e,"at"),s=r(n,"rotate");for(let[i,o]of[[a,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==c)throw new Error(`${o} needs one placement per copy: qty is ${c} but ${o} has ${i.length}`);return Array.from({length:c},(i,o)=>({at:a[a.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((c,r)=>{if(!Array.isArray(c)||!Number.isFinite(c[0])||!Number.isFinite(c[1]))throw new Error(`${n}[${r}] must be an [x, y] point, got ${_0(c)}`);return[c[0],c[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,c){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,c)}checkSize(e,n,c,r){if(e>this.limits.maxListLength)throw new i1(`${r?`${r}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,c);this.charge(n?Math.ceil(e/ct):e+$3,c)}segs(e){let n=A0(this.dyn(e,"$fn"))||0,c=A0(this.dyn(e,"$fa"))||2,r=A0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let i=_e(s,n,c,r);if(!(i<=a))throw new Error(`a circle with ${i} segments is more than the limit of ${a}. Lower $fn, or raise $fa or $fs.`);return i}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||n<=0)throw new Error("$thickness must be a positive number");return n}fingerWidth(e,n,c){let r=this.arg(e,"finger",c);return typeof r=="number"&&r>0?r:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new i1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let c=P3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!c.whole)throw new i1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,c.text.length);try{return Z6(this.opts.fonts,c.text,this.textOpts(e,n,c.text))}catch(r){throw r instanceof i1?r:new i1(r.message,e.at)}}textOpts(e,n,c){let r={size:this.num(this.arg(e,"size",1,10),"text","size"),font:L0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:L0(this.arg(e,"halign",-1,"left")),valign:L0(this.arg(e,"valign",-1,"baseline")),spacing:A0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&c!==void 0&&this.opts.fonts){let s=this.num(a,"text","fit");if(!(s>0))throw new Error("fit must be a width more than 0");let i=Z6(this.opts.fonts,c,{...r,size:1}).advance;if(i>0){let o=this.arg(e,"size",1);r.size=o===void 0?s/i:Math.min(r.size,s/i)}}return r}edges(e){let n=c=>{if(c==="out"||c==="in"||c==="flat")return c;throw new Error(`edges must be "out", "in" or "flat", got ${_0(c)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,c=this.layers.get(n);if(c&&c.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!c){let r=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...r,name:n,side:"back"})}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((c,r)=>{if(!Array.isArray(c)||c.length!==3||!c.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${_0(c)}${n.length>1?` at ${r}`:""}`);let[a,s,i]=c;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${_0(c)}`);return{x0:a,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>z3(s.children(),i),n=s=>i=>i5(i.children(),s),c=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${_0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!h0(this.dyn(i.env,"$mirrored"))),i5(i.children(),o==="back"?this.backLayer(s):s)};return{rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0,1),"size"),l=A0(this.arg(s.args,"r",-1,0))||0,h=h0(this.arg(s.args,"center",1,!1)),u=We(i,o,l,this.segs(s.env));return z0(w1([h?u.map(([f,d])=>[f-i/2,d-o/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let i=this.arg(s.args,"d",-1),o=i!==void 0?this.num(i,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return z0([k3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return z0([k3(i,o,this.segs(s.env)(Math.max(i,o)))])},regular_polygon:s=>{let i=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),o=this.num(this.arg(s.args,"r",1,10),"regular_polygon","r");if(!(i<=this.limits.maxSegments))throw new Error(`${i} corners is more than the limit of ${this.limits.maxSegments}`);return z0([k3(o,o,i)])},star:s=>{let i=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),o=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.args,"inner",2,o*.45),"star","inner");if(!(i*2<=this.limits.maxSegments))throw new Error(`${i} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<i*2;u++){let f=Math.PI/2+Math.PI*u/i,d=u%2?l:o;h.push([d*Math.cos(f),d*Math.sin(f)])}return z0(w1([h]))},polygon:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"paths",1),l=Array.isArray(o)?o.map(h=>(Array.isArray(h)?h:[]).map(u=>i[A0(u)]).filter(Boolean)):[i];return z0(w1(l,"evenodd"))},path:s=>{let i=this.arg(s.args,"d",0);if(typeof i!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let o=E3(T3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return h0(this.arg(s.args,"close",-1,!1))?z0(w1([...o.closed,...o.open.filter(h=>h.length>2)],l)):q2([z0(w1(o.closed,l)),D2(o.open)])},line:s=>{let i=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),o=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return D2([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!u)return J0();let f=-(o[1]-i[1])/u*(h/2),d=(o[0]-i[0])/u*(h/2);return z0(w1([[[i[0]+f,i[1]+d],[i[0]-f,i[1]-d],[o[0]-f,o[1]-d],[o[0]+f,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=h0(this.arg(s.args,"closed",1,!1));return D2([o&&i.length?[...i,i[0]]:i])},arc:s=>{let i=this.num(this.arg(s.args,"r",0,10),"arc","r"),o=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.env)(i)*Math.abs(l-o)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(o+(l-o)*f/h)*Math.PI/180;u.push([i*Math.cos(d),i*Math.sin(d)])}return D2([u])},text:s=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let i=this.arg(s.args,"text",0,""),o=P3(i,this.limits.maxTextLength);if(!o.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(s.args.at,o.text.length);let l=b4(this.opts.fonts,o.text,this.textOpts(s.args,s.env,o.text));if(h0(this.dyn(s.env,"$mirrored"))){let[h,u]=[1/0,-1/0];for(let f of l)for(let[d]of f)[h,u]=[Math.min(h,d),Math.max(u,d)];return z0(w1(l.map(f=>f.map(([d,m])=>[h+u-d,m]))))}return z0(l)},translate:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,i,o])},rotate:s=>{let i=this.arg(s.args,"a",0,0),l=(Array.isArray(i)?A0(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[m,p]=this.vec2(f,"center",!1);d=[h,u,-u,h,m-h*m+u*p,p-u*m-h*p]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,u=o/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let i=this.arg(s.args,"m",0);if(!Array.isArray(i)||i.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let o=i[0],l=i[1];return e(s,[o[0],l[0],o[1],l[1],o[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[i,...o]=s.childList();if(!i)return J0();let l=r(o,"difference");return a(i,h=>({regions:y0(h.regions,l.regions),lines:g2(h.lines,w1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return J0();let o=m=>[...m.layers.values()].some(p=>p.regions.length),l=m=>{let p;for(let g of i){if(g===m||!o(g))continue;let v=w1(r([g],"intersection").regions);p=p?b0(p,v):v}return p},h=i[0],u=i.every(o),f=l(h),d=a(h,m=>({regions:u?f?b0(m.regions,f):m.regions:[],lines:f?g2(m.lines,f,"inside"):m.lines}));for(let m of i){if(m===h)continue;if(m.parts.length)throw new Error("part() can only be the first child of intersection()");let p=l(m),g=new Map;for(let[v,y]of m.layers)y.lines.length&&g.set(v,{regions:[],lines:p?g2(y.lines,p,"inside"):y.lines});g.size&&(d=q2([d,{layers:g,parts:[]}]))}return d},hull:s=>{let i=s.children(),o=l=>{let h=[],u="cut",f=!0;for(let[m,p]of l){f&&(p.regions.length||p.lines.length)&&(u=m,f=!1);for(let g of[...p.regions,...p.lines])for(let v of g)h.push(v)}let d=je(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:o(i.layers),parts:i.parts.map(l=>({...l,layers:o(l.layers)}))}},offset:s=>{let i=this.arg(s.args,"r",0),o=this.arg(s.args,"delta",-1),l=h0(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),u=i!==void 0?"round":l?"square":"miter";return a(s.children(),f=>({regions:p0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[i,o]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(i>0&&o>0))throw new Error("spacing must be more than 0");let[h,...u]=s.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=w1(r(u,"pattern").regions),d=$0(h.layers),m=k0(f);if(!d||!m)return J0();let p=Math.floor((m[1]-d[3])/o),g=Math.ceil((m[3]-d[1])/o),v=Math.floor((m[0]-d[2])/i)-1,y=Math.ceil((m[2]-d[0])/i)+1,b=(g-p+1)*(y-v+1);if(!(b<=this.limits.maxParts*10))throw new Error(`the pattern would have ${b} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(s.args.at,b);let x=B0(f).map(C=>({polys:C,box:k0(C)})),M=f,S=(C,k)=>{let T=0;for(let q of M)for(let R=0,U=q.length-1;R<q.length;U=R++){let[j,V]=q[U],[Q,W]=q[R];V<=k?W>k&&(Q-j)*(k-V)-(C-j)*(W-V)>0&&T++:W<=k&&(Q-j)*(k-V)-(C-j)*(W-V)<0&&T--}return T!==0},w=new Map,z=(C,k)=>{let T=w.get(C)??{regions:[],lines:[]};for(let q of k.regions)T.regions.push(q);for(let q of k.lines)T.lines.push(q);w.set(C,T)};for(let C=p;C<=g;C++)for(let k=v;k<=y;k++){let T=k*i+(C%2?l*i:0),q=C*o,R=[d[0]+T,d[1]+q,d[2]+T,d[3]+q];if(R[2]<m[0]||R[0]>m[2]||R[3]<m[1]||R[1]>m[3])continue;let U=x.filter(o1=>!(R[2]<o1.box[0]||R[0]>o1.box[2]||R[3]<o1.box[1]||R[1]>o1.box[3]));if(!U.length)continue;M=U.length===x.length?f:U.flatMap(o1=>o1.polys);let j=[S(R[0],R[1]),S(R[2],R[1]),S(R[2],R[3]),S(R[0],R[3])],V=M.some(o1=>o1.some(([m1,I])=>m1>R[0]&&m1<R[2]&&I>R[1]&&I<R[3])),Q=j.every(Boolean)&&!V,W=[1,0,0,1,T,q];for(let[o1,m1]of z3({layers:h.layers,parts:[]},W).layers)z(o1,Q?m1:{regions:b0(m1.regions,M),lines:g2(m1.lines,M,"inside")})}return{layers:w,parts:[]}},spline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=h0(this.arg(s.args,"closed",-1,!1));if(!(i.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=p6(i,l,h);if(o===void 0)return D2([u]);let f=this.num(o,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return z0(w1(j5([u],f)))},hatch:s=>{let i=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),o=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(o>0))throw new Error("pitch must be more than 0");let h=w1(r([s.children()],"hatch").regions),u=k0(h);if(!u)return J0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],m=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,p=i*Math.PI/180,[g,v]=[Math.cos(p),Math.sin(p)],[y,b]=[-v,g],x=Math.ceil(m/o);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let M=[],S=Math.round((f*y+d*b)/o);for(let z=S-x;z<=S+x;z++){let C=z*o-(f*y+d*b),[k,T]=[f+y*C,d+b*C];M.push([[k-g*m,T-v*m],[k+g*m,T+v*m]])}if(l===void 0)return D2(g2(M,h,"inside"));let w=this.num(l,"hatch","width");if(!(w>0))throw new Error("width must be more than 0");return z0(b0(w1(j5(M,w).map(z=>z)),h))},paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],u=[];for(let f=o.length-1;f>=0;f--){let d=o[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let m=h,p=w1(r([d],"paint").regions);u[f]=p,h=m.length?w1([...m,...p]):p;let g=Array.isArray(i)?i[f]:void 0;g!==""&&(g!==void 0?(this.layers.has(g)||this.layers.set(g,{name:g,mode:"fill",color:"#000000"}),l.push(z0(m.length?y0(p,m):p,g))):l.push(m.length?a(d,v=>({regions:y0(v.regions,m),lines:g2(v.lines,m,"outside")})):d))}return this.invisiblePaint(o,u,i,s.args.at),q2(l.reverse())},measure:s=>{let i=h0(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let u=$0(h.layers)??k0(h.parts.flatMap(f=>[...f.layers.values()].flatMap(d=>[...d.regions,...d.lines])));s.env.vars.set("$bounds",u?[...u]:void 0)});return q2(i?o:o.slice(1))},fill_holes:s=>{let i=this.arg(s.args,"min_area",0),o=i===void 0?1/0:this.num(i,"fill_holes","min_area");return a(s.children(),l=>({regions:w1(l.regions).filter(h=>!(H1(h)<0&&-H1(h)<o)),lines:l.lines}))},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),o=>({regions:p0(p0(o.regions,i,"round"),-i,"round"),lines:o.lines}))},stroke:s=>{let i=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),o=>({regions:w1([...o.regions,...j5(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...w1(i.regions).map(o=>[...o,o[0]])]})),cut:n("cut"),score:c("score"),engrave:c("engrave"),guide:n("guide"),layer:s=>{let i=this.arg(s.args,"name",0);if(typeof i!="string"||!i)throw new Error("layer() needs a name");let o=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(i),u=this.arg(s.args,"order",-1),f=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${i}" is the back of layer "${i.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let m=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(m))throw new Error('mode must be "cut", "line", "fill" or "guide"');let p=L0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(p))throw new Error('color must look like "#00aa00"');let g=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&m==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:m,color:p,...g!==void 0&&{order:g},...v!==void 0&&{bleed:v}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${_0(d)}`);if(d==="back"&&this.layers.get(i)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&s.env.vars.set("$mirrored",!h0(this.dyn(s.env,"$mirrored"))),i5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=L0(this.arg(s.args,"name",0,"part")),o=Math.max(1,Math.floor(A0(this.arg(s.args,"qty",1,1))||1)),l=this.arg(s.args,"stack",-1),h=l===void 0?1:Math.floor(this.num(l,"part","stack"));if(!(h>=1))throw new Error("stack must be 1 or more");if(this.copies+=o*h,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let u=this.arg(s.args,"at",-1),f=this.arg(s.args,"rotate",-1),d=this.arg(s.args,"glue",-1),m=d===void 0?void 0:L0(d),p=L0(this.arg(s.args,"face",-1,"top"));if(p!=="top"&&p!=="bottom")throw new Error(`face must be "top" or "bottom", got ${_0(p)}`);let g=this.frame!==l6&&m===void 0,v=this.arg(s.args,"bend",-1),y=u===void 0&&f===void 0&&!g&&m===void 0&&v===void 0?void 0:this.placements(u,f,o),b=this.thickness(s.env);y&&(g||h>1)&&(y=y.flatMap(W=>{let o1=m===void 0?$1(this.frame,K0(W)):K0(W),m1=m!==void 0&&p==="bottom"?-b:b;return Array.from({length:h},(I,$)=>({...W,matrix:$1(o1,D0(0,0,$*m1))}))}));let x=this.arg(s.args,"mirror",-1,!1),M;if(Array.isArray(x)){if(x.length!==o)throw new Error(`mirror needs one true or false per copy: qty is ${o} but mirror has ${x.length}`);M=x.map(W=>h0(W))}else M=Array.from({length:o},()=>h0(x));let S=M.some(W=>W)&&!M.every(W=>W);if(S&&m!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let w=M[0],z=W=>{let o1=s.env.vars.get("$mirrored"),m1=s.env.vars.has("$mirrored");W&&s.env.vars.set("$mirrored",!0);try{let I=s.children();return W?z3(I,[-1,0,0,1,0,0]):I}finally{W&&(m1?s.env.vars.set("$mirrored",o1):s.env.vars.delete("$mirrored"))}},C=z(w),k=this.bends(v),T=this.arg(s.args,"on",-1),q=this.arg(s.args,"slots",-1),R=q===void 0?void 0:(Array.isArray(q)?q:[q]).map(W=>{if(typeof W!="string")throw new Error("slots must be part names");return W}),U=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),j=(W,o1,m1)=>{let I=m1.length===o,$=y?.filter((Z,_)=>m1.includes(Math.floor(_/h)+1));return{name:i,qty:m1.length*h,layers:W,thickness:b,kerf:A0(this.dyn(s.env,"$kerf"))||0,material:L0(this.dyn(s.env,"$material")??"material"),...$?{placements:$}:{},...h>1?{stack:h}:{},...k.length?{bends:k}:{},...T!==void 0?{on:L0(T)}:{},...R?{slots:R,clearance:U}:{},...this.step?{step:this.step}:{},...m!==void 0&&{glue:{host:m,face:p}},...o1&&{mirrored:!0},...!I&&{copies:m1}}},V=W=>M.flatMap((o1,m1)=>o1===W?[m1+1]:[]),Q=S?[j(C.layers,w,V(w)),j(z(!w).layers,!w,V(!w))]:[j(C.layers,w,V(w))];return{layers:new Map,parts:[...C.parts,...Q]}},place:s=>{let i=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),o=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=$1(l,K0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=L0(this.arg(s.args,"text",0,"")),o=h0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.children();let l=this.step,h=l&&i?`${this.stepNames[l-1]}: ${i}`:i,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=L0(this.arg(s.args,"kind",0,"dowel"));G0(I3,i)===void 0&&G0(d5,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${P2(s.args.at,!1)})${l3(i,Object.keys(I3))}`);let o=this.vec3(this.arg(s.args,"from",1),"from"),l=this.vec3(this.arg(s.args,"to",2),"to"),h=this.arg(s.args,"size",3,6),u=typeof h=="number"?h:this.vec2(h,"size",!1),f=[l[0]-o[0],l[1]-o[1],l[2]-o[2]],d=Math.abs(f[2])>.9*Math.hypot(...f),m=this.arg(s.args,"up",-1),p=m===void 0?d?[0,1,0]:[0,0,1]:this.vec3(m,"up"),g=Math.floor(this.num(this.arg(s.args,"sides",-1,24),"hardware","sides"));if(!(g>=3&&g<=nt))throw new Error(`sides must be from 3 to ${nt}, got ${_0(g)}`);if(this.pointCount+=g*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let v=this.arg(s.args,"label",-1),y=this.frame,b=M=>[y[0]*M[0]+y[1]*M[1]+y[2]*M[2]+y[3],y[4]*M[0]+y[5]*M[1]+y[6]*M[2]+y[7],y[8]*M[0]+y[9]*M[1]+y[10]*M[2]+y[11]],x=M=>[y[0]*M[0]+y[1]*M[1]+y[2]*M[2],y[4]*M[0]+y[5]*M[1]+y[6]*M[2],y[8]*M[0]+y[9]*M[1]+y[10]*M[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:i,from:b(o),to:b(l),size:u,up:x(p),sides:g,step:this.step,...v!==void 0?{label:L0(v)}:{}}),s.children()},material:s=>{let i=this.arg(s.args,"thickness",0),o=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return i!==void 0&&s.env.vars.set("$thickness",this.num(i,"material","thickness")),o!==void 0&&s.env.vars.set("$kerf",this.num(o,"material","kerf")),l!==void 0&&s.env.vars.set("$material",L0(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return J0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new E0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(p=>u.add(p));else for(let p of this.iterable(l,s.args.at))o[A0(p)]&&u.add(o[A0(p)]);let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let m=this.childKey(h);for(let p of i.stmts)if(p.kind==="assign")this.stmt(p,h);else if(u.has(p)){let g=m&&d.get(p);if(g&&g.key===m){g.shape&&f.push(g.shape);continue}let v=this.effects(),y=this.stmt(p,h);y&&f.push(y),m&&this.effects()===v&&!y?.parts.length&&d.set(p,{key:m,shape:y})}return q2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/u*4),z0(t4(i,o,l,h,u))},finger_holes:s=>{let i=this.num(this.arg(s.args,"length",0),"finger_holes","length"),o=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(o==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(i)/l*4),z0(g7(i,o,this.thickness(s.env),l))},tslot:s=>{let i=this.num(this.arg(s.args,"d",0,3),"tslot","d"),o=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[i*1.85,i*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return z0(w1(v7(i,o,l,h,u)))},living_hinge:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.num(this.arg(s.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(s.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(o-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||u<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(i)/l+1)*(Math.abs(o)/(u+h)+2)*2),D2(y7(i,o,l,h,u))}};function r(s,i){let o={regions:[],lines:[]};for(let l of s){if(l.parts.length)throw new Error(`part() can only be the first child of ${i}()`);for(let h of l.layers.values())for(let u of h.regions)o.regions.push(u)}return o}function a(s,i){let o=l=>{let h=new Map;for(let[u,f]of l)h.set(u,i(f));return h};return{layers:o(s.layers),parts:s.parts.map(l=>({...l,layers:o(l.layers)}))}}}};var q3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},Q6=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/"/g,"&quot;");function ee(t,e){let n=[];for(let[c,r]of t){let a=[q3(c),q3(r)],s=n[n.length-1];(!s||s[0]!==a[0]||s[1]!==a[1])&&n.push(a)}for(;e&&n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n}var N3=(t,e)=>`M${ee(t,e).map(([n,c])=>`${n} ${c}`).join("L")}${e?"Z":""}`;function M4(t,e){let n=[];for(let c of e){let r=[],a=[],s=[];for(let i of t){let o=i.layers.get(c.name);if(o){for(let l of o.lines)r.push(N3(l,!1));for(let l of o.regions)(H1(l)<0?a:s).push(N3(l,!0))}}(r.length||a.length||s.length)&&n.push({name:c.name,mode:c.mode,color:c.color,d:[...r,...a,...s].join(""),regions:[...a,...s].join(""),lines:r.join("")})}return n}function w4(t,e,n,c){let r=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${q3(e)}mm" height="${q3(n)}mm" viewBox="0 0 ${q3(e)} ${q3(n)}">`];for(let a of c){let s=[],i=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${Q6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>N3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${N3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${N3(f,!1)}"/>`);for(let f of h.regions)(H1(f)<0?s:i).push(`<path${u} d="${N3(f,!0)}"/>`)}if(!s.length&&!i.length)continue;let o=a.mode==="fill"?`fill="${a.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${a.color}" stroke-width="0.1"${a.mode==="guide"?' stroke-dasharray="1 1"':""}`;r.push(`<g id="${Q6(a.name)}" inkscape:groupmode="layer" inkscape:label="${Q6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return r.push("</svg>",""),r.join(`
2227
- `)}var Fs={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},$s=t=>{let e=Fs[t.toLowerCase()];if(e)return e;let[n,c,r]=[1,3,5].map(a=>parseInt(t.slice(a,a+2),16));return n>c&&n>r?1:c>n&&c>r?3:r>n&&r>c?5:7};function Ds(t){let e=i=>i.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(x4.map(i=>i.name)),c=new Set(t.map(i=>e(i.name))),r=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(r.has(o)){let l=2;for(;c.has(`${o}_${l}`)||r.has(`${o}_${l}`);)l++;o=`${o}_${l}`}r.add(o),a.set(i.name,o)}return a}function te(t,e,n,c){let r=[],a=(o,l)=>r.push(String(o),String(l)),s=Ds(c);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,c.length);for(let o of c)a(0,"LAYER"),a(2,s.get(o.name)),a(70,0),a(62,$s(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 ee(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 c){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)H1(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"),r.join(`
2563
+ `};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},c=Object.defineProperty,r=c(n,n,n)&&c}catch{}return r})(),e=function(n){if(this==null)throw TypeError();var c=String(this),r=c.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=r)){var s=c.charCodeAt(a),i;return s>=55296&&s<=56319&&r>a+1&&(i=c.charCodeAt(a+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var De=0,ut=-3;function M5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function y9(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new M5,this.dtree=new M5}var ft=new M5,dt=new M5,qe=new Uint8Array(30),Ne=new Uint16Array(30),pt=new Uint8Array(30),mt=new Uint16Array(30),b9=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),L7=new M5,y2=new Uint8Array(320);function gt(t,e,n,c){var r,a;for(r=0;r<n;++r)t[r]=0;for(r=0;r<30-n;++r)t[r+n]=r/n|0;for(a=c,r=0;r<30;++r)e[r]=a,a+=1<<t[r]}function x9(t,e){var n;for(n=0;n<7;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;n<24;++n)t.trans[n]=256+n;for(n=0;n<144;++n)t.trans[24+n]=n;for(n=0;n<8;++n)t.trans[168+n]=280+n;for(n=0;n<112;++n)t.trans[176+n]=144+n;for(n=0;n<5;++n)e.table[n]=0;for(e.table[5]=32,n=0;n<32;++n)e.trans[n]=n}var A7=new Uint16Array(16);function Me(t,e,n,c){var r,a;for(r=0;r<16;++r)t.table[r]=0;for(r=0;r<c;++r)t.table[e[n+r]]++;for(t.table[0]=0,a=0,r=0;r<16;++r)A7[r]=a,a+=t.table[r];for(r=0;r<c;++r)e[n+r]&&(t.trans[A7[e[n+r]]++]=r)}function M9(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function b2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var c=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,c+n}function Te(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,c=0,r=0,a=t.tag;do c=2*c+(a&1),a>>>=1,++r,n+=e.table[r],c-=e.table[r];while(c>=0);return t.tag=a,t.bitcount-=r,e.trans[n+c]}function w9(t,e,n){var c,r,a,s,i,o;for(c=b2(t,5,257),r=b2(t,5,1),a=b2(t,4,4),s=0;s<19;++s)y2[s]=0;for(s=0;s<a;++s){var l=b2(t,3,0);y2[b9[s]]=l}for(Me(L7,y2,0,19),i=0;i<c+r;){var h=Te(t,L7);switch(h){case 16:var u=y2[i-1];for(o=b2(t,2,3);o;--o)y2[i++]=u;break;case 17:for(o=b2(t,3,3);o;--o)y2[i++]=0;break;case 18:for(o=b2(t,7,11);o;--o)y2[i++]=0;break;default:y2[i++]=h;break}}Me(e,y2,0,c),Me(n,y2,c,r)}function C7(t,e,n){for(;;){var c=Te(t,e);if(c===256)return De;if(c<256)t.dest[t.destLen++]=c;else{var r,a,s,i;for(c-=257,r=b2(t,qe[c],Ne[c]),a=Te(t,n),s=t.destLen-b2(t,pt[a],mt[a]),i=s;i<s+r;++i)t.dest[t.destLen++]=t.dest[i]}}}function z9(t){for(var e,n,c;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return ut;for(t.sourceIndex+=4,c=e;c;--c)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,De}function k9(t,e){var n=new y9(t,e),c,r,a;do{switch(c=M9(n),r=b2(n,2,0),r){case 0:a=z9(n);break;case 1:a=C7(n,ft,dt);break;case 2:w9(n,n.ltree,n.dtree),a=C7(n,n.ltree,n.dtree);break;default:a=ut}if(a!==De)throw new Error("Data error")}while(!c);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}x9(ft,dt);gt(qe,Ne,4,3);gt(pt,mt,2,1);qe[28]=0;Ne[28]=258;var S9=k9;function V3(t,e,n,c,r){return Math.pow(1-r,3)*t+3*Math.pow(1-r,2)*r*e+3*(1-r)*Math.pow(r,2)*n+Math.pow(r,3)*c}function X2(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}X2.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};X2.prototype.addPoint=function(t,e){typeof t=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};X2.prototype.addX=function(t){this.addPoint(t,null)};X2.prototype.addY=function(t){this.addPoint(null,t)};X2.prototype.addBezier=function(t,e,n,c,r,a,s,i){var o=[t,e],l=[n,c],h=[r,a],u=[s,i];this.addPoint(t,e),this.addPoint(s,i);for(var f=0;f<=1;f++){var d=6*o[f]-12*l[f]+6*h[f],p=-3*o[f]+9*l[f]-9*h[f]+3*u[f],m=3*l[f]-3*o[f];if(p===0){if(d===0)continue;var g=-m/d;0<g&&g<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],g)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*m*p;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*p);0<y&&y<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],y)));var b=(-d-Math.sqrt(v))/(2*p);0<b&&b<1&&(f===0&&this.addX(V3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(V3(o[f],l[f],h[f],u[f],b)))}}};X2.prototype.addQuad=function(t,e,n,c,r,a){var s=t+.6666666666666666*(n-t),i=e+2/3*(c-e),o=s+1/3*(r-t),l=i+1/3*(a-e);this.addBezier(t,e,s,i,o,l,r,a)};function M0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}M0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};M0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};M0.prototype.curveTo=M0.prototype.bezierCurveTo=function(t,e,n,c,r,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:c,x:r,y:a})};M0.prototype.quadTo=M0.prototype.quadraticCurveTo=function(t,e,n,c){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:c})};M0.prototype.close=M0.prototype.closePath=function(){this.commands.push({type:"Z"})};M0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof X2){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};M0.prototype.getBoundingBox=function(){for(var t=new X2,e=0,n=0,c=0,r=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=c=s.x,n=r=s.y;break;case"L":t.addPoint(s.x,s.y),c=s.x,r=s.y;break;case"Q":t.addQuad(c,r,s.x1,s.y1,s.x,s.y),c=s.x,r=s.y;break;case"C":t.addBezier(c,r,s.x1,s.y1,s.x2,s.y2,s.x,s.y),c=s.x,r=s.y;break;case"Z":c=e,r=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};M0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};M0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var c="",r=0;r<this.commands.length;r+=1){var a=this.commands[r];a.type==="M"?c+="M"+n(a.x,a.y):a.type==="L"?c+="L"+n(a.x,a.y):a.type==="C"?c+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?c+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(c+="Z")}return c};M0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};M0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function vt(t){throw new Error(t)}function P7(t,e){t||vt(e)}var k1={fail:vt,argument:P7,assert:P7},T7=32768,E7=2147483648,O3={},K={},C1={};function l2(t){return function(){return t}}K.BYTE=function(t){return k1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};C1.BYTE=l2(1);K.CHAR=function(t){return[t.charCodeAt(0)]};C1.CHAR=l2(1);K.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};C1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};K.USHORT=function(t){return[t>>8&255,t&255]};C1.USHORT=l2(2);K.SHORT=function(t){return t>=T7&&(t=-(2*T7-t)),[t>>8&255,t&255]};C1.SHORT=l2(2);K.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};C1.UINT24=l2(3);K.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.ULONG=l2(4);K.LONG=function(t){return t>=E7&&(t=-(2*E7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONG=l2(4);K.FIXED=K.ULONG;C1.FIXED=C1.ULONG;K.FWORD=K.SHORT;C1.FWORD=C1.SHORT;K.UFWORD=K.USHORT;C1.UFWORD=C1.USHORT;K.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.LONGDATETIME=l2(8);K.TAG=function(t){return k1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};C1.TAG=l2(4);K.Card8=K.BYTE;C1.Card8=C1.BYTE;K.Card16=K.USHORT;C1.Card16=C1.USHORT;K.OffSize=K.BYTE;C1.OffSize=C1.BYTE;K.SID=K.USHORT;C1.SID=C1.USHORT;K.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?K.NUMBER16(t):K.NUMBER32(t)};C1.NUMBER=function(t){return K.NUMBER(t).length};K.NUMBER16=function(t){return[28,t>>8&255,t&255]};C1.NUMBER16=l2(3);K.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};C1.NUMBER32=l2(5);K.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var c=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*c)/c).toString()}for(var r="",a=0,s=e.length;a<s;a+=1){var i=e[a];i==="e"?r+=e[++a]==="-"?"c":"b":i==="."?r+="a":i==="-"?r+="e":r+=i}r+=r.length&1?"f":"ff";for(var o=[30],l=0,h=r.length;l<h;l+=2)o.push(parseInt(r.substr(l,2),16));return o};C1.REAL=function(t){return K.REAL(t).length};K.NAME=K.CHARARRAY;C1.NAME=C1.CHARARRAY;K.STRING=K.CHARARRAY;C1.STRING=C1.CHARARRAY;O3.UTF8=function(t,e,n){for(var c=[],r=n,a=0;a<r;a++,e+=1)c[a]=t.getUint8(e);return String.fromCharCode.apply(null,c)};O3.UTF16=function(t,e,n){for(var c=[],r=n/2,a=0;a<r;a++,e+=2)c[a]=t.getUint16(e);return String.fromCharCode.apply(null,c)};K.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var c=t.charCodeAt(n);e[e.length]=c>>8&255,e[e.length]=c&255}return e};C1.UTF16=function(t){return t.length*2};var Ee={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};O3.MACSTRING=function(t,e,n,c){var r=Ee[c];if(r!==void 0){for(var a="",s=0;s<n;s++){var i=t.getUint8(e+s);i<=127?a+=String.fromCharCode(i):a+=r[i&127]}return a}};var a4=typeof WeakMap=="function"&&new WeakMap,s4,L9=function(t){if(!s4){s4={};for(var e in Ee)s4[e]=new String(e)}var n=s4[t];if(n!==void 0){if(a4){var c=a4.get(n);if(c!==void 0)return c}var r=Ee[t];if(r!==void 0){for(var a={},s=0;s<r.length;s++)a[r.charCodeAt(s)]=s+128;return a4&&a4.set(n,a),a}}};K.MACSTRING=function(t,e){var n=L9(e);if(n!==void 0){for(var c=[],r=0;r<t.length;r++){var a=t.charCodeAt(r);if(a>=128&&(a=n[a],a===void 0))return;c[r]=a}return c}};C1.MACSTRING=function(t,e){var n=K.MACSTRING(t,e);return n!==void 0?n.length:0};function Ie(t){return t>=-128&&t<=127}function A9(t,e,n){for(var c=0,r=t.length;e<r&&c<64&&t[e]===0;)++e,++c;return n.push(128|c-1),e}function C9(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(!Ie(s)||s===0&&a+1<r&&t[a+1]===0)break;++a,++c}n.push(c-1);for(var i=e;i<a;++i)n.push(t[i]+256&255);return a}function P9(t,e,n){for(var c=0,r=t.length,a=e;a<r&&c<64;){var s=t[a];if(s===0||Ie(s)&&a+1<r&&Ie(t[a+1]))break;++a,++c}n.push(64|c-1);for(var i=e;i<a;++i){var o=t[i];n.push(o+65536>>8&255,o+256&255)}return a}K.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var c=t[e];c===0?e=A9(t,e,n):c>=-128&&c<=127?e=C9(t,e,n):e=P9(t,e,n)}return n};K.INDEX=function(t){for(var e=1,n=[e],c=[],r=0;r<t.length;r+=1){var a=K.OBJECT(t[r]);Array.prototype.push.apply(c,a),e+=a.length,n.push(e)}if(c.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,K.BYTE,K.USHORT,K.UINT24,K.ULONG][i],l=0;l<n.length;l+=1){var h=o(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(K.Card16(t.length),K.OffSize(i),s,c)};C1.INDEX=function(t){return K.INDEX(t).length};K.DICT=function(t){for(var e=[],n=Object.keys(t),c=n.length,r=0;r<c;r+=1){var a=parseInt(n[r],0),s=t[a];e=e.concat(K.OPERAND(s.value,s.type)),e=e.concat(K.OPERATOR(a))}return e};C1.DICT=function(t){return K.DICT(t).length};K.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};K.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)k1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(K.OPERAND(t[c],e[c]));else if(e==="SID")n=n.concat(K.NUMBER(t));else if(e==="offset")n=n.concat(K.NUMBER32(t));else if(e==="number")n=n.concat(K.NUMBER(t));else if(e==="real")n=n.concat(K.REAL(t));else throw new Error("Unknown operand type "+e);return n};K.OP=K.BYTE;C1.OP=C1.BYTE;var i4=typeof WeakMap=="function"&&new WeakMap;K.CHARSTRING=function(t){if(i4){var e=i4.get(t);if(e!==void 0)return e}for(var n=[],c=t.length,r=0;r<c;r+=1){var a=t[r];n=n.concat(K[a.type](a.value))}return i4&&i4.set(t,n),n};C1.CHARSTRING=function(t){return K.CHARSTRING(t).length};K.OBJECT=function(t){var e=K[t.type];return k1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};C1.OBJECT=function(t){var e=C1[t.type];return k1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};K.TABLE=function(t){for(var e=[],n=t.fields.length,c=[],r=[],a=0;a<n;a+=1){var s=t.fields[a],i=K[s.type];k1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=t[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(r.push(e.length),e=e.concat([0,0]),c.push(l)):e=e.concat(l)}for(var h=0;h<c.length;h+=1){var u=r[h],f=e.length;k1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(c[h])}return e};C1.TABLE=function(t){for(var e=0,n=t.fields.length,c=0;c<n;c+=1){var r=t.fields[c],a=C1[r.type];k1.argument(a!==void 0,"No sizeOf function for field type "+r.type+" ("+r.name+")");var s=t[r.name];s===void 0&&(s=r.value),e+=a(s),r.type==="TABLE"&&(e+=2)}return e};K.RECORD=K.TABLE;C1.RECORD=C1.TABLE;K.LITERAL=function(t){return t};C1.LITERAL=function(t){return t.length};function P0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var c=0;c<e.length;c+=1){var r=e[c];this[r.name]=r.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var i=a[s],o=n[i];this[i]!==void 0&&(this[i]=o)}}P0.prototype.encode=function(){return K.TABLE(this)};P0.prototype.sizeOf=function(){return C1.TABLE(this)};function w5(t,e,n){n===void 0&&(n=e.length);var c=new Array(e.length+1);c[0]={name:t+"Count",type:"USHORT",value:n};for(var r=0;r<e.length;r++)c[r+1]={name:t+r,type:"USHORT",value:e[r]};return c}function Ve(t,e,n){var c=e.length,r=new Array(c+1);r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return r}function z5(t,e,n){var c=e.length,r=[];r[0]={name:t+"Count",type:"USHORT",value:c};for(var a=0;a<c;a++)r=r.concat(n(e[a],a));return r}function f4(t){t.format===1?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(w5("glyph",t.glyphs))):t.format===2?P0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(z5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):k1.assert(!1,"Coverage format must be 1 or 2.")}f4.prototype=Object.create(P0.prototype);f4.prototype.constructor=f4;function d4(t){P0.call(this,"scriptListTable",z5("scriptRecord",t,function(e,n){var c=e.script,r=c.defaultLangSys;return k1.assert(!!r,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new P0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new P0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:r.reqFeatureIndex}].concat(w5("featureIndex",r.featureIndexes)))}].concat(z5("langSys",c.langSysRecords,function(a,s){var i=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new P0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(w5("featureIndex",i.featureIndexes)))}]})))}]}))}d4.prototype=Object.create(P0.prototype);d4.prototype.constructor=d4;function p4(t){P0.call(this,"featureListTable",z5("featureRecord",t,function(e,n){var c=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new P0("featureTable",[{name:"featureParams",type:"USHORT",value:c.featureParams}].concat(w5("lookupListIndex",c.lookupListIndexes)))}]}))}p4.prototype=Object.create(P0.prototype);p4.prototype.constructor=p4;function m4(t,e){P0.call(this,"lookupListTable",Ve("lookup",t,function(n){var c=e[n.lookupType];return k1.assert(!!c,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new P0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(Ve("subtable",n.subtables,c)))}))}m4.prototype=Object.create(P0.prototype);m4.prototype.constructor=m4;var n1={Table:P0,Record:P0,Coverage:f4,ScriptList:d4,FeatureList:p4,LookupList:m4,ushortList:w5,tableList:Ve,recordList:z5};function I7(t,e){return t.getUint8(e)}function g4(t,e){return t.getUint16(e,!1)}function T9(t,e){return t.getInt16(e,!1)}function Ue(t,e){return t.getUint32(e,!1)}function yt(t,e){var n=t.getInt16(e,!1),c=t.getUint16(e+2,!1);return n+c/65535}function E9(t,e){for(var n="",c=e;c<e+4;c+=1)n+=String.fromCharCode(t.getInt8(c));return n}function I9(t,e,n){for(var c=0,r=0;r<n;r+=1)c<<=8,c+=t.getUint8(e+r);return c}function V9(t,e,n){for(var c=[],r=e;r<n;r+=1)c.push(t.getUint8(r));return c}function H9(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var O9={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function O(t,e){this.data=t,this.offset=e,this.relativeOffset=0}O.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};O.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};O.prototype.parseCard8=O.prototype.parseByte;O.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};O.prototype.parseCard16=O.prototype.parseUShort;O.prototype.parseSID=O.prototype.parseUShort;O.prototype.parseOffset16=O.prototype.parseUShort;O.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};O.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};O.prototype.parseULong=function(){var t=Ue(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};O.prototype.parseOffset32=O.prototype.parseULong;O.prototype.parseFixed=function(){var t=yt(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};O.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,c="";this.relativeOffset+=t;for(var r=0;r<t;r++)c+=String.fromCharCode(e.getUint8(n+r));return c};O.prototype.parseTag=function(){return this.parseString(4)};O.prototype.parseLongDateTime=function(){var t=Ue(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};O.prototype.parseVersion=function(t){var e=g4(this.data,this.offset+this.relativeOffset),n=g4(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};O.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=O9[t]*e};O.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint32(c),c+=4;return this.relativeOffset+=t*4,e};O.prototype.parseOffset16List=O.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint16(c),c+=2;return this.relativeOffset+=t*2,e};O.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getInt16(c),c+=2;return this.relativeOffset+=t*2,e};O.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,c=this.offset+this.relativeOffset,r=0;r<t;r++)e[r]=n.getUint8(c++);return this.relativeOffset+=t,e};O.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};O.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=0;c<t;c++)n[c]=e.call(this);return n};O.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};O.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),c=Object.keys(e),r=0;r<t;r++){for(var a={},s=0;s<c.length;s++){var i=c[s],o=e[i];a[i]=o.call(this)}n[r]=a}return n};O.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},c=0;c<e.length;c++){var r=e[c],a=t[r];n[r]=a.call(this)}return n};O.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};O.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),c=0;c<e;c++)n[c]=this.parseValueRecord(t);return n};O.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new O(this.data,this.offset+e).parseStruct(t)};O.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new O(this.data,this.offset+e).parseStruct(t)};O.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,c=this.relativeOffset,r=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){r[a]=void 0;continue}if(this.relativeOffset=s,t){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=t.call(this);r[a]=o}else r[a]=this.parseUShortList()}return this.relativeOffset=c,r};O.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var c=new Array(n),r=0;r<n;r++)c[r]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:c}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};O.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:O.uShort,end:O.uShort,classId:O.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};O.list=function(t,e){return function(){return this.parseList(t,e)}};O.list32=function(t,e){return function(){return this.parseList32(t,e)}};O.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};O.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};O.pointer=function(t){return function(){return this.parsePointer(t)}};O.pointer32=function(t){return function(){return this.parsePointer32(t)}};O.tag=O.prototype.parseTag;O.byte=O.prototype.parseByte;O.uShort=O.offset16=O.prototype.parseUShort;O.uShortList=O.prototype.parseUShortList;O.uLong=O.offset32=O.prototype.parseULong;O.uLongList=O.prototype.parseULongList;O.struct=O.prototype.parseStruct;O.coverage=O.prototype.parseCoverage;O.classDef=O.prototype.parseClassDef;var V7={reserved:O.uShort,reqFeatureIndex:O.uShort,featureIndexes:O.uShortList};O.prototype.parseScriptList=function(){return this.parsePointer(O.recordList({tag:O.tag,script:O.pointer({defaultLangSys:O.pointer(V7),langSysRecords:O.recordList({tag:O.tag,langSys:O.pointer(V7)})})}))||[]};O.prototype.parseFeatureList=function(){return this.parsePointer(O.recordList({tag:O.tag,feature:O.pointer({featureParams:O.offset16,lookupListIndexes:O.uShortList})}))||[]};O.prototype.parseLookupList=function(t){return this.parsePointer(O.list(O.pointer(function(){var e=this.parseUShort();k1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),c=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(O.pointer(t[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};O.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();k1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:O.offset32,featureTableSubstitutionOffset:O.offset32});return n})||[]};var f1={getByte:I7,getCard8:I7,getUShort:g4,getCard16:g4,getShort:T9,getULong:Ue,getFixed:yt,getTag:E9,getOffset:I9,getBytes:V9,bytesToString:H9,Parser:O};function R9(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var c=0;c<n;c+=1)for(var r=e.parseULong(),a=e.parseULong(),s=e.parseULong(),i=r;i<=a;i+=1)t.glyphIndexMap[i]=s,s++}function F9(t,e,n,c,r){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new f1.Parser(n,c+r+14),i=new f1.Parser(n,c+r+16+a*2),o=new f1.Parser(n,c+r+16+a*4),l=new f1.Parser(n,c+r+16+a*6),h=c+r+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),p=i.parseUShort(),m=o.parseShort(),g=l.parseUShort(),v=p;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-p)*2,f=f1.getUShort(n,h),f!==0&&(f=f+m&65535)):f=v+m&65535,t.glyphIndexMap[v]=f}function $9(t,e){var n={};n.version=f1.getUShort(t,e),k1.argument(n.version===0,"cmap table version should be 0."),n.numTables=f1.getUShort(t,e+2);for(var c=-1,r=n.numTables-1;r>=0;r-=1){var a=f1.getUShort(t,e+4+r*8),s=f1.getUShort(t,e+4+r*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){c=f1.getULong(t,e+4+r*8+4);break}}if(c===-1)throw new Error("No valid cmap sub-tables found.");var i=new f1.Parser(t,e+c);if(n.format=i.parseUShort(),n.format===12)R9(n,i);else if(n.format===4)F9(n,i,t,e,c);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function D9(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function q9(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function N9(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var c=t.get(n);if(c.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var r=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(r=r.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),r=r.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var a=new n1.Table("cmap",r);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)D9(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}q9(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],p=[],m=[];for(n=0;n<o;n+=1){var g=a.segments[n];g.end<=65535&&g.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:g.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:g.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:g.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:g.offset}),g.glyphId!==void 0&&(p=p.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),m=m.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),m=m.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(a.segCountX2=(o-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(p),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+p.length*2,!e){var v=16+m.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:m.length/3}]),a.fields=a.fields.concat(m)}return a}var bt={parse:$9,make:N9},h4=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],U9=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],B9=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],s3=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function xt(t){this.font=t}xt.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var c=0;c<n.length;c+=1)for(var r=n.get(c),a=0;a<r.unicodes.length;a+=1)if(r.unicodes[a]===e)return c}return null};function Mt(t){this.cmap=t}Mt.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function v4(t,e){this.encoding=t,this.charset=e}v4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function Be(t){switch(t.version){case 1:this.names=s3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<s3.length?this.names[e]=s3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-s3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=s3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}Be.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};Be.prototype.glyphIndexToName=function(t){return this.names[t]};function _9(t){for(var e,n=t.tables.cmap.glyphIndexMap,c=Object.keys(n),r=0;r<c.length;r+=1){var a=c[r],s=n[a];e=t.glyphs.get(s),e.addUnicode(parseInt(a))}for(var i=0;i<t.glyphs.length;i+=1)e=t.glyphs.get(i),t.cffEncoding?t.isCIDFont?e.name="gid"+i:e.name=t.cffEncoding.charset[i]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(i))}function G9(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),c=0;c<n.length;c+=1){var r=n[c],a=e[r];t._IndexToUnicodeMap[a]===void 0?t._IndexToUnicodeMap[a]={unicodes:[parseInt(r)]}:t._IndexToUnicodeMap[a].unicodes.push(parseInt(r))}}function j9(t,e){e.lowMemory?G9(t):_9(t)}function W9(t,e,n,c,r){t.beginPath(),t.moveTo(e,n),t.lineTo(c,r),t.stroke()}var a3={line:W9};function X9(t,e){var n=e||new M0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(c){n=c}}}function e2(t){this.bindConstructorValues(t)}e2.prototype.bindConstructorValues=function(t){this.index=t.index||0,this.name=t.name||null,this.unicode=t.unicode||void 0,this.unicodes=t.unicodes||t.unicode!==void 0?[t.unicode]:[],"xMin"in t&&(this.xMin=t.xMin),"yMin"in t&&(this.yMin=t.yMin),"xMax"in t&&(this.xMax=t.xMax),"yMax"in t&&(this.yMax=t.yMax),"advanceWidth"in t&&(this.advanceWidth=t.advanceWidth),Object.defineProperty(this,"path",X9(this,t.path))};e2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};e2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};e2.prototype.getPath=function(t,e,n,c,r){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;c||(c={});var i=c.xScale,o=c.yScale;if(c.hinting&&r&&r.hinting&&(s=this.path&&r.hinting.exec(this,n)),s)a=r.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),i=o=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new M0,u=0;u<a.length;u+=1){var f=a[u];f.type==="M"?h.moveTo(t+f.x*i,e+-f.y*o):f.type==="L"?h.lineTo(t+f.x*i,e+-f.y*o):f.type==="Q"?h.quadraticCurveTo(t+f.x1*i,e+-f.y1*o,t+f.x*i,e+-f.y*o):f.type==="C"?h.curveTo(t+f.x1*i,e+-f.y1*o,t+f.x2*i,e+-f.y2*o,t+f.x*i,e+-f.y*o):f.type==="Z"&&h.closePath()}return h};e2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var c=this.points[n];e.push(c),c.lastPointOfContour&&(t.push(e),e=[])}return k1.argument(e.length===0,"There are still points left in the current contour."),t};e2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];r.type!=="Z"&&(e.push(r.x),n.push(r.y)),(r.type==="Q"||r.type==="C")&&(e.push(r.x1),n.push(r.y1)),r.type==="C"&&(e.push(r.x2),n.push(r.y2))}var a={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a};e2.prototype.draw=function(t,e,n,c,r){this.getPath(e,n,c,r).draw(t)};e2.prototype.drawPoints=function(t,e,n,c){function r(u,f,d,p){t.beginPath();for(var m=0;m<u.length;m+=1)t.moveTo(f+u[m].x*p,d+u[m].y*p),t.arc(f+u[m].x*p,d+u[m].y*p,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24;for(var a=1/this.path.unitsPerEm*c,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",r(s,e,n,a),t.fillStyle="red",r(i,e,n,a)};e2.prototype.drawMetrics=function(t,e,n,c){var r;e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:24,r=1/this.path.unitsPerEm*c,t.lineWidth=1,t.strokeStyle="black",a3.line(t,e,-1e4,e,1e4),a3.line(t,-1e4,n,1e4,n);var a=this.xMin||0,s=this.yMin||0,i=this.xMax||0,o=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",a3.line(t,e+a*r,-1e4,e+a*r,1e4),a3.line(t,e+i*r,-1e4,e+i*r,1e4),a3.line(t,-1e4,n+-s*r,1e4,n+-s*r),a3.line(t,-1e4,n+-o*r,1e4,n+-o*r),t.strokeStyle="green",a3.line(t,e+l*r,-1e4,e+l*r,1e4)};function o4(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(c){t[n]=c},enumerable:!0,configurable:!0})}function _e(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var c=e[n];c.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=c}this.length=e&&e.length||0}_e.prototype.get=function(t){if(this.glyphs[t]===void 0){this.font._push(t),typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());var e=this.glyphs[t],n=this.font._IndexToUnicodeMap[t];if(n)for(var c=0;c<n.unicodes.length;c++)e.addUnicode(n.unicodes[c]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+t:e.name=this.font.cffEncoding.charset[t]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(t)),this.glyphs[t].advanceWidth=this.font._hmtxTableData[t].advanceWidth,this.glyphs[t].leftSideBearing=this.font._hmtxTableData[t].leftSideBearing}else typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());return this.glyphs[t]};_e.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Z9(t,e){return new e2({index:e,font:t})}function Y9(t,e,n,c,r,a){return function(){var s=new e2({index:e,font:t});return s.path=function(){n(s,c,r);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},o4(s,"xMin","_xMin"),o4(s,"xMax","_xMax"),o4(s,"yMin","_yMin"),o4(s,"yMax","_yMax"),s}}function J9(t,e,n,c){return function(){var r=new e2({index:e,font:t});return r.path=function(){var a=n(t,r,c);return a.unitsPerEm=t.unitsPerEm,a},r}}var M2={GlyphSet:_e,glyphLoader:Z9,ttfGlyphLoader:Y9,cffGlyphLoader:J9};function wt(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n+=1)if(!wt(t[n],e[n]))return!1;return!0}else return!1}function He(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function _2(t,e,n){var c=[],r=[],a=f1.getCard16(t,e),s,i;if(a!==0){var o=f1.getByte(t,e+2);s=e+(a+1)*o+2;for(var l=e+3,h=0;h<a+1;h+=1)c.push(f1.getOffset(t,l,o)),l+=o;i=s+c[a]}else i=e+2;for(var u=0;u<c.length-1;u+=1){var f=f1.getBytes(t,s+c[u],s+c[u+1]);n&&(f=n(f)),r.push(f)}return{objects:r,startOffset:e,endOffset:i}}function K9(t,e){var n=[],c=f1.getCard16(t,e),r,a;if(c!==0){var s=f1.getByte(t,e+2);r=e+(c+1)*s+2;for(var i=e+3,o=0;o<c+1;o+=1)n.push(f1.getOffset(t,i,s)),i+=s;a=r+n[c]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function Q9(t,e,n,c,r){var a=f1.getCard16(n,c),s=0;if(a!==0){var i=f1.getByte(n,c+2);s=c+(a+1)*i+2}var o=f1.getBytes(n,s+e[t],s+e[t+1]);return r&&(o=r(o)),o}function ec(t){for(var e="",n=15,c=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var r=t.parseByte(),a=r>>4,s=r&15;if(a===n||(e+=c[a],s===n))break;e+=c[s]}return parseFloat(e)}function tc(t,e){var n,c,r,a;if(e===28)return n=t.parseByte(),c=t.parseByte(),n<<8|c;if(e===29)return n=t.parseByte(),c=t.parseByte(),r=t.parseByte(),a=t.parseByte(),n<<24|c<<16|r<<8|a;if(e===30)return ec(t);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return n=t.parseByte(),(e-247)*256+n+108;if(e>=251&&e<=254)return n=t.parseByte(),-(e-251)*256-n-108;throw new Error("Invalid b0 "+e)}function nc(t){for(var e={},n=0;n<t.length;n+=1){var c=t[n][0],r=t[n][1],a=void 0;if(r.length===1?a=r[0]:a=r,e.hasOwnProperty(c)&&!isNaN(e[c]))throw new Error("Object "+e+" already has key "+c);e[c]=a}return e}function zt(t,e,n){e=e!==void 0?e:0;var c=new f1.Parser(t,e),r=[],a=[];for(n=n!==void 0?n:t.length;c.relativeOffset<n;){var s=c.parseByte();s<=21?(s===12&&(s=1200+c.parseByte()),r.push([s,a]),a=[]):a.push(tc(c,s))}return nc(r)}function x5(t,e){return e<=390?e=h4[e]:e=t[e-391],e}function kt(t,e,n){for(var c={},r,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)r=t[s.op]!==void 0?t[s.op][o]:void 0,r===void 0&&(r=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(r=x5(n,r)),i[o]=r;c[s.name]=i}else r=t[s.op],r===void 0&&(r=s.value!==void 0?s.value:null),s.type==="SID"&&(r=x5(n,r)),c[s.name]=r}return c}function cc(t,e){var n={};return n.formatMajor=f1.getCard8(t,e),n.formatMinor=f1.getCard8(t,e+1),n.size=f1.getCard8(t,e+2),n.offsetSize=f1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var St=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],Lt=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function rc(t,e){var n=zt(t,0,t.byteLength);return kt(n,St,e)}function At(t,e,n,c){var r=zt(t,e,n);return kt(r,Lt,c)}function H7(t,e,n,c){for(var r=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=rc(s,c);i._subrs=[],i._subrsBias=0,i._defaultWidthX=0,i._nominalWidthX=0;var o=i.private[0],l=i.private[1];if(o!==0&&l!==0){var h=At(t,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=_2(t,u+e);i._subrs=f.objects,i._subrsBias=He(i._subrs)}i._privateDict=h}r.push(i)}return r}function ac(t,e,n,c){var r,a,s=new f1.Parser(t,e);n-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<n;l+=1)r=s.parseSID(),i.push(x5(c,r));else if(o===1)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)i.push(x5(c,r)),r+=1}else if(o===2)for(;i.length<=n;){r=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)i.push(x5(c,r)),r+=1}else throw new Error("Unknown charset format "+o);return i}function sc(t,e,n){var c,r={},a=new f1.Parser(t,e),s=a.parseCard8();if(s===0)for(var i=a.parseCard8(),o=0;o<i;o+=1)c=a.parseCard8(),r[c]=o;else if(s===1){var l=a.parseCard8();c=1;for(var h=0;h<l;h+=1)for(var u=a.parseCard8(),f=a.parseCard8(),d=u;d<=u+f;d+=1)r[d]=c,c+=1}else throw new Error("Unknown encoding format "+s);return new v4(r,n)}function O7(t,e,n){var c,r,a,s,i=new M0,o=[],l=0,h=!1,u=!1,f=0,d=0,p,m,g,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];p=b._subrs,m=b._subrsBias,g=b._defaultWidthX,v=b._nominalWidthX}else p=t.tables.cff.topDict._subrs,m=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function M(z,S){u&&i.closePath(),i.moveTo(z,S),u=!0}function w(){var z;z=o.length%2!==0,z&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function k(z){for(var S,L,I,q,R,N,G,V,J,o1,Z,p1,E=0;E<z.length;){var $=z[E];switch(E+=1,$){case 1:w();break;case 3:w();break;case 4:o.length>1&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),M(f,d);break;case 5:for(;o.length>0;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 6:for(;o.length>0&&(f+=o.shift(),i.lineTo(f,d),o.length!==0);)d+=o.shift(),i.lineTo(f,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(f,d),o.length!==0);)f+=o.shift(),i.lineTo(f,d);break;case 8:for(;o.length>0;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 10:R=o.pop()+m,N=p[R],N&&k(N);break;case 11:return;case 12:switch($=z[E],E+=1,$){case 35:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s+o.shift(),J=G+o.shift(),o1=V+o.shift(),Z=J+o.shift(),p1=o1+o.shift(),f=Z+o.shift(),d=p1+o.shift(),o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 34:c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s,J=G+o.shift(),o1=s,Z=J+o.shift(),p1=d,f=Z+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 36:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s,J=G+o.shift(),o1=s,Z=J+o.shift(),p1=o1+o.shift(),f=Z+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;case 37:c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),G=a+o.shift(),V=s+o.shift(),J=G+o.shift(),o1=V+o.shift(),Z=J+o.shift(),p1=o1+o.shift(),Math.abs(Z-f)>Math.abs(p1-d)?f=Z+o.shift():d=p1+o.shift(),i.curveTo(c,r,a,s,G,V),i.curveTo(J,o1,Z,p1,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+$),o.length=0}break;case 14:o.length>0&&!h&&(x=o.shift()+v,h=!0),u&&(i.closePath(),u=!1);break;case 18:w();break;case 19:case 20:w(),E+=l+7>>3;break;case 21:o.length>2&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),f+=o.pop(),M(f,d);break;case 22:o.length>1&&!h&&(x=o.shift()+v,h=!0),f+=o.pop(),M(f,d);break;case 23:w();break;case 24:for(;o.length>2;)c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 25:for(;o.length>6;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);c=f+o.shift(),r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 26:for(o.length%2&&(f+=o.shift());o.length>0;)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a,d=s+o.shift(),i.curveTo(c,r,a,s,f,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s,i.curveTo(c,r,a,s,f,d);break;case 28:S=z[E],L=z[E+1],o.push((S<<24|L<<16)>>16),E+=2;break;case 29:R=o.pop()+t.gsubrsBias,N=t.gsubrs[R],N&&k(N);break;case 30:for(;o.length>0&&(c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;case 31:for(;o.length>0&&(c=f+o.shift(),r=d,a=c+o.shift(),s=r+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d),o.length!==0);)c=f,r=d+o.shift(),a=c+o.shift(),s=r+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,r,a,s,f,d);break;default:$<32?console.log("Glyph "+e.index+": unknown operator "+$):$<247?o.push($-139):$<251?(S=z[E],E+=1,o.push(($-247)*256+S+108)):$<255?(S=z[E],E+=1,o.push(-($-251)*256-S-108)):(S=z[E],L=z[E+1],I=z[E+2],q=z[E+3],E+=4,o.push((S<<24|L<<16|I<<8|q)/65536))}}}return k(n),e.advanceWidth=x,i}function ic(t,e,n,c){var r=[],a,s=new f1.Parser(t,e),i=s.parseCard8();if(i===0)for(var o=0;o<n;o++){if(a=s.parseCard8(),a>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+c+")");r.push(a)}else if(i===3){var l=s.parseCard16(),h=s.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var u,f=0;f<l;f++){if(a=s.parseCard8(),u=s.parseCard16(),a>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+c+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)r.push(a);h=u}if(u!==n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+u)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);return r}function oc(t,e,n,c){n.tables.cff={};var r=cc(t,e),a=_2(t,r.endOffset,f1.bytesToString),s=_2(t,a.endOffset),i=_2(t,s.endOffset,f1.bytesToString),o=_2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=He(n.gsubrs);var l=H7(t,e,s.objects,i.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=_2(t,u),p=H7(t,e,d.objects,i.objects);h._fdArray=p,f+=e,h._fdSelect=ic(t,f,n.numGlyphs,p.length)}var m=e+h.private[1],g=At(t,m,h.private[0],i.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=m+g.subrs,y=_2(t,v);n.subrs=y.objects,n.subrsBias=He(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;c.lowMemory?(b=K9(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=_2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=ac(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new v4(U9,x):h.encoding===1?n.cffEncoding=new v4(B9,x):n.cffEncoding=sc(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new M2.GlyphSet(n),c.lowMemory)n._push=function(k){var z=Q9(k,b.offsets,t,e+h.charStrings);n.glyphs.push(k,M2.cffGlyphLoader(n,k,O7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var w=b.objects[M];n.glyphs.push(M,M2.cffGlyphLoader(n,M,O7,w))}}function Ct(t,e){var n,c=h4.indexOf(t);return c>=0&&(n=c),c=e.indexOf(t),c>=0?n=c+h4.length:(n=h4.length+e.length,e.push(t)),n}function lc(){return new n1.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function hc(t){var e=new n1.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var n=0;n<t.length;n+=1)e.names.push({name:"name_"+n,type:"NAME",value:t[n]});return e}function Pt(t,e,n){for(var c={},r=0;r<t.length;r+=1){var a=t[r],s=e[a.name];s!==void 0&&!wt(s,a.value)&&(a.type==="SID"&&(s=Ct(s,n)),c[a.op]={name:a.name,type:a.type,value:s})}return c}function R7(t,e){var n=new n1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=Pt(St,t,e),n}function F7(t){var e=new n1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function uc(t){var e=new n1.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var n=0;n<t.length;n+=1)e.strings.push({name:"string_"+n,type:"STRING",value:t[n]});return e}function fc(){return new n1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function dc(t,e){for(var n=new n1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),c=0;c<t.length;c+=1){var r=t[c],a=Ct(r,e);n.fields.push({name:"glyph_"+c,type:"SID",value:a})}return n}function pc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var c=0,r=0,a=0;a<n.commands.length;a+=1){var s=void 0,i=void 0,o=n.commands[a];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*c+h*o.x1),y1:Math.round(l*r+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-c),i=Math.round(o.y-r),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),c=Math.round(o.x),r=Math.round(o.y);else if(o.type==="C"){var u=Math.round(o.x1-c),f=Math.round(o.y1-r),d=Math.round(o.x2-o.x1),p=Math.round(o.y2-o.y1);s=Math.round(o.x-o.x2),i=Math.round(o.y-o.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:p}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),c=Math.round(o.x),r=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function mc(t){for(var e=new n1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var c=t.get(n),r=pc(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:r})}return e}function gc(t,e){var n=new n1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=Pt(Lt,t,e),n}function vc(t,e){for(var n=new n1.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),c=1/e.unitsPerEm,r={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[c,0,0,c,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},s=[],i,o=1;o<t.length;o+=1)i=t.get(o),s.push(i.name);var l=[];n.header=lc(),n.nameIndex=hc([e.postScriptName]);var h=R7(r,l);n.topDictIndex=F7(h),n.globalSubrIndex=fc(),n.charsets=dc(s,l),n.charStringsIndex=mc(t),n.privateDict=gc(a,l),n.stringIndex=uc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return r.charset=u,r.encoding=0,r.charStrings=r.charset+n.charsets.sizeOf(),r.private[1]=r.charStrings+n.charStringsIndex.sizeOf(),h=R7(r,l),n.topDictIndex=F7(h),n}var Tt={parse:oc,make:vc};function yc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.fontRevision=Math.round(c.parseFixed()*1e3)/1e3,n.checkSumAdjustment=c.parseULong(),n.magicNumber=c.parseULong(),k1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=c.parseUShort(),n.unitsPerEm=c.parseUShort(),n.created=c.parseLongDateTime(),n.modified=c.parseLongDateTime(),n.xMin=c.parseShort(),n.yMin=c.parseShort(),n.xMax=c.parseShort(),n.yMax=c.parseShort(),n.macStyle=c.parseUShort(),n.lowestRecPPEM=c.parseUShort(),n.fontDirectionHint=c.parseShort(),n.indexToLocFormat=c.parseShort(),n.glyphDataFormat=c.parseShort(),n}function bc(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new n1.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:n},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],t)}var Et={parse:yc,make:bc};function xc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.ascender=c.parseShort(),n.descender=c.parseShort(),n.lineGap=c.parseShort(),n.advanceWidthMax=c.parseUShort(),n.minLeftSideBearing=c.parseShort(),n.minRightSideBearing=c.parseShort(),n.xMaxExtent=c.parseShort(),n.caretSlopeRise=c.parseShort(),n.caretSlopeRun=c.parseShort(),n.caretOffset=c.parseShort(),c.relativeOffset+=8,n.metricDataFormat=c.parseShort(),n.numberOfHMetrics=c.parseUShort(),n}function Mc(t){return new n1.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],t)}var It={parse:xc,make:Mc};function wc(t,e,n,c,r){for(var a,s,i=new f1.Parser(t,e),o=0;o<c;o+=1){o<n&&(a=i.parseUShort(),s=i.parseShort());var l=r.get(o);l.advanceWidth=a,l.leftSideBearing=s}}function zc(t,e,n,c,r){t._hmtxTableData={};for(var a,s,i=new f1.Parser(e,n),o=0;o<r;o+=1)o<c&&(a=i.parseUShort(),s=i.parseShort()),t._hmtxTableData[o]={advanceWidth:a,leftSideBearing:s}}function kc(t,e,n,c,r,a,s){s.lowMemory?zc(t,e,n,c,r):wc(e,n,c,r,a)}function Sc(t){for(var e=new n1.Table("hmtx",[]),n=0;n<t.length;n+=1){var c=t.get(n),r=c.advanceWidth||0,a=c.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:r}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:a})}return e}var Vt={parse:kc,make:Sc};function Lc(t){for(var e=new n1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",c=12+t.length*4,r=0;r<t.length;++r){var a=n.indexOf(t[r]);a<0&&(a=n.length,n+=t[r]),e.fields.push({name:"offset "+r,type:"USHORT",value:c+a}),e.fields.push({name:"length "+r,type:"USHORT",value:t[r].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Ac(t,e){var n=new f1.Parser(t,e),c=n.parseULong();k1.argument(c===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var r=n.parseULong(),a=[],s=0;s<r;s++){for(var i="",o=e+n.parseUShort(),l=n.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(t.getInt8(h));a.push(i)}return a}var Ht={make:Lc,parse:Ac};function Cc(t,e){var n={},c=new f1.Parser(t,e);return n.version=c.parseVersion(),n.numGlyphs=c.parseUShort(),n.version===1&&(n.maxPoints=c.parseUShort(),n.maxContours=c.parseUShort(),n.maxCompositePoints=c.parseUShort(),n.maxCompositeContours=c.parseUShort(),n.maxZones=c.parseUShort(),n.maxTwilightPoints=c.parseUShort(),n.maxStorage=c.parseUShort(),n.maxFunctionDefs=c.parseUShort(),n.maxInstructionDefs=c.parseUShort(),n.maxStackElements=c.parseUShort(),n.maxSizeOfInstructions=c.parseUShort(),n.maxComponentElements=c.parseUShort(),n.maxComponentDepth=c.parseUShort()),n}function Pc(t){return new n1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var Ot={parse:Cc,make:Pc},Rt=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Ft={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},Tc={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},$t={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function Ec(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return Ft[e];case 3:return $t[e]}}var Oe="utf-16",Ic={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},Vc={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function Dt(t,e,n){switch(t){case 0:return Oe;case 1:return Vc[n]||Ic[e];case 3:if(e===1||e===10)return Oe;break}}function Hc(t,e,n){for(var c={},r=new f1.Parser(t,e),a=r.parseUShort(),s=r.parseUShort(),i=r.offset+r.parseUShort(),o=0;o<s;o++){var l=r.parseUShort(),h=r.parseUShort(),u=r.parseUShort(),f=r.parseUShort(),d=Rt[f]||f,p=r.parseUShort(),m=r.parseUShort(),g=Ec(l,u,n),v=Dt(l,h,u);if(v!==void 0&&g!==void 0){var y=void 0;if(v===Oe?y=O3.UTF16(t,i+m,p):y=O3.MACSTRING(t,i+m,p,v),y){var b=c[d];b===void 0&&(b=c[d]={}),b[g]=y}}}var x=0;return a===1&&(x=r.parseUShort()),c}function we(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function $7(t,e,n,c,r,a){return new n1.Record("NameRecord",[{name:"platformID",type:"USHORT",value:t},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:n},{name:"nameID",type:"USHORT",value:c},{name:"length",type:"USHORT",value:r},{name:"offset",type:"USHORT",value:a}])}function Oc(t,e){var n=t.length,c=e.length-n+1;e:for(var r=0;r<c;r++)for(;r<c;r++){for(var a=0;a<n;a++)if(e[r+a]!==t[a])continue e;return r}return-1}function D7(t,e){var n=Oc(t,e);if(n<0){n=e.length;for(var c=0,r=t.length;c<r;++c)e.push(t[c])}return n}function Rc(t,e){var n,c=[],r={},a=we(Rt);for(var s in t){var i=a[s];if(i===void 0&&(i=s),n=parseInt(i),isNaN(n))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');r[n]=t[s],c.push(n)}for(var o=we(Ft),l=we($t),h=[],u=[],f=0;f<c.length;f++){n=c[f];var d=r[n];for(var p in d){var m=d[p],g=1,v=o[p],y=Tc[v],b=Dt(g,y,v),x=K.MACSTRING(m,b);x===void 0&&(g=0,v=e.indexOf(p),v<0&&(v=e.length,e.push(p)),y=4,x=K.UTF16(m));var M=D7(x,u);h.push($7(g,y,v,n,x.length,M));var w=l[p];if(w!==void 0){var k=K.UTF16(m),z=D7(k,u);h.push($7(3,1,w,n,k.length,z))}}}h.sort(function(I,q){return I.platformID-q.platformID||I.encodingID-q.encodingID||I.languageID-q.languageID||I.nameID-q.nameID});for(var S=new n1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),L=0;L<h.length;L++)S.fields.push({name:"record_"+L,type:"RECORD",value:h[L]});return S.fields.push({name:"strings",type:"LITERAL",value:u}),S}var qt={parse:Hc,make:Rc},Re=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function Fc(t){for(var e=0;e<Re.length;e+=1){var n=Re[e];if(t>=n.begin&&t<n.end)return e}return-1}function $c(t,e){var n={},c=new f1.Parser(t,e);n.version=c.parseUShort(),n.xAvgCharWidth=c.parseShort(),n.usWeightClass=c.parseUShort(),n.usWidthClass=c.parseUShort(),n.fsType=c.parseUShort(),n.ySubscriptXSize=c.parseShort(),n.ySubscriptYSize=c.parseShort(),n.ySubscriptXOffset=c.parseShort(),n.ySubscriptYOffset=c.parseShort(),n.ySuperscriptXSize=c.parseShort(),n.ySuperscriptYSize=c.parseShort(),n.ySuperscriptXOffset=c.parseShort(),n.ySuperscriptYOffset=c.parseShort(),n.yStrikeoutSize=c.parseShort(),n.yStrikeoutPosition=c.parseShort(),n.sFamilyClass=c.parseShort(),n.panose=[];for(var r=0;r<10;r++)n.panose[r]=c.parseByte();return n.ulUnicodeRange1=c.parseULong(),n.ulUnicodeRange2=c.parseULong(),n.ulUnicodeRange3=c.parseULong(),n.ulUnicodeRange4=c.parseULong(),n.achVendID=String.fromCharCode(c.parseByte(),c.parseByte(),c.parseByte(),c.parseByte()),n.fsSelection=c.parseUShort(),n.usFirstCharIndex=c.parseUShort(),n.usLastCharIndex=c.parseUShort(),n.sTypoAscender=c.parseShort(),n.sTypoDescender=c.parseShort(),n.sTypoLineGap=c.parseShort(),n.usWinAscent=c.parseUShort(),n.usWinDescent=c.parseUShort(),n.version>=1&&(n.ulCodePageRange1=c.parseULong(),n.ulCodePageRange2=c.parseULong()),n.version>=2&&(n.sxHeight=c.parseShort(),n.sCapHeight=c.parseShort(),n.usDefaultChar=c.parseUShort(),n.usBreakChar=c.parseUShort(),n.usMaxContent=c.parseUShort()),n}function Dc(t){return new n1.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],t)}var Fe={parse:$c,make:Dc,unicodeRanges:Re,getUnicodeRange:Fc};function qc(t,e){var n={},c=new f1.Parser(t,e);switch(n.version=c.parseVersion(),n.italicAngle=c.parseFixed(),n.underlinePosition=c.parseShort(),n.underlineThickness=c.parseShort(),n.isFixedPitch=c.parseULong(),n.minMemType42=c.parseULong(),n.maxMemType42=c.parseULong(),n.minMemType1=c.parseULong(),n.maxMemType1=c.parseULong(),n.version){case 1:n.names=s3.slice();break;case 2:n.numberOfGlyphs=c.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var r=0;r<n.numberOfGlyphs;r++)n.glyphNameIndex[r]=c.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=s3.length){var s=c.parseChar();n.names.push(c.parseString(s))}break;case 2.5:n.numberOfGlyphs=c.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var i=0;i<n.numberOfGlyphs;i++)n.offset[i]=c.parseChar();break}return n}function Nc(){return new n1.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var Nt={parse:qc,make:Nc},s2=new Array(9);s2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(O.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(O.coverage),substitute:this.parseOffset16List()};k1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};s2[2]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),sequences:this.parseListOfLists()}};s2[3]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),alternateSets:this.parseListOfLists()}};s2[4]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var H3={sequenceIndex:O.uShort,lookupListIndex:O.uShort};s2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(O.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,H3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(O.coverage),classDef:this.parsePointer(O.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,H3)}})};if(n===3){var c=this.parseUShort(),r=this.parseUShort();return{substFormat:n,coverages:this.parseList(c,O.pointer(O.coverage)),lookupRecords:this.parseRecordList(r,H3)}}k1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};s2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(O.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(H3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(O.coverage),backtrackClassDef:this.parsePointer(O.classDef),inputClassDef:this.parsePointer(O.classDef),lookaheadClassDef:this.parsePointer(O.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(H3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(O.pointer(O.coverage)),inputCoverage:this.parseList(O.pointer(O.coverage)),lookaheadCoverage:this.parseList(O.pointer(O.coverage)),lookupRecords:this.parseRecordList(H3)};k1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};s2[7]=function(){var e=this.parseUShort();k1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),c=new O(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:s2[n].call(c)}};s2[8]=function(){var e=this.parseUShort();return k1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(O.coverage),backtrackCoverage:this.parseList(O.pointer(O.coverage)),lookaheadCoverage:this.parseList(O.pointer(O.coverage)),substitutes:this.parseUShortList()}};function Uc(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);return k1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(s2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(s2),variations:n.parseFeatureVariationsList()}}var R3=new Array(9);R3[1]=function(e){return e.substFormat===1?new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.ushortList("substitute",e.substitute)))};R3[2]=function(e){return k1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("seqSet",e.sequences,function(n){return new n1.Table("sequenceSetTable",n1.ushortList("sequence",n))})))};R3[3]=function(e){return k1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("altSet",e.alternateSets,function(n){return new n1.Table("alternateSetTable",n1.ushortList("alternate",n))})))};R3[4]=function(e){return k1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new n1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("ligSet",e.ligatureSets,function(n){return new n1.Table("ligatureSetTable",n1.tableList("ligature",n,function(c){return new n1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:c.ligGlyph}].concat(n1.ushortList("component",c.components,c.components.length+1)))}))})))};R3[6]=function(e){if(e.substFormat===1){var n=new n1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new n1.Coverage(e.coverage)}].concat(n1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new n1.Table("chainRuleSetTable",n1.tableList("chainRule",a,function(s){var i=n1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(n1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(n1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(n1.ushortList("substitution",[],s.lookupRecords.length));return s.lookupRecords.forEach(function(o,l){i=i.concat({name:"sequenceIndex"+l,type:"USHORT",value:o.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:o.lookupListIndex})}),new n1.Table("chainRuleTable",i)}))})));return n}else if(e.substFormat===2)k1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var c=[{name:"substFormat",type:"USHORT",value:e.substFormat}];c.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(a,s){c.push({name:"backtrackCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){c.push({name:"inputCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){c.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new n1.Coverage(a)})}),c.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){c=c.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var r=new n1.Table("chainContextTable",c);return r}k1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Bc(t){return new n1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new n1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new n1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new n1.LookupList(t.lookups,R3)}])}var Ut={parse:Uc,make:Bc};function _c(t,e){var n=new f1.Parser(t,e),c=n.parseULong();k1.argument(c===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var r=n.parseULong(),a={},s=0;s<r;s++){var i=n.parseTag(),o=n.parseULong(),l=n.parseULong(),h=O3.UTF8(t,e+o,l);a[i]=h}return a}function Gc(t){var e=Object.keys(t).length,n="",c=16+e*12,r=new n1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:c},{name:"numTags",type:"ULONG",value:e}]);for(var a in t){var s=n.length;n+=t[a],r.fields.push({name:"tag "+a,type:"TAG",value:a}),r.fields.push({name:"offset "+a,type:"ULONG",value:c+s}),r.fields.push({name:"length "+a,type:"ULONG",value:t[a].length})}return r.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),r}var Bt={parse:_c,make:Gc};function q7(t){return Math.log(t)/Math.log(2)|0}function Ge(t){for(;t.length%4!==0;)t.push(0);for(var e=0,n=0;n<t.length;n+=4)e+=(t[n]<<24)+(t[n+1]<<16)+(t[n+2]<<8)+t[n+3];return e%=Math.pow(2,32),e}function N7(t,e,n,c){return new n1.Record("Table Record",[{name:"tag",type:"TAG",value:t!==void 0?t:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:n!==void 0?n:0},{name:"length",type:"ULONG",value:c!==void 0?c:0}])}function _t(t){var e=new n1.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=t,e.numTables=t.length;var n=Math.pow(2,q7(e.numTables));e.searchRange=16*n,e.entrySelector=q7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],r=[],a=e.sizeOf()+N7().sizeOf()*e.numTables;a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var i=t[s];k1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=N7(i.tableName,Ge(i.encode()),a,o);for(c.push({name:l.tag+" Table Record",type:"RECORD",value:l}),r.push({name:i.tableName+" table",type:"RECORD",value:i}),a+=o,k1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,r.push({name:"padding",type:"BYTE",value:0})}return c.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(c),e.fields=e.fields.concat(r),e}function U7(t,e,n){for(var c=0;c<e.length;c+=1){var r=t.charToGlyphIndex(e[c]);if(r>0){var a=t.glyphs.get(r);return a.getMetrics()}}return n}function jc(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function Wc(t){for(var e=[],n=[],c=[],r=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,p=0;p<t.glyphs.length;p+=1){var m=t.glyphs.get(p),g=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+p+"): advanceWidth is not a number.");(o>g||o===void 0)&&g>0&&(o=g),l<g&&(l=g);var v=Fe.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(m.name!==".notdef"){var y=m.getMetrics();e.push(y.xMin),n.push(y.yMin),c.push(y.xMax),r.push(y.yMax),s.push(y.leftSideBearing),i.push(y.rightSideBearing),a.push(m.advanceWidth)}}var b={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,c),yMax:Math.max.apply(null,r),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:jc(a),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,i)};b.ascender=t.ascender,b.descender=t.descender;var x=Et.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=It.make({ascender:b.ascender,descender:b.descender,advanceWidthMax:b.advanceWidthMax,minLeftSideBearing:b.minLeftSideBearing,minRightSideBearing:b.minRightSideBearing,xMaxExtent:b.maxLeftSideBearing+(b.xMax-b.xMin),numberOfHMetrics:t.glyphs.length}),w=Ot.make(t.glyphs.length),k=Fe.make(Object.assign({xAvgCharWidth:Math.round(b.advanceWidthAvg),usFirstCharIndex:o,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:b.ascender,sTypoDescender:b.descender,sTypoLineGap:0,usWinAscent:b.yMax,usWinDescent:Math.abs(b.yMin),ulCodePageRange1:1,sxHeight:U7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:U7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=Vt.make(t.glyphs),S=bt.make(t.glyphs),L=t.getEnglishName("fontFamily"),I=t.getEnglishName("fontSubfamily"),q=L+" "+I,R=t.getEnglishName("postScriptName");R||(R=L.replace(/\s/g,"")+"-"+I);var N={};for(var G in t.names)N[G]=t.names[G];N.uniqueID||(N.uniqueID={en:t.getEnglishName("manufacturer")+":"+q}),N.postScriptName||(N.postScriptName={en:R}),N.preferredFamily||(N.preferredFamily=t.names.fontFamily),N.preferredSubfamily||(N.preferredSubfamily=t.names.fontSubfamily);var V=[],J=qt.make(N,V),o1=V.length>0?Ht.make(V):void 0,Z=Nt.make(),p1=Tt.make(t.glyphs,{version:t.getEnglishName("version"),fullName:q,familyName:L,weightName:I,postScriptName:R,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),E=t.metas&&Object.keys(t.metas).length>0?Bt.make(t.metas):void 0,$=[x,M,w,k,J,S,Z,p1,z];o1&&$.push(o1),t.tables.gsub&&$.push(Ut.make(t.tables.gsub)),E&&$.push(E);for(var X=_t($),j=X.encode(),w1=Ge(j),W1=X.fields,E1=!1,Z1=0;Z1<W1.length;Z1+=1)if(W1[Z1].name==="head table"){W1[Z1].value.checkSumAdjustment=2981146554-w1,E1=!0;break}if(!E1)throw new Error("Could not find head table with checkSum to adjust.");return X}var Xc={make:_t,fontToTable:Wc,computeCheckSum:Ge};function ze(t,e){for(var n=0,c=t.length-1;n<=c;){var r=n+c>>>1,a=t[r].tag;if(a===e)return r;a<e?n=r+1:c=r-1}return-n-1}function B7(t,e){for(var n=0,c=t.length-1;n<=c;){var r=n+c>>>1,a=t[r];if(a===e)return r;a<e?n=r+1:c=r-1}return-n-1}function _7(t,e){for(var n,c=0,r=t.length-1;c<=r;){var a=c+r>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?c=a+1:r=a-1}if(c>0)return n=t[c-1],e>n.end?0:n}function S5(t,e){this.font=t,this.tableName=e}S5.prototype={searchTag:ze,binSearch:B7,getTable:function(t){var e=this.font.tables[this.tableName];return!e&&t&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var t=this.getTable();return t?t.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var t=this.getTable();if(t){for(var e=!1,n=0;n<t.scripts.length;n++){var c=t.scripts[n].tag;if(c==="DFLT")return c;c==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var c=n.scripts,r=ze(n.scripts,t);if(r>=0)return c[r].script;if(e){var a={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return c.splice(-1-r,0,a),a.script}}},getLangSysTable:function(t,e,n){var c=this.getScriptTable(t,n);if(c){if(!e||e==="dflt"||e==="DFLT")return c.defaultLangSys;var r=ze(c.langSysRecords,e);if(r>=0)return c.langSysRecords[r].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return c.langSysRecords.splice(-1-r,0,a),a.langSys}}},getFeatureTable:function(t,e,n,c){var r=this.getLangSysTable(t,e,c);if(r){for(var a,s=r.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(a=i[s[o]],a.tag===n)return a.feature;if(c){var l=i.length;return k1.assert(l===0||n>=i[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},i.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,c,r){var a=this.getFeatureTable(t,e,n,r),s=[];if(a){for(var i,o=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===c&&s.push(i);if(s.length===0&&r){i={lookupType:c,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(i),o.push(u),[i]}}return s},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=_7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=B7(t.glyphs,e);return n>=0?n:-1;case 2:var c=_7(t.ranges,e);return c?c.index+e-c.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,c=0;c<n.length;c++)for(var r=n[c],a=r.start,s=r.end,i=a;i<=s;i++)e.push(i);return e}};function L5(t){S5.call(this,t,"gpos")}L5.prototype=S5.prototype;L5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};L5.prototype.getKerningValue=function(t,e,n){for(var c=0;c<t.length;c++)for(var r=t[c].subtables,a=0;a<r.length;a++){var s=r[a],i=this.getCoverageIndex(s.coverage,e);if(!(i<0))switch(s.posFormat){case 1:for(var o=s.pairSets[i],l=0;l<o.length;l++){var h=o[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};L5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function W0(t){S5.call(this,t,"gsub")}function Zc(t,e){var n=t.length;if(n!==e.length)return!1;for(var c=0;c<n;c++)if(t[c]!==e[c])return!1;return!0}function je(t,e,n){for(var c=t.subtables,r=0;r<c.length;r++){var a=c[r];if(a.substFormat===e)return a}if(n)return c.push(n),n}W0.prototype=S5.prototype;W0.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};W0.prototype.getSingle=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,1),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;if(o.substFormat===1){var u=o.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];c.push({sub:f,by:f+u})}}else{var d=o.substitute;for(h=0;h<l.length;h++)c.push({sub:l[h],by:d[h]})}}return c};W0.prototype.getMultiple=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,2),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=o.sequences[h];c.push({sub:u,by:f})}}return c};W0.prototype.getAlternates=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,3),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.alternateSets,u=0;u<l.length;u++)c.push({sub:l[u],by:h[u]});return c};W0.prototype.getLigatures=function(t,e,n){for(var c=[],r=this.getLookupTables(e,n,t,4),a=0;a<r.length;a++)for(var s=r[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],p=0;p<d.length;p++){var m=d[p];c.push({sub:[f].concat(m.components),by:m.ligGlyph})}return c};W0.prototype.addSingle=function(t,e,n,c){var r=this.getLookupTables(n,c,t,1,!0)[0],a=je(r,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});k1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.substitute.splice(i,0,0)),a.substitute[i]=e.by};W0.prototype.addMultiple=function(t,e,n,c){k1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var r=this.getLookupTables(n,c,t,2,!0)[0],a=je(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});k1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.sequences.splice(i,0,0)),a.sequences[i]=e.by};W0.prototype.addAlternate=function(t,e,n,c){var r=this.getLookupTables(n,c,t,3,!0)[0],a=je(r,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});k1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.alternateSets.splice(i,0,0)),a.alternateSets[i]=e.by};W0.prototype.addLigature=function(t,e,n,c){var r=this.getLookupTables(n,c,t,4,!0)[0],a=r.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},r.subtables[0]=a),k1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(Zc(h[u].components,i))return;h.push(o)}else l=-1-l,a.coverage.glyphs.splice(l,0,s),a.ligatureSets.splice(l,0,[o])};W0.prototype.getFeature=function(t,e,n){if(/ss\d\d/.test(t))return this.getSingle(t,e,n);switch(t){case"aalt":case"salt":return this.getSingle(t,e,n).concat(this.getAlternates(t,e,n));case"dlig":case"liga":case"rlig":return this.getLigatures(t,e,n);case"ccmp":return this.getMultiple(t,e,n).concat(this.getLigatures(t,e,n));case"stch":return this.getMultiple(t,e,n)}};W0.prototype.add=function(t,e,n,c){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,c);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,c):this.addAlternate(t,e,n,c);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,c);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,c):this.addLigature(t,e,n,c)}};function Yc(){return typeof window<"u"}function Jc(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),c=0;c<e.length;++c)e[c]=n[c];return e}function b5(t,e){if(!t)throw e}function G7(t,e,n,c,r){var a;return(e&c)>0?(a=t.parseByte(),(e&r)===0&&(a=-a),a=n+a):(e&r)>0?a=n:a=n+t.parseShort(),a}function Gt(t,e,n){var c=new f1.Parser(e,n);t.numberOfContours=c.parseShort(),t._xMin=c.parseShort(),t._yMin=c.parseShort(),t._xMax=c.parseShort(),t._yMax=c.parseShort();var r,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],i=0;i<t.numberOfContours;i+=1)s.push(c.parseUShort());t.instructionLength=c.parseUShort(),t.instructions=[];for(var o=0;o<t.instructionLength;o+=1)t.instructions.push(c.parseByte());var l=s[s.length-1]+1;r=[];for(var h=0;h<l;h+=1)if(a=c.parseByte(),r.push(a),(a&8)>0)for(var u=c.parseByte(),f=0;f<u;f+=1)r.push(a),h+=1;if(k1.argument(r.length===l,"Bad flags."),s.length>0){var d=[],p;if(l>0){for(var m=0;m<l;m+=1)a=r[m],p={},p.onCurve=!!(a&1),p.lastPointOfContour=s.indexOf(m)>=0,d.push(p);for(var g=0,v=0;v<l;v+=1)a=r[v],p=d[v],p.x=G7(c,a,g,2,16),g=p.x;for(var y=0,b=0;b<l;b+=1)a=r[b],p=d[b],p.y=G7(c,a,y,4,32),y=p.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){r=c.parseUShort();var M={glyphIndex:c.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(r&1)>0?(r&2)>0?(M.dx=c.parseShort(),M.dy=c.parseShort()):M.matchedPoints=[c.parseUShort(),c.parseUShort()]:(r&2)>0?(M.dx=c.parseChar(),M.dy=c.parseChar()):M.matchedPoints=[c.parseByte(),c.parseByte()],(r&8)>0?M.xScale=M.yScale=c.parseF2Dot14():(r&64)>0?(M.xScale=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()):(r&128)>0&&(M.xScale=c.parseF2Dot14(),M.scale01=c.parseF2Dot14(),M.scale10=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()),t.components.push(M),x=!!(r&32)}if(r&256){t.instructionLength=c.parseUShort(),t.instructions=[];for(var w=0;w<t.instructionLength;w+=1)t.instructions.push(c.parseByte())}}}function ke(t,e){for(var n=[],c=0;c<t.length;c+=1){var r=t[c],a={x:e.xScale*r.x+e.scale01*r.y+e.dx,y:e.scale10*r.x+e.yScale*r.y+e.dy,onCurve:r.onCurve,lastPointOfContour:r.lastPointOfContour};n.push(a)}return n}function Kc(t){for(var e=[],n=[],c=0;c<t.length;c+=1){var r=t[c];n.push(r),r.lastPointOfContour&&(e.push(n),n=[])}return k1.argument(n.length===0,"There are still points left in the current contour."),e}function jt(t){var e=new M0;if(!t)return e;for(var n=Kc(t),c=0;c<n.length;++c){var r=n[c],a=null,s=r[r.length-1],i=r[0];if(s.onCurve)e.moveTo(s.x,s.y);else if(i.onCurve)e.moveTo(i.x,i.y);else{var o={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5};e.moveTo(o.x,o.y)}for(var l=0;l<r.length;++l)if(a=s,s=i,i=r[(l+1)%r.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=a,u=i;a.onCurve||(h={x:(s.x+a.x)*.5,y:(s.y+a.y)*.5}),i.onCurve||(u={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5}),e.quadraticCurveTo(s.x,s.y,u.x,u.y)}e.closePath()}return e}function Wt(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var c=e.components[n],r=t.get(c.glyphIndex);if(r.getPath(),r.points){var a=void 0;if(c.matchedPoints===void 0)a=ke(r.points,c);else{if(c.matchedPoints[0]>e.points.length-1||c.matchedPoints[1]>r.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[c.matchedPoints[0]],i=r.points[c.matchedPoints[1]],o={xScale:c.xScale,scale01:c.scale01,scale10:c.scale10,yScale:c.yScale,dx:0,dy:0};i=ke([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=ke(r.points,o)}e.points=e.points.concat(a)}}return jt(e.points)}function Qc(t,e,n,c){for(var r=new M2.GlyphSet(c),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?r.push(a,M2.ttfGlyphLoader(c,a,Gt,t,e+s,Wt)):r.push(a,M2.glyphLoader(c,a))}return r}function er(t,e,n,c){var r=new M2.GlyphSet(c);return c._push=function(a){var s=n[a],i=n[a+1];s!==i?r.push(a,M2.ttfGlyphLoader(c,a,Gt,t,e+s,Wt)):r.push(a,M2.glyphLoader(c,a))},r}function tr(t,e,n,c,r){return r.lowMemory?er(t,e,n,c):Qc(t,e,n,c)}var Xt={getPath:jt,parse:tr},Zt,o3,Yt,$e;function Jt(t){this.font=t,this.getCommands=function(e){return Xt.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function nr(t){return t}function Kt(t){return Math.sign(t)*Math.round(Math.abs(t))}function cr(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function rr(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function ar(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function sr(t){return Math.sign(t)*Math.floor(Math.abs(t))}var Qt=function(t){var e=this.srPeriod,n=this.srPhase,c=this.srThreshold,r=1;return t<0&&(t=-t,r=-1),t+=c-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*r:t*r},x2={x:1,y:0,axis:"x",distance:function(t,e,n,c){return(n?t.xo:t.x)-(c?e.xo:e.x)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.xo-e.xo,a=t.xo-n.xo,o=e.x-e.xo,l=n.x-n.xo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.x=t.xo+(o+l)/2;return}t.x=t.xo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){x2.setRelative(t,t,(o+l)/2,c,!0);return}x2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,c,r){if(!c||c===this){t.x=(r?e.xo:e.x)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.x=i+(t.y-o)/c.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},E2={x:0,y:1,axis:"y",distance:function(t,e,n,c){return(n?t.yo:t.y)-(c?e.yo:e.y)},interpolate:function(t,e,n,c){var r,a,s,i,o,l,h;if(!c||c===this){if(r=t.yo-e.yo,a=t.yo-n.yo,o=e.y-e.yo,l=n.y-n.yo,s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){t.y=t.yo+(o+l)/2;return}t.y=t.yo+(o*i+l*s)/h;return}if(r=c.distance(t,e,!0,!0),a=c.distance(t,n,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(n,n,!1,!0),s=Math.abs(r),i=Math.abs(a),h=s+i,h===0){E2.setRelative(t,t,(o+l)/2,c,!0);return}E2.setRelative(t,t,(o*i+l*s)/h,c,!0)},normalSlope:0,setRelative:function(t,e,n,c,r){if(!c||c===this){t.y=(r?e.yo:e.y)+n;return}var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y;t.y=o+c.normalSlope*(t.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(x2);Object.freeze(E2);function A5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}A5.prototype.distance=function(t,e,n,c){return this.x*x2.distance(t,e,n,c)+this.y*E2.distance(t,e,n,c)};A5.prototype.interpolate=function(t,e,n,c){var r,a,s,i,o,l,h;if(s=c.distance(t,e,!0,!0),i=c.distance(t,n,!0,!0),r=c.distance(e,e,!1,!0),a=c.distance(n,n,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(t,t,(r+a)/2,c,!0);return}this.setRelative(t,t,(r*l+a*o)/h,c,!0)};A5.prototype.setRelative=function(t,e,n,c,r){c=c||this;var a=r?e.xo:e.x,s=r?e.yo:e.y,i=a+n*c.x,o=s+n*c.y,l=c.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*i+o-f)/(h-l),t.y=h*(t.x-u)+f};A5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function C5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?x2:t===0&&e===1?E2:new A5(t,e)}function I2(t,e,n,c){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=c,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}I2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};I2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var k5=Object.freeze(new I2(0,0)),ir={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function G2(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=x2,this.round=Kt}}Jt.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,c=this._prepState;if(!c||c.ppem!==e){var r=this._fpgmState;if(!r){G2.prototype=ir,r=this._fpgmState=new G2("fpgm",n.tables.fpgm),r.funcs=[],r.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),r.step=-1);try{o3(r)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}G2.prototype=r,c=this._prepState=new G2("prep",n.tables.prep),c.ppem=e;var a=n.tables.cvt;if(a)for(var s=c.cvt=new Array(a.length),i=e/n.unitsPerEm,o=0;o<a.length;o++)s[o]=a[o]*i;else c.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),c.step=-1);try{o3(c)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return Yt(t,c)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};Yt=function(t,e){var n=e.ppem/e.font.unitsPerEm,c=n,r=t.components,a,s,i;if(G2.prototype=e,!r)i=new G2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),$e(t,i,n,c),s=i.gZone;else{var o=e.font;s=[],a=[];for(var l=0;l<r.length;l++){var h=r[l],u=o.glyphs.get(h.glyphIndex);i=new G2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),$e(u,i,n,c);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*c),p=i.gZone,m=i.contours,g=0;g<p.length;g++){var v=p[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,p);for(var b=0;b<m.length;b++)a.push(m[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new G2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new I2(0,0),new I2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),o3(i),s.length-=2)}return s};$e=function(t,e,n,c){for(var r=t.points||[],a=r.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<a;l++)o=r[l],s[l]=new I2(o.x*n,o.y*c,o.lastPointOfContour,o.onCurve);for(var h,u,f=0;f<a;f++)o=s[f],h||(h=o,i.push(f)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(u=s[f+1],o.nextPointOnContour=u,u.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new I2(0,0),new I2(Math.round(t.advanceWidth*n),0)),o3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var p=0;p<a;p++)console.log(p,s[p].x,s[p].y)}}};o3=function(t){var e=t.prog;if(e){var n=e.length,c;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,c=Zt[e[t.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));c(t)}}};function y4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new I2(0,0)}function e8(t,e){var n=t.prog,c=t.ip,r=1,a;do if(a=n[++c],a===88)r++;else if(a===89)r--;else if(a===64)c+=n[c+1]+1;else if(a===65)c+=2*n[c+1]+1;else if(a>=176&&a<=183)c+=a-176+1;else if(a>=184&&a<=191)c+=(a-184+1)*2;else if(e&&r===1&&a===27)break;while(r>0);t.ip=c}function j7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function W7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function X7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function Z7(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.pv=e.dpv=C5(i,o)}function Y7(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log("SFVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.fv=C5(i,o)}function or(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.pv=t.dpv=C5(c,n)}function lr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,c),t.fv=C5(c,n)}function hr(t){var e=t.stack,n=t.pv;exports.DEBUG&&console.log(t.step,"GPV[]"),e.push(n.x*16384),e.push(n.y*16384)}function ur(t){var e=t.stack,n=t.fv;exports.DEBUG&&console.log(t.step,"GFV[]"),e.push(n.x*16384),e.push(n.y*16384)}function fr(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function dr(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop(),a=e.pop(),s=e.pop(),i=t.z0,o=t.z1,l=i[n],h=i[c],u=o[r],f=o[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,c,r,a,s);var p=l.x,m=l.y,g=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,w=(p-g)*(b-M)-(m-v)*(y-x),k=p*v-m*g,z=y*M-b*x;d.x=(k*(y-x)-z*(p-g))/w,d.y=(k*(b-M)-z*(m-v))/w}function pr(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function mr(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function gr(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function vr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||y4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function yr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||y4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function br(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||y4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function xr(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZPS[]",e),t.zp0=t.zp1=t.zp2=e,e){case 0:t.tZone||y4(t),t.z0=t.z1=t.z2=t.tZone;break;case 1:t.z0=t.z1=t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function Mr(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function wr(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=Kt}function zr(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=rr}function kr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function Sr(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),e8(t,!1)}function Lr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Ar(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Cr(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function Se(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function Pr(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Tr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(c)}function Er(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Ir(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,c);var r=t.ip,a=t.prog;t.prog=t.funcs[n];for(var s=0;s<c;s++)o3(t),exports.DEBUG&&console.log(++t.step,s+1<c?"next loopcall":"done loopcall",s);t.ip=r,t.prog=a}function Vr(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,c=t.prog;t.prog=t.funcs[e],o3(t),t.ip=n,t.prog=c,exports.DEBUG&&console.log(++t.step,"returning from",e)}function Hr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Or(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"MINDEX[]",n),e.push(e.splice(e.length-n,1)[0])}function Rr(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,c=t.ip,r=e.pop(),a=c;for(exports.DEBUG&&console.log(t.step,"FDEF[]",r);n[++c]!==45;);t.ip=c,t.funcs[r]=n.slice(a+1,c)}function J7(t,e){var n=e.stack.pop(),c=e.z0[n],r=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(c,k5);t&&(s=e.round(s)),r.setRelative(c,k5,s,a),r.touch(c),e.rp0=e.rp1=n}function K7(t,e){var n=e.z2,c=n.length-2,r,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var i=0;i<c;i++)r=n[i],!t.touched(r)&&(a=r.prevTouched(t),a!==r&&(s=r.nextTouched(t),a===s&&t.setRelative(r,r,t.distance(a,a,!1,!0),t,!0),t.interpolate(r,a,s,t)))}function Q7(t,e){for(var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=e.loop,o=e.z2;i--;){var l=n.pop(),h=o[l],u=s.distance(r,r,!1,!0);a.setRelative(h,h,u,s),a.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-i)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function et(t,e){var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=n.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",i);var h=s.distance(r,r,!1,!0);do l!==r&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function tt(t,e){var n=e.stack,c=t?e.rp1:e.rp2,r=(t?e.z0:e.z1)[c],a=e.fv,s=e.pv,i=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",i);var o;switch(i){case 0:o=e.tZone;break;case 1:o=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=s.distance(r,r,!1,!0),u=o.length-2,f=0;f<u;f++)l=o[f],a.setRelative(l,l,h,s)}function Fr(t){for(var e=t.stack,n=t.loop,c=t.fv,r=e.pop()/64,a=t.z2;n--;){var s=e.pop(),i=a[s];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",s,r),c.setRelative(i,i,r),c.touch(i)}t.loop=1}function $r(t){for(var e=t.stack,n=t.rp1,c=t.rp2,r=t.loop,a=t.z0[n],s=t.z1[c],i=t.fv,o=t.dpv,l=t.z2;r--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-r)+": ":"")+"IP[]",h,n,"<->",c),i.interpolate(u,a,s,o),i.touch(u)}t.loop=1}function nt(t,e){var n=e.stack,c=n.pop()/64,r=n.pop(),a=e.z1[r],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(a,s,c,o),i.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",c,r),e.rp1=e.rp0,e.rp2=r,t&&(e.rp0=r)}function Dr(t){for(var e=t.stack,n=t.rp0,c=t.z0[n],r=t.loop,a=t.fv,s=t.pv,i=t.z1;r--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-r)+": ":"")+"ALIGNRP[]",o),a.setRelative(l,c,0,s),a.touch(l)}t.loop=1}function qr(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=cr}function ct(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z0[r],s=e.fv,i=e.pv,o=e.cvt[c];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",c,"(",o,")",r);var l=i.distance(a,k5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,k5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=r}function Nr(t){var e=t.prog,n=t.ip,c=t.stack,r=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",r);for(var a=0;a<r;a++)c.push(e[++n]);t.ip=n}function Ur(t){var e=t.ip,n=t.prog,c=t.stack,r=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",r);for(var a=0;a<r;a++){var s=n[++e]<<8|n[++e];s&32768&&(s=-((s^65535)+1)),c.push(s)}t.ip=e}function Br(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var c=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WS",c,r),n[r]=c}function _r(t){var e=t.stack,n=t.store,c=e.pop();exports.DEBUG&&console.log(t.step,"RS",c);var r=n&&n[c]||0;e.push(r)}function Gr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,c),t.cvt[c]=n/64}function jr(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function rt(t,e){var n=e.stack,c=n.pop(),r=e.z2[c];exports.DEBUG&&console.log(e.step,"GC["+t+"]",c),n.push(e.dpv.distance(r,k5,t,!1)*64)}function at(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z1[c],s=e.z0[r],i=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",c,r,"->",i),e.stack.push(Math.round(i*64))}function Wr(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Xr(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Zr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,c),e.push(c<n?1:0)}function Yr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,c),e.push(c<=n?1:0)}function Jr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,c),e.push(c>n?1:0)}function Kr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,c),e.push(c>=n?1:0)}function Qr(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,c),e.push(n===c?1:0)}function ea(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,c),e.push(n!==c?1:0)}function ta(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ODD[]",n),e.push(Math.trunc(n)%2?1:0)}function na(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"EVEN[]",n),e.push(Math.trunc(n)%2?0:1)}function ca(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(e8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function ra(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function aa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,c),e.push(n&&c?1:0)}function sa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,c),e.push(n||c?1:0)}function ia(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function Le(t,e){var n=e.stack,c=n.pop(),r=e.fv,a=e.pv,s=e.ppem,i=e.deltaBase+(t-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",c,n);for(var h=0;h<c;h++){var u=n.pop(),f=n.pop(),d=i+((f&240)>>4);if(d===s){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",p*o);var m=l[u];r.setRelative(m,m,p*o,a)}}}function oa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function la(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function ha(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,c),e.push(c+n)}function ua(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,c),e.push(c-n)}function fa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,c),e.push(c*64/n)}function da(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,c),e.push(c*n/64)}function pa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function ma(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function ga(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function va(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function l4(t,e){var n=e.stack,c=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(c/64)*64)}function ya(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,c),t.cvt[c]=n*t.ppem/t.font.unitsPerEm}function Ae(t,e){var n=e.stack,c=n.pop(),r=e.ppem,a=e.deltaBase+(t-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",c,n);for(var i=0;i<c;i++){var o=n.pop(),l=n.pop(),h=a+((l&240)>>4);if(h===r){var u=(l&15)-8;u>=0&&u++;var f=u*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",o,"by",f),e.cvt[o]+=f}}}function ba(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=Qt;var n;switch(e&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw new Error("invalid SROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function xa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=Qt;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Ma(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=nr}function wa(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=ar}function za(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=sr}function ka(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function st(t,e){var n=e.stack,c=n.pop(),r=n.pop(),a=e.z2[c],s=e.z1[r];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",c,r);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.dpv=C5(i,o)}function Sa(t){var e=t.stack,n=e.pop(),c=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(c=35),n&32&&(c|=4096),e.push(c)}function La(t){var e=t.stack,n=e.pop(),c=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(c),e.push(n),e.push(r)}function Aa(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,c),e.push(Math.max(c,n))}function Ca(t){var e=t.stack,n=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,c),e.push(Math.min(c,n))}function Pa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ta(t){var e=t.stack.pop(),n=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"INSTCTRL[]",e,n),e){case 1:t.inhibitGridFit=!!n;return;case 2:t.ignoreCvt=!!n;return;default:throw new Error("invalid INSTCTRL[] selector")}}function U2(t,e){var n=e.stack,c=e.prog,r=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(c[++r]);e.ip=r}function B2(t,e){var n=e.ip,c=e.prog,r=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=c[++n]<<8|c[++n];s&32768&&(s=-((s^65535)+1)),r.push(s)}e.ip=n}function h1(t,e,n,c,r,a){var s=a.stack,i=t&&s.pop(),o=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[o],f=a.minDis,d=a.fv,p=a.dpv,m,g,v,y;g=m=p.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(y=a.cvt[i],c&&Math.abs(g-y)<a.cvCutIn&&(g=y)),n&&g<f&&(g=f),c&&(g=a.round(g)),d.setRelative(u,h,v*g,p),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(c?"R":"_")+(r===0?"Gr":r===1?"Bl":r===2?"Wh":"")+"]",t?i+"("+a.cvt[i]+","+y+")":"",o,"(d =",m,"->",v*g,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}Zt=[j7.bind(void 0,E2),j7.bind(void 0,x2),W7.bind(void 0,E2),W7.bind(void 0,x2),X7.bind(void 0,E2),X7.bind(void 0,x2),Z7.bind(void 0,0),Z7.bind(void 0,1),Y7.bind(void 0,0),Y7.bind(void 0,1),or,lr,hr,ur,fr,dr,pr,mr,gr,vr,yr,br,xr,Mr,wr,zr,kr,Sr,Lr,Ar,void 0,void 0,Cr,Se,Pr,Tr,Er,Hr,Or,void 0,void 0,void 0,Ir,Vr,Rr,void 0,J7.bind(void 0,0),J7.bind(void 0,1),K7.bind(void 0,E2),K7.bind(void 0,x2),Q7.bind(void 0,0),Q7.bind(void 0,1),et.bind(void 0,0),et.bind(void 0,1),tt.bind(void 0,0),tt.bind(void 0,1),Fr,$r,nt.bind(void 0,0),nt.bind(void 0,1),Dr,qr,ct.bind(void 0,0),ct.bind(void 0,1),Nr,Ur,Br,_r,Gr,jr,rt.bind(void 0,0),rt.bind(void 0,1),void 0,at.bind(void 0,0),at.bind(void 0,1),Wr,void 0,Xr,void 0,void 0,Zr,Yr,Jr,Kr,Qr,ea,ta,na,ca,ra,aa,sa,ia,Le.bind(void 0,1),oa,la,ha,ua,fa,da,pa,ma,ga,va,l4.bind(void 0,0),l4.bind(void 0,1),l4.bind(void 0,2),l4.bind(void 0,3),void 0,void 0,void 0,void 0,ya,Le.bind(void 0,2),Le.bind(void 0,3),Ae.bind(void 0,1),Ae.bind(void 0,2),Ae.bind(void 0,3),ba,xa,void 0,void 0,Ma,void 0,wa,za,Se,Se,void 0,void 0,void 0,void 0,void 0,ka,st.bind(void 0,0),st.bind(void 0,1),Sa,void 0,La,Aa,Ca,Pa,Ta,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,U2.bind(void 0,1),U2.bind(void 0,2),U2.bind(void 0,3),U2.bind(void 0,4),U2.bind(void 0,5),U2.bind(void 0,6),U2.bind(void 0,7),U2.bind(void 0,8),B2.bind(void 0,1),B2.bind(void 0,2),B2.bind(void 0,3),B2.bind(void 0,4),B2.bind(void 0,5),B2.bind(void 0,6),B2.bind(void 0,7),B2.bind(void 0,8),h1.bind(void 0,0,0,0,0,0),h1.bind(void 0,0,0,0,0,1),h1.bind(void 0,0,0,0,0,2),h1.bind(void 0,0,0,0,0,3),h1.bind(void 0,0,0,0,1,0),h1.bind(void 0,0,0,0,1,1),h1.bind(void 0,0,0,0,1,2),h1.bind(void 0,0,0,0,1,3),h1.bind(void 0,0,0,1,0,0),h1.bind(void 0,0,0,1,0,1),h1.bind(void 0,0,0,1,0,2),h1.bind(void 0,0,0,1,0,3),h1.bind(void 0,0,0,1,1,0),h1.bind(void 0,0,0,1,1,1),h1.bind(void 0,0,0,1,1,2),h1.bind(void 0,0,0,1,1,3),h1.bind(void 0,0,1,0,0,0),h1.bind(void 0,0,1,0,0,1),h1.bind(void 0,0,1,0,0,2),h1.bind(void 0,0,1,0,0,3),h1.bind(void 0,0,1,0,1,0),h1.bind(void 0,0,1,0,1,1),h1.bind(void 0,0,1,0,1,2),h1.bind(void 0,0,1,0,1,3),h1.bind(void 0,0,1,1,0,0),h1.bind(void 0,0,1,1,0,1),h1.bind(void 0,0,1,1,0,2),h1.bind(void 0,0,1,1,0,3),h1.bind(void 0,0,1,1,1,0),h1.bind(void 0,0,1,1,1,1),h1.bind(void 0,0,1,1,1,2),h1.bind(void 0,0,1,1,1,3),h1.bind(void 0,1,0,0,0,0),h1.bind(void 0,1,0,0,0,1),h1.bind(void 0,1,0,0,0,2),h1.bind(void 0,1,0,0,0,3),h1.bind(void 0,1,0,0,1,0),h1.bind(void 0,1,0,0,1,1),h1.bind(void 0,1,0,0,1,2),h1.bind(void 0,1,0,0,1,3),h1.bind(void 0,1,0,1,0,0),h1.bind(void 0,1,0,1,0,1),h1.bind(void 0,1,0,1,0,2),h1.bind(void 0,1,0,1,0,3),h1.bind(void 0,1,0,1,1,0),h1.bind(void 0,1,0,1,1,1),h1.bind(void 0,1,0,1,1,2),h1.bind(void 0,1,0,1,1,3),h1.bind(void 0,1,1,0,0,0),h1.bind(void 0,1,1,0,0,1),h1.bind(void 0,1,1,0,0,2),h1.bind(void 0,1,1,0,0,3),h1.bind(void 0,1,1,0,1,0),h1.bind(void 0,1,1,0,1,1),h1.bind(void 0,1,1,0,1,2),h1.bind(void 0,1,1,0,1,3),h1.bind(void 0,1,1,1,0,0),h1.bind(void 0,1,1,1,0,1),h1.bind(void 0,1,1,1,0,2),h1.bind(void 0,1,1,1,0,3),h1.bind(void 0,1,1,1,1,0),h1.bind(void 0,1,1,1,1,1),h1.bind(void 0,1,1,1,1,2),h1.bind(void 0,1,1,1,1,3)];function F3(t){this.char=t,this.state={},this.activeState=null}function We(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function Ea(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function i2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function b4(t){this.eventId=t,this.subscribers=[]}function Ia(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(r){Object.defineProperty(e.events,r,{value:new b4(r)})}),t&&n.forEach(function(r){var a=t[r];typeof a=="function"&&e.events[r].subscribe(a)});var c=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];c.forEach(function(r){e.events[r].subscribe(e.updateContextsRanges)})}function u0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Ia.call(this,t)}F3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};F3.prototype.getState=function(t){return this.state[t]||null};u0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};u0.prototype.composeRUD=function(t){var e=this,n=!0,c=t.map(function(a){return e[a[0]].apply(e,a.slice(1).concat(n))}),r=function(a){return typeof a=="object"&&a.hasOwnProperty("FAIL")};if(c.every(r))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:c.filter(r)};this.dispatch("composeRUD",[c.filter(function(a){return!r(a)})])};u0.prototype.replaceRange=function(t,e,n,c){e=e!==null?e:this.tokens.length;var r=n.every(function(s){return s instanceof F3});if(!isNaN(t)&&this.inboundIndex(t)&&r){var a=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return c||this.dispatch("replaceToken",[t,e,n]),[a,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};u0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof F3){var c=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[c[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};u0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var c=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[c,t,e]),c};u0.prototype.removeToken=function(t,e){if(!isNaN(t)&&this.inboundIndex(t)){var n=this.tokens.splice(t,1);return e||this.dispatch("removeToken",[n,t]),n}else return{FAIL:"removeToken: invalid token index."}};u0.prototype.insertToken=function(t,e,n){var c=t.every(function(r){return r instanceof F3});return c?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};u0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(c,r){var a=[c,r],s=e===null||e.apply(this,a)===!0,i=[c,r];if(s){var o=n.apply(this,i);c.setState(t,o)}}),this.registeredModifiers.push(t)};b4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};b4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};i2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};i2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};u0.prototype.rangeToText=function(t){if(t instanceof We)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};u0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};u0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};u0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};u0.prototype.dispatch=function(t,e){var n=this,c=this.events[t];c instanceof b4&&c.subscribers.forEach(function(r){r.apply(n,e||[])})};u0.prototype.registerContextChecker=function(t,e,n){if(this.getContext(t))return{FAIL:"context name '"+t+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof n!="function")return{FAIL:"missing context end check."};var c=new Ea(t,e,n);return this.registeredContexts[t]=c,this.contextCheckers.push(c),c};u0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};u0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};u0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};u0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(c){return c.char}),e=0;e<t.length;e++){var n=new i2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};u0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,c=new We(n,t,e),r=this.getContext(e).ranges;return c.rangeId=e+"."+r.length,r.push(c),this.getContext(e).openRange=null,c};u0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(c){var r=c.contextName,a=e.getContext(r).openRange;if(!a&&c.checkStart(t)&&(a=new We(n,null,r),e.getContext(r).openRange=a,e.dispatch("contextStart",[r,n])),a&&c.checkEnd(t)){var s=n-a.startIndex+1,i=e.setEndOffset(s,r);e.dispatch("contextEnd",[r,i])}})};u0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var c=e[n],r=new i2(e,n);this.dispatch("next",[r]),this.runContextCheck(r);var a=new F3(c);this.tokens.push(a),this.dispatch("newToken",[a,r])}return this.dispatch("end",[this.tokens]),this.tokens};function j2(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function t8(t){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(t)}function W2(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function u4(t){return/[A-z]/.test(t)}function Va(t){return/\s/.test(t)}function X0(t){this.font=t,this.features={}}function i3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function P5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,c=0;c<n.length;c++){var r=n[c];if(t>=r.start&&t<=r.end){var a=t-r.start;return r.index+a}}break;default:return-1}return-1}function Ha(t,e){var n=P5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Oa(t,e){var n=P5(t,e.coverage);return n===-1?null:e.substitute[n]}function Ce(t,e){for(var n=[],c=0;c<t.length;c++){var r=t[c],a=e.current;a=Array.isArray(a)?a[0]:a;var s=P5(a,r);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function Ra(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var c=Ce(e.inputCoverage,t);if(c===-1)return[];var r=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(r);a.length&&W2(a[0].char);)a.shift();var s=new i2(a,0),i=Ce(e.lookaheadCoverage,s),o=[].concat(t.backtrack);for(o.reverse();o.length&&W2(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new i2(o,0),h=Ce(e.backtrackCoverage,l),u=c.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var p=e.lookupRecords[d],m=p.lookupListIndex,g=this.getLookupByIndex(m),v=0;v<g.subtables.length;v++){var y=g.subtables[v],b=this.getLookupMethod(g,y),x=this.getSubstitutionType(g,y);if(x==="12")for(var M=0;M<c.length;M++){var w=t.get(M),k=b(w);k&&f.push(k)}}return f}function Fa(t,e){var n=t.current,c=P5(n,e.coverage);if(c===-1)return null;for(var r,a=e.ligatureSets[c],s=0;s<a.length;s++){r=a[s];for(var i=0;i<r.components.length;i++){var o=t.lookahead[i],l=r.components[i];if(o!==l)break;if(i===r.components.length-1)return r}}return null}function $a(t,e){var n=P5(t,e.coverage);return n===-1?null:e.sequences[n]}X0.prototype.getDefaultScriptFeaturesIndexes=function(){for(var t=this.font.tables.gsub.scripts,e=0;e<t.length;e++){var n=t[e];if(n.tag==="DFLT")return n.script.defaultLangSys.featureIndexes}return[]};X0.prototype.getScriptFeaturesIndexes=function(t){var e=this.font.tables;if(!e.gsub)return[];if(!t)return this.getDefaultScriptFeaturesIndexes();for(var n=this.font.tables.gsub.scripts,c=0;c<n.length;c++){var r=n[c];if(r.tag===t&&r.script.defaultLangSys)return r.script.defaultLangSys.featureIndexes;var a=r.langSysRecords;if(a)for(var s=0;s<a.length;s++){var i=a[s];if(i.tag===t){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};X0.prototype.mapTagsToFeatures=function(t,e){for(var n={},c=0;c<t.length;c++){var r=t[c].tag,a=t[c].feature;n[r]=a}this.features[e].tags=n};X0.prototype.getScriptFeatures=function(t){var e=this.features[t];if(this.features.hasOwnProperty(t))return e;var n=this.getScriptFeaturesIndexes(t);if(!n)return null;var c=this.font.tables.gsub;return e=n.map(function(r){return c.features[r]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};X0.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),c=e.substFormat.toString();return n+c};X0.prototype.getLookupMethod=function(t,e){var n=this,c=this.getSubstitutionType(t,e);switch(c){case"11":return function(r){return Ha.apply(n,[r,e])};case"12":return function(r){return Oa.apply(n,[r,e])};case"63":return function(r){return Ra.apply(n,[r,e])};case"41":return function(r){return Fa.apply(n,[r,e])};case"21":return function(r){return $a.apply(n,[r,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};X0.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,c=this.getFeature({tag:t.tag,script:t.script});if(!c)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var r=this.getFeatureLookups(c),a=[].concat(e.context),s=0;s<r.length;s++)for(var i=r[s],o=this.getLookupSubtables(i),l=0;l<o.length;l++){var h=o[l],u=this.getSubstitutionType(i,h),f=this.getLookupMethod(i,h),d=void 0;switch(u){case"11":d=f(e.current),d&&a.splice(n,1,new i3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new i3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new i3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new i3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new i3({id:21,tag:t.tag,substitution:d}));break}e=new i2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};X0.prototype.supports=function(t){if(!t.script)return!1;this.getScriptFeatures(t.script);var e=this.features.hasOwnProperty(t.script);if(!t.tag)return e;var n=this.features[t.script].some(function(c){return c.tag===t.tag});return e&&n};X0.prototype.getLookupSubtables=function(t){return t.subtables||null};X0.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};X0.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};X0.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var n=this.features[e.script];return n?n.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function Da(t){var e=t.current,n=t.get(-1);return n===null&&j2(e)||!j2(n)&&j2(e)}function qa(t){var e=t.get(1);return e===null||!j2(e)}var Na={startCheck:Da,endCheck:qa};function Ua(t){var e=t.current,n=t.get(-1);return(j2(e)||W2(e))&&!j2(n)}function Ba(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!j2(e)&&!W2(e)):var n=Va(e);if(!n)return!0;if(n){var c=!1;if(c=t.lookahead.some(function(r){return j2(r)||W2(r)}),!c)return!0}break;default:return!1}}var _a={startCheck:Ua,endCheck:Ba};function Ga(t,e,n){e[n].setState(t.tag,t.substitution)}function ja(t,e,n){e[n].setState(t.tag,t.substitution)}function Wa(t,e,n){t.substitution.forEach(function(c,r){var a=e[n+r];a.setState(t.tag,c)})}function Xa(t,e,n){var c=e[n];c.setState(t.tag,t.substitution.ligGlyph);for(var r=t.substitution.components.length,a=0;a<r;a++)c=e[n+a+1],c.setState("deleted",!0)}var it={11:Ga,12:ja,63:Wa,41:Xa};function Xe(t,e,n){t instanceof i3&&it[t.id]&&it[t.id](t,e,n)}function Za(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var c=e[n],r=t8(c),a=W2(c);if(!r&&!a)return!0;if(r)return!1}return!1}function Ya(t){if(t8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],c=W2(n);if(!c)return!0}return!1}function Ja(t){var e=this,n="arab",c=this.featuresTags[n],r=this.tokenizer.getRangeTokens(t);if(r.length!==1){var a=new i2(r.map(function(i){return i.getState("glyphIndex")}),0),s=new i2(r.map(function(i){return i.char}),0);r.forEach(function(i,o){if(!W2(i.char)){a.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;Za(s)&&(l|=1),Ya(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(c.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof i3&&(Xe(f,r,d),a.context[d]=f.substitution)})}}})}}function ot(t,e){var n=t.map(function(c){return c.activeState.value});return new i2(n,e||0)}function Ka(t){var e=this,n="arab",c=this.tokenizer.getRangeTokens(t),r=ot(c);r.context.forEach(function(a,s){r.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:n,contextParams:r});i.length&&(i.forEach(function(o){return Xe(o,c,s)}),r=ot(c))})}function Qa(t){var e=t.current,n=t.get(-1);return n===null&&u4(e)||!u4(n)&&u4(e)}function es(t){var e=t.get(1);return e===null||!u4(e)}var ts={startCheck:Qa,endCheck:es};function lt(t,e){var n=t.map(function(c){return c.activeState.value});return new i2(n,e||0)}function ns(t){var e=this,n="latn",c=this.tokenizer.getRangeTokens(t),r=lt(c);r.context.forEach(function(a,s){r.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:n,contextParams:r});i.length&&(i.forEach(function(o){return Xe(o,c,s)}),r=lt(c))})}function h2(t){this.baseDir=t||"ltr",this.tokenizer=new u0,this.featuresTags={}}h2.prototype.setText=function(t){this.text=t};h2.prototype.contextChecks={latinWordCheck:ts,arabicWordCheck:Na,arabicSentenceCheck:_a};function Pe(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function cs(){return Pe.call(this,"latinWord"),Pe.call(this,"arabicWord"),Pe.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function rs(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var c=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,c.reverse())})}h2.prototype.registerFeatures=function(t,e){var n=this,c=e.filter(function(r){return n.query.supports({script:t,tag:r})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(c):this.featuresTags[t]=c};h2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new X0(t));for(var n=0;n<e.length;n++){var c=e[n];this.query.supports({script:c.script})&&this.registerFeatures(c.script,c.tags)}};h2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function Ze(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function as(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){Ze.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(c){Ja.call(t,c)})}}function ss(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){Ze.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(r){Ka.call(t,r)})}}}function is(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){Ze.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(r){ns.call(t,r)})}}}h2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};h2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(as.call(this),ss.call(this)),this.checkContextReady("latinWord")&&is.call(this),this.checkContextReady("arabicSentence")&&rs.call(this)};h2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),cs.call(this),this.applyFeaturesToContexts())};h2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};h2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var c=this.tokenizer.tokens[n];if(!c.state.deleted){var r=c.activeState.value;e.push(Array.isArray(r)?r[0]:r)}}return e};function t0(t){t=t||{},t.tables=t.tables||{},t.empty||(b5(t.familyName,"When creating a new Font object, familyName is required."),b5(t.styleName,"When creating a new Font object, styleName is required."),b5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),b5(t.ascender,"When creating a new Font object, ascender is required."),b5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new M2.GlyphSet(this,t.glyphs||[]),this.encoding=new xt(this),this.position=new L5(this),this.substitution=new W0(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new Jt(this)}})}t0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};t0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};t0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};t0.prototype.stringToGlyphs=function(t,e){var n=this,c=new h2,r=function(u){return n.charToGlyphIndex(u.char)};c.registerModifier("glyphIndex",null,r);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;c.applyFeatures(this,a);for(var s=c.getTextGlyphs(t),i=s.length,o=new Array(i),l=this.glyphs.get(0),h=0;h<i;h+=1)o[h]=this.glyphs.get(s[h])||l;return o};t0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};t0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};t0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};t0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};t0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};t0.prototype.forEachGlyph=function(t,e,n,c,r,a){e=e!==void 0?e:0,n=n!==void 0?n:0,c=c!==void 0?c:72,r=Object.assign({},this.defaultRenderOptions,r);var s=1/this.unitsPerEm*c,i=this.stringToGlyphs(t,r),o;if(r.kerning){var l=r.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,r.language)}for(var h=0;h<i.length;h+=1){var u=i[h];if(a.call(this,u,e,n,c,r),u.advanceWidth&&(e+=u.advanceWidth*s),r.kerning&&h<i.length-1){var f=o?this.position.getKerningValue(o,u.index,i[h+1].index):this.getKerningValue(u,i[h+1]);e+=f*s}r.letterSpacing?e+=r.letterSpacing*c:r.tracking&&(e+=r.tracking/1e3*c)}return e};t0.prototype.getPath=function(t,e,n,c,r){var a=new M0;return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.extend(h)}),a};t0.prototype.getPaths=function(t,e,n,c,r){var a=[];return this.forEachGlyph(t,e,n,c,r,function(s,i,o,l){var h=s.getPath(i,o,l,r,this);a.push(h)}),a};t0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};t0.prototype.draw=function(t,e,n,c,r,a){this.getPath(e,n,c,r,a).draw(t)};t0.prototype.drawPoints=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawPoints(t,i,o,l)})};t0.prototype.drawMetrics=function(t,e,n,c,r,a){this.forEachGlyph(e,n,c,r,a,function(s,i,o,l){s.drawMetrics(t,i,o,l)})};t0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};t0.prototype.validate=function(){var t=this;function e(c,r){}function n(c){var r=t.getEnglishName(c);r&&r.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};t0.prototype.toTables=function(){return Xc.fontToTable(this)};t0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};t0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),c=new Uint8Array(n),r=0;r<e.length;r++)c[r]=e[r];return n};t0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var c=this.toArrayBuffer();if(Yc())if(window.URL=window.URL||window.webkitURL,window.URL){var r=new DataView(c),a=new Blob([r],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(a),s.download=t;var i=document.createEvent("MouseEvents");i.initEvent("click",!0,!1),s.dispatchEvent(i)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var o=S7(),l=Jc(c);o.writeFileSync(t,l)}};t0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};t0.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};t0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function n8(t,e){var n=JSON.stringify(t),c=256;for(var r in e){var a=parseInt(r);if(!(!a||a<256)){if(JSON.stringify(e[r])===n)return a;c<=a&&(c=a+1)}}return e[c]=t,c}function os(t,e,n){var c=n8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:c}]}function ls(t,e,n){var c={},r=new f1.Parser(t,e);return c.tag=r.parseTag(),c.minValue=r.parseFixed(),c.defaultValue=r.parseFixed(),c.maxValue=r.parseFixed(),r.skip("uShort",1),c.name=n[r.parseUShort()]||{},c}function hs(t,e,n,c){for(var r=n8(e.name,c),a=[{name:"nameID_"+t,type:"USHORT",value:r},{name:"flags_"+t,type:"USHORT",value:0}],s=0;s<n.length;++s){var i=n[s].tag;a.push({name:"axis_"+t+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return a}function us(t,e,n,c){var r={},a=new f1.Parser(t,e);r.name=c[a.parseUShort()]||{},a.skip("uShort",1),r.coordinates={};for(var s=0;s<n.length;++s)r.coordinates[n[s].tag]=a.parseFixed();return r}function fs(t,e){var n=new n1.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:t.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:t.instances.length},{name:"instanceSize",type:"USHORT",value:4+t.axes.length*4}]);n.offsetToData=n.sizeOf();for(var c=0;c<t.axes.length;c++)n.fields=n.fields.concat(os(c,t.axes[c],e));for(var r=0;r<t.instances.length;r++)n.fields=n.fields.concat(hs(r,t.instances[r],t.axes,e));return n}function ds(t,e,n){var c=new f1.Parser(t,e),r=c.parseULong();k1.argument(r===65536,"Unsupported fvar table version.");var a=c.parseOffset16();c.skip("uShort",1);for(var s=c.parseUShort(),i=c.parseUShort(),o=c.parseUShort(),l=c.parseUShort(),h=[],u=0;u<s;u++)h.push(ls(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,p=0;p<o;p++)f.push(us(t,d+p*l,h,n));return{axes:h,instances:f}}var ps={make:fs,parse:ds},ms=function(){return{coverage:this.parsePointer(O.coverage),attachPoints:this.parseList(O.pointer(O.uShortList))}},gs=function(){var t=this.parseUShort();if(k1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},vs=function(){return this.parseList(O.pointer(gs))},ys=function(){return{coverage:this.parsePointer(O.coverage),ligGlyphs:this.parseList(O.pointer(vs))}},bs=function(){return this.parseUShort(),this.parseList(O.pointer(O.coverage))};function xs(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);k1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var r={version:c,classDef:n.parsePointer(O.classDef),attachList:n.parsePointer(ms),ligCaretList:n.parsePointer(ys),markAttachClassDef:n.parsePointer(O.classDef)};return c>=1.2&&(r.markGlyphSets=n.parsePointer(bs)),r}var Ms={parse:xs},o2=new Array(10);o2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(O.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(O.coverage),values:this.parseValueRecordList()};k1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};o2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();k1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(O.coverage),r=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,pairSets:this.parseList(O.pointer(O.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(O.classDef),i=this.parsePointer(O.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:c,valueFormat1:r,valueFormat2:a,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,O.list(l,function(){return{value1:this.parseValueRecord(r),value2:this.parseValueRecord(a)}}))}}};o2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};o2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};o2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};o2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};o2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};o2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};o2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function ws(t,e){e=e||0;var n=new O(t,e),c=n.parseVersion(1);return k1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(o2)}:{version:c,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(o2),variations:n.parseFeatureVariationsList()}}var zs=new Array(10);function ks(t){return new n1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new n1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new n1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new n1.LookupList(t.lookups,zs)}])}var Ss={parse:ws,make:ks};function Ls(t){var e={};t.skip("uShort");var n=t.parseUShort();k1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var c=t.parseUShort();t.skip("uShort",3);for(var r=0;r<c;r+=1){var a=t.parseUShort(),s=t.parseUShort(),i=t.parseShort();e[a+","+s]=i}return e}function As(t){var e={};t.skip("uShort");var n=t.parseULong();n>1&&console.warn("Only the first kern subtable is supported."),t.skip("uLong");var c=t.parseUShort(),r=c&255;if(t.skip("uShort"),r===0){var a=t.parseUShort();t.skip("uShort",3);for(var s=0;s<a;s+=1){var i=t.parseUShort(),o=t.parseUShort(),l=t.parseShort();e[i+","+o]=l}}return e}function Cs(t,e){var n=new f1.Parser(t,e),c=n.parseUShort();if(c===0)return Ls(n);if(c===1)return As(n);throw new Error("Unsupported kern table version ("+c+").")}var Ps={parse:Cs};function Ts(t,e,n,c){for(var r=new f1.Parser(t,e),a=c?r.parseUShort:r.parseULong,s=[],i=0;i<n+1;i+=1){var o=a.call(r);c&&(o*=2),s.push(o)}return s}var Es={parse:Ts};function ht(t,e){for(var n=[],c=12,r=0;r<e;r+=1){var a=f1.getTag(t,c),s=f1.getULong(t,c+4),i=f1.getULong(t,c+8),o=f1.getULong(t,c+12);n.push({tag:a,checksum:s,offset:i,length:o,compression:!1}),c+=16}return n}function Is(t,e){for(var n=[],c=44,r=0;r<e;r+=1){var a=f1.getTag(t,c),s=f1.getULong(t,c+4),i=f1.getULong(t,c+8),o=f1.getULong(t,c+12),l=void 0;i<o?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:i,length:o}),c+=20}return n}function d0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),c=new Uint8Array(e.length);if(S9(n,c),c.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var r=new DataView(c.buffer,0);return{data:r,offset:0}}else return{data:t,offset:e.offset}}function c8(t,e){e=e??{};var n,c,r=new t0({empty:!0}),a=new DataView(t,0),s,i=[],o=f1.getTag(a,0);if(o==="\0\0\0"||o==="true"||o==="typ1")r.outlinesFormat="truetype",s=f1.getUShort(a,4),i=ht(a,s);else if(o==="OTTO")r.outlinesFormat="cff",s=f1.getUShort(a,4),i=ht(a,s);else if(o==="wOFF"){var l=f1.getTag(a,4);if(l==="\0\0\0")r.outlinesFormat="truetype";else if(l==="OTTO")r.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+o);s=f1.getUShort(a,12),i=Is(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,p,m,g,v,y,b,x,M,w=0;w<s;w+=1){var k=i[w],z=void 0;switch(k.tag){case"cmap":z=d0(a,k),r.tables.cmap=bt.parse(z.data,z.offset),r.encoding=new Mt(r.tables.cmap);break;case"cvt ":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.cvt=M.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.fpgm=M.parseByteList(k.length);break;case"head":z=d0(a,k),r.tables.head=Et.parse(z.data,z.offset),r.unitsPerEm=r.tables.head.unitsPerEm,n=r.tables.head.indexToLocFormat;break;case"hhea":z=d0(a,k),r.tables.hhea=It.parse(z.data,z.offset),r.ascender=r.tables.hhea.ascender,r.descender=r.tables.hhea.descender,r.numberOfHMetrics=r.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":z=d0(a,k),c=Ht.parse(z.data,z.offset);break;case"maxp":z=d0(a,k),r.tables.maxp=Ot.parse(z.data,z.offset),r.numGlyphs=r.tables.maxp.numGlyphs;break;case"name":b=k;break;case"OS/2":z=d0(a,k),r.tables.os2=Fe.parse(z.data,z.offset);break;case"post":z=d0(a,k),r.tables.post=Nt.parse(z.data,z.offset),r.glyphNames=new Be(r.tables.post);break;case"prep":z=d0(a,k),M=new f1.Parser(z.data,z.offset),r.tables.prep=M.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":y=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":p=k;break;case"GSUB":m=k;break;case"meta":x=k;break}}var S=d0(a,b);if(r.tables.name=qt.parse(S.data,S.offset,c),r.names=r.tables.name,f&&y){var L=n===0,I=d0(a,y),q=Es.parse(I.data,I.offset,r.numGlyphs,L),R=d0(a,f);r.glyphs=Xt.parse(R.data,R.offset,q,r,e)}else if(h){var N=d0(a,h);Tt.parse(N.data,N.offset,r,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var G=d0(a,g);if(Vt.parse(r,G.data,G.offset,r.numberOfHMetrics,r.numGlyphs,r.glyphs,e),j9(r,e),v){var V=d0(a,v);r.kerningPairs=Ps.parse(V.data,V.offset)}else r.kerningPairs={};if(d){var J=d0(a,d);r.tables.gdef=Ms.parse(J.data,J.offset)}if(p){var o1=d0(a,p);r.tables.gpos=Ss.parse(o1.data,o1.offset),r.position.init()}if(m){var Z=d0(a,m);r.tables.gsub=Ut.parse(Z.data,Z.offset)}if(u){var p1=d0(a,u);r.tables.fvar=ps.parse(p1.data,p1.offset,r.names)}if(x){var E=d0(a,x);r.tables.meta=Bt.parse(E.data,E.offset),r.metas=r.tables.meta}return r}var x4=class{constructor(e,n){this.sources=e;this.fallback=n;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let n=e||this.fallback||Object.keys(this.sources)[0];if(!n)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let c=this.parsed.get(n);if(c)return c;let r=G0(this.sources,n);if(!r)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let a=r instanceof Uint8Array?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r,s=c8(a);return this.parsed.set(n,s),s}};function Vs(t,e,n){let c={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,c).commands,advance:t.getAdvanceWidth(e,n.size,c)};let r=[],a=0,s=[...e];return s.forEach((i,o)=>{r.push(...t.getPath(i,a,0,n.size,c).commands),a+=t.getAdvanceWidth(i,n.size,c)*(o<s.length-1?n.spacing:1)}),{cmds:r,advance:a}}function r8(t,e,n){let{cmds:c,advance:r}=Vs(t,e,n),a=c.map(i=>i.type==="Z"?i:i.type==="C"?{...i,y1:-i.y1,y2:-i.y2,y:-i.y}:i.type==="Q"?{...i,y1:-i.y1,y:-i.y}:{...i,y:-i.y}),s=T3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:r}}function M4(t,e,n){if(!e)return[];let c=t.get(n.font),{polys:r,advance:a}=r8(c,e,n),s=x1(r),i=S0(s);if(!i)return[];let o=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-i[3]:n.valign==="center"?-(i[1]+i[3])/2:n.valign==="bottom"?-i[1]:0;return s.map(h=>h.map(([u,f])=>[u+o,f+l]))}function Ye(t,e,n){let c=t.get(n.font),{polys:r,advance:a}=r8(c,e,n),s=S0(r)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:c.ascender/c.unitsPerEm*n.size,descent:c.descender/c.unitsPerEm*n.size}}var Je=128,w4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],s8={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Hs(t,e){if(!t||G0(e6,t)!==void 0||e.startsWith("/"))return;let n=t.lastIndexOf("/");if(n<0)return;let c=[...t.slice(0,n).split("/"),...e.split("/")],r=[];for(let a of c)a===".."&&r.length&&r[r.length-1]!==".."?r.pop():a!=="."&&a!==""&&r.push(a);return(t.startsWith("/")?"/":"")+r.join("/")}var Os=100,Rs={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},$3=4,a8=8,Fs=t=>{let e=Os,n=c=>{for(let r of c.values()){for(let a of r.regions)e+=a.length;for(let a of r.lines)e+=a.length}};n(t.layers);for(let c of t.parts)n(c.layers);return e},T0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,c=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=c?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let c=n.fns.get(e);if(c)return c}}mod(e){for(let n=this;n;n=n.parent){let c=n.mods.get(e);if(c)return c}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let c=this;c;c=c.parent)n.push(...c[e].keys());return n}},Ke=t=>t?`.${t}`:"",Qe=["echo","assert","text_width","text_metrics","finger_count"];function l3(t,e){let n="",c=Math.min(2,Math.floor(t.length/3))+.5;for(let r of new Set(e)){if(r===t)continue;let a=r.toLowerCase()===t.toLowerCase()?0:$s(t,r);a<c&&([n,c]=[r,a])}return n?` Did you mean "${n}"?`:""}function $s(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(c,r)=>[r,...Array(e.length).fill(0)]);for(let c=1;c<=e.length;c++)n[0][c]=c;for(let c=1;c<=t.length;c++)for(let r=1;r<=e.length;r++)n[c][r]=Math.min(n[c-1][r]+1,n[c][r-1]+1,n[c-1][r-1]+(t[c-1]===e[r-1]?0:1)),c>1&&r>1&&t[c-1]===e[r-2]&&t[c-2]===e[r-1]&&(n[c][r]=Math.min(n[c][r],n[c-2][r-2]+1));return n[t.length][e.length]}var e6=y5,D3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.pointCount=0;this.itemCount=0;this.copies=0;this.frame=he;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(w4.map(e=>[e.name,e]));this.loaded=new Map;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...s8,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new T0,c={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[i,o]of Object.entries(c))n.vars.set(i,o);let r=new T0(n),a=this.block(e.body,r,!0),s=r.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${T2(this.unscaled,!1)})`),{shape:a,globals:r,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new i1(`Stopped after ${this.maxSteps} steps. Is there an endless loop?`,e)}load(e,n){let c=Hs(n.file,e),r=e,a=G0(e6,e);if(a===void 0&&c!==void 0){let i=this.loaded.get(c);if(i)return i;a=this.opts.resolve?.(c),typeof a=="string"&&(r=c)}if(r===e){let i=this.loaded.get(e);if(i)return i;a??(a=this.opts.resolve?.(e))}if(typeof a!="string")throw new i1(`Library <${e}> not found`,n);this.loaded.set(r,{body:[]});let{program:s}=a2(a,r);return this.loaded.set(r,s),s}hoist(e,n){for(let c of e)if((c.kind==="module"||c.kind==="function")&&(c.pos.file===void 0||G0(e6,c.pos.file)===void 0)&&(c.kind==="module"?G0(this.builtins,c.name)!==void 0:G0(f5,c.name)!==void 0||Qe.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${T2(c.pos,!1)})`),c.kind==="module")n.mods.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="function")n.fns.set(c.name,{params:c.params,body:c.body,env:n});else if(c.kind==="use"&&!c.include){this.enter(this.using,c.path,c.pos,"use");try{let r=this.included(this.load(c.path,c.pos).body,new Set([c.path])),a=new T0(n);this.hoist(r,a);for(let s of r)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,i]of a.mods)n.mods.set(s,i);for(let[s,i]of a.fns)n.fns.set(s,i)}finally{this.using.pop()}}}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let r=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,i=[];for(let l=r.length-1;l>=0;l--)i.push({text:";"},r[l][1],{text:`${r[l][0]}=`});for(;i.length;){if(s>2e4)return"";let l=i.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){i.push({text:"]"});for(let u=l.length-1;u>=0;u--)i.push(l[u],{text:","});h="["}else if(Q0(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(F0(l)){i.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)i.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";a.push(h),s+=h.length}let o=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies}`}enter(e,n,c,r){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new i1(a.length===2?`Library ${a[0]} ${r}s itself`:`Libraries ${r} each other in a loop: ${a.join(" \u2192 ")}`,c)}e.push(n)}included(e,n){let c=[];for(let r of e)if(r.kind!=="use"||!r.include)c.push(r);else if(!n.has(r.path)){n.add(r.path);for(let a of this.included(this.load(r.path,r.pos).body,n))c.push(a)}return c}assign(e,n,c){c.vars.set(e,n)}block(e,n,c=!1){this.hoist(e,n);let r=[];for(let a of e){let s=this.stmt(a,n,c);s&&!G6(s)&&r.push(s)}return r.length===1?r[0]:q2(r)}stmt(e,n,c=!1){switch(this.tick(e.pos),e.kind){case"assign":{let r=this.opts.overrides,a=c&&r&&Object.prototype.hasOwnProperty.call(r,e.name)?r[e.name]:this.expr(e.value,n);return this.assign(e.name,a,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new T0(n));case"if":return h0(this.expr(e.cond,n))?this.block(e.then,new T0(n)):this.block(e.else,new T0(n));case"let":{let r=new T0(n);return this.bindSeq(e.assigns,r),this.block(e.body,r)}case"for":{let r=[];return this.loop(e.assigns,n,a=>r.push(this.block(e.body,a))),q2(r)}case"call":if(e.modifier==="*")return null;{let r=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?o5(r,"guide"):r}}}bindSeq(e,n){for(let c of e)this.assign(c.name,this.expr(c.value,n),n)}iterable(e,n){if(Q0(e))try{return n4(e,this.limits.maxListLength)}catch(c){throw new i1(c.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,c,r=0,a=new T0(n)){if(r===e.length)return c(a);let s=e[r];for(let i of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let o=new T0(a);o.vars.set(s.name,i),this.loop(e,n,c,r+1,o)}}evalArgs(e,n,c){let r=[],a=new Map,s=[];for(let i of e){let o=this.expr(i.value,n);i.name===null?r.push(o):a.set(i.name,o),s.push({name:i.name,value:o})}return{pos:r,named:a,all:s,at:c}}bindParams(e,n,c,r,a){let s=e.map(i=>i.name);e.forEach((i,o)=>{let l;n.named.has(i.name)?l=n.named.get(i.name):o<n.pos.length?l=n.pos[o]:l=i.default?this.expr(i.default,c):void 0,c.vars.set(i.name,l)});for(let i of n.named.keys())i.startsWith("$")?c.vars.set(i,n.named.get(i)):s.includes(i)||this.unknownArg(a,i,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let c=v5(e);if(!c)return;let r=c.params.map(a=>a.name);if(!c.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!r.includes(a)&&this.unknownArg(`${e}()`,a,n.at,r);c.rest||this.checkCount(`${e}()`,c.params.filter(a=>!a.named).length,n)}checkCount(e,n,c){c.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${c.pos.length}; the rest are ignored (${T2(c.at,!1)})`)}unknownArg(e,n,c,r){this.warn(`${e}: unknown argument "${n}"${Ke(l3(n,r))} (${T2(c,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let c=e.args.findIndex(s=>s.name==="name"),r=c>=0?c:e.args.findIndex(s=>s.name===null);if(r<0)throw new i1("call() needs the name of a module",e.pos);let a=this.expr(e.args[r].value,n);if(typeof a!="string")throw new i1(`call() needs a module's name as a string, got ${j0(a)}`,e.pos);if(a==="call")throw new i1("call() can't call itself",e.pos);return this.callModule({...e,name:a,args:e.args.filter((s,i)=>i!==r)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let c=this.evalArgs(e.args,n,e.pos),r=n.mod(e.name);if(r){if(++this.depth>1e3)throw new i1(`Recursion too deep in module ${e.name}(): it calls itself without stopping`,e.pos);try{let f=new T0(r.env,n);return this.bindParams(r.params,c,f,r.env,`${e.name}()`),f.children={stmts:e.children,env:n},f.vars.set("$children",this.childStmts(e.children).length),this.block(r.body,f)}catch(f){throw this.inCall(f,"module",e.name,e.pos)}finally{this.depth--}}let a=G0(this.builtins,e.name);if(!a){let f=e.name==="color"?" Use layer(), cut(), score() or engrave() instead.":l3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new i1(`Unknown module ${e.name}().${f}`,e.pos)}this.checkArgs(e.name,c);let s=new T0(n,n);for(let[f,d]of c.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new T0(n,s),l={args:c,env:s,children:()=>e.children.length?this.block(e.children,o()):J0(),childList:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let p of e.children){let m=this.stmt(p,f);i.includes(p)&&d.push(m??J0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let p=[];for(let m of e.children){let g=this.stmt(m,d);i.includes(m)&&(p.push(g??J0()),f(p.length-1,g??J0()))}return p}},h;try{h=a(l)}catch(f){if(f instanceof i1||f instanceof RangeError)throw f;let d=new i1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=Fs(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new i1(u>this.limits.maxPoints?`The shapes have more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes, or a lower $fn.`:`Making the shapes took more than ${this.limits.maxPoints*10} points of work, the limit. Use fewer or simpler shapes, or a lower $fn.`,e.pos);return h}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,c,r){if(++this.depth>2e3)throw new i1(`Recursion too deep in ${r}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=P2(e)?e.scope:e.env,s=new T0(a,c);return this.bindParams(e.params,n,s,a,`${r}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",r,n.at)}finally{this.depth--}}inCall(e,n,c,r){return e instanceof Error&&!(e instanceof i1)&&e.message.includes("call stack")?new i1(`Recursion too deep in ${n==="module"?"module ":""}${c}(): it calls itself without stopping`,r):(e instanceof i1&&e.addFrame(n,c,r),e)}expr(e,n){switch(e.kind){case"num":return e.unit?this.length(e,n):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{let c=n.get(e.name);if(c.found)return c.value;let r=n.fn(e.name);if(r)return{type:"function",params:r.params,body:r.body,scope:r.env,name:e.name};if(e.name.startsWith("$"))return;throw new i1(`Unknown variable "${e.name}"${Ke(l3(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let c=[];for(let r of e.items)this.listItem(r,n,c,e.pos);return this.charge($3,e.pos),c}case"range":{let c=this.expr(e.start,n),r=this.expr(e.end,n),a=e.step?this.expr(e.step,n):1;if(typeof c!="number"||typeof r!="number"||typeof a!="number")throw new i1("Range values must be numbers",e.pos);return{type:"range",start:c,step:a,end:r}}case"unary":{let c=this.expr(e.arg,n);return e.op==="!"?!h0(c):e.op==="+"?c:this.arith("*",-1,c,e.pos)}case"binary":{if(e.op==="&&")return h0(this.expr(e.left,n))&&h0(this.expr(e.right,n));if(e.op==="||")return h0(this.expr(e.left,n))||h0(this.expr(e.right,n));let c=this.expr(e.left,n),r=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return C3(c,r,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof c=="number"&&typeof r=="number"||typeof c=="string"&&typeof r=="string"))throw new i1(`Can't compare ${j0(c)} ${e.op} ${j0(r)}`,e.pos);return e.op==="<"?c<r:e.op==="<="?c<=r:e.op===">"?c>r:c>=r}return this.arith(e.op,c,r,e.pos)}case"ternary":return h0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let c=this.expr(e.target,n),r=this.expr(e.index,n);if(F0(c)&&typeof r=="string")return c.fields.get(r);if(typeof r!="number")throw new i1(`List index must be a number, got ${j0(r)}`,e.pos);return Array.isArray(c)?c[Math.floor(r)]:typeof c=="string"?[...c][Math.floor(r)]:Q0(c)?[c.start,c.step,c.end][Math.floor(r)]:void 0}case"record":return this.record(e,n);case"member":{let c=this.expr(e.target,n);if(F0(c))return c.fields.get(e.name);let r={x:0,y:1,z:2}[e.name];return Array.isArray(c)&&r!==void 0?c[r]:Q0(c)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?c.start:e.name==="step"?c.step:c.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let c=new T0(n);return this.bindSeq(e.assigns,c),this.expr(e.body,c)}}}listItem(e,n,c,r){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(c,1,r),c.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),r);this.grow(c,a.length,r);for(let s of a)c.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,c,r));return;case"if":h0(this.expr(e.cond,n))?this.listItem(e.then,n,c,r):e.else&&this.listItem(e.else,n,c,r);return;case"let":{let a=new T0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,c,r)}}}grow(e,n,c){if(e.length+n>this.limits.maxListLength)throw new i1(`a list of ${e.length+n} items is more than the limit of ${this.limits.maxListLength}`,c);this.charge(n,c)}charge(e,n){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new i1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let r=e.callee.name,a=n.get(r),s=a.found&&!P2(a.value);if(!a.found||s&&this.callable(r,n)){let i=n.fn(r);if(i)return this.callFunction(i,this.evalArgs(e.args,n,e.pos),n,r);let o=this.specialFunction(r,e,n);if(o.handled)return o.value;let l=G0(f5,r);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(r,h);for(let p of g7(l,h.pos,h.named))this.warn(`${r}(): "${p}" is given by position and by name; the named value is used (${T2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:p=>this.tick(e.pos,p),given:h.pos.length+l.params.filter(p=>h.named.has(p)).length},f=v7(l,h.pos,h.named);this.tick(e.pos,y7(r,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(p){if(p instanceof i1)throw p;let m=new i1(p instanceof RangeError?`${r}(): the result is too large`:p.message,e.pos);throw m.call=r,m}return this.checkValue(d,e.pos,r),d}throw new i1(`Unknown function ${r}()${Ke(l3(r,[...n.names("fns"),...n.names("vars"),...Object.keys(f5),...Qe]))}`,e.pos)}if(!P2(a.value))throw new i1(`"${r}" is a ${j0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,r)}let c=this.expr(e.callee,n);if(!P2(c))throw new i1(`Can't call a ${j0(c)}`,e.pos);return this.callFunction(c,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,c,r){let a=s=>Array.isArray(c)?String(c[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let i=a(s),o=x1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||b0(n[s],o).reduce((h,u)=>h+Math.abs(H1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(c)&&i?` "${i}"`:""} under it, so it can't be seen (${T2(r,!1)})`)}}record(e,n){let c=new Map;for(let r of e.fields)c.set(r.name,this.expr(r.value,n));return{type:"record",fields:c}}length(e,n){let c=A0(n.get("$scale").value??1);if(!(c>0))throw new i1("$scale must be a number more than 0",e.pos);return c===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Rs[e.unit]/c}callable(e,n){return!!n.fn(e)||Qe.includes(e)||!!G0(f5,e)}specialFunction(e,n,c){if(e==="echo"){let r=this.evalArgs(n.args,c,n.pos);return this.echo(this.echoText(r),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let r=this.evalArgs(n.args,c,n.pos);return this.checkArgs(e,r),this.assert(r),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"){let r=this.evalArgs(n.args,c,n.pos);this.checkArgs(e,r);let a=this.measure(r,c);return e==="text_width"?{handled:!0,value:a.advance}:{handled:!0,value:[a.advance,a.bounds,a.ascent,a.descent]}}if(e==="finger_count"){let r=this.evalArgs(n.args,c,n.pos);this.checkArgs(e,r);let a=this.num(this.arg(r,"length",0),"finger_count","length");return{handled:!0,value:c3(a,this.fingerWidth(r,c,1))}}return{handled:!1}}assert(e){if(h0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new i1(`Assertion failed${n===void 0?"":": "+g0(n)}`,e.at)}echo(e,n){this.charge(Math.ceil(e.length/a8),n),this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,c=[],r=0,a=(s,i,o)=>{c.length&&(r+=2);let l=P3(i,n-r-s.length,o);if(r+=s.length+l.text.length,!l.whole)throw new i1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);c.push(s+l.text)};for(let{name:s,value:i}of e.all)s===null?a("",i,!1):a(`${s} = `,i,!0);return c.join(", ")}arith(e,n,c,r){if(typeof n=="number"&&typeof c=="number")switch(e){case"+":return n+c;case"-":return n-c;case"*":return n*c;case"/":return n/c;case"%":return n%c;case"^":return Math.pow(n,c)}if(e==="+"&&typeof n=="string"&&typeof c=="string")return this.checkSize(n.length+c.length,!0,r),n+c;if(Array.isArray(n)&&Array.isArray(c)){if(e==="+"||e==="-"){if(n.length!==c.length)throw new i1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${c.length}`,r);return this.charge(n.length+$3,r),n.map((s,i)=>this.arith(e,s,c[i],r))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+$3,r),n.map(i=>this.arith("*",i,c,r));let s=(i,o)=>{let l=this.arith("*",i,o,r);if(typeof l!="number")throw new i1("Can't multiply these lists: an item times an item is not a number",r);return l};if(Array.isArray(c[0])){let i=c[0].length;if(n.length!==c.length||c.some(o=>!Array.isArray(o)||o.length!==i))throw new i1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,r);return this.checkSize(i,!1,r),this.tick(r,i*n.length),Array.from({length:i},(o,l)=>n.reduce((h,u,f)=>h+s(u,c[f][l]),0))}if(n.length!==c.length)throw new i1(`Can't multiply lists of length ${n.length} and ${c.length}`,r);return this.tick(r,n.length),n.reduce((i,o,l)=>i+s(o,c[l]),0)}}if(Array.isArray(n)&&typeof c=="number"&&(e==="*"||e==="/"))return this.charge(n.length+$3,r),n.map(s=>this.arith(e,s,c,r));if(typeof n=="number"&&Array.isArray(c)&&e==="*")return this.charge(c.length+$3,r),c.map(s=>this.arith(e,n,s,r));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new i1(`Can't ${a[e]??e} ${j0(n)} and ${j0(c)}`,r)}arg(e,n,c,r){return e.named.has(n)?e.named.get(n):c>=0&&c<e.pos.length?e.pos[c]:r}num(e,n,c){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${c} must be a finite number, got ${q0(e)}`);return e}vec2(e,n,c=!0){let r=a=>typeof a=="number"&&Number.isFinite(a);if(r(e)&&c)return[e,e];if(Array.isArray(e)&&r(e[0])&&(e[1]===void 0||r(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${q0(e)}`)}vec3(e,n){let c=r=>typeof r=="number"&&Number.isFinite(r);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(c))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${q0(e)}`)}placements(e,n,c){let r=(i,o)=>i===void 0?[[0,0,0]]:Array.isArray(i)&&i.length>0&&Array.isArray(i[0])?i.map((l,h)=>this.vec3(l,`${o}[${h}]`)):[this.vec3(i,o)],a=r(e,"at"),s=r(n,"rotate");for(let[i,o]of[[a,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==c)throw new Error(`${o} needs one placement per copy: qty is ${c} but ${o} has ${i.length}`);return Array.from({length:c},(i,o)=>({at:a[a.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((c,r)=>{if(!Array.isArray(c)||!Number.isFinite(c[0])||!Number.isFinite(c[1]))throw new Error(`${n}[${r}] must be an [x, y] point, got ${q0(c)}`);return[c[0],c[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,c){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,c)}checkSize(e,n,c,r){if(e>this.limits.maxListLength)throw new i1(`${r?`${r}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,c);this.charge(n?Math.ceil(e/a8):e+$3,c)}segs(e){let n=A0(this.dyn(e,"$fn"))||0,c=A0(this.dyn(e,"$fa"))||2,r=A0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let i=Z6(s,n,c,r);if(!(i<=a))throw new Error(`a circle with ${i} segments is more than the limit of ${a}. Lower $fn, or raise $fa or $fs.`);return i}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||n<=0)throw new Error("$thickness must be a positive number");return n}fingerWidth(e,n,c){let r=this.arg(e,"finger",c);return typeof r=="number"&&r>0?r:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new i1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let c=P3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!c.whole)throw new i1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,c.text.length);try{return Ye(this.opts.fonts,c.text,this.textOpts(e,n,c.text))}catch(r){throw r instanceof i1?r:new i1(r.message,e.at)}}textOpts(e,n,c){let r={size:this.num(this.arg(e,"size",1,10),"text","size"),font:g0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:g0(this.arg(e,"halign",-1,"left")),valign:g0(this.arg(e,"valign",-1,"baseline")),spacing:A0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&c!==void 0&&this.opts.fonts){let s=this.num(a,"text","fit");if(!(s>0))throw new Error("fit must be a width more than 0");let i=Ye(this.opts.fonts,c,{...r,size:1}).advance;if(i>0){let o=this.arg(e,"size",1);r.size=o===void 0?s/i:Math.min(r.size,s/i)}}return r}edges(e){let n=c=>{if(c==="out"||c==="in"||c==="flat")return c;throw new Error(`edges must be "out", "in" or "flat", got ${q0(c)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,c=this.layers.get(n);if(c&&c.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!c){let r=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...r,name:n,side:"back"})}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((c,r)=>{if(!Array.isArray(c)||c.length!==3||!c.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${q0(c)}${n.length>1?` at ${r}`:""}`);let[a,s,i]=c;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${q0(c)}`);return{x0:a,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>z3(s.children(),i),n=s=>i=>o5(i.children(),s),c=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${q0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!h0(this.dyn(i.env,"$mirrored"))),o5(i.children(),o==="back"?this.backLayer(s):s)};return{rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0,1),"size"),l=A0(this.arg(s.args,"r",-1,0))||0,h=h0(this.arg(s.args,"center",1,!1)),u=Y6(i,o,l,this.segs(s.env));return k0(x1([h?u.map(([f,d])=>[f-i/2,d-o/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let i=this.arg(s.args,"d",-1),o=i!==void 0?this.num(i,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return k0([k3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return k0([k3(i,o,this.segs(s.env)(Math.max(i,o)))])},regular_polygon:s=>{let i=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),o=this.num(this.arg(s.args,"r",1,10),"regular_polygon","r");if(!(i<=this.limits.maxSegments))throw new Error(`${i} corners is more than the limit of ${this.limits.maxSegments}`);return k0([k3(o,o,i)])},star:s=>{let i=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),o=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.args,"inner",2,o*.45),"star","inner");if(!(i*2<=this.limits.maxSegments))throw new Error(`${i} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<i*2;u++){let f=Math.PI/2+Math.PI*u/i,d=u%2?l:o;h.push([d*Math.cos(f),d*Math.sin(f)])}return k0(x1([h]))},polygon:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"paths",1),l=Array.isArray(o)?o.map(h=>(Array.isArray(h)?h:[]).map(u=>i[A0(u)]).filter(Boolean)):[i];return k0(x1(l,"evenodd"))},path:s=>{let i=this.arg(s.args,"d",0);if(typeof i!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let o=T3(E3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return h0(this.arg(s.args,"close",-1,!1))?k0(x1([...o.closed,...o.open.filter(h=>h.length>2)],l)):q2([k0(x1(o.closed,l)),D2(o.open)])},line:s=>{let i=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),o=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return D2([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!u)return J0();let f=-(o[1]-i[1])/u*(h/2),d=(o[0]-i[0])/u*(h/2);return k0(x1([[[i[0]+f,i[1]+d],[i[0]-f,i[1]-d],[o[0]-f,o[1]-d],[o[0]+f,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=h0(this.arg(s.args,"closed",1,!1));return D2([o&&i.length?[...i,i[0]]:i])},arc:s=>{let i=this.num(this.arg(s.args,"r",0,10),"arc","r"),o=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.env)(i)*Math.abs(l-o)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(o+(l-o)*f/h)*Math.PI/180;u.push([i*Math.cos(d),i*Math.sin(d)])}return D2([u])},text:s=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let i=this.arg(s.args,"text",0,""),o=P3(i,this.limits.maxTextLength);if(!o.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(s.args.at,o.text.length);let l=M4(this.opts.fonts,o.text,this.textOpts(s.args,s.env,o.text));if(h0(this.dyn(s.env,"$mirrored"))){let[h,u]=[1/0,-1/0];for(let f of l)for(let[d]of f)[h,u]=[Math.min(h,d),Math.max(u,d)];return k0(x1(l.map(f=>f.map(([d,p])=>[h+u-d,p]))))}return k0(l)},translate:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,i,o])},rotate:s=>{let i=this.arg(s.args,"a",0,0),l=(Array.isArray(i)?A0(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[p,m]=this.vec2(f,"center",!1);d=[h,u,-u,h,p-h*p+u*m,m-u*p-h*m]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,u=o/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let i=this.arg(s.args,"m",0);if(!Array.isArray(i)||i.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let o=i[0],l=i[1];return e(s,[o[0],l[0],o[1],l[1],o[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[i,...o]=s.childList();if(!i)return J0();let l=r(o,"difference");return a(i,h=>({regions:b0(h.regions,l.regions),lines:v2(h.lines,x1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return J0();let o=p=>[...p.layers.values()].some(m=>m.regions.length),l=p=>{let m;for(let g of i){if(g===p||!o(g))continue;let v=x1(r([g],"intersection").regions);m=m?x0(m,v):v}return m},h=i[0],u=i.every(o),f=l(h),d=a(h,p=>({regions:u?f?x0(p.regions,f):p.regions:[],lines:f?v2(p.lines,f,"inside"):p.lines}));for(let p of i){if(p===h)continue;if(p.parts.length)throw new Error("part() can only be the first child of intersection()");let m=l(p),g=new Map;for(let[v,y]of p.layers)y.lines.length&&g.set(v,{regions:[],lines:m?v2(y.lines,m,"inside"):y.lines});g.size&&(d=q2([d,{layers:g,parts:[]}]))}return d},hull:s=>{let i=s.children(),o=l=>{let h=[],u="cut",f=!0;for(let[p,m]of l){f&&(m.regions.length||m.lines.length)&&(u=p,f=!1);for(let g of[...m.regions,...m.lines])for(let v of g)h.push(v)}let d=X6(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:o(i.layers),parts:i.parts.map(l=>({...l,layers:o(l.layers)}))}},offset:s=>{let i=this.arg(s.args,"r",0),o=this.arg(s.args,"delta",-1),l=h0(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),u=i!==void 0?"round":l?"square":"miter";return a(s.children(),f=>({regions:m0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[i,o]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(i>0&&o>0))throw new Error("spacing must be more than 0");let[h,...u]=s.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=x1(r(u,"pattern").regions),d=D0(h.layers),p=S0(f);if(!d||!p)return J0();let m=Math.floor((p[1]-d[3])/o),g=Math.ceil((p[3]-d[1])/o),v=Math.floor((p[0]-d[2])/i)-1,y=Math.ceil((p[2]-d[0])/i)+1,b=(g-m+1)*(y-v+1);if(!(b<=this.limits.maxParts*10))throw new Error(`the pattern would have ${b} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(s.args.at,b);let x=_0(f).map(S=>({polys:S,box:S0(S)})),M=f,w=(S,L)=>{let I=0;for(let q of M)for(let R=0,N=q.length-1;R<q.length;N=R++){let[G,V]=q[N],[J,o1]=q[R];V<=L?o1>L&&(J-G)*(L-V)-(S-G)*(o1-V)>0&&I++:o1<=L&&(J-G)*(L-V)-(S-G)*(o1-V)<0&&I--}return I!==0},k=new Map,z=(S,L)=>{let I=k.get(S)??{regions:[],lines:[]};for(let q of L.regions)I.regions.push(q);for(let q of L.lines)I.lines.push(q);k.set(S,I)};for(let S=m;S<=g;S++)for(let L=v;L<=y;L++){let I=L*i+(S%2?l*i:0),q=S*o,R=[d[0]+I,d[1]+q,d[2]+I,d[3]+q];if(R[2]<p[0]||R[0]>p[2]||R[3]<p[1]||R[1]>p[3])continue;let N=x.filter(Z=>!(R[2]<Z.box[0]||R[0]>Z.box[2]||R[3]<Z.box[1]||R[1]>Z.box[3]));if(!N.length)continue;M=N.length===x.length?f:N.flatMap(Z=>Z.polys);let G=[w(R[0],R[1]),w(R[2],R[1]),w(R[2],R[3]),w(R[0],R[3])],V=M.some(Z=>Z.some(([p1,E])=>p1>R[0]&&p1<R[2]&&E>R[1]&&E<R[3])),J=G.every(Boolean)&&!V,o1=[1,0,0,1,I,q];for(let[Z,p1]of z3({layers:h.layers,parts:[]},o1).layers)z(Z,J?p1:{regions:x0(p1.regions,M),lines:v2(p1.lines,M,"inside")})}return{layers:k,parts:[]}},spline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=h0(this.arg(s.args,"closed",-1,!1));if(!(i.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=ge(i,l,h);if(o===void 0)return D2([u]);let f=this.num(o,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return k0(x1(X5([u],f)))},hatch:s=>{let i=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),o=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(o>0))throw new Error("pitch must be more than 0");let h=x1(r([s.children()],"hatch").regions),u=S0(h);if(!u)return J0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],p=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,m=i*Math.PI/180,[g,v]=[Math.cos(m),Math.sin(m)],[y,b]=[-v,g],x=Math.ceil(p/o);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let M=[],w=Math.round((f*y+d*b)/o);for(let z=w-x;z<=w+x;z++){let S=z*o-(f*y+d*b),[L,I]=[f+y*S,d+b*S];M.push([[L-g*p,I-v*p],[L+g*p,I+v*p]])}if(l===void 0)return D2(v2(M,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return k0(x0(x1(X5(M,k).map(z=>z)),h))},paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],u=[];for(let f=o.length-1;f>=0;f--){let d=o[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let p=h,m=x1(r([d],"paint").regions);u[f]=m,h=p.length?x1([...p,...m]):m;let g=Array.isArray(i)?i[f]:void 0;g!==""&&(g!==void 0?(this.layers.has(g)||this.layers.set(g,{name:g,mode:"fill",color:"#000000"}),l.push(k0(p.length?b0(m,p):m,g))):l.push(p.length?a(d,v=>({regions:b0(v.regions,p),lines:v2(v.lines,p,"outside")})):d))}return this.invisiblePaint(o,u,i,s.args.at),q2(l.reverse())},measure:s=>{let i=h0(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let u=D0(h.layers)??S0(h.parts.flatMap(g=>[...g.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(g=>g.layers)],d=f.flatMap(g=>g.get("cut")?.regions??[]),p=d.length?d:f.flatMap(g=>[...g].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),m=W6(x1(p));s.env.vars.set("$area",m.area),s.env.vars.set("$centroid",m.area>0?m.centroid:void 0)});return q2(i?o:o.slice(1))},fill_holes:s=>{let i=this.arg(s.args,"min_area",0),o=i===void 0?1/0:this.num(i,"fill_holes","min_area");return a(s.children(),l=>({regions:x1(l.regions).filter(h=>!(H1(h)<0&&-H1(h)<o)),lines:l.lines}))},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),o=>({regions:m0(m0(o.regions,i,"round"),-i,"round"),lines:o.lines}))},stroke:s=>{let i=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),o=>({regions:x1([...o.regions,...X5(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...x1(i.regions).map(o=>[...o,o[0]])]})),cut:n("cut"),score:c("score"),engrave:c("engrave"),guide:n("guide"),layer:s=>{let i=this.arg(s.args,"name",0);if(typeof i!="string"||!i)throw new Error("layer() needs a name");let o=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(i),u=this.arg(s.args,"order",-1),f=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${i}" is the back of layer "${i.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let p=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(p))throw new Error('mode must be "cut", "line", "fill" or "guide"');let m=g0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(m))throw new Error('color must look like "#00aa00"');let g=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&p==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:p,color:m,...g!==void 0&&{order:g},...v!==void 0&&{bleed:v}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${q0(d)}`);if(d==="back"&&this.layers.get(i)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&s.env.vars.set("$mirrored",!h0(this.dyn(s.env,"$mirrored"))),o5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=g0(this.arg(s.args,"name",0,"part")),o=Math.max(1,Math.floor(A0(this.arg(s.args,"qty",1,1))||1)),l=this.arg(s.args,"stack",-1),h=l===void 0?1:Math.floor(this.num(l,"part","stack"));if(!(h>=1))throw new Error("stack must be 1 or more");if(this.copies+=o*h,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let u=this.arg(s.args,"at",-1),f=this.arg(s.args,"rotate",-1),d=this.arg(s.args,"glue",-1),p=d===void 0?void 0:g0(d),m=g0(this.arg(s.args,"face",-1,"top"));if(m!=="top"&&m!=="bottom")throw new Error(`face must be "top" or "bottom", got ${q0(m)}`);let g=this.frame!==he&&p===void 0,v=this.arg(s.args,"bend",-1),y=u===void 0&&f===void 0&&!g&&p===void 0&&v===void 0?void 0:this.placements(u,f,o),b=this.arg(s.args,"material",-1);b!==void 0&&s.env.vars.set("$material",g0(b));let x=this.thickness(s.env);y&&(g||h>1)&&(y=y.flatMap(Z=>{let p1=p===void 0?O1(this.frame,K0(Z)):K0(Z),E=p!==void 0&&m==="bottom"?-x:x;return Array.from({length:h},($,X)=>({...Z,matrix:O1(p1,R0(0,0,X*E))}))}));let M=this.arg(s.args,"mirror",-1,!1),w;if(Array.isArray(M)){if(M.length!==o)throw new Error(`mirror needs one true or false per copy: qty is ${o} but mirror has ${M.length}`);w=M.map(Z=>h0(Z))}else w=Array.from({length:o},()=>h0(M));let k=w.some(Z=>Z)&&!w.every(Z=>Z);if(k&&p!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let z=w[0],S=Z=>{let p1=s.env.vars.get("$mirrored"),E=s.env.vars.has("$mirrored");Z&&s.env.vars.set("$mirrored",!0);try{let $=s.children();return Z?z3($,[-1,0,0,1,0,0]):$}finally{Z&&(E?s.env.vars.set("$mirrored",p1):s.env.vars.delete("$mirrored"))}},L=S(z),I=this.bends(v),q=this.arg(s.args,"on",-1),R=this.arg(s.args,"slots",-1),N=R===void 0?void 0:(Array.isArray(R)?R:[R]).map(Z=>{if(typeof Z!="string")throw new Error("slots must be part names");return Z}),G=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),V=(Z,p1,E)=>{let $=E.length===o,X=y?.filter((j,w1)=>E.includes(Math.floor(w1/h)+1));return{name:i,qty:E.length*h,layers:Z,thickness:x,kerf:A0(this.dyn(s.env,"$kerf"))||0,material:g0(this.dyn(s.env,"$material")??"material"),...X?{placements:X}:{},...h>1?{stack:h}:{},...I.length?{bends:I}:{},...q!==void 0?{on:g0(q)}:{},...N?{slots:N,clearance:G}:{},...this.step?{step:this.step}:{},...p!==void 0&&{glue:{host:p,face:m}},...p1&&{mirrored:!0},...!$&&{copies:E}}},J=Z=>w.flatMap((p1,E)=>p1===Z?[E+1]:[]),o1=k?[V(L.layers,z,J(z)),V(S(!z).layers,!z,J(!z))]:[V(L.layers,z,J(z))];return{layers:new Map,parts:[...L.parts,...o1]}},place:s=>{let i=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),o=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=O1(l,K0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=g0(this.arg(s.args,"text",0,"")),o=h0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.children();let l=this.step,h=l&&i?`${this.stepNames[l-1]}: ${i}`:i,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=g0(this.arg(s.args,"kind",0,"dowel"));G0(I3,i)===void 0&&G0(m5,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${T2(s.args.at,!1)})${l3(i,Object.keys(I3))}`);let o=g0(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${q0(o)}`);let l=this.arg(s.args,"sides",-1),h=o==="ball"||l===0,u=this.vec3(this.arg(s.args,"from",1),"from"),f=this.arg(s.args,"to",2),d=h&&f===void 0?u:this.vec3(f,"to"),p=this.arg(s.args,"size",3,6),m=typeof p=="number"?p:this.vec2(p,"size",!1);if(h){if(typeof m!="number"||!(m>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let g=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(g[2])>.9*Math.hypot(...g),y=this.arg(s.args,"up",-1),b=y===void 0?v?[0,1,0]:[0,0,1]:this.vec3(y,"up"),x=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(x>=3&&x<=Je))throw new Error(`sides must be from 3 to ${Je} (or 0 for a ball), got ${q0(x)}`);if(this.pointCount+=h?2*Je:x*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let M=this.arg(s.args,"label",-1),w=this.frame,k=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2]+w[3],w[4]*S[0]+w[5]*S[1]+w[6]*S[2]+w[7],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]+w[11]],z=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2],w[4]*S[0]+w[5]*S[1]+w[6]*S[2],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:i,from:k(u),to:k(d),size:m,up:z(b),sides:x,step:this.step,...M!==void 0?{label:g0(M)}:{}}),s.children()},material:s=>{let i=this.arg(s.args,"thickness",0),o=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return i!==void 0&&s.env.vars.set("$thickness",this.num(i,"material","thickness")),o!==void 0&&s.env.vars.set("$kerf",this.num(o,"material","kerf")),l!==void 0&&s.env.vars.set("$material",g0(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return J0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new T0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(m=>u.add(m));else for(let m of this.iterable(l,s.args.at))o[A0(m)]&&u.add(o[A0(m)]);let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let p=this.childKey(h);for(let m of i.stmts)if(m.kind==="assign")this.stmt(m,h);else if(u.has(m)){let g=p&&d.get(m);if(g&&g.key===p){g.shape&&f.push(g.shape);continue}let v=this.effects(),y=this.stmt(m,h);y&&f.push(y),p&&this.effects()===v&&!y?.parts.length&&d.set(m,{key:p,shape:y})}return q2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/u*4),k0(c4(i,o,l,h,u))},finger_holes:s=>{let i=this.num(this.arg(s.args,"length",0),"finger_holes","length"),o=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(o==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(i)/l*4),k0(b7(i,o,this.thickness(s.env),l))},tslot:s=>{let i=this.num(this.arg(s.args,"d",0,3),"tslot","d"),o=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[i*1.85,i*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return k0(x1(x7(i,o,l,h,u)))},living_hinge:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.num(this.arg(s.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(s.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(o-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||u<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(i)/l+1)*(Math.abs(o)/(u+h)+2)*2),D2(M7(i,o,l,h,u))}};function r(s,i){let o={regions:[],lines:[]};for(let l of s){if(l.parts.length)throw new Error(`part() can only be the first child of ${i}()`);for(let h of l.layers.values())for(let u of h.regions)o.regions.push(u)}return o}function a(s,i){let o=l=>{let h=new Map;for(let[u,f]of l)h.set(u,i(f));return h};return{layers:o(s.layers),parts:s.parts.map(l=>({...l,layers:o(l.layers)}))}}}};var q3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},t6=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/"/g,"&quot;");function n6(t,e){let n=[];for(let[c,r]of t){let a=[q3(c),q3(r)],s=n[n.length-1];(!s||s[0]!==a[0]||s[1]!==a[1])&&n.push(a)}for(;e&&n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n}var N3=(t,e)=>`M${n6(t,e).map(([n,c])=>`${n} ${c}`).join("L")}${e?"Z":""}`;function z4(t,e){let n=[];for(let c of e){let r=[],a=[],s=[];for(let i of t){let o=i.layers.get(c.name);if(o){for(let l of o.lines)r.push(N3(l,!1));for(let l of o.regions)(H1(l)<0?a:s).push(N3(l,!0))}}(r.length||a.length||s.length)&&n.push({name:c.name,mode:c.mode,color:c.color,d:[...r,...a,...s].join(""),regions:[...a,...s].join(""),lines:r.join("")})}return n}function k4(t,e,n,c){let r=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${q3(e)}mm" height="${q3(n)}mm" viewBox="0 0 ${q3(e)} ${q3(n)}">`];for(let a of c){let s=[],i=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${t6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>N3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${N3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${N3(f,!1)}"/>`);for(let f of h.regions)(H1(f)<0?s:i).push(`<path${u} d="${N3(f,!0)}"/>`)}if(!s.length&&!i.length)continue;let o=a.mode==="fill"?`fill="${a.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${a.color}" stroke-width="0.1"${a.mode==="guide"?' stroke-dasharray="1 1"':""}`;r.push(`<g id="${t6(a.name)}" inkscape:groupmode="layer" inkscape:label="${t6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return r.push("</svg>",""),r.join(`
2564
+ `)}var Ds={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},qs=t=>{let e=Ds[t.toLowerCase()];if(e)return e;let[n,c,r]=[1,3,5].map(a=>parseInt(t.slice(a,a+2),16));return n>c&&n>r?1:c>n&&c>r?3:r>n&&r>c?5:7};function Ns(t){let e=i=>i.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(w4.map(i=>i.name)),c=new Set(t.map(i=>e(i.name))),r=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(r.has(o)){let l=2;for(;c.has(`${o}_${l}`)||r.has(`${o}_${l}`);)l++;o=`${o}_${l}`}r.add(o),a.set(i.name,o)}return a}function c6(t,e,n,c){let r=[],a=(o,l)=>r.push(String(o),String(l)),s=Ns(c);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,c.length);for(let o of c)a(0,"LAYER"),a(2,s.get(o.name)),a(70,0),a(62,qs(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 n6(l.map(([d,p])=>[d,n-p]),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 c){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)H1(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"),r.join(`
2228
2565
  `)+`
2229
- `}var at=(t,e)=>{let n=0;for(let c=1;c<t.length;c++)n+=Math.hypot(t[c][0]-t[c-1][0],t[c][1]-t[c-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},M0=t=>Math.round(t*100)/100;function qs(t,e={}){for(let[A,G]of Object.entries(e.params??{}))try{f6(A,G)}catch(N){throw new i1(N.message)}let{program:n}=r2(t),c=new Set(n.body.flatMap(A=>A.kind==="assign"?[A.name]:[])),r=Object.keys(e.params??{}).filter(A=>!A.startsWith("$")&&!c.has(A)),a=e.fonts?new y4(e.fonts,e.defaultFont):void 0,s=new D3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(n)}catch(A){let G=A instanceof RangeError?new i1(/call stack/i.test(A.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):A;throw G instanceof i1&&(G.echoes=s.echoes,G.warnings=[...s.warnings],a?.missing.size&&(G.missingFonts=[...a.missing])),G}let l=A=>o.globals.get(A).value,h=o.warnings;for(let A of r)h.push(`Setting "${A}" is not a variable of the program, so it is ignored.${l3(A,c)}`);let u=o.layers,f=A=>u.get(A)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(A=>A.regions.length||A.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:A0(l("$thickness"))||3,kerf:A0(l("$kerf"))||0,material:L0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let p=A=>JSON.stringify([A.thickness,A.material,[...A.layers].map(([G,N])=>[G,N.regions.map(s1=>s1.map(([K,S1])=>[Math.round(K*100),Math.round(S1*100)])),N.lines.map(s1=>s1.map(([K,S1])=>[Math.round(K*100),Math.round(S1*100)]))])]),g=new Map,v=new Set;for(let A of d){let G=p(A),N=A.mirrored?`${A.name}\0mirrored`:A.name,s1=g.get(N);s1===void 0?g.set(N,G):s1!==G&&v.add(A.name)}for(let A of v)h.push(`Two different parts are named "${A}"; slots, glue and on = find parts by name, so give each its own.`);Ws(d,h),Us(d,f,h);let y=[],b=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],M=new Map,S=[],w=new Set,z=[],C=l("$min_width"),k=C===void 0?1.5:A0(C),T=l("$label_parts")===!0,q=0;T&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");T&&a&&R&&R.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let U=T&&!!a&&(!R||R.side==="back");if(U){let A=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:A?.color??"#000000",side:"back"})}let j=[];for(let A of d){let G=w1([...A.layers].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.regions)),N;if(A.bends&&G.length){let l1=1/0,M1=-1/0;for(let g1 of G)for(let[d1]of g1)l1=Math.min(l1,d1),M1=Math.max(M1,d1);for(let g1 of A.bends)(g1.x0<l1-.001||g1.x1>M1+.001)&&h.push(`Part "${A.name}" bends from x = ${L2(g1.x0)} to ${L2(g1.x1)}, beyond the part (x = ${L2(l1)} to ${L2(M1)}); only the part itself bends.`)}if(U&&G.length){N=++q;let l1=Xs(G,String(N),a,L0(l("$font")??""));if(l1.length){let M1=A.layers.get("engrave-back")??{regions:[],lines:[]};A.layers=new Map(A.layers).set("engrave-back",{regions:[...M1.regions,...l1],lines:M1.lines})}else h.push(`Part "${A.name}" is too small to take its number ${N}.`)}if(k>0&&G.length){let l1=p0(p0(G,-k/2,"round"),k/2,"round"),M1=B0(y0(G,l1)).filter(g1=>g1.reduce((d1,v1)=>d1+H1(v1),0)>2*k*k);if(M1.length){let g1=M1.slice(0,3).map(d1=>{let[v1,N1,l0,w0]=$0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${M0((v1+l0)/2)}, ${M0((N1+w0)/2)}]`});h.push(`Part "${A.name}" is narrower than ${k} mm ($min_width) in ${M1.length} place${M1.length>1?"s":""}, at ${g1.join(", ")}${M1.length>3?" and more":""} in the part's coordinates.`)}}let s1=new Map;for(let[l1,M1]of A.layers){if(f(l1)==="guide"&&!e.guides)continue;let g1=w1(M1.regions),d1=M1.lines.filter(v1=>v1.length>=2);if((f(l1)==="line"||f(l1)==="guide")&&(d1=[...d1,...g1.map(v1=>[...v1,v1[0]])],g1=[]),G.length&&f(l1)!=="guide"){let v1=u.get(l1)?.bleed??0,N1=v1>0?p0(G,v1,"round"):G;f(l1)!=="cut"&&(g1=b0(g1,N1)),d1=g2(d1,N1,"inside")}(g1.length||d1.length)&&s1.set(l1,{regions:g1,lines:d1})}if(j.push(...js(A.name,s1,u)),G.length){let l1=[];for(let[g1,d1]of s1){let v1=u.get(g1);if(v1?.mode==="cut"&&d1.lines.length)for(let N1 of["front","back"])l1.push({layer:g1,mode:"line",color:"#000000",side:N1,regions:[],lines:d1.lines});!v1||v1.mode!=="fill"&&v1.mode!=="line"||l1.push({layer:g1,mode:v1.mode,color:v1.color,side:v1.side??"front",regions:d1.regions,lines:d1.lines})}let M1={name:A.name,thickness:A.thickness,material:A.material,outline:G,...l1.length&&{marks:l1}};if(A.placements){let g1=new Set;A.placements.forEach((d1,v1)=>{let N1={...M1,copy:st(A,v1),matrix:K0(d1),placed:!0,...A.bends&&{bends:A.bends},...A.step&&{step:A.step},...A.stack&&{stack:A.stack}};x.push(N1),A.on!==void 0&&M.set(N1,A.on);let l0=N1.matrix.map(w0=>w0.toFixed(6)).join(",");g1.has(l0)&&w.add(N1),g1.add(l0)}),g1.size<A.placements.length&&h.push(`Copies of part "${A.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let g1=0;g1<A.qty;g1++)S.push({...M1,copy:st(A,g1),matrix:K0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...A.step&&{step:A.step}})}let K=B0(G),S1=K.length;if(S1>1){let l1=d1=>d1.reduce((v1,N1)=>v1+H1(N1),0),g1=[...K].sort((d1,v1)=>l1(v1)-l1(d1)).slice(1,4).map(d1=>{let[v1,N1,l0,w0]=$0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${M0(v1)}, ${M0(N1)}] to [${M0(l0)}, ${M0(w0)}]`}).join(", ");h.push(`Part "${A.name}" cuts into ${S1} separate pieces. Join them, or make them separate parts. The smaller ${S1===2?"one is":"ones are"} at ${g1}${S1>4?" and more":""}, in the part's coordinates.`)}let Y1=0;for(let[l1,M1]of s1)if(f(l1)==="cut"){for(let g1 of M1.regions)Y1+=at(g1,!0);for(let g1 of M1.lines)Y1+=at(g1,!1)}let G1=$0(s1)??[0,0,0,0],A1=e.kerf??A.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new i1("$kerf must be a number, 0 or more");let B1={name:A.name,qty:A.qty,width:M0(G1[2]-G1[0]),height:M0(G1[3]-G1[1]),pieces:S1,cutLength:Math.round(Y1),thickness:A.thickness,kerf:A1,material:A.material,...A.stack&&{stack:A.stack},...A.glue&&{glued:A.glue.host},...A.mirrored&&{mirrored:!0},...N!==void 0&&{label:N}};if(b&&b.parts.push({name:A.name,kerf:A1,qty:A.qty,...A.stack&&{stack:A.stack},...A.glue&&{glue:A.glue},...A.on&&{on:A.on},cutRegions:G.map(l1=>l1.map(([M1,g1])=>[M1,g1])),cutLines:[...s1].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.lines.map(M1=>M1.map(([g1,d1])=>[g1,d1])))}),A1>0){for(let[l1,M1]of s1)if(f(l1)==="cut"){let g1=M1.regions.filter(N1=>H1(N1)<0);M1.regions=p0(M1.regions,A1/2,"round",Math.min(.01,A1/20));let d1=M1.regions.filter(N1=>H1(N1)<0),v1=g1.length-d1.length;if(v1>0){let N1=w0=>{let[$2,e3,d9,m9]=$0(new Map([["cut",{regions:[w0],lines:[]}]]));return[($2+d9)/2,(e3+m9)/2]},l0=g1.map(N1).filter(([w0,$2])=>!d1.some(e3=>it(e3,w0,$2))).slice(0,3).map(([w0,$2])=>`[${M0(w0)}, ${M0($2)}]`);h.push(`Part "${A.name}": ${v1} hole${v1===1?" is":"s are"} narrower than the ${A1} mm kerf and will not be cut${l0.length?`, at ${l0.join(", ")}${v1>l0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(B1),z.push({info:B1,layers:s1})}Bs(x,M,h);let V=new Map,Q=x.filter(A=>!w.has(A)).flatMap(A=>{let G=J5(A);for(let N of G)V.set(N,A);return G}),{found:W,complete:o1}=e7(Q,i.maxCollisionPairs),m1=W.filter(([A,G])=>V.get(A)!==V.get(G)).map(([A,G])=>[V.get(A)??A,V.get(G)??G]).filter(([A,G],N,s1)=>s1.findIndex(([K,S1])=>K===A&&S1===G)===N);o1||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[A,G]of m1.slice(0,5)){let[N,s1]=o5(A),[K,S1]=o5(G),Y1=[0,1,2].map(G1=>M0((Math.max(N[G1],K[G1])+Math.min(s1[G1],S1[G1]))/2));h.push(`Parts "${A.name}"${A.copy>1?` (copy ${A.copy})`:""} and "${G.name}"${G.copy>1?` (copy ${G.copy})`:""} collide in the assembly, around [${Y1.join(", ")}]. Check their edges and where they are placed.`)}if(m1.length>5&&h.push(`${m1.length-5} more pairs of parts collide in the assembly.`),_s(j,h),x.length&&S.length){let A=[...new Set(S.map(G=>`"${G.name}"`))];h.push(`${A.length===1?"Part":"Parts"} ${A.slice(0,5).join(", ")}${A.length>5?` and ${A.length-5} more`:""} ${A.length===1?"has":"have"} no at or rotate, so ${A.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...Qe(x,S))}let I=0;for(let A of z){let G=0;for(let N of A.layers.values()){for(let s1 of N.regions)G+=s1.length;for(let s1 of N.lines)G+=s1.length}I+=G*A.info.qty}if(I>i.maxOutputPoints)throw new i1(`The files would have ${I} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let $=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray($)||!(Number.isFinite($[0])&&$[0]>0)||!(Number.isFinite($[1])&&$[1]>0))throw new i1("$sheet must be [width, height], both more than 0");let Z=e.gap??A0(l("$gap")??3),_=e.margin??Z;if(!(Number.isFinite(Z)&&Z>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(_)&&_>=0))throw new i1("margin must be a number, 0 or more");let L1=e.nest??l("$nest")===!0,W1=e.layout??(l("$layout")==="none"?"none":"pack"),E1=[...u.keys()].filter(A=>!["engrave","score","cut","guide"].includes(A)),Z1=A=>(u.get(A)?.order??0)*2+(f(A)==="fill"?0:1),o0=["engrave",...E1.map((A,G)=>[A,G]).sort((A,G)=>Z1(A[0])-Z1(G[0])||A[1]-G[1]).map(([A])=>A),"score","cut","guide"].map(A=>u.get(A)).filter(Boolean),L=o0.filter(A=>A.side!=="back"),F=[...o0.filter(A=>A.side==="back")],t1=l("$registration")===!0;t1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),t1&&!L.some(A=>A.name==="registration")&&L.push(u.get("registration"));let r1=[],y1=[1,0,0,-1,0,0],P=A=>$0(A)??[0,0,0,0],Y=(A,G)=>z3({layers:A,parts:[]},G).layers;if(W1==="none"){let A=[];for(let K of z)for(let S1=0;S1<K.info.qty;S1++)A.push({part:K.info.name,copy:S1+1,layers:Y(K.layers,y1),rotated:!1});let G=new Map;for(let K of A)for(let[S1,Y1]of K.layers){let G1=G.get(S1)??{regions:[],lines:[]};for(let A1 of Y1.regions)G1.regions.push(A1);for(let A1 of Y1.lines)G1.lines.push(A1);G.set(S1,G1)}let N=P(G),s1=[1,0,0,1,_-N[0],_-N[1]];for(let K of A)K.layers=Y(K.layers,s1),K.offset=[s1[4],s1[5]];r1.push(X(A,N[2]-N[0]+2*_,N[3]-N[1]+2*_,z[0]?.info))}else{let A=new Map;for(let G of z){let N=`${G.info.material}|${G.info.thickness}`;A.set(N,[...A.get(N)??[],G])}for(let G of A.values()){let[N,s1]=$,K=[];for(let d1 of G){let v1=Y(d1.layers,y1),N1=P(v1),l0=N1[2]-N1[0],w0=N1[3]-N1[1],$2=!1;(l0>N-2*_||w0>s1-2*_)&&w0<=N-2*_&&l0<=s1-2*_&&(v1=Y(v1,[0,1,-1,0,0,0]),N1=P(v1),l0=N1[2]-N1[0],w0=N1[3]-N1[1],$2=!0),(l0>N-2*_||w0>s1-2*_)&&h.push(`Part "${d1.info.name}" (${M0(l0)} x ${M0(w0)} mm) is bigger than the ${N} x ${s1} mm sheet.`),v1=Y(v1,[1,0,0,1,-N1[0],-N1[1]]);for(let e3=0;e3<d1.info.qty;e3++)K.push({info:d1.info,layers:v1,w:l0,h:w0,copy:e3+1,rotated:$2})}K.sort((d1,v1)=>v1.h-d1.h||v1.w-d1.w);let S1=L1?Gs(K,Z,d1=>f(d1)==="cut"):K,Y1=[],G1=_,A1=_,B1=0,l1=0,M1=0,g1=()=>{if(Y1.length&&r1.length>=i.maxSheets)throw new i1(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);Y1.length&&r1.push(X(Y1,Math.max(l1+_,1),Math.max(M1+_,1),G[0].info)),Y1=[],G1=_,A1=_,B1=0,l1=0,M1=0};for(let d1 of S1){G1>_&&G1+d1.w>N-_&&(G1=_,A1+=B1+Z,B1=0),Y1.length&&A1+d1.h>s1-_&&g1(),Y1.push({part:d1.info.name,copy:d1.copy,layers:Y(d1.layers,[1,0,0,1,G1,A1]),rotated:d1.rotated});for(let v1 of d1.inner??[])Y1.push({part:v1.item.info.name,copy:v1.item.copy,layers:Y(v1.item.layers,[1,0,0,1,G1+v1.dx,A1+v1.dy]),rotated:v1.item.rotated});l1=Math.max(l1,G1+d1.w),M1=Math.max(M1,A1+d1.h),G1+=d1.w+Z,B1=Math.max(B1,d1.h)}g1()}}function X(A,G,N,s1){let K=M0(G),S1=M0(N);if(t1){let A1=Math.min(5,_-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let B1=(l1,M1)=>[[l1,M1],[l1+A1,M1],[l1+A1,M1+A1],[l1,M1+A1]];A=[...A,{part:"registration",copy:1,layers:new Map([["registration",{regions:[B1(.5,.5),B1(K-.5-A1,.5),B1(.5,S1-.5-A1)],lines:[]}]]),rotated:!1}]}}let Y1=A.some(A1=>F.some(B1=>A1.layers.has(B1.name))),G1=Y1?A.map(A1=>({...A1,layers:Y(A1.layers,[-1,0,0,1,K,0])})):[];return{width:K,height:S1,material:s1?.material??"material",thickness:s1?.thickness??0,items:A,paths:M4(A,L),svg:w4(A,K,S1,L),dxf:te(A,K,S1,L),...Y1&&{back:{paths:M4(G1,F),svg:w4(G1,K,S1,F),dxf:te(G1,K,S1,F)}}}}let b1=r1.length===1?r1[0]:void 0,a1=b1?[]:r1.flatMap((A,G)=>{let N=r1.slice(0,G).reduce((s1,K)=>s1+K.height+10,0);return A.items.map(s1=>({...s1,layers:Y(s1.layers,[1,0,0,1,0,N])}))}),R1=M0(Math.max(1,...r1.map(A=>A.width))),e1=M0(Math.max(1,r1.reduce((A,G)=>A+G.height,0)+10*Math.max(0,r1.length-1))),T1=b1?b1.svg:w4(a1,R1,e1,L),r0=b1?b1.paths:M4(a1,L);return{sheets:r1,width:b1?.width??R1,height:b1?.height??e1,paths:r0,svg:T1,parts:y,assembly:x,layers:[...L,...F],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function Ns(t){if(!t.includes("*"))return n=>n===t;let e=new RegExp(`^${t.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return n=>e.test(n)}function Us(t,e,n){if(!t.some(l=>l.slots))return;let c=new Map,r=l=>{let h=c.get(l);return h||(h=w1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},a=l=>(l.placements??[]).flatMap(h=>J5({name:l.name,copy:0,placed:!0,matrix:K0(h),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),s=new Map,i=new Map;for(let l of t){if(!l.slots)continue;if(!l.placements){n.push(`Part "${l.name}" has slots but no at or rotate, so they can't be found.`);continue}let h=new Set;for(let g of l.slots){let v=g.startsWith("!"),y=Ns(v?g.slice(1):g),b=t.filter(x=>x!==l&&y(x.name));!b.length&&!v&&n.push(`Part "${l.name}": no part "${g}" to cut slots for.`);for(let x of b)v?h.delete(x):h.add(x)}let u=[...h].flatMap(a),f=(l.placements??[]).map(g=>w1(J5({name:l.name,copy:0,placed:!0,matrix:K0(g),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).flatMap(v=>{let y=r7(v,u,l.clearance??.1);return l.bends?b0(y,p0(v.outline,1,"miter")):y}))),d=(g,v)=>M3(g,v).reduce((y,b)=>y+Math.abs(H1(b)),0)>.001,m=l.stack??1;if(m>1){let g=y=>f.filter((b,x)=>x%m===y),v=Array.from({length:m},(y,b)=>w1(g(b).flat()));if(v.slice(1).some(y=>d(v[0],y))){Array.from({length:m},(y,b)=>g(b)).some(y=>y.slice(1).some(b=>d(y[0],b)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),i.set(l,v);continue}}f.slice(1).some(g=>d(f[0],g))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);let p=w1(f.flat());if(!p.length){l.slots.some(g=>g.includes("*"))||n.push(`Part "${l.name}": none of ${l.slots.map(g=>`"${g}"`).join(", ")} pass through it, so it has no slots.`);continue}s.set(l,p)}let o=(l,h)=>{let u=new Map(l);for(let[f,d]of l)u.set(f,{regions:y0(d.regions,h),lines:g2(d.lines,h,"outside")});return u};for(let[l,h]of s)l.layers=o(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/u,layers:d.length?o(l.layers,d):l.layers,placements:l.placements.filter((p,g)=>g%u===m),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function Bs(t,e,n){let c=new Map;for(let[r,a]of e){let s=t.filter(M=>M.name===a&&M.placed);if(!s.length){c.has(a)||n.push(`Part "${r.name}" is on "${a}", which is not a placed part.`),c.set(a,0);continue}let i=[...e].filter(([M,S])=>M.name===r.name&&S===a).length,o=s.length===i?s[r.copy-1]:s[0];if(!o?.bends?.length)continue;let[l,h,u,f]=[1/0,1/0,-1/0,-1/0];for(let M of r.outline)for(let[S,w]of M)l=Math.min(l,S),h=Math.min(h,w),u=Math.max(u,S),f=Math.max(f,w);let d=r.matrix,[m,p,g]=[(l+u)/2,(h+f)/2,r.thickness/2],v=[d[0]*m+d[1]*p+d[2]*g+d[3],d[4]*m+d[5]*p+d[6]*g+d[7],d[8]*m+d[9]*p+d[10]*g+d[11]],y=S0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=Y5(o.bends,o.thickness)[n7(o.bends,b)];r.matrix=$1(o.matrix,$1(x,$1(y,r.matrix)))}}function Gs(t,e,n){var l;let c=[],r=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)H1(m)<0&&u.push([...m].reverse());return u.length?p0(w1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let m of h)for(let p=0,g=m.length-1;p<m.length;g=p++){let[v,y]=m[g],[b,x]=m[p];y<=f?x>f&&(b-v)*(f-y)-(u-v)*(x-y)>0&&d++:x<=f&&(b-v)*(f-y)-(u-v)*(x-y)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)H1(m)>0&&u.push(m);return w1(u)},i=(h,u)=>{let{w:f,h:d}=u,m=s(u),p=[];for(let g of m)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))p.push(g[v]);for(let g of h){if(H1(g)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[S,w]of g)v=Math.min(v,S),y=Math.min(y,w),b=Math.max(b,S),x=Math.max(x,w);if(b-v<f||x-y<d)continue;let M=Math.max(.5,Math.min(f,d,b-v-f+1,x-y-d+1)/4);for(let S=y;S<=x-d+1e-9;S+=M)for(let w=v;w<=b-f+1e-9;w+=M){if(!p.every(([C,k])=>a(h,C+w,k+S)))continue;let z=m.map(C=>C.map(([k,T])=>[k+w,T+S]));if(y0(z,h).reduce((C,k)=>C+Math.abs(H1(k)),0)<.01)return[w,S]}}},o=[];for(let h of t){let u=!1;for(let d of c){let m=i(d.region,h);if(!m)continue;let[p,g]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+p,dy:d.oy+g}),d.region=y0(d.region,p0(s(h).map(y=>y.map(([b,x])=>[b+p,x+g])),e,"miter"));let v=r(h);v.length&&c.push({host:d.host,ox:d.ox+p,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;o.push(h);let f=r(h);f.length&&c.push({host:h,ox:0,oy:0,region:f})}return o}function st(t,e){if(!t.copies)return e+1;let n=t.stack??1;return(t.copies[Math.floor(e/n)]-1)*n+e%n+1}function js(t,e,n){let c=[...n.keys()],r=[...e.keys()].filter(i=>n.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),a=[];if(r.length<2)return a;let s=i=>i==="engrave"?-1/0:(n.get(i)?.order??0)*2+c.indexOf(i)/c.length;r.sort((i,o)=>s(i)-s(o));for(let i=0;i<r.length-1;i++){let o=n.get(r[i]).side??"front",l=r.slice(i+1).filter(u=>(n.get(u).side??"front")===o);if(!l.length)continue;let h;for(let u of B0(e.get(r[i]).regions)){let f=u.reduce((M,S)=>M+H1(S),0);if(!(f>.001)||!p0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=y0(d,e.get(M).regions));if(d.reduce((M,S)=>M+H1(S),0)>.001*Math.max(1,f))continue;let p=l.filter(M=>b0(u,e.get(M).regions).length),g=p.length?p:l;if(h){h.count++;for(let M of g)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=$0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:r[i],under:g,count:1,at:[M0((v+b)/2),M0((y+x)/2)]}}h&&a.push(h)}return a}function _s(t,e){for(let n of t.slice(0,5)){let c=n.under.map(a=>`"${a}"`),r=c.length>1?`${c.slice(0,-1).join(", ")} and ${c.at(-1)}`:c[0];e.push(`Part "${n.part}": ${n.count>1?`${n.count} fills`:"a fill"} on layer "${n.layer}" (${n.count>1?"the first ":""}at [${n.at.join(", ")}]) ${n.count>1?"lie":"lies"} wholly under ${r}, stacked above it in the files: printed, ${n.count>1?"they":"it"} won't show, and engraved, ${n.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${n.layer}" a higher order.`)}if(t.length>5){let n=t.slice(5),c=new Set(n.map(a=>a.part)).size,r=[...new Set(n.map(a=>`"${a.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${c} part${c>1?"s":""} (layer${r.length>1?"s":""} ${r.slice(0,5).join(", ")}${r.length>5?" and more":""}).`)}}function Ws(t,e){let n=new Set,c=(r,a)=>{if(!r.glue||n.has(r))return;if(a.includes(r)){e.push(`Part "${r.name}" is glued in a loop of parts; it is left where it is.`),n.add(r);return}let s=t.find(h=>h.name===r.glue.host&&h!==r);if(!s?.placements){e.push(`Part "${r.name}" is glued to "${r.glue.host}", which is not a placed part.`),n.add(r);return}c(s,[...a,r]);let i=s.placements.map(K0),o=r.glue.face==="top"?s.thickness:-r.thickness,l=r.placements.length/(r.stack??1);r.placements=r.placements.map((h,u)=>{let f=i.length===l?i[Math.floor(u/(r.stack??1))]:i[0];return{...h,matrix:$1(f,$1(D0(0,0,o),K0(h)))}}),n.add(r)};for(let r of t)c(r,[])}function Xs(t,e,n,c){let r=0,a=50;for(let p=0;p<14;p++){let g=(r+a)/2;p0(t,-g,"round").length?r=g:a=g}if(r<1)return[];let s=p0(t,-r*.98,"round"),i=$0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((p,g)=>s.reduce((v,y)=>v+(it(y,p,g)?H1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((p,g)=>H1(g)>H1(p)?g:p)[0]);let u=Math.min(6,Math.max(2,r*.9)),f=b4(n,e,{size:u,font:c,halign:"center",valign:"center",spacing:1}),d=$0(new Map([["t",{regions:f,lines:[]}]])),m=d?Math.min(1,1.6*r/Math.max(d[2]-d[0],1e-9)):1;return f.map(p=>p.map(([g,v])=>[o-g*m,l+v*m]).reverse())}function it(t,e,n){let c=!1;for(let r=0,a=t.length-1;r<t.length;a=r++){let[s,i]=t[r],[o,l]=t[a];i>n!=l>n&&e<(o-s)*(n-i)/(l-i)+s&&(c=!c)}return c}function lt(t){switch(t.kind){case"num":return t.unit?{ok:!1}:{ok:!0,value:t.value};case"str":case"bool":return{ok:!0,value:t.value};case"unary":return t.op==="-"&&t.arg.kind==="num"?{ok:!0,value:-t.arg.value}:{ok:!1};case"list":{let e=[];for(let n of t.items){if(n.kind!=="item")return{ok:!1};let c=lt(n.expr);if(!c.ok||typeof c.value!="number")return{ok:!1};e.push(c.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function ot(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function Zs(t){let{program:e,comments:n}=r2(t),c=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),r=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),a=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),s=[];for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let o=lt(i.value);if(!o.ok)continue;let l=c.filter(p=>p.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(l.toLowerCase()==="hidden")continue;let h=r.get(i.pos.line),u=a.get(i.pos.line-1)??"",f=o.value,d={name:i.name,caption:u,group:l,type:typeof f=="number"||Array.isArray(f)?"number":typeof f=="boolean"?"boolean":"string",initial:f,span:i.span},m=h?/^\[(.*)\]$/.exec(h.trim()):null;if(m){let p=m[1];if(p.includes(",")||/[a-zA-Z"]/.test(p)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(p))d.options=p.split(",").map(g=>{let[v,y]=g.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=ot(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let g=p.split(":").map(ot);g.every(v=>v!==void 0)&&(g.length===1?d.max=g[0]:g.length===2?(d.min=g[0],d.max=g[1]):(d.min=g[0],d.step=g[1],d.max=g[2]))}}s.push(d)}return{parameters:s}}var Ys=8,Js=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,Ks=(t,e)=>Math.max(1,Js.exec(t.slice(e-1))?.[0].length??1);function Qs(t,e,n={}){if(!(t instanceof i1))return`error: ${t instanceof Error?t.message:String(t)}`;let c=n.file??"design.kerf",r=(o,l,h)=>`${o?`<${o}>`:c}:${l}:${h}`,a=o=>o===void 0?e:(Object.prototype.hasOwnProperty.call(g5,o)?g5[o]:void 0)??n.resolve?.(o),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${r(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
2230
- `)?.[t.line-1]?.replace(/\r$/,"");if(l!==void 0){let h=String(t.line),u=" ".repeat(h.length),f=l.slice(0,t.col-1),d=Ks(l,t.col),m=f.replace(/[^\t]/g," ");s.push(`${u} |`,`${h} | ${l}`,`${u} | ${m}${"^".repeat(d)}`)}}for(let o of ei(t,r))s.push(` = ${o}`);let i=t.call?p5(t.call):void 0;return i&&s.push(` = ${b6(i)}: ${i.doc}`),s.join(`
2231
- `)}function ei(t,e){let n=a=>`in ${a.kind==="module"?"module ":""}${a.name}(), called at ${e(a.file,a.line,a.col)}${a.count>1?` (${a.count} times)`:""}`,c=t.trace.slice(0,Ys).map(n),r=t.trace.length-c.length+t.traceMore;return r&&c.push(`and ${r} more call${r===1?"":"s"}`),c}var ht=new Set(["module","function","if","else","for","let","each","use","include"]),ti=new Set(["true","false","undef"]),ni=new Set(["for","if","let","function"]),ne={"(":")","[":"]","{":"}"},ci=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function ri(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let c=n+1;for(;t[c]!=='"';)c+=t[c]==="\\"?2:1;return t.slice(n,c+1)}function ce(t){let{tokens:e}=f5(t),n=[],c=0,r=0,a=s=>{for(;c<s;)if(t[c]===`
2566
+ `}var i8=(t,e)=>{let n=0;for(let c=1;c<t.length;c++)n+=Math.hypot(t[c][0]-t[c-1][0],t[c][1]-t[c-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},w0=t=>Math.round(t*100)/100;function Us(t,e={}){for(let[C,_]of Object.entries(e.params??{}))try{de(C,_)}catch(U){throw new i1(U.message)}let{program:n}=a2(t),c=new Set(n.body.flatMap(C=>C.kind==="assign"?[C.name]:[])),r=Object.keys(e.params??{}).filter(C=>!C.startsWith("$")&&!c.has(C)),a=e.fonts?new x4(e.fonts,e.defaultFont):void 0,s=new D3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(n)}catch(C){let _=C instanceof RangeError?new i1(/call stack/i.test(C.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):C;throw _ instanceof i1&&(_.echoes=s.echoes,_.warnings=[...s.warnings],a?.missing.size&&(_.missingFonts=[...a.missing])),_}let l=C=>o.globals.get(C).value,h=o.warnings;for(let C of r)h.push(`Setting "${C}" is not a variable of the program, so it is ignored.${l3(C,c)}`);let u=o.layers,f=C=>u.get(C)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(C=>C.regions.length||C.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:A0(l("$thickness"))||3,kerf:A0(l("$kerf"))||0,material:g0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let m=C=>JSON.stringify([C.thickness,C.material,[...C.layers].map(([_,U])=>[_,U.regions.map(s1=>s1.map(([Q,L1])=>[Math.round(Q*100),Math.round(L1*100)])),U.lines.map(s1=>s1.map(([Q,L1])=>[Math.round(Q*100),Math.round(L1*100)]))])]),g=new Map,v=new Set;for(let C of d){let _=m(C),U=C.mirrored?`${C.name}\0mirrored`:C.name,s1=g.get(U);s1===void 0?g.set(U,_):s1!==_&&v.add(C.name)}for(let C of v)h.push(`Two different parts are named "${C}"; slots, glue and on = find parts by name, so give each its own.`);Zs(d,h),_s(d,f,h);let y=[],b=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],M=new Map,w=[],k=new Set,z=[],S=l("$min_width"),L=S===void 0?1.5:A0(S),I=l("$label_parts")===!0,q=0;I&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");I&&a&&R&&R.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let N=I&&!!a&&(!R||R.side==="back");if(N){let C=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:C?.color??"#000000",side:"back"})}let G=[];for(let C of d){let _=x1([...C.layers].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.regions)),U;if(C.bends&&_.length){let l1=1/0,z1=-1/0;for(let g1 of _)for(let[d1]of g1)l1=Math.min(l1,d1),z1=Math.max(z1,d1);for(let g1 of C.bends)(g1.x0<l1-.001||g1.x1>z1+.001)&&h.push(`Part "${C.name}" bends from x = ${C2(g1.x0)} to ${C2(g1.x1)}, beyond the part (x = ${C2(l1)} to ${C2(z1)}); only the part itself bends.`)}if(N&&_.length){U=++q;let l1=Ys(_,String(U),a,g0(l("$font")??""));if(l1.length){let z1=C.layers.get("engrave-back")??{regions:[],lines:[]};C.layers=new Map(C.layers).set("engrave-back",{regions:[...z1.regions,...l1],lines:z1.lines})}else h.push(`Part "${C.name}" is too small to take its number ${U}.`)}if(L>0&&_.length){let l1=m0(m0(_,-L/2,"round"),L/2,"round"),z1=_0(b0(_,l1)).filter(g1=>g1.reduce((d1,v1)=>d1+H1(v1),0)>2*L*L);if(z1.length){let g1=z1.slice(0,3).map(d1=>{let[v1,U1,l0,z0]=D0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${w0((v1+l0)/2)}, ${w0((U1+z0)/2)}]`});h.push(`Part "${C.name}" is narrower than ${L} mm ($min_width) in ${z1.length} place${z1.length>1?"s":""}, at ${g1.join(", ")}${z1.length>3?" and more":""} in the part's coordinates.`)}}let s1=new Map;for(let[l1,z1]of C.layers){if(f(l1)==="guide"&&!e.guides)continue;let g1=x1(z1.regions),d1=z1.lines.filter(v1=>v1.length>=2);if((f(l1)==="line"||f(l1)==="guide")&&(d1=[...d1,...g1.map(v1=>[...v1,v1[0]])],g1=[]),_.length&&f(l1)!=="guide"){let v1=u.get(l1)?.bleed??0,U1=v1>0?m0(_,v1,"round"):_;f(l1)!=="cut"&&(g1=x0(g1,U1)),d1=v2(d1,U1,"inside")}(g1.length||d1.length)&&s1.set(l1,{regions:g1,lines:d1})}if(G.push(...Ws(C.name,s1,u)),_.length){let l1=[];for(let[g1,d1]of s1){let v1=u.get(g1);if(v1?.mode==="cut"&&d1.lines.length)for(let U1 of["front","back"])l1.push({layer:g1,mode:"line",color:"#000000",side:U1,regions:[],lines:d1.lines});!v1||v1.mode!=="fill"&&v1.mode!=="line"||l1.push({layer:g1,mode:v1.mode,color:v1.color,side:v1.side??"front",regions:d1.regions,lines:d1.lines})}let z1={name:C.name,thickness:C.thickness,material:C.material,outline:_,...l1.length&&{marks:l1}};if(C.placements){let g1=new Set;C.placements.forEach((d1,v1)=>{let U1={...z1,copy:o8(C,v1),matrix:K0(d1),placed:!0,...C.bends&&{bends:C.bends},...C.step&&{step:C.step},...C.stack&&{stack:C.stack}};x.push(U1),C.on!==void 0&&M.set(U1,C.on);let l0=U1.matrix.map(z0=>z0.toFixed(6)).join(",");g1.has(l0)&&k.add(U1),g1.add(l0)}),g1.size<C.placements.length&&h.push(`Copies of part "${C.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let g1=0;g1<C.qty;g1++)w.push({...z1,copy:o8(C,g1),matrix:K0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...C.step&&{step:C.step}})}let Q=_0(_),L1=Q.length;if(L1>1){let l1=d1=>d1.reduce((v1,U1)=>v1+H1(U1),0),g1=[...Q].sort((d1,v1)=>l1(v1)-l1(d1)).slice(1,4).map(d1=>{let[v1,U1,l0,z0]=D0(new Map([["cut",{regions:d1,lines:[]}]]));return`[${w0(v1)}, ${w0(U1)}] to [${w0(l0)}, ${w0(z0)}]`}).join(", ");h.push(`Part "${C.name}" cuts into ${L1} separate pieces. Join them, or make them separate parts. The smaller ${L1===2?"one is":"ones are"} at ${g1}${L1>4?" and more":""}, in the part's coordinates.`)}let Y1=0;for(let[l1,z1]of s1)if(f(l1)==="cut"){for(let g1 of z1.regions)Y1+=i8(g1,!0);for(let g1 of z1.lines)Y1+=i8(g1,!1)}let G1=D0(s1)??[0,0,0,0],A1=e.kerf??C.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new i1("$kerf must be a number, 0 or more");let _1={name:C.name,qty:C.qty,width:w0(G1[2]-G1[0]),height:w0(G1[3]-G1[1]),pieces:L1,cutLength:Math.round(Y1),thickness:C.thickness,kerf:A1,material:C.material,...C.stack&&{stack:C.stack},...C.glue&&{glued:C.glue.host},...C.mirrored&&{mirrored:!0},...U!==void 0&&{label:U}};if(b&&b.parts.push({name:C.name,kerf:A1,qty:C.qty,...C.stack&&{stack:C.stack},...C.glue&&{glue:C.glue},...C.on&&{on:C.on},cutRegions:_.map(l1=>l1.map(([z1,g1])=>[z1,g1])),cutLines:[...s1].filter(([l1])=>f(l1)==="cut").flatMap(([,l1])=>l1.lines.map(z1=>z1.map(([g1,d1])=>[g1,d1])))}),A1>0){for(let[l1,z1]of s1)if(f(l1)==="cut"){let g1=z1.regions.filter(U1=>H1(U1)<0);z1.regions=m0(z1.regions,A1/2,"round",Math.min(.01,A1/20));let d1=z1.regions.filter(U1=>H1(U1)<0),v1=g1.length-d1.length;if(v1>0){let U1=z0=>{let[$2,e3,gn,vn]=D0(new Map([["cut",{regions:[z0],lines:[]}]]));return[($2+gn)/2,(e3+vn)/2]},l0=g1.map(U1).filter(([z0,$2])=>!d1.some(e3=>l8(e3,z0,$2))).slice(0,3).map(([z0,$2])=>`[${w0(z0)}, ${w0($2)}]`);h.push(`Part "${C.name}": ${v1} hole${v1===1?" is":"s are"} narrower than the ${A1} mm kerf and will not be cut${l0.length?`, at ${l0.join(", ")}${v1>l0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(_1),z.push({info:_1,layers:s1})}Gs(x,M,h);let V=new Map,J=x.filter(C=>!k.has(C)).flatMap(C=>{let _=e4(C);for(let U of _)V.set(U,C);return _}),{found:o1,complete:Z}=c7(J,i.maxCollisionPairs),p1=o1.filter(([C,_])=>V.get(C)!==V.get(_)).map(([C,_])=>[V.get(C)??C,V.get(_)??_]).filter(([C,_],U,s1)=>s1.findIndex(([Q,L1])=>Q===C&&L1===_)===U);Z||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[C,_]of p1.slice(0,5)){let[U,s1]=l5(C),[Q,L1]=l5(_),Y1=[0,1,2].map(G1=>w0((Math.max(U[G1],Q[G1])+Math.min(s1[G1],L1[G1]))/2));h.push(`Parts "${C.name}"${C.copy>1?` (copy ${C.copy})`:""} and "${_.name}"${_.copy>1?` (copy ${_.copy})`:""} collide in the assembly, around [${Y1.join(", ")}]. Check their edges and where they are placed.`)}if(p1.length>5&&h.push(`${p1.length-5} more pairs of parts collide in the assembly.`),Xs(G,h),x.length&&w.length){let C=[...new Set(w.map(_=>`"${_.name}"`))];h.push(`${C.length===1?"Part":"Parts"} ${C.slice(0,5).join(", ")}${C.length>5?` and ${C.length-5} more`:""} ${C.length===1?"has":"have"} no at or rotate, so ${C.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...n7(x,w))}let E=0;for(let C of z){let _=0;for(let U of C.layers.values()){for(let s1 of U.regions)_+=s1.length;for(let s1 of U.lines)_+=s1.length}E+=_*C.info.qty}if(E>i.maxOutputPoints)throw new i1(`The files would have ${E} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let $=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray($)||!(Number.isFinite($[0])&&$[0]>0)||!(Number.isFinite($[1])&&$[1]>0))throw new i1("$sheet must be [width, height], both more than 0");let X=e.gap??A0(l("$gap")??3),j=e.margin??X;if(!(Number.isFinite(X)&&X>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(j)&&j>=0))throw new i1("margin must be a number, 0 or more");let w1=e.nest??l("$nest")===!0,W1=e.layout??(l("$layout")==="none"?"none":"pack"),E1=[...u.keys()].filter(C=>!["engrave","score","cut","guide"].includes(C)),Z1=C=>(u.get(C)?.order??0)*2+(f(C)==="fill"?0:1),o0=["engrave",...E1.map((C,_)=>[C,_]).sort((C,_)=>Z1(C[0])-Z1(_[0])||C[1]-_[1]).map(([C])=>C),"score","cut","guide"].map(C=>u.get(C)).filter(Boolean),A=o0.filter(C=>C.side!=="back"),F=[...o0.filter(C=>C.side==="back")],t1=l("$registration")===!0;t1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),t1&&!A.some(C=>C.name==="registration")&&A.push(u.get("registration"));let r1=[],y1=[1,0,0,-1,0,0],P=C=>D0(C)??[0,0,0,0],Y=(C,_)=>z3({layers:C,parts:[]},_).layers;if(W1==="none"){let C=[];for(let Q of z)for(let L1=0;L1<Q.info.qty;L1++)C.push({part:Q.info.name,copy:L1+1,layers:Y(Q.layers,y1),rotated:!1});let _=new Map;for(let Q of C)for(let[L1,Y1]of Q.layers){let G1=_.get(L1)??{regions:[],lines:[]};for(let A1 of Y1.regions)G1.regions.push(A1);for(let A1 of Y1.lines)G1.lines.push(A1);_.set(L1,G1)}let U=P(_),s1=[1,0,0,1,j-U[0],j-U[1]];for(let Q of C)Q.layers=Y(Q.layers,s1),Q.offset=[s1[4],s1[5]];r1.push(W(C,U[2]-U[0]+2*j,U[3]-U[1]+2*j,z[0]?.info))}else{let C=new Map;for(let _ of z){let U=`${_.info.material}|${_.info.thickness}`;C.set(U,[...C.get(U)??[],_])}for(let _ of C.values()){let[U,s1]=$,Q=[];for(let d1 of _){let v1=Y(d1.layers,y1),U1=P(v1),l0=U1[2]-U1[0],z0=U1[3]-U1[1],$2=!1;(l0>U-2*j||z0>s1-2*j)&&z0<=U-2*j&&l0<=s1-2*j&&(v1=Y(v1,[0,1,-1,0,0,0]),U1=P(v1),l0=U1[2]-U1[0],z0=U1[3]-U1[1],$2=!0),(l0>U-2*j||z0>s1-2*j)&&h.push(`Part "${d1.info.name}" (${w0(l0)} x ${w0(z0)} mm) is bigger than the ${U} x ${s1} mm sheet.`),v1=Y(v1,[1,0,0,1,-U1[0],-U1[1]]);for(let e3=0;e3<d1.info.qty;e3++)Q.push({info:d1.info,layers:v1,w:l0,h:z0,copy:e3+1,rotated:$2})}Q.sort((d1,v1)=>v1.h-d1.h||v1.w-d1.w);let L1=w1?js(Q,X,d1=>f(d1)==="cut"):Q,Y1=[],G1=j,A1=j,_1=0,l1=0,z1=0,g1=()=>{if(Y1.length&&r1.length>=i.maxSheets)throw new i1(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);Y1.length&&r1.push(W(Y1,Math.max(l1+j,1),Math.max(z1+j,1),_[0].info)),Y1=[],G1=j,A1=j,_1=0,l1=0,z1=0};for(let d1 of L1){G1>j&&G1+d1.w>U-j&&(G1=j,A1+=_1+X,_1=0),Y1.length&&A1+d1.h>s1-j&&g1(),Y1.push({part:d1.info.name,copy:d1.copy,layers:Y(d1.layers,[1,0,0,1,G1,A1]),rotated:d1.rotated});for(let v1 of d1.inner??[])Y1.push({part:v1.item.info.name,copy:v1.item.copy,layers:Y(v1.item.layers,[1,0,0,1,G1+v1.dx,A1+v1.dy]),rotated:v1.item.rotated});l1=Math.max(l1,G1+d1.w),z1=Math.max(z1,A1+d1.h),G1+=d1.w+X,_1=Math.max(_1,d1.h)}g1()}}function W(C,_,U,s1){let Q=w0(_),L1=w0(U);if(t1){let A1=Math.min(5,j-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let _1=(l1,z1)=>[[l1,z1],[l1+A1,z1],[l1+A1,z1+A1],[l1,z1+A1]];C=[...C,{part:"registration",copy:1,layers:new Map([["registration",{regions:[_1(.5,.5),_1(Q-.5-A1,.5),_1(.5,L1-.5-A1)],lines:[]}]]),rotated:!1}]}}let Y1=C.some(A1=>F.some(_1=>A1.layers.has(_1.name))),G1=Y1?C.map(A1=>({...A1,layers:Y(A1.layers,[-1,0,0,1,Q,0])})):[];return{width:Q,height:L1,material:s1?.material??"material",thickness:s1?.thickness??0,items:C,paths:z4(C,A),svg:k4(C,Q,L1,A),dxf:c6(C,Q,L1,A),...Y1&&{back:{paths:z4(G1,F),svg:k4(G1,Q,L1,F),dxf:c6(G1,Q,L1,F)}}}}let b1=r1.length===1?r1[0]:void 0,a1=b1?[]:r1.flatMap((C,_)=>{let U=r1.slice(0,_).reduce((s1,Q)=>s1+Q.height+10,0);return C.items.map(s1=>({...s1,layers:Y(s1.layers,[1,0,0,1,0,U])}))}),$1=w0(Math.max(1,...r1.map(C=>C.width))),e1=w0(Math.max(1,r1.reduce((C,_)=>C+_.height,0)+10*Math.max(0,r1.length-1))),I1=b1?b1.svg:k4(a1,$1,e1,A),r0=b1?b1.paths:z4(a1,A);return{sheets:r1,width:b1?.width??$1,height:b1?.height??e1,paths:r0,svg:I1,parts:y,assembly:x,layers:[...A,...F],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function Bs(t){if(!t.includes("*"))return n=>n===t;let e=new RegExp(`^${t.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return n=>e.test(n)}function _s(t,e,n){if(!t.some(l=>l.slots))return;let c=new Map,r=l=>{let h=c.get(l);return h||(h=x1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},a=l=>(l.placements??[]).flatMap(h=>e4({name:l.name,copy:0,placed:!0,matrix:K0(h),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),s=new Map,i=new Map;for(let l of t){if(!l.slots)continue;if(!l.placements){n.push(`Part "${l.name}" has slots but no at or rotate, so they can't be found.`);continue}let h=new Set;for(let g of l.slots){let v=g.startsWith("!"),y=Bs(v?g.slice(1):g),b=t.filter(x=>x!==l&&y(x.name));!b.length&&!v&&n.push(`Part "${l.name}": no part "${g}" to cut slots for.`);for(let x of b)v?h.delete(x):h.add(x)}let u=[...h].flatMap(a),f=(l.placements??[]).map(g=>x1(e4({name:l.name,copy:0,placed:!0,matrix:K0(g),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).flatMap(v=>{let y=i7(v,u,l.clearance??.1);return l.bends?x0(y,m0(v.outline,1,"miter")):y}))),d=(g,v)=>M3(g,v).reduce((y,b)=>y+Math.abs(H1(b)),0)>.001,p=l.stack??1;if(p>1){let g=y=>f.filter((b,x)=>x%p===y),v=Array.from({length:p},(y,b)=>x1(g(b).flat()));if(v.slice(1).some(y=>d(v[0],y))){Array.from({length:p},(y,b)=>g(b)).some(y=>y.slice(1).some(b=>d(y[0],b)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),i.set(l,v);continue}}f.slice(1).some(g=>d(f[0],g))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);let m=x1(f.flat());if(!m.length){l.slots.some(g=>g.includes("*"))||n.push(`Part "${l.name}": none of ${l.slots.map(g=>`"${g}"`).join(", ")} pass through it, so it has no slots.`);continue}s.set(l,m)}let o=(l,h)=>{let u=new Map(l);for(let[f,d]of l)u.set(f,{regions:b0(d.regions,h),lines:v2(d.lines,h,"outside")});return u};for(let[l,h]of s)l.layers=o(l.layers,h);for(let[l,h]of i){let u=h.length,f=h.map((d,p)=>({...l,name:`${l.name}, layer ${p+1}`,qty:l.qty/u,layers:d.length?o(l.layers,d):l.layers,placements:l.placements.filter((m,g)=>g%u===p),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function Gs(t,e,n){let c=new Map;for(let[r,a]of e){let s=t.filter(M=>M.name===a&&M.placed);if(!s.length){c.has(a)||n.push(`Part "${r.name}" is on "${a}", which is not a placed part.`),c.set(a,0);continue}let i=[...e].filter(([M,w])=>M.name===r.name&&w===a).length,o=s.length===i?s[r.copy-1]:s[0];if(!o?.bends?.length)continue;let[l,h,u,f]=[1/0,1/0,-1/0,-1/0];for(let M of r.outline)for(let[w,k]of M)l=Math.min(l,w),h=Math.min(h,k),u=Math.max(u,w),f=Math.max(f,k);let d=r.matrix,[p,m,g]=[(l+u)/2,(h+f)/2,r.thickness/2],v=[d[0]*p+d[1]*m+d[2]*g+d[3],d[4]*p+d[5]*m+d[6]*g+d[7],d[8]*p+d[9]*m+d[10]*g+d[11]],y=L0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=Q5(o.bends,o.thickness)[a7(o.bends,b)];r.matrix=O1(o.matrix,O1(x,O1(y,r.matrix)))}}function js(t,e,n){var l;let c=[],r=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)H1(p)<0&&u.push([...p].reverse());return u.length?m0(x1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let p of h)for(let m=0,g=p.length-1;m<p.length;g=m++){let[v,y]=p[g],[b,x]=p[m];y<=f?x>f&&(b-v)*(f-y)-(u-v)*(x-y)>0&&d++:x<=f&&(b-v)*(f-y)-(u-v)*(x-y)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)H1(p)>0&&u.push(p);return x1(u)},i=(h,u)=>{let{w:f,h:d}=u,p=s(u),m=[];for(let g of p)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))m.push(g[v]);for(let g of h){if(H1(g)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[w,k]of g)v=Math.min(v,w),y=Math.min(y,k),b=Math.max(b,w),x=Math.max(x,k);if(b-v<f||x-y<d)continue;let M=Math.max(.5,Math.min(f,d,b-v-f+1,x-y-d+1)/4);for(let w=y;w<=x-d+1e-9;w+=M)for(let k=v;k<=b-f+1e-9;k+=M){if(!m.every(([S,L])=>a(h,S+k,L+w)))continue;let z=p.map(S=>S.map(([L,I])=>[L+k,I+w]));if(b0(z,h).reduce((S,L)=>S+Math.abs(H1(L)),0)<.01)return[k,w]}}},o=[];for(let h of t){let u=!1;for(let d of c){let p=i(d.region,h);if(!p)continue;let[m,g]=p;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+m,dy:d.oy+g}),d.region=b0(d.region,m0(s(h).map(y=>y.map(([b,x])=>[b+m,x+g])),e,"miter"));let v=r(h);v.length&&c.push({host:d.host,ox:d.ox+m,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;o.push(h);let f=r(h);f.length&&c.push({host:h,ox:0,oy:0,region:f})}return o}function o8(t,e){if(!t.copies)return e+1;let n=t.stack??1;return(t.copies[Math.floor(e/n)]-1)*n+e%n+1}function Ws(t,e,n){let c=[...n.keys()],r=[...e.keys()].filter(i=>n.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),a=[];if(r.length<2)return a;let s=i=>i==="engrave"?-1/0:(n.get(i)?.order??0)*2+c.indexOf(i)/c.length;r.sort((i,o)=>s(i)-s(o));for(let i=0;i<r.length-1;i++){let o=n.get(r[i]).side??"front",l=r.slice(i+1).filter(u=>(n.get(u).side??"front")===o);if(!l.length)continue;let h;for(let u of _0(e.get(r[i]).regions)){let f=u.reduce((M,w)=>M+H1(w),0);if(!(f>.001)||!m0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=b0(d,e.get(M).regions));if(d.reduce((M,w)=>M+H1(w),0)>.001*Math.max(1,f))continue;let m=l.filter(M=>x0(u,e.get(M).regions).length),g=m.length?m:l;if(h){h.count++;for(let M of g)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=D0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:r[i],under:g,count:1,at:[w0((v+b)/2),w0((y+x)/2)]}}h&&a.push(h)}return a}function Xs(t,e){for(let n of t.slice(0,5)){let c=n.under.map(a=>`"${a}"`),r=c.length>1?`${c.slice(0,-1).join(", ")} and ${c.at(-1)}`:c[0];e.push(`Part "${n.part}": ${n.count>1?`${n.count} fills`:"a fill"} on layer "${n.layer}" (${n.count>1?"the first ":""}at [${n.at.join(", ")}]) ${n.count>1?"lie":"lies"} wholly under ${r}, stacked above it in the files: printed, ${n.count>1?"they":"it"} won't show, and engraved, ${n.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${n.layer}" a higher order.`)}if(t.length>5){let n=t.slice(5),c=new Set(n.map(a=>a.part)).size,r=[...new Set(n.map(a=>`"${a.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${c} part${c>1?"s":""} (layer${r.length>1?"s":""} ${r.slice(0,5).join(", ")}${r.length>5?" and more":""}).`)}}function Zs(t,e){let n=new Set,c=(r,a)=>{if(!r.glue||n.has(r))return;if(a.includes(r)){e.push(`Part "${r.name}" is glued in a loop of parts; it is left where it is.`),n.add(r);return}let s=t.find(h=>h.name===r.glue.host&&h!==r);if(!s?.placements){e.push(`Part "${r.name}" is glued to "${r.glue.host}", which is not a placed part.`),n.add(r);return}c(s,[...a,r]);let i=s.placements.map(K0),o=r.glue.face==="top"?s.thickness:-r.thickness,l=r.placements.length/(r.stack??1);r.placements=r.placements.map((h,u)=>{let f=i.length===l?i[Math.floor(u/(r.stack??1))]:i[0];return{...h,matrix:O1(f,O1(R0(0,0,o),K0(h)))}}),n.add(r)};for(let r of t)c(r,[])}function Ys(t,e,n,c){let r=0,a=50;for(let m=0;m<14;m++){let g=(r+a)/2;m0(t,-g,"round").length?r=g:a=g}if(r<1)return[];let s=m0(t,-r*.98,"round"),i=D0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((m,g)=>s.reduce((v,y)=>v+(l8(y,m,g)?H1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((m,g)=>H1(g)>H1(m)?g:m)[0]);let u=Math.min(6,Math.max(2,r*.9)),f=M4(n,e,{size:u,font:c,halign:"center",valign:"center",spacing:1}),d=D0(new Map([["t",{regions:f,lines:[]}]])),p=d?Math.min(1,1.6*r/Math.max(d[2]-d[0],1e-9)):1;return f.map(m=>m.map(([g,v])=>[o-g*p,l+v*p]).reverse())}function l8(t,e,n){let c=!1;for(let r=0,a=t.length-1;r<t.length;a=r++){let[s,i]=t[r],[o,l]=t[a];i>n!=l>n&&e<(o-s)*(n-i)/(l-i)+s&&(c=!c)}return c}function u8(t){switch(t.kind){case"num":return t.unit?{ok:!1}:{ok:!0,value:t.value};case"str":case"bool":return{ok:!0,value:t.value};case"unary":return t.op==="-"&&t.arg.kind==="num"?{ok:!0,value:-t.arg.value}:{ok:!1};case"list":{let e=[];for(let n of t.items){if(n.kind!=="item")return{ok:!1};let c=u8(n.expr);if(!c.ok||typeof c.value!="number")return{ok:!1};e.push(c.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function h8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function Js(t){let{program:e,comments:n}=a2(t),c=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),r=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),a=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),s=[];for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let o=u8(i.value);if(!o.ok)continue;let l=c.filter(m=>m.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(l.toLowerCase()==="hidden")continue;let h=r.get(i.pos.line),u=a.get(i.pos.line-1)??"",f=o.value,d={name:i.name,caption:u,group:l,type:typeof f=="number"||Array.isArray(f)?"number":typeof f=="boolean"?"boolean":"string",initial:f,span:i.span},p=h?/^\[(.*)\]$/.exec(h.trim()):null;if(p){let m=p[1];if(m.includes(",")||/[a-zA-Z"]/.test(m)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(m))d.options=m.split(",").map(g=>{let[v,y]=g.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=h8(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let g=m.split(":").map(h8);g.every(v=>v!==void 0)&&(g.length===1?d.max=g[0]:g.length===2?(d.min=g[0],d.max=g[1]):(d.min=g[0],d.step=g[1],d.max=g[2]))}}s.push(d)}return{parameters:s}}var Ks=8,Qs=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,ei=(t,e)=>Math.max(1,Qs.exec(t.slice(e-1))?.[0].length??1);function ti(t,e,n={}){if(!(t instanceof i1))return`error: ${t instanceof Error?t.message:String(t)}`;let c=n.file??"design.kerf",r=(o,l,h)=>`${o?`<${o}>`:c}:${l}:${h}`,a=o=>o===void 0?e:(Object.prototype.hasOwnProperty.call(y5,o)?y5[o]:void 0)??n.resolve?.(o),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${r(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
2567
+ `)?.[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=ei(l,t.col),p=f.replace(/[^\t]/g," ");s.push(`${u} |`,`${h} | ${l}`,`${u} | ${p}${"^".repeat(d)}`)}}for(let o of ni(t,r))s.push(` = ${o}`);let i=t.call?v5(t.call):void 0;return i&&s.push(` = ${xe(i)}: ${i.doc}`),s.join(`
2568
+ `)}function ni(t,e){let n=a=>`in ${a.kind==="module"?"module ":""}${a.name}(), called at ${e(a.file,a.line,a.col)}${a.count>1?` (${a.count} times)`:""}`,c=t.trace.slice(0,Ks).map(n),r=t.trace.length-c.length+t.traceMore;return r&&c.push(`and ${r} more call${r===1?"":"s"}`),c}var f8=new Set(["module","function","if","else","for","let","each","use","include"]),ci=new Set(["true","false","undef"]),ri=new Set(["for","if","let","function"]),r6={"(":")","[":"]","{":"}"},ai=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function si(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let c=n+1;for(;t[c]!=='"';)c+=t[c]==="\\"?2:1;return t.slice(n,c+1)}function a6(t){let{tokens:e}=p5(t),n=[],c=0,r=0,a=s=>{for(;c<s;)if(t[c]===`
2232
2569
  `)r++,c++;else if(t.startsWith("//",c)){let i=t.indexOf(`
2233
2570
  `,c),o=i<0?t.length:i;n.push({kind:"line",text:t.slice(c,o).trimEnd(),breaks:r}),[r,c]=[0,o]}else if(t.startsWith("/*",c)){let i=t.indexOf("*/",c+2)+2,o=t.slice(c,i).replace(/[ \t\r]+\n/g,`
2234
- `);n.push({kind:"block",text:o,breaks:r}),[r,c]=[0,i]}else c++};for(let s of e){if(a(s.pos.offset),s.type==="eof")break;let i=ri(t,s);n.push({kind:"token",text:i,token:s,breaks:r}),r=0,c=s.pos.offset+i.length}return n}function re(t,e={}){r2(t);let n=" ".repeat(e.indent??2),c=ce(t),r=[],a=null,s=-1,i=0,o=[],l=0,h=!0,u=0,f=!1,d=0,m=0,p,g,v=()=>o[o.length-1],y=()=>!v()||v().open==="{"&&!v().record,b=z=>z.kind==="token"&&!!v()&&z.text===ne[v().open],x=(z,C)=>{a!==null&&r.push(a.trimEnd()),C&&r.length&&r[r.length-1]!==""&&r.push(""),s++,i=z,a=n.repeat(z),g=void 0},M=z=>{if(b(z))return v().outer;if(!y())return!p||p.text===","||ne[p.text]?v().inner:p.role==="header"?m+1:v().inner+1;let C=v()?v().inner:0;return h?C:f?u+1:d+1},S=z=>c.slice(z).find(C=>C.kind==="token");for(let z=0;z<c.length;z++){let C=c[z],k=s<0||C.breaks>0;if(C.kind!=="token"){if(k){let R=S(z),U=R?b(R)?v().inner:M(R):0;x(U,C.breaks>1&&s>=0)}else a+=" ";a+=C.text,g=C;continue}let T=C.text,q=C.token.type;if("*!#%".includes(T)&&y()&&!f&&(h||p?.text===")"||p?.text==="else")?C.role="modifier":(T==="!"||(T==="-"||T==="+")&&(!p||ai(p)))&&(C.role="unary"),T===":"){let R=v();(R?R.ternaries:l)?R?R.ternaries--:l--:R?.open==="["&&(C.role="range")}if((T==="}"&&v()?.record||T==="{"&&p&&["=","(",",","[","?",":"].includes(p.text))&&(C.role="record"),k){let R=M(C);x(R,C.breaks>1&&s>=0),y()&&!b(C)&&(d=R)}else g&&si(g,C)&&(a+=" ");if(y()&&h&&!b(C)&&(u=i,f=q==="id"&&c[z+1]?.kind==="token"&&c[z+1].text==="="||T==="function",h=!1),a+=T,ne[T]){let R=v(),U=C.role==="record",j=R&&R.line===s&&(R.open!=="{"||R.record)&&(T!=="{"||U);o.push({record:U,open:T,outer:i,inner:j?R.inner:i+1,line:s,ternaries:0,header:T==="("&&!!p&&ni.has(p.text)&&p.token?.type==="id"}),T==="{"&&!U&&(h=!0)}else if(b(C)){let R=o.pop();R.header&&(C.role="header",m=R.outer),T==="}"&&!R.record&&(h=!0)}else T===";"&&y()||q==="str"&&T.startsWith("<")&&y()?h=!0:T==="?"&&(v()?v().ternaries++:l++);p=C,g=C}for(a!==null&&r.push(a.trimEnd());r.length&&r[r.length-1]==="";)r.pop();let w=r.length?r.join(`
2571
+ `);n.push({kind:"block",text:o,breaks:r}),[r,c]=[0,i]}else c++};for(let s of e){if(a(s.pos.offset),s.type==="eof")break;let i=si(t,s);n.push({kind:"token",text:i,token:s,breaks:r}),r=0,c=s.pos.offset+i.length}return n}function s6(t,e={}){a2(t);let n=" ".repeat(e.indent??2),c=a6(t),r=[],a=null,s=-1,i=0,o=[],l=0,h=!0,u=0,f=!1,d=0,p=0,m,g,v=()=>o[o.length-1],y=()=>!v()||v().open==="{"&&!v().record,b=z=>z.kind==="token"&&!!v()&&z.text===r6[v().open],x=(z,S)=>{a!==null&&r.push(a.trimEnd()),S&&r.length&&r[r.length-1]!==""&&r.push(""),s++,i=z,a=n.repeat(z),g=void 0},M=z=>{if(b(z))return v().outer;if(!y())return!m||m.text===","||r6[m.text]?v().inner:m.role==="header"?p+1:v().inner+1;let S=v()?v().inner:0;return h?S:f?u+1:d+1},w=z=>c.slice(z).find(S=>S.kind==="token");for(let z=0;z<c.length;z++){let S=c[z],L=s<0||S.breaks>0;if(S.kind!=="token"){if(L){let R=w(z),N=R?b(R)?v().inner:M(R):0;x(N,S.breaks>1&&s>=0)}else a+=" ";a+=S.text,g=S;continue}let I=S.text,q=S.token.type;if("*!#%".includes(I)&&y()&&!f&&(h||m?.text===")"||m?.text==="else")?S.role="modifier":(I==="!"||(I==="-"||I==="+")&&(!m||ii(m)))&&(S.role="unary"),I===":"){let R=v();(R?R.ternaries:l)?R?R.ternaries--:l--:R?.open==="["&&(S.role="range")}if((I==="}"&&v()?.record||I==="{"&&m&&["=","(",",","[","?",":"].includes(m.text))&&(S.role="record"),L){let R=M(S);x(R,S.breaks>1&&s>=0),y()&&!b(S)&&(d=R)}else g&&oi(g,S)&&(a+=" ");if(y()&&h&&!b(S)&&(u=i,f=q==="id"&&c[z+1]?.kind==="token"&&c[z+1].text==="="||I==="function",h=!1),a+=I,r6[I]){let R=v(),N=S.role==="record",G=R&&R.line===s&&(R.open!=="{"||R.record)&&(I!=="{"||N);o.push({record:N,open:I,outer:i,inner:G?R.inner:i+1,line:s,ternaries:0,header:I==="("&&!!m&&ri.has(m.text)&&m.token?.type==="id"}),I==="{"&&!N&&(h=!0)}else if(b(S)){let R=o.pop();R.header&&(S.role="header",p=R.outer),I==="}"&&!R.record&&(h=!0)}else I===";"&&y()||q==="str"&&I.startsWith("<")&&y()?h=!0:I==="?"&&(v()?v().ternaries++:l++);m=S,g=S}for(a!==null&&r.push(a.trimEnd());r.length&&r[r.length-1]==="";)r.pop();let k=r.length?r.join(`
2235
2572
  `)+`
2236
- `:"";return ii(t,w),w}var ai=t=>ci.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&ht.has(t.text)||t.role==="unary"||t.role==="modifier";function si(t,e){if(t.kind!=="token"||e.kind!=="token")return!0;let n=t.text,c=e.text;if(c===","||c===";"||c===")"||c==="]"||n==="("||n==="["||n==="{"&&c==="}"||n==="{"&&t.role==="record"||c==="}"&&e.role==="record"||n==="."||c==="."||t.role==="unary"||t.role==="modifier"||t.role==="range"||e.role==="range")return!1;let r=t.token,a=r.type==="num"||r.type==="str"&&!n.startsWith("<")||r.type==="id"&&(!ht.has(n)||ti.has(n))||n===")"&&t.role!=="header"||n==="]";return c==="("?n==="for"||n==="if"||n==="let"||!a&&n!=="function":c==="["?!a:!0}function ii(t,e){let n=ce(t),c=ce(e);if(!(n.length===c.length&&n.every((a,s)=>a.kind===c[s].kind&&a.text===c[s].text)))throw new i1("The formatter would change the program, so it was left as it is")}function ut(t){let e=new Map;for(let n of t.sheets)for(let c of n.items){let[r,a]=c.offset??[0,0],s=o=>o.map(([l,h])=>[l-r,a-h]),i=new Map;for(let[o,l]of c.layers)i.set(o,{regions:l.regions.map(s),lines:l.lines.map(s)});e.set(`${c.part}\0${c.copy}`,i)}return e}var ft=t=>Math.round(t*100)/100,z4=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function oi(t,e,n=.01){let c=ut(t),r=ut(e),a=[],s=i=>{let[o,l]=i.split("\0");return{part:o,copy:Number(l)}};for(let i of new Set([...c.keys(),...r.keys()])){let o=c.get(i),l=r.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=M3(u.regions,f.regions),m=d.reduce((x,M)=>x+Math.abs(H1(M)),0),p=new Set(u.lines.map(z4)),g=new Set(f.lines.map(z4)),v=u.lines.filter(x=>!g.has(z4(x))),y=f.lines.filter(x=>!p.has(z4(x)));if(m<=n&&!v.length&&!y.length)continue;let b=$0(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:ft(m)},...v.length&&{linesRemoved:v.length},...y.length&&{linesAdded:y.length},...b&&{at:b.map(ft)}})}}return a}var li=[Math.SQRT1_2,Math.SQRT1_2,0],hi=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],ae=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],ui=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),U3=(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]],fi=(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]],di=(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]],I2=t=>t.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]);function mt(t,e){let n=parseInt(t.slice(1),16),c=r=>Math.max(0,Math.min(255,Math.round(r*e))).toString(16).padStart(2,"0");return`#${c(n>>16)}${c(n>>8&255)}${c(n&255)}`}function mi(t,e,n){let c=(i,o,l)=>di(t.matrix,t.bends?.length?h6(t.bends,t.thickness,[i,o,l]):[i,o,l]),r=[],a=(i,o)=>{if(i.length<3)return;let l=fi(dt(i[1],i[0]),dt(i[2],i[0])),h=[0,0,0];for(let m=0;m<i.length;m++){let p=i[m],g=i[(m+1)%i.length];h[0]+=(p[1]-g[1])*(p[2]+g[2]),h[1]+=(p[2]-g[2])*(p[0]+g[0]),h[2]+=(p[0]-g[0])*(p[1]+g[1])}let u=Math.hypot(...h)||Math.hypot(...l);if(!u)return;let f=[h[0]/u,h[1]/u,h[2]/u];if(U3(f,ae)<=0)return;let d=i.reduce((m,p)=>[m[0]+p[0],m[1]+p[1],m[2]+p[2]],[0,0,0]);r.push({pts:i,holes:o,color:mt(e,.55+.45*Math.max(0,U3(f,ui))),depth:U3([d[0]/i.length,d[1]/i.length,d[2]/i.length],ae),stroke:n})},s=t.thickness;for(let i of u6(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])=>c(u,f,s)),h.map(u=>u.map(([f,d])=>c(f,d,s)))),a([...l].reverse().map(([u,f])=>c(u,f,0)),h.map(u=>[...u].reverse().map(([f,d])=>c(f,d,0))));for(let u of i)for(let f=0;f<u.length;f++){let[d,m]=u[f],[p,g]=u[(f+1)%u.length];a([c(d,m,0),c(p,g,0),c(p,g,s),c(d,m,s)])}}return r}function pi(t,e){let n=typeof t.size=="number"?t.size:Math.max(...t.size),c=[(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:U3(c,ae)+n/2,stroke:String(n)}]}function gi(t,e=640,n=420){let c=p=>[U3(p,li),-U3(p,hi)],r=1/0,a=1/0,s=-1/0,i=-1/0;for(let p of t)for(let g of p.pts){let[v,y]=c(g);r=Math.min(r,v),s=Math.max(s,v),a=Math.min(a,y),i=Math.max(i,y)}if(!Number.isFinite(r))return"";let o=Math.max(s-r,i-a)*.04+1,l=Math.min(e/(s-r+2*o),n/(i-a+2*o)),h=p=>{let[g,v]=c(p);return`${((g-r+o)*l).toFixed(1)} ${((v-a+o)*l).toFixed(1)}`},u=p=>`M${p.map(h).join("L")}Z`,f=[...t].sort((p,g)=>p.depth-g.depth).map(p=>p.pts.length===2?`<path d="M${h(p.pts[0])}L${h(p.pts[1])}" stroke="${p.color}" stroke-width="${(Number(p.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(p.pts)}${(p.holes??[]).map(u).join("")}" fill="${p.color}" fill-rule="evenodd" stroke="${p.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((s-r+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 vi="#d9bf91",yi="#cfc6b8",bi="#e08a3c";function xi(t,e){let n=new Map;t.parts.forEach((f,d)=>n.set(f.name,f.label??d+1));let c=t.assembly.filter(f=>f.placed),r=t.steps.length?t.steps:["Put the parts together"],a=f=>t.steps.length?f??0:1,s=f=>d5[f]??I3[f]?.color??"#9a9a9a",i=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",o=[],l=c.filter(f=>a(f.step)===0);r.forEach((f,d)=>{let m=d+1,p=[];for(let y of c){let b=a(y.step);b>m||p.push(...mi(y,b===m?bi:y.step===void 0&&!t.steps.length?vi:yi,b===m?"#7a3e0c":"#8a8274"))}for(let y of t.hardware){let b=t.steps.length?y.step:1;b<=m&&p.push(...pi(y,b===m?s(y.kind):mt(s(y.kind),.8)))}let g=new Map;for(let y of c)a(y.step)===m&&g.set(y.name,(g.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?`${I2(y.label)}: `:""}${I2(y.kind)}, ${b}, ${x} mm long`;v.set(M,(v.get(M)??0)+1)}o.push(`<section>
2237
- <h2><span>${m}</span> ${I2(f)}</h2>
2238
- <div class="view">${gi(p)}</div>
2239
- ${g.size?`<h3>Parts</h3>${i([...g].sort((y,b)=>(n.get(y[0])??0)-(n.get(b[0])??0)).map(([y,b])=>`<b>${n.get(y)??""}</b> ${I2(y)}${b>1?` &times; ${b}`:""}`))}`:""}
2573
+ `:"";return li(t,k),k}var ii=t=>ai.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&f8.has(t.text)||t.role==="unary"||t.role==="modifier";function oi(t,e){if(t.kind!=="token"||e.kind!=="token")return!0;let n=t.text,c=e.text;if(c===","||c===";"||c===")"||c==="]"||n==="("||n==="["||n==="{"&&c==="}"||n==="{"&&t.role==="record"||c==="}"&&e.role==="record"||n==="."||c==="."||t.role==="unary"||t.role==="modifier"||t.role==="range"||e.role==="range")return!1;let r=t.token,a=r.type==="num"||r.type==="str"&&!n.startsWith("<")||r.type==="id"&&(!f8.has(n)||ci.has(n))||n===")"&&t.role!=="header"||n==="]";return c==="("?n==="for"||n==="if"||n==="let"||!a&&n!=="function":c==="["?!a:!0}function li(t,e){let n=a6(t),c=a6(e);if(!(n.length===c.length&&n.every((a,s)=>a.kind===c[s].kind&&a.text===c[s].text)))throw new i1("The formatter would change the program, so it was left as it is")}function d8(t){let e=new Map;for(let n of t.sheets)for(let c of n.items){let[r,a]=c.offset??[0,0],s=o=>o.map(([l,h])=>[l-r,a-h]),i=new Map;for(let[o,l]of c.layers)i.set(o,{regions:l.regions.map(s),lines:l.lines.map(s)});e.set(`${c.part}\0${c.copy}`,i)}return e}var p8=t=>Math.round(t*100)/100,S4=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function hi(t,e,n=.01){let c=d8(t),r=d8(e),a=[],s=i=>{let[o,l]=i.split("\0");return{part:o,copy:Number(l)}};for(let i of new Set([...c.keys(),...r.keys()])){let o=c.get(i),l=r.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=M3(u.regions,f.regions),p=d.reduce((x,M)=>x+Math.abs(H1(M)),0),m=new Set(u.lines.map(S4)),g=new Set(f.lines.map(S4)),v=u.lines.filter(x=>!g.has(S4(x))),y=f.lines.filter(x=>!m.has(S4(x)));if(p<=n&&!v.length&&!y.length)continue;let b=D0(new Map([[h,{regions:p>n?d:[],lines:[...v,...y]}]]));a.push({...s(i),layer:h,change:o.has(h)?l.has(h)?"changed":"removed":"added",...p>n&&{area:p8(p)},...v.length&&{linesRemoved:v.length},...y.length&&{linesAdded:y.length},...b&&{at:b.map(p8)}})}}return a}var ui=[Math.SQRT1_2,Math.SQRT1_2,0],fi=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],i6=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],di=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),U3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],m8=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],pi=(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]],mi=(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]],V2=t=>t.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]);function g8(t,e){let n=parseInt(t.slice(1),16),c=r=>Math.max(0,Math.min(255,Math.round(r*e))).toString(16).padStart(2,"0");return`#${c(n>>16)}${c(n>>8&255)}${c(n&255)}`}function gi(t,e,n){let c=(i,o,l)=>mi(t.matrix,t.bends?.length?ue(t.bends,t.thickness,[i,o,l]):[i,o,l]),r=[],a=(i,o)=>{if(i.length<3)return;let l=pi(m8(i[1],i[0]),m8(i[2],i[0])),h=[0,0,0];for(let p=0;p<i.length;p++){let m=i[p],g=i[(p+1)%i.length];h[0]+=(m[1]-g[1])*(m[2]+g[2]),h[1]+=(m[2]-g[2])*(m[0]+g[0]),h[2]+=(m[0]-g[0])*(m[1]+g[1])}let u=Math.hypot(...h)||Math.hypot(...l);if(!u)return;let f=[h[0]/u,h[1]/u,h[2]/u];if(U3(f,i6)<=0)return;let d=i.reduce((p,m)=>[p[0]+m[0],p[1]+m[1],p[2]+m[2]],[0,0,0]);r.push({pts:i,holes:o,color:g8(e,.55+.45*Math.max(0,U3(f,di))),depth:U3([d[0]/i.length,d[1]/i.length,d[2]/i.length],i6),stroke:n})},s=t.thickness;for(let i of fe(t.outline,t.bends)){let o=u=>u.reduce((f,d,p)=>f+d[0]*u[(p+1)%u.length][1]-u[(p+1)%u.length][0]*d[1],0),l=i.find(u=>o(u)>0)??i[0],h=i.filter(u=>u!==l);a(l.map(([u,f])=>c(u,f,s)),h.map(u=>u.map(([f,d])=>c(f,d,s)))),a([...l].reverse().map(([u,f])=>c(u,f,0)),h.map(u=>[...u].reverse().map(([f,d])=>c(f,d,0))));for(let u of i)for(let f=0;f<u.length;f++){let[d,p]=u[f],[m,g]=u[(f+1)%u.length];a([c(d,p,0),c(m,g,0),c(m,g,s),c(d,p,s)])}}return r}function vi(t,e){let n=typeof t.size=="number"?t.size:Math.max(...t.size),c=[(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:U3(c,i6)+n/2,stroke:String(n)}]}function yi(t,e=640,n=420){let c=m=>[U3(m,ui),-U3(m,fi)],r=1/0,a=1/0,s=-1/0,i=-1/0;for(let m of t)for(let g of m.pts){let[v,y]=c(g);r=Math.min(r,v),s=Math.max(s,v),a=Math.min(a,y),i=Math.max(i,y)}if(!Number.isFinite(r))return"";let o=Math.max(s-r,i-a)*.04+1,l=Math.min(e/(s-r+2*o),n/(i-a+2*o)),h=m=>{let[g,v]=c(m);return`${((g-r+o)*l).toFixed(1)} ${((v-a+o)*l).toFixed(1)}`},u=m=>`M${m.map(h).join("L")}Z`,f=[...t].sort((m,g)=>m.depth-g.depth).map(m=>m.pts.length===2?`<path d="M${h(m.pts[0])}L${h(m.pts[1])}" stroke="${m.color}" stroke-width="${(Number(m.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(m.pts)}${(m.holes??[]).map(u).join("")}" fill="${m.color}" fill-rule="evenodd" stroke="${m.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((s-r+2*o)*l).toFixed(0),p=((i-a+2*o)*l).toFixed(0);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d} ${p}" width="${d}" height="${p}">${f.join("")}</svg>`}var bi="#d9bf91",xi="#cfc6b8",Mi="#e08a3c";function wi(t,e){let n=new Map;t.parts.forEach((f,d)=>n.set(f.name,f.label??d+1));let c=t.assembly.filter(f=>f.placed),r=t.steps.length?t.steps:["Put the parts together"],a=f=>t.steps.length?f??0:1,s=f=>m5[f]??I3[f]?.color??"#9a9a9a",i=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",o=[],l=c.filter(f=>a(f.step)===0);r.forEach((f,d)=>{let p=d+1,m=[];for(let y of c){let b=a(y.step);b>p||m.push(...gi(y,b===p?Mi:y.step===void 0&&!t.steps.length?bi:xi,b===p?"#7a3e0c":"#8a8274"))}for(let y of t.hardware){let b=t.steps.length?y.step:1;b<=p&&m.push(...vi(y,b===p?s(y.kind):g8(s(y.kind),.8)))}let g=new Map;for(let y of c)a(y.step)===p&&g.set(y.name,(g.get(y.name)??0)+1);let v=new Map;for(let y of t.hardware)if((t.steps.length?y.step:1)===p){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?`${V2(y.label)}: `:""}${V2(y.kind)}, ${b}, ${x} mm long`;v.set(M,(v.get(M)??0)+1)}o.push(`<section>
2574
+ <h2><span>${p}</span> ${V2(f)}</h2>
2575
+ <div class="view">${yi(m)}</div>
2576
+ ${g.size?`<h3>Parts</h3>${i([...g].sort((y,b)=>(n.get(y[0])??0)-(n.get(b[0])??0)).map(([y,b])=>`<b>${n.get(y)??""}</b> ${V2(y)}${b>1?` &times; ${b}`:""}`))}`:""}
2240
2577
  ${v.size?`<h3>Hardware</h3>${i([...v].map(([y,b])=>`${y}${b>1?` &times; ${b}`:""}`))}`:""}
2241
- </section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${I2(f.name)}${f.mirrored?" (mirrored)":""}</td><td>${f.qty}</td><td>${f.width} &times; ${f.height} mm</td><td>${f.thickness} mm ${I2(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} &times; ${f.height} mm, ${f.thickness} mm ${I2(f.material)}</figcaption></figure>`).join("");return`<!doctype html>
2578
+ </section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${V2(f.name)}${f.mirrored?" (mirrored)":""}</td><td>${f.qty}</td><td>${f.width} &times; ${f.height} mm</td><td>${f.thickness} mm ${V2(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} &times; ${f.height} mm, ${f.thickness} mm ${V2(f.material)}</figcaption></figure>`).join("");return`<!doctype html>
2242
2579
  <html lang="en">
2243
2580
  <head>
2244
2581
  <meta charset="utf-8">
2245
2582
  <meta name="viewport" content="width=device-width, initial-scale=1">
2246
- <title>${I2(e)}: assembly</title>
2583
+ <title>${V2(e)}: assembly</title>
2247
2584
  <style>
2248
2585
  body { font: 15px/1.45 system-ui, sans-serif; color: #222; margin: 24px auto; max-width: 760px; padding: 0 16px; }
2249
2586
  h1 { font-size: 26px; margin: 0 0 4px; }
@@ -2260,7 +2597,7 @@ figure { margin: 12px 0; } figcaption { color: #666; font-size: 13px; }
2260
2597
  </style>
2261
2598
  </head>
2262
2599
  <body>
2263
- <h1>${I2(e)}</h1>
2600
+ <h1>${V2(e)}</h1>
2264
2601
  <p class="note">${t.parts.reduce((f,d)=>f+d.qty,0)} parts on ${t.sheets.length} sheet${t.sheets.length===1?"":"s"}, ${r.length} step${r.length===1?"":"s"}.${l.length?" Some parts are in place before the first step.":""} The parts of each step are drawn in orange.</p>
2265
2602
  <h3>Parts</h3>
2266
2603
  <table><tr><th>#</th><th>Part</th><th>Qty</th><th>Size</th><th>Material</th></tr>${h}</table>
@@ -2269,46 +2606,46 @@ ${o.join(`
2269
2606
  `)}
2270
2607
  </body>
2271
2608
  </html>
2272
- `}var Mi={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function pt(t,e={}){return t.replace(/&(#x[0-9a-fA-F]+|#\d+|[A-Za-z_][\w.-]*);/g,(n,c)=>{if(c[0]==="#"){let r=c[1]==="x"?parseInt(c.slice(2),16):parseInt(c.slice(1),10);return Number.isFinite(r)&&r<=1114111?String.fromCodePoint(r):n}return Mi[c]??e[c]??n})}function gt(t){let e=[],n={},c={name:"#document",attrs:{},children:[],text:""},r=[c],a=0,s=o=>{let l=t.slice(0,a).split(`
2273
- `).length;throw new Error(`${o} (line ${l})`)};for(;a<t.length;){let o=t.indexOf("<",a),l=o<0?t.length:o;if(l>a&&(r[r.length-1].text+=pt(t.slice(a,l),n)),o<0)break;if(a=o,t.startsWith("<!--",a)){let h=t.indexOf("-->",a+4);h<0&&s("Unclosed comment"),e.push(t.slice(a+4,h)),a=h+3}else if(t.startsWith("<![CDATA[",a)){let h=t.indexOf("]]>",a+9);h<0&&s("Unclosed CDATA section"),r[r.length-1].text+=t.slice(a+9,h),a=h+3}else if(t.startsWith("<?",a)){let h=t.indexOf("?>",a+2);h<0&&s("Unclosed processing instruction"),a=h+2}else if(t.startsWith("<!",a)){let h=0,u=a+2;for(;u<t.length;u++){let d=t[u];if(d==="[")h++;else if(d==="]")h--;else if(d===">"&&h<=0)break}let f=t.slice(a,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];a=u+1}else if(t[a+1]==="/"){let h=t.indexOf(">",a);h<0&&s("Unclosed end tag");let u=t.slice(a+2,h).trim(),f=r.pop();(!f||f===c||f.name!==u)&&s(`</${u}> does not match <${f?.name??"nothing"}>`),a=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(a,a+256));h||s("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};a+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=a;let d=f.exec(t);if(d||s(`Bad attribute in <${u.name}>`),a=f.lastIndex,d[5]){r[r.length-1].children.push(u),d[5]===">"&&r.push(u);break}u.attrs[d[1]]=pt(d[3]??d[4]??"",n)}}}r.length>1&&s(`<${r[r.length-1].name}> is not closed`);let i=c.children[0];if(!i)throw new Error("The file has no elements");return{root:i,comments:e}}var t2={cut:{name:"cut",mode:"cut",color:"#ff0000"},score:{name:"score",mode:"line",color:"#0000ff"},engrave:{name:"engrave",mode:"fill",color:"#000000"},guide:{name:"guide",mode:"guide",color:"#00a0ff"}},ie={black:"#000000",white:"#ffffff",red:"#ff0000",lime:"#00ff00",green:"#008000",blue:"#0000ff",yellow:"#ffff00",cyan:"#00ffff",aqua:"#00ffff",magenta:"#ff00ff",fuchsia:"#ff00ff",gray:"#808080",grey:"#808080",silver:"#c0c0c0",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",teal:"#008080",orange:"#ffa500"},wi=Object.fromEntries(Object.entries(ie).reverse().map(([t,e])=>[e,t]));function C5(t,e){if(t===void 0)return;if(t=t.trim().toLowerCase(),t==="none"||t==="transparent")return"none";if(t==="currentcolor")return e;if(t.startsWith("url("))return"paint";if(ie[t])return ie[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let c=n[1];if(c.length===3||c.length===4)return"#"+[...c.slice(0,3)].map(r=>r+r).join("");if(c.length===6||c.length===8)return"#"+c.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let c=n[1].split(/[\s,/]+/).filter(Boolean);if(c.length>=3){let r=c.slice(0,3).map(a=>{let s=a.endsWith("%")?parseFloat(a)*255/100:parseFloat(a);return Math.max(0,Math.min(255,Math.round(s||0)))});return c[3]!==void 0&&parseFloat(c[3])===0?"none":"#"+r.map(a=>a.toString(16).padStart(2,"0")).join("")}}return"#000000"}var B3=(t,e)=>T3(t,Math.PI/12,e),P5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function zi(t){let e=r6;if(!t)return e;for(let[,n,c]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let r=P5(c),a=(r[0]??0)*Math.PI/180,s=r6;if(n==="matrix"&&r.length===6)s=r;else if(n==="translate")s=[1,0,0,1,r[0]??0,r[1]??0];else if(n==="scale")s=[r[0]??1,0,0,r[1]??r[0]??1,0,0];else if(n==="rotate"){let i=Math.cos(a),o=Math.sin(a),[l,h]=[r[1]??0,r[2]??0];s=[i,o,-o,i,l-i*l+o*h,h-o*l-i*h]}else n==="skewX"?s=[1,0,Math.tan(a),1,0,0]:n==="skewY"&&(s=[1,Math.tan(a),0,1,0,0]);e=w3(e,s)}return e}function ki(t,e){let n=[],c=[],r=[0,0],a=[0,0],s=(l,h)=>a5(e,[l,h]),i=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,o=l=>{c.length&&n.push({segs:c,closed:l}),c=[]};for(let l of t)if(l.type==="M")o(!1),r=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);i(a,h)||c.push({c:"L",a,b:h}),a=h}else if(l.type==="Q"){let h=s(l.x1,l.y1),u=s(l.x,l.y);c.push({c:"C",a,p1:[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),a=u}else if(l.type==="C"){let h=s(l.x,l.y);c.push({c:"C",a,p1:s(l.x1,l.y1),p2:s(l.x2,l.y2),b:h}),a=h}else c.length&&!i(a,r)&&c.push({c:"L",a,b:r}),o(!0),a=r;return o(!1),n}var Si=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],Li=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function vt(t){let e={};for(let n of t.split(";")){let c=n.indexOf(":");if(c<0)continue;let r=n.slice(0,c).trim().toLowerCase(),a=n.slice(c+1).replace(/!important/i,"").trim();r&&a&&(e[r]=a)}return e}function Ai(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,c]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let r=vt(c);for(let a of n.split(",")){let s=a.trim(),i=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(s);if(!i)continue;let o=[],l;for(let[,h,u]of i[2].matchAll(/([.#])([\w-]+)/g))h==="."?o.push(u):l=u;e.push({tag:i[1]&&i[1]!=="*"?i[1]:void 0,id:l,classes:o,decls:r})}}return e}function Ci(t,e){switch(t){case"mm":return 1;case"cm":return 10;case"in":return 25.4;case"pt":return 25.4/72;case"pc":return 25.4/6;case"q":return .25;default:return 25.4/e}}function se(t,e){if(!t)return;let n=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(t);if(!(!n||n[2]==="%"))return Number(n[1])*Ci(n[2].toLowerCase(),e)}var Pi=/^(path|g|rect|circle|ellipse|line|polyline|polygon|layer|svg|use|text|tspan|group|shape|cls|clip|mask|defs|_?x?\d|Layer_\d|Ebene|Calque|Capa|Livello|Laag|Warstwa)[-_ ]*[\d-]*$/i;function Ei(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Pi.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Ti(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return t2.score;if(/engrav|raster|etch/.test(e))return t2.engrave;if(/\bguide/.test(e))return t2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return t2.cut}function yt(t,e={}){if(t=t.replace(/^\uFEFF/,""),!/^\s*</.test(t)||t.includes("\0"))throw new Error("This is not an SVG file: it does not start with a tag");let n=gt(t),c=n.root;if(c.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let r=[],a=n.comments.some(P=>/Adobe Illustrator/i.test(P)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&r.push("Adobe Illustrator file: px measured at 72 per inch.");let i=P5(c.attrs.viewBox??""),o=se(c.attrs.width,s),l=se(c.attrs.height,s),h=25.4/s,u=h,f=h,d=0,m=0;i.length===4&&i[2]>0&&i[3]>0&&(u=o!==void 0?o/i[2]:l!==void 0?l/i[3]:h,f=l!==void 0?l/i[3]:u,d=i[0],m=i[1]),o===void 0&&l===void 0&&e.dpi===void 0&&!a&&r.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let p=l??(i.length===4?i[3]*f:0),g=w3([1,0,0,-1,0,p],[u,0,0,f,-d*u,-m*f]),v=[],y=new Map,b=P=>{P.name==="style"&&v.push(...Ai(P.text)),P.attrs.id&&y.set(P.attrs.id,P),P.children.forEach(b)};b(c);let x=(P,Y)=>{let X={};for(let a1 of Object.keys(Y))Li.has(a1)&&(X[a1]=Y[a1]);for(let a1 of Si)P.attrs[a1]!==void 0&&(X[a1]=P.attrs[a1]);let b1=(P.attrs.class??"").split(/\s+/).filter(Boolean);for(let a1 of v)(!a1.tag||a1.tag===P.name)&&(!a1.id||a1.id===P.attrs.id)&&a1.classes.every(R1=>b1.includes(R1))&&Object.assign(X,a1.decls);return P.attrs.style&&Object.assign(X,vt(P.attrs.style)),X},M=[],S=[],w=0,z=0,C=0,k=0,T=0,q=0,R=2e4,U=[],j=P=>Number.isFinite(P[0])&&Number.isFinite(P[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],Q=P=>[...V,"x1","y1","x2","y2","points"].some(Y=>P.attrs[Y]!==void 0&&P5(P.attrs[Y]).some(X=>!Number.isFinite(X))),W=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),o1=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),m1=P=>{let Y=X=>parseFloat(P.attrs[X]??"0")||0;switch(P.name){case"path":return B3(P.attrs.d??"",()=>C++);case"rect":{let[X,b1,a1,R1]=[Y("x"),Y("y"),Y("width"),Y("height")];if(a1<=0||R1<=0)return[];let e1=P.attrs.rx!==void 0?Y("rx"):P.attrs.ry!==void 0?Y("ry"):0,T1=P.attrs.ry!==void 0?Y("ry"):e1;return e1=Math.min(Math.abs(e1),a1/2),T1=Math.min(Math.abs(T1),R1/2),e1<=0||T1<=0?B3(`M${X} ${b1}H${X+a1}V${b1+R1}H${X}Z`):B3(`M${X+e1} ${b1}H${X+a1-e1}A${e1} ${T1} 0 0 1 ${X+a1} ${b1+T1}V${b1+R1-T1}A${e1} ${T1} 0 0 1 ${X+a1-e1} ${b1+R1}H${X+e1}A${e1} ${T1} 0 0 1 ${X} ${b1+R1-T1}V${b1+T1}A${e1} ${T1} 0 0 1 ${X+e1} ${b1}Z`)}case"circle":case"ellipse":{let[X,b1]=[Y("cx"),Y("cy")],a1=P.name==="circle"?Y("r"):Y("rx"),R1=P.name==="circle"?Y("r"):P.attrs.ry!==void 0?Y("ry"):a1;return a1<=0||R1<=0?[]:B3(`M${X+a1} ${b1}A${a1} ${R1} 0 0 1 ${X} ${b1+R1}A${a1} ${R1} 0 0 1 ${X-a1} ${b1}A${a1} ${R1} 0 0 1 ${X} ${b1-R1}A${a1} ${R1} 0 0 1 ${X+a1} ${b1}Z`)}case"line":return B3(`M${Y("x1")} ${Y("y1")}L${Y("x2")} ${Y("y2")}`);case"polyline":case"polygon":{let X=P5(P.attrs.points??"");if(X.length<4)return[];let b1=`M${X[0]} ${X[1]}`;for(let a1=2;a1+1<X.length;a1+=2)b1+=`L${X[a1]} ${X[a1+1]}`;return B3(P.name==="polygon"?b1+"Z":b1)}}},I=P=>(P.text+P.children.map(Y=>Y.name==="tspan"?" "+I(Y):"").join("")).replace(/\s+/g," ").trim(),$=(P,Y,X,b1,a1,R1)=>{if(R1>64||W.has(P.name)||T&&++q>R)return;let e1=x(P,X);if(e1.display==="none"||e1.visibility==="hidden"||e1.opacity==="0"){(P.children.length||o1.has(P.name))&&z++;return}let T1=w3(Y,zi(P.attrs.transform));if(!T1.every(Number.isFinite)){k++;return}let r0=Ei(P),A=P.attrs["inkscape:groupmode"]==="layer",G=b1;if(P.name==="g"||P.name==="svg"||P.name==="a"||P.name==="switch"){let B1=P.attrs["inkscape:label"]??P.attrs["data-name"]??P.attrs.id,l1=Ti(B1);if(P.attrs["data-mode"]&&B1&&/^(cut|line|fill|guide)$/.test(P.attrs["data-mode"])){let g1=C5(e1.stroke,"#000000"),d1=C5(e1.fill,"#000000"),v1=P.attrs["data-mode"]==="fill"?d1:g1;G=t2[B1]??{name:B1,mode:P.attrs["data-mode"],color:v1&&v1.startsWith("#")?v1:"#00aa00"}}else l1&&(G=l1);if(P!==c&&P.name==="svg"){let g1=d1=>parseFloat(P.attrs[d1]??"0")||0;T1=w3(T1,[1,0,0,1,g1("x"),g1("y")])}let M1=A||l1||P===c||!r0?a1:[r0,...a1];U.push(P);for(let g1 of P.children)$(g1,T1,e1,G,M1,R1+1);U.pop();return}if(P.name==="use"){let B1=y.get((P.attrs.href??P.attrs["xlink:href"]??"").replace(/^#/,""));if(!B1||U.includes(B1))return;let l1=d1=>parseFloat(P.attrs[d1]??"0")||0,M1=w3(T1,[1,0,0,1,l1("x"),l1("y")]),g1=B1.name==="symbol"?{...B1,name:"g"}:B1;U.push(B1),T++,$(g1,M1,e1,G,r0?[r0,...a1]:a1,R1+1),T--,U.pop();return}if(P.name==="image"){w++;return}let N=C5(e1.color,"#000000")??"#000000",s1=parseFloat(e1["stroke-width"]??"1"),K=C5(e1.stroke,N);K&&(s1===0||e1["stroke-opacity"]==="0")&&(K="none");let S1=C5(e1.fill??"black",N);if(e1["fill-opacity"]==="0"&&(S1="none"),P.name==="text"){let B1=I(P);if(!B1)return;let l1=P.children.find(l0=>l0.name==="tspan"),M1=l0=>P5(P.attrs[l0]??l1?.attrs[l0]??"0")[0]??0,g1=a5(T1,[M1("x"),M1("y")]),d1=Math.sqrt(Math.abs(T1[0]*T1[3]-T1[1]*T1[2])),v1=(se(e1["font-size"],96)??16*h)/h;if(!j(g1)||!Number.isFinite(v1*d1)){k++;return}let N1=e1["text-anchor"];S.push({text:B1,at:g1,size:v1*d1,angle:Math.atan2(-T1[1],T1[0])*180/Math.PI,font:(e1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:N1==="middle"?"center":N1==="end"?"right":"left",stroke:K,fill:S1,layer:G});return}if(P.name!=="path"&&Q(P)){k++;return}let Y1=m1(P);if(!Y1){for(let B1 of P.children)$(B1,T1,e1,G,a1,R1+1);return}let G1=ki(Y1,T1),A1=G1.filter(B1=>B1.segs.every(l1=>j(l1.a)&&j(l1.b)&&(l1.c==="L"||j(l1.p1)&&j(l1.p2))));A1.length<G1.length&&k++,A1.length&&M.push({subs:A1,stroke:K,fill:P.name==="line"||P.name==="polyline"?"none":S1,fillRule:e1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:G,names:r0?[r0,...a1]:a1})};$(c,g,{},void 0,[],0),w&&r.push(`${w} embedded image${w===1?" was":"s were"} left out: trace ${w===1?"it":"them"} to paths first.`),z&&r.push(`${z} hidden element${z===1?" was":"s were"} left out.`),C&&r.push(`${C} path${C===1?" has":"s have"} bad data: read up to the error, as browsers draw ${C===1?"it":"them"}.`),k&&r.push(`${k} element${k===1?" was":"s were"} left out: ${k===1?"its":"their"} numbers are too large to draw.`),q>R&&r.push(`The drawing repeats its elements with <use> more than ${R.toLocaleString("en")} times: only the first ${R.toLocaleString("en")} copies were read.`);let Z=P=>{let[Y,X,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return Y>=200&&X<=80&&b1<=80},_=P=>{let[Y,X,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return b1>=200&&Y<=80&&X<=80},L1=P=>!!P.stroke&&P.stroke!=="none",W1=M.filter(P=>!P.layer),E1=new Map;for(let P of W1)L1(P)&&P.stroke.startsWith("#")&&E1.set(P.stroke,(E1.get(P.stroke)??0)+P.subs.length);let Z1=[...E1.keys()],m0=Z1.filter(Z),o0=new Set(m0.length?m0:Z1.length?[Z1.reduce((P,Y)=>(E1.get(Y)??0)>(E1.get(P)??0)?Y:P)]:[]),L=M.some(P=>L1(P)&&!P.layer)||M.some(P=>P.layer),F=new Map,t1=(P,Y)=>{if(P&&P!=="none"){let X=P.startsWith("#")?P:"#000000";if(o0.has(X))return t2.cut;if(X==="#00a0ff")return t2.guide;if(_(X))return t2.score;if(!F.has(X)){let b1=wi[X]??"color_"+X.slice(1);F.set(X,{name:b1,mode:"line",color:X})}return F.get(X)}if(Y&&Y!=="none")return L?t2.engrave:t2.cut};!L&&M.some(P=>P.fill&&P.fill!=="none")?r.push("The file has filled shapes and no strokes: the shapes are cut out."):!m0.length&&o0.size&&r.push(`No red lines: ${[...o0][0]} lines, the most common colour, are cut.`),F.size&&r.push(`Lines in ${[...F.values()].map(P=>P.color).join(", ")} went on their own layer${F.size===1?"":"s"}, set to mark, not cut.`);let r1=[];for(let P of M){let Y=P.layer??t1(P.stroke,P.fill);if(!Y)continue;let X=!P.layer&&Y===t2.cut&&!L1(P);r1.push({subs:P.subs,layer:Y,fillRule:P.fillRule,names:P.names,filled:X})}let y1=[];for(let P of S){let Y=P.layer??t1(P.fill!=="none"?void 0:P.stroke,P.fill);Y&&y1.push({...P,layer:Y.mode==="cut"&&L?t2.engrave:Y})}return{items:r1,texts:y1,notes:r}}var O1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),h2=([t,e],n)=>{let c=n*Math.PI/180,r=Math.cos(c),a=Math.sin(c);return[t*r-e*a,t*a+e*r]},le=(t,e)=>[t[0]+e[0],t[1]+e[1]],u2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function u3(t,e=.005){let n=[t.segs[0].a];for(let c of t.segs)if(c.c==="L")n.push(c.b);else{let r=O1(c.a,c.p1)+O1(c.p1,c.p2)+O1(c.p2,c.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(r/e))));for(let s=1;s<=a;s++){let i=s/a,o=1-i;n.push([o*o*o*c.a[0]+3*o*o*i*c.p1[0]+3*o*i*i*c.p2[0]+i*i*i*c.b[0],o*o*o*c.a[1]+3*o*o*i*c.p1[1]+3*o*i*i*c.p2[1]+i*i*i*c.b[1]])}}return t.closed&&n.length>1&&O1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function M2(t,e=!0){let n=0;for(let c=1;c<t.length;c++)n+=O1(t[c-1],t[c]);return e&&t.length>2?n+O1(t[t.length-1],t[0]):n}function H2(t,e,n){let c=[],r=e?t.length:t.length-1;for(let a=0;a<r;a++){let s=t[a],i=t[(a+1)%t.length];c.push(s);let o=Math.floor(O1(s,i)/n);for(let l=1;l<o;l++)c.push([s[0]+(i[0]-s[0])*l/o,s[1]+(i[1]-s[1])*l/o])}return!e&&t.length&&c.push(t[t.length-1]),c}function Z2(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?((t[0]-e[0])*c+(t[1]-e[1])*r)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}var h3=class{constructor(e,n,c){this.size=c;this.cells=new Map;for(let r of e){let a=n?r.length:r.length-1;for(let s=0;s<a;s++){let i=r[s],o=r[(s+1)%r.length],l=Math.max(1,Math.ceil(O1(i,o)/(c*2)));for(let h=0;h<l;h++){let u=[i[0]+(o[0]-i[0])*h/l,i[1]+(o[1]-i[1])*h/l],f=[i[0]+(o[0]-i[0])*(h+1)/l,i[1]+(o[1]-i[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/c),m=Math.floor(Math.max(u[0],f[0])/c),p=Math.floor(Math.min(u[1],f[1])/c),g=Math.floor(Math.max(u[1],f[1])/c);for(let v=d;v<=m;v++)for(let y=p;y<=g;y++){let b=`${v},${y}`,x=this.cells.get(b);x?x.push([u,f]):this.cells.set(b,[[u,f]])}}}}}near(e,n){let c=Math.floor((e[0]-n)/this.size),r=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let i=c;i<=r;i++)for(let o=a;o<=s;o++)for(let[l,h]of this.cells.get(`${i},${o}`)??[])if(Z2(e,l,h)<=n)return!0;return!1}meets(e,n,c){let r=Math.max(1,Math.ceil(O1(e,n)/(this.size*2)));for(let a=0;a<r;a++){let s=[e[0]+(n[0]-e[0])*a/r,e[1]+(n[1]-e[1])*a/r],i=[e[0]+(n[0]-e[0])*(a+1)/r,e[1]+(n[1]-e[1])*(a+1)/r],o=Math.floor((Math.min(s[0],i[0])-c)/this.size),l=Math.floor((Math.max(s[0],i[0])+c)/this.size),h=Math.floor((Math.min(s[1],i[1])-c)/this.size),u=Math.floor((Math.max(s[1],i[1])+c)/this.size);for(let f=o;f<=l;f++)for(let d=h;d<=u;d++)for(let[m,p]of this.cells.get(`${f},${d}`)??[])if(xt(s,i,m,p)<=c)return!0}return!1}};function xt(t,e,n,c){let r=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),a=r(n,c,t),s=r(n,c,e),i=r(t,e,n),o=r(t,e,c);return a*s<0&&i*o<0?0:Math.min(Z2(t,n,c),Z2(e,n,c),Z2(n,t,e),Z2(c,t,e))}function Ii(t,e,n=.2){let c=t.length;if(c<4)return!1;let r=[0];for(let h=1;h<=c;h++)r.push(r[h-1]+O1(t[h-1],t[h%c]));let a=r[c],s=k0([t]),i=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(c)),o=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/i),m=Math.floor((Math.max(h[0],u[0])+e)/i),p=Math.floor((Math.min(h[1],u[1])-e)/i),g=Math.floor((Math.max(h[1],u[1])+e)/i);if((m-d+1)*(g-p+1)>4096)return null;for(let v=d;v<=m;v++)for(let y=p;y<=g;y++)f.push(`${v},${y}`);return f};for(let h=0;h<c;h++){let u=t[h],f=t[(h+1)%c],d=l(u,f);if(!d)return!1;for(let m of d)for(let p of o.get(m)??[]){let g=Math.abs(r[h]-r[p]);if(!(Math.min(g,a-g)-O1(u,f)-O1(t[p],t[(p+1)%c])<n)&&xt(u,f,t[p],t[(p+1)%c])<=e)return!0}for(let m of d){let p=o.get(m);p?p.push(h):o.set(m,[h])}}return!1}function Mt(t,e){let n=t.map(()=>!1),c=[],r=t.map(l=>k0([l]));t.forEach((l,h)=>{let u=w1([l]),f=u.reduce((p,g)=>p+H1(g),0),d=M2(l),m=u.reduce((p,g)=>p+M2(g),0);(u.length!==1||Math.abs(f-Math.abs(H1(l)))>d*.001+1e-6||Math.abs(m-d)>d*.001+.05||Ii(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new h3([t[l]],!0,Math.max(e*4,1))),h},i=t.map((l,h)=>h).sort((l,h)=>r[l][0]-r[h][0]),o=[];for(let l of i){let[h,u,f,d]=r[l];for(let m=o.length-1;m>=0;m--)r[o[m]][2]<h-e&&o.splice(m,1);for(let m of o){let p=r[m];if(p[1]>d+e||p[3]<u-e)continue;let[g,v]=t[l].length<=t[m].length?[l,m]:[m,l],y=t[g],b=s(v);for(let x=0;x<y.length;x++)if(b.meets(y[x],y[(x+1)%y.length],e)){c.push([l,m]);break}}o.push(l)}return{self:n,pairs:c}}function f3(t,e,n,c=!0){if(!t.length||!e.length)return t.length===e.length;let r=Math.max(n*2,.2),a=new h3(t,c,Math.max(n*4,1)),s=new h3(e,c,Math.max(n*4,1));for(let i of t)for(let o of H2(i,c,r))if(!s.near(o,n))return!1;for(let i of e)for(let o of H2(i,c,r))if(!a.near(o,n))return!1;return!0}function wt(t,e,n){let c=new h3([t,...e],!0,Math.max(n*4,1)),r=a=>V2(a,t)&&!e.some(s=>V2(a,s));return(a,s)=>{let i=s?a.length:a.length-1;if(i<1)return!1;let o;for(let l=0;l<i;l++){let h=a[l],u=a[(l+1)%a.length];if(!c.meets(h,u,n)){o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==i-1)return!1;let f=O1(h,u),d=Math.min(n*3,f/3)/f,m=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,p=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(c.meets(m,p,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?r(o):!0}}function zt(t,e,n){if(!t.length)return!1;let c=new h3([e],!0,Math.max(n*4,1));return t.some(r=>H2(r,!1,Math.max(n*2,.2)).some(a=>c.near(a,n)))}function V2(t,e){let n=!1;for(let c=0,r=e.length-1;c<e.length;r=c++){let[a,s]=e[c],[i,o]=e[r];s>t[1]!=o>t[1]&&t[0]<(i-a)*(t[1]-s)/(o-s)+a&&(n=!n)}return n}function A4(t){let e=t.length;if(e<3)return null;let n=0,c=0;for(let[g,v]of t)n+=g,c+=v;n/=e,c/=e;let r=0,a=0,s=0,i=0,o=0,l=0,h=0;for(let[g,v]of t){let y=g-n,b=v-c;r+=y*y,a+=y*b,s+=b*b,i+=y*y*y,o+=b*b*b,l+=y*b*b,h+=b*y*y}let u=r*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(i+l)/2,d=(o+h)/2,m=(f*s-d*a)/u,p=(d*r-f*a)/u;return{c:[m+n,p+c],r:Math.sqrt(m*m+p*p+(r+s)/e)}}function G3(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)O1(t[0],t[o])>O1(t[0],t[n])&&(n=o);let c=o=>{if(o.length<3)return o;let l=0,h=0;for(let f=1;f<o.length-1;f++){let d=Z2(o[f],o[0],o[o.length-1]);d>l&&(l=d,h=f)}return l<=e?[o[0],o[o.length-1]]:[...c(o.slice(0,h+1)).slice(0,-1),...c(o.slice(h))]},r=c(t.slice(0,n+1)),a=c([...t.slice(n),t[0]]),s=[...r.slice(0,-1),...a.slice(0,-1)],i=[];for(let o=0;o<s.length;o++){let l=s[(o-1+s.length)%s.length],h=s[(o+1)%s.length];Z2(s[o],l,h)>e&&i.push(s[o])}return i.length>=3?i:s}function kt(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=G3(a,.002),i=s.length,o=s.findIndex((u,f)=>O1(u,s[(f+1)%i])>=.5);if(i<4||o<0)continue;let l=H1(a)>0,h=[];for(let u=1;u<=i;u++){let f=(o+u)%i,d=s[f],m=s[(f+1)%i];if(O1(d,m)<.3){h.length||h.push(d),h.push(m);continue}if(h.length>=3){let p=A4(h),[g,v,y]=[h[0],h[1],h[h.length-1]],b=(v[0]-g[0])*(y[1]-g[1])-(v[1]-g[1])*(y[0]-g[0]);p&&p.r>.005&&p.r<.6&&(b>0===l?e:n).push(p.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let c=e[Math.floor(e.length/2)],r=a=>Math.abs(a-c)<=Math.max(.005,c*.1);if(!(c>.2||n.filter(r).length>e.length*.2))return e.filter(r).length>=e.length*.8?c:void 0}function he(t,e){let n=t.length,c=i=>O1(t[i],t[(i+1)%n])<e*1.5,r=t.findIndex((i,o)=>!c(o));if(r<0)return t;let a=[],s=r;do{let i=(s+1)%n;for(;c(i)&&i!==s;)i=(i+1)%n;let o=(i-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[i],f=t[(i+1)%n],d;if(o>0){let m=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(m)>1e-12){let p=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/m,g=[l[0]+p*(h[0]-l[0]),l[1]+p*(h[1]-l[1])],v=t[(s+1+Math.floor(o/2))%n],y=[];for(let M=1;M<=o+1;M++)y.push(t[(s+M)%n]);let b=y.length>=3?A4(y):{c:g,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&O1(g,v)<=e*2&&p>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let m=1;m<=o;m++)a.push(t[(s+m)%n]);s=i}while(s!==r);return a}function P1(t){for(let c of[0,1,2]){let r=10**c,a=Math.round(t*r)/r;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var k1=t=>String(P1(t)),n0=t=>`[${k1(t[0])}, ${k1(t[1])}]`;function Vi(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function w2(t,e,n){let c=[];(P1(t[0])!==0||P1(t[1])!==0)&&c.push(`translate(${n0(t)})`);let r=Vi(e);return r!==0&&c.push(`rotate(${r})`),[...c,n].join(" ")}function E5(t,e){return{poly:t,area:Math.abs(H1(t)),box:k0([t]),ends:e?.segs.map(n=>n.a)}}var L4=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function C4(t,e){let n=M2(t.poly),c=H2(t.poly,!0,Math.min(.5,n/256)),r=A4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:c);if(!r||r.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,r.r*3e-4));for(let i of t.poly)if(Math.abs(O1(i,r.c)-r.r)>a)return;let s=a+r.r*2e-4;for(let i of c)if(Math.abs(O1(i,r.c)-r.r)>s)return;if(!(Math.abs(t.area-Math.PI*r.r*r.r)>n*a*2))return{kind:"circle",body:`circle(d = ${k1(r.r*2)})`,at:r.c,angle:0,center:r.c,circle:r,radius:r.r}}function St(t){let e=0,n=0;for(let[s,i]of t)e+=s,n+=i;e/=t.length,n/=t.length;let c=0,r=0,a=0;for(let[s,i]of t)c+=(s-e)**2,r+=(i-n)**2,a+=(s-e)*(i-n);return .5*Math.atan2(2*a,c-r)*180/Math.PI}function P4(t,e){let n=M2(t.poly),c=H2(t.poly,!0,Math.min(.5,n/256)),r=St(c),a=c.map(p=>h2(p,-r)),[s,i,o,l]=k0([a]),h=(o-s)/2,u=(l-i)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+o)/2,(i+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[p,g]of a){let v=Math.hypot((p-f[0])/h,(g-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let m=h2(f,r);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${n0([h,u])})`,at:m,angle:r,center:m}}function Lt(t){let e=0,n=0;for(let c=0;c<t.length;c++){let r=t[c],a=t[(c+1)%t.length],s=O1(r,a);s>e&&(e=s,n=Math.atan2(a[1]-r[1],a[0]-r[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function E4(t,e){let n=G3(t.poly,e/4),c=Lt(n),r=M2(t.poly),a=H2(t.poly,!0,Math.min(.5,r/256)).map(y=>h2(y,-c)),[s,i,o,l]=k0([a]),h=o-s,u=l-i;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,i],[o,i],[o,l],[s,l]].map(y=>Math.min(...a.map(b=>O1(b,y)))*f),m=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;m<e&&(m=0),m=Math.min(m,h/2,u/2);let p=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-p[0])-(h/2-m),M=Math.abs(b-p[1])-(u/2-m),S=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-m;if(Math.abs(S)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*m*m))>r*e)return;let g=h2(p,c),v=P1(m)>0?`, r = ${k1(m)}`:"";return{kind:"rect",radius:m,body:`rect(${n0([h,u])}, center = true${v})`,at:g,angle:c,center:g,rect:{w:h,h:u,r:m}}}function T4(t,e){let n=G3(t.poly,e/4),c=n.length;if(c<3||c>48)return;let r=0,a=0;for(let[u,f]of n)r+=u/c,a+=f/c;let s=[r,a],i=n.map(u=>O1(u,s)),o=n.map((u,f)=>O1(u,n[(f+1)%c])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-r)*180/Math.PI);if(l(o)<=e&&l(i)<=e&&c<=24){let u=i.reduce((m,p)=>m+p,0)/c,f=360/c,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${c}, ${k1(u)})`,at:s,angle:d,center:s}}if(c%2===0&&c>=4&&l(o)<=e){let u=i.filter((x,M)=>M%2===0),f=i.filter((x,M)=>M%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,M)=>x+M,0)/u.length,m=f.reduce((x,M)=>x+M,0)/f.length,p=h[0];if(m>d&&([d,m]=[m,d],p=h[1]),d-m<e)return;let g=c/2,v=360/g,y=((p-90)%v+v)%v;v-y<.01&&(y=0);let b=P1(m)===P1(d*.45);return{kind:"star",body:`star(${g}, ${k1(d)}${b?"":`, ${k1(m)}`})`,at:s,angle:y,center:s}}}function Hi(t,e,n){let[c,r,a,s]=e,i=[[],[],[],[]],o=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let m=f[1];Math.abs(m-r)<=n?i[0].push(k4(f[0]-c,d[0]-c)):Math.abs(m-s)<=n?i[2].push(k4(a-f[0],a-d[0])):(o[0].push(m-r),o[2].push(s-m))}else{let m=f[0];Math.abs(m-a)<=n?i[1].push(k4(f[1]-r,d[1]-r)):Math.abs(m-c)<=n?i[3].push(k4(s-f[1],s-d[1])):(o[1].push(a-m),o[3].push(m-c))}}let l=[a-c,s-r,a-c,s-r],h=o.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:i.map(u=>Oi(u,n)),depth:h,length:l}}var k4=(t,e)=>t<e?[t,e]:[e,t];function Oi(t,e){t.sort((c,r)=>c[0]-r[0]);let n=[];for(let[c,r]of t){let a=n[n.length-1];a&&c<=a[1]+e?a[1]=Math.max(a[1],r):n.push([c,r])}return n}var oe=t=>t.reduce((e,[n,c])=>e+c-n,0);function Ri(t,e,n,c,r,a){let s=[L4(0,0,t,e)],i=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],o=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=o[h];for(let f=0;f<c[h];f++){let d=u*(f+.5)/c[h];s.push(L4(d-r[h]/2,-a,d+r[h]/2,0).map(i[h]))}}),w1(s)}function ue(t,e,n){let c=G3(t.poly,e/4);if(c.length<8)return;let r=Lt(c),a=c.map(I=>h2(I,-r)),s=e/2;for(let I=0;I<a.length;I++){let $=a[I],Z=a[(I+1)%a.length];if(Math.abs($[0]-Z[0])>s&&Math.abs($[1]-Z[1])>s)return}let i=k0([a]),o=Hi(a,i,s),l=(I,$)=>I.map(Z=>Z.map(_=>le(_,$))),h=(I,$)=>f3([a],l(I,$),e),u=(I,$,Z)=>{let _=h2(I,r);return{kind:"tabs",body:$,at:_,angle:r,center:h2([(i[0]+i[2])/2,(i[1]+i[3])/2],r),...Z}},f=M2(t.poly),d=[0,1,2,3].filter(I=>oe(o.outer[I])<o.length[I]-s);if(!d.length)return;let m=d.map(I=>o.depth[I]).filter(I=>I!==void 0);if(!m.length)return;let p=[...new Set([n,...m].filter(I=>!!I).map(P1))];for(let I of p){let $=P1(i[2]-i[0]),Z=P1(i[3]-i[1]),_=[[]];for(let N=0;N<4;N++){let K=oe(o.outer[N])>=o.length[N]-2*I-s?["flat"]:["out","in"],S1=[];for(let Y1 of _)for(let G1 of K)S1.push([...Y1,G1]);_.splice(0,_.length,...S1)}let L1=Math.max(3*I,6),W1=new Set([L1]);for(let N of d){let s1=o.outer[N].length;for(let K of[2*s1-1,2*s1+1,2*s1-3,2*s1+3])K>=3&&W1.add(P1(o.length[N]/K))}for(let N of W1)for(let s1 of _){if(s1.every(A1=>A1==="flat"))continue;let K=t4($,Z,s1,I,N);if(Math.abs(Math.abs(K.reduce((A1,B1)=>A1+H1(B1),0))-t.area)>f*e||!h(K,[i[0],i[1]]))continue;let Y1=s1.every(A1=>A1===s1[0])?`"${s1[0]}"`:`[${s1.map(A1=>`"${A1}"`).join(", ")}]`,G1=N===L1||[0,1].every(A1=>c3(o.length[A1],N)===c3(o.length[A1],L1));return u([i[0],i[1]],`finger_rect(${n0([$,Z])}, ${Y1}${G1?"":`, finger = ${k1(N)}`})`,{kind:"fingers",thickness:I,edges:s1,finger:G1?L1:N})}let E1=[0,1,2,3].map(N=>d.includes(N)&&o.depth[N]!==void 0&&Math.abs(o.depth[N]-I)<=s);if(!E1.some(Boolean))continue;let Z1=i[0]+(E1[3]?I:0),m0=i[1]+(E1[0]?I:0),o0=P1(i[2]-(E1[1]?I:0)-Z1),L=P1(i[3]-(E1[2]?I:0)-m0),F=[o0,L,o0,L],t1=[E1[3]?I:0,E1[0]?I:0,E1[1]?I:0,E1[2]?I:0],r1=[0,0,0,0],y1=[0,0,0,0],P=!0;for(let N=0;N<4&&P;N++){if(!E1[N])continue;let s1=o.outer[N].map(([K,S1])=>[K-t1[N],S1-t1[N]]);r1[N]=s1.length,y1[N]=s1.length?P1(s1.reduce((K,[S1,Y1])=>K+Y1-S1,0)/s1.length):0,s1.forEach(([K,S1],Y1)=>{(Math.abs((K+S1)/2-F[N]*(Y1+.5)/r1[N])>s||Math.abs(S1-K-y1[N])>s)&&(P=!1)})}if(!P||!h(Ri(o0,L,E1,r1,y1,I),[Z1,m0]))continue;let Y=E1.every(Boolean)?"":`[${E1.join(", ")}]`,X=[0,1,2,3].filter(N=>E1[N]),b1=N=>Math.max(1,Math.round(F[N]/50)),a1=X.every(N=>r1[N]===b1(N)),R1=X.every(N=>r1[N]===r1[X[0]]),e1=a1?void 0:R1?r1[X[0]]:null,T1=X.every(N=>Math.abs(y1[N]-F[N]/(2*r1[N]))<=s),r0=X.every(N=>Math.abs(y1[N]-y1[X[0]])<=s),A=T1?void 0:r0?y1[X[0]]:null,G;if(e1!==null&&A!==null){let N=[n0([o0,L])];Y?N.push(Y):(e1!==void 0||A!==void 0)&&N.push("true"),e1!==void 0&&N.push(`count = ${e1}`),A!==void 0&&N.push(`width = ${k1(A)}`),G=`tab_rect(${N.join(", ")})`}else{let N=[K=>K,K=>`translate(${n0([o0,0])}) rotate(90) ${K}`,K=>`translate(${n0([o0,L])}) rotate(180) ${K}`,K=>`translate(${n0([0,L])}) rotate(270) ${K}`],s1=[`rect(${n0([o0,L])});`];for(let K of X){let S1=[k1(F[K])];r1[K]!==b1(K)&&S1.push(`count = ${r1[K]}`),Math.abs(y1[K]-F[K]/(2*r1[K]))>s&&S1.push(`width = ${k1(y1[K])}`),s1.push(N[K](`tabs(${S1.join(", ")});`))}G=`{
2274
- ${s1.map(K=>" "+K).join(`
2609
+ `}var zi={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function v8(t,e={}){return t.replace(/&(#x[0-9a-fA-F]+|#\d+|[A-Za-z_][\w.-]*);/g,(n,c)=>{if(c[0]==="#"){let r=c[1]==="x"?parseInt(c.slice(2),16):parseInt(c.slice(1),10);return Number.isFinite(r)&&r<=1114111?String.fromCodePoint(r):n}return zi[c]??e[c]??n})}function y8(t){let e=[],n={},c={name:"#document",attrs:{},children:[],text:""},r=[c],a=0,s=o=>{let l=t.slice(0,a).split(`
2610
+ `).length;throw new Error(`${o} (line ${l})`)};for(;a<t.length;){let o=t.indexOf("<",a),l=o<0?t.length:o;if(l>a&&(r[r.length-1].text+=v8(t.slice(a,l),n)),o<0)break;if(a=o,t.startsWith("<!--",a)){let h=t.indexOf("-->",a+4);h<0&&s("Unclosed comment"),e.push(t.slice(a+4,h)),a=h+3}else if(t.startsWith("<![CDATA[",a)){let h=t.indexOf("]]>",a+9);h<0&&s("Unclosed CDATA section"),r[r.length-1].text+=t.slice(a+9,h),a=h+3}else if(t.startsWith("<?",a)){let h=t.indexOf("?>",a+2);h<0&&s("Unclosed processing instruction"),a=h+2}else if(t.startsWith("<!",a)){let h=0,u=a+2;for(;u<t.length;u++){let d=t[u];if(d==="[")h++;else if(d==="]")h--;else if(d===">"&&h<=0)break}let f=t.slice(a,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];a=u+1}else if(t[a+1]==="/"){let h=t.indexOf(">",a);h<0&&s("Unclosed end tag");let u=t.slice(a+2,h).trim(),f=r.pop();(!f||f===c||f.name!==u)&&s(`</${u}> does not match <${f?.name??"nothing"}>`),a=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(a,a+256));h||s("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};a+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=a;let d=f.exec(t);if(d||s(`Bad attribute in <${u.name}>`),a=f.lastIndex,d[5]){r[r.length-1].children.push(u),d[5]===">"&&r.push(u);break}u.attrs[d[1]]=v8(d[3]??d[4]??"",n)}}}r.length>1&&s(`<${r[r.length-1].name}> is not closed`);let i=c.children[0];if(!i)throw new Error("The file has no elements");return{root:i,comments:e}}var t2={cut:{name:"cut",mode:"cut",color:"#ff0000"},score:{name:"score",mode:"line",color:"#0000ff"},engrave:{name:"engrave",mode:"fill",color:"#000000"},guide:{name:"guide",mode:"guide",color:"#00a0ff"}},l6={black:"#000000",white:"#ffffff",red:"#ff0000",lime:"#00ff00",green:"#008000",blue:"#0000ff",yellow:"#ffff00",cyan:"#00ffff",aqua:"#00ffff",magenta:"#ff00ff",fuchsia:"#ff00ff",gray:"#808080",grey:"#808080",silver:"#c0c0c0",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",teal:"#008080",orange:"#ffa500"},ki=Object.fromEntries(Object.entries(l6).reverse().map(([t,e])=>[e,t]));function T5(t,e){if(t===void 0)return;if(t=t.trim().toLowerCase(),t==="none"||t==="transparent")return"none";if(t==="currentcolor")return e;if(t.startsWith("url("))return"paint";if(l6[t])return l6[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let c=n[1];if(c.length===3||c.length===4)return"#"+[...c.slice(0,3)].map(r=>r+r).join("");if(c.length===6||c.length===8)return"#"+c.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let c=n[1].split(/[\s,/]+/).filter(Boolean);if(c.length>=3){let r=c.slice(0,3).map(a=>{let s=a.endsWith("%")?parseFloat(a)*255/100:parseFloat(a);return Math.max(0,Math.min(255,Math.round(s||0)))});return c[3]!==void 0&&parseFloat(c[3])===0?"none":"#"+r.map(a=>a.toString(16).padStart(2,"0")).join("")}}return"#000000"}var B3=(t,e)=>E3(t,Math.PI/12,e),E5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function Si(t){let e=ae;if(!t)return e;for(let[,n,c]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let r=E5(c),a=(r[0]??0)*Math.PI/180,s=ae;if(n==="matrix"&&r.length===6)s=r;else if(n==="translate")s=[1,0,0,1,r[0]??0,r[1]??0];else if(n==="scale")s=[r[0]??1,0,0,r[1]??r[0]??1,0,0];else if(n==="rotate"){let i=Math.cos(a),o=Math.sin(a),[l,h]=[r[1]??0,r[2]??0];s=[i,o,-o,i,l-i*l+o*h,h-o*l-i*h]}else n==="skewX"?s=[1,0,Math.tan(a),1,0,0]:n==="skewY"&&(s=[1,Math.tan(a),0,1,0,0]);e=w3(e,s)}return e}function Li(t,e){let n=[],c=[],r=[0,0],a=[0,0],s=(l,h)=>s5(e,[l,h]),i=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,o=l=>{c.length&&n.push({segs:c,closed:l}),c=[]};for(let l of t)if(l.type==="M")o(!1),r=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);i(a,h)||c.push({c:"L",a,b:h}),a=h}else if(l.type==="Q"){let h=s(l.x1,l.y1),u=s(l.x,l.y);c.push({c:"C",a,p1:[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),a=u}else if(l.type==="C"){let h=s(l.x,l.y);c.push({c:"C",a,p1:s(l.x1,l.y1),p2:s(l.x2,l.y2),b:h}),a=h}else c.length&&!i(a,r)&&c.push({c:"L",a,b:r}),o(!0),a=r;return o(!1),n}var Ai=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],Ci=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function b8(t){let e={};for(let n of t.split(";")){let c=n.indexOf(":");if(c<0)continue;let r=n.slice(0,c).trim().toLowerCase(),a=n.slice(c+1).replace(/!important/i,"").trim();r&&a&&(e[r]=a)}return e}function Pi(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,c]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let r=b8(c);for(let a of n.split(",")){let s=a.trim(),i=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(s);if(!i)continue;let o=[],l;for(let[,h,u]of i[2].matchAll(/([.#])([\w-]+)/g))h==="."?o.push(u):l=u;e.push({tag:i[1]&&i[1]!=="*"?i[1]:void 0,id:l,classes:o,decls:r})}}return e}function Ti(t,e){switch(t){case"mm":return 1;case"cm":return 10;case"in":return 25.4;case"pt":return 25.4/72;case"pc":return 25.4/6;case"q":return .25;default:return 25.4/e}}function o6(t,e){if(!t)return;let n=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(t);if(!(!n||n[2]==="%"))return Number(n[1])*Ti(n[2].toLowerCase(),e)}var Ei=/^(path|g|rect|circle|ellipse|line|polyline|polygon|layer|svg|use|text|tspan|group|shape|cls|clip|mask|defs|_?x?\d|Layer_\d|Ebene|Calque|Capa|Livello|Laag|Warstwa)[-_ ]*[\d-]*$/i;function Ii(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Ei.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Vi(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return t2.score;if(/engrav|raster|etch/.test(e))return t2.engrave;if(/\bguide/.test(e))return t2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return t2.cut}function x8(t,e={}){if(t=t.replace(/^\uFEFF/,""),!/^\s*</.test(t)||t.includes("\0"))throw new Error("This is not an SVG file: it does not start with a tag");let n=y8(t),c=n.root;if(c.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let r=[],a=n.comments.some(P=>/Adobe Illustrator/i.test(P)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&r.push("Adobe Illustrator file: px measured at 72 per inch.");let i=E5(c.attrs.viewBox??""),o=o6(c.attrs.width,s),l=o6(c.attrs.height,s),h=25.4/s,u=h,f=h,d=0,p=0;i.length===4&&i[2]>0&&i[3]>0&&(u=o!==void 0?o/i[2]:l!==void 0?l/i[3]:h,f=l!==void 0?l/i[3]:u,d=i[0],p=i[1]),o===void 0&&l===void 0&&e.dpi===void 0&&!a&&r.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let m=l??(i.length===4?i[3]*f:0),g=w3([1,0,0,-1,0,m],[u,0,0,f,-d*u,-p*f]),v=[],y=new Map,b=P=>{P.name==="style"&&v.push(...Pi(P.text)),P.attrs.id&&y.set(P.attrs.id,P),P.children.forEach(b)};b(c);let x=(P,Y)=>{let W={};for(let a1 of Object.keys(Y))Ci.has(a1)&&(W[a1]=Y[a1]);for(let a1 of Ai)P.attrs[a1]!==void 0&&(W[a1]=P.attrs[a1]);let b1=(P.attrs.class??"").split(/\s+/).filter(Boolean);for(let a1 of v)(!a1.tag||a1.tag===P.name)&&(!a1.id||a1.id===P.attrs.id)&&a1.classes.every($1=>b1.includes($1))&&Object.assign(W,a1.decls);return P.attrs.style&&Object.assign(W,b8(P.attrs.style)),W},M=[],w=[],k=0,z=0,S=0,L=0,I=0,q=0,R=2e4,N=[],G=P=>Number.isFinite(P[0])&&Number.isFinite(P[1]),V=["x","y","width","height","rx","ry","cx","cy","r"],J=P=>[...V,"x1","y1","x2","y2","points"].some(Y=>P.attrs[Y]!==void 0&&E5(P.attrs[Y]).some(W=>!Number.isFinite(W))),o1=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),Z=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),p1=P=>{let Y=W=>parseFloat(P.attrs[W]??"0")||0;switch(P.name){case"path":return B3(P.attrs.d??"",()=>S++);case"rect":{let[W,b1,a1,$1]=[Y("x"),Y("y"),Y("width"),Y("height")];if(a1<=0||$1<=0)return[];let e1=P.attrs.rx!==void 0?Y("rx"):P.attrs.ry!==void 0?Y("ry"):0,I1=P.attrs.ry!==void 0?Y("ry"):e1;return e1=Math.min(Math.abs(e1),a1/2),I1=Math.min(Math.abs(I1),$1/2),e1<=0||I1<=0?B3(`M${W} ${b1}H${W+a1}V${b1+$1}H${W}Z`):B3(`M${W+e1} ${b1}H${W+a1-e1}A${e1} ${I1} 0 0 1 ${W+a1} ${b1+I1}V${b1+$1-I1}A${e1} ${I1} 0 0 1 ${W+a1-e1} ${b1+$1}H${W+e1}A${e1} ${I1} 0 0 1 ${W} ${b1+$1-I1}V${b1+I1}A${e1} ${I1} 0 0 1 ${W+e1} ${b1}Z`)}case"circle":case"ellipse":{let[W,b1]=[Y("cx"),Y("cy")],a1=P.name==="circle"?Y("r"):Y("rx"),$1=P.name==="circle"?Y("r"):P.attrs.ry!==void 0?Y("ry"):a1;return a1<=0||$1<=0?[]:B3(`M${W+a1} ${b1}A${a1} ${$1} 0 0 1 ${W} ${b1+$1}A${a1} ${$1} 0 0 1 ${W-a1} ${b1}A${a1} ${$1} 0 0 1 ${W} ${b1-$1}A${a1} ${$1} 0 0 1 ${W+a1} ${b1}Z`)}case"line":return B3(`M${Y("x1")} ${Y("y1")}L${Y("x2")} ${Y("y2")}`);case"polyline":case"polygon":{let W=E5(P.attrs.points??"");if(W.length<4)return[];let b1=`M${W[0]} ${W[1]}`;for(let a1=2;a1+1<W.length;a1+=2)b1+=`L${W[a1]} ${W[a1+1]}`;return B3(P.name==="polygon"?b1+"Z":b1)}}},E=P=>(P.text+P.children.map(Y=>Y.name==="tspan"?" "+E(Y):"").join("")).replace(/\s+/g," ").trim(),$=(P,Y,W,b1,a1,$1)=>{if($1>64||o1.has(P.name)||I&&++q>R)return;let e1=x(P,W);if(e1.display==="none"||e1.visibility==="hidden"||e1.opacity==="0"){(P.children.length||Z.has(P.name))&&z++;return}let I1=w3(Y,Si(P.attrs.transform));if(!I1.every(Number.isFinite)){L++;return}let r0=Ii(P),C=P.attrs["inkscape:groupmode"]==="layer",_=b1;if(P.name==="g"||P.name==="svg"||P.name==="a"||P.name==="switch"){let _1=P.attrs["inkscape:label"]??P.attrs["data-name"]??P.attrs.id,l1=Vi(_1);if(P.attrs["data-mode"]&&_1&&/^(cut|line|fill|guide)$/.test(P.attrs["data-mode"])){let g1=T5(e1.stroke,"#000000"),d1=T5(e1.fill,"#000000"),v1=P.attrs["data-mode"]==="fill"?d1:g1;_=t2[_1]??{name:_1,mode:P.attrs["data-mode"],color:v1&&v1.startsWith("#")?v1:"#00aa00"}}else l1&&(_=l1);if(P!==c&&P.name==="svg"){let g1=d1=>parseFloat(P.attrs[d1]??"0")||0;I1=w3(I1,[1,0,0,1,g1("x"),g1("y")])}let z1=C||l1||P===c||!r0?a1:[r0,...a1];N.push(P);for(let g1 of P.children)$(g1,I1,e1,_,z1,$1+1);N.pop();return}if(P.name==="use"){let _1=y.get((P.attrs.href??P.attrs["xlink:href"]??"").replace(/^#/,""));if(!_1||N.includes(_1))return;let l1=d1=>parseFloat(P.attrs[d1]??"0")||0,z1=w3(I1,[1,0,0,1,l1("x"),l1("y")]),g1=_1.name==="symbol"?{..._1,name:"g"}:_1;N.push(_1),I++,$(g1,z1,e1,_,r0?[r0,...a1]:a1,$1+1),I--,N.pop();return}if(P.name==="image"){k++;return}let U=T5(e1.color,"#000000")??"#000000",s1=parseFloat(e1["stroke-width"]??"1"),Q=T5(e1.stroke,U);Q&&(s1===0||e1["stroke-opacity"]==="0")&&(Q="none");let L1=T5(e1.fill??"black",U);if(e1["fill-opacity"]==="0"&&(L1="none"),P.name==="text"){let _1=E(P);if(!_1)return;let l1=P.children.find(l0=>l0.name==="tspan"),z1=l0=>E5(P.attrs[l0]??l1?.attrs[l0]??"0")[0]??0,g1=s5(I1,[z1("x"),z1("y")]),d1=Math.sqrt(Math.abs(I1[0]*I1[3]-I1[1]*I1[2])),v1=(o6(e1["font-size"],96)??16*h)/h;if(!G(g1)||!Number.isFinite(v1*d1)){L++;return}let U1=e1["text-anchor"];w.push({text:_1,at:g1,size:v1*d1,angle:Math.atan2(-I1[1],I1[0])*180/Math.PI,font:(e1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:U1==="middle"?"center":U1==="end"?"right":"left",stroke:Q,fill:L1,layer:_});return}if(P.name!=="path"&&J(P)){L++;return}let Y1=p1(P);if(!Y1){for(let _1 of P.children)$(_1,I1,e1,_,a1,$1+1);return}let G1=Li(Y1,I1),A1=G1.filter(_1=>_1.segs.every(l1=>G(l1.a)&&G(l1.b)&&(l1.c==="L"||G(l1.p1)&&G(l1.p2))));A1.length<G1.length&&L++,A1.length&&M.push({subs:A1,stroke:Q,fill:P.name==="line"||P.name==="polyline"?"none":L1,fillRule:e1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:_,names:r0?[r0,...a1]:a1})};$(c,g,{},void 0,[],0),k&&r.push(`${k} embedded image${k===1?" was":"s were"} left out: trace ${k===1?"it":"them"} to paths first.`),z&&r.push(`${z} hidden element${z===1?" was":"s were"} left out.`),S&&r.push(`${S} path${S===1?" has":"s have"} bad data: read up to the error, as browsers draw ${S===1?"it":"them"}.`),L&&r.push(`${L} element${L===1?" was":"s were"} left out: ${L===1?"its":"their"} numbers are too large to draw.`),q>R&&r.push(`The drawing repeats its elements with <use> more than ${R.toLocaleString("en")} times: only the first ${R.toLocaleString("en")} copies were read.`);let X=P=>{let[Y,W,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return Y>=200&&W<=80&&b1<=80},j=P=>{let[Y,W,b1]=[1,3,5].map(a1=>parseInt(P.slice(a1,a1+2),16));return b1>=200&&Y<=80&&W<=80},w1=P=>!!P.stroke&&P.stroke!=="none",W1=M.filter(P=>!P.layer),E1=new Map;for(let P of W1)w1(P)&&P.stroke.startsWith("#")&&E1.set(P.stroke,(E1.get(P.stroke)??0)+P.subs.length);let Z1=[...E1.keys()],p0=Z1.filter(X),o0=new Set(p0.length?p0:Z1.length?[Z1.reduce((P,Y)=>(E1.get(Y)??0)>(E1.get(P)??0)?Y:P)]:[]),A=M.some(P=>w1(P)&&!P.layer)||M.some(P=>P.layer),F=new Map,t1=(P,Y)=>{if(P&&P!=="none"){let W=P.startsWith("#")?P:"#000000";if(o0.has(W))return t2.cut;if(W==="#00a0ff")return t2.guide;if(j(W))return t2.score;if(!F.has(W)){let b1=ki[W]??"color_"+W.slice(1);F.set(W,{name:b1,mode:"line",color:W})}return F.get(W)}if(Y&&Y!=="none")return A?t2.engrave:t2.cut};!A&&M.some(P=>P.fill&&P.fill!=="none")?r.push("The file has filled shapes and no strokes: the shapes are cut out."):!p0.length&&o0.size&&r.push(`No red lines: ${[...o0][0]} lines, the most common colour, are cut.`),F.size&&r.push(`Lines in ${[...F.values()].map(P=>P.color).join(", ")} went on their own layer${F.size===1?"":"s"}, set to mark, not cut.`);let r1=[];for(let P of M){let Y=P.layer??t1(P.stroke,P.fill);if(!Y)continue;let W=!P.layer&&Y===t2.cut&&!w1(P);r1.push({subs:P.subs,layer:Y,fillRule:P.fillRule,names:P.names,filled:W})}let y1=[];for(let P of w){let Y=P.layer??t1(P.fill!=="none"?void 0:P.stroke,P.fill);Y&&y1.push({...P,layer:Y.mode==="cut"&&A?t2.engrave:Y})}return{items:r1,texts:y1,notes:r}}var F1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),u2=([t,e],n)=>{let c=n*Math.PI/180,r=Math.cos(c),a=Math.sin(c);return[t*r-e*a,t*a+e*r]},u6=(t,e)=>[t[0]+e[0],t[1]+e[1]],f2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function u3(t,e=.005){let n=[t.segs[0].a];for(let c of t.segs)if(c.c==="L")n.push(c.b);else{let r=F1(c.a,c.p1)+F1(c.p1,c.p2)+F1(c.p2,c.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(r/e))));for(let s=1;s<=a;s++){let i=s/a,o=1-i;n.push([o*o*o*c.a[0]+3*o*o*i*c.p1[0]+3*o*i*i*c.p2[0]+i*i*i*c.b[0],o*o*o*c.a[1]+3*o*o*i*c.p1[1]+3*o*i*i*c.p2[1]+i*i*i*c.b[1]])}}return t.closed&&n.length>1&&F1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function w2(t,e=!0){let n=0;for(let c=1;c<t.length;c++)n+=F1(t[c-1],t[c]);return e&&t.length>2?n+F1(t[t.length-1],t[0]):n}function O2(t,e,n){let c=[],r=e?t.length:t.length-1;for(let a=0;a<r;a++){let s=t[a],i=t[(a+1)%t.length];c.push(s);let o=Math.floor(F1(s,i)/n);for(let l=1;l<o;l++)c.push([s[0]+(i[0]-s[0])*l/o,s[1]+(i[1]-s[1])*l/o])}return!e&&t.length&&c.push(t[t.length-1]),c}function Z2(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?((t[0]-e[0])*c+(t[1]-e[1])*r)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}var h3=class{constructor(e,n,c){this.size=c;this.cells=new Map;for(let r of e){let a=n?r.length:r.length-1;for(let s=0;s<a;s++){let i=r[s],o=r[(s+1)%r.length],l=Math.max(1,Math.ceil(F1(i,o)/(c*2)));for(let h=0;h<l;h++){let u=[i[0]+(o[0]-i[0])*h/l,i[1]+(o[1]-i[1])*h/l],f=[i[0]+(o[0]-i[0])*(h+1)/l,i[1]+(o[1]-i[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/c),p=Math.floor(Math.max(u[0],f[0])/c),m=Math.floor(Math.min(u[1],f[1])/c),g=Math.floor(Math.max(u[1],f[1])/c);for(let v=d;v<=p;v++)for(let y=m;y<=g;y++){let b=`${v},${y}`,x=this.cells.get(b);x?x.push([u,f]):this.cells.set(b,[[u,f]])}}}}}near(e,n){let c=Math.floor((e[0]-n)/this.size),r=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let i=c;i<=r;i++)for(let o=a;o<=s;o++)for(let[l,h]of this.cells.get(`${i},${o}`)??[])if(Z2(e,l,h)<=n)return!0;return!1}meets(e,n,c){let r=Math.max(1,Math.ceil(F1(e,n)/(this.size*2)));for(let a=0;a<r;a++){let s=[e[0]+(n[0]-e[0])*a/r,e[1]+(n[1]-e[1])*a/r],i=[e[0]+(n[0]-e[0])*(a+1)/r,e[1]+(n[1]-e[1])*(a+1)/r],o=Math.floor((Math.min(s[0],i[0])-c)/this.size),l=Math.floor((Math.max(s[0],i[0])+c)/this.size),h=Math.floor((Math.min(s[1],i[1])-c)/this.size),u=Math.floor((Math.max(s[1],i[1])+c)/this.size);for(let f=o;f<=l;f++)for(let d=h;d<=u;d++)for(let[p,m]of this.cells.get(`${f},${d}`)??[])if(w8(s,i,p,m)<=c)return!0}return!1}};function w8(t,e,n,c){let r=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),a=r(n,c,t),s=r(n,c,e),i=r(t,e,n),o=r(t,e,c);return a*s<0&&i*o<0?0:Math.min(Z2(t,n,c),Z2(e,n,c),Z2(n,t,e),Z2(c,t,e))}function Hi(t,e,n=.2){let c=t.length;if(c<4)return!1;let r=[0];for(let h=1;h<=c;h++)r.push(r[h-1]+F1(t[h-1],t[h%c]));let a=r[c],s=S0([t]),i=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(c)),o=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/i),p=Math.floor((Math.max(h[0],u[0])+e)/i),m=Math.floor((Math.min(h[1],u[1])-e)/i),g=Math.floor((Math.max(h[1],u[1])+e)/i);if((p-d+1)*(g-m+1)>4096)return null;for(let v=d;v<=p;v++)for(let y=m;y<=g;y++)f.push(`${v},${y}`);return f};for(let h=0;h<c;h++){let u=t[h],f=t[(h+1)%c],d=l(u,f);if(!d)return!1;for(let p of d)for(let m of o.get(p)??[]){let g=Math.abs(r[h]-r[m]);if(!(Math.min(g,a-g)-F1(u,f)-F1(t[m],t[(m+1)%c])<n)&&w8(u,f,t[m],t[(m+1)%c])<=e)return!0}for(let p of d){let m=o.get(p);m?m.push(h):o.set(p,[h])}}return!1}function z8(t,e){let n=t.map(()=>!1),c=[],r=t.map(l=>S0([l]));t.forEach((l,h)=>{let u=x1([l]),f=u.reduce((m,g)=>m+H1(g),0),d=w2(l),p=u.reduce((m,g)=>m+w2(g),0);(u.length!==1||Math.abs(f-Math.abs(H1(l)))>d*.001+1e-6||Math.abs(p-d)>d*.001+.05||Hi(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new h3([t[l]],!0,Math.max(e*4,1))),h},i=t.map((l,h)=>h).sort((l,h)=>r[l][0]-r[h][0]),o=[];for(let l of i){let[h,u,f,d]=r[l];for(let p=o.length-1;p>=0;p--)r[o[p]][2]<h-e&&o.splice(p,1);for(let p of o){let m=r[p];if(m[1]>d+e||m[3]<u-e)continue;let[g,v]=t[l].length<=t[p].length?[l,p]:[p,l],y=t[g],b=s(v);for(let x=0;x<y.length;x++)if(b.meets(y[x],y[(x+1)%y.length],e)){c.push([l,p]);break}}o.push(l)}return{self:n,pairs:c}}function f3(t,e,n,c=!0){if(!t.length||!e.length)return t.length===e.length;let r=Math.max(n*2,.2),a=new h3(t,c,Math.max(n*4,1)),s=new h3(e,c,Math.max(n*4,1));for(let i of t)for(let o of O2(i,c,r))if(!s.near(o,n))return!1;for(let i of e)for(let o of O2(i,c,r))if(!a.near(o,n))return!1;return!0}function k8(t,e,n){let c=new h3([t,...e],!0,Math.max(n*4,1)),r=a=>H2(a,t)&&!e.some(s=>H2(a,s));return(a,s)=>{let i=s?a.length:a.length-1;if(i<1)return!1;let o;for(let l=0;l<i;l++){let h=a[l],u=a[(l+1)%a.length];if(!c.meets(h,u,n)){o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==i-1)return!1;let f=F1(h,u),d=Math.min(n*3,f/3)/f,p=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,m=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(c.meets(p,m,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?r(o):!0}}function S8(t,e,n){if(!t.length)return!1;let c=new h3([e],!0,Math.max(n*4,1));return t.some(r=>O2(r,!1,Math.max(n*2,.2)).some(a=>c.near(a,n)))}function H2(t,e){let n=!1;for(let c=0,r=e.length-1;c<e.length;r=c++){let[a,s]=e[c],[i,o]=e[r];s>t[1]!=o>t[1]&&t[0]<(i-a)*(t[1]-s)/(o-s)+a&&(n=!n)}return n}function P4(t){let e=t.length;if(e<3)return null;let n=0,c=0;for(let[g,v]of t)n+=g,c+=v;n/=e,c/=e;let r=0,a=0,s=0,i=0,o=0,l=0,h=0;for(let[g,v]of t){let y=g-n,b=v-c;r+=y*y,a+=y*b,s+=b*b,i+=y*y*y,o+=b*b*b,l+=y*b*b,h+=b*y*y}let u=r*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(i+l)/2,d=(o+h)/2,p=(f*s-d*a)/u,m=(d*r-f*a)/u;return{c:[p+n,m+c],r:Math.sqrt(p*p+m*m+(r+s)/e)}}function _3(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)F1(t[0],t[o])>F1(t[0],t[n])&&(n=o);let c=o=>{if(o.length<3)return o;let l=0,h=0;for(let f=1;f<o.length-1;f++){let d=Z2(o[f],o[0],o[o.length-1]);d>l&&(l=d,h=f)}return l<=e?[o[0],o[o.length-1]]:[...c(o.slice(0,h+1)).slice(0,-1),...c(o.slice(h))]},r=c(t.slice(0,n+1)),a=c([...t.slice(n),t[0]]),s=[...r.slice(0,-1),...a.slice(0,-1)],i=[];for(let o=0;o<s.length;o++){let l=s[(o-1+s.length)%s.length],h=s[(o+1)%s.length];Z2(s[o],l,h)>e&&i.push(s[o])}return i.length>=3?i:s}function L8(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=_3(a,.002),i=s.length,o=s.findIndex((u,f)=>F1(u,s[(f+1)%i])>=.5);if(i<4||o<0)continue;let l=H1(a)>0,h=[];for(let u=1;u<=i;u++){let f=(o+u)%i,d=s[f],p=s[(f+1)%i];if(F1(d,p)<.3){h.length||h.push(d),h.push(p);continue}if(h.length>=3){let m=P4(h),[g,v,y]=[h[0],h[1],h[h.length-1]],b=(v[0]-g[0])*(y[1]-g[1])-(v[1]-g[1])*(y[0]-g[0]);m&&m.r>.005&&m.r<.6&&(b>0===l?e:n).push(m.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let c=e[Math.floor(e.length/2)],r=a=>Math.abs(a-c)<=Math.max(.005,c*.1);if(!(c>.2||n.filter(r).length>e.length*.2))return e.filter(r).length>=e.length*.8?c:void 0}function f6(t,e){let n=t.length,c=i=>F1(t[i],t[(i+1)%n])<e*1.5,r=t.findIndex((i,o)=>!c(o));if(r<0)return t;let a=[],s=r;do{let i=(s+1)%n;for(;c(i)&&i!==s;)i=(i+1)%n;let o=(i-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[i],f=t[(i+1)%n],d;if(o>0){let p=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(p)>1e-12){let m=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/p,g=[l[0]+m*(h[0]-l[0]),l[1]+m*(h[1]-l[1])],v=t[(s+1+Math.floor(o/2))%n],y=[];for(let M=1;M<=o+1;M++)y.push(t[(s+M)%n]);let b=y.length>=3?P4(y):{c:g,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&F1(g,v)<=e*2&&m>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let p=1;p<=o;p++)a.push(t[(s+p)%n]);s=i}while(s!==r);return a}function T1(t){for(let c of[0,1,2]){let r=10**c,a=Math.round(t*r)/r;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var S1=t=>String(T1(t)),n0=t=>`[${S1(t[0])}, ${S1(t[1])}]`;function Oi(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function z2(t,e,n){let c=[];(T1(t[0])!==0||T1(t[1])!==0)&&c.push(`translate(${n0(t)})`);let r=Oi(e);return r!==0&&c.push(`rotate(${r})`),[...c,n].join(" ")}function I5(t,e){return{poly:t,area:Math.abs(H1(t)),box:S0([t]),ends:e?.segs.map(n=>n.a)}}var C4=(t,e,n,c)=>[[t,e],[n,e],[n,c],[t,c]];function T4(t,e){let n=w2(t.poly),c=O2(t.poly,!0,Math.min(.5,n/256)),r=P4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:c);if(!r||r.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,r.r*3e-4));for(let i of t.poly)if(Math.abs(F1(i,r.c)-r.r)>a)return;let s=a+r.r*2e-4;for(let i of c)if(Math.abs(F1(i,r.c)-r.r)>s)return;if(!(Math.abs(t.area-Math.PI*r.r*r.r)>n*a*2))return{kind:"circle",body:`circle(d = ${S1(r.r*2)})`,at:r.c,angle:0,center:r.c,circle:r,radius:r.r}}function A8(t){let e=0,n=0;for(let[s,i]of t)e+=s,n+=i;e/=t.length,n/=t.length;let c=0,r=0,a=0;for(let[s,i]of t)c+=(s-e)**2,r+=(i-n)**2,a+=(s-e)*(i-n);return .5*Math.atan2(2*a,c-r)*180/Math.PI}function E4(t,e){let n=w2(t.poly),c=O2(t.poly,!0,Math.min(.5,n/256)),r=A8(c),a=c.map(m=>u2(m,-r)),[s,i,o,l]=S0([a]),h=(o-s)/2,u=(l-i)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+o)/2,(i+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[m,g]of a){let v=Math.hypot((m-f[0])/h,(g-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let p=u2(f,r);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${n0([h,u])})`,at:p,angle:r,center:p}}function C8(t){let e=0,n=0;for(let c=0;c<t.length;c++){let r=t[c],a=t[(c+1)%t.length],s=F1(r,a);s>e&&(e=s,n=Math.atan2(a[1]-r[1],a[0]-r[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function I4(t,e){let n=_3(t.poly,e/4),c=C8(n),r=w2(t.poly),a=O2(t.poly,!0,Math.min(.5,r/256)).map(y=>u2(y,-c)),[s,i,o,l]=S0([a]),h=o-s,u=l-i;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,i],[o,i],[o,l],[s,l]].map(y=>Math.min(...a.map(b=>F1(b,y)))*f),p=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;p<e&&(p=0),p=Math.min(p,h/2,u/2);let m=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-m[0])-(h/2-p),M=Math.abs(b-m[1])-(u/2-p),w=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-p;if(Math.abs(w)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*p*p))>r*e)return;let g=u2(m,c),v=T1(p)>0?`, r = ${S1(p)}`:"";return{kind:"rect",radius:p,body:`rect(${n0([h,u])}, center = true${v})`,at:g,angle:c,center:g,rect:{w:h,h:u,r:p}}}function V4(t,e){let n=_3(t.poly,e/4),c=n.length;if(c<3||c>48)return;let r=0,a=0;for(let[u,f]of n)r+=u/c,a+=f/c;let s=[r,a],i=n.map(u=>F1(u,s)),o=n.map((u,f)=>F1(u,n[(f+1)%c])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-r)*180/Math.PI);if(l(o)<=e&&l(i)<=e&&c<=24){let u=i.reduce((p,m)=>p+m,0)/c,f=360/c,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${c}, ${S1(u)})`,at:s,angle:d,center:s}}if(c%2===0&&c>=4&&l(o)<=e){let u=i.filter((x,M)=>M%2===0),f=i.filter((x,M)=>M%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,M)=>x+M,0)/u.length,p=f.reduce((x,M)=>x+M,0)/f.length,m=h[0];if(p>d&&([d,p]=[p,d],m=h[1]),d-p<e)return;let g=c/2,v=360/g,y=((m-90)%v+v)%v;v-y<.01&&(y=0);let b=T1(p)===T1(d*.45);return{kind:"star",body:`star(${g}, ${S1(d)}${b?"":`, ${S1(p)}`})`,at:s,angle:y,center:s}}}function Ri(t,e,n){let[c,r,a,s]=e,i=[[],[],[],[]],o=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let p=f[1];Math.abs(p-r)<=n?i[0].push(L4(f[0]-c,d[0]-c)):Math.abs(p-s)<=n?i[2].push(L4(a-f[0],a-d[0])):(o[0].push(p-r),o[2].push(s-p))}else{let p=f[0];Math.abs(p-a)<=n?i[1].push(L4(f[1]-r,d[1]-r)):Math.abs(p-c)<=n?i[3].push(L4(s-f[1],s-d[1])):(o[1].push(a-p),o[3].push(p-c))}}let l=[a-c,s-r,a-c,s-r],h=o.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:i.map(u=>Fi(u,n)),depth:h,length:l}}var L4=(t,e)=>t<e?[t,e]:[e,t];function Fi(t,e){t.sort((c,r)=>c[0]-r[0]);let n=[];for(let[c,r]of t){let a=n[n.length-1];a&&c<=a[1]+e?a[1]=Math.max(a[1],r):n.push([c,r])}return n}var h6=t=>t.reduce((e,[n,c])=>e+c-n,0);function $i(t,e,n,c,r,a){let s=[C4(0,0,t,e)],i=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],o=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=o[h];for(let f=0;f<c[h];f++){let d=u*(f+.5)/c[h];s.push(C4(d-r[h]/2,-a,d+r[h]/2,0).map(i[h]))}}),x1(s)}function d6(t,e,n){let c=_3(t.poly,e/4);if(c.length<8)return;let r=C8(c),a=c.map(E=>u2(E,-r)),s=e/2;for(let E=0;E<a.length;E++){let $=a[E],X=a[(E+1)%a.length];if(Math.abs($[0]-X[0])>s&&Math.abs($[1]-X[1])>s)return}let i=S0([a]),o=Ri(a,i,s),l=(E,$)=>E.map(X=>X.map(j=>u6(j,$))),h=(E,$)=>f3([a],l(E,$),e),u=(E,$,X)=>{let j=u2(E,r);return{kind:"tabs",body:$,at:j,angle:r,center:u2([(i[0]+i[2])/2,(i[1]+i[3])/2],r),...X}},f=w2(t.poly),d=[0,1,2,3].filter(E=>h6(o.outer[E])<o.length[E]-s);if(!d.length)return;let p=d.map(E=>o.depth[E]).filter(E=>E!==void 0);if(!p.length)return;let m=[...new Set([n,...p].filter(E=>!!E).map(T1))];for(let E of m){let $=T1(i[2]-i[0]),X=T1(i[3]-i[1]),j=[[]];for(let U=0;U<4;U++){let Q=h6(o.outer[U])>=o.length[U]-2*E-s?["flat"]:["out","in"],L1=[];for(let Y1 of j)for(let G1 of Q)L1.push([...Y1,G1]);j.splice(0,j.length,...L1)}let w1=Math.max(3*E,6),W1=new Set([w1]);for(let U of d){let s1=o.outer[U].length;for(let Q of[2*s1-1,2*s1+1,2*s1-3,2*s1+3])Q>=3&&W1.add(T1(o.length[U]/Q))}for(let U of W1)for(let s1 of j){if(s1.every(A1=>A1==="flat"))continue;let Q=c4($,X,s1,E,U);if(Math.abs(Math.abs(Q.reduce((A1,_1)=>A1+H1(_1),0))-t.area)>f*e||!h(Q,[i[0],i[1]]))continue;let Y1=s1.every(A1=>A1===s1[0])?`"${s1[0]}"`:`[${s1.map(A1=>`"${A1}"`).join(", ")}]`,G1=U===w1||[0,1].every(A1=>c3(o.length[A1],U)===c3(o.length[A1],w1));return u([i[0],i[1]],`finger_rect(${n0([$,X])}, ${Y1}${G1?"":`, finger = ${S1(U)}`})`,{kind:"fingers",thickness:E,edges:s1,finger:G1?w1:U})}let E1=[0,1,2,3].map(U=>d.includes(U)&&o.depth[U]!==void 0&&Math.abs(o.depth[U]-E)<=s);if(!E1.some(Boolean))continue;let Z1=i[0]+(E1[3]?E:0),p0=i[1]+(E1[0]?E:0),o0=T1(i[2]-(E1[1]?E:0)-Z1),A=T1(i[3]-(E1[2]?E:0)-p0),F=[o0,A,o0,A],t1=[E1[3]?E:0,E1[0]?E:0,E1[1]?E:0,E1[2]?E:0],r1=[0,0,0,0],y1=[0,0,0,0],P=!0;for(let U=0;U<4&&P;U++){if(!E1[U])continue;let s1=o.outer[U].map(([Q,L1])=>[Q-t1[U],L1-t1[U]]);r1[U]=s1.length,y1[U]=s1.length?T1(s1.reduce((Q,[L1,Y1])=>Q+Y1-L1,0)/s1.length):0,s1.forEach(([Q,L1],Y1)=>{(Math.abs((Q+L1)/2-F[U]*(Y1+.5)/r1[U])>s||Math.abs(L1-Q-y1[U])>s)&&(P=!1)})}if(!P||!h($i(o0,A,E1,r1,y1,E),[Z1,p0]))continue;let Y=E1.every(Boolean)?"":`[${E1.join(", ")}]`,W=[0,1,2,3].filter(U=>E1[U]),b1=U=>Math.max(1,Math.round(F[U]/50)),a1=W.every(U=>r1[U]===b1(U)),$1=W.every(U=>r1[U]===r1[W[0]]),e1=a1?void 0:$1?r1[W[0]]:null,I1=W.every(U=>Math.abs(y1[U]-F[U]/(2*r1[U]))<=s),r0=W.every(U=>Math.abs(y1[U]-y1[W[0]])<=s),C=I1?void 0:r0?y1[W[0]]:null,_;if(e1!==null&&C!==null){let U=[n0([o0,A])];Y?U.push(Y):(e1!==void 0||C!==void 0)&&U.push("true"),e1!==void 0&&U.push(`count = ${e1}`),C!==void 0&&U.push(`width = ${S1(C)}`),_=`tab_rect(${U.join(", ")})`}else{let U=[Q=>Q,Q=>`translate(${n0([o0,0])}) rotate(90) ${Q}`,Q=>`translate(${n0([o0,A])}) rotate(180) ${Q}`,Q=>`translate(${n0([0,A])}) rotate(270) ${Q}`],s1=[`rect(${n0([o0,A])});`];for(let Q of W){let L1=[S1(F[Q])];r1[Q]!==b1(Q)&&L1.push(`count = ${r1[Q]}`),Math.abs(y1[Q]-F[Q]/(2*r1[Q]))>s&&L1.push(`width = ${S1(y1[Q])}`),s1.push(U[Q](`tabs(${L1.join(", ")});`))}_=`{
2611
+ ${s1.map(Q=>" "+Q).join(`
2275
2612
  `)}
2276
- }`}return u([Z1,m0],G,{kind:"tabs",thickness:I,library:"tabs",label:`tabs ${k1(I)} mm deep`})}let g=o.depth;if(d.some(I=>g[I]===void 0))return;let v=[0,1,2,3].map(I=>d.includes(I)&&oe(o.outer[I])<o.length[I]*.4),y=i[0]+(v[3]?g[3]:0),b=i[1]+(v[0]?g[0]:0),x=i[2]-(v[1]?g[1]:0)-y,M=i[3]-(v[2]?g[2]:0)-b,S=(I,$,Z,_,L1)=>I===0?[i[0]+$-y,_,Z-$,L1-_]:I===1?[x-L1,i[1]+$-b,L1-_,Z-$]:I===2?[i[2]-Z-y,M-L1,Z-$,L1-_]:[_,i[3]-Z-b,L1-_,Z-$],w=[[],[],[],[]],z=[[],[],[],[]],C=[],k=[[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 I of d)if(v[I])for(let[$,Z]of o.outer[I])w[I].push(S(I,$,Z,-g[I],0));else{let $=k[I][0];for(let[Z,_]of[...o.outer[I],[k[I][1],k[I][1]]]){let[L1,W1]=[Math.max($,k[I][0]),Math.min(Z,k[I][1])];W1-L1>s&&((L1-k[I][0]<=s||k[I][1]-W1<=s)&&C.push([I,z[I].length]),z[I].push(S(I,L1,W1,-1,g[I]))),$=Math.max($,_)}}let T=([I,$,Z,_])=>L4(I,$,I+Z,$+_),q=w1([L4(0,0,x,M),...w.flat().map(T)]),R=()=>h(y0(q,z.flat().map(T)),[y,b]);if(!R())return;for(let[I,$]of C.reverse()){let[Z]=z[I].splice($,1);R()||z[I].splice($,0,Z)}let U=(I,$)=>{let Z=$%2===0,_=L=>Z?L[0]:L[1];I.sort((L,F)=>_(L)-_(F));let L1=I.every(L=>Math.abs(L[2]-I[0][2])<=s&&Math.abs(L[3]-I[0][3])<=s),W1=I.length>1?_(I[1])-_(I[0]):0,E1=I.every((L,F)=>Math.abs(_(L)-_(I[0])-F*W1)<=s),Z1=P1(W1),m0=P1(_(I[0])),o0=P1(m0+Z1*(I.length-1));if(I.length>=3&&L1&&E1&&Z1>0&&Math.floor((o0-m0)/Z1+1e-9)+1===I.length){let[,,L,F]=I[0],t1=Z?`[x, ${k1(I[0][1])}]`:`[${k1(I[0][0])}, y]`;return[`for (${Z?"x":"y"} = [${k1(m0)}:${k1(Z1)}:${k1(o0)}]) translate(${t1}) rect(${n0([L,F])});`]}return I.map(([L,F,t1,r1])=>`translate(${n0([L,F])}) rect(${n0([t1,r1])});`)},j=[0,1,2,3].flatMap(I=>w[I].length?U(w[I],I):[]),V=[0,1,2,3].flatMap(I=>z[I].length?U(z[I],I):[]),Q=j.length?`union() {
2277
- ${[`rect(${n0([x,M])});`,...j].join(`
2613
+ }`}return u([Z1,p0],_,{kind:"tabs",thickness:E,library:"tabs",label:`tabs ${S1(E)} mm deep`})}let g=o.depth;if(d.some(E=>g[E]===void 0))return;let v=[0,1,2,3].map(E=>d.includes(E)&&h6(o.outer[E])<o.length[E]*.4),y=i[0]+(v[3]?g[3]:0),b=i[1]+(v[0]?g[0]:0),x=i[2]-(v[1]?g[1]:0)-y,M=i[3]-(v[2]?g[2]:0)-b,w=(E,$,X,j,w1)=>E===0?[i[0]+$-y,j,X-$,w1-j]:E===1?[x-w1,i[1]+$-b,w1-j,X-$]:E===2?[i[2]-X-y,M-w1,X-$,w1-j]:[j,i[3]-X-b,w1-j,X-$],k=[[],[],[],[]],z=[[],[],[],[]],S=[],L=[[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 E of d)if(v[E])for(let[$,X]of o.outer[E])k[E].push(w(E,$,X,-g[E],0));else{let $=L[E][0];for(let[X,j]of[...o.outer[E],[L[E][1],L[E][1]]]){let[w1,W1]=[Math.max($,L[E][0]),Math.min(X,L[E][1])];W1-w1>s&&((w1-L[E][0]<=s||L[E][1]-W1<=s)&&S.push([E,z[E].length]),z[E].push(w(E,w1,W1,-1,g[E]))),$=Math.max($,j)}}let I=([E,$,X,j])=>C4(E,$,E+X,$+j),q=x1([C4(0,0,x,M),...k.flat().map(I)]),R=()=>h(b0(q,z.flat().map(I)),[y,b]);if(!R())return;for(let[E,$]of S.reverse()){let[X]=z[E].splice($,1);R()||z[E].splice($,0,X)}let N=(E,$)=>{let X=$%2===0,j=A=>X?A[0]:A[1];E.sort((A,F)=>j(A)-j(F));let w1=E.every(A=>Math.abs(A[2]-E[0][2])<=s&&Math.abs(A[3]-E[0][3])<=s),W1=E.length>1?j(E[1])-j(E[0]):0,E1=E.every((A,F)=>Math.abs(j(A)-j(E[0])-F*W1)<=s),Z1=T1(W1),p0=T1(j(E[0])),o0=T1(p0+Z1*(E.length-1));if(E.length>=3&&w1&&E1&&Z1>0&&Math.floor((o0-p0)/Z1+1e-9)+1===E.length){let[,,A,F]=E[0],t1=X?`[x, ${S1(E[0][1])}]`:`[${S1(E[0][0])}, y]`;return[`for (${X?"x":"y"} = [${S1(p0)}:${S1(Z1)}:${S1(o0)}]) translate(${t1}) rect(${n0([A,F])});`]}return E.map(([A,F,t1,r1])=>`translate(${n0([A,F])}) rect(${n0([t1,r1])});`)},G=[0,1,2,3].flatMap(E=>k[E].length?N(k[E],E):[]),V=[0,1,2,3].flatMap(E=>z[E].length?N(z[E],E):[]),J=G.length?`union() {
2614
+ ${[`rect(${n0([x,M])});`,...G].join(`
2278
2615
  `)}
2279
- }`:`rect(${n0([x,M])})`,W=V.length?`difference() {
2280
- ${[Q.endsWith("}")?Q:Q+";",...V].join(`
2616
+ }`:`rect(${n0([x,M])})`,o1=V.length?`difference() {
2617
+ ${[J.endsWith("}")?J:J+";",...V].join(`
2281
2618
  `)}
2282
- }`:Q,o1=d.map(I=>P1(g[I])),m1=o1.sort((I,$)=>o1.filter(Z=>Z===$).length-o1.filter(Z=>Z===I).length)[0];return u([y,b],W,{kind:V.length?"fingers":"tabs",thickness:m1,generic:!0,label:`${V.length?"finger joints":"tabs"} ${k1(m1)} mm deep`})}function Fi(t){let[e,n,c,r]=k0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,Z2(h,t[d],t[f]));return u},s=[(e+c)/2,(n+r)/2],i=V2(s,t)?a(s):0,o=24;for(let h=0;h<=o;h++)for(let u=0;u<=o;u++){let f=[e+(c-e)*h/o,n+(r-n)*u/o];if(!V2(f,t))continue;let d=a(f);d>i&&(s=f,i=d)}let l=Math.max(c-e,r-n)/o;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!V2(d,t))continue;let m=a(d);m>i&&(s=d,i=m,h=!0)}h||(l/=2)}return{c:s,r:i}}function $i(t,e,n){let r=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let i=r+Math.PI/2+Math.PI*s/64;a.push([t[0]+n*Math.cos(i),t[1]+n*Math.sin(i)])}for(let s=0;s<=64;s++){let i=r-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(i),e[1]+n*Math.sin(i)])}return a}function At(t,e){let[n,c,r,a]=t.box;if(Math.max(r-n,a-c)>80)return;let s=M2(t.poly),i=H2(t.poly,!0,Math.min(.25,s/400)),o=Fi(t.poly),l=i.filter(V=>Math.abs(O1(V,o.c)-o.r)<=e),h=A4(l);if(!h||l.length<8)return;let u=i[0];for(let V of i)O1(V,h.c)>O1(u,h.c)&&(u=V);let f=O1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],m=V=>(V[0]-h.c[0])*d[0]+(V[1]-h.c[1])*d[1],p=V=>-(V[0]-h.c[0])*d[1]+(V[1]-h.c[1])*d[0],g=i.filter(V=>m(V)>h.r+e&&m(V)<f-h.r);if(g.length<4)return;let v=[g.filter(V=>p(V)>0),g.filter(V=>p(V)<0)];if(v.some(V=>V.length<2))return;let y=v.map(V=>h2([1,0],St(V))).map(V=>V[0]*d[0]+V[1]*d[1]<0?[-V[0],-V[1]]:V),b=[y[0][0]+y[1][0],y[0][1]+y[1][1]],x=Math.hypot(b[0],b[1]);if(d=[b[0]/x,b[1]/x],g=i.filter(V=>m(V)>h.r+e&&m(V)<f-h.r),g.length<4||Math.abs(g.reduce((V,Q)=>V+p(Q),0)/g.length)>e)return;let M=g.map(V=>Math.abs(p(V))).sort((V,Q)=>V-Q),S=M[Math.floor(M.length/2)]*2;if(S>=h.r*2-e||S<.3)return;let w=Math.max(...i.map(m)),z=le(h.c,[d[0]*(w-S/2),d[1]*(w-S/2)]),C=w1([k3(h.r,h.r,256).map(V=>le(V,h.c)),$i(h.c,z,S/2)]);if(!f3([t.poly],C,e))return;let k=w-S/2,T=h.r*2,q=Math.atan2(d[1],d[0])*180/Math.PI-90,R=[];P1(T)!==9&&R.push(`head = ${k1(T)}`),P1(S)!==4.5&&R.push(`shank = ${k1(S)}`),P1(k)!==10&&R.push(`drop = ${k1(k)}`);let U=k>=(T+S)/2-1e-9,j=U?`keyhole(${R.join(", ")})`:`{ translate(${n0([0,-k])}) circle(d = ${k1(T)}); hull() { circle(d = ${k1(S)}); translate(${n0([0,-k])}) circle(d = ${k1(S)}); } }`;return{kind:"keyhole",radius:T/2,body:j,at:z,angle:q,center:z,label:"keyhole",keyhole:{head:T,shank:S,drop:k,top:z},library:U?"hanging":void 0}}var bt=.0025,S4=(t,e)=>Math.abs(t[0]-e[0])>bt||Math.abs(t[1]-e[1])>bt;function j3(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(a=>a.a);t.closed||n.push(t.segs[t.segs.length-1].b);let c=[n[0]];for(let a of n.slice(1))S4(a,c[c.length-1])&&c.push(a);!t.closed&&c.length<2&&c.push(n[n.length-1]);let r=`[${c.map(a=>n0(u2(a,e))).join(", ")}]`;return t.closed?`polygon(${r})`:c.length===2?`line(${n0(u2(c[0],e))}, ${n0(u2(c[1],e))})`:`polyline(${r})`}return`path("${fe([t],e)}")`}function fe(t,e){let n=c=>`${k1(c[0]-e[0])} ${k1(c[1]-e[1])}`;return t.map(c=>{let r=`M${n(c.segs[0].a)}`,a=c.segs[0].a;for(let s of c.segs)!S4(s.b,a)&&(s.c==="L"||!S4(s.p1,a)&&!S4(s.p2,a))||(r+=s.c==="L"?`L${n(s.b)}`:`C${n(s.p1)} ${n(s.p2)} ${n(s.b)}`,a=s.b);return c.closed?r+"Z":r}).join("")}var V0=.01;function Ct(t){return{closed:t.closed,segs:t.segs.slice().reverse().map(e=>e.c==="L"?{c:"L",a:e.b,b:e.a}:{c:"C",a:e.b,p1:e.p2,p2:e.p1,b:e.a})}}var _3=t=>t.segs[0].a,Pt=t=>t.segs[t.segs.length-1].b;function Di(t){let e=new Set,n=[],c=s=>`${Math.round(s[0]/V0)},${Math.round(s[1]/V0)}`,r=new Map;t.forEach((s,i)=>{for(let o of[_3(s),Pt(s)]){let l=c(o);r.set(l,[...r.get(l)??[],i])}});let a=s=>{let[i,o]=[Math.round(s[0]/V0),Math.round(s[1]/V0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of r.get(`${i+l},${o+h}`)??[])if(!e.has(u)&&(O1(_3(t[u]),s)<=V0||O1(Pt(t[u]),s)<=V0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let i=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=i[i.length-1].b;if(O1(h,i[0].a)<=V0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=O1(_3(t[u]),h)<=V0?t[u]:Ct(t[u]);i=i.concat(f.segs)}i=Ct({segs:i,closed:!1}).segs}let o=i.length>1&&O1(i[i.length-1].b,i[0].a)<=V0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var Tt=.05;function qi(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n=e[0]===255&&e[1]===254||e[0]===60&&e[1]===0?"utf-16le":e[0]===254&&e[1]===255||e[0]===0&&e[1]===60?"utf-16be":"utf-8";return new TextDecoder(n).decode(e)}function Ni(t,e={}){let n=e.tolerance??Tt,c=typeof t=="string"?t:qi(t),r=yt(c,{dpi:e.dpi}),a=[...r.notes],s={},i=(L,F=1)=>s[L]=(s[L]??0)+F,o=[],l=[],h=new Map;for(let L of r.items)if(L.layer.mode==="cut")for(let F of L.subs)F.closed?o.push({sub:F,names:L.names,group:L.filled?L:void 0}):(l.push(F),h.set(F,L.names));let u=Di(l);l=[];for(let{sub:L,from:F}of u)L.closed?o.push({sub:L,names:h.get(F)??[],line:{segs:L.segs,closed:!1}}):l.push(L);let f=o.map(L=>({...L,outline:E5(u3(L.sub),L.sub)})),d=f.filter(L=>L.outline.poly.length>=3&&L.outline.area>M2(L.outline.poly)*V0);for(let L of f)d.includes(L)||l.push(L.line??{segs:L.sub.segs,closed:!1});let m=(L,F,t1,r1)=>{if(t1!==r1)return!1;let[y1,P,Y,X]=L.box,[b1,a1,R1,e1]=F.box;if(y1<b1-V0||P<a1-V0||Y>R1+V0||X>e1+V0)return!1;let T1=L.poly.length;return[0,Math.floor(T1/3),Math.floor(2*T1/3)].filter(A=>V2(L.poly[A],F.poly)).length>=2},p=L=>{let F=d.map((y1,P)=>P).filter(y1=>!L.has(y1)).sort((y1,P)=>d[P].outline.area-d[y1].outline.area),t1=new Map,r1=new Map;return F.forEach((y1,P)=>{let Y=-1;for(let X=P-1;X>=0;X--){let b1=F[X];if(d[b1].outline.area>d[y1].outline.area&&m(d[y1].outline,d[b1].outline,d[y1].group,d[b1].group)){Y=b1;break}}t1.set(y1,Y),r1.set(y1,Y<0?0:r1.get(Y)+1)}),{order:F,parent:t1,depth:r1}},g=Mt(d.map(L=>L.outline.poly),V0*2),v=p(new Set),{parent:y,depth:b}=v,x=L=>b.get(L)%2===0?L:y.get(L),M=new Set(d.map((L,F)=>F).filter(L=>g.self[L]));for(let[L,F]of g.pairs)x(L)===x(F)&&M.add(L).add(F);for(let L of v.order)b.get(L)%2===1&&M.has(y.get(L))&&M.add(L);for(let L of M)l.push(d[L].line??{segs:d[L].sub.segs,closed:!1});M.size&&a.push(`${M.size} outline${M.size===1?" touches or crosses":"s touch or cross"} a hole or ${M.size===1?"itself":"themselves"}, so ${M.size===1?"it is":"they are"} kept as cut lines.`);let S=[],w=new Map;for(let L of v.order){if(M.has(L))continue;let F=d[L];if(b.get(L)%2===0){let t1={sub:F.sub,outline:F.outline,names:F.names,holes:[],lines:[],marks:new Map,texts:[]};S.push(t1),w.set(L,t1)}else w.get(y.get(L)).holes.push({sub:F.sub,outline:F.outline,line:F.line})}let z=e.kerf!==void 0?e.kerf/2:kt(S.map(L=>L.outline.poly)),C=0;if(z&&z>0){let L=F=>({closed:!0,segs:F.map((t1,r1)=>({c:"L",a:t1,b:F[(r1+1)%F.length]}))});for(let F of S){let t1=y0([he(F.outline.poly,z)],F.holes.map(e1=>he(e1.outline.poly,z))),r1=B0(p0(t1,-z,"miter")),y1=p0(r1.flat(),z,"round",Math.min(.01,z/10)),P=y0([F.outline.poly],F.holes.map(e1=>e1.outline.poly)),Y=e1=>Math.abs(H1(e1))<=M2(e1)*V0;if(r1.length!==1||r1[0].length!==F.holes.length+1||r1[0].some(Y)||!f3(y1,P,n)){F.noKerf=!0;continue}F.drawn=[F.sub,...F.holes.map(e1=>e1.sub)];let[X,...b1]=r1[0].map(e1=>G3(e1,.001));F.outline=E5(X),F.sub=L(X);let a1=e1=>[(e1.box[0]+e1.box[2])/2,(e1.box[1]+e1.box[3])/2],R1=b1.map(e1=>E5(e1));for(let e1 of F.holes){let T1=a1(e1.outline),r0=R1.reduce((A,G)=>O1(a1(G),T1)<O1(a1(A),T1)?G:A);R1.splice(R1.indexOf(r0),1),e1.outline=r0,e1.sub=L(r0.poly),e1.line=void 0}}C=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${k1(C)} mm kerf: they are moved back, and $kerf is set.`)}let k=L=>{let F;for(let t1 of S){let[r1,y1,P,Y]=t1.outline.box;L[0]<r1||L[0]>P||L[1]<y1||L[1]>Y||V2(L,t1.outline.poly)&&(!F||t1.outline.area<F.outline.area)&&(F=t1)}return F},T={lines:[],marks:new Map,texts:[]},q=new Map,R=L=>{let F=k(_3(L));if(!F)return;let t1=q.get(F);return t1||(t1=wt(F.outline.poly,F.holes.map(r1=>r1.outline.poly),n),q.set(F,t1)),t1(u3(L,.02),L.closed)?F:void 0};for(let L of l){let F=R(L);(F?F.lines:T.lines).push(L)}for(let L of r.items)if(L.layer.mode!=="cut")for(let F of L.subs){let t1=(R(F)??T).marks;t1.set(L,[...t1.get(L)??[],F])}for(let L of r.texts)(k(L.at)??T).texts.push(L);r.texts.some(L=>L.layer.mode==="cut")&&a.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let L of S){let F=L.lines.map(t1=>u3(t1));L.holes=L.holes.filter(t1=>{if(!t1.line)return!0;let r1=P=>V2(P,t1.outline.poly),y1=zt(F,t1.outline.poly,V0*2)||L.lines.some(P=>r1(_3(P)))||[...L.marks.values()].some(P=>P.some(Y=>r1(_3(Y))))||L.texts.some(P=>r1(P.at))||S.some(P=>P!==L&&P.outline.area<t1.outline.area&&r1(P.outline.poly[0]));return y1&&L.lines.push(t1.line),!y1})}let U=L=>C4(L,n)??E4(L,n)??P4(L,n)??T4(L,n)??At(L,n),j=new Map;for(let L of S){let F=C4(L.outline,n)??E4(L.outline,n)??P4(L.outline,n)??T4(L.outline,n)??ue(L.outline,n);j.set(L,F);for(let t1 of L.holes)t1.found=U(t1.outline)}let V=new Map,Q=[...j.values()].some(L=>L?.thickness&&!L.generic);for(let L of j.values())L?.thickness&&L.thickness<=10&&(!Q||!L.generic)&&V.set(L.thickness,(V.get(L.thickness)??0)+1);let W=[...V.entries()].sort((L,F)=>F[1]-L[1])[0]?.[0];if(W!==void 0)for(let L of S){let F=j.get(L);if(F?.thickness!==void 0&&F.thickness!==W){let t1=ue(L.outline,n,W);t1&&t1.thickness===W&&j.set(L,t1)}}let o1=new Set;for(let L of j.values())L?.kind==="fingers"&&L.finger&&o1.add(P1(L.finger));S.sort((L,F)=>{let t1=F.outline.box[3]-L.outline.box[3];return Math.abs(t1)>1?t1:L.outline.box[0]-F.outline.box[0]});let m1=new Set,I=new Map,$=[];for(let[L,F]of S.entries()){let t1=F.names[0]??`part ${L+1}`,r1=(I.get(t1)??0)+1;I.set(t1,r1);let y1=r1>1?`${t1} ${r1}`:t1,P;for(let r0 of[2,1,0]){let A=Bi(F,j.get(F),r0,W,o1,n);if(_i(A,F,n)){P=A,r0<2&&a.push(r0===1?`Part "${y1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${y1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!P){let r0=F.drawn??[F.sub,...F.holes.map(A=>A.sub)];T.lines.push(...r0.map(A=>({segs:A.segs,closed:!1})),...F.lines);for(let[A,G]of F.marks)T.marks.set(A,[...T.marks.get(A)??[],...G]);T.texts.push(...F.texts),a.push(`Part "${y1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let r0 of P.found)i(r0);for(let r0 of P.libraries)m1.add(r0);let Y=Et(F.marks,[],F.texts,P.origin),X=[...P.cut,...Y],b1=P.thickness,a1=[...b1!==void 0&&(W===void 0||P1(b1)!==P1(W))?[`thickness = ${k1(b1)}`]:[],...F.noKerf&&C>0?["kerf = 0"]:[]],R1=a1.length?`material(${a1.join(", ")}) `:"",e1=`part("${y1.replace(/["\\]/g,"")}")`,T1=X.length===1&&!X[0].includes(`
2283
- `)?`${R1}${e1} ${X[0]}`:`${R1}${e1} {
2284
- ${X.join(`
2619
+ }`:J,Z=d.map(E=>T1(g[E])),p1=Z.sort((E,$)=>Z.filter(X=>X===$).length-Z.filter(X=>X===E).length)[0];return u([y,b],o1,{kind:V.length?"fingers":"tabs",thickness:p1,generic:!0,label:`${V.length?"finger joints":"tabs"} ${S1(p1)} mm deep`})}function Di(t){let[e,n,c,r]=S0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,Z2(h,t[d],t[f]));return u},s=[(e+c)/2,(n+r)/2],i=H2(s,t)?a(s):0,o=24;for(let h=0;h<=o;h++)for(let u=0;u<=o;u++){let f=[e+(c-e)*h/o,n+(r-n)*u/o];if(!H2(f,t))continue;let d=a(f);d>i&&(s=f,i=d)}let l=Math.max(c-e,r-n)/o;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!H2(d,t))continue;let p=a(d);p>i&&(s=d,i=p,h=!0)}h||(l/=2)}return{c:s,r:i}}function qi(t,e,n){let r=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let i=r+Math.PI/2+Math.PI*s/64;a.push([t[0]+n*Math.cos(i),t[1]+n*Math.sin(i)])}for(let s=0;s<=64;s++){let i=r-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(i),e[1]+n*Math.sin(i)])}return a}function P8(t,e){let[n,c,r,a]=t.box;if(Math.max(r-n,a-c)>80)return;let s=w2(t.poly),i=O2(t.poly,!0,Math.min(.25,s/400)),o=Di(t.poly),l=i.filter(V=>Math.abs(F1(V,o.c)-o.r)<=e),h=P4(l);if(!h||l.length<8)return;let u=i[0];for(let V of i)F1(V,h.c)>F1(u,h.c)&&(u=V);let f=F1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],p=V=>(V[0]-h.c[0])*d[0]+(V[1]-h.c[1])*d[1],m=V=>-(V[0]-h.c[0])*d[1]+(V[1]-h.c[1])*d[0],g=i.filter(V=>p(V)>h.r+e&&p(V)<f-h.r);if(g.length<4)return;let v=[g.filter(V=>m(V)>0),g.filter(V=>m(V)<0)];if(v.some(V=>V.length<2))return;let y=v.map(V=>u2([1,0],A8(V))).map(V=>V[0]*d[0]+V[1]*d[1]<0?[-V[0],-V[1]]:V),b=[y[0][0]+y[1][0],y[0][1]+y[1][1]],x=Math.hypot(b[0],b[1]);if(d=[b[0]/x,b[1]/x],g=i.filter(V=>p(V)>h.r+e&&p(V)<f-h.r),g.length<4||Math.abs(g.reduce((V,J)=>V+m(J),0)/g.length)>e)return;let M=g.map(V=>Math.abs(m(V))).sort((V,J)=>V-J),w=M[Math.floor(M.length/2)]*2;if(w>=h.r*2-e||w<.3)return;let k=Math.max(...i.map(p)),z=u6(h.c,[d[0]*(k-w/2),d[1]*(k-w/2)]),S=x1([k3(h.r,h.r,256).map(V=>u6(V,h.c)),qi(h.c,z,w/2)]);if(!f3([t.poly],S,e))return;let L=k-w/2,I=h.r*2,q=Math.atan2(d[1],d[0])*180/Math.PI-90,R=[];T1(I)!==9&&R.push(`head = ${S1(I)}`),T1(w)!==4.5&&R.push(`shank = ${S1(w)}`),T1(L)!==10&&R.push(`drop = ${S1(L)}`);let N=L>=(I+w)/2-1e-9,G=N?`keyhole(${R.join(", ")})`:`{ translate(${n0([0,-L])}) circle(d = ${S1(I)}); hull() { circle(d = ${S1(w)}); translate(${n0([0,-L])}) circle(d = ${S1(w)}); } }`;return{kind:"keyhole",radius:I/2,body:G,at:z,angle:q,center:z,label:"keyhole",keyhole:{head:I,shank:w,drop:L,top:z},library:N?"hanging":void 0}}var M8=.0025,A4=(t,e)=>Math.abs(t[0]-e[0])>M8||Math.abs(t[1]-e[1])>M8;function G3(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(a=>a.a);t.closed||n.push(t.segs[t.segs.length-1].b);let c=[n[0]];for(let a of n.slice(1))A4(a,c[c.length-1])&&c.push(a);!t.closed&&c.length<2&&c.push(n[n.length-1]);let r=`[${c.map(a=>n0(f2(a,e))).join(", ")}]`;return t.closed?`polygon(${r})`:c.length===2?`line(${n0(f2(c[0],e))}, ${n0(f2(c[1],e))})`:`polyline(${r})`}return`path("${p6([t],e)}")`}function p6(t,e){let n=c=>`${S1(c[0]-e[0])} ${S1(c[1]-e[1])}`;return t.map(c=>{let r=`M${n(c.segs[0].a)}`,a=c.segs[0].a;for(let s of c.segs)!A4(s.b,a)&&(s.c==="L"||!A4(s.p1,a)&&!A4(s.p2,a))||(r+=s.c==="L"?`L${n(s.b)}`:`C${n(s.p1)} ${n(s.p2)} ${n(s.b)}`,a=s.b);return c.closed?r+"Z":r}).join("")}var V0=.01;function T8(t){return{closed:t.closed,segs:t.segs.slice().reverse().map(e=>e.c==="L"?{c:"L",a:e.b,b:e.a}:{c:"C",a:e.b,p1:e.p2,p2:e.p1,b:e.a})}}var j3=t=>t.segs[0].a,E8=t=>t.segs[t.segs.length-1].b;function Ni(t){let e=new Set,n=[],c=s=>`${Math.round(s[0]/V0)},${Math.round(s[1]/V0)}`,r=new Map;t.forEach((s,i)=>{for(let o of[j3(s),E8(s)]){let l=c(o);r.set(l,[...r.get(l)??[],i])}});let a=s=>{let[i,o]=[Math.round(s[0]/V0),Math.round(s[1]/V0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of r.get(`${i+l},${o+h}`)??[])if(!e.has(u)&&(F1(j3(t[u]),s)<=V0||F1(E8(t[u]),s)<=V0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let i=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=i[i.length-1].b;if(F1(h,i[0].a)<=V0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=F1(j3(t[u]),h)<=V0?t[u]:T8(t[u]);i=i.concat(f.segs)}i=T8({segs:i,closed:!1}).segs}let o=i.length>1&&F1(i[i.length-1].b,i[0].a)<=V0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var V8=.05;function Ui(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n=e[0]===255&&e[1]===254||e[0]===60&&e[1]===0?"utf-16le":e[0]===254&&e[1]===255||e[0]===0&&e[1]===60?"utf-16be":"utf-8";return new TextDecoder(n).decode(e)}function Bi(t,e={}){let n=e.tolerance??V8,c=typeof t=="string"?t:Ui(t),r=x8(c,{dpi:e.dpi}),a=[...r.notes],s={},i=(A,F=1)=>s[A]=(s[A]??0)+F,o=[],l=[],h=new Map;for(let A of r.items)if(A.layer.mode==="cut")for(let F of A.subs)F.closed?o.push({sub:F,names:A.names,group:A.filled?A:void 0}):(l.push(F),h.set(F,A.names));let u=Ni(l);l=[];for(let{sub:A,from:F}of u)A.closed?o.push({sub:A,names:h.get(F)??[],line:{segs:A.segs,closed:!1}}):l.push(A);let f=o.map(A=>({...A,outline:I5(u3(A.sub),A.sub)})),d=f.filter(A=>A.outline.poly.length>=3&&A.outline.area>w2(A.outline.poly)*V0);for(let A of f)d.includes(A)||l.push(A.line??{segs:A.sub.segs,closed:!1});let p=(A,F,t1,r1)=>{if(t1!==r1)return!1;let[y1,P,Y,W]=A.box,[b1,a1,$1,e1]=F.box;if(y1<b1-V0||P<a1-V0||Y>$1+V0||W>e1+V0)return!1;let I1=A.poly.length;return[0,Math.floor(I1/3),Math.floor(2*I1/3)].filter(C=>H2(A.poly[C],F.poly)).length>=2},m=A=>{let F=d.map((y1,P)=>P).filter(y1=>!A.has(y1)).sort((y1,P)=>d[P].outline.area-d[y1].outline.area),t1=new Map,r1=new Map;return F.forEach((y1,P)=>{let Y=-1;for(let W=P-1;W>=0;W--){let b1=F[W];if(d[b1].outline.area>d[y1].outline.area&&p(d[y1].outline,d[b1].outline,d[y1].group,d[b1].group)){Y=b1;break}}t1.set(y1,Y),r1.set(y1,Y<0?0:r1.get(Y)+1)}),{order:F,parent:t1,depth:r1}},g=z8(d.map(A=>A.outline.poly),V0*2),v=m(new Set),{parent:y,depth:b}=v,x=A=>b.get(A)%2===0?A:y.get(A),M=new Set(d.map((A,F)=>F).filter(A=>g.self[A]));for(let[A,F]of g.pairs)x(A)===x(F)&&M.add(A).add(F);for(let A of v.order)b.get(A)%2===1&&M.has(y.get(A))&&M.add(A);for(let A of M)l.push(d[A].line??{segs:d[A].sub.segs,closed:!1});M.size&&a.push(`${M.size} outline${M.size===1?" touches or crosses":"s touch or cross"} a hole or ${M.size===1?"itself":"themselves"}, so ${M.size===1?"it is":"they are"} kept as cut lines.`);let w=[],k=new Map;for(let A of v.order){if(M.has(A))continue;let F=d[A];if(b.get(A)%2===0){let t1={sub:F.sub,outline:F.outline,names:F.names,holes:[],lines:[],marks:new Map,texts:[]};w.push(t1),k.set(A,t1)}else k.get(y.get(A)).holes.push({sub:F.sub,outline:F.outline,line:F.line})}let z=e.kerf!==void 0?e.kerf/2:L8(w.map(A=>A.outline.poly)),S=0;if(z&&z>0){let A=F=>({closed:!0,segs:F.map((t1,r1)=>({c:"L",a:t1,b:F[(r1+1)%F.length]}))});for(let F of w){let t1=b0([f6(F.outline.poly,z)],F.holes.map(e1=>f6(e1.outline.poly,z))),r1=_0(m0(t1,-z,"miter")),y1=m0(r1.flat(),z,"round",Math.min(.01,z/10)),P=b0([F.outline.poly],F.holes.map(e1=>e1.outline.poly)),Y=e1=>Math.abs(H1(e1))<=w2(e1)*V0;if(r1.length!==1||r1[0].length!==F.holes.length+1||r1[0].some(Y)||!f3(y1,P,n)){F.noKerf=!0;continue}F.drawn=[F.sub,...F.holes.map(e1=>e1.sub)];let[W,...b1]=r1[0].map(e1=>_3(e1,.001));F.outline=I5(W),F.sub=A(W);let a1=e1=>[(e1.box[0]+e1.box[2])/2,(e1.box[1]+e1.box[3])/2],$1=b1.map(e1=>I5(e1));for(let e1 of F.holes){let I1=a1(e1.outline),r0=$1.reduce((C,_)=>F1(a1(_),I1)<F1(a1(C),I1)?_:C);$1.splice($1.indexOf(r0),1),e1.outline=r0,e1.sub=A(r0.poly),e1.line=void 0}}S=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${S1(S)} mm kerf: they are moved back, and $kerf is set.`)}let L=A=>{let F;for(let t1 of w){let[r1,y1,P,Y]=t1.outline.box;A[0]<r1||A[0]>P||A[1]<y1||A[1]>Y||H2(A,t1.outline.poly)&&(!F||t1.outline.area<F.outline.area)&&(F=t1)}return F},I={lines:[],marks:new Map,texts:[]},q=new Map,R=A=>{let F=L(j3(A));if(!F)return;let t1=q.get(F);return t1||(t1=k8(F.outline.poly,F.holes.map(r1=>r1.outline.poly),n),q.set(F,t1)),t1(u3(A,.02),A.closed)?F:void 0};for(let A of l){let F=R(A);(F?F.lines:I.lines).push(A)}for(let A of r.items)if(A.layer.mode!=="cut")for(let F of A.subs){let t1=(R(F)??I).marks;t1.set(A,[...t1.get(A)??[],F])}for(let A of r.texts)(L(A.at)??I).texts.push(A);r.texts.some(A=>A.layer.mode==="cut")&&a.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let A of w){let F=A.lines.map(t1=>u3(t1));A.holes=A.holes.filter(t1=>{if(!t1.line)return!0;let r1=P=>H2(P,t1.outline.poly),y1=S8(F,t1.outline.poly,V0*2)||A.lines.some(P=>r1(j3(P)))||[...A.marks.values()].some(P=>P.some(Y=>r1(j3(Y))))||A.texts.some(P=>r1(P.at))||w.some(P=>P!==A&&P.outline.area<t1.outline.area&&r1(P.outline.poly[0]));return y1&&A.lines.push(t1.line),!y1})}let N=A=>T4(A,n)??I4(A,n)??E4(A,n)??V4(A,n)??P8(A,n),G=new Map;for(let A of w){let F=T4(A.outline,n)??I4(A.outline,n)??E4(A.outline,n)??V4(A.outline,n)??d6(A.outline,n);G.set(A,F);for(let t1 of A.holes)t1.found=N(t1.outline)}let V=new Map,J=[...G.values()].some(A=>A?.thickness&&!A.generic);for(let A of G.values())A?.thickness&&A.thickness<=10&&(!J||!A.generic)&&V.set(A.thickness,(V.get(A.thickness)??0)+1);let o1=[...V.entries()].sort((A,F)=>F[1]-A[1])[0]?.[0];if(o1!==void 0)for(let A of w){let F=G.get(A);if(F?.thickness!==void 0&&F.thickness!==o1){let t1=d6(A.outline,n,o1);t1&&t1.thickness===o1&&G.set(A,t1)}}let Z=new Set;for(let A of G.values())A?.kind==="fingers"&&A.finger&&Z.add(T1(A.finger));w.sort((A,F)=>{let t1=F.outline.box[3]-A.outline.box[3];return Math.abs(t1)>1?t1:A.outline.box[0]-F.outline.box[0]});let p1=new Set,E=new Map,$=[];for(let[A,F]of w.entries()){let t1=F.names[0]??`part ${A+1}`,r1=(E.get(t1)??0)+1;E.set(t1,r1);let y1=r1>1?`${t1} ${r1}`:t1,P;for(let r0 of[2,1,0]){let C=Gi(F,G.get(F),r0,o1,Z,n);if(Xi(C,F,n)){P=C,r0<2&&a.push(r0===1?`Part "${y1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${y1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!P){let r0=F.drawn??[F.sub,...F.holes.map(C=>C.sub)];I.lines.push(...r0.map(C=>({segs:C.segs,closed:!1})),...F.lines);for(let[C,_]of F.marks)I.marks.set(C,[...I.marks.get(C)??[],..._]);I.texts.push(...F.texts),a.push(`Part "${y1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let r0 of P.found)i(r0);for(let r0 of P.libraries)p1.add(r0);let Y=I8(F.marks,[],F.texts,P.origin),W=[...P.cut,...Y],b1=P.thickness,a1=[...b1!==void 0&&(o1===void 0||T1(b1)!==T1(o1))?[`thickness = ${S1(b1)}`]:[],...F.noKerf&&S>0?["kerf = 0"]:[]],$1=a1.length?`material(${a1.join(", ")}) `:"",e1=`part("${y1.replace(/["\\]/g,"")}")`,I1=W.length===1&&!W[0].includes(`
2620
+ `)?`${$1}${e1} ${W[0]}`:`${$1}${e1} {
2621
+ ${W.join(`
2285
2622
  `)}
2286
- }`;$.push({name:y1,code:w2(P.origin,0,T1),local:T1,thickness:b1})}let Z=Et(T.marks,T.lines,T.texts,[0,0]);Z.length&&S.length&&a.push("Some lines or marks are outside every part; they are kept on their own.");let _;if(e.pack){let L=new Map;for(let t1 of $){let r1=t1.local.replace(/part\("[^"]*"\)/,"part()"),y1=L.get(r1);y1?y1.qty++:L.set(r1,{name:t1.name,qty:1})}_=[...L.entries()].map(([t1,r1])=>t1.replace("part()",`part("${r1.name.replace(/["\\]/g,"")}"${r1.qty>1?`, qty = ${r1.qty}`:""})`));let F=$.length-L.size;F&&a.push(`${F} part${F===1?" is":"s are"} the same as another and became a quantity.`)}else _=$.map(L=>L.code);let L1=Object.entries(s).filter(([L])=>L!=="outline").map(([L,F])=>`${F} ${L}${F===1?"":Ui[L]??"s"}`).join(", "),W1=`${$.length} part${$.length===1?"":"s"}${L1?`; found ${L1}`:""}.`,E1=[`// ${e.name?e.name+": ":""}imported from an SVG drawing.`,`// ${W1}`,...a.map(L=>`// ${L}`),"",...[...m1].sort().map(L=>`use <kerf/${L}>`),...m1.size?[""]:[]],Z1=[];W!==void 0&&Z1.push(`$thickness = ${k1(W)}; // from the joints`),C>0&&Z1.push(`$kerf = ${k1(C)}; // the drawing's outlines were offset by half of this`),!e.pack&&$.length&&Z1.push('$layout = "none"; // keep the parts where the drawing has them');let o0=[E1.join(`
2623
+ }`;$.push({name:y1,code:z2(P.origin,0,I1),local:I1,thickness:b1})}let X=I8(I.marks,I.lines,I.texts,[0,0]);X.length&&w.length&&a.push("Some lines or marks are outside every part; they are kept on their own.");let j;if(e.pack){let A=new Map;for(let t1 of $){let r1=t1.local.replace(/part\("[^"]*"\)/,"part()"),y1=A.get(r1);y1?y1.qty++:A.set(r1,{name:t1.name,qty:1})}j=[...A.entries()].map(([t1,r1])=>t1.replace("part()",`part("${r1.name.replace(/["\\]/g,"")}"${r1.qty>1?`, qty = ${r1.qty}`:""})`));let F=$.length-A.size;F&&a.push(`${F} part${F===1?" is":"s are"} the same as another and became a quantity.`)}else j=$.map(A=>A.code);let w1=Object.entries(s).filter(([A])=>A!=="outline").map(([A,F])=>`${F} ${A}${F===1?"":_i[A]??"s"}`).join(", "),W1=`${$.length} part${$.length===1?"":"s"}${w1?`; found ${w1}`:""}.`,E1=[`// ${e.name?e.name+": ":""}imported from an SVG drawing.`,`// ${W1}`,...a.map(A=>`// ${A}`),"",...[...p1].sort().map(A=>`use <kerf/${A}>`),...p1.size?[""]:[]],Z1=[];o1!==void 0&&Z1.push(`$thickness = ${S1(o1)}; // from the joints`),S>0&&Z1.push(`$kerf = ${S1(S)}; // the drawing's outlines were offset by half of this`),!e.pack&&$.length&&Z1.push('$layout = "none"; // keep the parts where the drawing has them');let o0=[E1.join(`
2287
2624
  `),Z1.join(`
2288
- `),_.join(`
2625
+ `),j.join(`
2289
2626
 
2290
- `),Z.join(`
2627
+ `),X.join(`
2291
2628
  `)].filter(Boolean).join(`
2292
2629
 
2293
2630
  `).replace(/\n{3,}/g,`
2294
2631
 
2295
2632
  `)+`
2296
- `;try{o0=re(o0)}catch{}return{source:o0,parts:$.length,found:s,summary:W1,notes:a}}var Ui={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},T5=t=>t.trimEnd().endsWith("}")?t:t+";";function Bi(t,e,n,c,r,a){let s=[],i=new Set,o=n>0?e:void 0,l=t.outline.box,h,u;if(o?.kind==="rect"){let{w:k,h:T,r:q}=o.rect;h=u2(o.center,h2([k/2,T/2],o.angle)),h=[P1(h[0]),P1(h[1])],u=w2([0,0],o.angle,`rect(${n0([k,T])}${P1(q)>0?`, r = ${k1(q)}`:""})`),s.push("rectangle")}else o?(h=[P1(o.at[0]),P1(o.at[1])],u=w2(u2(o.at,h),o.angle,o.body),s.push(de[o.kind]),o.library&&i.add(o.library)):(h=[P1(l[0]),P1(l[1])],u=j3(t.sub,h),s.push("outline"));let f=t.holes.map(k=>({...k,found:n>0?k.found:void 0})),d=[],m=k=>u2(k,h),p=k=>k,g=0,v=new Set(f);if(n===2&&!o)for(let k of f){let T=k.found?.circle;if(!T||T.r*2>15)continue;let q=H2(t.outline.poly,!0,.25),R=Math.min(...q.map(Q=>O1(Q,T.c))),U=R-T.r;if(U<.5||q.filter(Q=>Math.abs(O1(Q,T.c)-R)<=a).length*.25<R*Math.PI*.8)continue;let V=[n0(m(T.c))];P1(T.r*2)!==4&&V.push(`d = ${k1(T.r*2)}`),P1(U)!==3&&V.push(`wall = ${k1(U)}`),p=Q=>`hanging_loop(${V.join(", ")}) ${Q}`,g=R,i.add("hanging"),s.push("hanging loop"),v.delete(k);break}if(n===2){let[k,T,q,R]=l,U=(k+q)/2,j=q-k,V=R-T,Q=$=>$[1]>=T+V*.66,W=$=>[...v].filter(Z=>Z.found?.circle&&P1(Z.found.circle.r)===P1($.found.circle.r)).length,o1=[...v].filter($=>$.found?.circle&&$.found.circle.r*2>=1.5&&$.found.circle.r*2<=15&&Q($.found.circle.c)&&W($)<=2),m1=!1;for(let $ of o1){let Z=$.found.circle;if(Math.abs(Z.c[0]-U)>Math.max(.5,j*.02))continue;let _=Z.r*2;d.push(`hanging_hole(${n0(m(Z.c))}${P1(_)!==5?`, d = ${k1(_)}`:""})`),v.delete($),m1=!0;break}if(!m1)for(let $ of o1)for(let Z of o1){if(m1||$===Z)continue;let[_,L1]=[$.found.circle,Z.found.circle];if(Math.abs(_.r-L1.r)>a||Math.abs(_.c[1]-L1.c[1])>a||_.c[0]>=L1.c[0])continue;let W1=[(_.c[0]+L1.c[0])/2,_.c[1]];if(Math.abs(W1[0]-U)>Math.max(1,j*.02))continue;let E1=_.r*2;d.push(`hanging_hole(${n0(m(W1))}${P1(E1)!==5?`, d = ${k1(E1)}`:""}, spacing = ${k1(L1.c[0]-_.c[0])})`),v.delete($),v.delete(Z),m1=!0}m1&&(i.add("hanging"),s.push("hanger hole"));let I=[...v].filter($=>$.found?.kind==="keyhole"&&$.found.library&&Math.abs($.found.angle)<.01);for(let $ of I)for(let Z of I){if(!v.has($)||!v.has(Z)||$===Z)continue;let[_,L1]=[$.found,Z.found];if(_.body!==L1.body||Math.abs(_.at[1]-L1.at[1])>a||_.at[0]>=L1.at[0])continue;let W1=[k1(L1.at[0]-_.at[0])],E1=m([(_.at[0]+L1.at[0])/2,_.at[1]]),Z1=_.body.slice(8,-1);W1.push(P1(E1[0])||P1(E1[1])?`at = ${n0(E1)}`:""),Z1&&W1.push(Z1),d.push(`keyholes(${W1.filter(Boolean).join(", ")})`),v.delete($),v.delete(Z),i.add("hanging"),s.push("keyhole","keyhole")}if(c!==void 0){let $=[...v].filter(Z=>Z.found?.kind==="rect"&&P1(Z.found.rect.r)===0);for(let Z of Gi($,a)){let{items:_,dir:L1,spacing:W1,along:E1,across:Z1}=Z,m0=_.length,o0=c,L=Z1-o0,F=u2(_[0].found.center,[L1[0]*W1/2,L1[1]*W1/2]),t1=Math.atan2(L1[1],L1[0])*180/Math.PI,r1=m0*W1;if(Math.abs(L)<=a&&Math.abs(E1-W1/2)<=a&&m0>=2){let y1=2*m0-1,P=y1*E1,Y=Math.max(3*o0,6),X=(R1,e1)=>{let T1=Math.round(R1/e1);return T1%2===0&&(T1+=R1/e1>T1?1:-1),Math.max(3,T1)};if(X(P,Y)!==y1&&X(P,E1)!==y1)continue;let b1=u2(_[0].found.center,[L1[0]*E1/2,L1[1]*E1/2]),a1=X(P,Y)===y1?"":`, finger = ${k1(E1)}`;d.push(w2(m(b1),t1,`finger_holes(${k1(P)}${a1})`)),s.push("finger joint slot row")}else if(L>=-a&&L<=1){let y1=[k1(r1)];m0!==Math.max(1,Math.round(r1/50))&&y1.push(`count = ${m0}`);let P=E1-L;Math.abs(P-r1/(2*m0))>a&&y1.push(`width = ${k1(P)}`),Math.abs(L-.1)>.001&&y1.push(`clearance = ${k1(L)}`),d.push(w2(m(F),t1,`slots(${y1.join(", ")})`)),i.add("tabs"),s.push("slot row")}else continue;for(let y1 of _)v.delete(y1)}}}let y=[...v].filter(k=>k.found),b=[...v].filter(k=>!k.found);if(n===2){let k=new Map;for(let T of y){let q=w2([0,0],T.found.angle,T.found.body);k.set(q,[...k.get(q)??[],T])}for(let[T,q]of k){let R=ji(q.map(U=>m(U.found.at)),a);if(R){d.push(`${R} ${T}`);for(let U of q)s.push(de[U.found.kind]),U.found.library&&i.add(U.found.library);s.push("hole pattern");for(let U of q)v.delete(U)}}}for(let k of v)k.found&&(d.push(w2(m(k.found.at),k.found.angle,k.found.body)),s.push(de[k.found.kind]),k.found.library&&i.add(k.found.library));for(let k of b)d.push(j3(k.sub,h)),s.push("outline");let x=p(u),M=d.length?[`difference() {
2297
- ${[x,...d].map(T5).join(`
2633
+ `;try{o0=s6(o0)}catch{}return{source:o0,parts:$.length,found:s,summary:W1,notes:a}}var _i={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},V5=t=>t.trimEnd().endsWith("}")?t:t+";";function Gi(t,e,n,c,r,a){let s=[],i=new Set,o=n>0?e:void 0,l=t.outline.box,h,u;if(o?.kind==="rect"){let{w:L,h:I,r:q}=o.rect;h=f2(o.center,u2([L/2,I/2],o.angle)),h=[T1(h[0]),T1(h[1])],u=z2([0,0],o.angle,`rect(${n0([L,I])}${T1(q)>0?`, r = ${S1(q)}`:""})`),s.push("rectangle")}else o?(h=[T1(o.at[0]),T1(o.at[1])],u=z2(f2(o.at,h),o.angle,o.body),s.push(m6[o.kind]),o.library&&i.add(o.library)):(h=[T1(l[0]),T1(l[1])],u=G3(t.sub,h),s.push("outline"));let f=t.holes.map(L=>({...L,found:n>0?L.found:void 0})),d=[],p=L=>f2(L,h),m=L=>L,g=0,v=new Set(f);if(n===2&&!o)for(let L of f){let I=L.found?.circle;if(!I||I.r*2>15)continue;let q=O2(t.outline.poly,!0,.25),R=Math.min(...q.map(J=>F1(J,I.c))),N=R-I.r;if(N<.5||q.filter(J=>Math.abs(F1(J,I.c)-R)<=a).length*.25<R*Math.PI*.8)continue;let V=[n0(p(I.c))];T1(I.r*2)!==4&&V.push(`d = ${S1(I.r*2)}`),T1(N)!==3&&V.push(`wall = ${S1(N)}`),m=J=>`hanging_loop(${V.join(", ")}) ${J}`,g=R,i.add("hanging"),s.push("hanging loop"),v.delete(L);break}if(n===2){let[L,I,q,R]=l,N=(L+q)/2,G=q-L,V=R-I,J=$=>$[1]>=I+V*.66,o1=$=>[...v].filter(X=>X.found?.circle&&T1(X.found.circle.r)===T1($.found.circle.r)).length,Z=[...v].filter($=>$.found?.circle&&$.found.circle.r*2>=1.5&&$.found.circle.r*2<=15&&J($.found.circle.c)&&o1($)<=2),p1=!1;for(let $ of Z){let X=$.found.circle;if(Math.abs(X.c[0]-N)>Math.max(.5,G*.02))continue;let j=X.r*2;d.push(`hanging_hole(${n0(p(X.c))}${T1(j)!==5?`, d = ${S1(j)}`:""})`),v.delete($),p1=!0;break}if(!p1)for(let $ of Z)for(let X of Z){if(p1||$===X)continue;let[j,w1]=[$.found.circle,X.found.circle];if(Math.abs(j.r-w1.r)>a||Math.abs(j.c[1]-w1.c[1])>a||j.c[0]>=w1.c[0])continue;let W1=[(j.c[0]+w1.c[0])/2,j.c[1]];if(Math.abs(W1[0]-N)>Math.max(1,G*.02))continue;let E1=j.r*2;d.push(`hanging_hole(${n0(p(W1))}${T1(E1)!==5?`, d = ${S1(E1)}`:""}, spacing = ${S1(w1.c[0]-j.c[0])})`),v.delete($),v.delete(X),p1=!0}p1&&(i.add("hanging"),s.push("hanger hole"));let E=[...v].filter($=>$.found?.kind==="keyhole"&&$.found.library&&Math.abs($.found.angle)<.01);for(let $ of E)for(let X of E){if(!v.has($)||!v.has(X)||$===X)continue;let[j,w1]=[$.found,X.found];if(j.body!==w1.body||Math.abs(j.at[1]-w1.at[1])>a||j.at[0]>=w1.at[0])continue;let W1=[S1(w1.at[0]-j.at[0])],E1=p([(j.at[0]+w1.at[0])/2,j.at[1]]),Z1=j.body.slice(8,-1);W1.push(T1(E1[0])||T1(E1[1])?`at = ${n0(E1)}`:""),Z1&&W1.push(Z1),d.push(`keyholes(${W1.filter(Boolean).join(", ")})`),v.delete($),v.delete(X),i.add("hanging"),s.push("keyhole","keyhole")}if(c!==void 0){let $=[...v].filter(X=>X.found?.kind==="rect"&&T1(X.found.rect.r)===0);for(let X of ji($,a)){let{items:j,dir:w1,spacing:W1,along:E1,across:Z1}=X,p0=j.length,o0=c,A=Z1-o0,F=f2(j[0].found.center,[w1[0]*W1/2,w1[1]*W1/2]),t1=Math.atan2(w1[1],w1[0])*180/Math.PI,r1=p0*W1;if(Math.abs(A)<=a&&Math.abs(E1-W1/2)<=a&&p0>=2){let y1=2*p0-1,P=y1*E1,Y=Math.max(3*o0,6),W=($1,e1)=>{let I1=Math.round($1/e1);return I1%2===0&&(I1+=$1/e1>I1?1:-1),Math.max(3,I1)};if(W(P,Y)!==y1&&W(P,E1)!==y1)continue;let b1=f2(j[0].found.center,[w1[0]*E1/2,w1[1]*E1/2]),a1=W(P,Y)===y1?"":`, finger = ${S1(E1)}`;d.push(z2(p(b1),t1,`finger_holes(${S1(P)}${a1})`)),s.push("finger joint slot row")}else if(A>=-a&&A<=1){let y1=[S1(r1)];p0!==Math.max(1,Math.round(r1/50))&&y1.push(`count = ${p0}`);let P=E1-A;Math.abs(P-r1/(2*p0))>a&&y1.push(`width = ${S1(P)}`),Math.abs(A-.1)>.001&&y1.push(`clearance = ${S1(A)}`),d.push(z2(p(F),t1,`slots(${y1.join(", ")})`)),i.add("tabs"),s.push("slot row")}else continue;for(let y1 of j)v.delete(y1)}}}let y=[...v].filter(L=>L.found),b=[...v].filter(L=>!L.found);if(n===2){let L=new Map;for(let I of y){let q=z2([0,0],I.found.angle,I.found.body);L.set(q,[...L.get(q)??[],I])}for(let[I,q]of L){let R=Wi(q.map(N=>p(N.found.at)),a);if(R){d.push(`${R} ${I}`);for(let N of q)s.push(m6[N.found.kind]),N.found.library&&i.add(N.found.library);s.push("hole pattern");for(let N of q)v.delete(N)}}}for(let L of v)L.found&&(d.push(z2(p(L.found.at),L.found.angle,L.found.body)),s.push(m6[L.found.kind]),L.found.library&&i.add(L.found.library));for(let L of b)d.push(G3(L.sub,h)),s.push("outline");let x=m(u),M=d.length?[`difference() {
2634
+ ${[x,...d].map(V5).join(`
2298
2635
  `)}
2299
- }`]:[T5(x)],S=t.lines.map(k=>T5(j3(k,h))),w=e?.thickness??c,z=[...[...i].map(k=>`use <kerf/${k}>`),`$thickness = ${w??3};`,`translate(${n0(h)}) {
2300
- ${[...M,...S].join(`
2636
+ }`]:[V5(x)],w=t.lines.map(L=>V5(G3(L,h))),k=e?.thickness??c,z=[...[...i].map(L=>`use <kerf/${L}>`),`$thickness = ${k??3};`,`translate(${n0(h)}) {
2637
+ ${[...M,...w].join(`
2301
2638
  `)}
2302
2639
  }`].join(`
2303
- `),C=Math.max(0,g,o?.radius??0,...f.map(k=>n>0?k.found?.radius??0:0));return{origin:h,round:C,cut:[...M,...S],check:z,found:s,libraries:i,thickness:o?.thickness}}var de={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function Gi(t,e){let n=[],c=new Set,r=s=>{let i=s.found.rect;return`${Math.round((s.found.angle%180+180)%180)}|${P1(i.w)}|${P1(i.h)}`},a=new Map;for(let s of t)a.set(r(s),[...a.get(r(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=h2([1,0],h),m=[-d[1],d[0]],p=s.filter(v=>!c.has(v)),g=new Map;for(let v of p){let y=v.found.center,b=Math.round((y[0]*m[0]+y[1]*m[1])/e),x=[...g.keys()].find(M=>Math.abs(M-b)<=1)??b;g.set(x,[...g.get(x)??[],v])}for(let v of g.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 S=v.slice(b,M+1);for(let w of S)c.add(w);n.push({items:S,dir:d,spacing:x,along:u,across:f})}b=M}}}}return n}function ji(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let p of[...h].sort((g,v)=>g-v))(!u.length||p-u[u.length-1]>e*2)&&u.push(p);if(u.length===1)return;let[f,d]=[P1(u[0]),P1((u[u.length-1]-u[0])/(u.length-1))],m=P1(f+d*(u.length-1));if(!(d<=0||Math.floor((m-f)/d+1e-9)+1!==u.length)&&!u.some((p,g)=>Math.abs(p-(f+g*d))>e))return`[${k1(f)}:${k1(d)}:${k1(m)}]`},c=t.map(h=>h[0]),r=t.map(h=>h[1]),a=h=>new Set(h.map(u=>Math.round(u/(e*2)))).size,s=a(c),i=a(r);if(i===1||s===1){let h=i===1?c:r;if(a(h)!==t.length)return;let u=n(h);return u?i===1?`for (x = ${u}) translate([x, ${k1(r[0])}])`:`for (y = ${u}) translate([${k1(c[0])}, y])`:void 0}if(s*i!==t.length)return;let o=n(c),l=n(r);if(!(!o||!l))return`for (x = ${o}, y = ${l}) translate([x, y])`}function Et(t,e,n,c){let r=[];for(let i of e)r.push(T5(j3(i,c)));let a=new Map,s=(i,o,l)=>{let h=i.name,u=a.get(h)??{layer:i,code:[]};u.code.push(T5(o)+(l?` // ${l}`:"")),a.set(h,u)};for(let[i,o]of t){let l=Tt;if(o.length===1&&o[0].closed){let d=E5(u3(o[0]),o[0]),m=d.area>1e-6?C4(d,l)??E4(d,l)??P4(d,l)??T4(d,l):void 0;if(m){s(i.layer,w2(u2(m.at,c),m.angle,m.body));continue}}if(i.layer.mode!=="fill"||o.every(d=>!d.closed)){for(let d of o)s(i.layer,j3(d,c));continue}let h=fe(o,c),u=o.filter(d=>d.closed).map(d=>u3(d)),f=i.fillRule==="evenodd"||f3(w1(u,"nonzero"),w1(u,"evenodd"),.01);s(i.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let i of n){let o=[JSON.stringify(i.text),`size = ${k1(i.size)}`];i.anchor!=="left"&&o.push(`halign = "${i.anchor}"`),s(i.layer,w2(u2(i.at,c),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}")`;r.push(o.length===1&&!o[0].includes("//")?`${l} ${o[0]}`:`${l} {
2640
+ `),S=Math.max(0,g,o?.radius??0,...f.map(L=>n>0?L.found?.radius??0:0));return{origin:h,round:S,cut:[...M,...w],check:z,found:s,libraries:i,thickness:o?.thickness}}var m6={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function ji(t,e){let n=[],c=new Set,r=s=>{let i=s.found.rect;return`${Math.round((s.found.angle%180+180)%180)}|${T1(i.w)}|${T1(i.h)}`},a=new Map;for(let s of t)a.set(r(s),[...a.get(r(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=u2([1,0],h),p=[-d[1],d[0]],m=s.filter(v=>!c.has(v)),g=new Map;for(let v of m){let y=v.found.center,b=Math.round((y[0]*p[0]+y[1]*p[1])/e),x=[...g.keys()].find(M=>Math.abs(M-b)<=1)??b;g.set(x,[...g.get(x)??[],v])}for(let v of g.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)c.add(k);n.push({items:w,dir:d,spacing:x,along:u,across:f})}b=M}}}}return n}function Wi(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let m of[...h].sort((g,v)=>g-v))(!u.length||m-u[u.length-1]>e*2)&&u.push(m);if(u.length===1)return;let[f,d]=[T1(u[0]),T1((u[u.length-1]-u[0])/(u.length-1))],p=T1(f+d*(u.length-1));if(!(d<=0||Math.floor((p-f)/d+1e-9)+1!==u.length)&&!u.some((m,g)=>Math.abs(m-(f+g*d))>e))return`[${S1(f)}:${S1(d)}:${S1(p)}]`},c=t.map(h=>h[0]),r=t.map(h=>h[1]),a=h=>new Set(h.map(u=>Math.round(u/(e*2)))).size,s=a(c),i=a(r);if(i===1||s===1){let h=i===1?c:r;if(a(h)!==t.length)return;let u=n(h);return u?i===1?`for (x = ${u}) translate([x, ${S1(r[0])}])`:`for (y = ${u}) translate([${S1(c[0])}, y])`:void 0}if(s*i!==t.length)return;let o=n(c),l=n(r);if(!(!o||!l))return`for (x = ${o}, y = ${l}) translate([x, y])`}function I8(t,e,n,c){let r=[];for(let i of e)r.push(V5(G3(i,c)));let a=new Map,s=(i,o,l)=>{let h=i.name,u=a.get(h)??{layer:i,code:[]};u.code.push(V5(o)+(l?` // ${l}`:"")),a.set(h,u)};for(let[i,o]of t){let l=V8;if(o.length===1&&o[0].closed){let d=I5(u3(o[0]),o[0]),p=d.area>1e-6?T4(d,l)??I4(d,l)??E4(d,l)??V4(d,l):void 0;if(p){s(i.layer,z2(f2(p.at,c),p.angle,p.body));continue}}if(i.layer.mode!=="fill"||o.every(d=>!d.closed)){for(let d of o)s(i.layer,G3(d,c));continue}let h=p6(o,c),u=o.filter(d=>d.closed).map(d=>u3(d)),f=i.fillRule==="evenodd"||f3(x1(u,"nonzero"),x1(u,"evenodd"),.01);s(i.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let i of n){let o=[JSON.stringify(i.text),`size = ${S1(i.size)}`];i.anchor!=="left"&&o.push(`halign = "${i.anchor}"`),s(i.layer,z2(f2(i.at,c),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}")`;r.push(o.length===1&&!o[0].includes("//")?`${l} ${o[0]}`:`${l} {
2304
2641
  ${o.join(`
2305
2642
  `)}
2306
- }`)}return r}function _i(t,e,n){let c;try{c=new D3({maxSteps:2e6}).run(r2(t.check).program).shape}catch{return!1}let r=c.layers.get("cut");if(!r)return!1;let a=y0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=w1(r.regions),i=n+t.round*16e-5;if(!f3(a,s,i))return!1;let o=e.lines.map(l=>u3(l));return!(o.length&&!f3(o,r.lines,i,!1))}var B=.001,J1=(t,e)=>t.reduce((n,c,r)=>n+c*e[r],0),p1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],x1=t=>Math.hypot(...t),Ht=t=>[t[2],t[6],t[10]],i0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]+t[n*4+3]),me=(t,e)=>$1(S0(t.matrix),e.matrix);function d3(t){let[e,n]=t[0],c=0;for(let r=1;r<t.length-1;r++)c+=(t[r][0]-e)*(t[r+1][1]-n)-(t[r][1]-n)*(t[r+1][0]-e);return c/2}var Y2=t=>Math.abs(t.reduce((e,n)=>e+d3(n),0)),pe=t=>t.reduce((e,n)=>e+n.reduce((c,r,a)=>c+Math.hypot(r[0]-n[(a+1)%n.length][0],r[1]-n[(a+1)%n.length][1]),0),0);function I4(t){let e=t.flat();return[Math.min(...e.map(n=>n[0])),Math.min(...e.map(n=>n[1])),Math.max(...e.map(n=>n[0])),Math.max(...e.map(n=>n[1]))]}var Ot=([t,e,n,c])=>[[t,e],[n,e],[n,c],[t,c]];function ge(t){if(t.length!==1)return!1;let e=I4(t);return Y2(M3(t,[Ot(e)]))<B*B}var ve=(t,e)=>b0(t,[Ot(e)]);function Rt(t,e,n=0){let c=e[0]*e[5]-e[1]*e[4]<0;return t.map(r=>{let a=r.map(([s,i])=>i0(e,[s,i,n]).slice(0,2));return c?a.reverse():a})}function Wi(t,e){let n=!1;for(let c=0,r=t.length-1;c<t.length;r=c++){let[a,s]=t[c],[i,o]=t[r];s>e[1]!=o>e[1]&&e[0]<(i-a)*(e[1]-s)/(o-s)+a&&(n=!n)}return n}function W3(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?Math.max(0,Math.min(1,((t[0]-e[0])*c+(t[1]-e[1])*r)/a)):0;return Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}function Ft(t,e){let n=1/0;for(let c of t)for(let r=0;r<e.length;r++)n=Math.min(n,W3(c,e[r],e[(r+1)%e.length]));for(let c of e)for(let r=0;r<t.length;r++)n=Math.min(n,W3(c,t[r],t[(r+1)%t.length]));return n}var ye=(t,e)=>t.filter(n=>d3(n)<0&&Wi(n,e));function X3(t){return t.placed?t.bends.length?"Flexible or bent geometry is not supported by this rigid check.":t.cutLines===null?"Nominal cutting-line geometry is unavailable; render with analysis: true.":t.cutLines.length?"Open cutting lines may remove or weaken material; this rigid check cannot model them.":null:"The part has no physical placement."}function $t(t){return[0,1,2,4,5,6,8,9,10].every(e=>Math.abs(t[e])<1e-9||Math.abs(Math.abs(t[e])-1)<1e-9)}function V4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&It(t.regions)===It(e.regions)&&Vt(t.cutLines)===Vt(e.cutLines)}function It(t){let e=n=>{let c=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,r=[c,[...c].reverse()].map(a=>{let s=0;for(let i=1;i<a.length;i++)(a[i][0]<a[s][0]||a[i][0]===a[s][0]&&a[i][1]<a[s][1])&&(s=i);return JSON.stringify([...a.slice(s),...a.slice(0,s)])});return JSON.stringify([Math.sign(d3(n)),r.sort()[0]])};return JSON.stringify(t.map(e).sort())}function Vt(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),c=JSON.stringify([...e].reverse());return n<c?n:c}).sort())}var D1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),g0=t=>typeof t=="string"&&t.length>0,z2=t=>typeof t=="number"&&Number.isFinite(t),R2=t=>z2(t)&&t>=0,F2=t=>z2(t)&&t>0,m3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(z2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,g3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(z2),f2=t=>g3(t,3)&&t.every(e=>Math.abs(e)<=1e7),J2=t=>D1(t)&&g0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),H4=t=>D1(t)&&g0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),Z3=t=>J2(t)||H4(t),O2=t=>Array.isArray(t)&&t.every(Z3),p3=t=>f2(t)&&Math.hypot(...t)>1e-9,Xi=t=>D1(t)&&(t.kind==="translate"&&f2(t.by)||t.kind==="rotate"&&f2(t.origin)&&p3(t.axis)&&z2(t.angle)&&Math.abs(t.angle)<=1e6),be=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),Dt=t=>D1(t)&&Object.values(t).every(be),Nt=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||z2(t)||Array.isArray(t)&&t.every(n=>Nt(n,e+1))),xe=t=>D1(t)&&Object.values(t).every(e=>Nt(e)),Zi=t=>t===null||D1(t)&&be(t.sourceHash)&&be(t.engineHash)&&Dt(t.dependencies)&&Dt(t.fonts);function I5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!D1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let c=(s,i,o)=>{for(let l of Object.keys(s))i.includes(l)||n(o?`${o}.${l}`:l,"Unknown specification field.")};c(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),g0(t.model)||n("model","Give the model a nonempty name.");let r=new Set,a=(s,i)=>{if(!D1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!D1(l)||!m3(l.thickness,Number.MIN_VALUE)||!m3(l.kerf)||l.edgeError!==void 0&&!R2(l.edgeError)||l.lot!==void 0&&!g0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),D1(l)&&c(l,["thickness","kerf","edgeError","lot"],`${i}.${o}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[s,i]of t.configurations.entries())!D1(i)||!g0(i.id)||i.params!==void 0&&!xe(i.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):r.has(i.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(r.add(i.id),c(i,["id","params","materials"],`configurations[${s}]`),i.materials!==void 0&&a(i.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,i=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!D1(h)||!g0(h.id)||!g0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(c(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),s.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),s.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&i++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(m=>typeof m=="string"&&r.has(m)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!J2(h.a)||!J2(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!F2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!J2(h.tab)||!J2(h.receiver)||!g3(h.region,4)||h.region.some(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!m3(h.clearance)||!R2(h.flushTolerance)||!R2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let m=h.stops;if(!H4(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(J2)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(J2)||!m3(h.clearance)||!m3(h.endplay)||!F2(h.minimumOverlap)||!R2(h.maximumStopGap)||!Array.isArray(m)||m.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let p of m){if(!D1(p)||!H4(p.body)||!D1(p.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}c(p,["body","attachment"],u+".stops");let g=p.attachment;c(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!H4(g.thread)||!F2(g.minimumEngagement)||typeof g.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!R2(h.minimumGap)||h.bodies!==void 0&&(!O2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!g0(h.from)||!r.has(h.from)||!g0(h.to)||!r.has(h.to)||h.from===h.to||!R2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(m=>D1(m)&&Z3(m.body)&&Xi(m.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!g0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!O2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!O2(h.scope)||!h.scope.length)||!R2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(m=>D1(m)&&g0(m.id)&&Z3(m.part)&&f2(m.from)&&typeof m.held=="boolean"&&(m.fasten===void 0||Array.isArray(m.fasten)&&m.fasten.every(g0))&&(m.tool===void 0||D1(m.tool)&&f2(m.tool.from)&&f2(m.tool.to)&&F2(m.tool.diameter)&&m.tool.diameter<=1e6&&f2(m.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!O2(h.roots)||!h.roots.length||h.removable!==void 0&&!O2(h.removable)||!Array.isArray(h.links)||!h.links.every(m=>D1(m)&&g0(m.claim)&&["glued","locked","captured"].includes(m.fastening)&&typeof m.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!O2(h.bodies)||!h.bodies.length||!O2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(m=>D1(m)&&Z3(m.a)&&Z3(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&f2(m.anchorA)&&f2(m.anchorB)&&p3(m.axisA)&&p3(m.axisB)&&(m.range===void 0||m3(m.range,-1e6))||m.kind==="prismatic"&&p3(m.axisA)&&m3(m.travel,-1e6)||m.kind==="gear"&&p3(m.axisA)&&p3(m.axisB)&&F2(m.ratio)&&m.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!O2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!z2(h.ground)||Math.abs(h.ground)>1e7||!p3(h.gravity)||h.gravity[2]>=0||!R2(h.minimumMargin)||!h.loads.every(m=>D1(m)&&Z3(m.body)&&F2(m.mass)&&(m.center===void 0||f2(m.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!g0(h.plan)||!g0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(m=>D1(m)&&g0(m.step)&&O2(m.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(m,p,g)=>{D1(m)&&c(m,p,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[m,p]of h.moving.entries())D1(p)&&(d(p,["body","trajectory"],`${u}.moving[${m}]`),d(p.trajectory,D1(p.trajectory)&&p.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${m}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[m,p]of h.steps.entries())D1(p)&&(d(p,["id","part","from","held","fasten","tool"],`${u}.steps[${m}]`),d(p.tool,["from","to","diameter","travel"],`${u}.steps[${m}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[m,p]of h.joints.entries())D1(p)&&d(p,["kind","a","b",...p.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:p.kind==="prismatic"?["axisA","travel"]:p.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${m}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((m,p)=>d(m,["claim","fastening","installed"],`${u}.links[${p}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((m,p)=>d(m,["body","mass","center"],`${u}.loads[${p}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((m,p)=>d(m,["step","bodies"],`${u}.holds[${p}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(D1);for(let l of o){let h=(u,f)=>o.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=o.find(p=>p.id===l.plan&&p.kind==="assembly-access"),f=o.find(p=>p.id===l.retention&&p.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(D1).map(p=>p.id)),m=new Set((Array.isArray(f?.links)?f.links:[]).filter(D1).map(p=>p.claim));if(Array.isArray(l.holds))for(let p of l.holds)D1(p)&&!d.has(p.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(p.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let p of u.steps)if(D1(p)&&Array.isArray(p.fasten))for(let g of p.fasten)m.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(p.id)} fastens ${String(g)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(D1(f)){let d=D1(f.body)?f.body:{},m=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(m)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(m)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)D1(u)&&!o.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function Me(t){let e=[],n=(r,a)=>e.push({code:"invalid-snapshot",path:r,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let c=new Set;for(let[r,a]of t.entries()){let s=`snapshots[${r}]`;if(!D1(a)||a.schemaVersion!==1||!g0(a.configuration)||!xe(a.params)||!xe(a.renderSettings)||!Zi(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(o=>typeof o=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}c.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),c.add(a.configuration);let i=new Set;for(let[o,l]of a.parts.entries()){if(!D1(l)||!g0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!F2(l.thickness)||l.glue!==void 0&&(!J2(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!g0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!R2(l.kerf)||l.kerf>1e6)||!Yi(l.matrix)||typeof l.placed!="boolean"||!qt(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!qt(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>D1(u)&&z2(u.x0)&&z2(u.x1)&&u.x1>u.x0&&z2(u.angle))){n(`${s}.parts[${o}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);i.has(h)&&n(`${s}.parts[${o}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),i.add(h)}for(let[o,l]of a.hardware.entries())(!D1(l)||l.label!==null&&!g0(l.label)||typeof l.kind!="string"||!g3(l.from,3)||!g3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!f2(l.up)||!(F2(l.size)&&l.size<=1e6||g3(l.size,2)&&l.size.every(h=>F2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function qt(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(c=>g3(c,2)&&c.every(r=>Math.abs(r)<=1e6)))}function Yi(t){if(!g3(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(c=>Math.abs(c)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let c=0;c<3;c++)for(let r=0;r<3;r++){let a=e[c]*e[r]+e[4+c]*e[4+r]+e[8+c]*e[8+r];if(Math.abs(a-(c===r?1:0))>n)return!1}return Math.abs(e[0]*(e[5]*e[10]-e[6]*e[9])-e[1]*(e[4]*e[10]-e[6]*e[8])+e[2]*(e[4]*e[9]-e[5]*e[8])-1)<n}function Ut(t){let e=[];for(let n of t.claims){let c=r=>e.push({claim:n.id,ref:r});n.kind==="glue-contact"&&(c(n.a),c(n.b)),n.kind==="tab-slot"&&(c(n.tab),c(n.receiver)),n.kind==="captured-shaft"&&(c(n.shaft),n.bearings.forEach(c),n.stack.forEach(c),n.stops.forEach(r=>{c(r.body),r.attachment.kind==="threaded"&&c(r.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(c),n.kind==="motion-clearance"&&n.moving.forEach(r=>c(r.body)),n.kind==="assembly-access"&&(n.initial.forEach(c),n.scope?.forEach(c),n.steps.forEach(r=>c(r.part))),n.kind==="retention"&&(n.roots.forEach(c),n.removable?.forEach(c)),n.kind==="joint-constraints"&&(n.bodies.forEach(c),n.roots.forEach(c),n.joints.forEach(r=>{c(r.a),c(r.b)})),n.kind==="stability"&&(n.supports.forEach(c),n.loads.forEach(r=>c(r.body))),n.kind==="assembly-support"&&n.holds?.forEach(r=>r.bodies.forEach(c))}return e}var Z0=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),k2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var Q1=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),c1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),Le=(t,e,n=[],c="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:c}),H5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,V5=(t,e)=>H5(t,e)?.thickness??[e.thickness,e.thickness];function R4(t,e){let n=H5(t,e);return n?e.kerf===null?[-1/0,1/0]:[e.kerf-n.kerf[1]-2*(n.edgeError??0),e.kerf-n.kerf[0]+2*(n.edgeError??0)]:[0,0]}var ke=(t,e)=>t[0]>=e[0]+B&&t[1]<=e[1]-B,Se=(t,e)=>t[0]<e[0]-B||t[1]>e[1]+B,Ae=(...t)=>t.map(X3).find(Boolean);function $4(t,e){let n=Z0(e,t.a),c=Z0(e,t.b);if(n===c)return Q1("A glue contact needs two different physical instances.");let r=Ae(n,c);if(r)return c1(r);let a=me(n,c),s=t.faceA==="top"?n.thickness:0,i=t.faceB==="top"?c.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return Q1("The selected faces are not parallel.");let o=Math.abs(a[11]+a[10]*i-s);if(o>B)return Q1("The selected faces are separated.",{faceGap:o});if(o>1e-7)return c1("Face separation is within numerical uncertainty; exact contact is not established.");let l=t.faceA==="top"?1:-1,h=t.faceB==="top"?1:-1;if(l*h*a[10]>-1+1e-7)return Q1("The selected surfaces face the same way, rather than meeting.");let u=Rt(c.regions,a,i),f=Y2(b0(n.regions,u)),d=B*(pe(n.regions)+pe(u)),m={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?Q1("There is insufficient geometric glue contact.",m):f<t.minimumArea+d?{...c1("Contact area is on the numerical acceptance boundary."),measurements:m}:Le("The selected nominal faces have the required geometric contact.",m,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function Bt(t,e,n){let c=Z0(e,t.tab),r=Z0(e,t.receiver);if(c===r)return Q1("A tongue and its receiving panel must be different instances.");let a=Ae(c,r);if(a)return c1(a);let s=me(r,c);if(!$t(s)||Math.abs(s[10])>B)return c1("Only orthogonal tab/slot geometry is supported.");let i=ve(c.regions,t.region);if(!ge(i))return c1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=I4(i),f=4*B,d=B,p=[[o-f,l+d,o,u-d],[h,l+d,h+f,u-d],[o+d,l-f,h-d,l],[o+d,u,h-d,u+f]].map(V=>Y2(ve(c.regions,V))>B*B).flatMap((V,Q)=>V?[Q]:[]);if(p.length>1)return c1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(p.length&&Math.abs(p[0]<2?s[8]:s[9])<.5)return c1("The tongue must join its parent along the insertion direction.");let g;if(p.length){let V=p[0],Q=V<2?[V===0?o:h,(l+u)/2,0]:[(o+h)/2,V===2?l:u,0],W=i0(s,Q)[2],o1=(V<2?s[8]:s[9])*(V%2===0?-1:1);g={z:W,outward:o1}}let v=[];for(let V of[o,h])for(let Q of[l,u])for(let W of[0,c.thickness])v.push(i0(s,[V,Q,W]));let y=[0,1,2].map(V=>Math.min(...v.map(Q=>Q[V]))),b=[0,1,2].map(V=>Math.max(...v.map(Q=>Q[V]))),x=ye(r.regions,[(y[0]+b[0])/2,(y[1]+b[1])/2]);if(!x.length)return Q1("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!ge([x[0]]))return c1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],S=I4([M]),w=R4(n,c),z=R4(n,r);if(![...w,...z].every(Number.isFinite))return c1("Compensated kerf metadata is needed for manufacturing bounds.");let C={},k=!1;for(let V=0;V<2;V++){let Q=Math.abs(s[V*4+2])>.5,W=Q?V5(n,c):[b[V]-y[V]+w[0],b[V]-y[V]+w[1]],o1=S[V+2]-S[V],m1=[o1-z[1]-W[1],o1-z[0]-W[0]];if(C[V?"clearanceY":"clearanceX"]=m1,Se(m1,t.clearance))return Q1("Tab/slot clearance is outside the required range.",C);k||(k=!ke(m1,t.clearance));let I=y[V],$=b[V];Q?s[V*4+2]>0?$+=W[1]-c.thickness:I-=W[1]-c.thickness:(I-=Math.max(0,w[1])/2,$+=Math.max(0,w[1])/2);let Z=Math.min(I-S[V],S[V+2]-$)-Math.max(0,z[1])/2;if(C[V?"minimumSideGapY":"minimumSideGapX"]=Z,Z<-B)return Q1("The tongue is offset into the edge of its slot.",C);Z<B&&(k=!0)}let T=Math.max(0,-w[0])/2,q=V5(n,r);if(t.flushTolerance>=q[0]-B)return c1("flushTolerance must be smaller than the receiving thickness.");let R=Math.max(0,Math.min(b[2]-T,q[1])-Math.max(y[2]+T,0)),U=q[1]-t.flushTolerance;if(C.engagement=R,C.requiredEngagement=U,R<=B)return Q1("The tongue does not engage the receiving panel.",C);if(R<U-B)return Q1("The tongue does not engage through the receiving panel.",C);if(R<U+B&&(k=!0),g&&(g.outward>0&&g.z<q[1]-B||g.outward<0&&g.z>B))return Q1("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",C);let j=Math.min(...r.regions.filter(V=>V!==M).map(V=>Ft(M,V)))-Math.max(0,-z[0]);return C.minimumLigament=j,j<t.minimumLigament-B?Q1("Too little material remains around the slot.",C):(j<t.minimumLigament+B&&(k=!0),k?{...c1("A fit condition is on its numerical acceptance boundary."),measurements:C}:Le("The rectangular tongue fits and engages its receiving slot.",C,["Rigid orthogonal parts; nominal placements are held fixed while finished dimensions vary.","The selected local rectangle must identify the physical tongue; this fit does not establish retention."],H5(n,c)||H5(n,r)?"bounded-fit":"nominal"))}function O4(t){let e=p1(t.to,t.from),n=x1(e);return typeof t.size=="number"&&n>B?{start:t.from,dir:e.map(c=>c/n),length:n,diameter:t.size}:null}function we(t,e){let n=O4(e);if(!n||x1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let c=p1(n.start,t.start),r=J1(c,t.dir);return x1(c.map((a,s)=>a-r*t.dir[s]))<B}var F4=(t,e)=>J1(p1(e,t.start),t.dir),ze=(t,e)=>[F4(t,e.from),F4(t,e.to)].sort((n,c)=>n-c);function Ji(t,e){let n=Ht(e.matrix);if(J1(n,t.dir)<0||x1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let c=i0(S0(e.matrix),t.start),r=[c[0],c[1]],a=ye(e.regions,r);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],i=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,o=[i.reduce((m,p)=>m+p[0],0)/i.length,i.reduce((m,p)=>m+p[1],0)/i.length];if(Math.hypot(o[0]-r[0],o[1]-r[1])>B)return"The shaft is not centered in the bore.";let l=s.map(m=>Math.hypot(m[0]-o[0],m[1]-o[1]));if(Math.max(...l)-Math.min(...l)>B)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((m,p)=>W3(r,m,s[(p+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-r[0],m[1]-r[1]))),f=F4(t,i0(e.matrix,[0,0,0])),d=F4(t,i0(e.matrix,[0,0,e.thickness]));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u]}}function Gt(t,e,n){let c=k2(e,t.shaft),r=O4(c);if(!r)return c1("The shaft must have a nonzero cylindrical physical envelope.");let a=[...t.bearings,...t.stack],s=a.map(x=>JSON.stringify([x.part,x.copy??1]));if(new Set(s).size!==s.length)return Q1("Bearing and stack references must name distinct physical parts.");let i=a.map(x=>Z0(e,x)),o=Ae(...i);if(o)return c1(o);let l={shaftDiameter:r.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],S=Ji(r,M);if(typeof S=="string")return/unsupported|supported/.test(S)?c1(`${M.name}: ${S}`):Q1(`${M.name}: ${S}`);let w=R4(n,M);if(!w.every(Number.isFinite))return c1("Kerf metadata is required for bore tolerance bounds.");let z=[S.hole[0]-w[1]-r.diameter,S.hole[1]-w[0]-r.diameter];if(l[`clearance${x+1}`]=z,Se(z,t.clearance))return Q1(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!ke(z,t.clearance)),S.lo<-B||S.lo+V5(n,M)[1]>r.length+B)return Q1(`${M.name}: the shaft does not extend through this part.`,l);h.push(S)}let f=h.slice(0,2).sort((x,M)=>x.lo-M.lo),d=h.slice(2).sort((x,M)=>x.lo-M.lo);if(f.some(x=>V5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>B)))return c1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-B)return Q1("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-B||d[x].hi>f[1].lo+B||x&&d[x-1].hi>d[x].lo+B)return Q1("The axial stack overlaps another component or its supports.");let m=f[1].lo-f[0].lo,g=[f[0].part,...d.map(x=>x.part)].map(x=>V5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[m-g[1],m-g[0]];if(l.endplay=v,Se(v,t.endplay))return Q1("The axial stack has insufficient or excessive endplay.",l);u||(u=!ke(v,t.endplay));let y=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],b=t.stops.map(x=>({stop:x,h:k2(e,x.body)})).map(x=>({...x,at:x.h&&we(r,x.h)?ze(r,x.h):void 0}));if(b.some(x=>!x.at))return Q1("A retainer is not coaxial with the shaft.");b.sort((x,M)=>x.at[0]+x.at[1]-(M.at[0]+M.at[1]));for(let x=0;x<2;x++){let{stop:M,h:S}=b[x];if(!we(r,S))return Q1("A retainer is not coaxial with the shaft.");let w=O4(S),z=ze(r,S),C=f[x],k=x===0?z[1]:z[0],T=x===0?C.lo:C.hi,q=x===0?T-k:k-T;l[`stopGap${x+1}`]=q;let R=R4(n,C.part),U=(w.diameter-(C.hole[1]-R[0]))/2;if(l[`stopOverlap${x+1}`]=U,q<-B||q>t.maximumStopGap+B)return Q1("A retainer is misplaced relative to the outside bearing face.",l);if((q<-1e-7||q>t.maximumStopGap+1e-7)&&(u=!0),U<t.minimumOverlap-B)return Q1("A retainer can pass through its bearing opening.",l);U<t.minimumOverlap+B&&(u=!0);let j=M.attachment;if(j.kind==="unknown")return{...c1("The stop is present but its fastening is unverified."),measurements:l};if(j.kind==="integral"){if(Math.min(Math.abs(k),Math.abs(k-r.length))>B)return Q1("An integral head must meet an end of its shaft.",l);y.push("The specified head and shaft are one integral purchased component.")}else{let V=k2(e,j.thread);if(!we(r,V))return Q1("The threaded attachment is off the shaft axis.");if(O4(V).diameter>r.diameter+B)return Q1("The declared threaded section exceeds the shaft envelope.");let Q=ze(r,V),W=Math.max(0,Math.min(z[1],Q[1])-Math.max(z[0],Q[0]));if(Q[0]<-B||Q[1]>r.length+B)return Q1("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=W,W<j.minimumEngagement-B)return Q1("The threaded stop has insufficient declared thread engagement.",l);if(W<j.minimumEngagement+B&&(u=!0),!j.secured)return{...c1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};y.push("The specified usable thread envelope and matching nut are installed and secured as declared; thread form/capacity and resistance to loosening are not verified.")}}return u?{...c1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:Le("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>H5(n,x))?"bounded-fit":"nominal")}var q4=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},u1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),T0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],v0=(t,e)=>t.map(n=>n*e),Wt=(t,e)=>t.map((n,c)=>n+e[c]),_1=t=>v0(t,1/x1(t)),Xt=()=>D0(0,0,0);function Ce(t,e){let n=c=>c.kind==="translate"?x1(c.by)<1e-9:Math.abs(c.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?x1(p1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?x1(p1(v0(_1(t.axis),t.angle),v0(_1(e.axis),e.angle)))<1e-9&&x1(T0(p1(t.origin,e.origin),_1(t.axis)))<1e-9:!1}function Ki(t,e){let n=new Map;for(let c of e)for(let r=0;r<c.length;r++){let a=c[r],s=c[(r+1)%c.length],i=a<s?[a,s]:[s,a];n.set(i.join(","),i)}return{vertices:t,faces:e,edges:[...n.values()]}}function D4(t,e,n){let c=t.length,r=[];for(let a of[0,e])for(let[s,i]of t)r.push(i0(n,[s,i,a]));return Ki(r,[t.map((a,s)=>s).reverse(),t.map((a,s)=>c+s),...t.map((a,s)=>[s,(s+1)%c,(s+1)%c+c,s+c])])}function Qi(t,e){let n=w1(t),c=[...new Set(n.flat().map(i=>i[0]))].sort((i,o)=>i-o),r=n.flatMap(i=>i.map((o,l)=>({a:o,b:i[(l+1)%i.length]}))),a=[],s=(i,o)=>i.a[1]+(o-i.a[0])*(i.b[1]-i.a[1])/(i.b[0]-i.a[0]);for(let i=1;i<c.length;i++){let o=c[i-1],l=c[i],h=(o+l)/2;e.tick(r.length);let u=r.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],m=u[f+1],p=[[o,s(d,o)],[l,s(d,l)],[l,s(m,l)],[o,s(m,o)]],g=p.filter((v,y)=>x1([v[0]-p[(y+1)%p.length][0],v[1]-p[(y+1)%p.length][1],0])>1e-10);if(g.length<3||Math.abs(d3(g))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(a.push(g),a.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!a.length||Math.abs(Y2(a)-Y2(n))>B*B*Math.max(1,Y2(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function v3(t){if(t.hardware.some(n=>!n.label))throw new Error("Physical hardware needs unique labels for whole-inventory checks.");let e=[...t.parts.map(n=>({part:n.name,copy:n.copy})),...t.hardware.map(n=>({hardware:n.label}))];if(new Set(e.map(u1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function c0(t,e){if("part"in e)return Z0(t,e).matrix;let n=k2(t,e),c=_1(p1(n.to,n.from));if(!x1(p1(n.to,n.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let r=p1(n.up,v0(c,J1(n.up,c)));if(x1(r)<1e-9){if(Array.isArray(n.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let s=Math.abs(c[0])<.8?[1,0,0]:[0,1,0];r=p1(s,v0(c,J1(s,c)))}r=_1(r);let a=T0(r,c);return[a[0],r[0],c[0],n.from[0],a[1],r[1],c[1],n.from[1],a[2],r[2],c[2],n.from[2],0,0,0,1]}function K2(t,e,n){if(n.tick(),"part"in e){let o=Z0(t,e),l=X3(o);if(l)throw new Error(l);let u=Qi(o.regions,n).map(f=>D4(f,o.thickness,o.matrix));return{ref:e,outer:u,inner:u}}let c=k2(t,e),r=c0(t,e),a=x1(p1(c.to,c.from));if(a<B)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(c.size)){let[o,l]=c.size,h=[[-o/2,-l/2],[o/2,-l/2],[o/2,l/2],[-o/2,l/2]],u=[D4(h,a,r)];return{ref:e,outer:u,inner:u}}let s=32,i=o=>Array.from({length:s},(l,h)=>[o*Math.cos(h*2*Math.PI/s),o*Math.sin(h*2*Math.PI/s)]);return{ref:e,inner:[D4(i(c.size/2),a,r)],outer:[D4(i(c.size/2/Math.cos(Math.PI/s)),a,r)]}}function N4(t,e){let n=r=>r.map(a=>({...a,vertices:a.vertices.map(s=>i0(e,s))})),c=n(t.outer);return{ref:t.ref,outer:c,inner:t.inner===t.outer?c:n(t.inner)}}function y3(t,e){if(t.kind==="translate")return D0(...v0(t.by,e));let[n,c,r]=_1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),i=Math.sin(a),o=1-s,l=[s+n*n*o,n*c*o-r*i,n*r*o+c*i,0,c*n*o+r*i,s+c*c*o,c*r*o-n*i,0,r*n*o-c*i,r*c*o+n*i,s+r*r*o,0,0,0,0,1];return $1(D0(...t.origin),$1(l,D0(...v0(t.origin,-1))))}function Pe(t,e){if(e.kind==="translate")return x1(e.by);let n=_1(e.axis),c=0;for(let r of t.outer)for(let a of r.vertices){let s=p1(a,e.origin);c=Math.max(c,x1(p1(s,v0(n,J1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*c}function jt(t){return t.faces.map(e=>T0(p1(t.vertices[e[1]],t.vertices[e[0]]),p1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>x1(e)>1e-12).map(_1)}function Zt(t,e){let n=[...jt(t),...jt(e)];for(let[c,r]of t.edges)for(let[a,s]of e.edges){let i=T0(p1(t.vertices[r],t.vertices[c]),p1(e.vertices[s],e.vertices[a]));x1(i)>1e-12&&n.push(_1(i))}return n}var Y3=(t,e)=>{let n=t.vertices.map(c=>J1(c,e));return[Math.min(...n),Math.max(...n)]};function eo(t,e,n){let c=-1/0;for(let r of Zt(t,e)){n.tick();let a=Y3(t,r),s=Y3(e,r);c=Math.max(c,s[0]-a[1],a[0]-s[1])}return c}function to(t,e){let n=0;for(let c=0;c<3;c++){let r=t.vertices.map(i=>i[c]),a=e.vertices.map(i=>i[c]),s=Math.max(0,Math.min(...a)-Math.max(...r),Math.min(...r)-Math.max(...a));n+=s*s}return Math.sqrt(n)}function no(t,e,n,c){let r=p1(n,e),a=p1(c,e),s=p1(t,e),i=J1(r,s),o=J1(a,s);if(i<=0&&o<=0)return x1(s);let l=p1(t,n),h=J1(r,l),u=J1(a,l);if(h>=0&&u<=h)return x1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return x1(p1(s,v0(r,i/(i-h))));let d=p1(t,c),m=J1(r,d),p=J1(a,d);if(p>=0&&m<=p)return x1(d);let g=m*o-i*p;if(g<=0&&o>=0&&p<=0)return x1(p1(s,v0(a,o/(o-p))));let v=h*p-m*u;if(v<=0&&u-h>=0&&m-p>=0)return x1(p1(l,v0(p1(c,n),(u-h)/(u-h+m-p))));let y=v+g+f;if(Math.abs(y)<1e-20)return 1/0;let b=Math.max(0,Math.min(1,g/y)),x=Math.max(0,Math.min(1-b,f/y));return x1(p1(s,Wt(v0(r,b),v0(a,x))))}function co(t,e,n,c){let r=p1(e,t),a=p1(c,n),s=p1(t,n),i=J1(r,r),o=J1(r,a),l=J1(a,a),h=J1(r,s),u=J1(a,s);if(i<1e-20||l<1e-20)return 1/0;let f=i*l-o*o,d=f>1e-20?Math.max(0,Math.min(1,(o*u-l*h)/f)):0,m=(o*d+u)/l;return m<0&&(m=0,d=Math.max(0,Math.min(1,-h/i))),m>1&&(m=1,d=Math.max(0,Math.min(1,(o-h)/i))),x1(Wt(s,p1(v0(r,d),v0(a,m))))}function ro(t,e,n){let c=1/0;for(let[r,a]of[[t,e],[e,t]])for(let s of r.vertices)for(let i of a.faces)for(let o=1;o<i.length-1;o++)n.tick(),c=Math.min(c,no(s,a.vertices[i[0]],a.vertices[i[o]],a.vertices[i[o+1]]));for(let[r,a]of t.edges)for(let[s,i]of e.edges)n.tick(),c=Math.min(c,co(t.vertices[r],t.vertices[a],e.vertices[s],e.vertices[i]));return c}function _t(t,e,n,c){let r=1/0,a=1/0,s=!1,i=!0;for(let o of t)for(let l of e){n.tick();let h=to(o,l);if(h>Math.min(a,c)){r=Math.min(r,h);continue}let u=eo(o,l,n);u<-B&&(s=!0),u<0&&(i=!1),r=Math.min(r,Math.max(0,h,u)),u<-B?a=0:u<=Math.min(a,c)&&(a=Math.min(a,ro(o,l,n)))}return{lower:r,upper:a,penetration:s,touchSafe:i}}function U4(t,e,n,c){let r=_t(t.outer,e.outer,n,c+B),a=t.outer===t.inner&&e.outer===e.inner;if(r.lower>c+B)return{lower:r.lower-B,upper:1/0,penetration:!1,touchSafe:!0};let s=a?r:_t(t.inner,e.inner,n,1/0);return{lower:Math.max(0,r.lower-B),upper:s.upper+B,penetration:s.penetration,touchSafe:r.touchSafe}}function Yt(t,e,n,c,r,a){for(let s=0;s<t.outer.length;s++)for(let i=0;i<n.outer.length;i++){let o=t.outer[s],l=n.outer[i],h=e.outer[s],u=c.outer[i],f=!1;for(let d of Zt(o,l)){a.tick();let m=Y3(o,d),p=Y3(l,d),g=Y3(h,d),v=Y3(u,d);if(Math.min(p[0]-m[1],v[0]-g[1])>=r||Math.min(m[0]-p[1],g[0]-v[1])>=r){f=!0;break}}if(!f)return!1}return!0}function B4(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let c={part:n.name,copy:n.copy},r=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(r>1&&(n.copy-1)%r!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:c,faceA:a?"bottom":"top",faceB:a?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:c,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var d2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),O5=(t,e)=>t.every((n,c)=>Math.abs(n-e[c])<B);function Jt(t,e,n){if(new Set(e.map(u1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(c=>K2(t,c,n))}function Kt(t,e,n){let c=Jt(e,t.bodies??v3(e),n);if(c.length<2)return c1("Rigid clearance requires at least two physical bodies.");let r=1/0;for(let a=0;a<c.length;a++)for(let s=a+1;s<c.length;s++){let i=U4(c[a],c[s],n,t.minimumGap);if(r=Math.min(r,i.lower),i.penetration||i.upper<t.minimumGap-B)return d2("Physical bodies interfere or violate the required clearance.",{gapUpper:i.upper},[c[a].ref,c[s].ref]);if(!(i.lower>t.minimumGap||t.minimumGap===0&&i.touchSafe))return{...c1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[c[a].ref,c[s].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:r},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function Ee(t,e,n,c,r=1e3){let a=o=>({solid:o,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let o=0;o<t.length;o++){for(let l of e)yield{a:t[o],b:a(l)};for(let l=o+1;l<t.length;l++)yield{a:t[o],b:t[l]}}}let i=0;for(let{a:o,b:l}of s()){c.tick();let h=(d,m)=>N4(d.solid,y3(d.trajectory,m));if(Ce(o.trajectory,l.trajectory)){let d=U4(o.solid,l.solid,c,n);if(d.penetration||d.upper<n-B)return d2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[o.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...c1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&Yt(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+B,c))continue;let u=Pe(o.solid,o.trajectory)+Pe(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>r)return{...c1("Continuous clearance interval budget exhausted."),measurements:{intervals:i},entities:[o.solid.ref,l.solid.ref]};c.tick();let[d,m]=f.shift(),p=(d+m)/2,g=u*(m-d)/2,v=U4(h(o,p),h(l,p),c,n+g);if(v.penetration||v.upper<n-B)return d2("The specified path has physical interference.",{phase:p,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(m-d<1e-9)return{...c1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,m]},entities:[o.solid.ref,l.solid.ref]};f.push([d,p],[p,m])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function ao(t,e){if(t.parts.length!==e.parts.length||t.hardware.length!==e.hardware.length)return"The physical inventory changes between motion endpoints.";for(let n of t.parts){let c=e.parts.find(r=>r.name===n.name&&r.copy===n.copy);if(!c||n.cutLines===null||c.cutLines===null||!V4(n,c))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([c.stack,c.glue,c.glueFace,c.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let c=e.hardware.find(r=>r.label===n.label);if(!n.label||!c||n.kind!==c.kind||JSON.stringify(n.size)!==JSON.stringify(c.size)||Math.abs(x1(p1(n.to,n.from))-x1(p1(c.to,c.from)))>B)return"Hardware identities and dimensions must remain invariant."}return null}function Qt(t,e,n,c,r=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return c1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=ao(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=v3(e),i=new Set(t.moving.map(l=>u1(l.body)));if(i.size!==t.moving.length)return d2("A body has conflicting simultaneous trajectories.");let o=l=>t.moving.find(h=>u1(h.body)===u1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...B4(e),...r]){let h=$1(S0(c0(e,l.a)),c0(e,l.b)),u=$1(S0(c0(n,l.a)),c0(n,l.b));if(!O5(h,u)||!Ce(o(l.a),o(l.b)))return d2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>u1(f.body)===u1(l))?.trajectory,u=h?y3(h,1):Xt();if("part"in l){if(!O5($1(u,c0(e,l)),c0(n,l)))return d2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=k2(e,l),d=k2(n,l);if(typeof f.size=="number"){if(!O5(i0(u,f.from),d.from)||!O5(i0(u,f.to),d.to))return d2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!O5($1(u,c0(e,l)),c0(n,l)))return d2("A box trajectory does not match its rendered destination.",{},[l])}}return Ee(t.moving.map(l=>({solid:K2(e,l.body,c),trajectory:l.trajectory})),Jt(e,s.filter(l=>!i.has(u1(l))),c),t.minimumGap,c,t.maxIntervals)}function e9(t,e,n){let c=t.scope??v3(e),r=new Set(c.map(u1)),a=new Map(t.initial.map(o=>[u1(o),K2(e,o,n)]));if(r.size!==c.length||a.size!==t.initial.length||t.initial.some(o=>!r.has(u1(o))))return d2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,i=0;for(let o of t.steps){if(s.has(o.id)||!r.has(u1(o.part))||a.has(u1(o.part)))return d2("An assembly step duplicates or misidentifies a required installation.");if(s.add(o.id),!o.held)return{...c1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=K2(e,o.part,n),h=N4(l,y3({kind:"translate",by:o.from},1)),u=Ee([{solid:h,trajectory:{kind:"translate",by:o.from.map(f=>-f)}}],[...a.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:o.id,message:`Assembly step ${o.id}: ${u.message}`};if(i+=u.measurements?.intervals??0,a.set(u1(o.part),l),o.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:o.tool.from,to:o.tool.to,size:o.tool.diameter,up:[0,1,0]}]},m=K2(d,{hardware:f},n),p=N4(m,y3({kind:"translate",by:o.tool.travel},1)),g=Ee([{solid:p,trajectory:{kind:"translate",by:o.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:o.id,message:`Tool access at step ${o.id}: ${g.message}`}}}return a.size!==r.size?d2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:a.size,intervals:i},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var K1=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),U0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),F0=t=>[t[3],t[7],t[11]],Te=t=>{let e=_1(t),n=_1(T0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,T0(e,n)]},G4=(t,e,n)=>{let c=Te(n)[0],r=_1(U0(e,c)),a=_1(U0(t,c)),s=_1(U0(e,n));return Math.atan2(J1(s,T0(r,a)),J1(r,a))*180/Math.PI},t9=(t,e,n)=>{let c=[],r=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let i=r;i<=a&&c.length<64;i++)c.push(t+360*i);let s=(e[0]+e[1])/2;return c.sort((i,o)=>Math.abs(i-s)-Math.abs(o-s))};function n9(t,e){if(t?.kind==="glue-contact"&&e==="glued")return[t.a,t.b];if(t?.kind==="captured-shaft"&&e==="captured"){let n=[t.shaft,...t.bearings,...t.stack,...t.stops.map(c=>c.body)];for(let c of t.stops)c.attachment.kind==="threaded"&&n.push(c.attachment.thread);return n}}function c9(t,e,n,c){let r=v3(e),a=new Set(r.map(u1));for(let f of t.removable??[])a.delete(u1(f));if(t.roots.some(f=>!a.has(u1(f))))return K1("A retention root cannot be excluded as removable.");let s=new Map,i=f=>{for(let d of f)for(let m of f){let p=u1(d),g=s.get(p)??new Set;g.add(u1(m)),s.set(p,g)}},o=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(g=>g.id===f.claim),m=c.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!m)return c1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(m.status==="fail")return K1(`Attachment ${f.claim} fails its geometric contract.`);if(m.status!=="pass")return c1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return K1(`The fastening for ${f.claim} is explicitly not installed.`);let p=n9(d,f.fastening);if(!p)return c1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(p),d.kind==="glue-contact"&&o.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(u1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=r.filter(f=>a.has(u1(f))&&!l.has(u1(f)));return u.length?{...K1("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:a.size,removableComponents:t.removable?.length??0},assumptions:o}}function so(t,e){if("hardware"in e){let i=c0(t,e),o=t.hardware.find(l=>l.label===e.hardware);return i0(i,[0,0,x1(p1(o.to,o.from))/2])}let n=Z0(t,e),c=X3(n);if(c)throw new Error(c);let r=0,a=0,s=0;for(let i of n.regions){let[o,l]=i[0],h=0,u=0,f=0;for(let m=0;m<i.length;m++){let p=i[m],g=i[(m+1)%i.length],v=p[0]-o,y=p[1]-l,b=g[0]-o,x=g[1]-l,M=v*x-b*y;h+=M,u+=(v+b)*M,f+=(y+x)*M}if(Math.abs(h)<1e-12)continue;let d=d3(i);r+=d,a+=(o+u/(3*h))*d,s+=(l+f/(3*h))*d}if(r<=B*B)throw new Error("Material centroid is numerically unresolved.");return i0(n.matrix,[a/r,s/r,n.thickness/2])}function io(t){let e=[...t].sort((s,i)=>s[0]-i[0]||s[1]-i[1]),n=(s,i,o)=>(i[0]-s[0])*(o[1]-s[1])-(i[1]-s[1])*(o[0]-s[0]),c=s=>{let i=[];for(let o of s){for(;i.length>1&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return i},r=c(e),a=c([...e].reverse());return[...r.slice(0,-1),...a.slice(0,-1)]}function oo(t,e,n){let c=new Map,r=i=>{for(let o of i)for(let l of i){let h=c.get(u1(o))??new Set;h.add(u1(l)),c.set(u1(o),h)}};for(let i of t.links){let o=n9(e.claims.find(l=>l.id===i.claim),i.fastening);o&&r(o)}if(!n.length)return!0;let a=new Set([u1(n[0])]),s=[...a];for(;s.length;)for(let i of c.get(s.pop())??[])a.has(i)||(a.add(i),s.push(i));return n.every(i=>a.has(u1(i)))}function r9(t,e,n,c=[],r){let a=v3(e),s=t.loads.map(p=>u1(p.body));if(new Set(s).size!==s.length||a.some(p=>!s.includes(u1(p))))return c1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let p=c.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=r?.claims.find(v=>v.id===t.retention);if(!p||p.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return c1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!oo(g,r,a))return c1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let i=0,o=[0,0,0];for(let p of t.loads){let g=p.center?i0(c0(e,p.body),p.center):so(e,p.body);i+=p.mass,o=o.map((v,y)=>v+p.mass*g[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return c1("Mass/centroid calculation exceeds its numerical range.");o=v0(o,1/i);let l=[];for(let p of a){let g=K2(e,p,n),v=Math.min(...g.inner.flatMap(b=>b.vertices.map(x=>x[2]))),y=Math.min(...g.outer.flatMap(b=>b.vertices.map(x=>x[2])));if(v<t.ground-B)return K1("A physical component penetrates the ground plane.");if(y<t.ground-B)return c1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(b=>u1(b)===u1(p))){if(Math.abs(v-t.ground)>1e-8)return c1("Ground contact is separated or within physical-envelope uncertainty.");for(let b of g.inner)for(let x of b.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=io(l);if(h.length<3)return c1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-o[2])/t.gravity[2],f=[o[0]+u*t.gravity[0],o[1]+u*t.gravity[1]],d=1/0;for(let p=0;p<h.length;p++){let g=h[p],v=h[(p+1)%h.length],y=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),b=W3(f,g,v);d=Math.min(d,y<0?-b:b)}let m={supportMargin:d,mass:i,centerX:o[0],centerY:o[1],centerZ:o[2]};return d<t.minimumMargin-B?K1("The gravity line lies outside the required support margin.",m):d<t.minimumMargin+B?{...c1("Stability is on its numerical support boundary."),measurements:m}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:m,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function a9(t,e,n,c){let r=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>c.find(m=>m.id===d&&m.configurations.includes(e.configuration));if(!r||r.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return c1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return c1("Per-step support of removable objects needs an explicit contact model.");let i=new Set(a.roots.map(u1)),o=new Set(r.initial.map(u1));if(r.initial.some(d=>!i.has(u1(d))))return c1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let m=n.claims.find(p=>p.id===d.claim);if(m?.kind==="glue-contact")l.set(d.claim,[m.a,m.b]);else if(m?.kind==="captured-shaft"){let p=[m.shaft,...m.bearings,...m.stack,...m.stops.map(g=>g.body)];m.stops.forEach(g=>{g.attachment.kind==="threaded"&&p.push(g.attachment.thread)}),l.set(d.claim,p)}}let h=new Set,u=new Set(r.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return K1("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let g of h)for(let v of l.get(g)??[])for(let y of l.get(g)??[]){let b=d.get(u1(v))??new Set;b.add(u1(y)),d.set(u1(v),b)}let m=new Set([...i].filter(g=>o.has(g))),p=[...m];for(;p.length;)for(let g of d.get(p.pop())??[])m.has(g)||(m.add(g),p.push(g));return m};for(let d of r.steps){o.add(u1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return K1(`Step ${d.id} names an unknown fastening.`);if(v.some(y=>!o.has(u1(y))))return K1(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let m=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(u1));if([...m].some(g=>!o.has(g)))return K1(`Step ${d.id} holds an uninstalled body.`);let p=f();if([...o].some(g=>!p.has(g)&&!m.has(g)))return K1(`Step ${d.id} releases a component before it is retained or supported.`)}return[...o].some(d=>!f().has(d))?K1("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function lo(t){let e=t.map(r=>{let a=Math.max(...r.map(Math.abs),1e-20);return r.map(s=>s/a)}),n=0,c=!1;for(let r=0;r<(e[0]?.length??0)&&n<e.length;r++){let a=n;for(let o=n+1;o<e.length;o++)Math.abs(e[o][r])>Math.abs(e[a][r])&&(a=o);let s=Math.abs(e[a][r]);if(s<1e-10)continue;s<1e-7&&(c=!0),[e[n],e[a]]=[e[a],e[n]];let i=e[n][r];for(let o=r;o<e[n].length;o++)e[n][o]/=i;for(let o=n+1;o<e.length;o++){let l=e[o][r];for(let h=r;h<e[o].length;h++)e[o][h]-=l*e[n][h]}n++}return{rank:n,uncertain:c}}function s9(t,e,n,c,r,a=[]){if(t.bodies.length>64)return c1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(u1),i=t.roots.map(u1);if(new Set(s).size!==s.length||new Set(i).size!==i.length||i.some(v=>!s.includes(v)))return K1("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>c0(e,v).some((y,b)=>Math.abs(y-c0(n,v)[b])>B)))return K1("A grounded kinematic root changes pose.");let o=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,y,b,x,M=1)=>{let S=s.indexOf(u1(y));if(S<0)throw new Error("A joint references a body outside its scope.");for(let w=0;w<3;w++)v[S*6+b+w]+=M*x[w]};for(let v of t.roots)for(let y=0;y<6;y++){let b=h();b[s.indexOf(u1(v))*6+y]=1,o.push(b)}let f=B4({...e,parts:e.parts.filter(v=>s.includes(u1({part:v.name,copy:v.copy})))});for(let v of r?.claims??[])if(v.kind==="retention")for(let y of v.links){let b=r.claims.find(x=>x.id===y.claim);y.installed&&y.fastening==="glued"&&b?.kind==="glue-contact"&&a.some(x=>x.id===b.id&&x.configurations.includes(e.configuration)&&x.status==="pass")&&f.push({a:b.a,b:b.b})}for(let v of f)if(!(!s.includes(u1(v.a))&&!s.includes(u1(v.b)))){if(!s.includes(u1(v.a))||!s.includes(u1(v.b)))return c1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=$4({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:B*B*4},e);if(y.status!=="pass")return{...y,message:`A native glue/stack bond is not physically established: ${y.message}`}}}let d=[...t.joints,...f.filter(v=>s.includes(u1(v.a))&&s.includes(u1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(c.tick(),u1(v.a)===u1(v.b))return K1("A joint cannot connect a body to itself.");let y=c0(e,v.a),b=c0(e,v.b),x=c0(n,v.a),M=c0(n,v.b),S=$1(S0(y),b),w=$1(S0(x),M),z=k=>{let T=h();u(T,v.b,3,k),u(T,v.a,3,k,-1),o.push(T)},C=(k,T,q)=>{let R=h();u(R,v.b,0,k),u(R,v.a,0,k,-1),u(R,v.b,3,T0(q,k)),u(R,v.a,3,T0(T,k),-1),o.push(R)};if(v.kind==="fixed"){if(S.some((k,T)=>Math.abs(k-w[T])>B))return K1("A fixed joint changes its relative transform.");l.forEach(k=>z(k)),l.forEach(k=>C(k,p1(F0(b),F0(y)),[0,0,0]))}else if(v.kind==="revolute"){let k=i0(y,v.anchorA),T=i0(b,v.anchorB),q=_1(U0(y,v.axisA)),R=_1(U0(b,v.axisB)),U=J1(_1(U0(x,v.axisA)),_1(U0(M,v.axisB)));if(x1(p1(k,T))>B||x1(T0(q,R))>1e-7||Math.abs(J1(q,R)-U)>1e-7)return K1("Revolute anchors or axes do not coincide.");if(v.range){let j=G4(S,w,v.axisB);if(!t9(j,v.range,B).length)return K1("A revolute joint exceeds its declared angular travel.",{angle:j})}l.forEach(j=>C(j,p1(k,F0(y)),p1(T,F0(b)))),Te(q).forEach(z)}else if(v.kind==="prismatic"){let k=p1(F0(S),F0(w)),T=_1(v.axisA),q=J1(k,T);if([0,1,2,4,5,6,8,9,10].some(R=>Math.abs(S[R]-w[R])>B)||x1(p1(k,v0(T,q)))>B)return K1("A slider rotates or moves away from its guide axis.");if(q<v.travel[0]-B||q>v.travel[1]+B)return K1("The slider exceeds its allowed travel.",{travel:q});l.forEach(z),Te(_1(U0(y,v.axisA))).forEach(R=>C(R,p1(F0(b),F0(y)),[0,0,0]))}else{let k=_1(U0(y,v.axisA)),T=_1(U0(b,v.axisB));if(x1(T0(k,T))>1e-7||x1(p1(F0(y),F0(x)))>B||x1(p1(F0(b),F0(M)))>B)return K1("The scoped gear axes/centers are not fixed and parallel.");let q=G4(y,x,v.axisA),R=G4(b,M,v.axisB);if(Math.abs(q)>90||Math.abs(R)>90)return c1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(R+v.ratio*q)>1e-6)return K1("The rendered gears do not obey their declared angular ratio.");let U=h();u(U,v.a,3,k,v.ratio),u(U,v.b,3,T),o.push(U)}}c.tick(o.length*s.length*6);let m=lo(o),p=s.length*6-m.rank;if(m.uncertain)return c1("Constraint rank is numerically singular.");let g={degreesOfFreedom:p,constraintRank:m.rank,redundantRows:o.length-m.rank};return p!==t.expectedDof?K1("The joint graph has unintended freedom or is overconstrained.",g):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:g,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function i9(t,e,n,c){let r=o=>t.moving.find(l=>u1(l.body)===u1(o))?.trajectory??{kind:"translate",by:[0,0,0]},a=o=>o.kind==="translate"?x1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?x1(p1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?x1(p1(v0(_1(o.axis),o.angle),v0(_1(l.axis),l.angle)))<1e-9&&x1(T0(p1(o.origin,l.origin),_1(o.axis)))<1e-9:!1;if(e.roots.some(o=>!a(r(o))))return K1("The analytic path moves a grounded joint root.");let i=new Map;for(let o of e.joints.filter(l=>l.kind!=="gear")){if(i.has(u1(o.b)))return c1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");i.set(u1(o.b),u1(o.a))}for(let o of i.keys()){let l=new Set,h=o;for(;h&&i.has(h);){if(l.has(h))return c1("Continuous closed-linkage constraints need a solver.");l.add(h),h=i.get(h)}}for(let o of e.joints){let l=r(o.a),h=r(o.b),u=c0(n,o.a),f=c0(n,o.b);if(o.kind==="fixed"){if(!s(l,h))return K1("The analytic path separates a fixed joint.");continue}if(o.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return c1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=i0(u,o.anchorA),m=_1(U0(u,o.axisA)),p=_1(h.axis);if(x1(T0(m,p))>1e-9||x1(T0(p1(h.origin,d),m))>B)return K1("The trajectory does not rotate about the actual hinge.");if(o.range){let g=$1(S0(u),f),v=$1(S0(c0(c,o.a)),c0(c,o.b)),y=h.angle*J1(_1(U0(f,o.axisB)),p),b=o.range;if(!t9(G4(g,v,o.axisB),b,B).some(M=>Math.min(M,M+y)>=b[0]-B&&Math.max(M,M+y)<=b[1]+B))return K1("The continuous hinge path exceeds its angular stops.")}}else if(o.kind==="prismatic"){if(s(l,h))continue;if(!a(l)||h.kind!=="translate")return c1("This slider trajectory composition needs a richer constraint solver.");let d=_1(U0(u,o.axisA));if(x1(T0(h.by,d))>B)return K1("The analytic slider path leaves its guide.");let m=$1(S0(u),f),p=$1(S0(c0(c,o.a)),c0(c,o.b)),g=J1(p1(F0(m),F0(p)),_1(o.axisA)),v=g+J1(h.by,d);if(Math.min(g,v)<o.travel[0]-B||Math.max(g,v)>o.travel[1]+B)return K1("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,y)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let b=c0(n,g),x=_1(U0(b,y));return x1(T0(_1(v.axis),x))>1e-9||x1(T0(p1(v.origin,F0(b)),x))>B?null:v.angle*J1(_1(v.axis),x)},m=d(o.a,l,o.axisA),p=d(o.b,h,o.axisB);if(m===null||p===null)return c1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(p+o.ratio*m)>1e-7)return K1("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function o9(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return l9(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(c=>{let r=n?.parts.filter(l=>l.name===c.name),a=r?.length===1?r[0]:void 0,s=a?.glue?.host,o=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((c.copy-1)/(a?.stack??1))+1:1;return{name:c.name,copy:c.copy,thickness:c.thickness,material:c.material??"",matrix:c.matrix,placed:c.placed,regions:a?.cutRegions??c.outline,bends:c.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:o},glueFace:a.glue.face},...a?.on&&{on:a.on}}}),hardware:t.hardware.map(c=>({label:c.label??null,kind:c.kind,from:c.from,to:c.to,size:c.size,up:c.up})),warnings:t.warnings,legacyHardware:t.echoes.some(c=>c.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function l9(t){if(t&&typeof t=="object"){for(let e of Object.values(t))l9(e);Object.freeze(t)}return t}function h9(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let c=I5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(c.length)throw new Error(c[0].message);let r=new Map;for(let a of e){let s=a.body,i=u1(s);if(("part"in s?t.assembly.filter(l=>l.name===s.part&&l.copy===(s.copy??1)).length:t.hardware.filter(l=>l.label===s.hardware).length)!==1||r.has(i))throw new Error("Pose controls must identify one unique physical instance each.");r.set(i,y3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=r.get(u1({part:a.name,copy:a.copy}));return s?{...a,matrix:$1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},i=r.get(u1(s));return i?{...a,from:i0(i,a.from),to:i0(i,a.to),up:p1(i0(i,a.up),i0(i,[0,0,0]))}:a})}}function ho(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==B||I5(e).length||Me(n).length||n.some(r=>r.error!==void 0||!r.provenance)||!Array.isArray(t.inputs))return!1;let c=r=>JSON.stringify(r,(a,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.fromEntries(Object.keys(s).sort().map(i=>[i,s[i]])):s);try{let r=n.map(s=>({configuration:s.configuration,params:s.params,renderSettings:s.renderSettings,provenance:s.provenance})),a=s=>[...s].sort((i,o)=>i.configuration.localeCompare(o.configuration));return c(e)===c(t.specification)&&c(a(r))===c(a(t.inputs))}catch{return!1}}function uo(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let c=I5(t);if(c.length)return{kind:"invalid-spec",issues:c};let r=Me(e);if(r.length)return{kind:"invalid-snapshot",issues:r};let a=t,s=e,i=[];for(let[g,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(g)||!Number.isSafeInteger(v)||!(v>0))&&i.push({code:"invalid-limits",path:`limits.${g}`,message:"Verification limits must be positive safe integers."});if(i.length)return{kind:"invalid-spec",issues:i};let o={schemaVersion:1,model:a.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:B,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.map(g=>({configuration:g.configuration,params:g.params,renderSettings:g.renderSettings,provenance:g.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(s.reduce((g,v)=>g+v.hardware.reduce((y,b)=>y+(typeof b.size=="number"?128:8),0)+v.parts.reduce((y,b)=>y+b.regions.reduce((x,M)=>x+M.length,0)+(b.cutLines??[]).reduce((x,M)=>x+M.length,0),0),0)>(n.maxPoints??2e5)||a.claims.length>(n.maxClaims??1e3)||a.configurations.length>(n.maxConfigurations??100))return o.claims.push(Q2("$resource-limit","resource-limit",!0,[],{status:"unverified",code:"resource-limit",message:"The verification input exceeds its point, claim or configuration budget. No mechanical conclusions were reached."})),{kind:"report",report:o};let h=new Set(a.configurations.map(g=>g.id));for(let g of s)h.has(g.configuration)||i.push({code:"unknown-configuration",message:`Snapshot ${g.configuration} is not declared.`});for(let g of s){let v=a.configurations.find(y=>y.id===g.configuration)?.params??{};for(let[y,b]of Object.entries(v))JSON.stringify(g.params[y])!==JSON.stringify(b)&&i.push({code:"configuration-mismatch",message:`${g.configuration}: captured parameter ${y} differs from its required value.`})}let u=new Map(a.claims.map(g=>[g.id,g]));for(let{claim:g,ref:v}of Ut(a)){let y=u.get(g);for(let b of s.filter(x=>x.error===void 0&&(!y.configurations||y.configurations.includes(x.configuration)))){let x="part"in v?b.parts.filter(M=>M.name===v.part&&M.copy===(v.copy??1)):b.hardware.filter(M=>M.label===v.hardware);x.length!==1&&i.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${b.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(i.length)return{kind:"invalid-spec",issues:i};for(let g of a.configurations){let v=s.find(b=>b.configuration===g.id),y=v&&v.error===void 0;o.claims.push(Q2(`$configuration:${g.id}`,"configuration",!0,[g.id],y?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),y&&(o.claims.push(Q2(`$provenance:${g.id}`,"provenance",!0,[g.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&o.claims.push(Q2(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
2307
- `)})),v.legacyHardware&&o.claims.push(Q2(`$legacy:${g.id}`,"hardware-inventory",!0,[g.id],{status:"unverified",code:"legacy-hardware",message:"echo hardware is not authoritative physical inventory. Migrate it to native hardware before verification."})))}let f=new q4(n.maxOperations),d=g=>g.kind==="retention"?3:g.kind==="stability"||g.kind==="assembly-support"?4:g.kind==="motion-clearance"||g.kind==="assembly-access"?2:g.kind==="joint-constraints"?1:0,m=[...a.claims].sort((g,v)=>d(g)-d(v));for(let g of m){let v=g.configurations??a.configurations.map(y=>y.id);if(g.kind==="cut-invariant"){let y=v.map(b=>s.find(x=>x.configuration===b));o.claims.push(Q2(g.id,g.kind,g.required!==!1,v,y.some(b=>!b||b.error!==void 0)?c1("A required configuration is unavailable."):fo(y)));continue}if(g.kind==="motion-clearance"){let y=s.find(M=>M.configuration===g.from),b=s.find(M=>M.configuration===g.to),x;if(!y||!b||y.error!==void 0||b.error!==void 0)x=c1("Motion endpoints are unavailable.");else try{if(x={status:"pass"},g.constraints){let M=a.claims.find(w=>w.id===g.constraints),S=o.claims.filter(w=>w.id===g.constraints);if(!M||M.kind!=="joint-constraints"||!S.length||S.some(w=>w.status!=="pass")||![g.from,g.to].every(w=>S.some(z=>z.configurations.includes(w))))x=c1("The motion needs verified endpoint joint constraints.");else{let w=s.find(z=>z.configuration===(M.configurations??a.configurations.map(C=>C.id))[0]);x=i9(g,M,y,w)}}if(x.status==="pass"){let M=[];for(let S of a.claims)if(S.kind==="retention")for(let w of S.links){let z=a.claims.find(C=>C.id===w.claim);w.installed&&w.fastening==="glued"&&z?.kind==="glue-contact"&&[g.from,g.to].every(C=>o.claims.some(k=>k.id===z.id&&k.configurations.includes(C)&&k.status==="pass"))&&M.push({a:z.a,b:z.b})}x=Qt(g,y,b,f,M)}}catch(M){x={status:"unverified",code:"geometry-unresolved",message:M.message}}o.claims.push(Q2(g.id,g.kind,g.required!==!1,[g.from,g.to],x,u9(g)));continue}for(let y of v){let b=s.find(w=>w.configuration===y),x=a.configurations.find(w=>w.id===y)?.materials,M=x?{...a,materials:{...a.materials,...x}}:a,S;if(!b||b.error!==void 0)S=c1("The configuration is unavailable.");else try{switch(g.kind){case"glue-contact":S=$4(g,b);break;case"tab-slot":S=Bt(g,b,M);break;case"captured-shaft":S=Gt(g,b,M);break;case"material-assignment":S=mo(b,M);break;case"rigid-clearance":S=Kt(g,b,f);break;case"assembly-access":S=e9(g,b,f);break;case"joint-constraints":{let w=s.find(z=>z.configuration===v[0]);S=w&&w.error===void 0?s9(g,b,w,f,a,o.claims):c1("The kinematic reference configuration is unavailable.");break}case"retention":S=c9(g,b,a,o.claims);break;case"stability":S=r9(g,b,f,o.claims,a);break;case"assembly-support":S=a9(g,b,a,o.claims);break;default:S=c1(`The ${g.kind} capability is not implemented; it cannot inherit a geometric-fit pass.`)}}catch(w){S={status:"unverified",code:"geometry-unresolved",message:`The geometric check could not complete: ${w.message}`}}o.claims.push(Q2(g.id,g.kind,g.required!==!1,[y],S,u9(g)))}}let p=o.claims.filter(g=>g.required);o.status=p.some(g=>g.status==="fail")?"fail":p.some(g=>g.status==="unverified")?"unverified":"pass";for(let[g,v]of[["retention","Retention of permanent inventory."],["stability","Static stability under declared masses and gravity."],["assembly-access","Authored insertion and tool access paths."],["assembly-support","Support throughout the installation sequence."],["motion-clearance","Continuous nominal operating motion clearance."],["joint-constraints","Mechanism constraints and intended mobility."]]){let y=o.claims.filter(x=>x.kind===g&&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 Q2(t,e,n,c,r,a=[]){return{id:t,kind:e,required:n,configurations:c,status:"unverified",code:"unverified",message:"",entities:a,measurements:{},assumptions:[],coverage:"none",...r}}function u9(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 fo(t){if(t.length<2)return c1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return c1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(c=>c.cutLines===null||c.kerf===null)))return c1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(c=>!c.label)))return c1("Cross-pose hardware requires unique native labels.");for(let n of t){let c=n.hardware.map(r=>r.label);if(new Set(c).size!==c.length)return c1("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 r of e.parts){let a=Z0(n,{part:r.name,copy:r.copy});if(!a||!V4(r,a))return{status:"fail",code:"cut-geometry-changed",message:`Operating motion changed cut geometry/material for ${r.name} copy ${r.copy}.`}}for(let r of e.hardware){let a=n.hardware.find(s=>s.label===r.label);if(!a||r.kind!==a.kind||JSON.stringify(r.size)!==JSON.stringify(a.size)||Math.abs(x1(p1(r.to,r.from))-x1(p1(a.to,a.from)))>B)return{status:"fail",code:"hardware-changed",message:`Operating motion changed hardware ${r.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 mo(t,e){if(!t.parts.length)return c1("There are no sheet parts to assign a stock profile.");for(let n of t.parts){let c=e.materials&&Object.prototype.hasOwnProperty.call(e.materials,n.material)?e.materials[n.material]:void 0;if(!c)return c1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<c.thickness[0]-B||n.thickness>c.thickness[1]+B)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return c1("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 po=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function f9(t){if(t.kind!=="report")return[];let e=new Map;for(let c of t.report.claims){if(c.status==="pass")continue;let r=`${c.status}\0${c.code}`,a=e.get(r)??{status:c.status,code:c.code,message:c.message,claims:[]};a.claims.push({id:c.id,configurations:c.configurations,bodies:c.entities.map(po),measurements:c.measurements}),e.set(r,a)}let n=c=>c==="fail"?0:1;return[...e.values()].sort((c,r)=>n(c.status)-n(r.status)||r.claims.length-c.claims.length)}function go(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(r=>r.message).join("; ")}
2308
- `;let e=f9(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
2643
+ }`)}return r}function Xi(t,e,n){let c;try{c=new D3({maxSteps:2e6}).run(a2(t.check).program).shape}catch{return!1}let r=c.layers.get("cut");if(!r)return!1;let a=b0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=x1(r.regions),i=n+t.round*16e-5;if(!f3(a,s,i))return!1;let o=e.lines.map(l=>u3(l));return!(o.length&&!f3(o,r.lines,i,!1))}var B=.001,J1=(t,e)=>t.reduce((n,c,r)=>n+c*e[r],0),m1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],M1=t=>Math.hypot(...t),R8=t=>[t[2],t[6],t[10]],i0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]+t[n*4+3]),g6=(t,e)=>O1(L0(t.matrix),e.matrix);function d3(t){let[e,n]=t[0],c=0;for(let r=1;r<t.length-1;r++)c+=(t[r][0]-e)*(t[r+1][1]-n)-(t[r][1]-n)*(t[r+1][0]-e);return c/2}var Y2=t=>Math.abs(t.reduce((e,n)=>e+d3(n),0)),v6=t=>t.reduce((e,n)=>e+n.reduce((c,r,a)=>c+Math.hypot(r[0]-n[(a+1)%n.length][0],r[1]-n[(a+1)%n.length][1]),0),0);function H4(t){let e=t.flat();return[Math.min(...e.map(n=>n[0])),Math.min(...e.map(n=>n[1])),Math.max(...e.map(n=>n[0])),Math.max(...e.map(n=>n[1]))]}var F8=([t,e,n,c])=>[[t,e],[n,e],[n,c],[t,c]];function y6(t){if(t.length!==1)return!1;let e=H4(t);return Y2(M3(t,[F8(e)]))<B*B}var b6=(t,e)=>x0(t,[F8(e)]);function $8(t,e,n=0){let c=e[0]*e[5]-e[1]*e[4]<0;return t.map(r=>{let a=r.map(([s,i])=>i0(e,[s,i,n]).slice(0,2));return c?a.reverse():a})}function Zi(t,e){let n=!1;for(let c=0,r=t.length-1;c<t.length;r=c++){let[a,s]=t[c],[i,o]=t[r];s>e[1]!=o>e[1]&&e[0]<(i-a)*(e[1]-s)/(o-s)+a&&(n=!n)}return n}function W3(t,e,n){let c=n[0]-e[0],r=n[1]-e[1],a=c*c+r*r,s=a?Math.max(0,Math.min(1,((t[0]-e[0])*c+(t[1]-e[1])*r)/a)):0;return Math.hypot(t[0]-e[0]-s*c,t[1]-e[1]-s*r)}function D8(t,e){let n=1/0;for(let c of t)for(let r=0;r<e.length;r++)n=Math.min(n,W3(c,e[r],e[(r+1)%e.length]));for(let c of e)for(let r=0;r<t.length;r++)n=Math.min(n,W3(c,t[r],t[(r+1)%t.length]));return n}var x6=(t,e)=>t.filter(n=>d3(n)<0&&Zi(n,e));function X3(t){return t.placed?t.bends.length?"Flexible or bent geometry is not supported by this rigid check.":t.cutLines===null?"Nominal cutting-line geometry is unavailable; render with analysis: true.":t.cutLines.length?"Open cutting lines may remove or weaken material; this rigid check cannot model them.":null:"The part has no physical placement."}function q8(t){return[0,1,2,4,5,6,8,9,10].every(e=>Math.abs(t[e])<1e-9||Math.abs(Math.abs(t[e])-1)<1e-9)}function O4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&H8(t.regions)===H8(e.regions)&&O8(t.cutLines)===O8(e.cutLines)}function H8(t){let e=n=>{let c=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,r=[c,[...c].reverse()].map(a=>{let s=0;for(let i=1;i<a.length;i++)(a[i][0]<a[s][0]||a[i][0]===a[s][0]&&a[i][1]<a[s][1])&&(s=i);return JSON.stringify([...a.slice(s),...a.slice(0,s)])});return JSON.stringify([Math.sign(d3(n)),r.sort()[0]])};return JSON.stringify(t.map(e).sort())}function O8(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),c=JSON.stringify([...e].reverse());return n<c?n:c}).sort())}var q1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),v0=t=>typeof t=="string"&&t.length>0,S2=t=>typeof t=="number"&&Number.isFinite(t),F2=t=>S2(t)&&t>=0,k2=t=>S2(t)&&t>0,p3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(S2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,g3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(S2),d2=t=>g3(t,3)&&t.every(e=>Math.abs(e)<=1e7),J2=t=>q1(t)&&v0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),R4=t=>q1(t)&&v0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),Z3=t=>J2(t)||R4(t),R2=t=>Array.isArray(t)&&t.every(Z3),m3=t=>d2(t)&&Math.hypot(...t)>1e-9,Yi=t=>q1(t)&&(t.kind==="translate"&&d2(t.by)||t.kind==="rotate"&&d2(t.origin)&&m3(t.axis)&&S2(t.angle)&&Math.abs(t.angle)<=1e6),M6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),N8=t=>q1(t)&&Object.values(t).every(M6),B8=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||S2(t)||Array.isArray(t)&&t.every(n=>B8(n,e+1))),w6=t=>q1(t)&&Object.values(t).every(e=>B8(e)),Ji=t=>t===null||q1(t)&&M6(t.sourceHash)&&M6(t.engineHash)&&N8(t.dependencies)&&N8(t.fonts);function H5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!q1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let c=(s,i,o)=>{for(let l of Object.keys(s))i.includes(l)||n(o?`${o}.${l}`:l,"Unknown specification field.")};c(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),v0(t.model)||n("model","Give the model a nonempty name.");let r=new Set,a=(s,i)=>{if(!q1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!q1(l)||!p3(l.thickness,Number.MIN_VALUE)||!p3(l.kerf)||l.edgeError!==void 0&&!F2(l.edgeError)||l.lot!==void 0&&!v0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),q1(l)&&c(l,["thickness","kerf","edgeError","lot"],`${i}.${o}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[s,i]of t.configurations.entries())!q1(i)||!v0(i.id)||i.params!==void 0&&!w6(i.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):r.has(i.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(r.add(i.id),c(i,["id","params","materials"],`configurations[${s}]`),i.materials!==void 0&&a(i.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,i=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!q1(h)||!v0(h.id)||!v0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(c(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),s.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),s.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&i++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(p=>typeof p=="string"&&r.has(p)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!J2(h.a)||!J2(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!k2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!J2(h.tab)||!J2(h.receiver)||!g3(h.region,4)||h.region.some(p=>Math.abs(p)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!p3(h.clearance)||!F2(h.flushTolerance)||!F2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let p=h.stops;if(!R4(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(J2)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(J2)||!p3(h.clearance)||!p3(h.endplay)||!k2(h.minimumOverlap)||!F2(h.maximumStopGap)||!Array.isArray(p)||p.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let m of p){if(!q1(m)||!R4(m.body)||!q1(m.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}c(m,["body","attachment"],u+".stops");let g=m.attachment;c(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!R4(g.thread)||!k2(g.minimumEngagement)||typeof g.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!F2(h.minimumGap)||h.bodies!==void 0&&(!R2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!v0(h.from)||!r.has(h.from)||!v0(h.to)||!r.has(h.to)||h.from===h.to||!F2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(p=>q1(p)&&Z3(p.body)&&Yi(p.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!v0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!R2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!R2(h.scope)||!h.scope.length)||!F2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(p=>q1(p)&&v0(p.id)&&Z3(p.part)&&d2(p.from)&&typeof p.held=="boolean"&&(p.fasten===void 0||Array.isArray(p.fasten)&&p.fasten.every(v0))&&(p.tool===void 0||q1(p.tool)&&d2(p.tool.from)&&d2(p.tool.to)&&k2(p.tool.diameter)&&p.tool.diameter<=1e6&&d2(p.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!R2(h.roots)||!h.roots.length||h.removable!==void 0&&!R2(h.removable)||!Array.isArray(h.links)||!h.links.every(p=>q1(p)&&v0(p.claim)&&["glued","locked","captured"].includes(p.fastening)&&typeof p.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!R2(h.bodies)||!h.bodies.length||!R2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(p=>q1(p)&&Z3(p.a)&&Z3(p.b)&&(p.kind==="fixed"||p.kind==="revolute"&&d2(p.anchorA)&&d2(p.anchorB)&&m3(p.axisA)&&m3(p.axisB)&&(p.range===void 0||p3(p.range,-1e6))||p.kind==="prismatic"&&m3(p.axisA)&&p3(p.travel,-1e6)||p.kind==="gear"&&m3(p.axisA)&&m3(p.axisB)&&k2(p.ratio)&&p.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!R2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!S2(h.ground)||Math.abs(h.ground)>1e7||!m3(h.gravity)||h.gravity[2]>=0||!F2(h.minimumMargin)||!h.loads.every(p=>q1(p)&&Z3(p.body)&&k2(p.mass)&&(p.center===void 0||d2(p.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!v0(h.plan)||!v0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(p=>q1(p)&&v0(p.step)&&R2(p.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(p,m,g)=>{q1(p)&&c(p,m,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[p,m]of h.moving.entries())q1(m)&&(d(m,["body","trajectory"],`${u}.moving[${p}]`),d(m.trajectory,q1(m.trajectory)&&m.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${p}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[p,m]of h.steps.entries())q1(m)&&(d(m,["id","part","from","held","fasten","tool"],`${u}.steps[${p}]`),d(m.tool,["from","to","diameter","travel"],`${u}.steps[${p}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[p,m]of h.joints.entries())q1(m)&&d(m,["kind","a","b",...m.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:m.kind==="prismatic"?["axisA","travel"]:m.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${p}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((p,m)=>d(p,["claim","fastening","installed"],`${u}.links[${m}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((p,m)=>d(p,["body","mass","center"],`${u}.loads[${m}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((p,m)=>d(p,["step","bodies"],`${u}.holds[${m}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(q1);for(let l of o){let h=(u,f)=>o.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=o.find(m=>m.id===l.plan&&m.kind==="assembly-access"),f=o.find(m=>m.id===l.retention&&m.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(q1).map(m=>m.id)),p=new Set((Array.isArray(f?.links)?f.links:[]).filter(q1).map(m=>m.claim));if(Array.isArray(l.holds))for(let m of l.holds)q1(m)&&!d.has(m.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(m.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let m of u.steps)if(q1(m)&&Array.isArray(m.fasten))for(let g of m.fasten)p.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(m.id)} fastens ${String(g)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(q1(f)){let d=q1(f.body)?f.body:{},p=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(p)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(p)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)q1(u)&&!o.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function z6(t){let e=[],n=(r,a)=>e.push({code:"invalid-snapshot",path:r,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let c=new Set;for(let[r,a]of t.entries()){let s=`snapshots[${r}]`;if(!q1(a)||a.schemaVersion!==1||!v0(a.configuration)||!w6(a.params)||!w6(a.renderSettings)||!Ji(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(o=>typeof o=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}c.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),c.add(a.configuration);let i=new Set;for(let[o,l]of a.parts.entries()){if(!q1(l)||!v0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!k2(l.thickness)||l.glue!==void 0&&(!J2(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!v0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!F2(l.kerf)||l.kerf>1e6)||!Ki(l.matrix)||typeof l.placed!="boolean"||!U8(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!U8(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>q1(u)&&S2(u.x0)&&S2(u.x1)&&u.x1>u.x0&&S2(u.angle))){n(`${s}.parts[${o}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);i.has(h)&&n(`${s}.parts[${o}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),i.add(h)}for(let[o,l]of a.hardware.entries())(!q1(l)||l.label!==null&&!v0(l.label)||typeof l.kind!="string"||!g3(l.from,3)||!g3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!d2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!k2(l.size))||!(k2(l.size)&&l.size<=1e6||g3(l.size,2)&&l.size.every(h=>k2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function U8(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(c=>g3(c,2)&&c.every(r=>Math.abs(r)<=1e6)))}function Ki(t){if(!g3(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(c=>Math.abs(c)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let c=0;c<3;c++)for(let r=0;r<3;r++){let a=e[c]*e[r]+e[4+c]*e[4+r]+e[8+c]*e[8+r];if(Math.abs(a-(c===r?1:0))>n)return!1}return Math.abs(e[0]*(e[5]*e[10]-e[6]*e[9])-e[1]*(e[4]*e[10]-e[6]*e[8])+e[2]*(e[4]*e[9]-e[5]*e[8])-1)<n}function _8(t){let e=[];for(let n of t.claims){let c=r=>e.push({claim:n.id,ref:r});n.kind==="glue-contact"&&(c(n.a),c(n.b)),n.kind==="tab-slot"&&(c(n.tab),c(n.receiver)),n.kind==="captured-shaft"&&(c(n.shaft),n.bearings.forEach(c),n.stack.forEach(c),n.stops.forEach(r=>{c(r.body),r.attachment.kind==="threaded"&&c(r.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(c),n.kind==="motion-clearance"&&n.moving.forEach(r=>c(r.body)),n.kind==="assembly-access"&&(n.initial.forEach(c),n.scope?.forEach(c),n.steps.forEach(r=>c(r.part))),n.kind==="retention"&&(n.roots.forEach(c),n.removable?.forEach(c)),n.kind==="joint-constraints"&&(n.bodies.forEach(c),n.roots.forEach(c),n.joints.forEach(r=>{c(r.a),c(r.b)})),n.kind==="stability"&&(n.supports.forEach(c),n.loads.forEach(r=>c(r.body))),n.kind==="assembly-support"&&n.holds?.forEach(r=>r.bodies.forEach(c))}return e}var Z0=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),L2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var Q1=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),c1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),C6=(t,e,n=[],c="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:c}),R5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,O5=(t,e)=>R5(t,e)?.thickness??[e.thickness,e.thickness];function $4(t,e){let n=R5(t,e);return n?e.kerf===null?[-1/0,1/0]:[e.kerf-n.kerf[1]-2*(n.edgeError??0),e.kerf-n.kerf[0]+2*(n.edgeError??0)]:[0,0]}var L6=(t,e)=>t[0]>=e[0]+B&&t[1]<=e[1]-B,A6=(t,e)=>t[0]<e[0]-B||t[1]>e[1]+B,P6=(...t)=>t.map(X3).find(Boolean);function q4(t,e){let n=Z0(e,t.a),c=Z0(e,t.b);if(n===c)return Q1("A glue contact needs two different physical instances.");let r=P6(n,c);if(r)return c1(r);let a=g6(n,c),s=t.faceA==="top"?n.thickness:0,i=t.faceB==="top"?c.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return Q1("The selected faces are not parallel.");let o=Math.abs(a[11]+a[10]*i-s);if(o>B)return Q1("The selected faces are separated.",{faceGap:o});if(o>1e-7)return c1("Face separation is within numerical uncertainty; exact contact is not established.");let l=t.faceA==="top"?1:-1,h=t.faceB==="top"?1:-1;if(l*h*a[10]>-1+1e-7)return Q1("The selected surfaces face the same way, rather than meeting.");let u=$8(c.regions,a,i),f=Y2(x0(n.regions,u)),d=B*(v6(n.regions)+v6(u)),p={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?Q1("There is insufficient geometric glue contact.",p):f<t.minimumArea+d?{...c1("Contact area is on the numerical acceptance boundary."),measurements:p}:C6("The selected nominal faces have the required geometric contact.",p,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function G8(t,e,n){let c=Z0(e,t.tab),r=Z0(e,t.receiver);if(c===r)return Q1("A tongue and its receiving panel must be different instances.");let a=P6(c,r);if(a)return c1(a);let s=g6(r,c);if(!q8(s)||Math.abs(s[10])>B)return c1("Only orthogonal tab/slot geometry is supported.");let i=b6(c.regions,t.region);if(!y6(i))return c1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=H4(i),f=4*B,d=B,m=[[o-f,l+d,o,u-d],[h,l+d,h+f,u-d],[o+d,l-f,h-d,l],[o+d,u,h-d,u+f]].map(V=>Y2(b6(c.regions,V))>B*B).flatMap((V,J)=>V?[J]:[]);if(m.length>1)return c1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(m.length&&Math.abs(m[0]<2?s[8]:s[9])<.5)return c1("The tongue must join its parent along the insertion direction.");let g;if(m.length){let V=m[0],J=V<2?[V===0?o:h,(l+u)/2,0]:[(o+h)/2,V===2?l:u,0],o1=i0(s,J)[2],Z=(V<2?s[8]:s[9])*(V%2===0?-1:1);g={z:o1,outward:Z}}let v=[];for(let V of[o,h])for(let J of[l,u])for(let o1 of[0,c.thickness])v.push(i0(s,[V,J,o1]));let y=[0,1,2].map(V=>Math.min(...v.map(J=>J[V]))),b=[0,1,2].map(V=>Math.max(...v.map(J=>J[V]))),x=x6(r.regions,[(y[0]+b[0])/2,(y[1]+b[1])/2]);if(!x.length)return Q1("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!y6([x[0]]))return c1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],w=H4([M]),k=$4(n,c),z=$4(n,r);if(![...k,...z].every(Number.isFinite))return c1("Compensated kerf metadata is needed for manufacturing bounds.");let S={},L=!1;for(let V=0;V<2;V++){let J=Math.abs(s[V*4+2])>.5,o1=J?O5(n,c):[b[V]-y[V]+k[0],b[V]-y[V]+k[1]],Z=w[V+2]-w[V],p1=[Z-z[1]-o1[1],Z-z[0]-o1[0]];if(S[V?"clearanceY":"clearanceX"]=p1,A6(p1,t.clearance))return Q1("Tab/slot clearance is outside the required range.",S);L||(L=!L6(p1,t.clearance));let E=y[V],$=b[V];J?s[V*4+2]>0?$+=o1[1]-c.thickness:E-=o1[1]-c.thickness:(E-=Math.max(0,k[1])/2,$+=Math.max(0,k[1])/2);let X=Math.min(E-w[V],w[V+2]-$)-Math.max(0,z[1])/2;if(S[V?"minimumSideGapY":"minimumSideGapX"]=X,X<-B)return Q1("The tongue is offset into the edge of its slot.",S);X<B&&(L=!0)}let I=Math.max(0,-k[0])/2,q=O5(n,r);if(t.flushTolerance>=q[0]-B)return c1("flushTolerance must be smaller than the receiving thickness.");let R=Math.max(0,Math.min(b[2]-I,q[1])-Math.max(y[2]+I,0)),N=q[1]-t.flushTolerance;if(S.engagement=R,S.requiredEngagement=N,R<=B)return Q1("The tongue does not engage the receiving panel.",S);if(R<N-B)return Q1("The tongue does not engage through the receiving panel.",S);if(R<N+B&&(L=!0),g&&(g.outward>0&&g.z<q[1]-B||g.outward<0&&g.z>B))return Q1("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",S);let G=Math.min(...r.regions.filter(V=>V!==M).map(V=>D8(M,V)))-Math.max(0,-z[0]);return S.minimumLigament=G,G<t.minimumLigament-B?Q1("Too little material remains around the slot.",S):(G<t.minimumLigament+B&&(L=!0),L?{...c1("A fit condition is on its numerical acceptance boundary."),measurements:S}:C6("The rectangular tongue fits and engages its receiving slot.",S,["Rigid orthogonal parts; nominal placements are held fixed while finished dimensions vary.","The selected local rectangle must identify the physical tongue; this fit does not establish retention."],R5(n,c)||R5(n,r)?"bounded-fit":"nominal"))}function F4(t){let e=m1(t.to,t.from),n=M1(e);return typeof t.size=="number"&&n>B?{start:t.from,dir:e.map(c=>c/n),length:n,diameter:t.size}:null}function k6(t,e){let n=F4(e);if(!n||M1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let c=m1(n.start,t.start),r=J1(c,t.dir);return M1(c.map((a,s)=>a-r*t.dir[s]))<B}var D4=(t,e)=>J1(m1(e,t.start),t.dir),S6=(t,e)=>[D4(t,e.from),D4(t,e.to)].sort((n,c)=>n-c);function Qi(t,e){let n=R8(e.matrix);if(J1(n,t.dir)<0||M1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let c=i0(L0(e.matrix),t.start),r=[c[0],c[1]],a=x6(e.regions,r);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],i=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,o=[i.reduce((p,m)=>p+m[0],0)/i.length,i.reduce((p,m)=>p+m[1],0)/i.length];if(Math.hypot(o[0]-r[0],o[1]-r[1])>B)return"The shaft is not centered in the bore.";let l=s.map(p=>Math.hypot(p[0]-o[0],p[1]-o[1]));if(Math.max(...l)-Math.min(...l)>B)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((p,m)=>W3(r,p,s[(m+1)%s.length]))),u=Math.max(...s.map(p=>Math.hypot(p[0]-r[0],p[1]-r[1]))),f=D4(t,i0(e.matrix,[0,0,0])),d=D4(t,i0(e.matrix,[0,0,e.thickness]));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u]}}function j8(t,e,n){let c=L2(e,t.shaft),r=F4(c);if(!r)return c1("The shaft must have a nonzero cylindrical physical envelope.");let a=[...t.bearings,...t.stack],s=a.map(x=>JSON.stringify([x.part,x.copy??1]));if(new Set(s).size!==s.length)return Q1("Bearing and stack references must name distinct physical parts.");let i=a.map(x=>Z0(e,x)),o=P6(...i);if(o)return c1(o);let l={shaftDiameter:r.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],w=Qi(r,M);if(typeof w=="string")return/unsupported|supported/.test(w)?c1(`${M.name}: ${w}`):Q1(`${M.name}: ${w}`);let k=$4(n,M);if(!k.every(Number.isFinite))return c1("Kerf metadata is required for bore tolerance bounds.");let z=[w.hole[0]-k[1]-r.diameter,w.hole[1]-k[0]-r.diameter];if(l[`clearance${x+1}`]=z,A6(z,t.clearance))return Q1(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!L6(z,t.clearance)),w.lo<-B||w.lo+O5(n,M)[1]>r.length+B)return Q1(`${M.name}: the shaft does not extend through this part.`,l);h.push(w)}let f=h.slice(0,2).sort((x,M)=>x.lo-M.lo),d=h.slice(2).sort((x,M)=>x.lo-M.lo);if(f.some(x=>O5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>B)))return c1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-B)return Q1("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-B||d[x].hi>f[1].lo+B||x&&d[x-1].hi>d[x].lo+B)return Q1("The axial stack overlaps another component or its supports.");let p=f[1].lo-f[0].lo,g=[f[0].part,...d.map(x=>x.part)].map(x=>O5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[p-g[1],p-g[0]];if(l.endplay=v,A6(v,t.endplay))return Q1("The axial stack has insufficient or excessive endplay.",l);u||(u=!L6(v,t.endplay));let y=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],b=t.stops.map(x=>({stop:x,h:L2(e,x.body)})).map(x=>({...x,at:x.h&&k6(r,x.h)?S6(r,x.h):void 0}));if(b.some(x=>!x.at))return Q1("A retainer is not coaxial with the shaft.");b.sort((x,M)=>x.at[0]+x.at[1]-(M.at[0]+M.at[1]));for(let x=0;x<2;x++){let{stop:M,h:w}=b[x];if(!k6(r,w))return Q1("A retainer is not coaxial with the shaft.");let k=F4(w),z=S6(r,w),S=f[x],L=x===0?z[1]:z[0],I=x===0?S.lo:S.hi,q=x===0?I-L:L-I;l[`stopGap${x+1}`]=q;let R=$4(n,S.part),N=(k.diameter-(S.hole[1]-R[0]))/2;if(l[`stopOverlap${x+1}`]=N,q<-B||q>t.maximumStopGap+B)return Q1("A retainer is misplaced relative to the outside bearing face.",l);if((q<-1e-7||q>t.maximumStopGap+1e-7)&&(u=!0),N<t.minimumOverlap-B)return Q1("A retainer can pass through its bearing opening.",l);N<t.minimumOverlap+B&&(u=!0);let G=M.attachment;if(G.kind==="unknown")return{...c1("The stop is present but its fastening is unverified."),measurements:l};if(G.kind==="integral"){if(Math.min(Math.abs(L),Math.abs(L-r.length))>B)return Q1("An integral head must meet an end of its shaft.",l);y.push("The specified head and shaft are one integral purchased component.")}else{let V=L2(e,G.thread);if(!k6(r,V))return Q1("The threaded attachment is off the shaft axis.");if(F4(V).diameter>r.diameter+B)return Q1("The declared threaded section exceeds the shaft envelope.");let J=S6(r,V),o1=Math.max(0,Math.min(z[1],J[1])-Math.max(z[0],J[0]));if(J[0]<-B||J[1]>r.length+B)return Q1("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=o1,o1<G.minimumEngagement-B)return Q1("The threaded stop has insufficient declared thread engagement.",l);if(o1<G.minimumEngagement+B&&(u=!0),!G.secured)return{...c1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};y.push("The specified usable thread envelope and matching nut are installed and secured as declared; thread form/capacity and resistance to loosening are not verified.")}}return u?{...c1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:C6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>R5(n,x))?"bounded-fit":"nominal")}var N4=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},u1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),E0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],y0=(t,e)=>t.map(n=>n*e),Z8=(t,e)=>t.map((n,c)=>n+e[c]),j1=t=>y0(t,1/M1(t)),Y8=()=>R0(0,0,0);function T6(t,e){let n=c=>c.kind==="translate"?M1(c.by)<1e-9:Math.abs(c.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?M1(m1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?M1(m1(y0(j1(t.axis),t.angle),y0(j1(e.axis),e.angle)))<1e-9&&M1(E0(m1(t.origin,e.origin),j1(t.axis)))<1e-9:!1}function eo(t,e){let n=new Map;for(let c of e)for(let r=0;r<c.length;r++){let a=c[r],s=c[(r+1)%c.length],i=a<s?[a,s]:[s,a];n.set(i.join(","),i)}return{vertices:t,faces:e,edges:[...n.values()]}}function Y3(t,e,n){let c=t.length,r=[];for(let a of[0,e])for(let[s,i]of t)r.push(i0(n,[s,i,a]));return eo(r,[t.map((a,s)=>s).reverse(),t.map((a,s)=>c+s),...t.map((a,s)=>[s,(s+1)%c,(s+1)%c+c,s+c])])}function to(t,e){let n=x1(t),c=[...new Set(n.flat().map(i=>i[0]))].sort((i,o)=>i-o),r=n.flatMap(i=>i.map((o,l)=>({a:o,b:i[(l+1)%i.length]}))),a=[],s=(i,o)=>i.a[1]+(o-i.a[0])*(i.b[1]-i.a[1])/(i.b[0]-i.a[0]);for(let i=1;i<c.length;i++){let o=c[i-1],l=c[i],h=(o+l)/2;e.tick(r.length);let u=r.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],p=u[f+1],m=[[o,s(d,o)],[l,s(d,l)],[l,s(p,l)],[o,s(p,o)]],g=m.filter((v,y)=>M1([v[0]-m[(y+1)%m.length][0],v[1]-m[(y+1)%m.length][1],0])>1e-10);if(g.length<3||Math.abs(d3(g))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(a.push(g),a.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!a.length||Math.abs(Y2(a)-Y2(n))>B*B*Math.max(1,Y2(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function v3(t){if(t.hardware.some(n=>!n.label))throw new Error("Physical hardware needs unique labels for whole-inventory checks.");let e=[...t.parts.map(n=>({part:n.name,copy:n.copy})),...t.hardware.map(n=>({hardware:n.label}))];if(new Set(e.map(u1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function F5(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function c0(t,e){if("part"in e)return Z0(t,e).matrix;let n=L2(t,e),[c,r]=F5(n),a={...n,from:c,to:r},s=j1(m1(a.to,a.from));if(!M1(m1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let i=m1(a.up,y0(s,J1(a.up,s)));if(M1(i)<1e-9){if(Array.isArray(a.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(s[0])<.8?[1,0,0]:[0,1,0];i=m1(l,y0(s,J1(l,s)))}i=j1(i);let o=E0(i,s);return[o[0],i[0],s[0],a.from[0],o[1],i[1],s[1],a.from[1],o[2],i[2],s[2],a.from[2],0,0,0,1]}function K2(t,e,n){if(n.tick(),"part"in e){let h=Z0(t,e),u=X3(h);if(u)throw new Error(u);let d=to(h.regions,n).map(p=>Y3(p,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let c=L2(t,e),r=c0(t,e),[a,s]=F5(c),i=M1(m1(s,a));if(i<B)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(c.size)){let[h,u]=c.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[Y3(f,i,r)];return{ref:e,outer:d,inner:d}}let o=32,l=h=>Array.from({length:o},(u,f)=>[h*Math.cos(f*2*Math.PI/o),h*Math.sin(f*2*Math.PI/o)]);if(c.shape==="ball"){let h=c.size/2,u=h/Math.SQRT2,f=R0(0,0,h-u);return{ref:e,inner:[Y3(l(u),2*u,O1(r,f))],outer:[Y3(l(h/Math.cos(Math.PI/o)),i,r)]}}return{ref:e,inner:[Y3(l(c.size/2),i,r)],outer:[Y3(l(c.size/2/Math.cos(Math.PI/o)),i,r)]}}function U4(t,e){let n=r=>r.map(a=>({...a,vertices:a.vertices.map(s=>i0(e,s))})),c=n(t.outer);return{ref:t.ref,outer:c,inner:t.inner===t.outer?c:n(t.inner)}}function y3(t,e){if(t.kind==="translate")return R0(...y0(t.by,e));let[n,c,r]=j1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),i=Math.sin(a),o=1-s,l=[s+n*n*o,n*c*o-r*i,n*r*o+c*i,0,c*n*o+r*i,s+c*c*o,c*r*o-n*i,0,r*n*o-c*i,r*c*o+n*i,s+r*r*o,0,0,0,0,1];return O1(R0(...t.origin),O1(l,R0(...y0(t.origin,-1))))}function E6(t,e){if(e.kind==="translate")return M1(e.by);let n=j1(e.axis),c=0;for(let r of t.outer)for(let a of r.vertices){let s=m1(a,e.origin);c=Math.max(c,M1(m1(s,y0(n,J1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*c}function W8(t){return t.faces.map(e=>E0(m1(t.vertices[e[1]],t.vertices[e[0]]),m1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>M1(e)>1e-12).map(j1)}function J8(t,e){let n=[...W8(t),...W8(e)];for(let[c,r]of t.edges)for(let[a,s]of e.edges){let i=E0(m1(t.vertices[r],t.vertices[c]),m1(e.vertices[s],e.vertices[a]));M1(i)>1e-12&&n.push(j1(i))}return n}var J3=(t,e)=>{let n=t.vertices.map(c=>J1(c,e));return[Math.min(...n),Math.max(...n)]};function no(t,e,n){let c=-1/0;for(let r of J8(t,e)){n.tick();let a=J3(t,r),s=J3(e,r);c=Math.max(c,s[0]-a[1],a[0]-s[1])}return c}function co(t,e){let n=0;for(let c=0;c<3;c++){let r=t.vertices.map(i=>i[c]),a=e.vertices.map(i=>i[c]),s=Math.max(0,Math.min(...a)-Math.max(...r),Math.min(...r)-Math.max(...a));n+=s*s}return Math.sqrt(n)}function ro(t,e,n,c){let r=m1(n,e),a=m1(c,e),s=m1(t,e),i=J1(r,s),o=J1(a,s);if(i<=0&&o<=0)return M1(s);let l=m1(t,n),h=J1(r,l),u=J1(a,l);if(h>=0&&u<=h)return M1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return M1(m1(s,y0(r,i/(i-h))));let d=m1(t,c),p=J1(r,d),m=J1(a,d);if(m>=0&&p<=m)return M1(d);let g=p*o-i*m;if(g<=0&&o>=0&&m<=0)return M1(m1(s,y0(a,o/(o-m))));let v=h*m-p*u;if(v<=0&&u-h>=0&&p-m>=0)return M1(m1(l,y0(m1(c,n),(u-h)/(u-h+p-m))));let y=v+g+f;if(Math.abs(y)<1e-20)return 1/0;let b=Math.max(0,Math.min(1,g/y)),x=Math.max(0,Math.min(1-b,f/y));return M1(m1(s,Z8(y0(r,b),y0(a,x))))}function ao(t,e,n,c){let r=m1(e,t),a=m1(c,n),s=m1(t,n),i=J1(r,r),o=J1(r,a),l=J1(a,a),h=J1(r,s),u=J1(a,s);if(i<1e-20||l<1e-20)return 1/0;let f=i*l-o*o,d=f>1e-20?Math.max(0,Math.min(1,(o*u-l*h)/f)):0,p=(o*d+u)/l;return p<0&&(p=0,d=Math.max(0,Math.min(1,-h/i))),p>1&&(p=1,d=Math.max(0,Math.min(1,(o-h)/i))),M1(Z8(s,m1(y0(r,d),y0(a,p))))}function so(t,e,n){let c=1/0;for(let[r,a]of[[t,e],[e,t]])for(let s of r.vertices)for(let i of a.faces)for(let o=1;o<i.length-1;o++)n.tick(),c=Math.min(c,ro(s,a.vertices[i[0]],a.vertices[i[o]],a.vertices[i[o+1]]));for(let[r,a]of t.edges)for(let[s,i]of e.edges)n.tick(),c=Math.min(c,ao(t.vertices[r],t.vertices[a],e.vertices[s],e.vertices[i]));return c}function X8(t,e,n,c){let r=1/0,a=1/0,s=!1,i=!0;for(let o of t)for(let l of e){n.tick();let h=co(o,l);if(h>Math.min(a,c)){r=Math.min(r,h);continue}let u=no(o,l,n);u<-B&&(s=!0),u<0&&(i=!1),r=Math.min(r,Math.max(0,h,u)),u<-B?a=0:u<=Math.min(a,c)&&(a=Math.min(a,so(o,l,n)))}return{lower:r,upper:a,penetration:s,touchSafe:i}}function B4(t,e,n,c){let r=X8(t.outer,e.outer,n,c+B),a=t.outer===t.inner&&e.outer===e.inner;if(r.lower>c+B)return{lower:r.lower-B,upper:1/0,penetration:!1,touchSafe:!0};let s=a?r:X8(t.inner,e.inner,n,1/0);return{lower:Math.max(0,r.lower-B),upper:s.upper+B,penetration:s.penetration,touchSafe:r.touchSafe}}function K8(t,e,n,c,r,a){for(let s=0;s<t.outer.length;s++)for(let i=0;i<n.outer.length;i++){let o=t.outer[s],l=n.outer[i],h=e.outer[s],u=c.outer[i],f=!1;for(let d of J8(o,l)){a.tick();let p=J3(o,d),m=J3(l,d),g=J3(h,d),v=J3(u,d);if(Math.min(m[0]-p[1],v[0]-g[1])>=r||Math.min(p[0]-m[1],g[0]-v[1])>=r){f=!0;break}}if(!f)return!1}return!0}function _4(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let c={part:n.name,copy:n.copy},r=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(r>1&&(n.copy-1)%r!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:c,faceA:a?"bottom":"top",faceB:a?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:c,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var p2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),$5=(t,e)=>t.every((n,c)=>Math.abs(n-e[c])<B);function Q8(t,e,n){if(new Set(e.map(u1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(c=>K2(t,c,n))}function en(t,e,n){let c=Q8(e,t.bodies??v3(e),n);if(c.length<2)return c1("Rigid clearance requires at least two physical bodies.");let r=1/0;for(let a=0;a<c.length;a++)for(let s=a+1;s<c.length;s++){let i=B4(c[a],c[s],n,t.minimumGap);if(r=Math.min(r,i.lower),i.penetration||i.upper<t.minimumGap-B)return p2("Physical bodies interfere or violate the required clearance.",{gapUpper:i.upper},[c[a].ref,c[s].ref]);if(!(i.lower>t.minimumGap||t.minimumGap===0&&i.touchSafe))return{...c1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[c[a].ref,c[s].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:r},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function I6(t,e,n,c,r=1e3){let a=o=>({solid:o,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let o=0;o<t.length;o++){for(let l of e)yield{a:t[o],b:a(l)};for(let l=o+1;l<t.length;l++)yield{a:t[o],b:t[l]}}}let i=0;for(let{a:o,b:l}of s()){c.tick();let h=(d,p)=>U4(d.solid,y3(d.trajectory,p));if(T6(o.trajectory,l.trajectory)){let d=B4(o.solid,l.solid,c,n);if(d.penetration||d.upper<n-B)return p2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[o.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...c1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&K8(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+B,c))continue;let u=E6(o.solid,o.trajectory)+E6(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>r)return{...c1("Continuous clearance interval budget exhausted."),measurements:{intervals:i},entities:[o.solid.ref,l.solid.ref]};c.tick();let[d,p]=f.shift(),m=(d+p)/2,g=u*(p-d)/2,v=B4(h(o,m),h(l,m),c,n+g);if(v.penetration||v.upper<n-B)return p2("The specified path has physical interference.",{phase:m,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(p-d<1e-9)return{...c1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,p]},entities:[o.solid.ref,l.solid.ref]};f.push([d,m],[m,p])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function io(t,e){if(t.parts.length!==e.parts.length||t.hardware.length!==e.hardware.length)return"The physical inventory changes between motion endpoints.";for(let n of t.parts){let c=e.parts.find(r=>r.name===n.name&&r.copy===n.copy);if(!c||n.cutLines===null||c.cutLines===null||!O4(n,c))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([c.stack,c.glue,c.glueFace,c.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let c=e.hardware.find(r=>r.label===n.label);if(!n.label||!c||n.kind!==c.kind||JSON.stringify(n.size)!==JSON.stringify(c.size)||Math.abs(M1(m1(n.to,n.from))-M1(m1(c.to,c.from)))>B)return"Hardware identities and dimensions must remain invariant."}return null}function tn(t,e,n,c,r=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return c1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=io(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=v3(e),i=new Set(t.moving.map(l=>u1(l.body)));if(i.size!==t.moving.length)return p2("A body has conflicting simultaneous trajectories.");let o=l=>t.moving.find(h=>u1(h.body)===u1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[..._4(e),...r]){let h=O1(L0(c0(e,l.a)),c0(e,l.b)),u=O1(L0(c0(n,l.a)),c0(n,l.b));if(!$5(h,u)||!T6(o(l.a),o(l.b)))return p2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>u1(f.body)===u1(l))?.trajectory,u=h?y3(h,1):Y8();if("part"in l){if(!$5(O1(u,c0(e,l)),c0(n,l)))return p2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=L2(e,l),d=L2(n,l);if(typeof f.size=="number"){if(!$5(i0(u,f.from),d.from)||!$5(i0(u,f.to),d.to))return p2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!$5(O1(u,c0(e,l)),c0(n,l)))return p2("A box trajectory does not match its rendered destination.",{},[l])}}return I6(t.moving.map(l=>({solid:K2(e,l.body,c),trajectory:l.trajectory})),Q8(e,s.filter(l=>!i.has(u1(l))),c),t.minimumGap,c,t.maxIntervals)}function nn(t,e,n){let c=t.scope??v3(e),r=new Set(c.map(u1)),a=new Map(t.initial.map(o=>[u1(o),K2(e,o,n)]));if(r.size!==c.length||a.size!==t.initial.length||t.initial.some(o=>!r.has(u1(o))))return p2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,i=0;for(let o of t.steps){if(s.has(o.id)||!r.has(u1(o.part))||a.has(u1(o.part)))return p2("An assembly step duplicates or misidentifies a required installation.");if(s.add(o.id),!o.held)return{...c1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=K2(e,o.part,n),h=U4(l,y3({kind:"translate",by:o.from},1)),u=I6([{solid:h,trajectory:{kind:"translate",by:o.from.map(f=>-f)}}],[...a.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:o.id,message:`Assembly step ${o.id}: ${u.message}`};if(i+=u.measurements?.intervals??0,a.set(u1(o.part),l),o.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:o.tool.from,to:o.tool.to,size:o.tool.diameter,up:[0,1,0]}]},p=K2(d,{hardware:f},n),m=U4(p,y3({kind:"translate",by:o.tool.travel},1)),g=I6([{solid:m,trajectory:{kind:"translate",by:o.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:o.id,message:`Tool access at step ${o.id}: ${g.message}`}}}return a.size!==r.size?p2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:a.size,intervals:i},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var K1=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),B0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),$0=t=>[t[3],t[7],t[11]],V6=t=>{let e=j1(t),n=j1(E0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,E0(e,n)]},G4=(t,e,n)=>{let c=V6(n)[0],r=j1(B0(e,c)),a=j1(B0(t,c)),s=j1(B0(e,n));return Math.atan2(J1(s,E0(r,a)),J1(r,a))*180/Math.PI},cn=(t,e,n)=>{let c=[],r=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let i=r;i<=a&&c.length<64;i++)c.push(t+360*i);let s=(e[0]+e[1])/2;return c.sort((i,o)=>Math.abs(i-s)-Math.abs(o-s))};function rn(t,e){if(t?.kind==="glue-contact"&&e==="glued")return[t.a,t.b];if(t?.kind==="captured-shaft"&&e==="captured"){let n=[t.shaft,...t.bearings,...t.stack,...t.stops.map(c=>c.body)];for(let c of t.stops)c.attachment.kind==="threaded"&&n.push(c.attachment.thread);return n}}function an(t,e,n,c){let r=v3(e),a=new Set(r.map(u1));for(let f of t.removable??[])a.delete(u1(f));if(t.roots.some(f=>!a.has(u1(f))))return K1("A retention root cannot be excluded as removable.");let s=new Map,i=f=>{for(let d of f)for(let p of f){let m=u1(d),g=s.get(m)??new Set;g.add(u1(p)),s.set(m,g)}},o=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(g=>g.id===f.claim),p=c.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!p)return c1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(p.status==="fail")return K1(`Attachment ${f.claim} fails its geometric contract.`);if(p.status!=="pass")return c1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return K1(`The fastening for ${f.claim} is explicitly not installed.`);let m=rn(d,f.fastening);if(!m)return c1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(m),d.kind==="glue-contact"&&o.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(u1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=r.filter(f=>a.has(u1(f))&&!l.has(u1(f)));return u.length?{...K1("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:a.size,removableComponents:t.removable?.length??0},assumptions:o}}function oo(t,e){if("hardware"in e){let i=c0(t,e),o=t.hardware.find(l=>l.label===e.hardware);return i0(i,[0,0,M1(m1(F5(o)[1],F5(o)[0]))/2])}let n=Z0(t,e),c=X3(n);if(c)throw new Error(c);let r=0,a=0,s=0;for(let i of n.regions){let[o,l]=i[0],h=0,u=0,f=0;for(let p=0;p<i.length;p++){let m=i[p],g=i[(p+1)%i.length],v=m[0]-o,y=m[1]-l,b=g[0]-o,x=g[1]-l,M=v*x-b*y;h+=M,u+=(v+b)*M,f+=(y+x)*M}if(Math.abs(h)<1e-12)continue;let d=d3(i);r+=d,a+=(o+u/(3*h))*d,s+=(l+f/(3*h))*d}if(r<=B*B)throw new Error("Material centroid is numerically unresolved.");return i0(n.matrix,[a/r,s/r,n.thickness/2])}function lo(t){let e=[...t].sort((s,i)=>s[0]-i[0]||s[1]-i[1]),n=(s,i,o)=>(i[0]-s[0])*(o[1]-s[1])-(i[1]-s[1])*(o[0]-s[0]),c=s=>{let i=[];for(let o of s){for(;i.length>1&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return i},r=c(e),a=c([...e].reverse());return[...r.slice(0,-1),...a.slice(0,-1)]}function ho(t,e,n){let c=new Map,r=i=>{for(let o of i)for(let l of i){let h=c.get(u1(o))??new Set;h.add(u1(l)),c.set(u1(o),h)}};for(let i of t.links){let o=rn(e.claims.find(l=>l.id===i.claim),i.fastening);o&&r(o)}if(!n.length)return!0;let a=new Set([u1(n[0])]),s=[...a];for(;s.length;)for(let i of c.get(s.pop())??[])a.has(i)||(a.add(i),s.push(i));return n.every(i=>a.has(u1(i)))}function sn(t,e,n,c=[],r){let a=v3(e),s=t.loads.map(m=>u1(m.body));if(new Set(s).size!==s.length||a.some(m=>!s.includes(u1(m))))return c1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let m=c.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=r?.claims.find(v=>v.id===t.retention);if(!m||m.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return c1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!ho(g,r,a))return c1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let i=0,o=[0,0,0];for(let m of t.loads){let g=m.center?i0(c0(e,m.body),m.center):oo(e,m.body);i+=m.mass,o=o.map((v,y)=>v+m.mass*g[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return c1("Mass/centroid calculation exceeds its numerical range.");o=y0(o,1/i);let l=[];for(let m of a){let g=K2(e,m,n),v=Math.min(...g.inner.flatMap(b=>b.vertices.map(x=>x[2]))),y=Math.min(...g.outer.flatMap(b=>b.vertices.map(x=>x[2])));if(v<t.ground-B)return K1("A physical component penetrates the ground plane.");if(y<t.ground-B)return c1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(b=>u1(b)===u1(m))){if(Math.abs(v-t.ground)>1e-8)return c1("Ground contact is separated or within physical-envelope uncertainty.");for(let b of g.inner)for(let x of b.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=lo(l);if(h.length<3)return c1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-o[2])/t.gravity[2],f=[o[0]+u*t.gravity[0],o[1]+u*t.gravity[1]],d=1/0;for(let m=0;m<h.length;m++){let g=h[m],v=h[(m+1)%h.length],y=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),b=W3(f,g,v);d=Math.min(d,y<0?-b:b)}let p={supportMargin:d,mass:i,centerX:o[0],centerY:o[1],centerZ:o[2]};return d<t.minimumMargin-B?K1("The gravity line lies outside the required support margin.",p):d<t.minimumMargin+B?{...c1("Stability is on its numerical support boundary."),measurements:p}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:p,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function on(t,e,n,c){let r=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>c.find(p=>p.id===d&&p.configurations.includes(e.configuration));if(!r||r.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return c1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return c1("Per-step support of removable objects needs an explicit contact model.");let i=new Set(a.roots.map(u1)),o=new Set(r.initial.map(u1));if(r.initial.some(d=>!i.has(u1(d))))return c1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let p=n.claims.find(m=>m.id===d.claim);if(p?.kind==="glue-contact")l.set(d.claim,[p.a,p.b]);else if(p?.kind==="captured-shaft"){let m=[p.shaft,...p.bearings,...p.stack,...p.stops.map(g=>g.body)];p.stops.forEach(g=>{g.attachment.kind==="threaded"&&m.push(g.attachment.thread)}),l.set(d.claim,m)}}let h=new Set,u=new Set(r.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return K1("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let g of h)for(let v of l.get(g)??[])for(let y of l.get(g)??[]){let b=d.get(u1(v))??new Set;b.add(u1(y)),d.set(u1(v),b)}let p=new Set([...i].filter(g=>o.has(g))),m=[...p];for(;m.length;)for(let g of d.get(m.pop())??[])p.has(g)||(p.add(g),m.push(g));return p};for(let d of r.steps){o.add(u1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return K1(`Step ${d.id} names an unknown fastening.`);if(v.some(y=>!o.has(u1(y))))return K1(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let p=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(u1));if([...p].some(g=>!o.has(g)))return K1(`Step ${d.id} holds an uninstalled body.`);let m=f();if([...o].some(g=>!m.has(g)&&!p.has(g)))return K1(`Step ${d.id} releases a component before it is retained or supported.`)}return[...o].some(d=>!f().has(d))?K1("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function uo(t){let e=t.map(r=>{let a=Math.max(...r.map(Math.abs),1e-20);return r.map(s=>s/a)}),n=0,c=!1;for(let r=0;r<(e[0]?.length??0)&&n<e.length;r++){let a=n;for(let o=n+1;o<e.length;o++)Math.abs(e[o][r])>Math.abs(e[a][r])&&(a=o);let s=Math.abs(e[a][r]);if(s<1e-10)continue;s<1e-7&&(c=!0),[e[n],e[a]]=[e[a],e[n]];let i=e[n][r];for(let o=r;o<e[n].length;o++)e[n][o]/=i;for(let o=n+1;o<e.length;o++){let l=e[o][r];for(let h=r;h<e[o].length;h++)e[o][h]-=l*e[n][h]}n++}return{rank:n,uncertain:c}}function ln(t,e,n,c,r,a=[]){if(t.bodies.length>64)return c1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(u1),i=t.roots.map(u1);if(new Set(s).size!==s.length||new Set(i).size!==i.length||i.some(v=>!s.includes(v)))return K1("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>c0(e,v).some((y,b)=>Math.abs(y-c0(n,v)[b])>B)))return K1("A grounded kinematic root changes pose.");let o=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,y,b,x,M=1)=>{let w=s.indexOf(u1(y));if(w<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[w*6+b+k]+=M*x[k]};for(let v of t.roots)for(let y=0;y<6;y++){let b=h();b[s.indexOf(u1(v))*6+y]=1,o.push(b)}let f=_4({...e,parts:e.parts.filter(v=>s.includes(u1({part:v.name,copy:v.copy})))});for(let v of r?.claims??[])if(v.kind==="retention")for(let y of v.links){let b=r.claims.find(x=>x.id===y.claim);y.installed&&y.fastening==="glued"&&b?.kind==="glue-contact"&&a.some(x=>x.id===b.id&&x.configurations.includes(e.configuration)&&x.status==="pass")&&f.push({a:b.a,b:b.b})}for(let v of f)if(!(!s.includes(u1(v.a))&&!s.includes(u1(v.b)))){if(!s.includes(u1(v.a))||!s.includes(u1(v.b)))return c1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=q4({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:B*B*4},e);if(y.status!=="pass")return{...y,message:`A native glue/stack bond is not physically established: ${y.message}`}}}let d=[...t.joints,...f.filter(v=>s.includes(u1(v.a))&&s.includes(u1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(c.tick(),u1(v.a)===u1(v.b))return K1("A joint cannot connect a body to itself.");let y=c0(e,v.a),b=c0(e,v.b),x=c0(n,v.a),M=c0(n,v.b),w=O1(L0(y),b),k=O1(L0(x),M),z=L=>{let I=h();u(I,v.b,3,L),u(I,v.a,3,L,-1),o.push(I)},S=(L,I,q)=>{let R=h();u(R,v.b,0,L),u(R,v.a,0,L,-1),u(R,v.b,3,E0(q,L)),u(R,v.a,3,E0(I,L),-1),o.push(R)};if(v.kind==="fixed"){if(w.some((L,I)=>Math.abs(L-k[I])>B))return K1("A fixed joint changes its relative transform.");l.forEach(L=>z(L)),l.forEach(L=>S(L,m1($0(b),$0(y)),[0,0,0]))}else if(v.kind==="revolute"){let L=i0(y,v.anchorA),I=i0(b,v.anchorB),q=j1(B0(y,v.axisA)),R=j1(B0(b,v.axisB)),N=J1(j1(B0(x,v.axisA)),j1(B0(M,v.axisB)));if(M1(m1(L,I))>B||M1(E0(q,R))>1e-7||Math.abs(J1(q,R)-N)>1e-7)return K1("Revolute anchors or axes do not coincide.");if(v.range){let G=G4(w,k,v.axisB);if(!cn(G,v.range,B).length)return K1("A revolute joint exceeds its declared angular travel.",{angle:G})}l.forEach(G=>S(G,m1(L,$0(y)),m1(I,$0(b)))),V6(q).forEach(z)}else if(v.kind==="prismatic"){let L=m1($0(w),$0(k)),I=j1(v.axisA),q=J1(L,I);if([0,1,2,4,5,6,8,9,10].some(R=>Math.abs(w[R]-k[R])>B)||M1(m1(L,y0(I,q)))>B)return K1("A slider rotates or moves away from its guide axis.");if(q<v.travel[0]-B||q>v.travel[1]+B)return K1("The slider exceeds its allowed travel.",{travel:q});l.forEach(z),V6(j1(B0(y,v.axisA))).forEach(R=>S(R,m1($0(b),$0(y)),[0,0,0]))}else{let L=j1(B0(y,v.axisA)),I=j1(B0(b,v.axisB));if(M1(E0(L,I))>1e-7||M1(m1($0(y),$0(x)))>B||M1(m1($0(b),$0(M)))>B)return K1("The scoped gear axes/centers are not fixed and parallel.");let q=G4(y,x,v.axisA),R=G4(b,M,v.axisB);if(Math.abs(q)>90||Math.abs(R)>90)return c1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(R+v.ratio*q)>1e-6)return K1("The rendered gears do not obey their declared angular ratio.");let N=h();u(N,v.a,3,L,v.ratio),u(N,v.b,3,I),o.push(N)}}c.tick(o.length*s.length*6);let p=uo(o),m=s.length*6-p.rank;if(p.uncertain)return c1("Constraint rank is numerically singular.");let g={degreesOfFreedom:m,constraintRank:p.rank,redundantRows:o.length-p.rank};return m!==t.expectedDof?K1("The joint graph has unintended freedom or is overconstrained.",g):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:g,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function hn(t,e,n,c){let r=o=>t.moving.find(l=>u1(l.body)===u1(o))?.trajectory??{kind:"translate",by:[0,0,0]},a=o=>o.kind==="translate"?M1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?M1(m1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?M1(m1(y0(j1(o.axis),o.angle),y0(j1(l.axis),l.angle)))<1e-9&&M1(E0(m1(o.origin,l.origin),j1(o.axis)))<1e-9:!1;if(e.roots.some(o=>!a(r(o))))return K1("The analytic path moves a grounded joint root.");let i=new Map;for(let o of e.joints.filter(l=>l.kind!=="gear")){if(i.has(u1(o.b)))return c1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");i.set(u1(o.b),u1(o.a))}for(let o of i.keys()){let l=new Set,h=o;for(;h&&i.has(h);){if(l.has(h))return c1("Continuous closed-linkage constraints need a solver.");l.add(h),h=i.get(h)}}for(let o of e.joints){let l=r(o.a),h=r(o.b),u=c0(n,o.a),f=c0(n,o.b);if(o.kind==="fixed"){if(!s(l,h))return K1("The analytic path separates a fixed joint.");continue}if(o.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return c1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=i0(u,o.anchorA),p=j1(B0(u,o.axisA)),m=j1(h.axis);if(M1(E0(p,m))>1e-9||M1(E0(m1(h.origin,d),p))>B)return K1("The trajectory does not rotate about the actual hinge.");if(o.range){let g=O1(L0(u),f),v=O1(L0(c0(c,o.a)),c0(c,o.b)),y=h.angle*J1(j1(B0(f,o.axisB)),m),b=o.range;if(!cn(G4(g,v,o.axisB),b,B).some(M=>Math.min(M,M+y)>=b[0]-B&&Math.max(M,M+y)<=b[1]+B))return K1("The continuous hinge path exceeds its angular stops.")}}else if(o.kind==="prismatic"){if(s(l,h))continue;if(!a(l)||h.kind!=="translate")return c1("This slider trajectory composition needs a richer constraint solver.");let d=j1(B0(u,o.axisA));if(M1(E0(h.by,d))>B)return K1("The analytic slider path leaves its guide.");let p=O1(L0(u),f),m=O1(L0(c0(c,o.a)),c0(c,o.b)),g=J1(m1($0(p),$0(m)),j1(o.axisA)),v=g+J1(h.by,d);if(Math.min(g,v)<o.travel[0]-B||Math.max(g,v)>o.travel[1]+B)return K1("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,y)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let b=c0(n,g),x=j1(B0(b,y));return M1(E0(j1(v.axis),x))>1e-9||M1(E0(m1(v.origin,$0(b)),x))>B?null:v.angle*J1(j1(v.axis),x)},p=d(o.a,l,o.axisA),m=d(o.b,h,o.axisB);if(p===null||m===null)return c1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(m+o.ratio*p)>1e-7)return K1("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function un(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return fn(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(c=>{let r=n?.parts.filter(l=>l.name===c.name),a=r?.length===1?r[0]:void 0,s=a?.glue?.host,o=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((c.copy-1)/(a?.stack??1))+1:1;return{name:c.name,copy:c.copy,thickness:c.thickness,material:c.material??"",matrix:c.matrix,placed:c.placed,regions:a?.cutRegions??c.outline,bends:c.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:o},glueFace:a.glue.face},...a?.on&&{on:a.on}}}),hardware:t.hardware.map(c=>({label:c.label??null,kind:c.kind,from:c.from,to:c.to,size:c.size,up:c.up,...c.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(c=>c.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function fn(t){if(t&&typeof t=="object"){for(let e of Object.values(t))fn(e);Object.freeze(t)}return t}function dn(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let c=H5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(c.length)throw new Error(c[0].message);let r=new Map;for(let a of e){let s=a.body,i=u1(s);if(("part"in s?t.assembly.filter(l=>l.name===s.part&&l.copy===(s.copy??1)).length:t.hardware.filter(l=>l.label===s.hardware).length)!==1||r.has(i))throw new Error("Pose controls must identify one unique physical instance each.");r.set(i,y3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=r.get(u1({part:a.name,copy:a.copy}));return s?{...a,matrix:O1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},i=r.get(u1(s));return i?{...a,from:i0(i,a.from),to:i0(i,a.to),up:m1(i0(i,a.up),i0(i,[0,0,0]))}:a})}}function fo(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==B||H5(e).length||z6(n).length||n.some(r=>r.error!==void 0||!r.provenance)||!Array.isArray(t.inputs))return!1;let c=r=>JSON.stringify(r,(a,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.fromEntries(Object.keys(s).sort().map(i=>[i,s[i]])):s);try{let r=n.map(s=>({configuration:s.configuration,params:s.params,renderSettings:s.renderSettings,provenance:s.provenance})),a=s=>[...s].sort((i,o)=>i.configuration.localeCompare(o.configuration));return c(e)===c(t.specification)&&c(a(r))===c(a(t.inputs))}catch{return!1}}function po(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let c=H5(t);if(c.length)return{kind:"invalid-spec",issues:c};let r=z6(e);if(r.length)return{kind:"invalid-snapshot",issues:r};let a=t,s=e,i=[];for(let[g,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(g)||!Number.isSafeInteger(v)||!(v>0))&&i.push({code:"invalid-limits",path:`limits.${g}`,message:"Verification limits must be positive safe integers."});if(i.length)return{kind:"invalid-spec",issues:i};let o={schemaVersion:1,model:a.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:B,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.map(g=>({configuration:g.configuration,params:g.params,renderSettings:g.renderSettings,provenance:g.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(s.reduce((g,v)=>g+v.hardware.reduce((y,b)=>y+(typeof b.size=="number"?128:8),0)+v.parts.reduce((y,b)=>y+b.regions.reduce((x,M)=>x+M.length,0)+(b.cutLines??[]).reduce((x,M)=>x+M.length,0),0),0)>(n.maxPoints??2e5)||a.claims.length>(n.maxClaims??1e3)||a.configurations.length>(n.maxConfigurations??100))return o.claims.push(Q2("$resource-limit","resource-limit",!0,[],{status:"unverified",code:"resource-limit",message:"The verification input exceeds its point, claim or configuration budget. No mechanical conclusions were reached."})),{kind:"report",report:o};let h=new Set(a.configurations.map(g=>g.id));for(let g of s)h.has(g.configuration)||i.push({code:"unknown-configuration",message:`Snapshot ${g.configuration} is not declared.`});for(let g of s){let v=a.configurations.find(y=>y.id===g.configuration)?.params??{};for(let[y,b]of Object.entries(v))JSON.stringify(g.params[y])!==JSON.stringify(b)&&i.push({code:"configuration-mismatch",message:`${g.configuration}: captured parameter ${y} differs from its required value.`})}let u=new Map(a.claims.map(g=>[g.id,g]));for(let{claim:g,ref:v}of _8(a)){let y=u.get(g);for(let b of s.filter(x=>x.error===void 0&&(!y.configurations||y.configurations.includes(x.configuration)))){let x="part"in v?b.parts.filter(M=>M.name===v.part&&M.copy===(v.copy??1)):b.hardware.filter(M=>M.label===v.hardware);x.length!==1&&i.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${b.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(i.length)return{kind:"invalid-spec",issues:i};for(let g of a.configurations){let v=s.find(b=>b.configuration===g.id),y=v&&v.error===void 0;o.claims.push(Q2(`$configuration:${g.id}`,"configuration",!0,[g.id],y?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),y&&(o.claims.push(Q2(`$provenance:${g.id}`,"provenance",!0,[g.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&o.claims.push(Q2(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
2644
+ `)})),v.legacyHardware&&o.claims.push(Q2(`$legacy:${g.id}`,"hardware-inventory",!0,[g.id],{status:"unverified",code:"legacy-hardware",message:"echo hardware is not authoritative physical inventory. Migrate it to native hardware before verification."})))}let f=new N4(n.maxOperations),d=g=>g.kind==="retention"?3:g.kind==="stability"||g.kind==="assembly-support"?4:g.kind==="motion-clearance"||g.kind==="assembly-access"?2:g.kind==="joint-constraints"?1:0,p=[...a.claims].sort((g,v)=>d(g)-d(v));for(let g of p){let v=g.configurations??a.configurations.map(y=>y.id);if(g.kind==="cut-invariant"){let y=v.map(b=>s.find(x=>x.configuration===b));o.claims.push(Q2(g.id,g.kind,g.required!==!1,v,y.some(b=>!b||b.error!==void 0)?c1("A required configuration is unavailable."):mo(y)));continue}if(g.kind==="motion-clearance"){let y=s.find(M=>M.configuration===g.from),b=s.find(M=>M.configuration===g.to),x;if(!y||!b||y.error!==void 0||b.error!==void 0)x=c1("Motion endpoints are unavailable.");else try{if(x={status:"pass"},g.constraints){let M=a.claims.find(k=>k.id===g.constraints),w=o.claims.filter(k=>k.id===g.constraints);if(!M||M.kind!=="joint-constraints"||!w.length||w.some(k=>k.status!=="pass")||![g.from,g.to].every(k=>w.some(z=>z.configurations.includes(k))))x=c1("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=hn(g,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"&&[g.from,g.to].every(S=>o.claims.some(L=>L.id===z.id&&L.configurations.includes(S)&&L.status==="pass"))&&M.push({a:z.a,b:z.b})}x=tn(g,y,b,f,M)}}catch(M){x={status:"unverified",code:"geometry-unresolved",message:M.message}}o.claims.push(Q2(g.id,g.kind,g.required!==!1,[g.from,g.to],x,pn(g)));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=c1("The configuration is unavailable.");else try{switch(g.kind){case"glue-contact":w=q4(g,b);break;case"tab-slot":w=G8(g,b,M);break;case"captured-shaft":w=j8(g,b,M);break;case"material-assignment":w=go(b,M);break;case"rigid-clearance":w=en(g,b,f);break;case"assembly-access":w=nn(g,b,f);break;case"joint-constraints":{let k=s.find(z=>z.configuration===v[0]);w=k&&k.error===void 0?ln(g,b,k,f,a,o.claims):c1("The kinematic reference configuration is unavailable.");break}case"retention":w=an(g,b,a,o.claims);break;case"stability":w=sn(g,b,f,o.claims,a);break;case"assembly-support":w=on(g,b,a,o.claims);break;default:w=c1(`The ${g.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(Q2(g.id,g.kind,g.required!==!1,[y],w,pn(g)))}}let m=o.claims.filter(g=>g.required);o.status=m.some(g=>g.status==="fail")?"fail":m.some(g=>g.status==="unverified")?"unverified":"pass";for(let[g,v]of[["retention","Retention of permanent inventory."],["stability","Static stability under declared masses and gravity."],["assembly-access","Authored insertion and tool access paths."],["assembly-support","Support throughout the installation sequence."],["motion-clearance","Continuous nominal operating motion clearance."],["joint-constraints","Mechanism constraints and intended mobility."]]){let y=o.claims.filter(x=>x.kind===g&&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 Q2(t,e,n,c,r,a=[]){return{id:t,kind:e,required:n,configurations:c,status:"unverified",code:"unverified",message:"",entities:a,measurements:{},assumptions:[],coverage:"none",...r}}function pn(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 mo(t){if(t.length<2)return c1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return c1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(c=>c.cutLines===null||c.kerf===null)))return c1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(c=>!c.label)))return c1("Cross-pose hardware requires unique native labels.");for(let n of t){let c=n.hardware.map(r=>r.label);if(new Set(c).size!==c.length)return c1("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 r of e.parts){let a=Z0(n,{part:r.name,copy:r.copy});if(!a||!O4(r,a))return{status:"fail",code:"cut-geometry-changed",message:`Operating motion changed cut geometry/material for ${r.name} copy ${r.copy}.`}}for(let r of e.hardware){let a=n.hardware.find(s=>s.label===r.label);if(!a||r.kind!==a.kind||JSON.stringify(r.size)!==JSON.stringify(a.size)||Math.abs(M1(m1(r.to,r.from))-M1(m1(a.to,a.from)))>B)return{status:"fail",code:"hardware-changed",message:`Operating motion changed hardware ${r.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 go(t,e){if(!t.parts.length)return c1("There are no sheet parts to assign a stock profile.");for(let n of t.parts){let c=e.materials&&Object.prototype.hasOwnProperty.call(e.materials,n.material)?e.materials[n.material]:void 0;if(!c)return c1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<c.thickness[0]-B||n.thickness>c.thickness[1]+B)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return c1("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 vo=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function mn(t){if(t.kind!=="report")return[];let e=new Map;for(let c of t.report.claims){if(c.status==="pass")continue;let r=`${c.status}\0${c.code}`,a=e.get(r)??{status:c.status,code:c.code,message:c.message,claims:[]};a.claims.push({id:c.id,configurations:c.configurations,bodies:c.entities.map(vo),measurements:c.measurements}),e.set(r,a)}let n=c=>c==="fail"?0:1;return[...e.values()].sort((c,r)=>n(c.status)-n(r.status)||r.claims.length-c.claims.length)}function yo(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(r=>r.message).join("; ")}
2645
+ `;let e=mn(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
2309
2646
  `;let n=r=>Array.isArray(r)?`${+r[0].toFixed(3)}..${+r[1].toFixed(3)}`:`${+r.toFixed(3)}`,c=[];for(let r of e){c.push(`${r.status} ${r.code} (${r.claims.length}): ${r.message}`);for(let a of r.claims){let s=Object.entries(a.measurements).slice(0,4).map(([i,o])=>`${i} ${n(o)}`).join(", ");c.push(` ${a.id}${a.configurations.length?` [${a.configurations.join(", ")}]`:""}${a.bodies.length?`: ${a.bodies.join(" / ")}`:""}${s?`; ${s}`:""}`)}}return c.join(`
2310
2647
  `)+`
2311
- `}var Mf="0.7.0",wf="0.3";export{x4 as DEFAULT_LAYERS,rt as DEFAULT_LIMITS,d5 as HARDWARE_COLORS,I3 as HARDWARE_KINDS,i1 as KerfError,wf as LANGUAGE_VERSION,x7 as SIGNATURES,Mf as VERSION,h6 as bendPoint,oi as diffRenders,re as format,Qs as formatError,b6 as formatSignature,Ni as importSvg,xi as instructionsHtml,u6 as meshPieces,Zs as parameters,r2 as parse,K0 as placementMatrix,h9 as poseAssembly,qs as render,p5 as signature,o9 as snapshotFromRender,f5 as tokenize,f9 as triage,go as triageText,ho as verificationIsCurrent,uo as verify};
2648
+ `}var zf="0.8.0",kf="0.3";export{w4 as DEFAULT_LAYERS,s8 as DEFAULT_LIMITS,m5 as HARDWARE_COLORS,I3 as HARDWARE_KINDS,i1 as KerfError,kf as LANGUAGE_VERSION,z7 as SIGNATURES,zf as VERSION,ue as bendPoint,hi as diffRenders,s6 as format,ti as formatError,xe as formatSignature,Bi as importSvg,wi as instructionsHtml,fe as meshPieces,Js as parameters,a2 as parse,K0 as placementMatrix,dn as poseAssembly,Us as render,v5 as signature,un as snapshotFromRender,p5 as tokenize,mn as triage,yo as triageText,fo as verificationIsCurrent,po as verify};
2312
2649
  /*! Bundled license information:
2313
2650
 
2314
2651
  opentype.js/dist/opentype.module.js: