@mylasertools/kerfscript 0.10.0 → 0.11.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 +199 -0
- package/LANGUAGE.md +90 -42
- package/dist/assembly.d.cts +20 -1
- package/dist/assembly.d.ts +20 -1
- package/dist/cli.js +2236 -375
- package/dist/colors.d.cts +4 -0
- package/dist/colors.d.ts +4 -0
- package/dist/effects.d.cts +2 -2
- package/dist/effects.d.ts +2 -2
- package/dist/evaluator.d.cts +9 -1
- package/dist/evaluator.d.ts +9 -1
- package/dist/export/mesh.d.cts +16 -3
- package/dist/export/mesh.d.ts +16 -3
- package/dist/export/model.d.cts +4 -2
- package/dist/export/model.d.ts +4 -2
- package/dist/export/pages.d.cts +23 -0
- package/dist/export/pages.d.ts +23 -0
- package/dist/geometry.d.cts +20 -0
- package/dist/geometry.d.ts +20 -0
- package/dist/hardware.d.cts +2 -0
- package/dist/hardware.d.ts +2 -0
- package/dist/highlight.cjs +1 -1
- package/dist/highlight.js +1 -1
- package/dist/index.cjs +1308 -77
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1308 -77
- package/dist/instructions.d.cts +27 -0
- package/dist/instructions.d.ts +27 -0
- package/dist/language.cjs +1281 -50
- package/dist/language.js +1281 -50
- package/dist/libraries.cjs +1262 -36
- package/dist/libraries.js +1262 -36
- package/dist/lights.d.cts +38 -0
- package/dist/lights.d.ts +38 -0
- package/dist/png.d.cts +14 -0
- package/dist/png.d.ts +14 -0
- package/dist/render.d.cts +5 -0
- package/dist/render.d.ts +5 -0
- package/dist/signatures.cjs +75 -4
- package/dist/signatures.js +75 -4
- package/dist/text.d.cts +23 -0
- package/dist/text.d.ts +23 -0
- package/dist/verify/types.d.cts +6 -0
- package/dist/verify/types.d.ts +6 -0
- package/docs/3d-files.md +29 -8
- package/docs/cli.md +12 -1
- package/docs/customizer.md +13 -0
- package/docs/javascript.md +6 -1
- package/docs/layers.md +24 -1
- package/docs/library.md +454 -16
- package/docs/parts-and-sheets.md +205 -28
- package/docs/verification.md +1 -1
- package/docs/versions.md +2 -2
- package/package.json +1 -1
package/dist/language.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*! @mylasertools/kerfscript | (c) MyLaserTools | AGPL-3.0-only or commercial licence, see COMMERCIAL-LICENSE.md. Includes Clipper2 (BSL-1.0), opentype.js, tiny-inflate and string.prototype.codepointat (MIT), see THIRD-PARTY-NOTICES.md. */
|
|
2
|
-
var re=Object.defineProperty;var se=(n,e,t)=>e in n?re(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var ie=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var F=(n,e,t)=>se(n,typeof e!="symbol"?e+"":e,t);var W6=ie((ii,j6)=>{j6.exports={}});var x0=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&n.type==="range",A0=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&n.type==="function",W4=n=>typeof n=="number",t0=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&n.type==="record",i0=(n,e)=>n&&Object.prototype.hasOwnProperty.call(n,e)?n[e]:void 0;function g5(n,e,t=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&t<32){for(let c of e)g5(n,c,t+1);return}throw new Error(`Setting "${n}" must be a number, string, boolean or list`)}}function b3(n,e){let t=[];if(n.step===0||(n.step>0?n.start>n.end:n.start<n.end))return t;let c=Math.floor((n.end-n.start)/n.step+1e-9)+1;if(c>e)throw new Error(`a range of ${c} items is more than the limit of ${e}`);for(let a=0;a<c;a++)t.push(n.start+a*n.step);return t}function T1(n){return n===void 0||n===!1||n===0||n===""?!1:Array.isArray(n)?n.length>0:typeof n=="number"?!Number.isNaN(n):!0}var j4=(n,e,t)=>x0(n)&&x0(e)?n.start===e.start&&n.step===e.step&&n.end===e.end:t0(n)&&t0(e)?n.fields.size===e.fields.size&&[...n.fields].every(([c,a])=>e.fields.has(c)&&k2(a,e.fields.get(c),t)):n===e;function k2(n,e,t){if(t?.(),!Array.isArray(n)||!Array.isArray(e))return j4(n,e,t);let c=new Map,a=[],r=(s,i)=>{let o=c.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||c.set(s,o=new Set),o.add(i),a.push([s,i,0]),!0)};if(!r(n,e))return!1;for(;a.length;){let s=a[a.length-1];if(s[2]===s[0].length){a.pop();continue}let i=s[0][s[2]],o=s[1][s[2]++];if(t?.(),Array.isArray(i)&&Array.isArray(o)?!r(i,o):!j4(i,o,t))return!1}return!0}function Z1(n){return n===void 0?"undef":Array.isArray(n)?"list":x0(n)?"range":A0(n)?"function":t0(n)?"record":typeof n}function oe(n){return n===void 0?"undef":typeof n=="string"?JSON.stringify(n):typeof n=="number"?W0(n):x0(n)?`[${W0(n.start)}:${W0(n.step)}:${W0(n.end)}]`:A0(n)?`function(${n.params.map(e=>e.name).join(", ")})`:t0(n)?"{}":String(n)}function L2(n,e,t=!1){if(typeof n=="string"&&!t)return{text:n.length>e?n.slice(0,Math.max(e,0)):n,whole:n.length<=e};let c=[],a=0,r=l=>{c.push(l),a+=l.length},s=[],i=n;for(;;){Array.isArray(i)?(r("["),s.push({items:i,i:0,close:"]"})):t0(i)&&i.fields.size?(r("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):r(oe(i));let l=!1;for(;s.length&&!l&&a<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&r(", "),h.keys&&r(`${h.keys[h.i]} = `),i=h.items[h.i++],l=!0):(s.pop(),r(h.close))}if(!l||a>e)break}let o=c.join("");return a>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function X4(n,e,t){let c=[],a=0;for(let r of n){c.length&&(a+=e.length);let s=L2(r,t-a);if(!s.whole)return;a+=s.text.length,c.push(s.text)}return c.join(e)}function U1(n){let e=L2(n,200,!0);return e.whole?e.text:e.text+"..."}var I1=n=>typeof n=="string"?n:U1(n);function e0(n){let e=!1;for(;Array.isArray(n)&&n.length===1;)n=n[0],e=!0;return Array.isArray(n)?n.length?NaN:0:e&&(n===void 0||typeof n=="boolean")?n===void 0?0:NaN:typeof n=="object"?NaN:Number(n)}function W0(n){return Number.isInteger(n)?String(n):String(Number(n.toPrecision(10)))}function S2(n,e=.02){let t=[],c=[],a=[],r=[0,0],s=[0,0],i=l=>{a.length>=2&&(l?t:c).push(a),a=[]},o=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of n)if(l.type==="M")i(!1),r=s=[l.x,l.y],a=[s];else if(l.type==="L")s=[l.x,l.y],a.push(s);else if(l.type==="Q"){let[h,f]=s,u=o(Math.hypot(l.x1-h,l.y1-f)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=u;d++){let m=d/u,p=1-m;a.push([p*p*h+2*p*m*l.x1+m*m*l.x,p*p*f+2*p*m*l.y1+m*m*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,f]=s,u=o(Math.hypot(l.x1-h,l.y1-f)+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<=u;d++){let m=d/u,p=1-m;a.push([p*p*p*h+3*p*p*m*l.x1+3*p*m*m*l.x2+m*m*m*l.x,p*p*p*f+3*p*p*m*l.y1+3*p*m*m*l.y2+m*m*m*l.y])}s=[l.x,l.y]}else i(!0),s=r,a=[r];return i(!1),{closed:t,open:c}}function M3(n,e=Math.PI/2,t){let c=b=>/^[a-zA-Z]$/.test(b),a=n.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],r=[],s=0,i="",o=0,l=0,h=0,f=0,u=0,d=0,m=0,p=0,v="",g=()=>{let b=a[s++];if(b===void 0||c(b))throw new Error(`Bad path data near "${b??"end"}"`);return Number(b)},M=()=>{let b=a[s];if(b===void 0)throw new Error("Bad path data: missing arc flag");return b.length>1&&(b[0]==="0"||b[0]==="1")&&!b.includes(".")?(a[s]=b.slice(1),Number(b[0])):(s++,Number(b))};try{y()}catch(b){if(!t)throw b;t(b.message)}return r;function y(){for(;s<a.length;){if(c(a[s]))i=a[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${a[s]}": Z takes no numbers`)}else throw new Error("Path data must start with a command");let b=i===i.toLowerCase(),w=i.toUpperCase(),x=b?o:0,z=b?l:0;if(w==="M")o=x+g(),l=z+g(),h=o,f=l,r.push({type:"M",x:o,y:l}),i=b?"l":"L";else if(w==="L")o=x+g(),l=z+g(),r.push({type:"L",x:o,y:l});else if(w==="H")o=x+g(),r.push({type:"L",x:o,y:l});else if(w==="V")l=z+g(),r.push({type:"L",x:o,y:l});else if(w==="C"||w==="S"){let L,S;if(w==="C")L=x+g(),S=z+g();else{let V=v==="C"||v==="S";L=V?2*o-u:o,S=V?2*l-d:l}let k=x+g(),E=z+g();o=x+g(),l=z+g(),u=k,d=E,r.push({type:"C",x1:L,y1:S,x2:k,y2:E,x:o,y:l})}else if(w==="Q"||w==="T"){let L,S;if(w==="Q")L=x+g(),S=z+g();else{let k=v==="Q"||v==="T";L=k?2*o-m:o,S=k?2*l-p:l}o=x+g(),l=z+g(),m=L,p=S,r.push({type:"Q",x1:L,y1:S,x:o,y:l})}else if(w==="A"){let L=g(),S=g(),k=g(),E=M(),V=M(),T=x+g(),H=z+g();r.push(...le(o,l,L,S,k,E,V,T,H,e)),o=T,l=H}else if(w==="Z")r.push({type:"Z"}),o=h,l=f;else throw new Error(`Unknown path command "${i}"`);v=w}}}function le(n,e,t,c,a,r,s,i,o,l=Math.PI/2){if(t===0||c===0||n===i&&e===o)return[{type:"L",x:i,y:o}];t=Math.abs(t),c=Math.abs(c);let h=a*Math.PI/180,f=Math.cos(h),u=Math.sin(h),d=(n-i)/2,m=(e-o)/2,p=f*d+u*m,v=-u*d+f*m,g=p*p/(t*t)+v*v/(c*c);g>1&&(t*=Math.sqrt(g),c*=Math.sqrt(g));let M=t*t*c*c-t*t*v*v-c*c*p*p,y=t*t*v*v+c*c*p*p,b=Math.sqrt(Math.max(0,M/y));r===s&&(b=-b);let w=b*t*v/c,x=-b*c*p/t,z=f*w-u*x+(n+i)/2,L=u*w+f*x+(e+o)/2,S=(O,R,N,q)=>Math.atan2(O*q-R*N,O*N+R*q),k=S(1,0,(p-w)/t,(v-x)/c),E=S((p-w)/t,(v-x)/c,(-p-w)/t,(-v-x)/c);!s&&E>0&&(E-=2*Math.PI),s&&E<0&&(E+=2*Math.PI);let V=Math.ceil(Math.abs(E)/l),T=[],H=O=>[z+t*Math.cos(O)*f-c*Math.sin(O)*u,L+t*Math.cos(O)*u+c*Math.sin(O)*f],D=O=>[-t*Math.sin(O)*f-c*Math.cos(O)*u,-t*Math.sin(O)*u+c*Math.cos(O)*f];for(let O=0;O<V;O++){let R=k+E*O/V,N=k+E*(O+1)/V,q=4/3*Math.tan((N-R)/4),Y=H(R),_=H(N),c1=D(R),w1=D(N);T.push({type:"C",x1:Y[0]+q*c1[0],y1:Y[1]+q*c1[1],x2:_[0]-q*w1[0],y2:_[1]-q*w1[1],x:_[0],y:_[1]})}return T}var j1=Math.PI/180;function e6(n,e,t,c){if(typeof n=="number"&&typeof e=="number")return n-e;if(typeof n=="string"&&typeof e=="string")return n<e?-1:n>e?1:0;if(Array.isArray(n)&&Array.isArray(e)){for(let a=0;a<Math.min(n.length,e.length);a++){c();let r=e6(n[a],e[a],t,c);if(r)return r}return n.length-e.length}throw new Error(`${t}() can only order numbers, strings or lists of them, not ${Z1(n)} and ${Z1(e)}`)}function x5(n,e,t){let c=Y1(n,e,t);return(c.length&&Array.isArray(c[0])&&Array.isArray(c[0][0])?c.flatMap(r=>Y1(r,e,t)):c).map(r=>{if(!Array.isArray(r)||r.length<2)throw new Error(`${e}() needs points [x, y], got ${Z1(r)}`);return[e1(r[0],e),e1(r[1],e)]})}function he(n,e,t){let c=Y1(n,e,t);return c.length&&Array.isArray(c[0])&&Array.isArray(c[0][0])?c.map(a=>x5(a,e,t)):[x5(c,e,t)]}var K=(n,e,t)=>({params:n.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:n.endsWith("..."),order:t,run:e});function t6(n,e,t){return n.order?[]:n.params.filter((c,a)=>a<e.length&&t.has(c))}function n6(n,e,t){if(n.rest){let r=[...e];return n.params.forEach((s,i)=>{t.has(s)&&(r[i]=t.get(s))}),r}if(!n.order)return n.params.map((r,s)=>t.has(r)?t.get(r):e[s]);let c=e.length+n.params.filter(r=>t.has(r)).length,a=n.order(c).filter(r=>!t.has(r));return n.params.map(r=>t.has(r)?t.get(r):e[a.indexOf(r)])}function y5(n,e,t,c){let a=X4(n,e,t.maxLength);if(a===void 0)throw new Error(`${c}(): the text would be longer than the limit of ${t.maxLength} characters`);return t.step(Math.ceil(a.length/8)),a}function e1(n,e){if(typeof n!="number")throw new Error(`${e}() needs a number, got ${Z1(n)}`);return n}function Y1(n,e,t){if(Array.isArray(n))return n;if(x0(n))return b3(n,t.maxLength);if(typeof n=="string")return[...n];throw new Error(`${e}() needs a list, got ${Z1(n)}`)}var ue=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function c6(n,e,t){if(ue.has(n))return 0;let c=0;for(let a of e)if(typeof a=="string")c+=a.length;else if(Array.isArray(a))c+=n==="len"?0:a.length;else if(x0(a)&&a.step!==0){let r=Math.floor((a.end-a.start)/a.step)+1;r>0&&(c+=Math.min(r,t+1))}return c}var o0=n=>K("x",e=>typeof e[0]=="number"?w0(n(e[0])):void 0);function w0(n){let e=Math.round(n);return Math.abs(n-e)<1e-12?e:n}function a6(n){let e=Math.floor(n)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}var x3=new Map;function fe(n){let e=x3.get(n);if(e)return e;let t=a6(n),c=Array.from({length:256},(a,r)=>r);for(let a=255;a>0;a--){let r=Math.floor(t()*(a+1));[c[a],c[r]]=[c[r],c[a]]}e=new Uint8Array(512);for(let a=0;a<512;a++)e[a]=c[a&255];return x3.size>64&&x3.clear(),x3.set(n,e),e}var b5=n=>n*n*n*(n*(n*6-15)+10);function e2(n,e,t,c){let a=n&15,r=a<8?e:t,s=a<4?t:a===12||a===14?e:c;return((a&1)===0?r:-r)+((a&2)===0?s:-s)}function de(n,e,t,c){let a=fe(c),r=Math.floor(n),s=Math.floor(e),i=Math.floor(t);n-=r,e-=s,t-=i;let o=r&255,l=s&255,h=i&255,f=b5(n),u=b5(e),d=b5(t),m=a[o]+l,p=a[m]+h,v=a[m+1]+h,g=a[o+1]+l,M=a[g]+h,y=a[g+1]+h,b=(w,x,z)=>x+w*(z-x);return b(d,b(u,b(f,e2(a[p],n,e,t),e2(a[M],n-1,e,t)),b(f,e2(a[v],n,e-1,t),e2(a[y],n-1,e-1,t))),b(u,b(f,e2(a[p+1],n,e,t-1),e2(a[M+1],n-1,e,t-1)),b(f,e2(a[v+1],n,e-1,t-1),e2(a[y+1],n-1,e-1,t-1))))}function Z4(n,e,t){let c=n.length===1&&Array.isArray(n[0])?n[0]:n;if(c.length)return e(c.map(a=>e1(a,t)))}var G2={abs:o0(Math.abs),sign:o0(Math.sign),floor:o0(Math.floor),ceil:o0(Math.ceil),round:o0(n=>n<0?-Math.round(-n):Math.round(n)),sqrt:o0(Math.sqrt),exp:o0(Math.exp),ln:o0(Math.log),log:K("x, base",(n,e)=>e.given<2?w0(Math.log10(e1(n[0],"log"))):Math.log(e1(n[0],"log"))/Math.log(e1(n[1],"log")),n=>n>=2?["base","x"]:["x","base"]),sin:o0(n=>Math.sin(n*j1)),cos:o0(n=>Math.cos(n*j1)),tan:o0(n=>Math.tan(n*j1)),asin:o0(n=>Math.asin(n)/j1),acos:o0(n=>Math.acos(n)/j1),atan:o0(n=>Math.atan(n)/j1),atan2:K("y, x",n=>w0(Math.atan2(e1(n[0],"atan2"),e1(n[1],"atan2"))/j1)),pow:K("x, y",n=>Math.pow(e1(n[0],"pow"),e1(n[1],"pow"))),min:K("values...",n=>Z4(n,e=>e.reduce((t,c)=>c<t?c:t,1/0),"min")),max:K("values...",n=>Z4(n,e=>e.reduce((t,c)=>c>t?c:t,-1/0),"max")),clamp:K("x, low, high",n=>Math.min(Math.max(e1(n[0],"clamp"),e1(n[1],"clamp")),e1(n[2],"clamp"))),lerp:K("a, b, t",n=>{let e=e1(n[2],"lerp");if(Array.isArray(n[0])&&Array.isArray(n[1])){let t=n[1];return n[0].map((c,a)=>e1(c,"lerp")+(e1(t[a],"lerp")-e1(c,"lerp"))*e)}return e1(n[0],"lerp")+(e1(n[1],"lerp")-e1(n[0],"lerp"))*e}),norm:K("v",(n,e)=>Math.sqrt(Y1(n[0],"norm",e).reduce((t,c)=>t+e1(c,"norm")**2,0))),cross:K("a, b",(n,e)=>{let t=Y1(n[0],"cross",e).map(a=>e1(a,"cross")),c=Y1(n[1],"cross",e).map(a=>e1(a,"cross"));return t.length===2?t[0]*c[1]-t[1]*c[0]:[t[1]*c[2]-t[2]*c[1],t[2]*c[0]-t[0]*c[2],t[0]*c[1]-t[1]*c[0]]}),len:K("value",n=>typeof n[0]=="string"?[...n[0]].length:Array.isArray(n[0])?n[0].length:t0(n[0])?n[0].fields.size:void 0),keys:K("record",n=>t0(n[0])?[...n[0].fields.keys()]:void 0),merge:K("a, b",n=>{if(!t0(n[0])||!t0(n[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...n[0].fields,...n[1].fields])}}),concat:K("...",(n,e)=>{let t=n.reduce((c,a)=>c+(Array.isArray(a)?a.length:1),0);if(t>e.maxLength)throw new Error(`concat(): a list of ${t} items is more than the limit of ${e.maxLength}`);return n.flatMap(c=>Array.isArray(c)?c:[c])}),reverse:K("value",(n,e)=>typeof n[0]=="string"?[...n[0]].reverse().join(""):[...Y1(n[0],"reverse",e)].reverse()),sort:K("values, key",(n,e)=>{let t=Y1(n[0],"sort",e),c=n[1],a=t.map(r=>[c===void 0?r:e.apply(c,[r]),r]);return e.step(Math.ceil(t.length*Math.log2(t.length+1))),a.sort((r,s)=>e6(r[0],s[0],"sort",()=>e.step())).map(([,r])=>r)}),fold:K("values, initial, fn",(n,e)=>{let t=n[1];for(let c of Y1(n[0],"fold",e))t=e.apply(n[2],[t,c]);return t}),scan:K("values, initial, fn",(n,e)=>{let t=n[1];return Y1(n[0],"scan",e).map(c=>t=e.apply(n[2],[t,c]))}),bounds:K("points",(n,e)=>{let t=x5(n[0],"bounds",e);if(!t.length)return;let[c,a,r,s]=[1/0,1/0,-1/0,-1/0];for(let[i,o]of t)c=Math.min(c,i),a=Math.min(a,o),r=Math.max(r,i),s=Math.max(s,o);return[c,a,r,s]}),crossings:K("points, x, y",(n,e)=>{if(n[1]===void 0==(n[2]===void 0))throw new Error("crossings() needs one of x or y");let t=n[1]===void 0,c=e1(t?n[2]:n[1],"crossings"),a=[];for(let r of he(n[0],"crossings",e))for(let s=0,i=r.length-1;s<r.length;i=s++){let[o,l]=t?[r[i][1],r[i][0]]:r[i],[h,f]=t?[r[s][1],r[s][0]]:r[s];o>c!=h>c&&a.push(l+(f-l)*(c-o)/(h-o))}return a.sort((r,s)=>r-s)}),sum:K("values",(n,e)=>Y1(n[0],"sum",e).reduce((t,c)=>t+e1(c,"sum"),0)),slice:K("value, start, end",(n,e)=>{let c=(typeof n[0]=="string"?[...n[0]]:Y1(n[0],"slice",e)).slice(e1(n[1]??0,"slice"),n[2]===void 0?void 0:e1(n[2],"slice"));return typeof n[0]=="string"?c.join(""):c}),str:K("...",(n,e)=>y5(n,"",e,"str")),chr:K("...",n=>n.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(e1(e,"chr"))).join("")),ord:K("text",n=>typeof n[0]=="string"&&n[0].length?n[0].codePointAt(0):void 0),upper:K("text",n=>typeof n[0]=="string"?n[0].toUpperCase():void 0),lower:K("text",n=>typeof n[0]=="string"?n[0].toLowerCase():void 0),split:K("text, separator",n=>typeof n[0]=="string"?n[0].split(typeof n[1]=="string"?n[1]:" "):void 0),join:K("values, separator",(n,e)=>y5(Y1(n[0],"join",e),typeof n[1]=="string"?n[1]:"",e,"join")),search:K("value, list",(n,e)=>{let c=(typeof n[1]=="string"?[...n[1]]:Y1(n[1],"search",e)).findIndex(a=>k2(a,n[0],e.step));return c<0?void 0:c}),contains:K("value, item",(n,e)=>typeof n[0]=="string"?n[0].includes(y5([n[1]],"",e,"contains")):Y1(n[0],"contains",e).some(t=>k2(t,n[1],e.step))),lookup:K("x, table",(n,e)=>{let t=e1(n[0],"lookup"),c=Y1(n[1],"lookup",e);if(!c.length)return;let a=c.map(r=>[e1(r[0],"lookup"),e1(r[1],"lookup")]).sort((r,s)=>r[0]-s[0]);if(t<=a[0][0])return a[0][1];for(let r=1;r<a.length;r++)if(t<=a[r][0]){let[s,i]=a[r-1],[o,l]=a[r];return i+(t-s)/(o-s)*(l-i)}return a[a.length-1][1]}),rands:K("min, max, count, seed",n=>{let e=e1(n[0],"rands"),t=e1(n[1],"rands"),c=e1(n[2],"rands"),a=a6(n[3]===void 0?1:e1(n[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(t-e)*a())}),noise:K("x, y, z, seed, octaves",n=>{let e,t=0,c=0;if(Array.isArray(n[0])){let h=n[0];e=e1(h[0],"noise"),t=h[1]===void 0?0:e1(h[1],"noise"),c=h[2]===void 0?0:e1(h[2],"noise")}else e=e1(n[0],"noise"),n[1]!==void 0&&(t=e1(n[1],"noise")),n[2]!==void 0&&(c=e1(n[2],"noise"));let a=Math.floor(n[3]===void 0?1:e1(n[3],"noise")),r=n[4]===void 0?1:Math.floor(e1(n[4],"noise"));if(!(r>=1&&r<=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<r;h++)s+=i*de(e*l+h*.3713,t*l+h*.6271,c*l+h*.1943,a+h*7919),o+=i,i/=2,l*=2;return w0(s/o)}),is_num:K("value",n=>W4(n[0])&&!Number.isNaN(n[0])),is_string:K("value",n=>typeof n[0]=="string"),is_bool:K("value",n=>typeof n[0]=="boolean"),is_list:K("value",n=>Array.isArray(n[0])),is_record:K("value",n=>t0(n[0])),is_undef:K("value",n=>n[0]===void 0),is_function:K("value",n=>A0(n[0])),type_of:K("value",n=>Z1(n[0])),path_length:K("points",(n,e)=>{let t=B2(n[0],"path_length",e),c=0;for(let a=1;a<t.length;a++)c+=Math.hypot(t[a][0]-t[a-1][0],t[a][1]-t[a-1][1]);return c}),point_at:K("points, s",(n,e)=>Y4(B2(n[0],"point_at",e),e1(n[1],"point_at")).point),heading_at:K("points, s",(n,e)=>w0(Y4(B2(n[0],"heading_at",e),e1(n[1],"heading_at")).heading)),offset_path:K("points, d, closed",(n,e)=>{let t=B2(n[0],"offset_path",e).filter(([l,h],f,u)=>f===0||l!==u[f-1][0]||h!==u[f-1][1]),c=e1(n[1],"offset_path"),a=n[2]===!0,r=a&&t.length>1&&t[0][0]===t.at(-1)[0]&&t[0][1]===t.at(-1)[1];if(r&&t.pop(),t.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(t.length);let s=t.length,i=l=>{let[h,f]=t[l%s],[u,d]=t[(l+1)%s],m=Math.hypot(u-h,d-f);return[-(d-f)/m,(u-h)/m]},o=t.map(([l,h],f)=>{let u=!a&&f===0,d=!a&&f===s-1,m=i(u?0:(f-1+s)%s),p=i(d?s-2:f),[v,g]=[m[0]+p[0],m[1]+p[1]],M=Math.hypot(v,g);if(M<1e-9)[v,g]=m;else{let y=Math.min(2/(M*M),4/M);[v,g]=[v*y,g*y]}return[w0(l+c*v),w0(h+c*g)]});return r?[...o,o[0]]:o}),train_for:K("ratio, stages, pinion, wheel",(n,e)=>{let t=e1(n[0],"train_for");if(!(t>0)||!Number.isFinite(t))throw new Error("train_for(): ratio must be more than 0");let c=n[1]===void 0?2:e1(n[1],"train_for");if(!(c===1||c===2||c===3))throw new Error("train_for(): stages must be 1, 2 or 3");let a=(g,M,y)=>{if(g===void 0)return M;if(!Array.isArray(g)||g.length!==2||!g.every(x=>typeof x=="number"))throw new Error(`train_for(): ${y} must be [fewest, most] teeth`);let[b,w]=[Math.ceil(g[0]),Math.floor(g[1])];if(!(b>=6&&w>=b&&w<=400))throw new Error(`train_for(): ${y} teeth must be from 6 to 400, fewest first`);return[b,w]},[r,s]=a(n[2],[10,20],"pinion"),[i,o]=a(n[3],[20,80],"wheel"),l=t<1,h=l?1/t:t,f=[];for(let g=r;g<=s;g++)for(let M=Math.max(i,g);M<=o;M++)f.push([g,M]);let u,d=g=>{let M=g.reduce((w,[x,z])=>w*z/x,1),y=Math.abs(M/h-1),b=g.reduce((w,[x,z])=>w+x+z,0);(!u||y<u.err-1e-12||Math.abs(y-u.err)<=1e-12&&b<u.teeth)&&(u={stages:g.map(w=>[...w]),err:y,teeth:b})},m=(g,M)=>{e.step();for(let y=r;y<=s;y++)for(let b of[Math.floor(M*y),Math.ceil(M*y)])b>=Math.max(i,y)&&b<=o&&d([...g,[y,b]])};if(c===1)m([],h);else for(let g=0;g<f.length;g++){let M=f[g][1]/f[g][0];if(c===2)m([f[g]],h/M);else for(let y=g;y<f.length;y++)m([f[g],f[y]],h/M/(f[y][1]/f[y][0]))}if(!u)throw new Error(`train_for(): no train of ${c} stages reaches a ratio of ${t}`);let p=u.stages.map(([g,M])=>l?[M,g]:[g,M]),v=p.reduce((g,[M,y])=>g*y/M,1);return{type:"record",fields:new Map([["stages",p],["ratio",v],["error",v/t-1]])}}),path_points:K("d, tolerance",(n,e)=>{if(typeof n[0]!="string")throw new Error("path_points() needs SVG path data");let t=n[1]===void 0?.05:e1(n[1],"path_points");if(!(t>0))throw new Error("path_points(): tolerance must be more than 0");let c=S2(M3(n[0]),t),a=[...c.closed.map(r=>[...r,r[0]]),...c.open];return e.step(a.reduce((r,s)=>r+s.length,0)),a.map(r=>r.map(([s,i])=>[s,i]))}),spline_points:K("points, steps, closed",(n,e)=>{let t=B2(n[0],"spline_points",e),c=n[1]===void 0?8:Math.floor(e1(n[1],"spline_points"));if(!(c>=1))throw new Error("spline_points(): steps must be 1 or more");if(t.length*c>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(t.length*c),w5(t,c,n[2]===!0)}),rotation:K("angles",n=>{let[e,t,c]=M5(n[0],"rotation");return ye(J4(ge(c),J4(ve(t),me(e))))}),euler:K("matrix",n=>Q4(pe(n[0],"euler"))),orient:K("x, z",n=>{let e=K4(M5(n[0],"orient"),"orient"),t=M5(n[1]??[0,0,1],"orient"),c=t[0]*e[0]+t[1]*e[1]+t[2]*e[2];t=K4([t[0]-c*e[0],t[1]-c*e[1],t[2]-c*e[2]],"orient");let a=[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]];return Q4([[e[0],a[0],t[0]],[e[1],a[1],t[1]],[e[2],a[2],t[2]]])})};function B2(n,e,t){return Y1(n,e,t).map((a,r)=>{if(!Array.isArray(a)||typeof a[0]!="number"||typeof a[1]!="number")throw new Error(`${e}(): points[${r}] must be an [x, y] point`);return[a[0],a[1]]})}function Y4(n,e){if(n.length<2)throw new Error("a path needs at least two points");let t=n.filter(([o,l],h)=>h===0||o!==n[h-1][0]||l!==n[h-1][1]);if(t.length<2)return{point:[t[0][0],t[0][1]],heading:0};let c=0,a=0;for(;c<t.length-2;c++){let o=Math.hypot(t[c+1][0]-t[c][0],t[c+1][1]-t[c][1]);if(a+o>=e)break;a+=o}let[r,s]=[t[c],t[c+1]],i=(e-a)/Math.hypot(s[0]-r[0],s[1]-r[1]);return{point:[r[0]+(s[0]-r[0])*i,r[1]+(s[1]-r[1])*i],heading:Math.atan2(s[1]-r[1],s[0]-r[0])/j1}}function M5(n,e){if(!Array.isArray(n)||n.length<2||n.length>3||!n.every(t=>typeof t=="number"))throw new Error(`${e}() needs [x, y, z]`);return[n[0],n[1],n[2]??0]}function K4(n,e){let t=Math.hypot(...n);if(!(t>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[n[0]/t,n[1]/t,n[2]/t]}function pe(n,e){if(!Array.isArray(n)||n.length<3||!n.slice(0,3).every(t=>Array.isArray(t)&&t.length>=3&&t.slice(0,3).every(c=>typeof c=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return n.slice(0,3).map(t=>t.slice(0,3))}var me=n=>{let[e,t]=[Math.cos(n*j1),Math.sin(n*j1)];return[[1,0,0],[0,e,-t],[0,t,e]]},ve=n=>{let[e,t]=[Math.cos(n*j1),Math.sin(n*j1)];return[[e,0,t],[0,1,0],[-t,0,e]]},ge=n=>{let[e,t]=[Math.cos(n*j1),Math.sin(n*j1)];return[[e,-t,0],[t,e,0],[0,0,1]]},J4=(n,e)=>n.map(t=>[0,1,2].map(c=>t[0]*e[0][c]+t[1]*e[1][c]+t[2]*e[2][c])),ye=n=>n.map(e=>e.map(w0));function Q4(n){let e=-n[2][0];if(Math.abs(e)>1-1e-12){let t=e>0?90:-90,c=Math.atan2(-n[0][1],n[1][1])/j1;return[0,t,w0(c)]}return[w0(Math.atan2(n[2][1],n[2][2])/j1),w0(Math.asin(e)/j1),w0(Math.atan2(n[1][0],n[0][0])/j1)]}function w5(n,e,t=!1){if(n.length<3)return n.map(([s,i])=>[s,i]);let c=s=>{if(t)return n[(s%n.length+n.length)%n.length];if(s<0)return[2*n[0][0]-n[1][0],2*n[0][1]-n[1][1]];if(s>=n.length){let[i,o]=[n[n.length-1],n[n.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return n[s]},a=[],r=t?n.length:n.length-1;for(let s=0;s<r;s++){let[i,o,l,h]=[c(s-1),c(s),c(s+1),c(s+2)];for(let f=0;f<e;f++){let u=f/e,d=u*u,m=d*u;a.push([0,1].map(p=>.5*(2*o[p]+(-i[p]+l[p])*u+(2*i[p]-5*o[p]+4*l[p]-h[p])*d+(-i[p]+3*o[p]-3*l[p]+h[p])*m)))}}return a.push(t?a[0]:[n[n.length-1][0],n[n.length-1][1]]),a}var M1;(function(n){n[n.NoClip=0]="NoClip",n[n.Intersection=1]="Intersection",n[n.Union=2]="Union",n[n.Difference=3]="Difference",n[n.Xor=4]="Xor"})(M1||(M1={}));var K1;(function(n){n[n.Subject=0]="Subject",n[n.Clip=1]="Clip"})(K1||(K1={}));var p1;(function(n){n[n.EvenOdd=0]="EvenOdd",n[n.NonZero=1]="NonZero",n[n.Positive=2]="Positive",n[n.Negative=3]="Negative"})(p1||(p1={}));var v1;(function(n){n[n.IsOn=0]="IsOn",n[n.IsInside=1]="IsInside",n[n.IsOutside=2]="IsOutside"})(v1||(v1={}));var A2=Number.MAX_SAFE_INTEGER,O1=Math.floor(Math.sqrt(A2));function w3(n,e){return!Number.isSafeInteger(n)||!Number.isSafeInteger(e)?!1:n===0||e===0?!0:Math.abs(n)<=A2/Math.abs(e)}function r6(n,e){return Math.abs(n)+Math.abs(e)<=A2}function z5(n,e,t,c){if(w3(n,e)&&w3(t,c)){let a=n*e,r=t*c;if(r6(a,r))return a-r}return Number.isSafeInteger(n)&&Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(c)?Number(BigInt(n)*BigInt(e)-BigInt(t)*BigInt(c)):n*e-t*c}function k5(n,e,t,c){if(w3(n,e)&&w3(t,c)){let a=n*e,r=t*c;if(r6(a,r))return a+r}return Number.isSafeInteger(n)&&Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(c)?Number(BigInt(n)*BigInt(e)+BigInt(t)*BigInt(c)):n*e+t*c}var L5=BigInt(0),z3=BigInt(2),be=BigInt(4),Me=BigInt(64),xe=BigInt("0xFFFFFFFFFFFFFFFF"),C5=BigInt("9223372036854775807"),j2=Number(C5/be),s6=Number(C5),i6=1e-12,we=.1,S5=Math.floor(O1/2),ze=Math.floor(Math.sqrt(Math.sqrt(A2/4)));function ke(n){if(!Number.isFinite(n))throw new RangeError("Scale must be a finite number");let e=Math.abs(n);return e===0?Number.POSITIVE_INFINITY:A2/e}function Le(n,e,t){if(!Number.isFinite(n)||Math.abs(n)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${t}`)}function Se(n,e){if(!Number.isFinite(n)||Math.abs(n)>A2)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function Ae(n,e,t){let c=e.x-n.x,a=t.y-e.y,r=e.y-n.y,s=t.x-e.x;return Math.abs(c)<O1&&Math.abs(a)<O1&&Math.abs(r)<O1&&Math.abs(s)<O1?c*a-r*s:z5(c,a,r,s)}function z0(n,e,t){let c=e.x-n.x,a=t.y-e.y,r=e.y-n.y,s=t.x-e.x;if(Math.abs(c)<O1&&Math.abs(a)<O1&&Math.abs(r)<O1&&Math.abs(s)<O1){let l=c*a,h=r*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)){let l=c*a,h=r*s;return l>h?1:l<h?-1:0}let i=BigInt(c)*BigInt(a),o=BigInt(r)*BigInt(s);return i===o?0:i>o?1:-1}function Ce(n){if(n<-8||n>8)throw new Error("Error: Precision is out of range.")}function Pe(n){return Math.abs(n)<=i6}function Ee(n){return n<0?-1:n>0?1:0}function Te(n,e){let t=BigInt(n),c=BigInt(e),a=t*c;return{lo64:a&xe,hi64:a>>Me}}function o6(n,e,t,c){let a=Math.abs(n),r=Math.abs(e),s=Math.abs(t),i=Math.abs(c);if(a<O1&&r<O1&&s<O1&&i<O1)return n*e===t*c;let o=(n<0?-1:n>0?1:0)*(e<0?-1:e>0?1:0),l=(t<0?-1:t>0?1:0)*(c<0?-1:c>0?1:0);if(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return n*e===t*c;let h=BigInt(a),f=BigInt(r),u=BigInt(s),d=BigInt(i);return h*f===u*d}function Ie(n,e,t){let c=e.x-n.x,a=t.y-e.y,r=e.y-n.y,s=t.x-e.x;return o6(c,a,r,s)}function He(n,e,t){let c=e.x-n.x,a=t.x-e.x,r=e.y-n.y,s=t.y-e.y;return Math.abs(c)<O1&&Math.abs(a)<O1&&Math.abs(r)<O1&&Math.abs(s)<O1?c*a+r*s:k5(c,a,r,s)}function Ve(n,e,t){let c=e.x-n.x,a=t.x-e.x,r=e.y-n.y,s=t.y-e.y;if(Math.abs(c)<O1&&Math.abs(a)<O1&&Math.abs(r)<O1&&Math.abs(s)<O1){let o=c*a+r*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)){let o=c*a+r*s;return o>0?1:o<0?-1:0}let i=BigInt(c)*BigInt(a)+BigInt(r)*BigInt(s);return i===L5?0:i>L5?1:-1}function Oe(n){let e=n.length;if(e<3)return 0;let t=!0;for(let r=0;r<e&&t;r++){let s=n[r];(Math.abs(s.x)>=S5||Math.abs(s.y)>=S5)&&(t=!1)}let c=n[e-1];if(t){let r=0;for(let s of n)r+=(c.y+s.y)*(c.x-s.x),c=s;return r*.5}let a=L5;for(let r of n){let s=c.y+r.y,i=c.x-r.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))a+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(c.y)&&Number.isSafeInteger(r.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(r.x)){let o=BigInt(c.y)+BigInt(r.y),l=BigInt(c.x)-BigInt(r.x);a+=o*l}else a+=BigInt(Math.round(s*i));c=r}return Number(a)*.5}function Fe(n,e){return n.y*e.x-e.y*n.x}function De(n,e){return n.x*e.x+n.y*e.y}function Re(n){let e=Math.round(n);return n===e-.5&&(e&1)!==0?e-1:e}function qe(n){return n>=j2||n<=-j2?s6:Math.round(n)}function Ue(n,e,t,c){let a=e.y-n.y,r=e.x-n.x,s=c.y-t.y,i=c.x-t.x,o=z5(a,i,s,r);if(o===0)return null;let l=z5(n.x-t.x,s,n.y-t.y,i)/o;return l<=0?{x:n.x,y:n.y,z:n.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(n.x+l*r),y:Math.trunc(n.y+l*a),z:0}}function Ne(n,e,t,c){let a=e.y-n.y,r=e.x-n.x,s=c.y-t.y,i=c.x-t.x,o=a*i-s*r;if(o===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((n.x-t.x)*s-(n.y-t.y)*i)/o,h;return l<=0?h={...n,z:0}:l>=1?h={...e,z:0}:h={x:n.x+l*r,y:n.y+l*a,z:0},{success:!0,ip:h}}function $e(n,e,t,c,a=!1){if(!a){let l=z0(n,t,c),h=z0(e,t,c),f=z0(t,n,e),u=z0(c,n,e);return l!==0&&h!==0&&l!==h&&f!==0&&u!==0&&f!==u}let r=z0(n,t,c),s=z0(e,t,c);if(r!==0&&r===s)return!1;let i=z0(t,n,e),o=z0(c,n,e);return i!==0&&i===o?!1:r!==0||s!==0||i!==0||o!==0}function l6(n){if(n.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 t of n)t.x<e.left&&(e.left=t.x),t.x>e.right&&(e.right=t.x),t.y<e.top&&(e.top=t.y),t.y>e.bottom&&(e.bottom=t.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function _e(n,e,t){if(e.x===t.x&&e.y===t.y)return{x:e.x,y:e.y,z:0};let c=t.x-e.x,a=t.y-e.y,r=k5(n.x-e.x,c,n.y-e.y,a)/k5(c,c,a,a),s=r<0?0:r>1?1:r;return{x:Math.round(e.x+s*c),y:Math.round(e.y+s*a),z:0}}function A5(n,e){let t=e.length,c=0;if(t<3)return v1.IsOutside;for(;c<t&&e[c].y===n.y;)c++;if(c===t)return v1.IsOutside;let a=e[c].y<n.y,r=a,s=0,i=c+1,o=t;for(;;){if(i===o){if(o===0||c===0)break;o=c,i=0}if(a)for(;i<o&&e[i].y<n.y;)i++;else for(;i<o&&e[i].y>n.y;)i++;if(i===o)continue;let h=e[i],f=i>0?e[i-1]:e[t-1];if(h.y===n.y){if(h.x===n.x||h.y===f.y&&n.x<f.x!=n.x<h.x)return v1.IsOn;if(i++,i===c)break;continue}if(!(n.x<h.x&&n.x<f.x))if(n.x>f.x&&n.x>h.x)s=1-s;else{let u=z0(f,h,n);if(u===0)return v1.IsOn;u<0===a&&(s=1-s)}a=!a,i++}if(a===r)return s===0?v1.IsOutside:v1.IsInside;i===t&&(i=0);let l=i===0?z0(e[t-1],e[0],n):z0(e[i-1],e[i],n);return l===0?v1.IsOn:(l<0===a&&(s=1-s),s===0?v1.IsOutside:v1.IsInside)}function Be(n,e){let t=v1.IsOn;for(let i of n)switch(A5(i,e)){case v1.IsOutside:if(t===v1.IsOutside)return!1;t=v1.IsOutside;break;case v1.IsInside:if(t===v1.IsInside)return!0;t=v1.IsInside;break;default:break}let c=l6(n),a,r;return Number.isSafeInteger(c.left)&&Number.isSafeInteger(c.right)&&Math.abs(c.left)+Math.abs(c.right)>Number.MAX_SAFE_INTEGER?(a=Number((BigInt(c.left)+BigInt(c.right))/z3),r=Number((BigInt(c.top)+BigInt(c.bottom))/z3)):(a=Math.round((c.left+c.right)/2),r=Math.round((c.top+c.bottom)/2)),A5({x:a,y:r},e)!==v1.IsOutside}var h1={MaxInt64:C5,MaxCoord:j2,max_coord:j2,min_coord:-j2,Invalid64:s6,floatingPointTolerance:i6,defaultMinimumEdgeLength:we,maxCoordForSafeAreaProduct:S5,maxCoordForSafeCrossSq:ze,maxSafeCoordinateForScale:ke,checkSafeScaleValue:Le,ensureSafeInteger:Se,crossProduct:Ae,crossProductSign:z0,checkPrecision:Ce,isAlmostZero:Pe,triSign:Ee,multiplyUInt64:Te,productsAreEqual:o6,isCollinear:Ie,dotProduct:He,dotProductSign:Ve,area:Oe,crossProductD:Fe,dotProductD:De,roundToEven:Re,checkCastInt64:qe,getLineIntersectPt:Ue,getLineIntersectPtD:Ne,segsIntersect:$e,getBounds:l6,getClosestPtOnSegment:_e,pointInPolygon:A5,path2ContainsPath1:Be},F0={create(n=0,e=0,t=0){return{x:Math.round(n),y:Math.round(e),z:t}},fromPointD(n){return h1.ensureSafeInteger(n.x,"Point64Utils.fromPointD"),h1.ensureSafeInteger(n.y,"Point64Utils.fromPointD"),{x:Math.round(n.x),y:Math.round(n.y),z:n.z||0}},scale(n,e){return{x:Math.round(n.x*e),y:Math.round(n.y*e),z:n.z||0}},equals(n,e){return n.x===e.x&&n.y===e.y},add(n,e){if(Number.isSafeInteger(n.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(e.y)){let t=n.x+e.x,c=n.y+e.y;return Number.isSafeInteger(t)&&Number.isSafeInteger(c)?{x:t,y:c,z:0}:{x:Number(BigInt(n.x)+BigInt(e.x)),y:Number(BigInt(n.y)+BigInt(e.y)),z:0}}return{x:n.x+e.x,y:n.y+e.y,z:0}},subtract(n,e){return{x:n.x-e.x,y:n.y-e.y,z:0}},toString(n){return n.z!==void 0&&n.z!==0?`${n.x},${n.y},${n.z} `:`${n.x},${n.y} `}},k3={create(n=0,e=0,t=0){return{x:n,y:e,z:t}},fromPoint64(n){return{x:n.x,y:n.y,z:n.z||0}},scale(n,e){return{x:n.x*e,y:n.y*e,z:n.z||0}},equals(n,e){return h1.isAlmostZero(n.x-e.x)&&h1.isAlmostZero(n.y-e.y)},negate(n){n.x=-n.x,n.y=-n.y},toString(n,e=2){return n.z!==void 0&&n.z!==0?`${n.x.toFixed(e)},${n.y.toFixed(e)},${n.z}`:`${n.x.toFixed(e)},${n.y.toFixed(e)}`}},d2={create(n=0,e=0,t=0,c=0){return{left:n,top:e,right:t,bottom:c}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(n){return n.right-n.left},height(n){return n.bottom-n.top},isEmpty(n){return n.bottom<=n.top||n.right<=n.left},isValid(n){return n.left<Number.MAX_SAFE_INTEGER},midPoint(n){if(Number.isSafeInteger(n.left)&&Number.isSafeInteger(n.right)&&Math.abs(n.left)+Math.abs(n.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(n.left)+BigInt(n.right))/z3),t=Number((BigInt(n.top)+BigInt(n.bottom))/z3);return{x:e,y:t}}return{x:Math.round((n.left+n.right)/2),y:Math.round((n.top+n.bottom)/2)}},contains(n,e){return e.x>n.left&&e.x<n.right&&e.y>n.top&&e.y<n.bottom},containsRect(n,e){return e.left>=n.left&&e.right<=n.right&&e.top>=n.top&&e.bottom<=n.bottom},intersects(n,e){return Math.max(n.left,e.left)<=Math.min(n.right,e.right)&&Math.max(n.top,e.top)<=Math.min(n.bottom,e.bottom)},asPath(n){return[{x:n.left,y:n.top,z:0},{x:n.right,y:n.top,z:0},{x:n.right,y:n.bottom,z:0},{x:n.left,y:n.bottom,z:0}]}},P5={create(n=0,e=0,t=0,c=0){return{left:n,top:e,right:t,bottom:c}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(n){return n.right-n.left},height(n){return n.bottom-n.top},isEmpty(n){return n.bottom<=n.top||n.right<=n.left},midPoint(n){return{x:(n.left+n.right)/2,y:(n.top+n.bottom)/2}},contains(n,e){return e.x>n.left&&e.x<n.right&&e.y>n.top&&e.y<n.bottom},containsRect(n,e){return e.left>=n.left&&e.right<=n.right&&e.top>=n.top&&e.bottom<=n.bottom},intersects(n,e){return Math.max(n.left,e.left)<Math.min(n.right,e.right)&&Math.max(n.top,e.top)<Math.min(n.bottom,e.bottom)},asPath(n){return[{x:n.left,y:n.top,z:0},{x:n.right,y:n.top,z:0},{x:n.right,y:n.bottom,z:0},{x:n.left,y:n.bottom,z:0}]}};var h6=Object.freeze(d2.createInvalid()),u6=Object.freeze(P5.createInvalid());var W2=BigInt(0),Ge=BigInt(2),f6=BigInt(4),g1;(function(n){n[n.None=0]="None",n[n.OpenStart=1]="OpenStart",n[n.OpenEnd=2]="OpenEnd",n[n.LocalMax=4]="LocalMax",n[n.LocalMin=8]="LocalMin"})(g1||(g1={}));var E5=class{constructor(){F(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],t=this.data.pop();return this.data.length>0&&(this.data[0]=t,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let t=this.data[e];for(;e>0;){let c=e-1>>1;if(this.data[c]>=t)break;this.data[e]=this.data[c],e=c}this.data[e]=t}siftDown(e){let t=this.data.length,c=this.data[e];for(;;){let a=(e<<1)+1;if(a>=t)break;let r=a+1,s=a;if(r<t&&this.data[r]>this.data[a]&&(s=r),this.data[s]<=c)break;this.data[e]=this.data[s],e=s}this.data[e]=c}},X2=class{constructor(e,t,c){F(this,"pt");F(this,"next",null);F(this,"prev",null);F(this,"flags");this.pt=e,this.flags=t,this.prev=c}},Z2=class{constructor(e,t,c=!1){F(this,"vertex");F(this,"polytype");F(this,"isOpen");this.vertex=e,this.polytype=t,this.isOpen=c}equals(e){return e!==null&&this.vertex===e.vertex}};function d6(n,e,t){return{pt:n,edge1:e,edge2:t}}var X0=class{constructor(e,t){F(this,"pt");F(this,"next");F(this,"prev");F(this,"outrec");F(this,"horz");this.pt=e,this.outrec=t,this.next=this,this.prev=this,this.horz=null}},n0;(function(n){n[n.None=0]="None",n[n.Left=1]="Left",n[n.Right=2]="Right"})(n0||(n0={}));var T5;(function(n){n[n.Bottom=0]="Bottom",n[n.Middle=1]="Middle",n[n.Top=2]="Top"})(T5||(T5={}));var L3=class{constructor(){F(this,"idx",0);F(this,"owner",null);F(this,"frontEdge",null);F(this,"backEdge",null);F(this,"pts",null);F(this,"polypath",null);F(this,"bounds",{left:0,top:0,right:0,bottom:0});F(this,"path",[]);F(this,"isOpen",!1);F(this,"splits",null);F(this,"recursiveSplit",null)}},S3=class{constructor(e){F(this,"leftOp");F(this,"rightOp");F(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},Y2=class{constructor(e,t){F(this,"op1");F(this,"op2");this.op1=e,this.op2=t}};function je(n,e){return n.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:n.leftOp.pt.x-e.leftOp.pt.x}function We(n,e){return n.pt.y!==e.pt.y?n.pt.y>e.pt.y?-1:1:n.pt.x!==e.pt.x?n.pt.x<e.pt.x?-1:1:n.edge1.curX!==e.edge1.curX?n.edge1.curX<e.edge1.curX?-1:1:n.edge2.curX<e.edge2.curX?-1:n.edge2.curX>e.edge2.curX?1:0}var K2=class{constructor(){F(this,"bot",{x:0,y:0});F(this,"top",{x:0,y:0});F(this,"curX",0);F(this,"dx",0);F(this,"windDx",0);F(this,"windCount",0);F(this,"windCount2",0);F(this,"outrec",null);F(this,"prevInAEL",null);F(this,"nextInAEL",null);F(this,"prevInSEL",null);F(this,"nextInSEL",null);F(this,"jump",null);F(this,"vertexTop",null);F(this,"localMin",null);F(this,"isLeftBound",!1);F(this,"joinWith",n0.None)}},C2={addLocMin(n,e,t,c){if((n.flags&g1.LocalMin)!==g1.None)return;n.flags|=g1.LocalMin;let a=new Z2(n,e,t);c.push(a)},addPathsToVertexList(n,e,t,c,a){for(let r=0,s=n.length;r<s;r++){let i=n[r],o=null,l=null,h=null;for(let m=0,p=i.length;m<p;m++){let v=i[m];if(o===null)o=new X2(v,g1.None,null),a.push(o),l=o,h=v;else if(!(h.x===v.x&&h.y===v.y)){let g=new X2(v,g1.None,l);l.next=g,l=g,h=v}}if(l?.prev==null||(!t&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!t&&l.next===l))continue;let f;if(t){let m=o.next;for(;m!==o&&m.pt.y===o.pt.y;)m=m.next;f=m.pt.y<=o.pt.y,f?(o.flags=g1.OpenStart,C2.addLocMin(o,e,!0,c)):o.flags=g1.OpenStart|g1.LocalMax}else{for(l=o.prev;l!==o&&l.pt.y===o.pt.y;)l=l.prev;if(l===o)continue;f=l.pt.y>o.pt.y}let u=f;l=o;let d=o.next;for(;d!==o;)d.pt.y>l.pt.y&&f?(l.flags|=g1.LocalMax,f=!1):d.pt.y<l.pt.y&&!f&&(f=!0,C2.addLocMin(l,e,t,c)),l=d,d=d.next;t?(l.flags|=g1.OpenEnd,f?l.flags|=g1.LocalMax:C2.addLocMin(l,e,t,c)):f!==u&&(u?C2.addLocMin(l,e,!1,c):l.flags|=g1.LocalMax)}}};var A3=class{constructor(e=null){F(this,"parent");F(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,t=this.parent;for(;t!==null;)++e,t=t.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,t){let c="",a=" ".repeat(t),r=this.children.length===1?"":"s";(t&1)===0?c+=`${a}+- hole (${e}) contains ${this.children.length} nested polygon${r}.
|
|
2
|
+
var St=Object.defineProperty;var Ct=(n,e,t)=>e in n?St(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Pt=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var q=(n,e,t)=>Ct(n,typeof e!="symbol"?e+"":e,t);var l6=Pt((Wi,o6)=>{o6.exports={}});var P0=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&n.type==="range",F0=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&n.type==="function",oe=n=>typeof n=="number",d0=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&n.type==="record",y0=(n,e)=>n&&Object.prototype.hasOwnProperty.call(n,e)?n[e]:void 0;function F5(n,e,t=0){if(!(e==null||["number","string","boolean"].includes(typeof e))){if(Array.isArray(e)&&t<32){for(let c of e)F5(n,c,t+1);return}throw new Error(`Setting "${n}" must be a number, string, boolean or list`)}}function U3(n,e){let t=[];if(n.step===0||(n.step>0?n.start>n.end:n.start<n.end))return t;let c=Math.floor((n.end-n.start)/n.step+1e-9)+1;if(c>e)throw new Error(`a range of ${c} items is more than the limit of ${e}`);for(let a=0;a<c;a++)t.push(n.start+a*n.step);return t}function O1(n){return n===void 0||n===!1||n===0||n===""?!1:Array.isArray(n)?n.length>0:typeof n=="number"?!Number.isNaN(n):!0}var ie=(n,e,t)=>P0(n)&&P0(e)?n.start===e.start&&n.step===e.step&&n.end===e.end:d0(n)&&d0(e)?n.fields.size===e.fields.size&&[...n.fields].every(([c,a])=>e.fields.has(c)&&V2(a,e.fields.get(c),t)):n===e;function V2(n,e,t){if(t?.(),!Array.isArray(n)||!Array.isArray(e))return ie(n,e,t);let c=new Map,a=[],r=(s,i)=>{let o=c.get(s);return o?.has(i)?!0:s.length!==i.length?!1:(o||c.set(s,o=new Set),o.add(i),a.push([s,i,0]),!0)};if(!r(n,e))return!1;for(;a.length;){let s=a[a.length-1];if(s[2]===s[0].length){a.pop();continue}let i=s[0][s[2]],o=s[1][s[2]++];if(t?.(),Array.isArray(i)&&Array.isArray(o)?!r(i,o):!ie(i,o,t))return!1}return!0}function c0(n){return n===void 0?"undef":Array.isArray(n)?"list":P0(n)?"range":F0(n)?"function":d0(n)?"record":typeof n}function Et(n){return n===void 0?"undef":typeof n=="string"?JSON.stringify(n):typeof n=="number"?k0(n):P0(n)?`[${k0(n.start)}:${k0(n.step)}:${k0(n.end)}]`:F0(n)?`function(${n.params.map(e=>e.name).join(", ")})`:d0(n)?"{}":String(n)}function O2(n,e,t=!1){if(typeof n=="string"&&!t)return{text:n.length>e?n.slice(0,Math.max(e,0)):n,whole:n.length<=e};let c=[],a=0,r=l=>{c.push(l),a+=l.length},s=[],i=n;for(;;){Array.isArray(i)?(r("["),s.push({items:i,i:0,close:"]"})):d0(i)&&i.fields.size?(r("{"),s.push({items:[...i.fields.values()],keys:[...i.fields.keys()],i:0,close:"}"})):r(Et(i));let l=!1;for(;s.length&&!l&&a<=e;){let h=s[s.length-1];h.i<h.items.length?(h.i&&r(", "),h.keys&&r(`${h.keys[h.i]} = `),i=h.items[h.i++],l=!0):(s.pop(),r(h.close))}if(!l||a>e)break}let o=c.join("");return a>e?{text:o.slice(0,Math.max(e,0)),whole:!1}:{text:o,whole:!0}}function le(n,e,t){let c=[],a=0;for(let r of n){c.length&&(a+=e.length);let s=O2(r,t-a);if(!s.whole)return;a+=s.text.length,c.push(s.text)}return c.join(e)}function w1(n){let e=O2(n,200,!0);return e.whole?e.text:e.text+"..."}var F1=n=>typeof n=="string"?n:w1(n);function j1(n){let e=!1;for(;Array.isArray(n)&&n.length===1;)n=n[0],e=!0;return Array.isArray(n)?n.length?NaN:0:e&&(n===void 0||typeof n=="boolean")?n===void 0?0:NaN:typeof n=="object"?NaN:Number(n)}function k0(n){return Number.isInteger(n)?String(n):String(Number(n.toPrecision(10)))}function F2(n,e=.02){let t=[],c=[],a=[],r=[0,0],s=[0,0],i=l=>{a.length>=2&&(l?t:c).push(a),a=[]},o=l=>Math.max(2,Math.min(256,Math.ceil(Math.sqrt(l/e))));for(let l of n)if(l.type==="M")i(!1),r=s=[l.x,l.y],a=[s];else if(l.type==="L")s=[l.x,l.y],a.push(s);else if(l.type==="Q"){let[h,f]=s,u=o(Math.hypot(l.x1-h,l.y1-f)+Math.hypot(l.x-l.x1,l.y-l.y1));for(let d=1;d<=u;d++){let m=d/u,p=1-m;a.push([p*p*h+2*p*m*l.x1+m*m*l.x,p*p*f+2*p*m*l.y1+m*m*l.y])}s=[l.x,l.y]}else if(l.type==="C"){let[h,f]=s,u=o(Math.hypot(l.x1-h,l.y1-f)+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<=u;d++){let m=d/u,p=1-m;a.push([p*p*p*h+3*p*p*m*l.x1+3*p*m*m*l.x2+m*m*m*l.x,p*p*p*f+3*p*p*m*l.y1+3*p*m*m*l.y2+m*m*m*l.y])}s=[l.x,l.y]}else i(!0),s=r,a=[r];return i(!1),{closed:t,open:c}}function N3(n,e=Math.PI/2,t){let c=x=>/^[a-zA-Z]$/.test(x),a=n.match(/[a-zA-Z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[],r=[],s=0,i="",o=0,l=0,h=0,f=0,u=0,d=0,m=0,p=0,g="",v=()=>{let x=a[s++];if(x===void 0||c(x))throw new Error(`Bad path data near "${x??"end"}"`);return Number(x)},b=()=>{let x=a[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(".")?(a[s]=x.slice(1),Number(x[0])):(s++,Number(x))};try{y()}catch(x){if(!t)throw x;t(x.message)}return r;function y(){for(;s<a.length;){if(c(a[s]))i=a[s++];else if(i){if(i==="Z"||i==="z")throw new Error(`Bad path data near "${a[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,f=l,r.push({type:"M",x:o,y:l}),i=x?"l":"L";else if(M==="L")o=w+v(),l=k+v(),r.push({type:"L",x:o,y:l});else if(M==="H")o=w+v(),r.push({type:"L",x:o,y:l});else if(M==="V")l=k+v(),r.push({type:"L",x:o,y:l});else if(M==="C"||M==="S"){let S,A;if(M==="C")S=w+v(),A=k+v();else{let P=g==="C"||g==="S";S=P?2*o-u:o,A=P?2*l-d:l}let z=w+v(),L=k+v();o=w+v(),l=k+v(),u=z,d=L,r.push({type:"C",x1:S,y1:A,x2:z,y2:L,x:o,y:l})}else if(M==="Q"||M==="T"){let S,A;if(M==="Q")S=w+v(),A=k+v();else{let z=g==="Q"||g==="T";S=z?2*o-m:o,A=z?2*l-p:l}o=w+v(),l=k+v(),m=S,p=A,r.push({type:"Q",x1:S,y1:A,x:o,y:l})}else if(M==="A"){let S=v(),A=v(),z=v(),L=b(),P=b(),I=w+v(),T=k+v();r.push(...Tt(o,l,S,A,z,L,P,I,T,e)),o=I,l=T}else if(M==="Z")r.push({type:"Z"}),o=h,l=f;else throw new Error(`Unknown path command "${i}"`);g=M}}}function Tt(n,e,t,c,a,r,s,i,o,l=Math.PI/2){if(t===0||c===0||n===i&&e===o)return[{type:"L",x:i,y:o}];t=Math.abs(t),c=Math.abs(c);let h=a*Math.PI/180,f=Math.cos(h),u=Math.sin(h),d=(n-i)/2,m=(e-o)/2,p=f*d+u*m,g=-u*d+f*m,v=p*p/(t*t)+g*g/(c*c);v>1&&(t*=Math.sqrt(v),c*=Math.sqrt(v));let b=t*t*c*c-t*t*g*g-c*c*p*p,y=t*t*g*g+c*c*p*p,x=Math.sqrt(Math.max(0,b/y));r===s&&(x=-x);let M=x*t*g/c,w=-x*c*p/t,k=f*M-u*w+(n+i)/2,S=u*M+f*w+(e+o)/2,A=(F,D,_,R)=>Math.atan2(F*R-D*_,F*_+D*R),z=A(1,0,(p-M)/t,(g-w)/c),L=A((p-M)/t,(g-w)/c,(-p-M)/t,(-g-w)/c);!s&&L>0&&(L-=2*Math.PI),s&&L<0&&(L+=2*Math.PI);let P=Math.ceil(Math.abs(L)/l),I=[],T=F=>[k+t*Math.cos(F)*f-c*Math.sin(F)*u,S+t*Math.cos(F)*u+c*Math.sin(F)*f],O=F=>[-t*Math.sin(F)*f-c*Math.cos(F)*u,-t*Math.sin(F)*u+c*Math.cos(F)*f];for(let F=0;F<P;F++){let D=z+L*F/P,_=z+L*(F+1)/P,R=4/3*Math.tan((_-D)/4),U=T(D),N=T(_),e1=O(D),E1=O(_);I.push({type:"C",x1:U[0]+R*e1[0],y1:U[1]+R*e1[1],x2:N[0]-R*E1[0],y2:N[1]-R*E1[1],x:N[0],y:N[1]})}return I}var Q1=Math.PI/180;function me(n,e,t,c){if(typeof n=="number"&&typeof e=="number")return n-e;if(typeof n=="string"&&typeof e=="string")return n<e?-1:n>e?1:0;if(Array.isArray(n)&&Array.isArray(e)){for(let a=0;a<Math.min(n.length,e.length);a++){c();let r=me(n[a],e[a],t,c);if(r)return r}return n.length-e.length}throw new Error(`${t}() can only order numbers, strings or lists of them, not ${c0(n)} and ${c0(e)}`)}function q5(n,e,t){let c=a0(n,e,t);return(c.length&&Array.isArray(c[0])&&Array.isArray(c[0][0])?c.flatMap(r=>a0(r,e,t)):c).map(r=>{if(!Array.isArray(r)||r.length<2)throw new Error(`${e}() needs points [x, y], got ${c0(r)}`);return[a1(r[0],e),a1(r[1],e)]})}function It(n,e,t){let c=a0(n,e,t);return c.length&&Array.isArray(c[0])&&Array.isArray(c[0][0])?c.map(a=>q5(a,e,t)):[q5(c,e,t)]}var c1=(n,e,t)=>({params:n.replace("...","").split(",").map(c=>c.trim()).filter(Boolean),rest:n.endsWith("..."),order:t,run:e});function ge(n,e,t){return n.order?[]:n.params.filter((c,a)=>a<e.length&&t.has(c))}function ve(n,e,t){if(n.rest){let r=[...e];return n.params.forEach((s,i)=>{t.has(s)&&(r[i]=t.get(s))}),r}if(!n.order)return n.params.map((r,s)=>t.has(r)?t.get(r):e[s]);let c=e.length+n.params.filter(r=>t.has(r)).length,a=n.order(c).filter(r=>!t.has(r));return n.params.map(r=>t.has(r)?t.get(r):e[a.indexOf(r)])}function _5(n,e,t,c){let a=le(n,e,t.maxLength);if(a===void 0)throw new Error(`${c}(): the text would be longer than the limit of ${t.maxLength} characters`);return t.step(Math.ceil(a.length/8)),a}function a1(n,e){if(typeof n!="number")throw new Error(`${e}() needs a number, got ${c0(n)}`);return n}function a0(n,e,t){if(Array.isArray(n))return n;if(P0(n))return U3(n,t.maxLength);if(typeof n=="string")return[...n];throw new Error(`${e}() needs a list, got ${c0(n)}`)}var Ht=new Set(["is_num","is_string","is_bool","is_list","is_undef","is_function","type_of","ord"]);function be(n,e,t){if(Ht.has(n))return 0;let c=0;for(let a of e)if(typeof a=="string")c+=a.length;else if(Array.isArray(a))c+=n==="len"?0:a.length;else if(P0(a)&&a.step!==0){let r=Math.floor((a.end-a.start)/a.step)+1;r>0&&(c+=Math.min(r,t+1))}return c}var x0=n=>c1("x",e=>typeof e[0]=="number"?E0(n(e[0])):void 0);function E0(n){let e=Math.round(n);return Math.abs(n-e)<1e-12?e:n}function ye(n){let e=Math.floor(n)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}var B3=new Map;function Vt(n){let e=B3.get(n);if(e)return e;let t=ye(n),c=Array.from({length:256},(a,r)=>r);for(let a=255;a>0;a--){let r=Math.floor(t()*(a+1));[c[a],c[r]]=[c[r],c[a]]}e=new Uint8Array(512);for(let a=0;a<512;a++)e[a]=c[a&255];return B3.size>64&&B3.clear(),B3.set(n,e),e}var D5=n=>n*n*n*(n*(n*6-15)+10);function o2(n,e,t,c){let a=n&15,r=a<8?e:t,s=a<4?t:a===12||a===14?e:c;return((a&1)===0?r:-r)+((a&2)===0?s:-s)}function Ot(n,e,t,c){let a=Vt(c),r=Math.floor(n),s=Math.floor(e),i=Math.floor(t);n-=r,e-=s,t-=i;let o=r&255,l=s&255,h=i&255,f=D5(n),u=D5(e),d=D5(t),m=a[o]+l,p=a[m]+h,g=a[m+1]+h,v=a[o+1]+l,b=a[v]+h,y=a[v+1]+h,x=(M,w,k)=>w+M*(k-w);return x(d,x(u,x(f,o2(a[p],n,e,t),o2(a[b],n-1,e,t)),x(f,o2(a[g],n,e-1,t),o2(a[y],n-1,e-1,t))),x(u,x(f,o2(a[p+1],n,e,t-1),o2(a[b+1],n-1,e,t-1)),x(f,o2(a[g+1],n,e-1,t-1),o2(a[y+1],n-1,e-1,t-1))))}function he(n,e,t){let c=n.length===1&&Array.isArray(n[0])?n[0]:n;if(c.length)return e(c.map(a=>a1(a,t)))}var i3={abs:x0(Math.abs),sign:x0(Math.sign),floor:x0(Math.floor),ceil:x0(Math.ceil),round:x0(n=>n<0?-Math.round(-n):Math.round(n)),sqrt:x0(Math.sqrt),exp:x0(Math.exp),ln:x0(Math.log),log:c1("x, base",(n,e)=>e.given<2?E0(Math.log10(a1(n[0],"log"))):Math.log(a1(n[0],"log"))/Math.log(a1(n[1],"log")),n=>n>=2?["base","x"]:["x","base"]),sin:x0(n=>Math.sin(n*Q1)),cos:x0(n=>Math.cos(n*Q1)),tan:x0(n=>Math.tan(n*Q1)),asin:x0(n=>Math.asin(n)/Q1),acos:x0(n=>Math.acos(n)/Q1),atan:x0(n=>Math.atan(n)/Q1),atan2:c1("y, x",n=>E0(Math.atan2(a1(n[0],"atan2"),a1(n[1],"atan2"))/Q1)),pow:c1("x, y",n=>Math.pow(a1(n[0],"pow"),a1(n[1],"pow"))),min:c1("values...",n=>he(n,e=>e.reduce((t,c)=>c<t?c:t,1/0),"min")),max:c1("values...",n=>he(n,e=>e.reduce((t,c)=>c>t?c:t,-1/0),"max")),clamp:c1("x, low, high",n=>Math.min(Math.max(a1(n[0],"clamp"),a1(n[1],"clamp")),a1(n[2],"clamp"))),lerp:c1("a, b, t",n=>{let e=a1(n[2],"lerp");if(Array.isArray(n[0])&&Array.isArray(n[1])){let t=n[1];return n[0].map((c,a)=>a1(c,"lerp")+(a1(t[a],"lerp")-a1(c,"lerp"))*e)}return a1(n[0],"lerp")+(a1(n[1],"lerp")-a1(n[0],"lerp"))*e}),norm:c1("v",(n,e)=>Math.sqrt(a0(n[0],"norm",e).reduce((t,c)=>t+a1(c,"norm")**2,0))),cross:c1("a, b",(n,e)=>{let t=a0(n[0],"cross",e).map(a=>a1(a,"cross")),c=a0(n[1],"cross",e).map(a=>a1(a,"cross"));return t.length===2?t[0]*c[1]-t[1]*c[0]:[t[1]*c[2]-t[2]*c[1],t[2]*c[0]-t[0]*c[2],t[0]*c[1]-t[1]*c[0]]}),len:c1("value",n=>typeof n[0]=="string"?[...n[0]].length:Array.isArray(n[0])?n[0].length:d0(n[0])?n[0].fields.size:void 0),keys:c1("record",n=>d0(n[0])?[...n[0].fields.keys()]:void 0),merge:c1("a, b",n=>{if(!d0(n[0])||!d0(n[1]))throw new Error("merge() takes two records");return{type:"record",fields:new Map([...n[0].fields,...n[1].fields])}}),concat:c1("...",(n,e)=>{let t=n.reduce((c,a)=>c+(Array.isArray(a)?a.length:1),0);if(t>e.maxLength)throw new Error(`concat(): a list of ${t} items is more than the limit of ${e.maxLength}`);return n.flatMap(c=>Array.isArray(c)?c:[c])}),reverse:c1("value",(n,e)=>typeof n[0]=="string"?[...n[0]].reverse().join(""):[...a0(n[0],"reverse",e)].reverse()),sort:c1("values, key",(n,e)=>{let t=a0(n[0],"sort",e),c=n[1],a=t.map(r=>[c===void 0?r:e.apply(c,[r]),r]);return e.step(Math.ceil(t.length*Math.log2(t.length+1))),a.sort((r,s)=>me(r[0],s[0],"sort",()=>e.step())).map(([,r])=>r)}),fold:c1("values, initial, fn",(n,e)=>{let t=n[1];for(let c of a0(n[0],"fold",e))t=e.apply(n[2],[t,c]);return t}),scan:c1("values, initial, fn",(n,e)=>{let t=n[1];return a0(n[0],"scan",e).map(c=>t=e.apply(n[2],[t,c]))}),bounds:c1("points",(n,e)=>{let t=q5(n[0],"bounds",e);if(!t.length)return;let[c,a,r,s]=[1/0,1/0,-1/0,-1/0];for(let[i,o]of t)c=Math.min(c,i),a=Math.min(a,o),r=Math.max(r,i),s=Math.max(s,o);return[c,a,r,s]}),crossings:c1("points, x, y",(n,e)=>{if(n[1]===void 0==(n[2]===void 0))throw new Error("crossings() needs one of x or y");let t=n[1]===void 0,c=a1(t?n[2]:n[1],"crossings"),a=[];for(let r of It(n[0],"crossings",e))for(let s=0,i=r.length-1;s<r.length;i=s++){let[o,l]=t?[r[i][1],r[i][0]]:r[i],[h,f]=t?[r[s][1],r[s][0]]:r[s];o>c!=h>c&&a.push(l+(f-l)*(c-o)/(h-o))}return a.sort((r,s)=>r-s)}),sum:c1("values",(n,e)=>a0(n[0],"sum",e).reduce((t,c)=>t+a1(c,"sum"),0)),slice:c1("value, start, end",(n,e)=>{let c=(typeof n[0]=="string"?[...n[0]]:a0(n[0],"slice",e)).slice(a1(n[1]??0,"slice"),n[2]===void 0?void 0:a1(n[2],"slice"));return typeof n[0]=="string"?c.join(""):c}),str:c1("...",(n,e)=>_5(n,"",e,"str")),chr:c1("...",n=>n.flatMap(e=>Array.isArray(e)?e:[e]).map(e=>String.fromCodePoint(a1(e,"chr"))).join("")),ord:c1("text",n=>typeof n[0]=="string"&&n[0].length?n[0].codePointAt(0):void 0),upper:c1("text",n=>typeof n[0]=="string"?n[0].toUpperCase():void 0),lower:c1("text",n=>typeof n[0]=="string"?n[0].toLowerCase():void 0),split:c1("text, separator",n=>typeof n[0]=="string"?n[0].split(typeof n[1]=="string"?n[1]:" "):void 0),join:c1("values, separator",(n,e)=>_5(a0(n[0],"join",e),typeof n[1]=="string"?n[1]:"",e,"join")),search:c1("value, list",(n,e)=>{let c=(typeof n[1]=="string"?[...n[1]]:a0(n[1],"search",e)).findIndex(a=>V2(a,n[0],e.step));return c<0?void 0:c}),contains:c1("value, item",(n,e)=>typeof n[0]=="string"?n[0].includes(_5([n[1]],"",e,"contains")):a0(n[0],"contains",e).some(t=>V2(t,n[1],e.step))),lookup:c1("x, table",(n,e)=>{let t=a1(n[0],"lookup"),c=a0(n[1],"lookup",e);if(!c.length)return;let a=c.map(r=>[a1(r[0],"lookup"),a1(r[1],"lookup")]).sort((r,s)=>r[0]-s[0]);if(t<=a[0][0])return a[0][1];for(let r=1;r<a.length;r++)if(t<=a[r][0]){let[s,i]=a[r-1],[o,l]=a[r];return i+(t-s)/(o-s)*(l-i)}return a[a.length-1][1]}),rands:c1("min, max, count, seed",n=>{let e=a1(n[0],"rands"),t=a1(n[1],"rands"),c=a1(n[2],"rands"),a=ye(n[3]===void 0?1:a1(n[3],"rands"));return Array.from({length:Math.min(Math.max(0,Math.floor(c)),1e6)},()=>e+(t-e)*a())}),noise:c1("x, y, z, seed, octaves",n=>{let e,t=0,c=0;if(Array.isArray(n[0])){let h=n[0];e=a1(h[0],"noise"),t=h[1]===void 0?0:a1(h[1],"noise"),c=h[2]===void 0?0:a1(h[2],"noise")}else e=a1(n[0],"noise"),n[1]!==void 0&&(t=a1(n[1],"noise")),n[2]!==void 0&&(c=a1(n[2],"noise"));let a=Math.floor(n[3]===void 0?1:a1(n[3],"noise")),r=n[4]===void 0?1:Math.floor(a1(n[4],"noise"));if(!(r>=1&&r<=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<r;h++)s+=i*Ot(e*l+h*.3713,t*l+h*.6271,c*l+h*.1943,a+h*7919),o+=i,i/=2,l*=2;return E0(s/o)}),is_num:c1("value",n=>oe(n[0])&&!Number.isNaN(n[0])),is_string:c1("value",n=>typeof n[0]=="string"),is_bool:c1("value",n=>typeof n[0]=="boolean"),is_list:c1("value",n=>Array.isArray(n[0])),is_record:c1("value",n=>d0(n[0])),is_undef:c1("value",n=>n[0]===void 0),is_function:c1("value",n=>F0(n[0])),type_of:c1("value",n=>c0(n[0])),path_length:c1("points",(n,e)=>{let t=s3(n[0],"path_length",e),c=0;for(let a=1;a<t.length;a++)c+=Math.hypot(t[a][0]-t[a-1][0],t[a][1]-t[a-1][1]);return c}),point_at:c1("points, s",(n,e)=>ue(s3(n[0],"point_at",e),a1(n[1],"point_at")).point),heading_at:c1("points, s",(n,e)=>E0(ue(s3(n[0],"heading_at",e),a1(n[1],"heading_at")).heading)),offset_path:c1("points, d, closed",(n,e)=>{let t=s3(n[0],"offset_path",e).filter(([l,h],f,u)=>f===0||l!==u[f-1][0]||h!==u[f-1][1]),c=a1(n[1],"offset_path"),a=n[2]===!0,r=a&&t.length>1&&t[0][0]===t.at(-1)[0]&&t[0][1]===t.at(-1)[1];if(r&&t.pop(),t.length<2)throw new Error("offset_path(): a path needs at least two points");e.step(t.length);let s=t.length,i=l=>{let[h,f]=t[l%s],[u,d]=t[(l+1)%s],m=Math.hypot(u-h,d-f);return[-(d-f)/m,(u-h)/m]},o=t.map(([l,h],f)=>{let u=!a&&f===0,d=!a&&f===s-1,m=i(u?0:(f-1+s)%s),p=i(d?s-2:f),[g,v]=[m[0]+p[0],m[1]+p[1]],b=Math.hypot(g,v);if(b<1e-9)[g,v]=m;else{let y=Math.min(2/(b*b),4/b);[g,v]=[g*y,v*y]}return[E0(l+c*g),E0(h+c*v)]});return r?[...o,o[0]]:o}),train_for:c1("ratio, stages, pinion, wheel",(n,e)=>{let t=a1(n[0],"train_for");if(!(t>0)||!Number.isFinite(t))throw new Error("train_for(): ratio must be more than 0");let c=n[1]===void 0?2:a1(n[1],"train_for");if(!(c===1||c===2||c===3))throw new Error("train_for(): stages must be 1, 2 or 3");let a=(v,b,y)=>{if(v===void 0)return b;if(!Array.isArray(v)||v.length!==2||!v.every(w=>typeof w=="number"))throw new Error(`train_for(): ${y} 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(): ${y} teeth must be from 6 to 400, fewest first`);return[x,M]},[r,s]=a(n[2],[10,20],"pinion"),[i,o]=a(n[3],[20,80],"wheel"),l=t<1,h=l?1/t:t,f=[];for(let v=r;v<=s;v++)for(let b=Math.max(i,v);b<=o;b++)f.push([v,b]);let u,d=v=>{let b=v.reduce((M,[w,k])=>M*k/w,1),y=Math.abs(b/h-1),x=v.reduce((M,[w,k])=>M+w+k,0);(!u||y<u.err-1e-12||Math.abs(y-u.err)<=1e-12&&x<u.teeth)&&(u={stages:v.map(M=>[...M]),err:y,teeth:x})},m=(v,b)=>{e.step();for(let y=r;y<=s;y++)for(let x of[Math.floor(b*y),Math.ceil(b*y)])x>=Math.max(i,y)&&x<=o&&d([...v,[y,x]])};if(c===1)m([],h);else for(let v=0;v<f.length;v++){let b=f[v][1]/f[v][0];if(c===2)m([f[v]],h/b);else for(let y=v;y<f.length;y++)m([f[v],f[y]],h/b/(f[y][1]/f[y][0]))}if(!u)throw new Error(`train_for(): no train of ${c} stages reaches a ratio of ${t}`);let p=u.stages.map(([v,b])=>l?[b,v]:[v,b]),g=p.reduce((v,[b,y])=>v*y/b,1);return{type:"record",fields:new Map([["stages",p],["ratio",g],["error",g/t-1]])}}),path_points:c1("d, tolerance",(n,e)=>{if(typeof n[0]!="string")throw new Error("path_points() needs SVG path data");let t=n[1]===void 0?.05:a1(n[1],"path_points");if(!(t>0))throw new Error("path_points(): tolerance must be more than 0");let c=F2(N3(n[0]),t),a=[...c.closed.map(r=>[...r,r[0]]),...c.open];return e.step(a.reduce((r,s)=>r+s.length,0)),a.map(r=>r.map(([s,i])=>[s,i]))}),spline_points:c1("points, steps, closed",(n,e)=>{let t=s3(n[0],"spline_points",e),c=n[1]===void 0?8:Math.floor(a1(n[1],"spline_points"));if(!(c>=1))throw new Error("spline_points(): steps must be 1 or more");if(t.length*c>e.maxLength)throw new Error("spline_points(): the result would be too long");return e.step(t.length*c),$5(t,c,n[2]===!0)}),rotation:c1("angles",n=>{let[e,t,c]=R5(n[0],"rotation");return qt(de(Rt(c),de(Dt(t),_t(e))))}),euler:c1("matrix",n=>pe(Ft(n[0],"euler"))),orient:c1("x, z",n=>{let e=fe(R5(n[0],"orient"),"orient"),t=R5(n[1]??[0,0,1],"orient"),c=t[0]*e[0]+t[1]*e[1]+t[2]*e[2];t=fe([t[0]-c*e[0],t[1]-c*e[1],t[2]-c*e[2]],"orient");let a=[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]];return pe([[e[0],a[0],t[0]],[e[1],a[1],t[1]],[e[2],a[2],t[2]]])})};function s3(n,e,t){return a0(n,e,t).map((a,r)=>{if(!Array.isArray(a)||typeof a[0]!="number"||typeof a[1]!="number")throw new Error(`${e}(): points[${r}] must be an [x, y] point`);return[a[0],a[1]]})}function ue(n,e){if(n.length<2)throw new Error("a path needs at least two points");let t=n.filter(([o,l],h)=>h===0||o!==n[h-1][0]||l!==n[h-1][1]);if(t.length<2)return{point:[t[0][0],t[0][1]],heading:0};let c=0,a=0;for(;c<t.length-2;c++){let o=Math.hypot(t[c+1][0]-t[c][0],t[c+1][1]-t[c][1]);if(a+o>=e)break;a+=o}let[r,s]=[t[c],t[c+1]],i=(e-a)/Math.hypot(s[0]-r[0],s[1]-r[1]);return{point:[r[0]+(s[0]-r[0])*i,r[1]+(s[1]-r[1])*i],heading:Math.atan2(s[1]-r[1],s[0]-r[0])/Q1}}function R5(n,e){if(!Array.isArray(n)||n.length<2||n.length>3||!n.every(t=>typeof t=="number"))throw new Error(`${e}() needs [x, y, z]`);return[n[0],n[1],n[2]??0]}function fe(n,e){let t=Math.hypot(...n);if(!(t>1e-12))throw new Error(`${e}(): a direction can't be [0, 0, 0], or x and z the same way`);return[n[0]/t,n[1]/t,n[2]/t]}function Ft(n,e){if(!Array.isArray(n)||n.length<3||!n.slice(0,3).every(t=>Array.isArray(t)&&t.length>=3&&t.slice(0,3).every(c=>typeof c=="number")))throw new Error(`${e}() needs a 3x3 matrix`);return n.slice(0,3).map(t=>t.slice(0,3))}var _t=n=>{let[e,t]=[Math.cos(n*Q1),Math.sin(n*Q1)];return[[1,0,0],[0,e,-t],[0,t,e]]},Dt=n=>{let[e,t]=[Math.cos(n*Q1),Math.sin(n*Q1)];return[[e,0,t],[0,1,0],[-t,0,e]]},Rt=n=>{let[e,t]=[Math.cos(n*Q1),Math.sin(n*Q1)];return[[e,-t,0],[t,e,0],[0,0,1]]},de=(n,e)=>n.map(t=>[0,1,2].map(c=>t[0]*e[0][c]+t[1]*e[1][c]+t[2]*e[2][c])),qt=n=>n.map(e=>e.map(E0));function pe(n){let e=-n[2][0];if(Math.abs(e)>1-1e-12){let t=e>0?90:-90,c=Math.atan2(-n[0][1],n[1][1])/Q1;return[0,t,E0(c)]}return[E0(Math.atan2(n[2][1],n[2][2])/Q1),E0(Math.asin(e)/Q1),E0(Math.atan2(n[1][0],n[0][0])/Q1)]}function $5(n,e,t=!1){if(n.length<3)return n.map(([s,i])=>[s,i]);let c=s=>{if(t)return n[(s%n.length+n.length)%n.length];if(s<0)return[2*n[0][0]-n[1][0],2*n[0][1]-n[1][1]];if(s>=n.length){let[i,o]=[n[n.length-1],n[n.length-2]];return[2*i[0]-o[0],2*i[1]-o[1]]}return n[s]},a=[],r=t?n.length:n.length-1;for(let s=0;s<r;s++){let[i,o,l,h]=[c(s-1),c(s),c(s+1),c(s+2)];for(let f=0;f<e;f++){let u=f/e,d=u*u,m=d*u;a.push([0,1].map(p=>.5*(2*o[p]+(-i[p]+l[p])*u+(2*i[p]-5*o[p]+4*l[p]-h[p])*d+(-i[p]+3*o[p]-3*l[p]+h[p])*m)))}}return a.push(t?a[0]:[n[n.length-1][0],n[n.length-1][1]]),a}var C1;(function(n){n[n.NoClip=0]="NoClip",n[n.Intersection=1]="Intersection",n[n.Union=2]="Union",n[n.Difference=3]="Difference",n[n.Xor=4]="Xor"})(C1||(C1={}));var r0;(function(n){n[n.Subject=0]="Subject",n[n.Clip=1]="Clip"})(r0||(r0={}));var g1;(function(n){n[n.EvenOdd=0]="EvenOdd",n[n.NonZero=1]="NonZero",n[n.Positive=2]="Positive",n[n.Negative=3]="Negative"})(g1||(g1={}));var v1;(function(n){n[n.IsOn=0]="IsOn",n[n.IsInside=1]="IsInside",n[n.IsOutside=2]="IsOutside"})(v1||(v1={}));var _2=Number.MAX_SAFE_INTEGER,N1=Math.floor(Math.sqrt(_2));function G3(n,e){return!Number.isSafeInteger(n)||!Number.isSafeInteger(e)?!1:n===0||e===0?!0:Math.abs(n)<=_2/Math.abs(e)}function xe(n,e){return Math.abs(n)+Math.abs(e)<=_2}function U5(n,e,t,c){if(G3(n,e)&&G3(t,c)){let a=n*e,r=t*c;if(xe(a,r))return a-r}return Number.isSafeInteger(n)&&Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(c)?Number(BigInt(n)*BigInt(e)-BigInt(t)*BigInt(c)):n*e-t*c}function N5(n,e,t,c){if(G3(n,e)&&G3(t,c)){let a=n*e,r=t*c;if(xe(a,r))return a+r}return Number.isSafeInteger(n)&&Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(c)?Number(BigInt(n)*BigInt(e)+BigInt(t)*BigInt(c)):n*e+t*c}var B5=BigInt(0),j3=BigInt(2),$t=BigInt(4),Ut=BigInt(64),Nt=BigInt("0xFFFFFFFFFFFFFFFF"),W5=BigInt("9223372036854775807"),o3=Number(W5/$t),Me=Number(W5),we=1e-12,Bt=.1,G5=Math.floor(N1/2),Gt=Math.floor(Math.sqrt(Math.sqrt(_2/4)));function jt(n){if(!Number.isFinite(n))throw new RangeError("Scale must be a finite number");let e=Math.abs(n);return e===0?Number.POSITIVE_INFINITY:_2/e}function Wt(n,e,t){if(!Number.isFinite(n)||Math.abs(n)>e)throw new RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${t}`)}function Xt(n,e){if(!Number.isFinite(n)||Math.abs(n)>_2)throw new RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${e}`)}function Zt(n,e,t){let c=e.x-n.x,a=t.y-e.y,r=e.y-n.y,s=t.x-e.x;return Math.abs(c)<N1&&Math.abs(a)<N1&&Math.abs(r)<N1&&Math.abs(s)<N1?c*a-r*s:U5(c,a,r,s)}function T0(n,e,t){let c=e.x-n.x,a=t.y-e.y,r=e.y-n.y,s=t.x-e.x;if(Math.abs(c)<N1&&Math.abs(a)<N1&&Math.abs(r)<N1&&Math.abs(s)<N1){let l=c*a,h=r*s;return l>h?1:l<h?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)){let l=c*a,h=r*s;return l>h?1:l<h?-1:0}let i=BigInt(c)*BigInt(a),o=BigInt(r)*BigInt(s);return i===o?0:i>o?1:-1}function Yt(n){if(n<-8||n>8)throw new Error("Error: Precision is out of range.")}function Kt(n){return Math.abs(n)<=we}function Jt(n){return n<0?-1:n>0?1:0}function Qt(n,e){let t=BigInt(n),c=BigInt(e),a=t*c;return{lo64:a&Nt,hi64:a>>Ut}}function ze(n,e,t,c){let a=Math.abs(n),r=Math.abs(e),s=Math.abs(t),i=Math.abs(c);if(a<N1&&r<N1&&s<N1&&i<N1)return n*e===t*c;let o=(n<0?-1:n>0?1:0)*(e<0?-1:e>0?1:0),l=(t<0?-1:t>0?1:0)*(c<0?-1:c>0?1:0);if(o!==l)return!1;if(o===0)return!0;if(!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)||!Number.isSafeInteger(i))return n*e===t*c;let h=BigInt(a),f=BigInt(r),u=BigInt(s),d=BigInt(i);return h*f===u*d}function e8(n,e,t){let c=e.x-n.x,a=t.y-e.y,r=e.y-n.y,s=t.x-e.x;return ze(c,a,r,s)}function t8(n,e,t){let c=e.x-n.x,a=t.x-e.x,r=e.y-n.y,s=t.y-e.y;return Math.abs(c)<N1&&Math.abs(a)<N1&&Math.abs(r)<N1&&Math.abs(s)<N1?c*a+r*s:N5(c,a,r,s)}function n8(n,e,t){let c=e.x-n.x,a=t.x-e.x,r=e.y-n.y,s=t.y-e.y;if(Math.abs(c)<N1&&Math.abs(a)<N1&&Math.abs(r)<N1&&Math.abs(s)<N1){let o=c*a+r*s;return o>0?1:o<0?-1:0}if(!Number.isSafeInteger(c)||!Number.isSafeInteger(a)||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)){let o=c*a+r*s;return o>0?1:o<0?-1:0}let i=BigInt(c)*BigInt(a)+BigInt(r)*BigInt(s);return i===B5?0:i>B5?1:-1}function c8(n){let e=n.length;if(e<3)return 0;let t=!0;for(let r=0;r<e&&t;r++){let s=n[r];(Math.abs(s.x)>=G5||Math.abs(s.y)>=G5)&&(t=!1)}let c=n[e-1];if(t){let r=0;for(let s of n)r+=(c.y+s.y)*(c.x-s.x),c=s;return r*.5}let a=B5;for(let r of n){let s=c.y+r.y,i=c.x-r.x;if(Number.isSafeInteger(s)&&Number.isSafeInteger(i))a+=BigInt(s)*BigInt(i);else if(Number.isSafeInteger(c.y)&&Number.isSafeInteger(r.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(r.x)){let o=BigInt(c.y)+BigInt(r.y),l=BigInt(c.x)-BigInt(r.x);a+=o*l}else a+=BigInt(Math.round(s*i));c=r}return Number(a)*.5}function a8(n,e){return n.y*e.x-e.y*n.x}function r8(n,e){return n.x*e.x+n.y*e.y}function s8(n){let e=Math.round(n);return n===e-.5&&(e&1)!==0?e-1:e}function i8(n){return n>=o3||n<=-o3?Me:Math.round(n)}function o8(n,e,t,c){let a=e.y-n.y,r=e.x-n.x,s=c.y-t.y,i=c.x-t.x,o=U5(a,i,s,r);if(o===0)return null;let l=U5(n.x-t.x,s,n.y-t.y,i)/o;return l<=0?{x:n.x,y:n.y,z:n.z||0}:l>=1?{x:e.x,y:e.y,z:e.z||0}:{x:Math.trunc(n.x+l*r),y:Math.trunc(n.y+l*a),z:0}}function l8(n,e,t,c){let a=e.y-n.y,r=e.x-n.x,s=c.y-t.y,i=c.x-t.x,o=a*i-s*r;if(o===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((n.x-t.x)*s-(n.y-t.y)*i)/o,h;return l<=0?h={...n,z:0}:l>=1?h={...e,z:0}:h={x:n.x+l*r,y:n.y+l*a,z:0},{success:!0,ip:h}}function h8(n,e,t,c,a=!1){if(!a){let l=T0(n,t,c),h=T0(e,t,c),f=T0(t,n,e),u=T0(c,n,e);return l!==0&&h!==0&&l!==h&&f!==0&&u!==0&&f!==u}let r=T0(n,t,c),s=T0(e,t,c);if(r!==0&&r===s)return!1;let i=T0(t,n,e),o=T0(c,n,e);return i!==0&&i===o?!1:r!==0||s!==0||i!==0||o!==0}function ke(n){if(n.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 t of n)t.x<e.left&&(e.left=t.x),t.x>e.right&&(e.right=t.x),t.y<e.top&&(e.top=t.y),t.y>e.bottom&&(e.bottom=t.y);return e.left===Number.MAX_SAFE_INTEGER?{left:0,top:0,right:0,bottom:0}:e}function u8(n,e,t){if(e.x===t.x&&e.y===t.y)return{x:e.x,y:e.y,z:0};let c=t.x-e.x,a=t.y-e.y,r=N5(n.x-e.x,c,n.y-e.y,a)/N5(c,c,a,a),s=r<0?0:r>1?1:r;return{x:Math.round(e.x+s*c),y:Math.round(e.y+s*a),z:0}}function j5(n,e){let t=e.length,c=0;if(t<3)return v1.IsOutside;for(;c<t&&e[c].y===n.y;)c++;if(c===t)return v1.IsOutside;let a=e[c].y<n.y,r=a,s=0,i=c+1,o=t;for(;;){if(i===o){if(o===0||c===0)break;o=c,i=0}if(a)for(;i<o&&e[i].y<n.y;)i++;else for(;i<o&&e[i].y>n.y;)i++;if(i===o)continue;let h=e[i],f=i>0?e[i-1]:e[t-1];if(h.y===n.y){if(h.x===n.x||h.y===f.y&&n.x<f.x!=n.x<h.x)return v1.IsOn;if(i++,i===c)break;continue}if(!(n.x<h.x&&n.x<f.x))if(n.x>f.x&&n.x>h.x)s=1-s;else{let u=T0(f,h,n);if(u===0)return v1.IsOn;u<0===a&&(s=1-s)}a=!a,i++}if(a===r)return s===0?v1.IsOutside:v1.IsInside;i===t&&(i=0);let l=i===0?T0(e[t-1],e[0],n):T0(e[i-1],e[i],n);return l===0?v1.IsOn:(l<0===a&&(s=1-s),s===0?v1.IsOutside:v1.IsInside)}function f8(n,e){let t=v1.IsOn;for(let i of n)switch(j5(i,e)){case v1.IsOutside:if(t===v1.IsOutside)return!1;t=v1.IsOutside;break;case v1.IsInside:if(t===v1.IsInside)return!0;t=v1.IsInside;break;default:break}let c=ke(n),a,r;return Number.isSafeInteger(c.left)&&Number.isSafeInteger(c.right)&&Math.abs(c.left)+Math.abs(c.right)>Number.MAX_SAFE_INTEGER?(a=Number((BigInt(c.left)+BigInt(c.right))/j3),r=Number((BigInt(c.top)+BigInt(c.bottom))/j3)):(a=Math.round((c.left+c.right)/2),r=Math.round((c.top+c.bottom)/2)),j5({x:a,y:r},e)!==v1.IsOutside}var d1={MaxInt64:W5,MaxCoord:o3,max_coord:o3,min_coord:-o3,Invalid64:Me,floatingPointTolerance:we,defaultMinimumEdgeLength:Bt,maxCoordForSafeAreaProduct:G5,maxCoordForSafeCrossSq:Gt,maxSafeCoordinateForScale:jt,checkSafeScaleValue:Wt,ensureSafeInteger:Xt,crossProduct:Zt,crossProductSign:T0,checkPrecision:Yt,isAlmostZero:Kt,triSign:Jt,multiplyUInt64:Qt,productsAreEqual:ze,isCollinear:e8,dotProduct:t8,dotProductSign:n8,area:c8,crossProductD:a8,dotProductD:r8,roundToEven:s8,checkCastInt64:i8,getLineIntersectPt:o8,getLineIntersectPtD:l8,segsIntersect:h8,getBounds:ke,getClosestPtOnSegment:u8,pointInPolygon:j5,path2ContainsPath1:f8},W0={create(n=0,e=0,t=0){return{x:Math.round(n),y:Math.round(e),z:t}},fromPointD(n){return d1.ensureSafeInteger(n.x,"Point64Utils.fromPointD"),d1.ensureSafeInteger(n.y,"Point64Utils.fromPointD"),{x:Math.round(n.x),y:Math.round(n.y),z:n.z||0}},scale(n,e){return{x:Math.round(n.x*e),y:Math.round(n.y*e),z:n.z||0}},equals(n,e){return n.x===e.x&&n.y===e.y},add(n,e){if(Number.isSafeInteger(n.x)&&Number.isSafeInteger(e.x)&&Number.isSafeInteger(n.y)&&Number.isSafeInteger(e.y)){let t=n.x+e.x,c=n.y+e.y;return Number.isSafeInteger(t)&&Number.isSafeInteger(c)?{x:t,y:c,z:0}:{x:Number(BigInt(n.x)+BigInt(e.x)),y:Number(BigInt(n.y)+BigInt(e.y)),z:0}}return{x:n.x+e.x,y:n.y+e.y,z:0}},subtract(n,e){return{x:n.x-e.x,y:n.y-e.y,z:0}},toString(n){return n.z!==void 0&&n.z!==0?`${n.x},${n.y},${n.z} `:`${n.x},${n.y} `}},W3={create(n=0,e=0,t=0){return{x:n,y:e,z:t}},fromPoint64(n){return{x:n.x,y:n.y,z:n.z||0}},scale(n,e){return{x:n.x*e,y:n.y*e,z:n.z||0}},equals(n,e){return d1.isAlmostZero(n.x-e.x)&&d1.isAlmostZero(n.y-e.y)},negate(n){n.x=-n.x,n.y=-n.y},toString(n,e=2){return n.z!==void 0&&n.z!==0?`${n.x.toFixed(e)},${n.y.toFixed(e)},${n.z}`:`${n.x.toFixed(e)},${n.y.toFixed(e)}`}},w2={create(n=0,e=0,t=0,c=0){return{left:n,top:e,right:t,bottom:c}},createInvalid(){return{left:Number.MAX_SAFE_INTEGER,top:Number.MAX_SAFE_INTEGER,right:Number.MIN_SAFE_INTEGER,bottom:Number.MIN_SAFE_INTEGER}},width(n){return n.right-n.left},height(n){return n.bottom-n.top},isEmpty(n){return n.bottom<=n.top||n.right<=n.left},isValid(n){return n.left<Number.MAX_SAFE_INTEGER},midPoint(n){if(Number.isSafeInteger(n.left)&&Number.isSafeInteger(n.right)&&Math.abs(n.left)+Math.abs(n.right)>Number.MAX_SAFE_INTEGER){let e=Number((BigInt(n.left)+BigInt(n.right))/j3),t=Number((BigInt(n.top)+BigInt(n.bottom))/j3);return{x:e,y:t}}return{x:Math.round((n.left+n.right)/2),y:Math.round((n.top+n.bottom)/2)}},contains(n,e){return e.x>n.left&&e.x<n.right&&e.y>n.top&&e.y<n.bottom},containsRect(n,e){return e.left>=n.left&&e.right<=n.right&&e.top>=n.top&&e.bottom<=n.bottom},intersects(n,e){return Math.max(n.left,e.left)<=Math.min(n.right,e.right)&&Math.max(n.top,e.top)<=Math.min(n.bottom,e.bottom)},asPath(n){return[{x:n.left,y:n.top,z:0},{x:n.right,y:n.top,z:0},{x:n.right,y:n.bottom,z:0},{x:n.left,y:n.bottom,z:0}]}},X5={create(n=0,e=0,t=0,c=0){return{left:n,top:e,right:t,bottom:c}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(n){return n.right-n.left},height(n){return n.bottom-n.top},isEmpty(n){return n.bottom<=n.top||n.right<=n.left},midPoint(n){return{x:(n.left+n.right)/2,y:(n.top+n.bottom)/2}},contains(n,e){return e.x>n.left&&e.x<n.right&&e.y>n.top&&e.y<n.bottom},containsRect(n,e){return e.left>=n.left&&e.right<=n.right&&e.top>=n.top&&e.bottom<=n.bottom},intersects(n,e){return Math.max(n.left,e.left)<Math.min(n.right,e.right)&&Math.max(n.top,e.top)<Math.min(n.bottom,e.bottom)},asPath(n){return[{x:n.left,y:n.top,z:0},{x:n.right,y:n.top,z:0},{x:n.right,y:n.bottom,z:0},{x:n.left,y:n.bottom,z:0}]}};var Le=Object.freeze(w2.createInvalid()),Ae=Object.freeze(X5.createInvalid());var l3=BigInt(0),d8=BigInt(2),Se=BigInt(4),y1;(function(n){n[n.None=0]="None",n[n.OpenStart=1]="OpenStart",n[n.OpenEnd=2]="OpenEnd",n[n.LocalMax=4]="LocalMax",n[n.LocalMin=8]="LocalMin"})(y1||(y1={}));var Z5=class{constructor(){q(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],t=this.data.pop();return this.data.length>0&&(this.data[0]=t,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let t=this.data[e];for(;e>0;){let c=e-1>>1;if(this.data[c]>=t)break;this.data[e]=this.data[c],e=c}this.data[e]=t}siftDown(e){let t=this.data.length,c=this.data[e];for(;;){let a=(e<<1)+1;if(a>=t)break;let r=a+1,s=a;if(r<t&&this.data[r]>this.data[a]&&(s=r),this.data[s]<=c)break;this.data[e]=this.data[s],e=s}this.data[e]=c}},h3=class{constructor(e,t,c){q(this,"pt");q(this,"next",null);q(this,"prev",null);q(this,"flags");this.pt=e,this.flags=t,this.prev=c}},u3=class{constructor(e,t,c=!1){q(this,"vertex");q(this,"polytype");q(this,"isOpen");this.vertex=e,this.polytype=t,this.isOpen=c}equals(e){return e!==null&&this.vertex===e.vertex}};function Ce(n,e,t){return{pt:n,edge1:e,edge2:t}}var a2=class{constructor(e,t){q(this,"pt");q(this,"next");q(this,"prev");q(this,"outrec");q(this,"horz");this.pt=e,this.outrec=t,this.next=this,this.prev=this,this.horz=null}},p0;(function(n){n[n.None=0]="None",n[n.Left=1]="Left",n[n.Right=2]="Right"})(p0||(p0={}));var Y5;(function(n){n[n.Bottom=0]="Bottom",n[n.Middle=1]="Middle",n[n.Top=2]="Top"})(Y5||(Y5={}));var X3=class{constructor(){q(this,"idx",0);q(this,"owner",null);q(this,"frontEdge",null);q(this,"backEdge",null);q(this,"pts",null);q(this,"polypath",null);q(this,"bounds",{left:0,top:0,right:0,bottom:0});q(this,"path",[]);q(this,"isOpen",!1);q(this,"splits",null);q(this,"recursiveSplit",null)}},Z3=class{constructor(e){q(this,"leftOp");q(this,"rightOp");q(this,"leftToRight");this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},f3=class{constructor(e,t){q(this,"op1");q(this,"op2");this.op1=e,this.op2=t}};function p8(n,e){return n.rightOp===null?e.rightOp===null?0:1:e.rightOp===null?-1:n.leftOp.pt.x-e.leftOp.pt.x}function m8(n,e){return n.pt.y!==e.pt.y?n.pt.y>e.pt.y?-1:1:n.pt.x!==e.pt.x?n.pt.x<e.pt.x?-1:1:n.edge1.curX!==e.edge1.curX?n.edge1.curX<e.edge1.curX?-1:1:n.edge2.curX<e.edge2.curX?-1:n.edge2.curX>e.edge2.curX?1:0}var d3=class{constructor(){q(this,"bot",{x:0,y:0});q(this,"top",{x:0,y:0});q(this,"curX",0);q(this,"dx",0);q(this,"windDx",0);q(this,"windCount",0);q(this,"windCount2",0);q(this,"outrec",null);q(this,"prevInAEL",null);q(this,"nextInAEL",null);q(this,"prevInSEL",null);q(this,"nextInSEL",null);q(this,"jump",null);q(this,"vertexTop",null);q(this,"localMin",null);q(this,"isLeftBound",!1);q(this,"joinWith",p0.None)}},D2={addLocMin(n,e,t,c){if((n.flags&y1.LocalMin)!==y1.None)return;n.flags|=y1.LocalMin;let a=new u3(n,e,t);c.push(a)},addPathsToVertexList(n,e,t,c,a){for(let r=0,s=n.length;r<s;r++){let i=n[r],o=null,l=null,h=null;for(let m=0,p=i.length;m<p;m++){let g=i[m];if(o===null)o=new h3(g,y1.None,null),a.push(o),l=o,h=g;else if(!(h.x===g.x&&h.y===g.y)){let v=new h3(g,y1.None,l);l.next=v,l=v,h=g}}if(l?.prev==null||(!t&&l.pt.x===o.pt.x&&l.pt.y===o.pt.y&&(l=l.prev),l.next=o,o.prev=l,!t&&l.next===l))continue;let f;if(t){let m=o.next;for(;m!==o&&m.pt.y===o.pt.y;)m=m.next;f=m.pt.y<=o.pt.y,f?(o.flags=y1.OpenStart,D2.addLocMin(o,e,!0,c)):o.flags=y1.OpenStart|y1.LocalMax}else{for(l=o.prev;l!==o&&l.pt.y===o.pt.y;)l=l.prev;if(l===o)continue;f=l.pt.y>o.pt.y}let u=f;l=o;let d=o.next;for(;d!==o;)d.pt.y>l.pt.y&&f?(l.flags|=y1.LocalMax,f=!1):d.pt.y<l.pt.y&&!f&&(f=!0,D2.addLocMin(l,e,t,c)),l=d,d=d.next;t?(l.flags|=y1.OpenEnd,f?l.flags|=y1.LocalMax:D2.addLocMin(l,e,t,c)):f!==u&&(u?D2.addLocMin(l,e,!1,c):l.flags|=y1.LocalMax)}}};var Y3=class{constructor(e=null){q(this,"parent");q(this,"children",[]);this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,t=this.parent;for(;t!==null;)++e,t=t.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,t){let c="",a=" ".repeat(t),r=this.children.length===1?"":"s";(t&1)===0?c+=`${a}+- hole (${e}) contains ${this.children.length} nested polygon${r}.
|
|
3
3
|
`:c+=`${a}+- polygon (${e}) contains ${this.children.length} hole${r}.
|
|
4
4
|
`;for(let s=0;s<this.count;s++)this.children[s].count>0&&(c+=this.children[s].toStringInternal(s,t+1));return c}toString(){if(this.level>0)return"";let e=this.children.length===1?"":"s",t=`Polytree with ${this.children.length} polygon${e}.
|
|
5
5
|
`;for(let c=0;c<this.count;c++)this.children[c].count>0&&(t+=this.children[c].toStringInternal(c,1));return t+`
|
|
6
|
-
`}},C3=class n extends A3{constructor(t=null){super(t);F(this,"polygon",null)}get poly(){return this.polygon}addChild(t){let c=new n(this);return c.polygon=t,this.children.push(c),c}child(t){if(t<0||t>=this.children.length)throw new Error("Index out of range");return this.children[t]}area(){let t=this.polygon===null?0:I5.area(this.polygon);for(let c of this.children)t+=c.area();return t}};var J2=class extends C3{};var P=class P{constructor(){F(this,"cliptype",M1.NoClip);F(this,"fillrule",p1.EvenOdd);F(this,"actives",null);F(this,"sel",null);F(this,"minimaList",[]);F(this,"intersectList",[]);F(this,"vertexList",[]);F(this,"outrecList",[]);F(this,"scanlineHeap",new E5);F(this,"scanlineSet",new Set);F(this,"scanlineArr",[]);F(this,"useScanlineArray",!1);F(this,"horzSegList",[]);F(this,"horzJoinList",[]);F(this,"currentLocMin",0);F(this,"currentBotY",0);F(this,"curXValidAtTop",!1);F(this,"isSortedMinimaList",!1);F(this,"hasOpenPaths",!1);F(this,"usingPolytree",!1);F(this,"succeeded",!1);F(this,"zCallbackInternal");F(this,"preserveCollinear",!0);F(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,t){return e.x===t.x&&e.y===t.y}setZ(e,t,c){let a=this.zCallbackInternal;a&&(P.getPolyType(e)===K1.Subject?(this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:this.xyEqual(c,t.bot)?c.z=t.bot.z??0:this.xyEqual(c,t.top)?c.z=t.top.z??0:c.z=0,a(e.bot,e.top,t.bot,t.top,c)):(this.xyEqual(c,t.bot)?c.z=t.bot.z??0:this.xyEqual(c,t.top)?c.z=t.top.z??0:this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:c.z=0,a(t.bot,t.top,e.bot,e.top,c)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return P.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return P.openPathsEnabled&&e.localMin.isOpen&&P.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(g1.OpenStart|g1.OpenEnd))!==g1.None}static getPrevHotEdge(e){let t=e.prevInAEL;if(!P.openPathsEnabled){for(;t!==null&&!P.isHotEdge(t);)t=t.prevInAEL;return t}for(;t!==null&&(t.localMin.isOpen||!P.isHotEdge(t));)t=t.prevInAEL;return t}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,t){let c=t.y-e.y;return c!==0?(t.x-e.x)/c:t.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,t){return t===e.top.y||e.top.x===e.bot.x?e.top.x:t===e.bot.y?e.bot.x:h1.roundToEven(e.bot.x+e.dx*(t-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,t){return e.localMin.polytype===t.localMin.polytype}static setDx(e){e.dx=P.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&g1.LocalMax)!==g1.None}static isMaximaEdge(e){return(e.vertexTop.flags&g1.LocalMax)!==g1.None}static getMaximaPair(e){let t=e.nextInAEL;for(;t!==null;){if(t.vertexTop===e.vertexTop)return t;t=t.nextInAEL}return null}boundingBoxesOverlap(e,t,c,a){let r=e.x<t.x?e.x:t.x;if((c.x>a.x?c.x:a.x)<r)return!1;let i=e.x>t.x?e.x:t.x,o=c.x<a.x?c.x:a.x;if(i<o)return!1;let l=e.y<t.y?e.y:t.y;if((c.y>a.y?c.y:a.y)<l)return!1;let f=e.y>t.y?e.y:t.y,u=c.y<a.y?c.y:a.y;return f>=u}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,t)=>t.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 t=0,c=e.length;t<c;t++){let a=e[t];this.scanlineSet.add(a),this.scanlineHeap.push(a)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let t=this.scanlineArr;for(let c=0,a=t.length;c<a;c++)if(t[c]===e)return;t.push(e),t.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let t=this.scanlineArr,c=t.length;if(c===0)return null;let a=0,r=t[0];for(let s=1;s<c;s++){let i=t[s];i>r&&(r=i,a=s)}return t[a]=t[c-1],t.pop(),r}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,t,c=!1){let a=[e];this.addPaths(a,t,c)}addPaths(e,t,c=!1){c&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,C2.addPathsToVertexList(e,t,c,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let t of e.minimaList)this.minimaList.push(new Z2(t.vertex,t.polytype,t.isOpen)),t.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let t=e.prevInAEL,c=e.nextInAEL;t===null&&c===null&&e!==this.actives||(t!==null?t.nextInAEL=c:this.actives=c,c!==null&&(c.prevInAEL=t))}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 t of this.vertexList){let c=t;do c.pt.x<e.left&&(e.left=c.pt.x),c.pt.x>e.right&&(e.right=c.pt.x),c.pt.y<e.top&&(e.top=c.pt.y),c.pt.y>e.bottom&&(e.bottom=c.pt.y),c=c.next;while(c!==t)}return d2.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,t){if(e===M1.NoClip)return;P.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=t,this.cliptype=e,this.reset();let c=this.popScanline();if(c!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(c);let a;for(;(a=this.popHorz())!==null;)this.doHorizontal(a);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=c;let r=this.popScanline();if(r===null)break;for(c=r,this.doIntersections(c),this.doTopOfScanbeam(c);(a=this.popHorz())!==null;)this.doHorizontal(a)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let t=this.popLocalMinima(),c;(t.vertex.flags&g1.OpenStart)!==g1.None?c=null:(c=new K2,c.bot=t.vertex.pt,c.curX=t.vertex.pt.x,c.windDx=-1,c.vertexTop=t.vertex.prev,c.top=t.vertex.prev.pt,c.outrec=null,c.localMin=t,P.setDx(c));let a;if((t.vertex.flags&g1.OpenEnd)!==g1.None?a=null:(a=new K2,a.bot=t.vertex.pt,a.curX=t.vertex.pt.x,a.windDx=1,a.vertexTop=t.vertex.next,a.top=t.vertex.next.pt,a.outrec=null,a.localMin=t,P.setDx(a)),c!==null&&a!==null){if(P.isHorizontal(c)){if(P.isHeadingRightHorz(c)){let s=c;c=a,a=s}}else if(P.isHorizontal(a)){if(P.isHeadingLeftHorz(a)){let s=c;c=a,a=s}}else if(c.dx<a.dx){let s=c;c=a,a=s}}else c===null&&(c=a,a=null);let r;if(c.isLeftBound=!0,this.insertLeftEdge(c),P.openPathsEnabled?P.isOpen(c)?(this.setWindCountForOpenPathEdge(c),r=this.isContributingOpen(c)):(this.setWindCountForClosedPathEdge(c),r=this.isContributingClosed(c)):(this.setWindCountForClosedPathEdge(c),r=this.isContributingClosed(c)),a!==null){for(a.windCount=c.windCount,a.windCount2=c.windCount2,this.insertRightEdge(c,a),r&&(this.addLocalMinPoly(c,a,c.bot,!0),P.isHorizontal(c)||this.checkJoinLeft(c,c.bot));a.nextInAEL!==null&&this.isValidAelOrder(a.nextInAEL,a);)this.intersectEdges(a,a.nextInAEL,a.bot),this.swapPositionsInAEL(a,a.nextInAEL);P.isHorizontal(a)?this.pushHorz(a):(this.checkJoinRight(a,a.bot),this.insertScanline(a.top.y))}else r&&P.openPathsEnabled&&this.startOpenPath(c,c.bot);P.isHorizontal(c)?this.pushHorz(c):this.insertScanline(c.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!P.openPathsEnabled){this.doHorizontalClosed(e);return}let t=P.isOpen(e),c=e.bot.y,a=t?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:r,leftX:s,rightX:i}=this.resetHorzDirection(e,a),o=s,l=i;if(P.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:c});this.addToHorzSegList(h)}for(;;){let h=r?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===a){if(P.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),P.isHotEdge(e)){for(;e.vertexTop!==a;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);r?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(a!==e.vertexTop||P.isOpenEnd(e)){if(r&&h.curX>l||!r&&h.curX<o)break;if(h.curX===e.top.x&&!P.isHorizontal(h)){let d=P.nextVertex(e).pt;if(P.isOpen(h)&&!P.isSamePolyType(h,e)&&!P.isHotEdge(h)){if(r&&P.topX(h,d.y)>d.x||!r&&P.topX(h,d.y)<d.x)break}else if(r&&P.topX(h,d.y)>=d.x||!r&&P.topX(h,d.y)<=d.x)break}}let u={x:h.curX,y:c};r?(this.intersectEdges(e,h,u),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,u),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,u),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,u),e.curX=h.curX,h=e.prevInAEL),P.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(t&&P.isOpenEnd(e)){P.isHotEdge(e)&&(this.addOutPt(e,e.top),P.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(P.nextVertex(e).pt.y!==e.top.y)break;P.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let f=this.resetHorzDirection(e,a);o=f.leftX,l=f.rightX}if(P.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let t=e.bot.y,c=this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:r,rightX:s}=this.resetHorzDirection(e,c),i=r,o=s;if(P.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:t});this.addToHorzSegList(l)}for(;;){let l=a?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===c){if(P.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),P.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(c!==e.vertexTop){if(a&&l.curX>o||!a&&l.curX<i)break;if(l.curX===e.top.x&&!P.isHorizontal(l)){let u=P.nextVertex(e).pt,d=P.topX(l,u.y);if(a&&d>=u.x||!a&&d<=u.x)break}}let f={x:l.curX,y:t};a?(this.intersectEdges(e,l,f),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,f),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,f),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,f),e.curX=l.curX,l=e.prevInAEL),P.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(P.nextVertex(e).pt.y!==e.top.y)break;P.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(P.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,t=0;for(let c=0,a=e.length;c<a;c++){let r=e[c];this.updateHorzSegment(r)&&(e[t++]=r)}if(!(t<2)){e.length=t,this.horzSegList.sort(je);for(let c=0;c<t-1;c++){let a=this.horzSegList[c];for(let r=c+1;r<t;r++){let s=this.horzSegList[r];if(s.leftOp.pt.x>=a.rightOp.pt.x||s.leftToRight===a.leftToRight||s.rightOp.pt.x<=a.leftOp.pt.x)continue;let i=a.leftOp.pt.y;if(a.leftToRight){for(;a.leftOp.next.pt.y===i&&a.leftOp.next.pt.x<=s.leftOp.pt.x;)a.leftOp=a.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=a.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new Y2(this.duplicateOp(a.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;a.leftOp.prev.pt.y===i&&a.leftOp.prev.pt.x<=s.leftOp.pt.x;)a.leftOp=a.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=a.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new Y2(this.duplicateOp(s.leftOp,!0),this.duplicateOp(a.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let t=e.leftOp,c=this.getRealOutRec(t.outrec),a=c.frontEdge!==null,r=t.pt.y,s=t,i=t;if(a){let l=c.pts,h=l.next;for(;s!==h&&s.prev.pt.y===r;)s=s.prev;for(;i!==l&&i.next.pt.y===r;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===r;)s=s.prev;for(;i.next!==s&&i.next.pt.y===r;)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,t,c){return t.pt.x===c.pt.x?!1:(t.pt.x<c.pt.x?(e.leftOp=t,e.rightOp=c,e.leftToRight=!0):(e.leftOp=c,e.rightOp=t,e.leftToRight=!1),!0)}duplicateOp(e,t){let c=new X0(e.pt,e.outrec);return t?(c.next=e.next,c.next.prev=c,c.prev=e,e.next=c):(c.prev=e.prev,c.prev.next=c,c.next=e,e.prev=c),c}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let t=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let c=this.actives;for(;c!==null;){if(c.top.y===e)if(c.curX=c.top.x,P.isMaximaEdge(c)){c=this.doMaxima(c);continue}else P.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),P.isHorizontal(c)&&this.pushHorz(c);else t||(c.curX=P.topX(c,e));c=c.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let t=this.getRealOutRec(e.op1.outrec),c=this.getRealOutRec(e.op2.outrec),a=e.op1.next,r=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,a.prev=r,r.next=a,t===c){let s=this.newOutRec();s.pts=a,this.fixOutRecPts(s),t.pts.outrec===s&&(t.pts=e.op1,t.pts.outrec=t),this.usingPolytree?(this.path1InsidePath2(t.pts,s.pts)?([s.pts,t.pts]=[t.pts,s.pts],this.fixOutRecPts(t),this.fixOutRecPts(s),s.owner=t):this.path1InsidePath2(s.pts,t.pts)?s.owner=t:s.owner=t.owner,t.splits===null&&(t.splits=[]),t.splits.push(s.idx)):s.owner=t}else c.pts=null,this.usingPolytree?(this.setOwner(c,t),this.moveSplits(c,t)):c.owner=t}}fixOutRecPts(e){let t=e.pts;do t.outrec=e,t=t.next;while(t!==e.pts)}path1InsidePath2(e,t){let c=v1.IsOn,a=e;do{switch(this.pointInOpPolygon(a.pt,t)){case v1.IsOutside:if(c===v1.IsOutside)return!1;c=v1.IsOutside;break;case v1.IsInside:if(c===v1.IsInside)return!0;c=v1.IsInside;break;default:break}a=a.next}while(a!==e);return h1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(t))}pointInOpPolygon(e,t){if(t===t.next||t.prev===t.next)return v1.IsOutside;let c=t;do{if(t.pt.y!==e.y)break;t=t.next}while(t!==c);if(t.pt.y===e.y)return v1.IsOutside;let a=t.pt.y<e.y,r=a,s=0;for(c=t.next;c!==t;){if(a)for(;c!==t&&c.pt.y<e.y;)c=c.next;else for(;c!==t&&c.pt.y>e.y;)c=c.next;if(c===t)break;if(c.pt.y===e.y){if(c.pt.x===e.x||c.pt.y===c.prev.pt.y&&e.x<c.prev.pt.x!=e.x<c.pt.x)return v1.IsOn;if(c=c.next,c===t)break;continue}if(c.pt.x<=e.x||c.prev.pt.x<=e.x)if(c.prev.pt.x<e.x&&c.pt.x<e.x)s=1-s;else{let i=h1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return v1.IsOn;i<0===a&&(s=1-s)}a=!a,c=c.next}if(a===r)return s===0?v1.IsOutside:v1.IsInside;{let i=h1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return v1.IsOn;i<0===a&&(s=1-s)}return s===0?v1.IsOutside:v1.IsInside}getCleanPath(e){let t=[],c=e;for(;c.next!==e&&(c.pt.x===c.next.pt.x&&c.pt.x===c.prev.pt.x||c.pt.y===c.next.pt.y&&c.pt.y===c.prev.pt.y);)c=c.next;t.push(c.pt);let a=c;for(c=c.next;c!==e;)(c.pt.x!==c.next.pt.x||c.pt.x!==a.pt.x)&&(c.pt.y!==c.next.pt.y||c.pt.y!==a.pt.y)&&(t.push(c.pt),a=c),c=c.next;return t}moveSplits(e,t){if(e.splits!==null){t.splits===null&&(t.splits=[]);for(let c of e.splits)c!==t.idx&&t.splits.push(c);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let t=this.sel;for(;t!==null&&t.jump!==null;){let c=null;for(;t!==null&&t.jump!==null;){let a=t,r=t.jump,s=r,i=r?.jump||null;for(t.jump=i;t!==s&&r!==i;)if(r.curX<t.curX){let o=r.prevInSEL;for(;this.addNewIntersectNode(o,r,e),o!==t;)o=o.prevInSEL;if(o=r,r=this.extractFromSEL(o),s=r,t!==null&&this.insert1Before2InSEL(o,t),t!==a)continue;a=o,a.jump=i,c===null?this.sel=a:c.jump=a}else t=t.nextInSEL;c=a,t=i}t=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(We);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let c=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[c]);)c++;[this.intersectList[c],this.intersectList[e]]=[this.intersectList[e],this.intersectList[c]]}let t=this.intersectList[e];this.intersectEdges(t.edge1,t.edge2,t.pt),this.swapPositionsInAEL(t.edge1,t.edge2),t.edge1.curX=t.pt.x,t.edge2.curX=t.pt.x,this.checkJoinLeft(t.edge2,t.pt,!0),this.checkJoinRight(t.edge1,t.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let t=this.actives;this.sel=t;let c=Number.NEGATIVE_INFINITY,a=!1;for(;t!==null;){t.prevInSEL=t.prevInAEL,t.nextInSEL=t.nextInAEL,t.jump=t.nextInSEL;let r=P.topX(t,e);t.curX=r,r<c&&(a=!0),c=r,t=t.nextInAEL}return a}doMaxima(e){let t=e.prevInAEL,c=e.nextInAEL;if(P.isOpenEnd(e))return P.isHotEdge(e)&&this.addOutPt(e,e.top),P.isHorizontal(e)||(P.isHotEdge(e)&&(P.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let a=P.getMaximaPair(e);if(a===null)return c;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(a)&&this.split(a,a.top);c!==a;)this.intersectEdges(e,c,e.top),this.swapPositionsInAEL(e,c),c=e.nextInAEL;return P.isOpen(e)?(P.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(a),this.deleteFromAEL(e),t!==null?t.nextInAEL:this.actives):(P.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(e),this.deleteFromAEL(a),t!==null?t.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=P.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,P.setDx(e),this.isJoined(e)&&this.split(e,e.bot),P.isHorizontal(e)){P.openPathsEnabled?P.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,t){let c=!1,a=P.nextVertex(e).pt;for(;a.y===e.top.y&&!(t&&a.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=P.nextVertex(e),e.top=a,c=!0,P.isMaximaVertex(e.vertexTop)));)a=P.nextVertex(e).pt;c&&P.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new S3(e))}addNewIntersectNode(e,t,c){let a=h1.getLineIntersectPt(e.bot,e.top,t.bot,t.top);if(a===null&&(a={x:e.curX,y:c}),a.y>this.currentBotY||a.y<c){let s=Math.abs(e.dx),i=Math.abs(t.dx);s>100&&i>100?s>i?a=h1.getClosestPtOnSegment(a,e.bot,e.top):a=h1.getClosestPtOnSegment(a,t.bot,t.top):s>100?a=h1.getClosestPtOnSegment(a,e.bot,e.top):i>100?a=h1.getClosestPtOnSegment(a,t.bot,t.top):(a.y<c?a.y=c:a.y=this.currentBotY,s<i?a.x=P.topX(e,a.y):a.x=P.topX(t,a.y))}let r=d6(a,e,t);this.intersectList.push(r)}extractFromSEL(e){let t=e.nextInSEL;return t!==null&&(t.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=t,t}insert1Before2InSEL(e,t){e.prevInSEL=t.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=t,t.prevInSEL=e}getCurrYMaximaVertexOpen(e){let t=e.vertexTop;if(e.windDx>0)for(;t.next.pt.y===t.pt.y&&(t.flags&(g1.OpenEnd|g1.LocalMax))===g1.None;)t=t.next;else for(;t.prev.pt.y===t.pt.y&&(t.flags&(g1.OpenEnd|g1.LocalMax))===g1.None;)t=t.prev;return P.isMaximaVertex(t)||(t=null),t}getCurrYMaximaVertex(e){let t=e.vertexTop;if(e.windDx>0)for(;t.next.pt.y===t.pt.y;)t=t.next;else for(;t.prev.pt.y===t.pt.y;)t=t.prev;return P.isMaximaVertex(t)||(t=null),t}resetHorzDirection(e,t){if(e.bot.x===e.top.x){let c=e.curX,a=e.curX,r=e.nextInAEL;for(;r!==null&&r.vertexTop!==t;)r=r.nextInAEL;return{isLeftToRight:r!==null,leftX:c,rightX:a}}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 t=e.outrec;return e===t.frontEdge?t.pts:t.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 t=this.actives;for(;t.nextInAEL!==null&&this.isValidAelOrder(t.nextInAEL,e);)t=t.nextInAEL;t.joinWith===n0.Right&&(t=t.nextInAEL),e.nextInAEL=t.nextInAEL,t.nextInAEL!==null&&(t.nextInAEL.prevInAEL=e),e.prevInAEL=t,t.nextInAEL=e}}insertRightEdge(e,t){t.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=t),t.prevInAEL=e,e.nextInAEL=t}setWindCountForOpenPathEdge(e){let t=this.actives;if(this.fillrule===p1.EvenOdd){let c=0,a=0;for(;t!==e;)P.getPolyType(t)===K1.Clip?a++:P.isOpen(t)||c++,t=t.nextInAEL;e.windCount=P.isOdd(c)?1:0,e.windCount2=P.isOdd(a)?1:0}else for(;t!==e;)P.getPolyType(t)===K1.Clip?e.windCount2+=t.windDx:P.isOpen(t)||(e.windCount+=t.windDx),t=t.nextInAEL}setWindCountForClosedPathEdge(e){let t=e.prevInAEL,c=P.getPolyType(e);if(!P.openPathsEnabled){for(;t!==null&&P.getPolyType(t)!==c;)t=t.prevInAEL;if(t===null?(e.windCount=e.windDx,t=this.actives):this.fillrule===p1.EvenOdd?(e.windCount=e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL):(t.windCount*t.windDx<0?Math.abs(t.windCount)>1?t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx:e.windCount=e.windDx:t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL),this.fillrule===p1.EvenOdd)for(;t!==e;)P.getPolyType(t)!==c&&(e.windCount2=e.windCount2===0?1:0),t=t.nextInAEL;else for(;t!==e;)P.getPolyType(t)!==c&&(e.windCount2+=t.windDx),t=t.nextInAEL;return}for(;t!==null&&(P.getPolyType(t)!==c||P.isOpen(t));)t=t.prevInAEL;if(t===null?(e.windCount=e.windDx,t=this.actives):this.fillrule===p1.EvenOdd?(e.windCount=e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL):(t.windCount*t.windDx<0?Math.abs(t.windCount)>1?t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx:e.windCount=P.isOpen(e)?1:e.windDx:t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL),this.fillrule===p1.EvenOdd)for(;t!==e;)P.getPolyType(t)!==c&&!P.isOpen(t)&&(e.windCount2=e.windCount2===0?1:0),t=t.nextInAEL;else for(;t!==e;)P.getPolyType(t)!==c&&!P.isOpen(t)&&(e.windCount2+=t.windDx),t=t.nextInAEL}isContributingOpen(e){let t,c;switch(this.fillrule){case p1.Positive:c=e.windCount>0,t=e.windCount2>0;break;case p1.Negative:c=e.windCount<0,t=e.windCount2<0;break;default:c=e.windCount!==0,t=e.windCount2!==0;break}switch(this.cliptype){case M1.Intersection:return t;case M1.Union:return!c&&!t;default:return!t}}isContributingClosed(e){switch(this.fillrule){case p1.Positive:if(e.windCount!==1)return!1;break;case p1.Negative:if(e.windCount!==-1)return!1;break;case p1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case M1.Intersection:return this.fillrule===p1.Positive?e.windCount2>0:this.fillrule===p1.Negative?e.windCount2<0:e.windCount2!==0;case M1.Union:return this.fillrule===p1.Positive?e.windCount2<=0:this.fillrule===p1.Negative?e.windCount2>=0:e.windCount2===0;case M1.Difference:{let t=this.fillrule===p1.Positive?e.windCount2<=0:this.fillrule===p1.Negative?e.windCount2>=0:e.windCount2===0;return P.getPolyType(e)===K1.Subject?t:!t}case M1.Xor:return!0;default:return!1}}addLocalMinPoly(e,t,c,a=!1){let r=this.newOutRec();if(e.outrec=r,t.outrec=r,P.isOpen(e))r.owner=null,r.isOpen=!0,e.windDx>0?this.setSides(r,e,t):this.setSides(r,t,e);else{r.isOpen=!1;let i=P.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(r,i.outrec),r.owner=i.outrec,this.outrecIsAscending(i)===a?this.setSides(r,t,e):this.setSides(r,e,t)):(r.owner=null,a?this.setSides(r,e,t):this.setSides(r,t,e))}let s=new X0(c,r);return r.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new L3;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,t){let c=this.newOutRec();c.isOpen=!0,e.windDx>0?(c.frontEdge=e,c.backEdge=null):(c.frontEdge=null,c.backEdge=e),e.outrec=c;let a=new X0(t,c);return c.pts=a,a}checkJoinLeft(e,t,c=!1){let a=e.prevInAEL;a!==null&&(!c&&e.curX!==a.curX||!P.isHotEdge(e)||!P.isHotEdge(a)||P.isHorizontal(e)||P.isHorizontal(a)||P.isOpen(e)||P.isOpen(a)||(t.y<e.top.y+2||t.y<a.top.y+2)&&(e.bot.y>t.y||a.bot.y>t.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(t,a.bot,a.top)||h1.isCollinear(e.top,t,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(a,e,t):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),a.joinWith=n0.Right,e.joinWith=n0.Left))}checkJoinRight(e,t,c=!1){let a=e.nextInAEL;a!==null&&(!c&&e.curX!==a.curX||!P.isHotEdge(e)||!P.isHotEdge(a)||P.isHorizontal(e)||P.isHorizontal(a)||P.isOpen(e)||P.isOpen(a)||(t.y<e.top.y+2||t.y<a.top.y+2)&&(e.bot.y>t.y||a.bot.y>t.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(t,a.bot,a.top)||h1.isCollinear(e.top,t,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(e,a,t):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),e.joinWith=n0.Right,a.joinWith=n0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,t,c){let a=e.x-t.x,r=e.y-t.y,s=c.x-t.x,i=c.y-t.y;if(s===0&&i===0)return!1;let o=h1.maxCoordForSafeCrossSq;if(Math.abs(a)<o&&Math.abs(r)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=a*i-s*r;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(a)&&Number.isSafeInteger(r)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(a)*BigInt(i)-BigInt(s)*BigInt(r),f=h*h,u=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return f6*f>u}let l=a*i-s*r;return l*l/(s*s+i*i)>.25}intersectEdges(e,t,c){let a;if(this.hasOpenPaths&&(P.isOpen(e)||P.isOpen(t))){if(P.isOpen(e)&&P.isOpen(t))return;if(P.isOpen(t)){let l=e;e=t,t=l}if(this.isJoined(t)&&this.split(t,c),this.cliptype===M1.Union){if(!P.isHotEdge(t))return}else if(t.localMin.polytype===K1.Subject)return;switch(this.fillrule){case p1.Positive:if(t.windCount!==1)return;break;case p1.Negative:if(t.windCount!==-1)return;break;default:if(Math.abs(t.windCount)!==1)return;break}if(P.isHotEdge(e))a=this.addOutPt(e,c),this.setZ(e,t,a.pt),P.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(c.x===e.localMin.vertex.pt.x&&c.y===e.localMin.vertex.pt.y&&!P.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&P.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}a=this.startOpenPath(e,c)}else a=this.startOpenPath(e,c);this.setZ(e,t,a.pt);return}this.isJoined(e)&&this.split(e,c),this.isJoined(t)&&this.split(t,c);let r,s;switch(e.localMin.polytype===t.localMin.polytype?this.fillrule===p1.EvenOdd?(r=e.windCount,e.windCount=t.windCount,t.windCount=r):(e.windCount+t.windDx===0?e.windCount=-e.windCount:e.windCount+=t.windDx,t.windCount-e.windDx===0?t.windCount=-t.windCount:t.windCount-=e.windDx):(this.fillrule!==p1.EvenOdd?e.windCount2+=t.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==p1.EvenOdd?t.windCount2-=e.windDx:t.windCount2=t.windCount2===0?1:0),this.fillrule){case p1.Positive:r=e.windCount,s=t.windCount;break;case p1.Negative:r=-e.windCount,s=-t.windCount;break;default:r=Math.abs(e.windCount),s=Math.abs(t.windCount);break}let i=r===0||r===1,o=s===0||s===1;if(!(!P.isHotEdge(e)&&!i||!P.isHotEdge(t)&&!o))if(P.isHotEdge(e)&&P.isHotEdge(t))if(r!==0&&r!==1||s!==0&&s!==1||e.localMin.polytype!==t.localMin.polytype&&this.cliptype!==M1.Xor)a=this.addLocalMaxPoly(e,t,c),a&&this.setZ(e,t,a.pt);else if(P.isFront(e)||e.outrec===t.outrec){a=this.addLocalMaxPoly(e,t,c),a&&this.setZ(e,t,a.pt);let l=this.addLocalMinPoly(e,t,c);this.setZ(e,t,l.pt)}else{a=this.addOutPt(e,c),this.setZ(e,t,a.pt);let l=this.addOutPt(t,c);this.setZ(e,t,l.pt),this.swapOutrecs(e,t)}else if(P.isHotEdge(e))a=this.addOutPt(e,c),this.setZ(e,t,a.pt),this.swapOutrecs(e,t);else if(P.isHotEdge(t))a=this.addOutPt(t,c),this.setZ(e,t,a.pt),this.swapOutrecs(e,t);else{let l,h;switch(this.fillrule){case p1.Positive:l=e.windCount2,h=t.windCount2;break;case p1.Negative:l=-e.windCount2,h=-t.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(t.windCount2);break}if(!P.isSamePolyType(e,t))a=this.addLocalMinPoly(e,t,c),this.setZ(e,t,a.pt);else if(r===1&&s===1){switch(a=null,this.cliptype){case M1.Union:if(l>0&&h>0)return;a=this.addLocalMinPoly(e,t,c);break;case M1.Difference:(P.getPolyType(e)===K1.Clip&&l>0&&h>0||P.getPolyType(e)===K1.Subject&&l<=0&&h<=0)&&(a=this.addLocalMinPoly(e,t,c));break;case M1.Xor:a=this.addLocalMinPoly(e,t,c);break;default:if(l<=0||h<=0)return;a=this.addLocalMinPoly(e,t,c);break}a&&this.setZ(e,t,a.pt)}}}swapPositionsInAEL(e,t){let c=t.nextInAEL;c!==null&&(c.prevInAEL=e);let a=e.prevInAEL;a!==null&&(a.nextInAEL=t),t.prevInAEL=a,t.nextInAEL=e,e.prevInAEL=t,e.nextInAEL=c,t.prevInAEL===null&&(this.actives=t)}isValidAelOrder(e,t){if(t.curX!==e.curX)return t.curX>e.curX;let c=h1.crossProductSign(e.top,t.bot,t.top);if(c!==0)return c<0;if(!P.isMaximaEdge(e)&&e.top.y>t.top.y)return h1.crossProductSign(t.bot,e.top,P.nextVertex(e).pt)<=0;if(!P.isMaximaEdge(t)&&t.top.y>e.top.y)return h1.crossProductSign(t.bot,t.top,P.nextVertex(t).pt)>=0;let a=t.bot.y,r=t.isLeftBound;return e.bot.y!==a||e.localMin.vertex.pt.y!==a?t.isLeftBound:e.isLeftBound!==r?r:h1.isCollinear(P.prevPrevVertex(e).pt,e.bot,e.top)?!0:h1.crossProductSign(P.prevPrevVertex(e).pt,t.bot,P.prevPrevVertex(t).pt)>0===r}isJoined(e){return e.joinWith!==n0.None}split(e,t){e.joinWith===n0.Right?(e.joinWith=n0.None,e.nextInAEL.joinWith=n0.None,this.addLocalMinPoly(e,e.nextInAEL,t,!0)):(e.joinWith=n0.None,e.prevInAEL.joinWith=n0.None,this.addLocalMinPoly(e.prevInAEL,e,t,!0))}setSides(e,t,c){e.frontEdge=t,e.backEdge=c}findEdgeWithMatchingLocMin(e){let t=e.nextInAEL;for(;t!==null;){if(t.localMin?.equals(e.localMin))return t;!P.isHorizontal(t)&&!(e.bot.x===t.bot.x&&e.bot.y===t.bot.y)?t=null:t=t.nextInAEL}for(t=e.prevInAEL;t!==null;){if(t.localMin?.equals(e.localMin))return t;if(!P.isHorizontal(t)&&!(e.bot.x===t.bot.x&&e.bot.y===t.bot.y))return null;t=t.prevInAEL}return t}addOutPt(e,t){let c=e.outrec,a=P.isFront(e),r=c.pts,s=r.next;if(a&&t.x===r.pt.x&&t.y===r.pt.y)return r;if(!a&&t.x===s.pt.x&&t.y===s.pt.y)return s;let i=new X0(t,c);return s.prev=i,i.prev=r,i.next=s,r.next=i,a&&(c.pts=i),i}addLocalMaxPoly(e,t,c){if(this.isJoined(e)&&this.split(e,c),this.isJoined(t)&&this.split(t,c),P.isFront(e)===P.isFront(t))if(P.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(P.isOpenEnd(t))this.swapFrontBackSides(t.outrec);else return this.succeeded=!1,null;let a=this.addOutPt(e,c);if(e.outrec===t.outrec){let r=e.outrec;if(r.pts=a,this.usingPolytree){let s=P.getPrevHotEdge(e);s===null?r.owner=null:this.setOwner(r,s.outrec)}this.uncoupleOutRec(e)}else P.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,t):this.joinOutrecPaths(t,e):e.outrec.idx<t.outrec.idx?this.joinOutrecPaths(e,t):this.joinOutrecPaths(t,e);return a}swapFrontBackSides(e){let t=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=t,e.pts=e.pts.next}setOwner(e,t){for(;t.owner!==null&&t.owner.pts===null;)t.owner=t.owner.owner;let c=t;for(;c!==null&&c!==e;)c=c.owner;c!==null&&(t.owner=e.owner),e.owner=t}uncoupleOutRec(e){let t=e.outrec;t!==null&&(t.frontEdge.outrec=null,t.backEdge.outrec=null,t.frontEdge=null,t.backEdge=null)}joinOutrecPaths(e,t){let c=e.outrec.pts,a=t.outrec.pts,r=c.next,s=a.next;P.isFront(e)?(s.prev=c,c.next=s,a.next=r,r.prev=a,e.outrec.pts=a,e.outrec.frontEdge=t.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(r.prev=a,a.next=r,c.next=s,s.prev=c,e.outrec.backEdge=t.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),t.outrec.frontEdge=null,t.outrec.backEdge=null,t.outrec.pts=null,this.setOwner(t.outrec,e.outrec),P.isOpenEnd(e)&&(t.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,t.outrec=null}swapOutrecs(e,t){let c=e.outrec,a=t.outrec;if(c===a){let r=c.frontEdge;c.frontEdge=c.backEdge,c.backEdge=r;return}c!==null&&(e===c.frontEdge?c.frontEdge=t:c.backEdge=t),a!==null&&(t===a.frontEdge?a.frontEdge=e:a.backEdge=e),e.outrec=a,t.outrec=c}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,t){return Math.abs(e.x-t.x)<2&&Math.abs(e.y-t.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(P.ptsReallyClose(e.prev.pt,e.next.pt)||P.ptsReallyClose(e.pt,e.next.pt)||P.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,t,c,a){if(e===null||e.next===e||!c&&e.next===e.prev)return!1;a.length=0;let r,s;for(t?(r=e.pt,s=e.prev):(e=e.next,r=e.pt,s=e.next),a.push(r);s!==e;)s.pt.x===r.x&&s.pt.y===r.y||(r=s.pt,a.push(r)),t?s=s.prev:s=s.next;return a.length!==3||c||!P.isVerySmallTriangle(s)}buildPaths(e,t){e.length=0,t.length=0;let c=0;for(;c<this.outrecList.length;){let a=this.outrecList[c++];if(a.pts===null)continue;let r=[];a.isOpen?P.buildPath(a.pts,this.reverseSolution,!0,r)&&t.push(r):(this.cleanCollinear(a),P.buildPath(a.pts,this.reverseSolution,!1,r)&&e.push(r))}return!0}buildTree(e,t){e.clear(),t.length=0;let c=0;for(;c<this.outrecList.length;){let a=this.outrecList[c++];if(a.pts!==null){if(a.isOpen){let r=[];P.buildPath(a.pts,this.reverseSolution,!0,r)&&t.push(r);continue}this.checkBounds(a)&&this.recursiveCheckOwners(a,e)}}}checkBounds(e){return e.pts===null?!1:d2.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!P.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=h1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,t){if(!(e.polypath!==null||d2.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,t),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=t.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 t=e.pts,c=t;for(;;){if(c!==null&&h1.isCollinear(c.prev.pt,c.pt,c.next.pt)&&(c.pt.x===c.prev.pt.x&&c.pt.y===c.prev.pt.y||c.pt.x===c.next.pt.x&&c.pt.y===c.next.pt.y||!this.preserveCollinear||h1.dotProductSign(c.prev.pt,c.pt,c.next.pt)<0)){if(c===e.pts&&(e.pts=c.prev),c=this.disposeOutPt(c),!this.isValidClosedPath(c)){e.pts=null;return}t=c;continue}if(c===null||(c=c.next,c===t))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!P.isVerySmallTriangle(e))}disposeOutPt(e){let t=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,t}fixSelfIntersects(e){let t=e.pts;if(t.prev!==t.next.next)for(;;){if(t.next&&t.next.next&&this.boundingBoxesOverlap(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)&&h1.segsIntersect(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)){if((t===e.pts||t.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,t),e.pts===null)return;if(t=e.pts,t.prev===t.next.next)break;continue}if(t=t.next,t===e.pts)break}}doSplitOp(e,t){let c=t.prev,a=t.next.next;e.pts=c;let r=h1.getLineIntersectPt(c.pt,t.pt,t.next.pt,a.pt);this.zCallbackInternal&&this.zCallbackInternal(c.pt,t.pt,t.next.pt,a.pt,r);let s=P.areaOutPt(c),i=s<W2?-s:s;if(i<f6){e.pts=null;return}let o=this.areaTriangle(r,t.pt,t.next.pt),l=o<W2?-o:o;if(r.x===c.pt.x&&r.y===c.pt.y||r.x===a.pt.x&&r.y===a.pt.y)a.prev=c,c.next=a;else{let u=new X0(r,e);u.prev=c,u.next=a,a.prev=u,c.next=u}if(!(l>Ge)||!(l>i)&&o>W2!=s>W2)return;let h=this.newOutRec();h.owner=e.owner,t.outrec=h,t.next.outrec=h;let f=new X0(r,h);f.prev=t.next,f.next=t,h.pts=f,t.prev=f,t.next.next=f,this.usingPolytree&&(this.path1InsidePath2(c,f)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let t=h1.maxCoordForSafeAreaProduct,c=0,a=!0,r=e;do{let i=r.prev,o=r.pt;if(Math.abs(i.pt.x)>=t||Math.abs(i.pt.y)>=t||Math.abs(o.x)>=t||Math.abs(o.y)>=t){a=!1;break}c+=(i.pt.y+o.y)*(i.pt.x-o.x),r=r.next}while(r!==e);if(a)return BigInt(Math.round(c));let s=W2;r=e;do{let i=r.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(r.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(r.pt.x)){let o=BigInt(i.pt.y)+BigInt(r.pt.y),l=BigInt(i.pt.x)-BigInt(r.pt.x);s+=o*l}else{let o=i.pt.y+r.pt.y,l=i.pt.x-r.pt.x;s+=BigInt(Math.round(o*l))}r=r.next}while(r!==e);return s}areaTriangle(e,t,c){let a=h1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<a&&Math.abs(e.y)<a&&Math.abs(t.x)<a&&Math.abs(t.y)<a&&Math.abs(c.x)<a&&Math.abs(c.y)<a){let s=(c.y+e.y)*(c.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+c.y)*(t.x-c.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(c.y)){let s=(BigInt(c.y)+BigInt(e.y))*(BigInt(c.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(t.y))*(BigInt(e.x)-BigInt(t.x)),o=(BigInt(t.y)+BigInt(c.y))*(BigInt(t.x)-BigInt(c.x));return s+i+o}let r=(c.y+e.y)*(c.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+c.y)*(t.x-c.x);return BigInt(Math.round(r))}isValidOwner(e,t){for(;t!==null&&t!==e;)t=t.owner;return t===null}containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom}checkSplitOwner(e,t){for(let c=0;c<t.length;c++){let a=this.outrecList[t[c]];if(a.pts===null&&a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(a=this.getRealOutRec(a),!(a===null||a===e||a.recursiveSplit===e)){if(a.recursiveSplit=e,a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(!(!this.checkBounds(a)||!this.containsRect(a.bounds,e.bounds)||!this.path1InsidePath2(e.pts,a.pts)))return this.isValidOwner(e,a)||(a.owner=e.owner),e.owner=a,!0}}return!1}};F(P,"openPathsEnabled",!0);var P3=P,D0=class extends P3{constructor(){super(...arguments);F(this,"zCallback")}getZCallback(){return this.zCallback}addPath(t,c,a=!1){super.addPath(t,c,a)}addReuseableData(t){super.addReuseableData(t)}addPaths(t,c,a=!1){super.addPaths(t,c,a)}addSubject(t){this.addPaths(t,K1.Subject)}addOpenSubject(t){this.addPaths(t,K1.Subject,!0)}addClip(t){this.addPaths(t,K1.Clip)}execute(t,c,a,r){if(Array.isArray(a)){let s=a,i=r;s.length=0,i&&(i.length=0);try{this.executeInternal(t,c),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=a,i=r;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(t,c),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var I5={area(n){return h1.area(n)},areaD(n){let e=0,t=n.length;if(t<3)return 0;let c=n[t-1];for(let a of n)e+=(c.y+a.y)*(c.x-a.x),c=a;return e*.5},scalePath64(n,e){let t=h1.maxSafeCoordinateForScale(e),c=[];for(let a of n)h1.checkSafeScaleValue(a.x,t,"scalePath64"),h1.checkSafeScaleValue(a.y,t,"scalePath64"),c.push({x:Math.round(a.x*e),y:Math.round(a.y*e)});return c},scalePaths64(n,e){let t=[];for(let c of n)t.push(I5.scalePath64(c,e));return t},scalePathD(n,e){let t=[];for(let c of n)t.push({x:c.x*e,y:c.y*e});return t},scalePathsD(n,e){let t=[];for(let c of n)t.push(I5.scalePathD(c,e));return t}};var c0;(function(n){n[n.Miter=0]="Miter",n[n.Square=1]="Square",n[n.Bevel=2]="Bevel",n[n.Round=3]="Round"})(c0||(c0={}));var S1;(function(n){n[n.Polygon=0]="Polygon",n[n.Joined=1]="Joined",n[n.Butt=2]="Butt",n[n.Square=3]="Square",n[n.Round=4]="Round"})(S1||(S1={}));var H5=class{constructor(e,t,c=S1.Polygon){F(this,"inPaths");F(this,"joinType");F(this,"endType");F(this,"pathsReversed");F(this,"lowestPathIdx");this.joinType=t,this.endType=c;let a=c===S1.Polygon||c===S1.Joined;this.inPaths=[];for(let r of e)this.inPaths.push(p2.stripDuplicates(r,a));if(c===S1.Polygon){let r=p2.getLowestPathInfo(this.inPaths);this.lowestPathIdx=r.idx,this.pathsReversed=this.lowestPathIdx>=0&&r.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},L1=class L1{constructor(e=2,t=0,c=!1,a=!1){F(this,"groupList",[]);F(this,"pathOut",[]);F(this,"normals",[]);F(this,"solution",[]);F(this,"solutionTree",null);F(this,"groupDelta",0);F(this,"delta",0);F(this,"mitLimSqr",0);F(this,"stepsPerRad",0);F(this,"stepSin",0);F(this,"stepCos",0);F(this,"joinType",c0.Bevel);F(this,"endType",S1.Polygon);F(this,"arcTolerance",0);F(this,"mergeGroups",!0);F(this,"miterLimit",2);F(this,"preserveCollinear",!1);F(this,"reverseSolution",!1);F(this,"zCallback");F(this,"deltaCallback",null);F(this,"ZCB",(e,t,c,a,r)=>{(e.z||0)!==0&&(e.z===c.z||e.z===a.z)?r.z=e.z:(c.z||0)!==0&&c.z===t.z?r.z=c.z:(t.z||0)!==0&&t.z===a.z?r.z=t.z:this.zCallback&&this.zCallback(e,t,c,a,r)});this.miterLimit=e,this.arcTolerance=t,this.mergeGroups=!0,this.preserveCollinear=c,this.reverseSolution=a}clear(){this.groupList.length=0}addPath(e,t,c){if(e.length===0)return;let a=[e];this.addPaths(a,t,c)}addPaths(e,t,c){e.length!==0&&this.groupList.push(new H5(e,t,c))}calcSolutionCapacity(){let e=0;for(let t of this.groupList)e+=t.endType===S1.Joined?t.inPaths.length*2:t.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let t of this.groupList)if(t.endType===S1.Polygon){e=t.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let r of this.groupList)for(let s of r.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/L1.sqr(this.miterLimit);for(let r of this.groupList)this.doGroupOffset(r);if(this.groupList.length===0)return;let t=this.checkPathsReversed(),c=t?p1.Negative:p1.Positive,a=new D0;a.preserveCollinear=this.preserveCollinear,a.reverseSolution=this.reverseSolution!==t,a.zCallback=this.ZCB,a.addSubject(this.solution),this.solutionTree!==null?a.execute(M1.Union,c,this.solutionTree):a.execute(M1.Union,c,this.solution)}execute(e,t){if(Array.isArray(t)){let c=t;c.length=0,this.solution=c,this.executeInternal(e)}else{let c=t;c.clear(),this.solutionTree=c,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,t){this.deltaCallback=e,this.execute(1,t)}static getUnitNormal(e,t){let c=t.x-e.x,a=t.y-e.y;if(c===0&&a===0)return{x:0,y:0};let r=1/Math.sqrt(c*c+a*a);return{x:a*r,y:-c*r}}static getLowestPathInfo(e){let t=-1,c=!1,a={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let r=0;r<e.length;++r){let s=Number.MAX_VALUE;for(let i of e[r])if(!(i.y<a.y||i.y===a.y&&i.x>=a.x)){if(s===Number.MAX_VALUE){if(s=L1.area(e[r]),s===0)break;c=s<0}t=r,a.x=i.x,a.y=i.y}}return{idx:t,isNegArea:c}}static translatePoint(e,t,c){return{x:e.x+t,y:e.y+c,z:e.z}}static reflectPoint(e,t){return{x:t.x+(t.x-e.x),y:t.y+(t.y-e.y),z:e.z}}static almostZero(e,t=.001){return Math.abs(e)<t}static hypotenuse(e,t){return Math.sqrt(e*e+t*t)}static normalizeVector(e){let t=L1.hypotenuse(e.x,e.y);if(L1.almostZero(t))return{x:0,y:0};let c=1/t;return{x:e.x*c,y:e.y*c}}static getAvgUnitVector(e,t){return L1.normalizeVector({x:e.x+t.x,y:e.y+t.y})}static intersectPoint(e,t,c,a){if(h1.isAlmostZero(e.x-t.x)){if(h1.isAlmostZero(c.x-a.x))return{x:0,y:0};let r=(a.y-c.y)/(a.x-c.x),s=c.y-r*c.x;return{x:e.x,y:r*e.x+s}}if(h1.isAlmostZero(c.x-a.x)){let r=(t.y-e.y)/(t.x-e.x),s=e.y-r*e.x;return{x:c.x,y:r*c.x+s}}else{let r=(t.y-e.y)/(t.x-e.x),s=e.y-r*e.x,i=(a.y-c.y)/(a.x-c.x),o=c.y-i*c.x;if(h1.isAlmostZero(r-i))return{x:0,y:0};let l=(o-s)/(r-i);return{x:l,y:r*l+s}}}getPerpendic(e,t){return{x:Math.round(e.x+t.x*this.groupDelta),y:Math.round(e.y+t.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,t){return{x:e.x+t.x*this.groupDelta,y:e.y+t.y*this.groupDelta,z:e.z||0}}doBevel(e,t,c){let a,r,s=e[t].z||0;if(t===c){let i=Math.abs(this.groupDelta);a={x:Math.round(e[t].x-i*this.normals[t].x),y:Math.round(e[t].y-i*this.normals[t].y),z:s},r={x:Math.round(e[t].x+i*this.normals[t].x),y:Math.round(e[t].y+i*this.normals[t].y),z:s}}else a={x:Math.round(e[t].x+this.groupDelta*this.normals[c].x),y:Math.round(e[t].y+this.groupDelta*this.normals[c].y),z:s},r={x:Math.round(e[t].x+this.groupDelta*this.normals[t].x),y:Math.round(e[t].y+this.groupDelta*this.normals[t].y),z:s};this.pathOut.push(a),this.pathOut.push(r)}doSquare(e,t,c){let a;t===c?a={x:this.normals[t].y,y:-this.normals[t].x}:a=L1.getAvgUnitVector({x:-this.normals[c].y,y:this.normals[c].x},{x:this.normals[t].y,y:-this.normals[t].x});let r=Math.abs(this.groupDelta),s={x:e[t].x,y:e[t].y,z:e[t].z||0};s=L1.translatePoint(s,r*a.x,r*a.y);let i=L1.translatePoint(s,this.groupDelta*a.y,this.groupDelta*-a.x),o=L1.translatePoint(s,this.groupDelta*-a.y,this.groupDelta*a.x),l=this.getPerpendicD(e[c],this.normals[c]);if(t===c){let h={x:l.x+a.x*this.groupDelta,y:l.y+a.y*this.groupDelta},f=L1.intersectPoint(i,o,l,h);f.z=s.z,this.pathOut.push(F0.fromPointD(L1.reflectPoint(f,s))),this.pathOut.push(F0.fromPointD(f))}else{let h=this.getPerpendicD(e[t],this.normals[c]),f=L1.intersectPoint(i,o,l,h);f.z=s.z,this.pathOut.push(F0.fromPointD(f)),this.pathOut.push(F0.fromPointD(L1.reflectPoint(f,s)))}}doMiter(e,t,c,a){let r=this.groupDelta/(a+1);this.pathOut.push({x:Math.round(e[t].x+(this.normals[c].x+this.normals[t].x)*r),y:Math.round(e[t].y+(this.normals[c].y+this.normals[t].y)*r),z:e[t].z||0})}doRound(e,t,c,a){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*L1.arc_const,f=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/f),this.stepCos=Math.cos(2*Math.PI/f),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=f/(2*Math.PI)}let r=e[t],s=r.z||0,i={x:this.normals[c].x*this.groupDelta,y:this.normals[c].y*this.groupDelta};t===c&&k3.negate(i),this.pathOut.push({x:Math.round(r.x+i.x),y:Math.round(r.y+i.y),z:s});let o=Math.ceil(this.stepsPerRad*Math.abs(a));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(r.x+i.x),y:Math.round(r.y+i.y),z:s});this.pathOut.push(this.getPerpendic(e[t],this.normals[t]))}buildNormals(e){let t=e.length;if(this.normals.length=0,t!==0){for(let c=0;c<t-1;c++)this.normals.push(L1.getUnitNormal(e[c],e[c+1]));this.normals.push(L1.getUnitNormal(e[t-1],e[0]))}}offsetPoint(e,t,c,a){if(F0.equals(t[c],t[a]))return;let r=h1.crossProductD(this.normals[c],this.normals[a]),s=h1.dotProductD(this.normals[c],this.normals[a]);if(r>1?r=1:r<-1&&(r=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(t,this.normals,c,a),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<L1.Tolerance){this.pathOut.push(t[c]);return}if(s>-.999&&r*this.groupDelta<0)this.pathOut.push(this.getPerpendic(t[c],this.normals[a])),this.pathOut.push(t[c]),this.pathOut.push(this.getPerpendic(t[c],this.normals[c]));else if(s>.999&&this.joinType!==c0.Round)this.doMiter(t,c,a,s);else switch(this.joinType){case c0.Miter:s>this.mitLimSqr-1?this.doMiter(t,c,a,s):this.doSquare(t,c,a);break;case c0.Round:this.doRound(t,c,a,Math.atan2(r,s));break;case c0.Bevel:this.doBevel(t,c,a);break;default:this.doSquare(t,c,a);break}}offsetPolygon(e,t){this.pathOut=[];let c=t.length,a=c-1;for(let r=0;r<c;r++)this.offsetPoint(e,t,r,a),a=r;this.solution.push(this.pathOut)}offsetOpenJoined(e,t){this.offsetPolygon(e,t);let c=[...t].reverse();this.buildNormals(c),this.offsetPolygon(e,c)}offsetOpenPath(e,t){this.pathOut=[];let c=t.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(t,this.normals,0,0)),Math.abs(this.groupDelta)<L1.Tolerance)this.pathOut.push(t[0]);else switch(this.endType){case S1.Butt:this.doBevel(t,0,0);break;case S1.Round:this.doRound(t,0,0,Math.PI);break;default:this.doSquare(t,0,0);break}for(let a=1,r=0;a<c;a++)this.offsetPoint(e,t,a,r),r=a;for(let a=c;a>0;a--)this.normals[a]={x:-this.normals[a-1].x,y:-this.normals[a-1].y};if(this.normals[0]=this.normals[c],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(t,this.normals,c,c)),Math.abs(this.groupDelta)<L1.Tolerance)this.pathOut.push(t[c]);else switch(this.endType){case S1.Butt:this.doBevel(t,c,c);break;case S1.Round:this.doRound(t,c,c,Math.PI);break;default:this.doSquare(t,c,c);break}for(let a=c-1,r=c;a>0;a--)this.offsetPoint(e,t,a,r),r=a;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===S1.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 t=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===c0.Round||e.endType===S1.Round){let c=this.arcTolerance>.01?this.arcTolerance:t*L1.arc_const,a=Math.PI/Math.acos(1-c/t);this.stepSin=Math.sin(2*Math.PI/a),this.stepCos=Math.cos(2*Math.PI/a),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=a/(2*Math.PI)}for(let c of e.inPaths){this.pathOut=[];let a=c.length;if(a===1){let r=c[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(c,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=r.z||0;if(e.endType===S1.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=L1.ellipse(r,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:r.x-i,top:r.y-i,right:r.x+i,bottom:r.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(a===2&&e.endType===S1.Joined&&(this.endType=e.joinType===c0.Round?S1.Round:S1.Square),this.buildNormals(c),this.endType){case S1.Polygon:this.offsetPolygon(e,c);break;case S1.Joined:this.offsetOpenJoined(e,c);break;default:this.offsetOpenPath(e,c);break}}}static stripDuplicates(e,t){let c=e.length,a=[];if(c===0)return a;let r=e[0];a.push(r);for(let s=1;s<c;s++)F0.equals(r,e[s])||(r=e[s],a.push(r));return t&&F0.equals(r,a[0])&&a.pop(),a}static area(e){return h1.area(e)}static sqr(e){return e*e}static ellipse(e,t,c=0,a=0){if(t<=0)return[];c<=0&&(c=t),a<=2&&(a=Math.ceil(Math.PI*Math.sqrt((t+c)/2)));let r=Math.sin(2*Math.PI/a),s=Math.cos(2*Math.PI/a),i=s,o=r,l=[{x:Math.round(e.x+t),y:e.y}];for(let h=1;h<a;++h){l.push({x:Math.round(e.x+t*i),y:Math.round(e.y+c*o)});let f=i*s-o*r;o=o*s+i*r,i=f}return l}};F(L1,"Tolerance",1e-12),F(L1,"arc_const",.002);var p2=L1;var Ar=BigInt(2);function O5(n,e,t){return typeof e=="number"?V5(M1.Union,n,null,e):V5(M1.Union,n,e,t)}function V5(n,e,t,c){let a=[];if(e===null)return a;let r=new D0;return r.addPaths(e,K1.Subject),t!==null&&r.addPaths(t,K1.Clip),r.execute(n,c,a),a}function E3(n,e,t,c,a=2,r=0){let s=new p2(a,r);s.addPaths(n,t,c);let i=[];return s.execute(e,i),i}var C0=1e4;function W1(){return{layers:new Map,parts:[]}}function N1(n,e="cut"){return{layers:new Map([[e,{regions:n,lines:[]}]]),parts:[]}}function R0(n,e="cut"){return{layers:new Map([[e,{regions:[],lines:n}]]),parts:[]}}function g6(n){if(n.parts.length)return!1;for(let e of n.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var y6=n=>n.map(e=>e.map(([t,c])=>({x:Math.round(t*C0),y:Math.round(c*C0)})));function Ye(n){let e=(c,a,r)=>(a.x-c.x)*(r.y-a.y)-(a.y-c.y)*(r.x-a.x)===0,t=[];for(let c of n){for(;t.length>=2&&e(t[t.length-2],t[t.length-1],c);)t.pop();let a=t[t.length-1];(!a||a.x!==c.x||a.y!==c.y)&&t.push(c)}for(let c=!0;c&&t.length>=3;){let a=t.length;c=!0,t[a-1].x===t[0].x&&t[a-1].y===t[0].y||e(t[a-2],t[a-1],t[0])?t.pop():e(t[a-1],t[0],t[1])?t.shift():c=!1}return t}var Q2=n=>y6(n).map(Ye),e3=n=>n.filter(e=>e.length>=2).map(e=>e.map(t=>[t.x/C0,t.y/C0]));function Z(n,e="nonzero"){if(!n.length)return[];let t=e==="evenodd"?p1.EvenOdd:p1.NonZero;return e3(O5(Q2(n),t)).filter(c=>c.length>=3)}function F5(n,e,t){if(!e.length)return[];let c=new D0;c.addSubject(Q2(e)),t.length&&c.addClip(Q2(t));let a=[];return c.execute(n,p1.NonZero,a),e3(a).filter(r=>r.length>=3)}var l0=(n,e)=>e.length?F5(M1.Difference,n,e):Z(n),P1=(n,e)=>F5(M1.Intersection,n,e),D5=(n,e)=>F5(M1.Xor,n,e);function h0(n,e,t){if(!n.length)return[];if(!e.length)return t==="outside"?n:[];let c=[];for(let p of e)for(let v=0;v<p.length;v++){let g=p[v],M=p[(v+1)%p.length];(g[0]!==M[0]||g[1]!==M[1])&&c.push([g,M])}if(!c.length)return t==="outside"?n:[];let a=m0(e),r=Math.max(a[2]-a[0],a[3]-a[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=p=>Math.floor(p/r),i=new Map,o=new Map,l=(p,v,g)=>{let M=p.get(v);M?M[M.length-1]!==g&&M.push(g):p.set(v,[g])};c.forEach(([p,v],g)=>{let M=Math.max(1,Math.ceil(Math.hypot(v[0]-p[0],v[1]-p[1])/r*2));for(let y=0;y<=M;y++){let b=p[0]+(v[0]-p[0])*y/M,w=p[1]+(v[1]-p[1])*y/M;for(let x of[-1,0,1])for(let z of[-1,0,1])l(i,`${s(b)+x},${s(w)+z}`,g)}for(let y=s(Math.min(p[1],v[1]));y<=s(Math.max(p[1],v[1]));y++)l(o,y,g)});let h=(p,v)=>{let g=new Set,M=0,y=1;for(let z of[0,1]){let L=v[z]-p[z],S=a[z]-r,k=a[z+2]+r;if(L===0){if(p[z]<S||p[z]>k)return g;continue}let E=(S-p[z])/L,V=(k-p[z])/L;M=Math.max(M,Math.min(E,V)),y=Math.min(y,Math.max(E,V))}if(!(M<=y))return g;let b=[p[0]+(v[0]-p[0])*M,p[1]+(v[1]-p[1])*M],w=[p[0]+(v[0]-p[0])*y,p[1]+(v[1]-p[1])*y],x=Math.max(1,Math.ceil(Math.hypot(w[0]-b[0],w[1]-b[1])/r*2));for(let z=0;z<=x;z++){let L=b[0]+(w[0]-b[0])*z/x,S=b[1]+(w[1]-b[1])*z/x;for(let k of i.get(`${s(L)},${s(S)}`)??[])g.add(k)}return g},f=.5/C0,u=p=>{for(let g of i.get(`${s(p[0])},${s(p[1])}`)??[]){let[M,y]=c[g],b=y[0]-M[0],w=y[1]-M[1],x=Math.max(0,Math.min(1,((p[0]-M[0])*b+(p[1]-M[1])*w)/(b*b+w*w)));if(Math.hypot(p[0]-M[0]-x*b,p[1]-M[1]-x*w)<=f)return}let v=0;for(let g of o.get(s(p[1]))??[]){let[M,y]=c[g],b=(y[0]-M[0])*(p[1]-M[1])-(p[0]-M[0])*(y[1]-M[1]);M[1]<=p[1]?y[1]>p[1]&&b>0&&v++:y[1]<=p[1]&&b<0&&v--}return v!==0},d=p=>Math.round(p*C0)/C0,m=[];for(let p of n){let v=null,g=()=>{v&&v.length>=2&&m.push(v),v=null};for(let M=1;M<p.length;M++){let y=p[M-1],b=p[M],w=b[0]-y[0],x=b[1]-y[1];if(!w&&!x)continue;let z=[0,1];for(let S of h(y,b)){let[k,E]=c[S],V=E[0]-k[0],T=E[1]-k[1],H=w*T-x*V;if(Math.abs(H)>1e-15){let D=((k[0]-y[0])*T-(k[1]-y[1])*V)/H,O=((k[0]-y[0])*x-(k[1]-y[1])*w)/H;D>0&&D<1&&O>=0&&O<=1&&z.push(D)}else{let D=w*w+x*x;for(let O of[k,E]){let R=((O[0]-y[0])*w+(O[1]-y[1])*x)/D,N=Math.abs((O[0]-y[0])*x-(O[1]-y[1])*w)/Math.sqrt(D);R>0&&R<1&&N<=f&&z.push(R)}}}z.sort((S,k)=>S-k);let L=Math.hypot(w,x);for(let S=1;S<z.length;S++){if((z[S]-z[S-1])*L<1e-9||z[S]-z[S-1]<1e-300)continue;let k=[d(y[0]+w*z[S-1]),d(y[1]+x*z[S-1])],E=[d(y[0]+w*z[S]),d(y[1]+x*z[S])],V=(z[S-1]+z[S])/2,T=u([y[0]+w*V,y[1]+x*V]);if(T!==void 0&&T===(t==="inside")){let H=v?v[v.length-1]:void 0;v&&H&&H[0]===k[0]&&H[1]===k[1]?(E[0]!==H[0]||E[1]!==H[1])&&v.push(E):(g(),v=[k,E])}else g()}}g()}return m}function A1(n,e,t="round",c=.01){if(!n.length)return[];if(e===0)return Z(n);let a=t==="round"?c0.Round:t==="square"?c0.Square:c0.Miter,r=E3(Q2(Z(n)),e*C0,a,S1.Polygon,2,c*C0);return e3(r).filter(s=>s.length>=3)}function T3(n,e){if(!n.length||e<=0)return[];let t=E3(y6(n),e/2*C0,c0.Round,S1.Round,2,.01*C0);return e3(t)}function p0(n){if(!n.length)return[];let e=new J2,t=new D0;t.addSubject(Q2(n)),t.execute(M1.Union,p1.NonZero,e);let c=[],a=r=>{for(let s=0;s<r.count;s++){let i=r.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),a(h)}c.push(e3(o))}};return a(e),c}function i1(n){let e=0;for(let t=0,c=n.length-1;t<n.length;c=t++)e+=(n[c][0]+n[t][0])*(n[c][1]-n[t][1]);return-e/2}function b6(n){let e=0,t=0,c=0;for(let a of n){if(a.length<3)continue;let[r,s]=a[0];for(let i=0,o=a.length-1;i<a.length;o=i++){let l=a[o][0]-r,h=a[o][1]-s,f=a[i][0]-r,u=a[i][1]-s,d=l*u-f*h;e+=d/2,t+=(l+f)*d/6+r*d/2,c+=(h+u)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[t/e,c/e]}}function p6(n,[e,t]){return[n[0]*e+n[2]*t+n[4],n[1]*e+n[3]*t+n[5]]}function m6(n,e){let t=e[0]*e[3]-e[1]*e[2]<0,c=new Map;for(let[a,r]of n)c.set(a,{regions:r.regions.map(s=>{let i=s.map(o=>p6(e,o));return t?i.reverse():i}),lines:r.lines.map(s=>s.map(i=>p6(e,i)))});return c}function m2(n,e){return{layers:m6(n.layers,e),parts:n.parts.map(t=>({...t,layers:m6(t.layers,e)}))}}function q0(n){let e=W1();for(let t of n){for(let[c,a]of t.layers){let r=e.layers.get(c)??{regions:[],lines:[]};for(let s of a.regions)r.regions.push(s);for(let s of a.lines)r.lines.push(s);e.layers.set(c,r)}for(let c of t.parts)e.parts.push(c)}return e}var d0="\0hidden";function v6(n,e){let t={regions:[],lines:[]};for(let[r,s]of n)if(r!==d0){for(let i of s.regions)t.regions.push(i);for(let i of s.lines)t.lines.push(i)}let c=new Map([[e,t]]),a=n.get(d0);return a&&e!==d0&&c.set(d0,a),c}function t3(n,e){if(n.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:v6(n.layers,e),parts:n.parts.map(t=>({...t,layers:v6(t.layers,e)}))}}function m0(n){let e=1/0,t=1/0,c=-1/0,a=-1/0;for(let r of n)for(let[s,i]of r)s<e&&(e=s),i<t&&(t=i),s>c&&(c=s),i>a&&(a=i);return e===1/0?null:[e,t,c,a]}function k0(n,e){let t=[];for(let[c,a]of n)if(!e?.(c))for(let r of[...a.regions,...a.lines])t.push(r);return m0(t)}function I3(n){let e=[...n].sort((r,s)=>r[0]-s[0]||r[1]-s[1]);if(e.length<3)return e;let t=(r,s,i)=>(s[0]-r[0])*(i[1]-r[1])-(s[1]-r[1])*(i[0]-r[0]),c=[];for(let r of e){for(;c.length>=2&&t(c[c.length-2],c[c.length-1],r)<=0;)c.pop();c.push(r)}let a=[];for(let r=e.length-1;r>=0;r--){let s=e[r];for(;a.length>=2&&t(a[a.length-2],a[a.length-1],s)<=0;)a.pop();a.push(s)}return a.pop(),c.pop(),c.concat(a)}function M6(n,e,t,c){return n<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/t,n*2*Math.PI/c)),5)}function H3(n,e,t){let c=[];for(let a=0;a<t;a++){let r=2*Math.PI*a/t;c.push([n*Math.cos(r),e*Math.sin(r)])}return c}function x6(n,e,t,c){if(t=Math.min(t,n/2,e/2),t<=0)return[[0,0],[n,0],[n,e],[0,e]];let a=Math.max(1,Math.ceil(c(t)/4)),r=[],s=[[n-t,t,-90],[n-t,e-t,0],[t,e-t,90],[t,t,180]];for(let[i,o,l]of s)for(let h=0;h<=a;h++){let f=(l+90*h/a)*Math.PI/180;r.push([i+t*Math.cos(f),o+t*Math.sin(f)])}return r}function R5(n,e){let t=Z(n);for(let c=0;c<100;c++){let a=p0(t);if(a.length<=1)return t;let r=i=>i.reduce((o,l)=>o+i1(l),0);a.sort((i,o)=>r(o)-r(i));let s=[];for(let i=1;i<a.length;i++){let o=1/0,l=[0,0],h=[0,0];for(let[y,b]of a[i][0])for(let w=0;w<a.length;w++)if(w!==i)for(let x of a[w])for(let z=0,L=x.length-1;z<x.length;L=z++){let[S,k]=x[L],[E,V]=x[z],T=E-S,H=V-k,D=T*T+H*H,O=D?Math.max(0,Math.min(1,((y-S)*T+(b-k)*H)/D)):0,R=S+O*T,N=k+O*H,q=Math.hypot(y-R,b-N);q<o&&([o,l,h]=[q,[y,b],[R,N]])}if(!Number.isFinite(o))continue;let f=h[0]-l[0],u=h[1]-l[1],d=Math.hypot(f,u);d<1e-9?[f,u]=[0,1]:[f,u]=[f/d,u/d];let[m,p]=[-u*(e/2),f*(e/2)],v=[l[0]-f*(e/2),l[1]-u*(e/2)],g=[h[0]+f*(e/2),h[1]+u*(e/2)],M=[[v[0]-m,v[1]-p],[g[0]-m,g[1]-p],[g[0]+m,g[1]+p],[v[0]+m,v[1]+p]];s.push(i1(M)<0?M.reverse():M)}if(!s.length)return t;t=Z([...t,...s])}return t}function V3(n,e){let t=Math.round(n/e);return t%2===0&&(t+=n/e>t?1:-1),Math.max(3,t)}var n3=(n,e,t,c)=>[[n,e],[t,e],[t,c],[n,c]];function Ke(n,e,t,c){if(e==="flat")return[];let a=V3(n,c),r=n/a,s=[];for(let i=0;i<a;i++)(e==="out"?i%2===1:i%2===0)&&s.push(n3(i*r,-1,(i+1)*r,t));return s}function w6(n,e,t,c,a){let r=[([o,l])=>[o,l],([o,l])=>[n-l,o],([o,l])=>[n-o,e-l],([o,l])=>[l,e-o]],s=[n,e,n,e],i=[];return t.forEach((o,l)=>{for(let h of Ke(s[l],o,c,a))i.push(h.map(r[l]))}),l0([n3(0,0,n,e)],i)}function z6(n,e,t,c){let a=V3(n,c),r=n/a,s=[];for(let i=0;i<a;i++)(e==="out"?i%2===0:i%2===1)&&s.push(n3(i*r,-t/2,(i+1)*r,t/2));return s}function k6(n,e,t,c,a){let r=n3(-n/2,-1,n/2,e),s=n3(-t/2,a,t/2,a+c);return[r,s]}function L6(n,e,t,c,a){let r=[],s=a+c,i=Math.floor(n/t),o=(n-i*t)/2;for(let l=0;l<=i;l++){let h=o+l*t,f=l%2===0?c:c-s/2;for(let u=f;u<e;u+=s){let d=Math.max(u,l%2===0?c:0),m=Math.min(u+a,e-(l%2===0?c:0));m-d>=c/2&&r.push([[h,d],[h,m]])}}return r}function Je(n){let e=Math.floor(n)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}function S6(n){let{spacing:e,step:t,box:c}=n,a=e/2,r=e,s=new Map,i=[],o=[],l=[],h=[],f=[],u=(V,T)=>Math.floor((V-c[0])/r)*1000003+Math.floor((T-c[1])/r),d=(V,T,H)=>{let D=u(V[0],V[1]),O=i.length;i.push(V[0]),o.push(V[1]),l.push(T),h.push(H);let R=s.get(D);R?R.push(O):s.set(D,[O])},m=Math.ceil(2*e/t)+2,p=(V,T,H=-1,D=0)=>{let O=Math.floor((V[0]-c[0])/r),R=Math.floor((V[1]-c[1])/r);for(let N=O-1;N<=O+1;N++)for(let q=R-1;q<=R+1;q++){let Y=s.get(N*1000003+q);if(Y)for(let _ of Y){let c1=l[_];if(!(!f[c1]&&c1!==H)&&!(c1===H&&Math.abs(h[_]-D)<m)&&Math.hypot(i[_]-V[0],o[_]-V[1])<T)return!1}}return!0},v=[],g=0,M=Math.ceil(4*(c[2]-c[0]+c[3]-c[1]+e)/t+2*m),y=(V,T)=>{let H=n.dir(V);if(!H)return null;let D=[V[0]+T*H[0]*t/2,V[1]+T*H[1]*t/2],O=n.dir(D)??H;return O[0]*H[0]+O[1]*H[1]<0?null:[V[0]+T*O[0]*t,V[1]+T*O[1]*t]},b=V=>{let T=v.length;f[T]=!1,d(V,T,0);let H=[[],[]];for(let[R,N]of[[0,1],[1,-1]]){let q=V;for(let Y=1;Y<=M;Y++){let _=y(q,N);if(!_)break;let c1=N*Y;if(!n.inside(_)){H[R].push(_);break}if(!p(_,a,T,c1))break;if(H[R].push(_),d(_,T,c1),++g>n.maxPoints)throw new Error(`the lines have more than ${n.maxPoints} points: use a larger spacing or step`);n.tick(),q=_}}let D=[...H[1].reverse(),V,...H[0]],O=0;for(let R=1;R<D.length;R++)O+=Math.hypot(D[R][0]-D[R-1][0],D[R][1]-D[R-1][1]);return v.push(D),D.length<2||O<n.minLength?null:(f[T]=!0,D)},w=Je(n.seed),x=[];for(let V=c[0]+e/2;V<c[2];V+=e)for(let T=c[1]+e/2;T<c[3];T+=e)x.push([V+(w()-.5)*e,T+(w()-.5)*e]);for(let V=x.length-1;V>0;V--){let T=Math.floor(w()*(V+1));[x[V],x[T]]=[x[T],x[V]]}let z=[],L=[],S=Math.max(1,Math.round(e/(2*t))),k=V=>{if(!n.inside(V)||!p(V,e)||!n.dir(V))return;let T=b(V);T&&(z.push(T),L.push(T))},E=0;for(;;){for(;L.length;){let V=L.shift();for(let T=0;T<V.length;T+=S){let H=V[Math.max(0,T-1)],D=V[Math.min(V.length-1,T+1)],O=Math.hypot(D[0]-H[0],D[1]-H[1]);if(O===0)continue;let R=-(D[1]-H[1])/O,N=(D[0]-H[0])/O;for(let q of[1,-1])k([V[T][0]+q*R*e,V[T][1]+q*N*e])}}if(E>=x.length)break;k(x[E++])}return z}function A6(n,e,t,c,a,r,s){let i=(v,g)=>n[g*e+v],o=(v,g)=>(g*e+v)*2,l=(v,g)=>(g*e+v)*2+1,h=v=>{let g=v>>1,M=g%e,y=(g-M)/e,b=i(M,y),w=v&1?i(M,y+1):i(M+1,y),x=b===w?.5:(s-b)/(w-b);return v&1?[c+M*r,a+(y+x)*r]:[c+(M+x)*r,a+y*r]},f=new Map,u=(v,g)=>{for(let[M,y]of[[v,g],[g,v]]){let b=f.get(M);b?b.push(y):f.set(M,[y])}};for(let v=0;v+1<t;v++)for(let g=0;g+1<e;g++){let M=i(g,v),y=i(g+1,v),b=i(g+1,v+1),w=i(g,v+1);if(Number.isNaN(M+y+b+w))continue;let x=(M>=s?1:0)|(y>=s?2:0)|(b>=s?4:0)|(w>=s?8:0);if(x===0||x===15)continue;let z=o(g,v),L=l(g+1,v),S=o(g,v+1),k=l(g,v);if(x===5||x===10){let V=(M+y+b+w)/4>=s;x===5===V?(u(z,L),u(k,S)):(u(k,z),u(L,S));continue}let E=[];(x&1)!==(x&2)>>1&&E.push(z),(x&2)>>1!==(x&4)>>2&&E.push(L),(x&4)>>2!==(x&8)>>3&&E.push(S),(x&8)>>3!==(x&1)&&E.push(k),E.length===2&&u(E[0],E[1])}let d=new Set,m=v=>{let g=[h(v)];d.add(v);let M=v;for(;;){let y=(f.get(M)??[]).find(b=>!d.has(b));if(y===void 0)return(f.get(M)??[]).includes(v)&&g.length>2&&g.push(g[0]),g;d.add(y),g.push(h(y)),M=y}},p=[];for(let[v,g]of f)g.length===1&&!d.has(v)&&p.push(m(v));for(let v of f.keys())d.has(v)||p.push(m(v));return p.map(v=>v.filter((g,M)=>M===0||g[0]!==v[M-1][0]||g[1]!==v[M-1][1])).filter(v=>v.length>=2&&!(v.length===2&&v[0][0]===v[1][0]&&v[0][1]===v[1][1]))}function C6(n,e=.001){let t=n.filter(l=>l.length>=2).map(l=>[...l]);if(t.length<2)return t;let c=l=>`${Math.round(l[0]/e)},${Math.round(l[1]/e)}`,a=new Map,r=(l,h)=>{let f=c(l),u=a.get(f);u?u.push(h):a.set(f,[h])};t.forEach((l,h)=>{r(l[0],h),r(l[l.length-1],h)});let s=new Array(t.length).fill(!1),i=l=>c(l[0])===c(l[l.length-1]),o=[];for(let l=0;l<t.length;l++){if(s[l])continue;s[l]=!0;let h=t[l];if(!i(h))for(let f=0;f<2;f++){for(;;){let u=h[h.length-1],d=(a.get(c(u))??[]).find(v=>!s[v]);if(d===void 0)break;s[d]=!0;let m=t[d],p=c(m[0])===c(u)?m:[...m].reverse();if(h=h.concat(p.slice(1)),i(h))break}if(i(h))break;h=h.reverse()}o.push(h)}return Qe(o)}function Qe(n){let e=n.length;if(e<2)return n;let t=1/0,c=1/0,a=-1/0,r=-1/0;for(let p of n)for(let v of[p[0],p[p.length-1]])t=Math.min(t,v[0]),c=Math.min(c,v[1]),a=Math.max(a,v[0]),r=Math.max(r,v[1]);let s=Math.max((a-t+r-c)/Math.sqrt(e),1e-6),i=p=>Math.floor((p-t)/s),o=p=>Math.floor((p-c)/s),l=i(a)+1,h=o(r)+1,f=new Map;n.forEach((p,v)=>{for(let g of[p[0],p[p.length-1]]){let M=o(g[1])*l+i(g[0]),y=f.get(M);y?y[y.length-1]!==v&&y.push(v):f.set(M,[v])}});let u=new Array(e).fill(!1),d=[],m=[0,0];for(let p=0;p<e;p++){let v=-1,g=1/0,M=!1,y=Math.min(Math.max(i(m[0]),0),l-1),b=Math.min(Math.max(o(m[1]),0),h-1);for(let x=0;x<=Math.max(l,h);x++){for(let z=y-x;z<=y+x;z++)for(let L=b-x;L<=b+x;L++)if(Math.max(Math.abs(z-y),Math.abs(L-b))===x&&!(z<0||L<0||z>=l||L>=h))for(let S of f.get(L*l+z)??[]){if(u[S])continue;let k=n[S],E=Math.hypot(k[0][0]-m[0],k[0][1]-m[1]),V=Math.hypot(k[k.length-1][0]-m[0],k[k.length-1][1]-m[1]);E<g&&([v,g,M]=[S,E,!1]),V<g&&([v,g,M]=[S,V,!0])}if(v>=0&&g<=x*s)break}if(v<0){for(let x=0;x<e;x++)if(!u[x]){v=x;break}}u[v]=!0;let w=M?[...n[v]].reverse():n[v];d.push(w),m=w[w.length-1]}return d}function P6(n){let e=[],t=1/0,c=-1/0;for(let i of n)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]]),t=Math.min(t,i[o][1]),c=Math.max(c,i[o][1]);if(!e.length)return()=>!1;let a=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),r=(c-t)/a||1,s=Array.from({length:a},()=>[]);return e.forEach(([,i,,o],l)=>{let h=Math.max(0,Math.min(a-1,Math.floor((Math.min(i,o)-t)/r))),f=Math.max(0,Math.min(a-1,Math.floor((Math.max(i,o)-t)/r)));for(let u=h;u<=f;u++)s[u].push(l)}),([i,o])=>{if(o<t||o>c)return!1;let l=0;for(let h of s[Math.max(0,Math.min(a-1,Math.floor((o-t)/r)))]){let[f,u,d,m]=e[h];u<=o?m>o&&(d-f)*(o-u)-(i-f)*(m-u)>0&&l++:m<=o&&(d-f)*(o-u)-(i-f)*(m-u)<0&&l--}return l!==0}}var E6=Math.PI/180;function q1(n,e){let t=new Array(16).fill(0);for(let c=0;c<4;c++)for(let a=0;a<4;a++)for(let r=0;r<4;r++)t[c*4+a]+=n[c*4+r]*e[r*4+a];return t}function O3(n,e){let t=Math.cos(e*E6),c=Math.sin(e*E6);return n===0?[1,0,0,0,0,t,-c,0,0,c,t,0,0,0,0,1]:n===1?[t,0,c,0,0,1,0,0,-c,0,t,0,0,0,0,1]:[t,-c,0,0,c,t,0,0,0,0,1,0,0,0,0,1]}var U5=n=>Math.abs(n)<1e-12?0:n;function a0(n){if(n.matrix)return n.matrix.map(U5);let[e,t,c]=n.rotate,a=q1(O3(2,c),q1(O3(1,t),O3(0,e)));return a[3]=n.at[0],a[7]=n.at[1],a[11]=n.at[2],a.map(U5)}function v2(n,e,t,c){return[n[0]*e+n[1]*t+n[2]*c+n[3],n[4]*e+n[5]*t+n[6]*c+n[7],n[8]*e+n[9]*t+n[10]*c+n[11]]}function c3(n){let[e,t,c]=[n[3],n[7],n[11]],a=[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]];return[a[0],a[1],a[2],-(a[0]*e+a[1]*t+a[2]*c),a[3],a[4],a[5],-(a[3]*e+a[4]*t+a[5]*c),a[6],a[7],a[8],-(a[6]*e+a[7]*t+a[8]*c),0,0,0,1]}function F3(n){let[e,t,c,a]=[1/0,1/0,-1/0,-1/0];for(let r of n)for(let[s,i]of r)e=Math.min(e,s),t=Math.min(t,i),c=Math.max(c,s),a=Math.max(a,i);return[e,t,c,a]}function V6(n){let[e,t,c,a]=F3(n.outline),r=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,c])for(let o of[t,a])for(let l of[0,n.thickness]){let h=v2(n.matrix,i,o,l);for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),s[f]=Math.max(s[f],h[f])}return[r,s]}function O6(n,e,t=10){let c=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let[h,f]of n.map(V6))for(let u=0;u<3;u++)c[u]=Math.min(c[u],h[u]),a[u]=Math.max(a[u],f[u]);let r=e.map(h=>F3(h.outline)),s=r.reduce((h,[f,,u])=>Math.max(h,u-f),a[0]-c[0]),i=0,o=0,l=0;return e.map((h,f)=>{let[u,d,m,p]=r[f];i>0&&i+m-u>s&&(i=0,o+=l+t,l=0);let v=[1,0,0,a[0]+t+i-u,0,1,0,c[1]+o-d,0,0,1,c[2],0,0,0,1];return i+=m-u+t,l=Math.max(l,p-d),{...h,matrix:v.map(U5)}})}var e9=(n,e,t)=>[0,1,2].every(c=>n[0][c]<e[1][c]-t&&e[0][c]<n[1][c]-t),P2=(n,e)=>n[0]*e[0]+n[1]*e[1]+n[2]*e[2],D3=(n,e)=>[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]],q5=(n,e,t=1)=>[n[0]+e[0]*t,n[1]+e[1]*t,n[2]+e[2]*t],T2=n=>[n[2],n[6],n[10]],T6=n=>[n[3],n[7],n[11]],t9=(n,e)=>[n[0]*e[0]+n[1]*e[1]+n[2]*e[2],n[4]*e[0]+n[5]*e[1]+n[6]*e[2],n[8]*e[0]+n[9]*e[1]+n[10]*e[2]];function E2(n,e,t){let c=t[0]*t[0]+t[1]*t[1],a=[];for(let r of n)for(let s=0,i=r.length-1;s<r.length;i=s++){let o=r[i],l=r[s],h=t[0]*(o[1]-e[1])-t[1]*(o[0]-e[0]),f=t[0]*(l[1]-e[1])-t[1]*(l[0]-e[0]);if(h>0==f>0)continue;let u=h/(h-f),d=o[0]+(l[0]-o[0])*u-e[0],m=o[1]+(l[1]-o[1])*u-e[1];a.push((d*t[0]+m*t[1])/c)}return a.sort((r,s)=>r-s)}function N5(n,e,t){let c=0,a=0,r=0,s=0,i=0;for(;s+1<n.length&&i+1<e.length;){let o=Math.max(n[s],e[i]),l=Math.min(n[s+1],e[i+1])-o;l>t&&(c+=l,l>r&&(r=l,a=o+l/2)),n[s+1]<e[i+1]?s+=2:i+=2}return{total:c,mid:a,run:r}}function n9(n,e){let[t,c,a]=v2(c3(n.matrix),e[0],e[1],e[2]);if(a<0||a>n.thickness)return!1;let r=!1;for(let s of n.outline)for(let i=0,o=s.length-1;i<s.length;o=i++){let[l,h]=s[o],[f,u]=s[i];h>c!=u>c&&t<l+(f-l)*(c-h)/(u-h)&&(r=!r)}return r}var R3=class{constructor(e=[]){this.parts=e;this.seen=[]}see(e,t){e>0&&this.seen.push([t(),e])}get at(){let e=0,t=[0,0,0];for(let[r,s]of this.seen){for(let i=0;i<3;i++)t[i]+=r[i]*s;e+=s}for(let r=0;r<3;r++)t[r]/=e;if(this.parts.length&&this.parts.every(r=>n9(r,t)))return t;let c=this.seen[0][0],a=1/0;for(let[r]of this.seen){let s=Math.hypot(r[0]-t[0],r[1]-t[1],r[2]-t[2]);s<a&&([c,a]=[r,s])}return c}};function q3(n,e,t,c){let a=n+t,r=e-t;if(r<=a)return{at:[],size:0};let s=Math.max(4,Math.ceil((r-a)/c));return{at:Array.from({length:s},(i,o)=>a+(r-a)*(o+.5)/s),size:(r-a)/s}}function I6(n,e,t){let c=v2(n,e[0],e[1],e[2]),a=t9(n,t);return[[c[0],c[1]],[a[0],a[1]]]}function F6(n,e,t,c,a,r,s,i=!1){let o=T2(n.matrix),l=T2(e.matrix),h=D3(o,l),f=Math.hypot(...h),u=[h[0]/f,h[1]/f,h[2]/f],d=D3(u,o),m=P2(l,d),p=T6(n.matrix),v=P2(l,T6(e.matrix)),g=1/0,M=-1/0;for(let L of e.outline)for(let[S,k]of L)for(let E of[0,e.thickness]){let V=v2(e.matrix,S,k,E),T=P2(o,[V[0]-p[0],V[1]-p[1],V[2]-p[2]]);T<g&&(g=T),T>M&&(M=T)}let y=q3(Math.max(0,g),Math.min(n.thickness,M),a,r),b=1/0,w=-1/0;for(let L of n.outline)for(let[S,k]of L){let E=v2(n.matrix,S,k,0),V=P2(d,[E[0]-p[0],E[1]-p[1],E[2]-p[2]]);V<b&&(b=V),V>w&&(w=V)}let x=0,z=new R3([n,e]);for(let L of y.at){let S=q5(p,o,L),k=(v-P2(l,S))/m,E=(v+e.thickness-P2(l,S))/m,V=q3(Math.max(b,Math.min(k,E)),Math.min(w,Math.max(k,E)),a,r);for(let T of V.at){let H=q5(S,d,T),[D,O]=I6(t,H,u),[R,N]=I6(c,H,u),q=N5(E2(n.outline,D,O),E2(e.outline,R,N),a);if(x+=q.total*y.size*V.size,z.see(q.run,()=>q5(H,u,q.mid)),x>s&&!i)return z.at}}return x>s?z.at:void 0}function D6(n,e,t,c,a,r,s=!1){let i=[0,1,2,3].flatMap(k=>[0,1,2,3].map(E=>{let V=0;for(let T=0;T<4;T++)V+=t[k*4+T]*e.matrix[T*4+E];return V})),o=i[11],l=i[11]+i[10]*e.thickness,h=Math.min(n.thickness,Math.max(o,l))-Math.max(0,Math.min(o,l));if(h<=c)return;let f=Math.max(0,Math.min(o,l))+h/2,u=new R3([n,e]),d=e.outline.map(k=>k.map(([E,V])=>[i[0]*E+i[1]*V+i[3],i[4]*E+i[5]*V+i[7]])),[m,p,v,g]=F3(n.outline),[M,y,b,w]=F3(d),x=q3(Math.max(p,y),Math.min(g,w),c,a),z=0;for(let k of x.at){let E=N5(E2(n.outline,[0,k],[1,0]),E2(d,[0,k],[1,0]),c);if(z+=E.total*x.size*h,u.see(E.run,()=>v2(n.matrix,E.mid,k,f)),z>r&&!s)return u.at}let L=q3(Math.max(m,M),Math.min(v,b),c,a),S=0;for(let k of L.at){let E=N5(E2(n.outline,[k,0],[0,1]),E2(d,[k,0],[0,1]),c);if(S+=E.total*L.size*h,u.see(E.run,()=>v2(n.matrix,k,E.mid,f)),S>r&&!s)return u.at}return z>r||S>r?u.at:void 0}function R6(n,e=1/0,t=.05,c=.25,a=.1){let r=n.map(V6),s=n.map(h=>c3(h.matrix)),i=n.map((h,f)=>f).sort((h,f)=>r[h][0][0]-r[f][0][0]),o=[],l=0;for(let h=0;h<i.length;h++)for(let f=h+1;f<i.length;f++){let u=i[h],d=i[f];if(r[d][0][0]>=r[u][1][0]-t)break;if(!e9(r[u],r[d],t))continue;if(++l>e)return{found:o,complete:!1};let[m,p]=u<d?[n[u],n[d]]:[n[d],n[u]],[v,g]=u<d?[s[u],s[d]]:[s[d],s[u]],y=Math.hypot(...D3(T2(m.matrix),T2(p.matrix)))<1e-9?D6(m,p,v,t,c,a):F6(m,p,v,g,t,c,a);y&&o.push([m,p,y])}return{found:o,complete:!0}}function q6(n,e,t=.05,c=.25,a=.1){let r=Math.hypot(...D3(T2(n.matrix),T2(e.matrix)))<1e-9,s=c3(n.matrix);return r?D6(n,e,s,t,c,a,!0):F6(n,e,s,c3(e.matrix),t,c,a,!0)}function Z0(n,e,t){return[1,0,0,n,0,1,0,e,0,0,1,t,0,0,0,1]}var $5=Z0(0,0,0);function t2(n){return c3(n)}function c9(n,e,t=n.angle,c=n.x1){let a=c-n.x0;if(!t||!(a>0))return Z0(0,0,0);let r=(n.x1-n.x0)/(n.angle*Math.PI/180),s=e/2+r;return q1(Z0(n.x0,0,s),q1(O3(1,-t),Z0(-n.x0-a,0,-s)))}function U3(n){return[...n].sort((e,t)=>e.x0-t.x0)}var _5=n=>n.length>0&&n.every(e=>e.mirrored),H6=[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],a9=n=>q1(H6,q1(n,H6));function U6(n){return U3(n).map(e=>e.mirrored?[-e.x1,-e.x0]:[e.x0,e.x1])}function B5(n,e){let t=[Z0(0,0,0)];for(let c of U3(n))t.push(q1(t[t.length-1],c9(c,e)));return _5(n)?t.map(a9):t}function N6(n,e){let t=_5(n)?-e:e;return U3(n).filter(c=>(c.x0+c.x1)/2<t).length}function N3(n){if(!n.bends?.length)return[n];let e=U3(n.bends),t=B5(n.bends,n.thickness),c=_5(n.bends),a=1e7,r=[];for(let s=0;s<=e.length;s++){let i=s===0?-a:e[s-1].x1,o=s===e.length?a:e[s].x0;if(!(o>i))continue;let[l,h]=c?[-o,-i]:[i,o],f=[[l,-a],[h,-a],[h,a],[l,a]],u=P1(n.outline,[f]);u.length&&r.push({...n,outline:u,bends:void 0,matrix:q1(n.matrix,t[s])})}return r}var v0=(n,e=!0)=>`line ${n.line}${e?`, column ${n.col}`:""}${n.file?` in <${n.file}>`:""}`;var G=class extends Error{constructor(t,c){super(c?`${t} (${v0(c)})`:t);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=t,c&&(this.line=c.line,this.col=c.col,this.file=c.file)}addFrame(t,c,a){let r=this.trace.find(s=>s.name===c&&s.line===a.line&&s.col===a.col&&s.file===a.file);r?r.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:t,name:c,line:a.line,col:a.col,...a.file&&{file:a.file},count:1})}},r9=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function I2(n,e){let t=[],c=[],a=0,r=1,s=0,i=()=>({line:r,col:a-s+1,offset:a,...e&&{file:e}}),o=l=>{for(let h=0;h<l;h++)n[a]===`
|
|
6
|
+
`}},K3=class n extends Y3{constructor(t=null){super(t);q(this,"polygon",null)}get poly(){return this.polygon}addChild(t){let c=new n(this);return c.polygon=t,this.children.push(c),c}child(t){if(t<0||t>=this.children.length)throw new Error("Index out of range");return this.children[t]}area(){let t=this.polygon===null?0:K5.area(this.polygon);for(let c of this.children)t+=c.area();return t}};var p3=class extends K3{};var H=class H{constructor(){q(this,"cliptype",C1.NoClip);q(this,"fillrule",g1.EvenOdd);q(this,"actives",null);q(this,"sel",null);q(this,"minimaList",[]);q(this,"intersectList",[]);q(this,"vertexList",[]);q(this,"outrecList",[]);q(this,"scanlineHeap",new Z5);q(this,"scanlineSet",new Set);q(this,"scanlineArr",[]);q(this,"useScanlineArray",!1);q(this,"horzSegList",[]);q(this,"horzJoinList",[]);q(this,"currentLocMin",0);q(this,"currentBotY",0);q(this,"curXValidAtTop",!1);q(this,"isSortedMinimaList",!1);q(this,"hasOpenPaths",!1);q(this,"usingPolytree",!1);q(this,"succeeded",!1);q(this,"zCallbackInternal");q(this,"preserveCollinear",!0);q(this,"reverseSolution",!1)}getZCallback(){}xyEqual(e,t){return e.x===t.x&&e.y===t.y}setZ(e,t,c){let a=this.zCallbackInternal;a&&(H.getPolyType(e)===r0.Subject?(this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:this.xyEqual(c,t.bot)?c.z=t.bot.z??0:this.xyEqual(c,t.top)?c.z=t.top.z??0:c.z=0,a(e.bot,e.top,t.bot,t.top,c)):(this.xyEqual(c,t.bot)?c.z=t.bot.z??0:this.xyEqual(c,t.top)?c.z=t.top.z??0:this.xyEqual(c,e.bot)?c.z=e.bot.z??0:this.xyEqual(c,e.top)?c.z=e.top.z??0:c.z=0,a(t.bot,t.top,e.bot,e.top,c)))}static isOdd(e){return(e&1)!==0}static isHotEdge(e){return e.outrec!=null}static isOpen(e){return H.openPathsEnabled&&e.localMin.isOpen}static isOpenEnd(e){return H.openPathsEnabled&&e.localMin.isOpen&&H.isOpenEndVertex(e.vertexTop)}static isOpenEndVertex(e){return(e.flags&(y1.OpenStart|y1.OpenEnd))!==y1.None}static getPrevHotEdge(e){let t=e.prevInAEL;if(!H.openPathsEnabled){for(;t!==null&&!H.isHotEdge(t);)t=t.prevInAEL;return t}for(;t!==null&&(t.localMin.isOpen||!H.isHotEdge(t));)t=t.prevInAEL;return t}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,t){let c=t.y-e.y;return c!==0?(t.x-e.x)/c:t.x>e.x?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY}static topX(e,t){return t===e.top.y||e.top.x===e.bot.x?e.top.x:t===e.bot.y?e.bot.x:d1.roundToEven(e.bot.x+e.dx*(t-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,t){return e.localMin.polytype===t.localMin.polytype}static setDx(e){e.dx=H.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 t=e.nextInAEL;for(;t!==null;){if(t.vertexTop===e.vertexTop)return t;t=t.nextInAEL}return null}boundingBoxesOverlap(e,t,c,a){let r=e.x<t.x?e.x:t.x;if((c.x>a.x?c.x:a.x)<r)return!1;let i=e.x>t.x?e.x:t.x,o=c.x<a.x?c.x:a.x;if(i<o)return!1;let l=e.y<t.y?e.y:t.y;if((c.y>a.y?c.y:a.y)<l)return!1;let f=e.y>t.y?e.y:t.y,u=c.y<a.y?c.y:a.y;return f>=u}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,t)=>t.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 t=0,c=e.length;t<c;t++){let a=e[t];this.scanlineSet.add(a),this.scanlineHeap.push(a)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let t=this.scanlineArr;for(let c=0,a=t.length;c<a;c++)if(t[c]===e)return;t.push(e),t.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let t=this.scanlineArr,c=t.length;if(c===0)return null;let a=0,r=t[0];for(let s=1;s<c;s++){let i=t[s];i>r&&(r=i,a=s)}return t[a]=t[c-1],t.pop(),r}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,t,c=!1){let a=[e];this.addPaths(a,t,c)}addPaths(e,t,c=!1){c&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,D2.addPathsToVertexList(e,t,c,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let t of e.minimaList)this.minimaList.push(new u3(t.vertex,t.polytype,t.isOpen)),t.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let t=e.prevInAEL,c=e.nextInAEL;t===null&&c===null&&e!==this.actives||(t!==null?t.nextInAEL=c:this.actives=c,c!==null&&(c.prevInAEL=t))}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 t of this.vertexList){let c=t;do c.pt.x<e.left&&(e.left=c.pt.x),c.pt.x>e.right&&(e.right=c.pt.x),c.pt.y<e.top&&(e.top=c.pt.y),c.pt.y>e.bottom&&(e.bottom=c.pt.y),c=c.next;while(c!==t)}return w2.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(e,t){if(e===C1.NoClip)return;H.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=t,this.cliptype=e,this.reset();let c=this.popScanline();if(c!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(c);let a;for(;(a=this.popHorz())!==null;)this.doHorizontal(a);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=c;let r=this.popScanline();if(r===null)break;for(c=r,this.doIntersections(c),this.doTopOfScanbeam(c);(a=this.popHorz())!==null;)this.doHorizontal(a)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(e){for(;this.hasLocMinAtY(e);){let t=this.popLocalMinima(),c;(t.vertex.flags&y1.OpenStart)!==y1.None?c=null:(c=new d3,c.bot=t.vertex.pt,c.curX=t.vertex.pt.x,c.windDx=-1,c.vertexTop=t.vertex.prev,c.top=t.vertex.prev.pt,c.outrec=null,c.localMin=t,H.setDx(c));let a;if((t.vertex.flags&y1.OpenEnd)!==y1.None?a=null:(a=new d3,a.bot=t.vertex.pt,a.curX=t.vertex.pt.x,a.windDx=1,a.vertexTop=t.vertex.next,a.top=t.vertex.next.pt,a.outrec=null,a.localMin=t,H.setDx(a)),c!==null&&a!==null){if(H.isHorizontal(c)){if(H.isHeadingRightHorz(c)){let s=c;c=a,a=s}}else if(H.isHorizontal(a)){if(H.isHeadingLeftHorz(a)){let s=c;c=a,a=s}}else if(c.dx<a.dx){let s=c;c=a,a=s}}else c===null&&(c=a,a=null);let r;if(c.isLeftBound=!0,this.insertLeftEdge(c),H.openPathsEnabled?H.isOpen(c)?(this.setWindCountForOpenPathEdge(c),r=this.isContributingOpen(c)):(this.setWindCountForClosedPathEdge(c),r=this.isContributingClosed(c)):(this.setWindCountForClosedPathEdge(c),r=this.isContributingClosed(c)),a!==null){for(a.windCount=c.windCount,a.windCount2=c.windCount2,this.insertRightEdge(c,a),r&&(this.addLocalMinPoly(c,a,c.bot,!0),H.isHorizontal(c)||this.checkJoinLeft(c,c.bot));a.nextInAEL!==null&&this.isValidAelOrder(a.nextInAEL,a);)this.intersectEdges(a,a.nextInAEL,a.bot),this.swapPositionsInAEL(a,a.nextInAEL);H.isHorizontal(a)?this.pushHorz(a):(this.checkJoinRight(a,a.bot),this.insertScanline(a.top.y))}else r&&H.openPathsEnabled&&this.startOpenPath(c,c.bot);H.isHorizontal(c)?this.pushHorz(c):this.insertScanline(c.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(e){if(!H.openPathsEnabled){this.doHorizontalClosed(e);return}let t=H.isOpen(e),c=e.bot.y,a=t?this.getCurrYMaximaVertexOpen(e):this.getCurrYMaximaVertex(e),{isLeftToRight:r,leftX:s,rightX:i}=this.resetHorzDirection(e,a),o=s,l=i;if(H.isHotEdge(e)){let h=this.addOutPt(e,{x:e.curX,y:c});this.addToHorzSegList(h)}for(;;){let h=r?e.nextInAEL:e.prevInAEL;for(;h!==null;){if(h.vertexTop===a){if(H.isHotEdge(e)&&this.isJoined(h)&&this.split(h,h.top),H.isHotEdge(e)){for(;e.vertexTop!==a;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);r?this.addLocalMaxPoly(e,h,e.top):this.addLocalMaxPoly(h,e,e.top)}this.deleteFromAEL(h),this.deleteFromAEL(e);return}if(a!==e.vertexTop||H.isOpenEnd(e)){if(r&&h.curX>l||!r&&h.curX<o)break;if(h.curX===e.top.x&&!H.isHorizontal(h)){let d=H.nextVertex(e).pt;if(H.isOpen(h)&&!H.isSamePolyType(h,e)&&!H.isHotEdge(h)){if(r&&H.topX(h,d.y)>d.x||!r&&H.topX(h,d.y)<d.x)break}else if(r&&H.topX(h,d.y)>=d.x||!r&&H.topX(h,d.y)<=d.x)break}}let u={x:h.curX,y:c};r?(this.intersectEdges(e,h,u),this.swapPositionsInAEL(e,h),this.checkJoinLeft(h,u),e.curX=h.curX,h=e.nextInAEL):(this.intersectEdges(h,e,u),this.swapPositionsInAEL(h,e),this.checkJoinRight(h,u),e.curX=h.curX,h=e.prevInAEL),H.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(t&&H.isOpenEnd(e)){H.isHotEdge(e)&&(this.addOutPt(e,e.top),H.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e);return}if(H.nextVertex(e).pt.y!==e.top.y)break;H.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let f=this.resetHorzDirection(e,a);o=f.leftX,l=f.rightX}if(H.isHotEdge(e)){let h=this.addOutPt(e,e.top);this.addToHorzSegList(h)}this.updateEdgeIntoAEL(e)}doHorizontalClosed(e){let t=e.bot.y,c=this.getCurrYMaximaVertex(e),{isLeftToRight:a,leftX:r,rightX:s}=this.resetHorzDirection(e,c),i=r,o=s;if(H.isHotEdge(e)){let l=this.addOutPt(e,{x:e.curX,y:t});this.addToHorzSegList(l)}for(;;){let l=a?e.nextInAEL:e.prevInAEL;for(;l!==null;){if(l.vertexTop===c){if(H.isHotEdge(e)&&this.isJoined(l)&&this.split(l,l.top),H.isHotEdge(e)){for(;e.vertexTop!==c;)this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);a?this.addLocalMaxPoly(e,l,e.top):this.addLocalMaxPoly(l,e,e.top)}this.deleteFromAEL(l),this.deleteFromAEL(e);return}if(c!==e.vertexTop){if(a&&l.curX>o||!a&&l.curX<i)break;if(l.curX===e.top.x&&!H.isHorizontal(l)){let u=H.nextVertex(e).pt,d=H.topX(l,u.y);if(a&&d>=u.x||!a&&d<=u.x)break}}let f={x:l.curX,y:t};a?(this.intersectEdges(e,l,f),this.swapPositionsInAEL(e,l),this.checkJoinLeft(l,f),e.curX=l.curX,l=e.nextInAEL):(this.intersectEdges(l,e,f),this.swapPositionsInAEL(l,e),this.checkJoinRight(l,f),e.curX=l.curX,l=e.prevInAEL),H.isHotEdge(e)&&this.addToHorzSegList(this.getLastOp(e))}if(H.nextVertex(e).pt.y!==e.top.y)break;H.isHotEdge(e)&&this.addOutPt(e,e.top),this.updateEdgeIntoAEL(e);let h=this.resetHorzDirection(e,c);i=h.leftX,o=h.rightX}if(H.isHotEdge(e)){let l=this.addOutPt(e,e.top);this.addToHorzSegList(l)}this.updateEdgeIntoAEL(e)}convertHorzSegsToJoins(){let e=this.horzSegList,t=0;for(let c=0,a=e.length;c<a;c++){let r=e[c];this.updateHorzSegment(r)&&(e[t++]=r)}if(!(t<2)){e.length=t,this.horzSegList.sort(p8);for(let c=0;c<t-1;c++){let a=this.horzSegList[c];for(let r=c+1;r<t;r++){let s=this.horzSegList[r];if(s.leftOp.pt.x>=a.rightOp.pt.x||s.leftToRight===a.leftToRight||s.rightOp.pt.x<=a.leftOp.pt.x)continue;let i=a.leftOp.pt.y;if(a.leftToRight){for(;a.leftOp.next.pt.y===i&&a.leftOp.next.pt.x<=s.leftOp.pt.x;)a.leftOp=a.leftOp.next;for(;s.leftOp.prev.pt.y===i&&s.leftOp.prev.pt.x<=a.leftOp.pt.x;)s.leftOp=s.leftOp.prev;let o=new f3(this.duplicateOp(a.leftOp,!0),this.duplicateOp(s.leftOp,!1));this.horzJoinList.push(o)}else{for(;a.leftOp.prev.pt.y===i&&a.leftOp.prev.pt.x<=s.leftOp.pt.x;)a.leftOp=a.leftOp.prev;for(;s.leftOp.next.pt.y===i&&s.leftOp.next.pt.x<=a.leftOp.pt.x;)s.leftOp=s.leftOp.next;let o=new f3(this.duplicateOp(s.leftOp,!0),this.duplicateOp(a.leftOp,!1));this.horzJoinList.push(o)}}}}}updateHorzSegment(e){let t=e.leftOp,c=this.getRealOutRec(t.outrec),a=c.frontEdge!==null,r=t.pt.y,s=t,i=t;if(a){let l=c.pts,h=l.next;for(;s!==h&&s.prev.pt.y===r;)s=s.prev;for(;i!==l&&i.next.pt.y===r;)i=i.next}else{for(;s.prev!==i&&s.prev.pt.y===r;)s=s.prev;for(;i.next!==s&&i.next.pt.y===r;)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,t,c){return t.pt.x===c.pt.x?!1:(t.pt.x<c.pt.x?(e.leftOp=t,e.rightOp=c,e.leftToRight=!0):(e.leftOp=c,e.rightOp=t,e.leftToRight=!1),!0)}duplicateOp(e,t){let c=new a2(e.pt,e.outrec);return t?(c.next=e.next,c.next.prev=c,c.prev=e,e.next=c):(c.prev=e.prev,c.prev.next=c,c.next=e,e.prev=c),c}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(e){let t=this.curXValidAtTop;this.curXValidAtTop=!1,this.sel=null;let c=this.actives;for(;c!==null;){if(c.top.y===e)if(c.curX=c.top.x,H.isMaximaEdge(c)){c=this.doMaxima(c);continue}else H.isHotEdge(c)&&this.addOutPt(c,c.top),this.updateEdgeIntoAEL(c),H.isHorizontal(c)&&this.pushHorz(c);else t||(c.curX=H.topX(c,e));c=c.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let t=this.getRealOutRec(e.op1.outrec),c=this.getRealOutRec(e.op2.outrec),a=e.op1.next,r=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,a.prev=r,r.next=a,t===c){let s=this.newOutRec();s.pts=a,this.fixOutRecPts(s),t.pts.outrec===s&&(t.pts=e.op1,t.pts.outrec=t),this.usingPolytree?(this.path1InsidePath2(t.pts,s.pts)?([s.pts,t.pts]=[t.pts,s.pts],this.fixOutRecPts(t),this.fixOutRecPts(s),s.owner=t):this.path1InsidePath2(s.pts,t.pts)?s.owner=t:s.owner=t.owner,t.splits===null&&(t.splits=[]),t.splits.push(s.idx)):s.owner=t}else c.pts=null,this.usingPolytree?(this.setOwner(c,t),this.moveSplits(c,t)):c.owner=t}}fixOutRecPts(e){let t=e.pts;do t.outrec=e,t=t.next;while(t!==e.pts)}path1InsidePath2(e,t){let c=v1.IsOn,a=e;do{switch(this.pointInOpPolygon(a.pt,t)){case v1.IsOutside:if(c===v1.IsOutside)return!1;c=v1.IsOutside;break;case v1.IsInside:if(c===v1.IsInside)return!0;c=v1.IsInside;break;default:break}a=a.next}while(a!==e);return d1.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(t))}pointInOpPolygon(e,t){if(t===t.next||t.prev===t.next)return v1.IsOutside;let c=t;do{if(t.pt.y!==e.y)break;t=t.next}while(t!==c);if(t.pt.y===e.y)return v1.IsOutside;let a=t.pt.y<e.y,r=a,s=0;for(c=t.next;c!==t;){if(a)for(;c!==t&&c.pt.y<e.y;)c=c.next;else for(;c!==t&&c.pt.y>e.y;)c=c.next;if(c===t)break;if(c.pt.y===e.y){if(c.pt.x===e.x||c.pt.y===c.prev.pt.y&&e.x<c.prev.pt.x!=e.x<c.pt.x)return v1.IsOn;if(c=c.next,c===t)break;continue}if(c.pt.x<=e.x||c.prev.pt.x<=e.x)if(c.prev.pt.x<e.x&&c.pt.x<e.x)s=1-s;else{let i=d1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return v1.IsOn;i<0===a&&(s=1-s)}a=!a,c=c.next}if(a===r)return s===0?v1.IsOutside:v1.IsInside;{let i=d1.crossProductSign(c.prev.pt,c.pt,e);if(i===0)return v1.IsOn;i<0===a&&(s=1-s)}return s===0?v1.IsOutside:v1.IsInside}getCleanPath(e){let t=[],c=e;for(;c.next!==e&&(c.pt.x===c.next.pt.x&&c.pt.x===c.prev.pt.x||c.pt.y===c.next.pt.y&&c.pt.y===c.prev.pt.y);)c=c.next;t.push(c.pt);let a=c;for(c=c.next;c!==e;)(c.pt.x!==c.next.pt.x||c.pt.x!==a.pt.x)&&(c.pt.y!==c.next.pt.y||c.pt.y!==a.pt.y)&&(t.push(c.pt),a=c),c=c.next;return t}moveSplits(e,t){if(e.splits!==null){t.splits===null&&(t.splits=[]);for(let c of e.splits)c!==t.idx&&t.splits.push(c);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;if(!this.adjustCurrXAndCopyToSEL(e))return this.curXValidAtTop=!0,!1;let t=this.sel;for(;t!==null&&t.jump!==null;){let c=null;for(;t!==null&&t.jump!==null;){let a=t,r=t.jump,s=r,i=r?.jump||null;for(t.jump=i;t!==s&&r!==i;)if(r.curX<t.curX){let o=r.prevInSEL;for(;this.addNewIntersectNode(o,r,e),o!==t;)o=o.prevInSEL;if(o=r,r=this.extractFromSEL(o),s=r,t!==null&&this.insert1Before2InSEL(o,t),t!==a)continue;a=o,a.jump=i,c===null?this.sel=a:c.jump=a}else t=t.nextInSEL;c=a,t=i}t=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort(m8);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let c=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[c]);)c++;[this.intersectList[c],this.intersectList[e]]=[this.intersectList[e],this.intersectList[c]]}let t=this.intersectList[e];this.intersectEdges(t.edge1,t.edge2,t.pt),this.swapPositionsInAEL(t.edge1,t.edge2),t.edge1.curX=t.pt.x,t.edge2.curX=t.pt.x,this.checkJoinLeft(t.edge2,t.pt,!0),this.checkJoinRight(t.edge1,t.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(e){let t=this.actives;this.sel=t;let c=Number.NEGATIVE_INFINITY,a=!1;for(;t!==null;){t.prevInSEL=t.prevInAEL,t.nextInSEL=t.nextInAEL,t.jump=t.nextInSEL;let r=H.topX(t,e);t.curX=r,r<c&&(a=!0),c=r,t=t.nextInAEL}return a}doMaxima(e){let t=e.prevInAEL,c=e.nextInAEL;if(H.isOpenEnd(e))return H.isHotEdge(e)&&this.addOutPt(e,e.top),H.isHorizontal(e)||(H.isHotEdge(e)&&(H.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null),this.deleteFromAEL(e)),c;let a=H.getMaximaPair(e);if(a===null)return c;for(this.isJoined(e)&&this.split(e,e.top),this.isJoined(a)&&this.split(a,a.top);c!==a;)this.intersectEdges(e,c,e.top),this.swapPositionsInAEL(e,c),c=e.nextInAEL;return H.isOpen(e)?(H.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(a),this.deleteFromAEL(e),t!==null?t.nextInAEL:this.actives):(H.isHotEdge(e)&&this.addLocalMaxPoly(e,a,e.top),this.deleteFromAEL(e),this.deleteFromAEL(a),t!==null?t.nextInAEL:this.actives)}updateEdgeIntoAEL(e){if(e.bot=e.top,e.vertexTop=H.nextVertex(e),e.top=e.vertexTop.pt,e.curX=e.bot.x,H.setDx(e),this.isJoined(e)&&this.split(e,e.bot),H.isHorizontal(e)){H.openPathsEnabled?H.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,t){let c=!1,a=H.nextVertex(e).pt;for(;a.y===e.top.y&&!(t&&a.x<e.top.x!=e.bot.x<e.top.x||(e.vertexTop=H.nextVertex(e),e.top=a,c=!0,H.isMaximaVertex(e.vertexTop)));)a=H.nextVertex(e).pt;c&&H.setDx(e)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new Z3(e))}addNewIntersectNode(e,t,c){let a=d1.getLineIntersectPt(e.bot,e.top,t.bot,t.top);if(a===null&&(a={x:e.curX,y:c}),a.y>this.currentBotY||a.y<c){let s=Math.abs(e.dx),i=Math.abs(t.dx);s>100&&i>100?s>i?a=d1.getClosestPtOnSegment(a,e.bot,e.top):a=d1.getClosestPtOnSegment(a,t.bot,t.top):s>100?a=d1.getClosestPtOnSegment(a,e.bot,e.top):i>100?a=d1.getClosestPtOnSegment(a,t.bot,t.top):(a.y<c?a.y=c:a.y=this.currentBotY,s<i?a.x=H.topX(e,a.y):a.x=H.topX(t,a.y))}let r=Ce(a,e,t);this.intersectList.push(r)}extractFromSEL(e){let t=e.nextInSEL;return t!==null&&(t.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=t,t}insert1Before2InSEL(e,t){e.prevInSEL=t.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=t,t.prevInSEL=e}getCurrYMaximaVertexOpen(e){let t=e.vertexTop;if(e.windDx>0)for(;t.next.pt.y===t.pt.y&&(t.flags&(y1.OpenEnd|y1.LocalMax))===y1.None;)t=t.next;else for(;t.prev.pt.y===t.pt.y&&(t.flags&(y1.OpenEnd|y1.LocalMax))===y1.None;)t=t.prev;return H.isMaximaVertex(t)||(t=null),t}getCurrYMaximaVertex(e){let t=e.vertexTop;if(e.windDx>0)for(;t.next.pt.y===t.pt.y;)t=t.next;else for(;t.prev.pt.y===t.pt.y;)t=t.prev;return H.isMaximaVertex(t)||(t=null),t}resetHorzDirection(e,t){if(e.bot.x===e.top.x){let c=e.curX,a=e.curX,r=e.nextInAEL;for(;r!==null&&r.vertexTop!==t;)r=r.nextInAEL;return{isLeftToRight:r!==null,leftX:c,rightX:a}}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 t=e.outrec;return e===t.frontEdge?t.pts:t.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 t=this.actives;for(;t.nextInAEL!==null&&this.isValidAelOrder(t.nextInAEL,e);)t=t.nextInAEL;t.joinWith===p0.Right&&(t=t.nextInAEL),e.nextInAEL=t.nextInAEL,t.nextInAEL!==null&&(t.nextInAEL.prevInAEL=e),e.prevInAEL=t,t.nextInAEL=e}}insertRightEdge(e,t){t.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=t),t.prevInAEL=e,e.nextInAEL=t}setWindCountForOpenPathEdge(e){let t=this.actives;if(this.fillrule===g1.EvenOdd){let c=0,a=0;for(;t!==e;)H.getPolyType(t)===r0.Clip?a++:H.isOpen(t)||c++,t=t.nextInAEL;e.windCount=H.isOdd(c)?1:0,e.windCount2=H.isOdd(a)?1:0}else for(;t!==e;)H.getPolyType(t)===r0.Clip?e.windCount2+=t.windDx:H.isOpen(t)||(e.windCount+=t.windDx),t=t.nextInAEL}setWindCountForClosedPathEdge(e){let t=e.prevInAEL,c=H.getPolyType(e);if(!H.openPathsEnabled){for(;t!==null&&H.getPolyType(t)!==c;)t=t.prevInAEL;if(t===null?(e.windCount=e.windDx,t=this.actives):this.fillrule===g1.EvenOdd?(e.windCount=e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL):(t.windCount*t.windDx<0?Math.abs(t.windCount)>1?t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx:e.windCount=e.windDx:t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL),this.fillrule===g1.EvenOdd)for(;t!==e;)H.getPolyType(t)!==c&&(e.windCount2=e.windCount2===0?1:0),t=t.nextInAEL;else for(;t!==e;)H.getPolyType(t)!==c&&(e.windCount2+=t.windDx),t=t.nextInAEL;return}for(;t!==null&&(H.getPolyType(t)!==c||H.isOpen(t));)t=t.prevInAEL;if(t===null?(e.windCount=e.windDx,t=this.actives):this.fillrule===g1.EvenOdd?(e.windCount=e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL):(t.windCount*t.windDx<0?Math.abs(t.windCount)>1?t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx:e.windCount=H.isOpen(e)?1:e.windDx:t.windDx*e.windDx<0?e.windCount=t.windCount:e.windCount=t.windCount+e.windDx,e.windCount2=t.windCount2,t=t.nextInAEL),this.fillrule===g1.EvenOdd)for(;t!==e;)H.getPolyType(t)!==c&&!H.isOpen(t)&&(e.windCount2=e.windCount2===0?1:0),t=t.nextInAEL;else for(;t!==e;)H.getPolyType(t)!==c&&!H.isOpen(t)&&(e.windCount2+=t.windDx),t=t.nextInAEL}isContributingOpen(e){let t,c;switch(this.fillrule){case g1.Positive:c=e.windCount>0,t=e.windCount2>0;break;case g1.Negative:c=e.windCount<0,t=e.windCount2<0;break;default:c=e.windCount!==0,t=e.windCount2!==0;break}switch(this.cliptype){case C1.Intersection:return t;case C1.Union:return!c&&!t;default:return!t}}isContributingClosed(e){switch(this.fillrule){case g1.Positive:if(e.windCount!==1)return!1;break;case g1.Negative:if(e.windCount!==-1)return!1;break;case g1.NonZero:if(Math.abs(e.windCount)!==1)return!1;break}switch(this.cliptype){case C1.Intersection:return this.fillrule===g1.Positive?e.windCount2>0:this.fillrule===g1.Negative?e.windCount2<0:e.windCount2!==0;case C1.Union:return this.fillrule===g1.Positive?e.windCount2<=0:this.fillrule===g1.Negative?e.windCount2>=0:e.windCount2===0;case C1.Difference:{let t=this.fillrule===g1.Positive?e.windCount2<=0:this.fillrule===g1.Negative?e.windCount2>=0:e.windCount2===0;return H.getPolyType(e)===r0.Subject?t:!t}case C1.Xor:return!0;default:return!1}}addLocalMinPoly(e,t,c,a=!1){let r=this.newOutRec();if(e.outrec=r,t.outrec=r,H.isOpen(e))r.owner=null,r.isOpen=!0,e.windDx>0?this.setSides(r,e,t):this.setSides(r,t,e);else{r.isOpen=!1;let i=H.getPrevHotEdge(e);i!==null?(this.usingPolytree&&this.setOwner(r,i.outrec),r.owner=i.outrec,this.outrecIsAscending(i)===a?this.setSides(r,t,e):this.setSides(r,e,t)):(r.owner=null,a?this.setSides(r,e,t):this.setSides(r,t,e))}let s=new a2(c,r);return r.pts=s,s}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new X3;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,t){let c=this.newOutRec();c.isOpen=!0,e.windDx>0?(c.frontEdge=e,c.backEdge=null):(c.frontEdge=null,c.backEdge=e),e.outrec=c;let a=new a2(t,c);return c.pts=a,a}checkJoinLeft(e,t,c=!1){let a=e.prevInAEL;a!==null&&(!c&&e.curX!==a.curX||!H.isHotEdge(e)||!H.isHotEdge(a)||H.isHorizontal(e)||H.isHorizontal(a)||H.isOpen(e)||H.isOpen(a)||(t.y<e.top.y+2||t.y<a.top.y+2)&&(e.bot.y>t.y||a.bot.y>t.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(t,a.bot,a.top)||d1.isCollinear(e.top,t,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(a,e,t):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),a.joinWith=p0.Right,e.joinWith=p0.Left))}checkJoinRight(e,t,c=!1){let a=e.nextInAEL;a!==null&&(!c&&e.curX!==a.curX||!H.isHotEdge(e)||!H.isHotEdge(a)||H.isHorizontal(e)||H.isHorizontal(a)||H.isOpen(e)||H.isOpen(a)||(t.y<e.top.y+2||t.y<a.top.y+2)&&(e.bot.y>t.y||a.bot.y>t.y)||c&&this.perpendicDistFromLineSqrdGreaterThanQuarter(t,a.bot,a.top)||d1.isCollinear(e.top,t,a.top)&&(e.outrec.idx===a.outrec.idx?this.addLocalMaxPoly(e,a,t):e.outrec.idx<a.outrec.idx?this.joinOutrecPaths(e,a):this.joinOutrecPaths(a,e),e.joinWith=p0.Right,a.joinWith=p0.Left))}perpendicDistFromLineSqrdGreaterThanQuarter(e,t,c){let a=e.x-t.x,r=e.y-t.y,s=c.x-t.x,i=c.y-t.y;if(s===0&&i===0)return!1;let o=d1.maxCoordForSafeCrossSq;if(Math.abs(a)<o&&Math.abs(r)<o&&Math.abs(s)<o&&Math.abs(i)<o){let h=a*i-s*r;return h*h/(s*s+i*i)>.25}if(Number.isSafeInteger(a)&&Number.isSafeInteger(r)&&Number.isSafeInteger(s)&&Number.isSafeInteger(i)){let h=BigInt(a)*BigInt(i)-BigInt(s)*BigInt(r),f=h*h,u=BigInt(s)*BigInt(s)+BigInt(i)*BigInt(i);return Se*f>u}let l=a*i-s*r;return l*l/(s*s+i*i)>.25}intersectEdges(e,t,c){let a;if(this.hasOpenPaths&&(H.isOpen(e)||H.isOpen(t))){if(H.isOpen(e)&&H.isOpen(t))return;if(H.isOpen(t)){let l=e;e=t,t=l}if(this.isJoined(t)&&this.split(t,c),this.cliptype===C1.Union){if(!H.isHotEdge(t))return}else if(t.localMin.polytype===r0.Subject)return;switch(this.fillrule){case g1.Positive:if(t.windCount!==1)return;break;case g1.Negative:if(t.windCount!==-1)return;break;default:if(Math.abs(t.windCount)!==1)return;break}if(H.isHotEdge(e))a=this.addOutPt(e,c),this.setZ(e,t,a.pt),H.isFront(e)?e.outrec.frontEdge=null:e.outrec.backEdge=null,e.outrec=null;else if(c.x===e.localMin.vertex.pt.x&&c.y===e.localMin.vertex.pt.y&&!H.isOpenEndVertex(e.localMin.vertex)){let l=this.findEdgeWithMatchingLocMin(e);if(l!==null&&H.isHotEdge(l)){e.outrec=l.outrec,e.windDx>0?this.setSides(l.outrec,e,l):this.setSides(l.outrec,l,e);return}a=this.startOpenPath(e,c)}else a=this.startOpenPath(e,c);this.setZ(e,t,a.pt);return}this.isJoined(e)&&this.split(e,c),this.isJoined(t)&&this.split(t,c);let r,s;switch(e.localMin.polytype===t.localMin.polytype?this.fillrule===g1.EvenOdd?(r=e.windCount,e.windCount=t.windCount,t.windCount=r):(e.windCount+t.windDx===0?e.windCount=-e.windCount:e.windCount+=t.windDx,t.windCount-e.windDx===0?t.windCount=-t.windCount:t.windCount-=e.windDx):(this.fillrule!==g1.EvenOdd?e.windCount2+=t.windDx:e.windCount2=e.windCount2===0?1:0,this.fillrule!==g1.EvenOdd?t.windCount2-=e.windDx:t.windCount2=t.windCount2===0?1:0),this.fillrule){case g1.Positive:r=e.windCount,s=t.windCount;break;case g1.Negative:r=-e.windCount,s=-t.windCount;break;default:r=Math.abs(e.windCount),s=Math.abs(t.windCount);break}let i=r===0||r===1,o=s===0||s===1;if(!(!H.isHotEdge(e)&&!i||!H.isHotEdge(t)&&!o))if(H.isHotEdge(e)&&H.isHotEdge(t))if(r!==0&&r!==1||s!==0&&s!==1||e.localMin.polytype!==t.localMin.polytype&&this.cliptype!==C1.Xor)a=this.addLocalMaxPoly(e,t,c),a&&this.setZ(e,t,a.pt);else if(H.isFront(e)||e.outrec===t.outrec){a=this.addLocalMaxPoly(e,t,c),a&&this.setZ(e,t,a.pt);let l=this.addLocalMinPoly(e,t,c);this.setZ(e,t,l.pt)}else{a=this.addOutPt(e,c),this.setZ(e,t,a.pt);let l=this.addOutPt(t,c);this.setZ(e,t,l.pt),this.swapOutrecs(e,t)}else if(H.isHotEdge(e))a=this.addOutPt(e,c),this.setZ(e,t,a.pt),this.swapOutrecs(e,t);else if(H.isHotEdge(t))a=this.addOutPt(t,c),this.setZ(e,t,a.pt),this.swapOutrecs(e,t);else{let l,h;switch(this.fillrule){case g1.Positive:l=e.windCount2,h=t.windCount2;break;case g1.Negative:l=-e.windCount2,h=-t.windCount2;break;default:l=Math.abs(e.windCount2),h=Math.abs(t.windCount2);break}if(!H.isSamePolyType(e,t))a=this.addLocalMinPoly(e,t,c),this.setZ(e,t,a.pt);else if(r===1&&s===1){switch(a=null,this.cliptype){case C1.Union:if(l>0&&h>0)return;a=this.addLocalMinPoly(e,t,c);break;case C1.Difference:(H.getPolyType(e)===r0.Clip&&l>0&&h>0||H.getPolyType(e)===r0.Subject&&l<=0&&h<=0)&&(a=this.addLocalMinPoly(e,t,c));break;case C1.Xor:a=this.addLocalMinPoly(e,t,c);break;default:if(l<=0||h<=0)return;a=this.addLocalMinPoly(e,t,c);break}a&&this.setZ(e,t,a.pt)}}}swapPositionsInAEL(e,t){let c=t.nextInAEL;c!==null&&(c.prevInAEL=e);let a=e.prevInAEL;a!==null&&(a.nextInAEL=t),t.prevInAEL=a,t.nextInAEL=e,e.prevInAEL=t,e.nextInAEL=c,t.prevInAEL===null&&(this.actives=t)}isValidAelOrder(e,t){if(t.curX!==e.curX)return t.curX>e.curX;let c=d1.crossProductSign(e.top,t.bot,t.top);if(c!==0)return c<0;if(!H.isMaximaEdge(e)&&e.top.y>t.top.y)return d1.crossProductSign(t.bot,e.top,H.nextVertex(e).pt)<=0;if(!H.isMaximaEdge(t)&&t.top.y>e.top.y)return d1.crossProductSign(t.bot,t.top,H.nextVertex(t).pt)>=0;let a=t.bot.y,r=t.isLeftBound;return e.bot.y!==a||e.localMin.vertex.pt.y!==a?t.isLeftBound:e.isLeftBound!==r?r:d1.isCollinear(H.prevPrevVertex(e).pt,e.bot,e.top)?!0:d1.crossProductSign(H.prevPrevVertex(e).pt,t.bot,H.prevPrevVertex(t).pt)>0===r}isJoined(e){return e.joinWith!==p0.None}split(e,t){e.joinWith===p0.Right?(e.joinWith=p0.None,e.nextInAEL.joinWith=p0.None,this.addLocalMinPoly(e,e.nextInAEL,t,!0)):(e.joinWith=p0.None,e.prevInAEL.joinWith=p0.None,this.addLocalMinPoly(e.prevInAEL,e,t,!0))}setSides(e,t,c){e.frontEdge=t,e.backEdge=c}findEdgeWithMatchingLocMin(e){let t=e.nextInAEL;for(;t!==null;){if(t.localMin?.equals(e.localMin))return t;!H.isHorizontal(t)&&!(e.bot.x===t.bot.x&&e.bot.y===t.bot.y)?t=null:t=t.nextInAEL}for(t=e.prevInAEL;t!==null;){if(t.localMin?.equals(e.localMin))return t;if(!H.isHorizontal(t)&&!(e.bot.x===t.bot.x&&e.bot.y===t.bot.y))return null;t=t.prevInAEL}return t}addOutPt(e,t){let c=e.outrec,a=H.isFront(e),r=c.pts,s=r.next;if(a&&t.x===r.pt.x&&t.y===r.pt.y)return r;if(!a&&t.x===s.pt.x&&t.y===s.pt.y)return s;let i=new a2(t,c);return s.prev=i,i.prev=r,i.next=s,r.next=i,a&&(c.pts=i),i}addLocalMaxPoly(e,t,c){if(this.isJoined(e)&&this.split(e,c),this.isJoined(t)&&this.split(t,c),H.isFront(e)===H.isFront(t))if(H.isOpenEnd(e))this.swapFrontBackSides(e.outrec);else if(H.isOpenEnd(t))this.swapFrontBackSides(t.outrec);else return this.succeeded=!1,null;let a=this.addOutPt(e,c);if(e.outrec===t.outrec){let r=e.outrec;if(r.pts=a,this.usingPolytree){let s=H.getPrevHotEdge(e);s===null?r.owner=null:this.setOwner(r,s.outrec)}this.uncoupleOutRec(e)}else H.isOpen(e)?e.windDx<0?this.joinOutrecPaths(e,t):this.joinOutrecPaths(t,e):e.outrec.idx<t.outrec.idx?this.joinOutrecPaths(e,t):this.joinOutrecPaths(t,e);return a}swapFrontBackSides(e){let t=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=t,e.pts=e.pts.next}setOwner(e,t){for(;t.owner!==null&&t.owner.pts===null;)t.owner=t.owner.owner;let c=t;for(;c!==null&&c!==e;)c=c.owner;c!==null&&(t.owner=e.owner),e.owner=t}uncoupleOutRec(e){let t=e.outrec;t!==null&&(t.frontEdge.outrec=null,t.backEdge.outrec=null,t.frontEdge=null,t.backEdge=null)}joinOutrecPaths(e,t){let c=e.outrec.pts,a=t.outrec.pts,r=c.next,s=a.next;H.isFront(e)?(s.prev=c,c.next=s,a.next=r,r.prev=a,e.outrec.pts=a,e.outrec.frontEdge=t.outrec.frontEdge,e.outrec.frontEdge!==null&&(e.outrec.frontEdge.outrec=e.outrec)):(r.prev=a,a.next=r,c.next=s,s.prev=c,e.outrec.backEdge=t.outrec.backEdge,e.outrec.backEdge!==null&&(e.outrec.backEdge.outrec=e.outrec)),t.outrec.frontEdge=null,t.outrec.backEdge=null,t.outrec.pts=null,this.setOwner(t.outrec,e.outrec),H.isOpenEnd(e)&&(t.outrec.pts=e.outrec.pts,e.outrec.pts=null),e.outrec=null,t.outrec=null}swapOutrecs(e,t){let c=e.outrec,a=t.outrec;if(c===a){let r=c.frontEdge;c.frontEdge=c.backEdge,c.backEdge=r;return}c!==null&&(e===c.frontEdge?c.frontEdge=t:c.backEdge=t),a!==null&&(t===a.frontEdge?a.frontEdge=e:a.backEdge=e),e.outrec=a,t.outrec=c}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,t){return Math.abs(e.x-t.x)<2&&Math.abs(e.y-t.y)<2}static isVerySmallTriangle(e){return e.next.next===e.prev&&(H.ptsReallyClose(e.prev.pt,e.next.pt)||H.ptsReallyClose(e.pt,e.next.pt)||H.ptsReallyClose(e.pt,e.prev.pt))}static buildPath(e,t,c,a){if(e===null||e.next===e||!c&&e.next===e.prev)return!1;a.length=0;let r,s;for(t?(r=e.pt,s=e.prev):(e=e.next,r=e.pt,s=e.next),a.push(r);s!==e;)s.pt.x===r.x&&s.pt.y===r.y||(r=s.pt,a.push(r)),t?s=s.prev:s=s.next;return a.length!==3||c||!H.isVerySmallTriangle(s)}buildPaths(e,t){e.length=0,t.length=0;let c=0;for(;c<this.outrecList.length;){let a=this.outrecList[c++];if(a.pts===null)continue;let r=[];a.isOpen?H.buildPath(a.pts,this.reverseSolution,!0,r)&&t.push(r):(this.cleanCollinear(a),H.buildPath(a.pts,this.reverseSolution,!1,r)&&e.push(r))}return!0}buildTree(e,t){e.clear(),t.length=0;let c=0;for(;c<this.outrecList.length;){let a=this.outrecList[c++];if(a.pts!==null){if(a.isOpen){let r=[];H.buildPath(a.pts,this.reverseSolution,!0,r)&&t.push(r);continue}this.checkBounds(a)&&this.recursiveCheckOwners(a,e)}}}checkBounds(e){return e.pts===null?!1:w2.isEmpty(e.bounds)?(this.cleanCollinear(e),e.pts===null||!H.buildPath(e.pts,this.reverseSolution,!1,e.path)?!1:(e.bounds=d1.getBounds(e.path),!0)):!0}recursiveCheckOwners(e,t){if(!(e.polypath!==null||w2.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,t),e.polypath=e.owner.polypath.addChild(e.path)):e.polypath=t.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 t=e.pts,c=t;for(;;){if(c!==null&&d1.isCollinear(c.prev.pt,c.pt,c.next.pt)&&(c.pt.x===c.prev.pt.x&&c.pt.y===c.prev.pt.y||c.pt.x===c.next.pt.x&&c.pt.y===c.next.pt.y||!this.preserveCollinear||d1.dotProductSign(c.prev.pt,c.pt,c.next.pt)<0)){if(c===e.pts&&(e.pts=c.prev),c=this.disposeOutPt(c),!this.isValidClosedPath(c)){e.pts=null;return}t=c;continue}if(c===null||(c=c.next,c===t))break}this.fixSelfIntersects(e)}isValidClosedPath(e){return e!==null&&e.next!==e&&(e.next!==e.prev||!H.isVerySmallTriangle(e))}disposeOutPt(e){let t=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,t}fixSelfIntersects(e){let t=e.pts;if(t.prev!==t.next.next)for(;;){if(t.next&&t.next.next&&this.boundingBoxesOverlap(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)&&d1.segsIntersect(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)){if((t===e.pts||t.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,t),e.pts===null)return;if(t=e.pts,t.prev===t.next.next)break;continue}if(t=t.next,t===e.pts)break}}doSplitOp(e,t){let c=t.prev,a=t.next.next;e.pts=c;let r=d1.getLineIntersectPt(c.pt,t.pt,t.next.pt,a.pt);this.zCallbackInternal&&this.zCallbackInternal(c.pt,t.pt,t.next.pt,a.pt,r);let s=H.areaOutPt(c),i=s<l3?-s:s;if(i<Se){e.pts=null;return}let o=this.areaTriangle(r,t.pt,t.next.pt),l=o<l3?-o:o;if(r.x===c.pt.x&&r.y===c.pt.y||r.x===a.pt.x&&r.y===a.pt.y)a.prev=c,c.next=a;else{let u=new a2(r,e);u.prev=c,u.next=a,a.prev=u,c.next=u}if(!(l>d8)||!(l>i)&&o>l3!=s>l3)return;let h=this.newOutRec();h.owner=e.owner,t.outrec=h,t.next.outrec=h;let f=new a2(r,h);f.prev=t.next,f.next=t,h.pts=f,t.prev=f,t.next.next=f,this.usingPolytree&&(this.path1InsidePath2(c,f)?(h.splits===null&&(h.splits=[]),h.splits.push(e.idx)):(e.splits===null&&(e.splits=[]),e.splits.push(h.idx)))}static areaOutPt(e){let t=d1.maxCoordForSafeAreaProduct,c=0,a=!0,r=e;do{let i=r.prev,o=r.pt;if(Math.abs(i.pt.x)>=t||Math.abs(i.pt.y)>=t||Math.abs(o.x)>=t||Math.abs(o.y)>=t){a=!1;break}c+=(i.pt.y+o.y)*(i.pt.x-o.x),r=r.next}while(r!==e);if(a)return BigInt(Math.round(c));let s=l3;r=e;do{let i=r.prev;if(Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(r.pt.y)&&Number.isSafeInteger(i.pt.x)&&Number.isSafeInteger(r.pt.x)){let o=BigInt(i.pt.y)+BigInt(r.pt.y),l=BigInt(i.pt.x)-BigInt(r.pt.x);s+=o*l}else{let o=i.pt.y+r.pt.y,l=i.pt.x-r.pt.x;s+=BigInt(Math.round(o*l))}r=r.next}while(r!==e);return s}areaTriangle(e,t,c){let a=d1.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<a&&Math.abs(e.y)<a&&Math.abs(t.x)<a&&Math.abs(t.y)<a&&Math.abs(c.x)<a&&Math.abs(c.y)<a){let s=(c.y+e.y)*(c.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+c.y)*(t.x-c.x);return BigInt(Math.round(s))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(c.x)&&Number.isSafeInteger(c.y)){let s=(BigInt(c.y)+BigInt(e.y))*(BigInt(c.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(t.y))*(BigInt(e.x)-BigInt(t.x)),o=(BigInt(t.y)+BigInt(c.y))*(BigInt(t.x)-BigInt(c.x));return s+i+o}let r=(c.y+e.y)*(c.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+c.y)*(t.x-c.x);return BigInt(Math.round(r))}isValidOwner(e,t){for(;t!==null&&t!==e;)t=t.owner;return t===null}containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom}checkSplitOwner(e,t){for(let c=0;c<t.length;c++){let a=this.outrecList[t[c]];if(a.pts===null&&a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(a=this.getRealOutRec(a),!(a===null||a===e||a.recursiveSplit===e)){if(a.recursiveSplit=e,a.splits!==null&&this.checkSplitOwner(e,a.splits))return!0;if(!(!this.checkBounds(a)||!this.containsRect(a.bounds,e.bounds)||!this.path1InsidePath2(e.pts,a.pts)))return this.isValidOwner(e,a)||(a.owner=e.owner),e.owner=a,!0}}return!1}};q(H,"openPathsEnabled",!0);var J3=H,X0=class extends J3{constructor(){super(...arguments);q(this,"zCallback")}getZCallback(){return this.zCallback}addPath(t,c,a=!1){super.addPath(t,c,a)}addReuseableData(t){super.addReuseableData(t)}addPaths(t,c,a=!1){super.addPaths(t,c,a)}addSubject(t){this.addPaths(t,r0.Subject)}addOpenSubject(t){this.addPaths(t,r0.Subject,!0)}addClip(t){this.addPaths(t,r0.Clip)}execute(t,c,a,r){if(Array.isArray(a)){let s=a,i=r;s.length=0,i&&(i.length=0);try{this.executeInternal(t,c),this.buildPaths(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let s=a,i=r;s.clear(),i&&(i.length=0),this.usingPolytree=!0;try{this.executeInternal(t,c),this.buildTree(s,i||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}};var K5={area(n){return d1.area(n)},areaD(n){let e=0,t=n.length;if(t<3)return 0;let c=n[t-1];for(let a of n)e+=(c.y+a.y)*(c.x-a.x),c=a;return e*.5},scalePath64(n,e){let t=d1.maxSafeCoordinateForScale(e),c=[];for(let a of n)d1.checkSafeScaleValue(a.x,t,"scalePath64"),d1.checkSafeScaleValue(a.y,t,"scalePath64"),c.push({x:Math.round(a.x*e),y:Math.round(a.y*e)});return c},scalePaths64(n,e){let t=[];for(let c of n)t.push(K5.scalePath64(c,e));return t},scalePathD(n,e){let t=[];for(let c of n)t.push({x:c.x*e,y:c.y*e});return t},scalePathsD(n,e){let t=[];for(let c of n)t.push(K5.scalePathD(c,e));return t}};var m0;(function(n){n[n.Miter=0]="Miter",n[n.Square=1]="Square",n[n.Bevel=2]="Bevel",n[n.Round=3]="Round"})(m0||(m0={}));var D1;(function(n){n[n.Polygon=0]="Polygon",n[n.Joined=1]="Joined",n[n.Butt=2]="Butt",n[n.Square=3]="Square",n[n.Round=4]="Round"})(D1||(D1={}));var J5=class{constructor(e,t,c=D1.Polygon){q(this,"inPaths");q(this,"joinType");q(this,"endType");q(this,"pathsReversed");q(this,"lowestPathIdx");this.joinType=t,this.endType=c;let a=c===D1.Polygon||c===D1.Joined;this.inPaths=[];for(let r of e)this.inPaths.push(z2.stripDuplicates(r,a));if(c===D1.Polygon){let r=z2.getLowestPathInfo(this.inPaths);this.lowestPathIdx=r.idx,this.pathsReversed=this.lowestPathIdx>=0&&r.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},_1=class _1{constructor(e=2,t=0,c=!1,a=!1){q(this,"groupList",[]);q(this,"pathOut",[]);q(this,"normals",[]);q(this,"solution",[]);q(this,"solutionTree",null);q(this,"groupDelta",0);q(this,"delta",0);q(this,"mitLimSqr",0);q(this,"stepsPerRad",0);q(this,"stepSin",0);q(this,"stepCos",0);q(this,"joinType",m0.Bevel);q(this,"endType",D1.Polygon);q(this,"arcTolerance",0);q(this,"mergeGroups",!0);q(this,"miterLimit",2);q(this,"preserveCollinear",!1);q(this,"reverseSolution",!1);q(this,"zCallback");q(this,"deltaCallback",null);q(this,"ZCB",(e,t,c,a,r)=>{(e.z||0)!==0&&(e.z===c.z||e.z===a.z)?r.z=e.z:(c.z||0)!==0&&c.z===t.z?r.z=c.z:(t.z||0)!==0&&t.z===a.z?r.z=t.z:this.zCallback&&this.zCallback(e,t,c,a,r)});this.miterLimit=e,this.arcTolerance=t,this.mergeGroups=!0,this.preserveCollinear=c,this.reverseSolution=a}clear(){this.groupList.length=0}addPath(e,t,c){if(e.length===0)return;let a=[e];this.addPaths(a,t,c)}addPaths(e,t,c){e.length!==0&&this.groupList.push(new J5(e,t,c))}calcSolutionCapacity(){let e=0;for(let t of this.groupList)e+=t.endType===D1.Joined?t.inPaths.length*2:t.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let t of this.groupList)if(t.endType===D1.Polygon){e=t.pathsReversed;break}return e}executeInternal(e){if(this.groupList.length===0)return;if(Math.abs(e)<.5){for(let r of this.groupList)for(let s of r.inPaths)this.solution.push(s);return}this.delta=e,this.mitLimSqr=this.miterLimit<=1?2:2/_1.sqr(this.miterLimit);for(let r of this.groupList)this.doGroupOffset(r);if(this.groupList.length===0)return;let t=this.checkPathsReversed(),c=t?g1.Negative:g1.Positive,a=new X0;a.preserveCollinear=this.preserveCollinear,a.reverseSolution=this.reverseSolution!==t,a.zCallback=this.ZCB,a.addSubject(this.solution),this.solutionTree!==null?a.execute(C1.Union,c,this.solutionTree):a.execute(C1.Union,c,this.solution)}execute(e,t){if(Array.isArray(t)){let c=t;c.length=0,this.solution=c,this.executeInternal(e)}else{let c=t;c.clear(),this.solutionTree=c,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,t){this.deltaCallback=e,this.execute(1,t)}static getUnitNormal(e,t){let c=t.x-e.x,a=t.y-e.y;if(c===0&&a===0)return{x:0,y:0};let r=1/Math.sqrt(c*c+a*a);return{x:a*r,y:-c*r}}static getLowestPathInfo(e){let t=-1,c=!1,a={x:Number.MAX_SAFE_INTEGER,y:Number.MIN_SAFE_INTEGER};for(let r=0;r<e.length;++r){let s=Number.MAX_VALUE;for(let i of e[r])if(!(i.y<a.y||i.y===a.y&&i.x>=a.x)){if(s===Number.MAX_VALUE){if(s=_1.area(e[r]),s===0)break;c=s<0}t=r,a.x=i.x,a.y=i.y}}return{idx:t,isNegArea:c}}static translatePoint(e,t,c){return{x:e.x+t,y:e.y+c,z:e.z}}static reflectPoint(e,t){return{x:t.x+(t.x-e.x),y:t.y+(t.y-e.y),z:e.z}}static almostZero(e,t=.001){return Math.abs(e)<t}static hypotenuse(e,t){return Math.sqrt(e*e+t*t)}static normalizeVector(e){let t=_1.hypotenuse(e.x,e.y);if(_1.almostZero(t))return{x:0,y:0};let c=1/t;return{x:e.x*c,y:e.y*c}}static getAvgUnitVector(e,t){return _1.normalizeVector({x:e.x+t.x,y:e.y+t.y})}static intersectPoint(e,t,c,a){if(d1.isAlmostZero(e.x-t.x)){if(d1.isAlmostZero(c.x-a.x))return{x:0,y:0};let r=(a.y-c.y)/(a.x-c.x),s=c.y-r*c.x;return{x:e.x,y:r*e.x+s}}if(d1.isAlmostZero(c.x-a.x)){let r=(t.y-e.y)/(t.x-e.x),s=e.y-r*e.x;return{x:c.x,y:r*c.x+s}}else{let r=(t.y-e.y)/(t.x-e.x),s=e.y-r*e.x,i=(a.y-c.y)/(a.x-c.x),o=c.y-i*c.x;if(d1.isAlmostZero(r-i))return{x:0,y:0};let l=(o-s)/(r-i);return{x:l,y:r*l+s}}}getPerpendic(e,t){return{x:Math.round(e.x+t.x*this.groupDelta),y:Math.round(e.y+t.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,t){return{x:e.x+t.x*this.groupDelta,y:e.y+t.y*this.groupDelta,z:e.z||0}}doBevel(e,t,c){let a,r,s=e[t].z||0;if(t===c){let i=Math.abs(this.groupDelta);a={x:Math.round(e[t].x-i*this.normals[t].x),y:Math.round(e[t].y-i*this.normals[t].y),z:s},r={x:Math.round(e[t].x+i*this.normals[t].x),y:Math.round(e[t].y+i*this.normals[t].y),z:s}}else a={x:Math.round(e[t].x+this.groupDelta*this.normals[c].x),y:Math.round(e[t].y+this.groupDelta*this.normals[c].y),z:s},r={x:Math.round(e[t].x+this.groupDelta*this.normals[t].x),y:Math.round(e[t].y+this.groupDelta*this.normals[t].y),z:s};this.pathOut.push(a),this.pathOut.push(r)}doSquare(e,t,c){let a;t===c?a={x:this.normals[t].y,y:-this.normals[t].x}:a=_1.getAvgUnitVector({x:-this.normals[c].y,y:this.normals[c].x},{x:this.normals[t].y,y:-this.normals[t].x});let r=Math.abs(this.groupDelta),s={x:e[t].x,y:e[t].y,z:e[t].z||0};s=_1.translatePoint(s,r*a.x,r*a.y);let i=_1.translatePoint(s,this.groupDelta*a.y,this.groupDelta*-a.x),o=_1.translatePoint(s,this.groupDelta*-a.y,this.groupDelta*a.x),l=this.getPerpendicD(e[c],this.normals[c]);if(t===c){let h={x:l.x+a.x*this.groupDelta,y:l.y+a.y*this.groupDelta},f=_1.intersectPoint(i,o,l,h);f.z=s.z,this.pathOut.push(W0.fromPointD(_1.reflectPoint(f,s))),this.pathOut.push(W0.fromPointD(f))}else{let h=this.getPerpendicD(e[t],this.normals[c]),f=_1.intersectPoint(i,o,l,h);f.z=s.z,this.pathOut.push(W0.fromPointD(f)),this.pathOut.push(W0.fromPointD(_1.reflectPoint(f,s)))}}doMiter(e,t,c,a){let r=this.groupDelta/(a+1);this.pathOut.push({x:Math.round(e[t].x+(this.normals[c].x+this.normals[t].x)*r),y:Math.round(e[t].y+(this.normals[c].y+this.normals[t].y)*r),z:e[t].z||0})}doRound(e,t,c,a){if(this.deltaCallback!==null){let l=Math.abs(this.groupDelta),h=this.arcTolerance>.01?this.arcTolerance:l*_1.arc_const,f=Math.PI/Math.acos(1-h/l);this.stepSin=Math.sin(2*Math.PI/f),this.stepCos=Math.cos(2*Math.PI/f),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=f/(2*Math.PI)}let r=e[t],s=r.z||0,i={x:this.normals[c].x*this.groupDelta,y:this.normals[c].y*this.groupDelta};t===c&&W3.negate(i),this.pathOut.push({x:Math.round(r.x+i.x),y:Math.round(r.y+i.y),z:s});let o=Math.ceil(this.stepsPerRad*Math.abs(a));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(r.x+i.x),y:Math.round(r.y+i.y),z:s});this.pathOut.push(this.getPerpendic(e[t],this.normals[t]))}buildNormals(e){let t=e.length;if(this.normals.length=0,t!==0){for(let c=0;c<t-1;c++)this.normals.push(_1.getUnitNormal(e[c],e[c+1]));this.normals.push(_1.getUnitNormal(e[t-1],e[0]))}}offsetPoint(e,t,c,a){if(W0.equals(t[c],t[a]))return;let r=d1.crossProductD(this.normals[c],this.normals[a]),s=d1.dotProductD(this.normals[c],this.normals[a]);if(r>1?r=1:r<-1&&(r=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(t,this.normals,c,a),e.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<_1.Tolerance){this.pathOut.push(t[c]);return}if(s>-.999&&r*this.groupDelta<0)this.pathOut.push(this.getPerpendic(t[c],this.normals[a])),this.pathOut.push(t[c]),this.pathOut.push(this.getPerpendic(t[c],this.normals[c]));else if(s>.999&&this.joinType!==m0.Round)this.doMiter(t,c,a,s);else switch(this.joinType){case m0.Miter:s>this.mitLimSqr-1?this.doMiter(t,c,a,s):this.doSquare(t,c,a);break;case m0.Round:this.doRound(t,c,a,Math.atan2(r,s));break;case m0.Bevel:this.doBevel(t,c,a);break;default:this.doSquare(t,c,a);break}}offsetPolygon(e,t){this.pathOut=[];let c=t.length,a=c-1;for(let r=0;r<c;r++)this.offsetPoint(e,t,r,a),a=r;this.solution.push(this.pathOut)}offsetOpenJoined(e,t){this.offsetPolygon(e,t);let c=[...t].reverse();this.buildNormals(c),this.offsetPolygon(e,c)}offsetOpenPath(e,t){this.pathOut=[];let c=t.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(t,this.normals,0,0)),Math.abs(this.groupDelta)<_1.Tolerance)this.pathOut.push(t[0]);else switch(this.endType){case D1.Butt:this.doBevel(t,0,0);break;case D1.Round:this.doRound(t,0,0,Math.PI);break;default:this.doSquare(t,0,0);break}for(let a=1,r=0;a<c;a++)this.offsetPoint(e,t,a,r),r=a;for(let a=c;a>0;a--)this.normals[a]={x:-this.normals[a-1].x,y:-this.normals[a-1].y};if(this.normals[0]=this.normals[c],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(t,this.normals,c,c)),Math.abs(this.groupDelta)<_1.Tolerance)this.pathOut.push(t[c]);else switch(this.endType){case D1.Butt:this.doBevel(t,c,c);break;case D1.Round:this.doRound(t,c,c,Math.PI);break;default:this.doSquare(t,c,c);break}for(let a=c-1,r=c;a>0;a--)this.offsetPoint(e,t,a,r),r=a;this.solution.push(this.pathOut)}doGroupOffset(e){e.endType===D1.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 t=Math.abs(this.groupDelta);if(this.joinType=e.joinType,this.endType=e.endType,e.joinType===m0.Round||e.endType===D1.Round){let c=this.arcTolerance>.01?this.arcTolerance:t*_1.arc_const,a=Math.PI/Math.acos(1-c/t);this.stepSin=Math.sin(2*Math.PI/a),this.stepCos=Math.cos(2*Math.PI/a),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=a/(2*Math.PI)}for(let c of e.inPaths){this.pathOut=[];let a=c.length;if(a===1){let r=c[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(c,this.normals,0,0),e.pathsReversed&&(this.groupDelta=-this.groupDelta));let s=r.z||0;if(e.endType===D1.Round){let i=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=_1.ellipse(r,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:r.x-i,top:r.y-i,right:r.x+i,bottom:r.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(a===2&&e.endType===D1.Joined&&(this.endType=e.joinType===m0.Round?D1.Round:D1.Square),this.buildNormals(c),this.endType){case D1.Polygon:this.offsetPolygon(e,c);break;case D1.Joined:this.offsetOpenJoined(e,c);break;default:this.offsetOpenPath(e,c);break}}}static stripDuplicates(e,t){let c=e.length,a=[];if(c===0)return a;let r=e[0];a.push(r);for(let s=1;s<c;s++)W0.equals(r,e[s])||(r=e[s],a.push(r));return t&&W0.equals(r,a[0])&&a.pop(),a}static area(e){return d1.area(e)}static sqr(e){return e*e}static ellipse(e,t,c=0,a=0){if(t<=0)return[];c<=0&&(c=t),a<=2&&(a=Math.ceil(Math.PI*Math.sqrt((t+c)/2)));let r=Math.sin(2*Math.PI/a),s=Math.cos(2*Math.PI/a),i=s,o=r,l=[{x:Math.round(e.x+t),y:e.y}];for(let h=1;h<a;++h){l.push({x:Math.round(e.x+t*i),y:Math.round(e.y+c*o)});let f=i*s-o*r;o=o*s+i*r,i=f}return l}};q(_1,"Tolerance",1e-12),q(_1,"arc_const",.002);var z2=_1;var hs=BigInt(2);function e4(n,e,t){return typeof e=="number"?Q5(C1.Union,n,null,e):Q5(C1.Union,n,e,t)}function Q5(n,e,t,c){let a=[];if(e===null)return a;let r=new X0;return r.addPaths(e,r0.Subject),t!==null&&r.addPaths(t,r0.Clip),r.execute(n,c,a),a}function Q3(n,e,t,c,a=2,r=0){let s=new z2(a,r);s.addPaths(n,t,c);let i=[];return s.execute(e,i),i}var _0=1e4;function e0(){return{layers:new Map,parts:[]}}function X1(n,e="cut"){return{layers:new Map([[e,{regions:n,lines:[]}]]),parts:[]}}function Z0(n,e="cut"){return{layers:new Map([[e,{regions:[],lines:n}]]),parts:[]}}function Te(n){if(n.parts.length)return!1;for(let e of n.layers.values())if(e.regions.length||e.lines.length)return!1;return!0}var Ie=n=>n.map(e=>e.map(([t,c])=>({x:Math.round(t*_0),y:Math.round(c*_0)})));function b8(n){let e=(c,a,r)=>(a.x-c.x)*(r.y-a.y)-(a.y-c.y)*(r.x-a.x)===0,t=[];for(let c of n){for(;t.length>=2&&e(t[t.length-2],t[t.length-1],c);)t.pop();let a=t[t.length-1];(!a||a.x!==c.x||a.y!==c.y)&&t.push(c)}for(let c=!0;c&&t.length>=3;){let a=t.length;c=!0,t[a-1].x===t[0].x&&t[a-1].y===t[0].y||e(t[a-2],t[a-1],t[0])?t.pop():e(t[a-1],t[0],t[1])?t.shift():c=!1}return t}var g3=n=>Ie(n).map(b8),v3=n=>n.filter(e=>e.length>=2).map(e=>e.map(t=>[t.x/_0,t.y/_0]));function G(n,e="nonzero"){if(!n.length)return[];let t=e==="evenodd"?g1.EvenOdd:g1.NonZero;return v3(e4(g3(n),t)).filter(c=>c.length>=3)}function t4(n,e,t){if(!e.length)return[];let c=new X0;c.addSubject(g3(e)),t.length&&c.addClip(g3(t));let a=[];return c.execute(n,g1.NonZero,a),v3(a).filter(r=>r.length>=3)}var t0=(n,e)=>e.length?t4(C1.Difference,n,e):G(n),b1=(n,e)=>t4(C1.Intersection,n,e),n4=(n,e)=>t4(C1.Xor,n,e);function s0(n,e,t){if(!n.length)return[];if(!e.length)return t==="outside"?n:[];let c=[];for(let p of e)for(let g=0;g<p.length;g++){let v=p[g],b=p[(g+1)%p.length];(v[0]!==b[0]||v[1]!==b[1])&&c.push([v,b])}if(!c.length)return t==="outside"?n:[];let a=Z1(e),r=Math.max(a[2]-a[0],a[3]-a[1],1e-6)/Math.max(1,Math.sqrt(c.length)),s=p=>Math.floor(p/r),i=new Map,o=new Map,l=(p,g,v)=>{let b=p.get(g);b?b[b.length-1]!==v&&b.push(v):p.set(g,[v])};c.forEach(([p,g],v)=>{let b=Math.max(1,Math.ceil(Math.hypot(g[0]-p[0],g[1]-p[1])/r*2));for(let y=0;y<=b;y++){let x=p[0]+(g[0]-p[0])*y/b,M=p[1]+(g[1]-p[1])*y/b;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 y=s(Math.min(p[1],g[1]));y<=s(Math.max(p[1],g[1]));y++)l(o,y,v)});let h=(p,g)=>{let v=new Set,b=0,y=1;for(let k of[0,1]){let S=g[k]-p[k],A=a[k]-r,z=a[k+2]+r;if(S===0){if(p[k]<A||p[k]>z)return v;continue}let L=(A-p[k])/S,P=(z-p[k])/S;b=Math.max(b,Math.min(L,P)),y=Math.min(y,Math.max(L,P))}if(!(b<=y))return v;let x=[p[0]+(g[0]-p[0])*b,p[1]+(g[1]-p[1])*b],M=[p[0]+(g[0]-p[0])*y,p[1]+(g[1]-p[1])*y],w=Math.max(1,Math.ceil(Math.hypot(M[0]-x[0],M[1]-x[1])/r*2));for(let k=0;k<=w;k++){let S=x[0]+(M[0]-x[0])*k/w,A=x[1]+(M[1]-x[1])*k/w;for(let z of i.get(`${s(S)},${s(A)}`)??[])v.add(z)}return v},f=.5/_0,u=p=>{for(let v of i.get(`${s(p[0])},${s(p[1])}`)??[]){let[b,y]=c[v],x=y[0]-b[0],M=y[1]-b[1],w=Math.max(0,Math.min(1,((p[0]-b[0])*x+(p[1]-b[1])*M)/(x*x+M*M)));if(Math.hypot(p[0]-b[0]-w*x,p[1]-b[1]-w*M)<=f)return}let g=0;for(let v of o.get(s(p[1]))??[]){let[b,y]=c[v],x=(y[0]-b[0])*(p[1]-b[1])-(p[0]-b[0])*(y[1]-b[1]);b[1]<=p[1]?y[1]>p[1]&&x>0&&g++:y[1]<=p[1]&&x<0&&g--}return g!==0},d=p=>Math.round(p*_0)/_0,m=[];for(let p of n){let g=null,v=()=>{g&&g.length>=2&&m.push(g),g=null};for(let b=1;b<p.length;b++){let y=p[b-1],x=p[b],M=x[0]-y[0],w=x[1]-y[1];if(!M&&!w)continue;let k=[0,1];for(let A of h(y,x)){let[z,L]=c[A],P=L[0]-z[0],I=L[1]-z[1],T=M*I-w*P;if(Math.abs(T)>1e-15){let O=((z[0]-y[0])*I-(z[1]-y[1])*P)/T,F=((z[0]-y[0])*w-(z[1]-y[1])*M)/T;O>0&&O<1&&F>=0&&F<=1&&k.push(O)}else{let O=M*M+w*w;for(let F of[z,L]){let D=((F[0]-y[0])*M+(F[1]-y[1])*w)/O,_=Math.abs((F[0]-y[0])*w-(F[1]-y[1])*M)/Math.sqrt(O);D>0&&D<1&&_<=f&&k.push(D)}}}k.sort((A,z)=>A-z);let S=Math.hypot(M,w);for(let A=1;A<k.length;A++){if((k[A]-k[A-1])*S<1e-9||k[A]-k[A-1]<1e-300)continue;let z=[d(y[0]+M*k[A-1]),d(y[1]+w*k[A-1])],L=[d(y[0]+M*k[A]),d(y[1]+w*k[A])],P=(k[A-1]+k[A])/2,I=u([y[0]+M*P,y[1]+w*P]);if(I!==void 0&&I===(t==="inside")){let T=g?g[g.length-1]:void 0;g&&T&&T[0]===z[0]&&T[1]===z[1]?(L[0]!==T[0]||L[1]!==T[1])&&g.push(L):(v(),g=[z,L])}else v()}}v()}return m}function L1(n,e,t="round",c=.01){if(!n.length)return[];if(e===0)return G(n);let a=t==="round"?m0.Round:t==="square"?m0.Square:m0.Miter,r=Q3(g3(G(n)),e*_0,a,D1.Polygon,2,c*_0);return v3(r).filter(s=>s.length>=3)}function R2(n,e){if(!n.length||e<=0)return[];let t=Q3(Ie(n),e/2*_0,m0.Round,D1.Round,2,.01*_0);return v3(t)}function i0(n){if(!n.length)return[];let e=new p3,t=new X0;t.addSubject(g3(n)),t.execute(C1.Union,g1.NonZero,e);let c=[],a=r=>{for(let s=0;s<r.count;s++){let i=r.child(s),o=[i.poly];for(let l=0;l<i.count;l++){let h=i.child(l);o.push(h.poly),a(h)}c.push(v3(o))}};return a(e),c}function b3(n){let e=n.length;if(e<2)return n.map((g,v)=>v);let t=n.map(g=>Z1([g])??[0,0,0,0]),c=n.map(g=>Math.abs(s1(g))),a=(g,v)=>{let b=!1;for(let y=0,x=v.length-1;y<v.length;x=y++){let[M,w]=v[x],[k,S]=v[y];w>g[1]!=S>g[1]&&g[0]<M+(g[1]-w)*(k-M)/(S-w)&&(b=!b)}return b},[r,s,i,o]=[1/0,1/0,-1/0,-1/0];for(let g of t)r=Math.min(r,g[0]),s=Math.min(s,g[1]),i=Math.max(i,g[2]),o=Math.max(o,g[3]);let l=Math.max(1,Math.ceil(Math.sqrt(e))),h=Math.max(i-r,1e-9)/l,f=Math.max(o-s,1e-9)/l,u=(g,v,b)=>Math.min(l-1,Math.max(0,Math.floor((g-v)/b))),d=new Map,m=[];t.forEach((g,v)=>{let[b,y]=[u(g[0],r,h),u(g[2],r,h)],[x,M]=[u(g[1],s,f),u(g[3],s,f)];if((y-b+1)*(M-x+1)>16)return m.push(v);for(let w=b;w<=y;w++)for(let k=x;k<=M;k++){let S=w*l+k,A=d.get(S);A?A.push(v):d.set(S,[v])}});let p=n.map((g,v)=>{let b=t[v];if(!g.length)return 0;let y=g[0],x=0,M=d.get(u(y[0],r,h)*l+u(y[1],s,f))??[];for(let w of[...M,...m]){let k=t[w];w===v||!(c[w]>c[v])||k[0]>b[0]||k[1]>b[1]||k[2]<b[2]||k[3]<b[3]||a(y,n[w])&&x++}return x});return n.map((g,v)=>v).sort((g,v)=>p[v]-p[g]||g-v)}function s1(n){let e=0;for(let t=0,c=n.length-1;t<n.length;c=t++)e+=(n[c][0]+n[t][0])*(n[c][1]-n[t][1]);return-e/2}function q2(n){let e=0,t=0,c=0;for(let a of n){if(a.length<3)continue;let[r,s]=a[0];for(let i=0,o=a.length-1;i<a.length;o=i++){let l=a[o][0]-r,h=a[o][1]-s,f=a[i][0]-r,u=a[i][1]-s,d=l*u-f*h;e+=d/2,t+=(l+f)*d/6+r*d/2,c+=(h+u)*d/6+s*d/2}}return Math.abs(e)<1e-12?{area:0,centroid:[0,0]}:{area:Math.abs(e),centroid:[t/e,c/e]}}function m3(n,[e,t]){return[n[0]*e+n[2]*t+n[4],n[1]*e+n[3]*t+n[5]]}function Pe(n,e){let t=e[0]*e[3]-e[1]*e[2]<0,c=new Map;for(let[a,r]of n)c.set(a,{regions:r.regions.map(s=>{let i=s.map(o=>m3(e,o));return t?i.reverse():i}),lines:r.lines.map(s=>s.map(i=>m3(e,i)))});return c}function k2(n,e){return{layers:Pe(n.layers,e),parts:n.parts.map(t=>({...t,layers:Pe(t.layers,e),...t.bends&&{bends:y8(t,e)},...t.folds&&{folds:t.folds.map(c=>({...c,from:m3(e,c.from),to:m3(e,c.to)}))},...t.hang&&{hang:{...t.hang,at:m3(e,t.hang.at)}}}))}}function y8(n,e){let t=n.bends,[c,,,a,r]=[e[0],e[1],e[2],e[3],e[4]];if(Math.abs(e[1])>1e-9||Math.abs(e[2])>1e-9||!(c!==0&&a!==0))throw new Error(`part "${n.name}" bends along its x, so it can be moved, scaled or mirrored but not turned: turn it with part(rotate = ...) instead`);return t.map(s=>{let[i,o]=s.mirrored?[-s.x1,-s.x0]:[s.x0,s.x1],[l,h]=[c*i+r,c*o+r].sort((m,p)=>m-p),f=!!s.mirrored!=c<0,{mirrored:u,...d}=s;return f?{...d,x0:-h,x1:-l,mirrored:!0}:{...d,x0:l,x1:h}})}function Y0(n){let e=e0();for(let t of n){for(let[c,a]of t.layers){let r=e.layers.get(c)??{regions:[],lines:[]};for(let s of a.regions)r.regions.push(s);for(let s of a.lines)r.lines.push(s);e.layers.set(c,r)}for(let c of t.parts)e.parts.push(c)}return e}var M0="\0hidden";function Ee(n,e){let t={regions:[],lines:[]};for(let[r,s]of n)if(r!==M0){for(let i of s.regions)t.regions.push(i);for(let i of s.lines)t.lines.push(i)}let c=new Map([[e,t]]),a=n.get(M0);return a&&e!==M0&&c.set(M0,a),c}function y3(n,e){if(n.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:Ee(n.layers,e),parts:n.parts.map(t=>({...t,layers:Ee(t.layers,e)}))}}function Z1(n){let e=1/0,t=1/0,c=-1/0,a=-1/0;for(let r of n)for(let[s,i]of r)s<e&&(e=s),i<t&&(t=i),s>c&&(c=s),i>a&&(a=i);return e===1/0?null:[e,t,c,a]}function L0(n,e){let t=[];for(let[c,a]of n)if(!e?.(c))for(let r of[...a.regions,...a.lines])t.push(r);return Z1(t)}function e5(n){let e=[...n].sort((r,s)=>r[0]-s[0]||r[1]-s[1]);if(e.length<3)return e;let t=(r,s,i)=>(s[0]-r[0])*(i[1]-r[1])-(s[1]-r[1])*(i[0]-r[0]),c=[];for(let r of e){for(;c.length>=2&&t(c[c.length-2],c[c.length-1],r)<=0;)c.pop();c.push(r)}let a=[];for(let r=e.length-1;r>=0;r--){let s=e[r];for(;a.length>=2&&t(a[a.length-2],a[a.length-1],s)<=0;)a.pop();a.push(s)}return a.pop(),c.pop(),c.concat(a)}function He(n,e,t,c){return n<1e-9?3:e>0?Math.max(Math.floor(e),3):Math.max(Math.ceil(Math.min(360/t,n*2*Math.PI/c)),5)}function t5(n,e,t){let c=[];for(let a=0;a<t;a++){let r=2*Math.PI*a/t;c.push([n*Math.cos(r),e*Math.sin(r)])}return c}function Ve(n,e,t,c){if(t=Math.min(t,n/2,e/2),t<=0)return[[0,0],[n,0],[n,e],[0,e]];let a=Math.max(1,Math.ceil(c(t)/4)),r=[],s=[[n-t,t,-90],[n-t,e-t,0],[t,e-t,90],[t,t,180]];for(let[i,o,l]of s)for(let h=0;h<=a;h++){let f=(l+90*h/a)*Math.PI/180;r.push([i+t*Math.cos(f),o+t*Math.sin(f)])}return r}function c4(n,e){let t=G(n);for(let c=0;c<100;c++){let a=i0(t);if(a.length<=1)return t;let r=i=>i.reduce((o,l)=>o+s1(l),0);a.sort((i,o)=>r(o)-r(i));let s=[];for(let i=1;i<a.length;i++){let o=1/0,l=[0,0],h=[0,0];for(let[y,x]of a[i][0])for(let M=0;M<a.length;M++)if(M!==i)for(let w of a[M])for(let k=0,S=w.length-1;k<w.length;S=k++){let[A,z]=w[S],[L,P]=w[k],I=L-A,T=P-z,O=I*I+T*T,F=O?Math.max(0,Math.min(1,((y-A)*I+(x-z)*T)/O)):0,D=A+F*I,_=z+F*T,R=Math.hypot(y-D,x-_);R<o&&([o,l,h]=[R,[y,x],[D,_]])}if(!Number.isFinite(o))continue;let f=h[0]-l[0],u=h[1]-l[1],d=Math.hypot(f,u);d<1e-9?[f,u]=[0,1]:[f,u]=[f/d,u/d];let[m,p]=[-u*(e/2),f*(e/2)],g=[l[0]-f*(e/2),l[1]-u*(e/2)],v=[h[0]+f*(e/2),h[1]+u*(e/2)],b=[[g[0]-m,g[1]-p],[v[0]-m,v[1]-p],[v[0]+m,v[1]+p],[g[0]+m,g[1]+p]];s.push(s1(b)<0?b.reverse():b)}if(!s.length)return t;t=G([...t,...s])}return t}function n5(n,e){let t=Math.round(n/e);return t%2===0&&(t+=n/e>t?1:-1),Math.max(3,t)}var x3=(n,e,t,c)=>[[n,e],[t,e],[t,c],[n,c]];function x8(n,e,t,c){if(e==="flat")return[];let a=n5(n,c),r=n/a,s=[];for(let i=0;i<a;i++)(e==="out"?i%2===1:i%2===0)&&s.push(x3(i*r,-1,(i+1)*r,t));return s}function Oe(n,e,t,c,a){let r=[([o,l])=>[o,l],([o,l])=>[n-l,o],([o,l])=>[n-o,e-l],([o,l])=>[l,e-o]],s=[n,e,n,e],i=[];return t.forEach((o,l)=>{for(let h of x8(s[l],o,c,a))i.push(h.map(r[l]))}),t0([x3(0,0,n,e)],i)}function Fe(n,e,t,c){let a=n5(n,c),r=n/a,s=[];for(let i=0;i<a;i++)(e==="out"?i%2===0:i%2===1)&&s.push(x3(i*r,-t/2,(i+1)*r,t/2));return s}function _e(n,e,t,c,a){let r=x3(-n/2,-1,n/2,e),s=x3(-t/2,a,t/2,a+c);return[r,s]}function De(n,e,t,c,a){let r=[],s=a+c,i=Math.floor(n/t),o=(n-i*t)/2;for(let l=0;l<=i;l++){let h=o+l*t,f=l%2===0?c:c-s/2;for(let u=f;u<e;u+=s){let d=Math.max(u,l%2===0?c:0),m=Math.min(u+a,e-(l%2===0?c:0));m-d>=c/2&&r.push([[h,d],[h,m]])}}return r}function M8(n){let e=Math.floor(n)>>>0||2654435769;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}function Re(n){let{spacing:e,step:t,box:c}=n,a=e/2,r=e,s=new Map,i=[],o=[],l=[],h=[],f=[],u=(P,I)=>Math.floor((P-c[0])/r)*1000003+Math.floor((I-c[1])/r),d=(P,I,T)=>{let O=u(P[0],P[1]),F=i.length;i.push(P[0]),o.push(P[1]),l.push(I),h.push(T);let D=s.get(O);D?D.push(F):s.set(O,[F])},m=Math.ceil(2*e/t)+2,p=(P,I,T=-1,O=0)=>{let F=Math.floor((P[0]-c[0])/r),D=Math.floor((P[1]-c[1])/r);for(let _=F-1;_<=F+1;_++)for(let R=D-1;R<=D+1;R++){let U=s.get(_*1000003+R);if(U)for(let N of U){let e1=l[N];if(!(!f[e1]&&e1!==T)&&!(e1===T&&Math.abs(h[N]-O)<m)&&Math.hypot(i[N]-P[0],o[N]-P[1])<I)return!1}}return!0},g=[],v=0,b=Math.ceil(4*(c[2]-c[0]+c[3]-c[1]+e)/t+2*m),y=(P,I)=>{let T=n.dir(P);if(!T)return null;let O=[P[0]+I*T[0]*t/2,P[1]+I*T[1]*t/2],F=n.dir(O)??T;return F[0]*T[0]+F[1]*T[1]<0?null:[P[0]+I*F[0]*t,P[1]+I*F[1]*t]},x=P=>{let I=g.length;f[I]=!1,d(P,I,0);let T=[[],[]];for(let[D,_]of[[0,1],[1,-1]]){let R=P;for(let U=1;U<=b;U++){let N=y(R,_);if(!N)break;let e1=_*U;if(!n.inside(N)){T[D].push(N);break}if(!p(N,a,I,e1))break;if(T[D].push(N),d(N,I,e1),++v>n.maxPoints)throw new Error(`the lines have more than ${n.maxPoints} points: use a larger spacing or step`);n.tick(),R=N}}let O=[...T[1].reverse(),P,...T[0]],F=0;for(let D=1;D<O.length;D++)F+=Math.hypot(O[D][0]-O[D-1][0],O[D][1]-O[D-1][1]);return g.push(O),O.length<2||F<n.minLength?null:(f[I]=!0,O)},M=M8(n.seed),w=[];for(let P=c[0]+e/2;P<c[2];P+=e)for(let I=c[1]+e/2;I<c[3];I+=e)w.push([P+(M()-.5)*e,I+(M()-.5)*e]);for(let P=w.length-1;P>0;P--){let I=Math.floor(M()*(P+1));[w[P],w[I]]=[w[I],w[P]]}let k=[],S=[],A=Math.max(1,Math.round(e/(2*t))),z=P=>{if(!n.inside(P)||!p(P,e)||!n.dir(P))return;let I=x(P);I&&(k.push(I),S.push(I))},L=0;for(;;){for(;S.length;){let P=S.shift();for(let I=0;I<P.length;I+=A){let T=P[Math.max(0,I-1)],O=P[Math.min(P.length-1,I+1)],F=Math.hypot(O[0]-T[0],O[1]-T[1]);if(F===0)continue;let D=-(O[1]-T[1])/F,_=(O[0]-T[0])/F;for(let R of[1,-1])z([P[I][0]+R*D*e,P[I][1]+R*_*e])}}if(L>=w.length)break;z(w[L++])}return k}function qe(n,e,t,c,a,r,s){let i=(g,v)=>n[v*e+g],o=(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=i(b,y),M=g&1?i(b,y+1):i(b+1,y),w=x===M?.5:(s-x)/(M-x);return g&1?[c+b*r,a+(y+w)*r]:[c+(b+w)*r,a+y*r]},f=new Map,u=(g,v)=>{for(let[b,y]of[[g,v],[v,g]]){let x=f.get(b);x?x.push(y):f.set(b,[y])}};for(let g=0;g+1<t;g++)for(let v=0;v+1<e;v++){let b=i(v,g),y=i(v+1,g),x=i(v+1,g+1),M=i(v,g+1);if(Number.isNaN(b+y+x+M))continue;let w=(b>=s?1:0)|(y>=s?2:0)|(x>=s?4:0)|(M>=s?8:0);if(w===0||w===15)continue;let k=o(v,g),S=l(v+1,g),A=o(v,g+1),z=l(v,g);if(w===5||w===10){let P=(b+y+x+M)/4>=s;w===5===P?(u(k,S),u(z,A)):(u(z,k),u(S,A));continue}let L=[];(w&1)!==(w&2)>>1&&L.push(k),(w&2)>>1!==(w&4)>>2&&L.push(S),(w&4)>>2!==(w&8)>>3&&L.push(A),(w&8)>>3!==(w&1)&&L.push(z),L.length===2&&u(L[0],L[1])}let d=new Set,m=g=>{let v=[h(g)];d.add(g);let b=g;for(;;){let y=(f.get(b)??[]).find(x=>!d.has(x));if(y===void 0)return(f.get(b)??[]).includes(g)&&v.length>2&&v.push(v[0]),v;d.add(y),v.push(h(y)),b=y}},p=[];for(let[g,v]of f)v.length===1&&!d.has(g)&&p.push(m(g));for(let g of f.keys())d.has(g)||p.push(m(g));return p.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 $e(n,e=.001){let t=n.filter(l=>l.length>=2).map(l=>[...l]);if(t.length<2)return t;let c=l=>`${Math.round(l[0]/e)},${Math.round(l[1]/e)}`,a=new Map,r=(l,h)=>{let f=c(l),u=a.get(f);u?u.push(h):a.set(f,[h])};t.forEach((l,h)=>{r(l[0],h),r(l[l.length-1],h)});let s=new Array(t.length).fill(!1),i=l=>c(l[0])===c(l[l.length-1]),o=[];for(let l=0;l<t.length;l++){if(s[l])continue;s[l]=!0;let h=t[l];if(!i(h))for(let f=0;f<2;f++){for(;;){let u=h[h.length-1],d=(a.get(c(u))??[]).find(g=>!s[g]);if(d===void 0)break;s[d]=!0;let m=t[d],p=c(m[0])===c(u)?m:[...m].reverse();if(h=h.concat(p.slice(1)),i(h))break}if(i(h))break;h=h.reverse()}o.push(h)}return w8(o)}function w8(n){let e=n.length;if(e<2)return n;let t=1/0,c=1/0,a=-1/0,r=-1/0;for(let p of n)for(let g of[p[0],p[p.length-1]])t=Math.min(t,g[0]),c=Math.min(c,g[1]),a=Math.max(a,g[0]),r=Math.max(r,g[1]);let s=Math.max((a-t+r-c)/Math.sqrt(e),1e-6),i=p=>Math.floor((p-t)/s),o=p=>Math.floor((p-c)/s),l=i(a)+1,h=o(r)+1,f=new Map;n.forEach((p,g)=>{for(let v of[p[0],p[p.length-1]]){let b=o(v[1])*l+i(v[0]),y=f.get(b);y?y[y.length-1]!==g&&y.push(g):f.set(b,[g])}});let u=new Array(e).fill(!1),d=[],m=[0,0];for(let p=0;p<e;p++){let g=-1,v=1/0,b=!1,y=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=y-w;k<=y+w;k++)for(let S=x-w;S<=x+w;S++)if(Math.max(Math.abs(k-y),Math.abs(S-x))===w&&!(k<0||S<0||k>=l||S>=h))for(let A of f.get(S*l+k)??[]){if(u[A])continue;let z=n[A],L=Math.hypot(z[0][0]-m[0],z[0][1]-m[1]),P=Math.hypot(z[z.length-1][0]-m[0],z[z.length-1][1]-m[1]);L<v&&([g,v,b]=[A,L,!1]),P<v&&([g,v,b]=[A,P,!0])}if(g>=0&&v<=w*s)break}if(g<0){for(let w=0;w<e;w++)if(!u[w]){g=w;break}}u[g]=!0;let M=b?[...n[g]].reverse():n[g];d.push(M),m=M[M.length-1]}return d}function Ue(n){let e=[],t=1/0,c=-1/0;for(let i of n)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]]),t=Math.min(t,i[o][1]),c=Math.max(c,i[o][1]);if(!e.length)return()=>!1;let a=Math.max(1,Math.min(4096,Math.ceil(Math.sqrt(e.length)))),r=(c-t)/a||1,s=Array.from({length:a},()=>[]);return e.forEach(([,i,,o],l)=>{let h=Math.max(0,Math.min(a-1,Math.floor((Math.min(i,o)-t)/r))),f=Math.max(0,Math.min(a-1,Math.floor((Math.max(i,o)-t)/r)));for(let u=h;u<=f;u++)s[u].push(l)}),([i,o])=>{if(o<t||o>c)return!1;let l=0;for(let h of s[Math.max(0,Math.min(a-1,Math.floor((o-t)/r)))]){let[f,u,d,m]=e[h];u<=o?m>o&&(d-f)*(o-u)-(i-f)*(m-u)>0&&l++:m<=o&&(d-f)*(o-u)-(i-f)*(m-u)<0&&l--}return l!==0}}var Ne=Math.PI/180;function q1(n,e){let t=new Array(16).fill(0);for(let c=0;c<4;c++)for(let a=0;a<4;a++)for(let r=0;r<4;r++)t[c*4+a]+=n[c*4+r]*e[r*4+a];return t}function c5(n,e){let t=Math.cos(e*Ne),c=Math.sin(e*Ne);return n===0?[1,0,0,0,0,t,-c,0,0,c,t,0,0,0,0,1]:n===1?[t,0,c,0,0,1,0,0,-c,0,t,0,0,0,0,1]:[t,-c,0,0,c,t,0,0,0,0,1,0,0,0,0,1]}var r4=n=>Math.abs(n)<1e-12?0:n;function o0(n){if(n.matrix)return n.matrix.map(r4);let[e,t,c]=n.rotate,a=q1(c5(2,c),q1(c5(1,t),c5(0,e)));return a[3]=n.at[0],a[7]=n.at[1],a[11]=n.at[2],a.map(r4)}function L2(n,e,t,c){return[n[0]*e+n[1]*t+n[2]*c+n[3],n[4]*e+n[5]*t+n[6]*c+n[7],n[8]*e+n[9]*t+n[10]*c+n[11]]}function M3(n){let[e,t,c]=[n[3],n[7],n[11]],a=[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]];return[a[0],a[1],a[2],-(a[0]*e+a[1]*t+a[2]*c),a[3],a[4],a[5],-(a[3]*e+a[4]*t+a[5]*c),a[6],a[7],a[8],-(a[6]*e+a[7]*t+a[8]*c),0,0,0,1]}function a5(n){let[e,t,c,a]=[1/0,1/0,-1/0,-1/0];for(let r of n)for(let[s,i]of r)e=Math.min(e,s),t=Math.min(t,i),c=Math.max(c,s),a=Math.max(a,i);return[e,t,c,a]}function We(n){let[e,t,c,a]=a5(n.outline),r=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0];for(let i of[e,c])for(let o of[t,a])for(let l of[0,n.thickness]){let h=L2(n.matrix,i,o,l);for(let f=0;f<3;f++)r[f]=Math.min(r[f],h[f]),s[f]=Math.max(s[f],h[f])}return[r,s]}function Xe(n,e,t=10){let c=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let[h,f]of n.map(We))for(let u=0;u<3;u++)c[u]=Math.min(c[u],h[u]),a[u]=Math.max(a[u],f[u]);let r=e.map(h=>a5(h.outline)),s=r.reduce((h,[f,,u])=>Math.max(h,u-f),a[0]-c[0]),i=0,o=0,l=0;return e.map((h,f)=>{let[u,d,m,p]=r[f];i>0&&i+m-u>s&&(i=0,o+=l+t,l=0);let g=[1,0,0,a[0]+t+i-u,0,1,0,c[1]+o-d,0,0,1,c[2],0,0,0,1];return i+=m-u+t,l=Math.max(l,p-d),{...h,matrix:g.map(r4)}})}var z8=(n,e,t)=>[0,1,2].every(c=>n[0][c]<e[1][c]-t&&e[0][c]<n[1][c]-t),$2=(n,e)=>n[0]*e[0]+n[1]*e[1]+n[2]*e[2],r5=(n,e)=>[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]],a4=(n,e,t=1)=>[n[0]+e[0]*t,n[1]+e[1]*t,n[2]+e[2]*t],N2=n=>[n[2],n[6],n[10]],Be=n=>[n[3],n[7],n[11]],k8=(n,e)=>[n[0]*e[0]+n[1]*e[1]+n[2]*e[2],n[4]*e[0]+n[5]*e[1]+n[6]*e[2],n[8]*e[0]+n[9]*e[1]+n[10]*e[2]];function U2(n,e,t){let c=t[0]*t[0]+t[1]*t[1],a=[];for(let r of n)for(let s=0,i=r.length-1;s<r.length;i=s++){let o=r[i],l=r[s],h=t[0]*(o[1]-e[1])-t[1]*(o[0]-e[0]),f=t[0]*(l[1]-e[1])-t[1]*(l[0]-e[0]);if(h>0==f>0)continue;let u=h/(h-f),d=o[0]+(l[0]-o[0])*u-e[0],m=o[1]+(l[1]-o[1])*u-e[1];a.push((d*t[0]+m*t[1])/c)}return a.sort((r,s)=>r-s)}function s4(n,e,t){let c=0,a=0,r=0,s=0,i=0;for(;s+1<n.length&&i+1<e.length;){let o=Math.max(n[s],e[i]),l=Math.min(n[s+1],e[i+1])-o;l>t&&(c+=l,l>r&&(r=l,a=o+l/2)),n[s+1]<e[i+1]?s+=2:i+=2}return{total:c,mid:a,run:r}}function L8(n,e){let[t,c,a]=L2(M3(n.matrix),e[0],e[1],e[2]);if(a<0||a>n.thickness)return!1;let r=!1;for(let s of n.outline)for(let i=0,o=s.length-1;i<s.length;o=i++){let[l,h]=s[o],[f,u]=s[i];h>c!=u>c&&t<l+(f-l)*(c-h)/(u-h)&&(r=!r)}return r}var s5=class{constructor(e=[]){this.parts=e;this.seen=[]}see(e,t){e>0&&this.seen.push([t(),e])}get at(){let e=0,t=[0,0,0];for(let[r,s]of this.seen){for(let i=0;i<3;i++)t[i]+=r[i]*s;e+=s}for(let r=0;r<3;r++)t[r]/=e;if(this.parts.length&&this.parts.every(r=>L8(r,t)))return t;let c=this.seen[0][0],a=1/0;for(let[r]of this.seen){let s=Math.hypot(r[0]-t[0],r[1]-t[1],r[2]-t[2]);s<a&&([c,a]=[r,s])}return c}};function i5(n,e,t,c){let a=n+t,r=e-t;if(r<=a)return{at:[],size:0};let s=Math.max(4,Math.ceil((r-a)/c));return{at:Array.from({length:s},(i,o)=>a+(r-a)*(o+.5)/s),size:(r-a)/s}}function Ge(n,e,t){let c=L2(n,e[0],e[1],e[2]),a=k8(n,t);return[[c[0],c[1]],[a[0],a[1]]]}function Ze(n,e,t,c,a,r,s,i=!1){let o=N2(n.matrix),l=N2(e.matrix),h=r5(o,l),f=Math.hypot(...h),u=[h[0]/f,h[1]/f,h[2]/f],d=r5(u,o),m=$2(l,d),p=Be(n.matrix),g=$2(l,Be(e.matrix)),v=1/0,b=-1/0;for(let S of e.outline)for(let[A,z]of S)for(let L of[0,e.thickness]){let P=L2(e.matrix,A,z,L),I=$2(o,[P[0]-p[0],P[1]-p[1],P[2]-p[2]]);I<v&&(v=I),I>b&&(b=I)}let y=i5(Math.max(0,v),Math.min(n.thickness,b),a,r),x=1/0,M=-1/0;for(let S of n.outline)for(let[A,z]of S){let L=L2(n.matrix,A,z,0),P=$2(d,[L[0]-p[0],L[1]-p[1],L[2]-p[2]]);P<x&&(x=P),P>M&&(M=P)}let w=0,k=new s5([n,e]);for(let S of y.at){let A=a4(p,o,S),z=(g-$2(l,A))/m,L=(g+e.thickness-$2(l,A))/m,P=i5(Math.max(x,Math.min(z,L)),Math.min(M,Math.max(z,L)),a,r);for(let I of P.at){let T=a4(A,d,I),[O,F]=Ge(t,T,u),[D,_]=Ge(c,T,u),R=s4(U2(n.outline,O,F),U2(e.outline,D,_),a);if(w+=R.total*y.size*P.size,k.see(R.run,()=>a4(T,u,R.mid)),w>s&&!i)return k.at}}return w>s?k.at:void 0}function Ye(n,e,t,c,a,r,s=!1){let i=[0,1,2,3].flatMap(z=>[0,1,2,3].map(L=>{let P=0;for(let I=0;I<4;I++)P+=t[z*4+I]*e.matrix[I*4+L];return P})),o=i[11],l=i[11]+i[10]*e.thickness,h=Math.min(n.thickness,Math.max(o,l))-Math.max(0,Math.min(o,l));if(h<=c)return;let f=Math.max(0,Math.min(o,l))+h/2,u=new s5([n,e]),d=e.outline.map(z=>z.map(([L,P])=>[i[0]*L+i[1]*P+i[3],i[4]*L+i[5]*P+i[7]])),[m,p,g,v]=a5(n.outline),[b,y,x,M]=a5(d),w=i5(Math.max(p,y),Math.min(v,M),c,a),k=0;for(let z of w.at){let L=s4(U2(n.outline,[0,z],[1,0]),U2(d,[0,z],[1,0]),c);if(k+=L.total*w.size*h,u.see(L.run,()=>L2(n.matrix,L.mid,z,f)),k>r&&!s)return u.at}let S=i5(Math.max(m,b),Math.min(g,x),c,a),A=0;for(let z of S.at){let L=s4(U2(n.outline,[z,0],[0,1]),U2(d,[z,0],[0,1]),c);if(A+=L.total*S.size*h,u.see(L.run,()=>L2(n.matrix,z,L.mid,f)),A>r&&!s)return u.at}return k>r||A>r?u.at:void 0}function Ke(n,e=1/0,t=.05,c=.25,a=.1){let r=n.map(We),s=n.map(h=>M3(h.matrix)),i=n.map((h,f)=>f).sort((h,f)=>r[h][0][0]-r[f][0][0]),o=[],l=0;for(let h=0;h<i.length;h++)for(let f=h+1;f<i.length;f++){let u=i[h],d=i[f];if(r[d][0][0]>=r[u][1][0]-t)break;if(!z8(r[u],r[d],t))continue;if(++l>e)return{found:o,complete:!1};let[m,p]=u<d?[n[u],n[d]]:[n[d],n[u]],[g,v]=u<d?[s[u],s[d]]:[s[d],s[u]],y=Math.hypot(...r5(N2(m.matrix),N2(p.matrix)))<1e-9?Ye(m,p,g,t,c,a):Ze(m,p,g,v,t,c,a);y&&o.push([m,p,y])}return{found:o,complete:!0}}function Je(n,e,t=.05,c=.25,a=.1){let r=Math.hypot(...r5(N2(n.matrix),N2(e.matrix)))<1e-9,s=M3(n.matrix);return r?Ye(n,e,s,t,c,a,!0):Ze(n,e,s,M3(e.matrix),t,c,a,!0)}function I0(n,e,t){return[1,0,0,n,0,1,0,e,0,0,1,t,0,0,0,1]}var i4=I0(0,0,0);function l2(n){return M3(n)}function A8(n,e,t=n.angle,c=n.x1){let a=c-n.x0;if(!t||!(a>0))return I0(0,0,0);let r=(n.x1-n.x0)/(n.angle*Math.PI/180),s=e/2+r;return q1(I0(n.x0,0,s),q1(c5(1,-t),I0(-n.x0-a,0,-s)))}function o5(n){return[...n].sort((e,t)=>e.x0-t.x0)}var o4=n=>n.length>0&&n.every(e=>e.mirrored),je=[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],S8=n=>q1(je,q1(n,je));function Qe(n){return o5(n).map(e=>e.mirrored?[-e.x1,-e.x0]:[e.x0,e.x1])}function l4(n,e){let t=[I0(0,0,0)];for(let c of o5(n))t.push(q1(t[t.length-1],A8(c,e)));return o4(n)?t.map(S8):t}function e6(n,e){let t=o4(n)?-e:e;return o5(n).filter(c=>(c.x0+c.x1)/2<t).length}function w3(n){if(n.folds?.length)return h4(n.outline,n.folds,n.thickness).map(s=>({...n,outline:s.outline,folds:void 0,matrix:q1(n.matrix,s.matrix)}));if(!n.bends?.length)return[n];let e=o5(n.bends),t=l4(n.bends,n.thickness),c=o4(n.bends),a=1e7,r=[];for(let s=0;s<=e.length;s++){let i=s===0?-a:e[s-1].x1,o=s===e.length?a:e[s].x0;if(!(o>i))continue;let[l,h]=c?[-o,-i]:[i,o],f=[[l,-a],[h,-a],[h,a],[l,a]],u=b1(n.outline,[f]);u.length&&r.push({...n,outline:u,bends:void 0,matrix:q1(n.matrix,t[s])})}return r}function C8(n,e,t){let c=t*Math.PI/180,[a,r,s]=[Math.cos(c),Math.sin(c),1-Math.cos(c)],[i,o,l]=e,h=[a+i*i*s,i*o*s-l*r,i*l*s+o*r,o*i*s+l*r,a+o*o*s,o*l*s-i*r,l*i*s-o*r,l*o*s+i*r,a+l*l*s];return[h[0],h[1],h[2],n[0]-(h[0]*n[0]+h[1]*n[1]+h[2]*n[2]),h[3],h[4],h[5],n[1]-(h[3]*n[0]+h[4]*n[1]+h[5]*n[2]),h[6],h[7],h[8],n[2]-(h[6]*n[0]+h[7]*n[1]+h[8]*n[2]),0,0,0,1]}var P8=(n,[e,t])=>{let c=!1;for(let a of n)for(let r=0,s=a.length-1;r<a.length;s=r++)a[r][1]>t!=a[s][1]>t&&e<(a[s][0]-a[r][0])*(t-a[r][1])/(a[s][1]-a[r][1])+a[r][0]&&(c=!c);return c};function h4(n,e,t){let c=e.map(d=>{let[m,p]=[d.to[0]-d.from[0],d.to[1]-d.from[1]],g=Math.hypot(m,p),[v,b]=[m/g,p/g],[y,x]=[-b*.005,v*.005],[M,w]=[[d.from[0]-v*.02,d.from[1]-b*.02],[d.to[0]+v*.02,d.to[1]+b*.02]];return[[M[0]-y,M[1]-x],[w[0]-y,w[1]-x],[w[0]+y,w[1]+x],[M[0]+y,M[1]+x]]}),a=i0(t0(n,c)),r=[];if(!a.length)return r;let s=d=>a.findIndex(m=>P8(m,d)),i=e.map(d=>{let[m,p]=[d.to[0]-d.from[0],d.to[1]-d.from[1]],g=Math.hypot(m,p),[v,b]=[-p/g*.05,m/g*.05],y=[];for(let x=0;x<25;x++){let M=(x+.5)/25,w=[d.from[0]+m*M,d.from[1]+p*M],k=s([w[0]+v,w[1]+b]),S=s([w[0]-v,w[1]-b]);k>=0&&S>=0&&k!==S&&!y.some(([A,z])=>A===k&&z===S)&&y.push([k,S])}return y}),o=d=>d.reduce((m,p)=>m+Math.abs(s1(p)),0),l=s([0,0]);l<0&&(l=a.map(o).reduce((d,m,p,g)=>m>g[d]?p:d,0));let h=a.map(()=>{});h[l]=I0(0,0,0);let f=[l];for(;f.length;){let d=f.shift();e.forEach((m,p)=>i[p].forEach(g=>{if(!g.includes(d))return;let v=g[0]===d?g[1]:g[0];if(h[v])return;let[b,y]=[m.to[0]-m.from[0],m.to[1]-m.from[1]],x=Math.hypot(b,y),M=v===g[0]?1:-1,w=m.angle>0?t:0,k=C8([m.from[0],m.from[1],w],[b/x,y/x,0],M*m.angle);h[v]=q1(h[d],k),f.push(v)}))}a.forEach((d,m)=>r.push({outline:d,matrix:h[m]??I0(0,0,0)}));let u=e.flatMap((d,m)=>i[m].length?[]:[m]);return u.length&&(r.unused=u),r}var g0=(n,e=!0)=>`line ${n.line}${e?`, column ${n.col}`:""}${n.file?` in <${n.file}>`:""}`;var X=class extends Error{constructor(t,c){super(c?`${t} (${g0(c)})`:t);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=t,c&&(this.line=c.line,this.col=c.col,this.file=c.file)}addFrame(t,c,a){let r=this.trace.find(s=>s.name===c&&s.line===a.line&&s.col===a.col&&s.file===a.file);r?r.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:t,name:c,line:a.line,col:a.col,...a.file&&{file:a.file},count:1})}},E8=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function B2(n,e){let t=[],c=[],a=0,r=1,s=0,i=()=>({line:r,col:a-s+1,offset:a,...e&&{file:e}}),o=l=>{for(let h=0;h<l;h++)n[a]===`
|
|
7
7
|
`&&(r++,s=a+1),a++};for(;a<n.length;){let l=n[a];if(l===" "||l===" "||l==="\r"||l===`
|
|
8
8
|
`){o(1);continue}if(l==="/"&&n[a+1]==="/"){let u=n.indexOf(`
|
|
9
9
|
`,a),d=u<0?n.length:u,m=/^[ \t]*$/.test(n.slice(n.lastIndexOf(`
|
|
10
|
-
`,a-1)+1,a));c.push({text:n.slice(a+2,d).trim(),line:r,block:!1,own:m,start:a,end:d}),a=d;continue}if(l==="/"&&n[a+1]==="*"){let u=i(),d=n.indexOf("*/",a+2);if(d<0)throw new
|
|
11
|
-
`;else if(d==="t")u+=" ";else if(d==="u"){let m=n.slice(a+2,a+6);if(!/^[0-9a-fA-F]{4}$/.test(m))throw new
|
|
12
|
-
`)throw new G("Unclosed string",h);u+=n[a],o(1)}if(a>=n.length)throw new G("Unclosed string",h);o(1),t.push({type:"str",value:u,pos:h,end:a});continue}if(l==="<"&&/^<[A-Za-z0-9_./\\: -]+>/.test(n.slice(a))){let u=t[t.length-1];if(u&&u.type==="id"&&(u.value==="use"||u.value==="include")){let d=/^<([A-Za-z0-9_./\\: -]+)>/.exec(n.slice(a));t.push({type:"str",value:d[1],pos:h,end:a+d[0].length}),o(d[0].length);continue}}let f=r9.find(u=>n.startsWith(u,a));if(!f)throw new G(`Unexpected character "${l}"`,h);t.push({type:"punct",value:f,pos:h,end:a+f.length}),o(f.length)}return t.push({type:"eof",value:"",pos:i(),end:a}),{tokens:t,comments:c}}var a3=(n,e)=>[n[0]-e[0],n[1]-e[1],n[2]-e[2]],$6=(n,e)=>n[0]*e[0]+n[1]*e[1]+n[2]*e[2],s9=(n,e)=>[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]],_6=n=>{let e=Math.hypot(...n);return[n[0]/e,n[1]/e,n[2]/e]},r3={turn:.3,press:-.1};function i9(n){let e=_6(a3(n.to,n.from)),t=a3(n.up,e.map(a=>a*$6(n.up,e)));Math.hypot(...t)<1e-9&&(t=Math.abs(e[0])<.9?[1,0,0]:[0,1,0]);let c=_6(a3(t,e.map(a=>a*$6(t,e))));return{axis:e,u:s9(c,e),v:c}}function o9(n,e){let{u:t,v:c}=i9(n);if(Array.isArray(n.size)){let[s,i]=[n.size[0]/2+e/2,n.size[1]/2+e/2];return[[-s,-i],[s,-i],[s,i],[-s,i]].map(([o,l])=>[t[0]*o+c[0]*l,t[1]*o+c[1]*l,t[2]*o+c[2]*l])}let a=n.size/2+e/2,r=n.sides<12?n.sides:64;return Array.from({length:r},(s,i)=>{let o=2*Math.PI*i/r,[l,h]=[Math.cos(o)*a,Math.sin(o)*a];return[t[0]*h+c[0]*l,t[1]*h+c[1]*l,t[2]*h+c[2]*l]})}function B6(n,e,t){let c=a3(e.to,e.from);if(!(Math.hypot(...c)>1e-9))return;let a=t2(n.matrix),r=o=>[a[0]*o[0]+a[1]*o[1]+a[2]*o[2]+a[3],a[4]*o[0]+a[5]*o[1]+a[6]*o[2]+a[7],a[8]*o[0]+a[9]*o[1]+a[10]*o[2]+a[11]],s=a3(r(c),r([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let i=[];for(let o of o9(e,t)){let l=r([e.from[0]+o[0],e.from[1]+o[1],e.from[2]+o[2]]),h=(0-l[2])/s[2],f=(n.thickness-l[2])/s[2];if(h>f&&([h,f]=[f,h]),h=Math.max(0,h),f=Math.min(1,f),f>h)for(let u of[h,f])i.push([l[0]+s[0]*u,l[1]+s[1]*u])}return i.length>=3?I3(i):void 0}var G5={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"}},G6={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var j5=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function Y0(n,e){let{tokens:t,comments:c}=I2(n,e),a=new W5(t),r=[];for(;!a.at("eof");)r.push(...a.statement());return{program:{body:r},comments:c}}var s3=class s3{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,t,c=0){let a=this.peek(c);return a.type===e&&(t===void 0||a.value===t)}isP(e,t=0){return this.at("punct",e,t)}isK(e,t=0){return this.at("id",e,t)}next(){return this.tokens[this.i++]}fail(e,t=this.peek()){let c=t.type==="eof"?"end of file":`"${t.value}"`;throw new G(`${e}, found ${c}`,t.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"||j5.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 t of e)t.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 t=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(t=this.next().value);let c=this.peek();(c.type!=="id"||j5.has(c.value))&&this.fail("Expected a statement"),this.next();let a=this.args(),r=this.body();return[{kind:"call",name:c.value,args:a,children:r,modifier:t,pos:c.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let t=this.ident(),c=null;this.isP("=")&&(this.next(),c=this.expr()),e.push({name:t.value,default:c,pos:t.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let t=this.next();this.next(),e.push({name:t.value,value:this.expr(),pos:t.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let t=this.ident();this.expectP("="),e.push({name:t.value,value:this.expr(),pos:t.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let c=this.params(),a=this.expr();return{kind:"lambda",params:c,body:a,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let c=this.assigns(),a=this.expr();return{kind:"let",assigns:c,body:a,pos:e.pos,end:this.last()}}if(this.at("id")&&(e.value==="assert"||e.value==="echo")&&this.isP("(",1)){let c=this.i;this.next();let a={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:a,body:this.expr(),pos:e.pos};this.i=c}let t=this.binary(0);if(this.isP("?")){this.next();let c=this.expr();this.expectP(":");let a=this.expr();return{kind:"ternary",cond:t,then:c,else:a,pos:e.pos}}return t}binary(e){if(e>=s3.LEVELS.length)return this.unary();let t=this.binary(e+1);for(;this.at("punct")&&s3.LEVELS[e].includes(this.peek().value);){let c=this.next(),a=this.binary(e+1);t={kind:"binary",op:c.value,left:t,right:a,pos:c.pos}}return t}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 t=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:t.pos}}return e}postfix(){let e=this.primary();for(;;){let t=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let c=this.expr();this.expectP("]"),e={kind:"index",target:e,index:c,pos:t.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:t.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let t=/(mm|cm|m|in|ft)$/.exec(e.value);return t?{kind:"num",value:Number(e.value.slice(0,-t[1].length)),unit:t[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}):(j5.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let t=this.expr();return this.expectP(")"),t}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),t=[];for(;!this.isP("}");){let c=this.ident();if(t.some(a=>a.name===c.value))throw new G(`Field ${c.value} is given twice`,c.pos);if(this.expectP("="),t.push({name:c.value,value:this.expr(),pos:c.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:t,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 t=this.expr();if(this.isP(":")){this.next();let a=null,r=this.expr();return this.isP(":")&&(this.next(),a=r,r=this.expr()),this.expectP("]"),{kind:"range",start:t,step:a,end:r,pos:e.pos}}let c=[{kind:"item",expr:t}];return this.listRest(c,e.pos)}return this.listRest([],e.pos)}listRest(e,t){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:t};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:t}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let t=this.assigns(),c=this.listItem();return{kind:"for",assigns:t,body:c,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let t=this.expr();this.expectP(")");let c=this.listItem(),a=null;return this.isK("else")&&(this.next(),a=this.listItem()),{kind:"if",cond:t,then:c,else:a}}if(this.isK("let")&&this.isP("(",1)){this.next();let t=this.assigns(),c=this.listItem();return{kind:"let",assigns:t,body:c,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let t=this.listItem();return this.expectP(")"),t}return{kind:"item",expr:this.expr()}}};s3.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var W5=s3;var A=(n,e,t)=>({name:n,...t!==void 0&&{default:t},...e&&{doc:e}}),t1=(n,e,t)=>({...A(n,e,t),named:!0}),X5="max(3 * $thickness, 6)",$3=[A("value")],l9=[A("x")],u0=(n,e)=>({name:n,kind:"function",params:l9,section:"Numbers and vectors",doc:e}),g2=(n,e)=>({name:n,kind:"function",params:$3,section:"Types",doc:`Whether the value is ${e}`}),Z5=(n,e)=>({name:n,kind:"function",params:[A("text","The text to measure",'""'),A("size","Font size in millimetres","10"),A("font","Font name","$font"),t1("halign","left, center or right",'"left"'),t1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),t1("spacing","Letter spacing factor","1"),t1("fit","Measure at the size that fits this width, or [width, cap height]")],section:"Text measurements",doc:e}),_3=[{name:"rect",kind:"module",params:[A("size","A number, or [width, height]","1"),A("center","Centre the rectangle on the origin instead of its corner","false"),t1("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[A("size","A number, or [width, height]","1"),A("center","Centre the square on the origin instead of its corner","false"),t1("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[A("r","Radius","1"),t1("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[A("r","[rx, ry], or one radius for both","1"),t1("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:[A("n","Number of corners","6"),A("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[A("n","Number of points","5"),A("r","Radius of the points","10"),A("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[A("points","A list of [x, y] points"),A("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:[A("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),t1("fill",'"evenodd" or "nonzero"','"evenodd"'),t1("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:[A("text","The text",'""'),A("size","Font size in millimetres","10"),A("font","Font name","$font"),t1("halign","left, center or right",'"left"'),t1("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),t1("spacing","Letter spacing factor","1"),t1("fit","Shrink the size so the text is no wider than this, or fits [width, cap height]"),t1("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),t1("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:[A("from","Start point","[0, 0]"),A("to","End point","[10, 0]"),A("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:[A("points","A list of [x, y] points"),A("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[A("r","Radius","10"),A("start","Start angle in degrees","0"),A("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[A("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[A("a","Angle in degrees, anticlockwise","0"),t1("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:[A("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[A("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:[A("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:[A("r","Grow (positive) or shrink areas with rounded corners"),t1("delta","Grow or shrink areas with sharp corners","0"),t1("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:[A("spacing","Distance between copies, a number or [x, y]","10"),A("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:[A("points","The [x, y] points the curve goes through"),A("width","Make an area this wide along the curve, instead of a line"),t1("steps","Points between each two given ones","8"),t1("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:[A("angle","Direction of the lines, in degrees from +x","45"),A("pitch","Distance between the lines","5"),A("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:[A("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),A("spacing","Distance between neighbouring lines","2"),A("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),t1("min_length","Lines shorter than this are left out","spacing * 2"),t1("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:[A("field","The height at a point: function(p) giving a number, or undef for none"),A("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),t1("interval","Instead of levels: every multiple of this height"),t1("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:[A("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:[A("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:[A("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:[A("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:[A("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:[A("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:[A("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:[A("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:[A("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:[A("name","Layer name"),A("mode",'"cut", "line", "fill" or "guide"'),A("color",'Colour in the output, as "#00aa00"'),t1("order","Where it goes among the custom layers in the files, lowest first","0"),t1("bleed","How far past the part's edge it may print","0"),t1("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:[A("name","Part name",'"part"'),A("qty","Number of copies to cut","1"),t1("at","Where the part goes in the assembled view, [x, y, z]"),t1("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),t1("stack","Layers glued in a stack at each placement, one thickness apart","1"),t1("mirror","Cut the part mirrored left to right, its text still reading","false"),t1("material","The material it is cut from, as material(name = ...) sets it"),t1("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),t1("on","The name of a bent part this one is glued to, to move with it"),t1("slots","Names of parts whose tabs pass through this one: their slots are cut"),t1("clearance","Added to the slots, in total across each","0.1"),t1("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),t1("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),t1("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),t1("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"'),t1("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),t1("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:[A("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),A("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:[A("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:[A("text","What to do in this step",'""'),A("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:[A("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),A("from","One end, [x, y, z]; a ball sits midway between from and to"),A("to","The other end, [x, y, z]; a ball may leave it out"),A("size","Diameter, or [width, height] for a flat section","6"),t1("up","The direction a [width, height] section's height points"),t1("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),t1("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),t1("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:[A("thickness","Sets $thickness"),A("kerf","Sets $kerf"),A("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:[A("size","[width, height]"),A("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),A("finger","Finger width",X5)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[A("length","Length of the edge that plugs in"),A("edge",'"out" or "in", the kind of edge that plugs in','"out"'),A("finger","Finger width",X5)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[A("d","Screw diameter","3"),A("length","Screw length into the panel","12"),A("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),A("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:[A("size","[width, height]"),A("spacing","Distance between the rows of cuts","1.5"),A("bridge","Uncut length between cuts","3"),A("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:[A("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:[A("condition","Stops the program when false"),A("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},u0("abs","Absolute value"),u0("sign","Sign as -1, 0 or 1"),u0("floor","Round down"),u0("ceil","Round up"),u0("round","Round to the nearest integer, halves away from zero"),u0("sqrt","Square root"),u0("exp","e raised to x"),u0("ln","Natural logarithm"),{name:"log",kind:"function",params:[A("x"),A("base",void 0,"10")],forms:["log(x)","log(base, x)"],section:"Numbers and vectors",doc:"Logarithm, base 10 or a chosen base; with two values the base comes first"},u0("sin","Sine of an angle in degrees"),u0("cos","Cosine of an angle in degrees"),u0("tan","Tangent of an angle in degrees"),u0("asin","Inverse sine, in degrees"),u0("acos","Inverse cosine, in degrees"),u0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[A("y"),A("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[A("x"),A("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[A("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:[A("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:[A("x"),A("low"),A("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[A("a"),A("b"),A("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[A("ratio","Turns in for one turn out; under 1 speeds up"),A("stages","Pairs of gears, 1 to 3","2"),A("pinion","Fewest and most teeth of the small gears","[10, 20]"),A("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:[A("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[A("a"),A("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[A("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:[A("points","A list of [x, y] points"),A("d","How far to move it: to the left going along it, or the right when less than 0"),A("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:[A("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:[A("points","A closed outline of [x, y] points, or a list of outlines"),A("x","The vertical line x = this"),A("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:[A("points","A list of [x, y] points"),A("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:[A("points","A list of [x, y] points"),A("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:[A("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),A("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:[A("points","The [x, y] points the curve goes through"),A("steps","Points between each two given ones","8"),A("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:[A("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:[A("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:[A("x","Where the part's own x axis points"),A("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:$3,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:[A("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:[A("a","A record"),A("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:$3,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[A("values","A list of numbers, strings or lists of them"),A("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:[A("values","A list"),A("initial","The value to start from"),A("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:[A("values","A list"),A("initial","The value to start from"),A("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:[A("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[A("value","A list or string"),A("start","First index","0"),A("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:[A("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[A("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[A("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[A("text"),A("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[A("values"),A("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[A("value"),A("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[A("value","A list or string"),A("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[A("x"),A("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},g2("is_num","a number other than NaN"),g2("is_string","a string"),g2("is_bool","true or false"),g2("is_list","a list"),g2("is_undef","undef"),g2("is_function","a function"),g2("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:$3,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[A("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),A("y",void 0,"0"),A("z","A third axis: step it to get a related but different pattern","0"),t1("seed","A different seed gives a different pattern","1"),t1("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:[A("min"),A("max"),A("count"),A("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},Z5("text_width","The advance width of the text, including spacing"),Z5("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),Z5("text_size","The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"),{name:"finger_count",kind:"function",params:[A("length","Edge length"),A("finger","Finger width",X5)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],h9=new Map(_3.map(n=>[n.name,n])),H2=n=>h9.get(n);function B3(n){let e=n.params.map(t=>t.default===void 0?t.name:`${t.name} = ${t.default}`);return n.rest&&e.push("..."),`${n.name}(${e.join(", ")})`}var U0={"kerf/box":`// kerf/box: finger-jointed boxes.
|
|
10
|
+
`,a-1)+1,a));c.push({text:n.slice(a+2,d).trim(),line:r,block:!1,own:m,start:a,end:d}),a=d;continue}if(l==="/"&&n[a+1]==="*"){let u=i(),d=n.indexOf("*/",a+2);if(d<0)throw new X("Unclosed block comment",u);c.push({text:n.slice(a+2,d).trim(),line:u.line,block:!0,own:!0,start:a,end:d+2}),o(d+2-a);continue}let h=i();if(/[0-9]/.test(l)||l==="."&&/[0-9]/.test(n[a+1]??"")){let u=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(n.slice(a));t.push({type:"num",value:u[0],pos:h,end:a+u[0].length}),o(u[0].length);continue}if(/[A-Za-z_$]/.test(l)){let u=/^[A-Za-z_$][A-Za-z0-9_]*/.exec(n.slice(a));t.push({type:"id",value:u[0],pos:h,end:a+u[0].length}),o(u[0].length);continue}if(l==='"'){let u="";for(o(1);a<n.length&&n[a]!=='"';){if(n[a]==="\\"){let d=n[a+1];if(d==="n")u+=`
|
|
11
|
+
`;else if(d==="t")u+=" ";else if(d==="u"){let m=n.slice(a+2,a+6);if(!/^[0-9a-fA-F]{4}$/.test(m))throw new X("Bad \\u escape",i());u+=String.fromCharCode(parseInt(m,16)),o(4)}else u+=d;o(2);continue}if(n[a]===`
|
|
12
|
+
`)throw new X("Unclosed string",h);u+=n[a],o(1)}if(a>=n.length)throw new X("Unclosed string",h);o(1),t.push({type:"str",value:u,pos:h,end:a});continue}if(l==="<"){let u=t[t.length-1];if(u&&u.type==="id"&&(u.value==="use"||u.value==="include")){let d=/^<([^<>\r\n]+)>/.exec(n.slice(a,a+4097));if(d){t.push({type:"str",value:d[1],pos:h,end:a+d[0].length}),o(d[0].length);continue}}}let f=E8.find(u=>n.startsWith(u,a));if(!f)throw new X(`Unexpected character "${l}"`,h);t.push({type:"punct",value:f,pos:h,end:a+f.length}),o(f.length)}return t.push({type:"eof",value:"",pos:i(),end:a}),{tokens:t,comments:c}}var z3=(n,e)=>[n[0]-e[0],n[1]-e[1],n[2]-e[2]],t6=(n,e)=>n[0]*e[0]+n[1]*e[1]+n[2]*e[2],T8=(n,e)=>[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]],n6=n=>{let e=Math.hypot(...n);return[n[0]/e,n[1]/e,n[2]/e]},k3={turn:.3,press:-.1};function I8(n){let e=n6(z3(n.to,n.from)),t=z3(n.up,e.map(a=>a*t6(n.up,e)));Math.hypot(...t)<1e-9&&(t=Math.abs(e[0])<.9?[1,0,0]:[0,1,0]);let c=n6(z3(t,e.map(a=>a*t6(t,e))));return{axis:e,u:T8(c,e),v:c}}function H8(n,e){let{u:t,v:c}=I8(n);if(Array.isArray(n.size)){let[s,i]=[n.size[0]/2+e/2,n.size[1]/2+e/2];return[[-s,-i],[s,-i],[s,i],[-s,i]].map(([o,l])=>[t[0]*o+c[0]*l,t[1]*o+c[1]*l,t[2]*o+c[2]*l])}let a=n.size/2+e/2,r=n.sides<12?n.sides:64;return Array.from({length:r},(s,i)=>{let o=2*Math.PI*i/r,[l,h]=[Math.cos(o)*a,Math.sin(o)*a];return[t[0]*h+c[0]*l,t[1]*h+c[1]*l,t[2]*h+c[2]*l]})}function c6(n,e,t){let c=z3(e.to,e.from);if(!(Math.hypot(...c)>1e-9))return;let a=l2(n.matrix),r=o=>[a[0]*o[0]+a[1]*o[1]+a[2]*o[2]+a[3],a[4]*o[0]+a[5]*o[1]+a[6]*o[2]+a[7],a[8]*o[0]+a[9]*o[1]+a[10]*o[2]+a[11]],s=z3(r(c),r([0,0,0]));if(Math.abs(s[2])<.05*Math.hypot(...s))return;let i=[];for(let o of H8(e,t)){let l=r([e.from[0]+o[0],e.from[1]+o[1],e.from[2]+o[2]]),h=(0-l[2])/s[2],f=(n.thickness-l[2])/s[2];if(h>f&&([h,f]=[f,h]),h=Math.max(0,h),f=Math.min(1,f),f>h)for(let u of[h,f])i.push([l[0]+s[0]*u,l[1]+s[1]*u])}return i.length>=3?e5(i):void 0}var u4={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",translucent:!0,doc:"a sheet or strip of paper"},vellum:{color:"#f3efe2",translucent:!0,doc:"vellum or tracing paper, as a lantern window that a light shines through"},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, giving off light"},bulb:{color:"#fff4c2",glow:!0,doc:'a light bulb, giving off light; give it shape = "ball"'},tealight:{color:"#d4d8dc",metal:!0,doc:"a tealight, 39 mm across and 16 mm high, standing at from; its flame flickers"},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"}},a6={pink:"#f2a7c3",yellow:"#f5d76e",red:"#d9534f",green:"#6dbb6d",blue:"#5b8fd9",orange:"#f0a04b",purple:"#9b72cf",black:"#222222",grey:"#9a9a9a",gray:"#9a9a9a"};var V8={red:"#c8372d",orange:"#e8742a",yellow:"#f2c230",green:"#3f8f4a","dark green":"#24582f","light green":"#8cc06a",blue:"#2f64b5","dark blue":"#1d3570","light blue":"#86b6e3",navy:"#1f2d55",teal:"#2a8c88",purple:"#7a4aa0",pink:"#ec8fb2",brown:"#7a4e2d",tan:"#d2b48c",cream:"#f3e9cf",white:"#f7f7f4",black:"#222222",grey:"#8f8f8f",gray:"#8f8f8f",silver:"#c0c4c8",gold:"#c9a227",copper:"#b87333",skin:"#f1c9a5","light grey":"#cfcfca","light gray":"#cfcfca","dark grey":"#4a4a4a","dark gray":"#4a4a4a","light brown":"#b07f4f","dark brown":"#4a2e1a",beige:"#e9d6b4",peach:"#f6b892","light pink":"#f8cbd8",maroon:"#7a1f2b","light yellow":"#f8e48a",lime:"#9ccc3c",olive:"#6b7a2f"};function L3(n){let e=n.trim().toLowerCase();return/^#[0-9a-f]{6}$/.test(e)?e:V8[e.replace(/\s+/g," ")]}var l5={flame:"#ff9a3c",candle:"#ff9a3c",warm:"#ffc27a","warm white":"#ffd9a0",white:"#fff4e5","cool white":"#eef3ff"};function s6(n){let e=n.trim().toLowerCase().replace(/\s+/g," ");return l5[e]??L3(e)}var G2={diameter:39,height:16,flame:10},O8=(n,e)=>[n[0]-e[0],n[1]-e[1],n[2]-e[2]],F8=n=>Math.hypot(n[0],n[1],n[2]),r6=(n,e)=>[(n[0]+e[0])/2,(n[1]+e[1])/2,(n[2]+e[2])/2];function i6(n){let e={step:n.step,...n.label!==void 0&&{label:n.label}},t=O8(n.to,n.from),c=F8(t);if(n.kind==="tealight"){let a=c>0?[t[0]/c,t[1]/c,t[2]/c]:[0,0,1],r=[n.to[0]+a[0]*G2.flame,n.to[1]+a[1]*G2.flame,n.to[2]+a[2]*G2.flame];return[{from:r,to:r,color:l5.flame,lumens:12,flicker:!0,source:"tealight",...e}]}if(n.kind==="led"){let a=c>20,r=r6(n.from,n.to);return[{from:a?n.from:r,to:a?n.to:r,color:l5["warm white"],lumens:a?Math.round(c*2)/10:20,flicker:!1,source:"led",...e}]}if(n.kind==="bulb"){let a=r6(n.from,n.to);return[{from:a,to:a,color:l5["warm white"],lumens:100,flicker:!1,source:"bulb",...e}]}return[]}var f4=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function K0(n,e){let{tokens:t,comments:c}=B2(n,e),a=new d4(t),r=[];for(;!a.at("eof");)r.push(...a.statement());return{program:{body:r},comments:c}}var A3=class A3{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,t,c=0){let a=this.peek(c);return a.type===e&&(t===void 0||a.value===t)}isP(e,t=0){return this.at("punct",e,t)}isK(e,t=0){return this.at("id",e,t)}next(){return this.tokens[this.i++]}fail(e,t=this.peek()){let c=t.type==="eof"?"end of file":`"${t.value}"`;throw new X(`${e}, found ${c}`,t.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"||f4.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 t of e)t.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 t=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(t=this.next().value);let c=this.peek();(c.type!=="id"||f4.has(c.value))&&this.fail("Expected a statement"),this.next();let a=this.args(),r=this.body();return[{kind:"call",name:c.value,args:a,children:r,modifier:t,pos:c.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let e=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),e.push(...this.statement());return this.next(),e}return this.statement()}params(){this.expectP("(");let e=[];for(;!this.isP(")");){let t=this.ident(),c=null;this.isP("=")&&(this.next(),c=this.expr()),e.push({name:t.value,default:c,pos:t.pos}),this.separator(")")}return this.next(),e}args(){this.expectP("(");let e=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let t=this.next();this.next(),e.push({name:t.value,value:this.expr(),pos:t.pos})}else e.push({name:null,value:this.expr()});this.separator(")")}return this.next(),e}assigns(){this.expectP("(");let e=[];for(;!this.isP(")");){let t=this.ident();this.expectP("="),e.push({name:t.value,value:this.expr(),pos:t.pos}),this.separator(")")}return this.next(),e}expr(){let e=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let c=this.params(),a=this.expr();return{kind:"lambda",params:c,body:a,pos:e.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let c=this.assigns(),a=this.expr();return{kind:"let",assigns:c,body:a,pos:e.pos,end:this.last()}}if(this.at("id")&&(e.value==="assert"||e.value==="echo")&&this.isP("(",1)){let c=this.i;this.next();let a={kind:"call",callee:{kind:"var",name:e.value,pos:e.pos},args:this.args(),pos:e.pos};if(this.startsValue())return{kind:"chain",check:a,body:this.expr(),pos:e.pos};this.i=c}let t=this.binary(0);if(this.isP("?")){this.next();let c=this.expr();this.expectP(":");let a=this.expr();return{kind:"ternary",cond:t,then:c,else:a,pos:e.pos}}return t}binary(e){if(e>=A3.LEVELS.length)return this.unary();let t=this.binary(e+1);for(;this.at("punct")&&A3.LEVELS[e].includes(this.peek().value);){let c=this.next(),a=this.binary(e+1);t={kind:"binary",op:c.value,left:t,right:a,pos:c.pos}}return t}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 t=this.next();return{kind:"binary",op:"^",left:e,right:this.unary(),pos:t.pos}}return e}postfix(){let e=this.primary();for(;;){let t=this.peek();if(this.isP("("))e={kind:"call",callee:e,args:this.args(),pos:e.pos};else if(this.isP("[")){this.next();let c=this.expr();this.expectP("]"),e={kind:"index",target:e,index:c,pos:t.pos}}else if(this.isP("."))this.next(),e={kind:"member",target:e,name:this.ident().value,pos:t.pos};else return e}}primary(){let e=this.peek();if(e.type==="num"){this.next();let t=/(mm|cm|m|in|ft)$/.exec(e.value);return t?{kind:"num",value:Number(e.value.slice(0,-t[1].length)),unit:t[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}):(f4.has(e.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:e.value,pos:e.pos});if(this.isP("(")){this.next();let t=this.expr();return this.expectP(")"),t}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let e=this.expectP("{"),t=[];for(;!this.isP("}");){let c=this.ident();if(t.some(a=>a.name===c.value))throw new X(`Field ${c.value} is given twice`,c.pos);if(this.expectP("="),t.push({name:c.value,value:this.expr(),pos:c.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:t,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 t=this.expr();if(this.isP(":")){this.next();let a=null,r=this.expr();return this.isP(":")&&(this.next(),a=r,r=this.expr()),this.expectP("]"),{kind:"range",start:t,step:a,end:r,pos:e.pos}}let c=[{kind:"item",expr:t}];return this.listRest(c,e.pos)}return this.listRest([],e.pos)}listRest(e,t){if(e.length){if(this.isP("]"))return this.next(),{kind:"list",items:e,pos:t};this.separator("]")}for(;!this.isP("]");)e.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:e,pos:t}}listItem(){let e=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let t=this.assigns(),c=this.listItem();return{kind:"for",assigns:t,body:c,pos:e.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let t=this.expr();this.expectP(")");let c=this.listItem(),a=null;return this.isK("else")&&(this.next(),a=this.listItem()),{kind:"if",cond:t,then:c,else:a}}if(this.isK("let")&&this.isP("(",1)){this.next();let t=this.assigns(),c=this.listItem();return{kind:"let",assigns:t,body:c,pos:e.pos,end:this.last()}}if(this.isK("each"))return this.next(),{kind:"each",expr:this.expr()};if(this.isP("(")&&(this.isK("for",1)||this.isK("if",1))){this.next();let t=this.listItem();return this.expectP(")"),t}return{kind:"item",expr:this.expr()}}};A3.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]];var d4=A3;var E=(n,e,t)=>({name:n,...t!==void 0&&{default:t},...e&&{doc:e}}),W=(n,e,t)=>({...E(n,e,t),named:!0}),p4="max(3 * $thickness, 6)",h5=[E("value")],_8=[E("x")],w0=(n,e)=>({name:n,kind:"function",params:_8,section:"Numbers and vectors",doc:e}),A2=(n,e)=>({name:n,kind:"function",params:h5,section:"Types",doc:`Whether the value is ${e}`}),m4=(n,e)=>({name:n,kind:"function",params:[E("text","The text to measure",'""'),E("size","Font size in millimetres","10"),E("font","Font name","$font"),W("halign","left, center or right",'"left"'),W("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),W("spacing","Letter spacing factor","1"),W("fit","Measure at the size that fits this width, or [width, cap height]")],section:"Text measurements",doc:e}),u5=[{name:"rect",kind:"module",params:[E("size","A number, or [width, height]","1"),E("center","Centre the rectangle on the origin instead of its corner","false"),W("r","Corner radius","0")],section:"Shapes",doc:"A rectangle with its corner at the origin"},{name:"square",kind:"module",params:[E("size","A number, or [width, height]","1"),E("center","Centre the square on the origin instead of its corner","false"),W("r","Corner radius","0")],section:"Shapes",doc:"Another name for rect()"},{name:"circle",kind:"module",params:[E("r","Radius","1"),W("d","Diameter, instead of r")],section:"Shapes",doc:"A circle centred on the origin"},{name:"ellipse",kind:"module",params:[E("r","[rx, ry], or one radius for both","1"),W("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:[E("n","Number of corners","6"),E("r","Distance to the corners","10")],section:"Shapes",doc:"A regular polygon centred on the origin"},{name:"star",kind:"module",params:[E("n","Number of points","5"),E("r","Radius of the points","10"),E("inner","Radius between the points","r * 0.45")],section:"Shapes",doc:"A star centred on the origin"},{name:"polygon",kind:"module",params:[E("points","A list of [x, y] points"),E("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:[E("d",'SVG path data, as "M0 0 L10 0 L5 8 Z"'),W("fill",'"evenodd" or "nonzero"','"evenodd"'),W("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:[E("text","The text",'""'),E("size","Font size in millimetres","10"),E("font","Font name","$font"),W("halign","left, center or right",'"left"'),W("valign","baseline, top, center, bottom, or cap (capitals centred on y = 0)",'"baseline"'),W("spacing","Letter spacing factor","1"),W("fit","Shrink the size so the text is no wider than this, or fits [width, cap height]"),W("weight",'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)','"regular"'),W("bridge","Join every island (an i's dot, an accent, a stencil's counter) to the rest with a strip this wide"),W("weld","Slide each word's letters together into one piece, as a script name is cut; a number is how far each overlaps the one before, in mm","false"),W("underline","With weld: a bar this high under the baseline, joining the words"),W("lines","Break the text at spaces into up to this many lines; with fit, as many as let it be biggest","1"),W("line_spacing","The distance between lines, as a share of the usual","1"),W("path","Lay the text along these [x, y] points, each letter turned to the path, centred on it"),W("arc","Lay the text round a circle of this radius about the origin: over the top, or along the bottom when less than 0")],section:"Shapes",doc:"Text as shapes; the font must be available to the renderer"},{name:"line",kind:"module",params:[E("from","Start point","[0, 0]"),E("to","End point","[10, 0]"),E("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:[E("points","A list of [x, y] points"),E("closed","Join the last point to the first","false")],section:"Shapes",doc:"Lines through a list of points"},{name:"arc",kind:"module",params:[E("r","Radius","10"),E("start","Start angle in degrees","0"),E("end","End angle in degrees","90")],section:"Shapes",doc:"An arc line around the origin"},{name:"translate",kind:"module",params:[E("v","[x, y]","[0, 0]")],children:!0,section:"Transforms",doc:"Move the children by x and y"},{name:"rotate",kind:"module",params:[E("a","Angle in degrees, anticlockwise","0"),W("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:[E("v","One factor, or [sx, sy]","1")],children:!0,section:"Transforms",doc:"Scale the children"},{name:"mirror",kind:"module",params:[E("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:[E("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:[E("r","Grow (positive) or shrink areas with rounded corners"),W("delta","Grow or shrink areas with sharp corners","0"),W("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:[E("spacing","Distance between copies, a number or [x, y]","10"),E("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:[E("points","The [x, y] points the curve goes through"),E("width","Make an area this wide along the curve, instead of a line"),W("steps","Points between each two given ones","8"),W("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:[E("angle","Direction of the lines, in degrees from +x","45"),E("pitch","Distance between the lines","5"),E("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:[E("field","The direction at a point: function(p) giving degrees, a vector [x, y], or undef where lines stop; or one angle"),E("spacing","Distance between neighbouring lines","2"),E("step","Length of each step along a line: smaller follows the field more closely","min(0.5, spacing / 4)"),W("min_length","Lines shorter than this are left out","spacing * 2"),W("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:[E("field","The height at a point: function(p) giving a number, or undef for none"),E("levels","How many levels, spread evenly between the lowest and highest, or a list of heights","10"),W("interval","Instead of levels: every multiple of this height"),W("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:[E("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:[E("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:[E("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:[E("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:[E("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:[E("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:[E("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:[E("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:[E("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:[E("name","Layer name"),E("mode",'"cut", "line", "fill", "guide" or "paint" (shown in 3D, not cut)'),E("color",'Colour in the output, as "#00aa00" or a name, as "red"'),W("order","Where it goes among the custom layers in the files, lowest first","0"),W("bleed","How far past the part's edge it may print","0"),W("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:[E("name","Part name",'"part"'),E("qty","Number of copies to cut","1"),W("at","Where the part goes in the assembled view, [x, y, z]"),W("rotate","How the part is turned in the assembled view, [x, y, z] in degrees"),W("stack","Layers glued in a stack at each placement, one thickness apart","1"),W("mirror","Cut the part mirrored left to right, its text still reading","false"),W("material","The material it is cut from, as material(name = ...) sets it"),W("pieces",'How many separate pieces it cuts into, as a pair of eyes, or "any": no warning that it is in pieces',"1"),W("paint",'Its colour in the 3D view and the print layout, as "red" or "#c8372d"; the part stays on the sheet of its material'),W("bend","Living hinge bends in the assembled view: [x0, x1, angle] or a list"),W("fold","Folds along any line in the assembled view, as for card: [from, to, angle] or a list; more than 0 folds towards the top face"),W("fold_open","How far the folds are folded: 0 lies flat, 1 as their angles say","1"),W("hang","The point [x, y] on the part it hangs from, at `at`: it swings in its own plane until its weight is below"),W("cord","The cord it hangs on, in mm; 0 for a ring or pin","0"),W("split","Cut a part too big for the bed into pieces joined by jigsaw knobs: true for the sheet, or [width, height]"),W("on","The name of a bent part this one is glued to, to move with it"),W("slots","Names of parts whose tabs pass through this one: their slots are cut"),W("clearance","Added to the slots, in total across each","0.1"),W("slot_extra","Each slot swept [dx, dy] further in this part, for a hook that goes in and drops"),W("halving","Names of parts this one crosses: both take a slot from opposite sides, meeting halfway"),W("bores","Labels or kinds of hardware rods passing through this one: holes are cut where they cross it"),W("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"'),W("glue","The name of a part this one is glued flat onto; at and rotate are then on its face"),W("face",'The face of the glue part it goes on: "top" or "bottom"','"top"'),W("press_fit","Pressed into the glue part, as an inlay: they overlap on purpose, so they are not checked against each other","false")],children:!0,section:"Parts and sheets",doc:"A named part, with its thickness, kerf and material"},{name:"place",kind:"module",params:[E("at","Where the parts inside go, [x, y, z]","[0, 0, 0]"),E("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:[E("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:[E("text","What to do in this step",'""'),E("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:[E("kind",'What it is, as "dowel", "screw", "magnet", "elastic" or "paper"','"dowel"'),E("from","One end, [x, y, z]; a ball sits midway between from and to"),E("to","The other end, [x, y, z]; a ball may leave it out"),E("size","Diameter, or [width, height] for a flat section","6"),W("up","The direction a [width, height] section's height points"),W("sides","Sides of a round section in the 3D view; 0 makes a ball","24"),W("shape",'"rod", or "ball" for a bulb, a marble or a bead','"rod"'),W("label","The name in the hardware list"),W("mass","Its weight in grams, for the check that the model stands, as an egg in a holder")],children:!0,section:"Parts and sheets",doc:"Hardware the assembly needs, in the parts list and the 3D view"},{name:"light",kind:"module",params:[E("at","Where the light is, [x, y, z]","[0, 0, 0]"),E("color",`Its colour: "warm white", "white", "cool white", "warm", "flame", a colour's name or "#ffd9a0"`,'"warm white"'),E("lumens","How much light it gives off: a tealight is about 12","20"),W("to","The other end of a strip of light, [x, y, z]: it lights all along"),W("flicker","A flame: it flickers in the 3D view","false"),W("label","Its name in 3D files")],children:!0,section:"Parts and sheets",doc:"A light source in the 3D view and GLB files, with nothing to show for it"},{name:"material",kind:"module",params:[E("thickness","Sets $thickness"),E("kerf","Sets $kerf"),E("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:[E("size","[width, height]"),E("edges",'"out", "in" or "flat", or [bottom, right, top, left]','"out"'),E("finger","Finger width",p4)],section:"Joinery",doc:"A rectangle with finger joints, notched $thickness deep"},{name:"finger_holes",kind:"module",params:[E("length","Length of the edge that plugs in"),E("edge",'"out" or "in", the kind of edge that plugs in','"out"'),E("finger","Finger width",p4)],section:"Joinery",doc:"A row of slots along x for a finger edge to plug into"},{name:"tslot",kind:"module",params:[E("d","Screw diameter","3"),E("length","Screw length into the panel","12"),E("nut","Nut size, [width, height]","[d * 1.85, d * 0.8]"),E("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:[E("size","[width, height]"),E("spacing","Distance between the rows of cuts","1.5"),E("bridge","Uncut length between cuts","3"),E("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:[E("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:[E("condition","Stops the program when false"),E("message","Says why")],section:"Other",doc:"Stop with an error when the condition is false"},w0("abs","Absolute value"),w0("sign","Sign as -1, 0 or 1"),w0("floor","Round down"),w0("ceil","Round up"),w0("round","Round to the nearest integer, halves away from zero"),w0("sqrt","Square root"),w0("exp","e raised to x"),w0("ln","Natural logarithm"),{name:"log",kind:"function",params:[E("x"),E("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"},w0("sin","Sine of an angle in degrees"),w0("cos","Cosine of an angle in degrees"),w0("tan","Tangent of an angle in degrees"),w0("asin","Inverse sine, in degrees"),w0("acos","Inverse cosine, in degrees"),w0("atan","Inverse tangent, in degrees"),{name:"atan2",kind:"function",params:[E("y"),E("x")],section:"Numbers and vectors",doc:"The angle of the point [x, y] from the x axis, in degrees"},{name:"pow",kind:"function",params:[E("x"),E("y")],section:"Numbers and vectors",doc:"x raised to y"},{name:"min",kind:"function",params:[E("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:[E("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:[E("x"),E("low"),E("high")],section:"Numbers and vectors",doc:"x limited to the interval from low to high"},{name:"lerp",kind:"function",params:[E("a"),E("b"),E("t","0 gives a, 1 gives b")],section:"Numbers and vectors",doc:"Interpolate between numbers or vectors"},{name:"train_for",kind:"function",params:[E("ratio","Turns in for one turn out; under 1 speeds up"),E("stages","Pairs of gears, 1 to 3","2"),E("pinion","Fewest and most teeth of the small gears","[10, 20]"),E("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:[E("v")],section:"Numbers and vectors",doc:"The length of a vector"},{name:"cross",kind:"function",params:[E("a"),E("b")],section:"Numbers and vectors",doc:"Cross product: a number for 2D vectors, a vector for 3D ones"},{name:"path_length",kind:"function",params:[E("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:[E("points","A list of [x, y] points"),E("d","How far to move it: to the left going along it, or the right when less than 0"),E("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:[E("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:[E("points","A closed outline of [x, y] points, or a list of outlines"),E("x","The vertical line x = this"),E("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:[E("points","A list of [x, y] points"),E("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:[E("points","A list of [x, y] points"),E("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:[E("d",'SVG path data, as "M0 0 L10 0 A5 5 0 0 1 20 0"'),E("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:[E("points","The [x, y] points the curve goes through"),E("steps","Points between each two given ones","8"),E("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:[E("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:[E("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:[E("x","Where the part's own x axis points"),E("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:h5,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:[E("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:[E("a","A record"),E("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:h5,section:"Lists and strings",doc:"A list or string in reverse order"},{name:"sort",kind:"function",params:[E("values","A list of numbers, strings or lists of them"),E("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:[E("values","A list"),E("initial","The value to start from"),E("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:[E("values","A list"),E("initial","The value to start from"),E("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:[E("values","A list of numbers")],section:"Lists and strings",doc:"The sum of a list of numbers"},{name:"slice",kind:"function",params:[E("value","A list or string"),E("start","First index","0"),E("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:[E("text")],section:"Lists and strings",doc:"The first character's Unicode code point"},{name:"upper",kind:"function",params:[E("text")],section:"Lists and strings",doc:"Text in capitals"},{name:"lower",kind:"function",params:[E("text")],section:"Lists and strings",doc:"Text in small letters"},{name:"split",kind:"function",params:[E("text"),E("separator",void 0,'" "')],section:"Lists and strings",doc:"Text split into a list of strings"},{name:"join",kind:"function",params:[E("values"),E("separator",void 0,'""')],section:"Lists and strings",doc:"Values joined into one string"},{name:"search",kind:"function",params:[E("value"),E("list","A list or string")],section:"Lists and strings",doc:"Index of the first equal item, or undef"},{name:"contains",kind:"function",params:[E("value","A list or string"),E("item")],section:"Lists and strings",doc:"Whether a list contains an item or a string contains a substring"},{name:"lookup",kind:"function",params:[E("x"),E("table","A list of [x, y] pairs")],section:"Lists and strings",doc:"Interpolate in a table; outside it, the nearest end"},A2("is_num","a number other than NaN"),A2("is_string","a string"),A2("is_bool","true or false"),A2("is_list","a list"),A2("is_undef","undef"),A2("is_function","a function"),A2("is_record","a record, as {name = value}"),{name:"type_of",kind:"function",params:h5,section:"Types",doc:"The type name: number, string, boolean, undef, list, range, function or record"},{name:"noise",kind:"function",params:[E("x","Where to read the noise: a number, or a point [x, y] or [x, y, z]"),E("y",void 0,"0"),E("z","A third axis: step it to get a related but different pattern","0"),W("seed","A different seed gives a different pattern","1"),W("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:[E("min"),E("max"),E("count"),E("seed","The same seed gives the same list","1")],section:"Random values",doc:"A list of count numbers between min and max"},m4("text_width","The advance width of the text, including spacing"),m4("text_metrics","The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),m4("text_size","The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"),{name:"finger_count",kind:"function",params:[E("length","Edge length"),E("finger","Finger width",p4)],section:"Joint dimensions",doc:"The odd number of fingers finger_rect() puts on an edge of that length"}],D8=new Map(u5.map(n=>[n.name,n])),j2=n=>D8.get(n);function f5(n){let e=n.params.map(t=>t.default===void 0?t.name:`${t.name} = ${t.default}`);return n.rest&&e.push("..."),`${n.name}(${e.join(", ")})`}var J0={"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.
|
|
@@ -198,6 +198,112 @@ module grid_dividers(size, cols = 2, rows = 2, clearance = 0.15, gap = 0.5, scoo
|
|
|
198
198
|
slotted_divider(d - 2 * gap, h, rows > 1 ? [for (i = [1:rows - 1]) d * i / rows - gap] : [],
|
|
199
199
|
"bottom", clearance, scoops ? rows : 0);
|
|
200
200
|
}
|
|
201
|
+
`,"kerf/drawers":`// kerf/drawers: a carcass of small numbered drawers in a grid, as for an
|
|
202
|
+
// advent calendar, behind a fa\xE7ade of any shape.
|
|
203
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
204
|
+
//
|
|
205
|
+
// The carcass is a finger-jointed box open at the front, shelves and
|
|
206
|
+
// walls halved into each other inside it, and a drawer in each cell
|
|
207
|
+
// with its number engraved on the front and a notch or hole to pull it by.
|
|
208
|
+
// Drawn in the assembly with the carcass's front left bottom corner at the
|
|
209
|
+
// origin, the drawers facing -y.
|
|
210
|
+
|
|
211
|
+
use <kerf/dividers>
|
|
212
|
+
|
|
213
|
+
// The outer size [width, height, depth] of a carcass of \`cols\` by \`rows\`
|
|
214
|
+
// cells, each cell [w, h] inside, \`depth\` deep
|
|
215
|
+
function drawers_size(cols, rows, cell, depth) =
|
|
216
|
+
[cols * cell[0] + (cols + 1) * $thickness, rows * cell[1] + (rows + 1) * $thickness, depth];
|
|
217
|
+
|
|
218
|
+
// The number on each drawer, row by row from the top left: \`numbers\` if
|
|
219
|
+
// given, else 1 up, in an order shuffled by \`shuffle\` (a seed) when given
|
|
220
|
+
function drawers_numbers(n, numbers, shuffle) =
|
|
221
|
+
!is_undef(numbers) ? numbers
|
|
222
|
+
: is_undef(shuffle) ? [for (i = [1:n]) i]
|
|
223
|
+
: let (keys = rands(0, 1, n, shuffle))
|
|
224
|
+
[for (k = sort([for (i = [0:n - 1]) [keys[i], i + 1]])) k[1]];
|
|
225
|
+
|
|
226
|
+
// A carcass of \`cols\` by \`rows\` drawers, each cell \`cell\` = [w, h] inside
|
|
227
|
+
// and \`depth\` deep. Drawers run on the shelves \`ease\` mm clear all round,
|
|
228
|
+
// and pull out \`open\` of their depth in the assembled view. \`pull\` is
|
|
229
|
+
// "notch" (a dip in the front's top edge), "hole" (a finger hole) or
|
|
230
|
+
// "none"; numbers are engraved on the fronts unless \`numbers\` is false.
|
|
231
|
+
// Children are a fa\xE7ade, drawn on the carcass's front from its bottom left
|
|
232
|
+
// corner: the drawers' openings are cut through it and it is glued on.
|
|
233
|
+
module drawers(cols = 4, rows = 6, cell = [40, 30], depth = 60, numbers, shuffle, pull = "notch", ease = 0.8, clearance = 0.15, open = 0, font_size, label = "") {
|
|
234
|
+
t = $thickness;
|
|
235
|
+
function n(s) = label == "" ? s : str(label, " ", s);
|
|
236
|
+
size = drawers_size(cols, rows, cell, depth);
|
|
237
|
+
W = size[0];
|
|
238
|
+
H = size[1];
|
|
239
|
+
D = depth;
|
|
240
|
+
assert(cell[1] > 3 * t + 6, str("drawers(): a cell must be more than ", 3 * t + 6, " mm high for this thickness"));
|
|
241
|
+
assert(cell[0] > 4 * t + 6, str("drawers(): a cell must be more than ", 4 * t + 6, " mm wide for this thickness"));
|
|
242
|
+
assert(open >= 0 && open <= 0.6, "drawers(): open must be from 0 to 0.6, so the drawers stay in");
|
|
243
|
+
facade = $children > 0;
|
|
244
|
+
labels = numbers == false ? [] : drawers_numbers(cols * rows, numbers, shuffle);
|
|
245
|
+
step("Glue up the carcass") {
|
|
246
|
+
part(n("carcass floor"), at = [0, 0, 0]) finger_rect([W, D], ["flat", "out", "out", "out"]);
|
|
247
|
+
part(n("carcass top"), at = [0, 0, H - t]) finger_rect([W, D], ["flat", "out", "out", "out"]);
|
|
248
|
+
part(n("carcass back"), at = [0, D, 0], rotate = [90, 0, 0]) finger_rect([W, H], ["in", "out", "in", "out"]);
|
|
249
|
+
part(n("carcass side"), qty = 2, at = [[0, 0, 0], [W - t, 0, 0]], rotate = [90, 0, 90])
|
|
250
|
+
finger_rect([D, H], ["in", "in", "in", "flat"]);
|
|
251
|
+
}
|
|
252
|
+
// Shelves and walls halve into each other: each shelf slotted from the
|
|
253
|
+
// back, each wall from the front, half the depth; they stop 0.3 mm short
|
|
254
|
+
// of the carcass all round
|
|
255
|
+
g = 0.3;
|
|
256
|
+
inner = D - t - g;
|
|
257
|
+
walls = [for (i = [1:cols - 1]) i * (cell[0] + t) + t / 2];
|
|
258
|
+
shelves = [for (j = [1:rows - 1]) j * (cell[1] + t) + t / 2];
|
|
259
|
+
step("Slot the shelves and walls together and slide them in") {
|
|
260
|
+
if (rows > 1)
|
|
261
|
+
part(n("shelf"), qty = rows - 1, at = [for (z = shelves) [t + g, 0, z - t / 2]])
|
|
262
|
+
slotted_divider(W - 2 * t - 2 * g, inner, cols > 1 ? [for (x = walls) x - t - g] : [], "top", clearance);
|
|
263
|
+
if (cols > 1)
|
|
264
|
+
part(n("wall"), qty = cols - 1, at = [for (x = walls) [x + t / 2, 0, t + g]], rotate = [0, -90, 0])
|
|
265
|
+
slotted_divider(H - 2 * t - 2 * g, inner, rows > 1 ? [for (z = shelves) z - t - g] : [], "bottom", clearance);
|
|
266
|
+
}
|
|
267
|
+
if (facade)
|
|
268
|
+
step("Glue on the front")
|
|
269
|
+
part(n("front"), at = [0, 0, 0], rotate = [90, 0, 0])
|
|
270
|
+
difference() {
|
|
271
|
+
children();
|
|
272
|
+
for (i = [0:cols - 1], j = [0:rows - 1])
|
|
273
|
+
// The drawer's front, ease / 2 clear all round
|
|
274
|
+
translate([t + i * (cell[0] + t) + ease / 2, t + j * (cell[1] + t) - ease / 2])
|
|
275
|
+
rect([cell[0] - ease, cell[1]]);
|
|
276
|
+
}
|
|
277
|
+
// Each drawer's box, its front flush with the carcass or the fa\xE7ade
|
|
278
|
+
dw = cell[0] - 2 * ease;
|
|
279
|
+
dh = cell[1] - ease;
|
|
280
|
+
dd = D - t - 2;
|
|
281
|
+
y0 = (facade ? -t : 0) - open * dd;
|
|
282
|
+
step("Glue up each drawer and slide it in")
|
|
283
|
+
for (j = [0:rows - 1], i = [0:cols - 1]) {
|
|
284
|
+
k = (rows - 1 - j) * cols + i;
|
|
285
|
+
x = t + i * (cell[0] + t) + ease;
|
|
286
|
+
z = t + j * (cell[1] + t);
|
|
287
|
+
num = len(labels) ? labels[k] : undef;
|
|
288
|
+
name = str(n("drawer"), " ", is_undef(num) ? k + 1 : num);
|
|
289
|
+
part(str(name, " floor"), at = [x, y0, z]) finger_rect([dw, dd], "out");
|
|
290
|
+
part(str(name, " front"), at = [x, y0 + t, z], rotate = [90, 0, 0]) {
|
|
291
|
+
difference() {
|
|
292
|
+
finger_rect([dw, dh], ["in", "out", "flat", "out"]);
|
|
293
|
+
if (pull == "notch") translate([dw / 2, dh]) circle(d = min(18, dw / 2, (dh - t) * 0.8));
|
|
294
|
+
if (pull == "hole") translate([dw / 2, dh * 0.72]) circle(d = min(12, dh * 0.3, dw / 3));
|
|
295
|
+
}
|
|
296
|
+
if (!is_undef(num))
|
|
297
|
+
engrave() translate([dw / 2, pull == "hole" ? dh * 0.36 : dh * 0.42])
|
|
298
|
+
text(str(num), size = is_undef(font_size) ? min(dh * 0.45, dw * 0.4) : font_size,
|
|
299
|
+
fit = [dw * 0.7, pull == "hole" ? dh * 0.4 : dh * 0.5], halign = "center", valign = "center");
|
|
300
|
+
}
|
|
301
|
+
part(str(name, " back"), at = [x, y0 + dd, z], rotate = [90, 0, 0])
|
|
302
|
+
finger_rect([dw, dh], ["in", "out", "flat", "out"]);
|
|
303
|
+
part(str(name, " side"), qty = 2, at = [[x, y0, z], [x + dw - t, y0, z]], rotate = [90, 0, 90])
|
|
304
|
+
finger_rect([dd, dh], ["in", "in", "flat", "in"]);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
201
307
|
`,"kerf/enclosure":`// kerf/enclosure: boxes with a screwed-on lid, for electronics and parts
|
|
202
308
|
// you need to get back to.
|
|
203
309
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
@@ -279,6 +385,589 @@ module vents(size, slot = 3, pitch = 6) {
|
|
|
279
385
|
translate([0, ends]) circle(d = slot, $fn = 24);
|
|
280
386
|
}
|
|
281
387
|
}
|
|
388
|
+
`,"kerf/figures":`// kerf/figures: layered characters for ornaments, standees, scenes and
|
|
389
|
+
// cards: Christmas, Easter, Halloween and nativity figures and animals.
|
|
390
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
391
|
+
// The figures are drawn for this library; none is copied from other art.
|
|
392
|
+
//
|
|
393
|
+
// A figure is built in layers, as layered wood art is. The "outline" is a
|
|
394
|
+
// backer of its whole silhouette, a border wider than the rest. On it lie
|
|
395
|
+
// the coloured pieces of its "clothes" (a coat, for an animal) and its
|
|
396
|
+
// "face" (skin, bellies, beaks, ears), side by side with a thin gap between
|
|
397
|
+
// them, so the backer shows as lines. On those lie the "details": eyes,
|
|
398
|
+
// noses, buttons. Each layer comes in one or more colours.
|
|
399
|
+
//
|
|
400
|
+
// Each figure is drawn 100 units tall, standing on y = 0 and centred on
|
|
401
|
+
// x = 0, as a list of pieces in painter's order: each piece of clothes or
|
|
402
|
+
// face loses what the pieces after it cover. A piece is [layer, colour,
|
|
403
|
+
// shapes], the shapes a list of:
|
|
404
|
+
// ["c", x, y, r] a circle
|
|
405
|
+
// ["e", x, y, rx, ry, angle] an ellipse, turned by angle
|
|
406
|
+
// ["k", x1, y1, x2, y2, r1, r2] a round-ended stroke from one end
|
|
407
|
+
// to the other, r1 wide at the first
|
|
408
|
+
// and r2 (r1 if left out) at the last
|
|
409
|
+
// ["r", x, y, w, h, r, angle] a rectangle round its centre, its
|
|
410
|
+
// corners rounded by r
|
|
411
|
+
// ["p", points] a polygon
|
|
412
|
+
// ["s", points] a closed smooth curve through points
|
|
413
|
+
// ["a", x, y, r, a0, a1, w] an arc w wide, as a smile
|
|
414
|
+
// ["m", shapes] the shapes and their mirror image
|
|
415
|
+
// ["h", shapes] the hull of the shapes
|
|
416
|
+
// ["-", shapes, minus] the shapes less the minus shapes
|
|
417
|
+
|
|
418
|
+
// The casts of figures
|
|
419
|
+
function figure_casts() = ["christmas", "easter", "halloween", "nativity", "animals"];
|
|
420
|
+
|
|
421
|
+
// The names of the figures, every one or those of one cast
|
|
422
|
+
function figure_names(cast) =
|
|
423
|
+
assert(is_undef(cast) || len([for (c = figure_casts()) if (c == cast) c]) > 0,
|
|
424
|
+
str("Unknown cast \\"", cast, "\\". Known: ", join(figure_casts(), ", ")))
|
|
425
|
+
[for (f = FIGURES) if (is_undef(cast) || f[1] == cast) f[0]];
|
|
426
|
+
|
|
427
|
+
// A figure's entry: [name, cast, outline colour, pieces]
|
|
428
|
+
function figure_entry(name) =
|
|
429
|
+
let (k = lower(name), hit = [for (f = FIGURES) if (f[0] == k) f])
|
|
430
|
+
len(hit) ? hit[0] : assert(false, str("Unknown figure \\"", name, "\\". Known: ", join(figure_names(), ", ")));
|
|
431
|
+
|
|
432
|
+
// The parts a figure is built of, as [layer, colour], bottom up: the
|
|
433
|
+
// outline, then each colour of clothes and face, then of details
|
|
434
|
+
function figure_layers(name) =
|
|
435
|
+
let (
|
|
436
|
+
e = figure_entry(name),
|
|
437
|
+
pieces = e[3],
|
|
438
|
+
middle = figure_unique([for (p = pieces) if (p[0] != "details") [p[0], p[1]]]),
|
|
439
|
+
top = figure_unique([for (p = pieces) if (p[0] == "details") [p[0], p[1]]])
|
|
440
|
+
)
|
|
441
|
+
concat([["outline", e[2]]], middle, top);
|
|
442
|
+
|
|
443
|
+
// The list without repeats, in the order first seen
|
|
444
|
+
function figure_unique(list) =
|
|
445
|
+
[for (i = [0:len(list) - 1]) if (len([for (j = [0:i - 1]) if (i > 0 && list[j] == list[i]) 1]) == 0) list[i]];
|
|
446
|
+
|
|
447
|
+
// The shapes of a figure's piece list, in its own units
|
|
448
|
+
module figure_shapes(shapes) {
|
|
449
|
+
for (q = shapes) {
|
|
450
|
+
if (q[0] == "c") translate([q[1], q[2]]) circle(r = q[3]);
|
|
451
|
+
else if (q[0] == "e") translate([q[1], q[2]]) rotate(is_undef(q[5]) ? 0 : q[5]) ellipse(r = [q[3], q[4]]);
|
|
452
|
+
else if (q[0] == "k")
|
|
453
|
+
hull() {
|
|
454
|
+
translate([q[1], q[2]]) circle(r = q[5]);
|
|
455
|
+
translate([q[3], q[4]]) circle(r = is_undef(q[6]) ? q[5] : q[6]);
|
|
456
|
+
}
|
|
457
|
+
else if (q[0] == "r")
|
|
458
|
+
translate([q[1], q[2]]) rotate(is_undef(q[6]) ? 0 : q[6])
|
|
459
|
+
rect([q[3], q[4]], center = true, r = min(is_undef(q[5]) ? 0 : q[5], q[3] / 2 - 0.01, q[4] / 2 - 0.01));
|
|
460
|
+
else if (q[0] == "p") polygon(q[1]);
|
|
461
|
+
else if (q[0] == "s") polygon(spline_points(q[1], closed = true));
|
|
462
|
+
else if (q[0] == "a")
|
|
463
|
+
stroke(q[6]) polyline([for (i = [0:16]) let (a = q[4] + (q[5] - q[4]) * i / 16) [q[1] + q[3] * cos(a), q[2] + q[3] * sin(a)]]);
|
|
464
|
+
else if (q[0] == "m") {
|
|
465
|
+
figure_shapes(q[1]);
|
|
466
|
+
mirror([1, 0]) figure_shapes(q[1]);
|
|
467
|
+
} else if (q[0] == "h") hull() figure_shapes(q[1]);
|
|
468
|
+
else if (q[0] == "-")
|
|
469
|
+
difference() {
|
|
470
|
+
figure_shapes(q[1]);
|
|
471
|
+
figure_shapes(q[2]);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// One layer of a figure: "outline", "clothes", "face" or "details", in
|
|
477
|
+
// every colour or only \`color\`. The outline is \`height\` mm tall, standing
|
|
478
|
+
// on y = 0 and centred on x = 0, \`border\` mm wider all round than the
|
|
479
|
+
// pieces on it; pieces of clothes and face keep \`gap\` mm apart, as do
|
|
480
|
+
// details, and lose any sliver narrower than \`min_width\` mm.
|
|
481
|
+
module figure_layer(name, layer, height = 100, color, border = 2, gap = 0.6, min_width = 1.6) {
|
|
482
|
+
e = figure_entry(name);
|
|
483
|
+
pieces = e[3];
|
|
484
|
+
n = len(pieces);
|
|
485
|
+
middle = [for (k = [0:n - 1]) if (pieces[k][0] != "details") k];
|
|
486
|
+
assert(len([for (l = ["outline", "clothes", "face", "details"]) if (l == layer) l]) > 0,
|
|
487
|
+
str("figure_layer(): layer must be \\"outline\\", \\"clothes\\", \\"face\\" or \\"details\\", got ", layer));
|
|
488
|
+
assert(is_num(height) && height > 2 * border + 1, "figure_layer(): height must be more than twice the border");
|
|
489
|
+
measure() {
|
|
490
|
+
for (k = [0:n - 1]) figure_shapes(pieces[k][2]);
|
|
491
|
+
let (b = $bounds, s = (height - 2 * border) / (b[3] - b[1]), at = [-(b[0] + b[2]) / 2, -b[1]]) {
|
|
492
|
+
if (layer == "outline") {
|
|
493
|
+
offset(r = border) translate([0, border]) scale(s) translate(at)
|
|
494
|
+
for (k = [0:n - 1]) figure_shapes(pieces[k][2]);
|
|
495
|
+
} else {
|
|
496
|
+
// Each piece loses what the pieces after it on its layer cover, a
|
|
497
|
+
// gap wider, and anything narrower than min_width; details stay on
|
|
498
|
+
// the clothes and face
|
|
499
|
+
same = [for (k = [0:n - 1]) if ((pieces[k][0] == "details") == (layer == "details")) k];
|
|
500
|
+
for (k = same)
|
|
501
|
+
if ((layer == "details" || pieces[k][0] == layer) && (is_undef(color) || pieces[k][1] == color))
|
|
502
|
+
offset(r = min_width / 2) offset(r = -min_width / 2)
|
|
503
|
+
difference() {
|
|
504
|
+
intersection() {
|
|
505
|
+
translate([0, border]) scale(s) translate(at) figure_shapes(pieces[k][2]);
|
|
506
|
+
if (layer == "details")
|
|
507
|
+
offset(delta = -gap) translate([0, border]) scale(s) translate(at)
|
|
508
|
+
for (j = middle) figure_shapes(pieces[j][2]);
|
|
509
|
+
}
|
|
510
|
+
offset(delta = gap) translate([0, border]) scale(s) translate(at)
|
|
511
|
+
for (j = same) if (j > k) figure_shapes(pieces[j][2]);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// A figure cut from one sheet, \`height\` mm tall: its outline cut, the
|
|
519
|
+
// lines between its coloured pieces scored and its details engraved
|
|
520
|
+
module figure(name, height = 100, border = 2, gap = 0.6) {
|
|
521
|
+
figure_layer(name, "outline", height, border = border, gap = gap);
|
|
522
|
+
score() for (l = ["clothes", "face"]) outline() figure_layer(name, l, height, border = border, gap = gap);
|
|
523
|
+
engrave() figure_layer(name, "details", height, border = border, gap = gap);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// A figure as layered parts, \`height\` mm tall: the outline at \`at\`, turned
|
|
527
|
+
// by \`rotate\`, its clothes and face glued on it and its details on those,
|
|
528
|
+
// one part for each colour of each layer, painted that colour. The parts
|
|
529
|
+
// are named after \`label\` (the figure's name), as "bunny face pink".
|
|
530
|
+
module figure_parts(name, height = 100, at = [0, 0, 0], rotate = [0, 0, 0], label, border = 2, gap = 0.6, qty = 1) {
|
|
531
|
+
base = is_undef(label) ? lower(name) : label;
|
|
532
|
+
layers = figure_layers(name);
|
|
533
|
+
middle = [for (l = layers) if (l[0] == "clothes" || l[0] == "face") l];
|
|
534
|
+
part(str(base, " outline"), qty = qty, at = at, rotate = rotate, paint = layers[0][1])
|
|
535
|
+
figure_layer(name, "outline", height, border = border, gap = gap);
|
|
536
|
+
// A part too small to cut at this height is left out
|
|
537
|
+
for (l = middle)
|
|
538
|
+
measure() {
|
|
539
|
+
figure_layer(name, l[0], height, l[1], border = border, gap = gap);
|
|
540
|
+
if (!is_undef($bounds))
|
|
541
|
+
part(str(base, " ", l[0], " ", l[1]), qty = qty, glue = str(base, " outline"), paint = l[1], pieces = "any")
|
|
542
|
+
figure_layer(name, l[0], height, l[1], border = border, gap = gap);
|
|
543
|
+
}
|
|
544
|
+
figure_details(name, height, base, qty, border, gap);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// A figure's details as painted parts named after \`base\`, glued on the
|
|
548
|
+
// first of its clothes and face parts, from the \`k\`-th, that is big enough
|
|
549
|
+
// to cut at this height
|
|
550
|
+
module figure_details(name, height, base, qty = 1, border = 2, gap = 0.6, k = 0) {
|
|
551
|
+
layers = figure_layers(name);
|
|
552
|
+
middle = [for (l = layers) if (l[0] == "clothes" || l[0] == "face") l];
|
|
553
|
+
if (k < len(middle))
|
|
554
|
+
measure() {
|
|
555
|
+
figure_layer(name, middle[k][0], height, middle[k][1], border = border, gap = gap);
|
|
556
|
+
if (is_undef($bounds)) figure_details(name, height, base, qty, border, gap, k + 1);
|
|
557
|
+
else
|
|
558
|
+
for (l = layers)
|
|
559
|
+
if (l[0] == "details")
|
|
560
|
+
measure() {
|
|
561
|
+
figure_layer(name, "details", height, l[1], border = border, gap = gap);
|
|
562
|
+
if (!is_undef($bounds))
|
|
563
|
+
part(str(base, " details ", l[1]), qty = qty, glue = str(base, " ", middle[k][0], " ", middle[k][1]), paint = l[1], pieces = "any")
|
|
564
|
+
figure_layer(name, "details", height, l[1], border = border, gap = gap);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// The figures: [name, cast, outline colour, pieces], each piece [layer,
|
|
570
|
+
// colour, shapes] in painter's order
|
|
571
|
+
FIGURES = [
|
|
572
|
+
// Christmas
|
|
573
|
+
["santa", "christmas", "dark brown", [
|
|
574
|
+
["clothes", "black", [["m", [["r", -8, 4, 12, 8, 3, 0]]]]],
|
|
575
|
+
["clothes", "red", [
|
|
576
|
+
["h", [["c", -16, 13, 4], ["c", 16, 13, 4], ["c", -12, 42, 8], ["c", 12, 42, 8]]],
|
|
577
|
+
["m", [["k", -15, 44, -24, 26, 6, 5]]]
|
|
578
|
+
]],
|
|
579
|
+
["face", "white", [["r", 0, 12, 40, 6, 3, 0], ["r", 0, 32, 6, 30, 2, 0]]],
|
|
580
|
+
["clothes", "black", [["r", 0, 31, 36, 5, 0, 0], ["m", [["c", -25, 21, 4.5]]]]],
|
|
581
|
+
["face", "white", [["m", [["r", -24, 26.5, 11, 4.5, 2, -20]]]]],
|
|
582
|
+
["face", "skin", [["e", 0, 63, 11, 9.5, 0]]],
|
|
583
|
+
["face", "white", [["s", [[-13, 61], [-11, 52], [-6, 46], [0, 44], [6, 46], [11, 52], [13, 61], [0, 58]]]]],
|
|
584
|
+
["clothes", "red", [["h", [["c", -12, 74, 2.5], ["c", 12, 74, 2.5], ["c", 16, 92, 2]]]]],
|
|
585
|
+
["face", "white", [["r", 0, 72, 30, 6.5, 3.2, 0], ["c", 17, 93, 5]]],
|
|
586
|
+
["details", "black", [["m", [["c", -4.5, 65.5, 1.8]]]]],
|
|
587
|
+
["details", "white", [["m", [["e", -4.2, 58.5, 4.5, 2.3, 12]]]]],
|
|
588
|
+
["details", "pink", [["c", 0, 61.5, 2.3]]],
|
|
589
|
+
["details", "yellow", [["r", 0, 31, 7, 6, 1, 0]]]
|
|
590
|
+
]],
|
|
591
|
+
["elf", "christmas", "dark brown", [
|
|
592
|
+
["clothes", "red", [["m", [["r", -6, 10, 6, 16, 2, 0]]]]],
|
|
593
|
+
["clothes", "dark brown", [["m", [["k", -9, 3.5, -15, 6, 3.5, 2]]]]],
|
|
594
|
+
["clothes", "green", [
|
|
595
|
+
["h", [["c", -10, 42, 6], ["c", 10, 42, 6], ["c", -14, 22, 5], ["c", 14, 22, 5]]],
|
|
596
|
+
["p", [[-19, 22], [-16, 13], [-11, 19], [-6, 13], [-1, 19], [4, 13], [9, 19], [14, 13], [19, 22]]],
|
|
597
|
+
["m", [["k", -14, 44, -21, 28, 5, 4.5]]]
|
|
598
|
+
]],
|
|
599
|
+
["clothes", "black", [["r", 0, 29, 32, 4.5, 0, 0]]],
|
|
600
|
+
["face", "skin", [["m", [["c", -22, 25, 4.2]]]]],
|
|
601
|
+
["face", "skin", [["m", [["p", [[-9, 64], [-20, 70], [-9, 57]]]]], ["c", 0, 61, 11]]],
|
|
602
|
+
["clothes", "green", [["h", [["c", -11, 70, 2.2], ["c", 11, 70, 2.2], ["c", 21, 89, 1.8]]]]],
|
|
603
|
+
["clothes", "red", [["r", 0, 69, 27, 5, 2.5, 0], ["c", 22, 90, 3.5]]],
|
|
604
|
+
["details", "black", [["m", [["c", -4.5, 62, 1.8]]]]],
|
|
605
|
+
["details", "pink", [["m", [["e", -7, 57.5, 2.6, 1.8, 0]]], ["c", 0, 59, 1.8]]],
|
|
606
|
+
["details", "yellow", [["r", 0, 29, 6, 5.5, 1, 0]]]
|
|
607
|
+
]],
|
|
608
|
+
["gnome", "christmas", "dark brown", [
|
|
609
|
+
["clothes", "dark brown", [["m", [["e", -8, 4, 8, 4, 0]]]]],
|
|
610
|
+
["clothes", "blue", [["h", [["c", -13, 9, 4], ["c", 13, 9, 4], ["c", -10, 32, 6], ["c", 10, 32, 6]]]]],
|
|
611
|
+
["face", "white", [["s", [[-15, 48], [15, 48], [13, 32], [7, 18], [0, 12], [-7, 18], [-13, 32]]]]],
|
|
612
|
+
["clothes", "red", [["p", [[-18, 46], [18, 46], [8, 82], [1, 97], [-3, 86]]]]],
|
|
613
|
+
["face", "skin", [["e", 0, 45.5, 6, 5, 0]]],
|
|
614
|
+
["details", "white", [["c", -6, 60, 1.8], ["c", 4, 68, 1.8], ["c", -2, 77, 1.8], ["c", 8, 55, 1.8]]]
|
|
615
|
+
]],
|
|
616
|
+
["angel", "christmas", "dark brown", [
|
|
617
|
+
["clothes", "white", [["m", [["e", -18, 50, 12, 20, -25]]]]],
|
|
618
|
+
["clothes", "light blue", [
|
|
619
|
+
["h", [["c", -6, 46, 6], ["c", 6, 46, 6], ["c", -19, 4, 3], ["c", 19, 4, 3]]]
|
|
620
|
+
]],
|
|
621
|
+
["clothes", "light blue", [["m", [["k", -8, 47, -4, 33, 4.5, 4]]]]],
|
|
622
|
+
["face", "skin", [["c", 0, 31, 4.2]]],
|
|
623
|
+
["face", "yellow", [["c", 0, 64, 12.5], ["m", [["e", -9, 56, 4.5, 8, 0]]]]],
|
|
624
|
+
["face", "skin", [["e", 0, 61, 8.5, 9, 0]]],
|
|
625
|
+
["clothes", "gold", [["-", [["e", 0, 79, 11, 3.8, 0]], [["e", 0, 79, 7, 1.6, 0]]]]],
|
|
626
|
+
["details", "black", [["m", [["c", -3.5, 62, 1.6]]]]],
|
|
627
|
+
["details", "pink", [["m", [["e", -6, 58, 2.2, 1.5, 0]]]]],
|
|
628
|
+
["details", "white", [["c", 0, 24, 2], ["c", -6, 14, 2], ["c", 6, 14, 2]]]
|
|
629
|
+
]],
|
|
630
|
+
["reindeer", "christmas", "dark brown", [
|
|
631
|
+
["clothes", "tan", [["m", [["k", -7, 70, -14, 93, 2.6, 2], ["k", -11, 82, -21, 86, 2.2, 1.8], ["k", -13, 89, -7, 96, 2, 1.6]]]]],
|
|
632
|
+
["clothes", "dark brown", [["m", [["r", -8, 4, 8, 8, 2.5, 0]]]]],
|
|
633
|
+
["clothes", "light brown", [
|
|
634
|
+
["e", 0, 24, 15, 18, 0],
|
|
635
|
+
["m", [["r", -8, 9, 7, 12, 2.5, 0]]],
|
|
636
|
+
["m", [["e", -16, 67, 7.5, 3.5, 25]]],
|
|
637
|
+
["e", 0, 58, 13, 15, 0]
|
|
638
|
+
]],
|
|
639
|
+
["face", "pink", [["m", [["e", -16, 67, 4.5, 1.8, 25]]]]],
|
|
640
|
+
["face", "beige", [["e", 0, 21, 9, 11, 0], ["e", 0, 49, 9, 7, 0]]],
|
|
641
|
+
["clothes", "green", [["r", 0, 40, 26, 6, 3, 0], ["r", 9, 33, 6, 12, 2, -10]]],
|
|
642
|
+
["details", "black", [["m", [["c", -5, 59, 2]]]]],
|
|
643
|
+
["details", "red", [["c", 0, 51.5, 4]]]
|
|
644
|
+
]],
|
|
645
|
+
["gingerbread", "christmas", "dark brown", [
|
|
646
|
+
["clothes", "light brown", [
|
|
647
|
+
["c", 0, 75, 15],
|
|
648
|
+
["r", 0, 39, 26, 36, 6, 0],
|
|
649
|
+
["k", -24, 52, 24, 52, 7, 7],
|
|
650
|
+
["m", [["k", -8, 30, -15, 7, 7, 7]]]
|
|
651
|
+
]],
|
|
652
|
+
["details", "white", [
|
|
653
|
+
["m", [["a", -27, 52, 5, -60, 60, 2], ["a", -15, 8, 5, 25, 155, 2]]],
|
|
654
|
+
["a", 0, 73, 6, 210, 330, 2]
|
|
655
|
+
]],
|
|
656
|
+
["details", "black", [["m", [["c", -5, 78, 2]]]]],
|
|
657
|
+
["details", "red", [["c", 0, 49, 2.8], ["c", 0, 31, 2.8]]],
|
|
658
|
+
["details", "green", [["c", 0, 40, 2.8]]],
|
|
659
|
+
["details", "pink", [["m", [["c", -9, 72, 2]]]]]
|
|
660
|
+
]],
|
|
661
|
+
["snowman", "christmas", "dark brown", [
|
|
662
|
+
["clothes", "dark brown", [["m", [["k", -13, 54, -29, 65, 1.9, 1.4], ["k", -24, 62, -27, 69, 1.4, 1.2]]]]],
|
|
663
|
+
["clothes", "white", [["c", 0, 21, 21], ["c", 0, 51, 15], ["c", 0, 76, 11]]],
|
|
664
|
+
["clothes", "red", [["r", 0, 66, 25, 6, 3, 0], ["r", 8, 57, 6, 14, 2, -10]]],
|
|
665
|
+
["clothes", "black", [["r", 0, 85, 26, 3.5, 1.5, 0], ["r", 0, 93, 16, 14, 1.5, 0]]],
|
|
666
|
+
["clothes", "red", [["r", 0, 88.5, 16, 3, 0, 0]]],
|
|
667
|
+
["details", "black", [["m", [["c", -4, 78, 1.8]]], ["c", 0, 53, 2], ["c", 0, 45, 2], ["c", 0, 26, 2.4]]],
|
|
668
|
+
["details", "orange", [["p", [[0, 76], [0, 72.5], [11, 73.5]]]]],
|
|
669
|
+
["details", "pink", [["m", [["c", -7, 73.5, 1.6]]]]]
|
|
670
|
+
]],
|
|
671
|
+
|
|
672
|
+
// Easter
|
|
673
|
+
["bunny", "easter", "dark grey", [
|
|
674
|
+
["clothes", "light grey", [
|
|
675
|
+
["m", [["k", -9, 64, -15, 93, 6.5, 5.5]]],
|
|
676
|
+
["m", [["e", -11, 5, 10, 5.5, 0]]],
|
|
677
|
+
["e", 0, 26, 19, 21, 0],
|
|
678
|
+
["e", 0, 53, 21, 17, 0]
|
|
679
|
+
]],
|
|
680
|
+
["face", "pink", [["m", [["k", -10, 71, -14.5, 90, 3, 2.5]]]]],
|
|
681
|
+
["face", "white", [["m", [["e", -5, 46, 7, 5.5, 0]]], ["e", 0, 24, 12.5, 13, 0]]],
|
|
682
|
+
["face", "light blue", [["e", 0, 21, 9, 11.5, 0]]],
|
|
683
|
+
["clothes", "light grey", [["m", [["e", -10, 25, 5, 8, -40]]]]],
|
|
684
|
+
["details", "black", [["m", [["c", -8, 56, 2.6]]]]],
|
|
685
|
+
["details", "pink", [["e", 0, 50.5, 3, 2.2, 0]]],
|
|
686
|
+
["details", "yellow", [["m", [["c", -4.5, 15, 1.5]]], ["c", 0, 12.5, 1.5]]]
|
|
687
|
+
]],
|
|
688
|
+
["chick", "easter", "dark brown", [
|
|
689
|
+
["clothes", "yellow", [
|
|
690
|
+
["e", 0, 36, 25, 24, 0],
|
|
691
|
+
["c", 0, 62, 18],
|
|
692
|
+
["k", 0, 78, -4, 89, 3, 1.8],
|
|
693
|
+
["k", 0, 78, 4.5, 87, 3, 1.6]
|
|
694
|
+
]],
|
|
695
|
+
["clothes", "yellow", [["m", [["e", -22, 40, 6.5, 11, 30]]]]],
|
|
696
|
+
["face", "orange", [["h", [["c", -4.5, 59.5, 1.6], ["c", 4.5, 59.5, 1.6], ["c", 0, 53, 1.6]]]]],
|
|
697
|
+
["face", "white", [["p", concat(
|
|
698
|
+
[for (a = [180:10:360]) [27 * cos(a), 27 + 26 * sin(a)]],
|
|
699
|
+
[for (i = [0:8]) [27 - i * 6.75, i % 2 == 0 ? 27 : 34]]
|
|
700
|
+
)]]],
|
|
701
|
+
["details", "black", [["m", [["c", -7, 66, 2.6]]]]],
|
|
702
|
+
["details", "pink", [["m", [["e", -12.5, 58.5, 3.2, 2.2, 0]]]]]
|
|
703
|
+
]],
|
|
704
|
+
["lamb", "easter", "dark grey", [
|
|
705
|
+
["face", "dark grey", [["m", [["r", -10, 9, 6.5, 18, 2.5, 0]]]]],
|
|
706
|
+
["clothes", "cream", [
|
|
707
|
+
["e", 0, 33, 23, 16, 0],
|
|
708
|
+
for (a = [0:30:330]) ["c", 21 * cos(a), 33 + 15 * sin(a), 6.5]
|
|
709
|
+
]],
|
|
710
|
+
["face", "skin", [["m", [["e", -15.5, 61, 8, 3.8, -25]]], ["e", 0, 57, 11.5, 13.5, 0]]],
|
|
711
|
+
["clothes", "cream", [["c", -6.5, 70, 5.5], ["c", 0, 73, 5.5], ["c", 6.5, 70, 5.5]]],
|
|
712
|
+
["details", "black", [["m", [["c", -5, 58, 2.3]]]]],
|
|
713
|
+
["details", "pink", [["e", 0, 50, 3, 2, 0], ["m", [["c", -8, 52.5, 1.8]]]]]
|
|
714
|
+
]],
|
|
715
|
+
|
|
716
|
+
// Halloween
|
|
717
|
+
["ghost", "halloween", "dark grey", [
|
|
718
|
+
["clothes", "white", [
|
|
719
|
+
["h", [["c", 0, 68, 22], ["r", 0, 28, 44, 8, 0, 0]]],
|
|
720
|
+
for (x = [-16.5, -5.5, 5.5, 16.5]) ["c", x, 24, 5.5],
|
|
721
|
+
["m", [["e", -23, 46, 8, 4, 35]]]
|
|
722
|
+
]],
|
|
723
|
+
["details", "black", [["m", [["e", -7.5, 64, 3, 4.5, 0]]], ["e", 0, 51, 4, 5.5, 0]]],
|
|
724
|
+
["details", "pink", [["m", [["e", -13, 57, 3, 2, 0]]]]]
|
|
725
|
+
]],
|
|
726
|
+
["witch", "halloween", "dark brown", [
|
|
727
|
+
["clothes", "black", [["m", [["e", -6, 4, 6, 3.5, 0]]]]],
|
|
728
|
+
["clothes", "purple", [["h", [["c", -6, 44, 6], ["c", 6, 44, 6], ["c", -18, 8, 3], ["c", 18, 8, 3]]]]],
|
|
729
|
+
["clothes", "purple", [["m", [["k", -9, 46, -21, 30, 5, 4]]]]],
|
|
730
|
+
["face", "light green", [["m", [["c", -22, 27, 3.8]]]]],
|
|
731
|
+
["face", "light green", [["c", 0, 62, 10]]],
|
|
732
|
+
["face", "orange", [["m", [["e", -10.5, 56, 4, 10, 10]]]]],
|
|
733
|
+
["clothes", "black", [["r", 0, 71, 38, 4.5, 2.2, -4], ["h", [["c", -10, 72, 2], ["c", 10, 72, 2], ["c", 9, 97, 1.5]]]]],
|
|
734
|
+
["clothes", "purple", [["r", 0, 75.5, 21, 4.5, 0, 0]]],
|
|
735
|
+
["details", "black", [["m", [["c", -4, 63, 1.8]]]]],
|
|
736
|
+
["details", "pink", [["m", [["e", -6.5, 58.5, 2.2, 1.5, 0]]]]],
|
|
737
|
+
["details", "yellow", [["r", 0, 75.5, 5, 4, 0.8, 0]]]
|
|
738
|
+
]],
|
|
739
|
+
["pumpkin", "halloween", "dark brown", [
|
|
740
|
+
["clothes", "green", [["k", 0, 66, 4, 82, 4, 2.8]]],
|
|
741
|
+
["clothes", "orange", [["m", [["e", -15, 34, 17, 32, 0]]]]],
|
|
742
|
+
["clothes", "orange", [["e", 0, 34, 15, 34, 0]]],
|
|
743
|
+
["details", "black", [
|
|
744
|
+
["m", [["p", [[-14, 40], [-4, 40], [-9, 49]]]]],
|
|
745
|
+
["p", [[-3, 33], [3, 33], [0, 37]]],
|
|
746
|
+
["p", [[-17, 25], [-12, 22], [-8, 25], [-4, 20], [0, 24], [4, 20], [8, 25], [12, 22], [17, 25], [12, 15], [-12, 15]]]
|
|
747
|
+
]]
|
|
748
|
+
]],
|
|
749
|
+
["bat", "halloween", "dark grey", [
|
|
750
|
+
["clothes", "black", [
|
|
751
|
+
["m", [["p", [[-4, 52], [-15, 64], [-26, 64], [-36, 56], [-31, 52], [-28, 45], [-22, 48], [-18, 41], [-12, 46], [-6, 41]]]]],
|
|
752
|
+
["e", 0, 48, 9.5, 14, 0],
|
|
753
|
+
["c", 0, 63, 9.5],
|
|
754
|
+
["m", [["p", [[-8.5, 66], [-8, 77], [-2, 70]]]]]
|
|
755
|
+
]],
|
|
756
|
+
["face", "purple", [["e", 0, 45, 5.5, 8.5, 0]]],
|
|
757
|
+
["details", "yellow", [["m", [["c", -3.8, 64, 2.2]]]]],
|
|
758
|
+
["details", "pink", [["m", [["c", -6.5, 59.5, 1.4]]]]]
|
|
759
|
+
]],
|
|
760
|
+
["skeleton", "halloween", "dark grey", [
|
|
761
|
+
["clothes", "black", [
|
|
762
|
+
["m", [["r", -6, 10, 8, 20, 3, 0]]],
|
|
763
|
+
["h", [["c", -9, 45, 5], ["c", 9, 45, 5], ["c", -10, 21, 5], ["c", 10, 21, 5]]],
|
|
764
|
+
["m", [["k", -13, 47, -19, 28, 4.5, 4]]]
|
|
765
|
+
]],
|
|
766
|
+
["face", "white", [
|
|
767
|
+
["r", 0, 32, 3, 24, 1.5, 0],
|
|
768
|
+
["m", [["k", -1, 44, -8.5, 42, 1.4], ["k", -1, 39, -8.5, 37, 1.4], ["k", -1, 34, -7.5, 32, 1.4]]],
|
|
769
|
+
["e", 0, 20, 7, 3.2, 0],
|
|
770
|
+
["m", [["r", -6, 10, 2.8, 15, 1.4, 0], ["k", -14, 45, -18.5, 30, 1.4]]]
|
|
771
|
+
]],
|
|
772
|
+
["face", "white", [["c", 0, 66, 13], ["r", 0, 54, 14, 8, 3, 0]]],
|
|
773
|
+
["details", "black", [["m", [["c", -5, 66, 3.6]]], ["p", [[-1.6, 59.5], [1.6, 59.5], [0, 62.5]]]]]
|
|
774
|
+
]],
|
|
775
|
+
|
|
776
|
+
// Nativity
|
|
777
|
+
["mary", "nativity", "dark brown", [
|
|
778
|
+
["clothes", "blue", [["h", [["c", 0, 64, 13.5], ["c", -18, 4, 3], ["c", 18, 4, 3]]]]],
|
|
779
|
+
["clothes", "white", [["h", [["c", 0, 46, 6], ["c", -9, 4, 3], ["c", 9, 4, 3]]]]],
|
|
780
|
+
["face", "dark brown", [["e", 0, 63, 10, 11.5, 0]]],
|
|
781
|
+
["face", "skin", [["e", 0, 61, 7.5, 8.5, 0], ["e", 0, 36, 5, 4, 0]]],
|
|
782
|
+
["details", "black", [["m", [["c", -3, 62, 1.4]]]]],
|
|
783
|
+
["details", "pink", [["m", [["e", -5, 58, 1.8, 1.2, 0]]]]]
|
|
784
|
+
]],
|
|
785
|
+
["joseph", "nativity", "dark brown", [
|
|
786
|
+
["clothes", "light brown", [["r", 22, 42, 3.2, 84, 1.6, 0]]],
|
|
787
|
+
["clothes", "brown", [["h", [["c", -9, 46, 6], ["c", 9, 46, 6], ["c", -17, 4, 3], ["c", 17, 4, 3]]]]],
|
|
788
|
+
["clothes", "green", [["p", [[-15, 50], [-6, 52], [12, 6], [3, 4]]]]],
|
|
789
|
+
["clothes", "brown", [["k", 7, 49, 18, 45, 4.5, 4]]],
|
|
790
|
+
["face", "skin", [["c", 20, 45, 4]]],
|
|
791
|
+
["face", "beige", [["e", 0, 65, 11, 12.5, 0], ["m", [["r", -9, 54, 5, 14, 2, 0]]]]],
|
|
792
|
+
["face", "skin", [["e", 0, 62, 7.5, 8, 0]]],
|
|
793
|
+
["face", "dark brown", [["-", [["e", 0, 58, 8, 9, 0]], [["r", 0, 66, 20, 12, 0, 0]]]]],
|
|
794
|
+
["clothes", "red", [["r", 0, 71, 21, 3.5, 1.5, 0]]],
|
|
795
|
+
["details", "black", [["m", [["c", -3.2, 63.5, 1.4]]]]]
|
|
796
|
+
]],
|
|
797
|
+
["baby", "nativity", "dark brown", [
|
|
798
|
+
["clothes", "light brown", [["m", [["r", -17, 5, 4, 10, 1, 0]]], ["p", [[-26, 22], [26, 22], [19, 7], [-19, 7]]]]],
|
|
799
|
+
["clothes", "yellow", [["p", [[-27, 21], [-24, 27], [-19, 22], [-14, 28], [-9, 22], [-4, 28], [1, 22], [6, 28], [11, 22], [16, 28], [21, 22], [25, 27], [27, 21]]]]],
|
|
800
|
+
["clothes", "white", [["e", -4, 27, 15, 6, 0]]],
|
|
801
|
+
["clothes", "cream", [["r", -9, 27, 2.5, 11, 1, 0], ["r", -1, 27, 2.5, 12, 1, 0]]],
|
|
802
|
+
["face", "skin", [["c", 15, 29, 6]]],
|
|
803
|
+
["details", "black", [["c", 13, 30, 1.1], ["c", 17.5, 30, 1.1]]],
|
|
804
|
+
["details", "pink", [["c", 12, 27.5, 1.3], ["c", 19, 27.5, 1.3]]]
|
|
805
|
+
]],
|
|
806
|
+
["shepherd", "nativity", "dark brown", [
|
|
807
|
+
["clothes", "light brown", [["r", 24, 41, 3, 80, 1.5, 0], ["a", 20, 81, 4, 0, 180, 3]]],
|
|
808
|
+
["clothes", "brown", [["h", [["c", -8, 46, 6], ["c", 8, 46, 6], ["c", -16, 4, 3], ["c", 16, 4, 3]]]]],
|
|
809
|
+
["clothes", "cream", [["p", [[-14, 50], [14, 50], [11, 36], [-11, 36]]]]],
|
|
810
|
+
["clothes", "brown", [["k", 6, 48, 20, 44, 4.5, 4]]],
|
|
811
|
+
["face", "skin", [["c", 22, 44, 4]]],
|
|
812
|
+
["face", "beige", [["e", 0, 65, 11, 12.5, 0], ["m", [["r", -9, 54, 5, 14, 2, 0]]]]],
|
|
813
|
+
["face", "skin", [["e", 0, 62, 7.5, 8, 0]]],
|
|
814
|
+
["clothes", "blue", [["r", 0, 71, 21, 3.5, 1.5, 0]]],
|
|
815
|
+
["details", "black", [["m", [["c", -3.2, 63, 1.4]]]]],
|
|
816
|
+
["details", "pink", [["m", [["e", -5, 59, 1.8, 1.2, 0]]]]]
|
|
817
|
+
]],
|
|
818
|
+
["caspar", "nativity", "dark brown", [
|
|
819
|
+
["clothes", "purple", [["h", [["c", -9, 46, 7], ["c", 9, 46, 7], ["c", -19, 4, 3], ["c", 19, 4, 3]]]]],
|
|
820
|
+
["clothes", "gold", [["r", 0, 25, 6, 44, 2, 0]]],
|
|
821
|
+
["clothes", "purple", [["m", [["k", -12, 47, -5, 34, 5, 4.5]]]]],
|
|
822
|
+
["face", "skin", [["m", [["c", -6, 33, 3.5]]]]],
|
|
823
|
+
["clothes", "gold", [["r", 0, 33, 11, 9, 1.5, 0]]],
|
|
824
|
+
["face", "skin", [["e", 0, 62, 8.5, 9.5, 0]]],
|
|
825
|
+
["face", "white", [["-", [["e", 0, 57, 9, 9.5, 0]], [["r", 0, 66, 20, 12, 0, 0]]]]],
|
|
826
|
+
["clothes", "gold", [["p", [[-9, 69], [9, 69], [10, 80], [5, 75], [0, 82], [-5, 75], [-10, 80]]]]],
|
|
827
|
+
["details", "red", [["c", 0, 33, 2]]],
|
|
828
|
+
["details", "black", [["m", [["c", -3.5, 63.5, 1.5]]]]]
|
|
829
|
+
]],
|
|
830
|
+
["melchior", "nativity", "dark brown", [
|
|
831
|
+
["clothes", "red", [["h", [["c", -9, 46, 7], ["c", 9, 46, 7], ["c", -19, 4, 3], ["c", 19, 4, 3]]]]],
|
|
832
|
+
["clothes", "gold", [["r", 0, 6, 34, 5, 2, 0]]],
|
|
833
|
+
["clothes", "red", [["m", [["k", -12, 47, -5, 34, 5, 4.5]]]]],
|
|
834
|
+
["face", "peach", [["m", [["c", -6, 33, 3.5]]]]],
|
|
835
|
+
["clothes", "gold", [["h", [["c", -4, 30, 2], ["c", 4, 30, 2], ["c", 0, 39, 3.5]]]]],
|
|
836
|
+
["face", "peach", [["e", 0, 62, 8.5, 9.5, 0]]],
|
|
837
|
+
["face", "dark brown", [["-", [["e", 0, 57, 9, 9.5, 0]], [["r", 0, 66, 20, 12, 0, 0]]]]],
|
|
838
|
+
["clothes", "gold", [["p", [[-9, 69], [9, 69], [11, 82], [4.5, 76], [0, 84], [-4.5, 76], [-11, 82]]]]],
|
|
839
|
+
["details", "green", [["c", 0, 72.5, 1.8]]],
|
|
840
|
+
["details", "black", [["m", [["c", -3.5, 63.5, 1.5]]]]]
|
|
841
|
+
]],
|
|
842
|
+
["balthasar", "nativity", "dark brown", [
|
|
843
|
+
["clothes", "green", [["h", [["c", -9, 46, 7], ["c", 9, 46, 7], ["c", -19, 4, 3], ["c", 19, 4, 3]]]]],
|
|
844
|
+
["clothes", "gold", [["m", [["r", -12, 25, 3.5, 42, 1.5, 6]]]]],
|
|
845
|
+
["clothes", "green", [["m", [["k", -12, 47, -5, 34, 5, 4.5]]]]],
|
|
846
|
+
["face", "brown", [["m", [["c", -6, 33, 3.5]]]]],
|
|
847
|
+
["clothes", "gold", [["e", 0, 34, 6, 7, 0]]],
|
|
848
|
+
["face", "brown", [["e", 0, 62, 8.5, 9.5, 0]]],
|
|
849
|
+
["clothes", "white", [["h", [["c", -9, 70, 3.5], ["c", 9, 70, 3.5], ["c", 0, 80, 7]]]]],
|
|
850
|
+
["details", "red", [["c", 0, 72, 2]]],
|
|
851
|
+
["details", "black", [["m", [["c", -3.5, 63.5, 1.5]]]]],
|
|
852
|
+
["details", "pink", [["e", 0, 57, 2.6, 1.3, 0]]]
|
|
853
|
+
]],
|
|
854
|
+
["ox", "nativity", "dark brown", [
|
|
855
|
+
["clothes", "cream", [["m", [["k", -14, 70, -26, 74, 3, 2], ["k", -26, 74, -27, 82, 2, 1.4]]]]],
|
|
856
|
+
["clothes", "brown", [
|
|
857
|
+
["m", [["r", -12, 7, 8, 14, 2.5, 0]]],
|
|
858
|
+
["e", 0, 28, 22, 18, 0],
|
|
859
|
+
["m", [["e", -19, 62, 8, 4, 15]]],
|
|
860
|
+
["e", 0, 58, 15, 16, 0]
|
|
861
|
+
]],
|
|
862
|
+
["face", "pink", [["m", [["e", -19, 62, 4.5, 2, 15]]]]],
|
|
863
|
+
["face", "beige", [["e", 0, 47, 12, 8, 0], ["c", 0, 69, 4]]],
|
|
864
|
+
["clothes", "dark brown", [["m", [["r", -12, 3, 8, 6, 2, 0]]]]],
|
|
865
|
+
["details", "black", [["m", [["c", -6.5, 60, 2.2]]]]],
|
|
866
|
+
["details", "dark brown", [["m", [["e", -4, 46.5, 1.8, 2.4, 0]]]]]
|
|
867
|
+
]],
|
|
868
|
+
["donkey", "nativity", "dark brown", [
|
|
869
|
+
["clothes", "grey", [
|
|
870
|
+
["m", [["r", -11, 8, 7, 16, 2.5, 0]]],
|
|
871
|
+
["e", 0, 28, 19, 17, 0],
|
|
872
|
+
["m", [["k", -7, 66, -12, 92, 5, 3.5]]],
|
|
873
|
+
["e", 0, 56, 12, 16, 0]
|
|
874
|
+
]],
|
|
875
|
+
["face", "light grey", [["m", [["k", -7.5, 70, -11.5, 88, 2.4, 1.6]]]]],
|
|
876
|
+
["face", "white", [["e", 0, 45, 10, 8, 0], ["e", 0, 24, 10, 10, 0]]],
|
|
877
|
+
["clothes", "dark grey", [["m", [["r", -11, 3, 7, 6, 2, 0]]], ["k", 0, 64, 0, 74, 3, 2.5]]],
|
|
878
|
+
["details", "black", [["m", [["c", -6, 58, 2.2]]]]],
|
|
879
|
+
["details", "dark grey", [["m", [["e", -3.5, 44, 1.6, 2.2, 0]]]]]
|
|
880
|
+
]],
|
|
881
|
+
["sheep", "nativity", "dark grey", [
|
|
882
|
+
["face", "black", [["m", [["r", -11, 9, 6, 18, 2.5, 0]]]]],
|
|
883
|
+
["clothes", "white", [
|
|
884
|
+
["e", 0, 35, 26, 18, 0],
|
|
885
|
+
for (a = [0:30:330]) ["c", 24 * cos(a), 35 + 17 * sin(a), 7]
|
|
886
|
+
]],
|
|
887
|
+
["face", "black", [["m", [["e", -16, 64, 8, 3.6, -25]]], ["e", 0, 59, 11, 14, 0]]],
|
|
888
|
+
["clothes", "white", [["c", -6.5, 72, 5.5], ["c", 0, 75, 5.5], ["c", 6.5, 72, 5.5]]],
|
|
889
|
+
["details", "white", [["m", [["c", -5, 60, 2.2]]]]],
|
|
890
|
+
["details", "pink", [["e", 0, 51.5, 3, 2, 0]]]
|
|
891
|
+
]],
|
|
892
|
+
|
|
893
|
+
// Animals
|
|
894
|
+
["bear", "animals", "dark brown", [
|
|
895
|
+
["clothes", "brown", [
|
|
896
|
+
["m", [["e", -13, 8, 9, 7.5, 0]]],
|
|
897
|
+
["e", 0, 28, 20, 20, 0],
|
|
898
|
+
["m", [["e", -18, 34, 6, 10, -30]]],
|
|
899
|
+
["m", [["c", -14, 75, 6.5]]],
|
|
900
|
+
["c", 0, 62, 17]
|
|
901
|
+
]],
|
|
902
|
+
["face", "beige", [["m", [["c", -14, 75, 3.5], ["e", -13, 7, 5, 4, 0]]], ["e", 0, 26, 12, 13, 0], ["e", 0, 56, 8, 6.5, 0]]],
|
|
903
|
+
["details", "black", [["m", [["c", -6, 65, 2.4]]], ["e", 0, 58.5, 3.2, 2.4, 0]]],
|
|
904
|
+
["details", "pink", [["m", [["e", -11, 57, 2.4, 1.6, 0]]]]]
|
|
905
|
+
]],
|
|
906
|
+
["fox", "animals", "dark brown", [
|
|
907
|
+
["clothes", "orange", [["e", 20, 18, 9, 18, 35]]],
|
|
908
|
+
["face", "white", [["e", 27, 30, 5, 6, 35]]],
|
|
909
|
+
["clothes", "orange", [
|
|
910
|
+
["h", [["c", -10, 12, 7], ["c", 10, 12, 7], ["c", 0, 40, 10]]],
|
|
911
|
+
["m", [["p", [[-16, 66], [-18, 86], [-5, 72]]]]],
|
|
912
|
+
["p", [[-19, 66], [19, 66], [16, 56], [0, 44], [-16, 56]]]
|
|
913
|
+
]],
|
|
914
|
+
["face", "dark brown", [["m", [["p", [[-13.5, 70.5], [-15, 79], [-9.5, 73]]]]]]],
|
|
915
|
+
["face", "white", [["p", [[-12, 58], [0, 46], [12, 58], [0, 55]]], ["e", 0, 28, 7, 12, 0]]],
|
|
916
|
+
["clothes", "dark brown", [["m", [["e", -7, 4, 4.5, 3, 0]]]]],
|
|
917
|
+
["details", "black", [["m", [["e", -6.5, 60, 1.8, 2.4, 0]]], ["c", 0, 47.5, 2.4]]]
|
|
918
|
+
]],
|
|
919
|
+
["cat", "animals", "dark grey", [
|
|
920
|
+
["clothes", "grey", [["k", 14, 6, 26, 30, 3.5, 3], ["c", 26, 34, 4]]],
|
|
921
|
+
["clothes", "grey", [
|
|
922
|
+
["h", [["c", -11, 9, 7], ["c", 11, 9, 7], ["c", 0, 38, 10]]],
|
|
923
|
+
["m", [["p", [[-15, 60], [-15, 77], [-4, 66]]]]],
|
|
924
|
+
["e", 0, 57, 15, 12.5, 0]
|
|
925
|
+
]],
|
|
926
|
+
["face", "pink", [["m", [["p", [[-13, 63], [-13.3, 72.5], [-7, 66]]]]]]],
|
|
927
|
+
["face", "white", [["e", 0, 26, 7, 13, 0], ["m", [["e", -3.5, 52, 4.5, 3.5, 0]]], ["m", [["e", -7, 4, 4, 3, 0]]]]],
|
|
928
|
+
["details", "light green", [["m", [["e", -6.5, 59, 2.4, 2.8, 0]]]]],
|
|
929
|
+
["details", "pink", [["p", [[-1.8, 55.5], [1.8, 55.5], [0, 53.5]]]]]
|
|
930
|
+
]],
|
|
931
|
+
["dog", "animals", "dark brown", [
|
|
932
|
+
["clothes", "tan", [["k", 14, 6, 25, 20, 3.5, 3]]],
|
|
933
|
+
["clothes", "tan", [
|
|
934
|
+
["h", [["c", -11, 9, 7], ["c", 11, 9, 7], ["c", 0, 38, 10]]],
|
|
935
|
+
["e", 0, 58, 15, 13.5, 0]
|
|
936
|
+
]],
|
|
937
|
+
["clothes", "brown", [["m", [["e", -15, 56, 5.5, 12, -15]]]]],
|
|
938
|
+
["face", "white", [["e", 0, 51, 7.5, 6, 0], ["e", 0, 26, 6.5, 11, 0], ["m", [["e", -7, 4, 4, 3, 0]]]]],
|
|
939
|
+
["clothes", "red", [["r", 0, 43, 19, 4, 2, 0]]],
|
|
940
|
+
["details", "black", [["m", [["c", -6, 61, 2.2]]], ["e", 0, 54, 3, 2.2, 0]]],
|
|
941
|
+
["details", "yellow", [["c", 0, 39.5, 2.4]]]
|
|
942
|
+
]],
|
|
943
|
+
["owl", "animals", "dark brown", [
|
|
944
|
+
["clothes", "brown", [
|
|
945
|
+
["e", 0, 40, 22, 30, 0],
|
|
946
|
+
["m", [["p", [[-18, 60], [-20, 78], [-8, 66]]]]]
|
|
947
|
+
]],
|
|
948
|
+
["face", "light brown", [["e", 0, 30, 14, 18, 0]]],
|
|
949
|
+
["clothes", "brown", [["m", [["e", -18, 36, 7, 15, 12]]]]],
|
|
950
|
+
["face", "beige", [["m", [["c", -8.5, 58, 9]]]]],
|
|
951
|
+
["face", "orange", [["p", [[-3, 53], [3, 53], [0, 47]]], ["m", [["e", -6, 9.5, 4.5, 3, 0]]]]],
|
|
952
|
+
["details", "black", [["m", [["c", -8.5, 58, 4]]]]],
|
|
953
|
+
["details", "brown", [
|
|
954
|
+
for (p = [[-6, 32], [0, 34], [6, 32], [-3, 26], [3, 26], [0, 19]]) ["a", p[0], p[1], 3, 200, 340, 1.8]
|
|
955
|
+
]]
|
|
956
|
+
]],
|
|
957
|
+
["deer", "animals", "dark brown", [
|
|
958
|
+
["clothes", "light brown", [
|
|
959
|
+
["m", [["r", -8, 10, 6, 20, 2.5, 0]]],
|
|
960
|
+
["e", 0, 32, 15, 16, 0],
|
|
961
|
+
["m", [["e", -15, 70, 9, 4.5, 30]]],
|
|
962
|
+
["e", 0, 62, 11, 14, 0]
|
|
963
|
+
]],
|
|
964
|
+
["face", "pink", [["m", [["e", -15, 70, 5.5, 2.2, 30]]]]],
|
|
965
|
+
["face", "beige", [["e", 0, 53, 7, 6, 0], ["e", 0, 28, 8, 10, 0]]],
|
|
966
|
+
["clothes", "dark brown", [["m", [["r", -8, 2.5, 6, 5, 1.5, 0]]]]],
|
|
967
|
+
["details", "black", [["m", [["c", -5, 63, 2.2]]], ["e", 0, 56, 2.6, 2, 0]]],
|
|
968
|
+
["details", "white", [["c", -10, 39, 1.6], ["c", 11, 41, 1.6], ["c", -8, 30, 1.4], ["c", 10, 25, 1.4], ["c", -11, 21, 1.4]]]
|
|
969
|
+
]]
|
|
970
|
+
];
|
|
282
971
|
`,"kerf/fit":`// kerf/fit: drawings scaled to a size and placed by a point of their box.
|
|
283
972
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
284
973
|
//
|
|
@@ -1175,17 +1864,72 @@ module narrow_hinge(size, spacing = 1.5, bridge = 1.5) {
|
|
|
1175
1864
|
if (i % 2 == 0) line([x, -1], [x, h - bridge]); else line([x, bridge], [x, h + 1]);
|
|
1176
1865
|
}
|
|
1177
1866
|
|
|
1867
|
+
// The points a strip's middle follows round the corner at \`p\`, coming from
|
|
1868
|
+
// \`a\` and going on to \`b\`: an arc of radius \`r\` inside (the middle of the
|
|
1869
|
+
// sheet tangent to both sides) where both sides are at least \`straight\`
|
|
1870
|
+
// long, else \`p\` itself. A corner too tight for its sides rounds to the
|
|
1871
|
+
// radius that fits half of each.
|
|
1872
|
+
function strip_corner(a, p, b, straight = 10, r = undef) =
|
|
1873
|
+
let (
|
|
1874
|
+
R = (is_undef(r) ? 2 * $thickness : r) + $thickness / 2,
|
|
1875
|
+
u = p - a, v = b - p, lu = norm(u), lv = norm(v),
|
|
1876
|
+
h0 = atan2(u[1], u[0]), d0 = atan2(v[1], v[0]) - h0,
|
|
1877
|
+
turn = d0 > 180 ? d0 - 360 : d0 < -180 ? d0 + 360 : d0
|
|
1878
|
+
)
|
|
1879
|
+
lu < straight || lv < straight || abs(turn) <= 0.01 || abs(turn) >= 179.99 ? [p]
|
|
1880
|
+
: let (
|
|
1881
|
+
// How far back the arc starts from the corner, and its radius
|
|
1882
|
+
set = min(R * tan(abs(turn) / 2), lu / 2, lv / 2),
|
|
1883
|
+
rad = set / tan(abs(turn) / 2),
|
|
1884
|
+
side = turn > 0 ? 1 : -1,
|
|
1885
|
+
c = p - set * u / lu + side * rad * [-sin(h0), cos(h0)],
|
|
1886
|
+
m = max(ceil(abs(turn) / 5), ceil(rad * abs(turn) * PI / 180 / (max(straight, 1) / 2)))
|
|
1887
|
+
) [for (k = [0:m]) let (g = h0 + turn * k / m) c + side * rad * [sin(g), -cos(g)]];
|
|
1888
|
+
|
|
1889
|
+
// \`path\` with each sharp corner, where two segments at least \`straight\`
|
|
1890
|
+
// long meet, rounded as strip_corner() rounds it: the path a strip that
|
|
1891
|
+
// bends round radius \`r\` there follows. The strip is as long as this path,
|
|
1892
|
+
// and ends where it does.
|
|
1893
|
+
function strip_path(path, straight = 10, r = undef) =
|
|
1894
|
+
let (
|
|
1895
|
+
pts = [for (i = [0:len(path) - 1]) if (i == 0 || norm(path[i] - path[i - 1]) > 1e-9) path[i]],
|
|
1896
|
+
n = len(pts),
|
|
1897
|
+
all = n < 3 ? pts : concat([pts[0]], [for (i = [1:n - 2]) each strip_corner(pts[i - 1], pts[i], pts[i + 1], straight, r)], [pts[n - 1]])
|
|
1898
|
+
)
|
|
1899
|
+
// Two arcs on one short side meet at its middle: that point once, so no
|
|
1900
|
+
// segment is too short to have a heading
|
|
1901
|
+
[for (i = [0:len(all) - 1]) if (i == 0 || norm(all[i] - all[i - 1]) > 1e-6) all[i]];
|
|
1902
|
+
|
|
1903
|
+
// A closed outline with its sharp corners rounded as strip_path() rounds a
|
|
1904
|
+
// path's, each judged by its whole sides: the loop a strip round it follows
|
|
1905
|
+
function strip_loop(outline, straight = 10, r = undef) =
|
|
1906
|
+
let (
|
|
1907
|
+
n0 = len(outline),
|
|
1908
|
+
o = norm(outline[n0 - 1] - outline[0]) < 1e-9 ? slice(outline, 0, n0 - 1) : outline,
|
|
1909
|
+
pts = [for (i = [0:len(o) - 1]) if (i == 0 || norm(o[i] - o[i - 1]) > 1e-9) o[i]],
|
|
1910
|
+
m = len(pts),
|
|
1911
|
+
all = [for (i = [0:m - 1]) each strip_corner(pts[(i + m - 1) % m], pts[i], pts[(i + 1) % m], straight, r)],
|
|
1912
|
+
k = len(all)
|
|
1913
|
+
)
|
|
1914
|
+
// Two arcs on one short side meet at its middle: that point once
|
|
1915
|
+
[for (i = [0:k - 1]) if (norm(all[i] - all[(i + k - 1) % k]) > 1e-6) all[i]];
|
|
1916
|
+
|
|
1178
1917
|
// The bends of a strip that follows \`path\`, a list of [x, y] points along
|
|
1179
1918
|
// its middle: [s0, s1, angle] for each curve, measured along the path,
|
|
1180
1919
|
// turning left positive. Segments shorter than \`straight\` are curve, the
|
|
1181
|
-
// rest straight; a sharp corner bends round radius \`r\`.
|
|
1920
|
+
// rest straight; a sharp corner bends round radius \`r\`. A curve whose
|
|
1921
|
+
// radius changes, as a tight fillet running into a wide arc, is several
|
|
1922
|
+
// bends end to end, one for each stretch of much the same radius.
|
|
1182
1923
|
function strip_bends(path, straight = 10, r = undef) =
|
|
1183
1924
|
let (
|
|
1184
1925
|
rr = is_undef(r) ? 2 * $thickness : r,
|
|
1185
|
-
|
|
1186
|
-
|
|
1926
|
+
// Sharp corners rounded; a point repeated, as where a straight run and
|
|
1927
|
+
// an arc share their end, has no heading of its own and is left out
|
|
1928
|
+
pts = strip_path(path, straight, r),
|
|
1929
|
+
n = len(pts),
|
|
1930
|
+
segs = [for (i = [0:n - 2]) norm(pts[i + 1] - pts[i])],
|
|
1187
1931
|
at = [for (i = [0:n - 1]) i == 0 ? 0 : sum([for (k = [0:i - 1]) segs[k]])],
|
|
1188
|
-
head = [for (i = [0:n - 2]) atan2(
|
|
1932
|
+
head = [for (i = [0:n - 2]) atan2(pts[i + 1][1] - pts[i][1], pts[i + 1][0] - pts[i][0])],
|
|
1189
1933
|
turn = [for (i = [1:n - 2]) let (d = head[i] - head[i - 1]) d > 180 ? d - 360 : d < -180 ? d + 360 : d],
|
|
1190
1934
|
// Each corner as [s0, s1, angle]: a short segment's turn spreads over
|
|
1191
1935
|
// it, a sharp corner's over a bend of radius rr
|
|
@@ -1196,7 +1940,23 @@ function strip_bends(path, straight = 10, r = undef) =
|
|
|
1196
1940
|
s1 = short_out ? at[i] + segs[i] / 2 : at[i] + half)
|
|
1197
1941
|
[s0, s1, turn[i - 1]]]
|
|
1198
1942
|
)
|
|
1199
|
-
|
|
1943
|
+
strip_join(corners);
|
|
1944
|
+
|
|
1945
|
+
// Joins bends that touch or overlap into one where they turn the same way
|
|
1946
|
+
// at much the same rate (within a quarter), so each bend keeps close to
|
|
1947
|
+
// one radius. Two that overlap but don't join meet halfway through the
|
|
1948
|
+
// overlap.
|
|
1949
|
+
function strip_join(list, i = 0, cur = undef, out = []) =
|
|
1950
|
+
i == len(list) ? (is_undef(cur) ? out : concat(out, [cur]))
|
|
1951
|
+
: is_undef(cur) ? strip_join(list, i + 1, list[i], out)
|
|
1952
|
+
: let (nx = list[i]) nx[0] > cur[1] + 0.01 ? strip_join(list, i + 1, nx, concat(out, [cur]))
|
|
1953
|
+
: let (p = cur[2] / (cur[1] - cur[0]), q = nx[2] / (nx[1] - nx[0]),
|
|
1954
|
+
alike = p * q > 0 && max(abs(p), abs(q)) <= 1.25 * min(abs(p), abs(q)))
|
|
1955
|
+
// Alike, or one within the other: one bend
|
|
1956
|
+
alike || nx[0] <= cur[0] || nx[1] <= cur[1]
|
|
1957
|
+
? strip_join(list, i + 1, [cur[0], max(cur[1], nx[1]), cur[2] + nx[2]], out)
|
|
1958
|
+
: nx[0] >= cur[1] ? strip_join(list, i + 1, nx, concat(out, [cur]))
|
|
1959
|
+
: let (m = (nx[0] + cur[1]) / 2) strip_join(list, i + 1, [m, nx[1], nx[2]], concat(out, [[cur[0], m, cur[2]]]));
|
|
1200
1960
|
|
|
1201
1961
|
// Joins bends that touch or overlap into one
|
|
1202
1962
|
function strip_merge(list, i = 0, cur = undef, out = []) =
|
|
@@ -1214,14 +1974,16 @@ function strip_merge(list, i = 0, cur = undef, out = []) =
|
|
|
1214
1974
|
// own slots for the tabs. The 3D view shows the strip bent.
|
|
1215
1975
|
module flex_strip(path, width, name = "strip", tabs = true, straight = 10, r = undef, spacing = 1.5, bridge = 3, narrow = false) {
|
|
1216
1976
|
t = $thickness;
|
|
1217
|
-
L = path_length(path);
|
|
1977
|
+
L = path_length(strip_path(path, straight, r));
|
|
1218
1978
|
bends = strip_bends(path, straight, r);
|
|
1979
|
+
// The hinges are cut over each stretch of bends end to end
|
|
1980
|
+
spans = strip_merge(bends);
|
|
1219
1981
|
h0 = heading_at(path, 0);
|
|
1220
1982
|
p0 = path[0] - t / 2 * [-sin(h0), cos(h0)];
|
|
1221
|
-
runs = [for (k = [0:len(
|
|
1983
|
+
runs = [for (k = [0:len(spans)]) [k == 0 ? 0 : spans[k - 1][1], k == len(spans) ? L : spans[k][0]]];
|
|
1222
1984
|
part(name, at = [p0[0], p0[1], 0], rotate = orient([cos(h0), sin(h0), 0], [-sin(h0), cos(h0), 0]), bend = [for (b = bends) [b[0], b[1], b[2]]]) {
|
|
1223
1985
|
rect([L, width]);
|
|
1224
|
-
for (b =
|
|
1986
|
+
for (b = spans) translate([b[0], 0])
|
|
1225
1987
|
if (narrow) narrow_hinge([b[1] - b[0], width], spacing, bridge);
|
|
1226
1988
|
else living_hinge([b[1] - b[0], width], spacing = spacing, bridge = bridge);
|
|
1227
1989
|
if (tabs)
|
|
@@ -1233,6 +1995,134 @@ module flex_strip(path, width, name = "strip", tabs = true, straight = 10, r = u
|
|
|
1233
1995
|
}
|
|
1234
1996
|
}
|
|
1235
1997
|
}
|
|
1998
|
+
|
|
1999
|
+
// The part of \`path\` from s0 to s1 along it, its ends where those fall
|
|
2000
|
+
function path_part(path, s0, s1) =
|
|
2001
|
+
let (at = concat([0], scan([for (i = [0:len(path) - 2]) norm(path[i + 1] - path[i])], 0, function(a, x) a + x)))
|
|
2002
|
+
concat([point_at(path, s0)], [for (i = [0:len(path) - 1]) if (at[i] > s0 + 1e-6 && at[i] < s1 - 1e-6) path[i]], [point_at(path, s1)]);
|
|
2003
|
+
|
|
2004
|
+
// A closed outline as a path round it that starts and ends at the point
|
|
2005
|
+
// of it nearest \`join\`, or with join undef the middle of its longest side
|
|
2006
|
+
function wall_path(outline, join = undef) =
|
|
2007
|
+
let (
|
|
2008
|
+
n = len(outline),
|
|
2009
|
+
pts = norm(outline[n - 1] - outline[0]) < 1e-9 ? slice(outline, 0, n - 1) : outline,
|
|
2010
|
+
m = len(pts),
|
|
2011
|
+
near = [for (i = [0:m - 1]) let (a = pts[i], b = pts[(i + 1) % m], d = b - a,
|
|
2012
|
+
u = is_undef(join) ? 0.5 : clamp(((join - a) * d) / max(d * d, 1e-12), 0, 1)) [a + u * d, is_undef(join) ? -norm(d) : norm(join - a - u * d)]],
|
|
2013
|
+
k = fold([for (i = [0:m - 1]) i], 0, function(b, i) near[i][1] < near[b][1] ? i : b),
|
|
2014
|
+
ring = concat([near[k][0]], [for (i = [1:m]) pts[(k + i) % m]], [near[k][0]])
|
|
2015
|
+
)
|
|
2016
|
+
[for (i = [0:len(ring) - 1]) if (i == 0 || norm(ring[i] - ring[i - 1]) > 1e-9) ring[i]];
|
|
2017
|
+
|
|
2018
|
+
// Where to split a strip L long into n pieces no longer than max_length:
|
|
2019
|
+
// near even spacing, at the middle of a straight run where one is near,
|
|
2020
|
+
// else at the middle of a segment of the path, where its bends end
|
|
2021
|
+
function wall_splits(L, n, max_length, mids, halves, k = 1, prev = 0, out = []) =
|
|
2022
|
+
k >= n ? out
|
|
2023
|
+
: let (t = k * L / n,
|
|
2024
|
+
// Where this cut may go: no piece longer than max_length, this one or
|
|
2025
|
+
// those still to come
|
|
2026
|
+
lo = max(prev + 1, L - (n - k) * max_length), hi = prev + max_length,
|
|
2027
|
+
fits = function(list) [for (c = list) if (c >= lo && c <= hi) c],
|
|
2028
|
+
nearest = function(list) fold(list, list[0], function(b, x) abs(x - t) < abs(b - t) ? x : b),
|
|
2029
|
+
ok = fits(mids), half = fits(halves),
|
|
2030
|
+
c = len(ok) ? nearest(ok) : len(half) ? nearest(half) : clamp(t, lo, hi))
|
|
2031
|
+
wall_splits(L, n, max_length, mids, halves, k + 1, c, concat(out, [c]));
|
|
2032
|
+
|
|
2033
|
+
// The names of the pieces of the strip wall() makes
|
|
2034
|
+
function wall_strip_names(name, pieces) = pieces == 1 ? [str(name, " strip")] : [for (k = [1:pieces]) str(name, " strip ", k)];
|
|
2035
|
+
|
|
2036
|
+
// How many pieces wall() cuts its strip into
|
|
2037
|
+
function wall_pieces(outline, max_length = 400, join = undef, straight = 10, r = undef) = max(1, ceil(path_length(wall_path(strip_loop(outline, straight, r), join)) / max_length));
|
|
2038
|
+
|
|
2039
|
+
// A wall round a closed outline: a front plate, a back plate \`depth\`
|
|
2040
|
+
// behind it and a strip between them that follows the outline, bent on
|
|
2041
|
+
// living hinges where it curves and tabbed into slots in both plates where
|
|
2042
|
+
// it runs straight. The strip's ends meet at the point of the outline
|
|
2043
|
+
// nearest \`join\`; a strip longer than \`max_length\` is cut into pieces no
|
|
2044
|
+
// longer, split where it runs straight when it can, so each fits the bed.
|
|
2045
|
+
//
|
|
2046
|
+
// The first child, when given, is the front plate, drawn as the outline
|
|
2047
|
+
// is; the second the back plate. Without them each plate is the outline
|
|
2048
|
+
// grown by \`rim\` (half a thickness and 3 mm). Where the strip's ends meet
|
|
2049
|
+
// they are \`seam\` apart, so pieces bent on their hinges don't press on
|
|
2050
|
+
// each other. The parts are
|
|
2051
|
+
// str(name, " front"), str(name, " back") and str(name, " strip"), or
|
|
2052
|
+
// " strip 1", " strip 2" and so on for a strip in pieces. It stands
|
|
2053
|
+
// upright as placed by \`at\` and \`rotate\`: the outline is seen from the
|
|
2054
|
+
// front, the back plate behind it.
|
|
2055
|
+
module wall(outline, depth, name = "wall", join = undef, max_length = 400, rim = undef, seam = 0.3, tabs = true, straight = 10, r = undef, spacing = 1.5, bridge = 3, narrow = false, at = [0, 0, 0], rotate = [90, 0, 0]) {
|
|
2056
|
+
t = $thickness;
|
|
2057
|
+
grow = is_undef(rim) ? t / 2 + 3 : rim;
|
|
2058
|
+
path = wall_path(strip_loop(outline, straight, r), join);
|
|
2059
|
+
L = path_length(path);
|
|
2060
|
+
n = max(1, ceil(L / max_length));
|
|
2061
|
+
spans = strip_merge(strip_bends(path, straight, r));
|
|
2062
|
+
runs = [for (k = [0:len(spans)]) [k == 0 ? 0 : spans[k - 1][1], k == len(spans) ? L : spans[k][0]]];
|
|
2063
|
+
mids = [for (run = runs) if (run[1] - run[0] >= 2 * straight) (run[0] + run[1]) / 2];
|
|
2064
|
+
at_ = concat([0], scan([for (i = [0:len(path) - 2]) norm(path[i + 1] - path[i])], 0, function(a, x) a + x));
|
|
2065
|
+
halves = [for (i = [0:len(path) - 2]) (at_[i] + at_[i + 1]) / 2];
|
|
2066
|
+
cuts = concat([0], wall_splits(L, n, max_length, mids, halves), [L]);
|
|
2067
|
+
names = wall_strip_names(name, n);
|
|
2068
|
+
pieces = [for (k = [0:n - 1]) path_part(path, cuts[k] + seam / 2, cuts[k + 1] - seam / 2)];
|
|
2069
|
+
// The pieces with tabs, as flex_strip() puts them on runs over 16 mm
|
|
2070
|
+
tabbed = !tabs ? [] : [for (k = [0:n - 1]) let (sp = strip_merge(strip_bends(pieces[k], straight, r)), l = path_length(pieces[k]),
|
|
2071
|
+
rs = [for (j = [0:len(sp)]) (j == len(sp) ? l : sp[j][0]) - (j == 0 ? 0 : sp[j - 1][1])]) if (max(rs) > 16) names[k]];
|
|
2072
|
+
place(at = at, rotate = rotate) {
|
|
2073
|
+
part(str(name, " front"), slots = tabbed) {
|
|
2074
|
+
if ($children > 0) children(0);
|
|
2075
|
+
else offset(delta = grow) polygon(outline);
|
|
2076
|
+
}
|
|
2077
|
+
part(str(name, " back"), at = [0, 0, -depth - t], slots = tabbed) {
|
|
2078
|
+
if ($children > 1) children(1);
|
|
2079
|
+
else offset(delta = grow) polygon(outline);
|
|
2080
|
+
}
|
|
2081
|
+
for (k = [0:n - 1])
|
|
2082
|
+
flex_strip(pieces[k], depth, name = names[k], tabs = tabs, straight = straight, r = r, spacing = spacing, bridge = bridge, narrow = narrow);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
`,"kerf/inlay":`// kerf/inlay: inlays of another wood, stock or colour: the shapes cut out
|
|
2086
|
+
// of one part (or engraved into it as pockets) and cut again as inserts
|
|
2087
|
+
// that press into them.
|
|
2088
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
2089
|
+
//
|
|
2090
|
+
// KerfScript takes the kerf off every cut, so a hole and an insert of the
|
|
2091
|
+
// same shape come out the same size; each insert is \`press\` mm bigger all
|
|
2092
|
+
// round so it holds.
|
|
2093
|
+
|
|
2094
|
+
// A part with inlays. Its first child is the part's shape; each child
|
|
2095
|
+
// after it is an inlay's shape. The inlays are cut through the part, or
|
|
2096
|
+
// with \`depth\` engraved that deep on the layer "pocket" (set that layer's
|
|
2097
|
+
// power for the depth). Each inlay is an insert of its own, named "name
|
|
2098
|
+
// inlay 1" up, \`press\` mm bigger all round, of materials[i] (stock of its
|
|
2099
|
+
// own, on a sheet of its own) or painted paints[i]; a pocket's insert is
|
|
2100
|
+
// \`depth\` thick. In the assembled view a through insert sits in its hole
|
|
2101
|
+
// and a pocket's on the surface over it.
|
|
2102
|
+
module inlaid(name, depth, press = 0.05, materials, paints, at = [0, 0, 0], rotate = [0, 0, 0]) {
|
|
2103
|
+
n = $children;
|
|
2104
|
+
assert(n >= 2, "inlaid(): give the part's shape, then one shape for each inlay");
|
|
2105
|
+
part(name, at = at, rotate = rotate) {
|
|
2106
|
+
if (is_undef(depth))
|
|
2107
|
+
difference() {
|
|
2108
|
+
children(0);
|
|
2109
|
+
for (i = [1:n - 1]) children(i);
|
|
2110
|
+
}
|
|
2111
|
+
else {
|
|
2112
|
+
children(0);
|
|
2113
|
+
layer("pocket", mode = "fill", color = "#555555") for (i = [1:n - 1]) children(i);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
for (i = [1:n - 1])
|
|
2117
|
+
let (
|
|
2118
|
+
m = is_undef(materials) || i - 1 >= len(materials) ? undef : materials[i - 1],
|
|
2119
|
+
c = is_undef(paints) || i - 1 >= len(paints) ? undef : paints[i - 1],
|
|
2120
|
+
t = is_undef(depth) ? $thickness : depth
|
|
2121
|
+
)
|
|
2122
|
+
material(thickness = t, name = is_undef(m) ? $material : m)
|
|
2123
|
+
part(str(name, " inlay ", i), glue = name, at = [0, 0, is_undef(depth) ? -t : 0], paint = c, press_fit = is_undef(depth))
|
|
2124
|
+
offset(delta = press) children(i);
|
|
2125
|
+
}
|
|
1236
2126
|
`,"kerf/joints":`// kerf/joints: joints between parts.
|
|
1237
2127
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1238
2128
|
|
|
@@ -1327,6 +2217,59 @@ module halved_pair(name, at = [0, 0, 0], cap = undef, feet = [], side_feet = und
|
|
|
1327
2217
|
}
|
|
1328
2218
|
}
|
|
1329
2219
|
}
|
|
2220
|
+
`,"kerf/layered":`// kerf/layered: multilayer pieces from one drawing, as layered ornaments,
|
|
2221
|
+
// mandalas, wreaths and signs are made.
|
|
2222
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
2223
|
+
//
|
|
2224
|
+
// The children are the art's layers, back to front. Each becomes a part of
|
|
2225
|
+
// its own, glued on the one behind it and painted its colour; each layer
|
|
2226
|
+
// is at least the outline of everything in front of it, \`border\` mm
|
|
2227
|
+
// wider, so every layer is held up and shows as a rim round the next.
|
|
2228
|
+
|
|
2229
|
+
// A layer's colour: the one given for it, else from a palette that goes
|
|
2230
|
+
// from dark at the back to light at the front
|
|
2231
|
+
function layered_color(colors, k, n) =
|
|
2232
|
+
!is_undef(colors) && k < len(colors) ? colors[k]
|
|
2233
|
+
: ["dark brown", "brown", "light brown", "tan", "beige", "cream", "white"][
|
|
2234
|
+
min(6, round(k * 6 / max(1, n - 1)))];
|
|
2235
|
+
|
|
2236
|
+
// Layered art from its children, the layers back to front: one part a
|
|
2237
|
+
// layer, named "name layer 1" up from the back, each glued on the one
|
|
2238
|
+
// behind it and painted colors[k]. Each layer is its own drawing joined
|
|
2239
|
+
// with everything in front of it grown by \`border\` mm. \`shadow\` adds a
|
|
2240
|
+
// layer at the back that much wider still, in \`shadow_color\`; \`hole\` =
|
|
2241
|
+
// [x, y, d] cuts a hole d across through every layer, to hang it by. The
|
|
2242
|
+
// back layer goes at \`at\`, turned by \`rotate\`.
|
|
2243
|
+
module layered(name = "layered", colors, border = 2, shadow = 0, shadow_color = "dark grey", hole, at = [0, 0, 0], rotate = [0, 0, 0]) {
|
|
2244
|
+
n = $children;
|
|
2245
|
+
assert(n >= 1, "layered(): give the layers as children, back to front");
|
|
2246
|
+
module through() if (!is_undef(hole)) translate([hole[0], hole[1]]) circle(d = hole[2]);
|
|
2247
|
+
first = shadow > 0 ? str(name, " shadow") : str(name, " layer 1");
|
|
2248
|
+
if (shadow > 0)
|
|
2249
|
+
part(first, at = at, rotate = rotate, paint = shadow_color)
|
|
2250
|
+
difference() {
|
|
2251
|
+
offset(r = shadow) union() {
|
|
2252
|
+
children(0);
|
|
2253
|
+
if (n > 1) offset(r = border) union() for (j = [1:n - 1]) children(j);
|
|
2254
|
+
}
|
|
2255
|
+
through();
|
|
2256
|
+
}
|
|
2257
|
+
// Layer k: its drawing, and everything in front of it grown by the border
|
|
2258
|
+
for (k = [0:n - 1])
|
|
2259
|
+
let (
|
|
2260
|
+
pname = str(name, " layer ", k + 1),
|
|
2261
|
+
host = k == 0 ? (shadow > 0 ? first : undef) : str(name, " layer ", k)
|
|
2262
|
+
)
|
|
2263
|
+
part(pname, at = is_undef(host) ? at : undef, rotate = is_undef(host) ? rotate : undef,
|
|
2264
|
+
glue = host, paint = layered_color(colors, k, n), pieces = "any")
|
|
2265
|
+
difference() {
|
|
2266
|
+
union() {
|
|
2267
|
+
children(k);
|
|
2268
|
+
if (k < n - 1) offset(r = border) union() for (j = [k + 1:n - 1]) children(j);
|
|
2269
|
+
}
|
|
2270
|
+
through();
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
1330
2273
|
`,"kerf/linkage":`// kerf/linkage: where the joints of a linkage are at a crank angle.
|
|
1331
2274
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1332
2275
|
//
|
|
@@ -1546,6 +2489,167 @@ module ring_stack(diameters, hole, name = "ring", count = undef, feet = true, cl
|
|
|
1546
2489
|
translate([-(t + clearance) / 2, -t - 1]) rect([t + clearance, h / 2 + t + 1]);
|
|
1547
2490
|
}
|
|
1548
2491
|
}
|
|
2492
|
+
`,"kerf/scene":`// kerf/scene: scene boxes and dioramas: a floor with rails, standees with
|
|
2493
|
+
// feet that stand in any rail, layered figures standing in them, and
|
|
2494
|
+
// snow-drip and wave edges.
|
|
2495
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
2496
|
+
//
|
|
2497
|
+
// A floor (or a shelf) has rails: slots running across it, front to back
|
|
2498
|
+
// in rows. Every standee has 8 mm feet that go into any rail, so a scene
|
|
2499
|
+
// is changed by taking the standees out and putting others in. Standees
|
|
2500
|
+
// are drawn standing on y = 0, centred on x = 0; their feet go below.
|
|
2501
|
+
|
|
2502
|
+
use <kerf/figures>
|
|
2503
|
+
|
|
2504
|
+
// Where a floor's rails run, front to back: \`rows\` of them across a floor
|
|
2505
|
+
// \`depth\` deep, the first 8 mm from the front and the last 7 mm from the
|
|
2506
|
+
// back
|
|
2507
|
+
function scene_rows(depth, rows = 6) =
|
|
2508
|
+
assert(is_num(depth) && depth > 15, "scene_rows(): depth must be more than 15")
|
|
2509
|
+
rows == 1 ? [depth / 2] : [for (i = [0:rows - 1]) 8 + i * (depth - 15) / (rows - 1)];
|
|
2510
|
+
|
|
2511
|
+
// The rails of a floor \`width\` wide and \`depth\` deep, as slots to cut from
|
|
2512
|
+
// it: each \`$thickness + clearance\` wide, running across the floor and
|
|
2513
|
+
// stopping \`margin\` short of each side
|
|
2514
|
+
module scene_rails(width, depth, rows = 6, clearance = 0.1, margin = 6) {
|
|
2515
|
+
w = $thickness + clearance;
|
|
2516
|
+
for (y = scene_rows(depth, rows)) translate([margin, y - w / 2]) rect([width - 2 * margin, w]);
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
// A floor with its rails, \`width\` by \`depth\`, its front edge on y = 0
|
|
2520
|
+
module scene_floor(width, depth, rows = 6, clearance = 0.1, margin = 6, r = 0) {
|
|
2521
|
+
difference() {
|
|
2522
|
+
rect([width, depth], r = r);
|
|
2523
|
+
scene_rails(width, depth, rows, clearance, margin);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
// Where a standee's feet go across it, from its middle: one for a standee
|
|
2528
|
+
// under 28 mm wide, two a quarter of the width either side otherwise, and
|
|
2529
|
+
// three for a full-width one, as a backdrop
|
|
2530
|
+
function standee_feet(width, full = false) =
|
|
2531
|
+
full ? [-width / 3, 0, width / 3] : width < 28 ? [0] : [-width / 4, width / 4];
|
|
2532
|
+
|
|
2533
|
+
// The mound a standee stands on: 4.5 mm under a standee under 28 mm wide,
|
|
2534
|
+
// so it stands clear of the floor's edge, else none
|
|
2535
|
+
function standee_mound(width) = width < 28 ? 4.5 : 0;
|
|
2536
|
+
|
|
2537
|
+
// A standee: its children, a drawing, stood on a mound \`mound\` mm high
|
|
2538
|
+
// (by default as standee_mound() says) with \`tab\` mm feet below y = 0 that
|
|
2539
|
+
// go \`floor\` mm (the floor's thickness, $thickness) into a rail, spread
|
|
2540
|
+
// over the width it stands on as standee_feet() says; without a mound, a
|
|
2541
|
+
// ground line 2 mm high joins what stands on the floor. With
|
|
2542
|
+
// \`clip\`, a polygon's points, the drawing and mound are clipped to it and
|
|
2543
|
+
// the feet left whole, as for a standee in a round case.
|
|
2544
|
+
module standee(mound, full = false, tab = 8, floor, clip) {
|
|
2545
|
+
t = is_undef(floor) ? $thickness : floor;
|
|
2546
|
+
measure() {
|
|
2547
|
+
children();
|
|
2548
|
+
let (
|
|
2549
|
+
b = $bounds,
|
|
2550
|
+
w = b[2] - b[0],
|
|
2551
|
+
cx = (b[0] + b[2]) / 2,
|
|
2552
|
+
m = is_undef(mound) ? standee_mound(w) : mound
|
|
2553
|
+
) {
|
|
2554
|
+
intersection() {
|
|
2555
|
+
union() {
|
|
2556
|
+
translate([0, m - b[1]]) children();
|
|
2557
|
+
if (m > 0) translate([b[0], 0]) rect([w, m + 0.5], r = min(m / 2, w / 4));
|
|
2558
|
+
}
|
|
2559
|
+
if (!is_undef(clip)) polygon(clip);
|
|
2560
|
+
}
|
|
2561
|
+
// The feet go where the drawing meets the floor: spread over the
|
|
2562
|
+
// width it stands on, each a whole tab inside it where it is wide
|
|
2563
|
+
// enough
|
|
2564
|
+
measure() {
|
|
2565
|
+
intersection() {
|
|
2566
|
+
union() {
|
|
2567
|
+
translate([0, m - b[1]]) children();
|
|
2568
|
+
if (m > 0) translate([b[0], 0]) rect([w, m + 0.5], r = min(m / 2, w / 4));
|
|
2569
|
+
}
|
|
2570
|
+
translate([b[0] - 1, -1]) rect([w + 2, 2]);
|
|
2571
|
+
}
|
|
2572
|
+
let (f = $bounds, fw = f[2] - f[0], fc = (f[0] + f[2]) / 2) {
|
|
2573
|
+
// A ground line 2 mm high joins legs and feet that meet the
|
|
2574
|
+
// floor apart
|
|
2575
|
+
if (m == 0) translate([f[0], 0]) rect([fw, 2]);
|
|
2576
|
+
for (x = standee_feet(fw, full))
|
|
2577
|
+
let (at = fw < tab ? fc : clamp(fc + x, f[0] + tab / 2, f[2] - tab / 2))
|
|
2578
|
+
translate([at - tab / 2, -t]) rect([tab, t + 0.5]);
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
// A layered figure from kerf/figures standing in a rail: its backer a
|
|
2586
|
+
// standee with feet (and a mound when narrow), its other layers glued on
|
|
2587
|
+
// the front. \`at\` is where its feet go: [x, the rail's y, the floor's top
|
|
2588
|
+
// z]; \`turn\` turns it about its feet. Each colour is a painted part, named
|
|
2589
|
+
// after \`label\`.
|
|
2590
|
+
module scene_figure(name, height = 60, at = [0, 0, 0], turn = 0, label, mound, floor, border = 2, gap = 0.6) {
|
|
2591
|
+
base = is_undef(label) ? lower(name) : label;
|
|
2592
|
+
t = is_undef(floor) ? $thickness : floor;
|
|
2593
|
+
layers = figure_layers(name);
|
|
2594
|
+
middle = [for (l = layers) if (l[0] == "clothes" || l[0] == "face") l];
|
|
2595
|
+
measure() {
|
|
2596
|
+
figure_layer(name, "outline", height, border = border, gap = gap);
|
|
2597
|
+
let (b = $bounds, m = is_undef(mound) ? standee_mound(b[2] - b[0]) : mound) {
|
|
2598
|
+
// Its thickness stands in the rail, centred on it
|
|
2599
|
+
part(str(base, " outline"), at = [at[0] - $thickness / 2 * sin(turn), at[1] + $thickness / 2 * cos(turn), at[2]],
|
|
2600
|
+
rotate = [90, 0, turn], paint = layers[0][1])
|
|
2601
|
+
standee(m, floor = t) figure_layer(name, "outline", height, border = border, gap = gap);
|
|
2602
|
+
for (l = middle)
|
|
2603
|
+
measure() {
|
|
2604
|
+
figure_layer(name, l[0], height, l[1], border = border, gap = gap);
|
|
2605
|
+
if (!is_undef($bounds))
|
|
2606
|
+
part(str(base, " ", l[0], " ", l[1]), glue = str(base, " outline"), at = [0, m, 0], paint = l[1], pieces = "any")
|
|
2607
|
+
figure_layer(name, l[0], height, l[1], border = border, gap = gap);
|
|
2608
|
+
}
|
|
2609
|
+
figure_details(name, height, base, 1, border, gap);
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
// A layered figure on a base of its own, to stand on a shelf: a base
|
|
2615
|
+
// plate \`base\` [w, d] mm with one rail, the figure's feet in it
|
|
2616
|
+
module figure_base(name, height = 80, base = [60, 20], at = [0, 0, 0], label, clearance = 0.1, r = 3) {
|
|
2617
|
+
label_ = is_undef(label) ? lower(name) : label;
|
|
2618
|
+
part(str(label_, " base"), at = [at[0] - base[0] / 2, at[1] - base[1] / 2, at[2]])
|
|
2619
|
+
difference() {
|
|
2620
|
+
rect(base, r = r);
|
|
2621
|
+
translate([6, base[1] / 2 - ($thickness + clearance) / 2]) rect([base[0] - 12, $thickness + clearance]);
|
|
2622
|
+
}
|
|
2623
|
+
scene_figure(name, height, at = [at[0], at[1], at[2] + $thickness], label = label_);
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// An edge that drips, as snow along a roof or icing on a cake: a strip
|
|
2627
|
+
// \`width\` wide and \`height\` tall above y = 0, with \`n\` round drips hanging
|
|
2628
|
+
// below it up to \`depth\` mm, their lengths and places varied by \`seed\`
|
|
2629
|
+
module drip_edge(width, height = 6, depth = 8, n, seed = 1) {
|
|
2630
|
+
k = is_undef(n) ? max(2, round(width / 12)) : n;
|
|
2631
|
+
len_ = rands(0.35, 1, k, seed);
|
|
2632
|
+
shift = rands(-0.25, 0.25, k, seed + 1);
|
|
2633
|
+
r = min(width / k / 4, depth / 3);
|
|
2634
|
+
rect([width, height]);
|
|
2635
|
+
for (i = [0:k - 1])
|
|
2636
|
+
let (x = width * (i + 0.5 + shift[i]) / k)
|
|
2637
|
+
hull() {
|
|
2638
|
+
translate([x, height / 2]) circle(r = r);
|
|
2639
|
+
translate([x, -depth * len_[i] + r]) circle(r = r);
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
// An edge of waves, as water or a frill: a strip \`width\` wide and \`height\`
|
|
2644
|
+
// tall above y = 0, its bottom edge \`n\` waves \`depth\` mm deep
|
|
2645
|
+
module wave_edge(width, height = 6, depth = 4, n) {
|
|
2646
|
+
k = is_undef(n) ? max(1, round(width / 20)) : n;
|
|
2647
|
+
steps = 24 * k;
|
|
2648
|
+
polygon(concat(
|
|
2649
|
+
[[0, height], [width, height]],
|
|
2650
|
+
[for (i = [0:steps]) let (x = width * (1 - i / steps)) [x, -depth / 2 + depth / 2 * cos(360 * k * x / width)]]
|
|
2651
|
+
));
|
|
2652
|
+
}
|
|
1549
2653
|
`,"kerf/shapes":`// kerf/shapes: basic shapes by name, sized to a box.
|
|
1550
2654
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1551
2655
|
//
|
|
@@ -1870,8 +2974,9 @@ module speech_bubble(size = [40, 30], r, tail) {
|
|
|
1870
2974
|
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
2975
|
}
|
|
1872
2976
|
}
|
|
1873
|
-
`,"kerf/sizes":`// kerf/sizes: paper, card and
|
|
1874
|
-
//
|
|
2977
|
+
`,"kerf/sizes":`// kerf/sizes: paper, card, photo and banknote sizes, and the sizes of
|
|
2978
|
+
// bought parts and everyday things, in millimetres, for holders, folders,
|
|
2979
|
+
// frames and boxes made to fit them.
|
|
1875
2980
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1876
2981
|
|
|
1877
2982
|
// Paper sizes as [width, height], portrait: "A0" to "A8", "B4" to "B6",
|
|
@@ -1884,7 +2989,8 @@ function paper_size(name) = let (s = lookup_size(name, PAPER_SIZES))
|
|
|
1884
2989
|
// Card sizes as [width, height], landscape: "business" (85 x 55, Europe),
|
|
1885
2990
|
// "us business" (88.9 x 50.8), "credit" (85.6 x 53.98, ID-1), "japan"
|
|
1886
2991
|
// (91 x 55), "playing" (63 x 88), "bridge" (56 x 87), "tarot" (70 x 120),
|
|
1887
|
-
// "postcard" (148 x 105), "us postcard" (152.4 x 101.6)
|
|
2992
|
+
// "postcard" (148 x 105), "us postcard" (152.4 x 101.6), "gift card"
|
|
2993
|
+
// (85.6 x 53.98, as a credit card).
|
|
1888
2994
|
function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
|
|
1889
2995
|
is_undef(s) ? assert(false, str("Unknown card size \\"", name, "\\". Known: ", size_names(CARD_SIZES))) : s;
|
|
1890
2996
|
|
|
@@ -1894,15 +3000,39 @@ function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
|
|
|
1894
3000
|
function photo_size(name) = let (s = lookup_size(lookup_alias(name, PHOTO_ALIASES), PHOTO_SIZES))
|
|
1895
3001
|
is_undef(s) ? assert(false, str("Unknown photo size \\"", name, "\\". Known: ", size_names(PHOTO_SIZES))) : s;
|
|
1896
3002
|
|
|
1897
|
-
//
|
|
1898
|
-
//
|
|
1899
|
-
//
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
3003
|
+
// Banknote sizes as [width, height], landscape: "usd" (every US note),
|
|
3004
|
+
// "cad" (every Canadian note), "eur 5" to "eur 200", "gbp 5" to "gbp 50",
|
|
3005
|
+
// "aud 5" to "aud 100".
|
|
3006
|
+
function note_size(name) = let (s = lookup_size(name, NOTE_SIZES))
|
|
3007
|
+
is_undef(s) ? assert(false, str("Unknown banknote \\"", name, "\\". Known: ", size_names(NOTE_SIZES))) : s;
|
|
3008
|
+
|
|
3009
|
+
// A bought part's or an everyday thing's sizes by name, as a record: \`body\`
|
|
3010
|
+
// [width, depth, height]; for a round one its \`diameter\` and \`height\` (an
|
|
3011
|
+
// egg's \`length\`); for parts with one, the \`shaft\` diameter, the
|
|
3012
|
+
// \`shaft_length\` it stands out of the body and the \`hole\` to cut for it.
|
|
3013
|
+
// Retail sizes vary: measure yours.
|
|
3014
|
+
// Movements: "music-18" (an 18-note wind-up music box movement, shaft the
|
|
3015
|
+
// winding key's), "quartz-clock" (a 56 mm quartz clock movement with the
|
|
3016
|
+
// 16.5 mm shaft for dials up to 8 mm thick).
|
|
3017
|
+
// Lights: "tealight", "maxi tealight", "led tealight", "led puck",
|
|
3018
|
+
// "fairy lights" (the battery box of a string of them, with its \`wire\`).
|
|
3019
|
+
// Eggs and bottles: "hen egg", "chocolate egg", "wine bottle" (with its
|
|
3020
|
+
// \`neck\`).
|
|
3021
|
+
// Small parts: "magnet 6x2", "magnet 10x3", "magnet 12x3" (discs),
|
|
3022
|
+
// "key ring 25", "battery box 2aa", "battery box 3aa", "coin cell holder",
|
|
3023
|
+
// "key fob", "marble-16", "marble-25".
|
|
3024
|
+
// Boxes: "tissue box", "tissue cube".
|
|
1903
3025
|
function part_size(name) = let (s = lookup_size(name, PART_SIZES))
|
|
1904
3026
|
is_undef(s) ? assert(false, str("Unknown part \\"", name, "\\". Known: ", size_names(PART_SIZES))) : s;
|
|
1905
3027
|
|
|
3028
|
+
// The names in one of the tables, as a list, for a customizer menu:
|
|
3029
|
+
// "paper", "card", "photo", "note" (banknotes) or "part"
|
|
3030
|
+
function size_list(kind) =
|
|
3031
|
+
let (t = kind == "paper" ? PAPER_SIZES : kind == "card" ? CARD_SIZES : kind == "photo" ? PHOTO_SIZES
|
|
3032
|
+
: kind == "note" ? NOTE_SIZES : kind == "part" ? PART_SIZES : undef)
|
|
3033
|
+
assert(!is_undef(t), str("size_list(): kind must be \\"paper\\", \\"card\\", \\"photo\\", \\"note\\" or \\"part\\", got ", kind))
|
|
3034
|
+
[for (e = t) e[0]];
|
|
3035
|
+
|
|
1906
3036
|
// A size turned to lie wider than tall
|
|
1907
3037
|
function landscape(size) = size[0] >= size[1] ? size : [size[1], size[0]];
|
|
1908
3038
|
// A size turned to stand taller than wide
|
|
@@ -1920,7 +3050,15 @@ PAPER_SIZES = [
|
|
|
1920
3050
|
CARD_SIZES = [
|
|
1921
3051
|
["business", [85, 55]], ["us business", [88.9, 50.8]], ["credit", [85.6, 53.98]],
|
|
1922
3052
|
["japan", [91, 55]], ["playing", [63, 88]], ["bridge", [56, 87]], ["tarot", [70, 120]],
|
|
1923
|
-
["postcard", [148, 105]], ["us postcard", [152.4, 101.6]]
|
|
3053
|
+
["postcard", [148, 105]], ["us postcard", [152.4, 101.6]], ["gift card", [85.6, 53.98]]
|
|
3054
|
+
];
|
|
3055
|
+
NOTE_SIZES = [
|
|
3056
|
+
["usd", [155.96, 66.29]], ["cad", [152.4, 69.85]],
|
|
3057
|
+
["eur 5", [120, 62]], ["eur 10", [127, 67]], ["eur 20", [133, 72]],
|
|
3058
|
+
["eur 50", [140, 77]], ["eur 100", [147, 77]], ["eur 200", [153, 77]],
|
|
3059
|
+
["gbp 5", [125, 65]], ["gbp 10", [132, 69]], ["gbp 20", [139, 73]], ["gbp 50", [146, 77]],
|
|
3060
|
+
["aud 5", [130, 65]], ["aud 10", [137, 65]], ["aud 20", [144, 65]],
|
|
3061
|
+
["aud 50", [151, 65]], ["aud 100", [158, 65]]
|
|
1924
3062
|
];
|
|
1925
3063
|
PHOTO_SIZES = [
|
|
1926
3064
|
["4x6", [152.4, 101.6]], ["5x7", [177.8, 127]], ["8x10", [254, 203.2]],
|
|
@@ -1936,7 +3074,25 @@ PART_SIZES = [
|
|
|
1936
3074
|
["music-18", {body = [50, 44, 20], shaft = 3.5, hole = 6}],
|
|
1937
3075
|
["quartz-clock", {body = [56, 56, 16], shaft = 7.6, shaft_length = 16.5, hole = 8, dial = 8}],
|
|
1938
3076
|
["marble-16", {body = [16, 16, 16]}],
|
|
1939
|
-
["marble-25", {body = [25, 25, 25]}]
|
|
3077
|
+
["marble-25", {body = [25, 25, 25]}],
|
|
3078
|
+
["tealight", {body = [39, 39, 16], diameter = 39, height = 16, hole = 40}],
|
|
3079
|
+
["maxi tealight", {body = [59, 59, 24], diameter = 59, height = 24, hole = 60}],
|
|
3080
|
+
["led tealight", {body = [38, 38, 36], diameter = 38, height = 36, hole = 40}],
|
|
3081
|
+
["led puck", {body = [70, 70, 25], diameter = 70, height = 25, hole = 72}],
|
|
3082
|
+
["fairy lights", {body = [62, 37, 22], wire = 2}],
|
|
3083
|
+
["hen egg", {body = [44, 44, 57], diameter = 44, length = 57}],
|
|
3084
|
+
["chocolate egg", {body = [40, 40, 60], diameter = 40, length = 60}],
|
|
3085
|
+
["wine bottle", {body = [76, 76, 300], diameter = 76, height = 300, neck = 30}],
|
|
3086
|
+
["magnet 6x2", {body = [6, 6, 2], diameter = 6, height = 2, hole = 6.2}],
|
|
3087
|
+
["magnet 10x3", {body = [10, 10, 3], diameter = 10, height = 3, hole = 10.2}],
|
|
3088
|
+
["magnet 12x3", {body = [12, 12, 3], diameter = 12, height = 3, hole = 12.2}],
|
|
3089
|
+
["key ring 25", {body = [25, 25, 2.5], diameter = 25, height = 2.5}],
|
|
3090
|
+
["battery box 2aa", {body = [68, 35, 18]}],
|
|
3091
|
+
["battery box 3aa", {body = [68, 48, 18]}],
|
|
3092
|
+
["coin cell holder", {body = [25, 21, 6]}],
|
|
3093
|
+
["key fob", {body = [60, 35, 15]}],
|
|
3094
|
+
["tissue box", {body = [240, 120, 90]}],
|
|
3095
|
+
["tissue cube", {body = [115, 115, 130]}]
|
|
1940
3096
|
];
|
|
1941
3097
|
|
|
1942
3098
|
// The size of that name in a table of [name, size], ignoring case
|
|
@@ -1948,6 +3104,65 @@ function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = ali
|
|
|
1948
3104
|
len(hit) ? hit[0] : name;
|
|
1949
3105
|
// The names in a table, for messages
|
|
1950
3106
|
function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
3107
|
+
`,"kerf/sphere":`// kerf/sphere: slot-together balls and domes, as 3D baubles, globes and
|
|
3108
|
+
// lantern domes.
|
|
3109
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
3110
|
+
//
|
|
3111
|
+
// A ball is half-disc fins standing round an upright axis, like the
|
|
3112
|
+
// segments of an orange, held by flat rings slotted onto them with halving
|
|
3113
|
+
// joints. The fins stop short of the axis, so they never meet each other.
|
|
3114
|
+
|
|
3115
|
+
// The heights of a ball's rings above its centre: the equator alone, or
|
|
3116
|
+
// \`rings\` spread between 60 degrees south and north; for a dome, from 10
|
|
3117
|
+
// to 70 degrees north
|
|
3118
|
+
function ball_rings(d, rings = 1, dome = false) =
|
|
3119
|
+
let (R = d / 2)
|
|
3120
|
+
dome ? (rings <= 1 ? [R * sin(10)] : [for (i = [0:rings - 1]) R * sin(10 + 60 * i / (rings - 1))])
|
|
3121
|
+
: rings <= 1 ? [0] : [for (i = [0:rings - 1]) R * sin(-60 + 120 * i / (rings - 1))];
|
|
3122
|
+
|
|
3123
|
+
// A ball \`d\` across, its centre at \`at\`: \`fins\` half-disc fins round its
|
|
3124
|
+
// upright axis and \`rings\` flat rings \`width\` wide slotted onto them. A
|
|
3125
|
+
// dome is the top half, standing on its lowest ring. \`hollow\` cuts the
|
|
3126
|
+
// fins away within that radius of the centre, to make room for a scene
|
|
3127
|
+
// inside; \`floor\` makes the lowest ring a whole disc for it to stand on,
|
|
3128
|
+
// with a rail along x across the hollow for a standee's feet.
|
|
3129
|
+
// \`loop\` (a diameter) puts a hole near the top of each fin for a ribbon
|
|
3130
|
+
// to hang it by. Parts are named after \`label\`: "ball fin", "ball ring 1".
|
|
3131
|
+
module ball(d = 80, fins = 6, rings = 1, width = 8, hollow = 0, floor = false, dome = false, loop = 4, at = [0, 0, 0], label = "ball", clearance = 0.1) {
|
|
3132
|
+
R = d / 2;
|
|
3133
|
+
t = $thickness;
|
|
3134
|
+
core = 1.2 * t;
|
|
3135
|
+
assert(fins >= 3, "ball(): fins must be 3 or more");
|
|
3136
|
+
assert(width < R / 2, "ball(): the rings must be narrower than a quarter of the ball");
|
|
3137
|
+
heights = ball_rings(d, rings, dome);
|
|
3138
|
+
hx = core + loop / 2 + 2;
|
|
3139
|
+
part(str(label, " fin"), qty = fins,
|
|
3140
|
+
at = [for (k = [0:fins - 1]) let (a = 360 * k / fins) at + [-t / 2 * sin(a), t / 2 * cos(a), 0]],
|
|
3141
|
+
rotate = [for (k = [0:fins - 1]) [90, 0, 360 * k / fins]],
|
|
3142
|
+
halving = [str(label, " ring*")], clearance = clearance)
|
|
3143
|
+
difference() {
|
|
3144
|
+
intersection() {
|
|
3145
|
+
circle(r = R);
|
|
3146
|
+
translate([core, dome ? 0 : -R]) rect([R, dome ? R : 2 * R]);
|
|
3147
|
+
}
|
|
3148
|
+
if (hollow > 0) circle(r = hollow);
|
|
3149
|
+
if (loop > 0) translate([hx, sqrt(R * R - (hx + loop / 2) * (hx + loop / 2)) - loop / 2 - 2]) circle(d = loop);
|
|
3150
|
+
}
|
|
3151
|
+
for (i = [0:len(heights) - 1])
|
|
3152
|
+
let (h = heights[i], r = sqrt(R * R - h * h))
|
|
3153
|
+
part(str(label, " ring ", i + 1), at = at + [0, 0, h - t / 2])
|
|
3154
|
+
// As many corners as a multiple of the fins, so every fin crosses
|
|
3155
|
+
// a ring alike and takes the same slot
|
|
3156
|
+
difference() {
|
|
3157
|
+
circle(r = r, $fn = fins * ceil(120 / fins));
|
|
3158
|
+
if (!(floor && i == 0)) circle(r = r - width, $fn = fins * ceil(120 / fins));
|
|
3159
|
+
// A floor in a hollow ball has a rail across its middle, where no
|
|
3160
|
+
// fin reaches, for a standee from kerf/scene
|
|
3161
|
+
if (floor && i == 0 && hollow > 12)
|
|
3162
|
+
translate([-(hollow - 6), -(t + clearance) / 2]) rect([2 * (hollow - 6), t + clearance]);
|
|
3163
|
+
}
|
|
3164
|
+
if (loop > 0) hardware("ribbon", at + [0, 0, R - 6], at + [0, 0, R + 25], [6, 0.4], label = str(label, " ribbon"));
|
|
3165
|
+
}
|
|
1951
3166
|
`,"kerf/stand":`// kerf/stand: a sign, a photo or a calendar standing in a base.
|
|
1952
3167
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1953
3168
|
//
|
|
@@ -2019,15 +3234,26 @@ module stand_slots(width, count = undef, tab = undef, lean = 0, clearance = 0.1)
|
|
|
2019
3234
|
// closed and its holes filled, with the drawing's detail engraved on it:
|
|
2020
3235
|
// a pictogram drawn as separate strokes (a moon and stars, yarn) cut out
|
|
2021
3236
|
// in one piece. bridge = w also joins pieces too far apart to close, by
|
|
2022
|
-
// strips w wide.
|
|
2023
|
-
|
|
3237
|
+
// strips w wide. min_width = w grows every line narrower than w to w, so
|
|
3238
|
+
// a symbol drawn small can be cut.
|
|
3239
|
+
module symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close = undef, bridge = undef, min_width = undef) {
|
|
2024
3240
|
assert(box == "drawn" || box == "grid", "box is \\"drawn\\" or \\"grid\\"");
|
|
2025
3241
|
s = symbol_entry(name);
|
|
2026
3242
|
vb = box == "grid" ? s[5] : s[2];
|
|
2027
3243
|
k = size / max(vb[2], vb[3]);
|
|
2028
|
-
module
|
|
3244
|
+
module art() translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
2029
3245
|
scale([k, -k]) translate([-vb[0] - vb[2] / 2, -vb[1] - vb[3] / 2])
|
|
2030
3246
|
path(s[4], fill = fill, close = true);
|
|
3247
|
+
// With min_width, every line narrower than it grows to it: what an
|
|
3248
|
+
// opening by that width removes, grown by half of it either side
|
|
3249
|
+
module drawn() if (is_undef(min_width) || min_width <= 0) art();
|
|
3250
|
+
else union() {
|
|
3251
|
+
art();
|
|
3252
|
+
offset(r = min_width / 2) difference() {
|
|
3253
|
+
art();
|
|
3254
|
+
offset(r = min_width / 2) offset(r = -min_width / 2) art();
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
2031
3257
|
r = is_undef(close) ? size / 30 : close;
|
|
2032
3258
|
module silhouette() if (is_undef(bridge)) fill_holes() close(r) drawn();
|
|
2033
3259
|
else join_islands(bridge) fill_holes() close(r) drawn();
|
|
@@ -3018,42 +4244,47 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
|
|
|
3018
4244
|
if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
|
|
3019
4245
|
if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
|
|
3020
4246
|
}
|
|
3021
|
-
`};String.prototype.codePointAt||(function(){var n=(function(){try{var t={},c=Object.defineProperty,a=c(t,t,t)&&c}catch{}return a})(),e=function(t){if(this==null)throw TypeError();var c=String(this),a=c.length,r=t?Number(t):0;if(r!=r&&(r=0),!(r<0||r>=a)){var s=c.charCodeAt(r),i;return s>=55296&&s<=56319&&a>r+1&&(i=c.charCodeAt(r+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};n?n(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var p4=0,H7=-3;function l3(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function u9(n,e){this.source=n,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new l3,this.dtree=new l3}var V7=new l3,O7=new l3,m4=new Uint8Array(30),v4=new Uint16Array(30),F7=new Uint8Array(30),D7=new Uint16Array(30),f9=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),X6=new l3,N0=new Uint8Array(320);function R7(n,e,t,c){var a,r;for(a=0;a<t;++a)n[a]=0;for(a=0;a<30-t;++a)n[a+t]=a/t|0;for(r=c,a=0;a<30;++a)e[a]=r,r+=1<<n[a]}function d9(n,e){var t;for(t=0;t<7;++t)n.table[t]=0;for(n.table[7]=24,n.table[8]=152,n.table[9]=112,t=0;t<24;++t)n.trans[t]=256+t;for(t=0;t<144;++t)n.trans[24+t]=t;for(t=0;t<8;++t)n.trans[168+t]=280+t;for(t=0;t<112;++t)n.trans[176+t]=144+t;for(t=0;t<5;++t)e.table[t]=0;for(e.table[5]=32,t=0;t<32;++t)e.trans[t]=t}var Z6=new Uint16Array(16);function Y5(n,e,t,c){var a,r;for(a=0;a<16;++a)n.table[a]=0;for(a=0;a<c;++a)n.table[e[t+a]]++;for(n.table[0]=0,r=0,a=0;a<16;++a)Z6[a]=r,r+=n.table[a];for(a=0;a<c;++a)e[t+a]&&(n.trans[Z6[e[t+a]]++]=a)}function p9(n){n.bitcount--||(n.tag=n.source[n.sourceIndex++],n.bitcount=7);var e=n.tag&1;return n.tag>>>=1,e}function $0(n,e,t){if(!e)return t;for(;n.bitcount<24;)n.tag|=n.source[n.sourceIndex++]<<n.bitcount,n.bitcount+=8;var c=n.tag&65535>>>16-e;return n.tag>>>=e,n.bitcount-=e,c+t}function r4(n,e){for(;n.bitcount<24;)n.tag|=n.source[n.sourceIndex++]<<n.bitcount,n.bitcount+=8;var t=0,c=0,a=0,r=n.tag;do c=2*c+(r&1),r>>>=1,++a,t+=e.table[a],c-=e.table[a];while(c>=0);return n.tag=r,n.bitcount-=a,e.trans[t+c]}function m9(n,e,t){var c,a,r,s,i,o;for(c=$0(n,5,257),a=$0(n,5,1),r=$0(n,4,4),s=0;s<19;++s)N0[s]=0;for(s=0;s<r;++s){var l=$0(n,3,0);N0[f9[s]]=l}for(Y5(X6,N0,0,19),i=0;i<c+a;){var h=r4(n,X6);switch(h){case 16:var f=N0[i-1];for(o=$0(n,2,3);o;--o)N0[i++]=f;break;case 17:for(o=$0(n,3,3);o;--o)N0[i++]=0;break;case 18:for(o=$0(n,7,11);o;--o)N0[i++]=0;break;default:N0[i++]=h;break}}Y5(e,N0,0,c),Y5(t,N0,c,a)}function Y6(n,e,t){for(;;){var c=r4(n,e);if(c===256)return p4;if(c<256)n.dest[n.destLen++]=c;else{var a,r,s,i;for(c-=257,a=$0(n,m4[c],v4[c]),r=r4(n,t),s=n.destLen-$0(n,F7[r],D7[r]),i=s;i<s+a;++i)n.dest[n.destLen++]=n.dest[i]}}}function v9(n){for(var e,t,c;n.bitcount>8;)n.sourceIndex--,n.bitcount-=8;if(e=n.source[n.sourceIndex+1],e=256*e+n.source[n.sourceIndex],t=n.source[n.sourceIndex+3],t=256*t+n.source[n.sourceIndex+2],e!==(~t&65535))return H7;for(n.sourceIndex+=4,c=e;c;--c)n.dest[n.destLen++]=n.source[n.sourceIndex++];return n.bitcount=0,p4}function g9(n,e){var t=new u9(n,e),c,a,r;do{switch(c=p9(t),a=$0(t,2,0),a){case 0:r=v9(t);break;case 1:r=Y6(t,V7,O7);break;case 2:m9(t,t.ltree,t.dtree),r=Y6(t,t.ltree,t.dtree);break;default:r=H7}if(r!==p4)throw new Error("Data error")}while(!c);return t.destLen<t.dest.length?typeof t.dest.slice=="function"?t.dest.slice(0,t.destLen):t.dest.subarray(0,t.destLen):t.dest}d9(V7,O7);R7(m4,v4,4,3);R7(F7,D7,2,1);m4[28]=0;v4[28]=258;var y9=g9;function V2(n,e,t,c,a){return Math.pow(1-a,3)*n+3*Math.pow(1-a,2)*a*e+3*(1-a)*Math.pow(a,2)*t+Math.pow(a,3)*c}function o2(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}o2.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};o2.prototype.addPoint=function(n,e){typeof n=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=n,this.x2=n),n<this.x1&&(this.x1=n),n>this.x2&&(this.x2=n)),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))};o2.prototype.addX=function(n){this.addPoint(n,null)};o2.prototype.addY=function(n){this.addPoint(null,n)};o2.prototype.addBezier=function(n,e,t,c,a,r,s,i){var o=[n,e],l=[t,c],h=[a,r],f=[s,i];this.addPoint(n,e),this.addPoint(s,i);for(var u=0;u<=1;u++){var d=6*o[u]-12*l[u]+6*h[u],m=-3*o[u]+9*l[u]-9*h[u]+3*f[u],p=3*l[u]-3*o[u];if(m===0){if(d===0)continue;var v=-p/d;0<v&&v<1&&(u===0&&this.addX(V2(o[u],l[u],h[u],f[u],v)),u===1&&this.addY(V2(o[u],l[u],h[u],f[u],v)));continue}var g=Math.pow(d,2)-4*p*m;if(!(g<0)){var M=(-d+Math.sqrt(g))/(2*m);0<M&&M<1&&(u===0&&this.addX(V2(o[u],l[u],h[u],f[u],M)),u===1&&this.addY(V2(o[u],l[u],h[u],f[u],M)));var y=(-d-Math.sqrt(g))/(2*m);0<y&&y<1&&(u===0&&this.addX(V2(o[u],l[u],h[u],f[u],y)),u===1&&this.addY(V2(o[u],l[u],h[u],f[u],y)))}}};o2.prototype.addQuad=function(n,e,t,c,a,r){var s=n+.6666666666666666*(t-n),i=e+2/3*(c-e),o=s+1/3*(a-n),l=i+1/3*(r-e);this.addBezier(n,e,s,i,o,l,a,r)};function $1(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}$1.prototype.moveTo=function(n,e){this.commands.push({type:"M",x:n,y:e})};$1.prototype.lineTo=function(n,e){this.commands.push({type:"L",x:n,y:e})};$1.prototype.curveTo=$1.prototype.bezierCurveTo=function(n,e,t,c,a,r){this.commands.push({type:"C",x1:n,y1:e,x2:t,y2:c,x:a,y:r})};$1.prototype.quadTo=$1.prototype.quadraticCurveTo=function(n,e,t,c){this.commands.push({type:"Q",x1:n,y1:e,x:t,y:c})};$1.prototype.close=$1.prototype.closePath=function(){this.commands.push({type:"Z"})};$1.prototype.extend=function(n){if(n.commands)n=n.commands;else if(n instanceof o2){var e=n;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,n)};$1.prototype.getBoundingBox=function(){for(var n=new o2,e=0,t=0,c=0,a=0,r=0;r<this.commands.length;r++){var s=this.commands[r];switch(s.type){case"M":n.addPoint(s.x,s.y),e=c=s.x,t=a=s.y;break;case"L":n.addPoint(s.x,s.y),c=s.x,a=s.y;break;case"Q":n.addQuad(c,a,s.x1,s.y1,s.x,s.y),c=s.x,a=s.y;break;case"C":n.addBezier(c,a,s.x1,s.y1,s.x2,s.y2,s.x,s.y),c=s.x,a=s.y;break;case"Z":c=e,a=t;break;default:throw new Error("Unexpected path command "+s.type)}}return n.isEmpty()&&n.addPoint(0,0),n};$1.prototype.draw=function(n){n.beginPath();for(var e=0;e<this.commands.length;e+=1){var t=this.commands[e];t.type==="M"?n.moveTo(t.x,t.y):t.type==="L"?n.lineTo(t.x,t.y):t.type==="C"?n.bezierCurveTo(t.x1,t.y1,t.x2,t.y2,t.x,t.y):t.type==="Q"?n.quadraticCurveTo(t.x1,t.y1,t.x,t.y):t.type==="Z"&&n.closePath()}this.fill&&(n.fillStyle=this.fill,n.fill()),this.stroke&&(n.strokeStyle=this.stroke,n.lineWidth=this.strokeWidth,n.stroke())};$1.prototype.toPathData=function(n){n=n!==void 0?n:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(n)}function t(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var c="",a=0;a<this.commands.length;a+=1){var r=this.commands[a];r.type==="M"?c+="M"+t(r.x,r.y):r.type==="L"?c+="L"+t(r.x,r.y):r.type==="C"?c+="C"+t(r.x1,r.y1,r.x2,r.y2,r.x,r.y):r.type==="Q"?c+="Q"+t(r.x1,r.y1,r.x,r.y):r.type==="Z"&&(c+="Z")}return c};$1.prototype.toSVG=function(n){var e='<path d="';return e+=this.toPathData(n),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};$1.prototype.toDOMElement=function(n){var e=this.toPathData(n),t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",e),t};function q7(n){throw new Error(n)}function K6(n,e){n||q7(e)}var n1={fail:q7,argument:K6,assert:K6},J6=32768,Q6=2147483648,F2={},U={},r1={};function I0(n){return function(){return n}}U.BYTE=function(n){return n1.argument(n>=0&&n<=255,"Byte value should be between 0 and 255."),[n]};r1.BYTE=I0(1);U.CHAR=function(n){return[n.charCodeAt(0)]};r1.CHAR=I0(1);U.CHARARRAY=function(n){typeof n>"u"&&(n="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],t=0;t<n.length;t+=1)e[t]=n.charCodeAt(t);return e};r1.CHARARRAY=function(n){return typeof n>"u"?0:n.length};U.USHORT=function(n){return[n>>8&255,n&255]};r1.USHORT=I0(2);U.SHORT=function(n){return n>=J6&&(n=-(2*J6-n)),[n>>8&255,n&255]};r1.SHORT=I0(2);U.UINT24=function(n){return[n>>16&255,n>>8&255,n&255]};r1.UINT24=I0(3);U.ULONG=function(n){return[n>>24&255,n>>16&255,n>>8&255,n&255]};r1.ULONG=I0(4);U.LONG=function(n){return n>=Q6&&(n=-(2*Q6-n)),[n>>24&255,n>>16&255,n>>8&255,n&255]};r1.LONG=I0(4);U.FIXED=U.ULONG;r1.FIXED=r1.ULONG;U.FWORD=U.SHORT;r1.FWORD=r1.SHORT;U.UFWORD=U.USHORT;r1.UFWORD=r1.USHORT;U.LONGDATETIME=function(n){return[0,0,0,0,n>>24&255,n>>16&255,n>>8&255,n&255]};r1.LONGDATETIME=I0(8);U.TAG=function(n){return n1.argument(n.length===4,"Tag should be exactly 4 ASCII characters."),[n.charCodeAt(0),n.charCodeAt(1),n.charCodeAt(2),n.charCodeAt(3)]};r1.TAG=I0(4);U.Card8=U.BYTE;r1.Card8=r1.BYTE;U.Card16=U.USHORT;r1.Card16=r1.USHORT;U.OffSize=U.BYTE;r1.OffSize=r1.BYTE;U.SID=U.USHORT;r1.SID=r1.USHORT;U.NUMBER=function(n){return n>=-107&&n<=107?[n+139]:n>=108&&n<=1131?(n=n-108,[(n>>8)+247,n&255]):n>=-1131&&n<=-108?(n=-n-108,[(n>>8)+251,n&255]):n>=-32768&&n<=32767?U.NUMBER16(n):U.NUMBER32(n)};r1.NUMBER=function(n){return U.NUMBER(n).length};U.NUMBER16=function(n){return[28,n>>8&255,n&255]};r1.NUMBER16=I0(3);U.NUMBER32=function(n){return[29,n>>24&255,n>>16&255,n>>8&255,n&255]};r1.NUMBER32=I0(5);U.REAL=function(n){var e=n.toString(),t=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(t){var c=parseFloat("1e"+((t[2]?+t[2]:0)+t[1].length));e=(Math.round(n*c)/c).toString()}for(var a="",r=0,s=e.length;r<s;r+=1){var i=e[r];i==="e"?a+=e[++r]==="-"?"c":"b":i==="."?a+="a":i==="-"?a+="e":a+=i}a+=a.length&1?"f":"ff";for(var o=[30],l=0,h=a.length;l<h;l+=2)o.push(parseInt(a.substr(l,2),16));return o};r1.REAL=function(n){return U.REAL(n).length};U.NAME=U.CHARARRAY;r1.NAME=r1.CHARARRAY;U.STRING=U.CHARARRAY;r1.STRING=r1.CHARARRAY;F2.UTF8=function(n,e,t){for(var c=[],a=t,r=0;r<a;r++,e+=1)c[r]=n.getUint8(e);return String.fromCharCode.apply(null,c)};F2.UTF16=function(n,e,t){for(var c=[],a=t/2,r=0;r<a;r++,e+=2)c[r]=n.getUint16(e);return String.fromCharCode.apply(null,c)};U.UTF16=function(n){for(var e=[],t=0;t<n.length;t+=1){var c=n.charCodeAt(t);e[e.length]=c>>8&255,e[e.length]=c&255}return e};r1.UTF16=function(n){return n.length*2};var s4={"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"};F2.MACSTRING=function(n,e,t,c){var a=s4[c];if(a!==void 0){for(var r="",s=0;s<t;s++){var i=n.getUint8(e+s);i<=127?r+=String.fromCharCode(i):r+=a[i&127]}return r}};var G3=typeof WeakMap=="function"&&new WeakMap,j3,b9=function(n){if(!j3){j3={};for(var e in s4)j3[e]=new String(e)}var t=j3[n];if(t!==void 0){if(G3){var c=G3.get(t);if(c!==void 0)return c}var a=s4[n];if(a!==void 0){for(var r={},s=0;s<a.length;s++)r[a.charCodeAt(s)]=s+128;return G3&&G3.set(t,r),r}}};U.MACSTRING=function(n,e){var t=b9(e);if(t!==void 0){for(var c=[],a=0;a<n.length;a++){var r=n.charCodeAt(a);if(r>=128&&(r=t[r],r===void 0))return;c[a]=r}return c}};r1.MACSTRING=function(n,e){var t=U.MACSTRING(n,e);return t!==void 0?t.length:0};function i4(n){return n>=-128&&n<=127}function M9(n,e,t){for(var c=0,a=n.length;e<a&&c<64&&n[e]===0;)++e,++c;return t.push(128|c-1),e}function x9(n,e,t){for(var c=0,a=n.length,r=e;r<a&&c<64;){var s=n[r];if(!i4(s)||s===0&&r+1<a&&n[r+1]===0)break;++r,++c}t.push(c-1);for(var i=e;i<r;++i)t.push(n[i]+256&255);return r}function w9(n,e,t){for(var c=0,a=n.length,r=e;r<a&&c<64;){var s=n[r];if(s===0||i4(s)&&r+1<a&&i4(n[r+1]))break;++r,++c}t.push(64|c-1);for(var i=e;i<r;++i){var o=n[i];t.push(o+65536>>8&255,o+256&255)}return r}U.VARDELTAS=function(n){for(var e=0,t=[];e<n.length;){var c=n[e];c===0?e=M9(n,e,t):c>=-128&&c<=127?e=x9(n,e,t):e=w9(n,e,t)}return t};U.INDEX=function(n){for(var e=1,t=[e],c=[],a=0;a<n.length;a+=1){var r=U.OBJECT(n[a]);Array.prototype.push.apply(c,r),e+=r.length,t.push(e)}if(c.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,U.BYTE,U.USHORT,U.UINT24,U.ULONG][i],l=0;l<t.length;l+=1){var h=o(t[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(U.Card16(n.length),U.OffSize(i),s,c)};r1.INDEX=function(n){return U.INDEX(n).length};U.DICT=function(n){for(var e=[],t=Object.keys(n),c=t.length,a=0;a<c;a+=1){var r=parseInt(t[a],0),s=n[r];e=e.concat(U.OPERAND(s.value,s.type)),e=e.concat(U.OPERATOR(r))}return e};r1.DICT=function(n){return U.DICT(n).length};U.OPERATOR=function(n){return n<1200?[n]:[12,n-1200]};U.OPERAND=function(n,e){var t=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)n1.argument(n.length===e.length,"Not enough arguments given for type"+e),t=t.concat(U.OPERAND(n[c],e[c]));else if(e==="SID")t=t.concat(U.NUMBER(n));else if(e==="offset")t=t.concat(U.NUMBER32(n));else if(e==="number")t=t.concat(U.NUMBER(n));else if(e==="real")t=t.concat(U.REAL(n));else throw new Error("Unknown operand type "+e);return t};U.OP=U.BYTE;r1.OP=r1.BYTE;var W3=typeof WeakMap=="function"&&new WeakMap;U.CHARSTRING=function(n){if(W3){var e=W3.get(n);if(e!==void 0)return e}for(var t=[],c=n.length,a=0;a<c;a+=1){var r=n[a];t=t.concat(U[r.type](r.value))}return W3&&W3.set(n,t),t};r1.CHARSTRING=function(n){return U.CHARSTRING(n).length};U.OBJECT=function(n){var e=U[n.type];return n1.argument(e!==void 0,"No encoding function for type "+n.type),e(n.value)};r1.OBJECT=function(n){var e=r1[n.type];return n1.argument(e!==void 0,"No sizeOf function for type "+n.type),e(n.value)};U.TABLE=function(n){for(var e=[],t=n.fields.length,c=[],a=[],r=0;r<t;r+=1){var s=n.fields[r],i=U[s.type];n1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=n[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(a.push(e.length),e=e.concat([0,0]),c.push(l)):e=e.concat(l)}for(var h=0;h<c.length;h+=1){var f=a[h],u=e.length;n1.argument(u<65536,"Table "+n.tableName+" too big."),e[f]=u>>8,e[f+1]=u&255,e=e.concat(c[h])}return e};r1.TABLE=function(n){for(var e=0,t=n.fields.length,c=0;c<t;c+=1){var a=n.fields[c],r=r1[a.type];n1.argument(r!==void 0,"No sizeOf function for field type "+a.type+" ("+a.name+")");var s=n[a.name];s===void 0&&(s=a.value),e+=r(s),a.type==="TABLE"&&(e+=2)}return e};U.RECORD=U.TABLE;r1.RECORD=r1.TABLE;U.LITERAL=function(n){return n};r1.LITERAL=function(n){return n.length};function X1(n,e,t){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var c=0;c<e.length;c+=1){var a=e[c];this[a.name]=a.value}if(this.tableName=n,this.fields=e,t)for(var r=Object.keys(t),s=0;s<r.length;s+=1){var i=r[s],o=t[i];this[i]!==void 0&&(this[i]=o)}}X1.prototype.encode=function(){return U.TABLE(this)};X1.prototype.sizeOf=function(){return r1.TABLE(this)};function h3(n,e,t){t===void 0&&(t=e.length);var c=new Array(e.length+1);c[0]={name:n+"Count",type:"USHORT",value:t};for(var a=0;a<e.length;a++)c[a+1]={name:n+a,type:"USHORT",value:e[a]};return c}function o4(n,e,t){var c=e.length,a=new Array(c+1);a[0]={name:n+"Count",type:"USHORT",value:c};for(var r=0;r<c;r++)a[r+1]={name:n+r,type:"TABLE",value:t(e[r],r)};return a}function u3(n,e,t){var c=e.length,a=[];a[0]={name:n+"Count",type:"USHORT",value:c};for(var r=0;r<c;r++)a=a.concat(t(e[r],r));return a}function J3(n){n.format===1?X1.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(h3("glyph",n.glyphs))):n.format===2?X1.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(u3("rangeRecord",n.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}]}))):n1.assert(!1,"Coverage format must be 1 or 2.")}J3.prototype=Object.create(X1.prototype);J3.prototype.constructor=J3;function Q3(n){X1.call(this,"scriptListTable",u3("scriptRecord",n,function(e,t){var c=e.script,a=c.defaultLangSys;return n1.assert(!!a,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+t,type:"TAG",value:e.tag},{name:"script"+t,type:"TABLE",value:new X1("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new X1("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:a.reqFeatureIndex}].concat(h3("featureIndex",a.featureIndexes)))}].concat(u3("langSys",c.langSysRecords,function(r,s){var i=r.langSys;return[{name:"langSysTag"+s,type:"TAG",value:r.tag},{name:"langSys"+s,type:"TABLE",value:new X1("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(h3("featureIndex",i.featureIndexes)))}]})))}]}))}Q3.prototype=Object.create(X1.prototype);Q3.prototype.constructor=Q3;function e5(n){X1.call(this,"featureListTable",u3("featureRecord",n,function(e,t){var c=e.feature;return[{name:"featureTag"+t,type:"TAG",value:e.tag},{name:"feature"+t,type:"TABLE",value:new X1("featureTable",[{name:"featureParams",type:"USHORT",value:c.featureParams}].concat(h3("lookupListIndex",c.lookupListIndexes)))}]}))}e5.prototype=Object.create(X1.prototype);e5.prototype.constructor=e5;function t5(n,e){X1.call(this,"lookupListTable",o4("lookup",n,function(t){var c=e[t.lookupType];return n1.assert(!!c,"Unable to write GSUB lookup type "+t.lookupType+" tables."),new X1("lookupTable",[{name:"lookupType",type:"USHORT",value:t.lookupType},{name:"lookupFlag",type:"USHORT",value:t.lookupFlag}].concat(o4("subtable",t.subtables,c)))}))}t5.prototype=Object.create(X1.prototype);t5.prototype.constructor=t5;var B={Table:X1,Record:X1,Coverage:J3,ScriptList:Q3,FeatureList:e5,LookupList:t5,ushortList:h3,tableList:o4,recordList:u3};function e7(n,e){return n.getUint8(e)}function n5(n,e){return n.getUint16(e,!1)}function z9(n,e){return n.getInt16(e,!1)}function g4(n,e){return n.getUint32(e,!1)}function U7(n,e){var t=n.getInt16(e,!1),c=n.getUint16(e+2,!1);return t+c/65535}function k9(n,e){for(var t="",c=e;c<e+4;c+=1)t+=String.fromCharCode(n.getInt8(c));return t}function L9(n,e,t){for(var c=0,a=0;a<t;a+=1)c<<=8,c+=n.getUint8(e+a);return c}function S9(n,e,t){for(var c=[],a=e;a<t;a+=1)c.push(n.getUint8(a));return c}function A9(n){for(var e="",t=0;t<n.length;t+=1)e+=String.fromCharCode(n[t]);return e}var C9={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function I(n,e){this.data=n,this.offset=e,this.relativeOffset=0}I.prototype.parseByte=function(){var n=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,n};I.prototype.parseChar=function(){var n=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,n};I.prototype.parseCard8=I.prototype.parseByte;I.prototype.parseUShort=function(){var n=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,n};I.prototype.parseCard16=I.prototype.parseUShort;I.prototype.parseSID=I.prototype.parseUShort;I.prototype.parseOffset16=I.prototype.parseUShort;I.prototype.parseShort=function(){var n=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,n};I.prototype.parseF2Dot14=function(){var n=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,n};I.prototype.parseULong=function(){var n=g4(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};I.prototype.parseOffset32=I.prototype.parseULong;I.prototype.parseFixed=function(){var n=U7(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};I.prototype.parseString=function(n){var e=this.data,t=this.offset+this.relativeOffset,c="";this.relativeOffset+=n;for(var a=0;a<n;a++)c+=String.fromCharCode(e.getUint8(t+a));return c};I.prototype.parseTag=function(){return this.parseString(4)};I.prototype.parseLongDateTime=function(){var n=g4(this.data,this.offset+this.relativeOffset+4);return n-=2082844800,this.relativeOffset+=8,n};I.prototype.parseVersion=function(n){var e=n5(this.data,this.offset+this.relativeOffset),t=n5(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,n===void 0&&(n=4096),e+t/n/10};I.prototype.skip=function(n,e){e===void 0&&(e=1),this.relativeOffset+=C9[n]*e};I.prototype.parseULongList=function(n){n===void 0&&(n=this.parseULong());for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getUint32(c),c+=4;return this.relativeOffset+=n*4,e};I.prototype.parseOffset16List=I.prototype.parseUShortList=function(n){n===void 0&&(n=this.parseUShort());for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getUint16(c),c+=2;return this.relativeOffset+=n*2,e};I.prototype.parseShortList=function(n){for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getInt16(c),c+=2;return this.relativeOffset+=n*2,e};I.prototype.parseByteList=function(n){for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getUint8(c++);return this.relativeOffset+=n,e};I.prototype.parseList=function(n,e){e||(e=n,n=this.parseUShort());for(var t=new Array(n),c=0;c<n;c++)t[c]=e.call(this);return t};I.prototype.parseList32=function(n,e){e||(e=n,n=this.parseULong());for(var t=new Array(n),c=0;c<n;c++)t[c]=e.call(this);return t};I.prototype.parseRecordList=function(n,e){e||(e=n,n=this.parseUShort());for(var t=new Array(n),c=Object.keys(e),a=0;a<n;a++){for(var r={},s=0;s<c.length;s++){var i=c[s],o=e[i];r[i]=o.call(this)}t[a]=r}return t};I.prototype.parseRecordList32=function(n,e){e||(e=n,n=this.parseULong());for(var t=new Array(n),c=Object.keys(e),a=0;a<n;a++){for(var r={},s=0;s<c.length;s++){var i=c[s],o=e[i];r[i]=o.call(this)}t[a]=r}return t};I.prototype.parseStruct=function(n){if(typeof n=="function")return n.call(this);for(var e=Object.keys(n),t={},c=0;c<e.length;c++){var a=e[c],r=n[a];t[a]=r.call(this)}return t};I.prototype.parseValueRecord=function(n){if(n===void 0&&(n=this.parseUShort()),n!==0){var e={};return n&1&&(e.xPlacement=this.parseShort()),n&2&&(e.yPlacement=this.parseShort()),n&4&&(e.xAdvance=this.parseShort()),n&8&&(e.yAdvance=this.parseShort()),n&16&&(e.xPlaDevice=void 0,this.parseShort()),n&32&&(e.yPlaDevice=void 0,this.parseShort()),n&64&&(e.xAdvDevice=void 0,this.parseShort()),n&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};I.prototype.parseValueRecordList=function(){for(var n=this.parseUShort(),e=this.parseUShort(),t=new Array(e),c=0;c<e;c++)t[c]=this.parseValueRecord(n);return t};I.prototype.parsePointer=function(n){var e=this.parseOffset16();if(e>0)return new I(this.data,this.offset+e).parseStruct(n)};I.prototype.parsePointer32=function(n){var e=this.parseOffset32();if(e>0)return new I(this.data,this.offset+e).parseStruct(n)};I.prototype.parseListOfLists=function(n){for(var e=this.parseOffset16List(),t=e.length,c=this.relativeOffset,a=new Array(t),r=0;r<t;r++){var s=e[r];if(s===0){a[r]=void 0;continue}if(this.relativeOffset=s,n){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=n.call(this);a[r]=o}else a[r]=this.parseUShortList()}return this.relativeOffset=c,a};I.prototype.parseCoverage=function(){var n=this.offset+this.relativeOffset,e=this.parseUShort(),t=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(t)};if(e===2){for(var c=new Array(t),a=0;a<t;a++)c[a]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:c}}throw new Error("0x"+n.toString(16)+": Coverage format must be 1 or 2.")};I.prototype.parseClassDef=function(){var n=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:I.uShort,end:I.uShort,classId:I.uShort})};throw new Error("0x"+n.toString(16)+": ClassDef format must be 1 or 2.")};I.list=function(n,e){return function(){return this.parseList(n,e)}};I.list32=function(n,e){return function(){return this.parseList32(n,e)}};I.recordList=function(n,e){return function(){return this.parseRecordList(n,e)}};I.recordList32=function(n,e){return function(){return this.parseRecordList32(n,e)}};I.pointer=function(n){return function(){return this.parsePointer(n)}};I.pointer32=function(n){return function(){return this.parsePointer32(n)}};I.tag=I.prototype.parseTag;I.byte=I.prototype.parseByte;I.uShort=I.offset16=I.prototype.parseUShort;I.uShortList=I.prototype.parseUShortList;I.uLong=I.offset32=I.prototype.parseULong;I.uLongList=I.prototype.parseULongList;I.struct=I.prototype.parseStruct;I.coverage=I.prototype.parseCoverage;I.classDef=I.prototype.parseClassDef;var t7={reserved:I.uShort,reqFeatureIndex:I.uShort,featureIndexes:I.uShortList};I.prototype.parseScriptList=function(){return this.parsePointer(I.recordList({tag:I.tag,script:I.pointer({defaultLangSys:I.pointer(t7),langSysRecords:I.recordList({tag:I.tag,langSys:I.pointer(t7)})})}))||[]};I.prototype.parseFeatureList=function(){return this.parsePointer(I.recordList({tag:I.tag,feature:I.pointer({featureParams:I.offset16,lookupListIndexes:I.uShortList})}))||[]};I.prototype.parseLookupList=function(n){return this.parsePointer(I.list(I.pointer(function(){var e=this.parseUShort();n1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var t=this.parseUShort(),c=t&16;return{lookupType:e,lookupFlag:t,subtables:this.parseList(I.pointer(n[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};I.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var n=this.parseUShort(),e=this.parseUShort();n1.argument(n===1&&e<1,"GPOS/GSUB feature variations table unknown.");var t=this.parseRecordList32({conditionSetOffset:I.offset32,featureTableSubstitutionOffset:I.offset32});return t})||[]};var W={getByte:e7,getCard8:e7,getUShort:n5,getCard16:n5,getShort:z9,getULong:g4,getFixed:U7,getTag:k9,getOffset:L9,getBytes:S9,bytesToString:A9,Parser:I};function P9(n,e){e.parseUShort(),n.length=e.parseULong(),n.language=e.parseULong();var t;n.groupCount=t=e.parseULong(),n.glyphIndexMap={};for(var c=0;c<t;c+=1)for(var a=e.parseULong(),r=e.parseULong(),s=e.parseULong(),i=a;i<=r;i+=1)n.glyphIndexMap[i]=s,s++}function E9(n,e,t,c,a){n.length=e.parseUShort(),n.language=e.parseUShort();var r;n.segCount=r=e.parseUShort()>>1,e.skip("uShort",3),n.glyphIndexMap={};for(var s=new W.Parser(t,c+a+14),i=new W.Parser(t,c+a+16+r*2),o=new W.Parser(t,c+a+16+r*4),l=new W.Parser(t,c+a+16+r*6),h=c+a+16+r*8,f=0;f<r-1;f+=1)for(var u=void 0,d=s.parseUShort(),m=i.parseUShort(),p=o.parseShort(),v=l.parseUShort(),g=m;g<=d;g+=1)v!==0?(h=l.offset+l.relativeOffset-2,h+=v,h+=(g-m)*2,u=W.getUShort(t,h),u!==0&&(u=u+p&65535)):u=g+p&65535,n.glyphIndexMap[g]=u}function T9(n,e){var t={};t.version=W.getUShort(n,e),n1.argument(t.version===0,"cmap table version should be 0."),t.numTables=W.getUShort(n,e+2);for(var c=-1,a=t.numTables-1;a>=0;a-=1){var r=W.getUShort(n,e+4+a*8),s=W.getUShort(n,e+4+a*8+2);if(r===3&&(s===0||s===1||s===10)||r===0&&(s===0||s===1||s===2||s===3||s===4)){c=W.getULong(n,e+4+a*8+4);break}}if(c===-1)throw new Error("No valid cmap sub-tables found.");var i=new W.Parser(n,e+c);if(t.format=i.parseUShort(),t.format===12)P9(t,i);else if(t.format===4)E9(t,i,n,e,c);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+t.format+").");return t}function I9(n,e,t){n.segments.push({end:e,start:e,delta:-(e-t),offset:0,glyphIndex:t})}function H9(n){n.segments.push({end:65535,start:65535,delta:1,offset:0})}function V9(n){var e=!0,t;for(t=n.length-1;t>0;t-=1){var c=n.get(t);if(c.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var a=[{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||(a=a.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),a=a.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 r=new B.Table("cmap",a);for(r.segments=[],t=0;t<n.length;t+=1){for(var s=n.get(t),i=0;i<s.unicodes.length;i+=1)I9(r,s.unicodes[i],t);r.segments=r.segments.sort(function(M,y){return M.start-y.start})}H9(r);var o=r.segments.length,l=0,h=[],f=[],u=[],d=[],m=[],p=[];for(t=0;t<o;t+=1){var v=r.segments[t];v.end<=65535&&v.start<=65535?(h=h.concat({name:"end_"+t,type:"USHORT",value:v.end}),f=f.concat({name:"start_"+t,type:"USHORT",value:v.start}),u=u.concat({name:"idDelta_"+t,type:"SHORT",value:v.delta}),d=d.concat({name:"idRangeOffset_"+t,type:"USHORT",value:v.offset}),v.glyphId!==void 0&&(m=m.concat({name:"glyph_"+t,type:"USHORT",value:v.glyphId}))):l+=1,!e&&v.glyphIndex!==void 0&&(p=p.concat({name:"cmap12Start_"+t,type:"ULONG",value:v.start}),p=p.concat({name:"cmap12End_"+t,type:"ULONG",value:v.end}),p=p.concat({name:"cmap12Glyph_"+t,type:"ULONG",value:v.glyphIndex}))}if(r.segCountX2=(o-l)*2,r.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,r.entrySelector=Math.log(r.searchRange/2)/Math.log(2),r.rangeShift=r.segCountX2-r.searchRange,r.fields=r.fields.concat(h),r.fields.push({name:"reservedPad",type:"USHORT",value:0}),r.fields=r.fields.concat(f),r.fields=r.fields.concat(u),r.fields=r.fields.concat(d),r.fields=r.fields.concat(m),r.cmap4Length=14+h.length*2+2+f.length*2+u.length*2+d.length*2+m.length*2,!e){var g=16+p.length*4;r.cmap12Offset=20+r.cmap4Length,r.fields=r.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:g},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:p.length/3}]),r.fields=r.fields.concat(p)}return r}var N7={parse:T9,make:V9},Y3=[".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"],O9=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],F9=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],b2=[".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(n){this.font=n}$7.prototype.charToGlyphIndex=function(n){var e=n.codePointAt(0),t=this.font.glyphs;if(t){for(var c=0;c<t.length;c+=1)for(var a=t.get(c),r=0;r<a.unicodes.length;r+=1)if(a.unicodes[r]===e)return c}return null};function _7(n){this.cmap=n}_7.prototype.charToGlyphIndex=function(n){return this.cmap.glyphIndexMap[n.codePointAt(0)]||0};function c5(n,e){this.encoding=n,this.charset=e}c5.prototype.charToGlyphIndex=function(n){var e=n.codePointAt(0),t=this.encoding[e];return this.charset.indexOf(t)};function y4(n){switch(n.version){case 1:this.names=b2.slice();break;case 2:this.names=new Array(n.numberOfGlyphs);for(var e=0;e<n.numberOfGlyphs;e++)n.glyphNameIndex[e]<b2.length?this.names[e]=b2[n.glyphNameIndex[e]]:this.names[e]=n.names[n.glyphNameIndex[e]-b2.length];break;case 2.5:this.names=new Array(n.numberOfGlyphs);for(var t=0;t<n.numberOfGlyphs;t++)this.names[t]=b2[t+n.glyphNameIndex[t]];break;case 3:this.names=[];break;default:this.names=[];break}}y4.prototype.nameToGlyphIndex=function(n){return this.names.indexOf(n)};y4.prototype.glyphIndexToName=function(n){return this.names[n]};function D9(n){for(var e,t=n.tables.cmap.glyphIndexMap,c=Object.keys(t),a=0;a<c.length;a+=1){var r=c[a],s=t[r];e=n.glyphs.get(s),e.addUnicode(parseInt(r))}for(var i=0;i<n.glyphs.length;i+=1)e=n.glyphs.get(i),n.cffEncoding?n.isCIDFont?e.name="gid"+i:e.name=n.cffEncoding.charset[i]:n.glyphNames.names&&(e.name=n.glyphNames.glyphIndexToName(i))}function R9(n){n._IndexToUnicodeMap={};for(var e=n.tables.cmap.glyphIndexMap,t=Object.keys(e),c=0;c<t.length;c+=1){var a=t[c],r=e[a];n._IndexToUnicodeMap[r]===void 0?n._IndexToUnicodeMap[r]={unicodes:[parseInt(a)]}:n._IndexToUnicodeMap[r].unicodes.push(parseInt(a))}}function q9(n,e){e.lowMemory?R9(n):D9(n)}function U9(n,e,t,c,a){n.beginPath(),n.moveTo(e,t),n.lineTo(c,a),n.stroke()}var y2={line:U9};function N9(n,e){var t=e||new $1;return{configurable:!0,get:function(){return typeof t=="function"&&(t=t()),t},set:function(c){t=c}}}function L0(n){this.bindConstructorValues(n)}L0.prototype.bindConstructorValues=function(n){this.index=n.index||0,this.name=n.name||null,this.unicode=n.unicode||void 0,this.unicodes=n.unicodes||n.unicode!==void 0?[n.unicode]:[],"xMin"in n&&(this.xMin=n.xMin),"yMin"in n&&(this.yMin=n.yMin),"xMax"in n&&(this.xMax=n.xMax),"yMax"in n&&(this.yMax=n.yMax),"advanceWidth"in n&&(this.advanceWidth=n.advanceWidth),Object.defineProperty(this,"path",N9(this,n.path))};L0.prototype.addUnicode=function(n){this.unicodes.length===0&&(this.unicode=n),this.unicodes.push(n)};L0.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};L0.prototype.getPath=function(n,e,t,c,a){n=n!==void 0?n:0,e=e!==void 0?e:0,t=t!==void 0?t:72;var r,s;c||(c={});var i=c.xScale,o=c.yScale;if(c.hinting&&a&&a.hinting&&(s=this.path&&a.hinting.exec(this,t)),s)r=a.hinting.getCommands(s),n=Math.round(n),e=Math.round(e),i=o=1;else{r=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*t;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new $1,f=0;f<r.length;f+=1){var u=r[f];u.type==="M"?h.moveTo(n+u.x*i,e+-u.y*o):u.type==="L"?h.lineTo(n+u.x*i,e+-u.y*o):u.type==="Q"?h.quadraticCurveTo(n+u.x1*i,e+-u.y1*o,n+u.x*i,e+-u.y*o):u.type==="C"?h.curveTo(n+u.x1*i,e+-u.y1*o,n+u.x2*i,e+-u.y2*o,n+u.x*i,e+-u.y*o):u.type==="Z"&&h.closePath()}return h};L0.prototype.getContours=function(){if(this.points===void 0)return[];for(var n=[],e=[],t=0;t<this.points.length;t+=1){var c=this.points[t];e.push(c),c.lastPointOfContour&&(n.push(e),e=[])}return n1.argument(e.length===0,"There are still points left in the current contour."),n};L0.prototype.getMetrics=function(){for(var n=this.path.commands,e=[],t=[],c=0;c<n.length;c+=1){var a=n[c];a.type!=="Z"&&(e.push(a.x),t.push(a.y)),(a.type==="Q"||a.type==="C")&&(e.push(a.x1),t.push(a.y1)),a.type==="C"&&(e.push(a.x2),t.push(a.y2))}var r={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,t),leftSideBearing:this.leftSideBearing};return isFinite(r.xMin)||(r.xMin=0),isFinite(r.xMax)||(r.xMax=this.advanceWidth),isFinite(r.yMin)||(r.yMin=0),isFinite(r.yMax)||(r.yMax=0),r.rightSideBearing=this.advanceWidth-r.leftSideBearing-(r.xMax-r.xMin),r};L0.prototype.draw=function(n,e,t,c,a){this.getPath(e,t,c,a).draw(n)};L0.prototype.drawPoints=function(n,e,t,c){function a(f,u,d,m){n.beginPath();for(var p=0;p<f.length;p+=1)n.moveTo(u+f[p].x*m,d+f[p].y*m),n.arc(u+f[p].x*m,d+f[p].y*m,2,0,Math.PI*2,!1);n.closePath(),n.fill()}e=e!==void 0?e:0,t=t!==void 0?t:0,c=c!==void 0?c:24;for(var r=1/this.path.unitsPerEm*c,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}n.fillStyle="blue",a(s,e,t,r),n.fillStyle="red",a(i,e,t,r)};L0.prototype.drawMetrics=function(n,e,t,c){var a;e=e!==void 0?e:0,t=t!==void 0?t:0,c=c!==void 0?c:24,a=1/this.path.unitsPerEm*c,n.lineWidth=1,n.strokeStyle="black",y2.line(n,e,-1e4,e,1e4),y2.line(n,-1e4,t,1e4,t);var r=this.xMin||0,s=this.yMin||0,i=this.xMax||0,o=this.yMax||0,l=this.advanceWidth||0;n.strokeStyle="blue",y2.line(n,e+r*a,-1e4,e+r*a,1e4),y2.line(n,e+i*a,-1e4,e+i*a,1e4),y2.line(n,-1e4,t+-s*a,1e4,t+-s*a),y2.line(n,-1e4,t+-o*a,1e4,t+-o*a),n.strokeStyle="green",y2.line(n,e+l*a,-1e4,e+l*a,1e4)};function X3(n,e,t){Object.defineProperty(n,e,{get:function(){return n.path,n[t]},set:function(c){n[t]=c},enumerable:!0,configurable:!0})}function b4(n,e){if(this.font=n,this.glyphs={},Array.isArray(e))for(var t=0;t<e.length;t++){var c=e[t];c.path.unitsPerEm=n.unitsPerEm,this.glyphs[t]=c}this.length=e&&e.length||0}b4.prototype.get=function(n){if(this.glyphs[n]===void 0){this.font._push(n),typeof this.glyphs[n]=="function"&&(this.glyphs[n]=this.glyphs[n]());var e=this.glyphs[n],t=this.font._IndexToUnicodeMap[n];if(t)for(var c=0;c<t.unicodes.length;c++)e.addUnicode(t.unicodes[c]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+n:e.name=this.font.cffEncoding.charset[n]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(n)),this.glyphs[n].advanceWidth=this.font._hmtxTableData[n].advanceWidth,this.glyphs[n].leftSideBearing=this.font._hmtxTableData[n].leftSideBearing}else typeof this.glyphs[n]=="function"&&(this.glyphs[n]=this.glyphs[n]());return this.glyphs[n]};b4.prototype.push=function(n,e){this.glyphs[n]=e,this.length++};function $9(n,e){return new L0({index:e,font:n})}function _9(n,e,t,c,a,r){return function(){var s=new L0({index:e,font:n});return s.path=function(){t(s,c,a);var i=r(n.glyphs,s);return i.unitsPerEm=n.unitsPerEm,i},X3(s,"xMin","_xMin"),X3(s,"xMax","_xMax"),X3(s,"yMin","_yMin"),X3(s,"yMax","_yMax"),s}}function B9(n,e,t,c){return function(){var a=new L0({index:e,font:n});return a.path=function(){var r=t(n,a,c);return r.unitsPerEm=n.unitsPerEm,r},a}}var B0={GlyphSet:b4,glyphLoader:$9,ttfGlyphLoader:_9,cffGlyphLoader:B9};function B7(n,e){if(n===e)return!0;if(Array.isArray(n)&&Array.isArray(e)){if(n.length!==e.length)return!1;for(var t=0;t<n.length;t+=1)if(!B7(n[t],e[t]))return!1;return!0}else return!1}function l4(n){var e;return n.length<1240?e=107:n.length<33900?e=1131:e=32768,e}function a2(n,e,t){var c=[],a=[],r=W.getCard16(n,e),s,i;if(r!==0){var o=W.getByte(n,e+2);s=e+(r+1)*o+2;for(var l=e+3,h=0;h<r+1;h+=1)c.push(W.getOffset(n,l,o)),l+=o;i=s+c[r]}else i=e+2;for(var f=0;f<c.length-1;f+=1){var u=W.getBytes(n,s+c[f],s+c[f+1]);t&&(u=t(u)),a.push(u)}return{objects:a,startOffset:e,endOffset:i}}function G9(n,e){var t=[],c=W.getCard16(n,e),a,r;if(c!==0){var s=W.getByte(n,e+2);a=e+(c+1)*s+2;for(var i=e+3,o=0;o<c+1;o+=1)t.push(W.getOffset(n,i,s)),i+=s;r=a+t[c]}else r=e+2;return{offsets:t,startOffset:e,endOffset:r}}function j9(n,e,t,c,a){var r=W.getCard16(t,c),s=0;if(r!==0){var i=W.getByte(t,c+2);s=c+(r+1)*i+2}var o=W.getBytes(t,s+e[n],s+e[n+1]);return a&&(o=a(o)),o}function W9(n){for(var e="",t=15,c=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var a=n.parseByte(),r=a>>4,s=a&15;if(r===t||(e+=c[r],s===t))break;e+=c[s]}return parseFloat(e)}function X9(n,e){var t,c,a,r;if(e===28)return t=n.parseByte(),c=n.parseByte(),t<<8|c;if(e===29)return t=n.parseByte(),c=n.parseByte(),a=n.parseByte(),r=n.parseByte(),t<<24|c<<16|a<<8|r;if(e===30)return W9(n);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return t=n.parseByte(),(e-247)*256+t+108;if(e>=251&&e<=254)return t=n.parseByte(),-(e-251)*256-t-108;throw new Error("Invalid b0 "+e)}function Z9(n){for(var e={},t=0;t<n.length;t+=1){var c=n[t][0],a=n[t][1],r=void 0;if(a.length===1?r=a[0]:r=a,e.hasOwnProperty(c)&&!isNaN(e[c]))throw new Error("Object "+e+" already has key "+c);e[c]=r}return e}function G7(n,e,t){e=e!==void 0?e:0;var c=new W.Parser(n,e),a=[],r=[];for(t=t!==void 0?t:n.length;c.relativeOffset<t;){var s=c.parseByte();s<=21?(s===12&&(s=1200+c.parseByte()),a.push([s,r]),r=[]):r.push(X9(c,s))}return Z9(a)}function o3(n,e){return e<=390?e=Y3[e]:e=n[e-391],e}function j7(n,e,t){for(var c={},a,r=0;r<e.length;r+=1){var s=e[r];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)a=n[s.op]!==void 0?n[s.op][o]:void 0,a===void 0&&(a=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(a=o3(t,a)),i[o]=a;c[s.name]=i}else a=n[s.op],a===void 0&&(a=s.value!==void 0?s.value:null),s.type==="SID"&&(a=o3(t,a)),c[s.name]=a}return c}function Y9(n,e){var t={};return t.formatMajor=W.getCard8(n,e),t.formatMinor=W.getCard8(n,e+1),t.size=W.getCard8(n,e+2),t.offsetSize=W.getCard8(n,e+3),t.startOffset=e,t.endOffset=e+4,t}var W7=[{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"}],X7=[{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 K9(n,e){var t=G7(n,0,n.byteLength);return j7(t,W7,e)}function Z7(n,e,t,c){var a=G7(n,e,t);return j7(a,X7,c)}function n7(n,e,t,c){for(var a=[],r=0;r<t.length;r+=1){var s=new DataView(new Uint8Array(t[r]).buffer),i=K9(s,c);i._subrs=[],i._subrsBias=0,i._defaultWidthX=0,i._nominalWidthX=0;var o=i.private[0],l=i.private[1];if(o!==0&&l!==0){var h=Z7(n,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var f=l+h.subrs,u=a2(n,f+e);i._subrs=u.objects,i._subrsBias=l4(i._subrs)}i._privateDict=h}a.push(i)}return a}function J9(n,e,t,c){var a,r,s=new W.Parser(n,e);t-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<t;l+=1)a=s.parseSID(),i.push(o3(c,a));else if(o===1)for(;i.length<=t;){a=s.parseSID(),r=s.parseCard8();for(var h=0;h<=r;h+=1)i.push(o3(c,a)),a+=1}else if(o===2)for(;i.length<=t;){a=s.parseSID(),r=s.parseCard16();for(var f=0;f<=r;f+=1)i.push(o3(c,a)),a+=1}else throw new Error("Unknown charset format "+o);return i}function Q9(n,e,t){var c,a={},r=new W.Parser(n,e),s=r.parseCard8();if(s===0)for(var i=r.parseCard8(),o=0;o<i;o+=1)c=r.parseCard8(),a[c]=o;else if(s===1){var l=r.parseCard8();c=1;for(var h=0;h<l;h+=1)for(var f=r.parseCard8(),u=r.parseCard8(),d=f;d<=f+u;d+=1)a[d]=c,c+=1}else throw new Error("Unknown encoding format "+s);return new c5(a,t)}function c7(n,e,t){var c,a,r,s,i=new $1,o=[],l=0,h=!1,f=!1,u=0,d=0,m,p,v,g;if(n.isCIDFont){var M=n.tables.cff.topDict._fdSelect[e.index],y=n.tables.cff.topDict._fdArray[M];m=y._subrs,p=y._subrsBias,v=y._defaultWidthX,g=y._nominalWidthX}else m=n.tables.cff.topDict._subrs,p=n.tables.cff.topDict._subrsBias,v=n.tables.cff.topDict._defaultWidthX,g=n.tables.cff.topDict._nominalWidthX;var b=v;function w(L,S){f&&i.closePath(),i.moveTo(L,S),f=!0}function x(){var L;L=o.length%2!==0,L&&!h&&(b=o.shift()+g),l+=o.length>>1,o.length=0,h=!0}function z(L){for(var S,k,E,V,T,H,D,O,R,N,q,Y,_=0;_<L.length;){var c1=L[_];switch(_+=1,c1){case 1:x();break;case 3:x();break;case 4:o.length>1&&!h&&(b=o.shift()+g,h=!0),d+=o.pop(),w(u,d);break;case 5:for(;o.length>0;)u+=o.shift(),d+=o.shift(),i.lineTo(u,d);break;case 6:for(;o.length>0&&(u+=o.shift(),i.lineTo(u,d),o.length!==0);)d+=o.shift(),i.lineTo(u,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(u,d),o.length!==0);)u+=o.shift(),i.lineTo(u,d);break;case 8:for(;o.length>0;)c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+o.shift(),i.curveTo(c,a,r,s,u,d);break;case 10:T=o.pop()+p,H=m[T],H&&z(H);break;case 11:return;case 12:switch(c1=L[_],_+=1,c1){case 35:c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),D=r+o.shift(),O=s+o.shift(),R=D+o.shift(),N=O+o.shift(),q=R+o.shift(),Y=N+o.shift(),u=q+o.shift(),d=Y+o.shift(),o.shift(),i.curveTo(c,a,r,s,D,O),i.curveTo(R,N,q,Y,u,d);break;case 34:c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),D=r+o.shift(),O=s,R=D+o.shift(),N=s,q=R+o.shift(),Y=d,u=q+o.shift(),i.curveTo(c,a,r,s,D,O),i.curveTo(R,N,q,Y,u,d);break;case 36:c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),D=r+o.shift(),O=s,R=D+o.shift(),N=s,q=R+o.shift(),Y=N+o.shift(),u=q+o.shift(),i.curveTo(c,a,r,s,D,O),i.curveTo(R,N,q,Y,u,d);break;case 37:c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),D=r+o.shift(),O=s+o.shift(),R=D+o.shift(),N=O+o.shift(),q=R+o.shift(),Y=N+o.shift(),Math.abs(q-u)>Math.abs(Y-d)?u=q+o.shift():d=Y+o.shift(),i.curveTo(c,a,r,s,D,O),i.curveTo(R,N,q,Y,u,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+c1),o.length=0}break;case 14:o.length>0&&!h&&(b=o.shift()+g,h=!0),f&&(i.closePath(),f=!1);break;case 18:x();break;case 19:case 20:x(),_+=l+7>>3;break;case 21:o.length>2&&!h&&(b=o.shift()+g,h=!0),d+=o.pop(),u+=o.pop(),w(u,d);break;case 22:o.length>1&&!h&&(b=o.shift()+g,h=!0),u+=o.pop(),w(u,d);break;case 23:x();break;case 24:for(;o.length>2;)c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+o.shift(),i.curveTo(c,a,r,s,u,d);u+=o.shift(),d+=o.shift(),i.lineTo(u,d);break;case 25:for(;o.length>6;)u+=o.shift(),d+=o.shift(),i.lineTo(u,d);c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+o.shift(),i.curveTo(c,a,r,s,u,d);break;case 26:for(o.length%2&&(u+=o.shift());o.length>0;)c=u,a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r,d=s+o.shift(),i.curveTo(c,a,r,s,u,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s,i.curveTo(c,a,r,s,u,d);break;case 28:S=L[_],k=L[_+1],o.push((S<<24|k<<16)>>16),_+=2;break;case 29:T=o.pop()+n.gsubrsBias,H=n.gsubrs[T],H&&z(H);break;case 30:for(;o.length>0&&(c=u,a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d),o.length!==0);)c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),d=s+o.shift(),u=r+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d);break;case 31:for(;o.length>0&&(c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),d=s+o.shift(),u=r+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d),o.length!==0);)c=u,a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d);break;default:c1<32?console.log("Glyph "+e.index+": unknown operator "+c1):c1<247?o.push(c1-139):c1<251?(S=L[_],_+=1,o.push((c1-247)*256+S+108)):c1<255?(S=L[_],_+=1,o.push(-(c1-251)*256-S-108)):(S=L[_],k=L[_+1],E=L[_+2],V=L[_+3],_+=4,o.push((S<<24|k<<16|E<<8|V)/65536))}}}return z(t),e.advanceWidth=b,i}function et(n,e,t,c){var a=[],r,s=new W.Parser(n,e),i=s.parseCard8();if(i===0)for(var o=0;o<t;o++){if(r=s.parseCard8(),r>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+r+" (FD count "+c+")");a.push(r)}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 f,u=0;u<l;u++){if(r=s.parseCard8(),f=s.parseCard16(),r>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+r+" (FD count "+c+")");if(f>t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+f);for(;h<f;h++)a.push(r);h=f}if(f!==t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+f)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);return a}function tt(n,e,t,c){t.tables.cff={};var a=Y9(n,e),r=a2(n,a.endOffset,W.bytesToString),s=a2(n,r.endOffset),i=a2(n,s.endOffset,W.bytesToString),o=a2(n,i.endOffset);t.gsubrs=o.objects,t.gsubrsBias=l4(t.gsubrs);var l=n7(n,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(t.tables.cff.topDict=h,h._privateDict&&(t.defaultWidthX=h._privateDict.defaultWidthX,t.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(t.isCIDFont=!0),t.isCIDFont){var f=h.fdArray,u=h.fdSelect;if(f===0||u===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");f+=e;var d=a2(n,f),m=n7(n,e,d.objects,i.objects);h._fdArray=m,u+=e,h._fdSelect=et(n,u,t.numGlyphs,m.length)}var p=e+h.private[1],v=Z7(n,p,h.private[0],i.objects);if(t.defaultWidthX=v.defaultWidthX,t.nominalWidthX=v.nominalWidthX,v.subrs!==0){var g=p+v.subrs,M=a2(n,g);t.subrs=M.objects,t.subrsBias=l4(t.subrs)}else t.subrs=[],t.subrsBias=0;var y;c.lowMemory?(y=G9(n,e+h.charStrings),t.nGlyphs=y.offsets.length):(y=a2(n,e+h.charStrings),t.nGlyphs=y.objects.length);var b=J9(n,e+h.charset,t.nGlyphs,i.objects);if(h.encoding===0?t.cffEncoding=new c5(O9,b):h.encoding===1?t.cffEncoding=new c5(F9,b):t.cffEncoding=Q9(n,e+h.encoding,b),t.encoding=t.encoding||t.cffEncoding,t.glyphs=new B0.GlyphSet(t),c.lowMemory)t._push=function(z){var L=j9(z,y.offsets,n,e+h.charStrings);t.glyphs.push(z,B0.cffGlyphLoader(t,z,c7,L))};else for(var w=0;w<t.nGlyphs;w+=1){var x=y.objects[w];t.glyphs.push(w,B0.cffGlyphLoader(t,w,c7,x))}}function Y7(n,e){var t,c=Y3.indexOf(n);return c>=0&&(t=c),c=e.indexOf(n),c>=0?t=c+Y3.length:(t=Y3.length+e.length,e.push(n)),t}function nt(){return new B.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 ct(n){var e=new B.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var t=0;t<n.length;t+=1)e.names.push({name:"name_"+t,type:"NAME",value:n[t]});return e}function K7(n,e,t){for(var c={},a=0;a<n.length;a+=1){var r=n[a],s=e[r.name];s!==void 0&&!B7(s,r.value)&&(r.type==="SID"&&(s=Y7(s,t)),c[r.op]={name:r.name,type:r.type,value:s})}return c}function a7(n,e){var t=new B.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=K7(W7,n,e),t}function r7(n){var e=new B.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:n}],e}function at(n){var e=new B.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var t=0;t<n.length;t+=1)e.strings.push({name:"string_"+t,type:"STRING",value:n[t]});return e}function rt(){return new B.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function st(n,e){for(var t=new B.Record("Charsets",[{name:"format",type:"Card8",value:0}]),c=0;c<n.length;c+=1){var a=n[c],r=Y7(a,e);t.fields.push({name:"glyph_"+c,type:"SID",value:r})}return t}function it(n){var e=[],t=n.path;e.push({name:"width",type:"NUMBER",value:n.advanceWidth});for(var c=0,a=0,r=0;r<t.commands.length;r+=1){var s=void 0,i=void 0,o=t.commands[r];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*c+h*o.x1),y1:Math.round(l*a+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-c),i=Math.round(o.y-a),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),c=Math.round(o.x),a=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-c),i=Math.round(o.y-a),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),c=Math.round(o.x),a=Math.round(o.y);else if(o.type==="C"){var f=Math.round(o.x1-c),u=Math.round(o.y1-a),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:f}),e.push({name:"dy1",type:"NUMBER",value:u}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:m}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),c=Math.round(o.x),a=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function ot(n){for(var e=new B.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),t=0;t<n.length;t+=1){var c=n.get(t),a=it(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:a})}return e}function lt(n,e){var t=new B.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=K7(X7,n,e),t}function ht(n,e){for(var t=new B.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),c=1/e.unitsPerEm,a={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[c,0,0,c,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},r={},s=[],i,o=1;o<n.length;o+=1)i=n.get(o),s.push(i.name);var l=[];t.header=nt(),t.nameIndex=ct([e.postScriptName]);var h=a7(a,l);t.topDictIndex=r7(h),t.globalSubrIndex=rt(),t.charsets=st(s,l),t.charStringsIndex=ot(n),t.privateDict=lt(r,l),t.stringIndex=at(l);var f=t.header.sizeOf()+t.nameIndex.sizeOf()+t.topDictIndex.sizeOf()+t.stringIndex.sizeOf()+t.globalSubrIndex.sizeOf();return a.charset=f,a.encoding=0,a.charStrings=a.charset+t.charsets.sizeOf(),a.private[1]=a.charStrings+t.charStringsIndex.sizeOf(),h=a7(a,l),t.topDictIndex=r7(h),t}var J7={parse:tt,make:ht};function ut(n,e){var t={},c=new W.Parser(n,e);return t.version=c.parseVersion(),t.fontRevision=Math.round(c.parseFixed()*1e3)/1e3,t.checkSumAdjustment=c.parseULong(),t.magicNumber=c.parseULong(),n1.argument(t.magicNumber===1594834165,"Font header has wrong magic number."),t.flags=c.parseUShort(),t.unitsPerEm=c.parseUShort(),t.created=c.parseLongDateTime(),t.modified=c.parseLongDateTime(),t.xMin=c.parseShort(),t.yMin=c.parseShort(),t.xMax=c.parseShort(),t.yMax=c.parseShort(),t.macStyle=c.parseUShort(),t.lowestRecPPEM=c.parseUShort(),t.fontDirectionHint=c.parseShort(),t.indexToLocFormat=c.parseShort(),t.glyphDataFormat=c.parseShort(),t}function ft(n){var e=Math.round(new Date().getTime()/1e3)+2082844800,t=e;return n.createdTimestamp&&(t=n.createdTimestamp+2082844800),new B.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:t},{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}],n)}var Q7={parse:ut,make:ft};function dt(n,e){var t={},c=new W.Parser(n,e);return t.version=c.parseVersion(),t.ascender=c.parseShort(),t.descender=c.parseShort(),t.lineGap=c.parseShort(),t.advanceWidthMax=c.parseUShort(),t.minLeftSideBearing=c.parseShort(),t.minRightSideBearing=c.parseShort(),t.xMaxExtent=c.parseShort(),t.caretSlopeRise=c.parseShort(),t.caretSlopeRun=c.parseShort(),t.caretOffset=c.parseShort(),c.relativeOffset+=8,t.metricDataFormat=c.parseShort(),t.numberOfHMetrics=c.parseUShort(),t}function pt(n){return new B.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}],n)}var e8={parse:dt,make:pt};function mt(n,e,t,c,a){for(var r,s,i=new W.Parser(n,e),o=0;o<c;o+=1){o<t&&(r=i.parseUShort(),s=i.parseShort());var l=a.get(o);l.advanceWidth=r,l.leftSideBearing=s}}function vt(n,e,t,c,a){n._hmtxTableData={};for(var r,s,i=new W.Parser(e,t),o=0;o<a;o+=1)o<c&&(r=i.parseUShort(),s=i.parseShort()),n._hmtxTableData[o]={advanceWidth:r,leftSideBearing:s}}function gt(n,e,t,c,a,r,s){s.lowMemory?vt(n,e,t,c,a):mt(e,t,c,a,r)}function yt(n){for(var e=new B.Table("hmtx",[]),t=0;t<n.length;t+=1){var c=n.get(t),a=c.advanceWidth||0,r=c.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+t,type:"USHORT",value:a}),e.fields.push({name:"leftSideBearing_"+t,type:"SHORT",value:r})}return e}var t8={parse:gt,make:yt};function bt(n){for(var e=new B.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:n.length}]),t="",c=12+n.length*4,a=0;a<n.length;++a){var r=t.indexOf(n[a]);r<0&&(r=t.length,t+=n[a]),e.fields.push({name:"offset "+a,type:"USHORT",value:c+r}),e.fields.push({name:"length "+a,type:"USHORT",value:n[a].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),e}function Mt(n,e){var t=new W.Parser(n,e),c=t.parseULong();n1.argument(c===1,"Unsupported ltag table version."),t.skip("uLong",1);for(var a=t.parseULong(),r=[],s=0;s<a;s++){for(var i="",o=e+t.parseUShort(),l=t.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(n.getInt8(h));r.push(i)}return r}var n8={make:bt,parse:Mt};function xt(n,e){var t={},c=new W.Parser(n,e);return t.version=c.parseVersion(),t.numGlyphs=c.parseUShort(),t.version===1&&(t.maxPoints=c.parseUShort(),t.maxContours=c.parseUShort(),t.maxCompositePoints=c.parseUShort(),t.maxCompositeContours=c.parseUShort(),t.maxZones=c.parseUShort(),t.maxTwilightPoints=c.parseUShort(),t.maxStorage=c.parseUShort(),t.maxFunctionDefs=c.parseUShort(),t.maxInstructionDefs=c.parseUShort(),t.maxStackElements=c.parseUShort(),t.maxSizeOfInstructions=c.parseUShort(),t.maxComponentElements=c.parseUShort(),t.maxComponentDepth=c.parseUShort()),t}function wt(n){return new B.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:n}])}var c8={parse:xt,make:wt},a8=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],r8={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"},zt={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},s8={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 kt(n,e,t){switch(n){case 0:if(e===65535)return"und";if(t)return t[e];break;case 1:return r8[e];case 3:return s8[e]}}var h4="utf-16",Lt={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"},St={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 i8(n,e,t){switch(n){case 0:return h4;case 1:return St[t]||Lt[e];case 3:if(e===1||e===10)return h4;break}}function At(n,e,t){for(var c={},a=new W.Parser(n,e),r=a.parseUShort(),s=a.parseUShort(),i=a.offset+a.parseUShort(),o=0;o<s;o++){var l=a.parseUShort(),h=a.parseUShort(),f=a.parseUShort(),u=a.parseUShort(),d=a8[u]||u,m=a.parseUShort(),p=a.parseUShort(),v=kt(l,f,t),g=i8(l,h,f);if(g!==void 0&&v!==void 0){var M=void 0;if(g===h4?M=F2.UTF16(n,i+p,m):M=F2.MACSTRING(n,i+p,m,g),M){var y=c[d];y===void 0&&(y=c[d]={}),y[v]=M}}}var b=0;return r===1&&(b=a.parseUShort()),c}function K5(n){var e={};for(var t in n)e[n[t]]=parseInt(t);return e}function s7(n,e,t,c,a,r){return new B.Record("NameRecord",[{name:"platformID",type:"USHORT",value:n},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:t},{name:"nameID",type:"USHORT",value:c},{name:"length",type:"USHORT",value:a},{name:"offset",type:"USHORT",value:r}])}function Ct(n,e){var t=n.length,c=e.length-t+1;e:for(var a=0;a<c;a++)for(;a<c;a++){for(var r=0;r<t;r++)if(e[a+r]!==n[r])continue e;return a}return-1}function i7(n,e){var t=Ct(n,e);if(t<0){t=e.length;for(var c=0,a=n.length;c<a;++c)e.push(n[c])}return t}function Pt(n,e){var t,c=[],a={},r=K5(a8);for(var s in n){var i=r[s];if(i===void 0&&(i=s),t=parseInt(i),isNaN(t))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');a[t]=n[s],c.push(t)}for(var o=K5(r8),l=K5(s8),h=[],f=[],u=0;u<c.length;u++){t=c[u];var d=a[t];for(var m in d){var p=d[m],v=1,g=o[m],M=zt[g],y=i8(v,M,g),b=U.MACSTRING(p,y);b===void 0&&(v=0,g=e.indexOf(m),g<0&&(g=e.length,e.push(m)),M=4,b=U.UTF16(p));var w=i7(b,f);h.push(s7(v,M,g,t,b.length,w));var x=l[m];if(x!==void 0){var z=U.UTF16(p),L=i7(z,f);h.push(s7(3,1,x,t,z.length,L))}}}h.sort(function(E,V){return E.platformID-V.platformID||E.encodingID-V.encodingID||E.languageID-V.languageID||E.nameID-V.nameID});for(var S=new B.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),k=0;k<h.length;k++)S.fields.push({name:"record_"+k,type:"RECORD",value:h[k]});return S.fields.push({name:"strings",type:"LITERAL",value:f}),S}var o8={parse:At,make:Pt},u4=[{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 Et(n){for(var e=0;e<u4.length;e+=1){var t=u4[e];if(n>=t.begin&&n<t.end)return e}return-1}function Tt(n,e){var t={},c=new W.Parser(n,e);t.version=c.parseUShort(),t.xAvgCharWidth=c.parseShort(),t.usWeightClass=c.parseUShort(),t.usWidthClass=c.parseUShort(),t.fsType=c.parseUShort(),t.ySubscriptXSize=c.parseShort(),t.ySubscriptYSize=c.parseShort(),t.ySubscriptXOffset=c.parseShort(),t.ySubscriptYOffset=c.parseShort(),t.ySuperscriptXSize=c.parseShort(),t.ySuperscriptYSize=c.parseShort(),t.ySuperscriptXOffset=c.parseShort(),t.ySuperscriptYOffset=c.parseShort(),t.yStrikeoutSize=c.parseShort(),t.yStrikeoutPosition=c.parseShort(),t.sFamilyClass=c.parseShort(),t.panose=[];for(var a=0;a<10;a++)t.panose[a]=c.parseByte();return t.ulUnicodeRange1=c.parseULong(),t.ulUnicodeRange2=c.parseULong(),t.ulUnicodeRange3=c.parseULong(),t.ulUnicodeRange4=c.parseULong(),t.achVendID=String.fromCharCode(c.parseByte(),c.parseByte(),c.parseByte(),c.parseByte()),t.fsSelection=c.parseUShort(),t.usFirstCharIndex=c.parseUShort(),t.usLastCharIndex=c.parseUShort(),t.sTypoAscender=c.parseShort(),t.sTypoDescender=c.parseShort(),t.sTypoLineGap=c.parseShort(),t.usWinAscent=c.parseUShort(),t.usWinDescent=c.parseUShort(),t.version>=1&&(t.ulCodePageRange1=c.parseULong(),t.ulCodePageRange2=c.parseULong()),t.version>=2&&(t.sxHeight=c.parseShort(),t.sCapHeight=c.parseShort(),t.usDefaultChar=c.parseUShort(),t.usBreakChar=c.parseUShort(),t.usMaxContent=c.parseUShort()),t}function It(n){return new B.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}],n)}var f4={parse:Tt,make:It,unicodeRanges:u4,getUnicodeRange:Et};function Ht(n,e){var t={},c=new W.Parser(n,e);switch(t.version=c.parseVersion(),t.italicAngle=c.parseFixed(),t.underlinePosition=c.parseShort(),t.underlineThickness=c.parseShort(),t.isFixedPitch=c.parseULong(),t.minMemType42=c.parseULong(),t.maxMemType42=c.parseULong(),t.minMemType1=c.parseULong(),t.maxMemType1=c.parseULong(),t.version){case 1:t.names=b2.slice();break;case 2:t.numberOfGlyphs=c.parseUShort(),t.glyphNameIndex=new Array(t.numberOfGlyphs);for(var a=0;a<t.numberOfGlyphs;a++)t.glyphNameIndex[a]=c.parseUShort();t.names=[];for(var r=0;r<t.numberOfGlyphs;r++)if(t.glyphNameIndex[r]>=b2.length){var s=c.parseChar();t.names.push(c.parseString(s))}break;case 2.5:t.numberOfGlyphs=c.parseUShort(),t.offset=new Array(t.numberOfGlyphs);for(var i=0;i<t.numberOfGlyphs;i++)t.offset[i]=c.parseChar();break}return t}function Vt(){return new B.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 l8={parse:Ht,make:Vt},P0=new Array(9);P0[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(I.coverage),deltaGlyphId:this.parseUShort()};if(t===2)return{substFormat:2,coverage:this.parsePointer(I.coverage),substitute:this.parseOffset16List()};n1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};P0[2]=function(){var e=this.parseUShort();return n1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(I.coverage),sequences:this.parseListOfLists()}};P0[3]=function(){var e=this.parseUShort();return n1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(I.coverage),alternateSets:this.parseListOfLists()}};P0[4]=function(){var e=this.parseUShort();return n1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(I.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var O2={sequenceIndex:I.uShort,lookupListIndex:I.uShort};P0[5]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:t,coverage:this.parsePointer(I.coverage),ruleSets:this.parseListOfLists(function(){var r=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(r-1),lookupRecords:this.parseRecordList(s,O2)}})};if(t===2)return{substFormat:t,coverage:this.parsePointer(I.coverage),classDef:this.parsePointer(I.classDef),classSets:this.parseListOfLists(function(){var r=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(r-1),lookupRecords:this.parseRecordList(s,O2)}})};if(t===3){var c=this.parseUShort(),a=this.parseUShort();return{substFormat:t,coverages:this.parseList(c,I.pointer(I.coverage)),lookupRecords:this.parseRecordList(a,O2)}}n1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};P0[6]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(I.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(O2)}})};if(t===2)return{substFormat:2,coverage:this.parsePointer(I.coverage),backtrackClassDef:this.parsePointer(I.classDef),inputClassDef:this.parsePointer(I.classDef),lookaheadClassDef:this.parsePointer(I.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(O2)}})};if(t===3)return{substFormat:3,backtrackCoverage:this.parseList(I.pointer(I.coverage)),inputCoverage:this.parseList(I.pointer(I.coverage)),lookaheadCoverage:this.parseList(I.pointer(I.coverage)),lookupRecords:this.parseRecordList(O2)};n1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};P0[7]=function(){var e=this.parseUShort();n1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var t=this.parseUShort(),c=new I(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:t,extension:P0[t].call(c)}};P0[8]=function(){var e=this.parseUShort();return n1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(I.coverage),backtrackCoverage:this.parseList(I.pointer(I.coverage)),lookaheadCoverage:this.parseList(I.pointer(I.coverage)),substitutes:this.parseUShortList()}};function Ot(n,e){e=e||0;var t=new I(n,e),c=t.parseVersion(1);return n1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(P0)}:{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(P0),variations:t.parseFeatureVariationsList()}}var D2=new Array(9);D2[1]=function(e){return e.substFormat===1?new B.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new B.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new B.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new B.Coverage(e.coverage)}].concat(B.ushortList("substitute",e.substitute)))};D2[2]=function(e){return n1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new B.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new B.Coverage(e.coverage)}].concat(B.tableList("seqSet",e.sequences,function(t){return new B.Table("sequenceSetTable",B.ushortList("sequence",t))})))};D2[3]=function(e){return n1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new B.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new B.Coverage(e.coverage)}].concat(B.tableList("altSet",e.alternateSets,function(t){return new B.Table("alternateSetTable",B.ushortList("alternate",t))})))};D2[4]=function(e){return n1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new B.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new B.Coverage(e.coverage)}].concat(B.tableList("ligSet",e.ligatureSets,function(t){return new B.Table("ligatureSetTable",B.tableList("ligature",t,function(c){return new B.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:c.ligGlyph}].concat(B.ushortList("component",c.components,c.components.length+1)))}))})))};D2[6]=function(e){if(e.substFormat===1){var t=new B.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new B.Coverage(e.coverage)}].concat(B.tableList("chainRuleSet",e.chainRuleSets,function(r){return new B.Table("chainRuleSetTable",B.tableList("chainRule",r,function(s){var i=B.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(B.ushortList("inputGlyph",s.input,s.input.length+1)).concat(B.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(B.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 B.Table("chainRuleTable",i)}))})));return t}else if(e.substFormat===2)n1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var c=[{name:"substFormat",type:"USHORT",value:e.substFormat}];c.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(r,s){c.push({name:"backtrackCoverage"+s,type:"TABLE",value:new B.Coverage(r)})}),c.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(r,s){c.push({name:"inputCoverage"+s,type:"TABLE",value:new B.Coverage(r)})}),c.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(r,s){c.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new B.Coverage(r)})}),c.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(r,s){c=c.concat({name:"sequenceIndex"+s,type:"USHORT",value:r.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:r.lookupListIndex})});var a=new B.Table("chainContextTable",c);return a}n1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function Ft(n){return new B.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new B.ScriptList(n.scripts)},{name:"features",type:"TABLE",value:new B.FeatureList(n.features)},{name:"lookups",type:"TABLE",value:new B.LookupList(n.lookups,D2)}])}var h8={parse:Ot,make:Ft};function Dt(n,e){var t=new W.Parser(n,e),c=t.parseULong();n1.argument(c===1,"Unsupported META table version."),t.parseULong(),t.parseULong();for(var a=t.parseULong(),r={},s=0;s<a;s++){var i=t.parseTag(),o=t.parseULong(),l=t.parseULong(),h=F2.UTF8(n,e+o,l);r[i]=h}return r}function Rt(n){var e=Object.keys(n).length,t="",c=16+e*12,a=new B.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:c},{name:"numTags",type:"ULONG",value:e}]);for(var r in n){var s=t.length;t+=n[r],a.fields.push({name:"tag "+r,type:"TAG",value:r}),a.fields.push({name:"offset "+r,type:"ULONG",value:c+s}),a.fields.push({name:"length "+r,type:"ULONG",value:n[r].length})}return a.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),a}var u8={parse:Dt,make:Rt};function o7(n){return Math.log(n)/Math.log(2)|0}function M4(n){for(;n.length%4!==0;)n.push(0);for(var e=0,t=0;t<n.length;t+=4)e+=(n[t]<<24)+(n[t+1]<<16)+(n[t+2]<<8)+n[t+3];return e%=Math.pow(2,32),e}function l7(n,e,t,c){return new B.Record("Table Record",[{name:"tag",type:"TAG",value:n!==void 0?n:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:t!==void 0?t:0},{name:"length",type:"ULONG",value:c!==void 0?c:0}])}function f8(n){var e=new B.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=n,e.numTables=n.length;var t=Math.pow(2,o7(e.numTables));e.searchRange=16*t,e.entrySelector=o7(t),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],a=[],r=e.sizeOf()+l7().sizeOf()*e.numTables;r%4!==0;)r+=1,a.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<n.length;s+=1){var i=n[s];n1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=l7(i.tableName,M4(i.encode()),r,o);for(c.push({name:l.tag+" Table Record",type:"RECORD",value:l}),a.push({name:i.tableName+" table",type:"RECORD",value:i}),r+=o,n1.argument(!isNaN(r),"Something went wrong calculating the offset.");r%4!==0;)r+=1,a.push({name:"padding",type:"BYTE",value:0})}return c.sort(function(h,f){return h.value.tag>f.value.tag?1:-1}),e.fields=e.fields.concat(c),e.fields=e.fields.concat(a),e}function h7(n,e,t){for(var c=0;c<e.length;c+=1){var a=n.charToGlyphIndex(e[c]);if(a>0){var r=n.glyphs.get(a);return r.getMetrics()}}return t}function qt(n){for(var e=0,t=0;t<n.length;t+=1)e+=n[t];return e/n.length}function Ut(n){for(var e=[],t=[],c=[],a=[],r=[],s=[],i=[],o,l=0,h=0,f=0,u=0,d=0,m=0;m<n.glyphs.length;m+=1){var p=n.glyphs.get(m),v=p.unicode|0;if(isNaN(p.advanceWidth))throw new Error("Glyph "+p.name+" ("+m+"): advanceWidth is not a number.");(o>v||o===void 0)&&v>0&&(o=v),l<v&&(l=v);var g=f4.getUnicodeRange(v);if(g<32)h|=1<<g;else if(g<64)f|=1<<g-32;else if(g<96)u|=1<<g-64;else if(g<123)d|=1<<g-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(p.name!==".notdef"){var M=p.getMetrics();e.push(M.xMin),t.push(M.yMin),c.push(M.xMax),a.push(M.yMax),s.push(M.leftSideBearing),i.push(M.rightSideBearing),r.push(p.advanceWidth)}}var y={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,c),yMax:Math.max.apply(null,a),advanceWidthMax:Math.max.apply(null,r),advanceWidthAvg:qt(r),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,i)};y.ascender=n.ascender,y.descender=n.descender;var b=Q7.make({flags:3,unitsPerEm:n.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:n.createdTimestamp}),w=e8.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:n.glyphs.length}),x=c8.make(n.glyphs.length),z=f4.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:o,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:f,ulUnicodeRange3:u,ulUnicodeRange4:d,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:h7(n,"xyvw",{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:h7(n,"HIKLEFJMNTZBDPRAGOQSUVWXY",y).yMax,usDefaultChar:n.hasChar(" ")?32:0,usBreakChar:n.hasChar(" ")?32:0},n.tables.os2)),L=t8.make(n.glyphs),S=N7.make(n.glyphs),k=n.getEnglishName("fontFamily"),E=n.getEnglishName("fontSubfamily"),V=k+" "+E,T=n.getEnglishName("postScriptName");T||(T=k.replace(/\s/g,"")+"-"+E);var H={};for(var D in n.names)H[D]=n.names[D];H.uniqueID||(H.uniqueID={en:n.getEnglishName("manufacturer")+":"+V}),H.postScriptName||(H.postScriptName={en:T}),H.preferredFamily||(H.preferredFamily=n.names.fontFamily),H.preferredSubfamily||(H.preferredSubfamily=n.names.fontSubfamily);var O=[],R=o8.make(H,O),N=O.length>0?n8.make(O):void 0,q=l8.make(),Y=J7.make(n.glyphs,{version:n.getEnglishName("version"),fullName:V,familyName:k,weightName:E,postScriptName:T,unitsPerEm:n.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),_=n.metas&&Object.keys(n.metas).length>0?u8.make(n.metas):void 0,c1=[b,w,x,z,R,S,q,Y,L];N&&c1.push(N),n.tables.gsub&&c1.push(h8.make(n.tables.gsub)),_&&c1.push(_);for(var w1=f8(c1),D1=w1.encode(),J=M4(D1),C1=w1.fields,r0=!1,u1=0;u1<C1.length;u1+=1)if(C1[u1].name==="head table"){C1[u1].value.checkSumAdjustment=2981146554-J,r0=!0;break}if(!r0)throw new Error("Could not find head table with checkSum to adjust.");return w1}var Nt={make:f8,fontToTable:Ut,computeCheckSum:M4};function J5(n,e){for(var t=0,c=n.length-1;t<=c;){var a=t+c>>>1,r=n[a].tag;if(r===e)return a;r<e?t=a+1:c=a-1}return-t-1}function u7(n,e){for(var t=0,c=n.length-1;t<=c;){var a=t+c>>>1,r=n[a];if(r===e)return a;r<e?t=a+1:c=a-1}return-t-1}function f7(n,e){for(var t,c=0,a=n.length-1;c<=a;){var r=c+a>>>1;t=n[r];var s=t.start;if(s===e)return t;s<e?c=r+1:a=r-1}if(c>0)return t=n[c-1],e>t.end?0:t}function d3(n,e){this.font=n,this.tableName=e}d3.prototype={searchTag:J5,binSearch:u7,getTable:function(n){var e=this.font.tables[this.tableName];return!e&&n&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var n=this.getTable();return n?n.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var n=this.getTable();if(n){for(var e=!1,t=0;t<n.scripts.length;t++){var c=n.scripts[t].tag;if(c==="DFLT")return c;c==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(n,e){var t=this.getTable(e);if(t){n=n||"DFLT";var c=t.scripts,a=J5(t.scripts,n);if(a>=0)return c[a].script;if(e){var r={tag:n,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return c.splice(-1-a,0,r),r.script}}},getLangSysTable:function(n,e,t){var c=this.getScriptTable(n,t);if(c){if(!e||e==="dflt"||e==="DFLT")return c.defaultLangSys;var a=J5(c.langSysRecords,e);if(a>=0)return c.langSysRecords[a].langSys;if(t){var r={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return c.langSysRecords.splice(-1-a,0,r),r.langSys}}},getFeatureTable:function(n,e,t,c){var a=this.getLangSysTable(n,e,c);if(a){for(var r,s=a.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(r=i[s[o]],r.tag===t)return r.feature;if(c){var l=i.length;return n1.assert(l===0||t>=i[l-1].tag,"Features must be added in alphabetical order."),r={tag:t,feature:{params:0,lookupListIndexes:[]}},i.push(r),s.push(l),r.feature}}},getLookupTables:function(n,e,t,c,a){var r=this.getFeatureTable(n,e,t,a),s=[];if(r){for(var i,o=r.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===c&&s.push(i);if(s.length===0&&a){i={lookupType:c,lookupFlag:0,subtables:[],markFilteringSet:void 0};var f=l.length;return l.push(i),o.push(f),[i]}}return s},getGlyphClass:function(n,e){switch(n.format){case 1:return n.startGlyph<=e&&e<n.startGlyph+n.classes.length?n.classes[e-n.startGlyph]:0;case 2:var t=f7(n.ranges,e);return t?t.classId:0}},getCoverageIndex:function(n,e){switch(n.format){case 1:var t=u7(n.glyphs,e);return t>=0?t:-1;case 2:var c=f7(n.ranges,e);return c?c.index+e-c.start:-1}},expandCoverage:function(n){if(n.format===1)return n.glyphs;for(var e=[],t=n.ranges,c=0;c<t.length;c++)for(var a=t[c],r=a.start,s=a.end,i=r;i<=s;i++)e.push(i);return e}};function p3(n){d3.call(this,n,"gpos")}p3.prototype=d3.prototype;p3.prototype.init=function(){var n=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(n)};p3.prototype.getKerningValue=function(n,e,t){for(var c=0;c<n.length;c++)for(var a=n[c].subtables,r=0;r<a.length;r++){var s=a[r],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===t)return h.value1&&h.value1.xAdvance||0}break;case 2:var f=this.getGlyphClass(s.classDef1,e),u=this.getGlyphClass(s.classDef2,t),d=s.classRecords[f][u];return d.value1&&d.value1.xAdvance||0}}return 0};p3.prototype.getKerningTables=function(n,e){if(this.font.tables.gpos)return this.getLookupTables(n,e,"kern",2)};function g0(n){d3.call(this,n,"gsub")}function $t(n,e){var t=n.length;if(t!==e.length)return!1;for(var c=0;c<t;c++)if(n[c]!==e[c])return!1;return!0}function x4(n,e,t){for(var c=n.subtables,a=0;a<c.length;a++){var r=c[a];if(r.substFormat===e)return r}if(t)return c.push(t),t}g0.prototype=d3.prototype;g0.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};g0.prototype.getSingle=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,1),r=0;r<a.length;r++)for(var s=a[r].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;if(o.substFormat===1){var f=o.deltaGlyphId;for(h=0;h<l.length;h++){var u=l[h];c.push({sub:u,by:u+f})}}else{var d=o.substitute;for(h=0;h<l.length;h++)c.push({sub:l[h],by:d[h]})}}return c};g0.prototype.getMultiple=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,2),r=0;r<a.length;r++)for(var s=a[r].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 f=l[h],u=o.sequences[h];c.push({sub:f,by:u})}}return c};g0.prototype.getAlternates=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,3),r=0;r<a.length;r++)for(var s=a[r].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.alternateSets,f=0;f<l.length;f++)c.push({sub:l[f],by:h[f]});return c};g0.prototype.getLigatures=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,4),r=0;r<a.length;r++)for(var s=a[r].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,f=0;f<l.length;f++)for(var u=l[f],d=h[f],m=0;m<d.length;m++){var p=d[m];c.push({sub:[u].concat(p.components),by:p.ligGlyph})}return c};g0.prototype.addSingle=function(n,e,t,c){var a=this.getLookupTables(t,c,n,1,!0)[0],r=x4(a,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});n1.assert(r.coverage.format===1,"Single: unable to modify coverage table format "+r.coverage.format);var s=e.sub,i=this.binSearch(r.coverage.glyphs,s);i<0&&(i=-1-i,r.coverage.glyphs.splice(i,0,s),r.substitute.splice(i,0,0)),r.substitute[i]=e.by};g0.prototype.addMultiple=function(n,e,t,c){n1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var a=this.getLookupTables(t,c,n,2,!0)[0],r=x4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});n1.assert(r.coverage.format===1,"Multiple: unable to modify coverage table format "+r.coverage.format);var s=e.sub,i=this.binSearch(r.coverage.glyphs,s);i<0&&(i=-1-i,r.coverage.glyphs.splice(i,0,s),r.sequences.splice(i,0,0)),r.sequences[i]=e.by};g0.prototype.addAlternate=function(n,e,t,c){var a=this.getLookupTables(t,c,n,3,!0)[0],r=x4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});n1.assert(r.coverage.format===1,"Alternate: unable to modify coverage table format "+r.coverage.format);var s=e.sub,i=this.binSearch(r.coverage.glyphs,s);i<0&&(i=-1-i,r.coverage.glyphs.splice(i,0,s),r.alternateSets.splice(i,0,0)),r.alternateSets[i]=e.by};g0.prototype.addLigature=function(n,e,t,c){var a=this.getLookupTables(t,c,n,4,!0)[0],r=a.subtables[0];r||(r={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},a.subtables[0]=r),n1.assert(r.coverage.format===1,"Ligature: unable to modify coverage table format "+r.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(r.coverage.glyphs,s);if(l>=0){for(var h=r.ligatureSets[l],f=0;f<h.length;f++)if($t(h[f].components,i))return;h.push(o)}else l=-1-l,r.coverage.glyphs.splice(l,0,s),r.ligatureSets.splice(l,0,[o])};g0.prototype.getFeature=function(n,e,t){if(/ss\d\d/.test(n))return this.getSingle(n,e,t);switch(n){case"aalt":case"salt":return this.getSingle(n,e,t).concat(this.getAlternates(n,e,t));case"dlig":case"liga":case"rlig":return this.getLigatures(n,e,t);case"ccmp":return this.getMultiple(n,e,t).concat(this.getLigatures(n,e,t));case"stch":return this.getMultiple(n,e,t)}};g0.prototype.add=function(n,e,t,c){if(/ss\d\d/.test(n))return this.addSingle(n,e,t,c);switch(n){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(n,e,t,c):this.addAlternate(n,e,t,c);case"dlig":case"liga":case"rlig":return this.addLigature(n,e,t,c);case"ccmp":return e.by instanceof Array?this.addMultiple(n,e,t,c):this.addLigature(n,e,t,c)}};function _t(){return typeof window<"u"}function Bt(n){for(var e=new Buffer(n.byteLength),t=new Uint8Array(n),c=0;c<e.length;++c)e[c]=t[c];return e}function i3(n,e){if(!n)throw e}function d7(n,e,t,c,a){var r;return(e&c)>0?(r=n.parseByte(),(e&a)===0&&(r=-r),r=t+r):(e&a)>0?r=t:r=t+n.parseShort(),r}function d8(n,e,t){var c=new W.Parser(e,t);n.numberOfContours=c.parseShort(),n._xMin=c.parseShort(),n._yMin=c.parseShort(),n._xMax=c.parseShort(),n._yMax=c.parseShort();var a,r;if(n.numberOfContours>0){for(var s=n.endPointIndices=[],i=0;i<n.numberOfContours;i+=1)s.push(c.parseUShort());n.instructionLength=c.parseUShort(),n.instructions=[];for(var o=0;o<n.instructionLength;o+=1)n.instructions.push(c.parseByte());var l=s[s.length-1]+1;a=[];for(var h=0;h<l;h+=1)if(r=c.parseByte(),a.push(r),(r&8)>0)for(var f=c.parseByte(),u=0;u<f;u+=1)a.push(r),h+=1;if(n1.argument(a.length===l,"Bad flags."),s.length>0){var d=[],m;if(l>0){for(var p=0;p<l;p+=1)r=a[p],m={},m.onCurve=!!(r&1),m.lastPointOfContour=s.indexOf(p)>=0,d.push(m);for(var v=0,g=0;g<l;g+=1)r=a[g],m=d[g],m.x=d7(c,r,v,2,16),v=m.x;for(var M=0,y=0;y<l;y+=1)r=a[y],m=d[y],m.y=d7(c,r,M,4,32),M=m.y}n.points=d}else n.points=[]}else if(n.numberOfContours===0)n.points=[];else{n.isComposite=!0,n.points=[],n.components=[];for(var b=!0;b;){a=c.parseUShort();var w={glyphIndex:c.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(a&1)>0?(a&2)>0?(w.dx=c.parseShort(),w.dy=c.parseShort()):w.matchedPoints=[c.parseUShort(),c.parseUShort()]:(a&2)>0?(w.dx=c.parseChar(),w.dy=c.parseChar()):w.matchedPoints=[c.parseByte(),c.parseByte()],(a&8)>0?w.xScale=w.yScale=c.parseF2Dot14():(a&64)>0?(w.xScale=c.parseF2Dot14(),w.yScale=c.parseF2Dot14()):(a&128)>0&&(w.xScale=c.parseF2Dot14(),w.scale01=c.parseF2Dot14(),w.scale10=c.parseF2Dot14(),w.yScale=c.parseF2Dot14()),n.components.push(w),b=!!(a&32)}if(a&256){n.instructionLength=c.parseUShort(),n.instructions=[];for(var x=0;x<n.instructionLength;x+=1)n.instructions.push(c.parseByte())}}}function Q5(n,e){for(var t=[],c=0;c<n.length;c+=1){var a=n[c],r={x:e.xScale*a.x+e.scale01*a.y+e.dx,y:e.scale10*a.x+e.yScale*a.y+e.dy,onCurve:a.onCurve,lastPointOfContour:a.lastPointOfContour};t.push(r)}return t}function Gt(n){for(var e=[],t=[],c=0;c<n.length;c+=1){var a=n[c];t.push(a),a.lastPointOfContour&&(e.push(t),t=[])}return n1.argument(t.length===0,"There are still points left in the current contour."),e}function p8(n){var e=new $1;if(!n)return e;for(var t=Gt(n),c=0;c<t.length;++c){var a=t[c],r=null,s=a[a.length-1],i=a[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<a.length;++l)if(r=s,s=i,i=a[(l+1)%a.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=r,f=i;r.onCurve||(h={x:(s.x+r.x)*.5,y:(s.y+r.y)*.5}),i.onCurve||(f={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5}),e.quadraticCurveTo(s.x,s.y,f.x,f.y)}e.closePath()}return e}function m8(n,e){if(e.isComposite)for(var t=0;t<e.components.length;t+=1){var c=e.components[t],a=n.get(c.glyphIndex);if(a.getPath(),a.points){var r=void 0;if(c.matchedPoints===void 0)r=Q5(a.points,c);else{if(c.matchedPoints[0]>e.points.length-1||c.matchedPoints[1]>a.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[c.matchedPoints[0]],i=a.points[c.matchedPoints[1]],o={xScale:c.xScale,scale01:c.scale01,scale10:c.scale10,yScale:c.yScale,dx:0,dy:0};i=Q5([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,r=Q5(a.points,o)}e.points=e.points.concat(r)}}return p8(e.points)}function jt(n,e,t,c){for(var a=new B0.GlyphSet(c),r=0;r<t.length-1;r+=1){var s=t[r],i=t[r+1];s!==i?a.push(r,B0.ttfGlyphLoader(c,r,d8,n,e+s,m8)):a.push(r,B0.glyphLoader(c,r))}return a}function Wt(n,e,t,c){var a=new B0.GlyphSet(c);return c._push=function(r){var s=t[r],i=t[r+1];s!==i?a.push(r,B0.ttfGlyphLoader(c,r,d8,n,e+s,m8)):a.push(r,B0.glyphLoader(c,r))},a}function Xt(n,e,t,c,a){return a.lowMemory?Wt(n,e,t,c):jt(n,e,t,c)}var v8={getPath:p8,parse:Xt},g8,x2,y8,d4;function b8(n){this.font=n,this.getCommands=function(e){return v8.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function Zt(n){return n}function M8(n){return Math.sign(n)*Math.round(Math.abs(n))}function Yt(n){return Math.sign(n)*Math.round(Math.abs(n*2))/2}function Kt(n){return Math.sign(n)*(Math.round(Math.abs(n)+.5)-.5)}function Jt(n){return Math.sign(n)*Math.ceil(Math.abs(n))}function Qt(n){return Math.sign(n)*Math.floor(Math.abs(n))}var x8=function(n){var e=this.srPeriod,t=this.srPhase,c=this.srThreshold,a=1;return n<0&&(n=-n,a=-1),n+=c-t,n=Math.trunc(n/e)*e,n+=t,n<0?t*a:n*a},_0={x:1,y:0,axis:"x",distance:function(n,e,t,c){return(t?n.xo:n.x)-(c?e.xo:e.x)},interpolate:function(n,e,t,c){var a,r,s,i,o,l,h;if(!c||c===this){if(a=n.xo-e.xo,r=n.xo-t.xo,o=e.x-e.xo,l=t.x-t.xo,s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){n.x=n.xo+(o+l)/2;return}n.x=n.xo+(o*i+l*s)/h;return}if(a=c.distance(n,e,!0,!0),r=c.distance(n,t,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(t,t,!1,!0),s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){_0.setRelative(n,n,(o+l)/2,c,!0);return}_0.setRelative(n,n,(o*i+l*s)/h,c,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(n,e,t,c,a){if(!c||c===this){n.x=(a?e.xo:e.x)+t;return}var r=a?e.xo:e.x,s=a?e.yo:e.y,i=r+t*c.x,o=s+t*c.y;n.x=i+(n.y-o)/c.normalSlope},slope:0,touch:function(n){n.xTouched=!0},touched:function(n){return n.xTouched},untouch:function(n){n.xTouched=!1}},K0={x:0,y:1,axis:"y",distance:function(n,e,t,c){return(t?n.yo:n.y)-(c?e.yo:e.y)},interpolate:function(n,e,t,c){var a,r,s,i,o,l,h;if(!c||c===this){if(a=n.yo-e.yo,r=n.yo-t.yo,o=e.y-e.yo,l=t.y-t.yo,s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){n.y=n.yo+(o+l)/2;return}n.y=n.yo+(o*i+l*s)/h;return}if(a=c.distance(n,e,!0,!0),r=c.distance(n,t,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(t,t,!1,!0),s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){K0.setRelative(n,n,(o+l)/2,c,!0);return}K0.setRelative(n,n,(o*i+l*s)/h,c,!0)},normalSlope:0,setRelative:function(n,e,t,c,a){if(!c||c===this){n.y=(a?e.yo:e.y)+t;return}var r=a?e.xo:e.x,s=a?e.yo:e.y,i=r+t*c.x,o=s+t*c.y;n.y=o+c.normalSlope*(n.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(n){n.yTouched=!0},touched:function(n){return n.yTouched},untouch:function(n){n.yTouched=!1}};Object.freeze(_0);Object.freeze(K0);function m3(n,e){this.x=n,this.y=e,this.axis=void 0,this.slope=e/n,this.normalSlope=-n/e,Object.freeze(this)}m3.prototype.distance=function(n,e,t,c){return this.x*_0.distance(n,e,t,c)+this.y*K0.distance(n,e,t,c)};m3.prototype.interpolate=function(n,e,t,c){var a,r,s,i,o,l,h;if(s=c.distance(n,e,!0,!0),i=c.distance(n,t,!0,!0),a=c.distance(e,e,!1,!0),r=c.distance(t,t,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(n,n,(a+r)/2,c,!0);return}this.setRelative(n,n,(a*l+r*o)/h,c,!0)};m3.prototype.setRelative=function(n,e,t,c,a){c=c||this;var r=a?e.xo:e.x,s=a?e.yo:e.y,i=r+t*c.x,o=s+t*c.y,l=c.normalSlope,h=this.slope,f=n.x,u=n.y;n.x=(h*f-l*i+o-u)/(h-l),n.y=h*(n.x-f)+u};m3.prototype.touch=function(n){n.xTouched=!0,n.yTouched=!0};function v3(n,e){var t=Math.sqrt(n*n+e*e);return n/=t,e/=t,n===1&&e===0?_0:n===0&&e===1?K0:new m3(n,e)}function J0(n,e,t,c){this.x=this.xo=Math.round(n*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=t,this.onCurve=c,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}J0.prototype.nextTouched=function(n){for(var e=this.nextPointOnContour;!n.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};J0.prototype.prevTouched=function(n){for(var e=this.prevPointOnContour;!n.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var f3=Object.freeze(new J0(0,0)),en={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function r2(n,e){switch(this.env=n,this.stack=[],this.prog=e,n){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=_0,this.round=M8}}b8.prototype.exec=function(n,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var t=this.font,c=this._prepState;if(!c||c.ppem!==e){var a=this._fpgmState;if(!a){r2.prototype=en,a=this._fpgmState=new r2("fpgm",t.tables.fpgm),a.funcs=[],a.font=t,exports.DEBUG&&(console.log("---EXEC FPGM---"),a.step=-1);try{x2(a)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}r2.prototype=a,c=this._prepState=new r2("prep",t.tables.prep),c.ppem=e;var r=t.tables.cvt;if(r)for(var s=c.cvt=new Array(r.length),i=e/t.unitsPerEm,o=0;o<r.length;o++)s[o]=r[o]*i;else c.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),c.step=-1);try{x2(c)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return y8(n,c)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};y8=function(n,e){var t=e.ppem/e.font.unitsPerEm,c=t,a=n.components,r,s,i;if(r2.prototype=e,!a)i=new r2("glyf",n.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),d4(n,i,t,c),s=i.gZone;else{var o=e.font;s=[],r=[];for(var l=0;l<a.length;l++){var h=a[l],f=o.glyphs.get(h.glyphIndex);i=new r2("glyf",f.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),d4(f,i,t,c);for(var u=Math.round(h.dx*t),d=Math.round(h.dy*c),m=i.gZone,p=i.contours,v=0;v<m.length;v++){var g=m[v];g.xTouched=g.yTouched=!1,g.xo=g.x=g.x+u,g.yo=g.y=g.y+d}var M=s.length;s.push.apply(s,m);for(var y=0;y<p.length;y++)r.push(p[y]+M)}n.instructions&&!i.inhibitGridFit&&(i=new r2("glyf",n.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=r,s.push(new J0(0,0),new J0(Math.round(n.advanceWidth*t),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),x2(i),s.length-=2)}return s};d4=function(n,e,t,c){for(var a=n.points||[],r=a.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<r;l++)o=a[l],s[l]=new J0(o.x*t,o.y*c,o.lastPointOfContour,o.onCurve);for(var h,f,u=0;u<r;u++)o=s[u],h||(h=o,i.push(u)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(f=s[u+1],o.nextPointOnContour=f,f.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<r;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new J0(0,0),new J0(Math.round(n.advanceWidth*t),0)),x2(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<r;m++)console.log(m,s[m].x,s[m].y)}}};x2=function(n){var e=n.prog;if(e){var t=e.length,c;for(n.ip=0;n.ip<t;n.ip++){if(exports.DEBUG&&n.step++,c=g8[e[n.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[n.ip]).toString(16));c(n)}}};function a5(n){for(var e=n.tZone=new Array(n.gZone.length),t=0;t<e.length;t++)e[t]=new J0(0,0)}function w8(n,e){var t=n.prog,c=n.ip,a=1,r;do if(r=t[++c],r===88)a++;else if(r===89)a--;else if(r===64)c+=t[c+1]+1;else if(r===65)c+=2*t[c+1]+1;else if(r>=176&&r<=183)c+=r-176+1;else if(r>=184&&r<=191)c+=(r-184+1)*2;else if(e&&a===1&&r===27)break;while(a>0);n.ip=c}function p7(n,e){exports.DEBUG&&console.log(e.step,"SVTCA["+n.axis+"]"),e.fv=e.pv=e.dpv=n}function m7(n,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+n.axis+"]"),e.pv=e.dpv=n}function v7(n,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+n.axis+"]"),e.fv=n}function g7(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z2[c],s=e.z1[a];exports.DEBUG&&console.log("SPVTL["+n+"]",c,a);var i,o;n?(i=r.y-s.y,o=s.x-r.x):(i=s.x-r.x,o=s.y-r.y),e.pv=e.dpv=v3(i,o)}function y7(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z2[c],s=e.z1[a];exports.DEBUG&&console.log("SFVTL["+n+"]",c,a);var i,o;n?(i=r.y-s.y,o=s.x-r.x):(i=s.x-r.x,o=s.y-r.y),e.fv=v3(i,o)}function tn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SPVFS[]",t,c),n.pv=n.dpv=v3(c,t)}function nn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SPVFS[]",t,c),n.fv=v3(c,t)}function cn(n){var e=n.stack,t=n.pv;exports.DEBUG&&console.log(n.step,"GPV[]"),e.push(t.x*16384),e.push(t.y*16384)}function an(n){var e=n.stack,t=n.fv;exports.DEBUG&&console.log(n.step,"GFV[]"),e.push(t.x*16384),e.push(t.y*16384)}function rn(n){n.fv=n.pv,exports.DEBUG&&console.log(n.step,"SFVTPV[]")}function sn(n){var e=n.stack,t=e.pop(),c=e.pop(),a=e.pop(),r=e.pop(),s=e.pop(),i=n.z0,o=n.z1,l=i[t],h=i[c],f=o[a],u=o[r],d=n.z2[s];exports.DEBUG&&console.log("ISECT[], ",t,c,a,r,s);var m=l.x,p=l.y,v=h.x,g=h.y,M=f.x,y=f.y,b=u.x,w=u.y,x=(m-v)*(y-w)-(p-g)*(M-b),z=m*g-p*v,L=M*w-y*b;d.x=(z*(M-b)-L*(m-v))/x,d.y=(z*(y-w)-L*(p-g))/x}function on(n){n.rp0=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SRP0[]",n.rp0)}function ln(n){n.rp1=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SRP1[]",n.rp1)}function hn(n){n.rp2=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SRP2[]",n.rp2)}function un(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZP0[]",e),n.zp0=e,e){case 0:n.tZone||a5(n),n.z0=n.tZone;break;case 1:n.z0=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function fn(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZP1[]",e),n.zp1=e,e){case 0:n.tZone||a5(n),n.z1=n.tZone;break;case 1:n.z1=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function dn(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZP2[]",e),n.zp2=e,e){case 0:n.tZone||a5(n),n.z2=n.tZone;break;case 1:n.z2=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function pn(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZPS[]",e),n.zp0=n.zp1=n.zp2=e,e){case 0:n.tZone||a5(n),n.z0=n.z1=n.z2=n.tZone;break;case 1:n.z0=n.z1=n.z2=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function mn(n){n.loop=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SLOOP[]",n.loop)}function vn(n){exports.DEBUG&&console.log(n.step,"RTG[]"),n.round=M8}function gn(n){exports.DEBUG&&console.log(n.step,"RTHG[]"),n.round=Kt}function yn(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SMD[]",e),n.minDis=e/64}function bn(n){exports.DEBUG&&console.log(n.step,"ELSE[]"),w8(n,!1)}function Mn(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"JMPR[]",e),n.ip+=e-1}function xn(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SCVTCI[]",e),n.cvCutIn=e/64}function wn(n){var e=n.stack;exports.DEBUG&&console.log(n.step,"DUP[]"),e.push(e[e.length-1])}function e4(n){exports.DEBUG&&console.log(n.step,"POP[]"),n.stack.pop()}function zn(n){exports.DEBUG&&console.log(n.step,"CLEAR[]"),n.stack.length=0}function kn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SWAP[]"),e.push(t),e.push(c)}function Ln(n){var e=n.stack;exports.DEBUG&&console.log(n.step,"DEPTH[]"),e.push(e.length)}function Sn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"LOOPCALL[]",t,c);var a=n.ip,r=n.prog;n.prog=n.funcs[t];for(var s=0;s<c;s++)x2(n),exports.DEBUG&&console.log(++n.step,s+1<c?"next loopcall":"done loopcall",s);n.ip=a,n.prog=r}function An(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"CALL[]",e);var t=n.ip,c=n.prog;n.prog=n.funcs[e],x2(n),n.ip=t,n.prog=c,exports.DEBUG&&console.log(++n.step,"returning from",e)}function Cn(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"CINDEX[]",t),e.push(e[e.length-t])}function Pn(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"MINDEX[]",t),e.push(e.splice(e.length-t,1)[0])}function En(n){if(n.env!=="fpgm")throw new Error("FDEF not allowed here");var e=n.stack,t=n.prog,c=n.ip,a=e.pop(),r=c;for(exports.DEBUG&&console.log(n.step,"FDEF[]",a);t[++c]!==45;);n.ip=c,n.funcs[a]=t.slice(r+1,c)}function b7(n,e){var t=e.stack.pop(),c=e.z0[t],a=e.fv,r=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+n+"]",t);var s=r.distance(c,f3);n&&(s=e.round(s)),a.setRelative(c,f3,s,r),a.touch(c),e.rp0=e.rp1=t}function M7(n,e){var t=e.z2,c=t.length-2,a,r,s;exports.DEBUG&&console.log(e.step,"IUP["+n.axis+"]");for(var i=0;i<c;i++)a=t[i],!n.touched(a)&&(r=a.prevTouched(n),r!==a&&(s=a.nextTouched(n),r===s&&n.setRelative(a,a,n.distance(r,r,!1,!0),n,!0),n.interpolate(a,r,s,n)))}function x7(n,e){for(var t=e.stack,c=n?e.rp1:e.rp2,a=(n?e.z0:e.z1)[c],r=e.fv,s=e.pv,i=e.loop,o=e.z2;i--;){var l=t.pop(),h=o[l],f=s.distance(a,a,!1,!0);r.setRelative(h,h,f,s),r.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-i)+": ":"")+"SHP["+(n?"rp1":"rp2")+"]",l)}e.loop=1}function w7(n,e){var t=e.stack,c=n?e.rp1:e.rp2,a=(n?e.z0:e.z1)[c],r=e.fv,s=e.pv,i=t.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+n+"]",i);var h=s.distance(a,a,!1,!0);do l!==a&&r.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function z7(n,e){var t=e.stack,c=n?e.rp1:e.rp2,a=(n?e.z0:e.z1)[c],r=e.fv,s=e.pv,i=t.pop();exports.DEBUG&&console.log(e.step,"SHZ["+n+"]",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(a,a,!1,!0),f=o.length-2,u=0;u<f;u++)l=o[u],r.setRelative(l,l,h,s)}function Tn(n){for(var e=n.stack,t=n.loop,c=n.fv,a=e.pop()/64,r=n.z2;t--;){var s=e.pop(),i=r[s];exports.DEBUG&&console.log(n.step,(n.loop>1?"loop "+(n.loop-t)+": ":"")+"SHPIX[]",s,a),c.setRelative(i,i,a),c.touch(i)}n.loop=1}function In(n){for(var e=n.stack,t=n.rp1,c=n.rp2,a=n.loop,r=n.z0[t],s=n.z1[c],i=n.fv,o=n.dpv,l=n.z2;a--;){var h=e.pop(),f=l[h];exports.DEBUG&&console.log(n.step,(n.loop>1?"loop "+(n.loop-a)+": ":"")+"IP[]",h,t,"<->",c),i.interpolate(f,r,s,o),i.touch(f)}n.loop=1}function k7(n,e){var t=e.stack,c=t.pop()/64,a=t.pop(),r=e.z1[a],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(r,s,c,o),i.touch(r),exports.DEBUG&&console.log(e.step,"MSIRP["+n+"]",c,a),e.rp1=e.rp0,e.rp2=a,n&&(e.rp0=a)}function Hn(n){for(var e=n.stack,t=n.rp0,c=n.z0[t],a=n.loop,r=n.fv,s=n.pv,i=n.z1;a--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(n.step,(n.loop>1?"loop "+(n.loop-a)+": ":"")+"ALIGNRP[]",o),r.setRelative(l,c,0,s),r.touch(l)}n.loop=1}function Vn(n){exports.DEBUG&&console.log(n.step,"RTDG[]"),n.round=Yt}function L7(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z0[a],s=e.fv,i=e.pv,o=e.cvt[c];exports.DEBUG&&console.log(e.step,"MIAP["+n+"]",c,"(",o,")",a);var l=i.distance(r,f3);n&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(r,f3,l,i),e.zp0===0&&(r.xo=r.x,r.yo=r.y),s.touch(r),e.rp0=e.rp1=a}function On(n){var e=n.prog,t=n.ip,c=n.stack,a=e[++t];exports.DEBUG&&console.log(n.step,"NPUSHB[]",a);for(var r=0;r<a;r++)c.push(e[++t]);n.ip=t}function Fn(n){var e=n.ip,t=n.prog,c=n.stack,a=t[++e];exports.DEBUG&&console.log(n.step,"NPUSHW[]",a);for(var r=0;r<a;r++){var s=t[++e]<<8|t[++e];s&32768&&(s=-((s^65535)+1)),c.push(s)}n.ip=e}function Dn(n){var e=n.stack,t=n.store;t||(t=n.store=[]);var c=e.pop(),a=e.pop();exports.DEBUG&&console.log(n.step,"WS",c,a),t[a]=c}function Rn(n){var e=n.stack,t=n.store,c=e.pop();exports.DEBUG&&console.log(n.step,"RS",c);var a=t&&t[c]||0;e.push(a)}function qn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"WCVTP",t,c),n.cvt[c]=t/64}function Un(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"RCVT",t),e.push(n.cvt[t]*64)}function S7(n,e){var t=e.stack,c=t.pop(),a=e.z2[c];exports.DEBUG&&console.log(e.step,"GC["+n+"]",c),t.push(e.dpv.distance(a,f3,n,!1)*64)}function A7(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z1[c],s=e.z0[a],i=e.dpv.distance(s,r,n,n);exports.DEBUG&&console.log(e.step,"MD["+n+"]",c,a,"->",i),e.stack.push(Math.round(i*64))}function Nn(n){exports.DEBUG&&console.log(n.step,"MPPEM[]"),n.stack.push(n.ppem)}function $n(n){exports.DEBUG&&console.log(n.step,"FLIPON[]"),n.autoFlip=!0}function _n(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"LT[]",t,c),e.push(c<t?1:0)}function Bn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"LTEQ[]",t,c),e.push(c<=t?1:0)}function Gn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"GT[]",t,c),e.push(c>t?1:0)}function jn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"GTEQ[]",t,c),e.push(c>=t?1:0)}function Wn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"EQ[]",t,c),e.push(t===c?1:0)}function Xn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"NEQ[]",t,c),e.push(t!==c?1:0)}function Zn(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"ODD[]",t),e.push(Math.trunc(t)%2?1:0)}function Yn(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"EVEN[]",t),e.push(Math.trunc(t)%2?0:1)}function Kn(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"IF[]",e),e||(w8(n,!0),exports.DEBUG&&console.log(n.step,"EIF[]"))}function Jn(n){exports.DEBUG&&console.log(n.step,"EIF[]")}function Qn(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"AND[]",t,c),e.push(t&&c?1:0)}function ec(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"OR[]",t,c),e.push(t||c?1:0)}function tc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"NOT[]",t),e.push(t?0:1)}function t4(n,e){var t=e.stack,c=t.pop(),a=e.fv,r=e.pv,s=e.ppem,i=e.deltaBase+(n-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+n+"]",c,t);for(var h=0;h<c;h++){var f=t.pop(),u=t.pop(),d=i+((u&240)>>4);if(d===s){var m=(u&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",f,"by",m*o);var p=l[f];a.setRelative(p,p,m*o,r)}}}function nc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"SDB[]",t),n.deltaBase=t}function cc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"SDS[]",t),n.deltaShift=Math.pow(.5,t)}function ac(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"ADD[]",t,c),e.push(c+t)}function rc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SUB[]",t,c),e.push(c-t)}function sc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"DIV[]",t,c),e.push(c*64/t)}function ic(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"MUL[]",t,c),e.push(c*t/64)}function oc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"ABS[]",t),e.push(Math.abs(t))}function lc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"NEG[]",t),e.push(-t)}function hc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"FLOOR[]",t),e.push(Math.floor(t/64)*64)}function uc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"CEILING[]",t),e.push(Math.ceil(t/64)*64)}function Z3(n,e){var t=e.stack,c=t.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),t.push(e.round(c/64)*64)}function fc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"WCVTF[]",t,c),n.cvt[c]=t*n.ppem/n.font.unitsPerEm}function n4(n,e){var t=e.stack,c=t.pop(),a=e.ppem,r=e.deltaBase+(n-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+n+"]",c,t);for(var i=0;i<c;i++){var o=t.pop(),l=t.pop(),h=r+((l&240)>>4);if(h===a){var f=(l&15)-8;f>=0&&f++;var u=f*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",o,"by",u),e.cvt[o]+=u}}}function dc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SROUND[]",e),n.round=x8;var t;switch(e&192){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(n.srPeriod=t,e&48){case 0:n.srPhase=0;break;case 16:n.srPhase=.25*t;break;case 32:n.srPhase=.5*t;break;case 48:n.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?n.srThreshold=0:n.srThreshold=(e/8-.5)*t}function pc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"S45ROUND[]",e),n.round=x8;var t;switch(e&192){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(n.srPeriod=t,e&48){case 0:n.srPhase=0;break;case 16:n.srPhase=.25*t;break;case 32:n.srPhase=.5*t;break;case 48:n.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?n.srThreshold=0:n.srThreshold=(e/8-.5)*t}function mc(n){exports.DEBUG&&console.log(n.step,"ROFF[]"),n.round=Zt}function vc(n){exports.DEBUG&&console.log(n.step,"RUTG[]"),n.round=Jt}function gc(n){exports.DEBUG&&console.log(n.step,"RDTG[]"),n.round=Qt}function yc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SCANCTRL[]",e)}function C7(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z2[c],s=e.z1[a];exports.DEBUG&&console.log(e.step,"SDPVTL["+n+"]",c,a);var i,o;n?(i=r.y-s.y,o=s.x-r.x):(i=s.x-r.x,o=s.y-r.y),e.dpv=v3(i,o)}function bc(n){var e=n.stack,t=e.pop(),c=0;exports.DEBUG&&console.log(n.step,"GETINFO[]",t),t&1&&(c=35),t&32&&(c|=4096),e.push(c)}function Mc(n){var e=n.stack,t=e.pop(),c=e.pop(),a=e.pop();exports.DEBUG&&console.log(n.step,"ROLL[]"),e.push(c),e.push(t),e.push(a)}function xc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"MAX[]",t,c),e.push(Math.max(c,t))}function wc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"MIN[]",t,c),e.push(Math.min(c,t))}function zc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SCANTYPE[]",e)}function kc(n){var e=n.stack.pop(),t=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"INSTCTRL[]",e,t),e){case 1:n.inhibitGridFit=!!t;return;case 2:n.ignoreCvt=!!t;return;default:throw new Error("invalid INSTCTRL[] selector")}}function n2(n,e){var t=e.stack,c=e.prog,a=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+n+"]");for(var r=0;r<n;r++)t.push(c[++a]);e.ip=a}function c2(n,e){var t=e.ip,c=e.prog,a=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+n+"]");for(var r=0;r<n;r++){var s=c[++t]<<8|c[++t];s&32768&&(s=-((s^65535)+1)),a.push(s)}e.ip=t}function j(n,e,t,c,a,r){var s=r.stack,i=n&&s.pop(),o=s.pop(),l=r.rp0,h=r.z0[l],f=r.z1[o],u=r.minDis,d=r.fv,m=r.dpv,p,v,g,M;v=p=m.distance(f,h,!0,!0),g=v>=0?1:-1,v=Math.abs(v),n&&(M=r.cvt[i],c&&Math.abs(v-M)<r.cvCutIn&&(v=M)),t&&v<u&&(v=u),c&&(v=r.round(v)),d.setRelative(f,h,g*v,m),d.touch(f),exports.DEBUG&&console.log(r.step,(n?"MIRP[":"MDRP[")+(e?"M":"m")+(t?">":"_")+(c?"R":"_")+(a===0?"Gr":a===1?"Bl":a===2?"Wh":"")+"]",n?i+"("+r.cvt[i]+","+M+")":"",o,"(d =",p,"->",g*v,")"),r.rp1=r.rp0,r.rp2=o,e&&(r.rp0=o)}g8=[p7.bind(void 0,K0),p7.bind(void 0,_0),m7.bind(void 0,K0),m7.bind(void 0,_0),v7.bind(void 0,K0),v7.bind(void 0,_0),g7.bind(void 0,0),g7.bind(void 0,1),y7.bind(void 0,0),y7.bind(void 0,1),tn,nn,cn,an,rn,sn,on,ln,hn,un,fn,dn,pn,mn,vn,gn,yn,bn,Mn,xn,void 0,void 0,wn,e4,zn,kn,Ln,Cn,Pn,void 0,void 0,void 0,Sn,An,En,void 0,b7.bind(void 0,0),b7.bind(void 0,1),M7.bind(void 0,K0),M7.bind(void 0,_0),x7.bind(void 0,0),x7.bind(void 0,1),w7.bind(void 0,0),w7.bind(void 0,1),z7.bind(void 0,0),z7.bind(void 0,1),Tn,In,k7.bind(void 0,0),k7.bind(void 0,1),Hn,Vn,L7.bind(void 0,0),L7.bind(void 0,1),On,Fn,Dn,Rn,qn,Un,S7.bind(void 0,0),S7.bind(void 0,1),void 0,A7.bind(void 0,0),A7.bind(void 0,1),Nn,void 0,$n,void 0,void 0,_n,Bn,Gn,jn,Wn,Xn,Zn,Yn,Kn,Jn,Qn,ec,tc,t4.bind(void 0,1),nc,cc,ac,rc,sc,ic,oc,lc,hc,uc,Z3.bind(void 0,0),Z3.bind(void 0,1),Z3.bind(void 0,2),Z3.bind(void 0,3),void 0,void 0,void 0,void 0,fc,t4.bind(void 0,2),t4.bind(void 0,3),n4.bind(void 0,1),n4.bind(void 0,2),n4.bind(void 0,3),dc,pc,void 0,void 0,mc,void 0,vc,gc,e4,e4,void 0,void 0,void 0,void 0,void 0,yc,C7.bind(void 0,0),C7.bind(void 0,1),bc,void 0,Mc,xc,wc,zc,kc,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,n2.bind(void 0,1),n2.bind(void 0,2),n2.bind(void 0,3),n2.bind(void 0,4),n2.bind(void 0,5),n2.bind(void 0,6),n2.bind(void 0,7),n2.bind(void 0,8),c2.bind(void 0,1),c2.bind(void 0,2),c2.bind(void 0,3),c2.bind(void 0,4),c2.bind(void 0,5),c2.bind(void 0,6),c2.bind(void 0,7),c2.bind(void 0,8),j.bind(void 0,0,0,0,0,0),j.bind(void 0,0,0,0,0,1),j.bind(void 0,0,0,0,0,2),j.bind(void 0,0,0,0,0,3),j.bind(void 0,0,0,0,1,0),j.bind(void 0,0,0,0,1,1),j.bind(void 0,0,0,0,1,2),j.bind(void 0,0,0,0,1,3),j.bind(void 0,0,0,1,0,0),j.bind(void 0,0,0,1,0,1),j.bind(void 0,0,0,1,0,2),j.bind(void 0,0,0,1,0,3),j.bind(void 0,0,0,1,1,0),j.bind(void 0,0,0,1,1,1),j.bind(void 0,0,0,1,1,2),j.bind(void 0,0,0,1,1,3),j.bind(void 0,0,1,0,0,0),j.bind(void 0,0,1,0,0,1),j.bind(void 0,0,1,0,0,2),j.bind(void 0,0,1,0,0,3),j.bind(void 0,0,1,0,1,0),j.bind(void 0,0,1,0,1,1),j.bind(void 0,0,1,0,1,2),j.bind(void 0,0,1,0,1,3),j.bind(void 0,0,1,1,0,0),j.bind(void 0,0,1,1,0,1),j.bind(void 0,0,1,1,0,2),j.bind(void 0,0,1,1,0,3),j.bind(void 0,0,1,1,1,0),j.bind(void 0,0,1,1,1,1),j.bind(void 0,0,1,1,1,2),j.bind(void 0,0,1,1,1,3),j.bind(void 0,1,0,0,0,0),j.bind(void 0,1,0,0,0,1),j.bind(void 0,1,0,0,0,2),j.bind(void 0,1,0,0,0,3),j.bind(void 0,1,0,0,1,0),j.bind(void 0,1,0,0,1,1),j.bind(void 0,1,0,0,1,2),j.bind(void 0,1,0,0,1,3),j.bind(void 0,1,0,1,0,0),j.bind(void 0,1,0,1,0,1),j.bind(void 0,1,0,1,0,2),j.bind(void 0,1,0,1,0,3),j.bind(void 0,1,0,1,1,0),j.bind(void 0,1,0,1,1,1),j.bind(void 0,1,0,1,1,2),j.bind(void 0,1,0,1,1,3),j.bind(void 0,1,1,0,0,0),j.bind(void 0,1,1,0,0,1),j.bind(void 0,1,1,0,0,2),j.bind(void 0,1,1,0,0,3),j.bind(void 0,1,1,0,1,0),j.bind(void 0,1,1,0,1,1),j.bind(void 0,1,1,0,1,2),j.bind(void 0,1,1,0,1,3),j.bind(void 0,1,1,1,0,0),j.bind(void 0,1,1,1,0,1),j.bind(void 0,1,1,1,0,2),j.bind(void 0,1,1,1,0,3),j.bind(void 0,1,1,1,1,0),j.bind(void 0,1,1,1,1,1),j.bind(void 0,1,1,1,1,2),j.bind(void 0,1,1,1,1,3)];function R2(n){this.char=n,this.state={},this.activeState=null}function w4(n,e,t){this.contextName=t,this.startIndex=n,this.endOffset=e}function Lc(n,e,t){this.contextName=n,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=t}function E0(n,e){this.context=n,this.index=e,this.length=n.length,this.current=n[e],this.backtrack=n.slice(0,e),this.lookahead=n.slice(e+1)}function r5(n){this.eventId=n,this.subscribers=[]}function Sc(n){var e=this,t=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];t.forEach(function(a){Object.defineProperty(e.events,a,{value:new r5(a)})}),n&&t.forEach(function(a){var r=n[a];typeof r=="function"&&e.events[a].subscribe(r)});var c=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];c.forEach(function(a){e.events[a].subscribe(e.updateContextsRanges)})}function H1(n){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],Sc.call(this,n)}R2.prototype.setState=function(n,e){return this.state[n]=e,this.activeState={key:n,value:this.state[n]},this.activeState};R2.prototype.getState=function(n){return this.state[n]||null};H1.prototype.inboundIndex=function(n){return n>=0&&n<this.tokens.length};H1.prototype.composeRUD=function(n){var e=this,t=!0,c=n.map(function(r){return e[r[0]].apply(e,r.slice(1).concat(t))}),a=function(r){return typeof r=="object"&&r.hasOwnProperty("FAIL")};if(c.every(a))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:c.filter(a)};this.dispatch("composeRUD",[c.filter(function(r){return!a(r)})])};H1.prototype.replaceRange=function(n,e,t,c){e=e!==null?e:this.tokens.length;var a=t.every(function(s){return s instanceof R2});if(!isNaN(n)&&this.inboundIndex(n)&&a){var r=this.tokens.splice.apply(this.tokens,[n,e].concat(t));return c||this.dispatch("replaceToken",[n,e,t]),[r,t]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};H1.prototype.replaceToken=function(n,e,t){if(!isNaN(n)&&this.inboundIndex(n)&&e instanceof R2){var c=this.tokens.splice(n,1,e);return t||this.dispatch("replaceToken",[n,e]),[c[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};H1.prototype.removeRange=function(n,e,t){e=isNaN(e)?this.tokens.length:e;var c=this.tokens.splice(n,e);return t||this.dispatch("removeRange",[c,n,e]),c};H1.prototype.removeToken=function(n,e){if(!isNaN(n)&&this.inboundIndex(n)){var t=this.tokens.splice(n,1);return e||this.dispatch("removeToken",[t,n]),t}else return{FAIL:"removeToken: invalid token index."}};H1.prototype.insertToken=function(n,e,t){var c=n.every(function(a){return a instanceof R2});return c?(this.tokens.splice.apply(this.tokens,[e,0].concat(n)),t||this.dispatch("insertToken",[n,e]),n):{FAIL:"insertToken: invalid token(s)."}};H1.prototype.registerModifier=function(n,e,t){this.events.newToken.subscribe(function(c,a){var r=[c,a],s=e===null||e.apply(this,r)===!0,i=[c,a];if(s){var o=t.apply(this,i);c.setState(n,o)}}),this.registeredModifiers.push(n)};r5.prototype.subscribe=function(n){return typeof n=="function"?this.subscribers.push(n)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};r5.prototype.unsubscribe=function(n){this.subscribers.splice(n,1)};E0.prototype.setCurrentIndex=function(n){this.index=n,this.current=this.context[n],this.backtrack=this.context.slice(0,n),this.lookahead=this.context.slice(n+1)};E0.prototype.get=function(n){switch(!0){case n===0:return this.current;case(n<0&&Math.abs(n)<=this.backtrack.length):return this.backtrack.slice(n)[0];case(n>0&&n<=this.lookahead.length):return this.lookahead[n-1];default:return null}};H1.prototype.rangeToText=function(n){if(n instanceof w4)return this.getRangeTokens(n).map(function(e){return e.char}).join("")};H1.prototype.getText=function(){return this.tokens.map(function(n){return n.char}).join("")};H1.prototype.getContext=function(n){var e=this.registeredContexts[n];return e||null};H1.prototype.on=function(n,e){var t=this.events[n];return t?t.subscribe(e):null};H1.prototype.dispatch=function(n,e){var t=this,c=this.events[n];c instanceof r5&&c.subscribers.forEach(function(a){a.apply(t,e||[])})};H1.prototype.registerContextChecker=function(n,e,t){if(this.getContext(n))return{FAIL:"context name '"+n+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof t!="function")return{FAIL:"missing context end check."};var c=new Lc(n,e,t);return this.registeredContexts[n]=c,this.contextCheckers.push(c),c};H1.prototype.getRangeTokens=function(n){var e=n.startIndex+n.endOffset;return[].concat(this.tokens.slice(n.startIndex,e))};H1.prototype.getContextRanges=function(n){var e=this.getContext(n);return e?e.ranges:{FAIL:"context checker '"+n+"' is not registered."}};H1.prototype.resetContextsRanges=function(){var n=this.registeredContexts;for(var e in n)if(n.hasOwnProperty(e)){var t=n[e];t.ranges=[]}};H1.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var n=this.tokens.map(function(c){return c.char}),e=0;e<n.length;e++){var t=new E0(n,e);this.runContextCheck(t)}this.dispatch("updateContextsRanges",[this.registeredContexts])};H1.prototype.setEndOffset=function(n,e){var t=this.getContext(e).openRange.startIndex,c=new w4(t,n,e),a=this.getContext(e).ranges;return c.rangeId=e+"."+a.length,a.push(c),this.getContext(e).openRange=null,c};H1.prototype.runContextCheck=function(n){var e=this,t=n.index;this.contextCheckers.forEach(function(c){var a=c.contextName,r=e.getContext(a).openRange;if(!r&&c.checkStart(n)&&(r=new w4(t,null,a),e.getContext(a).openRange=r,e.dispatch("contextStart",[a,t])),r&&c.checkEnd(n)){var s=t-r.startIndex+1,i=e.setEndOffset(s,a);e.dispatch("contextEnd",[a,i])}})};H1.prototype.tokenize=function(n){this.tokens=[],this.resetContextsRanges();var e=Array.from(n);this.dispatch("start");for(var t=0;t<e.length;t++){var c=e[t],a=new E0(e,t);this.dispatch("next",[a]),this.runContextCheck(a);var r=new R2(c);this.tokens.push(r),this.dispatch("newToken",[r,a])}return this.dispatch("end",[this.tokens]),this.tokens};function s2(n){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(n)}function z8(n){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(n)}function i2(n){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(n)}function K3(n){return/[A-z]/.test(n)}function Ac(n){return/\s/.test(n)}function y0(n){this.font=n,this.features={}}function M2(n){this.id=n.id,this.tag=n.tag,this.substitution=n.substitution}function g3(n,e){if(!n)return-1;switch(e.format){case 1:return e.glyphs.indexOf(n);case 2:for(var t=e.ranges,c=0;c<t.length;c++){var a=t[c];if(n>=a.start&&n<=a.end){var r=n-a.start;return a.index+r}}break;default:return-1}return-1}function Cc(n,e){var t=g3(n,e.coverage);return t===-1?null:n+e.deltaGlyphId}function Pc(n,e){var t=g3(n,e.coverage);return t===-1?null:e.substitute[t]}function c4(n,e){for(var t=[],c=0;c<n.length;c++){var a=n[c],r=e.current;r=Array.isArray(r)?r[0]:r;var s=g3(r,a);s!==-1&&t.push(s)}return t.length!==n.length?-1:t}function Ec(n,e){var t=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(n.context.length<t)return[];var c=c4(e.inputCoverage,n);if(c===-1)return[];var a=e.inputCoverage.length-1;if(n.lookahead.length<e.lookaheadCoverage.length)return[];for(var r=n.lookahead.slice(a);r.length&&i2(r[0].char);)r.shift();var s=new E0(r,0),i=c4(e.lookaheadCoverage,s),o=[].concat(n.backtrack);for(o.reverse();o.length&&i2(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new E0(o,0),h=c4(e.backtrackCoverage,l),f=c.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,u=[];if(f)for(var d=0;d<e.lookupRecords.length;d++)for(var m=e.lookupRecords[d],p=m.lookupListIndex,v=this.getLookupByIndex(p),g=0;g<v.subtables.length;g++){var M=v.subtables[g],y=this.getLookupMethod(v,M),b=this.getSubstitutionType(v,M);if(b==="12")for(var w=0;w<c.length;w++){var x=n.get(w),z=y(x);z&&u.push(z)}}return u}function Tc(n,e){var t=n.current,c=g3(t,e.coverage);if(c===-1)return null;for(var a,r=e.ligatureSets[c],s=0;s<r.length;s++){a=r[s];for(var i=0;i<a.components.length;i++){var o=n.lookahead[i],l=a.components[i];if(o!==l)break;if(i===a.components.length-1)return a}}return null}function Ic(n,e){var t=g3(n,e.coverage);return t===-1?null:e.sequences[t]}y0.prototype.getDefaultScriptFeaturesIndexes=function(){for(var n=this.font.tables.gsub.scripts,e=0;e<n.length;e++){var t=n[e];if(t.tag==="DFLT")return t.script.defaultLangSys.featureIndexes}return[]};y0.prototype.getScriptFeaturesIndexes=function(n){var e=this.font.tables;if(!e.gsub)return[];if(!n)return this.getDefaultScriptFeaturesIndexes();for(var t=this.font.tables.gsub.scripts,c=0;c<t.length;c++){var a=t[c];if(a.tag===n&&a.script.defaultLangSys)return a.script.defaultLangSys.featureIndexes;var r=a.langSysRecords;if(r)for(var s=0;s<r.length;s++){var i=r[s];if(i.tag===n){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};y0.prototype.mapTagsToFeatures=function(n,e){for(var t={},c=0;c<n.length;c++){var a=n[c].tag,r=n[c].feature;t[a]=r}this.features[e].tags=t};y0.prototype.getScriptFeatures=function(n){var e=this.features[n];if(this.features.hasOwnProperty(n))return e;var t=this.getScriptFeaturesIndexes(n);if(!t)return null;var c=this.font.tables.gsub;return e=t.map(function(a){return c.features[a]}),this.features[n]=e,this.mapTagsToFeatures(e,n),e};y0.prototype.getSubstitutionType=function(n,e){var t=n.lookupType.toString(),c=e.substFormat.toString();return t+c};y0.prototype.getLookupMethod=function(n,e){var t=this,c=this.getSubstitutionType(n,e);switch(c){case"11":return function(a){return Cc.apply(t,[a,e])};case"12":return function(a){return Pc.apply(t,[a,e])};case"63":return function(a){return Ec.apply(t,[a,e])};case"41":return function(a){return Tc.apply(t,[a,e])};case"21":return function(a){return Ic.apply(t,[a,e])};default:throw new Error("lookupType: "+n.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};y0.prototype.lookupFeature=function(n){var e=n.contextParams,t=e.index,c=this.getFeature({tag:n.tag,script:n.script});if(!c)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+n.tag+"' for script '"+n.script+"'.");for(var a=this.getFeatureLookups(c),r=[].concat(e.context),s=0;s<a.length;s++)for(var i=a[s],o=this.getLookupSubtables(i),l=0;l<o.length;l++){var h=o[l],f=this.getSubstitutionType(i,h),u=this.getLookupMethod(i,h),d=void 0;switch(f){case"11":d=u(e.current),d&&r.splice(t,1,new M2({id:11,tag:n.tag,substitution:d}));break;case"12":d=u(e.current),d&&r.splice(t,1,new M2({id:12,tag:n.tag,substitution:d}));break;case"63":d=u(e),Array.isArray(d)&&d.length&&r.splice(t,1,new M2({id:63,tag:n.tag,substitution:d}));break;case"41":d=u(e),d&&r.splice(t,1,new M2({id:41,tag:n.tag,substitution:d}));break;case"21":d=u(e.current),d&&r.splice(t,1,new M2({id:21,tag:n.tag,substitution:d}));break}e=new E0(r,t),!(Array.isArray(d)&&!d.length)&&(d=null)}return r.length?r:null};y0.prototype.supports=function(n){if(!n.script)return!1;this.getScriptFeatures(n.script);var e=this.features.hasOwnProperty(n.script);if(!n.tag)return e;var t=this.features[n.script].some(function(c){return c.tag===n.tag});return e&&t};y0.prototype.getLookupSubtables=function(n){return n.subtables||null};y0.prototype.getLookupByIndex=function(n){var e=this.font.tables.gsub.lookups;return e[n]||null};y0.prototype.getFeatureLookups=function(n){return n.lookupListIndexes.map(this.getLookupByIndex.bind(this))};y0.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var t=this.features[e.script];return t?t.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function Hc(n){var e=n.current,t=n.get(-1);return t===null&&s2(e)||!s2(t)&&s2(e)}function Vc(n){var e=n.get(1);return e===null||!s2(e)}var Oc={startCheck:Hc,endCheck:Vc};function Fc(n){var e=n.current,t=n.get(-1);return(s2(e)||i2(e))&&!s2(t)}function Dc(n){var e=n.get(1);switch(!0){case e===null:return!0;case(!s2(e)&&!i2(e)):var t=Ac(e);if(!t)return!0;if(t){var c=!1;if(c=n.lookahead.some(function(a){return s2(a)||i2(a)}),!c)return!0}break;default:return!1}}var Rc={startCheck:Fc,endCheck:Dc};function qc(n,e,t){e[t].setState(n.tag,n.substitution)}function Uc(n,e,t){e[t].setState(n.tag,n.substitution)}function Nc(n,e,t){n.substitution.forEach(function(c,a){var r=e[t+a];r.setState(n.tag,c)})}function $c(n,e,t){var c=e[t];c.setState(n.tag,n.substitution.ligGlyph);for(var a=n.substitution.components.length,r=0;r<a;r++)c=e[t+r+1],c.setState("deleted",!0)}var P7={11:qc,12:Uc,63:Nc,41:$c};function z4(n,e,t){n instanceof M2&&P7[n.id]&&P7[n.id](n,e,t)}function _c(n){for(var e=[].concat(n.backtrack),t=e.length-1;t>=0;t--){var c=e[t],a=z8(c),r=i2(c);if(!a&&!r)return!0;if(a)return!1}return!1}function Bc(n){if(z8(n.current))return!1;for(var e=0;e<n.lookahead.length;e++){var t=n.lookahead[e],c=i2(t);if(!c)return!0}return!1}function Gc(n){var e=this,t="arab",c=this.featuresTags[t],a=this.tokenizer.getRangeTokens(n);if(a.length!==1){var r=new E0(a.map(function(i){return i.getState("glyphIndex")}),0),s=new E0(a.map(function(i){return i.char}),0);a.forEach(function(i,o){if(!i2(i.char)){r.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;_c(s)&&(l|=1),Bc(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(c.indexOf(h)!==-1){var f=e.query.lookupFeature({tag:h,script:t,contextParams:r});if(f instanceof Error)return console.info(f.message);f.forEach(function(u,d){u instanceof M2&&(z4(u,a,d),r.context[d]=u.substitution)})}}})}}function E7(n,e){var t=n.map(function(c){return c.activeState.value});return new E0(t,e||0)}function jc(n){var e=this,t="arab",c=this.tokenizer.getRangeTokens(n),a=E7(c);a.context.forEach(function(r,s){a.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:t,contextParams:a});i.length&&(i.forEach(function(o){return z4(o,c,s)}),a=E7(c))})}function Wc(n){var e=n.current,t=n.get(-1);return t===null&&K3(e)||!K3(t)&&K3(e)}function Xc(n){var e=n.get(1);return e===null||!K3(e)}var Zc={startCheck:Wc,endCheck:Xc};function T7(n,e){var t=n.map(function(c){return c.activeState.value});return new E0(t,e||0)}function Yc(n){var e=this,t="latn",c=this.tokenizer.getRangeTokens(n),a=T7(c);a.context.forEach(function(r,s){a.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:t,contextParams:a});i.length&&(i.forEach(function(o){return z4(o,c,s)}),a=T7(c))})}function H0(n){this.baseDir=n||"ltr",this.tokenizer=new H1,this.featuresTags={}}H0.prototype.setText=function(n){this.text=n};H0.prototype.contextChecks={latinWordCheck:Zc,arabicWordCheck:Oc,arabicSentenceCheck:Rc};function a4(n){var e=this.contextChecks[n+"Check"];return this.tokenizer.registerContextChecker(n,e.startCheck,e.endCheck)}function Kc(){return a4.call(this,"latinWord"),a4.call(this,"arabicWord"),a4.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Jc(){var n=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(t){var c=n.tokenizer.getRangeTokens(t);n.tokenizer.replaceRange(t.startIndex,t.endOffset,c.reverse())})}H0.prototype.registerFeatures=function(n,e){var t=this,c=e.filter(function(a){return t.query.supports({script:n,tag:a})});this.featuresTags.hasOwnProperty(n)?this.featuresTags[n]=this.featuresTags[n].concat(c):this.featuresTags[n]=c};H0.prototype.applyFeatures=function(n,e){if(!n)throw new Error("No valid font was provided to apply features");this.query||(this.query=new y0(n));for(var t=0;t<e.length;t++){var c=e[t];this.query.supports({script:c.script})&&this.registerFeatures(c.script,c.tags)}};H0.prototype.registerModifier=function(n,e,t){this.tokenizer.registerModifier(n,e,t)};function k4(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Qc(){var n=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){k4.call(this);var t=this.tokenizer.getContextRanges("arabicWord");t.forEach(function(c){Gc.call(n,c)})}}function ea(){var n=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("rlig")!==-1){k4.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(a){jc.call(n,a)})}}}function ta(){var n=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("liga")!==-1){k4.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(a){Yc.call(n,a)})}}}H0.prototype.checkContextReady=function(n){return!!this.tokenizer.getContext(n)};H0.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Qc.call(this),ea.call(this)),this.checkContextReady("latinWord")&&ta.call(this),this.checkContextReady("arabicSentence")&&Jc.call(this)};H0.prototype.processText=function(n){(!this.text||this.text!==n)&&(this.setText(n),Kc.call(this),this.applyFeaturesToContexts())};H0.prototype.getBidiText=function(n){return this.processText(n),this.tokenizer.getText()};H0.prototype.getTextGlyphs=function(n){this.processText(n);for(var e=[],t=0;t<this.tokenizer.tokens.length;t++){var c=this.tokenizer.tokens[t];if(!c.state.deleted){var a=c.activeState.value;e.push(Array.isArray(a)?a[0]:a)}}return e};function x1(n){n=n||{},n.tables=n.tables||{},n.empty||(i3(n.familyName,"When creating a new Font object, familyName is required."),i3(n.styleName,"When creating a new Font object, styleName is required."),i3(n.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),i3(n.ascender,"When creating a new Font object, ascender is required."),i3(n.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:n.familyName||" "},fontSubfamily:{en:n.styleName||" "},fullName:{en:n.fullName||n.familyName+" "+n.styleName},postScriptName:{en:n.postScriptName||(n.familyName+n.styleName).replace(/\s/g,"")},designer:{en:n.designer||" "},designerURL:{en:n.designerURL||" "},manufacturer:{en:n.manufacturer||" "},manufacturerURL:{en:n.manufacturerURL||" "},license:{en:n.license||" "},licenseURL:{en:n.licenseURL||" "},version:{en:n.version||"Version 0.1"},description:{en:n.description||" "},copyright:{en:n.copyright||" "},trademark:{en:n.trademark||" "}},this.unitsPerEm=n.unitsPerEm||1e3,this.ascender=n.ascender,this.descender=n.descender,this.createdTimestamp=n.createdTimestamp,this.tables=Object.assign(n.tables,{os2:Object.assign({usWeightClass:n.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:n.widthClass||this.usWidthClasses.MEDIUM,fsSelection:n.fsSelection||this.fsSelectionValues.REGULAR},n.tables.os2)})),this.supported=!0,this.glyphs=new B0.GlyphSet(this,n.glyphs||[]),this.encoding=new $7(this),this.position=new p3(this),this.substitution=new g0(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 b8(this)}})}x1.prototype.hasChar=function(n){return this.encoding.charToGlyphIndex(n)!==null};x1.prototype.charToGlyphIndex=function(n){return this.encoding.charToGlyphIndex(n)};x1.prototype.charToGlyph=function(n){var e=this.charToGlyphIndex(n),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t};x1.prototype.updateFeatures=function(n){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(t){return n[t]})}:e})};x1.prototype.stringToGlyphs=function(n,e){var t=this,c=new H0,a=function(f){return t.charToGlyphIndex(f.char)};c.registerModifier("glyphIndex",null,a);var r=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;c.applyFeatures(this,r);for(var s=c.getTextGlyphs(n),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};x1.prototype.nameToGlyphIndex=function(n){return this.glyphNames.nameToGlyphIndex(n)};x1.prototype.nameToGlyph=function(n){var e=this.nameToGlyphIndex(n),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t};x1.prototype.glyphIndexToName=function(n){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(n):""};x1.prototype.getKerningValue=function(n,e){n=n.index||n,e=e.index||e;var t=this.position.defaultKerningTables;return t?this.position.getKerningValue(t,n,e):this.kerningPairs[n+","+e]||0};x1.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};x1.prototype.forEachGlyph=function(n,e,t,c,a,r){e=e!==void 0?e:0,t=t!==void 0?t:0,c=c!==void 0?c:72,a=Object.assign({},this.defaultRenderOptions,a);var s=1/this.unitsPerEm*c,i=this.stringToGlyphs(n,a),o;if(a.kerning){var l=a.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,a.language)}for(var h=0;h<i.length;h+=1){var f=i[h];if(r.call(this,f,e,t,c,a),f.advanceWidth&&(e+=f.advanceWidth*s),a.kerning&&h<i.length-1){var u=o?this.position.getKerningValue(o,f.index,i[h+1].index):this.getKerningValue(f,i[h+1]);e+=u*s}a.letterSpacing?e+=a.letterSpacing*c:a.tracking&&(e+=a.tracking/1e3*c)}return e};x1.prototype.getPath=function(n,e,t,c,a){var r=new $1;return this.forEachGlyph(n,e,t,c,a,function(s,i,o,l){var h=s.getPath(i,o,l,a,this);r.extend(h)}),r};x1.prototype.getPaths=function(n,e,t,c,a){var r=[];return this.forEachGlyph(n,e,t,c,a,function(s,i,o,l){var h=s.getPath(i,o,l,a,this);r.push(h)}),r};x1.prototype.getAdvanceWidth=function(n,e,t){return this.forEachGlyph(n,0,0,e,t,function(){})};x1.prototype.draw=function(n,e,t,c,a,r){this.getPath(e,t,c,a,r).draw(n)};x1.prototype.drawPoints=function(n,e,t,c,a,r){this.forEachGlyph(e,t,c,a,r,function(s,i,o,l){s.drawPoints(n,i,o,l)})};x1.prototype.drawMetrics=function(n,e,t,c,a,r){this.forEachGlyph(e,t,c,a,r,function(s,i,o,l){s.drawMetrics(n,i,o,l)})};x1.prototype.getEnglishName=function(n){var e=this.names[n];if(e)return e.en};x1.prototype.validate=function(){var n=this;function e(c,a){}function t(c){var a=n.getEnglishName(c);a&&a.trim().length>0}t("fontFamily"),t("weightName"),t("manufacturer"),t("copyright"),t("version"),this.unitsPerEm>0};x1.prototype.toTables=function(){return Nt.fontToTable(this)};x1.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};x1.prototype.toArrayBuffer=function(){for(var n=this.toTables(),e=n.encode(),t=new ArrayBuffer(e.length),c=new Uint8Array(t),a=0;a<e.length;a++)c[a]=e[a];return t};x1.prototype.download=function(n){var e=this.getEnglishName("fontFamily"),t=this.getEnglishName("fontSubfamily");n=n||e.replace(/\s/g,"")+"-"+t+".otf";var c=this.toArrayBuffer();if(_t())if(window.URL=window.URL||window.webkitURL,window.URL){var a=new DataView(c),r=new Blob([a],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(r),s.download=n;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=W6(),l=Bt(c);o.writeFileSync(n,l)}};x1.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};x1.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};x1.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function k8(n,e){var t=JSON.stringify(n),c=256;for(var a in e){var r=parseInt(a);if(!(!r||r<256)){if(JSON.stringify(e[a])===t)return r;c<=r&&(c=r+1)}}return e[c]=n,c}function na(n,e,t){var c=k8(e.name,t);return[{name:"tag_"+n,type:"TAG",value:e.tag},{name:"minValue_"+n,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+n,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+n,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+n,type:"USHORT",value:0},{name:"nameID_"+n,type:"USHORT",value:c}]}function ca(n,e,t){var c={},a=new W.Parser(n,e);return c.tag=a.parseTag(),c.minValue=a.parseFixed(),c.defaultValue=a.parseFixed(),c.maxValue=a.parseFixed(),a.skip("uShort",1),c.name=t[a.parseUShort()]||{},c}function aa(n,e,t,c){for(var a=k8(e.name,c),r=[{name:"nameID_"+n,type:"USHORT",value:a},{name:"flags_"+n,type:"USHORT",value:0}],s=0;s<t.length;++s){var i=t[s].tag;r.push({name:"axis_"+n+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return r}function ra(n,e,t,c){var a={},r=new W.Parser(n,e);a.name=c[r.parseUShort()]||{},r.skip("uShort",1),a.coordinates={};for(var s=0;s<t.length;++s)a.coordinates[t[s].tag]=r.parseFixed();return a}function sa(n,e){var t=new B.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:n.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:n.instances.length},{name:"instanceSize",type:"USHORT",value:4+n.axes.length*4}]);t.offsetToData=t.sizeOf();for(var c=0;c<n.axes.length;c++)t.fields=t.fields.concat(na(c,n.axes[c],e));for(var a=0;a<n.instances.length;a++)t.fields=t.fields.concat(aa(a,n.instances[a],n.axes,e));return t}function ia(n,e,t){var c=new W.Parser(n,e),a=c.parseULong();n1.argument(a===65536,"Unsupported fvar table version.");var r=c.parseOffset16();c.skip("uShort",1);for(var s=c.parseUShort(),i=c.parseUShort(),o=c.parseUShort(),l=c.parseUShort(),h=[],f=0;f<s;f++)h.push(ca(n,e+r+f*i,t));for(var u=[],d=e+r+s*i,m=0;m<o;m++)u.push(ra(n,d+m*l,h,t));return{axes:h,instances:u}}var oa={make:sa,parse:ia},la=function(){return{coverage:this.parsePointer(I.coverage),attachPoints:this.parseList(I.pointer(I.uShortList))}},ha=function(){var n=this.parseUShort();if(n1.argument(n===1||n===2||n===3,"Unsupported CaretValue table version."),n===1)return{coordinate:this.parseShort()};if(n===2)return{pointindex:this.parseShort()};if(n===3)return{coordinate:this.parseShort()}},ua=function(){return this.parseList(I.pointer(ha))},fa=function(){return{coverage:this.parsePointer(I.coverage),ligGlyphs:this.parseList(I.pointer(ua))}},da=function(){return this.parseUShort(),this.parseList(I.pointer(I.coverage))};function pa(n,e){e=e||0;var t=new I(n,e),c=t.parseVersion(1);n1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var a={version:c,classDef:t.parsePointer(I.classDef),attachList:t.parsePointer(la),ligCaretList:t.parsePointer(fa),markAttachClassDef:t.parsePointer(I.classDef)};return c>=1.2&&(a.markGlyphSets=t.parsePointer(da)),a}var ma={parse:pa},T0=new Array(10);T0[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{posFormat:1,coverage:this.parsePointer(I.coverage),value:this.parseValueRecord()};if(t===2)return{posFormat:2,coverage:this.parsePointer(I.coverage),values:this.parseValueRecordList()};n1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};T0[2]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();n1.assert(t===1||t===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(I.coverage),a=this.parseUShort(),r=this.parseUShort();if(t===1)return{posFormat:t,coverage:c,valueFormat1:a,valueFormat2:r,pairSets:this.parseList(I.pointer(I.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(a),value2:this.parseValueRecord(r)}})))};if(t===2){var s=this.parsePointer(I.classDef),i=this.parsePointer(I.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:t,coverage:c,valueFormat1:a,valueFormat2:r,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,I.list(l,function(){return{value1:this.parseValueRecord(a),value2:this.parseValueRecord(r)}}))}}};T0[3]=function(){return{error:"GPOS Lookup 3 not supported"}};T0[4]=function(){return{error:"GPOS Lookup 4 not supported"}};T0[5]=function(){return{error:"GPOS Lookup 5 not supported"}};T0[6]=function(){return{error:"GPOS Lookup 6 not supported"}};T0[7]=function(){return{error:"GPOS Lookup 7 not supported"}};T0[8]=function(){return{error:"GPOS Lookup 8 not supported"}};T0[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function va(n,e){e=e||0;var t=new I(n,e),c=t.parseVersion(1);return n1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(T0)}:{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(T0),variations:t.parseFeatureVariationsList()}}var ga=new Array(10);function ya(n){return new B.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new B.ScriptList(n.scripts)},{name:"features",type:"TABLE",value:new B.FeatureList(n.features)},{name:"lookups",type:"TABLE",value:new B.LookupList(n.lookups,ga)}])}var ba={parse:va,make:ya};function Ma(n){var e={};n.skip("uShort");var t=n.parseUShort();n1.argument(t===0,"Unsupported kern sub-table version."),n.skip("uShort",2);var c=n.parseUShort();n.skip("uShort",3);for(var a=0;a<c;a+=1){var r=n.parseUShort(),s=n.parseUShort(),i=n.parseShort();e[r+","+s]=i}return e}function xa(n){var e={};n.skip("uShort");var t=n.parseULong();t>1&&console.warn("Only the first kern subtable is supported."),n.skip("uLong");var c=n.parseUShort(),a=c&255;if(n.skip("uShort"),a===0){var r=n.parseUShort();n.skip("uShort",3);for(var s=0;s<r;s+=1){var i=n.parseUShort(),o=n.parseUShort(),l=n.parseShort();e[i+","+o]=l}}return e}function wa(n,e){var t=new W.Parser(n,e),c=t.parseUShort();if(c===0)return Ma(t);if(c===1)return xa(t);throw new Error("Unsupported kern table version ("+c+").")}var za={parse:wa};function ka(n,e,t,c){for(var a=new W.Parser(n,e),r=c?a.parseUShort:a.parseULong,s=[],i=0;i<t+1;i+=1){var o=r.call(a);c&&(o*=2),s.push(o)}return s}var La={parse:ka};function I7(n,e){for(var t=[],c=12,a=0;a<e;a+=1){var r=W.getTag(n,c),s=W.getULong(n,c+4),i=W.getULong(n,c+8),o=W.getULong(n,c+12);t.push({tag:r,checksum:s,offset:i,length:o,compression:!1}),c+=16}return t}function Sa(n,e){for(var t=[],c=44,a=0;a<e;a+=1){var r=W.getTag(n,c),s=W.getULong(n,c+4),i=W.getULong(n,c+8),o=W.getULong(n,c+12),l=void 0;i<o?l="WOFF":l=!1,t.push({tag:r,offset:s,compression:l,compressedLength:i,length:o}),c+=20}return t}function F1(n,e){if(e.compression==="WOFF"){var t=new Uint8Array(n.buffer,e.offset+2,e.compressedLength-2),c=new Uint8Array(e.length);if(y9(t,c),c.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var a=new DataView(c.buffer,0);return{data:a,offset:0}}else return{data:n,offset:e.offset}}function L8(n,e){e=e??{};var t,c,a=new x1({empty:!0}),r=new DataView(n,0),s,i=[],o=W.getTag(r,0);if(o==="\0\0\0"||o==="true"||o==="typ1")a.outlinesFormat="truetype",s=W.getUShort(r,4),i=I7(r,s);else if(o==="OTTO")a.outlinesFormat="cff",s=W.getUShort(r,4),i=I7(r,s);else if(o==="wOFF"){var l=W.getTag(r,4);if(l==="\0\0\0")a.outlinesFormat="truetype";else if(l==="OTTO")a.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+o);s=W.getUShort(r,12),i=Sa(r,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,f,u,d,m,p,v,g,M,y,b,w,x=0;x<s;x+=1){var z=i[x],L=void 0;switch(z.tag){case"cmap":L=F1(r,z),a.tables.cmap=N7.parse(L.data,L.offset),a.encoding=new _7(a.tables.cmap);break;case"cvt ":L=F1(r,z),w=new W.Parser(L.data,L.offset),a.tables.cvt=w.parseShortList(z.length/2);break;case"fvar":f=z;break;case"fpgm":L=F1(r,z),w=new W.Parser(L.data,L.offset),a.tables.fpgm=w.parseByteList(z.length);break;case"head":L=F1(r,z),a.tables.head=Q7.parse(L.data,L.offset),a.unitsPerEm=a.tables.head.unitsPerEm,t=a.tables.head.indexToLocFormat;break;case"hhea":L=F1(r,z),a.tables.hhea=e8.parse(L.data,L.offset),a.ascender=a.tables.hhea.ascender,a.descender=a.tables.hhea.descender,a.numberOfHMetrics=a.tables.hhea.numberOfHMetrics;break;case"hmtx":v=z;break;case"ltag":L=F1(r,z),c=n8.parse(L.data,L.offset);break;case"maxp":L=F1(r,z),a.tables.maxp=c8.parse(L.data,L.offset),a.numGlyphs=a.tables.maxp.numGlyphs;break;case"name":y=z;break;case"OS/2":L=F1(r,z),a.tables.os2=f4.parse(L.data,L.offset);break;case"post":L=F1(r,z),a.tables.post=l8.parse(L.data,L.offset),a.glyphNames=new y4(a.tables.post);break;case"prep":L=F1(r,z),w=new W.Parser(L.data,L.offset),a.tables.prep=w.parseByteList(z.length);break;case"glyf":u=z;break;case"loca":M=z;break;case"CFF ":h=z;break;case"kern":g=z;break;case"GDEF":d=z;break;case"GPOS":m=z;break;case"GSUB":p=z;break;case"meta":b=z;break}}var S=F1(r,y);if(a.tables.name=o8.parse(S.data,S.offset,c),a.names=a.tables.name,u&&M){var k=t===0,E=F1(r,M),V=La.parse(E.data,E.offset,a.numGlyphs,k),T=F1(r,u);a.glyphs=v8.parse(T.data,T.offset,V,a,e)}else if(h){var H=F1(r,h);J7.parse(H.data,H.offset,a,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var D=F1(r,v);if(t8.parse(a,D.data,D.offset,a.numberOfHMetrics,a.numGlyphs,a.glyphs,e),q9(a,e),g){var O=F1(r,g);a.kerningPairs=za.parse(O.data,O.offset)}else a.kerningPairs={};if(d){var R=F1(r,d);a.tables.gdef=ma.parse(R.data,R.offset)}if(m){var N=F1(r,m);a.tables.gpos=ba.parse(N.data,N.offset),a.position.init()}if(p){var q=F1(r,p);a.tables.gsub=h8.parse(q.data,q.offset)}if(f){var Y=F1(r,f);a.tables.fvar=oa.parse(Y.data,Y.offset,a.names)}if(b){var _=F1(r,b);a.tables.meta=u8.parse(_.data,_.offset),a.metas=a.tables.meta}return a}function S8(n,e){let t=n.tables?.os2?.sCapHeight;if(t&&t>0)return t/n.unitsPerEm*e;let c=m0(L4(n,"H",{size:e,font:"",halign:"left",valign:"baseline",spacing:1}).polys);return c?c[3]:n.ascender/n.unitsPerEm*e}var s5=class{constructor(e,t){this.sources=e;this.fallback=t;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let t=e||this.fallback||Object.keys(this.sources)[0];if(!t)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let c=this.parsed.get(t);if(c)return c;let a=i0(this.sources,t);if(!a)throw this.missing.add(t),new Error(`Font "${t}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let r=a instanceof Uint8Array?a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength):a,s=L8(r);return this.parsed.set(t,s),s}};function Aa(n,e,t){let c={kerning:!0};if(t.spacing===1)return{cmds:n.getPath(e,0,0,t.size,c).commands,advance:n.getAdvanceWidth(e,t.size,c)};let a=[],r=0,s=[...e];return s.forEach((i,o)=>{a.push(...n.getPath(i,r,0,t.size,c).commands),r+=n.getAdvanceWidth(i,t.size,c)*(o<s.length-1?t.spacing:1)}),{cmds:a,advance:r}}function L4(n,e,t){let{cmds:c,advance:a}=Aa(n,e,t),r=c.map(i=>i.type==="Z"?i:i.type==="C"?{...i,y1:-i.y1,y2:-i.y2,y:-i.y}:i.type==="Q"?{...i,y1:-i.y1,y:-i.y}:{...i,y:-i.y}),s=S2(r,Math.max(.005,t.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:a}}function i5(n,e,t){if(!e)return[];let c=n.get(t.font),{polys:a,advance:r}=L4(c,e,t),s=Z(a),i=m0(s);if(!i)return[];let o=t.halign==="center"?-r/2:t.halign==="right"?-r:0,l=t.valign==="top"?-i[3]:t.valign==="center"?-(i[1]+i[3])/2:t.valign==="bottom"?-i[1]:t.valign==="cap"?-S8(c,t.size)/2:0;return s.map(h=>h.map(([f,u])=>[f+o,u+l]))}function S4(n,e,t){let c=n.get(t.font),{polys:a,advance:r}=L4(c,e,t),s=m0(a)??[0,0,0,0];return{advance:r,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:c.ascender/c.unitsPerEm*t.size,descent:c.descender/c.unitsPerEm*t.size,cap:S8(c,t.size)}}var A8=Math.PI/180,A4=128,I4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],Ca={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function H4(n,e){if(!n||i0(T4,n)!==void 0)return;let t=n.split("\\").join("/"),c=e.split("\\").join("/");if(c.startsWith("/")||/^[A-Za-z]:\//.test(c))return;let a=t.lastIndexOf("/");if(a<0)return;let r=[...t.slice(0,a).split("/"),...c.split("/")],s=[];for(let i of r)i===".."&&s.length&&s[s.length-1]!==".."?s.pop():i!=="."&&i!==""&&s.push(i);return(t.startsWith("/")?"/":"")+s.join("/")}var Pa=100,Ea={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},q2=4,C8=8,Ta=n=>{let e=Pa,t=c=>{for(let a of c.values()){for(let r of a.regions)e+=r.length;for(let r of a.lines)e+=r.length}};t(n.layers);for(let c of n.parts)t(c.layers);return e},_1=class{constructor(e,t){this.parent=e;this.caller=t;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let t=this,c=e.startsWith("$");for(;t;){if(t.vars.has(e))return{found:!0,value:t.vars.get(e)};t=c?t.caller??t.parent:t.parent}return{found:!1}}fn(e){for(let t=this;t;t=t.parent){let c=t.fns.get(e);if(c)return c}}mod(e){for(let t=this;t;t=t.parent){let c=t.mods.get(e);if(c)return c}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let t=[];for(let c=this;c;c=c.parent)t.push(...c[e].keys());return t}},C4=n=>n?`.${n}`:"",P4=(n,e)=>n==="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`,Ia={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."},E4=["echo","assert","text_width","text_metrics","text_size","finger_count"];function w2(n,e){let t="",c=Math.min(2,Math.floor(n.length/3))+.5;for(let a of new Set(e)){if(a===n)continue;let r=a.toLowerCase()===n.toLowerCase()?0:Ha(n,a);r<c&&([t,c]=[a,r])}return t?` Did you mean "${t}"?`:""}function Ha(n,e){if(Math.abs(n.length-e.length)>2)return 3;let t=Array.from({length:n.length+1},(c,a)=>[a,...Array(e.length).fill(0)]);for(let c=1;c<=e.length;c++)t[0][c]=c;for(let c=1;c<=n.length;c++)for(let a=1;a<=e.length;a++)t[c][a]=Math.min(t[c-1][a]+1,t[c][a-1]+1,t[c-1][a-1]+(n[c-1]===e[a-1]?0:1)),c>1&&a>1&&n[c-1]===e[a-2]&&n[c-2]===e[a-1]&&(t[c][a]=Math.min(t[c][a],t[c-2][a-2]+1));return t[n.length][e.length]}var T4=U0,o5=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=$5;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.echoes=[];this.warnings=[];this.layers=new Map(I4.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={...Ca,...e.limits},this.builtins=this.makeBuiltins()}run(e){let t=new _1,c={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[i,o]of Object.entries(c))t.vars.set(i,o);let a=new _1(t),r=this.block(e.body,a,!0),s=a.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 (${v0(this.unscaled,!1)})`),{shape:r,globals:a,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,steps:this.stepNames}}tick(e,t=1){if(!((this.steps+=t)<=this.maxSteps))throw new G(`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,t){let c=H4(t.file,e),a=e,r=i0(T4,e);if(r===void 0&&c!==void 0){let i=this.loaded.get(c);if(i)return i;r=this.opts.resolve?.(c),typeof r=="string"&&(a=c)}if(a===e){let i=this.loaded.get(e);if(i)return i;r??(r=this.opts.resolve?.(e))}if(typeof r!="string")throw new G(`Library <${e}> not found`,t);this.loaded.set(a,{body:[]});let{program:s}=Y0(r,a);return this.loaded.set(a,s),s}hoist(e,t){for(let c of e)if((c.kind==="module"||c.kind==="function")&&(c.pos.file===void 0||i0(T4,c.pos.file)===void 0)&&(c.kind==="module"?i0(this.builtins,c.name)!==void 0:i0(G2,c.name)!==void 0||E4.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${v0(c.pos,!1)})`),c.kind==="module")t.mods.set(c.name,{params:c.params,body:c.body,env:t,pos:c.pos});else if(c.kind==="function")t.fns.set(c.name,{params:c.params,body:c.body,env:t,pos:c.pos});else if(c.kind==="use"&&!c.include){this.enter(this.using,c.path,c.pos,"use");try{let a=this.included(this.load(c.path,c.pos).body,new Set([c.path])),r=new _1(t);this.hoist(a,r);for(let s of a)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,r),r);for(let[s,i]of r.mods)this.clash("module",s,t.mods.get(s),i),t.mods.set(s,i);for(let[s,i]of r.fns)this.clash("function",s,t.fns.get(s),i),t.fns.set(s,i)}finally{this.using.pop()}}}clash(e,t,c,a){!c||c.body===a.body||!c.pos?.file||!a.pos?.file||c.pos.file===a.pos.file||this.clashed.has(`${e} ${t}`)||(this.clashed.add(`${e} ${t}`),this.warn(`${e} ${t} is defined in <${c.pos.file}> (line ${c.pos.line}) and in <${a.pos.file}> (line ${a.pos.line}); the one in <${a.pos.file}> is used. Rename one to use both.`))}childKey(e){let t=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[f,u]of l.vars)f.startsWith("$")&&!t.has(f)&&t.set(f,u)})(e,0);let a=[...t].sort(([l],[h])=>l<h?-1:1),r=[],s=0,i=[];for(let l=a.length-1;l>=0;l--)i.push({text:";"},a[l][1],{text:`${a[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 f=l.length-1;f>=0;f--)i.push(l[f],{text:","});h="["}else if(x0(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(t0(l)){i.push({text:"}"});let f=[...l.fields];for(let u=f.length-1;u>=0;u--)i.push(f[u][1],{text:`${f[u][0]}=`});h="{"}else return"";r.push(h),s+=h.length}let o=r.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${this.layerDefs}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.stepNames.length},${this.warnings.length},${this.copies},${this.layerDefs}`}enter(e,t,c,a){if(e.includes(t)){let r=[...e.slice(e.indexOf(t)),t].map(s=>`<${s}>`);throw new G(r.length===2?`Library ${r[0]} ${a}s itself`:`Libraries ${a} each other in a loop: ${r.join(" \u2192 ")}`,c)}e.push(t)}included(e,t){let c=[];for(let a of e)if(a.kind!=="use"||!a.include)c.push(a);else if(!t.has(a.path)){t.add(a.path);for(let r of this.included(this.load(a.path,a.pos).body,t))c.push(r)}return c}assign(e,t,c){c.vars.set(e,t)}block(e,t,c=!1){this.hoist(e,t);let a=[];for(let r of e){let s=this.stmt(r,t,c);s&&!g6(s)&&a.push(s)}return a.length===1?a[0]:q0(a)}stmt(e,t,c=!1){switch(this.tick(e.pos),e.kind){case"assign":{let a=this.opts.overrides,r=c&&a&&Object.prototype.hasOwnProperty.call(a,e.name)?a[e.name]:this.expr(e.value,t);return this.assign(e.name,r,t),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,t)}finally{this.including.pop()}}case"block":return this.block(e.body,new _1(t));case"if":return T1(this.expr(e.cond,t))?this.block(e.then,new _1(t)):this.block(e.else,new _1(t));case"let":{let a=new _1(t);return this.bindSeq(e.assigns,a),this.block(e.body,a)}case"for":{let a=[];return this.loop(e.assigns,t,r=>a.push(this.block(e.body,r))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:t,children:()=>q0(a),childList:()=>a,childSeq:()=>a,childItems:()=>a}):q0(a)}case"call":if(e.modifier==="*")return null;{let a=this.callModule(e,t);return e.modifier==="#"||e.modifier==="%"?t3(a,"guide"):a}}}bindSeq(e,t){for(let c of e)this.assign(c.name,this.expr(c.value,t),t)}iterable(e,t){if(x0(e))try{return b3(e,this.limits.maxListLength)}catch(c){throw new G(c.message,t)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,t,c,a=0,r=new _1(t)){if(a===e.length)return c(r);let s=e[a];for(let i of this.iterable(this.expr(s.value,r),s.pos)){this.tick(s.pos);let o=new _1(r);o.vars.set(s.name,i),this.loop(e,t,c,a+1,o)}}evalArgs(e,t,c){let a=[],r=new Map,s=[];for(let i of e){let o=this.expr(i.value,t);i.name===null?a.push(o):r.set(i.name,o),s.push({name:i.name,value:o})}return{pos:a,named:r,all:s,at:c}}bindParams(e,t,c,a,r){let s=e.map(i=>i.name);for(let[i,o]of t.named)i.startsWith("$")&&c.vars.set(i,o);e.forEach((i,o)=>{let l;t.named.has(i.name)?l=t.named.get(i.name):o<t.pos.length?l=t.pos[o]:l=i.default?this.expr(i.default,c):void 0,c.vars.set(i.name,l)});for(let i of t.named.keys())!i.startsWith("$")&&!s.includes(i)&&this.unknownArg(r,i,t.at,s);this.checkCount(r,e.length,t)}checkArgs(e,t){let c=H2(e);if(!c)return;let a=c.params.map(r=>r.name);if(!c.anyNamed)for(let r of t.named.keys())!r.startsWith("$")&&!a.includes(r)&&this.unknownArg(`${e}()`,r,t.at,a);c.rest||this.checkCount(`${e}()`,c.params.filter(r=>!r.named).length,t)}checkCount(e,t,c){c.pos.length>t&&this.warn(`${e}: takes ${t===0?"no":`at most ${t}`} positional argument${t===1?"":"s"}, got ${c.pos.length}; the rest are ignored (${v0(c.at,!1)})`)}unknownArg(e,t,c,a){this.warn(`${e}: unknown argument "${t}"${C4(w2(t,a))} (${v0(c,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,t){let c=e.args.findIndex(s=>s.name==="name"),a=c>=0?c:e.args.findIndex(s=>s.name===null);if(a<0)throw new G("call() needs the name of a module",e.pos);let r=this.expr(e.args[a].value,t);if(typeof r!="string")throw new G(`call() needs a module's name as a string, got ${Z1(r)}`,e.pos);if(r==="call")throw new G("call() can't call itself",e.pos);return this.callModule({...e,name:r,args:e.args.filter((s,i)=>i!==a)},t)}callModule(e,t){if(e.name==="call"&&!t.mod("call"))return this.callByName(e,t);let c=this.evalArgs(e.args,t,e.pos),a=t.mod(e.name);if(a){if(++this.depth>1e3)throw new G(P4("module",e.name),e.pos);try{let d=new _1(a.env,t);return this.bindParams(a.params,c,d,a.env,`${e.name}()`),d.children={stmts:e.children,env:t,module:e.name,pos:e.pos},d.vars.set("$children",this.childStmts(e.children).length),this.block(a.body,d)}catch(d){throw this.inCall(d,"module",e.name,e.pos)}finally{this.depth--}}let r=i0(this.builtins,e.name),s=i0(Ia,e.name);if(!r&&s)return this.warn(`${e.name}() is ignored: ${s} (${v0(e.pos,!1)})`),e.children.length?this.block(e.children,new _1(t,t)):W1();if(!r){let d=w2(e.name,[...t.names("mods"),...Object.keys(this.builtins)]);throw new G(`Unknown module ${e.name}().${d}`,e.pos)}this.checkArgs(e.name,c);let i=new _1(t,t);for(let[d,m]of c.named)d.startsWith("$")&&i.vars.set(d,m);let o=this.childStmts(e.children),l=()=>new _1(t,i),h={args:c,env:i,children:()=>e.children.length?this.block(e.children,l()):W1(),childList:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let p of e.children){let v=this.stmt(p,d);o.includes(p)&&m.push(v??W1())}return m},childItems:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let p of e.children){if(o.includes(p)&&p.kind==="for"&&!p.intersect){this.tick(p.pos),this.loop(p.assigns,d,g=>m.push(this.block(p.body,g)));continue}let v=this.stmt(p,d);o.includes(p)&&m.push(v??W1())}return m},childSeq:d=>{let m=l();this.hoist(e.children,m);let p=[];for(let v of e.children){let g=this.stmt(v,m);o.includes(v)&&(p.push(g??W1()),d(p.length-1,g??W1()))}return p}},f;try{f=r(h)}catch(d){if(d instanceof G||d instanceof RangeError)throw d;let m=new G(`${e.name}(): ${d.message}`,e.pos);throw m.call=e.name,m}let u=Ta(f);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new G(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 f}childStmts(e){return e.filter(t=>t.kind!=="assign"&&t.kind!=="module"&&t.kind!=="function"&&t.kind!=="use")}callFunction(e,t,c,a){if(++this.depth>2e3)throw new G(P4("function",a),t.at);try{this.tick(t.at);let r=A0(e)?e.scope:e.env,s=new _1(r,c);return this.bindParams(e.params,t,s,r,`${a}()`),this.expr(e.body,s)}catch(r){throw this.inCall(r,"function",a,t.at)}finally{this.depth--}}inCall(e,t,c,a){return e instanceof Error&&!(e instanceof G)&&e.message.includes("call stack")?new G(P4(t,c),a):(e instanceof G&&e.addFrame(t,c,a),e)}expr(e,t){switch(e.kind){case"num":return e.unit?this.length(e,t):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{let c=t.get(e.name);if(c.found)return c.value;let a=t.fn(e.name);if(a)return{type:"function",params:a.params,body:a.body,scope:a.env,name:e.name};if(e.name.startsWith("$"))return;throw new G(`Unknown variable "${e.name}"${C4(w2(e.name,[...t.names("vars"),...t.names("fns")]))}`,e.pos)}case"list":{let c=[];for(let a of e.items)this.listItem(a,t,c,e.pos);return this.charge(q2,e.pos),c}case"range":{let c=this.expr(e.start,t),a=this.expr(e.end,t),r=e.step?this.expr(e.step,t):1;if(typeof c!="number"||typeof a!="number"||typeof r!="number")throw new G("Range values must be numbers",e.pos);return{type:"range",start:c,step:r,end:a}}case"unary":{let c=this.expr(e.arg,t);return e.op==="!"?!T1(c):e.op==="+"?c:this.arith("*",-1,c,e.pos)}case"binary":{if(e.op==="&&")return T1(this.expr(e.left,t))&&T1(this.expr(e.right,t));if(e.op==="||")return T1(this.expr(e.left,t))||T1(this.expr(e.right,t));let c=this.expr(e.left,t),a=this.expr(e.right,t);if(e.op==="=="||e.op==="!=")return k2(c,a,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof c=="number"&&typeof a=="number"||typeof c=="string"&&typeof a=="string"))throw new G(`Can't compare ${Z1(c)} ${e.op} ${Z1(a)}`,e.pos);return e.op==="<"?c<a:e.op==="<="?c<=a:e.op===">"?c>a:c>=a}return this.arith(e.op,c,a,e.pos)}case"ternary":return T1(this.expr(e.cond,t))?this.expr(e.then,t):this.expr(e.else,t);case"index":{let c=this.expr(e.target,t),a=this.expr(e.index,t);if(t0(c)&&typeof a=="string")return c.fields.get(a);if(typeof a!="number")throw new G(`List index must be a number, got ${Z1(a)}`,e.pos);return Array.isArray(c)?c[Math.floor(a)]:typeof c=="string"?[...c][Math.floor(a)]:x0(c)?[c.start,c.step,c.end][Math.floor(a)]:void 0}case"record":return this.record(e,t);case"member":{let c=this.expr(e.target,t);if(t0(c))return c.fields.get(e.name);let a={x:0,y:1,z:2}[e.name];return Array.isArray(c)&&a!==void 0?c[a]:x0(c)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?c.start:e.name==="step"?c.step:c.end:void 0}case"call":return this.call(e,t);case"lambda":return{type:"function",params:e.params,body:e.body,scope:t};case"let":{let c=new _1(t);return this.bindSeq(e.assigns,c),this.expr(e.body,c)}case"chain":return this.expr(e.check,t),this.expr(e.body,t)}}listItem(e,t,c,a){switch(e.kind){case"item":{let r=this.expr(e.expr,t);this.grow(c,1,a),c.push(r);return}case"each":{let r=this.iterable(this.expr(e.expr,t),a);this.grow(c,r.length,a);for(let s of r)c.push(s);return}case"for":this.loop(e.assigns,t,r=>this.listItem(e.body,r,c,a));return;case"if":T1(this.expr(e.cond,t))?this.listItem(e.then,t,c,a):e.else&&this.listItem(e.else,t,c,a);return;case"let":{let r=new _1(t);this.bindSeq(e.assigns,r),this.listItem(e.body,r,c,a)}}}grow(e,t,c){if(e.length+t>this.limits.maxListLength)throw new G(`a list of ${e.length+t} items is more than the limit of ${this.limits.maxListLength}`,c);this.charge(t,c)}charge(e,t){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new G(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,t)}call(e,t){if(e.callee.kind==="var"){let a=e.callee.name,r=t.get(a),s=r.found&&!A0(r.value);if(!r.found||s&&this.callable(a,t)){let i=t.fn(a);if(i)return this.callFunction(i,this.evalArgs(e.args,t,e.pos),t,a);let o=this.specialFunction(a,e,t);if(o.handled)return o.value;let l=i0(G2,a);if(l){let h=this.evalArgs(e.args,t,e.pos);this.checkArgs(a,h);for(let m of t6(l,h.pos,h.named))this.warn(`${a}(): "${m}" is given by position and by name; the named value is used (${v0(e.pos,!1)})`);let f={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,p)=>{if(!A0(m))throw new Error(`${a}() needs a function, got ${Z1(m)}`);return this.callFunction(m,{pos:p,named:new Map,all:p.map(v=>({name:null,value:v})),at:e.pos},t,"function")}},u=n6(l,h.pos,h.named);this.tick(e.pos,c6(a,u,this.limits.maxListLength));let d;try{d=l.run(u,f)}catch(m){if(m instanceof G)throw m;let p=new G(m instanceof RangeError?`${a}(): the result is too large`:m.message,e.pos);throw p.call=a,p}return this.checkValue(d,e.pos,a),d}throw new G(`Unknown function ${a}()${C4(w2(a,[...t.names("fns"),...t.names("vars"),...Object.keys(G2),...E4]))}`,e.pos)}if(!A0(r.value))throw new G(`"${a}" is a ${Z1(r.value)}, not a function`,e.pos);return this.callFunction(r.value,this.evalArgs(e.args,t,e.pos),t,a)}let c=this.expr(e.callee,t);if(!A0(c))throw new G(`Can't call a ${Z1(c)}`,e.pos);return this.callFunction(c,this.evalArgs(e.args,t,e.pos),t,"function")}invisiblePaint(e,t,c,a){let r=s=>Array.isArray(c)?String(c[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!t[s]?.length)continue;let i=r(s),o=Z(e.flatMap((h,f)=>f<s&&r(f)===i?t[f]:[]));!o.length||l0(t[s],o).reduce((h,f)=>h+Math.abs(i1(f)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(c)&&i?` "${i}"`:""} under it, so it can't be seen (${v0(a,!1)})`)}}record(e,t){let c=new Map;for(let a of e.fields)c.set(a.name,this.expr(a.value,t));return{type:"record",fields:c}}length(e,t){let c=e0(t.get("$scale").value??1);if(!(c>0))throw new G("$scale must be a number more than 0",e.pos);return c===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*Ea[e.unit]/c}callable(e,t){return!!t.fn(e)||E4.includes(e)||!!i0(G2,e)}specialFunction(e,t,c){if(e==="echo"){let a=this.evalArgs(t.args,c,t.pos);return this.echo(this.echoText(a),t.pos),{handled:!0,value:void 0}}if(e==="assert"){let a=this.evalArgs(t.args,c,t.pos);return this.checkArgs(e,a),this.assert(a),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"||e==="text_size"){let a=this.evalArgs(t.args,c,t.pos);this.checkArgs(e,a);let r=this.measure(a,c);return e==="text_width"?{handled:!0,value:r.advance}:e==="text_size"?{handled:!0,value:{type:"record",fields:new Map([["width",r.advance],["height",r.bounds[1][1]-r.bounds[0][1]],["bounds",r.bounds],["cap",r.cap],["ascent",r.ascent],["descent",r.descent],["size",r.size]])}}:{handled:!0,value:[r.advance,r.bounds,r.ascent,r.descent]}}if(e==="finger_count"){let a=this.evalArgs(t.args,c,t.pos);this.checkArgs(e,a);let r=this.num(this.arg(a,"length",0),"finger_count","length");return{handled:!0,value:V3(r,this.fingerWidth(a,c,1))}}return{handled:!1}}assert(e){if(T1(this.arg(e,"condition",0)))return;let t=this.arg(e,"message",1);throw new G(`Assertion failed${t===void 0?"":": "+I1(t)}`,e.at)}echo(e,t){let c=Math.ceil(e.length/C8);this.charge(c,t),this.retained+=c,this.echoes.push(e)}echoText(e){let t=this.limits.maxListLength,c=[],a=0,r=(s,i,o)=>{c.length&&(a+=2);let l=L2(i,t-a-s.length,o);if(a+=s.length+l.text.length,!l.whole)throw new G(`echo(): the text would be longer than the limit of ${t} characters`,e.at);c.push(s+l.text)};for(let{name:s,value:i}of e.all)s===null?r("",i,!1):r(`${s} = `,i,!0);return c.join(", ")}arith(e,t,c,a){if(typeof t=="number"&&typeof c=="number")switch(e){case"+":return t+c;case"-":return t-c;case"*":return t*c;case"/":return t/c;case"%":return t%c;case"^":return Math.pow(t,c)}if(e==="+"&&typeof t=="string"&&typeof c=="string")return this.checkSize(t.length+c.length,!0,a),t+c;if(Array.isArray(t)&&Array.isArray(c)){if(e==="+"||e==="-"){if(t.length!==c.length)throw new G(`Can't ${e==="+"?"add":"subtract"} lists of length ${t.length} and ${c.length}`,a);return this.charge(t.length+q2,a),t.map((s,i)=>this.arith(e,s,c[i],a))}if(e==="*"){if(Array.isArray(t[0]))return this.charge(t.length+q2,a),t.map(i=>this.arith("*",i,c,a));let s=(i,o)=>{let l=this.arith("*",i,o,a);if(typeof l!="number")throw new G("Can't multiply these lists: an item times an item is not a number",a);return l};if(Array.isArray(c[0])){let i=c[0].length;if(t.length!==c.length||c.some(o=>!Array.isArray(o)||o.length!==i))throw new G(`Can't multiply a list of length ${t.length} by a matrix: it needs ${t.length} rows of the same length`,a);return this.checkSize(i,!1,a),this.tick(a,i*t.length),Array.from({length:i},(o,l)=>t.reduce((h,f,u)=>h+s(f,c[u][l]),0))}if(t.length!==c.length)throw new G(`Can't multiply lists of length ${t.length} and ${c.length}`,a);return this.tick(a,t.length),t.reduce((i,o,l)=>i+s(o,c[l]),0)}}if(Array.isArray(t)&&typeof c=="number"&&(e==="*"||e==="/"))return this.charge(t.length+q2,a),t.map(s=>this.arith(e,s,c,a));if(typeof t=="number"&&Array.isArray(c)&&e==="*")return this.charge(c.length+q2,a),c.map(s=>this.arith(e,t,s,a));let r={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new G(`Can't ${r[e]??e} ${Z1(t)} and ${Z1(c)}`,a)}fieldFn(e,t,c,a){if(!A0(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${U1(e)}`);return r=>{let s=this.itemCount,i=this.retained,o=this.callFunction(e,{pos:[r],named:new Map,all:[{name:null,value:r}],at:a},c,"field");return(!Array.isArray(o)||o.length<=3)&&(this.itemCount=s+this.retained-i),o}}arg(e,t,c,a){return e.named.has(t)?e.named.get(t):c>=0&&c<e.pos.length?e.pos[c]:a}num(e,t,c){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${c} must be a finite number, got ${U1(e)}`);return e}vec2(e,t,c=!0){let a=r=>typeof r=="number"&&Number.isFinite(r);if(a(e)&&c)return[e,e];if(Array.isArray(e)&&a(e[0])&&(e[1]===void 0||a(e[1])))return[e[0],e[1]??0];throw new Error(`${t} must be a number or [x, y], got ${U1(e)}`)}vec3(e,t){let c=a=>typeof a=="number"&&Number.isFinite(a);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(c))return[e[0],e[1],e[2]??0];throw new Error(`${t} must be [x, y, z], got ${U1(e)}`)}placements(e,t,c){let a=(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)],r=a(e,"at"),s=a(t,"rotate");for(let[i,o]of[[r,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==c)throw new Error(`${o} needs one placement per copy: qty is ${c} but ${o} has ${i.length}`);return Array.from({length:c},(i,o)=>({at:r[r.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,t){if(!Array.isArray(e))throw new Error(`${t} must be a list of [x, y] points`);return e.map((c,a)=>{if(!Array.isArray(c)||!Number.isFinite(c[0])||!Number.isFinite(c[1]))throw new Error(`${t}[${a}] must be an [x, y] point, got ${U1(c)}`);return[c[0],c[1]]})}dyn(e,t){return e.get(t).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,t,c){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",t,c)}checkSize(e,t,c,a){if(e>this.limits.maxListLength)throw new G(`${a?`${a}(): `:""}${t?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,c);this.charge(t?Math.ceil(e/C8):e+q2,c)}segs(e){let t=e0(this.dyn(e,"$fn"))||0,c=e0(this.dyn(e,"$fa"))||2,a=e0(this.dyn(e,"$fs"))||.2,r=this.limits.maxSegments;return s=>{let i=M6(s,t,c,a);if(!(i<=r))throw new Error(`a circle with ${i} segments is more than the limit of ${r}. Lower $fn, or raise $fa or $fs.`);return i}}thickness(e){let t=this.dyn(e,"$thickness");if(typeof t!="number"||t<=0)throw new Error("$thickness must be a positive number");return t}fingerWidth(e,t,c){let a=this.arg(e,"finger",c);return typeof a=="number"&&a>0?a:Math.max(3*this.thickness(t),6)}measure(e,t){if(!this.opts.fonts)throw new G("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let c=L2(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!c.whole)throw new G(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,c.text.length);try{let a=this.textOpts(e,t,c.text);return{...S4(this.opts.fonts,c.text,a),size:a.size}}catch(a){throw a instanceof G?a:new G(a.message,e.at)}}textOpts(e,t,c){let a={size:this.num(this.arg(e,"size",1,10),"text","size"),font:I1(this.arg(e,"font",2,this.dyn(t,"$font")??"")),halign:I1(this.arg(e,"halign",-1,"left")),valign:I1(this.arg(e,"valign",-1,"baseline")),spacing:e0(this.arg(e,"spacing",-1,1))},r=this.arg(e,"fit",-1);if(r!==void 0&&c!==void 0&&this.opts.fonts){let[s,i]=Array.isArray(r)?[r[0],r[1]]:[r,void 0],o=(d,m)=>{if(d===void 0)return;let p=this.num(d,"text","fit");if(!(p>0))throw new Error(`fit must be a ${m} more than 0`);return p},l=o(s,"width"),h=o(i,"height");if(Array.isArray(r)&&(r.length!==2||l===void 0&&h===void 0))throw new Error("fit must be a width, or [width, height] with either one undef");let f=S4(this.opts.fonts,c,{...a,size:1}),u=[...l!==void 0&&f.advance>0?[l/f.advance]:[],...h!==void 0&&f.cap>0?[h/f.cap]:[]];if(u.length){let d=this.arg(e,"size",1);a.size=Math.min(...u,...d===void 0?[]:[a.size])}}return a}edges(e){let t=c=>{if(c==="out"||c==="in"||c==="flat")return c;throw new Error(`edges must be "out", "in" or "flat", got ${U1(c)}`)};if(typeof e=="string")return[t(e),t(e),t(e),t(e)];if(Array.isArray(e)&&e.length===4)return e.map(t);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let t=`${e}-back`,c=this.layers.get(t);if(c&&c.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${t}", which this program already uses for the front. Rename that layer.`);if(!c){let a=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(t,{...a,name:t,side:"back"}),this.layerDefs++}return t}bends(e){if(e===void 0)return[];let t=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return t.map((c,a)=>{if(!Array.isArray(c)||c.length!==3||!c.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${U1(c)}${t.length>1?` at ${a}`:""}`);let[r,s,i]=c;if(!(s>r))throw new Error(`a bend's x1 must be more than its x0, got ${U1(c)}`);return{x0:r,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>m2(s.children(),i),t=s=>i=>t3(i.children(),s),c=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${U1(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!T1(this.dyn(i.env,"$mirrored"))),t3(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=e0(this.arg(s.args,"r",-1,0))||0,h=T1(this.arg(s.args,"center",1,!1)),f=x6(i,o,l,this.segs(s.env));return N1(Z([h?f.map(([u,d])=>[u-i/2,d-o/2]):f]))},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 N1([H3(o,o,this.segs(s.env)(o))])},ellipse:s=>{let i=this.arg(s.args,"d",-1),[o,l]=i!==void 0?this.vec2(i,"d").map(h=>h/2):this.vec2(this.arg(s.args,"r",0,1),"r");return N1([H3(o,l,this.segs(s.env)(Math.max(o,l)))])},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 N1([H3(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 f=0;f<i*2;f++){let u=Math.PI/2+Math.PI*f/i,d=f%2?l:o;h.push([d*Math.cos(u),d*Math.sin(u)])}return N1(Z([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(f=>i[e0(f)]).filter(Boolean)):[i];return N1(Z(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=S2(M3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return T1(this.arg(s.args,"close",-1,!1))?N1(Z([...o.closed,...o.open.filter(h=>h.length>2)],l)):q0([N1(Z(o.closed,l)),R0(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 R0([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let f=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!f)return W1();let u=-(o[1]-i[1])/f*(h/2),d=(o[0]-i[0])/f*(h/2);return N1(Z([[[i[0]+u,i[1]+d],[i[0]-u,i[1]-d],[o[0]-u,o[1]-d],[o[0]+u,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=T1(this.arg(s.args,"closed",1,!1));return R0([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 f=[];for(let u=0;u<=h;u++){let d=(o+(l-o)*u/h)*Math.PI/180;f.push([i*Math.cos(d),i*Math.sin(d)])}return R0([f])},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=L2(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=i5(this.opts.fonts,o.text,l),f=this.arg(s.args,"weight",-1),u=this.arg(s.args,"bridge",-1);if(f!==void 0&&f!=="regular"){let d=f==="bold"?.035*l.size:this.num(f,"text","weight");d&&(h=A1(Z(h),d,"round"))}if(u!==void 0&&(h=R5(h,this.num(u,"text","bridge"))),T1(this.dyn(s.env,"$mirrored"))){let[d,m]=[1/0,-1/0];for(let p of h)for(let[v]of p)[d,m]=[Math.min(d,v),Math.max(m,v)];return N1(Z(h.map(p=>p.map(([v,g])=>[d+m-v,g]))))}return N1(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)?e0(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),f=Math.sin(l),u=this.arg(s.args,"center",-1),d=[h,f,-f,h,0,0];if(u!==void 0){let[m,p]=this.vec2(u,"center",!1);d=[h,f,-f,h,m-h*m+f*p,p-f*m-h*p]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,f=o/l;return e(s,[1-2*h*h,-2*h*f,-2*h*f,1-2*f*f,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 W1();let l=a(o,"difference");return r(i,h=>({regions:l0(h.regions,l.regions),lines:h0(h.lines,Z(l.regions),"outside")}))},intersection:s=>{let i=s.childList();if(!i.length)return W1();let o=v=>[...v.layers.values()].some(g=>g.regions.length),l=v=>o(v)||v.parts.some(g=>[...g.layers.values()].some(M=>M.regions.length)),h=v=>[v.layers,...v.parts.map(g=>g.layers)].flatMap(g=>[...g].flatMap(([M,y])=>M===d0?[]:y.regions)),f=v=>{let g;for(let M of i){if(M===v||!l(M))continue;let y=Z(h(M));g=g?P1(g,y):y}return g},u=i[0],d=i.every(l),m=f(u),p=r(u,v=>({regions:d?m?P1(v.regions,m):v.regions:[],lines:m?h0(v.lines,m,"inside"):v.lines}));for(let v of i){if(v===u)continue;if(v.parts.length)throw new Error("part() can only be the first child of intersection()");let g=f(v),M=new Map;for(let[b,w]of v.layers)w.lines.length&&M.set(b,{regions:[],lines:g?h0(w.lines,g,"inside"):w.lines});if(!M.size)continue;let y=p.parts.length===1&&!o(u)?p.parts[0]:void 0;if(y){let b=new Map(y.layers);for(let[w,x]of M){let z=b.get(w);b.set(w,{regions:z?.regions??[],lines:[...z?.lines??[],...x.lines]})}p={layers:p.layers,parts:[{...y,layers:b}]}}else p=q0([p,{layers:M,parts:[]}])}return u.parts.forEach((v,g)=>{let M=[...v.layers.values()].some(b=>b.regions.length),y=[...p.parts[g]?.layers.values()??[]].some(b=>b.regions.length);M&&!y&&this.warn(`intersection() leaves part "${v.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"} (${v0(s.args.at,!1)})`)}),p},hull:s=>{let i=s.children(),o=l=>{let h=[],f="cut",u=!0;for(let[m,p]of l){u&&(p.regions.length||p.lines.length)&&(f=m,u=!1);for(let v of[...p.regions,...p.lines])for(let g of v)h.push(g)}let d=I3(h);return new Map([[f,{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=T1(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),f=i!==void 0?"round":l?"square":"miter";return r(s.children(),u=>({regions:A1(u.regions,h,f),lines:u.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,...f]=s.childList();if(!h||!f.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 u=Z(a(f,"pattern").regions),d=k0(h.layers),m=m0(u);if(!d||!m)return W1();let p=Math.floor((m[1]-d[3])/o),v=Math.ceil((m[3]-d[1])/o),g=Math.floor((m[0]-d[2])/i)-1,M=Math.ceil((m[2]-d[0])/i)+1,y=(v-p+1)*(M-g+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 b=p0(u).map(S=>({polys:S,box:m0(S)})),w=u,x=(S,k)=>{let E=0;for(let V of w)for(let T=0,H=V.length-1;T<V.length;H=T++){let[D,O]=V[H],[R,N]=V[T];O<=k?N>k&&(R-D)*(k-O)-(S-D)*(N-O)>0&&E++:N<=k&&(R-D)*(k-O)-(S-D)*(N-O)<0&&E--}return E!==0},z=new Map,L=(S,k)=>{let E=z.get(S)??{regions:[],lines:[]};for(let V of k.regions)E.regions.push(V);for(let V of k.lines)E.lines.push(V);z.set(S,E)};for(let S=p;S<=v;S++)for(let k=g;k<=M;k++){let E=k*i+(S%2?l*i:0),V=S*o,T=[d[0]+E,d[1]+V,d[2]+E,d[3]+V];if(T[2]<m[0]||T[0]>m[2]||T[3]<m[1]||T[1]>m[3])continue;let H=b.filter(q=>!(T[2]<q.box[0]||T[0]>q.box[2]||T[3]<q.box[1]||T[1]>q.box[3]));if(!H.length)continue;w=H.length===b.length?u:H.flatMap(q=>q.polys);let D=[x(T[0],T[1]),x(T[2],T[1]),x(T[2],T[3]),x(T[0],T[3])],O=w.some(q=>q.some(([Y,_])=>Y>T[0]&&Y<T[2]&&_>T[1]&&_<T[3])),R=D.every(Boolean)&&!O,N=[1,0,0,1,E,V];for(let[q,Y]of m2({layers:h.layers,parts:[]},N).layers)L(q,R?Y:{regions:P1(Y.regions,w),lines:h0(Y.lines,w,"inside")})}return{layers:z,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=T1(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 f=w5(i,l,h);if(o===void 0)return R0([f]);let u=this.num(o,"spline","width");if(!(u>0))throw new Error("width must be more than 0");return N1(Z(T3([f],u)))},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=Z(a([s.children()],"hatch").regions),f=m0(h);if(!f)return W1();let[u,d]=[(f[0]+f[2])/2,(f[1]+f[3])/2],m=Math.hypot(f[2]-f[0],f[3]-f[1])/2+o,p=i*Math.PI/180,[v,g]=[Math.cos(p),Math.sin(p)],[M,y]=[-g,v],b=Math.ceil(m/o);if(!(2*b+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*b+1);let w=[],x=Math.round((u*M+d*y)/o);for(let L=x-b;L<=x+b;L++){let S=L*o-(u*M+d*y),[k,E]=[u+M*S,d+y*S];w.push([[k-v*m,E-g*m],[k+v*m,E+g*m]])}if(l===void 0)return R0(h0(w,h,"inside"));let z=this.num(l,"hatch","width");if(!(z>0))throw new Error("width must be more than 0");return N1(P1(Z(T3(w,z).map(L=>L)),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"),f=this.num(this.arg(s.args,"seed",-1,1),"flow","seed"),u=Z(a([s.children()],"flow").regions),d=m0(u);if(!d)return W1();let m=M=>[Math.cos(M*A8),Math.sin(M*A8)],p;if(typeof i=="number"){let M=m(i);p=()=>M}else{let M=this.fieldFn(i,"flow",s.env,s.args.at);p=y=>{let b=M(y);if(b===void 0)return null;if(typeof b=="number"&&Number.isFinite(b))return m(b);if(Array.isArray(b)&&typeof b[0]=="number"&&typeof b[1]=="number"&&Number.isFinite(b[0])&&Number.isFinite(b[1])){let w=Math.hypot(b[0],b[1]);return w>1e-12?[b[0]/w,b[1]/w]:null}throw new Error(`field() must give an angle, a vector [x, y] or undef, got ${U1(b)}`)}}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 g=S6({spacing:o,step:l,minLength:h,seed:f,box:d,inside:P6(u),dir:p,tick:()=>this.tick(s.args.at),maxPoints:this.limits.maxPoints});return R0(h0(g,u,"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),f=this.num(this.arg(s.args,"cell",-1,1),"contours","cell");if(!(f>0))throw new Error("cell must be more than 0");let u=Z(a([s.children()],"contours").regions),d=m0(u);if(!d)return W1();let m=Math.ceil((d[2]-d[0])/f)+1,p=Math.ceil((d[3]-d[1])/f)+1;if(!(m*p<=this.limits.maxPoints/2))throw new Error(`a cell of ${f} samples the area at ${m*p} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let v=new Float64Array(m*p),g=1/0,M=-1/0;for(let x=0;x<p;x++)for(let z=0;z<m;z++){let L=o([d[0]+z*f,d[1]+x*f]);if(L===void 0){v[x*m+z]=NaN;continue}if(typeof L!="number"||!Number.isFinite(L))throw new Error(`field() must give a number or undef, got ${U1(L)}`);v[x*m+z]=L,g=Math.min(g,L),M=Math.max(M,L)}if(!(g<=M))return W1();let y;if(h!==void 0){let x=this.num(h,"contours","interval");if(!(x>0))throw new Error("interval must be more than 0");let z=Math.ceil(g/x),L=Math.floor(M/x);if(!Number.isSafeInteger(z)||!Number.isSafeInteger(L))throw new Error(`the heights are too large for an interval of ${x}`);let S=Math.max(0,L-z+1);if(!(S<=1e4))throw new Error(`interval ${x} gives ${S} levels: use a larger interval`);y=Array.from({length:S},(k,E)=>(z+E)*x)}else if(Array.isArray(l))y=l.map(x=>this.num(x,"contours","levels"));else{let x=Math.floor(this.num(l,"contours","levels"));if(!(x>=1&&x<=1e4))throw new Error("levels must be 1 to 10000");y=Array.from({length:x},(z,L)=>g+(M-g)*(L+1)/(x+1))}let b=[],w=0;for(let x of y){this.tick(s.args.at,Math.ceil(m*p/100));let z=A6(v,m,p,d[0],d[1],f,x),L=z.reduce((S,k)=>S+k.length,0);if(!((w+=L)<=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(L);for(let S of z)b.push(S)}return R0(h0(b,u,"inside"))},occlude:s=>{let i;this.occluding++;try{i=s.childItems()}finally{this.occluding--}let o=f=>this.layers.get(f)?.mode??"cut",l=[],h=[];for(let f=i.length-1;f>=0;f--){let u=i[f];if(u.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[p,v]of u.layers){if(p===d0)continue;let g=o(p);!h.length||g==="cut"||g==="guide"?d.set(p,v):g==="line"?d.set(p,{regions:[],lines:h0([...v.lines,...Z(v.regions).map(M=>[...M,M[0]])],h,"outside")}):d.set(p,{regions:l0(v.regions,h),lines:h0(v.lines,h,"outside")})}l.push({layers:d,parts:[]});let m=[...u.layers].filter(([p])=>o(p)!=="guide").flatMap(([,p])=>p.regions);m.length&&(h=Z([...h,...m]))}return q0(l.reverse())},hide:s=>this.occluding?N1(Z(a([s.children()],"hide").regions),d0):(this.warn(`hide() only works inside occlude(); it draws nothing (${v0(s.args.at,!1)})`),W1()),paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(u=>typeof u!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],f=[];for(let u=o.length-1;u>=0;u--){let d=o[u];if(d.parts.length)throw new Error("part() cannot go inside paint()");let m=h,p=Z(a([d],"paint").regions);f[u]=p,h=m.length?Z([...m,...p]):p;let v=Array.isArray(i)?i[u]:void 0;if(v!=="")if(v!==void 0){this.layers.has(v)||this.layers.set(v,{name:v,mode:"fill",color:"#000000"}),this.layerDefs++,l.push(N1(m.length?l0(p,m):p,v));let g=d.layers.get(d0);g&&l.push({layers:new Map([[d0,g]]),parts:[]})}else l.push(m.length?r(d,g=>({regions:l0(g.regions,m),lines:h0(g.lines,m,"outside")})):d)}return this.invisiblePaint(o,f,i,s.args.at),q0(l.reverse())},measure:s=>{let i=T1(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let f=k0(h.layers)??m0(h.parts.flatMap(v=>[...v.layers.values()].flatMap(g=>[...g.regions,...g.lines])));s.env.vars.set("$bounds",f?[...f]:void 0);let u=[h.layers,...h.parts.map(v=>v.layers)],d=u.flatMap(v=>v.get("cut")?.regions??[]),m=d.length?d:u.flatMap(v=>[...v].filter(([g])=>g!=="guide").flatMap(([,g])=>g.regions)),p=b6(Z(m));s.env.vars.set("$area",p.area),s.env.vars.set("$centroid",p.area>0?p.centroid:void 0)});return q0(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 r(s.children(),l=>({regions:Z(l.regions).filter(h=>!(i1(h)<0&&-i1(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(([f,u])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:R5(u.regions,i),lines:u.lines}:u]));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=f=>p0(f).map(u=>({g:u,a:u.reduce((d,m)=>d+i1(m),0)})).sort((u,d)=>d.a-u.a).slice(0,i).flatMap(({g:u})=>u),l=s.children(),h=f=>new Map([...f].map(([u,d])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:o(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(f=>({...f,layers:h(f.layers)}))}},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return r(s.children(),o=>({regions:A1(A1(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 r(s.children(),o=>({regions:Z([...o.regions,...T3(o.lines,i)]),lines:[]}))},outline:s=>r(s.children(),i=>({regions:[],lines:[...i.lines,...Z(i.regions).map(o=>[...o,o[0]])]})),cut:t("cut"),score:c("score"),engrave:c("engrave"),guide:t("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),f=this.arg(s.args,"order",-1),u=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||f!==void 0||u!==void 0||!h){if(h?.side==="back")throw new Error(`the layer "${i}" is the back of layer "${i.slice(0,-5)}"; set its mode and colour on that layer, or give this one another name`);let m=o??h?.mode??"line";if(!["cut","line","fill","guide"].includes(m))throw new Error('mode must be "cut", "line", "fill" or "guide"');let p=I1(l??h?.color??"#00aa00");if(!/^#[0-9a-fA-F]{6}$/.test(p))throw new Error('color must look like "#00aa00"');let v=f===void 0?h?.order:this.num(f,"layer","order"),g=u===void 0?h?.bleed:this.num(u,"layer","bleed");if(g!==void 0&&!(g>=0))throw new Error("bleed must be 0 or more");if(g&&m==="cut")throw new Error("a cut layer has no bleed");this.layerDefs++,this.layers.set(i,{name:i,mode:m,color:p,...v!==void 0&&{order:v},...g!==void 0&&{bleed:g}})}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${U1(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",!T1(this.dyn(s.env,"$mirrored"))),t3(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=I1(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 ${U1(o)}`);if(l===0)return{layers:new Map,parts:[]};let h=this.arg(s.args,"stack",-1),f=h===void 0?1:Math.floor(this.num(h,"part","stack"));if(!(f>=1))throw new Error("stack must be 1 or more");if(this.copies+=l*f,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let u=this.arg(s.args,"at",-1),d=this.arg(s.args,"rotate",-1),m=this.arg(s.args,"glue",-1),p=m===void 0?void 0:I1(m),v=I1(this.arg(s.args,"face",-1,"top"));if(v!=="top"&&v!=="bottom")throw new Error(`face must be "top" or "bottom", got ${U1(v)}`);let g=this.frame!==$5&&p===void 0,M=this.arg(s.args,"bend",-1),y=u===void 0&&d===void 0&&!g&&p===void 0&&M===void 0?void 0:this.placements(u,d,l),b=this.arg(s.args,"material",-1);b!==void 0&&s.env.vars.set("$material",I1(b));let w=this.thickness(s.env);y&&(g||f>1)&&(y=y.flatMap(u1=>{let J1=p===void 0?q1(this.frame,a0(u1)):a0(u1),R1=p!==void 0&&v==="bottom"?-w:w;return Array.from({length:f},(S0,B1)=>({...u1,matrix:q1(J1,Z0(0,0,B1*R1))}))}));let x=this.arg(s.args,"mirror",-1,!1),z;if(Array.isArray(x)){if(x.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${x.length}`);z=x.map(u1=>T1(u1))}else z=Array.from({length:l},()=>T1(x));let L=z.some(u1=>u1)&&!z.every(u1=>u1);if(L&&p!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let S=z[0],k=u1=>{let J1=s.env.vars.get("$mirrored"),R1=s.env.vars.has("$mirrored");u1&&s.env.vars.set("$mirrored",!0);try{let S0=s.children();return u1?m2(S0,[-1,0,0,1,0,0]):S0}finally{u1&&(R1?s.env.vars.set("$mirrored",J1):s.env.vars.delete("$mirrored"))}},E=k(S),V=this.bends(M),T=this.arg(s.args,"on",-1),H=this.arg(s.args,"slots",-1),D=H===void 0?void 0:(Array.isArray(H)?H:[H]).map(u1=>{if(typeof u1!="string")throw new Error("slots must be part names");return u1}),O=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),R=this.arg(s.args,"slot_extra",-1),N=R===void 0?void 0:this.vec2(R,"slot_extra",!1),q=this.arg(s.args,"bores",-1),Y=q===void 0?void 0:(Array.isArray(q)?q:[q]).map(u1=>{if(typeof u1!="string")throw new Error("bores must be hardware labels or kinds");return u1}),_=this.arg(s.args,"halving",-1),c1=_===void 0?void 0:(Array.isArray(_)?_:[_]).map(u1=>{if(typeof u1!="string")throw new Error("halving must be part names");return u1}),w1=this.arg(s.args,"fit",-1,"turn");if(typeof w1!="number"&&!Object.prototype.hasOwnProperty.call(r3,I1(w1)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${U1(w1)}`);let D1=typeof w1=="number"?w1:r3[I1(w1)],J=(u1,J1,R1)=>{let S0=R1.length===l,B1=y?.filter((V0,G0)=>R1.includes(Math.floor(G0/f)+1));return{name:i,qty:R1.length*f,layers:u1,thickness:w,kerf:e0(this.dyn(s.env,"$kerf"))||0,material:I1(this.dyn(s.env,"$material")??"material"),...B1?{placements:B1}:{},...f>1?{stack:f}:{},...V.length?{bends:J1?V.map(V0=>({...V0,mirrored:!0})):V}:{},...T!==void 0?{on:I1(T)}:{},...D?{slots:D,clearance:O}:{},...D&&N?{slotExtra:N}:{},...Y?{bores:Y,fit:D1}:{},...c1?{halving:c1,clearance:O}:{},...this.step?{step:this.step}:{},...p!==void 0&&{glue:{host:p,face:v}},...J1&&{mirrored:!0},...!S0&&{copies:R1}}},C1=u1=>z.flatMap((J1,R1)=>J1===u1?[R1+1]:[]),r0=L?[J(E.layers,S,C1(S)),J(k(!S).layers,!S,C1(!S))]:[J(E.layers,S,C1(S))];return{layers:new Map,parts:[...E.parts,...r0]}},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,a0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=I1(this.arg(s.args,"text",0,"")),o=T1(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,f=this.stepNames.indexOf(h)+1;f||(this.stepNames.push(h),f=this.stepNames.length),this.step=f,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=I1(this.arg(s.args,"kind",0,"dowel"));i0(G5,i)===void 0&&i0(G6,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${v0(s.args.at,!1)})${w2(i,Object.keys(G5))}`);let o=I1(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${U1(o)}`);let l=this.arg(s.args,"sides",-1),h=o==="ball"||l===0,f=this.vec3(this.arg(s.args,"from",1),"from"),u=this.arg(s.args,"to",2),d=h&&u===void 0?f:this.vec3(u,"to"),m=this.arg(s.args,"size",3,6),p=typeof m=="number"?m:this.vec2(m,"size",!1);if(h){if(typeof p!="number"||!(p>0))throw new Error("a ball's size is its diameter, a number more than 0");f=d=[(f[0]+d[0])/2,(f[1]+d[1])/2,(f[2]+d[2])/2]}let v=[d[0]-f[0],d[1]-f[1],d[2]-f[2]],g=Math.abs(v[2])>.9*Math.hypot(...v),M=this.arg(s.args,"up",-1),y=M===void 0?g?[0,1,0]:[0,0,1]:this.vec3(M,"up"),b=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(b>=3&&b<=A4))throw new Error(`sides must be from 3 to ${A4} (or 0 for a ball), got ${U1(b)}`);if(this.pointCount+=h?2*A4:b*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),x=this.frame,z=S=>[x[0]*S[0]+x[1]*S[1]+x[2]*S[2]+x[3],x[4]*S[0]+x[5]*S[1]+x[6]*S[2]+x[7],x[8]*S[0]+x[9]*S[1]+x[10]*S[2]+x[11]],L=S=>[x[0]*S[0]+x[1]*S[1]+x[2]*S[2],x[4]*S[0]+x[5]*S[1]+x[6]*S[2],x[8]*S[0]+x[9]*S[1]+x[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:z(f),to:z(d),size:p,up:L(y),sides:b,step:this.step,...w!==void 0?{label:I1(w)}:{}}),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",I1(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return W1();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new _1(i.env,s.env);this.hoist(i.stmts,h);let f=new Set;if(l===void 0)o.forEach(p=>f.add(p));else for(let p of this.iterable(l,s.args.at)){let v=e0(p);o[v]?f.add(o[v]):o.length&&v>=o.length&&i.module&&i.pos&&this.warn(`${i.module}() uses children(${v}) but was given ${o.length} child${o.length===1?"":"ren"} (${v0(i.pos,!1)}). A module call takes one statement as its child: put several in braces, ${i.module}() { a(); b(); }`)}let u=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let m=this.childKey(h);for(let p of i.stmts)if(p.kind==="assign")this.stmt(p,h);else if(f.has(p)){let v=m&&d.get(p);if(v&&v.key===m){v.shape&&u.push(v.shape);continue}let g=this.effects(),M=this.stmt(p,h);M&&u.push(M),m&&this.effects()===g&&!M?.parts.length&&d.set(p,{key:m,shape:M})}return q0(u)},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),f=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/f*4),N1(w6(i,o,l,h,f))},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),N1(z6(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),f=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return N1(Z(k6(i,o,l,h,f)))},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"),f=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(o-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||f<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(i)/l+1)*(Math.abs(o)/(f+h)+2)*2),R0(L6(i,o,l,h,f))}};function a(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,f]of l.layers)if(h!==d0)for(let u of f.regions)o.regions.push(u)}return o}function r(s,i){let o=l=>{let h=new Map;for(let[f,u]of l)h.set(f,i(u));return h};return{layers:o(s.layers),parts:s.parts.map(l=>({...l,layers:o(l.layers)}))}}}};function T8(n){switch(n.kind){case"num":return n.unit?{ok:!1}:{ok:!0,value:n.value};case"str":case"bool":return{ok:!0,value:n.value};case"unary":return n.op==="-"&&n.arg.kind==="num"?{ok:!0,value:-n.arg.value}:{ok:!1};case"list":{let e=[];for(let t of n.items){if(t.kind!=="item")return{ok:!1};let c=T8(t.expr);if(!c.ok||typeof c.value!="number")return{ok:!1};e.push(c.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function P8(n){let e=Number(n.trim());return n.trim()!==""&&Number.isFinite(e)?e:void 0}function l5(n){let{program:e,comments:t}=Y0(n),c=t.filter(o=>o.block&&/^\[[^\]]+\]$/.test(o.text)),a=new Map(t.filter(o=>!o.block&&!o.own).map(o=>[o.line,o.text])),r=new Map(t.filter(o=>!o.block&&o.own).map(o=>[o.line,o.text])),s=[],i=new Set;for(let o of e.body){if(o.kind!=="assign"||/^\$f[nas]$/.test(o.name))continue;let l=T8(o.value);if(!l.ok)continue;let h=c.filter(M=>M.line<=o.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(h.toLowerCase()==="hidden")continue;let f=a.get(o.pos.line),u=r.get(o.pos.line-1)??"",d=l.value,m={name:o.name,caption:u,group:h,type:typeof d=="number"||Array.isArray(d)?"number":typeof d=="boolean"?"boolean":"string",initial:d,span:o.span},p=f?/^((?:\[.*\](?:\s+drive)?)?)\s*when\s+(.+)$/.exec(f.trim()):null;p&&(m.when=p[2].trim()),p?.[1]&&i.add(m);let v=p?p[1].trim():f?.trim(),g=v?/^\[(.*)\](\s+drive)?$/.exec(v):null;if(g?.[2]&&m.type==="number"&&typeof d=="number"&&(m.drive=!0),g){let M=g[1];if(M.includes(",")||/[a-zA-Z"]/.test(M)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(M))m.options=M.split(",").map(y=>{let[b,w]=y.split(":").map(L=>L.trim().replace(/^"|"$/g,"")),x=P8(b),z=m.type==="number"&&x!==void 0?x:b;return{name:w??b,value:z}});else{let y=M.split(":").map(P8);y.every(b=>b!==void 0)&&(y.length===1?m.max=y[0]:y.length===2?(m.min=y[0],m.max=y[1]):(m.min=y[0],m.step=y[1],m.max=y[2]))}}s.push(m)}for(let o of s){if(o.when===void 0)continue;if(!i.has(o)&&typeof I8(o.when)=="string"){delete o.when;continue}let l=Va(o.when,s);l&&(o.whenProblem=l,delete o.when)}return{parameters:s}}function I8(n){try{let e=Y0(`when__ = (${n});`).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 E8=new Set(["==","!=","<","<=",">",">=","&&","||","+","-","*","/","%","!"]);function Va(n,e){let t=I8(n);if(typeof t=="string")return`its condition (${n}) is not an expression: ${t}`;let c=new Set(e.map(s=>s.name)),a=s=>{switch(s.kind){case"num":case"str":case"bool":case"undef":return;case"var":return c.has(s.name)?void 0:`uses ${s.name}, which is not a setting`;case"list":for(let i of s.items){if(i.kind!=="item")return"uses a list comprehension";let o=a(i.expr);if(o)return o}return;case"unary":return E8.has(s.op)?a(s.arg):`uses ${s.op}`;case"binary":return E8.has(s.op)?a(s.left)??a(s.right):`uses ${s.op}`;case"ternary":return a(s.cond)??a(s.then)??a(s.else);case"index":return a(s.target)??a(s.index);default:return"uses more than settings, values and operators"}},r=a(t);return r?`its condition (${n}) ${r}`:void 0}var Oa=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,H8=(n,e)=>Math.max(1,Oa.exec(n.slice(e-1))?.[0].length??1);var l2=1e6,h5=.01,h2=n=>i1(n)<0?[...n].reverse():n;function Fa(n,e){let t=q1(t2(n.matrix),e.matrix),[c,a]=[t[8],t[9]],r=Math.hypot(c,a);if(r<1e-9)return[];let s=0,i=e.thickness,o=T=>(-t[11]-Math.max(t[10]*s,t[10]*i)+T)/r,l=T=>(n.thickness-t[11]-Math.min(t[10]*s,t[10]*i)-T)/r;if(!(l(h5)>o(h5)))return[];let[h,f]=[c/r,a/r],[u,d]=[-f,h],m=(T,H)=>[[h*T-u*l2,f*T-d*l2],[h*H-u*l2,f*H-d*l2],[h*H+u*l2,f*H+d*l2],[h*T+u*l2,f*T+d*l2]],p=1/0,v=-1/0;for(let T of e.outline)for(let[H,D]of T)for(let O of[s,i]){let R=t[8]*H+t[9]*D+t[10]*O+t[11];R<p&&(p=R),R>v&&(v=R)}if(Math.min(n.thickness,v)-Math.max(0,p)<Math.min(1,n.thickness/2))return[];let M=((T,H)=>P1(e.outline,[h2(m(T,H))]).filter(D=>Math.abs(i1(D))>1e-6))(o(h5),l(h5));if(!M.length)return[];let y=Math.abs(l(0)-o(0))+1,b=T=>{let H=T.map(([R,N])=>[R-h*y,N-f*y]),D=T.map(([R,N])=>[R+h*y,N+f*y]),O=[h2(H),h2(D)];for(let R=0;R<T.length;R++){let N=(R+1)%T.length,q=[H[R],H[N],D[N],D[R]];Math.abs(i1(q))>1e-12&&O.push(h2(q))}return O},w=Z(M.flatMap(b),"nonzero"),x=P1(e.outline,w).filter(T=>Math.abs(i1(T))>1e-6);if(!x.length)return[];let z=T=>([H,D])=>[t[0]*H+t[1]*D+t[2]*T+t[3],t[4]*H+t[5]*D+t[6]*T+t[7]],L=n.thickness,S=(T,H)=>(T-t[11]-t[10]*H)/r,k=[],E=T=>{T.length>=3&&Math.abs(i1(T))>1e-9&&k.push(h2(T))};for(let T of[s,i])for(let H of P1(x,[h2(m(S(0,T),S(L,T)))]))E(H.map(z(T)));for(let T of[0,L])if(Math.abs(t[10])>1e-9){let[H,D]=[S(T,s),S(T,i)].sort((O,R)=>O-R);for(let O of P1(x,[h2(m(H,D))]))E(O.map(([R,N])=>z((T-t[11]-t[8]*R-t[9]*N)/t[10])([R,N])))}else{let H=S(T,0);for(let D of P1(x,[h2(m(H-1e-4,H+1e-4))])){let[O,R]=[1/0,-1/0];for(let[Y,_]of D){let c1=u*Y+d*_;O=Math.min(O,c1),R=Math.max(R,c1)}if(!(R-O>1e-6))continue;let N=[h*H+u*O,f*H+d*O],q=[h*H+u*R,f*H+d*R];E([z(s)(N),z(s)(q),z(i)(q),z(i)(N)])}}let V=(T,H,D)=>t[8]*T+t[9]*H+t[10]*D+t[11];for(let T of x)for(let H=0;H<T.length;H++){let[D,O]=T[H],[R,N]=T[(H+1)%T.length],q=[[0,s],[1,s],[1,i],[0,i]],Y=([_,c1])=>V(D+(R-D)*_,O+(N-O)*_,c1);for(let[_,c1]of[[1,0],[-1,-L]]){let w1=J=>_*Y(J)>=c1,D1=[];for(let J=0;J<q.length;J++){let C1=q[J],r0=q[(J+1)%q.length];if(w1(C1)&&D1.push(C1),w1(C1)!==w1(r0)){let u1=_*Y(C1)-c1,J1=_*Y(r0)-c1,R1=u1/(u1-J1);D1.push([C1[0]+(r0[0]-C1[0])*R1,C1[1]+(r0[1]-C1[1])*R1])}}if(q=D1,!q.length)break}q.length>=3&&E(q.map(([_,c1])=>z(c1)([D+(R-D)*_,O+(N-O)*_])))}return k.length?Z(k,"nonzero"):[]}function V8(n,e,t){let c=[];for(let r of e)for(let s of Fa(n,r))c.push(s);if(!c.length)return[];let a=p0(P1(Z(c),n.outline)).filter(r=>r.reduce((s,i)=>s+i1(i),0)>1e-4);return a.length?A1(a.flat(),t/2,"miter"):[]}var u5=(n,e)=>n[0]*e[0]+n[1]*e[1]+n[2]*e[2],Da=(n,e)=>[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]],O8=n=>[n[2],n[6],n[10]],F8=n=>[n[3],n[7],n[11]];function D8(n,e,t){let c=[];for(let a of n)for(let r=0,s=a.length-1;r<a.length;s=r++){let i=a[s],o=a[r],l=t[0]*(i[1]-e[1])-t[1]*(i[0]-e[0]),h=t[0]*(o[1]-e[1])-t[1]*(o[0]-e[0]);if(l>0==h>0)continue;let f=l/(l-h);c.push((i[0]+(o[0]-i[0])*f-e[0])*t[0]+(i[1]+(o[1]-i[1])*f-e[1])*t[1])}return c.sort((a,r)=>a-r)}function R8(n,e){for(let t=0;t+1<n.length;t+=2)if(n[t]<=e&&e<=n[t+1])return[n[t],n[t+1]]}function Ra(n,[e,t]){let c=!1;for(let a of n)for(let r=0,s=a.length-1;r<a.length;s=r++){let[i,o]=a[s],[l,h]=a[r];o>t!=h>t&&e<i+(l-i)*(t-o)/(h-o)&&(c=!c)}return c}function q8(n,e,t){let c={a:[],b:[],thin:0},a=O8(n.matrix),r=O8(e.matrix),s=Da(a,r),i=Math.hypot(...s);if(i<1e-6)return c;let o=Math.abs(u5(a,r)),l=[s[0]/i,s[1]/i,s[2]/i],h=u5(a,F8(n.matrix))+n.thickness/2,f=u5(r,F8(e.matrix))+e.thickness/2,u=u5(a,r),d=1-u*u,m=(h-f*u)/d,p=(f-h*u)/d,v=[m*a[0]+p*r[0],m*a[1]+p*r[1],m*a[2]+p*r[2]],g=k=>{let E=t2(k.matrix);return[[E[0]*v[0]+E[1]*v[1]+E[2]*v[2]+E[3],E[4]*v[0]+E[5]*v[1]+E[6]*v[2]+E[7]],[E[0]*l[0]+E[1]*l[1]+E[2]*l[2],E[4]*l[0]+E[5]*l[1]+E[6]*l[2]]]},[M,y]=g(n),[b,w]=g(e),x=D8(n.outline,M,y),z=D8(e.outline,b,w),L=(e.thickness+n.thickness*o)/i+t,S=(n.thickness+e.thickness*o)/i+t;for(let k=0;k+1<x.length;k+=2)for(let E=0;E+1<z.length;E+=2){let V=Math.max(x[k],z[E]),T=Math.min(x[k+1],z[E+1]);if(!(T-V>.01))continue;let H=(V+T)/2,[D,O]=R8(x,H),[R,N]=R8(z,H),q=Math.max(O-H,H-R)<=Math.max(H-D,N-H),Y=(w1,D1,J,C1,r0,u1)=>{let J1=[-J[1],J[0]],R1=(G1,u2)=>[D1[0]+J[0]*(H+r0*G1)+J1[0]*u2,D1[1]+J[1]*(H+r0*G1)+J1[1]*u2],S0=u1+C1+1,B1=[R1(0,-C1/2),R1(S0,-C1/2),R1(S0,C1/2),R1(0,C1/2)];i1(B1)<0&&B1.reverse();let V0=R1(Math.min(.01,u1/2),0),G0=p0(P1([B1],w1.outline)).find(G1=>Ra(G1,V0));if(!(!G0||!(G0.reduce((G1,u2)=>G1+i1(u2),0)>1e-4)))return P1(A1(G0,.05,"miter"),[B1])},_=Y(n,M,y,L,q?1:-1,q?O-H:H-D),c1=Y(e,b,w,S,q?-1:1,q?H-R:N-H);if(!_||!c1){c.thin++;continue}c.a.push(..._),c.b.push(...c1)}return c}var U2=n=>{let e=Math.round(n*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},V4=n=>n.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function O4(n,e){let t=[];for(let[c,a]of n){let r=[U2(c),U2(a)],s=t[t.length-1];(!s||s[0]!==r[0]||s[1]!==r[1])&&t.push(r)}for(;e&&t.length>1&&t[0][0]===t[t.length-1][0]&&t[0][1]===t[t.length-1][1];)t.pop();return t}var N2=(n,e)=>`M${O4(n,e).map(([t,c])=>`${t} ${c}`).join("L")}${e?"Z":""}`;function f5(n,e){let t=[];for(let c of e){let a=[],r=[],s=[];for(let i of n){let o=i.layers.get(c.name);if(o){for(let l of o.lines)a.push(N2(l,!1));for(let l of o.regions)(i1(l)<0?r:s).push(N2(l,!0))}}(a.length||r.length||s.length)&&t.push({name:c.name,mode:c.mode,color:c.color,d:[...a,...r,...s].join(""),regions:[...r,...s].join(""),lines:a.join("")})}return t}function d5(n,e,t,c){let a=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${U2(e)}mm" height="${U2(t)}mm" viewBox="0 0 ${U2(e)} ${U2(t)}">`];for(let r of c){let s=[],i=[];for(let l of n){let h=l.layers.get(r.name);if(!h)continue;let f=` data-part="${V4(l.part)}"`;if(r.mode==="fill"){h.regions.length&&i.push(`<path${f} d="${h.regions.map(u=>N2(u,!0)).join("")}"/>`);for(let u of h.lines)i.push(`<path${f} fill="none" stroke="${r.color}" stroke-width="0.1" d="${N2(u,!1)}"/>`);continue}for(let u of h.lines)s.push(`<path${f} d="${N2(u,!1)}"/>`);for(let u of h.regions)(i1(u)<0?s:i).push(`<path${f} d="${N2(u,!0)}"/>`)}if(!s.length&&!i.length)continue;let o=r.mode==="fill"?`fill="${r.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${r.color}" stroke-width="0.1"${r.mode==="guide"?' stroke-dasharray="1 1"':""}`;a.push(`<g id="${V4(r.name)}" inkscape:groupmode="layer" inkscape:label="${V4(r.name)}" data-mode="${r.mode}" ${o}>`,...s,...i,"</g>")}return a.push("</svg>",""),a.join(`
|
|
3022
|
-
`)
|
|
4247
|
+
`};String.prototype.codePointAt||(function(){var n=(function(){try{var t={},c=Object.defineProperty,a=c(t,t,t)&&c}catch{}return a})(),e=function(t){if(this==null)throw TypeError();var c=String(this),a=c.length,r=t?Number(t):0;if(r!=r&&(r=0),!(r<0||r>=a)){var s=c.charCodeAt(r),i;return s>=55296&&s<=56319&&a>r+1&&(i=c.charCodeAt(r+1),i>=56320&&i<=57343)?(s-55296)*1024+i-56320+65536:s}};n?n(String.prototype,"codePointAt",{value:e,configurable:!0,writable:!0}):String.prototype.codePointAt=e})();var V4=0,Z6=-3;function P3(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function R8(n,e){this.source=n,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new P3,this.dtree=new P3}var Y6=new P3,K6=new P3,O4=new Uint8Array(30),F4=new Uint16Array(30),J6=new Uint8Array(30),Q6=new Uint16Array(30),q8=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h6=new P3,Q0=new Uint8Array(320);function e7(n,e,t,c){var a,r;for(a=0;a<t;++a)n[a]=0;for(a=0;a<30-t;++a)n[a+t]=a/t|0;for(r=c,a=0;a<30;++a)e[a]=r,r+=1<<n[a]}function $8(n,e){var t;for(t=0;t<7;++t)n.table[t]=0;for(n.table[7]=24,n.table[8]=152,n.table[9]=112,t=0;t<24;++t)n.trans[t]=256+t;for(t=0;t<144;++t)n.trans[24+t]=t;for(t=0;t<8;++t)n.trans[168+t]=280+t;for(t=0;t<112;++t)n.trans[176+t]=144+t;for(t=0;t<5;++t)e.table[t]=0;for(e.table[5]=32,t=0;t<32;++t)e.trans[t]=t}var u6=new Uint16Array(16);function g4(n,e,t,c){var a,r;for(a=0;a<16;++a)n.table[a]=0;for(a=0;a<c;++a)n.table[e[t+a]]++;for(n.table[0]=0,r=0,a=0;a<16;++a)u6[a]=r,r+=n.table[a];for(a=0;a<c;++a)e[t+a]&&(n.trans[u6[e[t+a]]++]=a)}function U8(n){n.bitcount--||(n.tag=n.source[n.sourceIndex++],n.bitcount=7);var e=n.tag&1;return n.tag>>>=1,e}function e2(n,e,t){if(!e)return t;for(;n.bitcount<24;)n.tag|=n.source[n.sourceIndex++]<<n.bitcount,n.bitcount+=8;var c=n.tag&65535>>>16-e;return n.tag>>>=e,n.bitcount-=e,c+t}function L4(n,e){for(;n.bitcount<24;)n.tag|=n.source[n.sourceIndex++]<<n.bitcount,n.bitcount+=8;var t=0,c=0,a=0,r=n.tag;do c=2*c+(r&1),r>>>=1,++a,t+=e.table[a],c-=e.table[a];while(c>=0);return n.tag=r,n.bitcount-=a,e.trans[t+c]}function N8(n,e,t){var c,a,r,s,i,o;for(c=e2(n,5,257),a=e2(n,5,1),r=e2(n,4,4),s=0;s<19;++s)Q0[s]=0;for(s=0;s<r;++s){var l=e2(n,3,0);Q0[q8[s]]=l}for(g4(h6,Q0,0,19),i=0;i<c+a;){var h=L4(n,h6);switch(h){case 16:var f=Q0[i-1];for(o=e2(n,2,3);o;--o)Q0[i++]=f;break;case 17:for(o=e2(n,3,3);o;--o)Q0[i++]=0;break;case 18:for(o=e2(n,7,11);o;--o)Q0[i++]=0;break;default:Q0[i++]=h;break}}g4(e,Q0,0,c),g4(t,Q0,c,a)}function f6(n,e,t){for(;;){var c=L4(n,e);if(c===256)return V4;if(c<256)n.dest[n.destLen++]=c;else{var a,r,s,i;for(c-=257,a=e2(n,O4[c],F4[c]),r=L4(n,t),s=n.destLen-e2(n,J6[r],Q6[r]),i=s;i<s+a;++i)n.dest[n.destLen++]=n.dest[i]}}}function B8(n){for(var e,t,c;n.bitcount>8;)n.sourceIndex--,n.bitcount-=8;if(e=n.source[n.sourceIndex+1],e=256*e+n.source[n.sourceIndex],t=n.source[n.sourceIndex+3],t=256*t+n.source[n.sourceIndex+2],e!==(~t&65535))return Z6;for(n.sourceIndex+=4,c=e;c;--c)n.dest[n.destLen++]=n.source[n.sourceIndex++];return n.bitcount=0,V4}function G8(n,e){var t=new R8(n,e),c,a,r;do{switch(c=U8(t),a=e2(t,2,0),a){case 0:r=B8(t);break;case 1:r=f6(t,Y6,K6);break;case 2:N8(t,t.ltree,t.dtree),r=f6(t,t.ltree,t.dtree);break;default:r=Z6}if(r!==V4)throw new Error("Data error")}while(!c);return t.destLen<t.dest.length?typeof t.dest.slice=="function"?t.dest.slice(0,t.destLen):t.dest.subarray(0,t.destLen):t.dest}$8(Y6,K6);e7(O4,F4,4,3);e7(J6,Q6,2,1);O4[28]=0;F4[28]=258;var j8=G8;function W2(n,e,t,c,a){return Math.pow(1-a,3)*n+3*Math.pow(1-a,2)*a*e+3*(1-a)*Math.pow(a,2)*t+Math.pow(a,3)*c}function g2(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}g2.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};g2.prototype.addPoint=function(n,e){typeof n=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=n,this.x2=n),n<this.x1&&(this.x1=n),n>this.x2&&(this.x2=n)),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))};g2.prototype.addX=function(n){this.addPoint(n,null)};g2.prototype.addY=function(n){this.addPoint(null,n)};g2.prototype.addBezier=function(n,e,t,c,a,r,s,i){var o=[n,e],l=[t,c],h=[a,r],f=[s,i];this.addPoint(n,e),this.addPoint(s,i);for(var u=0;u<=1;u++){var d=6*o[u]-12*l[u]+6*h[u],m=-3*o[u]+9*l[u]-9*h[u]+3*f[u],p=3*l[u]-3*o[u];if(m===0){if(d===0)continue;var g=-p/d;0<g&&g<1&&(u===0&&this.addX(W2(o[u],l[u],h[u],f[u],g)),u===1&&this.addY(W2(o[u],l[u],h[u],f[u],g)));continue}var v=Math.pow(d,2)-4*p*m;if(!(v<0)){var b=(-d+Math.sqrt(v))/(2*m);0<b&&b<1&&(u===0&&this.addX(W2(o[u],l[u],h[u],f[u],b)),u===1&&this.addY(W2(o[u],l[u],h[u],f[u],b)));var y=(-d-Math.sqrt(v))/(2*m);0<y&&y<1&&(u===0&&this.addX(W2(o[u],l[u],h[u],f[u],y)),u===1&&this.addY(W2(o[u],l[u],h[u],f[u],y)))}}};g2.prototype.addQuad=function(n,e,t,c,a,r){var s=n+.6666666666666666*(t-n),i=e+2/3*(c-e),o=s+1/3*(a-n),l=i+1/3*(r-e);this.addBezier(n,e,s,i,o,l,a,r)};function Y1(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}Y1.prototype.moveTo=function(n,e){this.commands.push({type:"M",x:n,y:e})};Y1.prototype.lineTo=function(n,e){this.commands.push({type:"L",x:n,y:e})};Y1.prototype.curveTo=Y1.prototype.bezierCurveTo=function(n,e,t,c,a,r){this.commands.push({type:"C",x1:n,y1:e,x2:t,y2:c,x:a,y:r})};Y1.prototype.quadTo=Y1.prototype.quadraticCurveTo=function(n,e,t,c){this.commands.push({type:"Q",x1:n,y1:e,x:t,y:c})};Y1.prototype.close=Y1.prototype.closePath=function(){this.commands.push({type:"Z"})};Y1.prototype.extend=function(n){if(n.commands)n=n.commands;else if(n instanceof g2){var e=n;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,n)};Y1.prototype.getBoundingBox=function(){for(var n=new g2,e=0,t=0,c=0,a=0,r=0;r<this.commands.length;r++){var s=this.commands[r];switch(s.type){case"M":n.addPoint(s.x,s.y),e=c=s.x,t=a=s.y;break;case"L":n.addPoint(s.x,s.y),c=s.x,a=s.y;break;case"Q":n.addQuad(c,a,s.x1,s.y1,s.x,s.y),c=s.x,a=s.y;break;case"C":n.addBezier(c,a,s.x1,s.y1,s.x2,s.y2,s.x,s.y),c=s.x,a=s.y;break;case"Z":c=e,a=t;break;default:throw new Error("Unexpected path command "+s.type)}}return n.isEmpty()&&n.addPoint(0,0),n};Y1.prototype.draw=function(n){n.beginPath();for(var e=0;e<this.commands.length;e+=1){var t=this.commands[e];t.type==="M"?n.moveTo(t.x,t.y):t.type==="L"?n.lineTo(t.x,t.y):t.type==="C"?n.bezierCurveTo(t.x1,t.y1,t.x2,t.y2,t.x,t.y):t.type==="Q"?n.quadraticCurveTo(t.x1,t.y1,t.x,t.y):t.type==="Z"&&n.closePath()}this.fill&&(n.fillStyle=this.fill,n.fill()),this.stroke&&(n.strokeStyle=this.stroke,n.lineWidth=this.strokeWidth,n.stroke())};Y1.prototype.toPathData=function(n){n=n!==void 0?n:2;function e(s){return Math.round(s)===s?""+Math.round(s):s.toFixed(n)}function t(){for(var s=arguments,i="",o=0;o<arguments.length;o+=1){var l=s[o];l>=0&&o>0&&(i+=" "),i+=e(l)}return i}for(var c="",a=0;a<this.commands.length;a+=1){var r=this.commands[a];r.type==="M"?c+="M"+t(r.x,r.y):r.type==="L"?c+="L"+t(r.x,r.y):r.type==="C"?c+="C"+t(r.x1,r.y1,r.x2,r.y2,r.x,r.y):r.type==="Q"?c+="Q"+t(r.x1,r.y1,r.x,r.y):r.type==="Z"&&(c+="Z")}return c};Y1.prototype.toSVG=function(n){var e='<path d="';return e+=this.toPathData(n),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};Y1.prototype.toDOMElement=function(n){var e=this.toPathData(n),t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",e),t};function t7(n){throw new Error(n)}function d6(n,e){n||t7(e)}var r1={fail:t7,argument:d6,assert:d6},p6=32768,m6=2147483648,Z2={},B={},i1={};function $0(n){return function(){return n}}B.BYTE=function(n){return r1.argument(n>=0&&n<=255,"Byte value should be between 0 and 255."),[n]};i1.BYTE=$0(1);B.CHAR=function(n){return[n.charCodeAt(0)]};i1.CHAR=$0(1);B.CHARARRAY=function(n){typeof n>"u"&&(n="",console.warn("Undefined CHARARRAY encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var e=[],t=0;t<n.length;t+=1)e[t]=n.charCodeAt(t);return e};i1.CHARARRAY=function(n){return typeof n>"u"?0:n.length};B.USHORT=function(n){return[n>>8&255,n&255]};i1.USHORT=$0(2);B.SHORT=function(n){return n>=p6&&(n=-(2*p6-n)),[n>>8&255,n&255]};i1.SHORT=$0(2);B.UINT24=function(n){return[n>>16&255,n>>8&255,n&255]};i1.UINT24=$0(3);B.ULONG=function(n){return[n>>24&255,n>>16&255,n>>8&255,n&255]};i1.ULONG=$0(4);B.LONG=function(n){return n>=m6&&(n=-(2*m6-n)),[n>>24&255,n>>16&255,n>>8&255,n&255]};i1.LONG=$0(4);B.FIXED=B.ULONG;i1.FIXED=i1.ULONG;B.FWORD=B.SHORT;i1.FWORD=i1.SHORT;B.UFWORD=B.USHORT;i1.UFWORD=i1.USHORT;B.LONGDATETIME=function(n){return[0,0,0,0,n>>24&255,n>>16&255,n>>8&255,n&255]};i1.LONGDATETIME=$0(8);B.TAG=function(n){return r1.argument(n.length===4,"Tag should be exactly 4 ASCII characters."),[n.charCodeAt(0),n.charCodeAt(1),n.charCodeAt(2),n.charCodeAt(3)]};i1.TAG=$0(4);B.Card8=B.BYTE;i1.Card8=i1.BYTE;B.Card16=B.USHORT;i1.Card16=i1.USHORT;B.OffSize=B.BYTE;i1.OffSize=i1.BYTE;B.SID=B.USHORT;i1.SID=i1.USHORT;B.NUMBER=function(n){return n>=-107&&n<=107?[n+139]:n>=108&&n<=1131?(n=n-108,[(n>>8)+247,n&255]):n>=-1131&&n<=-108?(n=-n-108,[(n>>8)+251,n&255]):n>=-32768&&n<=32767?B.NUMBER16(n):B.NUMBER32(n)};i1.NUMBER=function(n){return B.NUMBER(n).length};B.NUMBER16=function(n){return[28,n>>8&255,n&255]};i1.NUMBER16=$0(3);B.NUMBER32=function(n){return[29,n>>24&255,n>>16&255,n>>8&255,n&255]};i1.NUMBER32=$0(5);B.REAL=function(n){var e=n.toString(),t=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(t){var c=parseFloat("1e"+((t[2]?+t[2]:0)+t[1].length));e=(Math.round(n*c)/c).toString()}for(var a="",r=0,s=e.length;r<s;r+=1){var i=e[r];i==="e"?a+=e[++r]==="-"?"c":"b":i==="."?a+="a":i==="-"?a+="e":a+=i}a+=a.length&1?"f":"ff";for(var o=[30],l=0,h=a.length;l<h;l+=2)o.push(parseInt(a.substr(l,2),16));return o};i1.REAL=function(n){return B.REAL(n).length};B.NAME=B.CHARARRAY;i1.NAME=i1.CHARARRAY;B.STRING=B.CHARARRAY;i1.STRING=i1.CHARARRAY;Z2.UTF8=function(n,e,t){for(var c=[],a=t,r=0;r<a;r++,e+=1)c[r]=n.getUint8(e);return String.fromCharCode.apply(null,c)};Z2.UTF16=function(n,e,t){for(var c=[],a=t/2,r=0;r<a;r++,e+=2)c[r]=n.getUint16(e);return String.fromCharCode.apply(null,c)};B.UTF16=function(n){for(var e=[],t=0;t<n.length;t+=1){var c=n.charCodeAt(t);e[e.length]=c>>8&255,e[e.length]=c&255}return e};i1.UTF16=function(n){return n.length*2};var A4={"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"};Z2.MACSTRING=function(n,e,t,c){var a=A4[c];if(a!==void 0){for(var r="",s=0;s<t;s++){var i=n.getUint8(e+s);i<=127?r+=String.fromCharCode(i):r+=a[i&127]}return r}};var d5=typeof WeakMap=="function"&&new WeakMap,p5,W8=function(n){if(!p5){p5={};for(var e in A4)p5[e]=new String(e)}var t=p5[n];if(t!==void 0){if(d5){var c=d5.get(t);if(c!==void 0)return c}var a=A4[n];if(a!==void 0){for(var r={},s=0;s<a.length;s++)r[a.charCodeAt(s)]=s+128;return d5&&d5.set(t,r),r}}};B.MACSTRING=function(n,e){var t=W8(e);if(t!==void 0){for(var c=[],a=0;a<n.length;a++){var r=n.charCodeAt(a);if(r>=128&&(r=t[r],r===void 0))return;c[a]=r}return c}};i1.MACSTRING=function(n,e){var t=B.MACSTRING(n,e);return t!==void 0?t.length:0};function S4(n){return n>=-128&&n<=127}function X8(n,e,t){for(var c=0,a=n.length;e<a&&c<64&&n[e]===0;)++e,++c;return t.push(128|c-1),e}function Z8(n,e,t){for(var c=0,a=n.length,r=e;r<a&&c<64;){var s=n[r];if(!S4(s)||s===0&&r+1<a&&n[r+1]===0)break;++r,++c}t.push(c-1);for(var i=e;i<r;++i)t.push(n[i]+256&255);return r}function Y8(n,e,t){for(var c=0,a=n.length,r=e;r<a&&c<64;){var s=n[r];if(s===0||S4(s)&&r+1<a&&S4(n[r+1]))break;++r,++c}t.push(64|c-1);for(var i=e;i<r;++i){var o=n[i];t.push(o+65536>>8&255,o+256&255)}return r}B.VARDELTAS=function(n){for(var e=0,t=[];e<n.length;){var c=n[e];c===0?e=X8(n,e,t):c>=-128&&c<=127?e=Z8(n,e,t):e=Y8(n,e,t)}return t};B.INDEX=function(n){for(var e=1,t=[e],c=[],a=0;a<n.length;a+=1){var r=B.OBJECT(n[a]);Array.prototype.push.apply(c,r),e+=r.length,t.push(e)}if(c.length===0)return[0,0];for(var s=[],i=1+Math.floor(Math.log(e)/Math.log(2))/8|0,o=[void 0,B.BYTE,B.USHORT,B.UINT24,B.ULONG][i],l=0;l<t.length;l+=1){var h=o(t[l]);Array.prototype.push.apply(s,h)}return Array.prototype.concat(B.Card16(n.length),B.OffSize(i),s,c)};i1.INDEX=function(n){return B.INDEX(n).length};B.DICT=function(n){for(var e=[],t=Object.keys(n),c=t.length,a=0;a<c;a+=1){var r=parseInt(t[a],0),s=n[r];e=e.concat(B.OPERAND(s.value,s.type)),e=e.concat(B.OPERATOR(r))}return e};i1.DICT=function(n){return B.DICT(n).length};B.OPERATOR=function(n){return n<1200?[n]:[12,n-1200]};B.OPERAND=function(n,e){var t=[];if(Array.isArray(e))for(var c=0;c<e.length;c+=1)r1.argument(n.length===e.length,"Not enough arguments given for type"+e),t=t.concat(B.OPERAND(n[c],e[c]));else if(e==="SID")t=t.concat(B.NUMBER(n));else if(e==="offset")t=t.concat(B.NUMBER32(n));else if(e==="number")t=t.concat(B.NUMBER(n));else if(e==="real")t=t.concat(B.REAL(n));else throw new Error("Unknown operand type "+e);return t};B.OP=B.BYTE;i1.OP=i1.BYTE;var m5=typeof WeakMap=="function"&&new WeakMap;B.CHARSTRING=function(n){if(m5){var e=m5.get(n);if(e!==void 0)return e}for(var t=[],c=n.length,a=0;a<c;a+=1){var r=n[a];t=t.concat(B[r.type](r.value))}return m5&&m5.set(n,t),t};i1.CHARSTRING=function(n){return B.CHARSTRING(n).length};B.OBJECT=function(n){var e=B[n.type];return r1.argument(e!==void 0,"No encoding function for type "+n.type),e(n.value)};i1.OBJECT=function(n){var e=i1[n.type];return r1.argument(e!==void 0,"No sizeOf function for type "+n.type),e(n.value)};B.TABLE=function(n){for(var e=[],t=n.fields.length,c=[],a=[],r=0;r<t;r+=1){var s=n.fields[r],i=B[s.type];r1.argument(i!==void 0,"No encoding function for field type "+s.type+" ("+s.name+")");var o=n[s.name];o===void 0&&(o=s.value);var l=i(o);s.type==="TABLE"?(a.push(e.length),e=e.concat([0,0]),c.push(l)):e=e.concat(l)}for(var h=0;h<c.length;h+=1){var f=a[h],u=e.length;r1.argument(u<65536,"Table "+n.tableName+" too big."),e[f]=u>>8,e[f+1]=u&255,e=e.concat(c[h])}return e};i1.TABLE=function(n){for(var e=0,t=n.fields.length,c=0;c<t;c+=1){var a=n.fields[c],r=i1[a.type];r1.argument(r!==void 0,"No sizeOf function for field type "+a.type+" ("+a.name+")");var s=n[a.name];s===void 0&&(s=a.value),e+=r(s),a.type==="TABLE"&&(e+=2)}return e};B.RECORD=B.TABLE;i1.RECORD=i1.TABLE;B.LITERAL=function(n){return n};i1.LITERAL=function(n){return n.length};function n0(n,e,t){if(e.length&&(e[0].name!=="coverageFormat"||e[0].value===1))for(var c=0;c<e.length;c+=1){var a=e[c];this[a.name]=a.value}if(this.tableName=n,this.fields=e,t)for(var r=Object.keys(t),s=0;s<r.length;s+=1){var i=r[s],o=t[i];this[i]!==void 0&&(this[i]=o)}}n0.prototype.encode=function(){return B.TABLE(this)};n0.prototype.sizeOf=function(){return i1.TABLE(this)};function E3(n,e,t){t===void 0&&(t=e.length);var c=new Array(e.length+1);c[0]={name:n+"Count",type:"USHORT",value:t};for(var a=0;a<e.length;a++)c[a+1]={name:n+a,type:"USHORT",value:e[a]};return c}function C4(n,e,t){var c=e.length,a=new Array(c+1);a[0]={name:n+"Count",type:"USHORT",value:c};for(var r=0;r<c;r++)a[r+1]={name:n+r,type:"TABLE",value:t(e[r],r)};return a}function T3(n,e,t){var c=e.length,a=[];a[0]={name:n+"Count",type:"USHORT",value:c};for(var r=0;r<c;r++)a=a.concat(t(e[r],r));return a}function x5(n){n.format===1?n0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(E3("glyph",n.glyphs))):n.format===2?n0.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(T3("rangeRecord",n.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}]}))):r1.assert(!1,"Coverage format must be 1 or 2.")}x5.prototype=Object.create(n0.prototype);x5.prototype.constructor=x5;function M5(n){n0.call(this,"scriptListTable",T3("scriptRecord",n,function(e,t){var c=e.script,a=c.defaultLangSys;return r1.assert(!!a,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+t,type:"TAG",value:e.tag},{name:"script"+t,type:"TABLE",value:new n0("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new n0("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:a.reqFeatureIndex}].concat(E3("featureIndex",a.featureIndexes)))}].concat(T3("langSys",c.langSysRecords,function(r,s){var i=r.langSys;return[{name:"langSysTag"+s,type:"TAG",value:r.tag},{name:"langSys"+s,type:"TABLE",value:new n0("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:i.reqFeatureIndex}].concat(E3("featureIndex",i.featureIndexes)))}]})))}]}))}M5.prototype=Object.create(n0.prototype);M5.prototype.constructor=M5;function w5(n){n0.call(this,"featureListTable",T3("featureRecord",n,function(e,t){var c=e.feature;return[{name:"featureTag"+t,type:"TAG",value:e.tag},{name:"feature"+t,type:"TABLE",value:new n0("featureTable",[{name:"featureParams",type:"USHORT",value:c.featureParams}].concat(E3("lookupListIndex",c.lookupListIndexes)))}]}))}w5.prototype=Object.create(n0.prototype);w5.prototype.constructor=w5;function z5(n,e){n0.call(this,"lookupListTable",C4("lookup",n,function(t){var c=e[t.lookupType];return r1.assert(!!c,"Unable to write GSUB lookup type "+t.lookupType+" tables."),new n0("lookupTable",[{name:"lookupType",type:"USHORT",value:t.lookupType},{name:"lookupFlag",type:"USHORT",value:t.lookupFlag}].concat(C4("subtable",t.subtables,c)))}))}z5.prototype=Object.create(n0.prototype);z5.prototype.constructor=z5;var j={Table:n0,Record:n0,Coverage:x5,ScriptList:M5,FeatureList:w5,LookupList:z5,ushortList:E3,tableList:C4,recordList:T3};function g6(n,e){return n.getUint8(e)}function k5(n,e){return n.getUint16(e,!1)}function K8(n,e){return n.getInt16(e,!1)}function _4(n,e){return n.getUint32(e,!1)}function n7(n,e){var t=n.getInt16(e,!1),c=n.getUint16(e+2,!1);return t+c/65535}function J8(n,e){for(var t="",c=e;c<e+4;c+=1)t+=String.fromCharCode(n.getInt8(c));return t}function Q8(n,e,t){for(var c=0,a=0;a<t;a+=1)c<<=8,c+=n.getUint8(e+a);return c}function en(n,e,t){for(var c=[],a=e;a<t;a+=1)c.push(n.getUint8(a));return c}function tn(n){for(var e="",t=0;t<n.length;t+=1)e+=String.fromCharCode(n[t]);return e}var nn={byte:1,uShort:2,short:2,uLong:4,fixed:4,longDateTime:8,tag:4};function V(n,e){this.data=n,this.offset=e,this.relativeOffset=0}V.prototype.parseByte=function(){var n=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,n};V.prototype.parseChar=function(){var n=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,n};V.prototype.parseCard8=V.prototype.parseByte;V.prototype.parseUShort=function(){var n=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,n};V.prototype.parseCard16=V.prototype.parseUShort;V.prototype.parseSID=V.prototype.parseUShort;V.prototype.parseOffset16=V.prototype.parseUShort;V.prototype.parseShort=function(){var n=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,n};V.prototype.parseF2Dot14=function(){var n=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,n};V.prototype.parseULong=function(){var n=_4(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};V.prototype.parseOffset32=V.prototype.parseULong;V.prototype.parseFixed=function(){var n=n7(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};V.prototype.parseString=function(n){var e=this.data,t=this.offset+this.relativeOffset,c="";this.relativeOffset+=n;for(var a=0;a<n;a++)c+=String.fromCharCode(e.getUint8(t+a));return c};V.prototype.parseTag=function(){return this.parseString(4)};V.prototype.parseLongDateTime=function(){var n=_4(this.data,this.offset+this.relativeOffset+4);return n-=2082844800,this.relativeOffset+=8,n};V.prototype.parseVersion=function(n){var e=k5(this.data,this.offset+this.relativeOffset),t=k5(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,n===void 0&&(n=4096),e+t/n/10};V.prototype.skip=function(n,e){e===void 0&&(e=1),this.relativeOffset+=nn[n]*e};V.prototype.parseULongList=function(n){n===void 0&&(n=this.parseULong());for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getUint32(c),c+=4;return this.relativeOffset+=n*4,e};V.prototype.parseOffset16List=V.prototype.parseUShortList=function(n){n===void 0&&(n=this.parseUShort());for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getUint16(c),c+=2;return this.relativeOffset+=n*2,e};V.prototype.parseShortList=function(n){for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getInt16(c),c+=2;return this.relativeOffset+=n*2,e};V.prototype.parseByteList=function(n){for(var e=new Array(n),t=this.data,c=this.offset+this.relativeOffset,a=0;a<n;a++)e[a]=t.getUint8(c++);return this.relativeOffset+=n,e};V.prototype.parseList=function(n,e){e||(e=n,n=this.parseUShort());for(var t=new Array(n),c=0;c<n;c++)t[c]=e.call(this);return t};V.prototype.parseList32=function(n,e){e||(e=n,n=this.parseULong());for(var t=new Array(n),c=0;c<n;c++)t[c]=e.call(this);return t};V.prototype.parseRecordList=function(n,e){e||(e=n,n=this.parseUShort());for(var t=new Array(n),c=Object.keys(e),a=0;a<n;a++){for(var r={},s=0;s<c.length;s++){var i=c[s],o=e[i];r[i]=o.call(this)}t[a]=r}return t};V.prototype.parseRecordList32=function(n,e){e||(e=n,n=this.parseULong());for(var t=new Array(n),c=Object.keys(e),a=0;a<n;a++){for(var r={},s=0;s<c.length;s++){var i=c[s],o=e[i];r[i]=o.call(this)}t[a]=r}return t};V.prototype.parseStruct=function(n){if(typeof n=="function")return n.call(this);for(var e=Object.keys(n),t={},c=0;c<e.length;c++){var a=e[c],r=n[a];t[a]=r.call(this)}return t};V.prototype.parseValueRecord=function(n){if(n===void 0&&(n=this.parseUShort()),n!==0){var e={};return n&1&&(e.xPlacement=this.parseShort()),n&2&&(e.yPlacement=this.parseShort()),n&4&&(e.xAdvance=this.parseShort()),n&8&&(e.yAdvance=this.parseShort()),n&16&&(e.xPlaDevice=void 0,this.parseShort()),n&32&&(e.yPlaDevice=void 0,this.parseShort()),n&64&&(e.xAdvDevice=void 0,this.parseShort()),n&128&&(e.yAdvDevice=void 0,this.parseShort()),e}};V.prototype.parseValueRecordList=function(){for(var n=this.parseUShort(),e=this.parseUShort(),t=new Array(e),c=0;c<e;c++)t[c]=this.parseValueRecord(n);return t};V.prototype.parsePointer=function(n){var e=this.parseOffset16();if(e>0)return new V(this.data,this.offset+e).parseStruct(n)};V.prototype.parsePointer32=function(n){var e=this.parseOffset32();if(e>0)return new V(this.data,this.offset+e).parseStruct(n)};V.prototype.parseListOfLists=function(n){for(var e=this.parseOffset16List(),t=e.length,c=this.relativeOffset,a=new Array(t),r=0;r<t;r++){var s=e[r];if(s===0){a[r]=void 0;continue}if(this.relativeOffset=s,n){for(var i=this.parseOffset16List(),o=new Array(i.length),l=0;l<i.length;l++)this.relativeOffset=s+i[l],o[l]=n.call(this);a[r]=o}else a[r]=this.parseUShortList()}return this.relativeOffset=c,a};V.prototype.parseCoverage=function(){var n=this.offset+this.relativeOffset,e=this.parseUShort(),t=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(t)};if(e===2){for(var c=new Array(t),a=0;a<t;a++)c[a]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:c}}throw new Error("0x"+n.toString(16)+": Coverage format must be 1 or 2.")};V.prototype.parseClassDef=function(){var n=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:V.uShort,end:V.uShort,classId:V.uShort})};throw new Error("0x"+n.toString(16)+": ClassDef format must be 1 or 2.")};V.list=function(n,e){return function(){return this.parseList(n,e)}};V.list32=function(n,e){return function(){return this.parseList32(n,e)}};V.recordList=function(n,e){return function(){return this.parseRecordList(n,e)}};V.recordList32=function(n,e){return function(){return this.parseRecordList32(n,e)}};V.pointer=function(n){return function(){return this.parsePointer(n)}};V.pointer32=function(n){return function(){return this.parsePointer32(n)}};V.tag=V.prototype.parseTag;V.byte=V.prototype.parseByte;V.uShort=V.offset16=V.prototype.parseUShort;V.uShortList=V.prototype.parseUShortList;V.uLong=V.offset32=V.prototype.parseULong;V.uLongList=V.prototype.parseULongList;V.struct=V.prototype.parseStruct;V.coverage=V.prototype.parseCoverage;V.classDef=V.prototype.parseClassDef;var v6={reserved:V.uShort,reqFeatureIndex:V.uShort,featureIndexes:V.uShortList};V.prototype.parseScriptList=function(){return this.parsePointer(V.recordList({tag:V.tag,script:V.pointer({defaultLangSys:V.pointer(v6),langSysRecords:V.recordList({tag:V.tag,langSys:V.pointer(v6)})})}))||[]};V.prototype.parseFeatureList=function(){return this.parsePointer(V.recordList({tag:V.tag,feature:V.pointer({featureParams:V.offset16,lookupListIndexes:V.uShortList})}))||[]};V.prototype.parseLookupList=function(n){return this.parsePointer(V.list(V.pointer(function(){var e=this.parseUShort();r1.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");var t=this.parseUShort(),c=t&16;return{lookupType:e,lookupFlag:t,subtables:this.parseList(V.pointer(n[e])),markFilteringSet:c?this.parseUShort():void 0}})))||[]};V.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){var n=this.parseUShort(),e=this.parseUShort();r1.argument(n===1&&e<1,"GPOS/GSUB feature variations table unknown.");var t=this.parseRecordList32({conditionSetOffset:V.offset32,featureTableSubstitutionOffset:V.offset32});return t})||[]};var Y={getByte:g6,getCard8:g6,getUShort:k5,getCard16:k5,getShort:K8,getULong:_4,getFixed:n7,getTag:J8,getOffset:Q8,getBytes:en,bytesToString:tn,Parser:V};function cn(n,e){e.parseUShort(),n.length=e.parseULong(),n.language=e.parseULong();var t;n.groupCount=t=e.parseULong(),n.glyphIndexMap={};for(var c=0;c<t;c+=1)for(var a=e.parseULong(),r=e.parseULong(),s=e.parseULong(),i=a;i<=r;i+=1)n.glyphIndexMap[i]=s,s++}function an(n,e,t,c,a){n.length=e.parseUShort(),n.language=e.parseUShort();var r;n.segCount=r=e.parseUShort()>>1,e.skip("uShort",3),n.glyphIndexMap={};for(var s=new Y.Parser(t,c+a+14),i=new Y.Parser(t,c+a+16+r*2),o=new Y.Parser(t,c+a+16+r*4),l=new Y.Parser(t,c+a+16+r*6),h=c+a+16+r*8,f=0;f<r-1;f+=1)for(var u=void 0,d=s.parseUShort(),m=i.parseUShort(),p=o.parseShort(),g=l.parseUShort(),v=m;v<=d;v+=1)g!==0?(h=l.offset+l.relativeOffset-2,h+=g,h+=(v-m)*2,u=Y.getUShort(t,h),u!==0&&(u=u+p&65535)):u=v+p&65535,n.glyphIndexMap[v]=u}function rn(n,e){var t={};t.version=Y.getUShort(n,e),r1.argument(t.version===0,"cmap table version should be 0."),t.numTables=Y.getUShort(n,e+2);for(var c=-1,a=t.numTables-1;a>=0;a-=1){var r=Y.getUShort(n,e+4+a*8),s=Y.getUShort(n,e+4+a*8+2);if(r===3&&(s===0||s===1||s===10)||r===0&&(s===0||s===1||s===2||s===3||s===4)){c=Y.getULong(n,e+4+a*8+4);break}}if(c===-1)throw new Error("No valid cmap sub-tables found.");var i=new Y.Parser(n,e+c);if(t.format=i.parseUShort(),t.format===12)cn(t,i);else if(t.format===4)an(t,i,n,e,c);else throw new Error("Only format 4 and 12 cmap tables are supported (found format "+t.format+").");return t}function sn(n,e,t){n.segments.push({end:e,start:e,delta:-(e-t),offset:0,glyphIndex:t})}function on(n){n.segments.push({end:65535,start:65535,delta:1,offset:0})}function ln(n){var e=!0,t;for(t=n.length-1;t>0;t-=1){var c=n.get(t);if(c.unicode>65535){console.log("Adding CMAP format 12 (needed!)"),e=!1;break}}var a=[{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||(a=a.concat([{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}])),a=a.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 r=new j.Table("cmap",a);for(r.segments=[],t=0;t<n.length;t+=1){for(var s=n.get(t),i=0;i<s.unicodes.length;i+=1)sn(r,s.unicodes[i],t);r.segments=r.segments.sort(function(b,y){return b.start-y.start})}on(r);var o=r.segments.length,l=0,h=[],f=[],u=[],d=[],m=[],p=[];for(t=0;t<o;t+=1){var g=r.segments[t];g.end<=65535&&g.start<=65535?(h=h.concat({name:"end_"+t,type:"USHORT",value:g.end}),f=f.concat({name:"start_"+t,type:"USHORT",value:g.start}),u=u.concat({name:"idDelta_"+t,type:"SHORT",value:g.delta}),d=d.concat({name:"idRangeOffset_"+t,type:"USHORT",value:g.offset}),g.glyphId!==void 0&&(m=m.concat({name:"glyph_"+t,type:"USHORT",value:g.glyphId}))):l+=1,!e&&g.glyphIndex!==void 0&&(p=p.concat({name:"cmap12Start_"+t,type:"ULONG",value:g.start}),p=p.concat({name:"cmap12End_"+t,type:"ULONG",value:g.end}),p=p.concat({name:"cmap12Glyph_"+t,type:"ULONG",value:g.glyphIndex}))}if(r.segCountX2=(o-l)*2,r.searchRange=Math.pow(2,Math.floor(Math.log(o-l)/Math.log(2)))*2,r.entrySelector=Math.log(r.searchRange/2)/Math.log(2),r.rangeShift=r.segCountX2-r.searchRange,r.fields=r.fields.concat(h),r.fields.push({name:"reservedPad",type:"USHORT",value:0}),r.fields=r.fields.concat(f),r.fields=r.fields.concat(u),r.fields=r.fields.concat(d),r.fields=r.fields.concat(m),r.cmap4Length=14+h.length*2+2+f.length*2+u.length*2+d.length*2+m.length*2,!e){var v=16+p.length*4;r.cmap12Offset=20+r.cmap4Length,r.fields=r.fields.concat([{name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:v},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:p.length/3}]),r.fields=r.fields.concat(p)}return r}var c7={parse:rn,make:ln},b5=[".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"],hn=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],un=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"],C2=[".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 a7(n){this.font=n}a7.prototype.charToGlyphIndex=function(n){var e=n.codePointAt(0),t=this.font.glyphs;if(t){for(var c=0;c<t.length;c+=1)for(var a=t.get(c),r=0;r<a.unicodes.length;r+=1)if(a.unicodes[r]===e)return c}return null};function r7(n){this.cmap=n}r7.prototype.charToGlyphIndex=function(n){return this.cmap.glyphIndexMap[n.codePointAt(0)]||0};function L5(n,e){this.encoding=n,this.charset=e}L5.prototype.charToGlyphIndex=function(n){var e=n.codePointAt(0),t=this.encoding[e];return this.charset.indexOf(t)};function D4(n){switch(n.version){case 1:this.names=C2.slice();break;case 2:this.names=new Array(n.numberOfGlyphs);for(var e=0;e<n.numberOfGlyphs;e++)n.glyphNameIndex[e]<C2.length?this.names[e]=C2[n.glyphNameIndex[e]]:this.names[e]=n.names[n.glyphNameIndex[e]-C2.length];break;case 2.5:this.names=new Array(n.numberOfGlyphs);for(var t=0;t<n.numberOfGlyphs;t++)this.names[t]=C2[t+n.glyphNameIndex[t]];break;case 3:this.names=[];break;default:this.names=[];break}}D4.prototype.nameToGlyphIndex=function(n){return this.names.indexOf(n)};D4.prototype.glyphIndexToName=function(n){return this.names[n]};function fn(n){for(var e,t=n.tables.cmap.glyphIndexMap,c=Object.keys(t),a=0;a<c.length;a+=1){var r=c[a],s=t[r];e=n.glyphs.get(s),e.addUnicode(parseInt(r))}for(var i=0;i<n.glyphs.length;i+=1)e=n.glyphs.get(i),n.cffEncoding?n.isCIDFont?e.name="gid"+i:e.name=n.cffEncoding.charset[i]:n.glyphNames.names&&(e.name=n.glyphNames.glyphIndexToName(i))}function dn(n){n._IndexToUnicodeMap={};for(var e=n.tables.cmap.glyphIndexMap,t=Object.keys(e),c=0;c<t.length;c+=1){var a=t[c],r=e[a];n._IndexToUnicodeMap[r]===void 0?n._IndexToUnicodeMap[r]={unicodes:[parseInt(a)]}:n._IndexToUnicodeMap[r].unicodes.push(parseInt(a))}}function pn(n,e){e.lowMemory?dn(n):fn(n)}function mn(n,e,t,c,a){n.beginPath(),n.moveTo(e,t),n.lineTo(c,a),n.stroke()}var S2={line:mn};function gn(n,e){var t=e||new Y1;return{configurable:!0,get:function(){return typeof t=="function"&&(t=t()),t},set:function(c){t=c}}}function H0(n){this.bindConstructorValues(n)}H0.prototype.bindConstructorValues=function(n){this.index=n.index||0,this.name=n.name||null,this.unicode=n.unicode||void 0,this.unicodes=n.unicodes||n.unicode!==void 0?[n.unicode]:[],"xMin"in n&&(this.xMin=n.xMin),"yMin"in n&&(this.yMin=n.yMin),"xMax"in n&&(this.xMax=n.xMax),"yMax"in n&&(this.yMax=n.yMax),"advanceWidth"in n&&(this.advanceWidth=n.advanceWidth),Object.defineProperty(this,"path",gn(this,n.path))};H0.prototype.addUnicode=function(n){this.unicodes.length===0&&(this.unicode=n),this.unicodes.push(n)};H0.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};H0.prototype.getPath=function(n,e,t,c,a){n=n!==void 0?n:0,e=e!==void 0?e:0,t=t!==void 0?t:72;var r,s;c||(c={});var i=c.xScale,o=c.yScale;if(c.hinting&&a&&a.hinting&&(s=this.path&&a.hinting.exec(this,t)),s)r=a.hinting.getCommands(s),n=Math.round(n),e=Math.round(e),i=o=1;else{r=this.path.commands;var l=1/(this.path.unitsPerEm||1e3)*t;i===void 0&&(i=l),o===void 0&&(o=l)}for(var h=new Y1,f=0;f<r.length;f+=1){var u=r[f];u.type==="M"?h.moveTo(n+u.x*i,e+-u.y*o):u.type==="L"?h.lineTo(n+u.x*i,e+-u.y*o):u.type==="Q"?h.quadraticCurveTo(n+u.x1*i,e+-u.y1*o,n+u.x*i,e+-u.y*o):u.type==="C"?h.curveTo(n+u.x1*i,e+-u.y1*o,n+u.x2*i,e+-u.y2*o,n+u.x*i,e+-u.y*o):u.type==="Z"&&h.closePath()}return h};H0.prototype.getContours=function(){if(this.points===void 0)return[];for(var n=[],e=[],t=0;t<this.points.length;t+=1){var c=this.points[t];e.push(c),c.lastPointOfContour&&(n.push(e),e=[])}return r1.argument(e.length===0,"There are still points left in the current contour."),n};H0.prototype.getMetrics=function(){for(var n=this.path.commands,e=[],t=[],c=0;c<n.length;c+=1){var a=n[c];a.type!=="Z"&&(e.push(a.x),t.push(a.y)),(a.type==="Q"||a.type==="C")&&(e.push(a.x1),t.push(a.y1)),a.type==="C"&&(e.push(a.x2),t.push(a.y2))}var r={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,t),leftSideBearing:this.leftSideBearing};return isFinite(r.xMin)||(r.xMin=0),isFinite(r.xMax)||(r.xMax=this.advanceWidth),isFinite(r.yMin)||(r.yMin=0),isFinite(r.yMax)||(r.yMax=0),r.rightSideBearing=this.advanceWidth-r.leftSideBearing-(r.xMax-r.xMin),r};H0.prototype.draw=function(n,e,t,c,a){this.getPath(e,t,c,a).draw(n)};H0.prototype.drawPoints=function(n,e,t,c){function a(f,u,d,m){n.beginPath();for(var p=0;p<f.length;p+=1)n.moveTo(u+f[p].x*m,d+f[p].y*m),n.arc(u+f[p].x*m,d+f[p].y*m,2,0,Math.PI*2,!1);n.closePath(),n.fill()}e=e!==void 0?e:0,t=t!==void 0?t:0,c=c!==void 0?c:24;for(var r=1/this.path.unitsPerEm*c,s=[],i=[],o=this.path,l=0;l<o.commands.length;l+=1){var h=o.commands[l];h.x!==void 0&&s.push({x:h.x,y:-h.y}),h.x1!==void 0&&i.push({x:h.x1,y:-h.y1}),h.x2!==void 0&&i.push({x:h.x2,y:-h.y2})}n.fillStyle="blue",a(s,e,t,r),n.fillStyle="red",a(i,e,t,r)};H0.prototype.drawMetrics=function(n,e,t,c){var a;e=e!==void 0?e:0,t=t!==void 0?t:0,c=c!==void 0?c:24,a=1/this.path.unitsPerEm*c,n.lineWidth=1,n.strokeStyle="black",S2.line(n,e,-1e4,e,1e4),S2.line(n,-1e4,t,1e4,t);var r=this.xMin||0,s=this.yMin||0,i=this.xMax||0,o=this.yMax||0,l=this.advanceWidth||0;n.strokeStyle="blue",S2.line(n,e+r*a,-1e4,e+r*a,1e4),S2.line(n,e+i*a,-1e4,e+i*a,1e4),S2.line(n,-1e4,t+-s*a,1e4,t+-s*a),S2.line(n,-1e4,t+-o*a,1e4,t+-o*a),n.strokeStyle="green",S2.line(n,e+l*a,-1e4,e+l*a,1e4)};function g5(n,e,t){Object.defineProperty(n,e,{get:function(){return n.path,n[t]},set:function(c){n[t]=c},enumerable:!0,configurable:!0})}function R4(n,e){if(this.font=n,this.glyphs={},Array.isArray(e))for(var t=0;t<e.length;t++){var c=e[t];c.path.unitsPerEm=n.unitsPerEm,this.glyphs[t]=c}this.length=e&&e.length||0}R4.prototype.get=function(n){if(this.glyphs[n]===void 0){this.font._push(n),typeof this.glyphs[n]=="function"&&(this.glyphs[n]=this.glyphs[n]());var e=this.glyphs[n],t=this.font._IndexToUnicodeMap[n];if(t)for(var c=0;c<t.unicodes.length;c++)e.addUnicode(t.unicodes[c]);this.font.cffEncoding?this.font.isCIDFont?e.name="gid"+n:e.name=this.font.cffEncoding.charset[n]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(n)),this.glyphs[n].advanceWidth=this.font._hmtxTableData[n].advanceWidth,this.glyphs[n].leftSideBearing=this.font._hmtxTableData[n].leftSideBearing}else typeof this.glyphs[n]=="function"&&(this.glyphs[n]=this.glyphs[n]());return this.glyphs[n]};R4.prototype.push=function(n,e){this.glyphs[n]=e,this.length++};function vn(n,e){return new H0({index:e,font:n})}function bn(n,e,t,c,a,r){return function(){var s=new H0({index:e,font:n});return s.path=function(){t(s,c,a);var i=r(n.glyphs,s);return i.unitsPerEm=n.unitsPerEm,i},g5(s,"xMin","_xMin"),g5(s,"xMax","_xMax"),g5(s,"yMin","_yMin"),g5(s,"yMax","_yMax"),s}}function yn(n,e,t,c){return function(){var a=new H0({index:e,font:n});return a.path=function(){var r=t(n,a,c);return r.unitsPerEm=n.unitsPerEm,r},a}}var n2={GlyphSet:R4,glyphLoader:vn,ttfGlyphLoader:bn,cffGlyphLoader:yn};function s7(n,e){if(n===e)return!0;if(Array.isArray(n)&&Array.isArray(e)){if(n.length!==e.length)return!1;for(var t=0;t<n.length;t+=1)if(!s7(n[t],e[t]))return!1;return!0}else return!1}function P4(n){var e;return n.length<1240?e=107:n.length<33900?e=1131:e=32768,e}function f2(n,e,t){var c=[],a=[],r=Y.getCard16(n,e),s,i;if(r!==0){var o=Y.getByte(n,e+2);s=e+(r+1)*o+2;for(var l=e+3,h=0;h<r+1;h+=1)c.push(Y.getOffset(n,l,o)),l+=o;i=s+c[r]}else i=e+2;for(var f=0;f<c.length-1;f+=1){var u=Y.getBytes(n,s+c[f],s+c[f+1]);t&&(u=t(u)),a.push(u)}return{objects:a,startOffset:e,endOffset:i}}function xn(n,e){var t=[],c=Y.getCard16(n,e),a,r;if(c!==0){var s=Y.getByte(n,e+2);a=e+(c+1)*s+2;for(var i=e+3,o=0;o<c+1;o+=1)t.push(Y.getOffset(n,i,s)),i+=s;r=a+t[c]}else r=e+2;return{offsets:t,startOffset:e,endOffset:r}}function Mn(n,e,t,c,a){var r=Y.getCard16(t,c),s=0;if(r!==0){var i=Y.getByte(t,c+2);s=c+(r+1)*i+2}var o=Y.getBytes(t,s+e[n],s+e[n+1]);return a&&(o=a(o)),o}function wn(n){for(var e="",t=15,c=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var a=n.parseByte(),r=a>>4,s=a&15;if(r===t||(e+=c[r],s===t))break;e+=c[s]}return parseFloat(e)}function zn(n,e){var t,c,a,r;if(e===28)return t=n.parseByte(),c=n.parseByte(),t<<8|c;if(e===29)return t=n.parseByte(),c=n.parseByte(),a=n.parseByte(),r=n.parseByte(),t<<24|c<<16|a<<8|r;if(e===30)return wn(n);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return t=n.parseByte(),(e-247)*256+t+108;if(e>=251&&e<=254)return t=n.parseByte(),-(e-251)*256-t-108;throw new Error("Invalid b0 "+e)}function kn(n){for(var e={},t=0;t<n.length;t+=1){var c=n[t][0],a=n[t][1],r=void 0;if(a.length===1?r=a[0]:r=a,e.hasOwnProperty(c)&&!isNaN(e[c]))throw new Error("Object "+e+" already has key "+c);e[c]=r}return e}function i7(n,e,t){e=e!==void 0?e:0;var c=new Y.Parser(n,e),a=[],r=[];for(t=t!==void 0?t:n.length;c.relativeOffset<t;){var s=c.parseByte();s<=21?(s===12&&(s=1200+c.parseByte()),a.push([s,r]),r=[]):r.push(zn(c,s))}return kn(a)}function C3(n,e){return e<=390?e=b5[e]:e=n[e-391],e}function o7(n,e,t){for(var c={},a,r=0;r<e.length;r+=1){var s=e[r];if(Array.isArray(s.type)){var i=[];i.length=s.type.length;for(var o=0;o<s.type.length;o++)a=n[s.op]!==void 0?n[s.op][o]:void 0,a===void 0&&(a=s.value!==void 0&&s.value[o]!==void 0?s.value[o]:null),s.type[o]==="SID"&&(a=C3(t,a)),i[o]=a;c[s.name]=i}else a=n[s.op],a===void 0&&(a=s.value!==void 0?s.value:null),s.type==="SID"&&(a=C3(t,a)),c[s.name]=a}return c}function Ln(n,e){var t={};return t.formatMajor=Y.getCard8(n,e),t.formatMinor=Y.getCard8(n,e+1),t.size=Y.getCard8(n,e+2),t.offsetSize=Y.getCard8(n,e+3),t.startOffset=e,t.endOffset=e+4,t}var l7=[{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"}],h7=[{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 An(n,e){var t=i7(n,0,n.byteLength);return o7(t,l7,e)}function u7(n,e,t,c){var a=i7(n,e,t);return o7(a,h7,c)}function b6(n,e,t,c){for(var a=[],r=0;r<t.length;r+=1){var s=new DataView(new Uint8Array(t[r]).buffer),i=An(s,c);i._subrs=[],i._subrsBias=0,i._defaultWidthX=0,i._nominalWidthX=0;var o=i.private[0],l=i.private[1];if(o!==0&&l!==0){var h=u7(n,l+e,o,c);if(i._defaultWidthX=h.defaultWidthX,i._nominalWidthX=h.nominalWidthX,h.subrs!==0){var f=l+h.subrs,u=f2(n,f+e);i._subrs=u.objects,i._subrsBias=P4(i._subrs)}i._privateDict=h}a.push(i)}return a}function Sn(n,e,t,c){var a,r,s=new Y.Parser(n,e);t-=1;var i=[".notdef"],o=s.parseCard8();if(o===0)for(var l=0;l<t;l+=1)a=s.parseSID(),i.push(C3(c,a));else if(o===1)for(;i.length<=t;){a=s.parseSID(),r=s.parseCard8();for(var h=0;h<=r;h+=1)i.push(C3(c,a)),a+=1}else if(o===2)for(;i.length<=t;){a=s.parseSID(),r=s.parseCard16();for(var f=0;f<=r;f+=1)i.push(C3(c,a)),a+=1}else throw new Error("Unknown charset format "+o);return i}function Cn(n,e,t){var c,a={},r=new Y.Parser(n,e),s=r.parseCard8();if(s===0)for(var i=r.parseCard8(),o=0;o<i;o+=1)c=r.parseCard8(),a[c]=o;else if(s===1){var l=r.parseCard8();c=1;for(var h=0;h<l;h+=1)for(var f=r.parseCard8(),u=r.parseCard8(),d=f;d<=f+u;d+=1)a[d]=c,c+=1}else throw new Error("Unknown encoding format "+s);return new L5(a,t)}function y6(n,e,t){var c,a,r,s,i=new Y1,o=[],l=0,h=!1,f=!1,u=0,d=0,m,p,g,v;if(n.isCIDFont){var b=n.tables.cff.topDict._fdSelect[e.index],y=n.tables.cff.topDict._fdArray[b];m=y._subrs,p=y._subrsBias,g=y._defaultWidthX,v=y._nominalWidthX}else m=n.tables.cff.topDict._subrs,p=n.tables.cff.topDict._subrsBias,g=n.tables.cff.topDict._defaultWidthX,v=n.tables.cff.topDict._nominalWidthX;var x=g;function M(S,A){f&&i.closePath(),i.moveTo(S,A),f=!0}function w(){var S;S=o.length%2!==0,S&&!h&&(x=o.shift()+v),l+=o.length>>1,o.length=0,h=!0}function k(S){for(var A,z,L,P,I,T,O,F,D,_,R,U,N=0;N<S.length;){var e1=S[N];switch(N+=1,e1){case 1:w();break;case 3:w();break;case 4:o.length>1&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),M(u,d);break;case 5:for(;o.length>0;)u+=o.shift(),d+=o.shift(),i.lineTo(u,d);break;case 6:for(;o.length>0&&(u+=o.shift(),i.lineTo(u,d),o.length!==0);)d+=o.shift(),i.lineTo(u,d);break;case 7:for(;o.length>0&&(d+=o.shift(),i.lineTo(u,d),o.length!==0);)u+=o.shift(),i.lineTo(u,d);break;case 8:for(;o.length>0;)c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+o.shift(),i.curveTo(c,a,r,s,u,d);break;case 10:I=o.pop()+p,T=m[I],T&&k(T);break;case 11:return;case 12:switch(e1=S[N],N+=1,e1){case 35:c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),O=r+o.shift(),F=s+o.shift(),D=O+o.shift(),_=F+o.shift(),R=D+o.shift(),U=_+o.shift(),u=R+o.shift(),d=U+o.shift(),o.shift(),i.curveTo(c,a,r,s,O,F),i.curveTo(D,_,R,U,u,d);break;case 34:c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),O=r+o.shift(),F=s,D=O+o.shift(),_=s,R=D+o.shift(),U=d,u=R+o.shift(),i.curveTo(c,a,r,s,O,F),i.curveTo(D,_,R,U,u,d);break;case 36:c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),O=r+o.shift(),F=s,D=O+o.shift(),_=s,R=D+o.shift(),U=_+o.shift(),u=R+o.shift(),i.curveTo(c,a,r,s,O,F),i.curveTo(D,_,R,U,u,d);break;case 37:c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),O=r+o.shift(),F=s+o.shift(),D=O+o.shift(),_=F+o.shift(),R=D+o.shift(),U=_+o.shift(),Math.abs(R-u)>Math.abs(U-d)?u=R+o.shift():d=U+o.shift(),i.curveTo(c,a,r,s,O,F),i.curveTo(D,_,R,U,u,d);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+e1),o.length=0}break;case 14:o.length>0&&!h&&(x=o.shift()+v,h=!0),f&&(i.closePath(),f=!1);break;case 18:w();break;case 19:case 20:w(),N+=l+7>>3;break;case 21:o.length>2&&!h&&(x=o.shift()+v,h=!0),d+=o.pop(),u+=o.pop(),M(u,d);break;case 22:o.length>1&&!h&&(x=o.shift()+v,h=!0),u+=o.pop(),M(u,d);break;case 23:w();break;case 24:for(;o.length>2;)c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+o.shift(),i.curveTo(c,a,r,s,u,d);u+=o.shift(),d+=o.shift(),i.lineTo(u,d);break;case 25:for(;o.length>6;)u+=o.shift(),d+=o.shift(),i.lineTo(u,d);c=u+o.shift(),a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+o.shift(),i.curveTo(c,a,r,s,u,d);break;case 26:for(o.length%2&&(u+=o.shift());o.length>0;)c=u,a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r,d=s+o.shift(),i.curveTo(c,a,r,s,u,d);break;case 27:for(o.length%2&&(d+=o.shift());o.length>0;)c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s,i.curveTo(c,a,r,s,u,d);break;case 28:A=S[N],z=S[N+1],o.push((A<<24|z<<16)>>16),N+=2;break;case 29:I=o.pop()+n.gsubrsBias,T=n.gsubrs[I],T&&k(T);break;case 30:for(;o.length>0&&(c=u,a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d),o.length!==0);)c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),d=s+o.shift(),u=r+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d);break;case 31:for(;o.length>0&&(c=u+o.shift(),a=d,r=c+o.shift(),s=a+o.shift(),d=s+o.shift(),u=r+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d),o.length!==0);)c=u,a=d+o.shift(),r=c+o.shift(),s=a+o.shift(),u=r+o.shift(),d=s+(o.length===1?o.shift():0),i.curveTo(c,a,r,s,u,d);break;default:e1<32?console.log("Glyph "+e.index+": unknown operator "+e1):e1<247?o.push(e1-139):e1<251?(A=S[N],N+=1,o.push((e1-247)*256+A+108)):e1<255?(A=S[N],N+=1,o.push(-(e1-251)*256-A-108)):(A=S[N],z=S[N+1],L=S[N+2],P=S[N+3],N+=4,o.push((A<<24|z<<16|L<<8|P)/65536))}}}return k(t),e.advanceWidth=x,i}function Pn(n,e,t,c){var a=[],r,s=new Y.Parser(n,e),i=s.parseCard8();if(i===0)for(var o=0;o<t;o++){if(r=s.parseCard8(),r>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+r+" (FD count "+c+")");a.push(r)}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 f,u=0;u<l;u++){if(r=s.parseCard8(),f=s.parseCard16(),r>=c)throw new Error("CFF table CID Font FDSelect has bad FD index value "+r+" (FD count "+c+")");if(f>t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+f);for(;h<f;h++)a.push(r);h=f}if(f!==t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final GID "+f)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);return a}function En(n,e,t,c){t.tables.cff={};var a=Ln(n,e),r=f2(n,a.endOffset,Y.bytesToString),s=f2(n,r.endOffset),i=f2(n,s.endOffset,Y.bytesToString),o=f2(n,i.endOffset);t.gsubrs=o.objects,t.gsubrsBias=P4(t.gsubrs);var l=b6(n,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(t.tables.cff.topDict=h,h._privateDict&&(t.defaultWidthX=h._privateDict.defaultWidthX,t.nominalWidthX=h._privateDict.nominalWidthX),h.ros[0]!==void 0&&h.ros[1]!==void 0&&(t.isCIDFont=!0),t.isCIDFont){var f=h.fdArray,u=h.fdSelect;if(f===0||u===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");f+=e;var d=f2(n,f),m=b6(n,e,d.objects,i.objects);h._fdArray=m,u+=e,h._fdSelect=Pn(n,u,t.numGlyphs,m.length)}var p=e+h.private[1],g=u7(n,p,h.private[0],i.objects);if(t.defaultWidthX=g.defaultWidthX,t.nominalWidthX=g.nominalWidthX,g.subrs!==0){var v=p+g.subrs,b=f2(n,v);t.subrs=b.objects,t.subrsBias=P4(t.subrs)}else t.subrs=[],t.subrsBias=0;var y;c.lowMemory?(y=xn(n,e+h.charStrings),t.nGlyphs=y.offsets.length):(y=f2(n,e+h.charStrings),t.nGlyphs=y.objects.length);var x=Sn(n,e+h.charset,t.nGlyphs,i.objects);if(h.encoding===0?t.cffEncoding=new L5(hn,x):h.encoding===1?t.cffEncoding=new L5(un,x):t.cffEncoding=Cn(n,e+h.encoding,x),t.encoding=t.encoding||t.cffEncoding,t.glyphs=new n2.GlyphSet(t),c.lowMemory)t._push=function(k){var S=Mn(k,y.offsets,n,e+h.charStrings);t.glyphs.push(k,n2.cffGlyphLoader(t,k,y6,S))};else for(var M=0;M<t.nGlyphs;M+=1){var w=y.objects[M];t.glyphs.push(M,n2.cffGlyphLoader(t,M,y6,w))}}function f7(n,e){var t,c=b5.indexOf(n);return c>=0&&(t=c),c=e.indexOf(n),c>=0?t=c+b5.length:(t=b5.length+e.length,e.push(n)),t}function Tn(){return new j.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 In(n){var e=new j.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(var t=0;t<n.length;t+=1)e.names.push({name:"name_"+t,type:"NAME",value:n[t]});return e}function d7(n,e,t){for(var c={},a=0;a<n.length;a+=1){var r=n[a],s=e[r.name];s!==void 0&&!s7(s,r.value)&&(r.type==="SID"&&(s=f7(s,t)),c[r.op]={name:r.name,type:r.type,value:s})}return c}function x6(n,e){var t=new j.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=d7(l7,n,e),t}function M6(n){var e=new j.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:n}],e}function Hn(n){var e=new j.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(var t=0;t<n.length;t+=1)e.strings.push({name:"string_"+t,type:"STRING",value:n[t]});return e}function Vn(){return new j.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function On(n,e){for(var t=new j.Record("Charsets",[{name:"format",type:"Card8",value:0}]),c=0;c<n.length;c+=1){var a=n[c],r=f7(a,e);t.fields.push({name:"glyph_"+c,type:"SID",value:r})}return t}function Fn(n){var e=[],t=n.path;e.push({name:"width",type:"NUMBER",value:n.advanceWidth});for(var c=0,a=0,r=0;r<t.commands.length;r+=1){var s=void 0,i=void 0,o=t.commands[r];if(o.type==="Q"){var l=.3333333333333333,h=2/3;o={type:"C",x:o.x,y:o.y,x1:Math.round(l*c+h*o.x1),y1:Math.round(l*a+h*o.y1),x2:Math.round(l*o.x+h*o.x1),y2:Math.round(l*o.y+h*o.y1)}}if(o.type==="M")s=Math.round(o.x-c),i=Math.round(o.y-a),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rmoveto",type:"OP",value:21}),c=Math.round(o.x),a=Math.round(o.y);else if(o.type==="L")s=Math.round(o.x-c),i=Math.round(o.y-a),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rlineto",type:"OP",value:5}),c=Math.round(o.x),a=Math.round(o.y);else if(o.type==="C"){var f=Math.round(o.x1-c),u=Math.round(o.y1-a),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:f}),e.push({name:"dy1",type:"NUMBER",value:u}),e.push({name:"dx2",type:"NUMBER",value:d}),e.push({name:"dy2",type:"NUMBER",value:m}),e.push({name:"dx",type:"NUMBER",value:s}),e.push({name:"dy",type:"NUMBER",value:i}),e.push({name:"rrcurveto",type:"OP",value:8}),c=Math.round(o.x),a=Math.round(o.y)}}return e.push({name:"endchar",type:"OP",value:14}),e}function _n(n){for(var e=new j.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]),t=0;t<n.length;t+=1){var c=n.get(t),a=Fn(c);e.charStrings.push({name:c.name,type:"CHARSTRING",value:a})}return e}function Dn(n,e){var t=new j.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return t.dict=d7(h7,n,e),t}function Rn(n,e){for(var t=new j.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),c=1/e.unitsPerEm,a={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[c,0,0,c,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},r={},s=[],i,o=1;o<n.length;o+=1)i=n.get(o),s.push(i.name);var l=[];t.header=Tn(),t.nameIndex=In([e.postScriptName]);var h=x6(a,l);t.topDictIndex=M6(h),t.globalSubrIndex=Vn(),t.charsets=On(s,l),t.charStringsIndex=_n(n),t.privateDict=Dn(r,l),t.stringIndex=Hn(l);var f=t.header.sizeOf()+t.nameIndex.sizeOf()+t.topDictIndex.sizeOf()+t.stringIndex.sizeOf()+t.globalSubrIndex.sizeOf();return a.charset=f,a.encoding=0,a.charStrings=a.charset+t.charsets.sizeOf(),a.private[1]=a.charStrings+t.charStringsIndex.sizeOf(),h=x6(a,l),t.topDictIndex=M6(h),t}var p7={parse:En,make:Rn};function qn(n,e){var t={},c=new Y.Parser(n,e);return t.version=c.parseVersion(),t.fontRevision=Math.round(c.parseFixed()*1e3)/1e3,t.checkSumAdjustment=c.parseULong(),t.magicNumber=c.parseULong(),r1.argument(t.magicNumber===1594834165,"Font header has wrong magic number."),t.flags=c.parseUShort(),t.unitsPerEm=c.parseUShort(),t.created=c.parseLongDateTime(),t.modified=c.parseLongDateTime(),t.xMin=c.parseShort(),t.yMin=c.parseShort(),t.xMax=c.parseShort(),t.yMax=c.parseShort(),t.macStyle=c.parseUShort(),t.lowestRecPPEM=c.parseUShort(),t.fontDirectionHint=c.parseShort(),t.indexToLocFormat=c.parseShort(),t.glyphDataFormat=c.parseShort(),t}function $n(n){var e=Math.round(new Date().getTime()/1e3)+2082844800,t=e;return n.createdTimestamp&&(t=n.createdTimestamp+2082844800),new j.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:t},{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}],n)}var m7={parse:qn,make:$n};function Un(n,e){var t={},c=new Y.Parser(n,e);return t.version=c.parseVersion(),t.ascender=c.parseShort(),t.descender=c.parseShort(),t.lineGap=c.parseShort(),t.advanceWidthMax=c.parseUShort(),t.minLeftSideBearing=c.parseShort(),t.minRightSideBearing=c.parseShort(),t.xMaxExtent=c.parseShort(),t.caretSlopeRise=c.parseShort(),t.caretSlopeRun=c.parseShort(),t.caretOffset=c.parseShort(),c.relativeOffset+=8,t.metricDataFormat=c.parseShort(),t.numberOfHMetrics=c.parseUShort(),t}function Nn(n){return new j.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}],n)}var g7={parse:Un,make:Nn};function Bn(n,e,t,c,a){for(var r,s,i=new Y.Parser(n,e),o=0;o<c;o+=1){o<t&&(r=i.parseUShort(),s=i.parseShort());var l=a.get(o);l.advanceWidth=r,l.leftSideBearing=s}}function Gn(n,e,t,c,a){n._hmtxTableData={};for(var r,s,i=new Y.Parser(e,t),o=0;o<a;o+=1)o<c&&(r=i.parseUShort(),s=i.parseShort()),n._hmtxTableData[o]={advanceWidth:r,leftSideBearing:s}}function jn(n,e,t,c,a,r,s){s.lowMemory?Gn(n,e,t,c,a):Bn(e,t,c,a,r)}function Wn(n){for(var e=new j.Table("hmtx",[]),t=0;t<n.length;t+=1){var c=n.get(t),a=c.advanceWidth||0,r=c.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+t,type:"USHORT",value:a}),e.fields.push({name:"leftSideBearing_"+t,type:"SHORT",value:r})}return e}var v7={parse:jn,make:Wn};function Xn(n){for(var e=new j.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:n.length}]),t="",c=12+n.length*4,a=0;a<n.length;++a){var r=t.indexOf(n[a]);r<0&&(r=t.length,t+=n[a]),e.fields.push({name:"offset "+a,type:"USHORT",value:c+r}),e.fields.push({name:"length "+a,type:"USHORT",value:n[a].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),e}function Zn(n,e){var t=new Y.Parser(n,e),c=t.parseULong();r1.argument(c===1,"Unsupported ltag table version."),t.skip("uLong",1);for(var a=t.parseULong(),r=[],s=0;s<a;s++){for(var i="",o=e+t.parseUShort(),l=t.parseUShort(),h=o;h<o+l;++h)i+=String.fromCharCode(n.getInt8(h));r.push(i)}return r}var b7={make:Xn,parse:Zn};function Yn(n,e){var t={},c=new Y.Parser(n,e);return t.version=c.parseVersion(),t.numGlyphs=c.parseUShort(),t.version===1&&(t.maxPoints=c.parseUShort(),t.maxContours=c.parseUShort(),t.maxCompositePoints=c.parseUShort(),t.maxCompositeContours=c.parseUShort(),t.maxZones=c.parseUShort(),t.maxTwilightPoints=c.parseUShort(),t.maxStorage=c.parseUShort(),t.maxFunctionDefs=c.parseUShort(),t.maxInstructionDefs=c.parseUShort(),t.maxStackElements=c.parseUShort(),t.maxSizeOfInstructions=c.parseUShort(),t.maxComponentElements=c.parseUShort(),t.maxComponentDepth=c.parseUShort()),t}function Kn(n){return new j.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:n}])}var y7={parse:Yn,make:Kn},x7=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],M7={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"},Jn={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},w7={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 Qn(n,e,t){switch(n){case 0:if(e===65535)return"und";if(t)return t[e];break;case 1:return M7[e];case 3:return w7[e]}}var E4="utf-16",e9={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"},t9={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 z7(n,e,t){switch(n){case 0:return E4;case 1:return t9[t]||e9[e];case 3:if(e===1||e===10)return E4;break}}function n9(n,e,t){for(var c={},a=new Y.Parser(n,e),r=a.parseUShort(),s=a.parseUShort(),i=a.offset+a.parseUShort(),o=0;o<s;o++){var l=a.parseUShort(),h=a.parseUShort(),f=a.parseUShort(),u=a.parseUShort(),d=x7[u]||u,m=a.parseUShort(),p=a.parseUShort(),g=Qn(l,f,t),v=z7(l,h,f);if(v!==void 0&&g!==void 0){var b=void 0;if(v===E4?b=Z2.UTF16(n,i+p,m):b=Z2.MACSTRING(n,i+p,m,v),b){var y=c[d];y===void 0&&(y=c[d]={}),y[g]=b}}}var x=0;return r===1&&(x=a.parseUShort()),c}function v4(n){var e={};for(var t in n)e[n[t]]=parseInt(t);return e}function w6(n,e,t,c,a,r){return new j.Record("NameRecord",[{name:"platformID",type:"USHORT",value:n},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:t},{name:"nameID",type:"USHORT",value:c},{name:"length",type:"USHORT",value:a},{name:"offset",type:"USHORT",value:r}])}function c9(n,e){var t=n.length,c=e.length-t+1;e:for(var a=0;a<c;a++)for(;a<c;a++){for(var r=0;r<t;r++)if(e[a+r]!==n[r])continue e;return a}return-1}function z6(n,e){var t=c9(n,e);if(t<0){t=e.length;for(var c=0,a=n.length;c<a;++c)e.push(n[c])}return t}function a9(n,e){var t,c=[],a={},r=v4(x7);for(var s in n){var i=r[s];if(i===void 0&&(i=s),t=parseInt(i),isNaN(t))throw new Error('Name table entry "'+s+'" does not exist, see nameTableNames for complete list.');a[t]=n[s],c.push(t)}for(var o=v4(M7),l=v4(w7),h=[],f=[],u=0;u<c.length;u++){t=c[u];var d=a[t];for(var m in d){var p=d[m],g=1,v=o[m],b=Jn[v],y=z7(g,b,v),x=B.MACSTRING(p,y);x===void 0&&(g=0,v=e.indexOf(m),v<0&&(v=e.length,e.push(m)),b=4,x=B.UTF16(p));var M=z6(x,f);h.push(w6(g,b,v,t,x.length,M));var w=l[m];if(w!==void 0){var k=B.UTF16(p),S=z6(k,f);h.push(w6(3,1,w,t,k.length,S))}}}h.sort(function(L,P){return L.platformID-P.platformID||L.encodingID-P.encodingID||L.languageID-P.languageID||L.nameID-P.nameID});for(var A=new j.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:h.length},{name:"stringOffset",type:"USHORT",value:6+h.length*12}]),z=0;z<h.length;z++)A.fields.push({name:"record_"+z,type:"RECORD",value:h[z]});return A.fields.push({name:"strings",type:"LITERAL",value:f}),A}var k7={parse:n9,make:a9},T4=[{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 r9(n){for(var e=0;e<T4.length;e+=1){var t=T4[e];if(n>=t.begin&&n<t.end)return e}return-1}function s9(n,e){var t={},c=new Y.Parser(n,e);t.version=c.parseUShort(),t.xAvgCharWidth=c.parseShort(),t.usWeightClass=c.parseUShort(),t.usWidthClass=c.parseUShort(),t.fsType=c.parseUShort(),t.ySubscriptXSize=c.parseShort(),t.ySubscriptYSize=c.parseShort(),t.ySubscriptXOffset=c.parseShort(),t.ySubscriptYOffset=c.parseShort(),t.ySuperscriptXSize=c.parseShort(),t.ySuperscriptYSize=c.parseShort(),t.ySuperscriptXOffset=c.parseShort(),t.ySuperscriptYOffset=c.parseShort(),t.yStrikeoutSize=c.parseShort(),t.yStrikeoutPosition=c.parseShort(),t.sFamilyClass=c.parseShort(),t.panose=[];for(var a=0;a<10;a++)t.panose[a]=c.parseByte();return t.ulUnicodeRange1=c.parseULong(),t.ulUnicodeRange2=c.parseULong(),t.ulUnicodeRange3=c.parseULong(),t.ulUnicodeRange4=c.parseULong(),t.achVendID=String.fromCharCode(c.parseByte(),c.parseByte(),c.parseByte(),c.parseByte()),t.fsSelection=c.parseUShort(),t.usFirstCharIndex=c.parseUShort(),t.usLastCharIndex=c.parseUShort(),t.sTypoAscender=c.parseShort(),t.sTypoDescender=c.parseShort(),t.sTypoLineGap=c.parseShort(),t.usWinAscent=c.parseUShort(),t.usWinDescent=c.parseUShort(),t.version>=1&&(t.ulCodePageRange1=c.parseULong(),t.ulCodePageRange2=c.parseULong()),t.version>=2&&(t.sxHeight=c.parseShort(),t.sCapHeight=c.parseShort(),t.usDefaultChar=c.parseUShort(),t.usBreakChar=c.parseUShort(),t.usMaxContent=c.parseUShort()),t}function i9(n){return new j.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}],n)}var I4={parse:s9,make:i9,unicodeRanges:T4,getUnicodeRange:r9};function o9(n,e){var t={},c=new Y.Parser(n,e);switch(t.version=c.parseVersion(),t.italicAngle=c.parseFixed(),t.underlinePosition=c.parseShort(),t.underlineThickness=c.parseShort(),t.isFixedPitch=c.parseULong(),t.minMemType42=c.parseULong(),t.maxMemType42=c.parseULong(),t.minMemType1=c.parseULong(),t.maxMemType1=c.parseULong(),t.version){case 1:t.names=C2.slice();break;case 2:t.numberOfGlyphs=c.parseUShort(),t.glyphNameIndex=new Array(t.numberOfGlyphs);for(var a=0;a<t.numberOfGlyphs;a++)t.glyphNameIndex[a]=c.parseUShort();t.names=[];for(var r=0;r<t.numberOfGlyphs;r++)if(t.glyphNameIndex[r]>=C2.length){var s=c.parseChar();t.names.push(c.parseString(s))}break;case 2.5:t.numberOfGlyphs=c.parseUShort(),t.offset=new Array(t.numberOfGlyphs);for(var i=0;i<t.numberOfGlyphs;i++)t.offset[i]=c.parseChar();break}return t}function l9(){return new j.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 L7={parse:o9,make:l9},D0=new Array(9);D0[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(V.coverage),deltaGlyphId:this.parseUShort()};if(t===2)return{substFormat:2,coverage:this.parsePointer(V.coverage),substitute:this.parseOffset16List()};r1.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};D0[2]=function(){var e=this.parseUShort();return r1.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(V.coverage),sequences:this.parseListOfLists()}};D0[3]=function(){var e=this.parseUShort();return r1.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(V.coverage),alternateSets:this.parseListOfLists()}};D0[4]=function(){var e=this.parseUShort();return r1.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(V.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var X2={sequenceIndex:V.uShort,lookupListIndex:V.uShort};D0[5]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:t,coverage:this.parsePointer(V.coverage),ruleSets:this.parseListOfLists(function(){var r=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(r-1),lookupRecords:this.parseRecordList(s,X2)}})};if(t===2)return{substFormat:t,coverage:this.parsePointer(V.coverage),classDef:this.parsePointer(V.classDef),classSets:this.parseListOfLists(function(){var r=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(r-1),lookupRecords:this.parseRecordList(s,X2)}})};if(t===3){var c=this.parseUShort(),a=this.parseUShort();return{substFormat:t,coverages:this.parseList(c,V.pointer(V.coverage)),lookupRecords:this.parseRecordList(a,X2)}}r1.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};D0[6]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(V.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(X2)}})};if(t===2)return{substFormat:2,coverage:this.parsePointer(V.coverage),backtrackClassDef:this.parsePointer(V.classDef),inputClassDef:this.parsePointer(V.classDef),lookaheadClassDef:this.parsePointer(V.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(X2)}})};if(t===3)return{substFormat:3,backtrackCoverage:this.parseList(V.pointer(V.coverage)),inputCoverage:this.parseList(V.pointer(V.coverage)),lookaheadCoverage:this.parseList(V.pointer(V.coverage)),lookupRecords:this.parseRecordList(X2)};r1.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};D0[7]=function(){var e=this.parseUShort();r1.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");var t=this.parseUShort(),c=new V(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:t,extension:D0[t].call(c)}};D0[8]=function(){var e=this.parseUShort();return r1.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(V.coverage),backtrackCoverage:this.parseList(V.pointer(V.coverage)),lookaheadCoverage:this.parseList(V.pointer(V.coverage)),substitutes:this.parseUShortList()}};function h9(n,e){e=e||0;var t=new V(n,e),c=t.parseVersion(1);return r1.argument(c===1||c===1.1,"Unsupported GSUB table version."),c===1?{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(D0)}:{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(D0),variations:t.parseFeatureVariationsList()}}var Y2=new Array(9);Y2[1]=function(e){return e.substFormat===1?new j.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new j.Coverage(e.coverage)},{name:"deltaGlyphID",type:"USHORT",value:e.deltaGlyphId}]):new j.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new j.Coverage(e.coverage)}].concat(j.ushortList("substitute",e.substitute)))};Y2[2]=function(e){return r1.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new j.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new j.Coverage(e.coverage)}].concat(j.tableList("seqSet",e.sequences,function(t){return new j.Table("sequenceSetTable",j.ushortList("sequence",t))})))};Y2[3]=function(e){return r1.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new j.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new j.Coverage(e.coverage)}].concat(j.tableList("altSet",e.alternateSets,function(t){return new j.Table("alternateSetTable",j.ushortList("alternate",t))})))};Y2[4]=function(e){return r1.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new j.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new j.Coverage(e.coverage)}].concat(j.tableList("ligSet",e.ligatureSets,function(t){return new j.Table("ligatureSetTable",j.tableList("ligature",t,function(c){return new j.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:c.ligGlyph}].concat(j.ushortList("component",c.components,c.components.length+1)))}))})))};Y2[6]=function(e){if(e.substFormat===1){var t=new j.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new j.Coverage(e.coverage)}].concat(j.tableList("chainRuleSet",e.chainRuleSets,function(r){return new j.Table("chainRuleSetTable",j.tableList("chainRule",r,function(s){var i=j.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(j.ushortList("inputGlyph",s.input,s.input.length+1)).concat(j.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(j.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 j.Table("chainRuleTable",i)}))})));return t}else if(e.substFormat===2)r1.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){var c=[{name:"substFormat",type:"USHORT",value:e.substFormat}];c.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length}),e.backtrackCoverage.forEach(function(r,s){c.push({name:"backtrackCoverage"+s,type:"TABLE",value:new j.Coverage(r)})}),c.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length}),e.inputCoverage.forEach(function(r,s){c.push({name:"inputCoverage"+s,type:"TABLE",value:new j.Coverage(r)})}),c.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length}),e.lookaheadCoverage.forEach(function(r,s){c.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new j.Coverage(r)})}),c.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length}),e.lookupRecords.forEach(function(r,s){c=c.concat({name:"sequenceIndex"+s,type:"USHORT",value:r.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:r.lookupListIndex})});var a=new j.Table("chainContextTable",c);return a}r1.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function u9(n){return new j.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new j.ScriptList(n.scripts)},{name:"features",type:"TABLE",value:new j.FeatureList(n.features)},{name:"lookups",type:"TABLE",value:new j.LookupList(n.lookups,Y2)}])}var A7={parse:h9,make:u9};function f9(n,e){var t=new Y.Parser(n,e),c=t.parseULong();r1.argument(c===1,"Unsupported META table version."),t.parseULong(),t.parseULong();for(var a=t.parseULong(),r={},s=0;s<a;s++){var i=t.parseTag(),o=t.parseULong(),l=t.parseULong(),h=Z2.UTF8(n,e+o,l);r[i]=h}return r}function d9(n){var e=Object.keys(n).length,t="",c=16+e*12,a=new j.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:c},{name:"numTags",type:"ULONG",value:e}]);for(var r in n){var s=t.length;t+=n[r],a.fields.push({name:"tag "+r,type:"TAG",value:r}),a.fields.push({name:"offset "+r,type:"ULONG",value:c+s}),a.fields.push({name:"length "+r,type:"ULONG",value:n[r].length})}return a.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),a}var S7={parse:f9,make:d9};function k6(n){return Math.log(n)/Math.log(2)|0}function q4(n){for(;n.length%4!==0;)n.push(0);for(var e=0,t=0;t<n.length;t+=4)e+=(n[t]<<24)+(n[t+1]<<16)+(n[t+2]<<8)+n[t+3];return e%=Math.pow(2,32),e}function L6(n,e,t,c){return new j.Record("Table Record",[{name:"tag",type:"TAG",value:n!==void 0?n:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:t!==void 0?t:0},{name:"length",type:"ULONG",value:c!==void 0?c:0}])}function C7(n){var e=new j.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=n,e.numTables=n.length;var t=Math.pow(2,k6(e.numTables));e.searchRange=16*t,e.entrySelector=k6(t),e.rangeShift=e.numTables*16-e.searchRange;for(var c=[],a=[],r=e.sizeOf()+L6().sizeOf()*e.numTables;r%4!==0;)r+=1,a.push({name:"padding",type:"BYTE",value:0});for(var s=0;s<n.length;s+=1){var i=n[s];r1.argument(i.tableName.length===4,"Table name"+i.tableName+" is invalid.");var o=i.sizeOf(),l=L6(i.tableName,q4(i.encode()),r,o);for(c.push({name:l.tag+" Table Record",type:"RECORD",value:l}),a.push({name:i.tableName+" table",type:"RECORD",value:i}),r+=o,r1.argument(!isNaN(r),"Something went wrong calculating the offset.");r%4!==0;)r+=1,a.push({name:"padding",type:"BYTE",value:0})}return c.sort(function(h,f){return h.value.tag>f.value.tag?1:-1}),e.fields=e.fields.concat(c),e.fields=e.fields.concat(a),e}function A6(n,e,t){for(var c=0;c<e.length;c+=1){var a=n.charToGlyphIndex(e[c]);if(a>0){var r=n.glyphs.get(a);return r.getMetrics()}}return t}function p9(n){for(var e=0,t=0;t<n.length;t+=1)e+=n[t];return e/n.length}function m9(n){for(var e=[],t=[],c=[],a=[],r=[],s=[],i=[],o,l=0,h=0,f=0,u=0,d=0,m=0;m<n.glyphs.length;m+=1){var p=n.glyphs.get(m),g=p.unicode|0;if(isNaN(p.advanceWidth))throw new Error("Glyph "+p.name+" ("+m+"): advanceWidth is not a number.");(o>g||o===void 0)&&g>0&&(o=g),l<g&&(l=g);var v=I4.getUnicodeRange(g);if(v<32)h|=1<<v;else if(v<64)f|=1<<v-32;else if(v<96)u|=1<<v-64;else if(v<123)d|=1<<v-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(p.name!==".notdef"){var b=p.getMetrics();e.push(b.xMin),t.push(b.yMin),c.push(b.xMax),a.push(b.yMax),s.push(b.leftSideBearing),i.push(b.rightSideBearing),r.push(p.advanceWidth)}}var y={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,c),yMax:Math.max.apply(null,a),advanceWidthMax:Math.max.apply(null,r),advanceWidthAvg:p9(r),minLeftSideBearing:Math.min.apply(null,s),maxLeftSideBearing:Math.max.apply(null,s),minRightSideBearing:Math.min.apply(null,i)};y.ascender=n.ascender,y.descender=n.descender;var x=m7.make({flags:3,unitsPerEm:n.unitsPerEm,xMin:y.xMin,yMin:y.yMin,xMax:y.xMax,yMax:y.yMax,lowestRecPPEM:3,createdTimestamp:n.createdTimestamp}),M=g7.make({ascender:y.ascender,descender:y.descender,advanceWidthMax:y.advanceWidthMax,minLeftSideBearing:y.minLeftSideBearing,minRightSideBearing:y.minRightSideBearing,xMaxExtent:y.maxLeftSideBearing+(y.xMax-y.xMin),numberOfHMetrics:n.glyphs.length}),w=y7.make(n.glyphs.length),k=I4.make(Object.assign({xAvgCharWidth:Math.round(y.advanceWidthAvg),usFirstCharIndex:o,usLastCharIndex:l,ulUnicodeRange1:h,ulUnicodeRange2:f,ulUnicodeRange3:u,ulUnicodeRange4:d,sTypoAscender:y.ascender,sTypoDescender:y.descender,sTypoLineGap:0,usWinAscent:y.yMax,usWinDescent:Math.abs(y.yMin),ulCodePageRange1:1,sxHeight:A6(n,"xyvw",{yMax:Math.round(y.ascender/2)}).yMax,sCapHeight:A6(n,"HIKLEFJMNTZBDPRAGOQSUVWXY",y).yMax,usDefaultChar:n.hasChar(" ")?32:0,usBreakChar:n.hasChar(" ")?32:0},n.tables.os2)),S=v7.make(n.glyphs),A=c7.make(n.glyphs),z=n.getEnglishName("fontFamily"),L=n.getEnglishName("fontSubfamily"),P=z+" "+L,I=n.getEnglishName("postScriptName");I||(I=z.replace(/\s/g,"")+"-"+L);var T={};for(var O in n.names)T[O]=n.names[O];T.uniqueID||(T.uniqueID={en:n.getEnglishName("manufacturer")+":"+P}),T.postScriptName||(T.postScriptName={en:I}),T.preferredFamily||(T.preferredFamily=n.names.fontFamily),T.preferredSubfamily||(T.preferredSubfamily=n.names.fontSubfamily);var F=[],D=k7.make(T,F),_=F.length>0?b7.make(F):void 0,R=L7.make(),U=p7.make(n.glyphs,{version:n.getEnglishName("version"),fullName:P,familyName:z,weightName:L,postScriptName:I,unitsPerEm:n.unitsPerEm,fontBBox:[0,y.yMin,y.ascender,y.advanceWidthMax]}),N=n.metas&&Object.keys(n.metas).length>0?S7.make(n.metas):void 0,e1=[x,M,w,k,D,A,R,U,S];_&&e1.push(_),n.tables.gsub&&e1.push(A7.make(n.tables.gsub)),N&&e1.push(N);for(var E1=C7(e1),l0=E1.encode(),G1=q4(l0),M1=E1.fields,A1=!1,z1=0;z1<M1.length;z1+=1)if(M1[z1].name==="head table"){M1[z1].value.checkSumAdjustment=2981146554-G1,A1=!0;break}if(!A1)throw new Error("Could not find head table with checkSum to adjust.");return E1}var g9={make:C7,fontToTable:m9,computeCheckSum:q4};function b4(n,e){for(var t=0,c=n.length-1;t<=c;){var a=t+c>>>1,r=n[a].tag;if(r===e)return a;r<e?t=a+1:c=a-1}return-t-1}function S6(n,e){for(var t=0,c=n.length-1;t<=c;){var a=t+c>>>1,r=n[a];if(r===e)return a;r<e?t=a+1:c=a-1}return-t-1}function C6(n,e){for(var t,c=0,a=n.length-1;c<=a;){var r=c+a>>>1;t=n[r];var s=t.start;if(s===e)return t;s<e?c=r+1:a=r-1}if(c>0)return t=n[c-1],e>t.end?0:t}function H3(n,e){this.font=n,this.tableName=e}H3.prototype={searchTag:b4,binSearch:S6,getTable:function(n){var e=this.font.tables[this.tableName];return!e&&n&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){var n=this.getTable();return n?n.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var n=this.getTable();if(n){for(var e=!1,t=0;t<n.scripts.length;t++){var c=n.scripts[t].tag;if(c==="DFLT")return c;c==="latn"&&(e=!0)}if(e)return"latn"}},getScriptTable:function(n,e){var t=this.getTable(e);if(t){n=n||"DFLT";var c=t.scripts,a=b4(t.scripts,n);if(a>=0)return c[a].script;if(e){var r={tag:n,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return c.splice(-1-a,0,r),r.script}}},getLangSysTable:function(n,e,t){var c=this.getScriptTable(n,t);if(c){if(!e||e==="dflt"||e==="DFLT")return c.defaultLangSys;var a=b4(c.langSysRecords,e);if(a>=0)return c.langSysRecords[a].langSys;if(t){var r={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return c.langSysRecords.splice(-1-a,0,r),r.langSys}}},getFeatureTable:function(n,e,t,c){var a=this.getLangSysTable(n,e,c);if(a){for(var r,s=a.featureIndexes,i=this.font.tables[this.tableName].features,o=0;o<s.length;o++)if(r=i[s[o]],r.tag===t)return r.feature;if(c){var l=i.length;return r1.assert(l===0||t>=i[l-1].tag,"Features must be added in alphabetical order."),r={tag:t,feature:{params:0,lookupListIndexes:[]}},i.push(r),s.push(l),r.feature}}},getLookupTables:function(n,e,t,c,a){var r=this.getFeatureTable(n,e,t,a),s=[];if(r){for(var i,o=r.lookupListIndexes,l=this.font.tables[this.tableName].lookups,h=0;h<o.length;h++)i=l[o[h]],i.lookupType===c&&s.push(i);if(s.length===0&&a){i={lookupType:c,lookupFlag:0,subtables:[],markFilteringSet:void 0};var f=l.length;return l.push(i),o.push(f),[i]}}return s},getGlyphClass:function(n,e){switch(n.format){case 1:return n.startGlyph<=e&&e<n.startGlyph+n.classes.length?n.classes[e-n.startGlyph]:0;case 2:var t=C6(n.ranges,e);return t?t.classId:0}},getCoverageIndex:function(n,e){switch(n.format){case 1:var t=S6(n.glyphs,e);return t>=0?t:-1;case 2:var c=C6(n.ranges,e);return c?c.index+e-c.start:-1}},expandCoverage:function(n){if(n.format===1)return n.glyphs;for(var e=[],t=n.ranges,c=0;c<t.length;c++)for(var a=t[c],r=a.start,s=a.end,i=r;i<=s;i++)e.push(i);return e}};function V3(n){H3.call(this,n,"gpos")}V3.prototype=H3.prototype;V3.prototype.init=function(){var n=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(n)};V3.prototype.getKerningValue=function(n,e,t){for(var c=0;c<n.length;c++)for(var a=n[c].subtables,r=0;r<a.length;r++){var s=a[r],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===t)return h.value1&&h.value1.xAdvance||0}break;case 2:var f=this.getGlyphClass(s.classDef1,e),u=this.getGlyphClass(s.classDef2,t),d=s.classRecords[f][u];return d.value1&&d.value1.xAdvance||0}}return 0};V3.prototype.getKerningTables=function(n,e){if(this.font.tables.gpos)return this.getLookupTables(n,e,"kern",2)};function A0(n){H3.call(this,n,"gsub")}function v9(n,e){var t=n.length;if(t!==e.length)return!1;for(var c=0;c<t;c++)if(n[c]!==e[c])return!1;return!0}function $4(n,e,t){for(var c=n.subtables,a=0;a<c.length;a++){var r=c[a];if(r.substFormat===e)return r}if(t)return c.push(t),t}A0.prototype=H3.prototype;A0.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};A0.prototype.getSingle=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,1),r=0;r<a.length;r++)for(var s=a[r].subtables,i=0;i<s.length;i++){var o=s[i],l=this.expandCoverage(o.coverage),h=void 0;if(o.substFormat===1){var f=o.deltaGlyphId;for(h=0;h<l.length;h++){var u=l[h];c.push({sub:u,by:u+f})}}else{var d=o.substitute;for(h=0;h<l.length;h++)c.push({sub:l[h],by:d[h]})}}return c};A0.prototype.getMultiple=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,2),r=0;r<a.length;r++)for(var s=a[r].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 f=l[h],u=o.sequences[h];c.push({sub:f,by:u})}}return c};A0.prototype.getAlternates=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,3),r=0;r<a.length;r++)for(var s=a[r].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.alternateSets,f=0;f<l.length;f++)c.push({sub:l[f],by:h[f]});return c};A0.prototype.getLigatures=function(n,e,t){for(var c=[],a=this.getLookupTables(e,t,n,4),r=0;r<a.length;r++)for(var s=a[r].subtables,i=0;i<s.length;i++)for(var o=s[i],l=this.expandCoverage(o.coverage),h=o.ligatureSets,f=0;f<l.length;f++)for(var u=l[f],d=h[f],m=0;m<d.length;m++){var p=d[m];c.push({sub:[u].concat(p.components),by:p.ligGlyph})}return c};A0.prototype.addSingle=function(n,e,t,c){var a=this.getLookupTables(t,c,n,1,!0)[0],r=$4(a,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});r1.assert(r.coverage.format===1,"Single: unable to modify coverage table format "+r.coverage.format);var s=e.sub,i=this.binSearch(r.coverage.glyphs,s);i<0&&(i=-1-i,r.coverage.glyphs.splice(i,0,s),r.substitute.splice(i,0,0)),r.substitute[i]=e.by};A0.prototype.addMultiple=function(n,e,t,c){r1.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');var a=this.getLookupTables(t,c,n,2,!0)[0],r=$4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});r1.assert(r.coverage.format===1,"Multiple: unable to modify coverage table format "+r.coverage.format);var s=e.sub,i=this.binSearch(r.coverage.glyphs,s);i<0&&(i=-1-i,r.coverage.glyphs.splice(i,0,s),r.sequences.splice(i,0,0)),r.sequences[i]=e.by};A0.prototype.addAlternate=function(n,e,t,c){var a=this.getLookupTables(t,c,n,3,!0)[0],r=$4(a,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});r1.assert(r.coverage.format===1,"Alternate: unable to modify coverage table format "+r.coverage.format);var s=e.sub,i=this.binSearch(r.coverage.glyphs,s);i<0&&(i=-1-i,r.coverage.glyphs.splice(i,0,s),r.alternateSets.splice(i,0,0)),r.alternateSets[i]=e.by};A0.prototype.addLigature=function(n,e,t,c){var a=this.getLookupTables(t,c,n,4,!0)[0],r=a.subtables[0];r||(r={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},a.subtables[0]=r),r1.assert(r.coverage.format===1,"Ligature: unable to modify coverage table format "+r.coverage.format);var s=e.sub[0],i=e.sub.slice(1),o={ligGlyph:e.by,components:i},l=this.binSearch(r.coverage.glyphs,s);if(l>=0){for(var h=r.ligatureSets[l],f=0;f<h.length;f++)if(v9(h[f].components,i))return;h.push(o)}else l=-1-l,r.coverage.glyphs.splice(l,0,s),r.ligatureSets.splice(l,0,[o])};A0.prototype.getFeature=function(n,e,t){if(/ss\d\d/.test(n))return this.getSingle(n,e,t);switch(n){case"aalt":case"salt":return this.getSingle(n,e,t).concat(this.getAlternates(n,e,t));case"dlig":case"liga":case"rlig":return this.getLigatures(n,e,t);case"ccmp":return this.getMultiple(n,e,t).concat(this.getLigatures(n,e,t));case"stch":return this.getMultiple(n,e,t)}};A0.prototype.add=function(n,e,t,c){if(/ss\d\d/.test(n))return this.addSingle(n,e,t,c);switch(n){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(n,e,t,c):this.addAlternate(n,e,t,c);case"dlig":case"liga":case"rlig":return this.addLigature(n,e,t,c);case"ccmp":return e.by instanceof Array?this.addMultiple(n,e,t,c):this.addLigature(n,e,t,c)}};function b9(){return typeof window<"u"}function y9(n){for(var e=new Buffer(n.byteLength),t=new Uint8Array(n),c=0;c<e.length;++c)e[c]=t[c];return e}function S3(n,e){if(!n)throw e}function P6(n,e,t,c,a){var r;return(e&c)>0?(r=n.parseByte(),(e&a)===0&&(r=-r),r=t+r):(e&a)>0?r=t:r=t+n.parseShort(),r}function P7(n,e,t){var c=new Y.Parser(e,t);n.numberOfContours=c.parseShort(),n._xMin=c.parseShort(),n._yMin=c.parseShort(),n._xMax=c.parseShort(),n._yMax=c.parseShort();var a,r;if(n.numberOfContours>0){for(var s=n.endPointIndices=[],i=0;i<n.numberOfContours;i+=1)s.push(c.parseUShort());n.instructionLength=c.parseUShort(),n.instructions=[];for(var o=0;o<n.instructionLength;o+=1)n.instructions.push(c.parseByte());var l=s[s.length-1]+1;a=[];for(var h=0;h<l;h+=1)if(r=c.parseByte(),a.push(r),(r&8)>0)for(var f=c.parseByte(),u=0;u<f;u+=1)a.push(r),h+=1;if(r1.argument(a.length===l,"Bad flags."),s.length>0){var d=[],m;if(l>0){for(var p=0;p<l;p+=1)r=a[p],m={},m.onCurve=!!(r&1),m.lastPointOfContour=s.indexOf(p)>=0,d.push(m);for(var g=0,v=0;v<l;v+=1)r=a[v],m=d[v],m.x=P6(c,r,g,2,16),g=m.x;for(var b=0,y=0;y<l;y+=1)r=a[y],m=d[y],m.y=P6(c,r,b,4,32),b=m.y}n.points=d}else n.points=[]}else if(n.numberOfContours===0)n.points=[];else{n.isComposite=!0,n.points=[],n.components=[];for(var x=!0;x;){a=c.parseUShort();var M={glyphIndex:c.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(a&1)>0?(a&2)>0?(M.dx=c.parseShort(),M.dy=c.parseShort()):M.matchedPoints=[c.parseUShort(),c.parseUShort()]:(a&2)>0?(M.dx=c.parseChar(),M.dy=c.parseChar()):M.matchedPoints=[c.parseByte(),c.parseByte()],(a&8)>0?M.xScale=M.yScale=c.parseF2Dot14():(a&64)>0?(M.xScale=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()):(a&128)>0&&(M.xScale=c.parseF2Dot14(),M.scale01=c.parseF2Dot14(),M.scale10=c.parseF2Dot14(),M.yScale=c.parseF2Dot14()),n.components.push(M),x=!!(a&32)}if(a&256){n.instructionLength=c.parseUShort(),n.instructions=[];for(var w=0;w<n.instructionLength;w+=1)n.instructions.push(c.parseByte())}}}function y4(n,e){for(var t=[],c=0;c<n.length;c+=1){var a=n[c],r={x:e.xScale*a.x+e.scale01*a.y+e.dx,y:e.scale10*a.x+e.yScale*a.y+e.dy,onCurve:a.onCurve,lastPointOfContour:a.lastPointOfContour};t.push(r)}return t}function x9(n){for(var e=[],t=[],c=0;c<n.length;c+=1){var a=n[c];t.push(a),a.lastPointOfContour&&(e.push(t),t=[])}return r1.argument(t.length===0,"There are still points left in the current contour."),e}function E7(n){var e=new Y1;if(!n)return e;for(var t=x9(n),c=0;c<t.length;++c){var a=t[c],r=null,s=a[a.length-1],i=a[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<a.length;++l)if(r=s,s=i,i=a[(l+1)%a.length],s.onCurve)e.lineTo(s.x,s.y);else{var h=r,f=i;r.onCurve||(h={x:(s.x+r.x)*.5,y:(s.y+r.y)*.5}),i.onCurve||(f={x:(s.x+i.x)*.5,y:(s.y+i.y)*.5}),e.quadraticCurveTo(s.x,s.y,f.x,f.y)}e.closePath()}return e}function T7(n,e){if(e.isComposite)for(var t=0;t<e.components.length;t+=1){var c=e.components[t],a=n.get(c.glyphIndex);if(a.getPath(),a.points){var r=void 0;if(c.matchedPoints===void 0)r=y4(a.points,c);else{if(c.matchedPoints[0]>e.points.length-1||c.matchedPoints[1]>a.points.length-1)throw Error("Matched points out of range in "+e.name);var s=e.points[c.matchedPoints[0]],i=a.points[c.matchedPoints[1]],o={xScale:c.xScale,scale01:c.scale01,scale10:c.scale10,yScale:c.yScale,dx:0,dy:0};i=y4([i],o)[0],o.dx=s.x-i.x,o.dy=s.y-i.y,r=y4(a.points,o)}e.points=e.points.concat(r)}}return E7(e.points)}function M9(n,e,t,c){for(var a=new n2.GlyphSet(c),r=0;r<t.length-1;r+=1){var s=t[r],i=t[r+1];s!==i?a.push(r,n2.ttfGlyphLoader(c,r,P7,n,e+s,T7)):a.push(r,n2.glyphLoader(c,r))}return a}function w9(n,e,t,c){var a=new n2.GlyphSet(c);return c._push=function(r){var s=t[r],i=t[r+1];s!==i?a.push(r,n2.ttfGlyphLoader(c,r,P7,n,e+s,T7)):a.push(r,n2.glyphLoader(c,r))},a}function z9(n,e,t,c,a){return a.lowMemory?w9(n,e,t,c):M9(n,e,t,c)}var I7={getPath:E7,parse:z9},H7,E2,V7,H4;function O7(n){this.font=n,this.getCommands=function(e){return I7.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function k9(n){return n}function F7(n){return Math.sign(n)*Math.round(Math.abs(n))}function L9(n){return Math.sign(n)*Math.round(Math.abs(n*2))/2}function A9(n){return Math.sign(n)*(Math.round(Math.abs(n)+.5)-.5)}function S9(n){return Math.sign(n)*Math.ceil(Math.abs(n))}function C9(n){return Math.sign(n)*Math.floor(Math.abs(n))}var _7=function(n){var e=this.srPeriod,t=this.srPhase,c=this.srThreshold,a=1;return n<0&&(n=-n,a=-1),n+=c-t,n=Math.trunc(n/e)*e,n+=t,n<0?t*a:n*a},t2={x:1,y:0,axis:"x",distance:function(n,e,t,c){return(t?n.xo:n.x)-(c?e.xo:e.x)},interpolate:function(n,e,t,c){var a,r,s,i,o,l,h;if(!c||c===this){if(a=n.xo-e.xo,r=n.xo-t.xo,o=e.x-e.xo,l=t.x-t.xo,s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){n.x=n.xo+(o+l)/2;return}n.x=n.xo+(o*i+l*s)/h;return}if(a=c.distance(n,e,!0,!0),r=c.distance(n,t,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(t,t,!1,!0),s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){t2.setRelative(n,n,(o+l)/2,c,!0);return}t2.setRelative(n,n,(o*i+l*s)/h,c,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(n,e,t,c,a){if(!c||c===this){n.x=(a?e.xo:e.x)+t;return}var r=a?e.xo:e.x,s=a?e.yo:e.y,i=r+t*c.x,o=s+t*c.y;n.x=i+(n.y-o)/c.normalSlope},slope:0,touch:function(n){n.xTouched=!0},touched:function(n){return n.xTouched},untouch:function(n){n.xTouched=!1}},r2={x:0,y:1,axis:"y",distance:function(n,e,t,c){return(t?n.yo:n.y)-(c?e.yo:e.y)},interpolate:function(n,e,t,c){var a,r,s,i,o,l,h;if(!c||c===this){if(a=n.yo-e.yo,r=n.yo-t.yo,o=e.y-e.yo,l=t.y-t.yo,s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){n.y=n.yo+(o+l)/2;return}n.y=n.yo+(o*i+l*s)/h;return}if(a=c.distance(n,e,!0,!0),r=c.distance(n,t,!0,!0),o=c.distance(e,e,!1,!0),l=c.distance(t,t,!1,!0),s=Math.abs(a),i=Math.abs(r),h=s+i,h===0){r2.setRelative(n,n,(o+l)/2,c,!0);return}r2.setRelative(n,n,(o*i+l*s)/h,c,!0)},normalSlope:0,setRelative:function(n,e,t,c,a){if(!c||c===this){n.y=(a?e.yo:e.y)+t;return}var r=a?e.xo:e.x,s=a?e.yo:e.y,i=r+t*c.x,o=s+t*c.y;n.y=o+c.normalSlope*(n.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(n){n.yTouched=!0},touched:function(n){return n.yTouched},untouch:function(n){n.yTouched=!1}};Object.freeze(t2);Object.freeze(r2);function O3(n,e){this.x=n,this.y=e,this.axis=void 0,this.slope=e/n,this.normalSlope=-n/e,Object.freeze(this)}O3.prototype.distance=function(n,e,t,c){return this.x*t2.distance(n,e,t,c)+this.y*r2.distance(n,e,t,c)};O3.prototype.interpolate=function(n,e,t,c){var a,r,s,i,o,l,h;if(s=c.distance(n,e,!0,!0),i=c.distance(n,t,!0,!0),a=c.distance(e,e,!1,!0),r=c.distance(t,t,!1,!0),o=Math.abs(s),l=Math.abs(i),h=o+l,h===0){this.setRelative(n,n,(a+r)/2,c,!0);return}this.setRelative(n,n,(a*l+r*o)/h,c,!0)};O3.prototype.setRelative=function(n,e,t,c,a){c=c||this;var r=a?e.xo:e.x,s=a?e.yo:e.y,i=r+t*c.x,o=s+t*c.y,l=c.normalSlope,h=this.slope,f=n.x,u=n.y;n.x=(h*f-l*i+o-u)/(h-l),n.y=h*(n.x-f)+u};O3.prototype.touch=function(n){n.xTouched=!0,n.yTouched=!0};function F3(n,e){var t=Math.sqrt(n*n+e*e);return n/=t,e/=t,n===1&&e===0?t2:n===0&&e===1?r2:new O3(n,e)}function s2(n,e,t,c){this.x=this.xo=Math.round(n*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=t,this.onCurve=c,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}s2.prototype.nextTouched=function(n){for(var e=this.nextPointOnContour;!n.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};s2.prototype.prevTouched=function(n){for(var e=this.prevPointOnContour;!n.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var I3=Object.freeze(new s2(0,0)),P9={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function d2(n,e){switch(this.env=n,this.stack=[],this.prog=e,n){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=F7}}O7.prototype.exec=function(n,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(!(this._errorState>2)){var t=this.font,c=this._prepState;if(!c||c.ppem!==e){var a=this._fpgmState;if(!a){d2.prototype=P9,a=this._fpgmState=new d2("fpgm",t.tables.fpgm),a.funcs=[],a.font=t,exports.DEBUG&&(console.log("---EXEC FPGM---"),a.step=-1);try{E2(a)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}d2.prototype=a,c=this._prepState=new d2("prep",t.tables.prep),c.ppem=e;var r=t.tables.cvt;if(r)for(var s=c.cvt=new Array(r.length),i=e/t.unitsPerEm,o=0;o<r.length;o++)s[o]=r[o]*i;else c.cvt=[];exports.DEBUG&&(console.log("---EXEC PREP---"),c.step=-1);try{E2(c)}catch(l){this._errorState<2&&console.log("Hinting error in PREP:"+l),this._errorState=2}}if(!(this._errorState>1))try{return V7(n,c)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}};V7=function(n,e){var t=e.ppem/e.font.unitsPerEm,c=t,a=n.components,r,s,i;if(d2.prototype=e,!a)i=new d2("glyf",n.instructions),exports.DEBUG&&(console.log("---EXEC GLYPH---"),i.step=-1),H4(n,i,t,c),s=i.gZone;else{var o=e.font;s=[],r=[];for(var l=0;l<a.length;l++){var h=a[l],f=o.glyphs.get(h.glyphIndex);i=new d2("glyf",f.instructions),exports.DEBUG&&(console.log("---EXEC COMP "+l+"---"),i.step=-1),H4(f,i,t,c);for(var u=Math.round(h.dx*t),d=Math.round(h.dy*c),m=i.gZone,p=i.contours,g=0;g<m.length;g++){var v=m[g];v.xTouched=v.yTouched=!1,v.xo=v.x=v.x+u,v.yo=v.y=v.y+d}var b=s.length;s.push.apply(s,m);for(var y=0;y<p.length;y++)r.push(p[y]+b)}n.instructions&&!i.inhibitGridFit&&(i=new d2("glyf",n.instructions),i.gZone=i.z0=i.z1=i.z2=s,i.contours=r,s.push(new s2(0,0),new s2(Math.round(n.advanceWidth*t),0)),exports.DEBUG&&(console.log("---EXEC COMPOSITE---"),i.step=-1),E2(i),s.length-=2)}return s};H4=function(n,e,t,c){for(var a=n.points||[],r=a.length,s=e.gZone=e.z0=e.z1=e.z2=[],i=e.contours=[],o,l=0;l<r;l++)o=a[l],s[l]=new s2(o.x*t,o.y*c,o.lastPointOfContour,o.onCurve);for(var h,f,u=0;u<r;u++)o=s[u],h||(h=o,i.push(u)),o.lastPointOfContour?(o.nextPointOnContour=h,h.prevPointOnContour=o,h=void 0):(f=s[u+1],o.nextPointOnContour=f,f.prevPointOnContour=o);if(!e.inhibitGridFit){if(exports.DEBUG){console.log("PROCESSING GLYPH",e.stack);for(var d=0;d<r;d++)console.log(d,s[d].x,s[d].y)}if(s.push(new s2(0,0),new s2(Math.round(n.advanceWidth*t),0)),E2(e),s.length-=2,exports.DEBUG){console.log("FINISHED GLYPH",e.stack);for(var m=0;m<r;m++)console.log(m,s[m].x,s[m].y)}}};E2=function(n){var e=n.prog;if(e){var t=e.length,c;for(n.ip=0;n.ip<t;n.ip++){if(exports.DEBUG&&n.step++,c=H7[e[n.ip]],!c)throw new Error("unknown instruction: 0x"+Number(e[n.ip]).toString(16));c(n)}}};function A5(n){for(var e=n.tZone=new Array(n.gZone.length),t=0;t<e.length;t++)e[t]=new s2(0,0)}function D7(n,e){var t=n.prog,c=n.ip,a=1,r;do if(r=t[++c],r===88)a++;else if(r===89)a--;else if(r===64)c+=t[c+1]+1;else if(r===65)c+=2*t[c+1]+1;else if(r>=176&&r<=183)c+=r-176+1;else if(r>=184&&r<=191)c+=(r-184+1)*2;else if(e&&a===1&&r===27)break;while(a>0);n.ip=c}function E6(n,e){exports.DEBUG&&console.log(e.step,"SVTCA["+n.axis+"]"),e.fv=e.pv=e.dpv=n}function T6(n,e){exports.DEBUG&&console.log(e.step,"SPVTCA["+n.axis+"]"),e.pv=e.dpv=n}function I6(n,e){exports.DEBUG&&console.log(e.step,"SFVTCA["+n.axis+"]"),e.fv=n}function H6(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z2[c],s=e.z1[a];exports.DEBUG&&console.log("SPVTL["+n+"]",c,a);var i,o;n?(i=r.y-s.y,o=s.x-r.x):(i=s.x-r.x,o=s.y-r.y),e.pv=e.dpv=F3(i,o)}function V6(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z2[c],s=e.z1[a];exports.DEBUG&&console.log("SFVTL["+n+"]",c,a);var i,o;n?(i=r.y-s.y,o=s.x-r.x):(i=s.x-r.x,o=s.y-r.y),e.fv=F3(i,o)}function E9(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SPVFS[]",t,c),n.pv=n.dpv=F3(c,t)}function T9(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SPVFS[]",t,c),n.fv=F3(c,t)}function I9(n){var e=n.stack,t=n.pv;exports.DEBUG&&console.log(n.step,"GPV[]"),e.push(t.x*16384),e.push(t.y*16384)}function H9(n){var e=n.stack,t=n.fv;exports.DEBUG&&console.log(n.step,"GFV[]"),e.push(t.x*16384),e.push(t.y*16384)}function V9(n){n.fv=n.pv,exports.DEBUG&&console.log(n.step,"SFVTPV[]")}function O9(n){var e=n.stack,t=e.pop(),c=e.pop(),a=e.pop(),r=e.pop(),s=e.pop(),i=n.z0,o=n.z1,l=i[t],h=i[c],f=o[a],u=o[r],d=n.z2[s];exports.DEBUG&&console.log("ISECT[], ",t,c,a,r,s);var m=l.x,p=l.y,g=h.x,v=h.y,b=f.x,y=f.y,x=u.x,M=u.y,w=(m-g)*(y-M)-(p-v)*(b-x),k=m*v-p*g,S=b*M-y*x;d.x=(k*(b-x)-S*(m-g))/w,d.y=(k*(y-M)-S*(p-v))/w}function F9(n){n.rp0=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SRP0[]",n.rp0)}function _9(n){n.rp1=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SRP1[]",n.rp1)}function D9(n){n.rp2=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SRP2[]",n.rp2)}function R9(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZP0[]",e),n.zp0=e,e){case 0:n.tZone||A5(n),n.z0=n.tZone;break;case 1:n.z0=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function q9(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZP1[]",e),n.zp1=e,e){case 0:n.tZone||A5(n),n.z1=n.tZone;break;case 1:n.z1=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function $9(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZP2[]",e),n.zp2=e,e){case 0:n.tZone||A5(n),n.z2=n.tZone;break;case 1:n.z2=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function U9(n){var e=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"SZPS[]",e),n.zp0=n.zp1=n.zp2=e,e){case 0:n.tZone||A5(n),n.z0=n.z1=n.z2=n.tZone;break;case 1:n.z0=n.z1=n.z2=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function N9(n){n.loop=n.stack.pop(),exports.DEBUG&&console.log(n.step,"SLOOP[]",n.loop)}function B9(n){exports.DEBUG&&console.log(n.step,"RTG[]"),n.round=F7}function G9(n){exports.DEBUG&&console.log(n.step,"RTHG[]"),n.round=A9}function j9(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SMD[]",e),n.minDis=e/64}function W9(n){exports.DEBUG&&console.log(n.step,"ELSE[]"),D7(n,!1)}function X9(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"JMPR[]",e),n.ip+=e-1}function Z9(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SCVTCI[]",e),n.cvCutIn=e/64}function Y9(n){var e=n.stack;exports.DEBUG&&console.log(n.step,"DUP[]"),e.push(e[e.length-1])}function x4(n){exports.DEBUG&&console.log(n.step,"POP[]"),n.stack.pop()}function K9(n){exports.DEBUG&&console.log(n.step,"CLEAR[]"),n.stack.length=0}function J9(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SWAP[]"),e.push(t),e.push(c)}function Q9(n){var e=n.stack;exports.DEBUG&&console.log(n.step,"DEPTH[]"),e.push(e.length)}function ec(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"LOOPCALL[]",t,c);var a=n.ip,r=n.prog;n.prog=n.funcs[t];for(var s=0;s<c;s++)E2(n),exports.DEBUG&&console.log(++n.step,s+1<c?"next loopcall":"done loopcall",s);n.ip=a,n.prog=r}function tc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"CALL[]",e);var t=n.ip,c=n.prog;n.prog=n.funcs[e],E2(n),n.ip=t,n.prog=c,exports.DEBUG&&console.log(++n.step,"returning from",e)}function nc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"CINDEX[]",t),e.push(e[e.length-t])}function cc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"MINDEX[]",t),e.push(e.splice(e.length-t,1)[0])}function ac(n){if(n.env!=="fpgm")throw new Error("FDEF not allowed here");var e=n.stack,t=n.prog,c=n.ip,a=e.pop(),r=c;for(exports.DEBUG&&console.log(n.step,"FDEF[]",a);t[++c]!==45;);n.ip=c,n.funcs[a]=t.slice(r+1,c)}function O6(n,e){var t=e.stack.pop(),c=e.z0[t],a=e.fv,r=e.pv;exports.DEBUG&&console.log(e.step,"MDAP["+n+"]",t);var s=r.distance(c,I3);n&&(s=e.round(s)),a.setRelative(c,I3,s,r),a.touch(c),e.rp0=e.rp1=t}function F6(n,e){var t=e.z2,c=t.length-2,a,r,s;exports.DEBUG&&console.log(e.step,"IUP["+n.axis+"]");for(var i=0;i<c;i++)a=t[i],!n.touched(a)&&(r=a.prevTouched(n),r!==a&&(s=a.nextTouched(n),r===s&&n.setRelative(a,a,n.distance(r,r,!1,!0),n,!0),n.interpolate(a,r,s,n)))}function _6(n,e){for(var t=e.stack,c=n?e.rp1:e.rp2,a=(n?e.z0:e.z1)[c],r=e.fv,s=e.pv,i=e.loop,o=e.z2;i--;){var l=t.pop(),h=o[l],f=s.distance(a,a,!1,!0);r.setRelative(h,h,f,s),r.touch(h),exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-i)+": ":"")+"SHP["+(n?"rp1":"rp2")+"]",l)}e.loop=1}function D6(n,e){var t=e.stack,c=n?e.rp1:e.rp2,a=(n?e.z0:e.z1)[c],r=e.fv,s=e.pv,i=t.pop(),o=e.z2[e.contours[i]],l=o;exports.DEBUG&&console.log(e.step,"SHC["+n+"]",i);var h=s.distance(a,a,!1,!0);do l!==a&&r.setRelative(l,l,h,s),l=l.nextPointOnContour;while(l!==o)}function R6(n,e){var t=e.stack,c=n?e.rp1:e.rp2,a=(n?e.z0:e.z1)[c],r=e.fv,s=e.pv,i=t.pop();exports.DEBUG&&console.log(e.step,"SHZ["+n+"]",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(a,a,!1,!0),f=o.length-2,u=0;u<f;u++)l=o[u],r.setRelative(l,l,h,s)}function rc(n){for(var e=n.stack,t=n.loop,c=n.fv,a=e.pop()/64,r=n.z2;t--;){var s=e.pop(),i=r[s];exports.DEBUG&&console.log(n.step,(n.loop>1?"loop "+(n.loop-t)+": ":"")+"SHPIX[]",s,a),c.setRelative(i,i,a),c.touch(i)}n.loop=1}function sc(n){for(var e=n.stack,t=n.rp1,c=n.rp2,a=n.loop,r=n.z0[t],s=n.z1[c],i=n.fv,o=n.dpv,l=n.z2;a--;){var h=e.pop(),f=l[h];exports.DEBUG&&console.log(n.step,(n.loop>1?"loop "+(n.loop-a)+": ":"")+"IP[]",h,t,"<->",c),i.interpolate(f,r,s,o),i.touch(f)}n.loop=1}function q6(n,e){var t=e.stack,c=t.pop()/64,a=t.pop(),r=e.z1[a],s=e.z0[e.rp0],i=e.fv,o=e.pv;i.setRelative(r,s,c,o),i.touch(r),exports.DEBUG&&console.log(e.step,"MSIRP["+n+"]",c,a),e.rp1=e.rp0,e.rp2=a,n&&(e.rp0=a)}function ic(n){for(var e=n.stack,t=n.rp0,c=n.z0[t],a=n.loop,r=n.fv,s=n.pv,i=n.z1;a--;){var o=e.pop(),l=i[o];exports.DEBUG&&console.log(n.step,(n.loop>1?"loop "+(n.loop-a)+": ":"")+"ALIGNRP[]",o),r.setRelative(l,c,0,s),r.touch(l)}n.loop=1}function oc(n){exports.DEBUG&&console.log(n.step,"RTDG[]"),n.round=L9}function $6(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z0[a],s=e.fv,i=e.pv,o=e.cvt[c];exports.DEBUG&&console.log(e.step,"MIAP["+n+"]",c,"(",o,")",a);var l=i.distance(r,I3);n&&(Math.abs(l-o)<e.cvCutIn&&(l=o),l=e.round(l)),s.setRelative(r,I3,l,i),e.zp0===0&&(r.xo=r.x,r.yo=r.y),s.touch(r),e.rp0=e.rp1=a}function lc(n){var e=n.prog,t=n.ip,c=n.stack,a=e[++t];exports.DEBUG&&console.log(n.step,"NPUSHB[]",a);for(var r=0;r<a;r++)c.push(e[++t]);n.ip=t}function hc(n){var e=n.ip,t=n.prog,c=n.stack,a=t[++e];exports.DEBUG&&console.log(n.step,"NPUSHW[]",a);for(var r=0;r<a;r++){var s=t[++e]<<8|t[++e];s&32768&&(s=-((s^65535)+1)),c.push(s)}n.ip=e}function uc(n){var e=n.stack,t=n.store;t||(t=n.store=[]);var c=e.pop(),a=e.pop();exports.DEBUG&&console.log(n.step,"WS",c,a),t[a]=c}function fc(n){var e=n.stack,t=n.store,c=e.pop();exports.DEBUG&&console.log(n.step,"RS",c);var a=t&&t[c]||0;e.push(a)}function dc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"WCVTP",t,c),n.cvt[c]=t/64}function pc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"RCVT",t),e.push(n.cvt[t]*64)}function U6(n,e){var t=e.stack,c=t.pop(),a=e.z2[c];exports.DEBUG&&console.log(e.step,"GC["+n+"]",c),t.push(e.dpv.distance(a,I3,n,!1)*64)}function N6(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z1[c],s=e.z0[a],i=e.dpv.distance(s,r,n,n);exports.DEBUG&&console.log(e.step,"MD["+n+"]",c,a,"->",i),e.stack.push(Math.round(i*64))}function mc(n){exports.DEBUG&&console.log(n.step,"MPPEM[]"),n.stack.push(n.ppem)}function gc(n){exports.DEBUG&&console.log(n.step,"FLIPON[]"),n.autoFlip=!0}function vc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"LT[]",t,c),e.push(c<t?1:0)}function bc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"LTEQ[]",t,c),e.push(c<=t?1:0)}function yc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"GT[]",t,c),e.push(c>t?1:0)}function xc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"GTEQ[]",t,c),e.push(c>=t?1:0)}function Mc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"EQ[]",t,c),e.push(t===c?1:0)}function wc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"NEQ[]",t,c),e.push(t!==c?1:0)}function zc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"ODD[]",t),e.push(Math.trunc(t)%2?1:0)}function kc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"EVEN[]",t),e.push(Math.trunc(t)%2?0:1)}function Lc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"IF[]",e),e||(D7(n,!0),exports.DEBUG&&console.log(n.step,"EIF[]"))}function Ac(n){exports.DEBUG&&console.log(n.step,"EIF[]")}function Sc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"AND[]",t,c),e.push(t&&c?1:0)}function Cc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"OR[]",t,c),e.push(t||c?1:0)}function Pc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"NOT[]",t),e.push(t?0:1)}function M4(n,e){var t=e.stack,c=t.pop(),a=e.fv,r=e.pv,s=e.ppem,i=e.deltaBase+(n-1)*16,o=e.deltaShift,l=e.z0;exports.DEBUG&&console.log(e.step,"DELTAP["+n+"]",c,t);for(var h=0;h<c;h++){var f=t.pop(),u=t.pop(),d=i+((u&240)>>4);if(d===s){var m=(u&15)-8;m>=0&&m++,exports.DEBUG&&console.log(e.step,"DELTAPFIX",f,"by",m*o);var p=l[f];a.setRelative(p,p,m*o,r)}}}function Ec(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"SDB[]",t),n.deltaBase=t}function Tc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"SDS[]",t),n.deltaShift=Math.pow(.5,t)}function Ic(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"ADD[]",t,c),e.push(c+t)}function Hc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"SUB[]",t,c),e.push(c-t)}function Vc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"DIV[]",t,c),e.push(c*64/t)}function Oc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"MUL[]",t,c),e.push(c*t/64)}function Fc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"ABS[]",t),e.push(Math.abs(t))}function _c(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"NEG[]",t),e.push(-t)}function Dc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"FLOOR[]",t),e.push(Math.floor(t/64)*64)}function Rc(n){var e=n.stack,t=e.pop();exports.DEBUG&&console.log(n.step,"CEILING[]",t),e.push(Math.ceil(t/64)*64)}function v5(n,e){var t=e.stack,c=t.pop();exports.DEBUG&&console.log(e.step,"ROUND[]"),t.push(e.round(c/64)*64)}function qc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"WCVTF[]",t,c),n.cvt[c]=t*n.ppem/n.font.unitsPerEm}function w4(n,e){var t=e.stack,c=t.pop(),a=e.ppem,r=e.deltaBase+(n-1)*16,s=e.deltaShift;exports.DEBUG&&console.log(e.step,"DELTAC["+n+"]",c,t);for(var i=0;i<c;i++){var o=t.pop(),l=t.pop(),h=r+((l&240)>>4);if(h===a){var f=(l&15)-8;f>=0&&f++;var u=f*s;exports.DEBUG&&console.log(e.step,"DELTACFIX",o,"by",u),e.cvt[o]+=u}}}function $c(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SROUND[]",e),n.round=_7;var t;switch(e&192){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(n.srPeriod=t,e&48){case 0:n.srPhase=0;break;case 16:n.srPhase=.25*t;break;case 32:n.srPhase=.5*t;break;case 48:n.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?n.srThreshold=0:n.srThreshold=(e/8-.5)*t}function Uc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"S45ROUND[]",e),n.round=_7;var t;switch(e&192){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(n.srPeriod=t,e&48){case 0:n.srPhase=0;break;case 16:n.srPhase=.25*t;break;case 32:n.srPhase=.5*t;break;case 48:n.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?n.srThreshold=0:n.srThreshold=(e/8-.5)*t}function Nc(n){exports.DEBUG&&console.log(n.step,"ROFF[]"),n.round=k9}function Bc(n){exports.DEBUG&&console.log(n.step,"RUTG[]"),n.round=S9}function Gc(n){exports.DEBUG&&console.log(n.step,"RDTG[]"),n.round=C9}function jc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SCANCTRL[]",e)}function B6(n,e){var t=e.stack,c=t.pop(),a=t.pop(),r=e.z2[c],s=e.z1[a];exports.DEBUG&&console.log(e.step,"SDPVTL["+n+"]",c,a);var i,o;n?(i=r.y-s.y,o=s.x-r.x):(i=s.x-r.x,o=s.y-r.y),e.dpv=F3(i,o)}function Wc(n){var e=n.stack,t=e.pop(),c=0;exports.DEBUG&&console.log(n.step,"GETINFO[]",t),t&1&&(c=35),t&32&&(c|=4096),e.push(c)}function Xc(n){var e=n.stack,t=e.pop(),c=e.pop(),a=e.pop();exports.DEBUG&&console.log(n.step,"ROLL[]"),e.push(c),e.push(t),e.push(a)}function Zc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"MAX[]",t,c),e.push(Math.max(c,t))}function Yc(n){var e=n.stack,t=e.pop(),c=e.pop();exports.DEBUG&&console.log(n.step,"MIN[]",t,c),e.push(Math.min(c,t))}function Kc(n){var e=n.stack.pop();exports.DEBUG&&console.log(n.step,"SCANTYPE[]",e)}function Jc(n){var e=n.stack.pop(),t=n.stack.pop();switch(exports.DEBUG&&console.log(n.step,"INSTCTRL[]",e,t),e){case 1:n.inhibitGridFit=!!t;return;case 2:n.ignoreCvt=!!t;return;default:throw new Error("invalid INSTCTRL[] selector")}}function h2(n,e){var t=e.stack,c=e.prog,a=e.ip;exports.DEBUG&&console.log(e.step,"PUSHB["+n+"]");for(var r=0;r<n;r++)t.push(c[++a]);e.ip=a}function u2(n,e){var t=e.ip,c=e.prog,a=e.stack;exports.DEBUG&&console.log(e.ip,"PUSHW["+n+"]");for(var r=0;r<n;r++){var s=c[++t]<<8|c[++t];s&32768&&(s=-((s^65535)+1)),a.push(s)}e.ip=t}function Z(n,e,t,c,a,r){var s=r.stack,i=n&&s.pop(),o=s.pop(),l=r.rp0,h=r.z0[l],f=r.z1[o],u=r.minDis,d=r.fv,m=r.dpv,p,g,v,b;g=p=m.distance(f,h,!0,!0),v=g>=0?1:-1,g=Math.abs(g),n&&(b=r.cvt[i],c&&Math.abs(g-b)<r.cvCutIn&&(g=b)),t&&g<u&&(g=u),c&&(g=r.round(g)),d.setRelative(f,h,v*g,m),d.touch(f),exports.DEBUG&&console.log(r.step,(n?"MIRP[":"MDRP[")+(e?"M":"m")+(t?">":"_")+(c?"R":"_")+(a===0?"Gr":a===1?"Bl":a===2?"Wh":"")+"]",n?i+"("+r.cvt[i]+","+b+")":"",o,"(d =",p,"->",v*g,")"),r.rp1=r.rp0,r.rp2=o,e&&(r.rp0=o)}H7=[E6.bind(void 0,r2),E6.bind(void 0,t2),T6.bind(void 0,r2),T6.bind(void 0,t2),I6.bind(void 0,r2),I6.bind(void 0,t2),H6.bind(void 0,0),H6.bind(void 0,1),V6.bind(void 0,0),V6.bind(void 0,1),E9,T9,I9,H9,V9,O9,F9,_9,D9,R9,q9,$9,U9,N9,B9,G9,j9,W9,X9,Z9,void 0,void 0,Y9,x4,K9,J9,Q9,nc,cc,void 0,void 0,void 0,ec,tc,ac,void 0,O6.bind(void 0,0),O6.bind(void 0,1),F6.bind(void 0,r2),F6.bind(void 0,t2),_6.bind(void 0,0),_6.bind(void 0,1),D6.bind(void 0,0),D6.bind(void 0,1),R6.bind(void 0,0),R6.bind(void 0,1),rc,sc,q6.bind(void 0,0),q6.bind(void 0,1),ic,oc,$6.bind(void 0,0),$6.bind(void 0,1),lc,hc,uc,fc,dc,pc,U6.bind(void 0,0),U6.bind(void 0,1),void 0,N6.bind(void 0,0),N6.bind(void 0,1),mc,void 0,gc,void 0,void 0,vc,bc,yc,xc,Mc,wc,zc,kc,Lc,Ac,Sc,Cc,Pc,M4.bind(void 0,1),Ec,Tc,Ic,Hc,Vc,Oc,Fc,_c,Dc,Rc,v5.bind(void 0,0),v5.bind(void 0,1),v5.bind(void 0,2),v5.bind(void 0,3),void 0,void 0,void 0,void 0,qc,M4.bind(void 0,2),M4.bind(void 0,3),w4.bind(void 0,1),w4.bind(void 0,2),w4.bind(void 0,3),$c,Uc,void 0,void 0,Nc,void 0,Bc,Gc,x4,x4,void 0,void 0,void 0,void 0,void 0,jc,B6.bind(void 0,0),B6.bind(void 0,1),Wc,void 0,Xc,Zc,Yc,Kc,Jc,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,h2.bind(void 0,1),h2.bind(void 0,2),h2.bind(void 0,3),h2.bind(void 0,4),h2.bind(void 0,5),h2.bind(void 0,6),h2.bind(void 0,7),h2.bind(void 0,8),u2.bind(void 0,1),u2.bind(void 0,2),u2.bind(void 0,3),u2.bind(void 0,4),u2.bind(void 0,5),u2.bind(void 0,6),u2.bind(void 0,7),u2.bind(void 0,8),Z.bind(void 0,0,0,0,0,0),Z.bind(void 0,0,0,0,0,1),Z.bind(void 0,0,0,0,0,2),Z.bind(void 0,0,0,0,0,3),Z.bind(void 0,0,0,0,1,0),Z.bind(void 0,0,0,0,1,1),Z.bind(void 0,0,0,0,1,2),Z.bind(void 0,0,0,0,1,3),Z.bind(void 0,0,0,1,0,0),Z.bind(void 0,0,0,1,0,1),Z.bind(void 0,0,0,1,0,2),Z.bind(void 0,0,0,1,0,3),Z.bind(void 0,0,0,1,1,0),Z.bind(void 0,0,0,1,1,1),Z.bind(void 0,0,0,1,1,2),Z.bind(void 0,0,0,1,1,3),Z.bind(void 0,0,1,0,0,0),Z.bind(void 0,0,1,0,0,1),Z.bind(void 0,0,1,0,0,2),Z.bind(void 0,0,1,0,0,3),Z.bind(void 0,0,1,0,1,0),Z.bind(void 0,0,1,0,1,1),Z.bind(void 0,0,1,0,1,2),Z.bind(void 0,0,1,0,1,3),Z.bind(void 0,0,1,1,0,0),Z.bind(void 0,0,1,1,0,1),Z.bind(void 0,0,1,1,0,2),Z.bind(void 0,0,1,1,0,3),Z.bind(void 0,0,1,1,1,0),Z.bind(void 0,0,1,1,1,1),Z.bind(void 0,0,1,1,1,2),Z.bind(void 0,0,1,1,1,3),Z.bind(void 0,1,0,0,0,0),Z.bind(void 0,1,0,0,0,1),Z.bind(void 0,1,0,0,0,2),Z.bind(void 0,1,0,0,0,3),Z.bind(void 0,1,0,0,1,0),Z.bind(void 0,1,0,0,1,1),Z.bind(void 0,1,0,0,1,2),Z.bind(void 0,1,0,0,1,3),Z.bind(void 0,1,0,1,0,0),Z.bind(void 0,1,0,1,0,1),Z.bind(void 0,1,0,1,0,2),Z.bind(void 0,1,0,1,0,3),Z.bind(void 0,1,0,1,1,0),Z.bind(void 0,1,0,1,1,1),Z.bind(void 0,1,0,1,1,2),Z.bind(void 0,1,0,1,1,3),Z.bind(void 0,1,1,0,0,0),Z.bind(void 0,1,1,0,0,1),Z.bind(void 0,1,1,0,0,2),Z.bind(void 0,1,1,0,0,3),Z.bind(void 0,1,1,0,1,0),Z.bind(void 0,1,1,0,1,1),Z.bind(void 0,1,1,0,1,2),Z.bind(void 0,1,1,0,1,3),Z.bind(void 0,1,1,1,0,0),Z.bind(void 0,1,1,1,0,1),Z.bind(void 0,1,1,1,0,2),Z.bind(void 0,1,1,1,0,3),Z.bind(void 0,1,1,1,1,0),Z.bind(void 0,1,1,1,1,1),Z.bind(void 0,1,1,1,1,2),Z.bind(void 0,1,1,1,1,3)];function K2(n){this.char=n,this.state={},this.activeState=null}function U4(n,e,t){this.contextName=t,this.startIndex=n,this.endOffset=e}function Qc(n,e,t){this.contextName=n,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=t}function R0(n,e){this.context=n,this.index=e,this.length=n.length,this.current=n[e],this.backtrack=n.slice(0,e),this.lookahead=n.slice(e+1)}function S5(n){this.eventId=n,this.subscribers=[]}function ea(n){var e=this,t=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];t.forEach(function(a){Object.defineProperty(e.events,a,{value:new S5(a)})}),n&&t.forEach(function(a){var r=n[a];typeof r=="function"&&e.events[a].subscribe(r)});var c=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];c.forEach(function(a){e.events[a].subscribe(e.updateContextsRanges)})}function U1(n){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],ea.call(this,n)}K2.prototype.setState=function(n,e){return this.state[n]=e,this.activeState={key:n,value:this.state[n]},this.activeState};K2.prototype.getState=function(n){return this.state[n]||null};U1.prototype.inboundIndex=function(n){return n>=0&&n<this.tokens.length};U1.prototype.composeRUD=function(n){var e=this,t=!0,c=n.map(function(r){return e[r[0]].apply(e,r.slice(1).concat(t))}),a=function(r){return typeof r=="object"&&r.hasOwnProperty("FAIL")};if(c.every(a))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:c.filter(a)};this.dispatch("composeRUD",[c.filter(function(r){return!a(r)})])};U1.prototype.replaceRange=function(n,e,t,c){e=e!==null?e:this.tokens.length;var a=t.every(function(s){return s instanceof K2});if(!isNaN(n)&&this.inboundIndex(n)&&a){var r=this.tokens.splice.apply(this.tokens,[n,e].concat(t));return c||this.dispatch("replaceToken",[n,e,t]),[r,t]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};U1.prototype.replaceToken=function(n,e,t){if(!isNaN(n)&&this.inboundIndex(n)&&e instanceof K2){var c=this.tokens.splice(n,1,e);return t||this.dispatch("replaceToken",[n,e]),[c[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};U1.prototype.removeRange=function(n,e,t){e=isNaN(e)?this.tokens.length:e;var c=this.tokens.splice(n,e);return t||this.dispatch("removeRange",[c,n,e]),c};U1.prototype.removeToken=function(n,e){if(!isNaN(n)&&this.inboundIndex(n)){var t=this.tokens.splice(n,1);return e||this.dispatch("removeToken",[t,n]),t}else return{FAIL:"removeToken: invalid token index."}};U1.prototype.insertToken=function(n,e,t){var c=n.every(function(a){return a instanceof K2});return c?(this.tokens.splice.apply(this.tokens,[e,0].concat(n)),t||this.dispatch("insertToken",[n,e]),n):{FAIL:"insertToken: invalid token(s)."}};U1.prototype.registerModifier=function(n,e,t){this.events.newToken.subscribe(function(c,a){var r=[c,a],s=e===null||e.apply(this,r)===!0,i=[c,a];if(s){var o=t.apply(this,i);c.setState(n,o)}}),this.registeredModifiers.push(n)};S5.prototype.subscribe=function(n){return typeof n=="function"?this.subscribers.push(n)-1:{FAIL:"invalid '"+this.eventId+"' event handler"}};S5.prototype.unsubscribe=function(n){this.subscribers.splice(n,1)};R0.prototype.setCurrentIndex=function(n){this.index=n,this.current=this.context[n],this.backtrack=this.context.slice(0,n),this.lookahead=this.context.slice(n+1)};R0.prototype.get=function(n){switch(!0){case n===0:return this.current;case(n<0&&Math.abs(n)<=this.backtrack.length):return this.backtrack.slice(n)[0];case(n>0&&n<=this.lookahead.length):return this.lookahead[n-1];default:return null}};U1.prototype.rangeToText=function(n){if(n instanceof U4)return this.getRangeTokens(n).map(function(e){return e.char}).join("")};U1.prototype.getText=function(){return this.tokens.map(function(n){return n.char}).join("")};U1.prototype.getContext=function(n){var e=this.registeredContexts[n];return e||null};U1.prototype.on=function(n,e){var t=this.events[n];return t?t.subscribe(e):null};U1.prototype.dispatch=function(n,e){var t=this,c=this.events[n];c instanceof S5&&c.subscribers.forEach(function(a){a.apply(t,e||[])})};U1.prototype.registerContextChecker=function(n,e,t){if(this.getContext(n))return{FAIL:"context name '"+n+"' is already registered."};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof t!="function")return{FAIL:"missing context end check."};var c=new Qc(n,e,t);return this.registeredContexts[n]=c,this.contextCheckers.push(c),c};U1.prototype.getRangeTokens=function(n){var e=n.startIndex+n.endOffset;return[].concat(this.tokens.slice(n.startIndex,e))};U1.prototype.getContextRanges=function(n){var e=this.getContext(n);return e?e.ranges:{FAIL:"context checker '"+n+"' is not registered."}};U1.prototype.resetContextsRanges=function(){var n=this.registeredContexts;for(var e in n)if(n.hasOwnProperty(e)){var t=n[e];t.ranges=[]}};U1.prototype.updateContextsRanges=function(){this.resetContextsRanges();for(var n=this.tokens.map(function(c){return c.char}),e=0;e<n.length;e++){var t=new R0(n,e);this.runContextCheck(t)}this.dispatch("updateContextsRanges",[this.registeredContexts])};U1.prototype.setEndOffset=function(n,e){var t=this.getContext(e).openRange.startIndex,c=new U4(t,n,e),a=this.getContext(e).ranges;return c.rangeId=e+"."+a.length,a.push(c),this.getContext(e).openRange=null,c};U1.prototype.runContextCheck=function(n){var e=this,t=n.index;this.contextCheckers.forEach(function(c){var a=c.contextName,r=e.getContext(a).openRange;if(!r&&c.checkStart(n)&&(r=new U4(t,null,a),e.getContext(a).openRange=r,e.dispatch("contextStart",[a,t])),r&&c.checkEnd(n)){var s=t-r.startIndex+1,i=e.setEndOffset(s,a);e.dispatch("contextEnd",[a,i])}})};U1.prototype.tokenize=function(n){this.tokens=[],this.resetContextsRanges();var e=Array.from(n);this.dispatch("start");for(var t=0;t<e.length;t++){var c=e[t],a=new R0(e,t);this.dispatch("next",[a]),this.runContextCheck(a);var r=new K2(c);this.tokens.push(r),this.dispatch("newToken",[r,a])}return this.dispatch("end",[this.tokens]),this.tokens};function p2(n){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(n)}function R7(n){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(n)}function m2(n){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(n)}function y5(n){return/[A-z]/.test(n)}function ta(n){return/\s/.test(n)}function S0(n){this.font=n,this.features={}}function P2(n){this.id=n.id,this.tag=n.tag,this.substitution=n.substitution}function _3(n,e){if(!n)return-1;switch(e.format){case 1:return e.glyphs.indexOf(n);case 2:for(var t=e.ranges,c=0;c<t.length;c++){var a=t[c];if(n>=a.start&&n<=a.end){var r=n-a.start;return a.index+r}}break;default:return-1}return-1}function na(n,e){var t=_3(n,e.coverage);return t===-1?null:n+e.deltaGlyphId}function ca(n,e){var t=_3(n,e.coverage);return t===-1?null:e.substitute[t]}function z4(n,e){for(var t=[],c=0;c<n.length;c++){var a=n[c],r=e.current;r=Array.isArray(r)?r[0]:r;var s=_3(r,a);s!==-1&&t.push(s)}return t.length!==n.length?-1:t}function aa(n,e){var t=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(n.context.length<t)return[];var c=z4(e.inputCoverage,n);if(c===-1)return[];var a=e.inputCoverage.length-1;if(n.lookahead.length<e.lookaheadCoverage.length)return[];for(var r=n.lookahead.slice(a);r.length&&m2(r[0].char);)r.shift();var s=new R0(r,0),i=z4(e.lookaheadCoverage,s),o=[].concat(n.backtrack);for(o.reverse();o.length&&m2(o[0].char);)o.shift();if(o.length<e.backtrackCoverage.length)return[];var l=new R0(o,0),h=z4(e.backtrackCoverage,l),f=c.length===e.inputCoverage.length&&i.length===e.lookaheadCoverage.length&&h.length===e.backtrackCoverage.length,u=[];if(f)for(var d=0;d<e.lookupRecords.length;d++)for(var m=e.lookupRecords[d],p=m.lookupListIndex,g=this.getLookupByIndex(p),v=0;v<g.subtables.length;v++){var b=g.subtables[v],y=this.getLookupMethod(g,b),x=this.getSubstitutionType(g,b);if(x==="12")for(var M=0;M<c.length;M++){var w=n.get(M),k=y(w);k&&u.push(k)}}return u}function ra(n,e){var t=n.current,c=_3(t,e.coverage);if(c===-1)return null;for(var a,r=e.ligatureSets[c],s=0;s<r.length;s++){a=r[s];for(var i=0;i<a.components.length;i++){var o=n.lookahead[i],l=a.components[i];if(o!==l)break;if(i===a.components.length-1)return a}}return null}function sa(n,e){var t=_3(n,e.coverage);return t===-1?null:e.sequences[t]}S0.prototype.getDefaultScriptFeaturesIndexes=function(){for(var n=this.font.tables.gsub.scripts,e=0;e<n.length;e++){var t=n[e];if(t.tag==="DFLT")return t.script.defaultLangSys.featureIndexes}return[]};S0.prototype.getScriptFeaturesIndexes=function(n){var e=this.font.tables;if(!e.gsub)return[];if(!n)return this.getDefaultScriptFeaturesIndexes();for(var t=this.font.tables.gsub.scripts,c=0;c<t.length;c++){var a=t[c];if(a.tag===n&&a.script.defaultLangSys)return a.script.defaultLangSys.featureIndexes;var r=a.langSysRecords;if(r)for(var s=0;s<r.length;s++){var i=r[s];if(i.tag===n){var o=i.langSys;return o.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};S0.prototype.mapTagsToFeatures=function(n,e){for(var t={},c=0;c<n.length;c++){var a=n[c].tag,r=n[c].feature;t[a]=r}this.features[e].tags=t};S0.prototype.getScriptFeatures=function(n){var e=this.features[n];if(this.features.hasOwnProperty(n))return e;var t=this.getScriptFeaturesIndexes(n);if(!t)return null;var c=this.font.tables.gsub;return e=t.map(function(a){return c.features[a]}),this.features[n]=e,this.mapTagsToFeatures(e,n),e};S0.prototype.getSubstitutionType=function(n,e){var t=n.lookupType.toString(),c=e.substFormat.toString();return t+c};S0.prototype.getLookupMethod=function(n,e){var t=this,c=this.getSubstitutionType(n,e);switch(c){case"11":return function(a){return na.apply(t,[a,e])};case"12":return function(a){return ca.apply(t,[a,e])};case"63":return function(a){return aa.apply(t,[a,e])};case"41":return function(a){return ra.apply(t,[a,e])};case"21":return function(a){return sa.apply(t,[a,e])};default:throw new Error("lookupType: "+n.lookupType+" - substFormat: "+e.substFormat+" is not yet supported")}};S0.prototype.lookupFeature=function(n){var e=n.contextParams,t=e.index,c=this.getFeature({tag:n.tag,script:n.script});if(!c)return new Error("font '"+this.font.names.fullName.en+"' doesn't support feature '"+n.tag+"' for script '"+n.script+"'.");for(var a=this.getFeatureLookups(c),r=[].concat(e.context),s=0;s<a.length;s++)for(var i=a[s],o=this.getLookupSubtables(i),l=0;l<o.length;l++){var h=o[l],f=this.getSubstitutionType(i,h),u=this.getLookupMethod(i,h),d=void 0;switch(f){case"11":d=u(e.current),d&&r.splice(t,1,new P2({id:11,tag:n.tag,substitution:d}));break;case"12":d=u(e.current),d&&r.splice(t,1,new P2({id:12,tag:n.tag,substitution:d}));break;case"63":d=u(e),Array.isArray(d)&&d.length&&r.splice(t,1,new P2({id:63,tag:n.tag,substitution:d}));break;case"41":d=u(e),d&&r.splice(t,1,new P2({id:41,tag:n.tag,substitution:d}));break;case"21":d=u(e.current),d&&r.splice(t,1,new P2({id:21,tag:n.tag,substitution:d}));break}e=new R0(r,t),!(Array.isArray(d)&&!d.length)&&(d=null)}return r.length?r:null};S0.prototype.supports=function(n){if(!n.script)return!1;this.getScriptFeatures(n.script);var e=this.features.hasOwnProperty(n.script);if(!n.tag)return e;var t=this.features[n.script].some(function(c){return c.tag===n.tag});return e&&t};S0.prototype.getLookupSubtables=function(n){return n.subtables||null};S0.prototype.getLookupByIndex=function(n){var e=this.font.tables.gsub.lookups;return e[n]||null};S0.prototype.getFeatureLookups=function(n){return n.lookupListIndexes.map(this.getLookupByIndex.bind(this))};S0.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};this.features.hasOwnProperty(e.script)||this.getScriptFeatures(e.script);var t=this.features[e.script];return t?t.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:"No feature for script "+e.script}};function ia(n){var e=n.current,t=n.get(-1);return t===null&&p2(e)||!p2(t)&&p2(e)}function oa(n){var e=n.get(1);return e===null||!p2(e)}var la={startCheck:ia,endCheck:oa};function ha(n){var e=n.current,t=n.get(-1);return(p2(e)||m2(e))&&!p2(t)}function ua(n){var e=n.get(1);switch(!0){case e===null:return!0;case(!p2(e)&&!m2(e)):var t=ta(e);if(!t)return!0;if(t){var c=!1;if(c=n.lookahead.some(function(a){return p2(a)||m2(a)}),!c)return!0}break;default:return!1}}var fa={startCheck:ha,endCheck:ua};function da(n,e,t){e[t].setState(n.tag,n.substitution)}function pa(n,e,t){e[t].setState(n.tag,n.substitution)}function ma(n,e,t){n.substitution.forEach(function(c,a){var r=e[t+a];r.setState(n.tag,c)})}function ga(n,e,t){var c=e[t];c.setState(n.tag,n.substitution.ligGlyph);for(var a=n.substitution.components.length,r=0;r<a;r++)c=e[t+r+1],c.setState("deleted",!0)}var G6={11:da,12:pa,63:ma,41:ga};function N4(n,e,t){n instanceof P2&&G6[n.id]&&G6[n.id](n,e,t)}function va(n){for(var e=[].concat(n.backtrack),t=e.length-1;t>=0;t--){var c=e[t],a=R7(c),r=m2(c);if(!a&&!r)return!0;if(a)return!1}return!1}function ba(n){if(R7(n.current))return!1;for(var e=0;e<n.lookahead.length;e++){var t=n.lookahead[e],c=m2(t);if(!c)return!0}return!1}function ya(n){var e=this,t="arab",c=this.featuresTags[t],a=this.tokenizer.getRangeTokens(n);if(a.length!==1){var r=new R0(a.map(function(i){return i.getState("glyphIndex")}),0),s=new R0(a.map(function(i){return i.char}),0);a.forEach(function(i,o){if(!m2(i.char)){r.setCurrentIndex(o),s.setCurrentIndex(o);var l=0;va(s)&&(l|=1),ba(s)&&(l|=2);var h;switch(l){case 1:h="fina";break;case 2:h="init";break;case 3:h="medi";break}if(c.indexOf(h)!==-1){var f=e.query.lookupFeature({tag:h,script:t,contextParams:r});if(f instanceof Error)return console.info(f.message);f.forEach(function(u,d){u instanceof P2&&(N4(u,a,d),r.context[d]=u.substitution)})}}})}}function j6(n,e){var t=n.map(function(c){return c.activeState.value});return new R0(t,e||0)}function xa(n){var e=this,t="arab",c=this.tokenizer.getRangeTokens(n),a=j6(c);a.context.forEach(function(r,s){a.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"rlig",script:t,contextParams:a});i.length&&(i.forEach(function(o){return N4(o,c,s)}),a=j6(c))})}function Ma(n){var e=n.current,t=n.get(-1);return t===null&&y5(e)||!y5(t)&&y5(e)}function wa(n){var e=n.get(1);return e===null||!y5(e)}var za={startCheck:Ma,endCheck:wa};function W6(n,e){var t=n.map(function(c){return c.activeState.value});return new R0(t,e||0)}function ka(n){var e=this,t="latn",c=this.tokenizer.getRangeTokens(n),a=W6(c);a.context.forEach(function(r,s){a.setCurrentIndex(s);var i=e.query.lookupFeature({tag:"liga",script:t,contextParams:a});i.length&&(i.forEach(function(o){return N4(o,c,s)}),a=W6(c))})}function U0(n){this.baseDir=n||"ltr",this.tokenizer=new U1,this.featuresTags={}}U0.prototype.setText=function(n){this.text=n};U0.prototype.contextChecks={latinWordCheck:za,arabicWordCheck:la,arabicSentenceCheck:fa};function k4(n){var e=this.contextChecks[n+"Check"];return this.tokenizer.registerContextChecker(n,e.startCheck,e.endCheck)}function La(){return k4.call(this,"latinWord"),k4.call(this,"arabicWord"),k4.call(this,"arabicSentence"),this.tokenizer.tokenize(this.text)}function Aa(){var n=this,e=this.tokenizer.getContextRanges("arabicSentence");e.forEach(function(t){var c=n.tokenizer.getRangeTokens(t);n.tokenizer.replaceRange(t.startIndex,t.endOffset,c.reverse())})}U0.prototype.registerFeatures=function(n,e){var t=this,c=e.filter(function(a){return t.query.supports({script:n,tag:a})});this.featuresTags.hasOwnProperty(n)?this.featuresTags[n]=this.featuresTags[n].concat(c):this.featuresTags[n]=c};U0.prototype.applyFeatures=function(n,e){if(!n)throw new Error("No valid font was provided to apply features");this.query||(this.query=new S0(n));for(var t=0;t<e.length;t++){var c=e[t];this.query.supports({script:c.script})&&this.registerFeatures(c.script,c.tags)}};U0.prototype.registerModifier=function(n,e,t){this.tokenizer.registerModifier(n,e,t)};function B4(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function Sa(){var n=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){B4.call(this);var t=this.tokenizer.getContextRanges("arabicWord");t.forEach(function(c){ya.call(n,c)})}}function Ca(){var n=this,e="arab";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("rlig")!==-1){B4.call(this);var c=this.tokenizer.getContextRanges("arabicWord");c.forEach(function(a){xa.call(n,a)})}}}function Pa(){var n=this,e="latn";if(this.featuresTags.hasOwnProperty(e)){var t=this.featuresTags[e];if(t.indexOf("liga")!==-1){B4.call(this);var c=this.tokenizer.getContextRanges("latinWord");c.forEach(function(a){ka.call(n,a)})}}}U0.prototype.checkContextReady=function(n){return!!this.tokenizer.getContext(n)};U0.prototype.applyFeaturesToContexts=function(){this.checkContextReady("arabicWord")&&(Sa.call(this),Ca.call(this)),this.checkContextReady("latinWord")&&Pa.call(this),this.checkContextReady("arabicSentence")&&Aa.call(this)};U0.prototype.processText=function(n){(!this.text||this.text!==n)&&(this.setText(n),La.call(this),this.applyFeaturesToContexts())};U0.prototype.getBidiText=function(n){return this.processText(n),this.tokenizer.getText()};U0.prototype.getTextGlyphs=function(n){this.processText(n);for(var e=[],t=0;t<this.tokenizer.tokens.length;t++){var c=this.tokenizer.tokens[t];if(!c.state.deleted){var a=c.activeState.value;e.push(Array.isArray(a)?a[0]:a)}}return e};function P1(n){n=n||{},n.tables=n.tables||{},n.empty||(S3(n.familyName,"When creating a new Font object, familyName is required."),S3(n.styleName,"When creating a new Font object, styleName is required."),S3(n.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),S3(n.ascender,"When creating a new Font object, ascender is required."),S3(n.descender<=0,"When creating a new Font object, negative descender value is required."),this.names={fontFamily:{en:n.familyName||" "},fontSubfamily:{en:n.styleName||" "},fullName:{en:n.fullName||n.familyName+" "+n.styleName},postScriptName:{en:n.postScriptName||(n.familyName+n.styleName).replace(/\s/g,"")},designer:{en:n.designer||" "},designerURL:{en:n.designerURL||" "},manufacturer:{en:n.manufacturer||" "},manufacturerURL:{en:n.manufacturerURL||" "},license:{en:n.license||" "},licenseURL:{en:n.licenseURL||" "},version:{en:n.version||"Version 0.1"},description:{en:n.description||" "},copyright:{en:n.copyright||" "},trademark:{en:n.trademark||" "}},this.unitsPerEm=n.unitsPerEm||1e3,this.ascender=n.ascender,this.descender=n.descender,this.createdTimestamp=n.createdTimestamp,this.tables=Object.assign(n.tables,{os2:Object.assign({usWeightClass:n.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:n.widthClass||this.usWidthClasses.MEDIUM,fsSelection:n.fsSelection||this.fsSelectionValues.REGULAR},n.tables.os2)})),this.supported=!0,this.glyphs=new n2.GlyphSet(this,n.glyphs||[]),this.encoding=new a7(this),this.position=new V3(this),this.substitution=new A0(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 O7(this)}})}P1.prototype.hasChar=function(n){return this.encoding.charToGlyphIndex(n)!==null};P1.prototype.charToGlyphIndex=function(n){return this.encoding.charToGlyphIndex(n)};P1.prototype.charToGlyph=function(n){var e=this.charToGlyphIndex(n),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t};P1.prototype.updateFeatures=function(n){return this.defaultRenderOptions.features.map(function(e){return e.script==="latn"?{script:"latn",tags:e.tags.filter(function(t){return n[t]})}:e})};P1.prototype.stringToGlyphs=function(n,e){var t=this,c=new U0,a=function(f){return t.charToGlyphIndex(f.char)};c.registerModifier("glyphIndex",null,a);var r=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;c.applyFeatures(this,r);for(var s=c.getTextGlyphs(n),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};P1.prototype.nameToGlyphIndex=function(n){return this.glyphNames.nameToGlyphIndex(n)};P1.prototype.nameToGlyph=function(n){var e=this.nameToGlyphIndex(n),t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t};P1.prototype.glyphIndexToName=function(n){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(n):""};P1.prototype.getKerningValue=function(n,e){n=n.index||n,e=e.index||e;var t=this.position.defaultKerningTables;return t?this.position.getKerningValue(t,n,e):this.kerningPairs[n+","+e]||0};P1.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]}]};P1.prototype.forEachGlyph=function(n,e,t,c,a,r){e=e!==void 0?e:0,t=t!==void 0?t:0,c=c!==void 0?c:72,a=Object.assign({},this.defaultRenderOptions,a);var s=1/this.unitsPerEm*c,i=this.stringToGlyphs(n,a),o;if(a.kerning){var l=a.script||this.position.getDefaultScriptName();o=this.position.getKerningTables(l,a.language)}for(var h=0;h<i.length;h+=1){var f=i[h];if(r.call(this,f,e,t,c,a),f.advanceWidth&&(e+=f.advanceWidth*s),a.kerning&&h<i.length-1){var u=o?this.position.getKerningValue(o,f.index,i[h+1].index):this.getKerningValue(f,i[h+1]);e+=u*s}a.letterSpacing?e+=a.letterSpacing*c:a.tracking&&(e+=a.tracking/1e3*c)}return e};P1.prototype.getPath=function(n,e,t,c,a){var r=new Y1;return this.forEachGlyph(n,e,t,c,a,function(s,i,o,l){var h=s.getPath(i,o,l,a,this);r.extend(h)}),r};P1.prototype.getPaths=function(n,e,t,c,a){var r=[];return this.forEachGlyph(n,e,t,c,a,function(s,i,o,l){var h=s.getPath(i,o,l,a,this);r.push(h)}),r};P1.prototype.getAdvanceWidth=function(n,e,t){return this.forEachGlyph(n,0,0,e,t,function(){})};P1.prototype.draw=function(n,e,t,c,a,r){this.getPath(e,t,c,a,r).draw(n)};P1.prototype.drawPoints=function(n,e,t,c,a,r){this.forEachGlyph(e,t,c,a,r,function(s,i,o,l){s.drawPoints(n,i,o,l)})};P1.prototype.drawMetrics=function(n,e,t,c,a,r){this.forEachGlyph(e,t,c,a,r,function(s,i,o,l){s.drawMetrics(n,i,o,l)})};P1.prototype.getEnglishName=function(n){var e=this.names[n];if(e)return e.en};P1.prototype.validate=function(){var n=this;function e(c,a){}function t(c){var a=n.getEnglishName(c);a&&a.trim().length>0}t("fontFamily"),t("weightName"),t("manufacturer"),t("copyright"),t("version"),this.unitsPerEm>0};P1.prototype.toTables=function(){return g9.fontToTable(this)};P1.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};P1.prototype.toArrayBuffer=function(){for(var n=this.toTables(),e=n.encode(),t=new ArrayBuffer(e.length),c=new Uint8Array(t),a=0;a<e.length;a++)c[a]=e[a];return t};P1.prototype.download=function(n){var e=this.getEnglishName("fontFamily"),t=this.getEnglishName("fontSubfamily");n=n||e.replace(/\s/g,"")+"-"+t+".otf";var c=this.toArrayBuffer();if(b9())if(window.URL=window.URL||window.webkitURL,window.URL){var a=new DataView(c),r=new Blob([a],{type:"font/opentype"}),s=document.createElement("a");s.href=window.URL.createObjectURL(r),s.download=n;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=l6(),l=y9(c);o.writeFileSync(n,l)}};P1.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};P1.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};P1.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};function q7(n,e){var t=JSON.stringify(n),c=256;for(var a in e){var r=parseInt(a);if(!(!r||r<256)){if(JSON.stringify(e[a])===t)return r;c<=r&&(c=r+1)}}return e[c]=n,c}function Ea(n,e,t){var c=q7(e.name,t);return[{name:"tag_"+n,type:"TAG",value:e.tag},{name:"minValue_"+n,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+n,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+n,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+n,type:"USHORT",value:0},{name:"nameID_"+n,type:"USHORT",value:c}]}function Ta(n,e,t){var c={},a=new Y.Parser(n,e);return c.tag=a.parseTag(),c.minValue=a.parseFixed(),c.defaultValue=a.parseFixed(),c.maxValue=a.parseFixed(),a.skip("uShort",1),c.name=t[a.parseUShort()]||{},c}function Ia(n,e,t,c){for(var a=q7(e.name,c),r=[{name:"nameID_"+n,type:"USHORT",value:a},{name:"flags_"+n,type:"USHORT",value:0}],s=0;s<t.length;++s){var i=t[s].tag;r.push({name:"axis_"+n+" "+i,type:"FIXED",value:e.coordinates[i]<<16})}return r}function Ha(n,e,t,c){var a={},r=new Y.Parser(n,e);a.name=c[r.parseUShort()]||{},r.skip("uShort",1),a.coordinates={};for(var s=0;s<t.length;++s)a.coordinates[t[s].tag]=r.parseFixed();return a}function Va(n,e){var t=new j.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:n.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:n.instances.length},{name:"instanceSize",type:"USHORT",value:4+n.axes.length*4}]);t.offsetToData=t.sizeOf();for(var c=0;c<n.axes.length;c++)t.fields=t.fields.concat(Ea(c,n.axes[c],e));for(var a=0;a<n.instances.length;a++)t.fields=t.fields.concat(Ia(a,n.instances[a],n.axes,e));return t}function Oa(n,e,t){var c=new Y.Parser(n,e),a=c.parseULong();r1.argument(a===65536,"Unsupported fvar table version.");var r=c.parseOffset16();c.skip("uShort",1);for(var s=c.parseUShort(),i=c.parseUShort(),o=c.parseUShort(),l=c.parseUShort(),h=[],f=0;f<s;f++)h.push(Ta(n,e+r+f*i,t));for(var u=[],d=e+r+s*i,m=0;m<o;m++)u.push(Ha(n,d+m*l,h,t));return{axes:h,instances:u}}var Fa={make:Va,parse:Oa},_a=function(){return{coverage:this.parsePointer(V.coverage),attachPoints:this.parseList(V.pointer(V.uShortList))}},Da=function(){var n=this.parseUShort();if(r1.argument(n===1||n===2||n===3,"Unsupported CaretValue table version."),n===1)return{coordinate:this.parseShort()};if(n===2)return{pointindex:this.parseShort()};if(n===3)return{coordinate:this.parseShort()}},Ra=function(){return this.parseList(V.pointer(Da))},qa=function(){return{coverage:this.parsePointer(V.coverage),ligGlyphs:this.parseList(V.pointer(Ra))}},$a=function(){return this.parseUShort(),this.parseList(V.pointer(V.coverage))};function Ua(n,e){e=e||0;var t=new V(n,e),c=t.parseVersion(1);r1.argument(c===1||c===1.2||c===1.3,"Unsupported GDEF table version.");var a={version:c,classDef:t.parsePointer(V.classDef),attachList:t.parsePointer(_a),ligCaretList:t.parsePointer(qa),markAttachClassDef:t.parsePointer(V.classDef)};return c>=1.2&&(a.markGlyphSets=t.parsePointer($a)),a}var Na={parse:Ua},q0=new Array(10);q0[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{posFormat:1,coverage:this.parsePointer(V.coverage),value:this.parseValueRecord()};if(t===2)return{posFormat:2,coverage:this.parsePointer(V.coverage),values:this.parseValueRecordList()};r1.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};q0[2]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();r1.assert(t===1||t===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var c=this.parsePointer(V.coverage),a=this.parseUShort(),r=this.parseUShort();if(t===1)return{posFormat:t,coverage:c,valueFormat1:a,valueFormat2:r,pairSets:this.parseList(V.pointer(V.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(a),value2:this.parseValueRecord(r)}})))};if(t===2){var s=this.parsePointer(V.classDef),i=this.parsePointer(V.classDef),o=this.parseUShort(),l=this.parseUShort();return{posFormat:t,coverage:c,valueFormat1:a,valueFormat2:r,classDef1:s,classDef2:i,class1Count:o,class2Count:l,classRecords:this.parseList(o,V.list(l,function(){return{value1:this.parseValueRecord(a),value2:this.parseValueRecord(r)}}))}}};q0[3]=function(){return{error:"GPOS Lookup 3 not supported"}};q0[4]=function(){return{error:"GPOS Lookup 4 not supported"}};q0[5]=function(){return{error:"GPOS Lookup 5 not supported"}};q0[6]=function(){return{error:"GPOS Lookup 6 not supported"}};q0[7]=function(){return{error:"GPOS Lookup 7 not supported"}};q0[8]=function(){return{error:"GPOS Lookup 8 not supported"}};q0[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function Ba(n,e){e=e||0;var t=new V(n,e),c=t.parseVersion(1);return r1.argument(c===1||c===1.1,"Unsupported GPOS table version "+c),c===1?{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(q0)}:{version:c,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(q0),variations:t.parseFeatureVariationsList()}}var Ga=new Array(10);function ja(n){return new j.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new j.ScriptList(n.scripts)},{name:"features",type:"TABLE",value:new j.FeatureList(n.features)},{name:"lookups",type:"TABLE",value:new j.LookupList(n.lookups,Ga)}])}var Wa={parse:Ba,make:ja};function Xa(n){var e={};n.skip("uShort");var t=n.parseUShort();r1.argument(t===0,"Unsupported kern sub-table version."),n.skip("uShort",2);var c=n.parseUShort();n.skip("uShort",3);for(var a=0;a<c;a+=1){var r=n.parseUShort(),s=n.parseUShort(),i=n.parseShort();e[r+","+s]=i}return e}function Za(n){var e={};n.skip("uShort");var t=n.parseULong();t>1&&console.warn("Only the first kern subtable is supported."),n.skip("uLong");var c=n.parseUShort(),a=c&255;if(n.skip("uShort"),a===0){var r=n.parseUShort();n.skip("uShort",3);for(var s=0;s<r;s+=1){var i=n.parseUShort(),o=n.parseUShort(),l=n.parseShort();e[i+","+o]=l}}return e}function Ya(n,e){var t=new Y.Parser(n,e),c=t.parseUShort();if(c===0)return Xa(t);if(c===1)return Za(t);throw new Error("Unsupported kern table version ("+c+").")}var Ka={parse:Ya};function Ja(n,e,t,c){for(var a=new Y.Parser(n,e),r=c?a.parseUShort:a.parseULong,s=[],i=0;i<t+1;i+=1){var o=r.call(a);c&&(o*=2),s.push(o)}return s}var Qa={parse:Ja};function X6(n,e){for(var t=[],c=12,a=0;a<e;a+=1){var r=Y.getTag(n,c),s=Y.getULong(n,c+4),i=Y.getULong(n,c+8),o=Y.getULong(n,c+12);t.push({tag:r,checksum:s,offset:i,length:o,compression:!1}),c+=16}return t}function er(n,e){for(var t=[],c=44,a=0;a<e;a+=1){var r=Y.getTag(n,c),s=Y.getULong(n,c+4),i=Y.getULong(n,c+8),o=Y.getULong(n,c+12),l=void 0;i<o?l="WOFF":l=!1,t.push({tag:r,offset:s,compression:l,compressedLength:i,length:o}),c+=20}return t}function B1(n,e){if(e.compression==="WOFF"){var t=new Uint8Array(n.buffer,e.offset+2,e.compressedLength-2),c=new Uint8Array(e.length);if(j8(t,c),c.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");var a=new DataView(c.buffer,0);return{data:a,offset:0}}else return{data:n,offset:e.offset}}function $7(n,e){e=e??{};var t,c,a=new P1({empty:!0}),r=new DataView(n,0),s,i=[],o=Y.getTag(r,0);if(o==="\0\0\0"||o==="true"||o==="typ1")a.outlinesFormat="truetype",s=Y.getUShort(r,4),i=X6(r,s);else if(o==="OTTO")a.outlinesFormat="cff",s=Y.getUShort(r,4),i=X6(r,s);else if(o==="wOFF"){var l=Y.getTag(r,4);if(l==="\0\0\0")a.outlinesFormat="truetype";else if(l==="OTTO")a.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+o);s=Y.getUShort(r,12),i=er(r,s)}else throw new Error("Unsupported OpenType signature "+o);for(var h,f,u,d,m,p,g,v,b,y,x,M,w=0;w<s;w+=1){var k=i[w],S=void 0;switch(k.tag){case"cmap":S=B1(r,k),a.tables.cmap=c7.parse(S.data,S.offset),a.encoding=new r7(a.tables.cmap);break;case"cvt ":S=B1(r,k),M=new Y.Parser(S.data,S.offset),a.tables.cvt=M.parseShortList(k.length/2);break;case"fvar":f=k;break;case"fpgm":S=B1(r,k),M=new Y.Parser(S.data,S.offset),a.tables.fpgm=M.parseByteList(k.length);break;case"head":S=B1(r,k),a.tables.head=m7.parse(S.data,S.offset),a.unitsPerEm=a.tables.head.unitsPerEm,t=a.tables.head.indexToLocFormat;break;case"hhea":S=B1(r,k),a.tables.hhea=g7.parse(S.data,S.offset),a.ascender=a.tables.hhea.ascender,a.descender=a.tables.hhea.descender,a.numberOfHMetrics=a.tables.hhea.numberOfHMetrics;break;case"hmtx":g=k;break;case"ltag":S=B1(r,k),c=b7.parse(S.data,S.offset);break;case"maxp":S=B1(r,k),a.tables.maxp=y7.parse(S.data,S.offset),a.numGlyphs=a.tables.maxp.numGlyphs;break;case"name":y=k;break;case"OS/2":S=B1(r,k),a.tables.os2=I4.parse(S.data,S.offset);break;case"post":S=B1(r,k),a.tables.post=L7.parse(S.data,S.offset),a.glyphNames=new D4(a.tables.post);break;case"prep":S=B1(r,k),M=new Y.Parser(S.data,S.offset),a.tables.prep=M.parseByteList(k.length);break;case"glyf":u=k;break;case"loca":b=k;break;case"CFF ":h=k;break;case"kern":v=k;break;case"GDEF":d=k;break;case"GPOS":m=k;break;case"GSUB":p=k;break;case"meta":x=k;break}}var A=B1(r,y);if(a.tables.name=k7.parse(A.data,A.offset,c),a.names=a.tables.name,u&&b){var z=t===0,L=B1(r,b),P=Qa.parse(L.data,L.offset,a.numGlyphs,z),I=B1(r,u);a.glyphs=I7.parse(I.data,I.offset,P,a,e)}else if(h){var T=B1(r,h);p7.parse(T.data,T.offset,a,e)}else throw new Error("Font doesn't contain TrueType or CFF outlines.");var O=B1(r,g);if(v7.parse(a,O.data,O.offset,a.numberOfHMetrics,a.numGlyphs,a.glyphs,e),pn(a,e),v){var F=B1(r,v);a.kerningPairs=Ka.parse(F.data,F.offset)}else a.kerningPairs={};if(d){var D=B1(r,d);a.tables.gdef=Na.parse(D.data,D.offset)}if(m){var _=B1(r,m);a.tables.gpos=Wa.parse(_.data,_.offset),a.position.init()}if(p){var R=B1(r,p);a.tables.gsub=A7.parse(R.data,R.offset)}if(f){var U=B1(r,f);a.tables.fvar=Fa.parse(U.data,U.offset,a.names)}if(x){var N=B1(r,x);a.tables.meta=S7.parse(N.data,N.offset),a.metas=a.tables.meta}return a}function P5(n,e){let t=n.tables?.os2?.sCapHeight;if(t&&t>0)return t/n.unitsPerEm*e;let c=Z1(J2(n,"H",{size:e,font:"",halign:"left",valign:"baseline",spacing:1}).polys);return c?c[3]:n.ascender/n.unitsPerEm*e}var C5=class{constructor(e,t){this.sources=e;this.fallback=t;this.parsed=new Map;this.missing=new Set}names(){return Object.keys(this.sources)}get(e){let t=e||this.fallback||Object.keys(this.sources)[0];if(!t)throw this.missing.add(""),new Error("text() needs a font. Pass fonts to render(), or --font on the command line.");let c=this.parsed.get(t);if(c)return c;let a=y0(this.sources,t);if(!a)throw this.missing.add(t),new Error(`Font "${t}" is not available.${this.names().length?` Available fonts: ${this.names().join(", ")}`:""}`);let r=a instanceof Uint8Array?a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength):a,s=$7(r);return this.parsed.set(t,s),s}};function tr(n,e,t){let c={kerning:!0};if(t.spacing===1)return{cmds:n.getPath(e,0,0,t.size,c).commands,advance:n.getAdvanceWidth(e,t.size,c)};let a=[],r=0,s=[...e];return s.forEach((i,o)=>{a.push(...n.getPath(i,r,0,t.size,c).commands),r+=n.getAdvanceWidth(i,t.size,c)*(o<s.length-1?t.spacing:1)}),{cmds:a,advance:r}}function J2(n,e,t){let{cmds:c,advance:a}=tr(n,e,t),r=c.map(i=>i.type==="Z"?i:i.type==="C"?{...i,y1:-i.y1,y2:-i.y2,y:-i.y}:i.type==="Q"?{...i,y1:-i.y1,y:-i.y}:{...i,y:-i.y}),s=F2(r,Math.max(.005,t.size/2e3));return{polys:[...s.closed,...s.open.filter(i=>i.length>=3)],advance:a}}function Q2(n,e,t){if(!e)return[];let c=n.get(t.font),{polys:a,advance:r}=J2(c,e,t),s=G(a),i=Z1(s);if(!i)return[];let o=t.halign==="center"?-r/2:t.halign==="right"?-r:0,l=t.valign==="top"?-i[3]:t.valign==="center"?-(i[1]+i[3])/2:t.valign==="bottom"?-i[1]:t.valign==="cap"?-P5(c,t.size)/2:0;return s.map(h=>h.map(([f,u])=>[f+o,u+l]))}function D3(n,e,t){let c=n.get(t.font),{polys:a,advance:r}=J2(c,e,t),s=Z1(a)??[0,0,0,0];return{advance:r,bounds:[[s[0],s[1]],[s[2],s[3]]],ascent:c.ascender/c.unitsPerEm*t.size,descent:c.descender/c.unitsPerEm*t.size,cap:P5(c,t.size)}}function nr(n,e,t){let c=0;for(;c<n.length-2&&e[c+1]<t;)c++;let[a,r]=[n[c],n[c+1]],s=e[c+1]-e[c],i=(t-e[c])/s,o=[(r[0]-a[0])/s,(r[1]-a[1])/s];return{at:[a[0]+(r[0]-a[0])*i,a[1]+(r[1]-a[1])*i],t:o}}function U7(n,e,t,c){let a=c.filter(([v,b],y)=>y===0||v!==c[y-1][0]||b!==c[y-1][1]);if(!e||a.length<2)return{polys:[],over:0};let r=n.get(t.font),s={kerning:!0},i=[...e],o=[],l=0;i.forEach((v,b)=>{o.push(t.spacing===1?r.getAdvanceWidth(i.slice(0,b+1).join(""),t.size,s)-r.getAdvanceWidth(v,t.size,s):l),l+=r.getAdvanceWidth(v,t.size,s)*(b<i.length-1?t.spacing:1)});let h=t.spacing===1?r.getAdvanceWidth(e,t.size,s):l,f=Z1(J2(r,e,t).polys);if(!f)return{polys:[],over:0};let u=t.valign==="top"?-f[3]:t.valign==="center"?-(f[1]+f[3])/2:t.valign==="bottom"?-f[1]:t.valign==="cap"?-P5(r,t.size)/2:0,d=[0];for(let v=1;v<a.length;v++)d.push(d[v-1]+Math.hypot(a[v][0]-a[v-1][0],a[v][1]-a[v-1][1]));let m=d[d.length-1],p=t.halign==="center"?(m-h)/2:t.halign==="right"?m-h:0,g=[];return i.forEach((v,b)=>{let y=r.getAdvanceWidth(v,t.size,s),{at:x,t:M}=nr(a,d,p+o[b]+y/2),w=[-M[1],M[0]];for(let k of J2(r,v,t).polys)g.push(k.map(([S,A])=>{let z=S-y/2,L=A+u;return[x[0]+z*M[0]+L*w[0],x[1]+z*M[1]+L*w[1]]}))}),{polys:G(g),over:Math.max(0,-p,p+h-m)}}function N7(n){let e=Math.abs(n),t=Math.min(720,Math.max(72,Math.ceil(2*Math.PI*e/.5)));return Array.from({length:t+1},(c,a)=>{let r=n>0?1.5*Math.PI-2*Math.PI*a/t:.5*Math.PI+2*Math.PI*a/t;return[e*Math.cos(r),e*Math.sin(r)]})}function B7(n,e,t,c=0,a){if(!e)return{polys:[],loose:[]};let r=n.get(t.font),s={kerning:!0},i=[...e],o=a??Math.max(t.size*.1,1.5),l=t.size*.6,h=[],f=[],u=0,d=0,m=(A,z)=>A.map(L=>L.map(([P,I])=>[P+z,I])),p=(A,z)=>b1(A,z).length>0;i.forEach((A,z)=>{let L=t.spacing===1?r.getAdvanceWidth(i.slice(0,z+1).join(""),t.size,s)-r.getAdvanceWidth(A,t.size,s):d;if(d+=r.getAdvanceWidth(A,t.size,s)*(z<i.length-1?t.spacing:1),/\s/.test(A)){f=[];return}let P=G(J2(r,A,t).polys);if(!P.length)return;let I=m(P,L+u);if(f.length&&!p(f,I)){let[T,O]=[0,l];if(p(f,m(I,-O))){for(let D=0;D<24;D++){let _=(T+O)/2;p(f,m(I,-_))?O=_:T=_}let F=Math.min(l,O+o);u-=F,I=m(I,-F)}}f=G([...f,...I]),h.push({ch:A,polys:I})});let g=L1(L1(G(h.flatMap(A=>A.polys)),.8,"round"),-.8,"round"),v=Z1(g);if(!v)return{polys:[],loose:[]};c>0&&(g=G([...g,[[v[0],-c*.6],[v[2],-c*.6],[v[2],c*.4],[v[0],c*.4]]]));let b=i0(g),y=A=>A.reduce((z,L)=>z+Math.abs(s1(L)),0),x=b.reduce((A,z)=>y(z)>y(A)?z:A,b[0]),M=b.filter(A=>A!==x).map(A=>{let z=h.find(L=>b1(L.polys,A).length);return z?z.ch:"?"}),w=Z1(g),k=t.halign==="center"?-(w[0]+w[2])/2:t.halign==="right"?-w[2]:-w[0],S=t.valign==="top"?-w[3]:t.valign==="center"?-(w[1]+w[3])/2:t.valign==="bottom"?-w[1]:t.valign==="cap"?-P5(r,t.size)/2:0;return{polys:g.map(A=>A.map(([z,L])=>[z+k,L+S])),loose:M}}var G7=Math.PI/180,G4=128;function cr(n,e,t){let[c,a]=[0,1],r=e[0]-n[0],s=e[1]-n[1];for(let[i,o]of[[-r,n[0]-t[0]],[r,t[2]-n[0]],[-s,n[1]-t[1]],[s,t[3]-n[1]]])if(i===0){if(o<=0)return!1}else{let l=o/i;i<0?c=Math.max(c,l):a=Math.min(a,l)}return c<a}var Y4=[{name:"engrave",mode:"fill",color:"#000000"},{name:"score",mode:"line",color:"#0000ff"},{name:"cut",mode:"cut",color:"#ff0000"},{name:"guide",mode:"guide",color:"#00a0ff"}],ar={maxParts:1e4,maxSegments:1e4,maxListLength:1e6,maxListItems:3e6,maxTextLength:2e3,maxPoints:2e6,maxOutputPoints:1e6,maxSheets:200,maxCollisionPairs:2e4};function K4(n,e){if(!n||y0(Z4,n)!==void 0)return;let t=n.split("\\").join("/"),c=e.split("\\").join("/");if(c.startsWith("/")||/^[A-Za-z]:\//.test(c))return;let a=t.lastIndexOf("/");if(a<0)return;let r=[...t.slice(0,a).split("/"),...c.split("/")],s=[];for(let i of r)i===".."&&s.length&&s[s.length-1]!==".."?s.pop():i!=="."&&i!==""&&s.push(i);return(t.startsWith("/")?"/":"")+s.join("/")}var X7=new WeakSet,rr=()=>{let n=e0();return X7.add(n),n},j7=n=>!X7.has(n),sr=100,ir={mm:1,cm:10,m:1e3,in:25.4,ft:304.8},e3=4,W7=8,or=n=>{let e=sr,t=c=>{for(let a of c.values()){for(let r of a.regions)e+=r.length;for(let r of a.lines)e+=r.length}};t(n.layers);for(let c of n.parts)t(c.layers);return e},K1=class{constructor(e,t){this.parent=e;this.caller=t;this.vars=new Map;this.fns=new Map;this.mods=new Map}get(e){let t=this,c=e.startsWith("$");for(;t;){if(t.vars.has(e))return{found:!0,value:t.vars.get(e)};t=c?t.caller??t.parent:t.parent}return{found:!1}}fn(e){for(let t=this;t;t=t.parent){let c=t.fns.get(e);if(c)return c}}mod(e){for(let t=this;t;t=t.parent){let c=t.mods.get(e);if(c)return c}}childCtx(){for(let e=this;e;e=e.parent)if(e.children)return e.children}names(e){let t=[];for(let c=this;c;c=c.parent)t.push(...c[e].keys());return t}},j4=n=>n?`.${n}`:"",W4=(n,e)=>n==="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`,lr={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."},X4=["echo","assert","text_width","text_metrics","text_size","finger_count"];function T2(n,e){let t="",c=Math.min(2,Math.floor(n.length/3))+.5;for(let a of new Set(e)){if(a===n)continue;let r=a.toLowerCase()===n.toLowerCase()?0:hr(n,a);r<c&&([t,c]=[a,r])}return t?` Did you mean "${t}"?`:""}function hr(n,e){if(Math.abs(n.length-e.length)>2)return 3;let t=Array.from({length:n.length+1},(c,a)=>[a,...Array(e.length).fill(0)]);for(let c=1;c<=e.length;c++)t[0][c]=c;for(let c=1;c<=n.length;c++)for(let a=1;a<=e.length;a++)t[c][a]=Math.min(t[c-1][a]+1,t[c][a-1]+1,t[c-1][a-1]+(n[c-1]===e[a-1]?0:1)),c>1&&a>1&&n[c-1]===e[a-2]&&n[c-2]===e[a-1]&&(t[c][a]=Math.min(t[c][a],t[c-2][a-2]+1));return t[n.length][e.length]}var Z4=J0,t3=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=i4;this.step=0;this.stepNames=[];this.stepFolded=!1;this.hardware=[];this.lights=[];this.echoes=[];this.warnings=[];this.layers=new Map(Y4.map(e=>[e.name,e]));this.loaded=new Map;this.clashed=new Set;this.childCache=new WeakMap;this.copyReads=0;this.using=[];this.including=[];this.maxSteps=e.maxSteps??5e6,this.limits={...ar,...e.limits},this.builtins=this.makeBuiltins()}run(e){let t=new K1,c={$fn:0,$fa:2,$fs:.2,$thickness:3,$kerf:0,$material:"material",$sheet:[600,400],$gap:3,$layout:"pack",$scale:1,PI:Math.PI};for(let[i,o]of Object.entries(c))t.vars.set(i,o);let a=new K1(t),r=this.block(e.body,a,!0),s=a.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 (${g0(this.unscaled,!1)})`),{shape:r,globals:a,layers:this.layers,echoes:this.echoes,warnings:this.warnings,hardware:this.hardware,lights:this.lights,steps:this.stepNames}}tick(e,t=1){if(!((this.steps+=t)<=this.maxSteps))throw new X(`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,t){let c=K4(t.file,e),a=e,r=y0(Z4,e);if(r===void 0&&c!==void 0){let i=this.loaded.get(c);if(i)return i;r=this.opts.resolve?.(c),typeof r=="string"&&(a=c)}if(a===e){let i=this.loaded.get(e);if(i)return i;r??(r=this.opts.resolve?.(e))}if(typeof r!="string")throw new X(`Library <${e}> not found`,t);this.loaded.set(a,{body:[]});let{program:s}=K0(r,a);return this.loaded.set(a,s),s}hoist(e,t){for(let c of e)if((c.kind==="module"||c.kind==="function")&&(c.pos.file===void 0||y0(Z4,c.pos.file)===void 0)&&(c.kind==="module"?y0(this.builtins,c.name)!==void 0:y0(i3,c.name)!==void 0||X4.includes(c.name))&&this.warn(`${c.kind} ${c.name} hides the built-in ${c.name}(); rename it to use both (${g0(c.pos,!1)})`),c.kind==="module")t.mods.set(c.name,{params:c.params,body:c.body,env:t,pos:c.pos});else if(c.kind==="function")t.fns.set(c.name,{params:c.params,body:c.body,env:t,pos:c.pos});else if(c.kind==="use"&&!c.include){this.enter(this.using,c.path,c.pos,"use");try{let a=this.included(this.load(c.path,c.pos).body,new Set([c.path])),r=new K1(t);this.hoist(a,r);for(let s of a)s.kind==="assign"&&this.assign(s.name,this.expr(s.value,r),r);for(let[s,i]of r.mods)this.clash("module",s,t.mods.get(s),i),t.mods.set(s,i);for(let[s,i]of r.fns)this.clash("function",s,t.fns.get(s),i),t.fns.set(s,i)}finally{this.using.pop()}}}clash(e,t,c,a){!c||c.body===a.body||!c.pos?.file||!a.pos?.file||c.pos.file===a.pos.file||this.clashed.has(`${e} ${t}`)||(this.clashed.add(`${e} ${t}`),this.warn(`${e} ${t} is defined in <${c.pos.file}> (line ${c.pos.line}) and in <${a.pos.file}> (line ${a.pos.line}); the one in <${a.pos.file}> is used. Rename one to use both.`))}childKey(e){let t=new Map;((l,h)=>{for(;l&&h<200;l=l.caller??l.parent,h++)for(let[f,u]of l.vars)f.startsWith("$")&&!t.has(f)&&t.set(f,u)})(e,0);let a=[...t].sort(([l],[h])=>l<h?-1:1),r=[],s=0,i=[];for(let l=a.length-1;l>=0;l--)i.push({text:";"},a[l][1],{text:`${a[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 f=l.length-1;f>=0;f--)i.push(l[f],{text:","});h="["}else if(P0(l))h=`[${l.start}:${l.step}:${l.end}]`;else if(d0(l)){i.push({text:"}"});let f=[...l.fields];for(let u=f.length-1;u>=0;u--)i.push(f[u][1],{text:`${f[u][0]}=`});h="{"}else return"";r.push(h),s+=h.length}let o=r.join("");return`${this.frame.join(",")}|${this.step}|${this.stepFolded}|${this.layerDefs}|${o}`}effects(){return`${this.echoes.length},${this.hardware.length},${this.lights.length},${this.stepNames.length},${this.warnings.length},${this.copies},${this.layerDefs}`}enter(e,t,c,a){if(e.includes(t)){let r=[...e.slice(e.indexOf(t)),t].map(s=>`<${s}>`);throw new X(r.length===2?`Library ${r[0]} ${a}s itself`:`Libraries ${a} each other in a loop: ${r.join(" \u2192 ")}`,c)}e.push(t)}included(e,t){let c=[];for(let a of e)if(a.kind!=="use"||!a.include)c.push(a);else if(!t.has(a.path)){t.add(a.path);for(let r of this.included(this.load(a.path,a.pos).body,t))c.push(r)}return c}assign(e,t,c){c.vars.set(e,t)}block(e,t,c=!1){this.hoist(e,t);let a=[];for(let r of e){let s=this.stmt(r,t,c);s&&!Te(s)&&a.push(s)}return a.length===1?a[0]:Y0(a)}stmt(e,t,c=!1){switch(this.tick(e.pos),e.kind){case"assign":{let a=this.opts.overrides,r=c&&a&&Object.prototype.hasOwnProperty.call(a,e.name)?a[e.name]:this.expr(e.value,t);return this.assign(e.name,r,t),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,t)}finally{this.including.pop()}}case"block":return this.block(e.body,new K1(t));case"if":return O1(this.expr(e.cond,t))?this.block(e.then,new K1(t)):e.else.length?this.block(e.else,new K1(t)):null;case"let":{let a=new K1(t);return this.bindSeq(e.assigns,a),this.block(e.body,a)}case"for":{let a=[];return this.loop(e.assigns,t,r=>a.push(this.block(e.body,r))),e.intersect?this.builtins.intersection({args:{pos:[],named:new Map,all:[],at:e.pos},env:t,children:()=>Y0(a),childList:()=>a,childSeq:()=>a,childItems:()=>a}):Y0(a)}case"call":if(e.modifier==="*")return null;{let a=this.callModule(e,t);return(e.name==="echo"||e.name==="assert")&&!e.children.length&&!t.mod(e.name)?null:e.modifier==="#"||e.modifier==="%"?y3(a,"guide"):a}}}bindSeq(e,t){for(let c of e)this.assign(c.name,this.expr(c.value,t),t)}iterable(e,t){if(P0(e))try{return U3(e,this.limits.maxListLength)}catch(c){throw new X(c.message,t)}return Array.isArray(e)?e:typeof e=="string"?[...e]:e===void 0?[]:[e]}loop(e,t,c,a=0,r=new K1(t)){if(a===e.length)return c(r);let s=e[a];for(let i of this.iterable(this.expr(s.value,r),s.pos)){this.tick(s.pos);let o=new K1(r);o.vars.set(s.name,i),this.loop(e,t,c,a+1,o)}}evalArgs(e,t,c){let a=[],r=new Map,s=[];for(let i of e){let o=this.expr(i.value,t);i.name===null?a.push(o):r.set(i.name,o),s.push({name:i.name,value:o})}return{pos:a,named:r,all:s,at:c}}bindParams(e,t,c,a,r){let s=e.map(i=>i.name);for(let[i,o]of t.named)i.startsWith("$")&&c.vars.set(i,o);e.forEach((i,o)=>{let l;t.named.has(i.name)?l=t.named.get(i.name):o<t.pos.length?l=t.pos[o]:l=i.default?this.expr(i.default,c):void 0,c.vars.set(i.name,l)});for(let i of t.named.keys())!i.startsWith("$")&&!s.includes(i)&&this.unknownArg(r,i,t.at,s);this.checkCount(r,e.length,t)}checkArgs(e,t){let c=j2(e);if(!c)return;let a=c.params.map(r=>r.name);if(!c.anyNamed)for(let r of t.named.keys())!r.startsWith("$")&&!a.includes(r)&&this.unknownArg(`${e}()`,r,t.at,a);c.rest||this.checkCount(`${e}()`,c.params.filter(r=>!r.named).length,t)}checkCount(e,t,c){c.pos.length>t&&this.warn(`${e}: takes ${t===0?"no":`at most ${t}`} positional argument${t===1?"":"s"}, got ${c.pos.length}; the rest are ignored (${g0(c.at,!1)})`)}unknownArg(e,t,c,a){this.warn(`${e}: unknown argument "${t}"${j4(T2(t,a))} (${g0(c,!1)})`)}warn(e){this.warnings.includes(e)||this.warnings.push(e)}callByName(e,t){let c=e.args.findIndex(s=>s.name==="name"),a=c>=0?c:e.args.findIndex(s=>s.name===null);if(a<0)throw new X("call() needs the name of a module",e.pos);let r=this.expr(e.args[a].value,t);if(typeof r!="string")throw new X(`call() needs a module's name as a string, got ${c0(r)}`,e.pos);if(r==="call")throw new X("call() can't call itself",e.pos);return this.callModule({...e,name:r,args:e.args.filter((s,i)=>i!==a)},t)}callModule(e,t){if(e.name==="call"&&!t.mod("call"))return this.callByName(e,t);let c=this.evalArgs(e.args,t,e.pos),a=t.mod(e.name);if(a){if(++this.depth>1e3)throw new X(W4("module",e.name),e.pos);try{let d=new K1(a.env,t);return this.bindParams(a.params,c,d,a.env,`${e.name}()`),d.children={stmts:e.children,env:t,module:e.name,pos:e.pos},d.vars.set("$children",this.childStmts(e.children).length),this.block(a.body,d)}catch(d){throw this.inCall(d,"module",e.name,e.pos)}finally{this.depth--}}let r=y0(this.builtins,e.name),s=y0(lr,e.name);if(!r&&s)return this.warn(`${e.name}() is ignored: ${s} (${g0(e.pos,!1)})`),e.children.length?this.block(e.children,new K1(t,t)):e0();if(!r){let d=T2(e.name,[...t.names("mods"),...Object.keys(this.builtins)]);throw new X(`Unknown module ${e.name}().${d}`,e.pos)}this.checkArgs(e.name,c);let i=new K1(t,t);for(let[d,m]of c.named)d.startsWith("$")&&i.vars.set(d,m);let o=this.childStmts(e.children),l=()=>new K1(t,i),h={args:c,env:i,children:()=>e.children.length?this.block(e.children,l()):e0(),childList:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let p of e.children){let g=this.stmt(p,d);o.includes(p)&&m.push(g??rr())}return m},childItems:()=>{let d=l();this.hoist(e.children,d);let m=[];for(let p of e.children){if(o.includes(p)&&p.kind==="for"&&!p.intersect){this.tick(p.pos),this.loop(p.assigns,d,v=>m.push(this.block(p.body,v)));continue}let g=this.stmt(p,d);o.includes(p)&&m.push(g??e0())}return m},childSeq:d=>{let m=l();this.hoist(e.children,m);let p=[];for(let g of e.children){let v=this.stmt(g,m);o.includes(g)&&(p.push(v??e0()),d(p.length-1,v??e0()))}return p}},f;try{f=r(h)}catch(d){if(d instanceof X||d instanceof RangeError)throw d;let m=new X(`${e.name}(): ${d.message}`,e.pos);throw m.call=e.name,m}let u=or(f);if(e.name!=="children"&&(this.pointCount+=u),u>this.limits.maxPoints||this.pointCount>this.limits.maxPoints*10)throw new X(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 f}childStmts(e){return e.filter(t=>t.kind!=="assign"&&t.kind!=="module"&&t.kind!=="function"&&t.kind!=="use")}callFunction(e,t,c,a){if(++this.depth>2e3)throw new X(W4("function",a),t.at);try{this.tick(t.at);let r=F0(e)?e.scope:e.env,s=new K1(r,c);return this.bindParams(e.params,t,s,r,`${a}()`),this.expr(e.body,s)}catch(r){throw this.inCall(r,"function",a,t.at)}finally{this.depth--}}inCall(e,t,c,a){return e instanceof Error&&!(e instanceof X)&&e.message.includes("call stack")?new X(W4(t,c),a):(e instanceof X&&e.addFrame(t,c,a),e)}expr(e,t){switch(e.kind){case"num":return e.unit?this.length(e,t):e.value;case"str":case"bool":return e.value;case"undef":return;case"var":{e.name==="$copy"&&this.copyReads++;let c=t.get(e.name);if(c.found)return c.value;let a=t.fn(e.name);if(a)return{type:"function",params:a.params,body:a.body,scope:a.env,name:e.name};if(e.name.startsWith("$"))return;throw new X(`Unknown variable "${e.name}"${j4(T2(e.name,[...t.names("vars"),...t.names("fns")]))}`,e.pos)}case"list":{let c=[];for(let a of e.items)this.listItem(a,t,c,e.pos);return this.charge(e3,e.pos),c}case"range":{let c=this.expr(e.start,t),a=this.expr(e.end,t),r=e.step?this.expr(e.step,t):1;if(typeof c!="number"||typeof a!="number"||typeof r!="number")throw new X("Range values must be numbers",e.pos);return{type:"range",start:c,step:r,end:a}}case"unary":{let c=this.expr(e.arg,t);return e.op==="!"?!O1(c):e.op==="+"?c:this.arith("*",-1,c,e.pos)}case"binary":{if(e.op==="&&")return O1(this.expr(e.left,t))&&O1(this.expr(e.right,t));if(e.op==="||")return O1(this.expr(e.left,t))||O1(this.expr(e.right,t));let c=this.expr(e.left,t),a=this.expr(e.right,t);if(e.op==="=="||e.op==="!=")return V2(c,a,()=>this.tick(e.pos))===(e.op==="==");if(e.op==="<"||e.op==="<="||e.op===">"||e.op===">="){if(!(typeof c=="number"&&typeof a=="number"||typeof c=="string"&&typeof a=="string"))throw new X(`Can't compare ${c0(c)} ${e.op} ${c0(a)}`,e.pos);return e.op==="<"?c<a:e.op==="<="?c<=a:e.op===">"?c>a:c>=a}return this.arith(e.op,c,a,e.pos)}case"ternary":return O1(this.expr(e.cond,t))?this.expr(e.then,t):this.expr(e.else,t);case"index":{let c=this.expr(e.target,t),a=this.expr(e.index,t);if(d0(c)&&typeof a=="string")return c.fields.get(a);if(typeof a!="number")throw new X(`List index must be a number, got ${c0(a)}`,e.pos);return Array.isArray(c)?c[Math.floor(a)]:typeof c=="string"?[...c][Math.floor(a)]:P0(c)?[c.start,c.step,c.end][Math.floor(a)]:void 0}case"record":return this.record(e,t);case"member":{let c=this.expr(e.target,t);if(d0(c))return c.fields.get(e.name);let a={x:0,y:1,z:2}[e.name];return Array.isArray(c)&&a!==void 0?c[a]:P0(c)&&(e.name==="begin"||e.name==="step"||e.name==="end")?e.name==="begin"?c.start:e.name==="step"?c.step:c.end:void 0}case"call":return this.call(e,t);case"lambda":return{type:"function",params:e.params,body:e.body,scope:t};case"let":{let c=new K1(t);return this.bindSeq(e.assigns,c),this.expr(e.body,c)}case"chain":return this.expr(e.check,t),this.expr(e.body,t)}}listItem(e,t,c,a){switch(e.kind){case"item":{let r=this.expr(e.expr,t);this.grow(c,1,a),c.push(r);return}case"each":{let r=this.iterable(this.expr(e.expr,t),a);this.grow(c,r.length,a);for(let s of r)c.push(s);return}case"for":this.loop(e.assigns,t,r=>this.listItem(e.body,r,c,a));return;case"if":O1(this.expr(e.cond,t))?this.listItem(e.then,t,c,a):e.else&&this.listItem(e.else,t,c,a);return;case"let":{let r=new K1(t);this.bindSeq(e.assigns,r),this.listItem(e.body,r,c,a)}}}grow(e,t,c){if(e.length+t>this.limits.maxListLength)throw new X(`a list of ${e.length+t} items is more than the limit of ${this.limits.maxListLength}`,c);this.charge(t,c)}charge(e,t){if(this.itemCount+=e,!(this.itemCount<=this.limits.maxListItems))throw new X(`The lists and strings hold more than ${this.limits.maxListItems} items in all, the limit. Is a loop building more than it needs?`,t)}call(e,t){if(e.callee.kind==="var"){let a=e.callee.name,r=t.get(a),s=r.found&&!F0(r.value);if(!r.found||s&&this.callable(a,t)){let i=t.fn(a);if(i)return this.callFunction(i,this.evalArgs(e.args,t,e.pos),t,a);let o=this.specialFunction(a,e,t);if(o.handled)return o.value;let l=y0(i3,a);if(l){let h=this.evalArgs(e.args,t,e.pos);this.checkArgs(a,h);for(let m of ge(l,h.pos,h.named))this.warn(`${a}(): "${m}" is given by position and by name; the named value is used (${g0(e.pos,!1)})`);let f={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,p)=>{if(!F0(m))throw new Error(`${a}() needs a function, got ${c0(m)}`);return this.callFunction(m,{pos:p,named:new Map,all:p.map(g=>({name:null,value:g})),at:e.pos},t,"function")}},u=ve(l,h.pos,h.named);this.tick(e.pos,be(a,u,this.limits.maxListLength));let d;try{d=l.run(u,f)}catch(m){if(m instanceof X)throw m;let p=new X(m instanceof RangeError?`${a}(): the result is too large`:m.message,e.pos);throw p.call=a,p}return this.checkValue(d,e.pos,a),d}throw new X(`Unknown function ${a}()${j4(T2(a,[...t.names("fns"),...t.names("vars"),...Object.keys(i3),...X4]))}`,e.pos)}if(!F0(r.value))throw new X(`"${a}" is a ${c0(r.value)}, not a function`,e.pos);return this.callFunction(r.value,this.evalArgs(e.args,t,e.pos),t,a)}let c=this.expr(e.callee,t);if(!F0(c))throw new X(`Can't call a ${c0(c)}`,e.pos);return this.callFunction(c,this.evalArgs(e.args,t,e.pos),t,"function")}invisiblePaint(e,t,c,a){let r=s=>Array.isArray(c)?String(c[s]??""):[...e[s].layers.keys()].sort().join(",");for(let s=1;s<e.length;s++){if(!t[s]?.length)continue;let i=r(s),o=G(e.flatMap((h,f)=>f<s&&r(f)===i?t[f]:[]));!o.length||t0(t[s],o).reduce((h,f)=>h+Math.abs(s1(f)),0)>.001||this.warn(`paint(): child ${s+1} lies wholly on an area of the same layer${Array.isArray(c)&&i?` "${i}"`:""} under it, so it can't be seen (${g0(a,!1)})`)}}record(e,t){let c=new Map;for(let a of e.fields)c.set(a.name,this.expr(a.value,t));return{type:"record",fields:c}}length(e,t){let c=j1(t.get("$scale").value??1);if(!(c>0))throw new X("$scale must be a number more than 0",e.pos);return c===1&&e.unit!=="mm"&&(this.unscaled??(this.unscaled=e.pos)),e.value*ir[e.unit]/c}callable(e,t){return!!t.fn(e)||X4.includes(e)||!!y0(i3,e)}specialFunction(e,t,c){if(e==="echo"){let a=this.evalArgs(t.args,c,t.pos);return this.echo(this.echoText(a),t.pos),{handled:!0,value:void 0}}if(e==="assert"){let a=this.evalArgs(t.args,c,t.pos);return this.checkArgs(e,a),this.assert(a),{handled:!0,value:!0}}if(e==="text_width"||e==="text_metrics"||e==="text_size"){let a=this.evalArgs(t.args,c,t.pos);this.checkArgs(e,a);let r=this.measure(a,c);return e==="text_width"?{handled:!0,value:r.advance}:e==="text_size"?{handled:!0,value:{type:"record",fields:new Map([["width",r.advance],["height",r.bounds[1][1]-r.bounds[0][1]],["bounds",r.bounds],["cap",r.cap],["ascent",r.ascent],["descent",r.descent],["size",r.size]])}}:{handled:!0,value:[r.advance,r.bounds,r.ascent,r.descent]}}if(e==="finger_count"){let a=this.evalArgs(t.args,c,t.pos);this.checkArgs(e,a);let r=this.num(this.arg(a,"length",0),"finger_count","length");return{handled:!0,value:n5(r,this.fingerWidth(a,c,1))}}return{handled:!1}}assert(e){if(O1(this.arg(e,"condition",0)))return;let t=this.arg(e,"message",1);throw new X(`Assertion failed${t===void 0?"":": "+F1(t)}`,e.at)}echo(e,t){let c=Math.ceil(e.length/W7);this.charge(c,t),this.retained+=c,this.echoes.push(e)}echoText(e){let t=this.limits.maxListLength,c=[],a=0,r=(s,i,o)=>{c.length&&(a+=2);let l=O2(i,t-a-s.length,o);if(a+=s.length+l.text.length,!l.whole)throw new X(`echo(): the text would be longer than the limit of ${t} characters`,e.at);c.push(s+l.text)};for(let{name:s,value:i}of e.all)s===null?r("",i,!1):r(`${s} = `,i,!0);return c.join(", ")}arith(e,t,c,a){if(typeof t=="number"&&typeof c=="number")switch(e){case"+":return t+c;case"-":return t-c;case"*":return t*c;case"/":return t/c;case"%":return t%c;case"^":return Math.pow(t,c)}if(e==="+"&&typeof t=="string"&&typeof c=="string")return this.checkSize(t.length+c.length,!0,a),t+c;if(Array.isArray(t)&&Array.isArray(c)){if(e==="+"||e==="-"){if(t.length!==c.length)throw new X(`Can't ${e==="+"?"add":"subtract"} lists of length ${t.length} and ${c.length}`,a);return this.charge(t.length+e3,a),t.map((s,i)=>this.arith(e,s,c[i],a))}if(e==="*"){if(Array.isArray(t[0]))return this.charge(t.length+e3,a),t.map(i=>this.arith("*",i,c,a));let s=(i,o)=>{let l=this.arith("*",i,o,a);if(typeof l!="number")throw new X("Can't multiply these lists: an item times an item is not a number",a);return l};if(Array.isArray(c[0])){let i=c[0].length;if(t.length!==c.length||c.some(o=>!Array.isArray(o)||o.length!==i))throw new X(`Can't multiply a list of length ${t.length} by a matrix: it needs ${t.length} rows of the same length`,a);return this.checkSize(i,!1,a),this.tick(a,i*t.length),Array.from({length:i},(o,l)=>t.reduce((h,f,u)=>h+s(f,c[u][l]),0))}if(t.length!==c.length)throw new X(`Can't multiply lists of length ${t.length} and ${c.length}`,a);return this.tick(a,t.length),t.reduce((i,o,l)=>i+s(o,c[l]),0)}}if(Array.isArray(t)&&typeof c=="number"&&(e==="*"||e==="/"))return this.charge(t.length+e3,a),t.map(s=>this.arith(e,s,c,a));if(typeof t=="number"&&Array.isArray(c)&&e==="*")return this.charge(c.length+e3,a),c.map(s=>this.arith(e,t,s,a));let r={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"take remainder of","^":"raise"};throw new X(`Can't ${r[e]??e} ${c0(t)} and ${c0(c)}`,a)}fieldFn(e,t,c,a){if(!F0(e))throw new Error(`field must be a function of a point, as function(p) ..., got ${w1(e)}`);return r=>{let s=this.itemCount,i=this.retained,o=this.callFunction(e,{pos:[r],named:new Map,all:[{name:null,value:r}],at:a},c,"field");return(!Array.isArray(o)||o.length<=3)&&(this.itemCount=s+this.retained-i),o}}arg(e,t,c,a){return e.named.has(t)?e.named.get(t):c>=0&&c<e.pos.length?e.pos[c]:a}num(e,t,c){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${c} must be a finite number, got ${w1(e)}`);return e}vec2(e,t,c=!0){let a=r=>typeof r=="number"&&Number.isFinite(r);if(a(e)&&c)return[e,e];if(Array.isArray(e)&&a(e[0])&&(e[1]===void 0||a(e[1])))return[e[0],e[1]??0];throw new Error(`${t} must be a number or [x, y], got ${w1(e)}`)}vec3(e,t){let c=a=>typeof a=="number"&&Number.isFinite(a);if(Array.isArray(e)&&(e.length===2||e.length===3)&&e.every(c))return[e[0],e[1],e[2]??0];throw new Error(`${t} must be [x, y, z], got ${w1(e)}`)}placements(e,t,c){let a=(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)],r=a(e,"at"),s=a(t,"rotate");for(let[i,o]of[[r,"at"],[s,"rotate"]])if(i.length!==1&&i.length!==c)throw new Error(`${o} needs one placement per copy: qty is ${c} but ${o} has ${i.length}`);return Array.from({length:c},(i,o)=>({at:r[r.length===1?0:o],rotate:s[s.length===1?0:o]}))}points(e,t){if(!Array.isArray(e))throw new Error(`${t} must be a list of [x, y] points`);return e.map((c,a)=>{if(!Array.isArray(c)||!Number.isFinite(c[0])||!Number.isFinite(c[1]))throw new Error(`${t}[${a}] must be an [x, y] point, got ${w1(c)}`);return[c[0],c[1]]})}dyn(e,t){return e.get(t).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,t,c){(Array.isArray(e)||typeof e=="string")&&this.checkSize(e.length,typeof e=="string",t,c)}checkSize(e,t,c,a){if(e>this.limits.maxListLength)throw new X(`${a?`${a}(): `:""}${t?`a string of ${e} characters`:`a list of ${e} items`} is more than the limit of ${this.limits.maxListLength}`,c);this.charge(t?Math.ceil(e/W7):e+e3,c)}segs(e){let t=j1(this.dyn(e,"$fn"))||0,c=j1(this.dyn(e,"$fa"))||2,a=j1(this.dyn(e,"$fs"))||.2,r=this.limits.maxSegments;return s=>{let i=He(s,t,c,a);if(!(i<=r))throw new Error(`a circle with ${i} segments is more than the limit of ${r}. Lower $fn, or raise $fa or $fs.`);return i}}thickness(e){let t=this.dyn(e,"$thickness");if(typeof t!="number"||!(t>0&&Number.isFinite(t)))throw new Error(`$thickness must be a positive number, got ${w1(t)}`);return t}kerf(e){let t=this.dyn(e,"$kerf");if(t===void 0)return 0;if(typeof t!="number"||!(t>=0&&Number.isFinite(t)))throw new Error(`$kerf must be a number, 0 or more, got ${w1(t)}`);return t}fingerWidth(e,t,c){let a=this.arg(e,"finger",c);return typeof a=="number"&&a>0?a:Math.max(3*this.thickness(t),6)}measure(e,t){if(!this.opts.fonts)throw new X("text needs a font. Pass fonts to render(), or --font on the command line.",e.at);let c=O2(this.arg(e,"text",0,""),this.limits.maxTextLength);if(!c.whole)throw new X(`the text is more than ${this.limits.maxTextLength} characters, the limit for one text()`,e.at);this.tick(e.at,c.text.length);try{let a=this.textOpts(e,t,c.text);return{...D3(this.opts.fonts,c.text,a),size:a.size}}catch(a){throw a instanceof X?a:new X(a.message,e.at)}}textOpts(e,t,c){let a={size:this.num(this.arg(e,"size",1,10),"text","size"),font:F1(this.arg(e,"font",2,this.dyn(t,"$font")??"")),halign:F1(this.arg(e,"halign",-1,"left")),valign:F1(this.arg(e,"valign",-1,"baseline")),spacing:j1(this.arg(e,"spacing",-1,1))},r=this.arg(e,"fit",-1);if(r!==void 0&&c!==void 0&&this.opts.fonts){let[s,i]=Array.isArray(r)?[r[0],r[1]]:[r,void 0],o=(p,g)=>{if(p===void 0)return;let v=this.num(p,"text","fit");if(!(v>0))throw new Error(`fit must be a ${g} more than 0`);return v},l=o(s,"width"),h=o(i,"height");if(Array.isArray(r)&&(r.length!==2||l===void 0&&h===void 0))throw new Error("fit must be a width, or [width, height] with either one undef");let f=D3(this.opts.fonts,c,{...a,size:1}),u=l===void 0?null:Z1(Q2(this.opts.fonts,c,{...a,size:1})),d=Math.max(f.advance,u?u[2]-u[0]:0),m=[...l!==void 0&&d>0?[l/d]:[],...h!==void 0&&f.cap>0?[h/f.cap]:[]];if(m.length){let p=this.arg(e,"size",1);a.size=Math.min(...m,...p===void 0?[]:[a.size])}}return a}textBlock(e,t,c,a,r){let s=this.opts.fonts,i={...c,size:1},o=new Map,l=A=>{if(!A)return 0;let z=o.get(A);if(z===void 0){let L=D3(s,A,i);z=Math.max(L.advance,L.bounds[1][0]-L.bounds[0][0]),o.set(A,z)}return z},h=t.split(`
|
|
4248
|
+
`).map(A=>A.split(/ +/).filter(Boolean)),f=(A,z)=>{if(z<=1||A.length<=1)return[A.join(" ")];let L=A.length,P=Math.min(z,L),I=(D,_)=>l(A.slice(D,_).join(" ")),T=Array.from({length:P+1},()=>new Array(L+1).fill(1/0)),O=Array.from({length:P+1},()=>new Array(L+1).fill(L));for(let D=0;D<L;D++)T[1][D]=I(D,L);for(let D=2;D<=P;D++)for(let _=0;_<L;_++)for(let R=_+1;R<=L-D+1;R++){let U=Math.max(I(_,R),T[D-1][R]);U<T[D][_]&&([T[D][_],O[D][_]]=[U,R])}let F=[];for(let D=P,_=0;D>=1;D--){let R=D===1?L:O[D][_];F.push(A.slice(_,R).join(" ")),_=R}return F},u=A=>{let z=h.map(()=>1);for(let L=A-h.length;L>0;L--){let P=-1,I=-1;if(h.forEach((T,O)=>{if(z[O]>=T.length)return;let F=Math.max(...f(T,z[O]).map(l));F>P&&([P,I]=[F,O])}),I<0)break;z[I]++}return h.flatMap((L,P)=>f(L,z[P]))},d=D3(s,"H",i),m=r*(d.ascent-d.descent),p=this.arg(e,"size",1),g=this.arg(e,"fit",-1),[v,b]=g===void 0?[void 0,void 0]:Array.isArray(g)?[g[0],g[1]]:[g,void 0],y=A=>{if(g===void 0)return c.size;let z=[...v!==void 0?[v/Math.max(...A.map(l),1e-9)]:[],...b!==void 0?[b/(d.cap+(A.length-1)*m)]:[],...p!==void 0?[this.num(p,"text","size")]:[]];return Math.min(...z)},x=u(Math.max(a,h.length));if(g!==void 0){let A=-1;for(let z=h.length;z<=Math.max(a,h.length);z++){let L=u(z),P=y(L);P>A*(1+1e-9)&&([x,A]=[L,P])}}let M=y(x),w=[];x.forEach((A,z)=>{for(let L of Q2(s,A,{...c,size:M,valign:"baseline"}))w.push(L.map(([P,I])=>[P,I-z*m*M]))});let k=Z1(w);if(!k)return[];let S=c.valign==="top"?-k[3]:c.valign==="center"?-(k[1]+k[3])/2:c.valign==="bottom"?-k[1]:c.valign==="cap"?-(d.cap*M-(x.length-1)*m*M)/2:0;return S?w.map(A=>A.map(([z,L])=>[z,L+S])):w}edges(e){let t=c=>{if(c==="out"||c==="in"||c==="flat")return c;throw new Error(`edges must be "out", "in" or "flat", got ${w1(c)}`)};if(typeof e=="string")return[t(e),t(e),t(e),t(e)];if(Array.isArray(e)&&e.length===4)return e.map(t);throw new Error("edges must be one value or a list of 4: [bottom, right, top, left]")}backLayer(e){let t=`${e}-back`,c=this.layers.get(t);if(c&&c.side!=="back")throw new Error(`the back of layer "${e}" is the layer "${t}", which this program already uses for the front. Rename that layer.`);if(!c){let a=this.layers.get(e)??{name:e,mode:"line",color:"#00aa00"};this.layers.set(t,{...a,name:t,side:"back"}),this.layerDefs++}return t}folds(e,t){if(e===void 0)return[];let c=t===void 0?1:this.num(t,"part","fold_open");if(!Number.isFinite(c))throw new Error("fold_open must be a number");let a=Array.isArray(e)&&e.length&&Array.isArray(e[0])&&Array.isArray(e[0][0])?e:[e];return a.map((r,s)=>{if(!Array.isArray(r)||r.length!==3)throw new Error(`fold${a.length>1?`[${s}]`:""} must be [from, to, angle], as [[0, 0], [0, 60], 90]`);let[i,o]=[this.vec2(r[0],"fold",!1),this.vec2(r[1],"fold",!1)],l=this.num(r[2],"part","fold");if(Math.hypot(o[0]-i[0],o[1]-i[1])<1e-6)throw new Error("a fold needs two different points");if(!(Math.abs(l)<=180))throw new Error(`a fold's angle must be from -180 to 180, got ${w1(r[2])}`);return{from:i,to:o,angle:l*c}})}bends(e){if(e===void 0||Array.isArray(e)&&!e.length)return[];let t=Array.isArray(e)&&Array.isArray(e[0])?e:[e];return t.map((c,a)=>{if(!Array.isArray(c)||c.length!==3||!c.every(o=>typeof o=="number"&&Number.isFinite(o)))throw new Error(`bend must be [x0, x1, angle] or a list of them, got ${w1(c)}${t.length>1?` at ${a}`:""}`);let[r,s,i]=c;if(!(s>r))throw new Error(`a bend's x1 must be more than its x0, got ${w1(c)}`);return{x0:r,x1:s,angle:i}})}makeBuiltins(){let e=(s,i)=>k2(s.children(),i),t=s=>i=>y3(i.children(),s),c=s=>i=>{let o=this.arg(i.args,"side",0,"front");if(o!=="front"&&o!=="back")throw new Error(`side must be "front" or "back", got ${w1(o)}`);return o==="back"&&i.env.vars.set("$mirrored",!O1(this.dyn(i.env,"$mirrored"))),y3(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=j1(this.arg(s.args,"r",-1,0))||0,h=O1(this.arg(s.args,"center",1,!1)),f=Ve(i,o,l,this.segs(s.env));return X1(G([h?f.map(([u,d])=>[u-i/2,d-o/2]):f]))},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 X1([t5(o,o,this.segs(s.env)(o))])},ellipse:s=>{let i=this.arg(s.args,"d",-1),[o,l]=i!==void 0?this.vec2(i,"d").map(h=>h/2):this.vec2(this.arg(s.args,"r",0,1),"r");return X1([t5(o,l,this.segs(s.env)(Math.max(o,l)))])},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 X1([t5(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 f=0;f<i*2;f++){let u=Math.PI/2+Math.PI*f/i,d=f%2?l:o;h.push([d*Math.cos(u),d*Math.sin(u)])}return X1(G([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(f=>i[j1(f)]).filter(Boolean)):[i];return X1(G(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=F2(N3(i),.01),l=this.arg(s.args,"fill",-1,"evenodd")==="nonzero"?"nonzero":"evenodd";return O1(this.arg(s.args,"close",-1,!1))?X1(G([...o.closed,...o.open.filter(h=>h.length>2)],l)):Y0([X1(G(o.closed,l)),Z0(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 Z0([[i,o]]);let h=this.num(l,"line","width");if(!(h>0))throw new Error("width must be more than 0");let f=Math.hypot(o[0]-i[0],o[1]-i[1]);if(!f)return e0();let u=-(o[1]-i[1])/f*(h/2),d=(o[0]-i[0])/f*(h/2);return X1(G([[[i[0]+u,i[1]+d],[i[0]-u,i[1]-d],[o[0]-u,o[1]-d],[o[0]+u,o[1]+d]]]))},polyline:s=>{let i=this.points(this.arg(s.args,"points",0),"points"),o=O1(this.arg(s.args,"closed",1,!1));return Z0([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 f=[];for(let u=0;u<=h;u++){let d=(o+(l-o)*u/h)*Math.PI/180;f.push([i*Math.cos(d),i*Math.sin(d)])}return Z0([f])},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=O2(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=this.arg(s.args,"path",-1),f=this.arg(s.args,"arc",-1);if(h!==void 0&&f!==void 0)throw new Error("text() takes path or arc, not both");let u=this.arg(s.args,"lines",-1),d=u===void 0?1:Math.floor(this.num(u,"text","lines"));if(!(d>=1&&d<=20))throw new Error(`lines must be from 1 to 20, got ${w1(u)}`);let m=o.text.includes(`
|
|
4249
|
+
`)||d>1;if(m&&(h!==void 0||f!==void 0))throw new Error("text() lays lines in a block, or along a path, not both");let p,g=this.num(this.arg(s.args,"line_spacing",-1,1),"text","line_spacing");if(!(g>0))throw new Error("line_spacing must be more than 0");let v=this.arg(s.args,"weld",-1,!1),b=typeof v=="number"?v>0:O1(v),y=typeof v=="number"?v:void 0,x=this.arg(s.args,"underline",-1),M=x===void 0?0:this.num(x,"text","underline");if(!(M>=0))throw new Error("underline must be a height, 0 or more");if(M>0&&!b)throw new Error("underline goes with weld = true");if(b&&(m||h!==void 0||f!==void 0))throw new Error("weld = true is for one line of text, not lines or a path");if(b){let S=B7(this.opts.fonts,o.text,l,M,y);p=S.polys,S.loose.length&&this.warn(`text(): welded, "${o.text.length>20?`${o.text.slice(0,20)}...`:o.text}" still has ${S.loose.length} loose piece${S.loose.length>1?"s":""} (${S.loose.map(A=>`in "${A}"`).join(", ")}), as an i's dot or a word apart; add underline = h or bridge = w to join ${S.loose.length>1?"them":"it"} (${g0(s.args.at,!1)})`)}else if(m)p=this.textBlock(s.args,o.text,l,d,g);else if(h!==void 0||f!==void 0){let S;if(f!==void 0){let z=this.num(f,"text","arc");if(!(z!==0&&Number.isFinite(z)))throw new Error(`arc must be a radius other than 0, got ${w1(f)}`);S=N7(z)}else if(S=this.points(h,"path"),S.length<2)throw new Error("path needs at least two points");this.arg(s.args,"halign",-1)===void 0&&(l.halign="center");let A=U7(this.opts.fonts,o.text,l,S);A.over>.01&&this.warn(`text(): "${o.text.length>20?`${o.text.slice(0,20)}...`:o.text}" is ${Math.round(A.over*10)/10} mm longer than its ${f!==void 0?"circle":"path"} allows, so it carries on past the end (${g0(s.args.at,!1)})`),p=A.polys}else p=Q2(this.opts.fonts,o.text,l);let w=this.arg(s.args,"weight",-1),k=this.arg(s.args,"bridge",-1);if(w!==void 0&&w!=="regular"){let S=w==="bold"?.035*l.size:this.num(w,"text","weight");S&&(p=L1(G(p),S,"round"))}if(k!==void 0&&(p=c4(p,this.num(k,"text","bridge"))),O1(this.dyn(s.env,"$mirrored"))){let[S,A]=[1/0,-1/0];for(let z of p)for(let[L]of z)[S,A]=[Math.min(S,L),Math.max(A,L)];return X1(G(p.map(z=>z.map(([L,P])=>[S+A-L,P]))))}return X1(p)},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)?j1(i[2]??0):this.num(i,"rotate","a"))*Math.PI/180,h=Math.cos(l),f=Math.sin(l),u=this.arg(s.args,"center",-1),d=[h,f,-f,h,0,0];if(u!==void 0){let[m,p]=this.vec2(u,"center",!1);d=[h,f,-f,h,m-h*m+f*p,p-f*m-h*p]}return e(s,d)},scale:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,1),"v");return e(s,[i,0,0,o,0,0])},mirror:s=>{let[i,o]=this.vec2(this.arg(s.args,"v",0,[1,0]),"v",!1),l=Math.hypot(i,o)||1,h=i/l,f=o/l;return e(s,[1-2*h*h,-2*h*f,-2*h*f,1-2*f*f,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().filter(j7);if(!i)return e0();let l=a(o,"difference");return r(i,h=>({regions:t0(h.regions,l.regions),lines:s0(h.lines,G(l.regions),"outside")}))},intersection:s=>{let i=s.childList().filter(j7);if(!i.length)return e0();let o=g=>[...g.layers.values()].some(v=>v.regions.length),l=g=>o(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===M0?[]:y.regions)),f=g=>{let v;for(let b of i){if(b===g||!l(b))continue;let y=G(h(b));v=v?b1(v,y):y}return v},u=i[0],d=i.every(l),m=f(u),p=r(u,g=>({regions:d?m?b1(g.regions,m):g.regions:[],lines:m?s0(g.lines,m,"inside"):g.lines}));for(let g of i){if(g===u)continue;if(g.parts.length)throw new Error("part() can only be the first child of intersection()");let v=f(g),b=new Map;for(let[x,M]of g.layers)M.lines.length&&b.set(x,{regions:[],lines:v?s0(M.lines,v,"inside"):M.lines});if(!b.size)continue;let y=p.parts.length===1&&!o(u)?p.parts[0]:void 0;if(y){let x=new Map(y.layers);for(let[M,w]of b){let k=x.get(M);x.set(M,{regions:k?.regions??[],lines:[...k?.lines??[],...w.lines]})}p={layers:p.layers,parts:[{...y,layers:x}]}}else p=Y0([p,{layers:b,parts:[]}])}return u.parts.forEach((g,v)=>{let b=[...g.layers.values()].some(x=>x.regions.length),y=[...p.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"} (${g0(s.args.at,!1)})`)}),p},hull:s=>{let i=s.children(),o=l=>{let h=[],f="cut",u=!0;for(let[m,p]of l){u&&(p.regions.length||p.lines.length)&&(f=m,u=!1);for(let g of[...p.regions,...p.lines])for(let v of g)h.push(v)}let d=e5(h);return new Map([[f,{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=O1(this.arg(s.args,"chamfer",-1,!1)),h=i!==void 0?this.num(i,"offset","r"):this.num(o??0,"offset","delta"),f=i!==void 0?"round":l?"square":"miter";return r(s.children(),u=>({regions:L1(u.regions,h,f),lines:u.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,...f]=s.childList();if(!h||!f.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 u=G(a(f,"pattern").regions),d=L0(h.layers),m=Z1(u);if(!d||!m)return e0();let p=Math.floor((m[1]-d[3])/o),g=Math.ceil((m[3]-d[1])/o),v=Math.floor((m[0]-d[2])/i)-1,b=Math.ceil((m[2]-d[0])/i)+1,y=(g-p+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=i0(u).map(A=>({polys:A,box:Z1(A)})),M=u,w=(A,z)=>{let L=0;for(let P of M)for(let I=0,T=P.length-1;I<P.length;T=I++){let[O,F]=P[T],[D,_]=P[I];F<=z?_>z&&(D-O)*(z-F)-(A-O)*(_-F)>0&&L++:_<=z&&(D-O)*(z-F)-(A-O)*(_-F)<0&&L--}return L!==0},k=new Map,S=(A,z)=>{let L=k.get(A)??{regions:[],lines:[]};for(let P of z.regions)L.regions.push(P);for(let P of z.lines)L.lines.push(P);k.set(A,L)};for(let A=p;A<=g;A++)for(let z=v;z<=b;z++){let L=z*i+(A%2?l*i:0),P=A*o,I=[d[0]+L,d[1]+P,d[2]+L,d[3]+P];if(I[2]<m[0]||I[0]>m[2]||I[3]<m[1]||I[1]>m[3])continue;let T=x.filter(R=>!(I[2]<R.box[0]||I[0]>R.box[2]||I[3]<R.box[1]||I[1]>R.box[3]));if(!T.length)continue;M=T.length===x.length?u:T.flatMap(R=>R.polys);let O=[w(I[0],I[1]),w(I[2],I[1]),w(I[2],I[3]),w(I[0],I[3])],F=M.some(R=>R.some((U,N)=>cr(R[N?N-1:R.length-1],U,I))),D=O.every(Boolean)&&!F,_=[1,0,0,1,L,P];for(let[R,U]of k2({layers:h.layers,parts:[]},_).layers)S(R,D?U:{regions:b1(U.regions,M),lines:s0(U.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=O1(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 f=$5(i,l,h);if(o===void 0)return Z0([f]);let u=this.num(o,"spline","width");if(!(u>0))throw new Error("width must be more than 0");return X1(G(R2([f],u)))},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=G(a([s.children()],"hatch").regions),f=Z1(h);if(!f)return e0();let[u,d]=[(f[0]+f[2])/2,(f[1]+f[3])/2],m=Math.hypot(f[2]-f[0],f[3]-f[1])/2+o,p=i*Math.PI/180,[g,v]=[Math.cos(p),Math.sin(p)],[b,y]=[-v,g],x=Math.ceil(m/o);if(!(2*x+1<=this.limits.maxSegments*10))throw new Error("pitch is too small for the area");this.tick(s.args.at,2*x+1);let M=[],w=Math.round((u*b+d*y)/o);for(let S=w-x;S<=w+x;S++){let A=S*o-(u*b+d*y),[z,L]=[u+b*A,d+y*A];M.push([[z-g*m,L-v*m],[z+g*m,L+v*m]])}if(l===void 0)return Z0(s0(M,h,"inside"));let k=this.num(l,"hatch","width");if(!(k>0))throw new Error("width must be more than 0");return X1(b1(G(R2(M,k).map(S=>S)),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"),f=this.num(this.arg(s.args,"seed",-1,1),"flow","seed"),u=G(a([s.children()],"flow").regions),d=Z1(u);if(!d)return e0();let m=b=>[Math.cos(b*G7),Math.sin(b*G7)],p;if(typeof i=="number"){let b=m(i);p=()=>b}else{let b=this.fieldFn(i,"flow",s.env,s.args.at);p=y=>{let x=b(y);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 ${w1(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=Re({spacing:o,step:l,minLength:h,seed:f,box:d,inside:Ue(u),dir:p,tick:()=>this.tick(s.args.at),maxPoints:this.limits.maxPoints});return Z0(s0(v,u,"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),f=this.num(this.arg(s.args,"cell",-1,1),"contours","cell");if(!(f>0))throw new Error("cell must be more than 0");let u=G(a([s.children()],"contours").regions),d=Z1(u);if(!d)return e0();let m=Math.ceil((d[2]-d[0])/f)+1,p=Math.ceil((d[3]-d[1])/f)+1;if(!(m*p<=this.limits.maxPoints/2))throw new Error(`a cell of ${f} samples the area at ${m*p} points, more than the limit of ${this.limits.maxPoints/2}: use a larger cell`);let g=new Float64Array(m*p),v=1/0,b=-1/0;for(let w=0;w<p;w++)for(let k=0;k<m;k++){let S=o([d[0]+k*f,d[1]+w*f]);if(S===void 0){g[w*m+k]=NaN;continue}if(typeof S!="number"||!Number.isFinite(S))throw new Error(`field() must give a number or undef, got ${w1(S)}`);g[w*m+k]=S,v=Math.min(v,S),b=Math.max(b,S)}if(!(v<=b))return e0();let y;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),S=Math.floor(b/w);if(!Number.isSafeInteger(k)||!Number.isSafeInteger(S))throw new Error(`the heights are too large for an interval of ${w}`);let A=Math.max(0,S-k+1);if(!(A<=1e4))throw new Error(`interval ${w} gives ${A} levels: use a larger interval`);y=Array.from({length:A},(z,L)=>(k+L)*w)}else if(Array.isArray(l))y=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");y=Array.from({length:w},(k,S)=>v+(b-v)*(S+1)/(w+1))}let x=[],M=0;for(let w of y){this.tick(s.args.at,Math.ceil(m*p/100));let k=qe(g,m,p,d[0],d[1],f,w),S=k.reduce((A,z)=>A+z.length,0);if(!((M+=S)<=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(S);for(let A of k)x.push(A)}return Z0(s0(x,u,"inside"))},occlude:s=>{let i;this.occluding++;try{i=s.childItems()}finally{this.occluding--}let o=f=>this.layers.get(f)?.mode??"cut",l=[],h=[];for(let f=i.length-1;f>=0;f--){let u=i[f];if(u.parts.length)throw new Error("part() cannot go inside occlude()");let d=new Map;for(let[p,g]of u.layers){if(p===M0)continue;let v=o(p);!h.length||v==="cut"||v==="guide"?d.set(p,g):v==="line"?d.set(p,{regions:[],lines:s0([...g.lines,...G(g.regions).map(b=>[...b,b[0]])],h,"outside")}):d.set(p,{regions:t0(g.regions,h),lines:s0(g.lines,h,"outside")})}l.push({layers:d,parts:[]});let m=[...u.layers].filter(([p])=>o(p)!=="guide").flatMap(([,p])=>p.regions);m.length&&(h=G([...h,...m]))}return Y0(l.reverse())},hide:s=>this.occluding?X1(G(a([s.children()],"hide").regions),M0):(this.warn(`hide() only works inside occlude(); it draws nothing (${g0(s.args.at,!1)})`),e0()),paint:s=>{let i=this.arg(s.args,"layers",0);if(i!==void 0&&(!Array.isArray(i)||i.some(u=>typeof u!="string")))throw new Error("layers must be a list of layer names");let o=s.childList(),l=[],h=[],f=[];for(let u=o.length-1;u>=0;u--){let d=o[u];if(d.parts.length)throw new Error("part() cannot go inside paint()");let m=h,p=G(a([d],"paint").regions);f[u]=p,h=m.length?G([...m,...p]):p;let g=Array.isArray(i)?i[u]: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(X1(m.length?t0(p,m):p,g));let v=d.layers.get(M0);v&&l.push({layers:new Map([[M0,v]]),parts:[]})}else l.push(m.length?r(d,v=>({regions:t0(v.regions,m),lines:s0(v.lines,m,"outside")})):d)}return this.invisiblePaint(o,f,i,s.args.at),Y0(l.reverse())},measure:s=>{let i=O1(this.arg(s.args,"draw",0,!1)),o=s.childSeq((l,h)=>{if(l!==0)return;let f=L0(h.layers)??Z1(h.parts.flatMap(v=>[...v.layers.values()].flatMap(b=>[...b.regions,...b.lines])));s.env.vars.set("$bounds",f?[...f]:void 0);let u=[h.layers,...h.parts.map(v=>v.layers)],d=v=>this.layers.get(v)?.mode??(v==="cut"||v==="guide"?v:void 0),m=u.flatMap(v=>[...v].filter(([b])=>d(b)==="cut").flatMap(([,b])=>b.regions)),p=m.length?m:u.flatMap(v=>[...v].filter(([b])=>d(b)!=="guide"&&d(b)!=="paint").flatMap(([,b])=>b.regions)),g=q2(G(p));s.env.vars.set("$area",g.area),s.env.vars.set("$centroid",g.area>0?g.centroid:void 0)});return Y0(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 r(s.children(),l=>({regions:G(l.regions).filter(h=>!(s1(h)<0&&-s1(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(([f,u])=>[f,(this.layers.get(f)?.mode??"cut")==="cut"?{regions:c4(u.regions,i),lines:u.lines}:u]));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=f=>i0(f).map(u=>({g:u,a:u.reduce((d,m)=>d+s1(m),0)})).sort((u,d)=>d.a-u.a).slice(0,i).flatMap(({g:u})=>u),l=s.children(),h=f=>new Map([...f].map(([u,d])=>[u,(this.layers.get(u)?.mode??"cut")==="cut"?{regions:o(d.regions),lines:d.lines}:d]));return{layers:h(l.layers),parts:l.parts.map(f=>({...f,layers:h(f.layers)}))}},close:s=>{let i=this.num(this.arg(s.args,"r",0,.5),"close","r");return r(s.children(),o=>({regions:L1(L1(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 r(s.children(),o=>({regions:G([...o.regions,...R2(o.lines,i)]),lines:[]}))},outline:s=>r(s.children(),i=>({regions:[],lines:[...i.lines,...G(i.regions).map(o=>[...o,o[0]])]})),cut:t("cut"),score:c("score"),engrave:c("engrave"),guide:t("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),f=this.arg(s.args,"order",-1),u=this.arg(s.args,"bleed",-1);if(o!==void 0||l!==void 0||f!==void 0||u!==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","paint"].includes(m))throw new Error('mode must be "cut", "line", "fill", "guide" or "paint"');let p=F1(l??h?.color??"#00aa00"),g=/^#[0-9a-fA-F]{6}$/.test(p)?p:L3(p);if(!g)throw new Error(`color must look like "#00aa00" or be a colour's name, as "red", got ${w1(p)}`);let v=f===void 0?h?.order:this.num(f,"layer","order"),b=u===void 0?h?.bleed:this.num(u,"layer","bleed");if(b!==void 0&&!(b>=0))throw new Error("bleed must be 0 or more");if(b&&(m==="cut"||m==="paint"))throw new Error(`a ${m} layer has no bleed`);this.layerDefs++;let y={name:i,mode:m,color:g,...v!==void 0&&{order:v},...b!==void 0&&{bleed:b}};this.layers.set(i,y);let x=this.layers.get(`${i}-back`);if(x?.side==="back"){if(m==="cut")throw new Error(`layer "${i}" already has marks on the back face, so it cannot become a cut layer`);this.layers.set(x.name,{...y,name:x.name,side:"back"})}}let d=this.arg(s.args,"side",-1,"front");if(d!=="front"&&d!=="back")throw new Error(`side must be "front" or "back", got ${w1(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",!O1(this.dyn(s.env,"$mirrored"))),y3(s.children(),d==="back"?this.backLayer(i):i)},part:s=>{let i=F1(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 ${w1(o)}`);if(l===0)return{layers:new Map,parts:[]};let h=this.arg(s.args,"stack",-1),f=h===void 0?1:Math.floor(this.num(h,"part","stack"));if(!(f>=1))throw new Error("stack must be 1 or more");if(this.copies+=l*f,!(this.copies<=this.limits.maxParts))throw new Error(`more than ${this.limits.maxParts} part copies in total, the limit`);let u=this.arg(s.args,"at",-1),d=this.arg(s.args,"rotate",-1),m=this.arg(s.args,"glue",-1),p=m===void 0?void 0:F1(m),g=F1(this.arg(s.args,"face",-1,"top"));if(g!=="top"&&g!=="bottom")throw new Error(`face must be "top" or "bottom", got ${w1(g)}`);let v=this.frame!==i4&&p===void 0,b=this.arg(s.args,"bend",-1),y=this.arg(s.args,"fold",-1),x=this.folds(y,this.arg(s.args,"fold_open",-1));if(x.length&&b!==void 0)throw new Error("a part bends on living hinges or folds, not both");let M=O1(this.arg(s.args,"press_fit",-1,!1));if(M&&p===void 0)throw new Error('press_fit goes with glue = "host"');let w=this.arg(s.args,"split",-1),k=w===void 0||w===!1?void 0:w===!0?!0:this.vec2(w,"split",!1);if(Array.isArray(k)&&!(k[0]>0&&k[1]>0))throw new Error("split must be true, or [width, height] more than 0");if(k&&(b!==void 0||x.length))throw new Error("a part that bends or folds cannot be split");let S=this.arg(s.args,"hang",-1),A=this.arg(s.args,"cord",-1),z=S===void 0?void 0:{at:this.vec2(S,"hang",!1),cord:A===void 0?0:this.num(A,"part","cord")};if(z&&!(z.cord>=0&&Number.isFinite(z.cord)))throw new Error(`cord must be a length, 0 or more, got ${w1(A)}`);if(A!==void 0&&!z)throw new Error("cord goes with hang = [x, y]");if(z&&(u===void 0||p!==void 0||b!==void 0||x.length))throw new Error("a hanging part needs at, the point it hangs from, and no glue, bend or fold");let L=u===void 0&&d===void 0&&!v&&p===void 0&&b===void 0&&y===void 0?void 0:this.placements(u,d,l),P=this.arg(s.args,"material",-1);P!==void 0&&s.env.vars.set("$material",F1(P));let I=this.thickness(s.env),T=this.arg(s.args,"paint",-1),O=T===void 0?void 0:L3(F1(T));if(T!==void 0&&!O)throw new Error(`paint must look like "#c8372d" or be a colour's name, as "red", got ${w1(T)}`);let F=this.arg(s.args,"pieces",-1);if(F!==void 0&&F!=="any"&&!(typeof F=="number"&&Number.isInteger(F)&&F>=1))throw new Error(`pieces must be a whole number, 1 or more, or "any", got ${w1(F)}`);let D=F;L&&(v||f>1)&&(L=L.flatMap(m1=>{let S1=p===void 0?q1(this.frame,o0(m1)):o0(m1),f0=p!==void 0&&g==="bottom"?-I:I;return Array.from({length:f},(O0,B0)=>({...m1,matrix:q1(S1,I0(0,0,B0*f0))}))}));let _=this.arg(s.args,"mirror",-1,!1),R;if(Array.isArray(_)){if(_.length!==l)throw new Error(`mirror needs one true or false per copy: qty is ${l} but mirror has ${_.length}`);R=_.map(m1=>O1(m1))}else R=Array.from({length:l},()=>O1(_));let U=R.some(m1=>m1)&&!R.every(m1=>m1);if(U&&p!==void 0)throw new Error("mirror per copy cannot go with glue: make the mirrored copies a part of their own");let N=R[0],e1=m1=>{let S1=s.env.vars.get("$mirrored"),f0=s.env.vars.has("$mirrored");m1&&s.env.vars.set("$mirrored",!0);try{let O0=s.children();return m1?k2(O0,[-1,0,0,1,0,0]):O0}finally{m1&&(f0?s.env.vars.set("$mirrored",S1):s.env.vars.delete("$mirrored"))}},E1=s.env.vars.has("$copy"),l0=s.env.vars.get("$copy");s.env.vars.set("$copy",0);let G1=this.copyReads,M1,A1;try{if(M1=e1(N),l>1&&this.copyReads!==G1){let m1=new Map;for(let S1=0;S1<l;S1++){s.env.vars.set("$copy",S1);let f0=S1===0&&R[0]===N?M1:e1(R[S1]),O0=`${R[S1]}|${JSON.stringify([...f0.layers].map(([C0,H2])=>[C0,H2.regions.map(C=>C.map(([$,J])=>[Math.round($*1e4),Math.round(J*1e4)])),H2.lines.map(C=>C.map(([$,J])=>[Math.round($*1e4),Math.round(J*1e4)]))]))}`,B0=m1.get(O0);B0?B0.copies.push(S1+1):m1.set(O0,{layers:f0.layers,flip:R[S1],copies:[S1+1]})}A1=[...m1.values()]}}finally{E1?s.env.vars.set("$copy",l0):s.env.vars.delete("$copy")}let z1=this.bends(b),o1=this.arg(s.args,"on",-1),h0=this.arg(s.args,"slots",-1),V0=h0===void 0?void 0:(Array.isArray(h0)?h0:[h0]).map(m1=>{if(typeof m1!="string")throw new Error("slots must be part names");return m1}),c2=this.num(this.arg(s.args,"clearance",-1,.1),"part","clearance"),y2=this.arg(s.args,"slot_extra",-1),x2=y2===void 0?void 0:this.vec2(y2,"slot_extra",!1),v0=this.arg(s.args,"bores",-1),u0=v0===void 0?void 0:(Array.isArray(v0)?v0:[v0]).map(m1=>{if(typeof m1!="string")throw new Error("bores must be hardware labels or kinds");return m1}),N0=this.arg(s.args,"halving",-1),I2=N0===void 0?void 0:(Array.isArray(N0)?N0:[N0]).map(m1=>{if(typeof m1!="string")throw new Error("halving must be part names");return m1}),W1=this.arg(s.args,"fit",-1,"turn");if(typeof W1!="number"&&!Object.prototype.hasOwnProperty.call(k3,F1(W1)))throw new Error(`fit must be "turn", "press" or a number of mm, got ${w1(W1)}`);let $3=typeof W1=="number"?W1:k3[F1(W1)],i2=(m1,S1,f0)=>{let O0=f0.length===l,B0=L?.filter((C0,H2)=>f0.includes(Math.floor(H2/f)+1));return{name:i,qty:f0.length*f,layers:m1,thickness:I,kerf:this.kerf(s.env),material:F1(this.dyn(s.env,"$material")??"material"),...O&&{paint:O},...D!==void 0&&{pieces:D},...z&&{hang:S1?{...z,at:[-z.at[0],z.at[1]]}:z},...k&&{split:k},...M&&{pressFit:!0},...B0?{placements:B0}:{},...f>1?{stack:f}:{},...z1.length?{bends:S1?z1.map(C0=>({...C0,mirrored:!0})):z1}:{},...x.length&&{folds:S1?x.map(C0=>({...C0,from:[-C0.from[0],C0.from[1]],to:[-C0.to[0],C0.to[1]]})):x},...o1!==void 0?{on:F1(o1)}:{},...V0?{slots:V0,clearance:c2}:{},...V0&&x2?{slotExtra:x2}:{},...u0?{bores:u0,fit:$3}:{},...I2?{halving:I2,clearance:c2}:{},...this.step?{step:this.step}:{},...p!==void 0&&{glue:{host:p,face:g}},...S1&&{mirrored:!0},...!O0&&{copies:f0}}},z0=m1=>R.flatMap((S1,f0)=>S1===m1?[f0+1]:[]),M2=A1?A1.map(m1=>i2(m1.layers,m1.flip,m1.copies)):U?[i2(M1.layers,N,z0(N)),i2(e1(!N).layers,!N,z0(!N))]:[i2(M1.layers,N,z0(N))];return{layers:new Map,parts:[...M1.parts,...M2]}},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,o0({at:i,rotate:o}));try{return s.children()}finally{this.frame=l}},step:s=>{let i=F1(this.arg(s.args,"text",0,"")),o=O1(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,f=this.stepNames.indexOf(h)+1;f||(this.stepNames.push(h),f=this.stepNames.length),this.step=f,this.stepFolded=!o;try{return s.children()}finally{this.step=l,this.stepFolded=!1}},hardware:s=>{let i=F1(this.arg(s.args,"kind",0,"dowel"));y0(u4,i)===void 0&&y0(a6,i)===void 0&&this.warn(`hardware(): unknown kind "${i}"; the 3D view shows it grey (${g0(s.args.at,!1)})${T2(i,Object.keys(u4))}`);let o=F1(this.arg(s.args,"shape",-1,"rod"));if(o!=="rod"&&o!=="ball")throw new Error(`shape must be "rod" or "ball", got ${w1(o)}`);let l=this.arg(s.args,"sides",-1),h=o==="ball"||l===0,f=this.vec3(this.arg(s.args,"from",1),"from"),u=this.arg(s.args,"to",2),d=i==="tealight",m=u!==void 0?this.vec3(u,"to"):d?[f[0],f[1],f[2]+G2.height]:h?f:this.vec3(u,"to"),p=this.arg(s.args,"size",3,d?G2.diameter:6),g=typeof p=="number"?p:this.vec2(p,"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");f=m=[(f[0]+m[0])/2,(f[1]+m[1])/2,(f[2]+m[2])/2]}let v=[m[0]-f[0],m[1]-f[1],m[2]-f[2]],b=Math.abs(v[2])>.9*Math.hypot(...v),y=this.arg(s.args,"up",-1),x=y===void 0?b?[0,1,0]:[0,0,1]:this.vec3(y,"up"),M=h?0:Math.floor(this.num(l??24,"hardware","sides"));if(!h&&!(M>=3&&M<=G4))throw new Error(`sides must be from 3 to ${G4} (or 0 for a ball), got ${w1(M)}`);if(this.pointCount+=h?2*G4:M*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),k=this.arg(s.args,"mass",-1),S=k===void 0?void 0:this.num(k,"hardware","mass");if(S!==void 0&&!(S>=0))throw new Error("mass must be grams, 0 or more");let A=this.frame,z=I=>[A[0]*I[0]+A[1]*I[1]+A[2]*I[2]+A[3],A[4]*I[0]+A[5]*I[1]+A[6]*I[2]+A[7],A[8]*I[0]+A[9]*I[1]+A[10]*I[2]+A[11]],L=I=>[A[0]*I[0]+A[1]*I[1]+A[2]*I[2],A[4]*I[0]+A[5]*I[1]+A[6]*I[2],A[8]*I[0]+A[9]*I[1]+A[10]*I[2]];if(this.hardware.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} pieces of hardware, the limit`);let P={kind:i,from:z(f),to:z(m),size:g,up:L(x),sides:M,step:this.step,...w!==void 0?{label:F1(w)}:{},...S!==void 0&&{mass:S}};return this.hardware.push(P),this.lights.push(...i6(P)),s.children()},light:s=>{let i=this.vec3(this.arg(s.args,"at",0,[0,0,0]),"at"),o=this.arg(s.args,"to",-1),l=o===void 0?i:this.vec3(o,"to"),h=F1(this.arg(s.args,"color",1,"warm white")),f=s6(h);if(!f)throw new Error(`color must look like "#ffd9a0" or be a colour's name, as "warm white" or "flame", got ${w1(h)}`);let u=this.num(this.arg(s.args,"lumens",2,20),"light","lumens");if(!(u>=0&&Number.isFinite(u)))throw new Error(`lumens must be 0 or more, got ${w1(u)}`);let d=O1(this.arg(s.args,"flicker",-1,!1)),m=this.arg(s.args,"label",-1);if(this.lights.length>=this.limits.maxParts)throw new Error(`more than ${this.limits.maxParts} lights, the limit`);let p=this.frame,g=v=>[p[0]*v[0]+p[1]*v[1]+p[2]*v[2]+p[3],p[4]*v[0]+p[5]*v[1]+p[6]*v[2]+p[7],p[8]*v[0]+p[9]*v[1]+p[10]*v[2]+p[11]];return this.lights.push({from:g(i),to:g(l),color:f,lumens:u,flicker:d,source:"light",step:this.step,...m!==void 0&&{label:F1(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",F1(l)),s.children()},children:s=>{let i=s.env.childCtx();if(!i)return e0();let o=this.childStmts(i.stmts),l=this.arg(s.args,"index",0),h=new K1(i.env,s.env);this.hoist(i.stmts,h);let f=new Set;if(l===void 0)o.forEach(p=>f.add(p));else for(let p of this.iterable(l,s.args.at)){let g=j1(p);o[g]?f.add(o[g]):o.length&&g>=o.length&&i.module&&i.pos&&this.warn(`${i.module}() uses children(${g}) but was given ${o.length} child${o.length===1?"":"ren"} (${g0(i.pos,!1)}). A module call takes one statement as its child: put several in braces, ${i.module}() { a(); b(); }`)}let u=[],d=this.childCache.get(i)??new Map;this.childCache.set(i,d);let m=this.childKey(h);for(let p of i.stmts)if(p.kind==="assign")this.stmt(p,h);else if(f.has(p)){let g=m&&d.get(p);if(g&&g.key===m){g.shape&&u.push(g.shape);continue}let v=this.effects(),b=this.stmt(p,h);b&&u.push(b),m&&this.effects()===v&&!b?.parts.length&&d.set(p,{key:m,shape:b})}return Y0(u)},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),f=this.fingerWidth(s.args,s.env,2);return this.spend(2*(Math.abs(i)+Math.abs(o))/f*4),X1(Oe(i,o,l,h,f))},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),X1(Fe(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),f=this.num(this.arg(s.args,"nut_at",3,o/2),"tslot","nut_at");return X1(G(_e(i,o,l,h,f)))},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"),f=this.num(this.arg(s.args,"cut",3,Math.max(h*2,(o-3*h)/2)),"living_hinge","cut");if(l<=0||h<=0||f<=0)throw new Error("spacing, bridge and cut must be positive");return this.spend((Math.abs(i)/l+1)*(Math.abs(o)/(f+h)+2)*2),Z0(De(i,o,l,h,f))}};function a(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,f]of l.layers)if(h!==M0)for(let u of f.regions)o.regions.push(u)}return o}function r(s,i){let o=l=>{let h=new Map;for(let[f,u]of l)h.set(f,i(u));return h};return{layers:o(s.layers),parts:s.parts.map(l=>({...l,layers:o(l.layers)}))}}}};function K7(n){switch(n.kind){case"num":return n.unit?{ok:!1}:{ok:!0,value:n.value};case"str":case"bool":return{ok:!0,value:n.value};case"unary":return n.op==="-"&&n.arg.kind==="num"?{ok:!0,value:-n.arg.value}:{ok:!1};case"list":{let e=[];for(let t of n.items){if(t.kind!=="item")return{ok:!1};let c=K7(t.expr);if(!c.ok||typeof c.value!="number")return{ok:!1};e.push(c.value)}return{ok:!0,value:e}}default:return{ok:!1}}}function ur(n,e){if(!/^[A-Za-z_][A-Za-z0-9_]*\s*\(.*\)$/.test(e.trim()))return;let t=n.split(`
|
|
4250
|
+
`).filter(c=>/^\s*(use|include)\s*<kerf\/[A-Za-z0-9_/-]+>/.test(c)).map(c=>/^\s*(?:use|include)\s*<kerf\/[A-Za-z0-9_/-]+>/.exec(c)[0].trim()).map(c=>c.replace(/^include/,"use"));try{let a=new t3({maxSteps:2e6}).run(K0(`${t.join(`
|
|
4251
|
+
`)}
|
|
4252
|
+
__options = ${e};`).program).globals.get("__options").value;return!Array.isArray(a)||!a.length?void 0:a.map(r=>Array.isArray(r)&&r.length===2?{name:String(r[1]),value:typeof r[0]=="number"?r[0]:String(r[0])}:{name:String(r),value:typeof r=="number"?r:String(r)})}catch{return}}function Z7(n){let e=Number(n.trim());return n.trim()!==""&&Number.isFinite(e)?e:void 0}function E5(n){let{program:e,comments:t}=K0(n),c=t.filter(o=>o.block&&/^\[[^\]]+\]$/.test(o.text)),a=new Map(t.filter(o=>!o.block&&!o.own).map(o=>[o.line,o.text])),r=new Map(t.filter(o=>!o.block&&o.own).map(o=>[o.line,o.text])),s=[],i=new Set;for(let o of e.body){if(o.kind!=="assign"||/^\$f[nas]$/.test(o.name))continue;let l=K7(o.value);if(!l.ok)continue;let h=c.filter(y=>y.line<=o.pos.line).pop()?.text.slice(1,-1).trim()??"Parameters";if(h.toLowerCase()==="hidden")continue;let f=a.get(o.pos.line),u=r.get(o.pos.line-1)??"",d=l.value,m={name:o.name,caption:u,group:h,type:typeof d=="number"||Array.isArray(d)?"number":typeof d=="boolean"?"boolean":"string",initial:d,span:o.span},p=f?/^((?:\[.*\](?:\s+drive)?)?)\s*when\s+(.+)$/.exec(f.trim()):null;p&&(m.when=p[2].trim()),p?.[1]&&i.add(m);let g=p?p[1].trim():f?.trim(),v=g?/^\[(.*)\](\s+drive)?$/.exec(g):null;v?.[2]&&m.type==="number"&&typeof d=="number"&&(m.drive=!0);let b=v?ur(n,v[1]):void 0;if(b)m.options=b;else if(v){let y=v[1];if(y.includes(",")||/[a-zA-Z"]/.test(y)&&!/^-?[\d.]+(:-?[\d.]+){0,2}$/.test(y))m.options=y.split(",").map(x=>{let[M,w]=x.split(":").map(A=>A.trim().replace(/^"|"$/g,"")),k=Z7(M),S=m.type==="number"&&k!==void 0?k:M;return{name:w??M,value:S}});else{let x=y.split(":").map(Z7);x.every(M=>M!==void 0)&&(x.length===1?m.max=x[0]:x.length===2?(m.min=x[0],m.max=x[1]):(m.min=x[0],m.step=x[1],m.max=x[2]))}}s.push(m)}for(let o of s){if(o.when===void 0)continue;if(!i.has(o)&&typeof J7(o.when)=="string"){delete o.when;continue}let l=fr(o.when,s);l&&(o.whenProblem=l,delete o.when)}return{parameters:s}}function J7(n){try{let e=K0(`when__ = (${n});`).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 Y7=new Set(["==","!=","<","<=",">",">=","&&","||","+","-","*","/","%","!"]);function fr(n,e){let t=J7(n);if(typeof t=="string")return`its condition (${n}) is not an expression: ${t}`;let c=new Set(e.map(s=>s.name)),a=s=>{switch(s.kind){case"num":case"str":case"bool":case"undef":return;case"var":return c.has(s.name)?void 0:`uses ${s.name}, which is not a setting`;case"list":for(let i of s.items){if(i.kind!=="item")return"uses a list comprehension";let o=a(i.expr);if(o)return o}return;case"unary":return Y7.has(s.op)?a(s.arg):`uses ${s.op}`;case"binary":return Y7.has(s.op)?a(s.left)??a(s.right):`uses ${s.op}`;case"ternary":return a(s.cond)??a(s.then)??a(s.else);case"index":return a(s.target)??a(s.index);default:return"uses more than settings, values and operators"}},r=a(t);return r?`its condition (${n}) ${r}`:void 0}var dr=/^(?:[A-Za-z_$][A-Za-z0-9_]*|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|"(?:[^"\\]|\\.)*"?|<=|>=|==|!=|&&|\|\|)/,Q7=(n,e)=>Math.max(1,dr.exec(n.slice(e-1))?.[0].length??1);var v2=1e6,R3=.01,b2=n=>s1(n)<0?[...n].reverse():n;function pr(n,e){let t=q1(l2(n.matrix),e.matrix),[c,a]=[t[8],t[9]],r=Math.hypot(c,a);if(r<1e-9)return[];let s=0,i=e.thickness,o=T=>(-t[11]-Math.max(t[10]*s,t[10]*i)+T)/r,l=T=>(n.thickness-t[11]-Math.min(t[10]*s,t[10]*i)-T)/r;if(!(l(R3)>o(R3)))return[];let[h,f]=[c/r,a/r],[u,d]=[-f,h],m=(T,O)=>[[h*T-u*v2,f*T-d*v2],[h*O-u*v2,f*O-d*v2],[h*O+u*v2,f*O+d*v2],[h*T+u*v2,f*T+d*v2]],p=1/0,g=-1/0;for(let T of e.outline)for(let[O,F]of T)for(let D of[s,i]){let _=t[8]*O+t[9]*F+t[10]*D+t[11];_<p&&(p=_),_>g&&(g=_)}if(Math.min(n.thickness,g)-Math.max(0,p)<Math.min(1,n.thickness/2))return[];let v=(T,O)=>b1(e.outline,[b2(m(T,O))]).filter(F=>Math.abs(s1(F))>1e-6),b=T=>{let[O,F]=[1/0,-1/0];for(let D of T)for(let[_,R]of D)for(let U of[s,i]){let N=t[8]*_+t[9]*R+t[10]*U+t[11];O=Math.min(O,N),F=Math.max(F,N)}return Math.min(n.thickness,F)-Math.max(0,O)},y=i0(v(o(R3),l(R3))).filter(T=>b(T)>=Math.min(1,n.thickness/2)-2*R3).flat();if(!y.length)return[];let x=Math.abs(l(0)-o(0))+1,M=T=>{let O=T.map(([_,R])=>[_-h*x,R-f*x]),F=T.map(([_,R])=>[_+h*x,R+f*x]),D=[b2(O),b2(F)];for(let _=0;_<T.length;_++){let R=(_+1)%T.length,U=[O[_],O[R],F[R],F[_]];Math.abs(s1(U))>1e-12&&D.push(b2(U))}return D},w=G(y.flatMap(M),"nonzero"),k=b1(e.outline,w).filter(T=>Math.abs(s1(T))>1e-6);if(!k.length)return[];let S=T=>([O,F])=>[t[0]*O+t[1]*F+t[2]*T+t[3],t[4]*O+t[5]*F+t[6]*T+t[7]],A=n.thickness,z=(T,O)=>(T-t[11]-t[10]*O)/r,L=[],P=T=>{T.length>=3&&Math.abs(s1(T))>1e-9&&L.push(b2(T))};for(let T of[s,i])for(let O of b1(k,[b2(m(z(0,T),z(A,T)))]))P(O.map(S(T)));for(let T of[0,A])if(Math.abs(t[10])>1e-9){let[O,F]=[z(T,s),z(T,i)].sort((D,_)=>D-_);for(let D of b1(k,[b2(m(O,F))]))P(D.map(([_,R])=>S((T-t[11]-t[8]*_-t[9]*R)/t[10])([_,R])))}else{let O=z(T,0);for(let F of b1(k,[b2(m(O-1e-4,O+1e-4))])){let[D,_]=[1/0,-1/0];for(let[N,e1]of F){let E1=u*N+d*e1;D=Math.min(D,E1),_=Math.max(_,E1)}if(!(_-D>1e-6))continue;let R=[h*O+u*D,f*O+d*D],U=[h*O+u*_,f*O+d*_];P([S(s)(R),S(s)(U),S(i)(U),S(i)(R)])}}let I=(T,O,F)=>t[8]*T+t[9]*O+t[10]*F+t[11];for(let T of k)for(let O=0;O<T.length;O++){let[F,D]=T[O],[_,R]=T[(O+1)%T.length],U=[[0,s],[1,s],[1,i],[0,i]],N=([e1,E1])=>I(F+(_-F)*e1,D+(R-D)*e1,E1);for(let[e1,E1]of[[1,0],[-1,-A]]){let l0=M1=>e1*N(M1)>=E1,G1=[];for(let M1=0;M1<U.length;M1++){let A1=U[M1],z1=U[(M1+1)%U.length];if(l0(A1)&&G1.push(A1),l0(A1)!==l0(z1)){let o1=e1*N(A1)-E1,h0=e1*N(z1)-E1,V0=o1/(o1-h0);G1.push([A1[0]+(z1[0]-A1[0])*V0,A1[1]+(z1[1]-A1[1])*V0])}}if(U=G1,!U.length)break}U.length>=3&&P(U.map(([e1,E1])=>S(E1)([F+(_-F)*e1,D+(R-D)*e1])))}return L.length?G(L,"nonzero"):[]}function et(n,e,t){let c=[];for(let r of e)for(let s of pr(n,r))c.push(s);if(!c.length)return[];let a=i0(b1(G(c),n.outline)).filter(r=>r.reduce((s,i)=>s+s1(i),0)>1e-4);return a.length?L1(a.flat(),t/2,"miter"):[]}var T5=(n,e)=>n[0]*e[0]+n[1]*e[1]+n[2]*e[2],mr=(n,e)=>[n[1]*e[2]-n[2]*e[1],n[2]*e[0]-n[0]*e[2],n[0]*e[1]-n[1]*e[0]],tt=n=>[n[2],n[6],n[10]],nt=n=>[n[3],n[7],n[11]];function ct(n,e,t){let c=[];for(let a of n)for(let r=0,s=a.length-1;r<a.length;s=r++){let i=a[s],o=a[r],l=t[0]*(i[1]-e[1])-t[1]*(i[0]-e[0]),h=t[0]*(o[1]-e[1])-t[1]*(o[0]-e[0]);if(l>0==h>0)continue;let f=l/(l-h);c.push((i[0]+(o[0]-i[0])*f-e[0])*t[0]+(i[1]+(o[1]-i[1])*f-e[1])*t[1])}return c.sort((a,r)=>a-r)}function at(n,e){for(let t=0;t+1<n.length;t+=2)if(n[t]<=e&&e<=n[t+1])return[n[t],n[t+1]]}function gr(n,[e,t]){let c=!1;for(let a of n)for(let r=0,s=a.length-1;r<a.length;s=r++){let[i,o]=a[s],[l,h]=a[r];o>t!=h>t&&e<i+(l-i)*(t-o)/(h-o)&&(c=!c)}return c}function rt(n,e,t){let c={a:[],b:[],thin:0},a=tt(n.matrix),r=tt(e.matrix),s=mr(a,r),i=Math.hypot(...s);if(i<1e-6)return c;let o=Math.abs(T5(a,r)),l=[s[0]/i,s[1]/i,s[2]/i],h=T5(a,nt(n.matrix))+n.thickness/2,f=T5(r,nt(e.matrix))+e.thickness/2,u=T5(a,r),d=1-u*u,m=(h-f*u)/d,p=(f-h*u)/d,g=[m*a[0]+p*r[0],m*a[1]+p*r[1],m*a[2]+p*r[2]],v=z=>{let L=l2(z.matrix);return[[L[0]*g[0]+L[1]*g[1]+L[2]*g[2]+L[3],L[4]*g[0]+L[5]*g[1]+L[6]*g[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]]]},[b,y]=v(n),[x,M]=v(e),w=ct(n.outline,b,y),k=ct(e.outline,x,M),S=(e.thickness+n.thickness*o)/i+t,A=(n.thickness+e.thickness*o)/i+t;for(let z=0;z+1<w.length;z+=2)for(let L=0;L+1<k.length;L+=2){let P=Math.max(w[z],k[L]),I=Math.min(w[z+1],k[L+1]);if(!(I-P>.01))continue;let T=(P+I)/2,[O,F]=at(w,T),[D,_]=at(k,T),R=Math.max(F-T,T-D)<=Math.max(T-O,_-T),U=(E1,l0,G1,M1,A1,z1)=>{let o1=[-G1[1],G1[0]],h0=(v0,u0)=>[l0[0]+G1[0]*(T+A1*v0)+o1[0]*u0,l0[1]+G1[1]*(T+A1*v0)+o1[1]*u0],V0=z1+M1+1,c2=[h0(0,-M1/2),h0(V0,-M1/2),h0(V0,M1/2),h0(0,M1/2)];s1(c2)<0&&c2.reverse();let y2=h0(Math.min(.01,z1/2),0),x2=i0(b1([c2],E1.outline)).find(v0=>gr(v0,y2));if(!(!x2||!(x2.reduce((v0,u0)=>v0+s1(u0),0)>1e-4)))return b1(L1(x2,.05,"miter"),[c2])},N=U(n,b,y,S,R?1:-1,R?F-T:T-O),e1=U(e,x,M,A,R?-1:1,R?T-D:_-T);if(!N||!e1){c.thin++;continue}c.a.push(...N),c.b.push(...e1)}return c}var n3=n=>{let e=Math.round(n*1e3)/1e3;return Object.is(e,-0)?"0":String(e)},J4=n=>n.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");function Q4(n,e){let t=[];for(let[c,a]of n){let r=[n3(c),n3(a)],s=t[t.length-1];(!s||s[0]!==r[0]||s[1]!==r[1])&&t.push(r)}for(;e&&t.length>1&&t[0][0]===t[t.length-1][0]&&t[0][1]===t[t.length-1][1];)t.pop();return t}var c3=(n,e)=>`M${Q4(n,e).map(([t,c])=>`${t} ${c}`).join("L")}${e?"Z":""}`;function I5(n,e){let t=[];for(let c of e){let a=[],r=[];for(let i of n){let o=i.layers.get(c.name);if(o){for(let l of o.lines)a.push(c3(l,!1));for(let l of o.regions)r.push(l)}}let s=b3(r).map(i=>c3(r[i],!0));(a.length||s.length)&&t.push({name:c.name,mode:c.mode,color:c.color,d:[...a,...s].join(""),regions:s.join(""),lines:a.join("")})}return t}function H5(n,e,t,c){let a=['<?xml version="1.0" encoding="UTF-8"?>',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="${n3(e)}mm" height="${n3(t)}mm" viewBox="0 0 ${n3(e)} ${n3(t)}">`];for(let r of c){let s=[],i=[],o=[];for(let h of n){let f=h.layers.get(r.name);if(!f)continue;let u=` data-part="${J4(h.part)}"`;if(r.mode==="fill"){f.regions.length&&i.push(`<path${u} d="${f.regions.map(d=>c3(d,!0)).join("")}"/>`);for(let d of f.lines)i.push(`<path${u} fill="none" stroke="${r.color}" stroke-width="0.1" d="${c3(d,!1)}"/>`);continue}for(let d of f.lines)s.push(`<path${u} d="${c3(d,!1)}"/>`);for(let d of f.regions)o.push([d,u])}for(let h of b3(o.map(([f])=>f)))s.push(`<path${o[h][1]} d="${c3(o[h][0],!0)}"/>`);if(!s.length&&!i.length)continue;let l=r.mode==="fill"?`fill="${r.color}" fill-rule="evenodd" stroke="none"`:`fill="none" stroke="${r.color}" stroke-width="0.1"${r.mode==="guide"?' stroke-dasharray="1 1"':""}`;a.push(`<g id="${J4(r.name)}" inkscape:groupmode="layer" inkscape:label="${J4(r.name)}" data-mode="${r.mode}" ${l}>`,...s,...i,"</g>")}return a.push("</svg>",""),a.join(`
|
|
4253
|
+
`)}var vr={"#ff0000":1,"#ffff00":2,"#00ff00":3,"#00ffff":4,"#0000ff":5,"#ff00ff":6,"#000000":7},br=n=>{let e=vr[n.toLowerCase()];if(e)return e;let[t,c,a]=[1,3,5].map(r=>parseInt(n.slice(r,r+2),16));return t>c&&t>a?1:c>t&&c>a?3:a>t&&a>c?5:7};function yr(n){let e=i=>i.toUpperCase().replace(/[^A-Z0-9_-]/g,"_"),t=new Set(Y4.map(i=>i.name)),c=new Set(n.map(i=>e(i.name))),a=new Set,r=new Map,s=[...n.filter(i=>t.has(i.name)),...n.filter(i=>!t.has(i.name))];for(let i of s){let o=e(i.name);if(a.has(o)){let l=2;for(;c.has(`${o}_${l}`)||a.has(`${o}_${l}`);)l++;o=`${o}_${l}`}a.add(o),r.set(i.name,o)}return r}function ee(n,e,t,c){let a=[],r=(o,l)=>a.push(String(o),String(l)),s=yr(c);r(0,"SECTION"),r(2,"HEADER"),r(9,"$ACADVER"),r(1,"AC1009"),r(9,"$INSUNITS"),r(70,4),r(0,"ENDSEC"),r(0,"SECTION"),r(2,"TABLES"),r(0,"TABLE"),r(2,"LAYER"),r(70,c.length);for(let o of c)r(0,"LAYER"),r(2,s.get(o.name)),r(70,0),r(62,br(o.color)),r(6,"CONTINUOUS");r(0,"ENDTAB"),r(0,"ENDSEC"),r(0,"SECTION"),r(2,"ENTITIES");let i=(o,l,h)=>{r(0,"POLYLINE"),r(8,o),r(66,1),r(10,0),r(20,0),r(30,0),r(70,h?1:0);for(let[f,u]of Q4(l.map(([d,m])=>[d,t-m]),h))r(0,"VERTEX"),r(8,o),r(10,f),r(20,u),r(30,0);r(0,"SEQEND"),r(8,o)};for(let o of c){let l=s.get(o.name),h=[];for(let f of n){let u=f.layers.get(o.name);if(u){for(let d of u.lines)i(l,d,!1);for(let d of u.regions)h.push(d)}}for(let f of b3(h))i(l,h[f],!0)}return r(0,"ENDSEC"),r(0,"EOF"),a.join(`
|
|
3023
4254
|
`)+`
|
|
3024
|
-
`}var
|
|
3025
|
-
`).length})`)}catch{}let p=C=>JSON.stringify([C.thickness,C.material,[...C.layers].map(([$,s1])=>[$,s1.regions.map(o1=>o1.map(([f1,y1])=>[Math.round(f1*100),Math.round(y1*100)])),s1.lines.map(o1=>o1.map(([f1,y1])=>[Math.round(f1*100),Math.round(y1*100)]))])]),v=new Map,g=new Set;for(let C of d){let $=p(C),s1=C.mirrored?`${C.name}\0mirrored`:C.name,o1=v.get(s1);o1===void 0?v.set(s1,$):o1!==$&&g.add(C.name)}for(let C of g)h.push(`Two different parts are named "${C}"; slots, glue and on = find parts by name, so give each its own.`);Ja(d,h),Ga(d,u,h),_a(d,u,h,o.hardware),Ba(d,u,h);let M=[],y=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,b=[],w=[],x=[],z=new Set,L=[],S=l("$min_width"),k=S===void 0?1.5:e0(S),E=l("$label_parts")===!0,V=l("$join_lines")===!0,T=0;E&&!r&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let H=f.get("engrave-back");E&&r&&H&&H.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 D=E&&!!r&&(!H||H.side==="back");if(D){let C=f.get("engrave");f.has("engrave-back")||f.set("engrave-back",{name:"engrave-back",mode:"fill",color:C?.color??"#000000",side:"back"})}let O=[];for(let C of d){let $=Z([...C.layers].filter(([X])=>u(X)==="cut").flatMap(([,X])=>X.regions)),s1;if(C.bends&&$.length){let X=1/0,a1=-1/0;for(let Q of $)for(let[l1]of Q)X=Math.min(X,l1),a1=Math.max(a1,l1);for(let[Q,l1]of U6(C.bends))(Q<X-.001||l1>a1+.001)&&h.push(`Part "${C.name}" bends from x = ${W0(Q)} to ${W0(l1)}, beyond the part (x = ${W0(X)} to ${W0(a1)}); only the part itself bends.`)}if(D&&$.length){s1=++T;let X=Qa($,String(s1),r,I1(l("$font")??""));if(X.length){let a1=C.layers.get("engrave-back")??{regions:[],lines:[]};C.layers=new Map(C.layers).set("engrave-back",{regions:[...a1.regions,...X],lines:a1.lines})}else h.push(`Part "${C.name}" is too small to take its number ${s1}.`)}if(k>0&&$.length){let X=A1(A1($,-k/2,"round"),k/2,"round"),a1=p0(l0($,X)).filter(Q=>Q.reduce((l1,m1)=>l1+i1(m1),0)>2*k*k);if(a1.length){let Q=a1.slice(0,3).map(l1=>{let[m1,k1,f0,d1]=k0(new Map([["cut",{regions:l1,lines:[]}]]));return`[${E1((m1+f0)/2)}, ${E1((k1+d1)/2)}]`});h.push(`Part "${C.name}" is narrower than ${k} mm ($min_width) in ${a1.length} place${a1.length>1?"s":""}, at ${Q.join(", ")}${a1.length>3?" and more":""} in the part's coordinates.`)}}let o1=new Map;for(let[X,a1]of C.layers){if(X===d0||u(X)==="guide"&&!e.guides)continue;let Q=Z(a1.regions),l1=a1.lines.filter(m1=>m1.length>=2);if((u(X)==="line"||u(X)==="guide")&&(l1=[...l1,...Q.map(m1=>[...m1,m1[0]])],Q=[]),$.length&&u(X)!=="guide"){let m1=f.get(X)?.bleed??0,k1=m1>0?A1($,m1,"round"):$;u(X)!=="cut"&&(Q=P1(Q,k1)),l1=h0(l1,k1,"inside")}V&&l1.length>1&&u(X)!=="guide"&&(l1=C6(l1)),(Q.length||l1.length)&&o1.set(X,{regions:Q,lines:l1})}if(O.push(...Ya(C.name,o1,f)),$.length){let X=[];for(let[Q,l1]of o1){let m1=f.get(Q);if(m1?.mode==="cut"&&l1.lines.length)for(let k1 of["front","back"])X.push({layer:Q,mode:"line",color:"#000000",side:k1,regions:[],lines:l1.lines});!m1||m1.mode!=="fill"&&m1.mode!=="line"||X.push({layer:Q,mode:m1.mode,color:m1.color,side:m1.side??"front",regions:l1.regions,lines:l1.lines})}let a1={name:C.name,thickness:C.thickness,material:C.material,outline:$,...X.length&&{marks:X}};for(let Q=0;Q<(C.placements?.length??C.qty);Q++)x.push({...a1,copy:$2(C,Q),matrix:a0({at:[0,0,0],rotate:[0,0,0]}),placed:!1});if(C.placements){let Q=new Set;C.placements.forEach((l1,m1)=>{let k1={...a1,copy:$2(C,m1),matrix:a0(l1),placed:!0,...C.bends&&{bends:C.bends},...C.step&&{step:C.step},...C.stack&&{stack:C.stack}};b.push(k1);let f0=k1.matrix.map(d1=>d1.toFixed(6)).join(",");Q.has(f0)&&z.add(k1),Q.add(f0)}),Q.size<C.placements.length&&h.push(`Copies of part "${C.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let Q=0;Q<C.qty;Q++)w.push({...a1,copy:$2(C,Q),matrix:a0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...C.step&&{step:C.step}})}let f1=p0($),y1=f1.length;if(y1>1){let X=l1=>l1.reduce((m1,k1)=>m1+i1(k1),0),Q=[...f1].sort((l1,m1)=>X(m1)-X(l1)).slice(1,4).map(l1=>{let[m1,k1,f0,d1]=k0(new Map([["cut",{regions:l1,lines:[]}]]));return`[${E1(m1)}, ${E1(k1)}] to [${E1(f0)}, ${E1(d1)}]`}).join(", ");h.push(`Part "${C.name}" cuts into ${y1} separate pieces. Join them, or make them separate parts. The smaller ${y1===2?"one is":"ones are"} at ${Q}${y1>4?" and more":""}, in the part's coordinates.`)}let b0=0;for(let[X,a1]of o1)if(u(X)==="cut"){for(let Q of a1.regions)b0+=U8(Q,!0);for(let Q of a1.lines)b0+=U8(Q,!1)}let Q1=k0(o1)??[0,0,0,0],b1=e.kerf??C.kerf;if(!(Number.isFinite(b1)&&b1>=0))throw new G("$kerf must be a number, 0 or more");let O0={name:C.name,qty:C.qty,width:E1(Q1[2]-Q1[0]),height:E1(Q1[3]-Q1[1]),pieces:y1,cutLength:Math.round(b0),thickness:C.thickness,kerf:b1,material:C.material,...C.stack&&{stack:C.stack},...C.glue&&{glued:C.glue.host},...C.mirrored&&{mirrored:!0},...s1!==void 0&&{label:s1}};if(y&&y.parts.push({name:C.name,kerf:b1,qty:C.qty,...C.stack&&{stack:C.stack},...C.glue&&{glue:C.glue},...C.on&&{on:C.on},cutRegions:$.map(X=>X.map(([a1,Q])=>[a1,Q])),cutLines:[...o1].filter(([X])=>u(X)==="cut").flatMap(([,X])=>X.lines.map(a1=>a1.map(([Q,l1])=>[Q,l1])))}),b1>0){for(let[X,a1]of o1)if(u(X)==="cut"){let Q=a1.regions.filter(k1=>i1(k1)<0);a1.regions=A1(a1.regions,b1/2,"round",Math.min(.01,b1/20));let l1=a1.regions.filter(k1=>i1(k1)<0),m1=Q.length-l1.length;if(m1>0){let k1=d1=>{let[z1,V1,M0,s0]=k0(new Map([["cut",{regions:[d1],lines:[]}]]));return[(z1+M0)/2,(V1+s0)/2]},f0=Q.map(k1).filter(([d1,z1])=>!l1.some(V1=>$8(V1,d1,z1))).slice(0,3).map(([d1,z1])=>`[${E1(d1)}, ${E1(z1)}]`);h.push(`Part "${C.name}": ${m1} hole${m1===1?" is":"s are"} narrower than the ${b1} mm kerf and will not be cut${f0.length?`, at ${f0.join(", ")}${m1>f0.length?" and more":""} in the part's coordinates`:""}.`)}}}M.push(O0),L.push({info:O0,layers:o1,copy:X=>$2(C,X)})}let R=new Map,N=b.filter(C=>!z.has(C)).flatMap(C=>{let $=N3(C);for(let s1 of $)R.set(s1,C);return $}),{found:q,complete:Y}=R6(N,i.maxCollisionPairs),_=q.filter(([C,$])=>R.get(C)!==R.get($)).map(([C,$,s1])=>[R.get(C)??C,R.get($)??$,s1,C,$]).filter(([C,$],s1,o1)=>o1.findIndex(([f1,y1])=>f1===C&&y1===$)===s1);Y||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[C,$,s1,o1,f1]of _.slice(0,5)){let y1=(q6(o1,f1)??s1).map(E1);h.push(`Parts "${C.name}"${C.copy>1?` (copy ${C.copy})`:""} and "${$.name}"${$.copy>1?` (copy ${$.copy})`:""} collide in the assembly, around [${y1.join(", ")}]. Check their edges and where they are placed.`)}if(_.length>5&&h.push(`${_.length-5} more pairs of parts collide in the assembly.`),Ka(O,h),b.length&&w.length){let C=[...new Set(w.map($=>`"${$.name}"`))];h.push(`${C.length===1?"Part":"Parts"} ${C.slice(0,5).join(", ")}${C.length>5?` and ${C.length-5} more`:""} ${C.length===1?"has":"have"} no at or rotate, so ${C.length===1?"it lies":"they lie"} flat beside the assembly.`),b.push(...O6(b,w))}let c1=0;for(let C of L){let $=0;for(let s1 of C.layers.values()){for(let o1 of s1.regions)$+=o1.length;for(let o1 of s1.lines)$+=o1.length}c1+=$*C.info.qty}if(c1>i.maxOutputPoints)throw new G(`The files would have ${c1} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let w1=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(w1)||!(Number.isFinite(w1[0])&&w1[0]>0)||!(Number.isFinite(w1[1])&&w1[1]>0))throw new G("$sheet must be [width, height], both more than 0");let D1=e.gap??e0(l("$gap")??3),J=e.margin??D1;if(!(Number.isFinite(D1)&&D1>=0))throw new G("$gap must be a number, 0 or more");if(!(Number.isFinite(J)&&J>=0))throw new G("margin must be a number, 0 or more");let C1=e.nest??l("$nest")===!0,r0=e.layout??(l("$layout")==="none"?"none":"pack"),u1=[...f.keys()].filter(C=>!["engrave","score","cut","guide"].includes(C)),J1=C=>(f.get(C)?.order??0)*2+(u(C)==="fill"?0:1),S0=["engrave",...u1.map((C,$)=>[C,$]).sort((C,$)=>J1(C[0])-J1($[0])||C[1]-$[1]).map(([C])=>C),"score","cut","guide"].map(C=>f.get(C)).filter(Boolean),B1=S0.filter(C=>C.side!=="back"),V0=[...S0.filter(C=>C.side==="back")],G0=l("$registration")===!0;G0&&!f.has("registration")&&f.set("registration",{name:"registration",mode:"fill",color:"#000000"}),G0&&!B1.some(C=>C.name==="registration")&&B1.push(f.get("registration"));let G1=[],u2=[1,0,0,-1,0,0],v5=C=>k0(C)??[0,0,0,0],j0=(C,$)=>m2({layers:C,parts:[]},$).layers;if(r0==="none"){let C=[];for(let f1 of L)for(let y1=0;y1<f1.info.qty;y1++)C.push({part:f1.info.name,copy:f1.copy(y1),layers:j0(f1.layers,u2),rotated:!1});let $=new Map;for(let f1 of C)for(let[y1,b0]of f1.layers){let Q1=$.get(y1)??{regions:[],lines:[]};for(let b1 of b0.regions)Q1.regions.push(b1);for(let b1 of b0.lines)Q1.lines.push(b1);$.set(y1,Q1)}let s1=v5($),o1=[1,0,0,1,J-s1[0],J-s1[1]];for(let f1 of C)f1.layers=j0(f1.layers,o1),f1.offset=[o1[4],o1[5]];G1.push($4(C,s1[2]-s1[0]+2*J,s1[3]-s1[1]+2*J,L[0]?.info))}else{let C=new Map;for(let $ of L){let s1=`${$.info.material}|${$.info.thickness}`;C.set(s1,[...C.get(s1)??[],$])}for(let $ of C.values()){let[s1,o1]=w1,f1=[];for(let d1 of $){let z1=j0(d1.layers,u2),V1=v5(z1),M0=V1[2]-V1[0],s0=V1[3]-V1[1],z2=!1;(M0>s1-2*J||s0>o1-2*J)&&s0<=s1-2*J&&M0<=o1-2*J&&(z1=j0(z1,[0,1,-1,0,0,0]),V1=v5(z1),M0=V1[2]-V1[0],s0=V1[3]-V1[1],z2=!0),(M0>s1-2*J||s0>o1-2*J)&&h.push(`Part "${d1.info.name}" (${E1(M0)} x ${E1(s0)} mm) is bigger than the ${s1} x ${o1} mm sheet.`),z1=j0(z1,[1,0,0,1,-V1[0],-V1[1]]);for(let Q0=0;Q0<d1.info.qty;Q0++)f1.push({info:d1.info,layers:z1,w:M0,h:s0,copy:d1.copy(Q0),rotated:z2})}let y1=(d1,z1)=>z1.h-d1.h||z1.w-d1.w,b0=d1=>{let z1=0,V1=J,M0=J,s0=0,z2=!1;for(let Q0 of d1)V1>J&&V1+Q0.w>s1-J&&(V1=J,M0+=s0+D1,s0=0),z2&&M0+Q0.h>o1-J&&(z1++,[V1,M0,s0]=[J,J,0]),z2=!0,V1+=Q0.w+D1,s0=Math.max(s0,Q0.h);return z1+(z2?1:0)};f1.sort(y1);let Q1=Wa(f1,D1,d1=>u(d1)==="cut",[s1-2*J,o1-2*J]).sort(y1),b1=Q1.length<f1.length&&b0(Q1)<b0(f1)?Q1:f1,O0=C1?ja(b1,D1,d1=>u(d1)==="cut"):b1,X=[],a1=J,Q=J,l1=0,m1=0,k1=0,f0=()=>{if(X.length&&G1.length>=i.maxSheets)throw new G(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);X.length&&G1.push($4(X,Math.max(m1+J,1),Math.max(k1+J,1),$[0].info)),X=[],a1=J,Q=J,l1=0,m1=0,k1=0};for(let d1 of O0){a1>J&&a1+d1.w>s1-J&&(a1=J,Q+=l1+D1,l1=0),X.length&&Q+d1.h>o1-J&&f0(),X.push({part:d1.info.name,copy:d1.copy,layers:j0(d1.layers,[1,0,0,1,a1,Q]),rotated:d1.rotated});for(let z1 of d1.inner??[])X.push({part:z1.item.info.name,copy:z1.item.copy,layers:j0(z1.item.layers,[1,0,0,1,a1+z1.dx,Q+z1.dy]),rotated:z1.item.rotated});m1=Math.max(m1,a1+d1.w),k1=Math.max(k1,Q+d1.h),a1+=d1.w+D1,l1=Math.max(l1,d1.h)}f0()}}function $4(C,$,s1,o1){let f1=E1($),y1=E1(s1);if(G0){let b1=Math.min(5,J-1);if(!(b1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let O0=(X,a1)=>[[X,a1],[X+b1,a1],[X+b1,a1+b1],[X,a1+b1]];C=[...C,{part:"registration",copy:1,layers:new Map([["registration",{regions:[O0(.5,.5),O0(f1-.5-b1,.5),O0(.5,y1-.5-b1)],lines:[]}]]),rotated:!1}]}}let b0=C.some(b1=>V0.some(O0=>b1.layers.has(O0.name))),Q1=b0?C.map(b1=>({...b1,layers:j0(b1.layers,[-1,0,0,1,f1,0])})):[];return{width:f1,height:y1,material:o1?.material??"material",thickness:o1?.thickness??0,items:C,paths:f5(C,B1),svg:d5(C,f1,y1,B1),dxf:F4(C,f1,y1,B1),...b0&&{back:{paths:f5(Q1,V0),svg:d5(Q1,f1,y1,V0),dxf:F4(Q1,f1,y1,V0)}}}}let f2=G1.length===1?G1[0]:void 0,_4=f2?[]:G1.flatMap((C,$)=>{let s1=G1.slice(0,$).reduce((o1,f1)=>o1+f1.height+10,0);return C.items.map(o1=>({...o1,layers:j0(o1.layers,[1,0,0,1,0,s1])}))}),B4=E1(Math.max(1,...G1.map(C=>C.width))),G4=E1(Math.max(1,G1.reduce((C,$)=>C+$.height,0)+10*Math.max(0,G1.length-1))),ce=f2?f2.svg:d5(_4,B4,G4,B1),ae=f2?f2.paths:f5(_4,B1);return{sheets:G1,width:f2?.width??B4,height:f2?.height??G4,paths:ae,svg:ce,parts:M,assembly:b,flat:x,layers:[...B1,...V0],warnings:h,echoes:o.echoes,...y&&{analysis:y},hardware:o.hardware,steps:o.steps}}function D4(n){if(!n.includes("*"))return t=>t===n;let e=new RegExp(`^${n.split("*").map(t=>t.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return t=>e.test(t)}function $a(n,e){if(!e||!n.length||e[0]===0&&e[1]===0)return n;let t=[...n];for(let c of n){let a=c.map(([r,s])=>[r+e[0],s+e[1]]);t.push(a);for(let r=0;r<c.length;r++){let s=(r+1)%c.length,i=[c[r],c[s],a[s],a[r]];Math.abs(i1(i))>1e-9&&t.push(i1(i)<0?i.reverse():i)}}return Z(t,"nonzero")}function R4(n,e){let t=new Map(n);for(let[c,a]of n)t.set(c,{regions:l0(a.regions,e),lines:h0(a.lines,e,"outside")});return t}function _a(n,e,t,c=[]){if(!n.some(l=>l.slots||l.bores))return;let a=new Map,r=l=>{let h=a.get(l);return h||(h=Z([...l.layers].filter(([f])=>e(f)==="cut").flatMap(([,f])=>f.regions)),a.set(l,h)),h},s=l=>(l.placements??[]).flatMap(h=>N3({name:l.name,copy:0,placed:!0,matrix:a0(h),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).map(f=>({matrix:f.matrix,thickness:f.thickness,outline:f.outline}))),i=new Map,o=new Map;for(let l of n){if(!l.slots&&!l.bores)continue;if(!l.placements){t.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 b of l.bores??[]){let w=b.startsWith("!"),x=D4(w?b.slice(1):b),z=c.filter(L=>x(L.label??"")||x(L.kind));!z.length&&!w&&t.push(`Part "${l.name}": no hardware "${b}" to bore for.`);for(let L of z)w?h.splice(0,h.length,...h.filter(S=>S!==L)):h.includes(L)||h.push(L)}let f=!1,u=new Set;for(let b of l.slots??[]){let w=b.startsWith("!"),x=D4(w?b.slice(1):b),z=n.filter(L=>L!==l&&x(L.name));!z.length&&!w&&t.push(`Part "${l.name}": no part "${b}" to cut slots for.`);for(let L of z)w?u.delete(L):u.add(L)}let d=new Map,m=[...u].flatMap(b=>s(b).map(w=>(d.set(w,b.name),w))),p=new Set,v=(l.placements??[]).map(b=>Z(N3({name:l.name,copy:0,placed:!0,matrix:a0(b),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends}}).flatMap(w=>{let x=[];if(l.slots){let z=m.map(S=>V8(w,[S],0));for(let S=0;S<z.length;S++)for(let k=S+1;k<z.length;k++){let[E,V]=[d.get(m[S]),d.get(m[k])];if(!z[S].length||!z[k].length||E===V||!E||!V)continue;let T=P1(z[S],z[k]);if(T.reduce((H,D)=>H+Math.abs(i1(D)),0)>.01){let H=T.flat().map(Y=>Y[0]),D=T.flat().map(Y=>Y[1]),[O,R,N,q]=[Math.min(...H),Math.min(...D),Math.max(...H),Math.max(...D)];p.add(`Tabs of "${E}" and "${V}" meet in the same slot in "${l.name}", at [${E1(O)}, ${E1(R)}] to [${E1(N)}, ${E1(q)}] in its coordinates. Move one's tabs along the edge.`)}}let L=z.flat();x=L.length?$a(A1(Z(L),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let z of h){let L=B6(w,z,l.fit??r3.turn);L&&P1([L],w.outline).some(S=>Math.abs(i1(S))>1e-4)&&(x.push(L),f=!0)}return l.bends?P1(x,A1(w.outline,1,"miter")):x}))),g=(b,w)=>D5(b,w).reduce((x,z)=>x+Math.abs(i1(z)),0)>.001,M=l.stack??1;if(M>1){let b=x=>v.filter((z,L)=>L%M===x),w=Array.from({length:M},(x,z)=>Z(b(z).flat()));if(w.slice(1).some(x=>g(w[0],x))){Array.from({length:M},(x,z)=>b(z)).some(x=>x.slice(1).some(z=>g(x[0],z)))&&t.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,w);continue}}v.slice(1).some(b=>g(v[0],b))&&t.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 b of p)t.push(b);l.bores&&h.length&&!f&&t.push(`Part "${l.name}": none of ${l.bores.map(b=>`"${b}"`).join(", ")} pass through it, so it has no bores.`);let y=Z(v.flat());if(!y.length){l.slots&&!l.slots.some(b=>b.includes("*"))&&t.push(`Part "${l.name}": none of ${l.slots.map(b=>`"${b}"`).join(", ")} pass through it, so it has no slots.`);continue}i.set(l,y)}for(let[l,h]of i)l.layers=R4(l.layers,h);for(let[l,h]of o){let f=h.length,u=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/f,layers:d.length?R4(l.layers,d):l.layers,placements:l.placements.filter((p,v)=>v%f===m),stack:void 0}));n.splice(n.indexOf(l),1,...u)}}function Ba(n,e,t){if(!n.some(i=>i.halving))return;let c=i=>Z([...i.layers].filter(([o])=>e(o)==="cut").flatMap(([,o])=>o.regions)),a=i=>{let o=c(i);return(i.placements??[]).map(l=>({matrix:a0(l),thickness:i.thickness,outline:o}))},r=new Map,s=(i,o,l)=>{let h=r.get(i)??(i.placements??[]).map(()=>[]);h[o].push(...l),r.set(i,h)};for(let i of n){if(!i.halving)continue;if(!i.placements){t.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 u of i.halving){let d=u.startsWith("!"),m=D4(d?u.slice(1):u),p=n.filter(v=>v!==i&&m(v.name));!p.length&&!d&&t.push(`Part "${i.name}": no part "${u}" to halve with.`);for(let v of p)d?o.delete(v):o.add(v)}let l=0,h=0,f=a(i);for(let u of o){if(i.bends||u.bends){t.push(`Parts "${i.name}" and "${u.name}": halving joints can't go in a bent part.`);continue}if(!u.placements)continue;let d=a(u);f.forEach((m,p)=>d.forEach((v,g)=>{let M=q8(m,v,i.clearance??.1);h+=M.thin,M.a.length&&(l++,s(i,p,M.a),s(u,g,M.b))}))}h&&t.push(`Part "${i.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&o.size&&!i.halving.some(u=>u.includes("*"))&&t.push(`Part "${i.name}" crosses none of ${i.halving.map(u=>`"${u}"`).join(", ")}, so it has no halving slots.`)}for(let[i,o]of r){let l=o.map(h=>Z(h));l.slice(1).some(h=>D5(l[0],h).reduce((f,u)=>f+Math.abs(i1(u)),0)>.001)&&t.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=R4(i.layers,Z(l.flat()))}}function Ga(n,e,t){let c=new Set;for(let a of n){if(a.on===void 0||!a.placements?.length)continue;let r=a.on,s=n.filter(p=>p.name===r&&p.placements?.length).flatMap(p=>p.placements.map((v,g)=>({q:p,m:a0(v),copy:$2(p,g)}))),i=n.filter(p=>p.name===a.name&&p.on===r).reduce((p,v)=>p+(v.placements?.length??0),0);if(!s.length){c.has(r)||t.push(`Part "${a.name}" is on "${r}", which is not a placed part.`),c.add(r);continue}let[o,l,h,f]=[1/0,1/0,-1/0,-1/0];for(let[p,v]of a.layers)if(e(p)==="cut")for(let g of v.regions)for(let[M,y]of g)o=Math.min(o,M),l=Math.min(l,y),h=Math.max(h,M),f=Math.max(f,y);if(!(h>=o))continue;let[u,d,m]=[(o+h)/2,(l+f)/2,a.thickness/2];a.placements=a.placements.map((p,v)=>{let g=$2(a,v),M=s.length===i&&s.find(L=>L.copy===g)||s[0];if(!M.q.bends?.length)return p;let y=a0(p),b=[y[0]*u+y[1]*d+y[2]*m+y[3],y[4]*u+y[5]*d+y[6]*m+y[7],y[8]*u+y[9]*d+y[10]*m+y[11]],w=t2(M.m),x=w[0]*b[0]+w[1]*b[1]+w[2]*b[2]+w[3],z=B5(M.q.bends,M.q.thickness)[N6(M.q.bends,x)];return{...p,matrix:q1(M.m,q1(z,q1(w,y)))}})}}function ja(n,e,t){var l;let c=[],a=h=>{let f=[];for(let[u,d]of h.layers)if(t(u))for(let m of d.regions)i1(m)<0&&f.push([...m].reverse());return f.length?A1(Z(f),-e,"miter"):[]},r=(h,f,u)=>{let d=0;for(let m of h)for(let p=0,v=m.length-1;p<m.length;v=p++){let[g,M]=m[v],[y,b]=m[p];M<=u?b>u&&(y-g)*(u-M)-(f-g)*(b-M)>0&&d++:b<=u&&(y-g)*(u-M)-(f-g)*(b-M)<0&&d--}return d!==0},s=h=>{let f=[];for(let[u,d]of h.layers)if(t(u))for(let m of d.regions)i1(m)>0&&f.push(m);return Z(f)},i=(h,f)=>{let{w:u,h:d}=f,m=s(f),p=[];for(let v of m)for(let g=0;g<v.length;g+=Math.max(1,Math.floor(v.length/12)))p.push(v[g]);for(let v of h){if(i1(v)<=0)continue;let[g,M,y,b]=[1/0,1/0,-1/0,-1/0];for(let[x,z]of v)g=Math.min(g,x),M=Math.min(M,z),y=Math.max(y,x),b=Math.max(b,z);if(y-g<u||b-M<d)continue;let w=Math.max(.5,Math.min(u,d,y-g-u+1,b-M-d+1)/4);for(let x=M;x<=b-d+1e-9;x+=w)for(let z=g;z<=y-u+1e-9;z+=w){if(!p.every(([S,k])=>r(h,S+z,k+x)))continue;let L=m.map(S=>S.map(([k,E])=>[k+z,E+x]));if(l0(L,h).reduce((S,k)=>S+Math.abs(i1(k)),0)<.01)return[z,x]}}},o=[];for(let h of n){let f=!1;for(let d of h.inner?.length?[]:c){let m=i(d.region,h);if(!m)continue;let[p,v]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+p,dy:d.oy+v}),d.region=l0(d.region,A1(s(h).map(M=>M.map(([y,b])=>[y+p,b+v])),e,"miter"));let g=a(h);g.length&&c.push({host:d.host,ox:d.ox+p,oy:d.oy+v,region:g}),f=!0;break}if(f)continue;o.push(h);let u=a(h);u.length&&c.push({host:h,ox:0,oy:0,region:u})}return o}function Wa(n,e,t,c){let a=new Map;for(let i of n)a.set(i.info,[...a.get(i.info)??[],i]);let r=[],s=(i,o)=>m2({layers:i,parts:[]},o).layers;for(let[,i]of a){let o=i[0],l=Z([...o.layers].filter(([d])=>t(d)).flatMap(([,d])=>d.regions.filter(m=>i1(m)>0))),h=l.reduce((d,m)=>d+i1(m),0)/(o.w*o.h),f=i.length>=2&&l.length&&h<.75?Xa(l,o.w,o.h,e,c):void 0;if(!f){r.push(...i);continue}let u=s(o.layers,[-1,0,0,-1,o.w,o.h]);for(let d=0;d<i.length;d+=f.n){let m=i.slice(d,d+f.n);if(m.length===1){r.push(m[0]);continue}let p=f.at.slice(0,m.length),v=Math.min(...p.map(b=>b[0])),g=Math.min(...p.map(b=>b[1])),M=Math.max(...p.map(b=>b[0]+o.w))-v,y=Math.max(...p.map(b=>b[1]+o.h))-g;r.push({...m[0],layers:s(m[0].layers,[1,0,0,1,p[0][0]-v,p[0][1]-g]),w:M,h:y,inner:m.slice(1).map((b,w)=>({item:{...b,layers:(w+1)%2?u:b.layers},dx:p[w+1][0]-v,dy:p[w+1][1]-g}))})}}return r}function Xa(n,e,t,c,a){let s=A1(n.map(y=>Za(y,.25)).filter(y=>y.length>=3),.25,"miter"),i=A1(s,c,"miter"),o=s.map(y=>y.map(([b,w])=>[e-b,t-w])),l=(y,[b,w])=>y.map(x=>x.map(([z,L])=>[z+b,L+w])),h=(y,b)=>!P1(y,b).some(w=>Math.abs(i1(w))>.001),f=(y,b,w,x)=>{let[z,L]=[0,x];if(h(y,l(b,w(L)))){if(h(y,l(b,w(z))))return w(z);for(let S=0;S<10;S++){let k=(z+L)/2;h(y,l(b,w(k)))?L=k:z=k}return w(L)}},u;for(let y of[!1,!0])for(let b=-10;b<=10;b++){let w=b/10*(y?e:t),x=f(i,o,S=>y?[w,S]:[S,w],(y?t:e)+c);if(!x)continue;let z=Math.max(e,x[0]+e)-Math.min(0,x[0]),L=Math.max(t,x[1]+t)-Math.min(0,x[1]);z>a[0]||L>a[1]||z*L<.85*2*e*t&&(!u||z*L<u.area)&&(u={d:x,across:y,area:z*L})}if(!u)return;let{d,across:m}=u,p=Z([...i,...A1(l(o,d),c,"miter")]),g=f(p,s,y=>m?[0,y]:[y,0],2*((m?t:e)+c)+Math.abs(m?d[1]:d[0])),M=[[0,0],[d[0],d[1]]];if(g){let y=b=>Math.max(...b.map(w=>w[0]+e))-Math.min(...b.map(w=>w[0]))<=a[0]&&Math.max(...b.map(w=>w[1]+t))-Math.min(...b.map(w=>w[1]))<=a[1];for(let b=2;b<500;b++){let w=Math.floor(b/2),x=b%2?[d[0]+w*g[0],d[1]+w*g[1]]:[w*g[0],w*g[1]];if(!y([...M,x]))break;let z=l(b%2?o:s,x),L=Z(M.slice(Math.max(0,M.length-3)).map((S,k,E)=>{let V=M.length-E.length+k;return A1(l(V%2?o:s,S),c,"miter")}).flat());if(!h(L,z))break;M.push(x)}}return{at:M,n:M.length}}function Za(n,e){if(n.length<8)return n;let t=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,f]=l.pop(),[u,d]=i[h],[m,p]=i[f],v=Math.hypot(m-u,p-d),g=-1,M=-1;for(let y=h+1;y<f;y++){let[b,w]=i[y],x=v?Math.abs((m-u)*(d-w)-(u-b)*(p-d))/v:Math.hypot(b-u,w-d);x>g&&([g,M]=[x,y])}g>e&&(o[M]=1,l.push([h,M],[M,f]))}return i.filter((h,f)=>o[f])},c=i=>Math.hypot(i[0]-n[0][0],i[1]-n[0][1]),a=1;for(let i=2;i<n.length;i++)c(n[i])>c(n[a])&&(a=i);let r=t(n.slice(0,a+1)),s=t([...n.slice(a),n[0]]);return[...r,...s.slice(1,-1)]}function $2(n,e){if(!n.copies)return e+1;let t=n.stack??1;return(n.copies[Math.floor(e/t)]-1)*t+e%t+1}function Ya(n,e,t){let c=[...t.keys()],a=[...e.keys()].filter(i=>t.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),r=[];if(a.length<2)return r;let s=i=>i==="engrave"?-1/0:(t.get(i)?.order??0)*2+c.indexOf(i)/c.length;a.sort((i,o)=>s(i)-s(o));for(let i=0;i<a.length-1;i++){let o=t.get(a[i]).side??"front",l=a.slice(i+1).filter(f=>(t.get(f).side??"front")===o);if(!l.length)continue;let h;for(let f of p0(e.get(a[i]).regions)){let u=f.reduce((w,x)=>w+i1(x),0);if(!(u>.001)||!A1(f,-.5,"round").length)continue;let d=f;for(let w of l)d.length&&(d=l0(d,e.get(w).regions));if(d.reduce((w,x)=>w+i1(x),0)>.001*Math.max(1,u))continue;let p=l.filter(w=>P1(f,e.get(w).regions).length),v=p.length?p:l;if(h){h.count++;for(let w of v)h.under.includes(w)||h.under.push(w);continue}let[g,M,y,b]=k0(new Map([["f",{regions:f,lines:[]}]]));h={part:n,layer:a[i],under:v,count:1,at:[E1((g+y)/2),E1((M+b)/2)]}}h&&r.push(h)}return r}function Ka(n,e){for(let t of n.slice(0,5)){let c=t.under.map(r=>`"${r}"`),a=c.length>1?`${c.slice(0,-1).join(", ")} and ${c.at(-1)}`:c[0];e.push(`Part "${t.part}": ${t.count>1?`${t.count} fills`:"a fill"} on layer "${t.layer}" (${t.count>1?"the first ":""}at [${t.at.join(", ")}]) ${t.count>1?"lie":"lies"} wholly under ${a}, stacked above it in the files: printed, ${t.count>1?"they":"it"} won't show, and engraved, ${t.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${t.layer}" a higher order.`)}if(n.length>5){let t=n.slice(5),c=new Set(t.map(r=>r.part)).size,a=[...new Set(t.map(r=>`"${r.layer}"`))];e.push(`Fills are hidden the same way in ${t.length} more place${t.length>1?"s":""}, on ${c} part${c>1?"s":""} (layer${a.length>1?"s":""} ${a.slice(0,5).join(", ")}${a.length>5?" and more":""}).`)}}function Ja(n,e){let t=new Set,c=(a,r)=>{if(!a.glue||t.has(a))return;if(r.includes(a)){e.push(`Part "${a.name}" is glued in a loop of parts; it is left where it is.`),t.add(a);return}let s=n.find(h=>h.name===a.glue.host&&h!==a);if(!s?.placements){e.push(`Part "${a.name}" is glued to "${a.glue.host}", which is not a placed part.`),t.add(a);return}c(s,[...r,a]);let i=s.placements.map(a0),o=a.glue.face==="top"?s.thickness:-a.thickness,l=a.placements.length/(a.stack??1);a.placements=a.placements.map((h,f)=>{let u=i.length===l?i[Math.floor(f/(a.stack??1))]:i[0];return{...h,matrix:q1(u,q1(Z0(0,0,o),a0(h)))}}),t.add(a)};for(let a of n)c(a,[])}function Qa(n,e,t,c){let a=0,r=50;for(let p=0;p<14;p++){let v=(a+r)/2;A1(n,-v,"round").length?a=v:r=v}if(a<1)return[];let s=A1(n,-a*.98,"round"),i=k0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((p,v)=>s.reduce((g,M)=>g+($8(M,p,v)?i1(M)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((p,v)=>i1(v)>i1(p)?v:p)[0]);let f=Math.min(6,Math.max(2,a*.9)),u=i5(t,e,{size:f,font:c,halign:"center",valign:"center",spacing:1}),d=k0(new Map([["t",{regions:u,lines:[]}]])),m=d?Math.min(1,1.6*a/Math.max(d[2]-d[0],1e-9)):1;return u.map(p=>p.map(([v,g])=>[o-v*m,l+g*m]).reverse())}function $8(n,e,t){let c=!1;for(let a=0,r=n.length-1;a<n.length;r=a++){let[s,i]=n[a],[o,l]=n[r];i>t!=l>t&&e<(o-s)*(t-i)/(l-i)+s&&(c=!c)}return c}var Z8=new WeakMap,q4=new WeakSet,Y8=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]),K8={$thickness:{value:"3",doc:"Material thickness, used by joinery and stored on parts"},$kerf:{value:"0",doc:"Beam width; cut outlines are offset by half of it"},$material:{value:'"material"',doc:"Material name; parts are packed per material and thickness"},$sheet:{value:"[600, 400]",doc:"Sheet size for packing"},$gap:{value:"3",doc:"Space between packed parts and around the sheet edge"},$layout:{value:'"pack"',doc:'`"pack"` packs parts onto sheets, `"none"` keeps your placement'},$fn:{value:"0",doc:"Segments in a full circle; 0 uses `$fa` and `$fs`"},$fa:{value:"2",doc:"Largest angle of a curve segment, in degrees"},$fs:{value:"0.2",doc:"Largest length of a curve segment, in mm"},$font:{doc:"Default font name for `text()`"},$children:{doc:"How many child statements the module was called with"},$scale:{value:"1",doc:"The model's scale: `140cm` is 1400 mm divided by `$scale`"},$nest:{value:"false",doc:"Pack small parts into the holes of bigger ones"},$registration:{value:"false",doc:"Print-and-cut marks in three corners of every sheet"},$label_parts:{value:"false",doc:"Engrave each part's number on its back face, the same number as in the parts list and the steps"},$min_width:{value:"1.5",doc:"Warn where a part's material is narrower than this; `0` turns it off"},$join_lines:{value:"false",doc:"Join lines that meet end to end into one and order them nearest first, so the laser travels less between them"},$mirrored:{doc:"True inside a mirrored part and on the back face, so `text()` reads right"},$bounds:{doc:"Set by `measure()` for the children after the one it measures"},$area:{doc:"Set by `measure()`: the area of material the measured child cuts, holes taken out, in square millimetres"},$centroid:{doc:"Set by `measure()`: the measured child's balance point `[x, y]`, the centroid of its material"},PI:{value:"3.141592653589793",doc:"\u03C0, half a turn in radians"}},er=["true","false","undef"],tr="https://kerfscript.mylasertools.com/docs/reference/",nr=n=>n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),_2=(n,e)=>Object.prototype.hasOwnProperty.call(n,e)?n[e]:void 0;function _8(n){let t=n.split(`
|
|
4255
|
+
`}var st=(n,e)=>{let t=0;for(let c=1;c<n.length;c++)t+=Math.hypot(n[c][0]-n[c-1][0],n[c][1]-n[c-1][1]);return e&&n.length>2&&(t+=Math.hypot(n[0][0]-n[n.length-1][0],n[0][1]-n[n.length-1][1])),t},T1=n=>Math.round(n*100)/100;function lt(n,e={}){for(let[C,$]of Object.entries(e.params??{}))try{F5(C,$)}catch(J){throw new X(J.message)}let{program:t}=K0(n),c=new Set(t.body.flatMap(C=>C.kind==="assign"?[C.name]:[])),a=Object.keys(e.params??{}).filter(C=>!C.startsWith("$")&&!c.has(C)),r=e.fonts?new C5(e.fonts,e.defaultFont):void 0,s=new t3({overrides:e.params,resolve:e.resolve,fonts:r,maxSteps:e.maxSteps,limits:e.limits}),i=s.limits,o;try{o=s.run(t)}catch(C){let $=C instanceof RangeError?new X(/call stack/i.test(C.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?"):C;throw $ instanceof X&&($.echoes=s.echoes,$.warnings=[...s.warnings],r?.missing.size&&($.missingFonts=[...r.missing])),$}let l=C=>o.globals.get(C).value,h=o.warnings;for(let C of a)h.push(`Setting "${C}" is not a variable of the program, so it is ignored.${T2(C,c)}`);let f=o.layers,u=C=>f.get(C)?.mode??"line",d=[...o.shape.parts];[...o.shape.layers.values()].some(C=>C.regions.length||C.lines.length)&&d.unshift({name:"part",qty:1,layers:o.shape.layers,thickness:l("$thickness")===void 0?3:j1(l("$thickness")),kerf:l("$kerf")===void 0?0:j1(l("$kerf")),material:F1(l("$material")??"material")}),d.length||h.push("Nothing to cut: the program made no shapes.");let p=new Set;for(let C of d)p.has(C.name)||[...C.layers].some(([J,t1])=>J!==M0&&(t1.regions.length||t1.lines.length))||(p.add(C.name),h.some(J=>J.includes(`leaves part "${C.name}" with nothing to cut`))||h.push(`Part "${C.name}" is empty: nothing drawn in it is left to cut.`));try{for(let C of E5(n).parameters)C.whenProblem&&h.push(`Setting ${C.name} is always shown: ${C.whenProblem} (line ${n.slice(0,C.span[0]).split(`
|
|
4256
|
+
`).length})`)}catch{}let g=C=>JSON.stringify([C.thickness,C.material,[...C.layers].map(([$,J])=>[$,J.regions.map(t1=>t1.map(([l1,h1])=>[Math.round(l1*100),Math.round(h1*100)])),J.lines.map(t1=>t1.map(([l1,h1])=>[Math.round(l1*100),Math.round(h1*100)]))])]),v=new Map,b=new Set;for(let C of d){let $=g(C),J=C.copies?`${C.name}\0${C.copies.join(",")}${C.mirrored?"m":""}`:C.mirrored?`${C.name}\0mirrored`:C.name,t1=v.get(J);t1===void 0?v.set(J,$):t1!==$&&b.add(C.name)}for(let C of b)h.push(`Two different parts are named "${C}"; slots, glue and on = find parts by name, so give each its own.`);kr(d,u,o.hardware);{let C=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet")),$=l("$knob")===void 0?12:j1(l("$knob")),J=l("$knob_clearance")===void 0?.15:j1(l("$knob_clearance")),t1={left:i.maxParts-d.reduce((l1,h1)=>l1+h1.qty,0),max:i.maxParts};for(let l1=d.length-1;l1>=0;l1--){let h1=d[l1];if(!h1.split)continue;let I1=h1.split===!0?[C[0]-2*(e.margin??e.gap??j1(l("$gap")??3)),C[1]-2*(e.margin??e.gap??j1(l("$gap")??3))]:h1.split,k1=wr(h1,u,I1,$,J,h,t1);d.splice(l1,1,...k1),k1.length>1&&zr(d,h1.name,k1,u)}}Or(d,h),Cr(d,u,h),Ar(d,u,h,o.hardware),Sr(d,u,h);let y=[],x=e.analysis?{schemaVersion:1,relations:!0,parts:[]}:void 0,M=[],w=[],k=[],S=new Set,A=new Map,z=[],L=l("$min_width"),P=L===void 0?1.5:j1(L),I=l("$label_parts")===!0,T=l("$join_lines")===!0,O=0;I&&!r&&h.push("$label_parts needs a font for the numbers. Pass fonts to render().");let F=f.get("engrave-back");I&&r&&F&&F.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 D=I&&!!r&&(!F||F.side==="back");if(D){let C=f.get("engrave");f.has("engrave-back")||f.set("engrave-back",{name:"engrave-back",mode:"fill",color:C?.color??"#000000",side:"back"})}let _=[];for(let C of d){let $=G([...C.layers].filter(([Q])=>u(Q)==="cut").flatMap(([,Q])=>Q.regions)),J;if(C.bends&&$.length){let Q=1/0,u1=-1/0;for(let n1 of $)for(let[p1]of n1)Q=Math.min(Q,p1),u1=Math.max(u1,p1);for(let[n1,p1]of Qe(C.bends))(n1<Q-.001||p1>u1+.001)&&h.push(`Part "${C.name}" bends from x = ${k0(n1)} to ${k0(p1)}, beyond the part (x = ${k0(Q)} to ${k0(u1)}); only the part itself bends.`)}let t1=C.folds&&$.length?t0($,R2([...C.layers].filter(([Q])=>u(Q)==="cut").flatMap(([,Q])=>Q.lines.filter(u1=>u1.length>=2)),.2)):$;if(C.folds&&$.length){let Q=h4(t1,C.folds,C.thickness).unused??[];for(let u1 of Q){let n1=C.folds[u1];h.push(`Part "${C.name}": the fold from [${k0(n1.from[0])}, ${k0(n1.from[1])}] to [${k0(n1.to[0])}, ${k0(n1.to[1])}] does not divide the part, so nothing folds there; run it from edge to edge, or to a cut.`)}}if(D&&$.length){J=++O;let Q=Fr($,String(J),r,F1(l("$font")??""));if(Q.length){let u1=C.layers.get("engrave-back")??{regions:[],lines:[]};C.layers=new Map(C.layers).set("engrave-back",{regions:[...u1.regions,...Q],lines:u1.lines})}else h.push(`Part "${C.name}" is too small to take its number ${J}.`)}if(P>0&&$.length){let Q=L1(L1($,-P/2,"round"),P/2,"round"),u1=i0(t0($,Q)).filter(n1=>n1.reduce((p1,K)=>p1+s1(K),0)>2*P*P);if(u1.length){let n1=u1.slice(0,3).map(p1=>{let[K,f1,x1,R1]=L0(new Map([["cut",{regions:p1,lines:[]}]]));return`[${T1((K+x1)/2)}, ${T1((f1+R1)/2)}]`});h.push(`Part "${C.name}" is narrower than ${P} mm ($min_width) in ${u1.length} place${u1.length>1?"s":""}, at ${n1.join(", ")}${u1.length>3?" and more":""} in the part's coordinates.`)}}let l1=new Map,h1=[];for(let[Q,u1]of C.layers){if(Q===M0||u(Q)==="guide"&&!e.guides)continue;if(u(Q)==="paint"){let K=f.get(Q),f1=b1(G(u1.regions),$),x1=s0(u1.lines.filter(R1=>R1.length>=2),$,"inside");(f1.length||x1.length)&&h1.push({layer:Q,mode:"fill",color:K.color,side:K.side??"front",regions:f1,lines:x1});continue}let n1=G(u1.regions),p1=u1.lines.filter(K=>K.length>=2);if((u(Q)==="line"||u(Q)==="guide")&&(p1=[...p1,...n1.map(K=>[...K,K[0]])],n1=[]),$.length&&u(Q)!=="guide"){let K=f.get(Q)?.bleed??0,f1=K>0?L1($,K,"round"):$;u(Q)!=="cut"&&(n1=b1(n1,f1)),p1=s0(p1,f1,"inside")}T&&p1.length>1&&u(Q)!=="guide"&&(p1=$e(p1)),(n1.length||p1.length)&&l1.set(Q,{regions:n1,lines:p1})}if(_.push(...Hr(C.name,l1,f)),$.length){let Q=[...h1];for(let[n1,p1]of l1){let K=f.get(n1);if(K?.mode==="cut"&&p1.lines.length)for(let f1 of["front","back"])Q.push({layer:n1,mode:"line",color:"#000000",side:f1,regions:[],lines:p1.lines});!K||K.mode!=="fill"&&K.mode!=="line"||Q.push({layer:n1,mode:K.mode,color:K.color,side:K.side??"front",regions:p1.regions,lines:p1.lines})}let u1={name:C.name,thickness:C.thickness,material:C.material,...C.paint&&{paint:C.paint},outline:t1,...Q.length&&{marks:Q}};for(let n1=0;n1<(C.placements?.length??C.qty);n1++)k.push({...u1,copy:a3(C,n1),matrix:o0({at:[0,0,0],rotate:[0,0,0]}),placed:!1});if(C.placements){let n1=new Set;C.placements.forEach((p1,K)=>{let f1={...u1,copy:a3(C,K),matrix:o0(p1),placed:!0,...C.bends&&{bends:C.bends},...C.folds&&{folds:C.folds},...C.step&&{step:C.step},...C.stack&&{stack:C.stack},...C.pressFit&&{pressFit:!0}};A.set(C,[...A.get(C)??[],M.length]),M.push(f1);let x1=f1.matrix.map(R1=>R1.toFixed(6)).join(",");n1.has(x1)&&S.add(f1),n1.add(x1)}),n1.size<C.placements.length&&h.push(`Copies of part "${C.name}" are in the same place in the assembly. Give at a list with one placement per copy to spread them out.`)}else for(let n1=0;n1<C.qty;n1++)w.push({...u1,copy:a3(C,n1),matrix:o0({at:[0,0,0],rotate:[0,0,0]}),placed:!1,...C.step&&{step:C.step}})}let I1=i0($),k1=I1.length;if(typeof C.pieces=="number"&&k1>0&&k1!==C.pieces)h.push(`Part "${C.name}" cuts into ${k1} separate piece${k1>1?"s":""}, not the ${C.pieces} its pieces = says.`);else if(k1>1&&C.pieces===void 0){let Q=p1=>p1.reduce((K,f1)=>K+s1(f1),0),n1=[...I1].sort((p1,K)=>Q(K)-Q(p1)).slice(1,4).map(p1=>{let[K,f1,x1,R1]=L0(new Map([["cut",{regions:p1,lines:[]}]]));return`[${T1(K)}, ${T1(f1)}] to [${T1(x1)}, ${T1(R1)}]`}).join(", ");h.push(`Part "${C.name}" cuts into ${k1} separate pieces. Join them, or make them separate parts. The smaller ${k1===2?"one is":"ones are"} at ${n1}${k1>4?" and more":""}, in the part's coordinates.`)}let H1=0;for(let[Q,u1]of l1)if(u(Q)==="cut"){for(let n1 of u1.regions)H1+=st(n1,!0);for(let n1 of u1.lines)H1+=st(n1,!1)}let V1=L0(l1)??[0,0,0,0],$1=e.kerf??C.kerf;if(!(Number.isFinite($1)&&$1>=0))throw new X("$kerf must be a number, 0 or more");if(!(Number.isFinite(C.thickness)&&C.thickness>0))throw new X("$thickness must be a positive number");let b0={name:C.name,qty:C.qty,width:T1(V1[2]-V1[0]),height:T1(V1[3]-V1[1]),pieces:k1,cutLength:Math.round(H1),thickness:C.thickness,kerf:$1,material:C.material,...C.paint&&{paint:C.paint},...C.stack&&{stack:C.stack},...C.glue&&{glued:C.glue.host},...C.mirrored&&{mirrored:!0},...C.copies&&{copies:C.copies},...C.joins&&{joins:C.joins},...J!==void 0&&{label:J}};if(x&&x.parts.push({name:C.name,kerf:$1,qty:C.qty,...C.stack&&{stack:C.stack},...C.glue&&{glue:C.glue},...C.on&&{on:C.on},cutRegions:$.map(Q=>Q.map(([u1,n1])=>[u1,n1])),cutLines:[...l1].filter(([Q])=>u(Q)==="cut").flatMap(([,Q])=>Q.lines.map(u1=>u1.map(([n1,p1])=>[n1,p1])))}),$1>0){for(let[Q,u1]of l1)if(u(Q)==="cut"){let n1=u1.regions.filter(f1=>s1(f1)<0);u1.regions=L1(u1.regions,$1/2,"round",Math.min(.01,$1/20));let p1=u1.regions.filter(f1=>s1(f1)<0),K=n1.length-p1.length;if(K>0){let f1=R1=>{let[J1,G0,j0,At]=L0(new Map([["cut",{regions:[R1],lines:[]}]]));return[(J1+j0)/2,(G0+At)/2]},x1=n1.map(f1).filter(([R1,J1])=>!p1.some(G0=>ce(G0,R1,J1))).slice(0,3).map(([R1,J1])=>`[${T1(R1)}, ${T1(J1)}]`);h.push(`Part "${C.name}": ${K} hole${K===1?" is":"s are"} narrower than the ${$1} mm kerf and will not be cut${x1.length?`, at ${x1.join(", ")}${K>x1.length?" and more":""} in the part's coordinates`:""}.`)}}}y.push(b0),z.push({info:b0,layers:l1,copy:Q=>a3(C,Q)})}let R=new Map;for(let[C,$]of A){if(!C.layerOf){R.set(C,$);continue}let{part:J,k:t1}=C.layerOf,l1=J.stack??1,h1=R.get(J)??[];$.forEach((I1,k1)=>h1[k1*l1+t1]=I1),R.set(J,h1)}for(let[C,$]of R){let J=C.stack??1,t1=C.glue&&[...R.keys()].find(I1=>I1.name===C.glue.host&&I1!==C),l1=t1?R.get(t1):void 0,h1=$.length/J;$.forEach((I1,k1)=>{let H1=k1%J,V1=H1>0?$[k1-H1]:t1&&l1?.[ut(t1,C,Math.floor(k1/J),h1)];V1!==void 0&&(M[I1].glued=V1)})}let U=new Map,N=M.filter(C=>!S.has(C)).flatMap(C=>{let $=w3(C);for(let J of $)U.set(J,C);return $}),{found:e1,complete:E1}=Ke(N,i.maxCollisionPairs),l0=(C,$)=>!!C.pressFit&&C.glued!==void 0&&M[C.glued]===$,G1=e1.filter(([C,$])=>U.get(C)!==U.get($)).filter(([C,$])=>{let[J,t1]=[U.get(C)??C,U.get($)??$];return!l0(J,t1)&&!l0(t1,J)}).map(([C,$,J])=>[U.get(C)??C,U.get($)??$,J,C,$]).filter(([C,$],J,t1)=>t1.findIndex(([l1,h1])=>l1===C&&h1===$)===J);E1||h.push(`The assembly has more than ${i.maxCollisionPairs} pairs of touching parts, the limit, so only those were checked for collisions.`);for(let[C,$,J,t1,l1]of G1.slice(0,5)){let h1=(Je(t1,l1)??J).map(T1);h.push(`Parts "${C.name}"${C.copy>1?` (copy ${C.copy})`:""} and "${$.name}"${$.copy>1?` (copy ${$.copy})`:""} collide in the assembly, around [${h1.join(", ")}]. Check their edges and where they are placed.`)}if(G1.length>5&&h.push(`${G1.length-5} more pairs of parts collide in the assembly.`),l("$stands")===!0){let C=xr(M.filter($=>!S.has($)),o.hardware,j1(l("$density")??.6));C&&h.push(C)}if(Vr(_,h),M.length&&w.length){let C=[...new Set(w.map($=>`"${$.name}"`))];h.push(`${C.length===1?"Part":"Parts"} ${C.slice(0,5).join(", ")}${C.length>5?` and ${C.length-5} more`:""} ${C.length===1?"has":"have"} no at or rotate, so ${C.length===1?"it lies":"they lie"} flat beside the assembly.`),M.push(...Xe(M,w))}let M1=0;for(let C of z){let $=0;for(let J of C.layers.values()){for(let t1 of J.regions)$+=t1.length;for(let t1 of J.lines)$+=t1.length}M1+=$*C.info.qty}if(M1>i.maxOutputPoints)throw new X(`The files would have ${M1} points, more than the limit of ${i.maxOutputPoints}. Use fewer copies or simpler shapes.`);let A1=e.sheet??(o.globals.vars.has("$sheet")?l("$sheet"):e.defaultSheet??l("$sheet"));if(!Array.isArray(A1)||!(Number.isFinite(A1[0])&&A1[0]>0)||!(Number.isFinite(A1[1])&&A1[1]>0))throw new X("$sheet must be [width, height], both more than 0");let z1=e.gap??j1(l("$gap")??3),o1=e.margin??z1;if(!(Number.isFinite(z1)&&z1>=0))throw new X("$gap must be a number, 0 or more");if(!(Number.isFinite(o1)&&o1>=0))throw new X("margin must be a number, 0 or more");let h0=e.nest??l("$nest")===!0,V0=e.layout??(l("$layout")==="none"?"none":"pack"),c2=[...f.keys()].filter(C=>!["engrave","score","cut","guide"].includes(C)),y2=C=>(f.get(C)?.order??0)*2+(u(C)==="fill"?0:1),v0=["engrave",...c2.map((C,$)=>[C,$]).sort((C,$)=>y2(C[0])-y2($[0])||C[1]-$[1]).map(([C])=>C),"score","cut","guide"].map(C=>f.get(C)).filter(C=>C&&C.mode!=="paint"),u0=v0.filter(C=>C.side!=="back"),N0=[...v0.filter(C=>C.side==="back")],I2=l("$registration")===!0;I2&&!f.has("registration")&&f.set("registration",{name:"registration",mode:"fill",color:"#000000"}),I2&&!u0.some(C=>C.name==="registration")&&u0.push(f.get("registration"));let W1=[],$3=[1,0,0,-1,0,0],i2=C=>L0(C)??[0,0,0,0],z0=(C,$)=>k2({layers:C,parts:[]},$).layers,M2=new Map;for(let C of z){let $=`${C.info.material}|${C.info.thickness}`;M2.set($,[...M2.get($)??[],C])}if(V0==="none"){for(let C of M2.values()){let $=[];for(let h1 of C)for(let I1=0;I1<h1.info.qty;I1++)$.push({part:h1.info.name,copy:h1.copy(I1),layers:z0(h1.layers,$3),rotated:!1});let J=new Map;for(let h1 of $)for(let[I1,k1]of h1.layers){let H1=J.get(I1)??{regions:[],lines:[]};for(let V1 of k1.regions)H1.regions.push(V1);for(let V1 of k1.lines)H1.lines.push(V1);J.set(I1,H1)}let t1=i2(J),l1=[1,0,0,1,o1-t1[0],o1-t1[1]];for(let h1 of $)h1.layers=z0(h1.layers,l1),h1.offset=[l1[4],l1[5]];W1.push(m1($,t1[2]-t1[0]+2*o1,t1[3]-t1[1]+2*o1,C[0].info))}M2.size||W1.push(m1([],2*o1,2*o1,void 0))}else for(let C of M2.values()){let[$,J]=A1,t1=[];for(let K of C){let f1=z0(K.layers,$3),x1=i2(f1),R1=x1[2]-x1[0],J1=x1[3]-x1[1],G0=!1;(R1>$-2*o1||J1>J-2*o1)&&J1<=$-2*o1&&R1<=J-2*o1&&(f1=z0(f1,[0,1,-1,0,0,0]),x1=i2(f1),R1=x1[2]-x1[0],J1=x1[3]-x1[1],G0=!0),(R1>$-2*o1||J1>J-2*o1)&&h.push(`Part "${K.info.name}" (${T1(R1)} x ${T1(J1)} mm) is bigger than the ${$} x ${J} mm sheet.`),f1=z0(f1,[1,0,0,1,-x1[0],-x1[1]]);for(let j0=0;j0<K.info.qty;j0++)t1.push({info:K.info,layers:f1,w:R1,h:J1,copy:K.copy(j0),rotated:G0})}let l1=(K,f1)=>f1.h-K.h||f1.w-K.w,h1=K=>{let f1=0,x1=o1,R1=o1,J1=0,G0=!1;for(let j0 of K)x1>o1&&x1+j0.w>$-o1&&(x1=o1,R1+=J1+z1,J1=0),G0&&R1+j0.h>J-o1&&(f1++,[x1,R1,J1]=[o1,o1,0]),G0=!0,x1+=j0.w+z1,J1=Math.max(J1,j0.h);return f1+(G0?1:0)};t1.sort(l1);let I1=Er(t1,z1,K=>u(K)==="cut",[$-2*o1,J-2*o1]).sort(l1),k1=I1.length<t1.length&&h1(I1)<h1(t1)?I1:t1,H1=h0?Pr(k1,z1,K=>u(K)==="cut"):k1,V1=[],$1=o1,b0=o1,Q=0,u1=0,n1=0,p1=()=>{if(V1.length&&W1.length>=i.maxSheets)throw new X(`The parts need more than ${i.maxSheets} sheets, the limit. Use fewer copies or a bigger $sheet.`);V1.length&&W1.push(m1(V1,Math.max(u1+o1,1),Math.max(n1+o1,1),C[0].info)),V1=[],$1=o1,b0=o1,Q=0,u1=0,n1=0};for(let K of H1){$1>o1&&$1+K.w>$-o1&&($1=o1,b0+=Q+z1,Q=0),V1.length&&b0+K.h>J-o1&&p1(),V1.push({part:K.info.name,copy:K.copy,layers:z0(K.layers,[1,0,0,1,$1,b0]),rotated:K.rotated});for(let f1 of K.inner??[])V1.push({part:f1.item.info.name,copy:f1.item.copy,layers:z0(f1.item.layers,[1,0,0,1,$1+f1.dx,b0+f1.dy]),rotated:f1.item.rotated});u1=Math.max(u1,$1+K.w),n1=Math.max(n1,b0+K.h),$1+=K.w+z1,Q=Math.max(Q,K.h)}p1()}function m1(C,$,J,t1){let l1=T1($),h1=T1(J);if(I2){let H1=Math.min(5,o1-1);if(!(H1>=2))h.push("Registration marks need $gap of 3 or more round the sheet.");else{let V1=($1,b0)=>[[$1,b0],[$1+H1,b0],[$1+H1,b0+H1],[$1,b0+H1]];C=[...C,{part:"registration",copy:1,layers:new Map([["registration",{regions:[V1(.5,.5),V1(l1-.5-H1,.5),V1(.5,h1-.5-H1)],lines:[]}]]),rotated:!1}]}}let I1=C.some(H1=>N0.some(V1=>H1.layers.has(V1.name))),k1=I1?C.map(H1=>({...H1,layers:z0(H1.layers,[-1,0,0,1,l1,0])})):[];return{width:l1,height:h1,material:t1?.material??"material",thickness:t1?.thickness??0,items:C,paths:I5(C,u0),svg:H5(C,l1,h1,u0),dxf:ee(C,l1,h1,u0),...I1&&{back:{paths:I5(k1,N0),svg:H5(k1,l1,h1,N0),dxf:ee(k1,l1,h1,N0)}}}}let S1=W1.length===1?W1[0]:void 0,f0=S1?[]:W1.flatMap((C,$)=>{let J=W1.slice(0,$).reduce((t1,l1)=>t1+l1.height+10,0);return C.items.map(t1=>({...t1,layers:z0(t1.layers,[1,0,0,1,0,J])}))}),O0=T1(Math.max(1,...W1.map(C=>C.width))),B0=T1(Math.max(1,W1.reduce((C,$)=>C+$.height,0)+10*Math.max(0,W1.length-1))),C0=S1?S1.svg:H5(f0,O0,B0,u0),H2=S1?S1.paths:I5(f0,u0);return{sheets:W1,width:S1?.width??O0,height:S1?.height??B0,paths:H2,svg:C0,parts:y,assembly:M,flat:k,layers:[...u0,...N0],warnings:h,echoes:o.echoes,...x&&{analysis:x},hardware:o.hardware,lights:o.lights,steps:o.steps}}function xr(n,e,t){let c=n.filter(d=>d.placed).flatMap(d=>w3(d));if(!c.length)return;let a=(d,[m,p,g])=>[d[0]*m+d[1]*p+d[2]*g+d[3],d[4]*m+d[5]*p+d[6]*g+d[7],d[8]*m+d[9]*p+d[10]*g+d[11]],r=0,s=[0,0,0],i=1/0,o=[];for(let d of c){let{area:m,centroid:p}=q2(d.outline);if(!(m>0))continue;let g=m*d.thickness*t*.001,v=a(d.matrix,[p[0],p[1],d.thickness/2]);for(let b=0;b<3;b++)s[b]+=v[b]*g;r+=g;for(let b of d.outline)for(let[y,x]of b)for(let M of[0,d.thickness]){let w=a(d.matrix,[y,x,M]);o.push(w),i=Math.min(i,w[2])}}for(let d of e){if(!(d.mass&&d.mass>0))continue;let m=[0,1,2].map(p=>(d.from[p]+d.to[p])/2);for(let p=0;p<3;p++)s[p]+=m[p]*d.mass;r+=d.mass}if(!(r>0)||!o.length)return;let l=s.map(d=>d/r),h=o.filter(d=>d[2]<=i+.5).map(([d,m])=>[d,m]),f=Mr(h);if(!(d=>{if(f.length<3)return!1;for(let m=0;m<f.length;m++){let p=f[m],g=f[(m+1)%f.length];if((g[0]-p[0])*(d[1]-p[1])-(g[1]-p[1])*(d[0]-p[0])<-.5*Math.hypot(g[0]-p[0],g[1]-p[1]))return!1}return!0})([l[0],l[1]]))return`The model tips over: its weight's centre, at [${T1(l[0])}, ${T1(l[1])}, ${T1(l[2])}], is not over what it stands on. Widen its base or move weight over it.`}function Mr(n){let e=[...n].sort((r,s)=>r[0]-s[0]||r[1]-s[1]);if(e.length<3)return e;let t=(r,s,i)=>(s[0]-r[0])*(i[1]-r[1])-(s[1]-r[1])*(i[0]-r[0]),c=[];for(let r of e){for(;c.length>=2&&t(c[c.length-2],c[c.length-1],r)<=0;)c.pop();c.push(r)}let a=[];for(let r of[...e].reverse()){for(;a.length>=2&&t(a[a.length-2],a[a.length-1],r)<=0;)a.pop();a.push(r)}return[...c.slice(0,-1),...a.slice(0,-1)]}function ht(n,e,t){let c=[];for(let r of n)for(let s=0;s<r.length;s++){let i=r[s],o=r[(s+1)%r.length];if(i[t]>e!=o[t]>e){let l=(e-i[t])/(o[t]-i[t]);c.push(i[1-t]+l*(o[1-t]-i[1-t]))}}c.sort((r,s)=>r-s);let a=[];for(let r=0;r+1<c.length;r+=2)a.push([c[r],c[r+1]]);return a}function it(n,e,t,c,a){let r=[[n-.3*t,e-.22*t],[n+.4*t,e-.22*t],[n+.4*t,e+.22*t],[n-.3*t,e+.22*t]],s=Array.from({length:48},(o,l)=>{let h=2*Math.PI*l/48;return[n+.58*t+.32*t*Math.cos(h),e+.32*t*Math.sin(h)]}),i=G([r,s]);return a&&(i=L1(i,a,"round")),c===0?i:i.map(o=>o.map(([l,h])=>[h,l]).reverse())}function ot(n,e,t,c,a,r){let s=Math.ceil((c-t)/a-1e-9),i=[],o=t;for(let l=1;l<s;l++){let h=Math.max(o+1,c-(s-l)*a),f=Math.min(o+a,c-1),u=(h+f)/2,d=1/0;for(let m=0;m<=40;m++){let p=h+(f-h)*m/40,g=b=>ht(b,p,r).reduce((y,[x,M])=>y+M-x,0),v=g(n)+5*g(e);v<d-1e-6&&([d,u]=[v,p])}i.push(u),o=u}return i}function wr(n,e,t,c,a,r,s){let i=G([...n.layers].filter(([L])=>e(L)==="cut").flatMap(([,L])=>L.regions)),o=L0(new Map([["cut",{regions:i,lines:[]}]]));if(!o)return[n];let l=.9*c,h=[t[0]-l,t[1]-l];if(!(h[0]>c&&h[1]>c))return r.push(`Part "${n.name}": split = [${t.join(", ")}] is too small to cut into pieces with ${c} mm knobs.`),[n];let f=L=>o[L+2]-o[L]<=t[L]+1e-9,u=G([...n.layers].filter(([L])=>e(L)!=="cut").flatMap(([,L])=>L.regions)),d=L=>f(L)?1:Math.ceil((o[L+2]-o[L])/h[L]-1e-9),m=(d(0)*d(1)-1)*n.qty;if(!(m<=s.left))throw new X(`Part "${n.name}": split into ${d(0)*d(1)} pieces would make more than ${s.max} part copies in total, the limit`);s.left-=m;let p=f(0)?[]:ot(i,u,o[0],o[2],h[0],0),g=f(1)?[]:ot(i,u,o[1],o[3],h[1],1);if(!p.length&&!g.length)return[n];let v=1e6,b=(L,P,I)=>[I===0?[[L,-v],[P,-v],[P,v],[L,v]]:[[-v,L],[v,L],[v,P],[-v,P]]],y=(L,P,I,T)=>{let O=[];for(let[F,D]of ht(T,L,P)){let _=D-F;if(_<1.6*c)continue;let R=Math.max(1,Math.floor(_/(5*c)));for(let U=0;U<R;U++){let[N,e1]=[F+_*U/R,F+_*(U+1)/R],E1=(N+e1)/2;if(u.length){let l0=1/0;for(let G1=0;G1<=12;G1++){let M1=N+.7*c+(e1-N-1.4*c)*G1/12,A1=b1(it(L,M1,c*1.2,P,0),u).reduce((o1,h0)=>o1+Math.abs(s1(h0)),0),z1=Math.abs(M1-(N+e1)/2)*.001;A1+z1<l0&&([l0,E1]=[A1+z1,M1])}}O.push(...it(L,E1,c,P,I))}}return G([...b(-v,L,P),...O])},x=(L,P,I,T)=>{let O=P<L.length?y(L[P],I,-a/2,T):b(-v,v,I);return P>0?t0(O,y(L[P-1],I,a/2,T)):O},M=L=>[-v,...L,v],[w,k]=[M(p),M(g)],S=[],A=[],z=0;for(let L=0;L<=g.length;L++)for(let P=0;P<=p.length;P++){let I=b1(i,b(k[L],k[L+1],1)),T=b1(i,b(w[P],w[P+1],0)),O=b1(x(p,P,0,I),x(g,L,1,T));if(!b1(i,O).length)continue;let D=`${n.name} piece ${++z}`;(S[L]??(S[L]=[]))[P]=D;let _=new Map;for(let[R,U]of n.layers){let N=b1(U.regions,O),e1=s0(U.lines,O,"inside");(N.length||e1.length)&&_.set(R,{regions:N,lines:e1})}A.push({...n,name:D,layers:_,split:void 0})}for(let L of A){let P=S.findIndex(T=>T?.includes(L.name)),I=S[P].indexOf(L.name);L.joins=[S[P][I-1],S[P][I+1],S[P-1]?.[I],S[P+1]?.[I]].filter(T=>!!T)}return A}function zr(n,e,t,c){let a=i=>[...i.layers].filter(([o])=>c(o)==="cut").flatMap(([,o])=>o.regions),r=i=>{let{area:o,centroid:l}=q2(G(a(i))),h=o0(i.placements?.[0]??{at:[0,0,0],rotate:[0,0,0]}),[f,u]=o>0?l:[0,0],[d,m]=[h[0]*f+h[1]*u+h[3],h[4]*f+h[5]*u+h[7]],p=g=>a(g).reduce((v,b)=>v+(ce(b,d,m)?s1(b)>0?1:-1:0),0)>0;return(t.find(p)??t[0]).name},s=t.map(i=>i.name);for(let i of n)t.includes(i)||(i.glue?.host===e&&(i.glue={...i.glue,host:r(i)}),i.on===e&&(i.on=r(i)),i.slots?.includes(e)&&(i.slots=i.slots.flatMap(o=>o===e?s:[o])))}function kr(n,e,t){for(let c of n){if(!c.hang||!c.placements)continue;let a=G([...c.layers].filter(([u])=>e(u)==="cut").flatMap(([,u])=>u.regions)),{area:r,centroid:s}=q2(a),[i,o]=c.hang.at,[l,h]=r>0?[s[0]-i,s[1]-o]:[0,-1],f=c.hang.cord;c.placements=c.placements.map((u,d)=>{let m=o0(u),[p,g]=[m[8],m[9]],v=Math.hypot(p,g)<1e-9?0:Math.atan2(-(g*l-p*h),-(p*l+g*h)),[b,y]=[Math.cos(v),Math.sin(v)],x=[b,-y,0,-(b*i-y*o),y,b,0,-(y*i+b*o),0,0,1,0,0,0,0,1],M=q1(I0(0,0,-f),q1(m,x));if(f>0){let w=[m[3],m[7],m[11]];t.push({kind:"cord",from:w,to:[w[0],w[1],w[2]-f],size:1.5,up:[0,1,0],sides:12,step:c.step??0,label:`${c.name}${c.placements.length>1?` ${d+1}`:""} cord`})}return{...u,matrix:M}})}}function te(n){if(!n.includes("*"))return t=>t===n;let e=new RegExp(`^${n.split("*").map(t=>t.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")}$`);return t=>e.test(t)}function Lr(n,e){if(!e||!n.length||e[0]===0&&e[1]===0)return n;let t=[...n];for(let c of n){let a=c.map(([r,s])=>[r+e[0],s+e[1]]);t.push(a);for(let r=0;r<c.length;r++){let s=(r+1)%c.length,i=[c[r],c[s],a[s],a[r]];Math.abs(s1(i))>1e-9&&t.push(s1(i)<0?i.reverse():i)}}return G(t,"nonzero")}function ne(n,e){let t=new Map(n);for(let[c,a]of n)t.set(c,{regions:t0(a.regions,e),lines:s0(a.lines,e,"outside")});return t}function Ar(n,e,t,c=[]){if(!n.some(l=>l.slots||l.bores))return;let a=new Map,r=l=>{let h=a.get(l);return h||(h=G([...l.layers].filter(([f])=>e(f)==="cut").flatMap(([,f])=>f.regions)),a.set(l,h)),h},s=l=>(l.placements??[]).flatMap(h=>w3({name:l.name,copy:0,placed:!0,matrix:o0(h),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends},...l.folds&&{folds:l.folds}}).map(f=>({matrix:f.matrix,thickness:f.thickness,outline:f.outline}))),i=new Map,o=new Map;for(let l of n){if(!l.slots&&!l.bores)continue;if(!l.placements){t.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=te(M?x.slice(1):x),k=c.filter(S=>w(S.label??"")||w(S.kind));!k.length&&!M&&t.push(`Part "${l.name}": no hardware "${x}" to bore for.`);for(let S of k)M?h.splice(0,h.length,...h.filter(A=>A!==S)):h.includes(S)||h.push(S)}let f=!1,u=new Set;for(let x of l.slots??[]){let M=x.startsWith("!"),w=te(M?x.slice(1):x),k=n.filter(S=>S!==l&&w(S.name));!k.length&&!M&&t.push(`Part "${l.name}": no part "${x}" to cut slots for.`);for(let S of k)M?u.delete(S):u.add(S)}let d=new Map,m=[...u].flatMap(x=>s(x).map(M=>(d.set(M,x.name),M))),p=new Set,g=(l.placements??[]).map(x=>G(w3({name:l.name,copy:0,placed:!0,matrix:o0(x),thickness:l.thickness,outline:r(l),...l.bends&&{bends:l.bends},...l.folds&&{folds:l.folds}}).flatMap(M=>{let w=[];if(l.slots){let k=m.map(A=>et(M,[A],0));for(let A=0;A<k.length;A++)for(let z=A+1;z<k.length;z++){let[L,P]=[d.get(m[A]),d.get(m[z])];if(!k[A].length||!k[z].length||L===P||!L||!P)continue;let I=b1(k[A],k[z]);if(I.reduce((T,O)=>T+Math.abs(s1(O)),0)>.01){let T=I.flat().map(U=>U[0]),O=I.flat().map(U=>U[1]),[F,D,_,R]=[Math.min(...T),Math.min(...O),Math.max(...T),Math.max(...O)];p.add(`Tabs of "${L}" and "${P}" meet in the same slot in "${l.name}", at [${T1(F)}, ${T1(D)}] to [${T1(_)}, ${T1(R)}] in its coordinates. Move one's tabs along the edge.`)}}let S=k.flat();w=S.length?Lr(L1(G(S),(l.clearance??.1)/2,"miter"),l.slotExtra):[]}for(let k of h){let S=c6(M,k,l.fit??k3.turn);S&&b1([S],M.outline).some(A=>Math.abs(s1(A))>1e-4)&&(w.push(S),f=!0)}return l.bends?b1(w,L1(M.outline,1,"miter")):w}))),v=(x,M)=>n4(x,M).reduce((w,k)=>w+Math.abs(s1(k)),0)>.001,b=l.stack??1;if(b>1){let x=w=>g.filter((k,S)=>S%b===w),M=Array.from({length:b},(w,k)=>G(x(k).flat()));if(M.slice(1).some(w=>v(M[0],w))){Array.from({length:b},(w,k)=>x(k)).some(w=>w.slice(1).some(k=>v(w[0],k)))&&t.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}}g.slice(1).some(x=>v(g[0],x))&&t.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 p)t.push(x);l.bores&&h.length&&!f&&t.push(`Part "${l.name}": none of ${l.bores.map(x=>`"${x}"`).join(", ")} pass through it, so it has no bores.`);let y=G(g.flat());if(!y.length){l.slots?.length&&!l.slots.some(x=>x.includes("*"))&&t.push(`Part "${l.name}": none of ${l.slots.map(x=>`"${x}"`).join(", ")} pass through it, so it has no slots.`);continue}i.set(l,y)}for(let[l,h]of i)l.layers=ne(l.layers,h);for(let[l,h]of o){let f=h.length,u=h.map((d,m)=>({...l,name:`${l.name}, layer ${m+1}`,qty:l.qty/f,layers:d.length?ne(l.layers,d):l.layers,placements:l.placements.filter((p,g)=>g%f===m),stack:void 0,layerOf:{part:l.layerOf?.part??l,k:m}}));n.splice(n.indexOf(l),1,...u)}}function Sr(n,e,t){if(!n.some(i=>i.halving))return;let c=i=>G([...i.layers].filter(([o])=>e(o)==="cut").flatMap(([,o])=>o.regions)),a=i=>{let o=c(i);return(i.placements??[]).map(l=>({matrix:o0(l),thickness:i.thickness,outline:o}))},r=new Map,s=(i,o,l)=>{let h=r.get(i)??(i.placements??[]).map(()=>[]);h[o].push(...l),r.set(i,h)};for(let i of n){if(!i.halving)continue;if(!i.placements){t.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 u of i.halving){let d=u.startsWith("!"),m=te(d?u.slice(1):u),p=n.filter(g=>g!==i&&(m(g.name)||g.layerOf&&m(g.layerOf.part.name)));!p.length&&!d&&t.push(`Part "${i.name}": no part "${u}" to halve with.`);for(let g of p)d?o.delete(g):o.add(g)}let l=0,h=0,f=a(i);for(let u of o){if(i.bends||u.bends){t.push(`Parts "${i.name}" and "${u.name}": halving joints can't go in a bent part.`);continue}if(!u.placements)continue;let d=a(u);f.forEach((m,p)=>d.forEach((g,v)=>{let b=rt(m,g,i.clearance??.1);h+=b.thin,b.a.length&&(l++,s(i,p,b.a),s(u,v,b.b))}))}h&&t.push(`Part "${i.name}": ${h} crossing${h===1?"":"s"} too narrow to halve, left whole.`),!l&&o.size&&!i.halving.some(u=>u.includes("*"))&&t.push(`Part "${i.name}" crosses none of ${i.halving.map(u=>`"${u}"`).join(", ")}, so it has no halving slots.`)}for(let[i,o]of r){let l=o.map(h=>G(h));l.slice(1).some(h=>n4(l[0],h).reduce((f,u)=>f+Math.abs(s1(u)),0)>.001)&&t.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=ne(i.layers,G(l.flat()))}}function Cr(n,e,t){let c=new Set;for(let a of n){if(a.on===void 0||!a.placements?.length)continue;let r=a.on,s=n.filter(p=>p.name===r&&p.placements?.length).flatMap(p=>p.placements.map((g,v)=>({q:p,m:o0(g),copy:a3(p,v)}))),i=n.filter(p=>p.name===a.name&&p.on===r).reduce((p,g)=>p+(g.placements?.length??0),0);if(!s.length){c.has(r)||t.push(`Part "${a.name}" is on "${r}", which is not a placed part.`),c.add(r);continue}let[o,l,h,f]=[1/0,1/0,-1/0,-1/0];for(let[p,g]of a.layers)if(e(p)==="cut")for(let v of g.regions)for(let[b,y]of v)o=Math.min(o,b),l=Math.min(l,y),h=Math.max(h,b),f=Math.max(f,y);if(!(h>=o))continue;let[u,d,m]=[(o+h)/2,(l+f)/2,a.thickness/2];a.placements=a.placements.map((p,g)=>{let v=a3(a,g),b=s.length===i&&s.find(S=>S.copy===v)||s[0];if(!b.q.bends?.length)return p;let y=o0(p),x=[y[0]*u+y[1]*d+y[2]*m+y[3],y[4]*u+y[5]*d+y[6]*m+y[7],y[8]*u+y[9]*d+y[10]*m+y[11]],M=l2(b.m),w=M[0]*x[0]+M[1]*x[1]+M[2]*x[2]+M[3],k=l4(b.q.bends,b.q.thickness)[e6(b.q.bends,w)];return{...p,matrix:q1(b.m,q1(k,q1(M,y)))}})}}function Pr(n,e,t){var l;let c=[],a=h=>{let f=[];for(let[u,d]of h.layers)if(t(u))for(let m of d.regions)s1(m)<0&&f.push([...m].reverse());return f.length?L1(G(f),-e,"miter"):[]},r=(h,f,u)=>{let d=0;for(let m of h)for(let p=0,g=m.length-1;p<m.length;g=p++){let[v,b]=m[g],[y,x]=m[p];b<=u?x>u&&(y-v)*(u-b)-(f-v)*(x-b)>0&&d++:x<=u&&(y-v)*(u-b)-(f-v)*(x-b)<0&&d--}return d!==0},s=h=>{let f=[];for(let[u,d]of h.layers)if(t(u))for(let m of d.regions)s1(m)>0&&f.push(m);return G(f)},i=(h,f)=>{let{w:u,h:d}=f,m=s(f),p=[];for(let g of m)for(let v=0;v<g.length;v+=Math.max(1,Math.floor(g.length/12)))p.push(g[v]);for(let g of h){if(s1(g)<=0)continue;let[v,b,y,x]=[1/0,1/0,-1/0,-1/0];for(let[w,k]of g)v=Math.min(v,w),b=Math.min(b,k),y=Math.max(y,w),x=Math.max(x,k);if(y-v<u||x-b<d)continue;let M=Math.max(.5,Math.min(u,d,y-v-u+1,x-b-d+1)/4);for(let w=b;w<=x-d+1e-9;w+=M)for(let k=v;k<=y-u+1e-9;k+=M){if(!p.every(([A,z])=>r(h,A+k,z+w)))continue;let S=m.map(A=>A.map(([z,L])=>[z+k,L+w]));if(t0(S,h).reduce((A,z)=>A+Math.abs(s1(z)),0)<.01)return[k,w]}}},o=[];for(let h of n){let f=!1;for(let d of h.inner?.length?[]:c){let m=i(d.region,h);if(!m)continue;let[p,g]=m;((l=d.host).inner??(l.inner=[])).push({item:h,dx:d.ox+p,dy:d.oy+g}),d.region=t0(d.region,L1(s(h).map(b=>b.map(([y,x])=>[y+p,x+g])),e,"miter"));let v=a(h);v.length&&c.push({host:d.host,ox:d.ox+p,oy:d.oy+g,region:v}),f=!0;break}if(f)continue;o.push(h);let u=a(h);u.length&&c.push({host:h,ox:0,oy:0,region:u})}return o}function Er(n,e,t,c){let a=new Map;for(let i of n)a.set(i.info,[...a.get(i.info)??[],i]);let r=[],s=(i,o)=>k2({layers:i,parts:[]},o).layers;for(let[,i]of a){let o=i[0],l=G([...o.layers].filter(([d])=>t(d)).flatMap(([,d])=>d.regions.filter(m=>s1(m)>0))),h=l.reduce((d,m)=>d+s1(m),0)/(o.w*o.h),f=i.length>=2&&l.length&&h<.75?Tr(l,o.w,o.h,e,c):void 0;if(!f){r.push(...i);continue}let u=s(o.layers,[-1,0,0,-1,o.w,o.h]);for(let d=0;d<i.length;d+=f.n){let m=i.slice(d,d+f.n);if(m.length===1){r.push(m[0]);continue}let p=f.at.slice(0,m.length),g=Math.min(...p.map(x=>x[0])),v=Math.min(...p.map(x=>x[1])),b=Math.max(...p.map(x=>x[0]+o.w))-g,y=Math.max(...p.map(x=>x[1]+o.h))-v;r.push({...m[0],layers:s(m[0].layers,[1,0,0,1,p[0][0]-g,p[0][1]-v]),w:b,h:y,inner:m.slice(1).map((x,M)=>({item:{...x,layers:(M+1)%2?u:x.layers},dx:p[M+1][0]-g,dy:p[M+1][1]-v}))})}}return r}function Tr(n,e,t,c,a){let s=L1(n.map(y=>Ir(y,.25)).filter(y=>y.length>=3),.25,"miter"),i=L1(s,c,"miter"),o=s.map(y=>y.map(([x,M])=>[e-x,t-M])),l=(y,[x,M])=>y.map(w=>w.map(([k,S])=>[k+x,S+M])),h=(y,x)=>!b1(y,x).some(M=>Math.abs(s1(M))>.001),f=(y,x,M,w)=>{let[k,S]=[0,w];if(h(y,l(x,M(S)))){if(h(y,l(x,M(k))))return M(k);for(let A=0;A<10;A++){let z=(k+S)/2;h(y,l(x,M(z)))?S=z:k=z}return M(S)}},u;for(let y of[!1,!0])for(let x=-10;x<=10;x++){let M=x/10*(y?e:t),w=f(i,o,A=>y?[M,A]:[A,M],(y?t:e)+c);if(!w)continue;let k=Math.max(e,w[0]+e)-Math.min(0,w[0]),S=Math.max(t,w[1]+t)-Math.min(0,w[1]);k>a[0]||S>a[1]||k*S<.85*2*e*t&&(!u||k*S<u.area)&&(u={d:w,across:y,area:k*S})}if(!u)return;let{d,across:m}=u,p=G([...i,...L1(l(o,d),c,"miter")]),v=f(p,s,y=>m?[0,y]:[y,0],2*((m?t:e)+c)+Math.abs(m?d[1]:d[0])),b=[[0,0],[d[0],d[1]]];if(v){let y=x=>Math.max(...x.map(M=>M[0]+e))-Math.min(...x.map(M=>M[0]))<=a[0]&&Math.max(...x.map(M=>M[1]+t))-Math.min(...x.map(M=>M[1]))<=a[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(!y([...b,w]))break;let k=l(x%2?o:s,w),S=G(b.slice(Math.max(0,b.length-3)).map((A,z,L)=>{let P=b.length-L.length+z;return L1(l(P%2?o:s,A),c,"miter")}).flat());if(!h(S,k))break;b.push(w)}}return{at:b,n:b.length}}function Ir(n,e){if(n.length<8)return n;let t=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,f]=l.pop(),[u,d]=i[h],[m,p]=i[f],g=Math.hypot(m-u,p-d),v=-1,b=-1;for(let y=h+1;y<f;y++){let[x,M]=i[y],w=g?Math.abs((m-u)*(d-M)-(u-x)*(p-d))/g:Math.hypot(x-u,M-d);w>v&&([v,b]=[w,y])}v>e&&(o[b]=1,l.push([h,b],[b,f]))}return i.filter((h,f)=>o[f])},c=i=>Math.hypot(i[0]-n[0][0],i[1]-n[0][1]),a=1;for(let i=2;i<n.length;i++)c(n[i])>c(n[a])&&(a=i);let r=t(n.slice(0,a+1)),s=t([...n.slice(a),n[0]]);return[...r,...s.slice(1,-1)]}function a3(n,e){if(!n.copies)return e+1;let t=n.stack??1;return(n.copies[Math.floor(e/t)]-1)*t+e%t+1}function Hr(n,e,t){let c=[...t.keys()],a=[...e.keys()].filter(i=>t.get(i)?.mode==="fill"&&e.get(i).regions.length&&!["score","cut","guide"].includes(i)),r=[];if(a.length<2)return r;let s=i=>i==="engrave"?-1/0:(t.get(i)?.order??0)*2+c.indexOf(i)/c.length;a.sort((i,o)=>s(i)-s(o));for(let i=0;i<a.length-1;i++){let o=t.get(a[i]).side??"front",l=a.slice(i+1).filter(f=>(t.get(f).side??"front")===o);if(!l.length)continue;let h;for(let f of i0(e.get(a[i]).regions)){let u=f.reduce((M,w)=>M+s1(w),0);if(!(u>.001)||!L1(f,-.5,"round").length)continue;let d=f;for(let M of l)d.length&&(d=t0(d,e.get(M).regions));if(d.reduce((M,w)=>M+s1(w),0)>.001*Math.max(1,u))continue;let p=l.filter(M=>b1(f,e.get(M).regions).length),g=p.length?p:l;if(h){h.count++;for(let M of g)h.under.includes(M)||h.under.push(M);continue}let[v,b,y,x]=L0(new Map([["f",{regions:f,lines:[]}]]));h={part:n,layer:a[i],under:g,count:1,at:[T1((v+y)/2),T1((b+x)/2)]}}h&&r.push(h)}return r}function Vr(n,e){for(let t of n.slice(0,5)){let c=t.under.map(r=>`"${r}"`),a=c.length>1?`${c.slice(0,-1).join(", ")} and ${c.at(-1)}`:c[0];e.push(`Part "${t.part}": ${t.count>1?`${t.count} fills`:"a fill"} on layer "${t.layer}" (${t.count>1?"the first ":""}at [${t.at.join(", ")}]) ${t.count>1?"lie":"lies"} wholly under ${a}, stacked above it in the files: printed, ${t.count>1?"they":"it"} won't show, and engraved, ${t.count>1?"they burn":"it burns"} twice. Draw them in one paint(), or give "${t.layer}" a higher order.`)}if(n.length>5){let t=n.slice(5),c=new Set(t.map(r=>r.part)).size,a=[...new Set(t.map(r=>`"${r.layer}"`))];e.push(`Fills are hidden the same way in ${t.length} more place${t.length>1?"s":""}, on ${c} part${c>1?"s":""} (layer${a.length>1?"s":""} ${a.slice(0,5).join(", ")}${a.length>5?" and more":""}).`)}}function ut(n,e,t,c){let a=n.stack??1,s=(n.placements?.length??0)/a===c?t:0,i=n.glue?.face==="bottom",o=e.glue?.face==="top";return s*a+(o!==i?a-1:0)}function Or(n,e){let t=new Set,c=(a,r)=>{if(!a.glue||t.has(a))return;if(r.includes(a)){e.push(`Part "${a.name}" is glued in a loop of parts; it is left where it is.`),t.add(a);return}let s=n.find(h=>h.name===a.glue.host&&h!==a);if(!s?.placements){e.push(`Part "${a.name}" is glued to "${a.glue.host}", which is not a placed part.`),t.add(a);return}c(s,[...r,a]);let i=s.placements.map(o0),o=a.glue.face==="top"?s.thickness:-a.thickness,l=a.placements.length/(a.stack??1);a.placements=a.placements.map((h,f)=>{let u=i[ut(s,a,Math.floor(f/(a.stack??1)),l)];return{...h,matrix:q1(u,q1(I0(0,0,o),o0(h)))}}),t.add(a)};for(let a of n)c(a,[])}function Fr(n,e,t,c){let a=0,r=50;for(let p=0;p<14;p++){let g=(a+r)/2;L1(n,-g,"round").length?a=g:r=g}if(a<1)return[];let s=L1(n,-a*.98,"round"),i=L0(new Map([["cut",{regions:s,lines:[]}]]));if(!i)return[];let[o,l]=[(i[0]+i[2])/2,(i[1]+i[3])/2];((p,g)=>s.reduce((v,b)=>v+(ce(b,p,g)?s1(b)>0?1:-1:0),0)>0)(o,l)||([o,l]=s.reduce((p,g)=>s1(g)>s1(p)?g:p)[0]);let f=Math.min(6,Math.max(2,a*.9)),u=Q2(t,e,{size:f,font:c,halign:"center",valign:"center",spacing:1}),d=L0(new Map([["t",{regions:u,lines:[]}]])),m=d?Math.min(1,1.6*a/Math.max(d[2]-d[0],1e-9)):1;return u.map(p=>p.map(([g,v])=>[o-g*m,l+v*m]).reverse())}function ce(n,e,t){let c=!1;for(let a=0,r=n.length-1;a<n.length;r=a++){let[s,i]=n[a],[o,l]=n[r];i>t!=l>t&&e<(o-s)*(t-i)/(l-i)+s&&(c=!c)}return c}var bt=new WeakMap,ae=new WeakSet,yt=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]),xt={$thickness:{value:"3",doc:"Material thickness, used by joinery and stored on parts"},$kerf:{value:"0",doc:"Beam width; cut outlines are offset by half of it"},$material:{value:'"material"',doc:"Material name; parts are packed per material and thickness"},$sheet:{value:"[600, 400]",doc:"Sheet size for packing"},$gap:{value:"3",doc:"Space between packed parts and around the sheet edge"},$layout:{value:'"pack"',doc:'`"pack"` packs parts onto sheets, `"none"` keeps your placement'},$fn:{value:"0",doc:"Segments in a full circle; 0 uses `$fa` and `$fs`"},$fa:{value:"2",doc:"Largest angle of a curve segment, in degrees"},$fs:{value:"0.2",doc:"Largest length of a curve segment, in mm"},$font:{doc:"Default font name for `text()`"},$children:{doc:"How many child statements the module was called with"},$scale:{value:"1",doc:"The model's scale: `140cm` is 1400 mm divided by `$scale`"},$nest:{value:"false",doc:"Pack small parts into the holes of bigger ones"},$registration:{value:"false",doc:"Print-and-cut marks in three corners of every sheet"},$label_parts:{value:"false",doc:"Engrave each part's number on its back face, the same number as in the parts list and the steps"},$min_width:{value:"1.5",doc:"Warn where a part's material is narrower than this; `0` turns it off"},$join_lines:{value:"false",doc:"Join lines that meet end to end into one and order them nearest first, so the laser travels less between them"},$mirrored:{doc:"True inside a mirrored part and on the back face, so `text()` reads right"},$bounds:{doc:"Set by `measure()` for the children after the one it measures"},$area:{doc:"Set by `measure()`: the area of material the measured child cuts, holes taken out, in square millimetres"},$centroid:{doc:"Set by `measure()`: the measured child's balance point `[x, y]`, the centroid of its material"},PI:{value:"3.141592653589793",doc:"\u03C0, half a turn in radians"}},_r=["true","false","undef"],Dr="https://kerfscript.mylasertools.com/docs/reference/",Rr=n=>n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),r3=(n,e)=>Object.prototype.hasOwnProperty.call(n,e)?n[e]:void 0;function ft(n){let t=n.split(`
|
|
3026
4257
|
`).slice(0,8).join(`
|
|
3027
|
-
`);return t.length>400&&(t=t.slice(0,400)),t.length<n.length?t+" \u2026":t}var
|
|
3028
|
-
`):void 0}valueAfter(e){let t=this.tokenAt.get(e);if(t===void 0||this.tokens[t+1]?.value!=="=")return;let c=0,a=t+2;for(;a<this.tokens.length;a++){let r=this.tokens[a];if(r.type==="eof")break;if(r.type==="punct"){if(r.value==="("||r.value==="["||r.value==="{")c++;else if(r.value===")"||r.value==="]"||r.value==="}"){if(!c)break;c--}else if((r.value===","||r.value===";")&&!c)break}}if(a!==t+2)return
|
|
3029
|
-
`).length;e=
|
|
3030
|
-
`+i+";",t=!0;continue}}let s=
|
|
3031
|
-
`).length;function
|
|
4258
|
+
`);return t.length>400&&(t=t.slice(0,400)),t.length<n.length?t+" \u2026":t}var V5=class{constructor(e,t,c,a,r){this.src=e;this.tokens=t;this.comments=c;this.file=a;this.load=r;this.definitions=[];this.references=[];this.scopes=[];this.libraries=[];this.seq=0;this.order=new Map;this.pending=[];this.stmtDefs=new Map;this.tokenAt=new Map;t.forEach((s,i)=>this.tokenAt.set(s.pos.offset,i))}run(e){let t=this.scope(void 0,0,this.src.length);this.block(e,t);for(let c of this.pending)this.resolve(c);return t}scope(e,t,c){let a={start:t,end:c,parent:e,vars:new Map,fns:new Map,mods:new Map};return this.scopes.push(a),a}define(e,t,c){let a=e[t].get(c.name);a?a.push(c):e[t].set(c.name,[c]),this.order.set(c,this.seq++),c.file===this.file&&(this.definitions.push(c),bt.set(c,{scope:e,ns:t}))}def(e,t,c,a){return{name:t,kind:e,start:c.offset,end:c.offset+t.length,range:a,...this.file!==void 0&&{file:this.file}}}ref(e,t,c,a,r,s){let i={name:e,start:t.offset,end:t.offset+e.length};return this.references.push(i),this.pending.push({ref:i,scope:c,ns:a,builtin:r,callee:s,seq:this.seq++}),i}find(e,t,c,a){for(let r=e;r;r=r.parent){let s=r[t].get(c);if(!s)continue;if(t!=="vars")return s[s.length-1];let i=s.filter(o=>this.order.get(o)<a);if(i.length)return i[i.length-1]}if(t==="vars")for(let r=e;r;r=r.parent){let s=r.vars.get(c);if(s)return s[s.length-1]}}resolve(e){let{ref:t}=e;if(e.callee){let a=e.callee.def?.params,r=e.callee.builtin,s=a?.find(i=>i.name===t.name);s?t.def=s:r?.params.some(i=>i.name===t.name)&&(t.builtin=r,t.arg=t.name);return}for(let a of e.ns){let r=this.find(e.scope,a,t.name,e.seq);if(r){t.def=r;return}}let c=e.builtin&&j2(t.name);c&&(c.kind===e.builtin||c.kind==="both")&&(t.builtin=c)}docAbove(e){let t=[],c=e-1;for(let a=this.comments.length-1;a>=0;a--){let r=this.comments[a];if(r.line>c)continue;let s=r.line+(this.src.slice(r.start,r.end).match(/\n/g)?.length??0);if(!r.own||s!==c||/^\[[^\]]*\]$/.test(r.text))break;t.unshift(r.block?r.text.replace(/^[ \t]*\* ?/gm,""):r.text),c=r.line-1}return t.length?t.join(`
|
|
4259
|
+
`):void 0}valueAfter(e){let t=this.tokenAt.get(e);if(t===void 0||this.tokens[t+1]?.value!=="=")return;let c=0,a=t+2;for(;a<this.tokens.length;a++){let r=this.tokens[a];if(r.type==="eof")break;if(r.type==="punct"){if(r.value==="("||r.value==="["||r.value==="{")c++;else if(r.value===")"||r.value==="]"||r.value==="}"){if(!c)break;c--}else if((r.value===","||r.value===";")&&!c)break}}if(a!==t+2)return ft(this.src.slice(this.tokens[t+2].pos.offset,this.tokens[a-1].end))}end(e){return e.end??e.pos.offset}block(e,t){for(let c of e)if(c.kind==="module"||c.kind==="function"){let a=this.def(c.kind,c.name,c.namePos??c.pos,[c.pos.offset,this.end(c)]),r=this.docAbove(c.pos.line);r&&(a.doc=r),ae.add(a),this.stmtDefs.set(c,a),this.define(t,c.kind==="module"?"mods":"fns",a)}else c.kind==="use"&&!c.include&&this.library(c,t);for(let c of e)this.stmt(c,t)}inner(e,t){return this.scope(e,t.pos.offset,this.end(t))}stmt(e,t){switch(e.kind){case"assign":{this.expr(e.value,t);let c=this.def("variable",e.name,e.pos,[e.pos.offset,this.end(e)]);c.value=ft(this.src.slice(e.span[0],e.span[1]));let a=this.docAbove(e.pos.line);a&&(c.doc=a),ae.add(c),this.define(t,"vars",c);return}case"module":{let c=this.inner(t,e),a=this.stmtDefs.get(e);a.params=this.params(e.params,c,a),this.block(e.body,c);return}case"function":{let c=this.inner(t,e),a=this.stmtDefs.get(e);a.params=this.params(e.params,c,a),this.expr(e.body,c);return}case"use":e.include&&this.library(e,t);return;case"call":{let c=this.ref(e.name,e.pos,t,["mods"],"module");this.args(e.args,t,c),e.children.length&&this.block(e.children,this.inner(t,e));return}case"for":case"let":{let c=this.inner(t,e);this.assigns(e.assigns,c),this.block(e.body,c);return}case"if":this.expr(e.cond,t),this.block(e.then,this.inner(t,e)),this.block(e.else,this.inner(t,e));return;case"block":this.block(e.body,this.inner(t,e));return}}library(e,t){let c=this.tokenAt.get(e.pos.offset),a=c===void 0?void 0:this.tokens[c+1],r=this.load(e.path);if(a?.type==="str"&&this.libraries.push({path:e.path,include:e.include,start:a.pos.offset,end:a.end,found:!!r}),!!r){for(let s of r.mods)this.define(t,"mods",s);for(let s of r.fns)this.define(t,"fns",s);if(e.include)for(let s of r.vars)this.define(t,"vars",s)}}params(e,t,c){let a=e.map(r=>{let s=r.pos??{line:0,col:0,offset:c?.range[0]??0},i=this.def("parameter",r.name,s,[s.offset,s.offset+r.name.length]);if(r.default&&r.pos){let o=this.valueAfter(r.pos.offset);o!==void 0&&(i.value=o)}return c&&(i.owner=c),this.define(t,"vars",i),i});for(let r of e)r.default&&this.expr(r.default,t);return a}assigns(e,t){for(let c of e){this.expr(c.value,t);let a=this.def("variable",c.name,c.pos,[c.pos.offset,c.pos.offset+c.name.length]),r=this.valueAfter(c.pos.offset);r!==void 0&&(a.value=r),this.define(t,"vars",a)}}args(e,t,c){for(let a of e)a.name&&a.pos&&this.ref(a.name,a.pos,t,[],void 0,c),this.expr(a.value,t)}expr(e,t){switch(e.kind){case"var":this.ref(e.name,e.pos,t,["vars"]);return;case"list":for(let c of e.items)this.item(c,t);return;case"range":this.expr(e.start,t),e.step&&this.expr(e.step,t),this.expr(e.end,t);return;case"unary":this.expr(e.arg,t);return;case"binary":this.expr(e.left,t),this.expr(e.right,t);return;case"ternary":this.expr(e.cond,t),this.expr(e.then,t),this.expr(e.else,t);return;case"index":this.expr(e.target,t),this.expr(e.index,t);return;case"member":this.expr(e.target,t);return;case"record":for(let c of e.fields)this.expr(c.value,t);return;case"call":{let c;e.callee.kind==="var"?c=this.ref(e.callee.name,e.callee.pos,t,["vars","fns"],"function"):this.expr(e.callee,t),this.args(e.args,t,c);return}case"lambda":{let c=this.inner(t,e);this.params(e.params,c),this.expr(e.body,c);return}case"let":{let c=this.inner(t,e);this.assigns(e.assigns,c),this.expr(e.body,c);return}case"chain":this.expr(e.check,t),this.expr(e.body,t);return}}item(e,t){switch(e.kind){case"item":case"each":this.expr(e.expr,t);return;case"if":this.expr(e.cond,t),this.item(e.then,t),e.else&&this.item(e.else,t);return;case"for":case"let":{let c=e.pos?this.scope(t,e.pos.offset,e.end??e.pos.offset):t;this.assigns(e.assigns,c),this.item(e.body,c);return}}}};function Mt(n){let e=n,t=!1;for(let c=0;c<12;c++)try{let{tokens:a,comments:r}=B2(e),{program:s}=K0(e);return{text:e,tokens:a,comments:r,body:s.body,parsed:c===0}}catch(a){if(!(a instanceof X)||a.line===void 0)return;if(a.reason==="Unclosed block comment"){e+="*/";continue}let r=/found end of file$/.test(a.reason);if(t&&(r||a.line>dt(n))){e=e.slice(0,n.length),t=!1;let i=e.trimEnd().split(`
|
|
4260
|
+
`).length;e=pt(e,i);continue}if(r){let i=qr(e);if(i){e+=`
|
|
4261
|
+
`+i+";",t=!0;continue}}let s=pt(e,Math.min(a.line,dt(e)));if(s===e)return;e=s}}var dt=n=>n.split(`
|
|
4262
|
+
`).length;function pt(n,e){let t=0;for(let a=1;a<e;a++)t=n.indexOf(`
|
|
3032
4263
|
`,t)+1;let c=n.indexOf(`
|
|
3033
|
-
`,t);return c<0&&(c=n.length),n.slice(0,t)+n.slice(t,c).replace(/\S/g," ")+n.slice(c)}function
|
|
4264
|
+
`,t);return c<0&&(c=n.length),n.slice(0,t)+n.slice(t,c).replace(/\S/g," ")+n.slice(c)}function qr(n){let e;try{e=B2(n).tokens}catch{return""}let t=[];for(let c of e)c.type==="punct"&&(c.value==="("||c.value==="["||c.value==="{"?t.push(c.value):(c.value===")"||c.value==="]"||c.value==="}")&&t.pop());return t.reverse().map(c=>c==="("?")":c==="["?"]":";}").join("")}var mt=new Map;function wt(n,e){return t=>{let c=K4(e[e.length-1],t),a=c!==void 0&&r3(J0,t)===void 0?n?.(c):void 0,r=typeof a=="string"?c:t;if(e.includes(r))return;let s=r3(J0,r),i=s??(typeof a=="string"?a:n?.(r));if(typeof i!="string")return;let o=s!==void 0?mt.get(r):void 0;if(o)return o;let l=Mt(i),h={mods:[],fns:[],vars:[]};if(l){let u=new V5(l.text,l.tokens,l.comments,r,wt(n,[...e,r])).run(l.body),d=m=>[...m.values()].map(p=>p[p.length-1]);h.mods=d(u.mods),h.fns=d(u.fns),h.vars=d(u.vars)}return s!==void 0&&mt.set(r,h),h}}function rl(n,e={}){let t=Mt(n),c=[...Object.keys(J0),...e.libraries??[]];if(!t){let s={start:0,end:n.length,vars:new Map,fns:new Map,mods:new Map};return{source:n,parsed:!1,definitions:[],references:[],scopes:[s],libraries:[],available:c,settings:[]}}let a=new V5(t.text,t.tokens,t.comments,void 0,wt(e.resolve,[]));a.run(t.body);let r=[];if(t.parsed)try{r=E5(n).parameters}catch{}return{source:n,parsed:t.parsed,definitions:a.definitions,references:a.references,scopes:a.scopes,libraries:a.libraries,available:c,settings:r}}function re(n,e){let t=[...n.references,...n.definitions].filter(c=>c.start<=e&&e<=c.end);return t.find(c=>e<c.end)??t[0]}var O5=n=>"kind"in n;function $r(n,e){let t=re(n,e);if(t)return O5(t)?t:t.def}function Ur(n,e,t=!0){let c=$r(n,e);if(!c)return[];let a=bt.get(c),r=new Set(a?a.scope[a.ns].get(c.name):[c]),s=[];if(t)for(let i of r)i.file===void 0&&n.definitions.includes(i)&&s.push({start:i.start,end:i.end,definition:!0});for(let i of n.references)i.def&&r.has(i.def)&&s.push({start:i.start,end:i.end,definition:!1});return s.sort((i,o)=>i.start-o.start)}function Nr(n,e){let t=re(n,e),c=t&&(O5(t)?t:t.def);return!t||!c?t&&!O5(t)&&t.builtin?{error:`${t.name} is built in`}:{error:"There is no name here that the program defines"}:c.file!==void 0?{error:`${c.name} is defined in <${c.file}>`}:{start:t.start,end:t.end,name:t.name}}function sl(n,e,t){let c=Nr(n,e);return"error"in c?c:!/^\$?[A-Za-z_][A-Za-z0-9_]*$/.test(t)||yt.has(t)?{error:`"${t}" is not a name`}:t.startsWith("$")!==c.name.startsWith("$")?{error:"Names with $ are special variables, seen by every module called, so $ stays or goes"}:Ur(n,e).map(({start:a,end:r})=>({start:a,end:r}))}function se(n){let e=(n.params??[]).map(t=>t.value?`${t.name} = ${t.value}`:t.name);return`${n.kind} ${n.name}(${e.join(", ")})`}var q3=n=>"```kerfscript\n"+n+"\n```";function Br(n){let e=["Setting"];return n.group&&(e[0]+=` in **${n.group}**`),n.options?e.push(n.options.map(t=>`\`${t.name}\``).join(", ")):n.min!==void 0&&n.max!==void 0&&e.push(`${n.min} to ${n.max}${n.step!==void 0?`, in steps of ${n.step}`:""}`),e.join(": ")}function gt(n,e){let t=[];e.kind==="module"||e.kind==="function"?t.push(q3(se(e))):t.push(q3(e.value!==void 0?`${e.name} = ${e.value}`:e.name)),e.kind==="parameter"&&t.push(e.owner?`Parameter of ${e.owner.kind} \`${e.owner.name}()\``:"Parameter of a function"),e.doc&&t.push(e.doc);let c=e.file===void 0&&n.settings.find(a=>a.name===e.name&&a.span[0]>=e.start);return c&&e.kind==="variable"&&t.push(Br(c)),e.file!==void 0&&t.push(`From \`<${e.file}>\``),t.join(`
|
|
3034
4265
|
|
|
3035
|
-
`)}function
|
|
4266
|
+
`)}function Gr(n,e){let t=`[Reference](${Dr}#${Rr(n.section)})`;if(e){let r=n.params.find(s=>s.name===e);return[q3(r.default!==void 0?`${r.name} = ${r.default}`:r.name),`Parameter of \`${n.name}()\`${r.doc?`: ${r.doc}`:""}`].join(`
|
|
3036
4267
|
|
|
3037
|
-
`)}let c=[
|
|
4268
|
+
`)}let c=[f5(n),...n.forms??[]],a=n.params.filter(r=>r.doc).map(r=>`- \`${r.name}\`: ${r.doc}${r.named?" (by name only)":""}`);return[q3(c.join(`
|
|
3038
4269
|
`)),n.doc,a.join(`
|
|
3039
4270
|
`),t].filter(Boolean).join(`
|
|
3040
4271
|
|
|
3041
|
-
`)}function
|
|
4272
|
+
`)}function zt(n){let e=[];for(let t of n.split(`
|
|
3042
4273
|
`)){let c=/^\s*\/\/\s?(.*)$/.exec(t);if(!c)break;/copyright|spdx/i.test(c[1])||e.push(c[1])}return e.join(`
|
|
3043
|
-
`).trim()}function
|
|
4274
|
+
`).trim()}function il(n,e,t={}){let c=n.libraries.find(i=>i.start<=e&&e<=i.end);if(c){let i=r3(J0,c.path)??t.resolve?.(c.path),o=r3(J0,c.path)?"Standard library":"Library",l=i===void 0?`Library <${c.path}> not found`:zt(i)||o;return{start:c.start,end:c.end,text:l}}let a=re(n,e);if(!a)return;let r={start:a.start,end:a.end};if(O5(a))return{...r,text:gt(n,a)};if(a.def)return{...r,text:gt(n,a.def)};if(a.builtin)return{...r,text:Gr(a.builtin,a.arg)};let s=r3(xt,a.name);if(s)return{...r,text:[q3(s.value!==void 0?`${a.name} = ${s.value}`:a.name),s.doc].join(`
|
|
3044
4275
|
|
|
3045
|
-
`)}}function
|
|
3046
|
-
`,e-1)+1,e),a=/\b(?:use|include)\s*<([
|
|
3047
|
-
`)[0]}`:
|
|
4276
|
+
`)}}function kt(n,e){let t=/[A-Za-z0-9_$]*$/.exec(n.slice(0,e))[0],c=e-t.length,a;try{a=B2(n.slice(0,c)).tokens.slice(0,-1)}catch{return}let r=a.length?a[a.length-1].end:0;if(/\/\/[^\n]*$/.test(n.slice(r,c)))return;let s=[],i=0;return a.forEach((o,l)=>{if(o.type!=="punct")return;let h=s[s.length-1];if(o.value==="("||o.value==="["||o.value==="{"){let f={token:o,index:l,commas:[]},u=a[l-1];if(o.value==="("&&u?.type==="id"){let d=a[l-2];u.value==="for"||u.value==="if"||u.value==="let"?f.header=!0:u.value==="function"?f.params=!0:yt.has(u.value)||(f.callee=u,d?.type==="id"&&(d.value==="module"||d.value==="function")&&(f.params=!0))}s.push(f),o.value==="{"&&(i=l+1)}else o.value===")"||o.value==="]"||o.value==="}"?(s.pop(),o.value==="}"&&(i=l+1)):o.value===","&&h?h.commas.push(l):o.value===";"&&(!h||h.token.value==="{")&&(i=l+1)}),{word:t,from:c,tokens:a,stack:s,stmtStart:i,prev:a[a.length-1]}}function Lt(n,e){let t=n.references.find(a=>a.start===e.pos.offset);if(t?.def?.params)return{def:t.def};if(t?.builtin)return{sig:t.builtin};let c=j2(e.value);return c?{sig:c}:void 0}function jr(n,e){let t=n.scopes.filter(a=>a.start<=e&&e<=a.end).sort((a,r)=>a.end-a.start-(r.end-r.start))[0],c=[];for(let a=t??n.scopes[0];a;a=a.parent)c.push(a);return c}function ol(n,e){let t=n.source,c=t.slice(t.lastIndexOf(`
|
|
4277
|
+
`,e-1)+1,e),a=/\b(?:use|include)\s*<([^<>]*)$/.exec(c);if(a){let z=[...new Set(n.available)].map(L=>({label:L,kind:"library",...r3(J0,L)!==void 0&&{detail:"Standard library",doc:zt(J0[L])}}));return{from:e-a[1].length,to:e,items:z}}let r={from:e,to:e,items:[]},s=kt(t,e);if(!s||/^\d/.test(s.word))return r;let{tokens:i,stack:o,stmtStart:l,prev:h,from:f}=s,u=z=>({from:f,to:e,items:z});if(h?.type==="punct"&&h.value===".")return u(["x","y","z"].map(z=>({label:z,kind:"property",detail:`item ${z}`})));if(h?.type==="id"&&(h.value==="module"||h.value==="function"))return r;let d=o[o.length-1],m=d&&h&&(h===d.token||h.type==="punct"&&h.value===",");if(d?.params&&m)return r;let p=[],g=new Set,v=z=>{g.has(z.kind+" "+z.label)||(g.add(z.kind+" "+z.label),p.push(z))};if(d?.callee&&m){let z=Lt(n,d.callee);if(z?.def)for(let L of z.def.params)v({label:L.name,kind:"argument",insert:`${L.name} = `,...L.value!==void 0&&{detail:`${L.name} = ${L.value}`},...L.doc&&{doc:L.doc},first:!0});if(z?.sig)for(let L of z.sig.params)v({label:L.name,kind:"argument",insert:`${L.name} = `,...L.default!==void 0&&{detail:`${L.name} = ${L.default}`},...L.doc&&{doc:L.doc},first:!0})}let b=!d||d.token.value==="{",x=i[l]?.type==="id"&&i[l+1]?.value==="="&&i.length>l+1,M=b&&!x&&(!h||h.type==="punct"&&[";","{","}",")","*","#","%","!"].includes(h.value)||h.type==="id"&&h.value==="else"),w=jr(n,f),k=z=>{let L=[],P=new Set;for(let I of w)for(let[T,O]of I[z])P.has(T)||(P.add(T),L.push(O[O.length-1]));return L},S=z=>({label:z.name,kind:z.kind,detail:z.kind==="module"||z.kind==="function"?se(z):z.value!==void 0?`${z.name} = ${z.value.split(`
|
|
4278
|
+
`)[0]}`:z.name,...(z.doc||z.file)&&{doc:[z.doc,z.file!==void 0&&`From \`<${z.file}>\``].filter(Boolean).join(`
|
|
3048
4279
|
|
|
3049
|
-
`)}}),
|
|
3050
|
-
`)[0]}`:m.name,name:m.name,doc:m.doc})):a.sig.params.map(m=>({text:m.default!==void 0?`${m.name} = ${m.default}`:m.name,name:m.name,doc:m.doc}));a.sig?.rest&&s.push({text:"...",name:"...",doc:"Any number of values"});let i=`${r}(`,o=s.map((m,p)=>{p&&(i+=", ");let
|
|
4280
|
+
`)}}),A=z=>({label:z.name,kind:M?"module":"function",detail:f5(z),doc:z.doc,builtin:!0});for(let z of k("vars"))(z.name!==s.word||z.start<f)&&v(S(z));for(let[z,L]of Object.entries(xt))v({label:z,kind:z==="PI"?"constant":"variable",detail:L.value!==void 0?`${z} = ${L.value}`:z,doc:L.doc,builtin:!0});if(M){for(let z of k("mods"))v(S(z));for(let z of u5)z.kind!=="function"&&v(A(z));for(let z of["module","function","for","if","let","use","include"])v({label:z,kind:"keyword"});h?.type==="punct"&&h.value==="}"&&v({label:"else",kind:"keyword"})}else{for(let z of k("fns"))v(S(z));for(let z of u5)z.kind!=="module"&&v(A(z));for(let z of _r)v({label:z,kind:"constant",builtin:!0});if(v({label:"let",kind:"keyword"}),v({label:"function",kind:"keyword"}),d?.token.value==="[")for(let z of["for","if","else","each"])v({label:z,kind:"keyword"})}return u(p)}function ll(n,e){let t=kt(n.source,e);if(!t)return;let c;for(let m=t.stack.length-1;m>=0;m--){let p=t.stack[m];if(p.token.value==="{"||p.params)return;if(p.callee){c=p;break}}if(!c)return;let a=Lt(n,c.callee);if(!a)return;let r=c.callee.value,s=a.def?a.def.params.map(m=>({text:m.value!==void 0?`${m.name} = ${m.value.split(`
|
|
4281
|
+
`)[0]}`:m.name,name:m.name,doc:m.doc})):a.sig.params.map(m=>({text:m.default!==void 0?`${m.name} = ${m.default}`:m.name,name:m.name,doc:m.doc}));a.sig?.rest&&s.push({text:"...",name:"...",doc:"Any number of values"});let i=`${r}(`,o=s.map((m,p)=>{p&&(i+=", ");let g=i.length;return i+=m.text,{start:g,end:i.length,...m.doc&&{doc:m.doc}}});i+=")";let l=c.commas.length,h=l?c.commas[l-1]+1:c.index+1,f=t.tokens.slice(h),u=l;f[0]?.type==="id"&&f[1]?.value==="="?u=s.findIndex(m=>m.name===f[0].value):t.tokens.slice(c.index+1).some((m,p,g)=>m.type==="id"&&g[p+1]?.value==="="&&(p===0||g[p-1].value===","))&&(u=-1),a.sig?.rest&&u>=s.length&&(u=s.length-1),u>=s.length&&(u=-1);let d=a.def?[a.def.doc,a.def.file!==void 0&&`From \`<${a.def.file}>\``].filter(Boolean).join(`
|
|
3051
4282
|
|
|
3052
|
-
`):a.sig.doc;return{label:i,...d&&{doc:d},params:o,active:u}}function
|
|
3053
|
-
`)[0]}:a.kind!=="variable"&&{detail:
|
|
4283
|
+
`):a.sig.doc;return{label:i,...d&&{doc:d},params:o,active:u}}function hl(n){let e=n.definitions.filter(a=>ae.has(a)).sort((a,r)=>a.range[0]-r.range[0]),t=[],c=[];for(let a of e){let r={name:a.name,kind:a.kind,...a.kind==="variable"&&a.value!==void 0?{detail:a.value.split(`
|
|
4284
|
+
`)[0]}:a.kind!=="variable"&&{detail:se(a)},range:a.range,start:a.start,end:a.end,children:[]};for(;c.length&&c[c.length-1].range[1]<a.range[0];)c.pop();(c.length?c[c.length-1].children:t).push(r),a.kind!=="variable"&&c.push(r)}return t}var vt=/\s*\(line (\d+)(?:, column (\d+))?(?: in <([^>]+)>)?\)/;function ul(n,e={}){let t=[0];for(let o=n.indexOf(`
|
|
3054
4285
|
`);o>=0;o=n.indexOf(`
|
|
3055
|
-
`,o+1))t.push(o+1);let c=o=>n.slice(t[o-1],(t[o]??n.length+1)-1).replace(/\r$/,""),a=(o,l)=>{if(o<1||o>t.length)return{start:0,end:0};let h=c(o);if(l===void 0){let u=h.length-h.trimStart().length;return{start:t[o-1]+u,end:t[o-1]+h.trimEnd().length}}let f=t[o-1]+Math.min(l-1,h.length);return{start:f,end:Math.min(f+
|
|
3056
|
-
${
|
|
4286
|
+
`,o+1))t.push(o+1);let c=o=>n.slice(t[o-1],(t[o]??n.length+1)-1).replace(/\r$/,""),a=(o,l)=>{if(o<1||o>t.length)return{start:0,end:0};let h=c(o);if(l===void 0){let u=h.length-h.trimStart().length;return{start:t[o-1]+u,end:t[o-1]+h.trimEnd().length}}let f=t[o-1]+Math.min(l-1,h.length);return{start:f,end:Math.min(f+Q7(h,l),t[o-1]+h.length)}},r=o=>{let l=new RegExp(`\\b(?:use|include)\\s*<${o.replace(/[.*+?^${}()|[\]\\/]/g,"\\$&")}>`).exec(n);return l?{start:l.index,end:l.index+l[0].length}:{start:0,end:0}},s=[],i=o=>{if(o.startsWith("Nothing to cut"))return;let l=vt.exec(o);l?l[3]?s.push({severity:"warning",message:o,...r(l[3])}):s.push({severity:"warning",message:o.replace(vt,""),...a(Number(l[1]),l[2]===void 0?void 0:Number(l[2]))}):s.push({severity:"warning",message:o,start:0,end:0})};try{lt(n,e).warnings.forEach(i)}catch(o){if(!(o instanceof X))return s.push({severity:"error",message:o instanceof Error?o.message:String(o),start:0,end:0}),s;o.warnings.forEach(i);let l=o.trace.filter(m=>m.file===void 0),h=o.reason,f={start:0,end:0};if(o.file===void 0&&o.line!==void 0)f=a(o.line,o.col);else if(o.file!==void 0){h+=` (in <${o.file}>${o.line!==void 0?`, line ${o.line}`:""})`;let m=l.shift();f=m?a(m.line,m.col):r(o.file)}let u=o.call?j2(o.call):void 0;u&&(h+=`
|
|
4287
|
+
${f5(u)}: ${u.doc}`);let d=l.map(m=>({message:`in ${m.kind==="module"?"module ":""}${m.name}(), called here${m.count>1?` (${m.count} times)`:""}`,...a(m.line,m.col)}));s.push({severity:"error",message:h,...f,...d.length&&{related:d}})}return s}export{rl as analyze,ol as complete,$r as definition,il as hover,hl as outline,ul as problems,Ur as references,sl as rename,Nr as renameTarget,ll as signatureHelp};
|
|
3057
4288
|
/*! Bundled license information:
|
|
3058
4289
|
|
|
3059
4290
|
opentype.js/dist/opentype.module.js:
|