@mylasertools/kerfscript 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -0
- package/LANGUAGE.md +13 -5
- package/README.md +2 -1
- package/dist/assembly.d.cts +2 -0
- package/dist/assembly.d.ts +2 -0
- package/dist/bores.d.cts +10 -0
- package/dist/bores.d.ts +10 -0
- package/dist/cli.js +7899 -6630
- package/dist/customizer.d.cts +3 -0
- package/dist/customizer.d.ts +3 -0
- package/dist/effects.d.cts +31 -0
- package/dist/effects.d.ts +31 -0
- package/dist/evaluator.d.cts +1 -0
- package/dist/evaluator.d.ts +1 -0
- package/dist/export/mesh.d.cts +53 -0
- package/dist/export/mesh.d.ts +53 -0
- package/dist/export/model.d.cts +12 -0
- package/dist/export/model.d.ts +12 -0
- package/dist/export/triangulate.d.cts +5 -0
- package/dist/export/triangulate.d.ts +5 -0
- package/dist/export/zip.d.cts +5 -0
- package/dist/export/zip.d.ts +5 -0
- package/dist/geometry.d.cts +1 -0
- package/dist/geometry.d.ts +1 -0
- package/dist/highlight.cjs +2 -2
- package/dist/highlight.js +2 -2
- package/dist/import/dbg.d.cts +1 -0
- package/dist/import/dbg.d.ts +1 -0
- package/dist/index.cjs +435 -48
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +435 -48
- package/dist/language.cjs +410 -30
- package/dist/language.js +410 -30
- package/dist/libraries.cjs +393 -14
- package/dist/libraries.js +393 -14
- package/dist/render.d.cts +3 -0
- package/dist/render.d.ts +3 -0
- package/dist/signatures.cjs +23 -5
- package/dist/signatures.js +23 -5
- package/dist/text.d.cts +6 -0
- package/dist/text.d.ts +6 -0
- package/docs/3d-files.md +72 -0
- package/docs/cli.md +27 -22
- package/docs/customizer.md +56 -0
- package/docs/javascript.md +46 -0
- package/docs/library.md +120 -0
- package/docs/openscad.md +15 -13
- package/docs/parts-and-sheets.md +2 -1
- package/docs/versions.md +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*! @mylasertools/kerfscript | (c) MyLaserTools | AGPL-3.0-only or commercial licence, see COMMERCIAL-LICENSE.md. Includes Clipper2 (BSL-1.0), opentype.js, tiny-inflate and string.prototype.codepointat (MIT), see THIRD-PARTY-NOTICES.md. */
|
|
2
|
-
"use strict";var J5=Object.defineProperty;var i9=Object.getOwnPropertyDescriptor;var o9=Object.getOwnPropertyNames;var l9=Object.prototype.hasOwnProperty;var h9=(t,e,n)=>e in t?J5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u9=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f9=(t,e)=>{for(var n in e)J5(t,n,{get:e[n],enumerable:!0})},d9=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of o9(e))!l9.call(t,c)&&c!==n&&J5(t,c,{get:()=>e[c],enumerable:!(r=i9(e,c))||r.enumerable});return t};var m9=t=>d9(J5({},"__esModule",{value:!0}),t);var _=(t,e,n)=>h9(t,typeof e!="symbol"?e+"":e,n);var u7=u9((Mu,h7)=>{h7.exports={}});var vl={};f9(vl,{DEFAULT_LAYERS:()=>N5,DEFAULT_LIMITS:()=>w6,HARDWARE_COLORS:()=>U3,HARDWARE_KINDS:()=>d3,KerfError:()=>o1,LANGUAGE_VERSION:()=>gl,SIGNATURES:()=>Ne,VERSION:()=>pl,bendPoint:()=>p4,diffRenders:()=>rn,format:()=>_4,formatError:()=>Q8,formatSignature:()=>z4,importSvg:()=>Sn,instructionsHtml:()=>sn,meshPieces:()=>v4,parameters:()=>K8,parse:()=>l2,placementMatrix:()=>Z0,poseAssembly:()=>at,render:()=>X8,signature:()=>B3,snapshotFromRender:()=>ct,tokenize:()=>N3,triage:()=>st,triageText:()=>s9,verificationIsCurrent:()=>c9,verify:()=>a9});module.exports=m9(vl);var t0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(t0||(t0={}));var H0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})(H0||(H0={}));var _1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(_1||(_1={}));var G1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(G1||(G1={}));var E3=Number.MAX_SAFE_INTEGER,x0=Math.floor(Math.sqrt(E3));function K5(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=E3/Math.abs(e)}function it(t,e){return Math.abs(t)+Math.abs(e)<=E3}function fe(t,e,n,r){if(K5(t,e)&&K5(n,r)){let c=t*e,a=n*r;if(it(c,a))return c-a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(r)):t*e-n*r}function de(t,e,n,r){if(K5(t,e)&&K5(n,r)){let c=t*e,a=n*r;if(it(c,a))return c+a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(r)):t*e+n*r}var me=BigInt(0),Q5=BigInt(2),p9=BigInt(4),g9=BigInt(64),v9=BigInt("0xFFFFFFFFFFFFFFFF"),ve=BigInt("9223372036854775807"),l5=Number(ve/p9),ot=Number(ve),lt=1e-12,y9=.1,pe=Math.floor(x0/2),b9=Math.floor(Math.sqrt(Math.sqrt(E3/4)));function x9(t){if(!Number.isFinite(t))throw new RangeError("Scale must be a finite number");let e=Math.abs(t);return e===0?Number.POSITIVE_INFINITY:E3/e}function M9(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function w9(t,e){if(!Number.isFinite(t)||Math.abs(t)>E3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function k9(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(r)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0?r*c-a*s:fe(r,c,a,s)}function a2(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;if(Math.abs(r)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0){let l=r*c,h=a*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let l=r*c,h=a*s;return l>h?1:l<h?-1:0}let i=BigInt(r)*BigInt(c),o=BigInt(a)*BigInt(s);return i===o?0:i>o?1:-1}function z9(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function S9(t){return Math.abs(t)<=lt}function L9(t){return t<0?-1:t>0?1:0}function A9(t,e){let n=BigInt(t),r=BigInt(e),c=n*r;return{lo64:c&v9,hi64:c>>g9}}function ht(t,e,n,r){let c=Math.abs(t),a=Math.abs(e),s=Math.abs(n),i=Math.abs(r);if(c<x0&&a<x0&&s<x0&&i<x0)return t*e===n*r;let o=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(r<0?-1:r>0?1:0);if(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return t*e===n*r;let h=BigInt(c),u=BigInt(a),f=BigInt(s),d=BigInt(i);return h*u===f*d}function C9(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return ht(r,c,a,s)}function P9(t,e,n){let r=e.x-t.x,c=n.x-e.x,a=e.y-t.y,s=n.y-e.y;return Math.abs(r)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0?r*c+a*s:de(r,c,a,s)}function E9(t,e,n){let r=e.x-t.x,c=n.x-e.x,a=e.y-t.y,s=n.y-e.y;if(Math.abs(r)<x0&&Math.abs(c)<x0&&Math.abs(a)<x0&&Math.abs(s)<x0){let o=r*c+a*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let o=r*c+a*s;return o>0?1:o<0?-1:0}let i=BigInt(r)*BigInt(c)+BigInt(a)*BigInt(s);return i===me?0:i>me?1:-1}function T9(t){let e=t.length;if(e<3)return 0;let n=!0;for(let a=0;a<e&&n;a++){let s=t[a];(Math.abs(s.x)>=pe||Math.abs(s.y)>=pe)&&(n=!1)}let r=t[e-1];if(n){let a=0;for(let s of t)a+=(r.y+s.y)*(r.x-s.x),r=s;return a*.5}let c=me;for(let a of t){let s=r.y+a.y,i=r.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))c+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(a.x)){let o=BigInt(r.y)+BigInt(a.y),l=BigInt(r.x)-BigInt(a.x);c+=o*l}else c+=BigInt(Math.round(s*i));r=a}return Number(c)*.5}function I9(t,e){return t.y*e.x-e.y*t.x}function V9(t,e){return t.x*e.x+t.y*e.y}function H9(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function O9(t){return t>=l5||t<=-l5?ot:Math.round(t)}function F9(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,i=r.x-n.x,o=fe(c,i,s,a);if(o===0)return null;let l=fe(t.x-n.x,s,t.y-n.y,i)/o;return l<=0?{x:t.x,y:t.y,z:t.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(t.x+l*a),y:Math.trunc(t.y+l*c),z:0}}function R9(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,i=r.x-n.x,o=c*i-s*a;if(o===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*s-(t.y-n.y)*i)/o,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*a,y:t.y+l*c,z:0},{success:!0,ip:h}}function $9(t,e,n,r,c=!1){if(!c){let l=a2(t,n,r),h=a2(e,n,r),u=a2(n,t,e),f=a2(r,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=a2(t,n,r),s=a2(e,n,r);if(a!==0&&a===s)return!1;let i=a2(n,t,e),o=a2(r,t,e);return i!==0&&i===o?!1:a!==0||s!==0||i!==0||o!==0}function ut(t){if(t.length===0)return{left:0,top:0,right:0,bottom:0};let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of t)n.x<e.left&&(e.left=n.x),n.x>e.right&&(e.right=n.x),n.y<e.top&&(e.top=n.y),n.y>e.bottom&&(e.bottom=n.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function D9(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let r=n.x-e.x,c=n.y-e.y,a=de(t.x-e.x,r,t.y-e.y,c)/de(r,r,c,c),s=a<0?0:a>1?1:a;return{x:Math.round(e.x+s*r),y:Math.round(e.y+s*c),z:0}}function ge(t,e){let n=e.length,r=0;if(n<3)return G1.IsOutside;for(;r<n&&e[r].y===t.y;)r++;if(r===n)return G1.IsOutside;let c=e[r].y<t.y,a=c,s=0,i=r+1,o=n;for(;;){if(i===o){if(o===0||r===0)break;o=r,i=0}if(c)for(;i<o&&e[i].y<t.y;)i++;else for(;i<o&&e[i].y>t.y;)i++;if(i===o)continue;let h=e[i],u=i>0?e[i-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return G1.IsOn;if(i++,i===r)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)s=1-s;else{let f=a2(u,h,t);if(f===0)return G1.IsOn;f<0===c&&(s=1-s)}c=!c,i++}if(c===a)return s===0?G1.IsOutside:G1.IsInside;i===n&&(i=0);let l=i===0?a2(e[n-1],e[0],t):a2(e[i-1],e[i],t);return l===0?G1.IsOn:(l<0===c&&(s=1-s),s===0?G1.IsOutside:G1.IsInside)}function q9(t,e){let n=G1.IsOn;for(let i of t)switch(ge(i,e)){case G1.IsOutside:if(n===G1.IsOutside)return!1;n=G1.IsOutside;break;case G1.IsInside:if(n===G1.IsInside)return!0;n=G1.IsInside;break;default:break}let r=ut(t),c,a;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>Number.MAX_SAFE_INTEGER?(c=Number((BigInt(r.left)+BigInt(r.right))/Q5),a=Number((BigInt(r.top)+BigInt(r.bottom))/Q5)):(c=Math.round((r.left+r.right)/2),a=Math.round((r.top+r.bottom)/2)),ge({x:c,y:a},e)!==G1.IsOutside}var O1={MaxInt64:ve,MaxCoord:l5,max_coord:l5,min_coord:-l5,Invalid64:ot,floatingPointTolerance:lt,defaultMinimumEdgeLength:y9,maxCoordForSafeAreaProduct:pe,maxCoordForSafeCrossSq:b9,maxSafeCoordinateForScale:x9,checkSafeScaleValue:M9,ensureSafeInteger:w9,crossProduct:k9,crossProductSign:a2,checkPrecision:z9,isAlmostZero:S9,triSign:L9,multiplyUInt64:A9,productsAreEqual:ht,isCollinear:C9,dotProduct:P9,dotProductSign:E9,area:T9,crossProductD:I9,dotProductD:V9,roundToEven:H9,checkCastInt64:O9,getLineIntersectPt:F9,getLineIntersectPtD:R9,segsIntersect:$9,getBounds:ut,getClosestPtOnSegment:D9,pointInPolygon:ge,path2ContainsPath1:q9},z2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return O1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),O1.ensureSafeInteger(t.y,"Point64Utils.fromPointD"),{x:Math.round(t.x),y:Math.round(t.y),z:t.z||0}},scale(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e),z:t.z||0}},equals(t,e){return t.x===e.x&&t.y===e.y},add(t,e){if(Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(e.y)){let n=t.x+e.x,r=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?{x:n,y:r,z:0}:{x:Number(BigInt(t.x)+BigInt(e.x)),y:Number(BigInt(t.y)+BigInt(e.y)),z:0}}return{x:t.x+e.x,y:t.y+e.y,z:0}},subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:0}},toString(t){return t.z!==void 0&&t.z!==0?`${t.x},${t.y},${t.z} `:`${t.x},${t.y} `}},e4={create(t=0,e=0,n=0){return{x:t,y:e,z:n}},fromPoint64(t){return{x:t.x,y:t.y,z:t.z||0}},scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z||0}},equals(t,e){return O1.isAlmostZero(t.x-e.x)&&O1.isAlmostZero(t.y-e.y)},negate(t){t.x=-t.x,t.y=-t.y},toString(t,e=2){return t.z!==void 0&&t.z!==0?`${t.x.toFixed(e)},${t.y.toFixed(e)},${t.z}`:`${t.x.toFixed(e)},${t.y.toFixed(e)}`}},o3={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},isValid(t){return t.left<Number.MAX_SAFE_INTEGER},midPoint(t){if(Number.isSafeInteger(t.left)&&Number.isSafeInteger(t.right)&&Math.abs(t.left)+Math.abs(t.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(t.left)+BigInt(t.right))/Q5),n=Number((BigInt(t.top)+BigInt(t.bottom))/Q5);return{x:e,y:n}}return{x:Math.round((t.left+t.right)/2),y:Math.round((t.top+t.bottom)/2)}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<=Math.min(t.right,e.right)&&Math.max(t.top,e.top)<=Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}},ye={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},midPoint(t){return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<Math.min(t.right,e.right)&&Math.max(t.top,e.top)<Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}};var ft=Object.freeze(o3.createInvalid()),dt=Object.freeze(ye.createInvalid());var h5=BigInt(0),N9=BigInt(2),mt=BigInt(4),Z1;(function(t){t[t.None=0]="None",t[t.OpenStart=1]="OpenStart",t[t.OpenEnd=2]="OpenEnd",t[t.LocalMax=4]="LocalMax",t[t.LocalMin=8]="LocalMin"})(Z1||(Z1={}));var be=class{constructor(){_(this,"data",[])}push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],n=this.data.pop();return this.data.length>0&&(this.data[0]=n,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let n=this.data[e];for(;e>0;){let r=e-1>>1;if(this.data[r]>=n)break;this.data[e]=this.data[r],e=r}this.data[e]=n}siftDown(e){let n=this.data.length,r=this.data[e];for(;;){let c=(e<<1)+1;if(c>=n)break;let a=c+1,s=c;if(a<n&&this.data[a]>this.data[c]&&(s=a),this.data[s]<=r)break;this.data[e]=this.data[s],e=s}this.data[e]=r}},u5=class{constructor(e,n,r){_(this,"pt");_(this,"next",null);_(this,"prev",null);_(this,"flags");this.pt=e,this.flags=n,this.prev=r}},f5=class{constructor(e,n,r=!1){_(this,"vertex");_(this,"polytype");_(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=r}equals(e){return e!==null&&this.vertex===e.vertex}};function pt(t,e,n){return{pt:t,edge1:e,edge2:n}}var R2=class{constructor(e,n){_(this,"pt");_(this,"next");_(this,"prev");_(this,"outrec");_(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},N0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(N0||(N0={}));var xe;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(xe||(xe={}));var t4=class{constructor(){_(this,"idx",0);_(this,"owner",null);_(this,"frontEdge",null);_(this,"backEdge",null);_(this,"pts",null);_(this,"polypath",null);_(this,"bounds",{left:0,top:0,right:0,bottom:0});_(this,"path",[]);_(this,"isOpen",!1);_(this,"splits",null);_(this,"recursiveSplit",null)}},n4=class{constructor(e){_(this,"leftOp");_(this,"rightOp");_(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},d5=class{constructor(e,n){_(this,"op1");_(this,"op2");this.op1=e,this.op2=n}};function U9(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function B9(t,e){return t.pt.y!==e.pt.y?t.pt.y>e.pt.y?-1:1:t.pt.x!==e.pt.x?t.pt.x<e.pt.x?-1:1:t.edge1.curX!==e.edge1.curX?t.edge1.curX<e.edge1.curX?-1:1:t.edge2.curX<e.edge2.curX?-1:t.edge2.curX>e.edge2.curX?1:0}var m5=class{constructor(){_(this,"bot",{x:0,y:0});_(this,"top",{x:0,y:0});_(this,"curX",0);_(this,"dx",0);_(this,"windDx",0);_(this,"windCount",0);_(this,"windCount2",0);_(this,"outrec",null);_(this,"prevInAEL",null);_(this,"nextInAEL",null);_(this,"prevInSEL",null);_(this,"nextInSEL",null);_(this,"jump",null);_(this,"vertexTop",null);_(this,"localMin",null);_(this,"isLeftBound",!1);_(this,"joinWith",N0.None)}},T3={addLocMin(t,e,n,r){if((t.flags&Z1.LocalMin)!==Z1.None)return;t.flags|=Z1.LocalMin;let c=new f5(t,e,n);r.push(c)},addPathsToVertexList(t,e,n,r,c){for(let a=0,s=t.length;a<s;a++){let i=t[a],o=null,l=null,h=null;for(let m=0,g=i.length;m<g;m++){let p=i[m];if(o===null)o=new u5(p,Z1.None,null),c.push(o),l=o,h=p;else if(!(h.x===p.x&&h.y===p.y)){let v=new u5(p,Z1.None,l);l.next=v,l=v,h=p}}if(l?.prev==null||(!n&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!n&&l.next===l))continue;let u;if(n){let m=o.next;for(;m!==o&&m.pt.y===o.pt.y;)m=m.next;u=m.pt.y<=o.pt.y,u?(o.flags=Z1.OpenStart,T3.addLocMin(o,e,!0,r)):o.flags=Z1.OpenStart|Z1.LocalMax}else{for(l=o.prev;l!==o&&l.pt.y===o.pt.y;)l=l.prev;if(l===o)continue;u=l.pt.y>o.pt.y}let f=u;l=o;let d=o.next;for(;d!==o;)d.pt.y>l.pt.y&&u?(l.flags|=Z1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,T3.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=Z1.OpenEnd,u?l.flags|=Z1.LocalMax:T3.addLocMin(l,e,n,r)):u!==f&&(f?T3.addLocMin(l,e,!1,r):l.flags|=Z1.LocalMax)}}};var r4=class{constructor(e=null){_(this,"parent");_(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,n=this.parent;for(;n!==null;)++e,n=n.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)===0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,n){let r="",c=" ".repeat(n),a=this.children.length===1?"":"s";(n&1)===0?r+=`${c}+- hole (${e}) contains ${this.children.length} nested polygon${a}.
|
|
2
|
+
"use strict";var oe=Object.defineProperty;var W9=Object.getOwnPropertyDescriptor;var X9=Object.getOwnPropertyNames;var Z9=Object.prototype.hasOwnProperty;var Y9=(t,e,n)=>e in t?oe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var J9=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),K9=(t,e)=>{for(var n in e)oe(t,n,{get:e[n],enumerable:!0})},Q9=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of X9(e))!Z9.call(t,c)&&c!==n&&oe(t,c,{get:()=>e[c],enumerable:!(r=W9(e,c))||r.enumerable});return t};var er=t=>Q9(oe({},"__esModule",{value:!0}),t);var G=(t,e,n)=>Y9(t,typeof e!="symbol"?e+"":e,n);var Nn=J9((Cf,qn)=>{qn.exports={}});var kh={};K9(kh,{DEFAULT_LAYERS:()=>Z5,DEFAULT_LIMITS:()=>Dt,HARDWARE_COLORS:()=>Q2,HARDWARE_KINDS:()=>N2,KerfError:()=>i1,LANGUAGE_VERSION:()=>wh,SIGNATURES:()=>nt,VERSION:()=>Mh,bendPoint:()=>y3,diffRenders:()=>V8,effectsText:()=>G9,format:()=>e4,formatError:()=>P8,formatSignature:()=>Ie,importSvg:()=>t9,instructionsHtml:()=>$8,materialColor:()=>C6,meshBodies:()=>w4,meshPieces:()=>b3,parameters:()=>c5,parse:()=>e2,placementMatrix:()=>F0,poseAssembly:()=>M6,render:()=>Qe,settingEffects:()=>j9,shown:()=>Ke,signature:()=>Z3,snapshotFromRender:()=>x6,to3mf:()=>V6,toGlb:()=>H6,toModel:()=>B9,toStl:()=>I6,tokenize:()=>X3,triage:()=>w6,triageText:()=>$9,triangulate:()=>M4,verificationIsCurrent:()=>H9,verify:()=>O9});module.exports=er(kh);var r0;(function(t){t[t.NoClip=0]="NoClip",t[t.Intersection=1]="Intersection",t[t.Union=2]="Union",t[t.Difference=3]="Difference",t[t.Xor=4]="Xor"})(r0||(r0={}));var $0;(function(t){t[t.Subject=0]="Subject",t[t.Clip=1]="Clip"})($0||($0={}));var U1;(function(t){t[t.EvenOdd=0]="EvenOdd",t[t.NonZero=1]="NonZero",t[t.Positive=2]="Positive",t[t.Negative=3]="Negative"})(U1||(U1={}));var _1;(function(t){t[t.IsOn=0]="IsOn",t[t.IsInside=1]="IsInside",t[t.IsOutside=2]="IsOutside"})(_1||(_1={}));var R3=Number.MAX_SAFE_INTEGER,M0=Math.floor(Math.sqrt(R3));function ie(t,e){return!Number.isSafeInteger(t)||!Number.isSafeInteger(e)?!1:t===0||e===0?!0:Math.abs(t)<=R3/Math.abs(e)}function $6(t,e){return Math.abs(t)+Math.abs(e)<=R3}function z4(t,e,n,r){if(ie(t,e)&&ie(n,r)){let c=t*e,a=n*r;if($6(c,a))return c-a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)-BigInt(n)*BigInt(r)):t*e-n*r}function S4(t,e,n,r){if(ie(t,e)&&ie(n,r)){let c=t*e,a=n*r;if($6(c,a))return c+a}return Number.isSafeInteger(t)&&Number.isSafeInteger(e)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(t)*BigInt(e)+BigInt(n)*BigInt(r)):t*e+n*r}var A4=BigInt(0),le=BigInt(2),tr=BigInt(4),nr=BigInt(64),rr=BigInt("0xFFFFFFFFFFFFFFFF"),P4=BigInt("9223372036854775807"),y5=Number(P4/tr),R6=Number(P4),F6=1e-12,cr=.1,L4=Math.floor(M0/2),ar=Math.floor(Math.sqrt(Math.sqrt(R3/4)));function sr(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:R3/e}function or(t,e,n){if(!Number.isFinite(t)||Math.abs(t)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function ir(t,e){if(!Number.isFinite(t)||Math.abs(t)>R3)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function lr(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0?r*c-a*s:z4(r,c,a,s)}function l2(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;if(Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0){let l=r*c,h=a*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let l=r*c,h=a*s;return l>h?1:l<h?-1:0}let o=BigInt(r)*BigInt(c),i=BigInt(a)*BigInt(s);return o===i?0:o>i?1:-1}function hr(t){if(t<-8||t>8)throw new Error("Error: Precision is out of range.")}function ur(t){return Math.abs(t)<=F6}function fr(t){return t<0?-1:t>0?1:0}function dr(t,e){let n=BigInt(t),r=BigInt(e),c=n*r;return{lo64:c&rr,hi64:c>>nr}}function D6(t,e,n,r){let c=Math.abs(t),a=Math.abs(e),s=Math.abs(n),o=Math.abs(r);if(c<M0&&a<M0&&s<M0&&o<M0)return t*e===n*r;let i=(t<0?-1:t>0?1:0)*(e<0?-1:e>0?1:0),l=(n<0?-1:n>0?1:0)*(r<0?-1:r>0?1:0);if(i!==l)return!1;if(i===0)return!0;if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)||!Number.isSafeInteger(o))return t*e===n*r;let h=BigInt(c),u=BigInt(a),f=BigInt(s),d=BigInt(o);return h*u===f*d}function mr(t,e,n){let r=e.x-t.x,c=n.y-e.y,a=e.y-t.y,s=n.x-e.x;return D6(r,c,a,s)}function pr(t,e,n){let r=e.x-t.x,c=n.x-e.x,a=e.y-t.y,s=n.y-e.y;return Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0?r*c+a*s:S4(r,c,a,s)}function gr(t,e,n){let r=e.x-t.x,c=n.x-e.x,a=e.y-t.y,s=n.y-e.y;if(Math.abs(r)<M0&&Math.abs(c)<M0&&Math.abs(a)<M0&&Math.abs(s)<M0){let i=r*c+a*s;return i>0?1:i<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(s)){let i=r*c+a*s;return i>0?1:i<0?-1:0}let o=BigInt(r)*BigInt(c)+BigInt(a)*BigInt(s);return o===A4?0:o>A4?1:-1}function vr(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)>=L4||Math.abs(s.y)>=L4)&&(n=!1)}let r=t[e-1];if(n){let a=0;for(let s of t)a+=(r.y+s.y)*(r.x-s.x),r=s;return a*.5}let c=A4;for(let a of t){let s=r.y+a.y,o=r.x-a.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(o))c+=BigInt(s)*BigInt(o);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(a.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(a.x)){let i=BigInt(r.y)+BigInt(a.y),l=BigInt(r.x)-BigInt(a.x);c+=i*l}else c+=BigInt(Math.round(s*o));r=a}return Number(c)*.5}function yr(t,e){return t.y*e.x-e.y*t.x}function br(t,e){return t.x*e.x+t.y*e.y}function xr(t){let e=Math.round(t);return t===e-.5&&(e&1)!==0?e-1:e}function Mr(t){return t>=y5||t<=-y5?R6:Math.round(t)}function wr(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,o=r.x-n.x,i=z4(c,o,s,a);if(i===0)return null;let l=z4(t.x-n.x,s,t.y-n.y,o)/i;return l<=0?{x:t.x,y:t.y,z:t.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(t.x+l*a),y:Math.trunc(t.y+l*c),z:0}}function kr(t,e,n,r){let c=e.y-t.y,a=e.x-t.x,s=r.y-n.y,o=r.x-n.x,i=c*o-s*a;if(i===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((t.x-n.x)*s-(t.y-n.y)*o)/i,h;return l<=0?h={...t,z:0}:l>=1?h={...e,z:0}:h={x:t.x+l*a,y:t.y+l*c,z:0},{success:!0,ip:h}}function zr(t,e,n,r,c=!1){if(!c){let l=l2(t,n,r),h=l2(e,n,r),u=l2(n,t,e),f=l2(r,t,e);return l!==0&&h!==0&&l!==h&&u!==0&&f!==0&&u!==f}let a=l2(t,n,r),s=l2(e,n,r);if(a!==0&&a===s)return!1;let o=l2(n,t,e),i=l2(r,t,e);return o!==0&&o===i?!1:a!==0||s!==0||o!==0||i!==0}function q6(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 Sr(t,e,n){if(e.x===n.x&&e.y===n.y)return{x:e.x,y:e.y,z:0};let r=n.x-e.x,c=n.y-e.y,a=S4(t.x-e.x,r,t.y-e.y,c)/S4(r,r,c,c),s=a<0?0:a>1?1:a;return{x:Math.round(e.x+s*r),y:Math.round(e.y+s*c),z:0}}function C4(t,e){let n=e.length,r=0;if(n<3)return _1.IsOutside;for(;r<n&&e[r].y===t.y;)r++;if(r===n)return _1.IsOutside;let c=e[r].y<t.y,a=c,s=0,o=r+1,i=n;for(;;){if(o===i){if(i===0||r===0)break;i=r,o=0}if(c)for(;o<i&&e[o].y<t.y;)o++;else for(;o<i&&e[o].y>t.y;)o++;if(o===i)continue;let h=e[o],u=o>0?e[o-1]:e[n-1];if(h.y===t.y){if(h.x===t.x||h.y===u.y&&t.x<u.x!=t.x<h.x)return _1.IsOn;if(o++,o===r)break;continue}if(!(t.x<h.x&&t.x<u.x))if(t.x>u.x&&t.x>h.x)s=1-s;else{let f=l2(u,h,t);if(f===0)return _1.IsOn;f<0===c&&(s=1-s)}c=!c,o++}if(c===a)return s===0?_1.IsOutside:_1.IsInside;o===n&&(o=0);let l=o===0?l2(e[n-1],e[0],t):l2(e[o-1],e[o],t);return l===0?_1.IsOn:(l<0===c&&(s=1-s),s===0?_1.IsOutside:_1.IsInside)}function Ar(t,e){let n=_1.IsOn;for(let o of t)switch(C4(o,e)){case _1.IsOutside:if(n===_1.IsOutside)return!1;n=_1.IsOutside;break;case _1.IsInside:if(n===_1.IsInside)return!0;n=_1.IsInside;break;default:break}let r=q6(t),c,a;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>Number.MAX_SAFE_INTEGER?(c=Number((BigInt(r.left)+BigInt(r.right))/le),a=Number((BigInt(r.top)+BigInt(r.bottom))/le)):(c=Math.round((r.left+r.right)/2),a=Math.round((r.top+r.bottom)/2)),C4({x:c,y:a},e)!==_1.IsOutside}var R1={MaxInt64:P4,MaxCoord:y5,max_coord:y5,min_coord:-y5,Invalid64:R6,floatingPointTolerance:F6,defaultMinimumEdgeLength:cr,maxCoordForSafeAreaProduct:L4,maxCoordForSafeCrossSq:ar,maxSafeCoordinateForScale:sr,checkSafeScaleValue:or,ensureSafeInteger:ir,crossProduct:lr,crossProductSign:l2,checkPrecision:hr,isAlmostZero:ur,triSign:fr,multiplyUInt64:dr,productsAreEqual:D6,isCollinear:mr,dotProduct:pr,dotProductSign:gr,area:vr,crossProductD:yr,dotProductD:br,roundToEven:xr,checkCastInt64:Mr,getLineIntersectPt:wr,getLineIntersectPtD:kr,segsIntersect:zr,getBounds:q6,getClosestPtOnSegment:Sr,pointInPolygon:C4,path2ContainsPath1:Ar},S2={create(t=0,e=0,n=0){return{x:Math.round(t),y:Math.round(e),z:n}},fromPointD(t){return R1.ensureSafeInteger(t.x,"Point64Utils.fromPointD"),R1.ensureSafeInteger(t.y,"Point64Utils.fromPointD"),{x:Math.round(t.x),y:Math.round(t.y),z:t.z||0}},scale(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e),z:t.z||0}},equals(t,e){return t.x===e.x&&t.y===e.y},add(t,e){if(Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(e.y)){let n=t.x+e.x,r=t.y+e.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?{x:n,y:r,z:0}:{x:Number(BigInt(t.x)+BigInt(e.x)),y:Number(BigInt(t.y)+BigInt(e.y)),z:0}}return{x:t.x+e.x,y:t.y+e.y,z:0}},subtract(t,e){return{x:t.x-e.x,y:t.y-e.y,z:0}},toString(t){return t.z!==void 0&&t.z!==0?`${t.x},${t.y},${t.z} `:`${t.x},${t.y} `}},he={create(t=0,e=0,n=0){return{x:t,y:e,z:n}},fromPoint64(t){return{x:t.x,y:t.y,z:t.z||0}},scale(t,e){return{x:t.x*e,y:t.y*e,z:t.z||0}},equals(t,e){return R1.isAlmostZero(t.x-e.x)&&R1.isAlmostZero(t.y-e.y)},negate(t){t.x=-t.x,t.y=-t.y},toString(t,e=2){return t.z!==void 0&&t.z!==0?`${t.x.toFixed(e)},${t.y.toFixed(e)},${t.z}`:`${t.x.toFixed(e)},${t.y.toFixed(e)}`}},d3={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},isValid(t){return t.left<Number.MAX_SAFE_INTEGER},midPoint(t){if(Number.isSafeInteger(t.left)&&Number.isSafeInteger(t.right)&&Math.abs(t.left)+Math.abs(t.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(t.left)+BigInt(t.right))/le),n=Number((BigInt(t.top)+BigInt(t.bottom))/le);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}]}},E4={create(t=0,e=0,n=0,r=0){return{left:t,top:e,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(t){return t.right-t.left},height(t){return t.bottom-t.top},isEmpty(t){return t.bottom<=t.top||t.right<=t.left},midPoint(t){return{x:(t.left+t.right)/2,y:(t.top+t.bottom)/2}},contains(t,e){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom},containsRect(t,e){return e.left>=t.left&&e.right<=t.right&&e.top>=t.top&&e.bottom<=t.bottom},intersects(t,e){return Math.max(t.left,e.left)<Math.min(t.right,e.right)&&Math.max(t.top,e.top)<Math.min(t.bottom,e.bottom)},asPath(t){return[{x:t.left,y:t.top,z:0},{x:t.right,y:t.top,z:0},{x:t.right,y:t.bottom,z:0},{x:t.left,y:t.bottom,z:0}]}};var N6=Object.freeze(d3.createInvalid()),U6=Object.freeze(E4.createInvalid());var b5=BigInt(0),Lr=BigInt(2),B6=BigInt(4),Y1;(function(t){t[t.None=0]="None",t[t.OpenStart=1]="OpenStart",t[t.OpenEnd=2]="OpenEnd",t[t.LocalMax=4]="LocalMax",t[t.LocalMin=8]="LocalMin"})(Y1||(Y1={}));var T4=class{constructor(){G(this,"data",[])}push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],n=this.data.pop();return this.data.length>0&&(this.data[0]=n,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let n=this.data[e];for(;e>0;){let r=e-1>>1;if(this.data[r]>=n)break;this.data[e]=this.data[r],e=r}this.data[e]=n}siftDown(e){let n=this.data.length,r=this.data[e];for(;;){let c=(e<<1)+1;if(c>=n)break;let a=c+1,s=c;if(a<n&&this.data[a]>this.data[c]&&(s=a),this.data[s]<=r)break;this.data[e]=this.data[s],e=s}this.data[e]=r}},x5=class{constructor(e,n,r){G(this,"pt");G(this,"next",null);G(this,"prev",null);G(this,"flags");this.pt=e,this.flags=n,this.prev=r}},M5=class{constructor(e,n,r=!1){G(this,"vertex");G(this,"polytype");G(this,"isOpen");this.vertex=e,this.polytype=n,this.isOpen=r}equals(e){return e!==null&&this.vertex===e.vertex}};function _6(t,e,n){return{pt:t,edge1:e,edge2:n}}var F2=class{constructor(e,n){G(this,"pt");G(this,"next");G(this,"prev");G(this,"outrec");G(this,"horz");this.pt=e,this.outrec=n,this.next=this,this.prev=this,this.horz=null}},B0;(function(t){t[t.None=0]="None",t[t.Left=1]="Left",t[t.Right=2]="Right"})(B0||(B0={}));var I4;(function(t){t[t.Bottom=0]="Bottom",t[t.Middle=1]="Middle",t[t.Top=2]="Top"})(I4||(I4={}));var ue=class{constructor(){G(this,"idx",0);G(this,"owner",null);G(this,"frontEdge",null);G(this,"backEdge",null);G(this,"pts",null);G(this,"polypath",null);G(this,"bounds",{left:0,top:0,right:0,bottom:0});G(this,"path",[]);G(this,"isOpen",!1);G(this,"splits",null);G(this,"recursiveSplit",null)}},fe=class{constructor(e){G(this,"leftOp");G(this,"rightOp");G(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},w5=class{constructor(e,n){G(this,"op1");G(this,"op2");this.op1=e,this.op2=n}};function Cr(t,e){return t.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:t.leftOp.pt.x-e.leftOp.pt.x}function Pr(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 k5=class{constructor(){G(this,"bot",{x:0,y:0});G(this,"top",{x:0,y:0});G(this,"curX",0);G(this,"dx",0);G(this,"windDx",0);G(this,"windCount",0);G(this,"windCount2",0);G(this,"outrec",null);G(this,"prevInAEL",null);G(this,"nextInAEL",null);G(this,"prevInSEL",null);G(this,"nextInSEL",null);G(this,"jump",null);G(this,"vertexTop",null);G(this,"localMin",null);G(this,"isLeftBound",!1);G(this,"joinWith",B0.None)}},F3={addLocMin(t,e,n,r){if((t.flags&Y1.LocalMin)!==Y1.None)return;t.flags|=Y1.LocalMin;let c=new M5(t,e,n);r.push(c)},addPathsToVertexList(t,e,n,r,c){for(let a=0,s=t.length;a<s;a++){let o=t[a],i=null,l=null,h=null;for(let p=0,m=o.length;p<m;p++){let g=o[p];if(i===null)i=new x5(g,Y1.None,null),c.push(i),l=i,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new x5(g,Y1.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!n&&l.pt.x===i.pt.x&&l.pt.y===i.pt.y&&(l=l.prev),l.next=i,i.prev=l,!n&&l.next===l))continue;let u;if(n){let p=i.next;for(;p!==i&&p.pt.y===i.pt.y;)p=p.next;u=p.pt.y<=i.pt.y,u?(i.flags=Y1.OpenStart,F3.addLocMin(i,e,!0,r)):i.flags=Y1.OpenStart|Y1.LocalMax}else{for(l=i.prev;l!==i&&l.pt.y===i.pt.y;)l=l.prev;if(l===i)continue;u=l.pt.y>i.pt.y}let f=u;l=i;let d=i.next;for(;d!==i;)d.pt.y>l.pt.y&&u?(l.flags|=Y1.LocalMax,u=!1):d.pt.y<l.pt.y&&!u&&(u=!0,F3.addLocMin(l,e,n,r)),l=d,d=d.next;n?(l.flags|=Y1.OpenEnd,u?l.flags|=Y1.LocalMax:F3.addLocMin(l,e,n,r)):u!==f&&(f?F3.addLocMin(l,e,!1,r):l.flags|=Y1.LocalMax)}}};var de=class{constructor(e=null){G(this,"parent");G(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,n=this.parent;for(;n!==null;)++e,n=n.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)===0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,n){let r="",c=" ".repeat(n),a=this.children.length===1?"":"s";(n&1)===0?r+=`${c}+- hole (${e}) contains ${this.children.length} nested polygon${a}.
|
|
3
3
|
`:r+=`${c}+- polygon (${e}) contains ${this.children.length} hole${a}.
|
|
4
4
|
`;for(let s=0;s<this.count;s++)this.children[s].count>0&&(r+=this.children[s].toStringInternal(s,n+1));return r}toString(){if(this.level>0)return"";let e=this.children.length===1?"":"s",n=`Polytree with ${this.children.length} polygon${e}.
|
|
5
5
|
`;for(let r=0;r<this.count;r++)this.children[r].count>0&&(n+=this.children[r].toStringInternal(r,1));return n+`
|
|
6
|
-
`}},c4=class t extends r4{constructor(n=null){super(n);_(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let r=new t(this);return r.polygon=n,this.children.push(r),r}child(n){if(n<0||n>=this.children.length)throw new Error("Index out of range");return this.children[n]}area(){let n=this.polygon===null?0:Me.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var p5=class extends c4{};var F=class F{constructor(){_(this,"cliptype",t0.NoClip);_(this,"fillrule",_1.EvenOdd);_(this,"actives",null);_(this,"sel",null);_(this,"minimaList",[]);_(this,"intersectList",[]);_(this,"vertexList",[]);_(this,"outrecList",[]);_(this,"scanlineHeap",new be);_(this,"scanlineSet",new Set);_(this,"scanlineArr",[]);_(this,"useScanlineArray",!1);_(this,"horzSegList",[]);_(this,"horzJoinList",[]);_(this,"currentLocMin",0);_(this,"currentBotY",0);_(this,"curXValidAtTop",!1);_(this,"isSortedMinimaList",!1);_(this,"hasOpenPaths",!1);_(this,"usingPolytree",!1);_(this,"succeeded",!1);_(this,"zCallbackInternal");_(this,"preserveCollinear",!0);_(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,r){let c=this.zCallbackInternal;c&&(F.getPolyType(e)===H0.Subject?(this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:r.z=0,c(e.bot,e.top,n.bot,n.top,r)):(this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:r.z=0,c(n.bot,n.top,e.bot,e.top,r)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return F.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return F.openPathsEnabled&&e.localMin.isOpen&&F.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(Z1.OpenStart|Z1.OpenEnd))!==Z1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!F.openPathsEnabled){for(;n!==null&&!F.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!F.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let r=n.y-e.y;return r!==0?(n.x-e.x)/r:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:O1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=F.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&Z1.LocalMax)!==Z1.None}static isMaximaEdge(e){return(e.vertexTop.flags&Z1.LocalMax)!==Z1.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,r,c){let a=e.x<n.x?e.x:n.x;if((r.x>c.x?r.x:c.x)<a)return!1;let i=e.x>n.x?e.x:n.x,o=r.x<c.x?r.x:c.x;if(i<o)return!1;let l=e.y<n.y?e.y:n.y;if((r.y>c.y?r.y:c.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=r.y<c.y?r.y:c.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,r=e.length;n<r;n++){let c=e[n];this.scanlineSet.add(c),this.scanlineHeap.push(c)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let r=0,c=n.length;r<c;r++)if(n[r]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,r=n.length;if(r===0)return null;let c=0,a=n[0];for(let s=1;s<r;s++){let i=n[s];i>a&&(a=i,c=s)}return n[c]=n[r-1],n.pop(),a}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,r=!1){let c=[e];this.addPaths(c,n,r)}addPaths(e,n,r=!1){r&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,T3.addPathsToVertexList(e,n,r,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new f5(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,r=e.nextInAEL;n===null&&r===null&&e!==this.actives||(n!==null?n.nextInAEL=r:this.actives=r,r!==null&&(r.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let r=n;do r.pt.x<e.left&&(e.left=r.pt.x),r.pt.x>e.right&&(e.right=r.pt.x),r.pt.y<e.top&&(e.top=r.pt.y),r.pt.y>e.bottom&&(e.bottom=r.pt.y),r=r.next;while(r!==n)}return o3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===t0.NoClip)return;F.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let r=this.popScanline();if(r!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(r);let c;for(;(c=this.popHorz())!==null;)this.doHorizontal(c);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=r;let a=this.popScanline();if(a===null)break;for(r=a,this.doIntersections(r),this.doTopOfScanbeam(r);(c=this.popHorz())!==null;)this.doHorizontal(c)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),r;(n.vertex.flags&Z1.OpenStart)!==Z1.None?r=null:(r=new m5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=-1,r.vertexTop=n.vertex.prev,r.top=n.vertex.prev.pt,r.outrec=null,r.localMin=n,F.setDx(r));let c;if((n.vertex.flags&Z1.OpenEnd)!==Z1.None?c=null:(c=new m5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=1,c.vertexTop=n.vertex.next,c.top=n.vertex.next.pt,c.outrec=null,c.localMin=n,F.setDx(c)),r!==null&&c!==null){if(F.isHorizontal(r)){if(F.isHeadingRightHorz(r)){let s=r;r=c,c=s}}else if(F.isHorizontal(c)){if(F.isHeadingLeftHorz(c)){let s=r;r=c,c=s}}else if(r.dx<c.dx){let s=r;r=c,c=s}}else r===null&&(r=c,c=null);let a;if(r.isLeftBound=!0,this.insertLeftEdge(r),F.openPathsEnabled?F.isOpen(r)?(this.setWindCountForOpenPathEdge(r),a=this.isContributingOpen(r)):(this.setWindCountForClosedPathEdge(r),a=this.isContributingClosed(r)):(this.setWindCountForClosedPathEdge(r),a=this.isContributingClosed(r)),c!==null){for(c.windCount=r.windCount,c.windCount2=r.windCount2,this.insertRightEdge(r,c),a&&(this.addLocalMinPoly(r,c,r.bot,!0),F.isHorizontal(r)||this.checkJoinLeft(r,r.bot));c.nextInAEL!==null&&this.isValidAelOrder(c.nextInAEL,c);)this.intersectEdges(c,c.nextInAEL,c.bot),this.swapPositionsInAEL(c,c.nextInAEL);F.isHorizontal(c)?this.pushHorz(c):(this.checkJoinRight(c,c.bot),this.insertScanline(c.top.y))}else a&&F.openPathsEnabled&&this.startOpenPath(r,r.bot);F.isHorizontal(r)?this.pushHorz(r):this.insertScanline(r.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!F.openPathsEnabled){this.doHorizontalClosed(e);return}let n=F.isOpen(e),r=e.bot.y,c=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:i}=this.resetHorzDirection(e,c),o=s,l=i;if(F.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:r});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===c){if(F.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),F.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(c!==e.vertexTop||F.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<o)break;if(h.curX===e.top.x&&!F.isHorizontal(h)){let d=F.nextVertex(e).pt;if(F.isOpen(h)&&!F.isSamePolyType(h,e)&&!F.isHotEdge(h)){if(a&&F.topX(h,d.y)>d.x||!a&&F.topX(h,d.y)<d.x)break}else if(a&&F.topX(h,d.y)>=d.x||!a&&F.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:r};a?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&F.isOpenEnd(e)){F.isHotEdge(e)&&(this.addOutPt(e,e.top),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,c);o=u.leftX,l=u.rightX}if(F.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,r=this.getCurrYMaximaVertex(e),{isLeftToRight:c,leftX:a,rightX:s}=this.resetHorzDirection(e,r),i=a,o=s;if(F.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=c?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===r){if(F.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),F.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);c?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(r!==e.vertexTop){if(c&&l.curX>o||!c&&l.curX<i)break;if(l.curX===e.top.x&&!F.isHorizontal(l)){let f=F.nextVertex(e).pt,d=F.topX(l,f.y);if(c&&d>=f.x||!c&&d<=f.x)break}}let u={x:l.curX,y:n};c?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),F.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(F.nextVertex(e).pt.y!==e.top.y)break;F.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,r);i=h.leftX,o=h.rightX}if(F.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let r=0,c=e.length;r<c;r++){let a=e[r];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(U9);for(let r=0;r<n-1;r++){let c=this.horzSegList[r];for(let a=r+1;a<n;a++){let s=this.horzSegList[a];if(s.leftOp.pt.x>=c.rightOp.pt.x||s.leftToRight===c.leftToRight||s.rightOp.pt.x<=c.leftOp.pt.x)continue;let i=c.leftOp.pt.y;if(c.leftToRight){for(;c.leftOp.next.pt.y===i&&c.leftOp.next.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new d5(this.duplicateOp(c.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;c.leftOp.prev.pt.y===i&&c.leftOp.prev.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new d5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(c.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let n=e.leftOp,r=this.getRealOutRec(n.outrec),c=r.frontEdge!==null,a=n.pt.y,s=n,i=n;if(c){let l=r.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;i!==l&&i.next.pt.y===a;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===a;)s=s.prev;for(;i.next!==s&&i.next.pt.y===a;)i=i.next}let o=this.setHorzSegHeadingForward(e,s,i)&&e.leftOp.horz===null;return o?e.leftOp.horz=e:e.rightOp=null,o}setHorzSegHeadingForward(e,n,r){return n.pt.x===r.pt.x?!1:(n.pt.x<r.pt.x?(e.leftOp=n,e.rightOp=r,e.leftToRight=!0):(e.leftOp=r,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let r=new R2(e.pt,e.outrec);return n?(r.next=e.next,r.next.prev=r,r.prev=e,e.next=r):(r.prev=e.prev,r.prev.next=r,r.next=e,e.prev=r),r}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let r=this.actives;for(;r!==null;){if(r.top.y===e)if(r.curX=r.top.x,F.isMaximaEdge(r)){r=this.doMaxima(r);continue}else F.isHotEdge(r)&&this.addOutPt(r,r.top),this.updateEdgeIntoAEL(r),F.isHorizontal(r)&&this.pushHorz(r);else n||(r.curX=F.topX(r,e));r=r.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),r=this.getRealOutRec(e.op2.outrec),c=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,c.prev=a,a.next=c,n===r){let s=this.newOutRec();s.pts=c,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.owner=n}else r.pts=null,this.usingPolytree?(this.setOwner(r,n),this.moveSplits(r,n)):r.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let r=G1.IsOn,c=e;do{switch(this.pointInOpPolygon(c.pt,n)){case G1.IsOutside:if(r===G1.IsOutside)return!1;r=G1.IsOutside;break;case G1.IsInside:if(r===G1.IsInside)return!0;r=G1.IsInside;break;default:break}c=c.next}while(c!==e);return O1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return G1.IsOutside;let r=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==r);if(n.pt.y===e.y)return G1.IsOutside;let c=n.pt.y<e.y,a=c,s=0;for(r=n.next;r!==n;){if(c)for(;r!==n&&r.pt.y<e.y;)r=r.next;else for(;r!==n&&r.pt.y>e.y;)r=r.next;if(r===n)break;if(r.pt.y===e.y){if(r.pt.x===e.x||r.pt.y===r.prev.pt.y&&e.x<r.prev.pt.x!=e.x<r.pt.x)return G1.IsOn;if(r=r.next,r===n)break;continue}if(r.pt.x<=e.x||r.prev.pt.x<=e.x)if(r.prev.pt.x<e.x&&r.pt.x<e.x)s=1-s;else{let i=O1.crossProductSign(r.prev.pt,r.pt,e);if(i===0)return G1.IsOn;i<0===c&&(s=1-s)}c=!c,r=r.next}if(c===a)return s===0?G1.IsOutside:G1.IsInside;{let i=O1.crossProductSign(r.prev.pt,r.pt,e);if(i===0)return G1.IsOn;i<0===c&&(s=1-s)}return s===0?G1.IsOutside:G1.IsInside}getCleanPath(e){let n=[],r=e;for(;r.next!==e&&(r.pt.x===r.next.pt.x&&r.pt.x===r.prev.pt.x||r.pt.y===r.next.pt.y&&r.pt.y===r.prev.pt.y);)r=r.next;n.push(r.pt);let c=r;for(r=r.next;r!==e;)(r.pt.x!==r.next.pt.x||r.pt.x!==c.pt.x)&&(r.pt.y!==r.next.pt.y||r.pt.y!==c.pt.y)&&(n.push(r.pt),c=r),r=r.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let r of e.splits)r!==n.idx&&n.splits.push(r);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let r=null;for(;n!==null&&n.jump!==null;){let c=n,a=n.jump,s=a,i=a?.jump||null;for(n.jump=i;n!==s&&a!==i;)if(a.curX<n.curX){let o=a.prevInSEL;for(;this.addNewIntersectNode(o,a,e),o!==n;)o=o.prevInSEL;if(o=a,a=this.extractFromSEL(o),s=a,n!==null&&this.insert1Before2InSEL(o,n),n!==c)continue;c=o,c.jump=i,r===null?this.sel=c:r.jump=c}else n=n.nextInSEL;r=c,n=i}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(B9);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let r=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[r]);)r++;[this.intersectList[r],this.intersectList[e]]=[this.intersectList[e],this.intersectList[r]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let r=Number.NEGATIVE_INFINITY,c=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=F.topX(n,e);n.curX=a,a<r&&(c=!0),r=a,n=n.nextInAEL}return c}doMaxima(e){let n=e.prevInAEL,r=e.nextInAEL;if(F.isOpenEnd(e))return F.isHotEdge(e)&&this.addOutPt(e,e.top),F.isHorizontal(e)||(F.isHotEdge(e)&&(F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),r;let c=F.getMaximaPair(e);if(c===null)return r;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(c)&&this.split(c,c.top);r!==c;)this.intersectEdges(e,r,e.top),this.swapPositionsInAEL(e,r),r=e.nextInAEL;return F.isOpen(e)?(F.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(c),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):(F.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(e),this.deleteFromAEL(c),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=F.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,F.setDx(e),this.isJoined(e)&&this.split(e,e.bot),F.isHorizontal(e)){F.openPathsEnabled?F.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let r=!1,c=F.nextVertex(e).pt;for(;c.y===e.top.y&&!(n&&c.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=F.nextVertex(e),e.top=c,r=!0,F.isMaximaVertex(e.vertexTop)));)c=F.nextVertex(e).pt;r&&F.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new n4(e))}addNewIntersectNode(e,n,r){let c=O1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(c===null&&(c={x:e.curX,y:r}),c.y>this.currentBotY||c.y<r){let s=Math.abs(e.dx),i=Math.abs(n.dx);s>100&&i>100?s>i?c=O1.getClosestPtOnSegment(c,e.bot,e.top):c=O1.getClosestPtOnSegment(c,n.bot,n.top):s>100?c=O1.getClosestPtOnSegment(c,e.bot,e.top):i>100?c=O1.getClosestPtOnSegment(c,n.bot,n.top):(c.y<r?c.y=r:c.y=this.currentBotY,s<i?c.x=F.topX(e,c.y):c.x=F.topX(n,c.y))}let a=pt(c,e,n);this.intersectList.push(a)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(Z1.OpenEnd|Z1.LocalMax))===Z1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(Z1.OpenEnd|Z1.LocalMax))===Z1.None;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return F.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let r=e.curX,c=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:r,rightX:c}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===N0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===_1.EvenOdd){let r=0,c=0;for(;n!==e;)F.getPolyType(n)===H0.Clip?c++:F.isOpen(n)||r++,n=n.nextInAEL;e.windCount=F.isOdd(r)?1:0,e.windCount2=F.isOdd(c)?1:0}else for(;n!==e;)F.getPolyType(n)===H0.Clip?e.windCount2+=n.windDx:F.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,r=F.getPolyType(e);if(!F.openPathsEnabled){for(;n!==null&&F.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===_1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===_1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(F.getPolyType(n)!==r||F.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===_1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=F.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===_1.EvenOdd)for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)F.getPolyType(n)!==r&&!F.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,r;switch(this.fillrule){case _1.Positive:r=e.windCount>0,n=e.windCount2>0;break;case _1.Negative:r=e.windCount<0,n=e.windCount2<0;break;default:r=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case t0.Intersection:return n;case t0.Union:return!r&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case _1.Positive:if(e.windCount!==1)return!1;break;case _1.Negative:if(e.windCount!==-1)return!1;break;case _1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case t0.Intersection:return this.fillrule===_1.Positive?e.windCount2>0:this.fillrule===_1.Negative?e.windCount2<0:e.windCount2!==0;case t0.Union:return this.fillrule===_1.Positive?e.windCount2<=0:this.fillrule===_1.Negative?e.windCount2>=0:e.windCount2===0;case t0.Difference:{let n=this.fillrule===_1.Positive?e.windCount2<=0:this.fillrule===_1.Negative?e.windCount2>=0:e.windCount2===0;return F.getPolyType(e)===H0.Subject?n:!n}case t0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,r,c=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,F.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let i=F.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(a,i.outrec),a.owner=i.outrec,this.outrecIsAscending(i)===c?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,c?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new R2(r,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new t4;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let r=this.newOutRec();r.isOpen=!0,e.windDx>0?(r.frontEdge=e,r.backEdge=null):(r.frontEdge=null,r.backEdge=e),e.outrec=r;let c=new R2(n,r);return r.pts=c,c}checkJoinLeft(e,n,r=!1){let c=e.prevInAEL;c!==null&&(!r&&e.curX!==c.curX||!F.isHotEdge(e)||!F.isHotEdge(c)||F.isHorizontal(e)||F.isHorizontal(c)||F.isOpen(e)||F.isOpen(c)||(n.y<e.top.y+2||n.y<c.top.y+2)&&(e.bot.y>n.y||c.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,c.bot,c.top)||O1.isCollinear(e.top,n,c.top)&&(e.outrec.idx===c.outrec.idx?this.addLocalMaxPoly(c,e,n):e.outrec.idx<c.outrec.idx?this.joinOutrecPaths(e,c):this.joinOutrecPaths(c,e),c.joinWith=N0.Right,e.joinWith=N0.Left))}checkJoinRight(e,n,r=!1){let c=e.nextInAEL;c!==null&&(!r&&e.curX!==c.curX||!F.isHotEdge(e)||!F.isHotEdge(c)||F.isHorizontal(e)||F.isHorizontal(c)||F.isOpen(e)||F.isOpen(c)||(n.y<e.top.y+2||n.y<c.top.y+2)&&(e.bot.y>n.y||c.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,c.bot,c.top)||O1.isCollinear(e.top,n,c.top)&&(e.outrec.idx===c.outrec.idx?this.addLocalMaxPoly(e,c,n):e.outrec.idx<c.outrec.idx?this.joinOutrecPaths(e,c):this.joinOutrecPaths(c,e),e.joinWith=N0.Right,c.joinWith=N0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,r){let c=e.x-n.x,a=e.y-n.y,s=r.x-n.x,i=r.y-n.y;if(s===0&&i===0)return!1;let o=O1.maxCoordForSafeCrossSq;if(Math.abs(c)<o&&Math.abs(a)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=c*i-s*a;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(c)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(c)*BigInt(i)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return mt*u>f}let l=c*i-s*a;return l*l/(s*s+i*i)>.25}intersectEdges(e,n,r){let c;if(this.hasOpenPaths&&(F.isOpen(e)||F.isOpen(n))){if(F.isOpen(e)&&F.isOpen(n))return;if(F.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,r),this.cliptype===t0.Union){if(!F.isHotEdge(n))return}else if(n.localMin.polytype===H0.Subject)return;switch(this.fillrule){case _1.Positive:if(n.windCount!==1)return;break;case _1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if(F.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),F.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(r.x===e.localMin.vertex.pt.x&&r.y===e.localMin.vertex.pt.y&&!F.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&F.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}c=this.startOpenPath(e,r)}else c=this.startOpenPath(e,r);this.setZ(e,n,c.pt);return}this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===_1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==_1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==_1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case _1.Positive:a=e.windCount,s=n.windCount;break;case _1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let i=a===0||a===1,o=s===0||s===1;if(!(!F.isHotEdge(e)&&!i||!F.isHotEdge(n)&&!o))if(F.isHotEdge(e)&&F.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==t0.Xor)c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);else if(F.isFront(e)||e.outrec===n.outrec){c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);let l=this.addLocalMinPoly(e,n,r);this.setZ(e,n,l.pt)}else{c=this.addOutPt(e,r),this.setZ(e,n,c.pt);let l=this.addOutPt(n,r);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if(F.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else if(F.isHotEdge(n))c=this.addOutPt(n,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case _1.Positive:l=e.windCount2,h=n.windCount2;break;case _1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!F.isSamePolyType(e,n))c=this.addLocalMinPoly(e,n,r),this.setZ(e,n,c.pt);else if(a===1&&s===1){switch(c=null,this.cliptype){case t0.Union:if(l>0&&h>0)return;c=this.addLocalMinPoly(e,n,r);break;case t0.Difference:(F.getPolyType(e)===H0.Clip&&l>0&&h>0||F.getPolyType(e)===H0.Subject&&l<=0&&h<=0)&&(c=this.addLocalMinPoly(e,n,r));break;case t0.Xor:c=this.addLocalMinPoly(e,n,r);break;default:if(l<=0||h<=0)return;c=this.addLocalMinPoly(e,n,r);break}c&&this.setZ(e,n,c.pt)}}}swapPositionsInAEL(e,n){let r=n.nextInAEL;r!==null&&(r.prevInAEL=e);let c=e.prevInAEL;c!==null&&(c.nextInAEL=n),n.prevInAEL=c,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=r,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let r=O1.crossProductSign(e.top,n.bot,n.top);if(r!==0)return r<0;if(!F.isMaximaEdge(e)&&e.top.y>n.top.y)return O1.crossProductSign(n.bot,e.top,F.nextVertex(e).pt)<=0;if(!F.isMaximaEdge(n)&&n.top.y>e.top.y)return O1.crossProductSign(n.bot,n.top,F.nextVertex(n).pt)>=0;let c=n.bot.y,a=n.isLeftBound;return e.bot.y!==c||e.localMin.vertex.pt.y!==c?n.isLeftBound:e.isLeftBound!==a?a:O1.isCollinear(F.prevPrevVertex(e).pt,e.bot,e.top)?!0:O1.crossProductSign(F.prevPrevVertex(e).pt,n.bot,F.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==N0.None}split(e,n){e.joinWith===N0.Right?(e.joinWith=N0.None,e.nextInAEL.joinWith=N0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=N0.None,e.prevInAEL.joinWith=N0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,r){e.frontEdge=n,e.backEdge=r}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!F.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let r=e.outrec,c=F.isFront(e),a=r.pts,s=a.next;if(c&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!c&&n.x===s.pt.x&&n.y===s.pt.y)return s;let i=new R2(n,r);return s.prev=i,i.prev=a,i.next=s,a.next=i,c&&(r.pts=i),i}addLocalMaxPoly(e,n,r){if(this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r),F.isFront(e)===F.isFront(n))if(F.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(F.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let c=this.addOutPt(e,r);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=c,this.usingPolytree){let s=F.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else F.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return c}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let r=n;for(;r!==null&&r!==e;)r=r.owner;r!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let r=e.outrec.pts,c=n.outrec.pts,a=r.next,s=c.next;F.isFront(e)?(s.prev=r,r.next=s,c.next=a,a.prev=c,e.outrec.pts=c,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=c,c.next=a,r.next=s,s.prev=r,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),F.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let r=e.outrec,c=n.outrec;if(r===c){let a=r.frontEdge;r.frontEdge=r.backEdge,r.backEdge=a;return}r!==null&&(e===r.frontEdge?r.frontEdge=n:r.backEdge=n),c!==null&&(n===c.frontEdge?c.frontEdge=e:c.backEdge=e),e.outrec=c,n.outrec=r}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(F.ptsReallyClose(e.prev.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.next.pt)||F.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,r,c){if(e===null||e.next===e||!r&&e.next===e.prev)return!1;c.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),c.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,c.push(a)),n?s=s.prev:s=s.next;return c.length!==3||r||!F.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let c=this.outrecList[r++];if(c.pts===null)continue;let a=[];c.isOpen?F.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(c),F.buildPath(c.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let c=this.outrecList[r++];if(c.pts!==null){if(c.isOpen){let a=[];F.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(c)&&this.recursiveCheckOwners(c,e)}}}checkBounds(e){return e.pts===null?!1:o3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!F.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=O1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||o3.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,r=n;for(;;){if(r!==null&&O1.isCollinear(r.prev.pt,r.pt,r.next.pt)&&(r.pt.x===r.prev.pt.x&&r.pt.y===r.prev.pt.y||r.pt.x===r.next.pt.x&&r.pt.y===r.next.pt.y||!this.preserveCollinear||O1.dotProductSign(r.prev.pt,r.pt,r.next.pt)<0)){if(r===e.pts&&(e.pts=r.prev),r=this.disposeOutPt(r),!this.isValidClosedPath(r)){e.pts=null;return}n=r;continue}if(r===null||(r=r.next,r===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!F.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&O1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let r=n.prev,c=n.next.next;e.pts=r;let a=O1.getLineIntersectPt(r.pt,n.pt,n.next.pt,c.pt);this.zCallbackInternal&&this.zCallbackInternal(r.pt,n.pt,n.next.pt,c.pt,a);let s=F.areaOutPt(r),i=s<h5?-s:s;if(i<mt){e.pts=null;return}let o=this.areaTriangle(a,n.pt,n.next.pt),l=o<h5?-o:o;if(a.x===r.pt.x&&a.y===r.pt.y||a.x===c.pt.x&&a.y===c.pt.y)c.prev=r,r.next=c;else{let f=new R2(a,e);f.prev=r,f.next=c,c.prev=f,r.next=f}if(!(l>N9)||!(l>i)&&o>h5!=s>h5)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new R2(a,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(r,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=O1.maxCoordForSafeAreaProduct,r=0,c=!0,a=e;do{let i=a.prev,o=a.pt;if(Math.abs(i.pt.x)>=n||Math.abs(i.pt.y)>=n||Math.abs(o.x)>=n||Math.abs(o.y)>=n){c=!1;break}r+=(i.pt.y+o.y)*(i.pt.x-o.x),a=a.next}while(a!==e);if(c)return BigInt(Math.round(r));let s=h5;a=e;do{let i=a.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(a.pt.x)){let o=BigInt(i.pt.y)+BigInt(a.pt.y),l=BigInt(i.pt.x)-BigInt(a.pt.x);s+=o*l}else{let o=i.pt.y+a.pt.y,l=i.pt.x-a.pt.x;s+=BigInt(Math.round(o*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,r){let c=O1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<c&&Math.abs(e.y)<c&&Math.abs(n.x)<c&&Math.abs(n.y)<c&&Math.abs(r.x)<c&&Math.abs(r.y)<c){let s=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(r.y)){let s=(BigInt(r.y)+BigInt(e.y))*(BigInt(r.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),o=(BigInt(n.y)+BigInt(r.y))*(BigInt(n.x)-BigInt(r.x));return s+i+o}let a=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(a))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let r=0;r<n.length;r++){let c=this.outrecList[n[r]];if(c.pts===null&&c.splits!==null&&this.checkSplitOwner(e,c.splits))return!0;if(c=this.getRealOutRec(c),!(c===null||c===e||c.recursiveSplit===e)){if(c.recursiveSplit=e,c.splits!==null&&this.checkSplitOwner(e,c.splits))return!0;if(!(!this.checkBounds(c)||!this.containsRect(c.bounds,e.bounds)||!this.path1InsidePath2(e.pts,c.pts)))return this.isValidOwner(e,c)||(c.owner=e.owner),e.owner=c,!0}}return!1}};_(F,"openPathsEnabled",!0);var a4=F,S2=class extends a4{constructor(){super(...arguments);_(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,r,c=!1){super.addPath(n,r,c)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,r,c=!1){super.addPaths(n,r,c)}addSubject(n){this.addPaths(n,H0.Subject)}addOpenSubject(n){this.addPaths(n,H0.Subject,!0)}addClip(n){this.addPaths(n,H0.Clip)}execute(n,r,c,a){if(Array.isArray(c)){let s=c,i=a;s.length=0,i&&(i.length=0);try{this.executeInternal(n,r),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=c,i=a;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(n,r),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var Me={area(t){return O1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let r=t[n-1];for(let c of t)e+=(r.y+c.y)*(r.x-c.x),r=c;return e*.5},scalePath64(t,e){let n=O1.maxSafeCoordinateForScale(e),r=[];for(let c of t)O1.checkSafeScaleValue(c.x,n,"scalePath64"),O1.checkSafeScaleValue(c.y,n,"scalePath64"),r.push({x:Math.round(c.x*e),y:Math.round(c.y*e)});return r},scalePaths64(t,e){let n=[];for(let r of t)n.push(Me.scalePath64(r,e));return n},scalePathD(t,e){let n=[];for(let r of t)n.push({x:r.x*e,y:r.y*e});return n},scalePathsD(t,e){let n=[];for(let r of t)n.push(Me.scalePathD(r,e));return n}};var U0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(U0||(U0={}));var u0;(function(t){t[t.Polygon=0]="Polygon",t[t.Joined=1]="Joined",t[t.Butt=2]="Butt",t[t.Square=3]="Square",t[t.Round=4]="Round"})(u0||(u0={}));var we=class{constructor(e,n,r=u0.Polygon){_(this,"inPaths");_(this,"joinType");_(this,"endType");_(this,"pathsReversed");_(this,"lowestPathIdx");this.joinType=n,this.endType=r;let c=r===u0.Polygon||r===u0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(l3.stripDuplicates(a,c));if(r===u0.Polygon){let a=l3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},h0=class h0{constructor(e=2,n=0,r=!1,c=!1){_(this,"groupList",[]);_(this,"pathOut",[]);_(this,"normals",[]);_(this,"solution",[]);_(this,"solutionTree",null);_(this,"groupDelta",0);_(this,"delta",0);_(this,"mitLimSqr",0);_(this,"stepsPerRad",0);_(this,"stepSin",0);_(this,"stepCos",0);_(this,"joinType",U0.Bevel);_(this,"endType",u0.Polygon);_(this,"arcTolerance",0);_(this,"mergeGroups",!0);_(this,"miterLimit",2);_(this,"preserveCollinear",!1);_(this,"reverseSolution",!1);_(this,"zCallback");_(this,"deltaCallback",null);_(this,"ZCB",(e,n,r,c,a)=>{(e.z||0)!==0&&(e.z===r.z||e.z===c.z)?a.z=e.z:(r.z||0)!==0&&r.z===n.z?a.z=r.z:(n.z||0)!==0&&n.z===c.z?a.z=n.z:this.zCallback&&this.zCallback(e,n,r,c,a)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=r,this.reverseSolution=c}clear(){this.groupList.length=0}addPath(e,n,r){if(e.length===0)return;let c=[e];this.addPaths(c,n,r)}addPaths(e,n,r){e.length!==0&&this.groupList.push(new we(e,n,r))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===u0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===u0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/h0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),r=n?_1.Negative:_1.Positive,c=new S2;c.preserveCollinear=this.preserveCollinear,c.reverseSolution=this.reverseSolution!==n,c.zCallback=this.ZCB,c.addSubject(this.solution),this.solutionTree!==null?c.execute(t0.Union,r,this.solutionTree):c.execute(t0.Union,r,this.solution)}execute(e,n){if(Array.isArray(n)){let r=n;r.length=0,this.solution=r,this.executeInternal(e)}else{let r=n;r.clear(),this.solutionTree=r,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let r=n.x-e.x,c=n.y-e.y;if(r===0&&c===0)return{x:0,y:0};let a=1/Math.sqrt(r*r+c*c);return{x:c*a,y:-r*a}}static getLowestPathInfo(e){let n=-1,r=!1,c={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let i of e[a])if(!(i.y<c.y||i.y===c.y&&i.x>=c.x)){if(s===Number.MAX_VALUE){if(s=h0.area(e[a]),s===0)break;r=s<0}n=a,c.x=i.x,c.y=i.y}}return{idx:n,isNegArea:r}}static translatePoint(e,n,r){return{x:e.x+n,y:e.y+r,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=h0.hypotenuse(e.x,e.y);if(h0.almostZero(n))return{x:0,y:0};let r=1/n;return{x:e.x*r,y:e.y*r}}static getAvgUnitVector(e,n){return h0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,r,c){if(O1.isAlmostZero(e.x-n.x)){if(O1.isAlmostZero(r.x-c.x))return{x:0,y:0};let a=(c.y-r.y)/(c.x-r.x),s=r.y-a*r.x;return{x:e.x,y:a*e.x+s}}if(O1.isAlmostZero(r.x-c.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:r.x,y:a*r.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,i=(c.y-r.y)/(c.x-r.x),o=r.y-i*r.x;if(O1.isAlmostZero(a-i))return{x:0,y:0};let l=(o-s)/(a-i);return{x:l,y:a*l+s}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,r){let c,a,s=e[n].z||0;if(n===r){let i=Math.abs(this.groupDelta);c={x:Math.round(e[n].x-i*this.normals[n].x),y:Math.round(e[n].y-i*this.normals[n].y),z:s},a={x:Math.round(e[n].x+i*this.normals[n].x),y:Math.round(e[n].y+i*this.normals[n].y),z:s}}else c={x:Math.round(e[n].x+this.groupDelta*this.normals[r].x),y:Math.round(e[n].y+this.groupDelta*this.normals[r].y),z:s},a={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:s};this.pathOut.push(c),this.pathOut.push(a)}doSquare(e,n,r){let c;n===r?c={x:this.normals[n].y,y:-this.normals[n].x}:c=h0.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=h0.translatePoint(s,a*c.x,a*c.y);let i=h0.translatePoint(s,this.groupDelta*c.y,this.groupDelta*-c.x),o=h0.translatePoint(s,this.groupDelta*-c.y,this.groupDelta*c.x),l=this.getPerpendicD(e[r],this.normals[r]);if(n===r){let h={x:l.x+c.x*this.groupDelta,y:l.y+c.y*this.groupDelta},u=h0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(z2.fromPointD(h0.reflectPoint(u,s))),this.pathOut.push(z2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[r]),u=h0.intersectPoint(i,o,l,h);u.z=s.z,this.pathOut.push(z2.fromPointD(u)),this.pathOut.push(z2.fromPointD(h0.reflectPoint(u,s)))}}doMiter(e,n,r,c){let a=this.groupDelta/(c+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[r].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[r].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,r,c){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*h0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let a=e[n],s=a.z||0,i={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&e4.negate(i),this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});let o=Math.ceil(this.stepsPerRad*Math.abs(c));for(let l=1;l<o;l++)i={x:i.x*this.stepCos-this.stepSin*i.y,y:i.x*this.stepSin+i.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+i.x),y:Math.round(a.y+i.y),z:s});this.pathOut.push(this.getPerpendic(e[n],this.normals[n]))}buildNormals(e){let n=e.length;if(this.normals.length=0,n!==0){for(let r=0;r<n-1;r++)this.normals.push(h0.getUnitNormal(e[r],e[r+1]));this.normals.push(h0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,r,c){if(z2.equals(n[r],n[c]))return;let a=O1.crossProductD(this.normals[r],this.normals[c]),s=O1.dotProductD(this.normals[r],this.normals[c]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,c),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<h0.Tolerance){this.pathOut.push(n[r]);return}if(s>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[c])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(s>.999&&this.joinType!==U0.Round)this.doMiter(n,r,c,s);else switch(this.joinType){case U0.Miter:s>this.mitLimSqr-1?this.doMiter(n,r,c,s):this.doSquare(n,r,c);break;case U0.Round:this.doRound(n,r,c,Math.atan2(a,s));break;case U0.Bevel:this.doBevel(n,r,c);break;default:this.doSquare(n,r,c);break}}offsetPolygon(e,n){this.pathOut=[];let r=n.length,c=r-1;for(let a=0;a<r;a++)this.offsetPoint(e,n,a,c),c=a;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let r=[...n].reverse();this.buildNormals(r),this.offsetPolygon(e,r)}offsetOpenPath(e,n){this.pathOut=[];let r=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<h0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case u0.Butt:this.doBevel(n,0,0);break;case u0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let c=1,a=0;c<r;c++)this.offsetPoint(e,n,c,a),a=c;for(let c=r;c>0;c--)this.normals[c]={x:-this.normals[c-1].x,y:-this.normals[c-1].y};if(this.normals[0]=this.normals[r],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,r)),Math.abs(this.groupDelta)<h0.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case u0.Butt:this.doBevel(n,r,r);break;case u0.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let c=r-1,a=r;c>0;c--)this.offsetPoint(e,n,c,a),a=c;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===u0.Polygon?(e.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=e.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===U0.Round||e.endType===u0.Round){let r=this.arcTolerance>.01?this.arcTolerance:n*h0.arc_const,c=Math.PI/Math.acos(1-r/n);this.stepSin=Math.sin(2*Math.PI/c),this.stepCos=Math.cos(2*Math.PI/c),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=c/(2*Math.PI)}for(let r of e.inPaths){this.pathOut=[];let c=r.length;if(c===1){let a=r[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(r,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=a.z||0;if(e.endType===u0.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=h0.ellipse(a,Math.abs(this.groupDelta),Math.abs(this.groupDelta),i),s!==0)for(let o=0;o<this.pathOut.length;o++)this.pathOut[o].z=s}else{let i=Math.ceil(Math.abs(this.groupDelta)),o={left:a.x-i,top:a.y-i,right:a.x+i,bottom:a.y+i};this.pathOut=[{x:o.left,y:o.top,z:s},{x:o.right,y:o.top,z:s},{x:o.right,y:o.bottom,z:s},{x:o.left,y:o.bottom,z:s}]}this.solution.push(this.pathOut);continue}switch(c===2&&e.endType===u0.Joined&&(this.endType=e.joinType===U0.Round?u0.Round:u0.Square),this.buildNormals(r),this.endType){case u0.Polygon:this.offsetPolygon(e,r);break;case u0.Joined:this.offsetOpenJoined(e,r);break;default:this.offsetOpenPath(e,r);break}}}static stripDuplicates(e,n){let r=e.length,c=[];if(r===0)return c;let a=e[0];c.push(a);for(let s=1;s<r;s++)z2.equals(a,e[s])||(a=e[s],c.push(a));return n&&z2.equals(a,c[0])&&c.pop(),c}static area(e){return O1.area(e)}static sqr(e){return e*e}static ellipse(e,n,r=0,c=0){if(n<=0)return[];r<=0&&(r=n),c<=2&&(c=Math.ceil(Math.PI*Math.sqrt((n+r)/2)));let a=Math.sin(2*Math.PI/c),s=Math.cos(2*Math.PI/c),i=s,o=a,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<c;++h){l.push({x:Math.round(e.x+n*i),y:Math.round(e.y+r*o)});let u=i*s-o*a;o=o*s+i*a,i=u}return l}};_(h0,"Tolerance",1e-12),_(h0,"arc_const",.002);var l3=h0;var El=BigInt(2);function ze(t,e,n){return typeof e=="number"?ke(t0.Union,t,null,e):ke(t0.Union,t,e,n)}function ke(t,e,n,r){let c=[];if(e===null)return c;let a=new S2;return a.addPaths(e,H0.Subject),n!==null&&a.addPaths(n,H0.Clip),a.execute(t,r,c),c}function s4(t,e,n,r,c=2,a=0){let s=new l3(c,a);s.addPaths(t,n,r);let i=[];return s.execute(e,i),i}var f2=1e4,Se=[1,0,0,1,0,0];function O0(){return{layers:new Map,parts:[]}}function A0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function L2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function yt(t){if(t.parts.length)return!1;for(let e of t.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var bt=t=>t.map(e=>e.map(([n,r])=>({x:Math.round(n*f2),y:Math.round(r*f2)})));function G9(t){let e=(r,c,a)=>(c.x-r.x)*(a.y-c.y)-(c.y-r.y)*(a.x-c.x)===0,n=[];for(let r of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],r);)n.pop();let c=n[n.length-1];(!c||c.x!==r.x||c.y!==r.y)&&n.push(r)}for(let r=!0;r&&n.length>=3;){let c=n.length;r=!0,n[c-1].x===n[0].x&&n[c-1].y===n[0].y||e(n[c-2],n[c-1],n[0])?n.pop():e(n[c-1],n[0],n[1])?n.shift():r=!1}return n}var g5=t=>bt(t).map(G9),y5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/f2,n.y/f2]));function i1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?_1.EvenOdd:_1.NonZero;return y5(ze(g5(t),n)).filter(r=>r.length>=3)}function Le(t,e,n){if(!e.length)return[];let r=new S2;r.addSubject(g5(e)),n.length&&r.addClip(g5(n));let c=[];return r.execute(t,_1.NonZero,c),y5(c).filter(a=>a.length>=3)}var k0=(t,e)=>e.length?Le(t0.Difference,t,e):i1(t),a0=(t,e)=>Le(t0.Intersection,t,e),h3=(t,e)=>Le(t0.Xor,t,e);function W0(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let r=[];for(let g of e)for(let p=0;p<g.length;p++){let v=g[p],y=g[(p+1)%g.length];(v[0]!==y[0]||v[1]!==y[1])&&r.push([v,y])}if(!r.length)return n==="outside"?t:[];let c=z0(e),a=Math.max(c[2]-c[0],c[3]-c[1],1e-6)/Math.max(1,Math.sqrt(r.length)),s=g=>Math.floor(g/a),i=new Map,o=new Map,l=(g,p,v)=>{let y=g.get(p);y?y[y.length-1]!==v&&y.push(v):g.set(p,[v])};r.forEach(([g,p],v)=>{let y=Math.max(1,Math.ceil(Math.hypot(p[0]-g[0],p[1]-g[1])/a*2));for(let b=0;b<=y;b++){let x=g[0]+(p[0]-g[0])*b/y,M=g[1]+(p[1]-g[1])*b/y;for(let w of[-1,0,1])for(let k of[-1,0,1])l(i,`${s(x)+w},${s(M)+k}`,v)}for(let b=s(Math.min(g[1],p[1]));b<=s(Math.max(g[1],p[1]));b++)l(o,b,v)});let h=(g,p)=>{let v=new Set,y=0,b=1;for(let k of[0,1]){let z=p[k]-g[k],S=c[k]-a,A=c[k+2]+a;if(z===0){if(g[k]<S||g[k]>A)return v;continue}let L=(S-g[k])/z,C=(A-g[k])/z;y=Math.max(y,Math.min(L,C)),b=Math.min(b,Math.max(L,C))}if(!(y<=b))return v;let x=[g[0]+(p[0]-g[0])*y,g[1]+(p[1]-g[1])*y],M=[g[0]+(p[0]-g[0])*b,g[1]+(p[1]-g[1])*b],w=Math.max(1,Math.ceil(Math.hypot(M[0]-x[0],M[1]-x[1])/a*2));for(let k=0;k<=w;k++){let z=x[0]+(M[0]-x[0])*k/w,S=x[1]+(M[1]-x[1])*k/w;for(let A of i.get(`${s(z)},${s(S)}`)??[])v.add(A)}return v},u=.5/f2,f=g=>{for(let v of i.get(`${s(g[0])},${s(g[1])}`)??[]){let[y,b]=r[v],x=b[0]-y[0],M=b[1]-y[1],w=Math.max(0,Math.min(1,((g[0]-y[0])*x+(g[1]-y[1])*M)/(x*x+M*M)));if(Math.hypot(g[0]-y[0]-w*x,g[1]-y[1]-w*M)<=u)return}let p=0;for(let v of o.get(s(g[1]))??[]){let[y,b]=r[v],x=(b[0]-y[0])*(g[1]-y[1])-(g[0]-y[0])*(b[1]-y[1]);y[1]<=g[1]?b[1]>g[1]&&x>0&&p++:b[1]<=g[1]&&x<0&&p--}return p!==0},d=g=>Math.round(g*f2)/f2,m=[];for(let g of t){let p=null,v=()=>{p&&p.length>=2&&m.push(p),p=null};for(let y=1;y<g.length;y++){let b=g[y-1],x=g[y],M=x[0]-b[0],w=x[1]-b[1];if(!M&&!w)continue;let k=[0,1];for(let S of h(b,x)){let[A,L]=r[S],C=L[0]-A[0],P=L[1]-A[1],R=M*P-w*C;if(Math.abs(R)>1e-15){let q=((A[0]-b[0])*P-(A[1]-b[1])*C)/R,T=((A[0]-b[0])*w-(A[1]-b[1])*M)/R;q>0&&q<1&&T>=0&&T<=1&&k.push(q)}else{let q=M*M+w*w;for(let T of[A,L]){let B=((T[0]-b[0])*M+(T[1]-b[1])*w)/q,X=Math.abs((T[0]-b[0])*w-(T[1]-b[1])*M)/Math.sqrt(q);B>0&&B<1&&X<=u&&k.push(B)}}}k.sort((S,A)=>S-A);let z=Math.hypot(M,w);for(let S=1;S<k.length;S++){if((k[S]-k[S-1])*z<1e-9||k[S]-k[S-1]<1e-300)continue;let A=[d(b[0]+M*k[S-1]),d(b[1]+w*k[S-1])],L=[d(b[0]+M*k[S]),d(b[1]+w*k[S])],C=(k[S-1]+k[S])/2,P=f([b[0]+M*C,b[1]+w*C]);if(P!==void 0&&P===(n==="inside")){let R=p?p[p.length-1]:void 0;p&&R&&R[0]===A[0]&&R[1]===A[1]?(L[0]!==R[0]||L[1]!==R[1])&&p.push(L):(v(),p=[A,L])}else v()}}v()}return m}function n0(t,e,n="round",r=.01){if(!t.length)return[];if(e===0)return i1(t);let c=n==="round"?U0.Round:n==="square"?U0.Square:U0.Miter,a=s4(g5(i1(t)),e*f2,c,u0.Polygon,2,r*f2);return y5(a).filter(s=>s.length>=3)}function i4(t,e){if(!t.length||e<=0)return[];let n=s4(bt(t),e/2*f2,U0.Round,u0.Round,2,.01*f2);return y5(n)}function F0(t){if(!t.length)return[];let e=new p5,n=new S2;n.addSubject(g5(t)),n.execute(t0.Union,_1.NonZero,e);let r=[],c=a=>{for(let s=0;s<a.count;s++){let i=a.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),c(h)}r.push(y5(o))}};return c(e),r}function M1(t){let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]+t[n][0])*(t[r][1]-t[n][1]);return-e/2}function xt(t){let e=0,n=0,r=0;for(let c of t){if(c.length<3)continue;let[a,s]=c[0];for(let i=0,o=c.length-1;i<c.length;o=i++){let l=c[o][0]-a,h=c[o][1]-s,u=c[i][0]-a,f=c[i][1]-s,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+a*d/2,r+=(h+f)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,r/e]}}function I3(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}function v5(t,[e,n]){return[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]]}function gt(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,r=new Map;for(let[c,a]of t)r.set(c,{regions:a.regions.map(s=>{let i=s.map(o=>v5(e,o));return n?i.reverse():i}),lines:a.lines.map(s=>s.map(i=>v5(e,i)))});return r}function u3(t,e){return{layers:gt(t.layers,e),parts:t.parts.map(n=>({...n,layers:gt(n.layers,e)}))}}function A2(t){let e=O0();for(let n of t){for(let[r,c]of n.layers){let a=e.layers.get(r)??{regions:[],lines:[]};for(let s of c.regions)a.regions.push(s);for(let s of c.lines)a.lines.push(s);e.layers.set(r,a)}for(let r of n.parts)e.parts.push(r)}return e}var s2="\0hidden";function vt(t,e){let n={regions:[],lines:[]};for(let[a,s]of t)if(a!==s2){for(let i of s.regions)n.regions.push(i);for(let i of s.lines)n.lines.push(i)}let r=new Map([[e,n]]),c=t.get(s2);return c&&e!==s2&&r.set(s2,c),r}function b5(t,e){if(t.parts.length&&e!=="guide")throw new Error(`a part cannot go on the ${e} layer as a whole. Put ${e}() inside part() instead.`);return{layers:vt(t.layers,e),parts:t.parts.map(n=>({...n,layers:vt(n.layers,e)}))}}function z0(t){let e=1/0,n=1/0,r=-1/0,c=-1/0;for(let a of t)for(let[s,i]of a)s<e&&(e=s),i<n&&(n=i),s>r&&(r=s),i>c&&(c=i);return e===1/0?null:[e,n,r,c]}function X0(t,e){let n=[];for(let[r,c]of t)if(!e?.(r))for(let a of[...c.regions,...c.lines])n.push(a);return z0(n)}function o4(t){let e=[...t].sort((a,s)=>a[0]-s[0]||a[1]-s[1]);if(e.length<3)return e;let n=(a,s,i)=>(s[0]-a[0])*(i[1]-a[1])-(s[1]-a[1])*(i[0]-a[0]),r=[];for(let a of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],a)<=0;)r.pop();r.push(a)}let c=[];for(let a=e.length-1;a>=0;a--){let s=e[a];for(;c.length>=2&&n(c[c.length-2],c[c.length-1],s)<=0;)c.pop();c.push(s)}return c.pop(),r.pop(),r.concat(c)}function Mt(t,e,n,r){return t<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/n,t*2*Math.PI/r)),5)}function V3(t,e,n){let r=[];for(let c=0;c<n;c++){let a=2*Math.PI*c/n;r.push([t*Math.cos(a),e*Math.sin(a)])}return r}function wt(t,e,n,r){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let c=Math.max(1,Math.ceil(r(n)/4)),a=[],s=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[i,o,l]of s)for(let h=0;h<=c;h++){let u=(l+90*h/c)*Math.PI/180;a.push([i+n*Math.cos(u),o+n*Math.sin(u)])}return a}function Ae(t,e){let n=i1(t);for(let r=0;r<100;r++){let c=F0(n);if(c.length<=1)return n;let a=i=>i.reduce((o,l)=>o+M1(l),0);c.sort((i,o)=>a(o)-a(i));let s=[];for(let i=1;i<c.length;i++){let o=1/0,l=[0,0],h=[0,0];for(let[b,x]of c[i][0])for(let M=0;M<c.length;M++)if(M!==i)for(let w of c[M])for(let k=0,z=w.length-1;k<w.length;z=k++){let[S,A]=w[z],[L,C]=w[k],P=L-S,R=C-A,q=P*P+R*R,T=q?Math.max(0,Math.min(1,((b-S)*P+(x-A)*R)/q)):0,B=S+T*P,X=A+T*R,Z=Math.hypot(b-B,x-X);Z<o&&([o,l,h]=[Z,[b,x],[B,X]])}if(!Number.isFinite(o))continue;let u=h[0]-l[0],f=h[1]-l[1],d=Math.hypot(u,f);d<1e-9?[u,f]=[0,1]:[u,f]=[u/d,f/d];let[m,g]=[-f*(e/2),u*(e/2)],p=[l[0]-u*(e/2),l[1]-f*(e/2)],v=[h[0]+u*(e/2),h[1]+f*(e/2)],y=[[p[0]-m,p[1]-g],[v[0]-m,v[1]-g],[v[0]+m,v[1]+g],[p[0]+m,p[1]+g]];s.push(M1(y)<0?y.reverse():y)}if(!s.length)return n;n=i1([...n,...s])}return n}function W9(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function kt(t){let{spacing:e,step:n,box:r}=t,c=e/2,a=e,s=new Map,i=[],o=[],l=[],h=[],u=[],f=(C,P)=>Math.floor((C-r[0])/a)*1000003+Math.floor((P-r[1])/a),d=(C,P,R)=>{let q=f(C[0],C[1]),T=i.length;i.push(C[0]),o.push(C[1]),l.push(P),h.push(R);let B=s.get(q);B?B.push(T):s.set(q,[T])},m=Math.ceil(2*e/n)+2,g=(C,P,R=-1,q=0)=>{let T=Math.floor((C[0]-r[0])/a),B=Math.floor((C[1]-r[1])/a);for(let X=T-1;X<=T+1;X++)for(let Z=B-1;Z<=B+1;Z++){let h1=s.get(X*1000003+Z);if(h1)for(let H of h1){let U=l[H];if(!(!u[U]&&U!==R)&&!(U===R&&Math.abs(h[H]-q)<m)&&Math.hypot(i[H]-C[0],o[H]-C[1])<P)return!1}}return!0},p=[],v=0,y=Math.ceil(4*(r[2]-r[0]+r[3]-r[1]+e)/n+2*m),b=(C,P)=>{let R=t.dir(C);if(!R)return null;let q=[C[0]+P*R[0]*n/2,C[1]+P*R[1]*n/2],T=t.dir(q)??R;return T[0]*R[0]+T[1]*R[1]<0?null:[C[0]+P*T[0]*n,C[1]+P*T[1]*n]},x=C=>{let P=p.length;u[P]=!1,d(C,P,0);let R=[[],[]];for(let[B,X]of[[0,1],[1,-1]]){let Z=C;for(let h1=1;h1<=y;h1++){let H=b(Z,X);if(!H)break;let U=X*h1;if(!t.inside(H)){R[B].push(H);break}if(!g(H,c,P,U))break;if(R[B].push(H),d(H,P,U),++v>t.maxPoints)throw new Error(`the lines have more than ${t.maxPoints} points: use a larger spacing or step`);t.tick(),Z=H}}let q=[...R[1].reverse(),C,...R[0]],T=0;for(let B=1;B<q.length;B++)T+=Math.hypot(q[B][0]-q[B-1][0],q[B][1]-q[B-1][1]);return p.push(q),q.length<2||T<t.minLength?null:(u[P]=!0,q)},M=W9(t.seed),w=[];for(let C=r[0]+e/2;C<r[2];C+=e)for(let P=r[1]+e/2;P<r[3];P+=e)w.push([C+(M()-.5)*e,P+(M()-.5)*e]);for(let C=w.length-1;C>0;C--){let P=Math.floor(M()*(C+1));[w[C],w[P]]=[w[P],w[C]]}let k=[],z=[],S=Math.max(1,Math.round(e/(2*n))),A=C=>{if(!t.inside(C)||!g(C,e)||!t.dir(C))return;let P=x(C);P&&(k.push(P),z.push(P))},L=0;for(;;){for(;z.length;){let C=z.shift();for(let P=0;P<C.length;P+=S){let R=C[Math.max(0,P-1)],q=C[Math.min(C.length-1,P+1)],T=Math.hypot(q[0]-R[0],q[1]-R[1]);if(T===0)continue;let B=-(q[1]-R[1])/T,X=(q[0]-R[0])/T;for(let Z of[1,-1])A([C[P][0]+Z*B*e,C[P][1]+Z*X*e])}}if(L>=w.length)break;A(w[L++])}return k}function zt(t,e,n,r,c,a,s){let i=(p,v)=>t[v*e+p],o=(p,v)=>(v*e+p)*2,l=(p,v)=>(v*e+p)*2+1,h=p=>{let v=p>>1,y=v%e,b=(v-y)/e,x=i(y,b),M=p&1?i(y,b+1):i(y+1,b),w=x===M?.5:(s-x)/(M-x);return p&1?[r+y*a,c+(b+w)*a]:[r+(y+w)*a,c+b*a]},u=new Map,f=(p,v)=>{for(let[y,b]of[[p,v],[v,p]]){let x=u.get(y);x?x.push(b):u.set(y,[b])}};for(let p=0;p+1<n;p++)for(let v=0;v+1<e;v++){let y=i(v,p),b=i(v+1,p),x=i(v+1,p+1),M=i(v,p+1);if(Number.isNaN(y+b+x+M))continue;let w=(y>=s?1:0)|(b>=s?2:0)|(x>=s?4:0)|(M>=s?8:0);if(w===0||w===15)continue;let k=o(v,p),z=l(v+1,p),S=o(v,p+1),A=l(v,p);if(w===5||w===10){let C=(y+b+x+M)/4>=s;w===5===C?(f(k,z),f(A,S)):(f(A,k),f(z,S));continue}let L=[];(w&1)!==(w&2)>>1&&L.push(k),(w&2)>>1!==(w&4)>>2&&L.push(z),(w&4)>>2!==(w&8)>>3&&L.push(S),(w&8)>>3!==(w&1)&&L.push(A),L.length===2&&f(L[0],L[1])}let d=new Set,m=p=>{let v=[h(p)];d.add(p);let y=p;for(;;){let b=(u.get(y)??[]).find(x=>!d.has(x));if(b===void 0)return(u.get(y)??[]).includes(p)&&v.length>2&&v.push(v[0]),v;d.add(b),v.push(h(b)),y=b}},g=[];for(let[p,v]of u)v.length===1&&!d.has(p)&&g.push(m(p));for(let p of u.keys())d.has(p)||g.push(m(p));return g.map(p=>p.filter((v,y)=>y===0||v[0]!==p[y-1][0]||v[1]!==p[y-1][1])).filter(p=>p.length>=2&&!(p.length===2&&p[0][0]===p[1][0]&&p[0][1]===p[1][1]))}function St(t,e=.001){let n=t.filter(l=>l.length>=2).map(l=>[...l]);if(n.length<2)return n;let r=l=>`${Math.round(l[0]/e)},${Math.round(l[1]/e)}`,c=new Map,a=(l,h)=>{let u=r(l),f=c.get(u);f?f.push(h):c.set(u,[h])};n.forEach((l,h)=>{a(l[0],h),a(l[l.length-1],h)});let s=new Array(n.length).fill(!1),i=l=>r(l[0])===r(l[l.length-1]),o=[];for(let l=0;l<n.length;l++){if(s[l])continue;s[l]=!0;let h=n[l];if(!i(h))for(let u=0;u<2;u++){for(;;){let f=h[h.length-1],d=(c.get(r(f))??[]).find(p=>!s[p]);if(d===void 0)break;s[d]=!0;let m=n[d],g=r(m[0])===r(f)?m:[...m].reverse();if(h=h.concat(g.slice(1)),i(h))break}if(i(h))break;h=h.reverse()}o.push(h)}return X9(o)}function X9(t){let e=t.length;if(e<2)return t;let n=1/0,r=1/0,c=-1/0,a=-1/0;for(let g of t)for(let p of[g[0],g[g.length-1]])n=Math.min(n,p[0]),r=Math.min(r,p[1]),c=Math.max(c,p[0]),a=Math.max(a,p[1]);let s=Math.max((c-n+a-r)/Math.sqrt(e),1e-6),i=g=>Math.floor((g-n)/s),o=g=>Math.floor((g-r)/s),l=i(c)+1,h=o(a)+1,u=new Map;t.forEach((g,p)=>{for(let v of[g[0],g[g.length-1]]){let y=o(v[1])*l+i(v[0]),b=u.get(y);b?b[b.length-1]!==p&&b.push(p):u.set(y,[p])}});let f=new Array(e).fill(!1),d=[],m=[0,0];for(let g=0;g<e;g++){let p=-1,v=1/0,y=!1,b=Math.min(Math.max(i(m[0]),0),l-1),x=Math.min(Math.max(o(m[1]),0),h-1);for(let w=0;w<=Math.max(l,h);w++){for(let k=b-w;k<=b+w;k++)for(let z=x-w;z<=x+w;z++)if(Math.max(Math.abs(k-b),Math.abs(z-x))===w&&!(k<0||z<0||k>=l||z>=h))for(let S of u.get(z*l+k)??[]){if(f[S])continue;let A=t[S],L=Math.hypot(A[0][0]-m[0],A[0][1]-m[1]),C=Math.hypot(A[A.length-1][0]-m[0],A[A.length-1][1]-m[1]);L<v&&([p,v,y]=[S,L,!1]),C<v&&([p,v,y]=[S,C,!0])}if(p>=0&&v<=w*s)break}if(p<0){for(let w=0;w<e;w++)if(!f[w]){p=w;break}}f[p]=!0;let M=y?[...t[p]].reverse():t[p];d.push(M),m=M[M.length-1]}return d}function Lt(t){let e=[],n=1/0,r=-1/0;for(let i of t)for(let o=0,l=i.length-1;o<i.length;l=o++)e.push([i[l][0],i[l][1],i[o][0],i[o][1]]),n=Math.min(n,i[o][1]),r=Math.max(r,i[o][1]);if(!e.length)return()=>!1;let c=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),a=(r-n)/c||1,s=Array.from({length:c},()=>[]);return e.forEach(([,i,,o],l)=>{let h=Math.max(0,Math.min(c-1,Math.floor((Math.min(i,o)-n)/a))),u=Math.max(0,Math.min(c-1,Math.floor((Math.max(i,o)-n)/a)));for(let f=h;f<=u;f++)s[f].push(l)}),([i,o])=>{if(o<n||o>r)return!1;let l=0;for(let h of s[Math.max(0,Math.min(c-1,Math.floor((o-n)/a)))]){let[u,f,d,m]=e[h];f<=o?m>o&&(d-u)*(o-f)-(i-u)*(m-f)>0&&l++:m<=o&&(d-u)*(o-f)-(i-u)*(m-f)<0&&l--}return l!==0}}var At=Math.PI/180;function q1(t,e){let n=new Array(16).fill(0);for(let r=0;r<4;r++)for(let c=0;c<4;c++)for(let a=0;a<4;a++)n[r*4+c]+=t[r*4+a]*e[a*4+c];return n}function l4(t,e){let n=Math.cos(e*At),r=Math.sin(e*At);return t===0?[1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1]:t===1?[n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1]:[n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1]}var Pe=t=>Math.abs(t)<1e-12?0:t;function Z0(t){if(t.matrix)return t.matrix.map(Pe);let[e,n,r]=t.rotate,c=q1(l4(2,r),q1(l4(1,n),l4(0,e)));return c[3]=t.at[0],c[7]=t.at[1],c[11]=t.at[2],c.map(Pe)}function $2(t,e,n,r){return[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]]}function x5(t){let[e,n,r]=[t[3],t[7],t[11]],c=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[c[0],c[1],c[2],-(c[0]*e+c[1]*n+c[2]*r),c[3],c[4],c[5],-(c[3]*e+c[4]*n+c[5]*r),c[6],c[7],c[8],-(c[6]*e+c[7]*n+c[8]*r),0,0,0,1]}function h4(t){let[e,n,r,c]=[1/0,1/0,-1/0,-1/0];for(let a of t)for(let[s,i]of a)e=Math.min(e,s),n=Math.min(n,i),r=Math.max(r,s),c=Math.max(c,i);return[e,n,r,c]}function Et(t){let[e,n,r,c]=h4(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,r])for(let o of[n,c])for(let l of[0,t.thickness]){let h=$2(t.matrix,i,o,l);for(let u=0;u<3;u++)a[u]=Math.min(a[u],h[u]),s[u]=Math.max(s[u],h[u])}return[a,s]}function Tt(t,e,n=10){let r=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(Et))for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),c[f]=Math.max(c[f],u[f]);let a=e.map(h=>h4(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),c[0]-r[0]),i=0,o=0,l=0;return e.map((h,u)=>{let[f,d,m,g]=a[u];i>0&&i+m-f>s&&(i=0,o+=l+n,l=0);let p=[1,0,0,c[0]+n+i-f,0,1,0,r[1]+o-d,0,0,1,r[2],0,0,0,1];return i+=m-f+n,l=Math.max(l,g-d),{...h,matrix:p.map(Pe)}})}var Z9=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),H3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],u4=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ce=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],F3=t=>[t[2],t[6],t[10]],Ct=t=>[t[3],t[7],t[11]],Y9=(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[4]*e[0]+t[5]*e[1]+t[6]*e[2],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]];function O3(t,e,n){let r=n[0]*n[0]+n[1]*n[1],c=[];for(let a of t)for(let s=0,i=a.length-1;s<a.length;i=s++){let o=a[i],l=a[s],h=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=o[0]+(l[0]-o[0])*f-e[0],m=o[1]+(l[1]-o[1])*f-e[1];c.push((d*n[0]+m*n[1])/r)}return c.sort((a,s)=>a-s)}function Ee(t,e,n){let r=0,c=0,a=0,s=0,i=0;for(;s+1<t.length&&i+1<e.length;){let o=Math.max(t[s],e[i]),l=Math.min(t[s+1],e[i+1])-o;l>n&&(r+=l,l>a&&(a=l,c=o+l/2)),t[s+1]<e[i+1]?s+=2:i+=2}return{total:r,mid:c,run:a}}function J9(t,e){let[n,r,c]=$2(x5(t.matrix),e[0],e[1],e[2]);if(c<0||c>t.thickness)return!1;let a=!1;for(let s of t.outline)for(let i=0,o=s.length-1;i<s.length;o=i++){let[l,h]=s[o],[u,f]=s[i];h>r!=f>r&&n<l+(u-l)*(r-h)/(f-h)&&(a=!a)}return a}var f4=class{constructor(e=[]){this.parts=e;this.seen=[]}see(e,n){e>0&&this.seen.push([n(),e])}get at(){let e=0,n=[0,0,0];for(let[a,s]of this.seen){for(let i=0;i<3;i++)n[i]+=a[i]*s;e+=s}for(let a=0;a<3;a++)n[a]/=e;if(this.parts.length&&this.parts.every(a=>J9(a,n)))return n;let r=this.seen[0][0],c=1/0;for(let[a]of this.seen){let s=Math.hypot(a[0]-n[0],a[1]-n[1],a[2]-n[2]);s<c&&([r,c]=[a,s])}return r}};function d4(t,e,n,r){let c=t+n,a=e-n;if(a<=c)return{at:[],size:0};let s=Math.max(4,Math.ceil((a-c)/r));return{at:Array.from({length:s},(i,o)=>c+(a-c)*(o+.5)/s),size:(a-c)/s}}function Pt(t,e,n){let r=$2(t,e[0],e[1],e[2]),c=Y9(t,n);return[[r[0],r[1]],[c[0],c[1]]]}function It(t,e,n,r,c,a,s,i=!1){let o=F3(t.matrix),l=F3(e.matrix),h=u4(o,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=u4(f,o),m=H3(l,d),g=Ct(t.matrix),p=H3(l,Ct(e.matrix)),v=1/0,y=-1/0;for(let z of e.outline)for(let[S,A]of z)for(let L of[0,e.thickness]){let C=$2(e.matrix,S,A,L),P=H3(o,[C[0]-g[0],C[1]-g[1],C[2]-g[2]]);P<v&&(v=P),P>y&&(y=P)}let b=d4(Math.max(0,v),Math.min(t.thickness,y),c,a),x=1/0,M=-1/0;for(let z of t.outline)for(let[S,A]of z){let L=$2(t.matrix,S,A,0),C=H3(d,[L[0]-g[0],L[1]-g[1],L[2]-g[2]]);C<x&&(x=C),C>M&&(M=C)}let w=0,k=new f4([t,e]);for(let z of b.at){let S=Ce(g,o,z),A=(p-H3(l,S))/m,L=(p+e.thickness-H3(l,S))/m,C=d4(Math.max(x,Math.min(A,L)),Math.min(M,Math.max(A,L)),c,a);for(let P of C.at){let R=Ce(S,d,P),[q,T]=Pt(n,R,f),[B,X]=Pt(r,R,f),Z=Ee(O3(t.outline,q,T),O3(e.outline,B,X),c);if(w+=Z.total*b.size*C.size,k.see(Z.run,()=>Ce(R,f,Z.mid)),w>s&&!i)return k.at}}return w>s?k.at:void 0}function Vt(t,e,n,r,c,a,s=!1){let i=[0,1,2,3].flatMap(A=>[0,1,2,3].map(L=>{let C=0;for(let P=0;P<4;P++)C+=n[A*4+P]*e.matrix[P*4+L];return C})),o=i[11],l=i[11]+i[10]*e.thickness,h=Math.min(t.thickness,Math.max(o,l))-Math.max(0,Math.min(o,l));if(h<=r)return;let u=Math.max(0,Math.min(o,l))+h/2,f=new f4([t,e]),d=e.outline.map(A=>A.map(([L,C])=>[i[0]*L+i[1]*C+i[3],i[4]*L+i[5]*C+i[7]])),[m,g,p,v]=h4(t.outline),[y,b,x,M]=h4(d),w=d4(Math.max(g,b),Math.min(v,M),r,c),k=0;for(let A of w.at){let L=Ee(O3(t.outline,[0,A],[1,0]),O3(d,[0,A],[1,0]),r);if(k+=L.total*w.size*h,f.see(L.run,()=>$2(t.matrix,L.mid,A,u)),k>a&&!s)return f.at}let z=d4(Math.max(m,y),Math.min(p,x),r,c),S=0;for(let A of z.at){let L=Ee(O3(t.outline,[A,0],[0,1]),O3(d,[A,0],[0,1]),r);if(S+=L.total*z.size*h,f.see(L.run,()=>$2(t.matrix,A,L.mid,u)),S>a&&!s)return f.at}return k>a||S>a?f.at:void 0}function Ht(t,e=1/0,n=.05,r=.25,c=.1){let a=t.map(Et),s=t.map(h=>x5(h.matrix)),i=t.map((h,u)=>u).sort((h,u)=>a[h][0][0]-a[u][0][0]),o=[],l=0;for(let h=0;h<i.length;h++)for(let u=h+1;u<i.length;u++){let f=i[h],d=i[u];if(a[d][0][0]>=a[f][1][0]-n)break;if(!Z9(a[f],a[d],n))continue;if(++l>e)return{found:o,complete:!1};let[m,g]=f<d?[t[f],t[d]]:[t[d],t[f]],[p,v]=f<d?[s[f],s[d]]:[s[d],s[f]],b=Math.hypot(...u4(F3(m.matrix),F3(g.matrix)))<1e-9?Vt(m,g,p,n,r,c):It(m,g,p,v,n,r,c);b&&o.push([m,g,b])}return{found:o,complete:!0}}function Ot(t,e,n=.05,r=.25,c=.1){let a=Math.hypot(...u4(F3(t.matrix),F3(e.matrix)))<1e-9,s=x5(t.matrix);return a?Vt(t,e,s,n,r,c,!0):It(t,e,s,x5(e.matrix),n,r,c,!0)}function B0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var Te=B0(0,0,0);function p0(t){return x5(t)}function Ft(t,e,n=t.angle,r=t.x1){let c=r-t.x0;if(!n||!(c>0))return B0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return q1(B0(t.x0,0,s),q1(l4(1,-n),B0(-t.x0-c,0,-s)))}function M5(t){return[...t].sort((e,n)=>e.x0-n.x0)}function m4(t,e){let n=[B0(0,0,0)];for(let r of M5(t))n.push(q1(n[n.length-1],Ft(r,e)));return n}function p4(t,e,n){let r=M5(t),c=m4(r,e);for(let a=r.length-1;a>=0;a--){let s=r[a];if(n[0]>=s.x1)return $2(c[a+1],...n);if(n[0]>s.x0){let i=(n[0]-s.x0)/(s.x1-s.x0),o=q1(c[a],Ft(s,e,s.angle*i,n[0]));return $2(o,...n)}}return n}function Rt(t,e){return M5(t).filter(n=>(n.x0+n.x1)/2<e).length}function g4(t){if(!t.bends?.length)return[t];let e=M5(t.bends),n=m4(e,t.thickness),r=1e7,c=[];for(let a=0;a<=e.length;a++){let s=a===0?-r:e[a-1].x1,i=a===e.length?r:e[a].x0;if(!(i>s))continue;let o=[[s,-r],[i,-r],[i,r],[s,r]],l=a0(t.outline,[o]);l.length&&c.push({...t,outline:l,bends:void 0,matrix:q1(t.matrix,n[a])})}return c}var K9=2e3;function v4(t,e,n=2){if(!e?.length)return F0(t);let r=1e7,c=1/0,a=-1/0;for(let f of t)for(let[d]of f)c=Math.min(c,d),a=Math.max(a,d);let s=M5(e).map(f=>[Math.max(f.x0,c),Math.min(f.x1,a)]).filter(([f,d])=>d>f),i=s.reduce((f,[d,m])=>f+(m-d),0),o=Math.max(n,i/K9),l=[];for(let[f,d]of s){let m=Math.max(1,Math.ceil((d-f)/o));for(let g=0;g<=m;g++)l.push(f+(d-f)*g/m)}let h=[-r,...l.sort((f,d)=>f-d),r],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-r],[h[f+1],-r],[h[f+1],r],[h[f],r]];for(let m of F0(a0(t,[d])))u.push(m)}return u}var X2=1e6,y4=.01,w5=t=>M1(t)<0?[...t].reverse():t;function Q9(t,e){let n=q1(p0(t.matrix),e.matrix),[r,c]=[n[8],n[9]],a=Math.hypot(r,c);if(a<1e-9)return[];let s=0,i=e.thickness,o=L=>(-n[11]-Math.max(n[10]*s,n[10]*i)+L)/a,l=L=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*i)-L)/a;if(!(l(y4)>o(y4)))return[];let[h,u]=[r/a,c/a],[f,d]=[-u,h],m=(L,C)=>[[h*L-f*X2,u*L-d*X2],[h*C-f*X2,u*C-d*X2],[h*C+f*X2,u*C+d*X2],[h*L+f*X2,u*L+d*X2]],g=1/0,p=-1/0;for(let L of e.outline)for(let[C,P]of L)for(let R of[s,i]){let q=n[8]*C+n[9]*P+n[10]*R+n[11];q<g&&(g=q),q>p&&(p=q)}if(Math.min(t.thickness,p)-Math.max(0,g)<Math.min(1,t.thickness/2))return[];let v=(L,C)=>a0(e.outline,[w5(m(L,C))]).filter(P=>Math.abs(M1(P))>1e-6),y=v(o(y4),l(y4));if(!y.length)return[];let b=Math.abs(l(0)-o(0))+1,x=L=>{let C=L.map(([q,T])=>[q-h*b,T-u*b]),P=L.map(([q,T])=>[q+h*b,T+u*b]),R=[w5(C),w5(P)];for(let q=0;q<L.length;q++){let T=(q+1)%L.length,B=[C[q],C[T],P[T],P[q]];Math.abs(M1(B))>1e-12&&R.push(w5(B))}return R},M=i1(y.flatMap(x),"nonzero"),w=a0(v(o(0),l(0)),M).filter(L=>Math.abs(M1(L))>1e-6);if(!w.length)return[];let k=L=>([C,P])=>[n[0]*C+n[1]*P+n[2]*L+n[3],n[4]*C+n[5]*P+n[6]*L+n[7]],z=n[0]*n[5]-n[1]*n[4]<0,S=L=>w.map(C=>{let P=C.map(k(L));return z?P.reverse():P}),A=[];for(let L of w)for(let C=0;C<L.length;C++){let P=L[C],R=L[(C+1)%L.length],q=[k(s)(P),k(s)(R),k(i)(R),k(i)(P)];Math.abs(M1(q))>1e-9&&A.push(w5(q))}return i1([...S(s),...S(i),...A],"nonzero")}function $t(t,e,n){let r=[];for(let a of e)for(let s of Q9(t,a))r.push(s);if(!r.length)return[];let c=F0(a0(i1(r),t.outline)).filter(a=>a.reduce((s,i)=>s+M1(i),0)>1e-4);return c.length?n0(c.flat(),n/2,"miter"):[]}var k5=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Dt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],er=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],qt=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},z5={turn:.3,press:-.1};function tr(t,e){let n=qt(k5(t.to,t.from)),r=k5(t.up,n.map(o=>o*Dt(t.up,n)));Math.hypot(...r)<1e-9&&(r=Math.abs(n[0])<.9?[1,0,0]:[0,1,0]);let c=qt(k5(r,n.map(o=>o*Dt(r,n)))),a=er(c,n);if(Array.isArray(t.size)){let[o,l]=[t.size[0]/2+e/2,t.size[1]/2+e/2];return[[-o,-l],[o,-l],[o,l],[-o,l]].map(([h,u])=>[a[0]*h+c[0]*u,a[1]*h+c[1]*u,a[2]*h+c[2]*u])}let s=t.size/2+e/2,i=t.sides<12?t.sides:64;return Array.from({length:i},(o,l)=>{let h=2*Math.PI*l/i,[u,f]=[Math.cos(h)*s,Math.sin(h)*s];return[a[0]*f+c[0]*u,a[1]*f+c[1]*u,a[2]*f+c[2]*u]})}function Nt(t,e,n){let r=k5(e.to,e.from);if(!(Math.hypot(...r)>1e-9))return;let c=p0(t.matrix),a=o=>[c[0]*o[0]+c[1]*o[1]+c[2]*o[2]+c[3],c[4]*o[0]+c[5]*o[1]+c[6]*o[2]+c[7],c[8]*o[0]+c[9]*o[1]+c[10]*o[2]+c[11]],s=k5(a(r),a([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let i=[];for(let o of tr(e,n)){let l=a([e.from[0]+o[0],e.from[1]+o[1],e.from[2]+o[2]]),h=(0-l[2])/s[2],u=(t.thickness-l[2])/s[2];if(h>u&&([h,u]=[u,h]),h=Math.max(0,h),u=Math.min(1,u),u>h)for(let f of[h,u])i.push([l[0]+s[0]*f,l[1]+s[1]*f])}return i.length>=3?o4(i):void 0}var b4=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],nr=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ut=t=>[t[2],t[6],t[10]],Bt=t=>[t[3],t[7],t[11]];function _t(t,e,n){let r=[];for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let i=c[s],o=c[a],l=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]),h=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]);if(l>0==h>0)continue;let u=l/(l-h);r.push((i[0]+(o[0]-i[0])*u-e[0])*n[0]+(i[1]+(o[1]-i[1])*u-e[1])*n[1])}return r.sort((c,a)=>c-a)}function jt(t,e){for(let n=0;n+1<t.length;n+=2)if(t[n]<=e&&e<=t[n+1])return[t[n],t[n+1]]}function rr(t,[e,n]){let r=!1;for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let[i,o]=c[s],[l,h]=c[a];o>n!=h>n&&e<i+(l-i)*(n-o)/(h-o)&&(r=!r)}return r}function Gt(t,e,n){let r={a:[],b:[],thin:0},c=Ut(t.matrix),a=Ut(e.matrix),s=nr(c,a),i=Math.hypot(...s);if(i<1e-6)return r;let o=Math.abs(b4(c,a)),l=[s[0]/i,s[1]/i,s[2]/i],h=b4(c,Bt(t.matrix))+t.thickness/2,u=b4(a,Bt(e.matrix))+e.thickness/2,f=b4(c,a),d=1-f*f,m=(h-u*f)/d,g=(u-h*f)/d,p=[m*c[0]+g*a[0],m*c[1]+g*a[1],m*c[2]+g*a[2]],v=A=>{let L=p0(A.matrix);return[[L[0]*p[0]+L[1]*p[1]+L[2]*p[2]+L[3],L[4]*p[0]+L[5]*p[1]+L[6]*p[2]+L[7]],[L[0]*l[0]+L[1]*l[1]+L[2]*l[2],L[4]*l[0]+L[5]*l[1]+L[6]*l[2]]]},[y,b]=v(t),[x,M]=v(e),w=_t(t.outline,y,b),k=_t(e.outline,x,M),z=(e.thickness+t.thickness*o)/i+n,S=(t.thickness+e.thickness*o)/i+n;for(let A=0;A+1<w.length;A+=2)for(let L=0;L+1<k.length;L+=2){let C=Math.max(w[A],k[L]),P=Math.min(w[A+1],k[L+1]);if(!(P-C>.01))continue;let R=(C+P)/2,[q,T]=jt(w,R),[B,X]=jt(k,R),Z=Math.max(T-R,R-B)<=Math.max(R-q,X-R),h1=(Y,Q,W,F1,L1,g1)=>{let X1=[-W[1],W[0]],D1=(t1,V)=>[Q[0]+W[0]*(R+L1*t1)+X1[0]*V,Q[1]+W[1]*(R+L1*t1)+X1[1]*V],E=g1+F1+1,D=[D1(0,-F1/2),D1(E,-F1/2),D1(E,F1/2),D1(0,F1/2)];M1(D)<0&&D.reverse();let e1=D1(Math.min(.01,g1/2),0),u1=F0(a0([D],Y.outline)).find(t1=>rr(t1,e1));if(!(!u1||!(u1.reduce((t1,V)=>t1+M1(V),0)>1e-4)))return a0(n0(u1,.05,"miter"),[D])},H=h1(t,y,b,z,Z?1:-1,Z?T-R:R-q),U=h1(e,x,M,S,Z?-1:1,Z?R-B:X-R);if(!H||!U){r.thin++;continue}r.a.push(...H),r.b.push(...U)}return r}var i2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",d2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",Xt=t=>typeof t=="number",_0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",e2=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Ie(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)Ie(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function x4(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let r=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(r>e)throw new Error(`a range of ${r} items is more than the limit of ${e}`);for(let c=0;c<r;c++)n.push(t.start+c*t.step);return n}function g0(t){return t===void 0||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="number"?!Number.isNaN(t):!0}var Wt=(t,e,n)=>i2(t)&&i2(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:_0(t)&&_0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([r,c])=>e.fields.has(r)&&R3(c,e.fields.get(r),n)):t===e;function R3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return Wt(t,e,n);let r=new Map,c=[],a=(s,i)=>{let o=r.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||r.set(s,o=new Set),o.add(i),c.push([s,i,0]),!0)};if(!a(t,e))return!1;for(;c.length;){let s=c[c.length-1];if(s[2]===s[0].length){c.pop();continue}let i=s[0][s[2]],o=s[1][s[2]++];if(n?.(),Array.isArray(i)&&Array.isArray(o)?!a(i,o):!Wt(i,o,n))return!1}return!0}function R0(t){return t===void 0?"undef":Array.isArray(t)?"list":i2(t)?"range":d2(t)?"function":_0(t)?"record":typeof t}function cr(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?D2(t):i2(t)?`[${D2(t.start)}:${D2(t.step)}:${D2(t.end)}]`:d2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:_0(t)?"{}":String(t)}function $3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let r=[],c=0,a=l=>{r.push(l),c+=l.length},s=[],i=t;for(;;){Array.isArray(i)?(a("["),s.push({items:i,i:0,close:"]"})):_0(i)&&i.fields.size?(a("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):a(cr(i));let l=!1;for(;s.length&&!l&&c<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&a(", "),h.keys&&a(`${h.keys[h.i]} = `),i=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||c>e)break}let o=r.join("");return c>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function Zt(t,e,n){let r=[],c=0;for(let a of t){r.length&&(c+=e.length);let s=$3(a,n-c);if(!s.whole)return;c+=s.text.length,r.push(s.text)}return r.join(e)}function C0(t){let e=$3(t,200,!0);return e.whole?e.text:e.text+"..."}var v0=t=>typeof t=="string"?t:C0(t);function q0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function D2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function D3(t,e=.02){let n=[],r=[],c=[],a=[0,0],s=[0,0],i=l=>{c.length>=2&&(l?n:r).push(c),c=[]},o=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")i(!1),a=s=[l.x,l.y],c=[s];else if(l.type==="L")s=[l.x,l.y],c.push(s);else if(l.type==="Q"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=f;d++){let m=d/f,g=1-m;c.push([g*g*h+2*g*m*l.x1+m*m*l.x,g*g*u+2*g*m*l.y1+m*m*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,f=o(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let m=d/f,g=1-m;c.push([g*g*g*h+3*g*g*m*l.x1+3*g*m*m*l.x2+m*m*m*l.x,g*g*g*u+3*g*g*m*l.y1+3*g*m*m*l.y2+m*m*m*l.y])}s=[l.x,l.y]}else i(!0),s=a,c=[a];return i(!1),{closed:n,open:r}}function q3(t,e=Math.PI/2,n){let r=x=>/^[a-zA-Z]$/.test(x),c=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,i="",o=0,l=0,h=0,u=0,f=0,d=0,m=0,g=0,p="",v=()=>{let x=c[s++];if(x===void 0||r(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},y=()=>{let x=c[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(c[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{b()}catch(x){if(!n)throw x;n(x.message)}return a;function b(){for(;s<c.length;){if(r(c[s]))i=c[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${c[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=i===i.toLowerCase(),M=i.toUpperCase(),w=x?o:0,k=x?l:0;if(M==="M")o=w+v(),l=k+v(),h=o,u=l,a.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=w+v(),l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="H")o=w+v(),a.push({type:"L",x:o,y:l});else if(M==="V")l=k+v(),a.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let z,S;if(M==="C")z=w+v(),S=k+v();else{let C=p==="C"||p==="S";z=C?2*o-f:o,S=C?2*l-d:l}let A=w+v(),L=k+v();o=w+v(),l=k+v(),f=A,d=L,a.push({type:"C",x1:z,y1:S,x2:A,y2:L,x:o,y:l})}else if(M==="Q"||M==="T"){let z,S;if(M==="Q")z=w+v(),S=k+v();else{let A=p==="Q"||p==="T";z=A?2*o-m:o,S=A?2*l-g:l}o=w+v(),l=k+v(),m=z,g=S,a.push({type:"Q",x1:z,y1:S,x:o,y:l})}else if(M==="A"){let z=v(),S=v(),A=v(),L=y(),C=y(),P=w+v(),R=k+v();a.push(...ar(o,l,z,S,A,L,C,P,R,e)),o=P,l=R}else if(M==="Z")a.push({type:"Z"}),o=h,l=u;else throw new Error(`Unknown path command "${i}"`);p=M}}}function ar(t,e,n,r,c,a,s,i,o,l=Math.PI/2){if(n===0||r===0||t===i&&e===o)return[{type:"L",x:i,y:o}];n=Math.abs(n),r=Math.abs(r);let h=c*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-i)/2,m=(e-o)/2,g=u*d+f*m,p=-f*d+u*m,v=g*g/(n*n)+p*p/(r*r);v>1&&(n*=Math.sqrt(v),r*=Math.sqrt(v));let y=n*n*r*r-n*n*p*p-r*r*g*g,b=n*n*p*p+r*r*g*g,x=Math.sqrt(Math.max(0,y/b));a===s&&(x=-x);let M=x*n*p/r,w=-x*r*g/n,k=u*M-f*w+(t+i)/2,z=f*M+u*w+(e+o)/2,S=(T,B,X,Z)=>Math.atan2(T*Z-B*X,T*X+B*Z),A=S(1,0,(g-M)/n,(p-w)/r),L=S((g-M)/n,(p-w)/r,(-g-M)/n,(-p-w)/r);!s&&L>0&&(L-=2*Math.PI),s&&L<0&&(L+=2*Math.PI);let C=Math.ceil(Math.abs(L)/l),P=[],R=T=>[k+n*Math.cos(T)*u-r*Math.sin(T)*f,z+n*Math.cos(T)*f+r*Math.sin(T)*u],q=T=>[-n*Math.sin(T)*u-r*Math.cos(T)*f,-n*Math.sin(T)*f+r*Math.cos(T)*u];for(let T=0;T<C;T++){let B=A+L*T/C,X=A+L*(T+1)/C,Z=4/3*Math.tan((X-B)/4),h1=R(B),H=R(X),U=q(B),Y=q(X);P.push({type:"C",x1:h1[0]+Z*U[0],y1:h1[1]+Z*U[1],x2:H[0]-Z*Y[0],y2:H[1]-Z*Y[1],x:H[0],y:H[1]})}return P}var E0=Math.PI/180;function t7(t,e,n){if(typeof t=="number"&&typeof e=="number")return t-e;if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;if(Array.isArray(t)&&Array.isArray(e)){for(let r=0;r<Math.min(t.length,e.length);r++){let c=t7(t[r],e[r],n);if(c)return c}return t.length-e.length}throw new Error(`${n}() can only order numbers, strings or lists of them, not ${R0(t)} and ${R0(e)}`)}function Fe(t,e,n){let r=$0(t,e,n);return(r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.flatMap(a=>$0(a,e,n)):r).map(a=>{if(!Array.isArray(a)||a.length<2)throw new Error(`${e}() needs points [x, y], got ${R0(a)}`);return[z1(a[0],e),z1(a[1],e)]})}function sr(t,e,n){let r=$0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(c=>Fe(c,e,n)):[Fe(r,e,n)]}var w1=(t,e,n)=>({params:t.replace("...","").split(",").map(r=>r.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function n7(t,e,n){return t.order?[]:t.params.filter((r,c)=>c<e.length&&n.has(r))}function r7(t,e,n){if(t.rest){let a=[...e];return t.params.forEach((s,i)=>{n.has(s)&&(a[i]=n.get(s))}),a}if(!t.order)return t.params.map((a,s)=>n.has(a)?n.get(a):e[s]);let r=e.length+t.params.filter(a=>n.has(a)).length,c=t.order(r).filter(a=>!n.has(a));return t.params.map(a=>n.has(a)?n.get(a):e[c.indexOf(a)])}function Ve(t,e,n,r){let c=Zt(t,e,n.maxLength);if(c===void 0)throw new Error(`${r}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(c.length/8)),c}function z1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${R0(t)}`);return t}function $0(t,e,n){if(Array.isArray(t))return t;if(i2(t))return x4(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${R0(t)}`)}var ir=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function c7(t,e,n){if(ir.has(t))return 0;let r=0;for(let c of e)if(typeof c=="string")r+=c.length;else if(Array.isArray(c))r+=t==="len"?0:c.length;else if(i2(c)&&c.step!==0){let a=Math.floor((c.end-c.start)/c.step)+1;a>0&&(r+=Math.min(a,n+1))}return r}var Y0=t=>w1("x",e=>typeof e[0]=="number"?o2(t(e[0])):void 0);function o2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function a7(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var M4=new Map;function or(t){let e=M4.get(t);if(e)return e;let n=a7(t),r=Array.from({length:256},(c,a)=>a);for(let c=255;c>0;c--){let a=Math.floor(n()*(c+1));[r[c],r[a]]=[r[a],r[c]]}e=new Uint8Array(512);for(let c=0;c<512;c++)e[c]=r[c&255];return M4.size>64&&M4.clear(),M4.set(t,e),e}var He=t=>t*t*t*(t*(t*6-15)+10);function Z2(t,e,n,r){let c=t&15,a=c<8?e:n,s=c<4?n:c===12||c===14?e:r;return((c&1)===0?a:-a)+((c&2)===0?s:-s)}function lr(t,e,n,r){let c=or(r),a=Math.floor(t),s=Math.floor(e),i=Math.floor(n);t-=a,e-=s,n-=i;let o=a&255,l=s&255,h=i&255,u=He(t),f=He(e),d=He(n),m=c[o]+l,g=c[m]+h,p=c[m+1]+h,v=c[o+1]+l,y=c[v]+h,b=c[v+1]+h,x=(M,w,k)=>w+M*(k-w);return x(d,x(f,x(u,Z2(c[g],t,e,n),Z2(c[y],t-1,e,n)),x(u,Z2(c[p],t,e-1,n),Z2(c[b],t-1,e-1,n))),x(f,x(u,Z2(c[g+1],t,e,n-1),Z2(c[y+1],t-1,e,n-1)),x(u,Z2(c[p+1],t,e-1,n-1),Z2(c[b+1],t-1,e-1,n-1))))}function Yt(t,e,n){let r=t.length===1&&Array.isArray(t[0])?t[0]:t;if(r.length)return e(r.map(c=>z1(c,n)))}var L5={abs:Y0(Math.abs),sign:Y0(Math.sign),floor:Y0(Math.floor),ceil:Y0(Math.ceil),round:Y0(t=>t<0?-Math.round(-t):Math.round(t)),sqrt:Y0(Math.sqrt),exp:Y0(Math.exp),ln:Y0(Math.log),log:w1("x, base",(t,e)=>e.given<2?o2(Math.log10(z1(t[0],"log"))):Math.log(z1(t[0],"log"))/Math.log(z1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:Y0(t=>Math.sin(t*E0)),cos:Y0(t=>Math.cos(t*E0)),tan:Y0(t=>Math.tan(t*E0)),asin:Y0(t=>Math.asin(t)/E0),acos:Y0(t=>Math.acos(t)/E0),atan:Y0(t=>Math.atan(t)/E0),atan2:w1("y, x",t=>o2(Math.atan2(z1(t[0],"atan2"),z1(t[1],"atan2"))/E0)),pow:w1("x, y",t=>Math.pow(z1(t[0],"pow"),z1(t[1],"pow"))),min:w1("values...",t=>Yt(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:w1("values...",t=>Yt(t,e=>e.reduce((n,r)=>r>n?r:n,-1/0),"max")),clamp:w1("x, low, high",t=>Math.min(Math.max(z1(t[0],"clamp"),z1(t[1],"clamp")),z1(t[2],"clamp"))),lerp:w1("a, b, t",t=>{let e=z1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((r,c)=>z1(r,"lerp")+(z1(n[c],"lerp")-z1(r,"lerp"))*e)}return z1(t[0],"lerp")+(z1(t[1],"lerp")-z1(t[0],"lerp"))*e}),norm:w1("v",(t,e)=>Math.sqrt($0(t[0],"norm",e).reduce((n,r)=>n+z1(r,"norm")**2,0))),cross:w1("a, b",(t,e)=>{let n=$0(t[0],"cross",e).map(c=>z1(c,"cross")),r=$0(t[1],"cross",e).map(c=>z1(c,"cross"));return n.length===2?n[0]*r[1]-n[1]*r[0]:[n[1]*r[2]-n[2]*r[1],n[2]*r[0]-n[0]*r[2],n[0]*r[1]-n[1]*r[0]]}),len:w1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:_0(t[0])?t[0].fields.size:void 0),keys:w1("record",t=>_0(t[0])?[...t[0].fields.keys()]:void 0),merge:w1("a, b",t=>{if(!_0(t[0])||!_0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:w1("...",(t,e)=>{let n=t.reduce((r,c)=>r+(Array.isArray(c)?c.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(r=>Array.isArray(r)?r:[r])}),reverse:w1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...$0(t[0],"reverse",e)].reverse()),sort:w1("values, key",(t,e)=>{let n=$0(t[0],"sort",e),r=t[1],c=n.map(a=>[r===void 0?a:e.apply(r,[a]),a]);return e.step(Math.ceil(n.length*Math.log2(n.length+1))),c.sort((a,s)=>t7(a[0],s[0],"sort")).map(([,a])=>a)}),fold:w1("values, initial, fn",(t,e)=>{let n=t[1];for(let r of $0(t[0],"fold",e))n=e.apply(t[2],[n,r]);return n}),scan:w1("values, initial, fn",(t,e)=>{let n=t[1];return $0(t[0],"scan",e).map(r=>n=e.apply(t[2],[n,r]))}),bounds:w1("points",(t,e)=>{let n=Fe(t[0],"bounds",e);if(!n.length)return;let[r,c,a,s]=[1/0,1/0,-1/0,-1/0];for(let[i,o]of n)r=Math.min(r,i),c=Math.min(c,o),a=Math.max(a,i),s=Math.max(s,o);return[r,c,a,s]}),crossings:w1("points, x, y",(t,e)=>{if(t[1]===void 0==(t[2]===void 0))throw new Error("crossings() needs one of x or y");let n=t[1]===void 0,r=z1(n?t[2]:t[1],"crossings"),c=[];for(let a of sr(t[0],"crossings",e))for(let s=0,i=a.length-1;s<a.length;i=s++){let[o,l]=n?[a[i][1],a[i][0]]:a[i],[h,u]=n?[a[s][1],a[s][0]]:a[s];o>r!=h>r&&c.push(l+(u-l)*(r-o)/(h-o))}return c.sort((a,s)=>a-s)}),sum:w1("values",(t,e)=>$0(t[0],"sum",e).reduce((n,r)=>n+z1(r,"sum"),0)),slice:w1("value, start, end",(t,e)=>{let r=(typeof t[0]=="string"?[...t[0]]:$0(t[0],"slice",e)).slice(z1(t[1]??0,"slice"),t[2]===void 0?void 0:z1(t[2],"slice"));return typeof t[0]=="string"?r.join(""):r}),str:w1("...",(t,e)=>Ve(t,"",e,"str")),chr:w1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(z1(e,"chr"))).join("")),ord:w1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:w1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:w1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:w1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:w1("values, separator",(t,e)=>Ve($0(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:w1("value, list",(t,e)=>{let r=(typeof t[1]=="string"?[...t[1]]:$0(t[1],"search",e)).findIndex(c=>R3(c,t[0],e.step));return r<0?void 0:r}),contains:w1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(Ve([t[1]],"",e,"contains")):$0(t[0],"contains",e).some(n=>R3(n,t[1],e.step))),lookup:w1("x, table",(t,e)=>{let n=z1(t[0],"lookup"),r=$0(t[1],"lookup",e);if(!r.length)return;let c=r.map(a=>[z1(a[0],"lookup"),z1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=c[0][0])return c[0][1];for(let a=1;a<c.length;a++)if(n<=c[a][0]){let[s,i]=c[a-1],[o,l]=c[a];return i+(n-s)/(o-s)*(l-i)}return c[c.length-1][1]}),rands:w1("min, max, count, seed",t=>{let e=z1(t[0],"rands"),n=z1(t[1],"rands"),r=z1(t[2],"rands"),c=a7(t[3]===void 0?1:z1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(r)),1e6)},()=>e+(n-e)*c())}),noise:w1("x, y, z, seed, octaves",t=>{let e,n=0,r=0;if(Array.isArray(t[0])){let h=t[0];e=z1(h[0],"noise"),n=h[1]===void 0?0:z1(h[1],"noise"),r=h[2]===void 0?0:z1(h[2],"noise")}else e=z1(t[0],"noise"),t[1]!==void 0&&(n=z1(t[1],"noise")),t[2]!==void 0&&(r=z1(t[2],"noise"));let c=Math.floor(t[3]===void 0?1:z1(t[3],"noise")),a=t[4]===void 0?1:Math.floor(z1(t[4],"noise"));if(!(a>=1&&a<=8))throw new Error("noise(): octaves must be 1 to 8");let s=0,i=1,o=0,l=1;for(let h=0;h<a;h++)s+=i*lr(e*l+h*.3713,n*l+h*.6271,r*l+h*.1943,c+h*7919),o+=i,i/=2,l*=2;return o2(s/o)}),is_num:w1("value",t=>Xt(t[0])&&!Number.isNaN(t[0])),is_string:w1("value",t=>typeof t[0]=="string"),is_bool:w1("value",t=>typeof t[0]=="boolean"),is_list:w1("value",t=>Array.isArray(t[0])),is_record:w1("value",t=>_0(t[0])),is_undef:w1("value",t=>t[0]===void 0),is_function:w1("value",t=>d2(t[0])),type_of:w1("value",t=>R0(t[0])),path_length:w1("points",(t,e)=>{let n=S5(t[0],"path_length",e),r=0;for(let c=1;c<n.length;c++)r+=Math.hypot(n[c][0]-n[c-1][0],n[c][1]-n[c-1][1]);return r}),point_at:w1("points, s",(t,e)=>Jt(S5(t[0],"point_at",e),z1(t[1],"point_at")).point),heading_at:w1("points, s",(t,e)=>o2(Jt(S5(t[0],"heading_at",e),z1(t[1],"heading_at")).heading)),offset_path:w1("points, d, closed",(t,e)=>{let n=S5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),r=z1(t[1],"offset_path"),c=t[2]===!0,a=c&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(a&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let s=n.length,i=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],m=Math.hypot(f-h,d-u);return[-(d-u)/m,(f-h)/m]},o=n.map(([l,h],u)=>{let f=!c&&u===0,d=!c&&u===s-1,m=i(f?0:(u-1+s)%s),g=i(d?s-2:u),[p,v]=[m[0]+g[0],m[1]+g[1]],y=Math.hypot(p,v);if(y<1e-9)[p,v]=m;else{let b=Math.min(2/(y*y),4/y);[p,v]=[p*b,v*b]}return[o2(l+r*p),o2(h+r*v)]});return a?[...o,o[0]]:o}),train_for:w1("ratio, stages, pinion, wheel",(t,e)=>{let n=z1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let r=t[1]===void 0?2:z1(t[1],"train_for");if(!(r===1||r===2||r===3))throw new Error("train_for(): stages must be 1, 2 or 3");let c=(v,y,b)=>{if(v===void 0)return y;if(!Array.isArray(v)||v.length!==2||!v.every(w=>typeof w=="number"))throw new Error(`train_for(): ${b} must be [fewest, most] teeth`);let[x,M]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(x>=6&&M>=x&&M<=400))throw new Error(`train_for(): ${b} teeth must be from 6 to 400, fewest first`);return[x,M]},[a,s]=c(t[2],[10,20],"pinion"),[i,o]=c(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=a;v<=s;v++)for(let y=Math.max(i,v);y<=o;y++)u.push([v,y]);let f,d=v=>{let y=v.reduce((M,[w,k])=>M*k/w,1),b=Math.abs(y/h-1),x=v.reduce((M,[w,k])=>M+w+k,0);(!f||b<f.err-1e-12||Math.abs(b-f.err)<=1e-12&&x<f.teeth)&&(f={stages:v.map(M=>[...M]),err:b,teeth:x})},m=(v,y)=>{e.step();for(let b=a;b<=s;b++)for(let x of[Math.floor(y*b),Math.ceil(y*b)])x>=Math.max(i,b)&&x<=o&&d([...v,[b,x]])};if(r===1)m([],h);else for(let v=0;v<u.length;v++){let y=u[v][1]/u[v][0];if(r===2)m([u[v]],h/y);else for(let b=v;b<u.length;b++)m([u[v],u[b]],h/y/(u[b][1]/u[b][0]))}if(!f)throw new Error(`train_for(): no train of ${r} stages reaches a ratio of ${n}`);let g=f.stages.map(([v,y])=>l?[y,v]:[v,y]),p=g.reduce((v,[y,b])=>v*b/y,1);return{type:"record",fields:new Map([["stages",g],["ratio",p],["error",p/n-1]])}}),path_points:w1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:z1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let r=D3(q3(t[0]),n),c=[...r.closed.map(a=>[...a,a[0]]),...r.open];return e.step(c.reduce((a,s)=>a+s.length,0)),c.map(a=>a.map(([s,i])=>[s,i]))}),spline_points:w1("points, steps, closed",(t,e)=>{let n=S5(t[0],"spline_points",e),r=t[1]===void 0?8:Math.floor(z1(t[1],"spline_points"));if(!(r>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*r>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*r),Re(n,r,t[2]===!0)}),rotation:w1("angles",t=>{let[e,n,r]=Oe(t[0],"rotation");return mr(Qt(dr(r),Qt(fr(n),ur(e))))}),euler:w1("matrix",t=>e7(hr(t[0],"euler"))),orient:w1("x, z",t=>{let e=Kt(Oe(t[0],"orient"),"orient"),n=Oe(t[1]??[0,0,1],"orient"),r=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=Kt([n[0]-r*e[0],n[1]-r*e[1],n[2]-r*e[2]],"orient");let c=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return e7([[e[0],c[0],n[0]],[e[1],c[1],n[1]],[e[2],c[2],n[2]]])})};function S5(t,e,n){return $0(t,e,n).map((c,a)=>{if(!Array.isArray(c)||typeof c[0]!="number"||typeof c[1]!="number")throw new Error(`${e}(): points[${a}] must be an [x, y] point`);return[c[0],c[1]]})}function Jt(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([o,l],h)=>h===0||o!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let r=0,c=0;for(;r<n.length-2;r++){let o=Math.hypot(n[r+1][0]-n[r][0],n[r+1][1]-n[r][1]);if(c+o>=e)break;c+=o}let[a,s]=[n[r],n[r+1]],i=(e-c)/Math.hypot(s[0]-a[0],s[1]-a[1]);return{point:[a[0]+(s[0]-a[0])*i,a[1]+(s[1]-a[1])*i],heading:Math.atan2(s[1]-a[1],s[0]-a[0])/E0}}function Oe(t,e){if(!Array.isArray(t)||t.length<2||t.length>3||!t.every(n=>typeof n=="number"))throw new Error(`${e}() needs [x, y, z]`);return[t[0],t[1],t[2]??0]}function Kt(t,e){let n=Math.hypot(...t);if(!(n>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[t[0]/n,t[1]/n,t[2]/n]}function hr(t,e){if(!Array.isArray(t)||t.length<3||!t.slice(0,3).every(n=>Array.isArray(n)&&n.length>=3&&n.slice(0,3).every(r=>typeof r=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var ur=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[1,0,0],[0,e,-n],[0,n,e]]},fr=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[e,0,n],[0,1,0],[-n,0,e]]},dr=t=>{let[e,n]=[Math.cos(t*E0),Math.sin(t*E0)];return[[e,-n,0],[n,e,0],[0,0,1]]},Qt=(t,e)=>t.map(n=>[0,1,2].map(r=>n[0]*e[0][r]+n[1]*e[1][r]+n[2]*e[2][r])),mr=t=>t.map(e=>e.map(o2));function e7(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,r=Math.atan2(-t[0][1],t[1][1])/E0;return[0,n,o2(r)]}return[o2(Math.atan2(t[2][1],t[2][2])/E0),o2(Math.asin(e)/E0),o2(Math.atan2(t[1][0],t[0][0])/E0)]}function Re(t,e,n=!1){if(t.length<3)return t.map(([s,i])=>[s,i]);let r=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=t.length){let[i,o]=[t[t.length-1],t[t.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return t[s]},c=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[i,o,l,h]=[r(s-1),r(s),r(s+1),r(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,m=d*f;c.push([0,1].map(g=>.5*(2*o[g]+(-i[g]+l[g])*f+(2*i[g]-5*o[g]+4*l[g]-h[g])*d+(-i[g]+3*o[g]-3*l[g]+h[g])*m)))}}return c.push(n?c[0]:[t[t.length-1][0],t[t.length-1][1]]),c}function f3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var A5=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function pr(t,e,n,r){if(e==="flat")return[];let c=f3(t,r),a=t/c,s=[];for(let i=0;i<c;i++)(e==="out"?i%2===1:i%2===0)&&s.push(A5(i*a,-1,(i+1)*a,n));return s}function w4(t,e,n,r,c){let a=[([o,l])=>[o,l],([o,l])=>[t-l,o],([o,l])=>[t-o,e-l],([o,l])=>[l,e-o]],s=[t,e,t,e],i=[];return n.forEach((o,l)=>{for(let h of pr(s[l],o,r,c))i.push(h.map(a[l]))}),k0([A5(0,0,t,e)],i)}function s7(t,e,n,r){let c=f3(t,r),a=t/c,s=[];for(let i=0;i<c;i++)(e==="out"?i%2===0:i%2===1)&&s.push(A5(i*a,-n/2,(i+1)*a,n/2));return s}function i7(t,e,n,r,c){let a=A5(-t/2,-1,t/2,e),s=A5(-n/2,c,n/2,c+r);return[a,s]}function o7(t,e,n,r,c){let a=[],s=c+r,i=Math.floor(t/n),o=(t-i*n)/2;for(let l=0;l<=i;l++){let h=o+l*n,u=l%2===0?r:r-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?r:0),m=Math.min(f+c,e-(l%2===0?r:0));m-d>=r/2&&a.push([[h,d],[h,m]])}}return a}var m2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var o1=class extends Error{constructor(n,r){super(r?`${n} (${m2(r)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,r&&(this.line=r.line,this.col=r.col,this.file=r.file)}addFrame(n,r,c){let a=this.trace.find(s=>s.name===r&&s.line===c.line&&s.col===c.col&&s.file===c.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:r,line:c.line,col:c.col,...c.file&&{file:c.file},count:1})}},gr=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function N3(t,e){let n=[],r=[],c=0,a=1,s=0,i=()=>({line:a,col:c-s+1,offset:c,...e&&{file:e}}),o=l=>{for(let h=0;h<l;h++)t[c]===`
|
|
6
|
+
`}},me=class t extends de{constructor(n=null){super(n);G(this,"polygon",null)}get poly(){return this.polygon}addChild(n){let r=new t(this);return r.polygon=n,this.children.push(r),r}child(n){if(n<0||n>=this.children.length)throw new Error("Index out of range");return this.children[n]}area(){let n=this.polygon===null?0:V4.area(this.polygon);for(let r of this.children)n+=r.area();return n}};var z5=class extends me{};var $=class ${constructor(){G(this,"cliptype",r0.NoClip);G(this,"fillrule",U1.EvenOdd);G(this,"actives",null);G(this,"sel",null);G(this,"minimaList",[]);G(this,"intersectList",[]);G(this,"vertexList",[]);G(this,"outrecList",[]);G(this,"scanlineHeap",new T4);G(this,"scanlineSet",new Set);G(this,"scanlineArr",[]);G(this,"useScanlineArray",!1);G(this,"horzSegList",[]);G(this,"horzJoinList",[]);G(this,"currentLocMin",0);G(this,"currentBotY",0);G(this,"curXValidAtTop",!1);G(this,"isSortedMinimaList",!1);G(this,"hasOpenPaths",!1);G(this,"usingPolytree",!1);G(this,"succeeded",!1);G(this,"zCallbackInternal");G(this,"preserveCollinear",!0);G(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,n){return e.x===n.x&&e.y===n.y}setZ(e,n,r){let c=this.zCallbackInternal;c&&($.getPolyType(e)===$0.Subject?(this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:r.z=0,c(e.bot,e.top,n.bot,n.top,r)):(this.xyEqual(r,n.bot)?r.z=n.bot.z??0:this.xyEqual(r,n.top)?r.z=n.top.z??0:this.xyEqual(r,e.bot)?r.z=e.bot.z??0:this.xyEqual(r,e.top)?r.z=e.top.z??0:r.z=0,c(n.bot,n.top,e.bot,e.top,r)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return $.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return $.openPathsEnabled&&e.localMin.isOpen&&$.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(Y1.OpenStart|Y1.OpenEnd))!==Y1.None}static getPrevHotEdge(e){let n=e.prevInAEL;if(!$.openPathsEnabled){for(;n!==null&&!$.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!$.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,n){let r=n.y-e.y;return r!==0?(n.x-e.x)/r:n.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,n){return n===e.top.y||e.top.x===e.bot.x?e.top.x:n===e.bot.y?e.bot.x:R1.roundToEven(e.bot.x+e.dx*(n-e.bot.y))}static isHorizontal(e){return e.dx===Number.NEGATIVE_INFINITY||e.dx===Number.POSITIVE_INFINITY}static isHeadingRightHorz(e){return e.dx===Number.NEGATIVE_INFINITY}static isHeadingLeftHorz(e){return e.dx===Number.POSITIVE_INFINITY}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,n){return e.localMin.polytype===n.localMin.polytype}static setDx(e){e.dx=$.getDx(e.bot,e.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaximaVertex(e){return(e.flags&Y1.LocalMax)!==Y1.None}static isMaximaEdge(e){return(e.vertexTop.flags&Y1.LocalMax)!==Y1.None}static getMaximaPair(e){let n=e.nextInAEL;for(;n!==null;){if(n.vertexTop===e.vertexTop)return n;n=n.nextInAEL}return null}boundingBoxesOverlap(e,n,r,c){let a=e.x<n.x?e.x:n.x;if((r.x>c.x?r.x:c.x)<a)return!1;let o=e.x>n.x?e.x:n.x,i=r.x<c.x?r.x:c.x;if(o<i)return!1;let l=e.y<n.y?e.y:n.y;if((r.y>c.y?r.y:c.y)<l)return!1;let u=e.y>n.y?e.y:n.y,f=r.y<c.y?r.y:c.y;return u>=f}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||(this.minimaList.sort((e,n)=>n.vertex.pt.y-e.vertex.pt.y),this.isSortedMinimaList=!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.curXValidAtTop=!1,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let n=0,r=e.length;n<r;n++){let c=e[n];this.scanlineSet.add(c),this.scanlineHeap.push(c)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let n=this.scanlineArr;for(let r=0,c=n.length;r<c;r++)if(n[r]===e)return;n.push(e),n.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let n=this.scanlineArr,r=n.length;if(r===0)return null;let c=0,a=n[0];for(let s=1;s<r;s++){let o=n[s];o>a&&(a=o,c=s)}return n[c]=n[r-1],n.pop(),a}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,n,r=!1){let c=[e];this.addPaths(c,n,r)}addPaths(e,n,r=!1){r&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,F3.addPathsToVertexList(e,n,r,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let n of e.minimaList)this.minimaList.push(new M5(n.vertex,n.polytype,n.isOpen)),n.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let n=e.prevInAEL,r=e.nextInAEL;n===null&&r===null&&e!==this.actives||(n!==null?n.nextInAEL=r:this.actives=r,r!==null&&(r.prevInAEL=n))}getBounds(){let e={left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER};for(let n of this.vertexList){let r=n;do r.pt.x<e.left&&(e.left=r.pt.x),r.pt.x>e.right&&(e.right=r.pt.x),r.pt.y<e.top&&(e.top=r.pt.y),r.pt.y>e.bottom&&(e.bottom=r.pt.y),r=r.next;while(r!==n)}return d3.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,n){if(e===r0.NoClip)return;$.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=n,this.cliptype=e,this.reset();let r=this.popScanline();if(r!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(r);let c;for(;(c=this.popHorz())!==null;)this.doHorizontal(c);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=r;let a=this.popScanline();if(a===null)break;for(r=a,this.doIntersections(r),this.doTopOfScanbeam(r);(c=this.popHorz())!==null;)this.doHorizontal(c)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let n=this.popLocalMinima(),r;(n.vertex.flags&Y1.OpenStart)!==Y1.None?r=null:(r=new k5,r.bot=n.vertex.pt,r.curX=n.vertex.pt.x,r.windDx=-1,r.vertexTop=n.vertex.prev,r.top=n.vertex.prev.pt,r.outrec=null,r.localMin=n,$.setDx(r));let c;if((n.vertex.flags&Y1.OpenEnd)!==Y1.None?c=null:(c=new k5,c.bot=n.vertex.pt,c.curX=n.vertex.pt.x,c.windDx=1,c.vertexTop=n.vertex.next,c.top=n.vertex.next.pt,c.outrec=null,c.localMin=n,$.setDx(c)),r!==null&&c!==null){if($.isHorizontal(r)){if($.isHeadingRightHorz(r)){let s=r;r=c,c=s}}else if($.isHorizontal(c)){if($.isHeadingLeftHorz(c)){let s=r;r=c,c=s}}else if(r.dx<c.dx){let s=r;r=c,c=s}}else r===null&&(r=c,c=null);let a;if(r.isLeftBound=!0,this.insertLeftEdge(r),$.openPathsEnabled?$.isOpen(r)?(this.setWindCountForOpenPathEdge(r),a=this.isContributingOpen(r)):(this.setWindCountForClosedPathEdge(r),a=this.isContributingClosed(r)):(this.setWindCountForClosedPathEdge(r),a=this.isContributingClosed(r)),c!==null){for(c.windCount=r.windCount,c.windCount2=r.windCount2,this.insertRightEdge(r,c),a&&(this.addLocalMinPoly(r,c,r.bot,!0),$.isHorizontal(r)||this.checkJoinLeft(r,r.bot));c.nextInAEL!==null&&this.isValidAelOrder(c.nextInAEL,c);)this.intersectEdges(c,c.nextInAEL,c.bot),this.swapPositionsInAEL(c,c.nextInAEL);$.isHorizontal(c)?this.pushHorz(c):(this.checkJoinRight(c,c.bot),this.insertScanline(c.top.y))}else a&&$.openPathsEnabled&&this.startOpenPath(r,r.bot);$.isHorizontal(r)?this.pushHorz(r):this.insertScanline(r.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!$.openPathsEnabled){this.doHorizontalClosed(e);return}let n=$.isOpen(e),r=e.bot.y,c=n?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:s,rightX:o}=this.resetHorzDirection(e,c),i=s,l=o;if($.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:r});this.addToHorzSegList(h)}for(;;){let h=a?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===c){if($.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),$.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(c!==e.vertexTop||$.isOpenEnd(e)){if(a&&h.curX>l||!a&&h.curX<i)break;if(h.curX===e.top.x&&!$.isHorizontal(h)){let d=$.nextVertex(e).pt;if($.isOpen(h)&&!$.isSamePolyType(h,e)&&!$.isHotEdge(h)){if(a&&$.topX(h,d.y)>d.x||!a&&$.topX(h,d.y)<d.x)break}else if(a&&$.topX(h,d.y)>=d.x||!a&&$.topX(h,d.y)<=d.x)break}}let f={x:h.curX,y:r};a?(this.intersectEdges(e,h,f),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,f),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,f),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,f),e.curX=h.curX,h=e.prevInAEL),$.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(n&&$.isOpenEnd(e)){$.isHotEdge(e)&&(this.addOutPt(e,e.top),$.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if($.nextVertex(e).pt.y!==e.top.y)break;$.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let u=this.resetHorzDirection(e,c);i=u.leftX,l=u.rightX}if($.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let n=e.bot.y,r=this.getCurrYMaximaVertex(e),{isLeftToRight:c,leftX:a,rightX:s}=this.resetHorzDirection(e,r),o=a,i=s;if($.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:n});this.addToHorzSegList(l)}for(;;){let l=c?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===r){if($.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),$.isHotEdge(e)){for(;e.vertexTop!==r;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);c?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(r!==e.vertexTop){if(c&&l.curX>i||!c&&l.curX<o)break;if(l.curX===e.top.x&&!$.isHorizontal(l)){let f=$.nextVertex(e).pt,d=$.topX(l,f.y);if(c&&d>=f.x||!c&&d<=f.x)break}}let u={x:l.curX,y:n};c?(this.intersectEdges(e,l,u),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,u),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,u),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,u),e.curX=l.curX,l=e.prevInAEL),$.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if($.nextVertex(e).pt.y!==e.top.y)break;$.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,r);o=h.leftX,i=h.rightX}if($.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,n=0;for(let r=0,c=e.length;r<c;r++){let a=e[r];this.updateHorzSegment(a)&&(e[n++]=a)}if(!(n<2)){e.length=n,this.horzSegList.sort(Cr);for(let r=0;r<n-1;r++){let c=this.horzSegList[r];for(let a=r+1;a<n;a++){let s=this.horzSegList[a];if(s.leftOp.pt.x>=c.rightOp.pt.x||s.leftToRight===c.leftToRight||s.rightOp.pt.x<=c.leftOp.pt.x)continue;let o=c.leftOp.pt.y;if(c.leftToRight){for(;c.leftOp.next.pt.y===o&&c.leftOp.next.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.next;for(;s.leftOp.prev.pt.y===o&&s.leftOp.prev.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let i=new w5(this.duplicateOp(c.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(i)}else{for(;c.leftOp.prev.pt.y===o&&c.leftOp.prev.pt.x<=s.leftOp.pt.x;)c.leftOp=c.leftOp.prev;for(;s.leftOp.next.pt.y===o&&s.leftOp.next.pt.x<=c.leftOp.pt.x;)s.leftOp=s.leftOp.next;let i=new w5(this.duplicateOp(s.leftOp,!0),this.duplicateOp(c.leftOp,!1));this.horzJoinList.push(i)}}}}}updateHorzSegment(e){let n=e.leftOp,r=this.getRealOutRec(n.outrec),c=r.frontEdge!==null,a=n.pt.y,s=n,o=n;if(c){let l=r.pts,h=l.next;for(;s!==h&&s.prev.pt.y===a;)s=s.prev;for(;o!==l&&o.next.pt.y===a;)o=o.next}else{for(;s.prev!==o&&s.prev.pt.y===a;)s=s.prev;for(;o.next!==s&&o.next.pt.y===a;)o=o.next}let i=this.setHorzSegHeadingForward(e,s,o)&&e.leftOp.horz===null;return i?e.leftOp.horz=e:e.rightOp=null,i}setHorzSegHeadingForward(e,n,r){return n.pt.x===r.pt.x?!1:(n.pt.x<r.pt.x?(e.leftOp=n,e.rightOp=r,e.leftToRight=!0):(e.leftOp=r,e.rightOp=n,e.leftToRight=!1),!0)}duplicateOp(e,n){let r=new F2(e.pt,e.outrec);return n?(r.next=e.next,r.next.prev=r,r.prev=e,e.next=r):(r.prev=e.prev,r.prev.next=r,r.next=e,e.prev=r),r}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let n=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let r=this.actives;for(;r!==null;){if(r.top.y===e)if(r.curX=r.top.x,$.isMaximaEdge(r)){r=this.doMaxima(r);continue}else $.isHotEdge(r)&&this.addOutPt(r,r.top),this.updateEdgeIntoAEL(r),$.isHorizontal(r)&&this.pushHorz(r);else n||(r.curX=$.topX(r,e));r=r.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let n=this.getRealOutRec(e.op1.outrec),r=this.getRealOutRec(e.op2.outrec),c=e.op1.next,a=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,c.prev=a,a.next=c,n===r){let s=this.newOutRec();s.pts=c,this.fixOutRecPts(s),n.pts.outrec===s&&(n.pts=e.op1,n.pts.outrec=n),this.usingPolytree?(this.path1InsidePath2(n.pts,s.pts)?([s.pts,n.pts]=[n.pts,s.pts],this.fixOutRecPts(n),this.fixOutRecPts(s),s.owner=n):this.path1InsidePath2(s.pts,n.pts)?s.owner=n:s.owner=n.owner,n.splits===null&&(n.splits=[]),n.splits.push(s.idx)):s.owner=n}else r.pts=null,this.usingPolytree?(this.setOwner(r,n),this.moveSplits(r,n)):r.owner=n}}fixOutRecPts(e){let n=e.pts;do n.outrec=e,n=n.next;while(n!==e.pts)}path1InsidePath2(e,n){let r=_1.IsOn,c=e;do{switch(this.pointInOpPolygon(c.pt,n)){case _1.IsOutside:if(r===_1.IsOutside)return!1;r=_1.IsOutside;break;case _1.IsInside:if(r===_1.IsInside)return!0;r=_1.IsInside;break;default:break}c=c.next}while(c!==e);return R1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(n))}pointInOpPolygon(e,n){if(n===n.next||n.prev===n.next)return _1.IsOutside;let r=n;do{if(n.pt.y!==e.y)break;n=n.next}while(n!==r);if(n.pt.y===e.y)return _1.IsOutside;let c=n.pt.y<e.y,a=c,s=0;for(r=n.next;r!==n;){if(c)for(;r!==n&&r.pt.y<e.y;)r=r.next;else for(;r!==n&&r.pt.y>e.y;)r=r.next;if(r===n)break;if(r.pt.y===e.y){if(r.pt.x===e.x||r.pt.y===r.prev.pt.y&&e.x<r.prev.pt.x!=e.x<r.pt.x)return _1.IsOn;if(r=r.next,r===n)break;continue}if(r.pt.x<=e.x||r.prev.pt.x<=e.x)if(r.prev.pt.x<e.x&&r.pt.x<e.x)s=1-s;else{let o=R1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return _1.IsOn;o<0===c&&(s=1-s)}c=!c,r=r.next}if(c===a)return s===0?_1.IsOutside:_1.IsInside;{let o=R1.crossProductSign(r.prev.pt,r.pt,e);if(o===0)return _1.IsOn;o<0===c&&(s=1-s)}return s===0?_1.IsOutside:_1.IsInside}getCleanPath(e){let n=[],r=e;for(;r.next!==e&&(r.pt.x===r.next.pt.x&&r.pt.x===r.prev.pt.x||r.pt.y===r.next.pt.y&&r.pt.y===r.prev.pt.y);)r=r.next;n.push(r.pt);let c=r;for(r=r.next;r!==e;)(r.pt.x!==r.next.pt.x||r.pt.x!==c.pt.x)&&(r.pt.y!==r.next.pt.y||r.pt.y!==c.pt.y)&&(n.push(r.pt),c=r),r=r.next;return n}moveSplits(e,n){if(e.splits!==null){n.splits===null&&(n.splits=[]);for(let r of e.splits)r!==n.idx&&n.splits.push(r);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let n=this.sel;for(;n!==null&&n.jump!==null;){let r=null;for(;n!==null&&n.jump!==null;){let c=n,a=n.jump,s=a,o=a?.jump||null;for(n.jump=o;n!==s&&a!==o;)if(a.curX<n.curX){let i=a.prevInSEL;for(;this.addNewIntersectNode(i,a,e),i!==n;)i=i.prevInSEL;if(i=a,a=this.extractFromSEL(i),s=a,n!==null&&this.insert1Before2InSEL(i,n),n!==c)continue;c=i,c.jump=o,r===null?this.sel=c:r.jump=c}else n=n.nextInSEL;r=c,n=o}n=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(Pr);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let r=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[r]);)r++;[this.intersectList[r],this.intersectList[e]]=[this.intersectList[e],this.intersectList[r]]}let n=this.intersectList[e];this.intersectEdges(n.edge1,n.edge2,n.pt),this.swapPositionsInAEL(n.edge1,n.edge2),n.edge1.curX=n.pt.x,n.edge2.curX=n.pt.x,this.checkJoinLeft(n.edge2,n.pt,!0),this.checkJoinRight(n.edge1,n.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let n=this.actives;this.sel=n;let r=Number.NEGATIVE_INFINITY,c=!1;for(;n!==null;){n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL;let a=$.topX(n,e);n.curX=a,a<r&&(c=!0),r=a,n=n.nextInAEL}return c}doMaxima(e){let n=e.prevInAEL,r=e.nextInAEL;if($.isOpenEnd(e))return $.isHotEdge(e)&&this.addOutPt(e,e.top),$.isHorizontal(e)||($.isHotEdge(e)&&($.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),r;let c=$.getMaximaPair(e);if(c===null)return r;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(c)&&this.split(c,c.top);r!==c;)this.intersectEdges(e,r,e.top),this.swapPositionsInAEL(e,r),r=e.nextInAEL;return $.isOpen(e)?($.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(c),this.deleteFromAEL(e),n!==null?n.nextInAEL:this.actives):($.isHotEdge(e)&&this.addLocalMaxPoly(e,c,e.top),this.deleteFromAEL(e),this.deleteFromAEL(c),n!==null?n.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=$.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,$.setDx(e),this.isJoined(e)&&this.split(e,e.bot),$.isHorizontal(e)){$.openPathsEnabled?$.isOpen(e)||this.trimHorz(e,this.preserveCollinear):this.trimHorz(e,this.preserveCollinear);return}this.insertScanline(e.top.y),this.checkJoinLeft(e,e.bot),this.checkJoinRight(e,e.bot,!0)}trimHorz(e,n){let r=!1,c=$.nextVertex(e).pt;for(;c.y===e.top.y&&!(n&&c.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=$.nextVertex(e),e.top=c,r=!0,$.isMaximaVertex(e.vertexTop)));)c=$.nextVertex(e).pt;r&&$.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new fe(e))}addNewIntersectNode(e,n,r){let c=R1.getLineIntersectPt(e.bot,e.top,n.bot,n.top);if(c===null&&(c={x:e.curX,y:r}),c.y>this.currentBotY||c.y<r){let s=Math.abs(e.dx),o=Math.abs(n.dx);s>100&&o>100?s>o?c=R1.getClosestPtOnSegment(c,e.bot,e.top):c=R1.getClosestPtOnSegment(c,n.bot,n.top):s>100?c=R1.getClosestPtOnSegment(c,e.bot,e.top):o>100?c=R1.getClosestPtOnSegment(c,n.bot,n.top):(c.y<r?c.y=r:c.y=this.currentBotY,s<o?c.x=$.topX(e,c.y):c.x=$.topX(n,c.y))}let a=_6(c,e,n);this.intersectList.push(a)}extractFromSEL(e){let n=e.nextInSEL;return n!==null&&(n.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=n,n}insert1Before2InSEL(e,n){e.prevInSEL=n.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=n,n.prevInSEL=e}getCurrYMaximaVertexOpen(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(Y1.OpenEnd|Y1.LocalMax))===Y1.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(Y1.OpenEnd|Y1.LocalMax))===Y1.None;)n=n.prev;return $.isMaximaVertex(n)||(n=null),n}getCurrYMaximaVertex(e){let n=e.vertexTop;if(e.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return $.isMaximaVertex(n)||(n=null),n}resetHorzDirection(e,n){if(e.bot.x===e.top.x){let r=e.curX,c=e.curX,a=e.nextInAEL;for(;a!==null&&a.vertexTop!==n;)a=a.nextInAEL;return{isLeftToRight:a!==null,leftX:r,rightX:c}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let n=e.outrec;return e===n.frontEdge?n.pts:n.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let n=this.actives;for(;n.nextInAEL!==null&&this.isValidAelOrder(n.nextInAEL,e);)n=n.nextInAEL;n.joinWith===B0.Right&&(n=n.nextInAEL),e.nextInAEL=n.nextInAEL,n.nextInAEL!==null&&(n.nextInAEL.prevInAEL=e),e.prevInAEL=n,n.nextInAEL=e}}insertRightEdge(e,n){n.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=n),n.prevInAEL=e,e.nextInAEL=n}setWindCountForOpenPathEdge(e){let n=this.actives;if(this.fillrule===U1.EvenOdd){let r=0,c=0;for(;n!==e;)$.getPolyType(n)===$0.Clip?c++:$.isOpen(n)||r++,n=n.nextInAEL;e.windCount=$.isOdd(r)?1:0,e.windCount2=$.isOdd(c)?1:0}else for(;n!==e;)$.getPolyType(n)===$0.Clip?e.windCount2+=n.windDx:$.isOpen(n)||(e.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(e){let n=e.prevInAEL,r=$.getPolyType(e);if(!$.openPathsEnabled){for(;n!==null&&$.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===U1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===U1.EvenOdd)for(;n!==e;)$.getPolyType(n)!==r&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)$.getPolyType(n)!==r&&(e.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&($.getPolyType(n)!==r||$.isOpen(n));)n=n.prevInAEL;if(n===null?(e.windCount=e.windDx,n=this.actives):this.fillrule===U1.EvenOdd?(e.windCount=e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx:e.windCount=$.isOpen(e)?1:e.windDx:n.windDx*e.windDx<0?e.windCount=n.windCount:e.windCount=n.windCount+e.windDx,e.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===U1.EvenOdd)for(;n!==e;)$.getPolyType(n)!==r&&!$.isOpen(n)&&(e.windCount2=e.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==e;)$.getPolyType(n)!==r&&!$.isOpen(n)&&(e.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let n,r;switch(this.fillrule){case U1.Positive:r=e.windCount>0,n=e.windCount2>0;break;case U1.Negative:r=e.windCount<0,n=e.windCount2<0;break;default:r=e.windCount!==0,n=e.windCount2!==0;break}switch(this.cliptype){case r0.Intersection:return n;case r0.Union:return!r&&!n;default:return!n}}isContributingClosed(e){switch(this.fillrule){case U1.Positive:if(e.windCount!==1)return!1;break;case U1.Negative:if(e.windCount!==-1)return!1;break;case U1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case r0.Intersection:return this.fillrule===U1.Positive?e.windCount2>0:this.fillrule===U1.Negative?e.windCount2<0:e.windCount2!==0;case r0.Union:return this.fillrule===U1.Positive?e.windCount2<=0:this.fillrule===U1.Negative?e.windCount2>=0:e.windCount2===0;case r0.Difference:{let n=this.fillrule===U1.Positive?e.windCount2<=0:this.fillrule===U1.Negative?e.windCount2>=0:e.windCount2===0;return $.getPolyType(e)===$0.Subject?n:!n}case r0.Xor:return!0;default:return!1}}addLocalMinPoly(e,n,r,c=!1){let a=this.newOutRec();if(e.outrec=a,n.outrec=a,$.isOpen(e))a.owner=null,a.isOpen=!0,e.windDx>0?this.setSides(a,e,n):this.setSides(a,n,e);else{a.isOpen=!1;let o=$.getPrevHotEdge(e);o!==null?(this.usingPolytree&&this.setOwner(a,o.outrec),a.owner=o.outrec,this.outrecIsAscending(o)===c?this.setSides(a,n,e):this.setSides(a,e,n)):(a.owner=null,c?this.setSides(a,e,n):this.setSides(a,n,e))}let s=new F2(r,a);return a.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new ue;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,n){let r=this.newOutRec();r.isOpen=!0,e.windDx>0?(r.frontEdge=e,r.backEdge=null):(r.frontEdge=null,r.backEdge=e),e.outrec=r;let c=new F2(n,r);return r.pts=c,c}checkJoinLeft(e,n,r=!1){let c=e.prevInAEL;c!==null&&(!r&&e.curX!==c.curX||!$.isHotEdge(e)||!$.isHotEdge(c)||$.isHorizontal(e)||$.isHorizontal(c)||$.isOpen(e)||$.isOpen(c)||(n.y<e.top.y+2||n.y<c.top.y+2)&&(e.bot.y>n.y||c.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,c.bot,c.top)||R1.isCollinear(e.top,n,c.top)&&(e.outrec.idx===c.outrec.idx?this.addLocalMaxPoly(c,e,n):e.outrec.idx<c.outrec.idx?this.joinOutrecPaths(e,c):this.joinOutrecPaths(c,e),c.joinWith=B0.Right,e.joinWith=B0.Left))}checkJoinRight(e,n,r=!1){let c=e.nextInAEL;c!==null&&(!r&&e.curX!==c.curX||!$.isHotEdge(e)||!$.isHotEdge(c)||$.isHorizontal(e)||$.isHorizontal(c)||$.isOpen(e)||$.isOpen(c)||(n.y<e.top.y+2||n.y<c.top.y+2)&&(e.bot.y>n.y||c.bot.y>n.y)||r&&this.perpendicDistFromLineSqrdGreaterThanQuarter(n,c.bot,c.top)||R1.isCollinear(e.top,n,c.top)&&(e.outrec.idx===c.outrec.idx?this.addLocalMaxPoly(e,c,n):e.outrec.idx<c.outrec.idx?this.joinOutrecPaths(e,c):this.joinOutrecPaths(c,e),e.joinWith=B0.Right,c.joinWith=B0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,n,r){let c=e.x-n.x,a=e.y-n.y,s=r.x-n.x,o=r.y-n.y;if(s===0&&o===0)return!1;let i=R1.maxCoordForSafeCrossSq;if(Math.abs(c)<i&&Math.abs(a)<i&&Math.abs(s)<i&&Math.abs(o)<i){let h=c*o-s*a;return h*h/(s*s+o*o)>.25}if(Number.isSafeInteger(c)&&Number.isSafeInteger(a)&&Number.isSafeInteger(s)&&Number.isSafeInteger(o)){let h=BigInt(c)*BigInt(o)-BigInt(s)*BigInt(a),u=h*h,f=BigInt(s)*BigInt(s)+BigInt(o)*BigInt(o);return B6*u>f}let l=c*o-s*a;return l*l/(s*s+o*o)>.25}intersectEdges(e,n,r){let c;if(this.hasOpenPaths&&($.isOpen(e)||$.isOpen(n))){if($.isOpen(e)&&$.isOpen(n))return;if($.isOpen(n)){let l=e;e=n,n=l}if(this.isJoined(n)&&this.split(n,r),this.cliptype===r0.Union){if(!$.isHotEdge(n))return}else if(n.localMin.polytype===$0.Subject)return;switch(this.fillrule){case U1.Positive:if(n.windCount!==1)return;break;case U1.Negative:if(n.windCount!==-1)return;break;default:if(Math.abs(n.windCount)!==1)return;break}if($.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),$.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(r.x===e.localMin.vertex.pt.x&&r.y===e.localMin.vertex.pt.y&&!$.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&$.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}c=this.startOpenPath(e,r)}else c=this.startOpenPath(e,r);this.setZ(e,n,c.pt);return}this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r);let a,s;switch(e.localMin.polytype===n.localMin.polytype?this.fillrule===U1.EvenOdd?(a=e.windCount,e.windCount=n.windCount,n.windCount=a):(e.windCount+n.windDx===0?e.windCount=-e.windCount:e.windCount+=n.windDx,n.windCount-e.windDx===0?n.windCount=-n.windCount:n.windCount-=e.windDx):(this.fillrule!==U1.EvenOdd?e.windCount2+=n.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==U1.EvenOdd?n.windCount2-=e.windDx:n.windCount2=n.windCount2===0?1:0),this.fillrule){case U1.Positive:a=e.windCount,s=n.windCount;break;case U1.Negative:a=-e.windCount,s=-n.windCount;break;default:a=Math.abs(e.windCount),s=Math.abs(n.windCount);break}let o=a===0||a===1,i=s===0||s===1;if(!(!$.isHotEdge(e)&&!o||!$.isHotEdge(n)&&!i))if($.isHotEdge(e)&&$.isHotEdge(n))if(a!==0&&a!==1||s!==0&&s!==1||e.localMin.polytype!==n.localMin.polytype&&this.cliptype!==r0.Xor)c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);else if($.isFront(e)||e.outrec===n.outrec){c=this.addLocalMaxPoly(e,n,r),c&&this.setZ(e,n,c.pt);let l=this.addLocalMinPoly(e,n,r);this.setZ(e,n,l.pt)}else{c=this.addOutPt(e,r),this.setZ(e,n,c.pt);let l=this.addOutPt(n,r);this.setZ(e,n,l.pt),this.swapOutrecs(e,n)}else if($.isHotEdge(e))c=this.addOutPt(e,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else if($.isHotEdge(n))c=this.addOutPt(n,r),this.setZ(e,n,c.pt),this.swapOutrecs(e,n);else{let l,h;switch(this.fillrule){case U1.Positive:l=e.windCount2,h=n.windCount2;break;case U1.Negative:l=-e.windCount2,h=-n.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(n.windCount2);break}if(!$.isSamePolyType(e,n))c=this.addLocalMinPoly(e,n,r),this.setZ(e,n,c.pt);else if(a===1&&s===1){switch(c=null,this.cliptype){case r0.Union:if(l>0&&h>0)return;c=this.addLocalMinPoly(e,n,r);break;case r0.Difference:($.getPolyType(e)===$0.Clip&&l>0&&h>0||$.getPolyType(e)===$0.Subject&&l<=0&&h<=0)&&(c=this.addLocalMinPoly(e,n,r));break;case r0.Xor:c=this.addLocalMinPoly(e,n,r);break;default:if(l<=0||h<=0)return;c=this.addLocalMinPoly(e,n,r);break}c&&this.setZ(e,n,c.pt)}}}swapPositionsInAEL(e,n){let r=n.nextInAEL;r!==null&&(r.prevInAEL=e);let c=e.prevInAEL;c!==null&&(c.nextInAEL=n),n.prevInAEL=c,n.nextInAEL=e,e.prevInAEL=n,e.nextInAEL=r,n.prevInAEL===null&&(this.actives=n)}isValidAelOrder(e,n){if(n.curX!==e.curX)return n.curX>e.curX;let r=R1.crossProductSign(e.top,n.bot,n.top);if(r!==0)return r<0;if(!$.isMaximaEdge(e)&&e.top.y>n.top.y)return R1.crossProductSign(n.bot,e.top,$.nextVertex(e).pt)<=0;if(!$.isMaximaEdge(n)&&n.top.y>e.top.y)return R1.crossProductSign(n.bot,n.top,$.nextVertex(n).pt)>=0;let c=n.bot.y,a=n.isLeftBound;return e.bot.y!==c||e.localMin.vertex.pt.y!==c?n.isLeftBound:e.isLeftBound!==a?a:R1.isCollinear($.prevPrevVertex(e).pt,e.bot,e.top)?!0:R1.crossProductSign($.prevPrevVertex(e).pt,n.bot,$.prevPrevVertex(n).pt)>0===a}isJoined(e){return e.joinWith!==B0.None}split(e,n){e.joinWith===B0.Right?(e.joinWith=B0.None,e.nextInAEL.joinWith=B0.None,this.addLocalMinPoly(e,e.nextInAEL,n,!0)):(e.joinWith=B0.None,e.prevInAEL.joinWith=B0.None,this.addLocalMinPoly(e.prevInAEL,e,n,!0))}setSides(e,n,r){e.frontEdge=n,e.backEdge=r}findEdgeWithMatchingLocMin(e){let n=e.nextInAEL;for(;n!==null;){if(n.localMin?.equals(e.localMin))return n;!$.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y)?n=null:n=n.nextInAEL}for(n=e.prevInAEL;n!==null;){if(n.localMin?.equals(e.localMin))return n;if(!$.isHorizontal(n)&&!(e.bot.x===n.bot.x&&e.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(e,n){let r=e.outrec,c=$.isFront(e),a=r.pts,s=a.next;if(c&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!c&&n.x===s.pt.x&&n.y===s.pt.y)return s;let o=new F2(n,r);return s.prev=o,o.prev=a,o.next=s,a.next=o,c&&(r.pts=o),o}addLocalMaxPoly(e,n,r){if(this.isJoined(e)&&this.split(e,r),this.isJoined(n)&&this.split(n,r),$.isFront(e)===$.isFront(n))if($.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if($.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let c=this.addOutPt(e,r);if(e.outrec===n.outrec){let a=e.outrec;if(a.pts=c,this.usingPolytree){let s=$.getPrevHotEdge(e);s===null?a.owner=null:this.setOwner(a,s.outrec)}this.uncoupleOutRec(e)}else $.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e):e.outrec.idx<n.outrec.idx?this.joinOutrecPaths(e,n):this.joinOutrecPaths(n,e);return c}swapFrontBackSides(e){let n=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=n,e.pts=e.pts.next}setOwner(e,n){for(;n.owner!==null&&n.owner.pts===null;)n.owner=n.owner.owner;let r=n;for(;r!==null&&r!==e;)r=r.owner;r!==null&&(n.owner=e.owner),e.owner=n}uncoupleOutRec(e){let n=e.outrec;n!==null&&(n.frontEdge.outrec=null,n.backEdge.outrec=null,n.frontEdge=null,n.backEdge=null)}joinOutrecPaths(e,n){let r=e.outrec.pts,c=n.outrec.pts,a=r.next,s=c.next;$.isFront(e)?(s.prev=r,r.next=s,c.next=a,a.prev=c,e.outrec.pts=c,e.outrec.frontEdge=n.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(a.prev=c,c.next=a,r.next=s,s.prev=r,e.outrec.backEdge=n.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,e.outrec),$.isOpenEnd(e)&&(n.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,n.outrec=null}swapOutrecs(e,n){let r=e.outrec,c=n.outrec;if(r===c){let a=r.frontEdge;r.frontEdge=r.backEdge,r.backEdge=a;return}r!==null&&(e===r.frontEdge?r.frontEdge=n:r.backEdge=n),c!==null&&(n===c.frontEdge?c.frontEdge=e:c.backEdge=e),e.outrec=c,n.outrec=r}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,n){return Math.abs(e.x-n.x)<2&&Math.abs(e.y-n.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&($.ptsReallyClose(e.prev.pt,e.next.pt)||$.ptsReallyClose(e.pt,e.next.pt)||$.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,n,r,c){if(e===null||e.next===e||!r&&e.next===e.prev)return!1;c.length=0;let a,s;for(n?(a=e.pt,s=e.prev):(e=e.next,a=e.pt,s=e.next),c.push(a);s!==e;)s.pt.x===a.x&&s.pt.y===a.y||(a=s.pt,c.push(a)),n?s=s.prev:s=s.next;return c.length!==3||r||!$.isVerySmallTriangle(s)}buildPaths(e,n){e.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let c=this.outrecList[r++];if(c.pts===null)continue;let a=[];c.isOpen?$.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(c),$.buildPath(c.pts,this.reverseSolution,!1,a)&&e.push(a))}return!0}buildTree(e,n){e.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let c=this.outrecList[r++];if(c.pts!==null){if(c.isOpen){let a=[];$.buildPath(c.pts,this.reverseSolution,!0,a)&&n.push(a);continue}this.checkBounds(c)&&this.recursiveCheckOwners(c,e)}}}checkBounds(e){return e.pts===null?!1:d3.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!$.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=R1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,n){if(!(e.polypath!==null||d3.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner!==null?(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,n),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=n.addChild(e.path)}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let n=e.pts,r=n;for(;;){if(r!==null&&R1.isCollinear(r.prev.pt,r.pt,r.next.pt)&&(r.pt.x===r.prev.pt.x&&r.pt.y===r.prev.pt.y||r.pt.x===r.next.pt.x&&r.pt.y===r.next.pt.y||!this.preserveCollinear||R1.dotProductSign(r.prev.pt,r.pt,r.next.pt)<0)){if(r===e.pts&&(e.pts=r.prev),r=this.disposeOutPt(r),!this.isValidClosedPath(r)){e.pts=null;return}n=r;continue}if(r===null||(r=r.next,r===n))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!$.isVerySmallTriangle(e))}disposeOutPt(e){let n=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,n}fixSelfIntersects(e){let n=e.pts;if(n.prev!==n.next.next)for(;;){if(n.next&&n.next.next&&this.boundingBoxesOverlap(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)&&R1.segsIntersect(n.prev.pt,n.pt,n.next.pt,n.next.next.pt)){if((n===e.pts||n.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,n),e.pts===null)return;if(n=e.pts,n.prev===n.next.next)break;continue}if(n=n.next,n===e.pts)break}}doSplitOp(e,n){let r=n.prev,c=n.next.next;e.pts=r;let a=R1.getLineIntersectPt(r.pt,n.pt,n.next.pt,c.pt);this.zCallbackInternal&&this.zCallbackInternal(r.pt,n.pt,n.next.pt,c.pt,a);let s=$.areaOutPt(r),o=s<b5?-s:s;if(o<B6){e.pts=null;return}let i=this.areaTriangle(a,n.pt,n.next.pt),l=i<b5?-i:i;if(a.x===r.pt.x&&a.y===r.pt.y||a.x===c.pt.x&&a.y===c.pt.y)c.prev=r,r.next=c;else{let f=new F2(a,e);f.prev=r,f.next=c,c.prev=f,r.next=f}if(!(l>Lr)||!(l>o)&&i>b5!=s>b5)return;let h=this.newOutRec();h.owner=e.owner,n.outrec=h,n.next.outrec=h;let u=new F2(a,h);u.prev=n.next,u.next=n,h.pts=u,n.prev=u,n.next.next=u,this.usingPolytree&&(this.path1InsidePath2(r,u)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let n=R1.maxCoordForSafeAreaProduct,r=0,c=!0,a=e;do{let o=a.prev,i=a.pt;if(Math.abs(o.pt.x)>=n||Math.abs(o.pt.y)>=n||Math.abs(i.x)>=n||Math.abs(i.y)>=n){c=!1;break}r+=(o.pt.y+i.y)*(o.pt.x-i.x),a=a.next}while(a!==e);if(c)return BigInt(Math.round(r));let s=b5;a=e;do{let o=a.prev;if(Number.isSafeInteger(o.pt.y)&&Number.isSafeInteger(a.pt.y)&&Number.isSafeInteger(o.pt.x)&&Number.isSafeInteger(a.pt.x)){let i=BigInt(o.pt.y)+BigInt(a.pt.y),l=BigInt(o.pt.x)-BigInt(a.pt.x);s+=i*l}else{let i=o.pt.y+a.pt.y,l=o.pt.x-a.pt.x;s+=BigInt(Math.round(i*l))}a=a.next}while(a!==e);return s}areaTriangle(e,n,r){let c=R1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<c&&Math.abs(e.y)<c&&Math.abs(n.x)<c&&Math.abs(n.y)<c&&Math.abs(r.x)<c&&Math.abs(r.y)<c){let s=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(r.y)){let s=(BigInt(r.y)+BigInt(e.y))*(BigInt(r.x)-BigInt(e.x)),o=(BigInt(e.y)+BigInt(n.y))*(BigInt(e.x)-BigInt(n.x)),i=(BigInt(n.y)+BigInt(r.y))*(BigInt(n.x)-BigInt(r.x));return s+o+i}let a=(r.y+e.y)*(r.x-e.x)+(e.y+n.y)*(e.x-n.x)+(n.y+r.y)*(n.x-r.x);return BigInt(Math.round(a))}isValidOwner(e,n){for(;n!==null&&n!==e;)n=n.owner;return n===null}containsRect(e,n){return n.left>=e.left&&n.right<=e.right&&n.top>=e.top&&n.bottom<=e.bottom}checkSplitOwner(e,n){for(let r=0;r<n.length;r++){let c=this.outrecList[n[r]];if(c.pts===null&&c.splits!==null&&this.checkSplitOwner(e,c.splits))return!0;if(c=this.getRealOutRec(c),!(c===null||c===e||c.recursiveSplit===e)){if(c.recursiveSplit=e,c.splits!==null&&this.checkSplitOwner(e,c.splits))return!0;if(!(!this.checkBounds(c)||!this.containsRect(c.bounds,e.bounds)||!this.path1InsidePath2(e.pts,c.pts)))return this.isValidOwner(e,c)||(c.owner=e.owner),e.owner=c,!0}}return!1}};G($,"openPathsEnabled",!0);var pe=$,A2=class extends pe{constructor(){super(...arguments);G(this,"zCallback")}getZCallback(){return this.zCallback}addPath(n,r,c=!1){super.addPath(n,r,c)}addReuseableData(n){super.addReuseableData(n)}addPaths(n,r,c=!1){super.addPaths(n,r,c)}addSubject(n){this.addPaths(n,$0.Subject)}addOpenSubject(n){this.addPaths(n,$0.Subject,!0)}addClip(n){this.addPaths(n,$0.Clip)}execute(n,r,c,a){if(Array.isArray(c)){let s=c,o=a;s.length=0,o&&(o.length=0);try{this.executeInternal(n,r),this.buildPaths(s,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=c,o=a;s.clear(),o&&(o.length=0),this.usingPolytree=!0;try{this.executeInternal(n,r),this.buildTree(s,o||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var V4={area(t){return R1.area(t)},areaD(t){let e=0,n=t.length;if(n<3)return 0;let r=t[n-1];for(let c of t)e+=(r.y+c.y)*(r.x-c.x),r=c;return e*.5},scalePath64(t,e){let n=R1.maxSafeCoordinateForScale(e),r=[];for(let c of t)R1.checkSafeScaleValue(c.x,n,"scalePath64"),R1.checkSafeScaleValue(c.y,n,"scalePath64"),r.push({x:Math.round(c.x*e),y:Math.round(c.y*e)});return r},scalePaths64(t,e){let n=[];for(let r of t)n.push(V4.scalePath64(r,e));return n},scalePathD(t,e){let n=[];for(let r of t)n.push({x:r.x*e,y:r.y*e});return n},scalePathsD(t,e){let n=[];for(let r of t)n.push(V4.scalePathD(r,e));return n}};var _0;(function(t){t[t.Miter=0]="Miter",t[t.Square=1]="Square",t[t.Bevel=2]="Bevel",t[t.Round=3]="Round"})(_0||(_0={}));var h0;(function(t){t[t.Polygon=0]="Polygon",t[t.Joined=1]="Joined",t[t.Butt=2]="Butt",t[t.Square=3]="Square",t[t.Round=4]="Round"})(h0||(h0={}));var H4=class{constructor(e,n,r=h0.Polygon){G(this,"inPaths");G(this,"joinType");G(this,"endType");G(this,"pathsReversed");G(this,"lowestPathIdx");this.joinType=n,this.endType=r;let c=r===h0.Polygon||r===h0.Joined;this.inPaths=[];for(let a of e)this.inPaths.push(m3.stripDuplicates(a,c));if(r===h0.Polygon){let a=m3.getLowestPathInfo(this.inPaths);this.lowestPathIdx=a.idx,this.pathsReversed=this.lowestPathIdx>=0&&a.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},l0=class l0{constructor(e=2,n=0,r=!1,c=!1){G(this,"groupList",[]);G(this,"pathOut",[]);G(this,"normals",[]);G(this,"solution",[]);G(this,"solutionTree",null);G(this,"groupDelta",0);G(this,"delta",0);G(this,"mitLimSqr",0);G(this,"stepsPerRad",0);G(this,"stepSin",0);G(this,"stepCos",0);G(this,"joinType",_0.Bevel);G(this,"endType",h0.Polygon);G(this,"arcTolerance",0);G(this,"mergeGroups",!0);G(this,"miterLimit",2);G(this,"preserveCollinear",!1);G(this,"reverseSolution",!1);G(this,"zCallback");G(this,"deltaCallback",null);G(this,"ZCB",(e,n,r,c,a)=>{(e.z||0)!==0&&(e.z===r.z||e.z===c.z)?a.z=e.z:(r.z||0)!==0&&r.z===n.z?a.z=r.z:(n.z||0)!==0&&n.z===c.z?a.z=n.z:this.zCallback&&this.zCallback(e,n,r,c,a)});this.miterLimit=e,this.arcTolerance=n,this.mergeGroups=!0,this.preserveCollinear=r,this.reverseSolution=c}clear(){this.groupList.length=0}addPath(e,n,r){if(e.length===0)return;let c=[e];this.addPaths(c,n,r)}addPaths(e,n,r){e.length!==0&&this.groupList.push(new H4(e,n,r))}calcSolutionCapacity(){let e=0;for(let n of this.groupList)e+=n.endType===h0.Joined?n.inPaths.length*2:n.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let n of this.groupList)if(n.endType===h0.Polygon){e=n.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let a of this.groupList)for(let s of a.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/l0.sqr(this.miterLimit);for(let a of this.groupList)this.doGroupOffset(a);if(this.groupList.length===0)return;let n=this.checkPathsReversed(),r=n?U1.Negative:U1.Positive,c=new A2;c.preserveCollinear=this.preserveCollinear,c.reverseSolution=this.reverseSolution!==n,c.zCallback=this.ZCB,c.addSubject(this.solution),this.solutionTree!==null?c.execute(r0.Union,r,this.solutionTree):c.execute(r0.Union,r,this.solution)}execute(e,n){if(Array.isArray(n)){let r=n;r.length=0,this.solution=r,this.executeInternal(e)}else{let r=n;r.clear(),this.solutionTree=r,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,n){this.deltaCallback=e,this.execute(1,n)}static getUnitNormal(e,n){let r=n.x-e.x,c=n.y-e.y;if(r===0&&c===0)return{x:0,y:0};let a=1/Math.sqrt(r*r+c*c);return{x:c*a,y:-r*a}}static getLowestPathInfo(e){let n=-1,r=!1,c={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let a=0;a<e.length;++a){let s=Number.MAX_VALUE;for(let o of e[a])if(!(o.y<c.y||o.y===c.y&&o.x>=c.x)){if(s===Number.MAX_VALUE){if(s=l0.area(e[a]),s===0)break;r=s<0}n=a,c.x=o.x,c.y=o.y}}return{idx:n,isNegArea:r}}static translatePoint(e,n,r){return{x:e.x+n,y:e.y+r,z:e.z}}static reflectPoint(e,n){return{x:n.x+(n.x-e.x),y:n.y+(n.y-e.y),z:e.z}}static almostZero(e,n=.001){return Math.abs(e)<n}static hypotenuse(e,n){return Math.sqrt(e*e+n*n)}static normalizeVector(e){let n=l0.hypotenuse(e.x,e.y);if(l0.almostZero(n))return{x:0,y:0};let r=1/n;return{x:e.x*r,y:e.y*r}}static getAvgUnitVector(e,n){return l0.normalizeVector({x:e.x+n.x,y:e.y+n.y})}static intersectPoint(e,n,r,c){if(R1.isAlmostZero(e.x-n.x)){if(R1.isAlmostZero(r.x-c.x))return{x:0,y:0};let a=(c.y-r.y)/(c.x-r.x),s=r.y-a*r.x;return{x:e.x,y:a*e.x+s}}if(R1.isAlmostZero(r.x-c.x)){let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x;return{x:r.x,y:a*r.x+s}}else{let a=(n.y-e.y)/(n.x-e.x),s=e.y-a*e.x,o=(c.y-r.y)/(c.x-r.x),i=r.y-o*r.x;if(R1.isAlmostZero(a-o))return{x:0,y:0};let l=(i-s)/(a-o);return{x:l,y:a*l+s}}}getPerpendic(e,n){return{x:Math.round(e.x+n.x*this.groupDelta),y:Math.round(e.y+n.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,n){return{x:e.x+n.x*this.groupDelta,y:e.y+n.y*this.groupDelta,z:e.z||0}}doBevel(e,n,r){let c,a,s=e[n].z||0;if(n===r){let o=Math.abs(this.groupDelta);c={x:Math.round(e[n].x-o*this.normals[n].x),y:Math.round(e[n].y-o*this.normals[n].y),z:s},a={x:Math.round(e[n].x+o*this.normals[n].x),y:Math.round(e[n].y+o*this.normals[n].y),z:s}}else c={x:Math.round(e[n].x+this.groupDelta*this.normals[r].x),y:Math.round(e[n].y+this.groupDelta*this.normals[r].y),z:s},a={x:Math.round(e[n].x+this.groupDelta*this.normals[n].x),y:Math.round(e[n].y+this.groupDelta*this.normals[n].y),z:s};this.pathOut.push(c),this.pathOut.push(a)}doSquare(e,n,r){let c;n===r?c={x:this.normals[n].y,y:-this.normals[n].x}:c=l0.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),s={x:e[n].x,y:e[n].y,z:e[n].z||0};s=l0.translatePoint(s,a*c.x,a*c.y);let o=l0.translatePoint(s,this.groupDelta*c.y,this.groupDelta*-c.x),i=l0.translatePoint(s,this.groupDelta*-c.y,this.groupDelta*c.x),l=this.getPerpendicD(e[r],this.normals[r]);if(n===r){let h={x:l.x+c.x*this.groupDelta,y:l.y+c.y*this.groupDelta},u=l0.intersectPoint(o,i,l,h);u.z=s.z,this.pathOut.push(S2.fromPointD(l0.reflectPoint(u,s))),this.pathOut.push(S2.fromPointD(u))}else{let h=this.getPerpendicD(e[n],this.normals[r]),u=l0.intersectPoint(o,i,l,h);u.z=s.z,this.pathOut.push(S2.fromPointD(u)),this.pathOut.push(S2.fromPointD(l0.reflectPoint(u,s)))}}doMiter(e,n,r,c){let a=this.groupDelta/(c+1);this.pathOut.push({x:Math.round(e[n].x+(this.normals[r].x+this.normals[n].x)*a),y:Math.round(e[n].y+(this.normals[r].y+this.normals[n].y)*a),z:e[n].z||0})}doRound(e,n,r,c){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*l0.arc_const,u=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/u),this.stepCos=Math.cos(2*Math.PI/u),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=u/(2*Math.PI)}let a=e[n],s=a.z||0,o={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&he.negate(o),this.pathOut.push({x:Math.round(a.x+o.x),y:Math.round(a.y+o.y),z:s});let i=Math.ceil(this.stepsPerRad*Math.abs(c));for(let l=1;l<i;l++)o={x:o.x*this.stepCos-this.stepSin*o.y,y:o.x*this.stepSin+o.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+o.x),y:Math.round(a.y+o.y),z:s});this.pathOut.push(this.getPerpendic(e[n],this.normals[n]))}buildNormals(e){let n=e.length;if(this.normals.length=0,n!==0){for(let r=0;r<n-1;r++)this.normals.push(l0.getUnitNormal(e[r],e[r+1]));this.normals.push(l0.getUnitNormal(e[n-1],e[0]))}}offsetPoint(e,n,r,c){if(S2.equals(n[r],n[c]))return;let a=R1.crossProductD(this.normals[r],this.normals[c]),s=R1.dotProductD(this.normals[r],this.normals[c]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,c),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<l0.Tolerance){this.pathOut.push(n[r]);return}if(s>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[c])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(s>.999&&this.joinType!==_0.Round)this.doMiter(n,r,c,s);else switch(this.joinType){case _0.Miter:s>this.mitLimSqr-1?this.doMiter(n,r,c,s):this.doSquare(n,r,c);break;case _0.Round:this.doRound(n,r,c,Math.atan2(a,s));break;case _0.Bevel:this.doBevel(n,r,c);break;default:this.doSquare(n,r,c);break}}offsetPolygon(e,n){this.pathOut=[];let r=n.length,c=r-1;for(let a=0;a<r;a++)this.offsetPoint(e,n,a,c),c=a;this.solution.push(this.pathOut)}offsetOpenJoined(e,n){this.offsetPolygon(e,n);let r=[...n].reverse();this.buildNormals(r),this.offsetPolygon(e,r)}offsetOpenPath(e,n){this.pathOut=[];let r=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<l0.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case h0.Butt:this.doBevel(n,0,0);break;case h0.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let c=1,a=0;c<r;c++)this.offsetPoint(e,n,c,a),a=c;for(let c=r;c>0;c--)this.normals[c]={x:-this.normals[c-1].x,y:-this.normals[c-1].y};if(this.normals[0]=this.normals[r],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,r)),Math.abs(this.groupDelta)<l0.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case h0.Butt:this.doBevel(n,r,r);break;case h0.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let c=r-1,a=r;c>0;c--)this.offsetPoint(e,n,c,a),a=c;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===h0.Polygon?(e.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=e.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===_0.Round||e.endType===h0.Round){let r=this.arcTolerance>.01?this.arcTolerance:n*l0.arc_const,c=Math.PI/Math.acos(1-r/n);this.stepSin=Math.sin(2*Math.PI/c),this.stepCos=Math.cos(2*Math.PI/c),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=c/(2*Math.PI)}for(let r of e.inPaths){this.pathOut=[];let c=r.length;if(c===1){let a=r[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(r,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=a.z||0;if(e.endType===h0.Round){let o=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=l0.ellipse(a,Math.abs(this.groupDelta),Math.abs(this.groupDelta),o),s!==0)for(let i=0;i<this.pathOut.length;i++)this.pathOut[i].z=s}else{let o=Math.ceil(Math.abs(this.groupDelta)),i={left:a.x-o,top:a.y-o,right:a.x+o,bottom:a.y+o};this.pathOut=[{x:i.left,y:i.top,z:s},{x:i.right,y:i.top,z:s},{x:i.right,y:i.bottom,z:s},{x:i.left,y:i.bottom,z:s}]}this.solution.push(this.pathOut);continue}switch(c===2&&e.endType===h0.Joined&&(this.endType=e.joinType===_0.Round?h0.Round:h0.Square),this.buildNormals(r),this.endType){case h0.Polygon:this.offsetPolygon(e,r);break;case h0.Joined:this.offsetOpenJoined(e,r);break;default:this.offsetOpenPath(e,r);break}}}static stripDuplicates(e,n){let r=e.length,c=[];if(r===0)return c;let a=e[0];c.push(a);for(let s=1;s<r;s++)S2.equals(a,e[s])||(a=e[s],c.push(a));return n&&S2.equals(a,c[0])&&c.pop(),c}static area(e){return R1.area(e)}static sqr(e){return e*e}static ellipse(e,n,r=0,c=0){if(n<=0)return[];r<=0&&(r=n),c<=2&&(c=Math.ceil(Math.PI*Math.sqrt((n+r)/2)));let a=Math.sin(2*Math.PI/c),s=Math.cos(2*Math.PI/c),o=s,i=a,l=[{x:Math.round(e.x+n),y:e.y}];for(let h=1;h<c;++h){l.push({x:Math.round(e.x+n*o),y:Math.round(e.y+r*i)});let u=o*s-i*a;i=i*s+o*a,o=u}return l}};G(l0,"Tolerance",1e-12),G(l0,"arc_const",.002);var m3=l0;var $h=BigInt(2);function $4(t,e,n){return typeof e=="number"?O4(r0.Union,t,null,e):O4(r0.Union,t,e,n)}function O4(t,e,n,r){let c=[];if(e===null)return c;let a=new A2;return a.addPaths(e,$0.Subject),n!==null&&a.addPaths(n,$0.Clip),a.execute(t,r,c),c}function ge(t,e,n,r,c=2,a=0){let s=new m3(c,a);s.addPaths(t,n,r);let o=[];return s.execute(e,o),o}var m2=1e4,R4=[1,0,0,1,0,0];function T0(){return{layers:new Map,parts:[]}}function L0(t,e="cut"){return{layers:new Map([[e,{regions:t,lines:[]}]]),parts:[]}}function L2(t,e="cut"){return{layers:new Map([[e,{regions:[],lines:t}]]),parts:[]}}function W6(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 X6=t=>t.map(e=>e.map(([n,r])=>({x:Math.round(n*m2),y:Math.round(r*m2)})));function Ir(t){let e=(r,c,a)=>(c.x-r.x)*(a.y-c.y)-(c.y-r.y)*(a.x-c.x)===0,n=[];for(let r of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],r);)n.pop();let c=n[n.length-1];(!c||c.x!==r.x||c.y!==r.y)&&n.push(r)}for(let r=!0;r&&n.length>=3;){let c=n.length;r=!0,n[c-1].x===n[0].x&&n[c-1].y===n[0].y||e(n[c-2],n[c-1],n[0])?n.pop():e(n[c-1],n[0],n[1])?n.shift():r=!1}return n}var S5=t=>X6(t).map(Ir),L5=t=>t.filter(e=>e.length>=2).map(e=>e.map(n=>[n.x/m2,n.y/m2]));function s1(t,e="nonzero"){if(!t.length)return[];let n=e==="evenodd"?U1.EvenOdd:U1.NonZero;return L5($4(S5(t),n)).filter(r=>r.length>=3)}function F4(t,e,n){if(!e.length)return[];let r=new A2;r.addSubject(S5(e)),n.length&&r.addClip(S5(n));let c=[];return r.execute(t,U1.NonZero,c),L5(c).filter(a=>a.length>=3)}var g0=(t,e)=>e.length?F4(r0.Difference,t,e):s1(t),K1=(t,e)=>F4(r0.Intersection,t,e),p3=(t,e)=>F4(r0.Xor,t,e);function Y0(t,e,n){if(!t.length)return[];if(!e.length)return n==="outside"?t:[];let r=[];for(let m of e)for(let g=0;g<m.length;g++){let v=m[g],b=m[(g+1)%m.length];(v[0]!==b[0]||v[1]!==b[1])&&r.push([v,b])}if(!r.length)return n==="outside"?t:[];let c=w0(e),a=Math.max(c[2]-c[0],c[3]-c[1],1e-6)/Math.max(1,Math.sqrt(r.length)),s=m=>Math.floor(m/a),o=new Map,i=new Map,l=(m,g,v)=>{let b=m.get(g);b?b[b.length-1]!==v&&b.push(v):m.set(g,[v])};r.forEach(([m,g],v)=>{let b=Math.max(1,Math.ceil(Math.hypot(g[0]-m[0],g[1]-m[1])/a*2));for(let y=0;y<=b;y++){let x=m[0]+(g[0]-m[0])*y/b,w=m[1]+(g[1]-m[1])*y/b;for(let M of[-1,0,1])for(let k of[-1,0,1])l(o,`${s(x)+M},${s(w)+k}`,v)}for(let y=s(Math.min(m[1],g[1]));y<=s(Math.max(m[1],g[1]));y++)l(i,y,v)});let h=(m,g)=>{let v=new Set,b=0,y=1;for(let k of[0,1]){let z=g[k]-m[k],A=c[k]-a,S=c[k+2]+a;if(z===0){if(m[k]<A||m[k]>S)return v;continue}let C=(A-m[k])/z,I=(S-m[k])/z;b=Math.max(b,Math.min(C,I)),y=Math.min(y,Math.max(C,I))}if(!(b<=y))return v;let x=[m[0]+(g[0]-m[0])*b,m[1]+(g[1]-m[1])*b],w=[m[0]+(g[0]-m[0])*y,m[1]+(g[1]-m[1])*y],M=Math.max(1,Math.ceil(Math.hypot(w[0]-x[0],w[1]-x[1])/a*2));for(let k=0;k<=M;k++){let z=x[0]+(w[0]-x[0])*k/M,A=x[1]+(w[1]-x[1])*k/M;for(let S of o.get(`${s(z)},${s(A)}`)??[])v.add(S)}return v},u=.5/m2,f=m=>{for(let v of o.get(`${s(m[0])},${s(m[1])}`)??[]){let[b,y]=r[v],x=y[0]-b[0],w=y[1]-b[1],M=Math.max(0,Math.min(1,((m[0]-b[0])*x+(m[1]-b[1])*w)/(x*x+w*w)));if(Math.hypot(m[0]-b[0]-M*x,m[1]-b[1]-M*w)<=u)return}let g=0;for(let v of i.get(s(m[1]))??[]){let[b,y]=r[v],x=(y[0]-b[0])*(m[1]-b[1])-(m[0]-b[0])*(y[1]-b[1]);b[1]<=m[1]?y[1]>m[1]&&x>0&&g++:y[1]<=m[1]&&x<0&&g--}return g!==0},d=m=>Math.round(m*m2)/m2,p=[];for(let m of t){let g=null,v=()=>{g&&g.length>=2&&p.push(g),g=null};for(let b=1;b<m.length;b++){let y=m[b-1],x=m[b],w=x[0]-y[0],M=x[1]-y[1];if(!w&&!M)continue;let k=[0,1];for(let A of h(y,x)){let[S,C]=r[A],I=C[0]-S[0],L=C[1]-S[1],T=w*L-M*I;if(Math.abs(T)>1e-15){let q=((S[0]-y[0])*L-(S[1]-y[1])*I)/T,P=((S[0]-y[0])*M-(S[1]-y[1])*w)/T;q>0&&q<1&&P>=0&&P<=1&&k.push(q)}else{let q=w*w+M*M;for(let P of[S,C]){let F=((P[0]-y[0])*w+(P[1]-y[1])*M)/q,j=Math.abs((P[0]-y[0])*M-(P[1]-y[1])*w)/Math.sqrt(q);F>0&&F<1&&j<=u&&k.push(F)}}}k.sort((A,S)=>A-S);let z=Math.hypot(w,M);for(let A=1;A<k.length;A++){if((k[A]-k[A-1])*z<1e-9||k[A]-k[A-1]<1e-300)continue;let S=[d(y[0]+w*k[A-1]),d(y[1]+M*k[A-1])],C=[d(y[0]+w*k[A]),d(y[1]+M*k[A])],I=(k[A-1]+k[A])/2,L=f([y[0]+w*I,y[1]+M*I]);if(L!==void 0&&L===(n==="inside")){let T=g?g[g.length-1]:void 0;g&&T&&T[0]===S[0]&&T[1]===S[1]?(C[0]!==T[0]||C[1]!==T[1])&&g.push(C):(v(),g=[S,C])}else v()}}v()}return p}function c0(t,e,n="round",r=.01){if(!t.length)return[];if(e===0)return s1(t);let c=n==="round"?_0.Round:n==="square"?_0.Square:_0.Miter,a=ge(S5(s1(t)),e*m2,c,h0.Polygon,2,r*m2);return L5(a).filter(s=>s.length>=3)}function g3(t,e){if(!t.length||e<=0)return[];let n=ge(X6(t),e/2*m2,_0.Round,h0.Round,2,.01*m2);return L5(n)}function R0(t){if(!t.length)return[];let e=new z5,n=new A2;n.addSubject(S5(t)),n.execute(r0.Union,U1.NonZero,e);let r=[],c=a=>{for(let s=0;s<a.count;s++){let o=a.child(s),i=[o.poly];for(let l=0;l<o.count;l++){let h=o.child(l);i.push(h.poly),c(h)}r.push(L5(i))}};return c(e),r}function b1(t){let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]+t[n][0])*(t[r][1]-t[n][1]);return-e/2}function Z6(t){let e=0,n=0,r=0;for(let c of t){if(c.length<3)continue;let[a,s]=c[0];for(let o=0,i=c.length-1;o<c.length;i=o++){let l=c[i][0]-a,h=c[i][1]-s,u=c[o][0]-a,f=c[o][1]-s,d=l*f-u*h;e+=d/2,n+=(l+u)*d/6+a*d/2,r+=(h+f)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[n/e,r/e]}}function D3(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 j6(t,e){let n=e[0]*e[3]-e[1]*e[2]<0,r=new Map;for(let[c,a]of t)r.set(c,{regions:a.regions.map(s=>{let o=s.map(i=>A5(e,i));return n?o.reverse():o}),lines:a.lines.map(s=>s.map(o=>A5(e,o)))});return r}function v3(t,e){return{layers:j6(t.layers,e),parts:t.parts.map(n=>({...n,layers:j6(n.layers,e)}))}}function C2(t){let e=T0();for(let n of t){for(let[r,c]of n.layers){let a=e.layers.get(r)??{regions:[],lines:[]};for(let s of c.regions)a.regions.push(s);for(let s of c.lines)a.lines.push(s);e.layers.set(r,a)}for(let r of n.parts)e.parts.push(r)}return e}var r2="\0hidden";function G6(t,e){let n={regions:[],lines:[]};for(let[a,s]of t)if(a!==r2){for(let o of s.regions)n.regions.push(o);for(let o of s.lines)n.lines.push(o)}let r=new Map([[e,n]]),c=t.get(r2);return c&&e!==r2&&r.set(r2,c),r}function C5(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:G6(t.layers,e),parts:t.parts.map(n=>({...n,layers:G6(n.layers,e)}))}}function w0(t){let e=1/0,n=1/0,r=-1/0,c=-1/0;for(let a of t)for(let[s,o]of a)s<e&&(e=s),o<n&&(n=o),s>r&&(r=s),o>c&&(c=o);return e===1/0?null:[e,n,r,c]}function J0(t,e){let n=[];for(let[r,c]of t)if(!e?.(r))for(let a of[...c.regions,...c.lines])n.push(a);return w0(n)}function ve(t){let e=[...t].sort((a,s)=>a[0]-s[0]||a[1]-s[1]);if(e.length<3)return e;let n=(a,s,o)=>(s[0]-a[0])*(o[1]-a[1])-(s[1]-a[1])*(o[0]-a[0]),r=[];for(let a of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],a)<=0;)r.pop();r.push(a)}let c=[];for(let a=e.length-1;a>=0;a--){let s=e[a];for(;c.length>=2&&n(c[c.length-2],c[c.length-1],s)<=0;)c.pop();c.push(s)}return c.pop(),r.pop(),r.concat(c)}function Y6(t,e,n,r){return t<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/n,t*2*Math.PI/r)),5)}function q3(t,e,n){let r=[];for(let c=0;c<n;c++){let a=2*Math.PI*c/n;r.push([t*Math.cos(a),e*Math.sin(a)])}return r}function J6(t,e,n,r){if(n=Math.min(n,t/2,e/2),n<=0)return[[0,0],[t,0],[t,e],[0,e]];let c=Math.max(1,Math.ceil(r(n)/4)),a=[],s=[[t-n,n,-90],[t-n,e-n,0],[n,e-n,90],[n,n,180]];for(let[o,i,l]of s)for(let h=0;h<=c;h++){let u=(l+90*h/c)*Math.PI/180;a.push([o+n*Math.cos(u),i+n*Math.sin(u)])}return a}function D4(t,e){let n=s1(t);for(let r=0;r<100;r++){let c=R0(n);if(c.length<=1)return n;let a=o=>o.reduce((i,l)=>i+b1(l),0);c.sort((o,i)=>a(i)-a(o));let s=[];for(let o=1;o<c.length;o++){let i=1/0,l=[0,0],h=[0,0];for(let[y,x]of c[o][0])for(let w=0;w<c.length;w++)if(w!==o)for(let M of c[w])for(let k=0,z=M.length-1;k<M.length;z=k++){let[A,S]=M[z],[C,I]=M[k],L=C-A,T=I-S,q=L*L+T*T,P=q?Math.max(0,Math.min(1,((y-A)*L+(x-S)*T)/q)):0,F=A+P*L,j=S+P*T,_=Math.hypot(y-F,x-j);_<i&&([i,l,h]=[_,[y,x],[F,j]])}if(!Number.isFinite(i))continue;let u=h[0]-l[0],f=h[1]-l[1],d=Math.hypot(u,f);d<1e-9?[u,f]=[0,1]:[u,f]=[u/d,f/d];let[p,m]=[-f*(e/2),u*(e/2)],g=[l[0]-u*(e/2),l[1]-f*(e/2)],v=[h[0]+u*(e/2),h[1]+f*(e/2)],b=[[g[0]-p,g[1]-m],[v[0]-p,v[1]-m],[v[0]+p,v[1]+m],[g[0]+p,g[1]+m]];s.push(b1(b)<0?b.reverse():b)}if(!s.length)return n;n=s1([...n,...s])}return n}function Vr(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function K6(t){let{spacing:e,step:n,box:r}=t,c=e/2,a=e,s=new Map,o=[],i=[],l=[],h=[],u=[],f=(I,L)=>Math.floor((I-r[0])/a)*1000003+Math.floor((L-r[1])/a),d=(I,L,T)=>{let q=f(I[0],I[1]),P=o.length;o.push(I[0]),i.push(I[1]),l.push(L),h.push(T);let F=s.get(q);F?F.push(P):s.set(q,[P])},p=Math.ceil(2*e/n)+2,m=(I,L,T=-1,q=0)=>{let P=Math.floor((I[0]-r[0])/a),F=Math.floor((I[1]-r[1])/a);for(let j=P-1;j<=P+1;j++)for(let _=F-1;_<=F+1;_++){let Q=s.get(j*1000003+_);if(Q)for(let H of Q){let B=l[H];if(!(!u[B]&&B!==T)&&!(B===T&&Math.abs(h[H]-q)<p)&&Math.hypot(o[H]-I[0],i[H]-I[1])<L)return!1}}return!0},g=[],v=0,b=Math.ceil(4*(r[2]-r[0]+r[3]-r[1]+e)/n+2*p),y=(I,L)=>{let T=t.dir(I);if(!T)return null;let q=[I[0]+L*T[0]*n/2,I[1]+L*T[1]*n/2],P=t.dir(q)??T;return P[0]*T[0]+P[1]*T[1]<0?null:[I[0]+L*P[0]*n,I[1]+L*P[1]*n]},x=I=>{let L=g.length;u[L]=!1,d(I,L,0);let T=[[],[]];for(let[F,j]of[[0,1],[1,-1]]){let _=I;for(let Q=1;Q<=b;Q++){let H=y(_,j);if(!H)break;let B=j*Q;if(!t.inside(H)){T[F].push(H);break}if(!m(H,c,L,B))break;if(T[F].push(H),d(H,L,B),++v>t.maxPoints)throw new Error(`the lines have more than ${t.maxPoints} points: use a larger spacing or step`);t.tick(),_=H}}let q=[...T[1].reverse(),I,...T[0]],P=0;for(let F=1;F<q.length;F++)P+=Math.hypot(q[F][0]-q[F-1][0],q[F][1]-q[F-1][1]);return g.push(q),q.length<2||P<t.minLength?null:(u[L]=!0,q)},w=Vr(t.seed),M=[];for(let I=r[0]+e/2;I<r[2];I+=e)for(let L=r[1]+e/2;L<r[3];L+=e)M.push([I+(w()-.5)*e,L+(w()-.5)*e]);for(let I=M.length-1;I>0;I--){let L=Math.floor(w()*(I+1));[M[I],M[L]]=[M[L],M[I]]}let k=[],z=[],A=Math.max(1,Math.round(e/(2*n))),S=I=>{if(!t.inside(I)||!m(I,e)||!t.dir(I))return;let L=x(I);L&&(k.push(L),z.push(L))},C=0;for(;;){for(;z.length;){let I=z.shift();for(let L=0;L<I.length;L+=A){let T=I[Math.max(0,L-1)],q=I[Math.min(I.length-1,L+1)],P=Math.hypot(q[0]-T[0],q[1]-T[1]);if(P===0)continue;let F=-(q[1]-T[1])/P,j=(q[0]-T[0])/P;for(let _ of[1,-1])S([I[L][0]+_*F*e,I[L][1]+_*j*e])}}if(C>=M.length)break;S(M[C++])}return k}function Q6(t,e,n,r,c,a,s){let o=(g,v)=>t[v*e+g],i=(g,v)=>(v*e+g)*2,l=(g,v)=>(v*e+g)*2+1,h=g=>{let v=g>>1,b=v%e,y=(v-b)/e,x=o(b,y),w=g&1?o(b,y+1):o(b+1,y),M=x===w?.5:(s-x)/(w-x);return g&1?[r+b*a,c+(y+M)*a]:[r+(b+M)*a,c+y*a]},u=new Map,f=(g,v)=>{for(let[b,y]of[[g,v],[v,g]]){let x=u.get(b);x?x.push(y):u.set(b,[y])}};for(let g=0;g+1<n;g++)for(let v=0;v+1<e;v++){let b=o(v,g),y=o(v+1,g),x=o(v+1,g+1),w=o(v,g+1);if(Number.isNaN(b+y+x+w))continue;let M=(b>=s?1:0)|(y>=s?2:0)|(x>=s?4:0)|(w>=s?8:0);if(M===0||M===15)continue;let k=i(v,g),z=l(v+1,g),A=i(v,g+1),S=l(v,g);if(M===5||M===10){let I=(b+y+x+w)/4>=s;M===5===I?(f(k,z),f(S,A)):(f(S,k),f(z,A));continue}let C=[];(M&1)!==(M&2)>>1&&C.push(k),(M&2)>>1!==(M&4)>>2&&C.push(z),(M&4)>>2!==(M&8)>>3&&C.push(A),(M&8)>>3!==(M&1)&&C.push(S),C.length===2&&f(C[0],C[1])}let d=new Set,p=g=>{let v=[h(g)];d.add(g);let b=g;for(;;){let y=(u.get(b)??[]).find(x=>!d.has(x));if(y===void 0)return(u.get(b)??[]).includes(g)&&v.length>2&&v.push(v[0]),v;d.add(y),v.push(h(y)),b=y}},m=[];for(let[g,v]of u)v.length===1&&!d.has(g)&&m.push(p(g));for(let g of u.keys())d.has(g)||m.push(p(g));return m.map(g=>g.filter((v,b)=>b===0||v[0]!==g[b-1][0]||v[1]!==g[b-1][1])).filter(g=>g.length>=2&&!(g.length===2&&g[0][0]===g[1][0]&&g[0][1]===g[1][1]))}function en(t,e=.001){let n=t.filter(l=>l.length>=2).map(l=>[...l]);if(n.length<2)return n;let r=l=>`${Math.round(l[0]/e)},${Math.round(l[1]/e)}`,c=new Map,a=(l,h)=>{let u=r(l),f=c.get(u);f?f.push(h):c.set(u,[h])};n.forEach((l,h)=>{a(l[0],h),a(l[l.length-1],h)});let s=new Array(n.length).fill(!1),o=l=>r(l[0])===r(l[l.length-1]),i=[];for(let l=0;l<n.length;l++){if(s[l])continue;s[l]=!0;let h=n[l];if(!o(h))for(let u=0;u<2;u++){for(;;){let f=h[h.length-1],d=(c.get(r(f))??[]).find(g=>!s[g]);if(d===void 0)break;s[d]=!0;let p=n[d],m=r(p[0])===r(f)?p:[...p].reverse();if(h=h.concat(m.slice(1)),o(h))break}if(o(h))break;h=h.reverse()}i.push(h)}return Hr(i)}function Hr(t){let e=t.length;if(e<2)return t;let n=1/0,r=1/0,c=-1/0,a=-1/0;for(let m of t)for(let g of[m[0],m[m.length-1]])n=Math.min(n,g[0]),r=Math.min(r,g[1]),c=Math.max(c,g[0]),a=Math.max(a,g[1]);let s=Math.max((c-n+a-r)/Math.sqrt(e),1e-6),o=m=>Math.floor((m-n)/s),i=m=>Math.floor((m-r)/s),l=o(c)+1,h=i(a)+1,u=new Map;t.forEach((m,g)=>{for(let v of[m[0],m[m.length-1]]){let b=i(v[1])*l+o(v[0]),y=u.get(b);y?y[y.length-1]!==g&&y.push(g):u.set(b,[g])}});let f=new Array(e).fill(!1),d=[],p=[0,0];for(let m=0;m<e;m++){let g=-1,v=1/0,b=!1,y=Math.min(Math.max(o(p[0]),0),l-1),x=Math.min(Math.max(i(p[1]),0),h-1);for(let M=0;M<=Math.max(l,h);M++){for(let k=y-M;k<=y+M;k++)for(let z=x-M;z<=x+M;z++)if(Math.max(Math.abs(k-y),Math.abs(z-x))===M&&!(k<0||z<0||k>=l||z>=h))for(let A of u.get(z*l+k)??[]){if(f[A])continue;let S=t[A],C=Math.hypot(S[0][0]-p[0],S[0][1]-p[1]),I=Math.hypot(S[S.length-1][0]-p[0],S[S.length-1][1]-p[1]);C<v&&([g,v,b]=[A,C,!1]),I<v&&([g,v,b]=[A,I,!0])}if(g>=0&&v<=M*s)break}if(g<0){for(let M=0;M<e;M++)if(!f[M]){g=M;break}}f[g]=!0;let w=b?[...t[g]].reverse():t[g];d.push(w),p=w[w.length-1]}return d}function tn(t){let e=[],n=1/0,r=-1/0;for(let o of t)for(let i=0,l=o.length-1;i<o.length;l=i++)e.push([o[l][0],o[l][1],o[i][0],o[i][1]]),n=Math.min(n,o[i][1]),r=Math.max(r,o[i][1]);if(!e.length)return()=>!1;let c=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),a=(r-n)/c||1,s=Array.from({length:c},()=>[]);return e.forEach(([,o,,i],l)=>{let h=Math.max(0,Math.min(c-1,Math.floor((Math.min(o,i)-n)/a))),u=Math.max(0,Math.min(c-1,Math.floor((Math.max(o,i)-n)/a)));for(let f=h;f<=u;f++)s[f].push(l)}),([o,i])=>{if(i<n||i>r)return!1;let l=0;for(let h of s[Math.max(0,Math.min(c-1,Math.floor((i-n)/a)))]){let[u,f,d,p]=e[h];f<=i?p>i&&(d-u)*(i-f)-(o-u)*(p-f)>0&&l++:p<=i&&(d-u)*(i-f)-(o-u)*(p-f)<0&&l--}return l!==0}}var nn=Math.PI/180;function D1(t,e){let n=new Array(16).fill(0);for(let r=0;r<4;r++)for(let c=0;c<4;c++)for(let a=0;a<4;a++)n[r*4+c]+=t[r*4+a]*e[a*4+c];return n}function ye(t,e){let n=Math.cos(e*nn),r=Math.sin(e*nn);return t===0?[1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1]:t===1?[n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1]:[n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1]}var N4=t=>Math.abs(t)<1e-12?0:t;function F0(t){if(t.matrix)return t.matrix.map(N4);let[e,n,r]=t.rotate,c=D1(ye(2,r),D1(ye(1,n),ye(0,e)));return c[3]=t.at[0],c[7]=t.at[1],c[11]=t.at[2],c.map(N4)}function D2(t,e,n,r){return[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]]}function P5(t){let[e,n,r]=[t[3],t[7],t[11]],c=[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]];return[c[0],c[1],c[2],-(c[0]*e+c[1]*n+c[2]*r),c[3],c[4],c[5],-(c[3]*e+c[4]*n+c[5]*r),c[6],c[7],c[8],-(c[6]*e+c[7]*n+c[8]*r),0,0,0,1]}function be(t){let[e,n,r,c]=[1/0,1/0,-1/0,-1/0];for(let a of t)for(let[s,o]of a)e=Math.min(e,s),n=Math.min(n,o),r=Math.max(r,s),c=Math.max(c,o);return[e,n,r,c]}function sn(t){let[e,n,r,c]=be(t.outline),a=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let o of[e,r])for(let i of[n,c])for(let l of[0,t.thickness]){let h=D2(t.matrix,o,i,l);for(let u=0;u<3;u++)a[u]=Math.min(a[u],h[u]),s[u]=Math.max(s[u],h[u])}return[a,s]}function on(t,e,n=10){let r=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];for(let[h,u]of t.map(sn))for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),c[f]=Math.max(c[f],u[f]);let a=e.map(h=>be(h.outline)),s=a.reduce((h,[u,,f])=>Math.max(h,f-u),c[0]-r[0]),o=0,i=0,l=0;return e.map((h,u)=>{let[f,d,p,m]=a[u];o>0&&o+p-f>s&&(o=0,i+=l+n,l=0);let g=[1,0,0,c[0]+n+o-f,0,1,0,r[1]+i-d,0,0,1,r[2],0,0,0,1];return o+=p-f+n,l=Math.max(l,m-d),{...h,matrix:g.map(N4)}})}var Or=(t,e,n)=>[0,1,2].every(r=>t[0][r]<e[1][r]-n&&e[0][r]<t[1][r]-n),N3=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],xe=(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]],q4=(t,e,n=1)=>[t[0]+e[0]*n,t[1]+e[1]*n,t[2]+e[2]*n],B3=t=>[t[2],t[6],t[10]],rn=t=>[t[3],t[7],t[11]],$r=(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 U3(t,e,n){let r=n[0]*n[0]+n[1]*n[1],c=[];for(let a of t)for(let s=0,o=a.length-1;s<a.length;o=s++){let i=a[o],l=a[s],h=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]),u=n[0]*(l[1]-e[1])-n[1]*(l[0]-e[0]);if(h>0==u>0)continue;let f=h/(h-u),d=i[0]+(l[0]-i[0])*f-e[0],p=i[1]+(l[1]-i[1])*f-e[1];c.push((d*n[0]+p*n[1])/r)}return c.sort((a,s)=>a-s)}function U4(t,e,n){let r=0,c=0,a=0,s=0,o=0;for(;s+1<t.length&&o+1<e.length;){let i=Math.max(t[s],e[o]),l=Math.min(t[s+1],e[o+1])-i;l>n&&(r+=l,l>a&&(a=l,c=i+l/2)),t[s+1]<e[o+1]?s+=2:o+=2}return{total:r,mid:c,run:a}}function Rr(t,e){let[n,r,c]=D2(P5(t.matrix),e[0],e[1],e[2]);if(c<0||c>t.thickness)return!1;let a=!1;for(let s of t.outline)for(let o=0,i=s.length-1;o<s.length;i=o++){let[l,h]=s[i],[u,f]=s[o];h>r!=f>r&&n<l+(u-l)*(r-h)/(f-h)&&(a=!a)}return a}var Me=class{constructor(e=[]){this.parts=e;this.seen=[]}see(e,n){e>0&&this.seen.push([n(),e])}get at(){let e=0,n=[0,0,0];for(let[a,s]of this.seen){for(let o=0;o<3;o++)n[o]+=a[o]*s;e+=s}for(let a=0;a<3;a++)n[a]/=e;if(this.parts.length&&this.parts.every(a=>Rr(a,n)))return n;let r=this.seen[0][0],c=1/0;for(let[a]of this.seen){let s=Math.hypot(a[0]-n[0],a[1]-n[1],a[2]-n[2]);s<c&&([r,c]=[a,s])}return r}};function we(t,e,n,r){let c=t+n,a=e-n;if(a<=c)return{at:[],size:0};let s=Math.max(4,Math.ceil((a-c)/r));return{at:Array.from({length:s},(o,i)=>c+(a-c)*(i+.5)/s),size:(a-c)/s}}function cn(t,e,n){let r=D2(t,e[0],e[1],e[2]),c=$r(t,n);return[[r[0],r[1]],[c[0],c[1]]]}function ln(t,e,n,r,c,a,s,o=!1){let i=B3(t.matrix),l=B3(e.matrix),h=xe(i,l),u=Math.hypot(...h),f=[h[0]/u,h[1]/u,h[2]/u],d=xe(f,i),p=N3(l,d),m=rn(t.matrix),g=N3(l,rn(e.matrix)),v=1/0,b=-1/0;for(let z of e.outline)for(let[A,S]of z)for(let C of[0,e.thickness]){let I=D2(e.matrix,A,S,C),L=N3(i,[I[0]-m[0],I[1]-m[1],I[2]-m[2]]);L<v&&(v=L),L>b&&(b=L)}let y=we(Math.max(0,v),Math.min(t.thickness,b),c,a),x=1/0,w=-1/0;for(let z of t.outline)for(let[A,S]of z){let C=D2(t.matrix,A,S,0),I=N3(d,[C[0]-m[0],C[1]-m[1],C[2]-m[2]]);I<x&&(x=I),I>w&&(w=I)}let M=0,k=new Me([t,e]);for(let z of y.at){let A=q4(m,i,z),S=(g-N3(l,A))/p,C=(g+e.thickness-N3(l,A))/p,I=we(Math.max(x,Math.min(S,C)),Math.min(w,Math.max(S,C)),c,a);for(let L of I.at){let T=q4(A,d,L),[q,P]=cn(n,T,f),[F,j]=cn(r,T,f),_=U4(U3(t.outline,q,P),U3(e.outline,F,j),c);if(M+=_.total*y.size*I.size,k.see(_.run,()=>q4(T,f,_.mid)),M>s&&!o)return k.at}}return M>s?k.at:void 0}function hn(t,e,n,r,c,a,s=!1){let o=[0,1,2,3].flatMap(S=>[0,1,2,3].map(C=>{let I=0;for(let L=0;L<4;L++)I+=n[S*4+L]*e.matrix[L*4+C];return I})),i=o[11],l=o[11]+o[10]*e.thickness,h=Math.min(t.thickness,Math.max(i,l))-Math.max(0,Math.min(i,l));if(h<=r)return;let u=Math.max(0,Math.min(i,l))+h/2,f=new Me([t,e]),d=e.outline.map(S=>S.map(([C,I])=>[o[0]*C+o[1]*I+o[3],o[4]*C+o[5]*I+o[7]])),[p,m,g,v]=be(t.outline),[b,y,x,w]=be(d),M=we(Math.max(m,y),Math.min(v,w),r,c),k=0;for(let S of M.at){let C=U4(U3(t.outline,[0,S],[1,0]),U3(d,[0,S],[1,0]),r);if(k+=C.total*M.size*h,f.see(C.run,()=>D2(t.matrix,C.mid,S,u)),k>a&&!s)return f.at}let z=we(Math.max(p,b),Math.min(g,x),r,c),A=0;for(let S of z.at){let C=U4(U3(t.outline,[S,0],[0,1]),U3(d,[S,0],[0,1]),r);if(A+=C.total*z.size*h,f.see(C.run,()=>D2(t.matrix,S,C.mid,u)),A>a&&!s)return f.at}return k>a||A>a?f.at:void 0}function un(t,e=1/0,n=.05,r=.25,c=.1){let a=t.map(sn),s=t.map(h=>P5(h.matrix)),o=t.map((h,u)=>u).sort((h,u)=>a[h][0][0]-a[u][0][0]),i=[],l=0;for(let h=0;h<o.length;h++)for(let u=h+1;u<o.length;u++){let f=o[h],d=o[u];if(a[d][0][0]>=a[f][1][0]-n)break;if(!Or(a[f],a[d],n))continue;if(++l>e)return{found:i,complete:!1};let[p,m]=f<d?[t[f],t[d]]:[t[d],t[f]],[g,v]=f<d?[s[f],s[d]]:[s[d],s[f]],y=Math.hypot(...xe(B3(p.matrix),B3(m.matrix)))<1e-9?hn(p,m,g,n,r,c):ln(p,m,g,v,n,r,c);y&&i.push([p,m,y])}return{found:i,complete:!0}}function fn(t,e,n=.05,r=.25,c=.1){let a=Math.hypot(...xe(B3(t.matrix),B3(e.matrix)))<1e-9,s=P5(t.matrix);return a?hn(t,e,s,n,r,c,!0):ln(t,e,s,P5(e.matrix),n,r,c,!0)}function j0(t,e,n){return[1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1]}var B4=j0(0,0,0);function v0(t){return P5(t)}function dn(t,e,n=t.angle,r=t.x1){let c=r-t.x0;if(!n||!(c>0))return j0(0,0,0);let a=(t.x1-t.x0)/(t.angle*Math.PI/180),s=e/2+a;return D1(j0(t.x0,0,s),D1(ye(1,-n),j0(-t.x0-c,0,-s)))}function E5(t){return[...t].sort((e,n)=>e.x0-n.x0)}var ke=t=>t.length>0&&t.every(e=>e.mirrored),an=[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Fr=t=>D1(an,D1(t,an));function _4(t){return E5(t).map(e=>e.mirrored?[-e.x1,-e.x0]:[e.x0,e.x1])}function ze(t,e){let n=[j0(0,0,0)];for(let r of E5(t))n.push(D1(n[n.length-1],dn(r,e)));return ke(t)?n.map(Fr):n}function y3(t,e,n){if(ke(t)){let a=y3(t.map(({mirrored:s,...o})=>o),e,[-n[0],n[1],n[2]]);return[-a[0],a[1],a[2]]}let r=E5(t),c=ze(r,e);for(let a=r.length-1;a>=0;a--){let s=r[a];if(n[0]>=s.x1)return D2(c[a+1],...n);if(n[0]>s.x0){let o=(n[0]-s.x0)/(s.x1-s.x0),i=D1(c[a],dn(s,e,s.angle*o,n[0]));return D2(i,...n)}}return n}function mn(t,e){let n=ke(t)?-e:e;return E5(t).filter(r=>(r.x0+r.x1)/2<n).length}function Se(t){if(!t.bends?.length)return[t];let e=E5(t.bends),n=ze(t.bends,t.thickness),r=ke(t.bends),c=1e7,a=[];for(let s=0;s<=e.length;s++){let o=s===0?-c:e[s-1].x1,i=s===e.length?c:e[s].x0;if(!(i>o))continue;let[l,h]=r?[-i,-o]:[o,i],u=[[l,-c],[h,-c],[h,c],[l,c]],f=K1(t.outline,[u]);f.length&&a.push({...t,outline:f,bends:void 0,matrix:D1(t.matrix,n[s])})}return a}var Dr=2e3;function b3(t,e,n=2){if(!e?.length)return R0(t);let r=1e7,c=1/0,a=-1/0;for(let f of t)for(let[d]of f)c=Math.min(c,d),a=Math.max(a,d);let s=_4(e).map(([f,d])=>[Math.max(f,c),Math.min(d,a)]).filter(([f,d])=>d>f),o=s.reduce((f,[d,p])=>f+(p-d),0),i=Math.max(n,o/Dr),l=[];for(let[f,d]of s){let p=Math.max(1,Math.ceil((d-f)/i));for(let m=0;m<=p;m++)l.push(f+(d-f)*m/p)}let h=[-r,...l.sort((f,d)=>f-d),r],u=[];for(let f=0;f<h.length-1;f++){if(!(h[f+1]>h[f]))continue;let d=[[h[f],-r],[h[f+1],-r],[h[f+1],r],[h[f],r]];for(let p of R0(K1(t,[d])))u.push(p)}return u}var Y2=1e6,Ae=.01,J2=t=>b1(t)<0?[...t].reverse():t;function qr(t,e){let n=D1(v0(t.matrix),e.matrix),[r,c]=[n[8],n[9]],a=Math.hypot(r,c);if(a<1e-9)return[];let s=0,o=e.thickness,i=L=>(-n[11]-Math.max(n[10]*s,n[10]*o)+L)/a,l=L=>(t.thickness-n[11]-Math.min(n[10]*s,n[10]*o)-L)/a;if(!(l(Ae)>i(Ae)))return[];let[h,u]=[r/a,c/a],[f,d]=[-u,h],p=(L,T)=>[[h*L-f*Y2,u*L-d*Y2],[h*T-f*Y2,u*T-d*Y2],[h*T+f*Y2,u*T+d*Y2],[h*L+f*Y2,u*L+d*Y2]],m=1/0,g=-1/0;for(let L of e.outline)for(let[T,q]of L)for(let P of[s,o]){let F=n[8]*T+n[9]*q+n[10]*P+n[11];F<m&&(m=F),F>g&&(g=F)}if(Math.min(t.thickness,g)-Math.max(0,m)<Math.min(1,t.thickness/2))return[];let b=((L,T)=>K1(e.outline,[J2(p(L,T))]).filter(q=>Math.abs(b1(q))>1e-6))(i(Ae),l(Ae));if(!b.length)return[];let y=Math.abs(l(0)-i(0))+1,x=L=>{let T=L.map(([F,j])=>[F-h*y,j-u*y]),q=L.map(([F,j])=>[F+h*y,j+u*y]),P=[J2(T),J2(q)];for(let F=0;F<L.length;F++){let j=(F+1)%L.length,_=[T[F],T[j],q[j],q[F]];Math.abs(b1(_))>1e-12&&P.push(J2(_))}return P},w=s1(b.flatMap(x),"nonzero"),M=K1(e.outline,w).filter(L=>Math.abs(b1(L))>1e-6);if(!M.length)return[];let k=L=>([T,q])=>[n[0]*T+n[1]*q+n[2]*L+n[3],n[4]*T+n[5]*q+n[6]*L+n[7]],z=t.thickness,A=(L,T)=>(L-n[11]-n[10]*T)/a,S=[],C=L=>{L.length>=3&&Math.abs(b1(L))>1e-9&&S.push(J2(L))};for(let L of[s,o])for(let T of K1(M,[J2(p(A(0,L),A(z,L)))]))C(T.map(k(L)));for(let L of[0,z])if(Math.abs(n[10])>1e-9){let[T,q]=[A(L,s),A(L,o)].sort((P,F)=>P-F);for(let P of K1(M,[J2(p(T,q))]))C(P.map(([F,j])=>k((L-n[11]-n[8]*F-n[9]*j)/n[10])([F,j])))}else{let T=A(L,0);for(let q of K1(M,[J2(p(T-1e-4,T+1e-4))])){let[P,F]=[1/0,-1/0];for(let[Q,H]of q){let B=f*Q+d*H;P=Math.min(P,B),F=Math.max(F,B)}if(!(F-P>1e-6))continue;let j=[h*T+f*P,u*T+d*P],_=[h*T+f*F,u*T+d*F];C([k(s)(j),k(s)(_),k(o)(_),k(o)(j)])}}let I=(L,T,q)=>n[8]*L+n[9]*T+n[10]*q+n[11];for(let L of M)for(let T=0;T<L.length;T++){let[q,P]=L[T],[F,j]=L[(T+1)%L.length],_=[[0,s],[1,s],[1,o],[0,o]],Q=([H,B])=>I(q+(F-q)*H,P+(j-P)*H,B);for(let[H,B]of[[1,0],[-1,-z]]){let Y=X=>H*Q(X)>=B,e1=[];for(let X=0;X<_.length;X++){let M1=_[X],v1=_[(X+1)%_.length];if(Y(M1)&&e1.push(M1),Y(M1)!==Y(v1)){let p1=H*Q(M1)-B,G1=H*Q(v1)-B,F1=p1/(p1-G1);e1.push([M1[0]+(v1[0]-M1[0])*F1,M1[1]+(v1[1]-M1[1])*F1])}}if(_=e1,!_.length)break}_.length>=3&&C(_.map(([H,B])=>k(B)([q+(F-q)*H,P+(j-P)*H])))}return S.length?s1(S,"nonzero"):[]}function pn(t,e,n){let r=[];for(let a of e)for(let s of qr(t,a))r.push(s);if(!r.length)return[];let c=R0(K1(s1(r),t.outline)).filter(a=>a.reduce((s,o)=>s+b1(o),0)>1e-4);return c.length?c0(c.flat(),n/2,"miter"):[]}var T5=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],gn=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Nr=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],vn=t=>{let e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]},I5={turn:.3,press:-.1};function j4(t){let e=vn(T5(t.to,t.from)),n=T5(t.up,e.map(c=>c*gn(t.up,e)));Math.hypot(...n)<1e-9&&(n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0]);let r=vn(T5(n,e.map(c=>c*gn(n,e))));return{axis:e,u:Nr(r,e),v:r}}function Ur(t,e){let{u:n,v:r}=j4(t);if(Array.isArray(t.size)){let[s,o]=[t.size[0]/2+e/2,t.size[1]/2+e/2];return[[-s,-o],[s,-o],[s,o],[-s,o]].map(([i,l])=>[n[0]*i+r[0]*l,n[1]*i+r[1]*l,n[2]*i+r[2]*l])}let c=t.size/2+e/2,a=t.sides<12?t.sides:64;return Array.from({length:a},(s,o)=>{let i=2*Math.PI*o/a,[l,h]=[Math.cos(i)*c,Math.sin(i)*c];return[n[0]*h+r[0]*l,n[1]*h+r[1]*l,n[2]*h+r[2]*l]})}function yn(t,e,n){let r=T5(e.to,e.from);if(!(Math.hypot(...r)>1e-9))return;let c=v0(t.matrix),a=i=>[c[0]*i[0]+c[1]*i[1]+c[2]*i[2]+c[3],c[4]*i[0]+c[5]*i[1]+c[6]*i[2]+c[7],c[8]*i[0]+c[9]*i[1]+c[10]*i[2]+c[11]],s=T5(a(r),a([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let o=[];for(let i of Ur(e,n)){let l=a([e.from[0]+i[0],e.from[1]+i[1],e.from[2]+i[2]]),h=(0-l[2])/s[2],u=(t.thickness-l[2])/s[2];if(h>u&&([h,u]=[u,h]),h=Math.max(0,h),u=Math.min(1,u),u>h)for(let f of[h,u])o.push([l[0]+s[0]*f,l[1]+s[1]*f])}return o.length>=3?ve(o):void 0}var Le=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Br=(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]],bn=t=>[t[2],t[6],t[10]],xn=t=>[t[3],t[7],t[11]];function Mn(t,e,n){let r=[];for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let o=c[s],i=c[a],l=n[0]*(o[1]-e[1])-n[1]*(o[0]-e[0]),h=n[0]*(i[1]-e[1])-n[1]*(i[0]-e[0]);if(l>0==h>0)continue;let u=l/(l-h);r.push((o[0]+(i[0]-o[0])*u-e[0])*n[0]+(o[1]+(i[1]-o[1])*u-e[1])*n[1])}return r.sort((c,a)=>c-a)}function wn(t,e){for(let n=0;n+1<t.length;n+=2)if(t[n]<=e&&e<=t[n+1])return[t[n],t[n+1]]}function _r(t,[e,n]){let r=!1;for(let c of t)for(let a=0,s=c.length-1;a<c.length;s=a++){let[o,i]=c[s],[l,h]=c[a];i>n!=h>n&&e<o+(l-o)*(n-i)/(h-i)&&(r=!r)}return r}function kn(t,e,n){let r={a:[],b:[],thin:0},c=bn(t.matrix),a=bn(e.matrix),s=Br(c,a),o=Math.hypot(...s);if(o<1e-6)return r;let i=Math.abs(Le(c,a)),l=[s[0]/o,s[1]/o,s[2]/o],h=Le(c,xn(t.matrix))+t.thickness/2,u=Le(a,xn(e.matrix))+e.thickness/2,f=Le(c,a),d=1-f*f,p=(h-u*f)/d,m=(u-h*f)/d,g=[p*c[0]+m*a[0],p*c[1]+m*a[1],p*c[2]+m*a[2]],v=S=>{let C=v0(S.matrix);return[[C[0]*g[0]+C[1]*g[1]+C[2]*g[2]+C[3],C[4]*g[0]+C[5]*g[1]+C[6]*g[2]+C[7]],[C[0]*l[0]+C[1]*l[1]+C[2]*l[2],C[4]*l[0]+C[5]*l[1]+C[6]*l[2]]]},[b,y]=v(t),[x,w]=v(e),M=Mn(t.outline,b,y),k=Mn(e.outline,x,w),z=(e.thickness+t.thickness*i)/o+n,A=(t.thickness+e.thickness*i)/o+n;for(let S=0;S+1<M.length;S+=2)for(let C=0;C+1<k.length;C+=2){let I=Math.max(M[S],k[C]),L=Math.min(M[S+1],k[C+1]);if(!(L-I>.01))continue;let T=(I+L)/2,[q,P]=wn(M,T),[F,j]=wn(k,T),_=Math.max(P-T,T-F)<=Math.max(T-q,j-T),Q=(Y,e1,X,M1,v1,p1)=>{let G1=[-X[1],X[0]],F1=(a1,x1)=>[e1[0]+X[0]*(T+v1*a1)+G1[0]*x1,e1[1]+X[1]*(T+v1*a1)+G1[1]*x1],V=p1+M1+1,U=[F1(0,-M1/2),F1(V,-M1/2),F1(V,M1/2),F1(0,M1/2)];b1(U)<0&&U.reverse();let r1=F1(Math.min(.01,p1/2),0),h1=R0(K1([U],Y.outline)).find(a1=>_r(a1,r1));if(!(!h1||!(h1.reduce((a1,x1)=>a1+b1(x1),0)>1e-4)))return K1(c0(h1,.05,"miter"),[U])},H=Q(t,b,y,z,_?1:-1,_?P-T:T-q),B=Q(e,x,w,A,_?-1:1,_?T-F:j-T);if(!H||!B){r.thin++;continue}r.a.push(...H),r.b.push(...B)}return r}var h2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="range",p2=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="function",Sn=t=>typeof t=="number",G0=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&t.type==="record",K0=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function G4(t,e,n=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&n<32){for(let r of e)G4(t,r,n+1);return}throw new Error(`Setting "${t}" must be a number, string, boolean or list`)}}function Ce(t,e){let n=[];if(t.step===0||(t.step>0?t.start>t.end:t.start<t.end))return n;let r=Math.floor((t.end-t.start)/t.step+1e-9)+1;if(r>e)throw new Error(`a range of ${r} items is more than the limit of ${e}`);for(let c=0;c<r;c++)n.push(t.start+c*t.step);return n}function y0(t){return t===void 0||t===!1||t===0||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="number"?!Number.isNaN(t):!0}var zn=(t,e,n)=>h2(t)&&h2(e)?t.start===e.start&&t.step===e.step&&t.end===e.end:G0(t)&&G0(e)?t.fields.size===e.fields.size&&[...t.fields].every(([r,c])=>e.fields.has(r)&&_3(c,e.fields.get(r),n)):t===e;function _3(t,e,n){if(n?.(),!Array.isArray(t)||!Array.isArray(e))return zn(t,e,n);let r=new Map,c=[],a=(s,o)=>{let i=r.get(s);return i?.has(o)?!0:s.length!==o.length?!1:(i||r.set(s,i=new Set),i.add(o),c.push([s,o,0]),!0)};if(!a(t,e))return!1;for(;c.length;){let s=c[c.length-1];if(s[2]===s[0].length){c.pop();continue}let o=s[0][s[2]],i=s[1][s[2]++];if(n?.(),Array.isArray(o)&&Array.isArray(i)?!a(o,i):!zn(o,i,n))return!1}return!0}function D0(t){return t===void 0?"undef":Array.isArray(t)?"list":h2(t)?"range":p2(t)?"function":G0(t)?"record":typeof t}function jr(t){return t===void 0?"undef":typeof t=="string"?JSON.stringify(t):typeof t=="number"?q2(t):h2(t)?`[${q2(t.start)}:${q2(t.step)}:${q2(t.end)}]`:p2(t)?`function(${t.params.map(e=>e.name).join(", ")})`:G0(t)?"{}":String(t)}function j3(t,e,n=!1){if(typeof t=="string"&&!n)return{text:t.length>e?t.slice(0,Math.max(e,0)):t,whole:t.length<=e};let r=[],c=0,a=l=>{r.push(l),c+=l.length},s=[],o=t;for(;;){Array.isArray(o)?(a("["),s.push({items:o,i:0,close:"]"})):G0(o)&&o.fields.size?(a("{"),s.push({items:[...o.fields.values()],keys:[...o.fields.keys()],i:0,close:"}"})):a(jr(o));let l=!1;for(;s.length&&!l&&c<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&a(", "),h.keys&&a(`${h.keys[h.i]} = `),o=h.items[h.i++],l=!0):(s.pop(),a(h.close))}if(!l||c>e)break}let i=r.join("");return c>e?{text:i.slice(0,Math.max(e,0)),whole:!1}:{text:i,whole:!0}}function An(t,e,n){let r=[],c=0;for(let a of t){r.length&&(c+=e.length);let s=j3(a,n-c);if(!s.whole)return;c+=s.text.length,r.push(s.text)}return r.join(e)}function C0(t){let e=j3(t,200,!0);return e.whole?e.text:e.text+"..."}var b0=t=>typeof t=="string"?t:C0(t);function U0(t){let e=!1;for(;Array.isArray(t)&&t.length===1;)t=t[0],e=!0;return Array.isArray(t)?t.length?NaN:0:e&&(t===void 0||typeof t=="boolean")?t===void 0?0:NaN:typeof t=="object"?NaN:Number(t)}function q2(t){return Number.isInteger(t)?String(t):String(Number(t.toPrecision(10)))}function G3(t,e=.02){let n=[],r=[],c=[],a=[0,0],s=[0,0],o=l=>{c.length>=2&&(l?n:r).push(c),c=[]},i=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of t)if(l.type==="M")o(!1),a=s=[l.x,l.y],c=[s];else if(l.type==="L")s=[l.x,l.y],c.push(s);else if(l.type==="Q"){let[h,u]=s,f=i(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=f;d++){let p=d/f,m=1-p;c.push([m*m*h+2*m*p*l.x1+p*p*l.x,m*m*u+2*m*p*l.y1+p*p*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,u]=s,f=i(Math.hypot(l.x1-h,l.y1-u)+Math.hypot(l.x2-l.x1,l.y2-l.y1)+Math.hypot(l.x-l.x2,l.y-l.y2));for(let d=1;d<=f;d++){let p=d/f,m=1-p;c.push([m*m*m*h+3*m*m*p*l.x1+3*m*p*p*l.x2+p*p*p*l.x,m*m*m*u+3*m*m*p*l.y1+3*m*p*p*l.y2+p*p*p*l.y])}s=[l.x,l.y]}else o(!0),s=a,c=[a];return o(!1),{closed:n,open:r}}function W3(t,e=Math.PI/2,n){let r=x=>/^[a-zA-Z]$/.test(x),c=t.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],a=[],s=0,o="",i=0,l=0,h=0,u=0,f=0,d=0,p=0,m=0,g="",v=()=>{let x=c[s++];if(x===void 0||r(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},b=()=>{let x=c[s];if(x===void 0)throw new Error("Bad path data: missing arc flag");return x.length>1&&(x[0]==="0"||x[0]==="1")&&!x.includes(".")?(c[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{y()}catch(x){if(!n)throw x;n(x.message)}return a;function y(){for(;s<c.length;){if(r(c[s]))o=c[s++];else if(o){if(o==="Z"||o==="z")throw new Error(`Bad path data near "${c[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let x=o===o.toLowerCase(),w=o.toUpperCase(),M=x?i:0,k=x?l:0;if(w==="M")i=M+v(),l=k+v(),h=i,u=l,a.push({type:"M",x:i,y:l}),o=x?"l":"L";else if(w==="L")i=M+v(),l=k+v(),a.push({type:"L",x:i,y:l});else if(w==="H")i=M+v(),a.push({type:"L",x:i,y:l});else if(w==="V")l=k+v(),a.push({type:"L",x:i,y:l});else if(w==="C"||w==="S"){let z,A;if(w==="C")z=M+v(),A=k+v();else{let I=g==="C"||g==="S";z=I?2*i-f:i,A=I?2*l-d:l}let S=M+v(),C=k+v();i=M+v(),l=k+v(),f=S,d=C,a.push({type:"C",x1:z,y1:A,x2:S,y2:C,x:i,y:l})}else if(w==="Q"||w==="T"){let z,A;if(w==="Q")z=M+v(),A=k+v();else{let S=g==="Q"||g==="T";z=S?2*i-p:i,A=S?2*l-m:l}i=M+v(),l=k+v(),p=z,m=A,a.push({type:"Q",x1:z,y1:A,x:i,y:l})}else if(w==="A"){let z=v(),A=v(),S=v(),C=b(),I=b(),L=M+v(),T=k+v();a.push(...Gr(i,l,z,A,S,C,I,L,T,e)),i=L,l=T}else if(w==="Z")a.push({type:"Z"}),i=h,l=u;else throw new Error(`Unknown path command "${o}"`);g=w}}}function Gr(t,e,n,r,c,a,s,o,i,l=Math.PI/2){if(n===0||r===0||t===o&&e===i)return[{type:"L",x:o,y:i}];n=Math.abs(n),r=Math.abs(r);let h=c*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=(t-o)/2,p=(e-i)/2,m=u*d+f*p,g=-f*d+u*p,v=m*m/(n*n)+g*g/(r*r);v>1&&(n*=Math.sqrt(v),r*=Math.sqrt(v));let b=n*n*r*r-n*n*g*g-r*r*m*m,y=n*n*g*g+r*r*m*m,x=Math.sqrt(Math.max(0,b/y));a===s&&(x=-x);let w=x*n*g/r,M=-x*r*m/n,k=u*w-f*M+(t+o)/2,z=f*w+u*M+(e+i)/2,A=(P,F,j,_)=>Math.atan2(P*_-F*j,P*j+F*_),S=A(1,0,(m-w)/n,(g-M)/r),C=A((m-w)/n,(g-M)/r,(-m-w)/n,(-g-M)/r);!s&&C>0&&(C-=2*Math.PI),s&&C<0&&(C+=2*Math.PI);let I=Math.ceil(Math.abs(C)/l),L=[],T=P=>[k+n*Math.cos(P)*u-r*Math.sin(P)*f,z+n*Math.cos(P)*f+r*Math.sin(P)*u],q=P=>[-n*Math.sin(P)*u-r*Math.cos(P)*f,-n*Math.sin(P)*f+r*Math.cos(P)*u];for(let P=0;P<I;P++){let F=S+C*P/I,j=S+C*(P+1)/I,_=4/3*Math.tan((j-F)/4),Q=T(F),H=T(j),B=q(F),Y=q(j);L.push({type:"C",x1:Q[0]+_*B[0],y1:Q[1]+_*B[1],x2:H[0]-_*Y[0],y2:H[1]-_*Y[1],x:H[0],y:H[1]})}return L}var I0=Math.PI/180;function In(t,e,n,r){if(typeof t=="number"&&typeof e=="number")return t-e;if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;if(Array.isArray(t)&&Array.isArray(e)){for(let c=0;c<Math.min(t.length,e.length);c++){r();let a=In(t[c],e[c],n,r);if(a)return a}return t.length-e.length}throw new Error(`${n}() can only order numbers, strings or lists of them, not ${D0(t)} and ${D0(e)}`)}function Y4(t,e,n){let r=q0(t,e,n);return(r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.flatMap(a=>q0(a,e,n)):r).map(a=>{if(!Array.isArray(a)||a.length<2)throw new Error(`${e}() needs points [x, y], got ${D0(a)}`);return[C1(a[0],e),C1(a[1],e)]})}function Wr(t,e,n){let r=q0(t,e,n);return r.length&&Array.isArray(r[0])&&Array.isArray(r[0][0])?r.map(c=>Y4(c,e,n)):[Y4(r,e,n)]}var A1=(t,e,n)=>({params:t.replace("...","").split(",").map(r=>r.trim()).filter(Boolean),rest:t.endsWith("..."),order:n,run:e});function Vn(t,e,n){return t.order?[]:t.params.filter((r,c)=>c<e.length&&n.has(r))}function Hn(t,e,n){if(t.rest){let a=[...e];return t.params.forEach((s,o)=>{n.has(s)&&(a[o]=n.get(s))}),a}if(!t.order)return t.params.map((a,s)=>n.has(a)?n.get(a):e[s]);let r=e.length+t.params.filter(a=>n.has(a)).length,c=t.order(r).filter(a=>!n.has(a));return t.params.map(a=>n.has(a)?n.get(a):e[c.indexOf(a)])}function W4(t,e,n,r){let c=An(t,e,n.maxLength);if(c===void 0)throw new Error(`${r}(): the text would be longer than the limit of ${n.maxLength} characters`);return n.step(Math.ceil(c.length/8)),c}function C1(t,e){if(typeof t!="number")throw new Error(`${e}() needs a number, got ${D0(t)}`);return t}function q0(t,e,n){if(Array.isArray(t))return t;if(h2(t))return Ce(t,n.maxLength);if(typeof t=="string")return[...t];throw new Error(`${e}() needs a list, got ${D0(t)}`)}var Xr=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function On(t,e,n){if(Xr.has(t))return 0;let r=0;for(let c of e)if(typeof c=="string")r+=c.length;else if(Array.isArray(c))r+=t==="len"?0:c.length;else if(h2(c)&&c.step!==0){let a=Math.floor((c.end-c.start)/c.step)+1;a>0&&(r+=Math.min(a,n+1))}return r}var Q0=t=>A1("x",e=>typeof e[0]=="number"?u2(t(e[0])):void 0);function u2(t){let e=Math.round(t);return Math.abs(t-e)<1e-12?e:t}function $n(t){let e=Math.floor(t)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var Pe=new Map;function Zr(t){let e=Pe.get(t);if(e)return e;let n=$n(t),r=Array.from({length:256},(c,a)=>a);for(let c=255;c>0;c--){let a=Math.floor(n()*(c+1));[r[c],r[a]]=[r[a],r[c]]}e=new Uint8Array(512);for(let c=0;c<512;c++)e[c]=r[c&255];return Pe.size>64&&Pe.clear(),Pe.set(t,e),e}var X4=t=>t*t*t*(t*(t*6-15)+10);function K2(t,e,n,r){let c=t&15,a=c<8?e:n,s=c<4?n:c===12||c===14?e:r;return((c&1)===0?a:-a)+((c&2)===0?s:-s)}function Yr(t,e,n,r){let c=Zr(r),a=Math.floor(t),s=Math.floor(e),o=Math.floor(n);t-=a,e-=s,n-=o;let i=a&255,l=s&255,h=o&255,u=X4(t),f=X4(e),d=X4(n),p=c[i]+l,m=c[p]+h,g=c[p+1]+h,v=c[i+1]+l,b=c[v]+h,y=c[v+1]+h,x=(w,M,k)=>M+w*(k-M);return x(d,x(f,x(u,K2(c[m],t,e,n),K2(c[b],t-1,e,n)),x(u,K2(c[g],t,e-1,n),K2(c[y],t-1,e-1,n))),x(f,x(u,K2(c[m+1],t,e,n-1),K2(c[b+1],t-1,e,n-1)),x(u,K2(c[g+1],t,e-1,n-1),K2(c[y+1],t-1,e-1,n-1))))}function Ln(t,e,n){let r=t.length===1&&Array.isArray(t[0])?t[0]:t;if(r.length)return e(r.map(c=>C1(c,n)))}var 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:A1("x, base",(t,e)=>e.given<2?u2(Math.log10(C1(t[0],"log"))):Math.log(C1(t[0],"log"))/Math.log(C1(t[1],"log")),t=>t>=2?["base","x"]:["x","base"]),sin:Q0(t=>Math.sin(t*I0)),cos:Q0(t=>Math.cos(t*I0)),tan:Q0(t=>Math.tan(t*I0)),asin:Q0(t=>Math.asin(t)/I0),acos:Q0(t=>Math.acos(t)/I0),atan:Q0(t=>Math.atan(t)/I0),atan2:A1("y, x",t=>u2(Math.atan2(C1(t[0],"atan2"),C1(t[1],"atan2"))/I0)),pow:A1("x, y",t=>Math.pow(C1(t[0],"pow"),C1(t[1],"pow"))),min:A1("values...",t=>Ln(t,e=>e.reduce((n,r)=>r<n?r:n,1/0),"min")),max:A1("values...",t=>Ln(t,e=>e.reduce((n,r)=>r>n?r:n,-1/0),"max")),clamp:A1("x, low, high",t=>Math.min(Math.max(C1(t[0],"clamp"),C1(t[1],"clamp")),C1(t[2],"clamp"))),lerp:A1("a, b, t",t=>{let e=C1(t[2],"lerp");if(Array.isArray(t[0])&&Array.isArray(t[1])){let n=t[1];return t[0].map((r,c)=>C1(r,"lerp")+(C1(n[c],"lerp")-C1(r,"lerp"))*e)}return C1(t[0],"lerp")+(C1(t[1],"lerp")-C1(t[0],"lerp"))*e}),norm:A1("v",(t,e)=>Math.sqrt(q0(t[0],"norm",e).reduce((n,r)=>n+C1(r,"norm")**2,0))),cross:A1("a, b",(t,e)=>{let n=q0(t[0],"cross",e).map(c=>C1(c,"cross")),r=q0(t[1],"cross",e).map(c=>C1(c,"cross"));return n.length===2?n[0]*r[1]-n[1]*r[0]:[n[1]*r[2]-n[2]*r[1],n[2]*r[0]-n[0]*r[2],n[0]*r[1]-n[1]*r[0]]}),len:A1("value",t=>typeof t[0]=="string"?[...t[0]].length:Array.isArray(t[0])?t[0].length:G0(t[0])?t[0].fields.size:void 0),keys:A1("record",t=>G0(t[0])?[...t[0].fields.keys()]:void 0),merge:A1("a, b",t=>{if(!G0(t[0])||!G0(t[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...t[0].fields,...t[1].fields])}}),concat:A1("...",(t,e)=>{let n=t.reduce((r,c)=>r+(Array.isArray(c)?c.length:1),0);if(n>e.maxLength)throw new Error(`concat(): a list of ${n} items is more than the limit of ${e.maxLength}`);return t.flatMap(r=>Array.isArray(r)?r:[r])}),reverse:A1("value",(t,e)=>typeof t[0]=="string"?[...t[0]].reverse().join(""):[...q0(t[0],"reverse",e)].reverse()),sort:A1("values, key",(t,e)=>{let n=q0(t[0],"sort",e),r=t[1],c=n.map(a=>[r===void 0?a:e.apply(r,[a]),a]);return e.step(Math.ceil(n.length*Math.log2(n.length+1))),c.sort((a,s)=>In(a[0],s[0],"sort",()=>e.step())).map(([,a])=>a)}),fold:A1("values, initial, fn",(t,e)=>{let n=t[1];for(let r of q0(t[0],"fold",e))n=e.apply(t[2],[n,r]);return n}),scan:A1("values, initial, fn",(t,e)=>{let n=t[1];return q0(t[0],"scan",e).map(r=>n=e.apply(t[2],[n,r]))}),bounds:A1("points",(t,e)=>{let n=Y4(t[0],"bounds",e);if(!n.length)return;let[r,c,a,s]=[1/0,1/0,-1/0,-1/0];for(let[o,i]of n)r=Math.min(r,o),c=Math.min(c,i),a=Math.max(a,o),s=Math.max(s,i);return[r,c,a,s]}),crossings:A1("points, x, y",(t,e)=>{if(t[1]===void 0==(t[2]===void 0))throw new Error("crossings() needs one of x or y");let n=t[1]===void 0,r=C1(n?t[2]:t[1],"crossings"),c=[];for(let a of Wr(t[0],"crossings",e))for(let s=0,o=a.length-1;s<a.length;o=s++){let[i,l]=n?[a[o][1],a[o][0]]:a[o],[h,u]=n?[a[s][1],a[s][0]]:a[s];i>r!=h>r&&c.push(l+(u-l)*(r-i)/(h-i))}return c.sort((a,s)=>a-s)}),sum:A1("values",(t,e)=>q0(t[0],"sum",e).reduce((n,r)=>n+C1(r,"sum"),0)),slice:A1("value, start, end",(t,e)=>{let r=(typeof t[0]=="string"?[...t[0]]:q0(t[0],"slice",e)).slice(C1(t[1]??0,"slice"),t[2]===void 0?void 0:C1(t[2],"slice"));return typeof t[0]=="string"?r.join(""):r}),str:A1("...",(t,e)=>W4(t,"",e,"str")),chr:A1("...",t=>t.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(C1(e,"chr"))).join("")),ord:A1("text",t=>typeof t[0]=="string"&&t[0].length?t[0].codePointAt(0):void 0),upper:A1("text",t=>typeof t[0]=="string"?t[0].toUpperCase():void 0),lower:A1("text",t=>typeof t[0]=="string"?t[0].toLowerCase():void 0),split:A1("text, separator",t=>typeof t[0]=="string"?t[0].split(typeof t[1]=="string"?t[1]:" "):void 0),join:A1("values, separator",(t,e)=>W4(q0(t[0],"join",e),typeof t[1]=="string"?t[1]:"",e,"join")),search:A1("value, list",(t,e)=>{let r=(typeof t[1]=="string"?[...t[1]]:q0(t[1],"search",e)).findIndex(c=>_3(c,t[0],e.step));return r<0?void 0:r}),contains:A1("value, item",(t,e)=>typeof t[0]=="string"?t[0].includes(W4([t[1]],"",e,"contains")):q0(t[0],"contains",e).some(n=>_3(n,t[1],e.step))),lookup:A1("x, table",(t,e)=>{let n=C1(t[0],"lookup"),r=q0(t[1],"lookup",e);if(!r.length)return;let c=r.map(a=>[C1(a[0],"lookup"),C1(a[1],"lookup")]).sort((a,s)=>a[0]-s[0]);if(n<=c[0][0])return c[0][1];for(let a=1;a<c.length;a++)if(n<=c[a][0]){let[s,o]=c[a-1],[i,l]=c[a];return o+(n-s)/(i-s)*(l-o)}return c[c.length-1][1]}),rands:A1("min, max, count, seed",t=>{let e=C1(t[0],"rands"),n=C1(t[1],"rands"),r=C1(t[2],"rands"),c=$n(t[3]===void 0?1:C1(t[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(r)),1e6)},()=>e+(n-e)*c())}),noise:A1("x, y, z, seed, octaves",t=>{let e,n=0,r=0;if(Array.isArray(t[0])){let h=t[0];e=C1(h[0],"noise"),n=h[1]===void 0?0:C1(h[1],"noise"),r=h[2]===void 0?0:C1(h[2],"noise")}else e=C1(t[0],"noise"),t[1]!==void 0&&(n=C1(t[1],"noise")),t[2]!==void 0&&(r=C1(t[2],"noise"));let c=Math.floor(t[3]===void 0?1:C1(t[3],"noise")),a=t[4]===void 0?1:Math.floor(C1(t[4],"noise"));if(!(a>=1&&a<=8))throw new Error("noise(): octaves must be 1 to 8");let s=0,o=1,i=0,l=1;for(let h=0;h<a;h++)s+=o*Yr(e*l+h*.3713,n*l+h*.6271,r*l+h*.1943,c+h*7919),i+=o,o/=2,l*=2;return u2(s/i)}),is_num:A1("value",t=>Sn(t[0])&&!Number.isNaN(t[0])),is_string:A1("value",t=>typeof t[0]=="string"),is_bool:A1("value",t=>typeof t[0]=="boolean"),is_list:A1("value",t=>Array.isArray(t[0])),is_record:A1("value",t=>G0(t[0])),is_undef:A1("value",t=>t[0]===void 0),is_function:A1("value",t=>p2(t[0])),type_of:A1("value",t=>D0(t[0])),path_length:A1("points",(t,e)=>{let n=V5(t[0],"path_length",e),r=0;for(let c=1;c<n.length;c++)r+=Math.hypot(n[c][0]-n[c-1][0],n[c][1]-n[c-1][1]);return r}),point_at:A1("points, s",(t,e)=>Cn(V5(t[0],"point_at",e),C1(t[1],"point_at")).point),heading_at:A1("points, s",(t,e)=>u2(Cn(V5(t[0],"heading_at",e),C1(t[1],"heading_at")).heading)),offset_path:A1("points, d, closed",(t,e)=>{let n=V5(t[0],"offset_path",e).filter(([l,h],u,f)=>u===0||l!==f[u-1][0]||h!==f[u-1][1]),r=C1(t[1],"offset_path"),c=t[2]===!0,a=c&&n.length>1&&n[0][0]===n.at(-1)[0]&&n[0][1]===n.at(-1)[1];if(a&&n.pop(),n.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(n.length);let s=n.length,o=l=>{let[h,u]=n[l%s],[f,d]=n[(l+1)%s],p=Math.hypot(f-h,d-u);return[-(d-u)/p,(f-h)/p]},i=n.map(([l,h],u)=>{let f=!c&&u===0,d=!c&&u===s-1,p=o(f?0:(u-1+s)%s),m=o(d?s-2:u),[g,v]=[p[0]+m[0],p[1]+m[1]],b=Math.hypot(g,v);if(b<1e-9)[g,v]=p;else{let y=Math.min(2/(b*b),4/b);[g,v]=[g*y,v*y]}return[u2(l+r*g),u2(h+r*v)]});return a?[...i,i[0]]:i}),train_for:A1("ratio, stages, pinion, wheel",(t,e)=>{let n=C1(t[0],"train_for");if(!(n>0)||!Number.isFinite(n))throw new Error("train_for(): ratio must be more than 0");let r=t[1]===void 0?2:C1(t[1],"train_for");if(!(r===1||r===2||r===3))throw new Error("train_for(): stages must be 1, 2 or 3");let c=(v,b,y)=>{if(v===void 0)return b;if(!Array.isArray(v)||v.length!==2||!v.every(M=>typeof M=="number"))throw new Error(`train_for(): ${y} must be [fewest, most] teeth`);let[x,w]=[Math.ceil(v[0]),Math.floor(v[1])];if(!(x>=6&&w>=x&&w<=400))throw new Error(`train_for(): ${y} teeth must be from 6 to 400, fewest first`);return[x,w]},[a,s]=c(t[2],[10,20],"pinion"),[o,i]=c(t[3],[20,80],"wheel"),l=n<1,h=l?1/n:n,u=[];for(let v=a;v<=s;v++)for(let b=Math.max(o,v);b<=i;b++)u.push([v,b]);let f,d=v=>{let b=v.reduce((w,[M,k])=>w*k/M,1),y=Math.abs(b/h-1),x=v.reduce((w,[M,k])=>w+M+k,0);(!f||y<f.err-1e-12||Math.abs(y-f.err)<=1e-12&&x<f.teeth)&&(f={stages:v.map(w=>[...w]),err:y,teeth:x})},p=(v,b)=>{e.step();for(let y=a;y<=s;y++)for(let x of[Math.floor(b*y),Math.ceil(b*y)])x>=Math.max(o,y)&&x<=i&&d([...v,[y,x]])};if(r===1)p([],h);else for(let v=0;v<u.length;v++){let b=u[v][1]/u[v][0];if(r===2)p([u[v]],h/b);else for(let y=v;y<u.length;y++)p([u[v],u[y]],h/b/(u[y][1]/u[y][0]))}if(!f)throw new Error(`train_for(): no train of ${r} stages reaches a ratio of ${n}`);let m=f.stages.map(([v,b])=>l?[b,v]:[v,b]),g=m.reduce((v,[b,y])=>v*y/b,1);return{type:"record",fields:new Map([["stages",m],["ratio",g],["error",g/n-1]])}}),path_points:A1("d, tolerance",(t,e)=>{if(typeof t[0]!="string")throw new Error("path_points() needs SVG path data");let n=t[1]===void 0?.05:C1(t[1],"path_points");if(!(n>0))throw new Error("path_points(): tolerance must be more than 0");let r=G3(W3(t[0]),n),c=[...r.closed.map(a=>[...a,a[0]]),...r.open];return e.step(c.reduce((a,s)=>a+s.length,0)),c.map(a=>a.map(([s,o])=>[s,o]))}),spline_points:A1("points, steps, closed",(t,e)=>{let n=V5(t[0],"spline_points",e),r=t[1]===void 0?8:Math.floor(C1(t[1],"spline_points"));if(!(r>=1))throw new Error("spline_points(): steps must be 1 or more");if(n.length*r>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(n.length*r),J4(n,r,t[2]===!0)}),rotation:A1("angles",t=>{let[e,n,r]=Z4(t[0],"rotation");return tc(En(ec(r),En(Qr(n),Kr(e))))}),euler:A1("matrix",t=>Tn(Jr(t[0],"euler"))),orient:A1("x, z",t=>{let e=Pn(Z4(t[0],"orient"),"orient"),n=Z4(t[1]??[0,0,1],"orient"),r=n[0]*e[0]+n[1]*e[1]+n[2]*e[2];n=Pn([n[0]-r*e[0],n[1]-r*e[1],n[2]-r*e[2]],"orient");let c=[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]];return Tn([[e[0],c[0],n[0]],[e[1],c[1],n[1]],[e[2],c[2],n[2]]])})};function V5(t,e,n){return q0(t,e,n).map((c,a)=>{if(!Array.isArray(c)||typeof c[0]!="number"||typeof c[1]!="number")throw new Error(`${e}(): points[${a}] must be an [x, y] point`);return[c[0],c[1]]})}function Cn(t,e){if(t.length<2)throw new Error("a path needs at least two points");let n=t.filter(([i,l],h)=>h===0||i!==t[h-1][0]||l!==t[h-1][1]);if(n.length<2)return{point:[n[0][0],n[0][1]],heading:0};let r=0,c=0;for(;r<n.length-2;r++){let i=Math.hypot(n[r+1][0]-n[r][0],n[r+1][1]-n[r][1]);if(c+i>=e)break;c+=i}let[a,s]=[n[r],n[r+1]],o=(e-c)/Math.hypot(s[0]-a[0],s[1]-a[1]);return{point:[a[0]+(s[0]-a[0])*o,a[1]+(s[1]-a[1])*o],heading:Math.atan2(s[1]-a[1],s[0]-a[0])/I0}}function Z4(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 Pn(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 Jr(t,e){if(!Array.isArray(t)||t.length<3||!t.slice(0,3).every(n=>Array.isArray(n)&&n.length>=3&&n.slice(0,3).every(r=>typeof r=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return t.slice(0,3).map(n=>n.slice(0,3))}var Kr=t=>{let[e,n]=[Math.cos(t*I0),Math.sin(t*I0)];return[[1,0,0],[0,e,-n],[0,n,e]]},Qr=t=>{let[e,n]=[Math.cos(t*I0),Math.sin(t*I0)];return[[e,0,n],[0,1,0],[-n,0,e]]},ec=t=>{let[e,n]=[Math.cos(t*I0),Math.sin(t*I0)];return[[e,-n,0],[n,e,0],[0,0,1]]},En=(t,e)=>t.map(n=>[0,1,2].map(r=>n[0]*e[0][r]+n[1]*e[1][r]+n[2]*e[2][r])),tc=t=>t.map(e=>e.map(u2));function Tn(t){let e=-t[2][0];if(Math.abs(e)>1-1e-12){let n=e>0?90:-90,r=Math.atan2(-t[0][1],t[1][1])/I0;return[0,n,u2(r)]}return[u2(Math.atan2(t[2][1],t[2][2])/I0),u2(Math.asin(e)/I0),u2(Math.atan2(t[1][0],t[0][0])/I0)]}function J4(t,e,n=!1){if(t.length<3)return t.map(([s,o])=>[s,o]);let r=s=>{if(n)return t[(s%t.length+t.length)%t.length];if(s<0)return[2*t[0][0]-t[1][0],2*t[0][1]-t[1][1]];if(s>=t.length){let[o,i]=[t[t.length-1],t[t.length-2]];return[2*o[0]-i[0],2*o[1]-i[1]]}return t[s]},c=[],a=n?t.length:t.length-1;for(let s=0;s<a;s++){let[o,i,l,h]=[r(s-1),r(s),r(s+1),r(s+2)];for(let u=0;u<e;u++){let f=u/e,d=f*f,p=d*f;c.push([0,1].map(m=>.5*(2*i[m]+(-o[m]+l[m])*f+(2*o[m]-5*i[m]+4*l[m]-h[m])*d+(-o[m]+3*i[m]-3*l[m]+h[m])*p)))}}return c.push(n?c[0]:[t[t.length-1][0],t[t.length-1][1]]),c}function x3(t,e){let n=Math.round(t/e);return n%2===0&&(n+=t/e>n?1:-1),Math.max(3,n)}var O5=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function nc(t,e,n,r){if(e==="flat")return[];let c=x3(t,r),a=t/c,s=[];for(let o=0;o<c;o++)(e==="out"?o%2===1:o%2===0)&&s.push(O5(o*a,-1,(o+1)*a,n));return s}function Ee(t,e,n,r,c){let a=[([i,l])=>[i,l],([i,l])=>[t-l,i],([i,l])=>[t-i,e-l],([i,l])=>[l,e-i]],s=[t,e,t,e],o=[];return n.forEach((i,l)=>{for(let h of nc(s[l],i,r,c))o.push(h.map(a[l]))}),g0([O5(0,0,t,e)],o)}function Rn(t,e,n,r){let c=x3(t,r),a=t/c,s=[];for(let o=0;o<c;o++)(e==="out"?o%2===0:o%2===1)&&s.push(O5(o*a,-n/2,(o+1)*a,n/2));return s}function Fn(t,e,n,r,c){let a=O5(-t/2,-1,t/2,e),s=O5(-n/2,c,n/2,c+r);return[a,s]}function Dn(t,e,n,r,c){let a=[],s=c+r,o=Math.floor(t/n),i=(t-o*n)/2;for(let l=0;l<=o;l++){let h=i+l*n,u=l%2===0?r:r-s/2;for(let f=u;f<e;f+=s){let d=Math.max(f,l%2===0?r:0),p=Math.min(f+c,e-(l%2===0?r:0));p-d>=r/2&&a.push([[h,d],[h,p]])}}return a}var c2=(t,e=!0)=>`line ${t.line}${e?`, column ${t.col}`:""}${t.file?` in <${t.file}>`:""}`;var i1=class extends Error{constructor(n,r){super(r?`${n} (${c2(r)})`:n);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=n,r&&(this.line=r.line,this.col=r.col,this.file=r.file)}addFrame(n,r,c){let a=this.trace.find(s=>s.name===r&&s.line===c.line&&s.col===c.col&&s.file===c.file);a?a.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:n,name:r,line:c.line,col:c.col,...c.file&&{file:c.file},count:1})}},rc=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function X3(t,e){let n=[],r=[],c=0,a=1,s=0,o=()=>({line:a,col:c-s+1,offset:c,...e&&{file:e}}),i=l=>{for(let h=0;h<l;h++)t[c]===`
|
|
7
7
|
`&&(a++,s=c+1),c++};for(;c<t.length;){let l=t[c];if(l===" "||l===" "||l==="\r"||l===`
|
|
8
|
-
`){
|
|
9
|
-
`,c),d=f<0?t.length:f,
|
|
10
|
-
`,c-1)+1,c));r.push({text:t.slice(c+2,d).trim(),line:a,block:!1,own:
|
|
11
|
-
`;else if(d==="t")f+=" ";else if(d==="u"){let
|
|
12
|
-
`)throw new o1("Unclosed string",h);f+=t[c],o(1)}if(c>=t.length)throw new o1("Unclosed string",h);o(1),n.push({type:"str",value:f,pos:h,end:c});continue}if(l==="<"&&/^<[A-Za-z0-9_./-]+>/.test(t.slice(c))){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([A-Za-z0-9_./-]+)>/.exec(t.slice(c));n.push({type:"str",value:d[1],pos:h,end:c+d[0].length}),o(d[0].length);continue}}let u=gr.find(f=>t.startsWith(f,c));if(!u)throw new o1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:c+u.length}),o(u.length)}return n.push({type:"eof",value:"",pos:i(),end:c}),{tokens:n,comments:r}}var d3={dowel:{color:"#e2c48f",doc:"a wooden dowel or axle"},steel:{color:"#a7adb3",metal:!0,doc:"a steel rod, pin or axle"},brass:{color:"#c9a227",metal:!0,doc:"a brass rod, tube or pin"},screw:{color:"#9aa0a6",metal:!0,doc:"a screw"},bolt:{color:"#9aa0a6",metal:!0,doc:"a bolt"},nut:{color:"#9aa0a6",metal:!0,doc:"a nut"},magnet:{color:"#55585c",metal:!0,doc:"a disc or block magnet"},paper:{color:"#fbfaf6",doc:"a sheet or strip of paper"},card:{color:"#f4f1e8",doc:"card stock"},felt:{color:"#6f6a64",doc:"felt pads or lining"},elastic:{color:"#262626",doc:"an elastic band or cord"},cord:{color:"#b23a3a",doc:"cord, string or thread"},ribbon:{color:"#c2485a",doc:"ribbon or tape"},wire:{color:"#b87333",metal:!0,doc:"wire"},led:{color:"#fff4c2",glow:!0,doc:"an LED or a strip of them"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb; give it shape = "ball"'},ball:{color:"#8fb8d8",doc:'a marble, ball or bead; give it shape = "ball"'},tube:{color:"#c9a227",metal:!0,doc:"a tube, as a hollow arbor or a sleeve"},lens:{color:"#d6ecf3",doc:"a lens, a thin disc of glass or acrylic"},mirror:{color:"#c8d3da",metal:!0,doc:"a mirror"},movement:{color:"#3d3d3d",doc:"a bought movement, as a clock, music box or motor: a labelled block"},white:{color:"#f7f7f4",doc:"anything white"}},U3={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var $e=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function l2(t,e){let{tokens:n,comments:r}=N3(t,e),c=new De(n),a=[];for(;!c.at("eof");)a.push(...c.statement());return{program:{body:a},comments:r}}var C5=class C5{constructor(e){this.tokens=e;this.i=0}peek(e=0){return this.tokens[Math.min(this.i+e,this.tokens.length-1)]}at(e,n,r=0){let c=this.peek(r);return c.type===e&&(n===void 0||c.value===n)}isP(e,n=0){return this.at("punct",e,n)}isK(e,n=0){return this.at("id",e,n)}next(){return this.tokens[this.i++]}fail(e,n=this.peek()){let r=n.type==="eof"?"end of file":`"${n.value}"`;throw new o1(`${e}, found ${r}`,n.pos)}expectP(e){return this.isP(e)||this.fail(`Expected "${e}"`),this.next()}separator(e){this.isP(e)||(this.isP(",")||this.fail(`Expected "," or "${e}"`),this.next())}ident(){let e=this.peek();return(e.type!=="id"||$e.has(e.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let e=this.stmt();for(let n of e)n.end=this.last();return e}stmt(){let e=this.peek();if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let s=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),s.push(...this.statement());return this.next(),[{kind:"block",body:s,pos:e.pos}]}if(this.isK("module")){this.next();let s=this.ident(),i=this.params();return[{kind:"module",name:s.value,params:i,body:this.body(),pos:e.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),i=this.params();this.expectP("=");let o=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:i,body:o,pos:e.pos,namePos:s.pos}]}if(this.isK("use")||this.isK("include")){this.next();let s=this.peek();return s.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:s.value,include:e.value==="include",pos:e.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(this.isK("intersection_for")&&this.isP("(",1))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos,intersect:!0}];if(this.isK("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let i=this.body(),o=[];return this.isK("else")&&(this.next(),o=this.body()),[{kind:"if",cond:s,then:i,else:o,pos:e.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(e.type==="id"&&this.isP("=",1)){let s=this.ident().value;this.next();let i=this.peek().pos.offset,o=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:o,span:[i,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let r=this.peek();(r.type!=="id"||$e.has(r.value))&&this.fail("Expected a statement"),this.next();let c=this.args(),a=this.body();return[{kind:"call",name:r.value,args:c,children:a,modifier:n,pos:r.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident(),r=null;this.isP("=")&&(this.next(),r=this.expr()),e.push({name:n.value,default:r,pos:n.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let n=this.next();this.next(),e.push({name:n.value,value:this.expr(),pos:n.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident();this.expectP("="),e.push({name:n.value,value:this.expr(),pos:n.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let r=this.params(),c=this.expr();return{kind:"lambda",params:r,body:c,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let r=this.assigns(),c=this.expr();return{kind:"let",assigns:r,body:c,pos:e.pos,end:this.last()}}if(this.at("id")&&(e.value==="assert"||e.value==="echo")&&this.isP("(",1)){let r=this.i;this.next();let c={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:c,body:this.expr(),pos:e.pos};this.i=r}let n=this.binary(0);if(this.isP("?")){this.next();let r=this.expr();this.expectP(":");let c=this.expr();return{kind:"ternary",cond:n,then:r,else:c,pos:e.pos}}return n}binary(e){if(e>=C5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&C5.LEVELS[e].includes(this.peek().value);){let r=this.next(),c=this.binary(e+1);n={kind:"binary",op:r.value,left:n,right:c,pos:r.pos}}return n}startsValue(){let e=this.peek();return e.type==="num"||e.type==="str"||e.type==="id"?!0:this.isP("[")||this.isP("(")||this.isP("{")||this.isP("!")||this.isP("-")}unary(){if((this.isK("let")||this.isK("function"))&&this.isP("(",1))return this.expr();if(this.isP("-")||this.isP("!")||this.isP("+")){let e=this.next();return{kind:"unary",op:e.value,arg:this.unary(),pos:e.pos}}return this.power()}power(){let e=this.postfix();if(this.isP("^")){let n=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:n.pos}}return e}postfix(){let e=this.primary();for(;;){let n=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let r=this.expr();this.expectP("]"),e={kind:"index",target:e,index:r,pos:n.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:n.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let n=/(mm|cm|m|in|ft)$/.exec(e.value);return n?{kind:"num",value:Number(e.value.slice(0,-n[1].length)),unit:n[1],pos:e.pos}:{kind:"num",value:Number(e.value),pos:e.pos}}if(e.type==="str")return this.next(),{kind:"str",value:e.value,pos:e.pos};if(e.type==="id")return e.value==="true"||e.value==="false"?(this.next(),{kind:"bool",value:e.value==="true",pos:e.pos}):e.value==="undef"?(this.next(),{kind:"undef",pos:e.pos}):($e.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let n=this.expr();return this.expectP(")"),n}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),n=[];for(;!this.isP("}");){let r=this.ident();if(n.some(c=>c.name===r.value))throw new o1(`Field ${r.value} is given twice`,r.pos);if(this.expectP("="),n.push({name:r.value,value:this.expr(),pos:r.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:n,pos:e.pos}}list(){let e=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:e.pos};if(!this.isK("for")&&!this.isK("if")&&!this.isK("each")&&!(this.isK("let")&&this.isP("(",1))&&!(this.isP("(")&&(this.isK("for",1)||this.isK("if",1)))){let n=this.expr();if(this.isP(":")){this.next();let c=null,a=this.expr();return this.isP(":")&&(this.next(),c=a,a=this.expr()),this.expectP("]"),{kind:"range",start:n,step:c,end:a,pos:e.pos}}let r=[{kind:"item",expr:n}];return this.listRest(r,e.pos)}return this.listRest([],e.pos)}listRest(e,n){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:n};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:n}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"for",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let r=this.listItem(),c=null;return this.isK("else")&&(this.next(),c=this.listItem()),{kind:"if",cond:n,then:r,else:c}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"let",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let n=this.listItem();return this.expectP(")"),n}return{kind:"item",expr:this.expr()}}};C5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var De=C5;var O=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),E1=(t,e,n)=>({...O(t,e,n),named:!0}),qe="max(3 * $thickness, 6)",k4=[O("value")],vr=[O("x")],J0=(t,e)=>({name:t,kind:"function",params:vr,section:"Numbers and vectors",doc:e}),m3=(t,e)=>({name:t,kind:"function",params:k4,section:"Types",doc:`Whether the value is ${e}`}),l7=(t,e)=>({name:t,kind:"function",params:[O("text","The text to measure",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),E1("halign","left, center or right",'"left"'),E1("valign","baseline, top, center or bottom",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Measure at the size that fits this width")],section:"Text measurements",doc:e}),Ne=[{name:"rect",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the rectangle on the origin instead of its corner","false"),E1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the square on the origin instead of its corner","false"),E1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[O("r","Radius","1"),E1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[O("r","[rx, ry], or one radius for both","1")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[O("n","Number of corners","6"),O("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[O("n","Number of points","5"),O("r","Radius of the points","10"),O("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[O("points","A list of [x, y] points"),O("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[O("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),E1("fill",'"evenodd" or "nonzero"','"evenodd"'),E1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[O("text","The text",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),E1("halign","left, center or right",'"left"'),E1("valign","baseline, top, center or bottom",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Shrink the size so the text is no wider than this"),E1("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),E1("bridge","Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[O("from","Start point","[0, 0]"),O("to","End point","[10, 0]"),O("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[O("points","A list of [x, y] points"),O("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[O("r","Radius","10"),O("start","Start angle in degrees","0"),O("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[O("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[O("a","Angle in degrees, anticlockwise","0"),E1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[O("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[O("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[O("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[O("r","Grow (positive) or shrink areas with rounded corners"),E1("delta","Grow or shrink areas with sharp corners","0"),E1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[O("spacing","Distance between copies, a number or [x, y]","10"),O("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[O("points","The [x, y] points the curve goes through"),O("width","Make an area this wide along the curve, instead of a line"),E1("steps","Points between each two given ones","8"),E1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[O("angle","Direction of the lines, in degrees from +x","45"),O("pitch","Distance between the lines","5"),O("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"flow",kind:"module",params:[O("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),O("spacing","Distance between neighbouring lines","2"),O("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),E1("min_length","Lines shorter than this are left out","spacing * 2"),E1("seed","Where the first lines start; another seed gives another arrangement","1")],children:!0,section:"Combining",doc:"Evenly spaced lines that follow a direction field across the area of the children, never closer than half the spacing"},{name:"contours",kind:"module",params:[O("field","The height at a point: function(p) giving a number, or undef for none"),O("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),E1("interval","Instead of levels: every multiple of this height"),E1("cell","Distance between the points sampled: smaller is finer and slower","1")],children:!0,section:"Combining",doc:"Contour lines where a height field crosses each level, across the area of the children"},{name:"occlude",kind:"module",params:[],children:!0,section:"Combining",doc:"Children back to front, each opaque: lines and outlines hide behind the areas of later children, and fills lose that area. Each iteration of a for loop is a child of its own"},{name:"hide",kind:"module",params:[],children:!0,section:"Combining",doc:"Inside occlude(): an area that hides what is behind it but is not drawn"},{name:"paint",kind:"module",params:[O("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[O("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1], $area and $centroid = [x, y] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[O("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"join_islands",kind:"module",params:[O("width","How wide each joining strip is","1")],children:!0,section:"Combining",doc:"Join every separate piece of the material to the nearest other piece with a strip, until it is one piece"},{name:"largest",kind:"module",params:[O("n","How many pieces to keep","1")],children:!0,section:"Combining",doc:"Keep the n biggest connected pieces of the material, dropping crumbs; marks stay as drawn"},{name:"close",kind:"module",params:[O("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[O("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[O("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[O("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[O("name","Layer name"),O("mode",'"cut", "line", "fill" or "guide"'),O("color",'Colour in the output, as "#00aa00"'),E1("order","Where it goes among the custom layers in the files, lowest first","0"),E1("bleed","How far past the part's edge it may print","0"),E1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[O("name","Part name",'"part"'),O("qty","Number of copies to cut","1"),E1("at","Where the part goes in the assembled view, [x, y, z]"),E1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),E1("stack","Layers glued in a stack at each placement, one thickness apart","1"),E1("mirror","Cut the part mirrored left to right, its text still reading","false"),E1("material","The material it is cut from, as material(name = ...) sets it"),E1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),E1("on","The name of a bent part this one is glued to, to move with it"),E1("slots","Names of parts whose tabs pass through this one: their slots are cut"),E1("clearance","Added to the slots, in total across each","0.1"),E1("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),E1("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),E1("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),E1("fit",'Room in the bores: "turn" (0.3 mm on the diameter) for a part that turns on its axle, "press" (-0.1 mm) for one held fast, or a number of mm','"turn"'),E1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),E1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[O("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),O("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[O("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[O("text","What to do in this step",'""'),O("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[O("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),O("from","One end, [x, y, z]; a ball sits midway between from and to"),O("to","The other end, [x, y, z]; a ball may leave it out"),O("size","Diameter, or [width, height] for a flat section","6"),E1("up","The direction a [width, height] section's height points"),E1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),E1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),E1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[O("thickness","Sets $thickness"),O("kerf","Sets $kerf"),O("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[O("size","[width, height]"),O("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),O("finger","Finger width",qe)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[O("length","Length of the edge that plugs in"),O("edge",'"out" or "in", the kind of edge that plugs in','"out"'),O("finger","Finger width",qe)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[O("d","Screw diameter","3"),O("length","Screw length into the panel","12"),O("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),O("nut_at","Distance of the nut from the edge","length / 2")],section:"Joinery",doc:"A T-slot for a screw and nut, opening at y = 0; subtract it from a panel edge"},{name:"living_hinge",kind:"module",params:[O("size","[width, height]"),O("spacing","Distance between the rows of cuts","1.5"),O("bridge","Uncut length between cuts","3"),O("cut","Length of each cut","max(bridge * 2, (height - 3 * bridge) / 2)")],section:"Joinery",doc:"A straight-line flex pattern of cut lines filling [width, height]"},{name:"children",kind:"module",params:[O("index","Which child, from 0, or a list of them")],section:"Other",doc:"Run the child statements passed to the current module"},{name:"echo",kind:"both",params:[],rest:!0,anyNamed:!0,section:"Other",doc:"Write values to the output without making shapes"},{name:"assert",kind:"both",params:[O("condition","Stops the program when false"),O("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},J0("abs","Absolute value"),J0("sign","Sign as -1, 0 or 1"),J0("floor","Round down"),J0("ceil","Round up"),J0("round","Round to the nearest integer, halves away from zero"),J0("sqrt","Square root"),J0("exp","e raised to x"),J0("ln","Natural logarithm"),{name:"log",kind:"function",params:[O("x"),O("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},J0("sin","Sine of an angle in degrees"),J0("cos","Cosine of an angle in degrees"),J0("tan","Tangent of an angle in degrees"),J0("asin","Inverse sine, in degrees"),J0("acos","Inverse cosine, in degrees"),J0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[O("y"),O("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[O("x"),O("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[O("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[O("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[O("x"),O("low"),O("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[O("a"),O("b"),O("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[O("ratio","Turns in for one turn out; under 1 speeds up"),O("stages","Pairs of gears, 1 to 3","2"),O("pinion","Fewest and most teeth of the small gears","[10, 20]"),O("wheel","Fewest and most teeth of the big gears","[20, 80]")],section:"Numbers and vectors",doc:"Tooth counts for a gear train nearest a ratio: {stages = [[driver, driven], ...], ratio, error}"},{name:"norm",kind:"function",params:[O("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[O("a"),O("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[O("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"offset_path",kind:"function",params:[O("points","A list of [x, y] points"),O("d","How far to move it: to the left going along it, or the right when less than 0"),O("closed","The path goes round, its last point joined to its first","false")],section:"Paths and rotations",doc:"The path moved sideways, each corner mitred: the two edges of a strip along a curve"},{name:"bounds",kind:"function",params:[O("points","A list of [x, y] points, or of outlines")],section:"Paths and rotations",doc:"[x0, y0, x1, y1] round the points; undef for none"},{name:"crossings",kind:"function",params:[O("points","A closed outline of [x, y] points, or a list of outlines"),O("x","The vertical line x = this"),O("y","Or the horizontal line y = this")],section:"Paths and rotations",doc:"Where the line crosses the outline: the y (or x) values, smallest first, entering and leaving in turn"},{name:"point_at",kind:"function",params:[O("points","A list of [x, y] points"),O("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[O("points","A list of [x, y] points"),O("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[O("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),O("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[O("points","The [x, y] points the curve goes through"),O("steps","Points between each two given ones","8"),O("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[O("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[O("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[O("x","Where the part's own x axis points"),O("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:k4,section:"Lists and strings",doc:"Number of items in a list, characters in a string or fields in a record"},{name:"keys",kind:"function",params:[O("record","A record, as {name = value}")],section:"Lists and strings",doc:"A record's field names, in the order they were written"},{name:"merge",kind:"function",params:[O("a","A record"),O("b","A record whose fields add to or replace those of a")],section:"Lists and strings",doc:"A record with the fields of a and b, b winning where both have one"},{name:"concat",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Join lists and single values into one list"},{name:"reverse",kind:"function",params:k4,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[O("values","A list of numbers, strings or lists of them"),O("key","A function giving the value to order each item by")],section:"Lists and strings",doc:"The list in order, smallest first; items with equal keys keep their order"},{name:"fold",kind:"function",params:[O("values","A list"),O("initial","The value to start from"),O("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after fn(acc, item) for each item in turn, from initial: initial for an empty list"},{name:"scan",kind:"function",params:[O("values","A list"),O("initial","The value to start from"),O("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after each item as fold() goes: running totals, one per item"},{name:"sum",kind:"function",params:[O("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[O("value","A list or string"),O("start","First index","0"),O("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[O("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[O("text"),O("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[O("values"),O("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[O("value"),O("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[O("value","A list or string"),O("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[O("x"),O("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},m3("is_num","a number other than NaN"),m3("is_string","a string"),m3("is_bool","true or false"),m3("is_list","a list"),m3("is_undef","undef"),m3("is_function","a function"),m3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:k4,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[O("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),O("y",void 0,"0"),O("z","A third axis: step it to get a related but different pattern","0"),E1("seed","A different seed gives a different pattern","1"),E1("octaves","Layers of finer detail, 1 to 8","1")],section:"Random values",doc:"Smooth noise between about -1 and 1 that changes gradually from point to point: 0 at whole numbers, so scale the point down (x / 30) for broad shapes"},{name:"rands",kind:"function",params:[O("min"),O("max"),O("count"),O("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},l7("text_width","The advance width of the text, including spacing"),l7("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),{name:"finger_count",kind:"function",params:[O("length","Edge length"),O("finger","Finger width",qe)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],yr=new Map(Ne.map(t=>[t.name,t])),B3=t=>yr.get(t);function z4(t){let e=t.params.map(n=>n.default===void 0?n.name:`${n.name} = ${n.default}`);return t.rest&&e.push("..."),`${t.name}(${e.join(", ")})`}var P5={"kerf/box":`// kerf/box: finger-jointed boxes.
|
|
8
|
+
`){i(1);continue}if(l==="/"&&t[c+1]==="/"){let f=t.indexOf(`
|
|
9
|
+
`,c),d=f<0?t.length:f,p=/^[ \t]*$/.test(t.slice(t.lastIndexOf(`
|
|
10
|
+
`,c-1)+1,c));r.push({text:t.slice(c+2,d).trim(),line:a,block:!1,own:p,start:c,end:d}),c=d;continue}if(l==="/"&&t[c+1]==="*"){let f=o(),d=t.indexOf("*/",c+2);if(d<0)throw new i1("Unclosed block comment",f);r.push({text:t.slice(c+2,d).trim(),line:f.line,block:!0,own:!0,start:c,end:d+2}),i(d+2-c);continue}let h=o();if(/[0-9]/.test(l)||l==="."&&/[0-9]/.test(t[c+1]??"")){let f=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(t.slice(c));n.push({type:"num",value:f[0],pos:h,end:c+f[0].length}),i(f[0].length);continue}if(/[A-Za-z_$]/.test(l)){let f=/^[A-Za-z_$][A-Za-z0-9_]*/.exec(t.slice(c));n.push({type:"id",value:f[0],pos:h,end:c+f[0].length}),i(f[0].length);continue}if(l==='"'){let f="";for(i(1);c<t.length&&t[c]!=='"';){if(t[c]==="\\"){let d=t[c+1];if(d==="n")f+=`
|
|
11
|
+
`;else if(d==="t")f+=" ";else if(d==="u"){let p=t.slice(c+2,c+6);if(!/^[0-9a-fA-F]{4}$/.test(p))throw new i1("Bad \\u escape",o());f+=String.fromCharCode(parseInt(p,16)),i(4)}else f+=d;i(2);continue}if(t[c]===`
|
|
12
|
+
`)throw new i1("Unclosed string",h);f+=t[c],i(1)}if(c>=t.length)throw new i1("Unclosed string",h);i(1),n.push({type:"str",value:f,pos:h,end:c});continue}if(l==="<"&&/^<[A-Za-z0-9_./\\: -]+>/.test(t.slice(c))){let f=n[n.length-1];if(f&&f.type==="id"&&(f.value==="use"||f.value==="include")){let d=/^<([A-Za-z0-9_./\\: -]+)>/.exec(t.slice(c));n.push({type:"str",value:d[1],pos:h,end:c+d[0].length}),i(d[0].length);continue}}let u=rc.find(f=>t.startsWith(f,c));if(!u)throw new i1(`Unexpected character "${l}"`,h);n.push({type:"punct",value:u,pos:h,end:c+u.length}),i(u.length)}return n.push({type:"eof",value:"",pos:o(),end:c}),{tokens:n,comments:r}}var N2={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"}},Q2={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var K4=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function e2(t,e){let{tokens:n,comments:r}=X3(t,e),c=new Q4(n),a=[];for(;!c.at("eof");)a.push(...c.statement());return{program:{body:a},comments:r}}var $5=class $5{constructor(e){this.tokens=e;this.i=0}peek(e=0){return this.tokens[Math.min(this.i+e,this.tokens.length-1)]}at(e,n,r=0){let c=this.peek(r);return c.type===e&&(n===void 0||c.value===n)}isP(e,n=0){return this.at("punct",e,n)}isK(e,n=0){return this.at("id",e,n)}next(){return this.tokens[this.i++]}fail(e,n=this.peek()){let r=n.type==="eof"?"end of file":`"${n.value}"`;throw new i1(`${e}, found ${r}`,n.pos)}expectP(e){return this.isP(e)||this.fail(`Expected "${e}"`),this.next()}separator(e){this.isP(e)||(this.isP(",")||this.fail(`Expected "," or "${e}"`),this.next())}ident(){let e=this.peek();return(e.type!=="id"||K4.has(e.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let e=this.stmt();for(let n of e)n.end=this.last();return e}stmt(){let e=this.peek();if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let s=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),s.push(...this.statement());return this.next(),[{kind:"block",body:s,pos:e.pos}]}if(this.isK("module")){this.next();let s=this.ident(),o=this.params();return[{kind:"module",name:s.value,params:o,body:this.body(),pos:e.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),o=this.params();this.expectP("=");let i=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:o,body:i,pos:e.pos,namePos:s.pos}]}if(this.isK("use")||this.isK("include")){this.next();let s=this.peek();return s.type!=="str"&&this.fail("Expected a library path like <kerf/box>"),this.next(),this.isP(";")&&this.next(),[{kind:"use",path:s.value,include:e.value==="include",pos:e.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(this.isK("intersection_for")&&this.isP("(",1))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:e.pos,intersect:!0}];if(this.isK("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let o=this.body(),i=[];return this.isK("else")&&(this.next(),i=this.body()),[{kind:"if",cond:s,then:o,else:i,pos:e.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:e.pos}];if(e.type==="id"&&this.isP("=",1)){let s=this.ident().value;this.next();let o=this.peek().pos.offset,i=this.expr(),l=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:i,span:[o,l],pos:e.pos}]}let n=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(n=this.next().value);let r=this.peek();(r.type!=="id"||K4.has(r.value))&&this.fail("Expected a statement"),this.next();let c=this.args(),a=this.body();return[{kind:"call",name:r.value,args:c,children:a,modifier:n,pos:r.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident(),r=null;this.isP("=")&&(this.next(),r=this.expr()),e.push({name:n.value,default:r,pos:n.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let n=this.next();this.next(),e.push({name:n.value,value:this.expr(),pos:n.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let n=this.ident();this.expectP("="),e.push({name:n.value,value:this.expr(),pos:n.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let r=this.params(),c=this.expr();return{kind:"lambda",params:r,body:c,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let r=this.assigns(),c=this.expr();return{kind:"let",assigns:r,body:c,pos:e.pos,end:this.last()}}if(this.at("id")&&(e.value==="assert"||e.value==="echo")&&this.isP("(",1)){let r=this.i;this.next();let c={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:c,body:this.expr(),pos:e.pos};this.i=r}let n=this.binary(0);if(this.isP("?")){this.next();let r=this.expr();this.expectP(":");let c=this.expr();return{kind:"ternary",cond:n,then:r,else:c,pos:e.pos}}return n}binary(e){if(e>=$5.LEVELS.length)return this.unary();let n=this.binary(e+1);for(;this.at("punct")&&$5.LEVELS[e].includes(this.peek().value);){let r=this.next(),c=this.binary(e+1);n={kind:"binary",op:r.value,left:n,right:c,pos:r.pos}}return n}startsValue(){let e=this.peek();return e.type==="num"||e.type==="str"||e.type==="id"?!0:this.isP("[")||this.isP("(")||this.isP("{")||this.isP("!")||this.isP("-")}unary(){if((this.isK("let")||this.isK("function"))&&this.isP("(",1))return this.expr();if(this.isP("-")||this.isP("!")||this.isP("+")){let e=this.next();return{kind:"unary",op:e.value,arg:this.unary(),pos:e.pos}}return this.power()}power(){let e=this.postfix();if(this.isP("^")){let n=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:n.pos}}return e}postfix(){let e=this.primary();for(;;){let n=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let r=this.expr();this.expectP("]"),e={kind:"index",target:e,index:r,pos:n.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:n.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let n=/(mm|cm|m|in|ft)$/.exec(e.value);return n?{kind:"num",value:Number(e.value.slice(0,-n[1].length)),unit:n[1],pos:e.pos}:{kind:"num",value:Number(e.value),pos:e.pos}}if(e.type==="str")return this.next(),{kind:"str",value:e.value,pos:e.pos};if(e.type==="id")return e.value==="true"||e.value==="false"?(this.next(),{kind:"bool",value:e.value==="true",pos:e.pos}):e.value==="undef"?(this.next(),{kind:"undef",pos:e.pos}):(K4.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let n=this.expr();return this.expectP(")"),n}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),n=[];for(;!this.isP("}");){let r=this.ident();if(n.some(c=>c.name===r.value))throw new i1(`Field ${r.value} is given twice`,r.pos);if(this.expectP("="),n.push({name:r.value,value:this.expr(),pos:r.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:n,pos:e.pos}}list(){let e=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:e.pos};if(!this.isK("for")&&!this.isK("if")&&!this.isK("each")&&!(this.isK("let")&&this.isP("(",1))&&!(this.isP("(")&&(this.isK("for",1)||this.isK("if",1)))){let n=this.expr();if(this.isP(":")){this.next();let c=null,a=this.expr();return this.isP(":")&&(this.next(),c=a,a=this.expr()),this.expectP("]"),{kind:"range",start:n,step:c,end:a,pos:e.pos}}let r=[{kind:"item",expr:n}];return this.listRest(r,e.pos)}return this.listRest([],e.pos)}listRest(e,n){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:n};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:n}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"for",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let n=this.expr();this.expectP(")");let r=this.listItem(),c=null;return this.isK("else")&&(this.next(),c=this.listItem()),{kind:"if",cond:n,then:r,else:c}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),r=this.listItem();return{kind:"let",assigns:n,body:r,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let n=this.listItem();return this.expectP(")"),n}return{kind:"item",expr:this.expr()}}};$5.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var Q4=$5;var O=(t,e,n)=>({name:t,...n!==void 0&&{default:n},...e&&{doc:e}}),E1=(t,e,n)=>({...O(t,e,n),named:!0}),et="max(3 * $thickness, 6)",Te=[O("value")],cc=[O("x")],t2=(t,e)=>({name:t,kind:"function",params:cc,section:"Numbers and vectors",doc:e}),M3=(t,e)=>({name:t,kind:"function",params:Te,section:"Types",doc:`Whether the value is ${e}`}),tt=(t,e)=>({name:t,kind:"function",params:[O("text","The text to measure",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),E1("halign","left, center or right",'"left"'),E1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Measure at the size that fits this width, or [width, cap height]")],section:"Text measurements",doc:e}),nt=[{name:"rect",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the rectangle on the origin instead of its corner","false"),E1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[O("size","A number, or [width, height]","1"),O("center","Centre the square on the origin instead of its corner","false"),E1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[O("r","Radius","1"),E1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[O("r","[rx, ry], or one radius for both","1"),E1("d","[width, height], or one diameter for both, instead of r")],section:"Shapes",doc:"An ellipse centred on the origin"},{name:"regular_polygon",kind:"module",params:[O("n","Number of corners","6"),O("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[O("n","Number of points","5"),O("r","Radius of the points","10"),O("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[O("points","A list of [x, y] points"),O("paths","Lists of point indexes, one per outline; holes come from even-odd fill")],section:"Shapes",doc:"A shape from a list of points"},{name:"path",kind:"module",params:[O("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),E1("fill",'"evenodd" or "nonzero"','"evenodd"'),E1("close","Close every open subpath into an area","false")],section:"Shapes",doc:"Shapes from SVG path data: closed subpaths become areas, open ones lines"},{name:"text",kind:"module",params:[O("text","The text",'""'),O("size","Font size in millimetres","10"),O("font","Font name","$font"),E1("halign","left, center or right",'"left"'),E1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),E1("spacing","Letter spacing factor","1"),E1("fit","Shrink the size so the text is no wider than this, or fits [width, cap height]"),E1("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),E1("bridge","Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[O("from","Start point","[0, 0]"),O("to","End point","[10, 0]"),O("width","Make a strip this wide, an area, instead of a line")],section:"Shapes",doc:"A straight line, or with a width a strip between the points"},{name:"polyline",kind:"module",params:[O("points","A list of [x, y] points"),O("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[O("r","Radius","10"),O("start","Start angle in degrees","0"),O("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[O("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[O("a","Angle in degrees, anticlockwise","0"),E1("center","The point to turn around, [x, y]")],children:!0,section:"Transforms",doc:"Rotate the children around the origin or a point"},{name:"scale",kind:"module",params:[O("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[O("v","[nx, ny], perpendicular to the mirror line","[1, 0]")],children:!0,section:"Transforms",doc:"Reflect the children across a line through the origin"},{name:"multmatrix",kind:"module",params:[O("m","A 2 \xD7 3 or 3 \xD7 3 matrix")],children:!0,section:"Transforms",doc:"Apply a transformation matrix to the children"},{name:"union",kind:"module",params:[],children:!0,section:"Combining",doc:"Join the children"},{name:"group",kind:"module",params:[],children:!0,section:"Combining",doc:"Another name for union()"},{name:"difference",kind:"module",params:[],children:!0,section:"Combining",doc:"Remove every later child's area from every layer of the first child"},{name:"intersection",kind:"module",params:[],children:!0,section:"Combining",doc:"Keep only the area common to all children"},{name:"hull",kind:"module",params:[],children:!0,section:"Combining",doc:"The convex hull of the children; each part inside gets its own"},{name:"offset",kind:"module",params:[O("r","Grow (positive) or shrink areas with rounded corners"),E1("delta","Grow or shrink areas with sharp corners","0"),E1("chamfer","Cut the corners off when growing by delta","false")],children:!0,section:"Combining",doc:"Grow or shrink the areas of the children"},{name:"pattern",kind:"module",params:[O("spacing","Distance between copies, a number or [x, y]","10"),O("stagger","Shift of every other row, as a share of the x spacing","0")],children:!0,section:"Combining",doc:"Repeat the first child over the area of the others, clipping copies at its edge"},{name:"spline",kind:"module",params:[O("points","The [x, y] points the curve goes through"),O("width","Make an area this wide along the curve, instead of a line"),E1("steps","Points between each two given ones","8"),E1("closed","Join the curve back to its start","false")],section:"Shapes",doc:"A smooth curve through points: a line, or with a width an area"},{name:"hatch",kind:"module",params:[O("angle","Direction of the lines, in degrees from +x","45"),O("pitch","Distance between the lines","5"),O("width","Make stripes this wide, areas, instead of lines")],children:!0,section:"Combining",doc:"Parallel lines or stripes across the area of the children"},{name:"flow",kind:"module",params:[O("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),O("spacing","Distance between neighbouring lines","2"),O("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),E1("min_length","Lines shorter than this are left out","spacing * 2"),E1("seed","Where the first lines start; another seed gives another arrangement","1")],children:!0,section:"Combining",doc:"Evenly spaced lines that follow a direction field across the area of the children, never closer than half the spacing"},{name:"contours",kind:"module",params:[O("field","The height at a point: function(p) giving a number, or undef for none"),O("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),E1("interval","Instead of levels: every multiple of this height"),E1("cell","Distance between the points sampled: smaller is finer and slower","1")],children:!0,section:"Combining",doc:"Contour lines where a height field crosses each level, across the area of the children"},{name:"occlude",kind:"module",params:[],children:!0,section:"Combining",doc:"Children back to front, each opaque: lines and outlines hide behind the areas of later children, and fills lose that area. Each iteration of a for loop is a child of its own"},{name:"hide",kind:"module",params:[],children:!0,section:"Combining",doc:"Inside occlude(): an area that hides what is behind it but is not drawn"},{name:"paint",kind:"module",params:[O("layers",'A layer for each child; "" leaves that child out')],children:!0,section:"Combining",doc:"Painter's order: each child loses the area of the children after it"},{name:"measure",kind:"module",params:[O("draw","Draw the first child too","false")],children:!0,section:"Combining",doc:"Set $bounds = [x0, y0, x1, y1], $area and $centroid = [x, y] of the first child for the children after it"},{name:"fill_holes",kind:"module",params:[O("min_area","Fill only holes smaller than this many square millimetres")],children:!0,section:"Combining",doc:"Fill the holes in the areas of the children"},{name:"join_islands",kind:"module",params:[O("width","How wide each joining strip is","1")],children:!0,section:"Combining",doc:"Join every separate piece of the material to the nearest other piece with a strip, until it is one piece"},{name:"largest",kind:"module",params:[O("n","How many pieces to keep","1")],children:!0,section:"Combining",doc:"Keep the n biggest connected pieces of the material, dropping crumbs; marks stay as drawn"},{name:"close",kind:"module",params:[O("r","Close gaps and notches narrower than twice this","0.5")],children:!0,section:"Combining",doc:"Close narrow gaps between and in the areas of the children"},{name:"stroke",kind:"module",params:[O("width","Width of the area around each line","1")],children:!0,section:"Combining",doc:"Turn lines into areas, for cutting single-line art"},{name:"outline",kind:"module",params:[],children:!0,section:"Combining",doc:"Turn areas into their outline lines"},{name:"cut",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the cut layer"},{name:"score",kind:"module",params:[O("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the score layer: lines marked without cutting through"},{name:"engrave",kind:"module",params:[O("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on the engrave layer: areas filled in"},{name:"guide",kind:"module",params:[],children:!0,section:"Layers",doc:"Put the children on the guide layer, which is not cut"},{name:"layer",kind:"module",params:[O("name","Layer name"),O("mode",'"cut", "line", "fill" or "guide"'),O("color",'Colour in the output, as "#00aa00"'),E1("order","Where it goes among the custom layers in the files, lowest first","0"),E1("bleed","How far past the part's edge it may print","0"),E1("side",'"front", or "back" for the face underneath, made after turning the part over','"front"')],children:!0,section:"Layers",doc:"Put the children on a layer, defining it on first use"},{name:"part",kind:"module",params:[O("name","Part name",'"part"'),O("qty","Number of copies to cut","1"),E1("at","Where the part goes in the assembled view, [x, y, z]"),E1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),E1("stack","Layers glued in a stack at each placement, one thickness apart","1"),E1("mirror","Cut the part mirrored left to right, its text still reading","false"),E1("material","The material it is cut from, as material(name = ...) sets it"),E1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),E1("on","The name of a bent part this one is glued to, to move with it"),E1("slots","Names of parts whose tabs pass through this one: their slots are cut"),E1("clearance","Added to the slots, in total across each","0.1"),E1("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),E1("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),E1("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),E1("fit",'Room in the bores: "turn" (0.3 mm on the diameter) for a part that turns on its axle, "press" (-0.1 mm) for one held fast, or a number of mm','"turn"'),E1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),E1("face",'The face of the glue part it goes on: "top" or "bottom"','"top"')],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[O("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),O("rotate","How they are turned, [x, y, z] in degrees","[0, 0, 0]")],children:!0,section:"Parts and sheets",doc:"Place the parts inside in the assembled view, with their own placements inside this one"},{name:"call",kind:"module",params:[O("name",'The name of a module, as "roses"')],rest:!0,children:!0,section:"Other",doc:"Calls the module of that name with the other arguments and the children, so a table can carry which module draws each entry"},{name:"step",kind:"module",params:[O("text","What to do in this step",'""'),O("substeps","Steps inside it become its sub-steps; false adds them to this one","true")],children:!0,section:"Parts and sheets",doc:'An assembly step: the parts and hardware inside are added in it, in order. A step inside a step is a sub-step, named "outer: inner"'},{name:"hardware",kind:"module",params:[O("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),O("from","One end, [x, y, z]; a ball sits midway between from and to"),O("to","The other end, [x, y, z]; a ball may leave it out"),O("size","Diameter, or [width, height] for a flat section","6"),E1("up","The direction a [width, height] section's height points"),E1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),E1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),E1("label","The name in the hardware list")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"material",kind:"module",params:[O("thickness","Sets $thickness"),O("kerf","Sets $kerf"),O("name","Sets $material")],children:!0,section:"Parts and sheets",doc:"Set the thickness, kerf and material name for the children"},{name:"finger_rect",kind:"module",params:[O("size","[width, height]"),O("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),O("finger","Finger width",et)],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",et)],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"},t2("abs","Absolute value"),t2("sign","Sign as -1, 0 or 1"),t2("floor","Round down"),t2("ceil","Round up"),t2("round","Round to the nearest integer, halves away from zero"),t2("sqrt","Square root"),t2("exp","e raised to x"),t2("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"},t2("sin","Sine of an angle in degrees"),t2("cos","Cosine of an angle in degrees"),t2("tan","Tangent of an angle in degrees"),t2("asin","Inverse sine, in degrees"),t2("acos","Inverse cosine, in degrees"),t2("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[O("y"),O("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[O("x"),O("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[O("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The smallest of a list, or of several values"},{name:"max",kind:"function",params:[O("values","A list, or the first of several values")],rest:!0,section:"Numbers and vectors",doc:"The largest of a list, or of several values"},{name:"clamp",kind:"function",params:[O("x"),O("low"),O("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[O("a"),O("b"),O("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[O("ratio","Turns in for one turn out; under 1 speeds up"),O("stages","Pairs of gears, 1 to 3","2"),O("pinion","Fewest and most teeth of the small gears","[10, 20]"),O("wheel","Fewest and most teeth of the big gears","[20, 80]")],section:"Numbers and vectors",doc:"Tooth counts for a gear train nearest a ratio: {stages = [[driver, driven], ...], ratio, error}"},{name:"norm",kind:"function",params:[O("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[O("a"),O("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[O("points","A list of [x, y] points")],section:"Paths and rotations",doc:"The length of the lines through a list of points"},{name:"offset_path",kind:"function",params:[O("points","A list of [x, y] points"),O("d","How far to move it: to the left going along it, or the right when less than 0"),O("closed","The path goes round, its last point joined to its first","false")],section:"Paths and rotations",doc:"The path moved sideways, each corner mitred: the two edges of a strip along a curve"},{name:"bounds",kind:"function",params:[O("points","A list of [x, y] points, or of outlines")],section:"Paths and rotations",doc:"[x0, y0, x1, y1] round the points; undef for none"},{name:"crossings",kind:"function",params:[O("points","A closed outline of [x, y] points, or a list of outlines"),O("x","The vertical line x = this"),O("y","Or the horizontal line y = this")],section:"Paths and rotations",doc:"Where the line crosses the outline: the y (or x) values, smallest first, entering and leaving in turn"},{name:"point_at",kind:"function",params:[O("points","A list of [x, y] points"),O("s","Distance along the path")],section:"Paths and rotations",doc:"The point a distance along a path; past either end it carries on straight"},{name:"heading_at",kind:"function",params:[O("points","A list of [x, y] points"),O("s","Distance along the path")],section:"Paths and rotations",doc:"The direction of a path a distance along it, in degrees from +x"},{name:"path_points",kind:"function",params:[O("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),O("tolerance","How far curves may stray from their points","0.05")],section:"Paths and rotations",doc:"The points of SVG path data: one list of points for each subpath"},{name:"spline_points",kind:"function",params:[O("points","The [x, y] points the curve goes through"),O("steps","Points between each two given ones","8"),O("closed","Join the curve back to its start","false")],section:"Paths and rotations",doc:"The points of a smooth curve through points, as spline() draws it"},{name:"rotation",kind:"function",params:[O("angles","[x, y, z] in degrees, as part() turns")],section:"Paths and rotations",doc:"The 3x3 matrix of a rotation; matrices multiply with *"},{name:"euler",kind:"function",params:[O("matrix","A 3x3 rotation matrix")],section:"Paths and rotations",doc:"The [x, y, z] angles of a rotation matrix, for part()'s rotate"},{name:"orient",kind:"function",params:[O("x","Where the part's own x axis points"),O("z","Where its z axis, out of its top face, points","[0, 0, 1]")],section:"Paths and rotations",doc:"The rotate angles that turn a part's x and z axes onto two directions"},{name:"len",kind:"function",params:Te,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:Te,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[O("values","A list of numbers, strings or lists of them"),O("key","A function giving the value to order each item by")],section:"Lists and strings",doc:"The list in order, smallest first; items with equal keys keep their order"},{name:"fold",kind:"function",params:[O("values","A list"),O("initial","The value to start from"),O("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after fn(acc, item) for each item in turn, from initial: initial for an empty list"},{name:"scan",kind:"function",params:[O("values","A list"),O("initial","The value to start from"),O("fn","A function(acc, item) giving the next value")],section:"Lists and strings",doc:"The value after each item as fold() goes: running totals, one per item"},{name:"sum",kind:"function",params:[O("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[O("value","A list or string"),O("start","First index","0"),O("end","Index after the last; the length when left out")],section:"Lists and strings",doc:"Part of a list or string"},{name:"str",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Values as text, joined"},{name:"chr",kind:"function",params:[],rest:!0,section:"Lists and strings",doc:"Text from Unicode code points"},{name:"ord",kind:"function",params:[O("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[O("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[O("text"),O("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[O("values"),O("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[O("value"),O("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[O("value","A list or string"),O("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[O("x"),O("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},M3("is_num","a number other than NaN"),M3("is_string","a string"),M3("is_bool","true or false"),M3("is_list","a list"),M3("is_undef","undef"),M3("is_function","a function"),M3("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:Te,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[O("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),O("y",void 0,"0"),O("z","A third axis: step it to get a related but different pattern","0"),E1("seed","A different seed gives a different pattern","1"),E1("octaves","Layers of finer detail, 1 to 8","1")],section:"Random values",doc:"Smooth noise between about -1 and 1 that changes gradually from point to point: 0 at whole numbers, so scale the point down (x / 30) for broad shapes"},{name:"rands",kind:"function",params:[O("min"),O("max"),O("count"),O("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},tt("text_width","The advance width of the text, including spacing"),tt("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),tt("text_size","The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"),{name:"finger_count",kind:"function",params:[O("length","Edge length"),O("finger","Finger width",et)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],ac=new Map(nt.map(t=>[t.name,t])),Z3=t=>ac.get(t);function Ie(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 R5={"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.
|
|
@@ -1546,6 +1546,330 @@ module ring_stack(diameters, hole, name = "ring", count = undef, feet = true, cl
|
|
|
1546
1546
|
translate([-(t + clearance) / 2, -t - 1]) rect([t + clearance, h / 2 + t + 1]);
|
|
1547
1547
|
}
|
|
1548
1548
|
}
|
|
1549
|
+
`,"kerf/shapes":`// kerf/shapes: basic shapes by name, sized to a box.
|
|
1550
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1551
|
+
//
|
|
1552
|
+
// Hearts, teardrops, clouds, shields, banners, arrows and the other shapes
|
|
1553
|
+
// that signs, tags, ornaments and boxes are made of. Each takes its size as
|
|
1554
|
+
// [w, h] (or one number for both) and is centred on the origin, as circle()
|
|
1555
|
+
// and ellipse() are; arrows and chevrons point along x, the others stand
|
|
1556
|
+
// upright. A shape with one outline also has a _points() function giving
|
|
1557
|
+
// that outline, counter-clockwise, for offset_path(), flex_strip() and
|
|
1558
|
+
// anything else that works on points. Curves follow $fn when it is set,
|
|
1559
|
+
// and otherwise take about a point per millimetre.
|
|
1560
|
+
|
|
1561
|
+
use <kerf/fit>
|
|
1562
|
+
|
|
1563
|
+
// [w, h] from a number or a pair, checked
|
|
1564
|
+
function shape_size(size, what) =
|
|
1565
|
+
let (s = is_list(size) ? size : [size, size])
|
|
1566
|
+
assert(
|
|
1567
|
+
len(s) == 2 && is_num(s[0]) && is_num(s[1]) && s[0] > 0 && s[1] > 0,
|
|
1568
|
+
str(what, "(): size must be more than 0, as a number or [w, h]")
|
|
1569
|
+
)
|
|
1570
|
+
s;
|
|
1571
|
+
|
|
1572
|
+
// How many points a curve about \`length\` mm long is drawn with
|
|
1573
|
+
function shape_steps(length) = $fn > 0 ? max(3, $fn) : clamp(ceil(length), 32, 200);
|
|
1574
|
+
|
|
1575
|
+
// The points scaled to fill the box [w, h], centred on the origin
|
|
1576
|
+
function shape_fill(points, s) =
|
|
1577
|
+
let (b = bounds(points), c = [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2], kx = s[0] / (b[2] - b[0]), ky = s[1] / (b[3] - b[1]))
|
|
1578
|
+
[for (p = points) [(p[0] - c[0]) * kx, (p[1] - c[1]) * ky]];
|
|
1579
|
+
|
|
1580
|
+
// The points moved so their box is centred on the origin
|
|
1581
|
+
function shape_centre(points) =
|
|
1582
|
+
let (b = bounds(points), c = [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2])
|
|
1583
|
+
[for (p = points) p - c];
|
|
1584
|
+
|
|
1585
|
+
// Points along an arc round \`c\` of radius r, from angle a0 to a1, the first
|
|
1586
|
+
// and last included
|
|
1587
|
+
function shape_arc(c, r, a0, a1, n) = [for (i = [0:n]) let (a = a0 + (a1 - a0) * i / n) c + r * [cos(a), sin(a)]];
|
|
1588
|
+
|
|
1589
|
+
// A heart: two round lobes meeting in a dip, and a point at the bottom
|
|
1590
|
+
module heart(size = 20) polygon(heart_points(size));
|
|
1591
|
+
|
|
1592
|
+
// The outline of heart(), as points
|
|
1593
|
+
function heart_points(size = 20) =
|
|
1594
|
+
let (s = shape_size(size, "heart"), n = shape_steps(1.7 * (s[0] + s[1])))
|
|
1595
|
+
shape_fill([for (i = [0:n - 1]) let (a = -360 * i / n) [16 * pow(sin(a), 3), 13 * cos(a) - 5 * cos(2 * a) - 2 * cos(3 * a) - cos(4 * a)]], s);
|
|
1596
|
+
|
|
1597
|
+
// A drop: round at the bottom, coming to a point at the top. It must be
|
|
1598
|
+
// taller than it is wide.
|
|
1599
|
+
module teardrop(size = [14, 20]) polygon(teardrop_points(size));
|
|
1600
|
+
|
|
1601
|
+
// The outline of teardrop(), as points
|
|
1602
|
+
function teardrop_points(size = [14, 20]) =
|
|
1603
|
+
let (
|
|
1604
|
+
s = shape_size(size, "teardrop"),
|
|
1605
|
+
r = s[0] / 2,
|
|
1606
|
+
d = s[1] - r
|
|
1607
|
+
)
|
|
1608
|
+
assert(s[1] > s[0], "teardrop(): make it taller than it is wide")
|
|
1609
|
+
let (
|
|
1610
|
+
t = acos(r / d),
|
|
1611
|
+
n = shape_steps(PI * s[0])
|
|
1612
|
+
)
|
|
1613
|
+
[for (p = concat([[0, s[1]]], shape_arc([0, r], r, 90 + t, 450 - t, n))) p - [0, s[1] / 2]];
|
|
1614
|
+
|
|
1615
|
+
// An egg standing on its broad end; \`taper\` is how much narrower the top
|
|
1616
|
+
// is, 0 for an ellipse
|
|
1617
|
+
module egg(size = [16, 20], taper = 0.2) polygon(egg_points(size, taper));
|
|
1618
|
+
|
|
1619
|
+
// The outline of egg(), as points
|
|
1620
|
+
function egg_points(size = [16, 20], taper = 0.2) =
|
|
1621
|
+
let (s = shape_size(size, "egg"), n = shape_steps(1.6 * (s[0] + s[1])))
|
|
1622
|
+
assert(taper >= 0 && taper < 1, "egg(): taper is from 0 up to 1")
|
|
1623
|
+
shape_fill([for (i = [0:n - 1]) let (a = 360 * i / n) [cos(a) * (1 - taper * sin(a)), sin(a)]], s);
|
|
1624
|
+
|
|
1625
|
+
// A lens (a leaf, a petal, an eye): two arcs meeting in a point at each
|
|
1626
|
+
// end of its longer side, the top and bottom of a tall one, the left and
|
|
1627
|
+
// right of a wide one
|
|
1628
|
+
module lens(size = [10, 20]) polygon(lens_points(size));
|
|
1629
|
+
|
|
1630
|
+
// The outline of lens(), as points
|
|
1631
|
+
function lens_points(size = [10, 20]) =
|
|
1632
|
+
let (s = shape_size(size, "lens"))
|
|
1633
|
+
// A wide lens is a tall one turned a quarter turn, so its arcs stay less
|
|
1634
|
+
// than half circles and its ends pointed
|
|
1635
|
+
s[0] > s[1] ? [for (p = shape_tall_lens([s[1], s[0]])) [p[1], -p[0]]] : shape_tall_lens(s);
|
|
1636
|
+
|
|
1637
|
+
// A lens with its points at the top and the bottom, no wider than tall
|
|
1638
|
+
function shape_tall_lens(s) =
|
|
1639
|
+
let (
|
|
1640
|
+
g = s[0] / 2,
|
|
1641
|
+
R = g / 2 + s[1] * s[1] / (8 * g),
|
|
1642
|
+
t = asin(min(1, s[1] / 2 / R)),
|
|
1643
|
+
// even, so a point falls on the widest place
|
|
1644
|
+
n = 2 * max(2, ceil(shape_steps(PI * (s[0] + s[1]) / 2) / 4))
|
|
1645
|
+
)
|
|
1646
|
+
concat(shape_arc([g - R, 0], R, -t, t, n), [for (p = shape_arc([R - g, 0], R, 180 - t, 180 + t, n)) if (abs(p[1]) < s[1] / 2 - 1e-9) p]);
|
|
1647
|
+
|
|
1648
|
+
// A crescent moon \`d\` across, open to the right, \`thickness\` at its widest
|
|
1649
|
+
module crescent(d = 20, thickness) polygon(crescent_points(d, thickness));
|
|
1650
|
+
|
|
1651
|
+
// The outline of crescent(), as points
|
|
1652
|
+
function crescent_points(d = 20, thickness) =
|
|
1653
|
+
let (
|
|
1654
|
+
R = d / 2,
|
|
1655
|
+
t = is_undef(thickness) ? d / 4 : thickness
|
|
1656
|
+
)
|
|
1657
|
+
assert(is_num(d) && d > 0, "crescent(): d must be more than 0")
|
|
1658
|
+
assert(t > 0 && t < d, "crescent(): thickness must be more than 0 and less than d")
|
|
1659
|
+
let (
|
|
1660
|
+
Y = sqrt(R * R - t * t / 4),
|
|
1661
|
+
a = atan2(Y, t / 2),
|
|
1662
|
+
b = atan2(Y, -t / 2),
|
|
1663
|
+
n = shape_steps(PI * d)
|
|
1664
|
+
)
|
|
1665
|
+
shape_centre(concat(
|
|
1666
|
+
shape_arc([0, 0], R, a, 360 - a, n),
|
|
1667
|
+
[for (i = [1:n - 1]) let (q = 360 - b - (360 - 2 * b) * i / n) [t, 0] + R * [cos(q), sin(q)]]
|
|
1668
|
+
));
|
|
1669
|
+
|
|
1670
|
+
// A rectangle with round ends (a stadium, a pill)
|
|
1671
|
+
module capsule(size = [30, 10]) polygon(capsule_points(size));
|
|
1672
|
+
|
|
1673
|
+
// The outline of capsule(), as points
|
|
1674
|
+
function capsule_points(size = [30, 10]) =
|
|
1675
|
+
let (
|
|
1676
|
+
s = shape_size(size, "capsule"),
|
|
1677
|
+
r = min(s) / 2,
|
|
1678
|
+
c = s[0] >= s[1] ? [s[0] / 2 - r, 0] : [0, s[1] / 2 - r],
|
|
1679
|
+
a = s[0] >= s[1] ? -90 : 0,
|
|
1680
|
+
n = ceil(shape_steps(PI * r * 2) / 2)
|
|
1681
|
+
)
|
|
1682
|
+
concat(shape_arc(c, r, a, a + 180, n), shape_arc(-c, r, a + 180, a + 360, n));
|
|
1683
|
+
|
|
1684
|
+
// A diamond (a rhombus) touching the middle of each side of its box
|
|
1685
|
+
module diamond(size = [14, 20]) polygon(diamond_points(size));
|
|
1686
|
+
|
|
1687
|
+
// The outline of diamond(), as points
|
|
1688
|
+
function diamond_points(size = [14, 20]) =
|
|
1689
|
+
let (s = shape_size(size, "diamond") / 2) [[0, -s[1]], [s[0], 0], [0, s[1]], [-s[0], 0]];
|
|
1690
|
+
|
|
1691
|
+
// A regular polygon with \`n\` corners \`r\` from its centre, as
|
|
1692
|
+
// regular_polygon(n, r), each rounded with radius \`round\`
|
|
1693
|
+
module rounded_polygon(n = 6, r = 10, round = 2) polygon(rounded_polygon_points(n, r, round));
|
|
1694
|
+
|
|
1695
|
+
// The outline of rounded_polygon(), as points
|
|
1696
|
+
function rounded_polygon_points(n = 6, r = 10, round = 2) =
|
|
1697
|
+
assert(is_num(n) && n >= 3, "rounded_polygon(): n must be 3 or more")
|
|
1698
|
+
assert(r > 0, "rounded_polygon(): r must be more than 0")
|
|
1699
|
+
assert(round >= 0 && round < r * cos(180 / n), "rounded_polygon(): round must be less than the distance to a side")
|
|
1700
|
+
let (
|
|
1701
|
+
k = floor(n),
|
|
1702
|
+
c = r - round / cos(180 / k),
|
|
1703
|
+
m = round > 0 ? max(2, ceil(shape_steps(2 * PI * round) / k)) : 0
|
|
1704
|
+
)
|
|
1705
|
+
[for (i = [0:k - 1]) let (a = 360 * i / k)
|
|
1706
|
+
each (round > 0 ? shape_arc(c * [cos(a), sin(a)], round, a - 180 / k, a + 180 / k, m) : [r * [cos(a), sin(a)]])];
|
|
1707
|
+
|
|
1708
|
+
// A shield: a flat top, straight sides, curving in to a point at the
|
|
1709
|
+
// bottom. \`point\` is how much of the height the curved part takes.
|
|
1710
|
+
module shield(size = [16, 20], point = 0.55) polygon(shield_points(size, point));
|
|
1711
|
+
|
|
1712
|
+
// The outline of shield(), as points
|
|
1713
|
+
function shield_points(size = [16, 20], point = 0.55) =
|
|
1714
|
+
let (s = shape_size(size, "shield"), w = s[0] / 2, top = s[1] / 2)
|
|
1715
|
+
assert(point > 0 && point <= 1, "shield(): point is more than 0, up to 1")
|
|
1716
|
+
let (
|
|
1717
|
+
yk = top - s[1] * (1 - point),
|
|
1718
|
+
n = shape_steps(s[1] * point),
|
|
1719
|
+
side = function(u) [w * (1 - u * u), yk - (yk + top) * u]
|
|
1720
|
+
)
|
|
1721
|
+
concat(
|
|
1722
|
+
[[-w, top]],
|
|
1723
|
+
[for (i = [0:n]) let (p = side(i / n)) [-p[0], p[1]]],
|
|
1724
|
+
[for (i = [n - 1:-1:0]) side(i / n)],
|
|
1725
|
+
[[w, top]]
|
|
1726
|
+
);
|
|
1727
|
+
|
|
1728
|
+
// An arrow pointing along x: \`size\` is its length and the head's width,
|
|
1729
|
+
// \`shaft\` the shaft's width and \`head\` the head's length
|
|
1730
|
+
module arrow(size = [30, 14], shaft, head) polygon(arrow_points(size, shaft, head));
|
|
1731
|
+
|
|
1732
|
+
// The outline of arrow(), as points
|
|
1733
|
+
function arrow_points(size = [30, 14], shaft, head) =
|
|
1734
|
+
let (
|
|
1735
|
+
s = shape_size(size, "arrow"),
|
|
1736
|
+
L = s[0] / 2,
|
|
1737
|
+
W = s[1] / 2,
|
|
1738
|
+
sw = is_undef(shaft) ? s[1] / 3 : shaft,
|
|
1739
|
+
hl = is_undef(head) ? min(s[0] / 2, s[1]) : head
|
|
1740
|
+
)
|
|
1741
|
+
assert(sw > 0 && sw <= s[1], "arrow(): shaft must be more than 0 and no wider than the head")
|
|
1742
|
+
assert(hl > 0 && hl <= s[0], "arrow(): head must be more than 0 and no longer than the arrow")
|
|
1743
|
+
[[-L, -sw / 2], [L - hl, -sw / 2], [L - hl, -W], [L, 0], [L - hl, W], [L - hl, sw / 2], [-L, sw / 2]];
|
|
1744
|
+
|
|
1745
|
+
// A chevron (>) pointing along x, \`thickness\` across each arm along x
|
|
1746
|
+
module chevron(size = [12, 20], thickness) polygon(chevron_points(size, thickness));
|
|
1747
|
+
|
|
1748
|
+
// The outline of chevron(), as points
|
|
1749
|
+
function chevron_points(size = [12, 20], thickness) =
|
|
1750
|
+
let (
|
|
1751
|
+
s = shape_size(size, "chevron"),
|
|
1752
|
+
w = s[0] / 2,
|
|
1753
|
+
h = s[1] / 2,
|
|
1754
|
+
t = is_undef(thickness) ? s[0] / 2 : thickness
|
|
1755
|
+
)
|
|
1756
|
+
assert(t > 0 && t < s[0], "chevron(): thickness must be more than 0 and less than the width")
|
|
1757
|
+
[[-w, -h], [-w + t, -h], [w, 0], [-w + t, h], [-w, h], [w - t, 0]];
|
|
1758
|
+
|
|
1759
|
+
// A banner with a V cut \`notch\` deep into each end
|
|
1760
|
+
module banner(size = [60, 16], notch) polygon(banner_points(size, notch));
|
|
1761
|
+
|
|
1762
|
+
// The outline of banner(), as points
|
|
1763
|
+
function banner_points(size = [60, 16], notch) =
|
|
1764
|
+
let (
|
|
1765
|
+
s = shape_size(size, "banner"),
|
|
1766
|
+
w = s[0] / 2,
|
|
1767
|
+
h = s[1] / 2,
|
|
1768
|
+
v = is_undef(notch) ? s[1] / 3 : notch
|
|
1769
|
+
)
|
|
1770
|
+
assert(v >= 0 && v < s[0] / 2, "banner(): notch must be less than half the width")
|
|
1771
|
+
[[-w, -h], [w, -h], [w - v, 0], [w, h], [-w, h], [-w + v, 0]];
|
|
1772
|
+
|
|
1773
|
+
// A house: walls and a pitched roof \`roof\` tall
|
|
1774
|
+
module house(size = [20, 24], roof) polygon(house_points(size, roof));
|
|
1775
|
+
|
|
1776
|
+
// The outline of house(), as points
|
|
1777
|
+
function house_points(size = [20, 24], roof) =
|
|
1778
|
+
let (
|
|
1779
|
+
s = shape_size(size, "house"),
|
|
1780
|
+
w = s[0] / 2,
|
|
1781
|
+
h = s[1] / 2,
|
|
1782
|
+
rf = is_undef(roof) ? s[0] / 2 : roof
|
|
1783
|
+
)
|
|
1784
|
+
assert(rf > 0 && rf < s[1], "house(): roof must be more than 0 and less than the height")
|
|
1785
|
+
[[-w, -h], [w, -h], [w, h - rf], [0, h], [-w, h - rf]];
|
|
1786
|
+
|
|
1787
|
+
// A gift or luggage tag: its left end's corners cut off by \`cut\`, with a
|
|
1788
|
+
// hole \`hole\` across near that end (0 for none)
|
|
1789
|
+
module tag(size = [50, 25], cut, hole) {
|
|
1790
|
+
s = shape_size(size, "tag");
|
|
1791
|
+
hd = is_undef(hole) ? s[1] / 4 : hole;
|
|
1792
|
+
difference() {
|
|
1793
|
+
polygon(tag_points(size, cut));
|
|
1794
|
+
if (hd > 0) translate([-s[0] / 2 + s[1] / 3, 0]) circle(d = hd);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
// The outline of tag(), without its hole, as points
|
|
1799
|
+
function tag_points(size = [50, 25], cut) =
|
|
1800
|
+
let (
|
|
1801
|
+
s = shape_size(size, "tag"),
|
|
1802
|
+
w = s[0] / 2,
|
|
1803
|
+
h = s[1] / 2,
|
|
1804
|
+
c = is_undef(cut) ? s[1] / 4 : cut
|
|
1805
|
+
)
|
|
1806
|
+
assert(c >= 0 && c < min(s[0], s[1] / 2), "tag(): cut must be less than half the height")
|
|
1807
|
+
[[-w + c, -h], [w, -h], [w, h], [-w + c, h], [-w, h - c], [-w, -h + c]];
|
|
1808
|
+
|
|
1809
|
+
// A ring \`d\` across, its band \`width\` wide
|
|
1810
|
+
module ring(d = 20, width = 3) {
|
|
1811
|
+
assert(is_num(d) && d > 0, "ring(): d must be more than 0");
|
|
1812
|
+
assert(width > 0 && width < d / 2, "ring(): width must be more than 0 and less than half of d");
|
|
1813
|
+
difference() {
|
|
1814
|
+
circle(d = d);
|
|
1815
|
+
circle(d = d - 2 * width);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
// A circle \`d\` across with \`n\` round scallops round its edge
|
|
1820
|
+
module scalloped(d = 30, n = 16) {
|
|
1821
|
+
assert(is_num(d) && d > 0, "scalloped(): d must be more than 0");
|
|
1822
|
+
assert(n >= 3, "scalloped(): n must be 3 or more");
|
|
1823
|
+
k = sin(180 / n);
|
|
1824
|
+
rb = d / 2 / (1 + k);
|
|
1825
|
+
union() {
|
|
1826
|
+
circle(r = rb);
|
|
1827
|
+
for (i = [0:n - 1]) rotate(360 * i / n) translate([rb, 0]) circle(r = rb * k);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// A flower \`d\` across with \`petals\` petals round a round middle \`center\`
|
|
1832
|
+
// of d across
|
|
1833
|
+
module flower(d = 30, petals = 6, center = 0.35) {
|
|
1834
|
+
assert(is_num(d) && d > 0, "flower(): d must be more than 0");
|
|
1835
|
+
assert(petals >= 3, "flower(): petals must be 3 or more");
|
|
1836
|
+
assert(center > 0 && center < 1, "flower(): center is a part of d, more than 0 and less than 1");
|
|
1837
|
+
pl = d / 2 * (1 - center / 3);
|
|
1838
|
+
rc = d / 2 - pl / 2;
|
|
1839
|
+
pw = min(pl, 2.2 * rc * sin(180 / petals));
|
|
1840
|
+
union() {
|
|
1841
|
+
circle(d = d * center);
|
|
1842
|
+
for (i = [0:petals - 1]) rotate(90 + 360 * i / petals) translate([rc, 0]) ellipse(d = [pl, pw]);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// A cloud: a flat bottom with \`puffs\` round puffs along the top
|
|
1847
|
+
module cloud(size = [40, 24], puffs = 3) {
|
|
1848
|
+
s = shape_size(size, "cloud");
|
|
1849
|
+
assert(puffs >= 1, "cloud(): puffs must be 1 or more");
|
|
1850
|
+
fit(s, mode = "stretch", anchor = "center") union() {
|
|
1851
|
+
translate([0.08, 0]) rect([0.84, 0.3], r = 0.15);
|
|
1852
|
+
for (i = [0:puffs - 1]) let (f = (i + 0.5) / puffs, rise = sin(180 * f), r = (0.3 + 0.2 * rise) / max(1, puffs / 2.2))
|
|
1853
|
+
translate([0.12 + 0.76 * f, 0.18 + 0.32 * rise]) circle(r = r, $fn = shape_steps(150));
|
|
1854
|
+
translate([0.12, 0.17]) circle(r = 0.12, $fn = shape_steps(80));
|
|
1855
|
+
translate([0.88, 0.17]) circle(r = 0.12, $fn = shape_steps(80));
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// A speech bubble: a rounded box with a tail \`tail\` long at its bottom
|
|
1860
|
+
// left (mirror() it for the right). The tail is part of \`size\`.
|
|
1861
|
+
module speech_bubble(size = [40, 30], r, tail) {
|
|
1862
|
+
s = shape_size(size, "speech_bubble");
|
|
1863
|
+
th = is_undef(tail) ? s[1] / 4 : tail;
|
|
1864
|
+
assert(th > 0 && th < s[1] / 2, "speech_bubble(): tail must be more than 0 and less than half the height");
|
|
1865
|
+
rr = is_undef(r) ? min(s[0], s[1] - th) / 5 : r;
|
|
1866
|
+
bh = s[1] - th;
|
|
1867
|
+
yb = -s[1] / 2 + th;
|
|
1868
|
+
union() {
|
|
1869
|
+
translate([-s[0] / 2, yb]) rect([s[0], bh], r = rr);
|
|
1870
|
+
polygon([[-s[0] * 0.3, yb + min(bh / 2, rr + 1)], [-s[0] * 0.3 + s[0] / 5, yb + min(bh / 2, rr + 1)], [-s[0] * 0.38, -s[1] / 2]]);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1549
1873
|
`,"kerf/sizes":`// kerf/sizes: paper, card and photo sizes, in millimetres, for holders,
|
|
1550
1874
|
// folders, frames and boxes made to fit them.
|
|
1551
1875
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
@@ -1624,6 +1948,61 @@ function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = ali
|
|
|
1624
1948
|
len(hit) ? hit[0] : name;
|
|
1625
1949
|
// The names in a table, for messages
|
|
1626
1950
|
function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
1951
|
+
`,"kerf/stand":`// kerf/stand: a sign, a photo or a calendar standing in a base.
|
|
1952
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1953
|
+
//
|
|
1954
|
+
// The panel has tabs along its bottom edge that go through slots in a
|
|
1955
|
+
// base, upright or leaning back. stand() makes both parts and puts them
|
|
1956
|
+
// together; stand_tabs() and stand_slots() are the two halves of the joint
|
|
1957
|
+
// for a base of your own, and match whenever they are given the same
|
|
1958
|
+
// width, count, tab and lean. The base is $thickness thick, as the panel.
|
|
1959
|
+
|
|
1960
|
+
use <kerf/tabs>
|
|
1961
|
+
|
|
1962
|
+
// The panel \`width\` wide drawn by the children, its bottom edge on y = 0
|
|
1963
|
+
// from x = 0, standing in a base \`depth\` deep and \`margin\` wider than it
|
|
1964
|
+
// on each side, leaning back by \`lean\` degrees. Its back face meets the
|
|
1965
|
+
// base \`back\` from the front, half way by default. The parts are \`name\`
|
|
1966
|
+
// and "\`name\` stand".
|
|
1967
|
+
module stand(width, depth = 40, count = undef, tab = undef, lean = 0, margin = 10, back = undef, r = 3, clearance = 0.1, name = "Sign") {
|
|
1968
|
+
t = $thickness;
|
|
1969
|
+
assert(width > 0, "stand(): width must be more than 0");
|
|
1970
|
+
assert(lean >= 0 && lean < 45, "stand(): lean is from 0 up to 45 degrees");
|
|
1971
|
+
ys = is_undef(back) ? depth / 2 : back;
|
|
1972
|
+
assert(ys > 0 && ys < depth, "stand(): back must be inside the base's depth");
|
|
1973
|
+
part(name, at = [0, ys, t], rotate = [90 - lean, 0, 0]) {
|
|
1974
|
+
children();
|
|
1975
|
+
stand_tabs(width, count, tab, lean);
|
|
1976
|
+
}
|
|
1977
|
+
part(str(name, " stand"), at = [0, 0, 0]) difference() {
|
|
1978
|
+
translate([-margin, 0]) rect([width + 2 * margin, depth], r = r);
|
|
1979
|
+
translate([0, ys]) stand_slots(width, count, tab, lean, clearance);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
// Tabs for the bottom edge of a panel \`width\` wide, x from 0 to \`width\`,
|
|
1984
|
+
// hanging below y = 0 far enough to go through a base $thickness thick
|
|
1985
|
+
// when the panel leans back by \`lean\` degrees. Each is \`tab\` wide, half
|
|
1986
|
+
// the space between tabs by default; \`count\` is one for every 50 mm.
|
|
1987
|
+
module stand_tabs(width, count = undef, tab = undef, lean = 0) {
|
|
1988
|
+
at = tab_positions(width, count);
|
|
1989
|
+
w = is_undef(tab) ? width / (2 * len(at)) : tab;
|
|
1990
|
+
d = $thickness / cos(lean);
|
|
1991
|
+
for (x = at) translate([x - w / 2, -d]) rect([w, d + 0.01]);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
// The slots in a base for stand_tabs() with the same width, count, tab
|
|
1995
|
+
// and lean, x from 0 to \`width\`, for a panel whose back face meets the top
|
|
1996
|
+
// of the base on y = 0, standing towards -y and leaning back towards +y.
|
|
1997
|
+
// \`clearance\` is added to each slot's width and depth.
|
|
1998
|
+
module stand_slots(width, count = undef, tab = undef, lean = 0, clearance = 0.1) {
|
|
1999
|
+
at = tab_positions(width, count);
|
|
2000
|
+
w = is_undef(tab) ? width / (2 * len(at)) : tab;
|
|
2001
|
+
t = $thickness;
|
|
2002
|
+
// from the back face at the top to the tab's front corner at its end
|
|
2003
|
+
across = t * cos(lean) + t * tan(lean);
|
|
2004
|
+
for (x = at) translate([x, -across / 2]) rect([w + clearance, across + clearance], center = true);
|
|
2005
|
+
}
|
|
1627
2006
|
`,"kerf/symbols":`// kerf/symbols: 867 pictograms by name, for engraving and cutting.
|
|
1628
2007
|
// The library code: Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or
|
|
1629
2008
|
// MyLaserTools commercial licence. The symbols come from open icon sets,
|
|
@@ -2639,27 +3018,29 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
|
|
|
2639
3018
|
if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
|
|
2640
3019
|
if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
|
|
2641
3020
|
}
|
|
2642
|
-
`};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},r=Object.defineProperty,c=r(n,n,n)&&r}catch{}return c})(),e=function(n){if(this==null)throw TypeError();var r=String(this),c=r.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=c)){var s=r.charCodeAt(a),i;return s>=55296&&s<=56319&&c>a+1&&(i=r.charCodeAt(a+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var s6=0,J7=-3;function I5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function br(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new I5,this.dtree=new I5}var K7=new I5,Q7=new I5,i6=new Uint8Array(30),o6=new Uint16Array(30),e8=new Uint8Array(30),t8=new Uint16Array(30),xr=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),f7=new I5,C2=new Uint8Array(320);function n8(t,e,n,r){var c,a;for(c=0;c<n;++c)t[c]=0;for(c=0;c<30-n;++c)t[c+n]=c/n|0;for(a=r,c=0;c<30;++c)e[c]=a,a+=1<<t[c]}function Mr(t,e){var n;for(n=0;n<7;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;n<24;++n)t.trans[n]=256+n;for(n=0;n<144;++n)t.trans[24+n]=n;for(n=0;n<8;++n)t.trans[168+n]=280+n;for(n=0;n<112;++n)t.trans[176+n]=144+n;for(n=0;n<5;++n)e.table[n]=0;for(e.table[5]=32,n=0;n<32;++n)e.trans[n]=n}var d7=new Uint16Array(16);function Ue(t,e,n,r){var c,a;for(c=0;c<16;++c)t.table[c]=0;for(c=0;c<r;++c)t.table[e[n+c]]++;for(t.table[0]=0,a=0,c=0;c<16;++c)d7[c]=a,a+=t.table[c];for(c=0;c<r;++c)e[n+c]&&(t.trans[d7[e[n+c]]++]=c)}function wr(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function P2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var r=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,r+n}function Je(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,r=0,c=0,a=t.tag;do r=2*r+(a&1),a>>>=1,++c,n+=e.table[c],r-=e.table[c];while(r>=0);return t.tag=a,t.bitcount-=c,e.trans[n+r]}function kr(t,e,n){var r,c,a,s,i,o;for(r=P2(t,5,257),c=P2(t,5,1),a=P2(t,4,4),s=0;s<19;++s)C2[s]=0;for(s=0;s<a;++s){var l=P2(t,3,0);C2[xr[s]]=l}for(Ue(f7,C2,0,19),i=0;i<r+c;){var h=Je(t,f7);switch(h){case 16:var u=C2[i-1];for(o=P2(t,2,3);o;--o)C2[i++]=u;break;case 17:for(o=P2(t,3,3);o;--o)C2[i++]=0;break;case 18:for(o=P2(t,7,11);o;--o)C2[i++]=0;break;default:C2[i++]=h;break}}Ue(e,C2,0,r),Ue(n,C2,r,c)}function m7(t,e,n){for(;;){var r=Je(t,e);if(r===256)return s6;if(r<256)t.dest[t.destLen++]=r;else{var c,a,s,i;for(r-=257,c=P2(t,i6[r],o6[r]),a=Je(t,n),s=t.destLen-P2(t,e8[a],t8[a]),i=s;i<s+c;++i)t.dest[t.destLen++]=t.dest[i]}}}function zr(t){for(var e,n,r;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return J7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,s6}function Sr(t,e){var n=new br(t,e),r,c,a;do{switch(r=wr(n),c=P2(n,2,0),c){case 0:a=zr(n);break;case 1:a=m7(n,K7,Q7);break;case 2:kr(n,n.ltree,n.dtree),a=m7(n,n.ltree,n.dtree);break;default:a=J7}if(a!==s6)throw new Error("Data error")}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}Mr(K7,Q7);n8(i6,o6,4,3);n8(e8,t8,2,1);i6[28]=0;o6[28]=258;var Lr=Sr;function _3(t,e,n,r,c){return Math.pow(1-c,3)*t+3*Math.pow(1-c,2)*c*e+3*(1-c)*Math.pow(c,2)*n+Math.pow(c,3)*r}function n3(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}n3.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};n3.prototype.addPoint=function(t,e){typeof t=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};n3.prototype.addX=function(t){this.addPoint(t,null)};n3.prototype.addY=function(t){this.addPoint(null,t)};n3.prototype.addBezier=function(t,e,n,r,c,a,s,i){var o=[t,e],l=[n,r],h=[c,a],u=[s,i];this.addPoint(t,e),this.addPoint(s,i);for(var f=0;f<=1;f++){var d=6*o[f]-12*l[f]+6*h[f],m=-3*o[f]+9*l[f]-9*h[f]+3*u[f],g=3*l[f]-3*o[f];if(m===0){if(d===0)continue;var p=-g/d;0<p&&p<1&&(f===0&&this.addX(_3(o[f],l[f],h[f],u[f],p)),f===1&&this.addY(_3(o[f],l[f],h[f],u[f],p)));continue}var v=Math.pow(d,2)-4*g*m;if(!(v<0)){var y=(-d+Math.sqrt(v))/(2*m);0<y&&y<1&&(f===0&&this.addX(_3(o[f],l[f],h[f],u[f],y)),f===1&&this.addY(_3(o[f],l[f],h[f],u[f],y)));var b=(-d-Math.sqrt(v))/(2*m);0<b&&b<1&&(f===0&&this.addX(_3(o[f],l[f],h[f],u[f],b)),f===1&&this.addY(_3(o[f],l[f],h[f],u[f],b)))}}};n3.prototype.addQuad=function(t,e,n,r,c,a){var s=t+.6666666666666666*(n-t),i=e+2/3*(r-e),o=s+1/3*(c-t),l=i+1/3*(a-e);this.addBezier(t,e,s,i,o,l,c,a)};function P0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}P0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};P0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};P0.prototype.curveTo=P0.prototype.bezierCurveTo=function(t,e,n,r,c,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:r,x:c,y:a})};P0.prototype.quadTo=P0.prototype.quadraticCurveTo=function(t,e,n,r){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:r})};P0.prototype.close=P0.prototype.closePath=function(){this.commands.push({type:"Z"})};P0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof n3){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};P0.prototype.getBoundingBox=function(){for(var t=new n3,e=0,n=0,r=0,c=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=r=s.x,n=c=s.y;break;case"L":t.addPoint(s.x,s.y),r=s.x,c=s.y;break;case"Q":t.addQuad(r,c,s.x1,s.y1,s.x,s.y),r=s.x,c=s.y;break;case"C":t.addBezier(r,c,s.x1,s.y1,s.x2,s.y2,s.x,s.y),r=s.x,c=s.y;break;case"Z":r=e,c=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};P0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};P0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var r="",c=0;c<this.commands.length;c+=1){var a=this.commands[c];a.type==="M"?r+="M"+n(a.x,a.y):a.type==="L"?r+="L"+n(a.x,a.y):a.type==="C"?r+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?r+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(r+="Z")}return r};P0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};P0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function r8(t){throw new Error(t)}function p7(t,e){t||r8(e)}var C1={fail:r8,argument:p7,assert:p7},g7=32768,v7=2147483648,G3={},K={},I1={};function y2(t){return function(){return t}}K.BYTE=function(t){return C1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};I1.BYTE=y2(1);K.CHAR=function(t){return[t.charCodeAt(0)]};I1.CHAR=y2(1);K.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};I1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};K.USHORT=function(t){return[t>>8&255,t&255]};I1.USHORT=y2(2);K.SHORT=function(t){return t>=g7&&(t=-(2*g7-t)),[t>>8&255,t&255]};I1.SHORT=y2(2);K.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};I1.UINT24=y2(3);K.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};I1.ULONG=y2(4);K.LONG=function(t){return t>=v7&&(t=-(2*v7-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};I1.LONG=y2(4);K.FIXED=K.ULONG;I1.FIXED=I1.ULONG;K.FWORD=K.SHORT;I1.FWORD=I1.SHORT;K.UFWORD=K.USHORT;I1.UFWORD=I1.USHORT;K.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};I1.LONGDATETIME=y2(8);K.TAG=function(t){return C1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};I1.TAG=y2(4);K.Card8=K.BYTE;I1.Card8=I1.BYTE;K.Card16=K.USHORT;I1.Card16=I1.USHORT;K.OffSize=K.BYTE;I1.OffSize=I1.BYTE;K.SID=K.USHORT;I1.SID=I1.USHORT;K.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?K.NUMBER16(t):K.NUMBER32(t)};I1.NUMBER=function(t){return K.NUMBER(t).length};K.NUMBER16=function(t){return[28,t>>8&255,t&255]};I1.NUMBER16=y2(3);K.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};I1.NUMBER32=y2(5);K.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var r=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*r)/r).toString()}for(var c="",a=0,s=e.length;a<s;a+=1){var i=e[a];i==="e"?c+=e[++a]==="-"?"c":"b":i==="."?c+="a":i==="-"?c+="e":c+=i}c+=c.length&1?"f":"ff";for(var o=[30],l=0,h=c.length;l<h;l+=2)o.push(parseInt(c.substr(l,2),16));return o};I1.REAL=function(t){return K.REAL(t).length};K.NAME=K.CHARARRAY;I1.NAME=I1.CHARARRAY;K.STRING=K.CHARARRAY;I1.STRING=I1.CHARARRAY;G3.UTF8=function(t,e,n){for(var r=[],c=n,a=0;a<c;a++,e+=1)r[a]=t.getUint8(e);return String.fromCharCode.apply(null,r)};G3.UTF16=function(t,e,n){for(var r=[],c=n/2,a=0;a<c;a++,e+=2)r[a]=t.getUint16(e);return String.fromCharCode.apply(null,r)};K.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var r=t.charCodeAt(n);e[e.length]=r>>8&255,e[e.length]=r&255}return e};I1.UTF16=function(t){return t.length*2};var Ke={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};G3.MACSTRING=function(t,e,n,r){var c=Ke[r];if(c!==void 0){for(var a="",s=0;s<n;s++){var i=t.getUint8(e+s);i<=127?a+=String.fromCharCode(i):a+=c[i&127]}return a}};var S4=typeof WeakMap=="function"&&new WeakMap,L4,Ar=function(t){if(!L4){L4={};for(var e in Ke)L4[e]=new String(e)}var n=L4[t];if(n!==void 0){if(S4){var r=S4.get(n);if(r!==void 0)return r}var c=Ke[t];if(c!==void 0){for(var a={},s=0;s<c.length;s++)a[c.charCodeAt(s)]=s+128;return S4&&S4.set(n,a),a}}};K.MACSTRING=function(t,e){var n=Ar(e);if(n!==void 0){for(var r=[],c=0;c<t.length;c++){var a=t.charCodeAt(c);if(a>=128&&(a=n[a],a===void 0))return;r[c]=a}return r}};I1.MACSTRING=function(t,e){var n=K.MACSTRING(t,e);return n!==void 0?n.length:0};function Qe(t){return t>=-128&&t<=127}function Cr(t,e,n){for(var r=0,c=t.length;e<c&&r<64&&t[e]===0;)++e,++r;return n.push(128|r-1),e}function Pr(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(!Qe(s)||s===0&&a+1<c&&t[a+1]===0)break;++a,++r}n.push(r-1);for(var i=e;i<a;++i)n.push(t[i]+256&255);return a}function Er(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(s===0||Qe(s)&&a+1<c&&Qe(t[a+1]))break;++a,++r}n.push(64|r-1);for(var i=e;i<a;++i){var o=t[i];n.push(o+65536>>8&255,o+256&255)}return a}K.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var r=t[e];r===0?e=Cr(t,e,n):r>=-128&&r<=127?e=Pr(t,e,n):e=Er(t,e,n)}return n};K.INDEX=function(t){for(var e=1,n=[e],r=[],c=0;c<t.length;c+=1){var a=K.OBJECT(t[c]);Array.prototype.push.apply(r,a),e+=a.length,n.push(e)}if(r.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,K.BYTE,K.USHORT,K.UINT24,K.ULONG][i],l=0;l<n.length;l+=1){var h=o(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(K.Card16(t.length),K.OffSize(i),s,r)};I1.INDEX=function(t){return K.INDEX(t).length};K.DICT=function(t){for(var e=[],n=Object.keys(t),r=n.length,c=0;c<r;c+=1){var a=parseInt(n[c],0),s=t[a];e=e.concat(K.OPERAND(s.value,s.type)),e=e.concat(K.OPERATOR(a))}return e};I1.DICT=function(t){return K.DICT(t).length};K.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};K.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r+=1)C1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(K.OPERAND(t[r],e[r]));else if(e==="SID")n=n.concat(K.NUMBER(t));else if(e==="offset")n=n.concat(K.NUMBER32(t));else if(e==="number")n=n.concat(K.NUMBER(t));else if(e==="real")n=n.concat(K.REAL(t));else throw new Error("Unknown operand type "+e);return n};K.OP=K.BYTE;I1.OP=I1.BYTE;var A4=typeof WeakMap=="function"&&new WeakMap;K.CHARSTRING=function(t){if(A4){var e=A4.get(t);if(e!==void 0)return e}for(var n=[],r=t.length,c=0;c<r;c+=1){var a=t[c];n=n.concat(K[a.type](a.value))}return A4&&A4.set(t,n),n};I1.CHARSTRING=function(t){return K.CHARSTRING(t).length};K.OBJECT=function(t){var e=K[t.type];return C1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};I1.OBJECT=function(t){var e=I1[t.type];return C1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};K.TABLE=function(t){for(var e=[],n=t.fields.length,r=[],c=[],a=0;a<n;a+=1){var s=t.fields[a],i=K[s.type];C1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=t[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(c.push(e.length),e=e.concat([0,0]),r.push(l)):e=e.concat(l)}for(var h=0;h<r.length;h+=1){var u=c[h],f=e.length;C1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(r[h])}return e};I1.TABLE=function(t){for(var e=0,n=t.fields.length,r=0;r<n;r+=1){var c=t.fields[r],a=I1[c.type];C1.argument(a!==void 0,"No sizeOf function for field type "+c.type+" ("+c.name+")");var s=t[c.name];s===void 0&&(s=c.value),e+=a(s),c.type==="TABLE"&&(e+=2)}return e};K.RECORD=K.TABLE;I1.RECORD=I1.TABLE;K.LITERAL=function(t){return t};I1.LITERAL=function(t){return t.length};function T0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var r=0;r<e.length;r+=1){var c=e[r];this[c.name]=c.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var i=a[s],o=n[i];this[i]!==void 0&&(this[i]=o)}}T0.prototype.encode=function(){return K.TABLE(this)};T0.prototype.sizeOf=function(){return I1.TABLE(this)};function V5(t,e,n){n===void 0&&(n=e.length);var r=new Array(e.length+1);r[0]={name:t+"Count",type:"USHORT",value:n};for(var c=0;c<e.length;c++)r[c+1]={name:t+c,type:"USHORT",value:e[c]};return r}function e6(t,e,n){var r=e.length,c=new Array(r+1);c[0]={name:t+"Count",type:"USHORT",value:r};for(var a=0;a<r;a++)c[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return c}function H5(t,e,n){var r=e.length,c=[];c[0]={name:t+"Count",type:"USHORT",value:r};for(var a=0;a<r;a++)c=c.concat(n(e[a],a));return c}function I4(t){t.format===1?T0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(V5("glyph",t.glyphs))):t.format===2?T0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(H5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):C1.assert(!1,"Coverage format must be 1 or 2.")}I4.prototype=Object.create(T0.prototype);I4.prototype.constructor=I4;function V4(t){T0.call(this,"scriptListTable",H5("scriptRecord",t,function(e,n){var r=e.script,c=r.defaultLangSys;return C1.assert(!!c,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new T0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new T0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:c.reqFeatureIndex}].concat(V5("featureIndex",c.featureIndexes)))}].concat(H5("langSys",r.langSysRecords,function(a,s){var i=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new T0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(V5("featureIndex",i.featureIndexes)))}]})))}]}))}V4.prototype=Object.create(T0.prototype);V4.prototype.constructor=V4;function H4(t){T0.call(this,"featureListTable",H5("featureRecord",t,function(e,n){var r=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new T0("featureTable",[{name:"featureParams",type:"USHORT",value:r.featureParams}].concat(V5("lookupListIndex",r.lookupListIndexes)))}]}))}H4.prototype=Object.create(T0.prototype);H4.prototype.constructor=H4;function O4(t,e){T0.call(this,"lookupListTable",e6("lookup",t,function(n){var r=e[n.lookupType];return C1.assert(!!r,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new T0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(e6("subtable",n.subtables,r)))}))}O4.prototype=Object.create(T0.prototype);O4.prototype.constructor=O4;var s1={Table:T0,Record:T0,Coverage:I4,ScriptList:V4,FeatureList:H4,LookupList:O4,ushortList:V5,tableList:e6,recordList:H5};function y7(t,e){return t.getUint8(e)}function F4(t,e){return t.getUint16(e,!1)}function Tr(t,e){return t.getInt16(e,!1)}function l6(t,e){return t.getUint32(e,!1)}function c8(t,e){var n=t.getInt16(e,!1),r=t.getUint16(e+2,!1);return n+r/65535}function Ir(t,e){for(var n="",r=e;r<e+4;r+=1)n+=String.fromCharCode(t.getInt8(r));return n}function Vr(t,e,n){for(var r=0,c=0;c<n;c+=1)r<<=8,r+=t.getUint8(e+c);return r}function Hr(t,e,n){for(var r=[],c=e;c<n;c+=1)r.push(t.getUint8(c));return r}function Or(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var Fr={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function $(t,e){this.data=t,this.offset=e,this.relativeOffset=0}$.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};$.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};$.prototype.parseCard8=$.prototype.parseByte;$.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};$.prototype.parseCard16=$.prototype.parseUShort;$.prototype.parseSID=$.prototype.parseUShort;$.prototype.parseOffset16=$.prototype.parseUShort;$.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};$.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};$.prototype.parseULong=function(){var t=l6(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};$.prototype.parseOffset32=$.prototype.parseULong;$.prototype.parseFixed=function(){var t=c8(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};$.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,r="";this.relativeOffset+=t;for(var c=0;c<t;c++)r+=String.fromCharCode(e.getUint8(n+c));return r};$.prototype.parseTag=function(){return this.parseString(4)};$.prototype.parseLongDateTime=function(){var t=l6(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};$.prototype.parseVersion=function(t){var e=F4(this.data,this.offset+this.relativeOffset),n=F4(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};$.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=Fr[t]*e};$.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getUint32(r),r+=4;return this.relativeOffset+=t*4,e};$.prototype.parseOffset16List=$.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getUint16(r),r+=2;return this.relativeOffset+=t*2,e};$.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getInt16(r),r+=2;return this.relativeOffset+=t*2,e};$.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getUint8(r++);return this.relativeOffset+=t,e};$.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};$.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};$.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=Object.keys(e),c=0;c<t;c++){for(var a={},s=0;s<r.length;s++){var i=r[s],o=e[i];a[i]=o.call(this)}n[c]=a}return n};$.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=Object.keys(e),c=0;c<t;c++){for(var a={},s=0;s<r.length;s++){var i=r[s],o=e[i];a[i]=o.call(this)}n[c]=a}return n};$.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},r=0;r<e.length;r++){var c=e[r],a=t[c];n[c]=a.call(this)}return n};$.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};$.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),r=0;r<e;r++)n[r]=this.parseValueRecord(t);return n};$.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new $(this.data,this.offset+e).parseStruct(t)};$.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new $(this.data,this.offset+e).parseStruct(t)};$.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,r=this.relativeOffset,c=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){c[a]=void 0;continue}if(this.relativeOffset=s,t){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=t.call(this);c[a]=o}else c[a]=this.parseUShortList()}return this.relativeOffset=r,c};$.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var r=new Array(n),c=0;c<n;c++)r[c]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:r}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};$.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:$.uShort,end:$.uShort,classId:$.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};$.list=function(t,e){return function(){return this.parseList(t,e)}};$.list32=function(t,e){return function(){return this.parseList32(t,e)}};$.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};$.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};$.pointer=function(t){return function(){return this.parsePointer(t)}};$.pointer32=function(t){return function(){return this.parsePointer32(t)}};$.tag=$.prototype.parseTag;$.byte=$.prototype.parseByte;$.uShort=$.offset16=$.prototype.parseUShort;$.uShortList=$.prototype.parseUShortList;$.uLong=$.offset32=$.prototype.parseULong;$.uLongList=$.prototype.parseULongList;$.struct=$.prototype.parseStruct;$.coverage=$.prototype.parseCoverage;$.classDef=$.prototype.parseClassDef;var b7={reserved:$.uShort,reqFeatureIndex:$.uShort,featureIndexes:$.uShortList};$.prototype.parseScriptList=function(){return this.parsePointer($.recordList({tag:$.tag,script:$.pointer({defaultLangSys:$.pointer(b7),langSysRecords:$.recordList({tag:$.tag,langSys:$.pointer(b7)})})}))||[]};$.prototype.parseFeatureList=function(){return this.parsePointer($.recordList({tag:$.tag,feature:$.pointer({featureParams:$.offset16,lookupListIndexes:$.uShortList})}))||[]};$.prototype.parseLookupList=function(t){return this.parsePointer($.list($.pointer(function(){var e=this.parseUShort();C1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),r=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList($.pointer(t[e])),markFilteringSet:r?this.parseUShort():void 0}})))||[]};$.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();C1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:$.offset32,featureTableSubstitutionOffset:$.offset32});return n})||[]};var p1={getByte:y7,getCard8:y7,getUShort:F4,getCard16:F4,getShort:Tr,getULong:l6,getFixed:c8,getTag:Ir,getOffset:Vr,getBytes:Hr,bytesToString:Or,Parser:$};function Rr(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var r=0;r<n;r+=1)for(var c=e.parseULong(),a=e.parseULong(),s=e.parseULong(),i=c;i<=a;i+=1)t.glyphIndexMap[i]=s,s++}function $r(t,e,n,r,c){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new p1.Parser(n,r+c+14),i=new p1.Parser(n,r+c+16+a*2),o=new p1.Parser(n,r+c+16+a*4),l=new p1.Parser(n,r+c+16+a*6),h=r+c+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),m=i.parseUShort(),g=o.parseShort(),p=l.parseUShort(),v=m;v<=d;v+=1)p!==0?(h=l.offset+l.relativeOffset-2,h+=p,h+=(v-m)*2,f=p1.getUShort(n,h),f!==0&&(f=f+g&65535)):f=v+g&65535,t.glyphIndexMap[v]=f}function Dr(t,e){var n={};n.version=p1.getUShort(t,e),C1.argument(n.version===0,"cmap table version should be 0."),n.numTables=p1.getUShort(t,e+2);for(var r=-1,c=n.numTables-1;c>=0;c-=1){var a=p1.getUShort(t,e+4+c*8),s=p1.getUShort(t,e+4+c*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){r=p1.getULong(t,e+4+c*8+4);break}}if(r===-1)throw new Error("No valid cmap sub-tables found.");var i=new p1.Parser(t,e+r);if(n.format=i.parseUShort(),n.format===12)Rr(n,i);else if(n.format===4)$r(n,i,t,e,r);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function qr(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function Nr(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function Ur(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var r=t.get(n);if(r.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var c=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(c=c.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),c=c.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var a=new s1.Table("cmap",c);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),i=0;i<s.unicodes.length;i+=1)qr(a,s.unicodes[i],n);a.segments=a.segments.sort(function(y,b){return y.start-b.start})}Nr(a);var o=a.segments.length,l=0,h=[],u=[],f=[],d=[],m=[],g=[];for(n=0;n<o;n+=1){var p=a.segments[n];p.end<=65535&&p.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:p.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:p.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:p.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:p.offset}),p.glyphId!==void 0&&(m=m.concat({name:"glyph_"+n,type:"USHORT",value:p.glyphId}))):l+=1,!e&&p.glyphIndex!==void 0&&(g=g.concat({name:"cmap12Start_"+n,type:"ULONG",value:p.start}),g=g.concat({name:"cmap12End_"+n,type:"ULONG",value:p.end}),g=g.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:p.glyphIndex}))}if(a.segCountX2=(o-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(m),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+m.length*2,!e){var v=16+g.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:g.length/3}]),a.fields=a.fields.concat(g)}return a}var a8={parse:Dr,make:Ur},E4=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],Br=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],_r=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],g3=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function s8(t){this.font=t}s8.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var r=0;r<n.length;r+=1)for(var c=n.get(r),a=0;a<c.unicodes.length;a+=1)if(c.unicodes[a]===e)return r}return null};function i8(t){this.cmap=t}i8.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function R4(t,e){this.encoding=t,this.charset=e}R4.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function h6(t){switch(t.version){case 1:this.names=g3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<g3.length?this.names[e]=g3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-g3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=g3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}h6.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};h6.prototype.glyphIndexToName=function(t){return this.names[t]};function jr(t){for(var e,n=t.tables.cmap.glyphIndexMap,r=Object.keys(n),c=0;c<r.length;c+=1){var a=r[c],s=n[a];e=t.glyphs.get(s),e.addUnicode(parseInt(a))}for(var i=0;i<t.glyphs.length;i+=1)e=t.glyphs.get(i),t.cffEncoding?t.isCIDFont?e.name="gid"+i:e.name=t.cffEncoding.charset[i]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(i))}function Gr(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),r=0;r<n.length;r+=1){var c=n[r],a=e[c];t._IndexToUnicodeMap[a]===void 0?t._IndexToUnicodeMap[a]={unicodes:[parseInt(c)]}:t._IndexToUnicodeMap[a].unicodes.push(parseInt(c))}}function Wr(t,e){e.lowMemory?Gr(t):jr(t)}function Xr(t,e,n,r,c){t.beginPath(),t.moveTo(e,n),t.lineTo(r,c),t.stroke()}var p3={line:Xr};function Zr(t,e){var n=e||new P0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(r){n=r}}}function h2(t){this.bindConstructorValues(t)}h2.prototype.bindConstructorValues=function(t){this.index=t.index||0,this.name=t.name||null,this.unicode=t.unicode||void 0,this.unicodes=t.unicodes||t.unicode!==void 0?[t.unicode]:[],"xMin"in t&&(this.xMin=t.xMin),"yMin"in t&&(this.yMin=t.yMin),"xMax"in t&&(this.xMax=t.xMax),"yMax"in t&&(this.yMax=t.yMax),"advanceWidth"in t&&(this.advanceWidth=t.advanceWidth),Object.defineProperty(this,"path",Zr(this,t.path))};h2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};h2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};h2.prototype.getPath=function(t,e,n,r,c){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;r||(r={});var i=r.xScale,o=r.yScale;if(r.hinting&&c&&c.hinting&&(s=this.path&&c.hinting.exec(this,n)),s)a=c.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),i=o=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new P0,u=0;u<a.length;u+=1){var f=a[u];f.type==="M"?h.moveTo(t+f.x*i,e+-f.y*o):f.type==="L"?h.lineTo(t+f.x*i,e+-f.y*o):f.type==="Q"?h.quadraticCurveTo(t+f.x1*i,e+-f.y1*o,t+f.x*i,e+-f.y*o):f.type==="C"?h.curveTo(t+f.x1*i,e+-f.y1*o,t+f.x2*i,e+-f.y2*o,t+f.x*i,e+-f.y*o):f.type==="Z"&&h.closePath()}return h};h2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var r=this.points[n];e.push(r),r.lastPointOfContour&&(t.push(e),e=[])}return C1.argument(e.length===0,"There are still points left in the current contour."),t};h2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],r=0;r<t.length;r+=1){var c=t[r];c.type!=="Z"&&(e.push(c.x),n.push(c.y)),(c.type==="Q"||c.type==="C")&&(e.push(c.x1),n.push(c.y1)),c.type==="C"&&(e.push(c.x2),n.push(c.y2))}var a={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a};h2.prototype.draw=function(t,e,n,r,c){this.getPath(e,n,r,c).draw(t)};h2.prototype.drawPoints=function(t,e,n,r){function c(u,f,d,m){t.beginPath();for(var g=0;g<u.length;g+=1)t.moveTo(f+u[g].x*m,d+u[g].y*m),t.arc(f+u[g].x*m,d+u[g].y*m,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24;for(var a=1/this.path.unitsPerEm*r,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",c(s,e,n,a),t.fillStyle="red",c(i,e,n,a)};h2.prototype.drawMetrics=function(t,e,n,r){var c;e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24,c=1/this.path.unitsPerEm*r,t.lineWidth=1,t.strokeStyle="black",p3.line(t,e,-1e4,e,1e4),p3.line(t,-1e4,n,1e4,n);var a=this.xMin||0,s=this.yMin||0,i=this.xMax||0,o=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",p3.line(t,e+a*c,-1e4,e+a*c,1e4),p3.line(t,e+i*c,-1e4,e+i*c,1e4),p3.line(t,-1e4,n+-s*c,1e4,n+-s*c),p3.line(t,-1e4,n+-o*c,1e4,n+-o*c),t.strokeStyle="green",p3.line(t,e+l*c,-1e4,e+l*c,1e4)};function C4(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(r){t[n]=r},enumerable:!0,configurable:!0})}function u6(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var r=e[n];r.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=r}this.length=e&&e.length||0}u6.prototype.get=function(t){if(this.glyphs[t]===void 0){this.font._push(t),typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());var e=this.glyphs[t],n=this.font._IndexToUnicodeMap[t];if(n)for(var r=0;r<n.unicodes.length;r++)e.addUnicode(n.unicodes[r]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+t:e.name=this.font.cffEncoding.charset[t]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(t)),this.glyphs[t].advanceWidth=this.font._hmtxTableData[t].advanceWidth,this.glyphs[t].leftSideBearing=this.font._hmtxTableData[t].leftSideBearing}else typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());return this.glyphs[t]};u6.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Yr(t,e){return new h2({index:e,font:t})}function Jr(t,e,n,r,c,a){return function(){var s=new h2({index:e,font:t});return s.path=function(){n(s,r,c);var i=a(t.glyphs,s);return i.unitsPerEm=t.unitsPerEm,i},C4(s,"xMin","_xMin"),C4(s,"xMax","_xMax"),C4(s,"yMin","_yMin"),C4(s,"yMax","_yMax"),s}}function Kr(t,e,n,r){return function(){var c=new h2({index:e,font:t});return c.path=function(){var a=n(t,c,r);return a.unitsPerEm=t.unitsPerEm,a},c}}var T2={GlyphSet:u6,glyphLoader:Yr,ttfGlyphLoader:Jr,cffGlyphLoader:Kr};function o8(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n+=1)if(!o8(t[n],e[n]))return!1;return!0}else return!1}function t6(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function K2(t,e,n){var r=[],c=[],a=p1.getCard16(t,e),s,i;if(a!==0){var o=p1.getByte(t,e+2);s=e+(a+1)*o+2;for(var l=e+3,h=0;h<a+1;h+=1)r.push(p1.getOffset(t,l,o)),l+=o;i=s+r[a]}else i=e+2;for(var u=0;u<r.length-1;u+=1){var f=p1.getBytes(t,s+r[u],s+r[u+1]);n&&(f=n(f)),c.push(f)}return{objects:c,startOffset:e,endOffset:i}}function Qr(t,e){var n=[],r=p1.getCard16(t,e),c,a;if(r!==0){var s=p1.getByte(t,e+2);c=e+(r+1)*s+2;for(var i=e+3,o=0;o<r+1;o+=1)n.push(p1.getOffset(t,i,s)),i+=s;a=c+n[r]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function ec(t,e,n,r,c){var a=p1.getCard16(n,r),s=0;if(a!==0){var i=p1.getByte(n,r+2);s=r+(a+1)*i+2}var o=p1.getBytes(n,s+e[t],s+e[t+1]);return c&&(o=c(o)),o}function tc(t){for(var e="",n=15,r=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var c=t.parseByte(),a=c>>4,s=c&15;if(a===n||(e+=r[a],s===n))break;e+=r[s]}return parseFloat(e)}function nc(t,e){var n,r,c,a;if(e===28)return n=t.parseByte(),r=t.parseByte(),n<<8|r;if(e===29)return n=t.parseByte(),r=t.parseByte(),c=t.parseByte(),a=t.parseByte(),n<<24|r<<16|c<<8|a;if(e===30)return tc(t);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return n=t.parseByte(),(e-247)*256+n+108;if(e>=251&&e<=254)return n=t.parseByte(),-(e-251)*256-n-108;throw new Error("Invalid b0 "+e)}function rc(t){for(var e={},n=0;n<t.length;n+=1){var r=t[n][0],c=t[n][1],a=void 0;if(c.length===1?a=c[0]:a=c,e.hasOwnProperty(r)&&!isNaN(e[r]))throw new Error("Object "+e+" already has key "+r);e[r]=a}return e}function l8(t,e,n){e=e!==void 0?e:0;var r=new p1.Parser(t,e),c=[],a=[];for(n=n!==void 0?n:t.length;r.relativeOffset<n;){var s=r.parseByte();s<=21?(s===12&&(s=1200+r.parseByte()),c.push([s,a]),a=[]):a.push(nc(r,s))}return rc(c)}function T5(t,e){return e<=390?e=E4[e]:e=t[e-391],e}function h8(t,e,n){for(var r={},c,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)c=t[s.op]!==void 0?t[s.op][o]:void 0,c===void 0&&(c=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(c=T5(n,c)),i[o]=c;r[s.name]=i}else c=t[s.op],c===void 0&&(c=s.value!==void 0?s.value:null),s.type==="SID"&&(c=T5(n,c)),r[s.name]=c}return r}function cc(t,e){var n={};return n.formatMajor=p1.getCard8(t,e),n.formatMinor=p1.getCard8(t,e+1),n.size=p1.getCard8(t,e+2),n.offsetSize=p1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var u8=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],f8=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}];function ac(t,e){var n=l8(t,0,t.byteLength);return h8(n,u8,e)}function d8(t,e,n,r){var c=l8(t,e,n);return h8(c,f8,r)}function x7(t,e,n,r){for(var c=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),i=ac(s,r);i._subrs=[],i._subrsBias=0,i._defaultWidthX=0,i._nominalWidthX=0;var o=i.private[0],l=i.private[1];if(o!==0&&l!==0){var h=d8(t,l+e,o,r);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=K2(t,u+e);i._subrs=f.objects,i._subrsBias=t6(i._subrs)}i._privateDict=h}c.push(i)}return c}function sc(t,e,n,r){var c,a,s=new p1.Parser(t,e);n-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<n;l+=1)c=s.parseSID(),i.push(T5(r,c));else if(o===1)for(;i.length<=n;){c=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)i.push(T5(r,c)),c+=1}else if(o===2)for(;i.length<=n;){c=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)i.push(T5(r,c)),c+=1}else throw new Error("Unknown charset format "+o);return i}function ic(t,e,n){var r,c={},a=new p1.Parser(t,e),s=a.parseCard8();if(s===0)for(var i=a.parseCard8(),o=0;o<i;o+=1)r=a.parseCard8(),c[r]=o;else if(s===1){var l=a.parseCard8();r=1;for(var h=0;h<l;h+=1)for(var u=a.parseCard8(),f=a.parseCard8(),d=u;d<=u+f;d+=1)c[d]=r,r+=1}else throw new Error("Unknown encoding format "+s);return new R4(c,n)}function M7(t,e,n){var r,c,a,s,i=new P0,o=[],l=0,h=!1,u=!1,f=0,d=0,m,g,p,v;if(t.isCIDFont){var y=t.tables.cff.topDict._fdSelect[e.index],b=t.tables.cff.topDict._fdArray[y];m=b._subrs,g=b._subrsBias,p=b._defaultWidthX,v=b._nominalWidthX}else m=t.tables.cff.topDict._subrs,g=t.tables.cff.topDict._subrsBias,p=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=p;function M(z,S){u&&i.closePath(),i.moveTo(z,S),u=!0}function w(){var z;z=o.length%2!==0,z&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function k(z){for(var S,A,L,C,P,R,q,T,B,X,Z,h1,H=0;H<z.length;){var U=z[H];switch(H+=1,U){case 1:w();break;case 3:w();break;case 4:o.length>1&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),M(f,d);break;case 5:for(;o.length>0;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 6:for(;o.length>0&&(f+=o.shift(),i.lineTo(f,d),o.length!==0);)d+=o.shift(),i.lineTo(f,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(f,d),o.length!==0);)f+=o.shift(),i.lineTo(f,d);break;case 8:for(;o.length>0;)r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(r,c,a,s,f,d);break;case 10:P=o.pop()+g,R=m[P],R&&k(R);break;case 11:return;case 12:switch(U=z[H],H+=1,U){case 35:r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s+o.shift(),B=q+o.shift(),X=T+o.shift(),Z=B+o.shift(),h1=X+o.shift(),f=Z+o.shift(),d=h1+o.shift(),o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;case 34:r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s,B=q+o.shift(),X=s,Z=B+o.shift(),h1=d,f=Z+o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;case 36:r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s,B=q+o.shift(),X=s,Z=B+o.shift(),h1=X+o.shift(),f=Z+o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;case 37:r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),q=a+o.shift(),T=s+o.shift(),B=q+o.shift(),X=T+o.shift(),Z=B+o.shift(),h1=X+o.shift(),Math.abs(Z-f)>Math.abs(h1-d)?f=Z+o.shift():d=h1+o.shift(),i.curveTo(r,c,a,s,q,T),i.curveTo(B,X,Z,h1,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+U),o.length=0}break;case 14:o.length>0&&!h&&(x=o.shift()+v,h=!0),u&&(i.closePath(),u=!1);break;case 18:w();break;case 19:case 20:w(),H+=l+7>>3;break;case 21:o.length>2&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),f+=o.pop(),M(f,d);break;case 22:o.length>1&&!h&&(x=o.shift()+v,h=!0),f+=o.pop(),M(f,d);break;case 23:w();break;case 24:for(;o.length>2;)r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(r,c,a,s,f,d);f+=o.shift(),d+=o.shift(),i.lineTo(f,d);break;case 25:for(;o.length>6;)f+=o.shift(),d+=o.shift(),i.lineTo(f,d);r=f+o.shift(),c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+o.shift(),i.curveTo(r,c,a,s,f,d);break;case 26:for(o.length%2&&(f+=o.shift());o.length>0;)r=f,c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a,d=s+o.shift(),i.curveTo(r,c,a,s,f,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s,i.curveTo(r,c,a,s,f,d);break;case 28:S=z[H],A=z[H+1],o.push((S<<24|A<<16)>>16),H+=2;break;case 29:P=o.pop()+t.gsubrsBias,R=t.gsubrs[P],R&&k(R);break;case 30:for(;o.length>0&&(r=f,c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d),o.length!==0);)r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d);break;case 31:for(;o.length>0&&(r=f+o.shift(),c=d,a=r+o.shift(),s=c+o.shift(),d=s+o.shift(),f=a+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d),o.length!==0);)r=f,c=d+o.shift(),a=r+o.shift(),s=c+o.shift(),f=a+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(r,c,a,s,f,d);break;default:U<32?console.log("Glyph "+e.index+": unknown operator "+U):U<247?o.push(U-139):U<251?(S=z[H],H+=1,o.push((U-247)*256+S+108)):U<255?(S=z[H],H+=1,o.push(-(U-251)*256-S-108)):(S=z[H],A=z[H+1],L=z[H+2],C=z[H+3],H+=4,o.push((S<<24|A<<16|L<<8|C)/65536))}}}return k(n),e.advanceWidth=x,i}function oc(t,e,n,r){var c=[],a,s=new p1.Parser(t,e),i=s.parseCard8();if(i===0)for(var o=0;o<n;o++){if(a=s.parseCard8(),a>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+r+")");c.push(a)}else if(i===3){var l=s.parseCard16(),h=s.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var u,f=0;f<l;f++){if(a=s.parseCard8(),u=s.parseCard16(),a>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+r+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)c.push(a);h=u}if(u!==n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+u)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);return c}function lc(t,e,n,r){n.tables.cff={};var c=cc(t,e),a=K2(t,c.endOffset,p1.bytesToString),s=K2(t,a.endOffset),i=K2(t,s.endOffset,p1.bytesToString),o=K2(t,i.endOffset);n.gsubrs=o.objects,n.gsubrsBias=t6(n.gsubrs);var l=x7(t,e,s.objects,i.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=K2(t,u),m=x7(t,e,d.objects,i.objects);h._fdArray=m,f+=e,h._fdSelect=oc(t,f,n.numGlyphs,m.length)}var g=e+h.private[1],p=d8(t,g,h.private[0],i.objects);if(n.defaultWidthX=p.defaultWidthX,n.nominalWidthX=p.nominalWidthX,p.subrs!==0){var v=g+p.subrs,y=K2(t,v);n.subrs=y.objects,n.subrsBias=t6(n.subrs)}else n.subrs=[],n.subrsBias=0;var b;r.lowMemory?(b=Qr(t,e+h.charStrings),n.nGlyphs=b.offsets.length):(b=K2(t,e+h.charStrings),n.nGlyphs=b.objects.length);var x=sc(t,e+h.charset,n.nGlyphs,i.objects);if(h.encoding===0?n.cffEncoding=new R4(Br,x):h.encoding===1?n.cffEncoding=new R4(_r,x):n.cffEncoding=ic(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new T2.GlyphSet(n),r.lowMemory)n._push=function(k){var z=ec(k,b.offsets,t,e+h.charStrings);n.glyphs.push(k,T2.cffGlyphLoader(n,k,M7,z))};else for(var M=0;M<n.nGlyphs;M+=1){var w=b.objects[M];n.glyphs.push(M,T2.cffGlyphLoader(n,M,M7,w))}}function m8(t,e){var n,r=E4.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+E4.length:(n=E4.length+e.length,e.push(t)),n}function hc(){return new s1.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function uc(t){var e=new s1.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var n=0;n<t.length;n+=1)e.names.push({name:"name_"+n,type:"NAME",value:t[n]});return e}function p8(t,e,n){for(var r={},c=0;c<t.length;c+=1){var a=t[c],s=e[a.name];s!==void 0&&!o8(s,a.value)&&(a.type==="SID"&&(s=m8(s,n)),r[a.op]={name:a.name,type:a.type,value:s})}return r}function w7(t,e){var n=new s1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=p8(u8,t,e),n}function k7(t){var e=new s1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function fc(t){var e=new s1.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var n=0;n<t.length;n+=1)e.strings.push({name:"string_"+n,type:"STRING",value:t[n]});return e}function dc(){return new s1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function mc(t,e){for(var n=new s1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),r=0;r<t.length;r+=1){var c=t[r],a=m8(c,e);n.fields.push({name:"glyph_"+r,type:"SID",value:a})}return n}function pc(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var r=0,c=0,a=0;a<n.commands.length;a+=1){var s=void 0,i=void 0,o=n.commands[a];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*r+h*o.x1),y1:Math.round(l*c+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-r),i=Math.round(o.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),r=Math.round(o.x),c=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-r),i=Math.round(o.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),r=Math.round(o.x),c=Math.round(o.y);else if(o.type==="C"){var u=Math.round(o.x1-r),f=Math.round(o.y1-c),d=Math.round(o.x2-o.x1),m=Math.round(o.y2-o.y1);s=Math.round(o.x-o.x2),i=Math.round(o.y-o.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:m}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),r=Math.round(o.x),c=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function gc(t){for(var e=new s1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var r=t.get(n),c=pc(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:c})}return e}function vc(t,e){var n=new s1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=p8(f8,t,e),n}function yc(t,e){for(var n=new s1.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),r=1/e.unitsPerEm,c={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[r,0,0,r,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},s=[],i,o=1;o<t.length;o+=1)i=t.get(o),s.push(i.name);var l=[];n.header=hc(),n.nameIndex=uc([e.postScriptName]);var h=w7(c,l);n.topDictIndex=k7(h),n.globalSubrIndex=dc(),n.charsets=mc(s,l),n.charStringsIndex=gc(t),n.privateDict=vc(a,l),n.stringIndex=fc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return c.charset=u,c.encoding=0,c.charStrings=c.charset+n.charsets.sizeOf(),c.private[1]=c.charStrings+n.charStringsIndex.sizeOf(),h=w7(c,l),n.topDictIndex=k7(h),n}var g8={parse:lc,make:yc};function bc(t,e){var n={},r=new p1.Parser(t,e);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),C1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=r.parseUShort(),n.unitsPerEm=r.parseUShort(),n.created=r.parseLongDateTime(),n.modified=r.parseLongDateTime(),n.xMin=r.parseShort(),n.yMin=r.parseShort(),n.xMax=r.parseShort(),n.yMax=r.parseShort(),n.macStyle=r.parseUShort(),n.lowestRecPPEM=r.parseUShort(),n.fontDirectionHint=r.parseShort(),n.indexToLocFormat=r.parseShort(),n.glyphDataFormat=r.parseShort(),n}function xc(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new s1.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:n},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],t)}var v8={parse:bc,make:xc};function Mc(t,e){var n={},r=new p1.Parser(t,e);return n.version=r.parseVersion(),n.ascender=r.parseShort(),n.descender=r.parseShort(),n.lineGap=r.parseShort(),n.advanceWidthMax=r.parseUShort(),n.minLeftSideBearing=r.parseShort(),n.minRightSideBearing=r.parseShort(),n.xMaxExtent=r.parseShort(),n.caretSlopeRise=r.parseShort(),n.caretSlopeRun=r.parseShort(),n.caretOffset=r.parseShort(),r.relativeOffset+=8,n.metricDataFormat=r.parseShort(),n.numberOfHMetrics=r.parseUShort(),n}function wc(t){return new s1.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],t)}var y8={parse:Mc,make:wc};function kc(t,e,n,r,c){for(var a,s,i=new p1.Parser(t,e),o=0;o<r;o+=1){o<n&&(a=i.parseUShort(),s=i.parseShort());var l=c.get(o);l.advanceWidth=a,l.leftSideBearing=s}}function zc(t,e,n,r,c){t._hmtxTableData={};for(var a,s,i=new p1.Parser(e,n),o=0;o<c;o+=1)o<r&&(a=i.parseUShort(),s=i.parseShort()),t._hmtxTableData[o]={advanceWidth:a,leftSideBearing:s}}function Sc(t,e,n,r,c,a,s){s.lowMemory?zc(t,e,n,r,c):kc(e,n,r,c,a)}function Lc(t){for(var e=new s1.Table("hmtx",[]),n=0;n<t.length;n+=1){var r=t.get(n),c=r.advanceWidth||0,a=r.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:c}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:a})}return e}var b8={parse:Sc,make:Lc};function Ac(t){for(var e=new s1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",r=12+t.length*4,c=0;c<t.length;++c){var a=n.indexOf(t[c]);a<0&&(a=n.length,n+=t[c]),e.fields.push({name:"offset "+c,type:"USHORT",value:r+a}),e.fields.push({name:"length "+c,type:"USHORT",value:t[c].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function Cc(t,e){var n=new p1.Parser(t,e),r=n.parseULong();C1.argument(r===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var c=n.parseULong(),a=[],s=0;s<c;s++){for(var i="",o=e+n.parseUShort(),l=n.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(t.getInt8(h));a.push(i)}return a}var x8={make:Ac,parse:Cc};function Pc(t,e){var n={},r=new p1.Parser(t,e);return n.version=r.parseVersion(),n.numGlyphs=r.parseUShort(),n.version===1&&(n.maxPoints=r.parseUShort(),n.maxContours=r.parseUShort(),n.maxCompositePoints=r.parseUShort(),n.maxCompositeContours=r.parseUShort(),n.maxZones=r.parseUShort(),n.maxTwilightPoints=r.parseUShort(),n.maxStorage=r.parseUShort(),n.maxFunctionDefs=r.parseUShort(),n.maxInstructionDefs=r.parseUShort(),n.maxStackElements=r.parseUShort(),n.maxSizeOfInstructions=r.parseUShort(),n.maxComponentElements=r.parseUShort(),n.maxComponentDepth=r.parseUShort()),n}function Ec(t){return new s1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var M8={parse:Pc,make:Ec},w8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],k8={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},Tc={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},z8={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function Ic(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return k8[e];case 3:return z8[e]}}var n6="utf-16",Vc={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},Hc={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function S8(t,e,n){switch(t){case 0:return n6;case 1:return Hc[n]||Vc[e];case 3:if(e===1||e===10)return n6;break}}function Oc(t,e,n){for(var r={},c=new p1.Parser(t,e),a=c.parseUShort(),s=c.parseUShort(),i=c.offset+c.parseUShort(),o=0;o<s;o++){var l=c.parseUShort(),h=c.parseUShort(),u=c.parseUShort(),f=c.parseUShort(),d=w8[f]||f,m=c.parseUShort(),g=c.parseUShort(),p=Ic(l,u,n),v=S8(l,h,u);if(v!==void 0&&p!==void 0){var y=void 0;if(v===n6?y=G3.UTF16(t,i+g,m):y=G3.MACSTRING(t,i+g,m,v),y){var b=r[d];b===void 0&&(b=r[d]={}),b[p]=y}}}var x=0;return a===1&&(x=c.parseUShort()),r}function Be(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function z7(t,e,n,r,c,a){return new s1.Record("NameRecord",[{name:"platformID",type:"USHORT",value:t},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:n},{name:"nameID",type:"USHORT",value:r},{name:"length",type:"USHORT",value:c},{name:"offset",type:"USHORT",value:a}])}function Fc(t,e){var n=t.length,r=e.length-n+1;e:for(var c=0;c<r;c++)for(;c<r;c++){for(var a=0;a<n;a++)if(e[c+a]!==t[a])continue e;return c}return-1}function S7(t,e){var n=Fc(t,e);if(n<0){n=e.length;for(var r=0,c=t.length;r<c;++r)e.push(t[r])}return n}function Rc(t,e){var n,r=[],c={},a=Be(w8);for(var s in t){var i=a[s];if(i===void 0&&(i=s),n=parseInt(i),isNaN(n))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');c[n]=t[s],r.push(n)}for(var o=Be(k8),l=Be(z8),h=[],u=[],f=0;f<r.length;f++){n=r[f];var d=c[n];for(var m in d){var g=d[m],p=1,v=o[m],y=Tc[v],b=S8(p,y,v),x=K.MACSTRING(g,b);x===void 0&&(p=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),y=4,x=K.UTF16(g));var M=S7(x,u);h.push(z7(p,y,v,n,x.length,M));var w=l[m];if(w!==void 0){var k=K.UTF16(g),z=S7(k,u);h.push(z7(3,1,w,n,k.length,z))}}}h.sort(function(L,C){return L.platformID-C.platformID||L.encodingID-C.encodingID||L.languageID-C.languageID||L.nameID-C.nameID});for(var S=new s1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),A=0;A<h.length;A++)S.fields.push({name:"record_"+A,type:"RECORD",value:h[A]});return S.fields.push({name:"strings",type:"LITERAL",value:u}),S}var L8={parse:Oc,make:Rc},r6=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function $c(t){for(var e=0;e<r6.length;e+=1){var n=r6[e];if(t>=n.begin&&t<n.end)return e}return-1}function Dc(t,e){var n={},r=new p1.Parser(t,e);n.version=r.parseUShort(),n.xAvgCharWidth=r.parseShort(),n.usWeightClass=r.parseUShort(),n.usWidthClass=r.parseUShort(),n.fsType=r.parseUShort(),n.ySubscriptXSize=r.parseShort(),n.ySubscriptYSize=r.parseShort(),n.ySubscriptXOffset=r.parseShort(),n.ySubscriptYOffset=r.parseShort(),n.ySuperscriptXSize=r.parseShort(),n.ySuperscriptYSize=r.parseShort(),n.ySuperscriptXOffset=r.parseShort(),n.ySuperscriptYOffset=r.parseShort(),n.yStrikeoutSize=r.parseShort(),n.yStrikeoutPosition=r.parseShort(),n.sFamilyClass=r.parseShort(),n.panose=[];for(var c=0;c<10;c++)n.panose[c]=r.parseByte();return n.ulUnicodeRange1=r.parseULong(),n.ulUnicodeRange2=r.parseULong(),n.ulUnicodeRange3=r.parseULong(),n.ulUnicodeRange4=r.parseULong(),n.achVendID=String.fromCharCode(r.parseByte(),r.parseByte(),r.parseByte(),r.parseByte()),n.fsSelection=r.parseUShort(),n.usFirstCharIndex=r.parseUShort(),n.usLastCharIndex=r.parseUShort(),n.sTypoAscender=r.parseShort(),n.sTypoDescender=r.parseShort(),n.sTypoLineGap=r.parseShort(),n.usWinAscent=r.parseUShort(),n.usWinDescent=r.parseUShort(),n.version>=1&&(n.ulCodePageRange1=r.parseULong(),n.ulCodePageRange2=r.parseULong()),n.version>=2&&(n.sxHeight=r.parseShort(),n.sCapHeight=r.parseShort(),n.usDefaultChar=r.parseUShort(),n.usBreakChar=r.parseUShort(),n.usMaxContent=r.parseUShort()),n}function qc(t){return new s1.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],t)}var c6={parse:Dc,make:qc,unicodeRanges:r6,getUnicodeRange:$c};function Nc(t,e){var n={},r=new p1.Parser(t,e);switch(n.version=r.parseVersion(),n.italicAngle=r.parseFixed(),n.underlinePosition=r.parseShort(),n.underlineThickness=r.parseShort(),n.isFixedPitch=r.parseULong(),n.minMemType42=r.parseULong(),n.maxMemType42=r.parseULong(),n.minMemType1=r.parseULong(),n.maxMemType1=r.parseULong(),n.version){case 1:n.names=g3.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var c=0;c<n.numberOfGlyphs;c++)n.glyphNameIndex[c]=r.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=g3.length){var s=r.parseChar();n.names.push(r.parseString(s))}break;case 2.5:n.numberOfGlyphs=r.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var i=0;i<n.numberOfGlyphs;i++)n.offset[i]=r.parseChar();break}return n}function Uc(){return new s1.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var A8={parse:Nc,make:Uc},p2=new Array(9);p2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer($.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer($.coverage),substitute:this.parseOffset16List()};C1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};p2[2]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),sequences:this.parseListOfLists()}};p2[3]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),alternateSets:this.parseListOfLists()}};p2[4]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var j3={sequenceIndex:$.uShort,lookupListIndex:$.uShort};p2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer($.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,j3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer($.coverage),classDef:this.parsePointer($.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,j3)}})};if(n===3){var r=this.parseUShort(),c=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,$.pointer($.coverage)),lookupRecords:this.parseRecordList(c,j3)}}C1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};p2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer($.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(j3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer($.coverage),backtrackClassDef:this.parsePointer($.classDef),inputClassDef:this.parsePointer($.classDef),lookaheadClassDef:this.parsePointer($.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(j3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList($.pointer($.coverage)),inputCoverage:this.parseList($.pointer($.coverage)),lookaheadCoverage:this.parseList($.pointer($.coverage)),lookupRecords:this.parseRecordList(j3)};C1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};p2[7]=function(){var e=this.parseUShort();C1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),r=new $(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:p2[n].call(r)}};p2[8]=function(){var e=this.parseUShort();return C1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer($.coverage),backtrackCoverage:this.parseList($.pointer($.coverage)),lookaheadCoverage:this.parseList($.pointer($.coverage)),substitutes:this.parseUShortList()}};function Bc(t,e){e=e||0;var n=new $(t,e),r=n.parseVersion(1);return C1.argument(r===1||r===1.1,"Unsupported GSUB table version."),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(p2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(p2),variations:n.parseFeatureVariationsList()}}var W3=new Array(9);W3[1]=function(e){return e.substFormat===1?new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.ushortList("substitute",e.substitute)))};W3[2]=function(e){return C1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("seqSet",e.sequences,function(n){return new s1.Table("sequenceSetTable",s1.ushortList("sequence",n))})))};W3[3]=function(e){return C1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("altSet",e.alternateSets,function(n){return new s1.Table("alternateSetTable",s1.ushortList("alternate",n))})))};W3[4]=function(e){return C1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new s1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("ligSet",e.ligatureSets,function(n){return new s1.Table("ligatureSetTable",s1.tableList("ligature",n,function(r){return new s1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:r.ligGlyph}].concat(s1.ushortList("component",r.components,r.components.length+1)))}))})))};W3[6]=function(e){if(e.substFormat===1){var n=new s1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new s1.Coverage(e.coverage)}].concat(s1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new s1.Table("chainRuleSetTable",s1.tableList("chainRule",a,function(s){var i=s1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(s1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(s1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(s1.ushortList("substitution",[],s.lookupRecords.length));return s.lookupRecords.forEach(function(o,l){i=i.concat({name:"sequenceIndex"+l,type:"USHORT",value:o.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:o.lookupListIndex})}),new s1.Table("chainRuleTable",i)}))})));return n}else if(e.substFormat===2)C1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var r=[{name:"substFormat",type:"USHORT",value:e.substFormat}];r.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(a,s){r.push({name:"backtrackCoverage"+s,type:"TABLE",value:new s1.Coverage(a)})}),r.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){r.push({name:"inputCoverage"+s,type:"TABLE",value:new s1.Coverage(a)})}),r.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){r.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new s1.Coverage(a)})}),r.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){r=r.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var c=new s1.Table("chainContextTable",r);return c}C1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function _c(t){return new s1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new s1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new s1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new s1.LookupList(t.lookups,W3)}])}var C8={parse:Bc,make:_c};function jc(t,e){var n=new p1.Parser(t,e),r=n.parseULong();C1.argument(r===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var c=n.parseULong(),a={},s=0;s<c;s++){var i=n.parseTag(),o=n.parseULong(),l=n.parseULong(),h=G3.UTF8(t,e+o,l);a[i]=h}return a}function Gc(t){var e=Object.keys(t).length,n="",r=16+e*12,c=new s1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:r},{name:"numTags",type:"ULONG",value:e}]);for(var a in t){var s=n.length;n+=t[a],c.fields.push({name:"tag "+a,type:"TAG",value:a}),c.fields.push({name:"offset "+a,type:"ULONG",value:r+s}),c.fields.push({name:"length "+a,type:"ULONG",value:t[a].length})}return c.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),c}var P8={parse:jc,make:Gc};function L7(t){return Math.log(t)/Math.log(2)|0}function f6(t){for(;t.length%4!==0;)t.push(0);for(var e=0,n=0;n<t.length;n+=4)e+=(t[n]<<24)+(t[n+1]<<16)+(t[n+2]<<8)+t[n+3];return e%=Math.pow(2,32),e}function A7(t,e,n,r){return new s1.Record("Table Record",[{name:"tag",type:"TAG",value:t!==void 0?t:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:n!==void 0?n:0},{name:"length",type:"ULONG",value:r!==void 0?r:0}])}function E8(t){var e=new s1.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=t,e.numTables=t.length;var n=Math.pow(2,L7(e.numTables));e.searchRange=16*n,e.entrySelector=L7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],c=[],a=e.sizeOf()+A7().sizeOf()*e.numTables;a%4!==0;)a+=1,c.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var i=t[s];C1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=A7(i.tableName,f6(i.encode()),a,o);for(r.push({name:l.tag+" Table Record",type:"RECORD",value:l}),c.push({name:i.tableName+" table",type:"RECORD",value:i}),a+=o,C1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,c.push({name:"padding",type:"BYTE",value:0})}return r.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(r),e.fields=e.fields.concat(c),e}function C7(t,e,n){for(var r=0;r<e.length;r+=1){var c=t.charToGlyphIndex(e[r]);if(c>0){var a=t.glyphs.get(c);return a.getMetrics()}}return n}function Wc(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function Xc(t){for(var e=[],n=[],r=[],c=[],a=[],s=[],i=[],o,l=0,h=0,u=0,f=0,d=0,m=0;m<t.glyphs.length;m+=1){var g=t.glyphs.get(m),p=g.unicode|0;if(isNaN(g.advanceWidth))throw new Error("Glyph "+g.name+" ("+m+"): advanceWidth is not a number.");(o>p||o===void 0)&&p>0&&(o=p),l<p&&(l=p);var v=c6.getUnicodeRange(p);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(g.name!==".notdef"){var y=g.getMetrics();e.push(y.xMin),n.push(y.yMin),r.push(y.xMax),c.push(y.yMax),s.push(y.leftSideBearing),i.push(y.rightSideBearing),a.push(g.advanceWidth)}}var b={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,r),yMax:Math.max.apply(null,c),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:Wc(a),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,i)};b.ascender=t.ascender,b.descender=t.descender;var x=v8.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:b.xMin,yMin:b.yMin,xMax:b.xMax,yMax:b.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),M=y8.make({ascender:b.ascender,descender:b.descender,advanceWidthMax:b.advanceWidthMax,minLeftSideBearing:b.minLeftSideBearing,minRightSideBearing:b.minRightSideBearing,xMaxExtent:b.maxLeftSideBearing+(b.xMax-b.xMin),numberOfHMetrics:t.glyphs.length}),w=M8.make(t.glyphs.length),k=c6.make(Object.assign({xAvgCharWidth:Math.round(b.advanceWidthAvg),usFirstCharIndex:o,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:b.ascender,sTypoDescender:b.descender,sTypoLineGap:0,usWinAscent:b.yMax,usWinDescent:Math.abs(b.yMin),ulCodePageRange1:1,sxHeight:C7(t,"xyvw",{yMax:Math.round(b.ascender/2)}).yMax,sCapHeight:C7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",b).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=b8.make(t.glyphs),S=a8.make(t.glyphs),A=t.getEnglishName("fontFamily"),L=t.getEnglishName("fontSubfamily"),C=A+" "+L,P=t.getEnglishName("postScriptName");P||(P=A.replace(/\s/g,"")+"-"+L);var R={};for(var q in t.names)R[q]=t.names[q];R.uniqueID||(R.uniqueID={en:t.getEnglishName("manufacturer")+":"+C}),R.postScriptName||(R.postScriptName={en:P}),R.preferredFamily||(R.preferredFamily=t.names.fontFamily),R.preferredSubfamily||(R.preferredSubfamily=t.names.fontSubfamily);var T=[],B=L8.make(R,T),X=T.length>0?x8.make(T):void 0,Z=A8.make(),h1=g8.make(t.glyphs,{version:t.getEnglishName("version"),fullName:C,familyName:A,weightName:L,postScriptName:P,unitsPerEm:t.unitsPerEm,fontBBox:[0,b.yMin,b.ascender,b.advanceWidthMax]}),H=t.metas&&Object.keys(t.metas).length>0?P8.make(t.metas):void 0,U=[x,M,w,k,B,S,Z,h1,z];X&&U.push(X),t.tables.gsub&&U.push(C8.make(t.tables.gsub)),H&&U.push(H);for(var Y=E8(U),Q=Y.encode(),W=f6(Q),F1=Y.fields,L1=!1,g1=0;g1<F1.length;g1+=1)if(F1[g1].name==="head table"){F1[g1].value.checkSumAdjustment=2981146554-W,L1=!0;break}if(!L1)throw new Error("Could not find head table with checkSum to adjust.");return Y}var Zc={make:E8,fontToTable:Xc,computeCheckSum:f6};function _e(t,e){for(var n=0,r=t.length-1;n<=r;){var c=n+r>>>1,a=t[c].tag;if(a===e)return c;a<e?n=c+1:r=c-1}return-n-1}function P7(t,e){for(var n=0,r=t.length-1;n<=r;){var c=n+r>>>1,a=t[c];if(a===e)return c;a<e?n=c+1:r=c-1}return-n-1}function E7(t,e){for(var n,r=0,c=t.length-1;r<=c;){var a=r+c>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?r=a+1:c=a-1}if(r>0)return n=t[r-1],e>n.end?0:n}function F5(t,e){this.font=t,this.tableName=e}F5.prototype={searchTag:_e,binSearch:P7,getTable:function(t){var e=this.font.tables[this.tableName];return!e&&t&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var t=this.getTable();return t?t.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var t=this.getTable();if(t){for(var e=!1,n=0;n<t.scripts.length;n++){var r=t.scripts[n].tag;if(r==="DFLT")return r;r==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var r=n.scripts,c=_e(n.scripts,t);if(c>=0)return r[c].script;if(e){var a={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-c,0,a),a.script}}},getLangSysTable:function(t,e,n){var r=this.getScriptTable(t,n);if(r){if(!e||e==="dflt"||e==="DFLT")return r.defaultLangSys;var c=_e(r.langSysRecords,e);if(c>=0)return r.langSysRecords[c].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-c,0,a),a.langSys}}},getFeatureTable:function(t,e,n,r){var c=this.getLangSysTable(t,e,r);if(c){for(var a,s=c.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(a=i[s[o]],a.tag===n)return a.feature;if(r){var l=i.length;return C1.assert(l===0||n>=i[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},i.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,r,c){var a=this.getFeatureTable(t,e,n,c),s=[];if(a){for(var i,o=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===r&&s.push(i);if(s.length===0&&c){i={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(i),o.push(u),[i]}}return s},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=E7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=P7(t.glyphs,e);return n>=0?n:-1;case 2:var r=E7(t.ranges,e);return r?r.index+e-r.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,r=0;r<n.length;r++)for(var c=n[r],a=c.start,s=c.end,i=a;i<=s;i++)e.push(i);return e}};function R5(t){F5.call(this,t,"gpos")}R5.prototype=F5.prototype;R5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};R5.prototype.getKerningValue=function(t,e,n){for(var r=0;r<t.length;r++)for(var c=t[r].subtables,a=0;a<c.length;a++){var s=c[a],i=this.getCoverageIndex(s.coverage,e);if(!(i<0))switch(s.posFormat){case 1:for(var o=s.pairSets[i],l=0;l<o.length;l++){var h=o[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};R5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function t2(t){F5.call(this,t,"gsub")}function Yc(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}function d6(t,e,n){for(var r=t.subtables,c=0;c<r.length;c++){var a=r[c];if(a.substFormat===e)return a}if(n)return r.push(n),n}t2.prototype=F5.prototype;t2.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};t2.prototype.getSingle=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,1),a=0;a<c.length;a++)for(var s=c[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;if(o.substFormat===1){var u=o.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];r.push({sub:f,by:f+u})}}else{var d=o.substitute;for(h=0;h<l.length;h++)r.push({sub:l[h],by:d[h]})}}return r};t2.prototype.getMultiple=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,2),a=0;a<c.length;a++)for(var s=c[a].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=o.sequences[h];r.push({sub:u,by:f})}}return r};t2.prototype.getAlternates=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,3),a=0;a<c.length;a++)for(var s=c[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.alternateSets,u=0;u<l.length;u++)r.push({sub:l[u],by:h[u]});return r};t2.prototype.getLigatures=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,4),a=0;a<c.length;a++)for(var s=c[a].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],m=0;m<d.length;m++){var g=d[m];r.push({sub:[f].concat(g.components),by:g.ligGlyph})}return r};t2.prototype.addSingle=function(t,e,n,r){var c=this.getLookupTables(n,r,t,1,!0)[0],a=d6(c,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});C1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.substitute.splice(i,0,0)),a.substitute[i]=e.by};t2.prototype.addMultiple=function(t,e,n,r){C1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var c=this.getLookupTables(n,r,t,2,!0)[0],a=d6(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});C1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.sequences.splice(i,0,0)),a.sequences[i]=e.by};t2.prototype.addAlternate=function(t,e,n,r){var c=this.getLookupTables(n,r,t,3,!0)[0],a=d6(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});C1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,i=this.binSearch(a.coverage.glyphs,s);i<0&&(i=-1-i,a.coverage.glyphs.splice(i,0,s),a.alternateSets.splice(i,0,0)),a.alternateSets[i]=e.by};t2.prototype.addLigature=function(t,e,n,r){var c=this.getLookupTables(n,r,t,4,!0)[0],a=c.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},c.subtables[0]=a),C1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(Yc(h[u].components,i))return;h.push(o)}else l=-1-l,a.coverage.glyphs.splice(l,0,s),a.ligatureSets.splice(l,0,[o])};t2.prototype.getFeature=function(t,e,n){if(/ss\d\d/.test(t))return this.getSingle(t,e,n);switch(t){case"aalt":case"salt":return this.getSingle(t,e,n).concat(this.getAlternates(t,e,n));case"dlig":case"liga":case"rlig":return this.getLigatures(t,e,n);case"ccmp":return this.getMultiple(t,e,n).concat(this.getLigatures(t,e,n));case"stch":return this.getMultiple(t,e,n)}};t2.prototype.add=function(t,e,n,r){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,r);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,r):this.addAlternate(t,e,n,r);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,r);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,r):this.addLigature(t,e,n,r)}};function Jc(){return typeof window<"u"}function Kc(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),r=0;r<e.length;++r)e[r]=n[r];return e}function E5(t,e){if(!t)throw e}function T7(t,e,n,r,c){var a;return(e&r)>0?(a=t.parseByte(),(e&c)===0&&(a=-a),a=n+a):(e&c)>0?a=n:a=n+t.parseShort(),a}function T8(t,e,n){var r=new p1.Parser(e,n);t.numberOfContours=r.parseShort(),t._xMin=r.parseShort(),t._yMin=r.parseShort(),t._xMax=r.parseShort(),t._yMax=r.parseShort();var c,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],i=0;i<t.numberOfContours;i+=1)s.push(r.parseUShort());t.instructionLength=r.parseUShort(),t.instructions=[];for(var o=0;o<t.instructionLength;o+=1)t.instructions.push(r.parseByte());var l=s[s.length-1]+1;c=[];for(var h=0;h<l;h+=1)if(a=r.parseByte(),c.push(a),(a&8)>0)for(var u=r.parseByte(),f=0;f<u;f+=1)c.push(a),h+=1;if(C1.argument(c.length===l,"Bad flags."),s.length>0){var d=[],m;if(l>0){for(var g=0;g<l;g+=1)a=c[g],m={},m.onCurve=!!(a&1),m.lastPointOfContour=s.indexOf(g)>=0,d.push(m);for(var p=0,v=0;v<l;v+=1)a=c[v],m=d[v],m.x=T7(r,a,p,2,16),p=m.x;for(var y=0,b=0;b<l;b+=1)a=c[b],m=d[b],m.y=T7(r,a,y,4,32),y=m.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){c=r.parseUShort();var M={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(c&1)>0?(c&2)>0?(M.dx=r.parseShort(),M.dy=r.parseShort()):M.matchedPoints=[r.parseUShort(),r.parseUShort()]:(c&2)>0?(M.dx=r.parseChar(),M.dy=r.parseChar()):M.matchedPoints=[r.parseByte(),r.parseByte()],(c&8)>0?M.xScale=M.yScale=r.parseF2Dot14():(c&64)>0?(M.xScale=r.parseF2Dot14(),M.yScale=r.parseF2Dot14()):(c&128)>0&&(M.xScale=r.parseF2Dot14(),M.scale01=r.parseF2Dot14(),M.scale10=r.parseF2Dot14(),M.yScale=r.parseF2Dot14()),t.components.push(M),x=!!(c&32)}if(c&256){t.instructionLength=r.parseUShort(),t.instructions=[];for(var w=0;w<t.instructionLength;w+=1)t.instructions.push(r.parseByte())}}}function je(t,e){for(var n=[],r=0;r<t.length;r+=1){var c=t[r],a={x:e.xScale*c.x+e.scale01*c.y+e.dx,y:e.scale10*c.x+e.yScale*c.y+e.dy,onCurve:c.onCurve,lastPointOfContour:c.lastPointOfContour};n.push(a)}return n}function Qc(t){for(var e=[],n=[],r=0;r<t.length;r+=1){var c=t[r];n.push(c),c.lastPointOfContour&&(e.push(n),n=[])}return C1.argument(n.length===0,"There are still points left in the current contour."),e}function I8(t){var e=new P0;if(!t)return e;for(var n=Qc(t),r=0;r<n.length;++r){var c=n[r],a=null,s=c[c.length-1],i=c[0];if(s.onCurve)e.moveTo(s.x,s.y);else if(i.onCurve)e.moveTo(i.x,i.y);else{var o={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5};e.moveTo(o.x,o.y)}for(var l=0;l<c.length;++l)if(a=s,s=i,i=c[(l+1)%c.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=a,u=i;a.onCurve||(h={x:(s.x+a.x)*.5,y:(s.y+a.y)*.5}),i.onCurve||(u={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5}),e.quadraticCurveTo(s.x,s.y,u.x,u.y)}e.closePath()}return e}function V8(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var r=e.components[n],c=t.get(r.glyphIndex);if(c.getPath(),c.points){var a=void 0;if(r.matchedPoints===void 0)a=je(c.points,r);else{if(r.matchedPoints[0]>e.points.length-1||r.matchedPoints[1]>c.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[r.matchedPoints[0]],i=c.points[r.matchedPoints[1]],o={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};i=je([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,a=je(c.points,o)}e.points=e.points.concat(a)}}return I8(e.points)}function ea(t,e,n,r){for(var c=new T2.GlyphSet(r),a=0;a<n.length-1;a+=1){var s=n[a],i=n[a+1];s!==i?c.push(a,T2.ttfGlyphLoader(r,a,T8,t,e+s,V8)):c.push(a,T2.glyphLoader(r,a))}return c}function ta(t,e,n,r){var c=new T2.GlyphSet(r);return r._push=function(a){var s=n[a],i=n[a+1];s!==i?c.push(a,T2.ttfGlyphLoader(r,a,T8,t,e+s,V8)):c.push(a,T2.glyphLoader(r,a))},c}function na(t,e,n,r,c){return c.lowMemory?ta(t,e,n,r):ea(t,e,n,r)}var H8={getPath:I8,parse:na},O8,y3,F8,a6;function R8(t){this.font=t,this.getCommands=function(e){return H8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function ra(t){return t}function $8(t){return Math.sign(t)*Math.round(Math.abs(t))}function ca(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function aa(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function sa(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function ia(t){return Math.sign(t)*Math.floor(Math.abs(t))}var D8=function(t){var e=this.srPeriod,n=this.srPhase,r=this.srThreshold,c=1;return t<0&&(t=-t,c=-1),t+=r-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*c:t*c},E2={x:1,y:0,axis:"x",distance:function(t,e,n,r){return(n?t.xo:t.x)-(r?e.xo:e.x)},interpolate:function(t,e,n,r){var c,a,s,i,o,l,h;if(!r||r===this){if(c=t.xo-e.xo,a=t.xo-n.xo,o=e.x-e.xo,l=n.x-n.xo,s=Math.abs(c),i=Math.abs(a),h=s+i,h===0){t.x=t.xo+(o+l)/2;return}t.x=t.xo+(o*i+l*s)/h;return}if(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),o=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),i=Math.abs(a),h=s+i,h===0){E2.setRelative(t,t,(o+l)/2,r,!0);return}E2.setRelative(t,t,(o*i+l*s)/h,r,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,r,c){if(!r||r===this){t.x=(c?e.xo:e.x)+n;return}var a=c?e.xo:e.x,s=c?e.yo:e.y,i=a+n*r.x,o=s+n*r.y;t.x=i+(t.y-o)/r.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},q2={x:0,y:1,axis:"y",distance:function(t,e,n,r){return(n?t.yo:t.y)-(r?e.yo:e.y)},interpolate:function(t,e,n,r){var c,a,s,i,o,l,h;if(!r||r===this){if(c=t.yo-e.yo,a=t.yo-n.yo,o=e.y-e.yo,l=n.y-n.yo,s=Math.abs(c),i=Math.abs(a),h=s+i,h===0){t.y=t.yo+(o+l)/2;return}t.y=t.yo+(o*i+l*s)/h;return}if(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),o=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),i=Math.abs(a),h=s+i,h===0){q2.setRelative(t,t,(o+l)/2,r,!0);return}q2.setRelative(t,t,(o*i+l*s)/h,r,!0)},normalSlope:0,setRelative:function(t,e,n,r,c){if(!r||r===this){t.y=(c?e.yo:e.y)+n;return}var a=c?e.xo:e.x,s=c?e.yo:e.y,i=a+n*r.x,o=s+n*r.y;t.y=o+r.normalSlope*(t.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(E2);Object.freeze(q2);function $5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}$5.prototype.distance=function(t,e,n,r){return this.x*E2.distance(t,e,n,r)+this.y*q2.distance(t,e,n,r)};$5.prototype.interpolate=function(t,e,n,r){var c,a,s,i,o,l,h;if(s=r.distance(t,e,!0,!0),i=r.distance(t,n,!0,!0),c=r.distance(e,e,!1,!0),a=r.distance(n,n,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(t,t,(c+a)/2,r,!0);return}this.setRelative(t,t,(c*l+a*o)/h,r,!0)};$5.prototype.setRelative=function(t,e,n,r,c){r=r||this;var a=c?e.xo:e.x,s=c?e.yo:e.y,i=a+n*r.x,o=s+n*r.y,l=r.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*i+o-f)/(h-l),t.y=h*(t.x-u)+f};$5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function D5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?E2:t===0&&e===1?q2:new $5(t,e)}function N2(t,e,n,r){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=r,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}N2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};N2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var O5=Object.freeze(new N2(0,0)),oa={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function Q2(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=E2,this.round=$8}}R8.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,r=this._prepState;if(!r||r.ppem!==e){var c=this._fpgmState;if(!c){Q2.prototype=oa,c=this._fpgmState=new Q2("fpgm",n.tables.fpgm),c.funcs=[],c.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),c.step=-1);try{y3(c)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}Q2.prototype=c,r=this._prepState=new Q2("prep",n.tables.prep),r.ppem=e;var a=n.tables.cvt;if(a)for(var s=r.cvt=new Array(a.length),i=e/n.unitsPerEm,o=0;o<a.length;o++)s[o]=a[o]*i;else r.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),r.step=-1);try{y3(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return F8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};F8=function(t,e){var n=e.ppem/e.font.unitsPerEm,r=n,c=t.components,a,s,i;if(Q2.prototype=e,!c)i=new Q2("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),a6(t,i,n,r),s=i.gZone;else{var o=e.font;s=[],a=[];for(var l=0;l<c.length;l++){var h=c[l],u=o.glyphs.get(h.glyphIndex);i=new Q2("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),a6(u,i,n,r);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*r),m=i.gZone,g=i.contours,p=0;p<m.length;p++){var v=m[p];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var y=s.length;s.push.apply(s,m);for(var b=0;b<g.length;b++)a.push(g[b]+y)}t.instructions&&!i.inhibitGridFit&&(i=new Q2("glyf",t.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=a,s.push(new N2(0,0),new N2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),y3(i),s.length-=2)}return s};a6=function(t,e,n,r){for(var c=t.points||[],a=c.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<a;l++)o=c[l],s[l]=new N2(o.x*n,o.y*r,o.lastPointOfContour,o.onCurve);for(var h,u,f=0;f<a;f++)o=s[f],h||(h=o,i.push(f)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(u=s[f+1],o.nextPointOnContour=u,u.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new N2(0,0),new N2(Math.round(t.advanceWidth*n),0)),y3(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<a;m++)console.log(m,s[m].x,s[m].y)}}};y3=function(t){var e=t.prog;if(e){var n=e.length,r;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,r=O8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function $4(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new N2(0,0)}function q8(t,e){var n=t.prog,r=t.ip,c=1,a;do if(a=n[++r],a===88)c++;else if(a===89)c--;else if(a===64)r+=n[r+1]+1;else if(a===65)r+=2*n[r+1]+1;else if(a>=176&&a<=183)r+=a-176+1;else if(a>=184&&a<=191)r+=(a-184+1)*2;else if(e&&c===1&&a===27)break;while(c>0);t.ip=r}function I7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function V7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function H7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function O7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log("SPVTL["+t+"]",r,c);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.pv=e.dpv=D5(i,o)}function F7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log("SFVTL["+t+"]",r,c);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.fv=D5(i,o)}function la(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.pv=t.dpv=D5(r,n)}function ha(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.fv=D5(r,n)}function ua(t){var e=t.stack,n=t.pv;exports.DEBUG&&console.log(t.step,"GPV[]"),e.push(n.x*16384),e.push(n.y*16384)}function fa(t){var e=t.stack,n=t.fv;exports.DEBUG&&console.log(t.step,"GFV[]"),e.push(n.x*16384),e.push(n.y*16384)}function da(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function ma(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop(),a=e.pop(),s=e.pop(),i=t.z0,o=t.z1,l=i[n],h=i[r],u=o[c],f=o[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,r,c,a,s);var m=l.x,g=l.y,p=h.x,v=h.y,y=u.x,b=u.y,x=f.x,M=f.y,w=(m-p)*(b-M)-(g-v)*(y-x),k=m*v-g*p,z=y*M-b*x;d.x=(k*(y-x)-z*(m-p))/w,d.y=(k*(b-M)-z*(g-v))/w}function pa(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function ga(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function va(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function ya(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||$4(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function ba(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||$4(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function xa(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||$4(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function Ma(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZPS[]",e),t.zp0=t.zp1=t.zp2=e,e){case 0:t.tZone||$4(t),t.z0=t.z1=t.z2=t.tZone;break;case 1:t.z0=t.z1=t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function wa(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function ka(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=$8}function za(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=aa}function Sa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function La(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),q8(t,!1)}function Aa(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function Ca(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function Pa(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function Ge(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function Ea(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function Ta(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(r)}function Ia(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function Va(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,r);var c=t.ip,a=t.prog;t.prog=t.funcs[n];for(var s=0;s<r;s++)y3(t),exports.DEBUG&&console.log(++t.step,s+1<r?"next loopcall":"done loopcall",s);t.ip=c,t.prog=a}function Ha(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,r=t.prog;t.prog=t.funcs[e],y3(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function Oa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function Fa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"MINDEX[]",n),e.push(e.splice(e.length-n,1)[0])}function Ra(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,r=t.ip,c=e.pop(),a=r;for(exports.DEBUG&&console.log(t.step,"FDEF[]",c);n[++r]!==45;);t.ip=r,t.funcs[c]=n.slice(a+1,r)}function R7(t,e){var n=e.stack.pop(),r=e.z0[n],c=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(r,O5);t&&(s=e.round(s)),c.setRelative(r,O5,s,a),c.touch(r),e.rp0=e.rp1=n}function $7(t,e){var n=e.z2,r=n.length-2,c,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var i=0;i<r;i++)c=n[i],!t.touched(c)&&(a=c.prevTouched(t),a!==c&&(s=c.nextTouched(t),a===s&&t.setRelative(c,c,t.distance(a,a,!1,!0),t,!0),t.interpolate(c,a,s,t)))}function D7(t,e){for(var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,i=e.loop,o=e.z2;i--;){var l=n.pop(),h=o[l],u=s.distance(c,c,!1,!0);a.setRelative(h,h,u,s),a.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-i)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function q7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,i=n.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",i);var h=s.distance(c,c,!1,!0);do l!==c&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function N7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,i=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",i);var o;switch(i){case 0:o=e.tZone;break;case 1:o=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=s.distance(c,c,!1,!0),u=o.length-2,f=0;f<u;f++)l=o[f],a.setRelative(l,l,h,s)}function $a(t){for(var e=t.stack,n=t.loop,r=t.fv,c=e.pop()/64,a=t.z2;n--;){var s=e.pop(),i=a[s];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",s,c),r.setRelative(i,i,c),r.touch(i)}t.loop=1}function Da(t){for(var e=t.stack,n=t.rp1,r=t.rp2,c=t.loop,a=t.z0[n],s=t.z1[r],i=t.fv,o=t.dpv,l=t.z2;c--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"IP[]",h,n,"<->",r),i.interpolate(u,a,s,o),i.touch(u)}t.loop=1}function U7(t,e){var n=e.stack,r=n.pop()/64,c=n.pop(),a=e.z1[c],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(a,s,r,o),i.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",r,c),e.rp1=e.rp0,e.rp2=c,t&&(e.rp0=c)}function qa(t){for(var e=t.stack,n=t.rp0,r=t.z0[n],c=t.loop,a=t.fv,s=t.pv,i=t.z1;c--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"ALIGNRP[]",o),a.setRelative(l,r,0,s),a.touch(l)}t.loop=1}function Na(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=ca}function B7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z0[c],s=e.fv,i=e.pv,o=e.cvt[r];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",r,"(",o,")",c);var l=i.distance(a,O5);t&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(a,O5,l,i),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=c}function Ua(t){var e=t.prog,n=t.ip,r=t.stack,c=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",c);for(var a=0;a<c;a++)r.push(e[++n]);t.ip=n}function Ba(t){var e=t.ip,n=t.prog,r=t.stack,c=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",c);for(var a=0;a<c;a++){var s=n[++e]<<8|n[++e];s&32768&&(s=-((s^65535)+1)),r.push(s)}t.ip=e}function _a(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var r=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WS",r,c),n[c]=r}function ja(t){var e=t.stack,n=t.store,r=e.pop();exports.DEBUG&&console.log(t.step,"RS",r);var c=n&&n[r]||0;e.push(c)}function Ga(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,r),t.cvt[r]=n/64}function Wa(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function _7(t,e){var n=e.stack,r=n.pop(),c=e.z2[r];exports.DEBUG&&console.log(e.step,"GC["+t+"]",r),n.push(e.dpv.distance(c,O5,t,!1)*64)}function j7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z1[r],s=e.z0[c],i=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",r,c,"->",i),e.stack.push(Math.round(i*64))}function Xa(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function Za(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Ya(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,r),e.push(r<n?1:0)}function Ja(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,r),e.push(r<=n?1:0)}function Ka(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,r),e.push(r>n?1:0)}function Qa(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,r),e.push(r>=n?1:0)}function es(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,r),e.push(n===r?1:0)}function ts(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,r),e.push(n!==r?1:0)}function ns(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ODD[]",n),e.push(Math.trunc(n)%2?1:0)}function rs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"EVEN[]",n),e.push(Math.trunc(n)%2?0:1)}function cs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(q8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function as(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function ss(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,r),e.push(n&&r?1:0)}function is(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,r),e.push(n||r?1:0)}function os(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function We(t,e){var n=e.stack,r=n.pop(),c=e.fv,a=e.pv,s=e.ppem,i=e.deltaBase+(t-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",r,n);for(var h=0;h<r;h++){var u=n.pop(),f=n.pop(),d=i+((f&240)>>4);if(d===s){var m=(f&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",m*o);var g=l[u];c.setRelative(g,g,m*o,a)}}}function ls(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function hs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function us(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,r),e.push(r+n)}function fs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,r),e.push(r-n)}function ds(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,r),e.push(r*64/n)}function ms(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,r),e.push(r*n/64)}function ps(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function gs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function vs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function ys(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function P4(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function bs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,r),t.cvt[r]=n*t.ppem/t.font.unitsPerEm}function Xe(t,e){var n=e.stack,r=n.pop(),c=e.ppem,a=e.deltaBase+(t-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",r,n);for(var i=0;i<r;i++){var o=n.pop(),l=n.pop(),h=a+((l&240)>>4);if(h===c){var u=(l&15)-8;u>=0&&u++;var f=u*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",o,"by",f),e.cvt[o]+=f}}}function xs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=D8;var n;switch(e&192){case 0:n=.5;break;case 64:n=1;break;case 128:n=2;break;default:throw new Error("invalid SROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function Ms(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=D8;var n;switch(e&192){case 0:n=Math.sqrt(2)/2;break;case 64:n=Math.sqrt(2);break;case 128:n=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(t.srPeriod=n,e&48){case 0:t.srPhase=0;break;case 16:t.srPhase=.25*n;break;case 32:t.srPhase=.5*n;break;case 48:t.srPhase=.75*n;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?t.srThreshold=0:t.srThreshold=(e/8-.5)*n}function ws(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=ra}function ks(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=sa}function zs(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=ia}function Ss(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function G7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",r,c);var i,o;t?(i=a.y-s.y,o=s.x-a.x):(i=s.x-a.x,o=s.y-a.y),e.dpv=D5(i,o)}function Ls(t){var e=t.stack,n=e.pop(),r=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(r=35),n&32&&(r|=4096),e.push(r)}function As(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(r),e.push(n),e.push(c)}function Cs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,r),e.push(Math.max(r,n))}function Ps(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,r),e.push(Math.min(r,n))}function Es(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function Ts(t){var e=t.stack.pop(),n=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"INSTCTRL[]",e,n),e){case 1:t.inhibitGridFit=!!n;return;case 2:t.ignoreCvt=!!n;return;default:throw new Error("invalid INSTCTRL[] selector")}}function Y2(t,e){var n=e.stack,r=e.prog,c=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(r[++c]);e.ip=c}function J2(t,e){var n=e.ip,r=e.prog,c=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=r[++n]<<8|r[++n];s&32768&&(s=-((s^65535)+1)),c.push(s)}e.ip=n}function f1(t,e,n,r,c,a){var s=a.stack,i=t&&s.pop(),o=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[o],f=a.minDis,d=a.fv,m=a.dpv,g,p,v,y;p=g=m.distance(u,h,!0,!0),v=p>=0?1:-1,p=Math.abs(p),t&&(y=a.cvt[i],r&&Math.abs(p-y)<a.cvCutIn&&(p=y)),n&&p<f&&(p=f),r&&(p=a.round(p)),d.setRelative(u,h,v*p,m),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(r?"R":"_")+(c===0?"Gr":c===1?"Bl":c===2?"Wh":"")+"]",t?i+"("+a.cvt[i]+","+y+")":"",o,"(d =",g,"->",v*p,")"),a.rp1=a.rp0,a.rp2=o,e&&(a.rp0=o)}O8=[I7.bind(void 0,q2),I7.bind(void 0,E2),V7.bind(void 0,q2),V7.bind(void 0,E2),H7.bind(void 0,q2),H7.bind(void 0,E2),O7.bind(void 0,0),O7.bind(void 0,1),F7.bind(void 0,0),F7.bind(void 0,1),la,ha,ua,fa,da,ma,pa,ga,va,ya,ba,xa,Ma,wa,ka,za,Sa,La,Aa,Ca,void 0,void 0,Pa,Ge,Ea,Ta,Ia,Oa,Fa,void 0,void 0,void 0,Va,Ha,Ra,void 0,R7.bind(void 0,0),R7.bind(void 0,1),$7.bind(void 0,q2),$7.bind(void 0,E2),D7.bind(void 0,0),D7.bind(void 0,1),q7.bind(void 0,0),q7.bind(void 0,1),N7.bind(void 0,0),N7.bind(void 0,1),$a,Da,U7.bind(void 0,0),U7.bind(void 0,1),qa,Na,B7.bind(void 0,0),B7.bind(void 0,1),Ua,Ba,_a,ja,Ga,Wa,_7.bind(void 0,0),_7.bind(void 0,1),void 0,j7.bind(void 0,0),j7.bind(void 0,1),Xa,void 0,Za,void 0,void 0,Ya,Ja,Ka,Qa,es,ts,ns,rs,cs,as,ss,is,os,We.bind(void 0,1),ls,hs,us,fs,ds,ms,ps,gs,vs,ys,P4.bind(void 0,0),P4.bind(void 0,1),P4.bind(void 0,2),P4.bind(void 0,3),void 0,void 0,void 0,void 0,bs,We.bind(void 0,2),We.bind(void 0,3),Xe.bind(void 0,1),Xe.bind(void 0,2),Xe.bind(void 0,3),xs,Ms,void 0,void 0,ws,void 0,ks,zs,Ge,Ge,void 0,void 0,void 0,void 0,void 0,Ss,G7.bind(void 0,0),G7.bind(void 0,1),Ls,void 0,As,Cs,Ps,Es,Ts,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,Y2.bind(void 0,1),Y2.bind(void 0,2),Y2.bind(void 0,3),Y2.bind(void 0,4),Y2.bind(void 0,5),Y2.bind(void 0,6),Y2.bind(void 0,7),Y2.bind(void 0,8),J2.bind(void 0,1),J2.bind(void 0,2),J2.bind(void 0,3),J2.bind(void 0,4),J2.bind(void 0,5),J2.bind(void 0,6),J2.bind(void 0,7),J2.bind(void 0,8),f1.bind(void 0,0,0,0,0,0),f1.bind(void 0,0,0,0,0,1),f1.bind(void 0,0,0,0,0,2),f1.bind(void 0,0,0,0,0,3),f1.bind(void 0,0,0,0,1,0),f1.bind(void 0,0,0,0,1,1),f1.bind(void 0,0,0,0,1,2),f1.bind(void 0,0,0,0,1,3),f1.bind(void 0,0,0,1,0,0),f1.bind(void 0,0,0,1,0,1),f1.bind(void 0,0,0,1,0,2),f1.bind(void 0,0,0,1,0,3),f1.bind(void 0,0,0,1,1,0),f1.bind(void 0,0,0,1,1,1),f1.bind(void 0,0,0,1,1,2),f1.bind(void 0,0,0,1,1,3),f1.bind(void 0,0,1,0,0,0),f1.bind(void 0,0,1,0,0,1),f1.bind(void 0,0,1,0,0,2),f1.bind(void 0,0,1,0,0,3),f1.bind(void 0,0,1,0,1,0),f1.bind(void 0,0,1,0,1,1),f1.bind(void 0,0,1,0,1,2),f1.bind(void 0,0,1,0,1,3),f1.bind(void 0,0,1,1,0,0),f1.bind(void 0,0,1,1,0,1),f1.bind(void 0,0,1,1,0,2),f1.bind(void 0,0,1,1,0,3),f1.bind(void 0,0,1,1,1,0),f1.bind(void 0,0,1,1,1,1),f1.bind(void 0,0,1,1,1,2),f1.bind(void 0,0,1,1,1,3),f1.bind(void 0,1,0,0,0,0),f1.bind(void 0,1,0,0,0,1),f1.bind(void 0,1,0,0,0,2),f1.bind(void 0,1,0,0,0,3),f1.bind(void 0,1,0,0,1,0),f1.bind(void 0,1,0,0,1,1),f1.bind(void 0,1,0,0,1,2),f1.bind(void 0,1,0,0,1,3),f1.bind(void 0,1,0,1,0,0),f1.bind(void 0,1,0,1,0,1),f1.bind(void 0,1,0,1,0,2),f1.bind(void 0,1,0,1,0,3),f1.bind(void 0,1,0,1,1,0),f1.bind(void 0,1,0,1,1,1),f1.bind(void 0,1,0,1,1,2),f1.bind(void 0,1,0,1,1,3),f1.bind(void 0,1,1,0,0,0),f1.bind(void 0,1,1,0,0,1),f1.bind(void 0,1,1,0,0,2),f1.bind(void 0,1,1,0,0,3),f1.bind(void 0,1,1,0,1,0),f1.bind(void 0,1,1,0,1,1),f1.bind(void 0,1,1,0,1,2),f1.bind(void 0,1,1,0,1,3),f1.bind(void 0,1,1,1,0,0),f1.bind(void 0,1,1,1,0,1),f1.bind(void 0,1,1,1,0,2),f1.bind(void 0,1,1,1,0,3),f1.bind(void 0,1,1,1,1,0),f1.bind(void 0,1,1,1,1,1),f1.bind(void 0,1,1,1,1,2),f1.bind(void 0,1,1,1,1,3)];function X3(t){this.char=t,this.state={},this.activeState=null}function m6(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function Is(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function g2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function D4(t){this.eventId=t,this.subscribers=[]}function Vs(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(c){Object.defineProperty(e.events,c,{value:new D4(c)})}),t&&n.forEach(function(c){var a=t[c];typeof a=="function"&&e.events[c].subscribe(a)});var r=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];r.forEach(function(c){e.events[c].subscribe(e.updateContextsRanges)})}function y0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Vs.call(this,t)}X3.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};X3.prototype.getState=function(t){return this.state[t]||null};y0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};y0.prototype.composeRUD=function(t){var e=this,n=!0,r=t.map(function(a){return e[a[0]].apply(e,a.slice(1).concat(n))}),c=function(a){return typeof a=="object"&&a.hasOwnProperty("FAIL")};if(r.every(c))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:r.filter(c)};this.dispatch("composeRUD",[r.filter(function(a){return!c(a)})])};y0.prototype.replaceRange=function(t,e,n,r){e=e!==null?e:this.tokens.length;var c=n.every(function(s){return s instanceof X3});if(!isNaN(t)&&this.inboundIndex(t)&&c){var a=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return r||this.dispatch("replaceToken",[t,e,n]),[a,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};y0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof X3){var r=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[r[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};y0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var r=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[r,t,e]),r};y0.prototype.removeToken=function(t,e){if(!isNaN(t)&&this.inboundIndex(t)){var n=this.tokens.splice(t,1);return e||this.dispatch("removeToken",[n,t]),n}else return{FAIL:"removeToken: invalid token index."}};y0.prototype.insertToken=function(t,e,n){var r=t.every(function(c){return c instanceof X3});return r?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};y0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(r,c){var a=[r,c],s=e===null||e.apply(this,a)===!0,i=[r,c];if(s){var o=n.apply(this,i);r.setState(t,o)}}),this.registeredModifiers.push(t)};D4.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};D4.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};g2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};g2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};y0.prototype.rangeToText=function(t){if(t instanceof m6)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};y0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};y0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};y0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};y0.prototype.dispatch=function(t,e){var n=this,r=this.events[t];r instanceof D4&&r.subscribers.forEach(function(c){c.apply(n,e||[])})};y0.prototype.registerContextChecker=function(t,e,n){if(this.getContext(t))return{FAIL:"context name '"+t+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof n!="function")return{FAIL:"missing context end check."};var r=new Is(t,e,n);return this.registeredContexts[t]=r,this.contextCheckers.push(r),r};y0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};y0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};y0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};y0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(r){return r.char}),e=0;e<t.length;e++){var n=new g2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};y0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,r=new m6(n,t,e),c=this.getContext(e).ranges;return r.rangeId=e+"."+c.length,c.push(r),this.getContext(e).openRange=null,r};y0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(r){var c=r.contextName,a=e.getContext(c).openRange;if(!a&&r.checkStart(t)&&(a=new m6(n,null,c),e.getContext(c).openRange=a,e.dispatch("contextStart",[c,n])),a&&r.checkEnd(t)){var s=n-a.startIndex+1,i=e.setEndOffset(s,c);e.dispatch("contextEnd",[c,i])}})};y0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var r=e[n],c=new g2(e,n);this.dispatch("next",[c]),this.runContextCheck(c);var a=new X3(r);this.tokens.push(a),this.dispatch("newToken",[a,c])}return this.dispatch("end",[this.tokens]),this.tokens};function e3(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function N8(t){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(t)}function t3(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function T4(t){return/[A-z]/.test(t)}function Hs(t){return/\s/.test(t)}function n2(t){this.font=t,this.features={}}function v3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function q5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,r=0;r<n.length;r++){var c=n[r];if(t>=c.start&&t<=c.end){var a=t-c.start;return c.index+a}}break;default:return-1}return-1}function Os(t,e){var n=q5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function Fs(t,e){var n=q5(t,e.coverage);return n===-1?null:e.substitute[n]}function Ze(t,e){for(var n=[],r=0;r<t.length;r++){var c=t[r],a=e.current;a=Array.isArray(a)?a[0]:a;var s=q5(a,c);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function Rs(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=Ze(e.inputCoverage,t);if(r===-1)return[];var c=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(c);a.length&&t3(a[0].char);)a.shift();var s=new g2(a,0),i=Ze(e.lookaheadCoverage,s),o=[].concat(t.backtrack);for(o.reverse();o.length&&t3(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new g2(o,0),h=Ze(e.backtrackCoverage,l),u=r.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var m=e.lookupRecords[d],g=m.lookupListIndex,p=this.getLookupByIndex(g),v=0;v<p.subtables.length;v++){var y=p.subtables[v],b=this.getLookupMethod(p,y),x=this.getSubstitutionType(p,y);if(x==="12")for(var M=0;M<r.length;M++){var w=t.get(M),k=b(w);k&&f.push(k)}}return f}function $s(t,e){var n=t.current,r=q5(n,e.coverage);if(r===-1)return null;for(var c,a=e.ligatureSets[r],s=0;s<a.length;s++){c=a[s];for(var i=0;i<c.components.length;i++){var o=t.lookahead[i],l=c.components[i];if(o!==l)break;if(i===c.components.length-1)return c}}return null}function Ds(t,e){var n=q5(t,e.coverage);return n===-1?null:e.sequences[n]}n2.prototype.getDefaultScriptFeaturesIndexes=function(){for(var t=this.font.tables.gsub.scripts,e=0;e<t.length;e++){var n=t[e];if(n.tag==="DFLT")return n.script.defaultLangSys.featureIndexes}return[]};n2.prototype.getScriptFeaturesIndexes=function(t){var e=this.font.tables;if(!e.gsub)return[];if(!t)return this.getDefaultScriptFeaturesIndexes();for(var n=this.font.tables.gsub.scripts,r=0;r<n.length;r++){var c=n[r];if(c.tag===t&&c.script.defaultLangSys)return c.script.defaultLangSys.featureIndexes;var a=c.langSysRecords;if(a)for(var s=0;s<a.length;s++){var i=a[s];if(i.tag===t){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};n2.prototype.mapTagsToFeatures=function(t,e){for(var n={},r=0;r<t.length;r++){var c=t[r].tag,a=t[r].feature;n[c]=a}this.features[e].tags=n};n2.prototype.getScriptFeatures=function(t){var e=this.features[t];if(this.features.hasOwnProperty(t))return e;var n=this.getScriptFeaturesIndexes(t);if(!n)return null;var r=this.font.tables.gsub;return e=n.map(function(c){return r.features[c]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};n2.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),r=e.substFormat.toString();return n+r};n2.prototype.getLookupMethod=function(t,e){var n=this,r=this.getSubstitutionType(t,e);switch(r){case"11":return function(c){return Os.apply(n,[c,e])};case"12":return function(c){return Fs.apply(n,[c,e])};case"63":return function(c){return Rs.apply(n,[c,e])};case"41":return function(c){return $s.apply(n,[c,e])};case"21":return function(c){return Ds.apply(n,[c,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};n2.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,r=this.getFeature({tag:t.tag,script:t.script});if(!r)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var c=this.getFeatureLookups(r),a=[].concat(e.context),s=0;s<c.length;s++)for(var i=c[s],o=this.getLookupSubtables(i),l=0;l<o.length;l++){var h=o[l],u=this.getSubstitutionType(i,h),f=this.getLookupMethod(i,h),d=void 0;switch(u){case"11":d=f(e.current),d&&a.splice(n,1,new v3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new v3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new v3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new v3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new v3({id:21,tag:t.tag,substitution:d}));break}e=new g2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};n2.prototype.supports=function(t){if(!t.script)return!1;this.getScriptFeatures(t.script);var e=this.features.hasOwnProperty(t.script);if(!t.tag)return e;var n=this.features[t.script].some(function(r){return r.tag===t.tag});return e&&n};n2.prototype.getLookupSubtables=function(t){return t.subtables||null};n2.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};n2.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};n2.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var n=this.features[e.script];return n?n.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function qs(t){var e=t.current,n=t.get(-1);return n===null&&e3(e)||!e3(n)&&e3(e)}function Ns(t){var e=t.get(1);return e===null||!e3(e)}var Us={startCheck:qs,endCheck:Ns};function Bs(t){var e=t.current,n=t.get(-1);return(e3(e)||t3(e))&&!e3(n)}function _s(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!e3(e)&&!t3(e)):var n=Hs(e);if(!n)return!0;if(n){var r=!1;if(r=t.lookahead.some(function(c){return e3(c)||t3(c)}),!r)return!0}break;default:return!1}}var js={startCheck:Bs,endCheck:_s};function Gs(t,e,n){e[n].setState(t.tag,t.substitution)}function Ws(t,e,n){e[n].setState(t.tag,t.substitution)}function Xs(t,e,n){t.substitution.forEach(function(r,c){var a=e[n+c];a.setState(t.tag,r)})}function Zs(t,e,n){var r=e[n];r.setState(t.tag,t.substitution.ligGlyph);for(var c=t.substitution.components.length,a=0;a<c;a++)r=e[n+a+1],r.setState("deleted",!0)}var W7={11:Gs,12:Ws,63:Xs,41:Zs};function p6(t,e,n){t instanceof v3&&W7[t.id]&&W7[t.id](t,e,n)}function Ys(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],c=N8(r),a=t3(r);if(!c&&!a)return!0;if(c)return!1}return!1}function Js(t){if(N8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],r=t3(n);if(!r)return!0}return!1}function Ks(t){var e=this,n="arab",r=this.featuresTags[n],c=this.tokenizer.getRangeTokens(t);if(c.length!==1){var a=new g2(c.map(function(i){return i.getState("glyphIndex")}),0),s=new g2(c.map(function(i){return i.char}),0);c.forEach(function(i,o){if(!t3(i.char)){a.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;Ys(s)&&(l|=1),Js(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(r.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof v3&&(p6(f,c,d),a.context[d]=f.substitution)})}}})}}function X7(t,e){var n=t.map(function(r){return r.activeState.value});return new g2(n,e||0)}function Qs(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),c=X7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:n,contextParams:c});i.length&&(i.forEach(function(o){return p6(o,r,s)}),c=X7(r))})}function ei(t){var e=t.current,n=t.get(-1);return n===null&&T4(e)||!T4(n)&&T4(e)}function ti(t){var e=t.get(1);return e===null||!T4(e)}var ni={startCheck:ei,endCheck:ti};function Z7(t,e){var n=t.map(function(r){return r.activeState.value});return new g2(n,e||0)}function ri(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),c=Z7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:n,contextParams:c});i.length&&(i.forEach(function(o){return p6(o,r,s)}),c=Z7(r))})}function b2(t){this.baseDir=t||"ltr",this.tokenizer=new y0,this.featuresTags={}}b2.prototype.setText=function(t){this.text=t};b2.prototype.contextChecks={latinWordCheck:ni,arabicWordCheck:Us,arabicSentenceCheck:js};function Ye(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function ci(){return Ye.call(this,"latinWord"),Ye.call(this,"arabicWord"),Ye.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function ai(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var r=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,r.reverse())})}b2.prototype.registerFeatures=function(t,e){var n=this,r=e.filter(function(c){return n.query.supports({script:t,tag:c})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(r):this.featuresTags[t]=r};b2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new n2(t));for(var n=0;n<e.length;n++){var r=e[n];this.query.supports({script:r.script})&&this.registerFeatures(r.script,r.tags)}};b2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function g6(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function si(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){g6.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){Ks.call(t,r)})}}function ii(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){g6.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(c){Qs.call(t,c)})}}}function oi(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){g6.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(c){ri.call(t,c)})}}}b2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};b2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(si.call(this),ii.call(this)),this.checkContextReady("latinWord")&&oi.call(this),this.checkContextReady("arabicSentence")&&ai.call(this)};b2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),ci.call(this),this.applyFeaturesToContexts())};b2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};b2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var r=this.tokenizer.tokens[n];if(!r.state.deleted){var c=r.activeState.value;e.push(Array.isArray(c)?c[0]:c)}}return e};function r0(t){t=t||{},t.tables=t.tables||{},t.empty||(E5(t.familyName,"When creating a new Font object, familyName is required."),E5(t.styleName,"When creating a new Font object, styleName is required."),E5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),E5(t.ascender,"When creating a new Font object, ascender is required."),E5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new T2.GlyphSet(this,t.glyphs||[]),this.encoding=new s8(this),this.position=new R5(this),this.substitution=new t2(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new R8(this)}})}r0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};r0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};r0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};r0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};r0.prototype.stringToGlyphs=function(t,e){var n=this,r=new b2,c=function(u){return n.charToGlyphIndex(u.char)};r.registerModifier("glyphIndex",null,c);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;r.applyFeatures(this,a);for(var s=r.getTextGlyphs(t),i=s.length,o=new Array(i),l=this.glyphs.get(0),h=0;h<i;h+=1)o[h]=this.glyphs.get(s[h])||l;return o};r0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};r0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};r0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};r0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};r0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};r0.prototype.forEachGlyph=function(t,e,n,r,c,a){e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:72,c=Object.assign({},this.defaultRenderOptions,c);var s=1/this.unitsPerEm*r,i=this.stringToGlyphs(t,c),o;if(c.kerning){var l=c.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,c.language)}for(var h=0;h<i.length;h+=1){var u=i[h];if(a.call(this,u,e,n,r,c),u.advanceWidth&&(e+=u.advanceWidth*s),c.kerning&&h<i.length-1){var f=o?this.position.getKerningValue(o,u.index,i[h+1].index):this.getKerningValue(u,i[h+1]);e+=f*s}c.letterSpacing?e+=c.letterSpacing*r:c.tracking&&(e+=c.tracking/1e3*r)}return e};r0.prototype.getPath=function(t,e,n,r,c){var a=new P0;return this.forEachGlyph(t,e,n,r,c,function(s,i,o,l){var h=s.getPath(i,o,l,c,this);a.extend(h)}),a};r0.prototype.getPaths=function(t,e,n,r,c){var a=[];return this.forEachGlyph(t,e,n,r,c,function(s,i,o,l){var h=s.getPath(i,o,l,c,this);a.push(h)}),a};r0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};r0.prototype.draw=function(t,e,n,r,c,a){this.getPath(e,n,r,c,a).draw(t)};r0.prototype.drawPoints=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,i,o,l){s.drawPoints(t,i,o,l)})};r0.prototype.drawMetrics=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,i,o,l){s.drawMetrics(t,i,o,l)})};r0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};r0.prototype.validate=function(){var t=this;function e(r,c){}function n(r){var c=t.getEnglishName(r);c&&c.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};r0.prototype.toTables=function(){return Zc.fontToTable(this)};r0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};r0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),r=new Uint8Array(n),c=0;c<e.length;c++)r[c]=e[c];return n};r0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var r=this.toArrayBuffer();if(Jc())if(window.URL=window.URL||window.webkitURL,window.URL){var c=new DataView(r),a=new Blob([c],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(a),s.download=t;var i=document.createEvent("MouseEvents");i.initEvent("click",!0,!1),s.dispatchEvent(i)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var o=u7(),l=Kc(r);o.writeFileSync(t,l)}};r0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};r0.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};r0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function U8(t,e){var n=JSON.stringify(t),r=256;for(var c in e){var a=parseInt(c);if(!(!a||a<256)){if(JSON.stringify(e[c])===n)return a;r<=a&&(r=a+1)}}return e[r]=t,r}function li(t,e,n){var r=U8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:r}]}function hi(t,e,n){var r={},c=new p1.Parser(t,e);return r.tag=c.parseTag(),r.minValue=c.parseFixed(),r.defaultValue=c.parseFixed(),r.maxValue=c.parseFixed(),c.skip("uShort",1),r.name=n[c.parseUShort()]||{},r}function ui(t,e,n,r){for(var c=U8(e.name,r),a=[{name:"nameID_"+t,type:"USHORT",value:c},{name:"flags_"+t,type:"USHORT",value:0}],s=0;s<n.length;++s){var i=n[s].tag;a.push({name:"axis_"+t+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return a}function fi(t,e,n,r){var c={},a=new p1.Parser(t,e);c.name=r[a.parseUShort()]||{},a.skip("uShort",1),c.coordinates={};for(var s=0;s<n.length;++s)c.coordinates[n[s].tag]=a.parseFixed();return c}function di(t,e){var n=new s1.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:t.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:t.instances.length},{name:"instanceSize",type:"USHORT",value:4+t.axes.length*4}]);n.offsetToData=n.sizeOf();for(var r=0;r<t.axes.length;r++)n.fields=n.fields.concat(li(r,t.axes[r],e));for(var c=0;c<t.instances.length;c++)n.fields=n.fields.concat(ui(c,t.instances[c],t.axes,e));return n}function mi(t,e,n){var r=new p1.Parser(t,e),c=r.parseULong();C1.argument(c===65536,"Unsupported fvar table version.");var a=r.parseOffset16();r.skip("uShort",1);for(var s=r.parseUShort(),i=r.parseUShort(),o=r.parseUShort(),l=r.parseUShort(),h=[],u=0;u<s;u++)h.push(hi(t,e+a+u*i,n));for(var f=[],d=e+a+s*i,m=0;m<o;m++)f.push(fi(t,d+m*l,h,n));return{axes:h,instances:f}}var pi={make:di,parse:mi},gi=function(){return{coverage:this.parsePointer($.coverage),attachPoints:this.parseList($.pointer($.uShortList))}},vi=function(){var t=this.parseUShort();if(C1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},yi=function(){return this.parseList($.pointer(vi))},bi=function(){return{coverage:this.parsePointer($.coverage),ligGlyphs:this.parseList($.pointer(yi))}},xi=function(){return this.parseUShort(),this.parseList($.pointer($.coverage))};function Mi(t,e){e=e||0;var n=new $(t,e),r=n.parseVersion(1);C1.argument(r===1||r===1.2||r===1.3,"Unsupported GDEF table version.");var c={version:r,classDef:n.parsePointer($.classDef),attachList:n.parsePointer(gi),ligCaretList:n.parsePointer(bi),markAttachClassDef:n.parsePointer($.classDef)};return r>=1.2&&(c.markGlyphSets=n.parsePointer(xi)),c}var wi={parse:Mi},v2=new Array(10);v2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer($.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer($.coverage),values:this.parseValueRecordList()};C1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};v2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();C1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer($.coverage),c=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,pairSets:this.parseList($.pointer($.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer($.classDef),i=this.parsePointer($.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,$.list(l,function(){return{value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}}))}}};v2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};v2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};v2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};v2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};v2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};v2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};v2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function ki(t,e){e=e||0;var n=new $(t,e),r=n.parseVersion(1);return C1.argument(r===1||r===1.1,"Unsupported GPOS table version "+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(v2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(v2),variations:n.parseFeatureVariationsList()}}var zi=new Array(10);function Si(t){return new s1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new s1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new s1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new s1.LookupList(t.lookups,zi)}])}var Li={parse:ki,make:Si};function Ai(t){var e={};t.skip("uShort");var n=t.parseUShort();C1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var r=t.parseUShort();t.skip("uShort",3);for(var c=0;c<r;c+=1){var a=t.parseUShort(),s=t.parseUShort(),i=t.parseShort();e[a+","+s]=i}return e}function Ci(t){var e={};t.skip("uShort");var n=t.parseULong();n>1&&console.warn("Only the first kern subtable is supported."),t.skip("uLong");var r=t.parseUShort(),c=r&255;if(t.skip("uShort"),c===0){var a=t.parseUShort();t.skip("uShort",3);for(var s=0;s<a;s+=1){var i=t.parseUShort(),o=t.parseUShort(),l=t.parseShort();e[i+","+o]=l}}return e}function Pi(t,e){var n=new p1.Parser(t,e),r=n.parseUShort();if(r===0)return Ai(n);if(r===1)return Ci(n);throw new Error("Unsupported kern table version ("+r+").")}var Ei={parse:Pi};function Ti(t,e,n,r){for(var c=new p1.Parser(t,e),a=r?c.parseUShort:c.parseULong,s=[],i=0;i<n+1;i+=1){var o=a.call(c);r&&(o*=2),s.push(o)}return s}var Ii={parse:Ti};function Y7(t,e){for(var n=[],r=12,c=0;c<e;c+=1){var a=p1.getTag(t,r),s=p1.getULong(t,r+4),i=p1.getULong(t,r+8),o=p1.getULong(t,r+12);n.push({tag:a,checksum:s,offset:i,length:o,compression:!1}),r+=16}return n}function Vi(t,e){for(var n=[],r=44,c=0;c<e;c+=1){var a=p1.getTag(t,r),s=p1.getULong(t,r+4),i=p1.getULong(t,r+8),o=p1.getULong(t,r+12),l=void 0;i<o?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:i,length:o}),r+=20}return n}function M0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),r=new Uint8Array(e.length);if(Lr(n,r),r.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var c=new DataView(r.buffer,0);return{data:c,offset:0}}else return{data:t,offset:e.offset}}function B8(t,e){e=e??{};var n,r,c=new r0({empty:!0}),a=new DataView(t,0),s,i=[],o=p1.getTag(a,0);if(o==="\0\0\0"||o==="true"||o==="typ1")c.outlinesFormat="truetype",s=p1.getUShort(a,4),i=Y7(a,s);else if(o==="OTTO")c.outlinesFormat="cff",s=p1.getUShort(a,4),i=Y7(a,s);else if(o==="wOFF"){var l=p1.getTag(a,4);if(l==="\0\0\0")c.outlinesFormat="truetype";else if(l==="OTTO")c.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+o);s=p1.getUShort(a,12),i=Vi(a,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,u,f,d,m,g,p,v,y,b,x,M,w=0;w<s;w+=1){var k=i[w],z=void 0;switch(k.tag){case"cmap":z=M0(a,k),c.tables.cmap=a8.parse(z.data,z.offset),c.encoding=new i8(c.tables.cmap);break;case"cvt ":z=M0(a,k),M=new p1.Parser(z.data,z.offset),c.tables.cvt=M.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=M0(a,k),M=new p1.Parser(z.data,z.offset),c.tables.fpgm=M.parseByteList(k.length);break;case"head":z=M0(a,k),c.tables.head=v8.parse(z.data,z.offset),c.unitsPerEm=c.tables.head.unitsPerEm,n=c.tables.head.indexToLocFormat;break;case"hhea":z=M0(a,k),c.tables.hhea=y8.parse(z.data,z.offset),c.ascender=c.tables.hhea.ascender,c.descender=c.tables.hhea.descender,c.numberOfHMetrics=c.tables.hhea.numberOfHMetrics;break;case"hmtx":p=k;break;case"ltag":z=M0(a,k),r=x8.parse(z.data,z.offset);break;case"maxp":z=M0(a,k),c.tables.maxp=M8.parse(z.data,z.offset),c.numGlyphs=c.tables.maxp.numGlyphs;break;case"name":b=k;break;case"OS/2":z=M0(a,k),c.tables.os2=c6.parse(z.data,z.offset);break;case"post":z=M0(a,k),c.tables.post=A8.parse(z.data,z.offset),c.glyphNames=new h6(c.tables.post);break;case"prep":z=M0(a,k),M=new p1.Parser(z.data,z.offset),c.tables.prep=M.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":y=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":m=k;break;case"GSUB":g=k;break;case"meta":x=k;break}}var S=M0(a,b);if(c.tables.name=L8.parse(S.data,S.offset,r),c.names=c.tables.name,f&&y){var A=n===0,L=M0(a,y),C=Ii.parse(L.data,L.offset,c.numGlyphs,A),P=M0(a,f);c.glyphs=H8.parse(P.data,P.offset,C,c,e)}else if(h){var R=M0(a,h);g8.parse(R.data,R.offset,c,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var q=M0(a,p);if(b8.parse(c,q.data,q.offset,c.numberOfHMetrics,c.numGlyphs,c.glyphs,e),Wr(c,e),v){var T=M0(a,v);c.kerningPairs=Ei.parse(T.data,T.offset)}else c.kerningPairs={};if(d){var B=M0(a,d);c.tables.gdef=wi.parse(B.data,B.offset)}if(m){var X=M0(a,m);c.tables.gpos=Li.parse(X.data,X.offset),c.position.init()}if(g){var Z=M0(a,g);c.tables.gsub=C8.parse(Z.data,Z.offset)}if(u){var h1=M0(a,u);c.tables.fvar=pi.parse(h1.data,h1.offset,c.names)}if(x){var H=M0(a,x);c.tables.meta=P8.parse(H.data,H.offset),c.metas=c.tables.meta}return c}var q4=class{constructor(e,n){this.sources=e;this.fallback=n;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let n=e||this.fallback||Object.keys(this.sources)[0];if(!n)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let r=this.parsed.get(n);if(r)return r;let c=e2(this.sources,n);if(!c)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let a=c instanceof Uint8Array?c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength):c,s=B8(a);return this.parsed.set(n,s),s}};function Hi(t,e,n){let r={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,r).commands,advance:t.getAdvanceWidth(e,n.size,r)};let c=[],a=0,s=[...e];return s.forEach((i,o)=>{c.push(...t.getPath(i,a,0,n.size,r).commands),a+=t.getAdvanceWidth(i,n.size,r)*(o<s.length-1?n.spacing:1)}),{cmds:c,advance:a}}function _8(t,e,n){let{cmds:r,advance:c}=Hi(t,e,n),a=r.map(i=>i.type==="Z"?i:i.type==="C"?{...i,y1:-i.y1,y2:-i.y2,y:-i.y}:i.type==="Q"?{...i,y1:-i.y1,y:-i.y}:{...i,y:-i.y}),s=D3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:c}}function N4(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:c,advance:a}=_8(r,e,n),s=i1(c),i=z0(s);if(!i)return[];let o=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-i[3]:n.valign==="center"?-(i[1]+i[3])/2:n.valign==="bottom"?-i[1]:0;return s.map(h=>h.map(([u,f])=>[u+o,f+l]))}function v6(t,e,n){let r=t.get(n.font),{polys:c,advance:a}=_8(r,e,n),s=z0(c)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:r.ascender/r.unitsPerEm*n.size,descent:r.descender/r.unitsPerEm*n.size}}var j8=Math.PI/180,y6=128,N5=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],w6={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function Oi(t,e){if(!t||e2(M6,t)!==void 0||e.startsWith("/"))return;let n=t.lastIndexOf("/");if(n<0)return;let r=[...t.slice(0,n).split("/"),...e.split("/")],c=[];for(let a of r)a===".."&&c.length&&c[c.length-1]!==".."?c.pop():a!=="."&&a!==""&&c.push(a);return(t.startsWith("/")?"/":"")+c.join("/")}var Fi=100,Ri={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},Z3=4,G8=8,$i=t=>{let e=Fi,n=r=>{for(let c of r.values()){for(let a of c.regions)e+=a.length;for(let a of c.lines)e+=a.length}};n(t.layers);for(let r of t.parts)n(r.layers);return e},I0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,r=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=r?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let r=n.fns.get(e);if(r)return r}}mod(e){for(let n=this;n;n=n.parent){let r=n.mods.get(e);if(r)return r}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let r=this;r;r=r.parent)n.push(...r[e].keys());return n}},b6=t=>t?`.${t}`:"",x6=["echo","assert","text_width","text_metrics","finger_count"];function b3(t,e){let n="",r=Math.min(2,Math.floor(t.length/3))+.5;for(let c of new Set(e)){if(c===t)continue;let a=c.toLowerCase()===t.toLowerCase()?0:Di(t,c);a<r&&([n,r]=[c,a])}return n?` Did you mean "${n}"?`:""}function Di(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(r,c)=>[c,...Array(e.length).fill(0)]);for(let r=1;r<=e.length;r++)n[0][r]=r;for(let r=1;r<=t.length;r++)for(let c=1;c<=e.length;c++)n[r][c]=Math.min(n[r-1][c]+1,n[r][c-1]+1,n[r-1][c-1]+(t[r-1]===e[c-1]?0:1)),r>1&&c>1&&t[r-1]===e[c-2]&&t[r-2]===e[c-1]&&(n[r][c]=Math.min(n[r][c],n[r-2][c-2]+1));return n[t.length][e.length]}var M6=P5,Y3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.occluding=0;this.pointCount=0;this.itemCount=0;this.retained=0;this.copies=0;this.frame=Te;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(N5.map(e=>[e.name,e]));this.loaded=new Map;this.clashed=new Set;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...w6,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new I0,r={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[i,o]of Object.entries(r))n.vars.set(i,o);let c=new I0(n),a=this.block(e.body,c,!0),s=c.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${m2(this.unscaled,!1)})`),{shape:a,globals:c,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new o1(`Stopped after ${this.maxSteps} steps. Is there an endless loop?`,e)}load(e,n){let r=Oi(n.file,e),c=e,a=e2(M6,e);if(a===void 0&&r!==void 0){let i=this.loaded.get(r);if(i)return i;a=this.opts.resolve?.(r),typeof a=="string"&&(c=r)}if(c===e){let i=this.loaded.get(e);if(i)return i;a??(a=this.opts.resolve?.(e))}if(typeof a!="string")throw new o1(`Library <${e}> not found`,n);this.loaded.set(c,{body:[]});let{program:s}=l2(a,c);return this.loaded.set(c,s),s}hoist(e,n){for(let r of e)if((r.kind==="module"||r.kind==="function")&&(r.pos.file===void 0||e2(M6,r.pos.file)===void 0)&&(r.kind==="module"?e2(this.builtins,r.name)!==void 0:e2(L5,r.name)!==void 0||x6.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${m2(r.pos,!1)})`),r.kind==="module")n.mods.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="function")n.fns.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="use"&&!r.include){this.enter(this.using,r.path,r.pos,"use");try{let c=this.included(this.load(r.path,r.pos).body,new Set([r.path])),a=new I0(n);this.hoist(c,a);for(let s of c)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,i]of a.mods)this.clash("module",s,n.mods.get(s),i),n.mods.set(s,i);for(let[s,i]of a.fns)this.clash("function",s,n.fns.get(s),i),n.fns.set(s,i)}finally{this.using.pop()}}}clash(e,n,r,c){!r||r.body===c.body||!r.pos?.file||!c.pos?.file||r.pos.file===c.pos.file||this.clashed.has(`${e} ${n}`)||(this.clashed.add(`${e} ${n}`),this.warn(`${e} ${n} is defined in <${r.pos.file}> (line ${r.pos.line}) and in <${c.pos.file}> (line ${c.pos.line}); the one in <${c.pos.file}> is used. Rename one to use both.`))}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let c=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,i=[];for(let l=c.length-1;l>=0;l--)i.push({text:";"},c[l][1],{text:`${c[l][0]}=`});for(;i.length;){if(s>2e4)return"";let l=i.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){i.push({text:"]"});for(let u=l.length-1;u>=0;u--)i.push(l[u],{text:","});h="["}else if(i2(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(_0(l)){i.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)i.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";a.push(h),s+=h.length}let o=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies}`}enter(e,n,r,c){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new o1(a.length===2?`Library ${a[0]} ${c}s itself`:`Libraries ${c} each other in a loop: ${a.join(" \u2192 ")}`,r)}e.push(n)}included(e,n){let r=[];for(let c of e)if(c.kind!=="use"||!c.include)r.push(c);else if(!n.has(c.path)){n.add(c.path);for(let a of this.included(this.load(c.path,c.pos).body,n))r.push(a)}return r}assign(e,n,r){r.vars.set(e,n)}block(e,n,r=!1){this.hoist(e,n);let c=[];for(let a of e){let s=this.stmt(a,n,r);s&&!yt(s)&&c.push(s)}return c.length===1?c[0]:A2(c)}stmt(e,n,r=!1){switch(this.tick(e.pos),e.kind){case"assign":{let c=this.opts.overrides,a=r&&c&&Object.prototype.hasOwnProperty.call(c,e.name)?c[e.name]:this.expr(e.value,n);return this.assign(e.name,a,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new I0(n));case"if":return g0(this.expr(e.cond,n))?this.block(e.then,new I0(n)):this.block(e.else,new I0(n));case"let":{let c=new I0(n);return this.bindSeq(e.assigns,c),this.block(e.body,c)}case"for":{let c=[];return this.loop(e.assigns,n,a=>c.push(this.block(e.body,a))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:n,children:()=>A2(c),childList:()=>c,childSeq:()=>c,childItems:()=>c}):A2(c)}case"call":if(e.modifier==="*")return null;{let c=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?b5(c,"guide"):c}}}bindSeq(e,n){for(let r of e)this.assign(r.name,this.expr(r.value,n),n)}iterable(e,n){if(i2(e))try{return x4(e,this.limits.maxListLength)}catch(r){throw new o1(r.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,r,c=0,a=new I0(n)){if(c===e.length)return r(a);let s=e[c];for(let i of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let o=new I0(a);o.vars.set(s.name,i),this.loop(e,n,r,c+1,o)}}evalArgs(e,n,r){let c=[],a=new Map,s=[];for(let i of e){let o=this.expr(i.value,n);i.name===null?c.push(o):a.set(i.name,o),s.push({name:i.name,value:o})}return{pos:c,named:a,all:s,at:r}}bindParams(e,n,r,c,a){let s=e.map(i=>i.name);e.forEach((i,o)=>{let l;n.named.has(i.name)?l=n.named.get(i.name):o<n.pos.length?l=n.pos[o]:l=i.default?this.expr(i.default,r):void 0,r.vars.set(i.name,l)});for(let i of n.named.keys())i.startsWith("$")?r.vars.set(i,n.named.get(i)):s.includes(i)||this.unknownArg(a,i,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let r=B3(e);if(!r)return;let c=r.params.map(a=>a.name);if(!r.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!c.includes(a)&&this.unknownArg(`${e}()`,a,n.at,c);r.rest||this.checkCount(`${e}()`,r.params.filter(a=>!a.named).length,n)}checkCount(e,n,r){r.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${r.pos.length}; the rest are ignored (${m2(r.at,!1)})`)}unknownArg(e,n,r,c){this.warn(`${e}: unknown argument "${n}"${b6(b3(n,c))} (${m2(r,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let r=e.args.findIndex(s=>s.name==="name"),c=r>=0?r:e.args.findIndex(s=>s.name===null);if(c<0)throw new o1("call() needs the name of a module",e.pos);let a=this.expr(e.args[c].value,n);if(typeof a!="string")throw new o1(`call() needs a module's name as a string, got ${R0(a)}`,e.pos);if(a==="call")throw new o1("call() can't call itself",e.pos);return this.callModule({...e,name:a,args:e.args.filter((s,i)=>i!==c)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let r=this.evalArgs(e.args,n,e.pos),c=n.mod(e.name);if(c){if(++this.depth>1e3)throw new o1(`Recursion too deep in module ${e.name}(): it calls itself without stopping`,e.pos);try{let f=new I0(c.env,n);return this.bindParams(c.params,r,f,c.env,`${e.name}()`),f.children={stmts:e.children,env:n,module:e.name,pos:e.pos},f.vars.set("$children",this.childStmts(e.children).length),this.block(c.body,f)}catch(f){throw this.inCall(f,"module",e.name,e.pos)}finally{this.depth--}}let a=e2(this.builtins,e.name);if(!a){let f=e.name==="color"?" Use layer(), cut(), score() or engrave() instead.":b3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new o1(`Unknown module ${e.name}().${f}`,e.pos)}this.checkArgs(e.name,r);let s=new I0(n,n);for(let[f,d]of r.named)f.startsWith("$")&&s.vars.set(f,d);let i=this.childStmts(e.children),o=()=>new I0(n,s),l={args:r,env:s,children:()=>e.children.length?this.block(e.children,o()):O0(),childList:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let m of e.children){let g=this.stmt(m,f);i.includes(m)&&d.push(g??O0())}return d},childItems:()=>{let f=o();this.hoist(e.children,f);let d=[];for(let m of e.children){if(i.includes(m)&&m.kind==="for"&&!m.intersect){this.tick(m.pos),this.loop(m.assigns,f,p=>d.push(this.block(m.body,p)));continue}let g=this.stmt(m,f);i.includes(m)&&d.push(g??O0())}return d},childSeq:f=>{let d=o();this.hoist(e.children,d);let m=[];for(let g of e.children){let p=this.stmt(g,d);i.includes(g)&&(m.push(p??O0()),f(m.length-1,p??O0()))}return m}},h;try{h=a(l)}catch(f){if(f instanceof o1||f instanceof RangeError)throw f;let d=new o1(`${e.name}(): ${f.message}`,e.pos);throw d.call=e.name,d}let u=$i(h);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new o1(u>this.limits.maxPoints?`The shapes have more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes, or a lower $fn.`:`Making the shapes took more than ${this.limits.maxPoints*10} points of work, the limit. Use fewer or simpler shapes, or a lower $fn.`,e.pos);return h}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,r,c){if(++this.depth>2e3)throw new o1(`Recursion too deep in ${c}(): it calls itself without stopping`,n.at);try{this.tick(n.at);let a=d2(e)?e.scope:e.env,s=new I0(a,r);return this.bindParams(e.params,n,s,a,`${c}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",c,n.at)}finally{this.depth--}}inCall(e,n,r,c){return e instanceof Error&&!(e instanceof o1)&&e.message.includes("call stack")?new o1(`Recursion too deep in ${n==="module"?"module ":""}${r}(): it calls itself without stopping`,c):(e instanceof o1&&e.addFrame(n,r,c),e)}expr(e,n){switch(e.kind){case"num":return e.unit?this.length(e,n):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{let r=n.get(e.name);if(r.found)return r.value;let c=n.fn(e.name);if(c)return{type:"function",params:c.params,body:c.body,scope:c.env,name:e.name};if(e.name.startsWith("$"))return;throw new o1(`Unknown variable "${e.name}"${b6(b3(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let r=[];for(let c of e.items)this.listItem(c,n,r,e.pos);return this.charge(Z3,e.pos),r}case"range":{let r=this.expr(e.start,n),c=this.expr(e.end,n),a=e.step?this.expr(e.step,n):1;if(typeof r!="number"||typeof c!="number"||typeof a!="number")throw new o1("Range values must be numbers",e.pos);return{type:"range",start:r,step:a,end:c}}case"unary":{let r=this.expr(e.arg,n);return e.op==="!"?!g0(r):e.op==="+"?r:this.arith("*",-1,r,e.pos)}case"binary":{if(e.op==="&&")return g0(this.expr(e.left,n))&&g0(this.expr(e.right,n));if(e.op==="||")return g0(this.expr(e.left,n))||g0(this.expr(e.right,n));let r=this.expr(e.left,n),c=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return R3(r,c,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof r=="number"&&typeof c=="number"||typeof r=="string"&&typeof c=="string"))throw new o1(`Can't compare ${R0(r)} ${e.op} ${R0(c)}`,e.pos);return e.op==="<"?r<c:e.op==="<="?r<=c:e.op===">"?r>c:r>=c}return this.arith(e.op,r,c,e.pos)}case"ternary":return g0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let r=this.expr(e.target,n),c=this.expr(e.index,n);if(_0(r)&&typeof c=="string")return r.fields.get(c);if(typeof c!="number")throw new o1(`List index must be a number, got ${R0(c)}`,e.pos);return Array.isArray(r)?r[Math.floor(c)]:typeof r=="string"?[...r][Math.floor(c)]:i2(r)?[r.start,r.step,r.end][Math.floor(c)]:void 0}case"record":return this.record(e,n);case"member":{let r=this.expr(e.target,n);if(_0(r))return r.fields.get(e.name);let c={x:0,y:1,z:2}[e.name];return Array.isArray(r)&&c!==void 0?r[c]:i2(r)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?r.start:e.name==="step"?r.step:r.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let r=new I0(n);return this.bindSeq(e.assigns,r),this.expr(e.body,r)}case"chain":return this.expr(e.check,n),this.expr(e.body,n)}}listItem(e,n,r,c){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(r,1,c),r.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),c);this.grow(r,a.length,c);for(let s of a)r.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,r,c));return;case"if":g0(this.expr(e.cond,n))?this.listItem(e.then,n,r,c):e.else&&this.listItem(e.else,n,r,c);return;case"let":{let a=new I0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,r,c)}}}grow(e,n,r){if(e.length+n>this.limits.maxListLength)throw new o1(`a list of ${e.length+n} items is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n,r)}charge(e,n){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new o1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let c=e.callee.name,a=n.get(c),s=a.found&&!d2(a.value);if(!a.found||s&&this.callable(c,n)){let i=n.fn(c);if(i)return this.callFunction(i,this.evalArgs(e.args,n,e.pos),n,c);let o=this.specialFunction(c,e,n);if(o.handled)return o.value;let l=e2(L5,c);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(c,h);for(let m of n7(l,h.pos,h.named))this.warn(`${c}(): "${m}" is given by position and by name; the named value is used (${m2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:m=>this.tick(e.pos,m),given:h.pos.length+l.params.filter(m=>h.named.has(m)).length,apply:(m,g)=>{if(!d2(m))throw new Error(`${c}() needs a function, got ${R0(m)}`);return this.callFunction(m,{pos:g,named:new Map,all:g.map(p=>({name:null,value:p})),at:e.pos},n,"function")}},f=r7(l,h.pos,h.named);this.tick(e.pos,c7(c,f,this.limits.maxListLength));let d;try{d=l.run(f,u)}catch(m){if(m instanceof o1)throw m;let g=new o1(m instanceof RangeError?`${c}(): the result is too large`:m.message,e.pos);throw g.call=c,g}return this.checkValue(d,e.pos,c),d}throw new o1(`Unknown function ${c}()${b6(b3(c,[...n.names("fns"),...n.names("vars"),...Object.keys(L5),...x6]))}`,e.pos)}if(!d2(a.value))throw new o1(`"${c}" is a ${R0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,c)}let r=this.expr(e.callee,n);if(!d2(r))throw new o1(`Can't call a ${R0(r)}`,e.pos);return this.callFunction(r,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,r,c){let a=s=>Array.isArray(r)?String(r[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let i=a(s),o=i1(e.flatMap((h,u)=>u<s&&a(u)===i?n[u]:[]));!o.length||k0(n[s],o).reduce((h,u)=>h+Math.abs(M1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(r)&&i?` "${i}"`:""} under it, so it can't be seen (${m2(c,!1)})`)}}record(e,n){let r=new Map;for(let c of e.fields)r.set(c.name,this.expr(c.value,n));return{type:"record",fields:r}}length(e,n){let r=q0(n.get("$scale").value??1);if(!(r>0))throw new o1("$scale must be a number more than 0",e.pos);return r===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Ri[e.unit]/r}callable(e,n){return!!n.fn(e)||x6.includes(e)||!!e2(L5,e)}specialFunction(e,n,r){if(e==="echo"){let c=this.evalArgs(n.args,r,n.pos);return this.echo(this.echoText(c),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let c=this.evalArgs(n.args,r,n.pos);return this.checkArgs(e,c),this.assert(c),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"){let c=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,c);let a=this.measure(c,r);return e==="text_width"?{handled:!0,value:a.advance}:{handled:!0,value:[a.advance,a.bounds,a.ascent,a.descent]}}if(e==="finger_count"){let c=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,c);let a=this.num(this.arg(c,"length",0),"finger_count","length");return{handled:!0,value:f3(a,this.fingerWidth(c,r,1))}}return{handled:!1}}assert(e){if(g0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new o1(`Assertion failed${n===void 0?"":": "+v0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/G8);this.charge(r,n),this.retained+=r,this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,r=[],c=0,a=(s,i,o)=>{r.length&&(c+=2);let l=$3(i,n-c-s.length,o);if(c+=s.length+l.text.length,!l.whole)throw new o1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);r.push(s+l.text)};for(let{name:s,value:i}of e.all)s===null?a("",i,!1):a(`${s} = `,i,!0);return r.join(", ")}arith(e,n,r,c){if(typeof n=="number"&&typeof r=="number")switch(e){case"+":return n+r;case"-":return n-r;case"*":return n*r;case"/":return n/r;case"%":return n%r;case"^":return Math.pow(n,r)}if(e==="+"&&typeof n=="string"&&typeof r=="string")return this.checkSize(n.length+r.length,!0,c),n+r;if(Array.isArray(n)&&Array.isArray(r)){if(e==="+"||e==="-"){if(n.length!==r.length)throw new o1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${r.length}`,c);return this.charge(n.length+Z3,c),n.map((s,i)=>this.arith(e,s,r[i],c))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+Z3,c),n.map(i=>this.arith("*",i,r,c));let s=(i,o)=>{let l=this.arith("*",i,o,c);if(typeof l!="number")throw new o1("Can't multiply these lists: an item times an item is not a number",c);return l};if(Array.isArray(r[0])){let i=r[0].length;if(n.length!==r.length||r.some(o=>!Array.isArray(o)||o.length!==i))throw new o1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,c);return this.checkSize(i,!1,c),this.tick(c,i*n.length),Array.from({length:i},(o,l)=>n.reduce((h,u,f)=>h+s(u,r[f][l]),0))}if(n.length!==r.length)throw new o1(`Can't multiply lists of length ${n.length} and ${r.length}`,c);return this.tick(c,n.length),n.reduce((i,o,l)=>i+s(o,r[l]),0)}}if(Array.isArray(n)&&typeof r=="number"&&(e==="*"||e==="/"))return this.charge(n.length+Z3,c),n.map(s=>this.arith(e,s,r,c));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+Z3,c),r.map(s=>this.arith(e,n,s,c));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new o1(`Can't ${a[e]??e} ${R0(n)} and ${R0(r)}`,c)}fieldFn(e,n,r,c){if(!d2(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${C0(e)}`);return a=>{let s=this.itemCount,i=this.retained,o=this.callFunction(e,{pos:[a],named:new Map,all:[{name:null,value:a}],at:c},r,"field");return(!Array.isArray(o)||o.length<=3)&&(this.itemCount=s+this.retained-i),o}}arg(e,n,r,c){return e.named.has(n)?e.named.get(n):r>=0&&r<e.pos.length?e.pos[r]:c}num(e,n,r){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${r} must be a finite number, got ${C0(e)}`);return e}vec2(e,n,r=!0){let c=a=>typeof a=="number"&&Number.isFinite(a);if(c(e)&&r)return[e,e];if(Array.isArray(e)&&c(e[0])&&(e[1]===void 0||c(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${C0(e)}`)}vec3(e,n){let r=c=>typeof c=="number"&&Number.isFinite(c);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(r))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${C0(e)}`)}placements(e,n,r){let c=(i,o)=>i===void 0?[[0,0,0]]:Array.isArray(i)&&i.length>0&&Array.isArray(i[0])?i.map((l,h)=>this.vec3(l,`${o}[${h}]`)):[this.vec3(i,o)],a=c(e,"at"),s=c(n,"rotate");for(let[i,o]of[[a,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==r)throw new Error(`${o} needs one placement per copy: qty is ${r} but ${o} has ${i.length}`);return Array.from({length:r},(i,o)=>({at:a[a.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((r,c)=>{if(!Array.isArray(r)||!Number.isFinite(r[0])||!Number.isFinite(r[1]))throw new Error(`${n}[${c}] must be an [x, y] point, got ${C0(r)}`);return[r[0],r[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,r){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,r)}checkSize(e,n,r,c){if(e>this.limits.maxListLength)throw new o1(`${c?`${c}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n?Math.ceil(e/G8):e+Z3,r)}segs(e){let n=q0(this.dyn(e,"$fn"))||0,r=q0(this.dyn(e,"$fa"))||2,c=q0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let i=Mt(s,n,r,c);if(!(i<=a))throw new Error(`a circle with ${i} segments is more than the limit of ${a}. Lower $fn, or raise $fa or $fs.`);return i}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||n<=0)throw new Error("$thickness must be a positive number");return n}fingerWidth(e,n,r){let c=this.arg(e,"finger",r);return typeof c=="number"&&c>0?c:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new o1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let r=$3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!r.whole)throw new o1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,r.text.length);try{return v6(this.opts.fonts,r.text,this.textOpts(e,n,r.text))}catch(c){throw c instanceof o1?c:new o1(c.message,e.at)}}textOpts(e,n,r){let c={size:this.num(this.arg(e,"size",1,10),"text","size"),font:v0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:v0(this.arg(e,"halign",-1,"left")),valign:v0(this.arg(e,"valign",-1,"baseline")),spacing:q0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&r!==void 0&&this.opts.fonts){let s=this.num(a,"text","fit");if(!(s>0))throw new Error("fit must be a width more than 0");let i=v6(this.opts.fonts,r,{...c,size:1}).advance;if(i>0){let o=this.arg(e,"size",1);c.size=o===void 0?s/i:Math.min(c.size,s/i)}}return c}edges(e){let n=r=>{if(r==="out"||r==="in"||r==="flat")return r;throw new Error(`edges must be "out", "in" or "flat", got ${C0(r)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,r=this.layers.get(n);if(r&&r.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!r){let c=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...c,name:n,side:"back"})}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((r,c)=>{if(!Array.isArray(r)||r.length!==3||!r.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${C0(r)}${n.length>1?` at ${c}`:""}`);let[a,s,i]=r;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${C0(r)}`);return{x0:a,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>u3(s.children(),i),n=s=>i=>b5(i.children(),s),r=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${C0(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!g0(this.dyn(i.env,"$mirrored"))),b5(i.children(),o==="back"?this.backLayer(s):s)};return{rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0,1),"size"),l=q0(this.arg(s.args,"r",-1,0))||0,h=g0(this.arg(s.args,"center",1,!1)),u=wt(i,o,l,this.segs(s.env));return A0(i1([h?u.map(([f,d])=>[f-i/2,d-o/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let i=this.arg(s.args,"d",-1),o=i!==void 0?this.num(i,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return A0([V3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let[i,o]=this.vec2(this.arg(s.args,"r",0,1),"r");return A0([V3(i,o,this.segs(s.env)(Math.max(i,o)))])},regular_polygon:s=>{let i=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),o=this.num(this.arg(s.args,"r",1,10),"regular_polygon","r");if(!(i<=this.limits.maxSegments))throw new Error(`${i} corners is more than the limit of ${this.limits.maxSegments}`);return A0([V3(o,o,i)])},star:s=>{let i=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),o=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.args,"inner",2,o*.45),"star","inner");if(!(i*2<=this.limits.maxSegments))throw new Error(`${i} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<i*2;u++){let f=Math.PI/2+Math.PI*u/i,d=u%2?l:o;h.push([d*Math.cos(f),d*Math.sin(f)])}return A0(i1([h]))},polygon:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"paths",1),l=Array.isArray(o)?o.map(h=>(Array.isArray(h)?h:[]).map(u=>i[q0(u)]).filter(Boolean)):[i];return A0(i1(l,"evenodd"))},path:s=>{let i=this.arg(s.args,"d",0);if(typeof i!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let o=D3(q3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return g0(this.arg(s.args,"close",-1,!1))?A0(i1([...o.closed,...o.open.filter(h=>h.length>2)],l)):A2([A0(i1(o.closed,l)),L2(o.open)])},line:s=>{let i=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),o=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return L2([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!u)return O0();let f=-(o[1]-i[1])/u*(h/2),d=(o[0]-i[0])/u*(h/2);return A0(i1([[[i[0]+f,i[1]+d],[i[0]-f,i[1]-d],[o[0]-f,o[1]-d],[o[0]+f,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=g0(this.arg(s.args,"closed",1,!1));return L2([o&&i.length?[...i,i[0]]:i])},arc:s=>{let i=this.num(this.arg(s.args,"r",0,10),"arc","r"),o=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.env)(i)*Math.abs(l-o)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(o+(l-o)*f/h)*Math.PI/180;u.push([i*Math.cos(d),i*Math.sin(d)])}return L2([u])},text:s=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let i=this.arg(s.args,"text",0,""),o=$3(i,this.limits.maxTextLength);if(!o.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(s.args.at,o.text.length);let l=this.textOpts(s.args,s.env,o.text),h=N4(this.opts.fonts,o.text,l),u=this.arg(s.args,"weight",-1),f=this.arg(s.args,"bridge",-1);if(u!==void 0&&u!=="regular"){let d=u==="bold"?.035*l.size:this.num(u,"text","weight");d&&(h=n0(i1(h),d,"round"))}if(f!==void 0&&(h=Ae(h,this.num(f,"text","bridge"))),g0(this.dyn(s.env,"$mirrored"))){let[d,m]=[1/0,-1/0];for(let g of h)for(let[p]of g)[d,m]=[Math.min(d,p),Math.max(m,p)];return A0(i1(h.map(g=>g.map(([p,v])=>[d+m-p,v]))))}return A0(h)},translate:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,i,o])},rotate:s=>{let i=this.arg(s.args,"a",0,0),l=(Array.isArray(i)?q0(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[m,g]=this.vec2(f,"center",!1);d=[h,u,-u,h,m-h*m+u*g,g-u*m-h*g]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,u=o/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let i=this.arg(s.args,"m",0);if(!Array.isArray(i)||i.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let o=i[0],l=i[1];return e(s,[o[0],l[0],o[1],l[1],o[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[i,...o]=s.childList();if(!i)return O0();let l=c(o,"difference");return a(i,h=>({regions:k0(h.regions,l.regions),lines:W0(h.lines,i1(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return O0();let o=m=>[...m.layers.values()].some(g=>g.regions.length),l=m=>{let g;for(let p of i){if(p===m||!o(p))continue;let v=i1(c([p],"intersection").regions);g=g?a0(g,v):v}return g},h=i[0],u=i.every(o),f=l(h),d=a(h,m=>({regions:u?f?a0(m.regions,f):m.regions:[],lines:f?W0(m.lines,f,"inside"):m.lines}));for(let m of i){if(m===h)continue;if(m.parts.length)throw new Error("part() can only be the first child of intersection()");let g=l(m),p=new Map;for(let[v,y]of m.layers)y.lines.length&&p.set(v,{regions:[],lines:g?W0(y.lines,g,"inside"):y.lines});p.size&&(d=A2([d,{layers:p,parts:[]}]))}return d},hull:s=>{let i=s.children(),o=l=>{let h=[],u="cut",f=!0;for(let[m,g]of l){f&&(g.regions.length||g.lines.length)&&(u=m,f=!1);for(let p of[...g.regions,...g.lines])for(let v of p)h.push(v)}let d=o4(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:o(i.layers),parts:i.parts.map(l=>({...l,layers:o(l.layers)}))}},offset:s=>{let i=this.arg(s.args,"r",0),o=this.arg(s.args,"delta",-1),l=g0(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),u=i!==void 0?"round":l?"square":"miter";return a(s.children(),f=>({regions:n0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[i,o]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(i>0&&o>0))throw new Error("spacing must be more than 0");let[h,...u]=s.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=i1(c(u,"pattern").regions),d=X0(h.layers),m=z0(f);if(!d||!m)return O0();let g=Math.floor((m[1]-d[3])/o),p=Math.ceil((m[3]-d[1])/o),v=Math.floor((m[0]-d[2])/i)-1,y=Math.ceil((m[2]-d[0])/i)+1,b=(p-g+1)*(y-v+1);if(!(b<=this.limits.maxParts*10))throw new Error(`the pattern would have ${b} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(s.args.at,b);let x=F0(f).map(S=>({polys:S,box:z0(S)})),M=f,w=(S,A)=>{let L=0;for(let C of M)for(let P=0,R=C.length-1;P<C.length;R=P++){let[q,T]=C[R],[B,X]=C[P];T<=A?X>A&&(B-q)*(A-T)-(S-q)*(X-T)>0&&L++:X<=A&&(B-q)*(A-T)-(S-q)*(X-T)<0&&L--}return L!==0},k=new Map,z=(S,A)=>{let L=k.get(S)??{regions:[],lines:[]};for(let C of A.regions)L.regions.push(C);for(let C of A.lines)L.lines.push(C);k.set(S,L)};for(let S=g;S<=p;S++)for(let A=v;A<=y;A++){let L=A*i+(S%2?l*i:0),C=S*o,P=[d[0]+L,d[1]+C,d[2]+L,d[3]+C];if(P[2]<m[0]||P[0]>m[2]||P[3]<m[1]||P[1]>m[3])continue;let R=x.filter(Z=>!(P[2]<Z.box[0]||P[0]>Z.box[2]||P[3]<Z.box[1]||P[1]>Z.box[3]));if(!R.length)continue;M=R.length===x.length?f:R.flatMap(Z=>Z.polys);let q=[w(P[0],P[1]),w(P[2],P[1]),w(P[2],P[3]),w(P[0],P[3])],T=M.some(Z=>Z.some(([h1,H])=>h1>P[0]&&h1<P[2]&&H>P[1]&&H<P[3])),B=q.every(Boolean)&&!T,X=[1,0,0,1,L,C];for(let[Z,h1]of u3({layers:h.layers,parts:[]},X).layers)z(Z,B?h1:{regions:a0(h1.regions,M),lines:W0(h1.lines,M,"inside")})}return{layers:k,parts:[]}},spline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=g0(this.arg(s.args,"closed",-1,!1));if(!(i.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=Re(i,l,h);if(o===void 0)return L2([u]);let f=this.num(o,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return A0(i1(i4([u],f)))},hatch:s=>{let i=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),o=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(o>0))throw new Error("pitch must be more than 0");let h=i1(c([s.children()],"hatch").regions),u=z0(h);if(!u)return O0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],m=Math.hypot(u[2]-u[0],u[3]-u[1])/2+o,g=i*Math.PI/180,[p,v]=[Math.cos(g),Math.sin(g)],[y,b]=[-v,p],x=Math.ceil(m/o);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let M=[],w=Math.round((f*y+d*b)/o);for(let z=w-x;z<=w+x;z++){let S=z*o-(f*y+d*b),[A,L]=[f+y*S,d+b*S];M.push([[A-p*m,L-v*m],[A+p*m,L+v*m]])}if(l===void 0)return L2(W0(M,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return A0(a0(i1(i4(M,k).map(z=>z)),h))},flow:s=>{let i=this.arg(s.args,"field",0),o=this.num(this.arg(s.args,"spacing",1,2),"flow","spacing");if(!(o>0))throw new Error("spacing must be more than 0");let l=this.num(this.arg(s.args,"step",2,Math.min(.5,o/4)),"flow","step");if(!(l>0&&l<=o))throw new Error("step must be more than 0 and at most the spacing");let h=this.num(this.arg(s.args,"min_length",-1,2*o),"flow","min_length"),u=this.num(this.arg(s.args,"seed",-1,1),"flow","seed"),f=i1(c([s.children()],"flow").regions),d=z0(f);if(!d)return O0();let m=y=>[Math.cos(y*j8),Math.sin(y*j8)],g;if(typeof i=="number"){let y=m(i);g=()=>y}else{let y=this.fieldFn(i,"flow",s.env,s.args.at);g=b=>{let x=y(b);if(x===void 0)return null;if(typeof x=="number"&&Number.isFinite(x))return m(x);if(Array.isArray(x)&&typeof x[0]=="number"&&typeof x[1]=="number"&&Number.isFinite(x[0])&&Number.isFinite(x[1])){let M=Math.hypot(x[0],x[1]);return M>1e-12?[x[0]/M,x[1]/M]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${C0(x)}`)}}if(!((d[2]-d[0])/o*((d[3]-d[1])/o)<=this.limits.maxPoints/10))throw new Error("spacing is too small for the area");let v=kt({spacing:o,step:l,minLength:h,seed:u,box:d,inside:Lt(f),dir:g,tick:()=>this.tick(s.args.at),maxPoints:this.limits.maxPoints});return L2(W0(v,f,"inside"))},contours:s=>{let i=this.arg(s.args,"field",0),o=this.fieldFn(i,"contours",s.env,s.args.at),l=this.arg(s.args,"levels",1,10),h=this.arg(s.args,"interval",-1),u=this.num(this.arg(s.args,"cell",-1,1),"contours","cell");if(!(u>0))throw new Error("cell must be more than 0");let f=i1(c([s.children()],"contours").regions),d=z0(f);if(!d)return O0();let m=Math.ceil((d[2]-d[0])/u)+1,g=Math.ceil((d[3]-d[1])/u)+1;if(!(m*g<=this.limits.maxPoints/2))throw new Error(`a cell of ${u} samples the area at ${m*g} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let p=new Float64Array(m*g),v=1/0,y=-1/0;for(let w=0;w<g;w++)for(let k=0;k<m;k++){let z=o([d[0]+k*u,d[1]+w*u]);if(z===void 0){p[w*m+k]=NaN;continue}if(typeof z!="number"||!Number.isFinite(z))throw new Error(`field() must give a number or undef, got ${C0(z)}`);p[w*m+k]=z,v=Math.min(v,z),y=Math.max(y,z)}if(!(v<=y))return O0();let b;if(h!==void 0){let w=this.num(h,"contours","interval");if(!(w>0))throw new Error("interval must be more than 0");let k=Math.ceil(v/w),z=Math.floor(y/w);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(z))throw new Error(`the heights are too large for an interval of ${w}`);let S=Math.max(0,z-k+1);if(!(S<=1e4))throw new Error(`interval ${w} gives ${S} levels: use a larger interval`);b=Array.from({length:S},(A,L)=>(k+L)*w)}else if(Array.isArray(l))b=l.map(w=>this.num(w,"contours","levels"));else{let w=Math.floor(this.num(l,"contours","levels"));if(!(w>=1&&w<=1e4))throw new Error("levels must be 1 to 10000");b=Array.from({length:w},(k,z)=>v+(y-v)*(z+1)/(w+1))}let x=[],M=0;for(let w of b){this.tick(s.args.at,Math.ceil(m*g/100));let k=zt(p,m,g,d[0],d[1],u,w),z=k.reduce((S,A)=>S+A.length,0);if(!((M+=z)<=this.limits.maxPoints))throw new Error(`the contour lines have more than ${this.limits.maxPoints} points, the limit: use fewer levels or a larger cell`);this.spend(z);for(let S of k)x.push(S)}return L2(W0(x,f,"inside"))},occlude:s=>{let i;this.occluding++;try{i=s.childItems()}finally{this.occluding--}let o=u=>this.layers.get(u)?.mode??"cut",l=[],h=[];for(let u=i.length-1;u>=0;u--){let f=i[u];if(f.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[g,p]of f.layers){if(g===s2)continue;let v=o(g);!h.length||v==="cut"||v==="guide"?d.set(g,p):v==="line"?d.set(g,{regions:[],lines:W0([...p.lines,...i1(p.regions).map(y=>[...y,y[0]])],h,"outside")}):d.set(g,{regions:k0(p.regions,h),lines:W0(p.lines,h,"outside")})}l.push({layers:d,parts:[]});let m=[...f.layers].filter(([g])=>o(g)!=="guide").flatMap(([,g])=>g.regions);m.length&&(h=i1([...h,...m]))}return A2(l.reverse())},hide:s=>this.occluding?A0(i1(c([s.children()],"hide").regions),s2):(this.warn(`hide() only works inside occlude(); it draws nothing (${m2(s.args.at,!1)})`),O0()),paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],u=[];for(let f=o.length-1;f>=0;f--){let d=o[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let m=h,g=i1(c([d],"paint").regions);u[f]=g,h=m.length?i1([...m,...g]):g;let p=Array.isArray(i)?i[f]:void 0;if(p!=="")if(p!==void 0){this.layers.has(p)||this.layers.set(p,{name:p,mode:"fill",color:"#000000"}),l.push(A0(m.length?k0(g,m):g,p));let v=d.layers.get(s2);v&&l.push({layers:new Map([[s2,v]]),parts:[]})}else l.push(m.length?a(d,v=>({regions:k0(v.regions,m),lines:W0(v.lines,m,"outside")})):d)}return this.invisiblePaint(o,u,i,s.args.at),A2(l.reverse())},measure:s=>{let i=g0(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let u=X0(h.layers)??z0(h.parts.flatMap(p=>[...p.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(p=>p.layers)],d=f.flatMap(p=>p.get("cut")?.regions??[]),m=d.length?d:f.flatMap(p=>[...p].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),g=xt(i1(m));s.env.vars.set("$area",g.area),s.env.vars.set("$centroid",g.area>0?g.centroid:void 0)});return A2(i?o:o.slice(1))},fill_holes:s=>{let i=this.arg(s.args,"min_area",0),o=i===void 0?1/0:this.num(i,"fill_holes","min_area");return a(s.children(),l=>({regions:i1(l.regions).filter(h=>!(M1(h)<0&&-M1(h)<o)),lines:l.lines}))},join_islands:s=>{let i=this.num(this.arg(s.args,"width",0,1),"join_islands","width");if(!(i>0))throw new Error("join_islands(): width must be more than 0");let o=s.children(),l=h=>new Map([...h].map(([u,f])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:Ae(f.regions,i),lines:f.lines}:f]));return{layers:l(o.layers),parts:o.parts.map(h=>({...h,layers:l(h.layers)}))}},largest:s=>{let i=Math.floor(this.num(this.arg(s.args,"n",0,1),"largest","n"));if(!(i>=1))throw new Error("largest(): n must be 1 or more");let o=u=>F0(u).map(f=>({g:f,a:f.reduce((d,m)=>d+M1(m),0)})).sort((f,d)=>d.a-f.a).slice(0,i).flatMap(({g:f})=>f),l=s.children(),h=u=>new Map([...u].map(([f,d])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:o(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(u=>({...u,layers:h(u.layers)}))}},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),o=>({regions:n0(n0(o.regions,i,"round"),-i,"round"),lines:o.lines}))},stroke:s=>{let i=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),o=>({regions:i1([...o.regions,...i4(o.lines,i)]),lines:[]}))},outline:s=>a(s.children(),i=>({regions:[],lines:[...i.lines,...i1(i.regions).map(o=>[...o,o[0]])]})),cut:n("cut"),score:r("score"),engrave:r("engrave"),guide:n("guide"),layer:s=>{let i=this.arg(s.args,"name",0);if(typeof i!="string"||!i)throw new Error("layer() needs a name");let o=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(i),u=this.arg(s.args,"order",-1),f=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${i}" is the back of layer "${i.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let m=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(m))throw new Error('mode must be "cut", "line", "fill" or "guide"');let g=v0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(g))throw new Error('color must look like "#00aa00"');let p=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&m==="cut")throw new Error("a cut layer has no bleed");this.layers.set(i,{name:i,mode:m,color:g,...p!==void 0&&{order:p},...v!==void 0&&{bleed:v}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${C0(d)}`);if(d==="back"&&this.layers.get(i)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&s.env.vars.set("$mirrored",!g0(this.dyn(s.env,"$mirrored"))),b5(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=v0(this.arg(s.args,"name",0,"part")),o=this.arg(s.args,"qty",1,1),l=typeof o=="number"?Math.floor(o):1;if(!(l>=0))throw new Error(`qty must be 0 or more, got ${C0(o)}`);if(l===0)return{layers:new Map,parts:[]};let h=this.arg(s.args,"stack",-1),u=h===void 0?1:Math.floor(this.num(h,"part","stack"));if(!(u>=1))throw new Error("stack must be 1 or more");if(this.copies+=l*u,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let f=this.arg(s.args,"at",-1),d=this.arg(s.args,"rotate",-1),m=this.arg(s.args,"glue",-1),g=m===void 0?void 0:v0(m),p=v0(this.arg(s.args,"face",-1,"top"));if(p!=="top"&&p!=="bottom")throw new Error(`face must be "top" or "bottom", got ${C0(p)}`);let v=this.frame!==Te&&g===void 0,y=this.arg(s.args,"bend",-1),b=f===void 0&&d===void 0&&!v&&g===void 0&&y===void 0?void 0:this.placements(f,d,l),x=this.arg(s.args,"material",-1);x!==void 0&&s.env.vars.set("$material",v0(x));let M=this.thickness(s.env);b&&(v||u>1)&&(b=b.flatMap(g1=>{let X1=g===void 0?q1(this.frame,Z0(g1)):Z0(g1),D1=g!==void 0&&p==="bottom"?-M:M;return Array.from({length:u},(E,D)=>({...g1,matrix:q1(X1,B0(0,0,D*D1))}))}));let w=this.arg(s.args,"mirror",-1,!1),k;if(Array.isArray(w)){if(w.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${w.length}`);k=w.map(g1=>g0(g1))}else k=Array.from({length:l},()=>g0(w));let z=k.some(g1=>g1)&&!k.every(g1=>g1);if(z&&g!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let S=k[0],A=g1=>{let X1=s.env.vars.get("$mirrored"),D1=s.env.vars.has("$mirrored");g1&&s.env.vars.set("$mirrored",!0);try{let E=s.children();return g1?u3(E,[-1,0,0,1,0,0]):E}finally{g1&&(D1?s.env.vars.set("$mirrored",X1):s.env.vars.delete("$mirrored"))}},L=A(S),C=this.bends(y),P=this.arg(s.args,"on",-1),R=this.arg(s.args,"slots",-1),q=R===void 0?void 0:(Array.isArray(R)?R:[R]).map(g1=>{if(typeof g1!="string")throw new Error("slots must be part names");return g1}),T=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),B=this.arg(s.args,"slot_extra",-1),X=B===void 0?void 0:this.vec2(B,"slot_extra",!1),Z=this.arg(s.args,"bores",-1),h1=Z===void 0?void 0:(Array.isArray(Z)?Z:[Z]).map(g1=>{if(typeof g1!="string")throw new Error("bores must be hardware labels or kinds");return g1}),H=this.arg(s.args,"halving",-1),U=H===void 0?void 0:(Array.isArray(H)?H:[H]).map(g1=>{if(typeof g1!="string")throw new Error("halving must be part names");return g1}),Y=this.arg(s.args,"fit",-1,"turn");if(typeof Y!="number"&&!Object.prototype.hasOwnProperty.call(z5,v0(Y)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${C0(Y)}`);let Q=typeof Y=="number"?Y:z5[v0(Y)],W=(g1,X1,D1)=>{let E=D1.length===l,D=b?.filter((e1,u1)=>D1.includes(Math.floor(u1/u)+1));return{name:i,qty:D1.length*u,layers:g1,thickness:M,kerf:q0(this.dyn(s.env,"$kerf"))||0,material:v0(this.dyn(s.env,"$material")??"material"),...D?{placements:D}:{},...u>1?{stack:u}:{},...C.length?{bends:C}:{},...P!==void 0?{on:v0(P)}:{},...q?{slots:q,clearance:T}:{},...q&&X?{slotExtra:X}:{},...h1?{bores:h1,fit:Q}:{},...U?{halving:U,clearance:T}:{},...this.step?{step:this.step}:{},...g!==void 0&&{glue:{host:g,face:p}},...X1&&{mirrored:!0},...!E&&{copies:D1}}},F1=g1=>k.flatMap((X1,D1)=>X1===g1?[D1+1]:[]),L1=z?[W(L.layers,S,F1(S)),W(A(!S).layers,!S,F1(!S))]:[W(L.layers,S,F1(S))];return{layers:new Map,parts:[...L.parts,...L1]}},place:s=>{let i=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),o=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=q1(l,Z0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=v0(this.arg(s.args,"text",0,"")),o=g0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.children();let l=this.step,h=l&&i?`${this.stepNames[l-1]}: ${i}`:i,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=v0(this.arg(s.args,"kind",0,"dowel"));e2(d3,i)===void 0&&e2(U3,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${m2(s.args.at,!1)})${b3(i,Object.keys(d3))}`);let o=v0(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${C0(o)}`);let l=this.arg(s.args,"sides",-1),h=o==="ball"||l===0,u=this.vec3(this.arg(s.args,"from",1),"from"),f=this.arg(s.args,"to",2),d=h&&f===void 0?u:this.vec3(f,"to"),m=this.arg(s.args,"size",3,6),g=typeof m=="number"?m:this.vec2(m,"size",!1);if(h){if(typeof g!="number"||!(g>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let p=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(p[2])>.9*Math.hypot(...p),y=this.arg(s.args,"up",-1),b=y===void 0?v?[0,1,0]:[0,0,1]:this.vec3(y,"up"),x=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(x>=3&&x<=y6))throw new Error(`sides must be from 3 to ${y6} (or 0 for a ball), got ${C0(x)}`);if(this.pointCount+=h?2*y6:x*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let M=this.arg(s.args,"label",-1),w=this.frame,k=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2]+w[3],w[4]*S[0]+w[5]*S[1]+w[6]*S[2]+w[7],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]+w[11]],z=S=>[w[0]*S[0]+w[1]*S[1]+w[2]*S[2],w[4]*S[0]+w[5]*S[1]+w[6]*S[2],w[8]*S[0]+w[9]*S[1]+w[10]*S[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:i,from:k(u),to:k(d),size:g,up:z(b),sides:x,step:this.step,...M!==void 0?{label:v0(M)}:{}}),s.children()},material:s=>{let i=this.arg(s.args,"thickness",0),o=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return i!==void 0&&s.env.vars.set("$thickness",this.num(i,"material","thickness")),o!==void 0&&s.env.vars.set("$kerf",this.num(o,"material","kerf")),l!==void 0&&s.env.vars.set("$material",v0(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return O0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new I0(i.env,s.env);this.hoist(i.stmts,h);let u=new Set;if(l===void 0)o.forEach(g=>u.add(g));else for(let g of this.iterable(l,s.args.at)){let p=q0(g);o[p]?u.add(o[p]):o.length&&p>=o.length&&i.module&&i.pos&&this.warn(`${i.module}() uses children(${p}) but was given ${o.length} child${o.length===1?"":"ren"} (${m2(i.pos,!1)}). A module call takes one statement as its child: put several in braces, ${i.module}() { a(); b(); }`)}let f=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let m=this.childKey(h);for(let g of i.stmts)if(g.kind==="assign")this.stmt(g,h);else if(u.has(g)){let p=m&&d.get(g);if(p&&p.key===m){p.shape&&f.push(p.shape);continue}let v=this.effects(),y=this.stmt(g,h);y&&f.push(y),m&&this.effects()===v&&!y?.parts.length&&d.set(g,{key:m,shape:y})}return A2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/u*4),A0(w4(i,o,l,h,u))},finger_holes:s=>{let i=this.num(this.arg(s.args,"length",0),"finger_holes","length"),o=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(o==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(i)/l*4),A0(s7(i,o,this.thickness(s.env),l))},tslot:s=>{let i=this.num(this.arg(s.args,"d",0,3),"tslot","d"),o=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[i*1.85,i*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return A0(i1(i7(i,o,l,h,u)))},living_hinge:s=>{let[i,o]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.num(this.arg(s.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(s.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(o-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||u<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(i)/l+1)*(Math.abs(o)/(u+h)+2)*2),L2(o7(i,o,l,h,u))}};function c(s,i){let o={regions:[],lines:[]};for(let l of s){if(l.parts.length)throw new Error(`part() can only be the first child of ${i}()`);for(let[h,u]of l.layers)if(h!==s2)for(let f of u.regions)o.regions.push(f)}return o}function a(s,i){let o=l=>{let h=new Map;for(let[u,f]of l)h.set(u,i(f));return h};return{layers:o(s.layers),parts:s.parts.map(l=>({...l,layers:o(l.layers)}))}}}};var J3=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},k6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function z6(t,e){let n=[];for(let[r,c]of t){let a=[J3(r),J3(c)],s=n[n.length-1];(!s||s[0]!==a[0]||s[1]!==a[1])&&n.push(a)}for(;e&&n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n}var K3=(t,e)=>`M${z6(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function U4(t,e){let n=[];for(let r of e){let c=[],a=[],s=[];for(let i of t){let o=i.layers.get(r.name);if(o){for(let l of o.lines)c.push(K3(l,!1));for(let l of o.regions)(M1(l)<0?a:s).push(K3(l,!0))}}(c.length||a.length||s.length)&&n.push({name:r.name,mode:r.mode,color:r.color,d:[...c,...a,...s].join(""),regions:[...a,...s].join(""),lines:c.join("")})}return n}function B4(t,e,n,r){let c=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${J3(e)}mm" height="${J3(n)}mm" viewBox="0 0 ${J3(e)} ${J3(n)}">`];for(let a of r){let s=[],i=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${k6(l.part)}"`;if(a.mode==="fill"){h.regions.length&&i.push(`<path${u} d="${h.regions.map(f=>K3(f,!0)).join("")}"/>`);for(let f of h.lines)i.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${K3(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${K3(f,!1)}"/>`);for(let f of h.regions)(M1(f)<0?s:i).push(`<path${u} d="${K3(f,!0)}"/>`)}if(!s.length&&!i.length)continue;let o=a.mode==="fill"?`fill="${a.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${a.color}" stroke-width="0.1"${a.mode==="guide"?' stroke-dasharray="1 1"':""}`;c.push(`<g id="${k6(a.name)}" inkscape:groupmode="layer" inkscape:label="${k6(a.name)}" data-mode="${a.mode}" ${o}>`,...s,...i,"</g>")}return c.push("</svg>",""),c.join(`
|
|
2643
|
-
`)}var
|
|
3021
|
+
`};String.prototype.codePointAt||(function(){var t=(function(){try{var n={},r=Object.defineProperty,c=r(n,n,n)&&r}catch{}return c})(),e=function(n){if(this==null)throw TypeError();var r=String(this),c=r.length,a=n?Number(n):0;if(a!=a&&(a=0),!(a<0||a>=c)){var s=r.charCodeAt(a),o;return s>=55296&&s<=56319&&c>a+1&&(o=r.charCodeAt(a+1),o>=56320&&o<=57343)?(s-55296)*1024+o-56320+65536:s}};t?t(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var Mt=0,L7=-3;function q5(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function sc(t,e){this.source=t,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new q5,this.dtree=new q5}var C7=new q5,P7=new q5,wt=new Uint8Array(30),kt=new Uint16Array(30),E7=new Uint8Array(30),T7=new Uint16Array(30),oc=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Un=new q5,P2=new Uint8Array(320);function I7(t,e,n,r){var c,a;for(c=0;c<n;++c)t[c]=0;for(c=0;c<30-n;++c)t[c+n]=c/n|0;for(a=r,c=0;c<30;++c)e[c]=a,a+=1<<t[c]}function ic(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 Bn=new Uint16Array(16);function rt(t,e,n,r){var c,a;for(c=0;c<16;++c)t.table[c]=0;for(c=0;c<r;++c)t.table[e[n+c]]++;for(t.table[0]=0,a=0,c=0;c<16;++c)Bn[c]=a,a+=t.table[c];for(c=0;c<r;++c)e[n+c]&&(t.trans[Bn[e[n+c]]++]=c)}function lc(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=t.tag&1;return t.tag>>>=1,e}function E2(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var r=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,r+n}function ft(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,r=0,c=0,a=t.tag;do r=2*r+(a&1),a>>>=1,++c,n+=e.table[c],r-=e.table[c];while(r>=0);return t.tag=a,t.bitcount-=c,e.trans[n+r]}function hc(t,e,n){var r,c,a,s,o,i;for(r=E2(t,5,257),c=E2(t,5,1),a=E2(t,4,4),s=0;s<19;++s)P2[s]=0;for(s=0;s<a;++s){var l=E2(t,3,0);P2[oc[s]]=l}for(rt(Un,P2,0,19),o=0;o<r+c;){var h=ft(t,Un);switch(h){case 16:var u=P2[o-1];for(i=E2(t,2,3);i;--i)P2[o++]=u;break;case 17:for(i=E2(t,3,3);i;--i)P2[o++]=0;break;case 18:for(i=E2(t,7,11);i;--i)P2[o++]=0;break;default:P2[o++]=h;break}}rt(e,P2,0,r),rt(n,P2,r,c)}function _n(t,e,n){for(;;){var r=ft(t,e);if(r===256)return Mt;if(r<256)t.dest[t.destLen++]=r;else{var c,a,s,o;for(r-=257,c=E2(t,wt[r],kt[r]),a=ft(t,n),s=t.destLen-E2(t,E7[a],T7[a]),o=s;o<s+c;++o)t.dest[t.destLen++]=t.dest[o]}}}function uc(t){for(var e,n,r;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],n=t.source[t.sourceIndex+3],n=256*n+t.source[t.sourceIndex+2],e!==(~n&65535))return L7;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,Mt}function fc(t,e){var n=new sc(t,e),r,c,a;do{switch(r=lc(n),c=E2(n,2,0),c){case 0:a=uc(n);break;case 1:a=_n(n,C7,P7);break;case 2:hc(n,n.ltree,n.dtree),a=_n(n,n.ltree,n.dtree);break;default:a=L7}if(a!==Mt)throw new Error("Data error")}while(!r);return n.destLen<n.dest.length?typeof n.dest.slice=="function"?n.dest.slice(0,n.destLen):n.dest.subarray(0,n.destLen):n.dest}ic(C7,P7);I7(wt,kt,4,3);I7(E7,T7,2,1);wt[28]=0;kt[28]=258;var dc=fc;function Y3(t,e,n,r,c){return Math.pow(1-c,3)*t+3*Math.pow(1-c,2)*c*e+3*(1-c)*Math.pow(c,2)*n+Math.pow(c,3)*r}function s3(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}s3.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};s3.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))};s3.prototype.addX=function(t){this.addPoint(t,null)};s3.prototype.addY=function(t){this.addPoint(null,t)};s3.prototype.addBezier=function(t,e,n,r,c,a,s,o){var i=[t,e],l=[n,r],h=[c,a],u=[s,o];this.addPoint(t,e),this.addPoint(s,o);for(var f=0;f<=1;f++){var d=6*i[f]-12*l[f]+6*h[f],p=-3*i[f]+9*l[f]-9*h[f]+3*u[f],m=3*l[f]-3*i[f];if(p===0){if(d===0)continue;var g=-m/d;0<g&&g<1&&(f===0&&this.addX(Y3(i[f],l[f],h[f],u[f],g)),f===1&&this.addY(Y3(i[f],l[f],h[f],u[f],g)));continue}var v=Math.pow(d,2)-4*m*p;if(!(v<0)){var b=(-d+Math.sqrt(v))/(2*p);0<b&&b<1&&(f===0&&this.addX(Y3(i[f],l[f],h[f],u[f],b)),f===1&&this.addY(Y3(i[f],l[f],h[f],u[f],b)));var y=(-d-Math.sqrt(v))/(2*p);0<y&&y<1&&(f===0&&this.addX(Y3(i[f],l[f],h[f],u[f],y)),f===1&&this.addY(Y3(i[f],l[f],h[f],u[f],y)))}}};s3.prototype.addQuad=function(t,e,n,r,c,a){var s=t+.6666666666666666*(n-t),o=e+2/3*(r-e),i=s+1/3*(c-t),l=o+1/3*(a-e);this.addBezier(t,e,s,o,i,l,c,a)};function P0(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}P0.prototype.moveTo=function(t,e){this.commands.push({type:"M",x:t,y:e})};P0.prototype.lineTo=function(t,e){this.commands.push({type:"L",x:t,y:e})};P0.prototype.curveTo=P0.prototype.bezierCurveTo=function(t,e,n,r,c,a){this.commands.push({type:"C",x1:t,y1:e,x2:n,y2:r,x:c,y:a})};P0.prototype.quadTo=P0.prototype.quadraticCurveTo=function(t,e,n,r){this.commands.push({type:"Q",x1:t,y1:e,x:n,y:r})};P0.prototype.close=P0.prototype.closePath=function(){this.commands.push({type:"Z"})};P0.prototype.extend=function(t){if(t.commands)t=t.commands;else if(t instanceof s3){var e=t;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,t)};P0.prototype.getBoundingBox=function(){for(var t=new s3,e=0,n=0,r=0,c=0,a=0;a<this.commands.length;a++){var s=this.commands[a];switch(s.type){case"M":t.addPoint(s.x,s.y),e=r=s.x,n=c=s.y;break;case"L":t.addPoint(s.x,s.y),r=s.x,c=s.y;break;case"Q":t.addQuad(r,c,s.x1,s.y1,s.x,s.y),r=s.x,c=s.y;break;case"C":t.addBezier(r,c,s.x1,s.y1,s.x2,s.y2,s.x,s.y),r=s.x,c=s.y;break;case"Z":r=e,c=n;break;default:throw new Error("Unexpected path command "+s.type)}}return t.isEmpty()&&t.addPoint(0,0),t};P0.prototype.draw=function(t){t.beginPath();for(var e=0;e<this.commands.length;e+=1){var n=this.commands[e];n.type==="M"?t.moveTo(n.x,n.y):n.type==="L"?t.lineTo(n.x,n.y):n.type==="C"?t.bezierCurveTo(n.x1,n.y1,n.x2,n.y2,n.x,n.y):n.type==="Q"?t.quadraticCurveTo(n.x1,n.y1,n.x,n.y):n.type==="Z"&&t.closePath()}this.fill&&(t.fillStyle=this.fill,t.fill()),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.stroke())};P0.prototype.toPathData=function(t){t=t!==void 0?t:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(t)}function n(){for(var s=arguments,o="",i=0;i<arguments.length;i+=1){var l=s[i];l>=0&&i>0&&(o+=" "),o+=e(l)}return o}for(var r="",c=0;c<this.commands.length;c+=1){var a=this.commands[c];a.type==="M"?r+="M"+n(a.x,a.y):a.type==="L"?r+="L"+n(a.x,a.y):a.type==="C"?r+="C"+n(a.x1,a.y1,a.x2,a.y2,a.x,a.y):a.type==="Q"?r+="Q"+n(a.x1,a.y1,a.x,a.y):a.type==="Z"&&(r+="Z")}return r};P0.prototype.toSVG=function(t){var e='<path d="';return e+=this.toPathData(t),e+='"',this.fill&&this.fill!=="black"&&(this.fill===null?e+=' fill="none"':e+=' fill="'+this.fill+'"'),this.stroke&&(e+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),e+="/>",e};P0.prototype.toDOMElement=function(t){var e=this.toPathData(t),n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d",e),n};function V7(t){throw new Error(t)}function jn(t,e){t||V7(e)}var T1={fail:V7,argument:jn,assert:jn},Gn=32768,Wn=2147483648,K3={},c1={},H1={};function b2(t){return function(){return t}}c1.BYTE=function(t){return T1.argument(t>=0&&t<=255,"Byte value should be between 0 and 255."),[t]};H1.BYTE=b2(1);c1.CHAR=function(t){return[t.charCodeAt(0)]};H1.CHAR=b2(1);c1.CHARARRAY=function(t){typeof t>"u"&&(t="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],n=0;n<t.length;n+=1)e[n]=t.charCodeAt(n);return e};H1.CHARARRAY=function(t){return typeof t>"u"?0:t.length};c1.USHORT=function(t){return[t>>8&255,t&255]};H1.USHORT=b2(2);c1.SHORT=function(t){return t>=Gn&&(t=-(2*Gn-t)),[t>>8&255,t&255]};H1.SHORT=b2(2);c1.UINT24=function(t){return[t>>16&255,t>>8&255,t&255]};H1.UINT24=b2(3);c1.ULONG=function(t){return[t>>24&255,t>>16&255,t>>8&255,t&255]};H1.ULONG=b2(4);c1.LONG=function(t){return t>=Wn&&(t=-(2*Wn-t)),[t>>24&255,t>>16&255,t>>8&255,t&255]};H1.LONG=b2(4);c1.FIXED=c1.ULONG;H1.FIXED=H1.ULONG;c1.FWORD=c1.SHORT;H1.FWORD=H1.SHORT;c1.UFWORD=c1.USHORT;H1.UFWORD=H1.USHORT;c1.LONGDATETIME=function(t){return[0,0,0,0,t>>24&255,t>>16&255,t>>8&255,t&255]};H1.LONGDATETIME=b2(8);c1.TAG=function(t){return T1.argument(t.length===4,"Tag should be exactly 4 ASCII characters."),[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]};H1.TAG=b2(4);c1.Card8=c1.BYTE;H1.Card8=H1.BYTE;c1.Card16=c1.USHORT;H1.Card16=H1.USHORT;c1.OffSize=c1.BYTE;H1.OffSize=H1.BYTE;c1.SID=c1.USHORT;H1.SID=H1.USHORT;c1.NUMBER=function(t){return t>=-107&&t<=107?[t+139]:t>=108&&t<=1131?(t=t-108,[(t>>8)+247,t&255]):t>=-1131&&t<=-108?(t=-t-108,[(t>>8)+251,t&255]):t>=-32768&&t<=32767?c1.NUMBER16(t):c1.NUMBER32(t)};H1.NUMBER=function(t){return c1.NUMBER(t).length};c1.NUMBER16=function(t){return[28,t>>8&255,t&255]};H1.NUMBER16=b2(3);c1.NUMBER32=function(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]};H1.NUMBER32=b2(5);c1.REAL=function(t){var e=t.toString(),n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(n){var r=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));e=(Math.round(t*r)/r).toString()}for(var c="",a=0,s=e.length;a<s;a+=1){var o=e[a];o==="e"?c+=e[++a]==="-"?"c":"b":o==="."?c+="a":o==="-"?c+="e":c+=o}c+=c.length&1?"f":"ff";for(var i=[30],l=0,h=c.length;l<h;l+=2)i.push(parseInt(c.substr(l,2),16));return i};H1.REAL=function(t){return c1.REAL(t).length};c1.NAME=c1.CHARARRAY;H1.NAME=H1.CHARARRAY;c1.STRING=c1.CHARARRAY;H1.STRING=H1.CHARARRAY;K3.UTF8=function(t,e,n){for(var r=[],c=n,a=0;a<c;a++,e+=1)r[a]=t.getUint8(e);return String.fromCharCode.apply(null,r)};K3.UTF16=function(t,e,n){for(var r=[],c=n/2,a=0;a<c;a++,e+=2)r[a]=t.getUint16(e);return String.fromCharCode.apply(null,r)};c1.UTF16=function(t){for(var e=[],n=0;n<t.length;n+=1){var r=t.charCodeAt(n);e[e.length]=r>>8&255,e[e.length]=r&255}return e};H1.UTF16=function(t){return t.length*2};var dt={"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"};K3.MACSTRING=function(t,e,n,r){var c=dt[r];if(c!==void 0){for(var a="",s=0;s<n;s++){var o=t.getUint8(e+s);o<=127?a+=String.fromCharCode(o):a+=c[o&127]}return a}};var Ve=typeof WeakMap=="function"&&new WeakMap,He,mc=function(t){if(!He){He={};for(var e in dt)He[e]=new String(e)}var n=He[t];if(n!==void 0){if(Ve){var r=Ve.get(n);if(r!==void 0)return r}var c=dt[t];if(c!==void 0){for(var a={},s=0;s<c.length;s++)a[c.charCodeAt(s)]=s+128;return Ve&&Ve.set(n,a),a}}};c1.MACSTRING=function(t,e){var n=mc(e);if(n!==void 0){for(var r=[],c=0;c<t.length;c++){var a=t.charCodeAt(c);if(a>=128&&(a=n[a],a===void 0))return;r[c]=a}return r}};H1.MACSTRING=function(t,e){var n=c1.MACSTRING(t,e);return n!==void 0?n.length:0};function mt(t){return t>=-128&&t<=127}function pc(t,e,n){for(var r=0,c=t.length;e<c&&r<64&&t[e]===0;)++e,++r;return n.push(128|r-1),e}function gc(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(!mt(s)||s===0&&a+1<c&&t[a+1]===0)break;++a,++r}n.push(r-1);for(var o=e;o<a;++o)n.push(t[o]+256&255);return a}function vc(t,e,n){for(var r=0,c=t.length,a=e;a<c&&r<64;){var s=t[a];if(s===0||mt(s)&&a+1<c&&mt(t[a+1]))break;++a,++r}n.push(64|r-1);for(var o=e;o<a;++o){var i=t[o];n.push(i+65536>>8&255,i+256&255)}return a}c1.VARDELTAS=function(t){for(var e=0,n=[];e<t.length;){var r=t[e];r===0?e=pc(t,e,n):r>=-128&&r<=127?e=gc(t,e,n):e=vc(t,e,n)}return n};c1.INDEX=function(t){for(var e=1,n=[e],r=[],c=0;c<t.length;c+=1){var a=c1.OBJECT(t[c]);Array.prototype.push.apply(r,a),e+=a.length,n.push(e)}if(r.length===0)return[0,0];for(var s=[],o=1+Math.floor(Math.log(e)/Math.log(2))/8|0,i=[void 0,c1.BYTE,c1.USHORT,c1.UINT24,c1.ULONG][o],l=0;l<n.length;l+=1){var h=i(n[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(c1.Card16(t.length),c1.OffSize(o),s,r)};H1.INDEX=function(t){return c1.INDEX(t).length};c1.DICT=function(t){for(var e=[],n=Object.keys(t),r=n.length,c=0;c<r;c+=1){var a=parseInt(n[c],0),s=t[a];e=e.concat(c1.OPERAND(s.value,s.type)),e=e.concat(c1.OPERATOR(a))}return e};H1.DICT=function(t){return c1.DICT(t).length};c1.OPERATOR=function(t){return t<1200?[t]:[12,t-1200]};c1.OPERAND=function(t,e){var n=[];if(Array.isArray(e))for(var r=0;r<e.length;r+=1)T1.argument(t.length===e.length,"Not enough arguments given for type"+e),n=n.concat(c1.OPERAND(t[r],e[r]));else if(e==="SID")n=n.concat(c1.NUMBER(t));else if(e==="offset")n=n.concat(c1.NUMBER32(t));else if(e==="number")n=n.concat(c1.NUMBER(t));else if(e==="real")n=n.concat(c1.REAL(t));else throw new Error("Unknown operand type "+e);return n};c1.OP=c1.BYTE;H1.OP=H1.BYTE;var Oe=typeof WeakMap=="function"&&new WeakMap;c1.CHARSTRING=function(t){if(Oe){var e=Oe.get(t);if(e!==void 0)return e}for(var n=[],r=t.length,c=0;c<r;c+=1){var a=t[c];n=n.concat(c1[a.type](a.value))}return Oe&&Oe.set(t,n),n};H1.CHARSTRING=function(t){return c1.CHARSTRING(t).length};c1.OBJECT=function(t){var e=c1[t.type];return T1.argument(e!==void 0,"No encoding function for type "+t.type),e(t.value)};H1.OBJECT=function(t){var e=H1[t.type];return T1.argument(e!==void 0,"No sizeOf function for type "+t.type),e(t.value)};c1.TABLE=function(t){for(var e=[],n=t.fields.length,r=[],c=[],a=0;a<n;a+=1){var s=t.fields[a],o=c1[s.type];T1.argument(o!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var i=t[s.name];i===void 0&&(i=s.value);var l=o(i);s.type==="TABLE"?(c.push(e.length),e=e.concat([0,0]),r.push(l)):e=e.concat(l)}for(var h=0;h<r.length;h+=1){var u=c[h],f=e.length;T1.argument(f<65536,"Table "+t.tableName+" too big."),e[u]=f>>8,e[u+1]=f&255,e=e.concat(r[h])}return e};H1.TABLE=function(t){for(var e=0,n=t.fields.length,r=0;r<n;r+=1){var c=t.fields[r],a=H1[c.type];T1.argument(a!==void 0,"No sizeOf function for field type "+c.type+" ("+c.name+")");var s=t[c.name];s===void 0&&(s=c.value),e+=a(s),c.type==="TABLE"&&(e+=2)}return e};c1.RECORD=c1.TABLE;H1.RECORD=H1.TABLE;c1.LITERAL=function(t){return t};H1.LITERAL=function(t){return t.length};function V0(t,e,n){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var r=0;r<e.length;r+=1){var c=e[r];this[c.name]=c.value}if(this.tableName=t,this.fields=e,n)for(var a=Object.keys(n),s=0;s<a.length;s+=1){var o=a[s],i=n[o];this[o]!==void 0&&(this[o]=i)}}V0.prototype.encode=function(){return c1.TABLE(this)};V0.prototype.sizeOf=function(){return H1.TABLE(this)};function N5(t,e,n){n===void 0&&(n=e.length);var r=new Array(e.length+1);r[0]={name:t+"Count",type:"USHORT",value:n};for(var c=0;c<e.length;c++)r[c+1]={name:t+c,type:"USHORT",value:e[c]};return r}function pt(t,e,n){var r=e.length,c=new Array(r+1);c[0]={name:t+"Count",type:"USHORT",value:r};for(var a=0;a<r;a++)c[a+1]={name:t+a,type:"TABLE",value:n(e[a],a)};return c}function U5(t,e,n){var r=e.length,c=[];c[0]={name:t+"Count",type:"USHORT",value:r};for(var a=0;a<r;a++)c=c.concat(n(e[a],a));return c}function qe(t){t.format===1?V0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(N5("glyph",t.glyphs))):t.format===2?V0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(U5("rangeRecord",t.ranges,function(e){return[{name:"startGlyphID",type:"USHORT",value:e.start},{name:"endGlyphID",type:"USHORT",value:e.end},{name:"startCoverageIndex",type:"USHORT",value:e.index}]}))):T1.assert(!1,"Coverage format must be 1 or 2.")}qe.prototype=Object.create(V0.prototype);qe.prototype.constructor=qe;function Ne(t){V0.call(this,"scriptListTable",U5("scriptRecord",t,function(e,n){var r=e.script,c=r.defaultLangSys;return T1.assert(!!c,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+n,type:"TAG",value:e.tag},{name:"script"+n,type:"TABLE",value:new V0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new V0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:c.reqFeatureIndex}].concat(N5("featureIndex",c.featureIndexes)))}].concat(U5("langSys",r.langSysRecords,function(a,s){var o=a.langSys;return[{name:"langSysTag"+s,type:"TAG",value:a.tag},{name:"langSys"+s,type:"TABLE",value:new V0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:o.reqFeatureIndex}].concat(N5("featureIndex",o.featureIndexes)))}]})))}]}))}Ne.prototype=Object.create(V0.prototype);Ne.prototype.constructor=Ne;function Ue(t){V0.call(this,"featureListTable",U5("featureRecord",t,function(e,n){var r=e.feature;return[{name:"featureTag"+n,type:"TAG",value:e.tag},{name:"feature"+n,type:"TABLE",value:new V0("featureTable",[{name:"featureParams",type:"USHORT",value:r.featureParams}].concat(N5("lookupListIndex",r.lookupListIndexes)))}]}))}Ue.prototype=Object.create(V0.prototype);Ue.prototype.constructor=Ue;function Be(t,e){V0.call(this,"lookupListTable",pt("lookup",t,function(n){var r=e[n.lookupType];return T1.assert(!!r,"Unable to write GSUB lookup type "+n.lookupType+" tables."),new V0("lookupTable",[{name:"lookupType",type:"USHORT",value:n.lookupType},{name:"lookupFlag",type:"USHORT",value:n.lookupFlag}].concat(pt("subtable",n.subtables,r)))}))}Be.prototype=Object.create(V0.prototype);Be.prototype.constructor=Be;var o1={Table:V0,Record:V0,Coverage:qe,ScriptList:Ne,FeatureList:Ue,LookupList:Be,ushortList:N5,tableList:pt,recordList:U5};function Xn(t,e){return t.getUint8(e)}function _e(t,e){return t.getUint16(e,!1)}function yc(t,e){return t.getInt16(e,!1)}function zt(t,e){return t.getUint32(e,!1)}function H7(t,e){var n=t.getInt16(e,!1),r=t.getUint16(e+2,!1);return n+r/65535}function bc(t,e){for(var n="",r=e;r<e+4;r+=1)n+=String.fromCharCode(t.getInt8(r));return n}function xc(t,e,n){for(var r=0,c=0;c<n;c+=1)r<<=8,r+=t.getUint8(e+c);return r}function Mc(t,e,n){for(var r=[],c=e;c<n;c+=1)r.push(t.getUint8(c));return r}function wc(t){for(var e="",n=0;n<t.length;n+=1)e+=String.fromCharCode(t[n]);return e}var kc={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function N(t,e){this.data=t,this.offset=e,this.relativeOffset=0}N.prototype.parseByte=function(){var t=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};N.prototype.parseChar=function(){var t=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,t};N.prototype.parseCard8=N.prototype.parseByte;N.prototype.parseUShort=function(){var t=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};N.prototype.parseCard16=N.prototype.parseUShort;N.prototype.parseSID=N.prototype.parseUShort;N.prototype.parseOffset16=N.prototype.parseUShort;N.prototype.parseShort=function(){var t=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,t};N.prototype.parseF2Dot14=function(){var t=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,t};N.prototype.parseULong=function(){var t=zt(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseOffset32=N.prototype.parseULong;N.prototype.parseFixed=function(){var t=H7(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,t};N.prototype.parseString=function(t){var e=this.data,n=this.offset+this.relativeOffset,r="";this.relativeOffset+=t;for(var c=0;c<t;c++)r+=String.fromCharCode(e.getUint8(n+c));return r};N.prototype.parseTag=function(){return this.parseString(4)};N.prototype.parseLongDateTime=function(){var t=zt(this.data,this.offset+this.relativeOffset+4);return t-=2082844800,this.relativeOffset+=8,t};N.prototype.parseVersion=function(t){var e=_e(this.data,this.offset+this.relativeOffset),n=_e(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,t===void 0&&(t=4096),e+n/t/10};N.prototype.skip=function(t,e){e===void 0&&(e=1),this.relativeOffset+=kc[t]*e};N.prototype.parseULongList=function(t){t===void 0&&(t=this.parseULong());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getUint32(r),r+=4;return this.relativeOffset+=t*4,e};N.prototype.parseOffset16List=N.prototype.parseUShortList=function(t){t===void 0&&(t=this.parseUShort());for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getUint16(r),r+=2;return this.relativeOffset+=t*2,e};N.prototype.parseShortList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getInt16(r),r+=2;return this.relativeOffset+=t*2,e};N.prototype.parseByteList=function(t){for(var e=new Array(t),n=this.data,r=this.offset+this.relativeOffset,c=0;c<t;c++)e[c]=n.getUint8(r++);return this.relativeOffset+=t,e};N.prototype.parseList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};N.prototype.parseList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=0;r<t;r++)n[r]=e.call(this);return n};N.prototype.parseRecordList=function(t,e){e||(e=t,t=this.parseUShort());for(var n=new Array(t),r=Object.keys(e),c=0;c<t;c++){for(var a={},s=0;s<r.length;s++){var o=r[s],i=e[o];a[o]=i.call(this)}n[c]=a}return n};N.prototype.parseRecordList32=function(t,e){e||(e=t,t=this.parseULong());for(var n=new Array(t),r=Object.keys(e),c=0;c<t;c++){for(var a={},s=0;s<r.length;s++){var o=r[s],i=e[o];a[o]=i.call(this)}n[c]=a}return n};N.prototype.parseStruct=function(t){if(typeof t=="function")return t.call(this);for(var e=Object.keys(t),n={},r=0;r<e.length;r++){var c=e[r],a=t[c];n[c]=a.call(this)}return n};N.prototype.parseValueRecord=function(t){if(t===void 0&&(t=this.parseUShort()),t!==0){var e={};return t&1&&(e.xPlacement=this.parseShort()),t&2&&(e.yPlacement=this.parseShort()),t&4&&(e.xAdvance=this.parseShort()),t&8&&(e.yAdvance=this.parseShort()),t&16&&(e.xPlaDevice=void 0,this.parseShort()),t&32&&(e.yPlaDevice=void 0,this.parseShort()),t&64&&(e.xAdvDevice=void 0,this.parseShort()),t&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};N.prototype.parseValueRecordList=function(){for(var t=this.parseUShort(),e=this.parseUShort(),n=new Array(e),r=0;r<e;r++)n[r]=this.parseValueRecord(t);return n};N.prototype.parsePointer=function(t){var e=this.parseOffset16();if(e>0)return new N(this.data,this.offset+e).parseStruct(t)};N.prototype.parsePointer32=function(t){var e=this.parseOffset32();if(e>0)return new N(this.data,this.offset+e).parseStruct(t)};N.prototype.parseListOfLists=function(t){for(var e=this.parseOffset16List(),n=e.length,r=this.relativeOffset,c=new Array(n),a=0;a<n;a++){var s=e[a];if(s===0){c[a]=void 0;continue}if(this.relativeOffset=s,t){for(var o=this.parseOffset16List(),i=new Array(o.length),l=0;l<o.length;l++)this.relativeOffset=s+o[l],i[l]=t.call(this);c[a]=i}else c[a]=this.parseUShortList()}return this.relativeOffset=r,c};N.prototype.parseCoverage=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort(),n=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(n)};if(e===2){for(var r=new Array(n),c=0;c<n;c++)r[c]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:r}}throw new Error("0x"+t.toString(16)+": Coverage format must be 1 or 2.")};N.prototype.parseClassDef=function(){var t=this.offset+this.relativeOffset,e=this.parseUShort();if(e===1)return{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()};if(e===2)return{format:2,ranges:this.parseRecordList({start:N.uShort,end:N.uShort,classId:N.uShort})};throw new Error("0x"+t.toString(16)+": ClassDef format must be 1 or 2.")};N.list=function(t,e){return function(){return this.parseList(t,e)}};N.list32=function(t,e){return function(){return this.parseList32(t,e)}};N.recordList=function(t,e){return function(){return this.parseRecordList(t,e)}};N.recordList32=function(t,e){return function(){return this.parseRecordList32(t,e)}};N.pointer=function(t){return function(){return this.parsePointer(t)}};N.pointer32=function(t){return function(){return this.parsePointer32(t)}};N.tag=N.prototype.parseTag;N.byte=N.prototype.parseByte;N.uShort=N.offset16=N.prototype.parseUShort;N.uShortList=N.prototype.parseUShortList;N.uLong=N.offset32=N.prototype.parseULong;N.uLongList=N.prototype.parseULongList;N.struct=N.prototype.parseStruct;N.coverage=N.prototype.parseCoverage;N.classDef=N.prototype.parseClassDef;var Zn={reserved:N.uShort,reqFeatureIndex:N.uShort,featureIndexes:N.uShortList};N.prototype.parseScriptList=function(){return this.parsePointer(N.recordList({tag:N.tag,script:N.pointer({defaultLangSys:N.pointer(Zn),langSysRecords:N.recordList({tag:N.tag,langSys:N.pointer(Zn)})})}))||[]};N.prototype.parseFeatureList=function(){return this.parsePointer(N.recordList({tag:N.tag,feature:N.pointer({featureParams:N.offset16,lookupListIndexes:N.uShortList})}))||[]};N.prototype.parseLookupList=function(t){return this.parsePointer(N.list(N.pointer(function(){var e=this.parseUShort();T1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var n=this.parseUShort(),r=n&16;return{lookupType:e,lookupFlag:n,subtables:this.parseList(N.pointer(t[e])),markFilteringSet:r?this.parseUShort():void 0}})))||[]};N.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var t=this.parseUShort(),e=this.parseUShort();T1.argument(t===1&&e<1,"GPOS/GSUB feature variations table unknown.");var n=this.parseRecordList32({conditionSetOffset:N.offset32,featureTableSubstitutionOffset:N.offset32});return n})||[]};var d1={getByte:Xn,getCard8:Xn,getUShort:_e,getCard16:_e,getShort:yc,getULong:zt,getFixed:H7,getTag:bc,getOffset:xc,getBytes:Mc,bytesToString:wc,Parser:N};function zc(t,e){e.parseUShort(),t.length=e.parseULong(),t.language=e.parseULong();var n;t.groupCount=n=e.parseULong(),t.glyphIndexMap={};for(var r=0;r<n;r+=1)for(var c=e.parseULong(),a=e.parseULong(),s=e.parseULong(),o=c;o<=a;o+=1)t.glyphIndexMap[o]=s,s++}function Sc(t,e,n,r,c){t.length=e.parseUShort(),t.language=e.parseUShort();var a;t.segCount=a=e.parseUShort()>>1,e.skip("uShort",3),t.glyphIndexMap={};for(var s=new d1.Parser(n,r+c+14),o=new d1.Parser(n,r+c+16+a*2),i=new d1.Parser(n,r+c+16+a*4),l=new d1.Parser(n,r+c+16+a*6),h=r+c+16+a*8,u=0;u<a-1;u+=1)for(var f=void 0,d=s.parseUShort(),p=o.parseUShort(),m=i.parseShort(),g=l.parseUShort(),v=p;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-p)*2,f=d1.getUShort(n,h),f!==0&&(f=f+m&65535)):f=v+m&65535,t.glyphIndexMap[v]=f}function Ac(t,e){var n={};n.version=d1.getUShort(t,e),T1.argument(n.version===0,"cmap table version should be 0."),n.numTables=d1.getUShort(t,e+2);for(var r=-1,c=n.numTables-1;c>=0;c-=1){var a=d1.getUShort(t,e+4+c*8),s=d1.getUShort(t,e+4+c*8+2);if(a===3&&(s===0||s===1||s===10)||a===0&&(s===0||s===1||s===2||s===3||s===4)){r=d1.getULong(t,e+4+c*8+4);break}}if(r===-1)throw new Error("No valid cmap sub-tables found.");var o=new d1.Parser(t,e+r);if(n.format=o.parseUShort(),n.format===12)zc(n,o);else if(n.format===4)Sc(n,o,t,e,r);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+n.format+").");return n}function Lc(t,e,n){t.segments.push({end:e,start:e,delta:-(e-n),offset:0,glyphIndex:n})}function Cc(t){t.segments.push({end:65535,start:65535,delta:1,offset:0})}function Pc(t){var e=!0,n;for(n=t.length-1;n>0;n-=1){var r=t.get(n);if(r.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var c=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||(c=c.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),c=c.concat([{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var a=new o1.Table("cmap",c);for(a.segments=[],n=0;n<t.length;n+=1){for(var s=t.get(n),o=0;o<s.unicodes.length;o+=1)Lc(a,s.unicodes[o],n);a.segments=a.segments.sort(function(b,y){return b.start-y.start})}Cc(a);var i=a.segments.length,l=0,h=[],u=[],f=[],d=[],p=[],m=[];for(n=0;n<i;n+=1){var g=a.segments[n];g.end<=65535&&g.start<=65535?(h=h.concat({name:"end_"+n,type:"USHORT",value:g.end}),u=u.concat({name:"start_"+n,type:"USHORT",value:g.start}),f=f.concat({name:"idDelta_"+n,type:"SHORT",value:g.delta}),d=d.concat({name:"idRangeOffset_"+n,type:"USHORT",value:g.offset}),g.glyphId!==void 0&&(p=p.concat({name:"glyph_"+n,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(m=m.concat({name:"cmap12Start_"+n,type:"ULONG",value:g.start}),m=m.concat({name:"cmap12End_"+n,type:"ULONG",value:g.end}),m=m.concat({name:"cmap12Glyph_"+n,type:"ULONG",value:g.glyphIndex}))}if(a.segCountX2=(i-l)*2,a.searchRange=Math.pow(2,Math.floor(Math.log(i-l)/Math.log(2)))*2,a.entrySelector=Math.log(a.searchRange/2)/Math.log(2),a.rangeShift=a.segCountX2-a.searchRange,a.fields=a.fields.concat(h),a.fields.push({name:"reservedPad",type:"USHORT",value:0}),a.fields=a.fields.concat(u),a.fields=a.fields.concat(f),a.fields=a.fields.concat(d),a.fields=a.fields.concat(p),a.cmap4Length=14+h.length*2+2+u.length*2+f.length*2+d.length*2+p.length*2,!e){var v=16+m.length*4;a.cmap12Offset=20+a.cmap4Length,a.fields=a.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:m.length/3}]),a.fields=a.fields.concat(m)}return a}var O7={parse:Ac,make:Pc},Fe=[".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"],Ec=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],Tc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],k3=[".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 $7(t){this.font=t}$7.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.font.glyphs;if(n){for(var r=0;r<n.length;r+=1)for(var c=n.get(r),a=0;a<c.unicodes.length;a+=1)if(c.unicodes[a]===e)return r}return null};function R7(t){this.cmap=t}R7.prototype.charToGlyphIndex=function(t){return this.cmap.glyphIndexMap[t.codePointAt(0)]||0};function je(t,e){this.encoding=t,this.charset=e}je.prototype.charToGlyphIndex=function(t){var e=t.codePointAt(0),n=this.encoding[e];return this.charset.indexOf(n)};function St(t){switch(t.version){case 1:this.names=k3.slice();break;case 2:this.names=new Array(t.numberOfGlyphs);for(var e=0;e<t.numberOfGlyphs;e++)t.glyphNameIndex[e]<k3.length?this.names[e]=k3[t.glyphNameIndex[e]]:this.names[e]=t.names[t.glyphNameIndex[e]-k3.length];break;case 2.5:this.names=new Array(t.numberOfGlyphs);for(var n=0;n<t.numberOfGlyphs;n++)this.names[n]=k3[n+t.glyphNameIndex[n]];break;case 3:this.names=[];break;default:this.names=[];break}}St.prototype.nameToGlyphIndex=function(t){return this.names.indexOf(t)};St.prototype.glyphIndexToName=function(t){return this.names[t]};function Ic(t){for(var e,n=t.tables.cmap.glyphIndexMap,r=Object.keys(n),c=0;c<r.length;c+=1){var a=r[c],s=n[a];e=t.glyphs.get(s),e.addUnicode(parseInt(a))}for(var o=0;o<t.glyphs.length;o+=1)e=t.glyphs.get(o),t.cffEncoding?t.isCIDFont?e.name="gid"+o:e.name=t.cffEncoding.charset[o]:t.glyphNames.names&&(e.name=t.glyphNames.glyphIndexToName(o))}function Vc(t){t._IndexToUnicodeMap={};for(var e=t.tables.cmap.glyphIndexMap,n=Object.keys(e),r=0;r<n.length;r+=1){var c=n[r],a=e[c];t._IndexToUnicodeMap[a]===void 0?t._IndexToUnicodeMap[a]={unicodes:[parseInt(c)]}:t._IndexToUnicodeMap[a].unicodes.push(parseInt(c))}}function Hc(t,e){e.lowMemory?Vc(t):Ic(t)}function Oc(t,e,n,r,c){t.beginPath(),t.moveTo(e,n),t.lineTo(r,c),t.stroke()}var w3={line:Oc};function $c(t,e){var n=e||new P0;return{configurable:!0,get:function(){return typeof n=="function"&&(n=n()),n},set:function(r){n=r}}}function f2(t){this.bindConstructorValues(t)}f2.prototype.bindConstructorValues=function(t){this.index=t.index||0,this.name=t.name||null,this.unicode=t.unicode||void 0,this.unicodes=t.unicodes||t.unicode!==void 0?[t.unicode]:[],"xMin"in t&&(this.xMin=t.xMin),"yMin"in t&&(this.yMin=t.yMin),"xMax"in t&&(this.xMax=t.xMax),"yMax"in t&&(this.yMax=t.yMax),"advanceWidth"in t&&(this.advanceWidth=t.advanceWidth),Object.defineProperty(this,"path",$c(this,t.path))};f2.prototype.addUnicode=function(t){this.unicodes.length===0&&(this.unicode=t),this.unicodes.push(t)};f2.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};f2.prototype.getPath=function(t,e,n,r,c){t=t!==void 0?t:0,e=e!==void 0?e:0,n=n!==void 0?n:72;var a,s;r||(r={});var o=r.xScale,i=r.yScale;if(r.hinting&&c&&c.hinting&&(s=this.path&&c.hinting.exec(this,n)),s)a=c.hinting.getCommands(s),t=Math.round(t),e=Math.round(e),o=i=1;else{a=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*n;o===void 0&&(o=l),i===void 0&&(i=l)}for(var h=new P0,u=0;u<a.length;u+=1){var f=a[u];f.type==="M"?h.moveTo(t+f.x*o,e+-f.y*i):f.type==="L"?h.lineTo(t+f.x*o,e+-f.y*i):f.type==="Q"?h.quadraticCurveTo(t+f.x1*o,e+-f.y1*i,t+f.x*o,e+-f.y*i):f.type==="C"?h.curveTo(t+f.x1*o,e+-f.y1*i,t+f.x2*o,e+-f.y2*i,t+f.x*o,e+-f.y*i):f.type==="Z"&&h.closePath()}return h};f2.prototype.getContours=function(){if(this.points===void 0)return[];for(var t=[],e=[],n=0;n<this.points.length;n+=1){var r=this.points[n];e.push(r),r.lastPointOfContour&&(t.push(e),e=[])}return T1.argument(e.length===0,"There are still points left in the current contour."),t};f2.prototype.getMetrics=function(){for(var t=this.path.commands,e=[],n=[],r=0;r<t.length;r+=1){var c=t[r];c.type!=="Z"&&(e.push(c.x),n.push(c.y)),(c.type==="Q"||c.type==="C")&&(e.push(c.x1),n.push(c.y1)),c.type==="C"&&(e.push(c.x2),n.push(c.y2))}var a={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,n),leftSideBearing:this.leftSideBearing};return isFinite(a.xMin)||(a.xMin=0),isFinite(a.xMax)||(a.xMax=this.advanceWidth),isFinite(a.yMin)||(a.yMin=0),isFinite(a.yMax)||(a.yMax=0),a.rightSideBearing=this.advanceWidth-a.leftSideBearing-(a.xMax-a.xMin),a};f2.prototype.draw=function(t,e,n,r,c){this.getPath(e,n,r,c).draw(t)};f2.prototype.drawPoints=function(t,e,n,r){function c(u,f,d,p){t.beginPath();for(var m=0;m<u.length;m+=1)t.moveTo(f+u[m].x*p,d+u[m].y*p),t.arc(f+u[m].x*p,d+u[m].y*p,2,0,Math.PI*2,!1);t.closePath(),t.fill()}e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24;for(var a=1/this.path.unitsPerEm*r,s=[],o=[],i=this.path,l=0;l<i.commands.length;l+=1){var h=i.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&o.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&o.push({x:h.x2,y:-h.y2})}t.fillStyle="blue",c(s,e,n,a),t.fillStyle="red",c(o,e,n,a)};f2.prototype.drawMetrics=function(t,e,n,r){var c;e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:24,c=1/this.path.unitsPerEm*r,t.lineWidth=1,t.strokeStyle="black",w3.line(t,e,-1e4,e,1e4),w3.line(t,-1e4,n,1e4,n);var a=this.xMin||0,s=this.yMin||0,o=this.xMax||0,i=this.yMax||0,l=this.advanceWidth||0;t.strokeStyle="blue",w3.line(t,e+a*c,-1e4,e+a*c,1e4),w3.line(t,e+o*c,-1e4,e+o*c,1e4),w3.line(t,-1e4,n+-s*c,1e4,n+-s*c),w3.line(t,-1e4,n+-i*c,1e4,n+-i*c),t.strokeStyle="green",w3.line(t,e+l*c,-1e4,e+l*c,1e4)};function $e(t,e,n){Object.defineProperty(t,e,{get:function(){return t.path,t[n]},set:function(r){t[n]=r},enumerable:!0,configurable:!0})}function At(t,e){if(this.font=t,this.glyphs={},Array.isArray(e))for(var n=0;n<e.length;n++){var r=e[n];r.path.unitsPerEm=t.unitsPerEm,this.glyphs[n]=r}this.length=e&&e.length||0}At.prototype.get=function(t){if(this.glyphs[t]===void 0){this.font._push(t),typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());var e=this.glyphs[t],n=this.font._IndexToUnicodeMap[t];if(n)for(var r=0;r<n.unicodes.length;r++)e.addUnicode(n.unicodes[r]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+t:e.name=this.font.cffEncoding.charset[t]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(t)),this.glyphs[t].advanceWidth=this.font._hmtxTableData[t].advanceWidth,this.glyphs[t].leftSideBearing=this.font._hmtxTableData[t].leftSideBearing}else typeof this.glyphs[t]=="function"&&(this.glyphs[t]=this.glyphs[t]());return this.glyphs[t]};At.prototype.push=function(t,e){this.glyphs[t]=e,this.length++};function Rc(t,e){return new f2({index:e,font:t})}function Fc(t,e,n,r,c,a){return function(){var s=new f2({index:e,font:t});return s.path=function(){n(s,r,c);var o=a(t.glyphs,s);return o.unitsPerEm=t.unitsPerEm,o},$e(s,"xMin","_xMin"),$e(s,"xMax","_xMax"),$e(s,"yMin","_yMin"),$e(s,"yMax","_yMax"),s}}function Dc(t,e,n,r){return function(){var c=new f2({index:e,font:t});return c.path=function(){var a=n(t,c,r);return a.unitsPerEm=t.unitsPerEm,a},c}}var I2={GlyphSet:At,glyphLoader:Rc,ttfGlyphLoader:Fc,cffGlyphLoader:Dc};function F7(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(!F7(t[n],e[n]))return!1;return!0}else return!1}function gt(t){var e;return t.length<1240?e=107:t.length<33900?e=1131:e=32768,e}function n3(t,e,n){var r=[],c=[],a=d1.getCard16(t,e),s,o;if(a!==0){var i=d1.getByte(t,e+2);s=e+(a+1)*i+2;for(var l=e+3,h=0;h<a+1;h+=1)r.push(d1.getOffset(t,l,i)),l+=i;o=s+r[a]}else o=e+2;for(var u=0;u<r.length-1;u+=1){var f=d1.getBytes(t,s+r[u],s+r[u+1]);n&&(f=n(f)),c.push(f)}return{objects:c,startOffset:e,endOffset:o}}function qc(t,e){var n=[],r=d1.getCard16(t,e),c,a;if(r!==0){var s=d1.getByte(t,e+2);c=e+(r+1)*s+2;for(var o=e+3,i=0;i<r+1;i+=1)n.push(d1.getOffset(t,o,s)),o+=s;a=c+n[r]}else a=e+2;return{offsets:n,startOffset:e,endOffset:a}}function Nc(t,e,n,r,c){var a=d1.getCard16(n,r),s=0;if(a!==0){var o=d1.getByte(n,r+2);s=r+(a+1)*o+2}var i=d1.getBytes(n,s+e[t],s+e[t+1]);return c&&(i=c(i)),i}function Uc(t){for(var e="",n=15,r=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var c=t.parseByte(),a=c>>4,s=c&15;if(a===n||(e+=r[a],s===n))break;e+=r[s]}return parseFloat(e)}function Bc(t,e){var n,r,c,a;if(e===28)return n=t.parseByte(),r=t.parseByte(),n<<8|r;if(e===29)return n=t.parseByte(),r=t.parseByte(),c=t.parseByte(),a=t.parseByte(),n<<24|r<<16|c<<8|a;if(e===30)return Uc(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 _c(t){for(var e={},n=0;n<t.length;n+=1){var r=t[n][0],c=t[n][1],a=void 0;if(c.length===1?a=c[0]:a=c,e.hasOwnProperty(r)&&!isNaN(e[r]))throw new Error("Object "+e+" already has key "+r);e[r]=a}return e}function D7(t,e,n){e=e!==void 0?e:0;var r=new d1.Parser(t,e),c=[],a=[];for(n=n!==void 0?n:t.length;r.relativeOffset<n;){var s=r.parseByte();s<=21?(s===12&&(s=1200+r.parseByte()),c.push([s,a]),a=[]):a.push(Bc(r,s))}return _c(c)}function D5(t,e){return e<=390?e=Fe[e]:e=t[e-391],e}function q7(t,e,n){for(var r={},c,a=0;a<e.length;a+=1){var s=e[a];if(Array.isArray(s.type)){var o=[];o.length=s.type.length;for(var i=0;i<s.type.length;i++)c=t[s.op]!==void 0?t[s.op][i]:void 0,c===void 0&&(c=s.value!==void 0&&s.value[i]!==void 0?s.value[i]:null),s.type[i]==="SID"&&(c=D5(n,c)),o[i]=c;r[s.name]=o}else c=t[s.op],c===void 0&&(c=s.value!==void 0?s.value:null),s.type==="SID"&&(c=D5(n,c)),r[s.name]=c}return r}function jc(t,e){var n={};return n.formatMajor=d1.getCard8(t,e),n.formatMinor=d1.getCard8(t,e+1),n.size=d1.getCard8(t,e+2),n.offsetSize=d1.getCard8(t,e+3),n.startOffset=e,n.endOffset=e+4,n}var N7=[{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"}],U7=[{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 Gc(t,e){var n=D7(t,0,t.byteLength);return q7(n,N7,e)}function B7(t,e,n,r){var c=D7(t,e,n);return q7(c,U7,r)}function Yn(t,e,n,r){for(var c=[],a=0;a<n.length;a+=1){var s=new DataView(new Uint8Array(n[a]).buffer),o=Gc(s,r);o._subrs=[],o._subrsBias=0,o._defaultWidthX=0,o._nominalWidthX=0;var i=o.private[0],l=o.private[1];if(i!==0&&l!==0){var h=B7(t,l+e,i,r);if(o._defaultWidthX=h.defaultWidthX,o._nominalWidthX=h.nominalWidthX,h.subrs!==0){var u=l+h.subrs,f=n3(t,u+e);o._subrs=f.objects,o._subrsBias=gt(o._subrs)}o._privateDict=h}c.push(o)}return c}function Wc(t,e,n,r){var c,a,s=new d1.Parser(t,e);n-=1;var o=[".notdef"],i=s.parseCard8();if(i===0)for(var l=0;l<n;l+=1)c=s.parseSID(),o.push(D5(r,c));else if(i===1)for(;o.length<=n;){c=s.parseSID(),a=s.parseCard8();for(var h=0;h<=a;h+=1)o.push(D5(r,c)),c+=1}else if(i===2)for(;o.length<=n;){c=s.parseSID(),a=s.parseCard16();for(var u=0;u<=a;u+=1)o.push(D5(r,c)),c+=1}else throw new Error("Unknown charset format "+i);return o}function Xc(t,e,n){var r,c={},a=new d1.Parser(t,e),s=a.parseCard8();if(s===0)for(var o=a.parseCard8(),i=0;i<o;i+=1)r=a.parseCard8(),c[r]=i;else if(s===1){var l=a.parseCard8();r=1;for(var h=0;h<l;h+=1)for(var u=a.parseCard8(),f=a.parseCard8(),d=u;d<=u+f;d+=1)c[d]=r,r+=1}else throw new Error("Unknown encoding format "+s);return new je(c,n)}function Jn(t,e,n){var r,c,a,s,o=new P0,i=[],l=0,h=!1,u=!1,f=0,d=0,p,m,g,v;if(t.isCIDFont){var b=t.tables.cff.topDict._fdSelect[e.index],y=t.tables.cff.topDict._fdArray[b];p=y._subrs,m=y._subrsBias,g=y._defaultWidthX,v=y._nominalWidthX}else p=t.tables.cff.topDict._subrs,m=t.tables.cff.topDict._subrsBias,g=t.tables.cff.topDict._defaultWidthX,v=t.tables.cff.topDict._nominalWidthX;var x=g;function w(z,A){u&&o.closePath(),o.moveTo(z,A),u=!0}function M(){var z;z=i.length%2!==0,z&&!h&&(x=i.shift()+v),l+=i.length>>1,i.length=0,h=!0}function k(z){for(var A,S,C,I,L,T,q,P,F,j,_,Q,H=0;H<z.length;){var B=z[H];switch(H+=1,B){case 1:M();break;case 3:M();break;case 4:i.length>1&&!h&&(x=i.shift()+v,h=!0),d+=i.pop(),w(f,d);break;case 5:for(;i.length>0;)f+=i.shift(),d+=i.shift(),o.lineTo(f,d);break;case 6:for(;i.length>0&&(f+=i.shift(),o.lineTo(f,d),i.length!==0);)d+=i.shift(),o.lineTo(f,d);break;case 7:for(;i.length>0&&(d+=i.shift(),o.lineTo(f,d),i.length!==0);)f+=i.shift(),o.lineTo(f,d);break;case 8:for(;i.length>0;)r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+i.shift(),o.curveTo(r,c,a,s,f,d);break;case 10:L=i.pop()+m,T=p[L],T&&k(T);break;case 11:return;case 12:switch(B=z[H],H+=1,B){case 35:r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s+i.shift(),F=q+i.shift(),j=P+i.shift(),_=F+i.shift(),Q=j+i.shift(),f=_+i.shift(),d=Q+i.shift(),i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;case 34:r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s,F=q+i.shift(),j=s,_=F+i.shift(),Q=d,f=_+i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;case 36:r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s,F=q+i.shift(),j=s,_=F+i.shift(),Q=j+i.shift(),f=_+i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;case 37:r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),q=a+i.shift(),P=s+i.shift(),F=q+i.shift(),j=P+i.shift(),_=F+i.shift(),Q=j+i.shift(),Math.abs(_-f)>Math.abs(Q-d)?f=_+i.shift():d=Q+i.shift(),o.curveTo(r,c,a,s,q,P),o.curveTo(F,j,_,Q,f,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+B),i.length=0}break;case 14:i.length>0&&!h&&(x=i.shift()+v,h=!0),u&&(o.closePath(),u=!1);break;case 18:M();break;case 19:case 20:M(),H+=l+7>>3;break;case 21:i.length>2&&!h&&(x=i.shift()+v,h=!0),d+=i.pop(),f+=i.pop(),w(f,d);break;case 22:i.length>1&&!h&&(x=i.shift()+v,h=!0),f+=i.pop(),w(f,d);break;case 23:M();break;case 24:for(;i.length>2;)r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+i.shift(),o.curveTo(r,c,a,s,f,d);f+=i.shift(),d+=i.shift(),o.lineTo(f,d);break;case 25:for(;i.length>6;)f+=i.shift(),d+=i.shift(),o.lineTo(f,d);r=f+i.shift(),c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+i.shift(),o.curveTo(r,c,a,s,f,d);break;case 26:for(i.length%2&&(f+=i.shift());i.length>0;)r=f,c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a,d=s+i.shift(),o.curveTo(r,c,a,s,f,d);break;case 27:for(i.length%2&&(d+=i.shift());i.length>0;)r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s,o.curveTo(r,c,a,s,f,d);break;case 28:A=z[H],S=z[H+1],i.push((A<<24|S<<16)>>16),H+=2;break;case 29:L=i.pop()+t.gsubrsBias,T=t.gsubrs[L],T&&k(T);break;case 30:for(;i.length>0&&(r=f,c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d),i.length!==0);)r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),d=s+i.shift(),f=a+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d);break;case 31:for(;i.length>0&&(r=f+i.shift(),c=d,a=r+i.shift(),s=c+i.shift(),d=s+i.shift(),f=a+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d),i.length!==0);)r=f,c=d+i.shift(),a=r+i.shift(),s=c+i.shift(),f=a+i.shift(),d=s+(i.length===1?i.shift():0),o.curveTo(r,c,a,s,f,d);break;default:B<32?console.log("Glyph "+e.index+": unknown operator "+B):B<247?i.push(B-139):B<251?(A=z[H],H+=1,i.push((B-247)*256+A+108)):B<255?(A=z[H],H+=1,i.push(-(B-251)*256-A-108)):(A=z[H],S=z[H+1],C=z[H+2],I=z[H+3],H+=4,i.push((A<<24|S<<16|C<<8|I)/65536))}}}return k(n),e.advanceWidth=x,o}function Zc(t,e,n,r){var c=[],a,s=new d1.Parser(t,e),o=s.parseCard8();if(o===0)for(var i=0;i<n;i++){if(a=s.parseCard8(),a>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+r+")");c.push(a)}else if(o===3){var l=s.parseCard16(),h=s.parseCard16();if(h!==0)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+h);for(var u,f=0;f<l;f++){if(a=s.parseCard8(),u=s.parseCard16(),a>=r)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+r+")");if(u>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+u);for(;h<u;h++)c.push(a);h=u}if(u!==n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+u)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+o);return c}function Yc(t,e,n,r){n.tables.cff={};var c=jc(t,e),a=n3(t,c.endOffset,d1.bytesToString),s=n3(t,a.endOffset),o=n3(t,s.endOffset,d1.bytesToString),i=n3(t,o.endOffset);n.gsubrs=i.objects,n.gsubrsBias=gt(n.gsubrs);var l=Yn(t,e,s.objects,o.objects);if(l.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+l.length);var h=l[0];if(n.tables.cff.topDict=h,h._privateDict&&(n.defaultWidthX=h._privateDict.defaultWidthX,n.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(n.isCIDFont=!0),n.isCIDFont){var u=h.fdArray,f=h.fdSelect;if(u===0||f===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");u+=e;var d=n3(t,u),p=Yn(t,e,d.objects,o.objects);h._fdArray=p,f+=e,h._fdSelect=Zc(t,f,n.numGlyphs,p.length)}var m=e+h.private[1],g=B7(t,m,h.private[0],o.objects);if(n.defaultWidthX=g.defaultWidthX,n.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=m+g.subrs,b=n3(t,v);n.subrs=b.objects,n.subrsBias=gt(n.subrs)}else n.subrs=[],n.subrsBias=0;var y;r.lowMemory?(y=qc(t,e+h.charStrings),n.nGlyphs=y.offsets.length):(y=n3(t,e+h.charStrings),n.nGlyphs=y.objects.length);var x=Wc(t,e+h.charset,n.nGlyphs,o.objects);if(h.encoding===0?n.cffEncoding=new je(Ec,x):h.encoding===1?n.cffEncoding=new je(Tc,x):n.cffEncoding=Xc(t,e+h.encoding,x),n.encoding=n.encoding||n.cffEncoding,n.glyphs=new I2.GlyphSet(n),r.lowMemory)n._push=function(k){var z=Nc(k,y.offsets,t,e+h.charStrings);n.glyphs.push(k,I2.cffGlyphLoader(n,k,Jn,z))};else for(var w=0;w<n.nGlyphs;w+=1){var M=y.objects[w];n.glyphs.push(w,I2.cffGlyphLoader(n,w,Jn,M))}}function _7(t,e){var n,r=Fe.indexOf(t);return r>=0&&(n=r),r=e.indexOf(t),r>=0?n=r+Fe.length:(n=Fe.length+e.length,e.push(t)),n}function Jc(){return new o1.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function Kc(t){var e=new o1.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var n=0;n<t.length;n+=1)e.names.push({name:"name_"+n,type:"NAME",value:t[n]});return e}function j7(t,e,n){for(var r={},c=0;c<t.length;c+=1){var a=t[c],s=e[a.name];s!==void 0&&!F7(s,a.value)&&(a.type==="SID"&&(s=_7(s,n)),r[a.op]={name:a.name,type:a.type,value:s})}return r}function Kn(t,e){var n=new o1.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=j7(N7,t,e),n}function Qn(t){var e=new o1.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:t}],e}function Qc(t){var e=new o1.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var n=0;n<t.length;n+=1)e.strings.push({name:"string_"+n,type:"STRING",value:t[n]});return e}function ea(){return new o1.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function ta(t,e){for(var n=new o1.Record("Charsets",[{name:"format",type:"Card8",value:0}]),r=0;r<t.length;r+=1){var c=t[r],a=_7(c,e);n.fields.push({name:"glyph_"+r,type:"SID",value:a})}return n}function na(t){var e=[],n=t.path;e.push({name:"width",type:"NUMBER",value:t.advanceWidth});for(var r=0,c=0,a=0;a<n.commands.length;a+=1){var s=void 0,o=void 0,i=n.commands[a];if(i.type==="Q"){var l=.3333333333333333,h=2/3;i={type:"C",x:i.x,y:i.y,x1:Math.round(l*r+h*i.x1),y1:Math.round(l*c+h*i.y1),x2:Math.round(l*i.x+h*i.x1),y2:Math.round(l*i.y+h*i.y1)}}if(i.type==="M")s=Math.round(i.x-r),o=Math.round(i.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rmoveto",type:"OP",value:21}),r=Math.round(i.x),c=Math.round(i.y);else if(i.type==="L")s=Math.round(i.x-r),o=Math.round(i.y-c),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rlineto",type:"OP",value:5}),r=Math.round(i.x),c=Math.round(i.y);else if(i.type==="C"){var u=Math.round(i.x1-r),f=Math.round(i.y1-c),d=Math.round(i.x2-i.x1),p=Math.round(i.y2-i.y1);s=Math.round(i.x-i.x2),o=Math.round(i.y-i.y2),e.push({name:"dx1",type:"NUMBER",value:u}),e.push({name:"dy1",type:"NUMBER",value:f}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:p}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:o}),e.push({name:"rrcurveto",type:"OP",value:8}),r=Math.round(i.x),c=Math.round(i.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function ra(t){for(var e=new o1.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),n=0;n<t.length;n+=1){var r=t.get(n),c=na(r);e.charStrings.push({name:r.name,type:"CHARSTRING",value:c})}return e}function ca(t,e){var n=new o1.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return n.dict=j7(U7,t,e),n}function aa(t,e){for(var n=new o1.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),r=1/e.unitsPerEm,c={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[r,0,0,r,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},a={},s=[],o,i=1;i<t.length;i+=1)o=t.get(i),s.push(o.name);var l=[];n.header=Jc(),n.nameIndex=Kc([e.postScriptName]);var h=Kn(c,l);n.topDictIndex=Qn(h),n.globalSubrIndex=ea(),n.charsets=ta(s,l),n.charStringsIndex=ra(t),n.privateDict=ca(a,l),n.stringIndex=Qc(l);var u=n.header.sizeOf()+n.nameIndex.sizeOf()+n.topDictIndex.sizeOf()+n.stringIndex.sizeOf()+n.globalSubrIndex.sizeOf();return c.charset=u,c.encoding=0,c.charStrings=c.charset+n.charsets.sizeOf(),c.private[1]=c.charStrings+n.charStringsIndex.sizeOf(),h=Kn(c,l),n.topDictIndex=Qn(h),n}var G7={parse:Yc,make:aa};function sa(t,e){var n={},r=new d1.Parser(t,e);return n.version=r.parseVersion(),n.fontRevision=Math.round(r.parseFixed()*1e3)/1e3,n.checkSumAdjustment=r.parseULong(),n.magicNumber=r.parseULong(),T1.argument(n.magicNumber===1594834165,"Font header has wrong magic number."),n.flags=r.parseUShort(),n.unitsPerEm=r.parseUShort(),n.created=r.parseLongDateTime(),n.modified=r.parseLongDateTime(),n.xMin=r.parseShort(),n.yMin=r.parseShort(),n.xMax=r.parseShort(),n.yMax=r.parseShort(),n.macStyle=r.parseUShort(),n.lowestRecPPEM=r.parseUShort(),n.fontDirectionHint=r.parseShort(),n.indexToLocFormat=r.parseShort(),n.glyphDataFormat=r.parseShort(),n}function oa(t){var e=Math.round(new Date().getTime()/1e3)+2082844800,n=e;return t.createdTimestamp&&(n=t.createdTimestamp+2082844800),new o1.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:n},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:0},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],t)}var W7={parse:sa,make:oa};function ia(t,e){var n={},r=new d1.Parser(t,e);return n.version=r.parseVersion(),n.ascender=r.parseShort(),n.descender=r.parseShort(),n.lineGap=r.parseShort(),n.advanceWidthMax=r.parseUShort(),n.minLeftSideBearing=r.parseShort(),n.minRightSideBearing=r.parseShort(),n.xMaxExtent=r.parseShort(),n.caretSlopeRise=r.parseShort(),n.caretSlopeRun=r.parseShort(),n.caretOffset=r.parseShort(),r.relativeOffset+=8,n.metricDataFormat=r.parseShort(),n.numberOfHMetrics=r.parseUShort(),n}function la(t){return new o1.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],t)}var X7={parse:ia,make:la};function ha(t,e,n,r,c){for(var a,s,o=new d1.Parser(t,e),i=0;i<r;i+=1){i<n&&(a=o.parseUShort(),s=o.parseShort());var l=c.get(i);l.advanceWidth=a,l.leftSideBearing=s}}function ua(t,e,n,r,c){t._hmtxTableData={};for(var a,s,o=new d1.Parser(e,n),i=0;i<c;i+=1)i<r&&(a=o.parseUShort(),s=o.parseShort()),t._hmtxTableData[i]={advanceWidth:a,leftSideBearing:s}}function fa(t,e,n,r,c,a,s){s.lowMemory?ua(t,e,n,r,c):ha(e,n,r,c,a)}function da(t){for(var e=new o1.Table("hmtx",[]),n=0;n<t.length;n+=1){var r=t.get(n),c=r.advanceWidth||0,a=r.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+n,type:"USHORT",value:c}),e.fields.push({name:"leftSideBearing_"+n,type:"SHORT",value:a})}return e}var Z7={parse:fa,make:da};function ma(t){for(var e=new o1.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:t.length}]),n="",r=12+t.length*4,c=0;c<t.length;++c){var a=n.indexOf(t[c]);a<0&&(a=n.length,n+=t[c]),e.fields.push({name:"offset "+c,type:"USHORT",value:r+a}),e.fields.push({name:"length "+c,type:"USHORT",value:t[c].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),e}function pa(t,e){var n=new d1.Parser(t,e),r=n.parseULong();T1.argument(r===1,"Unsupported ltag table version."),n.skip("uLong",1);for(var c=n.parseULong(),a=[],s=0;s<c;s++){for(var o="",i=e+n.parseUShort(),l=n.parseUShort(),h=i;h<i+l;++h)o+=String.fromCharCode(t.getInt8(h));a.push(o)}return a}var Y7={make:ma,parse:pa};function ga(t,e){var n={},r=new d1.Parser(t,e);return n.version=r.parseVersion(),n.numGlyphs=r.parseUShort(),n.version===1&&(n.maxPoints=r.parseUShort(),n.maxContours=r.parseUShort(),n.maxCompositePoints=r.parseUShort(),n.maxCompositeContours=r.parseUShort(),n.maxZones=r.parseUShort(),n.maxTwilightPoints=r.parseUShort(),n.maxStorage=r.parseUShort(),n.maxFunctionDefs=r.parseUShort(),n.maxInstructionDefs=r.parseUShort(),n.maxStackElements=r.parseUShort(),n.maxSizeOfInstructions=r.parseUShort(),n.maxComponentElements=r.parseUShort(),n.maxComponentDepth=r.parseUShort()),n}function va(t){return new o1.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:t}])}var J7={parse:ga,make:va},K7=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Q7={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"},ya={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},e8={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 ba(t,e,n){switch(t){case 0:if(e===65535)return"und";if(n)return n[e];break;case 1:return Q7[e];case 3:return e8[e]}}var vt="utf-16",xa={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"},Ma={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 t8(t,e,n){switch(t){case 0:return vt;case 1:return Ma[n]||xa[e];case 3:if(e===1||e===10)return vt;break}}function wa(t,e,n){for(var r={},c=new d1.Parser(t,e),a=c.parseUShort(),s=c.parseUShort(),o=c.offset+c.parseUShort(),i=0;i<s;i++){var l=c.parseUShort(),h=c.parseUShort(),u=c.parseUShort(),f=c.parseUShort(),d=K7[f]||f,p=c.parseUShort(),m=c.parseUShort(),g=ba(l,u,n),v=t8(l,h,u);if(v!==void 0&&g!==void 0){var b=void 0;if(v===vt?b=K3.UTF16(t,o+m,p):b=K3.MACSTRING(t,o+m,p,v),b){var y=r[d];y===void 0&&(y=r[d]={}),y[g]=b}}}var x=0;return a===1&&(x=c.parseUShort()),r}function ct(t){var e={};for(var n in t)e[t[n]]=parseInt(n);return e}function e7(t,e,n,r,c,a){return new o1.Record("NameRecord",[{name:"platformID",type:"USHORT",value:t},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:n},{name:"nameID",type:"USHORT",value:r},{name:"length",type:"USHORT",value:c},{name:"offset",type:"USHORT",value:a}])}function ka(t,e){var n=t.length,r=e.length-n+1;e:for(var c=0;c<r;c++)for(;c<r;c++){for(var a=0;a<n;a++)if(e[c+a]!==t[a])continue e;return c}return-1}function t7(t,e){var n=ka(t,e);if(n<0){n=e.length;for(var r=0,c=t.length;r<c;++r)e.push(t[r])}return n}function za(t,e){var n,r=[],c={},a=ct(K7);for(var s in t){var o=a[s];if(o===void 0&&(o=s),n=parseInt(o),isNaN(n))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');c[n]=t[s],r.push(n)}for(var i=ct(Q7),l=ct(e8),h=[],u=[],f=0;f<r.length;f++){n=r[f];var d=c[n];for(var p in d){var m=d[p],g=1,v=i[p],b=ya[v],y=t8(g,b,v),x=c1.MACSTRING(m,y);x===void 0&&(g=0,v=e.indexOf(p),v<0&&(v=e.length,e.push(p)),b=4,x=c1.UTF16(m));var w=t7(x,u);h.push(e7(g,b,v,n,x.length,w));var M=l[p];if(M!==void 0){var k=c1.UTF16(m),z=t7(k,u);h.push(e7(3,1,M,n,k.length,z))}}}h.sort(function(C,I){return C.platformID-I.platformID||C.encodingID-I.encodingID||C.languageID-I.languageID||C.nameID-I.nameID});for(var A=new o1.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),S=0;S<h.length;S++)A.fields.push({name:"record_"+S,type:"RECORD",value:h[S]});return A.fields.push({name:"strings",type:"LITERAL",value:u}),A}var n8={parse:wa,make:za},yt=[{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 Sa(t){for(var e=0;e<yt.length;e+=1){var n=yt[e];if(t>=n.begin&&t<n.end)return e}return-1}function Aa(t,e){var n={},r=new d1.Parser(t,e);n.version=r.parseUShort(),n.xAvgCharWidth=r.parseShort(),n.usWeightClass=r.parseUShort(),n.usWidthClass=r.parseUShort(),n.fsType=r.parseUShort(),n.ySubscriptXSize=r.parseShort(),n.ySubscriptYSize=r.parseShort(),n.ySubscriptXOffset=r.parseShort(),n.ySubscriptYOffset=r.parseShort(),n.ySuperscriptXSize=r.parseShort(),n.ySuperscriptYSize=r.parseShort(),n.ySuperscriptXOffset=r.parseShort(),n.ySuperscriptYOffset=r.parseShort(),n.yStrikeoutSize=r.parseShort(),n.yStrikeoutPosition=r.parseShort(),n.sFamilyClass=r.parseShort(),n.panose=[];for(var c=0;c<10;c++)n.panose[c]=r.parseByte();return n.ulUnicodeRange1=r.parseULong(),n.ulUnicodeRange2=r.parseULong(),n.ulUnicodeRange3=r.parseULong(),n.ulUnicodeRange4=r.parseULong(),n.achVendID=String.fromCharCode(r.parseByte(),r.parseByte(),r.parseByte(),r.parseByte()),n.fsSelection=r.parseUShort(),n.usFirstCharIndex=r.parseUShort(),n.usLastCharIndex=r.parseUShort(),n.sTypoAscender=r.parseShort(),n.sTypoDescender=r.parseShort(),n.sTypoLineGap=r.parseShort(),n.usWinAscent=r.parseUShort(),n.usWinDescent=r.parseUShort(),n.version>=1&&(n.ulCodePageRange1=r.parseULong(),n.ulCodePageRange2=r.parseULong()),n.version>=2&&(n.sxHeight=r.parseShort(),n.sCapHeight=r.parseShort(),n.usDefaultChar=r.parseUShort(),n.usBreakChar=r.parseUShort(),n.usMaxContent=r.parseUShort()),n}function La(t){return new o1.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],t)}var bt={parse:Aa,make:La,unicodeRanges:yt,getUnicodeRange:Sa};function Ca(t,e){var n={},r=new d1.Parser(t,e);switch(n.version=r.parseVersion(),n.italicAngle=r.parseFixed(),n.underlinePosition=r.parseShort(),n.underlineThickness=r.parseShort(),n.isFixedPitch=r.parseULong(),n.minMemType42=r.parseULong(),n.maxMemType42=r.parseULong(),n.minMemType1=r.parseULong(),n.maxMemType1=r.parseULong(),n.version){case 1:n.names=k3.slice();break;case 2:n.numberOfGlyphs=r.parseUShort(),n.glyphNameIndex=new Array(n.numberOfGlyphs);for(var c=0;c<n.numberOfGlyphs;c++)n.glyphNameIndex[c]=r.parseUShort();n.names=[];for(var a=0;a<n.numberOfGlyphs;a++)if(n.glyphNameIndex[a]>=k3.length){var s=r.parseChar();n.names.push(r.parseString(s))}break;case 2.5:n.numberOfGlyphs=r.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(var o=0;o<n.numberOfGlyphs;o++)n.offset[o]=r.parseChar();break}return n}function Pa(){return new o1.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:0},{name:"underlinePosition",type:"FWORD",value:0},{name:"underlineThickness",type:"FWORD",value:0},{name:"isFixedPitch",type:"ULONG",value:0},{name:"minMemType42",type:"ULONG",value:0},{name:"maxMemType42",type:"ULONG",value:0},{name:"minMemType1",type:"ULONG",value:0},{name:"maxMemType1",type:"ULONG",value:0}])}var r8={parse:Ca,make:Pa},g2=new Array(9);g2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(N.coverage),deltaGlyphId:this.parseUShort()};if(n===2)return{substFormat:2,coverage:this.parsePointer(N.coverage),substitute:this.parseOffset16List()};T1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};g2[2]=function(){var e=this.parseUShort();return T1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),sequences:this.parseListOfLists()}};g2[3]=function(){var e=this.parseUShort();return T1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),alternateSets:this.parseListOfLists()}};g2[4]=function(){var e=this.parseUShort();return T1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var J3={sequenceIndex:N.uShort,lookupListIndex:N.uShort};g2[5]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:n,coverage:this.parsePointer(N.coverage),ruleSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,J3)}})};if(n===2)return{substFormat:n,coverage:this.parsePointer(N.coverage),classDef:this.parsePointer(N.classDef),classSets:this.parseListOfLists(function(){var a=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(a-1),lookupRecords:this.parseRecordList(s,J3)}})};if(n===3){var r=this.parseUShort(),c=this.parseUShort();return{substFormat:n,coverages:this.parseList(r,N.pointer(N.coverage)),lookupRecords:this.parseRecordList(c,J3)}}T1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};g2[6]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{substFormat:1,coverage:this.parsePointer(N.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(J3)}})};if(n===2)return{substFormat:2,coverage:this.parsePointer(N.coverage),backtrackClassDef:this.parsePointer(N.classDef),inputClassDef:this.parsePointer(N.classDef),lookaheadClassDef:this.parsePointer(N.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(J3)}})};if(n===3)return{substFormat:3,backtrackCoverage:this.parseList(N.pointer(N.coverage)),inputCoverage:this.parseList(N.pointer(N.coverage)),lookaheadCoverage:this.parseList(N.pointer(N.coverage)),lookupRecords:this.parseRecordList(J3)};T1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};g2[7]=function(){var e=this.parseUShort();T1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var n=this.parseUShort(),r=new N(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:n,extension:g2[n].call(r)}};g2[8]=function(){var e=this.parseUShort();return T1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(N.coverage),backtrackCoverage:this.parseList(N.pointer(N.coverage)),lookaheadCoverage:this.parseList(N.pointer(N.coverage)),substitutes:this.parseUShortList()}};function Ea(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return T1.argument(r===1||r===1.1,"Unsupported GSUB table version."),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(g2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(g2),variations:n.parseFeatureVariationsList()}}var Q3=new Array(9);Q3[1]=function(e){return e.substFormat===1?new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.ushortList("substitute",e.substitute)))};Q3[2]=function(e){return T1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("seqSet",e.sequences,function(n){return new o1.Table("sequenceSetTable",o1.ushortList("sequence",n))})))};Q3[3]=function(e){return T1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("altSet",e.alternateSets,function(n){return new o1.Table("alternateSetTable",o1.ushortList("alternate",n))})))};Q3[4]=function(e){return T1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new o1.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("ligSet",e.ligatureSets,function(n){return new o1.Table("ligatureSetTable",o1.tableList("ligature",n,function(r){return new o1.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:r.ligGlyph}].concat(o1.ushortList("component",r.components,r.components.length+1)))}))})))};Q3[6]=function(e){if(e.substFormat===1){var n=new o1.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new o1.Coverage(e.coverage)}].concat(o1.tableList("chainRuleSet",e.chainRuleSets,function(a){return new o1.Table("chainRuleSetTable",o1.tableList("chainRule",a,function(s){var o=o1.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(o1.ushortList("inputGlyph",s.input,s.input.length+1)).concat(o1.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(o1.ushortList("substitution",[],s.lookupRecords.length));return s.lookupRecords.forEach(function(i,l){o=o.concat({name:"sequenceIndex"+l,type:"USHORT",value:i.sequenceIndex}).concat({name:"lookupListIndex"+l,type:"USHORT",value:i.lookupListIndex})}),new o1.Table("chainRuleTable",o)}))})));return n}else if(e.substFormat===2)T1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var r=[{name:"substFormat",type:"USHORT",value:e.substFormat}];r.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(a,s){r.push({name:"backtrackCoverage"+s,type:"TABLE",value:new o1.Coverage(a)})}),r.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(a,s){r.push({name:"inputCoverage"+s,type:"TABLE",value:new o1.Coverage(a)})}),r.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(a,s){r.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new o1.Coverage(a)})}),r.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(a,s){r=r.concat({name:"sequenceIndex"+s,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:a.lookupListIndex})});var c=new o1.Table("chainContextTable",r);return c}T1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Ta(t){return new o1.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new o1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new o1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new o1.LookupList(t.lookups,Q3)}])}var c8={parse:Ea,make:Ta};function Ia(t,e){var n=new d1.Parser(t,e),r=n.parseULong();T1.argument(r===1,"Unsupported META table version."),n.parseULong(),n.parseULong();for(var c=n.parseULong(),a={},s=0;s<c;s++){var o=n.parseTag(),i=n.parseULong(),l=n.parseULong(),h=K3.UTF8(t,e+i,l);a[o]=h}return a}function Va(t){var e=Object.keys(t).length,n="",r=16+e*12,c=new o1.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:r},{name:"numTags",type:"ULONG",value:e}]);for(var a in t){var s=n.length;n+=t[a],c.fields.push({name:"tag "+a,type:"TAG",value:a}),c.fields.push({name:"offset "+a,type:"ULONG",value:r+s}),c.fields.push({name:"length "+a,type:"ULONG",value:t[a].length})}return c.fields.push({name:"stringPool",type:"CHARARRAY",value:n}),c}var a8={parse:Ia,make:Va};function n7(t){return Math.log(t)/Math.log(2)|0}function Lt(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 r7(t,e,n,r){return new o1.Record("Table Record",[{name:"tag",type:"TAG",value:t!==void 0?t:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:n!==void 0?n:0},{name:"length",type:"ULONG",value:r!==void 0?r:0}])}function s8(t){var e=new o1.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=t,e.numTables=t.length;var n=Math.pow(2,n7(e.numTables));e.searchRange=16*n,e.entrySelector=n7(n),e.rangeShift=e.numTables*16-e.searchRange;for(var r=[],c=[],a=e.sizeOf()+r7().sizeOf()*e.numTables;a%4!==0;)a+=1,c.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<t.length;s+=1){var o=t[s];T1.argument(o.tableName.length===4,"Table name"+o.tableName+" is invalid.");var i=o.sizeOf(),l=r7(o.tableName,Lt(o.encode()),a,i);for(r.push({name:l.tag+" Table Record",type:"RECORD",value:l}),c.push({name:o.tableName+" table",type:"RECORD",value:o}),a+=i,T1.argument(!isNaN(a),"Something went wrong calculating the offset.");a%4!==0;)a+=1,c.push({name:"padding",type:"BYTE",value:0})}return r.sort(function(h,u){return h.value.tag>u.value.tag?1:-1}),e.fields=e.fields.concat(r),e.fields=e.fields.concat(c),e}function c7(t,e,n){for(var r=0;r<e.length;r+=1){var c=t.charToGlyphIndex(e[r]);if(c>0){var a=t.glyphs.get(c);return a.getMetrics()}}return n}function Ha(t){for(var e=0,n=0;n<t.length;n+=1)e+=t[n];return e/t.length}function Oa(t){for(var e=[],n=[],r=[],c=[],a=[],s=[],o=[],i,l=0,h=0,u=0,f=0,d=0,p=0;p<t.glyphs.length;p+=1){var m=t.glyphs.get(p),g=m.unicode|0;if(isNaN(m.advanceWidth))throw new Error("Glyph "+m.name+" ("+p+"): advanceWidth is not a number.");(i>g||i===void 0)&&g>0&&(i=g),l<g&&(l=g);var v=bt.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)u|=1<<v-32;else if(v<96)f|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(m.name!==".notdef"){var b=m.getMetrics();e.push(b.xMin),n.push(b.yMin),r.push(b.xMax),c.push(b.yMax),s.push(b.leftSideBearing),o.push(b.rightSideBearing),a.push(m.advanceWidth)}}var y={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,n),xMax:Math.max.apply(null,r),yMax:Math.max.apply(null,c),advanceWidthMax:Math.max.apply(null,a),advanceWidthAvg:Ha(a),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,o)};y.ascender=t.ascender,y.descender=t.descender;var x=W7.make({flags:3,unitsPerEm:t.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:t.createdTimestamp}),w=X7.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:t.glyphs.length}),M=J7.make(t.glyphs.length),k=bt.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:i,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:u,ulUnicodeRange3:f,ulUnicodeRange4:d,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:c7(t,"xyvw",{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:c7(t,"HIKLEFJMNTZBDPRAGOQSUVWXY",y).yMax,usDefaultChar:t.hasChar(" ")?32:0,usBreakChar:t.hasChar(" ")?32:0},t.tables.os2)),z=Z7.make(t.glyphs),A=O7.make(t.glyphs),S=t.getEnglishName("fontFamily"),C=t.getEnglishName("fontSubfamily"),I=S+" "+C,L=t.getEnglishName("postScriptName");L||(L=S.replace(/\s/g,"")+"-"+C);var T={};for(var q in t.names)T[q]=t.names[q];T.uniqueID||(T.uniqueID={en:t.getEnglishName("manufacturer")+":"+I}),T.postScriptName||(T.postScriptName={en:L}),T.preferredFamily||(T.preferredFamily=t.names.fontFamily),T.preferredSubfamily||(T.preferredSubfamily=t.names.fontSubfamily);var P=[],F=n8.make(T,P),j=P.length>0?Y7.make(P):void 0,_=r8.make(),Q=G7.make(t.glyphs,{version:t.getEnglishName("version"),fullName:I,familyName:S,weightName:C,postScriptName:L,unitsPerEm:t.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),H=t.metas&&Object.keys(t.metas).length>0?a8.make(t.metas):void 0,B=[x,w,M,k,F,A,_,Q,z];j&&B.push(j),t.tables.gsub&&B.push(c8.make(t.tables.gsub)),H&&B.push(H);for(var Y=s8(B),e1=Y.encode(),X=Lt(e1),M1=Y.fields,v1=!1,p1=0;p1<M1.length;p1+=1)if(M1[p1].name==="head table"){M1[p1].value.checkSumAdjustment=2981146554-X,v1=!0;break}if(!v1)throw new Error("Could not find head table with checkSum to adjust.");return Y}var $a={make:s8,fontToTable:Oa,computeCheckSum:Lt};function at(t,e){for(var n=0,r=t.length-1;n<=r;){var c=n+r>>>1,a=t[c].tag;if(a===e)return c;a<e?n=c+1:r=c-1}return-n-1}function a7(t,e){for(var n=0,r=t.length-1;n<=r;){var c=n+r>>>1,a=t[c];if(a===e)return c;a<e?n=c+1:r=c-1}return-n-1}function s7(t,e){for(var n,r=0,c=t.length-1;r<=c;){var a=r+c>>>1;n=t[a];var s=n.start;if(s===e)return n;s<e?r=a+1:c=a-1}if(r>0)return n=t[r-1],e>n.end?0:n}function _5(t,e){this.font=t,this.tableName=e}_5.prototype={searchTag:at,binSearch:a7,getTable:function(t){var e=this.font.tables[this.tableName];return!e&&t&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var t=this.getTable();return t?t.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var t=this.getTable();if(t){for(var e=!1,n=0;n<t.scripts.length;n++){var r=t.scripts[n].tag;if(r==="DFLT")return r;r==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(t,e){var n=this.getTable(e);if(n){t=t||"DFLT";var r=n.scripts,c=at(n.scripts,t);if(c>=0)return r[c].script;if(e){var a={tag:t,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return r.splice(-1-c,0,a),a.script}}},getLangSysTable:function(t,e,n){var r=this.getScriptTable(t,n);if(r){if(!e||e==="dflt"||e==="DFLT")return r.defaultLangSys;var c=at(r.langSysRecords,e);if(c>=0)return r.langSysRecords[c].langSys;if(n){var a={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return r.langSysRecords.splice(-1-c,0,a),a.langSys}}},getFeatureTable:function(t,e,n,r){var c=this.getLangSysTable(t,e,r);if(c){for(var a,s=c.featureIndexes,o=this.font.tables[this.tableName].features,i=0;i<s.length;i++)if(a=o[s[i]],a.tag===n)return a.feature;if(r){var l=o.length;return T1.assert(l===0||n>=o[l-1].tag,"Features must be added in alphabetical order."),a={tag:n,feature:{params:0,lookupListIndexes:[]}},o.push(a),s.push(l),a.feature}}},getLookupTables:function(t,e,n,r,c){var a=this.getFeatureTable(t,e,n,c),s=[];if(a){for(var o,i=a.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<i.length;h++)o=l[i[h]],o.lookupType===r&&s.push(o);if(s.length===0&&c){o={lookupType:r,lookupFlag:0,subtables:[],markFilteringSet:void 0};var u=l.length;return l.push(o),i.push(u),[o]}}return s},getGlyphClass:function(t,e){switch(t.format){case 1:return t.startGlyph<=e&&e<t.startGlyph+t.classes.length?t.classes[e-t.startGlyph]:0;case 2:var n=s7(t.ranges,e);return n?n.classId:0}},getCoverageIndex:function(t,e){switch(t.format){case 1:var n=a7(t.glyphs,e);return n>=0?n:-1;case 2:var r=s7(t.ranges,e);return r?r.index+e-r.start:-1}},expandCoverage:function(t){if(t.format===1)return t.glyphs;for(var e=[],n=t.ranges,r=0;r<n.length;r++)for(var c=n[r],a=c.start,s=c.end,o=a;o<=s;o++)e.push(o);return e}};function j5(t){_5.call(this,t,"gpos")}j5.prototype=_5.prototype;j5.prototype.init=function(){var t=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(t)};j5.prototype.getKerningValue=function(t,e,n){for(var r=0;r<t.length;r++)for(var c=t[r].subtables,a=0;a<c.length;a++){var s=c[a],o=this.getCoverageIndex(s.coverage,e);if(!(o<0))switch(s.posFormat){case 1:for(var i=s.pairSets[o],l=0;l<i.length;l++){var h=i[l];if(h.secondGlyph===n)return h.value1&&h.value1.xAdvance||0}break;case 2:var u=this.getGlyphClass(s.classDef1,e),f=this.getGlyphClass(s.classDef2,n),d=s.classRecords[u][f];return d.value1&&d.value1.xAdvance||0}}return 0};j5.prototype.getKerningTables=function(t,e){if(this.font.tables.gpos)return this.getLookupTables(t,e,"kern",2)};function a2(t){_5.call(this,t,"gsub")}function Ra(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}function Ct(t,e,n){for(var r=t.subtables,c=0;c<r.length;c++){var a=r[c];if(a.substFormat===e)return a}if(n)return r.push(n),n}a2.prototype=_5.prototype;a2.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};a2.prototype.getSingle=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,1),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++){var i=s[o],l=this.expandCoverage(i.coverage),h=void 0;if(i.substFormat===1){var u=i.deltaGlyphId;for(h=0;h<l.length;h++){var f=l[h];r.push({sub:f,by:f+u})}}else{var d=i.substitute;for(h=0;h<l.length;h++)r.push({sub:l[h],by:d[h]})}}return r};a2.prototype.getMultiple=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,2),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++){var i=s[o],l=this.expandCoverage(i.coverage),h=void 0;for(h=0;h<l.length;h++){var u=l[h],f=i.sequences[h];r.push({sub:u,by:f})}}return r};a2.prototype.getAlternates=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,3),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++)for(var i=s[o],l=this.expandCoverage(i.coverage),h=i.alternateSets,u=0;u<l.length;u++)r.push({sub:l[u],by:h[u]});return r};a2.prototype.getLigatures=function(t,e,n){for(var r=[],c=this.getLookupTables(e,n,t,4),a=0;a<c.length;a++)for(var s=c[a].subtables,o=0;o<s.length;o++)for(var i=s[o],l=this.expandCoverage(i.coverage),h=i.ligatureSets,u=0;u<l.length;u++)for(var f=l[u],d=h[u],p=0;p<d.length;p++){var m=d[p];r.push({sub:[f].concat(m.components),by:m.ligGlyph})}return r};a2.prototype.addSingle=function(t,e,n,r){var c=this.getLookupTables(n,r,t,1,!0)[0],a=Ct(c,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});T1.assert(a.coverage.format===1,"Single: unable to modify coverage table format "+a.coverage.format);var s=e.sub,o=this.binSearch(a.coverage.glyphs,s);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,s),a.substitute.splice(o,0,0)),a.substitute[o]=e.by};a2.prototype.addMultiple=function(t,e,n,r){T1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var c=this.getLookupTables(n,r,t,2,!0)[0],a=Ct(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});T1.assert(a.coverage.format===1,"Multiple: unable to modify coverage table format "+a.coverage.format);var s=e.sub,o=this.binSearch(a.coverage.glyphs,s);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,s),a.sequences.splice(o,0,0)),a.sequences[o]=e.by};a2.prototype.addAlternate=function(t,e,n,r){var c=this.getLookupTables(n,r,t,3,!0)[0],a=Ct(c,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});T1.assert(a.coverage.format===1,"Alternate: unable to modify coverage table format "+a.coverage.format);var s=e.sub,o=this.binSearch(a.coverage.glyphs,s);o<0&&(o=-1-o,a.coverage.glyphs.splice(o,0,s),a.alternateSets.splice(o,0,0)),a.alternateSets[o]=e.by};a2.prototype.addLigature=function(t,e,n,r){var c=this.getLookupTables(n,r,t,4,!0)[0],a=c.subtables[0];a||(a={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},c.subtables[0]=a),T1.assert(a.coverage.format===1,"Ligature: unable to modify coverage table format "+a.coverage.format);var s=e.sub[0],o=e.sub.slice(1),i={ligGlyph:e.by,components:o},l=this.binSearch(a.coverage.glyphs,s);if(l>=0){for(var h=a.ligatureSets[l],u=0;u<h.length;u++)if(Ra(h[u].components,o))return;h.push(i)}else l=-1-l,a.coverage.glyphs.splice(l,0,s),a.ligatureSets.splice(l,0,[i])};a2.prototype.getFeature=function(t,e,n){if(/ss\d\d/.test(t))return this.getSingle(t,e,n);switch(t){case"aalt":case"salt":return this.getSingle(t,e,n).concat(this.getAlternates(t,e,n));case"dlig":case"liga":case"rlig":return this.getLigatures(t,e,n);case"ccmp":return this.getMultiple(t,e,n).concat(this.getLigatures(t,e,n));case"stch":return this.getMultiple(t,e,n)}};a2.prototype.add=function(t,e,n,r){if(/ss\d\d/.test(t))return this.addSingle(t,e,n,r);switch(t){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(t,e,n,r):this.addAlternate(t,e,n,r);case"dlig":case"liga":case"rlig":return this.addLigature(t,e,n,r);case"ccmp":return e.by instanceof Array?this.addMultiple(t,e,n,r):this.addLigature(t,e,n,r)}};function Fa(){return typeof window<"u"}function Da(t){for(var e=new Buffer(t.byteLength),n=new Uint8Array(t),r=0;r<e.length;++r)e[r]=n[r];return e}function F5(t,e){if(!t)throw e}function o7(t,e,n,r,c){var a;return(e&r)>0?(a=t.parseByte(),(e&c)===0&&(a=-a),a=n+a):(e&c)>0?a=n:a=n+t.parseShort(),a}function o8(t,e,n){var r=new d1.Parser(e,n);t.numberOfContours=r.parseShort(),t._xMin=r.parseShort(),t._yMin=r.parseShort(),t._xMax=r.parseShort(),t._yMax=r.parseShort();var c,a;if(t.numberOfContours>0){for(var s=t.endPointIndices=[],o=0;o<t.numberOfContours;o+=1)s.push(r.parseUShort());t.instructionLength=r.parseUShort(),t.instructions=[];for(var i=0;i<t.instructionLength;i+=1)t.instructions.push(r.parseByte());var l=s[s.length-1]+1;c=[];for(var h=0;h<l;h+=1)if(a=r.parseByte(),c.push(a),(a&8)>0)for(var u=r.parseByte(),f=0;f<u;f+=1)c.push(a),h+=1;if(T1.argument(c.length===l,"Bad flags."),s.length>0){var d=[],p;if(l>0){for(var m=0;m<l;m+=1)a=c[m],p={},p.onCurve=!!(a&1),p.lastPointOfContour=s.indexOf(m)>=0,d.push(p);for(var g=0,v=0;v<l;v+=1)a=c[v],p=d[v],p.x=o7(r,a,g,2,16),g=p.x;for(var b=0,y=0;y<l;y+=1)a=c[y],p=d[y],p.y=o7(r,a,b,4,32),b=p.y}t.points=d}else t.points=[]}else if(t.numberOfContours===0)t.points=[];else{t.isComposite=!0,t.points=[],t.components=[];for(var x=!0;x;){c=r.parseUShort();var w={glyphIndex:r.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(c&1)>0?(c&2)>0?(w.dx=r.parseShort(),w.dy=r.parseShort()):w.matchedPoints=[r.parseUShort(),r.parseUShort()]:(c&2)>0?(w.dx=r.parseChar(),w.dy=r.parseChar()):w.matchedPoints=[r.parseByte(),r.parseByte()],(c&8)>0?w.xScale=w.yScale=r.parseF2Dot14():(c&64)>0?(w.xScale=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()):(c&128)>0&&(w.xScale=r.parseF2Dot14(),w.scale01=r.parseF2Dot14(),w.scale10=r.parseF2Dot14(),w.yScale=r.parseF2Dot14()),t.components.push(w),x=!!(c&32)}if(c&256){t.instructionLength=r.parseUShort(),t.instructions=[];for(var M=0;M<t.instructionLength;M+=1)t.instructions.push(r.parseByte())}}}function st(t,e){for(var n=[],r=0;r<t.length;r+=1){var c=t[r],a={x:e.xScale*c.x+e.scale01*c.y+e.dx,y:e.scale10*c.x+e.yScale*c.y+e.dy,onCurve:c.onCurve,lastPointOfContour:c.lastPointOfContour};n.push(a)}return n}function qa(t){for(var e=[],n=[],r=0;r<t.length;r+=1){var c=t[r];n.push(c),c.lastPointOfContour&&(e.push(n),n=[])}return T1.argument(n.length===0,"There are still points left in the current contour."),e}function i8(t){var e=new P0;if(!t)return e;for(var n=qa(t),r=0;r<n.length;++r){var c=n[r],a=null,s=c[c.length-1],o=c[0];if(s.onCurve)e.moveTo(s.x,s.y);else if(o.onCurve)e.moveTo(o.x,o.y);else{var i={x:(s.x+o.x)*.5,y:(s.y+o.y)*.5};e.moveTo(i.x,i.y)}for(var l=0;l<c.length;++l)if(a=s,s=o,o=c[(l+1)%c.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=a,u=o;a.onCurve||(h={x:(s.x+a.x)*.5,y:(s.y+a.y)*.5}),o.onCurve||(u={x:(s.x+o.x)*.5,y:(s.y+o.y)*.5}),e.quadraticCurveTo(s.x,s.y,u.x,u.y)}e.closePath()}return e}function l8(t,e){if(e.isComposite)for(var n=0;n<e.components.length;n+=1){var r=e.components[n],c=t.get(r.glyphIndex);if(c.getPath(),c.points){var a=void 0;if(r.matchedPoints===void 0)a=st(c.points,r);else{if(r.matchedPoints[0]>e.points.length-1||r.matchedPoints[1]>c.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[r.matchedPoints[0]],o=c.points[r.matchedPoints[1]],i={xScale:r.xScale,scale01:r.scale01,scale10:r.scale10,yScale:r.yScale,dx:0,dy:0};o=st([o],i)[0],i.dx=s.x-o.x,i.dy=s.y-o.y,a=st(c.points,i)}e.points=e.points.concat(a)}}return i8(e.points)}function Na(t,e,n,r){for(var c=new I2.GlyphSet(r),a=0;a<n.length-1;a+=1){var s=n[a],o=n[a+1];s!==o?c.push(a,I2.ttfGlyphLoader(r,a,o8,t,e+s,l8)):c.push(a,I2.glyphLoader(r,a))}return c}function Ua(t,e,n,r){var c=new I2.GlyphSet(r);return r._push=function(a){var s=n[a],o=n[a+1];s!==o?c.push(a,I2.ttfGlyphLoader(r,a,o8,t,e+s,l8)):c.push(a,I2.glyphLoader(r,a))},c}function Ba(t,e,n,r,c){return c.lowMemory?Ua(t,e,n,r):Na(t,e,n,r)}var h8={getPath:i8,parse:Ba},u8,S3,f8,xt;function d8(t){this.font=t,this.getCommands=function(e){return h8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function _a(t){return t}function m8(t){return Math.sign(t)*Math.round(Math.abs(t))}function ja(t){return Math.sign(t)*Math.round(Math.abs(t*2))/2}function Ga(t){return Math.sign(t)*(Math.round(Math.abs(t)+.5)-.5)}function Wa(t){return Math.sign(t)*Math.ceil(Math.abs(t))}function Xa(t){return Math.sign(t)*Math.floor(Math.abs(t))}var p8=function(t){var e=this.srPeriod,n=this.srPhase,r=this.srThreshold,c=1;return t<0&&(t=-t,c=-1),t+=r-n,t=Math.trunc(t/e)*e,t+=n,t<0?n*c:t*c},T2={x:1,y:0,axis:"x",distance:function(t,e,n,r){return(n?t.xo:t.x)-(r?e.xo:e.x)},interpolate:function(t,e,n,r){var c,a,s,o,i,l,h;if(!r||r===this){if(c=t.xo-e.xo,a=t.xo-n.xo,i=e.x-e.xo,l=n.x-n.xo,s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){t.x=t.xo+(i+l)/2;return}t.x=t.xo+(i*o+l*s)/h;return}if(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){T2.setRelative(t,t,(i+l)/2,r,!0);return}T2.setRelative(t,t,(i*o+l*s)/h,r,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(t,e,n,r,c){if(!r||r===this){t.x=(c?e.xo:e.x)+n;return}var a=c?e.xo:e.x,s=c?e.yo:e.y,o=a+n*r.x,i=s+n*r.y;t.x=o+(t.y-i)/r.normalSlope},slope:0,touch:function(t){t.xTouched=!0},touched:function(t){return t.xTouched},untouch:function(t){t.xTouched=!1}},U2={x:0,y:1,axis:"y",distance:function(t,e,n,r){return(n?t.yo:t.y)-(r?e.yo:e.y)},interpolate:function(t,e,n,r){var c,a,s,o,i,l,h;if(!r||r===this){if(c=t.yo-e.yo,a=t.yo-n.yo,i=e.y-e.yo,l=n.y-n.yo,s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){t.y=t.yo+(i+l)/2;return}t.y=t.yo+(i*o+l*s)/h;return}if(c=r.distance(t,e,!0,!0),a=r.distance(t,n,!0,!0),i=r.distance(e,e,!1,!0),l=r.distance(n,n,!1,!0),s=Math.abs(c),o=Math.abs(a),h=s+o,h===0){U2.setRelative(t,t,(i+l)/2,r,!0);return}U2.setRelative(t,t,(i*o+l*s)/h,r,!0)},normalSlope:0,setRelative:function(t,e,n,r,c){if(!r||r===this){t.y=(c?e.yo:e.y)+n;return}var a=c?e.xo:e.x,s=c?e.yo:e.y,o=a+n*r.x,i=s+n*r.y;t.y=i+r.normalSlope*(t.x-o)},slope:Number.POSITIVE_INFINITY,touch:function(t){t.yTouched=!0},touched:function(t){return t.yTouched},untouch:function(t){t.yTouched=!1}};Object.freeze(T2);Object.freeze(U2);function G5(t,e){this.x=t,this.y=e,this.axis=void 0,this.slope=e/t,this.normalSlope=-t/e,Object.freeze(this)}G5.prototype.distance=function(t,e,n,r){return this.x*T2.distance(t,e,n,r)+this.y*U2.distance(t,e,n,r)};G5.prototype.interpolate=function(t,e,n,r){var c,a,s,o,i,l,h;if(s=r.distance(t,e,!0,!0),o=r.distance(t,n,!0,!0),c=r.distance(e,e,!1,!0),a=r.distance(n,n,!1,!0),i=Math.abs(s),l=Math.abs(o),h=i+l,h===0){this.setRelative(t,t,(c+a)/2,r,!0);return}this.setRelative(t,t,(c*l+a*i)/h,r,!0)};G5.prototype.setRelative=function(t,e,n,r,c){r=r||this;var a=c?e.xo:e.x,s=c?e.yo:e.y,o=a+n*r.x,i=s+n*r.y,l=r.normalSlope,h=this.slope,u=t.x,f=t.y;t.x=(h*u-l*o+i-f)/(h-l),t.y=h*(t.x-u)+f};G5.prototype.touch=function(t){t.xTouched=!0,t.yTouched=!0};function W5(t,e){var n=Math.sqrt(t*t+e*e);return t/=n,e/=n,t===1&&e===0?T2:t===0&&e===1?U2:new G5(t,e)}function B2(t,e,n,r){this.x=this.xo=Math.round(t*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=n,this.onCurve=r,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}B2.prototype.nextTouched=function(t){for(var e=this.nextPointOnContour;!t.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};B2.prototype.prevTouched=function(t){for(var e=this.prevPointOnContour;!t.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var B5=Object.freeze(new B2(0,0)),Za={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function r3(t,e){switch(this.env=t,this.stack=[],this.prog=e,t){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=T2,this.round=m8}}d8.prototype.exec=function(t,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var n=this.font,r=this._prepState;if(!r||r.ppem!==e){var c=this._fpgmState;if(!c){r3.prototype=Za,c=this._fpgmState=new r3("fpgm",n.tables.fpgm),c.funcs=[],c.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),c.step=-1);try{S3(c)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}r3.prototype=c,r=this._prepState=new r3("prep",n.tables.prep),r.ppem=e;var a=n.tables.cvt;if(a)for(var s=r.cvt=new Array(a.length),o=e/n.unitsPerEm,i=0;i<a.length;i++)s[i]=a[i]*o;else r.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),r.step=-1);try{S3(r)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return f8(t,r)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};f8=function(t,e){var n=e.ppem/e.font.unitsPerEm,r=n,c=t.components,a,s,o;if(r3.prototype=e,!c)o=new r3("glyf",t.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),o.step=-1),xt(t,o,n,r),s=o.gZone;else{var i=e.font;s=[],a=[];for(var l=0;l<c.length;l++){var h=c[l],u=i.glyphs.get(h.glyphIndex);o=new r3("glyf",u.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),o.step=-1),xt(u,o,n,r);for(var f=Math.round(h.dx*n),d=Math.round(h.dy*r),p=o.gZone,m=o.contours,g=0;g<p.length;g++){var v=p[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+f,v.yo=v.y=v.y+d}var b=s.length;s.push.apply(s,p);for(var y=0;y<m.length;y++)a.push(m[y]+b)}t.instructions&&!o.inhibitGridFit&&(o=new r3("glyf",t.instructions),o.gZone=o.z0=o.z1=o.z2=s,o.contours=a,s.push(new B2(0,0),new B2(Math.round(t.advanceWidth*n),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),o.step=-1),S3(o),s.length-=2)}return s};xt=function(t,e,n,r){for(var c=t.points||[],a=c.length,s=e.gZone=e.z0=e.z1=e.z2=[],o=e.contours=[],i,l=0;l<a;l++)i=c[l],s[l]=new B2(i.x*n,i.y*r,i.lastPointOfContour,i.onCurve);for(var h,u,f=0;f<a;f++)i=s[f],h||(h=i,o.push(f)),i.lastPointOfContour?(i.nextPointOnContour=h,h.prevPointOnContour=i,h=void 0):(u=s[f+1],i.nextPointOnContour=u,u.prevPointOnContour=i);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<a;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new B2(0,0),new B2(Math.round(t.advanceWidth*n),0)),S3(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)}}};S3=function(t){var e=t.prog;if(e){var n=e.length,r;for(t.ip=0;t.ip<n;t.ip++){if(exports.DEBUG&&t.step++,r=u8[e[t.ip]],!r)throw new Error("unknown instruction: 0x"+Number(e[t.ip]).toString(16));r(t)}}};function Ge(t){for(var e=t.tZone=new Array(t.gZone.length),n=0;n<e.length;n++)e[n]=new B2(0,0)}function g8(t,e){var n=t.prog,r=t.ip,c=1,a;do if(a=n[++r],a===88)c++;else if(a===89)c--;else if(a===64)r+=n[r+1]+1;else if(a===65)r+=2*n[r+1]+1;else if(a>=176&&a<=183)r+=a-176+1;else if(a>=184&&a<=191)r+=(a-184+1)*2;else if(e&&c===1&&a===27)break;while(c>0);t.ip=r}function i7(t,e){exports.DEBUG&&console.log(e.step,"SVTCA["+t.axis+"]"),e.fv=e.pv=e.dpv=t}function l7(t,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+t.axis+"]"),e.pv=e.dpv=t}function h7(t,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+t.axis+"]"),e.fv=t}function u7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log("SPVTL["+t+"]",r,c);var o,i;t?(o=a.y-s.y,i=s.x-a.x):(o=s.x-a.x,i=s.y-a.y),e.pv=e.dpv=W5(o,i)}function f7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log("SFVTL["+t+"]",r,c);var o,i;t?(o=a.y-s.y,i=s.x-a.x):(o=s.x-a.x,i=s.y-a.y),e.fv=W5(o,i)}function Ya(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.pv=t.dpv=W5(r,n)}function Ja(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SPVFS[]",n,r),t.fv=W5(r,n)}function Ka(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 Qa(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 es(t){t.fv=t.pv,exports.DEBUG&&console.log(t.step,"SFVTPV[]")}function ts(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop(),a=e.pop(),s=e.pop(),o=t.z0,i=t.z1,l=o[n],h=o[r],u=i[c],f=i[a],d=t.z2[s];exports.DEBUG&&console.log("ISECT[], ",n,r,c,a,s);var p=l.x,m=l.y,g=h.x,v=h.y,b=u.x,y=u.y,x=f.x,w=f.y,M=(p-g)*(y-w)-(m-v)*(b-x),k=p*v-m*g,z=b*w-y*x;d.x=(k*(b-x)-z*(p-g))/M,d.y=(k*(y-w)-z*(m-v))/M}function ns(t){t.rp0=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP0[]",t.rp0)}function rs(t){t.rp1=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP1[]",t.rp1)}function cs(t){t.rp2=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SRP2[]",t.rp2)}function as(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP0[]",e),t.zp0=e,e){case 0:t.tZone||Ge(t),t.z0=t.tZone;break;case 1:t.z0=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function ss(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP1[]",e),t.zp1=e,e){case 0:t.tZone||Ge(t),t.z1=t.tZone;break;case 1:t.z1=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function os(t){var e=t.stack.pop();switch(exports.DEBUG&&console.log(t.step,"SZP2[]",e),t.zp2=e,e){case 0:t.tZone||Ge(t),t.z2=t.tZone;break;case 1:t.z2=t.gZone;break;default:throw new Error("Invalid zone pointer")}}function is(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||Ge(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 ls(t){t.loop=t.stack.pop(),exports.DEBUG&&console.log(t.step,"SLOOP[]",t.loop)}function hs(t){exports.DEBUG&&console.log(t.step,"RTG[]"),t.round=m8}function us(t){exports.DEBUG&&console.log(t.step,"RTHG[]"),t.round=Ga}function fs(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SMD[]",e),t.minDis=e/64}function ds(t){exports.DEBUG&&console.log(t.step,"ELSE[]"),g8(t,!1)}function ms(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"JMPR[]",e),t.ip+=e-1}function ps(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCVTCI[]",e),t.cvCutIn=e/64}function gs(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DUP[]"),e.push(e[e.length-1])}function ot(t){exports.DEBUG&&console.log(t.step,"POP[]"),t.stack.pop()}function vs(t){exports.DEBUG&&console.log(t.step,"CLEAR[]"),t.stack.length=0}function ys(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SWAP[]"),e.push(n),e.push(r)}function bs(t){var e=t.stack;exports.DEBUG&&console.log(t.step,"DEPTH[]"),e.push(e.length)}function xs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LOOPCALL[]",n,r);var c=t.ip,a=t.prog;t.prog=t.funcs[n];for(var s=0;s<r;s++)S3(t),exports.DEBUG&&console.log(++t.step,s+1<r?"next loopcall":"done loopcall",s);t.ip=c,t.prog=a}function Ms(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"CALL[]",e);var n=t.ip,r=t.prog;t.prog=t.funcs[e],S3(t),t.ip=n,t.prog=r,exports.DEBUG&&console.log(++t.step,"returning from",e)}function ws(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CINDEX[]",n),e.push(e[e.length-n])}function ks(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 zs(t){if(t.env!=="fpgm")throw new Error("FDEF not allowed here");var e=t.stack,n=t.prog,r=t.ip,c=e.pop(),a=r;for(exports.DEBUG&&console.log(t.step,"FDEF[]",c);n[++r]!==45;);t.ip=r,t.funcs[c]=n.slice(a+1,r)}function d7(t,e){var n=e.stack.pop(),r=e.z0[n],c=e.fv,a=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+t+"]",n);var s=a.distance(r,B5);t&&(s=e.round(s)),c.setRelative(r,B5,s,a),c.touch(r),e.rp0=e.rp1=n}function m7(t,e){var n=e.z2,r=n.length-2,c,a,s;exports.DEBUG&&console.log(e.step,"IUP["+t.axis+"]");for(var o=0;o<r;o++)c=n[o],!t.touched(c)&&(a=c.prevTouched(t),a!==c&&(s=c.nextTouched(t),a===s&&t.setRelative(c,c,t.distance(a,a,!1,!0),t,!0),t.interpolate(c,a,s,t)))}function p7(t,e){for(var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,o=e.loop,i=e.z2;o--;){var l=n.pop(),h=i[l],u=s.distance(c,c,!1,!0);a.setRelative(h,h,u,s),a.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-o)+": ":"")+"SHP["+(t?"rp1":"rp2")+"]",l)}e.loop=1}function g7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,o=n.pop(),i=e.z2[e.contours[o]],l=i;exports.DEBUG&&console.log(e.step,"SHC["+t+"]",o);var h=s.distance(c,c,!1,!0);do l!==c&&a.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==i)}function v7(t,e){var n=e.stack,r=t?e.rp1:e.rp2,c=(t?e.z0:e.z1)[r],a=e.fv,s=e.pv,o=n.pop();exports.DEBUG&&console.log(e.step,"SHZ["+t+"]",o);var i;switch(o){case 0:i=e.tZone;break;case 1:i=e.gZone;break;default:throw new Error("Invalid zone")}for(var l,h=s.distance(c,c,!1,!0),u=i.length-2,f=0;f<u;f++)l=i[f],a.setRelative(l,l,h,s)}function Ss(t){for(var e=t.stack,n=t.loop,r=t.fv,c=e.pop()/64,a=t.z2;n--;){var s=e.pop(),o=a[s];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-n)+": ":"")+"SHPIX[]",s,c),r.setRelative(o,o,c),r.touch(o)}t.loop=1}function As(t){for(var e=t.stack,n=t.rp1,r=t.rp2,c=t.loop,a=t.z0[n],s=t.z1[r],o=t.fv,i=t.dpv,l=t.z2;c--;){var h=e.pop(),u=l[h];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"IP[]",h,n,"<->",r),o.interpolate(u,a,s,i),o.touch(u)}t.loop=1}function y7(t,e){var n=e.stack,r=n.pop()/64,c=n.pop(),a=e.z1[c],s=e.z0[e.rp0],o=e.fv,i=e.pv;o.setRelative(a,s,r,i),o.touch(a),exports.DEBUG&&console.log(e.step,"MSIRP["+t+"]",r,c),e.rp1=e.rp0,e.rp2=c,t&&(e.rp0=c)}function Ls(t){for(var e=t.stack,n=t.rp0,r=t.z0[n],c=t.loop,a=t.fv,s=t.pv,o=t.z1;c--;){var i=e.pop(),l=o[i];exports.DEBUG&&console.log(t.step,(t.loop>1?"loop "+(t.loop-c)+": ":"")+"ALIGNRP[]",i),a.setRelative(l,r,0,s),a.touch(l)}t.loop=1}function Cs(t){exports.DEBUG&&console.log(t.step,"RTDG[]"),t.round=ja}function b7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z0[c],s=e.fv,o=e.pv,i=e.cvt[r];exports.DEBUG&&console.log(e.step,"MIAP["+t+"]",r,"(",i,")",c);var l=o.distance(a,B5);t&&(Math.abs(l-i)<e.cvCutIn&&(l=i),l=e.round(l)),s.setRelative(a,B5,l,o),e.zp0===0&&(a.xo=a.x,a.yo=a.y),s.touch(a),e.rp0=e.rp1=c}function Ps(t){var e=t.prog,n=t.ip,r=t.stack,c=e[++n];exports.DEBUG&&console.log(t.step,"NPUSHB[]",c);for(var a=0;a<c;a++)r.push(e[++n]);t.ip=n}function Es(t){var e=t.ip,n=t.prog,r=t.stack,c=n[++e];exports.DEBUG&&console.log(t.step,"NPUSHW[]",c);for(var a=0;a<c;a++){var s=n[++e]<<8|n[++e];s&32768&&(s=-((s^65535)+1)),r.push(s)}t.ip=e}function Ts(t){var e=t.stack,n=t.store;n||(n=t.store=[]);var r=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"WS",r,c),n[c]=r}function Is(t){var e=t.stack,n=t.store,r=e.pop();exports.DEBUG&&console.log(t.step,"RS",r);var c=n&&n[r]||0;e.push(c)}function Vs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTP",n,r),t.cvt[r]=n/64}function Hs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"RCVT",n),e.push(t.cvt[n]*64)}function x7(t,e){var n=e.stack,r=n.pop(),c=e.z2[r];exports.DEBUG&&console.log(e.step,"GC["+t+"]",r),n.push(e.dpv.distance(c,B5,t,!1)*64)}function M7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z1[r],s=e.z0[c],o=e.dpv.distance(s,a,t,t);exports.DEBUG&&console.log(e.step,"MD["+t+"]",r,c,"->",o),e.stack.push(Math.round(o*64))}function Os(t){exports.DEBUG&&console.log(t.step,"MPPEM[]"),t.stack.push(t.ppem)}function $s(t){exports.DEBUG&&console.log(t.step,"FLIPON[]"),t.autoFlip=!0}function Rs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LT[]",n,r),e.push(r<n?1:0)}function Fs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"LTEQ[]",n,r),e.push(r<=n?1:0)}function Ds(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GT[]",n,r),e.push(r>n?1:0)}function qs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"GTEQ[]",n,r),e.push(r>=n?1:0)}function Ns(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"EQ[]",n,r),e.push(n===r?1:0)}function Us(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"NEQ[]",n,r),e.push(n!==r?1:0)}function Bs(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 _s(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 js(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"IF[]",e),e||(g8(t,!0),exports.DEBUG&&console.log(t.step,"EIF[]"))}function Gs(t){exports.DEBUG&&console.log(t.step,"EIF[]")}function Ws(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"AND[]",n,r),e.push(n&&r?1:0)}function Xs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"OR[]",n,r),e.push(n||r?1:0)}function Zs(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NOT[]",n),e.push(n?0:1)}function it(t,e){var n=e.stack,r=n.pop(),c=e.fv,a=e.pv,s=e.ppem,o=e.deltaBase+(t-1)*16,i=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+t+"]",r,n);for(var h=0;h<r;h++){var u=n.pop(),f=n.pop(),d=o+((f&240)>>4);if(d===s){var p=(f&15)-8;p>=0&&p++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",u,"by",p*i);var m=l[u];c.setRelative(m,m,p*i,a)}}}function Ys(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDB[]",n),t.deltaBase=n}function Js(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"SDS[]",n),t.deltaShift=Math.pow(.5,n)}function Ks(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"ADD[]",n,r),e.push(r+n)}function Qs(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"SUB[]",n,r),e.push(r-n)}function eo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"DIV[]",n,r),e.push(r*64/n)}function to(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MUL[]",n,r),e.push(r*n/64)}function no(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"ABS[]",n),e.push(Math.abs(n))}function ro(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"NEG[]",n),e.push(-n)}function co(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"FLOOR[]",n),e.push(Math.floor(n/64)*64)}function ao(t){var e=t.stack,n=e.pop();exports.DEBUG&&console.log(t.step,"CEILING[]",n),e.push(Math.ceil(n/64)*64)}function Re(t,e){var n=e.stack,r=n.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),n.push(e.round(r/64)*64)}function so(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"WCVTF[]",n,r),t.cvt[r]=n*t.ppem/t.font.unitsPerEm}function lt(t,e){var n=e.stack,r=n.pop(),c=e.ppem,a=e.deltaBase+(t-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+t+"]",r,n);for(var o=0;o<r;o++){var i=n.pop(),l=n.pop(),h=a+((l&240)>>4);if(h===c){var u=(l&15)-8;u>=0&&u++;var f=u*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",i,"by",f),e.cvt[i]+=f}}}function oo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SROUND[]",e),t.round=p8;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 io(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"S45ROUND[]",e),t.round=p8;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 lo(t){exports.DEBUG&&console.log(t.step,"ROFF[]"),t.round=_a}function ho(t){exports.DEBUG&&console.log(t.step,"RUTG[]"),t.round=Wa}function uo(t){exports.DEBUG&&console.log(t.step,"RDTG[]"),t.round=Xa}function fo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANCTRL[]",e)}function w7(t,e){var n=e.stack,r=n.pop(),c=n.pop(),a=e.z2[r],s=e.z1[c];exports.DEBUG&&console.log(e.step,"SDPVTL["+t+"]",r,c);var o,i;t?(o=a.y-s.y,i=s.x-a.x):(o=s.x-a.x,i=s.y-a.y),e.dpv=W5(o,i)}function mo(t){var e=t.stack,n=e.pop(),r=0;exports.DEBUG&&console.log(t.step,"GETINFO[]",n),n&1&&(r=35),n&32&&(r|=4096),e.push(r)}function po(t){var e=t.stack,n=e.pop(),r=e.pop(),c=e.pop();exports.DEBUG&&console.log(t.step,"ROLL[]"),e.push(r),e.push(n),e.push(c)}function go(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MAX[]",n,r),e.push(Math.max(r,n))}function vo(t){var e=t.stack,n=e.pop(),r=e.pop();exports.DEBUG&&console.log(t.step,"MIN[]",n,r),e.push(Math.min(r,n))}function yo(t){var e=t.stack.pop();exports.DEBUG&&console.log(t.step,"SCANTYPE[]",e)}function bo(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 e3(t,e){var n=e.stack,r=e.prog,c=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+t+"]");for(var a=0;a<t;a++)n.push(r[++c]);e.ip=c}function t3(t,e){var n=e.ip,r=e.prog,c=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+t+"]");for(var a=0;a<t;a++){var s=r[++n]<<8|r[++n];s&32768&&(s=-((s^65535)+1)),c.push(s)}e.ip=n}function u1(t,e,n,r,c,a){var s=a.stack,o=t&&s.pop(),i=s.pop(),l=a.rp0,h=a.z0[l],u=a.z1[i],f=a.minDis,d=a.fv,p=a.dpv,m,g,v,b;g=m=p.distance(u,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),t&&(b=a.cvt[o],r&&Math.abs(g-b)<a.cvCutIn&&(g=b)),n&&g<f&&(g=f),r&&(g=a.round(g)),d.setRelative(u,h,v*g,p),d.touch(u),exports.DEBUG&&console.log(a.step,(t?"MIRP[":"MDRP[")+(e?"M":"m")+(n?">":"_")+(r?"R":"_")+(c===0?"Gr":c===1?"Bl":c===2?"Wh":"")+"]",t?o+"("+a.cvt[o]+","+b+")":"",i,"(d =",m,"->",v*g,")"),a.rp1=a.rp0,a.rp2=i,e&&(a.rp0=i)}u8=[i7.bind(void 0,U2),i7.bind(void 0,T2),l7.bind(void 0,U2),l7.bind(void 0,T2),h7.bind(void 0,U2),h7.bind(void 0,T2),u7.bind(void 0,0),u7.bind(void 0,1),f7.bind(void 0,0),f7.bind(void 0,1),Ya,Ja,Ka,Qa,es,ts,ns,rs,cs,as,ss,os,is,ls,hs,us,fs,ds,ms,ps,void 0,void 0,gs,ot,vs,ys,bs,ws,ks,void 0,void 0,void 0,xs,Ms,zs,void 0,d7.bind(void 0,0),d7.bind(void 0,1),m7.bind(void 0,U2),m7.bind(void 0,T2),p7.bind(void 0,0),p7.bind(void 0,1),g7.bind(void 0,0),g7.bind(void 0,1),v7.bind(void 0,0),v7.bind(void 0,1),Ss,As,y7.bind(void 0,0),y7.bind(void 0,1),Ls,Cs,b7.bind(void 0,0),b7.bind(void 0,1),Ps,Es,Ts,Is,Vs,Hs,x7.bind(void 0,0),x7.bind(void 0,1),void 0,M7.bind(void 0,0),M7.bind(void 0,1),Os,void 0,$s,void 0,void 0,Rs,Fs,Ds,qs,Ns,Us,Bs,_s,js,Gs,Ws,Xs,Zs,it.bind(void 0,1),Ys,Js,Ks,Qs,eo,to,no,ro,co,ao,Re.bind(void 0,0),Re.bind(void 0,1),Re.bind(void 0,2),Re.bind(void 0,3),void 0,void 0,void 0,void 0,so,it.bind(void 0,2),it.bind(void 0,3),lt.bind(void 0,1),lt.bind(void 0,2),lt.bind(void 0,3),oo,io,void 0,void 0,lo,void 0,ho,uo,ot,ot,void 0,void 0,void 0,void 0,void 0,fo,w7.bind(void 0,0),w7.bind(void 0,1),mo,void 0,po,go,vo,yo,bo,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,e3.bind(void 0,1),e3.bind(void 0,2),e3.bind(void 0,3),e3.bind(void 0,4),e3.bind(void 0,5),e3.bind(void 0,6),e3.bind(void 0,7),e3.bind(void 0,8),t3.bind(void 0,1),t3.bind(void 0,2),t3.bind(void 0,3),t3.bind(void 0,4),t3.bind(void 0,5),t3.bind(void 0,6),t3.bind(void 0,7),t3.bind(void 0,8),u1.bind(void 0,0,0,0,0,0),u1.bind(void 0,0,0,0,0,1),u1.bind(void 0,0,0,0,0,2),u1.bind(void 0,0,0,0,0,3),u1.bind(void 0,0,0,0,1,0),u1.bind(void 0,0,0,0,1,1),u1.bind(void 0,0,0,0,1,2),u1.bind(void 0,0,0,0,1,3),u1.bind(void 0,0,0,1,0,0),u1.bind(void 0,0,0,1,0,1),u1.bind(void 0,0,0,1,0,2),u1.bind(void 0,0,0,1,0,3),u1.bind(void 0,0,0,1,1,0),u1.bind(void 0,0,0,1,1,1),u1.bind(void 0,0,0,1,1,2),u1.bind(void 0,0,0,1,1,3),u1.bind(void 0,0,1,0,0,0),u1.bind(void 0,0,1,0,0,1),u1.bind(void 0,0,1,0,0,2),u1.bind(void 0,0,1,0,0,3),u1.bind(void 0,0,1,0,1,0),u1.bind(void 0,0,1,0,1,1),u1.bind(void 0,0,1,0,1,2),u1.bind(void 0,0,1,0,1,3),u1.bind(void 0,0,1,1,0,0),u1.bind(void 0,0,1,1,0,1),u1.bind(void 0,0,1,1,0,2),u1.bind(void 0,0,1,1,0,3),u1.bind(void 0,0,1,1,1,0),u1.bind(void 0,0,1,1,1,1),u1.bind(void 0,0,1,1,1,2),u1.bind(void 0,0,1,1,1,3),u1.bind(void 0,1,0,0,0,0),u1.bind(void 0,1,0,0,0,1),u1.bind(void 0,1,0,0,0,2),u1.bind(void 0,1,0,0,0,3),u1.bind(void 0,1,0,0,1,0),u1.bind(void 0,1,0,0,1,1),u1.bind(void 0,1,0,0,1,2),u1.bind(void 0,1,0,0,1,3),u1.bind(void 0,1,0,1,0,0),u1.bind(void 0,1,0,1,0,1),u1.bind(void 0,1,0,1,0,2),u1.bind(void 0,1,0,1,0,3),u1.bind(void 0,1,0,1,1,0),u1.bind(void 0,1,0,1,1,1),u1.bind(void 0,1,0,1,1,2),u1.bind(void 0,1,0,1,1,3),u1.bind(void 0,1,1,0,0,0),u1.bind(void 0,1,1,0,0,1),u1.bind(void 0,1,1,0,0,2),u1.bind(void 0,1,1,0,0,3),u1.bind(void 0,1,1,0,1,0),u1.bind(void 0,1,1,0,1,1),u1.bind(void 0,1,1,0,1,2),u1.bind(void 0,1,1,0,1,3),u1.bind(void 0,1,1,1,0,0),u1.bind(void 0,1,1,1,0,1),u1.bind(void 0,1,1,1,0,2),u1.bind(void 0,1,1,1,0,3),u1.bind(void 0,1,1,1,1,0),u1.bind(void 0,1,1,1,1,1),u1.bind(void 0,1,1,1,1,2),u1.bind(void 0,1,1,1,1,3)];function e5(t){this.char=t,this.state={},this.activeState=null}function Pt(t,e,n){this.contextName=n,this.startIndex=t,this.endOffset=e}function xo(t,e,n){this.contextName=t,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=n}function v2(t,e){this.context=t,this.index=e,this.length=t.length,this.current=t[e],this.backtrack=t.slice(0,e),this.lookahead=t.slice(e+1)}function We(t){this.eventId=t,this.subscribers=[]}function Mo(t){var e=this,n=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];n.forEach(function(c){Object.defineProperty(e.events,c,{value:new We(c)})}),t&&n.forEach(function(c){var a=t[c];typeof a=="function"&&e.events[c].subscribe(a)});var r=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];r.forEach(function(c){e.events[c].subscribe(e.updateContextsRanges)})}function x0(t){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Mo.call(this,t)}e5.prototype.setState=function(t,e){return this.state[t]=e,this.activeState={key:t,value:this.state[t]},this.activeState};e5.prototype.getState=function(t){return this.state[t]||null};x0.prototype.inboundIndex=function(t){return t>=0&&t<this.tokens.length};x0.prototype.composeRUD=function(t){var e=this,n=!0,r=t.map(function(a){return e[a[0]].apply(e,a.slice(1).concat(n))}),c=function(a){return typeof a=="object"&&a.hasOwnProperty("FAIL")};if(r.every(c))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:r.filter(c)};this.dispatch("composeRUD",[r.filter(function(a){return!c(a)})])};x0.prototype.replaceRange=function(t,e,n,r){e=e!==null?e:this.tokens.length;var c=n.every(function(s){return s instanceof e5});if(!isNaN(t)&&this.inboundIndex(t)&&c){var a=this.tokens.splice.apply(this.tokens,[t,e].concat(n));return r||this.dispatch("replaceToken",[t,e,n]),[a,n]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};x0.prototype.replaceToken=function(t,e,n){if(!isNaN(t)&&this.inboundIndex(t)&&e instanceof e5){var r=this.tokens.splice(t,1,e);return n||this.dispatch("replaceToken",[t,e]),[r[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};x0.prototype.removeRange=function(t,e,n){e=isNaN(e)?this.tokens.length:e;var r=this.tokens.splice(t,e);return n||this.dispatch("removeRange",[r,t,e]),r};x0.prototype.removeToken=function(t,e){if(!isNaN(t)&&this.inboundIndex(t)){var n=this.tokens.splice(t,1);return e||this.dispatch("removeToken",[n,t]),n}else return{FAIL:"removeToken: invalid token index."}};x0.prototype.insertToken=function(t,e,n){var r=t.every(function(c){return c instanceof e5});return r?(this.tokens.splice.apply(this.tokens,[e,0].concat(t)),n||this.dispatch("insertToken",[t,e]),t):{FAIL:"insertToken: invalid token(s)."}};x0.prototype.registerModifier=function(t,e,n){this.events.newToken.subscribe(function(r,c){var a=[r,c],s=e===null||e.apply(this,a)===!0,o=[r,c];if(s){var i=n.apply(this,o);r.setState(t,i)}}),this.registeredModifiers.push(t)};We.prototype.subscribe=function(t){return typeof t=="function"?this.subscribers.push(t)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};We.prototype.unsubscribe=function(t){this.subscribers.splice(t,1)};v2.prototype.setCurrentIndex=function(t){this.index=t,this.current=this.context[t],this.backtrack=this.context.slice(0,t),this.lookahead=this.context.slice(t+1)};v2.prototype.get=function(t){switch(!0){case t===0:return this.current;case(t<0&&Math.abs(t)<=this.backtrack.length):return this.backtrack.slice(t)[0];case(t>0&&t<=this.lookahead.length):return this.lookahead[t-1];default:return null}};x0.prototype.rangeToText=function(t){if(t instanceof Pt)return this.getRangeTokens(t).map(function(e){return e.char}).join("")};x0.prototype.getText=function(){return this.tokens.map(function(t){return t.char}).join("")};x0.prototype.getContext=function(t){var e=this.registeredContexts[t];return e||null};x0.prototype.on=function(t,e){var n=this.events[t];return n?n.subscribe(e):null};x0.prototype.dispatch=function(t,e){var n=this,r=this.events[t];r instanceof We&&r.subscribers.forEach(function(c){c.apply(n,e||[])})};x0.prototype.registerContextChecker=function(t,e,n){if(this.getContext(t))return{FAIL:"context name '"+t+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof n!="function")return{FAIL:"missing context end check."};var r=new xo(t,e,n);return this.registeredContexts[t]=r,this.contextCheckers.push(r),r};x0.prototype.getRangeTokens=function(t){var e=t.startIndex+t.endOffset;return[].concat(this.tokens.slice(t.startIndex,e))};x0.prototype.getContextRanges=function(t){var e=this.getContext(t);return e?e.ranges:{FAIL:"context checker '"+t+"' is not registered."}};x0.prototype.resetContextsRanges=function(){var t=this.registeredContexts;for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];n.ranges=[]}};x0.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var t=this.tokens.map(function(r){return r.char}),e=0;e<t.length;e++){var n=new v2(t,e);this.runContextCheck(n)}this.dispatch("updateContextsRanges",[this.registeredContexts])};x0.prototype.setEndOffset=function(t,e){var n=this.getContext(e).openRange.startIndex,r=new Pt(n,t,e),c=this.getContext(e).ranges;return r.rangeId=e+"."+c.length,c.push(r),this.getContext(e).openRange=null,r};x0.prototype.runContextCheck=function(t){var e=this,n=t.index;this.contextCheckers.forEach(function(r){var c=r.contextName,a=e.getContext(c).openRange;if(!a&&r.checkStart(t)&&(a=new Pt(n,null,c),e.getContext(c).openRange=a,e.dispatch("contextStart",[c,n])),a&&r.checkEnd(t)){var s=n-a.startIndex+1,o=e.setEndOffset(s,c);e.dispatch("contextEnd",[c,o])}})};x0.prototype.tokenize=function(t){this.tokens=[],this.resetContextsRanges();var e=Array.from(t);this.dispatch("start");for(var n=0;n<e.length;n++){var r=e[n],c=new v2(e,n);this.dispatch("next",[c]),this.runContextCheck(c);var a=new e5(r);this.tokens.push(a),this.dispatch("newToken",[a,c])}return this.dispatch("end",[this.tokens]),this.tokens};function c3(t){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(t)}function v8(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 a3(t){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(t)}function De(t){return/[A-z]/.test(t)}function wo(t){return/\s/.test(t)}function s2(t){this.font=t,this.features={}}function z3(t){this.id=t.id,this.tag=t.tag,this.substitution=t.substitution}function X5(t,e){if(!t)return-1;switch(e.format){case 1:return e.glyphs.indexOf(t);case 2:for(var n=e.ranges,r=0;r<n.length;r++){var c=n[r];if(t>=c.start&&t<=c.end){var a=t-c.start;return c.index+a}}break;default:return-1}return-1}function ko(t,e){var n=X5(t,e.coverage);return n===-1?null:t+e.deltaGlyphId}function zo(t,e){var n=X5(t,e.coverage);return n===-1?null:e.substitute[n]}function ht(t,e){for(var n=[],r=0;r<t.length;r++){var c=t[r],a=e.current;a=Array.isArray(a)?a[0]:a;var s=X5(a,c);s!==-1&&n.push(s)}return n.length!==t.length?-1:n}function So(t,e){var n=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(t.context.length<n)return[];var r=ht(e.inputCoverage,t);if(r===-1)return[];var c=e.inputCoverage.length-1;if(t.lookahead.length<e.lookaheadCoverage.length)return[];for(var a=t.lookahead.slice(c);a.length&&a3(a[0].char);)a.shift();var s=new v2(a,0),o=ht(e.lookaheadCoverage,s),i=[].concat(t.backtrack);for(i.reverse();i.length&&a3(i[0].char);)i.shift();if(i.length<e.backtrackCoverage.length)return[];var l=new v2(i,0),h=ht(e.backtrackCoverage,l),u=r.length===e.inputCoverage.length&&o.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,f=[];if(u)for(var d=0;d<e.lookupRecords.length;d++)for(var p=e.lookupRecords[d],m=p.lookupListIndex,g=this.getLookupByIndex(m),v=0;v<g.subtables.length;v++){var b=g.subtables[v],y=this.getLookupMethod(g,b),x=this.getSubstitutionType(g,b);if(x==="12")for(var w=0;w<r.length;w++){var M=t.get(w),k=y(M);k&&f.push(k)}}return f}function Ao(t,e){var n=t.current,r=X5(n,e.coverage);if(r===-1)return null;for(var c,a=e.ligatureSets[r],s=0;s<a.length;s++){c=a[s];for(var o=0;o<c.components.length;o++){var i=t.lookahead[o],l=c.components[o];if(i!==l)break;if(o===c.components.length-1)return c}}return null}function Lo(t,e){var n=X5(t,e.coverage);return n===-1?null:e.sequences[n]}s2.prototype.getDefaultScriptFeaturesIndexes=function(){for(var t=this.font.tables.gsub.scripts,e=0;e<t.length;e++){var n=t[e];if(n.tag==="DFLT")return n.script.defaultLangSys.featureIndexes}return[]};s2.prototype.getScriptFeaturesIndexes=function(t){var e=this.font.tables;if(!e.gsub)return[];if(!t)return this.getDefaultScriptFeaturesIndexes();for(var n=this.font.tables.gsub.scripts,r=0;r<n.length;r++){var c=n[r];if(c.tag===t&&c.script.defaultLangSys)return c.script.defaultLangSys.featureIndexes;var a=c.langSysRecords;if(a)for(var s=0;s<a.length;s++){var o=a[s];if(o.tag===t){var i=o.langSys;return i.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};s2.prototype.mapTagsToFeatures=function(t,e){for(var n={},r=0;r<t.length;r++){var c=t[r].tag,a=t[r].feature;n[c]=a}this.features[e].tags=n};s2.prototype.getScriptFeatures=function(t){var e=this.features[t];if(this.features.hasOwnProperty(t))return e;var n=this.getScriptFeaturesIndexes(t);if(!n)return null;var r=this.font.tables.gsub;return e=n.map(function(c){return r.features[c]}),this.features[t]=e,this.mapTagsToFeatures(e,t),e};s2.prototype.getSubstitutionType=function(t,e){var n=t.lookupType.toString(),r=e.substFormat.toString();return n+r};s2.prototype.getLookupMethod=function(t,e){var n=this,r=this.getSubstitutionType(t,e);switch(r){case"11":return function(c){return ko.apply(n,[c,e])};case"12":return function(c){return zo.apply(n,[c,e])};case"63":return function(c){return So.apply(n,[c,e])};case"41":return function(c){return Ao.apply(n,[c,e])};case"21":return function(c){return Lo.apply(n,[c,e])};default:throw new Error("lookupType: "+t.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};s2.prototype.lookupFeature=function(t){var e=t.contextParams,n=e.index,r=this.getFeature({tag:t.tag,script:t.script});if(!r)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+t.tag+"' for script '"+t.script+"'.");for(var c=this.getFeatureLookups(r),a=[].concat(e.context),s=0;s<c.length;s++)for(var o=c[s],i=this.getLookupSubtables(o),l=0;l<i.length;l++){var h=i[l],u=this.getSubstitutionType(o,h),f=this.getLookupMethod(o,h),d=void 0;switch(u){case"11":d=f(e.current),d&&a.splice(n,1,new z3({id:11,tag:t.tag,substitution:d}));break;case"12":d=f(e.current),d&&a.splice(n,1,new z3({id:12,tag:t.tag,substitution:d}));break;case"63":d=f(e),Array.isArray(d)&&d.length&&a.splice(n,1,new z3({id:63,tag:t.tag,substitution:d}));break;case"41":d=f(e),d&&a.splice(n,1,new z3({id:41,tag:t.tag,substitution:d}));break;case"21":d=f(e.current),d&&a.splice(n,1,new z3({id:21,tag:t.tag,substitution:d}));break}e=new v2(a,n),!(Array.isArray(d)&&!d.length)&&(d=null)}return a.length?a:null};s2.prototype.supports=function(t){if(!t.script)return!1;this.getScriptFeatures(t.script);var e=this.features.hasOwnProperty(t.script);if(!t.tag)return e;var n=this.features[t.script].some(function(r){return r.tag===t.tag});return e&&n};s2.prototype.getLookupSubtables=function(t){return t.subtables||null};s2.prototype.getLookupByIndex=function(t){var e=this.font.tables.gsub.lookups;return e[t]||null};s2.prototype.getFeatureLookups=function(t){return t.lookupListIndexes.map(this.getLookupByIndex.bind(this))};s2.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var n=this.features[e.script];return n?n.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function Co(t){var e=t.current,n=t.get(-1);return n===null&&c3(e)||!c3(n)&&c3(e)}function Po(t){var e=t.get(1);return e===null||!c3(e)}var Eo={startCheck:Co,endCheck:Po};function To(t){var e=t.current,n=t.get(-1);return(c3(e)||a3(e))&&!c3(n)}function Io(t){var e=t.get(1);switch(!0){case e===null:return!0;case(!c3(e)&&!a3(e)):var n=wo(e);if(!n)return!0;if(n){var r=!1;if(r=t.lookahead.some(function(c){return c3(c)||a3(c)}),!r)return!0}break;default:return!1}}var Vo={startCheck:To,endCheck:Io};function Ho(t,e,n){e[n].setState(t.tag,t.substitution)}function Oo(t,e,n){e[n].setState(t.tag,t.substitution)}function $o(t,e,n){t.substitution.forEach(function(r,c){var a=e[n+c];a.setState(t.tag,r)})}function Ro(t,e,n){var r=e[n];r.setState(t.tag,t.substitution.ligGlyph);for(var c=t.substitution.components.length,a=0;a<c;a++)r=e[n+a+1],r.setState("deleted",!0)}var k7={11:Ho,12:Oo,63:$o,41:Ro};function Et(t,e,n){t instanceof z3&&k7[t.id]&&k7[t.id](t,e,n)}function Fo(t){for(var e=[].concat(t.backtrack),n=e.length-1;n>=0;n--){var r=e[n],c=v8(r),a=a3(r);if(!c&&!a)return!0;if(c)return!1}return!1}function Do(t){if(v8(t.current))return!1;for(var e=0;e<t.lookahead.length;e++){var n=t.lookahead[e],r=a3(n);if(!r)return!0}return!1}function qo(t){var e=this,n="arab",r=this.featuresTags[n],c=this.tokenizer.getRangeTokens(t);if(c.length!==1){var a=new v2(c.map(function(o){return o.getState("glyphIndex")}),0),s=new v2(c.map(function(o){return o.char}),0);c.forEach(function(o,i){if(!a3(o.char)){a.setCurrentIndex(i),s.setCurrentIndex(i);var l=0;Fo(s)&&(l|=1),Do(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(r.indexOf(h)!==-1){var u=e.query.lookupFeature({tag:h,script:n,contextParams:a});if(u instanceof Error)return console.info(u.message);u.forEach(function(f,d){f instanceof z3&&(Et(f,c,d),a.context[d]=f.substitution)})}}})}}function z7(t,e){var n=t.map(function(r){return r.activeState.value});return new v2(n,e||0)}function No(t){var e=this,n="arab",r=this.tokenizer.getRangeTokens(t),c=z7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var o=e.query.lookupFeature({tag:"rlig",script:n,contextParams:c});o.length&&(o.forEach(function(i){return Et(i,r,s)}),c=z7(r))})}function Uo(t){var e=t.current,n=t.get(-1);return n===null&&De(e)||!De(n)&&De(e)}function Bo(t){var e=t.get(1);return e===null||!De(e)}var _o={startCheck:Uo,endCheck:Bo};function S7(t,e){var n=t.map(function(r){return r.activeState.value});return new v2(n,e||0)}function jo(t){var e=this,n="latn",r=this.tokenizer.getRangeTokens(t),c=S7(r);c.context.forEach(function(a,s){c.setCurrentIndex(s);var o=e.query.lookupFeature({tag:"liga",script:n,contextParams:c});o.length&&(o.forEach(function(i){return Et(i,r,s)}),c=S7(r))})}function x2(t){this.baseDir=t||"ltr",this.tokenizer=new x0,this.featuresTags={}}x2.prototype.setText=function(t){this.text=t};x2.prototype.contextChecks={latinWordCheck:_o,arabicWordCheck:Eo,arabicSentenceCheck:Vo};function ut(t){var e=this.contextChecks[t+"Check"];return this.tokenizer.registerContextChecker(t,e.startCheck,e.endCheck)}function Go(){return ut.call(this,"latinWord"),ut.call(this,"arabicWord"),ut.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Wo(){var t=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(n){var r=t.tokenizer.getRangeTokens(n);t.tokenizer.replaceRange(n.startIndex,n.endOffset,r.reverse())})}x2.prototype.registerFeatures=function(t,e){var n=this,r=e.filter(function(c){return n.query.supports({script:t,tag:c})});this.featuresTags.hasOwnProperty(t)?this.featuresTags[t]=this.featuresTags[t].concat(r):this.featuresTags[t]=r};x2.prototype.applyFeatures=function(t,e){if(!t)throw new Error("No valid font was provided to apply features");this.query||(this.query=new s2(t));for(var n=0;n<e.length;n++){var r=e[n];this.query.supports({script:r.script})&&this.registerFeatures(r.script,r.tags)}};x2.prototype.registerModifier=function(t,e,n){this.tokenizer.registerModifier(t,e,n)};function Tt(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Xo(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){Tt.call(this);var n=this.tokenizer.getContextRanges("arabicWord");n.forEach(function(r){qo.call(t,r)})}}function Zo(){var t=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("rlig")!==-1){Tt.call(this);var r=this.tokenizer.getContextRanges("arabicWord");r.forEach(function(c){No.call(t,c)})}}}function Yo(){var t=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var n=this.featuresTags[e];if(n.indexOf("liga")!==-1){Tt.call(this);var r=this.tokenizer.getContextRanges("latinWord");r.forEach(function(c){jo.call(t,c)})}}}x2.prototype.checkContextReady=function(t){return!!this.tokenizer.getContext(t)};x2.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Xo.call(this),Zo.call(this)),this.checkContextReady("latinWord")&&Yo.call(this),this.checkContextReady("arabicSentence")&&Wo.call(this)};x2.prototype.processText=function(t){(!this.text||this.text!==t)&&(this.setText(t),Go.call(this),this.applyFeaturesToContexts())};x2.prototype.getBidiText=function(t){return this.processText(t),this.tokenizer.getText()};x2.prototype.getTextGlyphs=function(t){this.processText(t);for(var e=[],n=0;n<this.tokenizer.tokens.length;n++){var r=this.tokenizer.tokens[n];if(!r.state.deleted){var c=r.activeState.value;e.push(Array.isArray(c)?c[0]:c)}}return e};function a0(t){t=t||{},t.tables=t.tables||{},t.empty||(F5(t.familyName,"When creating a new Font object, familyName is required."),F5(t.styleName,"When creating a new Font object, styleName is required."),F5(t.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),F5(t.ascender,"When creating a new Font object, ascender is required."),F5(t.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:t.familyName||" "},fontSubfamily:{en:t.styleName||" "},fullName:{en:t.fullName||t.familyName+" "+t.styleName},postScriptName:{en:t.postScriptName||(t.familyName+t.styleName).replace(/\s/g,"")},designer:{en:t.designer||" "},designerURL:{en:t.designerURL||" "},manufacturer:{en:t.manufacturer||" "},manufacturerURL:{en:t.manufacturerURL||" "},license:{en:t.license||" "},licenseURL:{en:t.licenseURL||" "},version:{en:t.version||"Version 0.1"},description:{en:t.description||" "},copyright:{en:t.copyright||" "},trademark:{en:t.trademark||" "}},this.unitsPerEm=t.unitsPerEm||1e3,this.ascender=t.ascender,this.descender=t.descender,this.createdTimestamp=t.createdTimestamp,this.tables=Object.assign(t.tables,{os2:Object.assign({usWeightClass:t.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:t.widthClass||this.usWidthClasses.MEDIUM,fsSelection:t.fsSelection||this.fsSelectionValues.REGULAR},t.tables.os2)})),this.supported=!0,this.glyphs=new I2.GlyphSet(this,t.glyphs||[]),this.encoding=new $7(this),this.position=new j5(this),this.substitution=new a2(this),this.tables=this.tables||{},this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){if(this._hinting)return this._hinting;if(this.outlinesFormat==="truetype")return this._hinting=new d8(this)}})}a0.prototype.hasChar=function(t){return this.encoding.charToGlyphIndex(t)!==null};a0.prototype.charToGlyphIndex=function(t){return this.encoding.charToGlyphIndex(t)};a0.prototype.charToGlyph=function(t){var e=this.charToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};a0.prototype.updateFeatures=function(t){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(n){return t[n]})}:e})};a0.prototype.stringToGlyphs=function(t,e){var n=this,r=new x2,c=function(u){return n.charToGlyphIndex(u.char)};r.registerModifier("glyphIndex",null,c);var a=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;r.applyFeatures(this,a);for(var s=r.getTextGlyphs(t),o=s.length,i=new Array(o),l=this.glyphs.get(0),h=0;h<o;h+=1)i[h]=this.glyphs.get(s[h])||l;return i};a0.prototype.nameToGlyphIndex=function(t){return this.glyphNames.nameToGlyphIndex(t)};a0.prototype.nameToGlyph=function(t){var e=this.nameToGlyphIndex(t),n=this.glyphs.get(e);return n||(n=this.glyphs.get(0)),n};a0.prototype.glyphIndexToName=function(t){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(t):""};a0.prototype.getKerningValue=function(t,e){t=t.index||t,e=e.index||e;var n=this.position.defaultKerningTables;return n?this.position.getKerningValue(n,t,e):this.kerningPairs[t+","+e]||0};a0.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};a0.prototype.forEachGlyph=function(t,e,n,r,c,a){e=e!==void 0?e:0,n=n!==void 0?n:0,r=r!==void 0?r:72,c=Object.assign({},this.defaultRenderOptions,c);var s=1/this.unitsPerEm*r,o=this.stringToGlyphs(t,c),i;if(c.kerning){var l=c.script||this.position.getDefaultScriptName();i=this.position.getKerningTables(l,c.language)}for(var h=0;h<o.length;h+=1){var u=o[h];if(a.call(this,u,e,n,r,c),u.advanceWidth&&(e+=u.advanceWidth*s),c.kerning&&h<o.length-1){var f=i?this.position.getKerningValue(i,u.index,o[h+1].index):this.getKerningValue(u,o[h+1]);e+=f*s}c.letterSpacing?e+=c.letterSpacing*r:c.tracking&&(e+=c.tracking/1e3*r)}return e};a0.prototype.getPath=function(t,e,n,r,c){var a=new P0;return this.forEachGlyph(t,e,n,r,c,function(s,o,i,l){var h=s.getPath(o,i,l,c,this);a.extend(h)}),a};a0.prototype.getPaths=function(t,e,n,r,c){var a=[];return this.forEachGlyph(t,e,n,r,c,function(s,o,i,l){var h=s.getPath(o,i,l,c,this);a.push(h)}),a};a0.prototype.getAdvanceWidth=function(t,e,n){return this.forEachGlyph(t,0,0,e,n,function(){})};a0.prototype.draw=function(t,e,n,r,c,a){this.getPath(e,n,r,c,a).draw(t)};a0.prototype.drawPoints=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,o,i,l){s.drawPoints(t,o,i,l)})};a0.prototype.drawMetrics=function(t,e,n,r,c,a){this.forEachGlyph(e,n,r,c,a,function(s,o,i,l){s.drawMetrics(t,o,i,l)})};a0.prototype.getEnglishName=function(t){var e=this.names[t];if(e)return e.en};a0.prototype.validate=function(){var t=this;function e(r,c){}function n(r){var c=t.getEnglishName(r);c&&c.trim().length>0}n("fontFamily"),n("weightName"),n("manufacturer"),n("copyright"),n("version"),this.unitsPerEm>0};a0.prototype.toTables=function(){return $a.fontToTable(this)};a0.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};a0.prototype.toArrayBuffer=function(){for(var t=this.toTables(),e=t.encode(),n=new ArrayBuffer(e.length),r=new Uint8Array(n),c=0;c<e.length;c++)r[c]=e[c];return n};a0.prototype.download=function(t){var e=this.getEnglishName("fontFamily"),n=this.getEnglishName("fontSubfamily");t=t||e.replace(/\s/g,"")+"-"+n+".otf";var r=this.toArrayBuffer();if(Fa())if(window.URL=window.URL||window.webkitURL,window.URL){var c=new DataView(r),a=new Blob([c],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(a),s.download=t;var o=document.createEvent("MouseEvents");o.initEvent("click",!0,!1),s.dispatchEvent(o)}else console.warn("Font file could not be downloaded. Try using a different browser.");else{var i=Nn(),l=Da(r);i.writeFileSync(t,l)}};a0.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};a0.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};a0.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function y8(t,e){var n=JSON.stringify(t),r=256;for(var c in e){var a=parseInt(c);if(!(!a||a<256)){if(JSON.stringify(e[c])===n)return a;r<=a&&(r=a+1)}}return e[r]=t,r}function Jo(t,e,n){var r=y8(e.name,n);return[{name:"tag_"+t,type:"TAG",value:e.tag},{name:"minValue_"+t,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+t,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+t,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+t,type:"USHORT",value:0},{name:"nameID_"+t,type:"USHORT",value:r}]}function Ko(t,e,n){var r={},c=new d1.Parser(t,e);return r.tag=c.parseTag(),r.minValue=c.parseFixed(),r.defaultValue=c.parseFixed(),r.maxValue=c.parseFixed(),c.skip("uShort",1),r.name=n[c.parseUShort()]||{},r}function Qo(t,e,n,r){for(var c=y8(e.name,r),a=[{name:"nameID_"+t,type:"USHORT",value:c},{name:"flags_"+t,type:"USHORT",value:0}],s=0;s<n.length;++s){var o=n[s].tag;a.push({name:"axis_"+t+" "+o,type:"FIXED",value:e.coordinates[o]<<16})}return a}function ei(t,e,n,r){var c={},a=new d1.Parser(t,e);c.name=r[a.parseUShort()]||{},a.skip("uShort",1),c.coordinates={};for(var s=0;s<n.length;++s)c.coordinates[n[s].tag]=a.parseFixed();return c}function ti(t,e){var n=new o1.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:t.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:t.instances.length},{name:"instanceSize",type:"USHORT",value:4+t.axes.length*4}]);n.offsetToData=n.sizeOf();for(var r=0;r<t.axes.length;r++)n.fields=n.fields.concat(Jo(r,t.axes[r],e));for(var c=0;c<t.instances.length;c++)n.fields=n.fields.concat(Qo(c,t.instances[c],t.axes,e));return n}function ni(t,e,n){var r=new d1.Parser(t,e),c=r.parseULong();T1.argument(c===65536,"Unsupported fvar table version.");var a=r.parseOffset16();r.skip("uShort",1);for(var s=r.parseUShort(),o=r.parseUShort(),i=r.parseUShort(),l=r.parseUShort(),h=[],u=0;u<s;u++)h.push(Ko(t,e+a+u*o,n));for(var f=[],d=e+a+s*o,p=0;p<i;p++)f.push(ei(t,d+p*l,h,n));return{axes:h,instances:f}}var ri={make:ti,parse:ni},ci=function(){return{coverage:this.parsePointer(N.coverage),attachPoints:this.parseList(N.pointer(N.uShortList))}},ai=function(){var t=this.parseUShort();if(T1.argument(t===1||t===2||t===3,"Unsupported CaretValue table version."),t===1)return{coordinate:this.parseShort()};if(t===2)return{pointindex:this.parseShort()};if(t===3)return{coordinate:this.parseShort()}},si=function(){return this.parseList(N.pointer(ai))},oi=function(){return{coverage:this.parsePointer(N.coverage),ligGlyphs:this.parseList(N.pointer(si))}},ii=function(){return this.parseUShort(),this.parseList(N.pointer(N.coverage))};function li(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);T1.argument(r===1||r===1.2||r===1.3,"Unsupported GDEF table version.");var c={version:r,classDef:n.parsePointer(N.classDef),attachList:n.parsePointer(ci),ligCaretList:n.parsePointer(oi),markAttachClassDef:n.parsePointer(N.classDef)};return r>=1.2&&(c.markGlyphSets=n.parsePointer(ii)),c}var hi={parse:li},y2=new Array(10);y2[1]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();if(n===1)return{posFormat:1,coverage:this.parsePointer(N.coverage),value:this.parseValueRecord()};if(n===2)return{posFormat:2,coverage:this.parsePointer(N.coverage),values:this.parseValueRecordList()};T1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};y2[2]=function(){var e=this.offset+this.relativeOffset,n=this.parseUShort();T1.assert(n===1||n===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer(N.coverage),c=this.parseUShort(),a=this.parseUShort();if(n===1)return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,pairSets:this.parseList(N.pointer(N.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}})))};if(n===2){var s=this.parsePointer(N.classDef),o=this.parsePointer(N.classDef),i=this.parseUShort(),l=this.parseUShort();return{posFormat:n,coverage:r,valueFormat1:c,valueFormat2:a,classDef1:s,classDef2:o,class1Count:i,class2Count:l,classRecords:this.parseList(i,N.list(l,function(){return{value1:this.parseValueRecord(c),value2:this.parseValueRecord(a)}}))}}};y2[3]=function(){return{error:"GPOS Lookup 3 not supported"}};y2[4]=function(){return{error:"GPOS Lookup 4 not supported"}};y2[5]=function(){return{error:"GPOS Lookup 5 not supported"}};y2[6]=function(){return{error:"GPOS Lookup 6 not supported"}};y2[7]=function(){return{error:"GPOS Lookup 7 not supported"}};y2[8]=function(){return{error:"GPOS Lookup 8 not supported"}};y2[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function ui(t,e){e=e||0;var n=new N(t,e),r=n.parseVersion(1);return T1.argument(r===1||r===1.1,"Unsupported GPOS table version "+r),r===1?{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(y2)}:{version:r,scripts:n.parseScriptList(),features:n.parseFeatureList(),lookups:n.parseLookupList(y2),variations:n.parseFeatureVariationsList()}}var fi=new Array(10);function di(t){return new o1.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new o1.ScriptList(t.scripts)},{name:"features",type:"TABLE",value:new o1.FeatureList(t.features)},{name:"lookups",type:"TABLE",value:new o1.LookupList(t.lookups,fi)}])}var mi={parse:ui,make:di};function pi(t){var e={};t.skip("uShort");var n=t.parseUShort();T1.argument(n===0,"Unsupported kern sub-table version."),t.skip("uShort",2);var r=t.parseUShort();t.skip("uShort",3);for(var c=0;c<r;c+=1){var a=t.parseUShort(),s=t.parseUShort(),o=t.parseShort();e[a+","+s]=o}return e}function gi(t){var e={};t.skip("uShort");var n=t.parseULong();n>1&&console.warn("Only the first kern subtable is supported."),t.skip("uLong");var r=t.parseUShort(),c=r&255;if(t.skip("uShort"),c===0){var a=t.parseUShort();t.skip("uShort",3);for(var s=0;s<a;s+=1){var o=t.parseUShort(),i=t.parseUShort(),l=t.parseShort();e[o+","+i]=l}}return e}function vi(t,e){var n=new d1.Parser(t,e),r=n.parseUShort();if(r===0)return pi(n);if(r===1)return gi(n);throw new Error("Unsupported kern table version ("+r+").")}var yi={parse:vi};function bi(t,e,n,r){for(var c=new d1.Parser(t,e),a=r?c.parseUShort:c.parseULong,s=[],o=0;o<n+1;o+=1){var i=a.call(c);r&&(i*=2),s.push(i)}return s}var xi={parse:bi};function A7(t,e){for(var n=[],r=12,c=0;c<e;c+=1){var a=d1.getTag(t,r),s=d1.getULong(t,r+4),o=d1.getULong(t,r+8),i=d1.getULong(t,r+12);n.push({tag:a,checksum:s,offset:o,length:i,compression:!1}),r+=16}return n}function Mi(t,e){for(var n=[],r=44,c=0;c<e;c+=1){var a=d1.getTag(t,r),s=d1.getULong(t,r+4),o=d1.getULong(t,r+8),i=d1.getULong(t,r+12),l=void 0;o<i?l="WOFF":l=!1,n.push({tag:a,offset:s,compression:l,compressedLength:o,length:i}),r+=20}return n}function k0(t,e){if(e.compression==="WOFF"){var n=new Uint8Array(t.buffer,e.offset+2,e.compressedLength-2),r=new Uint8Array(e.length);if(dc(n,r),r.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var c=new DataView(r.buffer,0);return{data:c,offset:0}}else return{data:t,offset:e.offset}}function b8(t,e){e=e??{};var n,r,c=new a0({empty:!0}),a=new DataView(t,0),s,o=[],i=d1.getTag(a,0);if(i==="\0\0\0"||i==="true"||i==="typ1")c.outlinesFormat="truetype",s=d1.getUShort(a,4),o=A7(a,s);else if(i==="OTTO")c.outlinesFormat="cff",s=d1.getUShort(a,4),o=A7(a,s);else if(i==="wOFF"){var l=d1.getTag(a,4);if(l==="\0\0\0")c.outlinesFormat="truetype";else if(l==="OTTO")c.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+i);s=d1.getUShort(a,12),o=Mi(a,s)}else throw new Error("Unsupported OpenType signature "+i);for(var h,u,f,d,p,m,g,v,b,y,x,w,M=0;M<s;M+=1){var k=o[M],z=void 0;switch(k.tag){case"cmap":z=k0(a,k),c.tables.cmap=O7.parse(z.data,z.offset),c.encoding=new R7(c.tables.cmap);break;case"cvt ":z=k0(a,k),w=new d1.Parser(z.data,z.offset),c.tables.cvt=w.parseShortList(k.length/2);break;case"fvar":u=k;break;case"fpgm":z=k0(a,k),w=new d1.Parser(z.data,z.offset),c.tables.fpgm=w.parseByteList(k.length);break;case"head":z=k0(a,k),c.tables.head=W7.parse(z.data,z.offset),c.unitsPerEm=c.tables.head.unitsPerEm,n=c.tables.head.indexToLocFormat;break;case"hhea":z=k0(a,k),c.tables.hhea=X7.parse(z.data,z.offset),c.ascender=c.tables.hhea.ascender,c.descender=c.tables.hhea.descender,c.numberOfHMetrics=c.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":z=k0(a,k),r=Y7.parse(z.data,z.offset);break;case"maxp":z=k0(a,k),c.tables.maxp=J7.parse(z.data,z.offset),c.numGlyphs=c.tables.maxp.numGlyphs;break;case"name":y=k;break;case"OS/2":z=k0(a,k),c.tables.os2=bt.parse(z.data,z.offset);break;case"post":z=k0(a,k),c.tables.post=r8.parse(z.data,z.offset),c.glyphNames=new St(c.tables.post);break;case"prep":z=k0(a,k),w=new d1.Parser(z.data,z.offset),c.tables.prep=w.parseByteList(k.length);break;case"glyf":f=k;break;case"loca":b=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":p=k;break;case"GSUB":m=k;break;case"meta":x=k;break}}var A=k0(a,y);if(c.tables.name=n8.parse(A.data,A.offset,r),c.names=c.tables.name,f&&b){var S=n===0,C=k0(a,b),I=xi.parse(C.data,C.offset,c.numGlyphs,S),L=k0(a,f);c.glyphs=h8.parse(L.data,L.offset,I,c,e)}else if(h){var T=k0(a,h);G7.parse(T.data,T.offset,c,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var q=k0(a,g);if(Z7.parse(c,q.data,q.offset,c.numberOfHMetrics,c.numGlyphs,c.glyphs,e),Hc(c,e),v){var P=k0(a,v);c.kerningPairs=yi.parse(P.data,P.offset)}else c.kerningPairs={};if(d){var F=k0(a,d);c.tables.gdef=hi.parse(F.data,F.offset)}if(p){var j=k0(a,p);c.tables.gpos=mi.parse(j.data,j.offset),c.position.init()}if(m){var _=k0(a,m);c.tables.gsub=c8.parse(_.data,_.offset)}if(u){var Q=k0(a,u);c.tables.fvar=ri.parse(Q.data,Q.offset,c.names)}if(x){var H=k0(a,x);c.tables.meta=a8.parse(H.data,H.offset),c.metas=c.tables.meta}return c}function x8(t,e){let n=t.tables?.os2?.sCapHeight;if(n&&n>0)return n/t.unitsPerEm*e;let r=w0(It(t,"H",{size:e,font:"",halign:"left",valign:"baseline",spacing:1}).polys);return r?r[3]:t.ascender/t.unitsPerEm*e}var Xe=class{constructor(e,n){this.sources=e;this.fallback=n;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let n=e||this.fallback||Object.keys(this.sources)[0];if(!n)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let r=this.parsed.get(n);if(r)return r;let c=K0(this.sources,n);if(!c)throw this.missing.add(n),new Error(`Font "${n}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let a=c instanceof Uint8Array?c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength):c,s=b8(a);return this.parsed.set(n,s),s}};function wi(t,e,n){let r={kerning:!0};if(n.spacing===1)return{cmds:t.getPath(e,0,0,n.size,r).commands,advance:t.getAdvanceWidth(e,n.size,r)};let c=[],a=0,s=[...e];return s.forEach((o,i)=>{c.push(...t.getPath(o,a,0,n.size,r).commands),a+=t.getAdvanceWidth(o,n.size,r)*(i<s.length-1?n.spacing:1)}),{cmds:c,advance:a}}function It(t,e,n){let{cmds:r,advance:c}=wi(t,e,n),a=r.map(o=>o.type==="Z"?o:o.type==="C"?{...o,y1:-o.y1,y2:-o.y2,y:-o.y}:o.type==="Q"?{...o,y1:-o.y1,y:-o.y}:{...o,y:-o.y}),s=G3(a,Math.max(.005,n.size/2e3));return{polys:[...s.closed,...s.open.filter(o=>o.length>=3)],advance:c}}function Ze(t,e,n){if(!e)return[];let r=t.get(n.font),{polys:c,advance:a}=It(r,e,n),s=s1(c),o=w0(s);if(!o)return[];let i=n.halign==="center"?-a/2:n.halign==="right"?-a:0,l=n.valign==="top"?-o[3]:n.valign==="center"?-(o[1]+o[3])/2:n.valign==="bottom"?-o[1]:n.valign==="cap"?-x8(r,n.size)/2:0;return s.map(h=>h.map(([u,f])=>[u+i,f+l]))}function Vt(t,e,n){let r=t.get(n.font),{polys:c,advance:a}=It(r,e,n),s=w0(c)??[0,0,0,0];return{advance:a,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:r.ascender/r.unitsPerEm*n.size,descent:r.descender/r.unitsPerEm*n.size,cap:x8(r,n.size)}}var M8=Math.PI/180,Ht=128,Z5=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],Dt={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function ki(t,e){if(!t||K0(Ft,t)!==void 0)return;let n=t.split("\\").join("/"),r=e.split("\\").join("/");if(r.startsWith("/")||/^[A-Za-z]:\//.test(r))return;let c=n.lastIndexOf("/");if(c<0)return;let a=[...n.slice(0,c).split("/"),...r.split("/")],s=[];for(let o of a)o===".."&&s.length&&s[s.length-1]!==".."?s.pop():o!=="."&&o!==""&&s.push(o);return(n.startsWith("/")?"/":"")+s.join("/")}var zi=100,Si={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},t5=4,w8=8,Ai=t=>{let e=zi,n=r=>{for(let c of r.values()){for(let a of c.regions)e+=a.length;for(let a of c.lines)e+=a.length}};n(t.layers);for(let r of t.parts)n(r.layers);return e},E0=class{constructor(e,n){this.parent=e;this.caller=n;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let n=this,r=e.startsWith("$");for(;n;){if(n.vars.has(e))return{found:!0,value:n.vars.get(e)};n=r?n.caller??n.parent:n.parent}return{found:!1}}fn(e){for(let n=this;n;n=n.parent){let r=n.fns.get(e);if(r)return r}}mod(e){for(let n=this;n;n=n.parent){let r=n.mods.get(e);if(r)return r}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let n=[];for(let r=this;r;r=r.parent)n.push(...r[e].keys());return n}},Ot=t=>t?`.${t}`:"",$t=(t,e)=>t==="module"?`Recursion too deep in module ${e}(): check that it stops`:`Recursion too deep in ${e}(): check that it stops, or use fold(), scan() or a list comprehension to go through a long list`,Li={color:"its children are drawn as they are. Use cut(), score(), engrave() or layer() to choose how they are cut.",linear_extrude:"its children are drawn flat, as the part outline. A part takes its height from $thickness."},Rt=["echo","assert","text_width","text_metrics","text_size","finger_count"];function A3(t,e){let n="",r=Math.min(2,Math.floor(t.length/3))+.5;for(let c of new Set(e)){if(c===t)continue;let a=c.toLowerCase()===t.toLowerCase()?0:Ci(t,c);a<r&&([n,r]=[c,a])}return n?` Did you mean "${n}"?`:""}function Ci(t,e){if(Math.abs(t.length-e.length)>2)return 3;let n=Array.from({length:t.length+1},(r,c)=>[c,...Array(e.length).fill(0)]);for(let r=1;r<=e.length;r++)n[0][r]=r;for(let r=1;r<=t.length;r++)for(let c=1;c<=e.length;c++)n[r][c]=Math.min(n[r-1][c]+1,n[r][c-1]+1,n[r-1][c-1]+(t[r-1]===e[c-1]?0:1)),r>1&&c>1&&t[r-1]===e[c-2]&&t[r-2]===e[c-1]&&(n[r][c]=Math.min(n[r][c],n[r-2][c-2]+1));return n[t.length][e.length]}var Ft=R5,o3=class{constructor(e={}){this.opts=e;this.steps=0;this.depth=0;this.occluding=0;this.pointCount=0;this.itemCount=0;this.retained=0;this.copies=0;this.layerDefs=0;this.frame=B4;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(Z5.map(e=>[e.name,e]));this.loaded=new Map;this.clashed=new Set;this.childCache=new WeakMap;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...Dt,...e.limits},this.builtins=this.makeBuiltins()}run(e){let n=new E0,r={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[o,i]of Object.entries(r))n.vars.set(o,i);let c=new E0(n),a=this.block(e.body,c,!0),s=c.vars.get("$scale");return this.unscaled&&s!==void 0&&s!==1&&this.warn(`A length with a unit comes before $scale is set, so it is not scaled; set $scale first (${c2(this.unscaled,!1)})`),{shape:a,globals:c,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,n=1){if(!((this.steps+=n)<=this.maxSteps))throw new i1(`Stopped after ${this.maxSteps} steps. Is there an endless loop, or more work than one program may do (a long list, a fine spacing)?`,e)}load(e,n){let r=ki(n.file,e),c=e,a=K0(Ft,e);if(a===void 0&&r!==void 0){let o=this.loaded.get(r);if(o)return o;a=this.opts.resolve?.(r),typeof a=="string"&&(c=r)}if(c===e){let o=this.loaded.get(e);if(o)return o;a??(a=this.opts.resolve?.(e))}if(typeof a!="string")throw new i1(`Library <${e}> not found`,n);this.loaded.set(c,{body:[]});let{program:s}=e2(a,c);return this.loaded.set(c,s),s}hoist(e,n){for(let r of e)if((r.kind==="module"||r.kind==="function")&&(r.pos.file===void 0||K0(Ft,r.pos.file)===void 0)&&(r.kind==="module"?K0(this.builtins,r.name)!==void 0:K0(H5,r.name)!==void 0||Rt.includes(r.name))&&this.warn(`${r.kind} ${r.name} hides the built-in ${r.name}(); rename it to use both (${c2(r.pos,!1)})`),r.kind==="module")n.mods.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="function")n.fns.set(r.name,{params:r.params,body:r.body,env:n,pos:r.pos});else if(r.kind==="use"&&!r.include){this.enter(this.using,r.path,r.pos,"use");try{let c=this.included(this.load(r.path,r.pos).body,new Set([r.path])),a=new E0(n);this.hoist(c,a);for(let s of c)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,a),a);for(let[s,o]of a.mods)this.clash("module",s,n.mods.get(s),o),n.mods.set(s,o);for(let[s,o]of a.fns)this.clash("function",s,n.fns.get(s),o),n.fns.set(s,o)}finally{this.using.pop()}}}clash(e,n,r,c){!r||r.body===c.body||!r.pos?.file||!c.pos?.file||r.pos.file===c.pos.file||this.clashed.has(`${e} ${n}`)||(this.clashed.add(`${e} ${n}`),this.warn(`${e} ${n} is defined in <${r.pos.file}> (line ${r.pos.line}) and in <${c.pos.file}> (line ${c.pos.line}); the one in <${c.pos.file}> is used. Rename one to use both.`))}childKey(e){let n=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[u,f]of l.vars)u.startsWith("$")&&!n.has(u)&&n.set(u,f)})(e,0);let c=[...n].sort(([l],[h])=>l<h?-1:1),a=[],s=0,o=[];for(let l=c.length-1;l>=0;l--)o.push({text:";"},c[l][1],{text:`${c[l][0]}=`});for(;o.length;){if(s>2e4)return"";let l=o.pop(),h;if(l&&typeof l=="object"&&"text"in l&&!Array.isArray(l))h=l.text;else if(typeof l=="number")h=Object.is(l,-0)?"-0":String(l);else if(typeof l=="string")h=JSON.stringify(l);else if(l===void 0||typeof l=="boolean")h=String(l);else if(Array.isArray(l)){o.push({text:"]"});for(let u=l.length-1;u>=0;u--)o.push(l[u],{text:","});h="["}else if(h2(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(G0(l)){o.push({text:"}"});let u=[...l.fields];for(let f=u.length-1;f>=0;f--)o.push(u[f][1],{text:`${u[f][0]}=`});h="{"}else return"";a.push(h),s+=h.length}let i=a.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${this.layerDefs}|${i}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies},${this.layerDefs}`}enter(e,n,r,c){if(e.includes(n)){let a=[...e.slice(e.indexOf(n)),n].map(s=>`<${s}>`);throw new i1(a.length===2?`Library ${a[0]} ${c}s itself`:`Libraries ${c} each other in a loop: ${a.join(" \u2192 ")}`,r)}e.push(n)}included(e,n){let r=[];for(let c of e)if(c.kind!=="use"||!c.include)r.push(c);else if(!n.has(c.path)){n.add(c.path);for(let a of this.included(this.load(c.path,c.pos).body,n))r.push(a)}return r}assign(e,n,r){r.vars.set(e,n)}block(e,n,r=!1){this.hoist(e,n);let c=[];for(let a of e){let s=this.stmt(a,n,r);s&&!W6(s)&&c.push(s)}return c.length===1?c[0]:C2(c)}stmt(e,n,r=!1){switch(this.tick(e.pos),e.kind){case"assign":{let c=this.opts.overrides,a=r&&c&&Object.prototype.hasOwnProperty.call(c,e.name)?c[e.name]:this.expr(e.value,n);return this.assign(e.name,a,n),null}case"module":case"function":return null;case"use":{if(!e.include)return null;this.enter(this.including,e.path,e.pos,"include");try{return this.block(this.load(e.path,e.pos).body,n)}finally{this.including.pop()}}case"block":return this.block(e.body,new E0(n));case"if":return y0(this.expr(e.cond,n))?this.block(e.then,new E0(n)):this.block(e.else,new E0(n));case"let":{let c=new E0(n);return this.bindSeq(e.assigns,c),this.block(e.body,c)}case"for":{let c=[];return this.loop(e.assigns,n,a=>c.push(this.block(e.body,a))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:n,children:()=>C2(c),childList:()=>c,childSeq:()=>c,childItems:()=>c}):C2(c)}case"call":if(e.modifier==="*")return null;{let c=this.callModule(e,n);return e.modifier==="#"||e.modifier==="%"?C5(c,"guide"):c}}}bindSeq(e,n){for(let r of e)this.assign(r.name,this.expr(r.value,n),n)}iterable(e,n){if(h2(e))try{return Ce(e,this.limits.maxListLength)}catch(r){throw new i1(r.message,n)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,n,r,c=0,a=new E0(n)){if(c===e.length)return r(a);let s=e[c];for(let o of this.iterable(this.expr(s.value,a),s.pos)){this.tick(s.pos);let i=new E0(a);i.vars.set(s.name,o),this.loop(e,n,r,c+1,i)}}evalArgs(e,n,r){let c=[],a=new Map,s=[];for(let o of e){let i=this.expr(o.value,n);o.name===null?c.push(i):a.set(o.name,i),s.push({name:o.name,value:i})}return{pos:c,named:a,all:s,at:r}}bindParams(e,n,r,c,a){let s=e.map(o=>o.name);for(let[o,i]of n.named)o.startsWith("$")&&r.vars.set(o,i);e.forEach((o,i)=>{let l;n.named.has(o.name)?l=n.named.get(o.name):i<n.pos.length?l=n.pos[i]:l=o.default?this.expr(o.default,r):void 0,r.vars.set(o.name,l)});for(let o of n.named.keys())!o.startsWith("$")&&!s.includes(o)&&this.unknownArg(a,o,n.at,s);this.checkCount(a,e.length,n)}checkArgs(e,n){let r=Z3(e);if(!r)return;let c=r.params.map(a=>a.name);if(!r.anyNamed)for(let a of n.named.keys())!a.startsWith("$")&&!c.includes(a)&&this.unknownArg(`${e}()`,a,n.at,c);r.rest||this.checkCount(`${e}()`,r.params.filter(a=>!a.named).length,n)}checkCount(e,n,r){r.pos.length>n&&this.warn(`${e}: takes ${n===0?"no":`at most ${n}`} positional argument${n===1?"":"s"}, got ${r.pos.length}; the rest are ignored (${c2(r.at,!1)})`)}unknownArg(e,n,r,c){this.warn(`${e}: unknown argument "${n}"${Ot(A3(n,c))} (${c2(r,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,n){let r=e.args.findIndex(s=>s.name==="name"),c=r>=0?r:e.args.findIndex(s=>s.name===null);if(c<0)throw new i1("call() needs the name of a module",e.pos);let a=this.expr(e.args[c].value,n);if(typeof a!="string")throw new i1(`call() needs a module's name as a string, got ${D0(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,o)=>o!==c)},n)}callModule(e,n){if(e.name==="call"&&!n.mod("call"))return this.callByName(e,n);let r=this.evalArgs(e.args,n,e.pos),c=n.mod(e.name);if(c){if(++this.depth>1e3)throw new i1($t("module",e.name),e.pos);try{let d=new E0(c.env,n);return this.bindParams(c.params,r,d,c.env,`${e.name}()`),d.children={stmts:e.children,env:n,module:e.name,pos:e.pos},d.vars.set("$children",this.childStmts(e.children).length),this.block(c.body,d)}catch(d){throw this.inCall(d,"module",e.name,e.pos)}finally{this.depth--}}let a=K0(this.builtins,e.name),s=K0(Li,e.name);if(!a&&s)return this.warn(`${e.name}() is ignored: ${s} (${c2(e.pos,!1)})`),e.children.length?this.block(e.children,new E0(n,n)):T0();if(!a){let d=A3(e.name,[...n.names("mods"),...Object.keys(this.builtins)]);throw new i1(`Unknown module ${e.name}().${d}`,e.pos)}this.checkArgs(e.name,r);let o=new E0(n,n);for(let[d,p]of r.named)d.startsWith("$")&&o.vars.set(d,p);let i=this.childStmts(e.children),l=()=>new E0(n,o),h={args:r,env:o,children:()=>e.children.length?this.block(e.children,l()):T0(),childList:()=>{let d=l();this.hoist(e.children,d);let p=[];for(let m of e.children){let g=this.stmt(m,d);i.includes(m)&&p.push(g??T0())}return p},childItems:()=>{let d=l();this.hoist(e.children,d);let p=[];for(let m of e.children){if(i.includes(m)&&m.kind==="for"&&!m.intersect){this.tick(m.pos),this.loop(m.assigns,d,v=>p.push(this.block(m.body,v)));continue}let g=this.stmt(m,d);i.includes(m)&&p.push(g??T0())}return p},childSeq:d=>{let p=l();this.hoist(e.children,p);let m=[];for(let g of e.children){let v=this.stmt(g,p);i.includes(g)&&(m.push(v??T0()),d(m.length-1,v??T0()))}return m}},u;try{u=a(h)}catch(d){if(d instanceof i1||d instanceof RangeError)throw d;let p=new i1(`${e.name}(): ${d.message}`,e.pos);throw p.call=e.name,p}let f=Ai(u);if(e.name!=="children"&&(this.pointCount+=f),f>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new i1(f>this.limits.maxPoints?`The shapes have more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes, or a lower $fn.`:`Making the shapes took more than ${this.limits.maxPoints*10} points of work, the limit. Use fewer or simpler shapes, or a lower $fn.`,e.pos);return u}childStmts(e){return e.filter(n=>n.kind!=="assign"&&n.kind!=="module"&&n.kind!=="function"&&n.kind!=="use")}callFunction(e,n,r,c){if(++this.depth>2e3)throw new i1($t("function",c),n.at);try{this.tick(n.at);let a=p2(e)?e.scope:e.env,s=new E0(a,r);return this.bindParams(e.params,n,s,a,`${c}()`),this.expr(e.body,s)}catch(a){throw this.inCall(a,"function",c,n.at)}finally{this.depth--}}inCall(e,n,r,c){return e instanceof Error&&!(e instanceof i1)&&e.message.includes("call stack")?new i1($t(n,r),c):(e instanceof i1&&e.addFrame(n,r,c),e)}expr(e,n){switch(e.kind){case"num":return e.unit?this.length(e,n):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{let r=n.get(e.name);if(r.found)return r.value;let c=n.fn(e.name);if(c)return{type:"function",params:c.params,body:c.body,scope:c.env,name:e.name};if(e.name.startsWith("$"))return;throw new i1(`Unknown variable "${e.name}"${Ot(A3(e.name,[...n.names("vars"),...n.names("fns")]))}`,e.pos)}case"list":{let r=[];for(let c of e.items)this.listItem(c,n,r,e.pos);return this.charge(t5,e.pos),r}case"range":{let r=this.expr(e.start,n),c=this.expr(e.end,n),a=e.step?this.expr(e.step,n):1;if(typeof r!="number"||typeof c!="number"||typeof a!="number")throw new i1("Range values must be numbers",e.pos);return{type:"range",start:r,step:a,end:c}}case"unary":{let r=this.expr(e.arg,n);return e.op==="!"?!y0(r):e.op==="+"?r:this.arith("*",-1,r,e.pos)}case"binary":{if(e.op==="&&")return y0(this.expr(e.left,n))&&y0(this.expr(e.right,n));if(e.op==="||")return y0(this.expr(e.left,n))||y0(this.expr(e.right,n));let r=this.expr(e.left,n),c=this.expr(e.right,n);if(e.op==="=="||e.op==="!=")return _3(r,c,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof r=="number"&&typeof c=="number"||typeof r=="string"&&typeof c=="string"))throw new i1(`Can't compare ${D0(r)} ${e.op} ${D0(c)}`,e.pos);return e.op==="<"?r<c:e.op==="<="?r<=c:e.op===">"?r>c:r>=c}return this.arith(e.op,r,c,e.pos)}case"ternary":return y0(this.expr(e.cond,n))?this.expr(e.then,n):this.expr(e.else,n);case"index":{let r=this.expr(e.target,n),c=this.expr(e.index,n);if(G0(r)&&typeof c=="string")return r.fields.get(c);if(typeof c!="number")throw new i1(`List index must be a number, got ${D0(c)}`,e.pos);return Array.isArray(r)?r[Math.floor(c)]:typeof r=="string"?[...r][Math.floor(c)]:h2(r)?[r.start,r.step,r.end][Math.floor(c)]:void 0}case"record":return this.record(e,n);case"member":{let r=this.expr(e.target,n);if(G0(r))return r.fields.get(e.name);let c={x:0,y:1,z:2}[e.name];return Array.isArray(r)&&c!==void 0?r[c]:h2(r)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?r.start:e.name==="step"?r.step:r.end:void 0}case"call":return this.call(e,n);case"lambda":return{type:"function",params:e.params,body:e.body,scope:n};case"let":{let r=new E0(n);return this.bindSeq(e.assigns,r),this.expr(e.body,r)}case"chain":return this.expr(e.check,n),this.expr(e.body,n)}}listItem(e,n,r,c){switch(e.kind){case"item":{let a=this.expr(e.expr,n);this.grow(r,1,c),r.push(a);return}case"each":{let a=this.iterable(this.expr(e.expr,n),c);this.grow(r,a.length,c);for(let s of a)r.push(s);return}case"for":this.loop(e.assigns,n,a=>this.listItem(e.body,a,r,c));return;case"if":y0(this.expr(e.cond,n))?this.listItem(e.then,n,r,c):e.else&&this.listItem(e.else,n,r,c);return;case"let":{let a=new E0(n);this.bindSeq(e.assigns,a),this.listItem(e.body,a,r,c)}}}grow(e,n,r){if(e.length+n>this.limits.maxListLength)throw new i1(`a list of ${e.length+n} items is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n,r)}charge(e,n){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new i1(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,n)}call(e,n){if(e.callee.kind==="var"){let c=e.callee.name,a=n.get(c),s=a.found&&!p2(a.value);if(!a.found||s&&this.callable(c,n)){let o=n.fn(c);if(o)return this.callFunction(o,this.evalArgs(e.args,n,e.pos),n,c);let i=this.specialFunction(c,e,n);if(i.handled)return i.value;let l=K0(H5,c);if(l){let h=this.evalArgs(e.args,n,e.pos);this.checkArgs(c,h);for(let p of Vn(l,h.pos,h.named))this.warn(`${c}(): "${p}" is given by position and by name; the named value is used (${c2(e.pos,!1)})`);let u={maxLength:this.limits.maxListLength,step:p=>this.tick(e.pos,p),given:h.pos.length+l.params.filter(p=>h.named.has(p)).length,apply:(p,m)=>{if(!p2(p))throw new Error(`${c}() needs a function, got ${D0(p)}`);return this.callFunction(p,{pos:m,named:new Map,all:m.map(g=>({name:null,value:g})),at:e.pos},n,"function")}},f=Hn(l,h.pos,h.named);this.tick(e.pos,On(c,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?`${c}(): the result is too large`:p.message,e.pos);throw m.call=c,m}return this.checkValue(d,e.pos,c),d}throw new i1(`Unknown function ${c}()${Ot(A3(c,[...n.names("fns"),...n.names("vars"),...Object.keys(H5),...Rt]))}`,e.pos)}if(!p2(a.value))throw new i1(`"${c}" is a ${D0(a.value)}, not a function`,e.pos);return this.callFunction(a.value,this.evalArgs(e.args,n,e.pos),n,c)}let r=this.expr(e.callee,n);if(!p2(r))throw new i1(`Can't call a ${D0(r)}`,e.pos);return this.callFunction(r,this.evalArgs(e.args,n,e.pos),n,"function")}invisiblePaint(e,n,r,c){let a=s=>Array.isArray(r)?String(r[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!n[s]?.length)continue;let o=a(s),i=s1(e.flatMap((h,u)=>u<s&&a(u)===o?n[u]:[]));!i.length||g0(n[s],i).reduce((h,u)=>h+Math.abs(b1(u)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(r)&&o?` "${o}"`:""} under it, so it can't be seen (${c2(c,!1)})`)}}record(e,n){let r=new Map;for(let c of e.fields)r.set(c.name,this.expr(c.value,n));return{type:"record",fields:r}}length(e,n){let r=U0(n.get("$scale").value??1);if(!(r>0))throw new i1("$scale must be a number more than 0",e.pos);return r===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Si[e.unit]/r}callable(e,n){return!!n.fn(e)||Rt.includes(e)||!!K0(H5,e)}specialFunction(e,n,r){if(e==="echo"){let c=this.evalArgs(n.args,r,n.pos);return this.echo(this.echoText(c),n.pos),{handled:!0,value:void 0}}if(e==="assert"){let c=this.evalArgs(n.args,r,n.pos);return this.checkArgs(e,c),this.assert(c),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"||e==="text_size"){let c=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,c);let a=this.measure(c,r);return e==="text_width"?{handled:!0,value:a.advance}:e==="text_size"?{handled:!0,value:{type:"record",fields:new Map([["width",a.advance],["height",a.bounds[1][1]-a.bounds[0][1]],["bounds",a.bounds],["cap",a.cap],["ascent",a.ascent],["descent",a.descent],["size",a.size]])}}:{handled:!0,value:[a.advance,a.bounds,a.ascent,a.descent]}}if(e==="finger_count"){let c=this.evalArgs(n.args,r,n.pos);this.checkArgs(e,c);let a=this.num(this.arg(c,"length",0),"finger_count","length");return{handled:!0,value:x3(a,this.fingerWidth(c,r,1))}}return{handled:!1}}assert(e){if(y0(this.arg(e,"condition",0)))return;let n=this.arg(e,"message",1);throw new i1(`Assertion failed${n===void 0?"":": "+b0(n)}`,e.at)}echo(e,n){let r=Math.ceil(e.length/w8);this.charge(r,n),this.retained+=r,this.echoes.push(e)}echoText(e){let n=this.limits.maxListLength,r=[],c=0,a=(s,o,i)=>{r.length&&(c+=2);let l=j3(o,n-c-s.length,i);if(c+=s.length+l.text.length,!l.whole)throw new i1(`echo(): the text would be longer than the limit of ${n} characters`,e.at);r.push(s+l.text)};for(let{name:s,value:o}of e.all)s===null?a("",o,!1):a(`${s} = `,o,!0);return r.join(", ")}arith(e,n,r,c){if(typeof n=="number"&&typeof r=="number")switch(e){case"+":return n+r;case"-":return n-r;case"*":return n*r;case"/":return n/r;case"%":return n%r;case"^":return Math.pow(n,r)}if(e==="+"&&typeof n=="string"&&typeof r=="string")return this.checkSize(n.length+r.length,!0,c),n+r;if(Array.isArray(n)&&Array.isArray(r)){if(e==="+"||e==="-"){if(n.length!==r.length)throw new i1(`Can't ${e==="+"?"add":"subtract"} lists of length ${n.length} and ${r.length}`,c);return this.charge(n.length+t5,c),n.map((s,o)=>this.arith(e,s,r[o],c))}if(e==="*"){if(Array.isArray(n[0]))return this.charge(n.length+t5,c),n.map(o=>this.arith("*",o,r,c));let s=(o,i)=>{let l=this.arith("*",o,i,c);if(typeof l!="number")throw new i1("Can't multiply these lists: an item times an item is not a number",c);return l};if(Array.isArray(r[0])){let o=r[0].length;if(n.length!==r.length||r.some(i=>!Array.isArray(i)||i.length!==o))throw new i1(`Can't multiply a list of length ${n.length} by a matrix: it needs ${n.length} rows of the same length`,c);return this.checkSize(o,!1,c),this.tick(c,o*n.length),Array.from({length:o},(i,l)=>n.reduce((h,u,f)=>h+s(u,r[f][l]),0))}if(n.length!==r.length)throw new i1(`Can't multiply lists of length ${n.length} and ${r.length}`,c);return this.tick(c,n.length),n.reduce((o,i,l)=>o+s(i,r[l]),0)}}if(Array.isArray(n)&&typeof r=="number"&&(e==="*"||e==="/"))return this.charge(n.length+t5,c),n.map(s=>this.arith(e,s,r,c));if(typeof n=="number"&&Array.isArray(r)&&e==="*")return this.charge(r.length+t5,c),r.map(s=>this.arith(e,n,s,c));let a={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new i1(`Can't ${a[e]??e} ${D0(n)} and ${D0(r)}`,c)}fieldFn(e,n,r,c){if(!p2(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${C0(e)}`);return a=>{let s=this.itemCount,o=this.retained,i=this.callFunction(e,{pos:[a],named:new Map,all:[{name:null,value:a}],at:c},r,"field");return(!Array.isArray(i)||i.length<=3)&&(this.itemCount=s+this.retained-o),i}}arg(e,n,r,c){return e.named.has(n)?e.named.get(n):r>=0&&r<e.pos.length?e.pos[r]:c}num(e,n,r){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${r} must be a finite number, got ${C0(e)}`);return e}vec2(e,n,r=!0){let c=a=>typeof a=="number"&&Number.isFinite(a);if(c(e)&&r)return[e,e];if(Array.isArray(e)&&c(e[0])&&(e[1]===void 0||c(e[1])))return[e[0],e[1]??0];throw new Error(`${n} must be a number or [x, y], got ${C0(e)}`)}vec3(e,n){let r=c=>typeof c=="number"&&Number.isFinite(c);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(r))return[e[0],e[1],e[2]??0];throw new Error(`${n} must be [x, y, z], got ${C0(e)}`)}placements(e,n,r){let c=(o,i)=>o===void 0?[[0,0,0]]:Array.isArray(o)&&o.length>0&&Array.isArray(o[0])?o.map((l,h)=>this.vec3(l,`${i}[${h}]`)):[this.vec3(o,i)],a=c(e,"at"),s=c(n,"rotate");for(let[o,i]of[[a,"at"],[s,"rotate"]])if(o.length!==1&&o.length!==r)throw new Error(`${i} needs one placement per copy: qty is ${r} but ${i} has ${o.length}`);return Array.from({length:r},(o,i)=>({at:a[a.length===1?0:i],rotate:s[s.length===1?0:i]}))}points(e,n){if(!Array.isArray(e))throw new Error(`${n} must be a list of [x, y] points`);return e.map((r,c)=>{if(!Array.isArray(r)||!Number.isFinite(r[0])||!Number.isFinite(r[1]))throw new Error(`${n}[${c}] must be an [x, y] point, got ${C0(r)}`);return[r[0],r[1]]})}dyn(e,n){return e.get(n).value}spend(e){if(this.pointCount+=e,!(e<=this.limits.maxPoints&&this.pointCount<=this.limits.maxPoints*10))throw new Error(`the shapes need more than ${this.limits.maxPoints} points, the limit. Use fewer or simpler shapes.`)}checkValue(e,n,r){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",n,r)}checkSize(e,n,r,c){if(e>this.limits.maxListLength)throw new i1(`${c?`${c}(): `:""}${n?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,r);this.charge(n?Math.ceil(e/w8):e+t5,r)}segs(e){let n=U0(this.dyn(e,"$fn"))||0,r=U0(this.dyn(e,"$fa"))||2,c=U0(this.dyn(e,"$fs"))||.2,a=this.limits.maxSegments;return s=>{let o=Y6(s,n,r,c);if(!(o<=a))throw new Error(`a circle with ${o} segments is more than the limit of ${a}. Lower $fn, or raise $fa or $fs.`);return o}}thickness(e){let n=this.dyn(e,"$thickness");if(typeof n!="number"||n<=0)throw new Error("$thickness must be a positive number");return n}fingerWidth(e,n,r){let c=this.arg(e,"finger",r);return typeof c=="number"&&c>0?c:Math.max(3*this.thickness(n),6)}measure(e,n){if(!this.opts.fonts)throw new i1("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let r=j3(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!r.whole)throw new i1(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,r.text.length);try{let c=this.textOpts(e,n,r.text);return{...Vt(this.opts.fonts,r.text,c),size:c.size}}catch(c){throw c instanceof i1?c:new i1(c.message,e.at)}}textOpts(e,n,r){let c={size:this.num(this.arg(e,"size",1,10),"text","size"),font:b0(this.arg(e,"font",2,this.dyn(n,"$font")??"")),halign:b0(this.arg(e,"halign",-1,"left")),valign:b0(this.arg(e,"valign",-1,"baseline")),spacing:U0(this.arg(e,"spacing",-1,1))},a=this.arg(e,"fit",-1);if(a!==void 0&&r!==void 0&&this.opts.fonts){let[s,o]=Array.isArray(a)?[a[0],a[1]]:[a,void 0],i=(d,p)=>{if(d===void 0)return;let m=this.num(d,"text","fit");if(!(m>0))throw new Error(`fit must be a ${p} more than 0`);return m},l=i(s,"width"),h=i(o,"height");if(Array.isArray(a)&&(a.length!==2||l===void 0&&h===void 0))throw new Error("fit must be a width, or [width, height] with either one undef");let u=Vt(this.opts.fonts,r,{...c,size:1}),f=[...l!==void 0&&u.advance>0?[l/u.advance]:[],...h!==void 0&&u.cap>0?[h/u.cap]:[]];if(f.length){let d=this.arg(e,"size",1);c.size=Math.min(...f,...d===void 0?[]:[c.size])}}return c}edges(e){let n=r=>{if(r==="out"||r==="in"||r==="flat")return r;throw new Error(`edges must be "out", "in" or "flat", got ${C0(r)}`)};if(typeof e=="string")return[n(e),n(e),n(e),n(e)];if(Array.isArray(e)&&e.length===4)return e.map(n);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let n=`${e}-back`,r=this.layers.get(n);if(r&&r.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${n}", which this program already uses for the front. Rename that layer.`);if(!r){let c=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(n,{...c,name:n,side:"back"}),this.layerDefs++}return n}bends(e){if(e===void 0)return[];let n=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return n.map((r,c)=>{if(!Array.isArray(r)||r.length!==3||!r.every(i=>typeof i=="number"&&Number.isFinite(i)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${C0(r)}${n.length>1?` at ${c}`:""}`);let[a,s,o]=r;if(!(s>a))throw new Error(`a bend's x1 must be more than its x0, got ${C0(r)}`);return{x0:a,x1:s,angle:o}})}makeBuiltins(){let e=(s,o)=>v3(s.children(),o),n=s=>o=>C5(o.children(),s),r=s=>o=>{let i=this.arg(o.args,"side",0,"front");if(i!=="front"&&i!=="back")throw new Error(`side must be "front" or "back", got ${C0(i)}`);return i==="back"&&o.env.vars.set("$mirrored",!y0(this.dyn(o.env,"$mirrored"))),C5(o.children(),i==="back"?this.backLayer(s):s)};return{rect:s=>{let[o,i]=this.vec2(this.arg(s.args,"size",0,1),"size"),l=U0(this.arg(s.args,"r",-1,0))||0,h=y0(this.arg(s.args,"center",1,!1)),u=J6(o,i,l,this.segs(s.env));return L0(s1([h?u.map(([f,d])=>[f-o/2,d-i/2]):u]))},square:s=>this.builtins.rect(s),circle:s=>{let o=this.arg(s.args,"d",-1),i=o!==void 0?this.num(o,"circle","d")/2:this.num(this.arg(s.args,"r",0,1),"circle","r");return L0([q3(i,i,this.segs(s.env)(i))])},ellipse:s=>{let o=this.arg(s.args,"d",-1),[i,l]=o!==void 0?this.vec2(o,"d").map(h=>h/2):this.vec2(this.arg(s.args,"r",0,1),"r");return L0([q3(i,l,this.segs(s.env)(Math.max(i,l)))])},regular_polygon:s=>{let o=Math.max(3,Math.floor(this.num(this.arg(s.args,"n",0,6),"regular_polygon","n"))),i=this.num(this.arg(s.args,"r",1,10),"regular_polygon","r");if(!(o<=this.limits.maxSegments))throw new Error(`${o} corners is more than the limit of ${this.limits.maxSegments}`);return L0([q3(i,i,o)])},star:s=>{let o=Math.max(2,Math.floor(this.num(this.arg(s.args,"n",0,5),"star","n"))),i=this.num(this.arg(s.args,"r",1,10),"star","r"),l=this.num(this.arg(s.args,"inner",2,i*.45),"star","inner");if(!(o*2<=this.limits.maxSegments))throw new Error(`${o} points is more than the limit of ${this.limits.maxSegments/2}`);let h=[];for(let u=0;u<o*2;u++){let f=Math.PI/2+Math.PI*u/o,d=u%2?l:i;h.push([d*Math.cos(f),d*Math.sin(f)])}return L0(s1([h]))},polygon:s=>{let o=this.points(this.arg(s.args,"points",0),"points"),i=this.arg(s.args,"paths",1),l=Array.isArray(i)?i.map(h=>(Array.isArray(h)?h:[]).map(u=>o[U0(u)]).filter(Boolean)):[o];return L0(s1(l,"evenodd"))},path:s=>{let o=this.arg(s.args,"d",0);if(typeof o!="string")throw new Error('path() needs SVG path data, like path("M0 0 L10 0 L5 8 Z")');let i=G3(W3(o),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return y0(this.arg(s.args,"close",-1,!1))?L0(s1([...i.closed,...i.open.filter(h=>h.length>2)],l)):C2([L0(s1(i.closed,l)),L2(i.open)])},line:s=>{let o=this.vec2(this.arg(s.args,"from",0,[0,0]),"from",!1),i=this.vec2(this.arg(s.args,"to",1,[10,0]),"to",!1),l=this.arg(s.args,"width",2);if(l===void 0)return L2([[o,i]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let u=Math.hypot(i[0]-o[0],i[1]-o[1]);if(!u)return T0();let f=-(i[1]-o[1])/u*(h/2),d=(i[0]-o[0])/u*(h/2);return L0(s1([[[o[0]+f,o[1]+d],[o[0]-f,o[1]-d],[i[0]-f,i[1]-d],[i[0]+f,i[1]+d]]]))},polyline:s=>{let o=this.points(this.arg(s.args,"points",0),"points"),i=y0(this.arg(s.args,"closed",1,!1));return L2([i&&o.length?[...o,o[0]]:o])},arc:s=>{let o=this.num(this.arg(s.args,"r",0,10),"arc","r"),i=this.num(this.arg(s.args,"start",1,0),"arc","start"),l=this.num(this.arg(s.args,"end",2,90),"arc","end"),h=Math.max(2,Math.ceil(this.segs(s.env)(o)*Math.abs(l-i)/360));if(!(h<=this.limits.maxSegments))throw new Error(`an arc with ${h} segments is more than the limit of ${this.limits.maxSegments}`);let u=[];for(let f=0;f<=h;f++){let d=(i+(l-i)*f/h)*Math.PI/180;u.push([o*Math.cos(d),o*Math.sin(d)])}return L2([u])},text:s=>{if(!this.opts.fonts)throw new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let o=this.arg(s.args,"text",0,""),i=j3(o,this.limits.maxTextLength);if(!i.whole)throw new Error(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`);this.tick(s.args.at,i.text.length);let l=this.textOpts(s.args,s.env,i.text),h=Ze(this.opts.fonts,i.text,l),u=this.arg(s.args,"weight",-1),f=this.arg(s.args,"bridge",-1);if(u!==void 0&&u!=="regular"){let d=u==="bold"?.035*l.size:this.num(u,"text","weight");d&&(h=c0(s1(h),d,"round"))}if(f!==void 0&&(h=D4(h,this.num(f,"text","bridge"))),y0(this.dyn(s.env,"$mirrored"))){let[d,p]=[1/0,-1/0];for(let m of h)for(let[g]of m)[d,p]=[Math.min(d,g),Math.max(p,g)];return L0(s1(h.map(m=>m.map(([g,v])=>[d+p-g,v]))))}return L0(h)},translate:s=>{let[o,i]=this.vec2(this.arg(s.args,"v",0,[0,0]),"v",!1);return e(s,[1,0,0,1,o,i])},rotate:s=>{let o=this.arg(s.args,"a",0,0),l=(Array.isArray(o)?U0(o[2]??0):this.num(o,"rotate","a"))*Math.PI/180,h=Math.cos(l),u=Math.sin(l),f=this.arg(s.args,"center",-1),d=[h,u,-u,h,0,0];if(f!==void 0){let[p,m]=this.vec2(f,"center",!1);d=[h,u,-u,h,p-h*p+u*m,m-u*p-h*m]}return e(s,d)},scale:s=>{let[o,i]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[o,0,0,i,0,0])},mirror:s=>{let[o,i]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(o,i)||1,h=o/l,u=i/l;return e(s,[1-2*h*h,-2*h*u,-2*h*u,1-2*u*u,0,0])},multmatrix:s=>{let o=this.arg(s.args,"m",0);if(!Array.isArray(o)||o.length<2)throw new Error("m must be a 2x3 or 3x3 matrix");let i=o[0],l=o[1];return e(s,[i[0],l[0],i[1],l[1],i[2]??0,l[2]??0])},union:s=>s.children(),group:s=>s.children(),difference:s=>{let[o,...i]=s.childList();if(!o)return T0();let l=c(i,"difference");return a(o,h=>({regions:g0(h.regions,l.regions),lines:Y0(h.lines,s1(l.regions),"outside")}))},intersection:s=>{let o=s.childList();if(!o.length)return T0();let i=g=>[...g.layers.values()].some(v=>v.regions.length),l=g=>i(g)||g.parts.some(v=>[...v.layers.values()].some(b=>b.regions.length)),h=g=>[g.layers,...g.parts.map(v=>v.layers)].flatMap(v=>[...v].flatMap(([b,y])=>b===r2?[]:y.regions)),u=g=>{let v;for(let b of o){if(b===g||!l(b))continue;let y=s1(h(b));v=v?K1(v,y):y}return v},f=o[0],d=o.every(l),p=u(f),m=a(f,g=>({regions:d?p?K1(g.regions,p):g.regions:[],lines:p?Y0(g.lines,p,"inside"):g.lines}));for(let g of o){if(g===f)continue;if(g.parts.length)throw new Error("part() can only be the first child of intersection()");let v=u(g),b=new Map;for(let[x,w]of g.layers)w.lines.length&&b.set(x,{regions:[],lines:v?Y0(w.lines,v,"inside"):w.lines});if(!b.size)continue;let y=m.parts.length===1&&!i(f)?m.parts[0]:void 0;if(y){let x=new Map(y.layers);for(let[w,M]of b){let k=x.get(w);x.set(w,{regions:k?.regions??[],lines:[...k?.lines??[],...M.lines]})}m={layers:m.layers,parts:[{...y,layers:x}]}}else m=C2([m,{layers:b,parts:[]}])}return f.parts.forEach((g,v)=>{let b=[...g.layers.values()].some(x=>x.regions.length),y=[...m.parts[v]?.layers.values()??[]].some(x=>x.regions.length);b&&!y&&this.warn(`intersection() leaves part "${g.name}" with nothing to cut: ${d?"its other children cover none of it":"a child of lines alone leaves no area; to clip lines to the part, put the intersection() inside it"} (${c2(s.args.at,!1)})`)}),m},hull:s=>{let o=s.children(),i=l=>{let h=[],u="cut",f=!0;for(let[p,m]of l){f&&(m.regions.length||m.lines.length)&&(u=p,f=!1);for(let g of[...m.regions,...m.lines])for(let v of g)h.push(v)}let d=ve(h);return new Map([[u,{regions:d.length>=3?[d]:[],lines:[]}]])};return{layers:i(o.layers),parts:o.parts.map(l=>({...l,layers:i(l.layers)}))}},offset:s=>{let o=this.arg(s.args,"r",0),i=this.arg(s.args,"delta",-1),l=y0(this.arg(s.args,"chamfer",-1,!1)),h=o!==void 0?this.num(o,"offset","r"):this.num(i??0,"offset","delta"),u=o!==void 0?"round":l?"square":"miter";return a(s.children(),f=>({regions:c0(f.regions,h,u),lines:f.lines}))},pattern:s=>{let[o,i]=this.vec2(this.arg(s.args,"spacing",0,10),"spacing"),l=this.num(this.arg(s.args,"stagger",1,0),"pattern","stagger");if(!(o>0&&i>0))throw new Error("spacing must be more than 0");let[h,...u]=s.childList();if(!h||!u.length)throw new Error("pattern() needs a tile and then the area to fill: pattern(10) { tile(); area(); }");if(h.parts.length)throw new Error("part() cannot be the tile of pattern()");let f=s1(c(u,"pattern").regions),d=J0(h.layers),p=w0(f);if(!d||!p)return T0();let m=Math.floor((p[1]-d[3])/i),g=Math.ceil((p[3]-d[1])/i),v=Math.floor((p[0]-d[2])/o)-1,b=Math.ceil((p[2]-d[0])/o)+1,y=(g-m+1)*(b-v+1);if(!(y<=this.limits.maxParts*10))throw new Error(`the pattern would have ${y} copies, more than the limit of ${this.limits.maxParts*10}`);this.tick(s.args.at,y);let x=R0(f).map(A=>({polys:A,box:w0(A)})),w=f,M=(A,S)=>{let C=0;for(let I of w)for(let L=0,T=I.length-1;L<I.length;T=L++){let[q,P]=I[T],[F,j]=I[L];P<=S?j>S&&(F-q)*(S-P)-(A-q)*(j-P)>0&&C++:j<=S&&(F-q)*(S-P)-(A-q)*(j-P)<0&&C--}return C!==0},k=new Map,z=(A,S)=>{let C=k.get(A)??{regions:[],lines:[]};for(let I of S.regions)C.regions.push(I);for(let I of S.lines)C.lines.push(I);k.set(A,C)};for(let A=m;A<=g;A++)for(let S=v;S<=b;S++){let C=S*o+(A%2?l*o:0),I=A*i,L=[d[0]+C,d[1]+I,d[2]+C,d[3]+I];if(L[2]<p[0]||L[0]>p[2]||L[3]<p[1]||L[1]>p[3])continue;let T=x.filter(_=>!(L[2]<_.box[0]||L[0]>_.box[2]||L[3]<_.box[1]||L[1]>_.box[3]));if(!T.length)continue;w=T.length===x.length?f:T.flatMap(_=>_.polys);let q=[M(L[0],L[1]),M(L[2],L[1]),M(L[2],L[3]),M(L[0],L[3])],P=w.some(_=>_.some(([Q,H])=>Q>L[0]&&Q<L[2]&&H>L[1]&&H<L[3])),F=q.every(Boolean)&&!P,j=[1,0,0,1,C,I];for(let[_,Q]of v3({layers:h.layers,parts:[]},j).layers)z(_,F?Q:{regions:K1(Q.regions,w),lines:Y0(Q.lines,w,"inside")})}return{layers:k,parts:[]}},spline:s=>{let o=this.points(this.arg(s.args,"points",0),"points"),i=this.arg(s.args,"width",1),l=Math.max(1,Math.floor(this.num(this.arg(s.args,"steps",-1,8),"spline","steps"))),h=y0(this.arg(s.args,"closed",-1,!1));if(!(o.length*l<=this.limits.maxSegments*10))throw new Error("too many points: use fewer points or steps");let u=J4(o,l,h);if(i===void 0)return L2([u]);let f=this.num(i,"spline","width");if(!(f>0))throw new Error("width must be more than 0");return L0(s1(g3([u],f)))},hatch:s=>{let o=this.num(this.arg(s.args,"angle",0,45),"hatch","angle"),i=this.num(this.arg(s.args,"pitch",1,5),"hatch","pitch"),l=this.arg(s.args,"width",2);if(!(i>0))throw new Error("pitch must be more than 0");let h=s1(c([s.children()],"hatch").regions),u=w0(h);if(!u)return T0();let[f,d]=[(u[0]+u[2])/2,(u[1]+u[3])/2],p=Math.hypot(u[2]-u[0],u[3]-u[1])/2+i,m=o*Math.PI/180,[g,v]=[Math.cos(m),Math.sin(m)],[b,y]=[-v,g],x=Math.ceil(p/i);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let w=[],M=Math.round((f*b+d*y)/i);for(let z=M-x;z<=M+x;z++){let A=z*i-(f*b+d*y),[S,C]=[f+b*A,d+y*A];w.push([[S-g*p,C-v*p],[S+g*p,C+v*p]])}if(l===void 0)return L2(Y0(w,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return L0(K1(s1(g3(w,k).map(z=>z)),h))},flow:s=>{let o=this.arg(s.args,"field",0),i=this.num(this.arg(s.args,"spacing",1,2),"flow","spacing");if(!(i>0))throw new Error("spacing must be more than 0");let l=this.num(this.arg(s.args,"step",2,Math.min(.5,i/4)),"flow","step");if(!(l>0&&l<=i))throw new Error("step must be more than 0 and at most the spacing");let h=this.num(this.arg(s.args,"min_length",-1,2*i),"flow","min_length"),u=this.num(this.arg(s.args,"seed",-1,1),"flow","seed"),f=s1(c([s.children()],"flow").regions),d=w0(f);if(!d)return T0();let p=b=>[Math.cos(b*M8),Math.sin(b*M8)],m;if(typeof o=="number"){let b=p(o);m=()=>b}else{let b=this.fieldFn(o,"flow",s.env,s.args.at);m=y=>{let x=b(y);if(x===void 0)return null;if(typeof x=="number"&&Number.isFinite(x))return p(x);if(Array.isArray(x)&&typeof x[0]=="number"&&typeof x[1]=="number"&&Number.isFinite(x[0])&&Number.isFinite(x[1])){let w=Math.hypot(x[0],x[1]);return w>1e-12?[x[0]/w,x[1]/w]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${C0(x)}`)}}if(!((d[2]-d[0])/i*((d[3]-d[1])/i)<=this.limits.maxPoints/10))throw new Error("spacing is too small for the area");let v=K6({spacing:i,step:l,minLength:h,seed:u,box:d,inside:tn(f),dir:m,tick:()=>this.tick(s.args.at),maxPoints:this.limits.maxPoints});return L2(Y0(v,f,"inside"))},contours:s=>{let o=this.arg(s.args,"field",0),i=this.fieldFn(o,"contours",s.env,s.args.at),l=this.arg(s.args,"levels",1,10),h=this.arg(s.args,"interval",-1),u=this.num(this.arg(s.args,"cell",-1,1),"contours","cell");if(!(u>0))throw new Error("cell must be more than 0");let f=s1(c([s.children()],"contours").regions),d=w0(f);if(!d)return T0();let p=Math.ceil((d[2]-d[0])/u)+1,m=Math.ceil((d[3]-d[1])/u)+1;if(!(p*m<=this.limits.maxPoints/2))throw new Error(`a cell of ${u} samples the area at ${p*m} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let g=new Float64Array(p*m),v=1/0,b=-1/0;for(let M=0;M<m;M++)for(let k=0;k<p;k++){let z=i([d[0]+k*u,d[1]+M*u]);if(z===void 0){g[M*p+k]=NaN;continue}if(typeof z!="number"||!Number.isFinite(z))throw new Error(`field() must give a number or undef, got ${C0(z)}`);g[M*p+k]=z,v=Math.min(v,z),b=Math.max(b,z)}if(!(v<=b))return T0();let y;if(h!==void 0){let M=this.num(h,"contours","interval");if(!(M>0))throw new Error("interval must be more than 0");let k=Math.ceil(v/M),z=Math.floor(b/M);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(z))throw new Error(`the heights are too large for an interval of ${M}`);let A=Math.max(0,z-k+1);if(!(A<=1e4))throw new Error(`interval ${M} gives ${A} levels: use a larger interval`);y=Array.from({length:A},(S,C)=>(k+C)*M)}else if(Array.isArray(l))y=l.map(M=>this.num(M,"contours","levels"));else{let M=Math.floor(this.num(l,"contours","levels"));if(!(M>=1&&M<=1e4))throw new Error("levels must be 1 to 10000");y=Array.from({length:M},(k,z)=>v+(b-v)*(z+1)/(M+1))}let x=[],w=0;for(let M of y){this.tick(s.args.at,Math.ceil(p*m/100));let k=Q6(g,p,m,d[0],d[1],u,M),z=k.reduce((A,S)=>A+S.length,0);if(!((w+=z)<=this.limits.maxPoints))throw new Error(`the contour lines have more than ${this.limits.maxPoints} points, the limit: use fewer levels or a larger cell`);this.spend(z);for(let A of k)x.push(A)}return L2(Y0(x,f,"inside"))},occlude:s=>{let o;this.occluding++;try{o=s.childItems()}finally{this.occluding--}let i=u=>this.layers.get(u)?.mode??"cut",l=[],h=[];for(let u=o.length-1;u>=0;u--){let f=o[u];if(f.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[m,g]of f.layers){if(m===r2)continue;let v=i(m);!h.length||v==="cut"||v==="guide"?d.set(m,g):v==="line"?d.set(m,{regions:[],lines:Y0([...g.lines,...s1(g.regions).map(b=>[...b,b[0]])],h,"outside")}):d.set(m,{regions:g0(g.regions,h),lines:Y0(g.lines,h,"outside")})}l.push({layers:d,parts:[]});let p=[...f.layers].filter(([m])=>i(m)!=="guide").flatMap(([,m])=>m.regions);p.length&&(h=s1([...h,...p]))}return C2(l.reverse())},hide:s=>this.occluding?L0(s1(c([s.children()],"hide").regions),r2):(this.warn(`hide() only works inside occlude(); it draws nothing (${c2(s.args.at,!1)})`),T0()),paint:s=>{let o=this.arg(s.args,"layers",0);if(o!==void 0&&(!Array.isArray(o)||o.some(f=>typeof f!="string")))throw new Error("layers must be a list of layer names");let i=s.childList(),l=[],h=[],u=[];for(let f=i.length-1;f>=0;f--){let d=i[f];if(d.parts.length)throw new Error("part() cannot go inside paint()");let p=h,m=s1(c([d],"paint").regions);u[f]=m,h=p.length?s1([...p,...m]):m;let g=Array.isArray(o)?o[f]:void 0;if(g!=="")if(g!==void 0){this.layers.has(g)||this.layers.set(g,{name:g,mode:"fill",color:"#000000"}),this.layerDefs++,l.push(L0(p.length?g0(m,p):m,g));let v=d.layers.get(r2);v&&l.push({layers:new Map([[r2,v]]),parts:[]})}else l.push(p.length?a(d,v=>({regions:g0(v.regions,p),lines:Y0(v.lines,p,"outside")})):d)}return this.invisiblePaint(i,u,o,s.args.at),C2(l.reverse())},measure:s=>{let o=y0(this.arg(s.args,"draw",0,!1)),i=s.childSeq((l,h)=>{if(l!==0)return;let u=J0(h.layers)??w0(h.parts.flatMap(g=>[...g.layers.values()].flatMap(v=>[...v.regions,...v.lines])));s.env.vars.set("$bounds",u?[...u]:void 0);let f=[h.layers,...h.parts.map(g=>g.layers)],d=f.flatMap(g=>g.get("cut")?.regions??[]),p=d.length?d:f.flatMap(g=>[...g].filter(([v])=>v!=="guide").flatMap(([,v])=>v.regions)),m=Z6(s1(p));s.env.vars.set("$area",m.area),s.env.vars.set("$centroid",m.area>0?m.centroid:void 0)});return C2(o?i:i.slice(1))},fill_holes:s=>{let o=this.arg(s.args,"min_area",0),i=o===void 0?1/0:this.num(o,"fill_holes","min_area");return a(s.children(),l=>({regions:s1(l.regions).filter(h=>!(b1(h)<0&&-b1(h)<i)),lines:l.lines}))},join_islands:s=>{let o=this.num(this.arg(s.args,"width",0,1),"join_islands","width");if(!(o>0))throw new Error("join_islands(): width must be more than 0");let i=s.children(),l=h=>new Map([...h].map(([u,f])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:D4(f.regions,o),lines:f.lines}:f]));return{layers:l(i.layers),parts:i.parts.map(h=>({...h,layers:l(h.layers)}))}},largest:s=>{let o=Math.floor(this.num(this.arg(s.args,"n",0,1),"largest","n"));if(!(o>=1))throw new Error("largest(): n must be 1 or more");let i=u=>R0(u).map(f=>({g:f,a:f.reduce((d,p)=>d+b1(p),0)})).sort((f,d)=>d.a-f.a).slice(0,o).flatMap(({g:f})=>f),l=s.children(),h=u=>new Map([...u].map(([f,d])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:i(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(u=>({...u,layers:h(u.layers)}))}},close:s=>{let o=this.num(this.arg(s.args,"r",0,.5),"close","r");return a(s.children(),i=>({regions:c0(c0(i.regions,o,"round"),-o,"round"),lines:i.lines}))},stroke:s=>{let o=this.num(this.arg(s.args,"width",0,1),"stroke","width");return a(s.children(),i=>({regions:s1([...i.regions,...g3(i.lines,o)]),lines:[]}))},outline:s=>a(s.children(),o=>({regions:[],lines:[...o.lines,...s1(o.regions).map(i=>[...i,i[0]])]})),cut:n("cut"),score:r("score"),engrave:r("engrave"),guide:n("guide"),layer:s=>{let o=this.arg(s.args,"name",0);if(typeof o!="string"||!o)throw new Error("layer() needs a name");let i=this.arg(s.args,"mode",1),l=this.arg(s.args,"color",2),h=this.layers.get(o),u=this.arg(s.args,"order",-1),f=this.arg(s.args,"bleed",-1);if(i!==void 0||l!==void 0||u!==void 0||f!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${o}" is the back of layer "${o.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let p=i??h?.mode??"line";if(!["cut","line","fill","guide"].includes(p))throw new Error('mode must be "cut", "line", "fill" or "guide"');let m=b0(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(m))throw new Error('color must look like "#00aa00"');let g=u===void 0?h?.order:this.num(u,"layer","order"),v=f===void 0?h?.bleed:this.num(f,"layer","bleed");if(v!==void 0&&!(v>=0))throw new Error("bleed must be 0 or more");if(v&&p==="cut")throw new Error("a cut layer has no bleed");this.layerDefs++,this.layers.set(o,{name:o,mode:p,color:m,...g!==void 0&&{order:g},...v!==void 0&&{bleed:v}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${C0(d)}`);if(d==="back"&&this.layers.get(o)?.mode==="cut")throw new Error("a cut layer has no back: only marks go on the back face");return d==="back"&&s.env.vars.set("$mirrored",!y0(this.dyn(s.env,"$mirrored"))),C5(s.children(),d==="back"?this.backLayer(o):o)},part:s=>{let o=b0(this.arg(s.args,"name",0,"part")),i=this.arg(s.args,"qty",1,1),l=typeof i=="number"?Math.floor(i):1;if(!(l>=0))throw new Error(`qty must be 0 or more, got ${C0(i)}`);if(l===0)return{layers:new Map,parts:[]};let h=this.arg(s.args,"stack",-1),u=h===void 0?1:Math.floor(this.num(h,"part","stack"));if(!(u>=1))throw new Error("stack must be 1 or more");if(this.copies+=l*u,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let f=this.arg(s.args,"at",-1),d=this.arg(s.args,"rotate",-1),p=this.arg(s.args,"glue",-1),m=p===void 0?void 0:b0(p),g=b0(this.arg(s.args,"face",-1,"top"));if(g!=="top"&&g!=="bottom")throw new Error(`face must be "top" or "bottom", got ${C0(g)}`);let v=this.frame!==B4&&m===void 0,b=this.arg(s.args,"bend",-1),y=f===void 0&&d===void 0&&!v&&m===void 0&&b===void 0?void 0:this.placements(f,d,l),x=this.arg(s.args,"material",-1);x!==void 0&&s.env.vars.set("$material",b0(x));let w=this.thickness(s.env);y&&(v||u>1)&&(y=y.flatMap(p1=>{let G1=m===void 0?D1(this.frame,F0(p1)):F0(p1),F1=m!==void 0&&g==="bottom"?-w:w;return Array.from({length:u},(V,U)=>({...p1,matrix:D1(G1,j0(0,0,U*F1))}))}));let M=this.arg(s.args,"mirror",-1,!1),k;if(Array.isArray(M)){if(M.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${M.length}`);k=M.map(p1=>y0(p1))}else k=Array.from({length:l},()=>y0(M));let z=k.some(p1=>p1)&&!k.every(p1=>p1);if(z&&m!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let A=k[0],S=p1=>{let G1=s.env.vars.get("$mirrored"),F1=s.env.vars.has("$mirrored");p1&&s.env.vars.set("$mirrored",!0);try{let V=s.children();return p1?v3(V,[-1,0,0,1,0,0]):V}finally{p1&&(F1?s.env.vars.set("$mirrored",G1):s.env.vars.delete("$mirrored"))}},C=S(A),I=this.bends(b),L=this.arg(s.args,"on",-1),T=this.arg(s.args,"slots",-1),q=T===void 0?void 0:(Array.isArray(T)?T:[T]).map(p1=>{if(typeof p1!="string")throw new Error("slots must be part names");return p1}),P=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),F=this.arg(s.args,"slot_extra",-1),j=F===void 0?void 0:this.vec2(F,"slot_extra",!1),_=this.arg(s.args,"bores",-1),Q=_===void 0?void 0:(Array.isArray(_)?_:[_]).map(p1=>{if(typeof p1!="string")throw new Error("bores must be hardware labels or kinds");return p1}),H=this.arg(s.args,"halving",-1),B=H===void 0?void 0:(Array.isArray(H)?H:[H]).map(p1=>{if(typeof p1!="string")throw new Error("halving must be part names");return p1}),Y=this.arg(s.args,"fit",-1,"turn");if(typeof Y!="number"&&!Object.prototype.hasOwnProperty.call(I5,b0(Y)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${C0(Y)}`);let e1=typeof Y=="number"?Y:I5[b0(Y)],X=(p1,G1,F1)=>{let V=F1.length===l,U=y?.filter((r1,h1)=>F1.includes(Math.floor(h1/u)+1));return{name:o,qty:F1.length*u,layers:p1,thickness:w,kerf:U0(this.dyn(s.env,"$kerf"))||0,material:b0(this.dyn(s.env,"$material")??"material"),...U?{placements:U}:{},...u>1?{stack:u}:{},...I.length?{bends:G1?I.map(r1=>({...r1,mirrored:!0})):I}:{},...L!==void 0?{on:b0(L)}:{},...q?{slots:q,clearance:P}:{},...q&&j?{slotExtra:j}:{},...Q?{bores:Q,fit:e1}:{},...B?{halving:B,clearance:P}:{},...this.step?{step:this.step}:{},...m!==void 0&&{glue:{host:m,face:g}},...G1&&{mirrored:!0},...!V&&{copies:F1}}},M1=p1=>k.flatMap((G1,F1)=>G1===p1?[F1+1]:[]),v1=z?[X(C.layers,A,M1(A)),X(S(!A).layers,!A,M1(!A))]:[X(C.layers,A,M1(A))];return{layers:new Map,parts:[...C.parts,...v1]}},place:s=>{let o=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),i=this.vec3(this.arg(s.args,"rotate",1,[0,0,0]),"rotate"),l=this.frame;this.frame=D1(l,F0({at:o,rotate:i}));try{return s.children()}finally{this.frame=l}},step:s=>{let o=b0(this.arg(s.args,"text",0,"")),i=y0(this.arg(s.args,"substeps",1,!0));if(this.stepFolded)return s.children();let l=this.step,h=l&&o?`${this.stepNames[l-1]}: ${o}`:o,u=this.stepNames.indexOf(h)+1;u||(this.stepNames.push(h),u=this.stepNames.length),this.step=u,this.stepFolded=!i;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let o=b0(this.arg(s.args,"kind",0,"dowel"));K0(N2,o)===void 0&&K0(Q2,o)===void 0&&this.warn(`hardware(): unknown kind "${o}"; the 3D view shows it grey (${c2(s.args.at,!1)})${A3(o,Object.keys(N2))}`);let i=b0(this.arg(s.args,"shape",-1,"rod"));if(i!=="rod"&&i!=="ball")throw new Error(`shape must be "rod" or "ball", got ${C0(i)}`);let l=this.arg(s.args,"sides",-1),h=i==="ball"||l===0,u=this.vec3(this.arg(s.args,"from",1),"from"),f=this.arg(s.args,"to",2),d=h&&f===void 0?u:this.vec3(f,"to"),p=this.arg(s.args,"size",3,6),m=typeof p=="number"?p:this.vec2(p,"size",!1);if(h){if(typeof m!="number"||!(m>0))throw new Error("a ball's size is its diameter, a number more than 0");u=d=[(u[0]+d[0])/2,(u[1]+d[1])/2,(u[2]+d[2])/2]}let g=[d[0]-u[0],d[1]-u[1],d[2]-u[2]],v=Math.abs(g[2])>.9*Math.hypot(...g),b=this.arg(s.args,"up",-1),y=b===void 0?v?[0,1,0]:[0,0,1]:this.vec3(b,"up"),x=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(x>=3&&x<=Ht))throw new Error(`sides must be from 3 to ${Ht} (or 0 for a ball), got ${C0(x)}`);if(this.pointCount+=h?2*Ht:x*2,this.pointCount>this.limits.maxPoints*10)throw new Error(`making the shapes and hardware took more than ${this.limits.maxPoints*10} points of work, the limit`);let w=this.arg(s.args,"label",-1),M=this.frame,k=A=>[M[0]*A[0]+M[1]*A[1]+M[2]*A[2]+M[3],M[4]*A[0]+M[5]*A[1]+M[6]*A[2]+M[7],M[8]*A[0]+M[9]*A[1]+M[10]*A[2]+M[11]],z=A=>[M[0]*A[0]+M[1]*A[1]+M[2]*A[2],M[4]*A[0]+M[5]*A[1]+M[6]*A[2],M[8]*A[0]+M[9]*A[1]+M[10]*A[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);return this.hardware.push({kind:o,from:k(u),to:k(d),size:m,up:z(y),sides:x,step:this.step,...w!==void 0?{label:b0(w)}:{}}),s.children()},material:s=>{let o=this.arg(s.args,"thickness",0),i=this.arg(s.args,"kerf",1),l=this.arg(s.args,"name",2);return o!==void 0&&s.env.vars.set("$thickness",this.num(o,"material","thickness")),i!==void 0&&s.env.vars.set("$kerf",this.num(i,"material","kerf")),l!==void 0&&s.env.vars.set("$material",b0(l)),s.children()},children:s=>{let o=s.env.childCtx();if(!o)return T0();let i=this.childStmts(o.stmts),l=this.arg(s.args,"index",0),h=new E0(o.env,s.env);this.hoist(o.stmts,h);let u=new Set;if(l===void 0)i.forEach(m=>u.add(m));else for(let m of this.iterable(l,s.args.at)){let g=U0(m);i[g]?u.add(i[g]):i.length&&g>=i.length&&o.module&&o.pos&&this.warn(`${o.module}() uses children(${g}) but was given ${i.length} child${i.length===1?"":"ren"} (${c2(o.pos,!1)}). A module call takes one statement as its child: put several in braces, ${o.module}() { a(); b(); }`)}let f=[],d=this.childCache.get(o)??new Map;this.childCache.set(o,d);let p=this.childKey(h);for(let m of o.stmts)if(m.kind==="assign")this.stmt(m,h);else if(u.has(m)){let g=p&&d.get(m);if(g&&g.key===p){g.shape&&f.push(g.shape);continue}let v=this.effects(),b=this.stmt(m,h);b&&f.push(b),p&&this.effects()===v&&!b?.parts.length&&d.set(m,{key:p,shape:b})}return C2(f)},echo:s=>(this.echo(this.echoText(s.args),s.args.at),s.children()),assert:s=>(this.assert(s.args),s.children()),finger_rect:s=>{let[o,i]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.edges(this.arg(s.args,"edges",1,"out")),h=this.thickness(s.env),u=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(o)+Math.abs(i))/u*4),L0(Ee(o,i,l,h,u))},finger_holes:s=>{let o=this.num(this.arg(s.args,"length",0),"finger_holes","length"),i=this.edges(this.arg(s.args,"edge",1,"out"))[0];if(i==="flat")throw new Error('edge must be "out" or "in"');let l=this.fingerWidth(s.args,s.env,2);return this.spend(Math.abs(o)/l*4),L0(Rn(o,i,this.thickness(s.env),l))},tslot:s=>{let o=this.num(this.arg(s.args,"d",0,3),"tslot","d"),i=this.num(this.arg(s.args,"length",1,12),"tslot","length"),[l,h]=this.vec2(this.arg(s.args,"nut",2,[o*1.85,o*.8]),"nut",!1),u=this.num(this.arg(s.args,"nut_at",3,i/2),"tslot","nut_at");return L0(s1(Fn(o,i,l,h,u)))},living_hinge:s=>{let[o,i]=this.vec2(this.arg(s.args,"size",0),"size"),l=this.num(this.arg(s.args,"spacing",1,1.5),"living_hinge","spacing"),h=this.num(this.arg(s.args,"bridge",2,3),"living_hinge","bridge"),u=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(i-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||u<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(o)/l+1)*(Math.abs(i)/(u+h)+2)*2),L2(Dn(o,i,l,h,u))}};function c(s,o){let i={regions:[],lines:[]};for(let l of s){if(l.parts.length)throw new Error(`part() can only be the first child of ${o}()`);for(let[h,u]of l.layers)if(h!==r2)for(let f of u.regions)i.regions.push(f)}return i}function a(s,o){let i=l=>{let h=new Map;for(let[u,f]of l)h.set(u,o(f));return h};return{layers:i(s.layers),parts:s.parts.map(l=>({...l,layers:i(l.layers)}))}}}};var n5=t=>{let e=Math.round(t*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},qt=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function Nt(t,e){let n=[];for(let[r,c]of t){let a=[n5(r),n5(c)],s=n[n.length-1];(!s||s[0]!==a[0]||s[1]!==a[1])&&n.push(a)}for(;e&&n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n}var r5=(t,e)=>`M${Nt(t,e).map(([n,r])=>`${n} ${r}`).join("L")}${e?"Z":""}`;function Ye(t,e){let n=[];for(let r of e){let c=[],a=[],s=[];for(let o of t){let i=o.layers.get(r.name);if(i){for(let l of i.lines)c.push(r5(l,!1));for(let l of i.regions)(b1(l)<0?a:s).push(r5(l,!0))}}(c.length||a.length||s.length)&&n.push({name:r.name,mode:r.mode,color:r.color,d:[...c,...a,...s].join(""),regions:[...a,...s].join(""),lines:c.join("")})}return n}function Je(t,e,n,r){let c=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${n5(e)}mm" height="${n5(n)}mm" viewBox="0 0 ${n5(e)} ${n5(n)}">`];for(let a of r){let s=[],o=[];for(let l of t){let h=l.layers.get(a.name);if(!h)continue;let u=` data-part="${qt(l.part)}"`;if(a.mode==="fill"){h.regions.length&&o.push(`<path${u} d="${h.regions.map(f=>r5(f,!0)).join("")}"/>`);for(let f of h.lines)o.push(`<path${u} fill="none" stroke="${a.color}" stroke-width="0.1" d="${r5(f,!1)}"/>`);continue}for(let f of h.lines)s.push(`<path${u} d="${r5(f,!1)}"/>`);for(let f of h.regions)(b1(f)<0?s:o).push(`<path${u} d="${r5(f,!0)}"/>`)}if(!s.length&&!o.length)continue;let i=a.mode==="fill"?`fill="${a.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${a.color}" stroke-width="0.1"${a.mode==="guide"?' stroke-dasharray="1 1"':""}`;c.push(`<g id="${qt(a.name)}" inkscape:groupmode="layer" inkscape:label="${qt(a.name)}" data-mode="${a.mode}" ${i}>`,...s,...o,"</g>")}return c.push("</svg>",""),c.join(`
|
|
3022
|
+
`)}var Pi={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},Ei=t=>{let e=Pi[t.toLowerCase()];if(e)return e;let[n,r,c]=[1,3,5].map(a=>parseInt(t.slice(a,a+2),16));return n>r&&n>c?1:r>n&&r>c?3:c>n&&c>r?5:7};function Ti(t){let e=o=>o.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),n=new Set(Z5.map(o=>o.name)),r=new Set(t.map(o=>e(o.name))),c=new Set,a=new Map,s=[...t.filter(o=>n.has(o.name)),...t.filter(o=>!n.has(o.name))];for(let o of s){let i=e(o.name);if(c.has(i)){let l=2;for(;r.has(`${i}_${l}`)||c.has(`${i}_${l}`);)l++;i=`${i}_${l}`}c.add(i),a.set(o.name,i)}return a}function Ut(t,e,n,r){let c=[],a=(i,l)=>c.push(String(i),String(l)),s=Ti(r);a(0,"SECTION"),a(2,"HEADER"),a(9,"$ACADVER"),a(1,"AC1009"),a(9,"$INSUNITS"),a(70,4),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"TABLES"),a(0,"TABLE"),a(2,"LAYER"),a(70,r.length);for(let i of r)a(0,"LAYER"),a(2,s.get(i.name)),a(70,0),a(62,Ei(i.color)),a(6,"CONTINUOUS");a(0,"ENDTAB"),a(0,"ENDSEC"),a(0,"SECTION"),a(2,"ENTITIES");let o=(i,l,h)=>{a(0,"POLYLINE"),a(8,i),a(66,1),a(10,0),a(20,0),a(30,0),a(70,h?1:0);for(let[u,f]of Nt(l.map(([d,p])=>[d,n-p]),h))a(0,"VERTEX"),a(8,i),a(10,u),a(20,f),a(30,0);a(0,"SEQEND"),a(8,i)};for(let i of r){let l=s.get(i.name),h=[];for(let u of t){let f=u.layers.get(i.name);if(f){for(let d of f.lines)o(l,d,!1);for(let d of f.regions)b1(d)<0?o(l,d,!0):h.push(d)}}for(let u of h)o(l,u,!0)}return a(0,"ENDSEC"),a(0,"EOF"),c.join(`
|
|
2644
3023
|
`)+`
|
|
2645
|
-
`}var W8=(t,e)=>{let n=0;for(let r=1;r<t.length;r++)n+=Math.hypot(t[r][0]-t[r-1][0],t[r][1]-t[r-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},m0=t=>Math.round(t*100)/100;function X8(t,e={}){for(let[I,N]of Object.entries(e.params??{}))try{Ie(I,N)}catch(a1){throw new o1(a1.message)}let{program:n}=l2(t),r=new Set(n.body.flatMap(I=>I.kind==="assign"?[I.name]:[])),c=Object.keys(e.params??{}).filter(I=>!I.startsWith("$")&&!r.has(I)),a=e.fonts?new q4(e.fonts,e.defaultFont):void 0,s=new Y3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(n)}catch(I){let N=I instanceof RangeError?new o1(/call stack/i.test(I.message)?"Recursion too deep: the program calls itself without stopping":"A value grew too large. Is a list or string doubling without end?"):I;throw N instanceof o1&&(N.echoes=s.echoes,N.warnings=[...s.warnings],a?.missing.size&&(N.missingFonts=[...a.missing])),N}let l=I=>o.globals.get(I).value,h=o.warnings;for(let I of c)h.push(`Setting "${I}" is not a variable of the program, so it is ignored.${b3(I,r)}`);let u=o.layers,f=I=>u.get(I)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(I=>I.regions.length||I.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:q0(l("$thickness"))||3,kerf:q0(l("$kerf"))||0,material:v0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let g=I=>JSON.stringify([I.thickness,I.material,[...I.layers].map(([N,a1])=>[N,a1.regions.map(J=>J.map(([x1,R1])=>[Math.round(x1*100),Math.round(R1*100)])),a1.lines.map(J=>J.map(([x1,R1])=>[Math.round(x1*100),Math.round(R1*100)]))])]),p=new Map,v=new Set;for(let I of d){let N=g(I),a1=I.mirrored?`${I.name}\0mirrored`:I.name,J=p.get(a1);J===void 0?p.set(a1,N):J!==N&&v.add(I.name)}for(let I of v)h.push(`Two different parts are named "${I}"; slots, glue and on = find parts by name, so give each its own.`);Qi(d,h),_i(d,f,h,o.hardware),ji(d,f,h);let y=[],b=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],M=new Map,w=[],k=new Set,z=[],S=l("$min_width"),A=S===void 0?1.5:q0(S),L=l("$label_parts")===!0,C=l("$join_lines")===!0,P=0;L&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let R=u.get("engrave-back");L&&a&&R&&R.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let q=L&&!!a&&(!R||R.side==="back");if(q){let I=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:I?.color??"#000000",side:"back"})}let T=[];for(let I of d){let N=i1([...I.layers].filter(([m1])=>f(m1)==="cut").flatMap(([,m1])=>m1.regions)),a1;if(I.bends&&N.length){let m1=1/0,v1=-1/0;for(let y1 of N)for(let[T1]of y1)m1=Math.min(m1,T1),v1=Math.max(v1,T1);for(let y1 of I.bends)(y1.x0<m1-.001||y1.x1>v1+.001)&&h.push(`Part "${I.name}" bends from x = ${D2(y1.x0)} to ${D2(y1.x1)}, beyond the part (x = ${D2(m1)} to ${D2(v1)}); only the part itself bends.`)}if(q&&N.length){a1=++P;let m1=eo(N,String(a1),a,v0(l("$font")??""));if(m1.length){let v1=I.layers.get("engrave-back")??{regions:[],lines:[]};I.layers=new Map(I.layers).set("engrave-back",{regions:[...v1.regions,...m1],lines:v1.lines})}else h.push(`Part "${I.name}" is too small to take its number ${a1}.`)}if(A>0&&N.length){let m1=n0(n0(N,-A/2,"round"),A/2,"round"),v1=F0(k0(N,m1)).filter(y1=>y1.reduce((T1,$1)=>T1+M1($1),0)>2*A*A);if(v1.length){let y1=v1.slice(0,3).map(T1=>{let[$1,J1,Q0,B1]=X0(new Map([["cut",{regions:T1,lines:[]}]]));return`[${m0(($1+Q0)/2)}, ${m0((J1+B1)/2)}]`});h.push(`Part "${I.name}" is narrower than ${A} mm ($min_width) in ${v1.length} place${v1.length>1?"s":""}, at ${y1.join(", ")}${v1.length>3?" and more":""} in the part's coordinates.`)}}let J=new Map;for(let[m1,v1]of I.layers){if(m1===s2||f(m1)==="guide"&&!e.guides)continue;let y1=i1(v1.regions),T1=v1.lines.filter($1=>$1.length>=2);if((f(m1)==="line"||f(m1)==="guide")&&(T1=[...T1,...y1.map($1=>[...$1,$1[0]])],y1=[]),N.length&&f(m1)!=="guide"){let $1=u.get(m1)?.bleed??0,J1=$1>0?n0(N,$1,"round"):N;f(m1)!=="cut"&&(y1=a0(y1,J1)),T1=W0(T1,J1,"inside")}C&&T1.length>1&&f(m1)!=="guide"&&(T1=St(T1)),(y1.length||T1.length)&&J.set(m1,{regions:y1,lines:T1})}if(T.push(...Ji(I.name,J,u)),N.length){let m1=[];for(let[y1,T1]of J){let $1=u.get(y1);if($1?.mode==="cut"&&T1.lines.length)for(let J1 of["front","back"])m1.push({layer:y1,mode:"line",color:"#000000",side:J1,regions:[],lines:T1.lines});!$1||$1.mode!=="fill"&&$1.mode!=="line"||m1.push({layer:y1,mode:$1.mode,color:$1.color,side:$1.side??"front",regions:T1.regions,lines:T1.lines})}let v1={name:I.name,thickness:I.thickness,material:I.material,outline:N,...m1.length&&{marks:m1}};if(I.placements){let y1=new Set;I.placements.forEach((T1,$1)=>{let J1={...v1,copy:L6(I,$1),matrix:Z0(T1),placed:!0,...I.bends&&{bends:I.bends},...I.step&&{step:I.step},...I.stack&&{stack:I.stack}};x.push(J1),I.on!==void 0&&M.set(J1,I.on);let Q0=J1.matrix.map(B1=>B1.toFixed(6)).join(",");y1.has(Q0)&&k.add(J1),y1.add(Q0)}),y1.size<I.placements.length&&h.push(`Copies of part "${I.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let y1=0;y1<I.qty;y1++)w.push({...v1,copy:L6(I,y1),matrix:Z0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...I.step&&{step:I.step}})}let x1=F0(N),R1=x1.length;if(R1>1){let m1=T1=>T1.reduce(($1,J1)=>$1+M1(J1),0),y1=[...x1].sort((T1,$1)=>m1($1)-m1(T1)).slice(1,4).map(T1=>{let[$1,J1,Q0,B1]=X0(new Map([["cut",{regions:T1,lines:[]}]]));return`[${m0($1)}, ${m0(J1)}] to [${m0(Q0)}, ${m0(B1)}]`}).join(", ");h.push(`Part "${I.name}" cuts into ${R1} separate pieces. Join them, or make them separate parts. The smaller ${R1===2?"one is":"ones are"} at ${y1}${R1>4?" and more":""}, in the part's coordinates.`)}let w0=0;for(let[m1,v1]of J)if(f(m1)==="cut"){for(let y1 of v1.regions)w0+=W8(y1,!0);for(let y1 of v1.lines)w0+=W8(y1,!1)}let Y1=X0(J)??[0,0,0,0],A1=e.kerf??I.kerf;if(!(Number.isFinite(A1)&&A1>=0))throw new o1("$kerf must be a number, 0 or more");let l0={name:I.name,qty:I.qty,width:m0(Y1[2]-Y1[0]),height:m0(Y1[3]-Y1[1]),pieces:R1,cutLength:Math.round(w0),thickness:I.thickness,kerf:A1,material:I.material,...I.stack&&{stack:I.stack},...I.glue&&{glued:I.glue.host},...I.mirrored&&{mirrored:!0},...a1!==void 0&&{label:a1}};if(b&&b.parts.push({name:I.name,kerf:A1,qty:I.qty,...I.stack&&{stack:I.stack},...I.glue&&{glue:I.glue},...I.on&&{on:I.on},cutRegions:N.map(m1=>m1.map(([v1,y1])=>[v1,y1])),cutLines:[...J].filter(([m1])=>f(m1)==="cut").flatMap(([,m1])=>m1.lines.map(v1=>v1.map(([y1,T1])=>[y1,T1])))}),A1>0){for(let[m1,v1]of J)if(f(m1)==="cut"){let y1=v1.regions.filter(J1=>M1(J1)<0);v1.regions=n0(v1.regions,A1/2,"round",Math.min(.01,A1/20));let T1=v1.regions.filter(J1=>M1(J1)<0),$1=y1.length-T1.length;if($1>0){let J1=B1=>{let[c0,b0,c2,G0]=X0(new Map([["cut",{regions:[B1],lines:[]}]]));return[(c0+c2)/2,(b0+G0)/2]},Q0=y1.map(J1).filter(([B1,c0])=>!T1.some(b0=>Z8(b0,B1,c0))).slice(0,3).map(([B1,c0])=>`[${m0(B1)}, ${m0(c0)}]`);h.push(`Part "${I.name}": ${$1} hole${$1===1?" is":"s are"} narrower than the ${A1} mm kerf and will not be cut${Q0.length?`, at ${Q0.join(", ")}${$1>Q0.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(l0),z.push({info:l0,layers:J,copy:m1=>L6(I,m1)})}Gi(x,M,h);let B=new Map,X=x.filter(I=>!k.has(I)).flatMap(I=>{let N=g4(I);for(let a1 of N)B.set(a1,I);return N}),{found:Z,complete:h1}=Ht(X,i.maxCollisionPairs),H=Z.filter(([I,N])=>B.get(I)!==B.get(N)).map(([I,N,a1])=>[B.get(I)??I,B.get(N)??N,a1,I,N]).filter(([I,N],a1,J)=>J.findIndex(([x1,R1])=>x1===I&&R1===N)===a1);h1||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[I,N,a1,J,x1]of H.slice(0,5)){let R1=(Ot(J,x1)??a1).map(m0);h.push(`Parts "${I.name}"${I.copy>1?` (copy ${I.copy})`:""} and "${N.name}"${N.copy>1?` (copy ${N.copy})`:""} collide in the assembly, around [${R1.join(", ")}]. Check their edges and where they are placed.`)}if(H.length>5&&h.push(`${H.length-5} more pairs of parts collide in the assembly.`),Ki(T,h),x.length&&w.length){let I=[...new Set(w.map(N=>`"${N.name}"`))];h.push(`${I.length===1?"Part":"Parts"} ${I.slice(0,5).join(", ")}${I.length>5?` and ${I.length-5} more`:""} ${I.length===1?"has":"have"} no at or rotate, so ${I.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...Tt(x,w))}let U=0;for(let I of z){let N=0;for(let a1 of I.layers.values()){for(let J of a1.regions)N+=J.length;for(let J of a1.lines)N+=J.length}U+=N*I.info.qty}if(U>i.maxOutputPoints)throw new o1(`The files would have ${U} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let Y=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(Y)||!(Number.isFinite(Y[0])&&Y[0]>0)||!(Number.isFinite(Y[1])&&Y[1]>0))throw new o1("$sheet must be [width, height], both more than 0");let Q=e.gap??q0(l("$gap")??3),W=e.margin??Q;if(!(Number.isFinite(Q)&&Q>=0))throw new o1("$gap must be a number, 0 or more");if(!(Number.isFinite(W)&&W>=0))throw new o1("margin must be a number, 0 or more");let F1=e.nest??l("$nest")===!0,L1=e.layout??(l("$layout")==="none"?"none":"pack"),g1=[...u.keys()].filter(I=>!["engrave","score","cut","guide"].includes(I)),X1=I=>(u.get(I)?.order??0)*2+(f(I)==="fill"?0:1),E=["engrave",...g1.map((I,N)=>[I,N]).sort((I,N)=>X1(I[0])-X1(N[0])||I[1]-N[1]).map(([I])=>I),"score","cut","guide"].map(I=>u.get(I)).filter(Boolean),D=E.filter(I=>I.side!=="back"),e1=[...E.filter(I=>I.side==="back")],u1=l("$registration")===!0;u1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),u1&&!D.some(I=>I.name==="registration")&&D.push(u.get("registration"));let t1=[],V=[1,0,0,-1,0,0],n1=I=>X0(I)??[0,0,0,0],G=(I,N)=>u3({layers:I,parts:[]},N).layers;if(L1==="none"){let I=[];for(let x1 of z)for(let R1=0;R1<x1.info.qty;R1++)I.push({part:x1.info.name,copy:x1.copy(R1),layers:G(x1.layers,V),rotated:!1});let N=new Map;for(let x1 of I)for(let[R1,w0]of x1.layers){let Y1=N.get(R1)??{regions:[],lines:[]};for(let A1 of w0.regions)Y1.regions.push(A1);for(let A1 of w0.lines)Y1.lines.push(A1);N.set(R1,Y1)}let a1=n1(N),J=[1,0,0,1,W-a1[0],W-a1[1]];for(let x1 of I)x1.layers=G(x1.layers,J),x1.offset=[J[4],J[5]];t1.push(k1(I,a1[2]-a1[0]+2*W,a1[3]-a1[1]+2*W,z[0]?.info))}else{let I=new Map;for(let N of z){let a1=`${N.info.material}|${N.info.thickness}`;I.set(a1,[...I.get(a1)??[],N])}for(let N of I.values()){let[a1,J]=Y,x1=[];for(let B1 of N){let c0=G(B1.layers,V),b0=n1(c0),c2=b0[2]-b0[0],G0=b0[3]-b0[1],P3=!1;(c2>a1-2*W||G0>J-2*W)&&G0<=a1-2*W&&c2<=J-2*W&&(c0=G(c0,[0,1,-1,0,0,0]),b0=n1(c0),c2=b0[2]-b0[0],G0=b0[3]-b0[1],P3=!0),(c2>a1-2*W||G0>J-2*W)&&h.push(`Part "${B1.info.name}" (${m0(c2)} x ${m0(G0)} mm) is bigger than the ${a1} x ${J} mm sheet.`),c0=G(c0,[1,0,0,1,-b0[0],-b0[1]]);for(let W2=0;W2<B1.info.qty;W2++)x1.push({info:B1.info,layers:c0,w:c2,h:G0,copy:B1.copy(W2),rotated:P3})}let R1=(B1,c0)=>c0.h-B1.h||c0.w-B1.w,w0=B1=>{let c0=0,b0=W,c2=W,G0=0,P3=!1;for(let W2 of B1)b0>W&&b0+W2.w>a1-W&&(b0=W,c2+=G0+Q,G0=0),P3&&c2+W2.h>J-W&&(c0++,[b0,c2,G0]=[W,W,0]),P3=!0,b0+=W2.w+Q,G0=Math.max(G0,W2.h);return c0+(P3?1:0)};x1.sort(R1);let Y1=Xi(x1,Q,B1=>f(B1)==="cut",[a1-2*W,J-2*W]).sort(R1),A1=Y1.length<x1.length&&w0(Y1)<w0(x1)?Y1:x1,l0=F1?Wi(A1,Q,B1=>f(B1)==="cut"):A1,m1=[],v1=W,y1=W,T1=0,$1=0,J1=0,Q0=()=>{if(m1.length&&t1.length>=i.maxSheets)throw new o1(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);m1.length&&t1.push(k1(m1,Math.max($1+W,1),Math.max(J1+W,1),N[0].info)),m1=[],v1=W,y1=W,T1=0,$1=0,J1=0};for(let B1 of l0){v1>W&&v1+B1.w>a1-W&&(v1=W,y1+=T1+Q,T1=0),m1.length&&y1+B1.h>J-W&&Q0(),m1.push({part:B1.info.name,copy:B1.copy,layers:G(B1.layers,[1,0,0,1,v1,y1]),rotated:B1.rotated});for(let c0 of B1.inner??[])m1.push({part:c0.item.info.name,copy:c0.item.copy,layers:G(c0.item.layers,[1,0,0,1,v1+c0.dx,y1+c0.dy]),rotated:c0.item.rotated});$1=Math.max($1,v1+B1.w),J1=Math.max(J1,y1+B1.h),v1+=B1.w+Q,T1=Math.max(T1,B1.h)}Q0()}}function k1(I,N,a1,J){let x1=m0(N),R1=m0(a1);if(u1){let A1=Math.min(5,W-1);if(!(A1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let l0=(m1,v1)=>[[m1,v1],[m1+A1,v1],[m1+A1,v1+A1],[m1,v1+A1]];I=[...I,{part:"registration",copy:1,layers:new Map([["registration",{regions:[l0(.5,.5),l0(x1-.5-A1,.5),l0(.5,R1-.5-A1)],lines:[]}]]),rotated:!1}]}}let w0=I.some(A1=>e1.some(l0=>A1.layers.has(l0.name))),Y1=w0?I.map(A1=>({...A1,layers:G(A1.layers,[-1,0,0,1,x1,0])})):[];return{width:x1,height:R1,material:J?.material??"material",thickness:J?.thickness??0,items:I,paths:U4(I,D),svg:B4(I,x1,R1,D),dxf:S6(I,x1,R1,D),...w0&&{back:{paths:U4(Y1,e1),svg:B4(Y1,x1,R1,e1),dxf:S6(Y1,x1,R1,e1)}}}}let r1=t1.length===1?t1[0]:void 0,U1=r1?[]:t1.flatMap((I,N)=>{let a1=t1.slice(0,N).reduce((J,x1)=>J+x1.height+10,0);return I.items.map(J=>({...J,layers:G(J.layers,[1,0,0,1,0,a1])}))}),c1=m0(Math.max(1,...t1.map(I=>I.width))),V1=m0(Math.max(1,t1.reduce((I,N)=>I+N.height,0)+10*Math.max(0,t1.length-1))),o0=r1?r1.svg:B4(U1,c1,V1,D),d0=r1?r1.paths:U4(U1,D);return{sheets:t1,width:r1?.width??c1,height:r1?.height??V1,paths:d0,svg:o0,parts:y,assembly:x,layers:[...D,...e1],warnings:h,echoes:o.echoes,...b&&{analysis:b},hardware:o.hardware,steps:o.steps}}function A6(t){if(!t.includes("*"))return n=>n===t;let e=new RegExp(`^${t.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return n=>e.test(n)}function Bi(t,e){if(!e||!t.length||e[0]===0&&e[1]===0)return t;let n=[...t];for(let r of t){let c=r.map(([a,s])=>[a+e[0],s+e[1]]);n.push(c);for(let a=0;a<r.length;a++){let s=(a+1)%r.length,i=[r[a],r[s],c[s],c[a]];Math.abs(M1(i))>1e-9&&n.push(M1(i)<0?i.reverse():i)}}return i1(n,"nonzero")}function C6(t,e){let n=new Map(t);for(let[r,c]of t)n.set(r,{regions:k0(c.regions,e),lines:W0(c.lines,e,"outside")});return n}function _i(t,e,n,r=[]){if(!t.some(l=>l.slots||l.bores))return;let c=new Map,a=l=>{let h=c.get(l);return h||(h=i1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},s=l=>(l.placements??[]).flatMap(h=>g4({name:l.name,copy:0,placed:!0,matrix:Z0(h),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),i=new Map,o=new Map;for(let l of t){if(!l.slots&&!l.bores)continue;if(!l.placements){n.push(`Part "${l.name}" has ${l.slots?"slots":"bores"} but no at or rotate, so they can't be found.`);continue}let h=[];for(let x of l.bores??[]){let M=x.startsWith("!"),w=A6(M?x.slice(1):x),k=r.filter(z=>w(z.label??"")||w(z.kind));!k.length&&!M&&n.push(`Part "${l.name}": no hardware "${x}" to bore for.`);for(let z of k)M?h.splice(0,h.length,...h.filter(S=>S!==z)):h.includes(z)||h.push(z)}let u=!1,f=new Set;for(let x of l.slots??[]){let M=x.startsWith("!"),w=A6(M?x.slice(1):x),k=t.filter(z=>z!==l&&w(z.name));!k.length&&!M&&n.push(`Part "${l.name}": no part "${x}" to cut slots for.`);for(let z of k)M?f.delete(z):f.add(z)}let d=new Map,m=[...f].flatMap(x=>s(x).map(M=>(d.set(M,x.name),M))),g=new Set,p=(l.placements??[]).map(x=>i1(g4({name:l.name,copy:0,placed:!0,matrix:Z0(x),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).flatMap(M=>{let w=[];if(l.slots){let k=m.map(S=>$t(M,[S],0));for(let S=0;S<k.length;S++)for(let A=S+1;A<k.length;A++){let[L,C]=[d.get(m[S]),d.get(m[A])];if(!k[S].length||!k[A].length||L===C||!L||!C)continue;let P=a0(k[S],k[A]);if(P.reduce((R,q)=>R+Math.abs(M1(q)),0)>.01){let R=P.flat().map(h1=>h1[0]),q=P.flat().map(h1=>h1[1]),[T,B,X,Z]=[Math.min(...R),Math.min(...q),Math.max(...R),Math.max(...q)];g.add(`Tabs of "${L}" and "${C}" meet in the same slot in "${l.name}", at [${m0(T)}, ${m0(B)}] to [${m0(X)}, ${m0(Z)}] in its coordinates. Move one's tabs along the edge.`)}}let z=k.flat();w=z.length?Bi(n0(i1(z),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let z=Nt(M,k,l.fit??z5.turn);z&&a0([z],M.outline).some(S=>Math.abs(M1(S))>1e-4)&&(w.push(z),u=!0)}return l.bends?a0(w,n0(M.outline,1,"miter")):w}))),v=(x,M)=>h3(x,M).reduce((w,k)=>w+Math.abs(M1(k)),0)>.001,y=l.stack??1;if(y>1){let x=w=>p.filter((k,z)=>z%y===w),M=Array.from({length:y},(w,k)=>i1(x(k).flat()));if(M.slice(1).some(w=>v(M[0],w))){Array.from({length:y},(w,k)=>x(k)).some(w=>w.slice(1).some(k=>v(w[0],k)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),o.set(l,M);continue}}p.slice(1).some(x=>v(p[0],x))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);for(let x of g)n.push(x);l.bores&&h.length&&!u&&n.push(`Part "${l.name}": none of ${l.bores.map(x=>`"${x}"`).join(", ")} pass through it, so it has no bores.`);let b=i1(p.flat());if(!b.length){l.slots&&!l.slots.some(x=>x.includes("*"))&&n.push(`Part "${l.name}": none of ${l.slots.map(x=>`"${x}"`).join(", ")} pass through it, so it has no slots.`);continue}i.set(l,b)}for(let[l,h]of i)l.layers=C6(l.layers,h);for(let[l,h]of o){let u=h.length,f=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/u,layers:d.length?C6(l.layers,d):l.layers,placements:l.placements.filter((g,p)=>p%u===m),stack:void 0}));t.splice(t.indexOf(l),1,...f)}}function ji(t,e,n){if(!t.some(i=>i.halving))return;let r=i=>i1([...i.layers].filter(([o])=>e(o)==="cut").flatMap(([,o])=>o.regions)),c=i=>{let o=r(i);return(i.placements??[]).map(l=>({matrix:Z0(l),thickness:i.thickness,outline:o}))},a=new Map,s=(i,o,l)=>{let h=a.get(i)??(i.placements??[]).map(()=>[]);h[o].push(...l),a.set(i,h)};for(let i of t){if(!i.halving)continue;if(!i.placements){n.push(`Part "${i.name}" has halving but no at or rotate, so the crossings can't be found.`);continue}let o=new Set;for(let f of i.halving){let d=f.startsWith("!"),m=A6(d?f.slice(1):f),g=t.filter(p=>p!==i&&m(p.name));!g.length&&!d&&n.push(`Part "${i.name}": no part "${f}" to halve with.`);for(let p of g)d?o.delete(p):o.add(p)}let l=0,h=0,u=c(i);for(let f of o){if(i.bends||f.bends){n.push(`Parts "${i.name}" and "${f.name}": halving joints can't go in a bent part.`);continue}if(!f.placements)continue;let d=c(f);u.forEach((m,g)=>d.forEach((p,v)=>{let y=Gt(m,p,i.clearance??.1);h+=y.thin,y.a.length&&(l++,s(i,g,y.a),s(f,v,y.b))}))}h&&n.push(`Part "${i.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&o.size&&!i.halving.some(f=>f.includes("*"))&&n.push(`Part "${i.name}" crosses none of ${i.halving.map(f=>`"${f}"`).join(", ")}, so it has no halving slots.`)}for(let[i,o]of a){let l=o.map(h=>i1(h));l.slice(1).some(h=>h3(l[0],h).reduce((u,f)=>u+Math.abs(M1(f)),0)>.001)&&n.push(`Copies of part "${i.name}" are halved in different places; they all get every slot. Make them separate parts to cut each its own.`),i.layers=C6(i.layers,i1(l.flat()))}}function Gi(t,e,n){let r=new Map;for(let[c,a]of e){let s=t.filter(M=>M.name===a&&M.placed);if(!s.length){r.has(a)||n.push(`Part "${c.name}" is on "${a}", which is not a placed part.`),r.set(a,0);continue}let i=[...e].filter(([M,w])=>M.name===c.name&&w===a).length,o=s.length===i?s[c.copy-1]:s[0];if(!o?.bends?.length)continue;let[l,h,u,f]=[1/0,1/0,-1/0,-1/0];for(let M of c.outline)for(let[w,k]of M)l=Math.min(l,w),h=Math.min(h,k),u=Math.max(u,w),f=Math.max(f,k);let d=c.matrix,[m,g,p]=[(l+u)/2,(h+f)/2,c.thickness/2],v=[d[0]*m+d[1]*g+d[2]*p+d[3],d[4]*m+d[5]*g+d[6]*p+d[7],d[8]*m+d[9]*g+d[10]*p+d[11]],y=p0(o.matrix),b=y[0]*v[0]+y[1]*v[1]+y[2]*v[2]+y[3],x=m4(o.bends,o.thickness)[Rt(o.bends,b)];c.matrix=q1(o.matrix,q1(x,q1(y,c.matrix)))}}function Wi(t,e,n){var l;let r=[],c=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)M1(m)<0&&u.push([...m].reverse());return u.length?n0(i1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let m of h)for(let g=0,p=m.length-1;g<m.length;p=g++){let[v,y]=m[p],[b,x]=m[g];y<=f?x>f&&(b-v)*(f-y)-(u-v)*(x-y)>0&&d++:x<=f&&(b-v)*(f-y)-(u-v)*(x-y)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let m of d.regions)M1(m)>0&&u.push(m);return i1(u)},i=(h,u)=>{let{w:f,h:d}=u,m=s(u),g=[];for(let p of m)for(let v=0;v<p.length;v+=Math.max(1,Math.floor(p.length/12)))g.push(p[v]);for(let p of h){if(M1(p)<=0)continue;let[v,y,b,x]=[1/0,1/0,-1/0,-1/0];for(let[w,k]of p)v=Math.min(v,w),y=Math.min(y,k),b=Math.max(b,w),x=Math.max(x,k);if(b-v<f||x-y<d)continue;let M=Math.max(.5,Math.min(f,d,b-v-f+1,x-y-d+1)/4);for(let w=y;w<=x-d+1e-9;w+=M)for(let k=v;k<=b-f+1e-9;k+=M){if(!g.every(([S,A])=>a(h,S+k,A+w)))continue;let z=m.map(S=>S.map(([A,L])=>[A+k,L+w]));if(k0(z,h).reduce((S,A)=>S+Math.abs(M1(A)),0)<.01)return[k,w]}}},o=[];for(let h of t){let u=!1;for(let d of h.inner?.length?[]:r){let m=i(d.region,h);if(!m)continue;let[g,p]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+g,dy:d.oy+p}),d.region=k0(d.region,n0(s(h).map(y=>y.map(([b,x])=>[b+g,x+p])),e,"miter"));let v=c(h);v.length&&r.push({host:d.host,ox:d.ox+g,oy:d.oy+p,region:v}),u=!0;break}if(u)continue;o.push(h);let f=c(h);f.length&&r.push({host:h,ox:0,oy:0,region:f})}return o}function Xi(t,e,n,r){let c=new Map;for(let i of t)c.set(i.info,[...c.get(i.info)??[],i]);let a=[],s=(i,o)=>u3({layers:i,parts:[]},o).layers;for(let[,i]of c){let o=i[0],l=i1([...o.layers].filter(([d])=>n(d)).flatMap(([,d])=>d.regions.filter(m=>M1(m)>0))),h=l.reduce((d,m)=>d+M1(m),0)/(o.w*o.h),u=i.length>=2&&l.length&&h<.75?Zi(l,o.w,o.h,e,r):void 0;if(!u){a.push(...i);continue}let f=s(o.layers,[-1,0,0,-1,o.w,o.h]);for(let d=0;d<i.length;d+=u.n){let m=i.slice(d,d+u.n);if(m.length===1){a.push(m[0]);continue}let g=u.at.slice(0,m.length),p=Math.min(...g.map(x=>x[0])),v=Math.min(...g.map(x=>x[1])),y=Math.max(...g.map(x=>x[0]+o.w))-p,b=Math.max(...g.map(x=>x[1]+o.h))-v;a.push({...m[0],layers:s(m[0].layers,[1,0,0,1,g[0][0]-p,g[0][1]-v]),w:y,h:b,inner:m.slice(1).map((x,M)=>({item:{...x,layers:(M+1)%2?f:x.layers},dx:g[M+1][0]-p,dy:g[M+1][1]-v}))})}}return a}function Zi(t,e,n,r,c){let s=n0(t.map(b=>Yi(b,.25)).filter(b=>b.length>=3),.25,"miter"),i=n0(s,r,"miter"),o=s.map(b=>b.map(([x,M])=>[e-x,n-M])),l=(b,[x,M])=>b.map(w=>w.map(([k,z])=>[k+x,z+M])),h=(b,x)=>!a0(b,x).some(M=>Math.abs(M1(M))>.001),u=(b,x,M,w)=>{let[k,z]=[0,w];if(h(b,l(x,M(z)))){if(h(b,l(x,M(k))))return M(k);for(let S=0;S<10;S++){let A=(k+z)/2;h(b,l(x,M(A)))?z=A:k=A}return M(z)}},f;for(let b of[!1,!0])for(let x=-10;x<=10;x++){let M=x/10*(b?e:n),w=u(i,o,S=>b?[M,S]:[S,M],(b?n:e)+r);if(!w)continue;let k=Math.max(e,w[0]+e)-Math.min(0,w[0]),z=Math.max(n,w[1]+n)-Math.min(0,w[1]);k>c[0]||z>c[1]||k*z<.85*2*e*n&&(!f||k*z<f.area)&&(f={d:w,across:b,area:k*z})}if(!f)return;let{d,across:m}=f,g=i1([...i,...n0(l(o,d),r,"miter")]),v=u(g,s,b=>m?[0,b]:[b,0],2*((m?n:e)+r)+Math.abs(m?d[1]:d[0])),y=[[0,0],[d[0],d[1]]];if(v){let b=x=>Math.max(...x.map(M=>M[0]+e))-Math.min(...x.map(M=>M[0]))<=c[0]&&Math.max(...x.map(M=>M[1]+n))-Math.min(...x.map(M=>M[1]))<=c[1];for(let x=2;x<500;x++){let M=Math.floor(x/2),w=x%2?[d[0]+M*v[0],d[1]+M*v[1]]:[M*v[0],M*v[1]];if(!b([...y,w]))break;let k=l(x%2?o:s,w),z=i1(y.slice(Math.max(0,y.length-3)).map((S,A,L)=>{let C=y.length-L.length+A;return n0(l(C%2?o:s,S),r,"miter")}).flat());if(!h(z,k))break;y.push(w)}}return{at:y,n:y.length}}function Yi(t,e){if(t.length<8)return t;let n=i=>{let o=new Uint8Array(i.length);o[0]=o[i.length-1]=1;let l=[[0,i.length-1]];for(;l.length;){let[h,u]=l.pop(),[f,d]=i[h],[m,g]=i[u],p=Math.hypot(m-f,g-d),v=-1,y=-1;for(let b=h+1;b<u;b++){let[x,M]=i[b],w=p?Math.abs((m-f)*(d-M)-(f-x)*(g-d))/p:Math.hypot(x-f,M-d);w>v&&([v,y]=[w,b])}v>e&&(o[y]=1,l.push([h,y],[y,u]))}return i.filter((h,u)=>o[u])},r=i=>Math.hypot(i[0]-t[0][0],i[1]-t[0][1]),c=1;for(let i=2;i<t.length;i++)r(t[i])>r(t[c])&&(c=i);let a=n(t.slice(0,c+1)),s=n([...t.slice(c),t[0]]);return[...a,...s.slice(1,-1)]}function L6(t,e){if(!t.copies)return e+1;let n=t.stack??1;return(t.copies[Math.floor(e/n)]-1)*n+e%n+1}function Ji(t,e,n){let r=[...n.keys()],c=[...e.keys()].filter(i=>n.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),a=[];if(c.length<2)return a;let s=i=>i==="engrave"?-1/0:(n.get(i)?.order??0)*2+r.indexOf(i)/r.length;c.sort((i,o)=>s(i)-s(o));for(let i=0;i<c.length-1;i++){let o=n.get(c[i]).side??"front",l=c.slice(i+1).filter(u=>(n.get(u).side??"front")===o);if(!l.length)continue;let h;for(let u of F0(e.get(c[i]).regions)){let f=u.reduce((M,w)=>M+M1(w),0);if(!(f>.001)||!n0(u,-.5,"round").length)continue;let d=u;for(let M of l)d.length&&(d=k0(d,e.get(M).regions));if(d.reduce((M,w)=>M+M1(w),0)>.001*Math.max(1,f))continue;let g=l.filter(M=>a0(u,e.get(M).regions).length),p=g.length?g:l;if(h){h.count++;for(let M of p)h.under.includes(M)||h.under.push(M);continue}let[v,y,b,x]=X0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:c[i],under:p,count:1,at:[m0((v+b)/2),m0((y+x)/2)]}}h&&a.push(h)}return a}function Ki(t,e){for(let n of t.slice(0,5)){let r=n.under.map(a=>`"${a}"`),c=r.length>1?`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`:r[0];e.push(`Part "${n.part}": ${n.count>1?`${n.count} fills`:"a fill"} on layer "${n.layer}" (${n.count>1?"the first ":""}at [${n.at.join(", ")}]) ${n.count>1?"lie":"lies"} wholly under ${c}, stacked above it in the files: printed, ${n.count>1?"they":"it"} won't show, and engraved, ${n.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${n.layer}" a higher order.`)}if(t.length>5){let n=t.slice(5),r=new Set(n.map(a=>a.part)).size,c=[...new Set(n.map(a=>`"${a.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${r} part${r>1?"s":""} (layer${c.length>1?"s":""} ${c.slice(0,5).join(", ")}${c.length>5?" and more":""}).`)}}function Qi(t,e){let n=new Set,r=(c,a)=>{if(!c.glue||n.has(c))return;if(a.includes(c)){e.push(`Part "${c.name}" is glued in a loop of parts; it is left where it is.`),n.add(c);return}let s=t.find(h=>h.name===c.glue.host&&h!==c);if(!s?.placements){e.push(`Part "${c.name}" is glued to "${c.glue.host}", which is not a placed part.`),n.add(c);return}r(s,[...a,c]);let i=s.placements.map(Z0),o=c.glue.face==="top"?s.thickness:-c.thickness,l=c.placements.length/(c.stack??1);c.placements=c.placements.map((h,u)=>{let f=i.length===l?i[Math.floor(u/(c.stack??1))]:i[0];return{...h,matrix:q1(f,q1(B0(0,0,o),Z0(h)))}}),n.add(c)};for(let c of t)r(c,[])}function eo(t,e,n,r){let c=0,a=50;for(let g=0;g<14;g++){let p=(c+a)/2;n0(t,-p,"round").length?c=p:a=p}if(c<1)return[];let s=n0(t,-c*.98,"round"),i=X0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((g,p)=>s.reduce((v,y)=>v+(Z8(y,g,p)?M1(y)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((g,p)=>M1(p)>M1(g)?p:g)[0]);let u=Math.min(6,Math.max(2,c*.9)),f=N4(n,e,{size:u,font:r,halign:"center",valign:"center",spacing:1}),d=X0(new Map([["t",{regions:f,lines:[]}]])),m=d?Math.min(1,1.6*c/Math.max(d[2]-d[0],1e-9)):1;return f.map(g=>g.map(([p,v])=>[o-p*m,l+v*m]).reverse())}function Z8(t,e,n){let r=!1;for(let c=0,a=t.length-1;c<t.length;a=c++){let[s,i]=t[c],[o,l]=t[a];i>n!=l>n&&e<(o-s)*(n-i)/(l-i)+s&&(r=!r)}return r}function J8(t){switch(t.kind){case"num":return t.unit?{ok:!1}:{ok:!0,value:t.value};case"str":case"bool":return{ok:!0,value:t.value};case"unary":return t.op==="-"&&t.arg.kind==="num"?{ok:!0,value:-t.arg.value}:{ok:!1};case"list":{let e=[];for(let n of t.items){if(n.kind!=="item")return{ok:!1};let r=J8(n.expr);if(!r.ok||typeof r.value!="number")return{ok:!1};e.push(r.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function Y8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function K8(t){let{program:e,comments:n}=l2(t),r=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),c=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),a=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),s=[];for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let o=J8(i.value);if(!o.ok)continue;let l=r.filter(g=>g.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(l.toLowerCase()==="hidden")continue;let h=c.get(i.pos.line),u=a.get(i.pos.line-1)??"",f=o.value,d={name:i.name,caption:u,group:l,type:typeof f=="number"||Array.isArray(f)?"number":typeof f=="boolean"?"boolean":"string",initial:f,span:i.span},m=h?/^\[(.*)\](\s+drive)?$/.exec(h.trim()):null;if(m?.[2]&&d.type==="number"&&typeof f=="number"&&(d.drive=!0),m){let g=m[1];if(g.includes(",")||/[a-zA-Z"]/.test(g)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(g))d.options=g.split(",").map(p=>{let[v,y]=p.split(":").map(M=>M.trim().replace(/^"|"$/g,"")),b=Y8(v),x=d.type==="number"&&b!==void 0?b:v;return{name:y??v,value:x}});else{let p=g.split(":").map(Y8);p.every(v=>v!==void 0)&&(p.length===1?d.max=p[0]:p.length===2?(d.min=p[0],d.max=p[1]):(d.min=p[0],d.step=p[1],d.max=p[2]))}}s.push(d)}return{parameters:s}}var to=8,no=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,ro=(t,e)=>Math.max(1,no.exec(t.slice(e-1))?.[0].length??1);function Q8(t,e,n={}){if(!(t instanceof o1))return`error: ${t instanceof Error?t.message:String(t)}`;let r=n.file??"design.kerf",c=(o,l,h)=>`${o?`<${o}>`:r}:${l}:${h}`,a=o=>o===void 0?e:(Object.prototype.hasOwnProperty.call(P5,o)?P5[o]:void 0)??n.resolve?.(o),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${c(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
|
|
2646
|
-
`)
|
|
2647
|
-
`)}function co(t,e){let n=a=>`in ${a.kind==="module"?"module ":""}${a.name}(), called at ${e(a.file,a.line,a.col)}${a.count>1?` (${a.count} times)`:""}`,r=t.trace.slice(0,to).map(n),c=t.trace.length-r.length+t.traceMore;return c&&r.push(`and ${c} more call${c===1?"":"s"}`),r}var en=new Set(["module","function","if","else","for","let","each","use","include"]),ao=new Set(["true","false","undef"]),so=new Set(["for","if","let","function"]),P6={"(":")","[":"]","{":"}"},io=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function oo(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let r=n+1;for(;t[r]!=='"';)r+=t[r]==="\\"?2:1;return t.slice(n,r+1)}function E6(t){let{tokens:e}=N3(t),n=[],r=0,c=0,a=s=>{for(;r<s;)if(t[r]===`
|
|
2648
|
-
`)
|
|
2649
|
-
|
|
2650
|
-
`)
|
|
3024
|
+
`}function S8(t){switch(t.kind){case"num":return t.unit?{ok:!1}:{ok:!0,value:t.value};case"str":case"bool":return{ok:!0,value:t.value};case"unary":return t.op==="-"&&t.arg.kind==="num"?{ok:!0,value:-t.arg.value}:{ok:!1};case"list":{let e=[];for(let n of t.items){if(n.kind!=="item")return{ok:!1};let r=S8(n.expr);if(!r.ok||typeof r.value!="number")return{ok:!1};e.push(r.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function k8(t){let e=Number(t.trim());return t.trim()!==""&&Number.isFinite(e)?e:void 0}function c5(t){let{program:e,comments:n}=e2(t),r=n.filter(i=>i.block&&/^\[[^\]]+\]$/.test(i.text)),c=new Map(n.filter(i=>!i.block&&!i.own).map(i=>[i.line,i.text])),a=new Map(n.filter(i=>!i.block&&i.own).map(i=>[i.line,i.text])),s=[],o=new Set;for(let i of e.body){if(i.kind!=="assign"||/^\$f[nas]$/.test(i.name))continue;let l=S8(i.value);if(!l.ok)continue;let h=r.filter(b=>b.line<=i.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(h.toLowerCase()==="hidden")continue;let u=c.get(i.pos.line),f=a.get(i.pos.line-1)??"",d=l.value,p={name:i.name,caption:f,group:h,type:typeof d=="number"||Array.isArray(d)?"number":typeof d=="boolean"?"boolean":"string",initial:d,span:i.span},m=u?/^((?:\[.*\](?:\s+drive)?)?)\s*when\s+(.+)$/.exec(u.trim()):null;m&&(p.when=m[2].trim()),m?.[1]&&o.add(p);let g=m?m[1].trim():u?.trim(),v=g?/^\[(.*)\](\s+drive)?$/.exec(g):null;if(v?.[2]&&p.type==="number"&&typeof d=="number"&&(p.drive=!0),v){let b=v[1];if(b.includes(",")||/[a-zA-Z"]/.test(b)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(b))p.options=b.split(",").map(y=>{let[x,w]=y.split(":").map(z=>z.trim().replace(/^"|"$/g,"")),M=k8(x),k=p.type==="number"&&M!==void 0?M:x;return{name:w??x,value:k}});else{let y=b.split(":").map(k8);y.every(x=>x!==void 0)&&(y.length===1?p.max=y[0]:y.length===2?(p.min=y[0],p.max=y[1]):(p.min=y[0],p.step=y[1],p.max=y[2]))}}s.push(p)}for(let i of s){if(i.when===void 0)continue;if(!o.has(i)&&typeof A8(i.when)=="string"){delete i.when;continue}let l=Ii(i.when,s);l&&(i.whenProblem=l,delete i.when)}return{parameters:s}}function A8(t){try{let e=e2(`when__ = (${t});`).program.body[0];return e?.kind==="assign"?e.value:"it is not an expression"}catch(e){return e.message.replace(/\s*\(line \d+, column \d+\)$/,"")}}var z8=new Set(["==","!=","<","<=",">",">=","&&","||","+","-","*","/","%","!"]);function Ii(t,e){let n=A8(t);if(typeof n=="string")return`its condition (${t}) is not an expression: ${n}`;let r=new Set(e.map(s=>s.name)),c=s=>{switch(s.kind){case"num":case"str":case"bool":case"undef":return;case"var":return r.has(s.name)?void 0:`uses ${s.name}, which is not a setting`;case"list":for(let o of s.items){if(o.kind!=="item")return"uses a list comprehension";let i=c(o.expr);if(i)return i}return;case"unary":return z8.has(s.op)?c(s.arg):`uses ${s.op}`;case"binary":return z8.has(s.op)?c(s.left)??c(s.right):`uses ${s.op}`;case"ternary":return c(s.cond)??c(s.then)??c(s.else);case"index":return c(s.target)??c(s.index);default:return"uses more than settings, values and operators"}},a=c(n);return a?`its condition (${t}) ${a}`:void 0}function Ke(t,e,n){if(t.when===void 0)return!0;let r=Object.fromEntries(n.map(a=>[a.name,a.initial])),c=Object.fromEntries(Object.entries(e).filter(([a])=>Object.prototype.hasOwnProperty.call(r,a)));try{let a=[...n.map(o=>`${o.name} = undef;`),`echo((${t.when}) ? 1 : 0);`];return new o3({overrides:{...r,...c},maxSteps:1e5}).run(e2(a.join(`
|
|
3025
|
+
`)).program).echoes[0]!=="0"}catch{return!0}}var L8=(t,e)=>{let n=0;for(let r=1;r<t.length;r++)n+=Math.hypot(t[r][0]-t[r-1][0],t[r][1]-t[r-1][1]);return e&&t.length>2&&(n+=Math.hypot(t[0][0]-t[t.length-1][0],t[0][1]-t[t.length-1][1])),n},p0=t=>Math.round(t*100)/100;function Qe(t,e={}){for(let[E,R]of Object.entries(e.params??{}))try{G4(E,R)}catch(Z){throw new i1(Z.message)}let{program:n}=e2(t),r=new Set(n.body.flatMap(E=>E.kind==="assign"?[E.name]:[])),c=Object.keys(e.params??{}).filter(E=>!E.startsWith("$")&&!r.has(E)),a=e.fonts?new Xe(e.fonts,e.defaultFont):void 0,s=new o3({overrides:e.params,resolve:e.resolve,fonts:a,maxSteps:e.maxSteps,limits:e.limits}),o=s.limits,i;try{i=s.run(n)}catch(E){let R=E instanceof RangeError?new i1(/call stack/i.test(E.message)?"Recursion too deep: check that it stops, or use fold(), scan() or a list comprehension to go through a long list":"A value grew too large. Is a list or string doubling without end?"):E;throw R instanceof i1&&(R.echoes=s.echoes,R.warnings=[...s.warnings],a?.missing.size&&(R.missingFonts=[...a.missing])),R}let l=E=>i.globals.get(E).value,h=i.warnings;for(let E of c)h.push(`Setting "${E}" is not a variable of the program, so it is ignored.${A3(E,r)}`);let u=i.layers,f=E=>u.get(E)?.mode??"line",d=[...i.shape.parts];[...i.shape.layers.values()].some(E=>E.regions.length||E.lines.length)&&d.unshift({name:"part",qty:1,layers:i.shape.layers,thickness:U0(l("$thickness"))||3,kerf:U0(l("$kerf"))||0,material:b0(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");try{for(let E of c5(t).parameters)E.whenProblem&&h.push(`Setting ${E.name} is always shown: ${E.whenProblem} (line ${t.slice(0,E.span[0]).split(`
|
|
3026
|
+
`).length})`)}catch{}let m=E=>JSON.stringify([E.thickness,E.material,[...E.layers].map(([R,Z])=>[R,Z.regions.map(K=>K.map(([k1,O1])=>[Math.round(k1*100),Math.round(O1*100)])),Z.lines.map(K=>K.map(([k1,O1])=>[Math.round(k1*100),Math.round(O1*100)]))])]),g=new Map,v=new Set;for(let E of d){let R=m(E),Z=E.mirrored?`${E.name}\0mirrored`:E.name,K=g.get(Z);K===void 0?g.set(Z,R):K!==R&&v.add(E.name)}for(let E of v)h.push(`Two different parts are named "${E}"; slots, glue and on = find parts by name, so give each its own.`);Bi(d,h),$i(d,f,h),Hi(d,f,h,i.hardware),Oi(d,f,h);let b=[],y=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,x=[],w=[],M=[],k=new Set,z=[],A=l("$min_width"),S=A===void 0?1.5:U0(A),C=l("$label_parts")===!0,I=l("$join_lines")===!0,L=0;C&&!a&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let T=u.get("engrave-back");C&&a&&T&&T.side!=="back"&&h.push('$label_parts engraves the numbers on the layer "engrave-back", which this program uses for the front; rename that layer to number the parts.');let q=C&&!!a&&(!T||T.side==="back");if(q){let E=u.get("engrave");u.has("engrave-back")||u.set("engrave-back",{name:"engrave-back",mode:"fill",color:E?.color??"#000000",side:"back"})}let P=[];for(let E of d){let R=s1([...E.layers].filter(([g1])=>f(g1)==="cut").flatMap(([,g1])=>g1.regions)),Z;if(E.bends&&R.length){let g1=1/0,L1=-1/0;for(let z1 of R)for(let[m1]of z1)g1=Math.min(g1,m1),L1=Math.max(L1,m1);for(let[z1,m1]of _4(E.bends))(z1<g1-.001||m1>L1+.001)&&h.push(`Part "${E.name}" bends from x = ${q2(z1)} to ${q2(m1)}, beyond the part (x = ${q2(g1)} to ${q2(L1)}); only the part itself bends.`)}if(q&&R.length){Z=++L;let g1=_i(R,String(Z),a,b0(l("$font")??""));if(g1.length){let L1=E.layers.get("engrave-back")??{regions:[],lines:[]};E.layers=new Map(E.layers).set("engrave-back",{regions:[...L1.regions,...g1],lines:L1.lines})}else h.push(`Part "${E.name}" is too small to take its number ${Z}.`)}if(S>0&&R.length){let g1=c0(c0(R,-S/2,"round"),S/2,"round"),L1=R0(g0(R,g1)).filter(z1=>z1.reduce((m1,S1)=>m1+b1(S1),0)>2*S*S);if(L1.length){let z1=L1.slice(0,3).map(m1=>{let[S1,Z1,i0,V1]=J0(new Map([["cut",{regions:m1,lines:[]}]]));return`[${p0((S1+i0)/2)}, ${p0((Z1+V1)/2)}]`});h.push(`Part "${E.name}" is narrower than ${S} mm ($min_width) in ${L1.length} place${L1.length>1?"s":""}, at ${z1.join(", ")}${L1.length>3?" and more":""} in the part's coordinates.`)}}let K=new Map;for(let[g1,L1]of E.layers){if(g1===r2||f(g1)==="guide"&&!e.guides)continue;let z1=s1(L1.regions),m1=L1.lines.filter(S1=>S1.length>=2);if((f(g1)==="line"||f(g1)==="guide")&&(m1=[...m1,...z1.map(S1=>[...S1,S1[0]])],z1=[]),R.length&&f(g1)!=="guide"){let S1=u.get(g1)?.bleed??0,Z1=S1>0?c0(R,S1,"round"):R;f(g1)!=="cut"&&(z1=K1(z1,Z1)),m1=Y0(m1,Z1,"inside")}I&&m1.length>1&&f(g1)!=="guide"&&(m1=en(m1)),(z1.length||m1.length)&&K.set(g1,{regions:z1,lines:m1})}if(P.push(...Ni(E.name,K,u)),R.length){let g1=[];for(let[z1,m1]of K){let S1=u.get(z1);if(S1?.mode==="cut"&&m1.lines.length)for(let Z1 of["front","back"])g1.push({layer:z1,mode:"line",color:"#000000",side:Z1,regions:[],lines:m1.lines});!S1||S1.mode!=="fill"&&S1.mode!=="line"||g1.push({layer:z1,mode:S1.mode,color:S1.color,side:S1.side??"front",regions:m1.regions,lines:m1.lines})}let L1={name:E.name,thickness:E.thickness,material:E.material,outline:R,...g1.length&&{marks:g1}};for(let z1=0;z1<(E.placements?.length??E.qty);z1++)M.push({...L1,copy:a5(E,z1),matrix:F0({at:[0,0,0],rotate:[0,0,0]}),placed:!1});if(E.placements){let z1=new Set;E.placements.forEach((m1,S1)=>{let Z1={...L1,copy:a5(E,S1),matrix:F0(m1),placed:!0,...E.bends&&{bends:E.bends},...E.step&&{step:E.step},...E.stack&&{stack:E.stack}};x.push(Z1);let i0=Z1.matrix.map(V1=>V1.toFixed(6)).join(",");z1.has(i0)&&k.add(Z1),z1.add(i0)}),z1.size<E.placements.length&&h.push(`Copies of part "${E.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let z1=0;z1<E.qty;z1++)w.push({...L1,copy:a5(E,z1),matrix:F0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...E.step&&{step:E.step}})}let k1=R0(R),O1=k1.length;if(O1>1){let g1=m1=>m1.reduce((S1,Z1)=>S1+b1(Z1),0),z1=[...k1].sort((m1,S1)=>g1(S1)-g1(m1)).slice(1,4).map(m1=>{let[S1,Z1,i0,V1]=J0(new Map([["cut",{regions:m1,lines:[]}]]));return`[${p0(S1)}, ${p0(Z1)}] to [${p0(i0)}, ${p0(V1)}]`}).join(", ");h.push(`Part "${E.name}" cuts into ${O1} separate pieces. Join them, or make them separate parts. The smaller ${O1===2?"one is":"ones are"} at ${z1}${O1>4?" and more":""}, in the part's coordinates.`)}let z0=0;for(let[g1,L1]of K)if(f(g1)==="cut"){for(let z1 of L1.regions)z0+=L8(z1,!0);for(let z1 of L1.lines)z0+=L8(z1,!1)}let n0=J0(K)??[0,0,0,0],j1=e.kerf??E.kerf;if(!(Number.isFinite(j1)&&j1>=0))throw new i1("$kerf must be a number, 0 or more");let X0={name:E.name,qty:E.qty,width:p0(n0[2]-n0[0]),height:p0(n0[3]-n0[1]),pieces:O1,cutLength:Math.round(z0),thickness:E.thickness,kerf:j1,material:E.material,...E.stack&&{stack:E.stack},...E.glue&&{glued:E.glue.host},...E.mirrored&&{mirrored:!0},...Z!==void 0&&{label:Z}};if(y&&y.parts.push({name:E.name,kerf:j1,qty:E.qty,...E.stack&&{stack:E.stack},...E.glue&&{glue:E.glue},...E.on&&{on:E.on},cutRegions:R.map(g1=>g1.map(([L1,z1])=>[L1,z1])),cutLines:[...K].filter(([g1])=>f(g1)==="cut").flatMap(([,g1])=>g1.lines.map(L1=>L1.map(([z1,m1])=>[z1,m1])))}),j1>0){for(let[g1,L1]of K)if(f(g1)==="cut"){let z1=L1.regions.filter(Z1=>b1(Z1)<0);L1.regions=c0(L1.regions,j1/2,"round",Math.min(.01,j1/20));let m1=L1.regions.filter(Z1=>b1(Z1)<0),S1=z1.length-m1.length;if(S1>0){let Z1=V1=>{let[X1,d0,O0,Z0]=J0(new Map([["cut",{regions:[V1],lines:[]}]]));return[(X1+O0)/2,(d0+Z0)/2]},i0=z1.map(Z1).filter(([V1,X1])=>!m1.some(d0=>C8(d0,V1,X1))).slice(0,3).map(([V1,X1])=>`[${p0(V1)}, ${p0(X1)}]`);h.push(`Part "${E.name}": ${S1} hole${S1===1?" is":"s are"} narrower than the ${j1} mm kerf and will not be cut${i0.length?`, at ${i0.join(", ")}${S1>i0.length?" and more":""} in the part's coordinates`:""}.`)}}}b.push(X0),z.push({info:X0,layers:K,copy:g1=>a5(E,g1)})}let F=new Map,j=x.filter(E=>!k.has(E)).flatMap(E=>{let R=Se(E);for(let Z of R)F.set(Z,E);return R}),{found:_,complete:Q}=un(j,o.maxCollisionPairs),H=_.filter(([E,R])=>F.get(E)!==F.get(R)).map(([E,R,Z])=>[F.get(E)??E,F.get(R)??R,Z,E,R]).filter(([E,R],Z,K)=>K.findIndex(([k1,O1])=>k1===E&&O1===R)===Z);Q||h.push(`The assembly has more than ${o.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[E,R,Z,K,k1]of H.slice(0,5)){let O1=(fn(K,k1)??Z).map(p0);h.push(`Parts "${E.name}"${E.copy>1?` (copy ${E.copy})`:""} and "${R.name}"${R.copy>1?` (copy ${R.copy})`:""} collide in the assembly, around [${O1.join(", ")}]. Check their edges and where they are placed.`)}if(H.length>5&&h.push(`${H.length-5} more pairs of parts collide in the assembly.`),Ui(P,h),x.length&&w.length){let E=[...new Set(w.map(R=>`"${R.name}"`))];h.push(`${E.length===1?"Part":"Parts"} ${E.slice(0,5).join(", ")}${E.length>5?` and ${E.length-5} more`:""} ${E.length===1?"has":"have"} no at or rotate, so ${E.length===1?"it lies":"they lie"} flat beside the assembly.`),x.push(...on(x,w))}let B=0;for(let E of z){let R=0;for(let Z of E.layers.values()){for(let K of Z.regions)R+=K.length;for(let K of Z.lines)R+=K.length}B+=R*E.info.qty}if(B>o.maxOutputPoints)throw new i1(`The files would have ${B} points, more than the limit of ${o.maxOutputPoints}. Use fewer copies or simpler shapes.`);let Y=e.sheet??(i.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(Y)||!(Number.isFinite(Y[0])&&Y[0]>0)||!(Number.isFinite(Y[1])&&Y[1]>0))throw new i1("$sheet must be [width, height], both more than 0");let e1=e.gap??U0(l("$gap")??3),X=e.margin??e1;if(!(Number.isFinite(e1)&&e1>=0))throw new i1("$gap must be a number, 0 or more");if(!(Number.isFinite(X)&&X>=0))throw new i1("margin must be a number, 0 or more");let M1=e.nest??l("$nest")===!0,v1=e.layout??(l("$layout")==="none"?"none":"pack"),p1=[...u.keys()].filter(E=>!["engrave","score","cut","guide"].includes(E)),G1=E=>(u.get(E)?.order??0)*2+(f(E)==="fill"?0:1),V=["engrave",...p1.map((E,R)=>[E,R]).sort((E,R)=>G1(E[0])-G1(R[0])||E[1]-R[1]).map(([E])=>E),"score","cut","guide"].map(E=>u.get(E)).filter(Boolean),U=V.filter(E=>E.side!=="back"),r1=[...V.filter(E=>E.side==="back")],h1=l("$registration")===!0;h1&&!u.has("registration")&&u.set("registration",{name:"registration",mode:"fill",color:"#000000"}),h1&&!U.some(E=>E.name==="registration")&&U.push(u.get("registration"));let a1=[],x1=[1,0,0,-1,0,0],J1=E=>J0(E)??[0,0,0,0],q1=(E,R)=>v3({layers:E,parts:[]},R).layers;if(v1==="none"){let E=[];for(let k1 of z)for(let O1=0;O1<k1.info.qty;O1++)E.push({part:k1.info.name,copy:k1.copy(O1),layers:q1(k1.layers,x1),rotated:!1});let R=new Map;for(let k1 of E)for(let[O1,z0]of k1.layers){let n0=R.get(O1)??{regions:[],lines:[]};for(let j1 of z0.regions)n0.regions.push(j1);for(let j1 of z0.lines)n0.lines.push(j1);R.set(O1,n0)}let Z=J1(R),K=[1,0,0,1,X-Z[0],X-Z[1]];for(let k1 of E)k1.layers=q1(k1.layers,K),k1.offset=[K[4],K[5]];a1.push(f0(E,Z[2]-Z[0]+2*X,Z[3]-Z[1]+2*X,z[0]?.info))}else{let E=new Map;for(let R of z){let Z=`${R.info.material}|${R.info.thickness}`;E.set(Z,[...E.get(Z)??[],R])}for(let R of E.values()){let[Z,K]=Y,k1=[];for(let V1 of R){let X1=q1(V1.layers,x1),d0=J1(X1),O0=d0[2]-d0[0],Z0=d0[3]-d0[1],$3=!1;(O0>Z-2*X||Z0>K-2*X)&&Z0<=Z-2*X&&O0<=K-2*X&&(X1=q1(X1,[0,1,-1,0,0,0]),d0=J1(X1),O0=d0[2]-d0[0],Z0=d0[3]-d0[1],$3=!0),(O0>Z-2*X||Z0>K-2*X)&&h.push(`Part "${V1.info.name}" (${p0(O0)} x ${p0(Z0)} mm) is bigger than the ${Z} x ${K} mm sheet.`),X1=q1(X1,[1,0,0,1,-d0[0],-d0[1]]);for(let Z2=0;Z2<V1.info.qty;Z2++)k1.push({info:V1.info,layers:X1,w:O0,h:Z0,copy:V1.copy(Z2),rotated:$3})}let O1=(V1,X1)=>X1.h-V1.h||X1.w-V1.w,z0=V1=>{let X1=0,d0=X,O0=X,Z0=0,$3=!1;for(let Z2 of V1)d0>X&&d0+Z2.w>Z-X&&(d0=X,O0+=Z0+e1,Z0=0),$3&&O0+Z2.h>K-X&&(X1++,[d0,O0,Z0]=[X,X,0]),$3=!0,d0+=Z2.w+e1,Z0=Math.max(Z0,Z2.h);return X1+($3?1:0)};k1.sort(O1);let n0=Fi(k1,e1,V1=>f(V1)==="cut",[Z-2*X,K-2*X]).sort(O1),j1=n0.length<k1.length&&z0(n0)<z0(k1)?n0:k1,X0=M1?Ri(j1,e1,V1=>f(V1)==="cut"):j1,g1=[],L1=X,z1=X,m1=0,S1=0,Z1=0,i0=()=>{if(g1.length&&a1.length>=o.maxSheets)throw new i1(`The parts need more than ${o.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);g1.length&&a1.push(f0(g1,Math.max(S1+X,1),Math.max(Z1+X,1),R[0].info)),g1=[],L1=X,z1=X,m1=0,S1=0,Z1=0};for(let V1 of X0){L1>X&&L1+V1.w>Z-X&&(L1=X,z1+=m1+e1,m1=0),g1.length&&z1+V1.h>K-X&&i0(),g1.push({part:V1.info.name,copy:V1.copy,layers:q1(V1.layers,[1,0,0,1,L1,z1]),rotated:V1.rotated});for(let X1 of V1.inner??[])g1.push({part:X1.item.info.name,copy:X1.item.copy,layers:q1(X1.item.layers,[1,0,0,1,L1+X1.dx,z1+X1.dy]),rotated:X1.item.rotated});S1=Math.max(S1,L1+V1.w),Z1=Math.max(Z1,z1+V1.h),L1+=V1.w+e1,m1=Math.max(m1,V1.h)}i0()}}function f0(E,R,Z,K){let k1=p0(R),O1=p0(Z);if(h1){let j1=Math.min(5,X-1);if(!(j1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let X0=(g1,L1)=>[[g1,L1],[g1+j1,L1],[g1+j1,L1+j1],[g1,L1+j1]];E=[...E,{part:"registration",copy:1,layers:new Map([["registration",{regions:[X0(.5,.5),X0(k1-.5-j1,.5),X0(.5,O1-.5-j1)],lines:[]}]]),rotated:!1}]}}let z0=E.some(j1=>r1.some(X0=>j1.layers.has(X0.name))),n0=z0?E.map(j1=>({...j1,layers:q1(j1.layers,[-1,0,0,1,k1,0])})):[];return{width:k1,height:O1,material:K?.material??"material",thickness:K?.thickness??0,items:E,paths:Ye(E,U),svg:Je(E,k1,O1,U),dxf:Ut(E,k1,O1,U),...z0&&{back:{paths:Ye(n0,r1),svg:Je(n0,k1,O1,r1),dxf:Ut(n0,k1,O1,r1)}}}}let m0=a1.length===1?a1[0]:void 0,D=m0?[]:a1.flatMap((E,R)=>{let Z=a1.slice(0,R).reduce((K,k1)=>K+k1.height+10,0);return E.items.map(K=>({...K,layers:q1(K.layers,[1,0,0,1,0,Z])}))}),J=p0(Math.max(1,...a1.map(E=>E.width))),t1=p0(Math.max(1,a1.reduce((E,R)=>E+R.height,0)+10*Math.max(0,a1.length-1))),w1=m0?m0.svg:Je(D,J,t1,U),n1=m0?m0.paths:Ye(D,U);return{sheets:a1,width:m0?.width??J,height:m0?.height??t1,paths:n1,svg:w1,parts:b,assembly:x,flat:M,layers:[...U,...r1],warnings:h,echoes:i.echoes,...y&&{analysis:y},hardware:i.hardware,steps:i.steps}}function Bt(t){if(!t.includes("*"))return n=>n===t;let e=new RegExp(`^${t.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return n=>e.test(n)}function Vi(t,e){if(!e||!t.length||e[0]===0&&e[1]===0)return t;let n=[...t];for(let r of t){let c=r.map(([a,s])=>[a+e[0],s+e[1]]);n.push(c);for(let a=0;a<r.length;a++){let s=(a+1)%r.length,o=[r[a],r[s],c[s],c[a]];Math.abs(b1(o))>1e-9&&n.push(b1(o)<0?o.reverse():o)}}return s1(n,"nonzero")}function _t(t,e){let n=new Map(t);for(let[r,c]of t)n.set(r,{regions:g0(c.regions,e),lines:Y0(c.lines,e,"outside")});return n}function Hi(t,e,n,r=[]){if(!t.some(l=>l.slots||l.bores))return;let c=new Map,a=l=>{let h=c.get(l);return h||(h=s1([...l.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),c.set(l,h)),h},s=l=>(l.placements??[]).flatMap(h=>Se({name:l.name,copy:0,placed:!0,matrix:F0(h),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).map(u=>({matrix:u.matrix,thickness:u.thickness,outline:u.outline}))),o=new Map,i=new Map;for(let l of t){if(!l.slots&&!l.bores)continue;if(!l.placements){n.push(`Part "${l.name}" has ${l.slots?"slots":"bores"} but no at or rotate, so they can't be found.`);continue}let h=[];for(let x of l.bores??[]){let w=x.startsWith("!"),M=Bt(w?x.slice(1):x),k=r.filter(z=>M(z.label??"")||M(z.kind));!k.length&&!w&&n.push(`Part "${l.name}": no hardware "${x}" to bore for.`);for(let z of k)w?h.splice(0,h.length,...h.filter(A=>A!==z)):h.includes(z)||h.push(z)}let u=!1,f=new Set;for(let x of l.slots??[]){let w=x.startsWith("!"),M=Bt(w?x.slice(1):x),k=t.filter(z=>z!==l&&M(z.name));!k.length&&!w&&n.push(`Part "${l.name}": no part "${x}" to cut slots for.`);for(let z of k)w?f.delete(z):f.add(z)}let d=new Map,p=[...f].flatMap(x=>s(x).map(w=>(d.set(w,x.name),w))),m=new Set,g=(l.placements??[]).map(x=>s1(Se({name:l.name,copy:0,placed:!0,matrix:F0(x),thickness:l.thickness,outline:a(l),...l.bends&&{bends:l.bends}}).flatMap(w=>{let M=[];if(l.slots){let k=p.map(A=>pn(w,[A],0));for(let A=0;A<k.length;A++)for(let S=A+1;S<k.length;S++){let[C,I]=[d.get(p[A]),d.get(p[S])];if(!k[A].length||!k[S].length||C===I||!C||!I)continue;let L=K1(k[A],k[S]);if(L.reduce((T,q)=>T+Math.abs(b1(q)),0)>.01){let T=L.flat().map(Q=>Q[0]),q=L.flat().map(Q=>Q[1]),[P,F,j,_]=[Math.min(...T),Math.min(...q),Math.max(...T),Math.max(...q)];m.add(`Tabs of "${C}" and "${I}" meet in the same slot in "${l.name}", at [${p0(P)}, ${p0(F)}] to [${p0(j)}, ${p0(_)}] in its coordinates. Move one's tabs along the edge.`)}}let z=k.flat();M=z.length?Vi(c0(s1(z),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let z=yn(w,k,l.fit??I5.turn);z&&K1([z],w.outline).some(A=>Math.abs(b1(A))>1e-4)&&(M.push(z),u=!0)}return l.bends?K1(M,c0(w.outline,1,"miter")):M}))),v=(x,w)=>p3(x,w).reduce((M,k)=>M+Math.abs(b1(k)),0)>.001,b=l.stack??1;if(b>1){let x=M=>g.filter((k,z)=>z%b===M),w=Array.from({length:b},(M,k)=>s1(x(k).flat()));if(w.slice(1).some(M=>v(w[0],M))){Array.from({length:b},(M,k)=>x(k)).some(M=>M.slice(1).some(k=>v(M[0],k)))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`),i.set(l,w);continue}}g.slice(1).some(x=>v(g[0],x))&&n.push(`Copies of part "${l.name}" meet the parts in slots in different places; they all get every slot. Make them separate parts to cut each its own.`);for(let x of m)n.push(x);l.bores&&h.length&&!u&&n.push(`Part "${l.name}": none of ${l.bores.map(x=>`"${x}"`).join(", ")} pass through it, so it has no bores.`);let y=s1(g.flat());if(!y.length){l.slots&&!l.slots.some(x=>x.includes("*"))&&n.push(`Part "${l.name}": none of ${l.slots.map(x=>`"${x}"`).join(", ")} pass through it, so it has no slots.`);continue}o.set(l,y)}for(let[l,h]of o)l.layers=_t(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?_t(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 Oi(t,e,n){if(!t.some(o=>o.halving))return;let r=o=>s1([...o.layers].filter(([i])=>e(i)==="cut").flatMap(([,i])=>i.regions)),c=o=>{let i=r(o);return(o.placements??[]).map(l=>({matrix:F0(l),thickness:o.thickness,outline:i}))},a=new Map,s=(o,i,l)=>{let h=a.get(o)??(o.placements??[]).map(()=>[]);h[i].push(...l),a.set(o,h)};for(let o of t){if(!o.halving)continue;if(!o.placements){n.push(`Part "${o.name}" has halving but no at or rotate, so the crossings can't be found.`);continue}let i=new Set;for(let f of o.halving){let d=f.startsWith("!"),p=Bt(d?f.slice(1):f),m=t.filter(g=>g!==o&&p(g.name));!m.length&&!d&&n.push(`Part "${o.name}": no part "${f}" to halve with.`);for(let g of m)d?i.delete(g):i.add(g)}let l=0,h=0,u=c(o);for(let f of i){if(o.bends||f.bends){n.push(`Parts "${o.name}" and "${f.name}": halving joints can't go in a bent part.`);continue}if(!f.placements)continue;let d=c(f);u.forEach((p,m)=>d.forEach((g,v)=>{let b=kn(p,g,o.clearance??.1);h+=b.thin,b.a.length&&(l++,s(o,m,b.a),s(f,v,b.b))}))}h&&n.push(`Part "${o.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&i.size&&!o.halving.some(f=>f.includes("*"))&&n.push(`Part "${o.name}" crosses none of ${o.halving.map(f=>`"${f}"`).join(", ")}, so it has no halving slots.`)}for(let[o,i]of a){let l=i.map(h=>s1(h));l.slice(1).some(h=>p3(l[0],h).reduce((u,f)=>u+Math.abs(b1(f)),0)>.001)&&n.push(`Copies of part "${o.name}" are halved in different places; they all get every slot. Make them separate parts to cut each its own.`),o.layers=_t(o.layers,s1(l.flat()))}}function $i(t,e,n){let r=new Set;for(let c of t){if(c.on===void 0||!c.placements?.length)continue;let a=c.on,s=t.filter(m=>m.name===a&&m.placements?.length).flatMap(m=>m.placements.map((g,v)=>({q:m,m:F0(g),copy:a5(m,v)}))),o=t.filter(m=>m.name===c.name&&m.on===a).reduce((m,g)=>m+(g.placements?.length??0),0);if(!s.length){r.has(a)||n.push(`Part "${c.name}" is on "${a}", which is not a placed part.`),r.add(a);continue}let[i,l,h,u]=[1/0,1/0,-1/0,-1/0];for(let[m,g]of c.layers)if(e(m)==="cut")for(let v of g.regions)for(let[b,y]of v)i=Math.min(i,b),l=Math.min(l,y),h=Math.max(h,b),u=Math.max(u,y);if(!(h>=i))continue;let[f,d,p]=[(i+h)/2,(l+u)/2,c.thickness/2];c.placements=c.placements.map((m,g)=>{let v=a5(c,g),b=s.length===o&&s.find(z=>z.copy===v)||s[0];if(!b.q.bends?.length)return m;let y=F0(m),x=[y[0]*f+y[1]*d+y[2]*p+y[3],y[4]*f+y[5]*d+y[6]*p+y[7],y[8]*f+y[9]*d+y[10]*p+y[11]],w=v0(b.m),M=w[0]*x[0]+w[1]*x[1]+w[2]*x[2]+w[3],k=ze(b.q.bends,b.q.thickness)[mn(b.q.bends,M)];return{...m,matrix:D1(b.m,D1(k,D1(w,y)))}})}}function Ri(t,e,n){var l;let r=[],c=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)b1(p)<0&&u.push([...p].reverse());return u.length?c0(s1(u),-e,"miter"):[]},a=(h,u,f)=>{let d=0;for(let p of h)for(let m=0,g=p.length-1;m<p.length;g=m++){let[v,b]=p[g],[y,x]=p[m];b<=f?x>f&&(y-v)*(f-b)-(u-v)*(x-b)>0&&d++:x<=f&&(y-v)*(f-b)-(u-v)*(x-b)<0&&d--}return d!==0},s=h=>{let u=[];for(let[f,d]of h.layers)if(n(f))for(let p of d.regions)b1(p)>0&&u.push(p);return s1(u)},o=(h,u)=>{let{w:f,h:d}=u,p=s(u),m=[];for(let g of p)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))m.push(g[v]);for(let g of h){if(b1(g)<=0)continue;let[v,b,y,x]=[1/0,1/0,-1/0,-1/0];for(let[M,k]of g)v=Math.min(v,M),b=Math.min(b,k),y=Math.max(y,M),x=Math.max(x,k);if(y-v<f||x-b<d)continue;let w=Math.max(.5,Math.min(f,d,y-v-f+1,x-b-d+1)/4);for(let M=b;M<=x-d+1e-9;M+=w)for(let k=v;k<=y-f+1e-9;k+=w){if(!m.every(([A,S])=>a(h,A+k,S+M)))continue;let z=p.map(A=>A.map(([S,C])=>[S+k,C+M]));if(g0(z,h).reduce((A,S)=>A+Math.abs(b1(S)),0)<.01)return[k,M]}}},i=[];for(let h of t){let u=!1;for(let d of h.inner?.length?[]:r){let p=o(d.region,h);if(!p)continue;let[m,g]=p;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+m,dy:d.oy+g}),d.region=g0(d.region,c0(s(h).map(b=>b.map(([y,x])=>[y+m,x+g])),e,"miter"));let v=c(h);v.length&&r.push({host:d.host,ox:d.ox+m,oy:d.oy+g,region:v}),u=!0;break}if(u)continue;i.push(h);let f=c(h);f.length&&r.push({host:h,ox:0,oy:0,region:f})}return i}function Fi(t,e,n,r){let c=new Map;for(let o of t)c.set(o.info,[...c.get(o.info)??[],o]);let a=[],s=(o,i)=>v3({layers:o,parts:[]},i).layers;for(let[,o]of c){let i=o[0],l=s1([...i.layers].filter(([d])=>n(d)).flatMap(([,d])=>d.regions.filter(p=>b1(p)>0))),h=l.reduce((d,p)=>d+b1(p),0)/(i.w*i.h),u=o.length>=2&&l.length&&h<.75?Di(l,i.w,i.h,e,r):void 0;if(!u){a.push(...o);continue}let f=s(i.layers,[-1,0,0,-1,i.w,i.h]);for(let d=0;d<o.length;d+=u.n){let p=o.slice(d,d+u.n);if(p.length===1){a.push(p[0]);continue}let m=u.at.slice(0,p.length),g=Math.min(...m.map(x=>x[0])),v=Math.min(...m.map(x=>x[1])),b=Math.max(...m.map(x=>x[0]+i.w))-g,y=Math.max(...m.map(x=>x[1]+i.h))-v;a.push({...p[0],layers:s(p[0].layers,[1,0,0,1,m[0][0]-g,m[0][1]-v]),w:b,h:y,inner:p.slice(1).map((x,w)=>({item:{...x,layers:(w+1)%2?f:x.layers},dx:m[w+1][0]-g,dy:m[w+1][1]-v}))})}}return a}function Di(t,e,n,r,c){let s=c0(t.map(y=>qi(y,.25)).filter(y=>y.length>=3),.25,"miter"),o=c0(s,r,"miter"),i=s.map(y=>y.map(([x,w])=>[e-x,n-w])),l=(y,[x,w])=>y.map(M=>M.map(([k,z])=>[k+x,z+w])),h=(y,x)=>!K1(y,x).some(w=>Math.abs(b1(w))>.001),u=(y,x,w,M)=>{let[k,z]=[0,M];if(h(y,l(x,w(z)))){if(h(y,l(x,w(k))))return w(k);for(let A=0;A<10;A++){let S=(k+z)/2;h(y,l(x,w(S)))?z=S:k=S}return w(z)}},f;for(let y of[!1,!0])for(let x=-10;x<=10;x++){let w=x/10*(y?e:n),M=u(o,i,A=>y?[w,A]:[A,w],(y?n:e)+r);if(!M)continue;let k=Math.max(e,M[0]+e)-Math.min(0,M[0]),z=Math.max(n,M[1]+n)-Math.min(0,M[1]);k>c[0]||z>c[1]||k*z<.85*2*e*n&&(!f||k*z<f.area)&&(f={d:M,across:y,area:k*z})}if(!f)return;let{d,across:p}=f,m=s1([...o,...c0(l(i,d),r,"miter")]),v=u(m,s,y=>p?[0,y]:[y,0],2*((p?n:e)+r)+Math.abs(p?d[1]:d[0])),b=[[0,0],[d[0],d[1]]];if(v){let y=x=>Math.max(...x.map(w=>w[0]+e))-Math.min(...x.map(w=>w[0]))<=c[0]&&Math.max(...x.map(w=>w[1]+n))-Math.min(...x.map(w=>w[1]))<=c[1];for(let x=2;x<500;x++){let w=Math.floor(x/2),M=x%2?[d[0]+w*v[0],d[1]+w*v[1]]:[w*v[0],w*v[1]];if(!y([...b,M]))break;let k=l(x%2?i:s,M),z=s1(b.slice(Math.max(0,b.length-3)).map((A,S,C)=>{let I=b.length-C.length+S;return c0(l(I%2?i:s,A),r,"miter")}).flat());if(!h(z,k))break;b.push(M)}}return{at:b,n:b.length}}function qi(t,e){if(t.length<8)return t;let n=o=>{let i=new Uint8Array(o.length);i[0]=i[o.length-1]=1;let l=[[0,o.length-1]];for(;l.length;){let[h,u]=l.pop(),[f,d]=o[h],[p,m]=o[u],g=Math.hypot(p-f,m-d),v=-1,b=-1;for(let y=h+1;y<u;y++){let[x,w]=o[y],M=g?Math.abs((p-f)*(d-w)-(f-x)*(m-d))/g:Math.hypot(x-f,w-d);M>v&&([v,b]=[M,y])}v>e&&(i[b]=1,l.push([h,b],[b,u]))}return o.filter((h,u)=>i[u])},r=o=>Math.hypot(o[0]-t[0][0],o[1]-t[0][1]),c=1;for(let o=2;o<t.length;o++)r(t[o])>r(t[c])&&(c=o);let a=n(t.slice(0,c+1)),s=n([...t.slice(c),t[0]]);return[...a,...s.slice(1,-1)]}function a5(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 Ni(t,e,n){let r=[...n.keys()],c=[...e.keys()].filter(o=>n.get(o)?.mode==="fill"&&e.get(o).regions.length&&!["score","cut","guide"].includes(o)),a=[];if(c.length<2)return a;let s=o=>o==="engrave"?-1/0:(n.get(o)?.order??0)*2+r.indexOf(o)/r.length;c.sort((o,i)=>s(o)-s(i));for(let o=0;o<c.length-1;o++){let i=n.get(c[o]).side??"front",l=c.slice(o+1).filter(u=>(n.get(u).side??"front")===i);if(!l.length)continue;let h;for(let u of R0(e.get(c[o]).regions)){let f=u.reduce((w,M)=>w+b1(M),0);if(!(f>.001)||!c0(u,-.5,"round").length)continue;let d=u;for(let w of l)d.length&&(d=g0(d,e.get(w).regions));if(d.reduce((w,M)=>w+b1(M),0)>.001*Math.max(1,f))continue;let m=l.filter(w=>K1(u,e.get(w).regions).length),g=m.length?m:l;if(h){h.count++;for(let w of g)h.under.includes(w)||h.under.push(w);continue}let[v,b,y,x]=J0(new Map([["f",{regions:u,lines:[]}]]));h={part:t,layer:c[o],under:g,count:1,at:[p0((v+y)/2),p0((b+x)/2)]}}h&&a.push(h)}return a}function Ui(t,e){for(let n of t.slice(0,5)){let r=n.under.map(a=>`"${a}"`),c=r.length>1?`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`:r[0];e.push(`Part "${n.part}": ${n.count>1?`${n.count} fills`:"a fill"} on layer "${n.layer}" (${n.count>1?"the first ":""}at [${n.at.join(", ")}]) ${n.count>1?"lie":"lies"} wholly under ${c}, stacked above it in the files: printed, ${n.count>1?"they":"it"} won't show, and engraved, ${n.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${n.layer}" a higher order.`)}if(t.length>5){let n=t.slice(5),r=new Set(n.map(a=>a.part)).size,c=[...new Set(n.map(a=>`"${a.layer}"`))];e.push(`Fills are hidden the same way in ${n.length} more place${n.length>1?"s":""}, on ${r} part${r>1?"s":""} (layer${c.length>1?"s":""} ${c.slice(0,5).join(", ")}${c.length>5?" and more":""}).`)}}function Bi(t,e){let n=new Set,r=(c,a)=>{if(!c.glue||n.has(c))return;if(a.includes(c)){e.push(`Part "${c.name}" is glued in a loop of parts; it is left where it is.`),n.add(c);return}let s=t.find(h=>h.name===c.glue.host&&h!==c);if(!s?.placements){e.push(`Part "${c.name}" is glued to "${c.glue.host}", which is not a placed part.`),n.add(c);return}r(s,[...a,c]);let o=s.placements.map(F0),i=c.glue.face==="top"?s.thickness:-c.thickness,l=c.placements.length/(c.stack??1);c.placements=c.placements.map((h,u)=>{let f=o.length===l?o[Math.floor(u/(c.stack??1))]:o[0];return{...h,matrix:D1(f,D1(j0(0,0,i),F0(h)))}}),n.add(c)};for(let c of t)r(c,[])}function _i(t,e,n,r){let c=0,a=50;for(let m=0;m<14;m++){let g=(c+a)/2;c0(t,-g,"round").length?c=g:a=g}if(c<1)return[];let s=c0(t,-c*.98,"round"),o=J0(new Map([["cut",{regions:s,lines:[]}]]));if(!o)return[];let[i,l]=[(o[0]+o[2])/2,(o[1]+o[3])/2];((m,g)=>s.reduce((v,b)=>v+(C8(b,m,g)?b1(b)>0?1:-1:0),0)>0)(i,l)||([i,l]=s.reduce((m,g)=>b1(g)>b1(m)?g:m)[0]);let u=Math.min(6,Math.max(2,c*.9)),f=Ze(n,e,{size:u,font:r,halign:"center",valign:"center",spacing:1}),d=J0(new Map([["t",{regions:f,lines:[]}]])),p=d?Math.min(1,1.6*c/Math.max(d[2]-d[0],1e-9)):1;return f.map(m=>m.map(([g,v])=>[i-g*p,l+v*p]).reverse())}function C8(t,e,n){let r=!1;for(let c=0,a=t.length-1;c<t.length;a=c++){let[s,o]=t[c],[i,l]=t[a];o>n!=l>n&&e<(i-s)*(n-o)/(l-o)+s&&(r=!r)}return r}var ji=8,Gi=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,Wi=(t,e)=>Math.max(1,Gi.exec(t.slice(e-1))?.[0].length??1);function P8(t,e,n={}){if(!(t instanceof i1))return`error: ${t instanceof Error?t.message:String(t)}`;let r=n.file??"design.kerf",c=(i,l,h)=>`${i?`<${i}>`:r}:${l}:${h}`,a=i=>i===void 0?e:(Object.prototype.hasOwnProperty.call(R5,i)?R5[i]:void 0)??n.resolve?.(i),s=[`error: ${t.reason}`];if(t.line!==void 0&&t.col!==void 0){s.push(` --> ${c(t.file,t.line,t.col)}`);let l=a(t.file)?.split(`
|
|
3027
|
+
`)?.[t.line-1]?.replace(/\r$/,"");if(l!==void 0){let h=String(t.line),u=" ".repeat(h.length),f=l.slice(0,t.col-1),d=Wi(l,t.col),p=f.replace(/[^\t]/g," ");s.push(`${u} |`,`${h} | ${l}`,`${u} | ${p}${"^".repeat(d)}`)}}for(let i of Xi(t,c))s.push(` = ${i}`);let o=t.call?Z3(t.call):void 0;return o&&s.push(` = ${Ie(o)}: ${o.doc}`),s.join(`
|
|
3028
|
+
`)}function Xi(t,e){let n=a=>`in ${a.kind==="module"?"module ":""}${a.name}(), called at ${e(a.file,a.line,a.col)}${a.count>1?` (${a.count} times)`:""}`,r=t.trace.slice(0,ji).map(n),c=t.trace.length-r.length+t.traceMore;return c&&r.push(`and ${c} more call${c===1?"":"s"}`),r}var E8=new Set(["module","function","if","else","for","let","each","use","include"]),Zi=new Set(["true","false","undef"]),Yi=new Set(["for","if","let","function"]),jt={"(":")","[":"]","{":"}"},Ji=new Set(["+","-","*","/","%","^","==","!=","<","<=",">",">=","&&","||","=","?",":"]);function Ki(t,e){let n=e.pos.offset;if(e.type==="str"&&t[n]==="<")return`<${e.value}>`;if(e.type!=="str")return e.value;let r=n+1;for(;t[r]!=='"';)r+=t[r]==="\\"?2:1;return t.slice(n,r+1)}function Gt(t){let{tokens:e}=X3(t),n=[],r=0,c=0,a=s=>{for(;r<s;)if(t[r]===`
|
|
3029
|
+
`)c++,r++;else if(t.startsWith("//",r)){let o=t.indexOf(`
|
|
3030
|
+
`,r),i=o<0?t.length:o;n.push({kind:"line",text:t.slice(r,i).trimEnd(),breaks:c}),[c,r]=[0,i]}else if(t.startsWith("/*",r)){let o=t.indexOf("*/",r+2)+2,i=t.slice(r,o).replace(/[ \t\r]+\n/g,`
|
|
3031
|
+
`);n.push({kind:"block",text:i,breaks:c}),[c,r]=[0,o]}else r++};for(let s of e){if(a(s.pos.offset),s.type==="eof")break;let o=Ki(t,s);n.push({kind:"token",text:o,token:s,breaks:c}),c=0,r=s.pos.offset+o.length}return n}function e4(t,e={}){e2(t);let n=" ".repeat(e.indent??2),r=Gt(t),c=[],a=null,s=-1,o=0,i=[],l=0,h=!0,u=0,f=!1,d=0,p=0,m,g,v=()=>i[i.length-1],b=()=>!v()||v().open==="{"&&!v().record,y=z=>z.kind==="token"&&!!v()&&z.text===jt[v().open],x=(z,A)=>{a!==null&&c.push(a.trimEnd()),A&&c.length&&c[c.length-1]!==""&&c.push(""),s++,o=z,a=n.repeat(z),g=void 0},w=z=>{if(y(z))return v().outer;if(!b())return!m||m.text===","||jt[m.text]?v().inner:m.role==="header"?p+1:v().inner+1;let A=v()?v().inner:0;return h?A:f?u+1:d+1},M=z=>r.slice(z).find(A=>A.kind==="token");for(let z=0;z<r.length;z++){let A=r[z],S=s<0||A.breaks>0;if(A.kind!=="token"){if(S){let L=M(z),T=L?y(L)?v().inner:w(L):0;x(T,A.breaks>1&&s>=0)}else a+=" ";a+=A.text,g=A;continue}let C=A.text,I=A.token.type;if("*!#%".includes(C)&&b()&&!f&&(h||m?.text===")"||m?.text==="else")?A.role="modifier":(C==="!"||(C==="-"||C==="+")&&(!m||Qi(m)))&&(A.role="unary"),C===":"){let L=v();(L?L.ternaries:l)?L?L.ternaries--:l--:L?.open==="["&&(A.role="range")}if((C==="}"&&v()?.record||C==="{"&&m&&["=","(",",","[","?",":"].includes(m.text))&&(A.role="record"),S){let L=w(A);x(L,A.breaks>1&&s>=0),b()&&!y(A)&&(d=L)}else g&&el(g,A)&&(a+=" ");if(b()&&h&&!y(A)&&(u=o,f=I==="id"&&r[z+1]?.kind==="token"&&r[z+1].text==="="||C==="function",h=!1),a+=C,jt[C]){let L=v(),T=A.role==="record",q=L&&L.line===s&&(L.open!=="{"||L.record)&&(C!=="{"||T);i.push({record:T,open:C,outer:o,inner:q?L.inner:o+1,line:s,ternaries:0,header:C==="("&&!!m&&Yi.has(m.text)&&m.token?.type==="id"}),C==="{"&&!T&&(h=!0)}else if(y(A)){let L=i.pop();L.header&&(A.role="header",p=L.outer),C==="}"&&!L.record&&(h=!0)}else C===";"&&b()||I==="str"&&C.startsWith("<")&&b()?h=!0:C==="?"&&(v()?v().ternaries++:l++);m=A,g=A}for(a!==null&&c.push(a.trimEnd());c.length&&c[c.length-1]==="";)c.pop();let k=c.length?c.join(`
|
|
2651
3032
|
`)+`
|
|
2652
|
-
`:"";return
|
|
2653
|
-
<h2><span>${
|
|
2654
|
-
<div class="view">${
|
|
2655
|
-
${
|
|
2656
|
-
${v.size?`<h3>Hardware</h3>${
|
|
2657
|
-
</section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${
|
|
3033
|
+
`:"";return tl(t,k),k}var Qi=t=>Ji.has(t.text)||["(","[",",","{",";","}"].includes(t.text)||t.token?.type==="id"&&E8.has(t.text)||t.role==="unary"||t.role==="modifier";function el(t,e){if(t.kind!=="token"||e.kind!=="token")return!0;let n=t.text,r=e.text;if(r===","||r===";"||r===")"||r==="]"||n==="("||n==="["||n==="{"&&r==="}"||n==="{"&&t.role==="record"||r==="}"&&e.role==="record"||n==="."||r==="."||t.role==="unary"||t.role==="modifier"||t.role==="range"||e.role==="range")return!1;let c=t.token,a=c.type==="num"||c.type==="str"&&!n.startsWith("<")||c.type==="id"&&(!E8.has(n)||Zi.has(n))||n===")"&&t.role!=="header"||n==="]";return r==="("?n==="for"||n==="if"||n==="let"||!a&&n!=="function":r==="["?!a:!0}function tl(t,e){let n=Gt(t),r=Gt(e);if(!(n.length===r.length&&n.every((a,s)=>a.kind===r[s].kind&&a.text===r[s].text)))throw new i1("The formatter would change the program, so it was left as it is")}function T8(t){let e=new Map;for(let n of t.sheets)for(let r of n.items){let[c,a]=r.offset??[0,0],s=i=>i.map(([l,h])=>[l-c,a-h]),o=new Map;for(let[i,l]of r.layers)o.set(i,{regions:l.regions.map(s),lines:l.lines.map(s)});e.set(`${r.part}\0${r.copy}`,o)}return e}var I8=t=>Math.round(t*100)/100,t4=t=>t.map(([e,n])=>`${Math.round(e*100)},${Math.round(n*100)}`).join(" ");function V8(t,e,n=.01){let r=T8(t),c=T8(e),a=[],s=o=>{let[i,l]=o.split("\0");return{part:i,copy:Number(l)}};for(let o of new Set([...r.keys(),...c.keys()])){let i=r.get(o),l=c.get(o);if(!i||!l){a.push({...s(o),change:i?"removed":"added"});continue}for(let h of new Set([...i.keys(),...l.keys()])){let u=i.get(h)??{regions:[],lines:[]},f=l.get(h)??{regions:[],lines:[]},d=p3(u.regions,f.regions),p=d.reduce((x,w)=>x+Math.abs(b1(w)),0),m=new Set(u.lines.map(t4)),g=new Set(f.lines.map(t4)),v=u.lines.filter(x=>!g.has(t4(x))),b=f.lines.filter(x=>!m.has(t4(x)));if(p<=n&&!v.length&&!b.length)continue;let y=J0(new Map([[h,{regions:p>n?d:[],lines:[...v,...b]}]]));a.push({...s(o),layer:h,change:i.has(h)?l.has(h)?"changed":"removed":"added",...p>n&&{area:I8(p)},...v.length&&{linesRemoved:v.length},...b.length&&{linesAdded:b.length},...y&&{at:y.map(I8)}})}}return a}var nl=[Math.SQRT1_2,Math.SQRT1_2,0],rl=[-1/Math.sqrt(6),1/Math.sqrt(6),2/Math.sqrt(6)],Wt=[1/Math.sqrt(3),-1/Math.sqrt(3),1/Math.sqrt(3)],cl=(()=>{let t=[.4,-.5,.9],e=Math.hypot(...t);return[t[0]/e,t[1]/e,t[2]/e]})(),s5=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],H8=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],al=(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]],sl=(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]],_2=t=>t.replace(/[&<>"]/g,e=>({"&":"&","<":"<",">":">",'"':"""})[e]);function O8(t,e){let n=parseInt(t.slice(1),16),r=c=>Math.max(0,Math.min(255,Math.round(c*e))).toString(16).padStart(2,"0");return`#${r(n>>16)}${r(n>>8&255)}${r(n&255)}`}function ol(t,e,n){let r=(o,i,l)=>sl(t.matrix,t.bends?.length?y3(t.bends,t.thickness,[o,i,l]):[o,i,l]),c=[],a=(o,i)=>{if(o.length<3)return;let l=al(H8(o[1],o[0]),H8(o[2],o[0])),h=[0,0,0];for(let p=0;p<o.length;p++){let m=o[p],g=o[(p+1)%o.length];h[0]+=(m[1]-g[1])*(m[2]+g[2]),h[1]+=(m[2]-g[2])*(m[0]+g[0]),h[2]+=(m[0]-g[0])*(m[1]+g[1])}let u=Math.hypot(...h)||Math.hypot(...l);if(!u)return;let f=[h[0]/u,h[1]/u,h[2]/u];if(s5(f,Wt)<=0)return;let d=o.reduce((p,m)=>[p[0]+m[0],p[1]+m[1],p[2]+m[2]],[0,0,0]);c.push({pts:o,holes:i,color:O8(e,.55+.45*Math.max(0,s5(f,cl))),depth:s5([d[0]/o.length,d[1]/o.length,d[2]/o.length],Wt),stroke:n})},s=t.thickness;for(let o of b3(t.outline,t.bends)){let i=u=>u.reduce((f,d,p)=>f+d[0]*u[(p+1)%u.length][1]-u[(p+1)%u.length][0]*d[1],0),l=o.find(u=>i(u)>0)??o[0],h=o.filter(u=>u!==l);a(l.map(([u,f])=>r(u,f,s)),h.map(u=>u.map(([f,d])=>r(f,d,s)))),a([...l].reverse().map(([u,f])=>r(u,f,0)),h.map(u=>[...u].reverse().map(([f,d])=>r(f,d,0))));for(let u of o)for(let f=0;f<u.length;f++){let[d,p]=u[f],[m,g]=u[(f+1)%u.length];a([r(d,p,0),r(m,g,0),r(m,g,s),r(d,p,s)])}}return c}function il(t,e){let n=typeof t.size=="number"?t.size:Math.max(...t.size),r=[(t.from[0]+t.to[0])/2,(t.from[1]+t.to[1])/2,(t.from[2]+t.to[2])/2];return[{pts:[t.from,t.to],color:e,depth:s5(r,Wt)+n/2,stroke:String(n)}]}function ll(t,e=640,n=420){let r=m=>[s5(m,nl),-s5(m,rl)],c=1/0,a=1/0,s=-1/0,o=-1/0;for(let m of t)for(let g of m.pts){let[v,b]=r(g);c=Math.min(c,v),s=Math.max(s,v),a=Math.min(a,b),o=Math.max(o,b)}if(!Number.isFinite(c))return"";let i=Math.max(s-c,o-a)*.04+1,l=Math.min(e/(s-c+2*i),n/(o-a+2*i)),h=m=>{let[g,v]=r(m);return`${((g-c+i)*l).toFixed(1)} ${((v-a+i)*l).toFixed(1)}`},u=m=>`M${m.map(h).join("L")}Z`,f=[...t].sort((m,g)=>m.depth-g.depth).map(m=>m.pts.length===2?`<path d="M${h(m.pts[0])}L${h(m.pts[1])}" stroke="${m.color}" stroke-width="${(Number(m.stroke)*l).toFixed(1)}" stroke-linecap="round"/>`:`<path d="${u(m.pts)}${(m.holes??[]).map(u).join("")}" fill="${m.color}" fill-rule="evenodd" stroke="${m.stroke}" stroke-width="0.6" stroke-linejoin="round"/>`),d=((s-c+2*i)*l).toFixed(0),p=((o-a+2*i)*l).toFixed(0);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${d} ${p}" width="${d}" height="${p}">${f.join("")}</svg>`}var hl="#d9bf91",ul="#cfc6b8",fl="#e08a3c";function $8(t,e){let n=new Map;t.parts.forEach((f,d)=>n.set(f.name,f.label??d+1));let r=t.assembly.filter(f=>f.placed),c=t.steps.length?t.steps:["Put the parts together"],a=f=>t.steps.length?f??0:1,s=f=>Q2[f]??N2[f]?.color??"#9a9a9a",o=f=>f.length?`<ul>${f.map(d=>`<li>${d}</li>`).join("")}</ul>`:"",i=[],l=r.filter(f=>a(f.step)===0);c.forEach((f,d)=>{let p=d+1,m=[];for(let b of r){let y=a(b.step);y>p||m.push(...ol(b,y===p?fl:b.step===void 0&&!t.steps.length?hl:ul,y===p?"#7a3e0c":"#8a8274"))}for(let b of t.hardware){let y=t.steps.length?b.step:1;y<=p&&m.push(...il(b,y===p?s(b.kind):O8(s(b.kind),.8)))}let g=new Map;for(let b of r)a(b.step)===p&&g.set(b.name,(g.get(b.name)??0)+1);let v=new Map;for(let b of t.hardware)if((t.steps.length?b.step:1)===p){let y=typeof b.size=="number"?`${b.size} mm`:`${b.size[0]} x ${b.size[1]} mm`,x=Math.round(Math.hypot(b.to[0]-b.from[0],b.to[1]-b.from[1],b.to[2]-b.from[2])),w=`${b.label?`${_2(b.label)}: `:""}${_2(b.kind)}, ${y}, ${x} mm long`;v.set(w,(v.get(w)??0)+1)}i.push(`<section>
|
|
3034
|
+
<h2><span>${p}</span> ${_2(f)}</h2>
|
|
3035
|
+
<div class="view">${ll(m)}</div>
|
|
3036
|
+
${g.size?`<h3>Parts</h3>${o([...g].sort((b,y)=>(n.get(b[0])??0)-(n.get(y[0])??0)).map(([b,y])=>`<b>${n.get(b)??""}</b> ${_2(b)}${y>1?` × ${y}`:""}`))}`:""}
|
|
3037
|
+
${v.size?`<h3>Hardware</h3>${o([...v].map(([b,y])=>`${b}${y>1?` × ${y}`:""}`))}`:""}
|
|
3038
|
+
</section>`)});let h=t.parts.map((f,d)=>`<tr><td>${f.label??d+1}</td><td>${_2(f.name)}${f.mirrored?" (mirrored)":""}</td><td>${f.qty}</td><td>${f.width} × ${f.height} mm</td><td>${f.thickness} mm ${_2(f.material)}</td></tr>`).join(""),u=t.sheets.map((f,d)=>`<figure><div class="sheet">${f.svg.replace(/^<\?xml[^>]*>\s*/,"")}</div><figcaption>Sheet ${d+1}: ${f.width} × ${f.height} mm, ${f.thickness} mm ${_2(f.material)}</figcaption></figure>`).join("");return`<!doctype html>
|
|
2658
3039
|
<html lang="en">
|
|
2659
3040
|
<head>
|
|
2660
3041
|
<meta charset="utf-8">
|
|
2661
3042
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2662
|
-
<title>${
|
|
3043
|
+
<title>${_2(e)}: assembly</title>
|
|
2663
3044
|
<style>
|
|
2664
3045
|
body { font: 15px/1.45 system-ui, sans-serif; color: #222; margin: 24px auto; max-width: 760px; padding: 0 16px; }
|
|
2665
3046
|
h1 { font-size: 26px; margin: 0 0 4px; }
|
|
@@ -2676,32 +3057,32 @@ figure { margin: 12px 0; } figcaption { color: #666; font-size: 13px; }
|
|
|
2676
3057
|
</style>
|
|
2677
3058
|
</head>
|
|
2678
3059
|
<body>
|
|
2679
|
-
<h1>${
|
|
3060
|
+
<h1>${_2(e)}</h1>
|
|
2680
3061
|
<p class="note">${t.parts.reduce((f,d)=>f+d.qty,0)} parts on ${t.sheets.length} sheet${t.sheets.length===1?"":"s"}, ${c.length} step${c.length===1?"":"s"}.${l.length?" Some parts are in place before the first step.":""} The parts of each step are drawn in orange.</p>
|
|
2681
3062
|
<h3>Parts</h3>
|
|
2682
3063
|
<table><tr><th>#</th><th>Part</th><th>Qty</th><th>Size</th><th>Material</th></tr>${h}</table>
|
|
2683
3064
|
${u}
|
|
2684
|
-
${
|
|
3065
|
+
${i.join(`
|
|
2685
3066
|
`)}
|
|
2686
3067
|
</body>
|
|
2687
3068
|
</html>
|
|
2688
|
-
`}var
|
|
2689
|
-
`).length;throw new Error(`${o} (line ${l})`)};for(;a<t.length;){let o=t.indexOf("<",a),l=o<0?t.length:o;if(l>a&&(c[c.length-1].text+=on(t.slice(a,l),n)),o<0)break;if(a=o,t.startsWith("<!--",a)){let h=t.indexOf("-->",a+4);h<0&&s("Unclosed comment"),e.push(t.slice(a+4,h)),a=h+3}else if(t.startsWith("<![CDATA[",a)){let h=t.indexOf("]]>",a+9);h<0&&s("Unclosed CDATA section"),c[c.length-1].text+=t.slice(a+9,h),a=h+3}else if(t.startsWith("<?",a)){let h=t.indexOf("?>",a+2);h<0&&s("Unclosed processing instruction"),a=h+2}else if(t.startsWith("<!",a)){let h=0,u=a+2;for(;u<t.length;u++){let d=t[u];if(d==="[")h++;else if(d==="]")h--;else if(d===">"&&h<=0)break}let f=t.slice(a,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];a=u+1}else if(t[a+1]==="/"){let h=t.indexOf(">",a);h<0&&s("Unclosed end tag");let u=t.slice(a+2,h).trim(),f=c.pop();(!f||f===r||f.name!==u)&&s(`</${u}> does not match <${f?.name??"nothing"}>`),a=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(a,a+256));h||s("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};a+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=a;let d=f.exec(t);if(d||s(`Bad attribute in <${u.name}>`),a=f.lastIndex,d[5]){c[c.length-1].children.push(u),d[5]===">"&&c.push(u);break}u.attrs[d[1]]=on(d[3]??d[4]??"",n)}}}c.length>1&&s(`<${c[c.length-1].name}> is not closed`);let i=r.children[0];if(!i)throw new Error("The file has no elements");return{root:i,comments:e}}var u2={cut:{name:"cut",mode:"cut",color:"#ff0000"},score:{name:"score",mode:"line",color:"#0000ff"},engrave:{name:"engrave",mode:"fill",color:"#000000"},guide:{name:"guide",mode:"guide",color:"#00a0ff"}},V6={black:"#000000",white:"#ffffff",red:"#ff0000",lime:"#00ff00",green:"#008000",blue:"#0000ff",yellow:"#ffff00",cyan:"#00ffff",aqua:"#00ffff",magenta:"#ff00ff",fuchsia:"#ff00ff",gray:"#808080",grey:"#808080",silver:"#c0c0c0",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",teal:"#008080",orange:"#ffa500"},So=Object.fromEntries(Object.entries(V6).reverse().map(([t,e])=>[e,t]));function U5(t,e){if(t===void 0)return;if(t=t.trim().toLowerCase(),t==="none"||t==="transparent")return"none";if(t==="currentcolor")return e;if(t.startsWith("url("))return"paint";if(V6[t])return V6[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let r=n[1];if(r.length===3||r.length===4)return"#"+[...r.slice(0,3)].map(c=>c+c).join("");if(r.length===6||r.length===8)return"#"+r.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let r=n[1].split(/[\s,/]+/).filter(Boolean);if(r.length>=3){let c=r.slice(0,3).map(a=>{let s=a.endsWith("%")?parseFloat(a)*255/100:parseFloat(a);return Math.max(0,Math.min(255,Math.round(s||0)))});return r[3]!==void 0&&parseFloat(r[3])===0?"none":"#"+c.map(a=>a.toString(16).padStart(2,"0")).join("")}}return"#000000"}var e5=(t,e)=>q3(t,Math.PI/12,e),B5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function Lo(t){let e=Se;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let c=B5(r),a=(c[0]??0)*Math.PI/180,s=Se;if(n==="matrix"&&c.length===6)s=c;else if(n==="translate")s=[1,0,0,1,c[0]??0,c[1]??0];else if(n==="scale")s=[c[0]??1,0,0,c[1]??c[0]??1,0,0];else if(n==="rotate"){let i=Math.cos(a),o=Math.sin(a),[l,h]=[c[1]??0,c[2]??0];s=[i,o,-o,i,l-i*l+o*h,h-o*l-i*h]}else n==="skewX"?s=[1,0,Math.tan(a),1,0,0]:n==="skewY"&&(s=[1,Math.tan(a),0,1,0,0]);e=I3(e,s)}return e}function Ao(t,e){let n=[],r=[],c=[0,0],a=[0,0],s=(l,h)=>v5(e,[l,h]),i=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,o=l=>{r.length&&n.push({segs:r,closed:l}),r=[]};for(let l of t)if(l.type==="M")o(!1),c=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);i(a,h)||r.push({c:"L",a,b:h}),a=h}else if(l.type==="Q"){let h=s(l.x1,l.y1),u=s(l.x,l.y);r.push({c:"C",a,p1:[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),a=u}else if(l.type==="C"){let h=s(l.x,l.y);r.push({c:"C",a,p1:s(l.x1,l.y1),p2:s(l.x2,l.y2),b:h}),a=h}else r.length&&!i(a,c)&&r.push({c:"L",a,b:c}),o(!0),a=c;return o(!1),n}var Co=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],Po=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function hn(t){let e={};for(let n of t.split(";")){let r=n.indexOf(":");if(r<0)continue;let c=n.slice(0,r).trim().toLowerCase(),a=n.slice(r+1).replace(/!important/i,"").trim();c&&a&&(e[c]=a)}return e}function Eo(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let c=hn(r);for(let a of n.split(",")){let s=a.trim(),i=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(s);if(!i)continue;let o=[],l;for(let[,h,u]of i[2].matchAll(/([.#])([\w-]+)/g))h==="."?o.push(u):l=u;e.push({tag:i[1]&&i[1]!=="*"?i[1]:void 0,id:l,classes:o,decls:c})}}return e}function To(t,e){switch(t){case"mm":return 1;case"cm":return 10;case"in":return 25.4;case"pt":return 25.4/72;case"pc":return 25.4/6;case"q":return .25;default:return 25.4/e}}function I6(t,e){if(!t)return;let n=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(t);if(!(!n||n[2]==="%"))return Number(n[1])*To(n[2].toLowerCase(),e)}var Io=/^(path|g|rect|circle|ellipse|line|polyline|polygon|layer|svg|use|text|tspan|group|shape|cls|clip|mask|defs|_?x?\d|Layer_\d|Ebene|Calque|Capa|Livello|Laag|Warstwa)[-_ ]*[\d-]*$/i;function Vo(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!Io.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function Ho(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return u2.score;if(/engrav|raster|etch/.test(e))return u2.engrave;if(/\bguide/.test(e))return u2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return u2.cut}function un(t,e={}){if(t=t.replace(/^\uFEFF/,""),!/^\s*</.test(t)||t.includes("\0"))throw new Error("This is not an SVG file: it does not start with a tag");let n=ln(t),r=n.root;if(r.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let c=[],a=n.comments.some(V=>/Adobe Illustrator/i.test(V)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&c.push("Adobe Illustrator file: px measured at 72 per inch.");let i=B5(r.attrs.viewBox??""),o=I6(r.attrs.width,s),l=I6(r.attrs.height,s),h=25.4/s,u=h,f=h,d=0,m=0;i.length===4&&i[2]>0&&i[3]>0&&(u=o!==void 0?o/i[2]:l!==void 0?l/i[3]:h,f=l!==void 0?l/i[3]:u,d=i[0],m=i[1]),o===void 0&&l===void 0&&e.dpi===void 0&&!a&&c.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let g=l??(i.length===4?i[3]*f:0),p=I3([1,0,0,-1,0,g],[u,0,0,f,-d*u,-m*f]),v=[],y=new Map,b=V=>{V.name==="style"&&v.push(...Eo(V.text)),V.attrs.id&&y.set(V.attrs.id,V),V.children.forEach(b)};b(r);let x=(V,n1)=>{let G={};for(let r1 of Object.keys(n1))Po.has(r1)&&(G[r1]=n1[r1]);for(let r1 of Co)V.attrs[r1]!==void 0&&(G[r1]=V.attrs[r1]);let k1=(V.attrs.class??"").split(/\s+/).filter(Boolean);for(let r1 of v)(!r1.tag||r1.tag===V.name)&&(!r1.id||r1.id===V.attrs.id)&&r1.classes.every(U1=>k1.includes(U1))&&Object.assign(G,r1.decls);return V.attrs.style&&Object.assign(G,hn(V.attrs.style)),G},M=[],w=[],k=0,z=0,S=0,A=0,L=0,C=0,P=2e4,R=[],q=V=>Number.isFinite(V[0])&&Number.isFinite(V[1]),T=["x","y","width","height","rx","ry","cx","cy","r"],B=V=>[...T,"x1","y1","x2","y2","points"].some(n1=>V.attrs[n1]!==void 0&&B5(V.attrs[n1]).some(G=>!Number.isFinite(G))),X=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),Z=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),h1=V=>{let n1=G=>parseFloat(V.attrs[G]??"0")||0;switch(V.name){case"path":return e5(V.attrs.d??"",()=>S++);case"rect":{let[G,k1,r1,U1]=[n1("x"),n1("y"),n1("width"),n1("height")];if(r1<=0||U1<=0)return[];let c1=V.attrs.rx!==void 0?n1("rx"):V.attrs.ry!==void 0?n1("ry"):0,V1=V.attrs.ry!==void 0?n1("ry"):c1;return c1=Math.min(Math.abs(c1),r1/2),V1=Math.min(Math.abs(V1),U1/2),c1<=0||V1<=0?e5(`M${G} ${k1}H${G+r1}V${k1+U1}H${G}Z`):e5(`M${G+c1} ${k1}H${G+r1-c1}A${c1} ${V1} 0 0 1 ${G+r1} ${k1+V1}V${k1+U1-V1}A${c1} ${V1} 0 0 1 ${G+r1-c1} ${k1+U1}H${G+c1}A${c1} ${V1} 0 0 1 ${G} ${k1+U1-V1}V${k1+V1}A${c1} ${V1} 0 0 1 ${G+c1} ${k1}Z`)}case"circle":case"ellipse":{let[G,k1]=[n1("cx"),n1("cy")],r1=V.name==="circle"?n1("r"):n1("rx"),U1=V.name==="circle"?n1("r"):V.attrs.ry!==void 0?n1("ry"):r1;return r1<=0||U1<=0?[]:e5(`M${G+r1} ${k1}A${r1} ${U1} 0 0 1 ${G} ${k1+U1}A${r1} ${U1} 0 0 1 ${G-r1} ${k1}A${r1} ${U1} 0 0 1 ${G} ${k1-U1}A${r1} ${U1} 0 0 1 ${G+r1} ${k1}Z`)}case"line":return e5(`M${n1("x1")} ${n1("y1")}L${n1("x2")} ${n1("y2")}`);case"polyline":case"polygon":{let G=B5(V.attrs.points??"");if(G.length<4)return[];let k1=`M${G[0]} ${G[1]}`;for(let r1=2;r1+1<G.length;r1+=2)k1+=`L${G[r1]} ${G[r1+1]}`;return e5(V.name==="polygon"?k1+"Z":k1)}}},H=V=>(V.text+V.children.map(n1=>n1.name==="tspan"?" "+H(n1):"").join("")).replace(/\s+/g," ").trim(),U=(V,n1,G,k1,r1,U1)=>{if(U1>64||X.has(V.name)||L&&++C>P)return;let c1=x(V,G);if(c1.display==="none"||c1.visibility==="hidden"||c1.opacity==="0"){(V.children.length||Z.has(V.name))&&z++;return}let V1=I3(n1,Lo(V.attrs.transform));if(!V1.every(Number.isFinite)){A++;return}let o0=Vo(V),d0=V.attrs["inkscape:groupmode"]==="layer",I=k1;if(V.name==="g"||V.name==="svg"||V.name==="a"||V.name==="switch"){let A1=V.attrs["inkscape:label"]??V.attrs["data-name"]??V.attrs.id,l0=Ho(A1);if(V.attrs["data-mode"]&&A1&&/^(cut|line|fill|guide)$/.test(V.attrs["data-mode"])){let v1=U5(c1.stroke,"#000000"),y1=U5(c1.fill,"#000000"),T1=V.attrs["data-mode"]==="fill"?y1:v1;I=u2[A1]??{name:A1,mode:V.attrs["data-mode"],color:T1&&T1.startsWith("#")?T1:"#00aa00"}}else l0&&(I=l0);if(V!==r&&V.name==="svg"){let v1=y1=>parseFloat(V.attrs[y1]??"0")||0;V1=I3(V1,[1,0,0,1,v1("x"),v1("y")])}let m1=d0||l0||V===r||!o0?r1:[o0,...r1];R.push(V);for(let v1 of V.children)U(v1,V1,c1,I,m1,U1+1);R.pop();return}if(V.name==="use"){let A1=y.get((V.attrs.href??V.attrs["xlink:href"]??"").replace(/^#/,""));if(!A1||R.includes(A1))return;let l0=y1=>parseFloat(V.attrs[y1]??"0")||0,m1=I3(V1,[1,0,0,1,l0("x"),l0("y")]),v1=A1.name==="symbol"?{...A1,name:"g"}:A1;R.push(A1),L++,U(v1,m1,c1,I,o0?[o0,...r1]:r1,U1+1),L--,R.pop();return}if(V.name==="image"){k++;return}let N=U5(c1.color,"#000000")??"#000000",a1=parseFloat(c1["stroke-width"]??"1"),J=U5(c1.stroke,N);J&&(a1===0||c1["stroke-opacity"]==="0")&&(J="none");let x1=U5(c1.fill??"black",N);if(c1["fill-opacity"]==="0"&&(x1="none"),V.name==="text"){let A1=H(V);if(!A1)return;let l0=V.children.find(J1=>J1.name==="tspan"),m1=J1=>B5(V.attrs[J1]??l0?.attrs[J1]??"0")[0]??0,v1=v5(V1,[m1("x"),m1("y")]),y1=Math.sqrt(Math.abs(V1[0]*V1[3]-V1[1]*V1[2])),T1=(I6(c1["font-size"],96)??16*h)/h;if(!q(v1)||!Number.isFinite(T1*y1)){A++;return}let $1=c1["text-anchor"];w.push({text:A1,at:v1,size:T1*y1,angle:Math.atan2(-V1[1],V1[0])*180/Math.PI,font:(c1["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:$1==="middle"?"center":$1==="end"?"right":"left",stroke:J,fill:x1,layer:I});return}if(V.name!=="path"&&B(V)){A++;return}let R1=h1(V);if(!R1){for(let A1 of V.children)U(A1,V1,c1,I,r1,U1+1);return}let w0=Ao(R1,V1),Y1=w0.filter(A1=>A1.segs.every(l0=>q(l0.a)&&q(l0.b)&&(l0.c==="L"||q(l0.p1)&&q(l0.p2))));Y1.length<w0.length&&A++,Y1.length&&M.push({subs:Y1,stroke:J,fill:V.name==="line"||V.name==="polyline"?"none":x1,fillRule:c1["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:I,names:o0?[o0,...r1]:r1})};U(r,p,{},void 0,[],0),k&&c.push(`${k} embedded image${k===1?" was":"s were"} left out: trace ${k===1?"it":"them"} to paths first.`),z&&c.push(`${z} hidden element${z===1?" was":"s were"} left out.`),S&&c.push(`${S} path${S===1?" has":"s have"} bad data: read up to the error, as browsers draw ${S===1?"it":"them"}.`),A&&c.push(`${A} element${A===1?" was":"s were"} left out: ${A===1?"its":"their"} numbers are too large to draw.`),C>P&&c.push(`The drawing repeats its elements with <use> more than ${P.toLocaleString("en")} times: only the first ${P.toLocaleString("en")} copies were read.`);let Y=V=>{let[n1,G,k1]=[1,3,5].map(r1=>parseInt(V.slice(r1,r1+2),16));return n1>=200&&G<=80&&k1<=80},Q=V=>{let[n1,G,k1]=[1,3,5].map(r1=>parseInt(V.slice(r1,r1+2),16));return k1>=200&&n1<=80&&G<=80},W=V=>!!V.stroke&&V.stroke!=="none",F1=M.filter(V=>!V.layer),L1=new Map;for(let V of F1)W(V)&&V.stroke.startsWith("#")&&L1.set(V.stroke,(L1.get(V.stroke)??0)+V.subs.length);let g1=[...L1.keys()],X1=g1.filter(Y),D1=new Set(X1.length?X1:g1.length?[g1.reduce((V,n1)=>(L1.get(n1)??0)>(L1.get(V)??0)?n1:V)]:[]),E=M.some(V=>W(V)&&!V.layer)||M.some(V=>V.layer),D=new Map,e1=(V,n1)=>{if(V&&V!=="none"){let G=V.startsWith("#")?V:"#000000";if(D1.has(G))return u2.cut;if(G==="#00a0ff")return u2.guide;if(Q(G))return u2.score;if(!D.has(G)){let k1=So[G]??"color_"+G.slice(1);D.set(G,{name:k1,mode:"line",color:G})}return D.get(G)}if(n1&&n1!=="none")return E?u2.engrave:u2.cut};!E&&M.some(V=>V.fill&&V.fill!=="none")?c.push("The file has filled shapes and no strokes: the shapes are cut out."):!X1.length&&D1.size&&c.push(`No red lines: ${[...D1][0]} lines, the most common colour, are cut.`),D.size&&c.push(`Lines in ${[...D.values()].map(V=>V.color).join(", ")} went on their own layer${D.size===1?"":"s"}, set to mark, not cut.`);let u1=[];for(let V of M){let n1=V.layer??e1(V.stroke,V.fill);if(!n1)continue;let G=!V.layer&&n1===u2.cut&&!W(V);u1.push({subs:V.subs,layer:n1,fillRule:V.fillRule,names:V.names,filled:G})}let t1=[];for(let V of w){let n1=V.layer??e1(V.fill!=="none"?void 0:V.stroke,V.fill);n1&&t1.push({...V,layer:n1.mode==="cut"&&E?u2.engrave:n1})}return{items:u1,texts:t1,notes:c}}var N1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),x2=([t,e],n)=>{let r=n*Math.PI/180,c=Math.cos(r),a=Math.sin(r);return[t*c-e*a,t*a+e*c]},O6=(t,e)=>[t[0]+e[0],t[1]+e[1]],M2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function M3(t,e=.005){let n=[t.segs[0].a];for(let r of t.segs)if(r.c==="L")n.push(r.b);else{let c=N1(r.a,r.p1)+N1(r.p1,r.p2)+N1(r.p2,r.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(c/e))));for(let s=1;s<=a;s++){let i=s/a,o=1-i;n.push([o*o*o*r.a[0]+3*o*o*i*r.p1[0]+3*o*i*i*r.p2[0]+i*i*i*r.b[0],o*o*o*r.a[1]+3*o*o*i*r.p1[1]+3*o*i*i*r.p2[1]+i*i*i*r.b[1]])}}return t.closed&&n.length>1&&N1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function I2(t,e=!0){let n=0;for(let r=1;r<t.length;r++)n+=N1(t[r-1],t[r]);return e&&t.length>2?n+N1(t[t.length-1],t[0]):n}function _2(t,e,n){let r=[],c=e?t.length:t.length-1;for(let a=0;a<c;a++){let s=t[a],i=t[(a+1)%t.length];r.push(s);let o=Math.floor(N1(s,i)/n);for(let l=1;l<o;l++)r.push([s[0]+(i[0]-s[0])*l/o,s[1]+(i[1]-s[1])*l/o])}return!e&&t.length&&r.push(t[t.length-1]),r}function r3(t,e,n){let r=n[0]-e[0],c=n[1]-e[1],a=r*r+c*c,s=a?((t[0]-e[0])*r+(t[1]-e[1])*c)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*r,t[1]-e[1]-s*c)}var x3=class{constructor(e,n,r){this.size=r;this.cells=new Map;for(let c of e){let a=n?c.length:c.length-1;for(let s=0;s<a;s++){let i=c[s],o=c[(s+1)%c.length],l=Math.max(1,Math.ceil(N1(i,o)/(r*2)));for(let h=0;h<l;h++){let u=[i[0]+(o[0]-i[0])*h/l,i[1]+(o[1]-i[1])*h/l],f=[i[0]+(o[0]-i[0])*(h+1)/l,i[1]+(o[1]-i[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/r),m=Math.floor(Math.max(u[0],f[0])/r),g=Math.floor(Math.min(u[1],f[1])/r),p=Math.floor(Math.max(u[1],f[1])/r);for(let v=d;v<=m;v++)for(let y=g;y<=p;y++){let b=`${v},${y}`,x=this.cells.get(b);x?x.push([u,f]):this.cells.set(b,[[u,f]])}}}}}near(e,n){let r=Math.floor((e[0]-n)/this.size),c=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let i=r;i<=c;i++)for(let o=a;o<=s;o++)for(let[l,h]of this.cells.get(`${i},${o}`)??[])if(r3(e,l,h)<=n)return!0;return!1}meets(e,n,r){let c=Math.max(1,Math.ceil(N1(e,n)/(this.size*2)));for(let a=0;a<c;a++){let s=[e[0]+(n[0]-e[0])*a/c,e[1]+(n[1]-e[1])*a/c],i=[e[0]+(n[0]-e[0])*(a+1)/c,e[1]+(n[1]-e[1])*(a+1)/c],o=Math.floor((Math.min(s[0],i[0])-r)/this.size),l=Math.floor((Math.max(s[0],i[0])+r)/this.size),h=Math.floor((Math.min(s[1],i[1])-r)/this.size),u=Math.floor((Math.max(s[1],i[1])+r)/this.size);for(let f=o;f<=l;f++)for(let d=h;d<=u;d++)for(let[m,g]of this.cells.get(`${f},${d}`)??[])if(dn(s,i,m,g)<=r)return!0}return!1}};function dn(t,e,n,r){let c=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),a=c(n,r,t),s=c(n,r,e),i=c(t,e,n),o=c(t,e,r);return a*s<0&&i*o<0?0:Math.min(r3(t,n,r),r3(e,n,r),r3(n,t,e),r3(r,t,e))}function Oo(t,e,n=.2){let r=t.length;if(r<4)return!1;let c=[0];for(let h=1;h<=r;h++)c.push(c[h-1]+N1(t[h-1],t[h%r]));let a=c[r],s=z0([t]),i=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(r)),o=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/i),m=Math.floor((Math.max(h[0],u[0])+e)/i),g=Math.floor((Math.min(h[1],u[1])-e)/i),p=Math.floor((Math.max(h[1],u[1])+e)/i);if((m-d+1)*(p-g+1)>4096)return null;for(let v=d;v<=m;v++)for(let y=g;y<=p;y++)f.push(`${v},${y}`);return f};for(let h=0;h<r;h++){let u=t[h],f=t[(h+1)%r],d=l(u,f);if(!d)return!1;for(let m of d)for(let g of o.get(m)??[]){let p=Math.abs(c[h]-c[g]);if(!(Math.min(p,a-p)-N1(u,f)-N1(t[g],t[(g+1)%r])<n)&&dn(u,f,t[g],t[(g+1)%r])<=e)return!0}for(let m of d){let g=o.get(m);g?g.push(h):o.set(m,[h])}}return!1}function mn(t,e){let n=t.map(()=>!1),r=[],c=t.map(l=>z0([l]));t.forEach((l,h)=>{let u=i1([l]),f=u.reduce((g,p)=>g+M1(p),0),d=I2(l),m=u.reduce((g,p)=>g+I2(p),0);(u.length!==1||Math.abs(f-Math.abs(M1(l)))>d*.001+1e-6||Math.abs(m-d)>d*.001+.05||Oo(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new x3([t[l]],!0,Math.max(e*4,1))),h},i=t.map((l,h)=>h).sort((l,h)=>c[l][0]-c[h][0]),o=[];for(let l of i){let[h,u,f,d]=c[l];for(let m=o.length-1;m>=0;m--)c[o[m]][2]<h-e&&o.splice(m,1);for(let m of o){let g=c[m];if(g[1]>d+e||g[3]<u-e)continue;let[p,v]=t[l].length<=t[m].length?[l,m]:[m,l],y=t[p],b=s(v);for(let x=0;x<y.length;x++)if(b.meets(y[x],y[(x+1)%y.length],e)){r.push([l,m]);break}}o.push(l)}return{self:n,pairs:r}}function w3(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let c=Math.max(n*2,.2),a=new x3(t,r,Math.max(n*4,1)),s=new x3(e,r,Math.max(n*4,1));for(let i of t)for(let o of _2(i,r,c))if(!s.near(o,n))return!1;for(let i of e)for(let o of _2(i,r,c))if(!a.near(o,n))return!1;return!0}function pn(t,e,n){let r=new x3([t,...e],!0,Math.max(n*4,1)),c=a=>B2(a,t)&&!e.some(s=>B2(a,s));return(a,s)=>{let i=s?a.length:a.length-1;if(i<1)return!1;let o;for(let l=0;l<i;l++){let h=a[l],u=a[(l+1)%a.length];if(!r.meets(h,u,n)){o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==i-1)return!1;let f=N1(h,u),d=Math.min(n*3,f/3)/f,m=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,g=l===i-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(r.meets(m,g,n))return!1;o??(o=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return o?c(o):!0}}function gn(t,e,n){if(!t.length)return!1;let r=new x3([e],!0,Math.max(n*4,1));return t.some(c=>_2(c,!1,Math.max(n*2,.2)).some(a=>r.near(a,n)))}function B2(t,e){let n=!1;for(let r=0,c=e.length-1;r<e.length;c=r++){let[a,s]=e[r],[i,o]=e[c];s>t[1]!=o>t[1]&&t[0]<(i-a)*(t[1]-s)/(o-s)+a&&(n=!n)}return n}function Z4(t){let e=t.length;if(e<3)return null;let n=0,r=0;for(let[p,v]of t)n+=p,r+=v;n/=e,r/=e;let c=0,a=0,s=0,i=0,o=0,l=0,h=0;for(let[p,v]of t){let y=p-n,b=v-r;c+=y*y,a+=y*b,s+=b*b,i+=y*y*y,o+=b*b*b,l+=y*b*b,h+=b*y*y}let u=c*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(i+l)/2,d=(o+h)/2,m=(f*s-d*a)/u,g=(d*c-f*a)/u;return{c:[m+n,g+r],r:Math.sqrt(m*m+g*g+(c+s)/e)}}function t5(t,e=.01){if(t.length<4)return t;let n=0;for(let o=1;o<t.length;o++)N1(t[0],t[o])>N1(t[0],t[n])&&(n=o);let r=o=>{if(o.length<3)return o;let l=0,h=0;for(let f=1;f<o.length-1;f++){let d=r3(o[f],o[0],o[o.length-1]);d>l&&(l=d,h=f)}return l<=e?[o[0],o[o.length-1]]:[...r(o.slice(0,h+1)).slice(0,-1),...r(o.slice(h))]},c=r(t.slice(0,n+1)),a=r([...t.slice(n),t[0]]),s=[...c.slice(0,-1),...a.slice(0,-1)],i=[];for(let o=0;o<s.length;o++){let l=s[(o-1+s.length)%s.length],h=s[(o+1)%s.length];r3(s[o],l,h)>e&&i.push(s[o])}return i.length>=3?i:s}function vn(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=t5(a,.002),i=s.length,o=s.findIndex((u,f)=>N1(u,s[(f+1)%i])>=.5);if(i<4||o<0)continue;let l=M1(a)>0,h=[];for(let u=1;u<=i;u++){let f=(o+u)%i,d=s[f],m=s[(f+1)%i];if(N1(d,m)<.3){h.length||h.push(d),h.push(m);continue}if(h.length>=3){let g=Z4(h),[p,v,y]=[h[0],h[1],h[h.length-1]],b=(v[0]-p[0])*(y[1]-p[1])-(v[1]-p[1])*(y[0]-p[0]);g&&g.r>.005&&g.r<.6&&(b>0===l?e:n).push(g.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let r=e[Math.floor(e.length/2)],c=a=>Math.abs(a-r)<=Math.max(.005,r*.1);if(!(r>.2||n.filter(c).length>e.length*.2))return e.filter(c).length>=e.length*.8?r:void 0}function F6(t,e){let n=t.length,r=i=>N1(t[i],t[(i+1)%n])<e*1.5,c=t.findIndex((i,o)=>!r(o));if(c<0)return t;let a=[],s=c;do{let i=(s+1)%n;for(;r(i)&&i!==s;)i=(i+1)%n;let o=(i-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[i],f=t[(i+1)%n],d;if(o>0){let m=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(m)>1e-12){let g=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/m,p=[l[0]+g*(h[0]-l[0]),l[1]+g*(h[1]-l[1])],v=t[(s+1+Math.floor(o/2))%n],y=[];for(let M=1;M<=o+1;M++)y.push(t[(s+M)%n]);let b=y.length>=3?Z4(y):{c:p,r:e};!!b&&Math.abs(b.r-e)<=e*.3&&N1(p,v)<=e*2&&g>=1-1e-9&&(d=p)}}if(a.push(l),d)a.push(d);else for(let m=1;m<=o;m++)a.push(t[(s+m)%n]);s=i}while(s!==c);return a}function H1(t){for(let r of[0,1,2]){let c=10**r,a=Math.round(t*c)/c;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var P1=t=>String(H1(t)),s0=t=>`[${P1(t[0])}, ${P1(t[1])}]`;function Fo(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function V2(t,e,n){let r=[];(H1(t[0])!==0||H1(t[1])!==0)&&r.push(`translate(${s0(t)})`);let c=Fo(e);return c!==0&&r.push(`rotate(${c})`),[...r,n].join(" ")}function _5(t,e){return{poly:t,area:Math.abs(M1(t)),box:z0([t]),ends:e?.segs.map(n=>n.a)}}var X4=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function Y4(t,e){let n=I2(t.poly),r=_2(t.poly,!0,Math.min(.5,n/256)),c=Z4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:r);if(!c||c.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,c.r*3e-4));for(let i of t.poly)if(Math.abs(N1(i,c.c)-c.r)>a)return;let s=a+c.r*2e-4;for(let i of r)if(Math.abs(N1(i,c.c)-c.r)>s)return;if(!(Math.abs(t.area-Math.PI*c.r*c.r)>n*a*2))return{kind:"circle",body:`circle(d = ${P1(c.r*2)})`,at:c.c,angle:0,center:c.c,circle:c,radius:c.r}}function yn(t){let e=0,n=0;for(let[s,i]of t)e+=s,n+=i;e/=t.length,n/=t.length;let r=0,c=0,a=0;for(let[s,i]of t)r+=(s-e)**2,c+=(i-n)**2,a+=(s-e)*(i-n);return .5*Math.atan2(2*a,r-c)*180/Math.PI}function J4(t,e){let n=I2(t.poly),r=_2(t.poly,!0,Math.min(.5,n/256)),c=yn(r),a=r.map(g=>x2(g,-c)),[s,i,o,l]=z0([a]),h=(o-s)/2,u=(l-i)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+o)/2,(i+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[g,p]of a){let v=Math.hypot((g-f[0])/h,(p-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let m=x2(f,c);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${s0([h,u])})`,at:m,angle:c,center:m}}function bn(t){let e=0,n=0;for(let r=0;r<t.length;r++){let c=t[r],a=t[(r+1)%t.length],s=N1(c,a);s>e&&(e=s,n=Math.atan2(a[1]-c[1],a[0]-c[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function K4(t,e){let n=t5(t.poly,e/4),r=bn(n),c=I2(t.poly),a=_2(t.poly,!0,Math.min(.5,c/256)).map(y=>x2(y,-r)),[s,i,o,l]=z0([a]),h=o-s,u=l-i;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,i],[o,i],[o,l],[s,l]].map(y=>Math.min(...a.map(b=>N1(b,y)))*f),m=d.reduce((y,b)=>y+b,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;m<e&&(m=0),m=Math.min(m,h/2,u/2);let g=[(s+o)/2,(i+l)/2];for(let[y,b]of a){let x=Math.abs(y-g[0])-(h/2-m),M=Math.abs(b-g[1])-(u/2-m),w=Math.hypot(Math.max(x,0),Math.max(M,0))+Math.min(Math.max(x,M),0)-m;if(Math.abs(w)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*m*m))>c*e)return;let p=x2(g,r),v=H1(m)>0?`, r = ${P1(m)}`:"";return{kind:"rect",radius:m,body:`rect(${s0([h,u])}, center = true${v})`,at:p,angle:r,center:p,rect:{w:h,h:u,r:m}}}function Q4(t,e){let n=t5(t.poly,e/4),r=n.length;if(r<3||r>48)return;let c=0,a=0;for(let[u,f]of n)c+=u/r,a+=f/r;let s=[c,a],i=n.map(u=>N1(u,s)),o=n.map((u,f)=>N1(u,n[(f+1)%r])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-c)*180/Math.PI);if(l(o)<=e&&l(i)<=e&&r<=24){let u=i.reduce((m,g)=>m+g,0)/r,f=360/r,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${r}, ${P1(u)})`,at:s,angle:d,center:s}}if(r%2===0&&r>=4&&l(o)<=e){let u=i.filter((x,M)=>M%2===0),f=i.filter((x,M)=>M%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,M)=>x+M,0)/u.length,m=f.reduce((x,M)=>x+M,0)/f.length,g=h[0];if(m>d&&([d,m]=[m,d],g=h[1]),d-m<e)return;let p=r/2,v=360/p,y=((g-90)%v+v)%v;v-y<.01&&(y=0);let b=H1(m)===H1(d*.45);return{kind:"star",body:`star(${p}, ${P1(d)}${b?"":`, ${P1(m)}`})`,at:s,angle:y,center:s}}}function Ro(t,e,n){let[r,c,a,s]=e,i=[[],[],[],[]],o=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let m=f[1];Math.abs(m-c)<=n?i[0].push(G4(f[0]-r,d[0]-r)):Math.abs(m-s)<=n?i[2].push(G4(a-f[0],a-d[0])):(o[0].push(m-c),o[2].push(s-m))}else{let m=f[0];Math.abs(m-a)<=n?i[1].push(G4(f[1]-c,d[1]-c)):Math.abs(m-r)<=n?i[3].push(G4(s-f[1],s-d[1])):(o[1].push(a-m),o[3].push(m-r))}}let l=[a-r,s-c,a-r,s-c],h=o.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:i.map(u=>$o(u,n)),depth:h,length:l}}var G4=(t,e)=>t<e?[t,e]:[e,t];function $o(t,e){t.sort((r,c)=>r[0]-c[0]);let n=[];for(let[r,c]of t){let a=n[n.length-1];a&&r<=a[1]+e?a[1]=Math.max(a[1],c):n.push([r,c])}return n}var H6=t=>t.reduce((e,[n,r])=>e+r-n,0);function Do(t,e,n,r,c,a){let s=[X4(0,0,t,e)],i=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],o=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=o[h];for(let f=0;f<r[h];f++){let d=u*(f+.5)/r[h];s.push(X4(d-c[h]/2,-a,d+c[h]/2,0).map(i[h]))}}),i1(s)}function R6(t,e,n){let r=t5(t.poly,e/4);if(r.length<8)return;let c=bn(r),a=r.map(H=>x2(H,-c)),s=e/2;for(let H=0;H<a.length;H++){let U=a[H],Y=a[(H+1)%a.length];if(Math.abs(U[0]-Y[0])>s&&Math.abs(U[1]-Y[1])>s)return}let i=z0([a]),o=Ro(a,i,s),l=(H,U)=>H.map(Y=>Y.map(Q=>O6(Q,U))),h=(H,U)=>w3([a],l(H,U),e),u=(H,U,Y)=>{let Q=x2(H,c);return{kind:"tabs",body:U,at:Q,angle:c,center:x2([(i[0]+i[2])/2,(i[1]+i[3])/2],c),...Y}},f=I2(t.poly),d=[0,1,2,3].filter(H=>H6(o.outer[H])<o.length[H]-s);if(!d.length)return;let m=d.map(H=>o.depth[H]).filter(H=>H!==void 0);if(!m.length)return;let g=[...new Set([n,...m].filter(H=>!!H).map(H1))];for(let H of g){let U=H1(i[2]-i[0]),Y=H1(i[3]-i[1]),Q=[[]];for(let N=0;N<4;N++){let J=H6(o.outer[N])>=o.length[N]-2*H-s?["flat"]:["out","in"],x1=[];for(let R1 of Q)for(let w0 of J)x1.push([...R1,w0]);Q.splice(0,Q.length,...x1)}let W=Math.max(3*H,6),F1=new Set([W]);for(let N of d){let a1=o.outer[N].length;for(let J of[2*a1-1,2*a1+1,2*a1-3,2*a1+3])J>=3&&F1.add(H1(o.length[N]/J))}for(let N of F1)for(let a1 of Q){if(a1.every(Y1=>Y1==="flat"))continue;let J=w4(U,Y,a1,H,N);if(Math.abs(Math.abs(J.reduce((Y1,A1)=>Y1+M1(A1),0))-t.area)>f*e||!h(J,[i[0],i[1]]))continue;let R1=a1.every(Y1=>Y1===a1[0])?`"${a1[0]}"`:`[${a1.map(Y1=>`"${Y1}"`).join(", ")}]`,w0=N===W||[0,1].every(Y1=>f3(o.length[Y1],N)===f3(o.length[Y1],W));return u([i[0],i[1]],`finger_rect(${s0([U,Y])}, ${R1}${w0?"":`, finger = ${P1(N)}`})`,{kind:"fingers",thickness:H,edges:a1,finger:w0?W:N})}let L1=[0,1,2,3].map(N=>d.includes(N)&&o.depth[N]!==void 0&&Math.abs(o.depth[N]-H)<=s);if(!L1.some(Boolean))continue;let g1=i[0]+(L1[3]?H:0),X1=i[1]+(L1[0]?H:0),D1=H1(i[2]-(L1[1]?H:0)-g1),E=H1(i[3]-(L1[2]?H:0)-X1),D=[D1,E,D1,E],e1=[L1[3]?H:0,L1[0]?H:0,L1[1]?H:0,L1[2]?H:0],u1=[0,0,0,0],t1=[0,0,0,0],V=!0;for(let N=0;N<4&&V;N++){if(!L1[N])continue;let a1=o.outer[N].map(([J,x1])=>[J-e1[N],x1-e1[N]]);u1[N]=a1.length,t1[N]=a1.length?H1(a1.reduce((J,[x1,R1])=>J+R1-x1,0)/a1.length):0,a1.forEach(([J,x1],R1)=>{(Math.abs((J+x1)/2-D[N]*(R1+.5)/u1[N])>s||Math.abs(x1-J-t1[N])>s)&&(V=!1)})}if(!V||!h(Do(D1,E,L1,u1,t1,H),[g1,X1]))continue;let n1=L1.every(Boolean)?"":`[${L1.join(", ")}]`,G=[0,1,2,3].filter(N=>L1[N]),k1=N=>Math.max(1,Math.round(D[N]/50)),r1=G.every(N=>u1[N]===k1(N)),U1=G.every(N=>u1[N]===u1[G[0]]),c1=r1?void 0:U1?u1[G[0]]:null,V1=G.every(N=>Math.abs(t1[N]-D[N]/(2*u1[N]))<=s),o0=G.every(N=>Math.abs(t1[N]-t1[G[0]])<=s),d0=V1?void 0:o0?t1[G[0]]:null,I;if(c1!==null&&d0!==null){let N=[s0([D1,E])];n1?N.push(n1):(c1!==void 0||d0!==void 0)&&N.push("true"),c1!==void 0&&N.push(`count = ${c1}`),d0!==void 0&&N.push(`width = ${P1(d0)}`),I=`tab_rect(${N.join(", ")})`}else{let N=[J=>J,J=>`translate(${s0([D1,0])}) rotate(90) ${J}`,J=>`translate(${s0([D1,E])}) rotate(180) ${J}`,J=>`translate(${s0([0,E])}) rotate(270) ${J}`],a1=[`rect(${s0([D1,E])});`];for(let J of G){let x1=[P1(D[J])];u1[J]!==k1(J)&&x1.push(`count = ${u1[J]}`),Math.abs(t1[J]-D[J]/(2*u1[J]))>s&&x1.push(`width = ${P1(t1[J])}`),a1.push(N[J](`tabs(${x1.join(", ")});`))}I=`{
|
|
2690
|
-
${
|
|
3069
|
+
`}var dl={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function R8(t,e={}){return t.replace(/&(#x[0-9a-fA-F]+|#\d+|[A-Za-z_][\w.-]*);/g,(n,r)=>{if(r[0]==="#"){let c=r[1]==="x"?parseInt(r.slice(2),16):parseInt(r.slice(1),10);return Number.isFinite(c)&&c<=1114111?String.fromCodePoint(c):n}return dl[r]??e[r]??n})}function F8(t){let e=[],n={},r={name:"#document",attrs:{},children:[],text:""},c=[r],a=0,s=i=>{let l=t.slice(0,a).split(`
|
|
3070
|
+
`).length;throw new Error(`${i} (line ${l})`)};for(;a<t.length;){let i=t.indexOf("<",a),l=i<0?t.length:i;if(l>a&&(c[c.length-1].text+=R8(t.slice(a,l),n)),i<0)break;if(a=i,t.startsWith("<!--",a)){let h=t.indexOf("-->",a+4);h<0&&s("Unclosed comment"),e.push(t.slice(a+4,h)),a=h+3}else if(t.startsWith("<![CDATA[",a)){let h=t.indexOf("]]>",a+9);h<0&&s("Unclosed CDATA section"),c[c.length-1].text+=t.slice(a+9,h),a=h+3}else if(t.startsWith("<?",a)){let h=t.indexOf("?>",a+2);h<0&&s("Unclosed processing instruction"),a=h+2}else if(t.startsWith("<!",a)){let h=0,u=a+2;for(;u<t.length;u++){let d=t[u];if(d==="[")h++;else if(d==="]")h--;else if(d===">"&&h<=0)break}let f=t.slice(a,u);for(let d of f.matchAll(/<!ENTITY\s+([\w.-]+)\s+(["'])([\s\S]*?)\2\s*>/g))n[d[1]]=d[3];a=u+1}else if(t[a+1]==="/"){let h=t.indexOf(">",a);h<0&&s("Unclosed end tag");let u=t.slice(a+2,h).trim(),f=c.pop();(!f||f===r||f.name!==u)&&s(`</${u}> does not match <${f?.name??"nothing"}>`),a=h+1}else{let h=/^<([^\s/>]+)/.exec(t.slice(a,a+256));h||s("Bad tag");let u={name:h[1],attrs:{},children:[],text:""};a+=h[0].length;let f=/\s*([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')|\s*(\/?>)/y;for(;;){f.lastIndex=a;let d=f.exec(t);if(d||s(`Bad attribute in <${u.name}>`),a=f.lastIndex,d[5]){c[c.length-1].children.push(u),d[5]===">"&&c.push(u);break}u.attrs[d[1]]=R8(d[3]??d[4]??"",n)}}}c.length>1&&s(`<${c[c.length-1].name}> is not closed`);let o=r.children[0];if(!o)throw new Error("The file has no elements");return{root:o,comments:e}}var d2={cut:{name:"cut",mode:"cut",color:"#ff0000"},score:{name:"score",mode:"line",color:"#0000ff"},engrave:{name:"engrave",mode:"fill",color:"#000000"},guide:{name:"guide",mode:"guide",color:"#00a0ff"}},Zt={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"},ml=Object.fromEntries(Object.entries(Zt).reverse().map(([t,e])=>[e,t]));function Y5(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(Zt[t])return Zt[t];let n=/^#([0-9a-f]{3,8})$/.exec(t);if(n){let r=n[1];if(r.length===3||r.length===4)return"#"+[...r.slice(0,3)].map(c=>c+c).join("");if(r.length===6||r.length===8)return"#"+r.slice(0,6)}if(n=/^rgba?\(([^)]*)\)$/.exec(t),n){let r=n[1].split(/[\s,/]+/).filter(Boolean);if(r.length>=3){let c=r.slice(0,3).map(a=>{let s=a.endsWith("%")?parseFloat(a)*255/100:parseFloat(a);return Math.max(0,Math.min(255,Math.round(s||0)))});return r[3]!==void 0&&parseFloat(r[3])===0?"none":"#"+c.map(a=>a.toString(16).padStart(2,"0")).join("")}}return"#000000"}var o5=(t,e)=>W3(t,Math.PI/12,e),J5=t=>(t.match(/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[]).map(Number);function pl(t){let e=R4;if(!t)return e;for(let[,n,r]of t.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let c=J5(r),a=(c[0]??0)*Math.PI/180,s=R4;if(n==="matrix"&&c.length===6)s=c;else if(n==="translate")s=[1,0,0,1,c[0]??0,c[1]??0];else if(n==="scale")s=[c[0]??1,0,0,c[1]??c[0]??1,0,0];else if(n==="rotate"){let o=Math.cos(a),i=Math.sin(a),[l,h]=[c[1]??0,c[2]??0];s=[o,i,-i,o,l-o*l+i*h,h-i*l-o*h]}else n==="skewX"?s=[1,0,Math.tan(a),1,0,0]:n==="skewY"&&(s=[1,Math.tan(a),0,1,0,0]);e=D3(e,s)}return e}function gl(t,e){let n=[],r=[],c=[0,0],a=[0,0],s=(l,h)=>A5(e,[l,h]),o=(l,h)=>Math.abs(l[0]-h[0])<1e-9&&Math.abs(l[1]-h[1])<1e-9,i=l=>{r.length&&n.push({segs:r,closed:l}),r=[]};for(let l of t)if(l.type==="M")i(!1),c=a=s(l.x,l.y);else if(l.type==="L"){let h=s(l.x,l.y);o(a,h)||r.push({c:"L",a,b:h}),a=h}else if(l.type==="Q"){let h=s(l.x1,l.y1),u=s(l.x,l.y);r.push({c:"C",a,p1:[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],p2:[u[0]+2/3*(h[0]-u[0]),u[1]+2/3*(h[1]-u[1])],b:u}),a=u}else if(l.type==="C"){let h=s(l.x,l.y);r.push({c:"C",a,p1:s(l.x1,l.y1),p2:s(l.x2,l.y2),b:h}),a=h}else r.length&&!o(a,c)&&r.push({c:"L",a,b:c}),i(!0),a=c;return i(!1),n}var vl=["fill","stroke","stroke-width","fill-rule","display","visibility","opacity","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"],yl=new Set(["fill","stroke","stroke-width","fill-rule","visibility","fill-opacity","stroke-opacity","color","font-size","font-family","text-anchor"]);function D8(t){let e={};for(let n of t.split(";")){let r=n.indexOf(":");if(r<0)continue;let c=n.slice(0,r).trim().toLowerCase(),a=n.slice(r+1).replace(/!important/i,"").trim();c&&a&&(e[c]=a)}return e}function bl(t){let e=[];t=t.replace(/\/\*[\s\S]*?\*\//g,"");for(let[,n,r]of t.matchAll(/([^{}@]+)\{([^}]*)\}/g)){let c=D8(r);for(let a of n.split(",")){let s=a.trim(),o=/^([a-zA-Z][\w-]*|\*)?((?:[.#][\w-]+)*)$/.exec(s);if(!o)continue;let i=[],l;for(let[,h,u]of o[2].matchAll(/([.#])([\w-]+)/g))h==="."?i.push(u):l=u;e.push({tag:o[1]&&o[1]!=="*"?o[1]:void 0,id:l,classes:i,decls:c})}}return e}function q8(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 Xt(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])*q8(n[2].toLowerCase(),e)}var xl=/^(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 Ml(t){for(let e of["data-part","inkscape:label","data-name","id"]){let n=t.attrs[e]?.trim();if(n&&!xl.test(n)&&!/^[\d_-]+$/.test(n))return n.replace(/_x5F_|_/g," ").trim()}}function wl(t){if(!t)return;let e=t.toLowerCase();if(/\bscor|\bscoring/.test(e))return d2.score;if(/engrav|raster|etch/.test(e))return d2.engrave;if(/\bguide/.test(e))return d2.guide;if(/^cut|\bcut\b|cutting|\bcuts\b/.test(e))return d2.cut}function N8(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=F8(t),r=n.root;if(r.name.replace(/^.*:/,"")!=="svg")throw new Error("This is not an SVG file");let c=[],a=n.comments.some(D=>/Adobe Illustrator/i.test(D)),s=e.dpi??(a?72:96);e.dpi===void 0&&a&&c.push("Adobe Illustrator file: px measured at 72 per inch.");let o=J5(r.attrs.viewBox??""),i=Xt(r.attrs.width,s),l=Xt(r.attrs.height,s),h=25.4/s,u=h,f=h,d=0,p=0,m=0,g=0;if(o.length===4&&o[2]>0&&o[3]>0&&(u=i!==void 0?i/o[2]:l!==void 0?l/o[3]:h,f=l!==void 0?l/o[3]:u,d=o[0],p=o[1],i!==void 0&&l!==void 0)){let D=(r.attrs.preserveAspectRatio??"").trim().split(/\s+/).filter(Boolean);D[0]==="defer"&&D.shift();let J=D[0]??"xMidYMid";if(J!=="none"){let t1=D[1]==="slice"?Math.max(u,f):Math.min(u,f),w1=(n1,E)=>n1.test(J)?0:E.test(J)?1:.5;m=(i-o[2]*t1)*w1(/xMin/,/xMax/),g=(l-o[3]*t1)*w1(/YMin/,/YMax/),u=f=t1}}i===void 0&&l===void 0&&e.dpi===void 0&&!a&&c.push(`The file gives no page size in mm or inches: px measured at ${s} per inch.`);let v=l??(o.length===4?o[3]*f:0),b=D3([1,0,0,-1,0,v],[u,0,0,f,-d*u+m,-p*f+g]),y=o.length===4?o[2]:(i??0)/h,x=o.length===4?o[3]:(l??0)/h,w=(D,J)=>{if(D===void 0)return 0;let t1=/^\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)\s*([a-zA-Z%]*)\s*$/.exec(D);if(!t1)return parseFloat(D)||0;let w1=Number(t1[1]),n1=t1[2].toLowerCase();return n1==="%"?w1/100*(J==="x"?y:J==="y"?x:Math.hypot(y,x)/Math.SQRT2):n1===""||n1==="px"?w1:w1*q8(n1,s)/h},M=[],k=new Map,z=D=>{D.name==="style"&&M.push(...bl(D.text)),D.attrs.id&&k.set(D.attrs.id,D),D.children.forEach(z)};z(r);let A=(D,J)=>{let t1={};for(let n1 of Object.keys(J))yl.has(n1)&&(t1[n1]=J[n1]);for(let n1 of vl)D.attrs[n1]!==void 0&&(t1[n1]=D.attrs[n1]);let w1=(D.attrs.class??"").split(/\s+/).filter(Boolean);for(let n1 of M)(!n1.tag||n1.tag===D.name)&&(!n1.id||n1.id===D.attrs.id)&&n1.classes.every(E=>w1.includes(E))&&Object.assign(t1,n1.decls);return D.attrs.style&&Object.assign(t1,D8(D.attrs.style)),t1},S=[],C=[],I=0,L=0,T=0,q=0,P=0,F=0,j=2e4,_=[],Q=D=>Number.isFinite(D[0])&&Number.isFinite(D[1]),H=["x","y","width","height","rx","ry","cx","cy","r"],B=D=>[...H,"x1","y1","x2","y2","points"].some(J=>D.attrs[J]!==void 0&&J5(D.attrs[J]).some(t1=>!Number.isFinite(t1))),Y=new Set(["defs","clipPath","mask","pattern","marker","symbol","metadata","title","desc","style","script","linearGradient","radialGradient","filter","sodipodi:namedview","foreignObject"]),e1=new Set(["path","rect","circle","ellipse","line","polyline","polygon"]),X=D=>{let J=t1=>w(D.attrs[t1],/^(x|cx|rx|x1|x2|width)$/.test(t1)?"x":/^(y|cy|ry|y1|y2|height)$/.test(t1)?"y":"r");switch(D.name){case"path":return o5(D.attrs.d??"",()=>T++);case"rect":{let[t1,w1,n1,E]=[J("x"),J("y"),J("width"),J("height")];if(n1<=0||E<=0)return[];let R=D.attrs.rx!==void 0?J("rx"):D.attrs.ry!==void 0?J("ry"):0,Z=D.attrs.ry!==void 0?J("ry"):R;return R=Math.min(Math.abs(R),n1/2),Z=Math.min(Math.abs(Z),E/2),R<=0||Z<=0?o5(`M${t1} ${w1}H${t1+n1}V${w1+E}H${t1}Z`):o5(`M${t1+R} ${w1}H${t1+n1-R}A${R} ${Z} 0 0 1 ${t1+n1} ${w1+Z}V${w1+E-Z}A${R} ${Z} 0 0 1 ${t1+n1-R} ${w1+E}H${t1+R}A${R} ${Z} 0 0 1 ${t1} ${w1+E-Z}V${w1+Z}A${R} ${Z} 0 0 1 ${t1+R} ${w1}Z`)}case"circle":case"ellipse":{let[t1,w1]=[J("cx"),J("cy")],n1=D.name==="circle"?J("r"):J("rx"),E=D.name==="circle"?J("r"):D.attrs.ry!==void 0?J("ry"):n1;return n1<=0||E<=0?[]:o5(`M${t1+n1} ${w1}A${n1} ${E} 0 0 1 ${t1} ${w1+E}A${n1} ${E} 0 0 1 ${t1-n1} ${w1}A${n1} ${E} 0 0 1 ${t1} ${w1-E}A${n1} ${E} 0 0 1 ${t1+n1} ${w1}Z`)}case"line":return o5(`M${J("x1")} ${J("y1")}L${J("x2")} ${J("y2")}`);case"polyline":case"polygon":{let t1=J5(D.attrs.points??"");if(t1.length<4)return[];let w1=`M${t1[0]} ${t1[1]}`;for(let n1=2;n1+1<t1.length;n1+=2)w1+=`L${t1[n1]} ${t1[n1+1]}`;return o5(D.name==="polygon"?w1+"Z":w1)}}},M1=D=>(D.text+D.children.map(J=>J.name==="tspan"?" "+M1(J):"").join("")).replace(/\s+/g," ").trim(),v1=(D,J,t1,w1,n1,E)=>{if(E>64||Y.has(D.name)||P&&++F>j)return;let R=A(D,t1);if(R.display==="none"||R.visibility==="hidden"||R.opacity==="0"){(D.children.length||e1.has(D.name))&&L++;return}let Z=D3(J,pl(D.attrs.transform));if(!Z.every(Number.isFinite)){q++;return}let K=Ml(D),k1=D.attrs["inkscape:groupmode"]==="layer",O1=w1;if(D.name==="g"||D.name==="svg"||D.name==="a"||D.name==="switch"){let m1=D.attrs["inkscape:label"]??D.attrs["data-name"]??D.attrs.id,S1=wl(m1);if(D.attrs["data-mode"]&&m1&&/^(cut|line|fill|guide)$/.test(D.attrs["data-mode"])){let i0=Y5(R.stroke,"#000000"),V1=Y5(R.fill,"#000000"),X1=D.attrs["data-mode"]==="fill"?V1:i0;O1=d2[m1]??{name:m1,mode:D.attrs["data-mode"],color:X1&&X1.startsWith("#")?X1:"#00aa00"}}else S1&&(O1=S1);if(D!==r&&D.name==="svg"){let i0=V1=>parseFloat(D.attrs[V1]??"0")||0;Z=D3(Z,[1,0,0,1,i0("x"),i0("y")])}let Z1=k1||S1||D===r||!K?n1:[K,...n1];_.push(D);for(let i0 of D.children)v1(i0,Z,R,O1,Z1,E+1);_.pop();return}if(D.name==="use"){let m1=k.get((D.attrs.href??D.attrs["xlink:href"]??"").replace(/^#/,""));if(!m1||_.includes(m1))return;let S1=V1=>parseFloat(D.attrs[V1]??"0")||0,Z1=D3(Z,[1,0,0,1,S1("x"),S1("y")]),i0=m1.name==="symbol"?{...m1,name:"g"}:m1;_.push(m1),P++,v1(i0,Z1,R,O1,K?[K,...n1]:n1,E+1),P--,_.pop();return}if(D.name==="image"){I++;return}let z0=Y5(R.color,"#000000")??"#000000",n0=parseFloat(R["stroke-width"]??"1"),j1=Y5(R.stroke,z0);j1&&(n0===0||R["stroke-opacity"]==="0")&&(j1="none");let X0=Y5(R.fill??"black",z0);if(R["fill-opacity"]==="0"&&(X0="none"),D.name==="text"){let m1=M1(D);if(!m1)return;let S1=D.children.find(O0=>O0.name==="tspan"),Z1=O0=>J5(D.attrs[O0]??S1?.attrs[O0]??"0")[0]??0,i0=A5(Z,[Z1("x"),Z1("y")]),V1=Math.sqrt(Math.abs(Z[0]*Z[3]-Z[1]*Z[2])),X1=(Xt(R["font-size"],96)??16*h)/h;if(!Q(i0)||!Number.isFinite(X1*V1)){q++;return}let d0=R["text-anchor"];C.push({text:m1,at:i0,size:X1*V1,angle:Math.atan2(-Z[1],Z[0])*180/Math.PI,font:(R["font-family"]??"").split(",")[0].replace(/['"]/g,"").trim(),anchor:d0==="middle"?"center":d0==="end"?"right":"left",stroke:j1,fill:X0,layer:O1});return}if(D.name!=="path"&&B(D)){q++;return}let g1=X(D);if(!g1){for(let m1 of D.children)v1(m1,Z,R,O1,n1,E+1);return}let L1=gl(g1,Z),z1=L1.filter(m1=>m1.segs.every(S1=>Q(S1.a)&&Q(S1.b)&&(S1.c==="L"||Q(S1.p1)&&Q(S1.p2))));z1.length<L1.length&&q++,z1.length&&S.push({subs:z1,stroke:j1,fill:D.name==="line"||D.name==="polyline"?"none":X0,fillRule:R["fill-rule"]==="evenodd"?"evenodd":"nonzero",layer:O1,names:K?[K,...n1]:n1})};v1(r,b,{},void 0,[],0),I&&c.push(`${I} embedded image${I===1?" was":"s were"} left out: trace ${I===1?"it":"them"} to paths first.`),L&&c.push(`${L} hidden element${L===1?" was":"s were"} left out.`),T&&c.push(`${T} path${T===1?" has":"s have"} bad data: read up to the error, as browsers draw ${T===1?"it":"them"}.`),q&&c.push(`${q} element${q===1?" was":"s were"} left out: ${q===1?"its":"their"} numbers are too large to draw.`),F>j&&c.push(`The drawing repeats its elements with <use> more than ${j.toLocaleString("en")} times: only the first ${j.toLocaleString("en")} copies were read.`);let p1=D=>{let[J,t1,w1]=[1,3,5].map(n1=>parseInt(D.slice(n1,n1+2),16));return J>=200&&t1<=80&&w1<=80},G1=D=>{let[J,t1,w1]=[1,3,5].map(n1=>parseInt(D.slice(n1,n1+2),16));return w1>=200&&J<=80&&t1<=80},F1=D=>!!D.stroke&&D.stroke!=="none",V=S.filter(D=>!D.layer),U=new Map;for(let D of V)F1(D)&&D.stroke.startsWith("#")&&U.set(D.stroke,(U.get(D.stroke)??0)+D.subs.length);let r1=[...U.keys()],h1=r1.filter(p1),a1=new Set(h1.length?h1:r1.length?[r1.reduce((D,J)=>(U.get(J)??0)>(U.get(D)??0)?J:D)]:[]),x1=S.some(D=>F1(D)&&!D.layer)||S.some(D=>D.layer),J1=new Map,q1=(D,J)=>{if(D&&D!=="none"){let t1=D.startsWith("#")?D:"#000000";if(a1.has(t1))return d2.cut;if(t1==="#00a0ff")return d2.guide;if(G1(t1))return d2.score;if(!J1.has(t1)){let w1=ml[t1]??"color_"+t1.slice(1);J1.set(t1,{name:w1,mode:"line",color:t1})}return J1.get(t1)}if(J&&J!=="none")return x1?d2.engrave:d2.cut};!x1&&S.some(D=>D.fill&&D.fill!=="none")?c.push("The file has filled shapes and no strokes: the shapes are cut out."):!h1.length&&a1.size&&c.push(`No red lines: ${[...a1][0]} lines, the most common colour, are cut.`),J1.size&&c.push(`Lines in ${[...J1.values()].map(D=>D.color).join(", ")} went on their own layer${J1.size===1?"":"s"}, set to mark, not cut.`);let f0=[];for(let D of S){let J=D.layer??q1(D.stroke,D.fill);if(!J)continue;let t1=!D.layer&&J===d2.cut&&!F1(D);f0.push({subs:D.subs,layer:J,fillRule:D.fillRule,names:D.names,filled:t1})}let m0=[];for(let D of C){let J=D.layer??q1(D.fill!=="none"?void 0:D.stroke,D.fill);J&&m0.push({...D,layer:J.mode==="cut"&&x1?d2.engrave:J})}return{items:f0,texts:m0,notes:c}}var N1=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),M2=([t,e],n)=>{let r=n*Math.PI/180,c=Math.cos(r),a=Math.sin(r);return[t*c-e*a,t*a+e*c]},Jt=(t,e)=>[t[0]+e[0],t[1]+e[1]],w2=(t,e)=>[t[0]-e[0],t[1]-e[1]];function C3(t,e=.005){let n=[t.segs[0].a];for(let r of t.segs)if(r.c==="L")n.push(r.b);else{let c=N1(r.a,r.p1)+N1(r.p1,r.p2)+N1(r.p2,r.b),a=Math.max(2,Math.min(512,Math.ceil(Math.sqrt(c/e))));for(let s=1;s<=a;s++){let o=s/a,i=1-o;n.push([i*i*i*r.a[0]+3*i*i*o*r.p1[0]+3*i*o*o*r.p2[0]+o*o*o*r.b[0],i*i*i*r.a[1]+3*i*i*o*r.p1[1]+3*i*o*o*r.p2[1]+o*o*o*r.b[1]])}}return t.closed&&n.length>1&&N1(n[0],n[n.length-1])<1e-9&&n.pop(),n}function V2(t,e=!0){let n=0;for(let r=1;r<t.length;r++)n+=N1(t[r-1],t[r]);return e&&t.length>2?n+N1(t[t.length-1],t[0]):n}function G2(t,e,n){let r=[],c=e?t.length:t.length-1;for(let a=0;a<c;a++){let s=t[a],o=t[(a+1)%t.length];r.push(s);let i=Math.floor(N1(s,o)/n);for(let l=1;l<i;l++)r.push([s[0]+(o[0]-s[0])*l/i,s[1]+(o[1]-s[1])*l/i])}return!e&&t.length&&r.push(t[t.length-1]),r}function i3(t,e,n){let r=n[0]-e[0],c=n[1]-e[1],a=r*r+c*c,s=a?((t[0]-e[0])*r+(t[1]-e[1])*c)/a:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(t[0]-e[0]-s*r,t[1]-e[1]-s*c)}var L3=class{constructor(e,n,r){this.size=r;this.cells=new Map;for(let c of e){let a=n?c.length:c.length-1;for(let s=0;s<a;s++){let o=c[s],i=c[(s+1)%c.length],l=Math.max(1,Math.ceil(N1(o,i)/(r*2)));for(let h=0;h<l;h++){let u=[o[0]+(i[0]-o[0])*h/l,o[1]+(i[1]-o[1])*h/l],f=[o[0]+(i[0]-o[0])*(h+1)/l,o[1]+(i[1]-o[1])*(h+1)/l],d=Math.floor(Math.min(u[0],f[0])/r),p=Math.floor(Math.max(u[0],f[0])/r),m=Math.floor(Math.min(u[1],f[1])/r),g=Math.floor(Math.max(u[1],f[1])/r);for(let v=d;v<=p;v++)for(let b=m;b<=g;b++){let y=`${v},${b}`,x=this.cells.get(y);x?x.push([u,f]):this.cells.set(y,[[u,f]])}}}}}near(e,n){let r=Math.floor((e[0]-n)/this.size),c=Math.floor((e[0]+n)/this.size),a=Math.floor((e[1]-n)/this.size),s=Math.floor((e[1]+n)/this.size);for(let o=r;o<=c;o++)for(let i=a;i<=s;i++)for(let[l,h]of this.cells.get(`${o},${i}`)??[])if(i3(e,l,h)<=n)return!0;return!1}meets(e,n,r){let c=Math.max(1,Math.ceil(N1(e,n)/(this.size*2)));for(let a=0;a<c;a++){let s=[e[0]+(n[0]-e[0])*a/c,e[1]+(n[1]-e[1])*a/c],o=[e[0]+(n[0]-e[0])*(a+1)/c,e[1]+(n[1]-e[1])*(a+1)/c],i=Math.floor((Math.min(s[0],o[0])-r)/this.size),l=Math.floor((Math.max(s[0],o[0])+r)/this.size),h=Math.floor((Math.min(s[1],o[1])-r)/this.size),u=Math.floor((Math.max(s[1],o[1])+r)/this.size);for(let f=i;f<=l;f++)for(let d=h;d<=u;d++)for(let[p,m]of this.cells.get(`${f},${d}`)??[])if(B8(s,o,p,m)<=r)return!0}return!1}};function B8(t,e,n,r){let c=(l,h,u)=>(h[0]-l[0])*(u[1]-l[1])-(h[1]-l[1])*(u[0]-l[0]),a=c(n,r,t),s=c(n,r,e),o=c(t,e,n),i=c(t,e,r);return a*s<0&&o*i<0?0:Math.min(i3(t,n,r),i3(e,n,r),i3(n,t,e),i3(r,t,e))}function kl(t,e,n=.2){let r=t.length;if(r<4)return!1;let c=[0];for(let h=1;h<=r;h++)c.push(c[h-1]+N1(t[h-1],t[h%r]));let a=c[r],s=w0([t]),o=Math.max(s[2]-s[0],s[3]-s[1],e)/Math.max(1,Math.sqrt(r)),i=new Map,l=(h,u)=>{let f=[],d=Math.floor((Math.min(h[0],u[0])-e)/o),p=Math.floor((Math.max(h[0],u[0])+e)/o),m=Math.floor((Math.min(h[1],u[1])-e)/o),g=Math.floor((Math.max(h[1],u[1])+e)/o);if((p-d+1)*(g-m+1)>4096)return null;for(let v=d;v<=p;v++)for(let b=m;b<=g;b++)f.push(`${v},${b}`);return f};for(let h=0;h<r;h++){let u=t[h],f=t[(h+1)%r],d=l(u,f);if(!d)return!1;for(let p of d)for(let m of i.get(p)??[]){let g=Math.abs(c[h]-c[m]);if(!(Math.min(g,a-g)-N1(u,f)-N1(t[m],t[(m+1)%r])<n)&&B8(u,f,t[m],t[(m+1)%r])<=e)return!0}for(let p of d){let m=i.get(p);m?m.push(h):i.set(p,[h])}}return!1}function _8(t,e){let n=t.map(()=>!1),r=[],c=t.map(l=>w0([l]));t.forEach((l,h)=>{let u=s1([l]),f=u.reduce((m,g)=>m+b1(g),0),d=V2(l),p=u.reduce((m,g)=>m+V2(g),0);(u.length!==1||Math.abs(f-Math.abs(b1(l)))>d*.001+1e-6||Math.abs(p-d)>d*.001+.05||kl(l,e))&&(n[h]=!0)});let a=new Map,s=l=>{let h=a.get(l);return h||a.set(l,h=new L3([t[l]],!0,Math.max(e*4,1))),h},o=t.map((l,h)=>h).sort((l,h)=>c[l][0]-c[h][0]),i=[];for(let l of o){let[h,u,f,d]=c[l];for(let p=i.length-1;p>=0;p--)c[i[p]][2]<h-e&&i.splice(p,1);for(let p of i){let m=c[p];if(m[1]>d+e||m[3]<u-e)continue;let[g,v]=t[l].length<=t[p].length?[l,p]:[p,l],b=t[g],y=s(v);for(let x=0;x<b.length;x++)if(y.meets(b[x],b[(x+1)%b.length],e)){r.push([l,p]);break}}i.push(l)}return{self:n,pairs:r}}function P3(t,e,n,r=!0){if(!t.length||!e.length)return t.length===e.length;let c=Math.max(n*2,.2),a=new L3(t,r,Math.max(n*4,1)),s=new L3(e,r,Math.max(n*4,1));for(let o of t)for(let i of G2(o,r,c))if(!s.near(i,n))return!1;for(let o of e)for(let i of G2(o,r,c))if(!a.near(i,n))return!1;return!0}function j8(t,e,n){let r=new L3([t,...e],!0,Math.max(n*4,1)),c=a=>j2(a,t)&&!e.some(s=>j2(a,s));return(a,s)=>{let o=s?a.length:a.length-1;if(o<1)return!1;let i;for(let l=0;l<o;l++){let h=a[l],u=a[(l+1)%a.length];if(!r.meets(h,u,n)){i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2]);continue}if(s||l!==0&&l!==o-1)return!1;let f=N1(h,u),d=Math.min(n*3,f/3)/f,p=l===0?[h[0]+(u[0]-h[0])*d,h[1]+(u[1]-h[1])*d]:h,m=l===o-1?[u[0]-(u[0]-h[0])*d,u[1]-(u[1]-h[1])*d]:u;if(r.meets(p,m,n))return!1;i??(i=[(h[0]+u[0])/2,(h[1]+u[1])/2])}return i?c(i):!0}}function G8(t,e,n){if(!t.length)return!1;let r=new L3([e],!0,Math.max(n*4,1));return t.some(c=>G2(c,!1,Math.max(n*2,.2)).some(a=>r.near(a,n)))}function j2(t,e){let n=!1;for(let r=0,c=e.length-1;r<e.length;c=r++){let[a,s]=e[r],[o,i]=e[c];s>t[1]!=i>t[1]&&t[0]<(o-a)*(t[1]-s)/(i-s)+a&&(n=!n)}return n}function a4(t){let e=t.length;if(e<3)return null;let n=0,r=0;for(let[g,v]of t)n+=g,r+=v;n/=e,r/=e;let c=0,a=0,s=0,o=0,i=0,l=0,h=0;for(let[g,v]of t){let b=g-n,y=v-r;c+=b*b,a+=b*y,s+=y*y,o+=b*b*b,i+=y*y*y,l+=b*y*y,h+=y*b*b}let u=c*s-a*a;if(Math.abs(u)<1e-12)return null;let f=(o+l)/2,d=(i+h)/2,p=(f*s-d*a)/u,m=(d*c-f*a)/u;return{c:[p+n,m+r],r:Math.sqrt(p*p+m*m+(c+s)/e)}}function i5(t,e=.01){if(t.length<4)return t;let n=0;for(let i=1;i<t.length;i++)N1(t[0],t[i])>N1(t[0],t[n])&&(n=i);let r=i=>{if(i.length<3)return i;let l=0,h=0;for(let f=1;f<i.length-1;f++){let d=i3(i[f],i[0],i[i.length-1]);d>l&&(l=d,h=f)}return l<=e?[i[0],i[i.length-1]]:[...r(i.slice(0,h+1)).slice(0,-1),...r(i.slice(h))]},c=r(t.slice(0,n+1)),a=r([...t.slice(n),t[0]]),s=[...c.slice(0,-1),...a.slice(0,-1)],o=[];for(let i=0;i<s.length;i++){let l=s[(i-1+s.length)%s.length],h=s[(i+1)%s.length];i3(s[i],l,h)>e&&o.push(s[i])}return o.length>=3?o:s}function W8(t){let e=[],n=[];for(let a of t.slice(0,300)){let s=i5(a,.002),o=s.length,i=s.findIndex((u,f)=>N1(u,s[(f+1)%o])>=.5);if(o<4||i<0)continue;let l=b1(a)>0,h=[];for(let u=1;u<=o;u++){let f=(i+u)%o,d=s[f],p=s[(f+1)%o];if(N1(d,p)<.3){h.length||h.push(d),h.push(p);continue}if(h.length>=3){let m=a4(h),[g,v,b]=[h[0],h[1],h[h.length-1]],y=(v[0]-g[0])*(b[1]-g[1])-(v[1]-g[1])*(b[0]-g[0]);m&&m.r>.005&&m.r<.6&&(y>0===l?e:n).push(m.r)}h=[]}}if(e.length<4)return;e.sort((a,s)=>a-s);let r=e[Math.floor(e.length/2)],c=a=>Math.abs(a-r)<=Math.max(.005,r*.1);if(!(r>.2||n.filter(c).length>e.length*.2))return e.filter(c).length>=e.length*.8?r:void 0}function Kt(t,e){let n=t.length,r=o=>N1(t[o],t[(o+1)%n])<e*1.5,c=t.findIndex((o,i)=>!r(i));if(c<0)return t;let a=[],s=c;do{let o=(s+1)%n;for(;r(o)&&o!==s;)o=(o+1)%n;let i=(o-s-1+n)%n,l=t[s],h=t[(s+1)%n],u=t[o],f=t[(o+1)%n],d;if(i>0){let p=(h[0]-l[0])*(f[1]-u[1])-(h[1]-l[1])*(f[0]-u[0]);if(Math.abs(p)>1e-12){let m=((u[0]-l[0])*(f[1]-u[1])-(u[1]-l[1])*(f[0]-u[0]))/p,g=[l[0]+m*(h[0]-l[0]),l[1]+m*(h[1]-l[1])],v=t[(s+1+Math.floor(i/2))%n],b=[];for(let w=1;w<=i+1;w++)b.push(t[(s+w)%n]);let y=b.length>=3?a4(b):{c:g,r:e};!!y&&Math.abs(y.r-e)<=e*.3&&N1(g,v)<=e*2&&m>=1-1e-9&&(d=g)}}if(a.push(l),d)a.push(d);else for(let p=1;p<=i;p++)a.push(t[(s+p)%n]);s=o}while(s!==c);return a}function $1(t){for(let r of[0,1,2]){let c=10**r,a=Math.round(t*c)/c;if(Math.abs(t-a)<=.003)return Object.is(a,-0)?0:a}let n=Math.round(t*1e3)/1e3;return Object.is(n,-0)?0:n}var I1=t=>String($1(t)),s0=t=>`[${I1(t[0])}, ${I1(t[1])}]`;function zl(t){t=(t%360+540)%360-180;let e=Math.round(t*100)/100;return Math.abs(e-Math.round(e))<.02?Math.round(e):e}function H2(t,e,n){let r=[];($1(t[0])!==0||$1(t[1])!==0)&&r.push(`translate(${s0(t)})`);let c=zl(e);return c!==0&&r.push(`rotate(${c})`),[...r,n].join(" ")}function K5(t,e){return{poly:t,area:Math.abs(b1(t)),box:w0([t]),ends:e?.segs.map(n=>n.a)}}var c4=(t,e,n,r)=>[[t,e],[n,e],[n,r],[t,r]];function s4(t,e){let n=V2(t.poly),r=G2(t.poly,!0,Math.min(.5,n/256)),c=a4(t.ends&&t.ends.length>=3?t.ends:t.poly.length>=8?t.poly:r);if(!c||c.r<.05)return;let a=Math.min(e*.6,Math.max(e/2,c.r*3e-4));for(let o of t.poly)if(Math.abs(N1(o,c.c)-c.r)>a)return;let s=a+c.r*2e-4;for(let o of r)if(Math.abs(N1(o,c.c)-c.r)>s)return;if(!(Math.abs(t.area-Math.PI*c.r*c.r)>n*a*2))return{kind:"circle",body:`circle(d = ${I1(c.r*2)})`,at:c.c,angle:0,center:c.c,circle:c,radius:c.r}}function X8(t){let e=0,n=0;for(let[s,o]of t)e+=s,n+=o;e/=t.length,n/=t.length;let r=0,c=0,a=0;for(let[s,o]of t)r+=(s-e)**2,c+=(o-n)**2,a+=(s-e)*(o-n);return .5*Math.atan2(2*a,r-c)*180/Math.PI}function o4(t,e){let n=V2(t.poly),r=G2(t.poly,!0,Math.min(.5,n/256)),c=X8(r),a=r.map(m=>M2(m,-c)),[s,o,i,l]=w0([a]),h=(i-s)/2,u=(l-o)/2;if(h<.05||u<.05||Math.abs(h-u)<=e)return;let f=[(s+i)/2,(o+l)/2],d=Math.min(e*.6,Math.max(e/2,Math.max(h,u)*3e-4))+Math.max(h,u)*2e-4;for(let[m,g]of a){let v=Math.hypot((m-f[0])/h,(g-f[1])/u);if(Math.abs(v-1)*Math.min(h,u)>d)return}if(Math.abs(t.area-Math.PI*h*u)>n*d*2)return;let p=M2(f,c);return{kind:"ellipse",radius:Math.max(h,u),body:`ellipse(${s0([h,u])})`,at:p,angle:c,center:p}}function Z8(t){let e=0,n=0;for(let r=0;r<t.length;r++){let c=t[r],a=t[(r+1)%t.length],s=N1(c,a);s>e&&(e=s,n=Math.atan2(a[1]-c[1],a[0]-c[0])*180/Math.PI)}return n=(n%90+90)%90,n>45?n-90:n}function i4(t,e){let n=i5(t.poly,e/4),r=Z8(n),c=V2(t.poly),a=G2(t.poly,!0,Math.min(.5,c/256)).map(b=>M2(b,-r)),[s,o,i,l]=w0([a]),h=i-s,u=l-o;if(h<.05||u<.05)return;let f=Math.SQRT2+1,d=[[s,o],[i,o],[i,l],[s,l]].map(b=>Math.min(...a.map(y=>N1(y,b)))*f),p=d.reduce((b,y)=>b+y,0)/4;if(Math.max(...d)-Math.min(...d)>e*f)return;p<e&&(p=0),p=Math.min(p,h/2,u/2);let m=[(s+i)/2,(o+l)/2];for(let[b,y]of a){let x=Math.abs(b-m[0])-(h/2-p),w=Math.abs(y-m[1])-(u/2-p),M=Math.hypot(Math.max(x,0),Math.max(w,0))+Math.min(Math.max(x,w),0)-p;if(Math.abs(M)>e/2)return}if(Math.abs(t.area-(h*u-(4-Math.PI)*p*p))>c*e)return;let g=M2(m,r),v=$1(p)>0?`, r = ${I1(p)}`:"";return{kind:"rect",radius:p,body:`rect(${s0([h,u])}, center = true${v})`,at:g,angle:r,center:g,rect:{w:h,h:u,r:p}}}function l4(t,e){let n=i5(t.poly,e/4),r=n.length;if(r<3||r>48)return;let c=0,a=0;for(let[u,f]of n)c+=u/r,a+=f/r;let s=[c,a],o=n.map(u=>N1(u,s)),i=n.map((u,f)=>N1(u,n[(f+1)%r])),l=u=>Math.max(...u)-Math.min(...u),h=n.map(u=>Math.atan2(u[1]-a,u[0]-c)*180/Math.PI);if(l(i)<=e&&l(o)<=e&&r<=24){let u=o.reduce((p,m)=>p+m,0)/r,f=360/r,d=(h[0]%f+f)%f;return f-d<.01&&(d=0),{kind:"polygon",body:`regular_polygon(${r}, ${I1(u)})`,at:s,angle:d,center:s}}if(r%2===0&&r>=4&&l(i)<=e){let u=o.filter((x,w)=>w%2===0),f=o.filter((x,w)=>w%2===1);if(l(u)>e||l(f)>e)return;let d=u.reduce((x,w)=>x+w,0)/u.length,p=f.reduce((x,w)=>x+w,0)/f.length,m=h[0];if(p>d&&([d,p]=[p,d],m=h[1]),d-p<e)return;let g=r/2,v=360/g,b=((m-90)%v+v)%v;v-b<.01&&(b=0);let y=$1(p)===$1(d*.45);return{kind:"star",body:`star(${g}, ${I1(d)}${y?"":`, ${I1(p)}`})`,at:s,angle:b,center:s}}}function Sl(t,e,n){let[r,c,a,s]=e,o=[[],[],[],[]],i=[[],[],[],[]];for(let u=0;u<t.length;u++){let f=t[u],d=t[(u+1)%t.length];if(Math.abs(f[1]-d[1])<=n){let p=f[1];Math.abs(p-c)<=n?o[0].push(n4(f[0]-r,d[0]-r)):Math.abs(p-s)<=n?o[2].push(n4(a-f[0],a-d[0])):(i[0].push(p-c),i[2].push(s-p))}else{let p=f[0];Math.abs(p-a)<=n?o[1].push(n4(f[1]-c,d[1]-c)):Math.abs(p-r)<=n?o[3].push(n4(s-f[1],s-d[1])):(i[1].push(a-p),i[3].push(p-r))}}let l=[a-r,s-c,a-r,s-c],h=i.map(u=>u.length?Math.min(...u.filter(f=>f>n)):void 0);return{outer:o.map(u=>Al(u,n)),depth:h,length:l}}var n4=(t,e)=>t<e?[t,e]:[e,t];function Al(t,e){t.sort((r,c)=>r[0]-c[0]);let n=[];for(let[r,c]of t){let a=n[n.length-1];a&&r<=a[1]+e?a[1]=Math.max(a[1],c):n.push([r,c])}return n}var Yt=t=>t.reduce((e,[n,r])=>e+r-n,0);function Ll(t,e,n,r,c,a){let s=[c4(0,0,t,e)],o=[([l,h])=>[l,h],([l,h])=>[t-h,l],([l,h])=>[t-l,e-h],([l,h])=>[h,e-l]],i=[t,e,t,e];return n.forEach((l,h)=>{if(!l)return;let u=i[h];for(let f=0;f<r[h];f++){let d=u*(f+.5)/r[h];s.push(c4(d-c[h]/2,-a,d+c[h]/2,0).map(o[h]))}}),s1(s)}function Qt(t,e,n){let r=i5(t.poly,e/4);if(r.length<8)return;let c=Z8(r),a=r.map(H=>M2(H,-c)),s=e/2;for(let H=0;H<a.length;H++){let B=a[H],Y=a[(H+1)%a.length];if(Math.abs(B[0]-Y[0])>s&&Math.abs(B[1]-Y[1])>s)return}let o=w0([a]),i=Sl(a,o,s),l=(H,B)=>H.map(Y=>Y.map(e1=>Jt(e1,B))),h=(H,B)=>P3([a],l(H,B),e),u=(H,B,Y)=>{let e1=M2(H,c);return{kind:"tabs",body:B,at:e1,angle:c,center:M2([(o[0]+o[2])/2,(o[1]+o[3])/2],c),...Y}},f=V2(t.poly),d=[0,1,2,3].filter(H=>Yt(i.outer[H])<i.length[H]-s);if(!d.length)return;let p=d.map(H=>i.depth[H]).filter(H=>H!==void 0);if(!p.length)return;let m=[...new Set([n,...p].filter(H=>!!H).map($1))];for(let H of m){let B=$1(o[2]-o[0]),Y=$1(o[3]-o[1]),e1=[[]];for(let R=0;R<4;R++){let K=Yt(i.outer[R])>=i.length[R]-2*H-s?["flat"]:["out","in"],k1=[];for(let O1 of e1)for(let z0 of K)k1.push([...O1,z0]);e1.splice(0,e1.length,...k1)}let X=Math.max(3*H,6),M1=new Set([X]);for(let R of d){let Z=i.outer[R].length;for(let K of[2*Z-1,2*Z+1,2*Z-3,2*Z+3])K>=3&&M1.add($1(i.length[R]/K))}for(let R of M1)for(let Z of e1){if(Z.every(n0=>n0==="flat"))continue;let K=Ee(B,Y,Z,H,R);if(Math.abs(Math.abs(K.reduce((n0,j1)=>n0+b1(j1),0))-t.area)>f*e||!h(K,[o[0],o[1]]))continue;let O1=Z.every(n0=>n0===Z[0])?`"${Z[0]}"`:`[${Z.map(n0=>`"${n0}"`).join(", ")}]`,z0=R===X||[0,1].every(n0=>x3(i.length[n0],R)===x3(i.length[n0],X));return u([o[0],o[1]],`finger_rect(${s0([B,Y])}, ${O1}${z0?"":`, finger = ${I1(R)}`})`,{kind:"fingers",thickness:H,edges:Z,finger:z0?X:R})}let v1=[0,1,2,3].map(R=>d.includes(R)&&i.depth[R]!==void 0&&Math.abs(i.depth[R]-H)<=s);if(!v1.some(Boolean))continue;let p1=o[0]+(v1[3]?H:0),G1=o[1]+(v1[0]?H:0),F1=$1(o[2]-(v1[1]?H:0)-p1),V=$1(o[3]-(v1[2]?H:0)-G1),U=[F1,V,F1,V],r1=[v1[3]?H:0,v1[0]?H:0,v1[1]?H:0,v1[2]?H:0],h1=[0,0,0,0],a1=[0,0,0,0],x1=!0;for(let R=0;R<4&&x1;R++){if(!v1[R])continue;let Z=i.outer[R].map(([K,k1])=>[K-r1[R],k1-r1[R]]);h1[R]=Z.length,a1[R]=Z.length?$1(Z.reduce((K,[k1,O1])=>K+O1-k1,0)/Z.length):0,Z.forEach(([K,k1],O1)=>{(Math.abs((K+k1)/2-U[R]*(O1+.5)/h1[R])>s||Math.abs(k1-K-a1[R])>s)&&(x1=!1)})}if(!x1||!h(Ll(F1,V,v1,h1,a1,H),[p1,G1]))continue;let J1=v1.every(Boolean)?"":`[${v1.join(", ")}]`,q1=[0,1,2,3].filter(R=>v1[R]),f0=R=>Math.max(1,Math.round(U[R]/50)),m0=q1.every(R=>h1[R]===f0(R)),D=q1.every(R=>h1[R]===h1[q1[0]]),J=m0?void 0:D?h1[q1[0]]:null,t1=q1.every(R=>Math.abs(a1[R]-U[R]/(2*h1[R]))<=s),w1=q1.every(R=>Math.abs(a1[R]-a1[q1[0]])<=s),n1=t1?void 0:w1?a1[q1[0]]:null,E;if(J!==null&&n1!==null){let R=[s0([F1,V])];J1?R.push(J1):(J!==void 0||n1!==void 0)&&R.push("true"),J!==void 0&&R.push(`count = ${J}`),n1!==void 0&&R.push(`width = ${I1(n1)}`),E=`tab_rect(${R.join(", ")})`}else{let R=[K=>K,K=>`translate(${s0([F1,0])}) rotate(90) ${K}`,K=>`translate(${s0([F1,V])}) rotate(180) ${K}`,K=>`translate(${s0([0,V])}) rotate(270) ${K}`],Z=[`rect(${s0([F1,V])});`];for(let K of q1){let k1=[I1(U[K])];h1[K]!==f0(K)&&k1.push(`count = ${h1[K]}`),Math.abs(a1[K]-U[K]/(2*h1[K]))>s&&k1.push(`width = ${I1(a1[K])}`),Z.push(R[K](`tabs(${k1.join(", ")});`))}E=`{
|
|
3071
|
+
${Z.map(K=>" "+K).join(`
|
|
2691
3072
|
`)}
|
|
2692
|
-
}`}return u([
|
|
2693
|
-
${[`rect(${s0([x,
|
|
3073
|
+
}`}return u([p1,G1],E,{kind:"tabs",thickness:H,library:"tabs",label:`tabs ${I1(H)} mm deep`})}let g=i.depth;if(d.some(H=>g[H]===void 0))return;let v=[0,1,2,3].map(H=>d.includes(H)&&Yt(i.outer[H])<i.length[H]*.4),b=o[0]+(v[3]?g[3]:0),y=o[1]+(v[0]?g[0]:0),x=o[2]-(v[1]?g[1]:0)-b,w=o[3]-(v[2]?g[2]:0)-y,M=(H,B,Y,e1,X)=>H===0?[o[0]+B-b,e1,Y-B,X-e1]:H===1?[x-X,o[1]+B-y,X-e1,Y-B]:H===2?[o[2]-Y-b,w-X,Y-B,X-e1]:[e1,o[3]-Y-y,X-e1,Y-B],k=[[],[],[],[]],z=[[],[],[],[]],A=[],S=[[b-o[0],b-o[0]+x],[y-o[1],y-o[1]+w],[o[2]-(b+x),o[2]-b],[o[3]-(y+w),o[3]-y]];for(let H of d)if(v[H])for(let[B,Y]of i.outer[H])k[H].push(M(H,B,Y,-g[H],0));else{let B=S[H][0];for(let[Y,e1]of[...i.outer[H],[S[H][1],S[H][1]]]){let[X,M1]=[Math.max(B,S[H][0]),Math.min(Y,S[H][1])];M1-X>s&&((X-S[H][0]<=s||S[H][1]-M1<=s)&&A.push([H,z[H].length]),z[H].push(M(H,X,M1,-1,g[H]))),B=Math.max(B,e1)}}let C=([H,B,Y,e1])=>c4(H,B,H+Y,B+e1),I=s1([c4(0,0,x,w),...k.flat().map(C)]),L=()=>h(g0(I,z.flat().map(C)),[b,y]);if(!L())return;for(let[H,B]of A.reverse()){let[Y]=z[H].splice(B,1);L()||z[H].splice(B,0,Y)}let T=(H,B)=>{let Y=B%2===0,e1=V=>Y?V[0]:V[1];H.sort((V,U)=>e1(V)-e1(U));let X=H.every(V=>Math.abs(V[2]-H[0][2])<=s&&Math.abs(V[3]-H[0][3])<=s),M1=H.length>1?e1(H[1])-e1(H[0]):0,v1=H.every((V,U)=>Math.abs(e1(V)-e1(H[0])-U*M1)<=s),p1=$1(M1),G1=$1(e1(H[0])),F1=$1(G1+p1*(H.length-1));if(H.length>=3&&X&&v1&&p1>0&&Math.floor((F1-G1)/p1+1e-9)+1===H.length){let[,,V,U]=H[0],r1=Y?`[x, ${I1(H[0][1])}]`:`[${I1(H[0][0])}, y]`;return[`for (${Y?"x":"y"} = [${I1(G1)}:${I1(p1)}:${I1(F1)}]) translate(${r1}) rect(${s0([V,U])});`]}return H.map(([V,U,r1,h1])=>`translate(${s0([V,U])}) rect(${s0([r1,h1])});`)},q=[0,1,2,3].flatMap(H=>k[H].length?T(k[H],H):[]),P=[0,1,2,3].flatMap(H=>z[H].length?T(z[H],H):[]),F=q.length?`union() {
|
|
3074
|
+
${[`rect(${s0([x,w])});`,...q].join(`
|
|
2694
3075
|
`)}
|
|
2695
|
-
}`:`rect(${s0([x,
|
|
2696
|
-
${[
|
|
3076
|
+
}`:`rect(${s0([x,w])})`,j=P.length?`difference() {
|
|
3077
|
+
${[F.endsWith("}")?F:F+";",...P].join(`
|
|
2697
3078
|
`)}
|
|
2698
|
-
}`:B,Z=d.map(H=>H1(p[H])),h1=Z.sort((H,U)=>Z.filter(Y=>Y===U).length-Z.filter(Y=>Y===H).length)[0];return u([y,b],X,{kind:T.length?"fingers":"tabs",thickness:h1,generic:!0,label:`${T.length?"finger joints":"tabs"} ${P1(h1)} mm deep`})}function qo(t){let[e,n,r,c]=z0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,r3(h,t[d],t[f]));return u},s=[(e+r)/2,(n+c)/2],i=B2(s,t)?a(s):0,o=24;for(let h=0;h<=o;h++)for(let u=0;u<=o;u++){let f=[e+(r-e)*h/o,n+(c-n)*u/o];if(!B2(f,t))continue;let d=a(f);d>i&&(s=f,i=d)}let l=Math.max(r-e,c-n)/o;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!B2(d,t))continue;let m=a(d);m>i&&(s=d,i=m,h=!0)}h||(l/=2)}return{c:s,r:i}}function No(t,e,n){let c=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let i=c+Math.PI/2+Math.PI*s/64;a.push([t[0]+n*Math.cos(i),t[1]+n*Math.sin(i)])}for(let s=0;s<=64;s++){let i=c-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(i),e[1]+n*Math.sin(i)])}return a}function xn(t,e){let[n,r,c,a]=t.box;if(Math.max(c-n,a-r)>80)return;let s=I2(t.poly),i=_2(t.poly,!0,Math.min(.25,s/400)),o=qo(t.poly),l=i.filter(T=>Math.abs(N1(T,o.c)-o.r)<=e),h=Z4(l);if(!h||l.length<8)return;let u=i[0];for(let T of i)N1(T,h.c)>N1(u,h.c)&&(u=T);let f=N1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],m=T=>(T[0]-h.c[0])*d[0]+(T[1]-h.c[1])*d[1],g=T=>-(T[0]-h.c[0])*d[1]+(T[1]-h.c[1])*d[0],p=i.filter(T=>m(T)>h.r+e&&m(T)<f-h.r);if(p.length<4)return;let v=[p.filter(T=>g(T)>0),p.filter(T=>g(T)<0)];if(v.some(T=>T.length<2))return;let y=v.map(T=>x2([1,0],yn(T))).map(T=>T[0]*d[0]+T[1]*d[1]<0?[-T[0],-T[1]]:T),b=[y[0][0]+y[1][0],y[0][1]+y[1][1]],x=Math.hypot(b[0],b[1]);if(d=[b[0]/x,b[1]/x],p=i.filter(T=>m(T)>h.r+e&&m(T)<f-h.r),p.length<4||Math.abs(p.reduce((T,B)=>T+g(B),0)/p.length)>e)return;let M=p.map(T=>Math.abs(g(T))).sort((T,B)=>T-B),w=M[Math.floor(M.length/2)]*2;if(w>=h.r*2-e||w<.3)return;let k=Math.max(...i.map(m)),z=O6(h.c,[d[0]*(k-w/2),d[1]*(k-w/2)]),S=i1([V3(h.r,h.r,256).map(T=>O6(T,h.c)),No(h.c,z,w/2)]);if(!w3([t.poly],S,e))return;let A=k-w/2,L=h.r*2,C=Math.atan2(d[1],d[0])*180/Math.PI-90,P=[];H1(L)!==9&&P.push(`head = ${P1(L)}`),H1(w)!==4.5&&P.push(`shank = ${P1(w)}`),H1(A)!==10&&P.push(`drop = ${P1(A)}`);let R=A>=(L+w)/2-1e-9,q=R?`keyhole(${P.join(", ")})`:`{ translate(${s0([0,-A])}) circle(d = ${P1(L)}); hull() { circle(d = ${P1(w)}); translate(${s0([0,-A])}) circle(d = ${P1(w)}); } }`;return{kind:"keyhole",radius:L/2,body:q,at:z,angle:C,center:z,label:"keyhole",keyhole:{head:L,shank:w,drop:A,top:z},library:R?"hanging":void 0}}var fn=.0025,W4=(t,e)=>Math.abs(t[0]-e[0])>fn||Math.abs(t[1]-e[1])>fn;function n5(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(a=>a.a);t.closed||n.push(t.segs[t.segs.length-1].b);let r=[n[0]];for(let a of n.slice(1))W4(a,r[r.length-1])&&r.push(a);!t.closed&&r.length<2&&r.push(n[n.length-1]);let c=`[${r.map(a=>s0(M2(a,e))).join(", ")}]`;return t.closed?`polygon(${c})`:r.length===2?`line(${s0(M2(r[0],e))}, ${s0(M2(r[1],e))})`:`polyline(${c})`}return`path("${$6([t],e)}")`}function $6(t,e){let n=r=>`${P1(r[0]-e[0])} ${P1(r[1]-e[1])}`;return t.map(r=>{let c=`M${n(r.segs[0].a)}`,a=r.segs[0].a;for(let s of r.segs)!W4(s.b,a)&&(s.c==="L"||!W4(s.p1,a)&&!W4(s.p2,a))||(c+=s.c==="L"?`L${n(s.b)}`:`C${n(s.p1)} ${n(s.p2)} ${n(s.b)}`,a=s.b);return r.closed?c+"Z":c}).join("")}var D0=.01;function Mn(t){return{closed:t.closed,segs:t.segs.slice().reverse().map(e=>e.c==="L"?{c:"L",a:e.b,b:e.a}:{c:"C",a:e.b,p1:e.p2,p2:e.p1,b:e.a})}}var r5=t=>t.segs[0].a,wn=t=>t.segs[t.segs.length-1].b;function Uo(t){let e=new Set,n=[],r=s=>`${Math.round(s[0]/D0)},${Math.round(s[1]/D0)}`,c=new Map;t.forEach((s,i)=>{for(let o of[r5(s),wn(s)]){let l=r(o);c.set(l,[...c.get(l)??[],i])}});let a=s=>{let[i,o]=[Math.round(s[0]/D0),Math.round(s[1]/D0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of c.get(`${i+l},${o+h}`)??[])if(!e.has(u)&&(N1(r5(t[u]),s)<=D0||N1(wn(t[u]),s)<=D0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let i=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=i[i.length-1].b;if(N1(h,i[0].a)<=D0&&i.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=N1(r5(t[u]),h)<=D0?t[u]:Mn(t[u]);i=i.concat(f.segs)}i=Mn({segs:i,closed:!1}).segs}let o=i.length>1&&N1(i[i.length-1].b,i[0].a)<=D0;n.push({sub:{segs:i,closed:o},from:t[s]})}return n}var zn=.05;function Bo(t){let e=t instanceof Uint8Array?t:new Uint8Array(t),n=e[0]===255&&e[1]===254||e[0]===60&&e[1]===0?"utf-16le":e[0]===254&&e[1]===255||e[0]===0&&e[1]===60?"utf-16be":"utf-8";return new TextDecoder(n).decode(e)}function Sn(t,e={}){let n=e.tolerance??zn,r=typeof t=="string"?t:Bo(t),c=un(r,{dpi:e.dpi}),a=[...c.notes],s={},i=(E,D=1)=>s[E]=(s[E]??0)+D,o=[],l=[],h=new Map;for(let E of c.items)if(E.layer.mode==="cut")for(let D of E.subs)D.closed?o.push({sub:D,names:E.names,group:E.filled?E:void 0}):(l.push(D),h.set(D,E.names));let u=Uo(l);l=[];for(let{sub:E,from:D}of u)E.closed?o.push({sub:E,names:h.get(D)??[],line:{segs:E.segs,closed:!1}}):l.push(E);let f=o.map(E=>({...E,outline:_5(M3(E.sub),E.sub)})),d=f.filter(E=>E.outline.poly.length>=3&&E.outline.area>I2(E.outline.poly)*D0);for(let E of f)d.includes(E)||l.push(E.line??{segs:E.sub.segs,closed:!1});let m=(E,D,e1,u1)=>{if(e1!==u1)return!1;let[t1,V,n1,G]=E.box,[k1,r1,U1,c1]=D.box;if(t1<k1-D0||V<r1-D0||n1>U1+D0||G>c1+D0)return!1;let V1=E.poly.length;return[0,Math.floor(V1/3),Math.floor(2*V1/3)].filter(d0=>B2(E.poly[d0],D.poly)).length>=2},g=E=>{let D=d.map((t1,V)=>V).filter(t1=>!E.has(t1)).sort((t1,V)=>d[V].outline.area-d[t1].outline.area),e1=new Map,u1=new Map;return D.forEach((t1,V)=>{let n1=-1;for(let G=V-1;G>=0;G--){let k1=D[G];if(d[k1].outline.area>d[t1].outline.area&&m(d[t1].outline,d[k1].outline,d[t1].group,d[k1].group)){n1=k1;break}}e1.set(t1,n1),u1.set(t1,n1<0?0:u1.get(n1)+1)}),{order:D,parent:e1,depth:u1}},p=mn(d.map(E=>E.outline.poly),D0*2),v=g(new Set),{parent:y,depth:b}=v,x=E=>b.get(E)%2===0?E:y.get(E),M=new Set(d.map((E,D)=>D).filter(E=>p.self[E]));for(let[E,D]of p.pairs)x(E)===x(D)&&M.add(E).add(D);for(let E of v.order)b.get(E)%2===1&&M.has(y.get(E))&&M.add(E);for(let E of M)l.push(d[E].line??{segs:d[E].sub.segs,closed:!1});M.size&&a.push(`${M.size} outline${M.size===1?" touches or crosses":"s touch or cross"} a hole or ${M.size===1?"itself":"themselves"}, so ${M.size===1?"it is":"they are"} kept as cut lines.`);let w=[],k=new Map;for(let E of v.order){if(M.has(E))continue;let D=d[E];if(b.get(E)%2===0){let e1={sub:D.sub,outline:D.outline,names:D.names,holes:[],lines:[],marks:new Map,texts:[]};w.push(e1),k.set(E,e1)}else k.get(y.get(E)).holes.push({sub:D.sub,outline:D.outline,line:D.line})}let z=e.kerf!==void 0?e.kerf/2:vn(w.map(E=>E.outline.poly)),S=0;if(z&&z>0){let E=D=>({closed:!0,segs:D.map((e1,u1)=>({c:"L",a:e1,b:D[(u1+1)%D.length]}))});for(let D of w){let e1=k0([F6(D.outline.poly,z)],D.holes.map(c1=>F6(c1.outline.poly,z))),u1=F0(n0(e1,-z,"miter")),t1=n0(u1.flat(),z,"round",Math.min(.01,z/10)),V=k0([D.outline.poly],D.holes.map(c1=>c1.outline.poly)),n1=c1=>Math.abs(M1(c1))<=I2(c1)*D0;if(u1.length!==1||u1[0].length!==D.holes.length+1||u1[0].some(n1)||!w3(t1,V,n)){D.noKerf=!0;continue}D.drawn=[D.sub,...D.holes.map(c1=>c1.sub)];let[G,...k1]=u1[0].map(c1=>t5(c1,.001));D.outline=_5(G),D.sub=E(G);let r1=c1=>[(c1.box[0]+c1.box[2])/2,(c1.box[1]+c1.box[3])/2],U1=k1.map(c1=>_5(c1));for(let c1 of D.holes){let V1=r1(c1.outline),o0=U1.reduce((d0,I)=>N1(r1(I),V1)<N1(r1(d0),V1)?I:d0);U1.splice(U1.indexOf(o0),1),c1.outline=o0,c1.sub=E(o0.poly),c1.line=void 0}}S=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${P1(S)} mm kerf: they are moved back, and $kerf is set.`)}let A=E=>{let D;for(let e1 of w){let[u1,t1,V,n1]=e1.outline.box;E[0]<u1||E[0]>V||E[1]<t1||E[1]>n1||B2(E,e1.outline.poly)&&(!D||e1.outline.area<D.outline.area)&&(D=e1)}return D},L={lines:[],marks:new Map,texts:[]},C=new Map,P=E=>{let D=A(r5(E));if(!D)return;let e1=C.get(D);return e1||(e1=pn(D.outline.poly,D.holes.map(u1=>u1.outline.poly),n),C.set(D,e1)),e1(M3(E,.02),E.closed)?D:void 0};for(let E of l){let D=P(E);(D?D.lines:L.lines).push(E)}for(let E of c.items)if(E.layer.mode!=="cut")for(let D of E.subs){let e1=(P(D)??L).marks;e1.set(E,[...e1.get(E)??[],D])}for(let E of c.texts)(A(E.at)??L).texts.push(E);c.texts.some(E=>E.layer.mode==="cut")&&a.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let E of w){let D=E.lines.map(e1=>M3(e1));E.holes=E.holes.filter(e1=>{if(!e1.line)return!0;let u1=V=>B2(V,e1.outline.poly),t1=gn(D,e1.outline.poly,D0*2)||E.lines.some(V=>u1(r5(V)))||[...E.marks.values()].some(V=>V.some(n1=>u1(r5(n1))))||E.texts.some(V=>u1(V.at))||w.some(V=>V!==E&&V.outline.area<e1.outline.area&&u1(V.outline.poly[0]));return t1&&E.lines.push(e1.line),!t1})}let R=E=>Y4(E,n)??K4(E,n)??J4(E,n)??Q4(E,n)??xn(E,n),q=new Map;for(let E of w){let D=Y4(E.outline,n)??K4(E.outline,n)??J4(E.outline,n)??Q4(E.outline,n)??R6(E.outline,n);q.set(E,D);for(let e1 of E.holes)e1.found=R(e1.outline)}let T=new Map,B=[...q.values()].some(E=>E?.thickness&&!E.generic);for(let E of q.values())E?.thickness&&E.thickness<=10&&(!B||!E.generic)&&T.set(E.thickness,(T.get(E.thickness)??0)+1);let X=[...T.entries()].sort((E,D)=>D[1]-E[1])[0]?.[0];if(X!==void 0)for(let E of w){let D=q.get(E);if(D?.thickness!==void 0&&D.thickness!==X){let e1=R6(E.outline,n,X);e1&&e1.thickness===X&&q.set(E,e1)}}let Z=new Set;for(let E of q.values())E?.kind==="fingers"&&E.finger&&Z.add(H1(E.finger));w.sort((E,D)=>{let e1=D.outline.box[3]-E.outline.box[3];return Math.abs(e1)>1?e1:E.outline.box[0]-D.outline.box[0]});let h1=new Set,H=new Map,U=[];for(let[E,D]of w.entries()){let e1=D.names[0]??`part ${E+1}`,u1=(H.get(e1)??0)+1;H.set(e1,u1);let t1=u1>1?`${e1} ${u1}`:e1,V;for(let o0 of[2,1,0]){let d0=jo(D,q.get(D),o0,X,Z,n);if(Xo(d0,D,n)){V=d0,o0<2&&a.push(o0===1?`Part "${t1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${t1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!V){let o0=D.drawn??[D.sub,...D.holes.map(d0=>d0.sub)];L.lines.push(...o0.map(d0=>({segs:d0.segs,closed:!1})),...D.lines);for(let[d0,I]of D.marks)L.marks.set(d0,[...L.marks.get(d0)??[],...I]);L.texts.push(...D.texts),a.push(`Part "${t1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let o0 of V.found)i(o0);for(let o0 of V.libraries)h1.add(o0);let n1=kn(D.marks,[],D.texts,V.origin),G=[...V.cut,...n1],k1=V.thickness,r1=[...k1!==void 0&&(X===void 0||H1(k1)!==H1(X))?[`thickness = ${P1(k1)}`]:[],...D.noKerf&&S>0?["kerf = 0"]:[]],U1=r1.length?`material(${r1.join(", ")}) `:"",c1=`part("${t1.replace(/["\\]/g,"")}")`,V1=G.length===1&&!G[0].includes(`
|
|
2699
|
-
`)?`${
|
|
2700
|
-
${
|
|
3079
|
+
}`:F,_=d.map(H=>$1(g[H])),Q=_.sort((H,B)=>_.filter(Y=>Y===B).length-_.filter(Y=>Y===H).length)[0];return u([b,y],j,{kind:P.length?"fingers":"tabs",thickness:Q,generic:!0,label:`${P.length?"finger joints":"tabs"} ${I1(Q)} mm deep`})}function Cl(t){let[e,n,r,c]=w0([t]),a=h=>{let u=1/0;for(let f=0,d=t.length-1;f<t.length;d=f++)u=Math.min(u,i3(h,t[d],t[f]));return u},s=[(e+r)/2,(n+c)/2],o=j2(s,t)?a(s):0,i=24;for(let h=0;h<=i;h++)for(let u=0;u<=i;u++){let f=[e+(r-e)*h/i,n+(c-n)*u/i];if(!j2(f,t))continue;let d=a(f);d>o&&(s=f,o=d)}let l=Math.max(r-e,c-n)/i;for(;l>1e-4;){let h=!1;for(let[u,f]of[[1,0],[-1,0],[0,1],[0,-1]]){let d=[s[0]+u*l,s[1]+f*l];if(!j2(d,t))continue;let p=a(d);p>o&&(s=d,o=p,h=!0)}h||(l/=2)}return{c:s,r:o}}function Pl(t,e,n){let c=Math.atan2(e[1]-t[1],e[0]-t[0]),a=[];for(let s=0;s<=64;s++){let o=c+Math.PI/2+Math.PI*s/64;a.push([t[0]+n*Math.cos(o),t[1]+n*Math.sin(o)])}for(let s=0;s<=64;s++){let o=c-Math.PI/2+Math.PI*s/64;a.push([e[0]+n*Math.cos(o),e[1]+n*Math.sin(o)])}return a}function Y8(t,e){let[n,r,c,a]=t.box;if(Math.max(c-n,a-r)>80)return;let s=V2(t.poly),o=G2(t.poly,!0,Math.min(.25,s/400)),i=Cl(t.poly),l=o.filter(P=>Math.abs(N1(P,i.c)-i.r)<=e),h=a4(l);if(!h||l.length<8)return;let u=o[0];for(let P of o)N1(P,h.c)>N1(u,h.c)&&(u=P);let f=N1(u,h.c),d=[(u[0]-h.c[0])/f,(u[1]-h.c[1])/f],p=P=>(P[0]-h.c[0])*d[0]+(P[1]-h.c[1])*d[1],m=P=>-(P[0]-h.c[0])*d[1]+(P[1]-h.c[1])*d[0],g=o.filter(P=>p(P)>h.r+e&&p(P)<f-h.r);if(g.length<4)return;let v=[g.filter(P=>m(P)>0),g.filter(P=>m(P)<0)];if(v.some(P=>P.length<2))return;let b=v.map(P=>M2([1,0],X8(P))).map(P=>P[0]*d[0]+P[1]*d[1]<0?[-P[0],-P[1]]:P),y=[b[0][0]+b[1][0],b[0][1]+b[1][1]],x=Math.hypot(y[0],y[1]);if(d=[y[0]/x,y[1]/x],g=o.filter(P=>p(P)>h.r+e&&p(P)<f-h.r),g.length<4||Math.abs(g.reduce((P,F)=>P+m(F),0)/g.length)>e)return;let w=g.map(P=>Math.abs(m(P))).sort((P,F)=>P-F),M=w[Math.floor(w.length/2)]*2;if(M>=h.r*2-e||M<.3)return;let k=Math.max(...o.map(p)),z=Jt(h.c,[d[0]*(k-M/2),d[1]*(k-M/2)]),A=s1([q3(h.r,h.r,256).map(P=>Jt(P,h.c)),Pl(h.c,z,M/2)]);if(!P3([t.poly],A,e))return;let S=k-M/2,C=h.r*2,I=Math.atan2(d[1],d[0])*180/Math.PI-90,L=[];$1(C)!==9&&L.push(`head = ${I1(C)}`),$1(M)!==4.5&&L.push(`shank = ${I1(M)}`),$1(S)!==10&&L.push(`drop = ${I1(S)}`);let T=S>=(C+M)/2-1e-9,q=T?`keyhole(${L.join(", ")})`:`{ translate(${s0([0,-S])}) circle(d = ${I1(C)}); hull() { circle(d = ${I1(M)}); translate(${s0([0,-S])}) circle(d = ${I1(M)}); } }`;return{kind:"keyhole",radius:C/2,body:q,at:z,angle:I,center:z,label:"keyhole",keyhole:{head:C,shank:M,drop:S,top:z},library:T?"hanging":void 0}}var U8=.0025,r4=(t,e)=>Math.abs(t[0]-e[0])>U8||Math.abs(t[1]-e[1])>U8;function l5(t,e){if(t.segs.every(n=>n.c==="L")&&t.segs.length<400){let n=t.segs.map(a=>a.a);t.closed||n.push(t.segs[t.segs.length-1].b);let r=[n[0]];for(let a of n.slice(1))r4(a,r[r.length-1])&&r.push(a);!t.closed&&r.length<2&&r.push(n[n.length-1]);let c=`[${r.map(a=>s0(w2(a,e))).join(", ")}]`;return t.closed?`polygon(${c})`:r.length===2?`line(${s0(w2(r[0],e))}, ${s0(w2(r[1],e))})`:`polyline(${c})`}return`path("${e6([t],e)}")`}function e6(t,e){let n=r=>`${I1(r[0]-e[0])} ${I1(r[1]-e[1])}`;return t.map(r=>{let c=`M${n(r.segs[0].a)}`,a=r.segs[0].a;for(let s of r.segs)!r4(s.b,a)&&(s.c==="L"||!r4(s.p1,a)&&!r4(s.p2,a))||(c+=s.c==="L"?`L${n(s.b)}`:`C${n(s.p1)} ${n(s.p2)} ${n(s.b)}`,a=s.b);return r.closed?c+"Z":c}).join("")}var N0=.01;function J8(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 h5=t=>t.segs[0].a,K8=t=>t.segs[t.segs.length-1].b;function El(t){let e=new Set,n=[],r=s=>`${Math.round(s[0]/N0)},${Math.round(s[1]/N0)}`,c=new Map;t.forEach((s,o)=>{for(let i of[h5(s),K8(s)]){let l=r(i);c.set(l,[...c.get(l)??[],o])}});let a=s=>{let[o,i]=[Math.round(s[0]/N0),Math.round(s[1]/N0)];for(let l=-1;l<=1;l++)for(let h=-1;h<=1;h++)for(let u of c.get(`${o+l},${i+h}`)??[])if(!e.has(u)&&(N1(h5(t[u]),s)<=N0||N1(K8(t[u]),s)<=N0))return u};for(let s=0;s<t.length;s++){if(e.has(s))continue;e.add(s);let o=t[s].segs.slice();for(let l=0;l<2;l++){for(;;){let h=o[o.length-1].b;if(N1(h,o[0].a)<=N0&&o.length>1)break;let u=a(h);if(u===void 0)break;e.add(u);let f=N1(h5(t[u]),h)<=N0?t[u]:J8(t[u]);o=o.concat(f.segs)}o=J8({segs:o,closed:!1}).segs}let i=o.length>1&&N1(o[o.length-1].b,o[0].a)<=N0;n.push({sub:{segs:o,closed:i},from:t[s]})}return n}var e9=.05;function Tl(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 t9(t,e={}){let n=e.tolerance??e9,r=typeof t=="string"?t:Tl(t),c=N8(r,{dpi:e.dpi}),a=[...c.notes],s={},o=(V,U=1)=>s[V]=(s[V]??0)+U,i=[],l=[],h=new Map;for(let V of c.items)if(V.layer.mode==="cut")for(let U of V.subs)U.closed?i.push({sub:U,names:V.names,group:V.filled?V:void 0}):(l.push(U),h.set(U,V.names));let u=El(l);l=[];for(let{sub:V,from:U}of u)V.closed?i.push({sub:V,names:h.get(U)??[],line:{segs:V.segs,closed:!1}}):l.push(V);let f=i.map(V=>({...V,outline:K5(C3(V.sub),V.sub)})),d=f.filter(V=>V.outline.poly.length>=3&&V.outline.area>V2(V.outline.poly)*N0);for(let V of f)d.includes(V)||l.push(V.line??{segs:V.sub.segs,closed:!1});let p=(V,U,r1,h1)=>{if(r1!==h1)return!1;let[a1,x1,J1,q1]=V.box,[f0,m0,D,J]=U.box;if(a1<f0-N0||x1<m0-N0||J1>D+N0||q1>J+N0)return!1;let t1=V.poly.length;return[0,Math.floor(t1/3),Math.floor(2*t1/3)].filter(n1=>j2(V.poly[n1],U.poly)).length>=2},m=V=>{let U=d.map((a1,x1)=>x1).filter(a1=>!V.has(a1)).sort((a1,x1)=>d[x1].outline.area-d[a1].outline.area),r1=new Map,h1=new Map;return U.forEach((a1,x1)=>{let J1=-1;for(let q1=x1-1;q1>=0;q1--){let f0=U[q1];if(d[f0].outline.area>d[a1].outline.area&&p(d[a1].outline,d[f0].outline,d[a1].group,d[f0].group)){J1=f0;break}}r1.set(a1,J1),h1.set(a1,J1<0?0:h1.get(J1)+1)}),{order:U,parent:r1,depth:h1}},g=_8(d.map(V=>V.outline.poly),N0*2),v=m(new Set),{parent:b,depth:y}=v,x=V=>y.get(V)%2===0?V:b.get(V),w=new Set(d.map((V,U)=>U).filter(V=>g.self[V]));for(let[V,U]of g.pairs)x(V)===x(U)&&w.add(V).add(U);for(let V of v.order)y.get(V)%2===1&&w.has(b.get(V))&&w.add(V);for(let V of w)l.push(d[V].line??{segs:d[V].sub.segs,closed:!1});w.size&&a.push(`${w.size} outline${w.size===1?" touches or crosses":"s touch or cross"} a hole or ${w.size===1?"itself":"themselves"}, so ${w.size===1?"it is":"they are"} kept as cut lines.`);let M=[],k=new Map;for(let V of v.order){if(w.has(V))continue;let U=d[V];if(y.get(V)%2===0){let r1={sub:U.sub,outline:U.outline,names:U.names,holes:[],lines:[],marks:new Map,texts:[]};M.push(r1),k.set(V,r1)}else k.get(b.get(V)).holes.push({sub:U.sub,outline:U.outline,line:U.line})}let z=e.kerf!==void 0?e.kerf/2:W8(M.map(V=>V.outline.poly)),A=0;if(z&&z>0){let V=U=>({closed:!0,segs:U.map((r1,h1)=>({c:"L",a:r1,b:U[(h1+1)%U.length]}))});for(let U of M){let r1=g0([Kt(U.outline.poly,z)],U.holes.map(J=>Kt(J.outline.poly,z))),h1=R0(c0(r1,-z,"miter")),a1=c0(h1.flat(),z,"round",Math.min(.01,z/10)),x1=g0([U.outline.poly],U.holes.map(J=>J.outline.poly)),J1=J=>Math.abs(b1(J))<=V2(J)*N0;if(h1.length!==1||h1[0].length!==U.holes.length+1||h1[0].some(J1)||!P3(a1,x1,n)){U.noKerf=!0;continue}U.drawn=[U.sub,...U.holes.map(J=>J.sub)];let[q1,...f0]=h1[0].map(J=>i5(J,.001));U.outline=K5(q1),U.sub=V(q1);let m0=J=>[(J.box[0]+J.box[2])/2,(J.box[1]+J.box[3])/2],D=f0.map(J=>K5(J));for(let J of U.holes){let t1=m0(J.outline),w1=D.reduce((n1,E)=>N1(m0(E),t1)<N1(m0(n1),t1)?E:n1);D.splice(D.indexOf(w1),1),J.outline=w1,J.sub=V(w1.poly),J.line=void 0}}A=z*2,e.kerf===void 0&&a.push(`The cut outlines are offset for a ${I1(A)} mm kerf: they are moved back, and $kerf is set.`)}let S=V=>{let U;for(let r1 of M){let[h1,a1,x1,J1]=r1.outline.box;V[0]<h1||V[0]>x1||V[1]<a1||V[1]>J1||j2(V,r1.outline.poly)&&(!U||r1.outline.area<U.outline.area)&&(U=r1)}return U},C={lines:[],marks:new Map,texts:[]},I=new Map,L=V=>{let U=S(h5(V));if(!U)return;let r1=I.get(U);return r1||(r1=j8(U.outline.poly,U.holes.map(h1=>h1.outline.poly),n),I.set(U,r1)),r1(C3(V,.02),V.closed)?U:void 0};for(let V of l){let U=L(V);(U?U.lines:C.lines).push(V)}for(let V of c.items)if(V.layer.mode!=="cut")for(let U of V.subs){let r1=(L(U)??C).marks;r1.set(V,[...r1.get(V)??[],U])}for(let V of c.texts)(S(V.at)??C).texts.push(V);c.texts.some(V=>V.layer.mode==="cut")&&a.push("Text to cut is written with the built-in font, so its letters are not the drawing's: convert the text to paths in your editor to cut it as drawn.");for(let V of M){let U=V.lines.map(r1=>C3(r1));V.holes=V.holes.filter(r1=>{if(!r1.line)return!0;let h1=x1=>j2(x1,r1.outline.poly),a1=G8(U,r1.outline.poly,N0*2)||V.lines.some(x1=>h1(h5(x1)))||[...V.marks.values()].some(x1=>x1.some(J1=>h1(h5(J1))))||V.texts.some(x1=>h1(x1.at))||M.some(x1=>x1!==V&&x1.outline.area<r1.outline.area&&h1(x1.outline.poly[0]));return a1&&V.lines.push(r1.line),!a1})}let T=V=>s4(V,n)??i4(V,n)??o4(V,n)??l4(V,n)??Y8(V,n),q=new Map;for(let V of M){let U=s4(V.outline,n)??i4(V.outline,n)??o4(V.outline,n)??l4(V.outline,n)??Qt(V.outline,n);q.set(V,U);for(let r1 of V.holes)r1.found=T(r1.outline)}let P=new Map,F=[...q.values()].some(V=>V?.thickness&&!V.generic);for(let V of q.values())V?.thickness&&V.thickness<=10&&(!F||!V.generic)&&P.set(V.thickness,(P.get(V.thickness)??0)+1);let j=[...P.entries()].sort((V,U)=>U[1]-V[1])[0]?.[0];if(j!==void 0)for(let V of M){let U=q.get(V);if(U?.thickness!==void 0&&U.thickness!==j){let r1=Qt(V.outline,n,j);r1&&r1.thickness===j&&q.set(V,r1)}}let _=new Set;for(let V of q.values())V?.kind==="fingers"&&V.finger&&_.add($1(V.finger));M.sort((V,U)=>{let r1=U.outline.box[3]-V.outline.box[3];return Math.abs(r1)>1?r1:V.outline.box[0]-U.outline.box[0]});let Q=new Set,H=new Map,B=[];for(let[V,U]of M.entries()){let r1=U.names[0]??`part ${V+1}`,h1=(H.get(r1)??0)+1;H.set(r1,h1);let a1=h1>1?`${r1} ${h1}`:r1,x1;for(let w1 of[2,1,0]){let n1=Vl(U,q.get(U),w1,j,_,n);if($l(n1,U,n)){x1=n1,w1<2&&a.push(w1===1?`Part "${a1}": its holes are written one by one; grouping them did not match the drawing.`:`Part "${a1}" is written as drawn: no recognised shape matched it closely enough.`);break}}if(!x1){let w1=U.drawn??[U.sub,...U.holes.map(n1=>n1.sub)];C.lines.push(...w1.map(n1=>({segs:n1.segs,closed:!1})),...U.lines);for(let[n1,E]of U.marks)C.marks.set(n1,[...C.marks.get(n1)??[],...E]);C.texts.push(...U.texts),a.push(`Part "${a1}" is cut as lines: no shape reproduces its outline exactly.`);continue}for(let w1 of x1.found)o(w1);for(let w1 of x1.libraries)Q.add(w1);let J1=Q8(U.marks,[],U.texts,x1.origin),q1=[...x1.cut,...J1],f0=x1.thickness,m0=[...f0!==void 0&&(j===void 0||$1(f0)!==$1(j))?[`thickness = ${I1(f0)}`]:[],...U.noKerf&&A>0?["kerf = 0"]:[]],D=m0.length?`material(${m0.join(", ")}) `:"",J=`part("${a1.replace(/["\\]/g,"")}")`,t1=q1.length===1&&!q1[0].includes(`
|
|
3080
|
+
`)?`${D}${J} ${q1[0]}`:`${D}${J} {
|
|
3081
|
+
${q1.join(`
|
|
2701
3082
|
`)}
|
|
2702
|
-
}`;
|
|
2703
|
-
`),
|
|
2704
|
-
`),
|
|
3083
|
+
}`;B.push({name:a1,code:H2(x1.origin,0,t1),local:t1,thickness:f0})}let Y=Q8(C.marks,C.lines,C.texts,[0,0]);Y.length&&M.length&&a.push("Some lines or marks are outside every part; they are kept on their own.");let e1;if(e.pack){let V=new Map;for(let r1 of B){let h1=r1.local.replace(/part\("[^"]*"\)/,"part()"),a1=V.get(h1);a1?a1.qty++:V.set(h1,{name:r1.name,qty:1})}e1=[...V.entries()].map(([r1,h1])=>r1.replace("part()",`part("${h1.name.replace(/["\\]/g,"")}"${h1.qty>1?`, qty = ${h1.qty}`:""})`));let U=B.length-V.size;U&&a.push(`${U} part${U===1?" is":"s are"} the same as another and became a quantity.`)}else e1=B.map(V=>V.code);let X=Object.entries(s).filter(([V])=>V!=="outline").map(([V,U])=>`${U} ${V}${U===1?"":Il[V]??"s"}`).join(", "),M1=`${B.length} part${B.length===1?"":"s"}${X?`; found ${X}`:""}.`,v1=[`// ${e.name?e.name+": ":""}imported from an SVG drawing.`,`// ${M1}`,...a.map(V=>`// ${V}`),"",...[...Q].sort().map(V=>`use <kerf/${V}>`),...Q.size?[""]:[]],p1=[];j!==void 0&&p1.push(`$thickness = ${I1(j)}; // from the joints`),A>0&&p1.push(`$kerf = ${I1(A)}; // the drawing's outlines were offset by half of this`),!e.pack&&B.length&&p1.push('$layout = "none"; // keep the parts where the drawing has them');let F1=[v1.join(`
|
|
3084
|
+
`),p1.join(`
|
|
3085
|
+
`),e1.join(`
|
|
2705
3086
|
|
|
2706
3087
|
`),Y.join(`
|
|
2707
3088
|
`)].filter(Boolean).join(`
|
|
@@ -2709,22 +3090,28 @@ ${G.join(`
|
|
|
2709
3090
|
`).replace(/\n{3,}/g,`
|
|
2710
3091
|
|
|
2711
3092
|
`)+`
|
|
2712
|
-
`;try{
|
|
2713
|
-
${[x,...d].map(
|
|
3093
|
+
`;try{F1=e4(F1)}catch{}return{source:F1,parts:B.length,found:s,summary:M1,notes:a}}var Il={"finger jointed panel":"s","hanger hole":"s","slot row":"s","hanging loop":"s","hole pattern":"s"},Q5=t=>t.trimEnd().endsWith("}")?t:t+";";function Vl(t,e,n,r,c,a){let s=[],o=new Set,i=n>0?e:void 0,l=t.outline.box,h,u;if(i?.kind==="rect"){let{w:S,h:C,r:I}=i.rect;h=w2(i.center,M2([S/2,C/2],i.angle)),h=[$1(h[0]),$1(h[1])],u=H2([0,0],i.angle,`rect(${s0([S,C])}${$1(I)>0?`, r = ${I1(I)}`:""})`),s.push("rectangle")}else i?(h=[$1(i.at[0]),$1(i.at[1])],u=H2(w2(i.at,h),i.angle,i.body),s.push(t6[i.kind]),i.library&&o.add(i.library)):(h=[$1(l[0]),$1(l[1])],u=l5(t.sub,h),s.push("outline"));let f=t.holes.map(S=>({...S,found:n>0?S.found:void 0})),d=[],p=S=>w2(S,h),m=S=>S,g=0,v=new Set(f);if(n===2&&!i)for(let S of f){let C=S.found?.circle;if(!C||C.r*2>15)continue;let I=G2(t.outline.poly,!0,.25),L=Math.min(...I.map(F=>N1(F,C.c))),T=L-C.r;if(T<.5||I.filter(F=>Math.abs(N1(F,C.c)-L)<=a).length*.25<L*Math.PI*.8)continue;let P=[s0(p(C.c))];$1(C.r*2)!==4&&P.push(`d = ${I1(C.r*2)}`),$1(T)!==3&&P.push(`wall = ${I1(T)}`),m=F=>`hanging_loop(${P.join(", ")}) ${F}`,g=L,o.add("hanging"),s.push("hanging loop"),v.delete(S);break}if(n===2){let[S,C,I,L]=l,T=(S+I)/2,q=I-S,P=L-C,F=B=>B[1]>=C+P*.66,j=B=>[...v].filter(Y=>Y.found?.circle&&$1(Y.found.circle.r)===$1(B.found.circle.r)).length,_=[...v].filter(B=>B.found?.circle&&B.found.circle.r*2>=1.5&&B.found.circle.r*2<=15&&F(B.found.circle.c)&&j(B)<=2),Q=!1;for(let B of _){let Y=B.found.circle;if(Math.abs(Y.c[0]-T)>Math.max(.5,q*.02))continue;let e1=Y.r*2;d.push(`hanging_hole(${s0(p(Y.c))}${$1(e1)!==5?`, d = ${I1(e1)}`:""})`),v.delete(B),Q=!0;break}if(!Q)for(let B of _)for(let Y of _){if(Q||B===Y)continue;let[e1,X]=[B.found.circle,Y.found.circle];if(Math.abs(e1.r-X.r)>a||Math.abs(e1.c[1]-X.c[1])>a||e1.c[0]>=X.c[0])continue;let M1=[(e1.c[0]+X.c[0])/2,e1.c[1]];if(Math.abs(M1[0]-T)>Math.max(1,q*.02))continue;let v1=e1.r*2;d.push(`hanging_hole(${s0(p(M1))}${$1(v1)!==5?`, d = ${I1(v1)}`:""}, spacing = ${I1(X.c[0]-e1.c[0])})`),v.delete(B),v.delete(Y),Q=!0}Q&&(o.add("hanging"),s.push("hanger hole"));let H=[...v].filter(B=>B.found?.kind==="keyhole"&&B.found.library&&Math.abs(B.found.angle)<.01);for(let B of H)for(let Y of H){if(!v.has(B)||!v.has(Y)||B===Y)continue;let[e1,X]=[B.found,Y.found];if(e1.body!==X.body||Math.abs(e1.at[1]-X.at[1])>a||e1.at[0]>=X.at[0])continue;let M1=[I1(X.at[0]-e1.at[0])],v1=p([(e1.at[0]+X.at[0])/2,e1.at[1]]),p1=e1.body.slice(8,-1);M1.push($1(v1[0])||$1(v1[1])?`at = ${s0(v1)}`:""),p1&&M1.push(p1),d.push(`keyholes(${M1.filter(Boolean).join(", ")})`),v.delete(B),v.delete(Y),o.add("hanging"),s.push("keyhole","keyhole")}if(r!==void 0){let B=[...v].filter(Y=>Y.found?.kind==="rect"&&$1(Y.found.rect.r)===0);for(let Y of Hl(B,a)){let{items:e1,dir:X,spacing:M1,along:v1,across:p1}=Y,G1=e1.length,F1=r,V=p1-F1,U=w2(e1[0].found.center,[X[0]*M1/2,X[1]*M1/2]),r1=Math.atan2(X[1],X[0])*180/Math.PI,h1=G1*M1;if(Math.abs(V)<=a&&Math.abs(v1-M1/2)<=a&&G1>=2){let a1=2*G1-1,x1=a1*v1,J1=Math.max(3*F1,6),q1=(D,J)=>{let t1=Math.round(D/J);return t1%2===0&&(t1+=D/J>t1?1:-1),Math.max(3,t1)};if(q1(x1,J1)!==a1&&q1(x1,v1)!==a1)continue;let f0=w2(e1[0].found.center,[X[0]*v1/2,X[1]*v1/2]),m0=q1(x1,J1)===a1?"":`, finger = ${I1(v1)}`;d.push(H2(p(f0),r1,`finger_holes(${I1(x1)}${m0})`)),s.push("finger joint slot row")}else if(V>=-a&&V<=1){let a1=[I1(h1)];G1!==Math.max(1,Math.round(h1/50))&&a1.push(`count = ${G1}`);let x1=v1-V;Math.abs(x1-h1/(2*G1))>a&&a1.push(`width = ${I1(x1)}`),Math.abs(V-.1)>.001&&a1.push(`clearance = ${I1(V)}`),d.push(H2(p(U),r1,`slots(${a1.join(", ")})`)),o.add("tabs"),s.push("slot row")}else continue;for(let a1 of e1)v.delete(a1)}}}let b=[...v].filter(S=>S.found),y=[...v].filter(S=>!S.found);if(n===2){let S=new Map;for(let C of b){let I=H2([0,0],C.found.angle,C.found.body);S.set(I,[...S.get(I)??[],C])}for(let[C,I]of S){let L=Ol(I.map(T=>p(T.found.at)),a);if(L){d.push(`${L} ${C}`);for(let T of I)s.push(t6[T.found.kind]),T.found.library&&o.add(T.found.library);s.push("hole pattern");for(let T of I)v.delete(T)}}}for(let S of v)S.found&&(d.push(H2(p(S.found.at),S.found.angle,S.found.body)),s.push(t6[S.found.kind]),S.found.library&&o.add(S.found.library));for(let S of y)d.push(l5(S.sub,h)),s.push("outline");let x=m(u),w=d.length?[`difference() {
|
|
3094
|
+
${[x,...d].map(Q5).join(`
|
|
2714
3095
|
`)}
|
|
2715
|
-
}`]:[
|
|
2716
|
-
${[...M
|
|
3096
|
+
}`]:[Q5(x)],M=t.lines.map(S=>Q5(l5(S,h))),k=e?.thickness??r,z=[...[...o].map(S=>`use <kerf/${S}>`),`$thickness = ${k??3};`,`translate(${s0(h)}) {
|
|
3097
|
+
${[...w,...M].join(`
|
|
2717
3098
|
`)}
|
|
2718
3099
|
}`].join(`
|
|
2719
|
-
`),
|
|
2720
|
-
${
|
|
3100
|
+
`),A=Math.max(0,g,i?.radius??0,...f.map(S=>n>0?S.found?.radius??0:0));return{origin:h,round:A,cut:[...w,...M],check:z,found:s,libraries:o,thickness:i?.thickness}}var t6={circle:"circle",ellipse:"ellipse",rect:"rectangle",polygon:"polygon",star:"star",tabs:"tabbed panel",fingers:"finger jointed panel",keyhole:"keyhole",outline:"outline"};function Hl(t,e){let n=[],r=new Set,c=s=>{let o=s.found.rect;return`${Math.round((s.found.angle%180+180)%180)}|${$1(o.w)}|${$1(o.h)}`},a=new Map;for(let s of t)a.set(c(s),[...a.get(c(s))??[],s]);for(let s of a.values()){if(s.length<2)continue;let{w:o,h:i}=s[0].found.rect,l=s[0].found.angle;for(let[h,u,f]of[[l,o,i],[l+90,i,o]]){let d=M2([1,0],h),p=[-d[1],d[0]],m=s.filter(v=>!r.has(v)),g=new Map;for(let v of m){let b=v.found.center,y=Math.round((b[0]*p[0]+b[1]*p[1])/e),x=[...g.keys()].find(w=>Math.abs(w-y)<=1)??y;g.set(x,[...g.get(x)??[],v])}for(let v of g.values()){let b=x=>x.found.center[0]*d[0]+x.found.center[1]*d[1];v.sort((x,w)=>b(x)-b(w));let y=0;for(;y<v.length-1;){let x=b(v[y+1])-b(v[y]),w=y+1;for(;w+1<v.length&&Math.abs(b(v[w+1])-b(v[w])-x)<=e;)w++;if(w>y&&x>u){let M=v.slice(y,w+1);for(let k of M)r.add(k);n.push({items:M,dir:d,spacing:x,along:u,across:f})}y=w}}}}return n}function Ol(t,e){if(t.length<3)return;let n=h=>{let u=[];for(let m of[...h].sort((g,v)=>g-v))(!u.length||m-u[u.length-1]>e*2)&&u.push(m);if(u.length===1)return;let[f,d]=[$1(u[0]),$1((u[u.length-1]-u[0])/(u.length-1))],p=$1(f+d*(u.length-1));if(!(d<=0||Math.floor((p-f)/d+1e-9)+1!==u.length)&&!u.some((m,g)=>Math.abs(m-(f+g*d))>e))return`[${I1(f)}:${I1(d)}:${I1(p)}]`},r=t.map(h=>h[0]),c=t.map(h=>h[1]),a=h=>new Set(h.map(u=>Math.round(u/(e*2)))).size,s=a(r),o=a(c);if(o===1||s===1){let h=o===1?r:c;if(a(h)!==t.length)return;let u=n(h);return u?o===1?`for (x = ${u}) translate([x, ${I1(c[0])}])`:`for (y = ${u}) translate([${I1(r[0])}, y])`:void 0}if(s*o!==t.length)return;let i=n(r),l=n(c);if(!(!i||!l))return`for (x = ${i}, y = ${l}) translate([x, y])`}function Q8(t,e,n,r){let c=[];for(let o of e)c.push(Q5(l5(o,r)));let a=new Map,s=(o,i,l)=>{let h=o.name,u=a.get(h)??{layer:o,code:[]};u.code.push(Q5(i)+(l?` // ${l}`:"")),a.set(h,u)};for(let[o,i]of t){let l=e9;if(i.length===1&&i[0].closed){let d=K5(C3(i[0]),i[0]),p=d.area>1e-6?s4(d,l)??i4(d,l)??o4(d,l)??l4(d,l):void 0;if(p){s(o.layer,H2(w2(p.at,r),p.angle,p.body));continue}}if(o.layer.mode!=="fill"||i.every(d=>!d.closed)){for(let d of i)s(o.layer,l5(d,r));continue}let h=e6(i,r),u=i.filter(d=>d.closed).map(d=>C3(d)),f=o.fillRule==="evenodd"||P3(s1(u,"nonzero"),s1(u,"evenodd"),.01);s(o.layer,`path("${h}"${f?"":', fill = "nonzero"'})`)}for(let o of n){let i=[JSON.stringify(o.text),`size = ${I1(o.size)}`];o.anchor!=="left"&&i.push(`halign = "${o.anchor}"`),s(o.layer,H2(w2(o.at,r),o.angle,`text(${i.join(", ")})`),o.font?`${o.font} in the drawing`:void 0)}for(let{layer:o,code:i}of a.values()){let l=["cut","score","engrave","guide"].includes(o.name)?`${o.name}()`:`layer("${o.name}", mode = "${o.mode}", color = "${o.color}")`;c.push(i.length===1&&!i[0].includes("//")?`${l} ${i[0]}`:`${l} {
|
|
3101
|
+
${i.join(`
|
|
2721
3102
|
`)}
|
|
2722
|
-
}`)}return c}function Xo(t,e,n){let r;try{r=new Y3({maxSteps:2e6}).run(l2(t.check).program).shape}catch{return!1}let c=r.layers.get("cut");if(!c)return!1;let a=k0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=i1(c.regions),i=n+t.round*16e-5;if(!w3(a,s,i))return!1;let o=e.lines.map(l=>M3(l));return!(o.length&&!w3(o,c.lines,i,!1))}var j=.001,K1=(t,e)=>t.reduce((n,r,c)=>n+r*e[c],0),b1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],S1=t=>Math.hypot(...t),Cn=t=>[t[2],t[6],t[10]],f0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]+t[n*4+3]),q6=(t,e)=>q1(p0(t.matrix),e.matrix);function k3(t){let[e,n]=t[0],r=0;for(let c=1;c<t.length-1;c++)r+=(t[c][0]-e)*(t[c+1][1]-n)-(t[c][1]-n)*(t[c+1][0]-e);return r/2}var c3=t=>Math.abs(t.reduce((e,n)=>e+k3(n),0)),N6=t=>t.reduce((e,n)=>e+n.reduce((r,c,a)=>r+Math.hypot(c[0]-n[(a+1)%n.length][0],c[1]-n[(a+1)%n.length][1]),0),0);function ee(t){let e=t.flat();return[Math.min(...e.map(n=>n[0])),Math.min(...e.map(n=>n[1])),Math.max(...e.map(n=>n[0])),Math.max(...e.map(n=>n[1]))]}var Pn=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function U6(t){if(t.length!==1)return!1;let e=ee(t);return c3(h3(t,[Pn(e)]))<j*j}var B6=(t,e)=>a0(t,[Pn(e)]);function En(t,e,n=0){let r=e[0]*e[5]-e[1]*e[4]<0;return t.map(c=>{let a=c.map(([s,i])=>f0(e,[s,i,n]).slice(0,2));return r?a.reverse():a})}function Zo(t,e){let n=!1;for(let r=0,c=t.length-1;r<t.length;c=r++){let[a,s]=t[r],[i,o]=t[c];s>e[1]!=o>e[1]&&e[0]<(i-a)*(e[1]-s)/(o-s)+a&&(n=!n)}return n}function c5(t,e,n){let r=n[0]-e[0],c=n[1]-e[1],a=r*r+c*c,s=a?Math.max(0,Math.min(1,((t[0]-e[0])*r+(t[1]-e[1])*c)/a)):0;return Math.hypot(t[0]-e[0]-s*r,t[1]-e[1]-s*c)}function Tn(t,e){let n=1/0;for(let r of t)for(let c=0;c<e.length;c++)n=Math.min(n,c5(r,e[c],e[(c+1)%e.length]));for(let r of e)for(let c=0;c<t.length;c++)n=Math.min(n,c5(r,t[c],t[(c+1)%t.length]));return n}var _6=(t,e)=>t.filter(n=>k3(n)<0&&Zo(n,e));function a5(t){return t.placed?t.bends.length?"Flexible or bent geometry is not supported by this rigid check.":t.cutLines===null?"Nominal cutting-line geometry is unavailable; render with analysis: true.":t.cutLines.length?"Open cutting lines may remove or weaken material; this rigid check cannot model them.":null:"The part has no physical placement."}function In(t){return[0,1,2,4,5,6,8,9,10].every(e=>Math.abs(t[e])<1e-9||Math.abs(Math.abs(t[e])-1)<1e-9)}function te(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&Ln(t.regions)===Ln(e.regions)&&An(t.cutLines)===An(e.cutLines)}function Ln(t){let e=n=>{let r=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,c=[r,[...r].reverse()].map(a=>{let s=0;for(let i=1;i<a.length;i++)(a[i][0]<a[s][0]||a[i][0]===a[s][0]&&a[i][1]<a[s][1])&&(s=i);return JSON.stringify([...a.slice(s),...a.slice(0,s)])});return JSON.stringify([Math.sign(k3(n)),c.sort()[0]])};return JSON.stringify(t.map(e).sort())}function An(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),r=JSON.stringify([...e].reverse());return n<r?n:r}).sort())}var j1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),S0=t=>typeof t=="string"&&t.length>0,O2=t=>typeof t=="number"&&Number.isFinite(t),G2=t=>O2(t)&&t>=0,H2=t=>O2(t)&&t>0,z3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every(O2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,L3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every(O2),w2=t=>L3(t,3)&&t.every(e=>Math.abs(e)<=1e7),a3=t=>j1(t)&&S0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),ne=t=>j1(t)&&S0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),s5=t=>a3(t)||ne(t),j2=t=>Array.isArray(t)&&t.every(s5),S3=t=>w2(t)&&Math.hypot(...t)>1e-9,Yo=t=>j1(t)&&(t.kind==="translate"&&w2(t.by)||t.kind==="rotate"&&w2(t.origin)&&S3(t.axis)&&O2(t.angle)&&Math.abs(t.angle)<=1e6),j6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),Vn=t=>j1(t)&&Object.values(t).every(j6),On=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||O2(t)||Array.isArray(t)&&t.every(n=>On(n,e+1))),G6=t=>j1(t)&&Object.values(t).every(e=>On(e)),Jo=t=>t===null||j1(t)&&j6(t.sourceHash)&&j6(t.engineHash)&&Vn(t.dependencies)&&Vn(t.fonts);function G5(t){let e=[],n=(s,i)=>e.push({code:"invalid-spec",path:s,message:i});if(!j1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let r=(s,i,o)=>{for(let l of Object.keys(s))i.includes(l)||n(o?`${o}.${l}`:l,"Unknown specification field.")};r(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),S0(t.model)||n("model","Give the model a nonempty name.");let c=new Set,a=(s,i)=>{if(!j1(s)){n(i,"Materials must map material names to measured profiles.");return}for(let[o,l]of Object.entries(s))(!o||!j1(l)||!z3(l.thickness,Number.MIN_VALUE)||!z3(l.kerf)||l.edgeError!==void 0&&!G2(l.edgeError)||l.lot!==void 0&&!S0(l.lot))&&n(`${i}.${o}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),j1(l)&&r(l,["thickness","kerf","edgeError","lot"],`${i}.${o}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[s,i]of t.configurations.entries())!j1(i)||!S0(i.id)||i.params!==void 0&&!G6(i.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):c.has(i.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(c.add(i.id),r(i,["id","params","materials"],`configurations[${s}]`),i.materials!==void 0&&a(i.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,i=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!j1(h)||!S0(h.id)||!S0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(r(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),s.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),s.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&i++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(m=>typeof m=="string"&&c.has(m)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!a3(h.a)||!a3(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!H2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!a3(h.tab)||!a3(h.receiver)||!L3(h.region,4)||h.region.some(m=>Math.abs(m)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!z3(h.clearance)||!G2(h.flushTolerance)||!G2(h.minimumLigament))&&n(u,"Tab-slot needs part references, a nonempty local rectangle, clearance bounds, flushTolerance and minimumLigament.");break;case"captured-shaft":{let m=h.stops;if(!ne(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(a3)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(a3)||!z3(h.clearance)||!z3(h.endplay)||!H2(h.minimumOverlap)||!G2(h.maximumStopGap)||!Array.isArray(m)||m.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let g of m){if(!j1(g)||!ne(g.body)||!j1(g.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}r(g,["body","attachment"],u+".stops");let p=g.attachment;r(p,p.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(p.kind)||p.kind==="threaded"&&(!ne(p.thread)||!H2(p.minimumEngagement)||typeof p.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!G2(h.minimumGap)||h.bodies!==void 0&&(!j2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!S0(h.from)||!c.has(h.from)||!S0(h.to)||!c.has(h.to)||h.from===h.to||!G2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(m=>j1(m)&&s5(m.body)&&Yo(m.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!S0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!j2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!j2(h.scope)||!h.scope.length)||!G2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(m=>j1(m)&&S0(m.id)&&s5(m.part)&&w2(m.from)&&typeof m.held=="boolean"&&(m.fasten===void 0||Array.isArray(m.fasten)&&m.fasten.every(S0))&&(m.tool===void 0||j1(m.tool)&&w2(m.tool.from)&&w2(m.tool.to)&&H2(m.tool.diameter)&&m.tool.diameter<=1e6&&w2(m.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!j2(h.roots)||!h.roots.length||h.removable!==void 0&&!j2(h.removable)||!Array.isArray(h.links)||!h.links.every(m=>j1(m)&&S0(m.claim)&&["glued","locked","captured"].includes(m.fastening)&&typeof m.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!j2(h.bodies)||!h.bodies.length||!j2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(m=>j1(m)&&s5(m.a)&&s5(m.b)&&(m.kind==="fixed"||m.kind==="revolute"&&w2(m.anchorA)&&w2(m.anchorB)&&S3(m.axisA)&&S3(m.axisB)&&(m.range===void 0||z3(m.range,-1e6))||m.kind==="prismatic"&&S3(m.axisA)&&z3(m.travel,-1e6)||m.kind==="gear"&&S3(m.axisA)&&S3(m.axisB)&&H2(m.ratio)&&m.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!j2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!O2(h.ground)||Math.abs(h.ground)>1e7||!S3(h.gravity)||h.gravity[2]>=0||!G2(h.minimumMargin)||!h.loads.every(m=>j1(m)&&s5(m.body)&&H2(m.mass)&&(m.center===void 0||w2(m.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!S0(h.plan)||!S0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(m=>j1(m)&&S0(m.step)&&j2(m.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(m,g,p)=>{j1(m)&&r(m,g,p)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[m,g]of h.moving.entries())j1(g)&&(d(g,["body","trajectory"],`${u}.moving[${m}]`),d(g.trajectory,j1(g.trajectory)&&g.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${m}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[m,g]of h.steps.entries())j1(g)&&(d(g,["id","part","from","held","fasten","tool"],`${u}.steps[${m}]`),d(g.tool,["from","to","diameter","travel"],`${u}.steps[${m}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[m,g]of h.joints.entries())j1(g)&&d(g,["kind","a","b",...g.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:g.kind==="prismatic"?["axisA","travel"]:g.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${m}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((m,g)=>d(m,["claim","fastening","installed"],`${u}.links[${g}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((m,g)=>d(m,["body","mass","center"],`${u}.loads[${g}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((m,g)=>d(m,["step","bodies"],`${u}.holds[${g}]`))}i||n("claims","At least one claim must be required.");let o=t.claims.filter(j1);for(let l of o){let h=(u,f)=>o.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=o.find(g=>g.id===l.plan&&g.kind==="assembly-access"),f=o.find(g=>g.id===l.retention&&g.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(j1).map(g=>g.id)),m=new Set((Array.isArray(f?.links)?f.links:[]).filter(j1).map(g=>g.claim));if(Array.isArray(l.holds))for(let g of l.holds)j1(g)&&!d.has(g.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(g.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let g of u.steps)if(j1(g)&&Array.isArray(g.fasten))for(let p of g.fasten)m.has(p)||n(`claims.${String(u.id)}.steps`,`Step ${String(g.id)} fastens ${String(p)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(j1(f)){let d=j1(f.body)?f.body:{},m=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(m)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(m)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)j1(u)&&!o.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function W6(t){let e=[],n=(c,a)=>e.push({code:"invalid-snapshot",path:c,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let r=new Set;for(let[c,a]of t.entries()){let s=`snapshots[${c}]`;if(!j1(a)||a.schemaVersion!==1||!S0(a.configuration)||!G6(a.params)||!G6(a.renderSettings)||!Jo(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(o=>typeof o=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}r.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),r.add(a.configuration);let i=new Set;for(let[o,l]of a.parts.entries()){if(!j1(l)||!S0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!H2(l.thickness)||l.glue!==void 0&&(!a3(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!S0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!G2(l.kerf)||l.kerf>1e6)||!Ko(l.matrix)||typeof l.placed!="boolean"||!Hn(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!Hn(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>j1(u)&&O2(u.x0)&&O2(u.x1)&&u.x1>u.x0&&O2(u.angle))){n(`${s}.parts[${o}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);i.has(h)&&n(`${s}.parts[${o}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),i.add(h)}for(let[o,l]of a.hardware.entries())(!j1(l)||l.label!==null&&!S0(l.label)||typeof l.kind!="string"||!L3(l.from,3)||!L3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!w2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!H2(l.size))||!(H2(l.size)&&l.size<=1e6||L3(l.size,2)&&l.size.every(h=>H2(h)&&h<=1e6)))&&n(`${s}.hardware[${o}]`,"Malformed hardware geometry or label.")}return e}function Hn(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>L3(r,2)&&r.every(c=>Math.abs(c)<=1e6)))}function Ko(t){if(!L3(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(r=>Math.abs(r)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let r=0;r<3;r++)for(let c=0;c<3;c++){let a=e[r]*e[c]+e[4+r]*e[4+c]+e[8+r]*e[8+c];if(Math.abs(a-(r===c?1:0))>n)return!1}return Math.abs(e[0]*(e[5]*e[10]-e[6]*e[9])-e[1]*(e[4]*e[10]-e[6]*e[8])+e[2]*(e[4]*e[9]-e[5]*e[8])-1)<n}function Fn(t){let e=[];for(let n of t.claims){let r=c=>e.push({claim:n.id,ref:c});n.kind==="glue-contact"&&(r(n.a),r(n.b)),n.kind==="tab-slot"&&(r(n.tab),r(n.receiver)),n.kind==="captured-shaft"&&(r(n.shaft),n.bearings.forEach(r),n.stack.forEach(r),n.stops.forEach(c=>{r(c.body),c.attachment.kind==="threaded"&&r(c.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(r),n.kind==="motion-clearance"&&n.moving.forEach(c=>r(c.body)),n.kind==="assembly-access"&&(n.initial.forEach(r),n.scope?.forEach(r),n.steps.forEach(c=>r(c.part))),n.kind==="retention"&&(n.roots.forEach(r),n.removable?.forEach(r)),n.kind==="joint-constraints"&&(n.bodies.forEach(r),n.roots.forEach(r),n.joints.forEach(c=>{r(c.a),r(c.b)})),n.kind==="stability"&&(n.supports.forEach(r),n.loads.forEach(c=>r(c.body))),n.kind==="assembly-support"&&n.holds?.forEach(c=>c.bodies.forEach(r))}return e}var r2=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),F2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var e0=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),l1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),K6=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),X5=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,W5=(t,e)=>X5(t,e)?.thickness??[e.thickness,e.thickness];function ce(t,e){let n=X5(t,e);return n?e.kerf===null?[-1/0,1/0]:[e.kerf-n.kerf[1]-2*(n.edgeError??0),e.kerf-n.kerf[0]+2*(n.edgeError??0)]:[0,0]}var Y6=(t,e)=>t[0]>=e[0]+j&&t[1]<=e[1]-j,J6=(t,e)=>t[0]<e[0]-j||t[1]>e[1]+j,Q6=(...t)=>t.map(a5).find(Boolean);function se(t,e){let n=r2(e,t.a),r=r2(e,t.b);if(n===r)return e0("A glue contact needs two different physical instances.");let c=Q6(n,r);if(c)return l1(c);let a=q6(n,r),s=t.faceA==="top"?n.thickness:0,i=t.faceB==="top"?r.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return e0("The selected faces are not parallel.");let o=Math.abs(a[11]+a[10]*i-s);if(o>j)return e0("The selected faces are separated.",{faceGap:o});if(o>1e-7)return l1("Face separation is within numerical uncertainty; exact contact is not established.");let l=t.faceA==="top"?1:-1,h=t.faceB==="top"?1:-1;if(l*h*a[10]>-1+1e-7)return e0("The selected surfaces face the same way, rather than meeting.");let u=En(r.regions,a,i),f=c3(a0(n.regions,u)),d=j*(N6(n.regions)+N6(u)),m={contactArea:f,requiredArea:t.minimumArea,faceGap:o,areaUncertainty:d};return f<t.minimumArea-d?e0("There is insufficient geometric glue contact.",m):f<t.minimumArea+d?{...l1("Contact area is on the numerical acceptance boundary."),measurements:m}:K6("The selected nominal faces have the required geometric contact.",m,["Rigid flat faces and a zero-thickness adhesive layer.","This checks nominal contact geometry; adhesive strength, stock variation and durability are not established."])}function Rn(t,e,n){let r=r2(e,t.tab),c=r2(e,t.receiver);if(r===c)return e0("A tongue and its receiving panel must be different instances.");let a=Q6(r,c);if(a)return l1(a);let s=q6(c,r);if(!In(s)||Math.abs(s[10])>j)return l1("Only orthogonal tab/slot geometry is supported.");let i=B6(r.regions,t.region);if(!U6(i))return l1("The selected tongue is not one solid rectangle.");let[o,l,h,u]=ee(i),f=4*j,d=j,g=[[o-f,l+d,o,u-d],[h,l+d,h+f,u-d],[o+d,l-f,h-d,l],[o+d,u,h-d,u+f]].map(T=>c3(B6(r.regions,T))>j*j).flatMap((T,B)=>T?[B]:[]);if(g.length>1)return l1("The selector crops through multiple material edges; it does not identify a physical tongue.");if(g.length&&Math.abs(g[0]<2?s[8]:s[9])<.5)return l1("The tongue must join its parent along the insertion direction.");let p;if(g.length){let T=g[0],B=T<2?[T===0?o:h,(l+u)/2,0]:[(o+h)/2,T===2?l:u,0],X=f0(s,B)[2],Z=(T<2?s[8]:s[9])*(T%2===0?-1:1);p={z:X,outward:Z}}let v=[];for(let T of[o,h])for(let B of[l,u])for(let X of[0,r.thickness])v.push(f0(s,[T,B,X]));let y=[0,1,2].map(T=>Math.min(...v.map(B=>B[T]))),b=[0,1,2].map(T=>Math.max(...v.map(B=>B[T]))),x=_6(c.regions,[(y[0]+b[0])/2,(y[1]+b[1])/2]);if(!x.length)return e0("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!U6([x[0]]))return l1("The receiving feature must be an unambiguous rectangular closed slot.");let M=x[0],w=ee([M]),k=ce(n,r),z=ce(n,c);if(![...k,...z].every(Number.isFinite))return l1("Compensated kerf metadata is needed for manufacturing bounds.");let S={},A=!1;for(let T=0;T<2;T++){let B=Math.abs(s[T*4+2])>.5,X=B?W5(n,r):[b[T]-y[T]+k[0],b[T]-y[T]+k[1]],Z=w[T+2]-w[T],h1=[Z-z[1]-X[1],Z-z[0]-X[0]];if(S[T?"clearanceY":"clearanceX"]=h1,J6(h1,t.clearance))return e0("Tab/slot clearance is outside the required range.",S);A||(A=!Y6(h1,t.clearance));let H=y[T],U=b[T];B?s[T*4+2]>0?U+=X[1]-r.thickness:H-=X[1]-r.thickness:(H-=Math.max(0,k[1])/2,U+=Math.max(0,k[1])/2);let Y=Math.min(H-w[T],w[T+2]-U)-Math.max(0,z[1])/2;if(S[T?"minimumSideGapY":"minimumSideGapX"]=Y,Y<-j)return e0("The tongue is offset into the edge of its slot.",S);Y<j&&(A=!0)}let L=Math.max(0,-k[0])/2,C=W5(n,c);if(t.flushTolerance>=C[0]-j)return l1("flushTolerance must be smaller than the receiving thickness.");let P=Math.max(0,Math.min(b[2]-L,C[1])-Math.max(y[2]+L,0)),R=C[1]-t.flushTolerance;if(S.engagement=P,S.requiredEngagement=R,P<=j)return e0("The tongue does not engage the receiving panel.",S);if(P<R-j)return e0("The tongue does not engage through the receiving panel.",S);if(P<R+j&&(A=!0),p&&(p.outward>0&&p.z<C[1]-j||p.outward<0&&p.z>j))return e0("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",S);let q=Math.min(...c.regions.filter(T=>T!==M).map(T=>Tn(M,T)))-Math.max(0,-z[0]);return S.minimumLigament=q,q<t.minimumLigament-j?e0("Too little material remains around the slot.",S):(q<t.minimumLigament+j&&(A=!0),A?{...l1("A fit condition is on its numerical acceptance boundary."),measurements:S}:K6("The rectangular tongue fits and engages its receiving slot.",S,["Rigid orthogonal parts; nominal placements are held fixed while finished dimensions vary.","The selected local rectangle must identify the physical tongue; this fit does not establish retention."],X5(n,r)||X5(n,c)?"bounded-fit":"nominal"))}function re(t){let e=b1(t.to,t.from),n=S1(e);return typeof t.size=="number"&&n>j?{start:t.from,dir:e.map(r=>r/n),length:n,diameter:t.size}:null}function X6(t,e){let n=re(e);if(!n||S1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let r=b1(n.start,t.start),c=K1(r,t.dir);return S1(r.map((a,s)=>a-c*t.dir[s]))<j}var ae=(t,e)=>K1(b1(e,t.start),t.dir),Z6=(t,e)=>[ae(t,e.from),ae(t,e.to)].sort((n,r)=>n-r);function Qo(t,e){let n=Cn(e.matrix);if(K1(n,t.dir)<0||S1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let r=f0(p0(e.matrix),t.start),c=[r[0],r[1]],a=_6(e.regions,c);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],i=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,o=[i.reduce((m,g)=>m+g[0],0)/i.length,i.reduce((m,g)=>m+g[1],0)/i.length];if(Math.hypot(o[0]-c[0],o[1]-c[1])>j)return"The shaft is not centered in the bore.";let l=s.map(m=>Math.hypot(m[0]-o[0],m[1]-o[1]));if(Math.max(...l)-Math.min(...l)>j)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((m,g)=>c5(c,m,s[(g+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-c[0],m[1]-c[1]))),f=ae(t,f0(e.matrix,[0,0,0])),d=ae(t,f0(e.matrix,[0,0,e.thickness]));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u]}}function $n(t,e,n){let r=F2(e,t.shaft),c=re(r);if(!c)return l1("The shaft must have a nonzero cylindrical physical envelope.");let a=[...t.bearings,...t.stack],s=a.map(x=>JSON.stringify([x.part,x.copy??1]));if(new Set(s).size!==s.length)return e0("Bearing and stack references must name distinct physical parts.");let i=a.map(x=>r2(e,x)),o=Q6(...i);if(o)return l1(o);let l={shaftDiameter:c.diameter},h=[],u=!1;for(let x=0;x<i.length;x++){let M=i[x],w=Qo(c,M);if(typeof w=="string")return/unsupported|supported/.test(w)?l1(`${M.name}: ${w}`):e0(`${M.name}: ${w}`);let k=ce(n,M);if(!k.every(Number.isFinite))return l1("Kerf metadata is required for bore tolerance bounds.");let z=[w.hole[0]-k[1]-c.diameter,w.hole[1]-k[0]-c.diameter];if(l[`clearance${x+1}`]=z,J6(z,t.clearance))return e0(`${M.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!Y6(z,t.clearance)),w.lo<-j||w.lo+W5(n,M)[1]>c.length+j)return e0(`${M.name}: the shaft does not extend through this part.`,l);h.push(w)}let f=h.slice(0,2).sort((x,M)=>x.lo-M.lo),d=h.slice(2).sort((x,M)=>x.lo-M.lo);if(f.some(x=>W5(n,x.part).some(M=>Math.abs(M-x.part.thickness)>j)))return l1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-j)return e0("Bearing panels overlap or leave no stack cavity.");for(let x=0;x<d.length;x++)if(d[x].lo<f[0].hi-j||d[x].hi>f[1].lo+j||x&&d[x-1].hi>d[x].lo+j)return e0("The axial stack overlaps another component or its supports.");let m=f[1].lo-f[0].lo,p=[f[0].part,...d.map(x=>x.part)].map(x=>W5(n,x)).reduce((x,M)=>[x[0]+M[0],x[1]+M[1]],[0,0]),v=[m-p[1],m-p[0]];if(l.endplay=v,J6(v,t.endplay))return e0("The axial stack has insufficient or excessive endplay.",l);u||(u=!Y6(v,t.endplay));let y=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],b=t.stops.map(x=>({stop:x,h:F2(e,x.body)})).map(x=>({...x,at:x.h&&X6(c,x.h)?Z6(c,x.h):void 0}));if(b.some(x=>!x.at))return e0("A retainer is not coaxial with the shaft.");b.sort((x,M)=>x.at[0]+x.at[1]-(M.at[0]+M.at[1]));for(let x=0;x<2;x++){let{stop:M,h:w}=b[x];if(!X6(c,w))return e0("A retainer is not coaxial with the shaft.");let k=re(w),z=Z6(c,w),S=f[x],A=x===0?z[1]:z[0],L=x===0?S.lo:S.hi,C=x===0?L-A:A-L;l[`stopGap${x+1}`]=C;let P=ce(n,S.part),R=(k.diameter-(S.hole[1]-P[0]))/2;if(l[`stopOverlap${x+1}`]=R,C<-j||C>t.maximumStopGap+j)return e0("A retainer is misplaced relative to the outside bearing face.",l);if((C<-1e-7||C>t.maximumStopGap+1e-7)&&(u=!0),R<t.minimumOverlap-j)return e0("A retainer can pass through its bearing opening.",l);R<t.minimumOverlap+j&&(u=!0);let q=M.attachment;if(q.kind==="unknown")return{...l1("The stop is present but its fastening is unverified."),measurements:l};if(q.kind==="integral"){if(Math.min(Math.abs(A),Math.abs(A-c.length))>j)return e0("An integral head must meet an end of its shaft.",l);y.push("The specified head and shaft are one integral purchased component.")}else{let T=F2(e,q.thread);if(!X6(c,T))return e0("The threaded attachment is off the shaft axis.");if(re(T).diameter>c.diameter+j)return e0("The declared threaded section exceeds the shaft envelope.");let B=Z6(c,T),X=Math.max(0,Math.min(z[1],B[1])-Math.max(z[0],B[0]));if(B[0]<-j||B[1]>c.length+j)return e0("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=X,X<q.minimumEngagement-j)return e0("The threaded stop has insufficient declared thread engagement.",l);if(X<q.minimumEngagement+j&&(u=!0),!q.secured)return{...l1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};y.push("The specified usable thread envelope and matching nut are installed and secured as declared; thread form/capacity and resistance to loosening are not verified.")}}return u?{...l1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:K6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,y,i.some(x=>X5(n,x))?"bounded-fit":"nominal")}var ie=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},d1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),V0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],L0=(t,e)=>t.map(n=>n*e),Nn=(t,e)=>t.map((n,r)=>n+e[r]),W1=t=>L0(t,1/S1(t)),Un=()=>B0(0,0,0);function et(t,e){let n=r=>r.kind==="translate"?S1(r.by)<1e-9:Math.abs(r.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?S1(b1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?S1(b1(L0(W1(t.axis),t.angle),L0(W1(e.axis),e.angle)))<1e-9&&S1(V0(b1(t.origin,e.origin),W1(t.axis)))<1e-9:!1}function el(t,e){let n=new Map;for(let r of e)for(let c=0;c<r.length;c++){let a=r[c],s=r[(c+1)%r.length],i=a<s?[a,s]:[s,a];n.set(i.join(","),i)}return{vertices:t,faces:e,edges:[...n.values()]}}function i5(t,e,n){let r=t.length,c=[];for(let a of[0,e])for(let[s,i]of t)c.push(f0(n,[s,i,a]));return el(c,[t.map((a,s)=>s).reverse(),t.map((a,s)=>r+s),...t.map((a,s)=>[s,(s+1)%r,(s+1)%r+r,s+r])])}function tl(t,e){let n=i1(t),r=[...new Set(n.flat().map(i=>i[0]))].sort((i,o)=>i-o),c=n.flatMap(i=>i.map((o,l)=>({a:o,b:i[(l+1)%i.length]}))),a=[],s=(i,o)=>i.a[1]+(o-i.a[0])*(i.b[1]-i.a[1])/(i.b[0]-i.a[0]);for(let i=1;i<r.length;i++){let o=r[i-1],l=r[i],h=(o+l)/2;e.tick(c.length);let u=c.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],m=u[f+1],g=[[o,s(d,o)],[l,s(d,l)],[l,s(m,l)],[o,s(m,o)]],p=g.filter((v,y)=>S1([v[0]-g[(y+1)%g.length][0],v[1]-g[(y+1)%g.length][1],0])>1e-10);if(p.length<3||Math.abs(k3(p))<1e-12)throw new Error("A material sliver is below the supported solid precision.");if(a.push(p),a.length>5e3)throw new Error("Rigid decomposition exceeds its cell budget.")}}if(!a.length||Math.abs(c3(a)-c3(n))>j*j*Math.max(1,c3(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function A3(t){if(t.hardware.some(n=>!n.label))throw new Error("Physical hardware needs unique labels for whole-inventory checks.");let e=[...t.parts.map(n=>({part:n.name,copy:n.copy})),...t.hardware.map(n=>({hardware:n.label}))];if(new Set(e.map(d1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function Z5(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function i0(t,e){if("part"in e)return r2(t,e).matrix;let n=F2(t,e),[r,c]=Z5(n),a={...n,from:r,to:c},s=W1(b1(a.to,a.from));if(!S1(b1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let i=b1(a.up,L0(s,K1(a.up,s)));if(S1(i)<1e-9){if(Array.isArray(a.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(s[0])<.8?[1,0,0]:[0,1,0];i=b1(l,L0(s,K1(l,s)))}i=W1(i);let o=V0(i,s);return[o[0],i[0],s[0],a.from[0],o[1],i[1],s[1],a.from[1],o[2],i[2],s[2],a.from[2],0,0,0,1]}function s3(t,e,n){if(n.tick(),"part"in e){let h=r2(t,e),u=a5(h);if(u)throw new Error(u);let d=tl(h.regions,n).map(m=>i5(m,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=F2(t,e),c=i0(t,e),[a,s]=Z5(r),i=S1(b1(s,a));if(i<j)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(r.size)){let[h,u]=r.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[i5(f,i,c)];return{ref:e,outer:d,inner:d}}let o=32,l=h=>Array.from({length:o},(u,f)=>[h*Math.cos(f*2*Math.PI/o),h*Math.sin(f*2*Math.PI/o)]);if(r.shape==="ball"){let h=r.size/2,u=h/Math.SQRT2,f=B0(0,0,h-u);return{ref:e,inner:[i5(l(u),2*u,q1(c,f))],outer:[i5(l(h/Math.cos(Math.PI/o)),i,c)]}}return{ref:e,inner:[i5(l(r.size/2),i,c)],outer:[i5(l(r.size/2/Math.cos(Math.PI/o)),i,c)]}}function oe(t,e){let n=c=>c.map(a=>({...a,vertices:a.vertices.map(s=>f0(e,s))})),r=n(t.outer);return{ref:t.ref,outer:r,inner:t.inner===t.outer?r:n(t.inner)}}function C3(t,e){if(t.kind==="translate")return B0(...L0(t.by,e));let[n,r,c]=W1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),i=Math.sin(a),o=1-s,l=[s+n*n*o,n*r*o-c*i,n*c*o+r*i,0,r*n*o+c*i,s+r*r*o,r*c*o-n*i,0,c*n*o-r*i,c*r*o+n*i,s+c*c*o,0,0,0,0,1];return q1(B0(...t.origin),q1(l,B0(...L0(t.origin,-1))))}function tt(t,e){if(e.kind==="translate")return S1(e.by);let n=W1(e.axis),r=0;for(let c of t.outer)for(let a of c.vertices){let s=b1(a,e.origin);r=Math.max(r,S1(b1(s,L0(n,K1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*r}function Dn(t){return t.faces.map(e=>V0(b1(t.vertices[e[1]],t.vertices[e[0]]),b1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>S1(e)>1e-12).map(W1)}function Bn(t,e){let n=[...Dn(t),...Dn(e)];for(let[r,c]of t.edges)for(let[a,s]of e.edges){let i=V0(b1(t.vertices[c],t.vertices[r]),b1(e.vertices[s],e.vertices[a]));S1(i)>1e-12&&n.push(W1(i))}return n}var o5=(t,e)=>{let n=t.vertices.map(r=>K1(r,e));return[Math.min(...n),Math.max(...n)]};function nl(t,e,n){let r=-1/0;for(let c of Bn(t,e)){n.tick();let a=o5(t,c),s=o5(e,c);r=Math.max(r,s[0]-a[1],a[0]-s[1])}return r}function rl(t,e){let n=0;for(let r=0;r<3;r++){let c=t.vertices.map(i=>i[r]),a=e.vertices.map(i=>i[r]),s=Math.max(0,Math.min(...a)-Math.max(...c),Math.min(...c)-Math.max(...a));n+=s*s}return Math.sqrt(n)}function cl(t,e,n,r){let c=b1(n,e),a=b1(r,e),s=b1(t,e),i=K1(c,s),o=K1(a,s);if(i<=0&&o<=0)return S1(s);let l=b1(t,n),h=K1(c,l),u=K1(a,l);if(h>=0&&u<=h)return S1(l);let f=i*u-h*o;if(f<=0&&i>=0&&h<=0)return S1(b1(s,L0(c,i/(i-h))));let d=b1(t,r),m=K1(c,d),g=K1(a,d);if(g>=0&&m<=g)return S1(d);let p=m*o-i*g;if(p<=0&&o>=0&&g<=0)return S1(b1(s,L0(a,o/(o-g))));let v=h*g-m*u;if(v<=0&&u-h>=0&&m-g>=0)return S1(b1(l,L0(b1(r,n),(u-h)/(u-h+m-g))));let y=v+p+f;if(Math.abs(y)<1e-20)return 1/0;let b=Math.max(0,Math.min(1,p/y)),x=Math.max(0,Math.min(1-b,f/y));return S1(b1(s,Nn(L0(c,b),L0(a,x))))}function al(t,e,n,r){let c=b1(e,t),a=b1(r,n),s=b1(t,n),i=K1(c,c),o=K1(c,a),l=K1(a,a),h=K1(c,s),u=K1(a,s);if(i<1e-20||l<1e-20)return 1/0;let f=i*l-o*o,d=f>1e-20?Math.max(0,Math.min(1,(o*u-l*h)/f)):0,m=(o*d+u)/l;return m<0&&(m=0,d=Math.max(0,Math.min(1,-h/i))),m>1&&(m=1,d=Math.max(0,Math.min(1,(o-h)/i))),S1(Nn(s,b1(L0(c,d),L0(a,m))))}function sl(t,e,n){let r=1/0;for(let[c,a]of[[t,e],[e,t]])for(let s of c.vertices)for(let i of a.faces)for(let o=1;o<i.length-1;o++)n.tick(),r=Math.min(r,cl(s,a.vertices[i[0]],a.vertices[i[o]],a.vertices[i[o+1]]));for(let[c,a]of t.edges)for(let[s,i]of e.edges)n.tick(),r=Math.min(r,al(t.vertices[c],t.vertices[a],e.vertices[s],e.vertices[i]));return r}function qn(t,e,n,r){let c=1/0,a=1/0,s=!1,i=!0;for(let o of t)for(let l of e){n.tick();let h=rl(o,l);if(h>Math.min(a,r)){c=Math.min(c,h);continue}let u=nl(o,l,n);u<-j&&(s=!0),u<0&&(i=!1),c=Math.min(c,Math.max(0,h,u)),u<-j?a=0:u<=Math.min(a,r)&&(a=Math.min(a,sl(o,l,n)))}return{lower:c,upper:a,penetration:s,touchSafe:i}}function le(t,e,n,r){let c=qn(t.outer,e.outer,n,r+j),a=t.outer===t.inner&&e.outer===e.inner;if(c.lower>r+j)return{lower:c.lower-j,upper:1/0,penetration:!1,touchSafe:!0};let s=a?c:qn(t.inner,e.inner,n,1/0);return{lower:Math.max(0,c.lower-j),upper:s.upper+j,penetration:s.penetration,touchSafe:c.touchSafe}}function _n(t,e,n,r,c,a){for(let s=0;s<t.outer.length;s++)for(let i=0;i<n.outer.length;i++){let o=t.outer[s],l=n.outer[i],h=e.outer[s],u=r.outer[i],f=!1;for(let d of Bn(o,l)){a.tick();let m=o5(o,d),g=o5(l,d),p=o5(h,d),v=o5(u,d);if(Math.min(g[0]-m[1],v[0]-p[1])>=c||Math.min(m[0]-g[1],p[0]-v[1])>=c){f=!0;break}}if(!f)return!1}return!0}function he(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let r={part:n.name,copy:n.copy},c=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(c>1&&(n.copy-1)%c!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:r,faceA:a?"bottom":"top",faceB:a?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:r,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var k2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),Y5=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<j);function jn(t,e,n){if(new Set(e.map(d1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(r=>s3(t,r,n))}function Gn(t,e,n){let r=jn(e,t.bodies??A3(e),n);if(r.length<2)return l1("Rigid clearance requires at least two physical bodies.");let c=1/0;for(let a=0;a<r.length;a++)for(let s=a+1;s<r.length;s++){let i=le(r[a],r[s],n,t.minimumGap);if(c=Math.min(c,i.lower),i.penetration||i.upper<t.minimumGap-j)return k2("Physical bodies interfere or violate the required clearance.",{gapUpper:i.upper},[r[a].ref,r[s].ref]);if(!(i.lower>t.minimumGap||t.minimumGap===0&&i.touchSafe))return{...l1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[r[a].ref,r[s].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:c},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function nt(t,e,n,r,c=1e3){let a=o=>({solid:o,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let o=0;o<t.length;o++){for(let l of e)yield{a:t[o],b:a(l)};for(let l=o+1;l<t.length;l++)yield{a:t[o],b:t[l]}}}let i=0;for(let{a:o,b:l}of s()){r.tick();let h=(d,m)=>oe(d.solid,C3(d.trajectory,m));if(et(o.trajectory,l.trajectory)){let d=le(o.solid,l.solid,r,n);if(d.penetration||d.upper<n-j)return k2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[o.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...l1("The fixed relative clearance is within geometric uncertainty."),entities:[o.solid.ref,l.solid.ref]}}if(o.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&_n(h(o,0),h(o,1),h(l,0),h(l,1),n===0?0:n+j,r))continue;let u=tt(o.solid,o.trajectory)+tt(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++i>c)return{...l1("Continuous clearance interval budget exhausted."),measurements:{intervals:i},entities:[o.solid.ref,l.solid.ref]};r.tick();let[d,m]=f.shift(),g=(d+m)/2,p=u*(m-d)/2,v=le(h(o,g),h(l,g),r,n+p);if(v.penetration||v.upper<n-j)return k2("The specified path has physical interference.",{phase:g,gapUpper:v.upper},[o.solid.ref,l.solid.ref]);if(!(v.lower-p>n)){if(m-d<1e-9)return{...l1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,m]},entities:[o.solid.ref,l.solid.ref]};f.push([d,g],[g,m])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:i},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function il(t,e){if(t.parts.length!==e.parts.length||t.hardware.length!==e.hardware.length)return"The physical inventory changes between motion endpoints.";for(let n of t.parts){let r=e.parts.find(c=>c.name===n.name&&c.copy===n.copy);if(!r||n.cutLines===null||r.cutLines===null||!te(n,r))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([r.stack,r.glue,r.glueFace,r.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let r=e.hardware.find(c=>c.label===n.label);if(!n.label||!r||n.kind!==r.kind||JSON.stringify(n.size)!==JSON.stringify(r.size)||Math.abs(S1(b1(n.to,n.from))-S1(b1(r.to,r.from)))>j)return"Hardware identities and dimensions must remain invariant."}return null}function Wn(t,e,n,r,c=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return l1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=il(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=A3(e),i=new Set(t.moving.map(l=>d1(l.body)));if(i.size!==t.moving.length)return k2("A body has conflicting simultaneous trajectories.");let o=l=>t.moving.find(h=>d1(h.body)===d1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...he(e),...c]){let h=q1(p0(i0(e,l.a)),i0(e,l.b)),u=q1(p0(i0(n,l.a)),i0(n,l.b));if(!Y5(h,u)||!et(o(l.a),o(l.b)))return k2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>d1(f.body)===d1(l))?.trajectory,u=h?C3(h,1):Un();if("part"in l){if(!Y5(q1(u,i0(e,l)),i0(n,l)))return k2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=F2(e,l),d=F2(n,l);if(typeof f.size=="number"){if(!Y5(f0(u,f.from),d.from)||!Y5(f0(u,f.to),d.to))return k2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!Y5(q1(u,i0(e,l)),i0(n,l)))return k2("A box trajectory does not match its rendered destination.",{},[l])}}return nt(t.moving.map(l=>({solid:s3(e,l.body,r),trajectory:l.trajectory})),jn(e,s.filter(l=>!i.has(d1(l))),r),t.minimumGap,r,t.maxIntervals)}function Xn(t,e,n){let r=t.scope??A3(e),c=new Set(r.map(d1)),a=new Map(t.initial.map(o=>[d1(o),s3(e,o,n)]));if(c.size!==r.length||a.size!==t.initial.length||t.initial.some(o=>!c.has(d1(o))))return k2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,i=0;for(let o of t.steps){if(s.has(o.id)||!c.has(d1(o.part))||a.has(d1(o.part)))return k2("An assembly step duplicates or misidentifies a required installation.");if(s.add(o.id),!o.held)return{...l1(`Step ${o.id} needs an explicit temporary holding/support assumption.`),assemblyStep:o.id};let l=s3(e,o.part,n),h=oe(l,C3({kind:"translate",by:o.from},1)),u=nt([{solid:h,trajectory:{kind:"translate",by:o.from.map(f=>-f)}}],[...a.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:o.id,message:`Assembly step ${o.id}: ${u.message}`};if(i+=u.measurements?.intervals??0,a.set(d1(o.part),l),o.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:o.tool.from,to:o.tool.to,size:o.tool.diameter,up:[0,1,0]}]},m=s3(d,{hardware:f},n),g=oe(m,C3({kind:"translate",by:o.tool.travel},1)),p=nt([{solid:g,trajectory:{kind:"translate",by:o.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(p.status!=="pass")return{...p,assemblyStep:o.id,message:`Tool access at step ${o.id}: ${p.message}`}}}return a.size!==c.size?k2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:a.size,intervals:i},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var Q1=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),K0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),j0=t=>[t[3],t[7],t[11]],rt=t=>{let e=W1(t),n=W1(V0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,V0(e,n)]},ue=(t,e,n)=>{let r=rt(n)[0],c=W1(K0(e,r)),a=W1(K0(t,r)),s=W1(K0(e,n));return Math.atan2(K1(s,V0(c,a)),K1(c,a))*180/Math.PI},Zn=(t,e,n)=>{let r=[],c=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let i=c;i<=a&&r.length<64;i++)r.push(t+360*i);let s=(e[0]+e[1])/2;return r.sort((i,o)=>Math.abs(i-s)-Math.abs(o-s))};function Yn(t,e){if(t?.kind==="glue-contact"&&e==="glued")return[t.a,t.b];if(t?.kind==="captured-shaft"&&e==="captured"){let n=[t.shaft,...t.bearings,...t.stack,...t.stops.map(r=>r.body)];for(let r of t.stops)r.attachment.kind==="threaded"&&n.push(r.attachment.thread);return n}}function Jn(t,e,n,r){let c=A3(e),a=new Set(c.map(d1));for(let f of t.removable??[])a.delete(d1(f));if(t.roots.some(f=>!a.has(d1(f))))return Q1("A retention root cannot be excluded as removable.");let s=new Map,i=f=>{for(let d of f)for(let m of f){let g=d1(d),p=s.get(g)??new Set;p.add(d1(m)),s.set(g,p)}},o=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(p=>p.id===f.claim),m=r.find(p=>p.id===f.claim&&p.configurations.includes(e.configuration));if(!d||!m)return l1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(m.status==="fail")return Q1(`Attachment ${f.claim} fails its geometric contract.`);if(m.status!=="pass")return l1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return Q1(`The fastening for ${f.claim} is explicitly not installed.`);let g=Yn(d,f.fastening);if(!g)return l1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);i(g),d.kind==="glue-contact"&&o.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(d1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=c.filter(f=>a.has(d1(f))&&!l.has(d1(f)));return u.length?{...Q1("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:a.size,removableComponents:t.removable?.length??0},assumptions:o}}function ol(t,e){if("hardware"in e){let i=i0(t,e),o=t.hardware.find(l=>l.label===e.hardware);return f0(i,[0,0,S1(b1(Z5(o)[1],Z5(o)[0]))/2])}let n=r2(t,e),r=a5(n);if(r)throw new Error(r);let c=0,a=0,s=0;for(let i of n.regions){let[o,l]=i[0],h=0,u=0,f=0;for(let m=0;m<i.length;m++){let g=i[m],p=i[(m+1)%i.length],v=g[0]-o,y=g[1]-l,b=p[0]-o,x=p[1]-l,M=v*x-b*y;h+=M,u+=(v+b)*M,f+=(y+x)*M}if(Math.abs(h)<1e-12)continue;let d=k3(i);c+=d,a+=(o+u/(3*h))*d,s+=(l+f/(3*h))*d}if(c<=j*j)throw new Error("Material centroid is numerically unresolved.");return f0(n.matrix,[a/c,s/c,n.thickness/2])}function ll(t){let e=[...t].sort((s,i)=>s[0]-i[0]||s[1]-i[1]),n=(s,i,o)=>(i[0]-s[0])*(o[1]-s[1])-(i[1]-s[1])*(o[0]-s[0]),r=s=>{let i=[];for(let o of s){for(;i.length>1&&n(i[i.length-2],i[i.length-1],o)<=0;)i.pop();i.push(o)}return i},c=r(e),a=r([...e].reverse());return[...c.slice(0,-1),...a.slice(0,-1)]}function hl(t,e,n){let r=new Map,c=i=>{for(let o of i)for(let l of i){let h=r.get(d1(o))??new Set;h.add(d1(l)),r.set(d1(o),h)}};for(let i of t.links){let o=Yn(e.claims.find(l=>l.id===i.claim),i.fastening);o&&c(o)}if(!n.length)return!0;let a=new Set([d1(n[0])]),s=[...a];for(;s.length;)for(let i of r.get(s.pop())??[])a.has(i)||(a.add(i),s.push(i));return n.every(i=>a.has(d1(i)))}function Kn(t,e,n,r=[],c){let a=A3(e),s=t.loads.map(g=>d1(g.body));if(new Set(s).size!==s.length||a.some(g=>!s.includes(d1(g))))return l1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let g=r.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),p=c?.claims.find(v=>v.id===t.retention);if(!g||g.status!=="pass"||!p||p.kind!=="retention"||p.removable?.length)return l1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!hl(p,c,a))return l1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let i=0,o=[0,0,0];for(let g of t.loads){let p=g.center?f0(i0(e,g.body),g.center):ol(e,g.body);i+=g.mass,o=o.map((v,y)=>v+g.mass*p[y])}if(!Number.isFinite(i)||!o.every(Number.isFinite))return l1("Mass/centroid calculation exceeds its numerical range.");o=L0(o,1/i);let l=[];for(let g of a){let p=s3(e,g,n),v=Math.min(...p.inner.flatMap(b=>b.vertices.map(x=>x[2]))),y=Math.min(...p.outer.flatMap(b=>b.vertices.map(x=>x[2])));if(v<t.ground-j)return Q1("A physical component penetrates the ground plane.");if(y<t.ground-j)return l1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(b=>d1(b)===d1(g))){if(Math.abs(v-t.ground)>1e-8)return l1("Ground contact is separated or within physical-envelope uncertainty.");for(let b of p.inner)for(let x of b.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=ll(l);if(h.length<3)return l1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-o[2])/t.gravity[2],f=[o[0]+u*t.gravity[0],o[1]+u*t.gravity[1]],d=1/0;for(let g=0;g<h.length;g++){let p=h[g],v=h[(g+1)%h.length],y=(v[0]-p[0])*(f[1]-p[1])-(v[1]-p[1])*(f[0]-p[0]),b=c5(f,p,v);d=Math.min(d,y<0?-b:b)}let m={supportMargin:d,mass:i,centerX:o[0],centerY:o[1],centerZ:o[2]};return d<t.minimumMargin-j?Q1("The gravity line lies outside the required support margin.",m):d<t.minimumMargin+j?{...l1("Stability is on its numerical support boundary."),measurements:m}:{status:"pass",code:"static-stability",message:"The declared mass/gravity case lies within the measured support polygon.",coverage:"nominal",measurements:m,assumptions:["The loads form one retained rigid assembly; declared masses are correct. Unspecified centers assume uniform material. Sliding resistance, impact and structural strength are not established."]}}function Qn(t,e,n,r){let c=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>r.find(m=>m.id===d&&m.configurations.includes(e.configuration));if(!c||c.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return l1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return l1("Per-step support of removable objects needs an explicit contact model.");let i=new Set(a.roots.map(d1)),o=new Set(c.initial.map(d1));if(c.initial.some(d=>!i.has(d1(d))))return l1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let m=n.claims.find(g=>g.id===d.claim);if(m?.kind==="glue-contact")l.set(d.claim,[m.a,m.b]);else if(m?.kind==="captured-shaft"){let g=[m.shaft,...m.bearings,...m.stack,...m.stops.map(p=>p.body)];m.stops.forEach(p=>{p.attachment.kind==="threaded"&&g.push(p.attachment.thread)}),l.set(d.claim,g)}}let h=new Set,u=new Set(c.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return Q1("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let p of h)for(let v of l.get(p)??[])for(let y of l.get(p)??[]){let b=d.get(d1(v))??new Set;b.add(d1(y)),d.set(d1(v),b)}let m=new Set([...i].filter(p=>o.has(p))),g=[...m];for(;g.length;)for(let p of d.get(g.pop())??[])m.has(p)||(m.add(p),g.push(p));return m};for(let d of c.steps){o.add(d1(d.part));for(let p of d.fasten??[]){let v=l.get(p);if(!v)return Q1(`Step ${d.id} names an unknown fastening.`);if(v.some(y=>!o.has(d1(y))))return Q1(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(p)}let m=new Set((t.holds?.find(p=>p.step===d.id)?.bodies??[]).map(d1));if([...m].some(p=>!o.has(p)))return Q1(`Step ${d.id} holds an uninstalled body.`);let g=f();if([...o].some(p=>!g.has(p)&&!m.has(p)))return Q1(`Step ${d.id} releases a component before it is retained or supported.`)}return[...o].some(d=>!f().has(d))?Q1("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function ul(t){let e=t.map(c=>{let a=Math.max(...c.map(Math.abs),1e-20);return c.map(s=>s/a)}),n=0,r=!1;for(let c=0;c<(e[0]?.length??0)&&n<e.length;c++){let a=n;for(let o=n+1;o<e.length;o++)Math.abs(e[o][c])>Math.abs(e[a][c])&&(a=o);let s=Math.abs(e[a][c]);if(s<1e-10)continue;s<1e-7&&(r=!0),[e[n],e[a]]=[e[a],e[n]];let i=e[n][c];for(let o=c;o<e[n].length;o++)e[n][o]/=i;for(let o=n+1;o<e.length;o++){let l=e[o][c];for(let h=c;h<e[o].length;h++)e[o][h]-=l*e[n][h]}n++}return{rank:n,uncertain:r}}function e9(t,e,n,r,c,a=[]){if(t.bodies.length>64)return l1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(d1),i=t.roots.map(d1);if(new Set(s).size!==s.length||new Set(i).size!==i.length||i.some(v=>!s.includes(v)))return Q1("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>i0(e,v).some((y,b)=>Math.abs(y-i0(n,v)[b])>j)))return Q1("A grounded kinematic root changes pose.");let o=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,y,b,x,M=1)=>{let w=s.indexOf(d1(y));if(w<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[w*6+b+k]+=M*x[k]};for(let v of t.roots)for(let y=0;y<6;y++){let b=h();b[s.indexOf(d1(v))*6+y]=1,o.push(b)}let f=he({...e,parts:e.parts.filter(v=>s.includes(d1({part:v.name,copy:v.copy})))});for(let v of c?.claims??[])if(v.kind==="retention")for(let y of v.links){let b=c.claims.find(x=>x.id===y.claim);y.installed&&y.fastening==="glued"&&b?.kind==="glue-contact"&&a.some(x=>x.id===b.id&&x.configurations.includes(e.configuration)&&x.status==="pass")&&f.push({a:b.a,b:b.b})}for(let v of f)if(!(!s.includes(d1(v.a))&&!s.includes(d1(v.b)))){if(!s.includes(d1(v.a))||!s.includes(d1(v.b)))return l1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let y=se({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:j*j*4},e);if(y.status!=="pass")return{...y,message:`A native glue/stack bond is not physically established: ${y.message}`}}}let d=[...t.joints,...f.filter(v=>s.includes(d1(v.a))&&s.includes(d1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(r.tick(),d1(v.a)===d1(v.b))return Q1("A joint cannot connect a body to itself.");let y=i0(e,v.a),b=i0(e,v.b),x=i0(n,v.a),M=i0(n,v.b),w=q1(p0(y),b),k=q1(p0(x),M),z=A=>{let L=h();u(L,v.b,3,A),u(L,v.a,3,A,-1),o.push(L)},S=(A,L,C)=>{let P=h();u(P,v.b,0,A),u(P,v.a,0,A,-1),u(P,v.b,3,V0(C,A)),u(P,v.a,3,V0(L,A),-1),o.push(P)};if(v.kind==="fixed"){if(w.some((A,L)=>Math.abs(A-k[L])>j))return Q1("A fixed joint changes its relative transform.");l.forEach(A=>z(A)),l.forEach(A=>S(A,b1(j0(b),j0(y)),[0,0,0]))}else if(v.kind==="revolute"){let A=f0(y,v.anchorA),L=f0(b,v.anchorB),C=W1(K0(y,v.axisA)),P=W1(K0(b,v.axisB)),R=K1(W1(K0(x,v.axisA)),W1(K0(M,v.axisB)));if(S1(b1(A,L))>j||S1(V0(C,P))>1e-7||Math.abs(K1(C,P)-R)>1e-7)return Q1("Revolute anchors or axes do not coincide.");if(v.range){let q=ue(w,k,v.axisB);if(!Zn(q,v.range,j).length)return Q1("A revolute joint exceeds its declared angular travel.",{angle:q})}l.forEach(q=>S(q,b1(A,j0(y)),b1(L,j0(b)))),rt(C).forEach(z)}else if(v.kind==="prismatic"){let A=b1(j0(w),j0(k)),L=W1(v.axisA),C=K1(A,L);if([0,1,2,4,5,6,8,9,10].some(P=>Math.abs(w[P]-k[P])>j)||S1(b1(A,L0(L,C)))>j)return Q1("A slider rotates or moves away from its guide axis.");if(C<v.travel[0]-j||C>v.travel[1]+j)return Q1("The slider exceeds its allowed travel.",{travel:C});l.forEach(z),rt(W1(K0(y,v.axisA))).forEach(P=>S(P,b1(j0(b),j0(y)),[0,0,0]))}else{let A=W1(K0(y,v.axisA)),L=W1(K0(b,v.axisB));if(S1(V0(A,L))>1e-7||S1(b1(j0(y),j0(x)))>j||S1(b1(j0(b),j0(M)))>j)return Q1("The scoped gear axes/centers are not fixed and parallel.");let C=ue(y,x,v.axisA),P=ue(b,M,v.axisB);if(Math.abs(C)>90||Math.abs(P)>90)return l1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(P+v.ratio*C)>1e-6)return Q1("The rendered gears do not obey their declared angular ratio.");let R=h();u(R,v.a,3,A,v.ratio),u(R,v.b,3,L),o.push(R)}}r.tick(o.length*s.length*6);let m=ul(o),g=s.length*6-m.rank;if(m.uncertain)return l1("Constraint rank is numerically singular.");let p={degreesOfFreedom:g,constraintRank:m.rank,redundantRows:o.length-m.rank};return g!==t.expectedDof?Q1("The joint graph has unintended freedom or is overconstrained.",p):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:p,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function t9(t,e,n,r){let c=o=>t.moving.find(l=>d1(l.body)===d1(o))?.trajectory??{kind:"translate",by:[0,0,0]},a=o=>o.kind==="translate"?S1(o.by)<1e-9:Math.abs(o.angle)<1e-9,s=(o,l)=>a(o)&&a(l)?!0:o.kind==="translate"&&l.kind==="translate"?S1(b1(o.by,l.by))<1e-9:o.kind==="rotate"&&l.kind==="rotate"?S1(b1(L0(W1(o.axis),o.angle),L0(W1(l.axis),l.angle)))<1e-9&&S1(V0(b1(o.origin,l.origin),W1(o.axis)))<1e-9:!1;if(e.roots.some(o=>!a(c(o))))return Q1("The analytic path moves a grounded joint root.");let i=new Map;for(let o of e.joints.filter(l=>l.kind!=="gear")){if(i.has(d1(o.b)))return l1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");i.set(d1(o.b),d1(o.a))}for(let o of i.keys()){let l=new Set,h=o;for(;h&&i.has(h);){if(l.has(h))return l1("Continuous closed-linkage constraints need a solver.");l.add(h),h=i.get(h)}}for(let o of e.joints){let l=c(o.a),h=c(o.b),u=i0(n,o.a),f=i0(n,o.b);if(o.kind==="fixed"){if(!s(l,h))return Q1("The analytic path separates a fixed joint.");continue}if(o.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return l1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=f0(u,o.anchorA),m=W1(K0(u,o.axisA)),g=W1(h.axis);if(S1(V0(m,g))>1e-9||S1(V0(b1(h.origin,d),m))>j)return Q1("The trajectory does not rotate about the actual hinge.");if(o.range){let p=q1(p0(u),f),v=q1(p0(i0(r,o.a)),i0(r,o.b)),y=h.angle*K1(W1(K0(f,o.axisB)),g),b=o.range;if(!Zn(ue(p,v,o.axisB),b,j).some(M=>Math.min(M,M+y)>=b[0]-j&&Math.max(M,M+y)<=b[1]+j))return Q1("The continuous hinge path exceeds its angular stops.")}}else if(o.kind==="prismatic"){if(s(l,h))continue;if(!a(l)||h.kind!=="translate")return l1("This slider trajectory composition needs a richer constraint solver.");let d=W1(K0(u,o.axisA));if(S1(V0(h.by,d))>j)return Q1("The analytic slider path leaves its guide.");let m=q1(p0(u),f),g=q1(p0(i0(r,o.a)),i0(r,o.b)),p=K1(b1(j0(m),j0(g)),W1(o.axisA)),v=p+K1(h.by,d);if(Math.min(p,v)<o.travel[0]-j||Math.max(p,v)>o.travel[1]+j)return Q1("The continuous slider path exceeds its travel stops.")}else{let d=(p,v,y)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let b=i0(n,p),x=W1(K0(b,y));return S1(V0(W1(v.axis),x))>1e-9||S1(V0(b1(v.origin,j0(b)),x))>j?null:v.angle*K1(W1(v.axis),x)},m=d(o.a,l,o.axisA),g=d(o.b,h,o.axisB);if(m===null||g===null)return l1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(g+o.ratio*m)>1e-7)return Q1("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function ct(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return n9(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(r=>{let c=n?.parts.filter(l=>l.name===r.name),a=c?.length===1?c[0]:void 0,s=a?.glue?.host,o=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((r.copy-1)/(a?.stack??1))+1:1;return{name:r.name,copy:r.copy,thickness:r.thickness,material:r.material??"",matrix:r.matrix,placed:r.placed,regions:a?.cutRegions??r.outline,bends:r.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:o},glueFace:a.glue.face},...a?.on&&{on:a.on}}}),hardware:t.hardware.map(r=>({label:r.label??null,kind:r.kind,from:r.from,to:r.to,size:r.size,up:r.up,...r.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(r=>r.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function n9(t){if(t&&typeof t=="object"){for(let e of Object.values(t))n9(e);Object.freeze(t)}return t}function at(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=G5({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(r.length)throw new Error(r[0].message);let c=new Map;for(let a of e){let s=a.body,i=d1(s);if(("part"in s?t.assembly.filter(l=>l.name===s.part&&l.copy===(s.copy??1)).length:t.hardware.filter(l=>l.label===s.hardware).length)!==1||c.has(i))throw new Error("Pose controls must identify one unique physical instance each.");c.set(i,C3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=c.get(d1({part:a.name,copy:a.copy}));return s?{...a,matrix:q1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},i=c.get(d1(s));return i?{...a,from:f0(i,a.from),to:f0(i,a.to),up:b1(f0(i,a.up),f0(i,[0,0,0]))}:a})}}function c9(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==j||G5(e).length||W6(n).length||n.some(c=>c.error!==void 0||!c.provenance)||!Array.isArray(t.inputs))return!1;let r=c=>JSON.stringify(c,(a,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.fromEntries(Object.keys(s).sort().map(i=>[i,s[i]])):s);try{let c=n.map(s=>({configuration:s.configuration,params:s.params,renderSettings:s.renderSettings,provenance:s.provenance})),a=s=>[...s].sort((i,o)=>i.configuration.localeCompare(o.configuration));return r(e)===r(t.specification)&&r(a(c))===r(a(t.inputs))}catch{return!1}}function a9(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let r=G5(t);if(r.length)return{kind:"invalid-spec",issues:r};let c=W6(e);if(c.length)return{kind:"invalid-snapshot",issues:c};let a=t,s=e,i=[];for(let[p,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(p)||!Number.isSafeInteger(v)||!(v>0))&&i.push({code:"invalid-limits",path:`limits.${p}`,message:"Verification limits must be positive safe integers."});if(i.length)return{kind:"invalid-spec",issues:i};let o={schemaVersion:1,model:a.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:j,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.map(p=>({configuration:p.configuration,params:p.params,renderSettings:p.renderSettings,provenance:p.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(s.reduce((p,v)=>p+v.hardware.reduce((y,b)=>y+(typeof b.size=="number"?128:8),0)+v.parts.reduce((y,b)=>y+b.regions.reduce((x,M)=>x+M.length,0)+(b.cutLines??[]).reduce((x,M)=>x+M.length,0),0),0)>(n.maxPoints??2e5)||a.claims.length>(n.maxClaims??1e3)||a.configurations.length>(n.maxConfigurations??100))return o.claims.push(i3("$resource-limit","resource-limit",!0,[],{status:"unverified",code:"resource-limit",message:"The verification input exceeds its point, claim or configuration budget. No mechanical conclusions were reached."})),{kind:"report",report:o};let h=new Set(a.configurations.map(p=>p.id));for(let p of s)h.has(p.configuration)||i.push({code:"unknown-configuration",message:`Snapshot ${p.configuration} is not declared.`});for(let p of s){let v=a.configurations.find(y=>y.id===p.configuration)?.params??{};for(let[y,b]of Object.entries(v))JSON.stringify(p.params[y])!==JSON.stringify(b)&&i.push({code:"configuration-mismatch",message:`${p.configuration}: captured parameter ${y} differs from its required value.`})}let u=new Map(a.claims.map(p=>[p.id,p]));for(let{claim:p,ref:v}of Fn(a)){let y=u.get(p);for(let b of s.filter(x=>x.error===void 0&&(!y.configurations||y.configurations.includes(x.configuration)))){let x="part"in v?b.parts.filter(M=>M.name===v.part&&M.copy===(v.copy??1)):b.hardware.filter(M=>M.label===v.hardware);x.length!==1&&i.push({code:"ambiguous-reference",path:`claims.${p}`,message:`${b.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(i.length)return{kind:"invalid-spec",issues:i};for(let p of a.configurations){let v=s.find(b=>b.configuration===p.id),y=v&&v.error===void 0;o.claims.push(i3(`$configuration:${p.id}`,"configuration",!0,[p.id],y?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),y&&(o.claims.push(i3(`$provenance:${p.id}`,"provenance",!0,[p.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&o.claims.push(i3(`$compiler:${p.id}`,"compiler-diagnostics",!0,[p.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
|
|
2723
|
-
`)})),v.legacyHardware&&
|
|
2724
|
-
`;let e=
|
|
2725
|
-
`;let n=c=>Array.isArray(c)?`${+c[0].toFixed(3)}..${+c[1].toFixed(3)}`:`${+c.toFixed(3)}`,r=[];for(let c of e){r.push(`${c.status} ${c.code} (${c.claims.length}): ${c.message}`);for(let a of c.claims){let s=Object.entries(a.measurements).slice(0,4).map(([i
|
|
3103
|
+
}`)}return c}function $l(t,e,n){let r;try{r=new o3({maxSteps:2e6}).run(e2(t.check).program).shape}catch{return!1}let c=r.layers.get("cut");if(!c)return!1;let a=g0([e.outline.poly],e.holes.map(l=>l.outline.poly)),s=s1(c.regions),o=n+t.round*16e-5;if(!P3(a,s,o))return!1;let i=e.lines.map(l=>C3(l));return!(i.length&&!P3(i,c.lines,o,!1))}var W=.001,Q1=(t,e)=>t.reduce((n,r,c)=>n+r*e[c],0),y1=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],P1=t=>Math.hypot(...t),c9=t=>[t[2],t[6],t[10]],u0=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]+t[n*4+3]),n6=(t,e)=>D1(v0(t.matrix),e.matrix);function E3(t){let[e,n]=t[0],r=0;for(let c=1;c<t.length-1;c++)r+=(t[c][0]-e)*(t[c+1][1]-n)-(t[c][1]-n)*(t[c+1][0]-e);return r/2}var l3=t=>Math.abs(t.reduce((e,n)=>e+E3(n),0)),r6=t=>t.reduce((e,n)=>e+n.reduce((r,c,a)=>r+Math.hypot(c[0]-n[(a+1)%n.length][0],c[1]-n[(a+1)%n.length][1]),0),0);function 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 a9=([t,e,n,r])=>[[t,e],[n,e],[n,r],[t,r]];function c6(t){if(t.length!==1)return!1;let e=h4(t);return l3(p3(t,[a9(e)]))<W*W}var a6=(t,e)=>K1(t,[a9(e)]);function s9(t,e,n=0){let r=e[0]*e[5]-e[1]*e[4]<0;return t.map(c=>{let a=c.map(([s,o])=>u0(e,[s,o,n]).slice(0,2));return r?a.reverse():a})}function Rl(t,e){let n=!1;for(let r=0,c=t.length-1;r<t.length;c=r++){let[a,s]=t[r],[o,i]=t[c];s>e[1]!=i>e[1]&&e[0]<(o-a)*(e[1]-s)/(i-s)+a&&(n=!n)}return n}function u5(t,e,n){let r=n[0]-e[0],c=n[1]-e[1],a=r*r+c*c,s=a?Math.max(0,Math.min(1,((t[0]-e[0])*r+(t[1]-e[1])*c)/a)):0;return Math.hypot(t[0]-e[0]-s*r,t[1]-e[1]-s*c)}function o9(t,e){let n=1/0;for(let r of t)for(let c=0;c<e.length;c++)n=Math.min(n,u5(r,e[c],e[(c+1)%e.length]));for(let r of e)for(let c=0;c<t.length;c++)n=Math.min(n,u5(r,t[c],t[(c+1)%t.length]));return n}var s6=(t,e)=>t.filter(n=>E3(n)<0&&Rl(n,e));function f5(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 i9(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 u4(t,e){return t.thickness===e.thickness&&t.material===e.material&&t.kerf===e.kerf&&n9(t.regions)===n9(e.regions)&&r9(t.cutLines)===r9(e.cutLines)}function n9(t){let e=n=>{let r=n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1]?n.slice(0,-1):n,c=[r,[...r].reverse()].map(a=>{let s=0;for(let o=1;o<a.length;o++)(a[o][0]<a[s][0]||a[o][0]===a[s][0]&&a[o][1]<a[s][1])&&(s=o);return JSON.stringify([...a.slice(s),...a.slice(0,s)])});return JSON.stringify([Math.sign(E3(n)),c.sort()[0]])};return JSON.stringify(t.map(e).sort())}function r9(t){return JSON.stringify(t.map(e=>{let n=JSON.stringify(e),r=JSON.stringify([...e].reverse());return n<r?n:r}).sort())}var B1=t=>!!t&&typeof t=="object"&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null),S0=t=>typeof t=="string"&&t.length>0,$2=t=>typeof t=="number"&&Number.isFinite(t),X2=t=>$2(t)&&t>=0,O2=t=>$2(t)&&t>0,T3=(t,e=0)=>Array.isArray(t)&&t.length===2&&t.every($2)&&t[0]>=e&&t[1]>=t[0]&&t[1]<=1e6,V3=(t,e)=>Array.isArray(t)&&t.length===e&&t.every($2),k2=t=>V3(t,3)&&t.every(e=>Math.abs(e)<=1e7),h3=t=>B1(t)&&S0(t.part)&&(t.copy===void 0||Number.isInteger(t.copy)&&t.copy>0)&&Object.keys(t).every(e=>["part","copy"].includes(e)),f4=t=>B1(t)&&S0(t.hardware)&&Object.keys(t).every(e=>e==="hardware"),d5=t=>h3(t)||f4(t),W2=t=>Array.isArray(t)&&t.every(d5),I3=t=>k2(t)&&Math.hypot(...t)>1e-9,Fl=t=>B1(t)&&(t.kind==="translate"&&k2(t.by)||t.kind==="rotate"&&k2(t.origin)&&I3(t.axis)&&$2(t.angle)&&Math.abs(t.angle)<=1e6),o6=t=>typeof t=="string"&&/^[a-f\d]{64}$/i.test(t),l9=t=>B1(t)&&Object.values(t).every(o6),u9=(t,e=0)=>e<32&&(t===void 0||typeof t=="boolean"||typeof t=="string"||$2(t)||Array.isArray(t)&&t.every(n=>u9(n,e+1))),i6=t=>B1(t)&&Object.values(t).every(e=>u9(e)),Dl=t=>t===null||B1(t)&&o6(t.sourceHash)&&o6(t.engineHash)&&l9(t.dependencies)&&l9(t.fonts);function ee(t){let e=[],n=(s,o)=>e.push({code:"invalid-spec",path:s,message:o});if(!B1(t))return[{code:"invalid-spec",message:"The specification must be an object."}];let r=(s,o,i)=>{for(let l of Object.keys(s))o.includes(l)||n(i?`${i}.${l}`:l,"Unknown specification field.")};r(t,["schemaVersion","model","configurations","materials","claims"],""),t.schemaVersion!==1&&n("schemaVersion","Expected verification schemaVersion 1."),S0(t.model)||n("model","Give the model a nonempty name.");let c=new Set,a=(s,o)=>{if(!B1(s)){n(o,"Materials must map material names to measured profiles.");return}for(let[i,l]of Object.entries(s))(!i||!B1(l)||!T3(l.thickness,Number.MIN_VALUE)||!T3(l.kerf)||l.edgeError!==void 0&&!X2(l.edgeError)||l.lot!==void 0&&!S0(l.lot))&&n(`${o}.${i}`,"A profile needs positive thickness bounds, kerf bounds and optional edgeError/lot."),B1(l)&&r(l,["thickness","kerf","edgeError","lot"],`${o}.${i}`)};if(!Array.isArray(t.configurations)||!t.configurations.length)n("configurations","Declare at least one supported configuration.");else for(let[s,o]of t.configurations.entries())!B1(o)||!S0(o.id)||o.params!==void 0&&!i6(o.params)?n(`configurations[${s}]`,"Expected a unique id and finite KerfScript parameter values."):c.has(o.id)?n(`configurations[${s}].id`,"Configuration ids must be unique."):(c.add(o.id),r(o,["id","params","materials"],`configurations[${s}]`),o.materials!==void 0&&a(o.materials,`configurations[${s}].materials`));if(t.materials!==void 0&&a(t.materials,"materials"),!Array.isArray(t.claims)||!t.claims.length)n("claims","Declare at least one required claim.");else{let s=new Set,o=0;for(let[l,h]of t.claims.entries()){let u=`claims[${l}]`;if(!B1(h)||!S0(h.id)||!S0(h.kind)){n(u,"Each claim needs an id and kind.");continue}let f={"rigid-clearance":["minimumGap","bodies"],"motion-clearance":["from","to","moving","minimumGap","maxIntervals","constraints"],"assembly-access":["initial","scope","steps","minimumGap","maxIntervals"],retention:["roots","links","removable"],"joint-constraints":["bodies","roots","joints","expectedDof"],stability:["supports","loads","ground","gravity","minimumMargin","retention"],"assembly-support":["plan","retention","holds"],"glue-contact":["a","b","faceA","faceB","minimumArea"],"tab-slot":["tab","receiver","region","clearance","flushTolerance","minimumLigament"],"captured-shaft":["shaft","bearings","stack","stops","clearance","endplay","minimumOverlap","maximumStopGap"]};switch(r(h,["id","kind","required","configurations",...Object.prototype.hasOwnProperty.call(f,h.kind)?f[h.kind]:[]],u),s.has(h.id)&&n(u+".id","Claim ids must be unique."),h.id.startsWith("$")&&n(u+".id","Claim ids beginning with $ are reserved for verifier diagnostics."),s.add(h.id),h.required!==void 0&&typeof h.required!="boolean"&&n(u+".required","Expected a boolean."),h.required!==!1&&o++,h.configurations!==void 0&&(!Array.isArray(h.configurations)||!h.configurations.length||new Set(h.configurations).size!==h.configurations.length||!h.configurations.every(p=>typeof p=="string"&&c.has(p)))&&n(u+".configurations","Reference unique declared configuration ids."),h.kind){case"glue-contact":(!h3(h.a)||!h3(h.b)||!["top","bottom"].includes(h.faceA)||!["top","bottom"].includes(h.faceB)||!O2(h.minimumArea))&&n(u,"Glue contact needs two part faces and a positive minimumArea.");break;case"tab-slot":(!h3(h.tab)||!h3(h.receiver)||!V3(h.region,4)||h.region.some(p=>Math.abs(p)>1e6)||h.region[0]>=h.region[2]||h.region[1]>=h.region[3]||!T3(h.clearance)||!X2(h.flushTolerance)||!X2(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(!f4(h.shaft)||!Array.isArray(h.bearings)||h.bearings.length!==2||!h.bearings.every(h3)||!Array.isArray(h.stack)||!h.stack.length||!h.stack.every(h3)||!T3(h.clearance)||!T3(h.endplay)||!O2(h.minimumOverlap)||!X2(h.maximumStopGap)||!Array.isArray(p)||p.length!==2){n(u,"Captured shaft needs two bearings, a stack, two stops, fit/endplay bounds and overlap/gap limits.");break}for(let m of p){if(!B1(m)||!f4(m.body)||!B1(m.attachment)){n(u+".stops","Each stop needs a hardware body and attachment.");continue}r(m,["body","attachment"],u+".stops");let g=m.attachment;r(g,g.kind==="threaded"?["kind","thread","minimumEngagement","secured"]:["kind"],u+".stops.attachment"),(!["integral","threaded","unknown"].includes(g.kind)||g.kind==="threaded"&&(!f4(g.thread)||!O2(g.minimumEngagement)||typeof g.secured!="boolean"))&&n(u+".stops","Threaded stops need a thread envelope, positive minimum engagement and a secured flag.")}break}case"cut-invariant":case"material-assignment":case"strength":break;case"rigid-clearance":(!X2(h.minimumGap)||h.bodies!==void 0&&(!W2(h.bodies)||!h.bodies.length))&&n(u,"Clearance requires a nonnegative gap and an optional nonempty body scope.");break;case"motion-clearance":(!S0(h.from)||!c.has(h.from)||!S0(h.to)||!c.has(h.to)||h.from===h.to||!X2(h.minimumGap)||!Array.isArray(h.moving)||!h.moving.length||!h.moving.every(p=>B1(p)&&d5(p.body)&&Fl(p.trajectory)))&&n(u,"Motion needs from/to configuration ids, moving body trajectories and a nonnegative minimumGap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000."),h.constraints!==void 0&&!S0(h.constraints)&&n(u,"constraints must reference an ideal joint claim.");break;case"assembly-access":(!W2(h.initial)||h.initial.length>1||h.scope!==void 0&&(!W2(h.scope)||!h.scope.length)||!X2(h.minimumGap)||!Array.isArray(h.steps)||!h.steps.length||!h.steps.every(p=>B1(p)&&S0(p.id)&&d5(p.part)&&k2(p.from)&&typeof p.held=="boolean"&&(p.fasten===void 0||Array.isArray(p.fasten)&&p.fasten.every(S0))&&(p.tool===void 0||B1(p.tool)&&k2(p.tool.from)&&k2(p.tool.to)&&O2(p.tool.diameter)&&p.tool.diameter<=1e6&&k2(p.tool.travel))))&&n(u,"Assembly needs zero or one initial body, insertion steps with part/from/held, and a nonnegative gap."),h.maxIntervals!==void 0&&(!Number.isSafeInteger(h.maxIntervals)||h.maxIntervals<1||h.maxIntervals>1e4)&&n(u,"maxIntervals must be 1 to 10000.");break;case"retention":(!W2(h.roots)||!h.roots.length||h.removable!==void 0&&!W2(h.removable)||!Array.isArray(h.links)||!h.links.every(p=>B1(p)&&S0(p.claim)&&["glued","locked","captured"].includes(p.fastening)&&typeof p.installed=="boolean"))&&n(u,"Retention needs roots and links to measured joint claims with fastening/installed.");break;case"joint-constraints":(!W2(h.bodies)||!h.bodies.length||!W2(h.roots)||!h.roots.length||!Number.isSafeInteger(h.expectedDof)||h.expectedDof<0||!Array.isArray(h.joints)||!h.joints.every(p=>B1(p)&&d5(p.a)&&d5(p.b)&&(p.kind==="fixed"||p.kind==="revolute"&&k2(p.anchorA)&&k2(p.anchorB)&&I3(p.axisA)&&I3(p.axisB)&&(p.range===void 0||T3(p.range,-1e6))||p.kind==="prismatic"&&I3(p.axisA)&&T3(p.travel,-1e6)||p.kind==="gear"&&I3(p.axisA)&&I3(p.axisB)&&O2(p.ratio)&&p.ratio<=1e6)))&&n(u,"Joint constraints need a body scope, roots, expectedDof and fixed/revolute/prismatic/gear relations.");break;case"stability":(!W2(h.supports)||!h.supports.length||!Array.isArray(h.loads)||!h.loads.length||!$2(h.ground)||Math.abs(h.ground)>1e7||!I3(h.gravity)||h.gravity[2]>=0||!X2(h.minimumMargin)||!h.loads.every(p=>B1(p)&&d5(p.body)&&O2(p.mass)&&(p.center===void 0||k2(p.center))))&&n(u,"Stability needs ground supports, positive masses, downward gravity and a nonnegative margin.");break;case"assembly-support":(!S0(h.plan)||!S0(h.retention)||h.holds!==void 0&&(!Array.isArray(h.holds)||!h.holds.every(p=>B1(p)&&S0(p.step)&&W2(p.bodies))))&&n(u,"Assembly support references a plan and retention contract, with optional per-step held bodies.");break;default:n(u+".kind",`Unknown claim kind ${String(h.kind)}.`)}let d=(p,m,g)=>{B1(p)&&r(p,m,g)};if(h.kind==="motion-clearance"&&Array.isArray(h.moving))for(let[p,m]of h.moving.entries())B1(m)&&(d(m,["body","trajectory"],`${u}.moving[${p}]`),d(m.trajectory,B1(m.trajectory)&&m.trajectory.kind==="translate"?["kind","by"]:["kind","origin","axis","angle"],`${u}.moving[${p}].trajectory`));if(h.kind==="assembly-access"&&Array.isArray(h.steps))for(let[p,m]of h.steps.entries())B1(m)&&(d(m,["id","part","from","held","fasten","tool"],`${u}.steps[${p}]`),d(m.tool,["from","to","diameter","travel"],`${u}.steps[${p}].tool`));if(h.kind==="joint-constraints"&&Array.isArray(h.joints))for(let[p,m]of h.joints.entries())B1(m)&&d(m,["kind","a","b",...m.kind==="revolute"?["anchorA","anchorB","axisA","axisB","range"]:m.kind==="prismatic"?["axisA","travel"]:m.kind==="gear"?["axisA","axisB","ratio"]:[]],`${u}.joints[${p}]`);h.kind==="retention"&&Array.isArray(h.links)&&h.links.forEach((p,m)=>d(p,["claim","fastening","installed"],`${u}.links[${m}]`)),h.kind==="stability"&&Array.isArray(h.loads)&&h.loads.forEach((p,m)=>d(p,["body","mass","center"],`${u}.loads[${m}]`)),h.kind==="assembly-support"&&Array.isArray(h.holds)&&h.holds.forEach((p,m)=>d(p,["step","bodies"],`${u}.holds[${m}]`))}o||n("claims","At least one claim must be required.");let i=t.claims.filter(B1);for(let l of i){let h=(u,f)=>i.some(d=>d.id===u&&d.kind===f);if(l.kind==="motion-clearance"&&l.constraints!==void 0&&!h(l.constraints,"joint-constraints")&&n(`claims.${String(l.id)}.constraints`,"Reference a declared joint-constraints claim."),l.kind==="assembly-support"&&(!h(l.plan,"assembly-access")||!h(l.retention,"retention"))&&n(`claims.${String(l.id)}`,"Support requires declared assembly-access and retention claims."),l.kind==="assembly-support"){let u=i.find(m=>m.id===l.plan&&m.kind==="assembly-access"),f=i.find(m=>m.id===l.retention&&m.kind==="retention"),d=new Set((Array.isArray(u?.steps)?u.steps:[]).filter(B1).map(m=>m.id)),p=new Set((Array.isArray(f?.links)?f.links:[]).filter(B1).map(m=>m.claim));if(Array.isArray(l.holds))for(let m of l.holds)B1(m)&&!d.has(m.step)&&n(`claims.${String(l.id)}.holds`,`Step ${String(m.step)} is not in the plan.`);if(u&&f&&Array.isArray(u.steps)){for(let m of u.steps)if(B1(m)&&Array.isArray(m.fasten))for(let g of m.fasten)p.has(g)||n(`claims.${String(u.id)}.steps`,`Step ${String(m.id)} fastens ${String(g)}, which is not a link of ${String(f.id)}.`)}}if(l.kind==="cut-invariant"&&(Array.isArray(l.configurations)?l.configurations.length:Array.isArray(t.configurations)?t.configurations.length:0)<2&&n(`claims.${String(l.id)}`,"cut-invariant needs at least two configurations."),l.kind==="motion-clearance"&&Array.isArray(l.moving)){let u=new Set;for(let f of l.moving)if(B1(f)){let d=B1(f.body)?f.body:{},p=JSON.stringify([d.part??null,d.hardware??null,d.copy??1]);u.has(p)&&n(`claims.${String(l.id)}.moving`,"A body is given two trajectories."),u.add(p)}}if(l.kind==="stability"&&l.retention!==void 0&&!h(l.retention,"retention")&&n(`claims.${String(l.id)}.retention`,"Reference a declared retention claim."),l.kind==="retention"&&Array.isArray(l.links))for(let u of l.links)B1(u)&&!i.some(f=>f.id===u.claim&&["glue-contact","tab-slot","captured-shaft"].includes(f.kind))&&n(`claims.${String(l.id)}.links`,"Reference a declared geometric attachment contract.")}}return e}function l6(t){let e=[],n=(c,a)=>e.push({code:"invalid-snapshot",path:c,message:a});if(!Array.isArray(t))return[{code:"invalid-snapshot",message:"Snapshots must be an array."}];let r=new Set;for(let[c,a]of t.entries()){let s=`snapshots[${c}]`;if(!B1(a)||a.schemaVersion!==1||!S0(a.configuration)||!i6(a.params)||!i6(a.renderSettings)||!Dl(a.provenance)||!Array.isArray(a.parts)||!Array.isArray(a.hardware)||!Array.isArray(a.warnings)||!a.warnings.every(i=>typeof i=="string")||typeof a.legacyHardware!="boolean"||typeof a.relationsKnown!="boolean"||a.error!==void 0&&typeof a.error!="string"){n(s,"Malformed snapshot, configuration, provenance or inventory.");continue}r.has(a.configuration)&&n(s,"Configuration snapshots must be unique."),r.add(a.configuration);let o=new Set;for(let[i,l]of a.parts.entries()){if(!B1(l)||!S0(l.name)||!Number.isInteger(l.copy)||l.copy<1||!O2(l.thickness)||l.glue!==void 0&&(!h3(l.glue)||!["top","bottom"].includes(l.glueFace))||l.stack!==void 0&&(!Number.isSafeInteger(l.stack)||l.stack<1)||l.on!==void 0&&!S0(l.on)||l.thickness>1e6||typeof l.material!="string"||l.kerf!==null&&(!X2(l.kerf)||l.kerf>1e6)||!ql(l.matrix)||typeof l.placed!="boolean"||!h9(l.regions,3)||!Array.isArray(l.regions)||!l.regions.length||l.cutLines!==null&&!h9(l.cutLines,2)||!Array.isArray(l.bends)||!l.bends.every(u=>B1(u)&&$2(u.x0)&&$2(u.x1)&&u.x1>u.x0&&$2(u.angle))){n(`${s}.parts[${i}]`,"Malformed part geometry, rigid transform, material or cutting metadata.");continue}let h=JSON.stringify([l.name,l.copy]);o.has(h)&&n(`${s}.parts[${i}]`,"Part name/copy references must be unique; separate definitions cannot share that reference."),o.add(h)}for(let[i,l]of a.hardware.entries())(!B1(l)||l.label!==null&&!S0(l.label)||typeof l.kind!="string"||!V3(l.from,3)||!V3(l.to,3)||[...l.from,...l.to].some(h=>Math.abs(h)>1e7)||!k2(l.up)||l.shape!==void 0&&(l.shape!=="ball"||!O2(l.size))||!(O2(l.size)&&l.size<=1e6||V3(l.size,2)&&l.size.every(h=>O2(h)&&h<=1e6)))&&n(`${s}.hardware[${i}]`,"Malformed hardware geometry or label.")}return e}function h9(t,e){return Array.isArray(t)&&t.every(n=>Array.isArray(n)&&n.length>=e&&n.every(r=>V3(r,2)&&r.every(c=>Math.abs(c)<=1e6)))}function ql(t){if(!V3(t,16))return!1;let e=t,n=1e-6;if([e[3],e[7],e[11]].some(r=>Math.abs(r)>1e7)||Math.abs(e[12])+Math.abs(e[13])+Math.abs(e[14])+Math.abs(e[15]-1)>n)return!1;for(let r=0;r<3;r++)for(let c=0;c<3;c++){let a=e[r]*e[c]+e[4+r]*e[4+c]+e[8+r]*e[8+c];if(Math.abs(a-(r===c?1:0))>n)return!1}return Math.abs(e[0]*(e[5]*e[10]-e[6]*e[9])-e[1]*(e[4]*e[10]-e[6]*e[8])+e[2]*(e[4]*e[9]-e[5]*e[8])-1)<n}function f9(t){let e=[];for(let n of t.claims){let r=c=>e.push({claim:n.id,ref:c});n.kind==="glue-contact"&&(r(n.a),r(n.b)),n.kind==="tab-slot"&&(r(n.tab),r(n.receiver)),n.kind==="captured-shaft"&&(r(n.shaft),n.bearings.forEach(r),n.stack.forEach(r),n.stops.forEach(c=>{r(c.body),c.attachment.kind==="threaded"&&r(c.attachment.thread)})),n.kind==="rigid-clearance"&&n.bodies?.forEach(r),n.kind==="motion-clearance"&&n.moving.forEach(c=>r(c.body)),n.kind==="assembly-access"&&(n.initial.forEach(r),n.scope?.forEach(r),n.steps.forEach(c=>r(c.part))),n.kind==="retention"&&(n.roots.forEach(r),n.removable?.forEach(r)),n.kind==="joint-constraints"&&(n.bodies.forEach(r),n.roots.forEach(r),n.joints.forEach(c=>{r(c.a),r(c.b)})),n.kind==="stability"&&(n.supports.forEach(r),n.loads.forEach(c=>r(c.body))),n.kind==="assembly-support"&&n.holds?.forEach(c=>c.bodies.forEach(r))}return e}var o2=(t,e)=>t.parts.find(n=>n.name===e.part&&n.copy===(e.copy??1)),R2=(t,e)=>t.hardware.find(n=>n.label===e.hardware);var e0=(t,e={})=>({status:"fail",code:"joint-condition-failed",message:t,measurements:e}),l1=t=>({status:"unverified",code:"unsupported-evidence",message:t}),m6=(t,e,n=[],r="nominal")=>({status:"pass",code:"conditions-satisfied",message:t,measurements:e,assumptions:n,coverage:r}),re=(t,e)=>t.materials&&Object.prototype.hasOwnProperty.call(t.materials,e.material)?t.materials[e.material]:void 0,ne=(t,e)=>re(t,e)?.thickness??[e.thickness,e.thickness];function m5(t,e){let n=re(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 f6=(t,e)=>t[0]>=e[0]+W&&t[1]<=e[1]-W,d6=(t,e)=>t[0]<e[0]-W||t[1]>e[1]+W,p6=(...t)=>t.map(f5).find(Boolean);function m4(t,e){let n=o2(e,t.a),r=o2(e,t.b);if(n===r)return e0("A glue contact needs two different physical instances.");let c=p6(n,r);if(c)return l1(c);let a=n6(n,r),s=t.faceA==="top"?n.thickness:0,o=t.faceB==="top"?r.thickness:0;if(Math.hypot(a[8],a[9])>1e-9)return e0("The selected faces are not parallel.");let i=Math.abs(a[11]+a[10]*o-s);if(i>W)return e0("The selected faces are separated.",{faceGap:i});if(i>1e-7)return l1("Face separation is within numerical uncertainty; exact contact is not established.");let l=t.faceA==="top"?1:-1,h=t.faceB==="top"?1:-1;if(l*h*a[10]>-1+1e-7)return e0("The selected surfaces face the same way, rather than meeting.");let u=s9(r.regions,a,o),f=l3(K1(n.regions,u)),d=W*(r6(n.regions)+r6(u)),p={contactArea:f,requiredArea:t.minimumArea,faceGap:i,areaUncertainty:d};return f<t.minimumArea-d?e0("There is insufficient geometric glue contact.",p):f<t.minimumArea+d?{...l1("Contact area is on the numerical acceptance boundary."),measurements:p}:m6("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 d9(t,e,n){let r=o2(e,t.tab),c=o2(e,t.receiver);if(r===c)return e0("A tongue and its receiving panel must be different instances.");let a=p6(r,c);if(a)return l1(a);let s=n6(c,r);if(!i9(s)||Math.abs(s[10])>W)return l1("Only orthogonal tab/slot geometry is supported.");let o=a6(r.regions,t.region);if(!c6(o))return l1("The selected tongue is not one solid rectangle.");let[i,l,h,u]=h4(o),f=4*W,d=W,m=[[i-f,l+d,i,u-d],[h,l+d,h+f,u-d],[i+d,l-f,h-d,l],[i+d,u,h-d,u+f]].map(P=>l3(a6(r.regions,P))>W*W).flatMap((P,F)=>P?[F]:[]);if(m.length>1)return l1("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 l1("The tongue must join its parent along the insertion direction.");let g;if(m.length){let P=m[0],F=P<2?[P===0?i:h,(l+u)/2,0]:[(i+h)/2,P===2?l:u,0],j=u0(s,F)[2],_=(P<2?s[8]:s[9])*(P%2===0?-1:1);g={z:j,outward:_}}let v=[];for(let P of[i,h])for(let F of[l,u])for(let j of[0,r.thickness])v.push(u0(s,[P,F,j]));let b=[0,1,2].map(P=>Math.min(...v.map(F=>F[P]))),y=[0,1,2].map(P=>Math.max(...v.map(F=>F[P]))),x=s6(c.regions,[(b[0]+y[0])/2,(b[1]+y[1])/2]);if(!x.length)return e0("The receiving panel has no closed slot at the tongue.");if(x.length!==1||!c6([x[0]]))return l1("The receiving feature must be an unambiguous rectangular closed slot.");let w=x[0],M=h4([w]),k=m5(n,r),z=m5(n,c);if(![...k,...z].every(Number.isFinite))return l1("Compensated kerf metadata is needed for manufacturing bounds.");let A={},S=!1;for(let P=0;P<2;P++){let F=Math.abs(s[P*4+2])>.5,j=F?ne(n,r):[y[P]-b[P]+k[0],y[P]-b[P]+k[1]],_=M[P+2]-M[P],Q=[_-z[1]-j[1],_-z[0]-j[0]];if(A[P?"clearanceY":"clearanceX"]=Q,d6(Q,t.clearance))return e0("Tab/slot clearance is outside the required range.",A);S||(S=!f6(Q,t.clearance));let H=b[P],B=y[P];F?s[P*4+2]>0?B+=j[1]-r.thickness:H-=j[1]-r.thickness:(H-=Math.max(0,k[1])/2,B+=Math.max(0,k[1])/2);let Y=Math.min(H-M[P],M[P+2]-B)-Math.max(0,z[1])/2;if(A[P?"minimumSideGapY":"minimumSideGapX"]=Y,Y<-W)return e0("The tongue is offset into the edge of its slot.",A);Y<W&&(S=!0)}let C=Math.max(0,-k[0])/2,I=ne(n,c);if(t.flushTolerance>=I[0]-W)return l1("flushTolerance must be smaller than the receiving thickness.");let L=Math.max(0,Math.min(y[2]-C,I[1])-Math.max(b[2]+C,0)),T=I[1]-t.flushTolerance;if(A.engagement=L,A.requiredEngagement=T,L<=W)return e0("The tongue does not engage the receiving panel.",A);if(L<T-W)return e0("The tongue does not engage through the receiving panel.",A);if(L<T+W&&(S=!0),g&&(g.outward>0&&g.z<I[1]-W||g.outward<0&&g.z>W))return e0("The tongue shoulder intrudes into the receiving panel under the declared thickness bounds.",A);let q=Math.min(...c.regions.filter(P=>P!==w).map(P=>o9(w,P)))-Math.max(0,-z[0]);return A.minimumLigament=q,q<t.minimumLigament-W?e0("Too little material remains around the slot.",A):(q<t.minimumLigament+W&&(S=!0),S?{...l1("A fit condition is on its numerical acceptance boundary."),measurements:A}:m6("The rectangular tongue fits and engages its receiving slot.",A,["Rigid orthogonal parts; nominal placements are held fixed while finished dimensions vary.","The selected local rectangle must identify the physical tongue; this fit does not establish retention."],re(n,r)||re(n,c)?"bounded-fit":"nominal"))}function te(t){let e=y1(t.to,t.from),n=P1(e);return typeof t.size=="number"&&n>W?{start:t.from,dir:e.map(r=>r/n),length:n,diameter:t.size}:null}function h6(t,e){let n=te(e);if(!n||P1([t.dir[1]*n.dir[2]-t.dir[2]*n.dir[1],t.dir[2]*n.dir[0]-t.dir[0]*n.dir[2],t.dir[0]*n.dir[1]-t.dir[1]*n.dir[0]])>1e-9)return!1;let r=y1(n.start,t.start),c=Q1(r,t.dir);return P1(r.map((a,s)=>a-c*t.dir[s]))<W}var d4=(t,e)=>Q1(y1(e,t.start),t.dir),u6=(t,e)=>[d4(t,e.from),d4(t,e.to)].sort((n,r)=>n-r);function Nl(t,e){let n=c9(e.matrix);if(Q1(n,t.dir)<0||P1([n[1]*t.dir[2]-n[2]*t.dir[1],n[2]*t.dir[0]-n[0]*t.dir[2],n[0]*t.dir[1]-n[1]*t.dir[0]])>1e-9)return"Bearing and stack faces have an unsupported orientation; their normals must follow the shaft.";let r=u0(v0(e.matrix),t.start),c=[r[0],r[1]],a=s6(e.regions,c);if(!a.length)return"No bore surrounds the shaft axis.";if(a.length!==1)return"The bore selector is ambiguous.";let s=a[0],o=s.length>1&&s[0][0]===s[s.length-1][0]&&s[0][1]===s[s.length-1][1]?s.slice(0,-1):s,i=[o.reduce((m,g)=>m+g[0],0)/o.length,o.reduce((m,g)=>m+g[1],0)/o.length];if(Math.hypot(i[0]-c[0],i[1]-c[1])>W)return"The shaft is not centered in the bore.";let l=s.map(m=>Math.hypot(m[0]-i[0],m[1]-i[1]));if(Math.max(...l)-Math.min(...l)>W)return"The bore is not a supported circular polygon.";let h=Math.min(...s.map((m,g)=>u5(c,m,s[(g+1)%s.length]))),u=Math.max(...s.map(m=>Math.hypot(m[0]-c[0],m[1]-c[1]))),f=d4(t,u0(e.matrix,[0,0,0])),d=d4(t,u0(e.matrix,[0,0,e.thickness])),p=Math.max(...e.regions.flatMap(m=>m.map(g=>Math.hypot(g[0]-c[0],g[1]-c[1]))));return{part:e,lo:Math.min(f,d),hi:Math.max(f,d),hole:[2*h,2*u],reach:p}}function m9(t,e,n){let r=R2(e,t.shaft),c=te(r);if(!c)return l1("The shaft must have a nonzero cylindrical physical envelope.");let a=[...t.bearings,...t.stack],s=a.map(M=>JSON.stringify([M.part,M.copy??1]));if(new Set(s).size!==s.length)return e0("Bearing and stack references must name distinct physical parts.");let o=a.map(M=>o2(e,M)),i=p6(...o);if(i)return l1(i);let l={shaftDiameter:c.diameter},h=[],u=!1;for(let M=0;M<o.length;M++){let k=o[M],z=Nl(c,k);if(typeof z=="string")return/unsupported|supported/.test(z)?l1(`${k.name}: ${z}`):e0(`${k.name}: ${z}`);let A=m5(n,k);if(!A.every(Number.isFinite))return l1("Kerf metadata is required for bore tolerance bounds.");let S=[z.hole[0]-A[1]-c.diameter,z.hole[1]-A[0]-c.diameter];if(l[`clearance${M+1}`]=S,d6(S,t.clearance))return e0(`${k.name}: shaft/bore clearance is outside the required range.`,l);if(u||(u=!f6(S,t.clearance)),z.lo<-W||z.lo+ne(n,k)[1]>c.length+W)return e0(`${k.name}: the shaft does not extend through this part.`,l);h.push(z)}let f=h.slice(0,2).sort((M,k)=>M.lo-k.lo),d=h.slice(2).sort((M,k)=>M.lo-k.lo);if(f.some(M=>ne(n,M.part).some(k=>Math.abs(k-M.part.thickness)>W)))return l1("Bearing thickness variation changes retainer seating. A bounded axial seating model is required for capture.");if(f[0].hi>f[1].lo-W)return e0("Bearing panels overlap or leave no stack cavity.");for(let M=0;M<d.length;M++)if(d[M].lo<f[0].hi-W||d[M].hi>f[1].lo+W||M&&d[M-1].hi>d[M].lo+W)return e0("The axial stack overlaps another component or its supports.");let p=f[1].lo-f[0].lo,g=[f[0].part,...d.map(M=>M.part)].map(M=>ne(n,M)).reduce((M,k)=>[M[0]+k[0],M[1]+k[1]],[0,0]),v=[p-g[1],p-g[0]];if(l.endplay=v,d6(v,t.endplay))return e0("The axial stack has insufficient or excessive endplay.",l);u||(u=!f6(v,t.endplay));let b=["Ideal cylindrical hardware at its declared dimensions. Hardware diameter/length variation, strength and loosening are not established."],y=t.stops.map(M=>({stop:M,h:R2(e,M.body)})).map(M=>({...M,at:M.h&&h6(c,M.h)?u6(c,M.h):void 0}));if(y.some(M=>!M.at))return e0("A retainer is not coaxial with the shaft.");y.sort((M,k)=>M.at[0]+M.at[1]-(k.at[0]+k.at[1]));let x=M=>M.hole[1]-m5(n,M.part)[0],w=M=>2*M.reach+m5(n,M.part)[0];for(let M=0;M<2;M++){let k=Math.max(w(f[M]),te(y[M].h)?.diameter??0),z=M===0?d.map((S,C)=>C):d.map((S,C)=>d.length-1-C),A=[];for(let S=0;S<z.length;S++){let C=d[z[S]],I=x(C),L=z.slice(0,S).map((F,j)=>({b:d[F],gone:A[j]})),T=F=>I>F+W,q=F=>Math.abs(I-F)<=W,P=T(k)&&L.every(F=>F.gone||T(w(F.b)));if(A.push(P),P)return e0(`${C.part.name} can slide off over ${f[M].part.name} and its retainer: its bore is wider than all that holds it on that side.`,l);(q(k)||L.some(F=>!F.gone&&q(w(F.b))))&&(u=!0)}}for(let M=0;M<2;M++){let{stop:k,h:z}=y[M];if(!h6(c,z))return e0("A retainer is not coaxial with the shaft.");let A=te(z),S=u6(c,z),C=f[M],I=M===0?S[1]:S[0],L=M===0?C.lo:C.hi,T=M===0?L-I:I-L;l[`stopGap${M+1}`]=T;let q=m5(n,C.part),P=(A.diameter-(C.hole[1]-q[0]))/2;if(l[`stopOverlap${M+1}`]=P,T<-W||T>t.maximumStopGap+W)return e0("A retainer is misplaced relative to the outside bearing face.",l);if((T<-1e-7||T>t.maximumStopGap+1e-7)&&(u=!0),P<t.minimumOverlap-W)return e0("A retainer can pass through its bearing opening.",l);P<t.minimumOverlap+W&&(u=!0);let F=k.attachment;if(F.kind==="unknown")return{...l1("The stop is present but its fastening is unverified."),measurements:l};if(F.kind==="integral"){if(Math.min(Math.abs(I),Math.abs(I-c.length))>W)return e0("An integral head must meet an end of its shaft.",l);b.push("The specified head and shaft are one integral purchased component.")}else{let j=R2(e,F.thread);if(!h6(c,j))return e0("The threaded attachment is off the shaft axis.");if(te(j).diameter>c.diameter+W)return e0("The declared threaded section exceeds the shaft envelope.");let _=u6(c,j),Q=Math.max(0,Math.min(S[1],_[1])-Math.max(S[0],_[0]));if(_[0]<-W||_[1]>c.length+W)return e0("The usable threaded section lies outside the physical shaft.",l);if(l.threadEngagement=Q,Q<F.minimumEngagement-W)return e0("The threaded stop has insufficient declared thread engagement.",l);if(Q<F.minimumEngagement+W&&(u=!0),!F.secured)return{...l1("Thread overlap exists but installation/securement of the retainer is unverified."),measurements:l};b.push("The specified usable thread envelope and matching nut are installed and secured as declared; thread form/capacity and resistance to loosening are not verified.")}}return u?{...l1("A shaft condition is on its numerical acceptance boundary."),measurements:l}:m6("The declared shaft has local bearing clearance, axial endplay and geometric end capture.",l,b,o.some(M=>re(n,M))?"bounded-fit":"nominal")}var p4=class{constructor(e=2e6){this.remaining=e}tick(e=1){if(this.remaining-=e,this.remaining<0)throw new Error("Verification operation budget exhausted.")}},f1=t=>"part"in t?JSON.stringify(["part",t.part,t.copy??1]):JSON.stringify(["hardware",t.hardware]),H0=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],A0=(t,e)=>t.map(n=>n*e),v9=(t,e)=>t.map((n,r)=>n+e[r]),W1=t=>A0(t,1/P1(t)),y9=()=>j0(0,0,0);function g6(t,e){let n=r=>r.kind==="translate"?P1(r.by)<1e-9:Math.abs(r.angle)<1e-9;return n(t)&&n(e)?!0:t.kind==="translate"&&e.kind==="translate"?P1(y1(t.by,e.by))<1e-9:t.kind==="rotate"&&e.kind==="rotate"?P1(y1(A0(W1(t.axis),t.angle),A0(W1(e.axis),e.angle)))<1e-9&&P1(H0(y1(t.origin,e.origin),W1(t.axis)))<1e-9:!1}function Ul(t,e){let n=new Map;for(let r of e)for(let c=0;c<r.length;c++){let a=r[c],s=r[(c+1)%r.length],o=a<s?[a,s]:[s,a];n.set(o.join(","),o)}return{vertices:t,faces:e,edges:[...n.values()]}}function p5(t,e,n){let r=t.length,c=[];for(let a of[0,e])for(let[s,o]of t)c.push(u0(n,[s,o,a]));return Ul(c,[t.map((a,s)=>s).reverse(),t.map((a,s)=>r+s),...t.map((a,s)=>[s,(s+1)%r,(s+1)%r+r,s+r])])}function Bl(t,e){let n=s1(t),r=[...new Set(n.flat().map(o=>o[0]))].sort((o,i)=>o-i),c=n.flatMap(o=>o.map((i,l)=>({a:i,b:o[(l+1)%o.length]}))),a=[],s=(o,i)=>o.a[1]+(i-o.a[0])*(o.b[1]-o.a[1])/(o.b[0]-o.a[0]);for(let o=1;o<r.length;o++){let i=r[o-1],l=r[o],h=(i+l)/2;e.tick(c.length);let u=c.filter(f=>Math.min(f.a[0],f.b[0])<h&&Math.max(f.a[0],f.b[0])>h).sort((f,d)=>s(f,h)-s(d,h));if(u.length%2)throw new Error("Cut boundaries do not define closed slab intervals.");for(let f=0;f<u.length;f+=2){let d=u[f],p=u[f+1],m=[[i,s(d,i)],[l,s(d,l)],[l,s(p,l)],[i,s(p,i)]],g=m.filter((v,b)=>P1([v[0]-m[(b+1)%m.length][0],v[1]-m[(b+1)%m.length][1],0])>1e-10);if(g.length<3||Math.abs(E3(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(l3(a)-l3(n))>W*W*Math.max(1,l3(n)))throw new Error("Rigid decomposition did not preserve material area.");return a}function H3(t){if(t.hardware.some(n=>!n.label))throw new Error("Physical hardware needs unique labels for whole-inventory checks.");let e=[...t.parts.map(n=>({part:n.name,copy:n.copy})),...t.hardware.map(n=>({hardware:n.label}))];if(new Set(e.map(f1)).size!==e.length)throw new Error("Physical inventory has ambiguous identities.");return e}function ce(t){if(t.shape!=="ball"||typeof t.size!="number")return[t.from,t.to];let e=t.size/2;return[[t.from[0],t.from[1],t.from[2]-e],[t.from[0],t.from[1],t.from[2]+e]]}function o0(t,e){if("part"in e)return o2(t,e).matrix;let n=R2(t,e),[r,c]=ce(n),a={...n,from:r,to:c},s=W1(y1(a.to,a.from));if(!P1(y1(a.to,a.from)))throw new Error("Zero-length hardware needs an explicit physical shape.");let o=y1(a.up,A0(s,Q1(a.up,s)));if(P1(o)<1e-9){if(Array.isArray(a.size))throw new Error("A rectangular hardware envelope needs an unambiguous up direction.");let l=Math.abs(s[0])<.8?[1,0,0]:[0,1,0];o=y1(l,A0(s,Q1(l,s)))}o=W1(o);let i=H0(o,s);return[i[0],o[0],s[0],a.from[0],i[1],o[1],s[1],a.from[1],i[2],o[2],s[2],a.from[2],0,0,0,1]}function u3(t,e,n){if(n.tick(),"part"in e){let h=o2(t,e),u=f5(h);if(u)throw new Error(u);let d=Bl(h.regions,n).map(p=>p5(p,h.thickness,h.matrix));return{ref:e,outer:d,inner:d}}let r=R2(t,e),c=o0(t,e),[a,s]=ce(r),o=P1(y1(s,a));if(o<W)throw new Error("Hardware needs a nonzero cylindrical or box envelope.");if(Array.isArray(r.size)){let[h,u]=r.size,f=[[-h/2,-u/2],[h/2,-u/2],[h/2,u/2],[-h/2,u/2]],d=[p5(f,o,c)];return{ref:e,outer:d,inner:d}}let i=32,l=h=>Array.from({length:i},(u,f)=>[h*Math.cos(f*2*Math.PI/i),h*Math.sin(f*2*Math.PI/i)]);if(r.shape==="ball"){let h=r.size/2,u=h/Math.SQRT2,f=j0(0,0,h-u);return{ref:e,inner:[p5(l(u),2*u,D1(c,f))],outer:[p5(l(h/Math.cos(Math.PI/i)),o,c)]}}return{ref:e,inner:[p5(l(r.size/2),o,c)],outer:[p5(l(r.size/2/Math.cos(Math.PI/i)),o,c)]}}function g4(t,e){let n=c=>c.map(a=>({...a,vertices:a.vertices.map(s=>u0(e,s))})),r=n(t.outer);return{ref:t.ref,outer:r,inner:t.inner===t.outer?r:n(t.inner)}}function O3(t,e){if(t.kind==="translate")return j0(...A0(t.by,e));let[n,r,c]=W1(t.axis),a=t.angle*Math.PI/180*e,s=Math.cos(a),o=Math.sin(a),i=1-s,l=[s+n*n*i,n*r*i-c*o,n*c*i+r*o,0,r*n*i+c*o,s+r*r*i,r*c*i-n*o,0,c*n*i-r*o,c*r*i+n*o,s+c*c*i,0,0,0,0,1];return D1(j0(...t.origin),D1(l,j0(...A0(t.origin,-1))))}function v6(t,e){if(e.kind==="translate")return P1(e.by);let n=W1(e.axis),r=0;for(let c of t.outer)for(let a of c.vertices){let s=y1(a,e.origin);r=Math.max(r,P1(y1(s,A0(n,Q1(s,n)))))}return Math.abs(e.angle)*Math.PI/180*r}function p9(t){return t.faces.map(e=>H0(y1(t.vertices[e[1]],t.vertices[e[0]]),y1(t.vertices[e[2]],t.vertices[e[0]]))).filter(e=>P1(e)>1e-12).map(W1)}function b9(t,e){let n=[...p9(t),...p9(e)];for(let[r,c]of t.edges)for(let[a,s]of e.edges){let o=H0(y1(t.vertices[c],t.vertices[r]),y1(e.vertices[s],e.vertices[a]));P1(o)>1e-12&&n.push(W1(o))}return n}var g5=(t,e)=>{let n=t.vertices.map(r=>Q1(r,e));return[Math.min(...n),Math.max(...n)]};function _l(t,e,n){let r=-1/0;for(let c of b9(t,e)){n.tick();let a=g5(t,c),s=g5(e,c);r=Math.max(r,s[0]-a[1],a[0]-s[1])}return r}function jl(t,e){let n=0;for(let r=0;r<3;r++){let c=t.vertices.map(o=>o[r]),a=e.vertices.map(o=>o[r]),s=Math.max(0,Math.min(...a)-Math.max(...c),Math.min(...c)-Math.max(...a));n+=s*s}return Math.sqrt(n)}function Gl(t,e,n,r){let c=y1(n,e),a=y1(r,e),s=y1(t,e),o=Q1(c,s),i=Q1(a,s);if(o<=0&&i<=0)return P1(s);let l=y1(t,n),h=Q1(c,l),u=Q1(a,l);if(h>=0&&u<=h)return P1(l);let f=o*u-h*i;if(f<=0&&o>=0&&h<=0)return P1(y1(s,A0(c,o/(o-h))));let d=y1(t,r),p=Q1(c,d),m=Q1(a,d);if(m>=0&&p<=m)return P1(d);let g=p*i-o*m;if(g<=0&&i>=0&&m<=0)return P1(y1(s,A0(a,i/(i-m))));let v=h*m-p*u;if(v<=0&&u-h>=0&&p-m>=0)return P1(y1(l,A0(y1(r,n),(u-h)/(u-h+p-m))));let b=v+g+f;if(Math.abs(b)<1e-20)return 1/0;let y=Math.max(0,Math.min(1,g/b)),x=Math.max(0,Math.min(1-y,f/b));return P1(y1(s,v9(A0(c,y),A0(a,x))))}function Wl(t,e,n,r){let c=y1(e,t),a=y1(r,n),s=y1(t,n),o=Q1(c,c),i=Q1(c,a),l=Q1(a,a),h=Q1(c,s),u=Q1(a,s);if(o<1e-20||l<1e-20)return 1/0;let f=o*l-i*i,d=f>1e-20?Math.max(0,Math.min(1,(i*u-l*h)/f)):0,p=(i*d+u)/l;return p<0&&(p=0,d=Math.max(0,Math.min(1,-h/o))),p>1&&(p=1,d=Math.max(0,Math.min(1,(i-h)/o))),P1(v9(s,y1(A0(c,d),A0(a,p))))}function Xl(t,e,n){let r=1/0;for(let[c,a]of[[t,e],[e,t]])for(let s of c.vertices)for(let o of a.faces)for(let i=1;i<o.length-1;i++)n.tick(),r=Math.min(r,Gl(s,a.vertices[o[0]],a.vertices[o[i]],a.vertices[o[i+1]]));for(let[c,a]of t.edges)for(let[s,o]of e.edges)n.tick(),r=Math.min(r,Wl(t.vertices[c],t.vertices[a],e.vertices[s],e.vertices[o]));return r}function g9(t,e,n,r){let c=1/0,a=1/0,s=!1,o=!0;for(let i of t)for(let l of e){n.tick();let h=jl(i,l);if(h>Math.min(a,r)){c=Math.min(c,h);continue}let u=_l(i,l,n);u<-W&&(s=!0),u<0&&(o=!1),c=Math.min(c,Math.max(0,h,u)),u<-W?a=0:u<=Math.min(a,r)&&(a=Math.min(a,Xl(i,l,n)))}return{lower:c,upper:a,penetration:s,touchSafe:o}}function v4(t,e,n,r){let c=g9(t.outer,e.outer,n,r+W),a=t.outer===t.inner&&e.outer===e.inner;if(c.lower>r+W)return{lower:c.lower-W,upper:1/0,penetration:!1,touchSafe:!0};let s=a?c:g9(t.inner,e.inner,n,1/0);return{lower:Math.max(0,c.lower-W),upper:s.upper+W,penetration:s.penetration,touchSafe:c.touchSafe}}function x9(t,e,n,r,c,a){for(let s=0;s<t.outer.length;s++)for(let o=0;o<n.outer.length;o++){let i=t.outer[s],l=n.outer[o],h=e.outer[s],u=r.outer[o],f=!1;for(let d of b9(i,l)){a.tick();let p=g5(i,d),m=g5(l,d),g=g5(h,d),v=g5(u,d);if(Math.min(m[0]-p[1],v[0]-g[1])>=c||Math.min(p[0]-m[1],g[0]-v[1])>=c){f=!0;break}}if(!f)return!1}return!0}function y4(t){if(!t.relationsKnown)throw new Error("Native glue/stack relation metadata is unavailable.");let e=[];for(let n of t.parts){let r={part:n.name,copy:n.copy},c=n.stack??1;if(n.on)throw new Error("Bend-rider joints require a resolved rigid-run attachment model.");if(c>1&&(n.copy-1)%c!==0){let a=n.glue&&n.glueFace==="bottom";e.push({a:{part:n.name,copy:n.copy-1},b:r,faceA:a?"bottom":"top",faceB:a?"top":"bottom"})}else n.glue&&e.push({a:n.glue,b:r,faceA:n.glueFace??"top",faceB:n.glueFace==="bottom"?"top":"bottom"})}return e}var z2=(t,e={},n=[])=>({status:"fail",code:"interference",message:t,measurements:e,entities:n}),ae=(t,e)=>t.every((n,r)=>Math.abs(n-e[r])<W);function M9(t,e,n){if(new Set(e.map(f1)).size!==e.length)throw new Error("A physical body appears more than once in this scope.");return e.map(r=>u3(t,r,n))}function w9(t,e,n){let r=M9(e,t.bodies??H3(e),n);if(r.length<2)return l1("Rigid clearance requires at least two physical bodies.");let c=1/0;for(let a=0;a<r.length;a++)for(let s=a+1;s<r.length;s++){let o=v4(r[a],r[s],n,t.minimumGap);if(c=Math.min(c,o.lower),o.penetration||o.upper<t.minimumGap-W)return z2("Physical bodies interfere or violate the required clearance.",{gapUpper:o.upper},[r[a].ref,r[s].ref]);if(!(o.lower>t.minimumGap||t.minimumGap===0&&o.touchSafe))return{...l1("The clearance is within geometric or hardware-envelope uncertainty."),entities:[r[a].ref,r[s].ref]}}return{status:"pass",code:"rigid-clearance",message:"Nominal physical envelopes satisfy the declared clearance.",coverage:"nominal",measurements:{minimumGapLower:c},assumptions:["Rigid nominal dimensions; contact forces, manufacturing variation and strength are separate checks."]}}function y6(t,e,n,r,c=1e3){let a=i=>({solid:i,trajectory:{kind:"translate",by:[0,0,0]}});function*s(){for(let i=0;i<t.length;i++){for(let l of e)yield{a:t[i],b:a(l)};for(let l=i+1;l<t.length;l++)yield{a:t[i],b:t[l]}}}let o=0;for(let{a:i,b:l}of s()){r.tick();let h=(d,p)=>g4(d.solid,O3(d.trajectory,p));if(g6(i.trajectory,l.trajectory)){let d=v4(i.solid,l.solid,r,n);if(d.penetration||d.upper<n-W)return z2("Bodies moving together violate their required clearance.",{gapUpper:d.upper},[i.solid.ref,l.solid.ref]);if(d.lower>n||n===0&&d.touchSafe)continue;return{...l1("The fixed relative clearance is within geometric uncertainty."),entities:[i.solid.ref,l.solid.ref]}}if(i.trajectory.kind==="translate"&&l.trajectory.kind==="translate"&&x9(h(i,0),h(i,1),h(l,0),h(l,1),n===0?0:n+W,r))continue;let u=v6(i.solid,i.trajectory)+v6(l.solid,l.trajectory),f=[[0,1]];for(;f.length;){if(++o>c)return{...l1("Continuous clearance interval budget exhausted."),measurements:{intervals:o},entities:[i.solid.ref,l.solid.ref]};r.tick();let[d,p]=f.shift(),m=(d+p)/2,g=u*(p-d)/2,v=v4(h(i,m),h(l,m),r,n+g);if(v.penetration||v.upper<n-W)return z2("The specified path has physical interference.",{phase:m,gapUpper:v.upper},[i.solid.ref,l.solid.ref]);if(!(v.lower-g>n)){if(p-d<1e-9)return{...l1("Continuous contact is within numerical uncertainty."),measurements:{phase:[d,p]},entities:[i.solid.ref,l.solid.ref]};f.push([d,m],[m,p])}}}return{status:"pass",code:"continuous-clearance",message:"The specified rigid path is clear over its full interval.",coverage:"continuous-nominal",measurements:{intervals:o},assumptions:["Analytic rigid trajectories and nominal geometry; the mechanism must separately satisfy its joint constraints."]}}function Zl(t,e){if(t.parts.length!==e.parts.length||t.hardware.length!==e.hardware.length)return"The physical inventory changes between motion endpoints.";for(let n of t.parts){let r=e.parts.find(c=>c.name===n.name&&c.copy===n.copy);if(!r||n.cutLines===null||r.cutLines===null||!u4(n,r))return"Full cut geometry must remain invariant throughout an operating motion.";if(JSON.stringify([n.stack,n.glue,n.glueFace,n.on])!==JSON.stringify([r.stack,r.glue,r.glueFace,r.on]))return"Installed native glue/stack relationships change during the operating motion."}for(let n of t.hardware){let r=e.hardware.find(c=>c.label===n.label);if(!n.label||!r||n.kind!==r.kind||JSON.stringify(n.size)!==JSON.stringify(r.size)||Math.abs(P1(y1(n.to,n.from))-P1(y1(r.to,r.from)))>W)return"Hardware identities and dimensions must remain invariant."}return null}function k9(t,e,n,r,c=[]){if(!e.relationsKnown||!n.relationsKnown||[...e.parts,...n.parts].some(l=>l.cutLines===null||l.kerf===null))return l1("Motion requires complete cutting and native attachment metadata at both endpoints.");let a=Zl(e,n);if(a)return{status:"fail",code:"motion-inventory",message:a};let s=H3(e),o=new Set(t.moving.map(l=>f1(l.body)));if(o.size!==t.moving.length)return z2("A body has conflicting simultaneous trajectories.");let i=l=>t.moving.find(h=>f1(h.body)===f1(l))?.trajectory??{kind:"translate",by:[0,0,0]};for(let l of[...y4(e),...c]){let h=D1(v0(o0(e,l.a)),o0(e,l.b)),u=D1(v0(o0(n,l.a)),o0(n,l.b));if(!ae(h,u)||!g6(i(l.a),i(l.b)))return z2("The operating path moves an installed glue bond or laminated stack.",{},[l.a,l.b])}for(let l of s){let h=t.moving.find(f=>f1(f.body)===f1(l))?.trajectory,u=h?O3(h,1):y9();if("part"in l){if(!ae(D1(u,o0(e,l)),o0(n,l)))return z2("A trajectory does not match the rendered destination pose.",{},[l])}else{let f=R2(e,l),d=R2(n,l);if(typeof f.size=="number"){if(!ae(u0(u,f.from),d.from)||!ae(u0(u,f.to),d.to))return z2("A hardware trajectory does not match its rendered endpoints.",{},[l])}else if(!ae(D1(u,o0(e,l)),o0(n,l)))return z2("A box trajectory does not match its rendered destination.",{},[l])}}return y6(t.moving.map(l=>({solid:u3(e,l.body,r),trajectory:l.trajectory})),M9(e,s.filter(l=>!o.has(f1(l))),r),t.minimumGap,r,t.maxIntervals)}function z9(t,e,n){let r=t.scope??H3(e),c=new Set(r.map(f1)),a=new Map(t.initial.map(i=>[f1(i),u3(e,i,n)]));if(c.size!==r.length||a.size!==t.initial.length||t.initial.some(i=>!c.has(f1(i))))return z2("Assembly scope and initial inventory must be unique and consistent.");let s=new Set,o=0;for(let i of t.steps){if(s.has(i.id)||!c.has(f1(i.part))||a.has(f1(i.part)))return z2("An assembly step duplicates or misidentifies a required installation.");if(s.add(i.id),!i.held)return{...l1(`Step ${i.id} needs an explicit temporary holding/support assumption.`),assemblyStep:i.id};let l=u3(e,i.part,n),h=g4(l,O3({kind:"translate",by:i.from},1)),u=y6([{solid:h,trajectory:{kind:"translate",by:i.from.map(f=>-f)}}],[...a.values()],t.minimumGap,n,t.maxIntervals);if(u.status!=="pass")return{...u,assemblyStep:i.id,message:`Assembly step ${i.id}: ${u.message}`};if(o+=u.measurements?.intervals??0,a.set(f1(i.part),l),i.tool){let f="$verification-tool";for(;e.hardware.some(v=>v.label===f);)f+=":";let d={...e,hardware:[...e.hardware,{label:f,kind:"tool",from:i.tool.from,to:i.tool.to,size:i.tool.diameter,up:[0,1,0]}]},p=u3(d,{hardware:f},n),m=g4(p,O3({kind:"translate",by:i.tool.travel},1)),g=y6([{solid:m,trajectory:{kind:"translate",by:i.tool.travel.map(v=>-v)}}],[...a.values()],0,n,t.maxIntervals);if(g.status!=="pass")return{...g,assemblyStep:i.id,message:`Tool access at step ${i.id}: ${g.message}`}}}return a.size!==c.size?z2("The procedure omits required physical inventory."):{status:"pass",code:"assembly-access",message:"Every scoped body has one clear authored insertion, with checked tool paths.",coverage:"continuous-nominal",measurements:{installed:a.size,intervals:o},assumptions:["The initial body is already supported; an operator/fixture holds each incoming body during insertion. Retention and stability after installation are separate required claims."]}}var t0=(t,e={})=>({status:"fail",code:"mechanical-condition-failed",message:t,measurements:e}),n2=(t,e)=>[0,1,2].map(n=>t[n*4]*e[0]+t[n*4+1]*e[1]+t[n*4+2]*e[2]),W0=t=>[t[3],t[7],t[11]],b6=t=>{let e=W1(t),n=W1(H0(e,Math.abs(e[0])<.8?[1,0,0]:[0,1,0]));return[n,H0(e,n)]},b4=(t,e,n)=>{let r=b6(n)[0],c=W1(n2(e,r)),a=W1(n2(t,r)),s=W1(n2(e,n));return Math.atan2(Q1(s,H0(c,a)),Q1(c,a))*180/Math.PI},S9=(t,e,n)=>{let r=[],c=Math.ceil((e[0]-n-t)/360),a=Math.floor((e[1]+n-t)/360);for(let o=c;o<=a&&r.length<64;o++)r.push(t+360*o);let s=(e[0]+e[1])/2;return r.sort((o,i)=>Math.abs(o-s)-Math.abs(i-s))};function A9(t,e){if(t?.kind==="glue-contact"&&e==="glued")return[t.a,t.b];if(t?.kind==="captured-shaft"&&e==="captured"){let n=[t.shaft,...t.bearings,...t.stack,...t.stops.map(r=>r.body)];for(let r of t.stops)r.attachment.kind==="threaded"&&n.push(r.attachment.thread);return n}}function L9(t,e,n,r){let c=H3(e),a=new Set(c.map(f1));for(let f of t.removable??[])a.delete(f1(f));if(t.roots.some(f=>!a.has(f1(f))))return t0("A retention root cannot be excluded as removable.");let s=new Map,o=f=>{for(let d of f)for(let p of f){let m=f1(d),g=s.get(m)??new Set;g.add(f1(p)),s.set(m,g)}},i=["Roots are supported as declared; specified adhesive/fastener installations are performed. Strength and durability are separate claims."];for(let f of t.links){let d=n.claims.find(g=>g.id===f.claim),p=r.find(g=>g.id===f.claim&&g.configurations.includes(e.configuration));if(!d||!p)return l1(`Retention depends on unavailable geometric claim ${f.claim}.`);if(p.status==="fail")return t0(`Attachment ${f.claim} fails its geometric contract.`);if(p.status!=="pass")return l1(`Attachment ${f.claim} has not been verified.`);if(!f.installed)return t0(`The fastening for ${f.claim} is explicitly not installed.`);let m=A9(d,f.fastening);if(!m)return l1(`Fit or kinematic claim ${f.claim} does not prove the specified positive fastening.`);o(m),d.kind==="glue-contact"&&i.push(`A cured fixed adhesive bond is assumed at ${f.claim}; only its contact geometry was measured.`)}let l=new Set(t.roots.map(f1)),h=[...l];for(;h.length;)for(let f of s.get(h.pop())??[])l.has(f)||(l.add(f),h.push(f));let u=c.filter(f=>a.has(f1(f))&&!l.has(f1(f)));return u.length?{...t0("Permanent components lack validated retention to a declared root."),entities:u}:{status:"pass",code:"retention-covered",message:"Every permanent component is retained to a root under the checked fastening assumptions.",coverage:"nominal",measurements:{permanentComponents:a.size,removableComponents:t.removable?.length??0},assumptions:i}}function Yl(t,e){if("hardware"in e){let o=o0(t,e),i=t.hardware.find(l=>l.label===e.hardware);return u0(o,[0,0,P1(y1(ce(i)[1],ce(i)[0]))/2])}let n=o2(t,e),r=f5(n);if(r)throw new Error(r);let c=0,a=0,s=0;for(let o of n.regions){let[i,l]=o[0],h=0,u=0,f=0;for(let p=0;p<o.length;p++){let m=o[p],g=o[(p+1)%o.length],v=m[0]-i,b=m[1]-l,y=g[0]-i,x=g[1]-l,w=v*x-y*b;h+=w,u+=(v+y)*w,f+=(b+x)*w}if(Math.abs(h)<1e-12)continue;let d=E3(o);c+=d,a+=(i+u/(3*h))*d,s+=(l+f/(3*h))*d}if(c<=W*W)throw new Error("Material centroid is numerically unresolved.");return u0(n.matrix,[a/c,s/c,n.thickness/2])}function Jl(t){let e=[...t].sort((s,o)=>s[0]-o[0]||s[1]-o[1]),n=(s,o,i)=>(o[0]-s[0])*(i[1]-s[1])-(o[1]-s[1])*(i[0]-s[0]),r=s=>{let o=[];for(let i of s){for(;o.length>1&&n(o[o.length-2],o[o.length-1],i)<=0;)o.pop();o.push(i)}return o},c=r(e),a=r([...e].reverse());return[...c.slice(0,-1),...a.slice(0,-1)]}function Kl(t,e,n){let r=new Map,c=o=>{for(let i of o)for(let l of o){let h=r.get(f1(i))??new Set;h.add(f1(l)),r.set(f1(i),h)}};for(let o of t.links){let i=A9(e.claims.find(l=>l.id===o.claim),o.fastening);i&&c(i)}if(!n.length)return!0;let a=new Set([f1(n[0])]),s=[...a];for(;s.length;)for(let o of r.get(s.pop())??[])a.has(o)||(a.add(o),s.push(o));return n.every(o=>a.has(f1(o)))}function C9(t,e,n,r=[],c){let a=H3(e),s=t.loads.map(m=>f1(m.body));if(new Set(s).size!==s.length||a.some(m=>!s.includes(f1(m))))return l1("Stability needs one declared positive mass for every physical component.");if(a.length>1){let m=r.find(v=>v.id===t.retention&&v.configurations.includes(e.configuration)),g=c?.claims.find(v=>v.id===t.retention);if(!m||m.status!=="pass"||!g||g.kind!=="retention"||g.removable?.length)return l1("Combined-load stability needs verified retention of every load; removable-contact support is not established.");if(!Kl(g,c,a))return l1("The loads are retained to separate roots, not joined into one rigid assembly; check each one\u2019s stability on its own.")}let o=0,i=[0,0,0];for(let m of t.loads){let g=m.center?u0(o0(e,m.body),m.center):Yl(e,m.body);o+=m.mass,i=i.map((v,b)=>v+m.mass*g[b])}if(!Number.isFinite(o)||!i.every(Number.isFinite))return l1("Mass/centroid calculation exceeds its numerical range.");i=A0(i,1/o);let l=[];for(let m of a){let g=u3(e,m,n),v=Math.min(...g.inner.flatMap(y=>y.vertices.map(x=>x[2]))),b=Math.min(...g.outer.flatMap(y=>y.vertices.map(x=>x[2])));if(v<t.ground-W)return t0("A physical component penetrates the ground plane.");if(b<t.ground-W)return l1("Ground penetration is within physical-envelope uncertainty.");if(t.supports.some(y=>f1(y)===f1(m))){if(Math.abs(v-t.ground)>1e-8)return l1("Ground contact is separated or within physical-envelope uncertainty.");for(let y of g.inner)for(let x of y.vertices)Math.abs(x[2]-t.ground)<1e-8&&l.push([x[0],x[1]])}}let h=Jl(l);if(h.length<3)return l1("Ground contacts do not establish a finite support polygon.");let u=(t.ground-i[2])/t.gravity[2],f=[i[0]+u*t.gravity[0],i[1]+u*t.gravity[1]],d=1/0;for(let m=0;m<h.length;m++){let g=h[m],v=h[(m+1)%h.length],b=(v[0]-g[0])*(f[1]-g[1])-(v[1]-g[1])*(f[0]-g[0]),y=u5(f,g,v);d=Math.min(d,b<0?-y:y)}let p={supportMargin:d,mass:o,centerX:i[0],centerY:i[1],centerZ:i[2]};return d<t.minimumMargin-W?t0("The gravity line lies outside the required support margin.",p):d<t.minimumMargin+W?{...l1("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 P9(t,e,n,r){let c=n.claims.find(d=>d.id===t.plan),a=n.claims.find(d=>d.id===t.retention),s=d=>r.find(p=>p.id===d&&p.configurations.includes(e.configuration));if(!c||c.kind!=="assembly-access"||!a||a.kind!=="retention"||s(t.plan)?.status!=="pass"||s(t.retention)?.status!=="pass")return l1("Assembly support needs verified insertion and retention contracts.");if(a.removable?.length)return l1("Per-step support of removable objects needs an explicit contact model.");let o=new Set(a.roots.map(f1)),i=new Set(c.initial.map(f1));if(c.initial.some(d=>!o.has(f1(d))))return l1("The initial subassembly needs a declared grounded support.");let l=new Map;for(let d of a.links){let p=n.claims.find(m=>m.id===d.claim);if(p?.kind==="glue-contact")l.set(d.claim,[p.a,p.b]);else if(p?.kind==="captured-shaft"){let m=[p.shaft,...p.bearings,...p.stack,...p.stops.map(g=>g.body)];p.stops.forEach(g=>{g.attachment.kind==="threaded"&&m.push(g.attachment.thread)}),l.set(d.claim,m)}}let h=new Set,u=new Set(c.steps.map(d=>d.id));if(t.holds?.some(d=>!u.has(d.step))||new Set(t.holds?.map(d=>d.step)).size!==(t.holds?.length??0))return t0("Temporary holds must identify unique existing assembly steps.");let f=()=>{let d=new Map;for(let g of h)for(let v of l.get(g)??[])for(let b of l.get(g)??[]){let y=d.get(f1(v))??new Set;y.add(f1(b)),d.set(f1(v),y)}let p=new Set([...o].filter(g=>i.has(g))),m=[...p];for(;m.length;)for(let g of d.get(m.pop())??[])p.has(g)||(p.add(g),m.push(g));return p};for(let d of c.steps){i.add(f1(d.part));for(let g of d.fasten??[]){let v=l.get(g);if(!v)return t0(`Step ${d.id} names an unknown fastening.`);if(v.some(b=>!i.has(f1(b))))return t0(`Step ${d.id} fastens a joint before all its components are installed.`);h.add(g)}let p=new Set((t.holds?.find(g=>g.step===d.id)?.bodies??[]).map(f1));if([...p].some(g=>!i.has(g)))return t0(`Step ${d.id} holds an uninstalled body.`);let m=f();if([...i].some(g=>!m.has(g)&&!p.has(g)))return t0(`Step ${d.id} releases a component before it is retained or supported.`)}return[...i].some(d=>!f().has(d))?t0("The final assembly still relies on temporary holding."):{status:"pass",code:"assembly-support",message:"Installed components remain rooted or explicitly held at every step; final temporary supports are released.",coverage:"discrete",assumptions:["The measured attachment contracts and their declared installation/cure assumptions hold. Operator holds are provided exactly as specified."]}}function Ql(t){let e=t.map(c=>{let a=Math.max(...c.map(Math.abs),1e-20);return c.map(s=>s/a)}),n=0,r=!1;for(let c=0;c<(e[0]?.length??0)&&n<e.length;c++){let a=n;for(let i=n+1;i<e.length;i++)Math.abs(e[i][c])>Math.abs(e[a][c])&&(a=i);let s=Math.abs(e[a][c]);if(s<1e-10)continue;s<1e-7&&(r=!0),[e[n],e[a]]=[e[a],e[n]];let o=e[n][c];for(let i=c;i<e[n].length;i++)e[n][i]/=o;for(let i=n+1;i<e.length;i++){let l=e[i][c];for(let h=c;h<e[i].length;h++)e[i][h]-=l*e[n][h]}n++}return{rank:n,uncertain:r}}function E9(t,e,n,r,c,a=[]){if(t.bodies.length>64)return l1("Joint rank checks support at most 64 scoped rigid bodies.");let s=t.bodies.map(f1),o=t.roots.map(f1);if(new Set(s).size!==s.length||new Set(o).size!==o.length||o.some(v=>!s.includes(v)))return t0("Joint bodies/roots must be unique and within scope.");if(t.roots.some(v=>o0(e,v).some((b,y)=>Math.abs(b-o0(n,v)[y])>W)))return t0("A grounded kinematic root changes pose.");let i=[],l=[[1,0,0],[0,1,0],[0,0,1]],h=()=>new Array(s.length*6).fill(0),u=(v,b,y,x,w=1)=>{let M=s.indexOf(f1(b));if(M<0)throw new Error("A joint references a body outside its scope.");for(let k=0;k<3;k++)v[M*6+y+k]+=w*x[k]};for(let v of t.roots)for(let b=0;b<6;b++){let y=h();y[s.indexOf(f1(v))*6+b]=1,i.push(y)}let f=y4({...e,parts:e.parts.filter(v=>s.includes(f1({part:v.name,copy:v.copy})))});for(let v of c?.claims??[])if(v.kind==="retention")for(let b of v.links){let y=c.claims.find(x=>x.id===b.claim);b.installed&&b.fastening==="glued"&&y?.kind==="glue-contact"&&a.some(x=>x.id===y.id&&x.configurations.includes(e.configuration)&&x.status==="pass")&&f.push({a:y.a,b:y.b})}for(let v of f)if(!(!s.includes(f1(v.a))&&!s.includes(f1(v.b)))){if(!s.includes(f1(v.a))||!s.includes(f1(v.b)))return l1("The joint scope omits a native fixed-bond host.");if(v.faceA&&v.faceB&&"part"in v.a&&"part"in v.b){let b=m4({id:"$native-bond",kind:"glue-contact",a:v.a,b:v.b,faceA:v.faceA,faceB:v.faceB,minimumArea:W*W*4},e);if(b.status!=="pass")return{...b,message:`A native glue/stack bond is not physically established: ${b.message}`}}}let d=[...t.joints,...f.filter(v=>s.includes(f1(v.a))&&s.includes(f1(v.b))).map(v=>({kind:"fixed",a:v.a,b:v.b}))];for(let v of d){if(r.tick(),f1(v.a)===f1(v.b))return t0("A joint cannot connect a body to itself.");let b=o0(e,v.a),y=o0(e,v.b),x=o0(n,v.a),w=o0(n,v.b),M=D1(v0(b),y),k=D1(v0(x),w),z=S=>{let C=h();u(C,v.b,3,S),u(C,v.a,3,S,-1),i.push(C)},A=(S,C,I)=>{let L=h();u(L,v.b,0,S),u(L,v.a,0,S,-1),u(L,v.b,3,H0(I,S)),u(L,v.a,3,H0(C,S),-1),i.push(L)};if(v.kind==="fixed"){if(M.some((S,C)=>Math.abs(S-k[C])>W))return t0("A fixed joint changes its relative transform.");l.forEach(S=>z(S)),l.forEach(S=>A(S,y1(W0(y),W0(b)),[0,0,0]))}else if(v.kind==="revolute"){let S=u0(b,v.anchorA),C=u0(y,v.anchorB),I=W1(n2(b,v.axisA)),L=W1(n2(y,v.axisB)),T=Q1(W1(n2(x,v.axisA)),W1(n2(w,v.axisB)));if(P1(y1(S,C))>W||P1(H0(I,L))>1e-7||Math.abs(Q1(I,L)-T)>1e-7)return t0("Revolute anchors or axes do not coincide.");if(v.range){let q=b4(M,k,v.axisB);if(!S9(q,v.range,W).length)return t0("A revolute joint exceeds its declared angular travel.",{angle:q})}l.forEach(q=>A(q,y1(S,W0(b)),y1(C,W0(y)))),b6(I).forEach(z)}else if(v.kind==="prismatic"){let S=y1(W0(M),W0(k)),C=W1(v.axisA),I=Q1(S,C);if([0,1,2,4,5,6,8,9,10].some(L=>Math.abs(M[L]-k[L])>W)||P1(y1(S,A0(C,I)))>W)return t0("A slider rotates or moves away from its guide axis.");if(I<v.travel[0]-W||I>v.travel[1]+W)return t0("The slider exceeds its allowed travel.",{travel:I});l.forEach(z),b6(W1(n2(b,v.axisA))).forEach(L=>A(L,y1(W0(y),W0(b)),[0,0,0]))}else{let S=W1(n2(b,v.axisA)),C=W1(n2(y,v.axisB));if(P1(H0(S,C))>1e-7||P1(y1(W0(b),W0(x)))>W||P1(y1(W0(y),W0(w)))>W)return t0("The scoped gear axes/centers are not fixed and parallel.");let I=b4(b,x,v.axisA),L=b4(y,w,v.axisB);if(Math.abs(I)>90||Math.abs(L)>90)return l1("Gear pose deltas exceed the unambiguous quarter-turn branch; add intermediate configurations.");if(Math.abs(L+v.ratio*I)>1e-6)return t0("The rendered gears do not obey their declared angular ratio.");let T=h();u(T,v.a,3,S,v.ratio),u(T,v.b,3,C),i.push(T)}}r.tick(i.length*s.length*6);let p=Ql(i),m=s.length*6-p.rank;if(p.uncertain)return l1("Constraint rank is numerically singular.");let g={degreesOfFreedom:m,constraintRank:p.rank,redundantRows:i.length-p.rank};return m!==t.expectedDof?t0("The joint graph has unintended freedom or is overconstrained.",g):{status:"pass",code:"joint-constraints",message:"The scoped ideal joints satisfy their pose constraints and expected mobility.",coverage:"discrete",measurements:g,assumptions:["Ideal rigid kinematic joints at declared configurations. Gear ratio is checked on the principal quarter-turn branch; actual tooth contact, driving torque and friction are separate checks."]}}function T9(t,e,n,r){let c=i=>t.moving.find(l=>f1(l.body)===f1(i))?.trajectory??{kind:"translate",by:[0,0,0]},a=i=>i.kind==="translate"?P1(i.by)<1e-9:Math.abs(i.angle)<1e-9,s=(i,l)=>a(i)&&a(l)?!0:i.kind==="translate"&&l.kind==="translate"?P1(y1(i.by,l.by))<1e-9:i.kind==="rotate"&&l.kind==="rotate"?P1(y1(A0(W1(i.axis),i.angle),A0(W1(l.axis),l.angle)))<1e-9&&P1(H0(y1(i.origin,l.origin),W1(i.axis)))<1e-9:!1;if(e.roots.some(i=>!a(c(i))))return t0("The analytic path moves a grounded joint root.");let o=new Map;for(let i of e.joints.filter(l=>l.kind!=="gear")){if(o.has(f1(i.b)))return l1("Continuous joint proof requires an ideal joint tree, not a closed linkage.");o.set(f1(i.b),f1(i.a))}for(let i of o.keys()){let l=new Set,h=i;for(;h&&o.has(h);){if(l.has(h))return l1("Continuous closed-linkage constraints need a solver.");l.add(h),h=o.get(h)}}for(let i of e.joints){let l=c(i.a),h=c(i.b),u=o0(n,i.a),f=o0(n,i.b);if(i.kind==="fixed"){if(!s(l,h))return t0("The analytic path separates a fixed joint.");continue}if(i.kind==="revolute"){if(s(l,h))continue;if(!a(l)||h.kind!=="rotate")return l1("This revolute trajectory composition is not supported by the analytic joint proof.");let d=u0(u,i.anchorA),p=W1(n2(u,i.axisA)),m=W1(h.axis);if(P1(H0(p,m))>1e-9||P1(H0(y1(h.origin,d),p))>W)return t0("The trajectory does not rotate about the actual hinge.");if(i.range){let g=D1(v0(u),f),v=D1(v0(o0(r,i.a)),o0(r,i.b)),b=h.angle*Q1(W1(n2(f,i.axisB)),m),y=i.range;if(!S9(b4(g,v,i.axisB),y,W).some(w=>Math.min(w,w+b)>=y[0]-W&&Math.max(w,w+b)<=y[1]+W))return t0("The continuous hinge path exceeds its angular stops.")}}else if(i.kind==="prismatic"){if(s(l,h))continue;if(!a(l)||h.kind!=="translate")return l1("This slider trajectory composition needs a richer constraint solver.");let d=W1(n2(u,i.axisA));if(P1(H0(h.by,d))>W)return t0("The analytic slider path leaves its guide.");let p=D1(v0(u),f),m=D1(v0(o0(r,i.a)),o0(r,i.b)),g=Q1(y1(W0(p),W0(m)),W1(i.axisA)),v=g+Q1(h.by,d);if(Math.min(g,v)<i.travel[0]-W||Math.max(g,v)>i.travel[1]+W)return t0("The continuous slider path exceeds its travel stops.")}else{let d=(g,v,b)=>{if(a(v))return 0;if(v.kind!=="rotate")return null;let y=o0(n,g),x=W1(n2(y,b));return P1(H0(W1(v.axis),x))>1e-9||P1(H0(y1(v.origin,W0(y)),x))>W?null:v.angle*Q1(W1(v.axis),x)},p=d(i.a,l,i.axisA),m=d(i.b,h,i.axisB);if(p===null||m===null)return l1("Gear coupling needs rotations about the fixed gear axes.");if(Math.abs(m+i.ratio*p)>1e-7)return t0("The continuous gear rotations violate their declared ratio.")}}return{status:"pass",code:"continuous-joints",message:"The analytic paths obey the supported ideal joint tree and stops.",coverage:"continuous-nominal"}}function x6(t,e){let n=t.analysis?.schemaVersion===1?t.analysis:void 0;return I9(JSON.parse(JSON.stringify({schemaVersion:1,configuration:e.configuration,params:e.params??{},renderSettings:e.renderSettings??{},provenance:e.provenance??null,parts:t.assembly.map(r=>{let c=n?.parts.filter(l=>l.name===r.name),a=c?.length===1?c[0]:void 0,s=a?.glue?.host,i=(s?t.assembly.filter(l=>l.name===s):[]).length===(a?.qty??0)/(a?.stack??1)?Math.floor((r.copy-1)/(a?.stack??1))+1:1;return{name:r.name,copy:r.copy,thickness:r.thickness,material:r.material??"",matrix:r.matrix,placed:r.placed,regions:a?.cutRegions??r.outline,bends:r.bends??[],kerf:a?.kerf??null,cutLines:a?.cutLines??null,...a?.stack&&{stack:a.stack},...s&&{glue:{part:s,copy:i},glueFace:a.glue.face},...a?.on&&{on:a.on}}}),hardware:t.hardware.map(r=>({label:r.label??null,kind:r.kind,from:r.from,to:r.to,size:r.size,up:r.up,...r.sides===0&&{shape:"ball"}})),warnings:t.warnings,legacyHardware:t.echoes.some(r=>r.startsWith("hardware, ")),relationsKnown:n?.relations===!0})))}function I9(t){if(t&&typeof t=="object"){for(let e of Object.values(t))I9(e);Object.freeze(t)}return t}function M6(t,e,n){if(!Number.isFinite(n)||n<0||n>1)throw new Error("Pose phase must be between 0 and 1.");let r=ee({schemaVersion:1,model:"pose",configurations:[{id:"a"},{id:"b"}],claims:[{id:"path",kind:"motion-clearance",from:"a",to:"b",moving:e,minimumGap:0}]});if(r.length)throw new Error(r[0].message);let c=new Map;for(let a of e){let s=a.body,o=f1(s);if(("part"in s?t.assembly.filter(l=>l.name===s.part&&l.copy===(s.copy??1)).length:t.hardware.filter(l=>l.label===s.hardware).length)!==1||c.has(o))throw new Error("Pose controls must identify one unique physical instance each.");c.set(o,O3(a.trajectory,n))}return{...t,assembly:t.assembly.map(a=>{let s=c.get(f1({part:a.name,copy:a.copy}));return s?{...a,matrix:D1(s,a.matrix)}:a}),hardware:t.hardware.map(a=>{let s={hardware:a.label??""},o=c.get(f1(s));return o?{...a,from:u0(o,a.from),to:u0(o,a.to),up:y1(u0(o,a.up),u0(o,[0,0,0]))}:a})}}function H9(t,e,n){if(!t||t.schemaVersion!==1||t.algorithm!=="kerf-rigid-v1"||t.numericalTolerance!==W||ee(e).length||l6(n).length||n.some(c=>c.error!==void 0||!c.provenance)||!Array.isArray(t.inputs))return!1;let r=c=>JSON.stringify(c,(a,s)=>s&&typeof s=="object"&&!Array.isArray(s)?Object.fromEntries(Object.keys(s).sort().map(o=>[o,s[o]])):s);try{let c=n.map(s=>({configuration:s.configuration,params:s.params,renderSettings:s.renderSettings,provenance:s.provenance})),a=s=>[...s].sort((o,i)=>o.configuration.localeCompare(i.configuration));return r(e)===r(t.specification)&&r(a(c))===r(a(t.inputs))}catch{return!1}}function O9(t,e,n={}){if(!n||typeof n!="object"||Array.isArray(n))return{kind:"invalid-spec",issues:[{code:"invalid-limits",message:"Verification limits must be an object."}]};let r=ee(t);if(r.length)return{kind:"invalid-spec",issues:r};let c=l6(e);if(c.length)return{kind:"invalid-snapshot",issues:c};let a=t,s=e,o=[];for(let[g,v]of Object.entries(n))(!["maxPoints","maxClaims","maxConfigurations","maxOperations"].includes(g)||!Number.isSafeInteger(v)||!(v>0))&&o.push({code:"invalid-limits",path:`limits.${g}`,message:"Verification limits must be positive safe integers."});if(o.length)return{kind:"invalid-spec",issues:o};let i={schemaVersion:1,model:a.model,status:"unverified",algorithm:"kerf-rigid-v1",numericalTolerance:W,specification:JSON.parse(JSON.stringify(a)),claims:[],inputs:JSON.parse(JSON.stringify(s.map(g=>({configuration:g.configuration,params:g.params,renderSettings:g.renderSettings,provenance:g.provenance})))),uncovered:["Physical strength, friction, wear, actual gear/cam driving contact and fastening durability.","Flexible bodies and unsupported closed-loop/contact dynamics.","Bodies and parameter regions outside the explicitly declared claim scopes."]};if(s.reduce((g,v)=>g+v.hardware.reduce((b,y)=>b+(typeof y.size=="number"?128:8),0)+v.parts.reduce((b,y)=>b+y.regions.reduce((x,w)=>x+w.length,0)+(y.cutLines??[]).reduce((x,w)=>x+w.length,0),0),0)>(n.maxPoints??2e5)||a.claims.length>(n.maxClaims??1e3)||a.configurations.length>(n.maxConfigurations??100))return i.claims.push(f3("$resource-limit","resource-limit",!0,[],{status:"unverified",code:"resource-limit",message:"The verification input exceeds its point, claim or configuration budget. No mechanical conclusions were reached."})),{kind:"report",report:i};let h=new Set(a.configurations.map(g=>g.id));for(let g of s)h.has(g.configuration)||o.push({code:"unknown-configuration",message:`Snapshot ${g.configuration} is not declared.`});for(let g of s){let v=a.configurations.find(b=>b.id===g.configuration)?.params??{};for(let[b,y]of Object.entries(v))JSON.stringify(g.params[b])!==JSON.stringify(y)&&o.push({code:"configuration-mismatch",message:`${g.configuration}: captured parameter ${b} differs from its required value.`})}let u=new Map(a.claims.map(g=>[g.id,g]));for(let{claim:g,ref:v}of f9(a)){let b=u.get(g);for(let y of s.filter(x=>x.error===void 0&&(!b.configurations||b.configurations.includes(x.configuration)))){let x="part"in v?y.parts.filter(w=>w.name===v.part&&w.copy===(v.copy??1)):y.hardware.filter(w=>w.label===v.hardware);x.length!==1&&o.push({code:"ambiguous-reference",path:`claims.${g}`,message:`${y.configuration}: ${JSON.stringify(v)} resolves to ${x.length} instances; exactly one is required.`})}}if(o.length)return{kind:"invalid-spec",issues:o};for(let g of a.configurations){let v=s.find(y=>y.configuration===g.id),b=v&&v.error===void 0;i.claims.push(f3(`$configuration:${g.id}`,"configuration",!0,[g.id],b?{status:"pass",code:"configuration-rendered",message:"The required configuration rendered."}:{status:"fail",code:"configuration-unavailable",message:v?.error||"A required configuration snapshot is missing or failed without a diagnostic."})),b&&(i.claims.push(f3(`$provenance:${g.id}`,"provenance",!0,[g.id],v.provenance?{status:"pass",code:"provenance-recorded",message:"Source, engine, dependency and font fingerprints are recorded."}:{status:"unverified",code:"missing-provenance",message:"Supply exact source/engine fingerprints and dependency/font maps before archiving a verified result."})),v.warnings.length&&i.claims.push(f3(`$compiler:${g.id}`,"compiler-diagnostics",!0,[g.id],{status:"unverified",code:"compiler-warnings",message:v.warnings.join(`
|
|
3104
|
+
`)})),v.legacyHardware&&i.claims.push(f3(`$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 p4(n.maxOperations),d=g=>g.kind==="retention"?3:g.kind==="stability"||g.kind==="assembly-support"?4:g.kind==="motion-clearance"||g.kind==="assembly-access"?2:g.kind==="joint-constraints"?1:0,p=[...a.claims].sort((g,v)=>d(g)-d(v));for(let g of p){let v=g.configurations??a.configurations.map(b=>b.id);if(g.kind==="cut-invariant"){let b=v.map(y=>s.find(x=>x.configuration===y));i.claims.push(f3(g.id,g.kind,g.required!==!1,v,b.some(y=>!y||y.error!==void 0)?l1("A required configuration is unavailable."):eh(b)));continue}if(g.kind==="motion-clearance"){let b=s.find(w=>w.configuration===g.from),y=s.find(w=>w.configuration===g.to),x;if(!b||!y||b.error!==void 0||y.error!==void 0)x=l1("Motion endpoints are unavailable.");else try{if(x={status:"pass"},g.constraints){let w=a.claims.find(k=>k.id===g.constraints),M=i.claims.filter(k=>k.id===g.constraints);if(!w||w.kind!=="joint-constraints"||!M.length||M.some(k=>k.status!=="pass")||![g.from,g.to].every(k=>M.some(z=>z.configurations.includes(k))))x=l1("The motion needs verified endpoint joint constraints.");else{let k=s.find(z=>z.configuration===(w.configurations??a.configurations.map(A=>A.id))[0]);x=T9(g,w,b,k)}}if(x.status==="pass"){let w=[];for(let M of a.claims)if(M.kind==="retention")for(let k of M.links){let z=a.claims.find(A=>A.id===k.claim);k.installed&&k.fastening==="glued"&&z?.kind==="glue-contact"&&[g.from,g.to].every(A=>i.claims.some(S=>S.id===z.id&&S.configurations.includes(A)&&S.status==="pass"))&&w.push({a:z.a,b:z.b})}x=k9(g,b,y,f,w)}}catch(w){x={status:"unverified",code:"geometry-unresolved",message:w.message}}i.claims.push(f3(g.id,g.kind,g.required!==!1,[g.from,g.to],x,V9(g)));continue}for(let b of v){let y=s.find(k=>k.configuration===b),x=a.configurations.find(k=>k.id===b)?.materials,w=x?{...a,materials:{...a.materials,...x}}:a,M;if(!y||y.error!==void 0)M=l1("The configuration is unavailable.");else try{switch(g.kind){case"glue-contact":M=m4(g,y);break;case"tab-slot":M=d9(g,y,w);break;case"captured-shaft":M=m9(g,y,w);break;case"material-assignment":M=th(y,w);break;case"rigid-clearance":M=w9(g,y,f);break;case"assembly-access":M=z9(g,y,f);break;case"joint-constraints":{let k=s.find(z=>z.configuration===v[0]);M=k&&k.error===void 0?E9(g,y,k,f,a,i.claims):l1("The kinematic reference configuration is unavailable.");break}case"retention":M=L9(g,y,a,i.claims);break;case"stability":M=C9(g,y,f,i.claims,a);break;case"assembly-support":M=P9(g,y,a,i.claims);break;default:M=l1(`The ${g.kind} capability is not implemented; it cannot inherit a geometric-fit pass.`)}}catch(k){M={status:"unverified",code:"geometry-unresolved",message:`The geometric check could not complete: ${k.message}`}}i.claims.push(f3(g.id,g.kind,g.required!==!1,[b],M,V9(g)))}}let m=i.claims.filter(g=>g.required);i.status=m.some(g=>g.status==="fail")?"fail":m.some(g=>g.status==="unverified")?"unverified":"pass";for(let[g,v]of[["retention","Retention of permanent inventory."],["stability","Static stability under declared masses and gravity."],["assembly-access","Authored insertion and tool access paths."],["assembly-support","Support throughout the installation sequence."],["motion-clearance","Continuous nominal operating motion clearance."],["joint-constraints","Mechanism constraints and intended mobility."]]){let b=i.claims.filter(x=>x.kind===g&&x.required),y=new Set(b.filter(x=>x.status==="pass").flatMap(x=>x.configurations));(!b.length||b.some(x=>x.status!=="pass")||a.configurations.some(x=>!y.has(x.id)))&&i.uncovered.push(v)}return{kind:"report",report:i}}function f3(t,e,n,r,c,a=[]){return{id:t,kind:e,required:n,configurations:r,status:"unverified",code:"unverified",message:"",entities:a,measurements:{},assumptions:[],coverage:"none",...c}}function V9(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 eh(t){if(t.length<2)return l1("Cut invariance needs at least two declared configurations.");let e=t[0];if(!e.parts.length&&!e.hardware.length)return l1("There is no physical inventory to compare.");if(t.some(n=>n.parts.some(r=>r.cutLines===null||r.kerf===null)))return l1("Full nominal cutting-line and kerf metadata is required for invariance.");if(t.some(n=>n.legacyHardware||n.hardware.some(r=>!r.label)))return l1("Cross-pose hardware requires unique native labels.");for(let n of t){let r=n.hardware.map(c=>c.label);if(new Set(r).size!==r.length)return l1("Hardware labels are ambiguous across operating poses.");if(n.parts.length!==e.parts.length||n.hardware.length!==e.hardware.length)return{status:"fail",code:"inventory-changed",message:"Operating motion changed the manufacturing inventory."};for(let c of e.parts){let a=o2(n,{part:c.name,copy:c.copy});if(!a||!u4(c,a))return{status:"fail",code:"cut-geometry-changed",message:`Operating motion changed cut geometry/material for ${c.name} copy ${c.copy}.`}}for(let c of e.hardware){let a=n.hardware.find(s=>s.label===c.label);if(!a||c.kind!==a.kind||JSON.stringify(c.size)!==JSON.stringify(a.size)||Math.abs(P1(y1(c.to,c.from))-P1(y1(a.to,a.from)))>W)return{status:"fail",code:"hardware-changed",message:`Operating motion changed hardware ${c.label}.`}}}return{status:"pass",code:"cuts-invariant",message:"Nominal cut regions, cut lines, materials and inventory agree at the declared poses.",coverage:"discrete",assumptions:["This checks the declared configurations only; it does not bound behavior between samples."]}}function th(t,e){if(!t.parts.length)return l1("There are no sheet parts to assign a stock profile.");for(let n of t.parts){let r=e.materials&&Object.prototype.hasOwnProperty.call(e.materials,n.material)?e.materials[n.material]:void 0;if(!r)return l1(`No measured material profile is assigned to ${n.material||n.name}.`);if(n.thickness<r.thickness[0]-W||n.thickness>r.thickness[1]+W)return{status:"fail",code:"material-mismatch",message:`${n.name}: design thickness is outside the assigned stock profile.`};if(n.kerf===null)return l1("Compensation metadata is unavailable.")}return{status:"pass",code:"materials-assigned",message:"Every sheet part has a measured profile containing its nominal design thickness.",coverage:"bounded-fit"}}var nh=t=>"hardware"in t?`hardware ${t.hardware}`:`${t.part}${t.copy&&t.copy>1?` (copy ${t.copy})`:""}`;function w6(t){if(t.kind!=="report")return[];let e=new Map;for(let r of t.report.claims){if(r.status==="pass")continue;let c=`${r.status}\0${r.code}`,a=e.get(c)??{status:r.status,code:r.code,message:r.message,claims:[]};a.claims.push({id:r.id,configurations:r.configurations,bodies:r.entities.map(nh),measurements:r.measurements}),e.set(c,a)}let n=r=>r==="fail"?0:1;return[...e.values()].sort((r,c)=>n(r.status)-n(c.status)||c.claims.length-r.claims.length)}function $9(t){if(t.kind!=="report")return`${t.kind}: ${t.issues.map(c=>c.message).join("; ")}
|
|
3105
|
+
`;let e=w6(t);if(!e.length)return`All ${t.report.claims.length} claims pass.
|
|
3106
|
+
`;let n=c=>Array.isArray(c)?`${+c[0].toFixed(3)}..${+c[1].toFixed(3)}`:`${+c.toFixed(3)}`,r=[];for(let c of e){r.push(`${c.status} ${c.code} (${c.claims.length}): ${c.message}`);for(let a of c.claims){let s=Object.entries(a.measurements).slice(0,4).map(([o,i])=>`${o} ${n(i)}`).join(", ");r.push(` ${a.id}${a.configurations.length?` [${a.configurations.join(", ")}]`:""}${a.bodies.length?`: ${a.bodies.join(" / ")}`:""}${s?`; ${s}`:""}`)}}return r.join(`
|
|
2726
3107
|
`)+`
|
|
2727
|
-
`}var pl="0.9.0",gl="0.3";
|
|
3108
|
+
`}var rh=t=>{let e=0;for(let n=0,r=t.length-1;n<t.length;r=n++)e+=(t[r][0]-t[n][0])*(t[r][1]+t[n][1]);return e},i2=(t,e,n)=>(e.x-t.x)*(n.y-t.y)-(e.y-t.y)*(n.x-t.x),v5=(t,e)=>t.x===e.x&&t.y===e.y;function z6(t,e,n){let r={i:t,x:e,y:n};return r.prev=r,r.next=r,r}function ch(t,e){return t&&(e.next=t.next,e.prev=t,t.next.prev=e,t.next=e),e}function R9(t,e,n){let r=null,c=rh(t)>0===n;for(let a=0;a<t.length;a++){let s=c?a:t.length-1-a;r=ch(r,z6(e+s,t[s][0],t[s][1]))}if(r&&v5(r,r.next)){let a=r.next;x4(r),r=a}return r?r.next:null}function x4(t){t.next.prev=t.prev,t.prev.next=t.next}function k6(t,e){let n=e??t,r=t,c;do if(c=!1,v5(r,r.next)||v5(r.prev,r.next)){if(x4(r),r=n=r.prev,r===r.next)break;c=!0}else r=r.next;while(c||r!==n);return n}function ah(t,e){let n=z6(t.i,t.x,t.y),r=z6(e.i,e.x,e.y),c=t.next,a=e.prev;return t.next=e,e.prev=t,n.next=c,c.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function S6(t,e,n,r,c,a,s,o){return(n-t)*(o-e)-(r-e)*(s-t)>=0&&(c-n)*(o-r)-(a-r)*(s-n)>=0&&(t-c)*(o-a)-(e-a)*(s-c)>=0}function sh(t,e){return i2(t.prev,t,t.next)>0?i2(t,e,t.next)<=0&&i2(t,t.prev,e)<=0:i2(t,e,t.prev)>0||i2(t,t.next,e)>0}function oh(t,e){let n=t.x,r=t.y,c=e,a=-1/0,s=null;do{if(r<=c.y&&r>=c.next.y&&c.next.y!==c.y){let u=c.x+(r-c.y)*(c.next.x-c.x)/(c.next.y-c.y);if(u<=n&&u>a&&(a=u,s=c.x<c.next.x?c:c.next,u===n))return s}c=c.next}while(c!==e);if(!s)return null;let o=s,i=s.x,l=s.y,h=1/0;c=s;do{if(n>=c.x&&c.x>=i&&n!==c.x&&(r<l?S6(n,r,i,l,a,r,c.x,c.y):S6(a,r,i,l,n,r,c.x,c.y))){let u=Math.abs(r-c.y)/(n-c.x);sh(c,t)&&(u<h||u===h&&(c.x>s.x||c.x===s.x&&i2(s.prev,s,c.prev)>0&&i2(c.next,s,s.next)>0))&&(s=c,h=u)}c=c.next}while(c!==o);return s}function ih(t){let e=t.prev,n=t.next;if(i2(e,t,n)<=0)return!1;for(let r=n.next;r!==e;r=r.next)if(!v5(r,e)&&!v5(r,n)&&!v5(r,t)&&S6(e.x,e.y,t.x,t.y,n.x,n.y,r.x,r.y)&&i2(r.prev,r,r.next)<=0)return!1;return!0}function M4(t,e=[]){let n=[];if(t.length<3)return n;let r=R9(t,0,!0);if(!r||r===r.next)return n;let c=t.length,a=[];for(let h of e){let u=h.length>=3?R9(h,c,!1):null;if(c+=h.length,!u||u===u.next)continue;let f=u,d=u;do(d.x<f.x||d.x===f.x&&d.y<f.y)&&(f=d),d=d.next;while(d!==u);a.push(f)}a.sort((h,u)=>h.x-u.x||h.y-u.y);for(let h of a){let u=oh(h,r);if(!u)continue;let f=ah(u,h);k6(f,f.next),r=k6(u,u.next)}let s=k6(r),o=0,i=s;do o++,i=i.next;while(i!==s);let l=0;for(;o>3;){if(ih(s)){n.push([s.prev.i,s.i,s.next.i]);let h=s.next;x4(s),o--,s=h,l=0;continue}if(s=s.next,++l>o){let h=s,u=s;do i2(u.prev,u,u.next)>i2(h.prev,h,h.next)&&(h=u),u=u.next;while(u!==s);i2(h.prev,h,h.next)>0&&n.push([h.prev.i,h.i,h.next.i]);let f=h.next;x4(h),o--,s=f,l=0}}return o===3&&i2(s.prev,s,s.next)>0&&n.push([s.prev.i,s.i,s.next.i]),n}var lh=[[/walnut|dark/i,"#7b5538"],[/cherry|mahogany|red/i,"#a0613f"],[/oak/i,"#c9a571"],[/mdf|hardboard/i,"#b4966c"],[/cork/i,"#c49a6c"],[/felt|leather/i,"#8a6a52"],[/card|paper/i,"#ece6d8"],[/black/i,"#2b2b2b"],[/white/i,"#f1f1ee"],[/clear|acrylic|perspex|glass/i,"#cfe6ee"]];function C6(t){return lh.find(([e])=>e.test(t))?.[1]??"#dcc39a"}var hh=t=>/clear|acrylic|perspex|glass/i.test(t),F9=.01,uh=(t,[e,n,r])=>[t[0]*e+t[1]*n+t[2]*r+t[3],t[4]*e+t[5]*n+t[6]*r+t[7],t[8]*e+t[9]*n+t[10]*r+t[11]],fh=t=>t[0]*(t[5]*t[10]-t[6]*t[9])-t[1]*(t[4]*t[10]-t[6]*t[8])+t[2]*(t[4]*t[9]-t[5]*t[8]),D9=(t,e)=>b1(t)>0===e?t:[...t].reverse();function A6(t,e,n,r,c,a){let[s,...o]=e;if(!s||s.length<3)return;let i=[D9(s,!0),...o.map(m=>D9(m,!1))],l=i.flat(),h=M4(i[0],i.slice(1));if(!h.length)return;let u=l.length,f=t.positions.length/3;for(let[m,g]of l)t.positions.push(...c([m,g,n]));for(let[m,g]of l)t.positions.push(...c([m,g,r]));let d=(m,g,v)=>a?t.indices.push(m,v,g):t.indices.push(m,g,v);for(let[m,g,v]of h)d(f+u+m,f+u+g,f+u+v),d(f+v,f+g,f+m);let p=0;for(let m of i){for(let g=0;g<m.length;g++){let v=f+p+g,b=f+p+(g+1)%m.length;d(v,b,b+u),d(v,b+u,v+u)}p+=m.length}}var L6=(t,e,n,r,c={})=>({name:t,kind:e,material:n,color:r,positions:[],indices:[],...c});function dh(t,e,n,r){let c=[];for(let a of t.marks??[]){if(r.has(a.layer))continue;let s=a.mode==="line"?[...a.lines,...a.regions.map(l=>[...l,l[0]])]:a.lines,o=s1([...a.mode==="fill"?a.regions:[],...g3(s,n)]),i=K1(o,e);i.length&&c.push({layer:a.layer,color:a.color,side:a.side,regions:i})}return c}function mh(t,e,n,r,c,a){let s=t.thickness,o=(t.marks??[]).filter(m=>c.has(m.layer)&&m.side==="front"),i=o.length?g0(t.outline,g3(o.flatMap(m=>m.lines),n.slitWidth)):t.outline,l=r?t.bends:void 0,h=m=>uh(e,l?.length?y3(l,s,m):m),u=fh(e)<0,f=t.material??"material",d=[],p=L6(t.name,"part",f,C6(f),{part:t.name,copy:t.copy,instance:a,clear:hh(f)});for(let m of b3(i,l))A6(p,m,0,s,h,u);if(d.push(p),n.markHeight>0)for(let m of dh(t,i,n.lineWidth,c)){if(m.side==="back"&&n.layout==="flat")continue;let[g,v]=m.side==="front"?[s-F9,s+n.markHeight]:[-n.markHeight,F9],b=L6(`${t.name} ${m.layer}`,"mark",m.layer,m.color,{part:t.name,copy:t.copy,instance:a});for(let y of b3(m.regions,l))A6(b,y,g,v,h,u);b.indices.length&&d.push(b)}return d}function ph(t){let e=N2[t.kind],n=Q2[t.kind]??e?.color??"#c8c8c8",r=L6(t.label??t.kind,"hardware",t.kind,n,{metal:e?.metal,clear:t.kind==="glass"}),c=t.to.map((d,p)=>d-t.from[p]),a=Math.hypot(...c),s=Array.isArray(t.size)?t.size:[t.size,t.size];if(t.sides===0&&!Array.isArray(t.size)&&t.size>0){let d=t.size/2,p=12,m=24;for(let g=0;g<=p;g++)for(let v=0;v<m;v++){let b=Math.PI*g/p,y=2*Math.PI*v/m;r.positions.push(t.from[0]+d*Math.sin(b)*Math.cos(y),t.from[1]+d*Math.sin(b)*Math.sin(y),t.from[2]+d*Math.cos(b))}for(let g=0;g<p;g++)for(let v=0;v<m;v++){let b=g*m+v,y=g*m+(v+1)%m;r.indices.push(b,b+m,y+m,b,y+m,y)}return r}if(!(a>0)||!(s[0]>0))return null;let{axis:o,u:i,v:l}=j4(t),h=Array.isArray(t.size)?4:Math.min(128,Math.max(3,Math.floor(t.sides)||24)),u=Array.isArray(t.size)?[[-s[0]/2,-s[1]/2],[s[0]/2,-s[1]/2],[s[0]/2,s[1]/2],[-s[0]/2,s[1]/2]]:Array.from({length:h},(d,p)=>{let m=2*Math.PI*p/h;return[s[0]/2*Math.sin(m),s[0]/2*Math.cos(m)]});return A6(r,[u],0,a,([d,p,m])=>[t.from[0]+d*i[0]+p*l[0]+m*o[0],t.from[1]+d*i[1]+p*l[1]+m*o[1],t.from[2]+d*i[2]+p*l[2]+m*o[2]],!1),r}function gh(t,e){let n=u=>{let[f,d,p,m]=[1/0,1/0,-1/0,-1/0];for(let g of u.outline)for(let[v,b]of g)f=Math.min(f,v),d=Math.min(d,b),p=Math.max(p,v),m=Math.max(m,b);return[f,d,p,m]},r=t.map(n),c=r.reduce((u,[f,d,p,m])=>u+(p-f+e)*(m-d+e),0),a=Math.max(Math.sqrt(c)*1.3,...r.map(([u,,f])=>f-u)),s=t.map((u,f)=>f).sort((u,f)=>r[f][3]-r[f][1]-(r[u][3]-r[u][1])),o=new Array(t.length),i=0,l=0,h=0;for(let u of s){let[f,d,p,m]=r[u];i>0&&i+(p-f)>a&&(i=0,l+=h+e,h=0),o[u]=[1,0,0,i-f,0,1,0,l-d,0,0,1,0,0,0,0,1],i+=p-f+e,h=Math.max(h,m-d)}return o}function w4(t,e={}){let n={layout:e.layout??"assembled",markHeight:e.markHeight??.1,lineWidth:e.lineWidth??.3,hardware:e.hardware??!0,gap:e.gap??5,slitWidth:e.slitWidth??.2},r=new Set((t.layers??[{name:"cut",mode:"cut"}]).filter(i=>i.mode==="cut").map(i=>i.name)),c=n.layout==="flat"||!t.assembly.length,a=(c?t.flat??t.assembly:t.assembly).filter(i=>i.outline.length),s=c?gh(a,n.gap):a.map(i=>i.matrix),o=a.flatMap((i,l)=>mh(i,s[l],{...n,layout:c?"flat":"assembled"},!c,r,l));if(!c&&n.hardware)for(let i of t.hardware??[]){let l=ph(i);l&&o.push(l)}return o}var vh=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}return t})();function yh(t){let e=4294967295;for(let n=0;n<t.length;n++)e=vh[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function q9(t){let e=new TextEncoder,n=[],r=[],c=0,a=0,s=23585;for(let f of t){let d=e.encode(f.name),p=yh(f.data),m=new DataView(new ArrayBuffer(30));m.setUint32(0,67324752,!0),m.setUint16(4,20,!0),m.setUint16(6,2048,!0),m.setUint16(8,0,!0),m.setUint16(10,a,!0),m.setUint16(12,s,!0),m.setUint32(14,p,!0),m.setUint32(18,f.data.length,!0),m.setUint32(22,f.data.length,!0),m.setUint16(26,d.length,!0),m.setUint16(28,0,!0),n.push(new Uint8Array(m.buffer),d,f.data);let g=new DataView(new ArrayBuffer(46));g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint16(8,2048,!0),g.setUint16(10,0,!0),g.setUint16(12,a,!0),g.setUint16(14,s,!0),g.setUint32(16,p,!0),g.setUint32(20,f.data.length,!0),g.setUint32(24,f.data.length,!0),g.setUint16(28,d.length,!0),g.setUint32(42,c,!0),r.push(new Uint8Array(g.buffer),d),c+=30+d.length+f.data.length}let o=r.reduce((f,d)=>f+d.length,0),i=new DataView(new ArrayBuffer(22));i.setUint32(0,101010256,!0),i.setUint16(8,t.length,!0),i.setUint16(10,t.length,!0),i.setUint32(12,o,!0),i.setUint32(16,c,!0);let l=[...n,...r,new Uint8Array(i.buffer)],h=new Uint8Array(l.reduce((f,d)=>f+d.length,0)),u=0;for(let f of l)h.set(f,u),u+=f.length;return h}var N9=t=>{let e=/^#?([0-9a-f]{6})$/i.exec(t.trim()),n=e?parseInt(e[1],16):13158600;return[n>>16&255,n>>8&255,n&255]},P6=t=>{let e=(Math.abs(t)<5e-7?0:t).toFixed(4);return e.includes(".")?e.replace(/\.?0+$/,""):e},k4=t=>t.copy&&t.copy>1?`${t.name} (${t.copy})`:t.name;function U9(t,e,n,r){let c=t[n*3]-t[e*3],a=t[n*3+1]-t[e*3+1],s=t[n*3+2]-t[e*3+2],o=t[r*3]-t[e*3],i=t[r*3+1]-t[e*3+1],l=t[r*3+2]-t[e*3+2],h=a*l-s*i,u=s*o-c*l,f=c*i-a*o,d=Math.hypot(h,u,f)||1;return[h/d,u/d,f/d]}function I6(t){let e=t.reduce((a,s)=>a+s.indices.length/3,0),n=new DataView(new ArrayBuffer(84+50*e)),r=new TextEncoder().encode("KerfScript model, millimetres");new Uint8Array(n.buffer).set(r.slice(0,80)),n.setUint32(80,e,!0);let c=84;for(let a of t)for(let s=0;s<a.indices.length;s+=3){let[o,i,l]=[a.indices[s],a.indices[s+1],a.indices[s+2]];for(let h of U9(a.positions,o,i,l))n.setFloat32(c,h,!0),c+=4;for(let h of[o,i,l])for(let u=0;u<3;u++)n.setFloat32(c,a.positions[h*3+u],!0),c+=4;c+=2}return new Uint8Array(n.buffer)}var E6=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function V6(t){let e=[],n=h=>{let u=`${h.material}\0${h.color}`,f=e.indexOf(u);return f<0&&(f=e.push(u)-1),f},r=[],c=[],a=new Map;t.forEach((h,u)=>{let f=h.instance===void 0?`h${u}`:`p${h.instance}`;a.set(f,[...a.get(f)??[],h])});let s=2;for(let h of a.values()){let u=[];for(let f of h){let d=[];for(let m=0;m<f.positions.length;m+=3)d.push(`<vertex x="${P6(f.positions[m])}" y="${P6(f.positions[m+1])}" z="${P6(f.positions[m+2])}"/>`);let p=[];for(let m=0;m<f.indices.length;m+=3)p.push(`<triangle v1="${f.indices[m]}" v2="${f.indices[m+1]}" v3="${f.indices[m+2]}"/>`);r.push(`<object id="${s}" type="model" name="${E6(k4(f))}" pid="1" pindex="${n(f)}"><mesh><vertices>${d.join("")}</vertices><triangles>${p.join("")}</triangles></mesh></object>`),u.push(s++)}u.length===1?c.push(`<item objectid="${u[0]}"/>`):(r.push(`<object id="${s}" type="model" name="${E6(k4(h[0]))}"><components>${u.map(f=>`<component objectid="${f}"/>`).join("")}</components></object>`),c.push(`<item objectid="${s++}"/>`))}let i=`<?xml version="1.0" encoding="UTF-8"?>
|
|
3109
|
+
<model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02"><metadata name="Application">KerfScript</metadata><resources><basematerials id="1">${e.map(h=>{let[u,f]=h.split("\0"),[d,p,m]=N9(f),g=[d,p,m].map(v=>v.toString(16).padStart(2,"0")).join("").toUpperCase();return`<base name="${E6(u)}" displaycolor="#${g}FF"/>`}).join("")}</basematerials>${r.join("")}</resources><build>${c.join("")}</build></model>
|
|
3110
|
+
`,l=new TextEncoder;return q9([{name:"[Content_Types].xml",data:l.encode(`<?xml version="1.0" encoding="UTF-8"?>
|
|
3111
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml"/></Types>
|
|
3112
|
+
`)},{name:"_rels/.rels",data:l.encode(`<?xml version="1.0" encoding="UTF-8"?>
|
|
3113
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="/3D/3dmodel.model" Id="rel0" Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel"/></Relationships>
|
|
3114
|
+
`)},{name:"3D/3dmodel.model",data:l.encode(i)}])}var T6=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)};function H6(t){let e=[],n=0,r=[],c=[],a=[],s=[],o=[],i=[],l=y=>{let x=new Uint8Array(y.buffer,y.byteOffset,y.byteLength);return r.push({buffer:0,byteOffset:n,byteLength:x.length,target:34962}),e.push(x),n+=x.length,r.length-1};for(let y of t){if(!y.indices.length)continue;let x=y.indices.length,w=new Float32Array(x*3),M=new Float32Array(x*3),k=[1/0,1/0,1/0],z=[-1/0,-1/0,-1/0];for(let L=0;L<x;L+=3){let[T,q,P]=[y.indices[L],y.indices[L+1],y.indices[L+2]],[F,j,_]=U9(y.positions,T,q,P);[T,q,P].forEach((Q,H)=>{let B=y.positions[Q*3]/1e3,Y=y.positions[Q*3+2]/1e3,e1=-y.positions[Q*3+1]/1e3,X=(L+H)*3;w.set([B,Y,e1],X),M.set([F,_,-j],X),[B,Y,e1].forEach((M1,v1)=>{k[v1]=Math.min(k[v1],M1),z[v1]=Math.max(z[v1],M1)})})}let A=l(w);c.push({bufferView:A,componentType:5126,count:x,type:"VEC3",min:k,max:z});let S=l(M);c.push({bufferView:S,componentType:5126,count:x,type:"VEC3"});let C=`${y.material}\0${y.color}\0${y.metal?1:0}\0${y.clear?1:0}`,I=i.indexOf(C);if(I<0){let[L,T,q]=N9(y.color);o.push({name:y.material,pbrMetallicRoughness:{baseColorFactor:[T6(L),T6(T),T6(q),y.clear?.45:1],metallicFactor:y.metal?.6:0,roughnessFactor:y.metal?.35:.85},...y.clear&&{alphaMode:"BLEND"}}),I=i.push(C)-1}a.push({name:k4(y),primitives:[{attributes:{POSITION:c.length-2,NORMAL:c.length-1},material:I}]}),s.push({name:k4(y),mesh:a.length-1,extras:{kind:y.kind,material:y.material,...y.part!==void 0&&{part:y.part,copy:y.copy}}})}let h={asset:{version:"2.0",generator:"KerfScript"},scene:0,scenes:[{nodes:s.map((y,x)=>x)}],nodes:s,meshes:a,materials:o,accessors:c,bufferViews:r,buffers:[{byteLength:n}]},f=new TextEncoder().encode(JSON.stringify(h)),d=(4-f.length%4)%4,p=(4-n%4)%4,m=20+f.length+d+8+n+p,g=new Uint8Array(m),v=new DataView(g.buffer);v.setUint32(0,1179937895,!0),v.setUint32(4,2,!0),v.setUint32(8,m,!0),v.setUint32(12,f.length+d,!0),v.setUint32(16,1313821514,!0),g.set(f,20),g.fill(32,20+f.length,20+f.length+d);let b=20+f.length+d;v.setUint32(b,n+p,!0),v.setUint32(b+4,5130562,!0),b+=8;for(let y of e)g.set(y,b),b+=y.length;return g}function B9(t,e,n={}){let r=w4(t,n);return e==="stl"?I6(r):e==="3mf"?V6(r):H6(r)}function _9(t){let e=2166136261,n=16777619;for(let r=0;r<t.length;r++){let c=t.charCodeAt(r);e=Math.imul(e^c,16777619),n=Math.imul(n^c,1540483477)}return`${(e>>>0).toString(36)}${(n>>>0).toString(36)}${t.length}`}var se=t=>Math.round(t*1e3)/1e3,O6=t=>t.map(e=>e.map(([n,r])=>[se(n),se(r)]));function bh(t){let e=JSON.stringify([t.sheets.map(r=>[r.svg,r.back?.svg??"",r.width,r.height,r.material,r.thickness]),t.parts.map(r=>[r.name,r.qty,r.thickness,r.material,r.kerf,r.stack,r.glued,r.mirrored])]),n=JSON.stringify([[...t.assembly,...t.flat].map(r=>[r.name,r.copy,r.placed,r.thickness,r.material,r.matrix.map(se),r.bends,r.step,O6(r.outline),(r.marks??[]).map(c=>[c.layer,c.side,O6(c.regions),O6(c.lines)])]),t.hardware,t.steps]);return{files:_9(e),view:_9(n)}}function xh(t,e){let n=t.initial;if(t.options)return t.options.map(a=>a.value);if(t.type==="boolean")return[!0,!1];if(t.type==="string"){let a=String(n??"");if(!a)return["","Sample"];let s=[...a].reverse().join("");return[...new Set([a,a.slice(0,Math.ceil(a.length/2)),s===a?a+a:s])]}if(Array.isArray(n))return"a list of numbers";if(typeof n!="number")return"not a number, text or choice";if(t.min===void 0||t.max===void 0||!(t.max>t.min)){let a=Math.abs(n)>0?Math.abs(n)/2:1;return[n-a,n,n+a]}let r=a=>t.step?se(t.min+Math.round((a-t.min)/t.step)*t.step):se(a),c=Array.from({length:e},(a,s)=>r(t.min+(t.max-t.min)*s/(e-1)));return[...new Set([...c,n])].sort((a,s)=>a-s)}function j9(t,e={},n=5){let r=c5(t).parameters,c={...e.params},a=[];for(let s of r){if(s.drive){a.push({name:s.name,tried:[],effect:"skipped",reason:"it drives the motion"});continue}if(!Ke(s,c,r)){a.push({name:s.name,tried:[],effect:"skipped",reason:`it applies only when ${s.when}`});continue}let o=xh(s,Math.max(3,n));if(typeof o=="string"){a.push({name:s.name,tried:[],effect:"skipped",reason:`it is ${o}`});continue}let i=[],l=[];for(let p of o)try{i.push(bh(Qe(t,{...e,params:{...c,[s.name]:p}})))}catch(m){i.push(null),l.push({value:p,message:m.message})}let h=i.filter(p=>p!==null),u=new Set(h.map(p=>p.files)).size>1,f=new Set(h.map(p=>`${p.files} ${p.view}`)).size>1,d={name:s.name,tried:o,effect:h.length<2?"failed":u?"files":f?"view":"nothing",...l.length&&{errors:l}};if(d.effect==="files"||d.effect==="view"){let p=g=>i[g]?`${i[g].files} ${i[g].view}`:`x${g}`,m=[];if(s.options){let g=new Map;o.forEach((v,b)=>g.set(p(b),[...g.get(p(b))??[],v]));for(let[v,b]of g)b.length>1&&!v.startsWith("x")&&m.push(b)}else{let g=0;for(let v=1;v<=o.length;v++)(v===o.length||p(v)!==p(g))&&(v-g>1&&i[g]&&m.push(o.slice(g,v)),g=v)}m.length&&(d.same=m)}a.push(d)}return a}function G9(t){let e=c=>JSON.stringify(c),n=["Each setting tried across its range, the others as they are:"],r=!1;for(let c of t){if(c.effect==="skipped"){n.push(`${c.name}: not tried, as ${c.reason}`);continue}c.effect==="failed"?(r=!0,n.push(`${c.name}: the program stops at ${c.errors?.length??0} of the ${c.tried.length} values tried`)):c.effect==="nothing"?(r=!0,n.push(`${c.name}: changes nothing at ${c.tried.map(e).join(", ")}`)):c.effect==="view"?n.push(`${c.name}: changes only the assembled view, not the files`):n.push(`${c.name}: changes the files`);for(let a of c.same??[])n.push(typeof a[0]=="number"?` from ${e(a[0])} to ${e(a[a.length-1])} it changes nothing`:` ${a.slice(0,-1).map(e).join(", ")} and ${e(a[a.length-1])} give the same result`);for(let a of c.errors??[])n.push(` at ${e(a.value)}: ${a.message}`)}return{lines:n,idle:r}}var Mh="0.10.0",wh="0.3";
|
|
2728
3115
|
/*! Bundled license information:
|
|
2729
3116
|
|
|
2730
3117
|
opentype.js/dist/opentype.module.js:
|